From kylotan at gmail.com Mon Dec 25 17:48:35 2006 From: kylotan at gmail.com (Ben Sizer) Date: 25 Dec 2006 14:48:35 -0800 Subject: Why does Python never add itself to the Windows path? References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> <1167059973.888721.251460@i12g2000cwa.googlegroups.com> Message-ID: <1167086915.786797.260130@n51g2000cwc.googlegroups.com> Ross Ridge wrote: > Ben Sizer wrote: > > I've installed several different versions of Python across several > > different versions of MS Windows, and not a single time was the Python > > directory or the Scripts subdirectory added to the PATH environment > > variable. > > Personally, I hate Windows applications that add themselves to the > PATH. So much crap gets put in there that I don't even use the default > system PATH and just set my own explicitly. Personally I hate programs that ask to be installed to the root folder of my hard drive, but Python suggests that as a default too. ;) In an ideal world, Python should operate pretty much the same across all platforms. Unfortunately, as it stands, you need to have different instructions for running things on Windows. eg. The standard "python setup.py install" invocation isn't going to do a damn thing unless you've fixed up the path beforehand. The same goes for "python ez_setup.py", another common favourite. The scripts directory is important too: TurboGears installs a "tg-admin" script which you're supposed to run from your project's directory: which on Windows means you need to type something like "c:\python24\scripts\tg-admin" each time. Half of the people who develop on Mac and Linux don't realise or acknowledge this. and so the instructions for using their packages don't work for the average person new to Python who probably just ran the Windows installer program and thought that would suffice. > Linux distributions normally install themselves somewhere that's > normally in the path already. I suppose you can do the same thing on > Windows if you want, just choose to install Python into directory > that's already in your path. Though installing to something like > C:\WINDOWS\SYSTEM32 is probably not a good idea. The Windows way is typically to install things in Program Files and then point things there as necessary. Installing it the Linux way would just cause a different set of problems. Adding it to the PATH variable is not going to cause problems for the vast majority of people, and it's far easier to edit up the PATH to remove an entry you don't want, than to move an installed program from one place to another. -- Ben Sizer From has.temp3 at virgin.net Mon Dec 18 11:38:44 2006 From: has.temp3 at virgin.net (has) Date: 18 Dec 2006 08:38:44 -0800 Subject: Is there a way to push data into Ical from Python ? In-Reply-To: <1166364160.192126.123420@n67g2000cwd.googlegroups.com> References: <4584591b$0$29324$426a74cc@news.free.fr> <1166364160.192126.123420@n67g2000cwd.googlegroups.com> Message-ID: <1166459924.298273.82290@t46g2000cwa.googlegroups.com> dwhall wrote: > One way would be to use > Python's tie-ins to Applescript_ and apple events (AE). As you will > read, this support isn't as strong as it used to be. What gave you that impression, if you don't mind my asking? It's true that Python's built-in application scripting support (aetools+gensuitemodule) has become increasingly broken on OS X and should be avoided. Third-party support has been continually improving over the last few years, however, and these days is pretty much on-par with AppleScript in terms of functionality. See for more information and downloads. > Another idea that would require more effort, but earn you some hacker > points, is to use PyObjC_ and access iCal's public programming > interface. The CALCore framework is private in OS X 10.4, so the usual disclaimers apply w.r.t. using that. See for a basic example of use. Scuttlebutt says there'll be a public iCal framework in 10.5, although that won't help the OP right now unless they're a paid-up ADC member. has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org From jstroud at mbi.ucla.edu Sat Dec 16 07:55:47 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 16 Dec 2006 12:55:47 GMT Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: <4583ED06.5000104@mbi.ucla.edu> Christoph Zwerschke wrote: > "Inhomogenous" in some meaning of the word --> tuple I think that you have nailed it here. I don't think anyone on this list is capable of giving a "concrete" (as you have put it) operational definition of "inhomogenous". They will resort to use cases and thus cloud the definition with programming philosophy. So, programming philosophy, whether it will be admitted or not, is fully responsible for the exclusion of index() from the tuple interface. But perhaps we could take "not necessarily homogenous" to be the operational definition of "inhomogenous". Of course then we would have to define necessary... James From mail at microcorp.co.za Fri Dec 22 00:16:29 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 22 Dec 2006 07:16:29 +0200 Subject: How a script can know if it has been called with the -i command lineoption? References: <1166720012.798260.6670@80g2000cwy.googlegroups.com> Message-ID: <01b701c7258d$17c8cac0$03000080@hendrik> "Michele Simionato" wrote: > The subject says it all, I would like a script to act differently when > called as > $ python script.py and when called as $ python -i script.py. I looked > at the sys module > but I don't see a way to retrieve the command line flags, where should > I look? sys.argv() ? - Hendrik From skip at pobox.com Sun Dec 3 00:55:58 2006 From: skip at pobox.com (skip at pobox.com) Date: Sat, 2 Dec 2006 23:55:58 -0600 Subject: Tools for Java/Python scripting In-Reply-To: References: <1162569614.650081.166270@h48g2000cwc.googlegroups.com> Message-ID: <17778.26350.1903.81152@montanaro.dyndns.org> steve> http://wiki.python.org/moin/Java_Scripting >> >> Renamed to "JavaScripting". >> >> Skip Rob> So nobody around here has heared of that other language called Rob> JavaScript then ? Rob> Perhaps "Scripting_Java" might be better. That would be JavaScriptScripting... Skip From http Fri Dec 15 08:41:35 2006 From: http (Paul Rubin) Date: 15 Dec 2006 05:41:35 -0800 Subject: skip last line in loops References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: <7xhcvx5l9s.fsf@ruckus.brouhaha.com> eight02645999 at yahoo.com writes: > for line in open("file): > print line. > > I want to skip printing last line of the file.thanks def all_but_last(it): # yield all but last item of an iterator a = it.next() for b in it: yield a a = b for line in all_but_last(open("file")): print line From tjreedy at udel.edu Tue Dec 12 20:01:41 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Dec 2006 20:01:41 -0500 Subject: YouTube written in Python Message-ID: In a thread on the PyDev list, Guido van Rossum today wrote: > And I just found out (after everyone else probably :-) that YouTube is > almost entirely written in Python. (And now I can rub shoulders with > the developers since they're all Googlers now... :-) In reply, Simon Brunning noted: > That'll put to bed any "Does Python scale" discussions. From bignose+hates-spam at benfinney.id.au Wed Dec 20 01:07:57 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 20 Dec 2006 17:07:57 +1100 Subject: Working with unsigned/signed types References: <20061220054657.7CEEA1E4006@bag.python.org> Message-ID: <87bqlz6qwy.fsf@benfinney.id.au> writes: > The first part of the question is fairly basic - in C, working with > signed integers, the MSB (is that still the right term?) is used to > denote positive and negative, and the following bits increase > towards positive infinity, correct? Such that in C, adding one to > 0x7fffffff would cause the number to go around to -0x7fffffff (or > whatever that is), giving -1 for 0xffffffff? > > Secondly, (and this is my weak point as a programmer) to re-insert > the data after, what would be the most efficient way to pull > everything back apart into individual characters for putting it all > back into the files? I could probably figure out something that > would work, but I wouldn't be so sure as to its reliability. I think, from the above, that you want to read about the 'struct' module in the standard library. > Third, being a photographer now rather than a coder, I'd like to > give back the modules I'm writing to the community (it looks like > very little of the sort exists), but would rather not worry about > them in the future... Is there a good way to go about this? Ideally, find someone who will actively maintain the code into the foreseeable future; maybe a user of the code with more interest in programming than you. Failing that, find a place to put it online for the foreseeable future, and notify repositories like Freshmeat of its existence and location. The most important thing to do is to explicitly license the rights to modify and redistribute freely for all people who receive the code, so they never have to try to track you down for permission. Choose a permissive license like the Expat license if you want to allow people to do just about anything except claim you didn't write it; choose a copyleft like the GNU General Public License if you want to ensure nobody can redistribute under more restrictive terms in future. Make each file clearly marked so that the grant of license is clear, and include the text of the license terms in an obvious file in the source code package. See the addendum of the GNU GPL for how this is best done, even if you end up not choosing that particular license. Thanks for thinking of the future hackers :-) -- \ "...one of the main causes of the fall of the Roman Empire was | `\ that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs." -- Robert Firth | Ben Finney From fredrik at pythonware.com Sun Dec 10 02:20:29 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 10 Dec 2006 08:20:29 +0100 Subject: ATTRIBUTE ERROR: 'module' object has no attribute 'ssl' In-Reply-To: <1165720787.910338.118940@j44g2000cwa.googlegroups.com> References: <1165720787.910338.118940@j44g2000cwa.googlegroups.com> Message-ID: johnny wrote: > I am getting the following errors: > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in > _send_output > self.send(msg) > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send > self.connect() > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in > connect > ssl = socket.ssl(sock, self.key_file, self.cert_file) > AttributeError: 'module' object has no attribute 'ssl' looks like you're using a Python distribution that doesn't support SSL. ActivePython, perhaps? From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Wed Dec 6 08:48:11 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Wed, 06 Dec 2006 14:48:11 +0100 Subject: len() and PEP 3000 References: <4tnqlkF13bbqeU1@mid.individual.net> Message-ID: <4to00aF14cki5U2@mid.individual.net> Thomas Guettler wrote: > I suggest that at least lists, tupples, sets, dictionaries and > strings get a len() method. Why? > I think the len function can stay, removing it would break to much > code. But adding the method, would bu usefull. > > Yes, I know, that I can call .__len__() but that is ugly. That's what len() is for. Regards, Bj?rn -- BOFH excuse #281: The co-locator cannot verify the frame-relay gateway to the ISDN server. From irmen.NOSPAM at xs4all.nl Fri Dec 1 19:59:51 2006 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 02 Dec 2006 01:59:51 +0100 Subject: client/server design and advice In-Reply-To: References: Message-ID: <4570d007$0$326$e4fe514c@news.xs4all.nl> bruce wrote: > hi irmen... > > happened to come across this post. haven't looked at pyro. regarding your > 'work packets' could these essentially be 'programs/apps' that that are > requested by the client apps, and are then granted by the dispatch/server > app? > Pyro supports a limited form of "mobile code" i.e. the automatic transfering of Python modules to the other side. But it has a few important limitations and there's the security aspect as well. It's really better if you can stick to passing data around, not code... ;-) > i'm considering condor (univ of wisconsin) but am curious as to if pyro > might also work. Not familiar with this. --Irmen From steve at REMOVE.THIS.cybersource.com.au Thu Dec 7 07:39:50 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Thu, 07 Dec 2006 23:39:50 +1100 Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> Message-ID: On Thu, 07 Dec 2006 04:08:18 -0800, Stephen Eilert wrote: > Given that Python says that "There Should Be Only One Way to Do It", Python says no such thing. Perhaps you should run "import this" at the prompt, and read _carefully_ and take note of the difference between the Zen of Python and what you wrote, because the difference is very, very significant. -- Steven. From ironfroggy at gmail.com Tue Dec 5 14:10:28 2006 From: ironfroggy at gmail.com (Calvin Spealman) Date: Tue, 5 Dec 2006 14:10:28 -0500 Subject: Subprocess with a Python Session? Message-ID: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> No matter what I do I cant get the following code to do what I expect. I hadn't used subprocess t o read and write to pipes of a still-running app, and I just can't seem to get it right. What gives? import subprocess p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE) p.stdin.write('print 10\n') assert p.stdout.readline() == '10\n' -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ From amichail at gmail.com Fri Dec 1 07:03:47 2006 From: amichail at gmail.com (Amir Michail) Date: 1 Dec 2006 04:03:47 -0800 Subject: python vs java & eclipse In-Reply-To: References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com> Message-ID: <1164974627.554596.300240@l12g2000cwl.googlegroups.com> krishnakant Mane wrote: > just used the py dev plugin for eclipse. > it is great. But isn't support for java better because the eclipse ide can take advantage of explicit type declarations (e.g., for intellisense, refactoring, etc.)? Amir > auto indentation and intellisence. > and all other things. > so now how does it look from this end? > python + productivity and eclipse + productivity = double productivity! > only problem with the plugin is that I find it difficult to manage the > script running. > I open a command prompt and run the scripts manually. > any suggestion for this. > for example I had name = raw_input("please enter your name") and the > moment I type the first letter on the keyboard the code execution > moves over to the next statement. should it not wait for the return > key as it always does? > Krishnakant. From researchbase at gmail.com Mon Dec 11 03:26:35 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Mon, 11 Dec 2006 13:56:35 +0530 Subject: need guidance on sending emails with attachment with python. In-Reply-To: <200612101328.44156.jonc@icicled.net> References: <200612101328.44156.jonc@icicled.net> Message-ID: hi jonathan, it is understandable from your point of view I wont say you were rood. but my question was different. I am very new to doing programmed emails. all I need to know is that will I need to use outlook or any thing to send emails to pop3 or smtp? I want to know because I wont like to make use of outlook or any thing to do my work. I know the python libraries are there but I want to know what these libraries will make use of on my windows machine. Krishnakant. From renwei at koal.com Thu Dec 21 20:46:23 2006 From: renwei at koal.com (weir) Date: 21 Dec 2006 17:46:23 -0800 Subject: Building python C++ extension modules using MS VC++ 2005? In-Reply-To: References: Message-ID: <1166751983.702105.175410@79g2000cws.googlegroups.com> Sure you can build extensions for Python2.4 with VS2005, I've always done this way. And with Pyrex it is very very easy. Make sure to have a look at Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex From joncle at googlemail.com Fri Dec 1 11:31:04 2006 From: joncle at googlemail.com (Jon Clements) Date: 1 Dec 2006 08:31:04 -0800 Subject: Simple question on indexing In-Reply-To: <20061201172146.ceb8a7f8.tartifola@gmail.com> References: <20061201172146.ceb8a7f8.tartifola@gmail.com> Message-ID: <1164990664.009977.140060@80g2000cwy.googlegroups.com> Tartifola wrote: > Hi, > I would like to obtain the position index in a tuple when an IF > statement is true. Something like > > >>>a=['aaa','bbb','ccc'] > >>>[ ??? for name in a if name == 'bbb'] > >>>1 > > but I'm not able to find the name of the function ??? in the python documentation, any help? > Thanks Ummm, that's a list not a tuple: I'll assume you meant sequence. This will generate a list of indexes which match the criteria: >>> a = [ 1, 2, 3, 2, 5, 7] >>> [elno for elno,el in enumerate(a) if el == 2] [1, 3] hth Jon. From george.sakkis at gmail.com Fri Dec 8 11:33:32 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 8 Dec 2006 08:33:32 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> Message-ID: <1165595612.159069.31720@f1g2000cwa.googlegroups.com> Alex Mizrahi wrote: > (message (Hello 'Istvan) > (you :wrote :on '(8 Dec 2006 06:11:20 -0800)) > ( > > ??>> seems to show that Python is a cut down (no macros) version of Lisp > ??>> with a worse performance. > > IA> or maybe it shows that Lisp is an obfuscated version of Python > > hell no, lisp's syntax is much easier than python's since it's homogenous It sure is easier... if you're a compiler rather than a human. Also a lightbulb is much easier understood as a bunch of homogeneous elemental particles. George From nmm1 at cus.cam.ac.uk Wed Dec 20 06:56:38 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 20 Dec 2006 11:56:38 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4uslgfF18sq18U1@mid.individual.net> Message-ID: In article <4uslgfF18sq18U1 at mid.individual.net>, greg writes: |> |> > Nope. Sorry. Consider the old model where an I/O list is an ordered |> > sequence of strings and agents (effectively procedure calls), with no |> > constraints on how those are ordered. With your specification, that |> > is neither heterogenous nor homogenous :-) |> |> I don't see any difficulty. This is a list (homogeneous) of |> two-element tuples (heterogeneous). Not at all. I didn't say that they came in pairs. Consider: [str1, str2, agent1, str3, agent2, agent3, agent4, str4, ...] See Algol 68 for an example of this. Regards, Nick Maclaren. From ptmcg at austin.rr._bogus_.com Mon Dec 25 19:04:02 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 25 Dec 2006 18:04:02 -0600 Subject: Generating all permutations from a regexp References: <1166845194.983480.79140@79g2000cws.googlegroups.com> Message-ID: <459066f2$0$27037$4c368faf@roadrunner.com> "Paul McGuire" wrote in message news:1166845194.983480.79140 at 79g2000cws.googlegroups.com... On Dec 22, 8:30 am, "BJ?rn Lindqvist" wrote: > With regexps you can search for strings matching it. For example, > given the regexp: "foobar\d\d\d". "foobar123" would match. I want to > do the reverse, from a regexp generate all strings that could match > it. > > The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000", > "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999". > > Is this possible to do? Here is a first cut at your problem (http://pyparsing-public.wikispaces.com/space/showimage/invRegex.py). I used pyparsing to identify repeatable ranges within a regex, then attached generator-generating classes to parse actions for each type of regex element. Some limitations: - unbounded '*' and '+' repetition is not allowed - only supports \d, \w, and \s macros ===================== Download the latest version of this file. It is now importable as its own module, with the invert method that takes a regexp string and returns a generator that yields all the possible matching strings. This file also includes a simple count method, which returns the number of elements returned by a generator (as opposed to calling len(list(invert("..."))), which generates an intermediate list just to invoke len on it). The reg exp features that have been added are: - alternation using '|' - min-max repetition using {min,max} format - '.' wildcard character Also fixed some repetition bugs, where "foobar{2}" was treated like "(foobar){2}" - now both cases are handled correctly. -- Paul From fumanchu at amor.org Thu Dec 28 01:56:49 2006 From: fumanchu at amor.org (fumanchu) Date: 27 Dec 2006 22:56:49 -0800 Subject: Hooking any/all 'calls' References: Message-ID: <1167289009.467552.33890@79g2000cws.googlegroups.com> Kevin Little wrote: > In Python 2.4 or 2.5, what is the easiest way to hook any and all > callables such that designated code is executed at the very start and > end of each call? (Yes, I'm trying to come up with a little debugging > tool!:) Is there a single metaclass who's "__call__" method can be > wrapped to do this? You probably want sys.settrace, which is specifically designed for creating debuggers, and is the basis for pdb, the debugger in the standard library. See http://docs.python.org/lib/module-sys.html#l2h-5159 Feel free also to look through my own debugging aid (for clues on how to implement your own, or just to use for your needs): http://projects.amor.org/misc/wiki/PyConquer Robert Brewer System Architect Amor Ministries fumanchu at amor.org From kloro2006 at gmail.com Sun Dec 10 12:51:43 2006 From: kloro2006 at gmail.com (tom arnall) Date: Sun, 10 Dec 2006 09:51:43 -0800 Subject: object data member dumper? Message-ID: <457c3b75$0$15555$88260bb3@free.teranews.com> > > object data member dumper? > George Sakkis george.sakkis at gmail.com > Wed Nov 8 03:42:47 CET 2006 > tom arnall wrote: > > > Bruno Desthuilliers wrote: > > > > > tom arnall a ?crit : > > >> does anyone know of a utility to do a recursive dump of object data > > >> members? > > >> > > > > > > What are "object data members" ? (hint: in Python, everything is an > > > object - even functions and methods). > > > > > > What is your real use case ? > > > > something like: > > > > class A: > > def __init__(self, p1): > > self.p1 = p1 > > > > class B: > > def __init__(self,p1, p2): > > self.a = A(p1) > > self.p2 = p2 > > self.v1 = '3' > > > > class C: > > def __init__(self): > > self.b = B(3,4) > > self.p3 = 5 > > > > class D: > > def __init__(self): > > self.v2=2 > > self.o1 = C() > > self.o2 = B(11,12) > > > > > > d = D() > > objectDataDumper(d) > > > > > > would produce something like: > > > > object of class D with: > > o1(C)->b(B)->a(A)->p1=3 > > o1(C)->b(B)->p2=4 > > o1(C)->b(B)->v1=3 > > o1(C)->p3=5 > > o2(B)->a(A)->p1=11 > > o2(B)->p2=12 > > o2(B)->v1=3 > > v2=2 > > > > > > tom arnall > > north spit, ca > > usa > > At first I thought pickle would be what you're looking for, because > that's exactly what it does; it dumps arbitrary objects, without > choking on recursive references. Only problem is, it's not human > readable (even in its ascii form).If you want it to be human readable, > you may check the gnosis.xml.pickle module > (http://cheeseshop.python.org/pypi/Gnosis_Utils/1.2.1-a). That's the > output of gnosis.xml.pickle.XML_Pickler(d).dumps() on your example: > > > > > > class="B"> > class="A"> > > > > > > class="C"> > > class="B"> > class="A"> > > > > > > > > > > I've also written a similar but less verbose xml dumper. The gnosis.xml > package provides a bidirectional mapping between objects and xml > (objects -> xml and xml->object) and therefore has to be precise; mine > simply generates a nice xml dump of the object which isn't necessarily > reversible. Here's the output for your example: > > > > > > 3 > > 4 > 3 > > 5 > > > > 11 > > 12 > 3 > > 2 > > > > If you find it suits you better, I'll try to make it available > somewhere (probably in the cookbook). > > George George, did you ever put your object dumper on the internet? tom arnall north spit, ca usa "Make cyberspace pretty: stamp out curly brackets and semicolons." -- Posted via a free Usenet account from http://www.teranews.com From juanrgonzaleza at canonicalscience.com Mon Dec 11 14:25:04 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 11 Dec 2006 11:25:04 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> Message-ID: <1165865104.255776.244290@f1g2000cwa.googlegroups.com> Ken Tilton ha escrito: > You missed it? Google fight: > > http://www.googlefight.com/index.php?lang=en_GB&word1=Python&word2=Ruby > > Python wins, 74 to 69.3. And there is no Monty Ruby to help. > > ken Nice animation! http://www.googlefight.com/index.php?lang=en_GB&word1=Ken+Tilton&word2=Monty+Ruby From mistersulu at gmail.com Wed Dec 13 14:02:27 2006 From: mistersulu at gmail.com (mistersulu) Date: 13 Dec 2006 11:02:27 -0800 Subject: free, python XML merger? In-Reply-To: References: <1165858953.389963.161000@f1g2000cwa.googlegroups.com> Message-ID: <1166036546.994794.146990@16g2000cwy.googlegroups.com> Thanks Harry. I just wrote a new one. Quicker than trying to mod somebody else's stuff. Thanks again, sulu Harry George wrote: > "mistersulu" writes: > > > All: > > > > We're looking for a python module which allows for quick merging of two > > XML files. Both files follow the same schema. One file contains the > > default values and structure, and the second file contains overriding > > data for the same tags. > > > > Thanks in advance, > > sulu > > > > Sounds like a general XML problem, to be solved with cElementTree > perhaps. Can you provide the schema and small examples of the input > files and the desired output file? > > -- > Harry George > PLM Engineering Architecture From gagsl-py at yahoo.com.ar Tue Dec 26 16:08:45 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Tue, 26 Dec 2006 18:08:45 -0300 Subject: Type text global In-Reply-To: <45915467.3040309@riddergarn.dk> References: <1167149636.601673.204030@a3g2000cwd.googlegroups.com> <45915467.3040309@riddergarn.dk> Message-ID: <7.0.1.0.0.20061226180741.0203f9a8@yahoo.com.ar> At Tuesday 26/12/2006 13:57, Andreas Lysdal wrote: >I'm a noob at python so.. > >I just want to know, is there a function to type text global not in the >program but in other programs(like you where typing it). >For example in a textbox, in a program like "cmd.exe" or "notebook.exe". > >I'm using windows xp. There is a module named SendKeys which may be useful, try to find it. -- 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 From paddy3118 at netscape.net Wed Dec 13 04:24:16 2006 From: paddy3118 at netscape.net (Paddy) Date: 13 Dec 2006 01:24:16 -0800 Subject: merits of Lisp vs Python In-Reply-To: <457fbb4f.5829983@news.readfreenews.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> <1165857526.721489.322470@73g2000cwn.googlegroups.com> <1165975429.053195.95700@j72g2000cwa.googlegroups.com> <457fbb4f.5829983@news.readfreenews.net> Message-ID: <1166001856.366220.91870@j44g2000cwa.googlegroups.com> On Dec 13, 8:39 am, g... at mail.ru (Timofei Shatrov) wrote: > On 12 Dec 2006 18:03:49 -0800, "Paddy" tried to confuse > everyone with this message: > > >There are a lot of people that use Wikipedia. I think some of them > >might want to learn to program. > I think you misunderstood the goal of Wikipedia. It is not to teach people > programming. You think wrong. Wikipedia articles get searched and links get followed. Its good for some of those to link to articles on Python. > > >I make it easier for them to find > >Python by helping to maintain Python within Wikipedia. > If someone wants to find Python, he types "Python" in the search bar and works > from there. He certainly wouldn't end up in "doctest" article. If someone is looking up comments or testing, then they might well end up reading the doctest article. And why not! Does Lisp have similar? Is the Lisp community as welcoming? Do you have to think yourself a genius to join the club? Is Lisp approachable? > > >Some people dislike Wikipedia which is fine. Some people dislike > >Wikipedia and deliberately sabotage it, which is vandalism. > Writing vanity articles about non-notable things is not much better. Should I have asked you first ;-) - Paddy. From whumeniu+anti+spam at telus.net Sat Dec 9 16:20:20 2006 From: whumeniu+anti+spam at telus.net (Wade Humeniuk) Date: Sat, 09 Dec 2006 21:20:20 GMT Subject: merits of Lisp vs Python In-Reply-To: <1165698244.563344.62270@73g2000cwn.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: mystilleef wrote: > > People only contribute to things they understand and appreciate. More > people would be writing Lisp libraries if it was worthwhile. > Apparently, it doesn't seem to be. A few years ago, I tried to write an > editor is Scheme. The experience was appalling. I was able to write a > fully functional prototype editor in less than a week in Python. > Shockingly, at the time, I had no experience in Python. Guess which > community I was inclined to contribute to afterwards. I hear stories > similar to mine time and again, yet the Lisp community won't take heed. > They'd rather squeal about the superiority of macros and whine about > their frustrations in Python news groups. > Hmm.. Here is my first prototype in Lisp. It took 20 seconds to write. (defun display-editor () (capi:contain (make-instance 'capi:editor-pane))) CL-USER 1 > (display-editor) # CL-USER 2 > W From gagsl-py at yahoo.com.ar Thu Dec 21 00:09:33 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 20 Dec 2006 21:09:33 -0800 Subject: list1.append(list2) returns None In-Reply-To: <1166673056.617582.176340@80g2000cwy.googlegroups.com> References: <87mz5hexf7.fsf@pyenos.pyenos.org> <1166673056.617582.176340@80g2000cwy.googlegroups.com> Message-ID: <1166677773.570605.176000@n67g2000cwd.googlegroups.com> > > def enlargetable(table,col): > > return table.append(col) Google for "python pitfalls" -- Gabriel Genellina From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Sat Dec 23 12:53:05 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Sat, 23 Dec 2006 18:53:05 +0100 Subject: removing the header from a gzip'd string References: <1166735512.435837.60080@42g2000cwt.googlegroups.com> <4v0f53F1afe47U1@mid.individual.net> <1166895890.297135.144990@i12g2000cwa.googlegroups.com> Message-ID: <4v58o1F1ak276U1@mid.individual.net> debarchana.ghosh at gmail.com wrote: > Actually I was implementing the use of the normalized compression > distance to evaluate molecular similarity as described in an > article in J.Chem.Inf.Model (http://dx.doi.org/10.1021/ci600384z, > subscriber access only, unfortunately). Interesting. Thanks for the reply. Regards, Bj?rn -- BOFH excuse #438: sticky bit has come loose From basti.wiesner at gmx.net Fri Dec 29 05:47:00 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Fri, 29 Dec 2006 11:47:00 +0100 Subject: Reverse of SendKeys?? References: <45944a63$1@nntp.zianet.com> Message-ID: "Erik Johnson" <> typed > Aside from the obvious security issues such a program would > represent (and your name and signature are curious in that respect as > well), you are basically asking for functionality (i.e., a key logger) > I believe to be outside what is offered by Python and/or the API of > most operating systems. I agree on the security issues, and on the statement, that writing a key logger is outside the scope of the standard python library. But it is easily possible to write a key logger using the API of common operating systems. Windows provides hooks for intercepting messages from input devices such as keyboard and mouse. On Linux you can either write a kernel module, which is the less portable, but more effective way, or you can code a X11 key logger, which will also work on other unix-like systems with a working X11 installation. -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From ejatwellkeeperdotcom Wed Dec 27 12:59:50 2006 From: ejatwellkeeperdotcom (Erik Johnson) Date: Wed, 27 Dec 2006 10:59:50 -0700 Subject: getting a process's PID References: <20061227102939.L20663@eris.io.com> <4592abf1$1@nntp.zianet.com> <20061227113158.J21223@eris.io.com> Message-ID: <4592b4bd$1@nntp.zianet.com> "eldorado" wrote in message news:20061227113158.J21223 at eris.io.com... > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] > >>> h = h[:-1] > >>> h > [] Oh, sorry... h is a list here because you are using readlines(). I am used to doing this: fd = os.popen('ps -ef | grep python') s = fd.read() to get a single string. You can do something like s = h[0] and then operate on s, or you can use read() in place of readlines() to get h as a single string, or you can operate on the first element of h: >>> h = ['87334\012'] >>> h[0][:-1] '87334' >>> h[0].rstrip('\n') '87334' All the error handling to do in the case where you actually have multiple processes being matched is up to you. ;) -ej From bj_666 at gmx.net Mon Dec 11 10:24:07 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Mon, 11 Dec 2006 16:24:07 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> Message-ID: In <1165849055.492230.119310 at n67g2000cwd.googlegroups.com>, Kay Schluehr wrote: > Once an easy to use metaprogramming system could be done for Python it > could be ported with some adaptions to other languages with more > "complicated syntax" ( non LL(1) parsable ). FYI: Here's how Nemerle does macros: http://nemerle.org/Macros I guess you can't really transform Nemerle into a completely different language, but it is at least interesting to see such a feature in language with a more complex syntax than Lisp. Ciao, Marc 'BlackJack' Rintsch From jon at ffconsultancy.com Sun Dec 10 02:15:59 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 07:15:59 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: <457bb4cf$0$8756$ed2619ec@ptn-nntp-reader02.plus.net> Ken Tilton wrote: > Andr? Thieme wrote: >> def foo(function, args): >> setup(1) >> setup(2) >> function(args) >> cleanup(1) >> cleanup(2) >> >> The nice thing in Lisp would now be to save a lambda with the macro. >> In Python one would fill the name space with throw away functions that >> get called only one time. That is a deficiency of Python that doesn't exist in modern FPLs like OCaml, SML, Haskell, F#... > Omigod. Is that what you meant? You think macros are unnecessary because > one could hard-code their expansions as separate functions? And that > would constitute hiding the boilerplate? What happens when the > boilerplate changes? He is correct. When the boilerplate changes, you change your HOF. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From basti.wiesner at gmx.net Thu Dec 28 06:12:48 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Thu, 28 Dec 2006 12:12:48 +0100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <4593185f$1@nntp.zianet.com> Message-ID: Steven D'Aprano typed > On Thu, 28 Dec 2006 09:26:28 +0100, Sebastian 'lunar' Wiesner wrote: > >> It is, and especially the problems with tabs shows you, why it is >> good practice to follow the standard in your own code, too... > > I don't know what "problems" with tabs you are talking about. I never > have problems with tabs. *Other people* who choose to use software > that doesn't understand tabs have problems. Mmmh, maybe you never worked together with a team of other programmers or have such a high position, that you can afford to ignore complaints of your co-workers... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From bignose+hates-spam at benfinney.id.au Tue Dec 5 22:12:56 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Wed, 06 Dec 2006 14:12:56 +1100 Subject: Submitting change requests through correct channels References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165298191.987140.176550@f1g2000cwa.googlegroups.com> <877ix6re1j.fsf_-_@benfinney.id.au> Message-ID: <873b7tra2v.fsf@benfinney.id.au> Fredrik Lundh writes: > Ben Finney wrote: > > > I hope that, instead, it's possible to perform the research needed > > to describe the requested change, submit it as an email or online > > form > > are you perhaps volunteering to help setup and monitoring such a > sub- mission channel ? I have done for other projects. I don't have the resources to do it for every project that I'm interested in, and Python is one of many that miss out. I also wasn't insisting that anyone else do so; merely pointing out some negative consequences of (what I understand to be) the current situation, that may not be apparent to those who are closest to the issue tracker. -- \ "Everything is futile." -- Marvin of Borg | `\ | _o__) | Ben Finney From george.sakkis at gmail.com Fri Dec 8 22:41:33 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 8 Dec 2006 19:41:33 -0800 Subject: autoadd class properties References: <1165567093.167813.109000@j44g2000cwa.googlegroups.com> <1165569502.811830.157900@73g2000cwn.googlegroups.com> <1165622366.780227.41870@79g2000cws.googlegroups.com> Message-ID: <1165635693.873501.203330@l12g2000cwl.googlegroups.com> manstey wrote: > We've looked at them a little. Cache is a native OO dbase, so there is > no ORM required. Cache does that for you behind the scenes if you need > it to. What I want is to translate Cache classes and properties into > Python classes and properties. We can only use class wrappers, because > cache uses old style python objects, but this still works. > > Because I am not an experienced programmer, the problem I face is how > to load ANY Cache class, whose properties the wrapper doesn't know in > advance, and turn the class properties into python properties. > > So in Cache, I might have Name = String, Age = Integer, Colours = List, > in the class Person. The python binding provided by Cache creates a > Person class in Python, but it provides none of its properties, so I > want to write a wrapping class that adds the properties. Can you advise > me on how to do this? I'm afraid not, at least not without seeing an example. By the way, I've never heard of Cache before and its name is too generic for looking it up online; you should at least provide a link if you're asking for help about obscure packages. George From kentilton at gmail.com Sat Dec 16 15:43:36 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 16 Dec 2006 15:43:36 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1166296713.967467.44490@73g2000cwn.googlegroups.com> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> <1166175804.202131.54070@l12g2000cwl.googlegroups.com> <1166296713.967467.44490@73g2000cwn.googlegroups.com> Message-ID: xscottg at gmail.com wrote: > Ken Tilton wrote: > >>xscottg at gmail.com wrote: >> >>>Code is data is code >> >>I was hoping no one would make that mistake. :) macros are all about >>code is data, but code is not data in Python* so the two words code and >>data serve to differentiate them for Pythonistas. >> > > > I disagree. I might agree. The suggest alternative where the engine would build up an "environment" such that a lambda could seem to be accessing a pre-defined slot-name reminded me of some of the magic I noticed when trying to port Cells to Python. If the interpreter (as it seems) gracefully handles things like that, then one could argue that Python can at least generate code to be consumed by what I would have as a macro body, and thus achieve a degree of code is data. Of course then I would point out that this would be terribly confusing and should be banned from Python for the same reason as are macros. :) I frequently write data-driven algorithms in C and Python > (data is code). I occasionally write code-generators too (code is > data). Just because the representation is different between code and > data in those languages doesn't mean that you can't use data as code > (interpreter style) or generate code as data (compiler style). (I > won't bother boring you with the Python bytecode hacks or the parser > module, because I think those are not terribly practical.) > > It's very elegant that Lisp makes the representations between code and > data so similar, but it looks like you know the mantra and not the > meaning if you can't apply that principle in other languages. > > BTW... Even in Scheme, I have to use syntax-object->datum and it's > inverse to switch between the two. I suspect this has something to do > with the other context that must be associated with the data to turn it > into code. Probably at least the enclosing environment for lexical > scoping and the line numbers for debugging or exception handling. Does > Common Lisp maintain this information with it's macro expansions? If > so, you have a slight difference between code and data too. If not, > how do you get the line number when a problem happens in a nested > macro? > > Moreover, if you really want to be pedantic about what "is" means in > "code is data", then you have to acknowledge that data is a superset of > code, since all code is obviously data, but there are plenty of types > of data that aren't used as code. Or are they? :-) > > > >>* Taking questions after a keynote to ILC200? where he reiterated that >>Python was the same as Lisp for all intents and purposes: >> >>Norvig: "Yes, John?" >>McCarthy: "Is code also data in Python?" >>Norvig: "No." >> >>End of exchange. :) >> > > > Really? You're relying on an appeal to authority? Ok, I'm going to > start arguing by analogy then... Analogies! My favorite! When a state trooper tells me not to drive my Corvair over 55 that is argument from authority. When Ralph Nader tells me.... > > > > >>> def reverse(cls, *args): >>> # I didn't understand what your code was doing >> >>yeah, and god forbid you should ask. :) this is the crux of the matter! >> >>Actually, it is kinda cool that you and Greg are semi-identifying the >>crux by saying "this is the only bit I do not get, I'll skip this, move >>on, nothing to see here". >> > > > Ok, I'll bite. What does it do? There's been more on this elsewhere and I need to get some work done, so i am afraid from now on it will have to be analogies and arguments from authority, much faster. > I read through it, and it looks the > code you're passing to the macro does some things like calculating the > number of decimal digits and generating a 2 + a random number of that > many digits to find a divisor or something. It also looks like you > have some "string interpolation" to substitute names in your text, but > as a whole, I really don't have any clue what it's all about. > > It looks like the macro itself is building some names on the fly and > defining methods (new specializations for multimethods?) with those > names. > > So I'm sure I'm missing something, but there is almost certainly a > readable equivalent in Python (and even C). If you really want to > generate dynamic names for functions, you can do that in Python by > modifying the class or globals hash or whatever. A more standard way > might be to be have members in the base class. > > There is even a multi-methods module in Python, but I've never used it. > I'd guess you could add to that dynamically too. > > > >>>That would be a reasonable place for a "pie decorator" on a class, but >>>I guess that's not allowed. >> >>Hmmm. Actually, that is the whole point, all of Python is allowed. >>decorators were used in PyCells, but I never got much of an idea what >>they did. Is there a moral equivalent of a macroexpansion for decorators >>so you can show the before and after? >> > > > It's Python that doesn't allow you to decorate classes. (You can > decorate functions, but not classes...) I made this comment as a > criticism of Python since it seems like a non-orthogonal corner... It > would have fit in this case. > > Decorators are pretty simple: > > @foo > def bar(): pass > > is equivalent to: > > def bar(): pass > bar = foo(bar) > > The callable foo can use whatever it wants to inspect, modify, or wrap > the function bar. > > but: > > @foo > class bar: pass > > is not currently allowed, so you have to do > > class bar: pass > bar = foo(bar) > > > > >>exactly what we are looking for in this cultural exchange: how would >>Python handle what I am doing with macros in the reverse functions? Make >>it as slick and programmer-friendly (cuz I may get to a hundred of these >>before I am done with Algebra I) as possible. When all the Pythonistas >>proclaim it optimal, then we compare and contrast. >> >>This, btw, is the Tilton Test for language comparison: Not measurements >>of programmer effort, rather examination of perfect equivalent code. >>PyCells vs Cells would be an amazing case, because that is some hairy >>functionality. >> > > > That seems like a fine strategy. I fall more on the programmer effort > side. I want to write as little code as possible in a readable way > such that it meets the requirements. You misunderstood. The Tilton Test is not indifferent to programmer effort, it simply acknowledges that one cannot use it to compare languages because one cannot control for programmer ability, which varies more than language expressiveness. I am guessing (literally) that we have a better chance of objective measures comparing two community-polished code products passing the same functional tests. > > I'm not a particularly good ambassador for Python. I know Python much > better than Lisp (Scheme), but I already think Scheme is a better > language. Macros are part of that. I'm mostly playing devil's > advocate here because I don't think your example really brings it home. > I've got limited time that I'm willing to invest in learning your > algebra system, but I haven't seen (understood, if you insist) anything > yet that couldn't be done readably in Python. That is fine, this is a cultural exchange, merely disguised as a war to keep the children amused. Again, I thought the environment suggestion was promising, and reminded me that Python /does/ do some neat things in re turning references into dictionary lookups such that datanames /can/ be at least generated dynamically. > If you want Common Lisp > to win in your language battle against the Pythonistas, you're going to > need to break out with something stronger. Then again, you're probably > pissing into the wind anyway. A long, civil, technical thread contrasting Python and Lisp is not exactly a loss to humanity. Too bad Ruby could not join us. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From at at tuko.nl Wed Dec 13 17:43:41 2006 From: at at tuko.nl (at) Date: Wed, 13 Dec 2006 23:43:41 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> Message-ID: <4580821a$0$334$e4fe514c@news.xs4all.nl> Dear Carl, Well, all I can say that for me as a user it would make sense... Curiosity: in what sense is it redundant? All solution/workarounds I have seen so far involve creation of new lists (subsets) adding to more processing/computation/memory usage. Redundant suggests that you know alternatives that don't do that. Does Guido ever change his mind? Cheers, @ Carl Banks wrote: > at wrote: >> I am not looking for a work around but more interest if other people >> might judge this syntax would come in handy? > > Of course people have expressed interest in this in the past, but it's > not going to happen. There's a way to nest for and if statements, and > a different way to nest for and if clauses in listcomps, and the two > methods are considered distinct. Although Guido has said that saving > indentation levels is important, he hasn't said anything (that I'm > aware of) that suggests it's important enough to add this complexity > and redundancy to the language. Sorry. > > > Carl Banks From bearophileHUGS at lycos.com Mon Dec 18 12:24:11 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 18 Dec 2006 09:24:11 -0800 Subject: Shed Skin - Does it break any Python assumptions? In-Reply-To: References: <17798.41151.547934.689629@montanaro.dyndns.org> Message-ID: <1166462651.456236.115160@f1g2000cwa.googlegroups.com> Jean-Paul Calderone: > So yes, it seems that what ShedSkin supports is pretty distant from what > a seasoned Python developer might expect, aside from syntactic constructs. At the moment SS doesn't allow to change the type of a variable during its lifetime, but SS is a moving target, maybe in the (far) future it will split it into two variables... I'm sure Mark likes to receive practical suggestions on how to improve SS to make it closer to Python. (And I think he likes to receive patches too, but usually it's better for people to start from simpler things, like speeding up a lib written with C++, etc). Bye, bearophile From PPNTWIMBXFFC at spammotel.com Tue Dec 5 04:28:03 2006 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Tue, 05 Dec 2006 10:28:03 +0100 Subject: The del statement References: Message-ID: > do you find the x[i] syntax for calling the getitem/setitem methods a > bit awkward too? what about HTTP's use of "GET" and "POST" for most > about everything ? ;-) No. I like the x[i] syntax. I use it in every second row of my code and getting an item like: x.getitem(i) would be a viable (in this case clumsy) way but here I find the introduced syntax justified. del on the other hand is used sparingly througout my code. If no del keyword would exist, it wouldn't disturb me. Marco From konrad.hinsen at laposte.net Tue Dec 12 16:53:18 2006 From: konrad.hinsen at laposte.net (konrad.hinsen at laposte.net) Date: Tue, 12 Dec 2006 22:53:18 +0100 Subject: About alternatives to Matlab In-Reply-To: <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <17D92C85-B077-4C48-AB61-376D64C1D94C@laposte.net> On 11.12.2006, at 14:21, Jon Harrop wrote: >> It's not a matter of number, it's a matter of availability when new >> processors appear on the market. How much time passes on average >> between the availability of a new processor type and the availability >> of a native code compiler for OCaml? > > OCaml had AMD64 support before many other language. It had a better > optimiser before gcc... A concrete example of interest to me: can I get an OCaml-to-native compiler for an IBM BlueGene? The processor is in the PowerPC family, but it has some modifications, and the binary format is different from standard Linux as well. Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Centre de Biophysique Mol?culaire, CNRS Orl?ans Synchrotron Soleil - Division Exp?riences Saint Aubin - BP 48 91192 Gif sur Yvette Cedex, France Tel. +33-1 69 35 97 15 E-Mail: hinsen at cnrs-orleans.fr --------------------------------------------------------------------- From 2006 at jmunch.dk Wed Dec 20 12:25:54 2006 From: 2006 at jmunch.dk (Anders J. Munch) Date: Wed, 20 Dec 2006 18:25:54 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> Message-ID: <45897266$0$4158$ba624c82@nntp02.dk.telia.net> jayessay wrote: > Please note: GC is not part of CL's definition. It is likely not part > of any Lisp's definition (for reasons that should be obvious), and for > the same reasons likely not part of any language's definition. Really? So how do you write a portable program in CL, that is to run for unbounded lengths of time? - Anders From sjmachin at lexicon.net Thu Dec 7 13:11:36 2006 From: sjmachin at lexicon.net (John Machin) Date: 7 Dec 2006 10:11:36 -0800 Subject: Best way to split up lines - RE: About the 79 character linerecommendation In-Reply-To: References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com> <012601c719f7$9e719990$0d7d12ac@kearfott.com> Message-ID: <1165515096.287635.252360@79g2000cws.googlegroups.com> Fredrik Lundh wrote: > Michael Yanowitz wrote: > > > What would be the best way to split the following line (Python doesn't like > > me to split it up between the comma-separated parameters): > > > > top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, > > utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, > > st2, st3, st4, st5, st6, numberOfLabels, dataWord = > > struct.unpack("!H4BH20BHI", strMessage) > > data = struct.unpack("!H4BH20BHI", strMessage) > > (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, > dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, > utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, > numberOfLabels, dataWord) = data > Those utc1, ..., utc12 etc inspire a suggestion: a mild addition to the syntax to allow specifying that the following repeat count should be interpreted as the expected dimension of a tuple (unpack) or any indexable object with a __len__ method (pack): (top, ip, messageCounter, ackRequired, dataType, utc, st, numberOfLabels, dataWord, ) = struct.unpack("! H /4B H B B /12B /6B H I", strMessage) Apropos of a recent thread: I don't need pointing at the suggestion box and the patch submission gizmoid on Sourceforge -- I'd be happy to do a patch, just wondering if anybody's interested in having that, besides me and Pat Malone :-) Cheers, John From esj at harvee.org Thu Dec 7 00:17:25 2006 From: esj at harvee.org (Eric S. Johansson) Date: Thu, 07 Dec 2006 00:17:25 -0500 Subject: differences between ubuntu and fedora python Message-ID: fedora [root at lbox ~]# file /etc/postfix/transport* /etc/postfix/transport: ASCII English text /etc/postfix/transport.db: Berkeley DB (Hash, version 8, native byte-order) # python /usr/lib/python2.4/whichdb.py /etc/postfix/transport UNKNOWN /etc/postfix/transport # python /usr/lib/python2.4/whichdb.py /etc/postfix/transport.db dbhash /etc/postfix/transport.db ubuntu /etc/postfix/transport: ASCII text /etc/postfix/transport.db: Berkeley DB (Hash, version 8, native byte-order) # python /usr/lib/python2.4/whichdb.py /etc/postfix/transport dbm /etc/postfix/transport # python /usr/lib/python2.4/whichdb.py /etc/postfix/transport.db dbhash /etc/postfix/transport.db why the difference? according to the whichdb code, It looks for the .db form and should pick it up except it isn't. From adonis at REMOVETHISearthlink.net Wed Dec 20 00:32:22 2006 From: adonis at REMOVETHISearthlink.net (Adonis Vargas) Date: Wed, 20 Dec 2006 05:32:22 GMT Subject: Simplest way to do Python/Ajax with server and client on same machine? In-Reply-To: References: Message-ID: Kenneth McDonald wrote: > I'm doing some work with a Python program that works hand-in-hand with > the DOM on a local client (processing DOM events, issuing DOM > modification commands, etc.) I'm currently using cherrypy as the Python > server for this communication, and simple AJAX on the client browser > end. This works just fine, I'm simply wondering if there is a better > (even easier) way to do this, if there are libraries I'm not aware of > that I should be, etc. > > Thanks, > Ken You can try looking into PyJamas its a Python version of Google Web Toolkit, offers a way to create AJAX apps using Python code. Hope this helps. Adonis From aidan at aidans.org Thu Dec 14 18:51:42 2006 From: aidan at aidans.org (Aidan Steele) Date: Fri, 15 Dec 2006 10:51:42 +1100 Subject: Password, trust and user notification In-Reply-To: <1166138555.764383.251020@j72g2000cwa.googlegroups.com> References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> <1165917102.008439.146400@16g2000cwy.googlegroups.com> <1166053509.270409.46390@f1g2000cwa.googlegroups.com> <7.0.1.0.0.20061213210006.04005d80@yahoo.com.ar> <364538570612131644l604930b9l861b94457bc1183@mail.gmail.com> <1166138555.764383.251020@j72g2000cwa.googlegroups.com> Message-ID: <364538570612141551h3916a240k5b8f689dccadd8f1@mail.gmail.com> On 14 Dec 2006 15:22:35 -0800, placid wrote: > > > Dennis Lee Bieber wrote: > > On Thu, 14 Dec 2006 11:44:14 +1100, "Aidan Steele" > > declaimed the following in gmane.comp.python.general: > > > > > While what you said is technically correct, I think you misread their > > > original question. They want to send email *from* the Gmail account > *to* the > > > work account. I suggested that he use Gmail's SMTP server to send the > email. > > > > > The most confusing thing is that is sounds very much like they > want > > to use the /recipient's/ Gmail account to send email to the > > /recipient's/ work email account -- rather than connecting directly to > > the recipient's work account mail server. (Of course, it may be that > > their own ISP blocks pass-through SMTP -- that's a different matter) -- > > > Ok, everyone now forget that i even asked about connecting to Gmail and > sending an email back to the work email, for some reason you guys are > not answering my question. > > Is there any other way (other than email's !) to notify a user of > events within a script? > > Thanks for all the help. > Cheers > > -- > http://mail.python.org/mailman/listinfo/python-list Perhaps by using instant messaging, eg: Jabber? (http:// jabberpy.sourceforge.net/) You could create an account for the daemon/script and have it send messages to the client throughout the script's execution. Fewer security concerns in that setup! Aidan Steele. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpw3 at rpw3.org Sat Dec 9 23:27:25 2006 From: rpw3 at rpw3.org (Rob Warnock) Date: Sat, 09 Dec 2006 22:27:25 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xac1wr7t9.fsf@ruckus.brouhaha.com> Message-ID: Aahz wrote: +--------------- | Paul Rubin wrote: | >I think an editing program that balances parens automatically is near | >indispensible for writing Lisp code. I can't stand writing Lisp | >without Emacs. | | And that is why I will never write Lisp. I loathe Emacs. +--------------- An appropriate version of "Vi" is sufficient. I prefer "nvi-1.79", but have found that the "vim" at work is also adequate. Either will: 1. Flash matching parens on insert; jump back & forth between matching parens on command ("%"). 2. Deal with S-exprs as "objects" for shifting left/right, copying, deleting, or pasting. [The shifting works best when you gloablly "set sw=1" and then use "." to repeat the last shift.] 3. Minimal auto-indent, but "good enough" for my purposes [given #2]. That's pretty much all you need to code in Lisp. It's what *I* use. So "I loathe Emacs" is *NOT* a believable excuse for avoiding Lisp... -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From rtw at freenet.co.uk Tue Dec 12 16:36:05 2006 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 12 Dec 2006 15:36:05 -0600 Subject: Problem understanding how closures work References: Message-ID: Tom Plunket wrote in news:cm3un2hec05uqndvumko3je03k59k00eqp at 4ax.com in comp.lang.python: > ...at least, I think that I'm having a problem understanding the way > closures work. > > I'm trying to define a function for an object which will take certain > objects from the parent scope at the time that function is defined. > For some reason, if I do this function definition in a loop, the > locals given by that function (is this a closure?) are changed each > iteration of the loop, whereas if the function definition is isn't > looped over, I get the behavior I desire. Can anyone provide any > insight for me? > Test 1 doesn't work the way I would expect: > Test 4 says, "Test 0" > Test 4 says, "Test 4" > > def CreateTests1(count): > tests = [] > for i in xrange(count): > name = 'Test %d' % i > t = Test(name) > tests.append(t) > > def ExCall(text): > print '%s says, "%s"' % (name, text) > > t.ExternalCall = ExCall > > return tests "name" in the above code is bound to a an entry in "CreateTests1"'s locals, and ExCall has a (hidden) reference to that locals, so by the time ExCall is finally called the value associated with "name" has been replaced by (count - 1). The solution (as always) is to add another level of indirection: def create_tests( count ): def make( arg ): def ExCall( text ): print arg, text return ExCall tests = [] for i in range( count ): name = i t = Test( name ) t.ExternalCall = make( name ) In the above, every call to make() creates a new frame (a new set of locals) and binds the value of the passed in "name" to the name "arg" in this new frame, it will be this value that is eventually printed. There is a trick with default arguments that lets you do what you want with a bit less faffing about: >>> r = [] >>> for i in range(10): def f( i = i ): print i r.append( f ) >>> for i in r: i() In this example the value of "i" is bound to the default argument for the function "f" every time the def f() statments are executed. Rob. -- http://www.victim-prime.dsl.pipex.com/ From oviedo96 at gmail.com Sat Dec 2 07:30:08 2006 From: oviedo96 at gmail.com (patkinson) Date: 2 Dec 2006 04:30:08 -0800 Subject: Python, PostgreSQL, What next? In-Reply-To: <1165043076.979652.201730@16g2000cwy.googlegroups.com> References: <1165043076.979652.201730@16g2000cwy.googlegroups.com> Message-ID: <1165062608.497803.38370@f1g2000cwa.googlegroups.com> Hi, Look at DJANGO ;-) http://www.djangoproject.com/ http://www.djangobook.com/ Regards Peter Atkinson vbgunz ha escrito: > Hello all, > > I've studied Python and studied PostgreSQL. What is the absolute next > best step to take to merge these two finely together? I've heard of > SQLAlchemy and some others but before I dive in, I would really like > the opinion of those who tried it and other toolkits. > > My main concern is, I would like to completely work with a database > from Python. What would you suggest I look into? > > Thank you for your time! From martin at v.loewis.de Tue Dec 12 01:04:23 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 12 Dec 2006 07:04:23 +0100 Subject: Tarfile .bz2 In-Reply-To: <1165887178.775792.142820@80g2000cwy.googlegroups.com> References: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> <1165887178.775792.142820@80g2000cwy.googlegroups.com> Message-ID: <457E4667.5080703@v.loewis.de> Jordan schrieb: > Not really on topic anymore but what's the method for tar.gz? It works like .tar.bz2, except that it uses gzip (www.gzip.org) as the compression library. The underlying compression algorithm is LZW. > And > even more off the topic, does anyone know a good lossless compression > method for images (mainly .jpg and .png)? Well, .jpg files are already compressed in a lossy way (.jpg is inherently lossy); to compress it further, you need to increase the loss. PNG is also compressed already, see http://www.mywebsite.force9.co.uk/png/ The compression algorithm inside PNG is zlib (which is the same as the gzip algorithm). Perhaps you should read the comp.compression FAQ: http://www.faqs.org/faqs/compression-faq/ Regards, Martin From andre.roberge at gmail.com Tue Dec 26 07:55:46 2006 From: andre.roberge at gmail.com (=?iso-8859-1?B?QW5kcuk=?=) Date: 26 Dec 2006 04:55:46 -0800 Subject: How to depress the output of an external module ? In-Reply-To: References: Message-ID: <1167137746.508848.140850@a3g2000cwd.googlegroups.com> fdu.xiaojf at gmail.com wrote: > Steven D'Aprano wrote: > > Try something like this: > > > > # WARNING: untested > > def run_without_stdout(*args, **kwargs): > > function = args[0] > > args = args[1:] > > savestdout = sys.stdout > > sys.stdout = cStringIO.StringIO() > > result = None > > try: > > result = function(*args, **kwargs) > > finally: > > # don't forget to restore stdout, or you > > # really will regret it... > > sys.stdout = savestdout > > return result > > > Thanks! > > I have tried your method, but I found it didn't work as expected. > > The output produced by the external function couldn't be depressed, > but the "print " statement i wrote in python is depressed. It seems > make cStringIO.StringIO() as a temporary replacement of sys.stdout > has no effect on the external function. > > Here is an example to make myself clear(actually it's modified version > of Steven's code): > > def run_without_stdout(*args, **kwargs): > function = args[0] > args = args[1:] > savestdout = sys.stdout > sys.stdout = cStringIO.StringIO() > print "something" > result = None > try: > result = function(*args, **kwargs) > finally: > # don't forget to restore stdout, or you > # really will regret it... > sys.stdout = savestdout > print "some other thing" > return result > > When run_without_stdout() is called, the "print" statements wrote in python > don't produce output, but function() produces output to the standard output > just as before:( > > I have tried to replace sys.stdout globally with cStringIO.StringIO() > in my program(I mean, make "sys.stdout = cStringIO.StringIO()" as a > globall statement), but it worked just as previous version did. Perhaps try redirecting sys.stderr instead of sys.stdout. Andr? > > Regards, > > xiaojf From basti.wiesner at gmx.net Thu Dec 21 07:07:48 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Thu, 21 Dec 2006 13:07:48 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Fredrik Lundh schrieb > Sebastian 'lunar' Wiesner wrote: > >>>>> no, I'm showing that a local file marked as executable overrides a >>>>> shared one, even if the local file isn't actually an executable. > >>> >>>> Only if you have your system set up badly. The current directory >>>> should not be in the search path, and it especially shouldn't have >>>> higher priority than the regular bin locations. > >> >>> and the award for completely missing the context of this subthread >>> goes to... >> >> Nevertheless his comment was absolutely correct... > > nope. a Unix system uses the same flag to determine if a file is > executable no matter how I've set up my path. Paul didn't even mention the word "executable". He was referring to completely different thing: The fact, that whether a local executable overrides a shared on, is matter of how you set your PATH. The local file would be executable, whether it is in the PATH or not... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From keshlam-nospam at comcast.net Sat Dec 23 21:08:00 2006 From: keshlam-nospam at comcast.net (Joe Kesselman) Date: Sat, 23 Dec 2006 21:08:00 -0500 Subject: regular expression In-Reply-To: <1233C373-AECC-411C-BDEC-39F55F830E0C@microsoft.com> References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> <22Gih.18093$Ca.6266@read2.cgocable.net> <1233C373-AECC-411C-BDEC-39F55F830E0C@microsoft.com> Message-ID: Reminder: anything crossposted across this many newsgroups, especially asking an inherently bogus question, is probably just trolling. If it's equally on topic everywhere, that means it's on topic nowhere. -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry From tleeuwenburg at gmail.com Mon Dec 18 00:21:16 2006 From: tleeuwenburg at gmail.com (tleeuwenburg at gmail.com) Date: 17 Dec 2006 21:21:16 -0800 Subject: trees In-Reply-To: <3fjhh.34587$wP1.7292@newssvr14.news.prodigy.net> References: <3fjhh.34587$wP1.7292@newssvr14.news.prodigy.net> Message-ID: <1166419276.552627.85030@f1g2000cwa.googlegroups.com> You could use ElementTree for XML. Or just use nested dictionaries. -T John Nagle wrote: > Delaney, Timothy (Tim) wrote: > > vertigo wrote: > > > > > >>Hello > >> > >>What library/functions/classes could i use to create trees ? > > SpeedTree, of course. > > http://www.speedtree.com > > They have great downloadable demos. > > John Nagle From brian at brianshirk.com Wed Dec 20 01:25:36 2006 From: brian at brianshirk.com (brian at brianshirk.com) Date: Tue, 19 Dec 2006 22:25:36 -0800 Subject: Working with unsigned/signed types Message-ID: <20061220062956.AF0811E4006@bag.python.org> That seems like it'll do the trick quite well. As far as the future generations go, there's no question as to whether it would last if it were on my site - there are always changes being made to it and I'm not expecting it to be very stable over the course of time, especially since it would confuse the heck out of a bride trying to find her pictures if she stumbled on it... Is there a repository of some sort available for this sort of thing anywhere? Thanks! -Brian On Tue Dec 19 22:07 , Ben Finney sent: >brian at brianshirk.com> writes: > >> The first part of the question is fairly basic - in C, working with >> signed integers, the MSB (is that still the right term?) is used to >> denote positive and negative, and the following bits increase >> towards positive infinity, correct? Such that in C, adding one to >> 0x7fffffff would cause the number to go around to -0x7fffffff (or >> whatever that is), giving -1 for 0xffffffff? >> >> Secondly, (and this is my weak point as a programmer) to re-insert >> the data after, what would be the most efficient way to pull >> everything back apart into individual characters for putting it all >> back into the files? I could probably figure out something that >> would work, but I wouldn't be so sure as to its reliability. > >I think, from the above, that you want to read about the 'struct' >module in the standard library. > > http://docs.python.org/lib/module-struct.html> > >> Third, being a photographer now rather than a coder, I'd like to >> give back the modules I'm writing to the community (it looks like >> very little of the sort exists), but would rather not worry about >> them in the future... Is there a good way to go about this? > >Ideally, find someone who will actively maintain the code into the >foreseeable future; maybe a user of the code with more interest in >programming than you. > >Failing that, find a place to put it online for the foreseeable >future, and notify repositories like Freshmeat >http://freshmeat.net/> of its existence and location. > >The most important thing to do is to explicitly license the rights to >modify and redistribute freely for all people who receive the code, so >they never have to try to track you down for permission. > >Choose a permissive license like the Expat license >http://www.jclark.com/xml/copying.txt> if you want to allow >people to do just about anything except claim you didn't write it; >choose a copyleft like the GNU General Public License >http://www.gnu.org/copyleft/gpl.html> if you want to ensure >nobody can redistribute under more restrictive terms in future. > >Make each file clearly marked so that the grant of license is clear, >and include the text of the license terms in an obvious file in the >source code package. See the addendum of the GNU GPL for how this is >best done, even if you end up not choosing that particular license. > >Thanks for thinking of the future hackers :-) > >-- > \ "...one of the main causes of the fall of the Roman Empire was | > `\ that, lacking zero, they had no way to indicate successful | >_o__) termination of their C programs." -- Robert Firth | >Ben Finney > >-- >http://mail.python.org/mailman/listinfo/python-list > From arkanes at gmail.com Tue Dec 19 09:15:18 2006 From: arkanes at gmail.com (Chris Mellon) Date: Tue, 19 Dec 2006 08:15:18 -0600 Subject: Good Looking UI for a stand alone application In-Reply-To: <1hql1xl.oz7gsvwz9w1qN%luc@honk-honk.com> References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> <1hql1xl.oz7gsvwz9w1qN%luc@honk-honk.com> Message-ID: <4866bea60612190615q1a6344e6k3315d606f1a47f1d@mail.gmail.com> > Ok, now here's a question for you: if crossplatform toolkits/frameworks > are sooooo great and automagically allow to produce superlickable and > native-looking/feeling applications on all three major platforms, why is > there so few of those applications on OS X ? > > "Because Mac users are elitists assholes" is not the good answer by the > way :) > You've got a ridiculous straw man here. Nobody has ever said that they do this, and nobody with any experience would. I don't actually think you're interested in what is possible and what isn't, and I don't even think that you actually evaluate the screenshots in a context where it's possible for you to have any other opinion. wx is the only popular toolkit of it's kind - it's a wrapper toolkit, that uses actual native controls, not just ones designed to look like them. For many wxPython/wxWidgets applications, there is *no difference* between an app written directly to cocoa and a wxwidgets app besides the API the author used. None, zero, zilch. Any "feel" issues you claim to be present are solely because the author either didn't know about or didn't care about a convention on the mac platform. The only other major cross platform toolkit with good mac support is Qt, and I don't follow it's development closely. It may also use native controls, at least in some cases, or it may still render everything via the presentation manager, but regardless it's got a lot of work and again, in most cases, it's hard if not impossible to tell the difference between a "native" app and a qt one. I'm not a qt expert so I won't spend too much energy defending it. The look is easiest, of course. There's more to the look than just that, of course, there's things like the stock behavior of controls. wxPython gets that mostly for free, because it's using actual native controls. There's things like the button order and layout, and wx provides APIs to address that. Not everyone uses them, which is too bad. There's some standard platform conventions like where your menu items go. wx provides support for that. There's the fairly minor issues of making sure your layout works with differently sized controls and text, the wx layout mechanism addresses that. Finally, there's some poorly defined "mac style" issues. wx, and no toolkit, not even the native one, can address that. Many cross platform apps are written on Windows with windows users in mind and use windows assumptions, like that it's fine for a context menu to be the only way to interact with something. This category is where almost all complaints against cross platform apps fall, and it's ridiculous because it's not something that a toolkit can address. You can, and people do, write exactly the same sort of interface into mac native applications. FinkCommander is a good example. There's a few more caveats I haven't addressed, and there are places where wx isn't perfect. In wxPython, there are quite a few commonly used controls that are custom controls hand-designed in Python, and don't wrap native controls, so that can be a problem. It's not a panacea, and anyone who sells it as such is wrong. But it doesn't "suck", either. And it's a lot easier than maintaining multiple GUI codebases, especially for platforms that don't see as much use. Why are there so few applications? The real answer is probably that the mac developer community is smaller than either the windows or linux dev community, and people who develop for the mac tend not to care about any other platform. So most of the crossover comes from the other direction, and the mac community, being elitist assholes, makes scathing comments about how it assumes you have 2 mouse buttons. FYI: OS X ships with wxWidgets installed. How many applications built into OS X are built using it? Are you sure? How would you know? From sjmachin at lexicon.net Tue Dec 26 16:08:34 2006 From: sjmachin at lexicon.net (John Machin) Date: 26 Dec 2006 13:08:34 -0800 Subject: Fuzzy string comparison References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> Message-ID: <1167167314.463288.98960@48g2000cwx.googlegroups.com> Wojciech Mula wrote: > Steve Bergman wrote: > > I'm looking for a module to do fuzzy comparison of strings. [...] > > Check module difflib, it returns difference between two sequences. and it's intended for comparing text files, and is relatively slow. Google "python levenshtein". You'll probably find this a better fit for typoed keys in a database. What I would do for a quick start on this exercise (as described) is: To compare two strings, take copies, and: 1. strip out all spaces (including \xA0 i.e.   if the data has been anywhere near the web) from each string; also all "-" (in general strip frequently occurring meaningless punctuation) 2. remove leading zeroes from each string 3. d = levenshtein_distance(string_a, string_b) # string_a etc is the reduced string, not the original 4. error_metric = float(d) / max(len(string_a), len(string_b)) The error_metric will be 0.0 if the strings are the same (after removing spaces, leading zeroes, etc) and 1.0 if they are completely different (no characters in common). ... and you don't want anything "kind of like soundex". That's a bit like saying you'd like to travel in an aeroplane "kind of like the Wright brothers' " ;-) Cheers, John From python at hope.cz Mon Dec 18 10:12:22 2006 From: python at hope.cz (Lad) Date: 18 Dec 2006 07:12:22 -0800 Subject: How to replace a comma In-Reply-To: References: <1166446034.406136.225770@80g2000cwy.googlegroups.com> Message-ID: <1166454742.875876.263190@73g2000cwn.googlegroups.com> Thank you for ALL for help. Hendrik, your solution works great but what is `_` in _.replace(',',', ') for? Thank you La. > re's are a pain. Do this instead: > > >>> s = "hello, goodbye,boo" > >>> s.replace(', ',',') > 'hello,goodbye,boo' > >>> _.replace(',',', ') > 'hello, goodbye, boo' > >>> > > Hope this helps - Hendrik From pyenos at pyenos.org Wed Dec 27 18:19:27 2006 From: pyenos at pyenos.org (Pyenos) Date: 28 Dec 2006 10:19:27 +1100 Subject: failing to instantiate an inner class because of order of inner classes References: <87wt4dos3i.fsf@pyenos.pyenos.org> <1167261247.982957.308820@a3g2000cwd.googlegroups.com> Message-ID: <87bqlp6i68.fsf@pyenos.pyenos.org> "Edward Kozlowski" writes: > Pyenos wrote: > > class model:pass > > class view: > > model() > > class controller: > > model() > > > > I can instantiate clsss model from inside class view but I can't > > instantiate class model from inside controller, due to the nature of > > python interpreter. > > > > I wish to circumvent this restriction by: > > > > class model:pass > > class view: > > parent_class.model() > > class controller: > > parent_class.model() > > > > but, I don't know the built-in variable that points to the parent > > class. Could someone tell me how can I instantiate class model from > > inside controller AND instantiate class model from inside view? > > I would try the following: > > class model: > def printFoo(self): > print "foo" > class view: > def __init__(self): > self.model = model() > class controller: > def __init__(self): > self.model = model() > > Then you can do: > vObj = view() > vObj.model.printFoo() > > And: > cObj = controller() > cObj.model.printFoo() I've made an error in the original article that you have quoted here but I have cancelled it. However, I have understood your solution and I think it is helpful. Thank you. From raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com Sun Dec 17 13:39:52 2006 From: raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com (Raffael Cavallaro) Date: Sun, 17 Dec 2006 13:39:52 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45844272$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <2006121614375650878-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45853e98$0$8712$ed2619ec@ptn-nntp-reader02.plus.net> <2006121711381343042-raffaelcavallaro@pasdespamsilvousplaitmaccom> <458583cd$0$8715$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <2006121713395278840-raffaelcavallaro@pasdespamsilvousplaitmaccom> On 2006-12-17 12:49:46 -0500, Jon Harrop said: > For example, when faced with a problem best solved using pattern matching > in Lisp, most Lisp programmers would reinvent an ad-hoc, informally > specified and bug-ridden pattern matcher of their own. No, I think most of us would use an exising lisp pattern matcher, like cl-unification. > >> By asking this question you've implicitly admitted that to solve it *as >> he thought of it* in a pure functional language would require >> reconceptualizing it (i.e., the aforementioned "jumping through >> hoops"). > > You are saying that solving it as he solved it requires a different > solution. How does that make Lisp any different to the next language? Give kenny some credit for not being a complete idiot. Cells was originally designed to keep UI elements in sync with an internal application model. The UI domain is I/O, i.e., a side effect. To do this lazily invites situations where an inherently unpredictable user action forces a complex series of constraints to be computed before anything can be displayed to the user, so the user must wait while the lazy system catches up. To do this eagerly means that at any time, any unpredictable user action will cause already computed state to be displayed, because everything has been kept up to date automatically all along. I'm saying that he conceived of the problem in the most natural way - state with mutations - and implemented it that way. He was not forced by his language to reconceive it purely functionally, have haskell implement the default lazy semantics, only to require the programmer to find an escape hatch from this default laziness since what he really wants is eager evaluation of side effects (i.e., I/O - syncing of model state with GUI display). People habitually think of the world as state and mutations of state. We've been doing so for a minimum of tens of thousands of years, quite possibly a million or more. People are good at thinking about mutation. Maybe this should tell us something about the desirability of certain programming language semantics and that referential transparency is a bit overrated. > >> We don't want to reconceptualize everything according to a particular >> paradigm, we want the flexibility to write the solution to >> the problem in the terms we think and talk about it, not the >> procrustean bed of pure functional semantics. > > Of the programming paradigms that can be implemented in Lisp, Lisp doesn't > exactly make them easy. Moreover, every time you pick a random Lisp library > off the wall to implement some feature already found in most other > languages, you fragment the already tiny user base into even fewer people. Not all lisp programmers will be solving the same sorts of problems as each other, so naturally they'll be using different sets of libraries. This use of different sets of libraries for different tasks doesn't constitute laguage fragmentation. From slawomir.nowaczyk.847 at student.lu.se Sun Dec 17 18:46:58 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Mon, 18 Dec 2006 00:46:58 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: Message-ID: <20061218003626.3DDE.SLAWOMIR.NOWACZYK.847@student.lu.se> On Sat, 16 Dec 2006 14:05:06 -0500 Kirk Sluder wrote: #> And there is something that is missing here in arguing about computer #> language notations in relationship to human language readability, or #> correspondence to spoken language. I'm not writing code for another #> human, I'm writing code for a machine. Often, the optimum expression #> of an mathematical concept for a machine is relatively baroque #> compared to the optimum expression for a human being. Well, the memorable quote from "Structure and Interpretation of Computer Programs" states that "Programs should be written for people to read, and only incidentally for machines to execute." -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) If at first you do succeed, try not to look astonished. From zhzhao at cisco.com Fri Dec 29 12:35:34 2006 From: zhzhao at cisco.com (Jenny Zhao (zhzhao)) Date: Fri, 29 Dec 2006 09:35:34 -0800 Subject: Looking for python SIP/MGCP stacks Message-ID: <1ECA23B17E8AB54C859FA0449B729F0E034284DA@xmb-sjc-235.amer.cisco.com> Hi Python users, I am using python to write a testing tools, currently this tool only supports skinny protocol. I am planning to add SIP and MGCP support as well, wondering if you have written these protocol stacks before which can be leveraged from. thanks Jenny -------------- next part -------------- An HTML attachment was scrubbed... URL: From Yue.Nicholas at gmail.com Tue Dec 19 05:52:11 2006 From: Yue.Nicholas at gmail.com (Yue.Nicholas at gmail.com) Date: 19 Dec 2006 02:52:11 -0800 Subject: Class constant for extension Message-ID: <1166525531.028424.15010@t46g2000cwa.googlegroups.com> Hi, I have written a small prototype Python extension for a C-library. I have the methods all sorted out and it is working fine. In the C-library, they are various constants of types like string, integer, float and matrix. I'd like to expose them as READONLY values. Is the use of PyMemberDefs a suitable way to provide such access? I'd like the user of the extension to be able to do something like the follow import MyExtension MyExtension.begin() mv = MyExtension.minValue MyExtension.process(MyExtension.versionStr) MyExtension.end() Is someone able to point me to an example code of how I can write my extension so that the references to those constants can be used in the above way. Regards From chris.cavalaria at free.fr Mon Dec 11 12:35:58 2006 From: chris.cavalaria at free.fr (Christophe) Date: Mon, 11 Dec 2006 18:35:58 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> Message-ID: <457d970b$0$31552$426a74cc@news.free.fr> Andr? Thieme a ?crit : > You don't even need to say 'function > (memoize function) would be enough. > And yes, you can memoize functions while the program is running. > And you don't need a tool like slime for it. Lisp already offers ways > for doing that. In Python while the program is running : import module module.function = memoize(module.function) From tolchz at gmail.com Wed Dec 20 22:48:51 2006 From: tolchz at gmail.com (Todd Neal) Date: 20 Dec 2006 19:48:51 -0800 Subject: list1.append(list2) returns None References: <87mz5hexf7.fsf@pyenos.pyenos.org> Message-ID: <1166672931.481388.121730@f1g2000cwa.googlegroups.com> Pyenos wrote: > def enlargetable(table,col): > return table.append(col) > > def removecolfromtable(table,col): > return table.remove(col) > > print enlargetable([[1],[2],[3]],[4]) # returns None > > Why does it return None instead of [[1],[2],[3],[4]] which I expected? append modifies the list and then returns None: >>> print a [1, 2, 3] >>> print a.append(4) None >>> print a [1, 2, 3, 4] The reasoning given at http://www.python.org/doc/faq/general.html#why-doesn-t-list-sort-return-the-sorted-list is so you wont do something like this: a = [1,2,3] b = a.append(4) and assume that a is still [1,2,3] More discussion on this topic is available at http://groups.google.com/group/comp.lang.python/browse_thread/thread/8ab2e67550123b92 Todd From maksim.kasimov at gmail.com Wed Dec 13 12:14:49 2006 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Wed, 13 Dec 2006 19:14:49 +0200 Subject: How to manage two (different) sockets without using threads? In-Reply-To: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> References: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> Message-ID: Hi, i don't know how to do it with asyncore/asynchat, but it is possible to handle different sockets in one process by using "select" standard module: for_reading, for_writing, where_errors =\ select.select( ( ), ( ), (), 0) you can find all necessary information in python documentation: http://www.python.org/doc/2.4/lib/module-select.html btw: "asyncore" use "select" for socket handling, take a look in asyncore.py hope it helps billie wrote: > Hi all. > I'm (re)writing an FTP server application by using asyncore/asynchat > modules. > FTP tipically got two different channels: command and data. > I'm succesfully managing command channel through asynchat framework, > but I'm not sure about how to manage data channel without using a > thread/subprocess. > Is there an optimal to do that? > Can anyone point me in the right direction? > -- Maksim Kasimov From bytter at gmail.com Mon Dec 4 12:48:18 2006 From: bytter at gmail.com (Hugo Ferreira) Date: Mon, 4 Dec 2006 17:48:18 +0000 Subject: Best way for inter-process communication in Python In-Reply-To: <4e8efcf50612040924lad6916fi188feef885cd0822@mail.gmail.com> References: <4e8efcf50612040924lad6916fi188feef885cd0822@mail.gmail.com> Message-ID: <4e8efcf50612040948p2c6f911dg14cecff327707539@mail.gmail.com> There is another option that I thought while writing this... I can use the database for data communication. Like having a table with both in and out parameters. On the client-side, I fill the in parameters columns. Then I signal the external application which reads the parameters, and write the output. Which raises me the following question... How do I signal a python application under windows? (Is it possible to send something like a SIGHUP?) Cheers! On 12/4/06, Hugo Ferreira wrote: > Hi everyone! > > Here's the current scenario: I have a program in Python that computes > something very fast (<1s), but it takes a considerable amount of time > to read the startup data (>90s). Since the startup data is pretty > static, I want this program to be resident and ready in memory all the > time. > > The client-side of this program is a function in PostgreSQL. For the > sake of simplicity, let's assume it is another program in Python that > will be asking the resident one for results on-demand. Let's also > assume that there will be dozens of concurrent requests. > > My problem is: what is the fastest, easiest way to accomplish this > inter-process communication? The data between them will be very small: > 1Kb max per request. I've thought about SOAP, sockets and named > pipes... But since I have no experience on any of them using Python, I > can't decide which way is better... > > Just a few considerations: Python version is 2.4. PostgreSQL version > is 8.2RC1, OS version is Windows Server 2003. > > Thanks in advance, > > Hugo Ferreira > > -- > GPG Fingerprint: B0D7 1249 447D F5BB 22C5 5B9B 078C 2615 504B 7B85 > -- GPG Fingerprint: B0D7 1249 447D F5BB 22C5 5B9B 078C 2615 504B 7B85 From http Mon Dec 11 08:28:43 2006 From: http (Paul Rubin) Date: 11 Dec 2006 05:28:43 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> <457c42a3$0$49196$14726298@news.sunsite.dk> <7xodqbpqun.fsf@ruckus.brouhaha.com> <457c92c7$0$49195$14726298@news.sunsite.dk> <7x1wn7vx5b.fsf@ruckus.brouhaha.com> <457d3cdc$0$49205$14726298@news.sunsite.dk> <7xodqa7hpf.fsf@ruckus.brouhaha.com> <457d5645$0$49208$14726298@news.sunsite.dk> <7xhcw2r2dj.fsf@ruckus.brouhaha.com> Message-ID: <7xlkled0j8.fsf@ruckus.brouhaha.com> Paul Rubin writes: > (defun sum_to_n (n &optional (acc 0)) > ;; (sum_to_n n) computes sum of integers from 0 to n > (if (= n 0) > 0 > (sum_to_n (- 1 n) (+ n acc)))) Of course meant: (defun sum_to_n (n &optional (acc 0)) ;; (sum_to_n n) computes sum of integers from 0 to n (if (= n 0) acc (sum_to_n (- 1 n) (+ n acc)))) I've made that same error several times in Haskell as well. I'm not used to this. From claird at lairds.us Sun Dec 24 11:15:02 2006 From: claird at lairds.us (Cameron Laird) Date: Sun, 24 Dec 2006 16:15:02 +0000 Subject: problem with PIPE References: Message-ID: <6ll264-3gj.ln1@lairds.us> In article , Felix Benner wrote: >Dhika Cikul schrieb: >> Hello, >> >> I'm new in Python, i don't know my subject is correct or wrong. I have >> problem with my script. I want to change password with passwd password >> in python without user submitted anything from keyboard. I get . [other issues I don't choose to address now] . . >I guess the passwd program doesn't allow changing passwords from a pipe >since it is a potential security hole. This is exactly the domain Pexpect addresses . From bugs at almad.net Thu Dec 14 05:04:47 2006 From: bugs at almad.net (Almad) Date: 14 Dec 2006 02:04:47 -0800 Subject: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__ In-Reply-To: <1165948261.745137.88540@j72g2000cwa.googlegroups.com> References: <1165948261.745137.88540@j72g2000cwa.googlegroups.com> Message-ID: <1166090687.196122.229950@n67g2000cwd.googlegroups.com> Thanks to everybody for replies, I'm now satisfied ^_^ Almad From fredrik at pythonware.com Tue Dec 5 10:55:42 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 16:55:42 +0100 Subject: global name 'self' is not defined In-Reply-To: <1165314421.354880.74380@j72g2000cwa.googlegroups.com> References: <1165084948.125632.121260@79g2000cws.googlegroups.com> <1165087301.512807.289200@16g2000cwy.googlegroups.com> <4teiqfF13krd9U1@mid.individual.net> <1165235129.405963.73860@73g2000cwn.googlegroups.com> <1165314421.354880.74380@j72g2000cwa.googlegroups.com> Message-ID: Evan wrote: > A few questions: Why does python use the double underscore (__main__ or > if __name__)? I've only been using python for about 3 weeks, and I see > this syntax a lot, but haven't found an explanation for it so far? to quote the language reference, "System-defined names. These names are defined by the interpreter and its implementation (including the standard library)". see: http://effbot.org/pyref/reserved-identifier-classes From aidan at aidans.org Wed Dec 13 20:17:21 2006 From: aidan at aidans.org (Aidan Steele) Date: Thu, 14 Dec 2006 12:17:21 +1100 Subject: Password, trust and user notification In-Reply-To: <7.0.1.0.0.20061213220018.03fb7bf8@yahoo.com.ar> References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> <1165917102.008439.146400@16g2000cwy.googlegroups.com> <1166053509.270409.46390@f1g2000cwa.googlegroups.com> <7.0.1.0.0.20061213210006.04005d80@yahoo.com.ar> <364538570612131644l604930b9l861b94457bc1183@mail.gmail.com> <7.0.1.0.0.20061213220018.03fb7bf8@yahoo.com.ar> Message-ID: <364538570612131717x621d0b00m8a3491bd8d3ec1c7@mail.gmail.com> On 12/14/06, Gabriel Genellina wrote: > > At Wednesday 13/12/2006 21:44, Aidan Steele wrote: > > >While what you said is technically correct, I think you misread > >their original question. They want to send email *from* the Gmail > >account *to* the work account. I suggested that he use Gmail's SMTP > >server to send the email. > > They were concerned about putting sensitive information (password) > inside the script, in order to connect to Gmail to send the mail > notifications. > I say that there is no need to use Gmail smtp services: to send mail > *to* anyone at anywhere.com, you only have to connect to the right SMTP > server for anywhere.com. The *from* email address is irrelevant and > can even be faked. > Of course a spam filter could block such mails, but you have to test it. > > > -- > Gabriel Genellina > Softlab SRL > > __________________________________________________ > Correo Yahoo! > Espacio para todos tus mensajes, antivirus y antispam ?gratis! > ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar Rather than "could block such mails" [sic], I'm fairly certain any respectable server would drop the mail. The prevalence of SPF and other assorted tools combat this, when used for malicious purposes. Sure, it's worth trying, but I doubt it will work. Good luck to them. ;-) Aidan Steele. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bbrown at speakeasy.net Tue Dec 12 00:12:13 2006 From: bbrown at speakeasy.net (Robert Brown) Date: Tue, 12 Dec 2006 00:12:13 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> Message-ID: greg writes: > From another angle, think about what a hypothetical Python-to-Lisp > translator would have to do. It couldn't just translate "a + b" into > "(+ a b)". It would have to be something like "(*python-add* a b)" where > *python-add* is some support function doing all the dynamic dispatching > that the Python interpreter would have done. Luckily, Willem Broekema has written a Python to Lisp compiler called clpython that can be consulted to answer questions like these. http://trac.common-lisp.net/clpython/ It turns out that addition is fairly straightforward. Attribute lookup, however, turns out to be complex, as is comparing objects. Here is Willem's description of the attribute lookup algorithm from the file doc/pres.txt: To look up person.name (the "name" attribute of object "person") a. if the class of "person" (say, Person), or one of Person's base classes (say, Animal) defines __getattribute__, that will intercept all attribute lookups. Call: Animal.__getattribute__(person, name) b. look in instance dictionary: val = person.__dict__["name"] - but if it has fixed slots: look in person.__slots__ and give error if "name" is not one of the fixed slots - unless "__dict__" is specified as one of the fixed slots: in that case, don't give an error if it is not one of the fixed slots, but search in the instance dictionary too c. look in the classes Person, Animal for an attribute called "name" - if it is a `descriptor', call its __get__ method - else, if it is a method, make it a bound method - else, return it unchanged d. if nothing found so far: look for __getattr__ method in the classes, and call it: C.__getattr__(person, "name") From Tonicopm at yahoo.com Fri Dec 1 19:16:17 2006 From: Tonicopm at yahoo.com (Tonico) Date: 1 Dec 2006 16:16:17 -0800 Subject: Take the $million challenge: Prove 911 conspriracy theorists are wrong In-Reply-To: <1165017973.094742.244340@73g2000cwn.googlegroups.com> References: <1165000252.255347.178950@73g2000cwn.googlegroups.com> <4570b9f9.1242604751@read.news.uk.uu.net> <1165017973.094742.244340@73g2000cwn.googlegroups.com> Message-ID: <1165018577.645390.268830@79g2000cws.googlegroups.com> st911 at rock.com wrote: > Do you mean to say that the dimension to pursue truth and freedom from > deception lack for people using TeX? or they must not be informed of > it? **************************************************************************** What kind of "dimension" is needed to pursue truths and freedom from deception stuff? Anyway, it is not lack of that: this is a maths group. That's all. Can you understand that or will there be need to spell it for you? Tonio From jstroud at mbi.ucla.edu Sun Dec 10 07:42:44 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 10 Dec 2006 12:42:44 GMT Subject: oo problem In-Reply-To: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> Message-ID: <8hTeh.3185$Gr2.1738@newssvr21.news.prodigy.net> Tool69 wrote: > Hi, > I've got a simple but difficult problem : > > Suppose I've got a Paper class, on wich I can draw i.e a rectangle, a > circle or whatever. > > class Paper(...): > def __init__(self, paperx, papery): > self.paperx = paperx > self.papery = papery > .... > def draw(self, Primitive_Object): > .... > class Rectangle( ): <--- a Primitive_Object > ... > > Now, inside my Rectangle class, I need to recover the Paper instance > who called it (because I need the paper sizes to calculate something). > I now I can use a global variable, say " _paper" and then, inside my > Paper.__init__() write something like this : > > global _paper > _paper = [paperx,papery] > > But it has drawbacks : what if I've got several Paper instances ? > > I don't know if I'm clear enought, > Thanks for your help : > 6TooL9 > I think you may not be thinking about your problem in the most object-oriented way. For example, the Paper.draw() method will already have a reference to the "calling" Paper instance accessible via the name "self". E.g.: class Paper(... def draw(self, primitive): do_something_with(self.paperx, self.papery) # etc Now, if the draw() method were in the primitive and not the paper, then a reference to the paper should be kept in the primitive. But, as you will see below, this seems to make little sense (to me, at least). If you find that you need to access the primitive's "parent" paper attributes from within the primitive, then you might want to check whether you have structured your code in the most sensible manner. Conceptually, children shouldn't be overly concerned with the workings of their parents, lest they be a bit too presumptuous and risk a good scolding. The thought process I always go through is "why does this object need to have this particular reference?" Do primitives really need to know anything about the paper on which they are drawn? I try not to make objects overly reflexive. For example, should a primitive really be drawing itself? Perhaps something else should bring a primitive into existence based on the attributes contained in a primitive's data structure and the properties of the medium in which or on which it will exist. What if some creator had asked of you: "Embed Thyself unto the 3-D Manifold Known as the Universe." Your first requirement before any steps toward physical existence would, of course, be a reference to the Universe--so that you could see if you would actually fit. Perhaps it would be better for a 3rd party to manage the process of person creation, like, say, a mother? Children would then not be required to ponder the extent of the Universe before their own physical manifestation and could focus on things more meaningful to themselves, like whether they are hungry or need to go potty. By this thought process, I propose that it makes more sense to create a Drawing object that has references to both the primitives and the paper and then manage drawing through that object. class Drawing(object): def __init__(self, paper, primitives): self._paper = paper self._primitives = primitives my_primitives = [Square(5), Circle(10), DoubleEndedArrow(5,5,5,1,2,1,2)] my_paper = Paper() my_drawing = Drawing(my_paper, my_primitives) Now the paper can just worry about its paper specific attributes (which might be its dimensions, border, bond weight, etc), the primitives can worry about primitive specific attributes (size, line-width, fill-color), and the drawing can manage everything required to make a drawing (paper, primitives, color model, etc.). I think that this is the what you were getting at with your global "_paper" variable, except now "global" is the context of the Drawing class. James From gagsl-py at yahoo.com.ar Mon Dec 11 19:07:27 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 21:07:27 -0300 Subject: enable pop3 for gmail from python In-Reply-To: <339657.28073.qm@web39106.mail.mud.yahoo.com> References: <339657.28073.qm@web39106.mail.mud.yahoo.com> Message-ID: <7.0.1.0.0.20061211210550.0379a158@yahoo.com.ar> At Sunday 10/12/2006 08:36, radu voicilas wrote: >Hi!I am making a script to connect to my gmail box and grep new >mails.I want to know if i can enable pop from python if it is not >enabled from gmail?I have been searching the python list but i >haven't found an answer to this....only ways of connecting to the >server wich i already know. >Thank you very much! Have you read http://gmail.google.com/support/bin/answer.py?answer=10350 ? Using poplib you can connect to the gmail pop3 server - what's your problem? -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From luxnoctis at gmail.com Thu Dec 28 22:27:46 2006 From: luxnoctis at gmail.com (luxnoctis at gmail.com) Date: 28 Dec 2006 19:27:46 -0800 Subject: A stupid question Message-ID: <1167362866.807346.73510@73g2000cwn.googlegroups.com> Hello all. Let me say first that I have no idea what python is or what it does. I bought a floor model computer, and it came with all sorts of ridiculousness on it that I promptly uninstalled. However, now whenever I start windows I get a message saying "LoadLibrary (pythondll ) failed." It also says this when I try to download into a bittorrent client, and it keeps it from downloading. What does this mean, and how can I make it go away? Thanks for any help, and sorry for the dumb question! From john.thingstad at chello.no Sat Dec 16 22:14:51 2006 From: john.thingstad at chello.no (John Thingstad) Date: Sun, 17 Dec 2006 04:14:51 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 17 Dec 2006 00:19:40 +0100, > wrote: > > Incorrect, I believe. The above is like saying Lisp's lack of > optional manual storage allocation and machine pointers makes Lisp > less powerful. It's in fact the absence of those features that lets > garbage collection work reliably. Reliable GC gets rid of a large and > important class of program errors and makes possible programming in a > style that relies on it. Truth with modifications. The foreign function library of most systems does allow manual storage. If it didn't it would go into conniptions when talking to C where stored values are never moved. > You can make languages more powerful by > removing features as well as by adding them. This is what Haskell > does, with its functional purity. Haskell's lazy evaluation semantics > pretty much depend on the purity. > Some people like it some people don't. (I should add I have never put serious effort into learning Haskell so my opinion should be taken with a grain of salt.) Like many lispers I use multiple paradigms. I have similar problems with SmallTalk by the way. > See also SPJ's papers on composable memory transactions in Haskell: > > http://research.microsoft.com/~simonpj/papers/stm/index.htm > > These transactions rely on Haskell's pure functional semantics and if > I understand correctly, can't be implemented reliably without it. And > just like GC gets rid of a large class of pointer and storage > allocation errors, composable transactions in concurrent programs get > rid of lock-related errors, traditionally a huge source of problems in > real-world code. These days modern CPU's have multiple cores. Parallelism is obviously easier to accomplish with a functional style so I might take a closer look in the near future. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From johnjsal at NOSPAMgmail.com Fri Dec 1 13:14:41 2006 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Fri, 01 Dec 2006 13:14:41 -0500 Subject: v2.3, 2.4, and 2.5's GUI is slow for me In-Reply-To: References: Message-ID: <457070f4$0$17829$c3e8da3@news.astraweb.com> g4rlik wrote: > I've been asking all over the place, namely different forums. I even > e-mailed help at python.org about my problem, but they couldn't assist me too > much. > > My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run very > sluggishly. When I type in them or move them around my desktop, it's very > slow. I have figured out that this is because of the subprocesses running. I don't use IDLE too much anymore, just for quick tests, but I noticed this from the beginning as well. It's sluggish when you drag it around the screen. Not sure why. From tleeuwenburg at gmail.com Thu Dec 21 22:28:30 2006 From: tleeuwenburg at gmail.com (tleeuwenburg at gmail.com) Date: 21 Dec 2006 19:28:30 -0800 Subject: I am taking a programming performance match! In-Reply-To: <1166757615.692080.96660@n67g2000cwd.googlegroups.com> References: <1166757615.692080.96660@n67g2000cwd.googlegroups.com> Message-ID: <1166758110.739740.185630@48g2000cwx.googlegroups.com> I'm sure it could do the job, but if the sole function is to be an IO relay, I would use a lower level language like C. Cheers, -T ??? wrote: > Hi all, > > The question is like this: > > ========================= > > One computer, 2 ethernet adapter. Receving UDP packages and send them > out throught another adapter. > > The one who's program could support the heavies traffic could win a > little bonus. > > ========================= > > I am considerring trying twited. Is it suitable for this kind of job? From spamless at nospam.com Fri Dec 1 23:01:01 2006 From: spamless at nospam.com (Doug) Date: Fri, 1 Dec 2006 22:01:01 -0600 Subject: Molten Metal Pools in WTC after weeks, only micronuke could have produced so much heat References: <1165026261.579383.57050@16g2000cwy.googlegroups.com> Message-ID: <4570fa53$0$97234$892e7fe2@authen.yellow.readfreenews.net> wrote in message news:1165026261.579383.57050 at 16g2000cwy.googlegroups.com... > W88 warhead design > > http://www.thepriceofliberty.org/06/09/25/wardpics-5.htm > > http://www.thepriceofliberty.org/06/09/25/wardpics-4.htm the diagrams are all wrong, they are fiction. From __peter__ at web.de Sun Dec 17 09:02:58 2006 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Dec 2006 15:02:58 +0100 Subject: Changing variable to integer References: Message-ID: vertigo wrote: > I receive such error: > File "p4.py", line 24, in PrintWordCountFloat > print "%s %f" % (word,words[word]) > TypeError: list indices must be integers > > i call PrintWordCountFloat with hash table, keys are words(string) and > values float. > This part of the code: > > def PrintWordCountFloat(words): > number = 0 > for word in words: > print "%s %f" % (word,words[word]) #line 24 > number = number + 1 > print "Total words: %d" %(number) > > My function displays whole table correctly, and after that i receive > mentioned error. > Why ? Where is the problem ? You could be calling PrintWordCountFloat() twice, once with a dictionary and then with a list :-) If I'm wrong, you have to provide more code. Peter From tim.tadh at gmail.com Mon Dec 18 22:10:19 2006 From: tim.tadh at gmail.com (Tim Henderson) Date: 18 Dec 2006 19:10:19 -0800 Subject: sha, PyCrypto, SHA-256 In-Reply-To: <1166296639.483483.292380@f1g2000cwa.googlegroups.com> References: <1166296639.483483.292380@f1g2000cwa.googlegroups.com> Message-ID: <1166497819.759533.146650@48g2000cwx.googlegroups.com> On Dec 16, 2:17 pm, mirandacasc... at yahoo.com wrote: > Operating system: Win XP > Vsn of Python: 2.4 > > Situation is this: Required to calcluate a message digest. The process > for calcluating the digest must use an SHA-256 algorithm. > > Questions: > 1) Is it correct that the sha module comes with python 2.4? > 2) Is it correct that the sha module that ships with python 2.4 does > NOT have the SHA-256 capability as part of the module? > 3) It looks like PyCrypto is a package that, among other things, > permits one to calculate a message digest using an SHA-256 > algorithm...is that correct? > 4) It looks like there are a couple couple possibilities available for > the download...either download the source code and run the setup which > (I'm assuming) compiles the various extension modules, or download the > pycrypto-2.0.1.win32-py2.4.zip which extracts out to a .exe; when one > runs the just-extracted .exe, it installs the stuff on one's > workstation. I'm leaning toward the second option because it seems > like most of the work has been done for me. A quick search on this > site didn't turn up anything that suggested there were problems with > running the installer. So, my question is this: are you aware of any > problems running the installer? > 5) Besides PyCrypto, are there any other Python packages that permit > one to calculate a message digest using an SHA-256 algorithm? > > Thank you. I have run that exact installer many many times and it works fine. to use SHA-256 with pycrypto: >>> from Crypto.Hash import SHA256 >>> sha = SHA256.new() >>> sha.update('message') >>> sha.hexdigest() # sha.digest gives the raw form 'ab530a13e45914982b79f9b7e3fba994cfd1f3fb22f71cea1afbf02b460c6d1d' cheers tim From http Sun Dec 10 04:33:20 2006 From: http (Paul Rubin) Date: 10 Dec 2006 01:33:20 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <1165616311.901535.249780@l12g2000cwl.googlegroups.com> <1165741450.601489.321550@73g2000cwn.googlegroups.com> Message-ID: <7x1wn8rt7j.fsf@ruckus.brouhaha.com> "Kay Schluehr" writes: > > A few months ago, I missed the Condition System most > > when using Python, and also lexical scope. However, it is nice to work > > with friends, who know Python and not Lisp.) > > Could you explain in which way Python lacks lexical scoping? Python has lexical scope but you can't update lexical variables from scopes other than the innermost or outermost (global) scope. I.e: def counter(): x = 0 def g(): x += 1 return x return g c = counter() print c() doesn't do what you'd hope. Yes there are workarounds but they're not all that satisfactory. From will at willNOmcguganSPAM.com Tue Dec 19 03:13:34 2006 From: will at willNOmcguganSPAM.com (Will McGugan) Date: Tue, 19 Dec 2006 08:13:34 +0000 Subject: trouble getting google through urllib In-Reply-To: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> Message-ID: <45879f2f$0$32025$fa0fcedb@news.zen.co.uk> Dr. Locke Z2A wrote: > Does anyone know how I would get the bot to have permission to get the > url? When I put the url in on firefox it works fine. I noticed that in > the output html that google gave me it replaced some of the characters > in the url with different stuff like the "&" and "%7C", so I'm > thinking thats the problem, does anyone know how I would make it keep > the url as I intended it to be? > Google doesnt like Python scripts. You will need to pretend to be a browser by setting the user-agent string in the HTTP header. Will McGugan -- blog: http://www.willmcgugan.com From Norbert.Klamann at projecthome.de Fri Dec 8 02:30:43 2006 From: Norbert.Klamann at projecthome.de (Norbert) Date: 7 Dec 2006 23:30:43 -0800 Subject: python.org not current Message-ID: <1165563043.341472.248270@j44g2000cwa.googlegroups.com> Hello all, the python website http://www.python.org/ mentions Version 2.3.6 and 2.4.4 on the most prominent place. Shouldn't this be changed to 2.5.x ? Regards Norbert From sonibergraj at youjoy.org Mon Dec 4 13:51:20 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Mon, 04 Dec 2006 19:51:20 +0100 Subject: decorators question In-Reply-To: <1165254977.903936.83180@16g2000cwy.googlegroups.com> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> Message-ID: <45746E28.70105@youjoy.org> > Shouldn't this code called when we actually DO call it ? Python statements are always executed to create the corresponding class and function objects when a module is imported. Cheers, -- Soni Bergraj http://www.YouJoy.org/ From rridge at csclub.uwaterloo.ca Mon Dec 25 10:19:33 2006 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: 25 Dec 2006 07:19:33 -0800 Subject: Why does Python never add itself to the Windows path? References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> Message-ID: <1167059973.888721.251460@i12g2000cwa.googlegroups.com> Ben Sizer wrote: > I've installed several different versions of Python across several > different versions of MS Windows, and not a single time was the Python > directory or the Scripts subdirectory added to the PATH environment > variable. Personally, I hate Windows applications that add themselves to the PATH. So much crap gets put in there that I don't even use the default system PATH and just set my own explicitly. > Every time, I've had to go through and add this by hand, to > have something resembling a usable Python installation. If you're installing multiple versions of Python on one machine you're going to have to do this anyways to ensure the version of Python you want first in the path actually is first. > No such problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or > Kubuntu. Linux distributions normally install themselves somewhere that's normally in the path already. I suppose you can do the same thing on Windows if you want, just choose to install Python into directory that's already in your path. Though installing to something like C:\WINDOWS\SYSTEM32 is probably not a good idea. Ross Ridge From st at tobiah.org Fri Dec 15 15:30:26 2006 From: st at tobiah.org (tobiah) Date: Fri, 15 Dec 2006 12:30:26 -0800 Subject: arrayType vs. typedArrayType? Message-ID: <4582f91f$0$15546$88260bb3@free.teranews.com> I hope no one minds my trying my question again in a more concise way: Using SOAPpy call, if I return [[1,2],[3,4]] from the server, I get back: : ['1', '2', '3', '4'] typedArrayType, and it flattened out my list of lists. But if I add some other type to the array: [1,[1,2],[3,4]] I get back something more useful: : [1, [1, 2], [3, 4]] What gives? Thanks, Toby -- Posted via a free Usenet account from http://www.teranews.com From python.list at tim.thechases.com Mon Dec 18 08:39:29 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 18 Dec 2006 07:39:29 -0600 Subject: How to get a substring with variable indices In-Reply-To: <45868B86.6010804@legche.net> References: <45868B86.6010804@legche.net> Message-ID: <45869A11.2000709@tim.thechases.com> > I have a string named text. I need to extract a substring from it > starting by variable 's' and ending by 'e'. > > text[s:e] generates the following error: > > TypeError: slice indices must be integers or None Your syntax is correct...the error you get back is the clue: either "s" or "e" fails to meet the criteria of being "integers or None". Check your values/types of those two variables before this call and you'll likely find that one or both is some other data-type. >>> text="hello world" >>> s = 4 >>> e = 5 >>> text[s:e] 'o' Darn those error messages that give away the answer... ;) -tkc From HardToSpell at gmail.com Tue Dec 12 02:11:03 2006 From: HardToSpell at gmail.com (Brian Mills) Date: 11 Dec 2006 23:11:03 -0800 Subject: Sorting Multidimesional array(newbie) In-Reply-To: References: <20061211193104.40fe7985.tartifola@gmail.com> <1165863508.967414.70350@73g2000cwn.googlegroups.com> Message-ID: <1165907463.624180.7990@79g2000cws.googlegroups.com> There's another (IMHO more readable) way to do it if you can afford defining a short little "compare" function, and telling .sort() to use that instead of its default: >>> def myListCmp(lst1, lst2): ... if lst1[0] < lst2[0]: return -1 ... if lst2[0] > lst2[0]: return 1 ... return 0 ... >>> a = [[5, 2], [1, 3]] >>> a [[5, 2], [1, 3]] >>> a.sort(cmp=myListCmp) >>> a [[1, 3], [5, 2]] >>> On Dec 11, 11:11 am, Peter Otten <__pete... at web.de> wrote: > Matimus wrote: > > Tartifola wrote: > >> Hi, > >> how can I sort an array like > > >> array([[5, 2], > >> [1, 3]]) > > >> along the first column to obtain > > >> array([[1, 3], > >> [5, 2]]) > >> i.e. keeping track of the ordered couples? > > >> Thanks, > >> A > > > use a sort key: > > >>>>from operators import getitem > >>>>a = [[5,2],[1,3]] > >>>>a > > [[5, 2], [1, 3]] > >>>>a.sort(key=lambda x:getitem(x,0)) > >>>>a > > [[1, 3], [5, 2]]Is that a faked session? > > >>> from operators import getitemTraceback (most recent call last): > File "", line 1, in > ImportError: No module named operators > > >>> from operator import itemgetter > >>> a = [[5, 2], [1, 3]] > >>> a.sort(key=itemgetter(0)) > >>> a[[1, 3], [5, 2]] > > Peter From sjmachin at lexicon.net Tue Dec 5 01:04:51 2006 From: sjmachin at lexicon.net (John Machin) Date: 4 Dec 2006 22:04:51 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> Message-ID: <1165298691.474503.184480@16g2000cwy.googlegroups.com> OKB (not okblacke) wrote: > John Machin wrote: > > > 3. The OP asked only for values; you are asking for names and > > values. If you have a magic flak jacket, please let me know; I'd > > like to borrow it occasionally :-) > > On reflection I think my alternative suggestion might be just as > good: the interpreter could indicate the character position within the > line. This also handles cases where the operands aren't simple names. > (Not that I have any idea how much harder/easier this would be to > implement.) OTTOMH, it would be easier. The compiler would "only" have to ensure that the line number and position within the line of each operator was available at run time (currently keeping only the line number of the first line in each statement). The cost/benefit ratio would IMHO still be far too high. > > I ask for names and values because that is what I want. If I have > some expression containing a bunch of variables and an exception is > raised, the most helpful information for me is the source code token > that is causing the error, because I can see the source code in my text > editor. The value is not as important, because there may be many > different variables that could be holding the same incorrect value. I > only want to look at the one that is ACTUALLY holding the incorrect > value. > Firstly, you may say that you want to look only at the ONE that is actually bound to THE incorrect value, but the interpreter has in general no way of telling which one is bad. For example: foo = "a" bar = [1] baz= "z" goo = [26] x = foo + bar This causes: "TypeError: cannot concatenate 'str' and 'list' objects" Which ONE out of foo and bar is actually bound to THE "incorrect" value? Did you mean to write "foo + baz", or did you mean to write "goo + bar"? Secondly, if you have so many variables referenced in one statement all with the same operator (e.g. +) that you have difficulty in working out where the problem is, I'd say that you have a statement that is far too long, and you have far too many variables in your function. Can you give a real example from your code where the location of such a human error (you cause a variable to bound to a value of inappropriate type) would be difficult to find, plus an estimate of how often you would make such an error? Cheers, John From jjl at pobox.com Sat Dec 30 16:29:05 2006 From: jjl at pobox.com (John J. Lee) Date: Sat, 30 Dec 2006 21:29:05 GMT Subject: Wow, Python much faster than MatLab References: <5bdf5$45969f9c$d443bb3a$14067@news.speedlinq.nl> Message-ID: <87r6uhf4zf.fsf@pobox.com> Stef Mientki writes: > Doran, Harold wrote: > > R is the open-source implementation of the S language developed at Bell > > laboratories. It is a statistical programming language that is becoming > > the de facto standard among statisticians. > Thanks for the information > I always thought that SPSS or SAS where th? standards. > Stef The 'SS' in SPSS stands for Social Science, IIRC. Looking at the lack of mention of that on their website, though, and the prominent use of the "E word" there, they have obviously grown out of (or want to grow out of) their original niche. Googling, SAS's market seems to be mostly in the business / financial worlds. No doubt R's community differs from those, though I don't know exactly how. From the long list of free software available for it, it sure seems popular with some people: http://www.stats.bris.ac.uk/R/ John From espen at vestre.net Tue Dec 12 02:55:41 2006 From: espen at vestre.net (Espen Vestre) Date: 12 Dec 2006 08:55:41 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> <7xwt4yju5e.fsf@ruckus.brouhaha.com> <7x1wn57voq.fsf@ruckus.brouhaha.com> <7xirghy7pu.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Robert Brown writes: > > Does this make Lisp "less dynamic" than Python? Espen would say it's not > > less dynamic, but rather that a similar level of dynamism is achieved in > > Common Lisp via well defined interfaces. The compiler knows the interfaces, > > so it can do a better job optimizing the code. [thank you for clarifying my post, Robert] > I'd say Python is more dynamic in the sense that the Python runtime > system has to actually concern itself about the dynamism all the time > in practice, i.e. on every object method invocation. Ok, but when you state that language A is more dynamic than language B, most programmers would interpret that as (or so I guess) "A offers more dynamism to the programmer than B" - not that it burdens the run time system implementor with more dynamism... -- (espen) From deets at nospam.web.de Thu Dec 14 05:19:16 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 14 Dec 2006 11:19:16 +0100 Subject: Conditional iteration In-Reply-To: <45810516$0$338$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> Message-ID: <4ucmp2F17jqc2U1@mid.uni-berlin.de> > Is it redundant according to your criteria, yes I would say: > > a = {True: a, False: c}[condition] > > or > > a = [c, a][condition] > > would yield exactly the same even in one sentence.... Obviously it is _not_ the exact same. def fac(n): return n * fac(n-1) if n else 1 Try that with your recipes above. Diez From Bulkan at gmail.com Tue Dec 26 07:22:38 2006 From: Bulkan at gmail.com (placid) Date: 26 Dec 2006 04:22:38 -0800 Subject: BeautifulSoup vs. loose & chars In-Reply-To: References: Message-ID: <1167135758.005112.67350@73g2000cwn.googlegroups.com> John Nagle wrote: > I've been parsing existing HTML with BeautifulSoup, and occasionally > hit content which has something like "Design & Advertising", that is, > an "&" instead of an "&". Is there some way I can get BeautifulSoup > to clean those up? There are various parsing options related to "&" > handling, but none of them seem to do quite the right thing. > > If I write the BeautifulSoup parse tree back out with "prettify", > the loose "&" is still in there. So the output is > rejected by XML parsers. Which is why this is a problem. > I need valid XML out, even if what went in wasn't quite valid. > > John Nagle So do you want to remove "&" or replace them with "&" ? If you want to replace it try the following; import urllib, sys try: location = urllib.urlopen(url) except IOError, (errno, strerror): sys.exit("I/O error(%s): %s" % (errno, strerror)) content = location.read() content = content.replace("&", "&") To do this with BeautifulSoup, i think you need to go through every Tag, get its content, see if it contains an "&" and then replace the Tag with the same Tag but the content contains "&" Hope this helps. Cheers From harry.g.george at boeing.com Mon Dec 11 13:21:11 2006 From: harry.g.george at boeing.com (Harry George) Date: Mon, 11 Dec 2006 18:21:11 GMT Subject: free, python XML merger? References: <1165858953.389963.161000@f1g2000cwa.googlegroups.com> Message-ID: "mistersulu" writes: > All: > > We're looking for a python module which allows for quick merging of two > XML files. Both files follow the same schema. One file contains the > default values and structure, and the second file contains overriding > data for the same tags. > > Thanks in advance, > sulu > Sounds like a general XML problem, to be solved with cElementTree perhaps. Can you provide the schema and small examples of the input files and the desired output file? -- Harry George PLM Engineering Architecture From pyenos at pyenos.org Fri Dec 22 19:57:44 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 11:57:44 +1100 Subject: let me simplify my question on scope of vars Message-ID: <877iwjcttj.fsf@pyenos.pyenos.org> "code" var=1 class CLASS: def METHOD1: def METHOD2: var+=var return var METHOD2() #line8 return var METHOD1() #line10 "end code" Q1: does class CLASS inherit var=0 from line1? Q2: does def METHOD1 inherit var=0 from line1? Q3: does def METHOD2 inherit var=0 from line1? Q3: does line8 return '2'? Q4: does line10 return '2\n2'? From paddy3118 at netscape.net Tue Dec 12 21:13:26 2006 From: paddy3118 at netscape.net (Paddy) Date: 12 Dec 2006 18:13:26 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4579c4f4$0$49201$14726298@news.sunsite.dk> <1165971298.617221.59450@n67g2000cwd.googlegroups.com> Message-ID: <1165976006.329013.54380@73g2000cwn.googlegroups.com> John Thingstad wrote: > On Wed, 13 Dec 2006 01:54:58 +0100, Paddy wrote: > > > > > Robert Uhl wrote: > > > >> Steven D'Aprano writes: > >> > > >> > Speaking as somebody who programmed in FORTH for a while, that doesn't > >> > impress me much. Prefix/postfix notation is, generally speaking, more > >> > of a pain in the rear end than it is worth, even if it saves you a > >> > tiny bit of thought when pasting code. > >> > >> Of course, you use prefix notation all the time in Python: > >> > >> for x in range(0,len(y)): > >> dosomething(x) > > > > In Python, most containers are directly iterable so we are much more > > likely to arrange our program to use: > > for a in y: > > dosomethingwith(a) > > > > -Paddy. > > > > In lisp: (loop for a in y do (do-something a)) > > There is one difference.. There is no iterator so you have different > pronouns for each sequence type: > > list: (loop for a in y .. > array: (loop for a across y .. > hash: (loop for a over y .. > > hardly ideal, but workable. > > Still it is a lot simpler to change the declaration in the start of the > loop > than having to changing the access to all references to a variable as you > might have to I can't quite figure out the meaning of your sentence above. > with recursion. Consider > > (defun func-iter (list) > (func (first list))) > (when (not (endp list)) > (func-iter (rest list))) > > (You could write (mapc #'(lambda (e) (func e)) list) but that is beside > the point.) > > or something like that. What happens if you change the type to a array? > Total rewrite.. Not even close. In my example above: for a in y: dosomethingwith(a) y could be a lot of built-in types such as an array, list, tuple, dict, file, or set. - Paddy. From cjw at sympatico.ca Fri Dec 1 16:03:17 2006 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 01 Dec 2006 16:03:17 -0500 Subject: Python25.zip In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > On Thu, 30 Nov 2006 18:14:11 -0500, "Colin J. Williams" > declaimed the following in comp.lang.python: > >> As part of the Python initialization, C:\Windows\System32\Python25.zip >> is set up in the path. >> >> I haven't seen any documentation on the use or purpose of the zip file. >> > Well, did you examine the contents of it? There is no such file in C:\Windows\System32 - Python 2.5 on a Windows XP > > I believe for some versions now, "import" can pull from a ZIP > archive -- perhaps they've put the many standard library imports into a > single file... Yes, since 2.3 - thanks to Fredrick for the pointer to PEP 273. That gives the helpful warning that the above should follow the home directory in the path list. PEP 302 says "[PYTHONPATH] is directly needed for Zip imports." The role of Python25.zip is not clear. Is it required in the path just to enable the import X.zip capability? Colin W. From kentilton at gmail.com Sat Dec 9 10:45:22 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 10:45:22 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote: > > >>if Common Lisp didn't have CLOS, its object system, I could write my own >>as a library and it would be just as powerful and just as easy to use as >>the system Common Lisp already provides. Stuff like this is impossible >>in other languages. > > > Dude. Turing Complete. Don't you Lisp developers know anything about > computer science? We just know the Turing Complete thing cannot be used to duck language feature comparisons because the whole point of language comparison is "how much pain does each language spare me?", where a Turing machine is ranked as the ultimate in programming pain. This might be because the whole point of a programming language is to spare us the pain of toggling switches on the back of an ENIAC. > > Anything any language can do is possible in any other language,... At what cost? ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From Roberto.Bonvallet at cern.ch Fri Dec 15 11:10:37 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Fri, 15 Dec 2006 16:10:37 +0000 (UTC) Subject: Restrictive APIs for Python References: <1166193072.925721.52780@80g2000cwy.googlegroups.com> Message-ID: Will Ware wrote: > Python has no inherent provision for a restrictive API that blocks > accesses to methods and variables outside an allowed set. > Inexperienced Python programmers may fail to adhere to an agreed-upon > API, directly accessing the private internals of a class. Just don't document those private internals. Or document that they must not be accessed directly. -- Roberto Bonvallet From fredrik at pythonware.com Tue Dec 19 14:22:12 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 20:22:12 +0100 Subject: regexp In-Reply-To: References: Message-ID: vertigo wrote: > I need to use some regular expressions for more than one line. > And i would like to use some modificators like: /m or /s in perl. > For example: > re.sub(".*","",data) > > will not cut out all javascript code if it's spread on many lines. that won't cut out all javascript code period. From fredrik at pythonware.com Wed Dec 20 03:22:59 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 09:22:59 +0100 Subject: MySQLdb, lots of columns and newb-ness In-Reply-To: <20061220002620.GA9142@localhost.localdomain> References: <20061220002620.GA9142@localhost.localdomain> Message-ID: Andrew Sackville-West wrote: > I've also tried building tuples and lists and then using this > > cursor.execute("insert into daily values (%s)", values) > > with no luck. it appears to me that I have to put in all 132 '%s' in > order to make that work and that just seems stupid. on the other hand, hackers just *love* people who think they're too clever to do things in a safe and robust way: http://en.wikipedia.org/wiki/SQL_injection using parameterized inserts also speeds things up for many databases, since the database engine don't have to parse and and analyze the sql statement over and over and over again. to quickly generate the parameter list, use string repeat to create the parameter list: params = "(" + ",".join(["%s"]*len(values)) + ")" cursor.execute("insert into daily values " + params, values) you probably want to do some normalization work on your database too, but that's another story. From benc_nospam at hotmail.com Tue Dec 26 16:22:50 2006 From: benc_nospam at hotmail.com (benc_nospam at hotmail.com) Date: 26 Dec 2006 13:22:50 -0800 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167059973.888721.251460@i12g2000cwa.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> <1167059973.888721.251460@i12g2000cwa.googlegroups.com> Message-ID: <1167168170.056927.246180@a3g2000cwd.googlegroups.com> Ross Ridge wrote: > Ben Sizer wrote: > > I've installed several different versions of Python across several > > different versions of MS Windows, and not a single time was the Python > > directory or the Scripts subdirectory added to the PATH environment > > variable. > > Personally, I hate Windows applications that add themselves to the > PATH. So much crap gets put in there that I don't even use the default > system PATH and just set my own explicitly. Agreed. A good Windows application minimizes its footprint, only adding registry keys, environment variables, system tray icons, services, shell extensions, etc, etc, when absolutely necessary. Python is such an application. But on the other hand, I use Python on the Windows command line all the time. Having to manually set PATH for each machine I use Python on is a minor annoyance. One solution would be an optional feature on the MSI to prepend the install directory to PATH. In fact, this is what ActivePython does. Any reason why the official Python distribution shouldn't? --Ben Cartwright From mike at nospam.com Fri Dec 8 09:54:41 2006 From: mike at nospam.com (Mike) Date: Fri, 8 Dec 2006 06:54:41 -0800 Subject: raw strings in regexps References: Message-ID: "Gabriel Genellina" wrote in message news:mailman.1288.1165563291.32031.python-list at python.org... ... > You have to quote metacharacters if you want to match them. The escape > method is useful for this: > > >>> re.escape('(a)') > '\\(a\\)' Doh! Of course! Thanks everyone. -- Mike -- From jfabiani at yolo.com Thu Dec 14 19:51:52 2006 From: jfabiani at yolo.com (johnf) Date: Thu, 14 Dec 2006 16:51:52 -0800 Subject: MySQLdb windows binaries for Python 2.5?? Yes, but from a World of Warcraft guild. References: <1162408100.985370.148650@m7g2000cwm.googlegroups.com> <1163238145.257490.144410@b28g2000cwb.googlegroups.com> Message-ID: John Nagle wrote: > Jan Dries wrote: >> Henk.van.Asselt at gmail.com wrote: >> >>> I'm also looking for a MySQLdb binary for windows. This is holding me >>> from upgrading from Python 2.4 to Python 2.5 ! >>> >> >> If you search the Help Forum of the MySQLdb project on SourceForge, you >> will find a couple of people who have successfully built MySQLdb on >> Windows for 2.5, and are willing to share their installers. >> That's how I got my binaries. >> >> Regards, >> Jan > > Yes, see > > http://sourceforge.net/forum/forum.php?thread_id=1571110&forum_id=70461 > > for an untested version created by a World of Warcraft guild: > > http://www.guildmanus.com/uploaded/MySQL-python.exe-1.2.2b2.win32-py2.5.exe > > This, apparently, is the extent of current Python support for MySQL. > Want to install that executable, as root, on your production machines? > > This is embarassing for the Python community. Perl and PHP come > with MySQL support built in. Python is out to lunch on this. > > John Nagle > Animats I couldn't disagree more. That fact that no Database drivers are built-in makes Python stronger - allowing Python to access any Data Engine that supports DBI 2.0. Of course I'm not including pickle in my assessment. Johnf From rtw at freenet.co.uk Wed Dec 13 16:42:20 2006 From: rtw at freenet.co.uk (Rob Williscroft) Date: Wed, 13 Dec 2006 15:42:20 -0600 Subject: Windows SetLocalTime References: <1166040733.947268.80050@16g2000cwy.googlegroups.com> <1166041988.571906.244570@j72g2000cwa.googlegroups.com> Message-ID: Podi wrote in news:1166041988.571906.244570 at j72g2000cwa.googlegroups.com in comp.lang.python: > Rob Williscroft wrote: >> >> Google will usually find the documentation of anything in the >> Windows API however sometimes it also helps to add "msdn" to >> your search as in: > Yes, thank you. > > I found the function SetLocalTime or SetSystemTime to set the time from > MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am > having trouble passing parameter to the functions in Python. > Ok I see, you will probably need these 2 bits of the ctypes documentation: http://docs.python.org/lib/ctypes-structures-unions.html http://docs.python.org/lib/ctypes-pointers.html >From there on geting to this is farly straight forward: from ctypes import * from ctypes.wintypes import WORD class SYSTEMTIME(Structure): _fields_ = [ ( 'wYear', WORD ), ( 'wMonth', WORD ), ( 'wDayOfWeek', WORD ), ( 'wDay', WORD ), ( 'wHour', WORD ), ( 'wMinute', WORD ), ( 'wSecond', WORD ), ( 'wMilliseconds', WORD ), ] GetSystemTime = windll.kernel32.GetSystemTime st = SYSTEMTIME() GetSystemTime( pointer( st ) ) print st.wYear, st.wMonth, st.wDayOfWeek A bit more digging into the docs will get to this: prototype = WINFUNCTYPE( None, POINTER( SYSTEMTIME ) ) paramflags = (1, "lpSystemTime" ), GetSystemTime = prototype(("GetSystemTime", windll.kernel32), paramflags ) st = SYSTEMTIME() GetSystemTime( st ) print st.wYear, st.wMonth, st.wDayOfWeek Which will give a much better error message if you try to pass something other than a SYSTEMTIME, as well as wrapping the argument in pointer for you. Rob. -- http://www.victim-prime.dsl.pipex.com/ From http Sat Dec 9 06:16:45 2006 From: http (Paul Rubin) Date: 09 Dec 2006 03:16:45 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> Message-ID: <7xfybpb9pe.fsf@ruckus.brouhaha.com> "Ramon Diaz-Uriarte" writes: > a) "old-fashioned"? Is that supposed to be an argument? I guess > addition and multiplication are old-fashioned, and so is calculus;so? > I think "old-fashioned" should only carry a negative connotation in > the fashion world, not in programming. If someone handed you a calculus book written in Latin, you'd probably find it undesirably old-fashioned too. > b) "the more serious Lisp-like language designers have moved on to > newer ideas." Can you elaborate? I am not an expert but by looking at, > say, lambda the ultimate, I'd say this statement is just not true. And > which are these "newer ideas"; what programming languages are > incorporating them? (Scala, Mozart/Oz, Alice-ML, ...). I don't know about Scala. I'd add Haskell to that list. I'm not enough of a languages buff to know what's happening at the bleeding edge. Lispers sometimes get confused into thinking you can't make a language less powerful by adding stuff to it. For example, part of the power of Lisp comes from reliable garbage collection, which follows from the language not having naked pointers. No more buffer overflow bugs clobbering the return stack and injecting hostile code, no more double-free errors, etc. As long as your program is written purely in Lisp, there are certain classes of bugs that you simply don't have to worry about. But if you add C++ style pointers to Lisp, your programs are once again susceptable to all those bugs, and so you've made Lisp in a sense less powerful. And if you can make Lisp less powerful by adding stuff, you logically have to ask whether you can make it more powerful by subtracting stuff. Haskell is pretty neat in that it basically removes things like setq. That makes possible (for example) very cool simplifications to concurrent programming. See the paper "Composable memory transactions": http://research.microsoft.com/~simonpj/papers/stm/index.htm Yeah you could do that with Lisp by writing in a restricted style, just like you could avoid pointer errors in C++ by writing in a restricted style. But it's hard for the compiler to guarantee that your program obeys the restrictions. You could write a language like Ada or Java that makes a lot of guarantees, but is unexpressive and a huge pain to program in. You can write a language like Lisp that's expressive but doesn't make as many guarantees. Interesting problems in language design arise in writing languages that are expressive AND make guarantees. From pavlovevidence at gmail.com Fri Dec 22 23:02:31 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 22 Dec 2006 20:02:31 -0800 Subject: Use a Thread to reload a Module? References: Message-ID: <1166846551.460203.242690@h40g2000cwb.googlegroups.com> Gregory Pi?ero wrote: > Hi Python Experts, > > I hope I can explain this right. I'll try. > > Background: > I have a module that I leave running in a server role. It has a > module which has data in it that can change. So every nth time a > function in the server gets called, I want to reload the module so it > has the freshest data. But there's a lot of data so it takes 5-10 > seconds to do a reload. > > My question is: > Would I be able to launch a seperate thread to reload the module while > the server does it work? Hopefully it would be using the old module > data right up until the thread was finished reloading. > > Thanks in advance, > > Greg > > Here's some psuedo code that might illustrate what I'm talking about: > > import lotsa_data > > def serve(): > reload(lotsa_data) #can this launch a thread so "do_stuff" runs right away? > do_stuff(lotsa_data.data) > > while 1: > listen_for_requests() Using a thread for this purpose is no problem. Using a module: yep, that's a problem. (I'd say using a module in this way, to update data, is very far from best practice, but its convenience justifies simple uses. You are going beyond simple now, though.) Not knowing more about your program, I'd say the simplest way is: 1. exec, don't reload, your data file (with the standard warning that exec should only be used on carefully contructed code, or to deliberately give the user the power to input python code--of course the same warning applies when reloading a dynamically generated module). 2. Store the new data somewhere (such as a Queue) waiting for a good time to update. 3. At a convenient time, overwrite the old data in the module. I'm going to assume that your server has heretofore been single-threaded; therefore you don't need locks or queues or semaphores in your main code. Here, then, is a very improvable example to consider. Notice that the lotsa_data module is empty. Instead, you call load_data() to exec the file where the data really is, and it puts the loaded data into a queue. Next time you wait for a new request, it checks to see if there are any data updates in the queue, and updates the date in lotsa_data module if so. import Queue import threading import lotsa_data ## empty! data_update_queue = Queue.Queue() def serve(): if request_count % n: threading.Thread(target=load_data).start() do_stuff(lotsa_data.data) request_count += 1 def load_data() d = {} exec "/path/to/data/file" in d data_update_queue.put(d) load_data() # run once in main thread to load data initially while True: try: d = data_update_queue.get_nowait(d) except Queue.Empty: pass else: for key,value in d: setattr(losta_data,key,value) listen_for_requests() There is much room for improvement. For example, can requests come in fast enough to spawn another load_data before the first had ended? You should consider trying to acquire a threading.Lock in load_data and waiting and/or returning immediately if you can't. Other things can go wrong, too. Using threads requires care. But hopefully this'll get you started. Carl Banks From http Fri Dec 15 18:37:37 2006 From: http (Paul Rubin) Date: 15 Dec 2006 15:37:37 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> <1166102108.129051.166580@73g2000cwn.googlegroups.com> <4ufenbF17of60U6@mid.individual.net> Message-ID: <7x7iwsd932.fsf@ruckus.brouhaha.com> Andr? Thieme writes: > Lisp has no parens. An editor could support a mode where code > is displayed in written in trees. There wouldn't be a single paren. But there would be even more tokens, the lines going between the nodes in the trees, for example. From jon at ffconsultancy.com Sun Dec 3 18:03:40 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 03 Dec 2006 23:03:40 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165169117.866499.181520@73g2000cwn.googlegroups.com> <45732974$0$8758$ed2619ec@ptn-nntp-reader02.plus.net> <1165183970.832303.323350@73g2000cwn.googlegroups.com> Message-ID: <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> Carl Banks wrote: >> Optimized Python is 14% slower than badly written OCaml. > > I'd call that roughly the same speed. Did you use any sort of > benchmark suite that miminized testing error, or did you just run it > surrounded by calls to the system timer like I did? System timer, best of three. > If the latter, > then it's poor benchmark, and 10% accuracy is better than you can > expect. (Naive tests like that tend to favor machine code.) Yes, they are roughly the same speed. My objection was that this OCaml program was not the unoptimised one, it was the badly written one. The unoptimised OCaml/F#/C++ are all several times faster than this OCaml, and much shorter and simpler too. >> Unoptimised but well-written OCaml/C/C++ is 2.5-2.8x faster than the >> fastest Python so far whilst also requiring about half as much code. > > Frankly, I have a hard time believing anyone would naively write the > Ocaml code like the optimized version you posted. That wasn't optimised. I haven't optimised any of my solutions. The OCaml I posted was a naive convolution with some unnecessary allocation. > You'd know better than I, though. When asked to convolve an array with a 4-element array (h0..h3), I think most programmers would write (pseudocode): for i in [0 .. n-4] x[i] = h0 y[i] + h1 y[i+1] + h2 y[i+2] + h3 y[i+3] in most languages. That is the essence of this benchmark. You can express it even more succinctly with a dot product: for i in [0 .. n-4] x[i] = h . y[i:] In this case, you'd want a cyclic array type too. >> That's my point, using numpy encouraged the programmer to optimise in the >> wrong direction in this case (to use slices instead of element-wise >> operations). > > Ok, I can see that. We have a sort of JIT compiler, psyco, that works > pretty well but I don't think it's as fast for large arrays as a good > numpy solution. But it has more to deal with than a JIT for a > statically typed language. Ok. Perhaps starting a Python JIT in something like MetaOCaml or Lisp/Scheme would be a good student project? >> Which begs the question, if you were writing in a compiled language like >> F# would you ever use slices? > > If I was writing in F#? I absolutely would, because some problems are > most cleanly, readably, and maintainably done with slices. I don't > have any speed-lust, and I don't waste time making things fast if they > don't need to be. I would rather spend my time designing and > implementing the system, and optimizing things that actually need it. > I don't want to spend my time tracking down some stupid indexing error. Ok. Can you name some problems that are solved more easily with slices than with indexing? I may have just answered my own question by posting some really concise pseudocode that uses slices. > Will any other F# people do it? I don't know if they all have > speed-lust, or if they'd all deliberately avoid slicing to prove some > kind of point about functional programming and/or non-machine-compiled > languages, but I assume there'd be some who would do it for the same > reasons I'd do it. My concern is that slices are being pulled into F# because they are popular in languages like Python and Matlab but I've yet to see an example where they are actually a good idea (in the context of F#, i.e. a compiled language where indexing is as fast or faster). >> What makes numpy convenient? > > ...it scales up well... What do you mean? > ...it expresses mathematical concepts straightforwardly... It didn't express this mathematical concept very straightforwardly. > And a lot of the time, you don't have to worry about indexing. Right. Ideally you want to factor that out without losing anything. Indeed, if you do factor the C++ code you should get back to the underlying mathematical definitions. Ideally, you'd want to write those directly and have them executed efficiently. >> > No problem, numpy will be fast enough for my needs. >> >> Ok. But you'd rather have a compiler? > > Python *is* compiled, buddy. It has a VM that runs bytecode. I meant a native-code compiler, of course. > But, would I rather have a seperate compile to *machine code*, when an > automatic compile to VM code is fast enough? > > Not remotely. Compilers are a PITA and I avoid them when it's > possible. I can envisage a JIT Python compiler that would spot statically typed code, compile it with no user intervention and then run it. I implemented such a thing for Mathematica a few years ago. >> Why not drop to C for this one function? > > Why would I? The assumptions clearly stated that numpy is fast enough. > Why would I take several hours to write a C extension when I could do > it with numpy in about 20 minutes, *and it's fast enough*? Is it very difficult to interface Python to other languages efficiently? > But let me offer you some advice: if you wan't to lure people from > Python, speed isn't going to cut it. Most people who chose Python > (and, let's face it, most people who use Python chose it themselves) > already knew it was slow, and chose it anyways. Pythonistas prefer > Python because it's clean, readable, well-supported, and practical. > Practical might be the sticking point here. If you were to get a > Python prompt, and type "import this", it would print the Zen of > Python, a set of principles by which the language is designed. One of > them is "Practicality beats purity." And let's face it, functional > languages are (or seem to be) all about purity. Notice that there's no > Zen that says "Fast is better than slow". If you want us to swtich to > Ocaml, you better figure out how it supports the Zen of Python better > than Python does. I'm keen on the practical aspect. I intend to take some of the excellent Python demos out there and port them to languages like F# in order to illustrate how they too can be practical languages. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists From jfabiani at yolo.com Thu Dec 21 01:58:42 2006 From: jfabiani at yolo.com (johnf) Date: Wed, 20 Dec 2006 22:58:42 -0800 Subject: your opinion about psycopg vs pygresql References: <45897630$0$326$e4fe514c@news.xs4all.nl> Message-ID: Martin P. Hellwig wrote: > Hi all, > > I'm playing a bit with PostgreSQL, in which I've set me the target to > create a python script which with user input creates a new user role and > a database with that owner (connecting to template1 since I know that at > least that db exists). > > Ok so I installed PostGreSQL and pygresql since it looked like that this > is endorsed by PG, I had some trouble with the DB-API2 (complains about > there is already a connection to template1, even when I closed and > deleted the connector) so I solved it by using the pg api. > > But I was intrigued by this problem and started googling and by that > time I've noticed that python projects like Django seem to favor the > psycopg module. > > So I installed that one (the 1.1 version, since Django uses that too) > and it looked like it has the same problem of creating a user after a > database, I'm sure that there is a user error in there somewhere :-) > > However, given the choice, what in your opinion would be the reason why > someone would chose one over the other? Now I know this could easily get > into a flamewar, so if you comment (but please do so) I'll still > investigate that, since at this moment I don't even have a clue how they > differ and on what reason, why does PostgreSQL seem to favour pygresql > and Pythoneers psycopg? > > Thanks in advance. > I have not used pygresql but I see it often as a standard package with the SUSE DISTRO. But I use Psycopg 2. I find that it is very fast and provides a few extentions that I have used. Reported bugs are fixed immediately. John From cito at online.de Fri Dec 15 07:49:29 2006 From: cito at online.de (Christoph Zwerschke) Date: Fri, 15 Dec 2006 13:49:29 +0100 Subject: No latin9 in Python? In-Reply-To: <457710EE.4090704@v.loewis.de> References: <457710EE.4090704@v.loewis.de> Message-ID: <458299D9.4010503@online.de> Martin v. L?wis wrote: > While you are at it, you'll notice that the current version of the > character-sets database lists > > Name: ISO-8859-15 > MIBenum: 111 > Source: ISO > Please see: > > Alias: ISO_8859-15 > Alias: Latin-9 > > so the "official" alias is "Latin-9", not "latin9". You may > want to ask the submitter of that entry why this inconsistency > was introduced. Unfortunately, I got no reply and I really cannot see any reason for this inconsistency; probably it was a mistake or carelessness. According to http://recode.progiciels-bpi.ca/manual/Tabular.html, "l9 and latin9 are aliases for this charset. Source: ISO 2375 registry." So I think it cannot harm adding latin9 as an alias name. "Latin-9" will then be recognized automatically since I think capitalization and hyphens do not matter anyway (I'll check that). Shall I proceed writing such a patch? Shall I also add latin0 and l0 which are other inofficial aliases? -- Christoph From maksim.kasimov at gmail.com Thu Dec 28 12:01:44 2006 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Thu, 28 Dec 2006 19:01:44 +0200 Subject: __getattr__ possible loop In-Reply-To: References: <1167314779.170915.145680@48g2000cwx.googlegroups.com> <1167320704.931970.175330@42g2000cwt.googlegroups.com> <4866bea60612280825r58ac878avf2615c799ef5384@mail.gmail.com> Message-ID: Chris Mellon wrote: > > Nothing so clever. dir() eats and ignores all exceptions, so when you > hit the recursion limit it eats the RecursionLimitExceeded exception > and continues merrily along the way. This is probably not good > behavior... > > class Foo: > def __getattr__(self, attr): > raise SystemExit, "Don't call me, again, ever" > > f = Foo() > f.method() #dies correctly > dir(f) #continues happily can't understand - what kind of problem you tried to fix in that way? if __getattr__ just raise some exception, it needless to define it at all. -- Maksim Kasimov From Roland.Puntaier at br-automation.com Wed Dec 20 08:18:44 2006 From: Roland.Puntaier at br-automation.com (Roland Puntaier) Date: Wed, 20 Dec 2006 14:18:44 +0100 Subject: array, a better shell In-Reply-To: <1166615065.807704.12480@48g2000cwx.googlegroups.com> Message-ID: >I have also used the shell of Mathematica. It's quite powerful and it >can show graphics too inlined, but globally I don't like it fully >because it makes editing small programs a pain (for me)... I use Vim to edit python code and can execute any selection (F3) or single lines (F2) whenever I want to (Vim must be built to include the python interpreter). Here is the according Vimrc code "pyout if present must be right below "r replaces, p prints, symb sets the start py << EOL def PrintCurrentLine(*args): cur_str = vim.current.line action, symb = None, None for i in args: if i in ["r","p"]: action = i else: symb = i try: start = cur_str.rindex(symb)+len(symb) except: start = 0 eval(compile("pyoutres="+cur_str[start:],'','exec'),globals()) result = eval("pyoutres",globals()) if action == "r": vim.current.line = cur_str[:start]+str(result) else: iPy=PyOutput() if iPy != -1: resS=cur_str+"=================="+'\n'+str(result)+'\n' resL=resS.split('\n') vim.buffers[iPy].range(0,0).append(resL) vim.command("wincmd b") vim.command("normal gg") vim.command("wincmd p") else: print result EOL command -narg=* Pyl python PrintCurrentLine() map :py PrintCurrentLine() python << EOL def EvaluateCurrentRange(): c_r=vim.current.range i=0 while c_r[0].startswith(' '*(i+1)): i+=1 rngstr='\n'.join([ln[i:] for ln in c_r]) eval(compile(rngstr,'','exec'),globals()) EOL map :py EvaluateCurrentRange() From bearophileHUGS at lycos.com Sat Dec 9 14:09:10 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 9 Dec 2006 11:09:10 -0800 Subject: len() and PEP 3000 In-Reply-To: References: <4tnqlkF13bbqeU1@mid.individual.net> <5HSdh.15210$P04.6844@tornado.fastwebnet.it> Message-ID: <1165691350.084268.104930@79g2000cws.googlegroups.com> Colin J. Williams: > Why not replace the __len__ method with a len property for strings, > lists, tuples, dictionaries etc. __len__ is not very special and the > property len eliminates the redundant parentheses. You mean something like: >>> "ab".len, [1, 2, 3].len (2, 3) In the given page Guido says: >I didn't want these special operations to use ordinary method names, because then pre-existing classes, or classes written by users without an encyclopedic memory for all the special methods, would be liable to accidentally define operations they didn't mean to implement, with possibly disastrous consequences.< I think it's easy enough to remember a len attribute, you use it all the time. >many functions are defined in terms of informal interfaces; for example, reversed works on anything that supports random access to items and has a known length. In practice, implementing things like max, sum, map, any, in and others, as built-in functions and operators is actually less code than implementing them as methods for each and every type that needs to support them.< I agree, but I think some exceptions can be made for len attribute, and for .copy(), .deepcopy(), and maybe for few other general methods. Bye, bearophile From atkinw at rpi.edu Sun Dec 10 17:28:11 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 17:28:11 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: Andr? Thieme writes: > But anyway, in Lisp you can save some code. Not much in this situation. > Instead of function = memoize(function) > one could just say: memoize(function). Um... From slawomir.nowaczyk.847 at student.lu.se Tue Dec 12 18:12:09 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Wed, 13 Dec 2006 00:12:09 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <20061212233611.573A.SLAWOMIR.NOWACZYK.847@student.lu.se> On Sat, 09 Dec 2006 14:57:08 -0500 Bill Atkins wrote: #> In Python, I would need to do something like: #> #> control_code = connection.read_next_control_code() #> if control_code == +break+: #> connection.kill() #> throw blah #> else if control_code == +status+: #> connection.send_status_summary() #> else if control_code == +noop+ || control_code == +keep_alive+: #> else: #> error "CONTROL_CODE fell through conditional cascade; was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+" Hardly. I mean, well, possibly, *you* might need to, but others might just do things like this: def main(): connection = "+break+" def kill(): print "kill",connection raise "broken-by-client" def status(): print "status" def do_nothing(): pass dispatch = {"+break+":kill,"+status+":status,"+noop+":do_nothing,"+keep-alive+":do_nothing} dispatch[connection]() When you compare the above with your lisp version #> (let ((control-code (read-next-control-code connection))) #> (ecase control-code #> (+break+ #> (kill-connection connection) #> (throw :broken-by-client)) #> (+status+ #> (send-status-summary connection)) #> ((+noop+ +keep-alive+)))) #> ;; +X+ indicates a constant you may be able to see that they are pretty similar. Sure, Python does not have fully functional lambda (which I, personally, consider to be a drawback, but I understand that it is -- objectively -- a valid design decision) so one needs to define functions for handling each case, but there are some benefits to this approach as well. #> To change what control codes you want to check for, you need to add #> conditionals Just as you need to add ecase branches... #> for them and keep the error text relevant. The reality is that a #> computer could be doing this for you, leaving your code simpler and #> more easily changed. Not really. If you care about the error message, you can use a subclass of a dictionary instead and provide the correct behaviour when key is not found. #> Now someone will complain that the ECASE code means nothing until I #> understand ECASE. Yep. But once you understand ECASE, you can look #> at that code and, *at a glance*, see how control flows through it. In #> the equivalent Python code, I need to walk through each conditional #> and make sure they're all following the same pattern. If you're not #> convinced, extend the example to 12 different control codes. What you say is right, but only for bad Python code. Want to bet I can write bad Lisp which will be just as unmaintainable? PS. Good sigmonster, have a cookie! -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) Get the facts first - you can distort them later! From dickinsm at gmail.com Wed Dec 6 18:45:54 2006 From: dickinsm at gmail.com (dickinsm at gmail.com) Date: 6 Dec 2006 15:45:54 -0800 Subject: Mirror imaging binary numbers In-Reply-To: <1165446077.584437.206310@73g2000cwn.googlegroups.com> References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> <1165445569.287552.266120@j44g2000cwa.googlegroups.com> <1165446077.584437.206310@73g2000cwn.googlegroups.com> Message-ID: <1165448754.718593.200170@f1g2000cwa.googlegroups.com> On Dec 6, 6:01 pm, "Craig" wrote: > Thanks so much for the response. I have an array of individual bytes > which will eventually make up a binary bitmap image that is loaded onto > an LCD screen (1 = black dot, 0 = white dot). At the moment each byte > is reversed to what it should be (completely reverse the bit order): > e.g 00111101 should be 10111100, 11001100 should be 00110011, etc. It > is not an int problem as such, it is more a bit level swap if you get > what I mean. If you could help that would be great. Yet another solution: def flipbits(x): """reverse bits in a byte""" x1 = x << 4 | x >> 4 x2 = (x1 & 51) << 2 | (x1 & 204) >> 2 return (x2 & 85) << 1 | (x2 & 170) >> 1 The idea is to first swap the two nybbles, then swap bits 0, 1, 5, 6 with 2, 3, 6, 7 respectively, and finally swap bits 0, 2, 4, 6 with bits 1, 3, 5, 7 respectively. Mark From DustanGroups at gmail.com Mon Dec 25 10:44:47 2006 From: DustanGroups at gmail.com (Dustan) Date: 25 Dec 2006 07:44:47 -0800 Subject: regular expression In-Reply-To: <1167056220.806080.3760@f1g2000cwa.googlegroups.com> References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> <4587dc54$0$18460$e4fe514c@dreader31.news.xs4all.nl> <1166967692.801622.295830@n51g2000cwc.googlegroups.com> <1167056220.806080.3760@f1g2000cwa.googlegroups.com> Message-ID: <1167061487.700212.168940@79g2000cws.googlegroups.com> deviantbunnylord at gmail.com wrote: > Rad [Visual C# MVP] wrote: > > On Sun, 24 Dec 2006 16:36:31 +0100, Stef Mientki wrote: > > > > > Dustan wrote: > > >> Kleine Aap wrote: > > >>> Asper Faner wrote: > > >>> > > >>>> I seem to always have hard time understaing how this regular expression > > >>>> works, especially how on earth do people bring it up as part of > > >>>> computer programming language. Natural language processing seems not > > >>>> enough to explain by the way. Why no eliminate it ? > > Hi folks, fairly new to the list(Python is my first programming > language, so I'm fairly new to the world of programming too)but this is > a question I've been wondering about since I started learning about the > re module. Are regular expressions what makes mark up languages > interpretable by webbrowsers? I don't actually know the answer, but my educated guess: Regular expressions are just the simplest way to parse any text, but there are other ways. Webbrowsers most likely depend on regular expressions just because it's a relatively quick and easy way to interpret the language. From greg at cosc.canterbury.ac.nz Sat Dec 16 02:22:14 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 20:22:14 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1166200235.110121.172160@f1g2000cwa.googlegroups.com> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <1166200235.110121.172160@f1g2000cwa.googlegroups.com> Message-ID: <4uhl83F108ri8U5@mid.individual.net> philip.armitage at gmail.com wrote: > Then bring in more statement and you either have to > remember precedence rules (I can never remember those) or add some > parenthesis (oops!). Probably you've been burned by C, which has a ridiculously large number of precedence levels -- I don't know *anyone* who can remember them all. Most people just remember a subset and use parens for everything else. Pascal had four levels, which was easy to remember but not really enough. About six or seven seems optimal to me. Python, incidentally, has rather too many (it seems to have caught this disease from C). -- Greg From jjl at pobox.com Sat Dec 30 16:11:43 2006 From: jjl at pobox.com (John J. Lee) Date: Sat, 30 Dec 2006 21:11:43 GMT Subject: Wow, Python much faster than MatLab References: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl> <1167449722.106162.93380@k21g2000cwa.googlegroups.com> <45966848$0$11868$3b214f66@tunews.univie.ac.at> <3acb7$4596767d$d443bb3a$7444@news.speedlinq.nl> Message-ID: <87vejtf5sd.fsf@pobox.com> Stef Mientki writes: > Mathias Panzenboeck wrote: > > A other great thing: With rpy you have R bindings for python. > > forgive my ignorance, what's R, rpy ? > Or is only relevant for Linux users ? [...] R is a language / environment for statistical programming. RPy is a Python interface to let you use R from Python. I think they both run on both Windows and Linux. http://www.r-project.org/ http://rpy.sourceforge.net/ John From duncan.booth at invalid.invalid Tue Dec 5 03:42:49 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Dec 2006 08:42:49 GMT Subject: decorators question References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> Message-ID: "king kikapu" wrote: > Hmmm...ok...it calls the decorator but when ?? It (the runtime) loads > the .py file and start to call every decorator > it finds on it, regardless of the existance of code that actually calls > the decorated functions ?? > I understand thet Python does not call the decoratated functiond but it > ends up this way... Try this code to help you understand what is going on: ----------- t.py ---------------- import inspect def adecorator(f): print "decorating", f.__name__, inspect.getargspec(f) return f def makeargument(n): print "makeargument", n, "called" return n print "for loop coming up" for i in range(3): print "in for loop, iteration", i @adecorator def fn(x=makeargument(i)): print "fn called, x=", x print "end of iteration", i print "now call fn" fn() print "done" --------------------------------- Run it and the output shows you clearly when each element executes. Note in particular that the def statement inside the loop executes every time through the loop and each time it creates a new function (which differs only in the default argument value), the default argument is evaluated when the def executes, NOT when the function is called. The decorator is called after the def executes and before the next statement. At the end of the for loop we are left only with the last definition of fn: the others are overwritten during the loop. The output looks like this: C:\temp>t.py for loop coming up in for loop, iteration 0 makeargument 0 called decorating fn (['x'], None, None, (0,)) end of iteration 0 in for loop, iteration 1 makeargument 1 called decorating fn (['x'], None, None, (1,)) end of iteration 1 in for loop, iteration 2 makeargument 2 called decorating fn (['x'], None, None, (2,)) end of iteration 2 now call fn fn called, x= 2 done From dborne at gmail.com Tue Dec 26 10:02:30 2006 From: dborne at gmail.com (Dave Borne) Date: Tue, 26 Dec 2006 09:02:30 -0600 Subject: Formatting a string to be a columned block of text In-Reply-To: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> References: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> Message-ID: <6e42ec490612260702g39630f98q2cae89067b40c6e5@mail.gmail.com> On 26 Dec 2006 04:14:27 -0800, Leon wrote: > I'm creating a python script that can take a string and print it to the > screen as a simple multi-columned block of mono-spaced, unhyphenated > text based on a specified character width and line hight for a column. Hi, Leon, For putting the columns together zip is your friend. Let me lay out an example: # get your text and strip the newlines: testdata = file('something').read().replace('\n','') # set some parameters (these are arbitrary, pick what you need):: colwidth = 35 colheight = 20 numcol = 2 rowperpage = colheight * numcol # first split into lines (this ignores word boundaries # you might want to use somehting more like placid posted for this) data1 = [testdata[x:x+colwidth] for x in range(0,len(testdata),colwidth)] # next pad out the list to be an even number of rows - this will give # a short final column. If you want them balanced you're on your own ;) data1.extend(['' for x in range(rowsperpage - len(data1) % rowsperpage)]) # then split up the list based on the column length you want: data2 = [data1[x:x+colheight] for x in range(0,len(data1),colheight)] # then use zip to transpose the lists into columns pages = [zip(*data2[x:x+numcol]) for x in range(0,len(data2),numcol)] # finally unpack this data with some loops and print: for page in pages: for line in page: for column in line: print ' %s ' % column, #<- note the comma keeps newlines out print '\n' print '\f' -dave From ask at me Sat Dec 9 00:04:02 2006 From: ask at me (alf) Date: Fri, 08 Dec 2006 23:04:02 -0600 Subject: where the extra space comes from on the stdout In-Reply-To: <1159831877.907144.171210@m73g2000cwd.googlegroups.com> References: <1159831877.907144.171210@m73g2000cwd.googlegroups.com> Message-ID: Simon Percivall wrote: > > You already got the answer, but as for the rest: It's really easier for > you if you use raw_input() for your question/input pair instead. > thx, this is what I was looking for, alf From thomasbartkus at comcast.net Sat Dec 2 11:33:42 2006 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Sat, 02 Dec 2006 10:33:42 -0600 Subject: Python, PostgreSQL, What next? References: <1165043076.979652.201730@16g2000cwy.googlegroups.com> Message-ID: On Fri, 01 Dec 2006 23:04:37 -0800, vbgunz wrote: > Hello all, > > I've studied Python and studied PostgreSQL. What is the absolute next > best step to take to merge these two finely together? I've heard of > SQLAlchemy and some others but before I dive in, I would really like > the opinion of those who tried it and other toolkits. > > My main concern is, I would like to completely work with a database > from Python. What would you suggest I look into? Let me venture that the biggest problem most people seem to have is that they endure great pain just to avoid learning SQL. SQL is a complete programming language in and of itself with a breadth and depth that most people miss. And it covers much terrain missed by Python. Which is a good thing because SQL and Python are perfect together. With this language mix you've got darn near everything licked. Get SQL in your head and all you will need would be the db-api interface with Postgres that Frederick Lundh pointed you to. All you want to do is throw SQL commands at Postgres and recover result sets into Python. It's a cinch. Thomas Bartkus From theller at ctypes.org Thu Dec 7 10:16:23 2006 From: theller at ctypes.org (Thomas Heller) Date: Thu, 07 Dec 2006 16:16:23 +0100 Subject: comtypes Message-ID: <45783047.1090400@ctypes.org> comtypes seems to gain some attention (comtypes is a pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.) I'll try to release a new version over the next days. However, I'm wondering what would be the correct list to discuss this package... - the python-win32 mailing list - the ctypes-users mailing list - or should I create a new comtypes-users mailing list, mirrored on gmane, of course? Thanks for any opinions, Thomas From st911 at rock.com Fri Dec 1 14:03:32 2006 From: st911 at rock.com (st911 at rock.com) Date: 1 Dec 2006 11:03:32 -0800 Subject: Watch Alex Jones' Terror Storm, Bohemian Grove, Arrest Video, on video.google.com and infowars.com Message-ID: <1164999812.186342.150370@n67g2000cwd.googlegroups.com> The one who digs a trap for others falls into it himself. - Moral law of all religions. ====================== Our confidence in 911 controlled demolition is such that we have invited people to see the truth under the pretext of debunking it. This letter was sent to professors in many US/Europe/China/India/Brazil Universities and please do not hesitate to duplicate. Volunteers are needed. Now please send this to county police stations, fire chiefs, City governments, police sheriffs, judges, magistrates, doctors, lawyers, highschools and all institutions of civil govermnents. ====================== Dear Professor, Ever since the crime of the century on 9/11/2001, there have been many conspiracy theories woven around the incident, and even 1 Million challenge/reward has been posted: http://reopen911.org/Contest.htm Some say that jet fuel cannot melt iron because car accident fires and plane fires have never melted even the steel body of the car or the aluminum body of the plane involved in a traffic accident. Only thermite can melt so much so fast. The conspiracy theorists have erected an enormous body of evidence and we APPEAL you to apply your intellectual power to the known facts and debunk the conspiracy theorists who are now the university professors and a blot on your occupation. Much of their theory is based on the hypothesis of CONTROLLED DEMOLITION based on compositional analysis, finding numerous pieces of columns with diagonal cuts for ejection, pyroclastic flow from pulverization of concrete into fluidized dust, and numerous testimonies of explosions, which they present in videos on the internet. They object that the pentagon was not hit by a plane and FBI confiscated all the pentagon videos. Furthermore, they have shown by producing a side by side video of Osama that his confession video is a fake, and they call it a synthetic terror. Please visit their sites to debunk their spins: www.scholarsfor911truth.org www.journalof911studies.org http://www.journalof911studies.com/JonesAnswersQuestionsWorldTradeCenter.pdf They are using videos to make a spin in the tradition of Edward L Bernays (Freud's Nephew, see wikipedia on him, and watch the video on how he broke the taboo and convinced women to smoke.). They claim that the government used explosives to bring down the buildings in controlled demolition, and used thermate to manufacture molten metal pools to put the blame on smoky jet fuel fire which is ice cold for melting steel. Please search google web for thermate using this link: http://www.google.com/search?as_q=&num=100&as_epq=thermate In the results you will find these videos that show their argument on thermate in brief: http://www.supportthetruth.com/jones.php http://www.youtube.com/watch?v=_wVLeKwSkXA&mode=related http://video.google.com/videoplay?docid=-4757274759497686216 They have put popular mechanics in retreat as in this audio debate with popular mechanics 5MB Audio download: http://www.911podcasts.com/display.php?vid=158 found via http://911blogger.com/node/2278?page=2 ============================================================== They are also calling professor Noam Chomsky as the gate keeper of the left. Here are the links: Here's the discovery path: On st911.org visit this: Hugo Chavez and the sulfuric odor of "devil" Bush 22 September 2006, onlinejournal.com, Larry Chin http://onlinejournal.com/artman/publish/article_1234.shtml There, visit this: Alternative Media Censorship http://questionsquestions.net/gatekeepers.html ============================================================== There are a lot of government grants available for research on this subject intimately linked to terrorism. We ask you as concerned citizens to exert your intellectual capabilities on this subject and give an ethical public opinion. If you can find a general thermodynamic type result that their conspiracy theory is impossible and that the cars that burn in accidents can melt their steel body and planes can melt their aluminum from jet fuel or a plane crash can quickly cause mixing of the needed reactants to produce a fast thermate reaction with sulfur from the gypsum wall board, the Administration would have won. Thank you for your time, fortitude and intellectual honesty. If you know someone in departments of Mechanical Engineering, Structural Engineering, Combustion Science and Engineering, Chemistry, Physics, Materials Science, Metallurgy who would have expertise in the subject, please pass on the email and just view the videos as a responsible informed citizen and for its highly entertaining value. There is also a lot of material to work with for your subject area of research and study. Concerned Citizens Appeal to you !!! We have sent this email to select recipients who will be proud of the government and know how to propagate the information intelligently. http://portland.indymedia.org/en/2006/06/341238.shtml If any of the video links dont work, and censored, just visit video.google.com and also youtube.com and search for terms like "thermate" "911 fraud" "steven jones" "alex jones" and you shall find a lot of stuff. Finally one more video archive: http://oldamericancentury.com/video_arch.htm Please prove your government right so that you can be again proud of it. Sincerely, Wolfgang Aushner Concerned Citizens Appeal to you one last time thru this email !!! ============================================================== THEY REJECT CONFESSION VIDEOS BASED ON THE BIO-METRICS MISMATCH of fat-nosed Osama with the actual Osama. American Patriot Friends Network http://www.apfn.org/apfn/WTC_STF.htm ============================================================== Here's their argument from one website: The exact goal of 9/11 was to create the appearance of a terrorist operation and large death toll. Some people had to be sacrificed and the ideological motive came from the training in skull and bones and the Bohemian Grove that Alex Jones has so admirably exposed in a great piece of investigative journalism and the full video of his penetration in that evil bohemian grove is on google. Although the building was demolished, intentionally with people inside, the blame for demolition had to be put on the "terrorists" and a plausible agent had to be found. The only plausible agent that could be found was fire. The impact of the plane could not bring the buildings down. If fire had to be made the scapegoat, and fire was not, thermite was to do its job secretly and put the blame on the jet fuel. They thought that the dynamics of combustion and fire is complex enough that people will not be able to figure it out. Thats why thermate was used. Unfortunately, this is their undoing as thermate was a single piece of evidence that shows the inside job. Someone had to plant it. Once our minds became free and we were on the right track of thinking, we began to see even more. Dust and paper => explosives, ie shattering agent. Horizontal ejection velocity => an agent other than gravity. Demolition wave ahead of free fall => not just explosives but synchronized explosives. WT7 without plane hitting => to reinforce the illusion of fire, but it is a demolition Who had the means, motive and opportunity ? Marvin Bush ran the security firm. There were power shutdowns to disable security cameras. The detonation cables were laid down under the pretext of ethernet cables. Were coaxials were used to synchronize explosions??? Bomb sniffing dogs were removed to prevent discovery. The gatekeeper robbed the bank. Most successful bank robberies involve a conspiracy of inside job. ======================== From nono at hotmail.com Sat Dec 23 08:15:52 2006 From: nono at hotmail.com (Osiris) Date: Sat, 23 Dec 2006 14:15:52 +0100 Subject: Newbie: what is a usefull IDE for Python on Windows ? References: Message-ID: btw: my system is an AMD 1.8 GHz, 512 Mbyte with WinXPSP2. I saw that a system like Wing would be sluggish ... From kentilton at gmail.com Sat Dec 9 12:54:49 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 12:54:49 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> Message-ID: Steven D'Aprano wrote: > Some languages are too expressive. :) > Look, all snarkiness aside, it just isn't true that "stuff like this is > impossible in other languages". If Wolfram Fenske had said "stuff like > this isn't easy in many other languages" he would have been right. Remember, Lisp macros are like being able to run a preprocessor on an ad-hoc basis. Without Lisp compilers (er, should I say the Lisp "reader"?) understanding macros and macro functions, not even Lisp could transform source code this way. We won't have an intelligent discussion on macros until this gets better understood. Macros are not about what one can do at run-time, they are about what happens at compile time. If your compiler/preprocessor/IDE are not going to cooperate, then embedding a preprocessed language in Python is so hard as to be unfeasible. I also would not quibble over "impossible" vs. "incredibly hard". The bottom line is that at a pretty low level hard becomes "aint gonna happen". > And if > he had said "and stuff like this carries risks as well as benefits" he > would have come across as less of a language fanatic. > > One of the risks with Python is the ease with which you can modify the > built-ins. An expression like list(2, 3, 4) doesn't necessarily create a > list from 2, 3, and 4, because the built-in list could be redefined. > (In practice, that's not often a real problem, because experienced > Python developers simply learn not to needlessly or confusingly shadow > built-ins. Well, duuhhhhh. This the Great Strawman, that Lisp programmers (a) love having a powerful language (b) so they can produce unreadable code. This nonsense is an implicit concession that you have no point at all. > It's not the best system, but it works well enough in > practice.) But at least the basic syntax and keywords of the language are > known to be constant. > > With Lisp macros, even that isn't guaranteed. Now, if Lispers would say > "Oh yes, macros give you great power, and with great power comes great > responsibility. Be careful." I have to admit you are probably still catching up on what I have written today. > then, no doubt, we'd take you guys more > seriously. But we don't hear that -- we hear Lispers going on and on about > how great it is that they can easily redefine every corner of the > language. You have this tendency as your paragraphs grow to get sillier and sillier and make up more and more hobgoblin crap, I suppose as you sense the weakness of your case. Can you point to where someone said that? No, of course not. Get a grip, will you, this could be a useful cultural exchange, but not with your hysterics. > why do you need > macros then if you are just using them as functions? Why not use functions? Hint: famous Lisp style rule: never use a macro where a function will do. Not sure it is worth wasting more time on you at this point or I would offer examples. Could you calm down a bit and stop making things up? ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From google at mrabarnett.plus.com Tue Dec 5 18:46:26 2006 From: google at mrabarnett.plus.com (MRAB) Date: 5 Dec 2006 15:46:26 -0800 Subject: Ensure a variable is divisible by 4 In-Reply-To: References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: <1165362386.721515.319360@l12g2000cwl.googlegroups.com> Jonathan Smith wrote: > > wrote in message > > news:1165252238.866708.293510 at j72g2000cwa.googlegroups.com... > >> I am sure this is a basic math issue, but is there a better way to > >> ensure an int variable is divisible by 4 than by doing the following; > >> > >> x = 111 > >> x = (x /4) * 4 > >> > >> Just seems a bit clunky to me. > > > if ( x % 4 ) == 0: > whatever # x is divisible by 4 > > modulus is your friend :) > > -smithj It's "modulo"; "modulus" is a different operation. From fredrik at pythonware.com Sun Dec 3 11:25:47 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 03 Dec 2006 17:25:47 +0100 Subject: Deleting from a list while iterating In-Reply-To: <1165162289.610285.126530@73g2000cwn.googlegroups.com> References: <1165160235.282030.96610@79g2000cws.googlegroups.com> <1165162289.610285.126530@73g2000cwn.googlegroups.com> Message-ID: Rhamphoryncus wrote: > Sorry, I should have clarified that the original post assumed you > needed info from the "do something" phase to determine if an element is > removed or not. As you say, a list comprehension is superior if that > is not necessary. that's spelled out = [] for i in items: ... do something ... if i > 0.5: out.append(i) in Python, and is only a little slower than a list comprehension, as written above. if performance is really important, move the method lookup out of the loop: out = [] append = out.append for i in items: ... do something ... if i > 0.5: append(i) From no-spam at no-spam-no-spam.invalid Sun Dec 10 16:15:24 2006 From: no-spam at no-spam-no-spam.invalid (robert) Date: Sun, 10 Dec 2006 22:15:24 +0100 Subject: GA/optimizer frameworks with automatic adjustment of mut/cross extent ? Message-ID: I'm looking for an efficient optimizer on a noisy high-dimensional and costly function. My own GA hack seems to be somewhat stiff and I find me trying too much around with different cooling speeds and other non-systematic screwing ... There are some GA frameworks and recipes around for Python (that one of scipy (scipy.ga?) disapeared?). Which can be recommended? The searching in my use cases is mainly on fixed length parameter vectors (float and integer ranges). Just a few use cases on chromosome-bits and complex variable length structure building. My main concern is about a smart, general and robust population alteration - an automatic selection of mutation/crossover-random-step-ranges and mutation/crossover-ratio. And possibly a dynamic population/selection scheme also. The mutation function accepts a vector with step-width's 0..inf (default 1.0) for each parameter/gene. And the crossover function accepts a scalar 0 .. 1.0 controlling the extent of crossover. Thus: def mutate(obj, astepstd=[1.0,1.0,1.0,...]): ... def crossover(obj, other, extent=0.5): ... The good optimizer alg which I think of should be smart enough to dynamically auto-adjust based the optimization history (independently of the task): * astepstd's * extent * crossover/mutate rate (* dynamic population size and selection-scheme) Any recommendations or hints? Robert From gagsl-py at yahoo.com.ar Wed Dec 27 20:03:22 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 27 Dec 2006 22:03:22 -0300 Subject: DOS, UNIX and tabs In-Reply-To: <87wt4daqbf.fsf@benfinney.id.au> References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <87wt4daqbf.fsf@benfinney.id.au> Message-ID: <7.0.1.0.0.20061227215512.046895b0@yahoo.com.ar> At Wednesday 27/12/2006 20:09, Ben Finney wrote: > > The python style guide [1] recommends four spaces per indentation > > level. > > > > [1] http://www.python.org/dev/peps/pep-0008/ > >It's not quite absolute on the topic: > > For new projects, spaces-only are strongly recommended over tabs. Of course you can do it anyway you like, but you should have a *strong* reason for not following a *strong* recommendation. (Just a note, you can use untabify.py (inside the Tools dir) to convert tabs to spaces, instead of unexpand) -- 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 From bj_666 at gmx.net Wed Dec 27 17:27:08 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 27 Dec 2006 23:27:08 +0100 Subject: Feasible in Python ? list of object , with two exeptional objects References: <6eo5p2di7lrcs5smouhg8ju83901b4hld0@4ax.com> Message-ID: In <6eo5p2di7lrcs5smouhg8ju83901b4hld0 at 4ax.com>, Osiris wrote: > I have an array (I come from C) of identical objects, called sections. > These sections have some feature, say a length, measured in mm, which > is calculated by a method A_length of the instantiation of the > Section's class. > Only, two elements in the array (or list ?) have a length that must be > calculated according to a totally different procedure, a different > function or method. Is this something that the instances of section "know" or is some external "knowledge" needed to identify those special objects? > After calculation of ALL the lengths, they must be added together and > output. > The calculation procedure screams for a FOR or a WHILE loop allong the > list of sections, only those two sections mentioned make life > difficult. Sounds like something like ``sum(section.length() for section in sections)``. Your description is a bit vague. Where and how do you start to treat the objects different. Is it possible to decide at instantiation time to create a `Section` object or a `SpecialSection` object? How much different is the calculation? Do you need two separate classes or just one with a flag or maybe a function as argument to the `__init__()` method? Are you writing the `Section` class(es) just for this calculation or do they contain other behavior too? Ciao, Marc 'BlackJack' Rintsch From clarence1126 at gmail.com Tue Dec 12 20:43:56 2006 From: clarence1126 at gmail.com (Clarence) Date: 12 Dec 2006 17:43:56 -0800 Subject: -W: Python bug? Documentation bug? References: <1165972171.158876.164660@73g2000cwn.googlegroups.com> Message-ID: <1165974236.292269.46980@f1g2000cwa.googlegroups.com> Clarence wrote: > It appears that the -W option on starting python doesn't work the same > as the warnings module. In particular, the "message" parameter is not > treated as a regular expression, but rather a string literal which must > appear at the beginning of a warning message in order to match. The I must have gotten confused during my testing. The behavior is the same whether coming from the command line or from within the program. However, I see that the regular expression is being tested using re.match rather than re.search. Does that seem correct to people? At the least, that should be mentioned in the documentation. From SPAM-IS-batkins57-FOR-LOSERS at gmail.com Sun Dec 17 02:28:05 2006 From: SPAM-IS-batkins57-FOR-LOSERS at gmail.com (Bill Atkins) Date: Sun, 17 Dec 2006 02:28:05 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> Message-ID: greg writes: > Andr? Thieme wrote: >> (aif (timeConsumingCalculation) >> (use it)) > > I think the answer is that you just wouldn't do > that in Python at all. Having magic variables > spring into existence in your local namespace > as a side effect of calling something is just > not Pythonic. (It is very Perlish, on the other > hand.) Anaphoric macros are controversial in CL, too, for just that reason. But there are a parallel set of macros that explicitly bind a variable so you can get the convenience without the weirdness: (bif (items (remove-if-not #'useful-p big-list-o-items)) (format t "~D items~%" (length items)) (format t "Nothing useful.~%")) You can rewrite the expression in the grandparent as: (aif (result (timeConsumingCalculation)) (use result) or, more idiomatically: (awhen (result (time-counsuming-calculation)) (use result)) From timr at probo.com Sat Dec 30 00:19:49 2006 From: timr at probo.com (Tim Roberts) Date: Sat, 30 Dec 2006 05:19:49 GMT Subject: Help with small program References: <1166966360.384179.101400@48g2000cwx.googlegroups.com> <1166979265.284345.173840@48g2000cwx.googlegroups.com> <4v94fuF1avmp3U1@mid.individual.net> <4v95b8F1b5csnU1@mid.individual.net> <1167270942.421817.280490@n51g2000cwc.googlegroups.com> Message-ID: gokkog at yahoo.com wrote: > >Interesting impl in Python! I am wondering what if the requirement is >to find the minimum number of coins which added to the "fin" sum... Given the set of coins in the original problem (100, 10, 5, 1, 0.5), the solution it provides will always be optimal. Even if we change this to American coinage (50, 25, 10, 5, 1), I believe it is still optimal. It is certainly possible to construct a set of denominations for which the algorithm occasionally chooses badly. For example, if you give it the set (40,35,10) and ask it to make change for 70, it will be suboptimal. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From S.Mientki-nospam at mailbox.kun.nl Thu Dec 28 13:49:53 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Thu, 28 Dec 2006 19:49:53 +0100 Subject: How to return a simple variable from a function (still newbie) ? In-Reply-To: References: <4593E2A6.6030804@eventuallyanyway.com> Message-ID: <8059c$459411c0$d443bb3a$4279@news.speedlinq.nl> Carsten Haese wrote: > On Thu, 2006-12-28 at 15:28 +0000, Paul Hummer wrote: >> You'd have to either pass the variables by reference into the function, [...] > > In Python, all function calls are call by reference. Period. The key > difference between Python and other programming languages is in the > behavior of the assignment statement. > > To paraphrase http://effbot.org/zone/python-objects.htm : > > In C/C++, assignments modify objects by copying the value from the right > hand side into the memory allocated to the object on the left hand side. > > In Python, assignments modify namespaces by making the name on the left > hand side become a reference to the object on the right hand side. It is > irrelevant whether the name referred to some other object before the > assignment, and it is irrelevant whether that object is mutable or not. > > The only way to achieve call-by-reference-like behavior in the > "assignment modifies objects" sense is by passing a reference to a > mutable object and then invoking the object's methods to mutate it. > Maybe that's what you meant, but that wasn't clear from what you said. > > -Carsten > > Laszlo, Carsten, Paul, Marc, thanks for your valuable input, I'm beginning to see the light, but it's still very dimmed. Not only Python looks much more promising than MatLab, but the also the Python newsgroup is much more helpfull than ... ;-) Maybe one of you could give me hint to solve the next problem (copied from one of my Matlab procedures ;-) I can find a solution (= something that works) myself, but I have the feeling this is completely the wrong way to go . # filter a chunk of a continuous signal IOI, # so a continuous filtered signal is created. # The function itself returns the filtered signal IOO, # now to handle the chunks and create a continuous signal # we must preserve a piece of history: "filter_prev" # so this should either be an input and output variable def chunk_Filter (filter_b, filter_a, Signal_IN, filter_prev): Extended = r_ [filter_prev, Signal_IN] filter_prev = Extended [ len(Signal_IN) : ] Extended = signal.lfilter(filter_b, filter_a, Extended) Signal_OUT = Extended [ len(filter_prev) : ] return Signal_OUT # call the function with actual parameters IOO = chunk_Filter (BP_filter_b, BP_filter_a, IOI, BP_filter_prev) When I replace the assignment to "filter_prev", by a loop, the function works as expected. #filter_prev = Extended [ len(Signal_IN) : ] for i in range( len(filter_prev )): filter_prev[i] = Extended [ len(Signal_IN) + i ] I can not use a global variable here, because this function should be called for several signals, each of course with it's own history. thanks, Stef From nagle at animats.com Wed Dec 27 13:38:14 2006 From: nagle at animats.com (John Nagle) Date: Wed, 27 Dec 2006 10:38:14 -0800 Subject: BeautifulSoup bug when ">>>" found in attribute value In-Reply-To: References: Message-ID: Duncan Booth wrote: > John Nagle wrote: > > >>And this came out, via prettify: >> >>>url="http%3A//www.apartmentsapart.com/Europe/Spain/Madrid/FAQ"> >> > value="/images/offersBanners/sw04.swf?binfot=We offer >>fantastic rates for selected weeks or days!!&blinkt=Click here >>>>>&linkurl=/Europe/Spain/Madrid/Apartments/Offer/2408"> >> >>>>&linkurl;=/Europe/Spain/Madrid/Apartments/Offer/2408" /> >> >> >> >>BeautifulSoup seems to have become confused by the ">>>" within >>a quoted attribute value. It first parsed it right, but then stuck >>in an extra, totally bogus line. Note the entity "&linkurl;", which >>appears nowhere in the original. It looks like code to handle a >>missing quote mark did the wrong thing. > > > I don't think I would quibble with what BeautifulSoup extracted from that > mess. The input isn't valid HTML so any output has to be guessing at what > was meant. A lot of code for parsing html would assume that there was a > quote missing and the tag was terminated by the first '>'. IE and Firefox > seem to assume that the '>' is allowed inside the attribute. BeautifulSoup > seems to have given you the best of both worlds: the attribute is parsed to > the closing quote, but the tag itself ends at the first '>'. > > As for inserting a semicolon after linkurl, I think you'll find it is just > being nice and cleaning up an unterminated entity. Browsers (or at least > IE) will often accept entities without the terminating semicolon, so that's > a common problem in badly formed html that BeautifulSoup can fix. It's worse than that. Look at the last line of BeautifulSoup output: &linkurl;=/Europe/Spain/Madrid/Apartments/Offer/2408" /> That "/>" doesn't match anything. We're outside a tag at that point. And it was introduced by BeautifulSoup. That's both wrong and puzzling; given that this was created from a parse tree, that type of error shouldn't ever happen. This looks like the parser didn't delete a string item after deciding it was actually part of a tag. John Nagle From nmm1 at cus.cam.ac.uk Thu Dec 14 10:57:22 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 14 Dec 2006 15:57:22 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: In article , "Fredrik Lundh" writes: |> |> > The point is that an index method makes sense on ANY data structure that |> > can be subscripted by an integer value but, for reasons that aren't at |> > all clear, is not defined for Python tuples. There is no technical or |> > mathematical reason why it shouldn't be. |> |> so where would you put such an "index" implementation so it would work on |> ANY data structure that can be subscripted by an integer value ? In the same place you put the subscription method, clearly. I really don't see the problem. I can see that it has not been done because Guido and others felt that it wasn't worth doing, but not that it is hard to do. Regards, Nick Maclaren. From ejatsomewhere.com Wed Dec 27 18:54:45 2006 From: ejatsomewhere.com (Erik Johnson) Date: Wed, 27 Dec 2006 16:54:45 -0700 Subject: persistant gloabl vars (very newbie) ? References: <4592af12$1@nntp.zianet.com> <411f8$4592c9fe$d443bb3a$30198@news.speedlinq.nl> Message-ID: <459307ec$1@nntp.zianet.com> > but it's still not quit handy > > # initialization file (init1.py) > import time; > xx = 44 > > # main file was > print xx > x=time.time() > > # main file should become > print init1.xx > x=init1.time.time() > > so even for the "standard" functions like "time" I've to include the > preceeding module "init1" :-( Ummm... does this help? /src/python/Foo> cat init.py #! /usr/local/bin/python from time import time xx = 44 /src/python/Foo> python Python 2.3.4 (#1, Feb 7 2005, 15:50:45) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from init import * >>> dir() ['__builtins__', '__doc__', '__file__', '__name__', 'time', 'xx'] >>> xx 44 >>> time >>> time() 1167262478.6845641 >>> xx = 42 # this does not change the init module's value! >>> import init >>> init.xx 44 As Piet points out, you get a copy of variables defined in a module when using the from module import * syntax (as is demonstrated by the assignment above). (And I stand corrected on the notion that you could execute "from module import *" in other than module level scope.) If it is your intention to use those variables defined in init to communicate with other modules making the same sort of import, then you probably don't want to use "from module import *" syntax. In that case, you can import just the module, and make assignments into that module's namespace. (e.g., init.xx = 3) If all you care about is getting some "stuff" into your global namespace in a convenient and repeatable way, then I think what I showed both above and originally is fine. -ej From bj_666 at gmx.net Mon Dec 11 12:28:38 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Mon, 11 Dec 2006 18:28:38 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <7xslfmju4g.fsf@ruckus.brouhaha.com> Message-ID: In <7xslfmju4g.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Marc 'BlackJack' Rintsch writes: >> FYI: Here's how Nemerle does macros: http://nemerle.org/Macros >> >> I guess you can't really transform Nemerle into a completely different >> language, but it is at least interesting to see such a feature in language >> with a more complex syntax than Lisp. > > Nobody seems to concerned that Haskell lacks macros. What's up with that? Hm, right from the Nemerle macro page linked above: We are following them in the direction of much more powerful, and at the same time more secure (type-safe) solutions like Haskell Template Meta-programming. So there seems to be something macro-like for Haskell. Ciao, Marc 'BlackJack' Rintsch From udodenko at users.sourceforge.net Sat Dec 9 14:40:23 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sat, 9 Dec 2006 21:40:23 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> Message-ID: <457b1129$0$49203$14726298@news.sunsite.dk> (message (Hello 'Paul) (you :wrote :on '(09 Dec 2006 01:01:14 -0800)) ( PR> If Common Lisp didn't have lexically scoped variables (most Lisp PR> dialects before Scheme didn't have them) then it would be very PR> difficult to add that with macros. i think there's some way to hack that. for example, make defun a macro that will collect all lexically scoped variable and mangle them. for example: (defun foo () (let ((i 1)) (print i))) will be transformed to (defun foo () (let ((i_foo 1)) (print i_foo))) (or just some random suffix). this way variables in different functions will never collide. maybe there's a catch somewhere, but that should look very close to lexical variables. PR> Do you seriously think lexical scoping is the last word in language PR> features and that there's now nothing left in other languages that PR> can't straightforwardly be done in CL? Hint: PR> call-with-current-continuation (also known as call/cc). there's nothing impossible :) we even have a lib for nondeterministic calculations -- Screamer, that's much much more cool than that call/cc.. (defun pythagorean-triples (n) (all-values (let ((a (an-integer-between 1 n)) (b (an-integer-between 1 n)) (c (an-integer-between 1 n))) (unless (= (+ (* a a) (* b b)) (* c c)) (fail)) (list a b c)))) you define ranges for variables, define constraints (in a form very close to normal lisp code) and then just say -- all-values, or solutions (first thing that satisfies constaints). ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From gagsl-py at yahoo.com.ar Wed Dec 27 16:51:36 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 27 Dec 2006 18:51:36 -0300 Subject: how can I modify an imported variable ? In-Reply-To: References: Message-ID: <7.0.1.0.0.20061227184407.052bc3c0@yahoo.com.ar> At Wednesday 27/12/2006 13:45, yomgui wrote: >your sample code works, but mine doesn't. >it must be a multi-thread issue. >I am certain that I am modifying MyPackage.aVariable >before using it. > >Both threads are importing MyPackage, >but the modification of MyPackage.aVariable >is not seen by the other thread. is this possible ? Put some print statements and see what happens. I'm sure things are a lot simpler than you think. You said a module, but now you use MyPackage - how do you assign to MyPackage.aVariable? inside its __init__.py? -- 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 From bearophileHUGS at lycos.com Fri Dec 15 10:51:48 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 15 Dec 2006 07:51:48 -0800 Subject: AI library In-Reply-To: <1166190477.577332.217060@73g2000cwn.googlegroups.com> References: <7CAC08AF-8C32-11DB-AD4B-000D93463186%felix.benner@imail.de> <1166190477.577332.217060@73g2000cwn.googlegroups.com> Message-ID: <1166197908.611429.232520@j72g2000cwa.googlegroups.com> Gabriel Genellina: > This is more stylish, but I prefer to use isxxx() or hasxxx() for > functions that return booleans. Lisp-like languages allow the ending ? or !, I think Ruby allows the ending ? too (allowing it with Python may be positive). Mathematica usually uses an ending uppercase Q, like PrimeQ, sometimes I use the ending Q in Python too. Bye, bearophile From e0427417 at student.tuwien.ac.at Sat Dec 9 17:48:55 2006 From: e0427417 at student.tuwien.ac.at (Mathias Panzenboeck) Date: Sat, 09 Dec 2006 23:48:55 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1165593283.523163.71730@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <1165593283.523163.71730@16g2000cwy.googlegroups.com> Message-ID: <457b3ca2$0$28520$3b214f66@tunews.univie.ac.at> Rob Thorpe wrote: > Mathias Panzenboeck wrote: >> Mark Tarver wrote: >>> How do you compare Python to Lisp? What specific advantages do you >>> think that one has over the other? >>> >>> Note I'm not a Python person and I have no axes to grind here. This is >>> just a question for my general education. >>> >>> Mark >>> >> I do not know much about Lisp. What I know is: >> Python is a imperative, object oriented dynamic language with duck typing, > > Yes, but Python also supports the functional style to some extent. > I currently visit a course about functional programming at the university of technology vienna: python implements only a small subset of things needed to be called a functional language (list comprehension). but yes, for a imperativ oop language python is very close to functional. >> List is a declarative, >> functional dynamic language > > Lisp is only a functional language in that it support both functional > and imperative programming styles. Duck typing is almost identical to > latent typing in Lisp. > And, Common Lisp at least is object orientated. > >> -> those two languages have different scopes. > > Their scope is actually very similar. Learn about lisp and you will > soon discover their similarity. > ic From carsten at uniqsys.com Mon Dec 4 17:36:20 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 04 Dec 2006 17:36:20 -0500 Subject: decorators question In-Reply-To: <1165269784.394649.7940@l12g2000cwl.googlegroups.com> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> <457476E6.5000603@youjoy.org> <1165269784.394649.7940@l12g2000cwl.googlegroups.com> Message-ID: <1165271780.3345.72.camel@dot.uniqsys.com> On Mon, 2006-12-04 at 14:03 -0800, king kikapu wrote: > I recap: if i put only functions declarations on a .py file, like > these: > def A(): print "a" > def B(): print "b" > def C(): print "c" > > and run the program, nothing happens, nothing executed. Nothing *visible* happens. The "def" statements *do* get executed. Executing the statement def A(): print "a" does the following, roughly, modulo irrelevant implementation details: * The function body gets compiled into byte code (but not executed). * A callable object with the byte code for the compiled function body is constructed. * The thusly constructed callable object is bound to the name A in your current namespace. So, a lot of stuff happens when the interpreter executes a def statement, but that stuff is not visible to you. Hope this helps, Carsten. From rampeters at gmail.com Sun Dec 10 08:10:15 2006 From: rampeters at gmail.com (johnny) Date: 10 Dec 2006 05:10:15 -0800 Subject: ATTRIBUTE ERROR: 'module' object has no attribute 'ssl' In-Reply-To: <1165753780.222613.180650@j72g2000cwa.googlegroups.com> References: <1165720787.910338.118940@j44g2000cwa.googlegroups.com> <1165753780.222613.180650@j72g2000cwa.googlegroups.com> Message-ID: <1165756215.897459.91850@16g2000cwy.googlegroups.com> I fixed it. I went to python site and downloaded the python 2.4 msi and extracted _ssl.lib and _ssl.pyd using winRar and put them into python/DLLs folder johnny wrote: > I am using ActiveState python. > > ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on > Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > > > Fredrik Lundh wrote: > > johnny wrote: > > > > > I am getting the following errors: > > > > > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in > > > _send_output > > > self.send(msg) > > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send > > > self.connect() > > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in > > > connect > > > ssl = socket.ssl(sock, self.key_file, self.cert_file) > > > AttributeError: 'module' object has no attribute 'ssl' > > > > looks like you're using a Python distribution that doesn't support SSL. > > ActivePython, perhaps? > > > > From bearophileHUGS at lycos.com Thu Dec 14 09:37:45 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 14 Dec 2006 06:37:45 -0800 Subject: speed of python vs matlab. In-Reply-To: <1166059648.320257.187310@j72g2000cwa.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> <1166059648.320257.187310@j72g2000cwa.googlegroups.com> Message-ID: <1166107064.994343.266890@l12g2000cwl.googlegroups.com> Chao, you can also try Psyco, applied on functions, and when necessary using its metaclass too. Bye, bearophile From bbrown at speakeasy.net Wed Dec 13 00:32:34 2006 From: bbrown at speakeasy.net (Robert Brown) Date: Wed, 13 Dec 2006 00:32:34 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <7xejr5y755.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Robert Brown writes: >> Luckily, Willem Broekema has written a Python to Lisp compiler called >> clpython that can be consulted to answer questions like these. >> >> http://trac.common-lisp.net/clpython/ > > Does this count as a "children of a lesser Python"? How does clpython > implement Python's immutable strings, for example? > > http://dirtsimple.org/2005/10/children-of-lesser-python.html I think CLPython is in the "children of a lesser Python" category, on the grounds that it doesn't implement the complete language and there's no obvious way to reuse the C packages that make CPython so useful. However, the other distinguishing feature of the "children" category is bending semantics to gain speed. CLPython doesn't appear to be doing much of this. The author says it runs at about the same speed as CPython. Python strings are implemented in CLPython as instances of a CLOS class, not as raw Common Lisp strings, so they appear to be immutable. From timothy.williams at nvl.army.mil Fri Dec 29 08:01:26 2006 From: timothy.williams at nvl.army.mil (timw.google) Date: 29 Dec 2006 05:01:26 -0800 Subject: INSERT statements not INSERTING when using mysql from python References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> <1167393801.950199.197830@48g2000cwx.googlegroups.com> <1167394098.642975.78350@73g2000cwn.googlegroups.com> <1167394662.665220.185680@a3g2000cwd.googlegroups.com> <1167395368.387567.283250@48g2000cwx.googlegroups.com> <1167396303.259891.144210@n51g2000cwc.googlegroups.com> Message-ID: <1167397286.819017.155930@k21g2000cwa.googlegroups.com> Not sure if this will help, as you said you already tried autocommit, but did you try to commit after creating the table, then doing all the inserts before commiting on disconnect? (I'm no MySQL or Python guru, but I do use it with python and MySQLdb .) From sjmachin at lexicon.net Tue Dec 5 06:07:05 2006 From: sjmachin at lexicon.net (John Machin) Date: 5 Dec 2006 03:07:05 -0800 Subject: win32 com problem In-Reply-To: <1165316228.944095.116310@79g2000cws.googlegroups.com> References: <1165316228.944095.116310@79g2000cws.googlegroups.com> Message-ID: <1165316825.234187.322900@73g2000cwn.googlegroups.com> Mike P wrote: > I've got a slight problem when running an excel macro from python using > the win32.com.client module, in that it says it can't load the DLL file Does it? All I see is a message that it can't find a macro. > (it doesn't say which one) What happens when you run the macro from the Excel UI? Have you tried using makepy? > > and gives me the following error message > > Traceback (most recent call last): > File "", line 93, in ? ??? It might help if you showed us the code that you are executing. > File ">", line 14, in Run > File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line > 258, in _ApplyTypes_ > result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, > argTypes) + args) > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, > 'Microsoft Office Excel', "The macro 'CTP.xla!sheet1.CTP' cannot be > found.", 'C:\\Program Files\\Microsoft > Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None) > > > Anybody have any ideas what this means? From sturlamolden at yahoo.no Thu Dec 14 09:37:06 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 14 Dec 2006 06:37:06 -0800 Subject: About alternatives to Matlab In-Reply-To: <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> <1166035311.357588.115070@80g2000cwy.googlegroups.com> <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1166107026.581075.129010@t46g2000cwa.googlegroups.com> Jon Harrop wrote: > Yes. The time taken is dominated by memory accesses. The amount of > arithmetic is almost irrelevant. That is extremely interesting. It would explain why I see almost the same performance in NumPy and Fortran 95 on this kind of task, using array slicing in both languages. From greg at cosc.canterbury.ac.nz Sat Dec 16 02:22:07 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 20:22:07 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <7xbqm4d97d.fsf@ruckus.brouhaha.com> Message-ID: <4uhl7sF108ri8U4@mid.individual.net> Andr? Thieme wrote: > So instead of > cmp(foo(a, b, c), bar(x, y, z)) you would prefer > foo(a, b, c) cmp bar(x, y, z) ? Incidentally, someone once came up with an fiendishly clever hack that lets you write things in Python like foo(a, b, c) |kmp| bar(x, y, z) i.e. effectively define your own infix operators. And it doesn't even require a macro. :-) (Finding the trick to implementing this is left as an exercise for the googler.) -- Greg From snobis at gmx.de Sat Dec 9 08:26:01 2006 From: snobis at gmx.de (Stefan Nobis) Date: Sat, 09 Dec 2006 14:26:01 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Message-ID: <87d56tkxp2.fsf@snobis.de> Steven D'Aprano writes: [Extensibility of syntax (via Lisp like macros)] > In the real world, programmers aren't lone wolves stalking the > programming landscape doing their own thing. Whether we're talking > open source projects maintained by volunteers, or commercial > software teams, standardized languages are a good thing. It is a > good thing that not every hare-brained idea that some random > programmer comes up with can be implemented as part of the core > language. Everything from functions over classes and class hierachies to macros are just ways to create your own personal language, to create abstractions. That's the whole point of high level languages: Say it your way. Create your (domain specific) vocabulary. (By the way: You must really hate Guido for allowing operator overloading in Python. It's exactly the same argument, nearly the same wording you used, that others used against operator overloading. You have to really love Java. :)) > It is a good thing that when Fred decides to stop contributing to an > open source project (or leave the company), other people can read > his code without having to learn his Uber-Special Custom Macro > Extended Language. You don't need macros for this kind of problem -- it's a really old problem, independend of language. There are assembler, C, Fortran, Java, Haskell, Lisp and many more hackers who write code, that's really hard to understand for other people. Heck, even in natural language there are many people who say or write things others have really trouble to understand. So what? Big class hierachies are always hard work to understand, even the very best designs of mankind. There is much Python code out there, that's really hard to understand. So Python is a bad language? No, quite not. So why do you think, Common Lisp or Macros are a bad thing? What's the difference (from the perspective of understanding) between a function foo and a macro bar? Both just transform their inputs. It's just another form of abstraction and from time to time really quite helpful. -- Stefan. From steve at REMOVE.THIS.cybersource.com.au Wed Dec 27 03:03:12 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Wed, 27 Dec 2006 19:03:12 +1100 Subject: loose methods : Smalltalk asPython References: Message-ID: On Tue, 26 Dec 2006 22:49:30 -0500, Jan Theodore Galkowski wrote: > Hi. > > One of the things I'd like to do with Python is find a way to > consistently implement Smalltalk's "loose methods". This is a > capability whereby additional methods can be added dynamically to > existing classes. You can't modify the built-in classes. I'm not sure that it is a good idea to allow built-ins to be modified. When I see an int, I like the fact that I know what the int can do, and I don't have to worry about whether it has been modified by some piece of code elsewhere. But custom classes can be modified (the risk of some other code modifying it is the price you pay for being able to customise the class in the first place): >>> class MyInt(int): ... pass ... >>> def odd(self): ... return bool(self % 2) ... >>> MyInt.odd = odd >>> n = MyInt(5) >>> n.odd() True > In some respects, it's possible with Python. While "object" cannot be > touched, it's possible to define > > class MutableObject( object ) : pass ; > > and derive subclasses from MutableObject instead of object. Thereafter, > for instance, if devising a class > > class Foo( MutableObject ) : isFoo = True ; ... > > you can also put in its module > > MutableObject.isFoo = False ; > > So, at least for the inheritance hierarchy descending from > MutableObject, for an arbitrary object instance x, > > x.isFoo > > will return whether it's a Foo or not, effectively although not > transparently extending the builtin type(.). Why not just say isinstance(x, Foo)? > Like, then, what of other classes which descend from object and not > MutableObject? You'd love to be able to set methods and attributes > within them. Can you? Yes you can. Did you bother to try it? >>> class Shrubbery(object): ... pass ... >>> Shrubbery.spam = lambda self, n: repr(self) + "spam"*n >>> >>> Shrubbery().spam(5) '<__main__.Shrubbery object at 0xb7d06aec>spamspamspamspamspam' -- Steven. From nnorwitz at gmail.com Fri Dec 22 23:51:26 2006 From: nnorwitz at gmail.com (nnorwitz at gmail.com) Date: 22 Dec 2006 20:51:26 -0800 Subject: Using Tools/freeze.py on AIX -- having problems In-Reply-To: <1166830874.761560.88550@73g2000cwn.googlegroups.com> References: <1166830874.761560.88550@73g2000cwn.googlegroups.com> Message-ID: <1166849486.424495.140650@42g2000cwt.googlegroups.com> jmalone at optio.com wrote: > > Python seems to install correctly for the most part ("make test" gives > a few messages about things that are not quite right (3 failed tests > (test_mmap, test_pty, & test_resource) and 2 unexpectedly skipped Don't worry about these. > Name File > ---- ---- > m _locale > /usr/local/lib/python2.4/lib-dynload/_locale.so > m _random > /usr/local/lib/python2.4/lib-dynload/_random.so > m _socket > /usr/local/lib/python2.4/lib-dynload/_socket.so > m array > /usr/local/lib/python2.4/lib-dynload/array.so > m binascii > /usr/local/lib/python2.4/lib-dynload/binascii.so [...] > generating table of frozen modules > Warning: unknown modules remain: _locale _random _socket array binascii > cStringIO collections fcntl itertools math select strop struct termios > time > Now run "make" in xfer to build the target: xfer > > After running make, here is the result of trying to execute the frozen > script: > > > > # ./xfer > Traceback (most recent call last): > File "xfer.py", line 2, in ? > File "/usr/local/lib/python2.4/socket.py", line 45, in ? > import _socket > ImportError: No module named _socket > # There's this note in freeze.py: """ The script should not use modules provided only as shared libraries; if it does, the resulting binary is not self-contained. """ I don't really remember much about freeze. IIRC, you will also need to copy the extension modules (I left them in above) in addition to 'xfer'. Try copying them into the same directory. You might need to set LIBPATH=. (or whatever the env't var is). On most Unixes, the env't var is LD_LIBRARY_PATH, but I recall AIX being different. If you want, you can just copy all the files from lib-dynload along with 'xfer'. HTH, n From rampeters at gmail.com Sun Dec 10 07:29:40 2006 From: rampeters at gmail.com (johnny) Date: 10 Dec 2006 04:29:40 -0800 Subject: ATTRIBUTE ERROR: 'module' object has no attribute 'ssl' In-Reply-To: References: <1165720787.910338.118940@j44g2000cwa.googlegroups.com> Message-ID: <1165753780.222613.180650@j72g2000cwa.googlegroups.com> I am using ActiveState python. ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> Fredrik Lundh wrote: > johnny wrote: > > > I am getting the following errors: > > > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in > > _send_output > > self.send(msg) > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send > > self.connect() > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in > > connect > > ssl = socket.ssl(sock, self.key_file, self.cert_file) > > AttributeError: 'module' object has no attribute 'ssl' > > looks like you're using a Python distribution that doesn't support SSL. > ActivePython, perhaps? > > From gagsl-py at yahoo.com.ar Tue Dec 12 05:11:55 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 02:11:55 -0800 Subject: Avoiding "invalid literal for int()" exception In-Reply-To: References: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> Message-ID: <1165918314.967089.99200@n67g2000cwd.googlegroups.com> Marc 'BlackJack' Rintsch ha escrito: > In , Gabriel > Genellina wrote: > > > elif uniList[0].isdigit(): > > The last does not work. Not only that it accepts numbers greater than 9 > because it checks if the whole string consists of digits, it also accepts > u'??' and other unicode digits. Oh, I didn't know that last part! Thanks. I get a bit confused by the [0], thinking it was checking a single character. -- Gabriel Genellina From grahamd at dscpl.com.au Wed Dec 6 17:55:58 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 6 Dec 2006 14:55:58 -0800 Subject: Mod_python vs. application server like CherryPy? References: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> <33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com> Message-ID: <1165445758.342163.37650@f1g2000cwa.googlegroups.com> Vincent Delporte wrote: > On 5 Dec 2006 17:05:06 -0800, "fumanchu" wrote: > >In a nutshell, mod_python gives you > >access from Python to the Apache API, whereas CherryPy and friends give > >you their own API. > > I didn't know Apache had an API of its own, or that it was even needed > when writing a web application in Python. What does it provide in > addition to Python/mod_python? Although Apache does have a quite considerable underlying API of its own, mod_python doesn't actually provide direct access to much of it from Python code. What mod_python does provide is still adequate for getting basic stuff done, but Apache could perhaps be better harnessed if all the Apache API were exposed and available. Where the power of Apache comes into play is the ability to compose together the functionality of different Apache modules to build up an application. That is, you aren't just doing everything in Python code. That said though, this doesn't mean you have to go off and write code in another language such as C. This is because the Apache modules are glued together through the Apache configuration files with some features also being able to be enabled from Python code running under mod_python. In some respects you need to see the whole of Apache as being a platform for building a web application. Unfortunately, most Python web application developers don't see that and simply use Apache as a convenient hopping off point for the main content handling phase of a request. Even where people do write stuff which makes use of mod_python as more than just a hopping off point, more often than not they still work within just mod_python and don't bring in other parts of Apache to any degree. For example, consider an extreme case such as WSGI. Through a goal of WSGI being portability it effectively ignores practically everything that Apache has to offer. Thus although Apache offers support for authentication and authorisation, a WSGI user would have to implement this functionality themselves or use a third party WSGI component that does it for them. Another example is Apache's support for enabling compression of content returned to a client. The WSGI approach is again to duplicate that functionality. Similarly with other Apache features such as URL rewriting, proxying, caching etc etc. Although WSGI is an extreme case because of the level it pitches at, other systems such as CherryPy and Django aren't much different as they effectively duplicate a lot of stuff that could be achieved using more basic functionality of Apache as well. Once one starts to make use of the underlying Apache functionality, you are binding yourself to Apache though and your stuff isn't portable to other web servers. Also, your job in part becomes more about integrating stuff to come up with a solution, rather than just writing pure Python code, something that many Python coders possibly wouldn't find appealing. :-) Graham From true911m at gmail.com Thu Dec 7 22:23:22 2006 From: true911m at gmail.com (true911) Date: 7 Dec 2006 19:23:22 -0800 Subject: problems caused by very large for-loop In-Reply-To: <1165540544.742681.143080@l12g2000cwl.googlegroups.com> References: <1165540544.742681.143080@l12g2000cwl.googlegroups.com> Message-ID: <1165548202.034834.308140@16g2000cwy.googlegroups.com> sam wrote: > hi all, > ... > has anyone else bumped up against this problem before? i suppose > for-loops with 250 million iterations are seldom used in most > applications. it was just the first time i'd ever solved a problem by > actually having some insight into how python works at a slightly lower > level. Sam, The problem is not with the 'for' operator, but the fact that the range() operator creates the iterable list (in this case, with 250 million elements) prior to beginning the loop. Try using xrange() with the same syntax, which returns items from a tuple (NOT a list, if it matters to you) just-in-time and discards them, much like FOR as used in a BASIC context. xrange() is somewhat less flexible, though, and may or may not suit your needs. If not, use 'while' instead, and set your own loop exit conditions. From listas at flavioribeiro.com Wed Dec 27 16:36:28 2006 From: listas at flavioribeiro.com (=?ISO-8859-1?Q?Fl=E1vio_Ribeiro?=) Date: Wed, 27 Dec 2006 18:36:28 -0300 Subject: problems with socket Message-ID: <873b128e0612271336l79ceb120u9d1ecbdf3b99625d@mail.gmail.com> Hi all, I will try to explain my problem, and wait for someone here give me solutions: (sorry for the bad, bad english) I have a server application that talks with another client applications using socket. The problem isnt this, i did and works very well. The problem is open the router port. The person who will use the server application wouldn't know how to open and configure the port using the modem web panel, and this job isnt for users, right? Anyone knows if i can do this remotely? Or have any solutions? Im thinking about make a central server application configured and hosted by me that will interact with the server and client application.. what do you think about?! have another solution? I hope that someone understand and help me.. thanks! -- Fl?vio Ribeiro listas at flavioribeiro.com www.flavioribeiro.com (83) 9952.1444 -------------- next part -------------- An HTML attachment was scrubbed... URL: From henrik.hjelte at gmail.com Fri Dec 8 11:17:01 2006 From: henrik.hjelte at gmail.com (hankhero) Date: 8 Dec 2006 08:17:01 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165594621.136524.198600@80g2000cwy.googlegroups.com> One overlooked advantage for Lisp over Python is a better development environment, for me that means Slime for Lisp. For Python I have several years of experience with IDLE and the win32 Ide, and Slime is the winner. Press a key and the function you are editing is recompiled and loaded into memory. The crossreference and the object inspector is very nice. How about fuzzy-complete, I only have to write de-me and press tab, and I get define-method-combination. Slime coupled with the paredit structured editing mode, which lets you edit Lisp code as list structure rather than characters, is a dream. Pythons advantages are: Faster startup-time which makes it a good scripting language. More platforms, there is no Common Lisp on Nokia phones. Some clever details, like using minus to index vectors from the right. (aref "hello" -1) gives an error on Lisp, but the character o on Python. Another detail I like is that you can choose how to quote strings, in Python you can write three double-quotes to start a string that can include anything, quotes, doublequotes and newlines. You can use double-quote if you want to embed single-quotes "john's" or single-quote if you want to embed double-quotes ''. Talking about Lisps advantages will take me too long. /hankhero, a switcher. From bj_666 at gmx.net Mon Dec 11 06:25:10 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Mon, 11 Dec 2006 12:25:10 +0100 Subject: Avoiding "invalid literal for int()" exception References: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> Message-ID: In <1165832540.392387.240550 at j72g2000cwa.googlegroups.com>, aine_canby wrote: > elif uniList[0].lower() in ("p","pass"): > break > elif int(uniList[0]) in range(0,10): Replace this line with: elif uniList[0].isdigit() and 0 <= int(uniList[0]) < 10: > verb.SetImportance(int(uniList[0])) > break > else: > verb.AddNewVerb((uniList[0]) You may want to give `uniList[0]` a name before entering the ``if``/``elif`` construct to avoid accessing the first element over and over. Ciao, Marc 'BlackJack' Rintsch From fredrik at pythonware.com Wed Dec 6 16:08:51 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 06 Dec 2006 22:08:51 +0100 Subject: Video stream server In-Reply-To: <1165221764.002660.197600@16g2000cwy.googlegroups.com> References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> <1165218527.632366.290350@j44g2000cwa.googlegroups.com> <1165221764.002660.197600@16g2000cwy.googlegroups.com> Message-ID: Lad wrote: > I love Python so I would like to implement video support in Python. maybe this might be helpful? http://blog.go4teams.com/archives/video-blogging-using-django-and-flashtm-video-flv/56 From hg at nospam.org Tue Dec 19 09:01:23 2006 From: hg at nospam.org (hg) Date: Tue, 19 Dec 2006 08:01:23 -0600 Subject: Is htmlGen still alive? References: <1166474264.348556.118510@n67g2000cwd.googlegroups.com> Message-ID: kgmuller at gmail.com wrote: > Does anybody know whether htmlGen, the Python-class library for > generating HTML, is still being maintained? Or from where it can be > downloaded? The Starship site where it used to be hosted is dead. > > Thanks for your help! > > Klaus Muller I am not certain it is, but besides some deprecation warnings, it seems to be complete/functional hg From mistersulu at gmail.com Mon Dec 11 12:42:33 2006 From: mistersulu at gmail.com (mistersulu) Date: 11 Dec 2006 09:42:33 -0800 Subject: free, python XML merger? Message-ID: <1165858953.389963.161000@f1g2000cwa.googlegroups.com> All: We're looking for a python module which allows for quick merging of two XML files. Both files follow the same schema. One file contains the default values and structure, and the second file contains overriding data for the same tags. Thanks in advance, sulu From robert.kern at gmail.com Wed Dec 6 16:32:10 2006 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 06 Dec 2006 15:32:10 -0600 Subject: advice on stripped down python In-Reply-To: <1165440544.475062.295250@n67g2000cwd.googlegroups.com> References: <1165440544.475062.295250@n67g2000cwd.googlegroups.com> Message-ID: fhaibach at polychromix.com wrote: > Will old Python releases, like 1.5.x, work with newer Numpy and Scipy? No. numpy and scipy require 2.3. -- 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 From skip at pobox.com Sat Dec 9 13:21:09 2006 From: skip at pobox.com (skip at pobox.com) Date: Sat, 9 Dec 2006 12:21:09 -0600 Subject: dict.has_key(x) versus 'x in dict' In-Reply-To: <027001c71a93$409575c0$03000080@hendrik> References: <4tnvstF14cki5U1@mid.individual.net> <17783.32458.730462.8403@montanaro.dyndns.org> <024f01c719d3$deff0fc0$03000080@hendrik> <17784.7961.898760.712605@montanaro.dyndns.org> <027001c71a93$409575c0$03000080@hendrik> Message-ID: <17786.65173.119568.864197@montanaro.dyndns.org> >>>>> "Hendrik" == Hendrik van Rooyen writes: Hendrik> wrote: Hendrik> - as long as it works, and is fast enough, its not broken, so Hendrik> don't fix it... >> That's the rub. It wasn't fast enough. I only realized that had >> been a problem once I fixed it though. Hendrik> LOL - this is kind of weird - it was working, nobody Hendrik> complained, you fiddled with it to make it faster, (just Hendrik> because you could, not because you had to, or were asked to), Hendrik> it became faster, and then, suddenly, retrospectively, it Hendrik> became a problem ???? No, I think you misunderstand. I was poking around in that function for other reasons, saw the "k in d.keys()" and realized that the wrong way to write it. Rewrote it and noticed the performance increase. What's so weird about that? Skip From tactics40 at gmail.com Thu Dec 28 11:14:34 2006 From: tactics40 at gmail.com (tac-tics) Date: 28 Dec 2006 08:14:34 -0800 Subject: Slowdown in Jython Message-ID: <1167322474.724142.210440@a3g2000cwd.googlegroups.com> I have an application written in jython which has to process a number of records. It runs fine until it gets to about 666 records (and maybe that's a sign), and then, it's performance and responsiveness goes down the toilet. It looks like it's running out of memory and is being forced to use extended memory, but I do not know enough about the language to figure out where this is happening. It will eventually finish the task, but the window stops responding, and it ends up taking several hours (as opposed to several minutes as it should). I really just wish I had a tool for polling the amount of memory Jython was using at any given moment. Does anyone have any strategy or advice for me? From gagsl-py at yahoo.com.ar Thu Dec 7 21:53:07 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 23:53:07 -0300 Subject: Need Help Parsing From File In-Reply-To: <1165517086.976152.216270@16g2000cwy.googlegroups.com> References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> <1165517086.976152.216270@16g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061207230730.03e40c38@yahoo.com.ar> At Thursday 7/12/2006 15:44, John Machin wrote: > > > > ftxt=open(filename,"rt") > > > > > >Is this a bug or a feature? Or is it one of those good old "unspecified > > >behaviour" cases? MSVC rtl only? > > > > The Python docs say only that the initial letter is checked. And the > > ANSI 89 C says that other characters may follow after r, r+, etc. > > "rt" is useless for an ANSI C compiler, since the default stream mode > > is "text" -on systems which differentiate between text and binary- > > and irrelevant on systems which don't do such distinction. > > (And since I got used to write "rt", > >Why did you do that? >(1) Text mode is was and ever shall be the default, even with MS. No, there used to be a flag in the stdio library, giving the default value when neither t or b was specified. For the Borland C++ 3.1 help (about 1991): If "t" or "b" is not given in the string, the mode is governed by _fmode. If _fmode is set to O_BINARY, files are opened in binary mode. If _fmode is set to O_TEXT, they are opened in text mode. MSC used to have a similar flag (perhaps using the same name). All of this predates wide usage of ANSI C 89, which made the "t" flag obsolete. >(2) Seeing we're referring to docs and standards: Microsoft C 5.0 >Optimizing Compiler, Run-Time Library Reference manual says "The t >option is not part of the ANSI standard for open, but is a Microsoft >extension and should not be used where ANSI portability is required". A "t" after the initial recognized characters should be ignored by any conforming compiler. I think the idea was to allow for extensions like fopen(fn, "rt;reclen=128") but except esoteric platforms I doubt anyone is using that. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From mccredie at gmail.com Mon Dec 11 13:58:29 2006 From: mccredie at gmail.com (Matimus) Date: 11 Dec 2006 10:58:29 -0800 Subject: Sorting Multidimesional array(newbie) References: <20061211193104.40fe7985.tartifola@gmail.com> Message-ID: <1165863508.967414.70350@73g2000cwn.googlegroups.com> Tartifola wrote: > Hi, > how can I sort an array like > > array([[5, 2], > [1, 3]]) > > along the first column to obtain > > array([[1, 3], > [5, 2]]) > i.e. keeping track of the ordered couples? > > Thanks, > A use a sort key: >>>from operators import getitem >>>a = [[5,2],[1,3]] >>>a [[5, 2], [1, 3]] >>>a.sort(key=lambda x:getitem(x,0)) >>>a [[1, 3], [5, 2]] From python.list at tim.thechases.com Mon Dec 4 12:35:42 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 04 Dec 2006 11:35:42 -0600 Subject: Ensure a variable is divisible by 4 In-Reply-To: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: <45745C6E.3040100@tim.thechases.com> > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. You're right...you'll want to read up on the "modulo" operator: if x % 4 <> 0: print "Hey, x isn't divisible by 4" http://docs.python.org/lib/typesnumeric.html To do what you describe above, you can also use x = x - (x % 4) which isn't greatly better in the clunkiness department. In both cases, non-divisible-by-4 numbers get bumped down (to the "left" on the number line) in the event that it's not divisible by 4. -tkc From gagsl-py at yahoo.com.ar Tue Dec 5 00:53:03 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Tue, 05 Dec 2006 02:53:03 -0300 Subject: Async callback in python In-Reply-To: <1165292302.454012.118540@n67g2000cwd.googlegroups.com> References: <1165292302.454012.118540@n67g2000cwd.googlegroups.com> Message-ID: <7.0.1.0.0.20061205022259.04014020@yahoo.com.ar> At Tuesday 5/12/2006 01:18, Linan wrote: >t=T('aVerySlowSite','/') >asyncore.loop() >for i in range(0,10): > print '%d in main process' % i > time.sleep(1) > >Suppose it's asynchronous, couple of '%d in main process' lines should >be mixed in the output of T.handle_read(), right? No. As you noticed, asyncore.loop (without arguments) won't return until all channels are closed. >But I found that >actually main process was blocked at asyncore.loop(), until the the >socket was closed. Exactly. >My questions: >1, Did I do anything wrong? >2, Is it real asynchronous? >3, If not, where to get the real one(s)? Perhaps you didn't understand the nature of asyncore processing. The idea is not to have many threads, each one blocking on its own (synchronous) socket processing. Instead, using a single thread which never blocks, and dispatches events to many instances, each one processing its own data. If you want to do other things mixed with network events, put those things inside the loop, that is, instead of asyncore.loop() do something like: while asyncore.socket_map: asyncore.loop(1, count=1) // do other things -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From http Tue Dec 12 19:55:59 2006 From: http (Paul Rubin) Date: 12 Dec 2006 16:55:59 -0800 Subject: merits of Lisp vs Python References: <1165867527.389209.80660@f1g2000cwa.googlegroups.com> Message-ID: <7xk60wty00.fsf@ruckus.brouhaha.com> Slawomir Nowaczyk writes: > #> Lisp interpreters are several orders of magnitude faster than Python, > #> and Lisp compilers are faster yet. Speed's not the most important > #> thing, but it is _an_ important thing; all other things being equal, > #> the faster solution is better. > > Sure. But in 20-30 years, Python might get there. I think compiled "Python" code may get as Lisp code sooner than that, but I put "Python" in quotes because I think the language is going to have to diverge somewhat from the current dialect to get that level of performance. From python.list at tim.thechases.com Thu Dec 14 06:34:22 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 14 Dec 2006 05:34:22 -0600 Subject: remove matching pairs In-Reply-To: <1166095293.445275.64850@73g2000cwn.googlegroups.com> References: <1166095293.445275.64850@73g2000cwn.googlegroups.com> Message-ID: <458136BE.8030105@tim.thechases.com> > Is there a simple way to to identify and remove matching pairs from 2 > lists? > > For example: > > I have > > a=[2, 5, 3, 4, 7, 2, 2, 4, 8, 1] > b=[7, 3, 5, 8, 1, 7, 4, 8, 2, 6] > > and I want to get this: > > a=[2, 5, 3, 4, 7, 2, 8, 1] > b=[7, 3, 5, 8, 1, 4, 2, 6] Well, with a few caveats, the following works: >>> a=[2, 5, 3, 4, 7, 2, 2, 4, 8, 1] >>> b=[7, 3, 5, 8, 1, 7, 4, 8, 2, 6] >>> a_prime, b_prime = zip(*set(zip(a,b))) >>> a_prime (2, 8, 4, 7, 1, 5, 2, 3) >>> b_prime (7, 2, 8, 1, 6, 3, 4, 5) Caveat #1: the order changed because sets are unordered Caveat #2: a_prime and b_prime are tuples, not lists If this isn't a true solution (because either #1 or #2 is an unacceptable condition), you'd have to go with a loop...something like this untested pairs = zip(a,b) uniq = set(pairs) a_prime = [] b_prime = [] for pair in pairs: if pair in uniq: a_prime.append(pair[0]) b_prime.append(pair[1]) uniq.remove(pair) #if not uniq: break This should preserve the order as well as maintain listsrather than return tuples. Depending on the number of duplicates you expect and the size of your a/b lists, uncommenting out that last line may give you a short speedup, as if you've already pulled all the items out the uniq set, there's no reason to continue iterating over the list of pairs. HTH, -tkc From spam at spam.pl Tue Dec 19 15:59:58 2006 From: spam at spam.pl (vertigo) Date: Tue, 19 Dec 2006 21:59:58 +0100 Subject: regexp References: Message-ID: Hello > On Tuesday 19 December 2006 13:15, vertigo wrote: >> Hello >> >> I need to use some regular expressions for more than one line. >> And i would like to use some modificators like: /m or /s in perl. >> For example: >> re.sub(".*","",data) >> >> will not cut out all javascript code if it's spread on many lines. >> I could use something like /s from perl which treats . as all signs >> (including new line). How can i do that ? >> >> Maybe there is other way to achieve the same results ? >> >> Thanx > > Take a look at Chapter 8 of 'Dive Into Python.' > http://diveintopython.org/toc/index.html > i read whole regexp chapter - but there was no solution for my problem. Example: re.sub("","",htmldata) would remove only comments which are in one line. If comment is in many lines like this: it would not work. It's because '.' sign does not matches '\n' sign. Does anybody knows solution for this particular problem ? Thanx From bj_666 at gmx.net Tue Dec 19 02:36:46 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Tue, 19 Dec 2006 08:36:46 +0100 Subject: How would I create an class with a "Person.Address.City" property? References: Message-ID: In , Jamie J. Begin wrote: > Let's say I wanted to create an object that simply outputted something > like this: > >>>> import employees >>>> person = employee("joe") # Get Joe's employment file >>>> print employee.Title # What does Joe do? > Developer >>>> print person.Address.City # Which city does Joe live in? > Detroit >>>> print person.Address.State # Which state? > Michigan > > To do this would I create nested "Address" class within the "employee" > class? Would it make more sense to just use "print > person.Address('City')" instead? That depends on the usage of the addresses. If you need them as objects with "behavior" i.e. methods then you would write an `Address` class. If you can live with something more simple than a `dict` as `address` attribute of `Employee` objects might be enough. BTW you wouldn't create a nested `Address` *class*, but hold a reference to an `Address` *object* within the `Employee` *object*. class Address(object): def __init__(self, city, state): self.city = city self.state = state class Employee(object): def __init__(self, name, title, address): self.name = name self.title = title self.address = address employees = { 'Joe': Employee('Joe', 'Developer', Address('Detroit', 'Michigan')) } def employee(name): return employees[name] def main(): person = employee('Joe') print person.title print person.address.city print person.address.state Ciao, Marc 'BlackJack' Rintsch From nnorwitz at gmail.com Tue Dec 26 13:34:32 2006 From: nnorwitz at gmail.com (nnorwitz at gmail.com) Date: 26 Dec 2006 10:34:32 -0800 Subject: perl better than python for users with disabilities? In-Reply-To: <87slfalf8h.fsf@jidanni.org> References: <87slfalf8h.fsf@jidanni.org> Message-ID: <1167158072.767316.31940@a3g2000cwd.googlegroups.com> Dan Jacobson wrote: > Can I feel even better about using perl vs. python, as apparently > python's dependence of formatting, indentation, etc. vs. perl's > "(){};" etc. makes writing python programs perhaps very device > dependent. Whereas perl can be written on a tiny tiny screen, and can > withstand all kinds of users with various disabilities, etc.? > Also perl is easier to squeeze into makefiles. My esteemed colleague does not agree. http://googleblog.blogspot.com/2006/07/finding-easy-to-read-web-content_20.html Reposted with permission: """ As for programming in Python while not being able to see, I think it comes down to the tools you have to do it with. When in Grad School, all I had was a screenreader, and I stayed away from python because of the whitespace having semantics problem. However once i wrote emacspeak, and speech-enabled Barry Warsaw's python-mode, programming in python has always been a pleasure -- and the paucity of delimiters actually makes the code more speakable. """ n From fredrik at pythonware.com Wed Dec 13 05:09:13 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Dec 2006 11:09:13 +0100 Subject: call of __del__ non-deterministic in python 2.4 (cpython)? In-Reply-To: References: Message-ID: Holger Joukl wrote: > Anyway: Is relying on __del__ getting called immediately when the refcount > drops to 0 a no-no? yes, but more importantly, relying on the refcount dropping to 0 when something goes out of scope is a major no-no. > If so should that maybe be prominently stated in the docs? is it perhaps the color that made you miss the big bold boxes in the documentation? http://docs.python.org/ref/customization.html#l2h-177 From skip at pobox.com Mon Dec 18 09:07:59 2006 From: skip at pobox.com (skip at pobox.com) Date: Mon, 18 Dec 2006 08:07:59 -0600 Subject: Shed Skin - Does it break any Python assumptions? Message-ID: <17798.41151.547934.689629@montanaro.dyndns.org> I just noticed the announcement of Shed Skin 0.0.16 on Freshmeat with this (partial) change announcement: Changes: frozenset was added. time.sleep now works on Win32. Given Python's highly dynamic nature it's unclear to me how Shed Skin could know enough about the semantics of time.sleep to know whether or not it's broken on Win32. This suggests that to gain speedups it probably implements a more static language than Python. For example, does Shed Skin handle a case like this? >>> import time >>> time.sleep(1) >>> def _sleep(n): ... print "sleeping for", n, "seconds" ... time._sleep(n) ... >>> time._sleep = time.sleep >>> time.sleep = _sleep >>> time.sleep(1) sleeping for 1 seconds What does this phrase in the announcement mean? "... pure but implicitly statically typed Python ...". Where does the static typing begin and end? Can one module tweak another module's attributes? Can a class's attributes be modified from outside the class? What about the attributes of a class instance? Skip From CRhode at LacusVeris.com Tue Dec 5 10:05:27 2006 From: CRhode at LacusVeris.com (Chuck Rhode) Date: Tue, 5 Dec 2006 09:05:27 -0600 Subject: PythonTidy Message-ID: <20061205150527.GA3854@loki> That went well. PythonTidy has been looked at at least 10**2 times, and I have received a couple of complaints, which I hope I have addressed satisfactorily -- plenty good enough for a beta test. The basic concept stands. PythonTidy.py cleans up, regularizes, and reformats the text of Python scripts: http://www.LacusVeris.com/PythonTidy/PythonTidy.python What next? Is it appropriately submitted to the Cheese Shop? -- .. Chuck Rhode, Sheboygan, WI, USA .. Weather: http://LacusVeris.com/WX .. 3? ? Wind W 8 mph From bdesth.quelquechose at free.quelquepart.fr Tue Dec 19 11:10:41 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 19 Dec 2006 17:10:41 +0100 Subject: python poetry? In-Reply-To: <1166524579.271548.32560@a3g2000cwd.googlegroups.com> References: <1166524579.271548.32560@a3g2000cwd.googlegroups.com> Message-ID: <45880942$0$8996$426a74cc@news.free.fr> BartlebyScrivener a ?crit : > I'm working on a book of technology and computer programming humor. > > First, can anybody recommend any other such books? You of course alreeady know "Tao of programming" and "BOFH" (aka the Bastard Operator From Hell') ? From felipe.lessa at gmail.com Sun Dec 31 07:59:15 2006 From: felipe.lessa at gmail.com (Felipe Almeida Lessa) Date: Sun, 31 Dec 2006 10:59:15 -0200 Subject: Are all classes new-style classes in 2.4+? In-Reply-To: <1167566224.439844.267250@42g2000cwt.googlegroups.com> References: <1167566224.439844.267250@42g2000cwt.googlegroups.com> Message-ID: On 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez wrote: > I am using Python 2.4, and I was wondering if by default, all > classes are assumed to be derived from "object". This won't tell you advantages or disadvantages, but will show you that the default still is the old-style: >>> class old: ... pass ... >>> type(old()) >>> dir(old()) ['__doc__', '__module__'] >>> >>> class new(object): ... pass ... >>> type(new()) >>> dir(new()) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] In general, even if you don't understand the differences, it's better to use new-style (they're new ;-). Anyway, see http://effbot.org/pyref/new-style-and-classic-classes.htm for a little more information. -- Felipe. From sjmachin at lexicon.net Sun Dec 3 20:02:51 2006 From: sjmachin at lexicon.net (John Machin) Date: 3 Dec 2006 17:02:51 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: <1165194171.257951.89040@j44g2000cwa.googlegroups.com> James Stroud wrote: > Russ wrote: > > Every Python programmer gets this message occasionally: > > > > IndexError: list index out of range > > > > The message tells you where the error occurred, but it doesn't tell you > > what the range and the offending index are. Why does it force you to > > determine that information for yourself when it could save you a step > > and just tell you? This seems like a "no-brainer" to me. Am I missing > > something? > > > > I think you have a point. I am curious to see how far people are willing > to go to defend this omission. It promises to be entertaining. > Add "Syntax Error: invalid syntax" to the list ... From mail at microcorp.co.za Wed Dec 20 00:29:16 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 20 Dec 2006 07:29:16 +0200 Subject: SQLALCHEMY - Method to have the last word, by Michael Bayer References: <1166543077.605993.276770@80g2000cwy.googlegroups.com> <4uqgeuF19khhgU1@mid.uni-berlin.de> Message-ID: <014d01c723f7$cae136c0$03000080@hendrik> "Diez B. Roggisch" wrote: > So - stop it, go away, and please, pretty please with sugar on top: don't > come back. Python doesn't need you, this NG doesn't need you, no FOSS > project needs you. Buy a dog. That needs you. Until it runs away from > being "evaluated". This proves it. Wearing skull socks makes you mean. - Hendrik From justin.mailinglists at gmail.com Mon Dec 4 05:08:41 2006 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: 4 Dec 2006 02:08:41 -0800 Subject: Multiple FTP download using Muliti thread References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> Message-ID: <1165226921.418634.169700@80g2000cwy.googlegroups.com> Fredrik Lundh wrote: > Justin Ezequiel wrote: > > > from TaskQueue import TaskQueue > > what Python version is this ? > > oops. forgot to note... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475160 From josephoswald at gmail.com Thu Dec 14 08:15:08 2006 From: josephoswald at gmail.com (josephoswaldgg@hotmail.com) Date: 14 Dec 2006 05:15:08 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> Message-ID: <1166102108.129051.166580@73g2000cwn.googlegroups.com> Neil Cerutti wrote: > On 2006-12-14, josephoswaldgg at hotmail.com wrote: > > > > Neil Cerutti wrote: > >> On 2006-12-13, josephoswaldgg at hotmail.com > >> wrote: > >> > Expressions keep the same meaning even if you have to start > >> > breaking them across lines, etc. > >> > >> Yes, it's the same way in Python. Of course, not everything is > >> an expression in Python, so it's not saying quite as much. > > > > I fail to see how it is the same in Python. > > if self.flee == (foo.humble(pie) / 500 * hats > + hippity.hoppity) > > The indentation of the second line of that expression is entirely > irrelevant to Python. The parenthesis I added means I don't have > to use the new-line escape character (\), either. Is this so unconscious that you don't recognize you are doing it, even though you take a sentence to explain what you had to do to work around it? Adding parentheses, new-line escape characters---all this is a burden specific to Python. > > How does a manual correction process come out as simple as > > "don't bother fixing the indentation if you don't care."? > > > > This is exactly the questionable math that I was questioning in > > the original post. > > Python simply replaces one manual process (moving to the correct > scope (usually sitting on an open or close parenthesis) and then > hitting the grab-s-expr command) with another (after pasting, > correct the indentation--generally a trivial task). I think it's > a major stretch to call either process anything but trivially > easy for an experiences user of the language. The reformatting (admittedly generally trivial, although again your qualifier of "generally" undermines your point) process is extra in Python. Period. 1) Recognizing where your code begins and ends to begin the copy-paste process is not unique to either. Equal. 2) In a python-aware editor, I presume the grab-block keystroke exists and is equivalent to grab-s-expr. Or, you have to manually select to tell the editor where the block ends. Equal. 3) Recognizing where you want to paste is the same. Equal. 4) The paste keystroke is presumed Equal. Lispers are done here. 5) After you are done, Pythonistas admit there is a possible step called "manually correct the indentation." Can I be any clearer? Now, you can say 5 is usually generally trivially easy for an experienced Pythonista in 'the flow' or whatever you like, but it just is not there for Lisp. This is pointless discussion if you guys can't even see what you are saying when you write it in your own posts. By the way, you guys seem fixate on the parentheses of Lisp without having the experience which shows that open parens are trivial to find, because they don't occur in clumps and they are marked by the operator symbol. The close parens occur in somewhat ugly clumps, but the editor is the only thing that needs to deal with them. From gregpinero at gmail.com Fri Dec 22 23:34:29 2006 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 22 Dec 2006 23:34:29 -0500 Subject: Use a Thread to reload a Module? In-Reply-To: <1166846551.460203.242690@h40g2000cwb.googlegroups.com> References: <1166846551.460203.242690@h40g2000cwb.googlegroups.com> Message-ID: <312cfe2b0612222034w7fa5185du2555924991f4e056@mail.gmail.com> On 22 Dec 2006 20:02:31 -0800, Carl Banks wrote: ... > There is much room for improvement. For example, can requests come in > fast enough to spawn another load_data before the first had ended? You > should consider trying to acquire a threading.Lock in load_data and > waiting and/or returning immediately if you can't. Other things can go > wrong, too. Using threads requires care. But hopefully this'll get > you started. > Thanks, Carl. That gives me a lot to consider. I won't be able to work on this project more until Wed. but I'll probably run into some follow up questions then. A few more details if it helps ... That module deals with accessing data from QuickBooks, marshaling it, and providing methods to access the marshaled data. Having the server program keep that module and all of its data in memory makes the server run really fast, but yeah, it does get complicated now that it's storing 100's of MB of data. I guess most people go to a database at this point? It's just so easy to store the data in the Python objects I already need them in instead of converting to tables in a DB and then converting back. So maybe this threading will work for me. Thanks again, Greg From evanmason at gmail.com Mon Dec 18 04:29:26 2006 From: evanmason at gmail.com (Evan) Date: 18 Dec 2006 01:29:26 -0800 Subject: first and last index as in matlab References: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> <1166397048.401143.71480@16g2000cwy.googlegroups.com> Message-ID: <1166434166.096047.75840@j72g2000cwa.googlegroups.com> Thanks for all the replies, it's much clearer now. -Evan From not-a-real-email-address at not-a-real-domain.com Sun Dec 17 22:15:24 2006 From: not-a-real-email-address at not-a-real-domain.com (Bill Atkins) Date: Sun, 17 Dec 2006 22:15:24 -0500 Subject: merits of Lisp vs Python References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > xscottg at gmail.com writes: >> I should assume you meant Common Lisp, but there isn't really any >> reason you couldn't >> >> (poke destination (peek source)) > > That breaks the reliability of GC. I'd say you're no longer writing > in Lisp if you use something like that. Writing in this "augmented > Lisp" can be ok if well-localized and done carefully, but you no > longer have the guarantees that you get from unaugmented Lisp. By > adding one feature you've removed another. Whatever do you mean? The portion of memory used for memory-mapped registers is simply excluded from GC; everything else works as normal. All modern Lisps (yes, *Common* Lisps) support a foreign-function interface to talk to C libraries. Data involved with these kinds of interface is ignored by the GC, for obvious reasons. Do you claim that these implementations are not truly Lisps? -- There are three doors. Behind one is a tiger. Behind another: the Truth. The third is a closet... choose wisely. E-mail me at: (remove-if (lambda (c) (find c ";:-")) "a;t:k-;n-w at r;p:i-.:e-d:u;") From fdu.xiaojf at gmail.com Tue Dec 26 08:23:55 2006 From: fdu.xiaojf at gmail.com (fdu.xiaojf at gmail.com) Date: Tue, 26 Dec 2006 21:23:55 +0800 Subject: How to depress the output of an external module ? In-Reply-To: <459117EE.6070205@gmail.com> References: <459117EE.6070205@gmail.com> Message-ID: <4591226B.505@gmail.com> fdu.xiaojf at gmail.com wrote: > > I have tried your method, but I found it didn't work as expected. > > The output produced by the external function couldn't be depressed, > but the "print " statement i wrote in python is depressed. It seems > make cStringIO.StringIO() as a temporary replacement of sys.stdout > has no effect on the external function. > > Here is an example to make myself clear(actually it's modified version > of Steven's code): > > def run_without_stdout(*args, **kwargs): > function = args[0] > args = args[1:] > savestdout = sys.stdout > sys.stdout = cStringIO.StringIO() > print "something" > result = None > try: > result = function(*args, **kwargs) > finally: > # don't forget to restore stdout, or you > # really will regret it... > sys.stdout = savestdout > print "some other thing" > return result > > When run_without_stdout() is called, the "print" statements wrote in python > don't produce output, but function() produces output to the standard output > just as before:( > > I have tried to replace sys.stdout globally with cStringIO.StringIO() > in my program(I mean, make "sys.stdout = cStringIO.StringIO()" as a > globall statement), but it worked just as previous version did. > After some trials I found that put "os.close(1)" before calling the function will depress the output. In fact, "os.close(1)" closed standard output, but I don't know how to open it again after the function's execution. Still trying... Regards, xiaojf From olsongt at verizon.net Mon Dec 11 13:31:22 2006 From: olsongt at verizon.net (olsongt at verizon.net) Date: 11 Dec 2006 10:31:22 -0800 Subject: About alternatives to Matlab In-Reply-To: <7xhcw2d0fo.fsf@ruckus.brouhaha.com> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <7xhcw2d0fo.fsf@ruckus.brouhaha.com> Message-ID: <1165861882.340331.200170@j72g2000cwa.googlegroups.com> Paul Rubin wrote: > Jon Harrop writes: > > F# runs under Linux with Mono. > > Interesting, where do I get it, and is there source? I've never been > interested in Mono but maybe this is a reason. How does the compiled > code compare to OCaml or MLton code? The source is avaliable, but it's under Microsoft's Shared Source license, which isn't quite an open source license. There are some restrictions on commercial usage. http://research.microsoft.com/fsharp/fsharp-license.txt From shb*NO*SPAM* at comporium.net Sun Dec 3 21:37:17 2006 From: shb*NO*SPAM* at comporium.net (Si Ballenger) Date: Mon, 04 Dec 2006 02:37:17 GMT Subject: Parsing data from pyserial References: <4572e860.53134312@news.comporium.net> <12n606he7k5uhb3@corp.supernews.com> <4573145a.64392531@news.comporium.net> <12n66nnm8ri1sd4@corp.supernews.com> <45737310.88637718@news.comporium.net> <1165196039.802469.77510@f1g2000cwa.googlegroups.com> Message-ID: <45738635.93539421@news.comporium.net> On 3 Dec 2006 17:33:59 -0800, "John Machin" wrote: >In any case, I wouldn't call that "the appropriate data is being >received" -- looks like chunks missing to me. Well, below is the posted expected return data format from the cam and below that is what has been reported to be returned from the cam when it is polled, which appears to be a fairly reasonable match. I assume that each xxx is a decimal number repersenting a single byte. In the binary mode each x in the string might be considered a byte in itelf and possibly evaluated as such. Anyhow it should be easy to see if the received string can be parsed on it own correctly when not being received via the serial port. That would start to narrow down where something not understood is comming into play. M xxx xxx xxx xxx xxx xxx xxx xxx M 37 79 3 4 59 124 86 25 From pjb at informatimago.com Fri Dec 15 10:42:34 2006 From: pjb at informatimago.com (Pascal Bourguignon) Date: Fri, 15 Dec 2006 16:42:34 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> Message-ID: <87psaljhcl.fsf@thalassa.informatimago.com> Paul Rubin writes: > Andr? Thieme writes: >> and the Lisp version has only 9: >> nth, 1+, truncate, signum, num, list, pos, zero, neg > > Oh come on, you have to count the parentheses too. No. Parentheses are editor commands. They don't count anymore than spaces "count" in Python. -- __Pascal Bourguignon__ http://www.informatimago.com/ "You question the worthiness of my code? I should kill you where you stand!" From pwatson at redlinepy.com Mon Dec 25 00:19:35 2006 From: pwatson at redlinepy.com (Paul Watson) Date: Sun, 24 Dec 2006 23:19:35 -0600 Subject: Help with small program In-Reply-To: <4v94fuF1avmp3U1@mid.individual.net> References: <1166966360.384179.101400@48g2000cwx.googlegroups.com> <1166979265.284345.173840@48g2000cwx.googlegroups.com> <4v94fuF1avmp3U1@mid.individual.net> Message-ID: <4v95b8F1b5csnU1@mid.individual.net> Better alternative. cointype = (100, 10, 5, 1, 0.5) def coins(fin): needed = {} for c in cointypes: v, r = divmod(fin, c) if v > 0: needed[c] = v fin = r return needed if __name__ == '__main__': print coins(51) print coins(127) print coins[12.5) From wojciechowski_m at o2.pl Mon Dec 11 17:12:33 2006 From: wojciechowski_m at o2.pl (mwojc) Date: 11 Dec 2006 14:12:33 -0800 Subject: feed-forward neural network for python In-Reply-To: <1165519443.693137.38570@16g2000cwy.googlegroups.com> References: <1165517109.290566.27390@l12g2000cwl.googlegroups.com> <1165519443.693137.38570@16g2000cwy.googlegroups.com> Message-ID: <1165875153.580512.276980@l12g2000cwl.googlegroups.com> Beliavsky napisal(a): > mwojc wrote: > > Hi! > > I released feed-forward neural network for python (ffnet) project at > > sourceforge. Implementation is extremelly fast (code written mostly in > > fortran with thin python interface, scipy optimizers involved) and very > > easy to use. > > I'm announcing it here because you, folks, are potential users/testers. > > > > If anyone is interested please visit http://ffnet.sourceforge.net (and > > then post comments if any...) > > Thanks for making available your code. The Fortran code compiles with > both g95 and gfortran. I looked at the code briefly, and it is > well-documented and clear, but I do wonder why you are writing new code > in Fortran 77. Using free source form instead of fixed source form > would make the code more readable, and using the array operations of > Fortran 90 would make it more concise. Gfortran is a Fortran 95 > compiler and is part of gcc, so using Fortran 95 features should not > inhibit portability. There are three reasons I use Fortran 77: 1. g77 compiler is just everywhere. 2. fortran 77 code compiles with all subsequent fortrans. 3. f2py not necessarily support fortran 90/95 instructions. Portability of Fortran 95 is not so obvious, for example my 2-years old Gentoo Linux has only g77 and I think there are many people like me. > I think using the single letter "o" as a variable name is a bad idea -- > it looks too much like "0". You're right, thanks. > I would like to see a Fortran driver (main program) for the code, so I > could see an example of its use independent from Python and f2py. Yes, this would be nice. The only problem is that all data arrays defining the network are set up in python. The simple case however (like XOR) can be inserted manually (or read from file) and I'll try to include this in the next release. In fact, in my work, I plan to train the networks in python but use them also from fortran. Thanks Marek From craigtw.online at gmail.com Wed Dec 6 18:01:17 2006 From: craigtw.online at gmail.com (Craig) Date: 6 Dec 2006 15:01:17 -0800 Subject: Mirror imaging binary numbers In-Reply-To: <1165445569.287552.266120@j44g2000cwa.googlegroups.com> References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> <1165445569.287552.266120@j44g2000cwa.googlegroups.com> Message-ID: <1165446077.584437.206310@73g2000cwn.googlegroups.com> Matimus wrote: > Craig wrote: > > I'm trying to switch binary numbers around so that the MSB becomes the > > LSB etc. > > What do you mean 'binary numbers'? They are all binary. If you mean the > int type, they are 32 bits long and there are 16 bits between the MSB > and LSB (Most/Least Significant _Byte_). Do you want to swap the most > significant word with the least significant word? Swap the most > significant nibble with the least significant nibble in a Byte? Or do > you want to completely reverse the bit order? > > To swap nibbles in a byte: > > reverseVal = (val & 0xf) << 4 | (val & 0xf0) >> 4 > > Basicly you are going to need to use the bit operators (|,&, << and >>) > to get what you need. If you could be more specific perhaps I could be > of more help. Thanks so much for the response. I have an array of individual bytes which will eventually make up a binary bitmap image that is loaded onto an LCD screen (1 = black dot, 0 = white dot). At the moment each byte is reversed to what it should be (completely reverse the bit order): e.g 00111101 should be 10111100, 11001100 should be 00110011, etc. It is not an int problem as such, it is more a bit level swap if you get what I mean. If you could help that would be great. From webmaster at cacradicalgrace.org Tue Dec 19 14:41:45 2006 From: webmaster at cacradicalgrace.org (J. Clifford Dyer) Date: Tue, 19 Dec 2006 12:41:45 -0700 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: Nick Maclaren wrote: > In article , > "J. Clifford Dyer" writes: > |> > |> On the contrary, I think that example fits perfectly with my definition > |> of homogenous. If there is no constraint on position, then what is the > |> position determinative of? Order in the queue. Nothing more. By my > |> definition, homogeneous. QED. > |> > |> I'll grant, it's not exactly the most intuitive definition of > |> homogenous, but I think it is the most accurate for this situation. > |> Perhaps homogenous and heterogenous aren't the best possible words here, > |> but I think they work. > > Grrk. I see what you mean. The homogeneity is referring to the order > and not to the types :-) Thank you. The more I tried to explain it, the more I was losing the sense of the actual words "homogeneous" and "heterogenous" in this context, but that helps me recapture it. It made so much sense until I tried to articulate it... > > |> By my definition, how can it be mutable AND heterogenous? If the first > |> element is a name, the second element is a phone number, and the third > |> element is an email address, and you insert an element in between the > |> first two elements, do you mean to tell me that the phone number, which > |> has moved to the third slot, is now an email address? It doesn't make > |> sense. > > Well, I could provide an example, but they are a bit weird. More > seriously, consider changing a structure consisting of a name and > telephone number, and then changing the value of the latter (not > exactly an unreasonable requirement!) With tuples that can't be done, > but it makes perfect sense, and it is a mutable heterogeneous sequence > with your definition. > Good example. Of course, an immutable sequence can be made up of mutable elements, but a string (which you'd probably use for a telephone number or an email address) isn't one of those types. > |> Maybe the words are wrong. I'm not sure. But I think the distinction > |> is valid. Furthermore, I think we "lists are intended to be homogenous" > |> people would say that you are perfectly welcome to use lists for other > |> purposes, if it suits you. Just as you can use a string as a list. We > |> don't have to be rigid to appreciate the difference. :) > > Nope. That is DEFINITELY wrong. If you write code that abuses a > language construct in a way that is discouraged but just happens to > work, a couple of decades down the line it will stop working, because > someone will change the feature. Been there - been caught by that :-( > Yeah, that could suck. Personally, I can't picture such a basic construct as a list or a tuple ever being given such a restrictive meaning. If you ask me what a list is (in python), I would never say "a list is a homogeneous sequence." I would say "a list is a mutable sequence," as I believe the language reference defines it. (No citation). If you then asked me why we have separate mutable and immutable sequences, THAT's when I'd bring up homogeneity and heterogeneity. So I wouldn't say you were misusing the structure for making a homogeneous tuple, as long as you didn't try to mutate it. Or that you were misusing a list if you really needed a mutable heterogeneous sequence (like for changing phone numbers). The mapping from heterogeneous to immutable is helpful, but not perfect, nor normative. However, if more powerful minds disagree with me, that's when you'd get in trouble. Cheers, Cliff > > Regards, > Nick Maclaren. From pierre at saiph.com Thu Dec 28 16:49:38 2006 From: pierre at saiph.com (Imbaud Pierre) Date: Thu, 28 Dec 2006 22:49:38 +0100 Subject: xml bug? In-Reply-To: <45941780$1@nntp.zianet.com> References: <4594130c$0$318$426a74cc@news.free.fr> <45941780$1@nntp.zianet.com> Message-ID: <45943b34$0$302$426a74cc@news.free.fr> Erik Johnson a ?crit : > "Imbaud Pierre" wrote in message > news:4594130c$0$318$426a74cc at news.free.fr... > >>Now my points are: >>- how do I spot the version of a given library? There is a __version__ >> attribute of the module, is that it? > > > Yes, the module maintainer should be incrementing this version for each new > release and so it should properly correspond to the actual revision of code. > > >>- How do I access to a given library buglist? Maybe this one is known, >> about to be fixed, it would then be useless to report it. > > > Not exactly sure, but this is probably a good place to start: > http://docs.python.org/modindex.html But python.org was the right entry point, it sent me to the bug tracker: http://sourceforge.net/tracker/?group_id=5470&atid=105470 Its a bit short on explanations... And I found unsolved issues, 3 years old! this indexes the modules, not the buglist! > > >>- How do I report bugs, on a standard lib? > > > I found this link: > > http://sourceforge.net/tracker/?group_id=5470&atid=105470 Right! Same place to fetch and to submit. Fair. > > by looking under the "help" item at www.python.org (an excellent starting > place for all sorts of things). > > >>- I tried to copy the lib somewhere, put it BEFORE the official lib in >> "the path" (that is:sys.path), the stack shown by the traceback >> still shows the original files being used. Is there a special >> mechanism bypassing the sys.path search, for standard libs? (I may >> be wrong on this, it seems hard to believe...) > > > My understanding is sys.path is searched in order. The first entry is > usually the empty string, interpreted to mean the current directory. If you > modify sys.path to put the directory containing your modified code in front > of where the standard library is found, your code should be the one used. > That is not the case? I put it in front, as for the unix PATH... > > >>- does someone know a good tool to validate an xml file? > > > Typing "XML validator" into google returns a bunch. I think I would start > with the one at w3.org: http://validator.w3.org/ > > Ill try this. Thanks a lot, my friend! From newsmailcomp6 at gustad.com Tue Dec 12 11:48:01 2006 From: newsmailcomp6 at gustad.com (Petter Gustad) Date: 12 Dec 2006 17:48:01 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> Message-ID: <7dodq93vsu.fsf@www.gratismegler.no> Robert Uhl writes: > that for can understand new objects; CL LOOP is not extensible, unless I > have missed something big, but it's simple enough to write a > map-new-object or loop-new-object or whatever). There is no standard way to extend loop, but most of the major vendors let you extend it using add-loop-path. In CLSQL you can do stuff like (loop for (time event) being the tuples of "select time,event from log" from *my-db* do ... ) Petter -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? From cptnwillard at gmail.com Sun Dec 3 13:17:46 2006 From: cptnwillard at gmail.com (cptnwillard at gmail.com) Date: 3 Dec 2006 10:17:46 -0800 Subject: wxpython worked out but can't find api docs for download. References: <1165169660.539522.285560@79g2000cws.googlegroups.com> Message-ID: <1165169866.432393.277570@16g2000cwy.googlegroups.com> Sorry, I think all you want is "wxPython-newdocs", which is the wxPython-specific documentation. From nmm1 at cus.cam.ac.uk Thu Dec 21 05:06:38 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 21 Dec 2006 10:06:38 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4uslgfF18sq18U1@mid.individual.net> <4589D599.6010704@cosc.canterbury.ac.nz> Message-ID: In article <4589D599.6010704 at cosc.canterbury.ac.nz>, greg writes: |> |> > Not at all. I didn't say that they came in pairs. Consider: |> > |> > [str1, str2, agent1, str3, agent2, agent3, agent4, str4, ...] |> |> That's homogeneous. Any item of the list can be |> either a string or an agent, and the only thing |> the position in the list affects is what order |> the strings and agents are processed in. Grrk. I think that I see Python's problem - and it is Python's problem, not mine or that of any of the other people who ask related questions. The terms "heterogeneous" and "homogeneous" are being used in an extremely specialised, unconventional and restricted way, without any kind of hint in the documentation that this is so. It isn't an UNREASONABLE use, but assuredly will NOT spring to the mind of anyone who sees the terms, most especially if they are familiar with their use in other areas of computing and mathematics. But, given that meaning, I now understand your point. Regards, Nick Maclaren. From magoldfish at gmail.com Tue Dec 12 15:41:03 2006 From: magoldfish at gmail.com (Marcus) Date: 12 Dec 2006 12:41:03 -0800 Subject: moinmoin advocacy? Message-ID: <1165956063.420236.80800@16g2000cwy.googlegroups.com> Apologies if this seems like it's off-topic, but since moinmoin is written in Python, I am hoping to solicit some good thoughts in this group. The problem: I'm setting up a wiki farm (small software company, my personal use as a PIM, hobby site). I may also deploy (customized) wikis to small/medium companies. I've been researching wikis recently, and I really like three: Moinmoin, Mediawiki, and SocialText (well, Trac, too, but ...). Moinmoin seems like a great match for me b.c. of the python underpinnings, but I'm worried that it is a dead or dying project, i.e. http://www.google.com/trends?q=TWiki%2C+MoinMoin%2C+PmWiki%2C+MediaWiki%2C+DokuWiki&ctab=0&geo=all&date=all) I'm also concerned b.c. the documentation and features seem sparse, and I read stray comments about "lack of scalability." Moinmoin also seems to lag (or plainly lack) some of the more popular "hot" wiki features found in other packages. Finally, I've read rave reviews of the latter two platforms, but I don't see much press (esp. positive) for Moinmoin. Should I invest the time in Moinmoin, and development for it, or use another platform? Will Moinmoin be able to keep up with the heated evolution of wikis for corporate and PIM usage? Is there a sense of moinmoin momentum (developer or user)? Is the lack of moinmoin advocacy a consequence of a weak product, or something else? Thanks, Marcus From kkylheku at gmail.com Sat Dec 9 16:50:24 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 9 Dec 2006 13:50:24 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <1165701024.138305.241500@j72g2000cwa.googlegroups.com> Steven D'Aprano wrote: > But Lisp's syntax is so unlike most written natural languages that that it > is a whole different story. Bahaha! > Yes, the human brain is amazingly flexible, > and people can learn extremely complex syntax and grammars (especially if > they start young enough) so I'm not surprised that there are thousands, > maybe tens or even hundreds of thousands of Lisp developers who find the > language perfectly readable. 1> '(especially if they start young enough) (ESPECIALLY IF THEY START YOUNG ENOUGH) 2> (sixth *) ENOUGH ... said! Yeah, so /unlike/ written natural languages! What a fucking moron. From tinodb at gmail.com Sat Dec 30 14:00:59 2006 From: tinodb at gmail.com (TiNo) Date: Sat, 30 Dec 2006 14:00:59 -0500 Subject: bad marshal data in site.py in fresh 2.5 install win In-Reply-To: <4595B89C.9090208@v.loewis.de> References: <4595B89C.9090208@v.loewis.de> Message-ID: <435b46e50612301100p295b60bdvb2c31657f11098cd@mail.gmail.com> Good question... I am now on a different computer, one that has never heard of Python, so no env vars are set. Again, this gives (my memory stick is now F:\): ------------------------------ F:\Python25>python -v # installing zipimport hook import zipimport # builtin # installed zipimport hook # F:\Python25\lib\site.pyc matches F:\Python25\lib\site.py import site # precompiled from F:\Python25\lib\site.pyc # F:\Python25\lib\os.pyc matches F:\Python25\lib\os.py import os # precompiled from F:\Python25\lib\os.pyc import nt # builtin # F:\Python25\lib\ntpath.pyc matches F:\Python25\lib\ntpath.py import ntpath # precompiled from F:\Python25\lib\ntpath.pyc # F:\Python25\lib\stat.pyc matches F:\Python25\lib\stat.py import stat # precompiled from F:\Python25\lib\stat.pyc # F:\Python25\lib\UserDict.pyc matches F:\Python25\lib\UserDict.py import UserDict # precompiled from F:\Python25\lib\UserDict.pyc # F:\Python25\lib\copy_reg.pyc matches F:\Python25\lib\copy_reg.py import copy_reg # precompiled from F:\Python25\lib\copy_reg.pyc # F:\Python25\lib\types.pyc matches F:\Python25\lib\types.py import types # precompiled from F:\Python25\lib\types.pyc import _types # builtin # zipimport: found 74 names in F:\Python25\lib\site-packages\setuptools-0.6c3-py 2.5.egg # F:\Python25\lib\locale.pyc matches F:\Python25\lib\locale.py import locale # precompiled from F:\Python25\lib\locale.pyc import encodings # directory F:\Python25\lib\encodings # F:\Python25\lib\encodings\__init__.pyc matches F:\Python25\lib\encodings\__ini t__.py import encodings # precompiled from F:\Python25\lib\encodings\__init__.pyc # F:\Python25\lib\codecs.pyc matches F:\Python25\lib\codecs.py import codecs # precompiled from F:\Python25\lib\codecs.pyc import _codecs # builtin # F:\Python25\lib\encodings\aliases.pyc matches F:\Python25\lib\encodings\aliase s.py 'import site' failed; traceback: Traceback (most recent call last): File "F:\Python25\lib\site.py", line 415, in main() File "F:\Python25\lib\site.py", line 406, in main aliasmbcs() File "F:\Python25\lib\site.py", line 356, in aliasmbcs import locale, codecs File "F:\Python25\lib\locale.py", line 14, in import sys, encodings, encodings.aliases File "F:\Python25\lib\encodings\__init__.py", line 32, in from encodings import aliases ValueError: bad marshal data # F:\Python25\lib\warnings.pyc matches F:\Python25\lib\warnings.py import warnings # precompiled from F:\Python25\lib\warnings.pyc # F:\Python25\lib\linecache.pyc matches F:\Python25\lib\linecache.py import linecache # precompiled from F:\Python25\lib\linecache.pyc Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> ------------------------------------------------------- ?? also removed site.pyc, and run it again, but with the same result. 2006/12/29, "Martin v. L?wis" : > TiNo schrieb: > > # G:\Python25\lib\encodings\aliases.pyc matches > [...] > > File "F:\Python25\lib\encodings\__init__.py", line 32, in > > > > What can I do about this? > > Where does F:\Python25 come from? > > If you have set any PYTHON* environment variables (e.g. PYTHONPATH), > unset them. > > Regards, > Martin > From __peter__ at web.de Thu Dec 14 11:42:40 2006 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Dec 2006 17:42:40 +0100 Subject: Logging module: problem with some mapping keys References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166106298.176199.301190@f1g2000cwa.googlegroups.com> <1166113691.753244.189350@f1g2000cwa.googlegroups.com> Message-ID: Tekkaman wrote: > Peter Otten wrote: >> Tekkaman wrote: >> >> > Thanks for the hint, but it's not a symlink >> >> What does logging._srcfile contain? Should be >> >> >>> import logging >> >>> logging._srcfile >> '/usr/lib/python2.4/logging/__init__.py' >> >> on your machine, but probably isn't. > '/usr/lib64/python2.4/logging/__init__.py' And neither /usr/lib nor /usr/lib/python2.4 are symlinks? Peter PS: Please don't top-post From kent at kentsjohnson.com Fri Dec 1 12:26:46 2006 From: kent at kentsjohnson.com (Kent Johnson) Date: Fri, 01 Dec 2006 17:26:46 GMT Subject: Functions, callable objects, and bound/unbound methods In-Reply-To: References: Message-ID: <457065D6.7060406@kentsjohnson.com> Ron Garret wrote: > The reason I want to do this is that I want to implement a trace > facility that traces only specific class methods. I want to say: > > trace(c1.m1) > > and have c1.m1 be replaced with a wrapper that prints debugging info > before actually calling the old value of m1. The reason I want that to > be an instance of a callable class instead of a function is that I need > a place to store the old value of the method so I can restore it, and I > don't want to start building a global data structure because that gets > horribly ugly, and a callable class is the Right Thing -- if there's a > way to actually make it work. If the only reason for a callable class is to save a single value (the original function), you could instead store it as an attribute of the wrapper function. Kent From steve at REMOVE.THIS.cybersource.com.au Wed Dec 20 06:53:51 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Wed, 20 Dec 2006 22:53:51 +1100 Subject: array, a better shell References: <1166615065.807704.12480@48g2000cwx.googlegroups.com> Message-ID: On Wed, 20 Dec 2006 03:44:25 -0800, bearophileHUGS wrote: > For array.array "B" means unsigned char, and such arrays accept to be > initialized from (str) strings too, this is quite useful: > >>>> from array import array >>>> a = array("B", "hello") > > But it seems such capability isn't shared with the append: [snip] > I like a lot the Python shell, it helps me in many different > situations. I have tried some Python shells: > - the vanilla one from DOS > - the one from ActivePython IDE > - the one from SPE > - ipython from a DOS shell > > But none of them has what I'd like. Is there a shortage of bytes, that Usenet posts about completely different topics have to message-pool? Did you have any questions, or were you just talking to yourself? [snip] > (Such interactive sessions can be saved too, and loaded again (they > become complex documents), but such ability isn't necessary into a > bare-bone shell that I am describing now. I am describing something as > simple as possible). No you're not. You're describing a quite complicated shell. You're describing a hypothetical shell with features other actual shells don't have, so therefore it can't possibly be as simple as possible. Perhaps what you meant to say was "the bare-minimum I consider worth using"? -- Steven. From reverseyorkage at david.com Sun Dec 17 09:33:56 2006 From: reverseyorkage at david.com (dyork) Date: Sun, 17 Dec 2006 14:33:56 GMT Subject: Roundtrip SQL data especially datetime References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: "Fredrik Lundh" wrote in message news:mailman.1710.1166356831.32031.python-list at python.org... > if you think that Python isn't typed, you've completely missed how things > work. your problem is that you're removing every trace of the type > information by casting everything to strings, not that Python itself (nor > the database adapters) cannot handle typed data. Fortunately, I'm not offended. I know perfectly well that Python variables are NOT typed, that Python relies on a dynamically typed model and most other languages support static typing.I assume you know that too. The advantage of static typing in this context is that the variable still holds the type even if the value happens to be null. Any value that has been exposed to user input comes back as a string and has to be validated and converted to the correct data type. Static typing provides a convenient place to generically find out what that type is, to drive a validator/convertor. There are many ways to do the equivalent in Python, and I'm interested in any suggestions that save me some work. DY From msherman77 at yahoo.com Mon Dec 4 08:50:07 2006 From: msherman77 at yahoo.com (Michael S) Date: Mon, 4 Dec 2006 08:50:07 -0500 (EST) Subject: Inheritance doesn't work In-Reply-To: Message-ID: <487166.32584.qm@web88305.mail.re4.yahoo.com> How about calling base class __init__ and then the pass statement? --- zefciu wrote: > I have a problem with inheritance under python. The > class definition is > longer, but the troublesome thing is: > > from PIL import Image > class MandelbrotImage (Image): > pass > > I am getting the following error: > Traceback (most recent call last): > File "", line 1, in ? > File "mandelimage.py", line 3, in ? > class MandelImage (Image): > TypeError: Error when calling the metaclass bases > module.__init__() takes at most 2 arguments (3 > given) > > > I am using python 2.4 from the Debian (Sid) > packages. > > Is it a bug, or am I doing something wrong? > zefciu > > -- > -----BEGIN zefciu's GEEK CODE BLOCK----- > Version: 3.12 > GS d-(+) s+++:-- a-- C++ UL P- L++(+++) E--- W+ N++ > o? > K? w-- M- V? PS-(--) PE++(+) Y PGP+ t 5 X R tv- b++ > DI D- G e>+++ h!>-- y? UF+ > ------END zefciu's GEEK CODE BLOCK------ > -- > http://mail.python.org/mailman/listinfo/python-list > From fredrik at pythonware.com Tue Dec 5 10:58:32 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 16:58:32 +0100 Subject: Printing unix Line endings from Windows. In-Reply-To: <1165320510.186512.59070@79g2000cws.googlegroups.com> References: <1165247935.679325.242850@80g2000cwy.googlegroups.com> <1165307391.447055.210020@n67g2000cwd.googlegroups.com> <1165309224.097576.66600@79g2000cws.googlegroups.com> <1165320510.186512.59070@79g2000cws.googlegroups.com> Message-ID: Ant wrote: > Is it worth me submitting a patch to fileinput which can take an > optional write mode parameter? absolutely. From fredrik at pythonware.com Sat Dec 23 02:41:42 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Dec 2006 08:41:42 +0100 Subject: scopes of local and global variable In-Reply-To: <87psabcvlc.fsf@pyenos.pyenos.org> References: <87tzzncx59.fsf@pyenos.pyenos.org> <87psabcvlc.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > does class WORK inherit t_len=0 from line1? > > does def getwork() inherit t_len=0 from line1? > > does def formattable(table_to_process,type) inherit t_len=0 from line1? > > does def format_t() inherit t_len=0 from line1? you may want to read the documentation: http://docs.python.org/ref/naming.html From steve at REMOVE.THIS.cybersource.com.au Sun Dec 24 16:58:51 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 25 Dec 2006 08:58:51 +1100 Subject: file/directory format/size help References: <1166975132.276914.77430@n51g2000cwc.googlegroups.com> Message-ID: On Sun, 24 Dec 2006 07:45:32 -0800, moishyyehuda wrote: > Hi > > I am writing a script to upload images. How do I check the format of > the file? How can I tell if the file is an image, movie, or text file? > I would also like to put a limit on how much a user can upload. So how > can I check how many bits, bytes, mb, gb are in a folder. > > So that sums up to > > #1 What type of file is the file? Is it a movie, image, or text > document? In the Windows world, one simply looks at the file extension (e.g. .gif, .avi, .txt, etc.) and hopes that it is correct. In the Linux world, there is a command "file" that tries to guess the file type, by looking at some combination of extension and/or signature bytes inside the file. Classic Macintosh OS kept file-type metadata as part of the file system; I don't know what OS X based Macintoshes do. Why do you care what the format of the file is? Can't you let the user upload whatever file they like? > #2 What particular form is the file jpeg, bmp, gif etc.? I don't understand the question. What do you mean "form"? > #3 The size of a directory? Directories themselves generally are a fixed size, e.g. on my ext3 file system my directories are typically 4K in size. But that's probably not what you mean :-) I assume you mean the size of all the files in a directory combined. You have to get the size of each file, and add them all together. If you use Google, you will find Python code to do that. Try looking on the ActiveState Python Cookbook: http://aspn.activestate.com/ASPN/Python/Cookbook/ -- Steven. From tmh.public at gmail.com Sat Dec 9 03:35:38 2006 From: tmh.public at gmail.com (tmh) Date: 9 Dec 2006 00:35:38 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165653338.110788.62580@n67g2000cwd.googlegroups.com> This is from the perspective of an aerospace engineer who passed through python several years ago on the way to lisp. Futhermore, this is a 2 glass of wine response. Nota Bene: All references to lisp in this response imply common lisp. Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? Way back, my initial motivation for learning python was the desire for something to post-process data files with a cleaner syntax than perl. It did that in spades. Despite having taken a C++ course in college, it wasn't until I started using python that I grokked concepts of object orientation. The aforementioned course spent too much time on basic concepts. I also envisioned being able to rapidly prototype things in python, then migrate them to C for performance. Long term, that was going to be the value of python, rapid prototype->C for performance. After writing a C interface for python to an engineering analysis code, I realized that there was nothing rapid about prototyping in python then migrating to C. This was also a period of time where there was some schizophrenia concerning numpy versus numeric python. I know this has been hashed out now, but at the time it was a distraction from the development of the library and I lost patience. So, I began searching for alternatives. Spent a couple years with a language that requires everything to be an object. Can someone hand me a hammer, I have a round peg here and a square hole there. Didn't have good numeric support, but based on other perceived advantages, I had hashed out an object system that would have provided numeric support. As I'm implementing the numeric stuff, I'm getting very annoyed with changes in the language that are requiring redesign of my objects. Plus, performance, while not bad, is not the best. The work required starts to outway the benefits, so here I go again, searching for the one language to rule them all. That's when I seriously consider lisp. At this point, if lisp doesn't work out, I'm giving up and going back to fortran, never to look at another language again. Ever. So, six months ago, I start digging into lisp. Hmm, lisp promotes functional programming, but you can do imperative if you really want to, or objective, or aspect, or your own. What about types? Well, to quote Yogi Berra, "In lisp, types are not required until they are required." This is great, I can quickly thrash out some code, profile, correct the algorithm, profile, add types, bam! Good performance. Looking over CMUCL/SBCL, really good numeric performance. Playing with code that is 30 years old, still runs, nice. Forced to learn emacs, why was I using vi again? In the correct settings, slime can be fun. Emacs+SBCL is one setting, I'll let you think of the other. What the hell are closures? Oh, yeah, now I get it, functions with state, I can use that in simulations with state vectors, very intuitive. And macros? Well, I don't need a domain specific language, yet, but using macros to build closures with multiple functions and shoving as much computation into the compilation stage as possible makes for very fast iteration over ODE's. Now I'm simultaneously iterating over 3 variations of an ODE in less time than iterating over 1 ODE in the previous one size fits all language. Code is data is code. I know, a tired old cliche. But for an engineer who wastes too much time data processing and not enough time analyzing/understanding said data, this is very powerful and provides a warm fuzzy feeling. Yet again, that could be the wine. > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. I've been writing code for engineering solutions for 15 years in various languages. I've gained more insight into coding in the last 6 months then in the previous 15 years. Since lisp allows you to employ any and every programming technique, it actually requires you to understand the techniques well enough to apply them when appropriate. I still respect python if for no other reason than I learned concepts of object orientation with it, but I don't consider for my coding. You should study lisp for at least a year, use it for some decent size projects. At the end of the day, even if you decide not to continue using it, you will be a much better coder. My bet, though, is that if you use it for a year, you won't want to use anything else. Don't be deterred by the parens or the prefix notation. You will have to rewire your brain to read lisp code, but the effort is worth it. The parens disappear and there is an elegance and simplicity to prefix notation that can't be matched by infix. Time for some more wine. Cheers, Tom From duncan.booth at invalid.invalid Thu Dec 14 03:56:33 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 14 Dec 2006 08:56:33 GMT Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> Message-ID: at wrote: > By the way, > > I think by approving > > a = b if condition else c > > used to avloind > > if condition: > a = b > else: > a = c Neither of those is much of an improvement over the other, and in fact if b or c are complex expressions I would definitely favour the longhand form. The benefit of having a conditional expression though is that in some situations it can make the code clearer by allowing you to avoid creating a name at all. e.g. if 'a' was then used as a parameter in a function call: d = fn(b if condition else c) and a has disappeared entirely. > > which is dealing with same psychological problem, Guido also > recognizes some need... > > Is it redundant according to your criteria, yes I would say: > > a = {True: a, False: c}[condition] > > or > > a = [c, a][condition] > > would yield exactly the same even in one sentence.... You do realise, I hope, that neither of these last two gives the same results as the inline 'if'? >>> x = 0 >>> print 3/x if x != 0 else -1 -1 >>> print {True: 3/x, False: -1}[x != 0] Traceback (most recent call last): File "", line 1, in print {True: 3/x, False: -1}[x != 0] ZeroDivisionError: integer division or modulo by zero >>> print [-1, 3/x][x != 0] Traceback (most recent call last): File "", line 1, in print [-1, 3/x][x != 0] ZeroDivisionError: integer division or modulo by zero >>> and before you suggest the good old standby and/or technique, that fails for other values: >>> print x != 0 and 3/x or -1 -1 >>> x=5 >>> print x != 0 and 3/x or -1 -1 >>> You need to use the messy: >>> print (x != 0 and (3/x,) or (-1,))[0] 0 to get exactly the same effect as the inline if with loss of both readability and performance. From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Sat Dec 9 17:33:22 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Sat, 09 Dec 2006 23:33:22 +0100 Subject: Error: unbound method in Tkinter class References: <6d3e0$457aefa4$4275d90a$12235@FUSE.NET> Message-ID: <4u0rtiF15oqr9U1@mid.individual.net> Kevin Walzer wrote: > I am trying to structure a Tkinter application with classes > instead of just with simple functions, but I'm not sure how to > call methods from my main class. > > My main class is packetstreamApp(). I don't think so -- packetstreamApp() would be an (unbound) instance. packetstreamApp without parentheses is the class. > Within that class I call various methods, including drawGUI() and > authorizeDump(). My problem comes when I try to call authorizeDump > from the Tkinter menu. Here is the code that calls > authorizeDump(): > > self.packetmenu.add_command(label="Start Network Monitor", > command=packetstreamApp.authorizeDump()) > [...] > TypeError: unbound method authorizeDump() must be called with > packetstreamApp instance as first argument (got nothing instead) Problem here: You call an instance method without having created an instance (it's not bound to any instance, thus it's an unbound method). One fix is to first create an instance and then access the method: 1. psApp = packetstreamApp() 2. test = psApp.authorizeDump() OR test = packetstreamApp.authorizeDump(psApp) Regards, Bj?rn P.S.: Beware: If you want to pass functions like above, leave out the parentheses or they will be executed immediately and their return value will be passed. -- BOFH excuse #389: /dev/clue was linked to /dev/null From amitsoni.1984 at gmail.com Wed Dec 6 02:10:11 2006 From: amitsoni.1984 at gmail.com (amitsoni.1984 at gmail.com) Date: 5 Dec 2006 23:10:11 -0800 Subject: CVXOPT Message-ID: <1165389011.695841.245150@79g2000cws.googlegroups.com> Hi, I want to use CVXOPT for my optimization problem but I am not able to find a good tutorial for that. Can someone give me a good link or tell me some basic steps how to write a simple code for a problem like following: min c'x subject to: x'Ax=0 x'Bx=b Thanks Amit From john106henry at hotmail.com Sat Dec 2 02:42:27 2006 From: john106henry at hotmail.com (John Henry) Date: 1 Dec 2006 23:42:27 -0800 Subject: client/server design and advice In-Reply-To: <4570d007$0$326$e4fe514c@news.xs4all.nl> References: <4570d007$0$326$e4fe514c@news.xs4all.nl> Message-ID: <1165045347.635141.178940@80g2000cwy.googlegroups.com> On the subject of passing things around, is there a no brainer way of sending files back and forth over Pyro? I am currently using a shared drive to do that. May be I missed that feature? Irmen de Jong wrote: > bruce wrote: > > hi irmen... > > > > happened to come across this post. haven't looked at pyro. regarding your > > 'work packets' could these essentially be 'programs/apps' that that are > > requested by the client apps, and are then granted by the dispatch/server > > app? > > > > Pyro supports a limited form of "mobile code" i.e. the automatic > transfering of Python modules to the other side. > But it has a few important limitations and there's the security > aspect as well. > > It's really better if you can stick to passing data around, not code... ;-) > > > i'm considering condor (univ of wisconsin) but am curious as to if pyro > > might also work. > > Not familiar with this. > > > --Irmen From juanrgonzaleza at canonicalscience.com Mon Dec 11 14:07:43 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 11 Dec 2006 11:07:43 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> Message-ID: <1165864063.900421.175800@l12g2000cwl.googlegroups.com> Harry George ha escrito: > Really? Given its small base, the percentage increases in Ruby use > (for any reason) can look quite impressive. I've see data suggesting > Ruby is replacing Perl and maybe Java. But I've yet to see data which > shows people dropping Python and moving to Ruby. Where do I find that > data? No _scientific_ data but TIOBE Dec index shows an increase of 9x on Ruby, 1x for Python and -4x for LISP [1]. More: "There is only 1 month to go before TIOBE announces its 'programming language of the year 2006'... Ruby remains to be top favorite for the title." Look also to Google Trends [2, 3]. One can notice further increase for Ruby and slight decreasing for Python. [1] http://www.tiobe.com/tpci.htm [2] http://www.google.com/trends?q=ruby+programming%2C+python+programming&ctab=0&geo=all&date=all http://www.google.com/trends?q=ruby+language%2C+python+language&ctab=0&geo=all&date=all From bjourne at gmail.com Mon Dec 4 16:07:23 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 4 Dec 2006 21:07:23 +0000 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> <45745C9E.9050500@v.loewis.de> <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> Message-ID: <740c3aec0612041307o5785d3c2vaade5378cb50a849@mail.gmail.com> On 12/4/06, Fredrik Lundh wrote: > BJ?rn Lindqvist wrote: > > > Sorry I haven't thought this through 100% > > obviously not. And you're not helping. Anyway, here's the patch: Index: Objects/listobject.c =================================================================== --- Objects/listobject.c (revision 52915) +++ Objects/listobject.c (arbetskopia) @@ -131,7 +131,18 @@ return ((PyListObject *)op) -> ob_size; } -static PyObject *indexerr = NULL; +static int +list_check_index(PyListObject *o, const char *ob_name, int i) +{ + if (i < 0 || i >= o->ob_size) { + const char fmt[] = "%s index %d not in range(%d)"; + char buf[256]; + snprintf(buf, 256, fmt, ob_name, i, o->ob_size); + PyErr_SetString(PyExc_IndexError, buf); + return -1; + } + return 0; +} PyObject * PyList_GetItem(PyObject *op, Py_ssize_t i) @@ -140,13 +151,9 @@ PyErr_BadInternalCall(); return NULL; } - if (i < 0 || i >= ((PyListObject *)op) -> ob_size) { - if (indexerr == NULL) - indexerr = PyString_FromString( - "list index out of range"); - PyErr_SetObject(PyExc_IndexError, indexerr); - return NULL; - } + + if (list_check_index((PyListObject *)op, "list", i) == -1) + return NULL; return ((PyListObject *)op) -> ob_item[i]; } @@ -161,12 +168,10 @@ PyErr_BadInternalCall(); return -1; } - if (i < 0 || i >= ((PyListObject *)op) -> ob_size) { - Py_XDECREF(newitem); - PyErr_SetString(PyExc_IndexError, - "list assignment index out of range"); - return -1; - } + if (list_check_index((PyListObject *)op, "list", i) == -1) { + Py_XDECREF(newitem); + return -1; + } p = ((PyListObject *)op) -> ob_item + i; olditem = *p; *p = newitem; @@ -387,15 +392,10 @@ static PyObject * list_item(PyListObject *a, Py_ssize_t i) { - if (i < 0 || i >= a->ob_size) { - if (indexerr == NULL) - indexerr = PyString_FromString( - "list index out of range"); - PyErr_SetObject(PyExc_IndexError, indexerr); - return NULL; - } - Py_INCREF(a->ob_item[i]); - return a->ob_item[i]; + if (list_check_index(a, "list", i) == -1) + return NULL; + Py_INCREF(a->ob_item[i]); + return a->ob_item[i]; } static PyObject * @@ -692,11 +692,9 @@ list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v) { PyObject *old_value; - if (i < 0 || i >= a->ob_size) { - PyErr_SetString(PyExc_IndexError, - "list assignment index out of range"); - return -1; - } + if (list_check_index(a, "list", i) == -1) + return -1; + if (v == NULL) return list_ass_slice(a, i, i+1, v); Py_INCREF(v); And the result: >>> L = range(10) >>> L[44] Traceback (most recent call last): File "", line 1, in IndexError: list index 44 not in range(10) >>> L[11] = 77 Traceback (most recent call last): File "", line 1, in IndexError: list index 11 not in range(10) ... And it was damn easy. -- mvh Bj?rn -------------- next part -------------- A non-text attachment was scrubbed... Name: better-index-error.patch Type: text/x-patch Size: 2560 bytes Desc: not available URL: From joe at skyrush.com Sun Dec 3 12:56:21 2006 From: joe at skyrush.com (Joe Peterson) Date: Sun, 03 Dec 2006 10:56:21 -0700 Subject: text adventure question Message-ID: <45730FC5.4020505@skyrush.com> On 2006-12-02, Ara Kooser wrote: > I am working on a text adventure game for python to get back > into python programming. My version 0.1 used only functions so > I could get familiar with how those work. I want to move beyond > that. I am not sure what would be a good Python way of handling > this. I was wondering if classes would help? What things > should be included in the main program? That's so funny! I did the same thing when I was learning Python! My cousin and I wrote some text adventure games when we were teenagers (the code was on a TRS-80 in BASIC back then, and the BASIC program became a kind of interpreter to interpret the adventure "program" files). I re-wrote it in C, then Java, then Python. I used it as a sort of learning tool, and since Python is so good with strings, it became very efficient. I now have the code running on one of my web pages, so you can play the games on-line: http://www.skyrush.com/explore/ -Joe From bjourne at gmail.com Sat Dec 9 16:00:08 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sat, 9 Dec 2006 22:00:08 +0100 Subject: merits of Lisp vs Python In-Reply-To: <457a95ac$0$8721$ed2619ec@ptn-nntp-reader02.plus.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <457a95ac$0$8721$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <740c3aec0612091300y4ac8013au32e814ec5a6146db@mail.gmail.com> > I think that people who know more languages and more about programming will > be much more inclined to use Lisp than Python. Look at the contents of the > newsgroups for example, c.l.l has a thread on memoization whereas c.l.p has > a thread about wrestling oiled pigs. Practicality beats purity. :) -- mvh Bj?rn From tleeuwenburg at gmail.com Sun Dec 3 23:48:30 2006 From: tleeuwenburg at gmail.com (tleeuwenburg at gmail.com) Date: 3 Dec 2006 20:48:30 -0800 Subject: Python library for reading ODF Spreadsheets In-Reply-To: <45735F89.7070507@lexicon.net> References: <45735F89.7070507@lexicon.net> Message-ID: <1165207710.600412.213810@79g2000cws.googlegroups.com> ODT is an XML format, so you can use any XML library, including the one in the default python distribution. It might be zipped XML in which case you will need to uncompress it first. -T John Machin wrote: > On 4/12/2006 10:18 AM, Jonathan Hunt wrote: > > Hi all, > > > > I have had a look on google/freshmeat etc. so please forgive me if I've missed > > an obvious answer. > > > > Can someone point me to a simple library to read/write ODF spreadsheets (i.e. > > OpenOffice Calc 2). I know I can interface with OOo but this is running on a > > server where I would rather avoid a full-on library. > > > > Something like > > http://sourceforge.net/projects/pyexcelerator/ > > but for reading ODF. > > > > I have found write only solutions - but no read library except for the full > > Monte OOo/UNO which I want to avoid. > > > > Please, please help. Or the pragmatist in me will be forced to use XLS to get > > this job done. Thanks in advance for any help. > > There is no such library as you describe. > > > > > Jonny > > > > (I'm not on the list. Please CC me answers). > > Such a request is usually considered to be impertinent bludging and is > likely to get you *no* answers. Consider subscribing to the list and > reading it. Alternatively you could use a newsreader pointed at > news:comp.lang.python or a browser pointed at > http://groups.google.com/group/comp.lang.python. > > HTH, > John From rzantow at gmail.com Thu Dec 14 11:15:41 2006 From: rzantow at gmail.com (rzed) Date: Thu, 14 Dec 2006 11:15:41 -0500 Subject: aggdraw for 2.5 on WinXP? Message-ID: Has anyone generated an aggdraw installer or aggdraw.pyd for Python 2.5 (WinXP)? If so, could it be made available for those of us who don't have a working compiler? -- rzed From steve at REMOVE.THIS.cybersource.com.au Sat Dec 16 20:46:02 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 17 Dec 2006 12:46:02 +1100 Subject: How to test if two strings point to the same file or directory? References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: On Sun, 17 Dec 2006 12:30:15 +1100, Steven D'Aprano wrote: >> Is there a >> better way to test if two paths point to the same file or directory >> (and that will work across platforms?) > > How complicated do you want to get? If you are thinking about aliases, > hard links, shortcuts, SMB shares and other complications, I'd be > surprised if there is a simple way. Almost, but not quite, platform independent. os.path.samefile(path1, path2) >From the docs: samefile(path1, path2) Return True if both pathname arguments refer to the same file or directory (as indicated by device number and i-node number). Raise an exception if a os.stat() call on either pathname fails. Availability: Macintosh, Unix http://docs.python.org/lib/module-os.path.html -- Steven. From paddy3118 at netscape.net Wed Dec 13 23:59:01 2006 From: paddy3118 at netscape.net (Paddy) Date: 13 Dec 2006 20:59:01 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> Message-ID: <1166072341.218097.34400@16g2000cwy.googlegroups.com> Ken Tilton wrote: > (apologies for nasty formatting): ;-) - Paddy! From bj_666 at gmx.net Sun Dec 31 07:54:37 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sun, 31 Dec 2006 13:54:37 +0100 Subject: Question concerning this list [WebCrawler] References: Message-ID: In , Thomas Ploch wrote: > This is how my regexes look like: > > import re > > class Tags: > def __init__(self, sourceText): > self.source = sourceText > self.curPos = 0 > self.namePattern = "[A-Za-z_][A-Za-z0-9_.:-]*" > self.tagPattern = re.compile("<(?P%s)(?P[^>]*)>" > % self.namePattern) > self.attrPattern = re.compile( > r"\s+(?P%s)\s*=\s*(?P\"[^\"]*\"|'[^']*')" > % self.namePattern) Have you tested this with tags inside comments? >>> You are probably right. For me it boils down to these problems: >>> - Implementing a stack for large queues of documents which is faster >>> than list.pop(index) (Is there a lib for this?) >> >> If you need a queue then use one: take a look at `collections.deque` or >> the `Queue` module in the standard library. > > Which of the two would you recommend for handling large queues with fast > response times? `Queue.Queue` builds on `collections.deque` and is thread safe. Speedwise I don't think this makes a difference as the most time is spend with IO and parsing. So if you make your spider multi-threaded to gain some speed go with `Queue.Queue`. Ciao, Marc 'BlackJack' Rintsch From JShrager at gmail.com Mon Dec 11 16:38:50 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 11 Dec 2006 13:38:50 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165868422.964826.52840@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> Message-ID: <1165873130.318729.298260@j72g2000cwa.googlegroups.com> > Yes, but these are community symbols or tribe marks. They don't have > much meaning per se, just like the language name or a corporate > identity. Unfortunately, I don't believe that this is entirely correct....I do lurk c.l.p and see quite often people arguing (if briefly) about what the one (and preferably only one) obvious way of doing things is. This is only subtly ridiculous. The other ("It fits your brain") is much less subtle, and much more problematic: Now, I'm willing to buy that "it fits your brain" is taken less seriously, but ... > However they express an attitude ( being easy and free from > language design redundancy ) that can be measured at least subjectively > by the user. If Ruby "fits the brain" better, then people will simply > drop Python in future or right now. There is nothing deep about it. ...if not deep, at least insidious, as demonstrated in part by the current thread wherein, until forced to give it up, the present pythonistas spent a significant number of chars trying to arguing, in effect, that Lisp does NOT fit (one's) brain (e.g, is easier to use, easier to learn, etc.) IN GENERAL. It seems to me (here and on c.l.p) that many pythonista have somehow drunk this Koolaide and that as a result have a sort of smug superiority about it. Of course, Lispers have a smug superiority as well, but at least we have actual language features (macros, compositionality, compilers) to wave around, not ridiculous pop psychological noise. From nospam at riddergarn.dk Fri Dec 29 03:55:28 2006 From: nospam at riddergarn.dk (Scripter47) Date: Fri, 29 Dec 2006 09:55:28 +0100 Subject: pythoncom module Message-ID: <4594D800.9040308@riddergarn.dk> Hey, I need a module called "pythoncom" anyone that knows where a can find that module??? thanks! From fredrik at pythonware.com Fri Dec 8 01:17:15 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 08 Dec 2006 07:17:15 +0100 Subject: Need Help Parsing From File In-Reply-To: <4578F6BB.4050204@lexicon.net> References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> <1165517086.976152.216270@16g2000cwy.googlegroups.com> <7.0.1.0.0.20061207230730.03e40c38@yahoo.com.ar> <4578F6BB.4050204@lexicon.net> Message-ID: John Machin wrote: > Indeed, and their docs say that the default for _fmode is text mode. the default doesn't matter much if you're writing library code for an application that may change it. From stefan.behnel-n05pAM at web.de Thu Dec 14 13:53:28 2006 From: stefan.behnel-n05pAM at web.de (Stefan Behnel) Date: Thu, 14 Dec 2006 19:53:28 +0100 Subject: Validate XML against a set of XSD files, with Python In-Reply-To: References: <1165962804.855630.222240@79g2000cws.googlegroups.com> Message-ID: <45819DA8.6050604@web.de> Laszlo Nagy wrote: >> - libxml : http://codespeak.net/lxml/ >> > Probably this is what I need to use. (However, I see in the mailing > lists that there are problems with this part of libxml2.) XML Schema support in libxml2 is not complete. It should work in most cases, but I've already stumbled into schemas that just don't work (especially generated ones). RelaxNG support in libxml2 is pretty much perfect, BTW. Stefan From franz.steinhaeusler at gmx.at Fri Dec 15 05:05:09 2006 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Fri, 15 Dec 2006 11:05:09 +0100 Subject: OT - Looking for DrPython project help Message-ID: <1ms4o25800tma081cv7nm6uvk098v4qq3m@4ax.com> Sorry for posting that, if you are not intersted, please ignore my post. I'm looking for person(s), which are interested in testing and possibly bug fixing for DrPython (hosted on Sourceforge) in general and with a certain focus for Linux. Sometimes, texts in dialogs are not entirely visible, some are without sizers, some crashes, plugin testing, ... If you have interest, please send a message to "Open Discussion": http://sourceforge.net/forum/forum.php?forum_id=283802 From steve at REMOVEME.cybersource.com.au Wed Dec 27 22:22:21 2006 From: steve at REMOVEME.cybersource.com.au (Steven D'Aprano) Date: Thu, 28 Dec 2006 14:22:21 +1100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: On Wed, 27 Dec 2006 20:15:33 +0100, Sebastian 'lunar' Wiesner wrote: > Ben typed > >> I have a python script on a windows system that runs fine. Both use >> tabs to indent sections of the code. > > Just a tip for you: In python you never use tabs for indentation. The > python style guide [1] recommends four spaces per indentation level. > > [1] http://www.python.org/dev/peps/pep-0008/ [obligatory pot-shot in the never-ending spaces versus tabs war] In Python, I frequently use tabs for indentation, and I never have any trouble *except* when posting code to Usenet, where other people's news readers can't cope with tabs. But I think we all agree that mixing tabs and spaces is A Very Bad Thing. -- Steven D'Aprano From pavlovevidence at gmail.com Thu Dec 14 13:49:33 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 14 Dec 2006 10:49:33 -0800 Subject: Conditional iteration In-Reply-To: <45819342$0$322$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> <1166118715.306793.122570@l12g2000cwl.googlegroups.com> <45819342$0$322$e4fe514c@news.xs4all.nl> Message-ID: <1166122173.374150.191560@t46g2000cwa.googlegroups.com> at wrote: > I am not claiming that it was THE motivation, but it solves my problem... So we're back to where we started. Look, this "it makes sense for ME", "it solves MY problem" stuff is just not going to cut it. A language change is something everyone has to live with, therefore it has to make sense for the community as a whole, not just one person. But you've completely ignored concerns that don't apply to YOU this whole thread. Carl Banks PS. You're top-posting again. Please respect other readers. From simone.leo at gmail.com Thu Dec 14 09:24:58 2006 From: simone.leo at gmail.com (Tekkaman) Date: 14 Dec 2006 06:24:58 -0800 Subject: Logging module: problem with some mapping keys In-Reply-To: References: <1166029343.340490.163490@79g2000cws.googlegroups.com> Message-ID: <1166106298.176199.301190@f1g2000cwa.googlegroups.com> Peter Otten wrote: > > An evil symlink, maybe? Thanks for the hint, but it's not a symlink > > $ ln -s /usr/local/lib/python2.4/logging > $ python > [snip] > >>> import logging > >>> logging.basicConfig(format="%(pathname)s") > >>> logging.getLogger().critical("yadda") > /usr/local/lib/python2.4/logging/__init__.py > >>> > $ rm logging > $ python > [snip] > >>> import logging > >>> logging.basicConfig(format="%(pathname)s") > >>> logging.getLogger().critical("yadda") > > > Peter From Stephen.Egan at medicalaffairs.com Tue Dec 5 18:31:34 2006 From: Stephen.Egan at medicalaffairs.com (Stephen.Egan at medicalaffairs.com) Date: Tue, 5 Dec 2006 17:31:34 -0600 Subject: Internet Gambling Losses Refunded Message-ID: Greetings, I came across your ad via Google Search and wanted to inquire about your services. I am hoping to recover my losses from online gaming Please Contact me as soon as possible Regards, Steve Egan ------------------------------------------------------------------------ Disclaimer "The information in this email is confidential and may be legally privileged. It is intended solely for the addressee and access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. When addressed to our clients, any opinions or advice contained in this email are subject to the terms and conditions expressed in the governing client engagement letter or contract." -------------- next part -------------- An HTML attachment was scrubbed... URL: From whumeniu+anti+spam at telus.net Sun Dec 10 13:07:59 2006 From: whumeniu+anti+spam at telus.net (Wade Humeniuk) Date: Sun, 10 Dec 2006 18:07:59 GMT Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <32Yeh.53739$rv4.44663@edtnps90> Steven D'Aprano wrote: > > But I also gained a little more insight into why Lispers love their > language. I've learnt that well-written Lisp code isn't as hard to read as > I remembered, so I'd just like to withdraw a comment I made early in the > piece. I no longer believe that Lisp is especially strange compared to > natural languages. > > Anyway, real life catches up on me, and so I must drop out of this thread. > May it not last for ever. > And I have heard why Pythonistas like their language. They can get things accomplished in it. The best positive feedback is success. You can get lost in theoretical, metaphorical discussions about computer languages. It is frustrating and in many cases pointless. As for why you have seen conflicting answers and, yes, sometimes hostile responses. I have no idea. But, I think I have come to a point in my life where I do not need to be right. W From jstroud at mbi.ucla.edu Wed Dec 20 20:09:33 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 21 Dec 2006 01:09:33 GMT Subject: Tkinter, StringVar and dict In-Reply-To: <147e6$4589bcdd$4275d90a$6123@FUSE.NET> References: <147e6$4589bcdd$4275d90a$6123@FUSE.NET> Message-ID: Kevin Walzer wrote: > I'm trying to manage user preferences in a Tkinter application by > initializing some values that can then be configured from a GUI. The > values are set up as a dict, like so: > > self.prefs= { > 'interface': '-en1', > 'verbose': '-v', > 'fontname': 'Courier', > 'point': 12, > } > > To link these values to the appropriate Tkinter variables, I'm using > code like this: > > self.prefs['interface'] = StringVar() > self.prefs['interface'].set("-en0") # initialize > > This raises an error in Tkinter: > > Exception in Tkinter callback > Traceback (most recent call last): > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", > line 1403, in __call__ > return self.func(*args) > File "/Users/kevin/Programming/packetstream/packetstream-classes.py", > line 293, in setPrefs > self.prefs['interface'] = StringVar() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", > line 3237, in __setitem__ > self.tk.call(self.name, 'configure', '-'+key, value) > TclError: unknown option "-interface" > > Can someone help me smooth this out--to get dict key-values into a > Tkinter variable like StringVar()? > > Thanks. > I overlooked this latter question. Probably, your naming confusion above with self.prefs and the resulting errors obscure your intention. But, were I to keep a dictionary of StringVars for prefs, I would initialize it in this manner: # somewhere in self defaults = { 'interface' : '-en1', 'verbose' : '-v', 'fontname' : 'Courier', 'point' : 12 } self.prefs = dict((d,StringVar()) for d in defaults) for d in defaults: self.prefs[d].set(defaults[d]) Note, of course, that you will need to access 'point' like this if you want it back as an int: int(self.prefs['point'].get()) Because StringVars return strings from their get() method. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Fri Dec 8 13:57:28 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Fri, 08 Dec 2006 19:57:28 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> Message-ID: <4ttqsoF15ld61U3@mid.individual.net> Alex Mizrahi wrote: > (message (Hello 'Bjoern) >> BS> Can you give an example? I cannot imagine how homogenity >> always BS> results in easiness. > homogenity means that i can cut any expression and paste in any > other expression, and as long as lexical variables are ok, i'll > get correct results -- i don't have to reindent it or whatever. Ah, so *that's* what you meant ... but I don't really understand the ease of it. > also, there's no need for operator precendence to be taken in > accound -- order is explicitly defined. expressions are > homogenous, they do not depend on other expressions near them > (except lexical variables and side effects). Sorry, I don't get it ;) Where does Python have things like nonexplicit defined operator order? > the other example of homogenous syntax is XML, that is very > popular nowadays, and it's very similar to lisp's s-expressions. Spoken freely, I don't like XML because it's hardly readable. Is it "easy"? If yes, what's your definition of "easy"? Regards, Bj?rn Xpost cll,clp -- BOFH excuse #437: crop circles in the corn shell From mccredie at gmail.com Wed Dec 6 17:52:49 2006 From: mccredie at gmail.com (Matimus) Date: 6 Dec 2006 14:52:49 -0800 Subject: Mirror imaging binary numbers In-Reply-To: <1165440014.762774.167950@73g2000cwn.googlegroups.com> References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> Message-ID: <1165445569.287552.266120@j44g2000cwa.googlegroups.com> Craig wrote: > I'm trying to switch binary numbers around so that the MSB becomes the > LSB etc. What do you mean 'binary numbers'? They are all binary. If you mean the int type, they are 32 bits long and there are 16 bits between the MSB and LSB (Most/Least Significant _Byte_). Do you want to swap the most significant word with the least significant word? Swap the most significant nibble with the least significant nibble in a Byte? Or do you want to completely reverse the bit order? To swap nibbles in a byte: reverseVal = (val & 0xf) << 4 | (val & 0xf0) >> 4 Basicly you are going to need to use the bit operators (|,&, << and >>) to get what you need. If you could be more specific perhaps I could be of more help. From bjorn.kempen at gmail.com Wed Dec 27 20:44:30 2006 From: bjorn.kempen at gmail.com (buffi) Date: 27 Dec 2006 17:44:30 -0800 Subject: failing to instantiate an inner class because of its order In-Reply-To: <873b707vx3.fsf@pyenos.pyenos.org> References: <87fyb16icw.fsf@pyenos.pyenos.org> <877iwc7w56.fsf@pyenos.pyenos.org> <873b707vx3.fsf@pyenos.pyenos.org> Message-ID: <1167270270.396061.91950@a3g2000cwd.googlegroups.com> > class Model: > def fuck(self):print "fuck!" > > class View: > Model() #this part is fine > > class Controller: > def __init__(self): > self.Model=Model() > > Controller().Model.fuck() #actually slight problem in previous solution > > > Has to call in this way. I have confirmed this works. What is even the point of the class View there since you don't use it? /buffi (buffis.com) From at at tuko.nl Thu Dec 14 12:59:21 2006 From: at at tuko.nl (at) Date: Thu, 14 Dec 2006 18:59:21 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> <4ucmp2F17jqc2U1@mid.uni-berlin.de> Message-ID: <458190f4$0$322$e4fe514c@news.xs4all.nl> Dear Diez, True, I was just mentioning a workaround for a typical case. Kind regards, Arjan Diez B. Roggisch wrote: >> Is it redundant according to your criteria, yes I would say: >> >> a = {True: a, False: c}[condition] >> >> or >> >> a = [c, a][condition] >> >> would yield exactly the same even in one sentence.... > > Obviously it is _not_ the exact same. > > > def fac(n): > return n * fac(n-1) if n else 1 > > > Try that with your recipes above. > > Diez From m.errami at gmail.com Thu Dec 7 21:51:45 2006 From: m.errami at gmail.com (m.errami at gmail.com) Date: 7 Dec 2006 18:51:45 -0800 Subject: write an update manager in python/wxPython In-Reply-To: <1165533541.009571.26510@73g2000cwn.googlegroups.com> References: <1165522027.874287.206150@16g2000cwy.googlegroups.com> <45788ffc$0$2448$db0fefd9@news.zen.co.uk> <1165533541.009571.26510@73g2000cwn.googlegroups.com> Message-ID: <1165546305.024425.214440@16g2000cwy.googlegroups.com> Will & Gabriel Well I will then think of something. Thank you very much. I do appreciate your help. M.E. gagsl-py at yahoo.com.ar wrote: > On 7 dic, 19:04, Will McGugan wrote: > > m.err... at gmail.com wrote: > > > I have a small application for which I would like to write an update > > > manager. I assume that the basics of it is to compare versions of the > > > user's current application and a new one store in a new file on a > > > particular URL. > > Dont think there is a standard way of doing it. The way I have done it > > in my applications is to keep an ini file containing the version number, > > which is downloaded and compared against the version of the app. That > > part is trivial to implement in python with urllib. I just point the > > user at the download url when there is a new version. It would require a > > little more effort if you want to have some kind of automatic update... > > There is a sample script (in tools/versioncheck in your Python > directory) you could use as a starting point. Not a big deal... > > -- > Gabriel Genellina From gagsl-py at yahoo.com.ar Sat Dec 16 22:34:30 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 16 Dec 2006 19:34:30 -0800 Subject: module wide metaclass for new style classes In-Reply-To: References: Message-ID: <1166326470.328566.150370@73g2000cwn.googlegroups.com> On 16 dic, 14:44, "Daniel Nogradi" wrote: > I used to have the following code to collect all (old style) class > names defined in the current module to a list called reg: > > def meta( reg ): > def _meta( name, bases, dictionary ): > reg.append( name ) > return _meta > > reg = [ ] > __metaclass__ = meta( reg ) > > class c1: > pass > > class c2: > pass > > print reg > > This would correctly print [ 'c1', 'c2' ]. Now I would like to switch > to new style classes but replacing class c1: and class c2: by class > c1(object): and class c2(object): doesn't work because the metaclass > associated with object will be called and not mine. Of course if I > would add __metaclass__ = meta(reg) to all class definitions that > would work, but how do I do this on the module level? That code doesn't work even for classic classes. Anyway, you don't have to add __metaclass__ everywhere, only to the base class(es). If all you want to register is contained in a single module, I prefer a function that iterates over all defined classes: from inspect import isclass for obj in globals().values(): if isclass(obj): # may be stricter too, like issubclass(obj, Base) reg.append(obj) -- Gabriel Genellina From researchbase at gmail.com Sun Dec 3 14:50:55 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Mon, 4 Dec 2006 01:20:55 +0530 Subject: please provide urls for some python success stories. Message-ID: hello all. actually I have been recently appointed as a technology consulltent at a huge company. and I have couple more such projects in the pypeline. unfortunately the officials out here are too much in favour of java and I have personally worked with both and find that python is heaven in syntax and makes it very easy to do complex things. on speed? I think experts on this list can give better answer, but efficiency and maintainance wise there is nothing like python I believe. the problem here is that I am from India and all indians on this list can correct me if I am wrong, very few people know about python here. infact a vast majority of programmers ask me "python? what is that!" they don't even know that it is a programming language, let alone using it. but I am amongst the very few who have actually used both java and python. I need some strong evidence to prove to these stupid and java oriented officials that there is some thing better than java called python. can some one provide me some urls or may be share some personal experience on this issue? I saw a couple of blogs and a few success stories on the python web site itself. but the common answer I am getting is "y! even java can do this and java is much faster!" I am really adicted to python due to its superiority and efficiency and the amount of libraries. but I need some strong official efidence. Please help me, I don't want to leave python. Krishnakant. From jon at ffconsultancy.com Sun Dec 17 20:54:48 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 18 Dec 2006 01:54:48 +0000 Subject: merits of Lisp vs Python References: <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> Message-ID: <4585f57b$0$8740$ed2619ec@ptn-nntp-reader02.plus.net> Kaz Kylheku wrote: > The removal for the need for manual object lifetime computation does > not cause a whole class of useful programs to be rejected. Sometimes you must be able to guarantee that a resource has been disposed before you can continue. That is why we have finalisers in OCaml and dispose in .NET (to manage external resources). > In fact, all previously correct programs continue to work as before, Removing (external) resource allocation will break some programs. > and in addition, some hitherto incorrect programs become correct. > That's an increase in power: new programs are possible without losing > the old ones. It is a trade-off. Aside from managing external resources, GC has performance implications that affect the design decisions of real-time applications. > Wheas programs can't be made to conform to the pure functional paradigm > by adjusting the semantics of some API function. Programs which don't > conform have to be rejected, You can rephrase any impure program as a pure program (Turing). >> Reliable GC gets rid of a large and >> important class of program errors and makes possible programming in a >> style that relies on it. > > Right. GC gets rid of /program errors/. Pure functional programming > gets rid of /programs/. Pure functional programming does not get rid of any programs. Pure functional programming does get rid of program errors, e.g. concurrency issues. >> You can make languages more powerful by removing features as well as by >> adding them. > > Note that changing the storage liberation request from an imperative to > a hint isn't the removal of a feature. It's the /addition/ of a > feature. The new feature is that objects can still be reliably used > after the implementation was advised by the program that they are no > longer needed. Programs which do this are no longer buggy. Another new > feature is that programs can fail to advise the implementation that > some objects are no longer needed, without causing a leak, so these > programs are no longer buggy. The pool of non-buggy programs has > increased without anything being rejected. You have rejected all programs that rely upon a resource being disposed before a certain point. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From rampeters at gmail.com Tue Dec 5 15:32:33 2006 From: rampeters at gmail.com (johnny) Date: 5 Dec 2006 12:32:33 -0800 Subject: Multiple FTP download using Muliti thread In-Reply-To: <1165342918.083063.150690@j44g2000cwa.googlegroups.com> References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> <1165277324.677203.107650@l12g2000cwl.googlegroups.com> <1165284311.911998.151460@l12g2000cwl.googlegroups.com> <1165342918.083063.150690@j44g2000cwa.googlegroups.com> Message-ID: <1165350752.984678.215390@80g2000cwy.googlegroups.com> Ok I fixed it. Needed to put in username, and password in the c.login inside while True loop. while True: host, e = tq.get() c = ftplib.FTP(host) c.connect() try: c.login() p = posixpath.basename(e) fp = open('H:/eclipse/workspace/src/ftp_download/' + p, 'wb') johnny wrote: > I am getting the following error: > > raise error_temp, resp > error_temp: 421 Unable to set up secure anonymous FTP > > Here is the code: > > import ftplib, posixpath, threading > from TaskQueue import TaskQueue > > def worker(tq): > while True: > host, e = tq.get() > > c = ftplib.FTP(host) > c.connect() > try: > c.login() > p = posixpath.basename(e) > fp = open('H:/eclipse/workspace/src/ftp_download/' + p, > 'wb') > try: c.retrbinary('RETR %s' % e, fp.write) > finally: fp.close() > finally: c.close() > > tq.task_done() > > if __name__ == '__main__': > q = TaskQueue() > #host = 'ftp.microsoft.com' > host = 'mysite.com' > c = ftplib.FTP(host) > c.connect() > try: > #c.login() > c.login("temp at mysite.com","temppass" ) > > #folder = '/deskapps/kids/' > folder = '' > for n in c.nlst(folder): > #if n.lower().endswith('.exe'): > # q.put((host, n)) > if n.lower().endswith('.jpg'): > q.put((host, n)) > elif n.lower().endswith('.jpeg'): > q.put((host, n)) > > finally: c.close() > > numworkers = 4 > for i in range(numworkers): > t = threading.Thread(target=worker, args=(q,)) > t.setDaemon(True) > t.start() > > q.join() > print 'Done.' > > > Justin Ezequiel wrote: > > johnny wrote: > > > When I run the following script, with host and password and username > > > changed, I get the following errors: > > > raise error_temp, resp > > > error_temp: 421 Unable to set up secure anonymous FTP > > > > > > Dose the host should allow 4 simultaneous login at a time? > > > > > > > does it work using ftp.microsoft.com? > > > > post your code From pwatson at redlinepy.com Wed Dec 13 22:14:55 2006 From: pwatson at redlinepy.com (Paul Watson) Date: Wed, 13 Dec 2006 21:14:55 -0600 Subject: how to determine Operating System in Use? In-Reply-To: References: Message-ID: <4ubttfF17m7vaU1@mid.individual.net> Ian F. Hood wrote: > Hi > In typically windows environments I have used: > if 'Windows' in os.environ['OS']... > to prove it, but now I need to properly support different environments. > To do so I must accurately determine what system the python instance is > running on (linux, win, mac, etc). > Is there a best practises way to do this? > TIA > Ian The more significant question is "why" do you want to do this? Are you writing an asset management tool? Do you just want to tell the user what operating system they are using? The reason may lead to a different solution. From vbgunz at gmail.com Sun Dec 31 00:34:22 2006 From: vbgunz at gmail.com (vbgunz) Date: 30 Dec 2006 21:34:22 -0800 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> Message-ID: <1167543262.361311.123700@v33g2000cwv.googlegroups.com> Ben Sizer wrote: > I've installed several different versions of Python across several > different versions of MS Windows, and not a single time was the Python > directory or the Scripts subdirectory added to the PATH environment > variable. I don't understand what all the fuss is about. Add a single page to the installer and on it, have 3 radio buttons. The choices could be "add to path (recommended)", "add to path with version", "do not add to path (not recommended)". On a brand new installation or if the user is upgrading, "add to path (recommended)" should automatically be selected. If the user is downgrading, "add to path with version" could be the default selection? If a user truly does not want the Python installation to touch the path, they'll know to select "do not add to path (not recommended)" and it's the end of the story, everyone is happy... It doesn't even have to be like this *but* why not help add the install to the path? I haven't used Windows in quite a while but I've done several installations across some of the family boxes and some inside some virtual machines and every time I tried launching python through a console I temporarily got stunned with an error. I just forget and wish the install could at least remind me. No problem, I know how to add the path so no biggie at all. Some if not most python documentation assumes Python is on the path... Anyhow, I don't get why it doesn't apply by default in some way on Windows even if at the least it could be a simple reminder or tip to do so. From Leo.Kislov at gmail.com Wed Dec 13 05:02:30 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 13 Dec 2006 02:02:30 -0800 Subject: inconvenient unicode conversion of non-string arguments References: Message-ID: <1166004150.866538.299670@j72g2000cwa.googlegroups.com> Holger Joukl wrote: > Hi there, > > I consider the behaviour of unicode() inconvenient wrt to conversion of > non-string > arguments. > While you can do: > > >>> unicode(17.3) > u'17.3' > > you cannot do: > > >>> unicode(17.3, 'ISO-8859-1', 'replace') > Traceback (most recent call last): > File "", line 1, in ? > TypeError: coercing to Unicode: need string or buffer, float found > >>> > > This is somehow annoying when you want to convert a mixed-type argument > list > to unicode strings, e.g. for a logging system (that's where it bit me) and > want to make sure that possible raw string arguments are also converted to > unicode without errors (although by force). > Especially as this is a performance-critical part in my application so I > really > do not like to wrap unicode() into some custom tounicode() function that > handles > such cases by distinction of argument types. > > Any reason why unicode() with a non-string argument should not allow the > encoding and errors arguments? There is reason: encoding is a property of bytes, it is not applicable to other objects. > Or some good solution to work around my problem? Do not put undecoded bytes in a mixed-type argument list. A rule of thumb working with unicode: decode as soon as possible, encode as late as possible. -- Leo From roy at panix.com Sun Dec 17 10:18:53 2006 From: roy at panix.com (Roy Smith) Date: Sun, 17 Dec 2006 10:18:53 -0500 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> lrqjl$j4s$1@newwwwwwwwwwwwwwww elrrgs$8p6$1@geeini.csx.cam.ac.... .1166111433.32001.python-list@ppppppppppp 2$a95$1@gemini............... ailman.1607.1166112864.32031.pyyhon-list@pythonnnnnn $1@gemini.csx.cccccccccc <4584E986.10502@cosc.canterbury.ac.nz> Message-ID: greg wrote: > A Python tuple is like a C struct, and a Python list is like a C array. A Python list is more like C++/STL vector than an array, but that's probably picking nits. The real problem is that while the *intent* of the Python tuple is to act like a C/C++ struct (again, the C++ flavor is a better analogy, since tuples have methods), that's a poor comparison. The struct does lookup by name, the tuple is inherently index based. Yes, I know that the struct element names are converted to offsets by the compiler, but from the programming interface point of view, they're named elements. In that respect, a Python dict is a better analogy for a C++ struct than a tuple is. Also, consider that tuples and lists are completely fungible. For any list l, list(tuple(l)) is an identity operation. The same is true of tuple(list(t)) for any tuple t. That implies that neither one contains any information that the other one doesn't. From fredrik at pythonware.com Thu Dec 21 15:35:46 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 21 Dec 2006 21:35:46 +0100 Subject: query In-Reply-To: <1166728656.830042.147690@79g2000cws.googlegroups.com> References: <1166728656.830042.147690@79g2000cws.googlegroups.com> Message-ID: libintr at gmail.com wrote: > can anyone help me on indentation in python and tell me some nice text > editors used for a beginner in python? http://effbot.org/pyfaq/tutor-whats-the-best-editor-ide-for-python From nono at hotmail.com Thu Dec 28 06:31:39 2006 From: nono at hotmail.com (Osiris) Date: Thu, 28 Dec 2006 12:31:39 +0100 Subject: Combining C and Python References: <5mt6p25dip5r59d10cu6e847r4614mv9lh@4ax.com> Message-ID: <4oa7p2td51r4dnl3vocjoui97vst80c0lq@4ax.com> On Thu, 28 Dec 2006 08:48:53 +0100, Osiris wrote: >On Wed, 27 Dec 2006 16:12:02 +0100, Osiris wrote: > >>I found this text about combining C-code with Pyton scripting on the >>P2P networks in PDF: >> >>Python Scripting for Computational Science >>Hans Petter Langtangen >>Simula Research Laboratory >>and >>Department of Informatics >>University of Oslo >> >> >>amazon and others have it in print. >>software for the text is here: >>http://folk.uio.no/hpl/scripting/ >> >>if you want to download the 1st edition from >>http://folk.uio.no/hpl/scripting/ >>the password (first word on page 92) is "leads" (no quotes) >> > >and for the second edition the password is "function" oh, and the PDF password is "foo" From kkylheku at gmail.com Mon Dec 11 21:17:34 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 11 Dec 2006 18:17:34 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165874781.930864.26750@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165857489.067258.27160@j44g2000cwa.googlegroups.com> <1165874781.930864.26750@16g2000cwy.googlegroups.com> Message-ID: <1165889854.421656.117720@l12g2000cwl.googlegroups.com> Kay Schluehr wrote: > Juan R. wrote: > > A bit ambiguous my reading. What is not feasible in general? Achieving > > compositionality? > > Given two languages L1 = (G1,T1), L2 = (G2, T2 ) where G1, G2 are > grammars and T1, T2 transformers that transform source written in L1 or > L2 into some base language > L0 = (G0, Id ). Can G1 and G2 be combined to create a new grammar G3 > s.t. the transformers T1 and T2 can be used also to transform L3 = (G3 > = G1(x)G2, T3 = T1(+)T2) ? In the general case G3 will be ambigous and > the answer is NO. But it could also be YES in many relevant cases. So > the question is whether it is necessary and sufficient to check whether > the "crossing" between G1 and G2 is feasible i.e. doesn't produce > ambiguities. See, we don't have this problem in Lisp, unless some of the transfomers in T1 have names that clash with those in T2. That problem can be avoided by placing the macros in separate packages, or by renaming. In In the absence of naming conflicts, the two macro languages L1 and L2 combine seamlessly into L3, because the transformers T are defined on structure, not on lexical grammar. The read grammar doesn't change (and is in fact irrelevant, since the whole drama is played out with objects, not text). In L1, the grammar is nested lists. In L2, the grammar is, again, nested lists. And in L3: nested lists. So that in fact, at one level, you don't even recognize them as being different languages, but on a different level you can. The problems you are grappling with are in fact created by the invention of an unsuitable encoding. You are in effect solving a puzzle that you or others created for you. From tiedon_jano at hotmail.com Mon Dec 18 15:58:35 2006 From: tiedon_jano at hotmail.com (Jussi Salmela) Date: Mon, 18 Dec 2006 20:58:35 GMT Subject: def index(self): In-Reply-To: References: Message-ID: <%hDhh.380$Mf2.170@read3.inet.fi> Gert Cuykens kirjoitti: > Is there a difference between > > > class HelloWorld: > def index(self): > index.exposed = True > return "Hello world!" > > > and > > > class HelloWorld: > def index(self): > self.exposed = True > return "Hello world!" > The resident experts seemingly being absent for a while, I'll strike: Yes: the first gives a runtime error and the second is OK. I've renamed the second class to HelloWorld2 and then: >>> hw = HelloWorld() >>> hw2 = HelloWorld2() >>> hw.index() Traceback (most recent call last): File "", line 1, in hw.index() File "C:\Python\Dive into Python\Py\apihelper.py", line 40, in index index.exposed = True NameError: global name 'index' is not defined >>> hw2.index() 'Hello world!' The error message shows that the Python compiler has interpreted the construction 'index.exposed' to refer to a global variable 'index' that doesn't exist at run time. The second class succesfully defines an instance attribute 'exposed' as can be seen by: >>> print hw2.exposed True HTH Jussi From __peter__ at web.de Sun Dec 10 03:12:16 2006 From: __peter__ at web.de (Peter Otten) Date: Sun, 10 Dec 2006 09:12:16 +0100 Subject: Newbie Question - Checkboxes References: <1165737399.895450.85620@f1g2000cwa.googlegroups.com> Message-ID: Leanne wrote: > I have been using Python for only a few months part-time and have > recently had my first encounter with retrieving user input from > checkboxes. I have a problem with the way Python reads the input > values from a set of checkboxes on a webpage. > > The values assigned to the checkboxes are integers. I first of all > check for a key of CHK_CHILDREN to see if any checkboxes have been > checked. That works fine. Checkboxes can be in Tkinter, wxPython, anything... Try to read your post from the addressees' perspective before you hit [Send]. > I then use a 'for x in CHK_CHILDREN' loop to get all the values from > the returned list. This works for most cases except one. If the user > only checks 1 checkbox, Python reads a scalar, not a list, and if this > scalar is a double digit integer (eg 11), then the loop goes through > each digit and retrieves these values, eg retrieves 1 and then > retrieves 1 again. > > I have created a not so elegant work-around that names each checkbox a > different name and therefore I know a scalar is returned each time, but > was wondering if anyone knows what's going here. Are you perchance using the cgi module? If so, the following tip from the documentation may be helpful: http://docs.python.org/dev/lib/node558.html """ If the submitted form data contains more than one field with the same name, the object retrieved by "form[key]" is not a FieldStorage or MiniFieldStorage instance but a list of such instances. Similarly, in this situation, "form.getvalue(key)" would return a list of strings. If you expect this possibility (when your HTML form contains multiple fields with the same name), use the getlist() function, which always returns a list of values (so that you do not need to special-case the single item case). For example, this code concatenates any number of username fields, separated by commas: value = form.getlist("username") usernames = ",".join(value) """ Peter From __peter__ at web.de Sat Dec 16 04:37:29 2006 From: __peter__ at web.de (Peter Otten) Date: Sat, 16 Dec 2006 10:37:29 +0100 Subject: parsing a dictionary from a string References: Message-ID: Benjamin Georgi wrote: > I could use some help extracting the keys/values of a list of > dictionaries from a string that is just the str() representation of the > list (the problem is related to some flat file format I'm using for file > IO). > > Example: > >>> s = str(dict_list) > >>> s > '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]' > > Then, what I want to do is to reconstruct dict_list given s. > Now, one possible solution would be > > >>> dict_list = eval(s) > > but since the content of s cannot be blindly trusted I`d rather not do > it that way. Basically my question is whether there is another solution > which is simpler than using regular expressions. Michael Spencer has published a simple eval() that only allows constant expressions: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 Peter From __peter__ at web.de Sat Dec 9 02:43:58 2006 From: __peter__ at web.de (Peter Otten) Date: Sat, 09 Dec 2006 08:43:58 +0100 Subject: how to remove the blank lines? References: Message-ID: boyeestudio wrote: Please keep the discourse on c.l.py/python-list. > Thanks a lot! > I have modified it,and it works well now! > but the KeyboardInterrupt on which I have a little problem. > When I type CTRL+C,it show me an I/O error. > it seems that even as I click the CTRL+C,the try block is to be invoked at > the same time! > > import os > import sys > import time > > class Tail: > def __init__(self,inputstream): > self.inputstream=inputstream > self.inputstream.seek(0,2) > > def tail(self): > line=self.inputstream.read().strip() > if not line: > return > print line This may skip whitespace in the inputstream, probably not what you want. > if __name__=="__main__": > if len(sys.argv)<=1: > print "You must type a file name" > sys.exit() > arg=file(sys.argv[1],'r+') > t=Tail(arg) As I told you, arg is always True. Change > while(arg): to while True: to make it obvious. > try: > t.tail() > time.sleep(0.75) > except KeyboardInterrupt: > print "File closing" > time.sleep(1) > arg.close() Put a break into the except clause, or you will never leave the loop in a controlled manner. Alternatively, move the try ... except out ouf the loop: try: while True: t.tail() time.sleep(0.75) except KeyboardInterrupt: pass arg.close() Peter From atkinw at rpi.edu Sat Dec 9 16:46:37 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 16:46:37 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: "mystilleef" writes: > Bill Atkins wrote: >> Are any of these not subjective? > > Objectivity is in the eye of the beholder. Well, for example, "Lisp uses a fully-parenthesized notation for writing programs" and "Python has significant whitespace" are both objective facts. Agreed? There's nothing subjective about those two facts. Do any of your points approach that level of objectivity? >> Lisp is much more than a functional language. > > Maybe so. But I've only ever appreciated its functional aspects. I > wouldn't choose Lisp or its derivatives for OO related tasks even if > I'm high. Ah yes. Glad you went into so much detail. >> Uh huh. Can you cite examples of this? Sounds like you're just >> making stuff up here. Contrary to popular belief, writing a Lisp >> macro that warps your mind and introduces a totally un-CL-like >> semantics is extremely difficult. Most of the people who are good >> enough at CL to do it (I'm certainly not one of them) are also >> experienced enough to know when it's the right choice. > > Any sizable Lisp applications will make extensive use of macros. Emacs > and magic ( the web framework) come to mind. My experience has shown > that nobody but the person who writes the DSL extension can maintain > their code. What experience is this? > The benefits of extending a language in a domain specific > manner are exaggerated. Great, it's settled then! (Look elsewhere in this thread for my post about Peter Seibel's DEFINE-BINARY-CLASS macro.) > My observation is that macros are important to > Lisp and it's derivative because they lack libraries to begin with. > Common problems solved using macros in Lisp and friends are solved > using specialized libraries in most other languages. And I like the Macros are not a substitute for libraries, nor are libraries a substitute for macros. Having macros lets you build more powerful and more expressive libraries. > specialized libraries route. Meta-programming just doesn't tickle my > fancy. It just spells maintainance nightmare. So it's not just macros but metaprogramming as a whole that bothers you? You must have an enjoyable time writing programs. >> And Lisp environments all support getting the macroexpansion, >> documentation, and source of any unfamiliar macro you might happen >> upon, so really this is not as much of a problem as you might >> fantasize it to be. > > How's this a good thing? I don't need a Python environment to grok > Python code. Nor do you need it to grok Lisp code. The environment is there to make your life better. I was merely responding to your original claim that it's impossible to make sense of code that uses macros. >> I don't agree with a lot of what you say in this paragraph, but I >> you're right that libraries are crucial. That's why I wish there were >> more people writing Lisp libraries instead of being scared away by >> sheer fabrications like the stuff that's appearing in this thread. > > People only contribute to things they understand and appreciate. More > people would be writing Lisp libraries if it was worthwhile. > Apparently, it doesn't seem to be. A few years ago, I tried to write an > editor is Scheme. The experience was appalling. I was able to write a > fully functional prototype editor in less than a week in Python. > Shockingly, at the time, I had no experience in Python. Guess which > community I was inclined to contribute to afterwards. I hear stories > similar to mine time and again, yet the Lisp community won't take heed. > They'd rather squeal about the superiority of macros and whine about > their frustrations in Python news groups. Hmm. Anecdotal evidence about Scheme (a vastly and fundamentally different language from Common Lisp). Again, you've clinched it for me. I do believe that the "squealing and whining about macros" was a response to Pythonistas claiming that macros are not useful. This was in turn in response to a foolishly (trollishly?) cross-posted question. It is not as if we have invaded your newsgroup. From jon at ffconsultancy.com Tue Dec 12 06:42:35 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 11:42:35 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165169117.866499.181520@73g2000cwn.googlegroups.com> <45732974$0$8758$ed2619ec@ptn-nntp-reader02.plus.net> <1165183970.832303.323350@73g2000cwn.googlegroups.com> <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> <1165252920.329341.284910@j44g2000cwa.googlegroups.com> <1165255758.967262.226400@73g2000cwn.googlegroups.com> <1165267711.364076.292000@79g2000cws.googlegroups.com> <457be14b$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <1165766069.028619.284860@80g2000cwy.googlegroups.com> <457d5c9c$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <7x64cir1ox.fsf@ruckus.brouhaha.com> Message-ID: <457e9647$0$8742$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: > Well, work is already under way (already mentioned) to implement > Python in Python, including a reasonable compiler (Psyco). > > The big deficiency of MLton from a concurrency perspective is > inability to use multiprocessors. Of course CPython has the same > deficiency. Same with OCaml. Is the ML community trying to do > anything about this? Yes. Several MLs support concurrency. Perhaps F# is the most notable in this case because it would provide an easier path to JIT (to .NET IL). Concurrent GC seems to be a lot slower though (e.g. Java or .NET vs OCaml or MLton). -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From ptmcg at austin.rr.com Fri Dec 22 22:59:53 2006 From: ptmcg at austin.rr.com (Paul McGuire) Date: 22 Dec 2006 19:59:53 -0800 Subject: [ANN] pyparsing 1.4.5 released Message-ID: <1166846392.920361.196990@73g2000cwn.googlegroups.com> This latest version of pyparsing has a few minor bug-fixes and enhancements, and a performance improvement of up to 100% increase in parsing speed. This release also includes some new examples: - parsePythonValue.py - parses strings representing lists, dicts, and tuples, with nesting support - sql2dot.py - SQL diagram generator, parsed from schema table definitions - htmlStripper.py - strips HTML tags from HTML pages, leaving only body text Download pyparsing 1.4.5 at http://pyparsing.sourceforge.net. The pyparsing Wiki is at http://pyparsing.wikispaces.com -- Paul ======================================== Pyparsing is a pure-Python class library for quickly developing recursive-descent parsers. Parser grammars are assembled directly in the calling Python code, using classes such as Literal, Word, OneOrMore, Optional, etc., combined with operators '+', '|', and '^' for And, MatchFirst, and Or. No separate code-generation or external files are required. Pyparsing comes with a number of parsing examples, including: - "Hello, World!" (English, Korean, and Greek) - chemical formulas - configuration file parser - web page URL extractor - 5-function arithmetic expression parser - subset of CORBA IDL - chess portable game notation - simple SQL parser - Mozilla calendar file parser - EBNF parser/compiler - Python value string parser (lists, dicts, tuples, with nesting) (new) - HTML tag stripper (new) Version 1.4.5 - December, 2006 ------------------------------ - Removed debugging print statement from QuotedString class. Sorry for not stripping this out before the 1.4.4 release! - A significant performance improvement, the first one in a while! For my Verilog parser, this version of pyparsing is about double the speed - YMMV. - Added support for pickling of ParseResults objects. (Reported by Jeff Poole, thanks Jeff!) - Fixed minor bug in makeHTMLTags that did not recognize tag attributes with embedded '-' or '_' characters. Also, added support for passing expressions to makeHTMLTags and makeXMLTags, and used this feature to define the globals anyOpenTag and anyCloseTag. - Fixed error in alphas8bit, I had omitted the y-with-umlaut character. - Added punc8bit string to complement alphas8bit - it contains all the non-alphabetic, non-blank 8-bit characters. - Added commonHTMLEntity expression, to match common HTML "ampersand" codes, such as "<", ">", "&", " ", and """. This expression also defines a results name 'entity', which can be used to extract the entity field (that is, "lt", "gt", etc.). Also added built-in parse action replaceHTMLEntity, which can be attached to commonHTMLEntity to translate "<", ">", "&", " ", and """ to "<", ">", "&", " ", and "'". - Added example, htmlStripper.py, that strips HTML tags and scripts from HTML pages. It also translates common HTML entities to their respective characters. From aine_canby at yahoo.com Thu Dec 7 07:56:03 2006 From: aine_canby at yahoo.com (aine_canby at yahoo.com) Date: 7 Dec 2006 04:56:03 -0800 Subject: Initializing with the correct type Message-ID: <1165496163.392526.322700@f1g2000cwa.googlegroups.com> Hi all, I'm new to Python and I'm just wordering if my approch is correct. Here's an example. I'm making sure that the length and types are correct. This is in case I use such a class and accidently pass it the wrong object. class Funkt: 'Funkt Class' def __init__(self, L): 'Constructer, accepts a list L of ints, which is 1 or listLength in length' if len(L) not in (1,listLength): errorString = "Format Error: L must be 1" if listLength != 1: errorString += " or "+str(listLength) errorString += " in Length" raise FormatError,errorString for i in L: if type(i) is not int: raise FormatError, "L must contain ints" class FunktError(Exception): "Exceptions base class for FUnkt class" pass class FormatError(FunktError): "Exception raised for wrong list length." def __init__(self, message): self.message = message def __str__(self): return self.message From fredrik at pythonware.com Fri Dec 15 12:53:35 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 18:53:35 +0100 Subject: Has comparison of instancemethods changed between python 2.5 and 2.4? In-Reply-To: <4582CFA3.5040305@niessink.com> References: <4582CFA3.5040305@niessink.com> Message-ID: Frank Niessink wrote: > However, the instance the two methods belong to are different, i.e. > id(callback) returns different values for the two methods. are you using the *object* as the callback? otherwise, that sentence doesn't make much sense; bound methods are generated on the fly, and the identity may or may not be reused, depending on how things are garbage collected: >>> f.bar > >>> id(f.bar) 10322248 >>> id(f.bar) 10322328 >>> id(f.bar) 10322328 >>> id(f.bar) 10322328 >>> id(f.bar), id(f.bar) (10322328, 10322328) >>> map(id, (f.bar, f.bar, f.bar)) [10322328, 10322248, 10322368] From greg at cosc.canterbury.ac.nz Mon Dec 11 05:36:31 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 11 Dec 2006 23:36:31 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> Message-ID: <4u4qoaF15uds8U2@mid.individual.net> Ken Tilton wrote: > But with Lisp one does not have to clean up the indentation manually > after thrashing away at ones code. That's not how I would describe the experience I have when I'm editing Python code. When moving a set of statements in Python, you are usually selecting a set of complete lines, cutting them out and then pasting them in between two other lines somewhere else. Having done that, the lines you've just pasted in are selected. Now it's just a matter of using using your editor's block-shifting commands to move them left or right until they're in the correct horizontal position. I find this to be quite a smooth and natural process -- no "thrashing" involved at all. Having edited both Lisp and Python code fairly extensively, I can't say that I find editing Python code to be any more difficult or error prone. On the plus side, Python makes less demands on the capabilities of the editor. All you really need is block-shifting commands. Bracket matching is handy for expressions but not vital, and you certainly don't need bracket-based auto-indenting. -- Greg From DustanGroups at gmail.com Wed Dec 13 06:52:49 2006 From: DustanGroups at gmail.com (Dustan) Date: 13 Dec 2006 03:52:49 -0800 Subject: newb: Creating Exception In-Reply-To: <1166010331.697359.46400@n67g2000cwd.googlegroups.com> References: <1165881722.928958.81490@79g2000cws.googlegroups.com> <1165954233.519919.107940@l12g2000cwl.googlegroups.com> <1166010331.697359.46400@n67g2000cwd.googlegroups.com> Message-ID: <1166010769.505973.41640@j72g2000cwa.googlegroups.com> Dustan wrote: > johnny wrote: > > Documentation is not written for newbs, it's written by guys with 6yrs > > of experience FOR guys with 6yrs of experience. > > You might want to get a book on python, rather than depend on the > documentation, which is, as you say, written for more experienced > programmers. > > http://wiki.python.org/moin/IntroductoryBooks > > I started with a book, and reading the tutorial now, am quite glad I > did. One thing that did bug me, at least briefly, is sometimes beginner > books don't explain what a line of code is actually doing - not > necessarily how it works, but as much information as is necessary to > actually be able to use the code shown. I didn't complete my thought. If you run into a situation like this, then you might want to look to the python documentation on the web for help; think of the web documentation as a reference manual rather than a tutorial, even though it does provide a tutorial. From sjmachin at lexicon.net Sat Dec 16 18:50:22 2006 From: sjmachin at lexicon.net (John Machin) Date: 16 Dec 2006 15:50:22 -0800 Subject: Is there a way to push data into Microsoft Excel & Word from Python ? In-Reply-To: <458455f2$0$8219$426a74cc@news.free.fr> References: <458455f2$0$8219$426a74cc@news.free.fr> Message-ID: <1166313022.742394.108460@80g2000cwy.googlegroups.com> The Night Blogger wrote: > Is there a way to push data to Microsoft Excel & Word from a Python > Application > > Is this a cross platform feature ? I'll need to push data on MS Windows & > Mac OS X .... Depends on what you mean by "push". If you wish to create Excel files but not update existing ones, you might consider pyExcelerator. It is pure Python and therefore will run on any platform that Python will. http://cheeseshop.python.org/pypi/pyExcelerator/ Cheers, John From k04jg02 at gmail.com Fri Dec 8 11:43:36 2006 From: k04jg02 at gmail.com (k04jg02 at gmail.com) Date: 8 Dec 2006 08:43:36 -0800 Subject: How to create a global hotkey? References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com> <1165515363.838887.109720@80g2000cwy.googlegroups.com> Message-ID: <1165596216.573871.259350@l12g2000cwl.googlegroups.com> Sorry, I should have mentioned that I'm running Linux, and I only will be running this app while X is running. pyHook doesn't seem to be an option because it's win32 only. I'm guessing python-xlib is the way to go, but it seems to be that it relies on you understanding the C xlib library, which is old and heavily obfuscated. Any advice on how to use python xlib to register a global hotkey? In the docs I found the KeyEvent event type, but it seems to want a specific window too. From tjgolden at gmail.com Sun Dec 17 05:04:26 2006 From: tjgolden at gmail.com (Tim Golden) Date: 17 Dec 2006 02:04:26 -0800 Subject: How to test if two strings point to the same file or directory? In-Reply-To: <1166317324.791635.274550@79g2000cws.googlegroups.com> References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: <1166349866.084271.277610@16g2000cwy.googlegroups.com> Sandra-24 wrote: > Comparing file system paths as strings is very brittle. Is there a > better way to test if two paths point to the same file or directory > (and that will work across platforms?) I suspect that the "and that will work across platforms" parenthesis is in effect a killer. However, if you're prepared to waive that particular requirement, I can suggest reading this page for a Win32 possibility: http://timgolden.me.uk/python/win32_how_do_i/see_if_two_files_are_the_same_file.html TJG From pete.forman at westerngeco.com Thu Dec 21 12:04:58 2006 From: pete.forman at westerngeco.com (Pete Forman) Date: Thu, 21 Dec 2006 17:04:58 +0000 Subject: Windows upgrade incomplete Message-ID: I've a few versions of Python on my XP PC, most recently Python 2.5. The file associations appear not to have been upgraded. Executing a .py file turned out to still be using 2.3. >assoc .py .py=Python.File >ftype Python.file Python.file=D:\PROGRA~1\Python23\python.exe "%1" %* Presumably if I'd uninstalled the old Python first I'd have not seen this. I've amended my file type associations and all is now well. Someone might care to look at the installer. I've used the MSIs since 2.4. -- Pete Forman -./\.- Disclaimer: This post is originated WesternGeco -./\.- by myself and does not represent pete.forman at westerngeco.com -./\.- the opinion of Schlumberger or http://petef.port5.com -./\.- WesternGeco. From irmen.NOSPAM at xs4all.nl Fri Dec 1 13:04:42 2006 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 01 Dec 2006 19:04:42 +0100 Subject: client/server design and advice In-Reply-To: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> References: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> Message-ID: <45706ec3$0$330$e4fe514c@news.xs4all.nl> TonyM wrote: > Lastly, as far as the networking goes, i have seen posts and such about > something called Pyro (http://pyro.sourceforge.net) and wondered if > that was worth looking into for the client/server interaction. I'm currently busy with a new version of Pyro (3.6) and it already includes a new 'distributed computing' example, where there is a single dispatcher service and one or more 'worker' clients. The clients request work 'packets' from the dispatcher and process them in parallel. Maybe this is a good starting point of your system? Current code is available from Pyro's CVS repository. --Irmen From rajarshi.guha at gmail.com Thu Dec 21 16:11:52 2006 From: rajarshi.guha at gmail.com (Rajarshi) Date: 21 Dec 2006 13:11:52 -0800 Subject: removing the header from a gzip'd string Message-ID: <1166735512.435837.60080@42g2000cwt.googlegroups.com> Hi, I have some code that takes a string and obtains a compressed version using zlib.compress Does anybody know how I can remove the header portion of the compressed bytes, such that I only have the compressed data remaining? (Obviously I do not intend to perform the decompression!) Thanks, From michele.petrazzoDELETE at DELETEunipex.it Fri Dec 22 07:38:16 2006 From: michele.petrazzoDELETE at DELETEunipex.it (Michele Petrazzo) Date: Fri, 22 Dec 2006 12:38:16 GMT Subject: optparser question Message-ID: I'm trying optparse and I see a strange (for me) behavior: def store_value(option, opt_str, value, parser): setattr(parser.values, option.dest, value) parser = optparse.OptionParser() parser.add_option("-f", "--foo", action="callback", callback=store_value, type="int", dest="foo") args = ["-f", "1"] (options, args) = parser.parse_args(args) print options, args {'foo': 1} [] # with the type {'foo': None} ['1'] #without it If I not specify the type in add_options, the value aren't passed to the store_value (into value variable), but it's understood as args! If I specify it, it Is this normal? Thanks, Michele From sjmachin at lexicon.net Sat Dec 16 18:36:30 2006 From: sjmachin at lexicon.net (John Machin) Date: 16 Dec 2006 15:36:30 -0800 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> <1166258893.044093.196820@79g2000cws.googlegroups.com> Message-ID: <1166312190.815541.72380@80g2000cwy.googlegroups.com> Carsten Haese wrote: > On Sat, 2006-12-16 at 20:48 +0000, John Nagle wrote: > > The SourceForge page > > > > http://sourceforge.net/project/showfiles.php?group_id=22307 > > > > says > > > > "MySQL versions 3.23-5.0; and Python versions 2.3-2.4 are supported." > > > > Last release was April, 2006. There's no binary for Python 2.5 yet. > > [...] > > So users should hold off from using Python 2.5 in production > > database applications. > > This may come as a shock to you, but MySQL is not the only database > engine on the planet. Your recommendation may apply to MySQL, but it is > not true for all databases in general. I can name at least two examples > (Informix and Oracle) of database engines that are supported under > Python 2.5, and if I were less lazy I could probably find more. Not sure if sqlite qualifies as an "engine", but it works just fine with Python 2.5. Heck, it's even supplied in the standard python.org distribution, Windows DLL and all and all ... From mee at quidquam.com Wed Dec 13 15:14:48 2006 From: mee at quidquam.com (Mike Erickson) Date: Wed, 13 Dec 2006 14:14:48 -0600 Subject: Iterating over several lists at once In-Reply-To: <45804d23$0$332$e4fe514c@news.xs4all.nl> References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> <1166021513.479174.113630@80g2000cwy.googlegroups.com> <45804d23$0$332$e4fe514c@news.xs4all.nl> Message-ID: <20061213201447.GA13302@gray.mee> * at (at at tuko.nl) wrote: > Sorry for breaking into this thread, but I agree completely that any > unnecessary indentations should be avoided. For the same reason I advocate > that the following syntax should work: > > for x in some_list if some_condition: > ... code ... > > in stead of > > for x in some_list > if some_condition: > ... code ... It is possible to avoid the extra level of indentaion, but I think it's much less readable than the 2-level verbose expresion: >>> a [1, 2, 3, 4, 5, 6, 7] >>> for odd in (num for num in a if num % 2 == 1): ... print odd ... 1 3 5 7 there is also continue, which I think is a good compromise: >>> for num in a: ... if num % 2 == 0: ... continue ... print num ... 1 3 5 7 HTH (and not lead astray), mike From pyenos at pyenos.org Fri Dec 22 20:24:56 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 12:24:56 +1100 Subject: let me simplify my question on scope of vars References: <877iwjcttj.fsf@pyenos.pyenos.org> <87vek3be9e.fsf@pyenos.pyenos.org> Message-ID: <87ejqrqu8n.fsf@pyenos.pyenos.org> Pyenos writes: > Pyenos writes: > > i will try to answer my own questions(pls verify): > > > "code" > > var=1 > > class CLASS: > > def METHOD1: > > def METHOD2: > > var+=var > > return var > > METHOD2() #line8 > > return var > > METHOD1() #line10 > > "end code" > > > > Q1: does class CLASS inherit var=0 from line1? > yes. > > Q2: does def METHOD1 inherit var=0 from line1? > no. > > Q3: does def METHOD2 inherit var=0 from line1? > no. > > Q3: does line8 return '2'? > no. will get unreferenced var error. > > Q4: does line10 return '2\n2'? > no. will get unreferenced var error. Now I know that Q1 is also no, since var=1 from line 2 is a global variable and I have not declared it as global inside def METHOD2. so var within def METHOD2 is a different variable to the global variable var. From harry.g.george at boeing.com Fri Dec 8 09:14:20 2006 From: harry.g.george at boeing.com (Harry George) Date: Fri, 8 Dec 2006 14:14:20 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> Message-ID: "Mark Tarver" writes: > Paul Rubin wrote: > > "Mark Tarver" writes: > > > How do you compare Python to Lisp? What specific advantages do you > > > think that one has over the other? > > > > > > Thanks; a quick read of your reference to Norvig's analysis > > http://norvig.com/python-lisp.html > > seems to show that Python is a cut down (no macros) version of Lisp > with a worse performance. The only substantial advantage I can see is > that GUI, and Web libraries are standard. This confirms my suspicion > that Lisp is losing out to newbies because of its > lack of standard support for the things many people want to do. > > Mark > It is not just a newbie thing. Even people who are reasonably fluent in Lisp use Python for many tasks, and some make python the default with Lisp as a special case. It would probably be fair to say that the more you know about a variety of languages, the more you appreciate Python. -- Harry George PLM Engineering Architecture From exarkun at divmod.com Wed Dec 27 10:44:06 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 27 Dec 2006 10:44:06 -0500 Subject: newbie question: any better way to write this code? In-Reply-To: <1167232702.061737.25610@42g2000cwt.googlegroups.com> Message-ID: <20061227154406.20948.1778494221.divmod.quotient.92695@ohm> On 27 Dec 2006 07:18:22 -0800, neoedmund wrote: >i want to let a byte array to be xor with some value. >but code show below i wrote seems not so .. good..., any better way to >write such function? thanks. >[code] >def xor(buf): > bout=[] > for i in range(len(buf)): > x = ord(buf[i]) > x ^= 123 > bout.append(chr(x)) > return "".join(buf) >buf = "xxxxxxxx".encode("utf8") >buf = xor(buf) > You can use numarray to do the same thing much more easily: >>> import numarray >>> buf = numarray.array('xxxxxxxx') >>> buf.tostring() 'xxxxxxxx' >>> (buf ^ 123).tostring() '\x03\x03\x03\x03\x03\x03\x03\x03' >>> In any case, you can at least drop the '.encode("utf8")'. "xxxxxxx" is already a byte string, there is no need to encode it. Jean-Paul From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Thu Dec 21 17:11:48 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Thu, 21 Dec 2006 23:11:48 +0100 Subject: removing the header from a gzip'd string References: <1166735512.435837.60080@42g2000cwt.googlegroups.com> Message-ID: <4v0f53F1afe47U1@mid.individual.net> Rajarshi wrote: > Does anybody know how I can remove the header portion of the > compressed bytes, such that I only have the compressed data > remaining? (Obviously I do not intend to perform the > decompression!) Just curious: What's your goal? :) A home made hash function? Regards, Bj?rn -- BOFH excuse #80: That's a great computer you have there; have you considered how it would work as a BSD machine? From sonibergraj at youjoy.org Mon Dec 4 14:46:12 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Mon, 04 Dec 2006 20:46:12 +0100 Subject: decorators question In-Reply-To: <457476E6.5000603@youjoy.org> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> <457476E6.5000603@youjoy.org> Message-ID: <45747B04.7080705@youjoy.org> There was a copy-and-paste error with my last message. Better try this for foobar.py: def foo(f): print "called foo" return 'some text' @foo def bar(): print "called bar" -- Soni Bergraj http://www.YouJoy.org/ From skip at pobox.com Sat Dec 30 11:41:10 2006 From: skip at pobox.com (skip at pobox.com) Date: Sat, 30 Dec 2006 10:41:10 -0600 Subject: No way to set a timeout in "urllib". In-Reply-To: References: <%hglh.1141$ji1.1051@newssvr12.news.prodigy.net> Message-ID: <17814.38566.945004.270393@montanaro.dyndns.org> John> If you're looking for a Summer of Code project, ... I'm not. I'm about 25 years out of grad school. ;-) Skip From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Sun Dec 10 06:18:06 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Sun, 10 Dec 2006 12:18:06 +0100 Subject: len() and PEP 3000 References: <4tnqlkF13bbqeU1@mid.individual.net> <5HSdh.15210$P04.6844@tornado.fastwebnet.it> <1165693115.007835.160250@j72g2000cwa.googlegroups.com> <1165729753.864860.82650@f1g2000cwa.googlegroups.com> <1165741437.119066.85600@16g2000cwy.googlegroups.com> Message-ID: <4u28neF15uiquU1@mid.individual.net> Klaas wrote: > We can think of arbitrarily-stupid ways of changing the perfectly > functional len(), but since it isn't going to change, why not drop > this topic? Don't read my mind again! ;) Regards, Bj?rn -- BOFH excuse #83: Support staff hung over, send aspirin and come back LATER. From john106henry at hotmail.com Fri Dec 15 00:35:28 2006 From: john106henry at hotmail.com (John Henry) Date: 14 Dec 2006 21:35:28 -0800 Subject: Is it good to create a thread in a non gui thread? In-Reply-To: References: Message-ID: <1166160928.082561.65290@j72g2000cwa.googlegroups.com> Yes, boogie man may show up and start munching your program. Lialie - KingMax wrote: > Hi, > I create a thread in a non gui thread, and it does well. But it seems > strange. Somebody told me better not for it may cause something hard to > imagine. > Is there any different between them? > > THX From peter at machell.net Tue Dec 26 16:57:12 2006 From: peter at machell.net (Peter Machell) Date: Wed, 27 Dec 2006 07:57:12 +1000 Subject: Splitting lines from a database query In-Reply-To: <45917f40$1@nntp0.pdx.net> References: <45910d4d$0$16553$afc38c87@news.optusnet.com.au> <459183eb$0$9775$afc38c87@news.optusnet.com.au> <45917f40$1@nntp0.pdx.net> Message-ID: <45919a3f$0$29329$afc38c87@news.optusnet.com.au> Scott David Daniels wrote: > Peter Machell wrote: >> ZeD wrote: >> >> Thanks very much ZeD. This will do what I need to. >> The next step is to do some regex on the phone number to ensure it's >> local and correct. How can I split these up so each value has a key? > > Well, you should try that, unless you intend to get the newsgroup to > write your code for you. Come back with your efforts and any problems > you have with them. As we say in Australia, fair enough. I can almost do it this way: for x in bar: fname = x[0] if fname == "": fname == "None" sname = x[1] if sname == "": sname == "None" print ""+fname+""+""+sname+"" Except that I should be using a list and loop to do the null checking, and it still stops when (I think) it hits a blank value: TypeError: cannot concatenate 'str' and 'NoneType' objects thanks, Peter. From kentilton at gmail.com Sat Dec 16 03:55:21 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 16 Dec 2006 03:55:21 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4uhl73F108ri8U1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <4uhl73F108ri8U1@mid.individual.net> Message-ID: greg wrote: > Ken Tilton wrote: > >> I did explain the last little fun bit (where reverse code miraculously >> got a case-specific "signed-value" parameter bound to exactly the >> right bit of math structure). > > > I didn't mention that because it was addressed by > another poster. The signature of the user's reverse > function can be made extremely flexible if you have > the foresight to define it as something like > > def reverse(resx, opnd, **kwds): > ... > > Then you can later change it to > > def reverse(resx, opnd, signed_value, **kwds): > ... > > and any existing reverse functions will just absorb > and ignore the extra argument. > > However, rather than add an ever-increasing number > of arguments to the signature, I think I would do it > a different way: pass a single object with attributes. > For the want of a better name, let's call it "env" > for "environment". The signature is then > > def reverse(env): > ... > > and the body can refer to env.resx, env.opnd, > env.signed_value, or whatever else is required. Looks promising. How does a generic engine that sees only a solution (a list of mathematical expressions and for each the transformations, results, and opnds logged by individual TF functions) build up this environment such that it has named attributes such as signed-value? Assume that it can examine all those opnds and results looking for tagged values such that it then knows the name of those values that have been named. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From robert.kern at gmail.com Fri Dec 1 19:23:40 2006 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 01 Dec 2006 18:23:40 -0600 Subject: How do I print a numpy array? In-Reply-To: <12n1fm121p9sv93@corp.supernews.com> References: <12n1b51i11rhv5e@corp.supernews.com> <12n1fm121p9sv93@corp.supernews.com> Message-ID: Grant Edwards wrote: > On 2006-12-01, Robert Kern wrote: >> Grant Edwards wrote: >>> How do you print a numpy array? > >> You might want to ask numpy questions on the numpy list: >> >> http://www.scipy.org/Mailing_Lists > > I tried, but it doesn't seem to be available through gmane.org. Yes, it is. http://dir.gmane.org/gmane.comp.python.numeric.general Did you have a specific problem accessing it? I can access it just fine. I think you may have to subscribe to the list to post (otherwise we get too much spam). Of course, you can turn off mail delivery if you only want to go through GMane. -- 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 From sjmachin at lexicon.net Sun Dec 17 18:58:55 2006 From: sjmachin at lexicon.net (John Machin) Date: 17 Dec 2006 15:58:55 -0800 Subject: Why there isn't a sort method for array ? In-Reply-To: References: Message-ID: <1166399935.226971.38680@n67g2000cwd.googlegroups.com> Tim Roberts wrote: > "fdu.xiaojf at gmail.com" wrote: > > > >It seems that an array acts like an list very much, except it doesn't > >have a method sort. > > What do you mean by "array"? There is no such beast in the Python > language. Do you mean the library module "array"? > Indubitably the OP means objects created by the array function in the array module. Does that help you answer his question? Cheers, John From chris.cavalaria at free.fr Thu Dec 14 06:49:54 2006 From: chris.cavalaria at free.fr (Christophe) Date: Thu, 14 Dec 2006 12:49:54 +0100 Subject: speed of python vs matlab. In-Reply-To: <1166059648.320257.187310@j72g2000cwa.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> <1166059648.320257.187310@j72g2000cwa.googlegroups.com> Message-ID: <45813a67$0$22501$426a74cc@news.free.fr> Chao a ?crit : > My Bad, the time used by python is 0.46~0.49 sec, > I tried xrange, but it doesn't make things better. > > import time > tic = time.time() > a = 1.0 > > array = range(1000) > > for i in array: > for j in array: > a = a + 0.1 > > toc = time.time() > print toc-tic,' has elapsed' Place all your code inside functions please. IIRC, local variable access is much faster that way, and you do a lot of lookup for the a local variable in that code. import time def main(): a = 1.0 array = range(1000) for i in array: for j in array: a = a + 0.1 tic = time.time() main() toc = time.time() print toc-tic,' has elapsed' From sjmachin at lexicon.net Tue Dec 26 17:59:04 2006 From: sjmachin at lexicon.net (John Machin) Date: 26 Dec 2006 14:59:04 -0800 Subject: Splitting lines from a database query In-Reply-To: <45919a3f$0$29329$afc38c87@news.optusnet.com.au> References: <45910d4d$0$16553$afc38c87@news.optusnet.com.au> <459183eb$0$9775$afc38c87@news.optusnet.com.au> <45917f40$1@nntp0.pdx.net> <45919a3f$0$29329$afc38c87@news.optusnet.com.au> Message-ID: <1167173944.175860.108790@48g2000cwx.googlegroups.com> Peter Machell wrote: > Scott David Daniels wrote: > > Peter Machell wrote: > >> ZeD wrote: > >> > >> Thanks very much ZeD. This will do what I need to. > >> The next step is to do some regex on the phone number to ensure it's > >> local and correct. How can I split these up so each value has a key? > > > > Well, you should try that, unless you intend to get the newsgroup to > > write your code for you. Come back with your efforts and any problems > > you have with them. > > As we say in Australia, fair enough. > I can almost do it this way: As we say in Australia, it's good to see that you're neither a bludger nor an utter dill/drongo/nong :-) > > for x in bar: Insert some code to show you what you've actually got: print repr(x) > fname = x[0] > if fname == "": > fname == "None" > sname = x[1] > if sname == "": > sname == "None" > > print ""+fname+""+""+sname+"" > > Except that I should be using a list and loop to do the null checking, That's *not* a null that you're checking for, mate, it's a zero-length string. > and it still stops when (I think) it hits a blank value: > TypeError: cannot concatenate 'str' and 'NoneType' objects > It's not a "blank value", it's an object None which you get as a substitute for a NULL in the database; it means "no value at all", as opposed to a zero-length string, which is a value. You can test for None by: if thing is None: You can test for both "" and None in one hit by doing this: if not thing: BTW, why do you want to fill in the missing data with the string value "None" (which could conceivably be a valid surname), instead of leaving it blank or empty? Cheers, John From Chrismdgr at aol.com Wed Dec 6 01:31:21 2006 From: Chrismdgr at aol.com (Chrismdgr at aol.com) Date: Wed, 6 Dec 2006 01:31:21 EST Subject: Adults Only! 96112 Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From JohnRoth1 at jhrothjr.com Sat Dec 30 10:34:56 2006 From: JohnRoth1 at jhrothjr.com (John Roth) Date: 30 Dec 2006 07:34:56 -0800 Subject: PEP 3107 Function Annotations for review and comment References: Message-ID: <1167492896.292605.15040@48g2000cwx.googlegroups.com> BJ?rn Lindqvist wrote: > On 12/29/06, Tony Lownds wrote: > > Rationale > > ========= > > > > Because Python's 2.x series lacks a standard way of annotating a > > function's parameters and return values (e.g., with information about > > what type a function's return value should be), a variety of tools > > and libraries have appeared to fill this gap [#tailexamp]_. Some > > utilise the decorators introduced in "PEP 318", while others parse a > > function's docstring, looking for annotations there. > > > > This PEP aims to provide a single, standard way of specifying this > > information, reducing the confusion caused by the wide variation in > > mechanism and syntax that has existed until this point. > > I think this rationale is very lacking and to weak for such a big > change to Python. I definitely like to see it expanded. > > The reference links to two small libraries implementing type checking > using decorators and doc strings. None of which to seem to be very > popular in the Python community. Surely, those two libraries *alone* > can't be enough of a motivation for this? To me, it is far from > self-evident what purpose function annotations would serve. > > I also wonder why a very obtrusive syntax addition is needed when it > clearly is possible to annotate functions in today's Python. Why is > syntax better than just adding a function annotation decorator to the > standard library? > > @annotate(a = int, b = dict, c = int) > def foo(a, b, c = 5): > ... > > Are decorators too ugly? > > -- > mvh Bj?rn The problem I have with it is that it doesn't solve the problem I've got, and I can see some user requests to use it rather than the metadata solution I've got now in Python FIT. Neither do decorators, by the way. So, what are the problems I see? First, it only handles functions/methods. Python FIT needs metadata on properties and assignable/readable attributes of all kinds. So in no sense is it a replacement. Parenthetically, neither is the decorator facility, and for exactly the same reason. Second, it has the potential to make reading the function header difficult. In the languages I'm familiar with, static type declarations are a very few, somewhat well chosen words. In this proposal, it can be a general expression. In Python FIT, that could well turn into a full blown dictionary with multiple keys. Third, it's half of a proposal. Type checking isn't the only use for metadata about functions/methods, classes, properties and other objects, and the notion that there are only going to be a small number of non-intersecting libraries out there is an abdication of responsibility to think this thing through. I should note that there are quite a few packages out there that use some form of annotation, be they comments (like Ned Bachelder's coverage analyzer and the two lint packages I'm aware of), docstrings, decorators or auxilliary dictionarys (like Python FIT, and a possible Python version of Naked Objects). They include a fair number of documentation packages. On a positive note, what I'd like is something similar to Java's Javadoc, but a bit looser. It could be a comment convention like Javadoc, but one that the compiler recognizes and stashes in the compiled .pyc / .pyo file. Or it could have different syntax. What is SHOULDN'T have is a mandatory tie to function/method syntax. Combined with a convention to identify which annotation belongs to who, it could be a quite useful mechanism. I, for one, have no difficulty with the notion of using someone else's annotations if I can identify them unambiguously. John Roth Python FIT From fredrik at dolda2000.com Sat Dec 2 22:48:22 2006 From: fredrik at dolda2000.com (Fredrik Tolf) Date: Sun, 03 Dec 2006 04:48:22 +0100 Subject: Non-exhaustive file reads Message-ID: <1165117703.12520.13.camel@pc7.dolda2000.com> I just got shocked to find out the hard way that the read() method on Python's file objects will, very much unlike the C read() function, read until the given size is reached, which is quite a problem for me when selecting a couple of pipes and wanting to just read the available data from them. The only hint I can find for avoiding this behavior is from file.read.__doc__, which says that it doesn't do that in non-blocking mode, but nowhere can I find any information about how to enable non-blocking mode in Python. Can anyone provide me with any information on how to accomplish this? Regards, Fredrik Tolf From sjmachin at lexicon.net Sun Dec 24 20:06:39 2006 From: sjmachin at lexicon.net (John Machin) Date: 24 Dec 2006 17:06:39 -0800 Subject: method names in __slots__ ?? Message-ID: <1167008799.074885.250770@73g2000cwn.googlegroups.com> I have stumbled across some class definitions which include all/most method names in a __slots__ "declaration". A cut-down and disguised example appears at the end of this posting. Never mind the __private_variables and the getter/setter approach, look at the list of methods in the __slots__. I note that all methods in an instance of a slotted class are read-only irrespective of whether their names are included in __slots__ or not: Given a = Adder(), a.tally = 0 gets AttributeError: 'Adder' object attribute 'tally' is read-only a.notinslots = 1 gets AttributeError: 'Adder' object attribute 'notinslots' is read-only So is there some magic class-fu going down here, or is this just a waste of memory space in the instances? === example === # class with method names in __slots__ class Adder(object): __slots__ = [ # methods '__init_', 'get_foo', 'get_value', 'set_foo', 'tally', # private variables '__foo', '__value', # public variables 'bar', 'zot', ] def __init__(self, start=0): self.__value = start self.__foo = 666 self.bar = None self.zot = 42 def tally(self, amount): self.__value += amount def get_value(self): return self.__value def set_foo(self, arg): self.__foo = arg def get_foo(self): return self.__foo def notinslots(self): pass === end of example === From st911 at rock.com Fri Dec 1 14:21:39 2006 From: st911 at rock.com (st911 at rock.com) Date: 1 Dec 2006 11:21:39 -0800 Subject: Take the $million challenge: Prove 911 conspriracy theorists are wrong Message-ID: <1165000252.255347.178950@73g2000cwn.googlegroups.com> I found this nice dialog on the internet: ===================================== > Well, if you want to convice me, just answer these questions: If you can prove that the official explanation is correct, what's keeping you from collecting a MILLION dollars? Even if you're too wealthy to bother, you could donate the proceeds to the Aryan Nation or the John Birch Society. > 1. How much explosives were used and what type? Thermate/thermite have been discovered in chemical tests, and evidence of its use is plainly visible in photographic an video evidence from the WTC buildings on 9/11. Thermate does not cause millions of tones of concrete to become pulverized into dust in mid-air (as video evidence clearly shows), so another high-energy explosive must have also been used. Now that we have positive proof that explosives were used, and once the secondary compounds have been discovered, the quantities and placement can be estimated from examinations of the video and photo evidence. > 2. How many people were needed to prepare the building for demolition? Irrelevant to the established fact that explosives were used. Will be determined in the new investigation. BTW: It's "buildings," not "building." Did you realize that *three* WTC towers collapsed on 9/11/01, despite only 2 buildings being hit by jets? Most Americans don't realize this obvious fact. Why? > 3. How long did it take to prepare the buildings for demolition? Irrelevant to the established fact that explosives were used. Once the identities of the conspirators are discovered in a new investigation, the timeline can be established. (That's what investigators do.) > 4. How many people had to be bribed and how much were they bribed to > keep silent about the preparations? Irrelevant to the established fact that explosives were used. Those conspirators (whether bribed or not) that are still alive must be discovered and convicted for their crimes, which may include conspiracy to commit treason. The only way to bring the criminals to justice is to open a new investigation which will examine *all* relevant evidence, including sequestered videos, audio tapes, and classified documents. Everybody with an IQ above room temperature knows that the 9/11 Commission report was a whitewash, which didn't even attempt to lay blame at the feet of military and civilian officials who were asleep at the wheel on 9/11/01. It proves that Bush is not serious about national security. From adelcoGENE at zeverSKYNET.BE Sat Dec 30 16:15:14 2006 From: adelcoGENE at zeverSKYNET.BE (karel) Date: Sat, 30 Dec 2006 21:15:14 -0000 Subject: find login name of user? References: <1167511677.250618.285250@v33g2000cwv.googlegroups.com> <4596d16b$0$21512$ba620e4c@news.skynet.be> <1167512414.065895.280560@s34g2000cwa.googlegroups.com> Message-ID: <4596d6e5$0$6476$ba620e4c@news.skynet.be> wrote in message news:1167512414.065895.280560 at s34g2000cwa.googlegroups.com... > > karel wrote: >> wrote in message >> news:1167511677.250618.285250 at v33g2000cwv.googlegroups.com... >> > Is there a function/module to find the login name of the user under >> > UNIX environment? >> >> who >> who am i >> finger >> id > > I was talking about under python environment. Ah! Thanks for enlightening me. Apologies for misunderstanding. From shandy.b at gmail.com Wed Dec 13 14:10:38 2006 From: shandy.b at gmail.com (shandy.b at gmail.com) Date: 13 Dec 2006 11:10:38 -0800 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> Message-ID: <1166037038.450004.223290@80g2000cwy.googlegroups.com> The proposed solution impairs readability because there's a "surprise" at the end. List comprehensions already open the language up to readability abuse. Lets not add more. To avoid the unwanted indentation, I would go with the already suggested "if not x>0: continue" solution or else something like this: positiveMembers = [x for x in [-2, -1, 0, 1, 2, 3, 4] if x>0] for x in positiveMembers: #do stuff This has the advantage of being more self-documenting. at wrote: > I would like to spark the discussion about the following syntax problem I > encounter. > > THE PROBLEM > > I have a lot times the following code: > > for x in [-2, -1, 0, 1, 2, 3, 4]: > if x > 0: > ... more code... > > > It is not the addional line containing 'if x > 0:' that bothers me, but the > additional indentation. > > > THE SOLUTION > > More pythonic in view would be: > > for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0: > ... more code ... > > > This blends basically > > [x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0] > > and > > x = y if x > 0 else 10 > > > EXTENDING > > And maybe a few usefull variants, like: > > for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0 else -x: > ... more code ... > > In this case x will be 2, 1, 0, 1, 2, 3, 4. From vbgunz at gmail.com Sat Dec 2 16:27:50 2006 From: vbgunz at gmail.com (vbgunz) Date: 2 Dec 2006 13:27:50 -0800 Subject: Python, PostgreSQL, What next? References: <1165043076.979652.201730@16g2000cwy.googlegroups.com> Message-ID: <1165094870.604497.156200@73g2000cwn.googlegroups.com> I need to thank you all for your suggestions and recommendations. I am ultimately aiming to work in Python, PostgreSQL and Django and this link http://www.sqlalchemy.org/news.myt#item_3 sort of made my day :) I really appreciate all of your feedback and will go through Fredrik's links as soon as I get the chance. I thank you all again, I appreciate it very much! From kentilton at gmail.com Thu Dec 14 11:49:02 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 11:49:02 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7xpsankoc6.fsf@ruckus.brouhaha.com> <7xpsangcs8.fsf@ruckus.brouhaha.com> <7N7gh.574$n34.527@newsfe09.lga> Message-ID: <2gfgh.20$kH1.17@newsfe11.lga> Robert Uhl wrote: > Ken Tilton writes: > >>meanwhile, I have not seen how Python lets you avoid revisiting dozens >>of instances when changes to a mechanism are required. > > > I think his solution would have been to use: > > def foo(**args): > > everywhere, and call it like this > > foo(bar=baz) > > Of course that makes calls pretty verbose, but it would prevent having > to visit every function/method every time the signature changes. As > long they'd all been set up initially to use keyword args like that. > And of course one would lose some of the compile-time benefits of > compiler signature checking. > > It's not optimal, but I think it'd get the job done. > Cue Steve and his Turing Equivalence rant. And as the mechanism has elaborated, neato things like signature flexibility were not enough to keep Python in the game. Or at least people stop offering Python equivalents, at which point we could have contrasted and compared. Python /does/ have a lot of reflection and meta-capability, as I know from an abortive attempt to port Cells there. So perhaps something was possible. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From duncan.booth at invalid.invalid Wed Dec 13 16:56:15 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 13 Dec 2006 21:56:15 GMT Subject: Defining classes References: Message-ID: nmm1 at cus.cam.ac.uk (Nick Maclaren) wrote: > > I am defining a class, and I need to refer to that class when > setting up its static data - don't ask - like this: > > Class weeble : > wumpus = brinjal(weeble) You cannot refer to weeble until it has been created which isn't until after all of the statements in the class body have executed. The usual way to achieve what you want is to assign the static member from outside the class. class weeble: pass weeble.wumpus = brinjal(weeble) Alternatively you can play tricks with metaclasses for a similar effect. From gagsl-py at yahoo.com.ar Thu Dec 7 03:15:44 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 05:15:44 -0300 Subject: Need Help Parsing From File In-Reply-To: <1165470696.899710.119250@16g2000cwy.googlegroups.com> References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061207045039.03d89868@yahoo.com.ar> At Thursday 7/12/2006 02:51, John Machin wrote: >Gabriel Genellina wrote: > > > > ftxt=open(filename,"rt") > >Never seen that done before. It's not in the docs. A remnant of my MSDOS+C background... >FWIW: > >Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >(Intel)] on win >32 >Type "help", "copyright", "credits" or "license" for more information. > >>> f = open('foo.txt', 'rt') > >>> f = open('foo.txt', 'rs') > >>> f = open('foo.txt', 'ratsdroppings') ># Nary an exception raised, not the slightest murmur > >Is this a bug or a feature? Or is it one of those good old "unspecified >behaviour" cases? MSVC rtl only? The Python docs say only that the initial letter is checked. And the ANSI 89 C says that other characters may follow after r, r+, etc. "rt" is useless for an ANSI C compiler, since the default stream mode is "text" -on systems which differentiate between text and binary- and irrelevant on systems which don't do such distinction. (And since I got used to write "rt", you can infer something about *when* I began to write C programs...) -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From uss.japan at gmail.com Sun Dec 24 05:20:15 2006 From: uss.japan at gmail.com (Belize) Date: 24 Dec 2006 02:20:15 -0800 Subject: split string with hieroglyphs In-Reply-To: References: <1166930928.663980.247610@73g2000cwn.googlegroups.com> Message-ID: <1166955615.615157.193170@48g2000cwx.googlegroups.com> Steven, thanks! Very nice algorithm. Here is code: #!/usr/bin/env python # -*- coding: utf_8 -*- # Thanks Steven D'Aprano for hints import unicodedata import MySQLdb #MySQL variables mysql_host = "localhost" mysql_user = "dict" mysql_password = "passwd" mysql_db = "dictionary" try: mysql_conn = MySQLdb.connect(mysql_host, mysql_user, mysql_password, mysql_db) cur = mysql_conn.cursor() cur.execute("""SET NAMES UTF8""") except: print "unable insert to MySQL, check connection" jap_text = "BZ???TV??DVD?" jap_text = unicode(jap_text, 'utf-8') # fight with full-width, half-width katakana madness :-) jap_text = unicodedata.normalize('NFKC', jap_text) # jap_text = jap_text.encode('utf-8') # def translate_hieroglyph(jap_text): eng_text = "" mysql_translate_query = "SELECT Eng FROM dictionary where Jis='%s' collate utf8_unicode_ci LIMIT 1" % jap_text cur.execute(mysql_translate_query) mysql_trans_data = cur.fetchall() for line in mysql_trans_data: eng_text = line[0] if not eng_text: eng_text = jap_text return eng_text def islatin(s): try: unicode(s, 'ascii') except UnicodeError: pass else: return True def split_fragments(s): fragments = [] latin = [] nonlatin = [] for c in s: if islatin(c): if nonlatin: fragments.append(''.join(nonlatin)) nonlatin = [] latin.append(c) else: if latin: fragments.append(''.join(latin)) latin = [] nonlatin.append(c) if latin: # without this we lose last fragment fragments.append(''.join(latin)) # else: # fragments.append(''.join(nonlatin)) # return fragments fragments = split_fragments(jap_text) def join_fragments(fragments): accumulator = [] for fragment in fragments: if islatin(fragment): accumulator.append(fragment) else: accumulator.append(translate_hieroglyph(fragment)) return ' '.join(accumulator) print join_fragments(fragments) home at my ~/Src/Code $ python translate.py BZ navigation TV display DVD? Work as needed :-) Thanks again! From gagsl-py at yahoo.com.ar Sat Dec 16 22:20:08 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 16 Dec 2006 19:20:08 -0800 Subject: Is there a way to push data into Microsoft Oulook from Python ? In-Reply-To: <45845738$0$8082$426a74cc@news.free.fr> References: <45845738$0$8082$426a74cc@news.free.fr> Message-ID: <1166325608.796801.255400@16g2000cwy.googlegroups.com> On 16 dic, 17:39, "The Night Blogger" wrote: > Is there a way to pull & push data (Tasks, Notes, Calendar Items ...) into > Microsoft Oulook from Python ? You will need the pywin32 package. Then you get the Outlook Application object using: import win32com.client Outlook = win32com.client.Dispatch("Outlook.Application") Now, you have to know the methods and properties of that object. Look for the Outlook object model in MSDN. Usually it's easier with google: http://www.google.com/search?q=outlook+application+site:msdn.microsoft.com Googling with "outlook application python" will give you more help. -- Gabriel Genellina From duncan.booth at invalid.invalid Tue Dec 19 04:08:59 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Dec 2006 09:08:59 GMT Subject: urllib.unquote and unicode References: <1166497058.109088.53120@80g2000cwy.googlegroups.com> <1166504578.169707.154900@n67g2000cwd.googlegroups.com> Message-ID: "Leo Kislov" wrote: > George Sakkis wrote: >> The following snippet results in different outcome for (at least) the >> last three major releases: >> >> >>> import urllib >> >>> urllib.unquote(u'%94') >> >> # Python 2.3.4 >> u'%94' >> >> # Python 2.4.2 >> UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position >> 0: ordinal not in range(128) >> >> # Python 2.5 >> u'\x94' >> >> Is the current version the "right" one or is this function supposed >> to change every other week ? > > IMHO, none of the results is right. Either unicode string should be > rejected by raising ValueError or it should be encoded with ascii > encoding and result should be the same as > urllib.unquote(u'%94'.encode('ascii')) that is '\x94'. You can > consider current behaviour as undefined just like if you pass a random > object into some function you can get different outcome in different > python versions. I agree with you that none of the results is right, but not that the behaviour should be undefined. The way that uri encoding is supposed to work is that first the input string in unicode is encoded to UTF-8 and then each byte which is not in the permitted range for characters is encoded as % followed by two hex characters. That means that the string u'\x94' should be encoded as %c2%94. The string %94 should generate a unicode decode error, but it should be the utf-8 codec raising the error not the ascii codec. Unfortunately RFC3986 isn't entirely clear-cut on this issue: > When a new URI scheme defines a component that represents textual > data consisting of characters from the Universal Character Set [UCS], > the data should first be encoded as octets according to the UTF-8 > character encoding [STD63]; then only those octets that do not > correspond to characters in the unreserved set should be percent- > encoded. For example, the character A would be represented as "A", > the character LATIN CAPITAL LETTER A WITH GRAVE would be represented > as "%C3%80", and the character KATAKANA LETTER A would be represented > as "%E3%82%A2". I think it leaves open the possibility that existing URI schemes which do not support unicode characters can use other encodings, but given that the original posting started by decoding a unicode string I think that utf-8 should definitely be assumed in this case. Also, urllib.quote() should encode into utf-8 instead of throwing KeyError for a unicode string. From filipwasilewski at gmail.com Mon Dec 4 09:18:15 2006 From: filipwasilewski at gmail.com (Filip Wasilewski) Date: 4 Dec 2006 06:18:15 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165241895.291617.143380@80g2000cwy.googlegroups.com> Jon Harrop wrote: [...] > I first wrote an OCaml translation of the Python and wrote my own > little "slice" implementation. I have since looked up a C++ solution and > translated that into OCaml instead: > > let rec d4_aux a n = > let n2 = n lsr 1 in > let tmp = Array.make n 0. in > for i=0 to n2-2 do > tmp.(i) <- a.(i*2)*.h0+.a.(i*2+1)*.h1+.a.(i*2+2)*.h2+.a.(i*2+3)*.h3; > tmp.(i+n2) <- a.(i*2)*.g0+.a.(i*2+1)*.g1+.a.(i*2+2)*.g2+.a.(i*2+3)*.g3; > done; > tmp.(n2-1) <- a.(n-2)*.h0 +. a.(n-1)*.h1 +. a.(0)*.h2 +. a.(1)*.h3; > tmp.(2*n2-1) <- a.(n-2)*.g0 +. a.(n-1)*.g1 +. a.(0)*.g2 +. a.(1)*.g3; > Array.blit tmp 0 a 0 n; > if n > 4 then d4_aux a (n lsr 1) > > let d4 a = d4_aux a (Array.length a) > > Not only is that shorter than the Python and makes my eyes bleeding, but it's only my personal feeling. Try reading the code above aloud and you will see why `shorter` is not necessarily considered a merit, especially on this group. Besides of that this code is irrelevant to the original one and your further conclusions may not be perfectly correct. Please learn first about the topic of your benchmark and different variants of wavelet transform, namely difference between lifting scheme and dwt, and try posting some relevant examples or use other topic for your benchmarks. Neglecting this issues, I wonder if it is equally easy to juggle arbitrary multidimensional arrays in a statically typed language and do operations on selected axis directly from the interactive interpreter like in the NumPy example from my other post - http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 ? I don't know much OCaml so it would be great if you could elaborate on this. > , it is much faster: > > 0.56s C++ (direct arrays) > 0.61s F# (direct arrays) > 0.62s OCaml (direct arrays) > 1.38s OCaml (slices) > 2.38s Python (slices) > 10s Mathematica 5.1 > > Note that all implementations are safe (e.g. C++ uses a.at(i) instead of > a[i]). [...] So why not use C++ instead of all others if the speed really matters? What is your point here? Could you please share full benchmark code, so we could make conclusions too? I would like to get to know about your benchmark methodology. I wonder if you are allocating the input data really dynamically or whether it's size is a priori knowledge for the compiler. > In this specific context (discrete wavelet transform benchmark), I'd have > said that speed was the most important thing after correctness. In this very specific context: Yes, if you are targeting specific one-shot issue like JPEG2000 encoder, where you are using only 2 types of wavelets. In that case you would probably draw back to low-level C or C++ and use a good optimizing compiler for a specific hardware. Not necessarily, if you are doing research with different kinds of wavelets and need a general, flexible and easily adaptable tool or just the computation speed is not considered a bottleneck. Language speed is a great advantage, but if it always was the most important, people would talk directly to the CPUs or knit DSP chips in theirs backyards whenever they need to solve a calculation problem. Please don't make this discussion heading towards `what is the fastest way of doing d4 transform and why OCaml rules` instead of `what is the optimal way of doing things under given circumstances and still have a free afternoon ;-)`. Different tasks need different, well-balanced measures. Neither Python nor OCalm nor any other language is a panacea for every single problem. cheers, fw From kkylheku at gmail.com Sat Dec 9 00:43:43 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 8 Dec 2006 21:43:43 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7x64cl90xx.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> Message-ID: <1165643023.729419.239470@j72g2000cwa.googlegroups.com> Paul Rubin wrote: > Lisp just seems hopelessly old-fashioned to me these days. A > modernized version would be cool, but I think the more serious > Lisp-like language designers have moved on to newer ideas. What are some of their names, and what ideas are they working on? Also, who are the less serious designers? From andrew at farwestbilliards.com Fri Dec 15 22:43:20 2006 From: andrew at farwestbilliards.com (Andrew Sackville-West) Date: Fri, 15 Dec 2006 19:43:20 -0800 Subject: automatically grading small programming assignments In-Reply-To: References: <4581896B.2020504@bryant.edu> Message-ID: <20061216034320.GD17867@localhost.localdomain> On Fri, Dec 15, 2006 at 06:44:37AM +0000, Dennis Lee Bieber wrote: > On Thu, 14 Dec 2006 12:27:07 -0500, Brian Blais > declaimed the following in gmane.comp.python.general: > > > > I envision a number of possible solutions. In one solution, I provide a function > > template with a docstring, and they have to fill it in to past a doctest. Is there a > > good (and safe) way to do that online? Something like having a student post code, > > and the doctest returns. I'd love to allow them to submit until they get it, logging > > each attempt. > > > I have some problems with the concept behind the last sentence... It > encourages brute-force trial&error coding (unless you are going to tell > them that each submittal gets logged, AND that multiple submittals will > reduce the final score they get for the assignment). its been decades since I was in a programming course... salt accordingly. Whenever I learn a new language, I spend a LOT of time just hacking stuff and seeing what it does -- learning syntax and effects by trial and error. Since I already know (okay, knew) good coding practice, the resulting code would not look like it had been hacked together in such a manner, but if I was graded on how many times I executed a bit of code, I'd fail right out. Now, maybe in the second or third semester of a particular language, that might make sense -- the student should already understand syntax and effects well enough to avoid that stuff. .02 from a python newb. A -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From eric.pederson at gmail.com Sat Dec 9 17:10:59 2006 From: eric.pederson at gmail.com (Eric Pederson) Date: 9 Dec 2006 14:10:59 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <5ojeh.41$_t3.21@newsfe12.lga> Message-ID: <1165702259.805790.297180@j72g2000cwa.googlegroups.com> > > "No programmer who learned Lisp ever gave up before he learned Lisp."That would be the obvious retort, but my observation was empirical, so I > am afraid you need numbers, not word games. > > You seem awfully hostile, by the way. Won't that make it harder to > conduct an intelligent exchange of value to lurkers? > > > I wonder, how many people gave up trying to learn Lisp because the > > language was too hard for them to read? Anyone like to bet that the number > > was more than zero?Sorry, no one ever discovered Lisp, decided it would be great for > programming, started learning it and then gave up because they could not > handle the syntax. Uh. Clearly no one would be dumb enough to admit it in front of the entire usenet world, right? - Mr. NoOne P.S. I am still going to get back to it when I get some time, really. LISP seems intriguing and superior, almost a magical Rubik's cube waiting for me. I just stumbled across Python in the meantime and code started flowing - I got distracted. I have CL (& Scheme) on all my machines awaiting my focus.... I'll join the flock any day now. :-) I've just been busy. There is a cost to learning and I've not had the spare change to date. But New Years resolutions need to be made: I could get up a couple hours early and spend some quality time with CL, do a daily hour jog, and eat a really heathly breakfast. Writing myself a note on this. P.P.S. Undoubtedly not learning a syntax either means not enough time was put in or the student lacked proper intelligence. This will always bias the significance of learning syntax as a factor in choice of language to be under reported. cheers From exarkun at divmod.com Thu Dec 21 17:59:50 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Thu, 21 Dec 2006 17:59:50 -0500 Subject: Why can't you use varargs and keyword arguments together? In-Reply-To: <1166741475.082694.223630@a3g2000cwd.googlegroups.com> Message-ID: <20061221225950.20948.490493558.divmod.quotient.85894@ohm> On 21 Dec 2006 14:51:15 -0800, Sandra-24 wrote: >I've always wondered why I can't do: > >def foo(a,b,c): > return a,b,c > >args = range(2) >foo(*args, c = 2) > >When you can do: > >foo(*args, **{'c':2}) You just need to turn things around: >>> def foo(a, b, c): ... return a, b, c ... >>> args = range(2) >>> foo(c=2, *args) (0, 1, 2) >>> Jean-Paul From fredrik at pythonware.com Fri Dec 8 01:13:53 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 08 Dec 2006 07:13:53 +0100 Subject: raw strings in regexps In-Reply-To: References: Message-ID: Mike wrote: > I've been having trouble with a regular expression, and I finally simplified > things down to the point that (a) my example is very simple, and (b) I'm > totally confused. There are those who would say (b) is normal, but that's > another thread. > > I finally simplified my problem down to this simple case: > > re.match(r'\\this', r'\\this') > > Both the pattern and the string to match are identical raw strings, yet they > don't match. the regular expression engine matches a pattern against a string, not a string against a string. in a pattern, "\\" matches a single backslash. in your raw string, you have *two* backslashes. try this instead: re.match(r'\\this', '\\this') From gregm-xyzpdq3 at toadmail.com Mon Dec 11 20:26:35 2006 From: gregm-xyzpdq3 at toadmail.com (Greg Menke) Date: 11 Dec 2006 20:26:35 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> <7xwt4y6j57.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Andr? Thieme writes: > > > import module > > > module.function = memoize(module.function) > > > > Yes, I mentioned that a bit earlier in this thread (not about the > > "during runtime" thing). > > I also said that many macros only save some small bits of code. > > Your python example contains 4 tokens / brain units. > > The Lisp version only has 2. > > You shouldn't count the import statement, since you'd need the > equivalent in Lisp as well. > > Contrast the much more common > > a[i] = b[n] > > with > > (setf (aref a i) (aref b n)) > > and the attractions of Python may make more sense. Not really. The syntax of getting and setting array elements isn't really the point. It ignores the cognitive efficiency of Lisp when things get more complex, and likewise whatever similar characteristics that Python offers. I don't mean to imply Python is inefficient, just that array manipulation syntax isn't where the two languages' strengths & weaknesses appear. To compare the languages when things get complicated, in effect, to see how they help and how they hurt when problems are difficult, then a more complex example is necessary. Since the arguments so far seem dominated by syntactical trivia, they seem to me more about perceived aesthetics and personal preference than anything else. I spent a year or so using Python as a scripting language for relatively simple applications where shell scripts were insufficient. It works fine as such. But it began to suck performance-wise when I started trying to manipulate more complex datasets and I began wanting compilation to get throughput up. Common Lisp, being a highly mature language (and thus sometimes ossified in appearance), offered a standardized language with a variety of implementations, some of which gave me the compiler tools I needed without forcing me to retool concepts and source code from the freebie implementations I started with. This is a very important point once there is considerable conceptual investment in a suite of source. When the New & Cool arguments are presented, this issue seems neglected. There are many tradeoffs to be made between New & Cool and Highly Matured, syntax being only one. Gregm From puttaramakrishna at gmail.com Fri Dec 15 04:18:14 2006 From: puttaramakrishna at gmail.com (puttaramakrishna at gmail.com) Date: 15 Dec 2006 01:18:14 -0800 Subject: connect from windows to linux using ssh Message-ID: <1166174294.248266.68040@79g2000cws.googlegroups.com> Hi Folks, How to connect from windows to linux using ssh without username/passwd. With this scenario, i need to write a program on python. Regards, Ramakrishna. From chandrasekar.kanagaraj at gmail.com Wed Dec 13 06:02:27 2006 From: chandrasekar.kanagaraj at gmail.com (chandrasekar.kanagaraj at gmail.com) Date: 13 Dec 2006 03:02:27 -0800 Subject: YouTube written in Python References: <457f58e5$0$27424$4d3efbfe@news.sover.net> Message-ID: <1166007747.777721.153650@73g2000cwn.googlegroups.com> Leif K-Brooks wrote: > Terry Reedy wrote: > > In a thread on the PyDev list, Guido van Rossum today wrote: > >> And I just found out (after everyone else probably :-) that YouTube is > >> almost entirely written in Python. (And now I can rub shoulders with > >> the developers since they're all Googlers now... :-) > > Interesting. I wonder what they're using for a Web framework? Of course, > sites that size generally use lots of custom stuff, but it would > presumably be based on something. awesome.Could you give the link where guido told this -Chandru From jeffrey.aylesworth at gmail.com Fri Dec 8 17:08:02 2006 From: jeffrey.aylesworth at gmail.com (jeff) Date: 8 Dec 2006 14:08:02 -0800 Subject: reading id3 tags with python In-Reply-To: <1164618762.975659.241520@j72g2000cwa.googlegroups.com> References: <1164328566.089711.89870@l12g2000cwl.googlegroups.com> <1164354948.000349.52170@m7g2000cwm.googlegroups.com> <1164386522.229372.116120@l12g2000cwl.googlegroups.com> <1164618762.975659.241520@j72g2000cwa.googlegroups.com> Message-ID: <1165615682.247690.211520@l12g2000cwl.googlegroups.com> ok, i see..nut its just for myself--im not planning on redistributing it, and most people dont have folders that end with '.mp3' in their music folder > It's just a friendly warning that you shouldn't suppose that all that > is scanned are indeed files, and not directories. From avassalotti at gmail.com Tue Dec 12 09:58:41 2006 From: avassalotti at gmail.com (Alexandre Vassalotti) Date: Tue, 12 Dec 2006 09:58:41 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> Message-ID: "There are only two kinds of languages: the ones people complain about and the ones nobody uses" -- Bjarne Stroustrup http://www.googlefight.com/index.php?word1=%22Python+sucks%22&word2=%22Ruby+sucks%22 According to the rule, Python is more popular. On the other side, Java squashes us. (http://www.googlefight.com/index.php?word1=%22Python+sucks%22&word2=%22Java+sucks%22) And by the way, I think we need alt.religion.lisp. On 12/11/06, Ken Tilton wrote: > You missed it? Google fight: > > http://www.googlefight.com/index.php?lang=en_GB&word1=Python&word2=Ruby > > Python wins, 74 to 69.3. And there is no Monty Ruby to help. -- Alexandre Vassalotti From michax at gmail.com Sat Dec 9 10:40:00 2006 From: michax at gmail.com (Michax) Date: 9 Dec 2006 07:40:00 -0800 Subject: py2exe Problem with cairo Message-ID: <1165678800.276619.236140@n67g2000cwd.googlegroups.com> Hi, I have problem with my py2exe. When I want to run my compiled exe, then i get error information like that: Trackback (most recent call last): File "mysql_gui.py", line 2 in ? File "gtk\__int__.pyc", line 12, in ? File "gtk\_gtk.pyc", line 12, in ? File "gtk\_gtk.pyc", line 10, in __load ImportError: No module named cairo I have similar problem with all compiled .exe using gtk library. I want to add, that when I launch *.py file directly , everything works great. Detailed information : System : Windows 2003 with SP1 Python 2.4.4 gtk-2.10.6-win32-1 gtk-dev-2.10.6-win32-1 py2exe-0.6.5.win32.py.2.4 pycairo-1.0.2-1.win32.py.2.4 pygtk-2.8.6-1.win32-py2.4 MySQL-python.exe-1.2.1_p2.win32-py2.4 And most important thing , I'm newbie :) My source code http://www.moha.pl/mysql_gui.py Thanks in advance for any suggestion -- Micha? Kuli?ski Poland From tim at bytesmith.us Fri Dec 29 10:51:30 2006 From: tim at bytesmith.us (Tim Smith) Date: Fri, 29 Dec 2006 10:51:30 -0500 Subject: Can I beat perl at grep-like processing speed? In-Reply-To: References: Message-ID: <1167407490@www.bytesmith.us> you may not be able to beat perl's regex speed, but you can take some steps to speed up your python program using map and filter here's a modified python program that will do your search faster #!/usr/bin/env python import re r = re.compile(r'destroy', re.IGNORECASE) def stripit(x): return x.rstrip("\r\n") print "\n".join( map(stripit, filter(r.search, file('bigfile'))) ) #time comparison on my machine real 0m0.218s user 0m0.210s sys 0m0.010s real 0m0.464s user 0m0.450s sys 0m0.010s #original time comparison on my machine real 0m0.224s user 0m0.220s sys 0m0.010s real 0m0.508s user 0m0.510s sys 0m0.000s also, if you replace the regex with a test like lambda x: x.lower().find("destroy") != -1, you will get really close to the speed of perl's (its possible perl will even take this shortcut when getting such a simple regex #here's the times when doing the search this way real 0m0.221s user 0m0.210s sys 0m0.010s real 0m0.277s user 0m0.280s sys 0m0.000s -- Tim -- On 12/29/06 "js " wrote: > Just my curiosity. > Can python beats perl at speed of grep-like processing? > > $ wget http://www.gutenberg.org/files/7999/7999-h.zip > $ unzip 7999-h.zip > $ cd 7999-h > $ cat *.htm > bigfile > $ du -h bigfile > du -h bigfile > 8.2M bigfile > > ---------- grep.pl ---------- > #!/usr/local/bin/perl > open(F, 'bigfile') or die; > > while() { > s/[\n\r]+$//; > print "$_\n" if m/destroy/oi; > } > ---------- END ---------- > ---------- grep.py ---------- > #!/usr/bin/env python > import re > r = re.compile(r'destroy', re.IGNORECASE) > > for s in file('bigfile'): > if r.search(s): print s.rstrip("\r\n") > ---------- END ---------- > > $ time perl grep.pl > pl.out; time python grep.py > py.out > real 0m0.168s > user 0m0.149s > sys 0m0.015s > > real 0m0.450s > user 0m0.374s > sys 0m0.068s > # I used python2.5 and perl 5.8.6 > -- > http://mail.python.org/mailman/listinfo/python-list From gagsl-py at yahoo.com.ar Wed Dec 6 21:40:37 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 06 Dec 2006 23:40:37 -0300 Subject: PyRun_SimpleString no sys.argv[0] In-Reply-To: <1165418630.840841.136290@n67g2000cwd.googlegroups.com> References: <1165418630.840841.136290@n67g2000cwd.googlegroups.com> Message-ID: <7.0.1.0.0.20061206231609.04cc8c98@yahoo.com.ar> At Wednesday 6/12/2006 12:23, iwl wrote: >I'm just starting with Python - would like to embed it in my >windows-programm as an script-processor. For tests I use easygui some >easy-wrapper for the py-tck-stuff. Looks a bit strange for me. If the GUI will be in Python, I think you could do things the other way, *extending* your main Python program with your own C code, not *embedding* Python inside your main C program. I'm not sure if Tk can run without a mainloop. Anyway, to answer your actual question: >Traceback (most recent call last): > File "", line 1, in > File "easygui.py", line 148, in msgbox > reply = buttonbox(message, title, choices) > File "easygui.py", line 170, in buttonbox > root = Tk() > File "C:\Python\Python25\Lib\lib-tk\Tkinter.py", line 1631, in >__init__ > baseName = os.path.basename(sys.argv[0]) >AttributeError: 'module' object has no attribute 'argv' > >May bee makes some sence that the embedded Interpreter has no argv[0], >however tk seems not to bee ready for that. >I try to define some sys.argv[0] myself after I get out how to do that, >maybee someone other has an better idea until than. From the Python/C API Reference Manual, section "Embedding Python" (that I hope you have already read): Py_Initialize() does not set the ``script argument list'' (sys.argv). If this variable is needed by Python code that will be executed later, it must be set explicitly with a call to PySys_SetArgv(argc, argv) subsequent to the call to Py_Initialize(). -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From fdu.xiaojf at gmail.com Wed Dec 27 12:30:50 2006 From: fdu.xiaojf at gmail.com (fdu.xiaojf at gmail.com) Date: Thu, 28 Dec 2006 01:30:50 +0800 Subject: How to depress the output of an external module ? In-Reply-To: <1167180130.305664.184120@a3g2000cwd.googlegroups.com> References: <459117EE.6070205@gmail.com> <1167179054.176478.254090@42g2000cwt.googlegroups.com> <1167180130.305664.184120@a3g2000cwd.googlegroups.com> Message-ID: <4592ADCA.80306@gmail.com> Carl Banks wrote: > Carl Banks wrote: > >> fdu.xiaojf at gmail.com wrote: >> >>> After some trials I found that put "os.close(1)" before calling the >>> function will depress the output. In fact, "os.close(1)" closed >>> standard output, but I don't know how to open it again after the function's >>> execution. >>> >> Try this: >> >> fd = os.dup(1) >> os.close(1) >> sys.stdout = os.fdopen(fd) >> > > Also, right after closing file descriptor 1, you might want to set it > to something so as to eliminate an annoying warning message when Python > tries to close it upon termination but finds it already closed. This > opens /dev/null and puts it in file descriptor 1 if not there already > (the fdz != 1 test might be unnecessary; I don't know if all flavors of > Unix always use the lowest available file descriptor). > > fdz = os.open("/dev/null",os.O_WRONLY) > Is it possible that I redirect low level standard output to a file-like object created by cStringIO.StringIO() instead of "/dev/null" ? > if fdz != 1: > os.dup2(fdz,1) > os.close(fdz) > > > Carl Banks > From e0427417 at student.tuwien.ac.at Sun Dec 10 14:17:57 2006 From: e0427417 at student.tuwien.ac.at (Mathias Panzenboeck) Date: Sun, 10 Dec 2006 20:17:57 +0100 Subject: multidimentional tables with different types In-Reply-To: References: Message-ID: <457c5cad$0$12384$3b214f66@tunews.univie.ac.at> vertigo wrote: > Hello > > I need to create structure which holds sorted records. > Each record should have two fields: > Float > String > > What type of structure will be the most appriopriate (simple) ? > > Thanx Just use a list. e.g.: data = [(5.5,"foo"),(7.7,"bar")] for a, b in data: print a, b data.append((4.3,"egg")) . . . From uymqlp502 at sneakemail.com Sun Dec 3 19:38:25 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 3 Dec 2006 16:38:25 -0800 Subject: Why not just show the out-of-range index? Message-ID: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the offending index are. Why does it force you to determine that information for yourself when it could save you a step and just tell you? This seems like a "no-brainer" to me. Am I missing something? From surekap at gmail.com Mon Dec 11 12:06:07 2006 From: surekap at gmail.com (Prateek) Date: 11 Dec 2006 09:06:07 -0800 Subject: How can I get involved Message-ID: <1165856767.477175.276380@80g2000cwy.googlegroups.com> Hey all, I'm messaging this group for the first time. Basically I've been a (pretty intensive) Python programmer for the past 2 years. I started a software company which has just released an SDK (v1.0b - developer preview) for developing web applications in Python. Key points: 1) It comes with a non-relational schema-free database we designed 2) The application server is based on CherryPy 3) The UI engine is XSLT based (but it also supports Cheetah and Clearsilver via plugins - out of the box) Basically, I really love the language and I'm looking for ways to get involved in the community and contribute. My past (pre-Python) experience has been mainly in web-technologies - Java, PHP, ASP and a little bit of C. Any ideas? Prateek From ptmcg at austin.rr._bogus_.com Sun Dec 17 14:30:04 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 17 Dec 2006 19:30:04 GMT Subject: first and last index as in matlab References: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> Message-ID: <0Vghh.51938$qp1.6450@tornado.texas.rr.com> "Evan" wrote in message news:1166379931.054933.77450 at j72g2000cwa.googlegroups.com... > In matlab I can do the following: > >>> ind = [3,5,7,2,4,7,8,24] > ind = 3 5 7 2 4 7 8 24 >>> ind(1) ans = 3 >>> ind(end) ans = 24 >>> ind([1 end]) ans = 3 24 > > but I can't get the last line in python: > > In [690]: ind = [3,5,7,2,4,7,8,24] > In [691]: ind[0] Out[691]: 3 > In [692]: ind[-1:] Out[692]: [24] > In [693]: ?? > > How do I pull out multiple indices as in matlab? > > > Thanks, Evan > Or use the third element of a slice, which defines a stepsize, and pick a step that will go from the first to the last element: >>> lst = list("ABCDEFG") >>> lst ['A', 'B', 'C', 'D', 'E', 'F', 'G'] >>> lst[0::len(lst)-1] ['A', 'G'] -- Paul From sjmachin at lexicon.net Tue Dec 26 17:23:22 2006 From: sjmachin at lexicon.net (John Machin) Date: 26 Dec 2006 14:23:22 -0800 Subject: Fuzzy string comparison In-Reply-To: References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> <1167167314.463288.98960@48g2000cwx.googlegroups.com> Message-ID: <1167171802.393139.240020@n51g2000cwc.googlegroups.com> Carsten Haese wrote: > On Tue, 2006-12-26 at 13:08 -0800, John Machin wrote: > > Wojciech Mula wrote: > > > Steve Bergman wrote: > > > > I'm looking for a module to do fuzzy comparison of strings. [...] > > > > > > Check module difflib, it returns difference between two sequences. > > > > and it's intended for comparing text files, and is relatively slow. > > > > Google "python levenshtein". You'll probably find this a better fit for > > typoed keys in a database. > > [...] > > Using the Levenshtein distance in combination with stripping "noise" > characters is a good start, but the OP might want to take it a step > further. One of the OP's requirements is to recognize visually similar > strings, but 241O (Letter O at the end) and 241X have the same > Levenshtein distance from 2410 (digit zero at the end) while the former > is visually much closer to 2410 than the latter. > > It seems to me that this could be achieved by starting with a standard > Levenshtein implementation such as http://hetland.org/python/distance.py > and altering the line "change = change + 1" to something like "change = > change + visual_distance(a[j-1], b[i-1])". visual_distance() would be a > function that embodies the OP's idea of which character replacements are > tolerable by returning a number between 0 (the two characters are > visually identical) and 1 (the two characters are completely different). Ya ya ya, I could have told him a whole lot more -- please consider that what I did tell him was IMHO over-generous in response to an OT question asking for assistance with performing a Google search. ... and given his keys are described as "numbers", a better example might be 241O or 241o false-matching with 2416. ... and it might be a good idea if he ran the simplistic approach first and saw what near-misses he actually came up with before complicating it and slowing down what is already an O(N**2*L**2) exercise in the traditional/novice implementation where N is the number of keys and L is their average length. The OP needs to think about 123456789 compared with 123426789; are they the same account or not? What other information does he have? HTH, John From mystilleef at gmail.com Sat Dec 9 16:04:04 2006 From: mystilleef at gmail.com (mystilleef) Date: 9 Dec 2006 13:04:04 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> Message-ID: <1165698244.563344.62270@73g2000cwn.googlegroups.com> Bill Atkins wrote: > Are any of these not subjective? Objectivity is in the eye of the beholder. > Lisp is much more than a functional language. Maybe so. But I've only ever appreciated its functional aspects. I wouldn't choose Lisp or its derivatives for OO related tasks even if I'm high. > Uh huh. Can you cite examples of this? Sounds like you're just > making stuff up here. Contrary to popular belief, writing a Lisp > macro that warps your mind and introduces a totally un-CL-like > semantics is extremely difficult. Most of the people who are good > enough at CL to do it (I'm certainly not one of them) are also > experienced enough to know when it's the right choice. Any sizable Lisp applications will make extensive use of macros. Emacs and magic ( the web framework) come to mind. My experience has shown that nobody but the person who writes the DSL extension can maintain their code. The benefits of extending a language in a domain specific manner are exaggerated. My observation is that macros are important to Lisp and it's derivative because they lack libraries to begin with. Common problems solved using macros in Lisp and friends are solved using specialized libraries in most other languages. And I like the specialized libraries route. Meta-programming just doesn't tickle my fancy. It just spells maintainance nightmare. > And Lisp environments all support getting the macroexpansion, > documentation, and source of any unfamiliar macro you might happen > upon, so really this is not as much of a problem as you might > fantasize it to be. How's this a good thing? I don't need a Python environment to grok Python code. > I don't agree with a lot of what you say in this paragraph, but I > you're right that libraries are crucial. That's why I wish there were > more people writing Lisp libraries instead of being scared away by > sheer fabrications like the stuff that's appearing in this thread. People only contribute to things they understand and appreciate. More people would be writing Lisp libraries if it was worthwhile. Apparently, it doesn't seem to be. A few years ago, I tried to write an editor is Scheme. The experience was appalling. I was able to write a fully functional prototype editor in less than a week in Python. Shockingly, at the time, I had no experience in Python. Guess which community I was inclined to contribute to afterwards. I hear stories similar to mine time and again, yet the Lisp community won't take heed. They'd rather squeal about the superiority of macros and whine about their frustrations in Python news groups. From pavlovevidence at gmail.com Mon Dec 4 12:22:00 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 4 Dec 2006 09:22:00 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165169117.866499.181520@73g2000cwn.googlegroups.com> <45732974$0$8758$ed2619ec@ptn-nntp-reader02.plus.net> <1165183970.832303.323350@73g2000cwn.googlegroups.com> <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165252920.329341.284910@j44g2000cwa.googlegroups.com> Jon Harrop wrote: [snip] > >> That's my point, using numpy encouraged the programmer to optimise in the > >> wrong direction in this case (to use slices instead of element-wise > >> operations). > > > > Ok, I can see that. We have a sort of JIT compiler, psyco, that works > > pretty well but I don't think it's as fast for large arrays as a good > > numpy solution. But it has more to deal with than a JIT for a > > statically typed language. > > Ok. Perhaps starting a Python JIT in something like MetaOCaml or Lisp/Scheme > would be a good student project? ...and finishing would be a good project for a well-funded team of experienced engineers. > >> Which begs the question, if you were writing in a compiled language like > >> F# would you ever use slices? > > > > If I was writing in F#? I absolutely would, because some problems are > > most cleanly, readably, and maintainably done with slices. I don't > > have any speed-lust, and I don't waste time making things fast if they > > don't need to be. I would rather spend my time designing and > > implementing the system, and optimizing things that actually need it. > > I don't want to spend my time tracking down some stupid indexing error. > > Ok. Can you name some problems that are solved more easily with slices than > with indexing? I may have just answered my own question by posting some > really concise pseudocode that uses slices. D4 transform? How about addition? How about the vast majority of cases where slicing is possible? Occasionally you have cases where slicing would work but be complicated, but in most cases, wherever slicing is feasible it's easier, less error-prone, less typing, more readable, more concise, more maintainable. > > Will any other F# people do it? I don't know if they all have > > speed-lust, or if they'd all deliberately avoid slicing to prove some > > kind of point about functional programming and/or non-machine-compiled > > languages, but I assume there'd be some who would do it for the same > > reasons I'd do it. > > My concern is that slices are being pulled into F# because they are popular > in languages like Python and Matlab but I've yet to see an example where > they are actually a good idea (in the context of F#, i.e. a compiled > language where indexing is as fast or faster). It's often a good idea where speed isn't crucial because it's easier, more readable, and more maintainable. I highly suspect F# and other languages would still using slicing for many problems for this reason. OTOH, it's rarely a good idea to always base coding decisions on speed to the exclusion of all other factors. > >> What makes numpy convenient? > > > > ...it scales up well... > > What do you mean? > > > ...it expresses mathematical concepts straightforwardly... > > It didn't express this mathematical concept very straightforwardly. I thought it did. One must know about the shared data nuances and the slicing syntax. Given that, the numpy way closely mimicked the way mathematical formulas look. Put it this way: which one of these two (numpy with slicing, Ocaml with indexing) would it be easer to reverse engineer a mathematical formula out of? I'd say the numpy version with slicing, by a long shot. > > And a lot of the time, you don't have to worry about indexing. > > Right. Ideally you want to factor that out without losing anything. Indeed, > if you do factor the C++ code you should get back to the underlying > mathematical definitions. Ideally, you'd want to write those directly and > have them executed efficiently. I am almost always happy to factor indexing out *with* losing something. > >> > No problem, numpy will be fast enough for my needs. > >> > >> Ok. But you'd rather have a compiler? > > > > Python *is* compiled, buddy. It has a VM that runs bytecode. > > I meant a native-code compiler, of course. > > > But, would I rather have a seperate compile to *machine code*, when an > > automatic compile to VM code is fast enough? > > > > Not remotely. Compilers are a PITA and I avoid them when it's > > possible. > > I can envisage a JIT Python compiler that would spot statically typed code, > compile it with no user intervention and then run it. I implemented such a > thing for Mathematica a few years ago. You can almost never spot "statically typed" code in Python reliably, even with a separate compile stage that does a global analysis. Even Lisp compilers, which are generally known to be the best compilers out there for a dynamically-typed language, don't do too well at this unless you help them out, and Lisp isn't nearly as dynamic as Python. As for JIT's, the best you could do is hook into a function, checking the types of its arguments, and cacheing optimized code for the given type signature. It's basically what psyco does. Anything more would require either help from the programmer or concessions in dynamicity. > >> Why not drop to C for this one function? > > > > Why would I? The assumptions clearly stated that numpy is fast enough. > > Why would I take several hours to write a C extension when I could do > > it with numpy in about 20 minutes, *and it's fast enough*? > > Is it very difficult to interface Python to other languages efficiently? No. It does involve lots of boilerplate. But even if it didn't, I wouldn't write an extension, because the numpy solution is cleaner, more readable, and more maintainable than anything I could write in C (which is a poor language that's good at being fast and talking to hardware and nothing else), and it's fast enough. > > But let me offer you some advice: if you wan't to lure people from > > Python, speed isn't going to cut it. Most people who chose Python > > (and, let's face it, most people who use Python chose it themselves) > > already knew it was slow, and chose it anyways. Pythonistas prefer > > Python because it's clean, readable, well-supported, and practical. > > Practical might be the sticking point here. If you were to get a > > Python prompt, and type "import this", it would print the Zen of > > Python, a set of principles by which the language is designed. One of > > them is "Practicality beats purity." And let's face it, functional > > languages are (or seem to be) all about purity. Notice that there's no > > Zen that says "Fast is better than slow". If you want us to swtich to > > Ocaml, you better figure out how it supports the Zen of Python better > > than Python does. > > I'm keen on the practical aspect. I intend to take some of the excellent > Python demos out there and port them to languages like F# in order to > illustrate how they too can be practical languages. That's what you say. But nothing you've done in this whole thread remotely suggests that "practical" means anything to you other than, "possible to write faster code in." Carl Banks From bjourne at gmail.com Mon Dec 4 14:58:30 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 4 Dec 2006 19:58:30 +0000 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: <740c3aec0612041158l73325436rbeaa3912513a8796@mail.gmail.com> On 12/4/06, OKB (not okblacke) wrote: > I think the same could be said of virtually all exceptions. What I > think would be ideal is that whenever an exception is raised, the > traceback tells you: > > 1) What the exception is > 2) The names of the variables involved in the offending expression > (or their character position in the line) > 3) The values of those variables There was a patch to that effect and a thread about it on python-dev two years ago [1]. Most python-devvers seemed skeptical. But the issue haven't come to closure yet. [1] - http://mail.python.org/pipermail/python-dev/2005-February/051470.html -- mvh Bj?rn From could.net at gmail.com Thu Dec 21 02:06:36 2006 From: could.net at gmail.com (could.net at gmail.com) Date: 20 Dec 2006 23:06:36 -0800 Subject: a question on python dict Message-ID: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> Python dict is a hash table, isn't it? I know that hashtable has the concept of "bucket size" and "min bucket count" stuff, and they should be configurable so I can set them to the proper value when I know how many items I'm going to handle. If these two values can't be set, the hashtable will give them default values. When there are more and more items being added to the hashtable, it increase its buckets and copy the old items into the new one and re-calculate the hash value of each item. I think this will waste some time doing the increasing-copying thing. If I know I'm going to handle about 20000 items, I can set the size of hashtable to 30000. So, can I do this in python? I can't figure it out so I come here for help. Thanks! From jon at ffconsultancy.com Sun Dec 10 03:57:03 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 08:57:03 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <457bb4cf$0$8756$ed2619ec@ptn-nntp-reader02.plus.net> <7xbqmcgola.fsf@ruckus.brouhaha.com> Message-ID: <457bcc7e$0$8739$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: >> That is a deficiency of Python that doesn't exist in modern FPLs like >> OCaml, SML, Haskell, F#... > > Nothing stops you from re-using the same internal function name in > your Python code, like you might use "i" as a throwaway loop index in > several places in the same function. It's just like in Scheme... It is not "just like in Scheme" if you don't have anonymous functions in Python. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From pretoriano_2001 at hotmail.com Sat Dec 9 18:52:42 2006 From: pretoriano_2001 at hotmail.com (pretoriano_2001 at hotmail.com) Date: 9 Dec 2006 15:52:42 -0800 Subject: Best Open Source Project? Message-ID: <1165708362.824899.250450@l12g2000cwl.googlegroups.com> Look at a poll in this site: http://www.grupthink.com/topic/index.php5?id=821&page=1 regards. From JShrager at gmail.com Tue Dec 12 23:48:00 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 12 Dec 2006 20:48:00 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165773218.686683.46640@16g2000cwy.googlegroups.com> Message-ID: <1165985280.821123.318210@f1g2000cwa.googlegroups.com> Robert Uhl wrote: > "JShrager at gmail.com" writes: > > I have the code here (probably not the latest bcs I left the company > > when it was acquired), let's do a little experiment, for what it's > > worth: 89727 lines of Lisp code in 131 modules (lisp code files), 3306 > > "(defun" (by grep|wc), and 261 "(defmacro". [We did NOT use macros as > > functions!] [Note that lines of code doesn't really matter in Lisp.] > > Wow--my emacs install has 1,152,598 lines of code in 1,570 files, 29,244 > defuns and 1,393 defmacros. This really doesn't prove anything > whatsoever (as I imagine that your stuff was a _lot_ more complex), > except maybe how great the FSF is for giving away this sort of thing for > free. Let us note that it's not FSF that gives this stuff away for free -- or if it is them proximally, it is not them ultimately -- ultimately it's the engineers who did all that work that gave it away for free. From tomas at fancy.org Sat Dec 30 01:22:24 2006 From: tomas at fancy.org (Tom Plunket) Date: Fri, 29 Dec 2006 22:22:24 -0800 Subject: Managing a queue of subprocesses? References: <1167442004.174070.71490@k21g2000cwa.googlegroups.com> Message-ID: <401cp296ljt2ch1kl94l1l4gvdjf1m84kh@4ax.com> cypher543 wrote: > self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) Instead of calling it self.buildPID, you might just call it self.buildProcess or something. It's actually a Popen object that gets returned. So yes you can do what you want: __init__ self.buildProcess to None. Then, in execute(), if (self.buildProcess is None) or (self.buildProcess.poll() is not None) start the next process. You've got to wait for one process to end before starting the next one, it's really that easy. So, don't just go ahead and fire them all instantly. Possibly what you want to do instead is have runQueue() do the check somehow that there's no active process running. What I would do, have runQueue() check to see if self.buildProcess is None. If it is None, fire the next process in the queue. If it isn't None, then check to see if it's ended. If it has ended, then set self.buildProcess to None. Next UI update the next step in the queue gets done. Mind that you'll have to modify the queue as you go, e.g. self.queue = self.queue[1:]. Finally, consider piping stderr separately, and direct its output to a different window in your GUI. You could even make that window pop open on demand, if errors occur. good luck, -tom! -- From robin at reportlab.com Fri Dec 15 11:58:20 2006 From: robin at reportlab.com (Robin Becker) Date: Fri, 15 Dec 2006 16:58:20 +0000 Subject: cxfrozen linux binaries run on FreeBSD? In-Reply-To: References: <1166195085.128464.294050@t46g2000cwa.googlegroups.com> Message-ID: <4582D42C.7050207@chamonix.reportlab.co.uk> robert wrote: > i80and wrote: >> I haven't personally used freeze (Kubuntu doesn't seem to install it >> with the python debs), but based on what I know of it, it makes make >> files. I'm not a make expert, but if FreeBSD has GNU tools, freeze's >> output _should_ be able to be compiled on FreeBSD. > > Yet do the Linux compiled cx_freeze binaries (and Python .so's) usually run directly on FreeBSD without a lot of trouble? > I have not access to a FreeBSD setup and someone wants to know the "probability" :-) > >> On Dec 15, 5:52 am, robert wrote: >>> When i freeze a python app (simple - no strange sys calls) for x86 Linux, does this stuff run well also on x86 FreeBSD? >>> >>> Robert I would guess not, but perhaps you could install one or other of the freebsd linux compatibility layers and link your stuff to their libs etc etc. -- Robin Becker From email at christoph-haas.de Fri Dec 1 11:36:39 2006 From: email at christoph-haas.de (Christoph Haas) Date: Fri, 1 Dec 2006 17:36:39 +0100 Subject: Simple question on indexing In-Reply-To: <20061201172146.ceb8a7f8.tartifola@gmail.com> References: <20061201172146.ceb8a7f8.tartifola@gmail.com> Message-ID: <200612011736.40130.email@christoph-haas.de> On Friday 01 December 2006 17:21, Tartifola wrote: > I would like to obtain the position index in a tuple when an IF > statement is true. Something like > > >>>a=['aaa','bbb','ccc'] > >>>[ ??? for name in a if name == 'bbb'] > >>>1 What about: [ x for x,y in enumerate(a) if y == 'bbb' ] Or if there is only one element 'bbb': a.index('bbb') Kindly Christoph From http Fri Dec 8 18:43:48 2006 From: http (Paul Rubin) Date: 08 Dec 2006 15:43:48 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> Message-ID: <7xslfqar7v.fsf@ruckus.brouhaha.com> "Mark Tarver" writes: > Thanks; a quick read of your reference to Norvig's analysis > > http://norvig.com/python-lisp.html > > seems to show that Python is a cut down (no macros) version of Lisp > with a worse performance. The only substantial advantage I can see is > that GUI, and Web libraries are standard. This confirms my suspicion > that Lisp is losing out to newbies because of its > lack of standard support for the things many people want to do. There is (IMO) some truth to that, but the flavor of Python programming is not that much like Lisp any more. Especially with recent Python releases (postdating that Norvig article) using iterator and generator objects (basically delayed evaluation streams) more heavily, Python is getting harder to describe in Lisp terms. It's moving more in the direction of Haskell. From tjreedy at udel.edu Wed Dec 13 14:07:20 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Dec 2006 14:07:20 -0500 Subject: YouTube written in Python References: <457f58e5$0$27424$4d3efbfe@news.sover.net> <1166007747.777721.153650@73g2000cwn.googlegroups.com> Message-ID: wrote in message news:1166007747.777721.153650 at 73g2000cwn.googlegroups.com... >> Terry Reedy wrote: >> > In a thread on the PyDev list, Guido van Rossum today wrote: >> >> And I just found out (after everyone else probably :-) that YouTube >> >> is >> >> almost entirely written in Python. (And now I can rub shoulders with >> >> the developers since they're all Googlers now... :-) > awesome.Could you give the link where guido told this No, I read the list via gmane.comp.python.devel. Search the archives at Python.org if you want, but I quoted all he wrote and will probably copy over any significant new info should any be posted. Exact details are probably considered trade secrets by YouTube. Terry Jan Reedy From tic_tac_toe44 at yahoo.com Fri Dec 15 08:04:57 2006 From: tic_tac_toe44 at yahoo.com (checoo) Date: 15 Dec 2006 05:04:57 -0800 Subject: sEcOnD LIfe; Be wHaT eVeR u wAnt To bE!!!! Message-ID: <1166187897.102835.36910@73g2000cwn.googlegroups.com> Second Life is a 3-D virtual world entirely built and owned by its residents. Since opening to the public in 2003, it has grown explosively and today is inhabited by a total of 2,007,546 people from around the globe. YOU LIVE IN A VIRTUAL WORLD, WHERE YOU CHOOSE HOW YOU LOOK AND WHAT YOU WANT TO DO IN LIFE.... well its in developing stage and will require all the talent and potential , so if you think you can do something really different this is the place you really want to be!!! >From the moment you enter the World you'll discover a vast digital continent, teeming with people, entertainment, experiences and opportunity. Once you've explored a bit, perhaps you'll find a perfect parcel of land to build your house or business. You'll also be surrounded by the Creations of your fellow residents. Because residents retain the rights to their digital creations, they can buy, sell and trade with other residents. The Marketplace currently supports millions of US dollars in monthly transactions. This commerce is handled with the in-world currency, the Linden dollar, which can be converted to US dollars at several thriving online currency exchanges. http://www.secondlife.com/?u=8731f5b8b5b14d8611be48107c7b72b1 (MIGHTY ALEXANDRE) HOPE TO SEE YOU IN MY WORLD From pecora at anvil.nrl.navy.mil Mon Dec 11 09:49:03 2006 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Mon, 11 Dec 2006 09:49:03 -0500 Subject: alternate language References: Message-ID: In article , Bryan wrote: > what is a good alternate language to learn? i just want something to expand > my mind and hopefully reduce or delay any chance of alzheimer's. i would > especially like to hear from those of you who learned python _before_ these > languages. > > haskell, erlang, ocaml, mozart/oz, rebel, etc. I have no experience with any of these. Of course, now I will give my opinions. :-) Just based on my experience with Python, C, C++, BASIC (several flavors), Fortran 77 (mostly). > > i don't require any of these features, but extra browny points for any of > the following: > > interactive interpreter Python has several. > batteries included Not sure what you mean here. Certainly the standard Python packages would offer you an immediately usable Python from Terminal and some other interpreters. But there are LOTS of add-ons available. A big plus with Open Source. Keeping them coordinated is a task, though (a big minus with Open Source). Overall, I haven't had to mess too much to get lots of usability from Python, especially for Scientific computing. > can integrate with c Yes. Several approaches, but none trivial. > compiles to native code No. > can use a gui toolkit such as wx Yep. Wx is here for Python. Also a book on it by Rappin and Dunn (Manning , publ. 2006) > doesn't take 60 hour weeks over years to master You'll be writing code on day 1. Useful code, too. Very, very nice language to learn and use. I recommend Python in a Nutshell by Martelli (O'Reilly Publ.) to read as you learn. Lots of online tutorials. See Python.org, SourceForge and google. I think you can get pretty good at Python coding in a month or so. Along with Perl and Ruby, Python is really a very popular interpreted/scripting language rather than a niche language (which I think most of the ones you mentioned are somewhat niche). That means there's a big, helpful community out there to talk to and lots of code available. I do all my new coding in it and then when I need speed in some routine I rewrite it in C as a Python extension. I can develop many times faster than I could in C/C++ or Fortran or BASIC (even). I cannot compare, however, to the languages you mentioned. Sorry. -- Lou Pecora (my views are my own) REMOVE THIS to email me. From robin at reportlab.com Thu Dec 21 09:10:01 2006 From: robin at reportlab.com (Robin Becker) Date: Thu, 21 Dec 2006 14:10:01 +0000 Subject: [ANN] PyInstaller 1.3 released In-Reply-To: <4589AEE8.8070600@jessikat.plus.net> References: <4589AEE8.8070600@jessikat.plus.net> Message-ID: <458A95B9.3050907@chamonix.reportlab.co.uk> Robin Becker wrote: > Giovanni Bajo wrote: > ........ >> yeah that's pretty cryptic. It's a known bug which I need to come around >> and fix it. Anyway, the message itself is harmless: if the program then >> exits, there is *another* problem. >> >> If you want to help with that, you could enable the console+debug mode >> and see what the traceback is. I'd be very glad to fix the problem for you. > > No problem I'll give it a whirl tomorrow. ....... OK I found the problem. First off I still see this message about msvcr71.dll could not be extracted! in the debug output. Secondly I found that the icon I specified in the Makespec.py invocation is actually being added to the distribution exe. I actually want to put the icon onto the running Tk app. We're using this code to do that self.tk.call('wm','iconbitmap', self._w, '-default', 'rptlabw.ico') ie it's assumed that the icon has been extracted into the runtime folder. I guess I either need to put the icon in as a resource or figure out some way to find the original exe and extract the icon from it. -- Robin Becker From pwatson at redlinepy.com Sat Dec 9 22:42:40 2006 From: pwatson at redlinepy.com (Paul Watson) Date: Sat, 09 Dec 2006 21:42:40 -0600 Subject: ooopy: newbie cannot get basic functionality to work In-Reply-To: References: Message-ID: <4u1e1gF15kmncU1@mid.individual.net> Andrew Sackville-West wrote: > Hi list, > > I am new to python and old to coding (as in I did it a long time > ago). I've got a task that cries out for a scripted solution -- > importing chunks of ASCII data dumps from a point-of-sale system into > an openoffice.org spreadsheet. What a great chance for me to get my > coding skills back and learn python too! The openoffice.org spreadsheet tool can read a CSV file. How about producing that first, just so you have something that works. I agree, this sounds like a nice way to dive into Python, but you might want something that works first, even if it is not elegant. From mohan.us2010 at gmail.com Mon Dec 11 05:56:08 2006 From: mohan.us2010 at gmail.com (mohan) Date: 11 Dec 2006 02:56:08 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? Message-ID: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> Hi Guys, I've been using the following IDE, "Pythonwin - Python IDE and GUI Framework for Windows. Copyright 1994-2001 Mark Hammond " With respect to my work, I had created my own modules (.py files) in drives and folders other than the python root. I know that if I need to import these modules, I need to specify the path of the directory where I've put my modules. I've tried the "Edit Python Path" sub menu in the menu "Tools" of PythonWin, but I could not add a new path i.e.- D:\xxxx\xxxx\xxxx\ATS. Could any one please let me know how could I add a new path to access my own modules. Thanks in advance, Mohan Swaminathan. From nick at craig-wood.com Mon Dec 4 13:30:04 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 04 Dec 2006 12:30:04 -0600 Subject: Ensure a variable is divisible by 4 References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 You should use // for future compatibility which is guaranteed to be an integer division whereas / isn't (see "from __future__ import division") Eg (x // 4) * 4 For the particular case of 4 being 2**2, you might consider x & ~0x3 which is a common idiom. If you want to round to the next largest 4 then add 3 first, eg for x in range(0,12): (x + 3) & ~0x3 Which prints 0,4,4,4,4,8,8,8,8,12... You could also consider the funky x>>2<<2 -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nono at hotmail.com Thu Dec 28 06:33:41 2006 From: nono at hotmail.com (Osiris) Date: Thu, 28 Dec 2006 12:33:41 +0100 Subject: Feasible in Python ? list of object , with two exeptional objects References: <6eo5p2di7lrcs5smouhg8ju83901b4hld0@4ax.com> <4592f3cc$0$17164$4c368faf@roadrunner.com> <8vv6p29lqjl24bkcge3iv66vflvt683akc@4ax.com> Message-ID: <4ra7p25sqtg02034cpiam99633ikimisi7@4ax.com> On Thu, 28 Dec 2006 11:14:27 +0100, Marc 'BlackJack' Rintsch wrote: >In <8vv6p29lqjl24bkcge3iv66vflvt683akc at 4ax.com>, Osiris wrote: > >> Would I put all the stuff that is the same in both classes in the base >> class and only the differing stuff in the subclasses ? > >Yes that's the intent of base/sub class relationships. Baseclasses >contain the behavior common to all their subclasses and subclasses >implement just the different or additional behavior. > >> Could I move the normal length method to the superclass, and override >> it in the special class, like this: > >Yes that can be done and makes perfectly sense if the `length()` in the >baseclass is the "normal" behavior and that baseclass can be instantiated >and used directly. > >Ciao, > Marc 'BlackJack' Rintsch now we're rolling ! :-) thnx both. From DustanGroups at gmail.com Wed Dec 6 08:00:28 2006 From: DustanGroups at gmail.com (Dustan) Date: 6 Dec 2006 05:00:28 -0800 Subject: reloading modules In-Reply-To: <1165409905.631587.178360@l12g2000cwl.googlegroups.com> References: <1165406976.641077.45350@f1g2000cwa.googlegroups.com> <1165409905.631587.178360@l12g2000cwl.googlegroups.com> Message-ID: <1165410028.356147.125650@n67g2000cwd.googlegroups.com> Dustan wrote: > aine_canby at yahoo.com wrote: > > I'm using python.exe to execute my modules. I have a music.py module > > which contains my classes and a main.py module which uses these > > classes. In python.exe, I call "import main" to execute my program. The > > problem is that I have to close python and reopen it everytime i change > > music.py or main.py. What should I be doing. > > > > Thanks, > > > > Aine. > > >>> import main > ### Execution Occurs ### > >>> # You go off to edit your module > >>> reload(main) > ### Execution Occurs ### I was obviously assuming that your module does something just by importing, which may or may not be the case. Either way, whenever a module may have been edited during a program's lifetime, it can be reloaded using the reload function. From http Wed Dec 13 21:22:04 2006 From: http (Paul Rubin) Date: 13 Dec 2006 18:22:04 -0800 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> Message-ID: <7x64cf6wtv.fsf@ruckus.brouhaha.com> at writes: > You proposal, seems nice to me but it doesn't work with Python 2.4.3, should > it work with 2.5? > > Again I am just wondering if the approach for > > [x for c x in some_list if some_condition] > > and > x = a if b else c > > could be generalized for normal straight forward iterations: > > for x in some_list if some_condition: Sorry, I got it wrong. Should have said: for x in (x for x in some_list if some_condition): ... So your example would have been: for x in (x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0): ... more code ... It should work in 2.4. From rupole at hotmail.com Fri Dec 1 08:49:00 2006 From: rupole at hotmail.com (Roger Upole) Date: Fri, 1 Dec 2006 08:49:00 -0500 Subject: Win32 Excel Generation Slow References: Message-ID: <1164981149_16081@sp6iad.superfeed.net> "Daniel Bowett" wrote in message news:mailman.928.1164969844.32031.python-list at python.org... >I am trying to create an excel document that displays a table of data. It does exactly what I want but takes a long time. I am >writing around 1000 rows and it takes around a second to do each row. > > Is there a quicker way to write this? The reason I want excel is this needs to read and manipulated by management. > > The function I am using is: > > def createExcel(data): > xlApp = Dispatch("Excel.Application") > wb = xlApp.Workbooks.Add() > xlApp.Visible = 1 > ws = wb.Worksheets[0]; > > headers = ["Sales Rank", "UPC", "Description", "Stock", "Manifest Stock", "Total Stock", "Week Sales", "Price", "Total Price", > "Days Cover"] > > column = 1 > for each in headers: > xlApp.ActiveSheet.Cells(1, column).Value = each > column = column + 1 > > row = 1 > for eachline in data: > xlApp.ActiveSheet.Cells(row, 1).Value = row > xlApp.ActiveSheet.Cells(row, 2).Value = eachline[0] > xlApp.ActiveSheet.Cells(row, 3).Value = eachline[1] > xlApp.ActiveSheet.Cells(row, 4).Value = eachline[2] > xlApp.ActiveSheet.Cells(row, 5).Value = eachline[3] > xlApp.ActiveSheet.Cells(row, 6).Value = eachline[4] > xlApp.ActiveSheet.Cells(row, 7).Value = eachline[5] > xlApp.ActiveSheet.Cells(row, 8).Value = eachline[6] > xlApp.ActiveSheet.Cells(row, 9).Value = eachline[7] > xlApp.ActiveSheet.Cells(row, 10).Value = eachline[8] row = row + 1 > If you preformat the data including the row number, you can insert it en masse using a Range object. This runs in just a couple of seconds: from win32com.client import Dispatch data=[(x,'data1','data2','data3','data4','data5','data6','data7','data8','data9') for x in xrange(1000)] def createExcel(data): xlApp = Dispatch("Excel.Application") wb = xlApp.Workbooks.Add() xlApp.Visible = 1 ws = wb.Worksheets[0]; headers = ["Sales Rank", "UPC", "Description", "Stock", "Manifest Stock", "Total Stock", "Week Sales", "Price", "Total Price", "Days Cover"] column = 1 for each in headers: xlApp.ActiveSheet.Cells(1, column).Value = each column = column + 1 xlApp.ActiveSheet.Range("A2:J1001").Value=data createExcel(data) Roger ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From mcphail_colin at hotmail.com Wed Dec 6 03:55:49 2006 From: mcphail_colin at hotmail.com (cmcp) Date: 6 Dec 2006 00:55:49 -0800 Subject: Cross-platform issue with wxRadioBox In-Reply-To: <1165357263.918851.79610@j72g2000cwa.googlegroups.com> References: <1165293376.188950.304820@79g2000cws.googlegroups.com> <1165357263.918851.79610@j72g2000cwa.googlegroups.com> Message-ID: <1165395348.761385.229330@73g2000cwn.googlegroups.com> eugene.gokhvat at gmail.com wrote: > I have updated my script to use wx.RadioButton instead, which works > perfectly on my mac again, but now the submit button doesn't show up on > the pc and I can't click in the netid field on the pc either. any > ideas? > I modified the __init__() method of class regFrame from your original posting to create a wx.Panel as a child of self and then made all the controls be children of this panel. Your app then seemed to work OK on Windows XP. Using a wx.Panel to hold the content of a frame is a standard wxPython idiom. I find reading the wxPython demo source is a very useful way to learn this sort of thing. HTH, -- CMcP From Tim.Golden at viacom-outdoor.co.uk Thu Dec 14 05:06:27 2006 From: Tim.Golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 14 Dec 2006 10:06:27 -0000 Subject: pwinauto to remote automate a GUI ? In-Reply-To: Message-ID: [baitelli] | pywinauto is a set of python modules to automate the | Microsoft Windows GUI. | With the lines below we start and atomates the apllication Notepad: | | from pywinauto import application | app = application.Application() | app.start('C:\Notepad.exe') | ... pywinauto automation code | | Question: Is it possible to start and automate a remote GUI | using Python? One way might be to have something like Pyro (http://pyro.sf.net) running on the remote machine linked to a proxy on the local machine. TJG Tim Golden Senior Analyst Programmer -------------------------------------------------------- Viacom Outdoor Ltd, Camden Wharf, 28 Jamestown Road, London, NW1 7BY T: 020 7482 3000 F: 020 7267 4944 Email: Tim.Golden at viacom-outdoor.co.uk www.viacom-outdoor.co.uk The contents of this e-mail are confidential to the ordinary user of the e-mail address to which it was addressed, and may also be privileged. If you are not the addressee of this e-mail you may not copy, forward, disclose or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error, please e-mail the sender by replying to this message. Viacom Outdoor Ltd reserves the right to monitor e-mail communications from external/internal sources for the purposes of ensuring correct and appropriate use of Viacom Outdoor facilities. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From juanrgonzaleza at canonicalscience.com Tue Dec 12 03:55:43 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 12 Dec 2006 00:55:43 -0800 Subject: merits of Lisp vs Python In-Reply-To: <4u6mffF161jbqU3@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> Message-ID: <1165913743.943676.5910@79g2000cws.googlegroups.com> greg ha escrito: > From another angle, think about what a hypothetical > Python-to-Lisp translator would have to do. It couldn't > just translate "a + b" into "(+ a b)". It would have > to be something like "(*python-add* a b)" where > *python-add* is some support function doing all the > dynamic dispatching that the Python interpreter would > have done. > > That's what I mean by Python being more dynamic than > Lisp. I see no dinamism on your example, just static overloading. From address.good.until.2006.dec.22 at justmail.de Mon Dec 11 11:44:17 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Mon, 11 Dec 2006 17:44:17 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <7xejr8r86m.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano schrieb: > On Sat, 09 Dec 2006 22:41:12 -0500, Ken Tilton wrote: > >>> I know that. It was more of a rhetorical question -- Lispers are either >>> trying to emphasis the radical nature of what you can do with macros, or >>> understate it and make them seem just like functions. >> Yep, both. The first is rare. CLOS is one, my Cells (ported this summer >> to PyCells as part of SoC 2006) is another. The latter is the norm. > > If macros' advanced usage is rare, and most usage of macros could be done > by functions, then maybe that explains why so many coders don't miss them. You can't do with functions what you can do with macros. Macros are just parameterized code. A template. Compare it with HTML templates Your name is .
Welcome! The page that arrives the user does not include any template code anymore. Just plain html. Same happens with Lisp macros. After compilation (preprocessing the html template by Zope) there are no macros left. So in the end you have just some Lisp functions. So one does not *need* macros, in the sense of turing completeness. But at the same time one can meet lots of places where templates can make sense and where they are used. Even the programmers of Zope thought of them as a plus for productivity. In Lisp you don't always design one huge macro after the other, which really saves a lot of code. Many macros save one or two short lines of code. This might sound not important. But it sums up. Somewhere else I asked you to imagine how you would like it if you had to call doodleBoodle() before each if-statement to make it work. That would be plain stupid if you had to. So if you meet something in code that you use several times, then you factor that repeating block of code out into a function that takes another function which will get called in the right environment. And macros help here "only" to save one or two loc. But as I said, it sums up. Andr? -- From rampeters at gmail.com Wed Dec 6 19:06:47 2006 From: rampeters at gmail.com (johnny) Date: 6 Dec 2006 16:06:47 -0800 Subject: newb: How to call one modue from other Message-ID: <1165450007.504080.327490@80g2000cwy.googlegroups.com> I have a module called ftp and I have another module called processKick. What I need is to have processKick, create fork and execute ftp like below. Relevant processKick code as follows: def do_child_stuff(): ftp def fork_test(): pid = os.fork() if pid == 0: # child do_child_stuff() os._exit(0) # parent - wait for child to finish os.waitpid(pid, os.P_WAIT) Can someone also tell me what is the purpose of if __name__ == "__main__": Do I have to call, main of ftp module within processKick? Thank you in advance From rschroev_nospam_ml at fastmail.fm Wed Dec 27 18:56:33 2006 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Wed, 27 Dec 2006 23:56:33 GMT Subject: DOS, UNIX and tabs In-Reply-To: <1167243129.972618.132520@48g2000cwx.googlegroups.com> References: <1167243129.972618.132520@48g2000cwx.googlegroups.com> Message-ID: Ben schreef: > I have a python script on a unix system that runs fine. I have a python > script on a windows system that runs fine. Both use tabs to indent > sections of the code. I now want to run them on the same system, > actually in the same script by combining bits and pieces. But whatever > I try my windows tabs get converted to spaces when I transfer it to the > unix system and the interpreter complains that the indentation style is > not consistant throughout the file. Short of going through 350 lines of > code and manually replacing spaces with tabs what an I do? I'm thinking > there surely must be a simple solution I have missed here! How do you transfer the files or their contents from Windows to Unix and vice versa? Whatever means you use shouldn't change the file contents, except possibly conversion of line endings. What editors do you use on both systems? Maybe it's just the way one of your editors is configured? Are you sure there are tabs in the files, or does one of your editors automatically convert them to spaces? Maybe it's not a bad idea to view your Windows files with a Windows-based hex editor to make sure the indentation is really made up of tabs. BTW I'm a proponent of spaces instead of tabs, but indentation by tabs only (i.e. not a mixture of tabs and spaces) is an acceptable solution too and it should work. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From felix.benner at imail.de Wed Dec 20 11:36:42 2006 From: felix.benner at imail.de (Felix Benner) Date: Wed, 20 Dec 2006 17:36:42 +0100 Subject: Fall of Roman Empire In-Reply-To: References: <20061220054657.7CEEA1E4006@bag.python.org> <1166595864.797404.260570@n67g2000cwd.googlegroups.com> <873b7b6one.fsf@benfinney.id.au> <45892D76.2050002@gmx.net> Message-ID: Thomas Ploch schrieb: >> Ben Finney schrieb: >>> "John Machin" writes: >>> >>>> Ben Finney wrote: >>>> >>>>> \ "...one of the main causes of the fall of the Roman Empire was | >>>>> `\ that, lacking zero, they had no way to indicate successful | >>>>> _o__) termination of their C programs." -- Robert Firth | >>>> An amusing .sig, but it doesn't address the root cause: As they had no >>>> way of testing for the end of a string, in many cases successful >>>> termination of their C programs would have been unlikely. >>> Yet historically proven: the 'imperium' process they were running >>> terminated many centuries ago. >>> >>> Or did it fork and exec a different process? >>> > > I rather stay with the metaphysics: > > > #include "metaphysics.h" > > static metaPower God; > > universe *makeUniverse(metaPower God) > { > if (!God) { > printf("Oops, no God available at the moment.Try again later!"); > return NULL; > } > > universe *everything; > > if (!(everything = malloc(sizeof(universe)))) { > God.mood = REALLY_BORED; > printf("God has no time to create a universe."); > return NULL; > } else { > return universe; > } > } > > > :-) > > Sorry, somehow had to do this. Please slap me (i like it, don't worry) > if it's totally stupid > > soooo totally stupid! You forgot the main function! (not to mention you returned universe instead of everything) static int main(int argc, char **argv) { char *god_name; if (argc) god_name = argv[1]; else god_name = "YHWH"; metaPower God = getGodByName(god_name); universe *everything = makeUniverse(God); while (simulatePhysics(everything)); return 0; } From shitizb at yahoo.com Wed Dec 6 17:00:14 2006 From: shitizb at yahoo.com (Shitiz Bansal) Date: Wed, 6 Dec 2006 14:00:14 -0800 (PST) Subject: Beautiful Soup : Problem extracting links In-Reply-To: <45773BBC.5020301@andrew.cmu.edu> Message-ID: <866078.50508.qm@web53811.mail.yahoo.com> Hi, I am using beautiful soup to get links from an html document. I found that beautiful Soup changes the & in the links to & due to which some of the links become unusable. Is there any way I could stop this behaviour? Regards, Shitiz __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From sarcasticzombie at gmail.com Mon Dec 18 10:50:45 2006 From: sarcasticzombie at gmail.com (Sarcastic Zombie) Date: 18 Dec 2006 07:50:45 -0800 Subject: Over my head with descriptors In-Reply-To: <9ab0d$45845ecb$534197b5$23314@news.inode.at> References: <1166119871.508417.239060@n67g2000cwd.googlegroups.com> <9ab0d$45845ecb$534197b5$23314@news.inode.at> Message-ID: <1166457045.576700.30960@f1g2000cwa.googlegroups.com> > > Is there a reason you don't just use __init__ instead of __new__, and use > > "self.age" and "self.weight" and so on?I was asking myself the same thing... > > Chris "A lack of understanding," he answered sheepishly. There are attributes (ie, question._qtext) that I do want to be the same for every instance and thus don't want the extra memory overhead of storing it anew for each instance. Using the "instance" reference as you guys suggested, I'm now storing the instance-specific information that the descriptors validate by cramming it into instance._foo. Works great now! Thanks for the additional understanding. It's a lot to wrap one's head around at first. -SZ From sjdevnull at yahoo.com Mon Dec 11 11:11:17 2006 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 11 Dec 2006 08:11:17 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> Message-ID: <1165853477.104769.325440@n67g2000cwd.googlegroups.com> Bill Atkins wrote: > > On the plus side, Python makes less demands on the > > capabilities of the editor. All you really need > > is block-shifting commands. Bracket matching is > > handy for expressions but not vital, and you > > certainly don't need bracket-based auto-indenting. > > Oh, please. So we should restrict the power of the languages we > choose just to make sure that our code can be edited in Notepad? In the real world, it's a non-negligible consideration, IMO. I find myself needing to write code on machines that aren't my usual dev machine at least a couple of times a year, and not having to install a particular editor is nice (especially in terms of keeping the modifications to someone else's machine down to a minimum). It's hardly a dealbreaker for a particular language, but it's far from worthless. From xx at wp.pl Thu Dec 14 03:50:32 2006 From: xx at wp.pl (avlee) Date: Thu, 14 Dec 2006 09:50:32 +0100 Subject: variables with dynamicly generated names Message-ID: Hello Is it possible to use in python variables with dynamicly created names ? How ? Thanx From dotancohen at gmail.com Sun Dec 10 07:36:36 2006 From: dotancohen at gmail.com (Dotan Cohen) Date: Sun, 10 Dec 2006 14:36:36 +0200 Subject: possible php convert Message-ID: <880dece00612100436v1051977fk966b77eecb4296cd@mail.gmail.com> Hi all, I've been contemplating the switch to python from php. I'm no wiz, but I can get my way around with help form the online docs. I see that python has much less documentation available, so expect to hear from me a bit in the next few weeks. :) One concern that I have is that my current host does not support python, and for a very technical reason (money) I'd rather not switch. I've googled the possibility of installing python in my user's home directory (RHEL server), and this seems possible. Can anyone enlighten me as to how I could do this? Thanks in advance. Dotan Cohen http://lyricslist.com/ http://what-is-what.com/ From udodenko at users.sourceforge.net Sun Dec 10 06:04:02 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sun, 10 Dec 2006 13:04:02 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> Message-ID: <457be9a6$0$49209$14726298@news.sunsite.dk> (message (Hello 'Paul) (you :wrote :on '(10 Dec 2006 00:01:34 -0800)) ( PR> I'm not persuaded, I haven't examined his example carefully yet but it PR> looks like basically a reader hack. Lexical scope in Lisp means among PR> other things lexical closures and (maybe I'm mistaken) it seemed to me PR> Alex's example didn't supply that. lexical scope is pretty low-level concept that affects lot of stuff, so it requires lot of changes -- we are not extending a language, but build a new one actually. we'll have to create object 'lexical environment' and to query it for variable values instead of just using variable values: var -> (query env 'var). then, we'll need to make closures -- that is a pair of environment and code itself. so, it's very close to writting new interpreter -- but it's order of magnitude easier to write this interpreter via macros than from scratch, most other language constructs can be reused. that's the point -- macros allow to implement a language with aprox. same syntax but different semantics relatively easily. PR> I'm also unconvinced (so far) of his description of call/cc as a Lisp PR> macro but that's going to take me some head scratching. there is a chapter about continuations in Paul Graham's "On Lisp". "Common Lisp doesn't provide call/cc, but with a little extra effort we can do the same things as we can in Scheme. This section shows how to use macros to build continuations in Common Lisp programs." ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From gagsl-py at yahoo.com.ar Wed Dec 6 22:46:29 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 00:46:29 -0300 Subject: newb: How to call one modue from other In-Reply-To: <1165458032.135595.321240@f1g2000cwa.googlegroups.com> References: <1165450007.504080.327490@80g2000cwy.googlegroups.com> <1165458032.135595.321240@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061207003811.05446518@yahoo.com.ar> At Wednesday 6/12/2006 23:20, johnny wrote: >Can someone also tell me what is the purpose of >if __name__ == "__main__": Reading the Python Tutorial helps a lot. >Do I have to call, main of ftp module within processKick? Yes, because the original script author didn't want to call a function inside that module, instead, he wanted to invoke the module as a child program. Reading the Python Tutorial helps a lot. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From sergey at fidoman.ru Thu Dec 21 09:04:23 2006 From: sergey at fidoman.ru (Sergey Dorofeev) Date: Thu, 21 Dec 2006 17:04:23 +0300 Subject: treating MIME messages Message-ID: Hello all. Anybody who has idle time, please look at my version of MIME tools at http://www.fidoman.ru/prog/mime/. Questions and critical notes are welcome. If somebody will consider that interesting, I will refine these modules and put to pypi. From crystalattice at gmail.com Mon Dec 11 22:22:13 2006 From: crystalattice at gmail.com (crystalattice) Date: 11 Dec 2006 19:22:13 -0800 Subject: Tkinter button doesn't appear in OS X In-Reply-To: <457CC308.1080801@codebykevin.com> References: <1165798158.199702.217180@79g2000cws.googlegroups.com> <457CC308.1080801@codebykevin.com> Message-ID: <1165893733.852293.229190@f1g2000cwa.googlegroups.com> Kevin Walzer wrote: > > What version of Tk are you running? I've seen this bug on old versions > of Tk (i.e. 8.4.7) but not recently. > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com I'm using Python 2.4.2, which I believe is the default version for OS X. How do I check the Tk version? Can I force my programs to use a different version of Python, e.g. if I installed Python 2.5? From klappnase at web.de Sun Dec 17 19:29:37 2006 From: klappnase at web.de (klappnase) Date: 17 Dec 2006 16:29:37 -0800 Subject: New os.path.exists() behavior - bug or feature? Message-ID: <1166401777.533652.208840@n67g2000cwd.googlegroups.com> Hi all, yesterday I installed Python-2.5 and python-2.4.4 on my windows2k box. When trying to use os.path.exists() to detect which drives are present on the system I noticed that these behave differently: Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import os >>> for char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': if os.path.exists('%s:\\' % char): print '%s:\\' % char A:\ C:\ D:\ E:\ >>> ########################################### Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import os >>> for char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': if os.path.exists('%s:\\' % char): print '%s:\\' % char C:\ >>> When I insert a floppy into A: os.path.exists('A:\\') will return True on Python-2.5, too. Does anyone know, is this inconsistent behavior a bug or a new feature? I also noticed that the Tix binaries are no longer present in 2.5, does anyone know if it is planned to remove them pemanently? Thanks in advance Michael From tactics40 at gmail.com Sat Dec 9 14:38:35 2006 From: tactics40 at gmail.com (tac-tics) Date: 9 Dec 2006 11:38:35 -0800 Subject: len() and PEP 3000 In-Reply-To: References: <4tnqlkF13bbqeU1@mid.individual.net> <5HSdh.15210$P04.6844@tornado.fastwebnet.it> Message-ID: <1165693115.007835.160250@j72g2000cwa.googlegroups.com> > __len__ is not very special and the > property len eliminates the redundant parentheses. One might say the current syntax eliminates the redundant dot. From nmm1 at cus.cam.ac.uk Tue Dec 19 05:01:47 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 19 Dec 2006 10:01:47 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> lrqjl$j4s$1@newwwwwwwwwwwwwwww elrrgs$8p6$1@geeini.csx.cam.ac.... .1166111433.32001.python-list@ppppppppppp 2$a95$1@gemini............... ailman.1607.1166112864.32031.pyyhon-list@pythonnnnnn $1@gemini.csx.cccccccccc <4587506D.50808@cosc.canterbury.ac.nz> Message-ID: In article <4587506D.50808 at cosc.canterbury.ac.nz>, greg writes: |> Nick Maclaren wrote: |> |> > Unfortunately, you are confusing the issue, because there are far |> > more extraneous aspects than relevant ones, and your view of the |> > similarities requires looking at the issue in a very strange way. |> > I think that I can see what you mean, but only just. |> |> Each member of a struct has a distinct, predefined |> role. Even if they all have the same type, you |> can't swap their values around without destroying |> the meaning of the data. That's what's meant by |> "heterogeneous" in this context -- it's not about |> the values themselves, but the way they're used. |> |> This is the kind of thing for which Python tuples |> are mainly designed -- use as a struct whose |> members happen to be named by integers rather |> than strings. Well, that was obvious to me on a cursory reading, because I have enough relevant experience with other languages. It wasn't what I was referring to, which was two things: C arrays are not extensible and, before C99, were fixed in size at compile time. That makes them rather more similar to tuples in those ways! I know that's not the aspect you were thinking of, but is why I made the remark that I did. It does explain why you think of lists as homogeneous, but the analogy doesn't hold water on closer inspection. There doesn't seem to be ANYTHING in the specification or implementation that assumes lists are homogeneous. Regards, Nick Maclaren. From gagsl-py at yahoo.com.ar Wed Dec 27 21:25:44 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 27 Dec 2006 23:25:44 -0300 Subject: can't instantiate following inner class In-Reply-To: <45932302$0$19091$4fafbaef@reader4.news.tin.it> References: <87mz586eyx.fsf@pyenos.pyenos.org> <45932302$0$19091$4fafbaef@reader4.news.tin.it> Message-ID: <7.0.1.0.0.20061227232258.05427eb0@yahoo.com.ar> At Wednesday 27/12/2006 23:55, Gian Mario Tagliaretti wrote: >class One(object): > def __init__(self): > whatever > >don't forget to call __init__ on new style classes otherwise you can pass >arbitrary arguments when instantiating the class e.g.: > >one = One(a, b) > >but python will silently ignore them and you probably won't like it... I don't understand what you say here. >>> class One(object): pass ... >>> a = One(1,2) Traceback (most recent call last): File "", line 1, in ? TypeError: default __new__ takes no parameters How do you make Python silently ignore the arguments? -- 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 From schoon at amgt.com Thu Dec 28 16:50:23 2006 From: schoon at amgt.com (Mark Schoonover) Date: Thu, 28 Dec 2006 13:50:23 -0800 Subject: rsync for python? Message-ID: <26845D561256D3428A862700DAF69B581AEF46@AG-EX1> nienfeng wrote: > Hi, everyone > > I want to build rsync server that can run in linux and windows, > and configure by python. So I'm looking for something like rsync for > python. I find rsync.py and pysync. But rsync.py looks like a > client mode, > it can't be a rsync server, is it? Can pysync be a rsync server? > > Thanks.... by nienfeng If you need bi-directional sync, then Unison is pretty good. Rsync can run in two modes, one of them using rsyncd. I've written up a page on how to build an rsync server that will do hourly, daily and weekly snapshots for multi-terabyte systems. I can't claim coming up with the original idea, it's just what works well for me. http://marks-tech-pages.blogspot.com will give you an example setup with scripts to use. Not developed in Python either... Sorry if this has been hashed already, I've been out on vacation, and just getting back to email. Thanks! Mark Schoonover IS Manager American Geotechnical V: 858-450-4040 - F: 714-685-3909 - C: 858-472-3816 "Stop the Earth!! I want off!!" From fredrik at pythonware.com Wed Dec 6 17:43:36 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 06 Dec 2006 23:43:36 +0100 Subject: len() and PEP 3000 In-Reply-To: <1165441974.734443.16760@j72g2000cwa.googlegroups.com> References: <4tnqlkF13bbqeU1@mid.individual.net> <1165441974.734443.16760@j72g2000cwa.googlegroups.com> Message-ID: Beliavsky wrote: > I agree with you -- a.__len__() is ugly compared to len(a) . I am > surprised that such common idioms as len(a) may be going away. no need to; the fact that something isn't currently mentioned in a preliminary Python 3000 PEP doesn't mean that it will be removed.
From vivainio at gmail.com Wed Dec 20 05:30:15 2006 From: vivainio at gmail.com (Ville Vainio) Date: 20 Dec 2006 02:30:15 -0800 Subject: IPython 0.7.3 upgrade notes In-Reply-To: <1166609906.624854.9350@79g2000cws.googlegroups.com> References: <1166609906.624854.9350@79g2000cws.googlegroups.com> Message-ID: <1166610615.306667.100310@n67g2000cwd.googlegroups.com> Ville Vainio wrote: > Something I forgot to emphasize in the announcement, knowing that not > everyone reads the release notes - if you are upgrading from a previous > version of IPython, you must either: > > - Delete your ~/ipython (or ~/_ipython) directory OR > - Run %upgrade once IPython starts. And if you are wondering what all of this is about, due to c.l.p.announce moderator approval wait period, see http://projects.scipy.org/ipython/ipython/wiki/Release/0.7.3 From robert.kern at gmail.com Thu Dec 28 22:35:55 2006 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 28 Dec 2006 22:35:55 -0500 Subject: A stupid question In-Reply-To: <1167362866.807346.73510@73g2000cwn.googlegroups.com> References: <1167362866.807346.73510@73g2000cwn.googlegroups.com> Message-ID: luxnoctis at gmail.com wrote: > Hello all. Let me say first that I have no idea what python is or what > it does. > > I bought a floor model computer, and it came with all sorts of > ridiculousness on it that I promptly uninstalled. However, now whenever > I start windows I get a message saying "LoadLibrary (pythondll > ) failed." It also says this when I try to download into a bittorrent > client, and it keeps it from downloading. What does this mean, and how > can I make it go away? http://effbot.org/pyfaq/installed-why-is-python-installed-on-my-machine.htm However, none of us know who built your system or any specifics as to what they installed Python for. You should ask them, instead. -- 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 From tactics40 at gmail.com Wed Dec 13 15:51:35 2006 From: tactics40 at gmail.com (tac-tics) Date: 13 Dec 2006 12:51:35 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> Message-ID: <1166043095.293450.282050@80g2000cwy.googlegroups.com> > > I use 'French units' instead of the term 'metric system' because the > > latter means 'measurement system,' and of course could validly be > > applied to _any_ system.Now we know how one contractor ended up using English units when the > other was using French units and an entire Mars mission was lost: they > were both using the metric system. LISP is better than Python, because it does not have a American Empirical Measurements library, preventing horrible spaceborne disasters. From ronrsr at gmail.com Mon Dec 18 01:59:17 2006 From: ronrsr at gmail.com (ronrsr) Date: 17 Dec 2006 22:59:17 -0800 Subject: dealing with special characters in Python and MySQL In-Reply-To: <1166423702.885345.30460@80g2000cwy.googlegroups.com> References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> <8rqhh.956$X72.39@newsread3.news.pas.earthlink.net> <1166423702.885345.30460@80g2000cwy.googlegroups.com> Message-ID: <1166425157.785409.94560@80g2000cwy.googlegroups.com> version of python is 2.2 - From http Tue Dec 12 19:52:45 2006 From: http (Paul Rubin) Date: 12 Dec 2006 16:52:45 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7x3b7lccjn.fsf@ruckus.brouhaha.com> Message-ID: <7xodq8ty5e.fsf@ruckus.brouhaha.com> Ken Tilton writes: > Oh, my. time to trot out my "hey, X is cool, let's use it for > everything!" rant. Somehow it's something other than a rant if X is Lisp? From e0427417 at student.tuwien.ac.at Fri Dec 8 06:45:52 2006 From: e0427417 at student.tuwien.ac.at (Mathias Panzenboeck) Date: Fri, 08 Dec 2006 12:45:52 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. > > Mark > I do not know much about Lisp. What I know is: Python is a imperative, object oriented dynamic language with duck typing, List is a declarative, functional dynamic language -> those two languages have different scopes. For more Information: http://en.wikipedia.org/wiki/Functional_programming http://en.wikipedia.org/wiki/Object-oriented_programming http://en.wikipedia.org/wiki/Dynamic_programming_language http://en.wikipedia.org/wiki/Lisp_programming_language http://en.wikipedia.org/wiki/Python_%28programming_language%29 From rdiaz02 at gmail.com Mon Dec 11 07:15:36 2006 From: rdiaz02 at gmail.com (rdiaz02 at gmail.com) Date: 11 Dec 2006 04:15:36 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165834892.338714.34850@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165824471.730090.153530@j72g2000cwa.googlegroups.com> <1165825648.930965.208130@j72g2000cwa.googlegroups.com> <457d2b13.3849154@news.readfreenews.net> <1165834892.338714.34850@16g2000cwy.googlegroups.com> Message-ID: <1165839336.466140.7670@80g2000cwy.googlegroups.com> Maybe this was already mentioned in this thread and I didn't see it. Anyway, I find that Scheme (so I am talking about Scheme as a member of the "lisp family") has pedagogical advantages over Python. 1. There are a range of excellent books that will introduce not just Scheme but programming and computer science to audiences with varied background and previous programming experience. 1.1. I do not know of any Python equivalents to "The Little Schemer" and "The Seasoned Schemer". These teach you recursion and "the art of scheme programming". I think "Core Python Programming" (and, to a lesser extent, "Learning Python") might teach some of "the art of python programming", but the focus, style, and effectivenes are quite different (and, I'd say, not as successful; you can read the little schemer in a couple of long train commutes; there is no way you can do that with Core Python Programming.). Sure, the style of "The little Schemer" is not for everyone. 1.2. "How to design programs" is obviously a much broader, comprehensive, detailed, and far-reaching textbook than (the nice) "How to think like a computer scientist; learning with Python". 1.3. SICP has no counterpart in the Python world. I've read some people have taught SICP like using Python (and that there is a new course at MIT, taught by Abelson and/or Sussman, that will use Python, not Scheme; but this is not a course that really substitutes the original for which SICP was written). But SICP remains SICP. It'd be nice to see something similar in Python. 1.4. More advanced material is available as "Programming Languages: Application and Interpretation" (Krishnamurthi). I know of no Python counterpart in the range and depth of topics covered. 1.5. Last, but not least, lots of this material is available on-line. So you can check it out before buying the dead-tree version. 2. PLT scheme and Dr. Scheme are a wonderful learning environment for Scheme, with no equivalent in Python. Its not just the great debugging and tracing facilities, but also who you can restrict the language you use to concentrate on some key features, so as to build incrementally (to avoid the forest from preventing you to see some specific trees). Interestingly, I think there has been at least one attempt to build something similar for Python on top of Dr. Scheme (in PyCon 2004 or 2005?). 3. Schemers (some Schemers at least) are making a strong effort to teach CS to audiences of varied backgrounds and experiences. They even have a sequence that starts from basically 0, teaches you Scheme, and ends up including Java (I guess this is catering to the "but I really need Java to get a job when I get out of here!"). That Scheme is way ahead of Python in this area I think has been recognized by relevant members of the Python community (comp.lnag.python not long ago). 4. Python, instead, has the wealth of "nutshells", "pocket guides", etc. Which are fine (I always have my Ptyhon in a Nuthsell and Python Pocket Reference nearby when writing Python). But I doubt these books really teach you basic computer science as the above do. They are of the applied kind (and here probably the only Lisp coutnerpart might be "Practical Common Lisp"). Why does all this matters (or at least matters to me, who am considering moving most of my programming from Python to Scheme and CL)? a) If the issue of teaching programming to a kid/adolescent arises, I'd definitely have a lot more resources, which also teach much more than just a language, if I choose Scheme. (And, no, I do not think a parenthesis is inherently more scary than a tab for someone who is new to both). b) I have no formal CS training; I am a biologist and statistician by training and have used Basic, C/C++, Pascal, Fortran, R (oh, and RPL, that minor language of the HP48 calc., which I used extensively for 18 months for writing lots of animal behavior recording programs). But once and for all, I'd like to learn some basic CS, while learning how to use a language. I have a strong feeling that, with the Scheme route, this will be fulfilled. Not with Python. (Sure, this is also fulfilled with Mozart/Oz and "Concepts and Techniques and Models of Comp. Progr.", but Mozart/Oz does not seem as ready for the types of projects I work on and there are speed issues). The first three chapters of SICP and the first four chapters of CTM so far have really been mind-expanding. None of the Python books I've read have felt anyway similar (Python has felt cozy, nice, easy to use; not eye opening). c) Now, if Scheme/CL were just "toy languages" we could dismiss all the above by saying "we are not talking about why kids learn XYZ, nor why CS ignorants like you prefer to be spoon fed basic CS concepts by learning language UVW". But of course, I think that neither Scheme nor CL are just toy languages. Just my 2 cents. Ramon From martin at v.loewis.de Mon Dec 18 06:35:32 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 18 Dec 2006 12:35:32 +0100 Subject: New os.path.exists() behavior - bug or feature? In-Reply-To: <1166401777.533652.208840@n67g2000cwd.googlegroups.com> References: <1166401777.533652.208840@n67g2000cwd.googlegroups.com> Message-ID: <45867D04.8010300@v.loewis.de> klappnase schrieb: > When I insert a floppy into A: os.path.exists('A:\\') will return True > on Python-2.5, too. > Does anyone know, is this inconsistent behavior a bug or a new feature? Neither, nor. In both cases, the operating system is asked, and gives this answer. However, in the Windows API, there is no "exists" function (nor is there on Unix); instead, exists is implemented by calling several underlying functions. The precise set of functions used did change between 2.4 and 2.5. It is quite difficult to investigate the precise nature of the change that leads to this change in observable behavior. If you think this is a bug, it would be best if you could also investigate a patch. > I also noticed that the Tix binaries are no longer present in 2.5, does > anyone know if it is > planned to remove them pemanently? That was a mistake, I'll add it back in 2.5.1. Regards, Martin From martin at v.loewis.de Fri Dec 15 18:58:56 2006 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 16 Dec 2006 00:58:56 +0100 Subject: No latin9 in Python? In-Reply-To: <458299D9.4010503@online.de> References: <457710EE.4090704@v.loewis.de> <458299D9.4010503@online.de> Message-ID: <458336c2$0$26013$9b622d9e@news.freenet.de> Christoph Zwerschke schrieb: > Shall I proceed writing such a patch? Shall I also add latin0 and l0 > which are other inofficial aliases? Sure, go ahead. I see no need for the latin0/l0 aliases, though: they predate the formal adoption of iso-8859-15, and should be phased out by now (I'm sure that somebody will provide an example of a software that still uses it, but I likely won't find that single example convincing). Regards, Martin From bj_666 at gmx.net Tue Dec 12 01:43:01 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Tue, 12 Dec 2006 07:43:01 +0100 Subject: namespace question References: <1165904406.053883.129610@l12g2000cwl.googlegroups.com> Message-ID: In <1165904406.053883.129610 at l12g2000cwl.googlegroups.com>, jm.suresh at no.spam.gmail.com wrote: > class Test: > a = 1 > b = 2 > c = 1+2 > > Now, all a,b and c would be directly visible to the user from the > instance of Test. I am looking for a way to make only c directly > visible from the instance. Simplest way: class Test: c = 3 :-) You know that `a`, `b` and `c` are class variables and not instance variables!? Ciao, Marc 'BlackJack' Rintsch From vivainio at gmail.com Wed Dec 20 05:18:26 2006 From: vivainio at gmail.com (Ville Vainio) Date: 20 Dec 2006 02:18:26 -0800 Subject: IPython 0.7.3 upgrade notes Message-ID: <1166609906.624854.9350@79g2000cws.googlegroups.com> Something I forgot to emphasize in the announcement, knowing that not everyone reads the release notes - if you are upgrading from a previous version of IPython, you must either: - Delete your ~/ipython (or ~/_ipython) directory OR - Run %upgrade once IPython starts. From python.list at tim.thechases.com Wed Dec 6 09:18:45 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 06 Dec 2006 08:18:45 -0600 Subject: Windows: get owner and group of a file In-Reply-To: <4tnvt4F14mmm6U1@mid.uni-berlin.de> References: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> <4tnvt4F14mmm6U1@mid.uni-berlin.de> Message-ID: <4576D145.2020805@tim.thechases.com> >> with ls -l on windows I get >> -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile > > Are you by any chance running cygwin? That comes with ls, but > windows doesn't. Another alternative might be mounting their Windows-formatted drive from within a *nix-like OS. These permissions are usually set via the /etc/fstab mounting options for the drive. I don't remember what the defaults are, as I have mine set up to take a forced set of uid/gid for users/groups specific to my system. Because at least FAT32 doesn't have this idea of groups (mapping to NTFS is an entirely different ball of wax), you can specify a default mask for everything or specify the directory mask separately from the file mask. man mount will give more details on such goods. -tkc From dhingra.mayank at gmail.com Tue Dec 19 01:39:30 2006 From: dhingra.mayank at gmail.com (Forced_Ambitions) Date: 18 Dec 2006 22:39:30 -0800 Subject: Script Error Message-ID: <1166510370.819303.94750@79g2000cws.googlegroups.com> Hi Guys, I am facing a problem with a script that i had written to automate opening a website and signing on to it. It was running fine for a long time but all of a sudden it has stopped progressing beyond opening the URL. I ran the code line by line on the pythonwin's IDE and it ran fine but when i execute the whole script it gives this error: Traceback (most recent call last): File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 307, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 631, in run exec cmd in globals, locals File "C:\Documents and Settings\Desktop\pi\Ressurection\Dec\19\CoE.py", line 4, in ? ie.SetTextBox(username,'txtUserId',0) File "cPAMIE.py", line 387, in SetTextBox doc = self._ie.Document.forms[frmName] File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 216, in __getitem__ return self._get_good_object_(self._enum_.__getitem__(index)) File "C:\Python24\Lib\site-packages\win32com\client\util.py", line 37, in __getitem__ return self.__GetIndex(index) File "C:\Python24\Lib\site-packages\win32com\client\util.py", line 56, in __GetIndex raise IndexError, "list index out of range" IndexError: list index out of range The code i was using is: import cPAMIE ie= cPAMIE.PAMIE() ie.Navigate ('URL') ie.SetTextBox(username,'txtUserId',0) ie.SetTextBox(pwd,'txtPassword',0) ie.ClickButton('btnSubmit',0) Any ideas as to why am i getting this error when running the code as a script Thanks in advance, Forced From __peter__ at web.de Fri Dec 15 09:04:54 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 Dec 2006 15:04:54 +0100 Subject: Problem comparing object graphs and trees References: <1166189934.686619.56720@16g2000cwy.googlegroups.com> Message-ID: raphael.marvie at gmail.com wrote: > > $ cat cmp.py > > class A: > def __init__(self, b): > self.b = b > def __cmp__(self, other): > return self.b == other.b > > class B: > pass > > if __name__ == '__main__': > b = B() > a1 = A(b) > a2 = A(b) > print a1 == a2 > print a1 == a1 > > $ python cmp.py > False > False > > > I swear I am not drunk, but why isn't a1 == a2 and worse why isn't a1 > == a1? Does someone have a clue and can explain to me this suprising > behavior? (python 2.4.3 on Ubuntu 6.06). __cmp__() must return 0 for equal objects: >>> 1 .__cmp__(0), 1 .__cmp__(1), 1 .__cmp__(2) (1, 0, -1) You might have a look at rich comparison before you proceed: >>> class A(object): ... def __init__(self, b): ... self.b = b ... def __eq__(self, other): ... return self.b == other.b ... >>> A(1) == A(1) True >>> A(1) == A(42) False Peter From JShrager at gmail.com Sun Dec 10 11:51:44 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 10 Dec 2006 08:51:44 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165715580.731398.131690@f1g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> Message-ID: <1165769504.098173.101860@j72g2000cwa.googlegroups.com> Paddy wrote: > Python is fun to use. > Easy to read. > Simple and powerful. > Easy to test. > Easy to maintain. > Fast. Very fast! Okay, I'm going to commit another rhetorical fallacy here called "Argument from Authority": I challenge anyone making psychological claims about language X (for any X) being easier to either read/learn/use than language Y (for any Y) to come up with any valid evidence whatever. Having a PhD in Cognitive Psychology (as well as two degrees in computer science) where my subject was how people learn to program (among other things), and having extensive experience in this field, I am almost certain that no such evidence exists (at least not for any real programming language). Now, like any good scientist, I could be wrong, but you'd have to convince me, and I very much doubt that you could. While I'm engaging in this particular fallacy, here's another instance: Since I'm probably (although I'm not certain) the only person in this thread who has made a significant amount of money on either of these languages (i.e., via the sale of a startup whose product was tens of thousands of lines of Lisp code, and some Tk GUI stuff), and knowing both Lisp and Python (although I'm certainly not a Python wizard), I am nearly certain that what we did in Lisp COULD NOT HAVE BEEN DONE IN PYTHON -- PERIOD. The reason has little to do with macros (although they were very helpful, of course, esp. in making Tcl look like a reasonable language so that we could use Tk); it has to do with speed, which has to do with compilers, which, as it turns out, has to do with macros. (See below.) Now, speaking as a scientist, permit me to make a small practical suggestion: Why not just figure out a way to simplify some brand of Python -- make parens (or whatever) optionally replace whitespace and line breaks as syntax -- and then add a simple macro facility -- macros are actually a very simple extension if you have homogenous syntax, homogenizing your syntax to the point where macros are possible is the hard part -- and just see what happens. One of two general things are likely to happen: Either people will not use them, and they will languish and die, and then at least you can say; "Been there, done that" to the Lisp community. Or, more likely, the some subset of the Python community will get it, and will figure out how useful they are, although it might take some time. And then you might find yourself with a wonderful new tool. You might even get a compiler out of the deal, at a pretty low cost, too! If you get macros, and get a compiler, I'm pretty sure that you will have no problem winning over the Lisp community, who would LOVE to have your extensive libraries, and that you will probably be able to maintain and improve your flagging position wrt Ruby (which, according to Matz, is more-or-less just Lisp w/o macros.) I'm not saying that this is going to be an easy or quick experiment, but it's one that I, and I think most Lispers, would both like to see happen, and would benefit from! Moreover, I dare say that some of us in the Lisp community would love to HELP -- at least I would, and I'm guessing that others would as well. (Unless you guys get a compiler too, you'll always just be a scripting language, but compilers are GREATLY facilitated by having a macro facility because (at first blush) all you need to do is to macro-expand down to something you know how to turn into code. This isn't the only, nor perhaps the best way to get a compiler, but it's a step in that direction. Later on you can learn the other great features offered by homogeneous syntax, like being able to write code walkers, which help improve over the "first blush" compiler. Soon enough, I predict, you'll be so far past us and Ruby that...well, even Kenny with jump on board! :-) From udodenko at users.sourceforge.net Sun Dec 10 12:23:44 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sun, 10 Dec 2006 19:23:44 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> Message-ID: <457c42a3$0$49196$14726298@news.sunsite.dk> (message (Hello 'Paul) (you :wrote :on '(10 Dec 2006 04:36:43 -0800)) ( ??>> so, it's very close to writting new interpreter -- but it's order of ??>> magnitude easier to write this interpreter via macros than from ??>> scratch, most other language constructs can be reused. PR> But now you've got an interpreter and you no longer have that Lisp PR> compiler. why do you think so? if you have C compiler that translates C to assembly, and then compiles assembly to machine language -- that's not C compiler, not asm compiler, or what? yes, possibly it would be sub-optimal, but at least it will work. and normally there would be no big performance penalties. ??>> there is a chapter about continuations in Paul Graham's "On Lisp". ??>> ??>> "Common Lisp doesn't provide call/cc, but with a little extra effort ??>> we can do the same things as we can in Scheme. This section shows how ??>> to use macros to build continuations in Common Lisp programs." PR> I think he's mistaken about being able to implement call/cc in full PR> generality with CL macros in any reasonable way. why do you think so? you know some case that does not work with call/cc? i was programming quite significant working system with call/cc in Common Lisp. and although there were some glitches, it was doing quite well. PR> But it might be possible to implement enough to do something like PR> Python generators using lexical closures that one re-enters through PR> some kind of cond statement selecting the yield point to be continued PR> from. why are you theoretizing -- i've showed working real example of generators! just get SBCL and ARNESI, load it, and then use call/cc as i've shown in example. that's real generators. there's no need for any cond -- you can save state as current-continuation. if you don't understand how it works, run macroexpand -- it's quite simple thing. you can find full defgenerator code here http://www.cl-user.net/asp/Mi4$4/sdataQvxM$sStWNjUDQ3t9G8X8yBX8yBXnMq=/sdataQu3F$sSHnB== you can find also other implementations of defgenerator's -- but with ARNESI's CPS call/cc works with LOOP (that's actually surprising -- since loop uses TAGBODY/GO -- maybe their code walker mutates TAGBODY making it functional-style, or something like that). ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From Benjamin.Barker at gmail.com Fri Dec 29 06:23:04 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 03:23:04 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> Message-ID: <1167391384.797523.37150@i12g2000cwa.googlegroups.com> Well that's odd... If I place the exact same Insert statement elswhere in the program it works as intended. That would suggest it is never being run in its old position, but the statements either side of it are printing... Ben wrote: > I don't know whether anyone can help, but I have an odd problem. I have > a PSP (Spyce) script that makes many calls to populate a database. They > all work without any problem except for one statement. > > I first connect to the database... > > self.con = MySQLdb.connect(user=username, passwd =password) > self.cursor = self.con.cursor() > self.cursor.execute("SET max_error_count=0") > > All the neccesary tables are created... > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > self.cursor.execute("USE "+name) > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > varchar(20)) > > Then I execute many insert statements in various different loops on > various tables, all of which are fine, and result in multiple table > entries. The following one is executed many times also. and seems > identical to the rest. The print statements output to the browser > window, and appear repeatedly, so the query must be being called > repeatedly also: > > print "

SQL query executing

" > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > ','c','2','e','f','g')") > print "

SQL query executed

" > > I have, for debugging, set "i" up as a counter variable. > > No errors are given, but the only entry to appear in the final database > is that from the final execution of the INSERT statement (the last > value of i) > > I suspect that this is to vague for anyone to be able to help, but if > anyone has any ideas I'd be really grateful :-) > > It occured to me that if I could access the mysql query log that might > help, but I was unsure how to enable logging for MysQL with python. > > Cheers, > > Ben From dingbat at codesmiths.com Sat Dec 2 07:47:49 2006 From: dingbat at codesmiths.com (Andy Dingley) Date: 2 Dec 2006 04:47:49 -0800 Subject: rdf, xmp In-Reply-To: <457153cd$0$13323$426a34cc@news.free.fr> References: <457153cd$0$13323$426a34cc@news.free.fr> Message-ID: <1165063669.646421.219890@16g2000cwy.googlegroups.com> Imbaud Pierre wrote: > I have to add access to some XMP data to an existing python > application. > XMP is built on RDF, RDF is built on XML. RDF is _NOT_ built on top of XML. Thinking that it is causes a lot of trouble in the architecture of big RDF projects. RDF is a data model, not a serialisation. The data model is also a graph (more than XML can cope with) and can span multiple documents. It's only RDF/XML that's the serialisation of RDF into XML and good architectures start from thinking about the RDF data model, not this RDF/XML serialisation. As to RDF handling, then the usual toolset is Jena (in Java) and Redland has a Python binding although Redland is fairly aged now. I'm unfamiliar with XMP and won't have a chance to look at it until Monday. However if XMP is strongly "XML like" despite claiming to be RDF, then you might find that handling a pure XMP problem is quite easily done with XML tools. Famously RDF/XML is unprocessable with XSLT if it's sophisticated, but quite easy if it's restricted to only a simple XML-like RDF model. XMP could well be similar. From Roberto.Bonvallet at cern.ch Wed Dec 13 09:11:43 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Wed, 13 Dec 2006 14:11:43 +0000 (UTC) Subject: newbie - HTML character codes References: <1166018453.981657.33780@79g2000cws.googlegroups.com> Message-ID: ardief wrote: [...] > And I want the HTML char codes to turn into their equivalent plain > text. I've looked at the newsgroup archives, the cookbook, the web in > general and can't manage to sort it out. I thought doing something like > this - > > file = open('filename', 'r') It's not a good idea to use 'file' as a variable name, since you are shadowing the builtin type of the same name. > ofile = open('otherfile', 'w') > > done = 0 > > while not done: > line = file.readline() > if 'THE END' in line: > done = 1 > elif '—' in line: > line.replace('—', '--') The replace method doesn't modify the 'line' string, it returns a new string. > ofile.write(line) > else: > ofile.write(line) This should work (untested): infile = open('filename', 'r') outfile = open('otherfile', 'w') for line in infile: outfile.write(line.replace('—', '--')) But I think the best approach is to use a existing aplication or library that solves the problem. recode(1) can easily convert to and from HTML entities: recode html..utf-8 filename Best regards. -- Roberto Bonvallet From mystilleef at gmail.com Wed Dec 13 01:02:37 2006 From: mystilleef at gmail.com (mystilleef at gmail.com) Date: 12 Dec 2006 22:02:37 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165971298.617221.59450@n67g2000cwd.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4579c4f4$0$49201$14726298@news.sunsite.dk> <1165971298.617221.59450@n67g2000cwd.googlegroups.com> Message-ID: <1165989757.181057.104200@j44g2000cwa.googlegroups.com> Paddy wrote: > Robert Uhl wrote: > > > Steven D'Aprano writes: > > > > > > Speaking as somebody who programmed in FORTH for a while, that doesn't > > > impress me much. Prefix/postfix notation is, generally speaking, more > > > of a pain in the rear end than it is worth, even if it saves you a > > > tiny bit of thought when pasting code. > > > > Of course, you use prefix notation all the time in Python: > > > > for x in range(0,len(y)): > > dosomething(x) > > In Python, most containers are directly iterable so we are much more > likely to arrange our program to use: > for a in y: > dosomethingwith(a) > > -Paddy. Or the more succinct Python (FP) construct: map(dosomething, y) From hanwen at xs4all.nl Wed Dec 20 05:17:39 2006 From: hanwen at xs4all.nl (Han-Wen Nienhuys) Date: Wed, 20 Dec 2006 11:17:39 +0100 Subject: cross-compiling python: reviewers needed Message-ID: <45890db7$0$321$e4fe514c@news.xs4all.nl> Hello, I have a small patch for Python SVN that makes it possible to cross-compile python on Unix to various other Unix targets. I have successfully built a binary for FreeBSD on Linux. The patch is available at https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1597850&group_id=5470 (file cross.patch) but it awaits further review. I'm looking for people willing to try this out, and give further review to the patch, so it may be applied to SVN. All you need is a bit of time, and experience in cross-compiling. From jonathan.beckett at gmail.com Thu Dec 28 11:40:02 2006 From: jonathan.beckett at gmail.com (jonathan.beckett) Date: 28 Dec 2006 08:40:02 -0800 Subject: Some basic newbie questions... Message-ID: <1167324002.516960.319870@79g2000cws.googlegroups.com> Hi all, While working on support at work, I have been picking away at Python - because I think it could be a valuable scripting tool for building utilities from. I have been reading the python.org tutorials, and playing around with some basic code, but I have ended up with a few questions that probably have straightforward answers - any quick explanations or assistance would be fantastic... Question 1... Given the code below, why does the count method return what it does? How *should* you call the count method? a = [] a.append(1) print a.count Question 2... What is the correct way of looping through a list object in a class via a method of it? (I've hit all sorts of errors picking away at this, and none of the tutorials I've found so far cover it very well) - apologies for the arbitrary class - it's the first example I thought up... class Gun: Shells = 10 class Battleship: Gun1 = Gun() Gun2 = Gun() Guns = [Gun1,Gun2] def getShellsLeft(self): NumShells = 0 for aGun in Guns: NumShells = NumShells + aGun.Shells return NumShells Bizmark = Battleship() print Bizmark.getShellsLeft() In the above code, I guess I'm just asking for the *correct* way to do these simple kinds of things... From kernel1983 at gmail.com Tue Dec 12 22:53:45 2006 From: kernel1983 at gmail.com (kernel1983) Date: 12 Dec 2006 19:53:45 -0800 Subject: how can i write a hello world in chinese with python Message-ID: <1165982024.978824.146920@n67g2000cwd.googlegroups.com> I'm try to build a bundle on OS X, so I write a simple python script for a test: #!/usr/bin/env python import EasyDialogs EasyDialogs.Message("Hello,Mac!") This runs OK,but when I try to replace "Hello,Mac!" with chinese, it can't be display rightly. Then I tried some way else: #!/usr/bin/env python import EasyDialogs EasyDialogs.Message("\xe4\xb8\xad") It doesn't work! As I know mac is unicode based,how can I display chinese on the screen? From rr_newsgroup_deleted at gmx.net Mon Dec 11 04:38:56 2006 From: rr_newsgroup_deleted at gmx.net (Roland Rickborn) Date: 11 Dec 2006 01:38:56 -0800 Subject: wxPython: Icon aus base64 decoded Image Message-ID: <1165829936.372334.53740@79g2000cws.googlegroups.com> Hallo zusammen, in meine Anwendung ist ein Bild eingebettet und oben in der Leiste soll ein Icon erscheinen. Ausserdem will ich nur _eine_ Datei ausgeben, also ohne zus?rtliche Bild-Dateien etc. Dazu habe ich das Bild in base64 codiert und als String im Skript gespeichert, siehe unten. Beim Ausf?hren des Skripts wird dieser String decodiert, in ein Image umgewandelt und als Bitmap dargestellt. Funzt prima. # Base64 codiertes Bild, einmalig ausserhalb des Skripts import base64 file = open('smallPic.png',"rb") pic = file.read() pic_b64 = pic.encode("base64") # ergibt einen String wie """'iVBORw0KGgoAAAATkSuQmCC\n'""" # Danach im Skript: self.staticImage = wx.ImageFromStream(StringIO(pic_b64.decode("base64"))) self.staticBitmap = wx.StaticBitmap(bitmap=wx.BitmapFromImage(self.staticImage, wx.BITMAP_TYPE_PNG), name='staticBitmap3', parent=self.panel1, pos=wx.Point(8, 96), size=wx.Size(168, 72), style=0) Wie gesagt, funkzt prima! Und jetzt das Icon: # Base64 codiertes Bild, einmalig ausserhalb des Skripts import base64 file = open('smallIcon.ico',"rb") ico = file.read() ico_b64 = ico.encode("base64") # ergibt einen String wie """'==123445342gsgadfgdghsfhsdhxfghxfghTRG>dfg\n'""" # Danach im Skript: icon = base64.b64decode(ico_b64) self.SetIcon(wx.Icon(icon, wx.BITMAP_TYPE_ICO)) --> Fehler beim Start der Anwendung: "Failed to load icom from the file" Wo ist der Fehler und was muss ich machen, damit das Icon angezeigt wird? Besten Dank und sch?ne Gr?sse, Roland -- E-Mail-Adresse ist reply-f?hig, wird aber nicht gelesen. Besser: r_2 bei Ge Em Ix oder hier in der NG From http Sun Dec 10 03:08:33 2006 From: http (Paul Rubin) Date: 10 Dec 2006 00:08:33 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <457bb4cf$0$8756$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <7xbqmcgola.fsf@ruckus.brouhaha.com> Jon Harrop writes: > >> The nice thing in Lisp would now be to save a lambda with the macro. > >> In Python one would fill the name space with throw away functions that > >> get called only one time. > > That is a deficiency of Python that doesn't exist in modern FPLs like OCaml, > SML, Haskell, F#... Nothing stops you from re-using the same internal function name in your Python code, like you might use "i" as a throwaway loop index in several places in the same function. It's just like in Scheme, the function is a first class object like an integer. From uymqlp502 at sneakemail.com Mon Dec 4 12:44:12 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 4 Dec 2006 09:44:12 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> Message-ID: <1165254251.948245.41280@80g2000cwy.googlegroups.com> Carsten Haese wrote: > You may not have meant this to be rude, but it does come off as rude and > arrogant, and I'll explain to you why: In your first post you stated > that the feature seems like a no-brainer to you. That implies to the > reader that you might have the necessary skill to implement the feature > yourself, hence Robert's suggestion to submit a patch was, in the > context you gave yourself, neither unreasonable nor silly. I can see how > your calling a reasonable suggestion by a valuable community member > "silly" would be construed as rude and arrogant. > > Hope this helps, OK, fair enough. I shouldn't have called his suggestion "silly." When I replied to him I honestly thought it was, but in retrospect I now see that it wasn't. My mistake. By the way, I consider myself a pretty good Python programmer, but I haven't used C in many years, and I have no desire to ever use it -- or even see it -- again. That's one of the reasons I use Python in the first place. (I am fortunate enough to get to choose the language I use.) I think it's unfortunate that Python is written in C, but I won't get into that now. (And yes, I am aware of Jython, but I don't care much for Java either.) From rampeters at gmail.com Wed Dec 6 23:03:31 2006 From: rampeters at gmail.com (johnny) Date: 6 Dec 2006 20:03:31 -0800 Subject: newb: How to call one modue from other In-Reply-To: References: <1165450007.504080.327490@80g2000cwy.googlegroups.com> <1165458032.135595.321240@f1g2000cwa.googlegroups.com> Message-ID: <1165464211.416352.26540@80g2000cwy.googlegroups.com> Gabriel Genellina wrote: > Reading the Python Tutorial helps a lot. > I did read "Dive Into Python", one week ago. It's a good book, but it didn't cover this kind of situation. From http Sun Dec 10 04:35:34 2006 From: http (Paul Rubin) Date: 10 Dec 2006 01:35:34 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165737791.744375.190080@l12g2000cwl.googlegroups.com> <7x7ix0godv.fsf@ruckus.brouhaha.com> <1165741455.889300.327100@j44g2000cwa.googlegroups.com> Message-ID: <7xwt50qejd.fsf@ruckus.brouhaha.com> "Wolfram Fenske" writes: > Yes, I wrote about it in another post. It was introduced in Python > 2.5. And if it hadn't been I'd still have to write code like this. You could do something with decorators that's not too bad. You'd end up writing: @withConnection def some_func(): do_whatever_stuff () From mahs at telcopartners.com Tue Dec 19 11:53:38 2006 From: mahs at telcopartners.com (Michael Spencer) Date: Tue, 19 Dec 2006 10:53:38 -0600 Subject: python poetry? In-Reply-To: <1166524579.271548.32560@a3g2000cwd.googlegroups.com> References: <1166524579.271548.32560@a3g2000cwd.googlegroups.com> Message-ID: BartlebyScrivener wrote: > Python pseudo code limericks anywhere? I wrote the following in response to Steve Holden's limerick challenge a couple of years ago: # run me or voice the alphanumeric tokens from itertools import repeat for feet in [3,3,2,2,3]: print " ".join("DA-DA-DUM" for dummy in [None] for foot in repeat("metric", feet)) Michael From fredrik at pythonware.com Sun Dec 10 11:07:34 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 10 Dec 2006 17:07:34 +0100 Subject: problem using lambdas for deferred callbacks In-Reply-To: <1165764662.462927.147010@79g2000cws.googlegroups.com> References: <1165764662.462927.147010@79g2000cws.googlegroups.com> Message-ID: edd at nunswithguns.net wrote: > I was hoping that the following code would print "Hello, world!", one > character per line. But instead it prints an exclamation mark for each > character of the string. I'm sure it's no coincidence that the last > value of c is '!', but beyond that I don't understand what's happening. > > # --- begin code --- > def callback(arg): > print arg > > funcs = [] > for c in 'Hello, world!': > funcs.append(lambda: callback(c)) the "lambda" introduces a new function scope, and since the "c" variable isn't defined in there, it's bound to the variable with the same name from the outer scope. the problem here is that it's bound to the *variable*, not the object, so *all* callbacks will use the same value. there are several ways to bind to an object value instead; the easiest in this case is to use a default argument value: for c in 'Hello, world!': funcs.append(lambda c=c: callback(c)) this turns the inner "c" variable to an argument that defaults to the value of the outer "c" at the time the lambda was created. From gokkog at yahoo.com Wed Dec 27 20:55:42 2006 From: gokkog at yahoo.com (gokkog at yahoo.com) Date: 27 Dec 2006 17:55:42 -0800 Subject: Help with small program In-Reply-To: <4v95b8F1b5csnU1@mid.individual.net> References: <1166966360.384179.101400@48g2000cwx.googlegroups.com> <1166979265.284345.173840@48g2000cwx.googlegroups.com> <4v94fuF1avmp3U1@mid.individual.net> <4v95b8F1b5csnU1@mid.individual.net> Message-ID: <1167270942.421817.280490@n51g2000cwc.googlegroups.com> "Paul Watson ??? Interesting impl in Python! I am wondering what if the requirement is to find the minimum number of coins which added to the "fin" sum... From researchbase at gmail.com Sun Dec 10 12:36:36 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Sun, 10 Dec 2006 23:06:36 +0530 Subject: need guidance on sending emails with attachment with python. Message-ID: hello, I am a bit confused. I want to make a program that will take some data from a database and make a string of text. and send it to the respective email id of a person. next I also want to send an attachment of a photo along with the email. I will be required to make this program run on windows xp. can some one guide me as to how I can achieve this? what I will need on windows to send emails? I believe yahoo, gmail, rediff and msn supports pop3 and smtp? correct me if I am wrong on this. secondly what library is used on windows to do this? I know there must be python libraries to do this, but apart from that I don't know what all I will need on my windows machine to send emails to mostly yahoo, gmail and msn. Please give me some idea about it. Krishnakant. From larry.bates at websafe.com Tue Dec 19 09:49:54 2006 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 19 Dec 2006 08:49:54 -0600 Subject: update attribute - (newbie) In-Reply-To: <1166538800.915433.38680@79g2000cws.googlegroups.com> References: <1166538800.915433.38680@79g2000cws.googlegroups.com> Message-ID: <4587FC12.2090806@websafe.com> Bruce wrote: >>>> class A: > ... def __init__(self): > ... self.t = 4 > ... self.p = self._get_p() > ... def _get_p(self): > ... return self.t > ... >>>> a = A() >>>> a.p > 4 >>>> a.t += 7 >>>> a.p > 4 > > I would like to have it that when I ask for p, method _get_p is always > called so that attribute can be updated. How can I have this > functionality here? thanks > Something like this? class A: def __init__(self): self.t=4 return def __getattr__(self, name): if name == 'p': return self.t else: return self.__dict__[name] if __name__ == "__main__": a=A() print a.p a.t+=7 print a.p From webraviteja at gmail.com Mon Dec 18 01:51:51 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 17 Dec 2006 22:51:51 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165834892.338714.34850@16g2000cwy.googlegroups.com> Message-ID: <1166424711.728147.259830@t46g2000cwa.googlegroups.com> Jean-Paul Calderone wrote: > On 11 Dec 2006 03:01:32 -0800, Ravi Teja wrote: > >Timofei Shatrov wrote: > > > > [snip] > > > >Of course, doctest is hardly the ultimate testing solution. But it does > >an admirable job for many cases where you don't need to setup elaborate > >tests. > > > >> It's not surprising that no one uses this stuff for serious work. > > > >I have seen enough libraries that use doctest. Zope, Twisted and Paste > >are some of the popular Python projects in that use it. Epydoc supports > >it as well. > > Just as a factual correction, Twisted does not use doctests. > > Jean-Paul You are right. I did a quick search on my Python Lib folder for that post to list some well known projects. Twisted does have some doctests in there but does not use them for actual testing (apparently, only to check for doctest support). Ravi Teja. From bj_666 at gmx.net Fri Dec 8 10:54:50 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Fri, 08 Dec 2006 16:54:50 +0100 Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> <1165518199.729518.112450@79g2000cws.googlegroups.com> Message-ID: In , Daniel Dittmar wrote: > John Machin wrote: >> No it doesn't look wrong to anyone who has read the docs on >> sys.modules. > > My point was really that there is no obvious implementation for 'in' on > dictionaries, so it should have been left out. And that GvR thought so > for quite some time as well (until he got mixed up with a crowd of ex > C++ programmers). Maybe there's no obvious implementation for ``in`` and dictionaries but there is the semantics of ``in`` and iterables. Dictionaries are iterable so it's clearly defined what ``'answer' in {'answer': 42}`` should return. In [84]: class A: ....: def __iter__(self): ....: return iter((1,2,3)) ....: In [85]: a = A() In [86]: 2 in a Out[86]: True In [87]: 5 in a Out[87]: False If ``in`` shouldn't work with dictionaries, either `__contains__()` must be implemented to throw an exception or dictionaries shouldn't be iterable. Ciao, Marc 'BlackJack' Rintsch From tiedon_jano at hotmail.com Wed Dec 13 10:12:02 2006 From: tiedon_jano at hotmail.com (Jussi Salmela) Date: Wed, 13 Dec 2006 15:12:02 GMT Subject: not a big deal or anything, but, curiously: In-Reply-To: References: <5c1d2d910612122214w22220f3fk6c5acfd1cfca7d6b@mail.gmail.com> Message-ID: <6LUfh.178$_z6.82@read3.inet.fi> Tim Peters kirjoitti: > [Simon Schuster] >> following this tutorial, > > Which tutorial? He's reading this tutorial which he was already advised not to do: =========================================== =========================================== =========================================== Simon Schuster wrote: > > I'm new to python, and almost new to programming in general. I'm at > > http://www.pasteur.fr/formation/infobio/python/ch04.html in that > > tutorial, and my 'count' function (if it's called a function?) isn't > > working suddenly. > > >>>> > >>> x = "fljshfjh" >>>> > >>> x > > 'fljshfjh' >>>> > >>> count(x, 'h') > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'count' is not defined > > > > I'm not sure what changed, because it used to work. anyhow thanks a lot! > > Probably because you omiitted the line from string import * However IMHO your use of a tutorial which: (1) introduces "from some_module import *" as though it is the normal way of doing things From chapter 1: """ Some magical stuff, that will be explained later: >>> from string import * """ That's *bad* magic (2) is still using (outdated) functions in the string module instead of teaching string methods should be discontinued immediately. You may wish to have a look at some of the /other/ tutorials mentioned on this page: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers HTH, John =========================================== =========================================== =========================================== > >> I copied and pasted: >> >> from string import * >> >> cds = """atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaaa >> tttcgggtgccgacctgacgcgcccgttaagcgataatcagtttgaacagctttaccatgcggtg >> ctgcgccatcaggtggtgtttctacgcgatcaagctattacgccgcagcagcaacgcgcgctggc >> ccagcgttttggcgaattgcatattcaccctgtttacccgcatgccgaaggggttgacgagatca >> tcgtgctggatacccataacgataatccgccagataacgacaactggcataccgatgtgacattt >> attgaaacgccacccgcaggggcgattctggcagctaaagagttaccttcgaccggcggtgatac >> gctctggaccagcggtattgcggcctatgaggcgctctctgttcccttccgccagctgctgagtg >> ggctgcgtgcggagcatgatttccgtaaatcgttcccggaatacaaataccgcaaaaccgaggag >> gaacatcaacgctggcgcgaggcggtcgcgaaaaacccgccgttgctacatccggtggtgcgaac >> gcatccggtgagcggtaaacaggcgctgtttgtgaatgaaggctttactacgcgaattgttgatg >> tgagcgagaaagagagcgaagccttgttaagttttttgtttgcccatatcaccaaaccggagttt >> caggtgcgctggcgctggcaaccaaatgatattgcgatttgggataaccgcgtgacccagcacta >> tgccaatgccgattacctgccacagcgacggataatgcatcgggcgacgatccttggggataaac >> cgttttatcgggcggggtaa""".replace("\n","") >> >> gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds) >> >> print gc >> >> -fin- >> >> which should yield: 0.54460093896713613.. >> >> but when I ran it I got: 0.544600938967 >> >> looking now I see it's truncating after a certain number of decimal >> places. any ideas why? > > Read the Python Tutorial appendix on floating-point issues: > > http://docs.python.org/tut/node16.html > > As it says, str(a_float) rounds to 12 significant digits, and > repr(a_float) to 17. The `print` statement implicitly applies str() > to each item it prints. Cheers, Jussi Salmela From lutz at rmi.net Wed Dec 13 21:23:53 2006 From: lutz at rmi.net (Mark Lutz) Date: 13 Dec 2006 18:23:53 -0800 Subject: Python training in Colorado, January 2007 Message-ID: <1166063033.043627.176470@f1g2000cwa.googlegroups.com> Python author and trainer Mark Lutz will be teaching another 3-day Python class at a conference center in Longmont, Colorado, on January 23-25, 2007. This is a public training session open to individual enrollments, and covers the same topics as the 3-day onsite sessions that Mark teaches, with hands-on lab work. For more information on this, and our other 2007 public classes, please visit these web pages: http://home.earthlink.net/~python-training/longmont-public-classes.htm http://home.earthlink.net/~python-training/public_classes.html Thanks for your interest. --Python Training Services, Inc. From http Tue Dec 12 19:48:31 2006 From: http (Paul Rubin) Date: 12 Dec 2006 16:48:31 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> <7xodqczf1h.fsf@ruckus.brouhaha.com> <7xk60zjl1e.fsf@ruckus.brouhaha.com> <7xk60x7wka.fsf@ruckus.brouhaha.com> <7x64chuig6.fsf@ruckus.brouhaha.com> Message-ID: <7x1wn4vcww.fsf@ruckus.brouhaha.com> jayessay writes: > You're mistaken, I'm not forgetting this. And despite this being > true, CL added several "new" things that (again through actual > experience) were deemed sufficiently understood to add (CLOS, > conditions, and such). I thought CL's condition system was similar to Maclisp or at least the Lisp machine. > > mistakes from the past. Scheme went somewhat further than CL at > > cleaning things up, > > But, Scheme was before CL (and indeed CL took some things from > Scheme). Of course Scheme too has continued to evolve. But Scheme was able to depart from earlier Lisps more than CL was, because it made no attempt at backwards compatibility. For example, its designers chose to make it a Lisp-1 (not saying that's better, just incompatibly different). CL's designers did really not have that choice. > > and Scheme's aficionados think CL is a clumsy old kludge as a > > result > > Well, if you lower into "flamewar" talk, CL aficionados have similar > things to say about Scheme. But that is just irrelevant silly flamage. I've never heard CL aficionados say that about Scheme. I've heard them say that it's an elegant jewel that's too academic and constricted for practical large program development, which is a completely different criticism. > > But it's still a Lisp dialect. The ML's, for their part, > > were able to start from scratch. > > There are Lisps like this as well (EuLisp sort of and now Arc). But > really, how is "starting from scratch" really an advantage? Starting from scratch means being able to make choices fundamentally incompatible with the old language. Consider ML's type system--ML is statically typed throughout and relies on type inference pervasively. Yes you could make it look like Lisp by replacing the surface syntax with parentheses, but it's really different under the skin. Again not necessarily better, but made choices unavailable to someone trying to incrementally evolve some Lisp dialect. > Especially from a _practical_ point of view. Topic started with how new ideas enter a language. Practicality is not of so much concern. > Admittedly, I used to think the same, but now think that is just > wrong. Again, the example of The Calculus and such come to mind... Not sure what you mean about calculus. From nmm1 at cus.cam.ac.uk Thu Dec 14 11:36:26 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 14 Dec 2006 16:36:26 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: In article , Carsten Haese writes: |> > |> |> > |> so where would you put such an "index" implementation so it would work on |> > |> ANY data structure that can be subscripted by an integer value ? |> > |> > In the same place you put the subscription method, clearly. |> |> Clearly not, because that would force *every* object that implements |> __getitem__ to also implement index. Well, yes, but why is that impossible? You may feel that it is undesirable, but that is not the same at all. And there is no problem with providing a generic default version of index that just does a linear search, so only objects that wanted to optimise index would need to provide anything. |> And to verify the truth of your assertion that index makes sense for |> "ANY data structure that can be subscripted by an integer value", |> consider the following theoretical but conceivable examples: |> |> 1) A mailbox object that returns the i-th message on subscripting. |> 2) A scroll cursor in a database that returns the i-th row of the result |> set. |> 3) A prime number generator that calculates the i-th prime number. |> |> Does .index() make sense for them? How would it be implemented? You are correct that it does also need some sort of a concept of equivalence, but a language like Python always has one - the 'is' operator, if nothing else. index makes sense for all of the above examples, and the implementation couls be based on 'is' for (1) and (2), and on value for (3). And, as mentioned above, it could be implemented as a linear search, if nothing else works. Mathematically, the counterexamples are only lists of entities where there is no definable concept of equivalence between entities, and Python has no such entities as far as I know. Guido's response is fine - we didn't because we didn't think that it was worth doing. One can dissent, but it makes perfect sense. Regards, Nick Maclaren. From mlh496 at gmail.com Tue Dec 19 16:29:44 2006 From: mlh496 at gmail.com (Michael) Date: 19 Dec 2006 13:29:44 -0800 Subject: Page layouts in mod_python? Message-ID: <1166563784.948936.253950@80g2000cwy.googlegroups.com> Hey everyone, Is it possible to automatically insert headers/footers using mod_python? I will be not be using PSP's, so I cannot use the PSP/include solution. Furthermore, the header will be dynamic; it won't be a static HTML page. In short, I've been looking for a page layout facility using mod_python. (Similar to the layout capability in Ruby on Rails.) Thank you in advance, -Michael From yuxi at ece.gatech.edu Tue Dec 12 03:46:04 2006 From: yuxi at ece.gatech.edu (Yu-Xi Lim) Date: Tue, 12 Dec 2006 03:46:04 -0500 Subject: Tarfile .bz2 In-Reply-To: <1165887178.775792.142820@80g2000cwy.googlegroups.com> References: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> <1165887178.775792.142820@80g2000cwy.googlegroups.com> Message-ID: Jordan wrote: > So that would explain why a tar.bz2 archive can't be appended to > wouldn't it... And also explain why winrar was so slow to open it (not > something I mentioned before, but definitely noticed). I had wondered > what it was that made bz2 so much better at compression than zip and > rar. Not really on topic anymore but what's the method for tar.gz? And > even more off the topic, does anyone know a good lossless compression > method for images (mainly .jpg and .png)? You can get the same effect from RAR and other formats (ACE, 7z) by using the "Solid Archive" or similar option. Ideally, you'd be compressing lots of similar files for this to be effective. The actual compression ratios of RAR and bz2 can be pretty similar when done this way. From walter at livinglogic.de Thu Dec 21 07:12:08 2006 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Thu, 21 Dec 2006 13:12:08 +0100 Subject: urllib.unquote and unicode In-Reply-To: <4588507E.20602@v.loewis.de> References: <1166497058.109088.53120@80g2000cwy.googlegroups.com> <1166504578.169707.154900@n67g2000cwd.googlegroups.com> <4588507E.20602@v.loewis.de> Message-ID: <458A7A18.9070301@livinglogic.de> Martin v. L?wis wrote: > Duncan Booth schrieb: >> The way that uri encoding is supposed to work is that first the input >> string in unicode is encoded to UTF-8 and then each byte which is not in >> the permitted range for characters is encoded as % followed by two hex >> characters. > > Can you back up this claim ("is supposed to work") by reference to > a specification (ideally, chapter and verse)? > > In URIs, it is entirely unspecified what the encoding is of non-ASCII > characters, and whether % escapes denote characters in the first place. http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1 Servus, Walter From gigs at hi.t-com.hr Thu Dec 14 14:19:17 2006 From: gigs at hi.t-com.hr (Gigs_) Date: Thu, 14 Dec 2006 20:19:17 +0100 Subject: beginner, thread & else Message-ID: can someone explain me this code: ---------------------------------- import thread stdoutmutex = thread.allocate_lock() exitmutexes = [0] * 10 def counter(myId, count): for i in range(count): stdoutmutex.acquire() print '[%s] => %s' % (myId, i) stdoutmutex.release() exitmutexes[myId] = 1 # signal main thread for i in range(10): thread.start_new(counter, (i, 100)) while 0 in exitmutexes: pass print 'Main thread exiting.' ----------------------------------- thread.start_new(counter, (i, 100)) is running counter function. Is counter function and while statement executed in same time (other things i understand, but can't get into this)? thanks From arkanes at gmail.com Wed Dec 13 10:52:04 2006 From: arkanes at gmail.com (Chris Mellon) Date: Wed, 13 Dec 2006 09:52:04 -0600 Subject: Conditional iteration In-Reply-To: <7xwt4vn6gk.fsf@ruckus.brouhaha.com> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> Message-ID: <4866bea60612130752p62d00009h30da737d57adc83b@mail.gmail.com> On 13 Dec 2006 07:47:23 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > at writes: > > I have a lot times the following code: > > > > for x in [-2, -1, 0, 1, 2, 3, 4]: > > if x > 0: > > ... more code... > > Use: > > for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x > 0): > ... more code ... > -- or filter: from itertools import ifilter for x in ifilter(lambda x: x > 0, [-2, -1, 0, 1, 2, 3, 4]): ...more code... > http://mail.python.org/mailman/listinfo/python-list > From kent at kentsjohnson.com Fri Dec 1 12:27:21 2006 From: kent at kentsjohnson.com (Kent Johnson) Date: Fri, 01 Dec 2006 17:27:21 GMT Subject: Functions, callable objects, and bound/unbound methods In-Reply-To: References: Message-ID: <457065F9.3040903@kentsjohnson.com> Ron Garret wrote: > The reason I want to do this is that I want to implement a trace > facility that traces only specific class methods. I want to say: > > trace(c1.m1) > > and have c1.m1 be replaced with a wrapper that prints debugging info > before actually calling the old value of m1. The reason I want that to > be an instance of a callable class instead of a function is that I need > a place to store the old value of the method so I can restore it, and I > don't want to start building a global data structure because that gets > horribly ugly, and a callable class is the Right Thing -- if there's a > way to actually make it work. If the only reason for a callable class is to save a single value (the original function), you could instead store it as an attribute of the wrapper function. Kent From deets at nospam.web.de Sun Dec 17 06:33:47 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 17 Dec 2006 12:33:47 +0100 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: <4uko8rF16stamU1@mid.uni-berlin.de> > > Most values tend to work, but only because the SQL string representation > happens to be the same as the Python representation. That may not apply to > some float values, bool, perhaps others. I had hoped the tools would have > solved those problems so I don't have to. In typed languages (Java, C#) > those things tend to just work. Not true. There might be frameworks that aid this process - as there are for python (e.g. TurboGears validators), but especially when it comes to dates, even the larger ones like Struts for Java pretty much suck. Diez From toolmaster at 163.com Tue Dec 12 06:46:43 2006 From: toolmaster at 163.com (WaterWalk) Date: 12 Dec 2006 03:46:43 -0800 Subject: Emulate @classmethod using decorator and descriptor Message-ID: <1165924003.681613.62790@80g2000cwy.googlegroups.com> Hello, I was recently learning python decorator and descriptor and emulated a @classmethod decorator: class EmuClassMethod(object): def __init__(self, f=None): self.f = f def __get__(self, obj, klass=None): if klass is None: klass = type(obj) def wrapped(*args): return self.f(klass, *args) return wrapped class Test(object): @EmuClassMethod def t(cls): print "I'm %s" % cls.__name__ It worked, and seems that a function decorator works as follows: # decf is a decorator @decf def func(): print 'func' will be "converted" to: def func(): print 'func' func = decf(func) Is this really the case? Or correct me if i'm wrong. Thanks in advance. From ratchetgrid at googlemail.com Thu Dec 7 03:28:39 2006 From: ratchetgrid at googlemail.com (Nathan Harmston) Date: Thu, 7 Dec 2006 08:28:39 +0000 Subject: Use of factory pattern in Python? Message-ID: <676224240612070028y7be5e8b5h8f860bc505da53c0@mail.gmail.com> Hi, Im trying to find the best way to do a certain task and my so far I have found that using something similar to factory pattern might be the best bet. I m parsing a file to be stored as a graph (using NetworkX). Each row in the file corresponds to a node in the graph. However rows have different types and different numbers of attributes. ( and their corresponding nodes in the future will have methods ) eg chr1 SGD gene 5 8 id=1 name=3 dbref=6 chr1 SGD intron 5 6 id=5 notes="spam" chr1 SGD exon 7 8 id=5 so I was thinking of having a factory class to return the individual objects for each row......ie class Factory(): # if passed a gene return a gene object # if passed an intron return an intron object # if passed an exom return an exon object Is this a good way of doing this, or is there a better way to do this in Python, this is probably the way I d do it in Java. Many Thanks Nathan From tomas at fancy.org Tue Dec 19 01:36:15 2006 From: tomas at fancy.org (Tom Plunket) Date: Mon, 18 Dec 2006 22:36:15 -0800 Subject: textwrap.dedent replaces tabs? References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> Message-ID: Peter Otten wrote: > > I?guess?I?could?manually?replace?all?tabs?with?eight > > spaces (as opposed to 'correct' tab stops), and then replace them when > > done, but it's probably just as easy to write a non-destructive dedent. > > You mean, as easy as > > >>> "\talpha\tbeta\t".expandtabs() > ' alpha beta ' > > ? Umm, no, that's why I wrote "eight spaces (as opposed to 'correct' tab stops)". In either case, though, it'd be hard to know how to replace the tabs, so it'd be better not to remove them in the first place. Indeed, dedent() would work perfectly for my cases if it simply didn't do the expandtabs() in the first place, but there'd be some pretty glaring holes in its logic then. I've since written up a fairly reasonable (IMO) replacement though, that started with textwrap.dedent(), removed the expandtabs() call, and Does The Right Thing with tabs vs. spaces (e.g. it doesn't treat a tab at the beginning of a line as the same as eight spaces). -tom! -- From paddy3118 at netscape.net Fri Dec 22 18:25:29 2006 From: paddy3118 at netscape.net (Paddy) Date: 22 Dec 2006 15:25:29 -0800 Subject: One module per class, bad idea? In-Reply-To: <1166823140.827296.92960@h40g2000cwb.googlegroups.com> References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> <458c489c$1@nntp.zianet.com> <1166823140.827296.92960@h40g2000cwb.googlegroups.com> Message-ID: <1166829929.511423.110970@h40g2000cwb.googlegroups.com> Carl Banks wrote: > Erik Johnson wrote: > > The file has now grown into a 6800 line beast (including docstring, > > whitespace, and CVS history). Pretty much any time we implement some new > > functionality, there are at least a few changes in that file. When you have > > multiple developers working on different projects, and they all need to be > > making changes to that file, the chances for someone making a merge error > > goes up. So, we are obviously at a point where that file needs to be split > > up, but there are lots of other files that import and use the one file, so > > it is a task that has been put off. In retrospect, I wish I has started > > things under a one class per file strategy, but at the time, it didn't make > > a lot of sense to split those things up and I didn't anticipate the code > > getting that big. > > Refactor NOW. > Carl Banks Are there tools out their to help with the refactoring task of splitting a module into two or more sections then showing what other files need to change? From Tim.Golden at viacom-outdoor.co.uk Wed Dec 6 08:26:07 2006 From: Tim.Golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 6 Dec 2006 13:26:07 -0000 Subject: Windows: get owner and group of a file In-Reply-To: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> Message-ID: [kai rosenthal] | with ls -l on windows I get | -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile | | How can I get on windows with a standard python 2.2 (without windows | extensions) the information "500" and "everyone" (owner and group)? | Also I cannot use popen('ls -l'). Wow. Python 2.2. No extensions. Not even popen (). You don't want much, do you? I *think* the answer is that you can't. If you were to loosen up any of your restrictions, you might have a fighting chance of using (in no particular order): 1) popen ("ls -l") as you suggest. I assume that the restriction on popen ("ls") extends to popen ("anything else"). 2) win32security from the pywin32 extensions 3) ctypes (builtin from Python 2.5; also available as an extension) TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From arkanes at gmail.com Thu Dec 21 08:48:22 2006 From: arkanes at gmail.com (Chris Mellon) Date: Thu, 21 Dec 2006 07:48:22 -0600 Subject: Good Looking UI for a stand alone application In-Reply-To: References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> <1hql1xl.oz7gsvwz9w1qN%luc@honk-honk.com> Message-ID: <4866bea60612210548p15e6fdafm5fc0ca17acf7f7e3@mail.gmail.com> On 12/20/06, Vincent Delporte wrote: > On Tue, 19 Dec 2006 08:15:18 -0600, "Chris Mellon" > wrote: > >There's a few more caveats I haven't addressed, and there are places > >where wx isn't perfect. > > BTW, do you know of a good article/book on writing cross-platform GUI > apps, with recommendations, pitfalls, etc. especially using wxWidgets? > -- > http://mail.python.org/mailman/listinfo/python-list > There's a book on both wxWidgets itself, and on wxPython. Both of them focus primarily on the wx api, rather than on the more general cross platform problems. The wxWidgets book is part of Bruce Perens' open source series, and you can get the PDF from http://phptr.com/perens. The wxPython book isn't freely available, but you can order it from wxpython.org. Unfortunately, neither book points out too much in the way of pitfalls - they're mainly focussed on the API. The wxWidgets book does have a section on some common errors with conforming to platform standards and what wx can and cannot do to help. From timr at probo.com Sat Dec 30 03:02:20 2006 From: timr at probo.com (Tim Roberts) Date: Sat, 30 Dec 2006 08:02:20 GMT Subject: INSERT statements not INSERTING when using mysql from python References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> <1167393801.950199.197830@48g2000cwx.googlegroups.com> <1167394098.642975.78350@73g2000cwn.googlegroups.com> <1167394662.665220.185680@a3g2000cwd.googlegroups.com> <1167395368.387567.283250@48g2000cwx.googlegroups.com> <1167396303.259891.144210@n51g2000cwc.googlegroups.com> Message-ID: "Ben" wrote: >Perhaps when I'm checking for table existance using mysql through >python I have to be more explicit: > >Where I did have: >USE database; >IF NOT EXISTS CREATE table(..... > >Perhaps I need: >USE database; >IF NOT EXISTS CREATE database.table(..... > >I'll try it after lunch. Does anyoone know whether this might be the >problem? The "IF NOT EXISTS" clauses are not standard SQL; they are MySQL extensions. Although my reasons are nebulous and more related to principle than to practicality, I try never to use them, because they might not be available in my next database. After all, you should have a pretty good idea at any given time whether your database and table already exist. I do occasionally allow myself a "DROP TABLE IF NOT EXISTS", which then allows the unadulterated "CREATE TABLE" command. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From duncan.booth at invalid.invalid Wed Dec 27 04:27:10 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Dec 2006 09:27:10 GMT Subject: BeautifulSoup bug when ">>>" found in attribute value References: Message-ID: John Nagle wrote: > And this came out, via prettify: > > url="http%3A//www.apartmentsapart.com/Europe/Spain/Madrid/FAQ"> > value="/images/offersBanners/sw04.swf?binfot=We offer > fantastic rates for selected weeks or days!!&blinkt=Click here > >>>&linkurl=/Europe/Spain/Madrid/Apartments/Offer/2408"> > >>&linkurl;=/Europe/Spain/Madrid/Apartments/Offer/2408" /> > > > BeautifulSoup seems to have become confused by the ">>>" within > a quoted attribute value. It first parsed it right, but then stuck > in an extra, totally bogus line. Note the entity "&linkurl;", which > appears nowhere in the original. It looks like code to handle a > missing quote mark did the wrong thing. I don't think I would quibble with what BeautifulSoup extracted from that mess. The input isn't valid HTML so any output has to be guessing at what was meant. A lot of code for parsing html would assume that there was a quote missing and the tag was terminated by the first '>'. IE and Firefox seem to assume that the '>' is allowed inside the attribute. BeautifulSoup seems to have given you the best of both worlds: the attribute is parsed to the closing quote, but the tag itself ends at the first '>'. As for inserting a semicolon after linkurl, I think you'll find it is just being nice and cleaning up an unterminated entity. Browsers (or at least IE) will often accept entities without the terminating semicolon, so that's a common problem in badly formed html that BeautifulSoup can fix. From tjgolden at gmail.com Fri Dec 15 04:04:52 2006 From: tjgolden at gmail.com (Tim Golden) Date: 15 Dec 2006 01:04:52 -0800 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: Message-ID: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> [Tim Daneliuk] > I have a program wherein I want one behavior when a file is > set as executable and a different behavior if it is not. Is > there a simple way to determine whether a given named file is > executable that does not resort to all the lowlevel ugliness > of os.stat() AND that is portable across Win32 and *nix? I'm fairly certain the answer is no. What follows is a relatively low-level and certainly not portable discussion. The last couple of times this question came up on the list I looked into the implementation and experimented a bit but in short I would say that os.stat / os.access were near enough useless for determining executablility under Windows. That's not down to Python as such; it's simply passing back what the crt offers. Of course that raises the slightly wider issue of: should the Python libs do more than simply call the underlying crt especially when that's known to give, perhaps misleading results? But I'm in no position to answer that. I suggest that for Windows, you either use the PATHEXT env var and determine whether a given file ends with one of its components. Or -- and this depends on your definition of executable under Windows -- use the FindExecutable win32 API call (exposed in the win32api module of pywin32 and available via ctypes) which will return the "executable" for anything which has an association defined. So the "executable" for a Word doc is the winword.exe program. The "executable" for an .exe is itself. TJG From pillsbury at gmail.com Mon Dec 11 21:13:39 2006 From: pillsbury at gmail.com (Pillsy) Date: 11 Dec 2006 18:13:39 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165888946.830812.125590@79g2000cws.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> <7xwt4y6j57.fsf@ruckus.brouhaha.com> <7xwt4x6gmy.fsf@ruckus.brouhaha.com> <1165888946.830812.125590@79g2000cws.googlegroups.com> Message-ID: <1165889619.431397.51590@j44g2000cwa.googlegroups.com> Piotr wrote: > Paul Rubin wrote: [...] > > Well, there's some similar way to look up elements in a Lisp > > hashtable, but I've forgotten the keyword for it (oops, cognitive > > inefficiency, having to remember separately.) FWIW, the command is GETHASH. The situation in CL is actually even worse than just having different names for these functions, since some functions put the index as the first argument (GETHASH, NTH) and others put it as the second argument (AREF, ELT). You can at least hide this archaic nonsense away by defining methods for a generic function if it bugs you. > > Python uses the same syntax for both. > That's true, Lisp would benefit from _standard_ homogenuous polymorphic > accessor functions to list-like objects and/or low-level (macro-like) > syntactic sugar. Yes, you can easily make (a i) act like (aref a i) > but it is not done by default. Legacy reasons? Well, it's not such a hot idea in a Lisp-2, since you'll often have a variable named, say, LIST, and then the meaning of (LIST 1) becomes ambiguous. In CL, you could do the implicit indexing with different braces, though, like [a i] for (aref i); this is something I periodically consider doing. Cheers, Pillsy From mcPas.De.Spam at mclaveauPas.De.Spam.com Sat Dec 16 18:10:40 2006 From: mcPas.De.Spam at mclaveauPas.De.Spam.com (Michel Claveau) Date: Sun, 17 Dec 2006 00:10:40 +0100 Subject: inquiry about installing Python 2.5 References: <1166308594.341370.8580@j72g2000cwa.googlegroups.com> Message-ID: Hi! For Python only, it's possible. But, if you add Pywin32... problem! -- @-salutations Michel Claveau From atkinw at rpi.edu Sat Dec 9 14:24:21 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 14:24:21 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> Message-ID: "mystilleef" writes: > Mark Tarver wrote: >> How do you compare Python to Lisp? What specific advantages do you >> think that one has over the other? >> >> Note I'm not a Python person and I have no axes to grind here. This is >> just a question for my general education. >> >> Mark > > Advantages of Python: > > 1). More and better mature standard libraries (Languages don't matter, > libraries do). > 2). Multiple programming paradigms (including functional style > programming see itertools, functools, operator modules (lambda, map, > filter, reduce, sum etc builtins), higher order functions, list > comprehension, blah, blah) > 3). Better OO implementation. (I used to hate OO until I started using > Python) > 4). Ultimate glue language (Plays well with C, C++, Java, .NET. nuff > said. Bindings for almost any lib worth using, at least on *nix) > 5). Clearer syntax. > 6). Better namespace management. (nobody ever talks about this, but > Python seems to be one of the few languages that gets symbol management > right from a users perspective) > 7). Easier packaging and distribution system. > 8). Ubiquity! Python is everywhere. Lisp, bleh. > 9). Relatively good docs (PHP has better). > 10). Fewer perceived community assholes. Large community. > 11). Less fragmentation. Are any of these not subjective? > Advantages of Lisp: > > Learning a functional language can improve your programming range and Lisp is much more than a functional language. > depth. And today, I wouldn't even recommend Lisp (it's rather archaic), > when there's mind bending Haskell. I'd go as far as saying I believe > Haskell has a better fate than Lisp. Yeah, that's pretty far. > On Lisp Macros: > > I think they are overrated, and in general cause more harm than good. > It's the reason I find Lisp-like programs difficult to grok, maintain > and extend. Cos every smart ass wants to needlessly write his own mini > language to the point of absolute obfuscation. Naturally, I'm supposed > to be awed by his mischievous cleverness. Uh huh. Can you cite examples of this? Sounds like you're just making stuff up here. Contrary to popular belief, writing a Lisp macro that warps your mind and introduces a totally un-CL-like semantics is extremely difficult. Most of the people who are good enough at CL to do it (I'm certainly not one of them) are also experienced enough to know when it's the right choice. And Lisp environments all support getting the macroexpansion, documentation, and source of any unfamiliar macro you might happen upon, so really this is not as much of a problem as you might fantasize it to be. > Conclusion: > > The semantics or features of a language is almost irrelevant today. > Developers want to put the lego pieces together, they don't want to > make lego. Rewriting the sun and moon, or needlessly reinvent the wheel > was popular in the 70s, but it's boring and expensive today. Today, > when a developer needs to solve a problem, the question they ask is, > "Is there a library for that?". If the answer is no, they a more likely > to switch to a language that provides a library that solves their > problem. The challenge for developers today is software architecture, > robustness and scalability, not language purity or semantics. The Lisp, > and to an extent Haskell, community will never ever ever grok this. > They'll continue to wonder why an "inferior" language like Python keeps > getting popular. It will always escape them that it might be because > Python is actually easier to use for most people to write "real world" > applications. It has good usability. I don't agree with a lot of what you say in this paragraph, but I you're right that libraries are crucial. That's why I wish there were more people writing Lisp libraries instead of being scared away by sheer fabrications like the stuff that's appearing in this thread. From rpw3 at rpw3.org Wed Dec 13 05:23:36 2006 From: rpw3 at rpw3.org (Rob Warnock) Date: Wed, 13 Dec 2006 04:23:36 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xhcw1l0sn.fsf@ruckus.brouhaha.com> <1165933208.789916.250730@f1g2000cwa.googlegroups.com> <7x7iwxccmv.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: +--------------- | CLTL2 is a model of precision and thoroughness compared | with any document that's ever been written about Python. +--------------- It's a great book, but one needs to be clear that CLtL2 is *not* the same as the ANSI Common Lisp standard, but was the author's best guess at the time as to where the standardization effort was going after CLtL1. You may find the following useful in marking up your copy of CLtL2 to be closer to the final standard: http://cbbrowne.com/info/commonlisp.html#AEN10499 http://bc.tech.coop/cltl2-ansi.htm But note the caveat therein: A doctored CLTL2 is NOT the ANSI standard. In fact, this FAQ has many known but minor omissions that are too awkward to add with pencil to CLTL2. The Common Lisp HyperSpec (CLHS), while also not the official ANSI standard per se, was created from "the same" TeX input as the ANSI standard (with permission from ANSI & X3), and is the reference most CL programmers use: http://www.lisp.org/HyperSpec/FrontMatter/index.html http://www.lispworks.com/documentation/HyperSpec/Front/index.htm For a downloadable tarball of the whole thing, there's a link near the bottom of this page: http://www.lispworks.com/documentation/HyperSpec/index.html -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From mail at microcorp.co.za Sat Dec 9 02:53:54 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 9 Dec 2006 09:53:54 +0200 Subject: Subprocess with a Python Session? References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com><1165577596.239341.47550@16g2000cwy.googlegroups.com> <1165595416.086428.204710@l12g2000cwl.googlegroups.com> Message-ID: <012501c71b67$2cdcd580$03000080@hendrik> "Paul Boddie" wrote: > Fredrik Lundh wrote: > > Paul Boddie wrote: > > > > > This is one of the more reliable methods since upon receiving a packet > > > "delimiter" the receiver knows that the data is complete. > > > > and for people who want RELIABLE and not just "at least > > not entirely unreliable", there's always: > > > > http://cr.yp.to/proto/netstrings.txt > > That's why I hedged my bets and put "one of the more" rather than "the > most" in that sentence. ;-) I've been using netstrings myself, although > I didn't know that they had that particular name. > > > (if you control both ends, there's hardly ever any reason not to use > > netstrings. they're trivial to generate from Python, and pretty simple > > to parse.). > > Indeed. I was not aware that putting the length in front of a data packet had been blessed with the name "netstring". It is almost obligatory to do something like this if you are using raw sockets as otherwise you never know where you are. What I tend to do is more complex and probably also has a name that I am unaware of - I "frame" packets between tildes - 0x7e - the SDLC/HDLC flag character - this requires me to escape tildes, and my "escape" char, to prevent them occurring in the message - I use the ordinary forward slash as the escape char, and alter the poison chars by exclusive oring them with 0xff to invert - after adding at least a bcc formed by the xor of all the chars in the package, (before the escaping), and where its important, I use message numbers too... - but then - I am paranoid... And yes I once wrote some x25 type stuff in z80 assembler... :-) - Hendrik From uval at rz.uni-karlsruhe.de Fri Dec 8 00:11:02 2006 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Sch=FCle_Daniel?=) Date: Fri, 08 Dec 2006 06:11:02 +0100 Subject: why is this different? In-Reply-To: <1165582005.677639.292990@16g2000cwy.googlegroups.com> References: <1165582005.677639.292990@16g2000cwy.googlegroups.com> Message-ID: Gabriel Genellina schrieb: Gabriel Genellina schrieb: > On 7 dic, 22:53, Sch?le Daniel wrote: > >> In [38]: f = [lambda:i for i in range(10)] >> In [39]: ff = map(lambda i: lambda : i, range(10)) >> In [40]: f[0]() >> Out[40]: 9 >> In [41]: f[1]() >> Out[41]: 9 >> In [42]: ff[0]() >> Out[42]: 0 >> In [43]: ff[1]() >> Out[43]: 1 >> >> I don't understand why in the first case f[for all i in 0..9]==9 > > In the first case, i is a free variable. That means that Python will > get it from other place (the global namespace, likely [surely?]) > >>>> f=[lambda:i for i in range(10)] >>>> f[0]() > 9 >>>> i=123 >>>> f[0]() > 123 >>>> print f[0].func_closure > None > > In the second case, the inner i is a free variable, but local to its > enclosing scope (outer lambda). It's a closure: >>>> ff = map(lambda i: lambda : i, range(10)) >>>> ff[4]() > 4 >>>> ff[4].func_closure > (,) >>>> i=321 >>>> ff[4]() > 4 > >> what is different from (more usefull) >> >> In [44]: f = ["%i" % i for i in range(10)] >> In [45]: f >> Out[45]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] > > This is a simple expression evaluated at each iteration > >> doing it like this works again >> >> In [54]: def d(x): >> ....: return lambda:x >> ....: > x inside lambda is a free variable, but since it's local to d, this > becomes a closure: > >>>> d(1) > at 0x00A35EF0> >>>> d(1).func_closure > (,) > >> In [55]: f = [d(i) for i in range(10)] >> In [56]: f[0]() >> Out[56]: 0 >> In [57]: f[1]() >> Out[57]: 1 > This is similar to the ff example above > >> in a C programmer sence I would say there seems to be no "sequence >> point" which would separate "now" from "next" > > No, the problem is that C has no way to express a closure; this is a > functional concept absolutely extraneous to the C language. > > On 7 dic, 22:53, Sch?le Daniel wrote: > >> In [38]: f = [lambda:i for i in range(10)] >> In [39]: ff = map(lambda i: lambda : i, range(10)) >> In [40]: f[0]() >> Out[40]: 9 >> In [41]: f[1]() >> Out[41]: 9 >> In [42]: ff[0]() >> Out[42]: 0 >> In [43]: ff[1]() >> Out[43]: 1 >> >> I don't understand why in the first case f[for all i in 0..9]==9 > > In the first case, i is a free variable. That means that Python will > get it from other place (the global namespace, likely [surely?]) > >>>> f=[lambda:i for i in range(10)] >>>> f[0]() > 9 >>>> i=123 >>>> f[0]() > 123 >>>> print f[0].func_closure > None intersting I think I got it [] I have two more examples, but now I understand the difference In [70]: x = [eval("lambda:i") for i in range(10)] In [71]: y = [eval("lambda:%i" % i) for i in range(10)] I think [71] is most obvious what the programmer intends Thx From stevenst at rocketmail.com Sun Dec 10 22:09:30 2006 From: stevenst at rocketmail.com (Leanne) Date: 10 Dec 2006 19:09:30 -0800 Subject: Newbie Question - Checkboxes In-Reply-To: References: <1165737399.895450.85620@f1g2000cwa.googlegroups.com> Message-ID: <1165806570.399209.269730@79g2000cws.googlegroups.com> Thanks for your reply Peter. Sorry if my technical wording of the problem is a bit lacking. I am still trying to put all parts of the puzzle together in terms of the programming environment. The checkboxes are in a PyMeld compatible HTML file. I'm using CherryPy 2.2. Leanne From vedran at v-programs.com Sun Dec 31 13:27:13 2006 From: vedran at v-programs.com (Croteam) Date: 31 Dec 2006 10:27:13 -0800 Subject: simple ftputil ssl client Message-ID: <1167589633.246117.130710@42g2000cwt.googlegroups.com> Hello, I trying to make ftputil client that uses ssl security.First I was try to make that with M2Crypto,but when I use it, I get the error: Traceback (most recent call last): File "", line 1, in -toplevel- import M2Crypto File "C:\Python24\lib\site-packages\M2Crypto\__init__.py", line 15, in -toplevel- import m2 File "C:\Python24\Lib\site-packages\M2Crypto\m2.py", line 28, in -toplevel- from __m2crypto import * ImportError: DLL load failed with error code 182 ...so now I trying to make it with pyOpenSSL or twistedmatrix ssl,but I don't know how.If anybody have any idea or example how to I make it,please help me!!! From mcfletch at vrplumber.com Fri Dec 15 18:09:36 2006 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Fri, 15 Dec 2006 18:09:36 -0500 Subject: Metaclass uses? In-Reply-To: <676224240612151434k12eccc5bh9f8efe419749886b@mail.gmail.com> References: <676224240612151434k12eccc5bh9f8efe419749886b@mail.gmail.com> Message-ID: <45832B30.4030409@vrplumber.com> Nathan Harmston wrote: > Hi, > > Recently I posted a question about the factory pattern in python. I ve > implemented this following one of the ideas posted. After some reading > I ve seem a lot of Aspect Oriented Programming mentioned but I m not > really sure what it is. > > Can anyone help me understand how metaclasses can improve the quality > of my code and let me do better things. > My presentation from three pycons ago was an attempt to address this issue (what metaclasses are useful for): http://www.vrplumber.com/programming/metaclasses-pycon.pdf HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 23:08:25 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 15:08:25 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: On Sun, 10 Dec 2006 01:53:50 +0100, Andr? Thieme wrote: > You could maybe give another example: how would one realize something > like (memoize function) in Python? By spending thirty seconds googling: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498110 If your needs are very simple, something as simple as this will do it: def memoize(func): def f(arg, _cache={}): if _cache.has_key(arg): return _cache[arg] t = func(arg) _cache[arg] = t return t return f > Or (defmethod name :after ..)? I don't even know what that means. Would you like to translate? -- Steven. From henning.jansen at gmail.com Sat Dec 16 17:49:19 2006 From: henning.jansen at gmail.com (jansenh) Date: 16 Dec 2006 14:49:19 -0800 Subject: Dictionary, iterate & update objects References: <1166302637.147669.266480@f1g2000cwa.googlegroups.com> <1166305376.376842.36270@16g2000cwy.googlegroups.com> Message-ID: <1166309359.764862.62110@l12g2000cwl.googlegroups.com> Hi and thanx! Caleb Hattingh wrote: > > >>> temp=d[12345] > >>> temp.x = 5 > > After I assign the object to the dict with ID=12345, I can easily get > the object by its key and manipulate its state. The last 4 lines show > that the state changed for all the active references to the created > object. Is this what you wanted? Yes. [... the temp object is by ref, and any manipulation of the temp object is to the object itself..? It really simplifies my first attempt] > If you are this Henning Jansen: > http://www.henning-jansen.com/ Yes, this is me :-/ and I have a little Ruby experience. And I will create a sample snippet the next time I pop a question. Thank you for a clear and helpful response. regards, Henning From pkarjala at paju.oulu.fi Mon Dec 11 14:21:07 2006 From: pkarjala at paju.oulu.fi (Pekka Karjalainen) Date: Mon, 11 Dec 2006 19:21:07 +0000 (UTC) Subject: alternate language References: <12nr93mis39tu45@corp.supernews.com> Message-ID: In article , Pekka Karjalainen wrote: Sorry, I messed up the attribution when editing and decided not to post. Accidentally did post an empty message anyway. I was going to recommend Haskell for the original poster too, and I wanted to answer that I did indeed (start to) learn another language after Python. Haskell is mind-expanding after all. I'm not sure which directions mine has expanded, because I have so much difficulty with slrn today, but never mind. I won't repeat the Haskell recommendation I typed up and then deleted. If you look at what people say about it you either want to try it or not. Pka From larry.bates at websafe.com Wed Dec 20 09:31:32 2006 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 20 Dec 2006 08:31:32 -0600 Subject: Any easy-to-use email send module? In-Reply-To: References: Message-ID: <45894944.5000507@websafe.com> oyster wrote: > I find that the existing email moudle is some hard for me to > understand, especially the part of how to set the CC, BCC and attach > the files. Is there any more easy one like this p-code? > > import easyemail > smtpserver=easyemail.server('something') > smtpserver.login('usr at gmail.com', pwd) > newletter=smtpsever.letter(smtpserver) > newletter.sendto=['to1 at 1.com', 'to2 at 2.com'] > newletter.sendcc=['cc1 at 111.com', 'cc2 at 222.com'] > newletter.sendbcc=['bcc1 at 111.com', 'bcc2 at 222.com'] > newletter.body='this is the body\nline 2' > newletter.att=['c:/file1.txt', 'd:/program files/app/app.exe'] > > if (newletter.send()==True): > print 'send ok' > smtpserver.close() > > Thanx. I'm not entirely sure where I got this code (Google search years ago) and I've extended it a little, but you are welcome to use it and it is very close to what you outlined above. I had to strip out a bunch of custom logging that I include in my version, but it think this will either work or at least be close enough to save you some time. -Larry import string,sys,types,os,tempfile,time import smtplib import poplib import mimetypes,mimetools,MimeWriter class SmtpWriter: def __init__(self, server="localhost", dest=None, src=None, userid=None, password=None): self.__server = server self.__dest = dest self.__src = src self.__userid = userid self.__password=password self.__debugLevel = 0 return def Debug(self,level): self.__debugLevel = level def Message(self,sender="", subject="", recipients=[], body="", attachments=[]): if self.__debugLevel > 2: sys.stderr.write("SmtpWriter: Building RFC822 message From: %s; " \ "Subject: %s; (Length=%d with %d attachments)\n" % \ (sender, subject, len(body), len(attachments))) sys.stderr.flush() tempFileName = tempfile.mktemp() tempFile = open(tempFileName,'wb') message = MimeWriter.MimeWriter(tempFile) message.addheader("From",sender) message.addheader("To", reduce(lambda a,b: a + ",\n " + b, recipients)) message.addheader("Subject", subject) message.flushheaders() if len(attachments) == 0: fp = message.startbody('text/plain') fp.write(body) else: message.startmultipartbody('mixed') submessage = message.nextpart() fp = submessage.startbody('text/plain') fp.write(body) for attachFile in attachments: if type(attachFile) == types.StringType: fileName = attachFile filePath = attachFile elif type(attachFile) == types.TupleType and len(attachFile) == 2: filePath, fileName = attachFile else: raise "Attachments Error: must be pathname string or path,filename tuple" submessage = message.nextpart() submessage.addheader("Content-Disposition", "attachment; filename=%s" % fileName) ctype,prog = mimetypes.guess_type(fileName) if ctype == None: ctype = 'unknown/unknown' if ctype == 'text/plain': enctype = 'quoted-printable' else: enctype = 'base64' submessage.addheader("Content-Transfer-Encoding",enctype) fp = submessage.startbody(ctype) afp = open(filePath,'rb') mimetools.encode(afp,fp,enctype) message.lastpart() tempFile.close() # properly formatted mime message should be in tmp file tempFile = open(tempFileName,'rb') msg = tempFile.read() tempFile.close() os.remove(tempFileName) #print "about to try to create SMTPserver instance" server=None # # See if I can create a smtplib.SMTP instance # try: server = smtplib.SMTP(self.__server) except: if self.__debugLevel > 2: emsg="SmtpWriter.Message-Unable to connect to " \ "SMTP server=%s" % self.__server sys.stderr.write(emsg) sys.stderr.flush() raise RuntimeError(emsg) if self.__debugLevel > 2: server.set_debuglevel(1) # # If server requires authentication to send mail, do it here # if self.__userid is not None and self.__password is not None: # # There are two possible ways to authenticate: direct or indirect # direct - smtp.login # indirect - smtp after pop3 auth # try: response=server.login(self.__userid, self.__password) except: if self.__debugLevel > 2: emsg="SmtpWriter.Message-SMTP auth failed, trying POP3 " \ "auth" sys.stderr.write(emsg) sys.stderr.flush() try: M=poplib.POP3(self.__server) M.user(self.__src) M.pass_(self.__password) M.stat() # Get mailbox status M.quit() except: if self.__debugLevel > 2: emsg="SmtpWriter.Message-Both SMTP and POP3 auth failed " \ "email message NOT sent" sys.stderr.write(emsg) sys.stderr.flush() raise RuntimeError(emsg) # # Send the email # server.sendmail(self.__src, self.__dest, msg) if self.__debugLevel > 1: sys.stderr.write("SmptWriter.Message sent\n") sys.stderr.flush() server.quit() return if __name__ == "__main__": import sys import time server="mail.domain.com" email=SmtpWriter(server=server, dest=["name at domain.com.com"], src="smtpwriter at domain.com", userid="smtpwriter at domain.com", password="password") email.Message(sender="smtpwriter at domain.com", subject="Test email #2", recipients=["me at domain.com"], body="This is a test email from the SmtpWriter class", attachments=["c:\\output.txt"]) From justask at acme.com Wed Dec 6 19:00:11 2006 From: justask at acme.com (Vincent Delporte) Date: Thu, 07 Dec 2006 01:00:11 +0100 Subject: Mod_python vs. application server like CherryPy? References: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> <33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com> <1165445758.342163.37650@f1g2000cwa.googlegroups.com> Message-ID: On 6 Dec 2006 14:55:58 -0800, "Graham Dumpleton" wrote: >Although WSGI is an extreme case because of the level it pitches at, >other systems such as CherryPy and Django aren't much different as they >effectively duplicate a lot of stuff that could be achieved using more >basic functionality of Apache as well. Mmm... So how can I use those goodies from Apache? Just through their configuration files, or do I have to somehow call them from Python? Is the fact that Python developers tend to ignore resources in Apach due to difficulties in making calls from Python, making the scripts unpythonic? From eadmund42 at NOSPAMgmail.com Wed Dec 13 11:40:24 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Wed, 13 Dec 2006 09:40:24 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> <1165969090.648421.177130@16g2000cwy.googlegroups.com> Message-ID: "George Sakkis" writes: > > Why is selecting a valid s-expression easier than selecting a python > block ? If you mistakenly select an extra parenthesis or omit one, it's > the same thing. Having said that, I find this problem is mostly > academic in both languages with modern editors... Or even nearly 30 year old editors; emacs provides support for error-free selection of s-expressions, although to be frank I still don't use them as often as I should. -- Robert Uhl Thanks to the joint efforts of OpenOffice, Mozilla, and a few others, Emacs officially entered the category of lightweight utilities. --kalifa on /. From chris.cavalaria at free.fr Fri Dec 15 09:50:04 2006 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Fri, 15 Dec 2006 15:50:04 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> Message-ID: <4582b61c$0$8164$426a74cc@news.free.fr> Paul Rubin wrote: > Andr? Thieme writes: >> def nif(num, pos, zero, neg): >> if num > 0: >> return pos >> else: >> if num == 0: >> return zero >> else: >> return neg > > def nif(num, pos, zero, neg): > return (neg, zero, pos)[cmp(num, 0)+1] Since we are in one liners, let's be even smarter and do it like that : def nif(num, pos, zero, neg): return (zero, pos, neg)[cmp(num, 0)] ;) From fredrik at pythonware.com Thu Dec 14 03:43:11 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 09:43:11 +0100 Subject: Sorting Multidimesional array(newbie) In-Reply-To: <1166083031.343359.63620@j72g2000cwa.googlegroups.com> References: <20061211193104.40fe7985.tartifola@gmail.com> <1165863508.967414.70350@73g2000cwn.googlegroups.com> <1165907463.624180.7990@79g2000cws.googlegroups.com> <1166083031.343359.63620@j72g2000cwa.googlegroups.com> Message-ID: Brian Mills wrote: > >> but using a compare function instead of a key mapper is not good advice, >> in general. brief discussion here: >> http://effbot.org/pyfaq/i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python > > Is this mostly because of the stability problem described here: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 ? as mentioned in the comments to that recipe, Python's sort has been stable since 2.3. > Or is it more a performance issue due having to make so many function calls? exactly (see the last sentence in the FAQ entry). From limodou at gmail.com Sun Dec 3 21:37:33 2006 From: limodou at gmail.com (limodou) Date: Mon, 4 Dec 2006 10:37:33 +0800 Subject: ANN: UliPad 3.6 released! Message-ID: <505f13c0612031837k7b9eaba7i2d5658f6d0d961de@mail.gmail.com> What's it? ======== It's an Editor based on wxPython. UliPad(NewEdit is the old name) uses Mixin and Plugin technique as its architecture. Most of its classes can be extended via mixin and plugin components, and finally become an integrity class at creating the instance. So UliPad is very dynamic. You can write the new features in new files, and hardly need to modify the existing code. And if you want to extend the existing classes, you could write mixins and plugins, and this will be bound to the target class that I call "Slot Class". This technique will make the changes centralized and easily managed. What's new in 3.6 ============== New features and improvement: #. Improve definition jump, and if there is no ctag file exist, UliPad can jump in one source file, including: variable, class, method, etc #. Improve auto-completion: variable auto-detect, class structure detect, base class recognize, etc. And it can improve your typing. As you backspace something, auto-completion will also available. And you can also write parameter datatype in function docstring, UliPad will auto recognize the parameter datatype. #. Add range support for live regular expression search support #. Add pairprog plugin, it's a collaborative programming support. One instance can be a server, and others can be client. For server, you can share source file with all client, and both server and client can change the same document and move the caret. UliPad support multi-client. And it has a chatroom support, so developer can use it to talk with each other. #. Add fortran, and lua syntax support. For fortran you should enable fortran plugin. #. Improve the display structure and content of class browser #. Add css auto-completion support Changes: #. Improve class browser windown, and single-click on class icon will expand or collapse the children items #. Fix the bug of clicking on Cancel button on Python Parameter Input Dialog still running #. Fix reStructuredText syntax highlight processing bug #. Fix python syntax analysis bug #. Fix cann't restore the last directories entries as reopen the directory browser bug #. Fix if the filename or directory that you want to open command line window on it(on windows platform) is not the same hard driver, will open wrong path bug. #. Fix music plugin's bug #. Remove open recently-directory functionality #. Fix as changing the encode of the document, but the tab page title doesn't be changed bug Where to download it? ================ download lastest version 3.6: http://wiki.woodpecker.org.cn/moin/UliPad?action=AttachFile&do=get&target=ulipad_3.6.zip also have windows installer: http://wiki.woodpecker.org.cn/moin/UliPad?action=AttachFile&do=get&target=UliPad.3.6.exe wiki: http://wiki.woodpecker.org.cn/moin/UliPad svn: http://cvs.woodpecker.org.cn/svn/woodpecker/ulipad/trunk maillist: http://groups.google.com/group/ulipad If you have any problem as using UliPad, welcome to join the UliPad maillist to discuss. Hope you enjoy it. ;-) -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou From gagsl-py at yahoo.com.ar Sat Dec 9 18:48:34 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 9 Dec 2006 15:48:34 -0800 Subject: Automatic debugging of copy by reference errors? In-Reply-To: References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165645676.694401.193580@16g2000cwy.googlegroups.com> <1165666093.996141.244760@n67g2000cwd.googlegroups.com> <1165672702.406793.320500@79g2000cws.googlegroups.com> Message-ID: <1165708114.587243.205910@n67g2000cwd.googlegroups.com> > I think what you want is a namespace that requires each object to have > exactly one reference - the namespace. Of course, additional references > will be created during evaluation of expressions. So the best you can do It's not enough. It won't catch the case where a list holds many references to the same object - the example provided by the OP. -- Gabriel Genellina From w_a_x_man at yahoo.com Fri Dec 15 16:33:00 2006 From: w_a_x_man at yahoo.com (William James) Date: 15 Dec 2006 13:33:00 -0800 Subject: merits of Lisp vs Python References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <1166207152.706475.76020@t46g2000cwa.googlegroups.com> <1166215871.110268.131890@j72g2000cwa.googlegroups.com> Message-ID: <1166218380.386581.116190@t46g2000cwa.googlegroups.com> Andr? Thieme wrote: > William James schrieb: > > Andr? Thieme wrote: > >> William James schrieb: > >> > >>> def nif num, pos, zero, neg > >>> send( num>0 ? pos : (num==0 ? zero : neg) ) > >>> end > >> btw, your nif body is built out of 13 tokens, so more > >> complicated than the Python version. > >> > >> > >> Andr? > >> -- > > > > def nif num, *args > > send args[ 1 + (0 <=> num) ] > > end > > > send > | > | > [ ] > / \ > / \ > / \ > args + > / \ > / \ > 1 () > | > | > <=> > / \ > / \ > 0 num > > Okay, 9. Now it is at the complexity level of the Lisp > and Python example. > But how would a call to nif look like? A call is unchanged: [0, 2.5, -8].map{|x| nif x, :p, :z, :n} > I hope it doesn't involve an extra operator to group the > args into a list or tuple. That would add more complexity to > each call - so one should better have a slightly more complex > nif because that exists only one time. > > And can this nif now handle any input values, such as strings > or function objects? It handles only symbols. I suppose this can handle anything ... p = proc { puts "very positive" "positive" } z = proc { puts "no no" "zero" } n = proc { puts "very negative" "negative" } def nif num, *args args[ 1 + (0 <=> num) ].call end [0, 2.5, -8].map{|x| nif x, p, z, n} puts [0, 2.5, -8].map{|x| nif x, proc{'zero'}, proc{'plus'}, proc{'minus'}} ... if you wrap everything in a proc (lambda). From sonibergraj at youjoy.org Mon Dec 4 14:28:38 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Mon, 04 Dec 2006 20:28:38 +0100 Subject: decorators question In-Reply-To: <1165259428.106492.44020@16g2000cwy.googlegroups.com> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> Message-ID: <457476E6.5000603@youjoy.org> > Hmmm...ok...it calls the decorator but when ?? It (the runtime) loads > the .py file and start to call every decorator > it finds on it, regardless of the existance of code that actually calls > the decorated functions ?? > I understand thet Python does not call the decoratated functiond but it > ends up this way... Python simply executes the module body when you import a module. class and def statements result in binding of class and function objects to the corresponding names. It's really that simple. Try the following to get a deeper insight: # file foobar.py def bar(f): return 'some text' @def bar def foo(): print "foo" When you import this module module in an interactive python session you will get he following. >>> from foobar import * called foo >>> bar() # this will fail because bar is not a function Traceback (most recent call last): File "", line 1, in ? TypeError: 'str' object is not callable >>> bar 'some text' Hope that helps;) -- Soni Bergraj http://www.YouJoy.org/ From hg at nospam.com Fri Dec 1 06:43:35 2006 From: hg at nospam.com (hg) Date: Fri, 01 Dec 2006 05:43:35 -0600 Subject: python vs java & eclipse In-Reply-To: References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <45701422.4050206@gmx.net> Message-ID: Thomas Ploch wrote: > Thomas Ploch schrieb: >> Amir Michail schrieb: >>> Hi, >>> >>> It seems to me that measuring productivity in a programming language >>> must take into account available tools and libraries. >>> >>> Eclipse for example provides such an amazing IDE for java that it is no >>> longer obvious to me that one would be much more productive in python >>> for medium sized projects. >>> >>> Sure, all that Java static typing can be painful, but Eclipse takes >>> some of that pain away. Moreover, static typing can result in better >>> on-the-fly error detection and refactoring support. >>> >>> Any thoughts on this? >>> >>> Amir >>> >> Yes, thats true, but since eclipse is resource monster (it is still >> using java), and some people (like me) don't have a super fresh and new >> computer, and have to run other services to test their work locally >> (like mysql and apache servers), it gets pretty harsh with eclipse. I >> personally tried eclipse on my laptop (which I work most with), and I >> had quite a system resource problem. So I switched back to vim and >> console and it hasn't been too bad, since if you know how to use a >> powerful editor, it can be as productive. >> >> But in the end, it is up to anyone to find the best solutiion for >> themselves. >> >> Thomas >> > > Yes, thats true, but since eclipse is resource monster (it is still > using java), and some people (like me) don't have a super fresh and new > computer, and have to run other services to test their work locally > (like mysql and apache servers), it gets pretty harsh with eclipse. I > personally tried eclipse on my laptop (which I work most with), and I > had quite a system resource problem. So I switched back to vim and > console and it hasn't been too bad, since if you know how to use a > powerful editor, it can be as productive. > > But in the end, it is up to anyone to find the best solutiion for > themselves. > > Thomas > If you compare eclipse to VS, it is not that memory hungry - but i agree with you that a min-config is needed. Yet (I believe that) a complete IDE can bring functions that an editor, however powerful, cannot (I still use emacs). I have tried Komodo, Wing, Eric3, Idle, emacs, (not vi ;-) ), SPE, boa-constructor, .... and many more - I like most of them but am really addicted to eclipse + pydev. ... but even without pydev, I would not use java just because of eclipse. hg From tony at PageDNA.com Sun Dec 31 11:23:25 2006 From: tony at PageDNA.com (Tony Lownds) Date: Sun, 31 Dec 2006 08:23:25 -0800 Subject: PEP 3107 Function Annotations for review and comment In-Reply-To: <1167580455.349588.234610@v33g2000cwv.googlegroups.com> References: <1167492896.292605.15040@48g2000cwx.googlegroups.com> <1167580455.349588.234610@v33g2000cwv.googlegroups.com> Message-ID: <217ACEEA-A0CF-4670-ABD5-19D03A922CE9@PageDNA.com> On Dec 31, 2006, at 7:54 AM, John Roth wrote: > Tony Lownds wrote: >> Perhaps you are right and intersecting libraries will become an >> issue. >> Designing a solution in advance of the problems being evident seems >> risky to me. What if the solution invented in a vacuum really is more >> of a hindrance? > > Vacuum? What vacuum? No libraries use the new syntax. Hence no libraries can be currently intersecting on the usage. [...] > At the moment the project I'm working on has annotations > from three packages: Python FIT (which is the actual package), > Ned Bachelder's code coverage tool, and one of the code > standards tools. None of these are either documentation > or type checking / coercion. > Let me see if I can guess how those tools will use function annotations. You've decided Python FIT can't use function annotations. Code coverage tool won't even use function annotations. It's possible packages like pylint will learn to interpret function annotations to provide better static analysis. Right? The problem is, pylint may only understand annotation scheme A and the module author has written the annotations in scheme B. Is this is the kind of "intersection" issue you had in mind? Do you have any more specific cases to consider? Thanks -Tony From tleeuwenburg at gmail.com Mon Dec 4 23:27:54 2006 From: tleeuwenburg at gmail.com (tleeuwenburg at gmail.com) Date: 4 Dec 2006 20:27:54 -0800 Subject: Async callback in python In-Reply-To: <1165292302.454012.118540@n67g2000cwd.googlegroups.com> References: <1165292302.454012.118540@n67g2000cwd.googlegroups.com> Message-ID: <1165292874.116694.282010@l12g2000cwl.googlegroups.com> Did you flush the buffer? It might be that the print statements are being called in the order you expect but that they are all written to the screen only at the end. I've had that happen before. Cheers, -T Linan wrote: > Hi, > > In javascript, code could be written like this: > > ... > > var _p=XMLHttpRequest(); > _p.open('GET',url,true); > _p.send(null); > _p.onreadystateChange=function(){ > if(_p.readyState==4) > cb(_p.responseText); > } > ... > > This basic AJAX code allows function to be called when it's invoked, > without blocking the main process. There is same library asyncore in > python. However, I can't validate it's asynchronous through code: > class T(asyncore.dispatcher): > def __init__(self,host,url): > asyncore.dispatcher.__init__(self) > self.create_socket(socket.AF_INET, socket.SOCK_STREAM) > self.connect((host,80)) > self.url='GET %s HTTP/1.0\r\n\r\n' % url > > def handle_connect(self): > pass > > def handle_close(self): > self.close() > > def handle_read(self): > print 'READING.....' > print self.recv(256) > > def handle_write(self): > sent=self.send(self.url) > self.url=self.url[sent:] > > t=T('aVerySlowSite','/') > asyncore.loop() > for i in range(0,10): > print '%d in main process' % i > time.sleep(1) > > Suppose it's asynchronous, couple of '%d in main process' lines should > be mixed in the output of T.handle_read(), right? But I found that > actually main process was blocked at asyncore.loop(), until the the > socket was closed. My questions: > 1, Did I do anything wrong? > 2, Is it real asynchronous? > 3, If not, where to get the real one(s)? > > Any comment is welcome :) From notontheweb at noisp.com Sat Dec 16 19:17:37 2006 From: notontheweb at noisp.com (Jive Dadson) Date: Sun, 17 Dec 2006 00:17:37 GMT Subject: wxPython help please Message-ID: I hope someone can help me with a couple of wxPython questions, or point me to the right newsgroup for the questions. I am trying to modify the floatcanvas demo program. I want to load an image from a file (jpg or whatever), then do a kind of color-picker action on it. I haven't tried yet to figure out how to load the file. Just for starters, when I click on the canvas, I want to get the rgb pixel value for the point under the cursor. I can't for the life of me figure out how to do it. I suppose it begins with event.GetPosition(), but after that I am at a loss. The larger question is how to use wxPython. It's got such fabulous stuff, but every time I try to do anything with it, I eventually give up because I can't find adequate documentation. I know very little about graphics programming. Please respond here. Because of spammers, the email address is fake. Thanks, "Jive" From gandalf at designaproduct.biz Thu Dec 28 11:37:24 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Thu, 28 Dec 2006 17:37:24 +0100 Subject: db access In-Reply-To: <1167322149.728456.204540@79g2000cws.googlegroups.com> References: <1167320723.501187.98810@h40g2000cwb.googlegroups.com> <4593eb66$0$322$e4fe514c@news.xs4all.nl> <1167322149.728456.204540@79g2000cws.googlegroups.com> Message-ID: <4593F2C4.5020102@designaproduct.biz> king kikapu ?rta: > Hey Martin, > > thanks for the fast reply! > > I have already seen that link and i just downloaded the pyodbc module > but isn't Python already containing a "built-in" odbc module so to > allow for db communication ?? > There is no built-in ODBC module. We all know that Python comes with batteries included. :-) So if you only want to play with SQL then you can use the SQLite package. That is built in Python 2.5. But if you wish to connect to MS SQL, you need to install a third party package. Python does not come with submarine battery packs included, only simple batteries. The good news is that it costs nothing to install additional extensions. By the way, if you plan to use MS SQL from Python, I would recommend ADO instead. ODBC is very old technology. ADO is much better supported. ADO can be accessed from Activestate Python (which is a special Python version from the win32 platform). The other alternative is to install the win32 extensions for Python. (And probably there are other alternatives as well.) I recommend this: http://www.mayukhbose.com/python/ado/index.php Best, Laszlo From gagsl-py at yahoo.com.ar Mon Dec 4 18:58:07 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 04 Dec 2006 20:58:07 -0300 Subject: Best way for inter-process communication in Python In-Reply-To: <4e8efcf50612040948p2c6f911dg14cecff327707539@mail.gmail.co m> References: <4e8efcf50612040924lad6916fi188feef885cd0822@mail.gmail.com> <4e8efcf50612040948p2c6f911dg14cecff327707539@mail.gmail.com> Message-ID: <7.0.1.0.0.20061204205259.047ad638@yahoo.com.ar> At Monday 4/12/2006 14:48, Hugo Ferreira wrote: >There is another option that I thought while writing this... >I can use the database for data communication. Like having a table >with both in and out parameters. On the client-side, I fill the in >parameters columns. Then I signal the external application which reads >the parameters, and write the output. > >Which raises me the following question... How do I signal a python >application under windows? (Is it possible to send something like a >SIGHUP?) Use a named Event object (same name on both programs) (I mean the Windows Event object, not the one found in the threading module) and WaitForSingleObject &Co. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From kkylheku at gmail.com Mon Dec 11 01:02:39 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 10 Dec 2006 22:02:39 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xy7pho7mj.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> Message-ID: <1165816959.002589.123070@n67g2000cwd.googlegroups.com> Paul Rubin wrote: > "Kaz Kylheku" writes: > > > Lisp just seems hopelessly old-fashioned to me these days. A > > > modernized version would be cool, but I think the more serious > > > Lisp-like language designers have moved on to newer ideas. > > > > What are some of their names, and what ideas are they working on? > > http://caml.inria.fr > http://www.haskell.org Right. What these have in common with Lisp is that they use manifest typing, whereas Lisp uses latent typing. But after that, they mostly diverge. From fredrik at pythonware.com Wed Dec 13 09:21:01 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Dec 2006 15:21:01 +0100 Subject: newbie - HTML character codes References: <1166018453.981657.33780@79g2000cws.googlegroups.com> Message-ID: "ardief" wrote: > sorry if I'm asking something very obvious but I'm stumped. I have a > text that looks like this: > > Sentence 401 > 4.00pm — We set off again; this time via Tony's home to collect > a variety of possessions, finally arriving at hospital no.3. > Sentence 402 > 4.55pm — Tony is ushered into a side ward with three doctors and > I stay outside with Mum. > > And I want the HTML char codes to turn into their equivalent plain > text. I've looked at the newsgroup archives, the cookbook, the web in > general and can't manage to sort it out. > file = open('filename', 'r') > ofile = open('otherfile', 'w') > > done = 0 > > while not done: > line = file.readline() > if 'THE END' in line: > done = 1 > elif '—' in line: > line.replace('—', '--') this returns a new line; it doesn't update the line in place. > ofile.write(line) > else: > ofile.write(line) for a more general solution to the actual replace problem, see: http://effbot.org/zone/re-sub.htm#unescape-html you may also want to lookup the "fileinput" module in the library reference manual. From fdu.xiaojf at gmail.com Sun Dec 17 11:21:34 2006 From: fdu.xiaojf at gmail.com (fdu.xiaojf at gmail.com) Date: Mon, 18 Dec 2006 00:21:34 +0800 Subject: Why there isn't a sort method for array ? Message-ID: <45856E8E.3070608@gmail.com> Hi, It seems that an array acts like an list very much, except it doesn't have a method sort. Regards, From jstroud at mbi.ucla.edu Mon Dec 4 01:31:55 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 04 Dec 2006 06:31:55 GMT Subject: A mail from Steve Ballmer. See what Microsoft will do and follow. In-Reply-To: <1165158102.058961.138390@n67g2000cwd.googlegroups.com> References: <1165158102.058961.138390@n67g2000cwd.googlegroups.com> Message-ID: JustStand wrote: > For detail, view http://www.homeoftester.com/viewtopic.php?t=281 > __________________________________ > I have a dream, I hope I can be as strong as Enter key. Does this pointless blogvertisement in anyway compensate for the fact that windows sucks so hard? James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From meesters at uni-mainz.de Tue Dec 19 09:47:52 2006 From: meesters at uni-mainz.de (Christian Meesters) Date: Tue, 19 Dec 2006 15:47:52 +0100 Subject: permutations - fast & with low memory consumption? References: Message-ID: Thanks Simon & Gerard! I will check those exampels out. Christian PS Of course, I did google - but apparently not creative enough. From zondo42 at googlemail.com Thu Dec 14 07:15:34 2006 From: zondo42 at googlemail.com (Glenn Hutchings) Date: 14 Dec 2006 04:15:34 -0800 Subject: tuple.index() References: Message-ID: <1166098534.704263.20240@l12g2000cwl.googlegroups.com> Nick Maclaren wrote: > Why doesn't the tuple type have an index method? It seems such a > bizarre restriction that there must be some reason for it. In fact, tuples have no non-__underscored__ methods at all. The list count() method would also be useful for tuples, since it doesn't modify anything. I have no idea why they aren't implemented either. Glenn From exarkun at divmod.com Wed Dec 6 09:41:43 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 6 Dec 2006 09:41:43 -0500 Subject: Am I stupid or is 'assert' broken in Python 2.5?? In-Reply-To: <1165415689.347819.129680@73g2000cwn.googlegroups.com> Message-ID: <20061206144143.20948.266284234.divmod.quotient.60143@ohm> On 6 Dec 2006 06:34:49 -0800, antred wrote: >I've noticed something odd in Python 2.5, namely that the 2 argument >version of 'assert' is broken. Or at least it seems that way to me. > >Run the following code in your Python interpreter: > >myString = None > >assert( myString, 'The string is either empty or set to the None type!' >) >assert( myString ) > > > >You'll notice that the first assert doesn't do anything, whereas the >second assert correctly recognizes that myString does not evaluate to >true. That doesn't seem right. Surely Python should have raised an >assertion error on the first assert statement, right?? assert is not a function, it's a keyword. "assert x" raises an AssertionError if "x" evaluates to false. "(myString, "foo")" is a two-tuple. two-tuples are never false. "(myString)" is the same as "myString". From phil_nospam_schmidt at yahoo.com Sun Dec 17 11:28:08 2006 From: phil_nospam_schmidt at yahoo.com (Phil Schmidt) Date: 17 Dec 2006 08:28:08 -0800 Subject: OT : Bug/Issue tracking systems In-Reply-To: <1166350104.375187.287820@16g2000cwy.googlegroups.com> References: <1166338246.113948.320240@l12g2000cwl.googlegroups.com> <1166350104.375187.287820@16g2000cwy.googlegroups.com> Message-ID: <1166370358.888898.291230@73g2000cwn.googlegroups.com> Steven, I have worked with Trac a bit, only to demo it in my company. We ended up not going with it (for reasons not related to Trac), but I found it easy to set up and configure. I seems to be a very nice tool. I especially like the wiki integration, as it makes it really easy to link tickets with supporting information. Phil From adonis at REMOVETHISearthlink.net Thu Dec 28 23:37:58 2006 From: adonis at REMOVETHISearthlink.net (Adonis Vargas) Date: Fri, 29 Dec 2006 04:37:58 GMT Subject: Starting a child process and getting its stdout? In-Reply-To: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> References: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> Message-ID: cypher543 wrote: > This has been driving me insane for the last hour or so. I have search > everywhere, and nothing works. I am trying to use the subprocess module > to run a program and get its output line by line. But, it always waits > for the process to terminate and then return the output all at once. > > Can someone please show me some code that actually works for this sort > of thing? It doesn't even have to use the subprocess module. Don't > worry if the code isn't compatible with Windows. My program is targeted > at Linux/UNIX users. > > Thanks! > try: Python 2.5c1 (r25c1:51305, Aug 17 2006, 17:07:04) [GCC 3.3.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> cmd = "ls" >>> process = subprocess.Popen(cmd, stdout=subprocess.PIPE) >>> print process.stdout.read() For more info on how to do stdin and other things check out: http://docs.python.org/lib/module-subprocess.html Hope this helps. Adonis From imageguy1206 at gmail.com Mon Dec 18 11:24:55 2006 From: imageguy1206 at gmail.com (imageguy1206 at gmail.com) Date: 18 Dec 2006 08:24:55 -0800 Subject: Windows Authetication vs seperate process Message-ID: <1166459095.924198.62170@n67g2000cwd.googlegroups.com> I was wondering of someone could steer me in the right direction. We have a package that we would like to "secure" so that only specific individuals can access specific portions of the application. Our wxPython application will revolve around updating a central database with information submitted from the app. We will eventually have a web front end fo rsome aspects of the app. With several packages I have seen options to "Use Windows Authentication", which seems to mean that "If the user has authenticated and signed onto Windows, then our application will use their windows userid and we will just focus on the the tasks within our application the user is authorized to perform" Does anyone have any experience using this type of authentication scheme ? Any related tips or suggestions ? I have found a few wikipedia entries, but they seem to be more related to webpages, etc. Thanks. From ptmcg at austin.rr._bogus_.com Sat Dec 16 07:00:57 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sat, 16 Dec 2006 12:00:57 GMT Subject: job posting: Sr Systems Programmer needed References: <1166069696.859817.18450@73g2000cwn.googlegroups.com> Message-ID: And why would you even use the word "iceberg" in an ad for a position in Minnesota? You might as well refer to: - the blizzard of opportunties for career growth in this position - how you'll slide through the job startup process as if you were on ice - the comfort of working in a small town, frozen in a simpler time -- Paul From kentilton at gmail.com Sat Dec 16 10:46:59 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 16 Dec 2006 10:46:59 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1166266686.683646.282840@80g2000cwy.googlegroups.com> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <4uhl73F108ri8U1@mid.individual.net> <1166266686.683646.282840@80g2000cwy.googlegroups.com> Message-ID: Kay Schluehr wrote: > Ken Tilton schrieb: > > >>Looks promising. How does a generic engine that sees only a solution (a >>list of mathematical expressions and for each the transformations, >>results, and opnds logged by individual TF functions) build up this >>environment such that it has named attributes such as signed-value? > > > Most likely it doesn't since there is no such engine. Instead local > rules and combinators are encoded in classes. Hence there is nothing > but an object tree and actions are threaded through recursive method > calls. Most likely that is the engine of which I was speaking. :) Why does the engine consisting of "internal" methods make it not an engine? I think you saw the word "engine" and assumed I did not understand OO design. I feel a Naggum coming on... kt ps. This won't make sense unless you know about my Cells project, but the solution to a /problem/ which has attributes expr and instructions, is a declarative attribute of a problem. But that attribute is coded essentially like this: (defclass problem () .... (solution :accessor solution :initform (c-formula () (solve (expr self) (instructions self))))) k > > This implies that the generic reverse function is just the dual of a > method call: > > def reverse(expr): > return expr.reverse() > > What expr does depends on the internal representation encoded in the > class of expr. This also implies that not only the form of the > expression is significant but also its ( dynamic ) type. > -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From steven.bethard at gmail.com Fri Dec 22 13:46:05 2006 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 22 Dec 2006 11:46:05 -0700 Subject: optparser question In-Reply-To: References: Message-ID: <5didnS2r1OZzuhHYnZ2dnUVZ_tSunZ2d@comcast.com> Michele Petrazzo wrote: > Ok, I have not understand the "trickle" for transform the > action="callback" and provide a callback to a new action. Yeah, you're not the only one. ;-) > I believe, however, that the doc has to be more explicit about this > strange behavior, because a not so expert dev (like me :) ), can don't > understand at the first time, it. Yeah, it's pretty complicated. I didn't really understand it until I wrote argparse_ to replace the optparse module. If you have a good idea for how to improve the documentation, I'm sure the maintainers would be grateful. You can post your suggestion here: http://sourceforge.net/tracker/?group_id=5470&atid=105470 You don't need to know LaTeX or anything -- just a simple snippet of text and where in the docs you think it should go is all they need. .. _argparse: http://argparse.python-hosting.com/ STeVe From http Tue Dec 12 01:12:38 2006 From: http (Paul Rubin) Date: 11 Dec 2006 22:12:38 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> Message-ID: <7xejr5y755.fsf@ruckus.brouhaha.com> Robert Brown writes: > Luckily, Willem Broekema has written a Python to Lisp compiler called > clpython that can be consulted to answer questions like these. > > http://trac.common-lisp.net/clpython/ Does this count as a "children of a lesser Python"? How does clpython implement Python's immutable strings, for example? http://dirtsimple.org/2005/10/children-of-lesser-python.html From tayssir.john at googlemail.com Sat Dec 9 18:32:49 2006 From: tayssir.john at googlemail.com (tayssir.john at googlemail.com) Date: 9 Dec 2006 15:32:49 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165700999.744643.207110@73g2000cwn.googlegroups.com> Message-ID: <1165707169.300567.84700@f1g2000cwa.googlegroups.com> mystilleef wrote: > John Thingstad wrote: > > You might even find out if you ever learnt how to use it. > > Donkeys have wings. Please stop misinforming your fellow Python users. Feel free to look up "CLOS" and the "metaobject protocol." Further, Lisp is not a functional language like Scheme; it has unusually powerful iteration and array facilities. Common Lisp's OOP has multiple inheritance, a metaobject protocol, method combinations, generic functions. I realize these sound like buzzwords to you; I vaguely recall this being a nice video intro: Alan Kay coined the term object oriented programming, and I think you'll enjoy his keynote "The computer revolution hasn't happened yet." At 54:30, he praised the book explaining Common Lisp's metobject protocol as being the "best book anybody's written in ten years", for containing "some of the most profound insights, and the most practical insights about OOP, that anybody has done about OOP in the last many years." And he offered a Limoge Balloon award to anyone who'd simply rewrite the book so that the general OOP community could understand it, for being "a great service to mankind." The concepts in that book underlie Lisp's modern OOP system. Further, you portray Lisp as a "functional" language. But it is a powerful iterative language. Check out LOOP, a powerful iteration facility. Check out its powerful multidimensional arrays, which are adjustable and have fill-pointers. There exist legitimate criticisms of Common Lisp, and I've even written a page with "gotchas." One should remain appropriately skeptical of Lisp users' claims, because they too can mislead. I wish we could critique thoughtfully. On the basis of facts, not invented claims. Tayssir From tomas at fancy.org Fri Dec 29 14:52:43 2006 From: tomas at fancy.org (Tom Plunket) Date: Fri, 29 Dec 2006 11:52:43 -0800 Subject: Starting a child process and getting its stdout? References: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> <7vl9p2h7f7adsbn6d6tfpmluera3njnb6g@4ax.com> <1167405767.308530.308800@48g2000cwx.googlegroups.com> Message-ID: <5csap29081ojqg123gphhod0ffq733b45h@4ax.com> cypher543 wrote: > Thank you for the examples, but I have tried all of that before. Did you try my example specifically? > No matter what I do, my program always hangs while it waits for the > process to exit and then it prints all of the output at once. > > self.buildPID = subprocess.Popen(["python", "tobeforked.py"], ... By default, python will execute in buffered mode if it's attached to a pipe. Start it with the '-u' command line option and you may be good to go. (`python -h` for more info on this, man pages may also discuss it.) -tom! -- From Holger.Joukl at LBBW.de Wed Dec 13 06:47:58 2006 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Wed, 13 Dec 2006 12:47:58 +0100 Subject: inconvenient unicode conversion of non-string arguments In-Reply-To: Message-ID: python-list-bounces+holger.joukl=lbbw.de at python.org schrieb am 13.12.2006 12:05:33: > Holger Joukl wrote: > > >>> Ok, but I still don't see why these arguments shouldn't simply be > >>> silently ignored > >> > >> >>> import this > > > > You probably refer to "Explicit is better than implicit.". > > "Errors should never pass silently." is a better match, I think. you're > trying to do an invalid operation. python tells you to fix your code. > > I'm not doing an invalid operation with unicode(17.3) What's invalid about unicode(17.3, "latin-1", "replace")? IMHO the encoding/errors args can only ever apply for string arguments so this could well fall back to unicode(17.3). Might be I'm overlooking something grave, but I'm still not convinced. But thanks for your advice, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From gherron at islandtraining.com Sun Dec 24 16:27:16 2006 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 24 Dec 2006 13:27:16 -0800 Subject: terminology question - "foreign function library" In-Reply-To: <1166980601.668105.256770@a3g2000cwd.googlegroups.com> References: <1166980601.668105.256770@a3g2000cwd.googlegroups.com> Message-ID: <458EF0B4.3020700@islandtraining.com> mirandacascade at yahoo.com wrote: > I am prompted to make these inquiries after seeing the following link > to ctypes: > > http://docs.python.org/lib/module-ctypes.html > > in which ctypes is described as a foreign function library. > > What is the definition of "foreign function library"? > Is the concept different from a "package"? > Is the concept different from a "module"? > Neither. If you have a library, completely unrelated to Python, but you would like to make calls into it from Python, there are several ways to proceed. (A good example of such a library is the OpenGL library: C:/WINDOWS/SYSTEM32/opengl32.dll.) You can craft an extension to Python, written in C perhaps and linked to the DLL in question, that provides functions which can be called from Python and which make the appropriate calls into the DLL. (Several products help with building of such an extension module, SWIG being the one I've used.) A newer alternative to building such extensions is ctypes. If you can discern (from the documentation) the exact calling parameters footprint to a function in a DLL, then ctypes can directly call that function with your parameters. This is done directly in Python and ctypes without the need for building any extension module. Gary Herron > Thank you. > > From nick at craig-wood.com Mon Dec 4 06:30:04 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 04 Dec 2006 05:30:04 -0600 Subject: os.mkdir and mode References: <1165043870.135812.232530@73g2000cwn.googlegroups.com> Message-ID: Peter Otten <__peter__ at web.de> wrote: > >> "Where it is used, the current umask value is first masked out." > >> > >> Use os.chmod() after os.mkdir() to get the desired permissions. > > > > I think you meant use os.umask(0) before the os.mkdir() ? > > No, I didn't. What is the difference/advantage of that approach? If you use use os.umask(0) then the os.mkdir(dir, perms) will create the directory with exactly those permissions, no chmod needed. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From atkinw at rpi.edu Sat Dec 9 18:09:18 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 18:09:18 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165703407.362890.23780@l12g2000cwl.googlegroups.com> Message-ID: Bill Atkins writes: > worried about the future of Lisp libraries. We already have some: > > - CL-PPCRE, a pure-Lisp regular expression package that is faster than Perl's > - Hunchentoot, a complete web server and web development framework > - CAPI, a proprietary but excellent GUI library > - CommonSQL (and CLSQL, its open-source offspring) > - parenscript, an embeddable Lisp that compiles to Javascript, letting > you use macros in your Javascript code > - assorted useful libraries, like MD5, base64, SDL, XML parsers, web > page fetchers, testing frameworks > - bindings to the common C libraries, like GD, Tk, Gtk+ Lest anyone interpret that list as exhaustive: http://www.cl-user.net/ From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 21:57:37 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 13:57:37 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165596641.245385.113090@f1g2000cwa.googlegroups.com> <1165704007.887869.192290@16g2000cwy.googlegroups.com> Message-ID: On Sat, 09 Dec 2006 14:40:07 -0800, webraviteja wrote: > Personally, I find it strange that we, who argued so many times for > dynamic typing, the need for expressiveness and that it is OK to trust > the programmer with power ("we are all adults here" argument) while > arguing against relatively restrictive languages like Java find macros, > a chaotic and disruptive concept. Why? The benefit of expressiveness and power isn't monotonically increasing. Look at us: we're all communicating in a common language, English, and we all agree on syntax and grammar. Now, I could be a lot more expressive, and language could be a lot more powerful, if I could define my own language where "You are a poopy-head" was in fact a detailed and devastatingly accurate and complete explanation for why Python was a better language than Lisp. You, however, not being an expert in my far greater expressive language, would see none of that, and would be under the mistaken impression that I was insulting you. So it is good that English restricts the expressiveness and power of the syntax and grammar. While we're talking English, we can both understand each other, and in fact people who redefine words and ignore the common meaning of them are often covering weaknesses in their arguments. The same goes for programming languages. Extra expressiveness comes at the cost of reduced communication between programmers -- the code becomes harder to read for those who haven't already learnt how to read it. So there is no contradiction in the positions that "we are all adults here" and "macros give too much power". The first is a design decision, the second is a trade-off, just like the lack of C-style pointers in Python is a trade-off. -- Steven. From meesters at uni-mainz.de Tue Dec 19 09:37:30 2006 From: meesters at uni-mainz.de (Christian Meesters) Date: Tue, 19 Dec 2006 15:37:30 +0100 Subject: Is htmlGen still alive? References: <1166474264.348556.118510@n67g2000cwd.googlegroups.com> Message-ID: If starship does not get up anymore (give it a few hours) you might want to have a look here: http://www.python.org/ftp/python/contrib-09-Dec-1999/Network/ Else, I can send you a tarfile of version 2.1, too. As hg said, apart from a few deprecation warnings it's working fine for me (but I'm only using it for one internal site, where layout doesn't matter ...). Cheers Christian kgmuller at gmail.com wrote: > Does anybody know whether htmlGen, the Python-class library for > generating HTML, is still being maintained? Or from where it can be > downloaded? The Starship site where it used to be hosted is dead. > > Thanks for your help! > > Klaus Muller From pavlovevidence at gmail.com Fri Dec 8 20:28:04 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 8 Dec 2006 17:28:04 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> Message-ID: <1165627684.709241.86340@16g2000cwy.googlegroups.com> JShrager at gmail.com wrote: > Okay, since everyone ignored the FAQ, I guess I can too... [snip] > What Python has is stupid slogans > ("It fits your brain." "Only one way to do things.") and an infinite > community of flies that, for some inexplicable reason, believe these > stupid slogns. IOW, you posted the FAQ so you could appear to have highest moral ground, then you ignore your own advice and promptly head to the very lowest ground with ad hominem insults. Congratulations! That was quite a turnaround. (In fact, it was almost as a big a turnaround as a typical newbie who tries Lisp.) Carl Banks From mcfletch at vrplumber.com Sat Dec 9 21:21:16 2006 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Sat, 09 Dec 2006 21:21:16 -0500 Subject: pyopengl glShaderSourceARB error In-Reply-To: <1165360495.840814.276610@j44g2000cwa.googlegroups.com> References: <1165360495.840814.276610@j44g2000cwa.googlegroups.com> Message-ID: <457B6F1C.5000801@vrplumber.com> joroy wrote: > Hi all, > > I think this is ctypes related but how can I call the glShaderSourceARB > function? > > The function have this header: > > glShaderSourceARB( GLhandleARB(shaderObj), GLsizei(count), > POINTER(arrays.GLcharARBArray)(string), GLintArray(length) ) -> None > > I call the function with someting like: glShaderSourceARB(self._object, > 1, sourceString, 1) > > The error is > "expected LP_GLcharArray instance instead of str" > > In fact I don't have any information on how to use this function. > This is the last version of pyopengl available on the CVS > (PyOpenGL-3.0.0a5-py2.5.egg) > Sorry about the lack of information available. There's a sample of usage here (known to work on Win32 and Linux with latest CVS HEAD): http://pyopengl.cvs.sourceforge.net/pyopengl/OpenGLContext/tests/shaderobjects.py?view=markup The key information you seem to be missing are that the Python version has a simpler API and that you have to pass an array (list) of strings, not just a single string to the compilation function. The count and length (array of lengths) parameters are pulled from the list-of-strings you pass. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From __peter__ at web.de Mon Dec 11 14:11:13 2006 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Dec 2006 20:11:13 +0100 Subject: Sorting Multidimesional array(newbie) References: <20061211193104.40fe7985.tartifola@gmail.com> <1165863508.967414.70350@73g2000cwn.googlegroups.com> Message-ID: Matimus wrote: > Tartifola wrote: >> Hi, >> how can I sort an array like >> >> array([[5, 2], >> [1, 3]]) >> >> along the first column to obtain >> >> array([[1, 3], >> [5, 2]]) >> i.e. keeping track of the ordered couples? >> >> Thanks, >> A > > use a sort key: > >>>>from operators import getitem >>>>a = [[5,2],[1,3]] >>>>a > [[5, 2], [1, 3]] >>>>a.sort(key=lambda x:getitem(x,0)) >>>>a > [[1, 3], [5, 2]] Is that a faked session? >>> from operators import getitem Traceback (most recent call last): File "", line 1, in ImportError: No module named operators >>> from operator import itemgetter >>> a = [[5, 2], [1, 3]] >>> a.sort(key=itemgetter(0)) >>> a [[1, 3], [5, 2]] Peter From fredrik at pythonware.com Thu Dec 21 16:08:19 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 21 Dec 2006 22:08:19 +0100 Subject: Decorator for Enforcing Argument Types In-Reply-To: <1166734180.455471.164910@79g2000cws.googlegroups.com> References: <1166734180.455471.164910@79g2000cws.googlegroups.com> Message-ID: Chris wrote: > I'm not sure if this has been done before see example 4 in the original specification: http://www.python.org/dev/peps/pep-0318/#examples From mike.klaas at gmail.com Fri Dec 1 17:09:51 2006 From: mike.klaas at gmail.com (Klaas) Date: 1 Dec 2006 14:09:51 -0800 Subject: Is python memory shared between theads? In-Reply-To: <1164993654.445974.60170@73g2000cwn.googlegroups.com> References: <1164987833.233073.265170@80g2000cwy.googlegroups.com> <1164993654.445974.60170@73g2000cwn.googlegroups.com> Message-ID: <1165010991.889852.189360@79g2000cws.googlegroups.com> John Henry wrote: > Wesley Henwood wrote: > > Is this normal behavior? Based on the little documentation I have been > > able to find on this topic, it is normal behavior. The only way to use > > same-named variables in scripts is to have them run in a different > > process, rather than different threads. > > Yes and No. > > local variables are local to each threads. Global variables are > global to the threads. That is somewhat misleading. _All_ variables accessible from two threads are shared. This includes globals, but also object attributes and even local variables (you could create a closure to share a local among threads). The only reason locals appear "thread-local" is that locals are "invokation-local" in that they are different bindings every time a function is executed, and generally a single invokation of a function is confined to a single thread. Another way to share local variables is to create a generator, and call .next() in two different threads... the local variables are simulatneously modifiable by both threads. FWIW, there is also threading.local(). -MIke From Eric_Dexter at msn.com Fri Dec 1 21:54:23 2006 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: 1 Dec 2006 18:54:23 -0800 Subject: strange problems with code generation In-Reply-To: <1165025792.522242.281730@l12g2000cwl.googlegroups.com> References: <1165022658.313170.134140@79g2000cws.googlegroups.com> <1165025792.522242.281730@l12g2000cwl.googlegroups.com> Message-ID: <1165028063.205065.75360@n67g2000cwd.googlegroups.com> John Machin wrote: > Eric_Dexter at msn.com wrote: > > I am writing out zero byte files with this (using python 2.5). I have > > no idea why I am having that problem > > Which output file(s) do you mean, temp.orc or temp.sco or both? > Two possible causes outlined below. > > > I am also looking for an example > > of readlines where I can choose a number of lines say lines 12 to 14 > > and then write them back to disk. > > To the same file? There was a long thread on updating text files very > recently. > > > any help would be apreaceted. > > Have you considered deploying a spelling checker? > > > > > import sys as sys2 > > import os as os2 > > Why the obfuscation? > > > > > def playscoreinrange(from_file, fromline, toline): > > "untested way to play a series of lines from a orc, sco combination > > line 14 may not be correct" > > and which is line 14?? According to my count, it is the blank line > after "outfile2 = open('temp.orc', 'w') "!! > > > print(from_file) > > fromfile = os2.path.basename(from_file) > > print(fromfile) > > > > orcfilename = fromfile[:-4] + '.orc' > > print(orcfilename) > > infile2 = open(orcfilename, 'r') > > outfile2 = open('temp.orc', 'w') > > > > for line in infile2: > > outfile2.write(line) > > > > > > infile = open(fromfile, 'r') > > infile is not used > > > outfile = open('temp.sco','w') > > > > data = sys2.stdin.readlines() > > print(data) > > and how many lines were there in data when you printed it? > > > for linenumber in range(fromline, toline): > > Consider the possibility that fromline >= toline (which may be caused > by either or both not being of a numerical type). > > Did you mean range(fromline, toline + 1) ? > > do this: > print repr(fromline), type(fromline) > print repr(toline), type(toline) > > BTW, print is a *statement*, not a function! > > > outfile.writeline(data[linenumber]) > > outfile.writeline() ??? > > | Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > (Intel)] on win > 32 > | Type "help", "copyright", "credits" or "license" for more > information. > | >>> f = open('fubar.txt', 'w') > | >>> f.writeline('bzzzzt!\n') > | Traceback (most recent call last): > | File "", line 1, in > | AttributeError: 'file' object has no attribute 'writeline' > > So, the body of your loop wasn't executed (or you overlooked the > exception, or that wasn't the code that was executed) -- so it looks > like the range was empty (or the problem occurred further upstream). > > > https://sourceforge.net/projects/dex-tracker > > http://www.dexrow.com > > > > > > os2.startfile('temp.bat') > > and what does this do?? Read temp.orc and/or temp.sco before you've > closed the file(s)? > > Where is the code that was used to call this playscoreinrange function? > > HTH, > John temp bat is csound temp.orc temp.sco and it plays the new files I can try closing the other files first. I am sure the readlines code is crashing it. Because I have moved it befour the code that is reading a line at a time and it would not even write the second zero byte file. The comment line is an old line that I did not update when I made changes. The code that calls it was auto-generated but boa-constructer .44 (I haven't updated it yet). #Boa:Dialog:Dialog2 import wx import csoundroutines2 def create(parent): return Dialog2(parent) [wxID_DIALOG2, wxID_DIALOG2BUTTON1, wxID_DIALOG2STATICTEXT1, wxID_DIALOG2STATICTEXT2, wxID_DIALOG2TEXTCTRL1, wxID_DIALOG2TEXTCTRL2, ] = [wx.NewId() for _init_ctrls in range(6)] class Dialog2(wx.Dialog): From_File = '' def _init_ctrls(self, prnt): # generated method, don't edit wx.Dialog.__init__(self, id=wxID_DIALOG2, name='', parent=prnt, pos=wx.Point(759, 203), size=wx.Size(420, 72), style=wx.DEFAULT_DIALOG_STYLE, title='play csound lines') self.SetClientSize(wx.Size(412, 38)) self.Bind(wx.EVT_RIGHT_DCLICK, self.OnDialog2RightDclick) self.textCtrl1 = wx.TextCtrl(id=wxID_DIALOG2TEXTCTRL1, name='textCtrl1', parent=self, pos=wx.Point(56, 8), size=wx.Size(100, 21), style=0, value='test') self.textCtrl2 = wx.TextCtrl(id=wxID_DIALOG2TEXTCTRL2, name='textCtrl2', parent=self, pos=wx.Point(216, 8), size=wx.Size(100, 21), style=0, value='') self.staticText1 = wx.StaticText(id=wxID_DIALOG2STATICTEXT1, label='from line', name='staticText1', parent=self, pos=wx.Point(8, 8), size=wx.Size(41, 13), style=0) self.staticText1.SetToolTipString('From Line') self.staticText1.SetBackgroundStyle(wx.BG_STYLE_SYSTEM) self.staticText1.SetForegroundColour(wx.Colour(255, 0, 0)) self.staticText2 = wx.StaticText(id=wxID_DIALOG2STATICTEXT2, label='To Line', name='staticText2', parent=self, pos=wx.Point(168, 8), size=wx.Size(34, 13), style=0) self.staticText2.SetForegroundColour(wx.Colour(255, 0, 0)) self.button1 = wx.Button(id=wxID_DIALOG2BUTTON1, label='play', name='button1', parent=self, pos=wx.Point(328, 8), size=wx.Size(75, 23), style=0) self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button, id=wxID_DIALOG2BUTTON1) def __init__(self, parent): self._init_ctrls(parent) def OnDialog2RightDclick(self, event): fromline = int(self.textCtrl1.GetValue(self)) toline = int(self.textCtrl2.GetValue(self)) csoundroutines2.playscoreinrange(From_File, fromline, toline)#needs filename def OnButton1Button(self, event): fromline = int(self.textCtrl1.GetValue()) toline = int(self.textCtrl2.GetValue()) csoundroutines2.playscoreinrange(self.From_File, fromline, toline)#needs filename https://sourceforge.net/projects/dex-tracker From at at tuko.nl Wed Dec 13 17:34:15 2006 From: at at tuko.nl (at) Date: Wed, 13 Dec 2006 23:34:15 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <1166037038.450004.223290@80g2000cwy.googlegroups.com> Message-ID: <45807fe3$0$328$e4fe514c@news.xs4all.nl> No offense, but my conclusions from your mail is that readability is a matter of taste. My brains need to process a whole lot more information with your solution than in my proposal... but I read somewhere else that GvR rejected the proposal :-( Ciao, @ shandy.b at gmail.com wrote: > The proposed solution impairs readability because there's a "surprise" > at the end. List comprehensions already open the language up to > readability abuse. Lets not add more. > > To avoid the unwanted indentation, I would go with the already > suggested "if not x>0: continue" solution or else something like this: > > positiveMembers = [x for x in [-2, -1, 0, 1, 2, 3, 4] if x>0] > for x in positiveMembers: > #do stuff > > This has the advantage of being more self-documenting. > > at wrote: >> I would like to spark the discussion about the following syntax problem I >> encounter. >> >> THE PROBLEM >> >> I have a lot times the following code: >> >> for x in [-2, -1, 0, 1, 2, 3, 4]: >> if x > 0: >> ... more code... >> >> >> It is not the addional line containing 'if x > 0:' that bothers me, but >> the additional indentation. >> >> >> THE SOLUTION >> >> More pythonic in view would be: >> >> for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0: >> ... more code ... >> >> >> This blends basically >> >> [x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0] >> >> and >> >> x = y if x > 0 else 10 >> >> >> EXTENDING >> >> And maybe a few usefull variants, like: >> >> for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0 else -x: >> ... more code ... >> >> In this case x will be 2, 1, 0, 1, 2, 3, 4. From bignose+hates-spam at benfinney.id.au Wed Dec 27 18:09:56 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 28 Dec 2006 10:09:56 +1100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: <87wt4daqbf.fsf@benfinney.id.au> "Sebastian 'lunar' Wiesner" writes: > Just a tip for you: In python you never use tabs for indentation. For some value of "you". > The python style guide [1] recommends four spaces per indentation > level. > > [1] http://www.python.org/dev/peps/pep-0008/ It's not quite absolute on the topic: For new projects, spaces-only are strongly recommended over tabs. -- \ "I filled my humidifier with wax. Now my room is all shiny." | `\ -- Steven Wright | _o__) | Ben Finney From theller at ctypes.org Fri Dec 15 12:10:13 2006 From: theller at ctypes.org (Thomas Heller) Date: Fri, 15 Dec 2006 18:10:13 +0100 Subject: Has comparison of instancemethods changed between python 2.5 and 2.4? In-Reply-To: <4582CFA3.5040305@niessink.com> References: <4582CFA3.5040305@niessink.com> Message-ID: Frank Niessink schrieb: [...] > Now, with Python 2.5 (and not with Python 2.4) I have a callback that is > not being added to the list because, apparently, it compares equal to > some of the callbacks already in the list. However, the instance the two > methods belong to are different, i.e. id(callback) returns different > values for the two methods. Both callbacks are of type 'instancemethod'>. Further investigation shows that "observer == > observerList[1]" is True. > > Has instancemethod.__cmp__ changed between python 2.4 and 2.5? > It seems so: python -c "o = object(); print o.__str__ == o.__str__" prints True with Python 2.5, and False with Python 2.4. Thomas From kj7ny at nakore.com Thu Dec 28 21:35:15 2006 From: kj7ny at nakore.com (kj7ny) Date: 28 Dec 2006 18:35:15 -0800 Subject: Comparing files in a zip to files on drive Message-ID: <1167359715.387219.250660@73g2000cwn.googlegroups.com> I am attempting to incrementally back up files using python. How can I compare a file on a hard drive to a file in a python created zip file to tell if the file has changed? Or should I be using some other method to determine if a file has changed? From kentilton at gmail.com Sun Dec 10 02:03:11 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sun, 10 Dec 2006 02:03:11 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165731005.529088.227360@j44g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <1165731005.529088.227360@j44g2000cwa.googlegroups.com> Message-ID: Wolfram Fenske wrote: > Steven D'Aprano schreibt: ... >>Some languages are too expressive. > > > I disagree. "Too expressive"--what a thing to say. A sad moment in Usenet discourse... a moment of silence, please. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From surekap at gmail.com Thu Dec 14 18:20:19 2006 From: surekap at gmail.com (Prateek) Date: 14 Dec 2006 15:20:19 -0800 Subject: Python Unpickler for Java Message-ID: <1166138419.058674.243830@j72g2000cwa.googlegroups.com> Hey guys, I've started work on JUnpickler - an Unpickler for Java. The Jython project has been going a little slow lately so I thought this would be a nice addition to the community (plus I'll probably need it for my work anyway) - So here is a bit of code I wrote (its my first open source contribution) which takes pickle data (protocol 2) and deserializes it into a Java object. http://code.brainwavelive.com/unpickler I plan to use this in conjunction with a different process running a Pyro daemon for IPC based object passing. Thoughts? Comments? Contributors? Prateek Sureka http://www.brainwavelive.com From noway at ask.me Thu Dec 7 06:13:20 2006 From: noway at ask.me (Giovanni Bajo) Date: Thu, 07 Dec 2006 12:13:20 +0100 Subject: len() and PEP 3000 In-Reply-To: <4tnqlkF13bbqeU1@mid.individual.net> References: <4tnqlkF13bbqeU1@mid.individual.net> Message-ID: <5HSdh.15210$P04.6844@tornado.fastwebnet.it> Thomas Guettler wrote: > I have read the FAQ to the len function: > http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list Outdated. You want to read the new FAQ, here: http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm -- Giovanni Bajo From laurent.pointal at limsi.fr Wed Dec 6 09:44:58 2006 From: laurent.pointal at limsi.fr (Laurent Pointal) Date: Wed, 06 Dec 2006 15:44:58 +0100 Subject: Am I stupid or is 'assert' broken in Python 2.5?? In-Reply-To: <1165415689.347819.129680@73g2000cwn.googlegroups.com> References: <1165415689.347819.129680@73g2000cwn.googlegroups.com> Message-ID: antred a ?crit : > I've noticed something odd in Python 2.5, namely that the 2 argument > version of 'assert' is broken. Or at least it seems that way to me. > > Run the following code in your Python interpreter: > > myString = None > > assert( myString, 'The string is either empty or set to the None type!' > ) > assert( myString ) > > You'll notice that the first assert doesn't do anything, whereas the > second assert correctly recognizes that myString does not evaluate to > true. That doesn't seem right. Surely Python should have raised an > assertion error on the first assert statement, right?? What you see is correct. Here is a test under Python 2.4: >>> myString = None >>> assert myString, "It is empty" Traceback (most recent call last): File "", line 1, in ? AssertionError: It is empty >>> assert (myString, "It is empty") If you use parenthesis to group the condition to test and the error message, then the whole created tuple is used as a condition to test... and this condition is true so assert dont raise any exception. So, just remove your parenthesis and all will go the expected way. A+ Laurent. From fredrik at pythonware.com Wed Dec 20 04:38:54 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 10:38:54 +0100 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Sebastian 'lunar' Wiesner wrote: > No, they aren't! Try this: you're confusing the shell's "is this file executable" check with the loader's "can I execute this file" check: $ export PATH=.:$PATH $ dd if=/dev/zero of=ls count=1 1+0 records in 1+0 records out $ ls -l ls -rw-rw-r-- 1 slab slab 512 Dec 20 03:33 ls $ chmod a+x ls $ ls -bash: ./ls: cannot execute binary file From greg at cosc.canterbury.ac.nz Tue Dec 12 22:07:20 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 13 Dec 2006 16:07:20 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1165947259.337340.121110@n67g2000cwd.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165867527.389209.80660@f1g2000cwa.googlegroups.com> <1165947259.337340.121110@n67g2000cwd.googlegroups.com> Message-ID: <4u9963F16pm7hU5@mid.individual.net> George Sakkis wrote: > I'm sure there should be more convincing examples for macros, but > neither this nor the 'unless' syntax sugar cuts it. Also, the new 'with' statement and associated protocol covers much of the ground that was left out by the existing constructs. -- Greg From timr at probo.com Wed Dec 20 00:51:28 2006 From: timr at probo.com (Tim Roberts) Date: Wed, 20 Dec 2006 05:51:28 GMT Subject: def index(self): References: <4587017b$0$22957$426a34cc@news.free.fr> <458807cc$0$19743$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > >Gert Cuykens a ?crit : >>> FWIW, the first version raises an exception (unless of course the name >>> 'index' is already bound in the enclosing scope). And the second won't >>> probably work as expected with CherryPy. >> >> >> class HelloWorld: >> def index(self): >> return "Hello world!" >> index.exposed = True #DOOOOOOH! > >And the winner is.... > >> > >The whole thing, I guess. While Python is quite easy to get started >with, there are a few gotchas. You're above snippet should be: > >class HelloWorld(object): > def index(self): > return "Hello World" > index.exposed = True Many people find it more readable to write that as: class HelloWorld(object): @cherrypy.exposed def index(self): return "Hello World" I haven't decided yet. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From chrisspen at gmail.com Sat Dec 23 10:57:38 2006 From: chrisspen at gmail.com (Chris) Date: 23 Dec 2006 07:57:38 -0800 Subject: Add/Remove Channels in Asyncore? Message-ID: <1166889458.844414.87500@42g2000cwt.googlegroups.com> I've implemented a real basic IRC client class in 100 lines using asynchat (yes I know about Twisted). The problem I'm having is arbitrarily starting and stopping multiple instances of this class after I call loop(). The asyncore docs seem to imply everything's fixed in stone once loop() is called, where they say, "Once the initial channel(s) is(are) created, calling the loop() function activates channel service, which continues until the last channel (including any that have been added to the map during asynchronous service) is closed." After I call asyncore.loop(), I'd like to be able to add/remove clients ("channels"?) to/from execution by asyncore. Is this possible? Thanks, Chris From sjmachin at lexicon.net Wed Dec 20 01:24:24 2006 From: sjmachin at lexicon.net (John Machin) Date: 19 Dec 2006 22:24:24 -0800 Subject: Fall of Roman Empire In-Reply-To: References: <20061220054657.7CEEA1E4006@bag.python.org> Message-ID: <1166595864.797404.260570@n67g2000cwd.googlegroups.com> Ben Finney wrote: > \ "...one of the main causes of the fall of the Roman Empire was | > `\ that, lacking zero, they had no way to indicate successful | > _o__) termination of their C programs." -- Robert Firth | An amusing .sig, but it doesn't address the root cause: As they had no way of testing for the end of a string, in many cases successful termination of their C programs would have been unlikely. Cheers, John From atkinw at rpi.edu Sat Dec 9 18:12:08 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 18:12:08 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165627684.709241.86340@16g2000cwy.googlegroups.com> <1165685950.758858.18960@n67g2000cwd.googlegroups.com> <1165702377.897545.22510@79g2000cws.googlegroups.com> Message-ID: "Carl Banks" writes: >> You're right, in part: My implicitly linking Python's pros or cons with >> its stupid marketing hype is, I think, an ad hominem argument. > > Ahem. Calling Python programmers "flies". For what it's worth, I don't think this was called for, either. > Whatever, fanboy. Weak. From duncan.booth at invalid.invalid Wed Dec 6 09:35:13 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Dec 2006 14:35:13 GMT Subject: Windows: get owner and group of a file References: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> Message-ID: Fredrik Lundh wrote: > Tim Golden wrote: > >> Wow. Python 2.2. No extensions. Not even popen (). You don't >> want much, do you? I *think* the answer is that you can't. > > does the "group" concept even exist on Windows ? cannot recall I've > ever seen "ls -l" print anything but "everyone"... Domain users have a 'primary group'. Actually, contrary to what I said in the previous post I'm not sure that files have the concept. It may just be users and the actual group permissions then get stored on the file. If so and if you assigned any other groups permission on the file you may not be able to distinguish which is the original group for the file and which was added later. From Thomas.Ploch at gmx.net Wed Dec 20 11:27:52 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Wed, 20 Dec 2006 17:27:52 +0100 Subject: Fall of Roman Empire In-Reply-To: <45892D76.2050002@gmx.net> References: <20061220054657.7CEEA1E4006@bag.python.org> <1166595864.797404.260570@n67g2000cwd.googlegroups.com> <873b7b6one.fsf@benfinney.id.au> <45892D76.2050002@gmx.net> Message-ID: <45896488.6040309@gmx.net> > Ben Finney schrieb: >> "John Machin" writes: >> >>> Ben Finney wrote: >>> >>>> \ "...one of the main causes of the fall of the Roman Empire was | >>>> `\ that, lacking zero, they had no way to indicate successful | >>>> _o__) termination of their C programs." -- Robert Firth | >>> An amusing .sig, but it doesn't address the root cause: As they had no >>> way of testing for the end of a string, in many cases successful >>> termination of their C programs would have been unlikely. >> Yet historically proven: the 'imperium' process they were running >> terminated many centuries ago. >> >> Or did it fork and exec a different process? >> I rather stay with the metaphysics: #include "metaphysics.h" static metaPower God; universe *makeUniverse(metaPower God) { if (!God) { printf("Oops, no God available at the moment.Try again later!"); return NULL; } universe *everything; if (!(everything = malloc(sizeof(universe)))) { God.mood = REALLY_BORED; printf("God has no time to create a universe."); return NULL; } else { return universe; } } :-) Sorry, somehow had to do this. Please slap me (i like it, don't worry) if it's totally stupid From arkanes at gmail.com Mon Dec 4 10:07:54 2006 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 4 Dec 2006 09:07:54 -0600 Subject: WxPython In-Reply-To: <1165148048.517865.156840@f1g2000cwa.googlegroups.com> References: <1165148048.517865.156840@f1g2000cwa.googlegroups.com> Message-ID: <4866bea60612040707v6c5573ebp401bcceef061740d@mail.gmail.com> On 3 Dec 2006 04:14:08 -0800, Raja wrote: > Hi, > I am trying to develop an application which would mainly do the > following 2 things . I would like to know how it can be achieved and > also the libraries needed for it . > > i) active window tracking > In this substate, the application records the title bar > contents of the active/foreground window > and how long, in seconds, that that window is active/in > the foreground. If the same window > remains in the foreground but the title bar changes (as > happens with a web browser application) then a new record is created > for each new window title. If a window title is recorded that > was previously recorded (on the same date -- see "Data > Structures" info in section 4.4), > then the time should be added to the previously recorded > active time for that window title. > -- Example -- > 1) User clicks "Start" -> app enters "recording" state. > 2) User opens window titled "Window 1" -> app looks for > any prior records for "Window 1" > on current date. Finding none, it creates a new > record. > 3) User opens another window titled "Window 2" -> app > records total time spent in "Window 1", then looks for any prior > records for "Window 2" on current date. Finding none, > it creates a new record. > 4) User re-raises/re-activates previous window "Window > 1" -> app records total time spent > in "Window 2", then looks for any prior records for > "Window 1" on current date. It finds > the record created earlier, so no new record is > created. > 5) User clicks "Stop" (or "Exit") -> the app adds the > time just spent in "Window 1" to the > previously recorded time spent in "Window 1". App > then returns to "ready" state. > ii) idle > In this substate, the app has detected that the computer's > screensaver is active and no time > will be recorded for the active/foreground window. This > substate is entered automatically > (from the active window tracking state) when the > screensaver activates and exited > automatically (returning to the active window tracking > state) when the screensaver is > deactivated. Note that this substate should only be > entered if the app was in the active > window tracking state when the screensaver activated. > > > Awaiting Your Reply, > Thank You , > Raja. > wxPython is a toolkit for writing interfaces, and most of the functionality you want are systems tasks. wxPython can provide the UI, but for the system calls you'll need to use the pywin32 module or ctypes to work directly with the win32 api. From at at tuko.nl Thu Dec 14 02:11:28 2006 From: at at tuko.nl (at) Date: Thu, 14 Dec 2006 08:11:28 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <4ubv67F17ggcuU1@mid.individual.net> Message-ID: <4580f91d$0$329$e4fe514c@news.xs4all.nl> Hi Greg, Well point is that the condition is the only thing happening and does not really apply to the indented code section, but basically to the list used in the indented code section. When I read this code back its like, 'oh we use this list' and by the if some_condition the next thing I think is 'hm, not all of the list' and even worse should I worry if more restrictions can be found when I read further... All the best, @ greg wrote: > at wrote: > >> It is not the addional line containing 'if x > 0:' that bothers me, but >> the additional indentation. > > I don't find the additional indentation bothersome. > In fact I think it's helpful, because it makes it > obvious that there is something else going on besides > just a loop. > > -- > Greg From http Fri Dec 8 20:15:32 2006 From: http (Paul Rubin) Date: 08 Dec 2006 17:15:32 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Message-ID: <7xodqdj2dn.fsf@ruckus.brouhaha.com> "JShrager at gmail.com" writes: > > There is (IMO) some truth to that, but the flavor of Python > > programming is not that much like Lisp any more. Especially with > > recent Python releases (postdating that Norvig article) using iterator > > and generator objects (basically delayed evaluation streams) more > > heavily, Python is getting harder to describe in Lisp terms. It's > > moving more in the direction of Haskell. > > Sorry, I missed something here. Why do you need a release to have these > sorts of things? Can't you just expand the language via macros to > create whatever facility of this sort you need... Huh? Are you saying Lisp systems never release new versions? And you can't implement Python generators as Lisp macros in any reasonable way. You could do them in Scheme using call-with-current-continuation but Lisp doesn't have that. > Oh, sorry. You CAN'T > expand the language.... Too bad. I guess waiting for Guido to figure > out what Fits Your Mind is part of The Python Way. Now I begin to think you're trolling. From sjmachin at lexicon.net Wed Dec 6 05:22:44 2006 From: sjmachin at lexicon.net (John Machin) Date: 6 Dec 2006 02:22:44 -0800 Subject: Novice: replacing strings with unicode variables in a list In-Reply-To: <1165397220.491511.159310@f1g2000cwa.googlegroups.com> References: <1165397220.491511.159310@f1g2000cwa.googlegroups.com> Message-ID: <1165400564.866573.13300@f1g2000cwa.googlegroups.com> aine_canby at yahoo.com wrote: > Hi, > > Im totally new to Python so please bare with me. > > Data is entered into my program using the folling code - > > str = raw_input(command) > words = str.split() > > for word in words: > word = unicode(word,'latin-1') > word.encode('utf8') The above statement produces a string in utf8 and then throws it away. It does not update "word". To retain the utf8 string, you would have to do word = word.encode('utf8') and in any case that won't update the original list. *** missing source code line(s) here *** > > This gives an error: *** missing traceback lines here *** > File "C:\Python25\lib\encodings\cp850.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in > position 0 > : character maps to No, it doesn't. You must have put "print word" to get the error that you did. *Please* when you are asking a question, copy/paste (1) the exact source code that you ran (2) the exact traceback that you got. > > but the following works. What do you mean by "works"? It may not have triggered an error, but on the other hand it doesn't do anything useful. > > str = raw_input(command) > words = str.split() > > for word in words: > uni = u"" Above line is pointless. Removing it will have no effect > uni = unicode(word,'latin-1') > uni.encode('utf8') Same problem as above -- utf8 string is produced and then thrown away. > > so the problem is that I want replace my list with unicode variables. > Or maybe I should create a new list. > > I also tried this: > > for word in words[:]: > word = u"" > word = unicode(word,'latin-1') You got the error on the above statement because you are trying (pointlessly) to decode the value u"". Decoding means to convert from some encoding to unicode. > word.encode('utf8') Again, utf8 straight down the gurgler. > print word This (if executed) will try to print the UNICODE version, and die [as in the 1st example] encoding the unicode in cp950, which is the encoding for your Windows command console. > > but got TypeError: decoding Unicode is not supported. > > What should I be doing? (1) Reading the Unicode howto: http://www.amk.ca/python/howto/ (2) Writing some code like this: | >>> strg = "\x94 foo bar zot" | >>> words = strg.split() | >>> words | ['\x94', 'foo', 'bar', 'zot'] | >>> utf8words = [unicode(word, 'latin1').encode('utf8') for word in words] | >>> utf8words | ['\xc2\x94', 'foo', 'bar', 'zot'] | >>> HTH, John From luc at honk-honk.com Tue Dec 19 02:36:06 2006 From: luc at honk-honk.com (Luc Heinrich) Date: Tue, 19 Dec 2006 08:36:06 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> Message-ID: <1hql31u.d0shpb5dprk0N%luc@honk-honk.com> Peter Decker wrote: > I don't have a Mac, although I would certainly like one. But one of > the two authors of Dabo is a Mac user, and says that he does all his > development on a Mac, and then tests it on the other platforms. Look > at the screencasts on the Dabo site - most of them are recorded on OS > X. Yeah, I have watched three of them and they are glaring examples of what I'm talking about. The applications presented not only don't look right, at all, they apparently don't feel right either. > OK, it's true: you don't have 100% access to the lickable Aqua stuff > that a Cocoa app might be able to use. But paged controls use native > Aqua tabs; progress bars are native Aqua bars, buttons are native Aqua > buttons... Perfect? Of course not. But stating that it sucks is a load > of crap. No it's not, because you insist on presenting only one part of the problem. Using native widgets is *far* from enough. > Such self-important pronouncements would be better received if you > brought them down the mountain on stone tablets. No problem, let me get my chisel, do you prefer Fedex or UPS ? :p -- Luc Heinrich From paddy3118 at netscape.net Fri Dec 8 17:05:03 2006 From: paddy3118 at netscape.net (Paddy) Date: 8 Dec 2006 14:05:03 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165615503.228351.137610@16g2000cwy.googlegroups.com> Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. > > Mark I've never programmed in Lisp but I have programmed in Cadence Skill a Lisp inspired language with infix notation as an option. I found Skill to be a very powerful language. At the time I new only AWK, C, Pascal, Forth, Postcript, Assembler and Basic. Skill was superior and I came to love it. But that was a decade ago. Now, I'd rather a company integrate Python into their product as I find Python to be less 'arcane' than Skill; with more accessible power, and a great community. . Analogy time! You need Pure Maths, but more mathematicians will be working applying maths to real-world problems. You need research physicists, but more physicists will be applying physics in the real world. It seems to me that Lisp and its basis in maths makes people research and develop a lot of new techniques in Lisp, but when it comes to applying those techniques in the real world - switch to Python! Lisp has a role to play, but maybe a language tuned to research and with its user base would naturally find it hard to compete in the roles in which dynamic languages such as Python are strongest. - Paddy. From deets at nospam.web.de Wed Dec 20 04:28:01 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 20 Dec 2006 10:28:01 +0100 Subject: SQLALCHEMY - Method to have the last word, by Michael Bayer References: <1166543077.605993.276770@80g2000cwy.googlegroups.com> <4uqgeuF19khhgU1@mid.uni-berlin.de> Message-ID: <4use11F19cameU1@mid.uni-berlin.de> Hendrik van Rooyen wrote: > "Diez B. Roggisch" wrote: > >> So - stop it, go away, and please, pretty please with sugar on top: don't >> come back. Python doesn't need you, this NG doesn't need you, no FOSS >> project needs you. Buy a dog. That needs you. Until it runs away from >> being "evaluated". > > This proves it. > > Wearing skull socks makes you mean. Ahh, I guess you're right - that twitching in my feet.... I should get rid of them, wear cherubim socks instead and take a more relaxed stance towards Ilias and his kind. If only I manage to really do this until "they" convince me to keep them, wearing them even in my sleep... Diez From Roberto.Bonvallet at cern.ch Tue Dec 5 06:48:27 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Tue, 5 Dec 2006 11:48:27 +0000 (UTC) Subject: Python regular expression References: <1165312335.481024.237360@l12g2000cwl.googlegroups.com> Message-ID: Wehrdamned wrote: > As I understand it, python uses a pcre engine to work with regular > expression. [...] > My question is, then, why expressions like : >>>> re.compile('asd|(?-i:QWE)', re.I) [...] > don't work? They are ok in perl... >From http://docs.python.org/lib/module-re.html: This module provides regular expression matching operations *similar* to those found in Perl. Similar != the same. See http://docs.python.org/lib/re-syntax.html for details about valid syntax for regular expressions in Python. Cheers, -- Roberto Bonvallet From kentilton at gmail.com Thu Dec 14 01:25:00 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 01:25:00 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> Message-ID: Ken Tilton wrote: > > > Paul Rubin wrote: > >> Ken Tilton writes: >> >>> don't know. The point is, we need code (not just data) in defskill >>> (apologies for nasty formatting): >> >> >> >> Man that whole thing is messy. I do not see much difference, except that the character count is 25% less in the macro version: (defskill absolute-value (title "Absolute Value") (annotations "Absolute value of #strn# is the 'distance' of #strn# from zero." "Absolute value is always zero or positive: #str|n|=n#, and #str|-n|=n#.") (hints "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#." "To get the absolute value of a number such as #signed-value#, we simply drop any minus sign.") (reverse (ensure-cloning resx (make-instance 'mx-number :value (loop with op1 = (car opnds) with log = (max 1 (ceiling (log (abs (value op1)) 10))) for n = (* (signum (value op1)) (+ 2 (random (expt 10 log)))) when (/= n (value op1)) return n) :representation (representation resx))))) (defmethod skill-title ((tf-id (eql 'absolute-value))) (list "absolute value")) (defmethod skill-annotations ((tf-id (eql 'absolute-value))) (list "absolute value of #strn# is the 'distance' of #strn# from zero." "absolute value is always zero or positive: #strn=n#, and #str-n=n#.")) (defmethod skill-hints ((tf-id (eql 'absolute-value))) (list "some examples: #str+42=42#, #str-42=42#, and #str0=0#." "to get the absolute value of a number such as #signed-value#, we simply drop any minus sign.")) (defmethod tf-reverse ((id (eql 'absolute-value)) resx opnds) (declare (ignorable resx opnds)) (ensure-cloning resx (make-instance 'mx-number :value (loop with op1 = (car opnds) with log = (max 1 (ceiling (log (abs (value op1)) 10))) for n = (* (signum (value op1)) (+ 2 (random (expt 10 log)))) when (/= n (value op1)) return n) :representation (representation resx))))) Let's lose the strings and count again, since they are a fixed cost. OK, now the macro version is 30% shorter. >> I can't for the life of me understand >> why it's so important to use a macro for that. Pythonistas, when arguing about macros, always seem to forget that one of the primary design imperatives of Python is cleaner code. Indentation is use to avoid single characters { and }. But when macros come up you all suddenly become the Mavis Beacon of programmers. And, again, perhaps the bigger thing going on here is that the 30% is boilerplate code representing implementation, which can change. I don't know, perhaps the best argument against macros is that no Pythonista wants them. That is actually a damn good reason. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From tjgolden at gmail.com Sat Dec 30 03:19:32 2006 From: tjgolden at gmail.com (Tim Golden) Date: 30 Dec 2006 00:19:32 -0800 Subject: Easiest way to print from XP/DOS. In-Reply-To: References: Message-ID: <1167466772.767450.226780@k21g2000cwa.googlegroups.com> jim-on-linux wrote: > The utility creates a text file that is sent to > the printer with the statement below. > os.system('type ' +FileName+ ' >prn'), > and the file prints. > > But, from an xp machine if I try to print using > the same statement, I get a question on the dos > screen which reads something like this; > Which program authorized this operation? > > Since I don't have an xp machine, the statement > above may not be exact, but you get the idea. You might want to look at this for some more conventional approaches to printing under windows: http://timgolden.me.uk/python/win32_how_do_i/print.html Specifically, I think you want the second option. TJG From fredrik at pythonware.com Sat Dec 2 04:43:40 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 02 Dec 2006 10:43:40 +0100 Subject: type(foo) == function ? In-Reply-To: <4570b689$0$11868$3b214f66@tunews.univie.ac.at> References: <4570b689$0$11868$3b214f66@tunews.univie.ac.at> Message-ID: Mathias Panzenboeck wrote: > This builtin will be removed in python 3.0! that's far from clear (since the replacement approach, "just call it", simply doesn't work). and if you track the Py3K discussions, you'll notice current threads about *more* support for interface testing, not less support. From rampeters at gmail.com Mon Dec 11 18:47:59 2006 From: rampeters at gmail.com (johnny) Date: 11 Dec 2006 15:47:59 -0800 Subject: newb: SENDING os.system(encode_cmd) output to a logging file Message-ID: <1165880879.620563.287790@l12g2000cwl.googlegroups.com> How do I pipe the output, generated from os.system(some_command), to the logging file? From thermate at india.com Sat Dec 2 17:01:05 2006 From: thermate at india.com (thermate at india.com) Date: 2 Dec 2006 14:01:05 -0800 Subject: ** Listen to Professor FETZER, JONES, JUDY WOOD, whose student was murdered by ACTUAL 911 CRIMINALS Message-ID: <1165096865.839548.209760@j44g2000cwa.googlegroups.com> LISTEN AND LEARN TO THINK CRITICALLY !!!!!!!!!!!! http://mp3.rbnlive.com/Fetzer06.html http://janedoe0911.tripod.com/ From exarkun at divmod.com Sun Dec 3 10:52:10 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Sun, 3 Dec 2006 10:52:10 -0500 Subject: twisted problem with reactor.stop() In-Reply-To: <1165144604.277008.266490@79g2000cws.googlegroups.com> Message-ID: <20061203155210.20948.1216362024.divmod.quotient.56099@ohm> On 3 Dec 2006 03:16:44 -0800, maxime_phan at hotmail.com wrote: >hello, everyone >I use twisted 1.3 in my python application. >in my program, I have one server and on client running at same time (so >2 reactor.run(installSignalHandlers=0) ) >the client run in one thread and the server in an other thread ( >reactor.callInThread(self.client... , reactor.callInThread(self.server >....) >when I catch "escape" button, I make a reactor.stop() but it doesn't >seem to work and quit, and the application freeze. does anyone have any >solution to quit the application with twisted? >thanks in advance >Maxime Don't do this. You don't need separate threads for client and server code. There is only one reactor, and you can only run it in one thread. Use it for both your client and your server. Jean-Paul From http Fri Dec 8 20:51:01 2006 From: http (Paul Rubin) Date: 08 Dec 2006 17:51:01 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <7xodqdj2dn.fsf@ruckus.brouhaha.com> <1165627958.748014.101950@16g2000cwy.googlegroups.com> Message-ID: <7xac1xsupm.fsf@ruckus.brouhaha.com> "JShrager at gmail.com" writes: > Well, okay, Scheme [same thing (to me), although I realize that they > aren't, quite -- and CWCC is one place where they aren't!] But I don't > follow why you can't come very close by appropriate macrification of > closures. You have to be able to return from the closure, then re-enter it (possibly from a different place in the calling program) with all the lexical variables intact. You have to be able to do this from multiple places inside the closure. You have to be able to re-enter and re-exit other such closures between the entry and exit of the first one. This all has to work with closures that are recursive. Yeah, Lisp macros are Turing-complete and you could basically implement a coroutine-supporting compiler out of macros and do all of the above, but the target language wouldn't be Lisp any more. From smkhalamayzer at gmail.com Mon Dec 11 10:33:24 2006 From: smkhalamayzer at gmail.com (smkhalamayzer at gmail.com) Date: 11 Dec 2006 07:33:24 -0800 Subject: Rinning Excel macro's with Jython? Message-ID: <1165851203.949329.231220@l12g2000cwl.googlegroups.com> Is there a way to run Excel macro's with jython? Similar to the win32com in python? Thank you. From bluejump at mac.com Fri Dec 29 06:59:02 2006 From: bluejump at mac.com (Kajsa Anka) Date: Fri, 29 Dec 2006 12:59:02 +0100 Subject: Scaling pictures References: <0001HW.C1B960C5006E7E2DF0488648@News.Individual.DE> Message-ID: <0001HW.C1BAC196009E4369F0182648@News.Individual.DE> On Thu, 28 Dec 2006 11:53:41 +0100, Kajsa Anka wrote (in article <0001HW.C1B960C5006E7E2DF0488648 at News.Individual.DE>): Thanks for the answers, I'll use PIL. jem From m.sloyko at gmail.com Thu Dec 21 03:26:42 2006 From: m.sloyko at gmail.com (Maxim Sloyko) Date: 21 Dec 2006 00:26:42 -0800 Subject: your opinion about psycopg vs pygresql References: <45897630$0$326$e4fe514c@news.xs4all.nl> Message-ID: <1166689602.290009.326370@42g2000cwt.googlegroups.com> Martin P. Hellwig wrote: > However, given the choice, what in your opinion would be the reason why > someone would chose one over the other? Now I know this could easily get > into a flamewar, so if you comment (but please do so) I'll still > investigate that, since at this moment I don't even have a clue how they > differ and on what reason, why does PostgreSQL seem to favour pygresql > and Pythoneers psycopg? > > Thanks in advance. Well, my info can be a little out of date, since I researched this problem more than a year ago. AFAIK, psycopg still lacks prepared statements, which can be a huge drawback (partial workaround: use executemany() whenever possible). Psycopg 2 (as opposed to psycopg 1.1) does not support commit() on cursor (no serialized connections) Among the advantages of psycopg 2 is its very good support of mappings between Python data types and PostgreSQL data types. You can easily introduce your own mappings, even for composite data types. My $0.02 From gagsl-py at yahoo.com.ar Mon Dec 4 17:32:12 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 04 Dec 2006 19:32:12 -0300 Subject: WxPython In-Reply-To: <1165148048.517865.156840@f1g2000cwa.googlegroups.com> References: <1165148048.517865.156840@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061204192016.047b8dd0@yahoo.com.ar> At Sunday 3/12/2006 09:14, Raja wrote: > I am trying to develop an application which would mainly do the >following 2 things . I would like to know how it can be achieved and >also the libraries needed for it . > >i) active window tracking I'd use GetForegroundWindow+GetWindowText in a loop with a reasonable delay (maybe 10 secs?). I can't find the former exposed on the pywin32 package but I have an old version. Anyway you could be able to use ctypes. > ii) idle I'd watch for the WM_SYSCOMMAND (SC_SCREENSAVE) and WM_POWERBROADCAST messages. Note that neither of these tasks has to do directly with wxPython -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From newptcai at gmail.com Thu Dec 21 22:20:15 2006 From: newptcai at gmail.com (=?gb2312?B?0rvK18qr?=) Date: 21 Dec 2006 19:20:15 -0800 Subject: I am taking a programming performance match! Message-ID: <1166757615.692080.96660@n67g2000cwd.googlegroups.com> Hi all, The question is like this: ========================= One computer, 2 ethernet adapter. Receving UDP packages and send them out throught another adapter. The one who's program could support the heavies traffic could win a little bonus. ========================= I am considerring trying twited. Is it suitable for this kind of job? From gagsl-py at yahoo.com.ar Fri Dec 15 22:22:58 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Sat, 16 Dec 2006 00:22:58 -0300 Subject: Designing a cancellable function In-Reply-To: <4ugvvfF18hlf1U1@mid.individual.net> References: <4ugvvfF18hlf1U1@mid.individual.net> Message-ID: <7.0.1.0.0.20061216000451.0381cd98@yahoo.com.ar> At Friday 15/12/2006 22:20, Leo Breebaart wrote: >I have written a function foo() that iterates over and processes >a large number of files. The function should be available to the >user as library function, via a command-line interface, and >through a GUI. > >So, I added a 'config' object as a parameter to foo() that can be >used by the caller to explicitly pass in user-defined settings. >Because the processing foo() does can take such a long time, the >next thing I did was add an 'update_function' callback parameter >that foo() will call regularly, so that the GUI can update a >progress bar, and the command-line version can print dots, etc. > >I now would also like to add the possibility to allow the user to >*cancel* the execution of foo() during the processing, and I am >wondering what the best / most Pythonic way to design this is. I can't say if this is the "best/more Pythonic way", but a simple way would be to use the return value from your callback. Consider it an "abort" function: if it returns True, cancel execution; as long as it returns False, keep going. (The somewhat "reversed" meaning is useful in case the user doesn't provide a callback at all, or it's an empty one, or it contains just a print ".", statement, all of these returning False; so, to actually abort the process it must have an explicit "return True" statement). -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From Carl.Wolff at imtech.nl Wed Dec 6 04:50:27 2006 From: Carl.Wolff at imtech.nl (Carl.Wolff at imtech.nl) Date: Wed, 6 Dec 2006 10:50:27 +0100 Subject: Does this always go right In-Reply-To: <7.0.1.0.0.20061205182010.03eba038@yahoo.com.ar> Message-ID: Hello Gabriel, > For your simple test dictionary, copy and deepcopy behaves > identically. If you wish, you should test using values that are > containers themselves. thanks, your answer clarifies a lot. Gtx carl -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike.klaas at gmail.com Mon Dec 18 16:01:57 2006 From: mike.klaas at gmail.com (Klaas) Date: 18 Dec 2006 13:01:57 -0800 Subject: sha, PyCrypto, SHA-256 In-Reply-To: <20061216205313.4083fa5d@dennis-laptop> References: <1166296639.483483.292380@f1g2000cwa.googlegroups.com> <20061216205313.4083fa5d@dennis-laptop> Message-ID: <1166475717.791263.179470@j72g2000cwa.googlegroups.com> Dennis Benzinger wrote: > > Python 2.5 comes with SHA-256 in the hashlib module. > So you could install Python 2.5 instead of the PyCrypto module. You can download the python2.5 hashlib module for use with python2.4 -MIke From uymqlp502 at sneakemail.com Mon Dec 4 02:10:40 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 3 Dec 2006 23:10:40 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> Message-ID: <1165216239.947608.64790@f1g2000cwa.googlegroups.com> Fredrik Lundh wrote: > Russ wrote: > > > Holy cow! I can't believe that many changes would be necessary unless > > the IndexError exception is scattered all over the place. I would hope > > that one well-placed change could fix the bulk of cases. > > when you write x[i], the interpreter makes no assumptions about x and i > and len(x); it just calls the corresponding method (__getitem__), either > directly, or via a C-level internal slot. > > there's no way to generate the error message you want in a single place > without changing the semantics of x[i]. Then how about just changing __getitem__ for the built-in list type. Wouldn't that take care of the vast majority of cases? Let anyone who writes their own __getitem__ handle it themselves if they wish. I'm just asking. I don't claim to know anything about the internals of the Python interpreter. From jacob_mathew at asus.com Mon Dec 18 00:00:50 2006 From: jacob_mathew at asus.com (Jacob Mathew) Date: Mon, 18 Dec 2006 10:30:50 +0530 Subject: HTTP or alternative upload for large files Message-ID: Hay Robin.. I am Jacob Mathew.. Doing some research in large file uploads for my project. I got your matured skills and ability to do programs for upload huge files. In fact I am a kid in programming, I cannot think to write such a god program. Will you able to share your uploading script with me so that it will be useful to me.. Waiting for Your Reply Thanks & Regards Jacob Mathew -------------- next part -------------- An HTML attachment was scrubbed... URL: From caleb.hattingh at gmail.com Fri Dec 15 19:07:59 2006 From: caleb.hattingh at gmail.com (Caleb Hattingh) Date: 15 Dec 2006 16:07:59 -0800 Subject: concatenating strings In-Reply-To: <1166181520.159222.53410@l12g2000cwl.googlegroups.com> References: <1166179761.991744.89630@j72g2000cwa.googlegroups.com> <1166181520.159222.53410@l12g2000cwl.googlegroups.com> Message-ID: <1166227679.480390.43050@16g2000cwy.googlegroups.com> Hi Erich If you're going to be doing a lot of string substitution, you should look at the Templating support in the library: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304005 and (a little bit fancier): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/335308 Regards Caleb On Dec 15, 12:18 pm, "Erich Pul" wrote: > thank you, i just plainly overlooked it ; ) > > now it works From juanrgonzaleza at canonicalscience.com Sun Dec 24 08:05:40 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 24 Dec 2006 05:05:40 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1166906310.452197.185700@48g2000cwx.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1166906310.452197.185700@48g2000cwx.googlegroups.com> Message-ID: <1166965540.332688.60070@48g2000cwx.googlegroups.com> Fuzzyman ha escrito: > Perhaps only with the addendum that although 'Lisp roolz', no-one uses > for anything of relevance anymore and it is continuing it's geriatric > decline into obscurity. ;-) I do not think that i cannot agree with the contrary of this but i do not think the contrary neither. I am being said that LISP is being actively pursued by a number of joung hackers as Graham and Tilton. Do not believe? Ken Tilton has noticed that Dalai Lama has becomed interested in LISP also. From python-list at eves.us Fri Dec 15 19:07:45 2006 From: python-list at eves.us (Simon Eves) Date: Sat, 16 Dec 2006 00:07:45 +0000 Subject: Python Interactive Interpreter Breakage Message-ID: <7828cec60612151607j281ab3e3sd6b1a8dd4e56fce3@mail.gmail.com> I am trying to write a Python module to embed the functionality of Maya (the 3D modelling and animation application from Autodesk, formerly Alias) for doing scripted scene manipulation and rendering processes in Python. I am aware of the CGKit project, which does this and a lot more, but it is over-complex for our needs, and also does not work in the context of a pure command-line Python script, only as an alternative scripting language within Maya. I am also aware that the next version of Maya (8.5) is reputed to have Python integrated, hopefully both internally and externally as I am trying to set up. Since I'm impatient, and also love having my code obsoleted within months, I'm still going ahead with doing it myself but have hit a problem. I have the code in two forms. Firstly, a pure C++ module, which links with the Maya DLLs (this is on Windows, before you ask) and provides three functions, one to initialize the Maya engine, one to send it a command it it's proprietary native scripting language, MEL, and a third to shut it down. An input script for this would be something like: import maya maya.initialize() maya.mel("float $a = 1.234; print $a * 2;") maya.cleanup() I also have it in the form of an executable which embeds the Python interpreter and implements the middle function as an internally "added" module, doing the initialize and shutdown itself (sandwiching the Python stuff). This version can either read in a script file and pass it to PyRun_SimpleFile() or pass stdin to PyRun_InteractiveLoop() to allow you to enter Python interactively just like python.exe. An input script for this would just be the maya.mel(...) line, since the rest is implicit. In both cases, if I feed it an actual Python script file, then everything works properly. The Maya engine fires up, and I can feed it commands which it will execute, and it shuts down at the end. However, also in both cases, if run interactively, if you send a command to the Maya engine to perform a particular process, it does it correctly, but the interactive interpreter is then broken. Whatever you then type, even a blank line, results in a SyntaxError exception, with the pointer pointing to the end of what you typed. The process in question is telling Maya to load a plug-in (a DLL) which is an application extension to render or export to the Mental Images "mental ray" renderer. This is a fairly complex DLL which itself is dependent on other DLLs, but that really shouldn't matter. I then tried building the executable version of my code in Debug mode against my own debug build of Python (I have tried 2.4.4, which is our current user version, and 2.5, with the same result) and then IT WORKS PERFECTLY! >:( If you've stayed with me this far, well done. Anyone have any ideas what could break the interactive interpreter mechanism like this? Obviously I have no control over the behaviour of the Maya API libraries or the mental ray libraries which are subsequently loaded, so it could be that something is trashing memory somewhere. There is no hard crash I can debug, though (especially since the problem doesn't happen AT ALL with a Debug build). Maybe I need BoundsChecker to trap it. Shame I can't afford it... <:\ Yours hopeful that I haven't bored you all to tears, Simon From horpner at yahoo.com Sat Dec 2 21:20:49 2006 From: horpner at yahoo.com (Neil Cerutti) Date: Sun, 03 Dec 2006 02:20:49 GMT Subject: converting dict to object References: <7649225.post@talk.nabble.com> <1165090584.103366.198220@l12g2000cwl.googlegroups.com> Message-ID: <5wqch.1502$eb5.995@newsreading01.news.tds.net> On 2006-12-02, John Machin wrote: > Neil Cerutti wrote: >> On 2006-12-02, Michel Claveau wrote: >> > Hi! >> > >> > Yes. >> > >> > But... >> > >> > Try: d = {'a': 1, 'b': 2, 'def': 123} >> > >> > Ok, I go out... >> >> How to convert a list of strings into a list of integers: >> >> a = ['82', '4', '16'] >> >> ai = [int(i) for i in a] >> >> Yes. >> >> But... >> >> Try: a = ['82', '4', '16', 'foo'] >> >> Ok, I go out... > > Michel was making (part of) a valid point: dictionaries have > more flexibility in choice of keys than objects have in > attribute names. More completely: > > Suppose d.keys() produces ["one", "def", "foo bar", 3, "3"] > > o.one is OK. I made the assumption that Michael was also the original poster, and had somehow laid a clever trap. If I was wrong about that, my apologies. It's one thing to ask how to convert 'a' and 'b' to attributes, but quite another to convert arbitrary text. > The OP might consider adding code to the __init__ method to > check for cases where the dictionary key is not a string > containing a valid Python identifier (not a keyword). That raises the interesting question of what to do in that case. Just letting an error occur might be perfectly good behavior. Plus, I didn't know about... > Observation: the keyword module's iskeyword() function gives an > easy check. If one is supporting multiple versions of Python, a > more complicated (overkill?) approach might be desirable: use > the latest version of Python to generate a source file > containing the latest keywords from keyword.kwlist. Thanks for the pointer to keyword module. I hadn't noticed it yet. -- Neil Cerutti From juanrgonzaleza at canonicalscience.com Sat Dec 16 06:47:33 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 16 Dec 2006 03:47:33 -0800 Subject: merits of Lisp vs Python In-Reply-To: <4ufenbF17of60U6@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> <1166102108.129051.166580@73g2000cwn.googlegroups.com> <4ufenbF17of60U6@mid.individual.net> Message-ID: <1166269653.388136.81520@79g2000cws.googlegroups.com> greg ha escrito: > I don't know about the other Pythonistas in this > discussion, but personally I do have experience with > Lisp, and I understand what you're saying. I have > nothing against Lisp parentheses, I just don't agree > that the Lisp way is superior to the Python way in > all respects, based on my experience with both. Parentheses have two advantages over identation. First is they can be used both inline and block. The inline (a b (c d (e f g))) needs to be formatted in several Python lines. Therein SLiP (Python) got problems for inline mixed markup but LML (LISP) or SXML (Scheme) do not. Second is that i do not need special editors for writting/editting. It is more difficult to do identation and editing by hand in 'Notepad' that adding parens from keyboard [*]. [*] Tip. Type always () and next move your cursor inside ( _ ). You never forget a closing ) this way! From fredrik at pythonware.com Fri Dec 15 11:46:01 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 17:46:01 +0100 Subject: Large files uploading In-Reply-To: <1166191381.083383.269710@80g2000cwy.googlegroups.com> References: <1165949410.458162.38300@79g2000cws.googlegroups.com> <1166014746.923171.38110@f1g2000cwa.googlegroups.com> <1166191381.083383.269710@80g2000cwy.googlegroups.com> Message-ID: Lad wrote: > HTTP protocol provides FORMs for uploading which is elegant and good > solution for small files but using HTTP protocol for large files is > not good ( server's timeouts, big memory consumption on server's > side, etc.). only if the server's buffering data in memory, of course. that's not necessary; there's nothing in the HTTP protocol that prevents you from storing incoming data to disk. > So,I was thinking about FTP protocol, but there may be better solutions > too. > (FTP server would be running on server) > I am sure, it can be done this or that way in Python too. (YouTube.com > is a good example) I still don't get what Python has to do with it -- your users won't be using Python, so you need to figure out what uploading tool to use before you do anything else. > Do you have any idea how to do that? this message may provide some ideas: http://article.gmane.org/gmane.comp.python.django.user/19089 From olakh at walla.co.il Sat Dec 2 11:23:15 2006 From: olakh at walla.co.il (Ola K) Date: 2 Dec 2006 08:23:15 -0800 Subject: a -very- case sensitive search References: <1164490795.866046.133230@45g2000cws.googlegroups.com> Message-ID: <1165076595.739071.281650@79g2000cws.googlegroups.com> Thank you! This was really helpful. Also the data bit about .istitle() was the missinng piece of the puzzle for me... So now my script is nice and working :) And as beside the point, yes I am from Israel, and no, we don't have uper case and lower case letters. Hebrew has only one set of letters. So my script was actualy for the english letters inside the hebrew text... --Ola Paul McGuire ???: > "Ola K" wrote in message > news:1164490795.866046.133230 at 45g2000cws.googlegroups.com... > > Hi, > > I am pretty new to Python and I want to make a script that will search > > for the following options: > > 1) words made of uppercase characters -only- (like "YES") > > 2) words made of lowercase character -only- (like "yes") > > 3) and words with only the first letter capitalized (like "Yes") > > * and I need to do all these considering the fact that not all letters > > are indeed English letters. > > > > I went through different documention section but couldn't find a right > > condition, function or method for it. > > Suggestions will be very much appriciated... > > --Ola > > > Ola, > > You may be new to Python, but are you new to regular expressions too? I am > no wiz at them, but here is a script that takes a stab at what you are > trying to do. (For more regular expression info, see > http://www.amk.ca/python/howto/regex/.) > > The script has these steps: > - create strings containing all unicode chars that are considered "lower" > and "upper", using the unicode.is* methods > - use these strings to construct 3 regular expressions (or "re"s), one for > words of all lowercase letters, one for words of all uppercase letters, and > one for words that start with an uppercase letter followed by at least one > lowercase letter. > - use each re to search the string u"YES yes Yes", and print the found > matches > > I've used unicode strings throughout, so this should be applicable to your > text consisting of letters beyond the basic Latin set (since Outlook Express > is trying to install Israeli fonts when reading your post, I assume these > are the characters you are trying to handle). You may have to do some setup > of your locale for proper handling of unicode.isupper, etc., but I hope this > gives you a jump start on your problem. > > -- Paul > > > import sys > import re > > uppers = u"".join( unichr(i) for i in range(sys.maxunicode) > if unichr(i).isupper() ) > lowers = u"".join( unichr(i) for i in range(sys.maxunicode) > if unichr(i).islower() ) > > allUpperRe = ur"\b[%s]+\b" % uppers > allLowerRe = ur"\b[%s]+\b" % lowers > capWordRe = ur"\b[%s][%s]+\b" % (uppers,lowers) > > regexes = [ > (allUpperRe, "all upper"), > (allLowerRe, "all lower"), > (capWordRe, "title case"), > ] > for reString,label in regexes: > reg = re.compile(reString) > result = reg.findall(u" YES yes Yes ") > print label,":",result > > Prints: > all upper : [u'YES'] > all lower : [u'yes'] > title case : [u'Yes'] From mike.klaas at gmail.com Tue Dec 19 13:58:36 2006 From: mike.klaas at gmail.com (Klaas) Date: 19 Dec 2006 10:58:36 -0800 Subject: Cpoying a PyList to a C string array In-Reply-To: <1166543791.065298.245860@f1g2000cwa.googlegroups.com> References: <1166543791.065298.245860@f1g2000cwa.googlegroups.com> Message-ID: <1166554716.119339.313850@f1g2000cwa.googlegroups.com> Sheldon wrote: > The code below is a rookie attempt to copy a python list of strings to > a string array in C. It works to some extent but results in memory > problems when trying to free the C string array. Does anyone know how > to do this properly? You have numerous problems in this code. The most important problem is that you are referring to global variables which appear to be c structs but you don't provide the definition (e.g., "work"). However, I can guess some of the issues: > for (i = 0; i < work.sumscenes; i++) { > msgop = PyList_GetItem(work.msgobj, i); > work.msg_scenes[i] = PyString_AsString(msgop); > ppsop = PyList_GetItem(work.ppsobj, i); > work.pps_scenes[i] = PyString_AsString(ppsop); > } PyString_AsString returns a pointer to the internal buffer of the python string. If you want to be able to free() it (or indeed have it exist for beyond the lifetime of the associated python string), you need to malloc() memory and strcpy() the data. If the strings contain binary data, you should be using PyString_AsStringAndSize. see http://docs.python.org/api/stringObjects.html. I notice that you are doing no error checking or ref counting, but my (inexperienced python c programming) opinion is that it should work (neither api could potentially call python code, so I don't think threading is an issue). > for (i = 0; i < NumberOfTiles; i++) { > tileop = PyList_GetItem(work.tileobj, i); > work.tiles[i] = PyString_AsString(tileop); > sceneop = PyList_GetItem(work.nscenesobj, i); > work.nscenes[i] = PyInt_AsLong(sceneop); > } > return 1; Similarly. -Mike From haraldarminmassa at gmail.com Wed Dec 6 12:41:36 2006 From: haraldarminmassa at gmail.com (GHUM) Date: 6 Dec 2006 09:41:36 -0800 Subject: how to get all the "variables" of a string formating? Message-ID: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> imagine: template=""" Hello %(name)s, how are you %(action)s""" we can use it to do things like: print template % dict (name="Guido", action="indenting") Is there an easy (i.e.: no regex) way to do get the names of all parameters? get_parameters(template) should return ["name", "action"] Python has to do this somewhere internally..... how to access this knowledge? Harald From Eric_Dexter at msn.com Sun Dec 24 23:12:20 2006 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: 24 Dec 2006 20:12:20 -0800 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167018067.659291.276020@79g2000cws.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> <1167018067.659291.276020@79g2000cws.googlegroups.com> Message-ID: <1167019940.036406.23980@79g2000cws.googlegroups.com> I don't seem to have any problem running python programs regardless of where they are. My platform is windows xp and I have run both 2.4 and 2.5 more details about what version of windows you are running might be helpfull https://sourceforge.net/project/showfiles.php?group_id=156455&package_id=174569 vbgunz wrote: > Ben Sizer wrote: > > I've installed several different versions of Python across several > > different versions of MS Windows, and not a single time was the Python > > directory or the Scripts subdirectory added to the PATH environment > > variable. Every time, I've had to go through and add this by hand, to > > have something resembling a usable Python installation. No such > > problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or > > Kubuntu. So why is the Windows install half-crippled by default? I just > > rediscovered this today when trying to run one of the Turbogears > > scripts, but this has puzzled me for years now. > > > > -- > > Ben Sizer > > excellent question From msherman77 at yahoo.com Fri Dec 1 09:57:45 2006 From: msherman77 at yahoo.com (Michael S) Date: Fri, 1 Dec 2006 09:57:45 -0500 (EST) Subject: PythonWin And Excel Problem In-Reply-To: Message-ID: <20061201145746.74468.qmail@web88304.mail.re4.yahoo.com> Andrea, Also, could it be that when you do the following: sheet.Range("A1:A10").Value = therand you actually initialize all 10 cells to the first element of the array? Try to iterate and initialize every cell separately. Michael --- Andrea Gavana wrote: > Hi All, > > I am having some problems in running a very > simple python script, > which prints some numbers in an Excel spreadsheet. > The numbers are > stored in a list. I know that the numbers are > different (random > generated), but when I open the Excel file I get a > column of data with > all the numbers equal to the first item in the > python list. > I attach a very simple script that reproduces the > problem. > > I am using Python 2.5, PythonWin build 210, Windows > XP. Am I missing > something? Thank you for every hint. > > import os > import random > > from win32com.client import Dispatch > > therand = [] > for ii in xrange(10): > therand.append(random.random()) > > xlsapp = Dispatch("Excel.Application") > wb = xlsapp.Workbooks.Add() > > xlsapp.Worksheets.Item(2).Delete() > xlsapp.Worksheets.Item(1).Delete() > sheet = wb.Sheets[0] > sheet.Name = "Data" > sheet.Range("A1:A10").Value = therand > > excelfile = "C:/HelloWin32.xls" > > wb.SaveAs(excelfile) > wb.Close() > xlsapp.Quit() > > os.startfile(excelfile) > > > Andrea. > > "Imagination Is The Only Weapon In The War Against > Reality." > http://xoomer.virgilio.it/infinity77/ > -- > http://mail.python.org/mailman/listinfo/python-list > From greg at cosc.canterbury.ac.nz Fri Dec 15 01:16:18 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 15 Dec 2006 19:16:18 +1300 Subject: Conditional iteration In-Reply-To: <45810516$0$338$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> Message-ID: <4uet0jF178j3fU1@mid.individual.net> at wrote: > I think by approving > > a = b if condition else c Again, this allows something to be written as an expression that formerly could only be written as a statement, which is a much bigger gain than just crunching two statements into one. -- Greg From grahamd at dscpl.com.au Mon Dec 25 21:50:39 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 25 Dec 2006 18:50:39 -0800 Subject: ANNOUNCE: Mod_python 3.3.0b (Beta) References: <20061225130442.O61514@grisha.dyndns.org> <1167086900.969232.252840@42g2000cwt.googlegroups.com> Message-ID: <1167101439.711883.51730@48g2000cwx.googlegroups.com> derekl00 wrote: > Gregory (Grisha) Trubetskoy wrote: > > The Apache Software Foundation and The Apache HTTP Server Project are > > pleased to announce the 3.3.0b (Beta) release of mod_python. > > How long does it usually take for these things to make there way into > the Fedora (or other distro) repositories? Given that this is a beta, I would hope that the distro people don't get on to it quickly or at all. It was a right pain the last time a beta of mod_python was released and RPMs got distributed, as it took us a lot longer to get rid of the beta version out of the pipeline when the non beta was actually released. Thus, if you really want to try out this beta, compile it from source code, otherwise wait for the official non beta release. If you don't like compiling from source, then you possibly aren't the sort of person who should be using this beta version in the first place, especially when compilation on different platforms is always a part of what we want tested in releasing a beta. Graham From wojciech_mula at poczta.null.onet.pl.invalid Sun Dec 17 13:01:35 2006 From: wojciech_mula at poczta.null.onet.pl.invalid (Wojciech =?ISO-8859-2?Q?Mu=B3a?=) Date: Sun, 17 Dec 2006 18:01:35 +0000 (UTC) Subject: length of multidimensional table References: Message-ID: vertigo wrote: > i have: > x = zeros([3,4],Float) > > how can i check how many rows and columns x have ? > (what is the X and Y size of that table) ? Data member x.shape (tuple) contains dimensions of array. From fredrik at pythonware.com Wed Dec 6 04:51:51 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 6 Dec 2006 10:51:51 +0100 Subject: Novice: replacing strings with unicode variables in a list References: <1165397220.491511.159310@f1g2000cwa.googlegroups.com> <4tnhghF14nrt7U1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Please provide the full script, and the desired input - then we might be > able to help you. the full *traceback* would pretty useful, too: http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do.htm my guess is that the OP left out the print statement that causing the error, and the traceback lines that pointed to that print statement: > more test.py uni = u"p\x95l" print uni > python test.py Traceback (most recent call last): File "test.py", line 2, in print uni File "C:\python25\lib\encodings\cp850.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x95' in position 1 : character maps to From sonibergraj at youjoy.org Tue Dec 5 08:07:45 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Tue, 05 Dec 2006 14:07:45 +0100 Subject: Coding standards without control? In-Reply-To: <1165321106.614601.95530@79g2000cws.googlegroups.com> References: <1165321106.614601.95530@79g2000cws.googlegroups.com> Message-ID: <45756F21.8030104@youjoy.org> editormt wrote: > A majority of the participating organisations have coding standards... > and a majority does not control them ;o) What is the situation at your > location? Does this lack of control really hurt? """A Foolish Consistency is the Hobgoblin of Little Minds""" from: http://www.python.org/dev/peps/pep-0008/ Python makes coding standards obsolete;) -- Soni Bergraj http://www.YouJoy.org/ From severin at rdc.ro Fri Dec 15 04:17:04 2006 From: severin at rdc.ro (severin at rdc.ro) Date: Fri, 15 Dec 2006 11:17:04 +0200 Subject: Mail System Error - Returned Mail Message-ID: The message was not delivered due to the following reason(s): Your message could not be delivered because the destination computer was not reachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message could not be delivered within 2 days: Host 121.23.77.116 is not responding. The following recipients could not receive this message: Please reply to postmaster at python.org if you feel this message to be in error. From http Thu Dec 14 02:24:55 2006 From: http (Paul Rubin) Date: 13 Dec 2006 23:24:55 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7xpsankoc6.fsf@ruckus.brouhaha.com> Message-ID: <7xpsangcs8.fsf@ruckus.brouhaha.com> Ken Tilton writes: > btw, you called the defskill messy (repeated below) "messy". The only > text not specific to absolute value is D-E-F-S-K-I-L-L. No, the messiness was not in the macro instantation (defskill blah...), but in the defmacro that tells the compiler how to expand it. Python function defs are lightweight enough that I don't experience a big pain from using an extra one for a thing like that. From mensanator at aol.com Sat Dec 30 13:37:28 2006 From: mensanator at aol.com (mensanator at aol.com) Date: 30 Dec 2006 10:37:28 -0800 Subject: Easiest way to print from XP/DOS. In-Reply-To: References: Message-ID: <1167503848.923074.258740@48g2000cwx.googlegroups.com> jim-on-linux wrote: > Thanks, > The client is in a one printer office. If the > output file is opened with note and then sent to > the printer everything is fine but it defeats the > purpose of the utility. Also tried > lpt1 but > the same results. This may not help, but it worked once for me although I don't remember the exact circumstances. If the printer is connected to the pc, give it a sharename, such as \\mypc\hpprinter. Then do a redirect of an lpt port to that sharename: net use LPT2: \\mypc\hpprinter. This indirect routing through the network driver back to the local hardware port seems silly, but it did fix a program that couldn't directly access the hardware. > > I'm trying to find out if this was some change in > xp from previous versions, or is there something > abnormal going on. I'm trying to avoid setting > up an xp machine for one client. > > > jim-on-linux > > > > > On Saturday 30 December 2006 03:05, Tim Roberts > wrote: > > jim-on-linux wrote: > > >Did you run from a file or type in from > > > keyboard? > > > > > >When the client runs the utility program the > > >output file is built but nothing prints and no > > >messages appear. When I typed from keyboard on > > > an xp pro at c:\, I got the message. > > > > > >Is it possible that virus detector or some > > >self.defense software is interacting? > > > > It is quite possible that they simply do not > > have a printer hooked up to their computer's > > parallel port. If all of your printers are > > from network shares, then the special file > > "prn" will not go anywhere. > > > > Typing to "prn" is a dreadful way to do > > printing on Windows. -- > > Tim Roberts, timr at probo.com > > Providenza & Boekelheide, Inc. From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Sat Dec 2 08:01:10 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Sat, 02 Dec 2006 14:01:10 +0100 Subject: Thread help References: <1164999221.679348.221000@16g2000cwy.googlegroups.com> <12n0v9l4ssfd7fc@corp.supernews.com> <4tbhffF13bmgrU1@mid.individual.net> <1165012409.569588.264600@79g2000cws.googlegroups.com> Message-ID: <4tdbo2F13ot3aU1@mid.individual.net> John Henry wrote: > Why stop there? Stop where, after one thread? Different question: Why use many threads? It adds complexity and overhead and forces you to think about thread safety and reentrance. Regards, Bj?rn -- BOFH excuse #134: because of network lag due to too many people playing deathmatch From thenightblogger at gmail.com Sat Dec 16 15:39:53 2006 From: thenightblogger at gmail.com (The Night Blogger) Date: Sat, 16 Dec 2006 21:39:53 +0100 Subject: Is there a way to push data into Microsoft Oulook from Python ? Message-ID: <45845738$0$8082$426a74cc@news.free.fr> Is there a way to pull & push data (Tasks, Notes, Calendar Items ...) into Microsoft Oulook from Python ? From Leo.Kislov at gmail.com Sat Dec 16 01:32:31 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 15 Dec 2006 22:32:31 -0800 Subject: Roundtrip SQL data especially datetime References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: <1166250751.590784.216540@l12g2000cwl.googlegroups.com> John Nagle wrote: > Routinely converting MySQL DATETIME objects to Python "datetime" > objects isn't really appropriate, because the MySQL objects have a > year range from 1000 to 9999, while Python only has the UNIX range > of 1970 to 2038. You're mistaken. Python datetime module excepts years from 1 up to 9999: >>> datetime.MINYEAR 1 >>> datetime.MAXYEAR 9999 -- Leo From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 23:34:12 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 15:34:12 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <7xk610a0kl.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 09 Dec 2006 19:31:38 -0800, Paul Rubin wrote: >> The day has not yet arrived that nobody ever needs to edit code in a >> plain, vanilla text editor. > > It's not impossible or terribly difficult to write Lisp that way, it's > just unpleasant, once you've gotten used to doing it with editors that > automatically indent and balance parens. Er, an editor that does that is not a plain, vanilla text editor. -- Steven. From martin at v.loewis.de Fri Dec 22 10:28:28 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 22 Dec 2006 16:28:28 +0100 Subject: urllib.unquote and unicode In-Reply-To: References: <458AEEBD.5040702@v.loewis.de> Message-ID: <458BF99C.8040008@v.loewis.de> Duncan Booth schrieb: > So you believe that because something is only recommended by a standard > Python should refuse to implement it? Yes. In the face of ambiguity, refuse the temptation to guess. This is *deeply* ambiguous; people have been using all kinds of encodings in http URLs. > You don't seem to have realised yet, but my objection to the behaviour of > urllib.unquote is precisely that it does guess, and it guesses wrongly. Yes, it seems that this was a bad move. Regards, Martin From address.good.until.2006.dec.22 at justmail.de Fri Dec 15 11:21:12 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=) Date: Fri, 15 Dec 2006 17:21:12 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7xodq5tboy.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin schrieb: > Andr? Thieme writes: >> and the Lisp version has only 9: >> nth, 1+, truncate, signum, num, list, pos, zero, neg > > Oh come on, you have to count the parentheses too. We could define hundreds of way how to count tokens. But see the program as a tree: nth / \ / \ / \ 1+ list | / | \ | / | \ truncate pos zero neg | | signum | | num And I didn't count the indentation level and \n in Python code. Why should I? They are editor commands. > Anyway, token count doesn't mean much, you have to instead go by the > user's cognitive effort in dealing with the prefix notation etc., How complicated ss it to say "cmp(a, b)" compared to "a cmp b"? After a few days writing Lisp code your brain specializes on that style. Arabian countries write from right to left. They seem to have no problem to use what they know. I admit that I am used to write +, -, * and / infix, because I were trained in that thinking since day 1 in school. In our example program there was only 1+ compared to ".. + 1" which looks "alien" to untrained people. If a program uses extensive math we can get syntax for Lisp that is even more pleasant to read than Pythons: 17a + x?-x? > which isn't purely a matter of token count. And if (+ 2 3) were > really as easy to read as 2+3, mathematics would have been written > that way all along. Mathmaticians invented prefix notation and they use it regularily. They inventey operators that wrap around their arguments, as one can see here: http://www.mathe-trainer.com/formel/?SN=&t=1 Or think of indices, etc. >> TypeError: 'str' object is not callable >> I don't know how I can fix that. Maybe you could tell me. > >>>> lazy_nif(0, lambda: "p", lambda: "z", lambda: "n") Yes, that works. And that's why I wanted to make it a macro. Now you are essentially doing what I did in my first Lisp version. While this works it is farer away from what we think. (nif 0 "p" "z" "n") (nif 0 #'p #'z #'n) are exactly what one thinks. For this reason "if" is implemented as a keyword in Python. It allows you to give code as a block instead of embedding it into a lambda or a def (which even needs a name). And we might go further (again with an easy Graham example). See this typical pattern: result = timeConsumingCalculation() if result: use(result) We need this ugly temporary variable result to refer to it. If we could use the anaphor[1] "it" that could make situations like these more clean. Imagine Python would have an "anaphoric if", "aif". Then: aif timeConsumingCalculation(): use(it) Many Lispers might have this as a macro in their toolbox after some time of coding or after reading Graham. A short three-liner in Lisp and I can really say: (aif (timeConsumingCalculation) (use it)) How would you solve this in Python? You could embed it inside a lambda and must somehow make the variable "it" visible in it, because in the context of aif this "it" gets bound to the result. >>> All Haskell evaluation is automatically lazy, so no lambdas etc. needed. >> Yes, that was what I already supposed. >> Do you also know how I can "deactivate" lazyness? > > There's a Haskell builtin called 'seq' which forces evaluation but > again I'm not sure precisely how to apply it here. I wouldn't wonder if there was an operator like "seq" to do that. So in some languages that support functional programming one needs to do extra work to get lazyness, while in Haskell one gets extra work if one doesn't want it. But maybe someone can correct me here. In Lisp one could build some features to get lazyness as well. [1] http://en.wikipedia.org/wiki/Anaphora_%28linguistics%29 I hope this posting was not sent two times. I just sent it but it didn't appear in my list after reloading. Andr? -- From steve at REMOVE.THIS.cybersource.com.au Sat Dec 2 19:58:42 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 03 Dec 2006 11:58:42 +1100 Subject: converting dict to object References: <7649225.post@talk.nabble.com> <1165090584.103366.198220@l12g2000cwl.googlegroups.com> Message-ID: On Sat, 02 Dec 2006 12:16:24 -0800, John Machin wrote: > The OP might consider adding code to the __init__ method to check for > cases where the dictionary key is not a string containing a valid > Python identifier (not a keyword). If the OP is doing something like this: attributes = {"length": 15, "id": 2345} # attribute names are known at compile time, created by the coder obj.__dict__.update(attributes) print obj.length print obj.id then checking that "length" and "id" are valid identifiers is hardly necessary, any more than this would be: class Spam: def __init__(self, length, id): check_valid_indentifier("length") self.length = length check_valid_indentifier("id") self.id = id But if he's doing something like this: attributes = fetch_user_dict() # attribute names aren't known until runtime obj.__dict__.update(attributes) for key in attributes: print getattr(obj, key) then it is also redundant to check for valid identifiers, since getattr() doesn't need them. However, one might still need to test for accidental clashes with pre-existing object attributes. On the third hand, if that's the case then there seems to be no real advantage to converting the dict into object attributes. Why not just delegate to a saved copy of the dict? class Spam: def __init__(self, d): self._d = d def __getitem__(self, key): return self._d[key] def __setitem__(self, key, value): self._d[key] = value s = Spam({"a": 1, "something else": 2}) s["a"] s["something else"] -- Steven. From mcPas.De.Spam at mclaveauPas.De.Spam.com Fri Dec 1 23:58:04 2006 From: mcPas.De.Spam at mclaveauPas.De.Spam.com (Michel Claveau) Date: Sat, 02 Dec 2006 05:58:04 +0100 Subject: converting dict to object References: <7649225.post@talk.nabble.com> Message-ID: Hi! Yes. But... Try: d = {'a': 1, 'b': 2, 'def': 123} Ok, I go out... -- @-salutations Michel Claveau From jon at ffconsultancy.com Wed Dec 13 04:46:09 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Wed, 13 Dec 2006 09:46:09 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <457fcc7c$0$8728$ed2619ec@ptn-nntp-reader02.plus.net> konrad.hinsen at laposte.net wrote: > A concrete example of interest to me: can I get an OCaml-to-native > compiler for an IBM BlueGene? The processor is in the PowerPC family, > but it has some modifications, and the binary format is different > from standard Linux as well. No idea. OCaml has quite a good PPC backend for the Mac already so you might be able to persuade a student to do the conversion as a project. If Mono runs on that platform then you might also consider F#... -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From http Mon Dec 11 20:35:01 2006 From: http (Paul Rubin) Date: 11 Dec 2006 17:35:01 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> <7xwt4y6j57.fsf@ruckus.brouhaha.com> Message-ID: <7xwt4x6gmy.fsf@ruckus.brouhaha.com> Greg Menke writes: re: comparison of > > a[i] = b[n] with > > (setf (aref a i) (aref b n)) > > Not really. The syntax of getting and setting array elements isn't > really the point. It ignores the cognitive efficiency of Lisp when > things get more complex, and likewise whatever similar characteristics > that Python offers. Well, there's some similar way to look up elements in a Lisp hashtable, but I've forgotten the keyword for it (oops, cognitive inefficiency, having to remember separately.) Python uses the same syntax for both. Yeah it's probably true that very complex applications are easier to develop in Lisp. For small and medium ones, I really do find Python more pleasant, and I'm speaking as someone for whom the discovery of Lisp was once an unbelievably powerful epiphany. From JShrager at gmail.com Fri Dec 8 16:28:00 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 8 Dec 2006 13:28:00 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165613280.584178.36470@16g2000cwy.googlegroups.com> Okay, since everyone ignored the FAQ, I guess I can too... Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? (Common) Lisp is the only industrial strength language with both pure compositionality and a real compiler. What Python has is stupid slogans ("It fits your brain." "Only one way to do things.") and an infinite community of flies that, for some inexplicable reason, believe these stupid slogns. These flies are, however, quite useful because they produce infinite numbers of random libraries, some of which end up being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python is rapidly replacing Perl, and Ruby is simultaneously and even more rapidly replacing Python. Each is closer to Lisp than the last; the world is returning to Lisp and is dragging the flies with it. Eventually the flies will descend upon Lisp itself and will bring with them their infinite number of random libraries, and then things will be where they should have been 20 years ago, but got sidetracked by Tcl and other line noise. From paul at boddie.org.uk Sun Dec 10 13:08:04 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 10 Dec 2006 10:08:04 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> Message-ID: <1165774084.477030.22640@j72g2000cwa.googlegroups.com> JShrager at gmail.com skrev: > > The reason has little to do with macros (although > they were very helpful, of course, esp. in making Tcl look like a > reasonable language so that we could use Tk) How long ago was this? ;-) [Macros in Python] > Either people will not use them, and they will languish and die, and then > at least you can say; "Been there, done that" to the Lisp community. Well, someone did write Logix probably with the intention of getting interest from the community: http://livelogix.net/logix/ It's already been noted what the response has been. > Or, more likely, the some subset of the Python community will get it, > and will figure out how useful they are, although it might take some time. I've been interested in macros for Python, and you'll find other people with similar views: http://www.fiber-space.de/EasyExtend/doc/EE.html That said, you'll find the discussion about macros to be quite open, occasionally even on the Python development lists. But it is also important to note that the development and usage of Python is not guided from purely technical motivations (or from technically pure motivations), and the heated discussion about natural language analogies reveals that just as people are content to form communities around certain kinds of literature, so are people interested in forming communities around developing certain kinds of systems. [...] > you will probably be able to maintain and improve your flagging > position wrt Ruby (which, according to Matz, is more-or-less just Lisp > w/o macros.) I think this would be a fairly weak argument for what would otherwise be a reasonable suggestion. "Come over to my way of thinking or be destroyed" sounds like something the Emperor would say to Luke Skywalker. And we all know how that ended. ;-) And on the subject of remarks about Python developers somehow being remote controlled by the BDFL, I think that anyone who takes a closer look will see varying levels of dissent and dissatisfaction, just as you'd find in any community. Again, many more issues must be considered to understand why people keep using Python (or alternatively stop using it). Paul From orsenthil at gmail.com Mon Dec 4 09:46:31 2006 From: orsenthil at gmail.com (Phoe6) Date: 4 Dec 2006 06:46:31 -0800 Subject: Annoucement- pyljvim-0.0.3 Released. Message-ID: <1165243590.730326.207020@l12g2000cwl.googlegroups.com> pyljvim is a a Livejournal Plugin for Vim. One can post to the Livejournal directly from vim! :) It is available at: http://www.vim.org/scripts/script.php?script_id=1724 Installation is pretty easy and so is the usage. Thanks, Senthil http://phoe6.livejournal.com Contemptuous lights flashed across the computer's console. -- Hitchhiker's Guide to the Galaxy From grante at visi.com Fri Dec 1 17:28:49 2006 From: grante at visi.com (Grant Edwards) Date: Fri, 01 Dec 2006 22:28:49 -0000 Subject: How do I print a numpy array? Message-ID: <12n1b51i11rhv5e@corp.supernews.com> How do you print a numpy array? I tried the obvious print a, print `a`, and print str(a), but none of them work on anything other than trivially small arrays. Most of my real data is elided and replaced with ellipses. -- Grant Edwards grante Yow! I want to kill at everyone here with a cute visi.com colorful Hydrogen Bomb!! From no at spam.com Thu Dec 14 11:15:23 2006 From: no at spam.com (Karl H.) Date: Thu, 14 Dec 2006 08:15:23 -0800 Subject: PyThreadState_SetAsyncExc (nThreadId ??????, exc); In-Reply-To: <1166101579.075399.63890@n67g2000cwd.googlegroups.com> References: <1166101579.075399.63890@n67g2000cwd.googlegroups.com> Message-ID: iwl wrote: > what is the nThreadId-Parameter of PyThreadState_SetAsyncExc? > > I try to implement a Terminate-Button in my C-Prog for my > embedded Python, but its hard to find an example how to > stop an interpreter running in an thread. > > I found no other Python C-App-Func returning such a parameter. > Use the "thread_id" member of the PyThreadState object: PyThreadState *tstate; PyThreadState_SetAsyncExc(tstate->thread_id,exc); -Karl From me47 at dipmicro.com Thu Dec 21 19:55:32 2006 From: me47 at dipmicro.com (Roman) Date: Thu, 21 Dec 2006 19:55:32 -0500 Subject: regular expression In-Reply-To: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> Message-ID: <22Gih.18093$Ca.6266@read2.cgocable.net> Asper Faner wrote: > I seem to always have hard time understaing how this regular expression > works, especially how on earth do people bring it up as part of > computer programming language. Natural language processing seems not > enough to explain by the way. Why no eliminate it ? > It has very much to do with computer programming. There is program flow, conditions, loops, variables. Roman From carsten at uniqsys.com Thu Dec 14 09:58:23 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Thu, 14 Dec 2006 09:58:23 -0500 Subject: Non greedy regex In-Reply-To: <1166107546.537991.165970@t46g2000cwa.googlegroups.com> References: <1166107546.537991.165970@t46g2000cwa.googlegroups.com> Message-ID: <1166108303.3346.5.camel@dot.uniqsys.com> On Thu, 2006-12-14 at 06:45 -0800, tibetan.houdini at gmail.com wrote: > Can someone please explain why these expressions both produce the same > result? Surely this means that non-greedy regex does not work? > > print re.sub( 'a.*b', '', 'ababc' ) > > gives: 'c' > > Understandable. But > > print re.sub( 'a.*?b', '', 'ababc' ) > > gives: 'c' > > NOT, understandable. Surely the answer should be: 'abc' You didn't tell re.sub to only substitute the first occurrence of the pattern. It non-greedily matches two occurrences of 'ab' and replaces each of them with ''. Try replacing with some non-empty string instead to observe the difference between the two behaviors. -Carsten From dakman at gmail.com Wed Dec 6 13:56:59 2006 From: dakman at gmail.com (dakman at gmail.com) Date: 6 Dec 2006 10:56:59 -0800 Subject: Getting started with the Python source In-Reply-To: <1165428508.314773.181130@l12g2000cwl.googlegroups.com> References: <1165428508.314773.181130@l12g2000cwl.googlegroups.com> Message-ID: <1165431419.747335.227940@80g2000cwy.googlegroups.com> Actually IDLE was written purley in python, you can find the sources to it in... UNIX: /usr/lib/python/idlelib Windows: C:\Python\Lib\idlelib If you are looking to modifly mostly just the IDE I would start there, however if you are more interesting in modifying python Itself just look around in the sources, it should be relativley easy to find. renguy wrote: > I am interested in making some changes and additions to the Python > environment (Python and IDLE). I have the source code and can build the > source, but what I want to know is what are the "main" functions or > source code for Python and IDLE. Specifically I would like to know what > in Python and IDLE would be analogous to void main () in a standard C > program. This will help me to work out the structure of the interpreter > and the environment. Your help will be greatly appreciated. The changes > I wish to make are for investigating the modification of the Python > environment for novice programmers. From pinkfloydhomer at gmail.com Tue Dec 26 08:25:52 2006 From: pinkfloydhomer at gmail.com (pinkfloydhomer at gmail.com) Date: 26 Dec 2006 05:25:52 -0800 Subject: keypressed() function Message-ID: <1167139552.235499.167090@48g2000cwx.googlegroups.com> I need a function (blocking or non-blocking) that tells me if a key has been pressed (even before it has been released etc.). Also, I would of course like to know _which_ key has been pressed. I know that this probably does not exist in the Python library already as a platform-independant abstraction (even though it probably could), but then I would at least like solutions that works on Windows and on Linux. /David From deets at nospam.web.de Thu Dec 7 07:07:55 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 07 Dec 2006 13:07:55 +0100 Subject: How to create a global hotkey? References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com> Message-ID: <4tqegrF157a54U1@mid.uni-berlin.de> k04jg02 at gmail.com wrote: > I want to make a Python app that runs in the background, and when a > user hits a key combination, for a function to run. This sounds simple > enough, but all of the keypress detecting libraries I can find count on > you creating a window and then detecting keypresses while that window > has focus. I want my function to execute when the user presses the > hotkey anywhere. I searched the PyGTK documentation and found an old > newsgroup post where someone mentioned the C GTK+ library has it but > PyGTK does not, PyQT showed no results, not sure where else I should > look. I'd be willing to use a library that isn't a windowing toolkit -- > I just want to be able to be able to globally detect a keypress. Any > ideas? What OS on? That is the key question here (sorry for the bad pun). It heavily depends on that, and possibly it hasn't to do with python at all, but instead configuring e.g. your window manager. Diez From DustanGroups at gmail.com Mon Dec 25 20:27:42 2006 From: DustanGroups at gmail.com (Dustan) Date: 25 Dec 2006 17:27:42 -0800 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167095702.282730.325610@n51g2000cwc.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> <1167095702.282730.325610@n51g2000cwc.googlegroups.com> Message-ID: <1167096462.000567.167740@48g2000cwx.googlegroups.com> WaterWalk wrote: > Ben Sizer wrote: > > I've installed several different versions of Python across several > > different versions of MS Windows, and not a single time was the Python > > directory or the Scripts subdirectory added to the PATH environment > > variable. Every time, I've had to go through and add this by hand, to > > have something resembling a usable Python installation. No such > > problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or > > Kubuntu. So why is the Windows install half-crippled by default? I just > > rediscovered this today when trying to run one of the Turbogears > > scripts, but this has puzzled me for years now. > > > > Well, after Python is installed on a Windows platform, files with > extention ".py" or ".pyw" are automatically associated with python or > pythonw. If a python script is double-clicked or input something like > "sth.py" in the "cmd" box, the python interpreter is automatically > called. I don't see any proplem or inconvenience with this. In the command line, entering "python" does not run the python interpreter (unless you modify the settings yourself). From Maksim.Kasimov at gmail.com Wed Dec 13 13:09:32 2006 From: Maksim.Kasimov at gmail.com (sim.sim) Date: 13 Dec 2006 10:09:32 -0800 Subject: Logging module: problem with some mapping keys In-Reply-To: <1166029343.340490.163490@79g2000cws.googlegroups.com> References: <1166029343.340490.163490@79g2000cws.googlegroups.com> Message-ID: <1166033372.240310.299860@73g2000cwn.googlegroups.com> Hi, i've check documentation, and found that logging.basicConfig takes no arguments (probably we have different versions of logging package), and i've never used it. just try this: fileName = 'testlog.log' logName = 'LOG' iHandler = logging.FileHandler(fileName) iHandler.setFormatter( logging.Formatter("%(levelname)-8s|%(asctime)s|%(pathname)s,%(name)s, line %(lineno)s|%(message)s") ) iLog = logging.getLogger(logName) iLog.addHandler(iHandler) iLog.setLevel(logging.DEBUG) iLog.info('hello logging') it gives me: INFO |2006-12-13 19:57:33,575|test.py,LOG, line 12|hello logging On 13 Dec., 19:02, "Tekkaman" wrote: > I'm getting a strange behaviour from the "pathname" and "lineno" > formatter mapping keys. Instead of my file and my line number I get: > > /usr/lib/python2.4/logging/__init__.py > > as the file, and 1072 as the line number. I set up my config as > follows: > > logBaseConf = { > 'level' : logging.DEBUG, > 'format' : "%(levelname)-8s|%(asctime)s|%(pathname)s, > %(name)s, line %(lineno)s|%(message)s", > 'datefmt ': '%d %b %Y, %H:%M:%S', > 'filename': 'logtest.log', > 'filemode': 'a' > } > logging.basicConfig(**logBaseConf) > > I'm not using any executable-generating tools such as cx_Freeze or > Psyco. In fact, I'm getting this error on a very basic script with the > specific purpose of testing the logging module capabilities. > > Thanks in advance for any contribution. > > T. -- Maksim Kasimov From rurpy at yahoo.com Tue Dec 5 12:45:45 2006 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: 5 Dec 2006 09:45:45 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: <1165298191.987140.176550@f1g2000cwa.googlegroups.com> References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165298191.987140.176550@f1g2000cwa.googlegroups.com> Message-ID: <1165340744.979428.317220@j72g2000cwa.googlegroups.com> Russ wrote: > Folks, > > I'm truly sorry that so many feathers got ruffled in this thread. Let's > see if I can put this thing to rest gracefully. I too am tired of this and I apologize to you (Russ) for jumping into it and for this (hopefullly last) followup. But the same thing happened here a short time ago and in that incident too, someone who made a suggestion was attacked and charged unjustifiably with rudeness. In neither that case nor this did anyone protest the unjustness and hypocrisy that was blatant. So this time I could not sit idly and watch. To summarize the "insults" subtread (for closure) An observation was made about a suboptimal error message and a suggestion about how to improve it made in good faith. (Even harebrained suggestions deserve a non-insulting explanation of why they're not a good idea, and this was not harebrained.) This resulted in a suggestion to "submit a patch". The response was (correctly) that it was not a viable suggestion. (characterized by "silly" hardly a strong epithet on usenet), that it would be "trivial" to fix and should "take 2 minutes" by someone with the requisite experience (obviously an opinion, not a claim, since the OP said in the same post that he was unfamiliar with Python internals). Obviously it takes more than two minutes. This was a usenet post for god's sake, not a PhD dissertation. And "trivial" is used almost as slang by many computer and science types and means "very easy" (as if you didn't know). o it is reasonable to question the description "trivial" and ask what actually would need to be done. It is not reasonable to be insulted by it. o Anyone who honestly interprets "two minutes" as 120 seconds should seek clinical help. A reasonable reading if this is that "it would take someone who works on Python internals regularly orders of magnitude less time than me, and with a higher probability of getting it right." Sorry folks. that is a factually true statement. Nothing to do with your time is less valuable than mine. More imaginary insults. The OP was blameless in this thread and this was another case the regulars here overreacting to imagined (or deliberately misinterpreted) "insults" that were not there. One can speculate that this serves a purpose of suppressing interference from "outsiders" in the development process. Or maybe it is just the alpha dogs asserting their authority. Either way, it should not be allowed to pass uncriticised. From riklaunim at gmail.com Thu Dec 7 13:41:17 2006 From: riklaunim at gmail.com (riklaunim at gmail.com) Date: 7 Dec 2006 10:41:17 -0800 Subject: how to delete matplotlib data between ploting In-Reply-To: <1165515692.909028.285360@79g2000cws.googlegroups.com> References: <1165512954.226086.125080@j44g2000cwa.googlegroups.com> <1165515692.909028.285360@79g2000cws.googlegroups.com> Message-ID: <1165516877.753795.42870@j44g2000cwa.googlegroups.com> clf() works :) thanks From arkanes at gmail.com Thu Dec 28 11:32:46 2006 From: arkanes at gmail.com (Chris Mellon) Date: Thu, 28 Dec 2006 10:32:46 -0600 Subject: per interpreter storage for C extensions In-Reply-To: <4593E44C.9000502@chamonix.reportlab.co.uk> References: <4593E44C.9000502@chamonix.reportlab.co.uk> Message-ID: <4866bea60612280832ib9700e6v3f191faa7d8ea488@mail.gmail.com> On 12/28/06, Robin Becker wrote: > As part of some django usage I need to get some ReportLab C extensions into a > state where they can be safely used with mod_python. > > Unfortunately we have C code that seems incompatible with mod_python and I'm > looking for ways to improve the situation. > > Basically the main things that are wrong are all privately cached copies of > python variables. This sample code > > > static PyObject *_pdfmetrics_fonts = NULL; > static PyObject *_pdfmetrics_ffar = NULL; > > .......... > if(!_pdfmetrics_fonts){ > res = PyImport_ImportModule("reportlab.pdfbase.pdfmetrics"); > if(!res) ERROR_EXIT(); > _o1 = _GetAttrString(res,"_fonts"); > if(!_o1) ERROR_EXIT(); > _o2 = _GetAttrString(res,"findFontAndRegister"); > if(!_o2) ERROR_EXIT(); > _pdfmetrics_fonts = _o1; > _pdfmetrics_ffar = _o2; > Py_DECREF(res); _o1 = _o2 = res = NULL; > } > if((res = PyObject_GetItem(_pdfmetrics_fonts,fontName))) return res; > ........... > > illustrates the general problem. If called first by interpreter A I'll get the > values from interpreter A. When later called by interpreter B I'll be using the > wrong values and _pdfmetrics_ffar can alter the wrong interpreter's data. > > > The functions themselves are fairly small, but may be called many times so > they're worth speeding up. > > Is there a simple/cheap way for C code to cache these sorts of module level > globals on a per interpreter basis? Is there even a way to tell which > interpreter I'm being called in? > > Anything too costly will probably bust any speedup. Luckily I don't think we > have too many of these cached variables so it's possible we may be able to get > away with just dropping the caching for some and eliminating others. > -- > Robin Becker > Just off the top of my head, I'd think that using thread-local storage instead of static would work, wouldn't it? I'm not that familiar with mod_python but I'm surely each python interpreter is in a different thread (if not process) than the others. From manstey at csu.edu.au Thu Dec 7 19:12:18 2006 From: manstey at csu.edu.au (manstey) Date: 7 Dec 2006 16:12:18 -0800 Subject: deriving classes from object extensions Message-ID: <1165536738.386380.262640@l12g2000cwl.googlegroups.com> Hi, I am using Python with Cache dbase, which provides pythonbind module, and intersys.pythonbind.object types. But I can't create a class based on this type: import intersys.pythonbind class MyClass(intersys.pythonbind.object): pass gives me the error: TypeError: Error when calling the metaclass bases type 'intersys.pythonbind.object' is not an acceptable base type Can anyone expain if it is possible for me to derive my own class from the intersys object so as to add my own functionality? thanks, matthew From python.list at tim.thechases.com Fri Dec 8 09:19:21 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 08 Dec 2006 08:19:21 -0600 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <45797469.4070309@tim.thechases.com> > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? Easy... Python reads like pseudocode Lisp reads like line-noise (much like most Perl or Ruby code) Python makes better use of my time as a programmer because it maps fairly closely to how I think, as well as being easy to pick up when you've been away from the code for several months. -tkc From fredrik at pythonware.com Tue Dec 12 09:34:12 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Dec 2006 15:34:12 +0100 Subject: How to do a Http HEAD requests References: <457DC9DC.9070803@youjoy.org> Message-ID: Soni Bergraj wrote: > I was just wondering if there is a more convenient way of doing a Http > HEAD requests then the socket module? quick version: >>> import urllib2 >>> request = urllib2.Request("http://www.python.org") >>> request.get_method = lambda: "HEAD" >>> http_file = urllib2.urlopen(request) >>> http_file.headers >>> http_file.headers["content-type"] 'text/html' >>> print http_file.headers Date: Tue, 12 Dec 2006 14:33:08 GMT Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3 Python /2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e Last-Modified: Tue, 12 Dec 2006 07:04:52 GMT ETag: "61b82-2fd2-e60f4d00" Accept-Ranges: bytes Content-Length: 12242 Connection: close Content-Type: text/html From w_a_x_man at yahoo.com Fri Dec 15 18:14:31 2006 From: w_a_x_man at yahoo.com (William James) Date: 15 Dec 2006 15:14:31 -0800 Subject: merits of Lisp vs Python References: <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <1166217335.432132.162750@l12g2000cwl.googlegroups.com> Message-ID: <1166224471.648541.289200@j72g2000cwa.googlegroups.com> Andr? Thieme wrote: > mikael.jansson at gmail.com schrieb: > William James schrieb: > >>> How would you solve this in Python? > >>> You could embed it inside a lambda and must somehow make the > >>> variable "it" visible in it, because in the context of aif this > >>> "it" gets bound to the result.In Ruby: > >> def aif val > >> yield val if val > >> end > >> > >> def complex_calc n > >> if n % 2 == 1 > >> n**n > >> else > >> nil > >> end > >> end > >> > >> aif( complex_calc( 9 ) ) {|x| puts "hello, #{x}"} > >> aif( complex_calc( 8 ) ) {|x| puts "hello, #{x}"} > >> > >> --- output ----- > >> hello, 387420489 > >> > > Okay, so it's certainly _doable_. I think the question is more if it's > > usable. Regular if:s don't like that in Ruby/Python/similar, and adding > > such a construct would mean extending the syntax. > > > > In Lisp, all (well, almost) functions are equal, so an (if ...) would > > look the same like the (aif ...). I think that's the point here. > > Exactly that is the point. > *Of course* it is doable. > And what William shows us is maybe one of the best solutions > in Ruby. He used advanced abstractions that made it possible. > The thing with most (if not all) programming languages other than Lisp > is: these abstractions are leaky. > They have a low level knowledge leak. Users of aif need to know how to > pass in arguments. As you see he had do embed the code that needs execution > into a block (anon function) and then use this special syntax for x. > > > Andr? > -- I may have tried too hard. The simpler way is usually better. No aif() is needed: if x = complex_calc( 9 ) puts "hello, #{x}" end From wojciechowski_m at o2.pl Thu Dec 7 13:45:09 2006 From: wojciechowski_m at o2.pl (mwojc) Date: 7 Dec 2006 10:45:09 -0800 Subject: feed-forward neural network for python Message-ID: <1165517109.290566.27390@l12g2000cwl.googlegroups.com> Hi! I released feed-forward neural network for python (ffnet) project at sourceforge. Implementation is extremelly fast (code written mostly in fortran with thin python interface, scipy optimizers involved) and very easy to use. I'm announcing it here because you, folks, are potential users/testers. If anyone is interested please visit http://ffnet.sourceforge.net (and then post comments if any...) Greetings -- Marek Wojciechowski From peter at machell.net Tue Dec 26 15:18:11 2006 From: peter at machell.net (Peter Machell) Date: Wed, 27 Dec 2006 06:18:11 +1000 Subject: Splitting lines from a database query In-Reply-To: References: <45910d4d$0$16553$afc38c87@news.optusnet.com.au> Message-ID: <459183eb$0$9775$afc38c87@news.optusnet.com.au> ZeD wrote: > Peter Machell wrote: > >> I have an application where I need to take a query from an existing >> database and send it to a web api. > > [...] > >> There are always 5 values, but some are blank and some are 'None'. >> I'd like to split the lines so I get something resembling XML, like this: >> Frank >> Spencer >> >> Dr I Feelgood >> > > quick and dirty solution: > > bar = ( > ("Jane Mary","SIMPSON","0411231234","Dr I Feelgood","2006-12-27 15:00:00"), > ("John","DOE","None","Dr I Feelgood","2006-12-27 15:30:00"), > ("Frank","SPENCER","","Dr I Feelgood","2006-12-27 16:00:00") > ) > > spam ="FNAME", "SNAME", "PHONE", "DR","TIME" > > for x in bar: > i=0 > while i<5: > if x[i] != 'None': > print "<%s>%s" % (spam[i], x[i], spam[i]) > else: > print "<%s>" % (spam[i], spam[i]) > i+=1 > print > Thanks very much ZeD. This will do what I need to. The next step is to do some regex on the phone number to ensure it's local and correct. How can I split these up so each value has a key? Peter. From at at tuko.nl Thu Dec 14 03:11:52 2006 From: at at tuko.nl (at) Date: Thu, 14 Dec 2006 09:11:52 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <7x64cf6wtv.fsf@ruckus.brouhaha.com> <4580f839$0$331$e4fe514c@news.xs4all.nl> <7xlklbgcp7.fsf@ruckus.brouhaha.com> Message-ID: <45810744$0$338$e4fe514c@news.xs4all.nl> Hi Paul, I appreciate your explanation! Thanx @ Paul Rubin wrote: > at writes: >> > for x in (x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0): >> > ... more code ... > >> Do you know if this generates a new list internally (memory consumption?) > > It does not. That parenthesized expression is a called generator > expression. It compiles to a small subroutine, more or less, that > gets invoked repeatedly as you iterate through it. > > A similar expression with square brackets is called a list > comprehension and does generate a new list. From steve at REMOVE.THIS.cybersource.com.au Sun Dec 24 00:04:44 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 24 Dec 2006 16:04:44 +1100 Subject: split string with hieroglyphs References: <1166930928.663980.247610@73g2000cwn.googlegroups.com> Message-ID: On Sat, 23 Dec 2006 19:28:48 -0800, Belize wrote: > Hi. > Essence of problem in the following: > Here is lines in utf8 of this form "BZ???TV%??DVD" > Is it possible to split them into the fragments that contain only latin > printable symbols (aplhabet + "?#" etc) Of course it is possible, but there probably isn't a built-in function to do it. Write a program to do it. > and fragments with the hieroglyphs, so it could be like this > ['BZ?', '\xe3\x83\x84\xe3\x83\xbc\xe3\x83\xaa', 'TV%', > '\xe3\x83\x84\xe3\x82\xad', 'DVD'] ? def split_fragments(s): """Split a string s into Latin and non-Latin fragments.""" # Warning -- untested. fragments = [] # hold the string fragments latin = [] # temporary accumulator for Latin fragment nonlatin = [] # temporary accumulator for non-Latin fragment for c in s: if islatin(c): if nonlatin: fragments.append(''.join(nonlatin)) nonlatin = [] latin.append(c) else: if latin: fragments.append(''.join(latin)) latin = [] nonlatin.append(c) return fragments I leave it to you to write the function islatin. Hints: There is a Perl module to guess the encoding: http://search.cpan.org/~dankogai/Encode-2.18/lib/Encode/Guess.pm You might like to read this too: http://effbot.org/pyfaq/what-does-unicodeerror-ascii-decoding-encoding-error-ordinal-not-in-range-128-mean.htm I also recommend you read this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871 And look at the module unicodedata. > Then, after translate of hieroglyphs, necessary to join line, so it > could be like this > "BZ? navigation TV% display DVD" def join_fragments(fragments) accumulator = [] for fragment in fragments: if islatin(fragment): accumulator.append(fragment) else: accumulator.append(translate_hieroglyphics(fragment)) return ''.join(accumulator) I leave it to you to write the function translate_hieroglyphics. -- Steven. From arkanes at gmail.com Thu Dec 28 11:38:36 2006 From: arkanes at gmail.com (Chris Mellon) Date: Thu, 28 Dec 2006 10:38:36 -0600 Subject: db access In-Reply-To: <4593f072$0$332$e4fe514c@news.xs4all.nl> References: <1167320723.501187.98810@h40g2000cwb.googlegroups.com> <4593eb66$0$322$e4fe514c@news.xs4all.nl> <1167322149.728456.204540@79g2000cws.googlegroups.com> <4593f072$0$332$e4fe514c@news.xs4all.nl> Message-ID: <4866bea60612280838g41047fb0n81c99d119637369b@mail.gmail.com> On 12/28/06, Martin P. Hellwig wrote: > king kikapu wrote: > > Hey Martin, > > > > thanks for the fast reply! > > > > I have already seen that link and i just downloaded the pyodbc module > > but isn't Python already containing a "built-in" odbc module so to > > allow for db communication ?? > > > > Not that I'm aware of, but it is possible to do odbc with the win32 > extensions which are commonly installed on windows machines, perhaps > you've seen something like that? > Yes, but you don't want to. Use pyodbc (or adodbapi, if you're windows only) and save yourself the trouble. From jstroud at mbi.ucla.edu Sun Dec 10 16:24:19 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 10 Dec 2006 21:24:19 GMT Subject: oo problem In-Reply-To: <1165759538.026560.235810@80g2000cwy.googlegroups.com> References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> <8hTeh.3185$Gr2.1738@newssvr21.news.prodigy.net> <1165759538.026560.235810@80g2000cwy.googlegroups.com> Message-ID: <7W_eh.4506$Ga1.562@newssvr12.news.prodigy.net> Tool69 wrote: > Thanks James, > > It was a matter of choice : in my earlier version, all primitives know > how to draw themselves, but they needed to have a parent and I found it > was not good for aesthetic reasons. > > but I think I've been misunderstood. Let's take a concrete sample : > > I've got a Paper instance(-5,5,5,5) (the coordinates of lower-left and > upper-right rectangle: xlowleft, ylowlef, xupright, yupright) of my > paper. > I want now to draw an x-axis on it with some ticks and maybe lables, I > need to catch the xlowleft and xupright variables of the Paper inside > my primitive, ok ? > The problem lies inside my primitive, not on the draw method. > Here's a simplified example, I need to retrieve paper.xll and > paper.xur: > > class Graduate_x( primitive ): > def __init__(self, orient = 'se', xorigin = 0, yorigin=0, xunit= > 1.0, yunit=1.0): > primitive.__init__(self) > for k in range( int(math.floor(( paper.xll - xorigin)/xun)), > int(math.floor((paper.xur-xorigin)/yun)) ): > ...something to construct my path > You can simply pass the paper to the __init__ method and even store a reference to the paper there if you have to re-construct the path later, say if the paper size changes or the origins of the primitive change. I wouldn't advise storing references to the primitives in the paper as well, because you would get circular references. Global variables are probably not the way to handle this. For OO, if you feel like you need a global variable, try to think up an object that can sensibly contain all the objects that would be global. James From http Sat Dec 9 22:31:38 2006 From: http (Paul Rubin) Date: 09 Dec 2006 19:31:38 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: <7xk610a0kl.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Even if you're stuck on some god-forsaken Windows PC with just Notepad, > you can still read Python code. > > Now, *writing* Python code with Notepad isn't as easy, but it is still > doable. How about Lisp code? I've generally used IDLE when editing Python under Windows. It comes with the Python distro after all. Yes, very large systems have been developed with much worse editing facilities than Notepad. Specifically, through the whole 1960's and early 1970's, display terminals were a rarity and people usually edited code (whether in Lisp or another language) on printing terminals (usually noisy Teletypes). It gets worse than that. In the very early days (the Lisp terms "car" and "cdr" are derived from names of registers of the ancient IBM 709 mainframes) they used punch card systems instead of printing terminals. It gets worse than THAT. One of the important historical Lisp applications was James R. Slagle's SAINT symbolic integration program on the IBM 704. Written on punched cards. Except Slagle sadly became blind while writing this program, so he did a fair amount of the development by feeling the holes in the cards with his fingers to read them. I don't think anyone writes Python that way ;-). > The day has not yet arrived that nobody ever needs to edit code in a > plain, vanilla text editor. It's not impossible or terribly difficult to write Lisp that way, it's just unpleasant, once you've gotten used to doing it with editors that automatically indent and balance parens. From agriff at tin.it Tue Dec 12 19:02:47 2006 From: agriff at tin.it (Andrea Griffini) Date: Wed, 13 Dec 2006 01:02:47 +0100 Subject: Lookup caching In-Reply-To: <1165964103.102679.63130@l12g2000cwl.googlegroups.com> References: <457b69ec$0$16153$4fafbaef@reader3.news.tin.it> <457dd837$0$4242$4fafbaef@reader1.news.tin.it> <1165964103.102679.63130@l12g2000cwl.googlegroups.com> Message-ID: <457f41f2$0$4260$4fafbaef@reader1.news.tin.it> MRAB wrote: ... > What are you using for the timestamp? Are you calling a function to > read a timer? For timestamp I used a static variable; to update the timestamp for a dictionary I used d->timestamp = ++global_dict_timestamp; I'm using a single counter for all dicts so that when doing the check for cached value validity I'm checking at the same time that the dict is the same dict was used and that it wasn't touched since when the lookup result was stored. Using this approach and tweaking the LOAD_GLOBAL double lookup for using a "two timestamps one value" cache I got an 8%-10% speedup (depending on the compiler options when building python) in a real application of mines and about 5% in a small test. I've yet to try more complex applications (the biggest real application I have however requires a lot of external modules so testing the speed gain with that will require a lot more work or just downgrading the python version to 2.4). Also I'm using an 32 bit int for timestamp... I wonder if I should listen to the paranoid in my head that is crying for 64 instead. Andrea From shejo284 at gmail.com Tue Dec 19 10:29:36 2006 From: shejo284 at gmail.com (Sheldon) Date: 19 Dec 2006 07:29:36 -0800 Subject: Core dump revisited In-Reply-To: References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> <1166474110.001428.137260@80g2000cwy.googlegroups.com> <1166476940.590579.133460@73g2000cwn.googlegroups.com> Message-ID: <1166542176.142415.305720@48g2000cwx.googlegroups.com> Nick Craig-Wood skrev: > Sheldon wrote: > > Sheldon skrev: > > > Wonderful! Now I know how to used gdb with python. > > Good! > > > > The are results area posted below. Since I am new at this I could > > > used some help in interpreting the problem. What I do know is > > > this: my allocation of the array is good but when freeing the > > > array, a problem arises. The problem is given below but since I am > > > new as well to C > > Ambitious! > > > > I sure could use some help. > > > > > > Program received signal SIGSEGV, Segmentation fault. > > > [Switching to Thread 1077321856 (LWP 32710)] > > > 0x40297b83 in mallopt () from /lib/tls/libc.so.6 > > > (gdb) bt > > > #0 0x40297b83 in mallopt () from /lib/tls/libc.so.6 > > > #1 0x402958ba in free () from /lib/tls/libc.so.6 > > > #2 0x405e070a in MemoryFreeOrd () at msgppsmodule_area.c:1675 > > > #3 0x405dae0a in msgppsarea (self=0x0, args=0x4042aa7c, kwargs=0x0) at > > > msgppsmodule_area.c:328 > > > #4 0x40073b16 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0 > > Typing "up" and "down" to move up and down the call stack is a good > thing. Type "l" to see a list of code at the point that things went > wrong. > > You can type "print " to see the values of variables. > gdb understands most C syntax so you can use "print > this->member[1].data" etc. > > This all assumes you compiled and linked with debugging (-g flag to > compiler and linker). Turning off optimisation may make the debugger > more accurate also. > > I can't tell exactly where your program crashed because of line > wrapping it your post, but is it certainly within MemoryFreeOrd(). > > What I would do next is run the program under gdb, wait for it to > crash then print the values of things in the MemoryFreeOrd() function. > You'll find one of the pointers has been corrupted, ie doesn't point > to valid memory or memory allocated with malloc() I expect. 0 or NULL > is an acceptable input to most free() implementations but not all. > > Finding out exactly where that pointer got corrupted is harder. Maybe > it was never initialised, or maybe you initialised it with a PyObject > or maybe you have a memory scribble somewhere. > > A memory scribble is the hardest bug to find because it happened > elsewhere in your program. Look at the data that was overwritten. > Maybe it is a string you can identify... You'll also want to start > reading the gdb manual on breakpoints and watchpoints at this moment! > > Find memory corruptions can be tricky and time consuming. > > Valgrind can help also. > > Good luck! > -- > Nick Craig-Wood -- http://www.craig-wood.com/nick Man. You are good. This is most insight I have had from anyone. I did initialize the arrays with PyObjects and today, after hours of debugging and now with your insight, I think the problem lies here: /* here a python list of strings is read into a C string array */ static int readPythonObject(void) { int i; PyObject *msgop; PyObject *ppsop; PyObject *tileop; PyObject *sceneop; for (i = 0; i < work.sumscenes; i++) { msgop = PyList_GetItem(work.msgobj, i); work.msg_scenes[i] = PyString_AsString(msgop); ppsop = PyList_GetItem(work.ppsobj, i); work.pps_scenes[i] = PyString_AsString(ppsop); } for (i = 0; i < NumberOfTiles; i++) { tileop = PyList_GetItem(work.tileobj, i); work.tiles[i] = PyString_AsString(tileop); sceneop = PyList_GetItem(work.nscenesobj, i); work.nscenes[i] = PyInt_AsLong(sceneop); } return 1; } /*end readPythonObject*/ I am new to this and copied this code from a colleague. So, it corrupts the pointer. How do I do this properly? Your help is truly appreciated! /S From grue at mail.ru Wed Dec 13 03:23:41 2006 From: grue at mail.ru (Timofei Shatrov) Date: Wed, 13 Dec 2006 08:23:41 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165867527.389209.80660@f1g2000cwa.googlegroups.com> <4u995gF16pm7hU4@mid.individual.net> Message-ID: <457fb737.4782236@news.readfreenews.net> On Wed, 13 Dec 2006 16:07:01 +1300, greg tried to confuse everyone with this message: >Robert Uhl wrote: > >> o Symbols >> >> In Lisp, a symbol is essentially a hashed string; > >Are you aware that strings can be interned in Python? >Furthermore, any string literal in the source that >is a syntactically valid identifier is automatically >interned, and you can intern any string explicitly >if you need. This gives you exactly the same >capabilities as symbols in Lisp. Are you aware that you hardly know any Lisp yet make such bold and unfounded claims? Unless interning a string somehow gives it a property list, slot value and function value it doesn't give you the same capabilities. -- |Don't believe this - you're not worthless ,gr---------.ru |It's us against millions and we can't take them all... | ue il | |But we can take them on! | @ma | | (A Wilhelm Scream - The Rip) |______________| From simon at brunningonline.net Fri Dec 1 04:51:18 2006 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 1 Dec 2006 09:51:18 +0000 Subject: python vs java & eclipse In-Reply-To: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> Message-ID: <8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com> On 1 Dec 2006 01:24:47 -0800, Amir Michail wrote: > Eclipse for example provides such an amazing IDE for java that it is no > longer obvious to me that one would be much more productive in python > for medium sized projects. Eclipse can generate a lot of the Java boilerplate code, it's true, saving you a lot of typing up front. But it can't maintain all those reams of pointless code for you, and perhaps more importantly, it can't read it for you. All the useless code that Java requires still has a large price, even if you don't need to type it yourself. > Sure, all that Java static typing can be painful, but Eclipse takes > some of that pain away. Moreover, static typing can result in better > on-the-fly error detection and refactoring support. I do sometimes spend some time finding and fixing bugs of the "I though I had a Spam instance, but it turns out to be a Eggs instance" issues when coding in Python, but then I spend some time sorting out "I know you've got a fry() method in there somewhere - just let me call it!" issues in Java, so it balances out. And the latter problems are more annoying, 'cos I feel the compiler isn't trusting me. Python usually trusts me, even if I don't always deserve it. ;-) FWIW, I spend perhaps 80% of my coding time with Java (and Eclipse), and 20% with Python. -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From ptmcg at austin.rr._bogus_.com Mon Dec 4 11:18:43 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 04 Dec 2006 16:18:43 GMT Subject: Why not just show the out-of-range index? References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> Message-ID: I think your biggest initial recoil to the response you got was in the request that you submit a patch. You thought, "Geez, I just want one friggin' error message changed, and they want me to learn the whole Python development environment." Given your newbiness with Python, probably a better response to you would be, "Submit this as a feature request at the SF tracker page. If you really feel ambitious, put together a patch to go with it, it will increase the likelihood of getting accepted about 50X." A couple of other notes: - The core developers do post here, but the real core Python development discussions go on on the pydev mailing list. - Please recognize that you did get at least one response from John Machin, who scanned the code for this simple error message, and found that the impact was actually in about a dozen places (not uncommon when peeling away at the onion of source code, you've probably seen this yourself). This gave all of us a better appreciation of the size of the effort required for what initially seemed like a 30-second job. (BTW, there are *never* any 30-second jobs, especially in a package the size of Python.) So let me echo the effbot and ask that you submit this at the feature request tracker page on SF - I think you've spent more time in posting to this thread than it would have taken to submit this request. If you don't want to learn the Python dev environment, that's fine, you might consider composing a pydev mailing list submission making your case on the merits of implementing some user-friendliness features, such as more explanatory error messages. But the plain truth is, patches speak louder than words, on pydev even moreso than c.l.py. -- Paul From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 19:29:43 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 11:29:43 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165701024.138305.241500@j72g2000cwa.googlegroups.com> Message-ID: On Sat, 09 Dec 2006 13:50:24 -0800, Kaz Kylheku wrote: > Steven D'Aprano wrote: >> But Lisp's syntax is so unlike most written natural languages that that it >> is a whole different story. > > Bahaha! > >> Yes, the human brain is amazingly flexible, >> and people can learn extremely complex syntax and grammars (especially if >> they start young enough) so I'm not surprised that there are thousands, >> maybe tens or even hundreds of thousands of Lisp developers who find the >> language perfectly readable. > > 1> '(especially if they start young enough) > (ESPECIALLY IF THEY START YOUNG ENOUGH) > 2> (sixth *) > ENOUGH > > ... said! > > Yeah, so /unlike/ written natural languages! > > What a fucking moron. Oh my god! Lisp can echo STRINGS to the interpreter???? Why didn't somebody somebody tell me that!!!! That *completely* changes my mind about the language! I'm especially impressed that it knew I wanted them printed in uppercase without being told. -- Steven. From fredrik at pythonware.com Fri Dec 1 02:27:38 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 01 Dec 2006 08:27:38 +0100 Subject: Python Question About Compiling. In-Reply-To: <1164956538.516498.14900@80g2000cwy.googlegroups.com> References: <1164956538.516498.14900@80g2000cwy.googlegroups.com> Message-ID: yndesai wrote: > Is it that no compiling facility is hindering the growth of python > in commercial circuit . . . ? good thing most commercial Python developers haven't noticed this, then. if you don't know that some random guy on the internet thinks that some- thing doesn't exist, there's nothing that keeps you from using it ;-) (why are you blaming you inability to use Linux installation tools on Python, btw? most basic Python libraries are only an apt-get away if you're using a sane Linux distribution.) From __peter__ at web.de Thu Dec 14 12:41:47 2006 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Dec 2006 18:41:47 +0100 Subject: Logging module: problem with some mapping keys References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166106298.176199.301190@f1g2000cwa.googlegroups.com> <1166113691.753244.189350@f1g2000cwa.googlegroups.com> <1166115714.082561.87420@t46g2000cwa.googlegroups.com> Message-ID: Tekkaman wrote: > lib is a symlink to lib64 So my initial diagnosis was correct. Unfortunately I can no longer recommend that you remove the symlink... Putting /usr/lib64/python2.4 as the first entry into your PYTHONPATH environment variable might fix the problem (the idea is that /usr/lib64/python2.4 precedes /usr/lib/python2.4 in sys.path and is therefore used for the import of the logging package). Peter From tayssir.john at googlemail.com Sun Dec 10 18:55:00 2006 From: tayssir.john at googlemail.com (tayssir.john at googlemail.com) Date: 10 Dec 2006 15:55:00 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165762281.579645.56990@l12g2000cwl.googlegroups.com> <1165767334.350312.36020@l12g2000cwl.googlegroups.com> <1165777915.940969.205700@f1g2000cwa.googlegroups.com> <1165785112.923267.8280@l12g2000cwl.googlegroups.com> <1165788773.166376.127470@79g2000cws.googlegroups.com> <1165791507.853527.315420@16g2000cwy.googlegroups.com> Message-ID: <1165794900.321296.83470@79g2000cws.googlegroups.com> Paul Boddie wrote: > tayssir.john at googlemail.com wrote: > > Keeping with the analogy, Lisp offers power to adapt your notation to > > the domain you're describing. One thing people expect from a language > > is a certain malleability in order for it to somehow resemble the > > domain they're describing. > > I think the more interesting issue of relevance to both communities > (and I wonder whether the original inquirer is still reading) is > whether a language like Python is an acceptable specialised notation > for so many domains as to make a more malleable language like Lisp less > interesting for most specialists. In other words, that there are so > many areas where Python's arguably mundane semantics are sufficient > that the specialists have their convenient, common means of > communication which happens to span large areas of computational > endeavour. Well, I think it's twofold: * How well do languages keep up with changing requirements and paradigms? * Don't you want a domain expert (perhaps you) designing your problem domain's notation, someone who cares deeply about the problems you face? When Python is fine for your domain, great. But as you stray from the intention of Python's central designers, your code loses correspondence with your problem domain. For example, this book offers a case study in an mp3 parser syntax which corresponds visually to the spec: Or here are some simple examples, with HTML: > And on the occasions where Python doesn't provide adequate, > convenient metaprogramming features, might it not be the case that less > elegant program transformation mechanisms or even other approaches to > architectural design aren't good enough solutions? After all, the > various object-oriented design movements, for example, even though they > may be regarded as having produced clumsy and verbose mechanisms for > expressing certain kinds of systems, have in some way or other provided > a recognisable vocabulary that many people understand. OOP is actually a good example. Alan Kay stated: "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." (From a link I gave earlier.) The central designers behind C++ were certainly thoughtful. But they weren't all OOP experts. There should be some room for interested people to easily experiment with a new paradigm's concepts. After going through enough testing and common use, it can even be folded into the language itself. There's another anecdote. At LL2, a convention of language designers, I recall the guy from Microsoft Research wanted nondeterminism in a programming language. But you can actually download a Lisp library which provides nondeterministic computing features. YMMV, as usual. Tayssir From michael.trausch at comcast.net Fri Dec 22 12:03:56 2006 From: michael.trausch at comcast.net (Michael B. Trausch) Date: Fri, 22 Dec 2006 12:03:56 -0500 Subject: How a script can know if it has been called with the -i command line option? In-Reply-To: <1166805005.943645.193860@48g2000cwx.googlegroups.com> References: <1166720012.798260.6670@80g2000cwy.googlegroups.com> <1166805005.943645.193860@48g2000cwx.googlegroups.com> Message-ID: <38SdnQj-WZKVjRHYnZ2dnUVZ_r6vnZ2d@comcast.com> Peter Wang wrote: > Michele Simionato wrote: >> The subject says it all, I would like a script to act differently when >> called as >> $ python script.py and when called as $ python -i script.py. I looked >> at the sys module >> but I don't see a way to retrieve the command line flags, where should >> I look? > > I realize this is quite a hack, but the entire command line is > preserved in the process's entry in the OS's process table. if you do > "ps -ax" you will see that the interpreter was invoked with -i. I > didn't test this under windows, but it works on Mac and Linux. > There is a set of utilities that have UNIX-like ps behavior, but, as is typical for Windows, they don't work the way their UNIX and UNIX-like counterparts do. Does 'ps' work from within Cygwin, and if so, would redistributing that be an option? -- Mike From jonathan.wright at gmail.com Tue Dec 5 13:50:50 2006 From: jonathan.wright at gmail.com (Jon) Date: 5 Dec 2006 10:50:50 -0800 Subject: Linear regression in NumPy References: Message-ID: <1165344328.997267.45460@73g2000cwn.googlegroups.com> > I have a question about the linear_least_squares in Numpy. Not quite sure what is going on, it looks like there could be some confusion as to linear_least_squares is expecting as an argument of some Numeric arrays and what you are supplying (a Matrix) is perhaps not close enough to being the same thing. Up-to-date versions for all this are all in "numpy" nowadays and the numpy mailing list is perhaps a better place to ask: http://projects.scipy.org/mailman/listinfo/numpy-discussion Anyway, I've pasted in an example using Numeric and LinearAlgebra, which you seem to have on your system. They still work fine. Not sure what the "Matrix" package is that you are using? HTH, Jon example: C:\>python Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from Numeric import * >>> from LinearAlgebra import linear_least_squares >>> a=array( [[1, 1], [1, 2], [1, 3]] ) >>> y=array( [ 1,2,4] ) # note 1 D >>> a array([[1, 1], [1, 2], [1, 3]]) >>> y array([1, 2, 4]) >>> linear_least_squares(a,y) (array([-0.66666667, 1.5 ]), array([ 0.16666667]), 2, array([ 4.07914333, 0.60049122])) >>> # Is this what you expect as output??? Jianzhong Liu wrote: > Hello, Guys, > > I have a question about the linear_least_squares in Numpy. > > My linear_least_squares cannot give me the results. > > I use Numpy1.0. The newest version. So I checked online and get your > guys some examples. > > I did like this. > > [john at crux 77] ~ >> py > Python 2.4.3 (#1, May 18 2006, 07:40:45) > [GCC 3.3.3 (cygwin special)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>> from Numeric import * > >>> from LinearAlgebra import linear_least_squares > >>> from Matrix import * > >>> y = Matrix([[1], [2], [4]]) > >>> x = Matrix([[1, 1], [1, 2], [1, 3]]) > >>> print y > Matrix([[1], > [2], > [4]]) > >>> x > Matrix([[1, 1], > [1, 2], > [1, 3]]) > >>> print linear_least_squares(x, y) > > Here my Numpy stops. and never give me a result. THis is the problem of > Numpy or sth wrong. > > Can you guys give me a LinearAlgebra.py so that I can have a try? > > Thanks, > > John From dakman at gmail.com Wed Dec 6 14:09:34 2006 From: dakman at gmail.com (dakman at gmail.com) Date: 6 Dec 2006 11:09:34 -0800 Subject: Getting started with the Python source In-Reply-To: <1165431727.248930.248430@80g2000cwy.googlegroups.com> References: <1165428508.314773.181130@l12g2000cwl.googlegroups.com> <1165431419.747335.227940@80g2000cwy.googlegroups.com> <1165431727.248930.248430@80g2000cwy.googlegroups.com> Message-ID: <1165432174.905333.45430@n67g2000cwd.googlegroups.com> Right, I am pretty sure that the "toplevel" source of idle is in dir-to-pylibs/idlelib/idle.py (or maybe .pyw) that is were all the glue code is for idle, as for the python source, I haven't messed around with it too much so I couldn' tell you, well just have to wait for somone else to post that information... ... renguy wrote: > Thank you for your response. I guess I was looking for a more specific > answer. I have the source and I have been looking around at the various > code. I think my question is, what is the name of the toplevel source > code file of C code for the Python interpreter, and what is the name of > the toplevel source code file for IDLE? Does that make sense? > > Thanks again. > > dakman at gmail.com wrote: > > Actually IDLE was written purley in python, you can find the sources to > > it in... > > > > UNIX: /usr/lib/python/idlelib > > Windows: C:\Python\Lib\idlelib > > > > If you are looking to modifly mostly just the IDE I would start there, > > however if you are more interesting in modifying python Itself just > > look around in the sources, it should be relativley easy to find. > > > > renguy wrote: > > > I am interested in making some changes and additions to the Python > > > environment (Python and IDLE). I have the source code and can build the > > > source, but what I want to know is what are the "main" functions or > > > source code for Python and IDLE. Specifically I would like to know what > > > in Python and IDLE would be analogous to void main () in a standard C > > > program. This will help me to work out the structure of the interpreter > > > and the environment. Your help will be greatly appreciated. The changes > > > I wish to make are for investigating the modification of the Python > > > environment for novice programmers. From rupole at hotmail.com Fri Dec 1 14:39:45 2006 From: rupole at hotmail.com (Roger Upole) Date: Fri, 1 Dec 2006 14:39:45 -0500 Subject: good documentation about win32api ?? References: <1164988151.675036.308920@j44g2000cwa.googlegroups.com> Message-ID: <1165002195_18377@sp6iad.superfeed.net> "__schronos__" wrote: > Hi all. > > Recently I've to developed a project in python that made operation > under win32 platform and I found a lot of problema to find good > information. The only one documentation is in ActivePython page > (http://aspn.activestate.com/ASPN/docs/ASPNTOC-APYTH2.4.0) but it is > not very good and finally I had to turn to the newsgroups (it was very > nice). > > And the question is: ?Anybody knows where can I find good > documentation about win32api? > > Thanks in advanced. The pywin32 package has a .chm help file that covers the modules, objects and methods. Also, there are demos of many of the functions and interfaces. Roger ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From riklaunim at gmail.com Thu Dec 7 12:35:54 2006 From: riklaunim at gmail.com (riklaunim at gmail.com) Date: 7 Dec 2006 09:35:54 -0800 Subject: how to delete matplotlib data between ploting Message-ID: <1165512954.226086.125080@j44g2000cwa.googlegroups.com> I want to make few plots from CSV files. I have the code below - it works - the first plot is ok, the second one has the first and the current data set and so on - I can't delete the plot data between plots. ########################################## # -*- coding: utf-8 -*- from pylab import * from os import listdir i = listdir('dane/') # list folders with CSV files for di in i: # list files in folders csv = listdir('dane/' + di + '/') for datafile in csv: # open each CSV file file = open('dane/' + di + '/' + datafile, 'r').readlines() x = [] y = [] # get the data for row in file: if row.find(',') != -1: r = row.split(',') if len(r[0]) > 0 and len(r[1]) > 0: x.append(float(r[0])) y.append(float(r[1])) xlabel('czas') ylabel('Moc') title(di.replace('.', ' ')) #plot plot(x, y) savefig('dane/' + di + '/' + datafile + '.png') del x del y del file From greg at cosc.canterbury.ac.nz Fri Dec 15 06:17:47 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:17:47 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> <87lklcrt00.fsf@thalassa.informatimago.com> <457fdb92$0$13245$426a74cc@news.free.fr> <45812f4c$0$26482$426a74cc@news.free.fr> Message-ID: <4ufelrF17of60U1@mid.individual.net> Gabriel Genellina wrote: > You can even make S = cT (c=ligth of speed in void space). > The choice of fundamental units is rather arbitrary, and can be reduced > further to only 1 fundamental unit and even NO fundamental units. I once heard mention of a system of units in use at one time with the odd feature that capacitance came out in units of length. Picture the scene: Hobbyist walks into Dick Smith store and says "I'd like a 5cm capacitor, please." -- Greg From webmaster at cacradicalgrace.org Mon Dec 18 18:21:54 2006 From: webmaster at cacradicalgrace.org (J. Clifford Dyer) Date: Mon, 18 Dec 2006 16:21:54 -0700 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4584E986.10502@cosc.canterbury.ac.nz> <4um6tgF18l1srU1@mid.individual.net> Message-ID: Roy Smith wrote: > In article <4um6tgF18l1srU1 at mid.individual.net>, > greg wrote: > >> Roy Smith wrote: >> >>> The struct does lookup by name, the tuple is inherently index based. >> I was trying to help people understand the distinction >> we're talking about by showing an example of the same >> distinction in another language where it's much clearer. >> >> There are a great many ways in which C structs are >> different from Python tuples, and C arrays are different >> from Python lists. But they're not the aspects I'm >> drawing an analogy between. >> >> -- >> Greg > > Well, yeah, but it's kind of like saying "a tangerine and an orange are > very different things because one of them is like an apple and the other > one is like a pear" :-) Actually, I found the distinction a bit more helpful than that--more like saying, "a tangerine and a pear are very different things because one of them is like an orange and the other is like an apple." Still not a precise definition, but a useful analogy in many ways. Cheers, Cliff From kw at codebykevin.com Fri Dec 8 16:16:01 2006 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 08 Dec 2006 16:16:01 -0500 Subject: Bug in pybwidgets, or my code? Message-ID: I'm trying to use pybwidgets in a Tkinter application I'm developing; the BWidgets listbox supports insertion of images alongside text, and is nicer than the alternatives I've looked at (various tree widgets, for instance). I've found what I think is a bug. When the BWidgets listbox is placed inside a panedwindow, it does not properly display the selectforeground/selectbackground colors--in fact, it provides no visual feedback at all that a listbox item is selected. The following code illustrates the problem. The listbox does respond to button events; when an item is selected, text is printed to the text widget. But there is no visual selection feedback in the listbox itself. Can someone review this, test it, and let me know if I'm doing something wrong, or if this is in fact a bug? Thanks. --- import Tkinter from bwidget import * import bwidget root = Tkinter.Tk() right = "" m = Tkinter.PanedWindow(root, orient="horizontal") m.pack(fill="both", expand=1) left = ListBox(m, selectbackground="black", selectforeground="white") m.add(left) for text in "abcde": left.insert("end", text=text*3) left.bind_text("", (lambda event: printstuff())) right = Tkinter.Text(m) m.add(right) right=right def printstuff(): global right right.insert("end", "pressed\n") root.mainloop() -- Kevin Walzer Code by Kevin http://www.codebykevin.com From nagle at animats.com Sat Dec 16 13:36:17 2006 From: nagle at animats.com (John Nagle) Date: Sat, 16 Dec 2006 18:36:17 GMT Subject: Roundtrip SQL data especially datetime In-Reply-To: <1166258893.044093.196820@79g2000cws.googlegroups.com> References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> <1166258893.044093.196820@79g2000cws.googlegroups.com> Message-ID: John Machin wrote: > John Nagle wrote: > >>dyork wrote: >> >>>"John Machin" wrote in message >>>news:1166211949.065578.292600 at f1g2000cwa.googlegroups.com... >>> >>> >>>>If you have, as you should, Python 2.5, you can use this: >> >> Actually, MySQLdb isn't released for Python 2.5 yet > > > Actually, that's interesting information [why should it take so long?], > but the OP didn't actually say what brand of database he was actually > using :-) True. Why should it take so long? The Python people don't support the MySQL interface, and the MySQL people don't support the Python interface. There's one guy on Sourceforge doing the MySQLdb glue code. And he's busy. This is unusual for database bindings. The standard Perl distribution supports MySQL and several other databases, so you can use MySQL out of the box, and it's tested for new releases. The standard MySQL distribution supports PHP, Java, etc., so that's standard and gets tested. With Python/MySQL, though, neither side takes responsibility for making that binding work. One side effect of this being third party code is that hosting services may not have it available, even when they have both Python and MySQL up. This is never a problem with Perl or PHP, so that's a negative for Python. I'm currently trying to get "EZpublishing", usually a good hosting service, to fix this on their systems. There are also some recent problems between versions of Apache, mod_python, MySQLdb, Python, and MySQL, some of which can crash a web server. (Ref: http://packages.debian.org/changelogs/pool/main/p/python-mysqldb/python-mysqldb_1.2.1-p2-4/changelog) Not sure if this has been resolved yet. John Nagle From Benjamin.Barker at gmail.com Thu Dec 28 12:16:18 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 28 Dec 2006 09:16:18 -0800 Subject: dictionary containing instances of classes behaving oddly Message-ID: <1167326178.386764.300200@n51g2000cwc.googlegroups.com> Hello... I have a dictionary, where each value is a seperate instance of the same class: self.mop_list[record_number]=record(self.mops[:]) In my case I know that record_number takes the values 0,3,and 7 thanks to a loop, giving me three instances of the record class instantiaterd with some data I've pased in. The record object contains a list, and each element of that list should also contain an instance of a class should I append one to it: self.mop_list[record_number].my_list.append(my_class(0,0,0,self.mop_list[record_no].mops,0)) So within each record class I have access to any number of my_class instances, depending on how many times I have appended: self.mop_list[record_number].my_list[index] This seems to work without any errors. But bizzarely I find that whatever my record number, the instance of "my_class" is appended to every list. So in this case self.mop_list[0].my_list.append(my_class(Some data for the constructor)) I would expect to append an instance of my_class to self.mop_list[0].my_list But annoyingly self.mop_list[0].my_list self.mop_list[3].my_list self.mop_list[7].my_list all have an instance of my_class created and appended to them. This is really confusing and quite annoying - I don't know whether anyone out there can make head or tail of what I'm doing wrong? Cheers, Ben From michele.simionato at gmail.com Thu Dec 21 11:53:32 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 21 Dec 2006 08:53:32 -0800 Subject: How a script can know if it has been called with the -i command line option? Message-ID: <1166720012.798260.6670@80g2000cwy.googlegroups.com> The subject says it all, I would like a script to act differently when called as $ python script.py and when called as $ python -i script.py. I looked at the sys module but I don't see a way to retrieve the command line flags, where should I look? TIA, Michele Simionato From PPNTWIMBXFFC at spammotel.com Tue Dec 5 03:50:17 2006 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Tue, 05 Dec 2006 09:50:17 +0100 Subject: The del statement References: Message-ID: > so what about > > del x Ups. I never used it for an object. So far I only used it for deletion of elements of a container. In that case del has two purposes: 1. Deletes an item from a container (and of course destructs it) --> list.remove(elem) 2. Calls the destructor of an object --> list.destruct() One statement and two distinct purposes. Why not having two "standard" function (for containers we have a remove-function) and all objects have a destruct-function. Still no need for a del keyword. A del keyword that calls the destructor... well that is okay (it could be handled without). I am used to see the del keyword in opposition to the new keyword (which does not exist/is implicit in Python). The del keyword for removing an element in a container is a bit awkward to me. I am not as knowledgeable about languages as you are and I am hoping people like you can enlighten me about the language decision taken. > for the curious, guido's rationale for len() can be found here: > > http://preview.tinyurl.com/y6vavp Thanks for the hint. Marco From luc at honk-honk.com Sun Dec 17 03:37:04 2006 From: luc at honk-honk.com (Luc Heinrich) Date: Sun, 17 Dec 2006 09:37:04 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> Message-ID: <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> The Night Blogger wrote: > Can someone recommend me a good API for writing a sexy looking (Rich UI like WinForms) shrink wrap application No, because such a thing doesn't exist. > My requirement is that the application needs to look as good on Windows as > on the Apple Mac Crossplatform GUIs are a myth, you *always* end up with a lowest common denominator (aka Windows) which makes your application look like crap on other platforms. And when the toolkit/framework only makes it look like semi-crap, it makes it *feel* like crap. Because, you know, user interfaces aren't only about the look but also (and most importantly) the feel, and the lowest common denominator (aka Windows) won't bring a Mac feel to your app. Crossplatform toolkits/frameworks suck. All of them. No exception. If you want your app to look *AND* feel great on all platform, abstract the core of your application and embed it in platform native GUI code. -- Luc Heinrich From m.yanowitz at kearfott.com Mon Dec 18 11:03:12 2006 From: m.yanowitz at kearfott.com (Michael Yanowitz) Date: Mon, 18 Dec 2006 11:03:12 -0500 Subject: Can a Tkinter GUI check for abort script: In-Reply-To: <605346.38535.qm@web31112.mail.mud.yahoo.com> Message-ID: <006901c722be$04c74f90$0d7d12ac@kearfott.com> Thank you (and Thanks to Hendrik). Both good ideas. I will need to do those or something similar too. But what I really want to know is what I need to do when pressing the "Run Script" button, so that I 'return' to the GUI every once in a while, like every 100 milliseconds to check if the "Abort Script" button is pressed. Presently what happens is that the script takes over and all the buttons on the GUI disappear as the GUI is not given any cpu time to refresh or check if any activity in the dialog. Thanks in advance: Michael Yanowitz -----Original Message----- From: python-list-bounces+m.yanowitz=kearfott.com at python.org [mailto:python-list-bounces+m.yanowitz=kearfott.com at python.org]On Behalf Of Mohammad Tayseer Sent: Monday, December 18, 2006 10:40 AM To: python-list at python.org Subject: Re: Can a Tkinter GUI check for abort script: To view a button & hide the other, call .pack_forget() on the button you want to hide & pack() on the button you want to show test3.py should contains a main() function that returns the new window. if you press 'Abort script' button you should call new_window.destroy(), pack_forget() the current button & pack() the 'run script' button __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From atkinw at rpi.edu Sat Dec 9 14:57:08 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 14:57:08 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > There is just not that much boilerplate in Python code, so there's > not so much need to hide it. Well, of course there is. There are always going to be patterns in the code you write that could be collapsed. Language has nothing to do with it; Lisp without macros would still be susceptible to boilerplate. Here's a concrete example: (let ((control-code (read-next-control-code connection))) (ecase control-code (+break+ (kill-connection connection) (throw :broken-by-client)) (+status+ (send-status-summary connection)) ((+noop+ +keep-alive+)))) ;; +X+ indicates a constant The standard ECASE macro encapsulates this pattern: Compare the variable control-code to +break+. If the two are EQL, then run the code provided in the +break+ clause. Likewise for +status+. In the last clause, the test-form is a list, so the generated code will compare control-code to either +noop+ or +keep-alive+. If it is EQL to either, it runs the body of that clause, which happens to be blank here. The E in ECASE stands for "error," so if control-code doesn't match any of these choices, the generated code will signal an error with the following text "CONTROL-CODE fell through ECASE expression; was not one of: +BREAK+, +STATUS+, +NOOP+, +KEEP-ALIVE+". All of that boilerplate is handled by the macro. In Python, I would need to do something like: control_code = connection.read_next_control_code() if control_code == +break+: connection.kill() throw blah else if control_code == +status+: connection.send_status_summary() else if control_code == +noop+ || control_code == +keep_alive+: else: error "CONTROL_CODE fell through conditional cascade; was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+" To change what control codes you want to check for, you need to add conditionals for them and keep the error text relevant. The reality is that a computer could be doing this for you, leaving your code simpler and more easily changed. Now someone will complain that the ECASE code means nothing until I understand ECASE. Yep. But once you understand ECASE, you can look at that code and, *at a glance*, see how control flows through it. In the equivalent Python code, I need to walk through each conditional and make sure they're all following the same pattern. If you're not convinced, extend the example to 12 different control codes. Note also that ECASE is just expanding to the COND conditional. There is nothing mind-bending (or even mind-twisty) going on inside of it. It's simply a way of expressing a common syntactic pattern in higher-level terms. To prove that macros are not the frightening beasts you guys are making them out to be: CL-USER 13 > (let ((*print-case* :downcase)) (pprint (macroexpand '(ecase control-code (+break+ (kill-connection connection) (throw :broken-by-client)) (+status+ (send-status-summary connection)) ((+noop+ +keep-alive+)))))) (let ((#:g17558 control-code)) (case #:g17558 (+break+ (kill-connection connection) (throw :broken-by-client)) (+status+ (send-status-summary connection)) ((+noop+ +keep-alive+)) (otherwise (conditions::ecase-error #:g17558 '(+break+ +status+ (+noop+ +keep-alive+)))))) If you treat the #:G17548 as just a weirdly-named variable, you can see that the code is just expanding into the standard CASE macro. I can in turn expand this CASE to: CL-USER 14 > (let ((*print-case* :downcase)) (pprint (macroexpand '(case #:g17558 (+break+ (kill-connection connection) (throw :broken-by-client)) (+status+ (send-status-summary connection)) ((+noop+ +keep-alive+)) (otherwise (conditions::ecase-error #:g17558 '(+break+ +status+ (+noop+ +keep-alive+)))))))) (let ((#:g17559 #:g17558)) (cond ((eql '+break+ #:g17559) (kill-connection connection) (throw :broken-by-client)) ((eql '+status+ #:g17559) (send-status-summary connection)) ((or (eql '+noop+ #:g17559) (eql '+keep-alive+ #:g17559)) nil) (t (conditions::ecase-error #:g17558 '(+break+ +status+ (+noop+ +keep-alive+)))))) COND is the Lisp conditional form. As you can see, ECASE does not blow your mind, but simply names and standardizes a common pattern of code. It expands into standard macros. And ECASE is so easy to write that most Lisp programmers have extended versions of it in their personal libraries. And most of these are named GENERIC-CASE or STRING-CASE, etc. and most expand into standard COND, CASE or ECASE macros. We are not going crazy and definining new langauges; we are simply extending Lisp to meet our needs, by creating macros that abstract common patterns. In many cases, the macros resemble standard, well-known Lisp macros even down to their names. (In the real world, I might use CLOS's eql-specifiers to define handlers for each kind of control code. But Python doesn't have anything analagous to that, so I'll be polite and pretend I have to use ECASE). From grante at visi.com Wed Dec 6 19:20:36 2006 From: grante at visi.com (Grant Edwards) Date: Thu, 07 Dec 2006 00:20:36 -0000 Subject: Mirror imaging binary numbers References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> <1165445569.287552.266120@j44g2000cwa.googlegroups.com> <1165446077.584437.206310@73g2000cwn.googlegroups.com> <1165448754.718593.200170@f1g2000cwa.googlegroups.com> Message-ID: <12nenik4vn4olf1@corp.supernews.com> On 2006-12-06, dickinsm at gmail.com wrote: > Yet another solution: > > def flipbits(x): > """reverse bits in a byte""" > x1 = x << 4 | x >> 4 > x2 = (x1 & 51) << 2 | (x1 & 204) >> 2 > return (x2 & 85) << 1 | (x2 & 170) >> 1 > > The idea is to first swap the two nybbles, then swap bits 0, > 1, 5, 6 with 2, 3, 6, 7 respectively, and finally swap bits 0, > 2, 4, 6 with bits 1, 3, 5, 7 respectively. It's a little less obtuse if you spell it this way: def flipbits(x): """reverse bits in a byte""" x1 = x << 4 | x >> 4 x2 = (x1 & 0x33) << 2 | (x1 & 0xcc) >> 2 return (x2 & 0x55) << 1 | (x2 & 0xaa) >> 1 -- Grant Edwards grante Yow! Now I understand the at meaning of "THE MOD SQUAD"! visi.com From kirk at nospam.jobsluder.net Sun Dec 10 09:21:17 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sun, 10 Dec 2006 14:21:17 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: In article , Steven D'Aprano wrote: > Yes. But you can't redefine 1+2 in Python, at least not without hacking > the interpreter. Can you redefine (+ 1 2) in Lisp? Not without barreling through error messages about name conflicts. From python.list at tim.thechases.com Wed Dec 6 14:03:47 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 06 Dec 2006 13:03:47 -0600 Subject: how to get all the "variables" of a string formating? In-Reply-To: References: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> Message-ID: <45771413.6080101@tim.thechases.com> >> Is there an easy (i.e.: no regex) way to do get the names of all >> parameters? >> >> get_parameters(template) should return ["name", "action"] > > How about: > > class gpHelper: > def __init__(self): > self.names = set() > def __getitem__(self, name): > self.names.add(name) > return 0 > > def get_parameters(template): > hlp = gpHelper() > template % hlp > return hlp.names > >>>> template=""" Hello %(name)s, how are you %(action)s""" >>>> get_parameters(template) > set(['action', 'name']) (darn, if I didn't have nearly identical code/reply, but two posts beat me to the Send button) Duncan's solution is a slightly more robust solution (returning 0 rather than returning the empty string), as format strings allow for things like "%(food)s costs $%(x)05.2f" % { 'x':3.14159, 'food':'a slice of pie' } which will choke if it gets a string instead of a number for attempts to get "x". It sure beats trying to hammer out a regexp or some stab at pyparsing it. Though I suppose one could do something like r = re.compile(r'%\(([^)]*)\)') as most of the edge-cases that I can think of that would cause problems in a general case would be problems for the string formatting as well (balanced parens, etc) -tkc From grflanagan at yahoo.co.uk Tue Dec 19 05:27:28 2006 From: grflanagan at yahoo.co.uk (Gerard Flanagan) Date: 19 Dec 2006 02:27:28 -0800 Subject: wrapping problem with old-style class In-Reply-To: <1166520577.085402.263580@48g2000cwx.googlegroups.com> References: <1166520577.085402.263580@48g2000cwx.googlegroups.com> Message-ID: <1166524048.252361.283790@73g2000cwn.googlegroups.com> manstey wrote: > The ipo class has three basic methods, namely, get, set, and > run_obj_method (which takes the Cache class method, as its first > argument, and the list of its arguments as the second argument) > > e.g. > >>> CacheClass=ipo() > >>> CacheClass.set('Name','John') > >>> valName = CacheClass.get('Name') > >>> print valName > 'John' > > I want to add functionality to ipo, so I have wrapped a new style class > (MyWrapper class, very basic) around it. > > PythonCacheClass=MyWrapper(CacheClass) > > Now, I want to make PythonCacheClass more pythonic, so I have a > dictionary of all the properties and values of each ipo. Eg > > dicCacheProperties = {'Name':'John', 'Address':'The Strand'} etc > for key, val in dicCacheProperties.iteritems(): > setattr(PythonCacheClass, key, val) > > So now I have: > >>>print PythonCacheClass.Name > 'John' > > My problem is this: how do I link the set and get methods of the ipo > class with the set and get methods in the wrapper class > PythonCacheClass? > > So, I would like the following code: > >>> PythonCacheClass.Name='Alexander' > to execute automatically > CacheClass.set('Name','Alexander') etc > Maybe try: class WrapperClass(BaseClass, object): get = object.__getattribute__ set = object.__setattr_ Gerard From python at hope.cz Sat Dec 2 03:33:26 2006 From: python at hope.cz (Lad) Date: 2 Dec 2006 00:33:26 -0800 Subject: Video feature Message-ID: <1165048406.302509.122060@16g2000cwy.googlegroups.com> I would like to add on my website a possibility for visitors to upload video and watch other user's video. How much difficult would it be with Python? Thank you any for idea. L. From martin.witte at gmail.com Fri Dec 29 10:57:30 2006 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 29 Dec 2006 07:57:30 -0800 Subject: I want to see all the variables In-Reply-To: References: Message-ID: <1167407850.869640.34780@a3g2000cwd.googlegroups.com> What do you mean? Can you specify which special functions you don't see? I get: py> class X: pass py> dir(X) ['__doc__', '__module__'] py> class X: def __getitem__(self, x): pass py> dir(X) ['__doc__', '__getitem__', '__module__'] On Dec 29, 12:35 pm, johnf wrote: > Hi, > When I use dir() I don't see the __ underscore items. Is there anything > that will show all the private vars and functions? > > johnf From jon at ffconsultancy.com Tue Dec 12 11:06:12 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 16:06:12 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> Message-ID: <457ed410$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> Andr? Thieme wrote: > Well, macros are one (big) thing that Lisp has and which many other > languages don't have. Their are other things too, and some of them are > in Python as well, which is a very nice scripting language. I think s-exprs and EVAL are the main things that Lisp has and that other languages don't. Note that most other languages don't have these because they were deemed to be a bad trade-off three decades ago. ;-) > Often macros save just some bits of code. Saving one loc is not much you > might say. But think about it the other way around. > How would you like it to call doodleShooble() each time before you use > the if statement? Of course you would not like it. The good thing about > Lisp is, that you can eliminate this pattern. You can eliminate that pattern with a HOF, of course. You don't need macros. let if' p e1 e2 = doodleShooble(); force (if p then e1 else e2) -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From renwei at koal.com Thu Dec 21 00:14:25 2006 From: renwei at koal.com (weir) Date: 20 Dec 2006 21:14:25 -0800 Subject: Does any one know of any good folder/directory modules In-Reply-To: <1166638399.367667.28410@48g2000cwx.googlegroups.com> References: <1166638399.367667.28410@48g2000cwx.googlegroups.com> Message-ID: <1166678065.775118.292980@79g2000cws.googlegroups.com> "moishyyehuda at gmail.com ??? " > Hi > > Does any one know of any good folder/directory modules. I need to be > able to see what files and directories are in a folder, I also need to > be able to see the size of the directory content. > > Thanks This one is more convenient: http://www.jorendorff.com/articles/python/path From gagsl-py at yahoo.com.ar Mon Dec 18 13:46:06 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 18 Dec 2006 15:46:06 -0300 Subject: Windows Authetication vs seperate process In-Reply-To: <1166459095.924198.62170@n67g2000cwd.googlegroups.com> References: <1166459095.924198.62170@n67g2000cwd.googlegroups.com> Message-ID: <7.0.1.0.0.20061218154326.0400f350@yahoo.com.ar> At Monday 18/12/2006 13:24, imageguy1206 at gmail.com wrote: >With several packages I have seen options to "Use Windows >Authentication", which seems to mean that "If the user has >authenticated and signed onto Windows, then our application will use >their windows userid and we will just focus on the the tasks within our >application the user is authorized to perform" Search for SSPI. But it may be a bit tricky to get running. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From yao1337 at gmail.com Sat Dec 2 09:13:16 2006 From: yao1337 at gmail.com (purple) Date: 2 Dec 2006 06:13:16 -0800 Subject: How to realize the interactive python in Eclipse? Message-ID: <1165068796.417513.86280@n67g2000cwd.googlegroups.com> I have installed the Eclipse and the plug-in Pydev. Also, I have add an python program in the external tools. When I run the python program in the external tools, i can type python command just like in the python shell.But when I finished running a python file, in the console, I could not type any command to check some argument generated in the process. Is there any way I can make it? thank you~~ From timr at probo.com Sun Dec 3 00:13:03 2006 From: timr at probo.com (Tim Roberts) Date: Sun, 03 Dec 2006 05:13:03 GMT Subject: v2.3, 2.4, and 2.5's GUI is slow for me References: <7630074.post@talk.nabble.com> Message-ID: <55n4n25cnrj6r7mblb77ec5pe20m85k1pa@4ax.com> g4rlik wrote: > >No one can help? This is seriously bugging me to no end. You waited 2 hours before posting this reply. Please note that Usenet is NOT a real-time medium. It can take half a day or more before your posting makes it to all the news servers around the world, and much longer before people actually download the message to their local reader, then an equal amount of time for replies to get back to you. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bj_666 at gmx.net Tue Dec 19 13:36:50 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Tue, 19 Dec 2006 19:36:50 +0100 Subject: When Closure get external variable's value? References: <1166473333.593246.238580@73g2000cwn.googlegroups.com> <1166474513.700608.201760@48g2000cwx.googlegroups.com> <1166542026.913912.82880@t46g2000cwa.googlegroups.com> <1166544951.721977.281100@t46g2000cwa.googlegroups.com> Message-ID: In <1166544951.721977.281100 at t46g2000cwa.googlegroups.com>, Huayang Xia wrote: > That is a really concise and precise answer. Thanks. > > So the object binding can only happen explicitly at the closure > declaration argument list(non-free variable). That's no declaration that's a definition and it happens at runtime! It's executed every time the outer function is called and executed and creates a function object. As far as I can see you don't create a closure BTW. You are *calling* that inner function and return the *result* of that call. Ciao, Marc 'BlackJack' Rintsch From exarkun at divmod.com Fri Dec 1 09:30:03 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Fri, 1 Dec 2006 09:30:03 -0500 Subject: I/O Multiplexing and non blocking socket In-Reply-To: <1164982048.938862.228890@79g2000cws.googlegroups.com> Message-ID: <20061201143003.20948.510022723.divmod.quotient.53269@ohm> On 1 Dec 2006 06:07:28 -0800, Salvatore Di Fazio wrote: >Hi guys, >I'm looking for a tutorial to make a client with a i/o multiplexing and >non blocking socket. > >Anybody knows where is a tutorial? http://twistedmatrix.com/projects/core/documentation/howto/clients.html Jean-Paul From kay.schluehr at gmx.net Mon Dec 11 17:06:21 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 11 Dec 2006 14:06:21 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165857489.067258.27160@j44g2000cwa.googlegroups.com> Message-ID: <1165874781.930864.26750@16g2000cwy.googlegroups.com> Juan R. wrote: > Kay Schluehr ha escrito: > > Note also that a homogenous syntax is not that important when > > analyzing parse trees ( on the contrary, the more different structures > > the better ) but when synthesizing new ones by fitting different > > fragments of them together. > > Interesting, could you provide some illustration for this? My approach is strongly grammar based. You start with a grammar description of your language. This is really not much different from using Lex/Yacc except that it is situated and adapted to a pre-existing language ecosystem. I do not intend to start from scratch. Besides the rules that constitute your host language you might add: repeat_stmt ::= 'repeat' ':' suite 'until' ':' test The transformation target ( the "template" ) is while True: if : break The structure of the rule is also the structure of its constituents in the parse tree. Since you match the repeat_stmt rule and its corresponding node in the parse tree you immediately get the node and the node: class FiberTransformer(Transformer): @transform def repeat_stmt(self, node): _suite = find_node(node, symbol.suite) _ test = find_node(node, symbol.test, depth = 1) # # create the while_stmt here # return _while_stmt_node So analysis works just fine. But what about creating the transformation target? The problem with the template above is that it can't work precisely this way as a Python statement, because the rule for a while statement looks like this: while_stmt: 'while' test ':' suite That's why the macro expander has to merge the node, passed into the template with the if_stmt of the template, into a new suite node. Now think about having created a while_stmt from your original repeat_stmt. You return the while_stmt and it has to be fitted into the original syntax tree in place of the repeat_stmt. This must be done carefully. Otherwise structure in the tree is desroyed or the node is inserted in a place where the compiler does not expect it. The framework has to do lots of work to ease the pain for the meta programmer. a) create the correct transformation target b) fit the target into the syntax tree Nothing depends here particularly on Python but is true for any language with a fixed grammar description. I've worked exclusively with LL(1) grammars but I see no reason why this general scheme shall not work with more powefull grammars and more complicated languages - Rubys for example. > > The next question concerns compositionality of language > > enhancements or composition of even completely independent language > > definitions and transformers both on source and on binary level. While > > this is not feasible in general without creating ambiguities, I believe > > this problem can be reduced to ambiguity detection in the underlying > > grammars. > > A bit ambiguous my reading. What is not feasible in general? Achieving > compositionality? Given two languages L1 = (G1,T1), L2 = (G2, T2 ) where G1, G2 are grammars and T1, T2 transformers that transform source written in L1 or L2 into some base language L0 = (G0, Id ). Can G1 and G2 be combined to create a new grammar G3 s.t. the transformers T1 and T2 can be used also to transform L3 = (G3 = G1(x)G2, T3 = T1(+)T2) ? In the general case G3 will be ambigous and the answer is NO. But it could also be YES in many relevant cases. So the question is whether it is necessary and sufficient to check whether the "crossing" between G1 and G2 is feasible i.e. doesn't produce ambiguities. From gagsl-py at yahoo.com.ar Thu Dec 7 22:36:39 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 08 Dec 2006 00:36:39 -0300 Subject: subversion revision number string within an application packaged with distutils? In-Reply-To: <1165542556.714372.193340@n67g2000cwd.googlegroups.com> References: <1165542556.714372.193340@n67g2000cwd.googlegroups.com> Message-ID: <7.0.1.0.0.20061208002813.04048d78@yahoo.com.ar> At Thursday 7/12/2006 22:49, Jim Tittsler wrote: >Is there a standard recipe for getting the subversion revision number >into my Python-based application each time I package it up with >distutils? (Not just the package name, but also a string that I will >display in my app's "About" dialog.) Under CVS, you use keywords like $Id$, $Author$, $Revision$ etc inside your code, they get expanded like this: __version__ = '$Revision: 1.8 $'[11:-2] Subversion uses a similar mechanism but I'm not sure of the spelling. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From klaus at seistrup.dk Fri Dec 8 11:51:23 2006 From: klaus at seistrup.dk (Klaus Alexander Seistrup) Date: Fri, 8 Dec 2006 16:51:23 +0000 (UTC) Subject: shell command needs whitespace characters escaped References: <1165596153.961003.285080@16g2000cwy.googlegroups.com> Message-ID: Metaperl wrote: > I downloaded a file which has a space in the filename. I want > to run a shell unzip on it, but it fails in my current code: > > syscmd = "cd %s ; unzip %s" % (self.storage.input, file.basename()) > os.system(syscmd) > > because no escaping was done. Using "cd '%s' ; unzip '%s'" as your formatting string should work. Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ From george.sakkis at gmail.com Mon Dec 4 12:13:26 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 4 Dec 2006 09:13:26 -0800 Subject: Factory pattern implementation in Python References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> Message-ID: <1165252406.405431.294040@79g2000cws.googlegroups.com> googlegroups at romulo.e4ward.com wrote: > Hi, > > I need to parse a binary file produced by an embedded system, whose > content consists in a set of events laid-out like this: > > ... > > Every "event" is a single byte in size, and it indicates how long is > the associated "data". Thus, to parse all events in the file, I need to > take it like a stream and read one event at a time, consuming bytes > according to the event value, and jumping to the next event, until an > EOF is reached. > > Since there are dozens of almost completely heterogeneous events and > each one of them may imply different actions on the program parsing the > file, I thought it would be convenient to have one class encapsulating > the logic for every event. The parser would then sit in a loop, > creating objects of different classes and calling a method (say > "execute"). That method (different in every class) is responsible for > consuming the bytes associated with the event. > > Hence, as the class the parser needs to instantiate in each iteration > is not known in advance, a factory should be implemented. Somehow the > factory should know how to map an event to a class. I don't know of the > best way I should do that in Python. I made an attempt along the > following lines: > > 1. Create a base class for the events; > 2. For every descendant class declare (in the class body) a public > attribute "eventNum" and assign it the value of the event it will be > responsible for; > 3. At runtime, the factory constructor scans the event class hierarchy > and builds a dictionary mapping "eventNum"'s to classes. > > A draft of the implementation follows: > > ################################# > > ##### ##### > > class EvtBase: > def __init__(self, file): > self.file = file > > def execute(self): > pass > > class Evt1(EvtBase): > eventNum = 1 > def execute(self): > ... > > class Evt2(EvtBase): > eventNum = 2 > def execute(self): > ... > > ... > > class EvtN(EvtBase): > eventNum = N > def execute(self): > ... > > > ##### ##### > > import inspect > import events > > class Factory: > def __isValidEventClass(self, obj): > if inspect.isclass(obj) and obj != events.EvtBase and \ > events.EvtBase in inspect.getmro(obj): > for m in inspect.getmembers(obj): > if m[0] == 'eventNum': > return True > return False > > def __init__(self): > self.__eventDict = {} > for m in inspect.getmembers(events, self.__isValidEventClass): > cls = m[1] > self.__eventDict.update({cls.eventNum: cls}) > > def parseEvents(self, file): > while not file.eof(): > ev = file.read(1) > self.__eventDict[ev](file).execute() > > ################################# > > I'm using the inspect module to find the event classes. One drawback of > this approach is the need to keep the event classes in a module > different from that of the factory, because the getmembers method > expects an already parsed object or module. (The advantage is keeping > the event number near the class declaration.) I've already had to make > the solution generic and I found it was not straightforward to separate > the common logic while avoiding the need to keep the factory and the > events in two distinct modules. > > Is there anything better I can do? I don't have enough experience with > Python, then I don't know whether it offers a more obvious way to > address my problem. > > Thanks in advance. If you actually intend to 1) name your Event subclasses Evt1, Evt2, ... EvtN and not give more descriptive (but unrelated to the magic event number) names, and 2) put them all in one module (events.py), you can avoid the code duplication of putting the event number both in the class name and as a class attribute. Your dispatcher could then be as simple as: import events def parseEvents(file): while not file.eof(): ev = int(file.read(1)) cls = getattr(events, 'Evt%d' % ev) cls(file).execute() By the way, it is not clear from your description if the event number equals to the size of the associated data. If it is, you can factor out the data extraction part in the factory function and pass just the extracted data in the Event constructor instead of the file: def parseEvents(file): while not file.eof(): ev = int(file.read(1)) cls = getattr(events, 'Evt%d' % ev) cls(file.read(ev)).execute() George From ronrsr at gmail.com Mon Dec 18 01:02:11 2006 From: ronrsr at gmail.com (ronrsr) Date: 17 Dec 2006 22:02:11 -0800 Subject: dealing with special characters in Python and MySQL Message-ID: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> I have an MySQL database called zingers. The structure is: zid - integer, key, autoincrement keyword - varchar citation - text quotation - text the encoding and collation is utf-8 I am having trouble storing text, as typed in last two fields. Special characters and punctuation all seem not to be stored and retrieved correctly. Special apostrophes and single quotes from Microsoft Word are causing a special problem, even though I have ''ed all 's error messages, when trying to save to database: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 71: ordinal not in range(128) args = ('ascii', "update zingers set keywords = ' aaaaaa;Action', ...ation = '''''''''''''\n\n ' where zid = 422", 71, 72, 'ordinal not in range(128)') encoding = 'ascii' end = 72 object = "update zingers set keywords = ' aaaaaa;Action', ...ation = '''''''''''''\n\n ' where zid = 422" reason = 'ordinal not in range(128)' start = 71 I think my problem may be that I need to encode the string before saving it in the databse. Can anyone point me in the right direction here? Thanks so much, From rampeters at gmail.com Wed Dec 13 21:07:19 2006 From: rampeters at gmail.com (johnny) Date: 13 Dec 2006 18:07:19 -0800 Subject: newb: Creating Exception In-Reply-To: <1166060677.580470.269540@n67g2000cwd.googlegroups.com> References: <1165881722.928958.81490@79g2000cws.googlegroups.com> <1165954233.519919.107940@l12g2000cwl.googlegroups.com> <1166010331.697359.46400@n67g2000cwd.googlegroups.com> <1166010769.505973.41640@j72g2000cwa.googlegroups.com> <1166060677.580470.269540@n67g2000cwd.googlegroups.com> Message-ID: <1166062039.328097.288380@73g2000cwn.googlegroups.com> I checked out couple of books from Library, one that I like called "Foundation of Python Network Programming", this is what I needed, code with understandable explantion. ;) Thread pooling and many others. Thanks all of you for the help. Dustan wrote: > Dennis Lee Bieber wrote: > > On 13 Dec 2006 03:52:49 -0800, "Dustan" > > declaimed the following in gmane.comp.python.general: > > > > > > > > I didn't complete my thought. If you run into a situation like this, > > > then you might want to look to the python documentation on the web for > > > help; think of the web documentation as a reference manual rather than > > > a tutorial, even though it does provide a tutorial. > > > > I believe it was stated that the installation was using the > > ActiveState build. The documentation is supplied in Windows CHM format, > > which is likely much faster to search/read locally than loading a chain > > of web pages. > > I couldn't think of a better word to describe the 'official' > documentation. > > > Including, last time I checked, an electronic copy of "Dive into > > Python" From steve at REMOVE.THIS.cybersource.com.au Tue Dec 26 18:51:56 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Wed, 27 Dec 2006 10:51:56 +1100 Subject: How to depress the output of an external module ? References: Message-ID: On Tue, 26 Dec 2006 03:21:57 -0800, Luis Armendariz wrote: > On Tuesday, 26.12.06 at 21:28, Steven D'Aprano wrote: >> >> # WARNING: untested >> def run_without_stdout(*args, **kwargs): >> function = args[0] >> args = args[1:] >> savestdout = sys.stdout >> sys.stdout = cStringIO.StringIO() >> result = None >> try: >> result = function(*args, **kwargs) >> finally: >> # don't forget to restore stdout, or you >> # really will regret it... >> sys.stdout = savestdout >> return result >> > > There's no need for savestdout. There's a backup copy in sys.__stdout__ You shouldn't assume that sys.stdout is standard output when the function is called. It may already have been reassigned to something else. My code will restore sys.stdout to whatever state it was in before the function ran. -- Steven. From bj_666 at gmx.net Thu Dec 28 07:43:34 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Thu, 28 Dec 2006 13:43:34 +0100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: In , Felix Benner wrote: > I like using tabs. And the style guide doesn't give a reason why one > shouldn't and neither does the thread > http://www.python.org/search/hypermail/python-1994q2/0198.html in the > archive. > So what's the point in typing four spaces for indentation instead of one > tab? You don't need to type four spaces. Every decent editor lets you use the Tab key and inserts the proper amount of spaces for you. Same for Backspace removing the proper amount of spaces to get to the previous "tab stop". There are plenty of "reasons" from both sides. This is a religious issue, so please search the net for answers and don't start another flam^H^H^H^Hdebate here. Please! Ciao, Marc 'BlackJack' Rintsch From atkinw at rpi.edu Sat Dec 9 22:58:16 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 22:58:16 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: Steven D'Aprano writes: > On Sat, 09 Dec 2006 17:01:15 -0500, Ken Tilton wrote: > >>> How's this a good thing? I don't need a Python environment to grok >>> Python code. >> >> How would that be a bad thing? Do you do a lot of programming without a >> Python environment. But I love the wall of flak you are throwing up. :) > > Actually, yes, sometimes it is useful to print code out and read it on the > train, or in the bath, without the advantage of syntax highlighting, > pretty-printing, parenthesis-balancing or code folding. Not necessarily as > pleasant as having all those things, but it is nice that working Python > code is, by definition, already formatted correctly for pretty printing. > Even if you're stuck on some god-forsaken Windows PC with just Notepad, > you can still read Python code. > > Now, *writing* Python code with Notepad isn't as easy, but it is still > doable. How about Lisp code? Of course we can read Lisp without IDE's; we look for indentation cues just as you guys do. > That's not a criticism of Lisp exactly, but a reminder to think about not > just what problem you're trying to solve, but what resources you will have > to solve it. If you *know* that you're going to need to edit code by > ssh-ing across an high-latency connection to a machine without Emacs, then > Lisp will probably not be the best solution. Oh no? Emacs lets you save and write files over an SSH connection, even if you end up in the strange straw man situation you're describing ("yeah, but can you edit Lisp if your keyboard doesn't have paren keys?"). From mail at razor.dk Wed Dec 27 15:31:31 2006 From: mail at razor.dk (Christian Joergensen) Date: Wed, 27 Dec 2006 21:31:31 +0100 Subject: Superclass for Errors? References: <1167250385.193546.125700@h40g2000cwb.googlegroups.com> Message-ID: <87slf13wt8.fsf@jamie.razor.dk> "tac-tics" writes: > I have a program which has a GUI front-end which that runs a separate > thread to handle all the important stuff. However, if there is a > problem with the important stuff, I want the GUI to raise a MessageBox > alert to indicate this. > > For exceptions, I can simply use a catch-all except statement like: > > try: > ... > except Exception, error: > JOptionPane.showMessageDialog(self, "Error: %s" % error) > > Only, I want it to catch Errors as well. Right now, I'm using: > > try: > ... > except (Exception, TypeError, NameError, RuntimeError, AttributeError), > error: > JOptionPane.showMessageDialog(self, "Error: %s" % error) > > I was wondering if there is a superclass for TypeError, NameError, > RuntimeError, AttributeError, etc. See http://rgruet.free.fr/PQR25/PQR2.5.html#BuiltInExc I would guess you're looking for StandardError. -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info From bearophileHUGS at lycos.com Fri Dec 15 06:15:35 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 15 Dec 2006 03:15:35 -0800 Subject: Writing and reading variables to/from flat file In-Reply-To: <45817a71$1_1@glkas0286.greenlnk.net> References: <84548$45816e6c$4275d90a$16465@FUSE.NET> <45817a71$1_1@glkas0286.greenlnk.net> Message-ID: <1166181335.465074.203230@16g2000cwy.googlegroups.com> Geoffrey Clements: > readfile = open('prefs').readlines() > for line in readfile: > print line > eval(line) > print Basic Instead of using eval, using a plain dict may be a better solution. Bye, bearophile From kay.schluehr at gmx.net Fri Dec 8 15:25:09 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Dec 2006 12:25:09 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> <1165593798.079105.144060@80g2000cwy.googlegroups.com> <45799841$0$49201$14726298@news.sunsite.dk> Message-ID: <1165609509.370461.122170@73g2000cwn.googlegroups.com> O.K. I agree with what you said about the generic function vs per object dictionary dispatch. But do the performance differences vanish when only builtin types and functions are used to express Python algorithms? From chrysain at gmail.com Fri Dec 29 02:50:27 2006 From: chrysain at gmail.com (=?ISO-8859-7?B?1/H189zt6Ocgwfrt4eve?=) Date: Fri, 29 Dec 2006 09:50:27 +0200 Subject: Convert Perl to Python Message-ID: <66b602900612282350ic0d4630x44640f90c0c774ca@mail.gmail.com> How can I convert a perl script to Python? Thank you! From horpner at yahoo.com Mon Dec 11 14:46:40 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 11 Dec 2006 20:46:40 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: On 2006-12-09, Bill Atkins wrote: > I'm afraid you're on the wrong track. Any programmer can pick > up Lisp and be productive in it these days. Please don't try > to make Lisp seem more mysterious or elitist than it really is. > It's just a programming language, and anyone can learn it: > > http://www.gigamonkeys.com/book I got stuck (last year) in that book: http://www.gigamonkeys.com/book/practical-a-portable-pathname-library.html The author didn't do Common Lisp (or me) any favors by drawing my attention to the pathname library. I suppose I missed whatever the point was supposed to be in the midst of the mind-boggling. I meant to get back to it but haven't yet. -- Neil Cerutti We will sell gasoline to anyone in a glass container. --sign at Santa Fe gas station From ask at me Sat Dec 9 00:00:26 2006 From: ask at me (alf) Date: Fri, 08 Dec 2006 23:00:26 -0600 Subject: testing for valid reference: obj vs. None!=obs vs. obj is not None In-Reply-To: References: Message-ID: alf wrote: > Hi, > > I have a reference to certain objects. What is the most pythonic way to > test for valid reference: > > if obj: > > if None!=obs: > > if obj is not None: > thx for all answers - now "if obj is not None:" in an obvious choice ... From clarence1126 at gmail.com Tue Dec 12 20:09:31 2006 From: clarence1126 at gmail.com (Clarence) Date: 12 Dec 2006 17:09:31 -0800 Subject: -W: Python bug? Documentation bug? Message-ID: <1165972171.158876.164660@73g2000cwn.googlegroups.com> It appears that the -W option on starting python doesn't work the same as the warnings module. In particular, the "message" parameter is not treated as a regular expression, but rather a string literal which must appear at the beginning of a warning message in order to match. The treatment of -W in "python -h" makes no mention of the warnings module (and I actually couldn't find any definitive documentation on command line switches), though the documentation for the warnings module does say: The interpreter saves the arguments for all -W options without interpretation in sys.warnoptions; the warnings module parses these when it is first imported That also kind of maybe implies that warnings is automatically imported by the interpreter, but it doesn't actually say so. How should this be treated? ========= Here's an example of the problem. (I've reproduced it in version 2.5 also) $ python -W ignore:whenThreaded Python 2.4.2 (#2, Mar 10 2006, 15:10:56) [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5 Type "help", "copyright", "credits" or "license" for more information. >>> from twisted.internet import reactor /usr/local/lib/python2.4/site-packages/twisted/internet/base.py:245: DeprecationWarning: threadable.whenThreaded is deprecated. Use application-level logic instead. threadable.whenThreaded(self.initThreads) >>> $ python -W ignore:'threadable.whenThreaded is deprecated. Use application-level logic instead.' Python 2.4.2 (#2, Mar 10 2006, 15:10:56) [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5 Type "help", "copyright", "credits" or "license" for more information. >>> from twisted.internet import reactor >>> $ python -W ignore:threadable.whenThreaded Python 2.4.2 (#2, Mar 10 2006, 15:10:56) [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5 Type "help", "copyright", "credits" or "license" for more information. >>> from twisted.internet import reactor >>> From jon at ffconsultancy.com Fri Dec 15 11:54:47 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Fri, 15 Dec 2006 16:54:47 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> <1166035311.357588.115070@80g2000cwy.googlegroups.com> <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> <1166137839.139465.280830@16g2000cwy.googlegroups.com> Message-ID: <4582d3ee$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> Filip Wasilewski wrote: > Jon Harrop wrote: >> Yes. The time taken is dominated by memory accesses. The amount of >> arithmetic is almost irrelevant. > > I can say from my experience, that this depends much on the input size > and the CPU cache size. For arrays of about n^18 or less and 2MB cache > the speedup for the straightforward C lifting implementation is around > 50%, while all operations are done in-place. For bigger arrays > traversing memory several times becomes too expensive, at least until > the input size is so big that the memory gets swapped and the inplace > method becomes faster again. I suppose that such behavior should be > quite similar for other low-level implementations as well. With my two OCaml implementations, the lifting scheme is always slower. Here is n vs t for convolution (i.e. a simple loop): {{4, 0.0000001}, {8, 0.0000003}, {16, 0.0000006}, {32, 0.0000012}, {64, 0.0000023}, {128, 0.0000046}, {256, 0.0000089}, {512, 0.0000178}, {1024, 0.0000355}, {2048, 0.0000720}, {4096, 0.0001445}, {8192, 0.0002968}, {16384, 0.0005956}, {32768, 0.0012225}, {65536, 0.0029214}, {131072, 0.0062959}, {262144, 0.0128418}, {524288, 0.0259961}, {1048576, 0.0519921}, {2097152, 0.1037343}, {4194304, 0.2064685}, {8388608, 0.4059380}} and the same for the lifting scheme with deforesting optimisations: {{4, 0.0000006}, {8, 0.0000013}, {16, 0.0000026}, {32, 0.0000048}, {64, 0.0000091}, {128, 0.0000174}, {256, 0.0000341}, {512, 0.0000681}, {1024, 0.0001373}, {2048, 0.0002736}, {4096, 0.0005483}, {8192, 0.0010936}, {16384, 0.0022086}, {32768, 0.0044017}, {65536, 0.0087643}, {131072, 0.0176380}, {262144, 0.0357446}, {524288, 0.0720515}, {1048576, 0.1449780}, {2097152, 0.2912058}, {4194304, 0.5824115}, {8388608, 1.1698220}} The results will vary between languages, of course, but from this it looks like convolution is ~3x faster for 4 <= n <= 2^23. Can convolution be implemented efficiently in Python? > Actually I started to wonder if I could automate conversion of > multi-loop lifting schemes [1] into one-pass loop. See below. > This could be done > by delaying computation of the "coming next" step just by few > units, until values from the preceding step are ready to use. Exactly. Functional programming makes this easy. You just compose closures from closures instead of arrays from arrays. I discussed exactly this technique in the context of the travelling salesman problem in my book "OCaml for Scientists". >> I used a more efficient approach because I could. Using a compiled >> language gave me that choice. We should compare both approaches in both >> languages. > > I am getting a bit tired of this discussion. I am not arguing which > approach is faster, because it very much depends on the use case. Compiled code is virtually always faster. > I > just ask you to do fair comparison using the original algorithm > presented here instead of forcing your arguments with the > not-so-relevant variant convenient for you. This is the third time that I've presented both variants. Now I've presented detailed timings as well. Where's the other Python implementation? > Every language (or at least vast majority of them) that has loops and > basic arithmetic gives you such choice, no matter compiled or not. I am under the impression that it is prohibitively slow in Python. > If the OCaml is so superior as you claim, I'm not claiming that OCaml is superior. I took the original Matlab vs Python language performance comparison and showed that C++, OCaml and F# all outperform both Matlab and Python. I'm keen to see what advantages Python has. > please show me how to do the lifting scheme > (preferably in the > http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 > form with features described in my previous post) so I could actually > learn something new and maybe even start to consider it as a possible > alternative to C-ish language family. Here's a starter. Your Python translated directly to functional OCaml/F# that simply constructs new arrays at every step: let rec d4_aux cA = function | 0 -> [cA] | n -> let n = n/2 in let f = init n in let even = f (fun i -> cA.(2*i)) in let odd = f (fun i -> cA.(2*i + 1)) in let even = f (fun i -> even.(i) +. c1 *. odd.(i)) in let odd = f (function | 0 -> odd.(0) -. c2 *. even.(0) -. c3 *. even.(n-1) | i -> odd.(i) -. c2 *. even.(i) -. c3 *. even.(i-1)) in let even = f (function | i when i=n-1 -> even.(i) -. odd.(0) | i -> even.(i) -. odd.(i+1)) in let even = f (fun i -> c4 *. even.(i)) in let odd = f (fun i -> c5 *. odd.(i)) in odd :: d4_aux even n;; Note the use of the "init" function, allocating and filling new arrays at every step of the computation. The advantages of the above code are not immediately apparent. However this is trivially deforested (i.e. multi-pass -> single pass) by accumulating new closures "even" and "odd" rather than new arrays: let rec d4_aux cA = function | 1 -> [cA] | n -> let n = n/2 in let even i = cA.(2*i) in let odd i = cA.(2*i + 1) in let even i = even i +. c1 *. odd i in let odd = function | 0 -> odd 0 -. c2 *. even 0 -. c3 *. even (n-1) | i -> odd i -. c2 *. even i -. c3 *. even (i-1) in let even = function | i when i = n-1 -> even (i) -. odd (0) | i -> even (i) -. odd (i+1) in let even = init n (fun i -> c4 *. even i) in let odd = init n (fun i -> c5 *. odd i) in odd :: d4_aux even n;; The code is almost identical but five of the seven O(n) array allocations have been replaced with O(1) closure allocations. The change simply replaces array lookup "a.(i)" with function invocation "a i". On my machine, your original Python took 2.49s, the forested OCaml above takes 1.34s and the deforested OCaml takes 1.16s. The deforesting optimisation is only possible because OCaml is compiled. If you do the same transformation in Python the program will become vastly slower because the closures must be interpreted for each array element. This is what I meant by optimising Python takes you in the wrong direction (foresting). I think you're only using slice-based rewriting because it is fast in Python, not because it is a good idea. So, is it worth adding slicing to F#? > As far as the DWT only is concerned, well, If I were to choose the most > efficient approach (in both the CPU time and the development time > terms) for Python I would use a ready extension instead of developing > the wheel once again. Let me think, that should go something like this: > > import pywt > coeffs = pywt.wavedec(x, 'db2', 'per') Is there a difference between this in Python and in any other language? >>> ... >> That is also an abstraction of get/set. > > Oh my, are all these abstractions to be put into reality every time > from a scratch? This entails converting "a.(i)" to "a i", so it isn't a big deal. >> > axis and maximum decomposition level as input >> >> I don't know what that is. > > When doing 1D operations on a multidimensional array it is often > convenient to be able to specify along which axis these operations > should be performed, for example: > >>>> x = numpy.ones((2,4)) >>>> x.sum(axis=0) > array([ 2., 2., 2., 2.]) >>>> x.sum(axis=1) > array([ 4., 4.]) I see. This can also be accomplished using functional programming. You have an array lookup that accepts an array of indices and build a closure that fills in all of the dimensions except the one you're looping over. The main difference is probably that I'd statically type the dimensionality of the arrays. I'll have a play with this. > The maximum level denotes how many decomposition steps should be > performed for multilevel transform. Just like described on > http://www.mathworks.com/access/helpdesk/help/toolbox/wavelet/wavedec.html What about a lazy list? >> > with transform coefficients for every level of >> > decomposition. Can do? >> >> Sure. Sounds like a lot of work though. > > See. It's for sure pretty much work to create a general solution in C. I looked at some of the sophisticated wavelet libraries when I did my PhD on wavelets and they were seriously complicated. Lisp might also be worth considering because you could easily compile efficient implementations of transforms that you were interested in. > It is a lot easier to focus on the real problem when using Python (and > NumPy or other package from a wide range of available extensions) and > save yourself getting much into implementation details while still > maintaining reasonable performance. I'm not sure, but you might find it better to factor what you're doing using functional programming constructs. The results will probably be almost as easy to use whilst being easier to optimise, e.g. by deforesting. If you're a researcher then I'm sure there's some new work to be done in this area... > That is one of the most important > reasons I prefer to use high-level language for most of my tasks. I > also try to avoid doing premature optimizations that could spare some > CPU cycles, just to see in a few moments that the performance gain is > completely swallowed by I/O overhead on some remote data access point. Absolutely. Good factorisation of your code will let you do that, as well as leveraging existing libraries as you already are. You will probably miss numpy if you try OCaml though. I'm keen to hear what you'd miss about numpy though, as we can add it to F#. :-) > For the rest of intensive number crunching, if there is no specialized > extension available yet, I still prefer to use the Python/Pyrex/C or > similar combo to get solution that can be easily integrated with other > parts of a bigger system (like networking, databases, reports, web, > etc. - wow, how many things the transition from C++ and Java few years > ago made just so accessible) or just used to play in the interactive > mode. That makes perfect sense. I think F# could become a better Python but I need to understand the relative benefits offered by Python first. >> I can't get that to work in Python. What do I need to do? > > Type exactly as presented above, starting from the very first line. The > `from module import ...` imports chosen identifiers into current > namespace, so you don't have to prefix them with module name. Sorry, I mistook the first line for English. :-) >> Well, OCaml does ok on the sudoku but K does awfully on the ray tracer. > > That's pretty natural. Different languages are designed to solve > different tasks. I hope your point is not to convince people to use > OCaml to solve (or complicate) every possible problem. Not at all. I haven't used OCaml for a while now because I'm working with F# instead. Both languages have a lot of merits but the time is ripe to add the features that you're touting from Python to F# because it is still evolving. We've yet to consider Scheme/Lisp for this task... >> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html > > Yes, I found this before but it is not very helpful to start with. Any > doc with basic use cases and examples would be much better. Think of it > as a possible restraint for people trying to learn the language. I'll try to find one. >> You probably want to use F# though. > > On the other hand, I wonder how this integrates with other .net > languages like C# or IronPython. Seamlessly. C# is very easy (look at my examples, which use C# interfaces from .NET). FFI to C is also very easy. There is a nice example of interfacing to LAPACK in the F# distro. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From tjreedy at udel.edu Wed Dec 6 21:35:29 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Dec 2006 21:35:29 -0500 Subject: True Division in Python References: <1165448464.077200.128340@n67g2000cwd.googlegroups.com> Message-ID: wrote in message news:1165448464.077200.128340 at n67g2000cwd.googlegroups.com... > For a long time,, There has been a discussion of trueFor division > versus integer division in Python. The discussion and the decision to use // and / were years ago. > I myslef prefer that / be used for integer division since almost > always, I want the result of the > division be truncated to integer. So use // > However, today I reviewed the method to be used in Python to get true > division, and this gave > me an idea how true division could be implemented without interferring > with the use of > / for integer division. > Use / for integer division > single slash is the operator for integer division. > Use ./ for true division. > period slash is the operator for true division. Proposing to use / and ./ instead of // and / is a waste of time. Really Terry Jan Reedy From grante at visi.com Sun Dec 3 13:45:04 2006 From: grante at visi.com (Grant Edwards) Date: Sun, 03 Dec 2006 18:45:04 -0000 Subject: Parsing data from pyserial References: <12n5nt138bcb109@corp.supernews.com> <1165171254.109294.281020@80g2000cwy.googlegroups.com> Message-ID: <12n66pgssk3va01@corp.supernews.com> On 2006-12-03, John Machin wrote: > Grant Edwards wrote: > >> When something odd seems to be happening with strings, always >> print `whatever` rather than whatever >> > >:-) > > Unholy perlism, Batman! OK, make that "print repr(whatever)". :) -- Grant Edwards grante Yow! I selected E5... but at I didn't hear "Sam the Sham visi.com and the Pharoahs"! From fredrik at pythonware.com Mon Dec 4 15:04:05 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 21:04:05 +0100 Subject: Why not just show the out-of-range index? In-Reply-To: <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> <45745C9E.9050500@v.loewis.de> <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> Message-ID: BJ?rn Lindqvist wrote: > Sorry I haven't thought this through 100% obviously not. From atkinw at rpi.edu Fri Dec 8 11:47:58 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Fri, 08 Dec 2006 11:47:58 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: "Mark Tarver" writes: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. > > Mark What was the reasoning behind cross-posting this to c.l.p and c.l.l? This type of question inevitably leads to controversy. From Amateur.N7TZG at gmail.com Fri Dec 15 17:12:36 2006 From: Amateur.N7TZG at gmail.com (Rob) Date: 15 Dec 2006 14:12:36 -0800 Subject: Serial port failure In-Reply-To: References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> <1166219528.807953.308840@80g2000cwy.googlegroups.com> Message-ID: <1166220756.887305.242190@73g2000cwn.googlegroups.com> I have been modifying the code today, tracing through it and trying to make it more robust and implement data hiding. That way as someone reads through my main they will see intuitively what I am doing. For that reason I went back and added a filename parameter to OpenPort. The reason I am closing and opening the port is the same reason I posted. I thought that by opening and closing the port each time (I don't do it in the 'real' code, I could determine whether the bug lay with hardware or software, or in the USB to Serial adapter. Rob On Dec 15, 3:02 pm, hg wrote: > Rob wrote: > > Here is OpenPort > > > #################################################################### > > #### OpenPort procedure > > #################################################################### > > def OpenPort(name): > > BRate = 19200 > > Tout = 3 > > > try: > > # Initialize the port > > p = serial.Serial(name) > > # handle failures gracefully > > except SerialException: > > print "The serial port is unavailable." > > print "Disconnect your USB to Serial adapter, Then" > > print "reconnect it and try again." > > sys.exit(1) > > > p.setBaudrate(19200) > > p.setTimeout(3) #set timeout to 1.5 seconds > > > # finish opening the port and assign a file handle > > p.open() > > return p > > > On Dec 15, 1:07 pm, hg wrote: > >> Rob wrote: > >> > Hi all, > > >> > I am fairly new to python, but not programming and embedded. I am > >> > having an issue which I believe is related to the hardware, triggered > >> > by the software read I am doing in pySerial. I am sending a short > >> > message to a group of embedded boxes daisy chained via the serial port. > >> > When I send a 'global' message, all the connected units should reply > >> > with their Id and Ack in this format '0 Ack' To be certain that I > >> > didn't miss a packet, and hence a unit, I do the procedure three times, > >> > sending the message and waiting for a timeout before I run through the > >> > next iteration. Frequently I get through the first two iterations > >> > without a problem, but the third hangs up and crashes, requiring me to > >> > remove the Belkin USB to serial adapter, and then reconnect it. Here > >> > is the code: > > >> > import sys, os > >> > import serial > >> > import sret > >> > import time > > >> > from serial.serialutil import SerialException > >> > #################################################################### > >> > #### GetAck Procedure > >> > #################################################################### > >> > def GetAck(p): > >> > response = "" > > >> > try: > >> > response = p.readline() > >> > except SerialException: > >> > print ">>>>>Timed out<<<<<" > >> > return -1 > >> > res = response.split() > > >> > #look for ack in the return message > >> > reslen = len(response) > >> > if reslen > 5: > >> > if res[1] == 'Ack': > >> > return res[0] > >> > elif res[1] == 'Nak': > >> > return 0x7F > >> > else: > >> > return -1 > > >> >>>>>> Snip <<<<<< > >> > #################################################################### > >> > #### GetNumLanes Procedure > >> > #################################################################### > >> > def GetNumLanes(Lanes): > >> > print "Looking for connected units" > >> > # give a turn command and wait for responses > >> > msg = ".g t 0 336\n" > > >> > for i in range(3): > >> > port = OpenPort() > >> > time.sleep(3) > >> > print port.isOpen() > >> > print "Request #%d" % (i+1) > >> > try: > >> > port.writelines(msg) > >> > except OSError: > >> > print "Serial port failure. Power cycle units" > >> > port.close() > >> > sys.exit(1) > > >> > done = False > >> > # Run first connection check > >> > #Loop through getting responses until we get a -1 from GetAck > >> > while done == False: > >> > # lane will either be -1 (timeout), 0x7F (Nak), > >> > # or the lane number that responded with an Ack > >> > lane = GetAck(port) > >> > if lane >= '0': > >> > if False == Lanes.has_key(lane): > >> > Lanes[lane] = True > >> > else: > >> > done = True > >> > port.close() > >> > time.sleep(3) > > >> > # Report number of lanes found > >> > NumLanes = len(Lanes) > >> > if NumLanes == 1: > >> > print "\n\nFound 1 unit connected" > >> > else: > >> > print "\n\nFound %d units connected" % NumLanes > > >> > return NumLanes > > >> >>>>>>> Snip <<<<<< > >> > #################################################################### > >> > #### Main Program Code Section > >> > #################################################################### > > >> > #open the serial port > >> > # capture serial port errors from trying to open the port > > >> > port = OpenPort() > > >> > # If we got to here, the port exists. Set the baud rate and timeout > >> > values > > >> > # I need to determine how many lanes are on this chain > >> > # First send a turn command > > >> > #Create a dictionary of lanes so I can check each lane's responses > >> > Lanes = {} > >> > #<><><><><><><><><><><><><><><><> > >> > # Call the lane finder utility > >> > NumLanes = GetNumLanes(Lanes) > >> > #<><><><><><><><><><><><><><><><> > > >> > #if no lanes responded, exit from the utility > >> > if 0 == NumLanes: > >> > print "I can't find any units connected." > >> > print "Check your connections and try again" > >> > sys.exit(1) > > >> > # list the lanes we have in our dictionary > >> > for n in Lanes: > >> > print "Lane - %s" % n > > >> > Now, here is the error message that I get > > >> > dad at nb29:~/py$ ./Thex.py > >> > Looking for connected units > >> > True > >> > Request #1 > >> > True > >> > Request #2 > >> > Serial port failure. Power cycle units > >> > dad at nb29:~/py$ ./Thex.py > >> > The serial port is unavailable. > >> > Disconnect your USB to Serial adapter, Then > >> > reconnect it and try again. > >> > dad at nb29:~/py$ > > >> > Does anyone have any ideas? > > >> > Thanks, > > >> > rob < Amateur.N7... at gmail.com >Where is OpenPort ? > > >> hgI don't get it: you never pass any parameter to OpenPort > > The second thing I wonder about is whether you need to reinit serial every > time . > > hg From tim at tdw.net Sat Dec 16 10:24:59 2006 From: tim at tdw.net (Tim Williams) Date: Sat, 16 Dec 2006 15:24:59 +0000 Subject: win32 service In-Reply-To: References: Message-ID: <9afea2ac0612160724k63dfd186s81f6b7b5aee223ab@mail.gmail.com> On 16/12/06, g.franzkowiak wrote: > Hi everybody, > > have a little problem with a service on Win32. > > I use a TCP server as service, but can't access from an other machine. > Only local access is possible. > > The service starts like this: > > -> myService.py --username user --password password install <- > > followed by start > > The user is member in "Log on as service", but... only local access :-( > > What is wrong or what can I do ? > Have you checked that your firewall isn't causing the problem, and that the servers IP address is accessible from other machines to start with ? From kirk at nospam.jobsluder.net Fri Dec 15 22:50:08 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Fri, 15 Dec 2006 22:50:08 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <7xbqm4d97d.fsf@ruckus.brouhaha.com> <7xodq4mule.fsf@ruckus.brouhaha.com> Message-ID: In article <7xodq4mule.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Don't be silly. Some operators are more natural as infix and others > as functions. It's just like in natural language. People have an > innate ability to make such distinctions and it's fine for a > programming language to use it. I don't think you can really make this case. In English, German and Spanish noun-verb order is flexible to accommodate differences in mood, tense, and emphasis: "Add 2 and 2." imperative. "The sum of 2 and 2" noun phrase. "2 was added to 2." passive voice. Personally, I've always preferred use the imperative to describe basic math rather than the passive. This would seem to map better to RPN than infix. And on top of that, some languages are even more flexible in regard to word order, preferring to communicate relationships through the modification of noun stems. In such a language, "He* her- the ring+ gave," is just as valid as "Her- the ring+ gave he*" and "He* gave her- the ring+." ("+/-/*" signifying modifications which do not exist in modern English.) At any rate, I find this argument to be weak given that English doesn't always use the same word order. And English is just one language out of hundreds. From ironfroggy at gmail.com Thu Dec 7 20:11:08 2006 From: ironfroggy at gmail.com (Calvin Spealman) Date: Thu, 7 Dec 2006 20:11:08 -0500 Subject: deriving classes from object extensions In-Reply-To: <1165536738.386380.262640@l12g2000cwl.googlegroups.com> References: <1165536738.386380.262640@l12g2000cwl.googlegroups.com> Message-ID: <76fd5acf0612071711u37cf3f1fg959b768e1c8e3ae@mail.gmail.com> On 7 Dec 2006 16:12:18 -0800, manstey wrote: > Hi, > > I am using Python with Cache dbase, which provides pythonbind module, > and intersys.pythonbind.object types. But I can't create a class based > on this type: > > import intersys.pythonbind > class MyClass(intersys.pythonbind.object): > pass > > gives me the error: TypeError: Error when calling the metaclass bases > type 'intersys.pythonbind.object' is not an acceptable base type > > Can anyone expain if it is possible for me to derive my own class from > the intersys object so as to add my own functionality? > > thanks, > matthew > > -- > http://mail.python.org/mailman/listinfo/python-list > Sounds like they are following outdated APIs before the new-style classes. The builtin types have been updated to be compatible with the newstyle classes, but your example is of an extension type that does not have such treatment. It simply is not inheritable, because it is from the era where one could not derive from any builtin types. The only solution you really have to use delegation instead of inheritence. Create your class by itself, give it a reference to an instance of intersys.pythonbind.object, and have it look for expected attributes there. To be a little nicer, you could have a special __getattr__ method to look up unfound attributes on the delegation object, your intersys.pythonbind.object instance. class Delegating(object): def __init__(self, old_object): self._old_object = old_object def __getattr__(self, name): return getattr(self._old_object, name) d = Delegating(my_old_object) d.my_old_attribute -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ From howardrh at westerncom.net Wed Dec 6 18:57:57 2006 From: howardrh at westerncom.net (hrh1818) Date: 6 Dec 2006 15:57:57 -0800 Subject: Windows installer for Scientific Python for Python 2.4? References: <12nehgaak7mte4@corp.supernews.com> Message-ID: <1165449476.969662.218990@n67g2000cwd.googlegroups.com> How did you come to your conclusion? The scipy page at http://www.scipy.org/Download shows the following: "Install SciPy 0.5.1 for Python 2.4 or SciPy 0.5.1 for Python 2.3" Howard Grant Edwards wrote: > Can anybody point me to a windows installer for scientific > python that will work with Python 2.4? The Scientific python > download page only has an installer for Python 2.3. > > -- > Grant Edwards grante Yow! Yow! I like my new > at DENTIST... > visi.com From jtgalkowski at alum.mit.edu Wed Dec 27 16:22:54 2006 From: jtgalkowski at alum.mit.edu (Jan Theodore Galkowski) Date: Wed, 27 Dec 2006 16:22:54 -0500 Subject: loose methods: Smalltalk asPython Message-ID: <1167254574.29174.282179531@webmail.messagingengine.com> >Guido was opposed to modifying builtin types before Java existed. It's >similar to his opposition to dynamic syntax. Opposition or not, the language definition is there. Surely Smalltalk's OO style can be respected. Smalltalkers have been doing OO in a dynamic context longer than many. There are things to learn there. There are two things here that need to be kept straight, I think. One is the primacy of builtin types. The other is placing those builtins at the top of their own object hierarchy. Is "int", properly speaking, a descendent of "object"? No, it's the root of its own tree. Smalltalk has "int" as well, as a *subclass* of Number. It's primitive. In any case, as respectful of Mr/Dr van Rossum as I am, simply because so-and-so says something is bad and therefore it must be true is a fallacious response. -- Jan From fredrik at pythonware.com Wed Dec 13 13:54:26 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Dec 2006 19:54:26 +0100 Subject: How to manage two (different) sockets without using threads? In-Reply-To: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> References: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> Message-ID: billie wrote: > I'm succesfully managing command channel through asynchat framework, > but I'm not sure about how to manage data channel without using a > thread/subprocess. use a separate dispatcher instance for the data transfer. see the ftp_handle_pasv_response method and async_ftp_download class in this article for a start: http://effbot.org/zone/asyncore-ftp-client.htm From agriff at tin.it Thu Dec 14 08:01:09 2006 From: agriff at tin.it (Andrea Griffini) Date: Thu, 14 Dec 2006 14:01:09 +0100 Subject: Pythonic style involves lots of lightweight classes (for me) In-Reply-To: <1166080057.944449.158320@n67g2000cwd.googlegroups.com> References: <1166080057.944449.158320@n67g2000cwd.googlegroups.com> Message-ID: <458149db$0$22392$4fafbaef@reader2.news.tin.it> metaperl wrote: > .... The above program started out as a list of dictionaries, but I > like the current approach much better. There is even a common idiom for this... class Record(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) This way you can use user = Record(name="Andrea Griffini", email="agriff at tin.it") and then access the fields using user.name syntax HTH Andrea From hg at nospam.org Tue Dec 19 09:43:39 2006 From: hg at nospam.org (hg) Date: Tue, 19 Dec 2006 08:43:39 -0600 Subject: Can a Tkinter GUI check for abort script: References: Message-ID: Michael Yanowitz wrote: > Hello: > > I have successfully implemented a Tkinter GUI which has > this (simplified here for explanation): > +-------------------------------------+ > | filename: [ ./test3.py] | > | | > | [Run Script] | > +-------------------------------------+ > > But, now what I would like to do while the script is > running, is replace the "Run Script" with "Abort Script". > > +-------------------------------------+ > | filename: [ ./test3.py] | > | | > | [Abort Script] | > +-------------------------------------+ > > So, every tenth of a seconds or ??? better time, I > would like to 'return' to the GUI and check if the > "Abort Script" button has been pressed. > How do I do this? Or is there a better way to > implement this? > > Thanks in advance: > Michael Yanowitz It depends: As you cannot "kill" a thread in Python, you need some mechanism to stop your script another way (is that a python script or a .sh / .bat ? ... from what you're writing, it seems you're calling some external entity which just might launch a bunch of processes) So do you or not control the inner workings of that external script ? If you don't, then "killing" might be the way as posted / clearly the methord will change from environment to environment. hg From Benjamin.Barker at gmail.com Thu Dec 28 14:13:38 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 28 Dec 2006 11:13:38 -0800 Subject: dictionary containing instances of classes behaving oddly In-Reply-To: <4594102d$1@nntp.zianet.com> References: <1167326178.386764.300200@n51g2000cwc.googlegroups.com> <4594102d$1@nntp.zianet.com> Message-ID: <1167333218.447246.236960@h40g2000cwb.googlegroups.com> Ah - ok. In fact I simply had: class record: my_list =[] mops=[] def __init__(self,mops): self.mops=mops Where mops is something I pass in when i create the instance. I had thought that then each time I created an instance of the record class as an element of my dictionary: self.mop_list[record_number]=record(self.mops[:]) I would create a brand new instance of the record class.It would have a mops list initialized with mops (because the def__init__ constructor is called when the class is instantiated), and an empty, individual list my_list. I could then access each individual list by doing: self.mop_list[x].my_list[y]=something But in fact the same my_list is being accessed for all values of x, so a change to one list is in fact a change to them all. I think you might be right, but can't quite work it out myself! I'll keep trying :-) Thanks for your help, Ben Erik Johnson wrote: > "Ben" wrote in message > news:1167326178.386764.300200 at n51g2000cwc.googlegroups.com... > > > > > This seems to work without any errors. But bizzarely I find that > > whatever my record number, the instance of "my_class" is appended to > > every list. So in this case > > > > self.mop_list[0].my_list.append(my_class(Some data for the > > constructor)) > > > > I would expect to append an instance of my_class to > > self.mop_list[0].my_list > > > > But annoyingly > > > > self.mop_list[0].my_list > > self.mop_list[3].my_list > > self.mop_list[7].my_list > > > > all have an instance of my_class created and appended to them. This is > > really confusing and quite annoying - I don't know whether anyone out > > there can make head or tail of what I'm doing wrong? > > Well, it's a little bit difficult, but I think I actually know what's going > on. You probably need some code that looks something like this, to ensure > each object has it's own, independent list: > > class record: > def __init__(self, init_list=None): > self.my_list = [] > if init_list is not None: > self.my_list.extend(init_list) > > > Here's what I think you are doing, and below should make it clear why that > doesn't work: > > class record: > def __init__(self, init_list=[]): > > That list above, the default initializer is constructed just once (when the > def statement executes)! > > >>> class record: > ... def __init__(self, init_list=[]): > ... self.my_list = init_list > ... > >>> r1 = record() > >>> r1.my_list > [] > >>> r2 = record() > >>> r2.my_list > [] > >>> r2.my_list.append('boo!') > >>> r1.my_list > ['boo!'] > >>> > >>> l1 = range(1, 4) > >>> l1 > [1, 2, 3] > >>> r1 = record(l1) > >>> r2 = record(l1) > >>> r1.my_list > [1, 2, 3] > >>> r2.my_list > [1, 2, 3] > >>> r1.my_list.append(42) > >>> l1 > [1, 2, 3, 42] > >>> r1.my_list > [1, 2, 3, 42] > >>> r2.my_list > [1, 2, 3, 42] > >>> From pc at p-cos.net Tue Dec 12 16:16:58 2006 From: pc at p-cos.net (Pascal Costanza) Date: Tue, 12 Dec 2006 22:16:58 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7x64chuig6.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> <7xodqczf1h.fsf@ruckus.brouhaha.com> <7xk60zjl1e.fsf@ruckus.brouhaha.com> <7xk60x7wka.fsf@ruckus.brouhaha.com> <7x64chuig6.fsf@ruckus.brouhaha.com> Message-ID: <4u8kibF15vhn5U1@mid.individual.net> Paul Rubin wrote: > jayessay writes: >>> It's simply that newer language designs by definition have more of an >>> experience base to build on than older ones, if the designers care to >>> make use of it. >> Agreed. Indeed, that was the underlying guiding principle in putting >> together CL. *ML being older than CL didn't have any more opportunity >> in this respect. > > You're forgetting that CL tried to be more or less backwards > compatible with its predecessors, at least compatible enough that > large systems in Maclisp, Interlisp, Zetalisp, etc. could be ported > without too much pain. Therefore, CL could not erase too many > mistakes from the past. Scheme went somewhat further than CL at > cleaning things up, and Scheme's aficionados think CL is a clumsy old > kludge as a result. But it's still a Lisp dialect. The ML's, for > their part, were able to start from scratch. It's funny: Language designers have been spending a lot of effort over the decades on designing language constructs that help to improve the opportunities to reuse of software libraries. Yet every five years, or so, new languages and technologies come up that require everyone to start from scratch. Starting from scratch is even being applauded, due to some mythical belief that "this time, we are going to get it all right." Something seems wrong here... Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From could.net at gmail.com Tue Dec 12 20:18:17 2006 From: could.net at gmail.com (could.net at gmail.com) Date: 12 Dec 2006 17:18:17 -0800 Subject: YouTube written in Python In-Reply-To: References: Message-ID: <1165972697.387673.274570@j72g2000cwa.googlegroups.com> Really? It's awful! Terry Reedy wrote: > In a thread on the PyDev list, Guido van Rossum today wrote: > > And I just found out (after everyone else probably :-) that YouTube is > > almost entirely written in Python. (And now I can rub shoulders with > > the developers since they're all Googlers now... :-) > > In reply, Simon Brunning noted: > > That'll put to bed any "Does Python scale" discussions. From python at hope.cz Fri Dec 15 09:03:01 2006 From: python at hope.cz (Lad) Date: 15 Dec 2006 06:03:01 -0800 Subject: Large files uploading In-Reply-To: References: <1165949410.458162.38300@79g2000cws.googlegroups.com> <1166014746.923171.38110@f1g2000cwa.googlegroups.com> Message-ID: <1166191381.083383.269710@80g2000cwy.googlegroups.com> Fredrik, Thank you for your reply I need to upload large files ( about 100MB ). HTTP protocol provides FORMs for uploading which is elegant and good solution for small files but using HTTP protocol for large files is not good ( server's timeouts, big memory consumption on server's side, etc.). So,I was thinking about FTP protocol, but there may be better solutions too. (FTP server would be running on server) I am sure, it can be done this or that way in Python too. (YouTube.com is a good example) Do you have any idea how to do that? Thank you Lad, As I mentioned YouTube also uses Python , so I thi > > > But how to call the FTP API from Python? > > if you want the users to upload things using FTP, why do *you* need > to call "the FTP API" (whatever that is) from Python ? why not just > set up a server? > From sandravandale at yahoo.com Sat Dec 16 19:59:46 2006 From: sandravandale at yahoo.com (Sandra-24) Date: 16 Dec 2006 16:59:46 -0800 Subject: wxPython help please In-Reply-To: References: Message-ID: <1166317186.248833.266220@79g2000cws.googlegroups.com> Try the wxPython mailing list, which you can find on their site. And the best wxPython reference is the book (also available as an e-book) by Robin Dunn, who created wxPython. Seeing wxPython from his perspective is well worth the money. If I recall correctly he devoted an entire chapter to drawing with a canvas widget. -Sandra From danielkleinad at gmail.com Fri Dec 29 10:33:25 2006 From: danielkleinad at gmail.com (Daniel Klein) Date: Fri, 29 Dec 2006 15:33:25 GMT Subject: Some basic newbie questions... References: <1167324002.516960.319870@79g2000cws.googlegroups.com> Message-ID: <7ncap25f2b3u4dsp1i2su404lgpu7tee5d@4ax.com> On 28 Dec 2006 08:40:02 -0800, "jonathan.beckett" wrote: >Hi all, > >Question 2... >What is the correct way of looping through a list object in a class via >a method of it? Without peeking at any of the other responses, here is what I came up with. I hope it helps... class Gun(object): def __init__(self, shells = 10): self.shells = shells class Battleship(object): def __init__(self, shipname = '', guns = []): self.shipname = shipname self.guns = guns def getShellsLeft(self): numShells = 0 for gun in self.guns: numShells += gun.shells return numShells if __name__ == '__main__': aShip = Battleship(shipname = "Bizmark", guns = [Gun(), Gun(6)]) print "%s has %d shells left." \ % (aShip.shipname, aShip.getShellsLeft()) Dan From m_tayseer82 at yahoo.com Mon Dec 18 11:28:24 2006 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Mon, 18 Dec 2006 08:28:24 -0800 (PST) Subject: Can a Tkinter GUI check for abort script: In-Reply-To: <006901c722be$04c74f90$0d7d12ac@kearfott.com> Message-ID: <20061218162824.574.qmail@web31106.mail.mud.yahoo.com> I don't know why this happen. do you call mainloop() inside the test3.py?? you shouldn't Michael Yanowitz wrote: > Presently what happens is that the script takes over and all the buttons on > the GUI disappear > as the GUI is not given any cpu time to refresh or check if any activity in > the dialog. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From eadmund42 at NOSPAMgmail.com Wed Dec 13 13:51:44 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Wed, 13 Dec 2006 11:51:44 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> <87lklcrt00.fsf@thalassa.informatimago.com> <457fdb92$0$13245$426a74cc@news.free.fr> Message-ID: Christophe writes: > > Saying that the French units are technically worse than standard units > is a troll of very poor quality and a very weak argument. It was just an example that the argument from popularity is invalid. However, I (and many others) would argue that optimisation for unit conversion is the wrong choice when designing a system of measures. But this is not the venue for such a discussion, so I'll stop now:-) -- Robert Uhl ...It [the Mexican dictatorship] has demanded us to deliver up our arms, which are essential for our defence, the rightful property of freemen, and formidable only to tyrannical governments... --Texas Declaration of Independence From rNOSPAMon at flownet.com Fri Dec 1 02:44:52 2006 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 30 Nov 2006 23:44:52 -0800 Subject: Is there a reason not to do this? References: Message-ID: In article , Ron Garret wrote: > In article , > "Hendrik van Rooyen" wrote: > > > "Ron Garret" wrote: > > > > > > > > > > One of the things I find annoying about Python is that when you make a > > > change to a method definition that change is not reflected in existing > > > instances of a class (because you're really defining a new class when > > > you reload a class definition, not actually redefining it). So I came > > > up with this programming style: > > > > I would have thought that not changing yesterday was the very essence of > > dynamism (dynamicness ??) - but that when you change something - it applies > > from that point in time forwards... > > I don't want to get into a philosophical debate. Actually, I changed my mind. Consider: def g(): print 'G' def h(): print 'H' def f(): g() class C1: def m1(self): f() class C2: def m1(self): g() c1 = C1() c2 = C2() def f(): h() class C2: def m1(self): h() c1.m1() # Prints H c2.m1() # Prints G On what principled basis can you justify two different outputs in this case? Why should I be able to change the definition of f and not have to go back and recompile all references to it, but not m1? rg From kentilton at gmail.com Sat Dec 9 11:55:23 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 11:55:23 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> Message-ID: <%TBeh.331$tv5.155@newsfe11.lga> Steven D'Aprano wrote: > On Sat, 09 Dec 2006 02:29:56 -0500, Ken Tilton wrote: > > >> >>David Lees wrote: > > >>Those raving about >>Lisp are quite accomplished at all those other languages, and know about >> what they are talking. > > > Such a sweeping generalization. Every person who raves about Lisp is also > accomplished with other languages. Yeah, right. I believe you, even if > millions wouldn't. Ah, but that is because you are not a careful thinker, you just like sounding off on Usenet. Me, too! Think, Steve, think: do you think we pay the rent with /Lisp/ jobs?! If logic does not work for you, try this: http://wiki.alu.org/RtL_Highlight_Film Behind each sound bite is a full survey response, one question being "what other languages do you use?". >>I doubt the Pythonistas weighing in on this >>thread ever got far at all with Lisp, so... should they really be >>offering comparative analysis? > > > I hit my hand with a hammer once. Cool, first you use the lame Turing Completeness thing, now you are arguing by analogy, which does not work because now we have to argue about how well the analogue maps onto the topic. When I switched Lisps after several years of Lisp I also had to switch IDEs (not using Emacs+ILisp). I hated the new IDE. I also told myself to wait thirty days before worrying about it, since obviously it might just be a matter of habit. Now when I port things back to the first Lisp I hate that IDE (except I know a couple of weeks would turn it around). Now it may be distressing to you that I am talking about something closer to programming languages than is hammering ones hand, and for that I apologize in advance. :) I didn't keep going until I was an > expert in hitting-own-hand-with-hammer before deciding that hitting my > hand with a hammer was not for me. Did I do the wrong thing? Should I have > kept going until I was an expect at it? > > (Of course, writing Lisp isn't precisely like hitting one's hand with a > hammer. With the hammer, the endorphins kick in eventually, and it can > become quite pleasant...) > > > >>> Personally, I never like Lisp syntax; >>>Clearly some people, some fanatic judging by this thread :) think easily >>>in prefix. I am not one of them. >> >>Yeah, you are, you just did not use it heads down for a month. > > > The sheer arrogance of this claim is astounding. > > Actually, this is comp.lang.lisp. It isn't astounding at all. Exactly, and Usenet. Not the Supreme Court. We can speak casually. We can also speak cordially. > > I don't know, maybe lisp coders actually are more intelligent than > ordinary mortals, No, it's the Lisp that makes them so effective. I was joking in my original remark. But not about Lisp programmers being better looking. :) > but it has been my experience that they have absolutely > no grasp whatsoever of the way most (many? some?) people think. And I'm > not talking about can't-walk-and-think-at-the-same-time people either, I'm > talking about bright, intelligent people who, nevertheless, don't agree > with lisp coders. As you will soon realize because you are such an open, intellectually-honest person and will do the reading I recommended, most of us came to Lisp late in our programming careers, having used and excelled at (in my case) Apple Integer Basic, Microsoft Basic, 6502 Assembler, COBOL, any DEC Basics, C, Logo, and now Lisp (chosen over the new C++ because the latter seemed like evry bit the horror it turned out to be). I have done enough Python to appreciate the cleanliness of the code and its power, and enough Java... well, after Lisp it is impossible to find anything in some other language that would tempt one to work much in it. My point is that we grasp what you think because we /are/ you, we have worked alongside you, and we are very good at your language. And we use Lisp and gloat about it and piss everyone off with our smugness. It can't be helped--Lisp is that good. >>The way >>to tell if you spent enough time on Lisp is to look at Lisp code. If you >>see any parentheses, you have not spent enough time. They disappear in a >>month. > > > If the parentheses are that meaningless, why do you need them? Meaningless? Who said that? Did you say that? Someone said that. :) I said they disappear. I am not looking at parens, I am looking at the code structure, as manifested by (you'll like this) the indentation, the indentation provided automatically when I kerplunk control-shift-P (I think, my fingers know). You like analogies. When i tried on my first glasses I said "I can see the frames!". the glasses guy said, "That is because you are looking for them." Something like that. With the editor handling the parens 90% of the time, I do not have to thnk about or look for them. btw, change all the ()s to []s and I /do/ see them. Possibly they would go away with time, but I have a hunch that []s might not go away, two cornery or something. > > > >>The typical Pythonista values clean code but trembles in the face of >>macros, which exist to hide boilerplate. > > > Funny, when I write code, I try to remove boilerplate, not hide it. Boilerplate does not mean meaningless. You cannot remove it. It is absolutely necessary. But it has blanks that must be filled in differently for each use of the boilerplate. With macros, one supplies just the fill-ins and the name of the boilerplate, but in a way a function cannot handle. The last time we went thru this a Pythonista finally said, Oh, I get it. These five lines of code I have to write all the time (two setup, one func call, two cleanup) can be collapsed into one or two. The thread will be hard to miss in Google groups (two years back?) and the epiphany appears right at the end of the thread. >>That means the only thing >>showing in any given block of code is exactly the interesting variable >>and function names. Talk about readability. > > > Yes. And your point is? You would love macros if Python had them. >>>Computer languages are tools and >>>everyone should pick the ones that they are most comfortable and >>>productive with. >> >>No, languages are not interchangeable. > > > Perhaps you should consider what the term "Turing complete" implies. I have destroyed this elsewhere, but in case you missed it: HLLs exist precisely to distance us from having to program Turing machines directly, and are to be judged precisely on how well they do that, so this fig leaf offers no cover. > > > >>Python is a fine language, but >>Lisp is much more expressive/powerful. > > > Maybe so. A bulldozer is a lot more powerful than a tack-hammer, but if > somebody suggested using a bulldozer to lay carpet, I'd politely show them > to the door. Sometimes more power isn't better. I thought we agreed that analogies are useless because they become their own debate? :) Again, power means maximizing the ratio between how much time am I thinking about the problem I am trying to express and how much time am I thnking about your beloved Turing machine. Not sure how I would say that in infix. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From antroy at gmail.com Tue Dec 5 03:29:51 2006 From: antroy at gmail.com (Ant) Date: 5 Dec 2006 00:29:51 -0800 Subject: Printing unix Line endings from Windows. In-Reply-To: References: <1165247935.679325.242850@80g2000cwy.googlegroups.com> Message-ID: <1165307391.447055.210020@n67g2000cwd.googlegroups.com> Larry Bates wrote: > Ant wrote: ... > > Is there any way of doing this without having to post-process the file > > in binary mode (a-la the crlf.py script) ... > You can write to a new file and create your own line endings. > When done, delete the original file and rename the output file. How can I create my own line endings? I've tried setting os.linesep = "\n", (and to \x0a). I've tried things like: print "xxx yyy \n", print "xxx uuu \x0a", filehandle.write("xxx \n") filehandle.write("xxx \x0a") and all of these give me a nice windows-style crlf! Surely there must be a way to do this ... From robert.kern at gmail.com Mon Dec 4 00:30:53 2006 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 03 Dec 2006 23:30:53 -0600 Subject: problem formatting dates from text fields. In-Reply-To: References: <6eHch.7012$1s6.5812@newsread2.news.pas.earthlink.net> Message-ID: krishnakant Mane wrote: > is there a soft copy of wxpython in action available for free download? > I saw the book on my book store but since I am totally blind, I have > to depend on soft copies. It is not available for free, no. However, it is available in PDF form from Manning's website: http://www.manning.com/rappin/ If their Yahoo store is not accessible via your web reader (I have no experience, so I won't depend on it), you can email the publisher's customer service at support at manning.com and I'm sure they will get the book to you in a form you can read. -- 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 From bj_666 at gmx.net Sun Dec 24 04:45:44 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sun, 24 Dec 2006 10:45:44 +0100 Subject: some OT: how to solve this kind of problem in our program? References: Message-ID: In , oyster wrote: > 1. first of all, what is the English jargon (Optimize? But I think > this is not a very good keyword :( )for this problem? So I can use it > to search on the internet > 2. is there any free/open lib for this? > 3. I know for some questions(case 1, case 2, and sudoku), we can use > bundles of "FOR...NEXT" loop to program. however I think it is clumsy > and inconvenient, especially when there is many vars > 4. I don't know how to deal with case 3 and case 4 > > > case: > 1. choose x0~x9 from 1~9, and must use all of 1~9, let > x0/(10*x1+x2)+x3/(10*x4+x5)+x6/(10*x7+x8)=1/2 > > 2. choose x0~x15 from 1~16, and must use all of 1~16, let > +-----+-----+-----+-----+ > | x0 | x1 | x2 | x3 | > +-----+-----+-----+-----+ > | x4 | x5 | x6 | x7 | > +-----+-----+-----+-----+ > | x8 | x9 | x10 | x11 | > +-----+-----+-----+-----+ > | x12 | x13 | x14 | x15 | > +-----+-----+-----+-----+ > > sum of every column =sum of of every row > = x0+x5+x10+x11 =x3+x6+x9+x12 The first two can be solved by a finite domain constraint solver. Logilab has a pure-python package: http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20852 Ciao, Marc 'BlackJack' Rintsch From nmm1 at cus.cam.ac.uk Tue Dec 19 10:55:00 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 19 Dec 2006 15:55:00 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> In article , "J. Clifford Dyer" writes: |> |> How about: "A heterogenous sequence is one in which each element plays a |> unique role, specific to its position in the sequence. A homogenous |> sequence is one in which position is determinative of nothing |> significant other than (perhaps) order." Nope. Sorry. Consider the old model where an I/O list is an ordered sequence of strings and agents (effectively procedure calls), with no constraints on how those are ordered. With your specification, that is neither heterogenous nor homogenous :-) |> I doubt the python interpreter will ever try to enforce |> homogeneity/heterogeneity on lists/tuples, in part because there no good |> ways of definining it syntactically, and in part because there are |> certainly good reasons for breaking the rules. As someone said: passing |> lists to untrustworthy functions. And as someone else said, *args |> passes a tuple, even though it is frequently just a homogenous list of |> more arguments. It's a complete delusion, because even the claimed assumption of list homogeneity is tantmount to saying that Python doesn't encourage (or, arguably, support) ANY way of using mutable heterogenous sequences (such as the example above). To claim that they are inherently an undesirable programming practice is a clear descent into religion! I would be amused to know what Python type the "lists are intended to be homogenous" people use to implement mutable heterogenous sequences, or whether they claim that wanting such a feature is heresy :-) Regards, Nick Maclaren. From Holger.Joukl at LBBW.de Wed Dec 13 05:16:09 2006 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Wed, 13 Dec 2006 11:16:09 +0100 Subject: inconvenient unicode conversion of non-string arguments In-Reply-To: <1166004150.866538.299670@j72g2000cwa.googlegroups.com> Message-ID: python-list-bounces+holger.joukl=lbbw.de at python.org schrieb am 13.12.2006 11:02:30: > > Holger Joukl wrote: > > Hi there, > > > > I consider the behaviour of unicode() inconvenient wrt to conversion of > > non-string > > arguments. > > While you can do: > > > > >>> unicode(17.3) > > u'17.3' > > > > you cannot do: > > > > >>> unicode(17.3, 'ISO-8859-1', 'replace') > > Traceback (most recent call last): > > File "", line 1, in ? > > TypeError: coercing to Unicode: need string or buffer, float found > > >>> > > [...] > > Any reason why unicode() with a non-string argument should not allow the > > encoding and errors arguments? > > There is reason: encoding is a property of bytes, it is not applicable > to other objects. Ok, but I still don't see why these arguments shouldn't simply be silently ignored for non-string arguments. > > Or some good solution to work around my problem? > > Do not put undecoded bytes in a mixed-type argument list. A rule of > thumb working with unicode: decode as soon as possible, encode as late > as possible. It's not always that easy when you deal with a tree data structure with the tree elements containing different data types and your user may decide to output root.element.subelement.whateverData. I have the problems in a logging mechanism, and it would vanish if unicode(, encoding, errors) would work and just ignore the obsolete arguments. Best regards, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From kirk at nospam.jobsluder.net Sat Dec 9 22:37:26 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sun, 10 Dec 2006 03:37:26 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: In article , Steven D'Aprano wrote: > On Sat, 09 Dec 2006 21:55:19 +0000, Kirk Sluder wrote: > > Who says they do? All forms of abstraction have been criticized. Sometimes > the criticism is valid. Sometimes it warns against abuses of the > abstraction. Just because a feature is useful sometimes doesn't > necessarily mean the benefit outweighs the cost. The primary focus of the criticism in this discussion has been that macros are a bad from of abstraction compared to libraries, (and I'm admittedly extending that to objects, functions and classes.) > But at least you know that foolib is a module or package. You know what > from and import do, and that can't change. And you know that bar is an > object with a method also called bar, it is being called, and the > argument is a string "somefile". Those things can't change. Imagine a > hypothetical language where those two lines could mean *anything*. But as was pointed out earlier in the thread, those keywords can be overshadowed by custom functions in python as well. The only reason that we don't assume those two python lines could mean *anything* is because those mechanisms are not well advertised, and most people don't have a need to shadow "import." Of course, it is possible to abstract away all of the lisp in such a way that you have a completely new programming language. But is this really a problem? Perl5 and bash are abstractions of C. Python has been implemented on both C and java, and chunks of perl6 have been implemented on top of Haskell. Completely new programming languages and frameworks develop their own base of knowledge and expertise separate from the parent language. > My point isn't whether or not their claims are correct (a "couple" of > macros? really?) but that things like this feed the perception that Lisp > is close to that hypothetical language where anything could be anything. > If anything could be anything, do you really know what (+ 1 2) means > without reading every line of code? How do you know that operator has not been shadowed or overloaded in python? In most cases what you have to do is trust both the underlying implementation, and the author(s) of the libraries you use. Both python and lisp share mechanisms to protect namespaces is part of the answer. So one way to protect myself is to run my code in it's own namespace, and require explicit addressing of imported functions and constructs. In this way I can be pretty certain that (+ 1 2) uses the lisp primitives, and has not been shadowed, while (SOMEPACKAGE:+ 1 2) should be treated with suspicion. The process of writing lisp often involves access to the REPL, so I can have lisp expand the definition of any expression: CL-USER> (macroexpand '(+ 1 2)) (+ 1 2) NIL CL-USER> (macroexpand '(loop for i upto 100 collect i)) (BLOCK NIL ...... ) T CL-USER> This tells me that + is not a macro in my current environment. While loop is. And at least one of the powerful aspects of lisp is than since lisp programs are nested stets of s-expressions, you can design something that walks through the code and highlights all macro calls, and foreign functions that shadow native functions. I don't how difficult this would be for languages such as python. ... extended argument snipped ... > Or maybe it is only an advantage while Lisp programmers are a > self-selected group of above-average skill. Wait until fifty million VB > code monkeys start writing Lisp macros and maybe, just maybe, you'll wish > they were using a less powerful and more restrictive language. Perhaps it's because I'm a social scientist and not a programmer by training, but I find many arguments for *technical* solutions to *human performance* problems to be rather weak as a general practice. In some cases, using a very restrictive language may be the best solution for the problem. However, there are plenty of other ways around the problem that can be tailored to special needs. In addition to sandboxing macros into packages and walking the code to detect macros, you could run a custom lisp image that does not permit DEFMACRO or enforces documentation on DEFMACRO. Or you could rely on social mechanisms like only using libraries from trusted sources, and better training of those code monkeys. From kentilton at gmail.com Sun Dec 10 09:20:51 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sun, 10 Dec 2006 09:20:51 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <7xejr8r86m.fsf@ruckus.brouhaha.com> Message-ID: <7JUeh.187$z_7.105@newsfe08.lga> Steven D'Aprano wrote: > On Sun, 10 Dec 2006 02:00:02 -0500, Ken Tilton wrote: > > > >>Steven D'Aprano wrote: >> >>>On Sat, 09 Dec 2006 22:41:12 -0500, Ken Tilton wrote: >>> >>> >>> >>>>>I know that. It was more of a rhetorical question -- Lispers are either >>>>>trying to emphasis the radical nature of what you can do with macros, or >>>>>understate it and make them seem just like functions. >>>> >>>>Yep, both. The first is rare. CLOS is one, my Cells (ported this summer >>>>to PyCells as part of SoC 2006) is another. The latter is the norm. >>> >>> >>>If macros' advanced usage is rare, >> >>Hunh? I have tons of them. Of coure at your level of discourse you will >>want to know if those are metric tons or... > > > Stop playing games Ken. You said they were rare. Not me. You. The fact > that you personally make lots of use of the more radical macros doesn't > come into it. As you said, the norm across the wider Lisp community is the > less radical macro, the ones that are basically just functions. > > That's what you said -- or are you changing your mind? No, I simply misapprehended what you wrote, though it was perfectly clear. You wrote: > If macros' advanced usage is rare, and most usage of macros could be done > by functions, then maybe that explains why so many coders don't miss them. Maybe my brain misfired because there is so much wrong with that. The meta-wrong is that clearly you do not understand macros or how they play out in real applications, but you have climbed up on this soapbox as if you were an expert on both issues. Like your interview, you are speculating without basis on what might happen. You do have a good excuse since GvR does the same. Here you have a chance to talk with people who program with macros day in and day out and learn about them, instead you are trying to tell us how they are used. Does that make a lot of sense? Or do you think we are lying? :) Language-transforming macros such as defclass/defmethod (the heart of CLOS) and my defmodel come along rarely. This does not mean my applications do not /use/ CLOS extensively. They do. It means I do not have ten such different language extensions. I have three: defclass, defmodel, and LOOP. Can you understand that difference? "Used everywhere because they are so cool" and "just a few such cool tools exist" are not contradictory. Does rare mean "who needs it"? Nice try, but obviously not. Well, maybe not obviously, because not everyone likes OO, but I would not want to program without defclass or defmodel or even LOOP. The latter is such a powerful iteration tool it justifies learning the new syntax, which is also not a problem because I use it all day making it is easy to remember. (Aside: I /did/ resist learning it for years because of the different syntax--my loss.) Recall that this subwar started over someone saying Lisp was able to "grow" CLOS without changing and have it look like part of the language, which led you and others to echo GvR and pronounce macros to be obfuscatory (?). Sorry, no, not in fact. Only in your nightmares. As for simple macros not being necessary, what they do is clean up the code, letting the beef stand out more. Obviously people with that interest do not turn around and create obfuscated code, no matter how many times you want to FUD that (which seems to be quite a lot ). ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From laurent.pointal at limsi.fr Fri Dec 1 04:21:26 2006 From: laurent.pointal at limsi.fr (Laurent Pointal) Date: Fri, 01 Dec 2006 10:21:26 +0100 Subject: Ruby/Python/REXX as a MUCK scripting language In-Reply-To: References: <2006112418112116807-zobeid@techiecom> <4sr3neF111j0gU1@mid.individual.net> Message-ID: Cameron Laird a ?crit : > In article , > Laurent Pointal wrote: >> Fred Bayer a ?crit : >>> Tony Belding wrote: >>>> I'm interested in using an off-the-shelf interpreted language as a >>>> user-accessible scripting language for a MUCK. I'm just not sure if I > . > . > . >>>> there's the security issue that really worries me. . . I have to be >>>> able to limit what the interpreter can execute. I can't have my users >>>> running scripts that access the console, access the filesystem or >>>> sockets directly, or call libraries or other binaries outside the MUCK. >>>> >>>> Is this practical? I'm thinking of Ruby or Python for this, if they >>>> can meet the requirements. >>>> >>> Don't forget Lua: www.lua.org >>> It fulfills your requirements and is easily embedable. >>> >> I Agree with F.Bayer, when reading OP post, I immediatly think about Lua. > > Does Lua have an appropriate security model--a sandbox or such? > Fond though I am of Lua, such would be news to me. I dont think of a security model like in Java, but in the possibility to limit the accessible libraries for interpreted code. http://www.lua.org/manual/5.1/manual.html#5 If OP just need some computation logic, he could limit external world communication libraries (these libraries must be loaded by the C host program before being usable by scripts). Need to look more precisely to the minimum library set to load and to available functions in this set. Maybe it is possible to remove some undesired functions from Lua symbol tables just after loading libraries. [note: I have still not used Lua, but I look at it for futur use in a current development where an embedded Python would be too heavy and make problems relative to the GIL - but I'm still a Python fan in other use cases] A+ Laurent. From cjw at sympatico.ca Sat Dec 23 11:18:50 2006 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 23 Dec 2006 11:18:50 -0500 Subject: let me simplify my question on scope of vars In-Reply-To: <877iwjcttj.fsf@pyenos.pyenos.org> References: <877iwjcttj.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > "code" > var=1 > class CLASS: > def METHOD1: > def METHOD2: > var+=var > return var > METHOD2() #line8 > return var > METHOD1() #line10 > "end code" > > Q1: does class CLASS inherit var=0 from line1? > Q2: does def METHOD1 inherit var=0 from line1? > Q3: does def METHOD2 inherit var=0 from line1? > Q3: does line8 return '2'? > Q4: does line10 return '2\n2'? Some print statements could verify, but my guess for your quiz are: A1: Yes A2: Yes A3: Yes A4: It should return 1, Method 2 is never called. I've modified you code a little, so that you can experiment with print statements. Colin W. # Pyenos wrote: "code" var=1 print id(var) class CLASS: def METHOD1(self): def METHOD2(): var+=var print id(var) return var METHOD2() #line8 return var c= CLASS() print c.METHOD1() #line10 "end code" From timr at probo.com Mon Dec 4 23:31:58 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 05 Dec 2006 04:31:58 GMT Subject: Video feature References: <1165048406.302509.122060@16g2000cwy.googlegroups.com> <1ot4n2dmkflrci1bus94vovpsoisbd1m64@4ax.com> <1165211862.716073.175940@f1g2000cwa.googlegroups.com> Message-ID: <2gt9n25ka2tvtpgtknoe6kn2unbfdebvru@4ax.com> "Lad" wrote: > >Hello Tim, >Thank you for your reply. >Yes, my site uses Python. >Do you have any idea how to add video playing ( video streaming >feature)to my webiste? That's not the hard part. You can use an or tag to play a movie as part of a web site. Google is your friend. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rampeters at gmail.com Wed Dec 6 11:54:37 2006 From: rampeters at gmail.com (johnny) Date: 6 Dec 2006 08:54:37 -0800 Subject: PHP calls python: process vs threads Message-ID: <1165424077.586240.122930@n67g2000cwd.googlegroups.com> What I want to do is the following: Web user uploads a word doc, and I need it to move the uploaded word doc, on to another machine and conver it to pdf. Then update the database and allow immediate pdf download. I am thinking of using ftp from machine 1 -> machine 2, then convert doc to pdf on machine 2, using process or thread. What is the best way to go about doing this, process or threads or pyro? Pdf is created by calling commands on the command line, through python script. Thank you in advance. John From fredrik at pythonware.com Wed Dec 13 10:28:39 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Dec 2006 16:28:39 +0100 Subject: Large files uploading In-Reply-To: <1166014746.923171.38110@f1g2000cwa.googlegroups.com> References: <1165949410.458162.38300@79g2000cws.googlegroups.com> <1166014746.923171.38110@f1g2000cwa.googlegroups.com> Message-ID: Lad wrote: >> to use any communications protocol (including HTTP), both ends must have >> programs that can talk that protocol... >> > Sure, but browsers have FTP support. ftp upload support ? > But how to call the FTP API from Python? if you want the users to upload things using FTP, why do *you* need to call "the FTP API" (whatever that is) from Python ? why not just set up a server? From Benjamin.Barker at gmail.com Fri Dec 29 06:37:56 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 03:37:56 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167391384.797523.37150@i12g2000cwa.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <1167391384.797523.37150@i12g2000cwa.googlegroups.com> Message-ID: <1167392276.165934.107040@48g2000cwx.googlegroups.com> Ben wrote: > Well that's odd... > > If I place the exact same Insert statement elswhere in the program it > works as intended. > That would suggest it is never being run in its old position, but the > statements either side of it are printing... > > > Ben wrote: > > I don't know whether anyone can help, but I have an odd problem. I have > > a PSP (Spyce) script that makes many calls to populate a database. They > > all work without any problem except for one statement. > > > > I first connect to the database... > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > self.cursor = self.con.cursor() > > self.cursor.execute("SET max_error_count=0") > > > > All the neccesary tables are created... > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > self.cursor.execute("USE "+name) > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > varchar(20)) > > > > Then I execute many insert statements in various different loops on > > various tables, all of which are fine, and result in multiple table > > entries. The following one is executed many times also. and seems > > identical to the rest. The print statements output to the browser > > window, and appear repeatedly, so the query must be being called > > repeatedly also: > > > > print "

SQL query executing

" > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > ','c','2','e','f','g')") > > print "

SQL query executed

" > > > > I have, for debugging, set "i" up as a counter variable. > > > > No errors are given, but the only entry to appear in the final database > > is that from the final execution of the INSERT statement (the last > > value of i) > > > > I suspect that this is to vague for anyone to be able to help, but if > > anyone has any ideas I'd be really grateful :-) > > > > It occured to me that if I could access the mysql query log that might > > help, but I was unsure how to enable logging for MysQL with python. > > > > Cheers, > > > > Ben Well, it would appear to be some kind of autocommit problem. I had autocommit off, bus committed when I disconnected from the database. For some reason although all the other statements seemed ok, multiple statements in that loop were'nt every commiting. For the moment I've turned autocommit on and that has sorted things out, but it slows things down too so I'll try to fix it :-) Ben From address.good.until.2006.dec.22 at justmail.de Fri Dec 15 16:06:31 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Fri, 15 Dec 2006 22:06:31 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1166215871.110268.131890@j72g2000cwa.googlegroups.com> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <1166207152.706475.76020@t46g2000cwa.googlegroups.com> <1166215871.110268.131890@j72g2000cwa.googlegroups.com> Message-ID: William James schrieb: > Andr? Thieme wrote: >> William James schrieb: >> >>> def nif num, pos, zero, neg >>> send( num>0 ? pos : (num==0 ? zero : neg) ) >>> end >> btw, your nif body is built out of 13 tokens, so more >> complicated than the Python version. >> >> >> Andr? >> -- > > def nif num, *args > send args[ 1 + (0 <=> num) ] > end send | | [ ] / \ / \ / \ args + / \ / \ 1 () | | <=> / \ / \ 0 num Okay, 9. Now it is at the complexity level of the Lisp and Python example. But how would a call to nif look like? I hope it doesn't involve an extra operator to group the args into a list or tuple. That would add more complexity to each call - so one should better have a slightly more complex nif because that exists only one time. And can this nif now handle any input values, such as strings or function objects? The <=> is called cmp in Python. In Lisp it is called signum. The Lisp function has in general the advantage that it keeps type information. While Pythons cmp returns either -1, 0 or 1 the Lisp version can also return -1.0 and 1.0 and also complex numbers: (signum #C(10 4)) => #C(0.9284767 0.37139067) Andr? -- From fredrik at pythonware.com Sun Dec 17 07:00:05 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Dec 2006 13:00:05 +0100 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: dyork wrote: > Most values tend to work, but only because the SQL string representation > happens to be the same as the Python representation. That may not apply to > some float values, bool, perhaps others. I had hoped the tools would have > solved those problems so I don't have to. In typed languages (Java, C#) > those things tend to just work. if you think that Python isn't typed, you've completely missed how things work. your problem is that you're removing every trace of the type information by casting everything to strings, not that Python itself (nor the database adapters) cannot handle typed data. From martin.witte at gmail.com Fri Dec 29 11:53:53 2006 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 29 Dec 2006 08:53:53 -0800 Subject: I want to see all the variables In-Reply-To: References: <1167407850.869640.34780@a3g2000cwd.googlegroups.com> Message-ID: <1167411233.319435.12550@48g2000cwx.googlegroups.com> On Dec 29, 5:17 pm, Steven D'Aprano wrote: > On Fri, 29 Dec 2006 07:57:30 -0800, witte... at hotmail.com wrote: > > What do you mean? Can you specify which special functions you don't > > see? > > I get: > > py> class X: > > pass > > py> dir(X) > > ['__doc__', '__module__']How about these? > > >>> X.__dict__{'__module__': '__main__', '__doc__': None}>>> X.__name__ > 'X' > >>> X.__bases__() > > Now that's interesting... if __name__ and __bases__ don't live in the > class __dict__, where do they live? What other methods and attributes are > invisibly in X? > > -- > Steven. Well, then we have to lookup what dir() does -- http://docs.python.org/lib/built-in-funcs.html -- it tries to bring up the interesting attributes of an object, apparently __name__ and __bases__ are considered to be not so interesting.... From Ingo.Wolf at gmx.de Thu Dec 14 08:06:19 2006 From: Ingo.Wolf at gmx.de (iwl) Date: 14 Dec 2006 05:06:19 -0800 Subject: PyThreadState_SetAsyncExc (nThreadId ??????, exc); Message-ID: <1166101579.075399.63890@n67g2000cwd.googlegroups.com> what is the nThreadId-Parameter of PyThreadState_SetAsyncExc? I try to implement a Terminate-Button in my C-Prog for my embedded Python, but its hard to find an example how to stop an interpreter running in an thread. I found no other Python C-App-Func returning such a parameter. From rtw at freenet.co.uk Sun Dec 17 13:56:16 2006 From: rtw at freenet.co.uk (Rob Williscroft) Date: Sun, 17 Dec 2006 12:56:16 -0600 Subject: first and last index as in matlab References: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> Message-ID: Evan wrote in news:1166379931.054933.77450 at j72g2000cwa.googlegroups.com in comp.lang.python: > In matlab I can do the following: > >>> ind = [3,5,7,2,4,7,8,24] > ind = 3 5 7 2 4 7 8 24 >>> ind(1) ans = 3 >>> ind(end) ans = 24 >>> ind([1 end]) ans = 3 24 > > but I can't get the last line in python: > > In [690]: ind = [3,5,7,2,4,7,8,24] > In [691]: ind[0] Out[691]: 3 > In [692]: ind[-1:] Out[692]: [24] > In [693]: ?? > > How do I pull out multiple indices as in matlab? [ind[0], ind[-1]] or if you need something that can be generalised: [ind[i] for i in [0, -1]] so if you have: indexes_of_ind = [0, 2, -1, -2] you can write: [ind[i] for i in indexes_of_ind] Rob. -- http://www.victim-prime.dsl.pipex.com/ From raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com Wed Dec 13 02:41:29 2006 From: raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com (Raffael Cavallaro) Date: Wed, 13 Dec 2006 02:41:29 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> <1165969090.648421.177130@16g2000cwy.googlegroups.com> Message-ID: <2006121302412950073-raffaelcavallaro@pasdespamsilvousplaitmaccom> On 2006-12-12 19:18:10 -0500, "George Sakkis" said: > If you mistakenly select an extra parenthesis or omit one, it's > the same thing. Because you can't mistakenly select an extra paren or omit one in a lisp-aware editor. Whether its a commercial lisp IDE or emacs, you don't manually select s-expressions. You put your cursor/point at one paren and you tell the editor - with a keystroke or a mouse click - to find the matching paren and select everything contained between the two. From mail at microcorp.co.za Sat Dec 9 01:48:47 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 9 Dec 2006 08:48:47 +0200 Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net><17783.32458.730462.8403@montanaro.dyndns.org><024f01c719d3$deff0fc0$03000080@hendrik> <17784.7961.898760.712605@montanaro.dyndns.org> Message-ID: <008501c71b5e$148e62e0$03000080@hendrik> "Roel Schroeven" wrote: > Hendrik van Rooyen schreef: > > wrote: > > > >> Hendrik> - as long as it works, and is fast enough, its not broken, so > >> Hendrik> don't fix it... > >> > >> That's the rub. It wasn't fast enough. I only realized that had been a > >> problem once I fixed it though. > > > > LOL - this is kind of weird - it was working, nobody complained, you fiddled > > with it to make it faster, (just because you could, not because you had to, or > > were asked to), it became faster, and then, suddenly, retrospectively, > > it became a problem ???? > > > > Would it have been no problem if it so happened that you were unable to make it > > go faster? > > > > I don't really follow that logic - but then I have never believed that I could > > change yesterday... > > Have you never experienced the following: > > A customer reports a bug. Upon investaging you find the source of the > problem, but from studying the code you don't understand anymore how it > has ever been able to function correctly. From that moment, it indeed > stops working even on computers where it always have worked correctly. > > You fix the bug and all is well again. > > Very strange, but it has happened to me on a few occasions. There's > probably a perfectly logical explanation for what happened, but I never > found it. > This is simply a manifestation of the faith that can move mountains - while everybody believed that it was working, it did, and stopped working only because of the heretical doubt of some infidel... :-) - Hendrik From gert.cuykens at gmail.com Tue Dec 19 15:43:42 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Tue, 19 Dec 2006 21:43:42 +0100 Subject: Http server Message-ID: so far this works import cherrypy import os.path class Http: def index(self): f = open(os.path.join(os.path.dirname(__file__), '../htm/index.htm')) xml = f.read() f.close() return xml index.exposed = True cherrypy.tree.mount(Http()) if __name__ == '__main__': cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'server.conf')) cherrypy.server.quickstart() cherrypy.engine.start() I would like a cute secretary for Christmas but i dont think i will get one. So i need to find a way to scan a directory. And map all files inside the directory and generate a class member like def filename(self): f = open(os.path.join(os.path.dirname(__file__), '../htm/filename')) xml = f.read() f.close() return xml filename.exposed = True Any idea or cute secretary maybe ? From stever at cruzio.com Wed Dec 6 18:14:51 2006 From: stever at cruzio.com (Steve) Date: 6 Dec 2006 15:14:51 -0800 Subject: SOAPpy - Getting info about the __init__ method Message-ID: <1165446891.692810.327010@l12g2000cwl.googlegroups.com> Hi All, I have a Python script that uses SOAPpy and I'm outputting all of the methods and info about the parameters... I'm having trouble getting information out of the __init__ parameter. My code : from SOAPpy import WSDL def GetWebServicesMethods(url): # requires import : #from SOAPpy import WSDL # just use the path to the wsdl of your choice full_url = url + '?WSDL' try: wsdlObject = WSDL.Proxy(full_url) except Exception: print "\n\nError in Getting WebServices Methods for : %s\n\n" % full_url print "\tUnexpected error : %s \n \t\t\t %s " % (sys.exc_info()[0], sys.exc_info()[1]) print return print '\nAvailable Methods for : %s\n\n' % (url) # print 'wsdlObject Raw : ', wsdlObject # print inspect.getmembers(wsdlObject) MethodCount = 1 for method in wsdlObject.methods.keys() : print '\t %d) %s\n' % (MethodCount, method) ci = wsdlObject.methods[method] # get the details of the current method for param in ci.outparams : # list of the function and type depending of the wsdl... AllParams = inspect.getmembers (param) for SubParam in AllParams: ParamName,ParamValue = SubParam # print '%15s = %s' % SubParam if ParamName == '__init__': print 'init_info = ', ParamValue else: print '%15s = %s' % (ParamName,ParamValue) input_parameter_values = '' for p in ci.getInParameters (): # save the parameters to a string input_parameter_values = '%s\t\t Name : %s\n' % (input_parameter_values, p.name) input_parameter_values = '%s\t\t Type : %s\n\n' % (input_parameter_values, p.type[1]) if input_parameter_values: # print only when there are parameters print '\n\n\t\tInput Parameters : \n' print input_parameter_values print print MethodCount = MethodCount + 1 Output : 1) getDate __doc__ = A ParameterInfo object captures parameter binding information. init_info = > *** How do I get the info out of the __init__ structure ??? __module__ = SOAPpy.wstools.WSDLTools default = None element_type = 0 name = getLastPromoOrSlottingDateReturn namespace = None type = (u'http://www.site.com/offerperf', u'ArrayOfPerfPromoInfo') Input Parameters : Name : in0 Type : ArrayOf_xsd_int Thanks! Steve From george.sakkis at gmail.com Tue Dec 12 15:46:49 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 12 Dec 2006 12:46:49 -0800 Subject: Frame hacking Message-ID: <1165956409.786690.150240@79g2000cws.googlegroups.com> I wonder if the following is possible: def inject_n_call(func, **kwds): '''Call func by first updating its locals with kwds.''' def f(): return x*y >>> inject_n_call(f, x=3, y=4) 12 I've been playing with sys.settrace, updating frame.f_locals in the trace function, but it doesn't seem to work. Any other ideas ? George From rampeters at gmail.com Fri Dec 8 16:33:05 2006 From: rampeters at gmail.com (johnny) Date: 8 Dec 2006 13:33:05 -0800 Subject: ERROR CLOSING CONNECTION: mysql connection close Message-ID: <1165613585.887732.182740@j72g2000cwa.googlegroups.com> I am getting following connection error from my python script: conn.close() AttributeError: adodb_mysql instance has no attribute 'close' Here is my relevant code below: def worker(tq): while True: host, e = tq.get() c = ftplib.FTP(host) c.connect() try: c.login() p = os.path.basename(e) download_dir = r'H:/ftp_download/' ps_dir = r'H:/ftp_download/' filename = download_dir+p fp = open(filename, 'wb') try: c.retrbinary('RETR %s' % e, fp.write) finally: fp.close() finally: c.close() if (p.lower().endswith('.ps') ): partFileName = p.split('.', 1) movedFile = download_dir + p #movedFile = p finalFile = ps_dir + partFileName[0]+'.pdf' encode_cmd = r'ps2pdf '+ movedFile + ' '+ finalFile os.system(encode_cmd) conn = adodb.NewADOConnection('mysql') conn.Connect('localhost', 'temp', 'temp', 'temp') sql = r"update video set pdf_file_path='" +finalFile+r"' where file_path='"+p+r"'" cursor = conn.Execute(sql) rows = cursor.Affected_Rows() cursor = conn.Execute(sql) rows = cursor.Affected_Rows() cursor.close() conn.close() tq.task_done() From gerard.blais at gmail.com Tue Dec 19 08:32:34 2006 From: gerard.blais at gmail.com (Gerry) Date: 19 Dec 2006 05:32:34 -0800 Subject: pyExcelerator question In-Reply-To: <1166496222.763413.71590@48g2000cwx.googlegroups.com> References: <1166477288.063934.221390@t46g2000cwa.googlegroups.com> <1166496222.763413.71590@48g2000cwx.googlegroups.com> Message-ID: <1166535154.469964.109780@48g2000cwx.googlegroups.com> Thanks!!! Looks great. Works for me. I'll try to submit the patch. Gerry From ecarlson at coe.eng.ua.edu Tue Dec 12 21:42:19 2006 From: ecarlson at coe.eng.ua.edu (Eric Carlson) Date: Tue, 12 Dec 2006 20:42:19 -0600 Subject: binary input and memory address passing Message-ID: Hello, I can open, read, and convert data to a numeric (double) array from a binary file using nc = #something given nr = #something given f_o=open('junk.bin','rb') x=reshape(array('d',f_o.read()),(nr,nc)) Is there a way in python that gives better performance? These commands take three to 4 times longer than loading the data into an array in (for example) octave. Also, is there a way to pass the address of a block of memory, and then access the data located there (pass by reference and let the python program know what data type to use)? My situation: I have two programs that can not communicate directly, but I can get memory addresses for any data in my programs. I currently save to a file, then load the data from file into my other program. Clearly it would be much faster if I could access the block of memory directly rather than making a copy. Any suggestions greatly appreciated. Cheers, Eric Carlson From juanrgonzaleza at canonicalscience.com Mon Dec 11 12:18:09 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 11 Dec 2006 09:18:09 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165849055.492230.119310@n67g2000cwd.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> Message-ID: <1165857489.067258.27160@j44g2000cwa.googlegroups.com> Kay Schluehr ha escrito: > Note also that a homogenous syntax is not that important when > analyzing parse trees ( on the contrary, the more different structures > the better ) but when synthesizing new ones by fitting different > fragments of them together. Interesting, could you provide some illustration for this? > The next question concerns compositionality of language > enhancements or composition of even completely independent language > definitions and transformers both on source and on binary level. While > this is not feasible in general without creating ambiguities, I believe > this problem can be reduced to ambiguity detection in the underlying > grammars. A bit ambiguous my reading. What is not feasible in general? Achieving compositionality? From googlegroups at romulo.e4ward.com Mon Dec 4 11:39:17 2006 From: googlegroups at romulo.e4ward.com (googlegroups at romulo.e4ward.com) Date: 4 Dec 2006 08:39:17 -0800 Subject: Factory pattern implementation in Python Message-ID: <1165250357.794022.87520@16g2000cwy.googlegroups.com> Hi, I need to parse a binary file produced by an embedded system, whose content consists in a set of events laid-out like this: ... Every "event" is a single byte in size, and it indicates how long is the associated "data". Thus, to parse all events in the file, I need to take it like a stream and read one event at a time, consuming bytes according to the event value, and jumping to the next event, until an EOF is reached. Since there are dozens of almost completely heterogeneous events and each one of them may imply different actions on the program parsing the file, I thought it would be convenient to have one class encapsulating the logic for every event. The parser would then sit in a loop, creating objects of different classes and calling a method (say "execute"). That method (different in every class) is responsible for consuming the bytes associated with the event. Hence, as the class the parser needs to instantiate in each iteration is not known in advance, a factory should be implemented. Somehow the factory should know how to map an event to a class. I don't know of the best way I should do that in Python. I made an attempt along the following lines: 1. Create a base class for the events; 2. For every descendant class declare (in the class body) a public attribute "eventNum" and assign it the value of the event it will be responsible for; 3. At runtime, the factory constructor scans the event class hierarchy and builds a dictionary mapping "eventNum"'s to classes. A draft of the implementation follows: ################################# ##### ##### class EvtBase: def __init__(self, file): self.file = file def execute(self): pass class Evt1(EvtBase): eventNum = 1 def execute(self): ... class Evt2(EvtBase): eventNum = 2 def execute(self): ... ... class EvtN(EvtBase): eventNum = N def execute(self): ... ##### ##### import inspect import events class Factory: def __isValidEventClass(self, obj): if inspect.isclass(obj) and obj != events.EvtBase and \ events.EvtBase in inspect.getmro(obj): for m in inspect.getmembers(obj): if m[0] == 'eventNum': return True return False def __init__(self): self.__eventDict = {} for m in inspect.getmembers(events, self.__isValidEventClass): cls = m[1] self.__eventDict.update({cls.eventNum: cls}) def parseEvents(self, file): while not file.eof(): ev = file.read(1) self.__eventDict[ev](file).execute() ################################# I'm using the inspect module to find the event classes. One drawback of this approach is the need to keep the event classes in a module different from that of the factory, because the getmembers method expects an already parsed object or module. (The advantage is keeping the event number near the class declaration.) I've already had to make the solution generic and I found it was not straightforward to separate the common logic while avoiding the need to keep the factory and the events in two distinct modules. Is there anything better I can do? I don't have enough experience with Python, then I don't know whether it offers a more obvious way to address my problem. Thanks in advance. -- Romulo A. Ceccon 'romulo%s\x40yahoo.com.br' % 'ceccon' From fredrik at pythonware.com Fri Dec 15 02:36:17 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 08:36:17 +0100 Subject: skip last line in loops In-Reply-To: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: eight02645999 at yahoo.com wrote: > how can i skip printing the last line using loops (for /while) > > eg > > for line in open("file): > print line. > > I want to skip printing last line of the file. do it lazily: last_line = None for line in open("file): if last_line: print last_line last_line = line or just gobble up the entire file, and slice off the last item: for line in list(open("file"))[:-1]: print line From gagsl-py at yahoo.com.ar Wed Dec 6 22:12:12 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 00:12:12 -0300 Subject: PHP calls python: process vs threads In-Reply-To: <1165424077.586240.122930@n67g2000cwd.googlegroups.com> References: <1165424077.586240.122930@n67g2000cwd.googlegroups.com> Message-ID: <7.0.1.0.0.20061207000656.054373c0@yahoo.com.ar> At Wednesday 6/12/2006 13:54, johnny wrote: >What I want to do is the following: > >Web user uploads a word doc, and I need it to move the uploaded word >doc, on to another machine and conver it to pdf. Then update the >database and allow immediate pdf download. I am thinking of using ftp >from machine 1 -> machine 2, then convert doc to pdf on machine 2, >using process or thread. What is the best way to go about doing this, >process or threads or pyro? Pdf is created by calling commands on the >command line, through python script. So, your python script does not write the pdf, just invokes some other commands to do the job, and waits for completion? In this case, I doubt Python would be a bottleneck, so the easy way is to launch a new process on each job. If you get many requests per second and notice that it's the Python startup which is slowing down the whole process, then you could consider changing it. But in that case I'd change the way the PDF are converted, not the Python script which controls that. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From fredrik at pythonware.com Fri Dec 22 03:06:44 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 22 Dec 2006 09:06:44 +0100 Subject: def index(self): In-Reply-To: References: <4587017b$0$22957$426a34cc@news.free.fr> <458807cc$0$19743$426a74cc@news.free.fr> <45891cb7$0$16994$426a34cc@news.free.fr> <1166659483.225301.48550@t46g2000cwa.googlegroups.com> Message-ID: Marc 'BlackJack' Rintsch wrote: > This depends on the definition of `expr`. If `expr` includes the > possibility of enclosing parenthesis then yes. There are scenarios where > you would need them. For example if you use objects that overload > operators to build a callable used as decorator: > > @spam + eggs + viking > def fn(...): ... that's a SyntaxError. the decorator syntax only allows for a dotted name, optionally followed by an argument list in parentheses. From inq1ltd at verizon.net Mon Dec 18 15:03:01 2006 From: inq1ltd at verizon.net (jim-on-linux) Date: Mon, 18 Dec 2006 15:03:01 -0500 Subject: writing serial port data to the gzip file In-Reply-To: <1166403993.201955.63290@l12g2000cwl.googlegroups.com> References: <1166403993.201955.63290@l12g2000cwl.googlegroups.com> Message-ID: <200612181503.01466.inq1ltd@verizon.net> If someone hasn't already commented, Aside from any other problems, the file you are trying to write to is (opened)?? in the "w" mode. Every time a file is opened in the 'w' mode, everything in the file is deleted. If you open a file in the 'a' mode, then everything in the file is left untouched and the new data is appended to the end of the file. Your while loop is deleting everything in the file on each loop with the 'w' mode. try, vfile = open('vfile', 'a') rather than vfile = open('vfile', 'w') jim-on-linux http:\\www.inqvista.com > while 1: > g=gzip.GzipFile("/root/foofile.gz","w") > while dataOnSerialPort(): > g.write(data) > else: g.close() On Sunday 17 December 2006 20:06, Petr Jakes wrote: > I am trying to save data it is comming from the > serial port continually for some period. > (expect reading from serial port is 100% not a > problem) Following is an example of the code I > am trying to write. It works, but it produce an > empty gz file (0kB size) even I am sure I am > getting data from the serial port. It looks > like g.close() does not close the gz file. > I was reading in the doc: > > Calling a GzipFile object's close() method does > not close fileobj, since you might wish to > append more material after the compressed > data... > > so I am completely lost now... > > thanks for your comments. > Petr Jakes > ==== snippet of the code ==== > def dataOnSerialPort(): > data=s.readLine() > if data: > return data > else: > return 0 > > while 1: > g=gzip.GzipFile("/root/foofile.gz","w") > while dataOnSerialPort(): > g.write(data) > else: g.close() From stefan.antonelli at operun.de Fri Dec 15 18:51:14 2006 From: stefan.antonelli at operun.de (Stefan Antonelli) Date: Fri, 15 Dec 2006 23:51:14 +0000 (UTC) Subject: convert from date string to epoch Message-ID: Hi, i have to convert several timestamps. The given format, eg "yyyy-mm-dd hh:mm:ss" has to be converted to an epoch string. Is there any proper way to do this? If not, i have to split the given string and resolve this by a calculation? Thanks for help. Stefan. From fredrik at pythonware.com Thu Dec 14 09:00:00 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 15:00:00 +0100 Subject: tuple.index() References: <1166103409.199435.290670@79g2000cws.googlegroups.com> Message-ID: Glenn Hutchings wrote: > But there are situations where you might want to treat it as a > read-only list. E.g., an argument to a function, so that you can > guarantee the function won't modify it. if you cannot trust your own code not to modify objects you pass to it, I'm not sure Python's the right language for you. From g.brandl-nospam at gmx.net Fri Dec 15 07:50:19 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Fri, 15 Dec 2006 12:50:19 +0000 Subject: Property error In-Reply-To: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> Message-ID: king kikapu wrote: > Hi to all, > > i am trying to use properties in Python and i am sure i have made > something wrong with the below code but i just cannot see what it is. > > Can anyone please help me on this ? > > The code is : > > class Person(object): > age = 0 > > @property > def age(): > def fget(self): > return self.age > def fset(self, value): > self.age = value > > me = Person() > me.age = "34" > print me.age > > > and i am getting the error: > > " File "C:\projects\Python\p2.py", line 12, in > me.age = "34" > AttributeError: can't set attribute " > > What exactly i am doing wrong ?? This will not work. There are some versions of a property decorator flowing around that allow you to do a similar thing, like class Person(object): age = 0 @Property def age(): def fget(self): return self.age def fset(self, value): self.age = value return locals() but here, Property is not the built-in "property" function. It is impossible to use the built-in property function as a decorator to create a property that isn't read-only. Georg From m.yanowitz at kearfott.com Tue Dec 19 06:51:17 2006 From: m.yanowitz at kearfott.com (Michael Yanowitz) Date: Tue, 19 Dec 2006 06:51:17 -0500 Subject: Can a Tkinter GUI check for abort script: In-Reply-To: <20061218162824.574.qmail@web31106.mail.mud.yahoo.com> Message-ID: <00d401c72363$fe468f40$0d7d12ac@kearfott.com> No. test3.py (for example) is just plain Python code that sends and receives socket data from another machine. It does (or could) contain loops that last a long time, repeating the read or write operations to and from the socket. This grabs the CPU. What I am hoping for is a function call I can make, without knowing any of the GUI objects, I can call from test3.py (or while test3.py is running) which will refresh the GUI and check for activity such as button presses on the GUI itself. For example, if I just call sleep(), will it do this? Thanks in advance: Michael Yanowitz -----Original Message----- From: python-list-bounces+m.yanowitz=kearfott.com at python.org [mailto:python-list-bounces+m.yanowitz=kearfott.com at python.org]On Behalf Of Mohammad Tayseer Sent: Monday, December 18, 2006 11:28 AM To: python-list at python.org Subject: RE: Can a Tkinter GUI check for abort script: I don't know why this happen. do you call mainloop() inside the test3.py?? you shouldn't Michael Yanowitz wrote: > Presently what happens is that the script takes over and all the buttons on > the GUI disappear > as the GUI is not given any cpu time to refresh or check if any activity in > the dialog. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Fri Dec 15 01:52:38 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 07:52:38 +0100 Subject: beginner, thread & else In-Reply-To: References: Message-ID: Gigs_ wrote: > can someone explain me this code did you write that yourself, or did you find it in some book or article? > ---------------------------------- > import thread the thread module should not be used directly by application programs; use the "threading" module instead. > stdoutmutex = thread.allocate_lock() > exitmutexes = [0] * 10 > > def counter(myId, count): > for i in range(count): > stdoutmutex.acquire() > print '[%s] => %s' % (myId, i) > stdoutmutex.release() > exitmutexes[myId] = 1 # signal main thread > > for i in range(10): > thread.start_new(counter, (i, 100)) > > while 0 in exitmutexes: > pass that's a "busy loop"; the CPU will spend all the cycles it can get checking for the condition. that's not a good way to wait for things. use the "threading" module instead; by default, it waits for all threads to finish without requiring flag lists and excessive CPU use. > print 'Main thread exiting.' > ----------------------------------- > > thread.start_new(counter, (i, 100)) is running counter function. it starts a new instance of counter, in a separate thread. > Is counter function and while statement executed in same time (other > things i understand, but can't get into this)? yes, the while loop will run in the "main" thread, in parallel with the other threads. however, Python uses a global lock to synchronize access to Python variables: http://effbot.org/pyfaq/what-is-the-global-interpreter-lock.htm so the threads in a simple program like this won't run fully in parallel on a multi-CPU machine. From duncan.booth at invalid.invalid Wed Dec 27 04:48:25 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Dec 2006 09:48:25 GMT Subject: Fuzzy string comparison References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> <1167167314.463288.98960@48g2000cwx.googlegroups.com> Message-ID: "John Machin" wrote: > To compare two strings, take copies, and: Taking a copy of a string seems kind of superfluous in Python. From __peter__ at web.de Fri Dec 15 06:14:22 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 Dec 2006 12:14:22 +0100 Subject: Logging module: problem with some mapping keys References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166106298.176199.301190@f1g2000cwa.googlegroups.com> <1166113691.753244.189350@f1g2000cwa.googlegroups.com> <1166115714.082561.87420@t46g2000cwa.googlegroups.com> <1166177343.040931.91100@n67g2000cwd.googlegroups.com> Message-ID: Tekkaman wrote: >> Putting /usr/lib64/python2.4 as the first entry into your >> >> PYTHONPATH >> >> environment variable might fix the problem (the idea is >> that /usr/lib64/python2.4 precedes /usr/lib/python2.4 in sys.path and is >> therefore used for the import of the logging package). > Thanks, I'll check it out. Anyway, since this is a hack, you think this > behaviour should be reported as a bug? Yes, that's a good idea. Peter From josephoswald at gmail.com Tue Dec 12 23:38:14 2006 From: josephoswald at gmail.com (josephoswaldgg@hotmail.com) Date: 12 Dec 2006 20:38:14 -0800 Subject: merits of Lisp vs Python In-Reply-To: <4u8hu5F177u11U1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> Message-ID: <1165984694.264366.261250@80g2000cwy.googlegroups.com> Bjoern Schliessmann wrote: > Robert Uhl wrote: > > > Because it's the language for which indentation is automatically > > determinable. That is, one can copy/paste a chunk of code, hit a > > key and suddenly everything is nicely indented. > > Cool, so in other languages I need to set block marks like () and {} > and also indent the code for readability, and in Python I indent > only. From my POV that's less work. Try reading again. In Lisp, you use () and *your editor* automatically indents according to the universal standard, or you leave it sloppy until other folks reading your code convince you to get a proper programming editor. Indentation does not get out of sync with semantics because the editor virtually never misses parentheses that the Lisp compiler sees. Expressions keep the same meaning even if you have to start breaking them across lines, etc. In Python, you group in your mind, and press indentation keys to make it happen in your editor. The editor cannot help that much, because it cannot read your mind. White space screwups in copy-paste cannot be fixed by the editor automatically, because it cannot read the original programmer's mind, and you have to fix it manually, and risk screwing it up. From __peter__ at web.de Sat Dec 2 05:47:50 2006 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Dec 2006 11:47:50 +0100 Subject: os.mkdir and mode References: <1165043870.135812.232530@73g2000cwn.googlegroups.com> Message-ID: Nick Craig-Wood wrote: > Peter Otten <__peter__ at web.de> wrote: >> vj wrote: >> >> > How do I do the following unix command: >> > >> > mkdir -m770 test >> > >> > with the os.mkdir command. Using os.mkdir(mode=0770) ends with the >> > incorrect permissions. >> >> mkdir() works just like its C equivalent, see >> http://docs.python.org/dev/lib/os-file-dir.html: >> >> "Where it is used, the current umask value is first masked out." >> >> Use os.chmod() after os.mkdir() to get the desired permissions. > > I think you meant use os.umask(0) before the os.mkdir() ? No, I didn't. What is the difference/advantage of that approach? Peter From exarkun at divmod.com Mon Dec 11 10:34:14 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 11 Dec 2006 10:34:14 -0500 Subject: SSH File Transfer Protocol or SFTP In-Reply-To: <1165850967.059239.109890@j72g2000cwa.googlegroups.com> Message-ID: <20061211153414.20948.566757565.divmod.quotient.67615@ohm> On 11 Dec 2006 07:29:27 -0800, Lad wrote: >Is there a module in Python available that I can use for uploading >files via > SFTP (SSH File Transfer Protocol)? >Or do you think that FTP protocol for files uploading is OK? >Thank you for replies >Lad. > Twisted Conch includes support for both SFTP servers and clients. http://twistedmatrix.com/trac/wiki/TwistedConch Jean-Paul From kentilton at gmail.com Sun Dec 10 10:11:37 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sun, 10 Dec 2006 10:11:37 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano wrote: > On Sun, 10 Dec 2006 02:12:29 -0500, Bill Atkins wrote: > > >>Steven D'Aprano writes: >> >> >>>Rightly or wrongly, people fear that Lisp's macros push Lisp closer to >>>that hypothetical anything-goes language than is healthy. Maybe that's a >> >>Wrongly. > > > That's your opinion, and as an experienced Lisp coder, it is an opinion > worth treating seriously. Nevertheless, a mere denial doesn't constitute > evidence, let alone proof. Well, it does unless you think we are lying, or creating obfuscated code and do not know it. This would be consistent with the theory that we positively love parentheses only because we are mutants. To be honest, I think it would be way cool if it turned out I was this mutant life form, the only kind that can understand Lisp. And this would be consistent with my theory that John McCarthy must be an alien. How else can he wander over to his desk one day, misread Church, and create a language that, as you say, is growing in popularity and whose essence can be found in every popular language except C++, which only makes my point. Have you read On Lisp by Paul Graham? It is on-line. Just the preface will do, I think, maybe also Chapter One where he raves on macros. Do you think he is mistaken? Confused? Lying? Mutant? This exchange has not been a complete disaster, but it sure could have covered a lot more ground if you had not had your hands over your ears. Now I see you want Lispniks to explain its unpopularity. I like that, we have to figure out what is wrong with you. :) Apparently that would be fear of the unknown, xenophobia, and prejudice. Meanwhile, given that Python and Ruby have copied so much from Lisp, and that languages seem to be converging on Lisp, now we have to have an equally daft exchange over the possibility that Lisp is the most popular language going. Even Java has Groovy. Lisp has all the cool qualities you like in your pets, plus native compilation in most implementations, plus maturity and a standard, plus a better OO, plus macros, plus a dozen more small wins. Including automatic indentation. :) It is just a matter of critical mass. At some very low threshold Lisp becomes "OK". I get the feeling that has already begun, but it is not quite there yet. Certainly it gets mentioned now when language names get bandied about, if only to be dismissed. That is a step up for us. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From pgurumur at gmail.com Sat Dec 23 06:32:32 2006 From: pgurumur at gmail.com (Prabhu Gurumurthy) Date: Sat, 23 Dec 2006 03:32:32 -0800 Subject: Question on regex Message-ID: <458D13D0.3000306@gmail.com> Hello all - I have a file which has IP address and subnet number and I use regex to extract the IP separately from subnet. pattern used for IP: \d{1,3}(\.\d{1,3}){3} pattern used for subnet:((\d{1,3})|(\d{1,3}(\.\d{1,3}){1,3}))/(\d{1,2}) so I have list of ip/subnets strewn around like this 10.200.0.34 10.200.4.5 10.178.9.45 10.200/22 10.178/16 10.100.4.64/26, 10.150.100.0/28 10/8 with that above examples: ip regex pattern works for all IP address subnet regex pattern works for all subnets problem now is ip pattern also matches the last 2 subnet numbers, because it falls under ip regex. to fix this problem, i used negative lookahead with ip pattern: so the ip pattern now changes to: \d{1,3}(\.\d{1,3}){3}(?!/\d+) now the problem is 10.150.100.0 works fine, 10.100.4.64 subnet gets matched with ip pattern with the following result: 10.100.4.6 Is there a workaround for this or what should change in ip regex pattern. python script: #!/usr/bin/env python import re, sys fh = 0 try: fh = open(sys.argv[1], "r") except IOError, message: print "cannot open file: %s" %message else: for lines in fh.readlines(): lines = lines.strip() pattIp = re.compile("(\d{1,3}(\.\d{1,3}){3})(?!/\d+)") pattNet = re.compile("((\d{1,3})|(\d{1,3}(\.\d{1,3}){1,3}))/(\d{1,2})") match = pattIp.search(lines) if match is not None: print "ipmatch: %s" %match.groups()[0] match = pattNet.search(lines) if match is not None: print "subnet: %s" %match.groups()[0] fh.close() output with that above ip/subnet in a file ipmatch: 10.200.0.34 ipmatch: 10.200.4.5 ipmatch: 10.178.9.45 subnet: 10.200 subnet: 10.178 ipmatch: 10.100.4.6 subnet: 10.100.4.64 subnet: 10.150.100.0 subnet: 10 TIA Prabhu -------------- next part -------------- A non-text attachment was scrubbed... Name: pgurumur.vcf Type: text/x-vcard Size: 369 bytes Desc: not available URL: From sjmachin at lexicon.net Tue Dec 19 21:04:56 2006 From: sjmachin at lexicon.net (John Machin) Date: 19 Dec 2006 18:04:56 -0800 Subject: tricky(?) win32com question - Mark Hammond or other experts please. In-Reply-To: <1166576759.360059.51230@48g2000cwx.googlegroups.com> References: <1166576759.360059.51230@48g2000cwx.googlegroups.com> Message-ID: <1166580296.034302.91450@f1g2000cwa.googlegroups.com> cfriedalek at gmail.com wrote: > OK, I've asked this earlier this week with no response. Since then I've > also received a suggestion from the app developers but that failed with > the same type error problem. Hopefully Mark Hammond or other experts > can offer a suggestion as to how to get around this problem. I'm > foolish enough to think that a solution can be found. Or can someone > suggest how to pm Mark. What is "pm"? You could email him directly, or ask your question on the pywin32 mailing list, or raise a bug/feature request on sourceforge -- he not only reads those, he actions them :-) > > --------------------------- > > I'm using pywin32com to drive a 3rd party app. The app has a VBS based > API. In VBS a specific query for data goes like this: > > Plot.QueryBegin datacode, Nothing > > where datacode is a number and Nothing is a VBS type/keyword > > The nominal python equivalent doesn't work. Plot.QueryBegin(datacode, > None) gives a type mismatch error as follows: com_error: (-2147352571, > 'Type mismatch.', None, 2) > > >From what I've been able to discover Nothing is not a null, 0, False, > "" Have you tried Plot.QueryBegin(datacode) ? Cheers, None From dcoffin at gmail.com Mon Dec 4 08:00:58 2006 From: dcoffin at gmail.com (David Coffin) Date: Mon, 4 Dec 2006 13:00:58 +0000 Subject: Beautiful Soup Question: Filtering Images based on their width and height attributes In-Reply-To: <1164919424.990637.98000@h54g2000cwb.googlegroups.com> References: <1164919424.990637.98000@h54g2000cwb.googlegroups.com> Message-ID: <2D56CEEE-E710-4060-BE9E-0311A3B58C85@gmail.com> > Hello, > > I want to extract some image links from different html pages, in > particular i want extract those image tags which height values are > greater than 200. Is there an elegant way in BeautifulSoup to do this? Yes. soup.findAll(lambda tag: tag.name=="img" and tag.has_key("height") and int(tag["height"]) > 200) From deets at nospam.web.de Tue Dec 19 09:47:06 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 19 Dec 2006 15:47:06 +0100 Subject: update attribute - (newbie) References: <1166538800.915433.38680@79g2000cws.googlegroups.com> Message-ID: <4uqcbaF18jc00U1@mid.uni-berlin.de> Bruce wrote: >>>> class A: > ... def __init__(self): > ... self.t = 4 > ... self.p = self._get_p() > ... def _get_p(self): > ... return self.t > ... >>>> a = A() >>>> a.p > 4 >>>> a.t += 7 >>>> a.p > 4 > > I would like to have it that when I ask for p, method _get_p is always > called so that attribute can be updated. How can I have this > functionality here? thanks You need to use a property, there are several possibilities to do so, a common idiom is this: class A(object): # must be newstyle def __init__(self): self._p = 6 def get_p(self): return self._p def set_p(self, v): self._p = v p = property(get_p, set_p) Diez From bytter at gmail.com Wed Dec 6 11:34:20 2006 From: bytter at gmail.com (Hugo Ferreira) Date: Wed, 6 Dec 2006 16:34:20 +0000 Subject: Best memory analyzer? Message-ID: <4e8efcf50612060834i25586797h9b0176136fd4d67e@mail.gmail.com> Hi! I'm using the BGL bindings, but I think I'm having a giant memory leak. Thing is, I'm not sure if it is the bound C++ variables that are not being trashed, or if the leak is inside my program. What is the best way to debug this? Thanks! Hugo Ferreira -- GPG Fingerprint: B0D7 1249 447D F5BB 22C5 5B9B 078C 2615 504B 7B85 From tim.peters at gmail.com Mon Dec 11 03:55:33 2006 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 11 Dec 2006 03:55:33 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165824471.730090.153530@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165824471.730090.153530@j72g2000cwa.googlegroups.com> Message-ID: <1f7befae0612110055s58c4f114tcfc12afe06bdc827@mail.gmail.com> [Paddy] >> http://en.wikipedia.org/wiki/Doctest [Kaz Kylheku] > I pity the hoplelessly anti-intellectual douche-bag who inflicted this > undergraduate misfeature upon the programming language. As a blind misshapen dwarf, I get far too much pity as it is, but I appreciate your willingness to share yours. If you like, feel free to give this precious gift to another. I get the impression that pity is something you don't feel often, and it would be a shame to waste it. > This must be some unofficial patch that still has a hope of being shot > down in flames, right? Alas, no. It was secretly snuck into Python's standard library in the 2.1 release (2001), and although we've done our best to hide it, it's widely used now. Strangely enough, it's especially popular among intellectuals ;-) From uymqlp502 at sneakemail.com Mon Dec 4 04:04:44 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 4 Dec 2006 01:04:44 -0800 Subject: Why not just show the out-of-range index? References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> Message-ID: <1165223084.558617.9570@79g2000cws.googlegroups.com> Robert Kern wrote: > Nothing is going to happen until you do one of these two things. Being more rude > (and yes, you are being incredibly rude and insulting) won't move things along. I re-read the thread, and I don't see anywhere where I was rude except in reply to rudeness by others. Sorry, but I haven't mastered the "turn the other cheek" thing yet. My suggestion that it would be much easier for the Python maintainers than for me to implement the requested feature is just basic common sense. I would have to spend many hours or days just to familiarize myself with the code, but they are obviously already very familiar with it. And they would probably have to spend nearly as much time checking my patch as they would writing it themselves anyway. By the way, your parenthical assertion that I am "being incredibly rude and insulting" is itself an unwarranted and devious insult, and I will not let you get away with it without being called on it. But I'm willing to forget about it and move on, and I'll assume you are too. From gregpinero at gmail.com Sun Dec 24 01:26:13 2006 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Sun, 24 Dec 2006 01:26:13 -0500 Subject: Use a Thread to reload a Module? In-Reply-To: <00f801c7271d$9feb95e0$03000080@hendrik> References: <312cfe2b0612221516x295949b5ka3f422d8bb41d5b@mail.gmail.com> <012b01c72662$b413de80$03000080@hendrik> <312cfe2b0612231704o56a6d6b8l82d8594268f0b71f@mail.gmail.com> <00f801c7271d$9feb95e0$03000080@hendrik> Message-ID: <312cfe2b0612232226l4046d357td4770b44882dc832@mail.gmail.com> On 12/24/06, Hendrik van Rooyen wrote: > "Gregory Pi?ero" wrote: ... > open( filename[,flag='c'[,protocol=None[,writeback=False[,binary=None]]]]) > > Open a persistent dictionary. The filename specified is the base filename for > the underlying database. As a side-effect, an extension may be added to the > filename and more than one file may be created. By default, the underlying > database file is opened for reading and writing. The optional flag parameter has > the same interpretation as the flag parameter of anydbm.open. > > hth - Hendrik So how is that better than using marshal as I am now? Is it faster to load? Perhaps I could do speed tests to compare. -Greg From aaronwmail-usenet at yahoo.com Wed Dec 27 15:56:01 2006 From: aaronwmail-usenet at yahoo.com (aaronwmail-usenet at yahoo.com) Date: 27 Dec 2006 12:56:01 -0800 Subject: ANN: Skimpy CAPTCHA adds WAVE audio, and a problem Message-ID: <1167252961.787211.15090@n51g2000cwc.googlegroups.com> SKIMPY CAPTCHA ADDS AUDIO, AND A PROBLEM [or what I did over xmas weekend at the inlaws -- python/web/audio experts skip to the bottom and solve my problem please.] Skimpy Gimpy CAPTCHA now supports WAVE audio output to help people with visual impairments answer Skimpy challenges. Read more, try it out, download it here: http://skimpygimpy.sourceforge.net Skimpy is a tool for generating HTML visual and WAVE audio representations for strings which people can understand but which web robots and other computer programs will have difficulty understanding. Skimpy is an example of a Captcha: an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart". The visual HTML Skimpy program skimpyGimpy.py and API (applications programmer interface) is implemented in a single self contained Python script (module). The input for Skimpy are words or phrases. The output of the program and API are strings containing HTML preformatted text. The preformatted text contains "ASCII art" representing the input phrase, which looks like somewhat sloppy handwriting on a speckled page, when viewed in an HTML browser. It is intended that it is easy for a human to read the word or phrase when rendered as HTML, but it is difficult for a program to extract the word or phrase automatically. The program uses a number of techniques to make the output difficult for a computer to interpret: curve interpolation, random rotation, random skew, random scale adjustment, "smearing", and addition of noise. In order to allow CAPTCHA tests that are usable by people with visual empairment, Skimpy also provides an audio implementation. The audio WAVE Skimpy program waveTools.py uses a compiled audio sample file waveIndex.zip. The input of the program are words or phrases and the output are the words or phrases spelled as individual spoken characters in an audio stream. It is intended that a human can understand the audio stream but a computer program will not be able to analyse the stream and extract the letters. To make the audio stream more difficult to automatically analyse (without making it unintelligible) the program randomly overlaps and stretches/shrinks the input samples, among other things. The Skimpy tools are far easier to install, use, and embed than other similar technologies. THE PROBLEM Unfortunately there is a problem with using Firefox and Quicktime with the Skimpy audio. If you save the audio to a temporary file and stream from there everything works fine, but if you try to stream directly from the CGI or mod-python module via HTTP Quicktime TRUNCATES THE AUDIO TO ABOUT 3 SECONDS. This ONLY happens under Firefox afaik -- IE, for example has no problems. Am I doing something wrong? Please inform. The skimpygimpy1.1 download has all the relevant source code if you'd like to have a look. Help! Thanks in advance. I'm leaving the bug demonstrated in my sample web scripts for now, but if no one comes up with a fix I will hack around it in a few days... probably... -- Aaron Watters === Later on, we'll perspire as we stare at the fire and face so afraid the bills left unpaid walking in a winter wonderland -- seen in "For Better or Worse" From espen at vestre.net Mon Dec 11 10:45:34 2006 From: espen at vestre.net (Espen Vestre) Date: 11 Dec 2006 16:45:34 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > If you say foo.frob() in Python, that's supposed to look up 'frob' in > a dictionary hanging off of foo. You can modify the contents of this > dictionary any time you want. You can redefine CLOS methods at run time any time you like, so this doesn't make Python more /dynamic/ than CLOS. Maybe you should replace "more dynamic" with "less managable", if that's what you mean? -- (espen) From basti.wiesner at gmx.net Wed Dec 20 06:44:45 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 20 Dec 2006 12:44:45 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Fredrik Lundh schrieb > Sebastian 'lunar' Wiesner wrote: > >> No, they aren't! Try this: > > you're confusing the shell's "is this file executable" check with the > loader's "can I execute this file" check: > > $ export PATH=.:$PATH > $ dd if=/dev/zero of=ls count=1 > 1+0 records in > 1+0 records out > $ ls -l ls > -rw-rw-r-- 1 slab slab 512 Dec 20 03:33 ls > $ chmod a+x ls > $ ls > -bash: ./ls: cannot execute binary file ??? Am I blind or is there really no difference between you shell example an mine? As far as I can see, you are doing exactly the same thing as I did... So what are trying to proof? Sebastian -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From atkinw at rpi.edu Sun Dec 10 13:14:07 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 13:14:07 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano writes: > You know, I'm really starting to think that you Lispers -- and I hate to > generalise, but in this case I feel I'm forced to -- have a real problem You feel you're forced to generalize about an entire group of language users based on what a handful of people have posted on a newsgroup? > So which is it? If Lisp is so self-evidently better than every other > language, and if nobody has any fears or concerns with Lisp, why is Lisp a > fringe language? Not as fringe as it was ten years ago, and maybe growing > in popularity, and it is beyond all doubt that Lisp has a lot of influence > amongst language designers, but outside of a few niche areas, its still a > fringe language. I'd like to know the answer. But the problem most people cite is the parentheses, not the fear that someone will abuse macros. I have certainly never seen anyone as worried about macros as you seem to be. >>> My point isn't whether or not their claims are correct (a "couple" of >>> macros? really?) but that things like this feed the perception that Lisp >>> is close to that hypothetical language where anything could be anything. >>> If anything could be anything, do you really know what (+ 1 2) means >>> without reading every line of code? >> >> Jesus H Christ. Didn't you just get through talking about how easily >> someone can redefine built-ins in Python? > > Yes. But you can't redefine 1+2 in Python, at least not without hacking > the interpreter. Can you redefine (+ 1 2) in Lisp? Yes. Can't you redefine standard functions in Python? Frank Buss correctly points out that you can shadow the + symbol and make it whatever you'd like it to be. This is true, but now someone has to intentionally and specifically import the package containing that shadowed + into their own package. You are never unwittingly using a different + than the standard CL one, although you really seem to want this to be the case. >>> (This is an interesting demonstration that any language that allows file >>> I/O and importing of external program files can always treat functions >>> as data, even if the language doesn't directly support it. An alternative >>> would be to keep the strings in memory instead of writing to a module, >>> then use exec on them instead of importing the module.) >> >> No, it treats code as text. See the difference? > > Text is data. > > What is the point of your comment? You don't have to argue about every > thing I say, even the ones we agree on. Look again at what I wrote. Is > there anything that gave you the impression that I think that having the > ability to write text to a file and import it is better than actually > supporting functional programming directly? Well, text is not code. Text is a syntaxful representation of the actual code, which is an AST. If I have a string full of text, I can't do very much meaningful work with it. On the other hand, if I have an AST, I can transform it or analyze it however I choose. >> Could you calm down? > > Okay, once was funny. Twice is worrying. What exactly is giving you the > idea I need to calm down? Was it the use of reasoning and logic? > Perhaps it was the attempt to be reasonable and moderate and find some > middle ground that we could agree on, or if not agree, at least say "Well, > I disagree with you, but at least I understand where you are coming from"? Where I'm coming from? Dude, you're writing paragraph upon paragraph about the same thing, multiple times per day. You're terrified of worst-case scenarios that everyone else is telling you are not realistic. From daniel at bowettsolutions.com Fri Dec 1 05:41:28 2006 From: daniel at bowettsolutions.com (Daniel Bowett) Date: Fri, 01 Dec 2006 10:41:28 +0000 Subject: Win32 Excel Generation Slow Message-ID: I am trying to create an excel document that displays a table of data. It does exactly what I want but takes a long time. I am writing around 1000 rows and it takes around a second to do each row. Is there a quicker way to write this? The reason I want excel is this needs to read and manipulated by management. The function I am using is: def createExcel(data): xlApp = Dispatch("Excel.Application") wb = xlApp.Workbooks.Add() xlApp.Visible = 1 ws = wb.Worksheets[0]; headers = ["Sales Rank", "UPC", "Description", "Stock", "Manifest Stock", "Total Stock", "Week Sales", "Price", "Total Price", "Days Cover"] column = 1 for each in headers: xlApp.ActiveSheet.Cells(1, column).Value = each column = column + 1 row = 1 for eachline in data: xlApp.ActiveSheet.Cells(row, 1).Value = row xlApp.ActiveSheet.Cells(row, 2).Value = eachline[0] xlApp.ActiveSheet.Cells(row, 3).Value = eachline[1] xlApp.ActiveSheet.Cells(row, 4).Value = eachline[2] xlApp.ActiveSheet.Cells(row, 5).Value = eachline[3] xlApp.ActiveSheet.Cells(row, 6).Value = eachline[4] xlApp.ActiveSheet.Cells(row, 7).Value = eachline[5] xlApp.ActiveSheet.Cells(row, 8).Value = eachline[6] xlApp.ActiveSheet.Cells(row, 9).Value = eachline[7] xlApp.ActiveSheet.Cells(row, 10).Value = eachline[8] row = row + 1 From mahs at telcopartners.com Wed Dec 13 18:50:00 2006 From: mahs at telcopartners.com (Michael Spencer) Date: Wed, 13 Dec 2006 17:50:00 -0600 Subject: Iterating over several lists at once In-Reply-To: <1166050184.791028.52610@j72g2000cwa.googlegroups.com> References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> <1166021513.479174.113630@80g2000cwy.googlegroups.com> <1166035250.709872.135350@t46g2000cwa.googlegroups.com> <1166050184.791028.52610@j72g2000cwa.googlegroups.com> Message-ID: John Henry wrote: > Carl Banks wrote: > >> The function can be extended to allow arbitrary arguments. Here's a >> non-minmal recursive version. >> >> def cartesian_product(*args): >> if len(args) > 1: >> for item in args[0]: >> for rest in cartesian_product(*args[1:]): >> yield (item,) + rest >> elif len(args) == 1: >> for item in args[0]: >> yield (item,) >> else: >> yield () >> >> > > Very nice. > another implementation of cartesian_product using 'reduce' to add mystery ;-) def star(outer, inner): for rest in outer: for item in inner: yield rest + (item,) def cartesian_product(*args): return reduce(star, args, ((),)) >>> list(cartesian_product("01","01","01")) [('0', '0', '0'), ('0', '0', '1'), ('0', '1', '0'), ('0', '1', '1'), ('1', '0', '0'), ('1', '0', '1'), ('1', '1', '0'), ('1', '1', '1')] >>> Michael From jm.suresh at gmail.com Tue Dec 12 01:57:43 2006 From: jm.suresh at gmail.com (jm.suresh@no.spam.gmail.com) Date: 11 Dec 2006 22:57:43 -0800 Subject: namespace question In-Reply-To: References: <1165904406.053883.129610@l12g2000cwl.googlegroups.com> Message-ID: <1165906663.732484.203200@73g2000cwn.googlegroups.com> Marc 'BlackJack' Rintsch wrote: > In <1165904406.053883.129610 at l12g2000cwl.googlegroups.com>, > jm.suresh at no.spam.gmail.com wrote: > > > class Test: > > a = 1 > > b = 2 > > c = 1+2 > > > > Now, all a,b and c would be directly visible to the user from the > > instance of Test. I am looking for a way to make only c directly > > visible from the instance. > > Simplest way: > > class Test: > c = 3 > > :-) > > You know that `a`, `b` and `c` are class variables and not instance > variables!? Yes. I want to have only one class variable called c and a and b are required as temporary variables to calculate the value for c. I just found one way: class Test: a = 1 b = 2 c = a + b del a,b This one works. But I suppose there must be a way to artificially create a new block of code, some thing like this, class Test: c = None <>: # Objects created here are local to this scope a = 1 b = 2 global c c = a + b > > Ciao, > Marc 'BlackJack' Rintsch From jon at ffconsultancy.com Sat Dec 23 13:40:15 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat, 23 Dec 2006 18:40:15 +0000 Subject: Xah's Edu Corner: Introduction to 3D Graphics Programing References: <1166836083.084101.25870@73g2000cwn.googlegroups.com> Message-ID: <458d7899$0$8725$ed2619ec@ptn-nntp-reader02.plus.net> Xah Lee wrote: > Introduction to 3D Graphics Programing > http://xahlee.org/3d/index.html You will probably find it more rewarding to use a more modern graphics system, such as OpenGL or DirectX, with a suitable programming language rather than Mathematica's. I would recommend any of OCaml, F#, Haskell, Lisp, Scheme, Python or Ruby for graphics, you can do much more sophisticated, animated, real time visualisations than you can with Mathematica's primitives. There are lots of great web pages out there. I've written some 2D and 3D graphics examples in OCaml: http://www.ffconsultancy.com/products/ocaml_for_scientists/visualisation http://www.ffconsultancy.com/free/ray_tracer http://www.ffconsultancy.com/free/fractal http://www.ffconsultancy.com/free/maze and more recently F#: http://www.ffconsultancy.com/dotnet/fsharp I was very impressed with the tutorial videos on VPython at ShowMeDo: http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries For an introduction to OpenGL, look no further than the NeHe tutorials at GameDev: http://nehe.gamedev.net One of our future products at FF Consultancy is a suite of extensions for the F# interactive mode that allows you to visualise 2D and 3D graphics in real time with simplicity rivalling Mathematica but the sophistication and performance of DirectX, whilst also having the power of the F# programming language and .NET to analyse your data. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From fredrik at pythonware.com Tue Dec 12 04:27:21 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Dec 2006 10:27:21 +0100 Subject: Tarfile .bz2 In-Reply-To: <457E4667.5080703@v.loewis.de> References: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> <1165887178.775792.142820@80g2000cwy.googlegroups.com> <457E4667.5080703@v.loewis.de> Message-ID: Martin v. L?wis wrote: > Well, .jpg files are already compressed in a lossy way (.jpg is > inherently lossy); to compress it further, you need to increase > the loss. or use a better algorithm, such as JPEG 2000 or Microsoft's HD Photo, which both give better visual quality at lower bit rates (which means that you can often get by with around half the bits compared to JPEG). From pavlovevidence at gmail.com Sat Dec 2 12:28:52 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 2 Dec 2006 09:28:52 -0800 Subject: About alternatives to Matlab In-Reply-To: <1165080056.083648.207580@16g2000cwy.googlegroups.com> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> Message-ID: <1165080532.147541.42040@n67g2000cwd.googlegroups.com> Carl Banks wrote: > Matlab has a few *cough* limitations when it comes to hand-optimizing. > When writing naive code, Matlab often is faster than Python with numpy > because it has many commerical man-year of optimizing behind it. > However, Matlab helps v That should say: However, Matlab helps very little when you need to speed things up, or (especially) use less memory than the naive way. Carl Banks From danielkleinad at gmail.com Fri Dec 15 09:37:53 2006 From: danielkleinad at gmail.com (Daniel Klein) Date: Fri, 15 Dec 2006 14:37:53 GMT Subject: skip last line in loops References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: <8kc5o29rjfiurn64s5abj9vgohnnspnl76@4ax.com> On 14 Dec 2006 22:47:23 -0800, eight02645999 at yahoo.com wrote: >hi, >how can i skip printing the last line using loops (for /while) > >eg > >for line in open("file): > print line. > >I want to skip printing last line of the file.thanks while True: line1 = myfile.readline() if not line1: break line2 = myfile.readline() if line2: print line1 else: break Dan From jtgalkowski at alum.mit.edu Wed Dec 27 11:56:40 2006 From: jtgalkowski at alum.mit.edu (Jan Theodore Galkowski) Date: Wed, 27 Dec 2006 11:56:40 -0500 Subject: loose methods: Smalltalk asPython Message-ID: <1167238600.6691.282149011@webmail.messagingengine.com> >Jan Theodore Galkowski wrote: >> Comments? Suggestions? > Luc, don't misunderstand: There's nothing at all wrong with Python nor am I suggesting there is. I'm just exploring how far I can go using its dynamic nature. There's no hope of using loose methods in Java. I think Python is very fine although, arguably, because many are approaching it from a Java strong-typing static mindset, I bet the space of design possibilities hasn't been explored thoroughly. We've not had an excellent dynamic OO language since Smalltalk, IMO. Perhaps Ruby is or is not. But I've looked a bit at Ruby, and I like Python more. - Jan From gagsl-py at yahoo.com.ar Tue Dec 12 05:06:28 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 02:06:28 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1165912704.390252.184260@n67g2000cwd.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> Message-ID: <1165917988.141401.195050@16g2000cwy.googlegroups.com> mohan ha escrito: > > > I had created my own modules (.py files) in > > > drives and folders other than the python root. > > > I tried your advice, by adding a new path to the "System Variable" > section. It still does not work. I don't understand how could PythonWin There was an error in a previous post, you should create a variable called PYTHONPATH, not change the system PATH. Or, group your modules into packages and put them below lib\site-packages. -- Gabriel Genellina From steven.bethard at gmail.com Tue Dec 5 12:36:30 2006 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 5 Dec 2006 10:36:30 -0700 Subject: [ANN] argparse 0.3 - Command-line parsing library Message-ID: Announcing argparse 0.3 ----------------------- argparse home: http://argparse.python-hosting.com/ argparse single module download: http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw argparse bundled downloads at PyPI: http://www.python.org/pypi/argparse/ About this release ================== This release moves argparse's development status from Pre-Alpha to Alpha. The API is basically stable, though reasonable change requests will still be considered. New in this release =================== * The '--' pseudo-argument can now be used to terminate the arg list of an optional:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('-x', nargs='+') >>> parser.add_argument('y') >>> parser.parse_args('-x X1 X2 X3 -- Y'.split()) Namespace(x=['X1', 'X2', 'X3'], y='Y') About argparse ============== The argparse module is an optparse-inspired command line parser that improves on optparse by: * handling both optional and positional arguments * supporting parsers that dispatch to sub-parsers * producing more informative usage messages * supporting actions that consume any number of command-line args * allowing types and actions to be specified with simple callables instead of hacking class attributes like STORE_ACTIONS or CHECK_METHODS as well as including a number of other more minor improvements on the optparse API. To whet your appetite, here's a simple program that sums its command-line arguments and writes them to a file:: parser = argparse.ArgumentParser() parser.add_argument('integers', type=int, nargs='+') parser.add_argument('--log', type='outfile', default=sys.stdout) args = parser.parse_args() args.log.write('%s\n' % sum(args.integers)) args.log.close() From rpdooling at gmail.com Thu Dec 14 09:00:09 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 14 Dec 2006 06:00:09 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> <1166046193.734274.124160@73g2000cwn.googlegroups.com> <1166055959.498100.116240@79g2000cws.googlegroups.com> Message-ID: <1166104809.818036.255270@80g2000cwy.googlegroups.com> Fredrik Lundh wrote: > > have you searched the *entire* registry for the "PythonCore" key? > (python looks under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER) > I found it in the Scripts key! I was searching on PythonPath before. Sorry. Thank you for the enlightenment. rd From address.good.until.2006.dec.22 at justmail.de Tue Dec 12 10:28:21 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Tue, 12 Dec 2006 16:28:21 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7xwt4y6j57.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> <7xwt4y6j57.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin schrieb: > Andr? Thieme writes: >>> import module >>> module.function = memoize(module.function) >> Yes, I mentioned that a bit earlier in this thread (not about the >> "during runtime" thing). >> I also said that many macros only save some small bits of code. >> Your python example contains 4 tokens / brain units. >> The Lisp version only has 2. > > You shouldn't count the import statement, since you'd need the > equivalent in Lisp as well. I didn't count it. 1P) module.function 2P) = 3P) memoize( 4P) module.function) vs 1L) (memoize 2L) function) I counted 1P and 4P only as one (each) although it should have been 2 for each. But it would have worked too if we didn't need the "module.": function = memoize(function). > Contrast the much more common > > a[i] = b[n] > > with > > (setf (aref a i) (aref b n)) > > and the attractions of Python may make more sense. Here Python and Lisp are equal, 7 tokens vs 7 tokens, but in Python one has to write less since "[]" are 2 chars while "aref" are 4, plus the setf. But from counting the brain units which I regard as an important factor they are both equal. Andr? -- From jstroud at mbi.ucla.edu Mon Dec 4 21:33:21 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 05 Dec 2006 02:33:21 GMT Subject: Why not just show the out-of-range index? In-Reply-To: <1165264641.125857.85980@80g2000cwy.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> <45745C9E.9050500@v.loewis.de> <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> <1165264641.125857.85980@80g2000cwy.googlegroups.com> Message-ID: <4574DA71.9090003@mbi.ucla.edu> Russ wrote: > Fredrik Lundh wrote: > > >>>Sorry I haven't thought this through 100% >> >>obviously not. > > > > And you didn't like the "tone" of some of my earlier posts? > Some people consider themselves above a sensible conversation. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From eight02645999 at yahoo.com Wed Dec 13 06:43:18 2006 From: eight02645999 at yahoo.com (eight02645999 at yahoo.com) Date: 13 Dec 2006 03:43:18 -0800 Subject: paramiko public key In-Reply-To: References: <1165898171.088807.100360@j44g2000cwa.googlegroups.com> Message-ID: <1166010198.691249.238040@j44g2000cwa.googlegroups.com> hg wrote: > eight02645999 at yahoo.com wrote: > > > paramiko > http://www.lag.net/paramiko/docs/ > > __str__ ? hi thanks for the tip i done up a function to generate priv/pub key pairs like this def keygen(bits,fil,password=None): k = paramiko.RSAKey.generate(bits) k.write_private_key_file(fil, password) pk = paramiko.RSAKey(filename=fil) o = open(pubk ,"w").write(pk.__str__()) Is this the correct way to do it ? thanks From CRhode at LacusVeris.com Wed Dec 6 12:53:24 2006 From: CRhode at LacusVeris.com (Chuck Rhode) Date: Wed, 6 Dec 2006 11:53:24 -0600 Subject: PythonTidy In-Reply-To: References: <20061205150527.GA3854@loki> Message-ID: <20061206175324.GC6333@loki> Thomas Heller wrote this on Tue, Dec 05, 2006 at 07:06:30PM +0100. My reply is below. > There is still one major issue. pythonTidy uses open(input-file, > "rb") to open the Python module to tidy up. That does not work on > Windows, at least if the file has (as it should) "\r\n" newlines. Thank you for challenging my parochial world view. I have posted yet another version of PythonTidy: http://www.lacusveris.com/PythonTidy/PythonTidy-1.5.python This one is omnivorous wrt to newlines. > For output, PythonTidy generates "\n" line endings, this should also > be changed on Windows. When OVERRIDE_NEWLINE = None, the first newline encountered on input is the one used throughout the output; otherwise, you can set it to what you want, e.g, OVERRIDE_NEWLINE = '\n'. > PythonTidy outputs strings with single quotes, while my own style is > to use double quotes (I don't think that pep8 prefers one over the > other). Is it possible to customize this? Here is a new global: DOUBLE_QUOTED_STRINGS = True. -- .. Chuck Rhode, Sheboygan, WI, USA .. Weather: http://LacusVeris.com/WX .. 30? ? Wind WNW 15 mph ? Sky overcast. From jon at ffconsultancy.com Sun Dec 17 12:49:46 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 17 Dec 2006 17:49:46 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45844272$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <2006121614375650878-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45853e98$0$8712$ed2619ec@ptn-nntp-reader02.plus.net> <2006121711381343042-raffaelcavallaro@pasdespamsilvousplaitmaccom> Message-ID: <458583cd$0$8715$ed2619ec@ptn-nntp-reader02.plus.net> Raffael Cavallaro wrote: > On 2006-12-17 07:54:28 -0500, Jon Harrop said: >> What if eager impurity isn't the "very nature" of the problem but, >> rather, is the very nature of Tilton's chosen solution? > > That's the whole point which you keep missing - that a programming > language is expressive precisely to the extent that it allows you to > express the solution in the *programmer's* chosen form, not the > paradigm imposed by the language. That is the ideal, yes. In practice, different languages encourage you to use different solutions. For example, when faced with a problem best solved using pattern matching in Lisp, most Lisp programmers would reinvent an ad-hoc, informally specified and bug-ridden pattern matcher of their own. Do you not think that Lispers typically "compile" their high-level algorithms into low-level Lisp constructs like COND or IF? > You look down your nose at cells, but if that's the way kenny conceived > of the problem - as a graph of changing state, why should he be forced > to reconceptualize it according to someone else's notion of programming > correctness (be that pure functional or any other paradigm)? Kenny isn't being forced to do anything. > By asking this question you've implicitly admitted that to solve it *as > he thought of it* in a pure functional language would require > reconceptualizing it (i.e., the aforementioned "jumping through > hoops"). You are saying that solving it as he solved it requires a different solution. How does that make Lisp any different to the next language? > We don't want to reconceptualize everything according to a > particular paradigm, we want the flexibility to write the solution to > the problem in the terms we think and talk about it, not the > procrustean bed of pure functional semantics. Of the programming paradigms that can be implemented in Lisp, Lisp doesn't exactly make them easy. Moreover, every time you pick a random Lisp library off the wall to implement some feature already found in most other languages, you fragment the already tiny user base into even fewer people. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From bjourne at gmail.com Mon Dec 25 18:36:32 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 25 Dec 2006 23:36:32 +0000 Subject: Generating all permutations from a regexp In-Reply-To: References: <740c3aec0612220630l39be117fu7977a7a2fb6e9998@mail.gmail.com> Message-ID: <740c3aec0612251536u74f32071sc14eef4ec8844fbf@mail.gmail.com> On 12/22/06, Fredrik Lundh wrote: > BJ?rn Lindqvist wrote: > > With regexps you can search for strings matching it. For example, > > given the regexp: "foobar\d\d\d". "foobar123" would match. I want to > > do the reverse, from a regexp generate all strings that could match > > it. > > > > The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000", > > "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999". > > > > Is this possible to do? Obviously, for some regexps the set of matches > > is unbounded (a list of everything that matches "*" would be very > > unpractical), but how would you do it for simple regexps like the one > > above? > > here's a start: > > http://mail.python.org/pipermail/python-list/2001-August/102739.html Thankyou! Who would have known that there is a sre_parse module... makes things quite a bit easier. -- mvh Bj?rn From JKPeck at gmail.com Thu Dec 7 21:19:14 2006 From: JKPeck at gmail.com (JKPeck) Date: 7 Dec 2006 18:19:14 -0800 Subject: Module Indexing In-Reply-To: <4tp0j0F14t555U1@mid.uni-berlin.de> References: <1165445933.933648.286730@j44g2000cwa.googlegroups.com> <4tp0j0F14t555U1@mid.uni-berlin.de> Message-ID: <1165544354.542202.246830@80g2000cwy.googlegroups.com> Thanks. I've gotten good results with epydoc pretty quickly. It hangs on one module just burning cpu time, but I've left that one out for now. Diez B. Roggisch wrote: > JKPeck schrieb: > > We are interested in building a module index for our libraries similar > > to the global module index on the Python site. Is there a tool/script > > available that builds something similar to that automatically? We > > would probably want the result to be an html document. > > Several, e.g. epydoc > > Diez From steve at REMOVE.THIS.cybersource.com.au Wed Dec 20 06:48:20 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Wed, 20 Dec 2006 22:48:20 +1100 Subject: Newbie: What are the rules wrt constructing PYDOC keywords References: <1166561296.831122.103230@a3g2000cwd.googlegroups.com> Message-ID: On Tue, 19 Dec 2006 12:48:16 -0800, paulsendave wrote: > Still learning python (2.4) and have instructions that all of our > python scripts should be SelfDoc'ing via pydoc standards. > > One thing that isn't clear to me is how pydoc searches for keywords. I > believe that there might be certain rules for putting keywords together > under the SYNOPSIS and search paths that "pydoc -k" uses that aren't > obvious to me. > > (Of course, it'd be a good training exercise to read through pydoc.py > itself and figure it out for myself, and I might just do that, but for > the moment, there are other priorities.) I'd love to help you, and I just might do that, but for the moment there are other priorities. Honestly, do you really expect to have people do your work for you, for free, when you all but say "I could answer this myself but I'm too lazy"? You might want to read this: http://catb.org/esr/faqs/smart-questions.html At least make a bit of an effort first. Or if you can't/won't make an effort, don't rub people's nose in the fact. E.g. you might like to tell us what behaviour leads you to believe there are "certain rules". Explain how you think pydoc searches for keywords, and what behaviour your guess doesn't explain. -- Steven From martin at v.loewis.de Sat Dec 2 13:29:05 2006 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 02 Dec 2006 19:29:05 +0100 Subject: os.mkdir and mode In-Reply-To: References: <1165043870.135812.232530@73g2000cwn.googlegroups.com> Message-ID: <4571C5F1.4080209@v.loewis.de> Nick Craig-Wood schrieb: > So it looks like python mkdir() is applying the umask where as > /bin/mkdir doesn't. From man 2 mkdir Actually, mkdir(1) has no chance to not apply the umask: it also has to use mkdir(2), which is implemented in the OS kernel, and that applies the umask. Try strace mkdir -m770 test to see how mkdir solves this problem; the relevant fragment is this: umask(0) = 022 mkdir("test", 0770) = 0 chmod("test", 0770) = 0 So it does *both* set the umask to 0, and then apply chmod. Looking at the source, I see that it invokes umask(0) not to clear the umask, but to find out what the old value was. It then invokes chmod to set any "special" bits (s, t) that might be specified, as mkdir(2) isn't required (by POSIX spec) to honor them. Regards, Martin From pavlovevidence at gmail.com Sun Dec 3 10:58:52 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 3 Dec 2006 07:58:52 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165161532.686060.78860@73g2000cwn.googlegroups.com> Jon Harrop wrote: > >> In particular, I think you are eagerly > >> allocating arrays when, in a functional language, you could just as > >> easily compose closures. > > > > You are completely wrong. > > I'll give an example. If you write the Python: > > a[:] = b[:] + c[:] + d[:] > > I think that is equivalent to the ML: > > fill a (map2 ( + ) (map2 ( + ) b c) d) > > which can be deforested in ML to avoid the creation of the intermediate > result b[:] + c[:] by using a closure to add three values at once: > > fill a (map3 (fun b c d -> b + c + d) b c d) > > which will be much faster because it doesn't generate an intermediate array. Ah, but, this wasn't about temporaries when you spoke of "eagerly allocating arrays", was it? But yes, you're right, in this example temporary arrays are created; arrays that Ocaml would not need. (I don't exactly understand why you'd need a functional language to get this optimization, though.) You might have guessed that you can get rid of most temporary arrays, at the expense of readability, with numpy. For example, replacing d1[:] = odd[:] - C1*even[:] with numpy.multiply(-C1,even,d1) numpy.add(d1,odd,d1) eliminates the intermediate. No unnecessary array allocations; no closures necessary. I'm curious whether this shared-slicing isn't, in some ways, advantageous over the Ocaml way. I presume that in Ocaml, the way you'd "share" array data is to create a closure can apply some operation to selected elements of the array, returning the result. But could this as easily modify the array in-place? I presume a good compiler could be able to inline the function and optimize the call to an in-place operation, but I'm not sure how well this works in practice. Here's a version of D4_Transform that uses no temporary arrays (aside from the work arrays s1, d1, and d2, which are allocated only once). It's about 40% faster for me than the one with infix operations. I'd be curious how it compares to a correct Ocaml version. (I'd still expect Ocaml to be at least twice as fast.) def alt_D4_Transform(x, s1=None, d1=None, d2=None): add = numpy.add multiply = numpy.multiply C1 = 1.7320508075688772 C2 = 0.4330127018922193 C3 = -0.066987298107780702 C4 = 0.51763809020504137 C5 = 1.9318516525781364 if d1 == None: d1 = numpy.zeros(x.size/2,numpy.Float) s1 = numpy.zeros(x.size/2,numpy.Float) d2 = numpy.zeros(x.size/2,numpy.Float) odd = x[1::2] even = x[:-1:2] multiply(-C1,even,d1) add(d1,odd,d1) multiply(C2,d1,s1) add(s1,even,s1) d2[0] = C3 * d1[-1] multiply(C3,d1[:-1],d2[1:]) add(s1,d2,s1) d2[0] = d1[0] + s1[-1] add(d1[1:],s1[:-1],d2[1:]) multiply(C4,s1,even) multiply(C5,d2,odd) if x.size > 2: alt_D4_Transform(even,s1[0:even.size/2],d1[0:even.size/2],d2[0:even.size/2]) > > It seems to > > me a big help is the ability to fold multiple array operations into a > > single loop, which is optimization a dynamically-typed language like > > Python can't easily make. (It'd require are really smart JIT compiler > > or some concessions in dynamicity.) > > Writing a JIT to compile this kind of stuff is easy. Eh, getting a JIT to do the optimization I spoke of in Python is not easy. It would be relatively easy in a statically typed language. In Python, it'd be tantamount to rewriting a dynamically reconfigurable version of numpy--you'd have to duplicate numpy's complex type-dispatching rules. > My point is that this > is fundamentally bad code, Whoa, there. I realize that for people who prefer functional programming, with their recursively reductionist way of thinking, it might seem as if leaving any sort of reducibility in final result is "fundamentally bad", but that's a pretty strong thing to say. > so why bother trying to write a Python JIT? Why > not just write in a better language for this task? Optimising within a > fundamentally slow language seems silly to me. Because, for most people, language choice is not a greedy maximizing of a single issue. Nobody who uses numpy is under the impression that it can match a statically-typed language that is compiled to machine code in peak performance. (Matlab is fair game, of course.) But speed is not the only important thing. I use Python because it's a excellently designed language that fits my overall needs, and numpy because sometimes I need more speed than vanilla Python. Only when speed is critical (for example, 3D collision detection) do I write an extension in a "better language for the task" (i.e. C). This is something that's quite popular in the numerically-intensive computing community, BTW. Many people use Python to handle boring stuff like file I/O, memory managment, and non-critical numerical calculations, and write C or Fortran extensions to do the numerically-intensive stuff. Carl Banks From S.Mientki-nospam at mailbox.kun.nl Sat Dec 30 05:56:35 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Sat, 30 Dec 2006 11:56:35 +0100 Subject: Wow, Python much faster than MatLab In-Reply-To: References: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl> <1167449722.106162.93380@k21g2000cwa.googlegroups.com> Message-ID: <1fe24$459645d0$d443bb3a$6599@news.speedlinq.nl> > > I'm not sure about SciPy, Yes SciPy allows it too ! but lists in standard Python allow this: > >>>> array = [1, 2, 3, 4] >>>> array[2:50000] > [3, 4] > > That's generally a good thing. > You're not perhaps by origin an analog engineer ;-) cheers, Stef Mientki From skip at pobox.com Thu Dec 7 09:03:05 2006 From: skip at pobox.com (skip at pobox.com) Date: Thu, 7 Dec 2006 08:03:05 -0600 Subject: dict.has_key(x) versus 'x in dict' In-Reply-To: <024f01c719d3$deff0fc0$03000080@hendrik> References: <4tnvstF14cki5U1@mid.individual.net> <17783.32458.730462.8403@montanaro.dyndns.org> <024f01c719d3$deff0fc0$03000080@hendrik> Message-ID: <17784.7961.898760.712605@montanaro.dyndns.org> >> I will admit that way back when (maybe 8 yrs ago) I actually did this >> in a piece of frequently executed code that's been stable for a >> looong time. I have no idea why I might have written it that way. >> Brain fart I suppose. I only noticed my mistake a couple months ago >> during a trip into the containing function for some other stuff. >> Man, was I embarrassed... Hendrik> why? - the main point is actually that the code worked, and was Hendrik> stable - that should make you proud, not embarrassed. that Hendrik> there is far too much emphasis on doing things the quickest way Hendrik> - as long as it works, and is fast enough, its not broken, so Hendrik> don't fix it... That's the rub. It wasn't fast enough. I only realized that had been a problem once I fixed it though. Skip From george.sakkis at gmail.com Fri Dec 22 17:05:48 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 22 Dec 2006 14:05:48 -0800 Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166807792.176011.170950@h40g2000cwb.googlegroups.com> <1166819094.554972.89360@48g2000cwx.googlegroups.com> Message-ID: <1166825148.058212.58390@a3g2000cwd.googlegroups.com> John Machin wrote: > Peter Wang wrote: > > Bruno Desthuilliers wrote: > > > > > > Python is dynamic, and fighting against the language is IMHO a really > > > bad idea. The only places where theres a real need for this kind of > > > stuff are when dealing with the "outside world" (IOW : inputs and > > > outputs). And then packages like formencode can do much more than mere > > > type-checking > > > > > > > I don't think proper use of type checking is "fighting against the > > language". The goal of any language is to enable programmers to > > express their intent in a form that executes correctly. > > > > Python is extremely expressive but there is a trade-off with > > correctness - you can easily say something that you don't mean. Unit > > testing is sometimes sufficient, but it can never span the infinite > > space of potential errors. Type-checking method signatures guarantees > > a certain amount of low-level correctness, and most type-checking > > mechanisms also serve as documentation aids. > > > > I think that with a sufficiently sophisticated type checking syntax, > > one can get the best of both worlds. If the type checker understood > > interfaces (like PyProtocols) and its syntax had the flexibility to > > indicate sets of allowed arguments and aggregates of allowed > > types/interfaces, it would cover the majority of cases without limiting > > expressive power. > > > > I understand that we're all adults, but it's still nice to have the > > computer tell us when we're being childish. :) > > Your comments on the following cut-down and disguised version of a > *real-world* example would be appreciated: > > @accepts(object, (int, float)) > def tally(self, anobj): > self.total += anobj > > I assure you that the comments of a caller whose code did this: > fubar.tally(someobj) > and got this: > AssertionError: arg 12345678901L does not match (, > ) > are definitely *not* repeatable in front of the children. I guess this is not the 'accepts' decorator of the typecheck module; with that you'd rather write it as @accepts(Self(), Number) and prevent this error (http://oakwinter.com/code/typecheck/tutorial/methods.html). I have also a very recent real-world example to share, from the other side of the fence this time. It's even worse because it's an error that passes silently. Cut-down version follows: @cherrypy.expose def retrieve(self, **kwds): queries = kwds['q'] rows = self._selectRows(*queries) # more stuff 'q' here is a multiselect field that is binded to a list of selected strings. Or so I thought, until someone noticed bizarre results in some cases. Turns out that if you select a single item from the select box, 'q' is binded to a string instead of a list of length 1, so instead of retrieving 'apple', she got back the results for 'a', 'p', 'p', 'l','e'. Bottom line, type checking is a tricky business. In some sense it's similar to the recall/precision tradeoff in information retrieval. With stricter type checking, you can increase the precision but may hurt the recall, i.e. valid code is rejected, as in your example. And vice versa, loosing up the type checks increases the recall but may hurt the precision, as in my example. George From gagsl-py at yahoo.com.ar Thu Dec 7 07:04:07 2006 From: gagsl-py at yahoo.com.ar (gagsl-py at yahoo.com.ar) Date: 7 Dec 2006 04:04:07 -0800 Subject: Embedded python adding variables linking to C++-Variables / callbacks In-Reply-To: <1165488494.074166.169240@79g2000cws.googlegroups.com> References: <1165488494.074166.169240@79g2000cws.googlegroups.com> Message-ID: <1165493047.575426.274630@j72g2000cwa.googlegroups.com> iwl ha escrito: > I would like to add Variables to my embedded python which represents > variables from my > C++-Programm. > I found C-Api-funcs for adding my C-Funcs to python but none to add > variables. > I would like some C-Function is called when the added Python-varible is > set (LValue) and > some other when it is read (RValue). Can I do this. > May be I have to do this in python and call the C-Funcs from a python > callback. Write some C functions -callable from Python- which will be used to get and set the variable value. >From inside Python, declare a property with getter and setter which will call your C functions. This works fine for object attributes. If you want to trap references to local or global "variables", I think you could provide customized dictionaries for locals and globals, but I'm not sure if it works really. -- Gabriel Genellina From hg at nospam.org Sun Dec 10 09:00:04 2006 From: hg at nospam.org (hg) Date: Sun, 10 Dec 2006 08:00:04 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: Bill Atkins wrote: > Steven D'Aprano writes: > >> On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote: >> >>> if Common Lisp didn't have CLOS, its object system, I could write my own >>> as a library and it would be just as powerful and just as easy to use as >>> the system Common Lisp already provides. Stuff like this is impossible >>> in other languages. >> >> Dude. Turing Complete. Don't you Lisp developers know anything about >> computer science? > > Of course, but you have to realize that Turing-completeness is a > useless concept when comparing languages. C and Python are both > Turing-complete. So: write me some code in each that reads in a line > of text, splits it on spaces and stores the result in an array. Which > would you rather write? Which will be shorter and more easily changed > and straightforwardly grasped in the future? > > QED. Turing-completeness is irrelevant when comparing languages. > Take it as a given. Lisp ? ;-) From kentilton at gmail.com Sat Dec 9 23:45:12 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 23:45:12 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> Message-ID: Steven D'Aprano wrote: > On Sat, 09 Dec 2006 22:06:29 -0500, Ken Tilton wrote: > > >>As I type each right parens I eyeball >>its partner as the editor highlights it to make sure I have not missed >>anything, > > > Er, weren't you one of the people claiming that you don't notice parens > when you're reading or writing Lisp code? Steve, you seem to be doing everything you can to make what is basically a decent cultural exchange unpleasant, mostly by bellowing like some mad rogue elephant over and over again about macros, now by trying to play gotcha. I said they disappear. They do. I do not see parens when I look at code. The "watching of the matching" is only after furious thrashing during refactoring, and even then it is unconscious most of the time because we are usually also indenting as we go. I presume you look to see if your indentation is correct while you are indenting, with no more effort than I eyeball the highlighted parens. You think that some gotcha is somehow going to miraculously reveal that I do in fact have trouble with parentheses? Now /that/ would be dumb of you. >> So, if you're still seeing parentheses, does that mean you've been coding > Lisp for less than a month? I see you figured it our for yourself. Obviously I love parentheses and would hate to program without them, so obviously your gotcha falls short. I myself am simply delighted. I decided I should indeed check out if I was up against the c.l.p village idiot. Nope, turns out you are the Master of FUD: http://www.itwire.com.au/content/view/7359/53/ "According to Steven D'Aprano, operations manager of longstanding open source services firm Cybersource, Microsoft's new game of attempting to strike fear into the heart of Linux users by invoking the spectre of patent infringements may soon take an ominous new twist. Mr D'Aprano believes that Microsoft may well use similar tactics employed by its proxy the BSA six years ago when it raided the offices of guitar string maker Ernie Ball with armed marshalls and found a few machines with non-compliant software." I love it, you turning FUD on the FUDster, MS. Good for you! A whole article with nothing but your unsubstantiated guesses as to Microsoft suing someone! I do not who impresses me more, you giving such an interview or the reporter who printed it... no, you guys are allowed to screw up, the editor should be shot. Hey, Steve, save that crap for Microsoft, will you? peace. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From rurpy at yahoo.com Mon Dec 4 19:49:05 2006 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: 4 Dec 2006 16:49:05 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165264641.125857.85980@80g2000cwy.googlegroups.com> <1165270969.942437.302020@n67g2000cwd.googlegroups.com> Message-ID: <1165279745.267190.288060@80g2000cwy.googlegroups.com> Robert Kern wrote: > rurpy at yahoo.com wrote: > > I saw no posts where there OP insulted anybody without being > > insulted first. It is ironic the Mr. Kern was the most consistent > > insulter while at the same time accusing the OP of rudeness. > > As I said, insult is in the ear of the listener, so I apologize if anyone > construed my comments as insults. However, facts are facts, and I stated them as > I believe them. If you can pick out the precise comments that you felt were > insulting, I will be happy to attempt clarifying them in a way that you do not > find insulting. Facts? As I explained in another post, "encouraging" someone to submit a patch without a clue about the poster's abilities or resources is offensive. > "begging for a fix on comp.lang.python is ..." I didn't see the OP "begging" for anything. >"His suggestion that his time is worth more than that of anyone else..." again (as the OP pointed out) no such claim was made. > "and yes, you are being incredibly rude and insulting" By responding in kind? I thought he was quite restrained given the provocation. > "The way that you have been acting..." Funny, I thought he was posting to c.l.p. Sounds like he is a petulant 6 year old child. In virtually every one of your posts you said things that I certainly would have been offended by. > "You're also missing that *I'm trying to help you*" I hope you understand that I'm trying to help *you*? You don't need to bother clarifying, your meaning is clear. It was the insulting tone you (and some others) expressed that meaning in, while attacking the OP for being "rude" that I found grossly unfair. From roger.miller at nova-sol.com Fri Dec 8 20:23:52 2006 From: roger.miller at nova-sol.com (Roger Miller) Date: 8 Dec 2006 17:23:52 -0800 Subject: wx.Font.GetPointSize returning bogus value? Message-ID: <1165627432.068619.275330@79g2000cws.googlegroups.com> The following program gets a TextCtrl's text attributes and sets them back unchanged. However it reports that the font size is 124, and after resetting the attributes the text becomes that size. That is, the window displays a normal-size "foo" and a gigantic "bar". Anyone know what's going on? This is WxPython 2.6 on Python 2.5 on Windows XP. ---------------------------------- import sys import wx class MyApp (wx.App): def __init__ (self): wx.App.__init__(self, redirect=0) def OnInit (self): top = wx.Frame(None, size=(500, 300)) txt = wx.TextCtrl(top, -1, "foo\n", (-1, -1), (400, 200), wx.TE_RICH|wx.TE_READONLY|wx.TE_MULTILINE) top.Show() attrs = wx.TextAttr() txt.GetStyle(0, attrs) font = attrs.GetFont() print "font face", font.GetFaceName() # prints MS Shell Dlg 2 print "font family", font.GetFamily() # prints 74 print "font size", font.GetPointSize() # prints 124! txt.SetDefaultStyle(attrs) txt.AppendText("bar\n") return True app = MyApp() app.MainLoop() From gagsl-py at yahoo.com.ar Tue Dec 12 17:16:28 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 14:16:28 -0800 Subject: Forking in windows. Possible? In-Reply-To: <1165949756.863476.57870@73g2000cwn.googlegroups.com> References: <1165949756.863476.57870@73g2000cwn.googlegroups.com> Message-ID: <1165961788.703215.312810@j72g2000cwa.googlegroups.com> dakman at gmail.com ha escrito: > I know under mac/*nix it's possible to fork the proccess to the > background and exit the parent process. I have used this on a couple of > my projects, but right now I am working on a project that will be > required to run in the background, I have considered using the .pyw > extension on my files, but there will be parts of the program that will > be required to show the console. So if anyone has an ideas... The usual way for Windows background processes that need user interaction, is to provide an icon in the Taskbar Notification Area (next to the clock). You can look at the win32gui_taskbar demo in the pywin32 package. -- Gabriel Genellina From bdesth.quelquechose at free.quelquepart.fr Mon Dec 18 15:45:14 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 18 Dec 2006 21:45:14 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7xejqx2wjb.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <1165593283.523163.71730@16g2000cwy.googlegroups.com> <457b3ca2$0$28520$3b214f66@tunews.univie.ac.at> <457f1b8c$0$7962$426a74cc@news.free.fr> <1166116337.983471.298630@16g2000cwy.googlegroups.com> <7xwt4ui3jk.fsf@ruckus.brouhaha.com> <45866ea7$0$20302$426a74cc@news.free.fr> <7xejqx2wjb.fsf@ruckus.brouhaha.com> Message-ID: <4586f821$0$13484$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: > >>Strictly speaking, only first-class functions are required, and >>tail-recursion optimisation is only an implentation detail. Now it's >>obvious that when it comes to real-life-size programs, this is a >>*very* important detail !-) > > > I don't buy this. Fine - I'm not trying to sell it !-) > One of my favorite quotes about specifications > (http://www.sgi.com/tech/stl/drdobbs-interview.html): > (snip). From a purely logical POV, the fact that a stack implementation has constant-time access or not is totally irrelevant (real-time problems set aside). This doesn't mean it's not important in practice. From tim at bytesmith.us Sat Dec 30 12:03:25 2006 From: tim at bytesmith.us (Tim Smith) Date: Sat, 30 Dec 2006 12:03:25 -0500 Subject: PEP 3107 Function Annotations for review and comment In-Reply-To: <1167492896.292605.15040@48g2000cwx.googlegroups.com> References: <1167492896.292605.15040@48g2000cwx.googlegroups.com> Message-ID: <1167498205@www.bytesmith.us> here's a potentially nifty way of adding decorators to input args for python: def a(int(arg1), arg2, tuple(arg3)): #arg1 is an int (or was converted to an int) #arg2's type is not known (ie this decoration is optional) #arg3 is a tuple (may have been a list coming in, but is now a tuple) pass this would add optional conversion of input arguments to desired types (you could drop the parens, making it more like standard type syntax, but I put them there to intone that the int() method will be called on every arg1 coming in, and so on) this would also add ability to write your own conversion functions to handle type checking as arguments come into a function should add little to no overhead (as you are likely doing this manually like so if desired: def a(arg1, arg2, arg3): arg1 = int(arg1) arg3 = tuple(arg3) pass addendum: any type conversion method should throw ValueError on failure (this would allow python to catch this error and throw a new exception (InputArgError) or something so this: def a(int(arg1), arg2, tuple(arg3)): pass would more or less translate to this: def a(arg1, arg2, arg3): try: arg1 = int(arg1) arg3 = tuple(arg3) except ValueError: raise InputArgError("what went wrong") pass it would likely be desired to create some extra builtin functions like: convdict, convlist, convtuple, that if input is already this type, will return the input unmodified, (as opposed to calling a constructor on dict, list, tuple to create a whole new object (copying all the data)) another nice side effect of this is it adds the ability to call by value instead of by reference: def a(list(b)): pass #call by value def a(convlist(b)): pass #call by reference (unless input type wasn't list) -- Tim -- On 12/30/06 "John Roth" wrote: > BJ??rn Lindqvist wrote: > > On 12/29/06, Tony Lownds wrote: > > > Rationale > > > ========= > > > > > > Because Python's 2.x series lacks a standard way of annotating a > > > function's parameters and return values (e.g., with information about > > > what type a function's return value should be), a variety of tools > > > and libraries have appeared to fill this gap [#tailexamp]_. Some > > > utilise the decorators introduced in "PEP 318", while others parse a > > > function's docstring, looking for annotations there. > > > > > > This PEP aims to provide a single, standard way of specifying this > > > information, reducing the confusion caused by the wide variation in > > > mechanism and syntax that has existed until this point. > > > > I think this rationale is very lacking and to weak for such a big > > change to Python. I definitely like to see it expanded. > > > > The reference links to two small libraries implementing type checking > > using decorators and doc strings. None of which to seem to be very > > popular in the Python community. Surely, those two libraries *alone* > > can't be enough of a motivation for this? To me, it is far from > > self-evident what purpose function annotations would serve. > > > > I also wonder why a very obtrusive syntax addition is needed when it > > clearly is possible to annotate functions in today's Python. Why is > > syntax better than just adding a function annotation decorator to the > > standard library? > > > > @annotate(a = int, b = dict, c = int) > > def foo(a, b, c = 5): > > ... > > > > Are decorators too ugly? > > > > -- > > mvh Bj??rn > > The problem I have with it is that it doesn't solve the problem > I've got, and I can see some user requests to use it rather than > the metadata solution I've got now in Python FIT. Neither do > decorators, by the way. > > So, what are the problems I see? > > First, it only handles functions/methods. Python FIT needs > metadata on properties and assignable/readable attributes > of all kinds. So in no sense is it a replacement. Parenthetically, > neither is the decorator facility, and for exactly the same reason. > > Second, it has the potential to make reading the function > header difficult. In the languages I'm familiar with, static type > declarations are a very few, somewhat well chosen words. > In this proposal, it can be a general expression. In Python > FIT, that could well turn into a full blown dictionary with > multiple keys. > > Third, it's half of a proposal. Type checking isn't the only use > for metadata about functions/methods, classes, properties > and other objects, and the notion that there are only going to > be a small number of non-intersecting libraries out there is > an abdication of responsibility to think this thing through. > > I should note that there are quite a few packages out there > that use some form of annotation, be they comments > (like Ned Bachelder's coverage analyzer and the two > lint packages I'm aware of), docstrings, decorators or > auxilliary dictionarys (like Python FIT, and a possible > Python version of Naked Objects). They include a > fair number of documentation packages. > > On a positive note, what I'd like is something similar to > Java's Javadoc, but a bit looser. It could be a comment > convention like Javadoc, but one that the compiler recognizes > and stashes in the compiled .pyc / .pyo file. Or it could have > different syntax. What is SHOULDN'T have is a mandatory tie > to function/method syntax. > > Combined with a convention to identify which annotation > belongs to who, it could be a quite useful mechanism. > I, for one, have no difficulty with the notion of using someone > else's annotations if I can identify them unambiguously. > > John Roth > Python FIT > > -- > http://mail.python.org/mailman/listinfo/python-list From roth at ursus.net Sat Dec 2 12:56:05 2006 From: roth at ursus.net (Carl D. Roth) Date: Sat, 02 Dec 2006 17:56:05 -0000 Subject: converting dict to object References: Message-ID: <12n3fhl4d1pep35@corp.supernews.com> On Fri, 01 Dec 2006 17:48:40 -0800, rieh25 wrote: > If I have a dictionary such as: > > d = {'a' : 1, 'b' : 2} > > is there a way to convert it into an object o, such as: > > o.a = 1 > o.b = 2 Rather, the question could be asked the other way around: how can you convert that object into a dict? The attributes in 'o' are part of its '__dict__' attribute, which is a dictionary. That is, o.a = 1 is equivalent to o.__dict__['a'] = 1 If you already have a dictionary 'd', you can overlay it onto the object's attributes with o.__dict__.update(d) Carl From mensanator at aol.com Sun Dec 3 21:07:16 2006 From: mensanator at aol.com (mensanator at aol.com) Date: 3 Dec 2006 18:07:16 -0800 Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165194171.257951.89040@j44g2000cwa.googlegroups.com> Message-ID: <1165198036.545819.77820@79g2000cws.googlegroups.com> John Machin wrote: > James Stroud wrote: > > Russ wrote: > > > Every Python programmer gets this message occasionally: > > > > > > IndexError: list index out of range > > > > > > The message tells you where the error occurred, but it doesn't tell you > > > what the range and the offending index are. Why does it force you to > > > determine that information for yourself when it could save you a step > > > and just tell you? This seems like a "no-brainer" to me. Am I missing > > > something? > > > > > > > I think you have a point. I am curious to see how far people are willing > > to go to defend this omission. It promises to be entertaining. > > > > Add "Syntax Error: invalid syntax" to the list ... But at least if you're using IDLE, the point of syntax error is highlighted. When I was a programmer, I thought as a programmer, I spake as a programmer and I understood as a programmer. But when I became a User, I put away such childish things. From kermit at polaris.net Wed Dec 6 18:41:04 2006 From: kermit at polaris.net (kermit at polaris.net) Date: 6 Dec 2006 15:41:04 -0800 Subject: True Division in Python Message-ID: <1165448464.077200.128340@n67g2000cwd.googlegroups.com> For a long time,, There has been a discussion of trueFor division versus integer division in Python. I myslef prefer that / be used for integer division since almost always, I want the result of the division be truncated to integer. However, today I reviewed the method to be used in Python to get true division, and this gave me an idea how true division could be implemented without interferring with the use of / for integer division. Use / for integer division single slash is the operator for integer division. Use ./ for true division. period slash is the operator for true division. Kermit < kermit at polaris.net > From johnjsal at NOSPAMgmail.com Mon Dec 4 11:53:45 2006 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Mon, 04 Dec 2006 11:53:45 -0500 Subject: Inheritance doesn't work In-Reply-To: References: Message-ID: <45745286$0$32597$c3e8da3@news.astraweb.com> zefciu wrote: > class MandelbrotImage (Image): > pass > I am getting the following error: > File "mandelimage.py", line 3, in ? > class MandelImage (Image): How do you get that error with that code? From pavlovevidence at gmail.com Thu Dec 7 00:41:59 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 6 Dec 2006 21:41:59 -0800 Subject: per instance descriptors In-Reply-To: <45777908_4@mk-nntp-2.news.uk.tiscali.com> References: <45777908_4@mk-nntp-2.news.uk.tiscali.com> Message-ID: <1165470119.056918.295240@80g2000cwy.googlegroups.com> Simon Bunker wrote: > Hi I have code similar to this: > > class Input(object): > > def __init__(self, val): > self.value = val > > def __get__(self, obj, objtype): > return self.value > > def __set__(self, obj, val): > # do some checking... only accept floats etc > self.value = val > > class Node(object): > > a = Input(1) > b = Input(2) > > I realise that a and b are now class attributes - however I want to do this: > > node1 = Node() > node2 = Node() > > node1.a = 3 > node2.b = 4 > > And have them keep these values per instance. However now node1.a is 4 > when it should be 3. [snip] > Is there any way of doing this nicely in Python? The easiest way is to store the value in a hidden attribute of the object. For instance: class Input(object): def __init__(self,default,name): self.default = default self.name = name # or, create a name automatically def __get__(self,obj,objtype): return getattr(obj,self.name,self.default) def __set__(self,obj,value): setattr(obj,self.name,value) class Node(object): a = Input(1,"_a") b = Input(2,"_b") Carl Banks From RichardTRMurphy at yahoo.com Thu Dec 14 01:44:56 2006 From: RichardTRMurphy at yahoo.com (rich murphy) Date: 13 Dec 2006 22:44:56 -0800 Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> Message-ID: <1166078696.227746.165750@j72g2000cwa.googlegroups.com> Ben Finney wrote: > "rich murphy" writes: > > > I am studying Python language. > > Welcome! Allow me to direct you to the Python tutorial: > > > > Please take the time to work through all the exercises in that > document, understanding each one before moving on. > > I recommend this because: > > > I placed the the script called "python_script" in C:\Python25 > > directory where all the other Python files are. > > you would not make this mistake if you had already worked through the > tutorial. The tutorial says: "For instance, use your favorite text editor to create a file called fibo.py in the current directory with the following contents:" So, I assumed "the current directory" is C:\Python25 which did not work. Then I placed the fibo.py file in C: director. That did not work either. What directory does it mean then? > > Enjoy! > > -- > \ "On the other hand, you have different fingers." -- Steven | > `\ Wright | > _o__) | > Ben Finney From python at hope.cz Mon Dec 4 03:42:44 2006 From: python at hope.cz (Lad) Date: 4 Dec 2006 00:42:44 -0800 Subject: Video stream server In-Reply-To: References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> <1165218527.632366.290350@j44g2000cwa.googlegroups.com> Message-ID: <1165221764.002660.197600@16g2000cwy.googlegroups.com> Fredrik, Thank you for your reply > > but I think you're missing the point; you need to provide more > information about your specific requirements than just "a HTML > page that links to a video file". like, say, in what way this > is related to Python, what software you're using today, what > kind of videos we're talking about, etc. The most important thing now is how to add a support for video files. As to kind of videos, it is not too much important because I can allow user to upload/play a certain kinds of videos only or transform some kinds of videos into the correct types > what way this is related to Python, I love Python so I would like to implement video support in Python. That is how it is related to Python only L. > > From mail at microcorp.co.za Tue Dec 19 00:02:22 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 19 Dec 2006 07:02:22 +0200 Subject: How to replace a comma References: <1166446034.406136.225770@80g2000cwy.googlegroups.com> <1166454742.875876.263190@73g2000cwn.googlegroups.com> Message-ID: <012301c72330$d272f4e0$03000080@hendrik> "Lad" top posted: > > re's are a pain. Do this instead: > > > > >>> s = "hello, goodbye,boo" > > >>> s.replace(', ',',') > > 'hello,goodbye,boo' > > >>> _.replace(',',', ') > > 'hello, goodbye, boo' > Thank you for ALL for help. > Hendrik, > your solution works great but > what is `_` in > _.replace(',',', ') > > for? The underscore, in the interactive interpreter, stands for the result of the last statement. So in the above, you can think of it as the "name" of the string without spaces after the commas, on the previous line. Note that to fix pathological stuff like: s = "asasd, oipuopioiu, this is bad shit,\tiuiuiu,,, , " you will have to do more work than the simple solution above... I am constantly amazed by how different we all are, when I read the diverse solutions to such a seemingly simple problem - and the nice thing is that they all work... Have a good look at Peter Otten's solution - try to understand it - it uses most of the very useful Python functions. - Hendrik From sjmachin at lexicon.net Fri Dec 22 02:50:47 2006 From: sjmachin at lexicon.net (John Machin) Date: 21 Dec 2006 23:50:47 -0800 Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166741966.242087.192390@n67g2000cwd.googlegroups.com> <1166767205.559937.185260@f1g2000cwa.googlegroups.com> Message-ID: <1166773847.368709.299960@48g2000cwx.googlegroups.com> George Sakkis wrote: > John Machin wrote: > > Bruno Desthuilliers wrote: > > > > > > > > Python is dynamic, and fighting against the language is IMHO a really > > > bad idea. The only places where theres a real need for this kind of > > > stuff are when dealing with the "outside world" (IOW : inputs and > > > outputs). And then packages like formencode can do much more than mere > > > type-checking > > > > > > > Agreed. The worst case I have seen: > > > > An elaborate decorator (similar to the OP's) laboriously checks arg > > types. That's IMHO not "consenting adults" territory. But it gets a > > whole lot worse when it's applied to a method whose body is like this: > > > > if isinstance(.... > > action_for_type1(... > > # big snip > > elif isinstance(... > > action_typeN( ... > > # no else statement > > Ouch.. someone must have skipped his/her OO class... Quite possibly :-) but that's not the problem here. The method in question might be called say emit_generic(self, any_type_of obj) and so one bunch of isinstance calls is actually needed, but not two bunches. So: lose the decorator and add an else and a raise at the end. There is a secondary problem: annoying the crap out of callers who often know what type they have and want an emit_real which would take an int, a long, or a float and an emit_strg and ... (yes, almost all the possible types are that simple) which wouldn't go through even one chain of isinstance calls. From http Sat Dec 9 20:51:36 2006 From: http (Paul Rubin) Date: 09 Dec 2006 17:51:36 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165701024.138305.241500@j72g2000cwa.googlegroups.com> <1165710753.495406.26740@j72g2000cwa.googlegroups.com> Message-ID: <7x1wn81psn.fsf@ruckus.brouhaha.com> "tac-tics" writes: > I think the lesson here is that LISP is the language you use when you > want mathematical elegance and perfection and Python is the language > you use if you want to actually program stuff. That's really a misperception. Lisp is extremely pragmatic in addition to traditionally having more mathematically oriented developers and users. There is a saying that Lisp is a ball of mud; you can throw whatever you want into it and it's still Lisp. Python's current implementations and the supposedly fancy Python applications that I've heard of are toys compared to what's been done in Lisp even on the much smaller machines of decades gone by. What I'd say is that the most interesting period of Lisp development was probably the 1970's and 1980's, trailing off into the beginning of the 1990's. Since then Lisp has gotten kind of stultified, although one of the cll posters claims there's now a revival going on (maybe true). It seems to me that many Lisp users and developers moved on to the ML family in the 1990's and maybe have been moving from ML to Haskell in more recent times. From theller at ctypes.org Fri Dec 1 14:33:03 2006 From: theller at ctypes.org (Thomas Heller) Date: Fri, 01 Dec 2006 20:33:03 +0100 Subject: good documentation about win32api ?? In-Reply-To: References: <1164988151.675036.308920@j44g2000cwa.googlegroups.com> <1164995768.963594.206030@73g2000cwn.googlegroups.com> Message-ID: krishnakant Mane schrieb: > On 1 Dec 2006 09:56:09 -0800, olsongt at verizon.net wrote: > >> http://msdn.microsoft.com covers the API itself, although you need to >> transliterate from the C code to python. > Exactly! that's where the problem lyes. > I am pritty well to do with windows API, I am an a good python > programmer, but I can't find the link between the two. > there are modules but no good documentation. > krishnakant. Maybe then ctypes is the right thing for you? Thomas From fredrik at pythonware.com Thu Dec 14 11:24:22 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 17:24:22 +0100 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: Nick Maclaren wrote: > In the same place you put the subscription method, clearly. which is? From wconnery at dodo.com.au Mon Dec 4 06:34:56 2006 From: wconnery at dodo.com.au (William Connery) Date: Mon, 04 Dec 2006 22:34:56 +1100 Subject: Monitoring number of smtp bytes sent through python e-mail socket Message-ID: <1165232096.3152.4.camel@localhost.localdomain> Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an e-mail with an attachment. I want to give users an indication of the percentage of the e-mail that has already been sent so as to avoid frustration when dealing with large attachments or a slow smtp server. But the smtplib module doesn't seem to provide access to the number of bytes that have already been sent. Can anyone help, or provide a working example of sending an e-mail attachment using basic python sockets whilst having access to the number of bytes that have already been sent through the socket? Many thanks. William Connery -------------- next part -------------- A non-text attachment was scrubbed... Name: smtp_sockets.py Type: text/x-python Size: 7909 bytes Desc: not available URL: From surekap at gmail.com Tue Dec 12 13:10:05 2006 From: surekap at gmail.com (Prateek) Date: 12 Dec 2006 10:10:05 -0800 Subject: How can I get involved In-Reply-To: <1165867719.421812.101400@l12g2000cwl.googlegroups.com> References: <1165856767.477175.276380@80g2000cwy.googlegroups.com> <1165867719.421812.101400@l12g2000cwl.googlegroups.com> Message-ID: <1165947003.417815.256590@l12g2000cwl.googlegroups.com> Hey everyone... Thanks a million for the warm welcome. Not sure WHY I haven't posted before (although I have been lurking for a few weeks). I guess I've been learning via practice and other random documentation online. In case anyone is interested, the url of my organization is http://www.brainwavelive.com There isn't too much technical documentation there yet, but more is coming soon - I promise. Let me know if anyone wants to participate. There are a couple of sub-projects which we're open sourcing which we'll put up soon. In the meantime, I had an interesting project I thought some of you may be interested in... I've been checking out Jython and I've been kinda disappointed to see nothing released in a while (so I'm eager to see what comes next). In the meantime, I need a way to access my database server (written in Python) from Java. Since the server process uses Pyro for IPC and I don't want to switch to XML (purely because of the overhead), I thought it might be fun to write something in Java. So I've started work on an Unpickler in Java. I'll post again soon with the URL (haven't uploaded it yet). If anyone is interested, email me. Prateek Paul Boddie wrote: > I find it interesting that you've been using Python for so long and yet > haven't posted to this group before. Have you been participating in > other forums or groups? I suppose this shows how big the community is, > and that comp.lang.python is just the tip of the iceberg. > > Anyway, welcome! :-) > > > Key points: > > 1) It comes with a non-relational schema-free database we designed > > 2) The application server is based on CherryPy > > 3) The UI engine is XSLT based (but it also supports Cheetah and > > Clearsilver via plugins - out of the box) > > I get along fairly well with XSLT, so this sounds rather interesting. > > > Basically, I really love the language and I'm looking for ways to get > > involved in the community and contribute. > > There are so many things you can do that it's hard to describe them > all. If you're free to contribute to open source projects, you might > choose some that interest you, or which might benefit the work you do > in your day job, and contribute some effort to those projects. > Alternatively, you could start your own interesting projects and share > them with us. Perhaps you want to help other people to understand > Python or its libraries, and you could decide to write some > documentation or some "how to" documents or guides. If you're really > enthusiastic, you could help the core developers with developing > CPython, but if you're more of a Java person then perhaps the > developers of Jython might appreciate the help a bit more. > > > My past (pre-Python) experience has been mainly in web-technologies - > > Java, PHP, ASP and a little bit of C. > > > > Any ideas? > > The python.org Wiki gives a few starting points, based on what I've > written above: > > http://wiki.python.org/moin/FrontPage > > It's a bit of a mess, unfortunately, despite some of us trying to keep > some areas reasonably tidy, but if you dive in and look around you'll > probably find something to inspire you. If not, just tell us and we'll > try and suggest something. ;-) > > Paul From mail at microcorp.co.za Fri Dec 8 00:40:41 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 8 Dec 2006 07:40:41 +0200 Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165503981.646812.320720@j72g2000cwa.googlegroups.com> Message-ID: <027101c71a93$413426c0$03000080@hendrik> \ "Istvan Albert" wrote: > what should happen if by accident one uses a 50Mb string as an index? > Should it be displayed? It is my opinion that yes, the first 40Mb or so should be displayed, as a lesson to the perpetrator, and to help him find the error. Displaying 50 Mb is obviously ridiculous. - Hendrik From pavlovevidence at gmail.com Tue Dec 26 19:42:10 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 26 Dec 2006 16:42:10 -0800 Subject: How to depress the output of an external module ? In-Reply-To: <1167179054.176478.254090@42g2000cwt.googlegroups.com> References: <459117EE.6070205@gmail.com> <1167179054.176478.254090@42g2000cwt.googlegroups.com> Message-ID: <1167180130.305664.184120@a3g2000cwd.googlegroups.com> Carl Banks wrote: > fdu.xiaojf at gmail.com wrote: > > After some trials I found that put "os.close(1)" before calling the > > function will depress the output. In fact, "os.close(1)" closed > > standard output, but I don't know how to open it again after the function's > > execution. > > Try this: > > fd = os.dup(1) > os.close(1) > sys.stdout = os.fdopen(fd) Also, right after closing file descriptor 1, you might want to set it to something so as to eliminate an annoying warning message when Python tries to close it upon termination but finds it already closed. This opens /dev/null and puts it in file descriptor 1 if not there already (the fdz != 1 test might be unnecessary; I don't know if all flavors of Unix always use the lowest available file descriptor). fdz = os.open("/dev/null",os.O_WRONLY) if fdz != 1: os.dup2(fdz,1) os.close(fdz) Carl Banks From metawilm at gmail.com Thu Dec 14 14:01:40 2006 From: metawilm at gmail.com (Willem Broekema) Date: 14 Dec 2006 11:01:40 -0800 Subject: CLPython (was Re: merits of Lisp vs Python) In-Reply-To: <1166048301.513012.245480@73g2000cwn.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <7xejr5y755.fsf@ruckus.brouhaha.com> <1166038096.200379.286830@80g2000cwy.googlegroups.com> <1166048301.513012.245480@73g2000cwn.googlegroups.com> Message-ID: <1166122900.477201.316320@73g2000cwn.googlegroups.com> Paul Boddie wrote: > What would it take to get Python people more interested in it? I've > been monitoring the site [1] and the mailing list [2] for some time, > but nothing particularly visible seems to be happening. Well, judging from the reactions on blogs to the initial announcement here, quite some people have heard about it and seem interested. But that didn't result in more people hacking on it, which is unfortunate. I guess in part it's because there are not that many people really into both Python and Lisp, and those who are might not find this an interesting project because there is nothing "wow" to show, yet. So you are right about the project silence. Right now it's a one-person pet project, and progress is slow. But I'm already quite happy about the current state: stable, usable, and fairly complete. As for more exposure: I'd prefer to wait with big announcements until there are really interesting things achieved. Thanks a lot for your interest and comments! - Willem From kibleur.christophe at gmail.com Fri Dec 15 06:56:55 2006 From: kibleur.christophe at gmail.com (Tool69) Date: 15 Dec 2006 03:56:55 -0800 Subject: need clarification with import statements In-Reply-To: <1166150391.600161.12920@l12g2000cwl.googlegroups.com> References: <1166133185.363843.120090@80g2000cwy.googlegroups.com> <1166150391.600161.12920@l12g2000cwl.googlegroups.com> Message-ID: <1166183815.309984.286310@f1g2000cwa.googlegroups.com> Hi John, > 1. Your directory/package hierarchy is far too complicated. Flatten it. Ok. > 2. You have circular references: the others module will import from > utils, but utils wants to import from others. This is prima facie > evidence that your modules are not structured properly Yes, that's why I asked the question in fact, circular references are a bit hazardous. >. Rule 1: Modules should contain /related/ classes and functions. > Rule 2: A graph of what imports what should not have loops. > > Consider combining others and utils -- does that make sense? Yes, I can combine them as they need eachother. > Another alternative: split out those "some functions of myutils.py (ie > myutils_func1 and myutils_func2)" into a fourth module. This module > might be the nucleus of a tool-kit of miscellaneous functions that you > might import in /any/ app -- in that case, move it outside the current > package. Good idea indeed, Thanks for all, 6TooL9 From __peter__ at web.de Thu Dec 14 03:13:48 2006 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Dec 2006 09:13:48 +0100 Subject: Sorting Multidimesional array(newbie) References: <20061211193104.40fe7985.tartifola@gmail.com> <1165863508.967414.70350@73g2000cwn.googlegroups.com> <1165907463.624180.7990@79g2000cws.googlegroups.com> <1166083031.343359.63620@j72g2000cwa.googlegroups.com> Message-ID: Brian Mills wrote: >> but using a compare function instead of a key mapper is not good advice, >> in general. brief discussion here: >> http://effbot.org/pyfaq/i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python > Is this mostly because of the stability problem described here: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 ? Or is > it more a performance issue due having to make so many function calls? http://docs.python.org/lib/typesseq-mutable.html """Starting with Python 2.3, the sort() method is guaranteed to be stable.""" So performance it is. It is also often simpler once you get used to it and start seeing the pattern def mycmp(a, b): return cmp(mykey(a), mykey(b)) in many of your custom comparison functions. Peter From gh at gregor-horvath.com Tue Dec 26 04:12:11 2006 From: gh at gregor-horvath.com (Gregor Horvath) Date: Tue, 26 Dec 2006 10:12:11 +0100 Subject: Can Python help? In-Reply-To: <1167113417.061901.287410@73g2000cwn.googlegroups.com> References: <1167113417.061901.287410@73g2000cwn.googlegroups.com> Message-ID: Lad schrieb: > On my website I allow users to upload files. I would like a user to see > how much time is left before a file is uploaded. So, I would like to > have a progress bar during a file uploading. Can Python help me with > that?Or how can be a progress bar made? > Thank you for ideas. > La. > http://docs.turbogears.org/1.0/FileUploadProgressBar -- Greg From http Sat Dec 9 05:55:49 2006 From: http (Paul Rubin) Date: 09 Dec 2006 02:55:49 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <7xodqdj2dn.fsf@ruckus.brouhaha.com> <457a8251$0$49201$14726298@news.sunsite.dk> Message-ID: <7xk611baoa.fsf@ruckus.brouhaha.com> "Alex Mizrahi" writes: > we can implement Scheme's call-with-current-continuation first :) > it's relatively easy -- just a code walker that coverts everyting into CPS. It's not enough to convert to CPS, you have to be able to actually save the continuation when you switch to another one, so you can go back to the first one later. Maybe I'm missing something but I just don't see how to do that in the Lisp execution model. I guess you could write an interpreter in Lisp that simulates it all, but it might as well be a Python interpreter ;-). From david at boddie.org.uk Wed Dec 6 16:32:47 2006 From: david at boddie.org.uk (David Boddie) Date: 6 Dec 2006 13:32:47 -0800 Subject: I'm looking to learn pyqt References: <1165435536.605407.112930@79g2000cws.googlegroups.com> Message-ID: <1165440766.847546.306660@16g2000cwy.googlegroups.com> vj wrote: > Is there a a tutorial or a sample application I can start with (that > works with qt4 and pyqt4)? PyQt4 is distributed with a set of small examples, mostly ported from the C++ ones supplied with Qt. Other than those, you could take a look at the PyQt and PyKDE Wiki for inspiration: http://www.diotavelli.net/PyQtWiki There's a page on there with a list of existing applications, some of which are based on PyQt4. As always, more helpful advice can be found on the PyKDE mailing list, where PyQt questions are also welcome: http://mats.imk.fraunhofer.de/mailman/listinfo/pykde David From Bulkan at gmail.com Thu Dec 14 18:22:35 2006 From: Bulkan at gmail.com (placid) Date: 14 Dec 2006 15:22:35 -0800 Subject: Password, trust and user notification In-Reply-To: References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> <1165917102.008439.146400@16g2000cwy.googlegroups.com> <1166053509.270409.46390@f1g2000cwa.googlegroups.com> <7.0.1.0.0.20061213210006.04005d80@yahoo.com.ar> <364538570612131644l604930b9l861b94457bc1183@mail.gmail.com> Message-ID: <1166138555.764383.251020@j72g2000cwa.googlegroups.com> Dennis Lee Bieber wrote: > On Thu, 14 Dec 2006 11:44:14 +1100, "Aidan Steele" > declaimed the following in gmane.comp.python.general: > > > While what you said is technically correct, I think you misread their > > original question. They want to send email *from* the Gmail account *to* the > > work account. I suggested that he use Gmail's SMTP server to send the email. > > > The most confusing thing is that is sounds very much like they want > to use the /recipient's/ Gmail account to send email to the > /recipient's/ work email account -- rather than connecting directly to > the recipient's work account mail server. (Of course, it may be that > their own ISP blocks pass-through SMTP -- that's a different matter) -- Ok, everyone now forget that i even asked about connecting to Gmail and sending an email back to the work email, for some reason you guys are not answering my question. Is there any other way (other than email's !) to notify a user of events within a script? Thanks for all the help. Cheers From martin at v.loewis.de Sat Dec 16 18:03:51 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 17 Dec 2006 00:03:51 +0100 Subject: inquiry about installing Python 2.5 In-Reply-To: <1166308594.341370.8580@j72g2000cwa.googlegroups.com> References: <1166308594.341370.8580@j72g2000cwa.googlegroups.com> Message-ID: <45847B57.4060000@v.loewis.de> mirandacascade at yahoo.com schrieb: > If possible, I would like to have both Python 2.4 and Python 2.5 > installed on my workstaiton. I downloaded the .msi for Python 2.5 from > the python.org site. If I run the 2.5 installer, will it give me the > option of keeping Python 2.4 installed on my workstation? Yes; you can run both versions just fine. The only question is which of these gets the .py association: it is the one that gets installed last. You can chose not to update the .py association when installing 2.5, then .py remains associated with 2.4. Regards, Martin From brochu121 at gmail.com Tue Dec 5 15:33:17 2006 From: brochu121 at gmail.com (david brochu jr) Date: Tue, 5 Dec 2006 15:33:17 -0500 Subject: Ensure a variable is divisible by 4 Message-ID: <9583ed900612051233m2cc8ac79x48c880c387a19da4@mail.gmail.com> You can use the modulous "%" to check for a remainder of division. If no remainder is found you know the number is divisible by 4. Ex: x = 111 if x%4 == 0: print "X is divisible by 4" ---------- Forwarded message ---------- From: "John Machin" To: python-list at python.org Date: 5 Dec 2006 11:26:49 -0800 Subject: Re: Ensure a variable is divisible by 4 Paul Rudin wrote: > Max M writes: > > > geskerrett at hotmail.com skrev: > >> Nick Craig-Wood wrote: > >>> geskerrett at hotmail.com wrote: > >>>> I am sure this is a basic math issue, but is there a better way to > >>>> ensure an int variable is divisible by 4 than by doing the following; > >>>> > >>>> x = 111 > >>>> x = (x /4) * 4 > > > > X *= 4 > > > > ;-) > > > > > x=4 > > :) Ensure x is divisible by *any* non-zero integer: x = 0 :-O -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Sun Dec 10 00:03:52 2006 From: sjmachin at lexicon.net (John Machin) Date: 9 Dec 2006 21:03:52 -0800 Subject: ATTRIBUTE ERROR: 'module' object has no attribute 'ssl' In-Reply-To: <1165726783.411321.36430@73g2000cwn.googlegroups.com> References: <1165720787.910338.118940@j44g2000cwa.googlegroups.com> <1165726783.411321.36430@73g2000cwn.googlegroups.com> Message-ID: <1165727032.668846.69920@79g2000cws.googlegroups.com> John Machin wrote: > johnny wrote: > > I am getting the following errors: > > That is *one* error. > > > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in > > _send_output > > self.send(msg) > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send > > self.connect() > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in > > connect > > ssl = socket.ssl(sock, self.key_file, self.cert_file) > > AttributeError: 'module' object has no attribute 'ssl' > > > > Thank You in Advance > > Thanks for what? We can't help you if you don't supply the full > traceback, plus what version of Python you are running, on what > platform [yeah, Windows, but which?] > Plus a copy/paste of the code that you were running, of course. From justask at acme.com Mon Dec 18 02:57:02 2006 From: justask at acme.com (Vincent Delporte) Date: Mon, 18 Dec 2006 08:57:02 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> <4585df6e$0$11500$426a74cc@news.free.fr> <1166419214.377866.82550@f1g2000cwa.googlegroups.com> Message-ID: <0aico21l1gvkquc20r7f21tc36ib0ej2u0@4ax.com> On 17 Dec 2006 21:20:14 -0800, "tleeuwenburg at gmail.com" wrote: >You could write it as a web app, with an executable which launches the >server and points a browser at it. Right, I was thinking of this too, but since the OP was talking of a fat app... >Python GUI work is a bit of a drag, really. One of the worst things >about it, IMHO. But then, it was built for write text-based scripts. I assume someone could take it, and turn it into a GUI-based solution for Windows, but it's probably quite a lot of work, and maybe there just isn't anyone willing to pay for it. It'd be cool, though to be able to just send someone a 10KB GUI Python script and have it run in Windows natively :-) From jan.dries at dcube-resource.be Mon Dec 11 10:39:15 2006 From: jan.dries at dcube-resource.be (Jan Dries) Date: Mon, 11 Dec 2006 16:39:15 +0100 Subject: SSH File Transfer Protocol or SFTP In-Reply-To: <1165850967.059239.109890@j72g2000cwa.googlegroups.com> References: <1165850967.059239.109890@j72g2000cwa.googlegroups.com> Message-ID: <457D7BA3.1010800@dcube-resource.be> Lad wrote: > Is there a module in Python available that I can use for uploading > files via > SFTP (SSH File Transfer Protocol)? > Or do you think that FTP protocol for files uploading is OK? > Thank you for replies > Lad. You probably want Paramiko (http://www.lag.net/paramiko/). It provides extensive support for the SSH protocol, and ships with, among other things, a sample script demonstrating SFTP. Regards, Jan From fredrik at pythonware.com Sat Dec 2 07:58:14 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 02 Dec 2006 13:58:14 +0100 Subject: Python 2.5 bindings for Subversion 1.4.2 on Win32 binary In-Reply-To: <1165062123.881400.55200@n67g2000cwd.googlegroups.com> References: <1165062123.881400.55200@n67g2000cwd.googlegroups.com> Message-ID: patkinson wrote: > Great python Projects like TRAC or DJANGO are the "keys" to a wide > acceptance of python. Making this easy to the final users is (in my > opinion) a survival question for the future of Python. any special reason why you cannot use the *recommended* releases in- stead of playing with bleeding edge development code and "use only if you don't need to interface with subversion" instructions, and then complain when you cannot get it to work? simple instructions for installing Trac 0.10 on Windows can be found here: http://trac.edgewall.org/wiki/TracOnWindows/Rewrite that page contains direct links to Python and Subversion installers, and a "all-in-one" installation scripts that fixes the rest. subversion bindings for Python on Windows can be found here: http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91 From S.Mientki-nospam at mailbox.kun.nl Fri Dec 29 09:43:44 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Fri, 29 Dec 2006 15:43:44 +0100 Subject: probably a stupid question: MatLab equivalent of "diff" ? Message-ID: Does anyone know the equivalent of the MatLab "diff" function. The "diff" functions calculates the difference between 2 succeeding elements of an array. I need to detect (fast) the falling edge of a binary signal. There's derivate function in Python diff, but when you use an binary (true/false) input, it also detects rising edges. Probably a stupid question, but I still have troubles, digging to huge amount of information about Python. thanks, Stef Mientki From Thomas.Ploch at gmx.net Wed Dec 6 07:15:17 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Wed, 06 Dec 2006 13:15:17 +0100 Subject: About the 79 character line recommendation In-Reply-To: References: Message-ID: <4576B455.3080308@gmx.net> Hello, for me the 80 (or 79) char border when writing code is a fundamental rule. Being at University and having to document each project on paper, it is a must do. i.e. I get code from fellow scolars, that have 160 chars per line, and to get that on paper is disgusting, especially in C/C++. So please, stay true to that. And don't forget those, who actually view source code in a terminal. :-) Thomas From eric_brunel at despammed.com Thu Dec 21 07:48:43 2006 From: eric_brunel at despammed.com (Eric Brunel) Date: Thu, 21 Dec 2006 13:48:43 +0100 Subject: an hex number problem References: <1166704431.573516.242830@n67g2000cwd.googlegroups.com> Message-ID: On Thu, 21 Dec 2006 13:33:51 +0100, wrote: > Hello, > I got a number 19968: > > 1. how can I change it to the hex form 0x4e00, '0x%x' % 19968 > 2. and how can I change 0x4e00 to a python unicode character u"\u4e00"? unichr(19968) > thank you! HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From isaac.rodriguez at comcast.net Tue Dec 12 14:17:29 2006 From: isaac.rodriguez at comcast.net (Isaac Rodriguez) Date: 12 Dec 2006 11:17:29 -0800 Subject: One module per class, bad idea? In-Reply-To: <1165916254.499121.62470@73g2000cwn.googlegroups.com> References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> Message-ID: <1165951049.090837.145390@73g2000cwn.googlegroups.com> > Yes, it would be a bad idea. =) Saying it is a bad idea and not explaining why will not help anyone. I would like you to elaborate on why it is a bad idea to have one file per class. Thanks, - Isaac. From bg_ie at yahoo.com Mon Dec 11 09:26:06 2006 From: bg_ie at yahoo.com (bg_ie at yahoo.com) Date: 11 Dec 2006 06:26:06 -0800 Subject: Newbie: Installing packages on windows Message-ID: <1165847166.383476.225700@n67g2000cwd.googlegroups.com> Hi, I'm reading the python tutorials on docs.python.org, but I'm still not sure how install a package. I have downloaded pylint in zip form from www.logilab.org, but I'm unsure what to do with it. The file I wish to test (i.e. the file I have writen myself) is located in C:\Python25\ Hope you can help, Barry. From XX.XmcX at XX.XmclaveauX.com Wed Dec 6 02:48:00 2006 From: XX.XmcX at XX.XmclaveauX.com (MC) Date: Wed, 06 Dec 2006 08:48:00 +0100 Subject: Python Plugin for Web Browser References: <1165389943.093365.20590@80g2000cwy.googlegroups.com> Message-ID: Bonjour ! Pour IE, il y a des exemples de plugins, fournis avec PyWin32. Pour FF (comme pour Opera), je ne sais pas. -- @-salutations Michel Claveau From robin at NOSPAMreportlab.com Sun Dec 3 09:35:31 2006 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sun, 03 Dec 2006 14:35:31 +0000 Subject: Resource cleanup In-Reply-To: <4tg356F131072U1@mid.uni-berlin.de> References: <4572BF6A.6000005@jessikat.plus.net> <4tg356F131072U1@mid.uni-berlin.de> Message-ID: <4572E0B3.8060206@jessikat.plus.net> Diez B. Roggisch wrote: ....... >> >> I have a vague feeling that I came across problems in the past about >> the order in which modules were finalized. > > I'm a bit on unsure ground here - so take it with a grain of salt. > > It is for sure that only executing code will refer to a global - the > mere mention of anything can't possibly create a reference (in python at > least) - consider this simple example: > > import random > > def foo(): > print schroedingers_cat > > if random.random() > .5: > schroedingers_cat = "I'm alive!" > > foo() > yes I guess although foo must know that schroedingers_cat is global it doesn't need to bring it into existence so would fail 50% of the time :) > > So I presume it can very well happen that you will lose a module when > trying to finalize. > > So most probably it is the cleverest solution to make the cleaner as > self-contained as possible, by storing explicit references to things you > might need in the instance itself. But I'm not sure if the transitivity > of dependencies might not kick your ass somewhere anyhow. I think this must be the right approach. Either the resources or the cleaner should hold everything required for cleanup. Probably the resource is the best place. -- Robin Becker From atkinw at rpi.edu Sat Dec 9 14:18:16 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 14:18:16 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: Steven D'Aprano writes: > On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote: > >> if Common Lisp didn't have CLOS, its object system, I could write my own >> as a library and it would be just as powerful and just as easy to use as >> the system Common Lisp already provides. Stuff like this is impossible >> in other languages. > > Dude. Turing Complete. Don't you Lisp developers know anything about > computer science? Of course, but you have to realize that Turing-completeness is a useless concept when comparing languages. C and Python are both Turing-complete. So: write me some code in each that reads in a line of text, splits it on spaces and stores the result in an array. Which would you rather write? Which will be shorter and more easily changed and straightforwardly grasped in the future? QED. Turing-completeness is irrelevant when comparing languages. Take it as a given. From Doug.Fort at gmail.com Thu Dec 14 14:09:19 2006 From: Doug.Fort at gmail.com (Doug.Fort at gmail.com) Date: 14 Dec 2006 11:09:19 -0800 Subject: FYI: Pythons Were the Oldest Gods Message-ID: <1166123359.047736.177440@f1g2000cwa.googlegroups.com> http://scienceblogs.com/insolence/2006/12/pythons_were_the_oldest_gods.php -- Doug Fort, Consulting Programmer http://www.dougfort.com From bdesth.quelquechose at free.quelquepart.fr Sat Dec 23 08:46:46 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 23 Dec 2006 14:46:46 +0100 Subject: Confusion over calling a nested function inside a parent function In-Reply-To: <877iwkdpsb.fsf@pyenos.pyenos.org> References: <877iwkdpsb.fsf@pyenos.pyenos.org> Message-ID: <458d2d6d$0$10071$426a74cc@news.free.fr> Pyenos a ?crit : > [code] You already got the answer - just a pair of stylistic advices: > class WORK: 1/ By convention, ALL_UPPER names denote (pseudo) symbolic constants. The convention for class names is CamelCase. 2/ better to use new-style classes. => class Work(object): ... From bearophileHUGS at lycos.com Thu Dec 28 09:06:19 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 28 Dec 2006 06:06:19 -0800 Subject: __getattr__ possible loop Message-ID: <1167314779.170915.145680@48g2000cwx.googlegroups.com> I have tried this, with Psyco it segfaults, and with Python 2.5 (on Win) hangs the interpreter, is it possible to improve the situation? class T(object): def __getattr__(self, x): dir(self) #import psyco #psyco.full() T().method() (Probably dir calls __getattr__). Bye, bearophile From fhaibach at polychromix.com Wed Dec 6 16:29:04 2006 From: fhaibach at polychromix.com (fhaibach at polychromix.com) Date: 6 Dec 2006 13:29:04 -0800 Subject: advice on stripped down python Message-ID: <1165440544.475062.295250@n67g2000cwd.googlegroups.com> I'm looking for advice on a stripped down Python for an SBC to run Numpy and Scipy. I have the following notes on the system We have code that requires recent versions of Numpy and Scipy. The processor is a Sharp ARM LH7A404 with 32MB of SDRAM. 512 MB flash disk - but 400 MB is reserved for data The OS is Linux only a tty interface is used. Does anyone have a feel as to whether the Python for ARM is a good starting point? What modules can I safely add/strip out? Will Python take more than 5-6 seconds to load? Would it be easier to add needed modules to deeply embedded Python or Pippy? Will old Python releases, like 1.5.x, work with newer Numpy and Scipy? Thanks! a Fred PS. attempted to post on gmane, but not sure if I succeeded. From fabri16 at inwind.it Mon Dec 11 04:57:55 2006 From: fabri16 at inwind.it (fabri16 at inwind.it) Date: 11 Dec 2006 01:57:55 -0800 Subject: sovrascrivere Message-ID: <1165829050.787365.56900@j72g2000cwa.googlegroups.com> ciao.. ho creato i tasti con le immagini def creaImmagine(self): img = tk.PhotoImage(file=self.ico1) b = tk.Button(root, image=img, command=self.allaPressione) b.pack(side='left',padx=25) b.configure (width=80, height=80) b.image = img mi resta solo un problema.. questo metodo viene richamato pi? volte, ma i tasti non vengono sovrasritti bens? aggiunti (a sinistra). come faccio per sovrascriverli? ho provato con destroy, ma finisce che non mi crea neppure l'immagine. oppure senza sovrascriverli mi basterebbe cambiare l'immagine all'interno (ma credo che il modo migliore sia sovrascriverli). ah...prima che mi scordi.. windows e tkinter. grazie fabri From fredrik at pythonware.com Fri Dec 8 02:40:49 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 08 Dec 2006 08:40:49 +0100 Subject: python.org not current In-Reply-To: <1165563043.341472.248270@j44g2000cwa.googlegroups.com> References: <1165563043.341472.248270@j44g2000cwa.googlegroups.com> Message-ID: Norbert wrote: > the python website http://www.python.org/ mentions Version 2.3.6 and > 2.4.4 on the most prominent place. Shouldn't this be changed to 2.5.x ? you're looking at the news section: the 2.3.6 and 2.4.4 maintenance releases were made after 2.5 was released. From jon at ffconsultancy.com Sun Dec 10 02:25:10 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 07:25:10 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <457bb6f6$0$8713$ed2619ec@ptn-nntp-reader02.plus.net> Steven D'Aprano wrote: > If that's the best example of what macros can be used for, frankly I'm > unimpressed. Yes, I can see some benefit. But I don't see that the benefit > is worth the added complexity. Maybe there are more complex tasks that > macros are better suited for. You both seem to be trying to implement a pattern match. It would probably be productive for you to compare Python and Lisp to languages that have pattern matching. For example, look at the symbolic simplifier here: http://www.ffconsultancy.com/free/ocaml/symbolic.html or the interpreter here: http://www.ffconsultancy.com/free/ocaml/interpreter.html Implementing this kind of stuff in Python is probably a nightmare. At least you can address Lisp's deficiencies with macros... -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From mail at microcorp.co.za Sun Dec 10 04:28:16 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 10 Dec 2006 11:28:16 +0200 Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net><17783.32458.730462.8403@montanaro.dyndns.org><024f01c719d3$deff0fc0$03000080@hendrik><17784.7961.898760.712605@montanaro.dyndns.org><027001c71a93$409575c0$03000080@hendrik> <17786.65173.119568.864197@montanaro.dyndns.org> Message-ID: <029c01c71c3d$c869ace0$03000080@hendrik> wrote: > >>>>> "Hendrik" == Hendrik van Rooyen writes: > > Hendrik> wrote: > Hendrik> - as long as it works, and is fast enough, its not broken, so > Hendrik> don't fix it... > > >> That's the rub. It wasn't fast enough. I only realized that had > >> been a problem once I fixed it though. > > Hendrik> LOL - this is kind of weird - it was working, nobody > Hendrik> complained, you fiddled with it to make it faster, (just > Hendrik> because you could, not because you had to, or were asked to), > Hendrik> it became faster, and then, suddenly, retrospectively, it > Hendrik> became a problem ???? > > No, I think you misunderstand. I was poking around in that function for > other reasons, saw the "k in d.keys()" and realized that the wrong way to > write it. Rewrote it and noticed the performance increase. What's so weird > about that? Nothing wrong with that - it is meet and good to make improvements as you spot them - what seemed weird to me was not that you made the change, but that you described it as a problem, retrospectively - why I say this, I expect, is that in my mind, such a definition would list as a "problem" all working code that could, by rummaging around in it, be improved in some way. I suspect that such a definition would condemn almost *all* production code to problem status... I just don't see it that way - my attitude, I suppose, is a wimpy one, as I think that working code in production use should be left alone, as every time you touch it, there is a finite non zero probability that you will do something stupid to break it, and the breakage may be subtle, and undiscovered for a while, and then it will really be a problem... So the weirdness for me was that you called a piece of perfectly good working code a problem, just because it was faster after you fixed it, even though you had no prior knowledge of the offending line that was doing the right thing, albeit slowly. - I would only have called such a piece of code a problem if I had been inundated with prior requests to fix the slow-running dog... I dunno if all this makes any sense - and we are getting way off topic. :-) - Hendrik From lists at webcrunchers.com Mon Dec 4 14:27:51 2006 From: lists at webcrunchers.com (John Draper) Date: Mon, 04 Dec 2006 11:27:51 -0800 Subject: Python spam? In-Reply-To: <02a401c71513$282936a0$03000080@hendrik> References: <02a401c71513$282936a0$03000080@hendrik> Message-ID: <457476B7.20508@webcrunchers.com> Hendrik van Rooyen wrote: >"Aahz" wrote: > > > >>Anyone else getting "Python-related" spam? So far, I've seen messages >>"from" Barry Warsaw and Skip Montanaro (although of course header >>analysis proves they didn't send it). >>-- >> >> > >not like that - just the normal crud from people giving me get rich quick tips >on the stock market that is aimed at mobilising my money to follow theirs to >help influence the price of a share... > >- Hendrik > > > > I'm ALWAYS getting python spam.... but what worries me, is the spammers Know my personal home address, and I NEVER EVER fill out any forms pages with my personal info - I think I'm being harrassed by hackers or something... John From jeff_barish at earthlink.net Mon Dec 18 18:46:06 2006 From: jeff_barish at earthlink.net (Jeffrey Barish) Date: Mon, 18 Dec 2006 16:46:06 -0700 Subject: Using DCOP from Python Message-ID: The package python-dcop makes it possible to use DCOP from Python. Does anyone know of a tutorial for this package or an example of its use? I would like to use it to read a journal entry in Korganizer. I got as far as figuring out that DCOP offers the interface korganizer.CalendarIface.openJournalEditor(QString text, QDate date) but I'm having trouble figuring out how to call this function from Python. And will it become clear how to control whether I am reading or writing the journal? -- Jeffrey Barish From whumeniu+anti+spam at telus.net Fri Dec 15 10:23:06 2006 From: whumeniu+anti+spam at telus.net (Wade Humeniuk) Date: Fri, 15 Dec 2006 15:23:06 GMT Subject: merits of Lisp vs Python In-Reply-To: <7x7iwtjk3a.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > > "nif" is even cleaner in Haskell, if I have this right: > > nif x p z n | (x < 0) = n > | (x == 0) = z > | (x > 0) = p > > All Haskell evaluation is automatically lazy, so no lambdas etc. needed. You can use that style in CL. (defun nif (x p z n) (or (when (< x 0) n) (when (= x 0) z) (when (> x 0) p))) Wade From gherron at islandtraining.com Sun Dec 3 23:54:56 2006 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 03 Dec 2006 20:54:56 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165195429.928771.148400@j44g2000cwa.googlegroups.com> Message-ID: <4573AA20.2070808@islandtraining.com> Russ wrote: >> Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. >> > > Now, that would be rather silly. I would have to familiarize myself > with the code for the Python interpreter, then send a patch to the > maintainers (and hope they notice it in their inboxes), while the > maintainers themselves could probably "fix" the problem in two minutes > flat. No thanks! > > My suggestion is trivial to implement and would benefit every Python > programmer (even if only slightly), so I don't think it is too much to > ask for. > > But with that argument you just perpetuate the problem. It is the way it is because nobody has cared enough to make it different. That error message has certainly never bothered me enough to wish for something different. You may be able to prompt someone into changing it, but if we've gone this long without caring to fix it, then I'd not hold out much hope for that. Python and the whole open source movement is a volunteer effort by people who care enough to contribute. Your contributions would be welcome, but your complaints are likely to be ignored. Gary Herron From nienfeng at multisuns.com.tw Thu Dec 21 02:34:42 2006 From: nienfeng at multisuns.com.tw (nienfeng) Date: Thu, 21 Dec 2006 15:34:42 +0800 Subject: rsync for python? Message-ID: <458A3912.4000003@multisuns.com.tw> Hi, everyone I want to build rsync server that can run in linux and windows, and configure by python. So I'm looking for something like rsync for python. I find rsync.py and pysync. But rsync.py looks like a client mode, it can't be a rsync server, is it? Can pysync be a rsync server? Thanks.... by nienfeng From sandravandale at yahoo.com Thu Dec 21 17:51:15 2006 From: sandravandale at yahoo.com (Sandra-24) Date: 21 Dec 2006 14:51:15 -0800 Subject: Why can't you use varargs and keyword arguments together? Message-ID: <1166741475.082694.223630@a3g2000cwd.googlegroups.com> I've always wondered why I can't do: def foo(a,b,c): return a,b,c args = range(2) foo(*args, c = 2) When you can do: foo(*args, **{'c':2}) Whenever I stub my toe on this one, I always just use the second approach, which seems less readable. As with most things in Python, I've suspected there's a good reason for it. Having just bumped into this one again, I thought I'd ask if anyone knows why the first syntax should not be allowed. This comes up anyplace you need variable arguments and keyword arguments together but don't have the keyword arguemnts in a dict. In this case you are forced to put them in a dict. I don't think anyone would find that to be more readable. Thanks and Merry Christmas, -Sandra From m_tayseer82 at yahoo.com Tue Dec 19 07:55:28 2006 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Tue, 19 Dec 2006 04:55:28 -0800 (PST) Subject: Can a Tkinter GUI check for abort script: In-Reply-To: <00d401c72363$fe468f40$0d7d12ac@kearfott.com> Message-ID: <20061219125528.90534.qmail@web31107.mail.mud.yahoo.com> Michael Yanowitz wrote: > What I am hoping for is a function call I can make, without knowing any > of the GUI objects, I can call from test3.py (or while test3.py is running) > which will refresh the GUI and check for activity such as button presses > on the GUI itself. call w.update_idletasks(). see http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html#update_idletasks > For example, if I just call sleep(), will it do this? No, it won't > Thanks in advance: > Michael Yanowitz You're welcome __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From bj_666 at gmx.net Sun Dec 31 05:45:00 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sun, 31 Dec 2006 11:45:00 +0100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: In , Paul McNett wrote: >> Did you try to open your code files with another editor, which has a >> different length for tabulator chars? It would look quite ugly, I >> guess... > > Actually, no. Everyone can choose their own number of spaces-per-tab and > it'll look right, as long as everyone uses a monospace font. You never tried that with tabs plus additional spaces to line up e.g. arguments that are broken across lines, right? And there are a number of environments where you can't change the length of a tab like email or terminals where code will be displayed from time to time for example as diffs from a version control system. Ciao, Marc 'BlackJack' Rintsch From xscottg at gmail.com Sun Dec 17 23:09:18 2006 From: xscottg at gmail.com (xscottg at gmail.com) Date: 17 Dec 2006 20:09:18 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xhcvtkhlc.fsf@ruckus.brouhaha.com> References: <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <1166412194.206364.73270@f1g2000cwa.googlegroups.com> <7xhcvtkhlc.fsf@ruckus.brouhaha.com> Message-ID: <1166414958.576783.149710@j72g2000cwa.googlegroups.com> Paul Rubin wrote: > xscottg at gmail.com writes: > > Even regarding interupts, I don't see a problem without a solution: > > (with-interupts-and-garbage-collection-disabled > > (poke destination (peek source)) > > It's not just GC or interrupts, it's the possibility of clobbering the > Lisp heap. If the peek/poke addresses are restricted to some i/o > region as Bill suggests, then the above approach may be reasonable. So don't (poke (random) value). That would be obvious to anyone capable of writing a device driver in C or Lisp or Oberon or .... Cheers, -Scott From tactics40 at gmail.com Fri Dec 15 02:35:10 2006 From: tactics40 at gmail.com (tac-tics) Date: 14 Dec 2006 23:35:10 -0800 Subject: skip last line in loops In-Reply-To: References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: <1166168110.660502.92300@j72g2000cwa.googlegroups.com> Try: afile = open(filename) lines = afile.readlines()[:-1] # assigns all except the last element to a list "lines" for line in lines: print line From NutJob at gmx.net Wed Dec 6 09:46:19 2006 From: NutJob at gmx.net (antred) Date: 6 Dec 2006 06:46:19 -0800 Subject: Am I stupid or is 'assert' broken in Python 2.5?? In-Reply-To: References: <1165415689.347819.129680@73g2000cwn.googlegroups.com> Message-ID: <1165416379.784513.51620@16g2000cwy.googlegroups.com> Yeah, it hit me seconds after I had posted my message. =0 Why didn't I think of it during the 30 minutes I spent banging my head against the keyboard going nuts over this 'bug' ... From kkylheku at gmail.com Mon Dec 11 03:45:00 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 11 Dec 2006 00:45:00 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165821773.670192.288860@79g2000cws.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> Message-ID: <1165826700.533496.316280@80g2000cwy.googlegroups.com> Paddy wrote: > Does Lisp have a doctest-like module as part of its standard > distribution? No, and it never will. The wording you are using betrays cluelessness. Lisp is an ANSI standard language. Its distribution is a stack of paper. There isn't a ``standard distribution'' of Lisp any more than there is such a thing of C++. > There are advantages to > doctest being one of Pythons standard modules. There are also advantages in being able to tell idiots who have terrible language extension ideas that they can simply roll their own crap---and kindly keep it from spreading. This is generally what happens in intelligent, mature programming language communities. For instance, whenever someone comes along who thinks he has a great idea for the C programming language, the standar answer is: Wonderful! Implement the feature into a major compiler like GCC, to show that it's feasible. Gain some experience with it in some community of users, work out any wrinkles, and then come back. In the Lisp community, we can do one better than that by saying: Your feature can be easily implemented in Lisp and loaded by whoever wants to use it. So, i.e. don't bother. Lisp disarms the nutjobs who want to inflict harm on the world by fancying themselves as programming language designers. They are reduced to the same humble level as other software developers, because the best they can do is write something which is just optionally loaded like any other module, and easily altered beyond their original design or rejected entirely. Those who are not happy with the lack of worship run off an invent shitty little languages for hordes of newbies, being careful that in the designs of those languages, they don't introduce anything from Lisp which would land them in the same predicament from which they escaped. From david.golden at oceanfree.net Thu Dec 14 04:47:15 2006 From: david.golden at oceanfree.net (David Golden) Date: Thu, 14 Dec 2006 09:47:15 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165991523.013767.224630@73g2000cwn.googlegroups.com> <1165998270.742602.23610@f1g2000cwa.googlegroups.com> <1166002627.186672.183730@73g2000cwn.googlegroups.com> <1166063919.645962.111770@l12g2000cwl.googlegroups.com> Message-ID: William James wrote: > Actually, it's 'among', not 'amongst', except to those who are > lisping, degenerate pansies. > lisping: "amongst" => "amongthpt" ? "amongst" is a fairly common british english variant of "among". > Some pronunciations and usages "froze" when they reached the >? American shore. In certain respects, American English is closer to >? the English of Shakespeare than modern British English is. In certain respects, modern British English is closer to the English of Shakespeare than American English is. In this particular case, in Shakespeare's actual time, we can be pretty sure ([1],[2]) that "parenthesis" meant the inserted parenthetical phrase. I do admit that since the later extension to round brackets themselves is mentioned at link [2] below (and OED) as first appearing in 1715, and given your later british examples, I was Just Wrong to lay sole blame on the americans for it. [1] The Arte of English Poesie by George Puttenham, 1589 http://www.gutenberg.org/etext/16420 Chap. XIII """ [Sidenote: _Parenthesis_, or the Insertour] Your first figure of tollerable disorder is [_Parenthesis_] or by an English name the [_Insertour_] and is when ye will seeme for larger information or some other purpose, to peece or graffe in the middest of your tale an vnnecessary parcell of speach, which neuerthelesse may be thence without any detriment to the rest. The figure is so common that it needeth none example, neuerthelesse because we are to teache Ladies and Gentlewomen to know their schoole points and termes appertaining to the Art, we may not refuse ro yeeld examples euen in the plainest cases, as that of maister _Diars_ very aptly. _But now my Deere_ (_for so my loue makes me to call you still_) _That loue I say, that lucklesse loue, that works me all this ill._ Also in our Eglogue intituled _Elpine_, which we made being but eightene yeares old, to king _Edward_ the sixt a Prince of great hope, we surmised that the Pilot of a ship answering the King, being inquisitiue and desirous to know all the parts of the ship and tackle, what they were, & to what vse they serued, vsing this insertion or Parenthesis. _Soueraigne Lord (for why a greater name To one on earth no mortall tongue can frame No statelie stile can giue the practisd penne: To one on earth conuersant among men.)_ And so proceedes to answere the kings question? _The shippe thou seest sayling in sea so large, &c._ This insertion is very long and vtterly impertinent to the principall matter, and makes a great gappe in the tale, neuerthelesse is no disgrace but rather a bewtie and to very good purpose, but you must not vse such insertions often nor to thick, nor those that bee very long as this of ours, for it will breede great confusion to haue the tale so much interrupted. """ [2] http://www.etymonline.com/index.php?term=parenthesis [3] http://rhetoric.byu.edu/Figures/P/parenthesis.htm From lone_wolf at ureach.com Sat Dec 2 23:02:06 2006 From: lone_wolf at ureach.com (Lone Wolf) Date: Sat, 2 Dec 2006 23:02:06 -0500 Subject: Parsing data from pyserial Message-ID: <200612030402.XAA23229@www23.ureach.com> I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is just a packet header) separated by spaces as follows: M xxx xxx xxx xxx xxx xxx xxx xxx Here is the code I am using (python v24): import serial ser=serial.Serial('com1',baudrate=115200, bytesize=8, parity='N', stopbits=1,xonxoff=0, timeout=1) ser.write("PM 1") #This sets the CMUcam to poll mode for i in range(0,100,1): ser.write("TC 016 240 100 240 016 240\r\n") reading = ser.read(40) print reading components = reading.split() print components ser.close Here is an example output: M 37 79 3 4 59 124 86 25 ['59', '123', '87', '25', 'M', '37', '79', '3', '4', '59', '124', '86', '25', 'M '] M 38 77 3 2 59 124 86 25 ['39', '85', '26', 'M', '38', '77', '3', '2', '59', '124', '86', '25', 'M', '38' , '7'] My problem is that I am trying to get each data point of the packet into a separate variable. Ordinarily, this would be easy, as I would just parse the packet, read the array and assign each element to a variable eg. mx = components[1]. However, that doesn't work here because the original packet and the array that I got from using the split() method are different. If I were to try read the array created in the first example output, mx would be 123 instead of 37 like it is in the packet. In the second example, the array is 85 while the packet is 38. As near as I can figure out, pyserial is reading a stream of data and helpfully rearranging it so that it fits the original packet format M xxx xxx xxx xxx xxx xxx xxx xxx. I would have thought the split() method that I used on original packet (ie the "reading" variable) would have just returned an array with nine elements like the packet has. This is not the case, and I am at a loss about how to fix this. I've searched the archive here and elsewhere with no luck. Any help REALLY appreciated! Wolf :) ________________________________________________ Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag From eric_brunel at despammed.com Fri Dec 22 03:20:49 2006 From: eric_brunel at despammed.com (Eric Brunel) Date: Fri, 22 Dec 2006 09:20:49 +0100 Subject: tkFileDialog closes main application References: <3qadnUMGb7pa6RTYnZ2dnUVZ_tyinZ2d@comcast.com> Message-ID: On Thu, 21 Dec 2006 22:37:37 +0100, James Stroud wrote: > Eric Brunel wrote: >> BTW, why do you create a sub-class of Frame for your application? Why >> not create a sub-class of Tk instead? >> > > The short answer is that inhereting from Frame will allow embedding of > the application in another application. A Tk() can not be embedded like > this. Tk is appropriately instantiated if (and only if) __name__ == > "__main__" here, allowing the App to run as the "main" application here. So I rephrase my question: will this application ever need to be embedded into another one? There are problems with this way of doing things, especially with menus: if you have to define a menu bar, you just can't attach it to a Frame; you have to have a Tk or Toplevel instance. So basically you're stuck: you can't make your application embeddable anymore. So if you actually need to have a graphical component / mega-widget that has a chance to be embedded in something else, sub-classing Frame is the way to go. If you don't, you'll have far less trouble if you sub-class Tk or Toplevel. -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From bjorn.kempen at gmail.com Wed Dec 27 06:17:18 2006 From: bjorn.kempen at gmail.com (buffi) Date: 27 Dec 2006 03:17:18 -0800 Subject: Persistent variables in python In-Reply-To: References: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> Message-ID: <1167218238.659985.128170@42g2000cwt.googlegroups.com> > There is a problem that this trick only works for functions and not for > methods as it assumes that there is a global name through which you can > access the function. I didn't really see any issue with this since methods can store the persistant data from the method inside the class containing it :) /buffi From kairosenthal at tiscali.de Wed Dec 6 07:46:37 2006 From: kairosenthal at tiscali.de (kai rosenthal) Date: 6 Dec 2006 04:46:37 -0800 Subject: Windows: get owner and group of a file Message-ID: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> Hello, with ls -l on windows I get -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile How can I get on windows with a standard python 2.2 (without windows extensions) the information "500" and "everyone" (owner and group)? Also I cannot use popen('ls -l'). With import stat stat_info = os.lstat(myfile) owner = "%-8s" % stat_info.st_uid group = "%-8s" % stat_info.st_gid I get 0 for owner and group. Thanks for your hints, Kai From duncan.booth at invalid.invalid Mon Dec 11 04:48:59 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Dec 2006 09:48:59 GMT Subject: sys.stdin.encoding References: <1165825571.435369.150110@79g2000cws.googlegroups.com> <1165829211.214261.307740@n67g2000cwd.googlegroups.com> Message-ID: aine_canby at yahoo.com wrote: > The call to sys.getdefaultencoding() returns ascii. Since I can enter > the characters ??? on the command line in Pydef/Eclipse doesn't that > mean that the stdin is not ascii? What should I do? > I think that depends on what sort of script you are writing. If it is just something for personal use on a single machine, or if you know that the same encoding is going to be used on all systems where you have this problem, then you could hardwire the encoding to whatever it should be (maybe 'latin1'). If it is to be used across a variety of systems with different encodings then you'll have to figure out some way to find the correct encoding. From DocZ2A at gmail.com Tue Dec 19 02:40:20 2006 From: DocZ2A at gmail.com (Dr. Locke Z2A) Date: 18 Dec 2006 23:40:20 -0800 Subject: trouble getting google through urllib Message-ID: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> So I'm writing a bot in python that will be able to do all kinds of weird shit. One of those weird shit is the ability to translate text from one language to another, which I figured I'd use google translate to do. Here is the section for translation that I'm having trouble with: elif(line[abuindex+1]=="translate"): #if user inputs translate text="" for i in range(abuindex+2, len(line)): #concantenate all text to be translated text=text+"%20"+line[i] t_url="http://translate.google.com/translate_t?text='"+text+"'&hl=en&langpair=es|en&tbb=1" print "url: %s" % t_url #debug msg urlfi=urllib.urlopen(t_url) #make a file object from what google sends t_html=urlfi.read( ) #read from urlfi file print "html: %s" % t_html #debug msg print "text: %s" % text #debug msg This uses urllib to open the url and abuindex+2 is the first word in the string to be translated and line is an array of the message sent to the bot from the server. After this I'll add something to parse through the html and take out the part that is the translated text. The problem is that when I run this the html output is the following (I asked it to translate como estas here): 403 Forbidden
Google    
Error
 

Forbidden

Your client does not have permission to get URL /translate_t?text='%20como%20estas'&hl=en&langpair=es%7Cen&tbb=1 from this server.

Does anyone know how I would get the bot to have permission to get the url? When I put the url in on firefox it works fine. I noticed that in the output html that google gave me it replaced some of the characters in the url with different stuff like the "&" and "%7C", so I'm thinking thats the problem, does anyone know how I would make it keep the url as I intended it to be? From pydecker at gmail.com Thu Dec 21 07:09:54 2006 From: pydecker at gmail.com (Peter Decker) Date: Thu, 21 Dec 2006 07:09:54 -0500 Subject: Stani's Python Editor - questions In-Reply-To: References: <7llko29d3nfg1bmm010js14r4av3ohm2uf@4ax.com> Message-ID: On 12/21/06, Franz Steinhaeusler wrote: > >Does not work for me! I'm getting messages like this: > > > >python:3255): Gtk-CRITICAL **: gtk_container_remove: assertion > >`GTK_IS_TOOLBARcontainer) || widget->parent == GTK_WIDGETcontainer)' failed > >python:3255): Gtk-CRITICAL **: gtk_container_remove: assertion > >`GTK_IS_TOOLBARcontainer) || widget->parent == GTK_WIDGETcontainer)' failed > > Same similar error messages with DrPy. > I would try to update to a higher wxPython version and/or reporting this > to the wxPython user mailing list. FWIW, this has been reported for ages on the wxPython list. It's a bug in the Gtk implementation that generates these scary-looking warnings, but doesn't seem to cause any real problems. -- # p.d. From gagsl-py at yahoo.com.ar Thu Dec 14 18:13:52 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 14 Dec 2006 20:13:52 -0300 Subject: Working w/ Yield In-Reply-To: <20061213113539.27709.qmail@web90309.mail.mud.yahoo.com> References: <20061213113539.27709.qmail@web90309.mail.mud.yahoo.com> Message-ID: <7.0.1.0.0.20061214194731.059a5388@yahoo.com.ar> At Wednesday 13/12/2006 08:35, Javier Subervi wrote: >I'm trying to tweak a script I found here: > >http://zopelabs.com/cookbook/1118667115 > >to get it to do what I want. You didn't say what you want. But lately I've improved my mind reading skills, so I can tell you want to choose an element at random along a Zope hierarchy of objects. >I'm no wizard at Python, much less newfangled tools like yield. I >understand that one cannot use "return" when working with yield, but >I don't understand how to achieve the same result. Here's my code: Just don't use a generator then. If you want to choose one element at random, you will have to know how many of them are, and then choose one of the previously seen elements. Unless you have a huge amount of items, just collect them on a list. You are interested only on "quotes", not Folder items, right? If they're the only thing contained in your Folders: def CollectItems(folder, itemList): dirs = [] objs = folder.objectValues() for obj in objs: if isdir(obj): dirs.append(obj) else: itemList.append(obj) for obj in dirs: CollectItems(obj, itemList) def isdir(obj): return obj.meta_type == 'Folder' def getRandomQuote(self): root = self.restrictedTraverse('/theSite/en-us/Books') quotes = [] CollectItems(root, quotes) num = randrange(len(quotes)) luckyWinner = quotes[num] path = luckyWinner.absolute_url() return path Should work, untested... -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From python at rcn.com Mon Dec 18 03:11:42 2006 From: python at rcn.com (Raymond Hettinger) Date: 18 Dec 2006 00:11:42 -0800 Subject: trees References: Message-ID: <1166429502.182707.160730@j72g2000cwa.googlegroups.com> vertigo wrote: > What library/functions/classes could i use to create trees ? Start with random.seed, login as root, use svn to download the trunk and branches, when Spring arrives, the leaves will fill-in ;-) Or just use lists as Fredrik suggested. Or look at an example in the cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/201423 Raymond From fredrik at pythonware.com Tue Dec 5 03:44:26 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 09:44:26 +0100 Subject: Printing unix Line endings from Windows. In-Reply-To: <1165307391.447055.210020@n67g2000cwd.googlegroups.com> References: <1165247935.679325.242850@80g2000cwy.googlegroups.com> <1165307391.447055.210020@n67g2000cwd.googlegroups.com> Message-ID: Ant wrote: > How can I create my own line endings? I've tried setting os.linesep = > "\n", (and to \x0a). I've tried things like: > > print "xxx yyy \n", > print "xxx uuu \x0a", > filehandle.write("xxx \n") > filehandle.write("xxx \x0a") > > and all of these give me a nice windows-style crlf! > > Surely there must be a way to do this ... endline normalization is done by the file object, on the way out. to switch this off, open the output file in binary mode ("wb"). From chris at simplistix.co.uk Sat Dec 16 09:40:36 2006 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 16 Dec 2006 14:40:36 +0000 Subject: A new text templating system for python! Message-ID: <45840564.7030405@simplistix.co.uk> Hi All, I'm proud to announce that after almost a year's development, the first public release of Twiddler is available! Twiddler is a simple but flexible templating system for dynamically generating textual output. The key features are: - No need to learn a templating language. - As simple as possible while still catering for all possible templating operations. - Configurable input parsing so source can be html, xml, plain text or anything you write an input parser for. - Configurable output rendering so output can be rendered to a unicode string, an email, or anything you write an output renderer for. You can find out more and download from here: http://www.simplistix.co.uk/software/python/twiddler If you wish to ask questions, pass judgement or get help, please do so in the following mailing list: http://groups.google.com/group/twiddler This is the first public release, so I'm looking for help with the following: - Finding anything that should be possible in a templating system but isn't with Twiddler - Packaging it up for easier distribution. I know nothing about eggs, distutils, etc, and so could do with help to package Twiddler so that it can be more easily installed. Finally, here's a couple of quick examples: >>> from twiddler import Twiddler >>> t = Twiddler(''' ...
A title
... ... ''') >>> t['title'].replace('My title') >>> r = t['item'].repeater() >>> for i in range(1,4): ... r.repeat('Item '+str(i),value=i,name=False) >>> print t.render()
My title
>>> from twiddler.input.plaintext import PlainText >>> t = Twiddler('''To: $to ... An item ... ''',input=PlainText) >>> t['to'].replace('John Smith') >>> r = t['item'].repeater() >>> for i in range(1,4): ... r.repeat('Item '+str(i),value=i,name=False) >>> print t.render() To: John Smith Item 1 Item 2 Item 3 Thanks for reading this far, I hope you enjoy it! cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From jon at ffconsultancy.com Mon Dec 4 16:11:10 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 04 Dec 2006 21:11:10 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <1165246753.867457.204270@79g2000cws.googlegroups.com> Message-ID: <45748f97$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> sturlamolden wrote: > I don't agree that slicing is not the best way to approach this > problem. Indeed, the C++ approach can be written very succinctly using slicing: for i=0 to n/2-1 do tmp[i] = dot a[2*i:] h; tmp[i + n/2] = dot a[2*i + 1:] g; where a[i:] denotes the array starting at index "i". > In both NumPy and Matlab, slicing (often) results in calls to > BLAS/ATLAS, which are heavily optimized numerical routines. One can > supply BLAS libraries that automatically exploits multiple CPUs, use > FMA (fused multiply and add) whenever appropriate, and make sure cache > is used in the most optimal way. If the Python were making only a few calls to BLAS then I would agree. However, in order to move as much computation as possible from the interpreted language onto BLAS you have had to call BLAS many times. So the super-fast BLAS routines are now iterating over the arrays many times instead of once and the whole program is slower than a simple loop written in C. Indeed, this algorithm could be written concisely using pattern matching over linked lists. I wonder if that would be as fast as using BLAS from Python. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From sjmachin at lexicon.net Mon Dec 11 23:15:42 2006 From: sjmachin at lexicon.net (John Machin) Date: 11 Dec 2006 20:15:42 -0800 Subject: problem while going through a tutorial In-Reply-To: References: Message-ID: <1165896942.360463.86820@l12g2000cwl.googlegroups.com> Simon Schuster wrote: > I'm new to python, and almost new to programming in general. I'm at > http://www.pasteur.fr/formation/infobio/python/ch04.html in that > tutorial, and my 'count' function (if it's called a function?) isn't > working suddenly. > > >>> x = "fljshfjh" > >>> x > 'fljshfjh' > >>> count(x, 'h') > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'count' is not defined > > I'm not sure what changed, because it used to work. anyhow thanks a lot! > Probably because you omiitted the line from string import * However IMHO your use of a tutorial which: (1) introduces "from some_module import *" as though it is the normal way of doing things From chapter 1: """ Some magical stuff, that will be explained later: >>> from string import * """ That's *bad* magic (2) is still using (outdated) functions in the string module instead of teaching string methods should be discontinued immediately. You may wish to have a look at some of the /other/ tutorials mentioned on this page: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers HTH, John From raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com Sat Dec 16 11:13:38 2006 From: raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com (Raffael Cavallaro) Date: Sat, 16 Dec 2006 11:13:38 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> Message-ID: <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> On 2006-12-16 08:21:59 -0500, Paul Rubin said: > It never occurs to Lisp programmers that Lisp, too, might be a Blub. Of course it does - Thats why we try ocaml and haskell etc. It's just that we don't see the useful features of these languages as being sufficiently useful to compensate for their lack of the ability to easily do syntactic abstractions over a uniform syntax. There's no question that other languages have some features that common lisp does not (and vice versa). Lispers just can't abide being locked into a particular paradigm because a language doesn't have the basic features (macros and uniform syntax) necessary to provide new paradigms for ourselves when needed or wanted. For example, a common lisp with optional static typing on demand would be strictly more expressive than common lisp. But, take say, haskell; haskell's static typing is not optional (you can work around it, but you have to go out of your way to do so); haskell's pure functional semantics are not optional (again, workarounds possible to a limited extent). This requires you to conceive your problem solution (i.e., program) within the framework of a particular paradigm. This lock-in to a particular paradigm, however powerful, is what makes any such language strictly less expressive than one with syntactic abstraction over a uniform syntax. From ptmcg at austin.rr._bogus_.com Tue Dec 26 09:50:46 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 26 Dec 2006 08:50:46 -0600 Subject: Formatting a string to be a columned block of text References: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> Message-ID: <459136c5$0$16985$4c368faf@roadrunner.com> "Leon" wrote in message news:1167135267.746094.188070 at h40g2000cwb.googlegroups.com... > Hi, > > I'm creating a python script that can take a string and print it to the > screen as a simple multi-columned block of mono-spaced, unhyphenated > text based on a specified character width and line hight for a column. > For example, if i fed the script an an essay, it would format the text > like a newspaper on the screen. Text processing is very new to me, any > ideas on how I could achieve a multi-columned text formatter. Are there > any libraries that already do this? > > Thanks and happy holidays! > Leon > Check out the textwrap module, new in 2.3. Here is code to do one- and two-column output. -- Paul gettysburgAddress = """Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth. """.split('\n') import textwrap # wrap text at 50 characters for line in gettysburgAddress: print "\n".join( textwrap.wrap(line,50) ) print # create two columns of text wrappedLines = sum([ textwrap.wrap(line,35) + [''] for line in gettysburgAddress ],[])[:-1] numLines = len(wrappedLines) halfway = numLines/2 twoCol = [ "%-38s%s" % pair for pair in zip(wrappedLines[:halfway],wrappedLines[halfway:]) ] print "\n".join(twoCol) From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Fri Dec 8 13:51:03 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Fri, 08 Dec 2006 19:51:03 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> Message-ID: <4ttqgnF15ld61U1@mid.individual.net> Bill Atkins wrote: > Um, so does that mean that Python couldn't have borrowed other > features? No, but he used this point in direct conjunction with the syntax. At least by my understanding. Regards, Bj?rn Xpost cll,clp -- BOFH excuse #61: not approved by the FCC From rampeters at gmail.com Mon Dec 4 17:15:21 2006 From: rampeters at gmail.com (johnny) Date: 4 Dec 2006 14:15:21 -0800 Subject: Multiple FTP download using Muliti thread In-Reply-To: <1165226193.934418.36660@l12g2000cwl.googlegroups.com> References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> Message-ID: <1165270520.975223.58540@l12g2000cwl.googlegroups.com> Where or What folder does the ftp files get downloaded to? Justin Ezequiel wrote: > import ftplib, posixpath, threading > from TaskQueue import TaskQueue > > def worker(tq): > while True: > host, e = tq.get() > > c = ftplib.FTP(host) > c.connect() > try: > c.login() > p = posixpath.basename(e) > fp = open(p, 'wb') > try: c.retrbinary('RETR %s' % e, fp.write) > finally: fp.close() > finally: c.close() > > tq.task_done() > > if __name__ == '__main__': > q = TaskQueue() > host = 'ftp.microsoft.com' > > c = ftplib.FTP(host) > c.connect() > try: > c.login() > folder = '/deskapps/kids/' > for n in c.nlst(folder): > if n.lower().endswith('.exe'): > q.put((host, n)) > finally: c.close() > > numworkers = 4 > for i in range(numworkers): > t = threading.Thread(target=worker, args=(q,)) > t.setDaemon(True) > t.start() > > q.join() > print 'Done.' From atkinw at rpi.edu Sat Dec 9 18:55:40 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 18:55:40 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165703407.362890.23780@l12g2000cwl.googlegroups.com> <7xirgkpr5p.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Bill Atkins writes: >> Lest anyone interpret that list as exhaustive: http://www.cl-user.net/ > > What have you got for concurrency? How would you write a > multi-threaded web server in Lisp? Multithreading is not a standard part of ANSI CL, but in practice all Lisps (with the major exception of the CLISP implementation) support threading. Hunchentoot is, in fact, a multi-threaded web server written in Lisp. :) There are also others, like AllegroServe and Araneida. There are compatibility layers that smooth over some of these implementation-dependent areas of Common Lisp. Bordeaux-threads is the package that provides a common interface to the different threading implementations: http://trac.common-lisp.net/bordeaux-threads/wiki/ApiDocumentation From webraviteja at gmail.com Thu Dec 28 08:32:35 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 28 Dec 2006 05:32:35 -0800 Subject: Scaling pictures In-Reply-To: <0001HW.C1B960C5006E7E2DF0488648@News.Individual.DE> References: <0001HW.C1B960C5006E7E2DF0488648@News.Individual.DE> Message-ID: <1167312754.991317.76370@n51g2000cwc.googlegroups.com> Kajsa Anka wrote: > I would like some advice, I'm going to build a small app that will, among > other things, scale images so that they can be published on a web site. I've > never done any image processing in python before so I would like to ask what > is the best way of doing this, I will not do anything else than scaling the > images. > > I found the Python Imaging Library but before I dive into that I would like > to know if there is a better way of doing this. Yes. Python Imaging Library (PIL) is the preferred Python way to do this. The example is right in the documentation. http://www.pythonware.com/library/pil/handbook/image.htm from PIL import Image import glob, os size = 128, 128 for infile in glob.glob("*.jpg"): file, ext = os.path.splitext(infile) im = Image.open(infile) im.thumbnail(size, Image.ANTIALIAS) im.save(file + ".thumbnail", "JPEG") From jeff at taupro.com Thu Dec 7 10:12:13 2006 From: jeff at taupro.com (Jeff Rush) Date: Thu, 07 Dec 2006 09:12:13 -0600 Subject: A Call to Arms for Python Advocacy Message-ID: <45782F4D.5060400@taupro.com> As the Python Advocacy Coordinator, I've put up some wiki pages on the Python website for which I'm soliciting ideas, writing and graphics. Some of the material exists scattered about and just needs locating and organizing. http://wiki.python.org/moin/Advocacy First there is a need for whitepapers and flyers - I've put up a list of suggested topics w/notes at: http://wiki.python.org/moin/AdvocacyWritingTasks And there are fields for signing up for specific documents. We also have a page of possible magazine articles if that's more your style: http://wiki.python.org/moin/ArticleIdeas. These works are to be formed into advocacy kits for various audiences. So far we have the following ideas for kits: - College Student's Python Advocacy Kit - IT Department Python Advocacy Kit - University Educator's Python Advocacy Kit - K-12 Educator's Python Advocacy Kit - Research Lab Python Advocacy Kit The table of contents for the various kits can be found at: http://wiki.python.org/moin/Advocacy#AdvocacyKits Did we miss your kit? And what would you include in any of these? Next, we are seeking reusable/retargetable teaching materials, such as those under a Creative Commons license. We need slide presentations and class handouts. Now I know there are a great many slide presentations on the web about Python. I can google them all but we're not looking for just any presentation, we're looking for the best of field. You can find the collection point at: http://wiki.python.org/moin/Advocacy#TeachingMaterials Last, perhaps you can dash off an idea or two for promotional merchandise. This could be the usuals like shirts but also posters, bumper stickers and buttons. What would you like to have? And with what graphics or slogans? We can reuse some of the slogans from the PyCon Slogan Contest, but are there others? Our collection point for promo item ideas is at: http://wiki.python.org/moin/Advocacy/WearablesGadgets All materials will be credited to the authors to the extent possible by the delivery media. Make your mark. Jeff Rush Python Advocacy Coordinator From fumanchu at amor.org Sat Dec 16 11:30:11 2006 From: fumanchu at amor.org (fumanchu) Date: 16 Dec 2006 08:30:11 -0800 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: <1166187115.915310.66810@l12g2000cwl.googlegroups.com> Message-ID: <1166286611.692347.67070@80g2000cwy.googlegroups.com> dyork wrote: > Thanks Gabriel, but when I said "round trip" I really did mean: convert all > the way to string and all the way back again, so your kind advice is not all > that helpful. I need string to get to a non-Python object or a Web page. Then you need two adaptation layers: one between your app and the DB (which you already have) and one between your app and the web page or other user interface. Here's the web adaptation layer I use: http://projects.amor.org/misc/browser/alamode.py Have a look at the coerce_in and coerce_out functions. Robert Brewer System Architect Amor Ministries fumanchu at amor.org From rpw3 at rpw3.org Sat Dec 9 23:30:38 2006 From: rpw3 at rpw3.org (Rob Warnock) Date: Sat, 09 Dec 2006 22:30:38 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165701024.138305.241500@j72g2000cwa.googlegroups.com> Message-ID: John Thingstad wrote: +--------------- | (If you want symbols to be case sensitive and default case to be lower | then most Lisp's allow that, but the ANSI spec dosn't give a standard way.) +--------------- What about (setf (readtable-case *readtable*) :invert)? That's in ANSI. -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From Divyap at amdale.com Tue Dec 19 09:49:21 2006 From: Divyap at amdale.com (Divya Prakash) Date: Tue, 19 Dec 2006 20:19:21 +0530 Subject: FW: [Jython-users] ERROR : parsing xml in jython Message-ID: <20061219144928.766E11E4006@bag.python.org> Hi But I am unable to parse all the nodes of the tree .....especially the subtree of the main tree It displays only the sibling not the subtree Regards Divya -----Original Message----- From: Matthias Berth [mailto:berth at decodon.com] Sent: Tuesday, December 19, 2006 3:18 PM To: Divya Prakash Subject: Re: [Jython-users] ERROR : parsing xml in jython Hi, looks like you have to make an InputSource from the file, like so: from java.io import File, FileReader, StringReader textReader = FileReader(File(filename)) inputSource = InputSource(textReader) dp.parse(inputSource) Hope this helps Matthias Divya Prakash schrieb: > Hi All, > > > > I m facing the problem while parsing xml file .. > > > > My code is :- > > > > > > import sys > > from org.apache.xerces.parsers import DOMParser as dp > > import javax.xml.parsers > > infilename = open("mos.xml","r") > > print infilename > def test(infilename): > > """Parse XML document and show attributes and names. > > """ > > print infilename > > parser = dp() > > print parser > > gh = parser.parse(infilename) > > print gh > > doc = parser.getDocument() > > node = doc.getFirstChild() > > print "Attributes:" > > show_attrs(node) > > print "Names:" > > show_names(node) > From researchbase at gmail.com Fri Dec 8 12:16:04 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Fri, 8 Dec 2006 22:46:04 +0530 Subject: is there a tutorial for creating packages in python? Message-ID: hello all, I have got a lot of sets of functions and classes that do related work. so just like we get python libraries I too need to create such libraries often called packages. I want to put my code to re-use so will create these libraries and put in the site-libs folder. can any one suggest me a good tutorial on line which can teach me to develop python packages and modules and most importantly to put them in libraries? I saw the official python tutorial and I think chapter 6 has quite a bit on that. but not what I could term as some thing complete in knowledge that one needs to create libraries as huge as wxpython etc. thanking all. Krishnakant. From mail at microcorp.co.za Fri Dec 22 23:41:59 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 23 Dec 2006 06:41:59 +0200 Subject: Question about Tkinter windows References: <01b801c7258d$1870a380$03000080@hendrik> Message-ID: <003001c7264c$af950f20$03000080@hendrik> Manuel Malo de Molina wrote in an email: >Hi, thanks for answering. The problem is that the window >can be closed in many ways (including some not >controlled by the program, as the X on the top right), >is there a way to capture the window closing event? Please keep it on the list so that other people can see it later in searches... You should be able to do this with a try ... finally - I don't, however, have any experience of this as I have never used it. Maybe some one else can give a definite answer? - Hendrik From nmm1 at cus.cam.ac.uk Fri Dec 15 15:12:30 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 15 Dec 2006 20:12:30 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> In article <1166187479.167471.169270 at n67g2000cwd.googlegroups.com>, "Tim Golden" writes: |> [Christoph Zwerschke] |> |> > And can somebody explain what is exactly meant with |> > "homogenous data"? |> |> This seems to have been explained a few times |> recently :) Basically, if you have a "list of xs" |> and remove one item from it, it is still a "list of xs", |> where "xs" might be people, coordinate-pairs, numbers |> or whatever made sense to you. If you have a tuple |> containing, say, a 2d coordinate pair, and remove something |> from it, it's no longer a coordinate pair. If you add one to it, |> it's something else as well (perhaps a 3d coord?) Hmm. If I remove an object from a list of objects, does it not remain a list of objects? The converse is worse, as in my example. If a heterogeneous list just happens to have objects that are all similar, does it remain heterogeneous? Loose guidelines are very useful, but should almost always come with the rider "Follow these unless you have good reasons to ignore them, but do make sure that you understand the rules first before deciding your rules are good". Some of the responses here went a little, er, a lot beyond that. Regards, Nick Maclaren. From chris.cavalaria at free.fr Thu Dec 28 05:44:43 2006 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Thu, 28 Dec 2006 11:44:43 +0100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <4593185f$1@nntp.zianet.com> Message-ID: <4593a01b$0$1073$426a74cc@news.free.fr> Steven D'Aprano wrote: > On Thu, 28 Dec 2006 09:26:28 +0100, Sebastian 'lunar' Wiesner wrote: > >> It is, and especially the problems with tabs shows you, why it is good >> practice to follow the standard in your own code, too... > > I don't know what "problems" with tabs you are talking about. I never have > problems with tabs. *Other people* who choose to use software that doesn't > understand tabs have problems. > > I've spent a lot of time reading both sides of the tabs versus spaces > argument, and I haven't found anything yet that explains why tabs are, in > and of themselves, bad. You gave the reason in your post : because other people who are using software that doesn't understand tabs as YOU expect them to have problems with your code. Tabs aren't a problem at all as long as nobody else than you edit your code. From g.tagliaretti at gmail.com Sat Dec 2 21:47:39 2006 From: g.tagliaretti at gmail.com (Gian Mario Tagliaretti) Date: Sun, 03 Dec 2006 03:47:39 +0100 Subject: evaluating gui modules, any experience on tkinter? References: <0qkch.2229$YI1.1130@newsfe15.lga> Message-ID: <4571ffec$0$19245$4fafbaef@reader4.news.tin.it> hg wrote: > Tkinter is fine under *nix and Windows for a large range of applications. > I think it has drawbacks and advantage compared to other toolkits. The > major advantage being bundled with python, and the drawbacks include (I > think) ... look and feel, printing support, imaging, documentation. agreed > Then there are two schools: PyQT and wxPython - you completely forgot pygtk. or you didn't want to mention it :) > both very easy to learn I think that pygtk is the easiest ciao -- Gian Mario Tagliaretti From h0leforfun at gmail.com Mon Dec 18 11:25:21 2006 From: h0leforfun at gmail.com (Hole) Date: 18 Dec 2006 08:25:21 -0800 Subject: Strange error with getattr() function In-Reply-To: <1166455980.365984.296680@l12g2000cwl.googlegroups.com> References: <1166455980.365984.296680@l12g2000cwl.googlegroups.com> Message-ID: <1166459121.661107.251700@73g2000cwn.googlegroups.com> Hole ha scritto: > Hi There! > > I'm trying to use Zope and the product OpenFlow. > > I got the following error while I was using the built-in function > getattr() to retrieve an OpenFlow object: > > attribute name must be string > > > Actually, I surely pass a string as attribute name to getattr() > > The code: > > #following instruction returns me the string "WorkFlowTest" > openflow_id=container.aq_parent.id > > if (hasattr(container,openflow_id): > #the interpreter enter in this block, so > #it's sure that container has an attribute called WorkFlowTest > openflow=getattr(container,openflow_id) > > At this point, I got the error: attribute name must be string > I'm wondering if the exception is raised in a hidden function and not in the explicit call to getattr(). How can I view the traceback in a script running in zope?? From fredrik at pythonware.com Thu Dec 21 16:32:05 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 21 Dec 2006 22:32:05 +0100 Subject: removing the header from a gzip'd string In-Reply-To: <1166735512.435837.60080@42g2000cwt.googlegroups.com> References: <1166735512.435837.60080@42g2000cwt.googlegroups.com> Message-ID: Rajarshi wrote: > Hi, I have some code that takes a string and obtains a compressed > version using zlib.compress > > Does anybody know how I can remove the header portion of the compressed > bytes, such that I only have the compressed data remaining? what makes you think there's a "header portion" in the data you get from zlib.compress ? it's just a continuous stream of bits, all of which are needed by the decoder. > (Obviously I do not intend to perform the decompression!) oh. in that case, this should be good enough: data[random.randint(0,len(data)):] From kkylheku at gmail.com Sat Dec 9 17:59:00 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 9 Dec 2006 14:59:00 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165705140.297282.103460@j72g2000cwa.googlegroups.com> Kirk Sluder wrote: > unnecessary abstraction. The question I have is why do critics > single out macros and not other forms of abstraction such as > objects, packages, libraries, and functions? The answer is: because they are pitiful morons. But you knew that already. From jon at ffconsultancy.com Mon Dec 11 08:24:14 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 11 Dec 2006 13:24:14 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165169117.866499.181520@73g2000cwn.googlegroups.com> <45732974$0$8758$ed2619ec@ptn-nntp-reader02.plus.net> <1165183970.832303.323350@73g2000cwn.googlegroups.com> <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> <1165252920.329341.284910@j44g2000cwa.googlegroups.com> <1165255758.967262.226400@73g2000cwn.googlegroups.com> <1165267711.364076.292000@79g2000cws.googlegroups.com> <457be14b$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <1165766069.028619.284860@80g2000cwy.googlegroups.com> Message-ID: <457d5c9c$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Carl Banks wrote: > Jon Harrop wrote: >> What about translating the current Python interpreter into a language >> with a GC, like MLton-compiled SML? That would probably make it much >> faster, more reliable and easier to develop. > > I doubt it would work too well. MLton-compiled SML's semantics differ > from Python's in subtle ways, and covering the edge cases usually means > you have to do all the stuff you thought you would avoid by using > another dynamically-typed language. Translating MTton-compiled SML > integers to Python ints would work probably 99 percent of the time, but > in the end you'd essentially have to reimplement the Python int type. > > If you're going to go through all that work, you might as well > translate it to C or directly to machine code. That's not what I meant. I was referring to translating the Python _interpreter_ into another language, not translating Python programs into other languages. MLton-compiled SML is especially fast at symbolic manipulation, e.g. interpreters, so it will be probably be as fast or faster than the current Python interpreter. Then you can start boiling the interpreter down, removing the GC for a start because MLton already has a much better GC... -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From steve at REMOVE.THIS.cybersource.com.au Sun Dec 10 12:30:07 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 11 Dec 2006 04:30:07 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: On Mon, 11 Dec 2006 02:51:50 +1100, Steven D'Aprano wrote: > On Sun, 10 Dec 2006 14:21:17 +0000, Kirk Sluder wrote: > >> In article >> , >> Steven D'Aprano wrote: >> >>> Yes. But you can't redefine 1+2 in Python, at least not without hacking >>> the interpreter. Can you redefine (+ 1 2) in Lisp? >> >> Not without barreling through error messages about name conflicts. > > Ah, nice to get a straight answer to a question for a change, and without > an insult or a misrepresentation in sight. Thank you. Such a pity that answer is, apparently, wrong. Thank you to those who wrote back with the more accurate answer, which apparently is "yes, it is easy and there are no error messages". I'd love to say it has been fun, but it has been more frustrating than enjoyable. I don't mind an honest disagreement between people who genuinely are trying to see the other's point of view, but I don't think that was the case here. What was especially frustrating was that the more I tried to understand certain Lispers' positions by asking questions, the more nasty and insulting they became. So now I have an even better understanding for why Lispers have a reputation for being difficult and arrogant. (And believe me, I could say a lot more about that, but I'm trying to be conciliatory, so I'll just shut up now.) But I also gained a little more insight into why Lispers love their language. I've learnt that well-written Lisp code isn't as hard to read as I remembered, so I'd just like to withdraw a comment I made early in the piece. I no longer believe that Lisp is especially strange compared to natural languages. Anyway, real life catches up on me, and so I must drop out of this thread. May it not last for ever. -- Steven. From peonleon at gmail.com Tue Dec 26 07:14:27 2006 From: peonleon at gmail.com (Leon) Date: 26 Dec 2006 04:14:27 -0800 Subject: Formatting a string to be a columned block of text Message-ID: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> Hi, I'm creating a python script that can take a string and print it to the screen as a simple multi-columned block of mono-spaced, unhyphenated text based on a specified character width and line hight for a column. For example, if i fed the script an an essay, it would format the text like a newspaper on the screen. Text processing is very new to me, any ideas on how I could achieve a multi-columned text formatter. Are there any libraries that already do this? Thanks and happy holidays! Leon From simon at brunningonline.net Thu Dec 14 09:13:04 2006 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 14 Dec 2006 14:13:04 +0000 Subject: tuple.index() In-Reply-To: <8c7f10c60612140610k77015147gaca9808c43ef3b9e@mail.gmail.com> References: <1166103409.199435.290670@79g2000cws.googlegroups.com> <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <8c7f10c60612140610k77015147gaca9808c43ef3b9e@mail.gmail.com> Message-ID: <8c7f10c60612140613h1f61d3bci57c41473eb5d3c92@mail.gmail.com> On 12/14/06, Simon Brunning wrote: > Tell that to Guido. They are his arguments. On 2nd thoughts, don't. He has enough on his plate at the moment. ;-) -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From http Sat Dec 16 08:21:59 2006 From: http (Paul Rubin) Date: 16 Dec 2006 05:21:59 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> Message-ID: <7xslfgou14.fsf@ruckus.brouhaha.com> Andr? Thieme writes: > Sounds like "Blub" to me: > http://www.paulgraham.com/avg.html It never occurs to Lisp programmers that Lisp, too, might be a Blub. From mail at microcorp.co.za Thu Dec 7 23:54:40 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 8 Dec 2006 06:54:40 +0200 Subject: Subprocess with a Python Session? References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> Message-ID: <026f01c71a93$3fcc0b40$03000080@hendrik> "Giovanni Bajo" > Fredrik Lundh wrote: > > >> No matter what I do I cant get the following code to do what I expect. > >> I hadn't used subprocess t o read and write to pipes of a > >> still-running app, and I just can't seem to get it right. What gives? > >> > >> import subprocess > >> > >> p = subprocess.Popen("python", stdout=subprocess.PIPE, > >> stdin=subprocess.PIPE) > >> p.stdin.write('print 10\n') > > > > + p.stdin.close() > > > >> assert p.stdout.readline() == '10\n' > > Yeah, but WHY was the API designed like this? Why can't I read and write > freely from a pipe connected to a process as many times as I want? you can - all you have to do is to somehow separate the "records" - else how is the receiving side to know that there is not more data to follow? The simplest way is to use newline as separator, and to use readline() on the receiving side. Or you can use read(1) and roll your own... To make sure the stuff is written from memory on the transmitting side, use flush(), if you want to do many records, or close() as Fredrik said if only one thing is to be transferred. - Hendrik From smh at alum.mit.edu Fri Dec 29 21:32:06 2006 From: smh at alum.mit.edu (Steven Haflich) Date: Sat, 30 Dec 2006 02:32:06 GMT Subject: Anyone persuaded by "merits of Lisp vs Python"? In-Reply-To: <1167357838.969945.15190@48g2000cwx.googlegroups.com> References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> <1167357838.969945.15190@48g2000cwx.googlegroups.com> Message-ID: Ray wrote: > Can one really survive knowing just > one language these days, anyway? ???? ????? From eurleif at ecritters.biz Tue Dec 12 20:41:23 2006 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Tue, 12 Dec 2006 20:41:23 -0500 Subject: YouTube written in Python In-Reply-To: References: Message-ID: <457f58e5$0$27424$4d3efbfe@news.sover.net> Terry Reedy wrote: > In a thread on the PyDev list, Guido van Rossum today wrote: >> And I just found out (after everyone else probably :-) that YouTube is >> almost entirely written in Python. (And now I can rub shoulders with >> the developers since they're all Googlers now... :-) Interesting. I wonder what they're using for a Web framework? Of course, sites that size generally use lots of custom stuff, but it would presumably be based on something. From rzantow at gmail.com Tue Dec 26 12:57:48 2006 From: rzantow at gmail.com (rzed) Date: Tue, 26 Dec 2006 12:57:48 -0500 Subject: Formatting a string to be a columned block of text References: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> <6e42ec490612260702g39630f98q2cae89067b40c6e5@mail.gmail.com> Message-ID: "Dave Borne" wrote in news:mailman.2023.1167146273.32031.python-list at python.org: > Thanks, Paul. I didn't know about textwrap, that's neat. > > Leon, > so in my example change >> data1= [testdata[x:x+colwidth] for x in >> range(0,len(testdata),colwidth)] > to >> data1 = textwrap.wrap(testdata,colwidth) >> data1 = [x.ljust(colwidth) for x in data1] > > oh and I made a mistake that double spaces it. the "print '\n'" > line needs to be either > print '' > or > print '\n', > (with a comma) > The solutions so far serve up text that is split within the confines of the column width, but leave a "ragged right" margin, where the line lengths appear to differ. I had the impression that the OP wanted right-and-left justified text, such as would typically be found in a newspaper column. Here's a shot at doing that for fixed-width fonts. To use it, first split your lines as others have suggested, then print aline(line,colwid) for each line in your data. # aline - align text to fit in specified width # This module arbitrarily chooses to operate only on long-enough # lines, where "long-enough" is defined as 60% of the specified # width in this case. # def aline(line, wid): line = line.strip() lnlen = len(line) if wid > lnlen > wid*0.6: ls = line.split() diff = wid - lnlen #nspaces = len(ls)-1 eix = 1 bix = 1 while diff > 0: # and nspaces > 0: if len(ls[bix]) == 0 or ls[bix].find(' ') >= 0: ls[bix] += ' ' else: ls.insert(bix,'') diff -= 1 bix += 2 if bix >= 1+len(ls)/2: bix = 1 if diff > 0: if len(ls[-eix]) == 0 or ls[-eix].find(' ') >= 0: ls[-eix] += ' ' else: ls.insert(-eix,'') diff -= 1 eix += 2 if eix >= 1+len(ls)/2: eix = 1 line = ' '.join(ls) return line -- rzed From kirk at nospam.jobsluder.net Sun Dec 10 09:35:07 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sun, 10 Dec 2006 14:35:07 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165596641.245385.113090@f1g2000cwa.googlegroups.com> <1165704007.887869.192290@16g2000cwy.googlegroups.com> Message-ID: In article , Steven D'Aprano wrote: > And here I was thinking that languages fell from the sky like donuts! > Gosh, thank you for explaining that too me. What a fool I must seem! Certainly that is what you wrote. If you had not meant that English enforces restrictions on expressiveness, perhaps you should not have written it. > Look, I was arguing a really simple point: for communication to occur > between two individuals, both people must agree on a set of rules for the > language that they use to communicate. If they don't have a common > language with agreed upon rules, communication will be feeble and weak, if > not non-existent, or there will be misunderstandings and errors. No, in that post you are arguing a straw man. In this post you seem to be agreeing with me while acting like you disagree. If we both agree that the rules of languages are social, then we should both agree that in the case of programming language, communities of language users help to constrain how the language is used by rejecting extensions that are not lispy/pythonic, and accepting extensions that converge with accepted style. > No. Your peers or your parents or your editor or your teachers correct > you. Or you get a reputation for being "stupid" and people start treating > you as if you were stupid -- maybe they start talk-ing ver-y slow-ly at > you, using baby words. Or people just find it difficult to communicate > with you, or misunderstand what you are trying to say. And likewise, if you propose a construct that is unlispy/unpythonic, that construct is not likely to be adopted by the community of computer language users. Since you are apparently in complete agreement with the post you dishonestly quoted out of context, I don't see where we have an argument. > Before patronizing me, do make the effort to understand what I am saying. I understand what you wrote. Perhaps your problem is that in your rhetoric zest you chose to dishonestly attack a strawman, and chose to defend a position you now claim not to hold. > Are you man enough to acknowledge your error, or are you going to continue > this ridiculous charade of attacking me for holding views I don't have? I have no way of knowing the views that you have, only the views that you write. And if you don't write what you mean, I have no way of understanding that you are really in agreement with me, when you attack something I did not say. From spedrosa at gmail.com Fri Dec 1 11:51:47 2006 From: spedrosa at gmail.com (Stephen Eilert) Date: 1 Dec 2006 08:51:47 -0800 Subject: python vs java & eclipse In-Reply-To: <1164974627.554596.300240@l12g2000cwl.googlegroups.com> References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com> <1164974627.554596.300240@l12g2000cwl.googlegroups.com> Message-ID: <1164991907.911276.221250@80g2000cwy.googlegroups.com> Amir Michail escreveu: > krishnakant Mane wrote: > > just used the py dev plugin for eclipse. > > it is great. > > But isn't support for java better because the eclipse ide can take > advantage of explicit type declarations (e.g., for intellisense, > refactoring, etc.)? > > Amir The support for Java is light-years ahead. Sometimes I feel that Eclipse is coding for me (quickfix, for instance). There's the fact that Eclipse is developed in Java, so they are eating their own dogfood. That said, the code completion for Python is still in its early stages. There is a lot of room for improvement, even for a dynamic language. Stephen From johnzenger at gmail.com Tue Dec 19 16:05:34 2006 From: johnzenger at gmail.com (johnzenger at gmail.com) Date: 19 Dec 2006 13:05:34 -0800 Subject: What am I supposed to do with an egg?! In-Reply-To: References: Message-ID: <1166562334.101514.36350@t46g2000cwa.googlegroups.com> Type "sudo easy_install myeggfile.egg." If that gives you an error, then you don't have easy_install installed. Install it this way: sudo apt-get install python-setuptools On Dec 19, 3:44 pm, Morpheus wrote: > On Windows I'm used to install packages by setup.py install. So did I with > Fibranet nanothreads - a few seconds and it was installed. > > On Linux (ubuntu 6.06) all I could get at is an egg file. I found out that > I have to exec easy_install, which didn't much help here (seems to me, at > least - sorry, Linux newbie). > > So, what am I supposed to do here now? > > Kind regards > Morpheus From johnjsal at NOSPAMgmail.com Thu Dec 7 12:39:10 2006 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Thu, 07 Dec 2006 12:39:10 -0500 Subject: List of Events in wxPython In-Reply-To: References: Message-ID: <457851a4$0$32622$c3e8da3@news.astraweb.com> Jacksondf wrote: > What is that procedure for determining which events can be binded for a > particular widget? The docs don't seem to help. For example, how can I > know which events wx.SpinButton will send. > > Thanks. Exactly which docs are you looking at? The wxPython docs have a link that lists all the classes, just scroll down to that particular class and it lists the events, like hg posted. From jeffrey at fro.man Mon Dec 25 16:46:15 2006 From: jeffrey at fro.man (Jeffrey Froman) Date: Mon, 25 Dec 2006 13:46:15 -0800 Subject: Unescaping URLs in Python References: Message-ID: <12p0hlongi7d35@corp.supernews.com> John Nagle wrote: > What's the appropriate Python function to call to unescape a URL which > might contain things like that? xml.sax.saxutils.unescape() > Will this interfere with the usual "%" > type escapes in URLs? Nope, and urllib.unquote() can be used to translate URL escapes manually. Jeffrey From http Mon Dec 11 20:21:14 2006 From: http (Paul Rubin) Date: 11 Dec 2006 17:21:14 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165867527.389209.80660@f1g2000cwa.googlegroups.com> Message-ID: <7x64ch7vud.fsf@ruckus.brouhaha.com> "HowiPepper" writes: > With Python's ease of learning and use, availability of a large number > of libraries, extremely active development community and large > user-base, I'd say the question to ask is what specific advantages over > Python does Lisp offer, to make people switch to it? Lisp has a more uniform design geared towards large system development. It doesn't have as many weird quirks and exceptions as Python. It has much more serious implementations with real compilers. There is an inevitability about the way the language works, it's just "cosmic". The only way I can suggest to appreciate that is study an implementation of it sometime. The parentheses really aren't a big deal. Lisp is simply hypnotic, to those receptive to that kind of thing. In musical terms, Python is like a Beatles song, very popular and easy to sway and dance to. Lisp is like a Bach fugue. From fredrik at pythonware.com Fri Dec 22 03:02:45 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 22 Dec 2006 09:02:45 +0100 Subject: Confusion with calling function of a subclass In-Reply-To: <873b78cr6k.fsf@pyenos.pyenos.org> References: <873b78cr6k.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > class TREE: > def gettree(self):print self > TREE.gettree() # I get an error saying > # TypeError: unbound method gettree() must be called > # with TREE instance as first argument (got nothing instead > > I still don't understand how to solve this simple code. what is it supposed to do? what do you expect "self" to be, and where do you expect it to come from ? have you tried adding some expletives, to see if that solves the problem ? From eduardo.padoan at gmail.com Wed Dec 27 13:11:11 2006 From: eduardo.padoan at gmail.com (eduardo.padoan at gmail.com) Date: 27 Dec 2006 10:11:11 -0800 Subject: Persistent variables in python In-Reply-To: References: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> <1167174100.432143.163760@i12g2000cwa.googlegroups.com> Message-ID: <1167243071.384717.294200@a3g2000cwd.googlegroups.com> > That's a matter of taste. Try replacing the try...except block with > hasattr: > > def doStuff(): > if hasattr(doStuff, timesUsed): > doStuff.timesUsed += 1 > else: > doStuff.timesUsed = 1 > do_common_code > Ok, it is a matter of taste and I prefer the try/except way, but with hasattr you will do a function call and a intern 'truthness' verification each time you increment .timeUsed. With try/except, after the first time, you do nothing else than increment it. From sjmachin at lexicon.net Tue Dec 5 20:04:02 2006 From: sjmachin at lexicon.net (John Machin) Date: 5 Dec 2006 17:04:02 -0800 Subject: newb: Join two string variables In-Reply-To: <1165366572.644641.73460@73g2000cwn.googlegroups.com> References: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> <1165366572.644641.73460@73g2000cwn.googlegroups.com> Message-ID: <1165367042.619389.254100@f1g2000cwa.googlegroups.com> johnny wrote: > In my code, I have the following: > > p = posixpath.basename(e).strip > filename = download_dir+p > > I am getting the following error: > > filename = download_dir+p > TypeError: cannot concatenate 'str' and 'builtin_function_or_method' > objects > > You need to *call* the strip method. To see what you've actually done, do this: p = posixpath.basename(e).strip print repr(p) filename = download_dir+p To see what happens when you've fixed the problem, do this: p = posixpath.basename(e).strip() print repr(p) filename = download_dir+p *and* for portability, *don't* use "posixpath", just use "path" HTH, John From salvatore.difazio at gmail.com Fri Dec 1 09:54:37 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 1 Dec 2006 06:54:37 -0800 Subject: I/O Multiplexing and non blocking socket In-Reply-To: References: <1164982048.938862.228890@79g2000cws.googlegroups.com> Message-ID: <1164984877.492407.59770@n67g2000cwd.googlegroups.com> Jean-Paul Calderone ha scritto: > On 1 Dec 2006 06:07:28 -0800, Salvatore Di Fazio wrote: > >Hi guys, > >I'm looking for a tutorial to make a client with a i/o multiplexing and > >non blocking socket. > > > >Anybody knows where is a tutorial? > > http://twistedmatrix.com/projects/core/documentation/howto/clients.html > > Jean-Paul Thank you guys, but I would like to use the standard libraries From jon at ffconsultancy.com Tue Dec 12 10:38:06 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 15:38:06 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <457ecd7a$0$8715$ed2619ec@ptn-nntp-reader02.plus.net> Konrad Hinsen wrote: > Well, then it should also run on my Mac... Do you have any experience > with performance of numerical code under Mono, or, for that matter, > under .NET? I suspect that the JIT compilers were not written with > number crunching in mind, but perhaps I am wrong. Actually, F# seems to be very fast for array-based floating-point calculations. From the timings I gave earlier in this thread, for example, it is between C++ and OCaml. F# (actually .NET) seems to be slower for GC intensive programs, like my ray tracer. I suspect this is because a concurrent GC is inherently slower. I haven't benchmarked this in detail but F# seems to be 2-4x slower than OCaml here. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From kw at codebykevin.com Sun Dec 10 21:31:36 2006 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 10 Dec 2006 21:31:36 -0500 Subject: Tkinter button doesn't appear in OS X In-Reply-To: <1165798158.199702.217180@79g2000cws.googlegroups.com> References: <1165798158.199702.217180@79g2000cws.googlegroups.com> Message-ID: <457CC308.1080801@codebykevin.com> crystalattice wrote: > I'm creating a shelve interface using Tkinter. I have a button that > allows the user to modify an existing entry; when the button is > clicked, a new TopLevel window appears with Entry boxes holding the > selected entry. Below the Entry boxes are two buttons, one that saves > the changes to the database and the other is simply a Cancel button. > > Under Linux, both buttons appear correctly. However, in OS X the > Cancel button is invisible unless the window is resized or you click in > the area where the Cancel button is located. I believe it works > correctly under Windows (it's been a few days since I was able to check > it on a Windows machine). > What version of Tk are you running? I've seen this bug on old versions of Tk (i.e. 8.4.7) but not recently. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From S.Mientki-nospam at mailbox.kun.nl Sat Dec 30 09:24:16 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Sat, 30 Dec 2006 15:24:16 +0100 Subject: Wow, Python much faster than MatLab In-Reply-To: <45966848$0$11868$3b214f66@tunews.univie.ac.at> References: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl> <1167449722.106162.93380@k21g2000cwa.googlegroups.com> <45966848$0$11868$3b214f66@tunews.univie.ac.at> Message-ID: <3acb7$4596767d$d443bb3a$7444@news.speedlinq.nl> Mathias Panzenboeck wrote: > A other great thing: With rpy you have R bindings for python. forgive my ignorance, what's R, rpy ? Or is only relevant for Linux users ? cheers Stef > So you have the power of R and the easy syntax and big standard lib of python! :) From mike.klaas at gmail.com Wed Dec 20 15:53:34 2006 From: mike.klaas at gmail.com (Klaas) Date: 20 Dec 2006 12:53:34 -0800 Subject: using methods base64 module in conjunction with Crypto.Hash.SHA256 In-Reply-To: <1166594309.454654.82110@80g2000cwy.googlegroups.com> References: <1166594309.454654.82110@80g2000cwy.googlegroups.com> Message-ID: <1166648014.843667.35860@73g2000cwn.googlegroups.com> mirandacascade at yahoo.com wrote: > I am attempting to implement a process, and I'm pretty sure that a > major roadblock is that I do not understand the nomenclature. The > specs indicate that the goal is to calculate a message digest using an > SHA-256 algorithm. There are 2 examples included with the specs. The > label on the 2 examples are: 'HMAC samples'. In both examples, the > message on which the digest is to be calculated is (the 33 chars within > the quotes): > > 'This is a test of VISION services' > > In the first example, the value labeled 'Shared key' is the 44 > characters within the quotes: > '6lfg2JWdrIR4qkejML0e3YtN4XevHvqowDCDu6XQEFc=' I doubt it. That is a base64 encoded value, not the value itself. <> > My interpretation of the first example is this: when you use an SHA-256 > algorithm to calculate a message digest on the message 'This is a test > of VISION services' where the key is > '6lfg2JWdrIR4qkejML0e3YtN4XevHvqowDCDu6XQEFc=', This isn't the key, but the base64-encoded key. > the result should be: > 'KF7GkfXkgXFNOgeRud58Oqx2equmKACAwzqQHZnZx9A=' . This isn't the result, but the base64-encoded result. > 2) If the interpretation of the first example is on target, do you see > anything above in the use of the SHA256, HMAC and base64 > classes/methods that indicates that I did not correctly implement the > process? You should base64 decode the key before passing it to the HMAC constructor. -Mike From rampeters at gmail.com Wed Dec 6 21:20:32 2006 From: rampeters at gmail.com (johnny) Date: 6 Dec 2006 18:20:32 -0800 Subject: newb: How to call one modue from other References: <1165450007.504080.327490@80g2000cwy.googlegroups.com> Message-ID: <1165458032.135595.321240@f1g2000cwa.googlegroups.com> johnny wrote: > I have a module called ftp and I have another module called > processKick. What I need is to have processKick, create fork and > execute ftp like below. > > Relevant processKick code as follows: > > def do_child_stuff(): > ftp > > def fork_test(): > pid = os.fork() > if pid == 0: > # child > do_child_stuff() > os._exit(0) > # parent - wait for child to finish > os.waitpid(pid, os.P_WAIT) > Here is my ftp module: import ftplib, posixpath, threading from TaskQueue import TaskQueue def worker(tq): while True: host, e = tq.get() c = ftplib.FTP(host) c.connect() try: c.login() p = posixpath.basename(e) fp = open('H:/ftp_download/' + p, 'wb') try: c.retrbinary('RETR %s' % e, fp.write) finally: fp.close() finally: c.close() tq.task_done() if __name__ == '__main__': q = TaskQueue() #host = 'ftp.microsoft.com' host = 'mysite.com' c = ftplib.FTP(host) c.connect() try: #c.login() c.login() #folder = '/deskapps/kids/' folder = '' for n in c.nlst(folder): if n.lower().endswith('.doc'): q.put((host, n)) finally: c.close() numworkers = 4 for i in range(numworkers): t = threading.Thread(target=worker, args=(q,)) t.setDaemon(True) t.start() q.join() print 'Done.' Can someone also tell me what is the purpose of if __name__ == "__main__": Do I have to call, main of ftp module within processKick? Thank you in advance From adelcoGENE at zeverSKYNET.BE Sat Dec 30 15:51:52 2006 From: adelcoGENE at zeverSKYNET.BE (karel) Date: Sat, 30 Dec 2006 20:51:52 -0000 Subject: find login name of user? References: <1167511677.250618.285250@v33g2000cwv.googlegroups.com> Message-ID: <4596d16b$0$21512$ba620e4c@news.skynet.be> wrote in message news:1167511677.250618.285250 at v33g2000cwv.googlegroups.com... > Is there a function/module to find the login name of the user under > UNIX environment? who who am i finger id From rattan at cps.cmich.edu Sat Dec 30 16:00:14 2006 From: rattan at cps.cmich.edu (rattan at cps.cmich.edu) Date: 30 Dec 2006 13:00:14 -0800 Subject: find login name of user? In-Reply-To: <4596d16b$0$21512$ba620e4c@news.skynet.be> References: <1167511677.250618.285250@v33g2000cwv.googlegroups.com> <4596d16b$0$21512$ba620e4c@news.skynet.be> Message-ID: <1167512414.065895.280560@s34g2000cwa.googlegroups.com> karel wrote: > wrote in message > news:1167511677.250618.285250 at v33g2000cwv.googlegroups.com... > > Is there a function/module to find the login name of the user under > > UNIX environment? > > who > who am i > finger > id I was talking about under python environment. -ishwar From atkinw at rpi.edu Fri Dec 8 21:11:54 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Fri, 08 Dec 2006 21:11:54 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: aahz at pythoncraft.com (Aahz) writes: > I would say that your statement about Lisp syntax is wrong. Not that it > is technically inaccurate, but that it completely misses the point, so > much so that it is wrong to say it. One of the key goals of Python is > readability, and while it is indeed easy to learn the rules for Lisp > syntax, observational experience indicates that many people (perhaps even > the vast majority of people) find it difficult to learn to read Lisp > programs. You see, this is what I meant by "controversy." As much as I'd like to ignore this whole discussion, I will eventually read something like the above and feel compelled to respond, thus ensuring that the thread continues until eventually everyone gives up and we end up....exactly where we started. (thanks again, Mark Tarver) This is a silly claim. What observational experience are you talking about? Lisp is delightfully readable. In fact, I find it more readable than any other language. Why do you think that is? Could it be because I use Lisp on a daily basis? Could that also explain why Python seems more readable than Lisp to you? > As for your claims about speed, they are also nonsense; I doubt one > would find an order of magnitude increase of speed for production > programs created by a competent Lisp programmer compared to programs > created by a competent Python programmer. Nonsense? Hardly. Most Lisp implementations compile to native code, and can take advantage of fifty years of research into making Lisp compile into efficient code. You are correct, though: the difference would probably be a little more than an order of magnitude. > Consider this: Lisp has had years of development, it has had millions of > dollars thrown at it by VC firms -- and yet Python is winning over Lisp > programmers. Think about it. OK, I'm thinking about it. What was supposed to happen? (BTW, which millions are you talking about? The millions that went into the AI boom in the 1980's?) From google at mrabarnett.plus.com Fri Dec 8 19:48:55 2006 From: google at mrabarnett.plus.com (MRAB) Date: 8 Dec 2006 16:48:55 -0800 Subject: Logging output from python In-Reply-To: References: <1165543315.696699.291910@j44g2000cwa.googlegroups.com> Message-ID: <1165625335.025817.188990@n67g2000cwd.googlegroups.com> Gabriel Genellina wrote: > At Thursday 7/12/2006 23:21, Cameron Walsh wrote: > > > > Here is my problem. I want to log everything displayed in the screen > > > after I start the main python script. Things include unhandled > > > exceptions , message from print statement and other sources. > > > Basically, if it is displayed on the screen, I want to log it.. > > > >If it's on linux you can just redirect the screen output to a file: > > > >python initialfile.py 1>stdout.txt 2>stderr.txt > >[...] > > > >As for windows, I'll test it now... > > > >It turns out you can at least redirect the output to a file, I'm not > >sure what it does with standard error or even if it exists or not. > > > >python initialfile.py > output.txt > > It's the same syntax as noted for linux above. 1> is the same as > alone. > > If ALL the testing is done on a single program (that is, no os.system > or spawn or subprocess...) then you could just replace sys.stdout and > sys.stderr with another open file (or file-like) object. > Redirection in Windows is explained here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true From fredrik at pythonware.com Mon Dec 4 14:30:28 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 20:30:28 +0100 Subject: decorators question In-Reply-To: <1165259428.106492.44020@16g2000cwy.googlegroups.com> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> Message-ID: king kikapu wrote: > Hmmm...ok...it calls the decorator but when ?? It (the runtime) loads > the .py file and start to call every decorator you seem to be missing that the interpreter *always* executes the code in a module to find out what it contains. "def" and "class" are exe- cutable statement, not compiler directives. and the decorators are simply called right after the corresponding "def" statement has been executed. From antroy at gmail.com Tue Dec 5 07:08:30 2006 From: antroy at gmail.com (Ant) Date: 5 Dec 2006 04:08:30 -0800 Subject: Printing unix Line endings from Windows. In-Reply-To: <1165309224.097576.66600@79g2000cws.googlegroups.com> References: <1165247935.679325.242850@80g2000cwy.googlegroups.com> <1165307391.447055.210020@n67g2000cwd.googlegroups.com> <1165309224.097576.66600@79g2000cws.googlegroups.com> Message-ID: <1165320510.186512.59070@79g2000cws.googlegroups.com> John Machin wrote: > Ant wrote: ... > > filehandle.write("xxx \n") > > filehandle.write("xxx \x0a") > > > > and all of these give me a nice windows-style crlf! > > > > Surely there must be a way to do this ... > > and there is: open your output file in binary mode; then it won't > convert every \n to \r\n. ... > | >>> '\n' is '\x0a' > | True (and F wrote something very similar.) Cheers guys. Shame that fileinput doesn't take an argument to specify the write mode when 'inplace' is True, because it is otherwise makes editing multiple files in place very simple. Is it worth me submitting a patch to fileinput which can take an optional write mode parameter? Cheers, From anthonybaxter at gmail.com Wed Dec 13 07:48:01 2006 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 13 Dec 2006 23:48:01 +1100 Subject: call of __del__ non-deterministic in python 2.4 (cpython)? In-Reply-To: References: Message-ID: On 12/13/06, Holger Joukl wrote: > I did read this but didn't think it applied to my situation. I'm quite > sure that the refcount of the local variable is 1 before the local scope > is left. > So let me rephrase the question: Even if I can make sure that non of the > problematic situtions apply, might it _still_ happen that __del__ gets > called > after some other code has already been "entered"? You shouldn't rely on __del__ being called exactly when you expect it, particularly in a threaded application. Make explicit cleanup calls, instead. From tiedon_jano at hotmail.com Mon Dec 18 10:48:34 2006 From: tiedon_jano at hotmail.com (Jussi Salmela) Date: Mon, 18 Dec 2006 15:48:34 GMT Subject: How to replace a comma In-Reply-To: <1166454742.875876.263190@73g2000cwn.googlegroups.com> References: <1166446034.406136.225770@80g2000cwy.googlegroups.com> <1166454742.875876.263190@73g2000cwn.googlegroups.com> Message-ID: Lad kirjoitti: > > Thank you for ALL for help. > Hendrik, > your solution works great but > what is `_` in > _.replace(',',', ') > > for? When you are trying things out in the Python shell IDLE, _ is a shorthand way to use the last value printed by IDLE. Thus when s.replace(', ',',') prints out 'hello,goodbye,boo' _ refers to that value so the replace operation _.replace(',',', ') manipulates that value. Cheers Jussi > Thank you > La. > >> re's are a pain. Do this instead: >> >>>>> s = "hello, goodbye,boo" >>>>> s.replace(', ',',') >> 'hello,goodbye,boo' >>>>> _.replace(',',', ') >> 'hello, goodbye, boo' >> Hope this helps - Hendrik > From researchbase at gmail.com Sat Dec 2 00:56:41 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Sat, 2 Dec 2006 11:26:41 +0530 Subject: python vs java & eclips In-Reply-To: <1165008224.116326.36580@79g2000cws.googlegroups.com> References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <45701422.4050206@gmx.net> <1165008224.116326.36580@79g2000cws.googlegroups.com> Message-ID: may be emacs can provide code completion (intellicense) I have not used it so far so can't say. but the main reason I use eclipse is for the above feature. and yes indentation happens in eclipse python-mode so that is not a major feature eclipse offers any way. syntax highlighting is a very common feature again. so if there is an editor which will give me auto code completion, I will happily give up using eclipse. by the way, there is one problem I am finding with eclipse and py dev. the following snippad of code is a mesterious problem. name = raw_input("please identify your self ") if name == "tom": print "hello and welcome" else: print "I don't know you" just run this script and you will find that you always get "I don't know you", even if you entered tom. I then figured out that length of name actually comes to 4 even when I entered tom. that's why it always goes in the else claws. but when I ran the same script from a command promt the length of name returned 3 when tom was entered and the code worked fine. I can't understand why is this happening? why is eclipse putting an extra character in the name variable? Krishnakant. From Holger.Joukl at LBBW.de Wed Dec 13 04:38:18 2006 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Wed, 13 Dec 2006 10:38:18 +0100 Subject: call of __del__ non-deterministic in python 2.4 (cpython)? Message-ID: Hi all, I've recently run into a problem that I haven't seen with python 1.5.2 and python 2.3. It seems that under certain conditions __del__ does not get immediately called when a local variable goes out of scope. I ended up with deadlocks in a threaded application because a locked section was supposed to be entered from within __del__ but apparently the same thread (the main thread, in that case) was already holding that lock. The result looked really strange with the main thread entering the locked section and then suddenly the delayed call of __del__ taking control, also wanting to acquire the lock but never being able to. Unfortunately I fail to put together a minimal example. Anyway: Is relying on __del__ getting called immediately when the refcount drops to 0 a no-no? If so should that maybe be prominently stated in the docs? Cheers, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From fredrik at pythonware.com Sun Dec 3 09:37:54 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 03 Dec 2006 15:37:54 +0100 Subject: cursor.executemany() float error In-Reply-To: <1165155896.161125.186490@j72g2000cwa.googlegroups.com> References: <1165155896.161125.186490@j72g2000cwa.googlegroups.com> Message-ID: progman wrote: > cursor.executemany('insert into promo (`From`,`To`, `RATE`) \ > values (%s,%s,%f)', [ ('AA','BB',10.2), ('CC','DD',10.3) ] ) > > i got this error: > TypeError: float argument required > > i checked, 10.2 & 10.3 , there are at the right loc. > what went wrong?? posting a bit more of the traceback, and mentioning what database you're using might be helpful. have you tried using "%s" markers for all parameters, btw? (SQL data binding and %-style string formatting are two different things, after all). From sable.sungard at gmail.com Wed Dec 13 05:12:53 2006 From: sable.sungard at gmail.com (=?ISO-8859-1?Q?S=E9bastien_Sabl=E9?=) Date: Wed, 13 Dec 2006 11:12:53 +0100 Subject: Sybase module 0.38pre1 released In-Reply-To: References: Message-ID: By the way, I forgot to say that new releases can now be downloaded from this page: https://sourceforge.net/project/showfiles.php?group_id=184050 regards -- S?bastien Sabl? 2006/12/12, S?bastien Sabl? : > WHAT IS IT: > > The Sybase module provides a Python interface to the Sybase relational > database system. It supports all of the Python Database API, version > 2.0 with extensions. > > MAJOR CHANGES SINCE 0.37: > > * This release works with python 2.5 > > * It also works with sybase 15 > > * It works with 64bits clients > > * It can be configured to return native python datetime objects > > * The bug "This routine cannot be called because another command > structure has results pending." which appears in various cases has > been corrected > > * It includes a unitary test suite based on the dbapi2.0 compliance > test suite > From jfabiani at yolo.com Sat Dec 30 14:08:10 2006 From: jfabiani at yolo.com (johnf) Date: Sat, 30 Dec 2006 11:08:10 -0800 Subject: I want to see all the variables References: <45952426.1080800@websafe.com> <8yelh.90$Q4.82@newsfe02.lga> Message-ID: Steven D'Aprano wrote: > > There are three other underscore conventions in use: > > (1) Objects with a single leading underscore like _attribute are private > by convention, but Python doesn't enforce it. Starting an object with a > single underscore is like writing "# Private! Don't touch!" after it. > > (2) By convention, if you want to create a name that is the same as a > built-in object without shadowing (hiding) the built-in, put a single > trailing underscore after it like "file_". That's just a style convention > though, you are free to call it FiLE ,or anything else, if you prefer. > > (3) Last but not least, class attributes with two leading and trailing > underscores are considered special but public, like __init__ and __repr__. > It is probably a bad idea to invent your own. > > > Very detailed. But I was attempting to debug some code which subclassed other code. I got a traceback that something like "no mySubClass.__source.query() did not exist". The superclass had something like "myClass.__source.query(sql)" which worked but "mySubClass.__source.query(sql)" did not work. So I tried to debug using "dir(myClass.__source)" and got an error. And I also got error when I "dir(mySubClass.__source". So how could I have debugged the problem if dir() will not display information on the __source? I hope that explains my issue. Thanks Johnf From uymqlp502 at sneakemail.com Mon Dec 4 15:37:21 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 4 Dec 2006 12:37:21 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> <45745C9E.9050500@v.loewis.de> <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> Message-ID: <1165264641.125857.85980@80g2000cwy.googlegroups.com> Fredrik Lundh wrote: > > Sorry I haven't thought this through 100% > > obviously not. And you didn't like the "tone" of some of my earlier posts? From john.thingstad at chello.no Sat Dec 9 16:29:45 2006 From: john.thingstad at chello.no (John Thingstad) Date: Sat, 09 Dec 2006 22:29:45 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: On Sat, 09 Dec 2006 22:04:04 +0100, mystilleef wrote: > Bill Atkins wrote: >> Are any of these not subjective? > > Objectivity is in the eye of the beholder. > >> Lisp is much more than a functional language. > > Maybe so. But I've only ever appreciated its functional aspects. I > wouldn't choose Lisp or its derivatives for OO related tasks even if > I'm high. > You are just being silly. Lisp's OO environment CLOS is vastly superior to Python classes. Both in terms of expressive power and flexibility. You might even find out if you ever learnt how to use it. Lisp also supports procedural programming just fine. In the windows world the best way to access system libraries are via .NET. Thus each language inventing it's own libraries is quickly becoming a thing of the past. Also you can mix and match languages according to need. Python is fine if you approach programming as Lego, simply gluing together libraries. But if you want to do some serious algorithmic's you may find that it is just to slow. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From Leo.Kislov at gmail.com Tue Dec 12 21:40:17 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 12 Dec 2006 18:40:17 -0800 Subject: How to turn of the monitor by python? References: <1165974152.822259.4140@l12g2000cwl.googlegroups.com> Message-ID: <1165977617.469043.219510@80g2000cwy.googlegroups.com> could.net at gmail.com wrote: > I want to turn off my monitor from within python, How to do it? > Thanks! Do you realize that hardware management and control is OS dependant? When asking such questions always specify OS. Assuming you are interested in Windows, then you just need to translate this C API calls into python. You can use ctypes (included in Python 2.5) or python win32 extensions. -- Leo From fredrik at pythonware.com Fri Dec 1 02:23:18 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 01 Dec 2006 08:23:18 +0100 Subject: Python spam? In-Reply-To: <1f7befae0611301404v5e3bb702n2be1c88a235143ef@mail.gmail.com> References: <1f7befae0611301404v5e3bb702n2be1c88a235143ef@mail.gmail.com> Message-ID: Tim Peters wrote: > It's been going on for years. The most frequent forged "Python > related" sender address I've seen is actually help at python.org, > followed (but not closely) by /F's fredrik at pythonware.com. Spammers > harvest legit addresses to forge via scraping web pages and via > Trojans scouring newbies' address books. when you get this kind of "clustering" effect, chances are that it's a trojan on someone's computer that's actually sending the mails, using mail addresses found on the infected computer (address books and browser caches are good sources for this). (so in your cases, it's probably just some poor python-dev reader who hasn't updated his virus checker lately...) From __peter__ at web.de Wed Dec 6 05:15:32 2006 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Dec 2006 11:15:32 +0100 Subject: Novice: replacing strings with unicode variables in a list References: <1165397220.491511.159310@f1g2000cwa.googlegroups.com> Message-ID: Peter Otten wrote: > words = s.split(): Oops, remove bogus colon here. From kirk at nospam.jobsluder.net Sat Dec 9 16:55:19 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sat, 09 Dec 2006 21:55:19 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: In article <874ps423sx.fsf at thalassa.informatimago.com>, Pascal Bourguignon wrote: > Kirk Sluder writes: > > I've not seen a convincing explanation as to why imported macros > > from some library are so much more evil than imported functions. In > > both cases one might have to dig into documentation and/or comments > > to understand exactly what that imported snippit is doing. > > And the difference with a library function is? > > (defpackage "LIBRARY" (:export "THIS-IS-A-FUNCTION")) > > (library:this-is-a-function ???) ; ??? Well, my argument is that there is little difference. Functions, objects and macros all redefine some aspect of the system's language, and all of them can be vulnerable to obfuscation or unnecessary abstraction. The question I have is why do critics single out macros and not other forms of abstraction such as objects, packages, libraries, and functions? just as an example: from foolib import * bar.bar("somefile") What does this program do? I have no idea. Its functionality is hidden behind multiple layers of abstraction (function, object, library.) From fredrik at pythonware.com Tue Dec 5 03:26:34 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 09:26:34 +0100 Subject: Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 In-Reply-To: <20061205081605.62681.qmail@web50901.mail.yahoo.com> References: <20061205081605.62681.qmail@web50901.mail.yahoo.com> Message-ID: f rom wrote: >> 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA at 24 referenced in function _make_buildinfo2 >> 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegOpenKeyA at 12 referenced in function _make_buildinfo2 you need to link with Advapi32.dll; see: http://msdn.microsoft.com/library/en-us/sysinfo/base/regqueryvalueex.asp From uymqlp502 at sneakemail.com Mon Dec 4 03:12:48 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 4 Dec 2006 00:12:48 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> Message-ID: <1165219968.619509.147990@73g2000cwn.googlegroups.com> Fredrik Lundh wrote: > Russ wrote: > > >> No one is castigating the OP for bringing up the issue. His suggestion that his > >> time is worth more than that of anyone else, though, is drawing some ire. > > > > I'm afraid that any such "suggestion" is purely in your own > > imagination. > > "Now, that would be rather silly. I would have to familiarize myself > with the code for the Python interpreter, then send a patch to the > maintainers (and hope they notice it in their inboxes), while the > maintainers themselves could probably "fix" the problem in two minutes > flat. No thanks!" That is a perfectly reasonable statement. Forgive me if I underestimated the difficulty of implementing the feature I suggested, but I still don't think it would be difficult for the code maintainers to implement. They are obviously familiar with the code, but I'm not! > and a couple of other posts with a similar tone. open source developers > tend to ignore people who use the "you're just a bunch of code monkeys" > intimidation approach, especially when combined with an undertone of > "what I'm proposing should be easy, and if it isn't, that's because > you're incompetent". claiming to talk for everyone else doesn't really > help, either. Boy, some of you guys seem to have a very low self esteem, reading insults where none exist. "Just a bunch of code monkeys"?!! Where in the friggin' world did I say anything remotely resembling that? I happen to be a proud "code monkey" myself, for crying out loud! And excuuuuuuuuuuuuuse me for suggesting a minor new feature to enhance the productivity of Python without implementing it myself! Geez! From at at tuko.nl Wed Dec 13 13:25:11 2006 From: at at tuko.nl (at) Date: Wed, 13 Dec 2006 19:25:11 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> Message-ID: <45804584$0$334$e4fe514c@news.xs4all.nl> You proposal, seems nice to me but it doesn't work with Python 2.4.3, should it work with 2.5? Again I am just wondering if the approach for [x for c x in some_list if some_condition] and x = a if b else c could be generalized for normal straight forward iterations: for x in some_list if some_condition: --- etc... I am not looking for a work around but more interest if other people might judge this syntax would come in handy? Interested in any feedback! Kind regards, @ Paul Rubin wrote: > at writes: >> I have a lot times the following code: >> >> for x in [-2, -1, 0, 1, 2, 3, 4]: >> if x > 0: >> ... more code... > > Use: > > for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x > 0): > ... more code ... From sigzero at gmail.com Mon Dec 4 14:00:06 2006 From: sigzero at gmail.com (Robert Hicks) Date: 4 Dec 2006 11:00:06 -0800 Subject: SQLObject release 0.7.2 In-Reply-To: References: Message-ID: <1165258806.137336.61330@j72g2000cwa.googlegroups.com> Oracle? Robert From fredrik at pythonware.com Mon Dec 4 01:58:25 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 07:58:25 +0100 Subject: Why not just show the out-of-range index? In-Reply-To: <1165211562.329647.164170@f1g2000cwa.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> Message-ID: Russ wrote: > Holy cow! I can't believe that many changes would be necessary unless > the IndexError exception is scattered all over the place. I would hope > that one well-placed change could fix the bulk of cases. when you write x[i], the interpreter makes no assumptions about x and i and len(x); it just calls the corresponding method (__getitem__), either directly, or via a C-level internal slot. there's no way to generate the error message you want in a single place without changing the semantics of x[i]. From george.sakkis at gmail.com Tue Dec 12 16:56:30 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 12 Dec 2006 13:56:30 -0800 Subject: Frame hacking References: <1165956409.786690.150240@79g2000cws.googlegroups.com> <1165957786.424433.236650@79g2000cws.googlegroups.com> Message-ID: <1165960590.466033.172030@l12g2000cwl.googlegroups.com> Gabriel Genellina wrote: > On 12 dic, 17:46, "George Sakkis" wrote: > > > I wonder if the following is possible: > > > > def inject_n_call(func, **kwds): > > '''Call func by first updating its locals with kwds.''' > > > > def f(): > > return x*y > > > > >>> eval(f.func_code, dict(x=3,y=4)) > 12 Sweet! I think I just reinvented what eval does in this case by fiddling with sys.settrace and frame.f_globals. Glad to trash my 20-line function for an one-liner :) Regards, George From sjmachin at lexicon.net Mon Dec 18 12:36:04 2006 From: sjmachin at lexicon.net (John Machin) Date: 18 Dec 2006 09:36:04 -0800 Subject: convert from date string to epoch In-Reply-To: References: <1360b7230612152204y44fa022fj2466a6e54e5b656f@mail.gmail.com> Message-ID: <1166463364.361860.114660@80g2000cwy.googlegroups.com> Stefan Antonelli wrote: > Amit Khemka gmail.com> writes: > > > > Check out timegm function in calendar module. The following function > > converts "mm/dd/yyyy" formats into epoch value, you can hack it for > > your date formats. > > > > def convertToEpoch(date): > > tup = map(int,date.split('/')) > > l = (tup[2], tup[0], tup[1], 0, 0, 0) > > epochs = calendar.timegm(l) > > return (int(epochs)) > > > Thanks for your suggestion... For me this was the Solutions: > > # convert 'yyyy-mm-dd hh:mm:ss' to epoch > def toEpoch(timestamp): > split = str(timestamp).split(' ') Binding the name "split" to this result is not a good idea, because it leads to ... > tdate = map(int,split[0].split('-')) ... the above line being rather difficult to read without exclamations :-) > ttime = map(int,split[1].split(':')) > tcode = (tdate[0], tdate[1], tdate[2], ttime[0], ttime[1], ttime[2]) ... and the above causes the same problem. tcode = ttime + tcode might be better. > epoch = timegm(tcode) > return (int(epoch)) > Try this: def toEpoch(timestamp): datestr, timestr = str(timestamp).split(' ') tdate = datestr.split('-') ttime = timestr.split(':') tcode = map(int, tdate + ttime) epoch = timegm(tcode) return int(epoch) Note: the last 5 lines can be jammed into one line if you are desperate :-) HTH, John From pyenos at pyenos.org Wed Dec 20 17:16:58 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 09:16:58 +1100 Subject: what is wrong with my code? Message-ID: <874prq6wmd.fsf@pyenos.pyenos.org> import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS=["new","remove","modify"] DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=["pass", "fail"] def unpickleProgressTable(pickled_progress_data_file): return unpickled_progress_table def pickleProgressTable(progress_table_to_pickle): return pickled_progress_data_file # Of course, you get progress_table is unpickled progress table. def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]): pid_column_list=progress_table[0] task_column_list=progress_table[1] outcome_column_list=progress_table[2] # But a task must also come with an outcome! def newEntry(new_task, new_outcome): new_pid=len(task_column_list) pid_column_list.extend(new_pid) task_column_list.extend(new_task) outcome_column_list.extend(new_outcome) def removeEntry(pid_to_remove, task_to_remove): if pid_column_list.index(pid_to_remove)==task_column_list.index(task_to_remove): # Must remove all columns for that task index_for_removal=pid_column_list.index(pid_to_remove) pid_column_list.remove(index_for_removal) task_column_list.remove(index_for_removal) outcome_column_list.remove(index_for_removal) # Default action is to modify to pass def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]): index_for_modifying=pid_column_list.index(pid_to_modify) # Modify the outcome outcome_column_list[index_for_modifying]=outcome_to_modify From fred at adventistcare.org Sat Dec 2 22:26:03 2006 From: fred at adventistcare.org (Sells, Fred) Date: Sat, 2 Dec 2006 22:26:03 -0500 Subject: python vs java eclipse Message-ID: <1A4BF05172023E468CB6E867923BC90402B6E3B4@accmail2.sunbelt.org> If you're in the PyDev perspective, F9 runs the current script while ctrl-F11 reruns the last script run. I have found that certain types of operations just plain don't work this way and must be run from a conventional shell window. -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org]On Behalf Of krishnakant Mane Sent: Friday, December 01, 2006 6:19 AM To: python-list at python.org Subject: Re: python vs java eclipse just used the py dev plugin for eclipse. it is great. auto indentation and intellisence. and all other things. so now how does it look from this end? python + productivity and eclipse + productivity = double productivity! only problem with the plugin is that I find it difficult to manage the script running. I open a command prompt and run the scripts manually. any suggestion for this. for example I had name = raw_input("please enter your name") and the moment I type the first letter on the keyboard the code execution moves over to the next statement. should it not wait for the return key as it always does? Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list From michax at gmail.com Sat Dec 9 11:10:54 2006 From: michax at gmail.com (Michax) Date: 9 Dec 2006 08:10:54 -0800 Subject: py2exe Problem with cairo In-Reply-To: References: <1165678800.276619.236140@n67g2000cwd.googlegroups.com> Message-ID: <1165680654.050508.98970@j72g2000cwa.googlegroups.com> > seen this: > > http://www.py2exe.org/index.cgi/Py2exeAndPyGTK Thanks ,I will check this one . Sorry for double post. From hg at nospam.org Tue Dec 12 10:43:31 2006 From: hg at nospam.org (hg) Date: Tue, 12 Dec 2006 09:43:31 -0600 Subject: Embedding a shell / editor in a wxPython application Message-ID: Hi, Are there modules out there (ex: scintilla for editor ...) ? Thanks hg From pavlovevidence at gmail.com Fri Dec 29 14:04:49 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 29 Dec 2006 11:04:49 -0800 Subject: Anyone persuaded by "merits of Lisp vs Python"? In-Reply-To: <1167391935.980609.279850@79g2000cws.googlegroups.com> References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> <1167372073.541929.57370@48g2000cwx.googlegroups.com> <1167391935.980609.279850@79g2000cws.googlegroups.com> Message-ID: <1167419089.157913.146520@48g2000cwx.googlegroups.com> Paddy wrote: > Carl Banks wrote: > > If you were so keen on avoiding a flame war, the first thing you should > > have done is to not cross-post this. > > I want to cover Pythonistas looking at Lisp and Lispers looking at > Python because of the thread. The cross posting is not as flame bait. Then post a separate message to each group. If you expect everyone on Usenet to obey your command to reply with only what you want them to reply with, you're a sad naive fool. Carl Banks From gagsl-py at yahoo.com.ar Thu Dec 7 22:09:24 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 08 Dec 2006 00:09:24 -0300 Subject: Multithreaded python script calls the COMMAND LINE In-Reply-To: <1165529622.148951.173460@l12g2000cwl.googlegroups.com> References: <1165523805.955071.246310@80g2000cwy.googlegroups.com> <1165525526.613324.145310@n67g2000cwd.googlegroups.com> <1165529622.148951.173460@l12g2000cwl.googlegroups.com> Message-ID: <7.0.1.0.0.20061208000400.040434b0@yahoo.com.ar> At Thursday 7/12/2006 19:13, johnny wrote: > > Anyway, if you have many conversion processes running, you should pass > > them unique file names to avoid conflicts. > > Where does the '1' name come from? If it's you, don't use a fixed name > > - the tempfile module may be useful. > >I am giving unique name to the converted file with .pdf. I think >something up with the thread. I am new to python, I am not sure what's >wrong. Unless the ps2pdf program uses explicitely '1' as a filename, I don't see where it may come from. Your python code doesn't generate it - unless you have a 1.ps file. [Quoting from a previous message] >For some >reason I am getting "File '1' is alread exists, Do you want to >overwrite [y/n]?" I have to manually enter 'y' or 'n' for the python >script to complete. Is that '1' just an example, or you always get that? -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com Sun Dec 17 14:11:13 2006 From: raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com (Raffael Cavallaro) Date: Sun, 17 Dec 2006 14:11:13 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45844272$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <2006121614375650878-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45853e98$0$8712$ed2619ec@ptn-nntp-reader02.plus.net> <200612171140567987-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45858476$0$8715$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <2006121714111333169-raffaelcavallaro@pasdespamsilvousplaitmaccom> On 2006-12-17 12:52:34 -0500, Jon Harrop said: > Implementing pattern matching does not mean imitating Haskell or OCaml. We were explicitly comparing lisp with haskell and ocaml. Adding features built into haskell and ocaml but not present in ANSI common lisp would therefore constitute imitating haskell and ocaml in the context of this discussion. Surely you don't think I'm unaware of the fact that haskell and ocaml weren't the first languages to use some form of pattern matching. I acutally used SNOBOL once upon a time. From hg at nospam.org Mon Dec 4 06:50:22 2006 From: hg at nospam.org (hg) Date: Mon, 04 Dec 2006 05:50:22 -0600 Subject: get script path Message-ID: <%7Uch.38012$1w6.17240@newsfe16.lga> Hi, must I parse argv[0] to get it, or is there an easier way (that works under Windows and *nix)? Ex: python /home/hg/test/test.py ==> test.py #knows it is in /home/hg/test Thanks, hg From could.net at gmail.com Tue Dec 12 20:42:32 2006 From: could.net at gmail.com (could.net at gmail.com) Date: 12 Dec 2006 17:42:32 -0800 Subject: How to turn of the monitor by python? Message-ID: <1165974152.822259.4140@l12g2000cwl.googlegroups.com> I want to turn off my monitor from within python, How to do it? Thanks! From bearophileHUGS at lycos.com Thu Dec 21 16:15:20 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 21 Dec 2006 13:15:20 -0800 Subject: Decorator for Enforcing Argument Types In-Reply-To: <1166734180.455471.164910@79g2000cws.googlegroups.com> References: <1166734180.455471.164910@79g2000cws.googlegroups.com> Message-ID: <1166735720.218742.72090@42g2000cwt.googlegroups.com> Chris wrote: > I'm not sure if this has been done before, I think this is the best implementation: http://oakwinter.com/code/typecheck/ I have never used it, but it seems well done. Bye, bearophile From eurleif at ecritters.biz Sun Dec 17 00:28:22 2006 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 17 Dec 2006 00:28:22 -0500 Subject: How to test if two strings point to the same file or directory? In-Reply-To: References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: <4584d3fe$0$27423$4d3efbfe@news.sover.net> Tim Chase wrote: >>> Comparing file system paths as strings is very brittle. >> >> Why do you say that? Are you thinking of something like this? >> >> /home//user/somedirectory/../file >> /home/user/file > > Or even > > ~/file ~ is interpreted as "my home directory" by the shell, but when it's used in a path, it has no special meaning. open('~/foo.txt') tries to open a file called foo.txt in a subdirectory of the current directory called '~'. From http Thu Dec 14 22:22:08 2006 From: http (Paul Rubin) Date: 14 Dec 2006 19:22:08 -0800 Subject: automatically grading small programming assignments References: Message-ID: <7xzm9palnj.fsf@ruckus.brouhaha.com> Brian Blais writes: > Unfortunately, it takes a lot of time to grade such things by hand, so > I would like to automate it as much as possible. > ... > Or perhaps there is a better way to do this sort of thing. How do > others who teach Python handle this? I think you should not attempt this. It means grading the program on pure functionality. Writing good code is about more than functionality; it's also about communicating with humans. Supplying a doctest is a reasonable idea but students should just run the test themselves until their code passes, no need to log all their debugging attempts. When they submit something that passes the test, you should read the code and supply some feedback about about their coding style and so forth. This matters as much as the pure issue of whether the program works. Imagine an English teacher wanting to grade class papers automatically by running them through a spelling and grammar checker without reading them. If the workload of grading manually is too high, see if you can bring on an assistant to help. From will at willmcgugan.com Tue Dec 19 09:13:05 2006 From: will at willmcgugan.com (Will McGugan) Date: 19 Dec 2006 06:13:05 -0800 Subject: trouble getting google through urllib References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> <45879f2f$0$32025$fa0fcedb@news.zen.co.uk> Message-ID: <1166537585.709708.223250@i12g2000cwa.googlegroups.com> Duncan Booth wrote: > > > > Google doesnt like Python scripts. You will need to pretend to be a > > browser by setting the user-agent string in the HTTP header. > > > and possibly also run the risk of having your system blocked by Google if > they figure out you are lying to them? It is possible. I wrote a 'googlewhack' (remember them?) script a while ago, which pretty much downloaded as many google pages as my adsl could handle. And they didn't punish me for it. Although apparently they do issue short term bans on IP's that abuse their service. It is best to play nice of course. I would recommend using their official APIs if possible! Will McGugan -- http://www.willmcgugan.com From Thomas.Ploch at gmx.net Tue Dec 19 07:22:10 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Tue, 19 Dec 2006 13:22:10 +0100 Subject: regular expression In-Reply-To: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> Message-ID: <4587D972.10101@gmx.net> Asper Faner schrieb: > I seem to always have hard time understaing how this regular expression > works, especially how on earth do people bring it up as part of > computer programming language. Natural language processing seems not > enough to explain by the way. Why no eliminate it ? > Erm, I am a student of Computational Linguistics and _NO_ , they should _NOT_ be eliminated since they are an important part of language processing in python. Read this: http://www.amk.ca/python/howto/regex/ From nono at hotmail.com Sun Dec 31 06:03:46 2006 From: nono at hotmail.com (Osiris) Date: Sun, 31 Dec 2006 12:03:46 +0100 Subject: python , Boost and straight (but complex) C code References: Message-ID: On Sat, 30 Dec 2006 23:35:22 +0200, "Roman Yakovenko" wrote: >On 12/30/06, Osiris wrote: >> Visual C++ build log at: >> >> http://213.10.133.192/BuildLog.htm > >It is better to ask Boost.Python related questions on it mailing list: >http://mail.python.org/mailman/listinfo/c++-sig/ > >You should add to the link line boost_python.lib, thus you will eliminate >"unresolved reference symbol" errors. If you did not build Boost.Python >next page( http://boost.org/libs/python/doc/building.html ) contains pretty >good explanation how to do this. That explanation I find confusing: "To build boost_python, use Boost.Build...": Where is boost.build and what is it ? in my D:\boost\libs\python\build there is no boost.build... in D:\boost there is a build-boost.jam file.... Is that it ? I have a D:\boost\libs\python\build\bin-stage\boost_python.dll (204kB size) and a D:\boost\libs\python\build\bin-stage\boost_build.lib (163 KB) I made them with Visual Studio... I made a bjam, it is in C:\ In D:\boost\libs\python\build there are a bin_stage and a VisualStudio folder , the files jamfile jamfile.v2 python_v1.zip Is it so, that I can build the boost_python.dll and lib, either with bjam OR with VisualStudio C++ ? Why are all those other folders there in d:\boost ? people, regression, tools, status etc ? What do I do with d:\boost\boost ? a lot of headers there... what are all these folders in d:\boost\libs\ ? In short: it's all rather confusing.... I think it must be like this: To use my C/C++ code with Python, add some stuff in the C/C++ source and compile it into a DLL, that must be combined with some boost-DLL to make it accessible to Python 2.4. Therefore I need a boost DLL from boost.org, and some headerfiles that belong to the boost DLL. (where are those boost header files ) As you see, a lot of obfuscation.... MAybe I see too many bears on the road... > >http://boost.org/libs/python/doc/v2/scope.html - here you will find example how >to expose my_int variable to Python. my_int has type int, so C++ code will not >see changes to the variable that are done from Python. You will have to write >set_my_int( x ) function to achieve this. > >If you are new to Boost.Python try to use Py++ - the code generator for >the library. The Py++ GUI( http://tinyurl.com/ycwvwo ) will help you >to start\learn Boost.Python. From nmm1 at cus.cam.ac.uk Wed Dec 13 16:04:56 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 13 Dec 2006 21:04:56 GMT Subject: Defining classes Message-ID: I am defining a class, and I need to refer to that class when setting up its static data - don't ask - like this: Class weeble : wumpus = brinjal(weeble) Does anyone know how I can achieve this? Naturally, I don't need anything more than the address of the class in brinjal, as it won't be used until after the class has been created properly. Actually, it won't be used except to test for class equivalence, but I may want to extend later. Regards, Nick Maclaren. From juanrgonzaleza at canonicalscience.com Sat Dec 16 12:52:17 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 16 Dec 2006 09:52:17 -0800 Subject: merits of Lisp vs Python In-Reply-To: <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> References: <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> Message-ID: <1166291536.972344.200810@t46g2000cwa.googlegroups.com> Raffael Cavallaro ha escrito: > This lock-in to > a particular paradigm, however powerful, is what makes any such > language strictly less expressive than one with syntactic abstraction > over a uniform syntax. Right, but it would be also remarked that there is not reason to ignoring the development and implementation of specific syntaxes, paradigms, etc. optimized to specialized (sub)fields of discourse. If all you need is basic arithmetics and 'static' data structures, optimization ? la Python Y = a + b * c gets sense in most of cases. If you are developing symbolic software where data structures as highly 'dinamic' and where you would wait something more than sums, divisions, sines and cosines, and some numeric differentials then the parens automatically gets sense. Using LISP-like syntax for everything would be so stupid as using quantum mechanics for billiards. From Divyap at amdale.com Tue Dec 19 01:54:11 2006 From: Divyap at amdale.com (Divya Prakash) Date: Tue, 19 Dec 2006 12:24:11 +0530 Subject: No subject In-Reply-To: <7.0.1.0.0.20061218214734.05e8c8d0@yahoo.com.ar> Message-ID: <20061219065425.38E051E4006@bag.python.org> Hi I don't know how to implement these API's .When I use the method "Parse (file object) " it gives error..... So, I m blank how to implement it in order to get all the info of java file and thn represent them in xml format.. Regards Divya -----Original Message----- From: Gabriel Genellina [mailto:gagsl-py at yahoo.com.ar] Sent: Tuesday, December 19, 2006 6:21 AM To: Divya Prakash Cc: python-list at python.org Subject: Re: At Monday 18/12/2006 03:34, Divya Prakash wrote: > I would like to parse java files and detect class name's, > attributes name's type's and visibility (and or list of > methods). > Is there any module who can parse easily a java file using jython? You could try javadoc (the java package), it is easier to use than a pure reflection approach. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam !gratis! !Abrm tu cuenta ya! - http://correo.yahoo.com.ar From duane at franz.com Fri Dec 8 18:12:14 2006 From: duane at franz.com (Duane Rettig) Date: Fri, 08 Dec 2006 15:12:14 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165615503.228351.137610@16g2000cwy.googlegroups.com> Message-ID: "Paddy" writes: > Mark Tarver wrote: > >> How do you compare Python to Lisp? What specific advantages do you >> think that one has over the other? >> >> Note I'm not a Python person and I have no axes to grind here. This is >> just a question for my general education. >> >> Mark > I've never programmed in Lisp but I have programmed in Cadence Skill a > Lisp inspired language with infix notation as an option. I found Skill > to be a very powerful language. At the time I new only AWK, C, Pascal, > Forth, Postcript, Assembler and Basic. Skill was superior and I came > to love it. Remember; Lisp is a program-language programming language. Sometimes, one programs in Lisp without really knowing it: http://www.franz.com/careers/jobs/outside/cadence03.21.06.lhtml -- Duane Rettig duane at franz.com Franz Inc. http://www.franz.com/ 555 12th St., Suite 1450 http://www.555citycenter.com/ Oakland, Ca. 94607 Phone: (510) 452-2000; Fax: (510) 452-0182 From jon at ffconsultancy.com Sun Dec 10 04:19:02 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 09:19:02 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <7xfybpb9pe.fsf@ruckus.brouhaha.com> Message-ID: <457bd1a5$0$8740$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: > Haskell is pretty neat in that it basically removes things like setq. > That makes possible (for example) very cool simplifications to > concurrent programming. See the paper "Composable memory transactions": > > http://research.microsoft.com/~simonpj/papers/stm/index.htm > > Yeah you could do that with Lisp by writing in a restricted style, > just like you could avoid pointer errors in C++ by writing in a > restricted style. But it's hard for the compiler to guarantee that > your program obeys the restrictions. You could write a language like > Ada or Java that makes a lot of guarantees, but is unexpressive and a > huge pain to program in. You can write a language like Lisp that's > expressive but doesn't make as many guarantees. Interesting problems > in language design arise in writing languages that are expressive AND > make guarantees. I discovered this recently with F#. Although F# (as a dialect of OCaml) is impure like Lisp, it does make purely functional programming easy and provides many purely functional data structures. I translated 15kLOC of mostly-functional OCaml code into F# and only had to add four locks to make the whole library concurrent. That is probably feasible in Lisp but not in Python... -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From stevenst at rocketmail.com Thu Dec 14 03:40:57 2006 From: stevenst at rocketmail.com (Leanne) Date: 14 Dec 2006 00:40:57 -0800 Subject: Newbie Question - Checkboxes In-Reply-To: <1165815168.464198.322250@79g2000cws.googlegroups.com> References: <1165737399.895450.85620@f1g2000cwa.googlegroups.com> <1165815168.464198.322250@79g2000cws.googlegroups.com> Message-ID: <1166085656.997694.38550@16g2000cwy.googlegroups.com> John Machin wrote: >> I'd try this: > > if isinstance(returned_value, basestring): > returned_value = [returned_value] > for item in returned_value: > do_something_with(item) > > HTH, > John This sounds like a neat way of doing it, thanks! From tomas at fancy.org Fri Dec 29 03:59:41 2006 From: tomas at fancy.org (Tom Plunket) Date: Fri, 29 Dec 2006 00:59:41 -0800 Subject: Starting a child process and getting its stdout? References: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> Message-ID: <7vl9p2h7f7adsbn6d6tfpmluera3njnb6g@4ax.com> cypher543 wrote: > This has been driving me insane for the last hour or so. I have search > everywhere, and nothing works. I am trying to use the subprocess module > to run a program and get its output line by line. But, it always waits > for the process to terminate and then return the output all at once. Right, you need to use subprocess.PIPE and polling of the process and the pipe to get it to do what you want. Hopefully this makes sense, I also hope it'll work on Linux but can't imagine why it wouldn't. Save this code to a file, name unimportant. Executing the file will fire the top clause of the if statement, the bit that runs the "parent" part. That starts the script again as a subprocess, which triggers the else clause. Hope it makes sense. Depending on your environment, you might need 'shell=True' in your Popen args. On Windows, that is required if you want to prevent a console window from popping up if you're running in a GUI app. -tom! -- import subprocess import sys import time if len(sys.argv) == 1: # no command line arg means, "we're the parent process." print 'starting parent process.' myName = sys.argv[0] # launch the subprocess with an additional parameter, to trigger # else clause below. p = subprocess.Popen( ( 'python', '-u', myName, 'x' ), stdout=subprocess.PIPE ) while p.poll() == None: data = p.stdout.readline() if data: print data, print 'process ended with return code', p.returncode else: # assume the command-line arg means "run the background process" print 'starting subprocess' for i in range(10): time.sleep(.25) print i sys.exit(14) From sonibergraj at youjoy.org Tue Dec 5 08:38:20 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Tue, 05 Dec 2006 14:38:20 +0100 Subject: Why not just show the out-of-range index? In-Reply-To: <1165325263.656851.87980@l12g2000cwl.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165325263.656851.87980@l12g2000cwl.googlegroups.com> Message-ID: <4575764C.80400@youjoy.org> stdazi wrote: > It really seems like a > feature that should be embedded in some Python debugger than a feature > in the interpreter itself. +1 -- Soni Bergraj http://www.YouJoy.org/ From shb*NO*SPAM* at comporium.net Sun Dec 3 20:13:25 2006 From: shb*NO*SPAM* at comporium.net (Si Ballenger) Date: Mon, 04 Dec 2006 01:13:25 GMT Subject: Parsing data from pyserial References: <4572e860.53134312@news.comporium.net> <12n606he7k5uhb3@corp.supernews.com> <4573145a.64392531@news.comporium.net> <12n66nnm8ri1sd4@corp.supernews.com> Message-ID: <45737310.88637718@news.comporium.net> On Sun, 03 Dec 2006 18:44:07 -0000, Grant Edwards wrote: >On 2006-12-03, Si Ballenger wrote: > >>>> In my dealing with serial gizmos I have to put a delay between >>>> the request sent to the gizmo and the reading of the serial input >>>> buffer for returned data. Serial ports and gizmos need some time >>>> to do their thing. >>> >>>I doubt that's the issue. He's reading with a 1-second timeout >>>value. >> >> I would think a time delay would be needed between the below two >> lines in the code if he expects to get a useable data string back >> from the gizmo for the command sent to it. >> >> ser.write("TC 016 240 100 240 016 240\r\n") >> reading = ser.read(40) > >No. A delay isn't needed as long as the device responds within >1 second. The read() call will wait up to 1 second for the >first byte of the response. Per what was posted (below), it appears that the the appropriate data is being received. It may be possible that the cam may be sending in a mode that is not in alignment with the binary transmission mode of the serial port. As a test I'd jumper between the Tx and Rx pin on the serial port and then send out the "M" line being received, then see if it will parse as expected. Here is an example output: M 37 79 3 4 59 124 86 25 ['59', '123', '87', '25', 'M', '37', '79', '3', '4', '59', '124', '86', '25', 'M '] M 38 77 3 2 59 124 86 25 ['39', '85', '26', 'M', '38', '77', '3', '2', '59', '124', '86', '25', 'M', '38' , '7'] From jstroud at mbi.ucla.edu Fri Dec 15 01:53:03 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 15 Dec 2006 06:53:03 GMT Subject: skip last line in loops In-Reply-To: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: eight02645999 at yahoo.com wrote: > hi, > how can i skip printing the last line using loops (for /while) > > eg > > for line in open("file): > print line. > > I want to skip printing last line of the file.thanks > afile = open(filename) xlines = afile.xreadlines() aline = xlines.next for nextline in xlines: print aline aline = nextline James From spedrosa at gmail.com Thu Dec 7 08:54:55 2006 From: spedrosa at gmail.com (Stephen Eilert) Date: 7 Dec 2006 05:54:55 -0800 Subject: Common Python Idioms In-Reply-To: References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> Message-ID: <1165499695.092184.72460@73g2000cwn.googlegroups.com> Duncan Booth escreveu: > > > > > Is there a list somewhere listing those not-so-obvious-idioms? I've > > seen some in this thread (like the replacement for .startswith). > > > The release notes for each new version. Unfortunately the rest of the > documentation sometimes lags behind the release notes. Right. If and when time allows, I'll try to compile a list. > > > > I do think that, if it is faster, Python should translate > > "x.has_key(y)" to "y in x". > > Python doesn't know whether x has a __contains__ method until it tries to > call it. In particular there may be user-defined dictionary-like objects in > your program which support has_key but not 'in'. e.g. in at least some > versions of Zope HTTPRequest objects support has_key but not __contains__. You're right. Brain fart. Stephen From larry.bates at websafe.com Fri Dec 29 17:58:24 2006 From: larry.bates at websafe.com (Larry Bates) Date: Fri, 29 Dec 2006 16:58:24 -0600 Subject: Easiest way to print from XP/DOS. In-Reply-To: References: Message-ID: jim-on-linux wrote: > > This is the situation I'm in. > > I've built a single file utility using py2exe. I > zip the dist directory and send it to the client. > > For clients that use win95, win98 machines, > They unpack the zip file and run the exe. > > The utility creates a text file that is sent to > the printer with the statement below. > os.system('type ' +FileName+ ' >prn'), > and the file prints. > > But, from an xp machine if I try to print using > the same statement, I get a question on the dos > screen which reads something like this; > Which program authorized this operation? > > Since I don't have an xp machine, the statement > above may not be exact, but you get the idea. > > The question I have is, first is there any way to > work around the question asked by the xp machine > using python. > > If not, I may have to register the package in xp, > if registering the utility the only way, which > package is the simplest to use. > Also, if the utility is registered in xp, will the > same statement send the file to the printer as it > does in win98. > > jim-on-linux > I don't get any such message on my XP Pro Service Pack 2 system here using your method. -Larry From kirk at nospam.jobsluder.net Sat Dec 16 13:33:35 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sat, 16 Dec 2006 13:33:35 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <7xbqm4d97d.fsf@ruckus.brouhaha.com> <7xodq4mule.fsf@ruckus.brouhaha.com> <7xvekcbhm9.fsf@ruckus.brouhaha.com> Message-ID: In article <7xvekcbhm9.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Kirk Sluder writes: > > Personally, I've always preferred use the imperative to describe > > _basic_ math rather than the passive. This would seem to map better to > > RPN than infix. (emphasis added) > For writing down complicated, nested expressions too? That's very > unusual. E.g. > > n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ... > > vs. the same thing in Lisp notation, and that's not even so complicated. I wasn't even talking about Polish notation vs. other standard notations. I was talking about your claimed correspondence between infix and natural Languages. (1/12n) - "divide 1 by the product of" of 12 and n" sqrt(2*pi*n) - "calculate the square root of the product of 2 pi and n." If computer languages were to mimic natural languages on this point, they would support both forms of expression and be sensitive to mode and mood. From stuart at bmsi.com Sat Dec 16 13:08:49 2006 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sat, 16 Dec 2006 13:08:49 -0500 Subject: I'm looking for a pythonic red-black tree... References: Message-ID: On Fri, 15 Dec 2006 01:20:34 +0000, Just Another Victim of the Ambient Morality wrote: > I need a red-black tree in Python and I was wondering if there was one > built in or if there's a good implementation out there. Something that, > lets face it, does whatever the C++ std::map<> allows you to do... Are you really looking specifically for a red-black tree, or do you want a container where iterators return values in sorted order? For instance, my favorite sorted container is the skip-list: * inherently thread safe even during container updates * updates as fast as searches - significantly faster than red-black tree * search as fast as trees on average - but probablistic (like hashtable) * sequential access as fast as a linked list * Uses 33% less memory than binary trees (like red-black tree) * in general, performs like a hashtable, but sorted Java example: http://bmsi.com/java/SkipList.java In Python, the performance of a pure Python container will be disappointing unless it leverages a native container. For many applications, you can use a dict and sort when iterating (using heapq to amortize the sorting). If I ever get the time, I would seriously consider trying to modify Python to replace the built-in dict with a skip-list algorithm and compare the performance. Failing that, an extension module implementing a sorted container of some description would be useful. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From tim.one at comcast.net Sun Dec 31 03:30:57 2006 From: tim.one at comcast.net (Tim Peters) Date: Sun, 31 Dec 2006 02:30:57 -0600 Subject: a question on python dict References: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> Message-ID: [Tim Peters] >> You should also note that copying a dict key or value (no matter of >> what type) consists in its entirety of copying one machine address (a >> 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] > Actually, no. It also consists of updating reference counts as well. Not in context: dict resizing is refcount-neutral, and the CPython implementation of dict resizing exploits that (quite directly in 2.5; indirectly before 2.5). It's not just that refcounts end up the same /across/ dict resizing, it's that they're not changed internally either for the duration of the resizing operation. From george.sakkis at gmail.com Fri Dec 8 17:44:45 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 8 Dec 2006 14:44:45 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> Message-ID: <1165617885.632226.104370@j72g2000cwa.googlegroups.com> JShrager at gmail.com wrote: > Okay, since everyone ignored the FAQ, I guess I can too... > > Mark Tarver wrote: > > How do you compare Python to Lisp? What specific advantages do you > > think that one has over the other? > > (Common) Lisp is the only industrial strength language with both pure > compositionality and a real compiler. What Python has is stupid slogans > ("It fits your brain." "Only one way to do things.") and an infinite > community of flies that, for some inexplicable reason, believe these > stupid slogns. These flies are, however, quite useful because they > produce infinite numbers of random libraries, some of which end up > being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python > is rapidly replacing Perl, and Ruby is simultaneously and even more > rapidly replacing Python. Each is closer to Lisp than the last; the > world is returning to Lisp and is dragging the flies with it. > Eventually the flies will descend upon Lisp itself and will bring with > them their infinite number of random libraries, and then things will be > where they should have been 20 years ago, but got sidetracked by Tcl > and other line noise. I know we shouldn't feed the trolls, but this one was particularly amusing to resist the urge. The joke about lisp's world domination in some unspecified point in the future never fails to bring a good chuckle. I heard it's scheduled right after strong AI and before time travel, is this still the plan? A quick look at http://www.tiobe.com/tpci.htm may be helpful as a reality check before you go back to your ivory tower (interesting how close in ratings and growth is the "Lisp/Scheme" entry with another dinosaur, Cobol). From fredrik at pythonware.com Fri Dec 15 08:07:47 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 14:07:47 +0100 Subject: skip last line in loops References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com><1166182692.041668.218730@f1g2000cwa.googlegroups.com> <0lwgh.31271$wP1.5113@newssvr14.news.prodigy.net> Message-ID: James Stroud wrote: > See the documentation for xreadlines. why? From seberino at spawar.navy.mil Mon Dec 11 19:11:10 2006 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 11 Dec 2006 16:11:10 -0800 Subject: Can't register to CheeseShop at command line...only on web?!.. Message-ID: <1165882269.932773.317580@j44g2000cwa.googlegroups.com> I created $HOME/.pypirc with this: [server-login] username:seberino password:SECRET but I can still only do CheeseShop tasks at web interface. Here is what happens when I try to register at command line with .pypirc above... Using PyPI login from /home/seb/.pypirc Server response (401): Authorization Required chris From kentilton at gmail.com Thu Dec 14 03:18:20 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 03:18:20 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7xpsangcs8.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7xpsankoc6.fsf@ruckus.brouhaha.com> <7xpsangcs8.fsf@ruckus.brouhaha.com> Message-ID: <7N7gh.574$n34.527@newsfe09.lga> Paul Rubin wrote: > Ken Tilton writes: > >>btw, you called the defskill messy (repeated below) "messy". The only >>text not specific to absolute value is D-E-F-S-K-I-L-L. > > > No, the messiness was not in the macro instantation (defskill blah...), > but in the defmacro that tells the compiler how to expand it. Again, that is precisely the point of macrology (in cases like this). When a pattern will repeat a sufficient number of times, and a function cannot handle the job, we do a little extra work (write some meta-code) to make dozens (or hundreds) of applications as minimalist as possible. That makes them concise, readable, and maintainable. > Python > function defs are lightweight enough that I don't experience a big pain > from using an extra one for a thing like that. Check out the latest, plz. The example has grown now beyond what a function can do, I think. meanwhile, I have not seen how Python lets you avoid revisiting dozens of instances when changes to a mechanism are required. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From http Fri Dec 8 07:08:24 2006 From: http (Paul Rubin) Date: 08 Dec 2006 04:08:24 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <7xejrah9on.fsf@ruckus.brouhaha.com> "Mark Tarver" writes: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? From pavlovevidence at gmail.com Tue Dec 12 19:34:13 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 12 Dec 2006 16:34:13 -0800 Subject: One module per class, bad idea? References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> Message-ID: <1165970053.237421.258620@n67g2000cwd.googlegroups.com> Carl J. Van Arsdall wrote: > Carl Banks wrote: > > Carl J. Van Arsdall wrote: > >> A module per class makes a lot of sense in some cases, or rather, make > >> your module your class (look at the singleton pattern). I actually like > >> to structure all of my code like this, it helps me keep things organized > >> and separated. > >> > > > > I don't understand. Are you saying you organize your code to be a > > bunch of modules masquerading as singleton classes? (When I was a > > young'n, we called that "procedure oriented programming" :) > > > Well, when you have a class you want instantiated once and only once > (i.e. a singleton) you can do it in python really easily vs a langauge > like C++ (and i'll explain). [snip] I understand what you're saying. It's a good technique to use sometimes; I've done it myself. (I've even gone so far as to write decorator to pass in the module as "self".) However, I'm quite sure the OP was talking about real classes, and whether we should limit ourselves to one real class per module. [snip] > Yea, you have a good point. I don't have a lot of experience with > packages, but I've also never written anything so large that i've had > more than 5-10 modules. I'll spend some time looking into it, thanks! A ha! I should note that in my reply I was not thinking about small programs. For a small program each class could very well be subsystem unto itself, so one class per module would be ok. Carl Banks From Benjamin.Barker at gmail.com Fri Dec 29 06:09:32 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 03:09:32 -0800 Subject: INSERT statements not INSERTING when using mysql from python Message-ID: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one statement. I first connect to the database... self.con = MySQLdb.connect(user=username, passwd =password) self.cursor = self.con.cursor() self.cursor.execute("SET max_error_count=0") All the neccesary tables are created... self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) self.cursor.execute("USE "+name) self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID varchar(20)) Then I execute many insert statements in various different loops on various tables, all of which are fine, and result in multiple table entries. The following one is executed many times also. and seems identical to the rest. The print statements output to the browser window, and appear repeatedly, so the query must be being called repeatedly also: print "

SQL query executing

" self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" ','c','2','e','f','g')") print "

SQL query executed

" I have, for debugging, set "i" up as a counter variable. No errors are given, but the only entry to appear in the final database is that from the final execution of the INSERT statement (the last value of i) I suspect that this is to vague for anyone to be able to help, but if anyone has any ideas I'd be really grateful :-) It occured to me that if I could access the mysql query log that might help, but I was unsure how to enable logging for MysQL with python. Cheers, Ben From http Sun Dec 10 04:27:45 2006 From: http (Paul Rubin) Date: 10 Dec 2006 01:27:45 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <1165731005.529088.227360@j44g2000cwa.googlegroups.com> <457bc963$0$8747$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <7xac1wrtgu.fsf@ruckus.brouhaha.com> Jon Harrop writes: > # cond 2 > [( = ) 1, "one"; > ( = ) 2, "two"; > ( = ) 3, "three"] > "neither one, two nor three";; > - : string = "two" I'm missing something. Doesn't Ocaml have strict evaluation? That means if you use function calls instead of string constants in those values, they all get called. You haven't really done what cond does. From RichardTRMurphy at yahoo.com Thu Dec 14 15:13:42 2006 From: RichardTRMurphy at yahoo.com (rich murphy) Date: 14 Dec 2006 12:13:42 -0800 Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> Message-ID: <1166127221.944683.65150@l12g2000cwl.googlegroups.com> Thanks to everyone who responded with valuable suggestions. I appreciate them all. I found the exact reason why "import" command fails. At the beginning I created my script file with MS Notepad. After studying all the advice, I realized that I did not try other text editors just becuase the tutorial says: "use your favorite text editor to create a file called fibo.py in the current directory with the following contents:" Then I created another file with the same stuff in it using WordPad. The behaviour of the "import" command improved a lot but still not good. Then I used MS-DOS' text editor to create the same file. Immediately the "import" command worked as it was supposed to. Almost. "fibo.fib2(100)" command stil does not work. This is fine: >>> fibo.fib(1000) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 This not fine: >>> fibo.fib2(100) [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] When I enter "fibo.fib2(100)", I get the following: >>> fibo.fib2(100) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\fibo.py", line 11, in fib2 while b < n: UnboundLocalError: local variable 'b' referenced before assignment This is fine: >>> fibo.__name__ 'fibo' >>> fib=fibo.fib >>> fib(500) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 Both Python2.4 and 2.5 are behaving the same. I will also try to create the file with Vi editor. From http Sat Dec 9 20:59:54 2006 From: http (Paul Rubin) Date: 09 Dec 2006 17:59:54 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> Message-ID: <7xodqczf1h.fsf@ruckus.brouhaha.com> jayessay writes: > > http://caml.inria.fr > > http://www.haskell.org > > Aren't these "old-fashioned" and boring as well? Maybe not bleeding edge, but more modern than CL in my opinion. From hpepper at gmail.com Mon Dec 11 15:05:27 2006 From: hpepper at gmail.com (HowiPepper) Date: 11 Dec 2006 12:05:27 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> Message-ID: <1165867527.389209.80660@f1g2000cwa.googlegroups.com> I'll vouch for what Harry said. I'm definitely not a "newbie", I've been programming since around 1982, and I am fluent in a plethora of programming languages, not including Lisp. I have checked out Lisp several times in the past, but I always get turned off completely by the parenthesis you have to use for everything. What's up with that anyway? I had been a big C/Java/Perl developer for many years, but due to a job change in May of 2005, I had to add Python into the mix. I had never even given Python a second thought, but after playing around with it for one afternoon, I had learned enough to enable me to write programs that did what I needed them to do. I now use Python on a professional basis almost every single day, and I can tell you with certainty that I am far more productive with Python, then with any other language in my arsenal. As an aside, I recently introduced a young acquaintance to Python, as a way to learn programming. Since he had absolutely no background in programming, it took a little to get him going, but thanks to the ease of use and readability of Python, he is now very confident in his work, and asks me questions only rarely. With Python's ease of learning and use, availability of a large number of libraries, extremely active development community and large user-base, I'd say the question to ask is what specific advantages over Python does Lisp offer, to make people switch to it? Cheers, Howard Harry George wrote: > "Mark Tarver" writes: > > > Paul Rubin wrote: > > > "Mark Tarver" writes: > > > > How do you compare Python to Lisp? What specific advantages do you > > > > think that one has over the other? > > > > > > > > > > Thanks; a quick read of your reference to Norvig's analysis > > > > http://norvig.com/python-lisp.html > > > > seems to show that Python is a cut down (no macros) version of Lisp > > with a worse performance. The only substantial advantage I can see is > > that GUI, and Web libraries are standard. This confirms my suspicion > > that Lisp is losing out to newbies because of its > > lack of standard support for the things many people want to do. > > > > Mark > > > > It is not just a newbie thing. Even people who are reasonably fluent > in Lisp use Python for many tasks, and some make python the default > with Lisp as a special case. It would probably be fair to say that > the more you know about a variety of languages, the more you > appreciate Python. > > > -- > Harry George > PLM Engineering Architecture From kibleur.christophe at gmail.com Sun Dec 10 06:47:21 2006 From: kibleur.christophe at gmail.com (Tool69) Date: 10 Dec 2006 03:47:21 -0800 Subject: oo problem In-Reply-To: <1165748214.955631.220080@f1g2000cwa.googlegroups.com> References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> <1165748214.955631.220080@f1g2000cwa.googlegroups.com> Message-ID: <1165751241.597422.108540@j44g2000cwa.googlegroups.com> Thanks for your answers, I though about the first solution too, but I've redundant code, say ie: p = Paper(100,200) p.draw( Rectangle(p,10,20,50,60) ) <-- we're forced to write 'p' two times. But that maybe the best solution, as I cannot see anything else. For the second one, I need to make some calculus on the shape to be drawn, so if I write: shape.paper_coordinates = self.x, self.y shape.draw() It's too late, the calculus have already been done with the default values, right or not? Thanks, 6TooL9 From gagsl-py at yahoo.com.ar Tue Dec 12 14:38:09 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 11:38:09 -0800 Subject: How can I get involved In-Reply-To: <1165947003.417815.256590@l12g2000cwl.googlegroups.com> References: <1165856767.477175.276380@80g2000cwy.googlegroups.com> <1165867719.421812.101400@l12g2000cwl.googlegroups.com> <1165947003.417815.256590@l12g2000cwl.googlegroups.com> Message-ID: <1165952289.727882.299960@l12g2000cwl.googlegroups.com> On 12 dic, 15:10, "Prateek" wrote: > So I've started work on an Unpickler in Java. I'll post again soon with > the URL (haven't uploaded it yet). If anyone is interested, email me. Have you seen Jython? (formerly JPython) www.jython.org -- Gabriel Genellina From ptmcg at austin.rr._bogus_.com Tue Dec 26 11:08:21 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 26 Dec 2006 10:08:21 -0600 Subject: Formatting a string to be a columned block of text References: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> <459136c5$0$16985$4c368faf@roadrunner.com> Message-ID: <459148f5$0$16750$4c368faf@roadrunner.com> "Paul McGuire" wrote in message news:459136c5$0$16985$4c368faf at roadrunner.com... > > gettysburgAddress = """Four score and seven years ago... By the way, this variable contains only 3 (very long) lines of text, one for each paragraph. (Not immediately obvious after Usenet wraps the text.) -- Paul From spam at spam.pl Tue Dec 19 14:39:45 2006 From: spam at spam.pl (vertigo) Date: Tue, 19 Dec 2006 20:39:45 +0100 Subject: regexp References: Message-ID: > vertigo wrote: >> I need to use some regular expressions for more than one line. >> And i would like to use some modificators like: /m or /s in perl. >> For example: >> re.sub(".*","",data) >> will not cut out all javascript code if it's spread on many lines. > > that won't cut out all javascript code period. do you have any idea what will do ? i need to cut everything but the pure text data. Thanx From lmsteadman at gmail.com Wed Dec 13 23:14:56 2006 From: lmsteadman at gmail.com (lmsteadman at gmail.com) Date: 13 Dec 2006 20:14:56 -0800 Subject: job posting: Sr Systems Programmer needed Message-ID: <1166069696.859817.18450@73g2000cwn.googlegroups.com> AGCO, Jackson Operations is nestled in the picturesque Des Moines River Valley---in the welcoming town of Jackson, Minnesota (56143). Jackson is a town of approximately 3600 neighbors, and is centrally located between the booming town of Sioux Falls, SD and the resort area of the Okoboji Lakes. AGCO's award-winning facility is jut the tip of the iceberg! Our employees enjoy an outstanding quality of life, great advancement opportunities, a results-oriented work environment all while nestled into a scenic rural area (which supports a reduced cost of living and unbelievably low crime rate). Enjoy the outdoors? You can't beat the fishing, hunting, golfing, hiking and biking opportunities in Jackson County. Do you prefer the adrenalin of watching sports live and in action? Jackson is also home to the famous Jackson Speedway (NASCAR/racing), and you can easily catch a Minnesota Vikings game or visit the Mall of America with a quick trip north up to Minneapolis for the day. Jackson's public school has just undergone a $20 million renovation to make it one of the nicest high schools in the area. The athletic facilities alone would make some colleges jealous. Currently, the City Council and the County Commission are working together on a new community center to house several city and county offices along with a training facility. The AGCO facility is a 100-acre campus that houses over 587,000 sq feet full fabrication and welding operation under one roof! AGCO currently employs over 900 team members (we have several employees that have worked here for over 20-30 years!). We are now looking for process-oriented MIS members to drive our continuous improvement effort at our state-of-the-art manufacturing campus. Target start date would be in 1st Quarter 2007, however we are starting to interview now! AGCO Jackson is a launch pad for long-term careers within AGCO Corporation! We over a very competitive compensation package, relocation package, continuing education opportunities, and a chance to have an immediate effect on our operations. Perhaps more importantly, we offer you old-fashioned Midwest hospitality. Come join us and get the experience you really want! View the detailed job descriptions and educational requirements by clicking on the links below! We are looking for a talented person to fill the role of Senior Systems Programmer, with a target of starting during 1st Quarter 2007. View the Job Descriptions: www.myspace.com/agcocorp Check out our corporate website by going to www.agcocorp.com. From nagle at animats.com Sun Dec 17 01:54:19 2006 From: nagle at animats.com (John Nagle) Date: Sun, 17 Dec 2006 06:54:19 GMT Subject: How to test if two strings point to the same file or directory? In-Reply-To: <1166317324.791635.274550@79g2000cws.googlegroups.com> References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: Sandra-24 wrote: > Comparing file system paths as strings is very brittle. Is there a > better way to test if two paths point to the same file or directory > (and that will work across platforms?) No. There are ways to do it for many operating systems, but there is no system-independent way. It's often not possible for files accessed across a network; the information just isn't being sent. John Nagle From flamesrock at gmail.com Wed Dec 27 22:11:21 2006 From: flamesrock at gmail.com (flamesrock) Date: 27 Dec 2006 19:11:21 -0800 Subject: socket.gaierror: (-2, 'Name or service not known') Message-ID: <1167275481.268174.168910@f1g2000cwa.googlegroups.com> Hi, Basically, I'm trying to send a multipart form to a server using some code from aspn.. here it is: MultipartPostHandler: http://pastie.caboo.se/29833 import MultipartPostHandler, urllib2, cookielib cookies = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies), MultipartPostHandler.MultipartPostHandler) login_params = { "user[login]" : "guest", "user[password]" : "guest"} url="http://localhost:2056/user/login?" opener.open(url, login_params) update_city_params = { "user[login]" : "guest", "user[password]" : "guest" , "city[cityfile]" : open("elephantia.sc4","rb"), "region[id]" : "2"} url="http://localhost:2056/simnet/update_city?" opener.open(url, update_city_params) The problem is that, while the login opener works, the update_city_params opener does not. It returns the following error: flamesrock at tux ~/send $ python send.py Traceback (most recent call last): File "send.py", line 14, in ? opener.open(url, update_city_params) File "/usr/lib/python2.4/urllib2.py", line 356, in open req = meth(req) File "/home/flamesrock/asdf/MultipartPostHandler.py", line 75, in http_request boundary, data = self.multipart_encode(v_vars, v_files) File "/home/flamesrock/asdf/MultipartPostHandler.py", line 87, in multipart_encode boundary = mimetools.choose_boundary() File "/usr/lib/python2.4/mimetools.py", line 130, in choose_boundary hostid = socket.gethostbyname(socket.gethostname()) socket.gaierror: (-2, 'Name or service not known') I simply do not know where to begin. Anyone have an idea what the error means? :/ -Thanks in Advance flamesrock From sandravandale at yahoo.com Sat Dec 16 21:26:12 2006 From: sandravandale at yahoo.com (Sandra-24) Date: 16 Dec 2006 18:26:12 -0800 Subject: How to test if two strings point to the same file or directory? In-Reply-To: References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: <1166322372.524454.301570@73g2000cwn.googlegroups.com> On Dec 16, 8:30 pm, Steven D'Aprano wrote: > On Sat, 16 Dec 2006 17:02:04 -0800, Sandra-24 wrote: > > Comparing file system paths as strings is very brittle.Why do you say that? Are you thinking of something like this? > > /home//user/somedirectory/../file > /home/user/file > > Both point to the same file. > > > Is there a > > better way to test if two paths point to the same file or directory > > (and that will work across platforms?)How complicated do you want to get? If you are thinking about aliases, > hard links, shortcuts, SMB shares and other complications, I'd be > surprised if there is a simple way. So would I. Maybe it would make a good addition to the os.path library? os.path.isalias(path1, path2) > But for the simple case above: > > >>> import os > >>> path = '/home//user/somedirectory/../file' > >>> os.path.normpath(path)'/home/user/file' The simplest I can think of that works for me is: def isalias(path1, path2): ... return os.path.normcase(os.path.normpath(path1)) == os.path.normcase(os.path.normpath(path2)) But that won't work with more complicated examples. A common one that bites me on windows is shortening of path segments to 6 characters and a ~1. -Dan From sjmachin at lexicon.net Sun Dec 24 00:13:18 2006 From: sjmachin at lexicon.net (John Machin) Date: 23 Dec 2006 21:13:18 -0800 Subject: some OT: how to solve this kind of problem in our program? In-Reply-To: References: Message-ID: <1166937198.441644.290810@79g2000cws.googlegroups.com> oyster wrote: [snip] > I have written the case 1 in python, it needs 90 seconds on my pc, and > the same approach in www.freebasic.net takes less than 1 seconds > [code for python] > import sets > import time > try: > import psyco > psyco.full() > except: > pass > > d0, d1=1, 2 > > st=time.time() > result=[] > for a0 in range(1,10): > for a1 in sets.Set(range(1,10))-sets.Set([a0]): > for a2 in sets.Set(range(1,10))-sets.Set([a0,a1]): > a1a2=a1*10+a2 > if 2*a0< a1a2: > for b0 in sets.Set(range(1,10))-sets.Set([a0,a1,a2]): > for b1 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0]): > for b2 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1]): > b1b2=b1*10+b2 > if 2*a0*b1b2 + 2*b0*a1a2 < a1a2*b1b2: > for c0 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1, b2]): > for c1 in > sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1, b2, c0]): > for c2 in > sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1, b2, c0, c1]): Has it not occurred to you to "calculate" sets.Set(range(1,10)) *ONCE*, store it, and reuse it? For the remaining uses of sets.Set, do set = sets.Set once up the front, and remember to remove it when (as you should!) you upgrade off Python 2.3. HTH, John From drake at ultech.com Fri Dec 15 14:27:05 2006 From: drake at ultech.com (drake at ultech.com) Date: 15 Dec 2006 11:27:05 -0800 Subject: Serial port failure In-Reply-To: <1166208449.351731.136780@73g2000cwn.googlegroups.com> References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> <1166208449.351731.136780@73g2000cwn.googlegroups.com> Message-ID: <1166210825.445139.315940@t46g2000cwa.googlegroups.com> drake at ultech.com wrote: ......snip> > In the second iteration of your loop, you appear to be opening a port > that is already open: > > for i in range(3): > port = OpenPort() > > thus the error message: "the serial port is unavailable". > > --Drake Smith Skip that -- I didn't notice that your port.close() was indented. From rthorpe at realworldtech.com Tue Dec 12 09:20:08 2006 From: rthorpe at realworldtech.com (Rob Thorpe) Date: 12 Dec 2006 06:20:08 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xhcw1l0sn.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7xhcw1l0sn.fsf@ruckus.brouhaha.com> Message-ID: <1165933208.789916.250730@f1g2000cwa.googlegroups.com> Paul Rubin wrote: > Pascal Costanza writes: > Yes; I'd rather go by what the standard says than rely on > implementation-dependent hacks. But in that case what do you call Python? The whole language has no standard - is it an "implementation dependent hack"? Standards are useful, but they are not the beginning and end of programming. From horpner at yahoo.com Fri Dec 15 14:38:57 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 15 Dec 2006 20:38:57 +0100 Subject: merits of Lisp vs Python References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <1166207152.706475.76020@t46g2000cwa.googlegroups.com> Message-ID: On 2006-12-15, Andr? Thieme wrote: > In Lisp it is like an IF and represents exactly what we think. > IF in Lisp: > (if expr > (then-part) > (else-part)) > > nif in Lisp: > (nif expr > (positive-part) > (zero-part) > (negative-part)) > > It looks as if it were a construct directly built into Lisp. If > one wants one could even add some additional syntax, so that it > looks like: > (nif expr > positive: > (foo1) > (foo2) > zero: > (foo3) > negative: > (foo4)) > > If you regard that idea nonsense then I suggest you to not use > Rubys if-statement anymore. But instead program your own > version "RubyIF" so that in future you have to pass all code > inside blocks to your RubyIF function. If you *really* think > that the Lisp savings are not worth it, then you would begin > with my suggestion today. I don't know how to build a house. It doesn't make me want to live in a cave. ;-) -- Neil Cerutti The third verse of Blessed Assurance will be sung without musical accomplishment. --Church Bulletin Blooper From gagsl-py at yahoo.com.ar Fri Dec 8 02:34:33 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 08 Dec 2006 04:34:33 -0300 Subject: raw strings in regexps In-Reply-To: References: Message-ID: <7.0.1.0.0.20061208043010.04084968@yahoo.com.ar> At Friday 8/12/2006 02:53, Mike wrote: >I finally simplified my problem down to this simple case: > > re.match(r'\\this', r'\\this') > >Both the pattern and the string to match are identical raw strings, yet they >don't match. What does match is this: > > re.match(r'\\\\this', r'\\this') Perhaps you can understand better with a simpler example without backslashes: >>> print re.match('(a)','(a)') None >>> print re.match(r'\(a\)', '(a)') <_sre.SRE_Match object at 0x00C5CDB0> You have to quote metacharacters if you want to match them. The escape method is useful for this: >>> re.escape('(a)') '\\(a\\)' -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From gabrielg_laburando at yahoo.com.ar Sat Dec 2 00:43:58 2006 From: gabrielg_laburando at yahoo.com.ar (Gabriel G) Date: Sat, 02 Dec 2006 02:43:58 -0300 Subject: One detail... In-Reply-To: <28574851.20771165030835616.JavaMail.nabble@jubjub.nabble.c om> References: <28574851.20771165030835616.JavaMail.nabble@jubjub.nabble.com> Message-ID: <7.0.1.0.0.20061202023845.03b55bb8@yahoo.com.ar> At Saturday 2/12/2006 00:40, robertoedwins at gmail.com wrote: >I'm trying to do in Zope, which doesn't allow "_" characters at the >beginning of identifiers. Even in an external method, it gives me an >error when I try to reference the o.a. Is there a trick to do it >some other way? Better to ask on a Zope group. But why do you want to do that? As you have noticed, you must provide security assertions for your objects so it's not an easy way. And dictionaries are fully supported by ZPT and DTML - as it appears to be what you want. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From greg at cosc.canterbury.ac.nz Mon Dec 18 21:37:33 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 19 Dec 2006 15:37:33 +1300 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> lrqjl$j4s$1@newwwwwwwwwwwwwwww elrrgs$8p6$1@geeini.csx.cam.ac.... .1166111433.32001.python-list@ppppppppppp 2$a95$1@gemini............... ailman.1607.1166112864.32031.pyyhon-list@pythonnnnnn $1@gemini.csx.cccccccccc Message-ID: <4587506D.50808@cosc.canterbury.ac.nz> Nick Maclaren wrote: > Unfortunately, you are confusing the issue, because there are far > more extraneous aspects than relevant ones, and your view of the > similarities requires looking at the issue in a very strange way. > I think that I can see what you mean, but only just. Each member of a struct has a distinct, predefined role. Even if they all have the same type, you can't swap their values around without destroying the meaning of the data. That's what's meant by "heterogeneous" in this context -- it's not about the values themselves, but the way they're used. This is the kind of thing for which Python tuples are mainly designed -- use as a struct whose members happen to be named by integers rather than strings. If you still don't understand, then I'm afraid I've run out of ideas on how to explain it. -- Greg From duncan.booth at invalid.invalid Tue Dec 26 11:28:31 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Dec 2006 16:28:31 GMT Subject: Formatting a string to be a columned block of text References: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> <459136c5$0$16985$4c368faf@roadrunner.com> <459148f5$0$16750$4c368faf@roadrunner.com> Message-ID: "Paul McGuire" wrote: > By the way, this variable contains only 3 (very long) lines of text, > one for each paragraph. (Not immediately obvious after Usenet wraps > the text.) Usenet doesn't wrap text, all it has is a convention which suggests that people posting to usenet should wrap their text at 72 characters. Your newsreader probably wrapped the text for you when you were posting, but for deliberately long lines many newsreaders will have an option somewhere to turn off the text wrapping (and the reader probably also has to turn off text wrapping when they read it). For source code where you want long unwrapped strings you would have been better to do the text wrapping in an editor first and use backslash line continuations. e.g. gettysburgAddress = """\ Four score and seven years ago our fathers brought forth on this \ continent, a new nation, conceived in Liberty, and dedicated to the \ proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, \ or any nation so conceived and so dedicated, can long endure. We are \ met on a great battle-field of that war. We have come to dedicate a \ portion of that field, as a final resting place for those who here \ gave their lives that that nation might live. It is altogether fitting \ and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not consecrate \ -- we can not hallow -- this ground. The brave men, living and dead, \ who struggled here, have consecrated it, far above our poor power to \ add or detract. The world will little note, nor long remember what we \ say here, but it can never forget what they did here. It is for us the \ living, rather, to be dedicated here to the unfinished work which they \ who fought here have thus far so nobly advanced. It is rather for us \ to be here dedicated to the great task remaining before us -- that \ from these honored dead we take increased devotion to that cause for \ which they gave the last full measure of devotion -- that we here \ highly resolve that these dead shall not have died in vain -- that \ this nation, under God, shall have a new birth of freedom -- and that \ government of the people, by the people, for the people, shall not \ perish from the earth.\ """.split('\n') From bj_666 at gmx.net Thu Dec 28 07:35:05 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Thu, 28 Dec 2006 13:35:05 +0100 Subject: answers.py v0.0.1 - source References: <87bqloz3fy.fsf@pyenos.pyenos.org> Message-ID: In <87bqloz3fy.fsf at pyenos.pyenos.org>, Pyenos wrote: > global ANSWER_PATH ``global`` at module level has no effect. That keyword is used to declare names in functions or methods global that would be local to the function otherwise and it's only needed if you want to *assign* to the global name from within a function. As this seems to be a constant it might be even an "error" to reassign the name. > global VERSION > VERSION=0.01 Version numbers aren't really numbers, so it's better to use strings here. > class Problem: > def __init__(self):self.problem="" > def set(self,problem):self.problem=problem > def get(self):return self.problem You like it compact right? :-) Take a look at the style guide: http://www.python.org/dev/peps/pep-0008/ Use more spaces. Around binary operators and the ``=`` in assignments. And newlines after the colon that introduces a body of a method or branch in an ``if``/``else`` statement and so on. Next thing are getters and setters: Don't use them it's just unnecessary typing. You don't loose the flexibility to decide to replace the simple attribute lookup by a calculated access later because Python has "properties". Look at the docs of the `property()` function. So the `Problem` can be simplified to: class Problem(object): def __init__(self, problem): self.problem = problem Maybe add docstrings to the classes and methods. > class Storage: > def add(self,problem,solution): > self.answers[problem]=solution > def save(self): > import pickle > try: pickle.dump(self.answers,file(ANSWER_PATH+".answers","w"));print "Answers saved" > except: print "Couldn't save answers. Something went wrong" Many people put ``import`` statements at the top of the module so it's very easy to find the dependencies of the module. Paths can be concatenated with `os.path.join()` in a platform independent way and pickles should always be opened in binary mode. Otherwise they won't survive transfers between operating systems in all cases. Using the ``;`` to put more than one statement on one line is even more uncommon than putting something after the ``:``. And the style guide suggests not to use lines longer than 80 characters. Don't use a bare ``except``! This catches every exception. If you mistyped a name you get a `NameError` or `AttributeError` which will be "replaced" by this rather meaningless text that's printed. In more complex programs such ``excepts`` can mask really hard to find bugs. You don't close the file which is at least a bit unclean. > def load(self): > import pickle > try: self.answers=pickle.load(file(ANSWER_PATH+".answers"));print "Answers loaded" > except: print "Couldn't load answers. Something went wrong or this may be your first time running" You might want to make load a `staticmethod` or a `classmethod` so you don't need an instance to load the answers. But this is a bit more advanced stuff. > def __init__(self,answers={}): > self.answers=answers Default arguments are only evaluated *once* when the ``def`` is executed, so all your `Storage` classes share the same dictionary. One idiom to solve this is: def __init__(self, answers=None): self.answers = answers or dict() I would expect the `__init__()` method to be the first method in a class definition followed by other special double underscore methods. Now comes a very strange and convoluted piece of code. You are "misusing" a class as namespace for other classes and nested classes with just one method that doesn't even use the `self` argument. That's an overly complex way to write a function. > class Console: > class Menu: > global storage > storage=Storage() If you want `storage` to be at module level why do you hide the binding in that nested class? > class Level0: > def do(self): > import sys > action=sys.exit() > > class Level1: > > def do(self): > problem=Problem();solution=Solution() > text=("Do you have a problem? $ ","Do you have the solution? $ ","no idea","Try again with your common sense") Why do you put all the texts into tuples so later there's a not very descriptive `text[x]` reference and one has to search the definition at another place? > commands=("answer","load(disabled, already > loaded)","quit","help") problem.set(raw_input(text[0])) > > if problem.get()==commands[0]:return 4 #elif > problem.get()==commands[1]:storage.load();return 1 elif > problem.get()==commands[2]:return 0 elif > problem.get()==commands[3]:print commands;return 1 Here you are doing something that doesn't belong here IMHO. You put potential commands into a `Problem` object. You are mixing the main menu and the input of a problem/solution in one function. The menu code would fit better in the main loop. Damned, I trimmed to much and my newsreader doesn't let me insert that overlong lines without reformatting. So without your code: You are storing the *text* of a `Solution` and a `Problem`, not the objects, so why do you have those classes at all? > def start(self): > storage.load() > level=1 > while 1: > if level==0: > Console.Menu.Level0().do() > if level==1: > level=Console.Menu.Level1().do() > if level==2: > level=Console.Menu.Level2().do() > if level==3: > level=Console.Menu.Level3().do() > if level==4: > level=Console.Menu.Level4().do() Level numbers and the function names are quite dull. It's really hard to get an idea what happens here without reading all the code and taking notes. Such constructs can be written with a dictionary which maps level numbers to functions. In this case even a list would do. Assuming the code is in ordinary functions named `level0` to `level4`: def dispatch(): levels = [level0, level1, level2, level3, level4] next_level = 1 while True: next_level = levels[next_level]() Giving the numbers meaningful names helps readability. Or even better give the functions better names and get rid of the numbers by returning the next to call function object directly. Then the `dispatch()` is just: def start_func(): ... if some_condition: return spam_func else: return eggs_func def spam_func(): ... ... def dispatch(): func = start_func while True: func =?func() Ciao, Marc 'BlackJack' Rintsch From mail at microcorp.co.za Sat Dec 23 00:26:29 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 23 Dec 2006 07:26:29 +0200 Subject: How a script can know if it has been called with the -i commandlineoption? References: <1166720012.798260.6670@80g2000cwy.googlegroups.com> <1166770486.116238.58390@a3g2000cwd.googlegroups.com> Message-ID: <006701c72653$06519760$03000080@hendrik> "Michele Simionato" wrote: > Hendrik van Rooyen wrote: > > "Michele Simionato" wrote: > > > but I don't see a way to retrieve the command line flags, where should > > > I look? > > > > sys.argv() ? > > > > - Hendrik > > No, read what Carsten said: > """ > That doesn't answer the question. The OP wants to inspect the options > passed to the interpreter, not the options passed to the script. > optparse aids in parsing sys.argv, which only contains the options that > are passed to the script. > """ True. - I was under the impression that sys.argv has all the stuff in it, but it just ain't so - I made a file called junk.py containing two lines: import sys print sys.argv and sys.argv just has junk.py in it, for both styles of command line. I also noticed that if you do the following: python junk.py -i then the interpreter is not interactive. I was also not aware that the options had positional dependency. you could do a work around by calling it like this: python -i junk.py -i then sys.argv has the extra -i... or better, insist on being told in both cases with say -i and -n at the end. it does not answer the real question, though, as someone could lie to you. - Hendrik From nntp at dvxs.net Sun Dec 3 18:49:00 2006 From: nntp at dvxs.net (Mark) Date: 03 Dec 2006 23:49:00 GMT Subject: ftputil upload error References: <1165061033.876956.275880@f1g2000cwa.googlegroups.com> Message-ID: <4573626c$0$10100$e4fe514c@dreader10.news.xs4all.nl> On Sat, 02 Dec 2006 04:03:53 -0800, Croteam wrote: > FTPIOError: 550 popravak.txt: Access is denied. Seems pretty self-explanatory to me. M From jwickard at gmail.com Thu Dec 28 10:17:52 2006 From: jwickard at gmail.com (jmw) Date: 28 Dec 2006 07:17:52 -0800 Subject: Fuzzy string comparison In-Reply-To: References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> <1167167314.463288.98960@48g2000cwx.googlegroups.com> Message-ID: <1167319072.316589.109330@48g2000cwx.googlegroups.com> Gabriel Genellina wrote: > At Tuesday 26/12/2006 18:08, John Machin wrote: > > > > I'm looking for a module to do fuzzy comparison of strings. [...] > Other alternatives: trigram, n-gram, Jaro's distance. There are some > Python implem. available. Quick question, you mentioned the data you need to run comparisons on is stored in a database. Is this string comparison a one-time processing kind of thing to clean up the data, or are you going to have to continually do fuzzy string comparison on the data in the database? There are some papers out there on implementing n-gram string comparisons completely in SQL so that you don't have to pull back all the data in your tables in order to do fuzzy comparisons. I can drum up some code I did a while ago and post it (in java). From altern2 at gmail.com Thu Dec 21 03:34:19 2006 From: altern2 at gmail.com (altern) Date: Thu, 21 Dec 2006 09:34:19 +0100 Subject: Python-list Digest, Vol 39, Issue 378 In-Reply-To: References: Message-ID: <458A470B.8060902@gmail.com> > Just a guess, but I think you need to be using at least Python 2.4 if > you are going to use IDLE version 2.4.4-2. sorry i did a typo. I am actually using python 2.4.4 > On Dec 20, 1:16 pm, altern wrote: >> Hi >> >> when i try to run IDLE on my debian laptop I get this error. >> >> $ idle >> Traceback (most recent call last): >> File "/usr/bin/idle", line 5, in ? >> main() >> File "idlelib/PyShell.py", line 1359, in main >> File "idlelib/FileList.py", line 44, in new >> File "idlelib/PyShell.py", line 105, in __init__ >> File "idlelib/EditorWindow.py", line 111, in __init__ >> File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 2764, in __init__ >> Widget.__init__(self, master, 'text', cnf, kw) >> File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1865, in __init__ >> self.tk.call( >> _tkinter.TclError: expected integer but got "`100" >> >> I am not sure about what could cause the problem because I didnt use my >> laptop for python programming for couple of weeks. Before that it worked >> fine. And on that period i might have installed few things. >> >> I am running Debian unstable with python 2.2.4, tcl8.4, tk8.4, python-tk >> 24.4-1 and IDLE 2.4.4-2. I already tried to reinstall IDLE, tk and tcl >> and python-tk but that did not solve anything, i keep getting the same >> error. >> >> any ideas? >> >> thanks >> >> enrike > > From pavlovevidence at gmail.com Mon Dec 4 16:28:31 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 4 Dec 2006 13:28:31 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165169117.866499.181520@73g2000cwn.googlegroups.com> <45732974$0$8758$ed2619ec@ptn-nntp-reader02.plus.net> <1165183970.832303.323350@73g2000cwn.googlegroups.com> <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> <1165252920.329341.284910@j44g2000cwa.googlegroups.com> <1165255758.967262.226400@73g2000cwn.googlegroups.com> Message-ID: <1165267711.364076.292000@79g2000cws.googlegroups.com> sturlamolden wrote: > Carl Banks wrote: > > > > Ok. Perhaps starting a Python JIT in something like MetaOCaml or Lisp/Scheme > > > would be a good student project? > > > > ...and finishing would be a good project for a well-funded team of > > experienced engineers. > > I think this is a good idea. We could use the AST from the CPython > compiler, translate on the fly to ANSI Common Lisp, and pass it off to > SBCL (which is very fast and supports native threads). It would even > solve the issue of Python's crappy GIL and reference counting (as > opposed to a modern garbage collector). I doubt it would work too well. Lisp's semantics differ from Python's in subtle ways, and covering the edge cases usually means you have to do all the stuff you thought you would avoid by using another dynamically-typed language. Translating Lisp integers to Python ints would work probably 99 percent of the time, but in the end you'd essentially have to reimplement the Python int type. If you're going to go through all that work, you might as well translate it to C or directly to machine code. Carl Banks From researchbase at gmail.com Sat Dec 2 02:29:11 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Sat, 2 Dec 2006 12:59:11 +0530 Subject: can't figure out how to create menus in urwid Message-ID: hello, I have been trying out urwid for creating ncurses based applications. I will like to know if any one has ever tried to create menu bar with drop down menus using urwid? any suggestion? Krishnakant. From meyer at acm.org Fri Dec 1 08:17:38 2006 From: meyer at acm.org (Andre Meyer) Date: Fri, 1 Dec 2006 14:17:38 +0100 Subject: route planning Message-ID: <7008329d0612010517o65e8b12frb5344a2fb459cd03@mail.gmail.com> Hi all Just a very simple question: where can I find a module for route planning? I have looked around and found some implementations of graph theory, e.g. http://sourceforge.net/projects/pynetwork/. But, what I need is not an abstract graph, but one where nodes/vertices have locations (2D), are connected (to follow a path, respecting distance among nodes) and where I can easily find the closest edge and vertex from any point in space. your links are much appreciated thanks Andr? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE.THIS.cybersource.com.au Sat Dec 30 21:47:31 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 31 Dec 2006 13:47:31 +1100 Subject: I want to see all the variables References: <45952426.1080800@websafe.com> <8yelh.90$Q4.82@newsfe02.lga> Message-ID: On Sat, 30 Dec 2006 11:08:10 -0800, johnf wrote: > Very detailed. But I was attempting to debug some code which subclassed > other code. I got a traceback that something like "no > mySubClass.__source.query() did not exist". The superclass had something > like "myClass.__source.query(sql)" which worked > but "mySubClass.__source.query(sql)" did not work. That's right, exactly as expected. As I said before, Python mangles the name of double-leading underscore class attributes. So when the developer of myClass wrote myClass.__source.query(sql) at compile time Python changes that to myClass._myClass__source.query(sql) When you write mySubClass.__source.query() it doesn't work because there is no attribute "__source". You need to change that to "_myClass__source" -- even when it appears in mySubClass. > So I tried to debug > using "dir(myClass.__source)" and got an error. And I also got error when > I "dir(mySubClass.__source". So how could I have debugged the problem if > dir() will not display information on the __source? I hope that explains > my issue. This isn't actually a problem with dir -- although dir does sometimes hide methods, this isn't one of those cases. This is a case of you not knowing that Python mangles the name of __attributes. What you should have done is call dir(myClass), in which case you almost certainly would have seen _myClass__source listed. -- Steven. From fredrik at pythonware.com Thu Dec 7 10:56:16 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 07 Dec 2006 16:56:16 +0100 Subject: Subprocess with a Python Session? In-Reply-To: References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> Message-ID: Giovanni Bajo wrote: >>> assert p.stdout.readline() == '10\n' > > Yeah, but WHY was the API designed like this? Why can't I read and write > freely from a pipe connected to a process as many times as I want? the subprocess module is designed to deal with Unix-style subprocesses in general, not interactive tty-based applications. you can fake it with some applications, if you make sure to flush your buffers and make sure you don't deadlock, but the right way to run an interactive tty-based application on remote is to attach it to a pseudo- tty. From rNOSPAMon at flownet.com Fri Dec 1 12:48:20 2006 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 01 Dec 2006 09:48:20 -0800 Subject: Is there a reason not to do this? References: <1164983226.620035.218790@l12g2000cwl.googlegroups.com> Message-ID: In article <1164983226.620035.218790 at l12g2000cwl.googlegroups.com>, "Carl Banks" wrote: > The principle behind this is pretty much "it was just a language design > decision". Yes, and I'm not taking issue with the decision, just pointing out that the desire to do things differently is not necessarily perverse. > P.S. If you want to be truly evil, you could use a class hook to get > the modifying in-place behavior: > > def modify_in_place(name,bases,clsdict): > cls = globals()[name] > for attr,val in clsdict.iteritems(): > setattr(cls,attr,val) > return cls > > # Replace second C2 class above with this > class C2: > __metaclass__ = modify_in_place > def m1(self): h() Doesn't work for me: >>> c2 <__main__.C2 instance at 0x51e850> >>> c2.m1() G >>> class C2: ... __metaclass__ = modify_in_place ... def m1(self): print 'Q' ... >>> c2.m1() G >>> C2().m1() Q rg From http Fri Dec 8 21:14:26 2006 From: http (Paul Rubin) Date: 08 Dec 2006 18:14:26 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <7xodqdj2dn.fsf@ruckus.brouhaha.com> <1165627958.748014.101950@16g2000cwy.googlegroups.com> <7xac1xsupm.fsf@ruckus.brouhaha.com> <1165629629.057033.282010@j44g2000cwa.googlegroups.com> Message-ID: <7x64clstml.fsf@ruckus.brouhaha.com> "JShrager at gmail.com" writes: > First off, it probably would be Lisp, but this is a mere issue of > semantics. More importantly, even if I grant you that it's not trivial > (which I'm happy to so stipulate) my point was that YOU COULD do this > if YOU wanted, How? From fredrik at pythonware.com Wed Dec 6 08:48:29 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 06 Dec 2006 14:48:29 +0100 Subject: Windows: get owner and group of a file In-Reply-To: References: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> Message-ID: Tim Golden wrote: > Wow. Python 2.2. No extensions. Not even popen (). You don't > want much, do you? I *think* the answer is that you can't. does the "group" concept even exist on Windows ? cannot recall I've ever seen "ls -l" print anything but "everyone"... From horpner at yahoo.com Wed Dec 20 08:47:17 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 20 Dec 2006 14:47:17 +0100 Subject: array, a better shell References: <1166615065.807704.12480@48g2000cwx.googlegroups.com> Message-ID: On 2006-12-20, bearophileHUGS at lycos.com wrote: > For array.array "B" means unsigned char, and such arrays accept to be > initialized from (str) strings too, this is quite useful: > >>>> from array import array >>>> a = array("B", "hello") > > But it seems such capability isn't shared with the append: > >>>> a.extend("hello") > Traceback (most recent call last): > File "", line 1, in > TypeError: an integer is required Try: >>> a.fromstring("hello") -- Neil Cerutti I have opinions of my own -- strong opinions -- but I don't always agree with them. --George W. Bush From exarkun at divmod.com Wed Dec 27 10:14:36 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 27 Dec 2006 10:14:36 -0500 Subject: how can I modify an imported variable ? In-Reply-To: Message-ID: <20061227151436.20948.1036569399.divmod.quotient.92665@ohm> On Wed, 27 Dec 2006 14:50:18 GMT, yomgui wrote: >I've tried this: > >import MyPackage >if MyPackage.aVariable is None: > MyPackage.aVariable = True > >but when I tried to access MyPackage.aVariable from another file >(ie through an other import) the value is still None. > > >how can I do this > >thanks > >yomgui You have the right idea, but you must have overlooked something. Consider this: exarkun at charm:~$ cat > foo.py a = None exarkun at charm:~$ cat > bar.py import foo foo.a = 10 exarkun at charm:~$ cat > baz.py import bar import foo print foo.a exarkun at charm:~$ python baz.py 10 exarkun at charm:~$ However, think about avoiding this pattern. Instead of using globals to track state, define a class, create an instance, and pass it to the different functions and methods of your program so that they can inspect and mutate it. If you use globals, you will end with code which is harder to unit test and harder to re-use. Jean-Paul From greg at cosc.canterbury.ac.nz Sat Dec 16 02:21:59 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 20:21:59 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <1166217335.432132.162750@l12g2000cwl.googlegroups.com> Message-ID: <4uhl7lF108ri8U3@mid.individual.net> Andr? Thieme wrote: > The thing with most (if not all) programming languages other than Lisp > is: these abstractions are leaky. > They have a low level knowledge leak. Users of aif need to know how to > pass in arguments. As you see he had do embed the code that needs execution > into a block (anon function) and then use this special syntax for x. Yes, but all the standard looping constructs, etc. in Ruby are expressed like this too. So it's perfectly consistent with the rest of the language. It's not something new that the user needs to learn just to use this function. This is even more evident in Smalltalk, where *all* control structures, without exception, are expressed in terms of code blocks, possibly with parameters. And Smalltalk has no macros, either, btw. -- Greg From roy at panix.com Thu Dec 7 14:46:17 2006 From: roy at panix.com (Roy Smith) Date: Thu, 07 Dec 2006 14:46:17 -0500 Subject: Best way to split up lines - RE: About the 79 character linerecommendation References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com> <012601c719f7$9e719990$0d7d12ac@kearfott.com> <1165519627.247663.165610@73g2000cwn.googlegroups.com> Message-ID: In article <1165519627.247663.165610 at 73g2000cwn.googlegroups.com>, "John Machin" wrote: > Roy Smith wrote: > > > It would be nice if struct.unpack() had a way to specify unpacking repeated > > items as a list, ie: > > > > data = struct.unpack ("! H 4(B) H 2B 12(B) 6(B) H I", strMessage) > > (top, > > ip, > > messageCounter, > > ackRequired, > > dataType, > > utc, > > st, > > numberOfLables, > > dataWord) = data > > > > and you'd end up with ip, utc, and st being lists. > > :-) > Extension: if you used [] in the format string, the results would be > tuples. > :-) I see your point. Actually, I think you want to force the sequences to be lists (regardless of what syntax we end up with), on the theory that tuples are for heterogeneous sequences and lists are for homogeneous ones. As for the parens, I was thinking fortran-style format specifiers, which may or may not be the best model for a modern language :-) > > Hmmm, maybe that's > > worth a PEP? > > Great minds think more-or-less alike :-) I was in the process of writing one up when I saw your earlier post. I'll mail you a draft when I've got it done. From thn at mail.utexas.edu Thu Dec 14 10:00:26 2006 From: thn at mail.utexas.edu (Thomas Nelson) Date: 14 Dec 2006 07:00:26 -0800 Subject: Non greedy regex In-Reply-To: References: <1166107546.537991.165970@t46g2000cwa.googlegroups.com> Message-ID: <1166108426.611459.195200@n67g2000cwd.googlegroups.com> There's an optional count argument that will give what you want. Try re.sub('a.*b','','ababc',count=1) Carsten Haese wrote: > On Thu, 2006-12-14 at 06:45 -0800, tibetan.houdini at gmail.com wrote: > > Can someone please explain why these expressions both produce the same > > result? Surely this means that non-greedy regex does not work? > > > > print re.sub( 'a.*b', '', 'ababc' ) > > > > gives: 'c' > > > > Understandable. But > > > > print re.sub( 'a.*?b', '', 'ababc' ) > > > > gives: 'c' > > > > NOT, understandable. Surely the answer should be: 'abc' > > You didn't tell re.sub to only substitute the first occurrence of the > pattern. It non-greedily matches two occurrences of 'ab' and replaces > each of them with ''. Try replacing with some non-empty string instead > to observe the difference between the two behaviors. > > -Carsten From tim at tdw.net Thu Dec 28 22:23:05 2006 From: tim at tdw.net (Tim Williams) Date: Fri, 29 Dec 2006 03:23:05 +0000 Subject: Comparing files in a zip to files on drive In-Reply-To: References: Message-ID: <9afea2ac0612281923r7835ed06n6c96069c5e53d1b9@mail.gmail.com> On 28 Dec 2006 18:35:15 -0800, kj7ny wrote: > I am attempting to incrementally back up files using python. How can I > compare a file on a hard drive to a file in a python created zip file > to tell if the file has changed? Or should I be using some other > method to determine if a file has changed? If you are running on an extended FAT or an NTFS filesytem you can utilise a file's archive attribute. It is set when a file is opened for modifying. See the following description of how a backup product describes the process http://www.grigsoft.com/wndsync/help/sources/abit.htm -- Tim Williams From cvanarsdall at mvista.com Wed Dec 13 14:24:58 2006 From: cvanarsdall at mvista.com (Carl J. Van Arsdall) Date: Wed, 13 Dec 2006 11:24:58 -0800 Subject: Is anyone using Python for embedded applications? In-Reply-To: <02c201c71e81$74476940$03000080@hendrik> References: <457EEC35.3090104@mvista.com> <02c201c71e81$74476940$03000080@hendrik> Message-ID: <4580538A.6010002@mvista.com> Hendrik van Rooyen wrote: > >> >> > > It depends a *lot* on what is meant by "embedded" : > Ha, very true.... > This definition seems to cover everything from: > - a cut down PC in a non standard box, through > - a processor in a Washing Machine, to > - a bare PIC processor in a Burglar Alarm... > We are considering now are mobile phone and pocket pc-esque devices. I know that several phones with arm processors are running an arm version of linux now, we're thinking how reasonable it might be to run python applications on a phone, and which python might best apply. Is there a good way to determine the "minimum requirements" for a python application? I'd imagine these might be something like the min requirements of python (cpython, pymite, etc) + additional requirements placed by the design of the application. Is there a good way to study a python application and figure that type of thing out? > I think the main hassles are that you need something big enough > to run a reasonable OS in, and it must support being programmed in C, > (which most things do), and it must have some MegaBytes of RAM > loose for the Python. (where more is merrier) > > Trying to run this on say an AVR or 8031 with a 64k address space and > a scarcity of RAM, will, to say the least, be a bit of a challenge... > > As far as the OS goes, Linux is probably the best bet, if you can get it to > fit in your hardware - It has been ported to ARM type processors from > various companies (Atmel springs to mind), and is free, which is a help > in a personal project. You could of course also roll your own kernel, > which will be good practice, as with a limited set of peripherals its not > THAT hard to do, but its a bit far away from Python - :- ) > Yea, we are thinking on the more robust end of the embedded side. So a system capable of running Linux or Windows CE (or something similar) > What display device are you going to use, or is it going to be a webserver > sitting on a power over ethernet link? > > I haven't actually taken the plunge myself yet to put Python on any of the > hardware we make, as it seems to add a lot of overhead to a simple device > - but I come from the bottom up, as it were, and the idea is intriguing, > as I in fact discovered Python because it is embedded in a GPS module > we were evaluating for building into a device - so I will follow your > progress with interest... > > -- Carl J. Van Arsdall cvanarsdall at mvista.com Build and Release MontaVista Software From g.brandl-nospam at gmx.net Sat Dec 2 03:05:02 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Sat, 02 Dec 2006 09:05:02 +0100 Subject: Python25.zip In-Reply-To: References: Message-ID: Colin J. Williams wrote: > Dennis Lee Bieber wrote: >> On Thu, 30 Nov 2006 18:14:11 -0500, "Colin J. Williams" >> declaimed the following in comp.lang.python: >> >>> As part of the Python initialization, C:\Windows\System32\Python25.zip >>> is set up in the path. >>> >>> I haven't seen any documentation on the use or purpose of the zip file. >>> >> Well, did you examine the contents of it? > There is no such file in C:\Windows\System32 - Python 2.5 on a Windows XP >> >> I believe for some versions now, "import" can pull from a ZIP >> archive -- perhaps they've put the many standard library imports into a >> single file... > Yes, since 2.3 - thanks to Fredrick for the pointer to PEP 273. That > gives the helpful warning that the above should follow the home > directory in the path list. > > PEP 302 says "[PYTHONPATH] is directly needed for Zip imports." > > The role of Python25.zip is not clear. Is it required in the path just > to enable the import X.zip capability? No. It's there just *in case* you have a Python25.zip lying around containing the library. By default, it isn't. Georg From NutJob at gmx.net Wed Dec 6 09:34:49 2006 From: NutJob at gmx.net (antred) Date: 6 Dec 2006 06:34:49 -0800 Subject: Am I stupid or is 'assert' broken in Python 2.5?? Message-ID: <1165415689.347819.129680@73g2000cwn.googlegroups.com> I've noticed something odd in Python 2.5, namely that the 2 argument version of 'assert' is broken. Or at least it seems that way to me. Run the following code in your Python interpreter: myString = None assert( myString, 'The string is either empty or set to the None type!' ) assert( myString ) You'll notice that the first assert doesn't do anything, whereas the second assert correctly recognizes that myString does not evaluate to true. That doesn't seem right. Surely Python should have raised an assertion error on the first assert statement, right?? From googlegroups at romulo.e4ward.com Mon Dec 4 12:34:45 2006 From: googlegroups at romulo.e4ward.com (Romulo A. Ceccon) Date: 4 Dec 2006 09:34:45 -0800 Subject: Factory pattern implementation in Python References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> <1165252406.405431.294040@79g2000cws.googlegroups.com> Message-ID: <1165253685.341911.60170@79g2000cws.googlegroups.com> George Sakkis wrote: > If you actually intend to > 1) name your Event subclasses Evt1, Evt2, ... EvtN and not give more > descriptive (but unrelated to the magic event number) names No, those names are just an example. The actual classes have descriptive names. > By the way, it is not clear from your description if the event number > equals to the size of the associated data. I'm sorry, George. The event number has nothing to do with the size of the associated data. I meant the program has a way to discover the size from the event number. -- Romulo A. Ceccon 'romulo%s\x40yahoo.com.br' % 'ceccon' From martin at v.loewis.de Sat Dec 2 04:43:39 2006 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 02 Dec 2006 10:43:39 +0100 Subject: python 2.5 install from source problem In-Reply-To: References: Message-ID: <45714acb$0$8594$9b622d9e@news.freenet.de> Fabian Braennstroem schrieb: > I just tried to install python 2.5 from source on my > ScienticLinux (Redhat Clone) machine. It seems to work > without any problem, at least I am able to run some of my > old scripts. I installed it with './configure > --prefix=/opt/python make make altinstall', but now for a > 'vtk' installation which needs the python libraries I am not > able to find a file like 'libpython2.5.so.*', which I think > should be produced (at least at my office's machine (redhat) > it is there). I just can find a 'libpython2.5.a' file ... > > Do I do something wrong? I'd say it is a bug in vtk that it requires libpython2.5.so.*. However, to work-around, you can configure Python with --enable-shared. Make sure to set LD_LIBRARY_PATH or LD_RUN_PATH appropriately. Regards, Martin From NO_Kroeger at gmx.de Sun Dec 10 14:45:42 2006 From: NO_Kroeger at gmx.de (=?ISO-8859-1?Q?Nils_Oliver_Kr=F6ger?=) Date: Sun, 10 Dec 2006 20:45:42 +0100 Subject: oo problem In-Reply-To: <1165759538.026560.235810@80g2000cwy.googlegroups.com> References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> <8hTeh.3185$Gr2.1738@newssvr21.news.prodigy.net> <1165759538.026560.235810@80g2000cwy.googlegroups.com> Message-ID: <457C63E6.1040506@gmx.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Tool69 wrote: > It was a matter of choice : in my earlier version, all primitives know > how to draw themselves, but they needed to have a parent and I found it > was not good for aesthetic reasons. Why should a parent reference not be aesthetic? OOD is all about Objects and their relationships. > I want now to draw an x-axis on it with some ticks and maybe lables, I > need to catch the xlowleft and xupright variables of the Paper inside > my primitive, ok ? This sentence describes the relationship between the paper and your Rectangle (to stick to your first example) as an association: The Rectangle needs to access information from the Paper. Moreover, the relationship could be named "Rectangle lies on Paper" this is perfect OOD in my opinion. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFfGPmRQeuB6ws8wERAgBgAKCiNlNU5vuVmUQQWy/Trqv2/hfd2gCg39Sh WC2+yoWA+lpJ4PNQ1sfiFTU= =UIww -----END PGP SIGNATURE----- From fgeiger at datec.at Wed Dec 20 08:22:26 2006 From: fgeiger at datec.at (F. GEIGER) Date: Wed, 20 Dec 2006 14:22:26 +0100 Subject: What am I supposed to do with an egg?! References: <1166562334.101514.36350@t46g2000cwa.googlegroups.com> Message-ID: <35aca$45893898$c2d0d373$30325@news.hispeed.ch> schrieb im Newsbeitrag news:1166562334.101514.36350 at t46g2000cwa.googlegroups.com... > Type "sudo easy_install myeggfile.egg." Sorry for not being clear. I did exec easy_install - no errors so far. But the egg was still there. I'd expected, that it was converted into .py-files somehow, which could be imported by my modules. Kind regards Morpheus > > If that gives you an error, then you don't have easy_install installed. > Install it this way: > > sudo apt-get install python-setuptools > > On Dec 19, 3:44 pm, Morpheus wrote: >> On Windows I'm used to install packages by setup.py install. So did I >> with >> Fibranet nanothreads - a few seconds and it was installed. >> >> On Linux (ubuntu 6.06) all I could get at is an egg file. I found out >> that >> I have to exec easy_install, which didn't much help here (seems to me, at >> least - sorry, Linux newbie). >> >> So, what am I supposed to do here now? >> >> Kind regards >> Morpheus > From erinhouston at gmail.com Wed Dec 20 11:50:11 2006 From: erinhouston at gmail.com (ina) Date: 20 Dec 2006 08:50:11 -0800 Subject: Any easy-to-use email send module? In-Reply-To: References: Message-ID: <1166633411.501977.167940@80g2000cwy.googlegroups.com> I put this together for some automated testing I do with an email system. I hope it is of help to you. It dosn't do cc and bcc In this version but it would be simple to add to the eMessage headder. http://phlik.ishpeck.net/index.php?P=b1114201575phlik From fredrik at pythonware.com Wed Dec 20 18:05:54 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 21 Dec 2006 00:05:54 +0100 Subject: what is wrong with my code? In-Reply-To: <874prq6wmd.fsf@pyenos.pyenos.org> References: <874prq6wmd.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > could someone tell me what things are wrong with my code? do you want a free code review, or do you have problems with the code and just forgot to mention what they are? From kentilton at gmail.com Sat Dec 9 04:28:45 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 04:28:45 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7xfybptow1.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165653338.110788.62580@n67g2000cwd.googlegroups.com> <7xfybptow1.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > > Do you know the Paul Graham piece "Beating the Averages"? It's at: > > http://www.paulgraham.com/avg.html > > The error in it is that Lisp is really just another Blub. > > http://weblog.raganwald.com/2006/10/are-we-blub-programmers.html > There we find: "But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn't realize he's looking up. What he sees are merely weird languages... Blub is good enough for him, because he thinks in Blub." What is up the power continuum from Lisp? ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From kay.schluehr at gmx.net Thu Dec 14 04:12:08 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 14 Dec 2006 01:12:08 -0800 Subject: Survey environment for Python? References: <1166083824.927340.102530@73g2000cwn.googlegroups.com> Message-ID: <1166087528.068107.234480@n67g2000cwd.googlegroups.com> exhuma.twn schrieb: > Hi, > > Just recently I had to take over support for legacy software written in > Blaise (www.cbs.nl). I don't understand the meaning of the link. Do you mean this language? http://blaise.sourceforge.net/ From rthorpe at realworldtech.com Wed Dec 20 14:33:48 2006 From: rthorpe at realworldtech.com (Rob Thorpe) Date: 20 Dec 2006 11:33:48 -0800 Subject: merits of Lisp vs Python In-Reply-To: <871wmu5sw6.fsf@thalassa.informatimago.com> References: <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <45897266$0$4158$ba624c82@nntp02.dk.telia.net> <1166637630.367729.279830@n67g2000cwd.googlegroups.com> <871wmu5sw6.fsf@thalassa.informatimago.com> Message-ID: <1166643228.669572.65650@73g2000cwn.googlegroups.com> Pascal Bourguignon wrote: > "Rob Thorpe" writes: > > Anders J. Munch wrote: > >> jayessay wrote: > >> > Please note: GC is not part of CL's definition. It is likely not part > >> > of any Lisp's definition (for reasons that should be obvious), and for > >> > the same reasons likely not part of any language's definition. > >> > >> Really? So how do you write a portable program in CL, that is to run > >> for unbounded lengths of time? > > > > You can't. > > You can. Just use reversible operations. > > Or use pre-allocated objects. Yes, that means that you implement your > own memory management or garbage collector, but this would be portable. I don't think there is any gaurantee in the spec that says that even doing nothing at all doesn't allocate more memory. AFAIK a conforming implementation could leak a fixed amount of memory per second. From Donald at dontdoithere.com Sat Dec 16 16:28:20 2006 From: Donald at dontdoithere.com (Donald) Date: Sat, 16 Dec 2006 14:28:20 -0700 Subject: How Micro-pump will change the future of computer/ mobile chips. In-Reply-To: <45845f87@clear.net.nz> References: <1166206191.003907.320530@73g2000cwn.googlegroups.com> <45845f87@clear.net.nz> Message-ID: <0_qdnUvgkPxy-RnYnZ2dnUVZ_sjinZ2d@comcast.com> Jim Granville wrote: > studyandjobs at yahoo.com wrote: > >> How Micro-pump will change the future of computer/ mobile chips. > > > FAR more hype than practical solution.... > Sorry guys, this will not "change the future of computer/ mobile chips." > >> Engineers at Purdue University have developed a tiny "micro-pump" >> cooling device small enough to fit on a computer chip that circulates >> coolant through channels etched into the chip. ............. For >> detail.... >> http://www.studyandjobs.com/Micro_pump.html >> >> or http://www.studyandjobs.com/IT_study.htm > > > ..ahh, up goes the spam-meter > > -jg > From ynd at hzw.ltindia.com Fri Dec 1 02:02:18 2006 From: ynd at hzw.ltindia.com (yndesai) Date: 30 Nov 2006 23:02:18 -0800 Subject: Python Question About Compiling. Message-ID: <1164956538.516498.14900@80g2000cwy.googlegroups.com> I got attracted to python since I heard about PythonCAD, while I used Fortran and Basic during graduation days & VBA for some macros in Office. I liked the python as it seems smart. But without compiling it is a trouble to end user. I downloaded PythonCAD and am still searching for the libraries GLIB GTK PYGTK and what not. Then there are dependancies issues of these libs on LINUX. I am scratching my head on how I would get the PythonCAD running. Is it that no compiling facility is hindering the growth of python in commercial circuit . . . ? From S.Mientki-nospam at mailbox.kun.nl Wed Dec 27 10:42:12 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Wed, 27 Dec 2006 16:42:12 +0100 Subject: persistant gloabl vars (very newbie) ? Message-ID: hi all, I'm investigating the possibilities to replace MatLab with Python (+NumPy +SciPy). I'm a very newbie, I just typed my first characters and calculated the sum of 2 and 3 in Python. My application is a Delphi program, for data-acquisition and real-time data analysis. The real-time analysis is done with MatLab, embedded through a OLE coupling. I already found PythonforDelphi which probably helps a lot to make the first steps. But I'm now stumbled about something very basic, which I don't understand. The problem might be due to the IDE I use (PyScripter), but I tried several and they all behave the same. And I expect that the observed behaviour might be very important notch in my final application (blockwise, real time interaction). In MatLab I declare a workspace, in which each variable I declare is automatically global, and can be reached from all views, i.e. from the command line interpreter as well as form the OLE environment, no matter where they are declared. I try to do something similar in Python: - I want to run an initialization part just once - I want to run some testcode often and interactively So the most simple example: #Initialization import time; A = 5; #code under test x=time.time(); # do something time consuming print 1000*(time.time()-x); Now if I run the initialization part, manual line by line in the command line interpreter, I can run the code under test as often as I want. My real initilization code is much larger and therefor very clumsy to run line by line in the command line interpreter. Is there a way to run the initialization code from a script(file) once, to achieve the same effect ? thanks, Stef Mientki From simon at brunningonline.net Tue Dec 19 05:28:24 2006 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 19 Dec 2006 10:28:24 +0000 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4587506D.50808@cosc.canterbury.ac.nz> Message-ID: <8c7f10c60612190228r15e30081s4a84fa6bd9769278@mail.gmail.com> On 19 Dec 2006 10:01:47 GMT, Nick Maclaren wrote: > > It does explain why you think of lists as homogeneous, but the > analogy doesn't hold water on closer inspection. There doesn't seem > to be ANYTHING in the specification or implementation that assumes > lists are homogeneous. As has been said a number of times in this thread, "lists are for homogeneous data" isn't a technical restriction, it's purely conceptual. It's what lists were designed for, and their API reflects this. Any by "objects of the same type", we are not talking about "type" in any technical sense. But you go ahead and put whatever you like in them if you have trouble with the idea. Similarly, the tuple API was designed for heterogeneous items where the items' position in the list has semantic meaning. Use them as you will, but don't complain if the API doesn't support what you want to do. I've had enough of this thread. You can lead a horse to water... -- Cheers, Simon B simon at brunningonline.net From pavlovevidence at gmail.com Fri Dec 22 16:32:20 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 22 Dec 2006 13:32:20 -0800 Subject: One module per class, bad idea? References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> <458c489c$1@nntp.zianet.com> Message-ID: <1166823140.827296.92960@h40g2000cwb.googlegroups.com> Erik Johnson wrote: > The file has now grown into a 6800 line beast (including docstring, > whitespace, and CVS history). Pretty much any time we implement some new > functionality, there are at least a few changes in that file. When you have > multiple developers working on different projects, and they all need to be > making changes to that file, the chances for someone making a merge error > goes up. So, we are obviously at a point where that file needs to be split > up, but there are lots of other files that import and use the one file, so > it is a task that has been put off. In retrospect, I wish I has started > things under a one class per file strategy, but at the time, it didn't make > a lot of sense to split those things up and I didn't anticipate the code > getting that big. Refactor NOW. I realize this is not as easy to do for a large team than it is for a solo programmer like me, but ISTM people tend to overestimate the cost and underestimate the benefit of it. And I've seen some pretty bad excuses besides for not doing it. (But how can we refactor when we have programmers checking stuff out all the time? Um, how bout doing it during off hours? But it's too much to do in a weekend! Which only goes to show you you've let it go too far. Refactor in small doses.) I have two files ~1000 lines that are marked as "these files are getting too big". (They currently define 20 and 24 classes--though in fairness the one with 24 has a bunch of small mixins.) Soon as this overloaded holiday season is over, they're getting broken up. > So... there's no magic "one size fits all" answer here - do what makes > sense. > > As Carl points out, decent editors should be able to handle dispaying > different files. Actually, I pointed out that decent editors should be able to handle displaying the same file twice. In case you want to edit two different points of the same file side-by-side. Carl Banks From gandalf at designaproduct.biz Fri Dec 8 10:43:42 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Fri, 08 Dec 2006 16:43:42 +0100 Subject: IMAP4 SEARCH question Message-ID: <4579882E.7080905@designaproduct.biz> Hi, I'm using imaplib to access an IMAP4 server. I'm reading the IMAP4 specification, and I found something odd. The search command can be used in conjuction with date values. For example, I would like to search for messages that are older than 30 days. However, the IMAP4 specs does not define date/time type(s). Here is a link: http://tools.ietf.org/html/rfc3501#page-16 As you can see, there are some types: NIL, Number, String and Parenthesized List. So how do I specify a date? If it is encapsulated in a string, then what format should I use? The the RFC contains an example: http://tools.ietf.org/html/rfc3501#page-49 BEFORE Messages whose internal date (disregarding time and timezone) is earlier than the specified date. Example: C: A282 SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM "Smith" S: * SEARCH 2 84 882 But of course I cannot tell what is the date format. I would like to use ISO8601 if possible. It is easy (at least from python) and it is well standardized. But will the IMAP4 server understand it? Okay, I know that I can try this with my IMAP server. But how strange it is that the RFC does not define the accepted date formats? Will my program work with any IMAP server? If any of you have experience with this, please respond. (I'm sorry, I know it is not strictly related to Python, it is more likely an RFC/IMAP question.) Best, Laszlo From guettli.usenet at thomas-guettler.de Tue Dec 12 10:11:53 2006 From: guettli.usenet at thomas-guettler.de (Thomas Guettler) Date: 12 Dec 2006 15:11:53 GMT Subject: os.popen3 hangs in Windows XP SP1, SP2. Python 2.5 & 2.4. Consistent test case. References: <1165857231.817280.152670@79g2000cws.googlegroups.com> Message-ID: <4u7v5pF15r8atU1@mid.individual.net> Pierre Rouleau wrote: > Hi all, > > I have a consistent test case where os.popen3() hangs in Windows. The > system hangs when retrieving the lines from the child process stdout. > I know there were several reports related to os.popen3() hanging under > Windows in this group before. I had a problem like this some time ago. But it was a problem that would happen under any operating system. If there is output on stdout and stderr, you will get a dead lock sooner or later. Example: The childprocess tries to write to stderr, and the parent process reads from stdin. The buffer of stderr will get full. The child will block. The parent will wait for ever. See http://docs.python.org/lib/popen2-flow-control.html My hint: Always use popen4 You can get dead locks with popen4, too. But only if you write to pipe.tochild. Thomas -- Thomas G?ttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: niemand.leermann at thomas-guettler.de From http Sat Dec 9 05:52:24 2006 From: http (Paul Rubin) Date: 09 Dec 2006 02:52:24 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165653338.110788.62580@n67g2000cwd.googlegroups.com> <7xfybptow1.fsf@ruckus.brouhaha.com> Message-ID: <7xodqdbatz.fsf@ruckus.brouhaha.com> Ken Tilton writes: > What is up the power continuum from Lisp? These days I've been fooling with Haskell. Mozart/Oz is also interesting. From johnjsal at NOSPAMgmail.com Mon Dec 4 15:06:14 2006 From: johnjsal at NOSPAMgmail.com (John Salerno) Date: Mon, 04 Dec 2006 15:06:14 -0500 Subject: Inheritance doesn't work In-Reply-To: References: <45745286$0$32597$c3e8da3@news.astraweb.com> Message-ID: <45747f90$0$17814$c3e8da3@news.astraweb.com> J. Clifford Dyer wrote: > Sure, but I think the question was more about how code that references > "MandelbrotImage could yield a stack that references MandelImage. Yeah, I guess I could have been more specific. :) From greg at cosc.canterbury.ac.nz Tue Dec 12 04:06:27 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 12 Dec 2006 22:06:27 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1165896979.850909.140700@79g2000cws.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> <1165876294.938323.233380@80g2000cwy.googlegroups.com> <4u6mf2F161jbqU2@mid.individual.net> <1165896979.850909.140700@79g2000cws.googlegroups.com> Message-ID: <4u79s5F16dujfU1@mid.individual.net> JShrager at gmail.com wrote: > Does the word "TRONDANT" hold some special meaning for you? Er, no, in fact my brain raises a KeyError on it. Is it supposed to mean anything? -- Greg From no-spam at no-spam-no-spam.invalid Fri Dec 15 06:52:58 2006 From: no-spam at no-spam-no-spam.invalid (robert) Date: Fri, 15 Dec 2006 12:52:58 +0100 Subject: cxfrozen linux binaries run on FreeBSD? Message-ID: When i freeze a python app (simple - no strange sys calls) for x86 Linux, does this stuff run well also on x86 FreeBSD? Robert From jon at ffconsultancy.com Sun Dec 17 12:52:34 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 17 Dec 2006 17:52:34 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45844272$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <2006121614375650878-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45853e98$0$8712$ed2619ec@ptn-nntp-reader02.plus.net> <200612171140567987-raffaelcavallaro@pasdespamsilvousplaitmaccom> Message-ID: <45858476$0$8715$ed2619ec@ptn-nntp-reader02.plus.net> Raffael Cavallaro wrote: > haskell and ocaml are more popular than any lisp library that tries to > imitate Haskell and ocaml. Implementing pattern matching does not mean imitating Haskell or OCaml. > This only speaks to the relative > unpopularity of imitating these features of haskell and ocaml when you > already have lisp. On the contrary, Lisp predates the features and, since their inception, most Lisp programmers have moved on to newer languages. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From python.list at tim.thechases.com Wed Dec 6 06:44:02 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 06 Dec 2006 05:44:02 -0600 Subject: What are python closures realy like? In-Reply-To: References: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> Message-ID: <4576AD02.9090708@tim.thechases.com> > def foobar(arg1, arg2, arg3): > def helper(arg): > do something with arg1 and argument > def foo(): > do something with arg1 and arg3 and > call helper > def bar(): > do something with arg1 and arg2 > def zoo(): > do something with arg2 and arg3 and > call helper > # oops; how do I return all these? > class bag(object): > pass > bag = bag() > bag.foo = foo > bag.bar = bar > bag.zoo = zoo > return bag > > which, I think, deserves no further comment... Could you please explain your reasoning behind why you opted to create the bag, fill it, and then return it? Usually I see something like return foo,bar,zoo and it would be helpful to understand the reasoning behind why one would choose one over the other. Some of the off-the-cuff thoughts in my trying to understand it: -defining a bag, instantiating a bag and filling it takes a few extra cycles for each call of foobar() so the returned tuple should be a hair faster (though perhaps defining a bag class outside the foobar() function might trim some of this?) -returning a tuple requires that any additional methods you might opt to add/return in the future involve adjusting all your code, whereas the bag method allows you to toss extra methods in the bag without adjusting every statement that calls foobar() Are either of these correct? Are there additional reasons I'm missing? Thanks, -tkc From tactics40 at gmail.com Tue Dec 26 12:15:04 2006 From: tactics40 at gmail.com (tac-tics) Date: 26 Dec 2006 09:15:04 -0800 Subject: Newbie: what is a usefull IDE for Python on Windows ? In-Reply-To: <45915397.7080604@websafe.com> References: <45915397.7080604@websafe.com> Message-ID: <1167153304.557326.151950@73g2000cwn.googlegroups.com> On Dec 26, 8:53 am, Larry Bates wrote: > Osiris wrote: > > what is a usefull IDE for Python on Windows ? I am a happy user of jEDIT. From george.sakkis at gmail.com Mon Dec 11 17:08:20 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 11 Dec 2006 14:08:20 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165623830.577613.236890@16g2000cwy.googlegroups.com> <1165652770.265978.272670@l12g2000cwl.googlegroups.com> Message-ID: <1165874900.221279.155250@n67g2000cwd.googlegroups.com> Cliff Wells wrote: > On Sat, 2006-12-09 at 00:26 -0800, hankhero wrote: > > > The Common-Lisp object systems has all and more OO-features, some which > > you never probably have thought of before. Here's one: > > Inheritance lets you specialise a method so a rectangle and a circle > > can have a different Draw method. If you wouldn't have OO you would > > need a function with if statements to dispatch on thing, if > > thing=rectange then drawRectangle if thing=circle then drawCircle. > > What if you want a draw method that takes a thing and a backend, then > > you need if statements again, draw(self,backend): if backend == > > postscript do one thing else do another. > > Maybe you can solve this with multiple inheritance, creating > > RectangePostscript and CirclePostscript objects. Lisp supports multiple > > inheritance too, but also multimethods which allow a looser coupling > > between objects and dispatching on all parameters, not only the first > > parameter (self in python speak). Just define one method > > draw(rectange,postscript) and another draw(rectangle, pdf) > > This mechanism doesn't make much sense in Python since dispatching based > on type rather than on capability is considered "bad" in the Python > world, and for good reason. > The classic example is file-like objects. What if you have two methods, > one that takes a file object and another that takes a string and you > pass an object that has string as a base class but provides file-like > capabilities? Which method should be called? Better to explicitly call > the desired method. Multimethods may make sense in many languages but > not so much in Python. Actually they do in Python too, and there's a long active discussion in the Python 3K list about whether should generic functions (aka multimethods in Lisp) be added in the language and how they blend with other concepts that compete in the same arena (interfaces, abstract base classes, etc.). Generic functions are available even today from the PEAK framework; see for example http://www-128.ibm.com/developerworks/library/l-cppeak2/. George From sandravandale at yahoo.com Thu Dec 21 20:03:05 2006 From: sandravandale at yahoo.com (Sandra-24) Date: 21 Dec 2006 17:03:05 -0800 Subject: Why can't you use varargs and keyword arguments together? In-Reply-To: References: <1166741475.082694.223630@a3g2000cwd.googlegroups.com> Message-ID: <1166749385.936883.41630@79g2000cws.googlegroups.com> On Dec 21, 5:59 pm, Jean-Paul Calderone wrote: >You just need to turn things around: > >>> def foo(a, b, c): > ... return a, b, c > ... > >>> args = range(2) > >>> foo(c=2, *args) > (0, 1, 2) > >>> You know, I feel like a real shmuck for not trying that... Thanks! -Sandra From cliff at develix.com Mon Dec 11 15:27:41 2006 From: cliff at develix.com (Cliff Wells) Date: Mon, 11 Dec 2006 12:27:41 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165652770.265978.272670@l12g2000cwl.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165623830.577613.236890@16g2000cwy.googlegroups.com> <1165652770.265978.272670@l12g2000cwl.googlegroups.com> Message-ID: <1165868861.3425.26.camel@portableevil> On Sat, 2006-12-09 at 00:26 -0800, hankhero wrote: > The Common-Lisp object systems has all and more OO-features, some which > you never probably have thought of before. Here's one: > Inheritance lets you specialise a method so a rectangle and a circle > can have a different Draw method. If you wouldn't have OO you would > need a function with if statements to dispatch on thing, if > thing=rectange then drawRectangle if thing=circle then drawCircle. > What if you want a draw method that takes a thing and a backend, then > you need if statements again, draw(self,backend): if backend == > postscript do one thing else do another. > Maybe you can solve this with multiple inheritance, creating > RectangePostscript and CirclePostscript objects. Lisp supports multiple > inheritance too, but also multimethods which allow a looser coupling > between objects and dispatching on all parameters, not only the first > parameter (self in python speak). Just define one method > draw(rectange,postscript) and another draw(rectangle, pdf) This mechanism doesn't make much sense in Python since dispatching based on type rather than on capability is considered "bad" in the Python world, and for good reason. The classic example is file-like objects. What if you have two methods, one that takes a file object and another that takes a string and you pass an object that has string as a base class but provides file-like capabilities? Which method should be called? Better to explicitly call the desired method. Multimethods may make sense in many languages but not so much in Python. Regards, Cliff From mail at microcorp.co.za Sat Dec 23 02:19:36 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 23 Dec 2006 09:19:36 +0200 Subject: Use a Thread to reload a Module? References: <312cfe2b0612221516x295949b5ka3f422d8bb41d5b@mail.gmail.com> Message-ID: <012b01c72662$b413de80$03000080@hendrik> "Gregory Pi?ero" wrote: > Hi Python Experts, > > I hope I can explain this right. I'll try. > > Background: > I have a module that I leave running in a server role. It has a > module which has data in it that can change. So every nth time a > function in the server gets called, I want to reload the module so it > has the freshest data. But there's a lot of data so it takes 5-10 > seconds to do a reload. > > My question is: > Would I be able to launch a seperate thread to reload the module while > the server does it work? Hopefully it would be using the old module > data right up until the thread was finished reloading. > have you looked at putting the data into a persistent dict? - Hendrik From mirandacascade at yahoo.com Sat Dec 16 14:17:19 2006 From: mirandacascade at yahoo.com (mirandacascade at yahoo.com) Date: 16 Dec 2006 11:17:19 -0800 Subject: sha, PyCrypto, SHA-256 Message-ID: <1166296639.483483.292380@f1g2000cwa.googlegroups.com> Operating system: Win XP Vsn of Python: 2.4 Situation is this: Required to calcluate a message digest. The process for calcluating the digest must use an SHA-256 algorithm. Questions: 1) Is it correct that the sha module comes with python 2.4? 2) Is it correct that the sha module that ships with python 2.4 does NOT have the SHA-256 capability as part of the module? 3) It looks like PyCrypto is a package that, among other things, permits one to calculate a message digest using an SHA-256 algorithm...is that correct? 4) It looks like there are a couple couple possibilities available for the download...either download the source code and run the setup which (I'm assuming) compiles the various extension modules, or download the pycrypto-2.0.1.win32-py2.4.zip which extracts out to a .exe; when one runs the just-extracted .exe, it installs the stuff on one's workstation. I'm leaning toward the second option because it seems like most of the work has been done for me. A quick search on this site didn't turn up anything that suggested there were problems with running the installer. So, my question is this: are you aware of any problems running the installer? 5) Besides PyCrypto, are there any other Python packages that permit one to calculate a message digest using an SHA-256 algorithm? Thank you. From konrad.hinsen at laposte.net Wed Dec 6 05:52:12 2006 From: konrad.hinsen at laposte.net (Konrad Hinsen) Date: Wed, 6 Dec 2006 11:52:12 +0100 Subject: About alternatives to Matlab In-Reply-To: <1165332936.164364.190860@73g2000cwn.googlegroups.com> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> Message-ID: On Dec 5, 2006, at 16:35, Mark Morss wrote: > very well-written) _Practical OCaml_. However, I also understand that > OCaml supports only double-precision implementation of real numbers; > that its implementation of arrays is a little clunky compared to > Fortran 95 or Numpy (and I suspect not as fast as Fortran's); and that > the available libraries, while powerful, are by no means as > comprehensive as those available for Python. For example, I am > unaware > of the existance of an HDF5 interface for OCaml. OCaml is a popular language with computer scientists in France (not surprisingly, given its origins), and I have regular contacts with the computer science research community, so I have been exposed quite a bit to OCaml, to the point of once considering it for numerical work. Not as a replacement for Python, but as a replacement for C or Fortran, i.e. for the heavy-duty parts of my work. What made me abandon this idea are mainly two points: 1) the lack of polymorphism 2) the difficulty of interfacing to C and Fortran code 3) the limited processor support of the native code compiler The lack of polymorphism, particularly in operators, makes OCaml code a pain to write and read in my opinion. Float arithmetic is already bad enough, with "+." etc. everywhere. If I add complex and vector types (which could easily be defined in OCaml), I'd have to come up with two more sets of arithmetic operators that make my code less readable. In addition, I'd either have to keep multiple implementations for many algorithms, or pass in all operators and mathematical functions as arguments. Neither solution is acceptable for me. Interfacing to C and Fortran code is important because that's what most libraries are written in. While it is possible in principle with OCaml, it is (or at least was at the time I looked) a pain to interface typical array-handling code, for lack of a compatible data structure on the OCaml side. Native code compilation is obviously important for speed. While many popular processors are supported by ocamlopt, scientific users are notorious for grabbing whatever fast hardware they can lay their hands on. It seems safe to count on the GNU suite being ported rapidly to any new platform. I don't have as much faith in the OCaml developers, though perhaps just out of ignorance. Konrad. From tshepang at gmail.com Tue Dec 19 07:31:27 2006 From: tshepang at gmail.com (Tshepang Lekhonkhobe) Date: Tue, 19 Dec 2006 14:31:27 +0200 Subject: on PySol's popularity Message-ID: <857993970612190431m48de4735w24576d96ce54724b@mail.gmail.com> Hi, On Python docs, on faq/installed.html, it's mentioned that PySol is the most common Python application. Is this a platform-specific fact? From burhan.khalid at gmail.com Sat Dec 2 08:28:04 2006 From: burhan.khalid at gmail.com (Burhan) Date: 2 Dec 2006 05:28:04 -0800 Subject: Printing Barcodes from webapp? In-Reply-To: <1165063816.365760.264300@73g2000cwn.googlegroups.com> References: <1165040626.505772.312350@j72g2000cwa.googlegroups.com> <1165063816.365760.264300@73g2000cwn.googlegroups.com> Message-ID: <1165066083.993153.28350@l12g2000cwl.googlegroups.com> Andy Dingley wrote: > Burhan wrote: > > > Is there an easy way to generate barcodes using Python > > Easy way for any application or language to generate barcodes is to > install a barcode font on the client machine, then just generate a > suitable text string for it. This is _very_ easy, if you can get the > font deployed. I usually find myself using Code 39 and printing them > from a HTML document. There are plenty of free code 39 fonts around and > the string mangling to get the barcode structured correctly is just a > trivial prefix / suffix. I thought about this as an option too, but I do not have control over the client machines, maybe I'll use this and go with the PDF idea mentioned above. Thanks for all the links, I have some reading to do now. From kenneth.m.mcdonald at sbcglobal.net Wed Dec 27 17:08:32 2006 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Wed, 27 Dec 2006 16:08:32 -0600 Subject: Getting unicode escape sequence from unicode character? Message-ID: <4592EEE0.5030501@sbcglobal.net> Given a Python unicode character (string of length one), how would I find out the \uXXXX escape sequence for it? This isn't obvious from the docs I've been looking through. Thanks, Ken From fredrik at pythonware.com Fri Dec 15 13:28:13 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 19:28:13 +0100 Subject: parsing a dictionary from a string In-Reply-To: <4582B45E.6000405@molgen.mpg.de> References: <4582B45E.6000405@molgen.mpg.de> Message-ID: Benjamin Georgi wrote: > I could use some help extracting the keys/values of a list of > dictionaries from a string that is just the str() representation of the > list (the problem is related to some flat file format I'm using for file > IO). > > Example: > >>> s = str(dict_list) > >>> s > '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]' > > Then, what I want to do is to reconstruct dict_list given s. > Now, one possible solution would be > > >>> dict_list = eval(s) > > but since the content of s cannot be blindly trusted I`d rather not do > it that way. Basically my question is whether there is another solution > which is simpler than using regular expressions. here are a couple of cut-and-paste alternatives: use the tokenizer and a simple parser pattern: http://groups.google.com/group/comp.lang.python/msg/a34397ba74892b4e use the compiler module and analyze the parse tree: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 note that you cannot parse Python's expression syntax with plain regular expressions; RE's are only good enough for lexical analysis. From gagsl-py at yahoo.com.ar Mon Dec 4 18:39:31 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 04 Dec 2006 20:39:31 -0300 Subject: Factory pattern implementation in Python In-Reply-To: <1165250357.794022.87520@16g2000cwy.googlegroups.com> References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061204202637.01f96008@yahoo.com.ar> At Monday 4/12/2006 13:39, googlegroups at romulo.e4ward.com wrote: >class Factory: > def __isValidEventClass(self, obj): > if inspect.isclass(obj) and obj != events.EvtBase and \ > events.EvtBase in inspect.getmro(obj): > for m in inspect.getmembers(obj): > if m[0] == 'eventNum': > return True > return False > > def __init__(self): > self.__eventDict = {} > for m in inspect.getmembers(events, self.__isValidEventClass): > cls = m[1] > self.__eventDict.update({cls.eventNum: cls}) > > def parseEvents(self, file): > while not file.eof(): > ev = file.read(1) > self.__eventDict[ev](file).execute() You already got other ways to go. But if you want to use several classes (maybe span along several modules), you can code the checking a lot more easily: if issubclass(cls, EvtBase) and hasattr(cls, 'eventNum'): ... I'd register each class itself, so no need to iterate over the members, but anyway you could use vars(module). In short, inspect may be good for debugging or documenting tools, but hardly needed for usual code. BTW, that file format is horrible. Users have to know *every* posible event (at least its size), even if the're not interested in them. And if you get out of sync, you can't recover. Add a new event, and all programs using the file don't work anymore. Ugh! -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From tali.wang at gmail.com Mon Dec 4 23:18:22 2006 From: tali.wang at gmail.com (Linan) Date: 4 Dec 2006 20:18:22 -0800 Subject: Async callback in python Message-ID: <1165292302.454012.118540@n67g2000cwd.googlegroups.com> Hi, In javascript, code could be written like this: ... var _p=XMLHttpRequest(); _p.open('GET',url,true); _p.send(null); _p.onreadystateChange=function(){ if(_p.readyState==4) cb(_p.responseText); } ... This basic AJAX code allows function to be called when it's invoked, without blocking the main process. There is same library asyncore in python. However, I can't validate it's asynchronous through code: class T(asyncore.dispatcher): def __init__(self,host,url): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((host,80)) self.url='GET %s HTTP/1.0\r\n\r\n' % url def handle_connect(self): pass def handle_close(self): self.close() def handle_read(self): print 'READING.....' print self.recv(256) def handle_write(self): sent=self.send(self.url) self.url=self.url[sent:] t=T('aVerySlowSite','/') asyncore.loop() for i in range(0,10): print '%d in main process' % i time.sleep(1) Suppose it's asynchronous, couple of '%d in main process' lines should be mixed in the output of T.handle_read(), right? But I found that actually main process was blocked at asyncore.loop(), until the the socket was closed. My questions: 1, Did I do anything wrong? 2, Is it real asynchronous? 3, If not, where to get the real one(s)? Any comment is welcome :) From at at tuko.nl Wed Dec 13 09:56:30 2006 From: at at tuko.nl (at) Date: Wed, 13 Dec 2006 15:56:30 +0100 Subject: Conditional iteration Message-ID: <4580149c$0$321$e4fe514c@news.xs4all.nl> I would like to spark the discussion about the following syntax problem I encounter. THE PROBLEM I have a lot times the following code: for x in [-2, -1, 0, 1, 2, 3, 4]: if x > 0: ... more code... It is not the addional line containing 'if x > 0:' that bothers me, but the additional indentation. THE SOLUTION More pythonic in view would be: for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0: ... more code ... This blends basically [x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0] and x = y if x > 0 else 10 EXTENDING And maybe a few usefull variants, like: for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0 else -x: ... more code ... In this case x will be 2, 1, 0, 1, 2, 3, 4. From toolmaster at 163.com Tue Dec 26 20:38:56 2006 From: toolmaster at 163.com (WaterWalk) Date: 26 Dec 2006 17:38:56 -0800 Subject: Noobie: Open file -> read characters & multiply In-Reply-To: <1167182523.297579.96720@n51g2000cwc.googlegroups.com> References: <1167182314.180326.204340@i12g2000cwa.googlegroups.com> <1167182523.297579.96720@n51g2000cwc.googlegroups.com> Message-ID: <1167183536.468897.163820@h40g2000cwb.googlegroups.com> WaterWalk wrote: > WaterWalk wrote: > > gonzlobo wrote: > > > I've been using Python for a few days. It's such the perfect language > > > for parsing data! > > > > > > I really like it so far, but I'm having a hard time reading a file, > > > reading the first few hex characters & converting them to an integer. > > > Once the characters are converted to an integer, I'd like to write the > > > data to another file. > > > > > > Here's the code snipped to the bare minimum: > > > --- > > > # Open File > > > AP_File= open("AP.txt", "r") > > > decoded_File= open("decoded.txt", "w") > > > > > > # read & process data line by line > > > for line in AP_File: > > > time = int(hex(line[0:8]), 16) * 0.0001 # this line is completely hosed! > > > decodedFile.write(time) > > > > > > #close files > > > AP_File.close() > > > decoded_File.close() > > > --- > > > AP.txt > > > 000000d5 26 0600 80 00 ec 80 02 03 7d db 02 33 > > > 000000d5 26 0601 80 00 80 00 02 37 fe 54 01 09 > > > 000000d5 06 0602 80 00 e0 00 01 29 fe d2 69 99 > > > 000000d5 06 0603 80 00 e0 00 02 29 fe d2 6a 99 > > > 000000d5 26 0604 80 00 fe 54 02 09 80 00 01 5d > > > 000000d5 06 0605 80 00 e0 00 02 15 fc 71 ca 0b > > > 000000d5 4a 0610 81 00 86 00 02 26 12 00 02 a6 > > > 000000d5 4f 0611 00 00 00 50 00 00 00 00 07 00 > > > 000000d5 06 0612 80 00 e0 00 01 15 fc 71 c9 0b > > > 000000d5 0a 0613 08 5c 04 88 08 98 00 00 00 00 > > > 000000d5 06 0614 80 00 e0 00 02 01 60 79 82 2b > > > 000000d5 0a 0615 08 00 00 00 00 00 00 00 00 00 > > > 000000d5 26 0616 80 00 80 00 02 5d 04 22 3a 88 > > > (actual files are 250MB!) > > > > > > decodedTime.txt (should be) > > > 0.0213 26 0600 80 00 ec 80 02 03 7d db 02 33 > > > ... > > > > > > My boss and I are trying to complete the same task (he figured out how > > > to do it, but his code uses a while != "" loop and doesn't look > > > pythony (it looks too 'c'). Not that there's anything wrong with that! > > > > > > Any help is really appreciated. > > > > Use the built-in int(). It has an optional argument "radix" which > > specifies the base for the conversion. For example: > > >>> int("0x0A", 16) > > >>> 10 > > Oh I forget that ">>>" will cause the line to be hidden by default. The > example is: > int("0x0A", 16) # will return 10 I misunderstand the question, sorry for this. Why not just split the line read since each number is separated by space or tab. After splitting there is a list of numbers, then convert the first element and write the list into a file. From craigtw.online at gmail.com Tue Dec 5 22:08:42 2006 From: craigtw.online at gmail.com (Craig) Date: 5 Dec 2006 19:08:42 -0800 Subject: Opening colour BMPs with PIL References: <1165270585.753466.62440@l12g2000cwl.googlegroups.com> Message-ID: <1165374522.690440.302060@l12g2000cwl.googlegroups.com> Fredrik Lundh wrote: > Craig wrote: > > > I'm trying to open colour BMPs using PIL and I'm getting the following > > errors. > > what program did you use to produce those BMP files? can you prepare > reasonably small samples using the same program and post them somewhere? > > Thanks for the reply. I'm using Microsoft Paint to create the files so that's most likely the problem (surprise, surprise). I found that by using GIMP to create them has no problems with opening BMP images. I'll just keep using GIMP instead. From tartifola at gmail.com Fri Dec 1 11:21:46 2006 From: tartifola at gmail.com (Tartifola) Date: Fri, 1 Dec 2006 17:21:46 +0100 Subject: Simple question on indexing Message-ID: <20061201172146.ceb8a7f8.tartifola@gmail.com> Hi, I would like to obtain the position index in a tuple when an IF statement is true. Something like >>>a=['aaa','bbb','ccc'] >>>[ ??? for name in a if name == 'bbb'] >>>1 but I'm not able to find the name of the function ??? in the python documentation, any help? Thanks From toolmaster at 163.com Tue Dec 26 20:22:03 2006 From: toolmaster at 163.com (WaterWalk) Date: 26 Dec 2006 17:22:03 -0800 Subject: Noobie: Open file -> read characters & multiply In-Reply-To: <1167182314.180326.204340@i12g2000cwa.googlegroups.com> References: <1167182314.180326.204340@i12g2000cwa.googlegroups.com> Message-ID: <1167182523.297579.96720@n51g2000cwc.googlegroups.com> WaterWalk wrote: > gonzlobo wrote: > > I've been using Python for a few days. It's such the perfect language > > for parsing data! > > > > I really like it so far, but I'm having a hard time reading a file, > > reading the first few hex characters & converting them to an integer. > > Once the characters are converted to an integer, I'd like to write the > > data to another file. > > > > Here's the code snipped to the bare minimum: > > --- > > # Open File > > AP_File= open("AP.txt", "r") > > decoded_File= open("decoded.txt", "w") > > > > # read & process data line by line > > for line in AP_File: > > time = int(hex(line[0:8]), 16) * 0.0001 # this line is completely hosed! > > decodedFile.write(time) > > > > #close files > > AP_File.close() > > decoded_File.close() > > --- > > AP.txt > > 000000d5 26 0600 80 00 ec 80 02 03 7d db 02 33 > > 000000d5 26 0601 80 00 80 00 02 37 fe 54 01 09 > > 000000d5 06 0602 80 00 e0 00 01 29 fe d2 69 99 > > 000000d5 06 0603 80 00 e0 00 02 29 fe d2 6a 99 > > 000000d5 26 0604 80 00 fe 54 02 09 80 00 01 5d > > 000000d5 06 0605 80 00 e0 00 02 15 fc 71 ca 0b > > 000000d5 4a 0610 81 00 86 00 02 26 12 00 02 a6 > > 000000d5 4f 0611 00 00 00 50 00 00 00 00 07 00 > > 000000d5 06 0612 80 00 e0 00 01 15 fc 71 c9 0b > > 000000d5 0a 0613 08 5c 04 88 08 98 00 00 00 00 > > 000000d5 06 0614 80 00 e0 00 02 01 60 79 82 2b > > 000000d5 0a 0615 08 00 00 00 00 00 00 00 00 00 > > 000000d5 26 0616 80 00 80 00 02 5d 04 22 3a 88 > > (actual files are 250MB!) > > > > decodedTime.txt (should be) > > 0.0213 26 0600 80 00 ec 80 02 03 7d db 02 33 > > ... > > > > My boss and I are trying to complete the same task (he figured out how > > to do it, but his code uses a while != "" loop and doesn't look > > pythony (it looks too 'c'). Not that there's anything wrong with that! > > > > Any help is really appreciated. > > Use the built-in int(). It has an optional argument "radix" which > specifies the base for the conversion. For example: > >>> int("0x0A", 16) > >>> 10 Oh I forget that ">>>" will cause the line to be hidden by default. The example is: int("0x0A", 16) # will return 10 From aahz at pythoncraft.com Wed Dec 27 12:58:55 2006 From: aahz at pythoncraft.com (Aahz) Date: 27 Dec 2006 09:58:55 -0800 Subject: loose methods: Smalltalk asPython References: Message-ID: In article , Jan Theodore Galkowski wrote: > >I think Python is very fine although, arguably, because many are >approaching it from a Java strong-typing static mindset, I bet the space >of design possibilities hasn't been explored thoroughly. We've not had >an excellent dynamic OO language since Smalltalk, IMO. Perhaps Ruby is >or is not. But I've looked a bit at Ruby, and I like Python more. Guido was opposed to modifying builtin types before Java existed. It's similar to his opposition to dynamic syntax. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I support family values -- Addams family values" --www.nancybuttons.com From python at hope.cz Mon Dec 18 10:52:17 2006 From: python at hope.cz (Lad) Date: 18 Dec 2006 07:52:17 -0800 Subject: How to replace a comma In-Reply-To: References: <1166446034.406136.225770@80g2000cwy.googlegroups.com> Message-ID: <1166457137.799412.57850@l12g2000cwl.googlegroups.com> Nick Craig-Wood wrote: > Lad wrote: > > In a text I need to add a blank(space) after a comma but only if > > there was no blank(space) after the comman If there was a > > blank(space), no change is made. > > > > I think it could be a task for regular expression but can not > > figure out the correct regular expression. > > You can do it with a zero width negative lookahead assertion, eg > > >>> import re > >>> s="One, Two,Three,Four, File" > >>> re.sub(r",(?!\s)", ", ", s) > 'One, Two, Three, Four, File' > >>> > > From the help :- > > (?!...) > Matches if ... doesn't match next. This is a negative lookahead > assertion. For example, Isaac (?!Asimov) will match 'Isaac ' only if > it's not followed by 'Asimov' > > Or in a more straightforward but less efficient and accurate style - > this matches the next character which gets added back into the string. > > >>> re.sub(r",([^\s])", r", \1", s) > 'One, Two, Three, Four, File' > >>> > > This shows a fundamental difference between the two methods > > >>> t = ",,,,," > >>> re.sub(r",(?!\s)", ", ", t) > ', , , , , ' > >>> re.sub(r",([^\s])", r", \1", t) > ', ,, ,,' > >>> Nick, Thanks a lot.It works GREAT! La. From george.sakkis at gmail.com Tue Dec 19 08:24:25 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 19 Dec 2006 05:24:25 -0800 Subject: urllib.unquote and unicode References: <1166497058.109088.53120@80g2000cwy.googlegroups.com> Message-ID: <1166534664.998906.306930@a3g2000cwd.googlegroups.com> Fredrik Lundh wrote: > George Sakkis wrote: > > > The following snippet results in different outcome for (at least) the > > last three major releases: > > > >>>> import urllib > >>>> urllib.unquote(u'%94') > > > > # Python 2.3.4 > > u'%94' > > > > # Python 2.4.2 > > UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0: > > ordinal not in range(128) > > > > # Python 2.5 > > u'\x94' > > > > Is the current version the "right" one or is this function supposed to > > change every other week ? > > why are you passing non-ASCII Unicode strings to a function designed for > fixing up 8-bit strings in the first place? if you do proper encoding > before you quote things, it'll work the same way in all Python releases. I'm using BeautifulSoup, which from version 3 returns Unicode only, and I stumbled on a page with such bogus char encodings; I have the impression that whatever generated it used ord() to encode reserved characters instead of the proper hex representation in latin-1. If that's the case, unquote() won't do anyway and I'd have to go with chr() on the number part. George From markc.westwood at gmail.com Fri Dec 1 04:06:56 2006 From: markc.westwood at gmail.com (Mark Westwood) Date: 1 Dec 2006 01:06:56 -0800 Subject: why would anyone use python when java is there? In-Reply-To: References: <1164762232.220759.57160@h54g2000cwb.googlegroups.com> Message-ID: <1164964016.836666.251860@f1g2000cwa.googlegroups.com> may I, as a former Englishman, say how proud we always were to be exploited by our betters many thanks guv Mark Jonathan Smith wrote: > gavino wrote: > > wtf > > Java is a coffee, and coffee comes from exploited Ethiopians (they do > have some damn fine coffee, though). Most of us prefer to exploit > Englishmen instead. (damn them and their humor!) > > -smithj From metaperl at gmail.com Thu Dec 14 02:07:37 2006 From: metaperl at gmail.com (metaperl) Date: 13 Dec 2006 23:07:37 -0800 Subject: Pythonic style involves lots of lightweight classes (for me) Message-ID: <1166080057.944449.158320@n67g2000cwd.googlegroups.com> I find it arduous to type dictionary['key'] and also feel that any data I create for a program deserves to have its operations tied to it. As a result, I often create lots of lightweight classes. Here's a small example: vlc = '/Applications/VLC.app/Contents/MacOS/VLC' class song(object): def __init__(self, title, url): self.title = title self.url = url urls = [ song(title='breath', url='mms://ra.colo.idt.net/ginsburgh/eng/med/breath.mp3'), song(title='waking', url= 'mms://ra.colo.idt.net/ginsburgh/eng/med/modeh.mp3') ] for url in urls: print url.title .... The above program started out as a list of dictionaries, but I like the current approach much better. From jdhunter at ace.bsd.uchicago.edu Thu Dec 7 16:45:41 2006 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 07 Dec 2006 15:45:41 -0600 Subject: memory error with matplot References: <1165324360.959614.55970@j72g2000cwa.googlegroups.com> Message-ID: <874ps7z8fu.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "lisa" == lisa engblom writes: lisa> Hi, I am using matplotlib with python to generate a bunch of lisa> charts. My code works fine for a single iteration, which lisa> creates and saves 4 different charts. The trouble is that lisa> when I try to run it for the entire set (about 200 items) it lisa> can run for 12 items at a time. On the 13th, I get an error lisa> from matplotlib that says it can't access data. However, if lisa> I start the program at the point it failed before it works lisa> fine and will create the charts for the next 12 before lisa> failing. I assume that I am not closing the files properly lisa> somehow or otherwise misallocating memory. I tried just lisa> reimporting pylab each iteration, but that didn't help. lisa> This is the function that creates a chart: There are a couple of things to try. First, on a long shot, does it help to do close(1) instead if simply close(). I don't think it will but worth a try. Second, I think there is a small leak in the tkcanvas, but not in matplotlib proper. Do you need to display the graphs you are creating, or do you merely want to save them? If the latter, simply use the Agg backend import matplotlib matplotlib.use('Agg') *before* you import pylab. Finally, if you are still having troubles, post a complete, free-standing, script to the matplotlib mailing list and we'll see if we can replicate it. You may also want to take a look at the FAQ on memory leaks: http://matplotlib.sourceforge.net/faq.html#LEAKS JDH From george.sakkis at gmail.com Mon Dec 18 21:57:38 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 18 Dec 2006 18:57:38 -0800 Subject: urllib.unquote and unicode Message-ID: <1166497058.109088.53120@80g2000cwy.googlegroups.com> The following snippet results in different outcome for (at least) the last three major releases: >>> import urllib >>> urllib.unquote(u'%94') # Python 2.3.4 u'%94' # Python 2.4.2 UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0: ordinal not in range(128) # Python 2.5 u'\x94' Is the current version the "right" one or is this function supposed to change every other week ? George From rdiaz02 at gmail.com Tue Dec 12 07:44:26 2006 From: rdiaz02 at gmail.com (Ramon Diaz-Uriarte) Date: Tue, 12 Dec 2006 13:44:26 +0100 Subject: About alternatives to Matlab In-Reply-To: <457e9647$0$8742$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> <1165252920.329341.284910@j44g2000cwa.googlegroups.com> <1165255758.967262.226400@73g2000cwn.googlegroups.com> <1165267711.364076.292000@79g2000cws.googlegroups.com> <457be14b$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <1165766069.028619.284860@80g2000cwy.googlegroups.com> <457d5c9c$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <7x64cir1ox.fsf@ruckus.brouhaha.com> <457e9647$0$8742$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <624934630612120444l4b16bf57w44224085fbea3171@mail.gmail.com> On 12/12/06, Jon Harrop wrote: > Paul Rubin wrote: > > Well, work is already under way (already mentioned) to implement > > Python in Python, including a reasonable compiler (Psyco). > > > > The big deficiency of MLton from a concurrency perspective is > > inability to use multiprocessors. Of course CPython has the same > > deficiency. Same with OCaml. Is the ML community trying to do > > anything about this? > > Yes. Several MLs support concurrency. Perhaps F# is the most notable in this > case because it would provide an easier path to JIT (to .NET IL). > > Concurrent GC seems to be a lot slower though (e.g. Java or .NET vs OCaml or > MLton). > Would this be of any interest? (specially since the Lisp vs. Python thread seems to be dying out :-). Its Scheme (Gambit, so one of the speedy Schemes) with Erlang-like concurrency http://toute.ca/ http://lambda-the-ultimate.org/node/841 Best, R. > -- > Dr Jon D Harrop, Flying Frog Consultancy > Objective CAML for Scientists > http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From gagsl-py at yahoo.com.ar Thu Dec 14 19:05:52 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 14 Dec 2006 21:05:52 -0300 Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: <1166127221.944683.65150@l12g2000cwl.googlegroups.com> References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> <1166127221.944683.65150@l12g2000cwl.googlegroups.com> Message-ID: <7.0.1.0.0.20061214205430.05995628@yahoo.com.ar> At Thursday 14/12/2006 17:13, rich murphy wrote: >Thanks to everyone who responded with valuable suggestions. I >appreciate them all. I found the exact reason why "import" command >fails. > >At the beginning I created my script file with MS Notepad. After >studying all the advice, I realized that I did not try other text >editors just becuase the tutorial says: "use your favorite text editor >to create a file called fibo.py in the current directory with the >following contents:" I bet your file is actually called fibo.py.txt then. (Perhaps some advise should be provided for Windows users, about enclosing the name inside "double quotes", or selecting "All files (*.*)" on the file type list) >Then I created another file with the same stuff in it using WordPad. >The behaviour of the "import" command improved a lot but still not >good. Uhm... either the import was successful, or not. Care to explain what you mean? > >>> fibo.fib2(100) >Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\fibo.py", line 11, in fib2 > while b < n: >UnboundLocalError: local variable 'b' referenced before assignment Compare your function with the version shown in the tutorial. Variable 'b' is assigned on the previous line. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From gagsl-py at yahoo.com.ar Thu Dec 7 02:39:49 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 04:39:49 -0300 Subject: extension programing with c In-Reply-To: <48928.96681.qm@web53605.mail.yahoo.com> References: <7.0.1.0.0.20061206234411.0542f6d0@yahoo.com.ar> <48928.96681.qm@web53605.mail.yahoo.com> Message-ID: <7.0.1.0.0.20061207042718.0371f6e0@yahoo.com.ar> At Thursday 7/12/2006 03:24, mahdieh saeed wrote: >thanks for your help .I compile these code with out "\" but when I >import module name insert error occurs like this: > >ImportError: Shared object "libdb-4.5.so" not found >--------------------------------------------------------- >my python code is the following: Please keep posting on the list, many others may have more clues than I. Your python code looks OK; the problem is that library not found. ldd may help, but since this is not related to python, you should look for help in a more convenient place. Anyway, are you sure the standard module bsddb is not enough? -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From paul at boddie.org.uk Sun Dec 10 11:15:34 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 10 Dec 2006 08:15:34 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165762281.579645.56990@l12g2000cwl.googlegroups.com> Message-ID: <1165767334.350312.36020@l12g2000cwl.googlegroups.com> hit_the_lights wrote: > [import side-effects] > Somehow the meaning of "import" changed between the first > and the second line. Doesn't it frighten you? > (BTW: Do you know how that works, or should a Lisper show > you?) Given that the meaning of import doesn't need to have changed to bring out the described consequences, I guess anyone wanting to know more won't be asking you specifically. > It seems that Phytonistas, including Guido, don't trust each > other. Guido always provides half assed restrictive solutions > instead of decent meta programming. Examples include "lambda", > the new "with" syntax and decorators. Actually there are people in the Python community who don't really approve of stuff like "with", the removal of "lambda" and the lack of macros, "programmable syntax", and so on. But that's probably not apparent to those who paint every picture with broad strokes. Paul From larsnostdal at gmail.com Wed Dec 27 00:35:11 2006 From: larsnostdal at gmail.com (=?iso-8859-1?q?Lars_Rune_N=F8stdal?=) Date: Wed, 27 Dec 2006 06:35:11 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1166906310.452197.185700@48g2000cwx.googlegroups.com> Message-ID: On Sat, 23 Dec 2006 12:38:30 -0800, Fuzzyman wrote: > > Lars Rune N?stdal wrote: >> On Fri, 08 Dec 2006 03:07:09 -0800, Mark Tarver wrote: >> >> > How do you compare Python to Lisp? What specific advantages do you >> > think that one has over the other? >> > >> > Note I'm not a Python person and I have no axes to grind here. This is >> > just a question for my general education. >> > >> > Mark >> >> Kill this frakkin thread; Lisp rules -- while Python is boring (but better >> than many other alternatives). E.O.F. >> > > Perhaps only with the addendum that although 'Lisp roolz', no-one uses > for anything of relevance anymore and it is continuing it's geriatric > decline into obscurity. ;-) Screw it; I'll die a "non-professional" programmer if I have to. Meanwhile ridiculing and scorning all the fools using inferior languages. *hah!* If I can't do what I love when it comes to programming I'd rather have a shitty non-programming job that enables me to instantly forget what I've been doing while at work as soon as I'm done for the day. My trade -- my tools. :} -- Lars Rune N?stdal http://nostdal.org/ From robert.kern at gmail.com Thu Dec 14 09:56:49 2006 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 14 Dec 2006 06:56:49 -0800 Subject: About alternatives to Matlab In-Reply-To: <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> <1166035311.357588.115070@80g2000cwy.googlegroups.com> <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: Jon Harrop wrote: > Filip Wasilewski wrote: >> from numpy import ones, arange, reshape, int32 >> a = ones((2,3,4,5)) >> b = ones(a.shape, dtype=int32) >> c = ones((3,4,5)) >> d = 2*a + 2.5*(3*b + 3.3) >> d[0] = d[0] + 5 >> d[1] *= c * (2+3*1.2) >> d[:,2,...] = reshape(arange(d[:,2,...].size), d[:,2,...].shape) >> print d[...,1] > > I can't get that to work in Python. What do I need to do? > >>>> import numpy >>>> a = ones((2,3,4,5)) > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'ones' is not defined Use the code that Filip wrote: from numpy import ones, arange, reshape, int32 -- 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 From roy at panix.com Sun Dec 17 20:45:45 2006 From: roy at panix.com (Roy Smith) Date: Sun, 17 Dec 2006 20:45:45 -0500 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4584E986.10502@cosc.canterbury.ac.nz> <4um6tgF18l1srU1@mid.individual.net> Message-ID: In article <4um6tgF18l1srU1 at mid.individual.net>, greg wrote: > Roy Smith wrote: > > > The struct does lookup by name, the tuple is inherently index based. > > I was trying to help people understand the distinction > we're talking about by showing an example of the same > distinction in another language where it's much clearer. > > There are a great many ways in which C structs are > different from Python tuples, and C arrays are different > from Python lists. But they're not the aspects I'm > drawing an analogy between. > > -- > Greg Well, yeah, but it's kind of like saying "a tangerine and an orange are very different things because one of them is like an apple and the other one is like a pear" :-) From nospam at foo.com Sun Dec 10 20:54:47 2006 From: nospam at foo.com (jayessay) Date: 10 Dec 2006 20:54:47 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > "Kaz Kylheku" writes: > > > Lisp just seems hopelessly old-fashioned to me these days. A > > > modernized version would be cool, but I think the more serious > > > Lisp-like language designers have moved on to newer ideas. > > > > What are some of their names, and what ideas are they working on? > > http://caml.inria.fr > http://www.haskell.org Aren't these "old-fashioned" and boring as well? /Jon -- 'j' - a n t h o n y at romeo/charley/november com From infoac at accsys-corp.com Wed Dec 6 14:02:07 2006 From: infoac at accsys-corp.com (renguy) Date: 6 Dec 2006 11:02:07 -0800 Subject: Getting started with the Python source References: <1165428508.314773.181130@l12g2000cwl.googlegroups.com> <1165431419.747335.227940@80g2000cwy.googlegroups.com> Message-ID: <1165431727.248930.248430@80g2000cwy.googlegroups.com> Thank you for your response. I guess I was looking for a more specific answer. I have the source and I have been looking around at the various code. I think my question is, what is the name of the toplevel source code file of C code for the Python interpreter, and what is the name of the toplevel source code file for IDLE? Does that make sense? Thanks again. dakman at gmail.com wrote: > Actually IDLE was written purley in python, you can find the sources to > it in... > > UNIX: /usr/lib/python/idlelib > Windows: C:\Python\Lib\idlelib > > If you are looking to modifly mostly just the IDE I would start there, > however if you are more interesting in modifying python Itself just > look around in the sources, it should be relativley easy to find. > > renguy wrote: > > I am interested in making some changes and additions to the Python > > environment (Python and IDLE). I have the source code and can build the > > source, but what I want to know is what are the "main" functions or > > source code for Python and IDLE. Specifically I would like to know what > > in Python and IDLE would be analogous to void main () in a standard C > > program. This will help me to work out the structure of the interpreter > > and the environment. Your help will be greatly appreciated. The changes > > I wish to make are for investigating the modification of the Python > > environment for novice programmers. From greg at cosc.canterbury.ac.nz Wed Dec 20 06:09:17 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 21 Dec 2006 00:09:17 +1300 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> lrqjl$j4s$1@newwwwwwwwwwwwwwww elrrgs$8p6$1@geeini.csx.cam.ac.... .1166111433.32001.python-list@ppppppppppp 2$a95$1@gemini............... ailman.1607.1166112864.32031.pyyhon-list@pythonnnnnn $1@gemini.csx.cccccccccc <4587506D.50808@cosc.canterbury.ac.nz> Message-ID: <458919DD.40901@cosc.canterbury.ac.nz> Nick Maclaren wrote: > It does explain why you think of lists as homogeneous, but the > analogy doesn't hold water on closer inspection. There doesn't seem > to be ANYTHING in the specification or implementation that assumes > lists are homogeneous. Then what do you think is suggested by the fact that lists have an index() method but tuples don't? That's how this whole discussion got started -- someone wanted an explanation of why that is so. The explanation is that tuples and lists were designed for different use cases. You don't *have* to use them that way, but if you use them differently, you're on your own and can't complain if they don't have all the features you want. -- Greg From laurent.pointal at limsi.fr Wed Dec 6 02:58:52 2006 From: laurent.pointal at limsi.fr (Laurent Pointal) Date: Wed, 06 Dec 2006 08:58:52 +0100 Subject: About the 79 character line recommendation In-Reply-To: References: Message-ID: Olivier Langlois a ?crit : > Hi, > > There was a coding standard where I worked and the intention behind this > requirement was to make the code printer friendly. Printing code source > with lines longer than 80 chars greatly hinder readability on paper. Try using size 10 font in place of size 12 when printing. Still readable, print correctly longer lines. [ :-) but I try to keep lines under the 80 columns too :-) ] > > Greetings, > Olivier Langlois > http://www.olivierlanglois.net >> I also think that limiting code to 80 columns often hinders >> readability. I personally try to limit my code to 100 columns. The end >> result is pretty nice. >> >> However, I'm all for the "flat is better than nested" philosophy, even >> when nested is under 100 columns. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list From cavada at itc.it Thu Dec 21 11:58:33 2006 From: cavada at itc.it (Roberto Cavada) Date: Thu, 21 Dec 2006 17:58:33 +0100 Subject: [ANNOUNCE] pygtkmvc version 1.0.0 has been released Message-ID: <458ABD39.1070502@itc.it> Hi all, I'm proud to announce that the first stable release 1.0.0 of pygtkmvc has been released. -------------------------------- ** pygtkmvc version 1.0.0 ** -------------------------------- pygtkmvc is a fully Python-based implementation of the Model-View-Controller (MVC) and Observer patterns for the PyGTK2 toolkit. MVC is a pattern that can be successfully used to design and develop well structured GUI applications. The MVC pattern basically helps in separating semantics and data of the application from their representation. The Observer pattern helps to weaken dependencies among parts that should be separated, but need to be connected each other. pygtkmvc provides a powerful and still simple infrastructure to help designing and implement GUI applications based on the MVC and Observer patterns. -------------------------------- ** Features ** -------------------------------- The framework has been designed to be: - Essential and small, it does only what it was designed for. - Not an external dependency for your application: it fits in 80KB and can be released along with it. - Easy to understand and to use; fully documented. - Portable: straightly runs under many platforms. Version 1.0.0 is the first stable release. Main features are: - Observer pattern supports pythonian containers and user-defined classes. - Support for multi-threading in models. - Support for gtk models like TreeModel and TextBuffer. - Bug fixes. - Documentation and several examples are provided. -------------------------------- ** Get it! ** -------------------------------- Latest version and information can be found at the project home page: License is LGPL. -------------------------------- ** Credits ** -------------------------------- Many thanks to: - Baruch Even for providing useful feedback and a pretty example. - Johannes Jordens and Robert Jordens for depeloping and maintaining Debian packages. -- Roberto Cavada From paddy3118 at netscape.net Sun Dec 10 18:37:05 2006 From: paddy3118 at netscape.net (Paddy) Date: 10 Dec 2006 15:37:05 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165769504.098173.101860@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> Message-ID: <1165793825.487994.52430@f1g2000cwa.googlegroups.com> JShrager at gmail.com wrote: > Paddy wrote: > > Python is fun to use. > > Easy to read. > > Simple and powerful. > > Easy to test. > > Easy to maintain. > > Fast. Very fast! > > Okay, I'm going to commit another rhetorical fallacy here called > "Argument from Authority": I challenge anyone making psychological > claims about language X (for any X) being easier to either > read/learn/use than language Y (for any Y) to come up with any valid > evidence whatever. Having a PhD in Cognitive Psychology (as well as two > degrees in computer science) where my subject was how people learn to > program (among other things), and having extensive experience in this > field, I am almost certain that no such evidence exists (at least not > for any real programming language). Now, like any good scientist, I > could be wrong, but you'd have to convince me, and I very much doubt > that you could. Whilst you wait for 'evidence' proving that, for any languages X and Y, for example, befunge is easier to grasp than Logo; people who have tried Python and found it easier to learn than other languages can switch to Python, (welcome, by the way); and just get things done. , > > While I'm engaging in this particular fallacy, here's another instance: > Since I'm probably (although I'm not certain) the only person in this > thread who has made a significant amount of money on either of these > languages (i.e., via the sale of a startup whose product was tens of > thousands of lines of Lisp code, and some Tk GUI stuff), and knowing > both Lisp and Python (although I'm certainly not a Python wizard), I am > nearly certain that what we did in Lisp COULD NOT HAVE BEEN DONE IN > PYTHON -- PERIOD. The reason has little to do with macros (although > they were very helpful, of course, esp. in making Tcl look like a > reasonable language so that we could use Tk); it has to do with speed, > which has to do with compilers, which, as it turns out, has to do with > macros. (See below.) Maybe for your application, but others think that speed is more to do with algorithm. Python has to rely more on using the right algorithm but it makes algorithm exploration easier than some languages, embedding good algorithms for things like sort, and allowing the wrapping of libraries optimised in other languages. > > Now, speaking as a scientist, permit me to make a small practical > suggestion: Speaking as an engineer please allow me to make the large practical suggestions ;-) > Python -- make parens (or whatever) optionally replace whitespace and > line breaks as syntax -- and then add a simple macro facility -- macros > are actually a very simple extension if you have homogenous syntax, > homogenizing your syntax to the point where macros are possible is the > hard part -- and just see what happens. One of two general things are > likely to happen: Either people will not use them, and they will > languish and die, and then at least you can say; "Been there, done > that" to the Lisp community. Or, more likely, the some subset of the > Python community will get it, and will figure out how useful they are, > although it might take some time. And then you might find yourself with > a wonderful new tool. You might even get a compiler out of the deal, at > a pretty low cost, too! If you get macros, and get a compiler, I'm > pretty sure that you will have no problem winning over the Lisp > community, who would LOVE to have your extensive libraries, and that > you will probably be able to maintain and improve your flagging > position wrt Ruby (which, according to Matz, is more-or-less just Lisp > w/o macros.) > > I'm not saying that this is going to be an easy or quick experiment, > but it's one that I, and I think most Lispers, would both like to see > happen, and would benefit from! Moreover, I dare say that some of us in > the Lisp community would love to HELP -- at least I would, and I'm > guessing that others would as well. Talk to these guys: http://en.wikipedia.org/wiki/PyPy they have an interesting take on Pythons interpreter, and their work is being used as part of a Python->C++ flow.. > > (Unless you guys get a compiler too, you'll always just be a > scripting language, Guess what. Scripting Language is not a pejorative term. If you mean that python can only be used for 'glue code' then, you'r right, you don't know enough about Python. > but compilers are GREATLY facilitated by having a > macro facility because (at first blush) all you need to do is to > macro-expand down to something you know how to turn into code. This > isn't the only, nor perhaps the best way to get a compiler, but it's > a step in that direction. Later on you can learn the other great > features offered by homogeneous syntax, like being able to write code > walkers, which help improve over the "first blush" compiler. Soon > enough, I predict, you'll be so far past us and Ruby that...well, > even Kenny with jump on board! :-) Code walkers? Do you mean reflection? Python has this unsung module called doctest that neatly shows some of the strengths of python: http://en.wikipedia.org/wiki/Doctest - Paddy. From fredrik at pythonware.com Fri Dec 8 12:04:08 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 08 Dec 2006 18:04:08 +0100 Subject: Problem in reading a URL In-Reply-To: <66b602900612080847v2e54123di4c0b8eca96d54b2a@mail.gmail.com> References: <66b602900612080847v2e54123di4c0b8eca96d54b2a@mail.gmail.com> Message-ID: ???????? ?????? wrote: > I get an error, when I am trying to read URL. > Where is the Problem? did you read the error message you got from the server? > Error: History is unavailable either because it has expired or because > your system cannot accept href='/entrez/query/static/faq.html#Acceptscookies'>cookies From aine_canby at yahoo.com Wed Dec 6 04:27:00 2006 From: aine_canby at yahoo.com (aine_canby at yahoo.com) Date: 6 Dec 2006 01:27:00 -0800 Subject: Novice: replacing strings with unicode variables in a list Message-ID: <1165397220.491511.159310@f1g2000cwa.googlegroups.com> Hi, Im totally new to Python so please bare with me. Data is entered into my program using the folling code - str = raw_input(command) words = str.split() for word in words: word = unicode(word,'latin-1') word.encode('utf8') This gives an error: File "C:\Python25\lib\encodings\cp850.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in position 0 : character maps to but the following works. str = raw_input(command) words = str.split() for word in words: uni = u"" uni = unicode(word,'latin-1') uni.encode('utf8') so the problem is that I want replace my list with unicode variables. Or maybe I should create a new list. I also tried this: for word in words[:]: word = u"" word = unicode(word,'latin-1') word.encode('utf8') print word but got TypeError: decoding Unicode is not supported. What should I be doing? Thanks for your help, Aine. From rsmckown at yahoo.com Wed Dec 6 12:05:48 2006 From: rsmckown at yahoo.com (R. Steve McKown) Date: Wed, 6 Dec 2006 10:05:48 -0700 Subject: Extension causes segmentation fault -- suggestions on troubleshooting? Message-ID: <200612061005.49140.rsmckown@yahoo.com> Hello, I'm writing a C extension for cygwin python to access a vendor supplied DLL that allows one to set the general purpose IO (gpio) pins of the Silicon Labs' cp2103 USB/serial chip. We communicate to the device using the vendor's virtual com port driver, but the gpio pins allow us access to other functions, like resetting the device and initiating a firmware download. The DLL provides a function, CP210xRT_WriteLatch which sets the gpio pins. It accepts the HANDLE of the open device's com port, a bit mask, and a bit data field to perform its task. Note: I load the DLL dynamically within the extension's init function. Even though the DLL functions are C, apparently the vendor did not use "extern C {", as the functions have C++-like decorations (seen via 'nm' on the .lib file) and cygwin's gcc linker generates symbol not found errors when linking to the provided .lib. Dynamically loading the library works. FWIW, the DLL is said to be compiled via VC++ 6.0. Also using the vendor supplied .h file. The extension code, python test program, stackdump output and program run output are included in the attached tgz file for reference. Th extension accepts a file descriptor to an open serial port, uses the cygwin get_osfhandle() function to get the corresponding HANDLE, calls the DLL function, then returns. When run, python core dumps somewhere between the return statement in the extension function and the python program statement following the call to the extension function. The gpio bits are set correctly. If I comment out the call to the DLL function within the extension, no core dump. Obviously, the gpio bits are not set in this case. If I do not open the com port in the python program, but instead call CreateFile/CloseFile within the extension itself and using the HANDLE provided by CreateFile to call the DLL function, the gpio bits are set and no core dump. I could live with this approach if Python could have the com port open when it calls the extension. When I try this, the extension's call to CreateFile to open the com port always fails, presumably because the serial module opens it in some manner that doesn't allow sharing...? Being relatively new to Python, I'm hoping someone can see an obvious mistake, or suggest some strategies to troubleshoot this problem. Thank you for your time, Steve -------------- next part -------------- A non-text attachment was scrubbed... Name: cp210x_rt.tgz Type: application/x-tgz Size: 2771 bytes Desc: not available URL: From martin at v.loewis.de Thu Dec 21 15:29:49 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 21 Dec 2006 21:29:49 +0100 Subject: urllib.unquote and unicode In-Reply-To: References: <1166497058.109088.53120@80g2000cwy.googlegroups.com> <1166504578.169707.154900@n67g2000cwd.googlegroups.com> <4588507E.20602@v.loewis.de> Message-ID: <458AEEBD.5040702@v.loewis.de> >>> The way that uri encoding is supposed to work is that first the input >>> string in unicode is encoded to UTF-8 and then each byte which is not in >>> the permitted range for characters is encoded as % followed by two hex >>> characters. >> Can you back up this claim ("is supposed to work") by reference to >> a specification (ideally, chapter and verse)? > http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1 Thanks. Unfortunately, this isn't normative, but "we recommend". In addition, it talks about URIs found HTML only. If somebody writes a user agent written in Python, they are certainly free to follow this recommendation - but I think this is a case where Python should refuse the temptation to guess. If somebody implemented IRIs, that would be an entirely different matter. Regards, Martin From rschroev_nospam_ml at fastmail.fm Thu Dec 14 15:56:33 2006 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 14 Dec 2006 20:56:33 GMT Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: <1166127221.944683.65150@l12g2000cwl.googlegroups.com> References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> <1166127221.944683.65150@l12g2000cwl.googlegroups.com> Message-ID: <5Uigh.236877$Lb3.5051427@phobos.telenet-ops.be> rich murphy schreef: > This not fine: >>>> fibo.fib2(100) > [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] > > > When I enter "fibo.fib2(100)", I get the following: > >>>> fibo.fib2(100) > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\fibo.py", line 11, in fib2 > while b < n: > UnboundLocalError: local variable 'b' referenced before assignment Can you show the code of fib2? It looks like there's an error in it, but without the code it's hard to say anything about it. > Both Python2.4 and 2.5 are behaving the same. I will also try to create > the file with Vi editor. If by Vi you mean Vim, that's my favorite editor for editing Python code, with Idle second. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From bjorn.kempen at gmail.com Wed Dec 27 20:41:16 2006 From: bjorn.kempen at gmail.com (buffi) Date: 27 Dec 2006 17:41:16 -0800 Subject: can't instantiate following inner class In-Reply-To: <87mz586eyx.fsf@pyenos.pyenos.org> References: <87mz586eyx.fsf@pyenos.pyenos.org> Message-ID: <1167270076.196904.242380@48g2000cwx.googlegroups.com> Pyenos wrote: > class One: > Two() #can't instantiate > class Two: > Three() #can't instantiate > class Three:pass Python parses code from top to bottom. Since it first tries to read the class One and finds the class Two inside it, it throws an error since it is not defined yet. Reverse the order and it will work (like this:) class Three:pass class Two: Three() class One: Two() Of course this makes no sense whatsoever as the poster above me wrote. The reason that you can use classes in the order the second poster wrote is because of init not being called until you make an instance of that class, and by then all classes are loaded. /buffi (buffis.com) From carsten at uniqsys.com Wed Dec 6 22:16:49 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Wed, 06 Dec 2006 22:16:49 -0500 Subject: how to convert a function into generator? In-Reply-To: References: Message-ID: <1165461409.3319.20.camel@localhost.localdomain> On Wed, 2006-12-06 at 17:33 +0100, Sch?le Daniel wrote: > def permute3gen(lst): > lenlst = len(lst) > def permute(perm, level): > if level == 1: > yield perm > return # not sure return without a value is allowed, > theoretically it could be replaces with if/else block > for i in lst: > if i not in perm: > permute(perm + (i,), level - 1) ##1## > for item in lst: > yield permute((item,), lenlst) # makes generator from the outer > function too ##2## Your only problem is in knowing what to do with recursively invoked sub-generators. You have two such invocations, which I marked above with ##1## and ##2##, and neither one is handled correctly. In ##1##, you construct a sub-generator and simply discard it. In ##2##, you construct a sub-generator, and yield it (instead of yielding its elements). In neither case do you actually consume any of the elements that the sub-generators are prepared to produce. To usefully invoke a sub-generator, you need to consume it (i.e. iterate over it) and yield whatever it produces. Hope this helps, Carsten From rthorpe at realworldtech.com Wed Dec 20 15:43:26 2006 From: rthorpe at realworldtech.com (Rob Thorpe) Date: 20 Dec 2006 12:43:26 -0800 Subject: merits of Lisp vs Python In-Reply-To: <45899b0a$0$4169$ba624c82@nntp02.dk.telia.net> References: <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <45897266$0$4158$ba624c82@nntp02.dk.telia.net> <1166637630.367729.279830@n67g2000cwd.googlegroups.com> <45899b0a$0$4169$ba624c82@nntp02.dk.telia.net> Message-ID: <1166647406.816210.166750@i12g2000cwa.googlegroups.com> Anders J. Munch wrote: > Rob Thorpe wrote: > > Anders J. Munch wrote: > >> Really? So how do you write a portable program in CL, that is to > >> run for unbounded lengths of time? > > > > You can't. > > > > The thing about the spec not defining GC is almost a bit of humour. > > No-one would use an implementation with no GC. > > > > The issue with specifying it is: How would you do it? The memory > > used by a program is an aspect of the language implementation and > > the system the program is running on, so how can it be defined in a > > useful way? > > Let u(t) be the actual memory used by the program at time t. > Let r(t) be the size of reachable memory at time t. > > Require that u(t) is a member of O(t -> max{t'<=t: r(t')}) > > There. That wasn't so hard, was it? That's quite a clever definition actually. But, let's say I have a lisp machine. It has an unusual architecture, it's made entirely of SRAM cells of ~9bits. Sometimes these cells are used as storage, sometimes their contents represent logic circuits and the routing between them is configured to form them into a processor. Please tell me what reachable memory is ;). (The above processor is not science fiction, it could easily be done with FPGAs) I suppose a solution would be:- If the lisp implementation runs on a fixed processor that has separate storage then ... Let u(t) be the actual memory used by the program at time t. Let r(t) be the size of reachable memory at time t. ... From mcPas.De.Spam at mclaveauPas.De.Spam.com Wed Dec 6 09:19:28 2006 From: mcPas.De.Spam at mclaveauPas.De.Spam.com (Michel Claveau) Date: Wed, 06 Dec 2006 15:19:28 +0100 Subject: Python Plugin for Web Browser References: <1165389943.093365.20590@80g2000cwy.googlegroups.com> <1165391969.824391.174140@l12g2000cwl.googlegroups.com> Message-ID: Re ! Je ne sais pas quel est ton objectif, mais il est possible de couplet Python & Javascript, de mani?re ? g?n?rer/modifier/piloter le contenu HTML de pages Web depuis Python. Je fais ?a tous les jours (avec IE) Pour cela je passe par COM. Malheureusement, ? cause de la parano?a s?curitaire ambiante, il y a de plus en plus de contraintes et d'obtacles. Ainsi, s'il n'y a pas (encore) trop de probl?mes tant que l'on est en local (avec les .HTA, par exemple), d?s que l'on est distant (Intranet, Extranet, Web), il y a maintenant des confirmations ? tout bout de champ, des avertissements peu utiles, mais devenus incontournables, des bo?te de dialogues intempestives, etc. Donc, si c'est pour utiliser comme interface pour des applis sur le disque (ou le r?seau local), OK ; sinon, ?a posera des probl?mes. C'en est ? tel point que je me demande si l'utilisation de frontaux HTML comme GUI est toujours int?ressante. Et le probl?me ne touche pas que Python. Par exemple, j'ai un client qui utilise un logiciel de gestion de l'assurance qualit?, utilisant des navigateurs comme interface. Du coup, ils ont des patchs 2 fois par mois, et les utilisateurs ont toujours plus choses ? valider... -- @-salutations Michel Claveau From since_humans_read_this_I_am_spammed_too_much at spamyourself.com Tue Dec 19 05:10:36 2006 From: since_humans_read_this_I_am_spammed_too_much at spamyourself.com (Erwin Moller) Date: Tue, 19 Dec 2006 11:10:36 +0100 Subject: regular expression References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> Message-ID: <4587ba9c$0$320$e4fe514c@news.xs4all.nl> Asper Faner wrote: > I seem to always have hard time understaing how this regular expression > works, especially how on earth do people bring it up as part of > computer programming language. Natural language processing seems not > enough to explain by the way. Why no eliminate it ? I am sure you'll get an answer in one of zillion groups you posted this stupid question to... Regards, Erwin From debarchana.ghosh at gmail.com Sat Dec 23 12:44:50 2006 From: debarchana.ghosh at gmail.com (debarchana.ghosh at gmail.com) Date: 23 Dec 2006 09:44:50 -0800 Subject: removing the header from a gzip'd string In-Reply-To: <4v0f53F1afe47U1@mid.individual.net> References: <1166735512.435837.60080@42g2000cwt.googlegroups.com> <4v0f53F1afe47U1@mid.individual.net> Message-ID: <1166895890.297135.144990@i12g2000cwa.googlegroups.com> Bjoern Schliessmann wrote: > Rajarshi wrote: > > > Does anybody know how I can remove the header portion of the > > compressed bytes, such that I only have the compressed data > > remaining? (Obviously I do not intend to perform the > > decompression!) > > Just curious: What's your goal? :) A home made hash function? Actually I was implementing the use of the normalized compression distance to evaluate molecular similarity as described in an article in J.Chem.Inf.Model (http://dx.doi.org/10.1021/ci600384z, subscriber access only, unfortunately). Essentially, they note that the NCD does not always bevave like a metric and one reason they put forward is that this may be due to the size of the header portion (they were using the command line gzip and bzip2 programs) compared to the strings being compressed (which are on average 48 bytes long). So I was interested to see if the NCD behaved like a metric if I removed everything that was not the compressed string. And since I only need to calculate similarity between two strings, I do not need to do any decompression. From paddy3118 at netscape.net Sun Dec 17 03:22:55 2006 From: paddy3118 at netscape.net (Paddy) Date: 17 Dec 2006 00:22:55 -0800 Subject: Metaclass uses? In-Reply-To: References: Message-ID: <1166343775.821520.212210@j72g2000cwa.googlegroups.com> Nathan Harmston wrote: > Also is there anymore interesting OO stuff that Python has apart from Java. Duck Typing: http://www.thescripts.com/forum/thread22721.html; http://mindview.net/WebLog/log-0025, Python does not have checked exceptions: http://www.mindview.net/Etc/Discussions/CheckedExceptions - Paddy. From inq1ltd at verizon.net Sat Dec 30 11:45:12 2006 From: inq1ltd at verizon.net (jim-on-linux) Date: Sat, 30 Dec 2006 11:45:12 -0500 Subject: Easiest way to print from XP/DOS. In-Reply-To: References: Message-ID: <200612301145.12579.inq1ltd@verizon.net> Thanks, The client is in a one printer office. If the output file is opened with note and then sent to the printer everything is fine but it defeats the purpose of the utility. Also tried > lpt1 but the same results. I'm trying to find out if this was some change in xp from previous versions, or is there something abnormal going on. I'm trying to avoid setting up an xp machine for one client. jim-on-linux On Saturday 30 December 2006 03:05, Tim Roberts wrote: > jim-on-linux wrote: > >Did you run from a file or type in from > > keyboard? > > > >When the client runs the utility program the > >output file is built but nothing prints and no > >messages appear. When I typed from keyboard on > > an xp pro at c:\, I got the message. > > > >Is it possible that virus detector or some > >self.defense software is interacting? > > It is quite possible that they simply do not > have a printer hooked up to their computer's > parallel port. If all of your printers are > from network shares, then the special file > "prn" will not go anywhere. > > Typing to "prn" is a dreadful way to do > printing on Windows. -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. From flamesrock at gmail.com Wed Dec 27 23:33:47 2006 From: flamesrock at gmail.com (flamesrock) Date: 27 Dec 2006 20:33:47 -0800 Subject: socket.gaierror: (-2, 'Name or service not known') In-Reply-To: References: <1167275481.268174.168910@f1g2000cwa.googlegroups.com> Message-ID: <1167280427.860283.80340@f1g2000cwa.googlegroups.com> Ahh that works! thanks a bunch Gabriel Gabriel Genellina wrote: > At Thursday 28/12/2006 00:11, flamesrock wrote: > > > >The problem is that, while the login opener works, the > >update_city_params opener does not. It returns the following error: > >flamesrock at tux ~/send $ python send.py > >Traceback (most recent call last): > > File "send.py", line 14, in ? > > opener.open(url, update_city_params) > > File "/usr/lib/python2.4/urllib2.py", line 356, in open > > req = meth(req) > > File "/home/flamesrock/asdf/MultipartPostHandler.py", line 75, in > >http_request > > boundary, data = self.multipart_encode(v_vars, v_files) > > File "/home/flamesrock/asdf/MultipartPostHandler.py", line 87, in > >multipart_encode > > boundary = mimetools.choose_boundary() > > File "/usr/lib/python2.4/mimetools.py", line 130, in choose_boundary > > hostid = socket.gethostbyname(socket.gethostname()) > >socket.gaierror: (-2, 'Name or service not known') > > MultipartPostHandler uses mimetools.choose_boundary; it relies on > socket.gethostbyname returning a sensible result for your machine. > But sometimes it fails: > http://mail.python.org/pipermail/python-list/2003-October/232722.html > It may be a bug in Python, or in the sockets implementation, or > somewhere. Anyway, choose_boundary() should be robust enough to catch > the possible exception and act accordingly, I think. > > In the meantime, you may put this near the top of your script: > > mimetools._prefix = "some-random-string-you-like" > > > -- > 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 From cvanarsdall at mvista.com Tue Dec 12 12:51:49 2006 From: cvanarsdall at mvista.com (Carl J. Van Arsdall) Date: Tue, 12 Dec 2006 09:51:49 -0800 Subject: Is anyone using Python for embedded applications? Message-ID: <457EEC35.3090104@mvista.com> I'm aware of a couple python projects for embedded systems. I am currently considering using Python on an embedded platform to develop a simple application as a personal project, mostly to see if it will work. I was wondering if anyone here was using python for anything of that nature? For those that are involved in these types of projects, how does development in python differ for embedded projects versus a non-embedded project? Is there a community standard technique or style for this type of development (i.e. heavy in OO design? commonly used patterns?) Are there any good tools to assist for this type of development environment? Oh, and if anyone has opinions/facts on why python should not be used in an embedded platform, I'd like to know that too. I'm somewhat familiar with pythons needs on a system, but there are a number of things I am not aware of. Thanks to everyone for their input! -carl -- Carl J. Van Arsdall cvanarsdall at mvista.com Build and Release From jUrner at arcor.de Sun Dec 3 16:44:56 2006 From: jUrner at arcor.de (jUrner at arcor.de) Date: 3 Dec 2006 13:44:56 -0800 Subject: Using win32gui.SendMessage and SysListView32 control In-Reply-To: <1165176116.034632.58270@f1g2000cwa.googlegroups.com> References: <1165176116.034632.58270@f1g2000cwa.googlegroups.com> Message-ID: <1165182296.347980.53620@f1g2000cwa.googlegroups.com> geskerrett at hotmail.com schrieb: > Hope someone can steer me in the right direction. > > I am trying to use python to collect the values from a Win32 > application's control. > I can successfull query an retreive the values ListBox, Edit and > Buttons, however, the application uses a control called a > 'SysListView32' Control. MSDN says that this descends from CListView > control and the msdn website reference for this control is; > http://msdn2.microsoft.com/en-gb/library/ms670560.aspx > (scroll to the message constants) > > This page seems to imply that the control can be queried with messages, > however, my problem seems to be that pywin32.win32con does not define a > constant for the LVM series of messages. > > All the relevant message ids are in comCtl.h a 340k file. This might explain why win32con does only cover some ids. Best is to download and install the platform sdk, wich you may get for free from Microsoft. It comes shipped along with all the headers and the complete documentation for all the apis windows offers the dedicated programmer. http://www.microsoft.com/downloads/details.aspx?familyid=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en And ...just a hint, check the ctypes module, wich will give you full access to all the apis windows has to offer and lets you translate C code almost 1:1 to python. Regards J?rgen From http Sat Dec 2 23:00:46 2006 From: http (Paul Rubin) Date: 02 Dec 2006 20:00:46 -0800 Subject: Non-exhaustive file reads References: Message-ID: <7x1wnhr5ld.fsf@ruckus.brouhaha.com> Fredrik Tolf writes: > mode, but nowhere can I find any information about how to enable > non-blocking mode in Python. > > Can anyone provide me with any information on how to accomplish this? In Linux you'd use fcntl. Some other discussion can be found on the web: http://www.google.com/search?q=python+non-blocking+mode From skip at pobox.com Wed Dec 6 21:39:06 2006 From: skip at pobox.com (skip at pobox.com) Date: Wed, 6 Dec 2006 20:39:06 -0600 Subject: dict.has_key(x) versus 'x in dict' In-Reply-To: References: <4tnvstF14cki5U1@mid.individual.net> Message-ID: <17783.32458.730462.8403@montanaro.dyndns.org> Peter> Bjoern Schliessmann wrote: >> Wouldn't be "if k in d.keys()" be the exact replacement? Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less Peter> (constant) overhead for the function call. 'k in d.keys()' on the Peter> other hand creates a list of keys which is then searched linearly Peter> -- about the worst thing you can do about both speed and memory Peter> footprint. I will admit that way back when (maybe 8 yrs ago) I actually did this in a piece of frequently executed code that's been stable for a looong time. I have no idea why I might have written it that way. Brain fart I suppose. I only noticed my mistake a couple months ago during a trip into the containing function for some other stuff. Man, was I embarrassed... Skip From fredrik at pythonware.com Wed Dec 6 14:20:55 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 06 Dec 2006 20:20:55 +0100 Subject: Getting started with the Python source In-Reply-To: <1165431727.248930.248430@80g2000cwy.googlegroups.com> References: <1165428508.314773.181130@l12g2000cwl.googlegroups.com> <1165431419.747335.227940@80g2000cwy.googlegroups.com> <1165431727.248930.248430@80g2000cwy.googlegroups.com> Message-ID: renguy wrote: > Thank you for your response. I guess I was looking for a more specific > answer. I have the source and I have been looking around at the various > code. I think my question is, what is the name of the toplevel source > code file of C code for the Python interpreter, and what is the name of > the toplevel source code file for IDLE? Does that make sense? to learn more about the Python interpreter, see: http://effbot.org/pyfaq/where-do-i-start-if-i-want-to-learn-about-the-cpython-implementation From CRhode at LacusVeris.com Sat Dec 2 09:01:08 2006 From: CRhode at LacusVeris.com (Chuck Rhode) Date: Sat, 2 Dec 2006 08:01:08 -0600 Subject: PythonTidy In-Reply-To: References: <20061130024509.GA8961@loki> <20061201025240.GE799@loki> Message-ID: <20061202140108.GB1427@loki> Thomas Heller wrote this on Fri, Dec 01, 2006 at 10:12:38PM +0100. My reply is below. > Here is part of a diff before and after running PythonTidy on it: > > > - def comptr_setitem(self, index, value): > - # We override the __setitem__ method of the > - # POINTER(POINTER(interface)) type, so that the COM > - # reference count is managed correctly. > + def comptr_setitem(self, index, value): # We override the __setitem__ method of the > + # POINTER(POINTER(interface)) type, so that the COM > + # reference count is managed correctly. > > Can this be customized? I am able to rationalize why this happens, but you are correct: This behavior is not appropriate. I am testing several changes, one of which should prevent it in all cases, obviating the need for a custom switch. -- .. Chuck Rhode, Sheboygan, WI, USA .. 1979 Honda Goldwing GL1000 (Geraldine) .. Weather: http://LacusVeris.com/WX .. 10? ? Wind S 5 mph From fredrik at pythonware.com Tue Dec 19 03:55:53 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 09:55:53 +0100 Subject: trouble getting google through urllib In-Reply-To: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> Message-ID: Dr. Locke Z2A wrote: >

Forbidden

> Your client does not have permission to get URL > /translate_t?text='%20como%20estas'&hl=en&langpair=es%7Cen&tbb=1 > from this server. > Does anyone know how I would get the bot to have permission to get the > url? http://www.google.com/terms_of_service.html "You may not send automated queries of any sort to Google's system without express permission in advance from Google." official API:s are available here: http://code.google.com/ From atkinw at rpi.edu Tue Dec 12 23:54:24 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Tue, 12 Dec 2006 23:54:24 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> Message-ID: greg writes: >> A compiler shifts a lot of decisions that an >> interpreter would have to make at runtime to compile-time. There is >> no reason a dynamic language can't enjoy this efficiency. > > I'm not saying that it's impossible to compile > Python, only that's there's a lot more to it than > just macro expansion. The OP was saying something > like "If you added macros, you might get a compiler > for free", which is clearly far from true. Yeah, my mistake - I simply glided right past the "just by macro expansion." Oops. :) >> Despite its dynamism, Lisp is quite compilable. > > Please correct me if I'm wrong, but as I understand, > getting efficient code out of a Lisp compiler requires > putting type declarations into the source. > > If you put the same declarations into a piece of > Python code, then of course it would be fairly > straightforward to compile it efficiently. But it > wouldn't really be dynamic Python any more. Type declarations can squeeze out extra efficiency, but vanilla Lisp without type declarations will still beat Python, both because the language is designed to compile well and because compilers for Lisp are generally very mature. So it is not the case that type declarations are the only thing that make Lisp efficient. From jmalone at optio.com Fri Dec 22 18:41:14 2006 From: jmalone at optio.com (jmalone at optio.com) Date: 22 Dec 2006 15:41:14 -0800 Subject: Using Tools/freeze.py on AIX -- having problems Message-ID: <1166830874.761560.88550@73g2000cwn.googlegroups.com> I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous versions of Freeze used a pretty simple-minded algorithm to find the modules that your program uses, essentially searching for lines starting with the word "import". It was pretty easy to trick it into making mistakes, either missing valid import statements, or mistaking string literals (e.g. doc strings) for import statements. This has been remedied: Freeze now uses the regular Python parser to parse the program (and all its modules) and scans the generated byte code for IMPORT instructions. It may still be confused -- it will not know about calls to the __import__ built-in function, or about import statements constructed on the fly and executed using the 'exec' statement, and it will consider import statements even when they are unreachable (e.g. "if 0: import foobar"). This new version of Freeze also knows about Python's new package import mechanism, and uses exactly the same rules to find imported modules and packages. One exception: if you write 'from package import *', Python will look into the __all__ variable of the package to determine which modules are to be imported, while Freeze will do a directory listing. One tricky issue: Freeze assumes that the Python interpreter and environment you're using to run Freeze is the same one that would be used to run your program, which should also be the same whose sources and installed files you will learn about in the next section. In particular, your PYTHONPATH setting should be the same as for running your program locally. (Tip: if the program doesn't run when you type "python hello.py" there's little chance of getting the frozen version to run.) I have installed Python-2.4.4 on AIX using the procedure: (logged in as root) ./configure --disable-ipv6 --disable-shared make make test make install The compiler being used during this process is: VisualAge C++ Professional / C for AIX Compiler, Version 6. Python seems to install correctly for the most part ("make test" gives a few messages about things that are not quite right (3 failed tests (test_mmap, test_pty, & test_resource) and 2 unexpectedly skipped (test_curses & test_largefile)), but nothing major (all the normal stuff, including test_socket and test_sys, passed)). Also, the unfrozen version of the script seems to run properly on the Python interpreter after installation. After this paragraph follows the output from the freeze. The biggest problem is the part at the bottom "Warning: unknown modules remain:". Neither of the suggestions in the README file in the Tools/freeze directory about this warning message have proven helpful. Name File ---- ---- m BaseHTTPServer /usr/local/lib/python2.4/BaseHTTPServer.py m FixTk /usr/local/lib/python2.4/lib-tk/FixTk.py m SocketServer /usr/local/lib/python2.4/SocketServer.py m StringIO /usr/local/lib/python2.4/StringIO.py m Tkconstants /usr/local/lib/python2.4/lib-tk/Tkconstants.py m Tkinter /usr/local/lib/python2.4/lib-tk/Tkinter.py m UserDict /usr/local/lib/python2.4/UserDict.py m __builtin__ m __main__ xfer.py m _codecs m _locale /usr/local/lib/python2.4/lib-dynload/_locale.so m _random /usr/local/lib/python2.4/lib-dynload/_random.so m _socket /usr/local/lib/python2.4/lib-dynload/_socket.so m _sre m _threading_local /usr/local/lib/python2.4/_threading_local.py m array /usr/local/lib/python2.4/lib-dynload/array.so m atexit /usr/local/lib/python2.4/atexit.py m base64 /usr/local/lib/python2.4/base64.py m binascii /usr/local/lib/python2.4/lib-dynload/binascii.so m cStringIO /usr/local/lib/python2.4/lib-dynload/cStringIO.so m codecs /usr/local/lib/python2.4/codecs.py m collections /usr/local/lib/python2.4/lib-dynload/collections.so m copy /usr/local/lib/python2.4/copy.py m copy_reg /usr/local/lib/python2.4/copy_reg.py m dis /usr/local/lib/python2.4/dis.py P distutils /usr/local/lib/python2.4/distutils/__init__.py m distutils.dep_util /usr/local/lib/python2.4/distutils/dep_util.py m distutils.errors /usr/local/lib/python2.4/distutils/errors.py m distutils.log /usr/local/lib/python2.4/distutils/log.py m distutils.spawn /usr/local/lib/python2.4/distutils/spawn.py m distutils.sysconfig /usr/local/lib/python2.4/distutils/sysconfig.py m distutils.text_file /usr/local/lib/python2.4/distutils/text_file.py m distutils.util /usr/local/lib/python2.4/distutils/util.py m dummy_thread /usr/local/lib/python2.4/dummy_thread.py P email /usr/local/lib/python2.4/email/__init__.py m email.Charset /usr/local/lib/python2.4/email/Charset.py m email.Encoders /usr/local/lib/python2.4/email/Encoders.py m email.Errors /usr/local/lib/python2.4/email/Errors.py m email.FeedParser /usr/local/lib/python2.4/email/FeedParser.py m email.Generator /usr/local/lib/python2.4/email/Generator.py m email.Header /usr/local/lib/python2.4/email/Header.py m email.Iterators /usr/local/lib/python2.4/email/Iterators.py m email.Message /usr/local/lib/python2.4/email/Message.py m email.Parser /usr/local/lib/python2.4/email/Parser.py m email.Utils /usr/local/lib/python2.4/email/Utils.py m email._parseaddr /usr/local/lib/python2.4/email/_parseaddr.py m email.base64MIME /usr/local/lib/python2.4/email/base64MIME.py m email.quopriMIME /usr/local/lib/python2.4/email/quopriMIME.py P encodings /usr/local/lib/python2.4/encodings/__init__.py m encodings.aliases /usr/local/lib/python2.4/encodings/aliases.py m errno m exceptions m fcntl /usr/local/lib/python2.4/lib-dynload/fcntl.so m fnmatch /usr/local/lib/python2.4/fnmatch.py m formatter /usr/local/lib/python2.4/formatter.py m ftplib /usr/local/lib/python2.4/ftplib.py m getopt /usr/local/lib/python2.4/getopt.py m getpass /usr/local/lib/python2.4/getpass.py m glob /usr/local/lib/python2.4/glob.py m gopherlib /usr/local/lib/python2.4/gopherlib.py m htmlentitydefs /usr/local/lib/python2.4/htmlentitydefs.py m htmllib /usr/local/lib/python2.4/htmllib.py m httplib /usr/local/lib/python2.4/httplib.py m imp m inspect /usr/local/lib/python2.4/inspect.py m itertools /usr/local/lib/python2.4/lib-dynload/itertools.so m linecache /usr/local/lib/python2.4/linecache.py m locale /usr/local/lib/python2.4/locale.py m macpath /usr/local/lib/python2.4/macpath.py m macurl2path /usr/local/lib/python2.4/macurl2path.py m markupbase /usr/local/lib/python2.4/markupbase.py m marshal m math /usr/local/lib/python2.4/lib-dynload/math.so m mimetools /usr/local/lib/python2.4/mimetools.py m mimetypes /usr/local/lib/python2.4/mimetypes.py m ntpath /usr/local/lib/python2.4/ntpath.py m nturl2path /usr/local/lib/python2.4/nturl2path.py m opcode /usr/local/lib/python2.4/opcode.py m os /usr/local/lib/python2.4/os.py m os2emxpath /usr/local/lib/python2.4/os2emxpath.py m popen2 /usr/local/lib/python2.4/popen2.py m posix m posixpath /usr/local/lib/python2.4/posixpath.py m pwd m py_compile /usr/local/lib/python2.4/py_compile.py m pydoc /usr/local/lib/python2.4/pydoc.py m quopri /usr/local/lib/python2.4/quopri.py m random /usr/local/lib/python2.4/random.py m re /usr/local/lib/python2.4/re.py m repr /usr/local/lib/python2.4/repr.py m rfc822 /usr/local/lib/python2.4/rfc822.py m select /usr/local/lib/python2.4/lib-dynload/select.so m sgmllib /usr/local/lib/python2.4/sgmllib.py m site /usr/local/lib/python2.4/site.py m socket /usr/local/lib/python2.4/socket.py m sre /usr/local/lib/python2.4/sre.py m sre_compile /usr/local/lib/python2.4/sre_compile.py m sre_constants /usr/local/lib/python2.4/sre_constants.py m sre_parse /usr/local/lib/python2.4/sre_parse.py m stat /usr/local/lib/python2.4/stat.py m string /usr/local/lib/python2.4/string.py m strop /usr/local/lib/python2.4/lib-dynload/strop.so m struct /usr/local/lib/python2.4/lib-dynload/struct.so m sys m tempfile /usr/local/lib/python2.4/tempfile.py m termios /usr/local/lib/python2.4/lib-dynload/termios.so m thread m threading /usr/local/lib/python2.4/threading.py m time /usr/local/lib/python2.4/lib-dynload/time.so m token /usr/local/lib/python2.4/token.py m tokenize /usr/local/lib/python2.4/tokenize.py m traceback /usr/local/lib/python2.4/traceback.py m tty /usr/local/lib/python2.4/tty.py m types /usr/local/lib/python2.4/types.py m urllib /usr/local/lib/python2.4/urllib.py m urlparse /usr/local/lib/python2.4/urlparse.py m uu /usr/local/lib/python2.4/uu.py m warnings /usr/local/lib/python2.4/warnings.py m webbrowser /usr/local/lib/python2.4/webbrowser.py Missing modules: ? Carbon.File imported from macpath ? Carbon.Folder imported from tempfile ? Carbon.Folders imported from tempfile ? EasyDialogs imported from getpass ? MacOS imported from Tkinter, distutils.sysconfig, py_compile ? SOCKS imported from ftplib ? _emx_link imported from os ? _ssl imported from socket ? _tkinter imported from FixTk, Tkinter ? _winreg imported from urllib ? ce imported from os ? ic imported from pydoc, urllib, webbrowser ? mac imported from os ? msvcrt imported from getpass ? nt imported from ntpath, os ? org.python.core imported from copy ? os.path imported from os ? os2 imported from os ? riscos imported from os ? riscosenviron imported from os ? riscospath imported from os ? rourl2path imported from urllib ? sitecustomize imported from site freezing BaseHTTPServer ... freezing FixTk ... freezing SocketServer ... freezing StringIO ... freezing Tkconstants ... freezing Tkinter ... freezing UserDict ... freezing __main__ ... freezing _threading_local ... freezing atexit ... freezing base64 ... freezing codecs ... freezing copy ... freezing copy_reg ... freezing dis ... freezing distutils ... freezing distutils.dep_util ... freezing distutils.errors ... freezing distutils.log ... freezing distutils.spawn ... freezing distutils.sysconfig ... freezing distutils.text_file ... freezing distutils.util ... freezing dummy_thread ... freezing email ... freezing email.Charset ... freezing email.Encoders ... freezing email.Errors ... freezing email.FeedParser ... freezing email.Generator ... freezing email.Header ... freezing email.Iterators ... freezing email.Message ... freezing email.Parser ... freezing email.Utils ... freezing email._parseaddr ... freezing email.base64MIME ... freezing email.quopriMIME ... freezing encodings ... freezing encodings.aliases ... freezing fnmatch ... freezing formatter ... freezing ftplib ... freezing getopt ... freezing getpass ... freezing glob ... freezing gopherlib ... freezing htmlentitydefs ... freezing htmllib ... freezing httplib ... freezing inspect ... freezing linecache ... freezing locale ... freezing macpath ... freezing macurl2path ... freezing markupbase ... freezing mimetools ... freezing mimetypes ... freezing ntpath ... freezing nturl2path ... freezing opcode ... freezing os ... freezing os2emxpath ... freezing popen2 ... freezing posixpath ... freezing py_compile ... freezing pydoc ... freezing quopri ... freezing random ... freezing re ... freezing repr ... freezing rfc822 ... freezing sgmllib ... freezing site ... freezing socket ... freezing sre ... freezing sre_compile ... freezing sre_constants ... freezing sre_parse ... freezing stat ... freezing string ... freezing tempfile ... freezing threading ... freezing token ... freezing tokenize ... freezing traceback ... freezing tty ... freezing types ... freezing urllib ... freezing urlparse ... freezing uu ... freezing warnings ... freezing webbrowser ... generating table of frozen modules Warning: unknown modules remain: _locale _random _socket array binascii cStringIO collections fcntl itertools math select strop struct termios time Now run "make" in xfer to build the target: xfer After running make, here is the result of trying to execute the frozen script: # ./xfer Traceback (most recent call last): File "xfer.py", line 2, in ? File "/usr/local/lib/python2.4/socket.py", line 45, in ? import _socket ImportError: No module named _socket # Any insight you can provide in regards to this problem would be greatly appreciated ! Thanks !!! Sincerely, John Malone Optio Software, Inc. From geskerrett at hotmail.com Mon Dec 4 12:10:38 2006 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 4 Dec 2006 09:10:38 -0800 Subject: Ensure a variable is divisible by 4 Message-ID: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> I am sure this is a basic math issue, but is there a better way to ensure an int variable is divisible by 4 than by doing the following; x = 111 x = (x /4) * 4 Just seems a bit clunky to me. From http Fri Dec 15 10:30:18 2006 From: http (Paul Rubin) Date: 15 Dec 2006 07:30:18 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> Message-ID: <7xslfhtbw5.fsf@ruckus.brouhaha.com> Wade Humeniuk writes: > > "nif" is even cleaner in Haskell, if I have this right: > > nif x p z n | (x < 0) = n > > | (x == 0) = z > > | (x > 0) = p > > All Haskell evaluation is automatically lazy, so no lambdas > > etc. needed. > > You can use that style in CL. > > (defun nif (x p z n) > (or (when (< x 0) n) > (when (= x 0) z) > (when (> x 0) p))) Yeah but you can't apply it the same way. [nif x p z n | x <- [0,2.5,-8]] evaluates exactly one of p, z, or n, for each of the args in that list. Side effects don't work the same way either, you have to use special declarations around code with side effects. I'm not yet conversant enough with Haskell to know how to do it for this example though. From bearophileHUGS at lycos.com Wed Dec 20 07:16:56 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 20 Dec 2006 04:16:56 -0800 Subject: array, a better shell In-Reply-To: References: <1166615065.807704.12480@48g2000cwx.googlegroups.com> Message-ID: <1166617016.225133.142840@48g2000cwx.googlegroups.com> Steven D'Aprano: > No you're not. You're describing a quite complicated shell. You're > describing a hypothetical shell with features other actual shells don't > have, so therefore it can't possibly be as simple as possible. You are right, it's not really simple, but: - It has just the basic functionality that I think is important. Many more features can be added, I too can list some of them, but I don't think they are much important. - It's very simple from the user point of view, because its usage requires no new commands to remember :-) (beside shift-enter or something similar to run a block). Thank you for listening, bye, bearophile From google at mrabarnett.plus.com Thu Dec 7 18:31:24 2006 From: google at mrabarnett.plus.com (MRAB) Date: 7 Dec 2006 15:31:24 -0800 Subject: Windows: get owner and group of a file In-Reply-To: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> References: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> Message-ID: <1165534284.917494.309030@j72g2000cwa.googlegroups.com> kai rosenthal wrote: > Hello, > > with ls -l on windows I get > -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile > > How can I get on windows with a standard python 2.2 (without windows > extensions) the information "500" and "everyone" (owner and group)? > Also I cannot use popen('ls -l'). > > With > import stat > stat_info = os.lstat(myfile) > owner = "%-8s" % stat_info.st_uid > group = "%-8s" % stat_info.st_gid > I get 0 for owner and group. > > Thanks for your hints, Kai > If you can't use os.popen('ls -l'), can you instead use os.system('ls -l >C:\\Temp\\result.txt') and then parse result.txt? From Roberto.Bonvallet at cern.ch Wed Dec 13 08:58:42 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Wed, 13 Dec 2006 13:58:42 +0000 (UTC) Subject: Iterating over several lists at once References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> Message-ID: Gal Diskin wrote: > Hi, > I am writing a code that needs to iterate over 3 lists at the same > time, i.e something like this: > > for x1 in l1: > for x2 in l2: > for x3 in l3: > print "do something with", x1, x2, x3 What's wrong with this? [...] > I'd be very happy to receive ideas about how to do this in one loop and > with minimal initialization (if at all required). def cartesian_product(l1, l2, l3): for i in l1: for j in l2: for k in l3: yield (i, j, k) for (i, j, k) in cartesian_product(l1, l2, l3): print "do something with", i, j, k -- Roberto Bonvallet From thenightblogger at gmail.com Sat Dec 16 15:47:54 2006 From: thenightblogger at gmail.com (The Night Blogger) Date: Sat, 16 Dec 2006 21:47:54 +0100 Subject: Is there a way to push data into Ical from Python ? Message-ID: <4584591b$0$29324$426a74cc@news.free.fr> Is there a way to pull & push data into (Apple Mac OS X Calendar) Ical from Python ? From fredrik at pythonware.com Fri Dec 22 11:04:04 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 22 Dec 2006 17:04:04 +0100 Subject: Generating all permutations from a regexp In-Reply-To: <740c3aec0612220630l39be117fu7977a7a2fb6e9998@mail.gmail.com> References: <740c3aec0612220630l39be117fu7977a7a2fb6e9998@mail.gmail.com> Message-ID: BJ?rn Lindqvist wrote: > With regexps you can search for strings matching it. For example, > given the regexp: "foobar\d\d\d". "foobar123" would match. I want to > do the reverse, from a regexp generate all strings that could match > it. > > The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000", > "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999". > > Is this possible to do? Obviously, for some regexps the set of matches > is unbounded (a list of everything that matches "*" would be very > unpractical), but how would you do it for simple regexps like the one > above? here's a start: http://mail.python.org/pipermail/python-list/2001-August/102739.html (the above generates *some* strings, not all, but the approach it uses can be generalized). From http Wed Dec 13 03:06:48 2006 From: http (Paul Rubin) Date: 13 Dec 2006 00:06:48 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165773218.686683.46640@16g2000cwy.googlegroups.com> <1165985280.821123.318210@f1g2000cwa.googlegroups.com> Message-ID: <7xirggte1z.fsf@ruckus.brouhaha.com> "JShrager at gmail.com" writes: > Let us note that it's not FSF that gives this stuff away for free -- or > if it is them proximally, it is not them ultimately -- ultimately it's > the engineers who did all that work that gave it away for free. When I worked there, they paid me ;-) From paul at boddie.org.uk Wed Dec 20 06:38:00 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 20 Dec 2006 03:38:00 -0800 Subject: automatically grading small programming assignments References: <4581896B.2020504@bryant.edu> Message-ID: <1166614680.226924.228710@a3g2000cwd.googlegroups.com> Jeff Rush wrote: > > For another solution, I wonder whether you could make use of the new Abstract > Syntax Tree (AST) in Python 2.5, where you convert the source of an attempt > into an abstract data structure, anonymize the method/variable/class names and > compare the tree against a correct solution. It would let you quickly handle > those students who solved it in a conformist way, and then you'd need to > manually review the rest for creatively solving it another way. ;-) You could attempt that kind of solution using previous versions of Python (and the compiler module), but as soon as you want to compare two different ASTs - and I think that unless there's only one obvious solution, they won't be identical - then you need to descend into a world of program transformations that Python doesn't encourage. It's probably no coincidence that the functional programming people were probably the only people trying this kind of automatic grading back when I was a student. Paul From martin at v.loewis.de Sun Dec 17 04:18:24 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 17 Dec 2006 10:18:24 +0100 Subject: Smarter way to do this? Unicode + stdin, stdout In-Reply-To: <1166331229.618202.16890@n67g2000cwd.googlegroups.com> References: <1166331229.618202.16890@n67g2000cwd.googlegroups.com> Message-ID: <45850b60$0$6312$9b622d9e@news.freenet.de> BenjaMinster schrieb: > I want to read and write unicode on stdin and stdout. I can't seem to > find any way to force sys.stdin.encoding and sys.stdout.encoding to be > utf-8, so I've got the following workaround: What operating system are you using? Why do you want to do this? Python attempts to determine the encoding of your terminal (if sys.stdout is a terminal), and set sys.stdout.encoding accordingly. Regards, Martin From atkinw at rpi.edu Wed Dec 13 00:02:00 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Wed, 13 Dec 2006 00:02:00 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Pascal Costanza writes: >> May you have tried the wrong Lisp dialects so far: >> >> (loop for i from 2 to 10 by 2 >> do (print i)) > > The loop language is so complicated and confusing that I never > bothered trying to learn it. I always used simpler primitives to > write loops and it was always enough. I think you're missing out. If you don't find LOOP appealing, look for the ITERATE package. ITERATE is a more Lispy, more extensible replacement for LOOP. >> This is Common Lisp. (Many Lisp and Scheme tutorials teach you that >> you should implement this using recursion, but you really don't have >> to. ;) > > You can't really use that much recursion in Lisp because of the lack > of guaranteed TCO. I think that makes it reasonable to say that > Scheme is a functional language but Lisp is not. ("Functional" = it's > reasonable to code in a style where the only way to connect variables > to values is lambda binding (maybe through syntax sugar), so all loops > are implemented with recursion). You should be pragmatic about this - I have never used a CL implementation that didn't do TCO optimization (indeed, are there any?). Although the standard doesn't require it, I treat it as a de facto requirement and don't worry too much about it. From gagsl-py at yahoo.com.ar Tue Dec 26 15:39:31 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Tue, 26 Dec 2006 17:39:31 -0300 Subject: some OT: how to solve this kind of problem in our program? In-Reply-To: <45906bab$0$27094$4c368faf@roadrunner.com> References: <458e4426$0$5286$4c368faf@roadrunner.com> <1166958490.785728.52430@h40g2000cwb.googlegroups.com> <1166974469.681026.101070@42g2000cwt.googlegroups.com> <45906bab$0$27094$4c368faf@roadrunner.com> Message-ID: <7.0.1.0.0.20061226164403.03e6e568@yahoo.com.ar> At Monday 25/12/2006 21:24, Paul McGuire wrote: >For example, for all the complexity in writing Sudoku solvers, there are >fewer than 3.3 million possible permutations of 9 rows of the digits 1-9, >and far fewer permutations that match the additional column and box >constraints. Why not just compute the set of valid solutions, and compare >an input mask with these? Are you sure? There are 9!=362880 rows of digits 1-9; taking 9 of these at random gives about 10**50 possibilities. Of course just a few match the additional constraints. Maybe you can trivially reduce them (just looking for no dupes on the first column) but anyway its a laaaaarge number... (Or I'm wrong computing the possibilities...) -- 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 From pavlovevidence at gmail.com Sun Dec 10 10:54:29 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 10 Dec 2006 07:54:29 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165169117.866499.181520@73g2000cwn.googlegroups.com> <45732974$0$8758$ed2619ec@ptn-nntp-reader02.plus.net> <1165183970.832303.323350@73g2000cwn.googlegroups.com> <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> <1165252920.329341.284910@j44g2000cwa.googlegroups.com> <1165255758.967262.226400@73g2000cwn.googlegroups.com> <1165267711.364076.292000@79g2000cws.googlegroups.com> <457be14b$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165766069.028619.284860@80g2000cwy.googlegroups.com> Jon Harrop wrote: > Carl Banks wrote: > > I doubt it would work too well. > > What about translating the current Python interpreter into a language with a > GC, like MLton-compiled SML? That would probably make it much faster, more > reliable and easier to develop. I doubt it would work too well. MLton-compiled SML's semantics differ from Python's in subtle ways, and covering the edge cases usually means you have to do all the stuff you thought you would avoid by using another dynamically-typed language. Translating MTton-compiled SML integers to Python ints would work probably 99 percent of the time, but in the end you'd essentially have to reimplement the Python int type. If you're going to go through all that work, you might as well translate it to C or directly to machine code. Carl Banks From emin.shopper at gmail.com Fri Dec 15 13:39:35 2006 From: emin.shopper at gmail.com (emin.shopper at gmail.com) Date: 15 Dec 2006 10:39:35 -0800 Subject: I'm looking for a pythonic red-black tree... In-Reply-To: References: Message-ID: <1166207975.203440.200510@n67g2000cwd.googlegroups.com> You could try and wrap the C/C++ code at http://web.mit.edu/~emin/www/source_code/index.html and make a python extension... On Dec 14, 8:20 pm, "Just Another Victim of the Ambient Morality" wrote: > I need a red-black tree in Python and I was wondering if there was one > built in or if there's a good implementation out there. Something that, > lets face it, does whatever the C++ std::map<> allows you to do... > Thank you... From int2k at gmx.net Sun Dec 10 01:10:05 2006 From: int2k at gmx.net (Wolfram Fenske) Date: 9 Dec 2006 22:10:05 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> Message-ID: <1165731005.529088.227360@j44g2000cwa.googlegroups.com> Steven D'Aprano schreibt: > On Sat, 09 Dec 2006 14:00:10 +0000, Timofei Shatrov wrote: > >> On Sat, 09 Dec 2006 20:36:02 +1100, Steven D'Aprano >> tried to confuse everyone with this >> message: >> >>>On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote: >>> >>>> if Common Lisp didn't have CLOS, its object system, I could write my own >>>> as a library and it would be just as powerful and just as easy to use as >>>> the system Common Lisp already provides. Stuff like this is impossible >>>> in other languages. >>> >>>Dude. Turing Complete. Don't you Lisp developers know anything about >>>computer science? >> >> Here, you've basically shot yourself in the ass. Appealing to >> Turing completeness when talking about programming language >> features is about the dumbest thing you can make. In Turing sense, >> a program is simply a function that takes an argument and returns a >> value. It doesn't say anything about how this function was >> implemented. It could be Turing machine, lambda calculus, Markov >> chains or whatever else. All these methods produce the same set of >> programs, but that doesn't mean you could implement lambda in >> Turing machine for example. [...] > If you're talking about practicality, then of course you're correct, > not all languages are equally expressive. Some languages are not > expressive enough. I agree. > Some languages are too expressive. I disagree. "Too expressive"--what a thing to say. [...] > Look, all snarkiness aside, it just isn't true that "stuff like this > is impossible in other languages". If Wolfram Fenske had said "stuff > like this isn't easy in many other languages" he would have been > right. I said that it's impossible to write you own object system in other languages *and* have it behave like it was part of the language. OK, you could always write your own pre-processor, i. e., your own Foo+Objects to Foo compiler. But that's almost like saying it's impossible. Now, object systems aside, how about that one: One of the new features of Python 2.5 is a syntax for --8<---------------cut here---------------start------------->8--- if condition: x = true_value else: x = false_value --8<---------------cut here---------------end--------------->8--- which becomes --8<---------------cut here---------------start------------->8--- x = true_value if condition else false_value --8<---------------cut here---------------end--------------->8--- (see [1]). IMO that's a nice addition because this pattern is something that has bothered me for some time. Here's another one, the "with" statement [2]: --8<---------------cut here---------------start------------->8--- Some standard Python objects now support the context management protocol and can be used with the 'with' statement. File objects are one example: with open('/etc/passwd', 'r') as f: for line in f: print line ... more processing code ... After this statement has executed, the file object in f will have been automatically closed, even if the 'for' loop raised an exception part-way through the block. --8<---------------cut here---------------end--------------->8--- My point is that in Python--and AFAIK any other language except maybe OCaml and maybe maybe Haskell--, you have to wait for these changes until the language designers decide to make the for you. And if they don't, you're out of luck. In Lisp, you can just add this yourself. > And if he had said "and stuff like this carries risks as well as > benefits" he would have come across as less of a language fanatic. Sure, you can shoot yourself in the foot with macros. But you can do that in any language of any degree of expressiveness [3]. Come to think of it, the whole reason why we use high level languages is because of their expressiveness: We get stuff done faster and introduce less errors. So "the more expressive, the better," right? But according to you, there's a point when a language gets "too expressive". I don't see why. > One of the risks with Python is the ease with which you can modify the > built-ins. An expression like list(2, 3, 4) doesn't necessarily create a > list from 2, 3, and 4, because the built-in list could be redefined. > (In practice, that's not often a real problem, because experienced > Python developers simply learn not to needlessly or confusingly shadow > built-ins. It's not the best system, but it works well enough in > practice.) So you do trust your developers not to do anything stupid. > But at least the basic syntax and keywords of the language are known > to be constant. With Lisp macros, even that isn't guaranteed. Let me summarize: you're allowed to redefine every built-in function you want but introducing new syntax is simply too much. See, this is the kind of thinking I don't understand. I say macros are good because a), b), and c) and you answer macros are bad because, uhm, well, it would be pure anarchy. > Now, if Lispers would say "Oh yes, macros give you great power, and > with great power comes great responsibility. Be careful." then, no > doubt, we'd take you guys more seriously. Sure, it's a powerful tool but it's not *that* hard to use. Maybe you're afraid of it because that it's something that's unique to Lisp? But IMO the reason for that is not that they're too powerful. IMO it has mostly to do with the fact that other languages' syntaxes make it too difficult to implement Lisp-style macros. > But we don't hear that -- we hear Lispers going on and on about how > great it is that they can easily redefine every corner of the > language. Do you blame people for *believing them* and imagining > that reading Lisp code is like following some ghostly > will-o-the-wisp across a swamp, where nothing is what it seems and > the landscape is forever shifting? Come on! You're telling me people don't learn Lisp because they are afraid of it? Python allows you to redefine built-in functions, as you said, Ruby allows you to attach new methods to live objects, but Lisp is simply going too far? > Now, if you want to tell me that, despite all the talk, Lisp coders > don't actually create new syntax or mini-languages all that often, > that they just use macros as functions, then the question becomes: > why do you need macros then if you are just using them as functions? > Why not use functions? Easy because macros are not functions. Functions allow you abstract functionality, macros allow you abstract syntax. Look at the examples above. How would you implement conditional expressions as a function? Answer: You can't, it's syntax. Footnotes: [1] [2] [3] And here's the proof :-) -- Wolfram Fenske A: Yes. >Q: Are you sure? >>A: Because it reverses the logical flow of conversation. >>>Q: Why is top posting frowned upon? From martin at v.loewis.de Sat Dec 30 09:43:06 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 30 Dec 2006 15:43:06 +0100 Subject: per interpreter storage for C extensions In-Reply-To: <45965FE4.5080807@jessikat.plus.net> References: <4595b573$0$25466$9b622d9e@news.freenet.de> <45965FE4.5080807@jessikat.plus.net> Message-ID: <45967afb$0$25064$9b622d9e@news.freenet.de> Robin Becker schrieb: > What is worrying is that in the extension init we're creating an > exception and version string etc and holding a pointer to them in C; is > it safe to use the same exception in different interpeters? It is safe as long as the base exception classes are also shared across interpreters, otherwise, the hierarchical exception matching will break. The builtin exceptions are all "global" (i.e. shared across interpreters) (I believe). In any case, it looks like that the "multiple interpreters" feature of Python is just broken. Regards, Martin From robert.kern at gmail.com Sun Dec 3 21:39:09 2006 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 03 Dec 2006 20:39:09 -0600 Subject: Why not just show the out-of-range index? In-Reply-To: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165195429.928771.148400@j44g2000cwa.googlegroups.com> Message-ID: Russ wrote: >> Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. > > Now, that would be rather silly. I would have to familiarize myself > with the code for the Python interpreter, then send a patch to the > maintainers (and hope they notice it in their inboxes), while the > maintainers themselves could probably "fix" the problem in two minutes > flat. No thanks! And I believe that answers your original question. PS: begging for a fix on comp.lang.python is even less likely to get the developer's attention than posting a patch. They listen to patch submissions much more than comp.lang.python. At the very least, you should submit a bug report even if you don't want to take the opportunity to learn how to fix it yourself. -- 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 From udodenko at users.sourceforge.net Fri Dec 8 09:43:23 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Fri, 8 Dec 2006 16:43:23 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> Message-ID: <45797a0c$0$49204$14726298@news.sunsite.dk> (message (Hello 'Richard) (you :wrote :on '(Fri, 8 Dec 2006 14:08:09 -0000)) ( ??>> seems to show that Python is a cut down (no macros) version of Lisp ??>> with a worse performance. RB> Performance claims are always controversial. So, Python is much slower RB> doing array multiplication, when you hand roll it, instead of using the RB> standard numerical packages available. heh, do you have "standard numeric packages" for everything? maybe then we'll make standard programs for everything -- that will obsolete "slow" "custom scripts" and we'll just use shell to select what program we want to run? certainly, it's possible to write code in C and use FFI to access it, but it's not suitable for rapid prototyping/fast development, when requirements may change, or you're just experimenting with different methods. it's interesting than as of bare "interpreter overhead", python is aprox order of magnitude (10 times) slower than lisp interpreters. it's also interesting, that python, perl, php and ruby show very similar peformance, while lisp and scheme implementations show large improvements -- it makes me think that there's something "pathalogically scripting" in their specifications (maybe some obligatory use of strings for method dispatch?). note that i've mentioned "lisp interpreters" above. as for lisp _compilers_, they run lots faster than lisp interpreters. please check http://shootout.alioth.debian.org/ to compare Python to Lisp SBCL. lisp is faster more then 10 times in many benchmarks, and even more than 100 times faster in two benchmarks. unfortunately there's no lisp interpreters (CLISP) in the benchmark. ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From jstroud at mbi.ucla.edu Fri Dec 15 07:14:53 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 15 Dec 2006 12:14:53 GMT Subject: skip last line in loops In-Reply-To: <1166182692.041668.218730@f1g2000cwa.googlegroups.com> References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> <1166182692.041668.218730@f1g2000cwa.googlegroups.com> Message-ID: <0lwgh.31271$wP1.5113@newssvr14.news.prodigy.net> eight02645999 at yahoo.com wrote: > Fredrik Lundh wrote: >> eight02645999 at yahoo.com wrote: >> >>> how can i skip printing the last line using loops (for /while) >>> >>> eg >>> >>> for line in open("file): >>> print line. >>> >>> I want to skip printing last line of the file. >> do it lazily: >> >> last_line = None >> for line in open("file): >> if last_line: >> print last_line >> last_line = line >> >> or just gobble up the entire file, and slice off the last item: >> >> for line in list(open("file"))[:-1]: >> print line >> >> > > hi > would it be a problem with these methods if the file is like 20Gb in > size...? > See the documentation for xreadlines. James From reverseyorkage at david.com Sun Dec 17 08:32:31 2006 From: reverseyorkage at david.com (dyork) Date: Sun, 17 Dec 2006 13:32:31 GMT Subject: Roundtrip SQL data especially datetime References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com><1166258893.044093.196820@79g2000cws.googlegroups.com> Message-ID: "Carsten Haese" wrote in message news:mailman.1699.1166304628.32031.python-list at python.org... > This may come as a shock to you, but MySQL is not the only database > engine on the planet. Your recommendation may apply to MySQL, but it is > not true for all databases in general. I can name at least two examples > (Informix and Oracle) of database engines that are supported under > Python 2.5, and if I were less lazy I could probably find more. Of course, no question about it. However, the database is currently in MySQL and it's convenient to keep working with it, given the other apps and other tools I'm using. This would be the first time I've been told: don't use that database, the language doesn't like it. DY From gagsl-py at yahoo.com.ar Mon Dec 11 20:03:33 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 22:03:33 -0300 Subject: issues with making a package. where do classes link? In-Reply-To: References: Message-ID: <7.0.1.0.0.20061211214429.0363ece0@yahoo.com.ar> At Monday 11/12/2006 15:47, krishnakant Mane wrote: >I am struggling a bit in making python packages. >when I am doing a project I want to create all my python modules >inside a single package. A package is a directory with an __init__.py file in it. That's the only thing needed. >I want to know when I make a package, what are the basic things I must >generally do in the __init__.py file? Most of the time, just an empty file. Or a lot of things. If you don't have nothing special to do, just let it empty. Maybe, you have a lot of functions scattered along many modules inside your package, for your own convenience, but you prefer that users of the package refer to those functions as top-level functions (hiding the internal structure that you may consider an implementation detail). By example, your package foo (in directory foo) contains: __init__.py bar.py which contains functions bar1, bar2 fido\ fido.py which contains Fido class dido.py which contains Dido class And you want your uses to refer to class Fido as foo.Fido (instead of foo.fido.fido.Fido), same thing for Dido, and foo.bar1 (instead of foo.bar.bar1) So in __init__.py you populate the package's namespace as: from bar import bar1, bar2 from fido.fido import Fido from fido.dido import Dido >and how do I link all the modules in my project with each other? Inside the same directory, just by name: inside dido.py you could import class Fido as "from fido import Fido" If you are using Python 2.5, you can use relative imports, see http://docs.python.org/whatsnew/pep-328.html >like when I make a compilation unit in java under a package, the first >like of that file will read "package mypackage". Not needed. Python is aware of the directory containing the package, that directory becomes the package's name. >I did not find any such thing in python that can say that this xyz >file is in the abc package. Look at the location of the file. From code, look at it's __file__ attribute. >if I want to use one module into another in my same package I can't >figure how python figures it out? See above. >I want every thing in a single package. >so that's my confusion. I hope it's clearer now. Read the Python tutorial about packages, and the PEP328 above. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From skip at pobox.com Tue Dec 19 13:12:42 2006 From: skip at pobox.com (skip at pobox.com) Date: Tue, 19 Dec 2006 12:12:42 -0600 Subject: on PySol's popularity In-Reply-To: References: <857993970612190431m48de4735w24576d96ce54724b@mail.gmail.com> Message-ID: <17800.11162.232310.942679@montanaro.dyndns.org> Harry> A plug for PySol. Harry> My wife is totally non-techno. She doesn't "get" the notions of Harry> windows, or minimize/maximize, or clicking on the icon down on Harry> the toolbar. My wife appears to be only slightly less non-techno than yours. Aside from mail and web browsing, PySol is her number one application. Harry> [PySol] should be considered a cultural treasure, and if a bit of Harry> funding would help keep it rolling into the future, that might be Harry> worthwhile. Agreed, and +1 QOTW. Skip From jjl at pobox.com Mon Dec 4 07:41:59 2006 From: jjl at pobox.com (John J. Lee) Date: 04 Dec 2006 12:41:59 +0000 Subject: Printing Barcodes from webapp? References: <1165040626.505772.312350@j72g2000cwa.googlegroups.com> <1165063816.365760.264300@73g2000cwn.googlegroups.com> Message-ID: "Andy Dingley" writes: > Burhan wrote: > > > Is there an easy way to generate barcodes using Python > > Easy way for any application or language to generate barcodes is to > install a barcode font on the client machine, then just generate a > suitable text string for it. This is _very_ easy, if you can get the > font deployed. I usually find myself using Code 39 and printing them > from a HTML document. There are plenty of free code 39 fonts around and > the string mangling to get the barcode structured correctly is just a > trivial prefix / suffix. Sometimes that's really convenient. Depending on the barcode, this may not always be easy, though. Certainly there are some complications, ranging from things like relatively simple check digits, through complicated encodings (my colleague Robin tells me US postal bar codes were a particular pain), up to funny-looking 2D "bar" codes like PDF417, that have lots of complicated rules associated with them. The ReportLab open source toolkit barcode support handles this kind of thing for you -- for the barcodes it supports, anyway. John From udodenko at users.sourceforge.net Sat Dec 9 06:14:02 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sat, 9 Dec 2006 13:14:02 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> <1165593798.079105.144060@80g2000cwy.googlegroups.com> <45799841$0$49201$14726298@news.sunsite.dk> <1165609509.370461.122170@73g2000cwn.googlegroups.com> <457a7ee5$0$49195$14726298@news.sunsite.dk> <457a89f4$0$4242$4fafbaef@reader1.news.tin.it> Message-ID: <457a9a7c$0$49200$14726298@news.sunsite.dk> (message (Hello 'Andrea) (you :wrote :on '(Sat, 09 Dec 2006 11:08:34 +0100)) ( ??>> so we can see PyDict access. moreover, it's inlined, since it's very ??>> performance-critical function. ??>> but even inlined PyDict access is not fast at all. ma_lookup is a long ??>> and hairy function containing the loop. AG> I once had a crazy idea about the lookup speed problem; AG> can't the lookup result be cached in the bytecode ? actually i don't see any reason why lookup is needed at all. i think you can use approach similar to Lisp Symbols in Python, so it's implementation slow, not the language. there are some subtle differences -- for example, if you del global binding, function gets undefined, but in Lisp uninterning does not invalidate code that uses that symbols. but you can easily override this invalidating the symbol bindings. i think symbols can be implemented just as cache you suggest, but without need of timestamp, but with additional indirection. you should associate a SYMBOL with each entry in the globals dict, however those SYMBOL lifetime should be managed independently (lifetime management is one of difficulties, but i think not non-solvable). once you need to cache lookup, you cache a SYMBOL pointer. then you just get symbol's value on firther lookups. if dict gets update, it should update all symbols associated with it. if entry (or whole dict) is deleted, it should invalidate all symbols, so accessing them will produce error, but it should not delete symbols. you can resolve symbols not on first access, but during the read operation (when bytecode is produced), as it's done in Lisp. however, it's only applicable to LOAD_GLOBAL and STORE_GLOBAL, i think it won't be possible to optimize STORE_ATTR that way without changing semantics. by the way, maybe some optimizations are already implemented in Psyco? it's Python JIT with profile-guided type optimization, but i don't know how it deals with lookups.. ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From udodenko at users.sourceforge.net Sun Dec 10 18:05:39 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Mon, 11 Dec 2006 01:05:39 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> <457c42a3$0$49196$14726298@news.sunsite.dk> <7xodqbpqun.fsf@ruckus.brouhaha.com> Message-ID: <457c92c7$0$49195$14726298@news.sunsite.dk> (message (Hello 'Paul) (you :wrote :on '(10 Dec 2006 10:07:12 -0800)) ( PR> There would be terrible performance penalties dealing with the PR> environment lookup on every lexical variable reference. LOL! you're saying it in Python newsgroup! do you know that python makes a dict lookup on each access to global variable/function/builtin? and it does dict lookup for each object's method/field access. and actually we can use vectors rather than dicts for lexical environments, so it will be much faster. and if you call that "terrible penalties", how will you call python's performace? i don't know which adjective can express it then.. PR> That's the point. The compiler would treat those as references to PR> slots in the call frame, would do type inference so it could use PR> unboxed atoms where it could, etc. You'd lose all that. i think there can be some optimizations (we need lex env object only where we need a closure, i think), but right -- to have best performance, you'll need to implement it in the language level. but you can get functionality working right, and with acceptable performance. if python's performance is acceptable for you, why other interpreter's won't be? ??>> why do you think so? ??>> you know some case that does not work with call/cc? PR> I don't see how to implement coroutines with CL macros. Maybe I'm PR> missing something. read the book. i can give you a basic idea: * (macroexpand '(with-call/cc (print 1) (call/cc (lambda (k1) k1)) (print 2))) (DRIVE-CPS (PROGN (PRINT 1) (LAMBDA () (FUNCALL #'TOPLEVEL-K (FUNCALL #'(LAMBDA (K1) K1) (MAKE-CALL/CC-K (LAMBDA (#:V-1712) (DECLARE (IGNORE #:V-1712)) (LAMBDA () (FUNCALL #'TOPLEVEL-K (PROGN (PRINT 2))))))))))) you see that it makes a cut in call/cc point -- continuous blocks are not affected with the transform. ??>> and then use call/cc as i've shown in ??>> example. that's real generators. there's no need for any cond -- you ??>> can save state as current-continuation. PR> Fully general call/cc has to be able to switch from one execution PR> stack to another and back. that's from imperative point of view. but once you convert it to CPS, you just operate with closures. stack is just a lexical variables caught into closure. do you know what does CPS mean at all?? ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From spe.stani.be at gmail.com Thu Dec 14 18:22:15 2006 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 14 Dec 2006 15:22:15 -0800 Subject: SPE website down? In-Reply-To: References: Message-ID: <1166138535.919134.155790@t46g2000cwa.googlegroups.com> On 14 dec, 21:07, William Allison wrote: > Laszlo Nagy wrote: > > The home page of SPE (Stani's editor) is not available. > > >http://pythonide.stani.be/ > > > Is there a mailing list for this editor? > > Where should I ask questions about it? > > Where can I report bugs and make suggestions? > > > Thanks, > > > LaszloI seem to remember he was looking for a new webhost a couple of > weeks ago. Tryhttp://sourceforge.net/projects/spe/for now. From Ingo.Wolf at gmx.de Fri Dec 8 12:34:25 2006 From: Ingo.Wolf at gmx.de (iwl) Date: 8 Dec 2006 09:34:25 -0800 Subject: Using Py_InitModule3 -> [Linker Error] Unresolved external '_Py_InitModule4TraceRefs' Message-ID: <1165599265.119546.194850@j44g2000cwa.googlegroups.com> Hello I copied the code from the Extending Embedded Python section in the Python 2.5 but get an linker Error Unresolved external _Py_InitModule4TraceRefs. Who knows what's wrong? From pavlovevidence at gmail.com Fri Dec 29 01:01:13 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 28 Dec 2006 22:01:13 -0800 Subject: Anyone persuaded by "merits of Lisp vs Python"? In-Reply-To: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> Message-ID: <1167372073.541929.57370@48g2000cwx.googlegroups.com> Paddy3118 wrote: > This month there was/is a 1000+ long thread called: > "merits of Lisp vs Python" > In comp.lang.lisp. > > If you followed even parts of the thread, AND previously > used only one of the languages AND (and this is the > crucial bit), were persuaded to have a more positive view > of the other language; (deep breath, this is a long, as > well as grammatically incorrect sentence), THEN WHY NOT > POST ON WHAT ARGUMENTS PERSUADED YOU. > > OTHERWISE LET THIS POST WITHER AND DIE ALONE. If you were so keen on avoiding a flame war, the first thing you should have done is to not cross-post this. Carl Banks From Ingo.Wolf at gmx.de Thu Dec 7 09:36:20 2006 From: Ingo.Wolf at gmx.de (iwl) Date: 7 Dec 2006 06:36:20 -0800 Subject: funcs without () like print Message-ID: <1165502180.715192.195240@j72g2000cwa.googlegroups.com> Hello can I make funktions callable without () like print at time the interpreter seems to printout the adres when I type the function without () From fredrik at pythonware.com Wed Dec 6 06:31:25 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 6 Dec 2006 12:31:25 +0100 Subject: What are python closures realy like? References: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> Message-ID: Paul Boddie wrote: > I know that everyone will say that Python is a "multi-paradigm" > language and that one should feel free to use whatever technique seems > appropriate to solve the problem at hand, but it seems to me that > there's been an explosion in nested function usage recently, with lots > of code snippets showing them off either in the context of a debugging > exercise or as a proposed solution to a problem, and yet in many cases > their usage seems frivolous in comparison to plain old object-oriented > techniques. when doing some heavy optimization, I recently found myself writing: def foobar(arg1, arg2, arg3): def helper(arg): do something with arg1 and argument def foo(): do something with arg1 and arg3 and call helper def bar(): do something with arg1 and arg2 def zoo(): do something with arg2 and arg3 and call helper # oops; how do I return all these? class bag(object): pass bag = bag() bag.foo = foo bag.bar = bar bag.zoo = zoo return bag which, I think, deserves no further comment... From uymqlp502 at sneakemail.com Mon Dec 11 12:17:32 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 11 Dec 2006 09:17:32 -0800 Subject: Automatic debugging of copy by reference errors? References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165808664.074268.114910@l12g2000cwl.googlegroups.com> <4u4smqF1691oiU1@mid.individual.net> Message-ID: <1165857451.951347.318760@80g2000cwy.googlegroups.com> greg wrote: > You need to stop using the term "copy by reference", > because it's meaningless. Just remember that assignment I agree that "copy by reference" is a bad choice of words. I meant pass by reference and assign by reference. But the effect is to make a virtual copy, so although the phrase is perhaps misleading, it is not "meaningless." > Again, this is something you'll find easier when > you've had more experience with Python. Generally, > you only need to copy something when you want an > independent object that you can manipulate without > affecting anything else, although that probably > doesn't sound very helpful. Yes, I realize that, but deciding *when* you need a copy is the hard part. From geskerrett at hotmail.com Sun Dec 3 15:01:56 2006 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 3 Dec 2006 12:01:56 -0800 Subject: Using win32gui.SendMessage and SysListView32 control Message-ID: <1165176116.034632.58270@f1g2000cwa.googlegroups.com> Hope someone can steer me in the right direction. I am trying to use python to collect the values from a Win32 application's control. I can successfull query an retreive the values ListBox, Edit and Buttons, however, the application uses a control called a 'SysListView32' Control. MSDN says that this descends from CListView control and the msdn website reference for this control is; http://msdn2.microsoft.com/en-gb/library/ms670560.aspx (scroll to the message constants) This page seems to imply that the control can be queried with messages, however, my problem seems to be that pywin32.win32con does not define a constant for the LVM series of messages. Any other suggestions ?? I am looking for something similar to code below which does a fine job of collecting all of the text values from a "ListBox" control; count = win32gui.SendMessage(hndl,win32con.LB_GETCOUNT) vals = [] for i in range(count): strlen = win32gui.SendMessage(hndl,win32con.LB_GETTEXTLEN) text = ' '*(strlen+1) #Buffer for returned text -50 characters lentext = win32gui.SendMessage(hndl,win32con.LB_GETTEXT,i,text) txt = text[0:lentext] print "Hndl: %8s Class: %-10s TxtLen:%3s TxtVal: %s " % (hndl,clname,lentext,txt) vals.append(txt.strip()) Thanks in advance. From jonathan.beckett at gmail.com Thu Dec 28 13:35:38 2006 From: jonathan.beckett at gmail.com (jonathan.beckett) Date: 28 Dec 2006 10:35:38 -0800 Subject: Some basic newbie questions... In-Reply-To: <4594005c$1@nntp0.pdx.net> References: <1167324002.516960.319870@79g2000cws.googlegroups.com> <4594005c$1@nntp0.pdx.net> Message-ID: <1167330938.386057.96870@a3g2000cwd.googlegroups.com> > Too many misconceptions here (I changed to a more PEP-8 style naming): > > class Gun(object): > def __init__(self): > self.shells = 10 > > class Battleship(object): > def __init__(self): > self.guns = [Gun(), Gun()] > > def getShellsLeft(self): > numShells = 0 > for aGun in self.guns: > numShells += aGun.shells > return numShells > > theBizmark = Battleship() > print theBizmark.getShellsLeft() Excellent example - once upon a time I used to write very neat code indeed, but exposure to C# had pretty much knackered that (where all the framework object methods are capitalized). From casevh at comcast.net Fri Dec 29 01:03:19 2006 From: casevh at comcast.net (casevh at comcast.net) Date: 28 Dec 2006 22:03:19 -0800 Subject: A stupid question In-Reply-To: <1167365141.757827.43670@48g2000cwx.googlegroups.com> References: <1167362866.807346.73510@73g2000cwn.googlegroups.com> <1167365141.757827.43670@48g2000cwx.googlegroups.com> Message-ID: <1167372198.897979.37690@i12g2000cwa.googlegroups.com> luxnoctis at gmail.com wrote: > It says exactly: > > The specified module could not be found. > LoadLibrary(pythondll) failed > > >I bought a floor model computer, and it came with all sorts of > > >ridiculousness on it that I promptly uninstalled. However, now whenever > > >I start windows I get a message saying "LoadLibrary (pythondll > > >) failed." It also says this when I try to download into a bittorrent > > >client, and it keeps it from downloading. What does this mean, and how > > >can I make it go away? Python is a programming language used to develop (some of) the bittorrent clients. You were a little exuberant in uninstalling applications and removed the Python files that are required for the bittorrent client. You could try downloading and installing Python, but I don't know which version you'll need. You could try uninstalling the bittorrent client and reinstalling a client with all its required dependencies. HTH, casevh From robin at reportlab.com Fri Dec 15 05:14:49 2006 From: robin at reportlab.com (Robin Becker) Date: Fri, 15 Dec 2006 10:14:49 +0000 Subject: merits of Lisp vs Python In-Reply-To: <2773CAC687FD5F4689F526998C7E4E5FF1EC34@au3010avexu1.global.avaya.com> References: <2773CAC687FD5F4689F526998C7E4E5FF1EC34@au3010avexu1.global.avaya.com> Message-ID: <45827599.2070507@chamonix.reportlab.co.uk> Delaney, Timothy (Tim) wrote: > Ken Tilton wrote: > >>> But this is not a case where a function can't handle the job. >> Is, too. > > And Ken moves one step closer towards Python ... > http://www.google.com.au/search?q=monty+python+argument+sketch > > Tim Delaney is it time to mention the storm troopers and A**** H*****? This thread certainly needs shutting down :) -- Robin Becker From S.Mientki-nospam at mailbox.kun.nl Sat Dec 30 05:52:42 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Sat, 30 Dec 2006 11:52:42 +0100 Subject: Wow, Python much faster than MatLab In-Reply-To: <1167449722.106162.93380@k21g2000cwa.googlegroups.com> References: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl> <1167449722.106162.93380@k21g2000cwa.googlegroups.com> Message-ID: >> MatLab: 14 msec >> Python: 2 msec > > For times this small, I wonder if timing comparisons are valid. I do > NOT think SciPy is in general an order of magnitude faster than Matlab > for the task typically performed with Matlab. The algorithm is meant for real-time analysis, where these kind of differences counts a lot. I'm also a typical "surface programmer" (don't need/want to know what's going inside), just want to get my analysis done, and the fact that Python has much more functions available, means I've to write far less explicit or implicit for loops, and thus I expect it to "look" faster for me always. > >> After taking the first difficult steps into Python, >> all kind of small problems as you already know, >> it nows seems a piece of cake to convert from MatLab to Python. >> (the final programs of MatLab and Python can almost only be >> distinguished by the comment character ;-) >> >> Especially I like: >> - more relaxed behavior of exceeded the upper limit of a (1-dimensional) >> array > > Could you explain what this means? In general, I don't want a > programming language to be "relaxed" about exceeding array bounds. > Well, I've to admit, that wasn't a very tactic remark, "noise" is still an unwanted issue in software. But in the meanwhile I've reading further and I should replace that by some other great things: - the very efficient way, comment is turned into help information - the (at first sight) very easy, but yet quit powerfull OOPs implemetation. cheers, Stef Mientki From robin at reportlab.com Thu Dec 28 11:51:25 2006 From: robin at reportlab.com (Robin Becker) Date: Thu, 28 Dec 2006 16:51:25 +0000 Subject: per interpreter storage for C extensions In-Reply-To: <4866bea60612280832ib9700e6v3f191faa7d8ea488@mail.gmail.com> References: <4593E44C.9000502@chamonix.reportlab.co.uk> <4866bea60612280832ib9700e6v3f191faa7d8ea488@mail.gmail.com> Message-ID: <4593F60D.5090005@chamonix.reportlab.co.uk> Chris Mellon wrote: > On 12/28/06, Robin Becker wrote: >> As part of some django usage I need to get some ReportLab C extensions into a >> state where they can be safely used with mod_python. ......... >> > > Just off the top of my head, I'd think that using thread-local storage > instead of static would work, wouldn't it? I'm not that familiar with > mod_python but I'm surely each python interpreter is in a different > thread (if not process) than the others. I was thinking along those lines and if that were the case then I could use > PyObject* PyThreadState_GetDict() > > Return value: Borrowed reference. > Return a dictionary in which extensions can store thread-specific state information. > Each extension should use a unique key to use to store state in the dictionary. > It is okay to call this function when no current thread state is available. > If this function returns NULL, no exception has been raised and the caller should > assume no current thread state is available. Changed in version 2.3: Previously > this could only be called when a current thread is active, and NULL meant that > an exception was raised. I'm just not sure that your guess is true though. It seems that PyThreadState* Py_NewInterpreter() points only to the first thread. Presumably I want to initialize my extension only in one of the possibly many threads in an interpreter. I think I need something called PyObject* PyInterpreterState_GetDict() but I don't think that exists. -- Robin Becker From carsten at uniqsys.com Wed Dec 27 13:33:55 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Wed, 27 Dec 2006 13:33:55 -0500 Subject: how can I modify an imported variable ? In-Reply-To: References: Message-ID: <1167244435.3388.40.camel@dot.uniqsys.com> On Wed, 2006-12-27 at 18:10 +0000, yomgui wrote: > actually, it is not linked to threading but to the scope. > the second attempt to access MyPackage.aVariable > is inside the __init__ of a class > and this seems to be the problem. > > I believe it is a genuine python bug. Please post a minimal but complete (runnable) example that demonstrates your problem. That way, we'll have a chance to actually figure out what you're doing wrong. -Carsten From steve at REMOVE.THIS.cybersource.com.au Fri Dec 29 11:35:01 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 30 Dec 2006 03:35:01 +1100 Subject: I want to see all the variables References: <45952426.1080800@websafe.com> Message-ID: On Fri, 29 Dec 2006 08:20:22 -0600, Larry Bates wrote: > johnf wrote: >> Hi, >> When I use dir() I don't see the __ underscore items. Is there anything >> that will show all the private vars and functions? >> >> johnf > > The idea of the underscore items is that they aren't to be used by > you. Double leading+trailing underscore attributes are NOT private, they are *special* but public (e.g. __dict__, __class__, __str__, etc.). If you don't believe me, have a look at dir(int) and count the underscored attributes listed. Then try to find __dict__, __name__, __bases__, __base__ or __mro__ within the list. Why are they suppressed? But even if underscored attributes were private, the Python philosophy is that private attributes are private by convention only -- even name-mangled __private methods can be reached if you know how. > If you wish to access private variables and functions you will > almost certainly have to look at the source code to make sure of > what they are and how they can be utilized. Not so. >>> class Parrot(object): ... def _private(self): ... """Private method, returns a magic string.""" ... return "Don't touch!!!" ... >>> Parrot._private.__doc__ "Private method, returns a magic string." -- Steven. From paul at boddie.org.uk Wed Dec 13 17:18:21 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 13 Dec 2006 14:18:21 -0800 Subject: CLPython (was Re: merits of Lisp vs Python) References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <7xejr5y755.fsf@ruckus.brouhaha.com> <1166038096.200379.286830@80g2000cwy.googlegroups.com> Message-ID: <1166048301.513012.245480@73g2000cwn.googlegroups.com> Willem Broekema wrote: > Paul Rubin wrote: > > Does this count as a "children of a lesser Python"? > > This sounds like a quite derogatory first question. I wouldn't take it that way: it's only a quote from an opinion piece about alternative Python implementations (albeit a contentious one). > CLPython is not a dead and abandoned project, nor is execution speed > its main goal, nor are Python semantics bended anywhere (it can run > the Pie-thon benchmark). Sure, some recently introduced language > features are missing, but with just a little effort that's solved... What would it take to get Python people more interested in it? I've been monitoring the site [1] and the mailing list [2] for some time, but nothing particularly visible seems to be happening. And wouldn't a more prominent announcement be the first step to some real publicity? I think it only got announced on comp.lang.lisp [3] with someone picking up on it in comp.lang.python. Perhaps getting it on the python.org front page would attract some attention, although I accept that a lot of Python developers would rather mess around writing C than writing Lisp. Anyway, I'm happy to hear that you're still working on CLPython. Paul P.S. Follow-ups set to comp.lang.python. [1] http://trac.common-lisp.net/clpython/ [2] http://common-lisp.net/pipermail/clpython-devel/ [3] http://groups.google.com/group/comp.lang.lisp/msg/57ae88c5f9a59143 From paddy3118 at netscape.net Sat Dec 9 00:37:48 2006 From: paddy3118 at netscape.net (Paddy) Date: 8 Dec 2006 21:37:48 -0800 Subject: I think Python is a OO and lite version of matlab References: <1165564104.379172.272890@l12g2000cwl.googlegroups.com> Message-ID: <1165642668.090366.67300@16g2000cwy.googlegroups.com> Allen wrote: > Does anyone agree with me? > If you have used Matlab, welcome to discuss it. I'm sorry Allen, but Python is heading on the long road to being Lisp. Matlab will have to wait its turn ;-) From gagsl-py at yahoo.com.ar Mon Dec 11 16:06:58 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 18:06:58 -0300 Subject: Lookup caching In-Reply-To: <457b69ec$0$16153$4fafbaef@reader3.news.tin.it> References: <457b69ec$0$16153$4fafbaef@reader3.news.tin.it> Message-ID: <7.0.1.0.0.20061211180439.03f8ded8@yahoo.com.ar> At Saturday 9/12/2006 23:04, Andrea Griffini wrote: >I implemented that crazy idea and seems working... in its >current hacked state can still pass the test suite (exluding What crazy idea? And what is this supposed to do? -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From sjmachin at lexicon.net Mon Dec 18 21:43:42 2006 From: sjmachin at lexicon.net (John Machin) Date: 18 Dec 2006 18:43:42 -0800 Subject: pyExcelerator question References: <1166477288.063934.221390@t46g2000cwa.googlegroups.com> Message-ID: <1166496222.763413.71590@48g2000cwx.googlegroups.com> Gerry wrote: > I'd like to word wrap some cells, but not others, in an Excel > spreadsheet, using pyExcelerator and Excel 2003, SP1, under XP. > > The code below creates the spreadsheet, but both cells are > word-wrapped. > > As far as I can tell, the second call to XFStyle() overwrites a GLOBAL > wrap setting, and affects even cells written before the call to > XFStyle. You are mostly correct. In Style.py, each style gets initialised to refer to a module-global bunch of default objects. No copying is done. Have a look at the patched code down the bottom of this posting -- it appears to work. > > Can anyone shed any light? > > Thanks, > > Gerry > > ============================ > from pyExcelerator import * > > > w = Workbook() > ws = w.add_sheet("alpha") > > style = XFStyle() > style.alignment.wrap = Alignment.NOT_WRAP_AT_RIGHT > ws.write(1,1,"Not wrapped" + "-" * 50, style) > > style2 = XFStyle() > style2.alignment.wrap = Alignment.WRAP_AT_RIGHT > ws.write(2,1,"Wrapped" + "-" * 50, style2) > > w.save("test.xls") if 0: # original _default_num_format = 'general' _default_font = Formatting.Font() _default_alignment = Formatting.Alignment() _default_borders = Formatting.Borders() _default_pattern = Formatting.Pattern() _default_protection = Formatting.Protection() class XFStyle(object): def __init__(self): self.num_format_str = _default_num_format self.font = _default_font self.alignment = _default_alignment self.borders = _default_borders self.pattern = _default_pattern self.protection = _default_protection else: # patch class XFStyle(object): def __init__(self): self.num_format_str = 'general' self.font = Formatting.Font() self.alignment = Formatting.Alignment() self.borders = Formatting.Borders() self.pattern = Formatting.Pattern() self.protection = Formatting.Protection() If this works for you, you might like to submit a patch to http://sourceforge.net/tracker/?func=browse&group_id=134081&atid=730645 HTH, John From bg_ie at yahoo.com Thu Dec 28 04:12:58 2006 From: bg_ie at yahoo.com (bg_ie at yahoo.com) Date: 28 Dec 2006 01:12:58 -0800 Subject: Python Wrapper for C# Com Object Message-ID: <1167297178.937748.91790@79g2000cws.googlegroups.com> Hi, I wish to write a Python wrapper for my C# COM object but am unsure where to start. I have a dll and a tlb file, and I can use this object in C via the following code - // ConsolApp.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "windows.h" #include "stdio.h" #import "C:\Documents and Settings\X\Mina dokument\Visual Studio 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb" using namespace X_COMObject; int _tmain(int argc, _TCHAR* argv[]) { CoInitialize(NULL); X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class)); XCOM_Interface *X_com_ptr ; X_com_ptr = p ; X_com_ptr->SetID(10); int x = X_com_ptr->GetID(); printf("%d",x); getchar(); return 0; } Can anyone offer me some tips as to how to do this in Python? Thanks very much for your help, Barry. From horpner at yahoo.com Fri Dec 8 15:08:20 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 8 Dec 2006 21:08:20 +0100 Subject: Snake references just as ok as Monty Python jokes/references in python community? :) References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> Message-ID: On 2006-12-08, Roy Smith wrote: > In article <1165607250.544331.124360 at j72g2000cwa.googlegroups.com>, > "seberino at spawar.navy.mil" wrote: >> I'm semi-seriously wondering if snake jokes are valid in the >> Python community since technically, Python came from Monty >> Python, not slithery animals. >> >> Problem is I don't know that anyone born after Elvis died gets >> any of these Monty Python jokes. >> >> Is it kosher to make snake jokes/references even though >> officially they don't have anything to do with the name of our >> favorite language? (*Everyone* gets snake jokes! :) > > It's people like you wot cause unrest! I think the decent people of this newsgroup are sick and tired of being told that the decent people of this newsgroup are sick and tired. I'm certainly not! And I'm sick and tired of being told that I am. -- Neil Cerutti Sermon Outline: I. Delineate your fear II. Disown your fear III. Displace your rear --Church Bulletin Blooper From jonc at icicled.net Sun Dec 10 14:48:45 2006 From: jonc at icicled.net (Jonathan Curran) Date: Sun, 10 Dec 2006 13:48:45 -0600 Subject: zeros() In-Reply-To: References: Message-ID: <200612101348.45729.jonc@icicled.net> On Sunday 10 December 2006 12:36, vertigo wrote: > Hello > > How to create table with string variables ? > I tried > > import string > X = zeros([10,10], string) > > (i used Numeric.Float earlier, but now can't find string class anywhere) > > Thanx I've read that the Numeric module is being replaced/better supported by NumPy. Anyway, try: X = zeros ([10,10], str) I have numpy installed so I did: >>> from numpy import * >>> X = zeros ([10,10], str) >>> X array([['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '', '']], dtype='|S1') >>> seemed to work, hope this helps. - Jonathan From horpner at yahoo.com Sat Dec 2 10:54:32 2006 From: horpner at yahoo.com (Neil Cerutti) Date: Sat, 02 Dec 2006 15:54:32 GMT Subject: converting dict to object References: <7649225.post@talk.nabble.com> Message-ID: On 2006-12-02, Michel Claveau wrote: > Hi! > > Yes. > > But... > > Try: d = {'a': 1, 'b': 2, 'def': 123} > > Ok, I go out... How to convert a list of strings into a list of integers: a = ['82', '4', '16'] ai = [int(i) for i in a] Yes. But... Try: a = ['82', '4', '16', 'foo'] Ok, I go out... -- Neil Cerutti From scumitchell at gmail.com Fri Dec 8 11:56:13 2006 From: scumitchell at gmail.com (scum) Date: 8 Dec 2006 08:56:13 -0800 Subject: MySQL-python-1.2.1_p2, Python 2.5 and OS X Tiger Message-ID: <1165596973.310634.108830@j72g2000cwa.googlegroups.com> How do you install MySQL-python-1.2.1_p2 on a PPC OS X 10.4 machine with MySQL 4.1? >>> python setup.py build ... ... _mysql.c:2854: error: parse error before ')' token _mysql.c:2854: error: called object '&' is not a function _mysql.c:2854: error: called object '&' is not a function _mysql.c:2854: error: called object '*(&)' is not a function lipo: can't figure out the architecture type of: /var/tmp//ccurx79n.out error: command 'gcc' failed with exit status 1 From mhellwig at xs4all.nl Sat Dec 30 17:17:58 2006 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Sat, 30 Dec 2006 23:17:58 +0100 Subject: find login name of user? In-Reply-To: References: <1167511677.250618.285250@v33g2000cwv.googlegroups.com> Message-ID: <4596e568$0$327$e4fe514c@news.xs4all.nl> Uwe Hoffmann wrote: > rattan at cps.cmich.edu schrieb: >> Is there a function/module to find the login name of the user under >> UNIX environment? > > > http://docs.python.org/lib/os-procinfo.html > > http://docs.python.org/lib/module-pwd.html Speaking of that, is there any reason why there isn't any syntactic sugar that gives the illusion of platform neutral fetching of the user name? -- mph From steve at REMOVE.THIS.cybersource.com.au Sun Dec 10 09:24:07 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 11 Dec 2006 01:24:07 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: On Sun, 10 Dec 2006 02:12:29 -0500, Bill Atkins wrote: > Steven D'Aprano writes: > >> Rightly or wrongly, people fear that Lisp's macros push Lisp closer to >> that hypothetical anything-goes language than is healthy. Maybe that's a > > Wrongly. That's your opinion, and as an experienced Lisp coder, it is an opinion worth treating seriously. Nevertheless, a mere denial doesn't constitute evidence, let alone proof. > And do they? To paraphrase Brian Griffin: "Are you sure it > was people? Are you sure it wasn't...nothing?" You know, I'm really starting to think that you Lispers -- and I hate to generalise, but in this case I feel I'm forced to -- have a real problem here. On the one hand, I keep reading how unfair it is that the rest of the programming world won't give Lisp a fair go, that all these other programmers are spreading FUD over Lisp, especially over the macros and parentheses. And then you come along and imply that nobody is concerned about Lisp macros. So which is it? If Lisp is so self-evidently better than every other language, and if nobody has any fears or concerns with Lisp, why is Lisp a fringe language? Not as fringe as it was ten years ago, and maybe growing in popularity, and it is beyond all doubt that Lisp has a lot of influence amongst language designers, but outside of a few niche areas, its still a fringe language. >> My point isn't whether or not their claims are correct (a "couple" of >> macros? really?) but that things like this feed the perception that Lisp >> is close to that hypothetical language where anything could be anything. >> If anything could be anything, do you really know what (+ 1 2) means >> without reading every line of code? > > Jesus H Christ. Didn't you just get through talking about how easily > someone can redefine built-ins in Python? Yes. But you can't redefine 1+2 in Python, at least not without hacking the interpreter. Can you redefine (+ 1 2) in Lisp? >> Even something simple like file I/O can be abused. Example: I've seen > > Agreed. This is why I've always argued that I/O should never have > been included in programming languages. Too dangerous. And, let's > face it, pretty old-fashioned these days. Ha ha, I love good sarcasm! Unfortunately, that isn't good sarcasm. >> (This is an interesting demonstration that any language that allows file >> I/O and importing of external program files can always treat functions >> as data, even if the language doesn't directly support it. An alternative >> would be to keep the strings in memory instead of writing to a module, >> then use exec on them instead of importing the module.) > > No, it treats code as text. See the difference? Text is data. What is the point of your comment? You don't have to argue about every thing I say, even the ones we agree on. Look again at what I wrote. Is there anything that gave you the impression that I think that having the ability to write text to a file and import it is better than actually supporting functional programming directly? [snip] >> Is that an argument against factory functions? Damn straight it is: >> they are a powerful tool, and in the hands of morons, they can be >> dangerous. Does that mean that languages shouldn't permit higher-order >> functions? Not necessarily: all programming tools can be misused, but some >> can be misused more easily than others. Power and risk is often a >> trade-off, and language designers can't eliminate all risk of stupid >> behaviour, but they can design the language to allow whatever level of >> risk they believe is acceptable. (E.g. there is no doubt that C's raw >> pointers are powerful, but many languages deliberately don't use them.) > > Could you please calm down? Huh? >> The risk of stupid factory functions is small compared to the benefit, but >> maybe there is some domain somewhere where the ideal solution is a >> language that DOESN'T treat functions as first class objects, deliberately >> weakening the language so that a particular class of errors (or stupid >> behaviour) just cannot happen. But that language isn't Python. > > Could you calm down? Okay, once was funny. Twice is worrying. What exactly is giving you the idea I need to calm down? Was it the use of reasoning and logic? Perhaps it was the attempt to be reasonable and moderate and find some middle ground that we could agree on, or if not agree, at least say "Well, I disagree with you, but at least I understand where you are coming from"? >> When it comes to Lisp's macros, the perception is that the power is > > NB: here, "the" means "Steven D'Aprano's" (the number of meanings > "the" can assume in different contexts is quite surprising). > >> correspondingly greater, and the risk of abuse even more so. The safe > > Don't you get tired of making the same arguments? Because I'm getting > tired of making the same counterpoints. From greg.johnston at gmail.com Mon Dec 11 22:55:47 2006 From: greg.johnston at gmail.com (Greg Johnston) Date: 11 Dec 2006 19:55:47 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165875324.171765.176660@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> Message-ID: <1165895747.477264.53720@16g2000cwy.googlegroups.com> Stephen Eilert wrote: > So, let's suppose I now want to learn LISP (I did try, on several > occasions). What I would like to do would be to replace Python and code > GUI applications. Yes, those boring business-like applications that > have to access databases and consume those new-fangled web-services and > whatnot. Heck, maybe even code games using DirectX. DrScheme for the first. Oh...well, there's loads of OpenGL support if you can bear using that instead of DirectX. If you want CL, cl-opengl and cells-gtk seem to work well. > So, how would I do that? For Python, that was simple. I learned the > basics, then moved to the libraries, learning as I went. Python has > some excelent online resources. http://www.gigamonkeys.com/book/ (Practical Common Lisp) http://www.paulgraham.com/onlisp.html (On Lisp) http://www.htdp.org/ (HTDP) http://mitpress.mit.edu/sicp/ (SICP) http://schemecookbook.org/ http://www.cliki.net/index (Note: I mixed Scheme and CL pages above) Not sure what other online resources you want. > No, I don't want to see yet another Fibonacci example. No, console > output is not fun. And yes, I know about this list processing stuff. > All I can find are introductions to LISP written for computer science > courses. I can't seem to put together all those mnemonics into a > working program. LISP is full of primitives with 3-4 characters, chosen > for historical reasons. You're welcome to use things like first, rest, or second instead of car, cdr, or cadr, but I always find the latter easier (car and cdr are composable, and remind you that you're using cons cells). What other mnemonics are there? I guess cons, but that shouldn't be hard... On the other hand, Python has no 3-letter words. *struck dead by a flying "def"* From carsten at uniqsys.com Mon Dec 4 19:36:47 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 04 Dec 2006 19:36:47 -0500 Subject: decorators question In-Reply-To: References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> <457476E6.5000603@youjoy.org> <1165269784.394649.7940@l12g2000cwl.googlegroups.com> <1165271780.3345.72.camel@dot.uniqsys.com> Message-ID: <1165279007.3536.10.camel@localhost.localdomain> On Mon, 2006-12-04 at 23:44 +0100, Fredrik Lundh wrote: > Carsten Haese wrote: > > > * The function body gets compiled into byte code (but not executed). > > careful: when you get as far as executing the "def" statement, the > function body has already been compiled. the byte code for the function > is stored as a module-level constant: You are, as always, correct, but I deliberately hid this detail inside the "roughly, modulo irrelevant implementation details" disclaimer in an attempt of causing the OP the smallest possible amount of confusion. -Carsten From kkylheku at gmail.com Sun Dec 10 02:12:47 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 9 Dec 2006 23:12:47 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165701024.138305.241500@j72g2000cwa.googlegroups.com> Message-ID: <1165734767.790505.55390@79g2000cws.googlegroups.com> Steven D'Aprano wrote: > Oh my god! Lisp can echo STRINGS to the interpreter? Indeed yes, but that's not exactly what's happening here. (And it's not necessarily an interpreter, by the way. Some Lisp implementations compile every expression to machine code and branch to it. Corman Lisp, for instance, doesn't even contain an interpreter). My point is not to showcase anything about Lisp, but simply to point out the irony that in the same paragraph in which you are going on about Lisp being unreadable compared to human written languages, there appear pieces of parseable Lisp syntax. > Why didn't somebody somebody tell me that! The answer to that would be: because your being properly informed for these kinds of debates is your responsibility, and it is assumed. > !!! That *completely* changes my mind about the language! If you keep up the mind changing, you can maybe trade up to one that works in perhaps fewer than twenty transactions. (Think: Kyle MacDonald). From s0094060 at sms.ed.ac.uk Sat Dec 2 17:39:50 2006 From: s0094060 at sms.ed.ac.uk (Sean Hammond) Date: Sat, 2 Dec 2006 22:39:50 +0000 Subject: Anyone understand this syntax error? Message-ID: Anyone understand this? Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def markdown_perl(input): ... """Send 'input' (string) to the markdown perl script, and return the ... output from markdown (string). ... ... input: a string of markdown-formatted text, including \n's at the end ... of lines, that will be sent to the markdown process. ... ... returns: a string of valid XHTML from markdown ... """ ... import tempfile ... import commands ... file = tempfile.NamedTemporaryFile() ... file.write(input) ... file.flush() ... return commands.getoutput('./markdown.pl '+file.name) File "", line 15 return commands.getoutput('./markdown.pl '+file.name) ^ SyntaxError: invalid syntax >>> I don't get it. Syntax seems fine to me, just a normal string concatenation. -- From barnaclejive at gmail.com Tue Dec 12 21:23:43 2006 From: barnaclejive at gmail.com (mkppk) Date: 12 Dec 2006 18:23:43 -0800 Subject: How to subclass sets.Set() to change intersection() behavior? Message-ID: <1165976623.478230.164660@j72g2000cwa.googlegroups.com> I have kind of strange change I'd like to make to the sets.Set() intersection() method.. Normally, intersection would return items in both s1 and s2 like with something like this: s1.intersection(s2) I want the item matching to be a bit "looser".. that is, items in s2 that match to just the beginning of items in s1 would be included in the result of intersection(). I do not know how intersection() is implemented, so I just kinda guessed it might have something to do with how it compares set elements, probably using __eq__ or __cmp__. SO, I though if I override these methods, maybe magically that would affect the way intersection works.. so far, no luck =( Please take a look at the little example script to try to illustrate what I would like to happen when using my subclass.. Is my approach totally wrong, or is there a better way to accomplish this? I am trying to avoid running through nested loops of lists (see final example). P.S. - the lists I am working with are small, like 1-10 items each - actually, not so concerned witht the items in the resulting set, just want to know that the two sets have at least one item "in common" - would welcome any other suggestions that would be FAST import sets # the way set intersection normally works s1=sets.Set(['macys','installment','oil','beans']) s2=sets.Set(['macy','oil','inst','coffee']) # prints Set(['oil']), as expected.. print s1.intersection(s2) # my subclass, mySet - I don't know how to effect the .intersection() method # my best guess was to change the __eq__ or maybe the __cmp__ methods?? # for now, mySet does nothing special at all but call the functions from sets.Set class mySet(sets.Set): def __init__(self,iterable=None): sets.Set.__init__(self,iterable) def __eq__(self,other): # maybe something here? return sets.Set.__eq__(self,other) def __cmp__(self,other): # or maybe something here? return sets.Set.__cmp__(self,other) # the same sets used in previous example s3=mySet(['macys','installment','oil','beans']) s4=mySet(['macy','oil','inst','coffee']) # and, the same result: mySet(['oil']) print s3.intersection(s4) #**************************************************************************** # THE RESULT I WOULD LIKE TO GET WOULD LOOK LIKE THIS # because I want items of s4 to match to the beginning of items in s3 # actually I am not so concerned with the result of intersection, just want to know there there was # at least one item in common between the two sets.. # # mySet(['macy','inst','oil']) #**************************************************************************** # this is the list implementation I am trying to avoid because I am under the impression using set would be faster..(??) # please let me know if I am wrong about that assumption L1=['macys','installment','oil','beans'] L2=['macy','oil','inst','coffee'] L3=[] for x in L1: for y in L2: if x.startswith(y): L3.append(y) # prints ['macy', 'inst', 'oil'] print L3 From nagle at animats.com Mon Dec 25 20:00:39 2006 From: nagle at animats.com (John Nagle) Date: Mon, 25 Dec 2006 17:00:39 -0800 Subject: BeautifulSoup vs. loose & chars Message-ID: I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&". Is there some way I can get BeautifulSoup to clean those up? There are various parsing options related to "&" handling, but none of them seem to do quite the right thing. If I write the BeautifulSoup parse tree back out with "prettify", the loose "&" is still in there. So the output is rejected by XML parsers. Which is why this is a problem. I need valid XML out, even if what went in wasn't quite valid. John Nagle From maxime_phan at hotmail.com Sun Dec 3 06:16:44 2006 From: maxime_phan at hotmail.com (maxime_phan at hotmail.com) Date: 3 Dec 2006 03:16:44 -0800 Subject: twisted problem with reactor.stop() Message-ID: <1165144604.277008.266490@79g2000cws.googlegroups.com> hello, everyone I use twisted 1.3 in my python application. in my program, I have one server and on client running at same time (so 2 reactor.run(installSignalHandlers=0) ) the client run in one thread and the server in an other thread ( reactor.callInThread(self.client... , reactor.callInThread(self.server ....) when I catch "escape" button, I make a reactor.stop() but it doesn't seem to work and quit, and the application freeze. does anyone have any solution to quit the application with twisted? thanks in advance Maxime From paddy3118 at netscape.net Fri Dec 29 06:32:16 2006 From: paddy3118 at netscape.net (Paddy) Date: 29 Dec 2006 03:32:16 -0800 Subject: Anyone persuaded by "merits of Lisp vs Python"? In-Reply-To: <1167372073.541929.57370@48g2000cwx.googlegroups.com> References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> <1167372073.541929.57370@48g2000cwx.googlegroups.com> Message-ID: <1167391935.980609.279850@79g2000cws.googlegroups.com> Carl Banks wrote: > If you were so keen on avoiding a flame war, the first thing you should > have done is to not cross-post this. I want to cover Pythonistas looking at Lisp and Lispers looking at Python because of the thread. The cross posting is not as flame bait. - Paddy. From google at mrabarnett.plus.com Wed Dec 13 17:31:42 2006 From: google at mrabarnett.plus.com (MRAB) Date: 13 Dec 2006 14:31:42 -0800 Subject: how can i write a hello world in chinese with python In-Reply-To: References: <1165982024.978824.146920@n67g2000cwd.googlegroups.com> <1165985255.490054.290680@80g2000cwy.googlegroups.com> <1165995641.270460.124350@73g2000cwn.googlegroups.com> Message-ID: <1166049102.276684.311510@t46g2000cwa.googlegroups.com> Dennis Lee Bieber wrote: > On 12 Dec 2006 23:40:41 -0800, "kernel1983" > declaimed the following in gmane.comp.python.general: > > > and I tried unicode and utf-8 > > I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not > > to use > > > "unicode" is a term covering many sins. "utf-8" is a specification > for encoding elements of specific unicode characters using 8-bit > elements (I believe by using certain codes x00 to x7F alone as "normal", > and then x80 to xFF to represent an "escape" to higher [16-bit] element > sets). > > "\xEF\xBB\xBF" is just a byte string with no identifier of what > encoding is in use (unless the first one or two are supposed to be > BOM)... In the "Windows: Western" character set, it is equivalent to > small-i-diaeresis/right-guillemot/upside-down? (?) In MS-DOS: Western > Europe, those same bytes represent an > acute-accent/double-down&left-box-drawing/solid-down&left > > I've not done any unicode work (iso-latin-1, or subset thereof, has > done for me). I also don't know Mac's, so I don't know if the windowing > API has specific calls for Unicode data... But you probably have to > encode or decod that bytestring into some compatible unicode > representation. > When you save a textfile as UTF-8 in Notepad.exe (Windows) it puts the bytestring "\xEF\xBB\xBF" at the start to indicate that it's UTF-8 and not ANSI (ie 8-bit characters). The bytes are actually the BOM bytestring "\xFE\xFF" encoded in UTF-8. From Ingo.Wolf at gmx.de Thu Dec 7 05:48:14 2006 From: Ingo.Wolf at gmx.de (iwl) Date: 7 Dec 2006 02:48:14 -0800 Subject: Embedded python adding variables linking to C++-Variables / callbacks Message-ID: <1165488494.074166.169240@79g2000cws.googlegroups.com> Hello, I would like to add Variables to my embedded python which represents variables from my C++-Programm. I found C-Api-funcs for adding my C-Funcs to python but none to add variables. I would like some C-Function is called when the added Python-varible is set (LValue) and some other when it is read (RValue). Can I do this. May be I have to do this in python and call the C-Funcs from a python callback. May be somebody can give short hints what to look for. From hg at nospam.org Tue Dec 19 09:38:54 2006 From: hg at nospam.org (hg) Date: Tue, 19 Dec 2006 08:38:54 -0600 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> Message-ID: <2QShh.22575$Rj.15414@newsfe19.lga> The Night Blogger wrote: > Can someone recommend me a good API for writing a sexy looking (Rich UI > like WinForms) shrink wrap application > > My requirement is that the application needs to look as good on Windows as > on the Apple Mac I would download the wxPython demo and test it on all platforms if I were you: no coding and you see stuff right away / decide whether it is a good choice. ... I know it is mine (although I must confess I never tried it on a mac). hg From burhan.khalid at gmail.com Sat Dec 2 01:23:46 2006 From: burhan.khalid at gmail.com (Burhan) Date: 1 Dec 2006 22:23:46 -0800 Subject: Printing Barcodes from webapp? Message-ID: <1165040626.505772.312350@j72g2000cwa.googlegroups.com> Hello Group: I am in the planning stages of an application that will be accessed over the web, and one of the ideas is to print a barcode that is generated when the user creates a record. The application is to track paperwork/items and uses barcodes to easily identify which paper/item belongs to which record. Is there an easy way to generate barcodes using Python -- considering the application will be printing to a printer at the client's machine? I thought of two ways this could be done; one would be to interface with the printing options of the browser to ensure that margins, headers, footers are setup properly (I have done this before using activex and IE, but with mixed results); the other would be to install some small application at the client machine that would intercept the print jobs and format them properly (taking the printing function away from the browser). Does anyone have any experience or advice? Any links I could read up on to help me find out how to program this? Another way (easier hopefully) to accomplish this? Thanks for any advice. From spedrosa at gmail.com Mon Dec 11 17:15:25 2006 From: spedrosa at gmail.com (Stephen Eilert) Date: 11 Dec 2006 14:15:25 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165873130.318729.298260@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> Message-ID: <1165875324.171765.176660@80g2000cwy.googlegroups.com> JShrager at gmail.com escreveu: > > Yes, but these are community symbols or tribe marks. They don't have > > much meaning per se, just like the language name or a corporate > > identity. > > Unfortunately, I don't believe that this is entirely correct....I do > lurk c.l.p and see quite often people arguing (if briefly) about what > the one (and preferably only one) obvious way of doing things is. This > is only subtly ridiculous. The other ("It fits your brain") is much > less subtle, and much more problematic: > > Now, I'm willing to buy that "it fits your brain" is taken less > seriously, but ... > > > However they express an attitude ( being easy and free from > > language design redundancy ) that can be measured at least subjectively > > by the user. If Ruby "fits the brain" better, then people will simply > > drop Python in future or right now. There is nothing deep about it. > > ...if not deep, at least insidious, as demonstrated in part by the > current thread wherein, until forced to give it up, the present > pythonistas spent a significant number of chars trying to arguing, in > effect, that Lisp does NOT fit (one's) brain (e.g, is easier to use, > easier to learn, etc.) IN GENERAL. It seems to me (here and on c.l.p) > that many pythonista have somehow drunk this Koolaide and that as a > result have a sort of smug superiority about it. Of course, Lispers > have a smug superiority as well, but at least we have actual language > features (macros, compositionality, compilers) to wave around, not > ridiculous pop psychological noise. Right. So, let's suppose I now want to learn LISP (I did try, on several occasions). What I would like to do would be to replace Python and code GUI applications. Yes, those boring business-like applications that have to access databases and consume those new-fangled web-services and whatnot. Heck, maybe even code games using DirectX. So, how would I do that? For Python, that was simple. I learned the basics, then moved to the libraries, learning as I went. Python has some excelent online resources. No, I don't want to see yet another Fibonacci example. No, console output is not fun. And yes, I know about this list processing stuff. All I can find are introductions to LISP written for computer science courses. I can't seem to put together all those mnemonics into a working program. LISP is full of primitives with 3-4 characters, chosen for historical reasons. The bottom line is that I didn't have a pleasant learning experience. Perhaps the lispers here could offer some insights? Stephen From tony at PageDNA.com Fri Dec 29 18:00:03 2006 From: tony at PageDNA.com (Tony Lownds) Date: Fri, 29 Dec 2006 15:00:03 -0800 Subject: PEP 3107 Function Annotations for review and comment Message-ID: (Note: PEPs in the 3xxx number range are intended for Python 3000) PEP: 3107 Title: Function Annotations Version: $Revision: 53169 $ Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec 2006) $ Author: Collin Winter , Tony Lownds Status: Draft Type: Standards Track Requires: 362 Content-Type: text/x-rst Created: 2-Dec-2006 Python-Version: 3.0 Post-History: Abstract ======== This PEP introduces a syntax for adding arbitrary metadata annotations to Python functions [#functerm]_. Rationale ========= Because Python's 2.x series lacks a standard way of annotating a function's parameters and return values (e.g., with information about what type a function's return value should be), a variety of tools and libraries have appeared to fill this gap [#tailexamp]_. Some utilise the decorators introduced in "PEP 318", while others parse a function's docstring, looking for annotations there. This PEP aims to provide a single, standard way of specifying this information, reducing the confusion caused by the wide variation in mechanism and syntax that has existed until this point. Fundamentals of Function Annotations ==================================== Before launching into a discussion of the precise ins and outs of Python 3.0's function annotations, let's first talk broadly about what annotations are and are not: 1. Function annotations, both for parameters and return values, are completely optional. 2. Function annotations are nothing more than a way of associating arbitrary Python expressions with various parts of a function at compile-time. By itself, Python does not attach any particular meaning or significance to annotations. Left to its own, Python simply makes these expressions available as described in `Accessing Function Annotations`_ below. The only way that annotations take on meaning is when they are interpreted by third-party libraries. These annotation consumers can do anything they want with a function's annotations. For example, one library might use string-based annotations to provide improved help messages, like so:: def compile(source: "something compilable", filename: "where the compilable thing comes from", mode: "is this a single statement or a suite?"): ... Another library might be used to provide typechecking for Python functions and methods. This library could use annotations to indicate the function's expected input and return types, possibly something like:: def haul(item: Haulable, *vargs: PackAnimal) -> Distance: ... However, neither the strings in the first example nor the type information in the second example have any meaning on their own; meaning comes from third-party libraries alone. 3. Following from point 2, this PEP makes no attempt to introduce any kind of standard semantics, even for the built-in types. This work will be left to third-party libraries. There is no worry that these libraries will assign semantics at random, or that a variety of libraries will appear, each with varying semantics and interpretations of what, say, a tuple of strings means. The difficulty inherent in writing annotation interpreting libraries will keep their number low and their authorship in the hands of people who, frankly, know what they're doing. Syntax ====== Parameters ---------- Annotations for parameters take the form of optional expressions that follow the parameter name. This example indicates that parameters 'a' and 'c' should both be an ``int``, while parameter 'b' should be a ``dict``:: def foo(a: int, b: dict, c: int = 5): ... In pseudo-grammar, parameters now look like ``identifier [: expression] [= expression]``. That is, annotations always precede a parameter's default value and both annotations and default values are optional. Just like how equal signs are used to indicate a default value, colons are used to mark annotations. All annotation expressions are evaluated when the function definition is executed. Annotations for excess parameters (i.e., ``*args`` and ``**kwargs``) are indicated similarly. In the following function definition, ``*args`` is flagged as a tuple of ``int``, and ``**kwargs`` is marked as a dict whose keys are strings and whose values are of type ``str``:: def foo(*args: int, **kwargs: str): ... Note that, depending on what annotation-interpreting library you're using, the following might also be a valid spelling of the above:: def foo(*args: [int], **kwargs: {str: str}): ... Only the first, however, has the BDFL's blessing [#blessedexcess]_ as the One Obvious Way. Return Values ------------- The examples thus far have omitted examples of how to annotate the type of a function's return value. This is done like so:: def sum(*args: int) -> int: ... The parameter list can now be followed by a literal ``->`` and a Python expression. Like the annotations for parameters, this expression will be evaluated when the function definition is executed. The grammar for function definitions [#grammar]_ is now:: decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE decorators: decorator+ funcdef: [decorators] 'def' NAME parameters ['->' test] ':' suite parameters: '(' [typedargslist] ')' typedargslist: ((tfpdef ['=' test] ',')* ('*' [tname] (',' tname ['=' test])* [',' '**' tname] | '**' tname) | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) tname: NAME [':' test] tfpdef: tname | '(' tfplist ')' tfplist: tfpdef (',' tfpdef)* [','] Lambda ------ ``lambda``'s syntax does not support annotations. The syntax of ``lambda`` could be changed to support annotations, by requiring parentheses around the parameter list. However it was decided [#lambda]_ not to make this change because: 1. It would be an incompatible change. 2. Lambda's are neutered anyway. 3. The lambda can always be changed to a function. Accessing Function Annotations ============================== Once compiled, a function's annotations are available via the function's ``func_annotations`` attribute. This attribute is a dictionary, mapping parameter names to an object representing the evaluated annotation expression There is a special key in the ``func_annotations`` mapping, ``"return"``. This key is present only if an annotation was supplied for the function's return value. For example, the following annotation:: def foo(a: 'x', b: 5 + 6, c: list) -> str: ... would result in a ``func_annotation`` mapping of :: {'a': 'x', 'b': 11, 'c': list, 'return': str} The ``return`` key was chosen because it cannot conflict with the name of a parameter; any attempt to use ``return`` as a parameter name would result in a ``SyntaxError``. ``func_annotations`` is an empty dictionary if no there are no annotations on the function. ``func_annotations`` is always an empty dictionary for functions created from ``lambda`` expressions. Standard Library ================ pydoc and inspect ----------------- The ``pydoc`` module should display the function annotations when displaying help for a function. The ``inspect`` module should change to support annotations. Relation to Other PEPs ====================== Function Signature Objects [#pep-362]_ -------------------------------------- Function Signature Objects should expose the function's annotations. The ``Parameter`` object may change or other changes may be warranted. Implementation ============== A sample implementation for the syntax changes has been provided [#implementation]_ by Tony Lownds. Rejected Proposals ================== + The BDFL rejected the author's idea for a special syntax for adding annotations to generators as being "too ugly" [#rejectgensyn]_. + Though discussed early on ([#threadgen]_, [#threadhof]_), including special objects in the stdlib for annotating generator functions and higher-order functions was ultimately rejected as being more appropriate for third-party libraries; including them in the standard library raised too many thorny issues. + Despite considerable discussion about a standard type parameterisation syntax, it was decided that this should also be left to third-party libraries. ([#threadimmlist]_, [#threadmixing]_, [#emphasistpls]_) References and Footnotes ======================== .. [#functerm] Unless specifically stated, "function" is generally used as a synonym for "callable" throughout this document. .. [#tailexamp] The author's typecheck_ library makes use of decorators, while `Maxime Bourget's own typechecker`_ utilises parsed docstrings. .. [#blessedexcess] http://mail.python.org/pipermail/python-3000/2006-May/002173.html .. [#rejectgensyn] http://mail.python.org/pipermail/python-3000/2006-May/002103.html .. _typecheck: http://oakwinter.com/code/typecheck/ .. _Maxime Bourget's own typechecker: http://maxrepo.info/taxonomy/term/3,6/all .. [#threadgen] http://mail.python.org/pipermail/python-3000/2006-May/002091.html .. [#threadhof] http://mail.python.org/pipermail/python-3000/2006-May/001972.html .. [#threadimmlist] http://mail.python.org/pipermail/python-3000/2006-May/002105.html .. [#threadmixing] http://mail.python.org/pipermail/python-3000/2006-May/002209.html .. [#emphasistpls] http://mail.python.org/pipermail/python-3000/2006-June/002438.html .. [#implementation] http://python.org/sf/1607548 .. _numeric: http://docs.python.org/lib/typesnumeric.html .. _mapping: http://docs.python.org/lib/typesmapping.html .. _sequence protocols: http://docs.python.org/lib/typesseq.html .. [#grammar] http://www.python.org/doc/current/ref/function.html .. [#lambda] http://mail.python.org/pipermail/python-3000/2006-May/001613.html .. [#pep-362] http://www.python.org/dev/peps/pep-0362/ Copyright ========= This document has been placed in the public domain. .. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 coding: utf-8 End: From nagle at animats.com Mon Dec 18 12:00:06 2006 From: nagle at animats.com (John Nagle) Date: Mon, 18 Dec 2006 17:00:06 GMT Subject: Roundtrip SQL data especially datetime In-Reply-To: <1166436990.570027.237260@t46g2000cwa.googlegroups.com> References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> <1166258893.044093.196820@79g2000cws.googlegroups.com> <1166436990.570027.237260@t46g2000cwa.googlegroups.com> Message-ID: GHUM wrote: >> One side effect of this being third party code is that hosting >>services may not have it available, even when they have both Python >>and MySQL up. This is never a problem with Perl or PHP, so that's >>a negative for Python. > > > I for one think it is a good thing to not have MySQL adapters > integrated into Python core. Neither the philopsophie, nor the licence > of the two products fit together. It's a wire protocol. At one end of a socket, there's MySQL, and at the other end, there's a client. Neither side needs code from the other. The protocol is published. So there's no license issue. John Nagle From cito at online.de Fri Dec 15 10:02:50 2006 From: cito at online.de (Christoph Zwerschke) Date: Fri, 15 Dec 2006 16:02:50 +0100 Subject: tuple.index() In-Reply-To: <1166187479.167471.169270@n67g2000cwd.googlegroups.com> References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <1166187479.167471.169270@n67g2000cwd.googlegroups.com> Message-ID: Tim Golden wrote: > Christoph Zwerschke wrote: >> And can somebody explain what is exactly meant with >> "homogenous data"? > > This seems to have been explained a few times > recently :) Basically, if you have a "list of xs" > and remove one item from it, it is still a "list of xs", According to that definition, everything would be homogenous. I guess what you wanted to say is if you have an "x" and remove one item from it it is still an "x", then it's homogenous. The problem is that depending on how exactly you define "x", you will come to different results. > If you have a tuple containing, say, a 2d coordinate pair, > and remove something from it, it's no longer a coordinate pair. Now here comes the ambiguity. If you interpret "x" as "coordinate tuple" it would be still one (a 1-tuple), but if you interpret "x" as "coordinate pair" then it would indeed not be an "x" any more. So that definition is not really helpful. > A typical example of their combined use is a set of > rows returned from a database: each row is a tuple > of fields, the same as all other such rows, and removing > or adding a field would make no sense. However, add > a new row to the list and it remains a list of rows. Sounds plausible. But when I read a row with the name and forename of a person, I might want to collapse the name and forename into one element before I hand it over to a function that will display it as a table. Or I may want to delete certain elements which are not important. In such cases, having each row as list may also make sense. >> Concretely speaking, which data type should I use >> for coordinate tuples? Usually, tuples are used. Does this mean that I >> should better use lists from now on because all the components have the >> same type? > > This would seem to be slightly false logic (and very > possibly used tongue-in-cheek). Heterogeneous data > doesn't mean that each item *has* to be different, merely > that they *may* be. I don't think it's a problem of false logic but the problem that "homogenous data" is not defined. We probably agree that it usually makes perfect sense to use tuples for coordinates. But in certain mathematical algorithms it also makes sense to ask for the number of zero components of a coordinate tuple - the count() method would be helpful here. The statement "if you are looking for index() or count() for your tuples, you're using the wrong container type" is too extreme I think. I would agree with "it *may indicate* that you should better use lists". -- Christoph From ravehanker at gmail.com Fri Dec 29 03:21:58 2006 From: ravehanker at gmail.com (ravehanker at gmail.com) Date: 29 Dec 2006 00:21:58 -0800 Subject: Kurukshetra Online Programming Contest Message-ID: <1167380518.128059.152030@48g2000cwx.googlegroups.com> Hello There! College of Engineering, Guindy announces the Kurukshetra Online Programming Contest as a part of it's Inter-departmental Tech. Fest, Kurukshetra. The event is your opportunity to compete with the World's best coders with algorithm-centric problems that will rattle your grey matter! The event is to be held on December 31th and is open to all. Date: 31-December-2006 Timings : 14:00hrs - 20:00 hrs Max. Team Size : 3 Prizes Worth 2000 USD!! Do visit http://opc.kurukshetra.org.in and register for the event. From sjmachin at lexicon.net Fri Dec 1 14:35:59 2006 From: sjmachin at lexicon.net (John Machin) Date: 1 Dec 2006 11:35:59 -0800 Subject: How to read the directory which the actively running python file is located in? In-Reply-To: <1164975227.723029.52250@80g2000cwy.googlegroups.com> References: <1164975227.723029.52250@80g2000cwy.googlegroups.com> Message-ID: <1165001759.425103.214190@80g2000cwy.googlegroups.com> anders wrote: > in os module there is many funktion/methods to extract this information > to ask the path to the current running pythonprogram you can do likes > this > > ----- CUT----------- > import os > print os.getcwd() > > ----- CUT ------ > > // Anders > > > Michael Malinowski skrev: > > > Is there a way to read the directory that the currently running python file > > is located in? > > Cheers > > Mike. os.getcwd() provides the "current working directory". This is *not* necessarily the directory that the "currently running python file" [whatever that means] is located in. Try picking what you really want/need out of this: C:\junk\foo>type ..\where.py import sys, os if __name__ == "__main__": print "running as script" else: print "imported module named", __name__ print "code loaded from file", __file__ print "sys.argv[0] is", sys.argv[0] print "cwd is", os.getcwd() C:\junk\foo>..\where.py running as script code loaded from file C:\junk\where.py sys.argv[0] is C:\junk\where.py cwd is C:\junk\foo C:\junk\foo>type runwhere.py import sys sys.path[0:0] = ['c:\\junk'] import where C:\junk\foo>runwhere.py imported module named where code loaded from file c:\junk\where.py sys.argv[0] is C:\junk\foo\runwhere.py cwd is C:\junk\foo C:\junk\foo>cd .. C:\junk>md bar C:\junk>cd bar C:\junk\bar>..\foo\runwhere.py imported module named where code loaded from file c:\junk\where.pyc sys.argv[0] is C:\junk\foo\runwhere.py cwd is C:\junk\bar HTH, John From paddy3118 at netscape.net Mon Dec 11 02:22:54 2006 From: paddy3118 at netscape.net (Paddy) Date: 10 Dec 2006 23:22:54 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165800527.225633.84180@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> Message-ID: <1165821773.670192.288860@79g2000cws.googlegroups.com> JShrager at gmail.com wrote: > > Python has to rely more on using the right algorithm... > > This sound familiar: "Macros are dangerous!" Yes. I changed my opinion on advocating Python having macros in one of our long threads on the subject. Maintainance counts. > "Compilers make you lazy." This is new to me. In fact, for the compiled languages available to me. Using them *first* would be the difficult choice. > "Worse is better!" Yep, I think I read that one. To (over), summarise what I read: the author states that waiting for perfect will often give the advantage to a competitor who ships with 'good enough'. The author gives examples. The skill to me resides in knowing what is good enough ;-) > (I have a Russian friend -- a mathematician -- who > jokes that the reason the Soviets were great mathematicians because > their computers sucked, so they had to use extensive formal > manipulation to get things to run fast enough to get anything done. He > was joking (I think); you don't appear to be.) I can't vouch for your Russian friend, but yes I do think that the gumph on exponential time algorithms versus linear time algorithms makes sense. I started using my first scripting language AWK whilst using C and went through only using it for small tasks to using it for more and more because it was fast enough. In my case I'd be finishing some task in a much shoter time giving my customers solutions that might take 10 minutes to run instead of ten seconds, but they were using it in a flow that took maybe overnight to run. Unlike Lisp, Python does not have a ubiquitous compiler. It is therefore made to interface nicely with compiled languages. Other compiled language users see the need for dynamic interpreted languages like Python and maintain links Python such as the Boost Python C++ wrapper. IronPython for .NET, Jython for Java. Lisp is its own interpreter and compiler, which should be a great advantage, but only if you don't make the mistake of ignoring the wealth of code out there that is written in other languages. > > > Talk to these guys: > > http://en.wikipedia.org/wiki/PyPy they have an interesting take on > > No, actually maybe you should talk to them since you seem to think that > making Python run fast is dangerous, or at least unnecessary. > > > Python has this unsung module called doctest that neatly shows some of > > the strengths of python: http://en.wikipedia.org/wiki/Doctest > > Now I'm *certain* that you're just pulling my leg: You guys document > all your random ten-line hacks in Wikipedia?!?! What a brilliant idea! Python is newbie-friendly. Part of that is being accessible. Doctest is about a novel way of using a feature shared by Lisp, that is docstrings. Testing is important, usually not done enough, and doctests are a way to get people to write more tests by making it easier. Does Lisp have similar? > Hey, you even have dead vaporware projects like uuu documented in > Wikipedia! Cool! (Actually, I don't know that doctest is ten lines in > Python, but it'd be about ten lines of Lisp, if that, so I'm just > guessing here.) Does Lisp have a doctest-like module as part of its standard distribution? Or are you saying that If you ever needed it, then it would be trivial to implement in Lisp, and you would 'roll your own'? There are advantages to doctest being one of Pythons standard modules. - Paddy. From michael.pearmain at tangozebra.com Tue Dec 5 05:57:08 2006 From: michael.pearmain at tangozebra.com (Mike P) Date: 5 Dec 2006 02:57:08 -0800 Subject: win32 com problem Message-ID: <1165316228.944095.116310@79g2000cws.googlegroups.com> I've got a slight problem when running an excel macro from python using the win32.com.client module, in that it says it can't load the DLL file (it doesn't say which one) and gives me the following error message Traceback (most recent call last): File "", line 93, in ? File ">", line 14, in Run File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line 258, in _ApplyTypes_ result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Office Excel', "The macro 'CTP.xla!sheet1.CTP' cannot be found.", 'C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None) Anybody have any ideas what this means? From olakh at walla.co.il Sun Dec 10 17:25:16 2006 From: olakh at walla.co.il (Ola K) Date: 10 Dec 2006 14:25:16 -0800 Subject: Search & Replace in MS Word Puzzle References: <1165702766.581612.45610@n67g2000cwd.googlegroups.com> <1165783011.964346.221100@80g2000cwy.googlegroups.com> Message-ID: <1165789516.055241.251560@n67g2000cwd.googlegroups.com> Waldemar Osuch wrote: > 1. doc.Styles is a container (a build in Word object) holding instances of > Styles (another build in Word object). One way to make the intended check > would be. > style_names = set(s.NameLocal for s in doc.Styles) > if "Italic" not in style_names: > # create style I changed the code to that and it works perfectly! How come this is better? I mean, I didn't find any logical or syntax problem with the way it was before. > 2. Read about Range object in Word VBA documentation. Range.Collapse may > explain what happens here. Well, so I did, and I can see now that the problem is probably that Word takes into consideration the previous characters as well, unless I collapse the range. However, I don't seem to find the way to properly do it, syntax-wise. I only managed to collapse the Selection, which didn't do the trick. >4. This is described in py2exe wiki. > http://www.py2exe.org/index.cgi/IncludingTypelibs Thanks. I am now implementing this. --Ola From bearophileHUGS at lycos.com Fri Dec 8 20:26:58 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 8 Dec 2006 17:26:58 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165623284.242403.295140@l12g2000cwl.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Message-ID: <1165625243.034854.181510@n67g2000cwd.googlegroups.com> JShrager at gmail.com: > Sorry, I missed something here. Why do you need a release to have these > sorts of things? Can't you just expand the language via macros to > create whatever facility of this sort you need... Oh, sorry. You CAN'T > expand the language.... Too bad. I guess waiting for Guido to figure > out what Fits Your Mind is part of The Python Way. There are few programmers that are very intelligent and know how very well how to design languages, so they can invent such things. They are able to manage and appreciate the more freedom Lisp gives them. But *most* other programmers aren't intelligent enough for that, or they don't know enough language design to produce something working or something nice. So maybe Lisp is for the more intelligent people, or for really difficult programs (or for dynamic and flexible programs that have to run quite faster than Python+Psyco code), where having a bit simpler language isn't an advantage. All the other people use Python that contains things already well designed for them, such language constructs are the same for everybody, they are standards of the language, like generators, so reading each other code is simpler and faster too. Bye, bearophile From gagsl-py at yahoo.com.ar Wed Dec 6 21:12:44 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 06 Dec 2006 23:12:44 -0300 Subject: Am I stupid or is 'assert' broken in Python 2.5?? In-Reply-To: <1165416379.784513.51620@16g2000cwy.googlegroups.com> References: <1165415689.347819.129680@73g2000cwn.googlegroups.com> <1165416379.784513.51620@16g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061206230859.01dee838@yahoo.com.ar> At Wednesday 6/12/2006 11:46, antred wrote: >Yeah, it hit me seconds after I had posted my message. =0 Why didn't I >think of it during the 30 minutes I spent banging my head against the >keyboard going nuts over this 'bug' ... The same reason you can sometimes find what's wrong just by explaining the symptoms to another guy... Having to put things sorted and simple to understand by another, just makes you think clearly on the problem... -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From pmartin at snakecard.com Sat Dec 2 11:00:03 2006 From: pmartin at snakecard.com (Philippe Martin) Date: Sat, 02 Dec 2006 10:00:03 -0600 Subject: python vs java & eclipse References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> Message-ID: Amir Michail wrote: > Hi, > > It seems to me that measuring productivity in a programming language > must take into account available tools and libraries. > > Eclipse for example provides such an amazing IDE for java that it is no > longer obvious to me that one would be much more productive in python > for medium sized projects. > > Sure, all that Java static typing can be painful, but Eclipse takes > some of that pain away. Moreover, static typing can result in better > on-the-fly error detection and refactoring support. > > Any thoughts on this? > > Amir FYI: http://showmedo.com/videos/series?name=PyDevEclipseList hg From stavenko at gmail.com Thu Dec 14 20:26:34 2006 From: stavenko at gmail.com (stavenko at gmail.com) Date: 14 Dec 2006 17:26:34 -0800 Subject: active directory Message-ID: <1166145994.007273.284200@j72g2000cwa.googlegroups.com> Hello all. I'm trying ot get users from Active directory. using python-ldap. We have a windows network domain. So I tried this code: import ldap l = ldap.initialize("ldap://ldap.server") l.protocol_version = ldap.VERSION3 l.simple_bind_s('','') for i in l.search_ext_s("CN=Users,dc=ldap,dc=server", ldap.SCOPE_SUBTREE, "objectclass=*"): print i Code prints me nothing... Then i tried to change auth string to this: l.simple_bind_s(r'CN=myname,CN=Users,DC=ldap,DC=server','') Code prints me this: ('CN=Users,DC=ces,DC=kamchatka,DC=su', {}) Then i tried next string : l.simple_bind_s(r'CN=myname,CN=Users,DC=ldap,DC=server','mypassword') Program raises exception in this case. ldap.INVALID_CREDENTIALS: {'info': '80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 525, v893', 'desc': 'Invalid credentials'} But everything is allright. Credentials and passwords correct, server gives me a lot of dnsNodes, dnsZones when i try to search under dc=ldap,dc=server. And in the same time i can easily connect to AD and get users using win32com... Help me please to authorise to AD... From mystilleef at gmail.com Sat Dec 9 13:39:05 2006 From: mystilleef at gmail.com (mystilleef) Date: 9 Dec 2006 10:39:05 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165689545.676886.289150@j44g2000cwa.googlegroups.com> Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. > > Mark Advantages of Python: 1). More and better mature standard libraries (Languages don't matter, libraries do). 2). Multiple programming paradigms (including functional style programming see itertools, functools, operator modules (lambda, map, filter, reduce, sum etc builtins), higher order functions, list comprehension, blah, blah) 3). Better OO implementation. (I used to hate OO until I started using Python) 4). Ultimate glue language (Plays well with C, C++, Java, .NET. nuff said. Bindings for almost any lib worth using, at least on *nix) 5). Clearer syntax. 6). Better namespace management. (nobody ever talks about this, but Python seems to be one of the few languages that gets symbol management right from a users perspective) 7). Easier packaging and distribution system. 8). Ubiquity! Python is everywhere. Lisp, bleh. 9). Relatively good docs (PHP has better). 10). Fewer perceived community assholes. Large community. 11). Less fragmentation. Advantages of Lisp: Learning a functional language can improve your programming range and depth. And today, I wouldn't even recommend Lisp (it's rather archaic), when there's mind bending Haskell. I'd go as far as saying I believe Haskell has a better fate than Lisp. On Lisp Macros: I think they are overrated, and in general cause more harm than good. It's the reason I find Lisp-like programs difficult to grok, maintain and extend. Cos every smart ass wants to needlessly write his own mini language to the point of absolute obfuscation. Naturally, I'm supposed to be awed by his mischievous cleverness. Conclusion: The semantics or features of a language is almost irrelevant today. Developers want to put the lego pieces together, they don't want to make lego. Rewriting the sun and moon, or needlessly reinvent the wheel was popular in the 70s, but it's boring and expensive today. Today, when a developer needs to solve a problem, the question they ask is, "Is there a library for that?". If the answer is no, they a more likely to switch to a language that provides a library that solves their problem. The challenge for developers today is software architecture, robustness and scalability, not language purity or semantics. The Lisp, and to an extent Haskell, community will never ever ever grok this. They'll continue to wonder why an "inferior" language like Python keeps getting popular. It will always escape them that it might be because Python is actually easier to use for most people to write "real world" applications. It has good usability. From duncan.booth at invalid.invalid Fri Dec 22 08:39:56 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Dec 2006 13:39:56 GMT Subject: Confusion over calling a nested function inside a parent function References: <877iwkdpsb.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > [code] > class WORK: > def getwork(self): > def choosetable(self):pass > choosetable() #TypeError: choosetable() takes exactly 1 > #argument (0 given) > [/code] > > Calling choosetable() at the above location gives me the error > described above. > > A function defined inside a method is just a function, it's only when a function is retrieved from the class dictionary (whether it was defined there or assigned to the class later) that it becomes a method. Just leave the self parameter off the choosetable function: you can still access self from the outer scope of getwork. From vasudevram at gmail.com Sun Dec 24 10:37:04 2006 From: vasudevram at gmail.com (vasudevram) Date: 24 Dec 2006 07:37:04 -0800 Subject: Saw a possibly interesting Python PDF library - pyPDF Message-ID: <1166974624.059415.110180@42g2000cwt.googlegroups.com> Saw a possibly interesting Python PDF library - pyPDF. For merging/splitting PDFs and related operations. It's at http://pybrary.net/pyPdf/ HTH Vasudev ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com Check out the cool Snap.com link preview feature on my site. Free sign-up at www.snap.com I'm not affiliated with Snap.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From duncan.booth at invalid.invalid Fri Dec 22 05:51:55 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Dec 2006 10:51:55 GMT Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166741966.242087.192390@n67g2000cwd.googlegroups.com> <1166767205.559937.185260@f1g2000cwa.googlegroups.com> <1166773847.368709.299960@48g2000cwx.googlegroups.com> <1166780607.921591.248000@f1g2000cwa.googlegroups.com> Message-ID: "John Machin" wrote: > You are saying that you think that George thinks that they are > teaching efficient coding methods in OO classes?? > No, but I hope they teach how to recognise patterns, and I imagine they also teach something about refactoring to remove switches or long if/elif chains. (My imagination may not, of course, bear any resemblance to real life.) From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Fri Dec 1 15:26:35 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Fri, 01 Dec 2006 21:26:35 +0100 Subject: Thread help References: <1164999221.679348.221000@16g2000cwy.googlegroups.com> <12n0v9l4ssfd7fc@corp.supernews.com> Message-ID: <4tbhffF13bmgrU1@mid.individual.net> Grant Edwards wrote: > On 2006-12-01, Salvatore Di Fazio >> I would make 3 threads for a client application. > You should use 4. I vote for just 1. Regards, Bj?rn -- BOFH excuse #236: Fanout dropping voltage too much, try cutting some of those little traces From fredrik at pythonware.com Thu Dec 14 12:48:50 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 18:48:50 +0100 Subject: WHAT is [0] in subprocess.Popen(blah).communicate()[0] In-Reply-To: <1166118046.514892.85360@16g2000cwy.googlegroups.com> References: <1166118046.514892.85360@16g2000cwy.googlegroups.com> Message-ID: johnny wrote: > Can someone tell me what is the reason "[0]" appears after > ".communicate()" > > For example: > last_line=subprocess.Popen([r"tail","-n 1", "x.txt"], > stdout=subprocess.PIPE).communicate()[0] as explained in the documentation, communication() returns two values, as a tuple. [0] is used to pick only the first one. see the Python tutorial for more on indexing and slicing. From vivainio at gmail.com Wed Dec 20 05:18:46 2006 From: vivainio at gmail.com (Ville Vainio) Date: 20 Dec 2006 02:18:46 -0800 Subject: IPython 0.7.3 upgrade notes Message-ID: Something I forgot to emphasize in the announcement, knowing that not everyone reads the release notes - if you are upgrading from a previous version of IPython, you must either: - Delete your ~/ipython (or ~/_ipython) directory OR - Run %upgrade once IPython starts. From david at cypherspace.info Thu Dec 28 11:57:32 2006 From: david at cypherspace.info (cypher543) Date: 28 Dec 2006 08:57:32 -0800 Subject: (PyGTK) Disabling ToolButton when no TreeView item is selected? Message-ID: <1167325052.790540.121810@42g2000cwt.googlegroups.com> I have a TreeView and a ToolButton. The ToolButton should only be active if the user has selected an item in the TreeView. What signal should I use to achieve this? Thanks, David From udodenko at users.sourceforge.net Sat Dec 9 05:06:38 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sat, 9 Dec 2006 12:06:38 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Message-ID: <457a916e$0$49198$14726298@news.sunsite.dk> (message (Hello 'Steven) (you :wrote :on '(Sat, 09 Dec 2006 20:02:06 +1100)) ( SD> It is a good thing that when Fred decides to stop contributing to an SD> open source project (or leave the company), other people can read his SD> code without having to learn his Uber-Special Custom Macro Extended SD> Language. Even if Fred's USCMEL ran 35% faster (and thus saved an SD> entire four seconds on an average run with typical data!) the five or SD> six weeks of reduced programmer productivity when somebody else has to SD> maintain his code outweighs that. have you ever faced this problem? it's not a problem at all. and it's possible to write unmaintanable code in any langauge. for example, Bram Cohen's BitTorrent (written in Python) has a constructors with 21 positional parameters class Rerequester: def __init__(self, url, interval, sched, howmany, minpeers, connect, externalsched, amount_left, up, down, port, ip, myid, infohash, timeout, errorfunc, maxpeers, doneflag, upratefunc, downratefunc, ever_got_incoming): and here's how it called: rerequest = Rerequester(response['announce'], config['rerequest_interval'], rawserver.add_task, connecter.how_many_connections, config['min_peers'], encoder.start_connection, rawserver.add_task, storagewrapper.get_amount_left, upmeasure.get_total, downmeasure.get_total, listen_port, config['ip'], myid, infohash, config['http_timeout'], errorfunc, config['max_initiate'], doneflag, upmeasure.get_rate, downmeasure.get_rate, encoder.ever_got_incoming) i think it might be a bit hard to non-autist to remember order of parameters in such constructor. (and it's not the only one such place in BitTorrent) and that guy teaches us how to write maintanable code! http://advogato.org/article/258.html thus, you don't need macros to write unmaintanable code -- functions are enough for this. and with macros you can make it more maintanable, actually ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From bill_maxwell_notMyRealAddress at notreal.net Mon Dec 4 01:37:03 2006 From: bill_maxwell_notMyRealAddress at notreal.net (Bill Maxwell) Date: Mon, 04 Dec 2006 01:37:03 -0500 Subject: Why not just show the out-of-range index? References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> Message-ID: <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> On Sun, 3 Dec 2006 23:31:56 -0500, Jean-Paul Calderone wrote: >On 3 Dec 2006 17:23:49 -0800, Russ wrote: >> >>> Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. >> >>Now, that would be rather silly. I would have to familiarize myself >>with the code for the Python interpreter, then send a patch to the >>maintainers (and hope they notice it in their inboxes), while the >>maintainers themselves could probably "fix" the problem in two minutes >>flat. No thanks! > >And I have some laundry that I would like you to do for me. Let me know >when a convenient time for you to pick it up would be. > >Jean-Paul Are you saying that you place such low value on feedback from Python users that you don't even want them to try and ask questions that might help to improve the language? In other words, if I'm not skilled or knowledgeable enough to improve something myself, I shouldn't even mention it? Bill From Tim.Golden at viacom-outdoor.co.uk Fri Dec 1 03:55:39 2006 From: Tim.Golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri, 1 Dec 2006 08:55:39 -0000 Subject: detecting that a SQL db is running In-Reply-To: <1164924313.495569.311330@80g2000cwy.googlegroups.com> Message-ID: [triode at xnet.co.nz] | Sorry if i did not make myself clear. let me try again. | | I can detect when the db is up and not responding, however, | if the DB does not start at all, my local application hangs. I need to find a | way to determine if the DB has started, that's all. Maybe (and only maybe) some code which will determine when the corresponding Service has started would suffice. There's probably a few ways to do that. Just as a starter, try using WMI: http://timgolden.me.uk/python/wmi.html import wmi c = wmi.WMI () for msde_service in c.Win32_Service (Name="Name-of-msde-service"): if msde_service.State == "Stopped": print "Not up yet" If this worked, you could use WMI events, but be warned, the most recent version of the WMI module has a bug in the event class which someone's pointed out and patched but which I haven't fixed yet. If you want to try WMI (and to use that module) then download the previous version; it'll work perfectly well for the purpose. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From cfbolz at gmx.de Tue Dec 5 12:04:43 2006 From: cfbolz at gmx.de (Carl Friedrich Bolz) Date: Tue, 05 Dec 2006 18:04:43 +0100 Subject: PyPy Leysin Winter Sports Sprint (8-14th January 2007) Message-ID: ===================================================================== PyPy Leysin Winter Sports Sprint (8-14th January 2007) ===================================================================== .. image:: http://www.ermina.ch/002.JPG The next PyPy sprint will be in Leysin, Switzerland, for the fourth time. This sprint will be the final public sprint of our EU-funded period, and a kick-off for the final work on the upcoming PyPy 1.0 release (scheduled for mid-February). The sprint is the last chance for students looking for a "summer" job with PyPy this winter! If you have a proposal and would like to work with us in the mountains please send it in before 15th December to "pypy-tb at codespeak.net" and cross-read this page: http://codespeak.net/pypy/dist/pypy/doc/summer-of-pypy.html ------------------------------ Goals and topics of the sprint ------------------------------ * Like previous winter, the main side goal is to have fun in winter sports :-) We can take a couple of days off for ski; at this time of year, ski days end before 4pm, which still leaves plenty of time to recover (er, I mean hack). * Progress on the JIT compiler, which we are just starting to scale to the whole of PyPy. `[1]`_ * Polish the code and documentation of the py lib, and eventually release it. * Work on prototypes that use the new features that PyPy enables: distribution `[2]`_ (based on transparent proxying `[3]`_), security `[4]`_, persistence `[5]`_, etc. `[6]`_. .. _[1]: http://codespeak.net/pypy/dist/pypy/doc/jit.html .. _[2]: http://codespeak.net/svn/pypy/dist/pypy/lib/distributed/ .. _[3]: http://codespeak.net/pypy/dist/pypy/doc/proxy.html .. _[4]: http://codespeak.net/pypy/dist/pypy/doc/project-ideas.html#security .. _[5]: http://codespeak.net/pypy/dist/pypy/doc/project-ideas.html#persistence .. _[6]: http://codespeak.net/pypy/dist/pypy/doc/project-ideas.html ----------------------- Location & Accomodation ----------------------- Leysin, Switzerland, "same place as before". Let me refresh your memory: both the sprint venue and the lodging will be in a very spacious pair of chalets built specifically for bed & breakfast: http://www.ermina.ch/. The place has a baseline ADSL Internet connexion (600Kb) with wireless installed. You can of course arrange your own lodging anywhere (so long as you are in Leysin, you cannot be more than a 15 minute walk away from the sprint venue), but I definitely recommend lodging there too -- you won't find a better view anywhere else (though you probably won't get much worse ones easily, either :-) I made pre-reservations in the Chalet, so please *confirm* quickly that you are coming so that we can adjust the reservations as appropriate. The rate so far has been 60 CHF a night all included in 2-person rooms, with breakfast. There are larger rooms too (less expensive, possibly more available too) and the possibility to get a single room if you really want to. Please register by svn: http://codespeak.net/svn/pypy/extradoc/sprintinfo/leysin-winter-2007/people.txt or on the pypy-sprint mailing list if you do not yet have check-in rights: http://codespeak.net/mailman/listinfo/pypy-sprint You need a Swiss-to-(insert country here) power adapter. There will be some Swiss-to-EU adapters around - bring a EU-format power strip if you have one. ----------- Exact times ----------- Officially, 8th-14th January 2007. Both dates are flexible, you can arrive or leave earlier or later, though it is recommended to arrive on the 7th (if many people arrive on the 6th we need to check for accomodation availability first). We will give introductions and tutorials on the 8th, in the morning if everybody is there, or in the afternoon otherwise. From aaronwmail-usenet at yahoo.com Mon Dec 18 17:40:14 2006 From: aaronwmail-usenet at yahoo.com (aaronwmail-usenet at yahoo.com) Date: 18 Dec 2006 14:40:14 -0800 Subject: ANN: Skimpy Gimpy ASCII Web Challenge CAPTCHA Message-ID: <1166481614.468018.250370@80g2000cwy.googlegroups.com> Please check it out and try it: http://skimpygimpy.sourceforge.net/ Find examples, documentation, links to demos and download links there. Skimpy Gimpy is a tool for generating HTML representations for strings which people can read but which web robots and other computer programs will have difficulty understanding. Skimpy is an example of a Captcha: an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart". The Skimpy program and API (applications programmer interface) is implemented in a single self contained Python script (module). The input for Skimpy are words or phrases. The output of the program and API are strings containing HTML preformatted text. The preformatted text contains "ASCII art" representing the input phrase, which looks like somewhat sloppy handwriting on a speckled page, when viewed in an HTML browser. It is intended that it is easy for a human to read the word or phrase when rendered as HTML, but it is difficult for a program to extract the word or phrase automatically. The program uses a number of techniques to make the output difficult for a computer to interpret: curve interpolation, random rotation, random skew, random scale adjustment, "smearing", and addition of noise. The Skimpy tool is far easier to install, use, and embed than other similar technologies. All you need is python installed and the skimpyGimpy.py source file. Enjoy and happy holidays! -- Aaron Watters === there ain't no sanity clause! From geskerrett at hotmail.com Tue Dec 5 08:02:06 2006 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 5 Dec 2006 05:02:06 -0800 Subject: Ensure a variable is divisible by 4 In-Reply-To: References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: <1165323726.255327.11530@j72g2000cwa.googlegroups.com> Nick Craig-Wood wrote: > geskerrett at hotmail.com wrote: > > I am sure this is a basic math issue, but is there a better way to > > ensure an int variable is divisible by 4 than by doing the following; > > > > x = 111 > > x = (x /4) * 4 > > You should use // for future compatibility which is guaranteed to be > an integer division whereas / isn't (see "from __future__ import > division") > > Eg > > (x // 4) * 4 > > For the particular case of 4 being 2**2, you might consider > > x & ~0x3 > > which is a common idiom. > Thanks for the tip about integer division and I will experiment with your other suggestion. From birdfamily at gmail.com Sun Dec 24 06:30:21 2006 From: birdfamily at gmail.com (Birdman) Date: 24 Dec 2006 03:30:21 -0800 Subject: Help please using telnetlib module In-Reply-To: <1166925091.055161.8090@f1g2000cwa.googlegroups.com> References: <1166925091.055161.8090@f1g2000cwa.googlegroups.com> Message-ID: <1166959821.755422.124330@h40g2000cwb.googlegroups.com> Simplest explanation is that you can't do a 'show run' from global configuration mode.... try something like #exit global configuration mode tn.write('end\n') print tn.read_until('#') #disable pause after 24 lines tn.write('term len 0\n') tn.read_until('#') #now show the entire running-config tn.write('show run\n') print tn.read_until('#') From fredrik at pythonware.com Wed Dec 20 14:22:21 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 20:22:21 +0100 Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects In-Reply-To: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> Message-ID: thompson.marisa at gmail.com wrote: > I'm extremely new to Python and programming as a whole. I have written > a python script with the assistance of ESRI ArcGIS 9.2, which uses > Python 2.4.1, however, it gives me this error when I try to run it. > I've already posted at ESRI support, and I was hoping that Python > people could help me more. > > I hope there is something simple I could do to be able to define the > object that it thinks is NoneType. that would be the None object. http://effbot.org/pyref/None which is often used as a placeholder in Python. my guess is that it's the next() call that returns None when you've reached the end of the shapefile list; try changing while Townshps !="": to while Townshps is not None: and see if the problem goes away. if you still get an exception, please post the full traceback; see http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do for details. From banaouas.medialog at wanadoo.fr Tue Dec 19 04:10:55 2006 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Tue, 19 Dec 2006 10:10:55 +0100 Subject: Apache 2.2.3 and mod_python 3.2.10 Message-ID: <4587ab8e$0$5114$ba4acef3@news.orange.fr> I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform I configured mod_python via httpd.conf: LoadModule python_module modules/mod_python.so but my script folder configuration doesn't work correctely: Alias /myfolder D:/myfolder Order allow,deny Allow from all AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On for test, this is a sample script d:\myfolder\test.py # test.py # from mod_python import apache # def hello(name=None): if name: return 'Hello, %s!' % name.capitalize() else: return 'Hello there!' # def handler(req): req.content_type = 'text/plain' req.write("from handler test, Hello World!") return apache.OK when I access to the url http://localhost/monrep/test.py, I obtain source test.py listing but not the rendering of handler or hello method. with url http://localhost/theriaque/test.py/hello, I obtain : =>The requested URL /theriaque/test.py/hello was not found on this server. It seems like something is missing ... but what ? thanks for any help From konrad.hinsen at laposte.net Thu Dec 7 03:14:58 2006 From: konrad.hinsen at laposte.net (konrad.hinsen at laposte.net) Date: Thu, 7 Dec 2006 09:14:58 +0100 Subject: Windows installer for Scientific Python for Python 2.4? In-Reply-To: <12nehgaak7mte4@corp.supernews.com> References: <12nehgaak7mte4@corp.supernews.com> Message-ID: <3EDBAF61-F1DA-44ED-AFC4-2F21A9EECDE1@laposte.net> On 06.12.2006, at 23:36, Grant Edwards wrote: > Can anybody point me to a windows installer for scientific > python that will work with Python 2.4? The Scientific python > download page only has an installer for Python 2.3. If you find one, please send me a copy so that I can put it on the download page! Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Centre de Biophysique Mol?culaire, CNRS Orl?ans Synchrotron Soleil - Division Exp?riences Saint Aubin - BP 48 91192 Gif sur Yvette Cedex, France Tel. +33-1 69 35 97 15 E-Mail: hinsen at cnrs-orleans.fr --------------------------------------------------------------------- From john106henry at hotmail.com Fri Dec 1 13:37:39 2006 From: john106henry at hotmail.com (John Henry) Date: 1 Dec 2006 10:37:39 -0800 Subject: client/server design and advice References: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> <4tauodF120o5fU1@mid.uni-berlin.de> <1164994789.168555.302490@f1g2000cwa.googlegroups.com> Message-ID: <1164998259.046246.323140@l12g2000cwl.googlegroups.com> TonyM wrote: > > Pyro rocks for that. > > Awesome, ill look into it in greater detail and will most likely use > it. Given what ive seen so far it looks like it will make the > client/server interface fairly easy to write. > Correction: not "fairly easy" - make that "incredibly easy". Even Micky likes it. :=) > Now...if only i could master python gui programming and development ;) > I'm not entirely sure which gui lib im going to end up using, but as of > now im leaning more towards tkinter as i know it will work where i need > and it seems to be one of the more documented. Ive looked at used > wxpython a little but had trouble figure out a few minor things while > playing around with it initially. I've also thought about pygtk > although I haven't taken the time to play with it quite yet as i > assumed it was primarily for linux (id be running the majority of these > on windows pcs). > You would short change yourself if you don't check out the other packages such as Pythoncard, and Dabo. The other thing I recommend for large scale applications: http://www-128.ibm.com/developerworks/library/l-pythrd.html > Thanks for the suggestions :) > Tony From Ingo.Wolf at gmx.de Wed Dec 6 10:23:50 2006 From: Ingo.Wolf at gmx.de (iwl) Date: 6 Dec 2006 07:23:50 -0800 Subject: PyRun_SimpleString no sys.argv[0] Message-ID: <1165418630.840841.136290@n67g2000cwd.googlegroups.com> Hello, I'm just starting with Python - would like to embed it in my windows-programm as an script-processor. For tests I use easygui some easy-wrapper for the py-tck-stuff. PyRun_SimpleString("from easygui import *\n"); PyRun_SimpleString("import sys\n"); PyRun_SimpleString("msgbox()\n"); Traceback (most recent call last): File "", line 1, in File "easygui.py", line 148, in msgbox reply = buttonbox(message, title, choices) File "easygui.py", line 170, in buttonbox root = Tk() File "C:\Python\Python25\Lib\lib-tk\Tkinter.py", line 1631, in __init__ baseName = os.path.basename(sys.argv[0]) AttributeError: 'module' object has no attribute 'argv' May bee makes some sence that the embedded Interpreter has no argv[0], however tk seems not to bee ready for that. I try to define some sys.argv[0] myself after I get out how to do that, maybee someone other has an better idea until than. From fredrik at pythonware.com Fri Dec 8 11:26:55 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 08 Dec 2006 17:26:55 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1165594593.077086.197050@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165594593.077086.197050@80g2000cwy.googlegroups.com> Message-ID: Carl Banks wrote: > Consumer choice can never be boiled down to one thing; there are so > many factors. No one knows the whole answer. I certainly don't. it's all due to Python's humongous marketing budget, of course. just imagine what would have happened if someone had spent that much VC money on Lisp. From python at hope.cz Tue Dec 26 14:28:09 2006 From: python at hope.cz (Lad) Date: 26 Dec 2006 11:28:09 -0800 Subject: Mod_python Message-ID: <1167161288.802707.64220@h40g2000cwb.googlegroups.com> In my web application I use Apache and mod_python. I allow users to upload huge files( via HTTP FORM , using POST method) I would like to store the file directly on a hard disk and not to upload the WHOLE huge file into server's memory first. Can anyone suggest a solution? Thank you LB From fredrik at pythonware.com Thu Dec 14 09:06:55 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 15:06:55 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com><7xejrah9on.fsf@ruckus.brouhaha.com><1165582654.974945.173700@79g2000cws.googlegroups.com><1165587080.038533.47910@80g2000cwy.googlegroups.com><45797b9b$0$49206$14726298@news.sunsite.dk><4ttiadF15dam8U1@mid.individual.net><45799bf6$0$49202$14726298@news.sunsite.dk><4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net><4u8hu5F177u11U1@mid.individual.net><1165984694.264366.261250@80g2000cwy.googlegroups.com><1166090708.361757.197170@l12g2000cwl.googlegroups.com><1166102108.129051.166580@73g2000cwn.googlegroups.com> Message-ID: Neil Cerutti wrote: > Please don't assume I speak for all Python programmers. They > might be rolling there eyes at me just as much as you are. ;-) we do, but that's only because you keep on arguing with cross-posting Lisp programmers. From fb at frank-buss.de Sun Dec 10 09:46:39 2006 From: fb at frank-buss.de (Frank Buss) Date: Sun, 10 Dec 2006 15:46:39 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano wrote: > Yes. But you can't redefine 1+2 in Python, at least not without hacking > the interpreter. Can you redefine (+ 1 2) in Lisp? Yes, that's no problem and works without warnings and in every Common Lisp implementation: CL-USER > (shadow '+) T CL-USER > (defun + (&rest rest) (apply #'- rest)) + CL-USER > (+ 3 1) 2 -- Frank Buss, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From gandalf at designaproduct.biz Tue Dec 12 07:38:18 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Tue, 12 Dec 2006 13:38:18 +0100 Subject: py-ldap question Message-ID: <457EA2BA.6000401@designaproduct.biz> Hello, I'm using the ldap module under Windows. This is the error that I get: import ldap l = ldap.initialize("ldaps://neptunus.msnet:636") l.simple_bind_s("cn=gandalf,ou=Users,dc=neptunus,dc=msnet","gandalf") l.search_s("ou=AddressBooks,dc=neptunus,dc=msnet", ldap.SCOPE_SUBTREE, "objectclass=inetOrgPerson") Traceback (most recent call last): File "T:\developer20\knowledgebase\FreeBSD\Thunderbird_OpenLDAP_AddressBook\working\05\example.py", line 3, in ? l.simple_bind_s("cn=gandalf,ou=Users,dc=neptunus,dc=msnet","gandalf") File "C:\Python24\Lib\site-packages\ldap\ldapobject.py", line 175, in simple_bind_s msgid = self.simple_bind(who,cred,serverctrls,clientctrls) File "C:\Python24\Lib\site-packages\ldap\ldapobject.py", line 169, in simple_bind return self._ldap_call(self._l.simple_bind,who,cred,serverctrls,clientctrls) File "C:\Python24\Lib\site-packages\ldap\ldapobject.py", line 94, in _ldap_call result = func(*args,**kwargs) ldap.SERVER_DOWN: {'info': 'error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed', 'desc': "Can't contact LDAP server"} I think that I need to specify to the openldap client to trust the server's certificate. The problem is that the ldap module bundles the openldap-client implementation, and there is no ldap.conf file (or at least I cannot find it). So how can I configure it to trust my server's certificate? Thanks, Laszlo From horpner at yahoo.com Sat Dec 2 21:30:48 2006 From: horpner at yahoo.com (Neil Cerutti) Date: Sun, 03 Dec 2006 02:30:48 GMT Subject: text adventure question References: Message-ID: On 2006-12-02, Ara Kooser wrote: > I am working on a text adventure game for python to get back > into python programming. My version 0.1 used only functions so > I could get familiar with how those work. I want to move beyond > that. I am not sure what would be a good Python way of handling > this. I was wondering if classes would help? What things > should be included in the main program? The language used by the Infocom implementors was called ZIL, and it so happens that the ZIL manual is available for download. It was sort of a wimpy version of Lisp. http://www.mv.com/ipusers/xlisper/zil.pdf Anyway, the ZIL manual explains how Infocom's "library" for text adventures worked. That should be inspirational for your design. It's also an entertaining historical artifact, if the history of computer games is your thing. Here's an amusing sampling: EXERCISE THREE Design and implement a full-size game. Submit it to testing, fix all resulting bugs, help marketing design a package, ship the game, and sell at lest 250,000 units. -- Neil Cerutti From surekap at gmail.com Thu Dec 14 02:58:32 2006 From: surekap at gmail.com (Prateek) Date: 13 Dec 2006 23:58:32 -0800 Subject: how to determine Operating System in Use? In-Reply-To: <2006121323105016807-jameshcunningham@gmailcom> References: <1166056094.751283.122760@79g2000cws.googlegroups.com> <2006121323105016807-jameshcunningham@gmailcom> Message-ID: <1166083112.525809.138860@79g2000cws.googlegroups.com> also try: sys.platform if sys.platform == "darwin": macStuff() elif sys.platform == "win32": linuxStuff() James Cunningham wrote: > On 2006-12-13 19:28:14 -0500, nanjundi at gmail.com said: > > > > > > > On Dec 13, 6:32 pm, "Ian F. Hood" wrote: > >> Hi > >> In typically windows environments I have used: > >> if 'Windows' in os.environ['OS']... > >> to prove it, but now I need to properly support different environments. > >> To do so I must accurately determine what system the python instance is > >> running on (linux, win, mac, etc). > >> Is there a best practises way to do this? > >> TIA > >> Ian > > > > I would do this: > > -------------------- > > if os.name == ''posix': > > linuxStuff() > > elif os.name == 'nt': > > windowsStuff() > > elif os.name == 'os2': ... > > ------------------- > > os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' > > > > -N > > Bearing in mind, of course, that Mac will return "posix", too. And > Cygwin might. Erg. > > Best, > James From tjreedy at udel.edu Wed Dec 6 15:39:08 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Dec 2006 15:39:08 -0500 Subject: Am I stupid or is 'assert' broken in Python 2.5?? References: <1165415689.347819.129680@73g2000cwn.googlegroups.com> <1165416379.784513.51620@16g2000cwy.googlegroups.com> Message-ID: "antred" wrote in message news:1165416379.784513.51620 at 16g2000cwy.googlegroups.com... > Yeah, it hit me seconds after I had posted my message. =0 Why didn't I > think of it during the 30 minutes I spent banging my head against the > keyboard going nuts over this 'bug' ... Because communication brings consciousness ;-) From sonibergraj at youjoy.org Wed Dec 6 22:12:43 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Thu, 07 Dec 2006 04:12:43 +0100 Subject: newb: What is the purpose of if __name__ == "__main__": In-Reply-To: <1165460385.607830.277220@n67g2000cwd.googlegroups.com> References: <1165460385.607830.277220@n67g2000cwd.googlegroups.com> Message-ID: <457786AB.1020703@youjoy.org> johnny wrote: > What is the purpose of > if __name__ == "__main__": > > If you have a module, does it get called automatically? > It is a common pattern to make one and the same source file usable as a program and as a module. When you import some python module its __name__ is never "__main__". When you run a python script __name__ is always "__main__". This way you can control what shall happen when you run the source file as a standalone program. To put it simple: Everything in the `if __name__ == "__main__":` block is only executed when you run the source file as a program. Hope that helps, -- Soni Bergraj http://www.YouJoy.org/ From gandalf at designaproduct.biz Thu Dec 28 11:27:43 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Thu, 28 Dec 2006 17:27:43 +0100 Subject: How to return a simple variable from a function (still newbie) ? In-Reply-To: <1167320150.3394.17.camel@dot.uniqsys.com> References: <1167320150.3394.17.camel@dot.uniqsys.com> Message-ID: <4593F07F.2050406@designaproduct.biz> > You should also think long and hard about *why* you want to return a > value from a function by modifying an input parameter instead of just > using the return statement. The "return by modifying an input parameter" > approach comes from C where that's the only way to return more than one > value from a function. In Python, no such crutch is necessary or > desirable. > Nobody mentioned the term for this. When a function changes its parameters or its environment, then it is called a "side effect" and generally it is considered harmful in all modern languages. ("Function" here refers to a piece of code that is used to calculate one or more values and provide these values to the caller.) So you are trying to create a function that has a side effect. You should not do this, unless you have a really good reason. Regards, Laszlo From dr.mtarver at ukonline.co.uk Fri Dec 8 13:45:42 2006 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: 8 Dec 2006 10:45:42 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <1165601839.678815.191410@79g2000cws.googlegroups.com> Message-ID: <1165603542.869042.263020@f1g2000cwa.googlegroups.com> Kaz Kylheku wrote: > Mark Tarver wrote: > > I don't mind controversy - as long as there is intelligent argument. > > And since it involves Python and Lisp, well it should be posted to both > > groups. The Lispers will tend to say that Lisp is better for sure - > > so it gives the Python people a chance to defend this creation. > > And that would be our confirmation that this is another trolling > asshole. This would be a confirmation that you are ignorant in your manners and don't know how to address a straight question. Mark From george.sakkis at gmail.com Mon Dec 4 12:17:33 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 4 Dec 2006 09:17:33 -0800 Subject: Ensure a variable is divisible by 4 References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: <1165252653.305416.253400@16g2000cwy.googlegroups.com> geskerrett at hotmail.com wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. if x % 4 == 0: # x is divisible by 4 George From caleb.hattingh at gmail.com Thu Dec 21 11:55:49 2006 From: caleb.hattingh at gmail.com (Caleb Hattingh) Date: 21 Dec 2006 08:55:49 -0800 Subject: Is there a way to push data into Microsoft Excel & Word from Python ? In-Reply-To: <1166313781.213299.100610@16g2000cwy.googlegroups.com> References: <458455f2$0$8219$426a74cc@news.free.fr> <1166303981.857285.156670@n67g2000cwd.googlegroups.com> <1166313781.213299.100610@16g2000cwy.googlegroups.com> Message-ID: <1166720149.524807.185080@a3g2000cwd.googlegroups.com> Hi Paul > Thanks for the kind words! No, thank _you_ for taking the time to write such a useful document. regards Caleb From atkinw at rpi.edu Mon Dec 11 09:31:39 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Mon, 11 Dec 2006 09:31:39 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> Message-ID: greg writes: > When moving a set of statements in Python, you > are usually selecting a set of complete lines, > cutting them out and then pasting them in > between two other lines somewhere else. You're missing Ken's point, which is that in Lisp an s-expression represents a single concept - I can cut out the second form of an IF and know that I'm cutting the entire test-form. I don't have to choose the correct "set of complete lines" to correctly move code around. > Having edited both Lisp and Python code fairly > extensively, I can't say that I find editing > Python code to be any more difficult or error > prone. How extensively? > On the plus side, Python makes less demands on the > capabilities of the editor. All you really need > is block-shifting commands. Bracket matching is > handy for expressions but not vital, and you > certainly don't need bracket-based auto-indenting. Oh, please. So we should restrict the power of the languages we choose just to make sure that our code can be edited in Notepad? From kirk at nospam.jobsluder.net Sun Dec 10 01:52:38 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sun, 10 Dec 2006 06:52:38 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: In article , Steven D'Aprano wrote: > That depends. If somebody smart is designing a new programming language, > then no, you get a new programming language. > > If somebody not-so-smart is merely hammering the round peg of Lisp into > the square hole of not-quite-Lisp-and-not-quite-anything-else, then yes, > that will be a problem. But apparently, despite the talk of using macros > to implement anything in Lisp, nobody actually does that. Then what exactly is your argument here? And BTW: CL-USER> (defun + (a b)) Lock on package COMMON-LISP violated when setting fdefinition of +. [Condition of type SYMBOL-PACKAGE-LOCKED-ERROR] While lisp doesn't prohibit such name conflicts, it does mean that anyone trying it will generate a fair number of errors each time the definition is compiled. > > Perhaps it's because I'm a social scientist and not a programmer by > > training, but I find many arguments for *technical* solutions to > > *human performance* problems to be rather weak as a general > > practice. In some cases, using a very restrictive language may be > > the best solution for the problem. > > I don't know about you, but I'm not talking about VERY restrictive > languages -- I'm using Python, which isn't very restrictive at all. But > even Lisp has some restrictions -- you can't jump to an arbitrary memory > location and treat whatever random bytes are there as executable code, can > you? Certainly, and I've even pointed out a few that would mediate against your claim of incompetent programmers being able to arbitrarily shadow core functions in a way that is invisible to anyone else. From vbgunz at gmail.com Sat Dec 2 02:04:37 2006 From: vbgunz at gmail.com (vbgunz) Date: 1 Dec 2006 23:04:37 -0800 Subject: Python, PostgreSQL, What next? Message-ID: <1165043076.979652.201730@16g2000cwy.googlegroups.com> Hello all, I've studied Python and studied PostgreSQL. What is the absolute next best step to take to merge these two finely together? I've heard of SQLAlchemy and some others but before I dive in, I would really like the opinion of those who tried it and other toolkits. My main concern is, I would like to completely work with a database from Python. What would you suggest I look into? Thank you for your time! From paddy3118 at netscape.net Mon Dec 11 10:04:16 2006 From: paddy3118 at netscape.net (Paddy) Date: 11 Dec 2006 07:04:16 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> Message-ID: <1165849456.411559.56490@80g2000cwy.googlegroups.com> On Dec 11, 2:17 pm, Bill Atkins wrote: > "Paddy" writes: > > JShra... at gmail.com wrote: > > >> > Python has to rely more on using the right algorithm... > > >> This sound familiar: "Macros are dangerous!" > > Yes. I changed my opinion on advocating Python having macros in one > > of our long threads on the subject. Maintainance counts.Yes, it does, but that should take you to exactly the opposite > conclusion. I won't duplicate the arguments against macros made elsewhere in the thread. > > >> "Compilers make you lazy." > > This is new to me. In fact, for the compiled languages available to me. > > Using them *first* would be the difficult choice.These are not real sentences, but if you're saying that compiled > languages make programming more difficult, then you're simply using > the wrong compiled languages. Lisp is a dynamic language that also > supports compilation to native code. Lisp was not a compiled language available to me, and even after my use of Cadence Skill, I would not consider Lisp for writing an extension unless Lisp had a library close to what I wanted, and there was a good way to link Python to the compiled Lisp code. > > > Unlike Lisp, Python does not have a ubiquitous compiler. It is > > therefore > > made to interface nicely with compiled languages. Other compiledWhat on earth does this mean? You're saying that because Python > doesn't have a compiler, it can interface more easily to compiled > languages? That's nonsense. No. I am saying that *because* it does not have a compiler, it has been *made to* integrate nicely with compiled languages; and further, I am saying that because some compiled language package maintainers see the advantages of using dynamic languages, they support Python integration. > > Further, most Lisp implementations support an interface to C that > doesn't require you to write and compile C code in order to use C > extensions in Lisp. Can Python do the same more "nicely" than Lisp? Python does the same. It might well be nicer but I do not know how Lisp does this. http://docs.python.org/dev/lib/module-ctypes.html http://www.boost.org/libs/python/doc/ http://www.python.org/pypi/pyobjc/1.3.5 (The last is used within Apple for some aspects of development). The above list is not exhaustive > > > language users see the need for dynamic interpreted languages like > > Python and maintain links Python such as the Boost Python C++ > > wrapper. IronPython for .NET, Jython for Java. > > Lisp is its own interpreter and compiler, which should be a great > > advantage, but only if you don't make the mistake of ignoring the > > wealth of code out there that is written in other languages. > Um. Yep. - Paddy. From rhamph at gmail.com Sun Dec 3 11:27:09 2006 From: rhamph at gmail.com (Rhamphoryncus) Date: 3 Dec 2006 08:27:09 -0800 Subject: Deleting from a list while iterating In-Reply-To: <4572F660.1070101@v.loewis.de> References: <1165160235.282030.96610@79g2000cws.googlegroups.com> <4572F660.1070101@v.loewis.de> Message-ID: <1165163229.065419.181810@73g2000cwn.googlegroups.com> Martin v. L?wis wrote: > Rhamphoryncus schrieb: > > setapproach = """\ > > def func(count): > > from random import random > > items = [random() for i in xrange(count)] > > remove = set() > > for index, x in enumerate(items): > > #...do something... > > if x < 0.5: > > remove.add(index) > > items = [x for index, x in enumerate(items) if index not in remove] > > """ > > This is different from the other approaches in that it doesn't > modify items. If you wanted a new list, you could incrementally > build one already in the first pass, no need to collect the > indices first (as BlackJack explains). I didn't feel this distinction was worth mentioning, since "oldlist[:] = newlist" is so trivial. The only solution that really avoids making a copy is the reverse-iteration one. > If you wanted in-place modification, I'd do > > newitems = [] > for x in items: > if not (x < 0.5): > newitems.append(x) > items[:] = newitems I agree, that does seem simpler. > > copyapproach = """\ > > def func(count): > > from random import random > > items = [random() for i in xrange(count)] > > for x in items[:]: > > if x < 0.5: > > items.remove(x) > > """ > > This happens to work for your example, but is incorrect > in the general case: you meant to write > > del items[i+removed] > > here, as .remove(x) will search the list again, looking > for the first value to remove. If your condition for > removal happens to leave some items equal to x in the > list, it would remove the wrong item. Because the numbering > changes while the iteration is in progress, you have > to count the number of removed items also. I agree that the example I gave here sucks. However, I copied it from another posting as a recommended method to get removal to work *right* (without noticing how slow it is). There seems to have been many distinct approaches to this problem over the years. Hopefully we can converge on a single ideal solution (or a few situational ones) as TOOWTDI. -- Adam Olsen, aka Rhamphoryncus From kevin_little at comkast.net.k2c Wed Dec 27 21:07:14 2006 From: kevin_little at comkast.net.k2c (Kevin Little) Date: Wed, 27 Dec 2006 21:07:14 -0500 Subject: Hooking any/all 'calls' Message-ID: In Python 2.4 or 2.5, what is the easiest way to hook any and all callables such that designated code is executed at the very start and end of each call? (Yes, I'm trying to come up with a little debugging tool!:) Is there a single metaclass who's "__call__" method can be wrapped to do this? TIA, -k From nmm1 at cus.cam.ac.uk Thu Dec 14 13:02:03 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 14 Dec 2006 18:02:03 GMT Subject: tuple.index() References: <1166103409.199435.290670@79g2000cws.googlegroups.com> <1166118142.144177.78790@l12g2000cwl.googlegroups.com> Message-ID: In article <1166118142.144177.78790 at l12g2000cwl.googlegroups.com>, "Carl Banks" writes: |> Glenn Hutchings wrote: |> > Simon Brunning wrote: |> > > It's because, philosophically, a Python tuple isn't just a read-only list. |> > |> > But there are situations where you might want to treat it as a |> > read-only list. E.g., an argument to a function, so that you can |> > guarantee the function won't modify it. |> |> Seems to me a misplaced fear. Do you take steps to also protect other |> mutable arguments (dicts, class instances, etc.)? If not, there should |> be no reason why you should protect lists that way either. If so, you |> could do a similar thing for lists as well. Well, in an ideal language, yes. And, yes, that is the correct solution. If I were a designing a language, mutability would be an orthogonal property to type. It isn't a misplaced fear, but the extra protection provided by doing that only for tuples is like locking one door out of ten to deter burglars - good practice, if there is no downside, but not worth putting much effort into. And the 'misplaced fear' assertion is equally applicable to the misuse of tuples - but that viewpoint is clearly heretical :-) |> For the record, I don't agree with tuple's absent count and index |> methods either, but for other reasons. It's a minor thing. I deal |> with it. Indeed. The code to sort out the problem was trivial. I was curious as to the reason, since there was no technical or mathematical one, and seem to have accidentally committed one of Python's Seven Unforgiveable Heresies, to have lost my soul irredeemably, and to be in danger of being burnt at the stake. Ah, well. [ Incidentally, my use was in argument decoding, where the Python layer holds the arguments as strings, and I need to pass them as an index to C (so they DO form a respectable tuple even in Guido's sense, being fixed in number and value and just happening to be homogeneous). ] Regards, Nick Maclaren. From fsenkel at lynx.neu.edu Mon Dec 11 11:13:28 2006 From: fsenkel at lynx.neu.edu (monkeyboy) Date: 11 Dec 2006 08:13:28 -0800 Subject: Help with weave.blitz() Message-ID: <1165853608.695373.270390@16g2000cwy.googlegroups.com> Hello, I'm a new scipy user, and I'm trying to speed up some array code with weave. I'm running xp with gcc from cgywin, and scipy.weave.test() returns an OK status. I'm trying to speed up the code below. I've found a couple of examples of weave on the web, and I think it should be straight forward, but I keep getting the following error when calling weave.blitz(expr). It's complaining about the variable being assigned, I've tried listing it in the blitz call with no luck. Any help is appreciated. PS I've also posted to scipy.org Thank you, Frank ***ERROR*** Traceback (most recent call last): File "D:/Documents/Homework/MTMG310/Project/hw6r3VectorizeWeave.py", line 436, in -toplevel- prof.runcall(main) File "C:\Python24\Lib\hotshot\__init__.py", line 76, in runcall return self._prof.runcall(func, args, kw) File "D:/Documents/Homework/MTMG310/Project/hw6r3VectorizeWeave.py", line 383, in main findw(w,wprior,phiprior,uprior,vprior) File "D:/Documents/Homework/MTMG310/Project/hw6r3VectorizeWeave.py", line 136, in findw weave.blitz(expr) File "C:\Python24\Lib\site-packages\scipy\weave\blitz_tools.py", line 35, in blitz if check_size and not size_check.check_expr(expr,local_dict,global_dict): File "C:\Python24\Lib\site-packages\scipy\weave\size_check.py", line 51, in check_expr exec(expr,values) File "", line 1 wnext[1:grows-1,1:gcols-1] =( alpha * w[1:grows-1,1:gcols-1] + ax * (w[1:grows-1,0:gcols-2] + w[1:grows-1,2:gcols]) + ^ SyntaxError: invalid syntax ***CODE*** def findw(wnext,wprior,phiprior,uprior,vprior): #format here is x[i,j] where i's are rows, j's columns, use flipud() to get the #print out consistent with the spacial up-down directions #assign local names that are more #inline with the class notation w = wprior phi = phiprior u = uprior v = vprior #three of the BC are known so just set them #symetry plane wnext[0,0:gcols] = 0.0 #upper wall wnext[gN,0:gcols] = 2.0/gdy**2 * (phi[gN,0:gcols] - phi[gN-1,0:gcols]) #inlet, off the walls wnext[1:grows-1,0] = 0.0 upos = where(u>0) vpos = where(v>0) Sx = ones_like(u) Sx[upos] = 0.0 xSx = 1.0 - Sx Sy = ones_like(v) Sy[vpos] = 0.0 ySy = 1.0 - Sy uw = u*w vw = v*w ax = gnu*gdt/gdx**2 ay = gnu*gdt/gdy**2 dtdx = gdt/gdx dtdy = gdt/gdy alpha = (1.0 - 2.0*ax - 2.0*ay) #interior nodes expr = """ \ wnext[1:grows-1,1:gcols-1] =( alpha * w[1:grows-1,1:gcols-1] + ax * (w[1:grows-1,0:gcols-2] + w[1:grows-1,2:gcols]) + ay * (w[0:grows-2,1:gcols-1] + w[2:grows,1:gcols-1]) - dtdx * (xSx[1:grows-1,1:gcols-1] * (uw[1:grows-1,1:gcols-1] - uw[1:grows-1,0:gcols-2]) - Sx[1:grows-1,1:gcols-1] * (uw[1:grows-1,2:gcols] - uw[1:grows-1,1:gcols-1])) - dtdy * (ySy[1:grows-1,1:gcols-1] * (vw[1:grows-1,1:gcols-1] - vw[1:grows-1,0:gcols-2]) - Sy[1:grows-1,1:gcols-1] * (vw[1:grows-1,2:gcols] - vw[1:grows-1,1:gcols-1])) ) """ #weave.inline(expr,['wnext','w','Sx','xSx','Sy','ySy','uw','vw','ax','ay','dtdx','dtdy','alpha','grows','gcols']) #weave.inline(expr,['wnext'],compiler='gcc',verbose=2) #weave.blitz(expr,['wnext','w','Sx','xSx','Sy','ySy','uw','vw','ax','ay','dtdx','dtdy','alpha','grows','gcols']) #weave.blitz(expr,size_check=1) #weave.inline(expr,['wnext']) weave.blitz(expr) ## for j in range(1,gasizej-1): ## for i in range(1,gasizei-1): ## ## wnext[i,j] =( w[i,j] + gnu*gdt/gdx**2 * (w[i,j-1] - 2.0*w[i,j] + w[i,j+1]) + ## gnu*gdt/gdy**2 * (w[i-1,j] - 2.0*w[i,j] + w[i+1,j]) - ## (1.0 - Sx[i,j]) * gdt/gdx * (uw[i,j] - uw[i,j-1]) - ## Sx[i,j] * gdt/gdx * (uw[i,j+1] - uw[i,j]) - ## (1.0 - Sy[i,j]) * gdt/gdy * (vw[i,j] - vw[i-1,j]) - ## Sy[i,j] * gdt/gdy * (vw[i+1,j] - vw[i,j]) ) ## print "***wnext****" ## print "i: ", i, "j: ", j, "wnext[i,j]: ", wnext[i,j] #final BC at outlet, off walls wnext[1:grows-1,gM] = wnext[1:grows-1,gM-1] From slawomir.nowaczyk.847 at student.lu.se Wed Dec 20 05:37:28 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Wed, 20 Dec 2006 11:37:28 +0100 Subject: automatically grading small programming assignments In-Reply-To: <45820A2F.5030204@bryant.edu> References: <1166123772.726309.138790@16g2000cwy.googlegroups.com> <45820A2F.5030204@bryant.edu> Message-ID: <20061220112621.292A.SLAWOMIR.NOWACZYK.847@student.lu.se> On Thu, 14 Dec 2006 21:36:31 -0500 Brian Blais wrote: #> Paddy wrote: #> > It might turn out to be a poor substitute for the personal touch, #> > especially If they are just starting to program. #> #> Oh, I didn't mean it to completely replace me grading things, but I #> think it would be useful if there were a lot of little assignments #> that could be done automatically, and then some larger ones that I #> would grade by hand. The little ones could be set up so that they can #> submit as many times as they want, until they get it right. Well, that sounds like a valid plan, but why would you want to grade the little ones at all, then? What I would most likely do is to publish those small assignments together with a set of tests for each one, and say that they should write programs and make sure their programs pass the tests. If you wish, you could publish two sets of tests, the "easy" and "tricky" ones, and have them use easy ones when writing program, and only run it through the "tricky" tests when they believe the program is bug-free. This can be a very valuable experience! (if you can devise the right tests, of course ;) If you either require the skills they develop doing "small" assignments in the "big" assignments, or if you check 2-3 small assignments by hand, you should be able to reduce cheating sufficiently... It's just a matter of making sure they really *do* write programs and that those programs *do* pass the tests. Or just require students to hand in the small assignments, together with the testing output, but do not check them at all (not too many will have the guts to fake the outputs). Then there is a whole range of ideas about peer review in the education community, where you could get students to verify one another's programs... But this can sometimes be tricky. -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) Someone Else's Code - a commonly used synonym for "Bad Code" From JohnRoth1 at jhrothjr.com Sun Dec 31 11:23:15 2006 From: JohnRoth1 at jhrothjr.com (John Roth) Date: 31 Dec 2006 08:23:15 -0800 Subject: PEP 3107 Function Annotations for review and comment In-Reply-To: References: <1167492896.292605.15040@48g2000cwx.googlegroups.com> Message-ID: <1167582195.660213.283160@a3g2000cwd.googlegroups.com> Tony Lownds wrote: > > First, it only handles functions/methods. Python FIT needs > > metadata on properties and assignable/readable attributes > > of all kinds. So in no sense is it a replacement. Parenthetically, > > neither is the decorator facility, and for exactly the same reason. > > > > I can't argue against docstrings and maybe annotations on attributes, > I'd like them myself. That should be a separate PEP because the scope > of this one is Function Annotations. > > The syntax for function annotations has been much more thoroughly > discussed than for annotations on attributes. See Guido's blog and > other references in the PEP. Syntax is always an issue. Looking at the history of annotations shows that people seem to prefer using a comment mechanism. This goes along with the notion of supplying minimal mechanism until you see what the actual usage is going to be. As far as I'm concerned, an annotation mechanism has to have several properties: 1. The annotation data needs to be available at run time without having the source available. 2. It needs to be syntax checkable by a mechanism supplied by the author of the annotation schema. I'd suggest a hook at the back end of import, since this doesn't get in the way of the compiler. The converse of this, of course, is that neither the language nor the compiler needs to have any idea of the actual syntax. This provides maximal freedom to experiment. 3. It needs to have a convention that will allow authors of different schemas to stay out of each other's way. Docstrings almost manage this. While they're certainly available at run time (at least if you don't compile in a way that strips them out) you can only have one in any module, class or method. This means you can't always put them where you want them, that is, close to the item that they're annotating. Parenthetically, I'd note that adding docstring capabilities to properties was a definite step forward. John Roth > > Thanks for the feedback from everyone so far, > -Tony From kernel1983 at gmail.com Wed Dec 13 02:40:41 2006 From: kernel1983 at gmail.com (kernel1983) Date: 12 Dec 2006 23:40:41 -0800 Subject: how can i write a hello world in chinese with python In-Reply-To: <1165985255.490054.290680@80g2000cwy.googlegroups.com> References: <1165982024.978824.146920@n67g2000cwd.googlegroups.com> <1165985255.490054.290680@80g2000cwy.googlegroups.com> Message-ID: <1165995641.270460.124350@73g2000cwn.googlegroups.com> and I tried unicode and utf-8 I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not to use Anyone knows about the setting in the python code file? Maybe python doesn't know I'm to use chinese?! On 12?13?, ??12?47?, "bearsprite" wrote: > try unicode? > > "kernel1983 ??? > " > > > I'm try to build a bundle on OS X, so I write a simple python script > > for a test: > > > #!/usr/bin/env python > > import EasyDialogs > > EasyDialogs.Message("Hello,Mac!") > > > This runs OK,but when I try to replace "Hello,Mac!" with chinese, it > > can't be display rightly. > > Then I tried some way else: > > > #!/usr/bin/env python > > import EasyDialogs > > EasyDialogs.Message("\xe4\xb8\xad") > > > It doesn't work! > > > As I know mac is unicode based,how can I display chinese on the screen? From salvatore.difazio at gmail.com Sun Dec 3 15:31:01 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 3 Dec 2006 12:31:01 -0800 Subject: Thread error Message-ID: <1165177861.653112.325020@73g2000cwn.googlegroups.com> Hi guys, when I close the application I get the following error: ----------------------------- Traceback (most recent call last): File "main.py", line 88, in while exit : pass KeyboardInterrupt Unhandled exception in thread started by Error in sys.excepthook: Original exception was: ----------------------------- This is the code: ----------------------------- # Echo client program import socket import sys import thread import mtalk HOST = '192.168.0.115' # The remote host PORT = 3580 # The same port as used by the server buff = "" buffStatus = 0 s = None exit = 1 ############### keywordDataIn ############### def keywordDataIn(): global buff, buffStatus, exit talkmsg = mtalk.TalkMessage() while exit: line = sys.stdin.readline() if line == 'quit\n': exit = 0 break elif line != '\n': lock.acquire() buff = talkmsg.Make(line) buffStatus = 1 lock.release() elif line == '\n': pass ############### dataToServer ############### def dataToServer(): global buff, buffStatus, exit while exit: if buffStatus == 1: try: lock.acquire() s.sendall(buff) buff = "" buffStatus = 0 lock.release() except: socket.error pass # errore da controllare ############## dataFromServer ############## def dataFromServer(): global exit while exit: data = s.recv(1024) print 'Received', repr(data) ############### Main ############### if __name__ == "__main__" : for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res buffStatus = 0 try: s = socket.socket(af, socktype, proto) except socket.error, msg: print("Unexpected error") s = None sys.exit(1) try: s.connect(sa) print 'Connection ...' except socket.error, msg: print("The server was not reachable") s.close() s = None sys.exit(1) print 'Connected' # mutex lock = thread.allocate_lock() thread.start_new_thread(keywordDataIn, ()) thread.start_new_thread(dataToServer, ()) thread.start_new_thread(dataFromServer, ()) while exit : pass s.close() ----------------------------- Tnx From javier_subervi at yahoo.com Wed Dec 13 06:35:39 2006 From: javier_subervi at yahoo.com (Javier Subervi) Date: Wed, 13 Dec 2006 03:35:39 -0800 (PST) Subject: Working w/ Yield Message-ID: <20061213113539.27709.qmail@web90309.mail.mud.yahoo.com> Hi; I'm trying to tweak a script I found here: http://zopelabs.com/cookbook/1118667115 to get it to do what I want. I'm no wizard at Python, much less newfangled tools like yield. I understand that one cannot use "return" when working with yield, but I don't understand how to achieve the same result. Here's my code: from random import randrange def getRandomQuote(top, topdown=True): objs = top.objectValues() num = 1 numAndQuote, quotes = [], [] for obj in objs: if isdir(obj): dirs.append(obj) else: quotes.append(obj) if topdown: yield top, dirs, quotes for obj in dirs: for x in getRandomQuote(obj, topdown): yield x if not topdown: yield top, dirs, quotes for q in quotes: numAndQuote.append(num, q) num += num def isdir(obj): if obj.meta_type == 'Folder': return True else: return False def demo(self): root = self.restrictedTraverse('/theSite/en-us/Books') num = randrange(1, len(num), 1) luckyWinner = numAndQuote.pop(num) path = '/'.join(luckyWinner.getPhysicalPath()) or '/' return path How can I stitch all this together to return the path? Or, how do I call the demo after executing the yield? TIA, Javier ____________________________________________________________________________________ Want to start your own business? Learn how on Yahoo! Small Business. http://smallbusiness.yahoo.com/r-index -------------- next part -------------- An HTML attachment was scrubbed... URL: From bdesth.quelquechose at free.quelquepart.fr Tue Dec 19 17:43:52 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 19 Dec 2006 23:43:52 +0100 Subject: Page layouts in mod_python? In-Reply-To: <1166563784.948936.253950@80g2000cwy.googlegroups.com> References: <1166563784.948936.253950@80g2000cwy.googlegroups.com> Message-ID: <45886568$0$31043$426a74cc@news.free.fr> Michael a ?crit : > Hey everyone, > > Is it possible to automatically insert headers/footers using > mod_python? > I will be not be using PSP's, so I cannot use the PSP/include solution. > Furthermore, the header will be dynamic; it won't be a static HTML > page. > > In short, I've been looking for a page layout facility using > mod_python. > (Similar to the layout capability in Ruby on Rails.) mod_python is mainly a librairy exposing the apache API to Python - not a full-stack db-to-web framework. What you want here is a HTML templating system. There are quite a lot available in Python - look for SimpleTAL, Genshi, Myghty, Jinja, Cheetah, etc... HTH From fredrik at pythonware.com Tue Dec 5 03:49:09 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 09:49:09 +0100 Subject: The del statement In-Reply-To: References: Message-ID: Marco Aschwanden wrote: > 2. Calls the destructor of an object --> list.destruct() "del name" only removes the name from the current namespace, it doesn't destroy the object: http://effbot.org/pyref/del the actual destruction is handled by the garbage collector, when the time is right. > The del keyword for removing an element in a container is a bit > awkward to me. do you find the x[i] syntax for calling the getitem/setitem methods a bit awkward too? what about HTTP's use of "GET" and "POST" for most about everything ? ;-) From paul at boddie.org.uk Fri Dec 8 12:19:36 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 8 Dec 2006 09:19:36 -0800 Subject: How to create a global hotkey? References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com> <1165515363.838887.109720@80g2000cwy.googlegroups.com> <1165596216.573871.259350@l12g2000cwl.googlegroups.com> Message-ID: <1165598376.346246.137520@j44g2000cwa.googlegroups.com> k04jg02 at gmail.com wrote: > Sorry, I should have mentioned that I'm running Linux, and I only will > be running this app while X is running. Global "hot keys" are typically the domain of the desktop environment (or window manager for archaic desktops). For example, KDE has a configuration dialogue where you can define hot keys or key combinations that do particular things: I've got the Windows key doing useful stuff in combination with other keys, for example. So programmatically setting hot keys may be something that requires communication with the desktop environment, and it would appear that on KDE you have to put hot key definitions in a file and then import them, the latter possibly being achieved using the DCOP interprocess communications mechanism provided in the environment (try "dcop khotkeys khotkeys" at the shell). Here's the only documentation I've found so far: http://developer.kde.org/~seli/khotkeys/ I suppose you could just plug in at the X level and have something define and intercept a hot key before the desktop environment has a chance to process it, but I doubt that this would be a particularly nice solution. Paul From shejo284 at gmail.com Tue Dec 19 17:48:29 2006 From: shejo284 at gmail.com (Sheldon) Date: 19 Dec 2006 14:48:29 -0800 Subject: Cpoying a PyList to a C string array In-Reply-To: <1166554716.119339.313850@f1g2000cwa.googlegroups.com> References: <1166543791.065298.245860@f1g2000cwa.googlegroups.com> <1166554716.119339.313850@f1g2000cwa.googlegroups.com> Message-ID: <1166568508.913030.161790@f1g2000cwa.googlegroups.com> Klaas skrev: > Sheldon wrote: > > The code below is a rookie attempt to copy a python list of strings to > > a string array in C. It works to some extent but results in memory > > problems when trying to free the C string array. Does anyone know how > > to do this properly? > > You have numerous problems in this code. The most important problem is > that you are referring to global variables which appear to be c structs > but you don't provide the definition (e.g., "work"). However, I can > guess some of the issues: > > > for (i = 0; i < work.sumscenes; i++) { > > msgop = PyList_GetItem(work.msgobj, i); > > work.msg_scenes[i] = PyString_AsString(msgop); > > ppsop = PyList_GetItem(work.ppsobj, i); > > work.pps_scenes[i] = PyString_AsString(ppsop); > > } > > PyString_AsString returns a pointer to the internal buffer of the > python string. If you want to be able to free() it (or indeed have it > exist for beyond the lifetime of the associated python string), you > need to malloc() memory and strcpy() the data. If the strings contain > binary data, you should be using PyString_AsStringAndSize. see > http://docs.python.org/api/stringObjects.html. > > I notice that you are doing no error checking or ref counting, but my > (inexperienced python c programming) opinion is that it should work > (neither api could potentially call python code, so I don't think > threading is an issue). > > > for (i = 0; i < NumberOfTiles; i++) { > > tileop = PyList_GetItem(work.tileobj, i); > > work.tiles[i] = PyString_AsString(tileop); > > sceneop = PyList_GetItem(work.nscenesobj, i); > > work.nscenes[i] = PyInt_AsLong(sceneop); > > } > > return 1; > > Similarly. > > -Mike Thanks Mike, I am rewriting the code but I don't understand the part about the c struct variable called work. The function I posted is a part of a larger script and I just posted that part that was problamatic. I was under the impression that if I declared the structure as global with the variable in tow: struct my_struct { int var; } work; then this is visible everywhere in the function as long as everything is in one file. Did I miss something? /S From ed at leafe.com Tue Dec 5 06:59:49 2006 From: ed at leafe.com (Ed Leafe) Date: Tue, 5 Dec 2006 06:59:49 -0500 Subject: Interface Designer In-Reply-To: <7.0.1.0.0.20061204194037.02066548@yahoo.com.ar> References: <32f2725f0612031347x79b21d3fkbf8cde9f6c4bbab9@mail.gmail.com> <7.0.1.0.0.20061204194037.02066548@yahoo.com.ar> Message-ID: <25F005E8-BE84-4797-8D19-E74697A0DD32@leafe.com> On Dec 4, 2006, at 5:41 PM, Gabriel Genellina wrote: >> I'm starting to program in python, i need a soft "interface >> designer" and adapt this interface to python. Somebody can help me >> with this? >> Sorry, my english is very bad. > > Mine too. I don't understand what you want - what do you mean by > "interface designer"? If by chance a visual tool for designing the user interface of an app is needed, then there are two good choices, both of which are based on the wxPython toolkit. One would be PythonCard (http:// pythoncard.sourceforge.net/), which features a simple, quick tool for laying out controls and binding code to them. The other is the Dabo Class Designer (of which I am the author; see URL in my sig), which gives you a choice of sizer-based layout or absolute positioning for laying out your GUI designs, as well as a simplified, more Pythonic API than wxPython provides. -- Ed Leafe -- http://leafe.com -- http://dabodev.com From spedrosa at gmail.com Wed Dec 6 11:41:40 2006 From: spedrosa at gmail.com (Stephen Eilert) Date: 6 Dec 2006 08:41:40 -0800 Subject: Looking for a decent HTML parser for Python... In-Reply-To: References: Message-ID: <1165423300.757002.156120@l12g2000cwl.googlegroups.com> Fredrik Lundh escreveu: > > Except it appears to be buggy or, at least, not very robust. There are > > websites for which it falsely terminates early in the parsing. > > which probably means that the sites are broken. the amount of broken > HTML on the net is staggering, as is the amount of code in a typical web > browser for dealing with all that crap. for a more tolerant parser, see: > > http://www.crummy.com/software/BeautifulSoup/ > > +1 for BeautifulSoup. The documentation is quite brief and sometimes confusing, but I've found it the easiest parser I've ever worked with. Stephen From whumeniu+anti+spam at telus.net Sat Dec 9 12:13:53 2006 From: whumeniu+anti+spam at telus.net (Wade Humeniuk) Date: Sat, 09 Dec 2006 17:13:53 GMT Subject: merits of Lisp vs Python In-Reply-To: <1165653338.110788.62580@n67g2000cwd.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165653338.110788.62580@n67g2000cwd.googlegroups.com> Message-ID: tmh wrote: > This is from the perspective of an aerospace engineer who passed > through python several years ago on the way to lisp. Futhermore, this > is a 2 glass of wine response. > Thanks for the comments. I think it is great that you took a "harder and less travelled way". It may be that some people get to a point where they are either tired or think they know everything. Or.. their brains just harden up and they become old dogs. There seems to be a recurring theme to many of the posts in this thread about syntax and readability. Some of it is "If I can not instantly read and understand what the code is doing then something is wrong with it". As if holding oneself as the standard of what is good and correct is the only way. If you see something and it is not readily apparent what it is, then that is a sign than something interesting may be going on. I got into Lisp because when I looked at it, I did not understand. I did not think WTF! but thought that something was going on and maybe I was cheating myself if I brushed it aside. There is also some disdain expressed about badly written programs. Why? They may be that way for some very good reasons, it is folly to think that programs have to be simple, obvious and elegant. I find interesting that a programmer got out their comfort zone and attempted something. Its better than the ones with the big egos who play it safe so they do not appear to be a fool. Wade From gagsl-py at yahoo.com.ar Sat Dec 9 00:35:41 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 8 Dec 2006 21:35:41 -0800 Subject: Driver selection In-Reply-To: References: Message-ID: <1165642541.222433.162640@l12g2000cwl.googlegroups.com> On 9 dic, 00:53, "Stuart D. Gathman" wrote: > The pyspf package [http://cheeseshop.python.org/pypi/pyspf/] can use > either pydns, or dnspython. The pyspf module has a simple driver > function, DNSLookup(), that defaults to the pydns version. It can be > assigned to a dnspython version, or to a test driver for in memory DNS. > Or you can modify the source to "from drivermodule import DNSLookup". > > What is the friendliest way to make this configurable? Currently, users > are modifying the source to supply the desired driver. Yuck. I would > like to supply several drivers, and have a simple way to select one at > installation or run time. You can store the user's choice in a configuration file (like the ones supported by ConfigParser). Then you can put all the logic to select and import the right function in a separate module, and export the DNSLookup name; make all the other parts of the application say "from mymodule import DNSLookup" -- Gabriel Genellina From paul at boddie.org.uk Wed Dec 6 06:51:22 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 6 Dec 2006 03:51:22 -0800 Subject: No latin9 in Python? References: Message-ID: <1165405881.933489.305260@f1g2000cwa.googlegroups.com> Christoph Zwerschke wrote: > I noticed that Python does not understand the codec alias names > latin7 = iso8859-13, latin9 = iso8859-15 > (see http://docs.python.org/lib/standard-encodings.html). > > Particularly latin9 is pretty popular here in Western Europe since it > contains the Euro symbol (contrary to latin1). One learns new things every day, I suppose: I've always referred to it as ISO-8859-15, using whatever combination or absence of "_" or "-" symbols that is deemed appropriate. > According to the Wikipedia (http://en.wikipedia.org/wiki/ISO-8859), the > latin7 and latin9 aliases seem to be official, at least they are widely > used an accepted. In PostgreSQL, LATIN9 is even the name of the charset, > and iso8859-15 is the alias name: > http://www.postgresql.org/docs/8.2/static/multibyte.html#CHARSET-TABLE My impression of relational databases is that they often have lots of legacy names for things like character encodings. A different perspective may be had by looking at the XML standards where encodings and their naming have received a great deal of attention: http://www.w3.org/TR/REC-xml/#NT-EncodingDecl It may be acceptable even in XML to use latin9 as an encoding name, but since the XML specifications appear to recommend the ISO names, and since XML has quite possibly raised awareness and usage of encoding declarations to previously unknown levels, there may be some benefit in conservatively shadowing XML and the expectations of its users (and of the wider Web page authoring community, amongst others). One would have to look into the rationale of the standards makers to understand why they've made those particular recommendations, however. > Is there anything speaking against adding these as aliases? If no, I > would submit a patch. (Also, Python does not support the > latin10=iso8859-16 charset. I could try to add that as well.) I don't see any disadvantages in having aliases, provided that they're unambiguous, but then I'm far from being any person who is going to be making that particular call. Paul From g.tagliaretti at gmail.com Fri Dec 8 17:38:26 2006 From: g.tagliaretti at gmail.com (Gian Mario Tagliaretti) Date: Fri, 08 Dec 2006 23:38:26 +0100 Subject: Is PyGTK only for local - not web? References: <1164642958.887985.53910@h54g2000cwb.googlegroups.com> Message-ID: <4579a91a$0$4253$4fafbaef@reader1.news.tin.it> walterbyrd wrote: > I have noticed that there is also pygtk-web project, I suppose that is > what you use for the web? It's the pygtk web site as you see it here.... www.pygtk.org cheers -- Gian Mario Tagliaretti From mystilleef at gmail.com Sat Dec 9 17:30:07 2006 From: mystilleef at gmail.com (mystilleef) Date: 9 Dec 2006 14:30:07 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: <1165703407.362890.23780@l12g2000cwl.googlegroups.com> Bill Atkins wrote: > Well, for example, "Lisp uses a fully-parenthesized notation for > writing programs" and "Python has significant whitespace" are both > objective facts. Agreed? There's nothing subjective about those two > facts. Do any of your points approach that level of objectivity? I believe so. Even though I wasn't trying to be. > What experience is this? Experience working with Scheme code in a project a few years back. > Macros are not a substitute for libraries, nor are libraries a > substitute for macros. Having macros lets you build more powerful and > more expressive libraries. > And not having them helps you build less powerful and expressive libraries? > > specialized libraries route. Meta-programming just doesn't tickle my > > fancy. It just spells maintainance nightmare. > > So it's not just macros but metaprogramming as a whole that bothers > you? You must have an enjoyable time writing programs. In Python, yes. > > >> And Lisp environments all support getting the macroexpansion, > >> documentation, and source of any unfamiliar macro you might happen > >> upon, so really this is not as much of a problem as you might > >> fantasize it to be. > > > > How's this a good thing? I don't need a Python environment to grok > > Python code. > > Nor do you need it to grok Lisp code. The environment is there to > make your life better. I was merely responding to your original claim > that it's impossible to make sense of code that uses macros. > Not impossible, just painstaking. > Hmm. Anecdotal evidence about Scheme (a vastly and fundamentally > different language from Common Lisp). Again, you've clinched it for > me. > I don't believe my experience would have been marginally different had I used Common Lisp. > I do believe that the "squealing and whining about macros" was a > response to Pythonistas claiming that macros are not useful. This was > in turn in response to a foolishly (trollishly?) cross-posted > question. It is not as if we have invaded your newsgroup. Pythonistas are not saying macros are not useful. They are saying their usefulness in overrated, exaggerated and needless in the context of Python. They are saying they don't see what they are missing and along with the rest of the world couldn't give a damn whether or not it is ever implemented in Python. Okay, I can't speak for all Pythonistas, but that's what I'm saying. From greg at cosc.canterbury.ac.nz Fri Dec 15 01:51:27 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 15 Dec 2006 19:51:27 +1300 Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> <1166127221.944683.65150@l12g2000cwl.googlegroups.com> Message-ID: <458245EF.6080504@cosc.canterbury.ac.nz> Gabriel Genellina wrote: > I bet your file is actually called fibo.py.txt then. > (Perhaps some advise should be provided for Windows users, about > enclosing the name inside "double quotes", or selecting "All files > (*.*)" on the file type list) Also, if by some chance you've got "Hide filename extensions" turned on in your View options, TURN IT OFF. It'll cause no end of confusion when you're trying to program. -- Greg From konrad.hinsen at laposte.net Sun Dec 10 07:29:09 2006 From: konrad.hinsen at laposte.net (konrad.hinsen at laposte.net) Date: Sun, 10 Dec 2006 13:29:09 +0100 Subject: About alternatives to Matlab In-Reply-To: <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <042F72AE-429B-4B3E-8E75-CB49B07C28DB@laposte.net> On 10.12.2006, at 11:23, Jon Harrop wrote: > Konrad Hinsen wrote: >> The lack of polymorphism, particularly in operators, makes OCaml code >> a pain to write and read in my opinion. > > F# addresses this by adding operator overloading. However, you have > to add more type annotations... That sounds interesting, but I'd have to see this in practice to form an opinion. As long as F# is a Windows-only language, I am not interested in it anyway. > You want bigarrays, they are just C/Fortran arrays. Look at the > bindings to > FFTW/LAPACK, for example. That's good news, thanks. >> Native code compilation is obviously important for speed. While many >> popular processors are supported by ocamlopt, scientific users are >> notorious for grabbing whatever fast hardware they can lay their >> hands on. It seems safe to count on the GNU suite being ported >> rapidly to any new platform. > > OCaml already supports 9 architectures and optimised to AMD64 > earlier than gcc. How many do you want? It's not a matter of number, it's a matter of availability when new processors appear on the market. How much time passes on average between the availability of a new processor type and the availability of a native code compiler for OCaml? Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Centre de Biophysique Mol?culaire, CNRS Orl?ans Synchrotron Soleil - Division Exp?riences Saint Aubin - BP 48 91192 Gif sur Yvette Cedex, France Tel. +33-1 69 35 97 15 E-Mail: hinsen at cnrs-orleans.fr --------------------------------------------------------------------- From crystalattice at gmail.com Tue Dec 12 15:04:39 2006 From: crystalattice at gmail.com (crystalattice) Date: 12 Dec 2006 12:04:39 -0800 Subject: Tkinter button doesn't appear in OS X In-Reply-To: <5de3b$457eba18$4275d90a$12544@FUSE.NET> References: <1165798158.199702.217180@79g2000cws.googlegroups.com> <457CC308.1080801@codebykevin.com> <1165893733.852293.229190@f1g2000cwa.googlegroups.com> <5de3b$457eba18$4275d90a$12544@FUSE.NET> Message-ID: <1165953879.140827.317120@79g2000cws.googlegroups.com> Kevin Walzer wrote: > When you run your program on OS X, there should be a menu item next to > the Apple menu that says "about Tcl/Tk," which you access from the > "Python" menu item. That will give you the version number. > > Python 2.3.5 and Tcl/Tk 8.4.7 ship with OS X 10.4. Python 2.4.2 is a > separate installation, but probably accesses the system Tcl/Tk unless > you have installed a more recent version. Using the official Mac build > of Python 2.5 will update your Python, but not Tcl/Tk--you'll need to > install something more recent. > > You can install ActiveTcl for a "batteries-included" distro of > Tcl/Tk--it has the latest and greatest of everything. Or, you can > install a slightly older (8.4.13) version of Tcl/Tk at > http://tk-components.sourceforge.net. (This is a version of Tcl/Tk Aqua > that I use in my own programs and I made the build available for others > to use.) > > Hope that helps, > Kevin > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com Thanks for the info. It looks like it should work. I wasn't aware that OS X is so "compartmentalized"; makes it a pain in the butt to develop on sometimes. From int2k at gmx.net Sun Dec 10 01:51:01 2006 From: int2k at gmx.net (Wolfram Fenske) Date: 9 Dec 2006 22:51:01 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xk611tpd1.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> Message-ID: <1165733461.368441.94940@16g2000cwy.googlegroups.com> Paul Rubin writes: > "Wolfram Fenske" writes: >> with a couple of macros. I. e. if Common Lisp didn't have CLOS, its >> object system, I could write my own as a library and it would be just >> as powerful and just as easy to use as the system Common Lisp already >> provides. Stuff like this is impossible in other languages. > > If Common Lisp didn't have lexically scoped variables (most Lisp > dialects before Scheme didn't have them) then it would be very > difficult to add that with macros. Alex Mizrahi already took care of that one. > Do you seriously think lexical scoping is the last word in language > features and that there's now nothing left in other languages that > can't straightforwardly be done in CL? No. My point was more that Lisp is so flexible that it even allows you to add something as huge as object orientation without requiring a change to the compiler. What about Aspect-Oriented Programming, for example? For Java, you need a new compiler/preprocessor, for Lisp, it can be implemented as a library [1]. > Hint: call-with-current-continuation (also known as call/cc). You're right call/cc is a problem because you basically can't implement call/cc without having call/cc. I. e. it requires pervasive changes to the compiler/interpreter if something like it is not already in there. Still, Scheme--also a Lisp--has call/cc and was probably the first language to implement it. > I just don't see a non-messy way to simulate Python generators in CL. > They can be done in Scheme using call/cc though. Scheme is also a Lisp. So? > Take a look sometime at Hughes' paper on "Why Functional Programming > Matters": > > http://www.math.chalmers.se/~rjmh/Papers/whyfp.html > > The examples in it are pretty easy to do in Python or Scheme, but I > think not so easy in CL. Anything in particular? I'd be surprised if the solutions in Scheme and CL would differ very much because apart from the Lisp-1/Lisp-2 issue and call/cc, Scheme and CL are not that different. Footnotes: [1] -- Wolfram Fenske A: Yes. >Q: Are you sure? >>A: Because it reverses the logical flow of conversation. >>>Q: Why is top posting frowned upon? From __peter__ at web.de Sun Dec 17 02:57:49 2006 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Dec 2006 08:57:49 +0100 Subject: textwrap.dedent replaces tabs? References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> Message-ID: Tom Plunket wrote: > I?guess?I?could?manually?replace?all?tabs?with?eight > spaces (as opposed to 'correct' tab stops), and then replace them when > done, but it's probably just as easy to write a non-destructive dedent. You mean, as easy as >>> "\talpha\tbeta\t".expandtabs() ' alpha beta ' ? Peter From salvatore.difazio at gmail.com Fri Dec 1 09:07:28 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 1 Dec 2006 06:07:28 -0800 Subject: I/O Multiplexing and non blocking socket Message-ID: <1164982048.938862.228890@79g2000cws.googlegroups.com> Hi guys, I'm looking for a tutorial to make a client with a i/o multiplexing and non blocking socket. Anybody knows where is a tutorial? Tnx From sturlamolden at yahoo.no Sat Dec 30 22:09:59 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 30 Dec 2006 19:09:59 -0800 Subject: Wow, Python much faster than MatLab In-Reply-To: <5bdf5$45969f9c$d443bb3a$14067@news.speedlinq.nl> References: <5bdf5$45969f9c$d443bb3a$14067@news.speedlinq.nl> Message-ID: <1167534599.274429.58550@i12g2000cwa.googlegroups.com> Stef Mientki wrote: > I always thought that SPSS or SAS where th? standards. > Stef As far as SPSS is a standard, it is in the field of "religious use of statistical procedures I don't understand (as I'm a math retard), but hey p<0.05 is always significant (and any other value is proof of the opposite ... I think)." SPSS is often used by scientists that don't understand maths at all, often within the fields of social sciences, but regrettably also within biology and medicine. I know of few program that have done so much harm as SPSS. It's like handing an armed weapon to a child. Generally one should stay away from the things that one don't understand, particularly within medicine where a wrong result can have dramatic consequences. SPSS encourages the opposite. Copy and paste from Excel to SPSS is regrettably becoming the de-facto standard in applied statistics. The problem is not the quality of Excel or SPSS, but rather the (in)competence of those conducting the data analysis. This can and does regrettably lead to serious misinterpretation of the data, in either direction. When a paper is submitted, these errors are usually not caught in the peer review process, as peer review is, well, exactly what is says: *peer* review. Thus, SPSS makes it easy to shoot your self in the foot. In my experience students in social sciences and medicine are currently thought to do exact that, in universities and colleges all around the World. And it is particularly dangerous within medical sciences, as peoples' life and health may be affected by it. I pray God something is done to prohibit or limit the use of these statistical toys. Sturla Molden PhD From Sebastien.Boisgerault at gmail.com Mon Dec 11 13:09:54 2006 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 11 Dec 2006 10:09:54 -0800 Subject: ElementTree, XML and Unicode -- C0 Controls In-Reply-To: References: <1165850683.430603.6500@79g2000cws.googlegroups.com> Message-ID: <1165860594.539502.231070@j44g2000cwa.googlegroups.com> On Dec 11, 4:51 pm, "Fredrik Lundh" wrote: > S?bastien Boisg?rault wrote: > > Could anyone comment on the rationale behind > > the current behavior ? Is it a performance issue, > > the search for non-valid unicode code points being > > too expensive ? > the default serializer doesn't do any validation or well-formedness checks at all; it assumes > that you know what you're doing. > > Fair enough ! Thanks Fredrik. SB From duncan.booth at invalid.invalid Fri Dec 29 09:17:59 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 29 Dec 2006 14:17:59 GMT Subject: Some basic newbie questions... References: <1167324002.516960.319870@79g2000cws.googlegroups.com> <12p7tah6gbtq53d@corp.supernews.com> <1167326253.557372.124110@a3g2000cwd.googlegroups.com> Message-ID: "jonathan.beckett" wrote: > I'm just finding it a bit weird that some of the built in functions are > static, rather than methods of objects (such as len() being used to > find the length of a list). When it comes down to it, its a design decision, so neither right nor wrong in itself. You need to look a bit wider than just 'len' to understand it. There is the historical attribute: as I understand it, once upon a time, way back in the mists of time tuples didn't have methods at all, so you had to use a global function if you wanted to get the length of a tuple. That of course is no longer the case. However, ignoring for a moment that this may have been part of the reason why Python started in the direction of global helper functions, there are a lot of reasons why it turns out to have been a good decision. Consider 'sum' for a moment. The function needs to know how to iterate over a sequence, but the sequence itself doesn't need to provide any support apart from iteration to be supported by 'sum'. If 'sum' was a method then you would have to implement it separately in every summable object; implement it in a common base class to all iterables; provide a 'Summable' mixin class requiring every designer of an iterable to decide at the outset whether they want it to be summable; or provide an adaptor class which takes an iterator and returns a summable iterator (which just adds a needless extra layer of complexity over the global function we started with). 'min', 'max', 'sorted', 'zip' are other functions which similarly provide support to any kind of iterable without encumbering the iterable protocol itself. Next consider 'iter'. That's a global function which calls the __iter__ method, but it also has a fallback behaviour. Before Python had __iter__ iteration was define by calling __getitem__ with increasing index values, and if you don't have an __iter__ method the iter builtin will try the old protocol instead. So the global function has some more benefits: we can change the protocol it implements and continue to provide backward compatability, and we can have it do more than just calling the method which does the implementation. getattr is another example of a builtin which appears to do the job of a method (__getattribute__) but actually does a whole lot more with fallback and exception handling in the function. Converting an AttributeError exception to a default value would be particularly nasty to get right if we were depending on a direct call to a base class __getattribute__ which might be overridden in the implemented class. cmp is another good example: cmp(a,b) returns a.__cmp__(b), but if a doesn't have an __cmp__ method then it tries to return -b.__cmp__(a) (and has another fallback if even that fails). There is also an argument that Python uses __ to distinguish internal implementation details so that the internal methods are effectively kept out of the user's namespace. The ordinary user shouldn't need to worry about the presence of __ methods as they never need to call them directly. In fact for beginners probably __init__ and "if __name__=='__main__':" are the only things besides 'keep off the double underscores' that they need to know about them. So where does that leave 'len'? It is a function primarily for consistency with the general idea that you call a builtin (or a function imported from a support module) rather than calling a __ method directly. It does add some minimal functionality over calling __len__ directly, but not such that you'ld normally notice the difference. From simon at brunningonline.net Fri Dec 8 12:07:11 2006 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 8 Dec 2006 17:07:11 +0000 Subject: Problem in reading a URL In-Reply-To: <66b602900612080847v2e54123di4c0b8eca96d54b2a@mail.gmail.com> References: <66b602900612080847v2e54123di4c0b8eca96d54b2a@mail.gmail.com> Message-ID: <8c7f10c60612080907u32d39474qd59e40e1ef3e0590@mail.gmail.com> On 12/8/06, ???????? ?????? wrote: > Hi, > > I get an error, when I am trying to read URL. > Where is the Problem? > > Thank u very much for all ideas!!! > > sincerely > > Chrysanthi > > > from urllib2 import * > > filename=urlopen('http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?query_key=1&db=nucleotide&qty=1&c_start=1&uids=&dopt=fasta&dispmax=20&sendto=t') > > for line in filename.readlines(): > > print line, > > > Error: History is unavailable either because it has expired or because > your system cannot accept href='/entrez/query/static/faq.html#Acceptscookies'>cookies Have you tried that URL on your browser? -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From john.d.clark at mac.com Sat Dec 9 21:28:35 2006 From: john.d.clark at mac.com (John Clark) Date: Sat, 9 Dec 2006 21:28:35 -0500 Subject: New York City Python Users Group meeting is planned for Dec. 12th @ 6pm - please RSVP! Message-ID: <001101c71c02$e61f6d00$b601a8c0@haengma> Greetings! The next New York City Python Users Group meeting is this Tuesday, Dec. 12th, 6pm at at the Millennium Partners office at 666 Fifth Avenue on the 8th Floor. We welcome all those in the NYC area who are interested in Python to attend. However, we need a list of first and last names to give to building security to make sure you can gain access to the building. If you would please RSVP to clajo04ATmacDOTcom to add your name to the list. More information can be found on the yahoo group page: http://tech.groups.yahoo.com/group/nycpython/ Hope to see you there! -John From adam at atlas.st Sat Dec 23 19:34:03 2006 From: adam at atlas.st (Adam Atlas) Date: 23 Dec 2006 16:34:03 -0800 Subject: Getting the name of an assignment In-Reply-To: References: <1166913499.494219.250440@48g2000cwx.googlegroups.com> Message-ID: <1166920443.257896.218800@79g2000cws.googlegroups.com> On Dec 23, 5:58 pm, "BJ?rn Lindqvist" wrote: > On 23 Dec 2006 14:38:19 -0800, Adam Atlas wrote: > > > Is it possible for an object, in its __init__ method, to find out if it > > is being assigned to a variable, and if so, what that variable's name > > is? I can think of some potentially ugly ways of finding out using > > sys._getframe, but if possible I'd prefer something less exotic. > > (Basically I have a class whose instances, upon being created, need a > > 'name' property, and if it's being assigned to a variable immediately, > > that variable's name would be the best value of 'name'; to make the > > code cleaner and less redundant, it would be best if it knew its own > > name upon creation, just like functions and classes do, without the > > code having to pass it its own name as a string.)I guess you mean something like this: > > >>> olle = Person() > >>> olle.name"olle" > > Instead of: > > >>> olle = Person("olle") > >>> olle.name"olle" > > It is not possible without ugly hacks. What you could use instead is > some kind of registry approach: > > reg = {} > class Person: > def __init__(self, name): > self.name = name > reg[name] = self > > >>> Person("olle") > >>> reg["olle"].name"olle" > > I think there are thousand different ways you could solve it. Yeah, I've thought of ways like that. I was just hoping to make the syntax as minimal and Pythonic as possible. I have the following working: > import sys > > class c: > def __init__(self): > f = sys._getframe(1) > names = [n for n in f.f_code.co_names if n not in f.f_locals] > if len(names) > 0: > name = names[0] > print name > > a = c() # prints 'a' > b = 'blah' > b = c() # prints nothing Question: too evil? From tshepang at gmail.com Thu Dec 21 12:01:36 2006 From: tshepang at gmail.com (Tshepang Lekhonkhobe) Date: Thu, 21 Dec 2006 19:01:36 +0200 Subject: are there Tomboy and F-Spot equivalents? Message-ID: <857993970612210901h5e56acf6lc726fc7a6315555a@mail.gmail.com> Hi, I dislike installing the entire Mono stack simply to take notes and manage photos, and am totally biased towards Python. At least for search I got Tracker, instead of Beagle. Are there equvalents applications for Tomboy and F-Spot which are written in Python. From Thomas.Ploch at gmx.net Wed Dec 20 08:29:11 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Wed, 20 Dec 2006 14:29:11 +0100 Subject: regexp In-Reply-To: <26845D561256D3428A862700DAF69B581AEF26@AG-EX1> References: <26845D561256D3428A862700DAF69B581AEF26@AG-EX1> Message-ID: <45893AA7.8020002@gmx.net> Mark Schoonover schrieb: > > You have to pay for this one, but I do like Komodo just for the regex > feature. I'm rather new to Python, coming over from 10 years of Perl, and > it's nice to have Komodo stay consistant. Can't wait for 4.0, so I can get > back to having VI key commands.... Back into "Learning Python", and DIP... Yes, I love that, too. The Komodo Rx Toolkit is really good for people who are new to regular expressions just to try them out, to get to know grouping, to see how MULTILINE and other flags work. I can recommend this to anyone who is new to regexes. Thomas From bjourne at gmail.com Fri Dec 29 19:09:38 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sat, 30 Dec 2006 00:09:38 +0000 Subject: PEP 3107 Function Annotations for review and comment In-Reply-To: References: Message-ID: <740c3aec0612291609w65f8becco5cf5b833d21c17da@mail.gmail.com> On 12/29/06, Tony Lownds wrote: > Rationale > ========= > > Because Python's 2.x series lacks a standard way of annotating a > function's parameters and return values (e.g., with information about > what type a function's return value should be), a variety of tools > and libraries have appeared to fill this gap [#tailexamp]_. Some > utilise the decorators introduced in "PEP 318", while others parse a > function's docstring, looking for annotations there. > > This PEP aims to provide a single, standard way of specifying this > information, reducing the confusion caused by the wide variation in > mechanism and syntax that has existed until this point. I think this rationale is very lacking and to weak for such a big change to Python. I definitely like to see it expanded. The reference links to two small libraries implementing type checking using decorators and doc strings. None of which to seem to be very popular in the Python community. Surely, those two libraries *alone* can't be enough of a motivation for this? To me, it is far from self-evident what purpose function annotations would serve. I also wonder why a very obtrusive syntax addition is needed when it clearly is possible to annotate functions in today's Python. Why is syntax better than just adding a function annotation decorator to the standard library? @annotate(a = int, b = dict, c = int) def foo(a, b, c = 5): ... Are decorators to ugly? -- mvh Bj?rn From fuzzyman at gmail.com Thu Dec 14 19:59:15 2006 From: fuzzyman at gmail.com (Fuzzyman) Date: 14 Dec 2006 16:59:15 -0800 Subject: MySQLdb windows binaries for Python 2.5?? Yes, but from a World of Warcraft guild. In-Reply-To: References: <1162408100.985370.148650@m7g2000cwm.googlegroups.com> <1163238145.257490.144410@b28g2000cwb.googlegroups.com> Message-ID: <1166144355.616642.127080@n67g2000cwd.googlegroups.com> johnf wrote: > John Nagle wrote: > > > Jan Dries wrote: > >> Henk.van.Asselt at gmail.com wrote: > >> > >>> I'm also looking for a MySQLdb binary for windows. This is holding me > >>> from upgrading from Python 2.4 to Python 2.5 ! > >>> > >> > >> If you search the Help Forum of the MySQLdb project on SourceForge, you > >> will find a couple of people who have successfully built MySQLdb on > >> Windows for 2.5, and are willing to share their installers. > >> That's how I got my binaries. > >> > >> Regards, > >> Jan > > > > Yes, see > > > > http://sourceforge.net/forum/forum.php?thread_id=1571110&forum_id=70461 > > > > for an untested version created by a World of Warcraft guild: > > > > > http://www.guildmanus.com/uploaded/MySQL-python.exe-1.2.2b2.win32-py2.5.exe > > > > This, apparently, is the extent of current Python support for MySQL. > > Want to install that executable, as root, on your production machines? > > > > This is embarassing for the Python community. Perl and PHP come > > with MySQL support built in. Python is out to lunch on this. > > > > John Nagle > > Animats > I couldn't disagree more. That fact that no Database drivers are built-in > makes Python stronger - allowing Python to access any Data Engine that > supports DBI 2.0. Of course I'm not including pickle in my assessment. > And providing 'built-in' drivers for massively popular databases would prevent that from being true how ? Fuzzyman http://www.voidspace.org.uk/index2.shtml > Johnf From bignose+hates-spam at benfinney.id.au Wed Dec 13 17:10:38 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 14 Dec 2006 09:10:38 +1100 Subject: Stupid email disclaimers (was: [unicode] inconvenient unicode conversion of non-string arguments) References: Message-ID: <87hcvzbg69.fsf_-_@benfinney.id.au> "Marc 'BlackJack' Rintsch" writes: > In , Holger Joukl > wrote: > > [a meaningless disclaimer text at the bottom of every message] > > Maybe you should rethink if it really makes sense to add this huge > block of "nonsense" to a post to a newsgroup or public mailing list. > If it's confidential, just keep it secret. ;-) In all likelihood, the OP isn't choosing specifically to attach it; these things are often done to *every* outgoing message at an organisational level by people who don't think the issue through very well. Please, those with such badly-configured systems, discuss the issue of public discussion forums with the boneheads who think these disclaimer texts are a good idea and at least try to change that behaviour. Alternatively, post from some other mail system that doesn't slap these obnoxious blocks onto your messages. -- \ "I wish there was a knob on the TV to turn up the intelligence. | `\ There's a knob called 'brightness' but it doesn't work." -- | _o__) Eugene P. Gallagher | Ben Finney From http Fri Dec 15 18:40:39 2006 From: http (Paul Rubin) Date: 15 Dec 2006 15:40:39 -0800 Subject: CLPython (was Re: merits of Lisp vs Python) References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <7xejr5y755.fsf@ruckus.brouhaha.com> <1166038096.200379.286830@80g2000cwy.googlegroups.com> <1166048301.513012.245480@73g2000cwn.googlegroups.com> <1166122900.477201.316320@73g2000cwn.googlegroups.com> <7xr6v2i3ay.fsf@ruckus.brouhaha.com> <1166210609.555804.304380@t46g2000cwa.googlegroups.com> Message-ID: <7x3b7gd8y0.fsf@ruckus.brouhaha.com> metawilm at gmail.com writes: > > a = 'hello' > > a[0] = 'H' # attempt to change first letter to upper case > > As CLPython mirrors Python semantics, this results in a TypeError. The > internal representation of an immutable Python string is a mutable Lisp > string, but there is no way you can actually modify it from within CLPython. How do you manage that? The compiler can't check. Is there some kind of special dispatch on the assignment statement instead of turning it into a setf? From atkinw at rpi.edu Sat Dec 9 14:14:27 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 14:14:27 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano writes: > I've read all the arguments against significant indents/whitespace, or > in favour of braces, and while there are a few minor good points they > make, a few edge cases where Python's significant indentation is > sub-optimal, overall I believe that the famous reaction of programmers to > Python and whitespace is simply them being more like cats than usual: > > "It's different, anything different is frightening, I don't like it, hiss > hiss spit!!!" What about "It's wrong, it's wrong, hiss hiss spit!" ? I want to be able to change my code and let the editor indent the result; if I make extensive changes to a section of Python code, I have to review it afterward and make sure I haven't introduced any subtle indentation mistakes. Compare (let ((x 'blah)) (if (eql x 'foo) (print "blah") (print "bloo")))) This could quite conceivably be the result of a lot of refactoring of (admittedly silly) code. But now I just press C-M-q and, pow: (let ((x 'blah)) (if (eql x 'foo) (print "blah") (print "bloo"))) All happily-indented. And mistakes in nesting show up as mistakes in indenting. Who could ask for anything more? Python requires me to review the structure of the code to make sure I haven't inadvertantly broken it. Why? Why do I need Python to enforce my indentation (potentially leading to bugs) when my editor can indent my code perfectly because the syntax of Lisp is so free of special cases? > But Lisp's syntax is so unlike most written natural languages that that it > is a whole different story. Yes, the human brain is amazingly flexible, > and people can learn extremely complex syntax and grammars (especially if > they start young enough) so I'm not surprised that there are thousands, > maybe tens or even hundreds of thousands of Lisp developers who find the > language perfectly readable. Most programming languages are nothing like natural languages (thankfully - ever heard of something called COBOL?). Lisp's syntax is trivial to lean, and its semantics are very precise. > But that isn't to say that the syntax of Lisp is for everybody. Far from > it -- I'd be willing to bet that Lisp developers are a self-selected group > of far above average intelligence. That would explain why so many of them > seem to be so much more comfortable with higher-order functions than most > other people -- even intelligent people. > > (Looking back, I'm embarrassed about my first reaction to factory > functions all those years ago. Hiss hiss spit. But even with added > familiarity, there comes a time where one has to question the benefit of > sufficiently high-order functions. If you are writing a factory function > that returns factory functions that return factory functions that return > the functions that you needed in the first place, chances are you really > need to rethink your tactics.) > > If I'm right, then maybe Lisp is "better" in some absolute sense, *for > those who can use it*. For those who can't, it isn't just a matter of > (say) the syntax being hard to read because it is unfamiliar, but it > being objectively harder to use. > > An interesting study would be to track people's eyeballs as they read > code, or look at how much oxygen their brain uses. Do Lisp coders do more > work to read Lisp than Python coders do to read Python? I suspect they do, > but successful Lisp coders don't notice. Everybody else does, and > gravitate to languages which might not be "better" but are "good enough". > > (If my post leads to any Lisp developer's already swollen head exploding > from pride, my job here is done *wink*) I'm afraid you're on the wrong track. Any programmer can pick up Lisp and be productive in it these days. Please don't try to make Lisp seem more mysterious or elitist than it really is. It's just a programming language, and anyone can learn it: http://www.gigamonkeys.com/book From oliphant.travis at ieee.org Tue Dec 12 13:50:47 2006 From: oliphant.travis at ieee.org (Travis E. Oliphant) Date: Tue, 12 Dec 2006 11:50:47 -0700 Subject: Sorting Multidimesional array(newbie) In-Reply-To: <20061211193104.40fe7985.tartifola@gmail.com> References: <20061211193104.40fe7985.tartifola@gmail.com> Message-ID: Tartifola wrote: > Hi, > how can I sort an array like > > array([[5, 2], > [1, 3]]) > > along the first column to obtain > > array([[1, 3], > [5, 2]]) > i.e. keeping track of the ordered couples? > > Thanks, > A Just to add one more solution to this question that works with numpy. You can also view the array using fields and then sort (which will do lexicographic ordering) and convert the result back to the original view. Something like this: a = array([[5,2],[1,3]]) dt = a.dtype g = a.view([('',dt),('',dt)]) g.sort(0) a = g.view(dt) -Travis From kay.schluehr at gmx.net Tue Dec 12 04:35:12 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 12 Dec 2006 01:35:12 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165857489.067258.27160@j44g2000cwa.googlegroups.com> <1165874781.930864.26750@16g2000cwy.googlegroups.com> <1165912604.892250.69930@80g2000cwy.googlegroups.com> Message-ID: <1165916112.603332.222030@j72g2000cwa.googlegroups.com> Juan R. schrieb: > > Given two languages L1 = (G1,T1), L2 = (G2, T2 ) where G1, G2 are > > grammars and T1, T2 transformers that transform source written in L1 or > > L2 into some base language > > L0 = (G0, Id ). Can G1 and G2 be combined to create a new grammar G3 > > s.t. the transformers T1 and T2 can be used also to transform L3 = (G3 > > = G1(x)G2, T3 = T1(+)T2) ? In the general case G3 will be ambigous and > > the answer is NO. > > You mean direct compositionality. Is there any formal proof that you > cannot find a (G2' , T2') unambiguously generating (G2, T2) and > combining with L1 or this is always possible? You mean a universal language adapter? I guess this is always possible using alpha conversion but I don't believe this leads to theoretical or practical interesting solutions but is just a limit concept. > This would not work for language enhancements but for composition of > completely independent languages. The practical problem with composing enhancements is that any two extensions L1, L2 share a lot of rules and rely on their structure. What if they don't just extend their host language L0 conservatively but also redefine rules of L0? This is not just a theoretical problem but it happens quite naturally if you want to adapt an extension developed for Python 2.4 for working with Python 2.5. Here Python 2.5 is considered as just another particular extension. Obviously Py3K will become an interesting testcase for all kinds of syntactical and semantical transformations. From kay.schluehr at gmx.net Mon Dec 11 11:03:55 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 11 Dec 2006 08:03:55 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> Message-ID: <1165853035.814913.46870@f1g2000cwa.googlegroups.com> Marc 'BlackJack' Rintsch schrieb: > In <1165849055.492230.119310 at n67g2000cwd.googlegroups.com>, Kay Schluehr > wrote: > > > Once an easy to use metaprogramming system could be done for Python it > > could be ported with some adaptions to other languages with more > > "complicated syntax" ( non LL(1) parsable ). > > FYI: Here's how Nemerle does macros: http://nemerle.org/Macros > > I guess you can't really transform Nemerle into a completely different > language, but it is at least interesting to see such a feature in language > with a more complex syntax than Lisp. > > Ciao, > Marc 'BlackJack' Rintsch Hi Mark, there are quite a lot of meta programming systems ( MPS ) for non Lispy languages ( O'Caml, Haskell, Java of course and also Dylan as a member of the "Lisp family" with non homogenous syntax ). I hope I will find time in the new year to review and compare them to the grammar based approach I described in the grandparent post and follow myself with "EasyExtend" for Python - which is *radical* and somewhat in between a language specific MPS and Lex/Yacc. The idea to separate the MPS from the host language but providing a multi-language framework is somewhat complementary to that of PyPy that is a framework that supports several backends for one language. From mfmorss at aep.com Tue Dec 5 10:35:37 2006 From: mfmorss at aep.com (Mark Morss) Date: 5 Dec 2006 07:35:37 -0800 Subject: About alternatives to Matlab In-Reply-To: <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165332936.164364.190860@73g2000cwn.googlegroups.com> I doubt that anyone would dispute that even as boosted by Numpy/Scipy, Python will almost certainly be notably slower than moderately well-written code in a compiled language. The reason Numpy exists, however, is not to deliver the best possible speed, but to deliver enough speed to make it possible to solve large numerical problems with the powerful and flexible Python language. As observed by Hans Latangen in _Python Scripting for Computational Science_, 2nd ed., Springer 2005, scientific computing is more than number crunching: "Very often programming is about shuffling data in and out of different tools, converting one data format to another, extracting numerical data from a text, and administering numerical experiments involving a large number of data files and directories. Such tasks are much faster to accomplish in a language like Python than in Fortran, C, C++ or Java." He might well have mentioned the importance of developing nice-looking reports once the analysis is complete, and that development is simpler and more flexible in Python than a compiled language. In principle, I agree that heavy-duty number-crunching, at least if it has to be repeated again and again, should be accomplished by means of a compiled language. However, if someone has to solve many different problems just one time, or just a few times (for example if you are an engineering consultant), there is an excellent argument for using Python + Numpy. Unless it affects feasibility, I opine, computational speed is important primarily in context of regular production, e.g., computing the daily "value at risk" in a commodity trading portfolio, or making daily weather predictions. I am aware of the power and flexibility of the OCaml language, and particularly that an OCaml user can easily switch back and forth between interpreted and compiled implementation. I'm attacted to OCaml and, indeed, I'm in the process of reading Smith's (unfortunately not very well-written) _Practical OCaml_. However, I also understand that OCaml supports only double-precision implementation of real numbers; that its implementation of arrays is a little clunky compared to Fortran 95 or Numpy (and I suspect not as fast as Fortran's); and that the available libraries, while powerful, are by no means as comprehensive as those available for Python. For example, I am unaware of the existance of an HDF5 interface for OCaml. In summary, I think that OCaml is an excellent language, but I think that the question of whether to use it in preference to Python+Numpy for general-purpose numerical analysis must rest on much more than its computational speed. Jon Harrop wrote: > Filip Wasilewski wrote: > > Besides of that this code is irrelevant to the original one and your > > further conclusions may not be perfectly correct. Please learn first > > about the topic of your benchmark and different variants of wavelet > > transform, namely difference between lifting scheme and dwt, and try > > posting some relevant examples or use other topic for your benchmarks. > > Your lifting implementation is slightly longer and slower than the > non-lifting one but its characteristics are identical. For n=2^25 I get: > > 1.88s C++ (816 non-whitespace bytes) > 2.00s OCaml (741 b) > 2.33s F# (741 b) > 9.83s Your Python (1,002 b) > > The original python was 789 bytes. > > > Neglecting this issues, I wonder if it is equally easy to juggle > > arbitrary multidimensional arrays in a statically typed language and do > > operations on selected axis directly from the interactive interpreter > > like in the NumPy example from my other post - > > http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 ? > > I don't know much OCaml so it would be great if you could elaborate on > > this. > > It is probably just as easy. Instead of dynamic typing you have parametric > polymorphism. If you want to make your function generic over arithmetic > type then you can pass in the arithmetic operators. > > >> 0.56s C++ (direct arrays) > >> 0.61s F# (direct arrays) > >> 0.62s OCaml (direct arrays) > >> 1.38s OCaml (slices) > >> 2.38s Python (slices) > >> 10s Mathematica 5.1 > >> > >> Note that all implementations are safe (e.g. C++ uses a.at(i) instead of > >> a[i]). > > > > So why not use C++ instead of all others if the speed really matters? > > What is your point here? > > 1. Benchmarks should not just include two inappropriate languages. > 2. Speed aside, the other languages are more concise. > > > Could you please share full benchmark code, so we could make > > conclusions too? > > I'll paste the whole programs at the end... > > > I would like to get to know about your benchmark > > methodology. I wonder if you are allocating the input data really > > dynamically or whether it's size is a priori knowledge for the > > compiler. > > The knowledge is there for the compiler to use but I don't believe any of > them exploit it. > > >> In this specific context (discrete wavelet transform benchmark), I'd have > >> said that speed was the most important thing after correctness. > > > > Not necessarily, if you are doing research with different kinds of > > wavelets and need a general, flexible and easily adaptable tool or just > > the computation speed is not considered a bottleneck. > > Brevity is probably next. > > > Language speed is a great advantage, but if it always was the most > > important, people would talk directly to the CPUs or knit DSP chips in > > theirs backyards whenever they need to solve a calculation problem. > > Sure. > > > Please don't make this discussion heading towards `what is the fastest > > way of doing d4 transform and why OCaml rules` instead of `what is the > > optimal way of doing things under given circumstances and still have a > > free afternoon ;-)`. > > Comments like that seem to be based on the fundamental misconception that > writing C++ like this is hard. > > > Different tasks need different, well-balanced > > measures. Neither Python nor OCalm nor any other language is a panacea > > for every single problem. > > Absolutely. OCaml is as good as the next (compiled) language in this case. > Python and Matlab seem to be particularly bad at this task. > > Here's my complete OCaml: > > let a = sqrt 3. and b = 4. *. sqrt 2. > let h0, h1, h2, h3 = > (1. +. a) /. b, (3. +. a) /. b, (3. -. a) /. b, (1. -. a) /. b > let g0, g1, g2, g3 = h3, -.h2, h1, -.h0 > > let rec d4_aux tmp a n = > let n2 = n lsr 1 in > for i=0 to n2-2 do > tmp.(i) <- a.(i*2)*.h0+.a.(i*2+1)*.h1+.a.(i*2+2)*.h2+.a.(i*2+3)*.h3; > tmp.(i+n2) <- a.(i*2)*.g0+.a.(i*2+1)*.g1+.a.(i*2+2)*.g2+.a.(i*2+3)*.g3; > done; > tmp.(n2-1) <- a.(n-2)*.h0 +. a.(n-1)*.h1 +. a.(0)*.h2 +. a.(1)*.h3; > tmp.(2*n2-1) <- a.(n-2)*.g0 +. a.(n-1)*.g1 +. a.(0)*.g2 +. a.(1)*.g3; > Array.blit tmp 0 a 0 n; > if n > 4 then d4_aux tmp a (n lsr 1) > > let d4 a = > let tmp = Array.make (Array.length a) 0. in > d4_aux tmp a (Array.length a) > > let () = > print_endline "Generating test data..."; > let x = Array.init (1 lsl 25) (fun _ -> Random.float 1.) in > print_endline "Benchmarking..."; > let t1 = Sys.time() in > ignore(d4 x); > Printf.printf "Elapsed time is %.6f seconds\n" (Sys.time() -. t1) > > and C++: > > #include > #include > #include > #include > > using namespace std; > > double a = sqrt(3), b = 4 * sqrt(2); > double h0 = (1 + a) / b, h1 = (3 + a) / b, h2 = (3 - a) / b, h3 = (1 - a) / > b; > double g0 = h3, g1 = -h2, g2 = h1, g3 = -h0; > > void d4(vector &a) { > vector tmp(a.size()); > for (int n = a.size(); n >= 4; n >>= 1) { > int half = n >> 1; > > for (int i=0; i tmp.at(i/2) = a.at(i)*h0 + a.at(i+1)*h1 + a.at(i+2)*h2 + a.at(i+3)*h3; > tmp.at(i/2+half) = a.at(i)*h3 - a.at(i+1)*h2 + a.at(i+2)*h1 - > a.at(i+3)*h0 > ; > } > > tmp.at(half-1) = a.at(n-2)*h0 + a.at(n-1)*h1 + a.at(0)*h2 + a.at(1)*h3; > tmp.at(2*half-1) = a.at(n-2)*h3 - a.at(n-1)*h2 + a.at(0)*h1 - > a.at(1)*h0; > > copy(tmp.begin(), tmp.begin() + n, a.begin()); > } > } > > int main() { > cout << "Generating data...\n"; > vector a(1 << 25); > for (int i=0; i cout << "Benchmarking...\n"; > double t1 = clock(); > d4(a); > cout << "Elapsed time " << (clock() - t1) / CLOCKS_PER_SEC << "s\n"; > } > > -- > Dr Jon D Harrop, Flying Frog Consultancy > Objective CAML for Scientists > http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From gagsl-py at yahoo.com.ar Mon Dec 4 19:35:28 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 04 Dec 2006 21:35:28 -0300 Subject: mapped drive missing when run as a service In-Reply-To: <005301c717fc$2f72f950$3d6ea8c0@eformswin2> References: <005301c717fc$2f72f950$3d6ea8c0@eformswin2> Message-ID: <7.0.1.0.0.20061204213256.047b4770@yahoo.com.ar> At Monday 4/12/2006 20:30, Thomas Thomas wrote: >I have a python application which i run as a service.. > > import win32api,string > drives=win32api.GetLogicalDriveStrings() > drives=string.splitfields(drives,'\000') > print drives > >in the list of drives my mapped network drive is not showing when i >run the application as a service. >I tried running the service as an administrator but with similar results.. > >any work around for this situation.. > >All i want is to access network files when run the application as a service.. Services usually run as Local System account, and it does not have access to mapped drives (that depends on the logged-in user). You can use a UNC path instead: \\servername\sharename -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From fredrik at pythonware.com Tue Dec 19 10:37:27 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 16:37:27 +0100 Subject: When Closure get external variable's value? In-Reply-To: <1166542026.913912.82880@t46g2000cwa.googlegroups.com> References: <1166473333.593246.238580@73g2000cwn.googlegroups.com> <1166474513.700608.201760@48g2000cwx.googlegroups.com> <1166542026.913912.82880@t46g2000cwa.googlegroups.com> Message-ID: Huayang Xia wrote: > When does the closure get the value of the maxIndex in the following > code snippet? > > def testClosure(maxIndex) : > > def closureTest(): > return maxIndex > > maxIndex += 5 > > return closureTest() > > print testClosure(10) > > > I thought it should be 10 instead of 15. That was wrong. free variables in an inner scope bind to variables in the outer scope, not objects. if you want to bind to objects, use explicit binding: def closureTest(maxIndex=maxIndex): return maxIndex From bignose+hates-spam at benfinney.id.au Sun Dec 10 19:15:20 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 11 Dec 2006 11:15:20 +1100 Subject: Barry Warsaw Python Webcast at GSFC References: Message-ID: <87fybncmp3.fsf@benfinney.id.au> William Allison writes: > http://isandtcolloq.gsfc.nasa.gov/webcasts.html > It's at the bottom of the page. In WMV format, and thus not viewable with free software :-( -- \ "I don't like country music, but I don't mean to denigrate | `\ those who do. And for the people who like country music, | _o__) denigrate means 'put down'." -- Bob Newhart | Ben Finney From kentilton at gmail.com Wed Dec 13 19:21:46 2006 From: kentilton at gmail.com (Ken Tilton) Date: Wed, 13 Dec 2006 19:21:46 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> Message-ID: Ken Tilton wrote: > > > Paul Rubin wrote: > >> Ken Tilton writes: >> >>> Have you read On Lisp by Paul Graham? It is on-line. Just the preface >>> will do, I think, maybe also Chapter One where he raves on macros. Do >>> you think he is mistaken? Confused? Lying? Mutant? >> >> >> >> I remember Paul Graham's piece about macros that made him sound like >> someone who went nuts with them, as is certainly possible to do. > > > But you could have just flipped thru the rest of the pages to see if he > /had/ gone nuts with them! > >> In >> my experience, good coders write for clarity and that includes in >> their use of Lisp macros. All in all Lisp's macro system is something >> like the C preprocessor. Yes, you can obfuscate things horribly with >> it, but you can also use it to make things clearer, and that's what >> good programmers do. > > > One has to be from the US and of a certain age to remember this, but > this old line from a commercial for high-octane gasoline says it for me: > power to be used, not abused. Here is a bit of concrete I just tossed off: (defmacro defskill (id &body skill-info) `(progn ,@(loop with sub-id = id for (q . q-def) in skill-info collecting (ecase q ((title annotations hints) `(defmethod ,(intern (conc$ 'skill- q)) ((tf-id (eql ',sub-id))) , at q-def)))))) It lets me code this: (defskill absolute-value (title "Absolute Value") (annotations "Take the absolute value of #op#." "The vertical bars around #op# mean 'the absolute value of' #op#." "Absolute value of #strn# is the 'distance' of #strn# from zero." "Absolute value is always zero or positive: #str|n|=n#, and #str|-n|=n#.") (hints "What do those vertical bars around #op# mean?" "Have you learned about 'absolute value'?" "Absolute value can be thought of as the 'distance' of a value from zero on the number line, and distance is always positive." "The rule is:#str|-n|=|n|##str=n#. Can you apply that to #op#?" "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#." "To get the absolute value of a number such as #op#, we simply drop any minus sign.")) ...and get this: (PROGN (DEFMETHOD SKILL-TITLE ((TF-ID (EQL 'ABSOLUTE-VALUE))) "Absolute Value") (DEFMETHOD SKILL-ANNOTATIONS ((TF-ID (EQL 'ABSOLUTE-VALUE))) "Take the absolute value of #op#." "The vertical bars around #op# mean 'the absolute value of' #op#." "Absolute value of #strn# is the 'distance' of #strn# from zero." "Absolute value is always zero or positive: #strn=n#, and #str-n=n#.") (DEFMETHOD SKILL-HINTS ((TF-ID (EQL 'ABSOLUTE-VALUE))) "What do those vertical bars around #op# mean?" "Have you learned about 'absolute value'?" "Absolute value can be thought of as the 'distance' of a value from zero on the number line, and distance is always positive." "The rule is:#str-n=n##str=n#. Can you apply that to #op#?" "Some examples: #str+42=42#, #str-42=42#, and #str0=0#." "To get the absolute value of a number such as #op#, we simply drop any minus sign.")) The above is how my upcoming death-defying interactive Algebra tutor-in-a-drum ("You'll laugh! You'll cry!") will know how to coax some befuddled teen through |-42| -> 42 if they get stuck. And a hundred other subskills (so there will be a hundred of these definitions). If I hire someone they will look at defskill and not fall to the ground frothing at the mouth. They likely will not even macroexpand it because it is self-explanatory. If they wonder if there are other options they can alt-. to the source. The language has been extended, but I followed a pattern familiar to Lispniks. Zero confusion results. If I decide not to use generic method dispatch to "look up" the hints I just have to change the macro and then write a DEFUN (no dispatch on type) to, say, look up the symbol in a hash table. hth,ken ps. I won't mention the other benefit, which is that I want educators to edit these if they have a better idea on how to tutor absolute value. I am not mentioning it because I am as impatient with superfluous syntax as a non-programmer would be. k pps. How would Python do this? Is it possible to avoid committing to an implementation mechanism? Compare and contrast. k -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From horpner at yahoo.com Tue Dec 12 16:15:02 2006 From: horpner at yahoo.com (Neil Cerutti) Date: Tue, 12 Dec 2006 21:15:02 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> <7xwt4y6j57.fsf@ruckus.brouhaha.com> Message-ID: On 2006-12-12, Andr? Thieme wrote: >> Contrast the much more common >> >> a[i] = b[n] >> >> with >> >> (setf (aref a i) (aref b n)) >> >> and the attractions of Python may make more sense. > > Here Python and Lisp are equal, 7 tokens vs 7 tokens, but in > Python one has to write less since "[]" are 2 chars while > "aref" are 4, plus the setf. But from counting the brain units > which I regard as an important factor they are both equal. A comparison of brain units of the above snippets is irrelevant, since the snippets are not equivalent. The Python snippet will work for any object a that provides __setitem__ and any object b that provides __getitem__. I don't know what an equivalent Lisp snippet would be (or even exactly how close the above snippet comes to matching the Python code), but whatever it is would be a better foundation for comparing brain units with the above Python. -- Neil Cerutti From kentilton at gmail.com Sat Dec 9 02:29:56 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 02:29:56 -0500 Subject: merits of Lisp vs Python In-Reply-To: <%Qseh.77$495.67@trnddc06> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> Message-ID: David Lees wrote: > JShrager at gmail.com wrote: > >> Okay, since everyone ignored the FAQ, I guess I can too... >> >> Mark Tarver wrote: >> >>> How do you compare Python to Lisp? What specific advantages do you >>> think that one has over the other? >> >> >> (Common) Lisp is the only industrial strength language with both pure >> compositionality and a real compiler. What Python has is stupid slogans >> ("It fits your brain." "Only one way to do things.") and an infinite >> community of flies that, for some inexplicable reason, believe these >> stupid slogns. These flies are, however, quite useful because they >> produce infinite numbers of random libraries, some of which end up >> being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python >> is rapidly replacing Perl, and Ruby is simultaneously and even more >> rapidly replacing Python. Each is closer to Lisp than the last; the >> world is returning to Lisp and is dragging the flies with it. >> Eventually the flies will descend upon Lisp itself and will bring with >> them their infinite number of random libraries, and then things will be >> where they should have been 20 years ago, but got sidetracked by Tcl >> and other line noise. >> > > Hmmm. The last time I fooled around with Lisp was 1966 from the Lisp > 1.5 Manual Published by MIT in cloth. It was interesting and different > from the other languages I was using, Algol 60, Basic and Macro > assembler for the GE-235 and GE-635. When I read some of the over the > top type hype by Lisp enthusiasts (like the stuff above) it feels like a > flash back to the mid 60's. Not sure I understand why, unless you mean folks were raving about Lisp in the 60s. Today's raving is about a much different language, though the core elegance remains, and is as much about the contrast with other languages as it is about the pleasure of Lisp itself. Those raving about Lisp are quite accomplished at all those other languages, and know about what they are talking. I doubt the Pythonistas weighing in on this thread ever got far at all with Lisp, so... should they really be offering comparative analysis? > Personally, I never like Lisp syntax; > Clearly some people, some fanatic judging by this thread :) think easily > in prefix. I am not one of them. Yeah, you are, you just did not use it heads down for a month. The way to tell if you spent enough time on Lisp is to look at Lisp code. If you see any parentheses, you have not spent enough time. They disappear in a month. The typical Pythonista values clean code but trembles in the face of macros, which exist to hide boilerplate. That means the only thing showing in any given block of code is exactly the interesting variable and function names. Talk about readability. > Computer languages are tools and > everyone should pick the ones that they are most comfortable and > productive with. No, languages are not interchangeable. Python is a fine language, but Lisp is much more expressive/powerful. > > Six years ago, when I drifted back into programming, I had to learn > about Object Oriented programming and C++. I used Python as a means to > update my programming skills (limited though they are) by 30 years or > so. It was a wonderful intro to OO and served me well. I ended up > writing all kinds of little things for work (simple HTTP servers for > load testing, ECAD hacks for the ASIC guys, even a register level chip > simulator) Even better, I find it a pleasure to write small utilities, > to prototype C code and generally do things quickly. I use it by choice > to get things done, not because it is mandated. At my current job as a > Systems Engineer for a large aerospace firm, I do not program daily, but > when I need to write a quick hack, I always use Python. Much of Lisp's power would be lost on a non-programmer, but Lisp might make a programmer out of a non-programmer if they had it in them. You might have the right language for you because what Python does have is lotsa libraries, and if you are just hacking scripts to glue together libraries the expressiveness of Lisp is more than offset by the better library support in Python. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From jan.dries at dcube-resource.be Fri Dec 8 13:35:15 2006 From: jan.dries at dcube-resource.be (Jan Dries) Date: Fri, 08 Dec 2006 19:35:15 +0100 Subject: merits of Lisp vs Python In-Reply-To: <45797a0c$0$49204$14726298@news.sunsite.dk> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> Message-ID: <4579B063.40200@dcube-resource.be> Alex Mizrahi wrote: > RB> Performance claims are always controversial. So, Python is much slower > RB> doing array multiplication, when you hand roll it, instead of using the > RB> standard numerical packages available. > > heh, do you have "standard numeric packages" for everything? maybe then > we'll make standard programs for everything -- that will obsolete "slow" > "custom scripts" and we'll just use shell to select what program we want to > run? I think you're missing the point. You must know your language's strengths and weaknesses, and use the approach/function/library that's right for the job in the given language. For instance, on my machine the following Python-code: some_string = "" while len(some_string) < 100000: some_string += "*" outperforms the following C-code: strcpy(some_string,""); while(strlen(some_string) < 100000) strcat(some_string,"*"); by roughly *factor 15*! The point of course is you shouldn't be using strlen/strcat this way, nor use this piece of code as a reference for benchmarking C versus Python performance. And for the same reason: in the presence of excellent optimized Python libraries for matrix multiplication, you probably shouldn't be doing that in pure Python if performance matters, nor use that as a reference case in benchmarking Python. Regards, Jan From researchbase at gmail.com Sat Dec 30 09:51:10 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Sat, 30 Dec 2006 20:21:10 +0530 Subject: can't find a suitable application server Message-ID: hello, I have read about zope and found it very good. but right now I am a bit confused about one project I have just procured. it is supposed to be a simple 3 tear application. the front end will be a thin client which we will develop using wxpython. We are using MySQL for the database and I need to find out a suitable application server where I can do just the following. 1. write my business logic which will actually be the workhorse. 2. send data to the thin client in form of either text or lists or tuples as required. I want my thin client just to take the data and recieve the data. 3. an application server that will process data coming from the thing client. this layer will fire the queries etc. 4. send the processed results in the forms mentioned in point number 2 (sorry if I am redundent). I thought zope is too heavy and complex for this task and zope is generally used in places where the data is too dynamic and the system very complex. I am any ways using MySQL for the rdbms which is more than sufficient so no need for a object oriented database like what zope has. can any one suggest me what to do? right now I get an impression that I must create sockets and send and receave data through that socket to the thin client and put the actual business logic on a seperate machine or on the database server what ever. thanking all. Krishnakant. From uval at rz.uni-karlsruhe.de Thu Dec 7 20:53:18 2006 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Sch=FCle_Daniel?=) Date: Fri, 08 Dec 2006 02:53:18 +0100 Subject: why is this different? Message-ID: Hello snakes :) In [38]: f = [lambda:i for i in range(10)] In [39]: ff = map(lambda i: lambda : i, range(10)) In [40]: f[0]() Out[40]: 9 In [41]: f[1]() Out[41]: 9 In [42]: ff[0]() Out[42]: 0 In [43]: ff[1]() Out[43]: 1 I don't understand why in the first case f[for all i in 0..9]==9 what is different from (more usefull) In [44]: f = ["%i" % i for i in range(10)] In [45]: f Out[45]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] doing it like this works again In [54]: def d(x): ....: return lambda:x ....: In [55]: f = [d(i) for i in range(10)] In [56]: f[0]() Out[56]: 0 In [57]: f[1]() Out[57]: 1 in a C programmer sence I would say there seems to be no "sequence point" which would separate "now" from "next" Regards, Daniel From roman.yakovenko at gmail.com Sat Dec 30 16:35:22 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 30 Dec 2006 23:35:22 +0200 Subject: python , Boost and straight (but complex) C code In-Reply-To: References: Message-ID: <7465b6170612301335n46c66dc8h19314f087f8b3896@mail.gmail.com> On 12/30/06, Osiris wrote: > Visual C++ build log at: > > http://213.10.133.192/BuildLog.htm It is better to ask Boost.Python related questions on it mailing list: http://mail.python.org/mailman/listinfo/c++-sig/ You should add to the link line boost_python.lib, thus you will eliminate "unresolved reference symbol" errors. If you did not build Boost.Python next page( http://boost.org/libs/python/doc/building.html ) contains pretty good explanation how to do this. http://boost.org/libs/python/doc/v2/scope.html - here you will find example how to expose my_int variable to Python. my_int has type int, so C++ code will not see changes to the variable that are done from Python. You will have to write set_my_int( x ) function to achieve this. If you are new to Boost.Python try to use Py++ - the code generator for the library. The Py++ GUI( http://tinyurl.com/ycwvwo ) will help you to start\learn Boost.Python. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From subscriber100 at rjs.org Fri Dec 29 14:35:17 2006 From: subscriber100 at rjs.org (Ray Schumacher) Date: Fri, 29 Dec 2006 11:35:17 -0800 Subject: Python-list Digest, Vol 39, Issue 465 In-Reply-To: References: Message-ID: <6.2.3.4.2.20061229105452.032fcaf0@rjs.org> An HTML attachment was scrubbed... URL: -------------- next part -------------- #Boa:Frame:Frame1 import gc from time import clock from numpy import fromstring, add, subtract, divide, where, zeros import socket import wx #import PyDShowCam import VideoCapture from StringIO import StringIO from PIL import Image def create(parent): return Frame1(parent) [wxID_FRAME1, wxID_FRAME1BUTTONCONNECT, wxID_FRAME1BUTTONPROPERTIES, wxID_FRAME1BUTTONSERVER, wxID_FRAME1BUTTONSETDARK, wxID_FRAME1BUTTONSTOP, wxID_FRAME1CHECKBOXDIFF, wxID_FRAME1PANEL1, wxID_FRAME1STATICBITMAPVIDEO, wxID_FRAME1STATUSBAR1, wxID_FRAME1TEXTCTRLADDRESS, wxID_FRAME1TOOLBAR1, wxID_FRAME1WINDOWVIDEO, ] = [wx.NewId() for _init_ctrls in range(13)] class Frame1(wx.Frame): def _init_coll_toolBar1_Tools(self, parent): # generated method, don't edit parent.AddControl(control=self.textCtrlAddress) parent.AddControl(control=self.buttonConnect) parent.AddControl(control=self.buttonStop) parent.AddControl(control=self.buttonProperties) parent.AddControl(control=self.checkBoxDiff) parent.AddControl(control=self.buttonSetDark) parent.AddControl(control=self.buttonServer) parent.Realize() def _init_coll_statusBar1_Fields(self, parent): # generated method, don't edit parent.SetFieldsCount(3) parent.SetStatusText(number=0, text='"frame:0,\t0fps"') parent.SetStatusText(number=1, text='') parent.SetStatusText(number=2, text='') parent.SetStatusWidths([200, -1, 100]) def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(278, 392), size=wx.Size(746, 377), style=wx.DEFAULT_FRAME_STYLE, title='Confer') self.SetClientSize(wx.Size(738, 350)) self.statusBar1 = wx.StatusBar(id=wxID_FRAME1STATUSBAR1, name='statusBar1', parent=self, style=0) self._init_coll_statusBar1_Fields(self.statusBar1) self.SetStatusBar(self.statusBar1) self.toolBar1 = wx.ToolBar(id=wxID_FRAME1TOOLBAR1, name='toolBar1', parent=self, pos=wx.Point(0, 0), size=wx.Size(767, 27), style=wx.TB_HORIZONTAL) self.SetToolBar(self.toolBar1) self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(0, 27), size=wx.Size(738, 303), style=wx.TAB_TRAVERSAL) self.panel1.SetBackgroundColour(wx.Colour(255, 255, 255)) self.windowVideo = wx.Window(id=wxID_FRAME1WINDOWVIDEO, name='windowVideo', parent=self.panel1, pos=wx.Point(8, 8), size=wx.Size(352, 288), style=0) self.windowVideo.SetBackgroundColour(wx.Colour(0, 0, 0)) self.textCtrlAddress = wx.TextCtrl(id=wxID_FRAME1TEXTCTRLADDRESS, name='textCtrlAddress', parent=self.toolBar1, pos=wx.Point(0, 0), size=wx.Size(100, 21), style=0, value='192.168.0.1') self.textCtrlAddress.SetToolTipString('Enter the remote address here') self.buttonConnect = wx.Button(id=wxID_FRAME1BUTTONCONNECT, label='Connect', name='buttonConnect', parent=self.toolBar1, pos=wx.Point(100, 1), size=wx.Size(60, 19), style=0) self.buttonConnect.Bind(wx.EVT_BUTTON, self.OnButtonConnectButton, id=wxID_FRAME1BUTTONCONNECT) self.buttonStop = wx.Button(id=wxID_FRAME1BUTTONSTOP, label='Stop', name='buttonStop', parent=self.toolBar1, pos=wx.Point(160, 1), size=wx.Size(49, 19), style=0) self.buttonStop.Bind(wx.EVT_BUTTON, self.OnButtonStopButton, id=wxID_FRAME1BUTTONSTOP) self.buttonProperties = wx.Button(id=wxID_FRAME1BUTTONPROPERTIES, label='Cam Properties', name='buttonProperties', parent=self.toolBar1, pos=wx.Point(209, 1), size=wx.Size(88, 19), style=0) self.buttonProperties.Bind(wx.EVT_BUTTON, self.OnButtonPropertiesButton, id=wxID_FRAME1BUTTONPROPERTIES) self.staticBitmapVideo = wx.StaticBitmap(bitmap=wx.NullBitmap, id=wxID_FRAME1STATICBITMAPVIDEO, name='staticBitmapVideo', parent=self.panel1, pos=wx.Point(374, 8), size=wx.Size(352, 288), style=0) self.checkBoxDiff = wx.CheckBox(id=wxID_FRAME1CHECKBOXDIFF, label='diff frames', name='checkBoxDiff', parent=self.toolBar1, pos=wx.Point(297, 4), size=wx.Size(70, 13), style=0) self.checkBoxDiff.SetValue(False) self.buttonSetDark = wx.Button(id=wxID_FRAME1BUTTONSETDARK, label='Dark frame', name='buttonSetDark', parent=self.toolBar1, pos=wx.Point(367, 1), size=wx.Size(75, 19), style=0) self.buttonSetDark.Bind(wx.EVT_BUTTON, self.OnButtonSetDarkButton, id=wxID_FRAME1BUTTONSETDARK) self.buttonServer = wx.Button(id=wxID_FRAME1BUTTONSERVER, label='Server', name='buttonServer', parent=self.toolBar1, pos=wx.Point(456, 0), size=wx.Size(75, 23), style=0) self.buttonServer.Bind(wx.EVT_BUTTON, self.OnButtonServerButton, id=wxID_FRAME1BUTTONSERVER) self._init_coll_toolBar1_Tools(self.toolBar1) def __init__(self, parent): self._init_ctrls(parent) self.cam = None self.buttonStop.Enable(True) self.darkFrame = None wx.InitAllImageHandlers() self.Show() def OnButtonConnectButton(self, event): self.cam = VideoCapture.Device(devnum=0, showVideoWindow=0) buff, width, height = self.cam.dev.getbuffer() buffArrayLast = fromstring(buff, 'uint8')[-1::-1].copy() im = wx.EmptyImage(width, height) self.buttonConnect.Enable(False) self.buttonStop.Enable(True) getbuffer = self.cam.dev.getbuffer darkFrame = self.darkFrame if darkFrame: darkArray = self.darkArray im_SetData = im.SetData im_Mirror = im.Mirror BitmapFromImage = wx.BitmapFromImage SetBitmap = self.staticBitmapVideo.SetBitmap SetStatusText = self.statusBar1.SetStatusText isDiff = self.checkBoxDiff.GetValue Yield = wx.Yield frame = 0 t1 = clock() while self.cam: buff, width, height = getbuffer() buffArray = fromstring(buff, 'uint8')[-1::-1].copy() if darkFrame: buffArray = where(buffArray>darkArray, subtract(buffArray, darkArray), 0) if isDiff(): im_SetData(subtract(buffArray, buffArrayLast).tostring()) buffArrayLast = buffArray.copy() else: im_SetData(buffArray.tostring()) SetBitmap(BitmapFromImage(im_Mirror())) Yield() frame += 1 if frame % 10 == 0: t2 = clock()-t1 SetStatusText(number=0, text="frame:%d,\t%.3ffps" % (frame, round(10/(t2), 3))) t1 = clock() def OnButtonStopButton(self, event): self.cam = None gc.collect self.buttonConnect.Enable(True) self.buttonServer.Enable(True) self.buttonStop.Enable(False) def OnButtonPropertiesButton(self, event): if(self.cam != None): ## explicitely remove references to the Capture device ## and run garbage collection self.cam = None gc.collect() self.SetStatusText('Device set to None') try: cam = Device(devnum=0, showVideoWindow=1) ## display the dialog-boxes which allow changing the video size cam.dev.displayCaptureFilterProperties() cam = None except: dlg = wx.MessageDialog(self, 'Cam device does not support displayCaptureFilterProperties()', 'Error', wx.OK | wx.ICON_INFORMATION) try: dlg.ShowModal() finally: dlg.Destroy() print '\'Device.displayCaptureFilterProperties\' call not done.' def OnButtonSetDarkButton(self, event): self.cam = VideoCapture.Device(devnum=0, showVideoWindow=0) buff, width, height = self.cam.dev.getbuffer() darkArray = zeros((width*height*3), 'uint8') im = wx.EmptyImage(width, height) getbuffer = self.cam.dev.getbuffer im_SetData = im.SetData im_Mirror = im.Mirror BitmapFromImage = wx.BitmapFromImage SetBitmap = self.staticBitmapVideo.SetBitmap SetStatusText = self.statusBar1.SetStatusText frame = 0 while frame<100: buff, width, height = getbuffer() #print fromstring(buff, 'uint8')[-1::-1].copy().shape, darkArray.shape darkArray = add(fromstring(buff, 'uint8')[-1::-1].copy(), darkArray) frame += 1 SetStatusText(number=0, text="frame:%d" % (frame)) im_SetData(darkArray.tostring()) self.bmp = BitmapFromImage(im_Mirror()) SetBitmap(self.bmp) #imPIL = (Image.frombuffer("RGB", (width, height), darkArray.tostring(), "raw", "RGB", 0, 1) ).transpose(Image.FLIP_LEFT_RIGHT) self.cam = None gc.collect #print darkArray[:21] #print divide(darkArray, 100).astype('uint8')[21000:21200] self.darkArray = divide(darkArray, 10).astype('uint8') #self.bmpFile = StringIO() #print dir(self.bmpFile) #im.SaveFile(self.bmpFile, wx.BITMAP_TYPE_JPEG) #self.bmp.SaveFile('temp.jpg', wx.BITMAP_TYPE_JPEG) #self.PILFile = StringIO() #imPIL.save(self.PILFile, "JPEG") def OnButtonServerButton(self, event): self.buttonStop.Enable(True) self.buttonServer.Enable(False) HOST = '' # Symbolic name meaning the local host PORT = 8888 # Arbitrary non-privileged port try: del(self.cam) except: pass self.cam = VideoCapture.Device(devnum=0, showVideoWindow=0) buff, width, height = self.cam.dev.getbuffer() buffArrayLast = fromstring(buff, 'uint8')[-1::-1].copy() im = wx.EmptyImage(width, height) self.buttonConnect.Enable(False) self.buttonStop.Enable(True) getbuffer = self.cam.dev.getbuffer darkFrame = self.darkFrame if darkFrame: darkArray = self.darkArray im_SetData = im.SetData im_Mirror = im.Mirror BitmapFromImage = wx.BitmapFromImage SetBitmap = self.staticBitmapVideo.SetBitmap SetStatusText = self.statusBar1.SetStatusText isDiff = self.checkBoxDiff.GetValue Yield = wx.Yield count = 0 while self.buttonStop.IsEnabled(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while self.buttonStop.IsEnabled(): data = conn.recv(1024) if not data: break print "Data received:" if data[:3] == 'GET': buff, width, height = getbuffer() imPIL = (Image.frombuffer("RGB", (width, height), buff, "raw", "RGB", 0, 1) ).transpose(Image.FLIP_LEFT_RIGHT) PILFile = StringIO() imPIL.save(PILFile, "JPEG") imString = PILFile.getvalue() try: conn.send("HTTP/1.0 200 OK"+"\015\012") conn.send("Server: RJS_video/0.0.1"+"\015\012") #conn.send("Content-type: text/html; charset=ISO-8859-1"+"\015\012") conn.send("Content-type: image/jpeg"+"\015\012") conn.send("Content-Length: "+str(len(imString))+"\015\012") conn.send("\015\012") conn.send(imString) except: print 'socket error' break count = count + 1 print 'len:', len(data), '\n'#, data #break else: conn.send('err') print 'err' print count, #if count == 5: #break print 'Closing connection to', addr s.close() Yield() PILFile.close() del(self.cam) def getimage(stream, intoImage=None): pass """ 0135 ##Returns a wxImage of the stream specified 0136 0137 # try to read the entire thing in one gulp 0138 data=stream.read() 0139 # save hex version for debugging 0140 # f=open(file+".hex", "w") 0141 # f.write(common.datatohexstring(data)) 0142 # f.close() 0143 0144 palettes={} 0145 0146 ### verify format 0147 0148 # header 0149 assert data[0x00:0x04]=='BCI\x00' 0150 # file length 0151 assert readlsb(data[0x04:0x08])<=len(data) # this would be == but the bci tool doesn't truncate the file! 0152 # image offset 0153 imageoffset=readlsb(data[0x08:0x0b]) 0154 assert imageoffset0 and height>0 0161 # number of objects/frames/palettes? no idea on order 0162 numitem1=readlsb(data[0x12:0x14]) 0163 numitem2=readlsb(data[0x14:0x16]) 0164 numitem3=readlsb(data[0x16:0x18]) 0165 # print "number of objects/frames/palettes? no idea on order: %d, %d, %d" % (numitem1, numitem2, numitem3) 0166 numpalettes=numitem1 # just a guess 0167 numotherthing=numitem2 # no idea what they are, possibly 'frames' as in the doc 0168 numimages=numitem3 # images, probably 'object' as in the doc 0169 # ? (0) 0170 assert readlsb(data[0x18:0x1a])==0 0171 # palette depth? 0172 bpp=readlsb(data[0x1a:0x1c]) 0173 # read the palettes 0174 offset=0x1c 0175 for _ in range(numpalettes): 0176 id=readlsb(data[offset:offset+2]) 0177 # print "palette id",id 0178 offset+=2 0179 numentries=readlsb(data[offset:offset+2]) 0180 # print "contains",numentries,"entries" 0181 offset+=2 0182 # f=open(file+".palette."+`id`+".hex", "w") 0183 # f.write(common.datatohexstring(data[offset:offset+numentries*4])) 0184 # f.close() 0185 pal=BCIPalette(data[offset:offset+numentries*4]) 0186 offset+=numentries*4 0187 palettes[id]=pal 0188 0189 0190 # some other type of object, possibly frames as in the doc 0191 for _ in range(numotherthing): 0192 # we just ignore the contents for the moment 0193 # print common.datatohexstring(data[offset:offset+0x14]) 0194 offset+=0x14 0195 0196 # images 0197 for _ in range(numimages): 0198 szdata=readlsb(data[offset:offset+4]) 0199 width=readlsb(data[offset+4:offset+6]) 0200 height=readlsb(data[offset+6:offset+8]) 0201 id1=readlsb(data[offset+8:offset+0xa]) # image id? 0202 id2=readlsb(data[offset+0xa:offset+0xc]) # palette id? 0203 offset+=0xc 0204 buf=data[offset:offset+szdata] 0205 res=zlib.decompress(buf) 0206 # f=open(file+".image."+`id1`+".hex", "w") 0207 # f.write(common.datatohexstring(res)) 0208 # f.close() 0209 0210 img=MyImage(width, height, res, palettes[id2]) 0211 0212 return img.toImage(intoImage) """ -------------- next part -------------- #!/usr/bin/env python #Boa:App:BoaApp import wx import Frame1 modules ={'Frame1': [1, 'Main frame of Application', 'Frame1.py']} class BoaApp(wx.App): def OnInit(self): wx.InitAllImageHandlers() self.main = Frame1.create(None) self.main.Show() self.SetTopWindow(self.main) return True def main(): #import psyco #psyco.full() application = BoaApp(0) application.MainLoop() if __name__ == '__main__': main() From gagsl-py at yahoo.com.ar Thu Dec 7 21:03:23 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 23:03:23 -0300 Subject: Subprocess with a Python Session? In-Reply-To: <1165504585.588297.104750@n67g2000cwd.googlegroups.com> References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> <1165493681.782704.203750@n67g2000cwd.googlegroups.com> <1165504585.588297.104750@n67g2000cwd.googlegroups.com> Message-ID: <7.0.1.0.0.20061207230203.03d17d28@yahoo.com.ar> At Thursday 7/12/2006 12:16, El Pitonero wrote: >Is there something equivalent to the "-u" option for a shell like >"bash"? In general (whether the subprocess is bash or python), how can >one make sure that once something is written into the subprocess' >stdin, the output from its stdout is fully completed and the subprocess >is ready to receive another command? Is there some kind of signal or >return status code one can capture? Not in the general case, AFAIK. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From kirk at nospam.jobsluder.net Sun Dec 10 01:57:57 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sun, 10 Dec 2006 06:57:57 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <7xk610a0kl.fsf@ruckus.brouhaha.com> <7xfybo1dlj.fsf@ruckus.brouhaha.com> Message-ID: In article <7xfybo1dlj.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Kirk Sluder writes: > > The pythonic way to do this would be to create a class that > > implements file-like behaviors: .... > > Actually the Python example can lose (e.g. leak a file descriptor > temporarily) if output.write raises an exception (prevents > output.close from running). For this reason Python recently > introduced the "with" statement: > > with output as fileLike.open(): > output.write("Hello world\n") > > Here the file gets closed automatically (by running an exit method in > the fileLike class) when the "with" block exits, whether normally or > through an exception. Ohhh, shiny! From mike.klaas at gmail.com Fri Dec 1 17:00:40 2006 From: mike.klaas at gmail.com (Klaas) Date: 1 Dec 2006 14:00:40 -0800 Subject: What are python closures realy like? In-Reply-To: References: Message-ID: <1165010439.935894.121030@l12g2000cwl.googlegroups.com> Karl Kofnarson wrote: > Hi, > while writing my last program I came upon the problem > of accessing a common local variable by a bunch of > functions. > I wanted to have a function which would, depending on > some argument, return other functions all having access to > the same variable. An OO approach would do but why not > try out closures... > So here is a simplified example of the idea: > def fun_basket(f): > common_var = [0] > def f1(): > print common_var[0] > common_var[0]=1 > def f2(): > print common_var[0] > common_var[0]=2 > if f == 1: > return f1 > if f == 2: > return f2 > If you call f1 and f2 from the inside of fun_basket, they > behave as expected, so common_var[0] is modified by > whatever function operates on it. > However, calling f1=fun_basket(1); f2 = fun_basket(2) and > then f1(); f2() returns 0 and 0. It is not the way one would > expect closures to work, knowing e.g. Lisp make-counter. > Any ideas what's going on behind the scene? Python can be read quite literally. "common_var" is a local variable to fun_basket, hence it independent among invokations of fun_basket. "def" is a statement that creates a function when it is executed. If you execute the same def statement twice, two different functions are created. Running fun_basket twice creates four closures, and the first two have no relation to the second two. The two sets close over different cell variables. If you want to share data between function invokation, you need an object which persists between calls. You can use a global variable, or a default argument. But since the value is shared everytime the function is called, I don't see the value in using a closure. I don't know lisp very well, but in my mind the whole point of closures is that you can reference a different unique cell each time. -MIke From joroy2 at gmail.com Tue Dec 5 18:14:55 2006 From: joroy2 at gmail.com (joroy) Date: 5 Dec 2006 15:14:55 -0800 Subject: pyopengl glShaderSourceARB error Message-ID: <1165360495.840814.276610@j44g2000cwa.googlegroups.com> Hi all, I think this is ctypes related but how can I call the glShaderSourceARB function? The function have this header: glShaderSourceARB( GLhandleARB(shaderObj), GLsizei(count), POINTER(arrays.GLcharARBArray)(string), GLintArray(length) ) -> None I call the function with someting like: glShaderSourceARB(self._object, 1, sourceString, 1) The error is "expected LP_GLcharArray instance instead of str" In fact I don't have any information on how to use this function. This is the last version of pyopengl available on the CVS (PyOpenGL-3.0.0a5-py2.5.egg) From felix.benner at imail.de Sat Dec 23 08:08:08 2006 From: felix.benner at imail.de (Felix Benner) Date: Sat, 23 Dec 2006 14:08:08 +0100 Subject: Question on regex In-Reply-To: References: Message-ID: Prabhu Gurumurthy schrieb: > to fix this problem, i used negative lookahead with ip pattern: > so the ip pattern now changes to: > \d{1,3}(\.\d{1,3}){3}(?!/\d+) > > now the problem is 10.150.100.0 works fine, 10.100.4.64 subnet gets > matched with ip pattern with the following result: > > 10.100.4.6 > > Is there a workaround for this or what should change in ip regex pattern. > I think what you want is that neither /d+ nor another digit nor a . follows: \d{1,3}(\.\d{1,3}){3}(?!(/\d)|\d|\.) This way 10.0.0.1234 won't be recognized as ip. Neither will 23.12. which could be a problem if an ip is at the end of a sentence, so you might want to omit that. From simon at brunningonline.net Thu Dec 14 07:22:41 2006 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 14 Dec 2006 12:22:41 +0000 Subject: tuple.index() In-Reply-To: References: Message-ID: <8c7f10c60612140422m21769fb7x4cd04d580a2ea4d1@mail.gmail.com> On 14 Dec 2006 11:24:04 GMT, Nick Maclaren wrote: > > Why doesn't the tuple type have an index method? It seems such a > bizarre restriction that there must be some reason for it. Yes, > I know it's a fairly rare requirement. It's because, philosophically, a Python tuple isn't just a read-only list. Lists are for homogeneous data, all entries being of the same 'type'. ('Type' here doesn't refer to class or anything like that - just conceptual type - what kind of thin g it is.) So, you can infer no semantic meaning from an items position in the list. Sorting makes sence,m and does looking though a list to find something - hence index(). A tuple, on the other hand, is heterogeneous. The fact that an item is the nth item is a tuple *means* something. Sorting a tuple would make no sense, even if it were possible, and you are supposed to know where in the tuple things are, so it makes no sense to search for it. -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From jpellerin at gmail.com Mon Dec 18 22:21:56 2006 From: jpellerin at gmail.com (jpellerin+nose@gmail.com) Date: 18 Dec 2006 19:21:56 -0800 Subject: python-hosting.com projects: dead? Message-ID: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> It looks to me like python hosting, aka webfaction, have shut down access to all projects hosted under their free hosting for open source python projects program. Including mine (nose). With no notice -- at least none that I received. Surprised doesn't quite cover it. Perhaps someone from python hosting can explain why this was done, why no notice was given (if it wasn't), and how those of us trying to restart our projects elsewhere can get access to our subversion repositories and trac data. JP From gagsl-py at yahoo.com.ar Thu Dec 7 16:05:26 2006 From: gagsl-py at yahoo.com.ar (gagsl-py at yahoo.com.ar) Date: 7 Dec 2006 13:05:26 -0800 Subject: Multithreaded python script calls the COMMAND LINE In-Reply-To: <1165523805.955071.246310@80g2000cwy.googlegroups.com> References: <1165523805.955071.246310@80g2000cwy.googlegroups.com> Message-ID: <1165525526.613324.145310@n67g2000cwd.googlegroups.com> On 7 dic, 17:36, "johnny" wrote: > I have python script does ftp download in a multi threaded way. Each > thread downloads a file, close the file, calls the comman line to > convert the .doc to pdf. Command line should go ahead and convert the > file. My question is, when each thread calls the command line, does one > command line process all the request, or each thread creates a one > command line process for themselves and executes the command? For some > reason I am getting "File '1' is alread exists, Do you want to > overwrite [y/n]?" I have to manually enter 'y' or 'n' for the python > script to complete. That depends on how you invoke it: os.system creates a new shell which in turn creates a new process; the spawn* functions do that directly. Anyway, if you have many conversion processes running, you should pass them unique file names to avoid conflicts. Where does the '1' name come from? If it's you, don't use a fixed name - the tempfile module may be useful. From gagsl-py at yahoo.com.ar Wed Dec 13 01:49:50 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 13 Dec 2006 03:49:50 -0300 Subject: not a big deal or anything, but, curiously: In-Reply-To: <5c1d2d910612122214w22220f3fk6c5acfd1cfca7d6b@mail.gmail.co m> References: <5c1d2d910612122214w22220f3fk6c5acfd1cfca7d6b@mail.gmail.com> Message-ID: <7.0.1.0.0.20061213032821.0403ba80@yahoo.com.ar> At Wednesday 13/12/2006 03:14, Simon Schuster wrote: >gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds) > >which should yield: 0.54460093896713613.. > >but when I ran it I got: 0.544600938967 > >looking now I see it's truncating after a certain number of decimal >places. any ideas why? Floating point numbers have finite precision so at *some* point the digits have to stop. The print statement uses str() to convert its arguments, and for a Python float that uses 12 digits. You could use repr() instead and get 17 digits: >>> print repr(gc) 0.54460093896713613 Read the Appendix B in the Python Tutorial for more info. Or look for "David Goldberg. What every computer scientist should know about floating-point arithmetic. ACM Computing Surveys, 23(1):5--48, March 1991." -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From tjreedy at udel.edu Thu Dec 14 14:37:10 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Dec 2006 14:37:10 -0500 Subject: Inconsistency in dictionary behaviour: dict(dict) not calling__setitem__ References: <1165948261.745137.88540@j72g2000cwa.googlegroups.com> <1166090687.196122.229950@n67g2000cwd.googlegroups.com> Message-ID: Final note: one of the developers ran into a similar issue with dict and has opened a discussion on pydev about how the C implementation might be changed to have derived classes act more consistently without imposing a time penalty on the normal use of dict. There might possibly be a change by 2.6 but I am not following the details. tjr From dhingra.mayank at gmail.com Fri Dec 22 02:36:42 2006 From: dhingra.mayank at gmail.com (Forced_Ambitions) Date: 21 Dec 2006 23:36:42 -0800 Subject: Script Error In-Reply-To: <1166510370.819303.94750@79g2000cws.googlegroups.com> References: <1166510370.819303.94750@79g2000cws.googlegroups.com> Message-ID: <1166773002.418760.50940@42g2000cwt.googlegroups.com> Guys any suggestions ? Could it be because of a MS patch or something as i believe i had some patching on the windows box i was running this script on. Forced_Ambitions wrote: > Hi Guys, > > I am facing a problem with a script that i had written to automate > opening a website and signing on to it. It was running fine for a long > time but all of a sudden it has stopped progressing beyond opening the > URL. I ran the code line by line on the pythonwin's IDE and it ran fine > but when i execute the whole script it gives this error: > > > Traceback (most recent call last): > File > "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", > line 307, in RunScript > debugger.run(codeObject, __main__.__dict__, start_stepping=0) > File > "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", > line 60, in run > _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) > File > "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", > line 631, in run > exec cmd in globals, locals > File "C:\Documents and > Settings\Desktop\pi\Ressurection\Dec\19\CoE.py", line 4, in ? > ie.SetTextBox(username,'txtUserId',0) > File "cPAMIE.py", line 387, in SetTextBox > doc = self._ie.Document.forms[frmName] > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line > 216, in __getitem__ > return self._get_good_object_(self._enum_.__getitem__(index)) > File "C:\Python24\Lib\site-packages\win32com\client\util.py", line > 37, in __getitem__ > return self.__GetIndex(index) > File "C:\Python24\Lib\site-packages\win32com\client\util.py", line > 56, in __GetIndex > raise IndexError, "list index out of range" > IndexError: list index out of range > > The code i was using is: > > import cPAMIE > > ie= cPAMIE.PAMIE() > > ie.Navigate ('URL') > ie.SetTextBox(username,'txtUserId',0) > ie.SetTextBox(pwd,'txtPassword',0) > ie.ClickButton('btnSubmit',0) > > Any ideas as to why am i getting this error when running the code as a > script > > Thanks in advance, > Forced From kentilton at gmail.com Mon Dec 11 23:25:25 2006 From: kentilton at gmail.com (Ken Tilton) Date: Mon, 11 Dec 2006 23:25:25 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4u6mf2F161jbqU2@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> <1165876294.938323.233380@80g2000cwy.googlegroups.com> <4u6mf2F161jbqU2@mid.individual.net> Message-ID: greg wrote: > JShrager at gmail.com wrote: > >> So if you guys would just fix >> your language by adding homogeneous syntax and all that it brings with >> it (macros, compilers, etc) we'd be happy to use your version of Lisp, >> and all its great libraries, instead of ours! :-) > > > But if we did that, it wouldn't be Python any > more, it'd be Lisp. And someone would then have to invent Python. Let Python be Python, let Lisp be Lisp. It's all good. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From caleb.hattingh at gmail.com Sat Dec 16 16:19:41 2006 From: caleb.hattingh at gmail.com (Caleb Hattingh) Date: 16 Dec 2006 13:19:41 -0800 Subject: Is there a way to push data into Microsoft Excel & Word from Python ? In-Reply-To: <458455f2$0$8219$426a74cc@news.free.fr> References: <458455f2$0$8219$426a74cc@news.free.fr> Message-ID: <1166303981.857285.156670@n67g2000cwd.googlegroups.com> The Night Blogger wrote: > Is there a way to push data to Microsoft Excel & Word from a Python > Application On Windows, it's easy after you install the win32 extensions. For example, for python: import win32com.client xl = win32com.client.Dispatch('Excel.Application') after which you can operate on "xl" (almost) as if you were coding in VBA. I have driven Excel from python a /lot/, and it works well. Paul Boddie has written a great tutorial---which includes some Outlook examples, btw---over here: http://thor.prohosting.com/~pboddie/Python/COM.html > Is this a cross platform feature ? I'll need to push data on MS Windows & > Mac OS X .... I have zero OSX experience, but 30s of googling brings up this: http://appscript.sourceforge.net/ Kevin Walzer mentions on this mailing list entry: http://mail.python.org/pipermail/python-list/2006-August/400255.html that Excel provides reasonably good support for applescript, but again, I have no idea whether these things work; I'm just doing your googling for you. Assuming applescript works, you may want to write a thin wrapper over the combination of the win32 COM interface and the applescript interface that at least lets your business logic sit in one place. The wrapper can use the right API depending on the platform it finds itself on at runtime. Regards Caleb From bearophileHUGS at lycos.com Sat Dec 9 07:41:01 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 9 Dec 2006 04:41:01 -0800 Subject: merits of Lisp vs Python In-Reply-To: <457a89f4$0$4242$4fafbaef@reader1.news.tin.it> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> <1165593798.079105.144060@80g2000cwy.googlegroups.com> <45799841$0$49201$14726298@news.sunsite.dk> <1165609509.370461.122170@73g2000cwn.googlegroups.com> <457a7ee5$0$49195$14726298@news.sunsite.dk> <457a89f4$0$4242$4fafbaef@reader1.news.tin.it> Message-ID: <1165668061.027169.73910@79g2000cws.googlegroups.com> Andrea Griffini>Is this worth investigation or it has already been suggested/tried ?< Recently some people around the net have discussed about similar ideas as a possible way to speed up Ruby interpreters a lot. Bye, bearophile From duncan.booth at invalid.invalid Wed Dec 20 07:18:20 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Dec 2006 12:18:20 GMT Subject: array, a better shell References: <1166615065.807704.12480@48g2000cwx.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > This Mathematica shell allows you to edit small programs (like 1-15 > lines of code) as input blocks, and later you can click on them and > edit them. When you press shift-enter inside a block, that small > program runs and its output goes just below it (and not at the end of > the current shell log). All the Input Blocks can be edited and run > again like that (an Input/Output number tag helps to keep things sorted > enough). Sounds pretty close to what Idle does: The Idle shell allows you to enter small programs as input blocks, and edit them while entering them. Later you can click on them and bring them back to the bottom of the input buffer for further editing (so no confusing output appearing out of order), and you can always look back at all earlier versions of the block. All the Input Blocks can be edited and run again like that. Your point was? From lars.spam at nocrew.org Wed Dec 13 02:54:56 2006 From: lars.spam at nocrew.org (Lars Brinkhoff) Date: Wed, 13 Dec 2006 08:54:56 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> Message-ID: <85odq8w7qn.fsf@junk.nocrew.org> Bill Atkins writes: > the macro is just a friendlier syntax for expressing an idea. I like that phrase! From researchbase at gmail.com Sun Dec 3 20:44:22 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Mon, 4 Dec 2006 07:14:22 +0530 Subject: problem formatting dates from text fields. In-Reply-To: <6eHch.7012$1s6.5812@newsread2.news.pas.earthlink.net> References: <6eHch.7012$1s6.5812@newsread2.news.pas.earthlink.net> Message-ID: On 04/12/06, Dennis Lee Bieber wrote: > You don't show us what format is used in the database, so there is > nothing to base a conversion on. Is it year/month/day, month/day/year; > months numeric or alpha (abbreviated or spelled out). Fields separated > by space, comma, -, :, or / > the format in the text field is dd/mm/yyyy which is perfect for what I need. but the problem as I said is to get this text into a value that can fit into a date time picker. can this be done? Krishnakant. From fredrik at pythonware.com Mon Dec 4 12:02:07 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 18:02:07 +0100 Subject: Inheritance doesn't work In-Reply-To: <45745286$0$32597$c3e8da3@news.astraweb.com> References: <45745286$0$32597$c3e8da3@news.astraweb.com> Message-ID: John Salerno wrote: > How do you get that error with that code? $ python >>> import os >>> class foo(os): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: Error when calling the metaclass bases module.__init__() takes at most 2 arguments (3 given) From felix.benner at imail.de Sun Dec 24 09:18:45 2006 From: felix.benner at imail.de (Felix Benner) Date: Sun, 24 Dec 2006 15:18:45 +0100 Subject: Help with small program In-Reply-To: <1166966360.384179.101400@48g2000cwx.googlegroups.com> References: <1166966360.384179.101400@48g2000cwx.googlegroups.com> Message-ID: smartbei schrieb: > Hello, I am a newbie with python, though I am having a lot of fun using > it. Here is one of the excersizes I am trying to complete: > the program is supposed to find the coin combination so that with 10 > coins you can reach a certain amoung, taken as a parameter. Here is the > current program: > > coins = (100,10,5,1,0.5) > anslist = [] > def bar(fin, hist = {100:0,10:0,5:0,1:0,0.5:0}): > s = sum(x*hist[x] for x in hist) > l = sum(hist.values()) > if s < fin and l < 10: > for c in coins: > if (s+c) <= fin: > hist[c] += 1 > bar(fin, hist) > hist[c] -= 1 > elif l==10 and s==fin and not hist in anslist: > #p1 > anslist.append(hist) > > bar(50) > print anslist > > The problem is that if I run it, anslist prints as [{0.5: 0, 1: 0, 10: > 0, 100: 0, 5: 0}], which doesnt even add up to 50. When I check how > many times the program has reached the #p1 by sticking a print there, > it only reaches it once, and it comes out correct. why is it that this > result is replaced by the incorrect final one? > hist is stored in anslist as a pointer only, therfore the hist[c] -= 1 operates on the same dict as is stored in the anslist. Try the following in the python interpreter: a = { 'key' : 1 } l = [a] l[0]['key'] -= 1 a instead use: anslist.append(dict(hist.items)) which will copy the dict. From Norbert.Klamann at projecthome.de Fri Dec 8 03:24:59 2006 From: Norbert.Klamann at projecthome.de (Norbert) Date: 8 Dec 2006 00:24:59 -0800 Subject: python.org not current In-Reply-To: References: <1165563043.341472.248270@j44g2000cwa.googlegroups.com> Message-ID: <1165566299.573531.143450@f1g2000cwa.googlegroups.com> On 8 Dez., 08:40, Fredrik Lundh wrote: > Norbert wrote: > > the python websitehttp://www.python.org/mentions Version 2.3.6 and > > 2.4.4 on the most prominent place. Shouldn't this be changed to 2.5.x ?you're looking at the news section: the 2.3.6 and 2.4.4 maintenance > releases were made after 2.5 was released. Did not notice that, maybe a subheding would be in order ? > > Norbert From kbk at shore.net Fri Dec 15 01:42:26 2006 From: kbk at shore.net (Kurt B. Kaiser) Date: Fri, 15 Dec 2006 01:42:26 -0500 (EST) Subject: Weekly Python Patch/Bug Summary Message-ID: <200612150642.kBF6gQ59028713@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 414 open ( +1) / 3498 closed ( +9) / 3912 total (+10) Bugs : 949 open ( +6) / 6376 closed (+12) / 7325 total (+18) RFE : 247 open ( +1) / 245 closed ( +1) / 492 total ( +2) New / Reopened Patches ______________________ C99 _Bool support for struct (2006-12-07) http://python.org/sf/1610575 opened by David Remahl BSD version of ctypes.util.find_library (2006-12-07) http://python.org/sf/1610795 opened by Martin Kammerhofer whitespace in `svnversion .` (2006-10-15) CLOSED http://python.org/sf/1577756 reopened by schmaller Enhanced tabbed pane widget (2006-12-10) http://python.org/sf/1612746 opened by Tal Einat encoding directive -- more examples (2006-12-11) http://python.org/sf/1613352 opened by Jim Jewett Write mode option for fileinput module. (2006-12-11) http://python.org/sf/1613500 opened by Anthony Roy POSIX capabilities support (2006-12-13) http://python.org/sf/1615158 opened by Matt Kern Creating dicts for dict subclasses (2006-12-14) http://python.org/sf/1615701 opened by Walter D?rwald BZ2File.seek() fails for large files (2006-12-14) http://python.org/sf/1615868 opened by Lars Gust?bel Cached globals+builtins lookup optimization (2006-12-15) http://python.org/sf/1616125 opened by Andrea Griffini Patches Closed ______________ whitespace in `svnversion .` (2006-10-15) http://python.org/sf/1577756 closed by gbrandl traceback on exit if syslog handler fails to initialize (2006-12-05) http://python.org/sf/1609407 closed by vsajip Race condition in os.makedirs (2006-12-04) http://python.org/sf/1608579 closed by gbrandl Prevent race condition in os.makedirs (2005-07-17) http://python.org/sf/1239890 closed by gbrandl os.makedirs - robust against partial path (2005-10-05) http://python.org/sf/1314067 closed by gbrandl modsupport does not use va_copy when available (2003-12-11) http://python.org/sf/858318 closed by sf-robot acknowledge signals in non-main threads (2004-12-21) http://python.org/sf/1088832 closed by loewis Patch for bug 999042. (2004-12-23) http://python.org/sf/1090482 closed by loewis socket leak in SocketServer (2004-12-30) http://python.org/sf/1093468 closed by loewis mailbox.py: check that os.fsync is available before using it (2006-11-19) http://python.org/sf/1599256 closed by akuchling New / Reopened Bugs ___________________ GUI for Python 2.3, 2.4, and 2.5 is very sluggish (2006-12-06) CLOSED http://python.org/sf/1610485 reopened by g4rlik cgi.py multipart/form-data (2006-12-07) http://python.org/sf/1610654 opened by Chui Tey \b in unicode regex gives strange results (2006-12-07) CLOSED http://python.org/sf/1611131 opened by akaihola os.path.exists("file/") failure on Solaris 9 (2006-12-07) http://python.org/sf/1611154 opened by Paul Eggert can't pickle NAN's in binary mode (2006-12-08) CLOSED http://python.org/sf/1611753 opened by Wayne Christopher sndhdr.what() does not recognize wav file (2006-12-09) http://python.org/sf/1611944 reopened by klankschap sndhdr.what() does not recognize wav file (2006-12-09) http://python.org/sf/1611944 opened by Floris van Manen builtin compile() doc needs PyCF_DONT_IMPLY_DEDENT (2006-12-09) http://python.org/sf/1612012 opened by Anthony Baxter Dictionary ordering docs are too unclear of dangers (2006-12-09) http://python.org/sf/1612113 opened by Calvin Spealman webchecker/urllib chokes on 404 pages (2006-12-10) CLOSED http://python.org/sf/1612729 opened by Fredrik Lundh lambda tuple parameter bus error (2006-12-11) CLOSED http://python.org/sf/1613059 opened by Bruce Cropley str.split creates new string even if pattern not found (2006-12-11) http://python.org/sf/1613130 opened by Antoine Pitrou pydoc info for a package doesn't list all package contents (2006-12-11) http://python.org/sf/1613479 opened by Nishkar Grover xmlrpclib ServerProxy uses old httplib interface (2006-12-12) http://python.org/sf/1613573 opened by Matt Brown recv_into not documented (2006-12-11) http://python.org/sf/1613651 opened by Eric Huss AttributesImpl does not implement __contains__ on Linux (2006-12-13) http://python.org/sf/1614387 opened by Jason Briggs dict throwing inaccurate KeyError on small tuple keys (2006-12-13) CLOSED http://python.org/sf/1614429 opened by toidinamai python-logging compatability with Zope. (2006-12-13) http://python.org/sf/1614460 opened by Simon Hookway tempile.TemporaryFile differences between linux and windows (2006-12-13) http://python.org/sf/1615275 opened by hirzel subprocess doesn't handle SIGPIPE (2006-12-14) http://python.org/sf/1615376 opened by Mark Diekhans IA64/AMD64/x64 confusion (2006-12-14) http://python.org/sf/1616109 opened by Sidnei da Silva Bugs Closed ___________ GUI for Python 2.3, 2.4, and 2.5 is very sluggish (2006-12-06) http://python.org/sf/1610485 closed by kbk \b in unicode regex gives strange results (2006-12-07) http://python.org/sf/1611131 deleted by akaihola can't pickle NAN's in binary mode (2006-12-08) http://python.org/sf/1611753 closed by mwh race in os.makedirs() (2005-06-18) http://python.org/sf/1223238 closed by gbrandl simple moves freeze IDLE (2006-10-05) http://python.org/sf/1571112 closed by kbk webchecker/urllib chokes on 404 pages (2006-12-10) http://python.org/sf/1612729 closed by gbrandl lambda tuple parameter bus error (2006-12-11) http://python.org/sf/1613059 closed by gbrandl logger.config problems with comma separated lists (2006-06-09) http://python.org/sf/1503765 closed by vsajip mailbox: Maildir.get_folder does not inherit factory (2006-11-20) http://python.org/sf/1600152 closed by akuchling dict throwing inaccurate KeyError on small tuple keys (2006-12-12) http://python.org/sf/1614429 closed by rhettinger New / Reopened RFE __________________ Py_DEBUG (2006-12-09) http://python.org/sf/1612190 opened by nitro Class Browser doesn't show internal classes (2006-12-09) http://python.org/sf/1612262 opened by Tal Einat RFE Closed __________ "".translate() docs should mention string.maketrans() (2006-11-08) http://python.org/sf/1592899 closed by gbrandl From dcikul at gmail.com Sun Dec 24 08:16:27 2006 From: dcikul at gmail.com (Dhika Cikul) Date: Sun, 24 Dec 2006 20:16:27 +0700 Subject: problem with PIPE Message-ID: <3f72d8290612240516m23c30707t3772d863244e7a3d@mail.gmail.com> Hello, I'm new in Python, i don't know my subject is correct or wrong. I have problem with my script. I want to change password with passwd password in python without user submitted anything from keyboard. I get tutorial that i must use pipe to process this. And this is my code : [code] 1. 2. #!/usr/bin/python 3. 4. import os 5. 6. COMMAND = 'passwd' 7. PASSWD = 'mypassword' 8. 9. # open a pipe to passwd program and 10. # write the data to the pipe 11. p = os.popen("%s" % COMMAND, 'w') 12. p.write(PASSWD) 13. p.write('\n') 14. p.write(PASSWD) 15. p.close() 16. [/code] but i got this error : [output] [cp at server cp]$ ./password Changing password for user cp. Changing password for cp (current) UNIX password: passwd: Authentication token manipulation error [/output] Anyone can help me how to write to pipe.. i try several method, and always fail. Thank's -- Dhika Cikul From uval at rz.uni-karlsruhe.de Wed Dec 6 11:33:27 2006 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Sch=FCle_Daniel?=) Date: Wed, 06 Dec 2006 17:33:27 +0100 Subject: how to convert a function into generator? Message-ID: Hello, I came up with this algorithm to generate all permutations it's not the best one, but it's easy enough # lst = list with objects def permute3(lst): tmp = [] lenlst = len(lst) def permute(perm, level): if level == 1: tmp.append(perm) return for i in lst: if i not in perm: permute(perm + (i,), level - 1) for item in lst: permute((item,), lenlst) return tuple(tmp) now I want to make a generator from it the idea is to get each time a new permutation I don't really understand how to handle the case when my function has an inner function which has a yield statement .. I would say that the inner function becomes an generator and stops&yields the value on each yield .. but in reality I want to propogate these values to the caller of the outer function I hope you got the idea of what I mean the code is the sketch of the idea def permute3gen(lst): lenlst = len(lst) def permute(perm, level): if level == 1: yield perm return # not sure return without a value is allowed, theoretically it could be replaces with if/else block for i in lst: if i not in perm: permute(perm + (i,), level - 1) for item in lst: yield permute((item,), lenlst) # makes generator from the outer function too this is what I get In [67]: reload permute -------> reload(permute) Out[67]: In [68]: p = permute.permute3gen(["a","b","c","d"]) In [69]: p Out[69]: In [70]: x = p.next() In [71]: y = p.next() In [72]: x Out[72]: In [73]: y Out[73]: In [74]: x.next() --------------------------------------------------------------------------- Traceback (most recent call last) /pool/PROG/python/permute/ in () : I don't understand why the generator x raises StopIteration exception I would expect that x.next() would call permute(("a",), 4) and would stop at "abcd" thanks in advance regards, Daniel From IanFHood at gmail.com Wed Dec 13 23:09:09 2006 From: IanFHood at gmail.com (Ian F. Hood) Date: Wed, 13 Dec 2006 20:09:09 -0800 Subject: how to determine Operating System in Use? References: <1166056094.751283.122760@79g2000cws.googlegroups.com> Message-ID: excellent, ty wrote in message news:1166056094.751283.122760 at 79g2000cws.googlegroups.com... > > > On Dec 13, 6:32 pm, "Ian F. Hood" wrote: >> Hi >> In typically windows environments I have used: >> if 'Windows' in os.environ['OS']... >> to prove it, but now I need to properly support different environments. >> To do so I must accurately determine what system the python instance is >> running on (linux, win, mac, etc). >> Is there a best practises way to do this? >> TIA >> Ian > > I would do this: > -------------------- > if os.name == ''posix': > linuxStuff() > elif os.name == 'nt': > windowsStuff() > elif os.name == 'os2': ... > ------------------- > os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' > > -N > > -- > http://mail.python.org/mailman/listinfo/python-list > From moishyyehuda at gmail.com Wed Dec 13 14:07:48 2006 From: moishyyehuda at gmail.com (moishyyehuda at gmail.com) Date: 13 Dec 2006 11:07:48 -0800 Subject: help: setup Python Imaging Library (PIL) for linux server Message-ID: <1166036868.389039.237210@j72g2000cwa.googlegroups.com> Hi I uploaded a pil library to my server. The problem is that I can't access the server with a command line. You see in order for the library to work you need to run setup.py and supply commands to the server when the setup.py script runs. so is there a solution to this. can I get a predone pil library (a pil library that I wont have the ru setup.py, and supply commands). Thanks in advance From deets at nospam.web.de Wed Dec 6 08:46:12 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 06 Dec 2006 14:46:12 +0100 Subject: Windows: get owner and group of a file References: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> Message-ID: <4tnvt4F14mmm6U1@mid.uni-berlin.de> kai rosenthal wrote: > Hello, > > with ls -l on windows I get > -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile > > How can I get on windows with a standard python 2.2 (without windows > extensions) the information "500" and "everyone" (owner and group)? > Also I cannot use popen('ls -l'). Are you by any chance running cygwin? That comes with ls, but windows doesn't. So you need to add the appropriate cygwin binary dirs to you path. But you probably won't want that anyway, as thus your code would only run on a machine with cygwin installed. > With > import stat > stat_info = os.lstat(myfile) > owner = "%-8s" % stat_info.st_uid > group = "%-8s" % stat_info.st_gid > I get 0 for owner and group. I'm not sure if stat-calls are fully supported on windows - the windows rights management is considerably different from unixish ones. >From the docs: """ For backward compatibility, the return value of stat() is also accessible as a tuple of at least 10 integers giving the most important (and portable) members of the stat structure, in the order st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime. More items may be added at the end by some implementations. The standard module stat defines functions and constants that are useful for extracting information from a stat structure. (On Windows, some items are filled with dummy values.) """ Note the last sentence. You should try and look what win32 has to offer. Diez From mskelton at vrms.com Mon Dec 18 12:26:16 2006 From: mskelton at vrms.com (mskelton at vrms.com) Date: Mon, 18 Dec 2006 18:26:16 +0100 Subject: REPORT Message-ID: <200612181735.kBIHZ7806294@P6416.pgirona.scs.es> *********************** A virus (WORM_MYDOOM.GEN) was detected in the file (letter.zip/letter.html .exe). Action taken = remove ***********-*********** Message could not be delivered From martin at v.loewis.de Mon Dec 4 12:47:16 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 04 Dec 2006 18:47:16 +0100 Subject: Why not just show the out-of-range index? In-Reply-To: <1165250963.660087.58410@n67g2000cwd.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> <1165250963.660087.58410@n67g2000cwd.googlegroups.com> Message-ID: <45745F24.2010406@v.loewis.de> rurpy at yahoo.com schrieb: > Thanks for explaining why the OP was rude. Having been > reading and listening to english for only a few decades > probably, I am sure the OP (and me too!) appreciates your > explanation of rudeness You mean, you don't feel insulted if somebody calls you silly? Regards, Martin From xscottg at gmail.com Sun Dec 17 21:50:56 2006 From: xscottg at gmail.com (xscottg at gmail.com) Date: 17 Dec 2006 18:50:56 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7x3b7ekk6p.fsf@ruckus.brouhaha.com> References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> Message-ID: <1166410256.785907.69140@73g2000cwn.googlegroups.com> Paul Rubin wrote: > > [...] There are programs you can write in C > but not in Lisp, like device drivers that poke specific machine > addresses. > I should assume you meant Common Lisp, but there isn't really any reason you couldn't (poke destination (peek source)) in some version of Lisp that was meant for writing device drivers (perhaps under a Lisp machine or something). SIOD actually has (%%% memref address) for peek. From antroy at gmail.com Wed Dec 20 10:00:38 2006 From: antroy at gmail.com (Ant) Date: 20 Dec 2006 07:00:38 -0800 Subject: MySQLdb, lots of columns and newb-ness In-Reply-To: References: <1166585698.732087.100750@79g2000cws.googlegroups.com> Message-ID: <1166626838.293044.4460@80g2000cwy.googlegroups.com> On Dec 20, 5:20 am, Andrew Sackville-West wrote: > > >>> values = ", ".join([escapeAndQuote(f[:-2]) for f in fields]) Obviously this is the appropriate choice since this is a database app. In general the strip() group of string methods do what you want in a safe way - assuming you don't care about whitespace: >>> s = " test \r\n" >>> s.strip() 'test' >>> s.rstrip() ' test' >>> s.lstrip() 'test \r\n' If you are concerned about whitespace: >>> s.strip("\n\r") ' test ' strips any \n's or \r's from the ends of the line. This way it doesn't matter what your line endings are - you won't be surprised by missing characters if the data dump changes for any reason. From Mark at twitchstudios.com Wed Dec 13 22:37:55 2006 From: Mark at twitchstudios.com (Mark) Date: Thu, 14 Dec 2006 14:37:55 +1100 Subject: Client side COM and Python Problem Message-ID: <4580C713.6040502@twitchstudios.com> Hey Guys, Im new to working with com but i only want to do one thing. I have activestate python and am trying to get python to run a simple function in a com enabled 3d program called 3dsmax. If i try and execute a function over the com interface it works fine as long as i dont try and run the function with an argument. when i run it with an argument like so. "o.mypingmax("test string")" it gives me an error in my client app and an error in python. please help me understand this error and what i am doing wrong? I have tried a similar script in another language and it works. but python does not like it. #code import win32com.client o = win32com.client.Dispatch("MAX.Application.8") o.mypingmax("test string") # Python Error Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ raise pythoncom.com_error, details com_error: (-2147220992, 'CONNECT_E_NOCONNECTION', None, None) #client Application error (3dsmax script output) -- Argument count error: mypingmax wanted 1, got 0 during OLE automation function call Sorry if its blindingly obvious but i just cant work out what is going on. Cheers, Mark From deets at nospam.web.de Sat Dec 30 09:57:22 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 30 Dec 2006 15:57:22 +0100 Subject: can't find a suitable application server References: Message-ID: <4vnd2iF1cpp5sU1@mid.uni-berlin.de> krishnakant Mane wrote: > hello, > I have read about zope and found it very good. > but right now I am a bit confused about one project I have just procured. > it is supposed to be a simple 3 tear application. the front end will > be a thin client which we will develop using wxpython. > We are using MySQL for the database and I need to find out a suitable > application server where I can do just the following. > 1. write my business logic which will actually be the workhorse. > 2. send data to the thin client in form of either text or lists or > tuples as required. I want my thin client just to take the data and > recieve the data. > 3. an application server that will process data coming from the thing > client. this layer will fire the queries etc. > 4. send the processed results in the forms mentioned in point number > 2 (sorry if I am redundent). > I thought zope is too heavy and complex for this task and zope is > generally used in places where the data is too dynamic and the system > very complex. > I am any ways using MySQL for the rdbms which is more than sufficient > so no need for a object oriented database like what zope has. > can any one suggest me what to do? > right now I get an impression that I must create sockets and send and > receave data through that socket to the thin client and put the actual > business logic on a seperate machine or on the database server what > ever. Use Pyro. It will make your server appear as a simple python object. It also comes with a name-service for look up of your actual server. Diez From bj_666 at gmx.net Fri Dec 29 03:39:55 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Fri, 29 Dec 2006 09:39:55 +0100 Subject: Convert Perl to Python References: Message-ID: In , ???????? ?????? wrote: > How can I convert a perl script to Python? Look what the Perl script does and then rewrite it in Python. Automatic translations between programming languages, if possible, usually result in code that is not supposed to be read by human beings. Every language has its idioms and a "literal" translation looks very odd to "native speakers" of the target language. Ciao, Marc 'BlackJack' Rintsch From kkylheku at gmail.com Fri Dec 29 23:48:58 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 29 Dec 2006 20:48:58 -0800 Subject: Anyone persuaded by "merits of Lisp vs Python"? In-Reply-To: References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> <1167357838.969945.15190@48g2000cwx.googlegroups.com> Message-ID: <1167454137.957453.71550@73g2000cwn.googlegroups.com> Steven Haflich wrote: > Ray wrote: > > Can one really survive knowing just > > one language these days, anyway? > > ???? ????? iie! chigaimas. No, I beg to differ! (Hey, I'm in right the middle of preparing my Kanji-drilling Lisp program for distribution). From sjmachin at lexicon.net Sat Dec 2 18:13:54 2006 From: sjmachin at lexicon.net (John Machin) Date: 2 Dec 2006 15:13:54 -0800 Subject: Anyone understand this syntax error? In-Reply-To: References: Message-ID: <1165101234.221465.255190@80g2000cwy.googlegroups.com> Sean Hammond wrote: > Anyone understand this? > > Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) > [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> def markdown_perl(input): > ... """Send 'input' (string) to the markdown perl script, and return > the > ... output from markdown (string). > ... > ... input: a string of markdown-formatted text, including \n's at > the end > ... of lines, that will be sent to the markdown process. > ... > ... returns: a string of valid XHTML from markdown > ... """ > ... import tempfile > ... import commands > ... file = tempfile.NamedTemporaryFile() > ... file.write(input) > ... file.flush() > ... return commands.getoutput('./markdown.pl '+file.name) > File "", line 15 > return commands.getoutput('./markdown.pl '+file.name) > ^ > SyntaxError: invalid syntax > >>> > > I don't get it. Syntax seems fine to me, just a normal string > concatenation. Superficially there is nothing wrong with it. After saving that to a file and doing the editing necessary to change it from a screen dump to a script, it loads OK on windows with Python 2.4.3 and 2.5. It is probably not complaining about the string concatenation. The caret is positioned at the start of the statement; this would indicate that the problem is on an earlier line. There was a while back a strange error that only manifested itself in very large source files (e.g. those generated by the pywin32 package's makepy routine) and could be cured by adding trailing spaces to the line before the allegedly offending line. However that seems to have gone away. My guess is that the problem is something to do with tabs/spaces or you have some other invisible character at the start of the return statement. As the text has been through two mail or news clients, the problem may have been munged away and I'm not seeing it. Two sugggestions: (1) at an interactive prompt: print repr(open("yourfile.py").readlines()) and eyeball the last few lines for monkey business. (2) e-mail somebody (like me) a zipped (i.e. e-mail-munging-proof) copy of your file. Two other comments on your code: (1) It's not wise to use "file" as a variable name; it shadows the built-in file(). Not a problem in this code but it's a bad habit that could bite you later. (2) Any good reason for flushing the file instead of closing it? HTH, John From aahz at pythoncraft.com Fri Dec 8 16:38:37 2006 From: aahz at pythoncraft.com (Aahz) Date: 8 Dec 2006 13:38:37 -0800 Subject: Snake references just as ok as Monty Python jokes/references in python community? :) References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> Message-ID: In article <1165607250.544331.124360 at j72g2000cwa.googlegroups.com>, seberino at spawar.navy.mil wrote: > >Problem is I don't know that anyone born after Elvis died gets any of >these Monty Python jokes. Who is Elvis? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Member of the Groucho Marx Fan Club From no.spam at designtools.maps.co.nz Sat Dec 16 16:06:34 2006 From: no.spam at designtools.maps.co.nz (Jim Granville) Date: Sun, 17 Dec 2006 10:06:34 +1300 Subject: How Micro-pump will change the future of computer/ mobile chips. In-Reply-To: <1166206191.003907.320530@73g2000cwn.googlegroups.com> References: <1166206191.003907.320530@73g2000cwn.googlegroups.com> Message-ID: <45845f87@clear.net.nz> studyandjobs at yahoo.com wrote: > How Micro-pump will change the future of computer/ mobile chips. FAR more hype than practical solution.... Sorry guys, this will not "change the future of computer/ mobile chips." > Engineers at Purdue University have developed a tiny "micro-pump" > cooling device small enough to fit on a computer chip that circulates > coolant through channels etched into the chip. ............. For > detail.... > http://www.studyandjobs.com/Micro_pump.html > > or > http://www.studyandjobs.com/IT_study.htm ..ahh, up goes the spam-meter -jg From gagsl-p32 at yahoo.com.ar Thu Dec 21 20:53:42 2006 From: gagsl-p32 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 21 Dec 2006 22:53:42 -0300 Subject: Displaying contents of a file using PyWin In-Reply-To: <1166719897.867134.323000@80g2000cwy.googlegroups.com> References: <1166706266.025197.199620@79g2000cws.googlegroups.com> <1166716722.937893.297670@79g2000cws.googlegroups.com> <1166719897.867134.323000@80g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061221224139.03e71a50@yahoo.com.ar> [Forwarded from python-list at ...] At Thursday 21/12/2006 13:51, MiguelS wrote: >import win32ui >from pywin.mfc import docview > >t = docview.DocTemplate() >t.OpenDocumentFile("d:/temp/music.log", True) > >This caused windows to close PythonWin. This appears to be a problem with pywin32. Using release 209 for Python 2.4 I get an Access Violation. Also I've noticed that this idiom: try: win32ui.GetApp().RemoveDocTemplate(template) except NameError: # haven't run this before - that's ok pass doesn't work anymore because RemoveDocTemplate raises a different exception now. -- 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 From duncan.booth at invalid.invalid Sat Dec 23 08:30:28 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Dec 2006 13:30:28 GMT Subject: Multi-line docstrings References: <1166879556.524218.96490@h40g2000cwb.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Duncan Booth: >> Not spuriously included: included by design, but sometimes annoying. > > Then it's a design decision I don't understand... > I think the decision is that the doc string should reflect exactly what you entered in the string. i.e. the system shouldn't tamper with it behind the scenes. From fredrik at pythonware.com Tue Dec 12 18:03:08 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Dec 2006 00:03:08 +0100 Subject: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__ In-Reply-To: References: <1165948261.745137.88540@j72g2000cwa.googlegroups.com> Message-ID: Mitja Trampus wrote: > I think what was unexpected for the OP is that dict.__init__ > does not use __setitem__ to create its internal structures. you can implement most methods on core objects in terms of other methods. picking one by random, and then complaining that other methods don't use the one you picked, strikes me as a rather naive view of how object-oriented design works in practice. From Benjamin.Barker at gmail.com Mon Dec 4 17:37:15 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 4 Dec 2006 14:37:15 -0800 Subject: MySQL from python - dropping a database IF EXISTS Message-ID: <1165271835.671807.200480@79g2000cws.googlegroups.com> Can someone explain why this might be happening: parser_beta.py:129: Warning: Can't drop database 'foobar'; database doesn't exist self.cursor.execute("DROP DATABASE IF EXISTS "+name) But the whole point about the "IF EXISTS" bit is (I thought) that it will only drop it if it exists, if it doesn't do nothing and don't throw an error. I'm using MySQL 5.024 and python 2.4.3 It still works, but the unneccesary error is annoying :-) Any ideas? Cheers, Ben From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Sun Dec 31 07:48:45 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Sun, 31 Dec 2006 13:48:45 +0100 Subject: Are all classes new-style classes in 2.4+? References: <1167566224.439844.267250@42g2000cwt.googlegroups.com> Message-ID: <4vppsjF1cm38aU1@mid.individual.net> Isaac Rodriguez wrote: > This is probably a very basic question, but I've been playing with > new style classes, and I cannot see any difference in behavior > when a declare a class as: > > class NewStyleClass(object): > > or > > class NewStyleClass: Try multiple inheritance (the order of superclass selection is different) or try using the keyword super. Regards, Bj?rn -- BOFH excuse #113: Root nameservers are out of sync From fredrik at pythonware.com Fri Dec 22 13:14:16 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 22 Dec 2006 19:14:16 +0100 Subject: Decorator for Enforcing Argument Types In-Reply-To: <1166807792.176011.170950@h40g2000cwb.googlegroups.com> References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166807792.176011.170950@h40g2000cwb.googlegroups.com> Message-ID: Peter Wang wrote: > I understand that we're all adults, but it's still nice to have the > computer tell us when we're being childish. :) like this? def accepts(*types): raise RuntimeError("don't be childish!") def returns(rtype): raise RuntimeError("don't be childish!") From vivainio at gmail.com Wed Dec 20 05:29:59 2006 From: vivainio at gmail.com (Ville Vainio) Date: 20 Dec 2006 02:29:59 -0800 Subject: IPython 0.7.3 upgrade notes In-Reply-To: <1166609906.624854.9350@79g2000cws.googlegroups.com> References: <1166609906.624854.9350@79g2000cws.googlegroups.com> Message-ID: <1166610598.843285.29770@f1g2000cwa.googlegroups.com> Ville Vainio wrote: > Something I forgot to emphasize in the announcement, knowing that not > everyone reads the release notes - if you are upgrading from a previous > version of IPython, you must either: > > - Delete your ~/ipython (or ~/_ipython) directory OR > - Run %upgrade once IPython starts. (And if you are wondering what all of this is about, due to c.l.p.announce moderator approval waitn period, see http://projects.scipy.org/ipython/ipython/wiki/Release/0.7.3 From bkhl at stp.lingfil.uu.se Sun Dec 10 10:35:49 2006 From: bkhl at stp.lingfil.uu.se (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) Date: Sun, 10 Dec 2006 16:35:49 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165764570.956203.223370@16g2000cwy.googlegroups.com> Message-ID: <87irgjkbl6.fsf@killalla.dreaming> "mystilleef" : > Better OO? You mean the one that doesn't support basic encapsulation > and is retardedly cumbersome to use? Encapsulation isn't so much a property of the language as of your data types. > There's a reason I said, I'd never use Lisp for OO not even when I'm > high. Gimme Python, Eiffel or Smalltalk anyday, not the retarded > add-on package bolted on CL. Python also lacks encapsulation, in the sense you probably mean. -- Bj?rn Lindstr?m Student of computational linguistics, Uppsala University, Sweden From jackdied at jackdied.com Tue Dec 19 13:04:38 2006 From: jackdied at jackdied.com (Jack Diederich) Date: Tue, 19 Dec 2006 13:04:38 -0500 Subject: permutations - fast & with low memory consumption? In-Reply-To: References: Message-ID: <20061219180438.GB5385@performancedrivers.com> On Tue, Dec 19, 2006 at 03:14:51PM +0100, Christian Meesters wrote: > Hi, > > I'd like to hack a function which returns all possible permutations as lists > (or tuples) of two from a given list. So far, I came up with this solution, > but it turned out to be too slow for the given problem, because the list > passed ("atomlist") can be some 1e5 items long: > [snip python] > > Does anybody know a solution which consumes less memory and is possibly > faster, perhaps using generator expressions? All my attempts so far failed. > You could try the probstat module (probstat.sourceforge.net). I use it regularly but then again I wrote it ;) On my rinky dink laptop just doing import probstat for twotup in probstat.Permutation(list('A'*10000), 2): pass takes 50 seconds. It gets much worse very quickly. A list of only a thousand A's takes .5 seconds. This is because "100 choose 2" has 9900 permutations, "1000 choose 2" has 999000, "1000 choose two" has 99990000, etc. -Jack From juanrgonzaleza at canonicalscience.com Sun Dec 10 10:10:23 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 10 Dec 2006 07:10:23 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165763423.440333.74080@79g2000cws.googlegroups.com> Kirk Sluder wrote: > In article > , > Steven D'Aprano wrote: > > > Yes. But you can't redefine 1+2 in Python, at least not without hacking > > the interpreter. Can you redefine (+ 1 2) in Lisp? > > Not without barreling through error messages about name conflicts. By LISP do you mean CL? In Scheme next (+ 1 2) --> -1 is possible. It would be possible in other dialects of LISP also From tjreedy at udel.edu Fri Dec 22 21:37:00 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 Dec 2006 21:37:00 -0500 Subject: let me simplify my question on scope of vars References: <877iwjcttj.fsf@pyenos.pyenos.org> Message-ID: "Pyenos" wrote in message news:877iwjcttj.fsf at pyenos.pyenos.org... | "code" | var=1 | class CLASS: | def METHOD1: | def METHOD2: | var+=var | return var | METHOD2() #line8 | return var | METHOD1() #line10 | "end code" | | Q1: does class CLASS inherit var=0 from line1? | Q2: does def METHOD1 inherit var=0 from line1? | Q3: does def METHOD2 inherit var=0 from line1? | Q3: does line8 return '2'? | Q4: does line10 return '2\n2'? You should find the answers yourself using the interactive interpreter or IDLE . This is the most valuable answer I can give you. tjr From duncan.booth at invalid.invalid Thu Dec 21 04:44:48 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Dec 2006 09:44:48 GMT Subject: def index(self): References: <4587017b$0$22957$426a34cc@news.free.fr> <458807cc$0$19743$426a74cc@news.free.fr> <45891cb7$0$16994$426a34cc@news.free.fr> <1166659483.225301.48550@t46g2000cwa.googlegroups.com> Message-ID: "George Sakkis" wrote: > Gert Cuykens wrote: >> > > class HelloWorld(object): >> > > @cherrypy.exposed >> > > def index(self): >> > > return "Hello World" >> >> do i have to write @cherrypy.exposed before every def or just once >> for all the def's ? and why not write something like @index.exposed ? >> >> in other words i have no idea what @ actually does i only know i have >> too write it to make it work :) Am guessing @ is something like >> prototyping in javascript but then def index is not a object but a >> method ? So that would not make sense ? >> >> oh and self stands more or less for private method right ? > > Ouch. Do you really expect to learn a language from scratch by Q&A in > a malining list ? That's a very inefficient way to spend both yours > and others' time. Do your homework first by reading one of the several > free tutorials online and come back when you have trouble with > something specific you didn't understand. > To be perfectly fair, searching for information about decorators if you don't know what they are called is kind of hard. Searching for information about the '@' character in the Python documentation doesn't lead to much. The CherryPy tutorial does at least mention this decorator, just not in any meaningful way: > Exposing objects > > CherryPy maps URL requests to objects and calls the suitable method > automatically. The methods that can be called as a result of external > requests are said to be exposed. > > Objects are exposed in CherryPy by setting the exposed attribute. This > an be done directly on the object itself: object.exposed = True. > Methods can also be exposed using a special decorator: > > Why this distinction? > > The distinction between published and exposed objects may seem silly > or unnecessary at first. By definition, all exposed objects are also > published, so why do we need to care about non-exposed objects? To the OP: > do i have to write @cherrypy.exposed before every def or just once for > all the def's ? Before every def that you wish to expose, which won't be all of them. > and why not write something like @index.exposed ? because that isn't how it works. cherrypy.exposed is a decorator, which means it is a function that takes a function as an argument modifies it in some way and returns the modified function as its result. > > in other words i have no idea what @ actually does i only know i have > too write it to make it work :) Am guessing @ is something like > prototyping in javascript but then def index is not a object but a > method ? So that would not make sense ? @expr def fn(...): ... is exactly equivalent to: def fn(...): ... fn = (expr)(fn) except that at the point when the decorator is called the function has not yet been assigned to the name 'fn'. (Also remember that def is an executable statement so it happens when the line containing the def is execfuted, and that names assigned to functions are just like other variable names and can be rebound at will.) > > oh and self stands more or less for private method right ? if you have to ask that question about 'self' you really do need to read some introductory texts on Python. Methods get passed their instance as their first parameter (usually this is implicit in the call, but it is always explicitly shown in the method) and self is simply the conventional name. Many other languages use 'this' instead of self and make the passing of 'this' implicit inside the method as well as outside. There are good reasons why it is explicit in Python, but just remember that the first parameter a method receives is always the instance and you won't go far wrong. From pavlovevidence at gmail.com Fri Dec 22 20:58:30 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 22 Dec 2006 17:58:30 -0800 Subject: One module per class, bad idea? In-Reply-To: References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> <458c489c$1@nntp.zianet.com> <1166823140.827296.92960@h40g2000cwb.googlegroups.com> <1166829929.511423.110970@h40g2000cwb.googlegroups.com> Message-ID: <1166839110.281352.138630@79g2000cws.googlegroups.com> Gabriel Genellina wrote: > At Friday 22/12/2006 20:25, Paddy wrote: > > >Are there tools out their to help with the refactoring task of > >splitting a module into two or more sections then showing what other > >files need to change? > > Usually no other files need to change. Ex: you have BigOldModule > including ClassA, ClassB and FunctionC. Move each one onto its own > module, perhaps including a subset of the original imports of BigOldModule. > Shrink BigOldModule to just: > > from ClassA import ClassA > from ClassB import ClassB > from functionC import functionC > > and maybe a few other things, so all imports from the outside remain > the same. That's all - most of the time. I wouldn't recommend this unless it's important not to change the external usage. If you're doing it just to save work in refactoring, it's a partial solution hack that'll lead to more confusion and delay a real solution even more. Carl Banks From robin at reportlab.com Fri Dec 15 12:03:42 2006 From: robin at reportlab.com (Robin Becker) Date: Fri, 15 Dec 2006 17:03:42 +0000 Subject: cxfrozen linux binaries run on FreeBSD? In-Reply-To: <4582D42C.7050207@chamonix.reportlab.co.uk> References: <1166195085.128464.294050@t46g2000cwa.googlegroups.com> <4582D42C.7050207@chamonix.reportlab.co.uk> Message-ID: <4582D56E.9070508@chamonix.reportlab.co.uk> Robin Becker wrote: > robert wrote: >> i80and wrote: >>> I haven't personally used freeze (Kubuntu doesn't seem to install it >>> with the python debs), but based on what I know of it, it makes make >>> files. I'm not a make expert, but if FreeBSD has GNU tools, freeze's >>> output _should_ be able to be compiled on FreeBSD. >> Yet do the Linux compiled cx_freeze binaries (and Python .so's) usually run directly on FreeBSD without a lot of trouble? >> I have not access to a FreeBSD setup and someone wants to know the "probability" :-) >> >>> On Dec 15, 5:52 am, robert wrote: >>>> When i freeze a python app (simple - no strange sys calls) for x86 Linux, does this stuff run well also on x86 FreeBSD? >>>> >>>> Robert > > I would guess not, but perhaps you could install one or other of the freebsd > linux compatibility layers and link your stuff to their libs etc etc. whoops, I forgot to add the relevant link http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/linuxemu.html -- Robin Becker From jm.suresh at gmail.com Sat Dec 16 08:24:28 2006 From: jm.suresh at gmail.com (jm.suresh@no.spam.gmail.com) Date: 16 Dec 2006 05:24:28 -0800 Subject: catching exceptions In-Reply-To: References: <1166270092.297610.19890@n67g2000cwd.googlegroups.com> Message-ID: <1166275468.140672.275010@t46g2000cwa.googlegroups.com> Steven D'Aprano wrote: > On Sat, 16 Dec 2006 03:54:52 -0800, jm.suresh at no.spam.gmail.com wrote: > > > Hi, In the following program, I have a class Test which has a property > > x. Its setx function gets a string value and converts it into a float > > and stores into it. > > [snip code] > > Python isn't Java. Are you sure you need properties? I do not know Java. But, object.x = value looks much better than object.set_x(value) . Is there any harm in doing it, provided I have to do more than just storing the value. > > > > I am looking for a way to call func1's exception handler also. > > Basically I want to have the class's error handler as the basic text > > based one, and in the calling side, If I have gui, I will pop-up a > > window and say the error message. > > One solution is to remove the exception handling inside the class and > > leave the entire thing to the caller (software people call this > > client?) side -- if the caller has access to gui it will use gui or > > else will print the message. Any other way? > > The exception is consumed by the try...except block inside the class, > so func1 never sees the exception. It might as well not exist. > > Generally, you should keep your class as simple as possible. It shouldn't > try to manage any exception it can't recover from. In your case, the class > can't recover from a failure of float(strvalue), so it shouldn't consume > the exception. Two ways of doing that: > > def _setx(self, strvalue): > self._x = float(strvalue) # just let the exception propagate > > or > > def _setx(self, strvalue): > try: > self._x = float(strvalue) > except ValueError: > raise SomeError('could not set x attribute to %s' % strvalue) > > where SomeError should be either ValueError or possibly some custom > exception (say, MyClassException). > > In either case, the error handling is separate from the object that > generates the error. And that is as it should be. Now your class can > remain the same, no matter how the rest of your program handles the > exception. > > By the way, if you want your class to generate warnings, perhaps you > should investigate the Warnings module: > > import warnings > help(warnings) I will go through it. Thanks a lot. > > > > -- > Steven. From Benjamin.Barker at gmail.com Wed Dec 27 13:12:10 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 27 Dec 2006 10:12:10 -0800 Subject: DOS, UNIX and tabs Message-ID: <1167243129.972618.132520@48g2000cwx.googlegroups.com> Hi, I have a python script on a unix system that runs fine. I have a python script on a windows system that runs fine. Both use tabs to indent sections of the code. I now want to run them on the same system, actually in the same script by combining bits and pieces. But whatever I try my windows tabs get converted to spaces when I transfer it to the unix system and the interpreter complains that the indentation style is not consistant throughout the file. Short of going through 350 lines of code and manually replacing spaces with tabs what an I do? I'm thinking there surely must be a simple solution I have missed here! Cheers, Ben From pkarjala at paju.oulu.fi Tue Dec 12 03:27:01 2006 From: pkarjala at paju.oulu.fi (Pekka Karjalainen) Date: Tue, 12 Dec 2006 08:27:01 +0000 (UTC) Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <7xslfmju4g.fsf@ruckus.brouhaha.com> <7xodqa6ixv.fsf@ruckus.brouhaha.com> Message-ID: In article <7xodqa6ixv.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >Marc 'BlackJack' Rintsch writes: >> So there seems to be something macro-like for Haskell. > >I think that's some kind of proposed or experimental Haskell feature, >not in the current standard, but I'm not sure. I'm barely even a >newbie with Haskell. It's called Template Haskell. http://www.haskell.org/th/ "Template Haskell is an extension to Haskell 98 that allows you to do type-safe compile-time meta-programming, with Haskell both as the manipulating language and the language being manipulated." There is an experimental implementation in new versions of GHC. Follow-ups set to comp.lang.haskell in case anyone wants to discuss it. I claim no understanding of it yet. Better figure out ordinary Haskell first... From http Sat Dec 9 09:14:30 2006 From: http (Paul Rubin) Date: 09 Dec 2006 06:14:30 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <878xhhkwsq.fsf@snobis.de> Message-ID: <7xlklhb1h5.fsf@ruckus.brouhaha.com> Stefan Nobis writes: > Intuitive interfaces (GUI, languages,...) are an urban legend, pure > illusion. You have to do hard work and practice to understand them. Well if you write enough code in general, the principles stick with you. What I found with Perl was that after not using it for a while, I completely forgot it. I mean the principles were still the same, but making any sense of the code depended on remembering a lot of detail which had left me. Python and C are not so much like that. Lisp is somewhere in between. From jameshcunningham at gmail.com Wed Dec 13 23:10:50 2006 From: jameshcunningham at gmail.com (James Cunningham) Date: Wed, 13 Dec 2006 23:10:50 -0500 Subject: how to determine Operating System in Use? References: <1166056094.751283.122760@79g2000cws.googlegroups.com> Message-ID: <2006121323105016807-jameshcunningham@gmailcom> On 2006-12-13 19:28:14 -0500, nanjundi at gmail.com said: > > > On Dec 13, 6:32 pm, "Ian F. Hood" wrote: >> Hi >> In typically windows environments I have used: >> if 'Windows' in os.environ['OS']... >> to prove it, but now I need to properly support different environments. >> To do so I must accurately determine what system the python instance is >> running on (linux, win, mac, etc). >> Is there a best practises way to do this? >> TIA >> Ian > > I would do this: > -------------------- > if os.name == ''posix': > linuxStuff() > elif os.name == 'nt': > windowsStuff() > elif os.name == 'os2': ... > ------------------- > os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' > > -N Bearing in mind, of course, that Mac will return "posix", too. And Cygwin might. Erg. Best, James From philip.armitage at gmail.com Sun Dec 10 11:30:21 2006 From: philip.armitage at gmail.com (philip.armitage at gmail.com) Date: 10 Dec 2006 08:30:21 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xac1wr7t9.fsf@ruckus.brouhaha.com> Message-ID: <1165768221.753809.4270@f1g2000cwa.googlegroups.com> On Dec 10, 12:28 am, a... at pythoncraft.com (Aahz) wrote: >And that is why I will never write Lisp. I loathe Emacs. Me too. So if that's what's stopping you then you might be interested to hear that when I moved my free time programming from Python to Lisp it took only a weekend to learn enough of the language to code up a little Lisp editor. It's funny that I was able to do this given what I've now learned from this thread: - Lisp is only used for research (but I'm not an academic) - Lisp is hard to learn (because of all those parenthesis) - There's no practical libraries available (so how did I do it so fast?) Phil From sturlamolden at yahoo.no Sat Dec 30 23:27:30 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 30 Dec 2006 20:27:30 -0800 Subject: Wow, Python much faster than MatLab In-Reply-To: References: <5bdf5$45969f9c$d443bb3a$14067@news.speedlinq.nl> <1167534599.274429.58550@i12g2000cwa.googlegroups.com> Message-ID: <1167539250.631900.255930@i12g2000cwa.googlegroups.com> Wensui Liu wrote: > doing. However, that is not the fault of excel/spss itself but of > people who is using it. Yes and no. I think SPSS makes it too tempting. Like children playing with fire, they may not even know it's dangerous. You can do an GLM in SPSS by just filling out a form - but how many social scientists or MDs know anything about general linear models? The command line interface of MySQL, SAS, Matlab and R makes an excellent deterrent. All statistical tool can be misused. But the difference is accidental and deliberate misuse. Anyone can naviagte a GUI, but you need to know you want to do an ANOVA before you can think of typing "anova" on the command line. You mentioned use of Excel as database. That is another example, although it has more to do with data security and integrity, and sometimes protection of privacy. Many companies have banned the use of Microsoft Access, as employees were building their own mock up databases - thus migrating these Access databases to an even worse solution (Excel). Sturla Molden From Divyap at amdale.com Tue Dec 19 09:45:34 2006 From: Divyap at amdale.com (Divya Prakash) Date: Tue, 19 Dec 2006 20:15:34 +0530 Subject: getting subchild of a tree through xerces Message-ID: <20061219144546.091461E4010@bag.python.org> Hi I m able to parse xml file using xerces as well as JAXP but I am unable to parse the sub- child of my tree Eg : ...(not able to parse this) But I m unable to parse the child of class"hello" .but I m able to parse the .sibling of class What should I do... Regards Divya -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Mon Dec 4 02:55:57 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 08:55:57 +0100 Subject: Video stream server In-Reply-To: <1165218527.632366.290350@j44g2000cwa.googlegroups.com> References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> <1165218527.632366.290350@j44g2000cwa.googlegroups.com> Message-ID: Lad wrote: > If I use the YOUTUBE.com server , I would have to connect to THEIR > computers whenever a user will come to MY website to play a video > stream on MY website. Is it so? no, your user's browser would have to connect to their computers: http://www.youtube.com/t/help_cat11 but I think you're missing the point; you need to provide more information about your specific requirements than just "a HTML page that links to a video file". like, say, in what way this is related to Python, what software you're using today, what kind of videos we're talking about, etc. From bj_666 at gmx.net Tue Dec 5 17:38:29 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Tue, 05 Dec 2006 23:38:29 +0100 Subject: About the 79 character line recommendation References: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> Message-ID: In <1165341320.094491.55480 at n67g2000cwd.googlegroups.com>, Steve Bergman wrote: > While I'm on this general topic, the guide mentions a pet peeve about > inserting more than one space to line up the "=" in assignment > statements. To me, lining them up, even if it requires quite a few > extra spaces, helps readability quite a bit. Comments? That may help readability a little bit but if one of the lines will be changed the other lines have to be changed too which results in a diff that masks the "real" change a bit. If just one line changes it's easier to read and follow diffs from version control systems. Ciao, Marc 'BlackJack' Rintsch From lestermosley at gmail.com Sun Dec 24 04:48:00 2006 From: lestermosley at gmail.com (Lester Mosley) Date: 24 Dec 2006 01:48:00 -0800 Subject: consequence and life In-Reply-To: References: Message-ID: <1166953680.366942.96730@48g2000cwx.googlegroups.com> I alway wondered if you are smelling a flower in a dream while on some crazy herbal medication. are you smelling the flower that is in the drug or a a flower that you once smelled when you were three years old on your daddy's knee ofr when you were bent over in the park looking for your lost keys. marika wrote: > 'The mind can make > > Substance, and people planets of its own > > With beings brighter than have been, and give > > A breath to forms which can outlive all flesh.' > > > > Byron - 'The > Dream' 1816 st.1 From fredrik at pythonware.com Tue Dec 12 05:29:36 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Dec 2006 11:29:36 +0100 Subject: Avoiding "invalid literal for int()" exception In-Reply-To: <1165918314.967089.99200@n67g2000cwd.googlegroups.com> References: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> <1165918314.967089.99200@n67g2000cwd.googlegroups.com> Message-ID: Gabriel Genellina wrote: >>> elif uniList[0].isdigit(): >> >> The last does not work. Not only that it accepts numbers greater than 9 >> because it checks if the whole string consists of digits, it also accepts >> u'??' and other unicode digits. > > Oh, I didn't know that last part! Thanks. > I get a bit confused by the [0], thinking it was checking a single > character. if you really want to use isdigit(), writing uniList[0].encode("ascii", "ignore").isdigit() should solve the unicode issue, I think. From not-a-real-email-address at not-a-real-domain.com Sun Dec 17 21:53:24 2006 From: not-a-real-email-address at not-a-real-domain.com (Bill Atkins) Date: Sun, 17 Dec 2006 21:53:24 -0500 Subject: merits of Lisp vs Python References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: >> In fact, all previously correct programs continue to work as before, >> and in addition, some hitherto incorrect programs become correct. >> That's an increase in power: new programs are possible without losing >> the old ones. > > There's more to power than making more programs possible. We also > want to be able to distinguish correct programs from incorrect ones. > Lisp has the power to eliminate a large class of pointer-related > errors that are common in C programs, so Lisp is more powerful than C > in that regard. Increasing the number of programs one can write in > the unfounded hope that they might be correct is just one way to > increase power. You can sometimes do that by adding features to the > language. Increasing the number of programs you can write that are > demonstrably free of large classes of errors is another way to > increase power. You can sometimes do that by REMOVING features. > That's what the Lisp holdouts don't seem to understand. > >> Right. GC gets rid of /program errors/. Pure functional programming >> gets rid of /programs/. > > GC also gets rid of programs. There are programs you can write in C > but not in Lisp, like device drivers that poke specific machine > addresses. I'm sure this would be news to the people who wrote the operating system for the Lisp machine. What makes you think that a Lisp implementation couldn't provide this? -- There are three doors. Behind one is a tiger. Behind another: the Truth. The third is a closet... choose wisely. (remove-if (lambda (c) (find c ";:-")) "a;t:k-;n-w at r;p:i-.:e-d:u;") From jeffrey.aylesworth at gmail.com Fri Dec 8 17:17:07 2006 From: jeffrey.aylesworth at gmail.com (jeff) Date: 8 Dec 2006 14:17:07 -0800 Subject: Anyone use GD with pyhton? Message-ID: <1165616227.906934.306860@n67g2000cwd.googlegroups.com> could somebody explain to me how to install (or compile) GD for linux, so that it works in pyhton? From filipwasilewski at gmail.com Tue Dec 12 11:38:41 2006 From: filipwasilewski at gmail.com (Filip Wasilewski) Date: 12 Dec 2006 08:38:41 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165941521.849053.284110@j72g2000cwa.googlegroups.com> Jon Harrop wrote: > Filip Wasilewski wrote: > > Besides of that this code is irrelevant to the original one and your > > further conclusions may not be perfectly correct. Please learn first > > about the topic of your benchmark and different variants of wavelet > > transform, namely difference between lifting scheme and dwt, and try > > posting some relevant examples or use other topic for your benchmarks. > > Your lifting implementation is slightly longer and slower than the > non-lifting one but its characteristics are identical. For n=2^25 I get: Jon, both Python and Matlab implementations discussed here use the lifting scheme, while yours is a classic convolution based approach. These are two *different* algorithms for computing wavelet transforms. Although they have similar names and give similar results, it does not mean you can use them interchangeably in one benchmark! It just does not make sense. What's more, taking only very big input 'n' gives only very limited information about true performance. How do you think who is faster, a sprinter or a long distance runner? If you want to draw objective conclusions about algorithm implementation you should measure timing and memory usage characteristic for different input lengths. This will also give you some idea about call overhead and possible memory bandwidth influence. For example, the 4-tap db2 lifting transform should be about 50% faster than the one using subband filtering. That's theory. In practice, due to specific memory usage, the speedup gained with reduction of number of arithmetic operations is easily wasted by huge cache miss overhead (C implementation, measured on x86 architecture) for arrays which don't fit entirely in the CPU cache. See my point? > 1.88s C++ (816 non-whitespace bytes) > 2.00s OCaml (741 b) > 2.33s F# (741 b) > 9.83s Your Python (1,002 b) > > The original python was 789 bytes. Is the byte count a standard measure you apply to describe code quality? I don't think you would be much happier to see totally obfuscated golf one-liners. > > Neglecting this issues, I wonder if it is equally easy to juggle > > arbitrary multidimensional arrays in a statically typed language and do > > operations on selected axis directly from the interactive interpreter > > like in the NumPy example from my other post - > > http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 ? > > I don't know much OCaml so it would be great if you could elaborate on > > this. > > It is probably just as easy. Instead of dynamic typing you have parametric > polymorphism. If you want to make your function generic over arithmetic > type then you can pass in the arithmetic operators. Probably? Using the interactive interpreter, how can I easily create two n-dimensional arrays of arbitrary data type, add them and multiply by 17? > >> In this specific context (discrete wavelet transform benchmark), I'd have > >> said that speed was the most important thing after correctness. > > > > Not necessarily, if you are doing research with different kinds of > > wavelets and need a general, flexible and easily adaptable tool or just > > the computation speed is not considered a bottleneck. > > Brevity is probably next. Memory usage, development time, cost, portability, scalability, readability, level of abstraction, usage experience and many many others, not necessarily in this order. I do not intend getting into advocacy of any specific language or feature here. I just prefer fair comparisons and clean use cases instead of marketing like that and I don't believe anyone will buy your story about OCaml superior brevity after seeing one fairly irrelevant loop with few arithmetic operations as a killer argument. > > Please don't make this discussion heading towards `what is the fastest > > way of doing d4 transform and why OCaml rules` instead of `what is the > > optimal way of doing things under given circumstances and still have a > > free afternoon ;-)`. > > Comments like that seem to be based on the fundamental misconception that > writing C++ like this is hard. Not harder than writing a loop in bazillion of other languages. When developing software do you only count time spent on typing because you are idle during build process? > Here's my complete OCaml: ... > and C++: > #include ... You didn't mention your platform and compiler settings. Using vector at() method instead of plain C/C++ array indexing increases the timings by factor of ~1.5 to 10 or more (GCC, MSVC), depending on the optimizations set, so it doesn't seem to be the best possible solution. I was also unable to run your OCaml example for n >= 2^21 (win32, out of the box OCaml installation). Is there some 16MB memory limit imposed on Array? # let q = Array.make (1 lsl 21) 0.0;; Exception: Invalid_argument "Array.make". cheers, fw From Eric_Dexter at msn.com Fri Dec 1 20:38:05 2006 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: 1 Dec 2006 17:38:05 -0800 Subject: Take the $million challenge: Prove 911 conspriracy theorists are wrong In-Reply-To: <1165000252.255347.178950@73g2000cwn.googlegroups.com> References: <1165000252.255347.178950@73g2000cwn.googlegroups.com> Message-ID: <1165023485.745502.193120@j44g2000cwa.googlegroups.com> The proper edicate would be to write software in python and then link to your point of view. It is common practice in music software. I tend of think of you like ufo people, if there is a conspiracy of some sort they use you to discredit it. https://sourceforge.net/projects/dex-tracker http://www.dexrow.com st911 at rock.com wrote: > I found this nice dialog on the internet: > ===================================== > > > Well, if you want to convice me, just answer these questions: > > If you can prove that the official explanation is correct, what's > keeping > you from collecting a MILLION dollars? Even if you're too wealthy to > bother, you could donate the proceeds to the Aryan Nation or the John > Birch > Society. > > > 1. How much explosives were used and what type? > > Thermate/thermite have been discovered in chemical tests, and evidence > of > its use is plainly visible in photographic an video evidence from the > WTC > buildings on 9/11. Thermate does not cause millions of tones of > concrete to > become pulverized into dust in mid-air (as video evidence clearly > shows), so > another high-energy explosive must have also been used. Now that we > have > positive proof that explosives were used, and once the secondary > compounds > have been discovered, the quantities and placement can be estimated > from > examinations of the video and photo evidence. > > > 2. How many people were needed to prepare the building for demolition? > > Irrelevant to the established fact that explosives were used. Will be > determined in the new investigation. BTW: It's "buildings," not > "building." > Did you realize that *three* WTC towers collapsed on 9/11/01, despite > only 2 > buildings being hit by jets? Most Americans don't realize this obvious > fact. Why? > > > 3. How long did it take to prepare the buildings for demolition? > > Irrelevant to the established fact that explosives were used. Once the > identities of the conspirators are discovered in a new investigation, > the > timeline can be established. (That's what investigators do.) > > > 4. How many people had to be bribed and how much were they bribed to > > keep silent about the preparations? > > Irrelevant to the established fact that explosives were used. Those > conspirators (whether bribed or not) that are still alive must be > discovered > and convicted for their crimes, which may include conspiracy to commit > treason. The only way to bring the criminals to justice is to open a > new > investigation which will examine *all* relevant evidence, including > sequestered videos, audio tapes, and classified documents. > > Everybody with an IQ above room temperature knows that the 9/11 > Commission > report was a whitewash, which didn't even attempt to lay blame at the > feet > of military and civilian officials who were asleep at the wheel on > 9/11/01. > It proves that Bush is not serious about national security. From jonc at icicled.net Thu Dec 14 18:01:05 2006 From: jonc at icicled.net (Jonathan Curran) Date: Thu, 14 Dec 2006 17:01:05 -0600 Subject: Strange return value from SOAP call In-Reply-To: <4581c010$0$15451$88260bb3@free.teranews.com> References: <4581c010$0$15451$88260bb3@free.teranews.com> Message-ID: <200612141701.05394.jonc@icicled.net> Toby, Strange stuff, I just tried it out myself and got flattened lists for both examples that you pasted. Maybe the answer to this could lie in the documentation provided in the source of SOAPpy: simpleTypes.txt & complexTypes.txt There are a few examples in there that show how to serve/retrieve actual data structures. I don't know all the details but SOAPpy is an incomplete library from what I've read. It works for me though (for now anyway) b/c I only use simple single dimensioned arrays. Let me know if you make any progress. Jonathan Curran -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Thu Dec 28 04:54:00 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Dec 2006 09:54:00 GMT Subject: BeautifulSoup bug when ">>>" found in attribute value References: <1167296561.186339.65610@79g2000cws.googlegroups.com> Message-ID: "Anne van Kesteren" wrote: >> Mind you, the sentence before that says 'should' for quoting < >> characters which is just plain silly. > > For quoted attribute values it isn't silly at all. It's actually part > of how HTML works. > Yes, but the sentence I was complaining about isn't talking specifically about attribute values. It says: > Authors wishing to put the "<" character in text should use "<" > (ASCII decimal 60) to avoid possible confusion with the beginning of a > tag (start tag open delimiter). Not requiring "<" to be quoted in text is, IMHO, silly. However I fully admit that all the browsers I tried will happily accept < followed by a space character as not starting a tag. From jon at ffconsultancy.com Tue Dec 5 07:36:38 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 05 Dec 2006 12:36:38 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> Message-ID: <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> Filip Wasilewski wrote: > Besides of that this code is irrelevant to the original one and your > further conclusions may not be perfectly correct. Please learn first > about the topic of your benchmark and different variants of wavelet > transform, namely difference between lifting scheme and dwt, and try > posting some relevant examples or use other topic for your benchmarks. Your lifting implementation is slightly longer and slower than the non-lifting one but its characteristics are identical. For n=2^25 I get: 1.88s C++ (816 non-whitespace bytes) 2.00s OCaml (741 b) 2.33s F# (741 b) 9.83s Your Python (1,002 b) The original python was 789 bytes. > Neglecting this issues, I wonder if it is equally easy to juggle > arbitrary multidimensional arrays in a statically typed language and do > operations on selected axis directly from the interactive interpreter > like in the NumPy example from my other post - > http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 ? > I don't know much OCaml so it would be great if you could elaborate on > this. It is probably just as easy. Instead of dynamic typing you have parametric polymorphism. If you want to make your function generic over arithmetic type then you can pass in the arithmetic operators. >> 0.56s C++ (direct arrays) >> 0.61s F# (direct arrays) >> 0.62s OCaml (direct arrays) >> 1.38s OCaml (slices) >> 2.38s Python (slices) >> 10s Mathematica 5.1 >> >> Note that all implementations are safe (e.g. C++ uses a.at(i) instead of >> a[i]). > > So why not use C++ instead of all others if the speed really matters? > What is your point here? 1. Benchmarks should not just include two inappropriate languages. 2. Speed aside, the other languages are more concise. > Could you please share full benchmark code, so we could make > conclusions too? I'll paste the whole programs at the end... > I would like to get to know about your benchmark > methodology. I wonder if you are allocating the input data really > dynamically or whether it's size is a priori knowledge for the > compiler. The knowledge is there for the compiler to use but I don't believe any of them exploit it. >> In this specific context (discrete wavelet transform benchmark), I'd have >> said that speed was the most important thing after correctness. > > Not necessarily, if you are doing research with different kinds of > wavelets and need a general, flexible and easily adaptable tool or just > the computation speed is not considered a bottleneck. Brevity is probably next. > Language speed is a great advantage, but if it always was the most > important, people would talk directly to the CPUs or knit DSP chips in > theirs backyards whenever they need to solve a calculation problem. Sure. > Please don't make this discussion heading towards `what is the fastest > way of doing d4 transform and why OCaml rules` instead of `what is the > optimal way of doing things under given circumstances and still have a > free afternoon ;-)`. Comments like that seem to be based on the fundamental misconception that writing C++ like this is hard. > Different tasks need different, well-balanced > measures. Neither Python nor OCalm nor any other language is a panacea > for every single problem. Absolutely. OCaml is as good as the next (compiled) language in this case. Python and Matlab seem to be particularly bad at this task. Here's my complete OCaml: let a = sqrt 3. and b = 4. *. sqrt 2. let h0, h1, h2, h3 = (1. +. a) /. b, (3. +. a) /. b, (3. -. a) /. b, (1. -. a) /. b let g0, g1, g2, g3 = h3, -.h2, h1, -.h0 let rec d4_aux tmp a n = let n2 = n lsr 1 in for i=0 to n2-2 do tmp.(i) <- a.(i*2)*.h0+.a.(i*2+1)*.h1+.a.(i*2+2)*.h2+.a.(i*2+3)*.h3; tmp.(i+n2) <- a.(i*2)*.g0+.a.(i*2+1)*.g1+.a.(i*2+2)*.g2+.a.(i*2+3)*.g3; done; tmp.(n2-1) <- a.(n-2)*.h0 +. a.(n-1)*.h1 +. a.(0)*.h2 +. a.(1)*.h3; tmp.(2*n2-1) <- a.(n-2)*.g0 +. a.(n-1)*.g1 +. a.(0)*.g2 +. a.(1)*.g3; Array.blit tmp 0 a 0 n; if n > 4 then d4_aux tmp a (n lsr 1) let d4 a = let tmp = Array.make (Array.length a) 0. in d4_aux tmp a (Array.length a) let () = print_endline "Generating test data..."; let x = Array.init (1 lsl 25) (fun _ -> Random.float 1.) in print_endline "Benchmarking..."; let t1 = Sys.time() in ignore(d4 x); Printf.printf "Elapsed time is %.6f seconds\n" (Sys.time() -. t1) and C++: #include #include #include #include using namespace std; double a = sqrt(3), b = 4 * sqrt(2); double h0 = (1 + a) / b, h1 = (3 + a) / b, h2 = (3 - a) / b, h3 = (1 - a) / b; double g0 = h3, g1 = -h2, g2 = h1, g3 = -h0; void d4(vector &a) { vector tmp(a.size()); for (int n = a.size(); n >= 4; n >>= 1) { int half = n >> 1; for (int i=0; i a(1 << 25); for (int i=0; i hello all, I seam to have noticed this a bit late but it appears to me that tkinter is being used very widely for gui development on all platform? is that right? since fredric lundh has written a very good introduction to tkinter (was that just an intro?), I have got keen interest to know the following. may be fredric himself might put some light on these points. 1. I seriously don't intend to start a flame war but does tkinter stand up to the standards of heavy gui development? can I have an entire mdi application working fine with tkinter? I know wxpython can do it and I have heard enough about pyqt, but tkinter seams to be very rich in gui objects. 2. as usual I always look out for accessibility when it comes to gui design. will tkinter be useful for blind people? I mean, are gui apps in tkinter accessible on windows? 3. I don't know if I need any thing else as dependencies on my windows machine. I am using python24 and I did not find any thing about installation in the introduction to tkinter. can some one give me the process of installing tkinter and all necessary things? 4. is tkinter absolutely compatible with windows gui? does it call on native api for native look and feel? in that case I think accessibility issue is automatically solved. I am looking out gui library for some serious application development. one is an erp system and the other is a customer relation management system. so I am confused between wxpython pyqt and now tkinter. out of the 3 I only found qt talking extencively about accessibility, but did not find a way to install qt in the first place. I could not compile qt nor did I find any run-time dlls for mingw so that I can use it out of the box. wxpython is the poorest in documentation and tkinter seams to be best at that. please give me some advice. thanking all. Krishnakant. From gerard.blais at gmail.com Fri Dec 22 10:30:32 2006 From: gerard.blais at gmail.com (Gerry) Date: 22 Dec 2006 07:30:32 -0800 Subject: PyExcelerator: how to set colours? Message-ID: <1166801432.240441.178000@i12g2000cwa.googlegroups.com> I'd like some cell to be a Blue "ABCDE". Here's come code thatv tries various values for pattern_for_colour and font.colour_index, to no avail. Can anyone suggest the right way to set colours? Thanks! Gerry ====================== from pyExcelerator import * w = Workbook() ws = w.add_sheet('alpha') style = XFStyle() fore_colour = style.pattern.pattern_fore_colour back_colour = style.pattern.pattern_back_colour ws.write (1, 1, "fore_colour") ws.write (1, 2, fore_colour) ws.write (2, 1, "back_colour") ws.write (2, 2, back_colour) text = "ABCDE" row = 5 for offset in range(-32,512): row += 1 style.font.colour_index = fore_colour + offset ws.write(row,3, fore_colour + offset, style) ws.write(row,5,text, style) style.pattern.pattern_fore_colour = fore_colour + offset ws.write(row,6,text, style) w.save('test.xls') ===================== shows no colour variation for any of these values of offset. From inq1ltd at verizon.net Fri Dec 29 17:33:17 2006 From: inq1ltd at verizon.net (jim-on-linux) Date: Fri, 29 Dec 2006 17:33:17 -0500 Subject: Easiest way to print from XP/DOS. Message-ID: <200612291733.17480.inq1ltd@verizon.net> This is the situation I'm in. I've built a single file utility using py2exe. I zip the dist directory and send it to the client. For clients that use win95, win98 machines, They unpack the zip file and run the exe. The utility creates a text file that is sent to the printer with the statement below. os.system('type ' +FileName+ ' >prn'), and the file prints. But, from an xp machine if I try to print using the same statement, I get a question on the dos screen which reads something like this; Which program authorized this operation? Since I don't have an xp machine, the statement above may not be exact, but you get the idea. The question I have is, first is there any way to work around the question asked by the xp machine using python. If not, I may have to register the package in xp, if registering the utility the only way, which package is the simplest to use. Also, if the utility is registered in xp, will the same statement send the file to the printer as it does in win98. jim-on-linux From ptmcg at austin.rr._bogus_.com Fri Dec 1 11:22:20 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 01 Dec 2006 16:22:20 GMT Subject: good documentation about win32api ?? References: <1164988151.675036.308920@j44g2000cwa.googlegroups.com> Message-ID: <0FYbh.9879$_H5.1960@tornado.texas.rr.com> "__schronos__" wrote in message news:1164988151.675036.308920 at j44g2000cwa.googlegroups.com... And the question is: ?Anybody knows where can I find good documentation about win32api? There is the book, Python Programming on WIN32, by Mark Hammond. http://www.amazon.com/Python-Programming-WIN32-Mark-Hammond/dp/1565926218/sr=8-1/qid=1164989859/ref=pd_bbs_sr_1/103-2563546-7494224?ie=UTF8&s=books -- Paul From http Sat Dec 9 02:23:16 2006 From: http (Paul Rubin) Date: 08 Dec 2006 23:23:16 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> Message-ID: <7xy7pho7mj.fsf@ruckus.brouhaha.com> "Kaz Kylheku" writes: > > Lisp just seems hopelessly old-fashioned to me these days. A > > modernized version would be cool, but I think the more serious > > Lisp-like language designers have moved on to newer ideas. > > What are some of their names, and what ideas are they working on? http://caml.inria.fr http://www.haskell.org etc. > Also, who are the less serious designers? The ones like us who waste their time on usenet. ;-) From andelys at riddergarn.dk Tue Dec 26 11:57:11 2006 From: andelys at riddergarn.dk (Andreas Lysdal) Date: Tue, 26 Dec 2006 17:57:11 +0100 Subject: Type text global In-Reply-To: <1167149636.601673.204030@a3g2000cwd.googlegroups.com> References: <1167149636.601673.204030@a3g2000cwd.googlegroups.com> Message-ID: <45915467.3040309@riddergarn.dk> Hey, I'm a noob at python so.. I just want to know, is there a function to type text global not in the program but in other programs(like you where typing it). For example in a textbox, in a program like "cmd.exe" or "notebook.exe". I'm using windows xp. Thanks! :) /Scripter47 From nicogrubert at gmail.com Fri Dec 8 10:17:15 2006 From: nicogrubert at gmail.com (Nico Grubert) Date: Fri, 08 Dec 2006 16:17:15 +0100 Subject: Python's email module - problem with umlauts in some email clients Message-ID: <457981FB.9030107@gmail.com> Hi there, I wrote a short python script that sends an email using python's email module and I am using Python 2.3.5. The problem is, that umlauts are not displayed properly in some email clients: + On a windows machine running thunderbird 1.0.2 umlauts are displayed properly. The email header contains "Content-type: text/plain; charset=utf-8" so the email client's character encoding automatically switches to "Unicode (UTF-8)" + On a solaris machine running thunderbird 1.5.0.8 and on a macintosh machine running eudora umlauts are *not* displayed properly. The email header does not contain any "Content-type". If I manually switch the email client's character encoding to "Unicode (UTF-8)", the umlauts are displayed properly. Therefore, I guess it has something to do with the missing "Content-type: text/plain; charset=utf-8" information in the email header. Any idea why the "Content-type: text/plain; charset=utf-8" is missing? Here is my script: #------------------------------------------------------------------ # send email from email.Header import Header import email.Message import email.Utils import mimetypes from smtplib import SMTP host = 'mail.example.com' mFrom = 'any.sender at example.com' mTo = 'foo.bar at example.com' mSubj = u'f\xfcr' mBody = u'f\xfcr foo bar' mBody = mBody.encode('UTF-8') mainMsg = email.Message.Message() mainMsg['From'] = mFrom mainMsg['To'] = mTo mainMsg['Subject'] = mSubj mainMsg.set_payload(mBody) mainMsg['Date'] = email.Utils.formatdate(localtime=1) mainMsg['Message-ID'] = email.Utils.make_msgid() mainMsg['Mime-version'] = '1.0' mainMsg['Content-type'] = 'text/plain; charset=utf-8' mainMsg['Content-transfer-encoding'] = '8bit' # 'quoted-printable' does not work either # mainMsg['Content-Transfer-Encoding'] = 'quoted-printable' s = SMTP(host) s.sendmail(mFrom, [mTo], mainMsg.as_string()) s.close() #------------------------------------------------------------------ Regards, Nico From dakman at gmail.com Wed Dec 6 13:58:56 2006 From: dakman at gmail.com (dakman at gmail.com) Date: 6 Dec 2006 10:58:56 -0800 Subject: how to get all the "variables" of a string formating? In-Reply-To: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> References: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> Message-ID: <1165431536.162899.15730@j72g2000cwa.googlegroups.com> "Is there an easy (i.e.: no regex) way to do get the names of all parameters? " ...regexp is the easy way :D GHUM wrote: > imagine: > > > template=""" Hello %(name)s, how are you %(action)s""" > > > we can use it to do things like: > > print template % dict (name="Guido", action="indenting") > > > Is there an easy (i.e.: no regex) way to do get the names of all > parameters? > > get_parameters(template) should return ["name", "action"] > > > Python has to do this somewhere internally..... how to access this > knowledge? > > Harald From macygasp at gmail.com Tue Dec 5 04:52:15 2006 From: macygasp at gmail.com (Wehrdamned) Date: 5 Dec 2006 01:52:15 -0800 Subject: Python regular expression Message-ID: <1165312335.481024.237360@l12g2000cwl.googlegroups.com> Hi, As I understand it, python uses a pcre engine to work with regular expression. My question is, then, why expressions like : >>> re.compile('asd|(?-i:QWE)', re.I) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/sre.py", line 180, in compile return _compile(pattern, flags) File "/usr/lib/python2.4/sre.py", line 227, in _compile raise error, v # invalid expression sre_constants.error: unexpected end of pattern don't work? They are ok in perl... Thanks in advance. From martin at v.loewis.de Sun Dec 3 15:13:13 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 03 Dec 2006 21:13:13 +0100 Subject: Deleting from a list while iterating In-Reply-To: <1165163229.065419.181810@73g2000cwn.googlegroups.com> References: <1165160235.282030.96610@79g2000cws.googlegroups.com> <4572F660.1070101@v.loewis.de> <1165163229.065419.181810@73g2000cwn.googlegroups.com> Message-ID: <45732FD9.2060208@v.loewis.de> Rhamphoryncus schrieb: >> This is different from the other approaches in that it doesn't >> modify items. If you wanted a new list, you could incrementally >> build one already in the first pass, no need to collect the >> indices first (as BlackJack explains). > > I didn't feel this distinction was worth mentioning, since "oldlist[:] > = newlist" is so trivial. The only solution that really avoids making > a copy is the reverse-iteration one. The distinction is relevant for performance, as the slice assignment has a complexity linear with the number of elements. Whether making a copy is expensive depends on the precise data: the solution that makes the copy in reverse may have quadratic complexity (if the number of removed elements increases with the list size); the version that appends all remaining elements to a new list and then does slice assignment should behave better-than-quadratic (in recent versions, it should give you linear performance). Regards, Martin From chris.lasher at gmail.com Sat Dec 9 00:18:27 2006 From: chris.lasher at gmail.com (Chris Lasher) Date: 8 Dec 2006 21:18:27 -0800 Subject: Interacting with keyboard LEDs Message-ID: <1165641507.187794.115360@l12g2000cwl.googlegroups.com> Is there a way to interact with keyboard LEDs (for Caps/Scroll/Num Lock) in Python? I'd like to achieve an effect similar to the *NIX command "setleds -L", but I'm not sure where to start, but I figured someone out there would have an idea or maybe experience with something similar. Thanks very much in advance for your help! Chris From john106henry at hotmail.com Thu Dec 14 15:07:02 2006 From: john106henry at hotmail.com (John Henry) Date: 14 Dec 2006 12:07:02 -0800 Subject: Iterating over several lists at once In-Reply-To: References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> <1166021513.479174.113630@80g2000cwy.googlegroups.com> <1166035250.709872.135350@t46g2000cwa.googlegroups.com> <1166050184.791028.52610@j72g2000cwa.googlegroups.com> Message-ID: <1166126821.920070.101350@f1g2000cwa.googlegroups.com> Is this suppose to be a brain teaser or something? Michael Spencer wrote: > John Henry wrote: > > Carl Banks wrote: > > > >> The function can be extended to allow arbitrary arguments. Here's a > >> non-minmal recursive version. > >> > >> def cartesian_product(*args): > >> if len(args) > 1: > >> for item in args[0]: > >> for rest in cartesian_product(*args[1:]): > >> yield (item,) + rest > >> elif len(args) == 1: > >> for item in args[0]: > >> yield (item,) > >> else: > >> yield () > >> > >> > > > > Very nice. > > > another implementation of cartesian_product using 'reduce' to add > mystery ;-) > > def star(outer, inner): > for rest in outer: > for item in inner: > yield rest + (item,) > > def cartesian_product(*args): > return reduce(star, args, ((),)) > > >>> list(cartesian_product("01","01","01")) > [('0', '0', '0'), ('0', '0', '1'), ('0', '1', '0'), ('0', '1', '1'), > ('1', '0', '0'), ('1', '0', '1'), ('1', '1', '0'), ('1', '1', '1')] > >>> > > Michael From aidan at aidans.org Mon Dec 11 21:15:57 2006 From: aidan at aidans.org (Aidan Steele) Date: Tue, 12 Dec 2006 13:15:57 +1100 Subject: enable pop3 for gmail from python In-Reply-To: <7.0.1.0.0.20061211210550.0379a158@yahoo.com.ar> References: <339657.28073.qm@web39106.mail.mud.yahoo.com> <7.0.1.0.0.20061211210550.0379a158@yahoo.com.ar> Message-ID: <364538570612111815v148f10edk5b7c3c38ca71192e@mail.gmail.com> He wants to automate the process of enabling POP access to Gmail, not access his Inbox via POP (which he can already do). That much said, a quick looksee at the Google site shows no mention of an automated method of doing this. That is not to say it is impossible, but it may be infeasible to do as one would have to write login code et al just to be authorised to do it - using one of the more advanced HTTP libraries, most likely. Sorry I couldn't solve the problem directly, but maybe my clarification will help someone who can. ;-) On 12/12/06, Gabriel Genellina wrote: > > At Sunday 10/12/2006 08:36, radu voicilas wrote: > > >Hi!I am making a script to connect to my gmail box and grep new > >mails.I want to know if i can enable pop from python if it is not > >enabled from gmail?I have been searching the python list but i > >haven't found an answer to this....only ways of connecting to the > >server wich i already know. > >Thank you very much! > > Have you read http://gmail.google.com/support/bin/answer.py?answer=10350 ? > Using poplib you can connect to the gmail pop3 server - what's your > problem? > > > -- > Gabriel Genellina > Softlab SRL > > __________________________________________________ > Correo Yahoo! > Espacio para todos tus mensajes, antivirus y antispam ?gratis! > ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.ploch at gmx.net Fri Dec 1 12:47:51 2006 From: thomas.ploch at gmx.net (Thomas Ploch) Date: Fri, 01 Dec 2006 18:47:51 +0100 Subject: No subject Message-ID: <20061201174751.78450@gmx.net> Amir Michail schrieb: > krishnakant Mane wrote: >> just used the py dev plugin for eclipse. >> it is great. > > But isn't support for java better because the eclipse ide can take > advantage of explicit type declarations (e.g., for intellisense, > refactoring, etc.)? > > Amir Obviously, since eclipse _is_ a full blown Java application, so support for Java is excellent. It was actually developed for being a Java IDE but (as far as I know) people were liking it so much, so they decided to make it expandable (and PyDev is actually a good thing, it supports PyLint and PyChecker, manages the python path when new modules are added, but can be improved (as can everything :-) )). But as I said, often my system hangs when having quite a few files opened, so that brought me off using it too often. Thomas -- "Ein Herz f?r Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de Unser Dankesch?n: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht! From adamadamadamamiadam at gmail.com Sat Dec 16 18:11:02 2006 From: adamadamadamamiadam at gmail.com (CakeProphet) Date: 16 Dec 2006 15:11:02 -0800 Subject: textwrap.dedent replaces tabs? In-Reply-To: References: Message-ID: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> Hmmm... a quick fix might be to temporarily replace all tab characters with another, relatively unused control character. MyString = MyString.replace("\t", chr(1)) MyString = textwrap.dedent(MyString) MyString = MyString.replace(chr(1), "\t") Of course... this isn't exactly safe, but it's not going to be fatal, if it does mess something up. As long as you don't expect receiving any ASCII 1 characters. From greg at cosc.canterbury.ac.nz Fri Dec 15 06:18:46 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:18:46 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> Message-ID: <4ufeniF17of60U7@mid.individual.net> Ken Tilton wrote: > What if it turns into an SQL lookup during refactoring? If the macro can produce SQL code, then whatever interprets the table can produce SQL code as well. If you're thinking of the macro taking apart the user's reverse function (rather than just wrapping it) and somehow translating it into SQL, well... a macro *could* do that, but it would be an awfully hairy thing to do, especially if the user is allowed to write arbitrary Lisp code in the body of his function (as it seems he is, in your example). A better way would be to design an abstract API for the user to use in his reverse functions. Then you can just re-implement the functions making up the API so that they do SQL queries instead of whatever they were doing before. No macro processing needed then. > The last example showed the macro inserting code to magically produce a > binding inside the reverse function. Are you sure? It looked to me like it was adding code *around* the reverse function, not inside it. I posted a Python function that achieves the same thing by calling the existing reverse function. > It would be easier to compare and > contrast with the Python equivalent if someone had posted such, but your > troops have fallen back to Fort So What? and pulled up the drawbridge. I'm still trying, but some of the code you posted is rather impenetrable without knowing a lot more about the details of your system. I'm doing my best to show some Python demonstrating the gist of what could be done. -- Greg From jonc at icicled.net Fri Dec 8 17:35:42 2006 From: jonc at icicled.net (Jonathan Curran) Date: Fri, 8 Dec 2006 16:35:42 -0600 Subject: Anyone use GD with pyhton? In-Reply-To: <1165616227.906934.306860@n67g2000cwd.googlegroups.com> References: <1165616227.906934.306860@n67g2000cwd.googlegroups.com> Message-ID: <200612081635.42258.jonc@icicled.net> On Friday 08 December 2006 16:17, jeff wrote: > could somebody explain to me how to install (or compile) GD for linux, > so that it works in pyhton? Jefff, the gd-library's website is at http://www.boutell.com/gd/ and they have a link there for download as well. It is highly likely that your linux distribution already has a gd library package ready to install. Use your package manager to search for 'gd' and you should get something. Now that you have that installed, you will need to get the python binding to it. A quick google search revealed gdmodule @ http://newcenturycomputers.net/projects/gdmodule.html Hope this helps, Jonathan From atkinw at rpi.edu Sun Dec 10 12:30:22 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 12:30:22 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano writes: > I'd love to say it has been fun, but it has been more frustrating than > enjoyable. I don't mind an honest disagreement between people who > genuinely are trying to see the other's point of view, but I don't think > that was the case here. What was especially frustrating was that the more > I tried to understand certain Lispers' positions by asking questions, the > more nasty and insulting they became. So now I have an even better Could that be because you were submitting enormous posts making the same claim and ignoring any new developments several times a day? > But I also gained a little more insight into why Lispers love their > language. I've learnt that well-written Lisp code isn't as hard to read as > I remembered, so I'd just like to withdraw a comment I made early in the > piece. I no longer believe that Lisp is especially strange compared to > natural languages. Strange that you'd come to that conclusion. I thought we'd established higher up that most programming languages are not like natural languages From http Sat Dec 9 09:12:09 2006 From: http (Paul Rubin) Date: 09 Dec 2006 06:12:09 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <87d56tkxp2.fsf@snobis.de> Message-ID: <7xpsatb1l2.fsf@ruckus.brouhaha.com> Stefan Nobis writes: > So why do you think, Common Lisp or Macros are a bad thing? What's the > difference (from the perspective of understanding) between a function > foo and a macro bar? Both just transform their inputs. It's just > another form of abstraction and from time to time really quite > helpful. For a long time Scheme had no macros, and Scheme developers who were exceedingly familiar with Common Lisp were nonetheless willing to get by without them. So I have to think macros aren't all THAT important. Scheme did eventually get macros, but somewhat different from CL's. From kernel1983 at gmail.com Sat Dec 16 10:18:59 2006 From: kernel1983 at gmail.com (kernel1983) Date: 16 Dec 2006 07:18:59 -0800 Subject: how can i write a hello world in chinese with python In-Reply-To: <1166049102.276684.311510@t46g2000cwa.googlegroups.com> References: <1165982024.978824.146920@n67g2000cwd.googlegroups.com> <1165985255.490054.290680@80g2000cwy.googlegroups.com> <1165995641.270460.124350@73g2000cwn.googlegroups.com> <1166049102.276684.311510@t46g2000cwa.googlegroups.com> Message-ID: <1166282339.654691.286660@n67g2000cwd.googlegroups.com> thanks everyone maybe this simple API doesn't fit the Chinese display but thanks everybody! At least I've got that what bundles is and maybe I can use Python to write program On 12?14?, ??6?31?, "MRAB" wrote: > Dennis Lee Bieber wrote: > > On 12 Dec 2006 23:40:41 -0800, "kernel1983" > > declaimed the following in gmane.comp.python.general: > > > > and I tried unicode and utf-8 > > > I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not > > > to use > > > "unicode" is a term covering many sins. "utf-8" is a specification > > for encoding elements of specific unicode characters using 8-bit > > elements (I believe by using certain codes x00 to x7F alone as "normal", > > and then x80 to xFF to represent an "escape" to higher [16-bit] element > > sets). > > > "\xEF\xBB\xBF" is just a byte string with no identifier of what > > encoding is in use (unless the first one or two are supposed to be > > BOM)... In the "Windows: Western" character set, it is equivalent to > > small-i-diaeresis/right-guillemot/upside-down? () In MS-DOS: Western > > Europe, those same bytes represent an > > acute-accent/double-down&left-box-drawing/solid-down&left > > > I've not done any unicode work (iso-latin-1, or subset thereof, has > > done for me). I also don't know Mac's, so I don't know if the windowing > > API has specific calls for Unicode data... But you probably have to > > encode or decod that bytestring into some compatible unicode > > representation.When you save a textfile as UTF-8 in Notepad.exe (Windows) it puts the > bytestring "\xEF\xBB\xBF" at the start to indicate that it's UTF-8 and > not ANSI (ie 8-bit characters). The bytes are actually the BOM > bytestring "\xFE\xFF" encoded in UTF-8. From Wolfram at invalid.invalid Sat Dec 2 08:14:53 2006 From: Wolfram at invalid.invalid (Wolfram) Date: Sat, 02 Dec 2006 14:14:53 +0100 Subject: Error handling. Python embedded into a C++ app. References: <0eoom290nb1m69n36gr97dsm0bn74ora5o@4ax.com> <1164767039.835715.162980@l12g2000cwl.googlegroups.com> Message-ID: Maybe of interest to people loking for a solution: I solved my issue by changing the program retroactively from a pure MFC app to a console one using this procedure: http://homepage3.nifty.com/ysflight/mfcconsole/mfcconsole.html I am still not sure why all of my other attempts failed, but most somehow changed stderr after the program started and before the python initialisation call. Maybe by binding in the python libraries some initialisation is done automatically before the first "user" C++ line is called and so any change done by the C++ code ignored? Oh well, it works now, even if with a kludge (I always need to have a console, even if I do not use Python). Bye bye, Wolfram Kuss. From frederik.cornillie at ua.ac.be Wed Dec 6 08:49:19 2006 From: frederik.cornillie at ua.ac.be (Frederik Cornillie) Date: Wed, 06 Dec 2006 14:49:19 +0100 Subject: SPE (Stani's Python Editor) web site? In-Reply-To: <1165280800.147167.108670@73g2000cwn.googlegroups.com> References: <1164748601.099263.98060@l12g2000cwl.googlegroups.com> <1165280800.147167.108670@73g2000cwn.googlegroups.com> Message-ID: Bernard schreef: > yes sir should I send them to you? You would do me and other gurus a great favour if you put it on a server somewhere. F > > John DeRosa a ?crit : > >> On 28 Nov 2006 13:16:41 -0800, "Bernard" >> wrote: >> >>> I can send you the latest tar.gz ( SPE-0.8.3.c-wx2.6.1.0.tar ) file if >>> you want it :) >> I'm looking for SPE for Python 2.5 and wxPython 2.7.2.0, on Windows. >> Do you have that? > From tubby at bandaheart.com Sun Dec 31 11:19:15 2006 From: tubby at bandaheart.com (tubby) Date: Sun, 31 Dec 2006 11:19:15 -0500 Subject: Progress Box or Bar in Windows In-Reply-To: <1167565484.032607.142850@n51g2000cwc.googlegroups.com> References: <1167565484.032607.142850@n51g2000cwc.googlegroups.com> Message-ID: cyberco wrote: > Go for wxPython, it'll fulfill all your GUI needs. Handsdown the best > GUI toolkit I ever ran into. Thanks a lot! I had no idea wxPython was so easy to use. I added a progress bar from wx to the app. Less than 20 lines of code and it only took about 5 minutes! From juanrgonzaleza at canonicalscience.com Wed Dec 13 04:06:01 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 13 Dec 2006 01:06:01 -0800 Subject: merits of Lisp vs Python In-Reply-To: <4u9948F16igllU1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <1165913743.943676.5910@79g2000cws.googlegroups.com> <4u9948F16igllU1@mid.individual.net> Message-ID: <1166000761.040517.262440@79g2000cws.googlegroups.com> greg ha escrito: > Juan R. wrote: > > > I see no dinamism on your example, just static overloading. > > There's nothing static about it: > > q = raw_input() > if q == "A": > a = 1 > b = 2 > else: > a = "x" > b = "y" > c = a + b > > There is no way that the compiler can statically > determine what the + operator needs to do here. Before or after the input? :] No, it is not that i did mean. Of course, the operation for c is dinamic, but just statically overloading the +. The definition for c could be adapted to the cases and introduced on the if. I would call dinamic code, for instance, if the if, the different cases and the def for c could be modified on the fly _? la_ LISP macro style. From webmaster at cacradicalgrace.org Wed Dec 27 16:11:04 2006 From: webmaster at cacradicalgrace.org (J. Clifford Dyer) Date: Wed, 27 Dec 2006 14:11:04 -0700 Subject: Mod_python References: <1167161288.802707.64220@h40g2000cwb.googlegroups.com> <1167212317.836419.162730@42g2000cwt.googlegroups.com> <1167231716.145292.293930@73g2000cwn.googlegroups.com> Message-ID: Lad wrote: > Maxim Sloyko wrote: >> Lad wrote: >>> In my web application I use Apache and mod_python. >>> I allow users to upload huge files( via HTTP FORM , using POST method) >>> I would like to store the file directly on a hard disk and not to >>> upload the WHOLE huge file into server's memory first. >>> Can anyone suggest a solution? >> The only solution you need is Apache and mod_python :) >> I mean, Apache won't load a huge POST request into its memory no >> matter what. All file uploads will be stored in temporary files. Under >> mod_python (provided you use FieldStorage) you'll need to deal only >> with 'file' objects. > > > Maxim , > Thank you for your reply. > Here is an example: > If a user uploads 100MB file , > what will be a consumption of memory, when the upload is complete? > > Or does it mean that Apache will read a part of a file , store it in a > temporary file, then read another part and adds this part to the > temporary file and so on until the whole uploaded file is read? > Thank you for the reply. > Lad > Are you working on *nix? Try this from the shell on your server: $ top Then upload a 100MB file and watch the memory usage. On Windows, I think you can do similar from Ctrl-Alt-Del, but graphically. Correct me if I'm wrong. Cheers, Cliff From bdesth.quelquechose at free.quelquepart.fr Sat Dec 23 08:41:31 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 23 Dec 2006 14:41:31 +0100 Subject: Confusion over calling a nested function inside a parent function In-Reply-To: <1166794524.504018.240630@h40g2000cwb.googlegroups.com> References: <877iwkdpsb.fsf@pyenos.pyenos.org> <1166794524.504018.240630@h40g2000cwb.googlegroups.com> Message-ID: <458d2c31$0$11618$426a74cc@news.free.fr> MacDonald a ?crit : > Pyenos wrote: > >>[code] >>class WORK: >> def getwork(self): >> def choosetable(self):pass >> choosetable() #TypeError: choosetable() takes exactly 1 >> #argument (0 given) >>[/code] >> >>Calling choosetable() at the above location gives me the error >>described above. > > > Although choosetable is a memeber of an instance method, s/is a member of/is defined in/ From omelnyk at gmail.com Mon Dec 18 17:51:18 2006 From: omelnyk at gmail.com (Olexandr Melnyk) Date: Tue, 19 Dec 2006 00:51:18 +0200 Subject: ANN: Skimpy Gimpy ASCII Web Challenge CAPTCHA In-Reply-To: <1166481614.468018.250370@80g2000cwy.googlegroups.com> References: <1166481614.468018.250370@80g2000cwy.googlegroups.com> Message-ID: Looks interesting; have you considered making an audio alternative for people with visual disabilities? ---------------------------- Olexandr Melnyk, http://omelynk.net/ 18 Dec 2006 14:40:14 -0800, aaronwmail-usenet at yahoo.com < aaronwmail-usenet at yahoo.com>: > > Please check it out and try it: > > http://skimpygimpy.sourceforge.net/ > > Find examples, documentation, links to demos > and download links there. > > Skimpy Gimpy is a tool for generating HTML > representations for strings which > people can read but which web > robots and other computer programs > will have difficulty understanding. > Skimpy is an example of a Captcha: > an acronym for "Completely Automated Public > Turing test to tell Computers and Humans Apart". > > The Skimpy program and API > (applications programmer interface) > is implemented in a single > self contained Python script (module). The > input for Skimpy are words or phrases. > The output of the program and API are strings containing > HTML preformatted text. The preformatted > text contains "ASCII art" representing the input > phrase, which looks like somewhat sloppy handwriting > on a speckled page, when viewed in an HTML browser. > > It is intended that it is easy for a human to > read the word or phrase when rendered > as HTML, but it is difficult for a program to > extract the word or phrase automatically. > The program uses a number of techniques > to make the output difficult for a computer to > interpret: curve interpolation, random rotation, > random skew, random scale adjustment, > "smearing", and addition of noise. > > The Skimpy tool is far easier to install, use, > and embed than other similar technologies. > All you need is python installed and the > skimpyGimpy.py source file. > > Enjoy and happy holidays! -- Aaron Watters > === > there ain't no sanity clause! > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nospam at riddergarn.dk Thu Dec 28 13:39:57 2006 From: nospam at riddergarn.dk (Scripter47) Date: Thu, 28 Dec 2006 19:39:57 +0100 Subject: Reverse of SendKeys?? Message-ID: <45940F7D.40900@riddergarn.dk> Hey! I know there is a module named SendKeys. SendKeys module it can type strings as you where typing it, on the keyboard. But is there a module that does the reverse. A module that gets _anything_ what the keyboard writes. For example. If i type "hey" on my keyboard. Will the program get the string even if the program not is on focus.. Thanks :) Sorry for bad English... -- _________ .__ __ ______________ / _____/ ___________|__|______/ |_ ___________ / | \______ \ \_____ \_/ ___\_ __ \ \____ \ __\/ __ \_ __ \/ | |_ / / / \ \___| | \/ | |_> > | \ ___/| | \/ ^ / / / /_______ /\___ >__| |__| __/|__| \___ >__| \____ | /____/ \/ \/ |__| \/ |__| From sjmachin at lexicon.net Thu Dec 7 02:14:37 2006 From: sjmachin at lexicon.net (John Machin) Date: 6 Dec 2006 23:14:37 -0800 Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> <1165298691.474503.184480@16g2000cwy.googlegroups.com> Message-ID: <1165474208.418638.270500@73g2000cwn.googlegroups.com> OKB (not okblacke) wrote: > John Machin wrote: > > > Can you give a real example from your code where the location of > > such a human error (you cause a variable to bound to a value of > > inappropriate type) would be difficult to find, plus an estimate of > > how often you would make such an error? > > Here is an example: > > self.outFile.write(str(len(self.hits)) + ' in ' + searchInfo.recordName > + '\t' + ']['.join((a. group() for a in self.hits)) + '\n') > > This is from a text-searching tool I have written to search > linguistic corpora. This statement writes a summary line to the output > file indicating how many hits were found in that file. > > The problem in this line was that I'd forgotten to put str() around > the len(). Now, it's not impossible to find the problem, because given > my knowledge of the program I know that that's the only part of the line > that would reasonably contain the number, but I still think it would be > a lot easier if there were a caret in the error message pointing to the > offending summand. It should be extremely easy (rather than "not impossible") for anybody with half a clue to find the problem given only the offending statement (rather than your "knowledge of the program"). There are 6 possibilities; 3 are string constants. That leaves us with len(something), searchInfo.recordName, and "][".join(something). len() very definitely returns an integer (unless some lunatic has bound the name to something else) and it's the *first* of the possibilities -- one can normally expect execution to proceed from left to right. recordName smells like a string. "][".join(blahblah) likewise unless the rebinding mania is pandemic. Sheesh. > > I'm glad you asked this question, though, because in searching for > examples in my code, I discovered that most of my beefs aren't actually > of this type. A lot of them are things like this: > > someStr.split(someList) > > Here I meant to write someList[0] (say), but have inadvertently > passed the list instead of one of its elements. > > In this case I receive an error message that says "TypeError: > expected a character buffer object". My question is: why can this error > message not say what was encountered INSTEAD of a character buffer > object? > > A similar situation occurs when I do someVar[0] and get an > "unsubscriptable object" error. The error does not even tell me the > type of the offending value, just that it is unsubscriptable. > > So my conclusion from this is: is there a reason that every error > message of the form "expected foo" or "this object cannot be frotzed" > cannot be changed to something like "expected foo but found bar" or > "this FooType object cannot be frotzed"? And despite your use of RHN (Reverse Hungarian Notation) you don't know that someList is a list? From ironfroggy at gmail.com Tue Dec 5 14:44:17 2006 From: ironfroggy at gmail.com (Calvin Spealman) Date: Tue, 5 Dec 2006 14:44:17 -0500 Subject: Subprocess with a Python Session? In-Reply-To: References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> Message-ID: <76fd5acf0612051144o1f89a724h9dd88c2cf5662a93@mail.gmail.com> On 12/5/06, Fredrik Lundh wrote: > Calvin Spealman wrote: > > > No matter what I do I cant get the following code to do what I expect. > > I hadn't used subprocess t o read and write to pipes of a > > still-running app, and I just can't seem to get it right. What gives? > > > > import subprocess > > > > p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE) > > p.stdin.write('print 10\n') > > + p.stdin.close() > > > assert p.stdout.readline() == '10\n' > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I know I can do that, but I am specifically trying to not close the pipe or terminate the process. I need to write additional statements, read additional output, etc. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ From Aditya.Vaish at efi.com Wed Dec 20 01:06:52 2006 From: Aditya.Vaish at efi.com (Aditya Vaish) Date: Wed, 20 Dec 2006 11:36:52 +0530 Subject: python script terminating Message-ID: <13B4D38ED7B116429C3A426A2C3998D90290D805@blrexmb01.efi.internal> Using perl ","",data) will not cut out all javascript code if it's spread on many lines. I could use something like /s from perl which treats . as all signs (including new line). How can i do that ? Maybe there is other way to achieve the same results ? Thanx From david at david-steuber.com Fri Dec 15 05:04:24 2006 From: david at david-steuber.com (David Steuber) Date: 15 Dec 2006 05:04:24 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165737791.744375.190080@l12g2000cwl.googlegroups.com> Message-ID: <87odq5a313.fsf@david-steuber.com> Steven D'Aprano writes: > How am I being silly? Do you not believe that people write case blocks > with fifty tests? Okay, how about twenty? Ten? Eight? You should check out generic functions in CLOS. Rather than writing a ridiculously long case block, you can use EQL specialized functions. It's a great way to do dispatch. -- This post uses 100% post consumer electrons and 100% virgin photons. At 2.6 miles per minute, you don't really have time to get bored. --- Pete Roehling on rec.motorcycles I bump into a lot of veteran riders in my travels. --- David Hough: Proficient Motorcycling From simon at renderIHATESPAMmania.com Wed Dec 6 21:14:39 2006 From: simon at renderIHATESPAMmania.com (Simon Bunker) Date: Thu, 07 Dec 2006 02:14:39 +0000 Subject: per instance descriptors Message-ID: <45777908_4@mk-nntp-2.news.uk.tiscali.com> Hi I have code similar to this: class Input(object): def __init__(self, val): self.value = val def __get__(self, obj, objtype): return self.value def __set__(self, obj, val): # do some checking... only accept floats etc self.value = val class Node(object): a = Input(1) b = Input(2) I realise that a and b are now class attributes - however I want to do this: node1 = Node() node2 = Node() node1.a = 3 node.b = 4 And have them keep these values per instance. However now node1.a is 4 when it should be 3. Basically I want to have the Input class as a gateway that does lots of checking when the attibute is assigned or read. I have had a look at __getattribute__(), but this gets very ugly as I have to check if the attribute is an Input class or not. Also I don't think property() is appropriate is it? All of the attributes will essentially be doing the same thing - they should not have individual set/get commands. Is there any way of doing this nicely in Python? thanks Simon From could.net at gmail.com Thu Dec 21 02:37:28 2006 From: could.net at gmail.com (could.net at gmail.com) Date: 20 Dec 2006 23:37:28 -0800 Subject: a question on python dict In-Reply-To: References: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> Message-ID: <1166686648.342966.78920@n67g2000cwd.googlegroups.com> Thank you very much for your explanation! I made a mistake that I said the hash value should be recalculated each time the dict resize, what I wanted to say was that the position of each item should be recalculated. Maybe I should take a look at the source code of python dict some day. I'll some here for help then. Thanks again! Tim Peters wrote: > [could.net at gmail.com] > > Python dict is a hash table, isn't it? > > Yup. > > > I know that hashtable has the concept of "bucket size" and "min bucket > > count" stuff, > > Some implementations of hash tables do. Python's does not. Python's > uses what's called "open addressing" instead. > > > and they should be configurable so I can set them to the proper value > > when I know how many items I'm going to handle. > > > > If these two values can't be set, the hashtable will give them default > > values. When there are more and more items being added to the > > hashtable, it increase its buckets and copy the old items into the new > > one and re-calculate the hash value of each item. > > That's several distinct claims, each of which is true of some hash > table implementations but not of others. Python's implementation has > no "buckets", so all that's simply irrelevant. Python's > implementation (not all do) saves the hash value of each item, so when > it does need to grow (or shrink) the space allocated to the table, it > does not need to recalculate the hash value of any item. > > You should also note that copying a dict key or value (no matter of > what type) consists in its entirety of copying one machine address (a > 4- or 8-byte pointer, depending on platform). > > > I think this will waste some time doing the increasing-copying thing. > > It does take time to resize. "Waste" is a value judgment ;-) > > > If I know I'm going to handle about 20000 items, I can set the size of > > hashtable to 30000. > > > > So, can I do this in python? > > You can't. Unless you build up to 20000 items over and over (many > thousands of times), it's unlikely you'd be able to measure the time > difference even if you could. From robertoedwins at gmail.com Fri Dec 1 20:48:40 2006 From: robertoedwins at gmail.com (rieh25) Date: Fri, 1 Dec 2006 17:48:40 -0800 (PST) Subject: converting dict to object Message-ID: <7649225.post@talk.nabble.com> If I have a dictionary such as: d = {'a' : 1, 'b' : 2} is there a way to convert it into an object o, such as: o.a = 1 o.b = 2 thanks -- View this message in context: http://www.nabble.com/converting-dict-to-object-tf2741429.html#a7649225 Sent from the Python - python-list mailing list archive at Nabble.com. From mhellwig at xs4all.nl Wed Dec 20 12:50:23 2006 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Wed, 20 Dec 2006 18:50:23 +0100 Subject: perl better than python for users with disabilities? In-Reply-To: <87slfalf8h.fsf@jidanni.org> References: <87slfalf8h.fsf@jidanni.org> Message-ID: <458977b7$0$326$e4fe514c@news.xs4all.nl> Dan Jacobson wrote: > Can I feel even better about using perl vs. python, as apparently > python's dependence of formatting, indentation, etc. vs. perl's > "(){};" etc. makes writing python programs perhaps very device > dependent. Whereas perl can be written on a tiny tiny screen, and can > withstand all kinds of users with various disabilities, etc.? > Also perl is easier to squeeze into makefiles. > Quite punny title though I assume you are really serious and mean people with a physical disability, I won't comment any further on this subject :-), if I already offended anyone, please excuse me, since I'm original from Germany I'm not supposed to be funny. -- mph From deepusdreamz at gmail.com Mon Dec 18 07:28:44 2006 From: deepusdreamz at gmail.com (pradeep kumar) Date: Mon, 18 Dec 2006 17:58:44 +0530 Subject: connecting webservers through HTTP port using python Message-ID: <86a272920612180428p49c89c43wf19fa5e9dccb15f6@mail.gmail.com> hii iam working on socket programming, i've to connect webservers through HTTP port and send/receive data.. so currently i'm installed apache server and trying to connect that server using python. so any tell me how to connect the apache server by python code. give suggestions.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptmcg at austin.rr.com Fri Dec 22 22:39:55 2006 From: ptmcg at austin.rr.com (Paul McGuire) Date: 22 Dec 2006 19:39:55 -0800 Subject: Generating all permutations from a regexp In-Reply-To: References: Message-ID: <1166845194.983480.79140@79g2000cws.googlegroups.com> On Dec 22, 8:30 am, "BJ?rn Lindqvist" wrote: > With regexps you can search for strings matching it. For example, > given the regexp: "foobar\d\d\d". "foobar123" would match. I want to > do the reverse, from a regexp generate all strings that could match > it. > > The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000", > "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999". > > Is this possible to do? Here is a first cut at your problem (http://pyparsing-public.wikispaces.com/space/showimage/invRegex.py). I used pyparsing to identify repeatable ranges within a regex, then attached generator-generating classes to parse actions for each type of regex element. Some limitations: - unbounded '*' and '+' repetition is not allowed - only supports \d, \w, and \s macros Here are the test cases in the program that generate the expected list of permutations: [A-E] [A-D]{3} X[A-C]{3}Y X[A-C]{3}\( X\d [A-C]\s[A-C]\s[A-C] [A-C]\s?[A-C][A-C] [A-C]\s([A-C][A-C]) [A-C]\s([A-C][A-C])? [A-C]{2}\d{2} From rampeters at gmail.com Mon Dec 11 18:45:33 2006 From: rampeters at gmail.com (johnny) Date: 11 Dec 2006 15:45:33 -0800 Subject: newb: logging.getLogger('') and logging.getLogger("something") Message-ID: <1165880733.900372.105980@n67g2000cwd.googlegroups.com> For getLogger, can you pass anything in there and it will return a object? Would that returned object, be your root logger? Thanks, From robert.kern at gmail.com Tue Dec 19 05:32:46 2006 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 19 Dec 2006 04:32:46 -0600 Subject: python-hosting.com projects: dead? In-Reply-To: <4upr9dF197g6cU1@mid.individual.net> References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> <1166499192.027000.151290@j72g2000cwa.googlegroups.com> <1166499671.678929.25180@n67g2000cwd.googlegroups.com> <4upr9dF197g6cU1@mid.individual.net> Message-ID: greg wrote: > jpellerin+nose at gmail.com wrote: > >> I certainly hope so, but this is what I'm reacting to (from >> http://www.webfaction.com/freetrac): >> >> "We're sorry, we're not longer accepting applications for free trac/svn >> accounts. People have left their Trac sites unattended and as a result >> our server is being flooded with spam. We need to do some serious >> cleanup and when that's done we'll accept new applications again (that >> might take weeks, if not months though). " > > Um, that sounds to me like they're not accepting *new* > projects, not that they're shutting down existing ones. > Unless *my* reading comprehension skills have completely > abandoned me. Well, nose.python-hosting.com (Jason Pellerin's project) is certainly inaccessible to me as well as most of the other free Tracs that I could scrounge up through Google. Jason's not just being paranoid. While it may be temporary and he will get hosting back in a few months(!), it's still down, and apparently without warning (I'm not a party to any of this, so I'm simply going with what Jason wrote). -- 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 From fredrik at pythonware.com Sun Dec 3 13:47:15 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 03 Dec 2006 19:47:15 +0100 Subject: Parsing data from pyserial In-Reply-To: <4573145a.64392531@news.comporium.net> References: <4572e860.53134312@news.comporium.net> <12n606he7k5uhb3@corp.supernews.com> <4573145a.64392531@news.comporium.net> Message-ID: Si Ballenger wrote: > I would think a time delay would be needed between the below two > lines in the code if he expects to get a useable data string back > from the gizmo for the command sent to it. > > ser.write("TC 016 240 100 240 016 240\r\n") > reading = ser.read(40) why's that? if the gizmo is busy "doing its thing", read() will wait for up to one second before giving up. From paddy3118 at netscape.net Tue Dec 19 02:14:30 2006 From: paddy3118 at netscape.net (Paddy) Date: 18 Dec 2006 23:14:30 -0800 Subject: regular expression In-Reply-To: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> Message-ID: <1166512470.675209.118170@j72g2000cwa.googlegroups.com> Asper Faner wrote: > I seem to always have hard time understaing how this regular expression > works, especially how on earth do people bring it up as part of > computer programming language. Natural language processing seems not > enough to explain by the way. Why no eliminate it ? If you try to eliminate what you don't understand you won't learn anything! I suggest that you put the learning of regexps aside for a while and come back to it 'later'. From carsten at uniqsys.com Mon Dec 4 12:17:16 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 04 Dec 2006 12:17:16 -0500 Subject: Why not just show the out-of-range index? In-Reply-To: <1165250963.660087.58410@n67g2000cwd.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> <1165250963.660087.58410@n67g2000cwd.googlegroups.com> Message-ID: <1165252637.3345.34.camel@dot.uniqsys.com> On Mon, 2006-12-04 at 08:49 -0800, rurpy at yahoo.com wrote: > Carsten Haese wrote: > > On Mon, 2006-12-04 at 01:04 -0800, Russ wrote: > > > Robert Kern wrote: > > > > > > > Nothing is going to happen until you do one of these two things. Being more rude > > > > (and yes, you are being incredibly rude and insulting) won't move things along. > > > > > > I re-read the thread, and I don't see anywhere where I was rude > > > > Please allow me to break it down for you: > > > > Your first reply on this thread, or second message, said: > > > > """ > > Now, that [submitting a patch that fixes the problem] would be rather > > silly. I would have to familiarize myself > > with the code for the Python interpreter, then send a patch to the > > maintainers (and hope they notice it in their inboxes), while the > > maintainers themselves could probably "fix" the problem in two minutes > > flat. No thanks! > > > > My suggestion is trivial to implement and would benefit every Python > > programmer (even if only slightly), so I don't think it is too much to > > ask for. > > """ > > > > You may not have meant this to be rude, but it does come off as rude and > > arrogant, and I'll explain to you why: In your first post you stated > > that the feature seems like a no-brainer to you. That implies to the > > reader that you might have the necessary skill to implement the feature > > yourself, hence Robert's suggestion to submit a patch was, in the > > context you gave yourself, neither unreasonable nor silly. I can see how > > your calling a reasonable suggestion by a valuable community member > > "silly" would be construed as rude and arrogant. > > Thanks for explaining why the OP was rude. Having been > reading and listening to english for only a few decades > probably, I am sure the OP (and me too!) appreciates your > explanation of rudeness. It was really hard for me to see it > until you explained it so well. The great thing about c.l.p. is > how much one learns about non-Python things here. > (oops, I hope I wasn't rude by saying there were non-Python > things? I didn't mean to diminish Python in any way.) > > Russ, > Please rememer that learning Python is not done overnight -- > there are many different levels of knowlage and only the > most elite Pythonists have reached True Understanding. > > Since there are many things you don't understand, it is > best you (and me too!) do not make suggrestions publically. > Infidels could read them and inplying that Python is not > perfect and you will undermine the spritual growth of > many other newbies.. Such dangerous sugggestions > should be made privately at the alter of Sourceforge, with > a lot of deep self-reflection and piety. > > Until you achive greater understanding it is best if in public > you make sure that you write with the following in mind: > Python is perfect > Perl sucks > Static typing sucks > Python is faster than C > Quoting frequently from the holy Zen of Python is also > helpful. Please remember that many regulars here are > members of the holy priesthood because they have spent > many years studying the Python scriptures. Be as circumspect > in addressing them as you would be a medival knight or > Japanese samurai. Only by following their guidance with > complete devoutness and faith will you be able to achive > the deepest level of Python appreciation. > > Hope this helps. My sarcasm meter just exploded. -Carsten From kentilton at gmail.com Wed Dec 13 23:44:26 2006 From: kentilton at gmail.com (Ken Tilton) Date: Wed, 13 Dec 2006 23:44:26 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4ubu3nF16kv7aU1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> Message-ID: greg wrote: > Ken Tilton wrote: > >> pps. How would Python do this? > > > Here's one way it could look: > > defskill("absolute-value", > title = "Absolute Value", > annotations = [ > "Take the absolute value of #op#.", > "The vertical bars around #op# mean 'the absolute value of' #op#.", > "Absolute value of #strn# is the 'distance' of #strn# from zero.", > "Absolute value is always zero or positive: #str|n|=n#, and > #str|-n|=n#." > ], > hints = [ > "What do those vertical bars around #op# mean?", > "Have you learned about 'absolute value'?", > """Absolute value can be thought of as the 'distance' of a value from > zero on the number line, and distance is always positive.""", > "The rule is:#str|-n|=|n|##str=n#. Can you apply that to #op#?", > "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#.", > """To get the absolute value of a number such as #op#, we simply drop > any minus sign.""" > ] > ) > > > Is it possible to avoid committing to an > > implementation mechanism? > > The defskill function could do just about anything with this. > Here's one possibility: > > skills = {} > > class Skill: > pass # fill in whatever methods you need here > > def defskill(name, title, annotations, hints): > skill = Skill() > skill.title = title > skill.annotations = annotations > skill.hints = hints > skills[name] = skill > > This gives you a dictionary of Skill instances indexed by name, > each one having a title and lists of annotation and hint strings. > The rest of the system can process this however required. Ok, not too bad, not much syntax in there. But now I have a tougher requirement for you, which I noticed only after posting. (I tried running the damn thing and it whined about not knowing how to "reverse" absolute-value (to clone one problem into a similar problem).) A reversal must be able to yield any given a result, and sometimes must use given operands already settled on by the larger reversing algorithm. In the simpler case, to reverse absolute-value with result 42 we produce either |42| or |-42|. In the more complicated case, the multiply-literal reverser may discover 6 is an operand and 42 is the result (meaning it does no randomization, it just supplies the (* 6 7) reversal. Why am I telling you all this? I don't know. The point is, we need code (not just data) in defskill (apologies for nasty formatting): (defmacro defskill (id &body skill-info) `(progn ,@(loop with sub-id = id for (q . q-def) in skill-info collecting (ecase q ((title annotations hints) `(defmethod ,(intern (conc$ 'skill- q)) ((tf-id (eql ',sub-id))) (list , at q-def))) (reverse `(defmethod tf-reverse ((id (eql ',sub-id)) resx opnds) (declare (ignorable resx opnds)) , at q-def)))))) --------------- (Abbreviated) Example.... ------------------------------ (defskill absolute-value (title "Absolute Value") (annotations "Absolute value is always zero or positive: #str|n|=n#, and #str|-n|=n#.") (hints "What do those vertical bars around #op# mean?") (reverse (ensure-cloning resx (make-instance 'mx-number :value (loop with op1 = (car opnds) with log = (max 1 (ceiling (log (abs (value op1)) 10))) for n = (* (signum (value op1)) (+ 2 (random (expt 10 log)))) when (/= n (value op1)) return n) :representation (representation resx))))) -------------- Producing.... --------------------------------- (progn (defmethod skill-title ((tf-id (eql 'absolute-value))) (list "absolute value")) (defmethod skill-annotations ((tf-id (eql 'absolute-value))) (list "absolute value is always zero or positive: #strn=n#, and #str-n=n#.")) (defmethod skill-hints ((tf-id (eql 'absolute-value))) (list "what do those vertical bars around #op# mean?")) (defmethod tf-reverse ((id (eql 'absolute-value)) resx opnds) (declare (ignorable resx opnds)) (ensure-cloning resx (make-instance 'mx-number :value (loop with op1 = (car opnds) with log = (max 1 (ceiling (log (abs (value op1)) 10))) for n = (* (signum (value op1)) (+ 2 (random (expt 10 log)))) when (/= n (value op1)) return n) :representation (representation resx))))) How close can Python get when code is involved? The reverse function signature is fixed, so can lambda help? ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From martin at v.loewis.de Mon Dec 11 13:54:15 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 11 Dec 2006 19:54:15 +0100 Subject: sys.stdin.encoding In-Reply-To: <1165832308.249225.226240@16g2000cwy.googlegroups.com> References: <1165825571.435369.150110@79g2000cws.googlegroups.com> <457D2652.7080200@v.loewis.de> <1165832308.249225.226240@16g2000cwy.googlegroups.com> Message-ID: <457DA957.9060001@v.loewis.de> Leo Kislov schrieb: > Environmental variable TERMENCODING ? Heck, maybe this will catch on > and will be used by other languages, libraries, terminals, etc. It's > not really Python only problem. I also considered environment variables. This can likely be made available only in 2.6, though. Plus, in the Eclipse case, we can't know for sure that stdout really goes to the terminal - as it is just a pipe file descriptor (Java is not capable of managing a full pseudo-terminal). Regards, Martin From rupole at hotmail.com Wed Dec 20 07:22:37 2006 From: rupole at hotmail.com (Roger Upole) Date: Wed, 20 Dec 2006 07:22:37 -0500 Subject: tricky(?) win32com question - Mark Hammond or other experts please. References: <1166576759.360059.51230@48g2000cwx.googlegroups.com> Message-ID: <1166617563_4137@sp6iad.superfeed.net> cfriedalek at gmail.com wrote > OK, I've asked this earlier this week with no response. Since then I've > also received a suggestion from the app developers but that failed with > the same type error problem. Hopefully Mark Hammond or other experts > can offer a suggestion as to how to get around this problem. I'm > foolish enough to think that a solution can be found. Or can someone > suggest how to pm Mark. > > --------------------------- > > I'm using pywin32com to drive a 3rd party app. The app has a VBS based > API. In VBS a specific query for data goes like this: > > Plot.QueryBegin datacode, Nothing > > where datacode is a number and Nothing is a VBS type/keyword > > The nominal python equivalent doesn't work. Plot.QueryBegin(datacode, > None) gives a type mismatch error as follows: com_error: (-2147352571, > 'Type mismatch.', None, 2) > >>From what I've been able to discover Nothing is not a null, 0, False, > "" > > Table 12.2 of > http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html does not > mention Nothing in its list of Variant types. > > Please, any clues about how to handle this (apart from running the > query in VBS). I so much more prefer python. Try either pythoncom.Missing, pythoncom.Empty, or pythoncom.ArgNotFound. Roger ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From fredrik at pythonware.com Thu Dec 7 03:31:26 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 07 Dec 2006 09:31:26 +0100 Subject: Use of factory pattern in Python? In-Reply-To: <676224240612070028y7be5e8b5h8f860bc505da53c0@mail.gmail.com> References: <676224240612070028y7be5e8b5h8f860bc505da53c0@mail.gmail.com> Message-ID: Nathan Harmston wrote: > so I was thinking of having a factory class to return the individual > objects for each row......ie > > class Factory(): > # if passed a gene return a gene object > # if passed an intron return an intron object > # if passed an exom return an exon object > > Is this a good way of doing this, or is there a better way to do this > in Python in python, that's spelled: def factory(...): # if passed a gene return a gene object # if passed an intron return an intron object # if passed an exom return an exon object From martin at v.loewis.de Fri Dec 29 19:40:18 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 30 Dec 2006 01:40:18 +0100 Subject: per interpreter storage for C extensions In-Reply-To: References: Message-ID: <4595b573$0$25466$9b622d9e@news.freenet.de> Robin Becker schrieb: > Is there a simple/cheap way for C code to cache these sorts of module > level globals on a per interpreter basis? Is there even a way to tell > which interpreter I'm being called in? There is no cheap way to add to the interpreter state. As Chris Mellon explains, you can use PyThreadState_Get()->interp to find the interpreter state. I recommend to do the caching only in the single-interpreter case (i.e. for the first interpreter). Notice that comparing interpreter states by identity is somewhat dangerous: the interpreter may have been deleted with you still holding a pointer to it, and a new interpreter may get allocated at the same address, making you believe it is the same interpreter. Regards, Martin From gandalf at designaproduct.biz Thu Dec 21 03:57:12 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Thu, 21 Dec 2006 09:57:12 +0100 Subject: rsync for python? In-Reply-To: <458A3912.4000003@multisuns.com.tw> References: <458A3912.4000003@multisuns.com.tw> Message-ID: <458A4C68.6050204@designaproduct.biz> nienfeng ?rta: > Hi, everyone > > I want to build rsync server that can run in linux and windows, and > configure by python. So I'm looking for something like rsync for python. > I find rsync.py and pysync. But rsync.py looks like a client mode, > it can't be a rsync server, is it? Can pysync be a rsync server? > Look at rdiff-backup here: http://www.nongnu.org/rdiff-backup/ Well, this can only sync in one direction, but it is very good at it. I'm using it to synchronize big directories (20GB data, thousands of hundreds of small files) over an ADSL connection and it works. If you need to sync in both directions, I would recommend subversion. There is a python module for subversion. Although subversion is not lightweight, and you really need to read its (very long) documentation. :-) Best, Laszlo From david.huard at gmail.com Tue Dec 12 10:40:41 2006 From: david.huard at gmail.com (David) Date: 12 Dec 2006 07:40:41 -0800 Subject: Reference to base namespace in a class. Message-ID: <1165938041.107485.169330@j44g2000cwa.googlegroups.com> Hi, I'm working on a project where we're juggling with two potential implementations. In the two scenarios, we create objects in the base namespace. These objects are interdependent, in the sense that to compute something, they have to look up the value of the other objects (their parents). The objects are functions, by the way, with some additional attributes. In the first scenario, as the objects are created, they immediately share references and can call each other's value. All these objects are then referenced in a class that defines some methods accessing those objects. The advantage is that you can call the functions from the base namespace and they'll know where to look to make the computations. The downsize is that if you delete one object by mistake, nothing works anymore, that is, the methods from the class will no longer reference the right objects. In the second scenario, as the objects are created, they only know the name of their parents, and don't have their actual reference. To compute something, we have to pass the values of the other objects explicitely. A class is then instantiated, where we look up the __main__ dictionary for the names of the parents given by each function, copy the objects inside the class, create an attribute for each object on the fly and link the objects together using the parents names. The advantage is that even if an object in the base namespace is destroyed, the class methods will still work since the references are all internal to the class instance. The disadvantage is that the objects in the base namespace are dummy objects, ie they don't speak to each other. I guess it's hard to understand the context from this quick description, but the code would look equally opaque. Here is an attempt to put that into a simple question: Are there counter indications to reference objects in the base namespace from a class ? Thanks for your help. David Huard From ptmcg at austin.rr._bogus_.com Fri Dec 1 04:24:51 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 01 Dec 2006 09:24:51 GMT Subject: Is there a reason not to do this? References: <4t96ujF134nv7U1@mid.uni-berlin.de> <1164942311.945476.147100@f1g2000cwa.googlegroups.com> Message-ID: "Ron Garret" wrote in message news:rNOSPAMon-C4348B.23494230112006 at news.gha.chartermi.net... > > These objects can be parts of huge networks of massively linked data > structures. They are in constant flux. It is not uncommon to hit a bug > after many minutes, sometimes hours, of computation. Having to store > the whole shlemobble after every operation would slow things down by > orders of magnitude. And writing code to be clever and only store the > dirty bits would be a pain in the ass. I think I'll stick with Plan A. > > rg Sorry, not quite what I meant, I'm not suggesting storing everything after every change. I just meant that to help your development, once you get some instances to a steady state, persist them off in some picklish format, so you can restart quickly by unpickling, instead of dynamically reconstructing. But you know your problem domain better than I, so I'll shut up. Best of luck to you. -- Paul From nono at hotmail.com Sat Dec 30 07:49:37 2006 From: nono at hotmail.com (Osiris) Date: Sat, 30 Dec 2006 13:49:37 +0100 Subject: python , Boost and straight (but complex) C code Message-ID: I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file: ============================ #include #include namespace { // Avoid cluttering the global namespace. int my_int; /* a global integer: or outside namespace ? */ double calc ( double f) { my_int = (int) (f/2); printf( "Half of %f is %d\n", f, my_int ); return f/2; } } #include using namespace boost::python; BOOST_PYTHON_MODULE( half ) { def("calc", calc ); } ================================ Which I put in a VC project and compile into a .DLL This DLL I put somewhere on my disk, where Python 2.4 can find it. then I write the following Python source: ===================== from half import * calc(34655.0) et voila ? Can I acces my_int too, this way ? From david at cypherspace.info Fri Dec 29 20:26:44 2006 From: david at cypherspace.info (cypher543) Date: 29 Dec 2006 17:26:44 -0800 Subject: Managing a queue of subprocesses? Message-ID: <1167442004.174070.71490@k21g2000cwa.googlegroups.com> My app uses a "queue" of commands which are run one at a time. I am using the subprocess module to execute the commands in the queue. However, processes always run at the same time. How can I make one process run at a time, and then execute the next process when the first has terminated? My code is below: self.cmdQueue = {} self.queue(theProject.directory, "ls", "-l") self.queue(theProject.directory, "echo", "hello, world!") def consoleLogAddLine(self, text): self.consoleLogBuffer.insert(self.consoleLogBuffer.get_end_iter(), text) self.consoleLog.scroll_to_mark(self.consoleLogBuffer.get_insert(), 0) def onGetData(self, fd, cond, *args): self.consoleLogAddLine(fd.readline()) return True def queue(self, rootDir, cmd, args = ""): count = len(self.cmdQueue) + 1 self.cmdQueue[count] = [cmd, args, rootDir] def runQueue(self): for i in self.cmdQueue.values(): self.execute(i[2], i[0], i[1]) def execute(self, rootDir, cmd, args = ""): os.chdir(rootDir) if args == "": buildCmd = cmd else: args = args.split(" ") buildCmd = [cmd] + args self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) gobject.io_add_watch(self.buildPID.stdout, gobject.IO_IN, self.onGetData) As you can see, I add the commands "ls -l" and "echo Hello" to the queue. However, "Hello" is always printed inside the output of "ls -l". I would like to wait for "ls -l" to terminate and then run "echo Hello". But, the output must still print to the consoleLogBuffer line-by-line, and my GUI must not hang during execution. Is this even possible? From HardToSpell at gmail.com Thu Dec 14 02:57:11 2006 From: HardToSpell at gmail.com (Brian Mills) Date: 13 Dec 2006 23:57:11 -0800 Subject: Sorting Multidimesional array(newbie) In-Reply-To: References: <20061211193104.40fe7985.tartifola@gmail.com> <1165863508.967414.70350@73g2000cwn.googlegroups.com> <1165907463.624180.7990@79g2000cws.googlegroups.com> Message-ID: <1166083031.343359.63620@j72g2000cwa.googlegroups.com> Fredrik Lundh wrote: > Brian Mills wrote: > > > There's another (IMHO more readable) way to do it if you can afford > > defining a short little "compare" function, and telling .sort() > > to use that instead of its default: > > > >>>> def myListCmp(lst1, lst2): > > ... if lst1[0] < lst2[0]: return -1 > > ... if lst2[0] > lst2[0]: return 1 > > ... return 0 > > shorter: > > def myListCmp(a, b): > return cmp(a[0], b[0]) Good point. > but using a compare function instead of a key mapper is not good advice, > in general. brief discussion here: > http://effbot.org/pyfaq/i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python Is this mostly because of the stability problem described here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 ? Or is it more a performance issue due having to make so many function calls? > > also note the OP didn't specify what to do for records where the first > column was identical, so I guess a plain sort() call, without any custom > compares or mappings, would work as well as the fancier alternatives... I can't believe I didn't try this, but for the given example it works perfectly. It even acts gracefully when you give it such sociopathic lists as >>> c = [[3, 1], [8, 2], [6, 3], [12, 4], [1, 5], ["oh noes!", 6], [24, 7], [ope n("file.txt", 'r'), 8], [[1, 2, 3], 9]] >>> c.sort() >>> c [[1, 5], [3, 1], [6, 3], [8, 2], [12, 4], [24, 7], [, 8], [[1, 2, 3], 9], ['oh noes!', 6]] Though changing the ordering system it decides to use may take some more research. From robin at NOSPAMreportlab.com Wed Dec 20 16:45:12 2006 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Wed, 20 Dec 2006 21:45:12 +0000 Subject: [ANN] PyInstaller 1.3 released In-Reply-To: References: Message-ID: <4589AEE8.8070600@jessikat.plus.net> Giovanni Bajo wrote: ........ > yeah that's pretty cryptic. It's a known bug which I need to come around > and fix it. Anyway, the message itself is harmless: if the program then > exits, there is *another* problem. > > If you want to help with that, you could enable the console+debug mode > and see what the traceback is. I'd be very glad to fix the problem for you. No problem I'll give it a whirl tomorrow. -- Robin Becker From jon at ffconsultancy.com Sun Dec 3 00:00:12 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 03 Dec 2006 05:00:12 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> Message-ID: <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> Carl Banks wrote: > No, they're never redefined (even in the recursive version). Slices of > them are reassigned. That's a big difference. I see. > (Actually, it does create a temporary array to store the intermediate > result, but that array does not get bound to odd.) Sure. >> In particular, I think you are eagerly >> allocating arrays when, in a functional language, you could just as >> easily compose closures. > > You are completely wrong. I'll give an example. If you write the Python: a[:] = b[:] + c[:] + d[:] I think that is equivalent to the ML: fill a (map2 ( + ) (map2 ( + ) b c) d) which can be deforested in ML to avoid the creation of the intermediate result b[:] + c[:] by using a closure to add three values at once: fill a (map3 (fun b c d -> b + c + d) b c d) which will be much faster because it doesn't generate an intermediate array. > This data sharing more or less accomplishes the same thing that the > "closures" you speak of accomplish (in this case), only without the > functional. The closure avoided the intermediate result. You said that the Python isn't doing that? > It's not correct, but what you left out is probably low cost. > > OCaml is compiled to machine code, right? Yes. > And types can be inferred at compile time, correct? Types are completely inferred at compile time. > Well then of course it's faster. Yes. So this doesn't seem to be a killer example of numpy, although I am still amazed that it can outperform Matlab. > It seems to > me a big help is the ability to fold multiple array operations into a > single loop, which is optimization a dynamically-typed language like > Python can't easily make. (It'd require are really smart JIT compiler > or some concessions in dynamicity.) Writing a JIT to compile this kind of stuff is easy. My point is that this is fundamentally bad code, so why bother trying to write a Python JIT? Why not just write in a better language for this task? Optimising within a fundamentally slow language seems silly to me. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists From banaouas.medialog at wanadoo.fr Fri Dec 8 06:08:06 2006 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Fri, 08 Dec 2006 12:08:06 +0100 Subject: apache & mod_python Message-ID: <4579472d$0$5066$ba4acef3@news.orange.fr> Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major issue ? thanks for any help. From skip at pobox.com Fri Dec 29 09:14:10 2006 From: skip at pobox.com (skip at pobox.com) Date: Fri, 29 Dec 2006 08:14:10 -0600 Subject: Beginner question on text processing In-Reply-To: <2323A6D37908A847A7C32F1E3662C80E6B0E38@dc1ex01.air.org> References: <2323A6D37908A847A7C32F1E3662C80E6B0E38@dc1ex01.air.org> Message-ID: <17813.8882.671125.949337@montanaro.dyndns.org> Harold> To illustrate, assume I have a text file, call it test.txt, with Harold> the following information: Harold> X11 .32 Harold> X22 .45 Harold> My goal in the python program is to manipulate this file such Harold> that a new file would be created that looks like: Harold> X11 IPB = .32 Harold> X22 IPB = .45 ... This is a problem with a number of different solutions. Here's one way to do it: for line in open(filename, "r"): fields = line.split() print fields[0], "IPB =", fields[1] Skip From adam at atlas.st Sat Dec 23 17:38:19 2006 From: adam at atlas.st (Adam Atlas) Date: 23 Dec 2006 14:38:19 -0800 Subject: Getting the name of an assignment Message-ID: <1166913499.494219.250440@48g2000cwx.googlegroups.com> Is it possible for an object, in its __init__ method, to find out if it is being assigned to a variable, and if so, what that variable's name is? I can think of some potentially ugly ways of finding out using sys._getframe, but if possible I'd prefer something less exotic. (Basically I have a class whose instances, upon being created, need a 'name' property, and if it's being assigned to a variable immediately, that variable's name would be the best value of 'name'; to make the code cleaner and less redundant, it would be best if it knew its own name upon creation, just like functions and classes do, without the code having to pass it its own name as a string.) From tactics40 at gmail.com Sat Dec 9 19:32:33 2006 From: tactics40 at gmail.com (tac-tics) Date: 9 Dec 2006 16:32:33 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165701024.138305.241500@j72g2000cwa.googlegroups.com> Message-ID: <1165710753.495406.26740@j72g2000cwa.googlegroups.com> I think the lesson here is that LISP is the language you use when you want mathematical elegance and perfection and Python is the language you use if you want to actually program stuff. From grante at visi.com Sun Dec 3 11:52:33 2006 From: grante at visi.com (Grant Edwards) Date: Sun, 03 Dec 2006 16:52:33 -0000 Subject: Parsing data from pyserial References: <4572e860.53134312@news.comporium.net> Message-ID: <12n606he7k5uhb3@corp.supernews.com> On 2006-12-03, Si Ballenger wrote: > In my dealing with serial gizmos I have to put a delay between > the request sent to the gizmo and the reading of the serial input > buffer for returned data. Serial ports and gizmos need some time > to do their thing. I doubt that's the issue. He's reading with a 1-second timeout value. -- Grant Edwards grante Yow! The Korean War must at have been fun. visi.com From dickinsm at gmail.com Wed Dec 6 19:32:04 2006 From: dickinsm at gmail.com (dickinsm at gmail.com) Date: 6 Dec 2006 16:32:04 -0800 Subject: Mirror imaging binary numbers In-Reply-To: <12nenik4vn4olf1@corp.supernews.com> References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> <1165445569.287552.266120@j44g2000cwa.googlegroups.com> <1165446077.584437.206310@73g2000cwn.googlegroups.com> <1165448754.718593.200170@f1g2000cwa.googlegroups.com> <12nenik4vn4olf1@corp.supernews.com> Message-ID: <1165451524.468292.194630@16g2000cwy.googlegroups.com> On Dec 6, 7:20 pm, Grant Edwards wrote: > It's a little less obtuse if you spell it this way: > > def flipbits(x): > """reverse bits in a byte""" > x1 = x << 4 | x >> 4 > x2 = (x1 & 0x33) << 2 | (x1 & 0xcc) >> 2 > return (x2 & 0x55) << 1 | (x2 & 0xaa) >> 1 > Granted. And a little more obtuse this way: def flipbits(x): """reverse bits in a byte""" x += 255*(x & 15) x += 15*(x & 816) x += 3*(x & 5440) return x >> 7 I apologise---it's the end of a long day and I'm feeling more than a little contrary. Mark From tim.peters at gmail.com Wed Dec 13 03:24:30 2006 From: tim.peters at gmail.com (tim.peters at gmail.com) Date: 13 Dec 2006 00:24:30 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165991523.013767.224630@73g2000cwn.googlegroups.com> Message-ID: <1165998270.742602.23610@f1g2000cwa.googlegroups.com> [Bill Atkins] >> (Why are people from c.l.p calling parentheses "brackets"?) [Kaz Kylheku] > Because that's what they are often called outside of the various > literate fields. For example, the English are "outside of the various literate fields"? FWIW, Python documentation consistently uses the jargon: () parentheses {} braces [] brackets That matches North American conventions, but occasionally confuses an international audience (for example, the English call parentheses "brackets" or "round brackets"). There's also a long tradition in both mathematics and computer science of using "bracket" as a generic term for any syntactic device used in pairs. For example, the "Revised Report on the Algorithmic Language Algol 60" way back in 1963 even called "begin" and "end" brackets. If it's tempting to call the authors of that illiterate too, keep in mind that John McCarthy was one of them -- although I'm sure Peter Naur would be willing to take the blame for dumbing it down for Europeans ;-) From deets at nospam.web.de Wed Dec 6 04:40:33 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 06 Dec 2006 10:40:33 +0100 Subject: Novice: replacing strings with unicode variables in a list References: <1165397220.491511.159310@f1g2000cwa.googlegroups.com> Message-ID: <4tnhghF14nrt7U1@mid.uni-berlin.de> aine_canby at yahoo.com wrote: > Hi, > > Im totally new to Python so please bare with me. > > Data is entered into my program using the folling code - > > str = raw_input(command) > words = str.split() > > for word in words: > word = unicode(word,'latin-1') > word.encode('utf8') > > This gives an error: > > File "C:\Python25\lib\encodings\cp850.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in > position 0 > : character maps to > > but the following works. > > str = raw_input(command) > words = str.split() > > for word in words: > uni = u"" > uni = unicode(word,'latin-1') > uni.encode('utf8') This is the exact same code as the one above - there is no type declaration in python, so your uni = u'' statement is bollocks. And I seriously doubt, that the above code and the above error message are related - as you can see, the error is from cp850, a windows codepage. But that isn't in the code above - so there must be something else happening. Please provide the full script, and the desired input - then we might be able to help you. Diez From sjmachin at lexicon.net Thu Dec 21 17:59:26 2006 From: sjmachin at lexicon.net (John Machin) Date: 21 Dec 2006 14:59:26 -0800 Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> Message-ID: <1166741966.242087.192390@n67g2000cwd.googlegroups.com> Bruno Desthuilliers wrote: > > Python is dynamic, and fighting against the language is IMHO a really > bad idea. The only places where theres a real need for this kind of > stuff are when dealing with the "outside world" (IOW : inputs and > outputs). And then packages like formencode can do much more than mere > type-checking > Agreed. The worst case I have seen: An elaborate decorator (similar to the OP's) laboriously checks arg types. That's IMHO not "consenting adults" territory. But it gets a whole lot worse when it's applied to a method whose body is like this: if isinstance(.... action_for_type1(... # big snip elif isinstance(... action_typeN( ... # no else statement From skip at pobox.com Sun Dec 17 11:40:51 2006 From: skip at pobox.com (skip at pobox.com) Date: Sun, 17 Dec 2006 10:40:51 -0600 Subject: converting mysql db into sqlite3. In-Reply-To: <1166301034.594220.154430@16g2000cwy.googlegroups.com> References: <1166301034.594220.154430@16g2000cwy.googlegroups.com> Message-ID: <17797.29459.306093.840006@montanaro.dyndns.org> gordy> You could probably use the mysqldump command with the proper gordy> options to export the contents of your mysql database to an ASCII gordy> text file that contains the SQL insert statements. Not sure where the original post is. All I see is this reply. In case the OP is listening, I believe you can do this in a fairly straightforward manner with SQLAlchemy. Skip From eldorado at io.com Wed Dec 27 11:37:52 2006 From: eldorado at io.com (eldorado) Date: Wed, 27 Dec 2006 10:37:52 -0600 Subject: getting a process's PID Message-ID: <20061227102939.L20663@eris.io.com> Hello, I am trying to get python to give me the PID of a process (in this case HUB). I have it working, except for the fact that the output includes \012 (newline). Is there a way to ask python not to give me a newline? Python 1.4 (Oct 14 1997) [C] Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import os >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") >>> h = g.readlines() >>> g.close() >>> h ['87334\012'] Thanks in advanced for any guidance. -- Randomly generated signature Whoever said nothing is impossible never tried slamming a revolving door. From tony at PageDNA.com Sun Dec 31 10:41:32 2006 From: tony at PageDNA.com (Tony Lownds) Date: Sun, 31 Dec 2006 07:41:32 -0800 Subject: PEP 3107 Function Annotations for review and comment In-Reply-To: <1167568000.728842.170160@48g2000cwx.googlegroups.com> References: <1167568000.728842.170160@48g2000cwx.googlegroups.com> Message-ID: On Dec 31, 2006, at 4:26 AM, Kay Schluehr wrote: > I have two questions: > > 1) I don't understand the clause ('*' [tname] (',' tname ['=' test])* > in the grammar rule of typedargslist. Does it stem from another PEP? > Yes, PEP 3102 Keyword-only Arguments. > 2) Is the func_annotation information for def foo(*c: list) > stored as {"*c": list} preserving optional argument information or > {"c":list} ? > {"c": list} -Tony From frank at niessink.com Fri Dec 15 18:57:49 2006 From: frank at niessink.com (Frank Niessink) Date: Sat, 16 Dec 2006 00:57:49 +0100 Subject: Has comparison of instancemethods changed between python 2.5 and 2.4? In-Reply-To: References: <4582CFA3.5040305@niessink.com> Message-ID: <4583367D.7090508@niessink.com> Fredrik Lundh: > Frank Niessink wrote: > > > However, the instance the two methods belong to are different, i.e. > > id(callback) returns different values for the two methods. > > are you using the *object* as the callback? otherwise, that sentence > doesn't make much sense; You are right, that sentence doesn't make much sense. The callbacks are instance methods, not the objects themselves. What I meant to say is that both the instances are different and the callbacks are different (i.e. their id is different), but the callbacks still compare as equal. So I have to instance methods where: id(instancemethod1) != id(instancemethod2) but instancemethod1 == instancemethod2. However, your explanation below explains why the id of the instance methods may be different. > bound methods are generated on the fly, and the > identity may or may not be reused, depending on how things are garbage > collected: > > >>> f.bar > > > >>> id(f.bar) > 10322248 > >>> id(f.bar) > 10322328 > >>> id(f.bar) > 10322328 > >>> id(f.bar) > 10322328 > >>> id(f.bar), id(f.bar) > (10322328, 10322328) > >>> map(id, (f.bar, f.bar, f.bar)) > [10322328, 10322248, 10322368] OK, so that explains why the id of (two references to the same) instancemethod(s) may differ. But I'm still confused why two instancemethods of two different instances can compare as equal. Thanks, Frank From txd007 at gmail.com Sun Dec 31 11:07:33 2006 From: txd007 at gmail.com (FREEDOM) Date: 31 Dec 2006 08:07:33 -0800 Subject: Do You Want To Be An Internet Millionaire? Message-ID: <1167581253.297389.275830@n51g2000cwc.googlegroups.com> Dumb question, right? Of course you do! Problem is, who is going to help you do it? That's where Worldprofit's Millionaire Mentoring Magic Millionaire Playbook comes in. It's produced by three self-made MULTI-Millionaires with over 36 combined years of Internet experience -- George Kosch, Sandi Hunter and Dr. Jeffrey Lant. These 100% client-centered experts have produced the detailed, step-by-step playbook you've been waiting for with EVERYTHING you need to become an online Millionaire! The Millionaire Playbook -- Millionaire Mentoring Magic -- is a unique combination of videos, written instructions, and live and recorded webcasts -- all designed to give you what you need to know and do to profit online -- whatever business you're in, whatever level of business expertise and experience you have. IMPORTANT! Unlike traditional books and information products, once you have acquired the Millionaire Playbook you get ALL subsequent edits and enhancements FREE forever! That means you permanently have three of the Internet's leading authorities -- George Kosch, Sandi Hunter, and Dr. Lant -- on your team FOREVER. Get ALL the details on this incredible step-by-step guide to maximizing your online income by clicking below and learning more about MILLIONAIRE MENTORING MAGIC. That's where you'll find complete details and a detailed video by Dr. Jeffrey Lant. Click Here: http://wealthcaptains.com/default.cfm?pageid=28401 HAPPY NEW YEAR! P.S. You won't believe these websites I found: http://www.DesktopLightning.com/letshare http://www.agloco.com/r/BBBD6685 From nagle at animats.com Thu Dec 14 22:56:13 2006 From: nagle at animats.com (John Nagle) Date: Fri, 15 Dec 2006 03:56:13 GMT Subject: MySQLdb windows binaries for Python 2.5?? Yes, but from a World of Warcraft guild. In-Reply-To: <1166144355.616642.127080@n67g2000cwd.googlegroups.com> References: <1162408100.985370.148650@m7g2000cwm.googlegroups.com> <1163238145.257490.144410@b28g2000cwb.googlegroups.com> <1166144355.616642.127080@n67g2000cwd.googlegroups.com> Message-ID: Fuzzyman wrote: > johnf wrote: > >>John Nagle wrote: >> >> >>>Jan Dries wrote: >>> >>>>Henk.van.Asselt at gmail.com wrote: >>>> >>>> >>>>>I'm also looking for a MySQLdb binary for windows. This is holding me >>>>>from upgrading from Python 2.4 to Python 2.5 ! >>>>> >>>> >>>>If you search the Help Forum of the MySQLdb project on SourceForge, you >>>>will find a couple of people who have successfully built MySQLdb on >>>>Windows for 2.5, and are willing to share their installers. >>>>That's how I got my binaries. >>>> >>>>Regards, >>>>Jan >>> >>> Yes, see >>> >>>http://sourceforge.net/forum/forum.php?thread_id=1571110&forum_id=70461 >>> >>>for an untested version created by a World of Warcraft guild: >>> >>> >> >>http://www.guildmanus.com/uploaded/MySQL-python.exe-1.2.2b2.win32-py2.5.exe >> >>>This, apparently, is the extent of current Python support for MySQL. >>>Want to install that executable, as root, on your production machines? >>> >>>This is embarassing for the Python community. Perl and PHP come >>>with MySQL support built in. Python is out to lunch on this. >>> >>>John Nagle >>>Animats >> >>I couldn't disagree more. That fact that no Database drivers are built-in >>makes Python stronger - allowing Python to access any Data Engine that >>supports DBI 2.0. Of course I'm not including pickle in my assessment. >> > > > And providing 'built-in' drivers for massively popular databases would > prevent that from being true how ? > > Fuzzyman What's happened is that Python fell through the cracks here. MySQL themselves support Java, Microsoft ".NET", PHP, and a C interface. The Perl interface to MySQL is part of the supported Perl distribution. But for for Python, everybody is running on glue code from one guy on Sourceforge, and he's having problems keeping up. Oops. John Nagle From address.good.until.2006.dec.22 at justmail.de Mon Dec 11 14:01:31 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Mon, 11 Dec 2006 20:01:31 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1165764570.956203.223370@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165764570.956203.223370@16g2000cwy.googlegroups.com> Message-ID: mystilleef schrieb: > Ken Tilton wrote: >> Lisp has all the cool qualities you like in your pets, plus native >> compilation in most implementations, plus maturity and a standard, plus >> a better OO, plus macros, plus a dozen more small wins. Including >> automatic indentation. :) >> > > Better OO? You mean the one that doesn't support basic encapsulation > and is retardedly cumbersome to use? There's a reason I said, I'd never > use Lisp for OO not even when I'm high. Gimme Python, Eiffel or > Smalltalk anyday, not the retarded add-on package bolted on CL. What do you mean with "encapsulation" in this context? I am looking for something that Pythons or Smalltalks OO system have which isn't in Lisps... Andr? -- From R.Brodie at rl.ac.uk Fri Dec 8 10:29:15 2006 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Fri, 8 Dec 2006 15:29:15 -0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> Message-ID: "Alex Mizrahi" wrote in message news:45797a0c$0$49204$14726298 at news.sunsite.dk... > heh, do you have "standard numeric packages" for everything? maybe then we'll make > standard programs for everything -- that will obsolete "slow" "custom scripts" and we'll > just use shell to select what program we want to run? No, I was observing that, faced with a matrix multiplication problem, most sensible Python developers would do "apt-get install python-numeric" or equivalent. Trying to do it in pure Python would be the wrong tool for the job. If you think that's a weakness of Python compared to Lisp, then so be it. From nmm1 at cus.cam.ac.uk Thu Dec 21 05:15:54 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 21 Dec 2006 10:15:54 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com> In article , "Hendrik van Rooyen" writes: |> "Nick Maclaren" wrote: |> |> > Not at all. I didn't say that they came in pairs. Consider: |> > |> > [str1, str2, agent1, str3, agent2, agent3, agent4, str4, ...] |> > |> > See Algol 68 for an example of this. |> |> When I looked at the above, I went "tilt" - Yes, you are confused :-) Neither the agents nor strings take the other as 'arguments', but are effectively methods of the I/O object. Let's consider a modern example: a text editor with hyperlink facilities. Note that I am referring to the hyperlinks of the kind that can occur anywhere, and not those associated with a particular, usually highlighted, word. Text is a sequence of letters/words/sentences/paragraphs/markup/etc.; let's assume words, as strings, for the purpose of argument. Words can be inserted, deleted, changed etc. Hyperlinks are agents and can be added at any point. Their only relationship with the text is the position at which they occur (i.e. none or more may occur between any two consecutive words). Regards, Nick Maclaren. From int2k at gmx.net Sun Dec 10 03:47:47 2006 From: int2k at gmx.net (Wolfram Fenske) Date: 10 Dec 2006 00:47:47 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xhcw4gowx.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> Message-ID: <1165740467.112594.303950@l12g2000cwl.googlegroups.com> Paul Rubin writes: > "Wolfram Fenske" writes: [...] >> > I just don't see a non-messy way to simulate Python generators in CL. >> > They can be done in Scheme using call/cc though. >> >> Scheme is also a Lisp. So? > > No I don't buy that, you can't say Scheme is Lisp when it suits you to > do so and that it isn't Lisp at other times. OK, I cheated a bit. (Although when I say "Lisp" I don't necessarily mean Common Lisp. Scheme is also Lisp.) You are right about call/cc and probably also about lexical variables. I have to modify my statement from "All the interesting features that haven't originated from Lisp could easily be implemented in Lisp" to "A lot of the interesting features ...". Assertions starting with "all" are a dangerous business because usually someone comes along with a counter-example. I should have been more careful when I wrote that. What I meant to say with the two sentences "a lot of 'modern' language features have originated from Lisp" and "a lot of the interesting features that haven't originated from Lisp could easily be implemented in Lisp" was that I believe that Lisp has hit a sweet spot in the programming language continuum. It must have been right about a lot of things to still be alive and kicking after all this time. [...] >> > http://www.math.chalmers.se/~rjmh/Papers/whyfp.html >> > >> > The examples in it are pretty easy to do in Python or Scheme, but I >> > think not so easy in CL. >> >> Anything in particular? I'd be surprised if the solutions in Scheme >> and CL would differ very much > > I took it back, Sorry, I only noticed that after posting. -- Wolfram Fenske A: Yes. >Q: Are you sure? >>A: Because it reverses the logical flow of conversation. >>>Q: Why is top posting frowned upon? From Roka100 at gmail.com Wed Dec 6 03:22:25 2006 From: Roka100 at gmail.com (Jia Lu) Date: 6 Dec 2006 00:22:25 -0800 Subject: How to use MySQL without MySQLdb module Message-ID: <1165393345.495393.53190@16g2000cwy.googlegroups.com> Hi all. I am using a hosting space with python cgi. But this host haven't got MySQLdb installed. Is there any methods to connect to Mysql without MySQLdb. Or any other DB methods with original python release? Thanx From kay.schluehr at gmx.net Mon Dec 4 12:16:32 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 4 Dec 2006 09:16:32 -0800 Subject: Ensure a variable is divisible by 4 In-Reply-To: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: <1165252592.442480.256570@80g2000cwy.googlegroups.com> geskerr... at hotmail.com schrieb: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. Division with rest: >>> x % 4 3 From Leo.Kislov at gmail.com Wed Dec 13 03:54:40 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 13 Dec 2006 00:54:40 -0800 Subject: how can i write a hello world in chinese with python References: <1165982024.978824.146920@n67g2000cwd.googlegroups.com> <1165985255.490054.290680@80g2000cwy.googlegroups.com> <1165995641.270460.124350@73g2000cwn.googlegroups.com> Message-ID: <1166000079.850607.80390@j72g2000cwa.googlegroups.com> kernel1983 wrote: > and I tried unicode and utf-8 How did you try unicode? Like this? : EasyDialogs.Message(u'\u4e2d') > I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not > to use > > Anyone knows about the setting in the python code file? > Maybe python doesn't know I'm to use chinese?! It depends on how EasyDialogs works. And by the way, when you say utf-8 encoded text is not displayed correctly, what do you actually see on the screen? -- Leo From address.good.until.2006.dec.22 at justmail.de Fri Dec 15 13:42:34 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=) Date: Fri, 15 Dec 2006 19:42:34 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1166207152.706475.76020@t46g2000cwa.googlegroups.com> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <1166207152.706475.76020@t46g2000cwa.googlegroups.com> Message-ID: William James schrieb: I suppose that is Ruby code. So my statement was correct when I said: "In some languages it would look a bit cleaner, for example Ruby." This is because it has a minimal syntax for "lambda". > def p > puts "very positive" > "positive" > end > def z > puts "no no" > "zero" > end > def n > puts "very negative" > "negative" > end > def nif num, pos, zero, neg > send( num>0 ? pos : (num==0 ? zero : neg) ) > end This code would work > [0, 2.5, -8].map{|x| nif x, :p, :z, :n} See how you move away from the idea of an if. Here you need to say :p, :z, :n. That is not much better as Lisps #' > ### Another way ##### > > p = proc { > puts "very positive" > "positive" } > z = proc { > puts "no no" > "zero" } > n = proc { > puts "very negative" > "negative" } > def nif num, pos, zero, neg > ( num>0 ? pos : (num==0 ? zero : neg) ).call > end > > [0, 2.5, -8].map{|x| nif x, p, z, n} But will this version also work this way: [0, 2.5, -8].map{|x| nif x, "p", "z", "n"} You can't express it like an "if" in Ruby. In Lisp it is like an IF and represents exactly what we think. IF in Lisp: (if expr (then-part) (else-part)) nif in Lisp: (nif expr (positive-part) (zero-part) (negative-part)) It looks as if it were a construct directly built into Lisp. If one wants one could even add some additional syntax, so that it looks like: (nif expr positive: (foo1) (foo2) zero: (foo3) negative: (foo4)) If you regard that idea nonsense then I suggest you to not use Rubys if-statement anymore. But instead program your own version "RubyIF" so that in future you have to pass all code inside blocks to your RubyIF function. If you *really* think that the Lisp savings are not worth it, then you would begin with my suggestion today. Andr? -- From vedran at v-programs.com Fri Dec 1 07:05:29 2006 From: vedran at v-programs.com (Croteam) Date: 1 Dec 2006 04:05:29 -0800 Subject: python voip modules Message-ID: <1164974729.251625.236660@n67g2000cwd.googlegroups.com> Hello, If somebody know any python module that uses voip or sip except shtoom and yate Please tell me full url of that module or send to vedran at v-programs.com. Thanks,I will really appreciate that!!!!!!!! From martin at v.loewis.de Fri Dec 29 19:53:48 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 30 Dec 2006 01:53:48 +0100 Subject: bad marshal data in site.py in fresh 2.5 install win In-Reply-To: References: Message-ID: <4595B89C.9090208@v.loewis.de> TiNo schrieb: > # G:\Python25\lib\encodings\aliases.pyc matches [...] > File "F:\Python25\lib\encodings\__init__.py", line 32, in > > What can I do about this? Where does F:\Python25 come from? If you have set any PYTHON* environment variables (e.g. PYTHONPATH), unset them. Regards, Martin From ajones1 at gmail.com Thu Dec 7 15:34:40 2006 From: ajones1 at gmail.com (Adam Jones) Date: 7 Dec 2006 12:34:40 -0800 Subject: Can't 'register' to Cheese Shop from command line..only web + egg dependency question In-Reply-To: <1165521216.869978.151290@16g2000cwy.googlegroups.com> References: <1165521216.869978.151290@16g2000cwy.googlegroups.com> Message-ID: <1165523680.605645.160650@j44g2000cwa.googlegroups.com> seberino at spawar.navy.mil wrote: > I seem to be able to register and upload from web site but not command > line. Command line register attempts keep giving " Server response > (401): Authorization Required" > > Any ideas? You probably need to set up a .pypirc file in your home directory. Info here: http://www.python.org/~jeremy/weblog/030924.html > > & What must I do to make installation of my egg also install > dependencies? I did an install and noticed other eggs didn't come > along for > the ride. Your setup.py file should have a "install_requires" parameter to the setup function. Most likely it is a list. Add the names of the projects you are trying to require and (optionally) the version. Here is a sample: install_requires = [ "FooBar", # installs latest version of 'FooBar' "Stump >= 1.0b2"], # installs 'Stump' of version 1.0b2 or later Full docs on this are here: http://peak.telecommunity.com/DevCenter/setuptools -Adam > > Chris From stas at legche.net Mon Dec 18 07:37:26 2006 From: stas at legche.net (=?KOI8-R?Q?=F3=D4=C1=CE=C9=D3=CC=C1=D7_=F1=C7=CC=CF?=) Date: Mon, 18 Dec 2006 15:37:26 +0300 Subject: How to get a substring with variable indices Message-ID: <45868B86.6010804@legche.net> Hello all! I have a string named text. I need to extract a substring from it starting by variable 's' and ending by 'e'. text[s:e] generates the following error: TypeError: slice indices must be integers or None How to be? :) Regards, Stanislav Yaglo. From huayang.xia at gmail.com Tue Dec 19 10:27:06 2006 From: huayang.xia at gmail.com (Huayang Xia) Date: 19 Dec 2006 07:27:06 -0800 Subject: When Closure get external variable's value? In-Reply-To: References: <1166473333.593246.238580@73g2000cwn.googlegroups.com> <1166474513.700608.201760@48g2000cwx.googlegroups.com> Message-ID: <1166542026.913912.82880@t46g2000cwa.googlegroups.com> Thanks for the clarification. But my question is: When does the closure get the value of the maxIndex in the following code snippet? def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest() print testClosure(10) I thought it should be 10 instead of 15. That was wrong. After several tests, I found maxIndex is, though, local to testClosure() but is external to the closureTest(). closureTest() gets the value of maxIndex at run time. So that it's 15 instead of 10. The following snippet will verify that further: def testClosure1(lst): def closureTest(): lst.append(lst[-1]+1) lst.append(lst[-1]+1) return closureTest() alist = [1] testClosure1(alist) alist.append(3) testClosure1(alist) The 'lst' in function testClosure1() and the closure closureTest() are same thing as alist. So everything is dynamic. Variable's value is determined at run time. From vedran at v-programs.com Sat Dec 2 07:03:53 2006 From: vedran at v-programs.com (Croteam) Date: 2 Dec 2006 04:03:53 -0800 Subject: ftputil upload error Message-ID: <1165061033.876956.275880@f1g2000cwa.googlegroups.com> Hello, I have one problem about ftputil file upload.Here is my short example: from ftputil import FTPHost import tkFileDialog import os from Tkinter import Tk ftp=FTPHost('myserver','username','password') forupload=tkFileDialog.askopenfile(parent=root) file=forupload.name ## I was choose file C:/Documents and Settings/VEKI/My Documents/internet/popravak.txt ## ftp.upload(file,os.path.basename(file)) THEN I GAIN ERROR: Traceback (most recent call last): File "", line 1, in -toplevel- ftp.upload(file,os.path.basename(file),'b') File "C:\Python24\lib\ftputil.py", line 417, in upload self.__copy_file(source, target, mode, open, self.file) File "C:\Python24\lib\ftputil.py", line 406, in __copy_file target = target_open(target, target_mode) File "C:\Python24\lib\ftputil.py", line 245, in file host._file._open(effective_file, mode) File "C:\Python24\lib\ftp_file.py", line 115, in _open self._conn = ftp_error._try_with_ioerror( File "C:\Python24\lib\ftp_error.py", line 101, in _try_with_ioerror raise FTPIOError(ftp_error) FTPIOError: 550 popravak.txt: Access is denied. Debugging info: ftputil 2.1, Python 2.4.2 (win32) Regards, Vedran From not at valid.com Wed Dec 27 11:45:03 2006 From: not at valid.com (yomgui) Date: Wed, 27 Dec 2006 16:45:03 GMT Subject: how can I modify an imported variable ? References: Message-ID: hi, your sample code works, but mine doesn't. it must be a multi-thread issue. I am certain that I am modifying MyPackage.aVariable before using it. Both threads are importing MyPackage, but the modification of MyPackage.aVariable is not seen by the other thread. is this possible ? is there a turn around to allow it ? thanks yomgui From sebastien.ramage at gmail.com Thu Dec 7 01:31:28 2006 From: sebastien.ramage at gmail.com (=?iso-8859-1?q?S=E9bastien_Ramage?=) Date: 6 Dec 2006 22:31:28 -0800 Subject: Python Plugin for Web Browser In-Reply-To: References: <1165389943.093365.20590@80g2000cwy.googlegroups.com> <1165391969.824391.174140@l12g2000cwl.googlegroups.com> <1165416520.077655.58540@16g2000cwy.googlegroups.com> Message-ID: <1165473088.148215.58030@f1g2000cwa.googlegroups.com> > Par contre, je pense qu'il existe une autre d?marche, qui consiste ? > g?n?rer, ? la vol?e, en Python, des sortes d'applets java/javascript. Il est clair que mon projet est un peu plus complexe mais je l'esp?re plus ambitieux aussi Le but ?tant vraimment de faire des applets en Python et non Java via Jython ou autre > Avantages : rien ? installer ; milti-navigateurs > Inconv?nient : ?a se programme c?t? serveur. > Voir : Pyjamas (http://pyjamas.pyworks.org/FR/overview/) oui d'ailleurs un utilisateur de Pyjamas m'a d?j? contact? et il serait int?ress? par un plugin tel que je l'imagine. Concernant les avantages je ne suis pas d'accord avec toi: - "rien ? installer" : oui par javascript mais non pour java il y a le runtime ? installer donc finalement avoir un runtime Python pourquoi pas - multi-navigateur : idem, rien n'interdit d'avoir un plugin multi-plateforme et multi-navigateur, Java le fait bien lui alors pourquoi pas Python bref ?a va certainement poser des tas de probl?mes de s?curit? et je pense qu'un plugin 100% op?rationnel ne verra pas le jour avant un bon moment mais rien n'emp?che de se lancer dans l'aventure ! Seb From rampeters at gmail.com Tue Dec 12 15:10:33 2006 From: rampeters at gmail.com (johnny) Date: 12 Dec 2006 12:10:33 -0800 Subject: newb: Creating Exception In-Reply-To: References: <1165881722.928958.81490@79g2000cws.googlegroups.com> Message-ID: <1165954233.519919.107940@l12g2000cwl.googlegroups.com> Thank you Dennis, So when line 2, gets executed, its exception goes to do_some1_error. And when line 3, gets executed, its exception goes to do_some2_error and so on. line 1: try line 2: do_some1 line 3: do_some2 line 4: do_some3 line 5: except do_some1_error: line 6: whatever1 line 7: except do_some2_error: line 8: whatever2 line 9: except do_some3_error: line 10: whatever3 Documentation is not written for newbs, it's written by guys with 6yrs of experience FOR guys with 6yrs of experience. Dennis Lee Bieber wrote: > On 11 Dec 2006 16:02:02 -0800, "johnny" declaimed > the following in gmane.comp.python.general: > > > I want to print individual exception for database connection, sql > > execution, database closing, closing the cursor. Can I do it with one > > try..catch or I need a nested try...catch? > > Python does not have a "catch" instruction. > > You could do: > > try: > make connection #though that should, in my mind, be done > #as part of the initialization of the thread > #and not as part of any processing loop > make cursor > execute sql > fetch results if any > close cursor > commit transaction > close connection #which I'd make part of the termination > #of the thread > except Exception1, msg: > do something > except Exception2, msg: > do something2 > ... > > IF each step raises a different exception type -- if all the database > returns is "DatabaseError", then there is nothing to separate them by. > Also note that if an exception happens in the "execute sql" stage, your > handler may need to do a rollback, and the closes. > > -- > Wulfraed Dennis Lee Bieber KD6MOG > wlfraed at ix.netcom.com wulfraed at bestiaria.com > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: web-asst at bestiaria.com) > HTTP://www.bestiaria.com/ From georgi at molgen.mpg.de Fri Dec 15 09:42:38 2006 From: georgi at molgen.mpg.de (Benjamin Georgi) Date: Fri, 15 Dec 2006 15:42:38 +0100 Subject: parsing a dictionary from a string Message-ID: <4582B45E.6000405@molgen.mpg.de> Hello list, I could use some help extracting the keys/values of a list of dictionaries from a string that is just the str() representation of the list (the problem is related to some flat file format I'm using for file IO). Example: >>> s = str(dict_list) >>> s '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]' Then, what I want to do is to reconstruct dict_list given s. Now, one possible solution would be >>> dict_list = eval(s) but since the content of s cannot be blindly trusted I`d rather not do it that way. Basically my question is whether there is another solution which is simpler than using regular expressions. Best, Benjamin From ptmcg at austin.rr._bogus_.com Sat Dec 16 04:19:13 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sat, 16 Dec 2006 09:19:13 GMT Subject: parsing a dictionary from a string References: Message-ID: "Benjamin Georgi" wrote in message news:mailman.1655.1166194994.32031.python-list at python.org... > Hello list, > > I could use some help extracting the keys/values of a list of dictionaries > from a string that is just the str() representation of the list (the > problem is related to some flat file format I'm using for file IO). > > Example: > >>> s = str(dict_list) > >>> s > '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]' > Pyparsing comes with a working example that will parse strings representing lists, even if they are nested. This is actually more complex than the example you've given - none of your lists is nested. Here is that example, adapted to handle dict elements, too. -- Paul (The pyparsing home page/wiki is at pyparsing.wikispaces.com.) from pyparsing import * cvtInt = lambda toks: int(toks[0]) cvtReal = lambda toks: float(toks[0]) cvtTuple = lambda toks : tuple(toks.asList()) cvtDict = lambda toks: dict(toks.asList()) # define punctuation as suppressed literals lparen,rparen,lbrack,rbrack,lbrace,rbrace,colon = \ map(Suppress,"()[]{}:") integer = Combine(Optional(oneOf("+ -")) + Word(nums))\ .setName("integer")\ .setParseAction( cvtInt ) real = Combine(Optional(oneOf("+ -")) + Word(nums) + "." + Optional(Word(nums)))\ .setName("real")\ .setParseAction( cvtReal ) tupleStr = Forward() listStr = Forward() dictStr = Forward() listItem = real|integer|quotedString.setParseAction(removeQuotes)| \ Group(listStr) | tupleStr | dictStr tupleStr << ( Suppress("(") + Optional(delimitedList(listItem)) + Optional(Suppress(",")) + Suppress(")") ) tupleStr.setParseAction( cvtTuple ) listStr << (lbrack + Optional(delimitedList(listItem) + Optional(Suppress(","))) + rbrack) dictEntry = Group( listItem + colon + listItem ) dictStr << (lbrace + Optional(delimitedList(dictEntry) + \ Optional(Suppress(","))) + rbrace) dictStr.setParseAction( cvtDict ) tests = """['a', 100, ('A', [101,102]), 3.14, [ +2.718, 'xyzzy', -1.414] ] [{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]""" for test in tests.split("\n"): print "Test:", test.strip() result = listStr.parseString(test) print "Result:", result for dd in result: if isinstance(dd,dict): print dd.items() print Prints: Test: ['a', 100, ('A', [101,102]), 3.14, [ +2.718, 'xyzzy', -1.414] ] Result: ['a', 100, ('A', [101, 102]), 3.1400000000000001, [2.718, 'xyzzy', -1.4139999999999999]] Test: [{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}] Result: [{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}] [(0, [2]), (1, [])] [(0, []), (1, []), (2, [])] [(0, [1, 2])] From hong.file at gmail.com Sun Dec 3 09:50:18 2006 From: hong.file at gmail.com (progman) Date: 3 Dec 2006 06:50:18 -0800 Subject: cursor.executemany() float error In-Reply-To: References: <1165155896.161125.186490@j72g2000cwa.googlegroups.com> Message-ID: <1165157418.638862.171950@73g2000cwn.googlegroups.com> i am using mysql i tried the cursor.executemany('insert into promo (`From`,`To`, `RATE`) \ values (%s,%s,%s)', [ ('AA','BB',10.2), ('CC','DD',10.3) ] ) and it works. very strange. isn't it????? Fredrik Lundh wrote: > progman wrote: > > > cursor.executemany('insert into promo (`From`,`To`, `RATE`) \ > > values (%s,%s,%f)', [ ('AA','BB',10.2), ('CC','DD',10.3) ] ) > > > > i got this error: > > TypeError: float argument required > > > > i checked, 10.2 & 10.3 , there are at the right loc. > > what went wrong?? > > posting a bit more of the traceback, and mentioning what database you're > using might be helpful. > > have you tried using "%s" markers for all parameters, btw? (SQL data > binding and %-style string formatting are two different things, after all). > > From jan.dries at dcube-resource.be Mon Dec 11 21:09:55 2006 From: jan.dries at dcube-resource.be (Jan Dries) Date: Tue, 12 Dec 2006 03:09:55 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7x64ch7vud.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165867527.389209.80660@f1g2000cwa.googlegroups.com> <7x64ch7vud.fsf@ruckus.brouhaha.com> Message-ID: <457E0F73.7070805@dcube-resource.be> Paul Rubin wrote: > In musical terms, Python is like a Beatles song, very popular > and easy to sway and dance to. Lisp is like a Bach fugue. While I agree with your point in principle, I think that comparing Python to a Beatles song doesn't give the language the credit it IMO deserves. To avoid another thread like this one I will not state what language I would compare to a Beatles song, but if Lisp is a Bach fugue then Python I think is more like Mozart. Sure, Bach is the ultimate Master, no doubt. But Mozart wrote some damn fine music, often heavily borrowing ideas not only from Bach but also other masters (Handel for instance), but turning the whole into "something popular and easy to sway and dance to". Come to think of it, there definitely is something pythonic to Mozart ... Regards, Jan From ptmcg at austin.rr._bogus_.com Mon Dec 4 18:30:24 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 04 Dec 2006 23:30:24 GMT Subject: Factory pattern implementation in Python References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> <1165263327.407166.276160@l12g2000cwl.googlegroups.com> Message-ID: wrote in message news:1165263327.407166.276160 at l12g2000cwl.googlegroups.com... > Dennis Lee Bieber: >> Presuming the is a type code I'd just set up a list of >> functions: >> Then create a dictionary of them, keyed by the code >> processors = { "1" : process_1, >> "2" : process_2, >> .... >> "x" : process_x } > > Just a dict of functions was my solution too, I think avoiding more > complex solutions is positive. > > Bye, > bearophile > I think I'd go one step up the OO ladder and match each event code to a class. Have every class implement a staticmethod something like "load(stream)" (using pickle terminology), and then use a dict to dispatch. eventTypes = { "1" : BlahEvent, "2" : BlehEvent, "3" : BelchEvent, "4" : BlechEvent } eventObj = eventTypes[ stream.read(1) ].load( stream ) Now transcending from plain-old-OO to Pythonic idiom, make this into a generator: eventTypes = { "1" : BlahEvent, "2" : BlehEvent, "3" : BelchEvent, "4" : BlechEvent } def eventsFromStream(stream): while not stream.EOF: evtTyp = stream.read(1) yield eventTypes[evtTyp].load(stream) and then get them all in a list using list( eventsFromStream( stream ) ) -- Paul From dingbat at codesmiths.com Mon Dec 4 11:00:53 2006 From: dingbat at codesmiths.com (Andy Dingley) Date: 4 Dec 2006 08:00:53 -0800 Subject: rdf, xmp In-Reply-To: <457153cd$0$13323$426a34cc@news.free.fr> References: <457153cd$0$13323$426a34cc@news.free.fr> Message-ID: <1165248052.949748.17850@73g2000cwn.googlegroups.com> Imbaud Pierre wrote: > I have to add access to some XMP data to an existing python > application. > XMP is built on RDF, I'm just looking at the XMP Spec from the Adobe SDK. First impressions only, as I don't have time to read the whole thing in detail. This spec doesn't inspire me with confidence as to its accuracy and consistency. I think I've already seen some obscure conditions where developers will be unable to unambiguously interpret the spec. Compared to MPEG-7 however, at least it's not 700 pages long! The spec does state that property values can be structured, which is one of the best reasons to start using RDF for storing metadata. However I think actual use of these would be minimal in "typical" XML applicaations. At worst it's a simple data typing exercise of a two-valued tuple for "dimensions", rather than separate height and width properties. These are no problem to process. In particular, the XMP data model is a single-rooted tree, i.e. there is an external model of "a resource" (i.e. one image file) and an XMP document only addresses a single "resource" at a time. A major restriction in XMP is that it has no concept of shared resources between properties (and it can't, as there's no rdf:ID or rdf:about allowed). This is always hard to process, but it's also very valuable for doing metadata. Imagine a series of wildlife images that all refer to a particular safari, national park and species. We might be able to share a species reference between images easily enough by referring to a well-known public vocabulary, but it would also be useful (and concise) to be able to define one "expedition" in a subject property on one image, then share that same resource to others. As it is, we'd have to duplicate the full definition. Even in XMP's "separate document for each image resource" model we still might wish to do something similar, such as both photographer and director being the same person. When you start having 20MB+ of metadata per video resource (been there, done that!) then this sort of duplication is a huge problem. Not just because of the data volume, but because we need to identify that referenced resources are identical, not merely havingg the same in their property values (i.e. I'm the same John Smith, not just two people with the same name). There is no visible documentation of vocabularies, inetrnal or external. Some pre-defined schemas are given that define property sets, but there's nothing on the values of these, or how to describe that values are being taken from a particular external vocabulary (you can do this with RDF, but they don't describe it). This isn't widely seen as important, except by people who've already been through large media annotation projects. It's RDF-like, not just XML. However it's also a subset of RDF - in particular rdf:about isn't supported, which removes many of the graph structure constructs that make RDF such a pain to process with the basic XML tools. Read their explicit not on which RDF features aren't supported -- they're enough to make XMP easily processable with XSLT. The notes on embedding of XMP in XML and XML in XMP are both simplistic and ugly. I still don't see much _point_ in XMP. I could achieve all this much with two cups of coffee, RDF and Dublin Core and a whiteboard pen. Publishing metadata is good, publishing new _ways_ of publishing metadata is very bad! Overall, it could be far better, it could be better without being more complicated, and it's at least 5 years behind industry best practice for fields like museums and libraries. It's also a field that's still so alien to media and creative industries that the poor description and support of XMP will cause them to invent many bad architectures and data models for a few years to come. From thenightblogger at gmail.com Sat Dec 16 15:34:27 2006 From: thenightblogger at gmail.com (The Night Blogger) Date: Sat, 16 Dec 2006 21:34:27 +0100 Subject: Is there a way to push data into Microsoft Excel & Word from Python ? Message-ID: <458455f2$0$8219$426a74cc@news.free.fr> Is there a way to push data to Microsoft Excel & Word from a Python Application Is this a cross platform feature ? I'll need to push data on MS Windows & Mac OS X .... From morpheus at spam.no Tue Dec 19 15:44:33 2006 From: morpheus at spam.no (Morpheus) Date: Tue, 19 Dec 2006 21:44:33 +0100 Subject: What am I supposed to do with an egg?! Message-ID: On Windows I'm used to install packages by setup.py install. So did I with Fibranet nanothreads - a few seconds and it was installed. On Linux (ubuntu 6.06) all I could get at is an egg file. I found out that I have to exec easy_install, which didn't much help here (seems to me, at least - sorry, Linux newbie). So, what am I supposed to do here now? Kind regards Morpheus From http Sun Dec 17 22:28:47 2006 From: http (Paul Rubin) Date: 17 Dec 2006 19:28:47 -0800 Subject: merits of Lisp vs Python References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <1166412194.206364.73270@f1g2000cwa.googlegroups.com> Message-ID: <7xhcvtkhlc.fsf@ruckus.brouhaha.com> xscottg at gmail.com writes: > Even regarding interupts, I don't see a problem without a solution: > (with-interupts-and-garbage-collection-disabled > (poke destination (peek source)) It's not just GC or interrupts, it's the possibility of clobbering the Lisp heap. If the peek/poke addresses are restricted to some i/o region as Bill suggests, then the above approach may be reasonable. From webraviteja at gmail.com Sun Dec 3 20:16:49 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 3 Dec 2006 17:16:49 -0800 Subject: How to realize the interactive python in Eclipse? In-Reply-To: <1165068796.417513.86280@n67g2000cwd.googlegroups.com> References: <1165068796.417513.86280@n67g2000cwd.googlegroups.com> Message-ID: <1165195009.650668.130470@j44g2000cwa.googlegroups.com> purple wrote: > I have installed the Eclipse and the plug-in Pydev. Also, I have add an > python program in the external tools. When I run the python program in > the external tools, i can type python command just like in the python > shell.But when I finished running a python file, in the console, I > could not type any command to check some argument generated in the > process. Is there any way I can make it? > thank you~~ I am beginning to wonder if you attempting to use PyDev as nothing more than a programmer's editor. PyDev is a lot more. You need not debug this way since it includes a visual debugger. Be sure to read the documentation at the web site. http://pydev.sourceforge.net/debug.html http://pydev.sourceforge.net/faq.html From anthra.norell at vtxmail.ch Thu Dec 28 16:00:59 2006 From: anthra.norell at vtxmail.ch (Frederic Rentsch) Date: Thu, 28 Dec 2006 22:00:59 +0100 Subject: textwrap.dedent replaces tabs? In-Reply-To: References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> <232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com> Message-ID: <4594308B.3090308@vtxmail.ch> Tom Plunket wrote: > Frederic Rentsch wrote: > > >> It this works, good for you. I can't say I understand your objective. >> (You dedent common leading tabs, except if preceded by common leading >> spaces (?)). >> > > I dedent common leading whitespace, and tabs aren't equivalent to > spaces. > > E.g. if some text is indented exclusively with tabs, then the leading > tabs are stripped appropriately. If some other text is indented with > common leading spaces, those are stripped appropriately. If the text to > be stripped has some lines starting with spaces and others starting with > tabs, there are no /common/ leading whitespace characters, and thus > nothing is stripped. > > Your rules seem incomplete. What if common tabs remain after stripping common white space? Does this never happen? Or can we hope it doesn't happen? To err on the side of caution I complete your rules and this is my (tested) attempt at expressing them pythonically. (I admit it does look awfully sevety-ish. Just a vulgar little function.) Cheers Frederic ------------------------------------------------------------- def dedent (lines): leading_space_re = re.compile (' *') leading_tab_re = re.compile ('\t*') number_of_lines = len (lines) while 1: common_space_length = common_tab_length = 100000 for line in lines: if line: # No '\n' try: common_space_length = min (common_space_length, len (leading_space_re.match (line).group ())) except AttributeError: pass try: common_tab_length = min (common_tab_length, len (leading_tab_re.match (line).group ())) except AttributeError: pass if 0 < common_space_length < 100000: for i in xrange (number_of_lines): lines [i] = lines [i][common_space_length:] elif 0 < common_tab_length < 100000: for i in xrange (number_of_lines): lines [i] = lines [i][common_tab_length:] else: break return lines From kw at codebykevin.com Mon Dec 11 13:59:31 2006 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 11 Dec 2006 13:59:31 -0500 Subject: No output from popen in Tkinter text widget Message-ID: I'm trying to display the output of an external process (invoked via popen) in a Tkinter text widget. I successfully start the process (based on what I'm seeing in my terminal output), but I can't get the output to display in the Tkinter widget. It seems to block. Any ideas? My code is below: def runDump(self): self.password.destroy() self.passtext = self.passtext.get() file = os.popen('echo %s | sudo -S /usr/sbin/tcpdump -v -i en1' % self.passtext, 'r') for line in file: self.t.insert(END, line) -- Kevin Walzer Code by Kevin http://www.codebykevin.com From irmen.NOSPAM at xs4all.nl Sat Dec 2 06:00:00 2006 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 02 Dec 2006 12:00:00 +0100 Subject: client/server design and advice In-Reply-To: <1165045347.635141.178940@80g2000cwy.googlegroups.com> References: <4570d007$0$326$e4fe514c@news.xs4all.nl> <1165045347.635141.178940@80g2000cwy.googlegroups.com> Message-ID: <45715cb1$0$336$e4fe514c@news.xs4all.nl> John Henry wrote: > On the subject of passing things around, is there a no brainer way of > sending files back and forth over Pyro? > > I am currently using a shared drive to do that. May be I missed that > feature? > Sending files around is just a special case of passing large amounts of data to other systems. There is no built in support for file transfer in Pyro. It's rather easy to make a file transfer tool though, there is an example in the Pyro distribution that shows how this *may* be done. But choose the right tool for the job, things like rsync or even ftp may be preferable for just file transfer! If you use a shared drive, you could use Pyro to 'tell' the receiving side that the file is there with this-and-this name, to trigger a download. When the receiver is done copying the file, it can signal back and the sender can delete the file. But that's just an idea. --Irmen From fredrik at pythonware.com Thu Dec 14 07:00:25 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 13:00:25 +0100 Subject: Easier way yo use Py2exe In-Reply-To: <5b0fce7a0611292156l38a20a40la590d9b7377219d4@mail.gmail.com> References: <5b0fce7a0611292156l38a20a40la590d9b7377219d4@mail.gmail.com> Message-ID: Scheol Service wrote: > The directions are confusing. Can someone clear them up. > > Intructions Location: http://www.py2exe.org/index.cgi/Tutorial looks pretty straightforward to me. create a simple python script, write a short setup.py file that points to the script, run it to get an executable, and then run the executable. maybe you could explain what you found confusing? From commander.coder at hotmail.com Thu Dec 14 17:18:15 2006 From: commander.coder at hotmail.com (commander.coder at hotmail.com) Date: 14 Dec 2006 14:18:15 -0800 Subject: automatically grading small programming assignments In-Reply-To: <1166129734.888298.210830@l12g2000cwl.googlegroups.com> References: <1166129734.888298.210830@l12g2000cwl.googlegroups.com> Message-ID: <1166131842.963017.206130@79g2000cws.googlegroups.com> bearophileHUGS at lycos.com wrote: Then on your PC you can > run a script that loads each of such programs, and runs a good series > of tests, to test their quality... What happens if someone-- perhaps not even someone in the class-- does some version of os.system('rm -Rf /') ? From python.list at tim.thechases.com Sat Dec 16 20:59:43 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 16 Dec 2006 19:59:43 -0600 Subject: How to test if two strings point to the same file or directory? In-Reply-To: <1166319494.222385.232890@t46g2000cwa.googlegroups.com> References: <1166317324.791635.274550@79g2000cws.googlegroups.com> <1166319494.222385.232890@t46g2000cwa.googlegroups.com> Message-ID: <4584A48F.3050608@tim.thechases.com> >>> Comparing file system paths as strings is very brittle. Is there a >>> better way to test if two paths point to the same file or directory >>> (and that will work across platforms?) >> os.path.samefile(filename1, filename2) >> os.path.sameopenfile(fileobject1, fileobject2) > > Nice try, but they don't "work across platforms". Okay...double-checking the docs.python.org writeup, it apparently does "work across platforms" (Mac & Unix), just not "across *all* platforms", with Win32 being the obvious outlier. It seems a strange omission from Win32 python, even if it were filled in with only a stub...something like def samefile(f1, f2): return abspath(f1.lower()) == abspath(f2.lower()) it might not so gracefully handle UNC-named files, or SUBST'ed file-paths, but at least it provides an attempt at providing the functionality on win32. As it currently stands, it would be entirely too easy for a [Mac|*nix] programmer to see that there's a samefile() function available, use it successfully based on its docstring, only to have it throw an exception or silently fail when run on win32. -tkc From http Thu Dec 14 00:21:56 2006 From: http (Paul Rubin) Date: 13 Dec 2006 21:21:56 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> Message-ID: <7x3b7j2gsr.fsf@ruckus.brouhaha.com> Ken Tilton writes: > don't know. The point is, we need code (not just data) in defskill > (apologies for nasty formatting): Man that whole thing is messy. I can't for the life of me understand why it's so important to use a macro for that. Even in Lisp, I'd probably set up the reverse thingie as an auxiliary function. From anthra.norell at vtxmail.ch Mon Dec 25 02:28:23 2006 From: anthra.norell at vtxmail.ch (Frederic Rentsch) Date: Mon, 25 Dec 2006 08:28:23 +0100 Subject: textwrap.dedent replaces tabs? In-Reply-To: References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> <232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com> Message-ID: <458F7D97.7040203@vtxmail.ch> Tom Plunket wrote: > Frederic Rentsch wrote: > > >> Following a call to dedent () it shouldn't be hard to translate leading >> groups of so many spaces back to tabs. >> > > Sure, but the point is more that I don't think it's valid to change to > tabs in the first place. > > E.g.: > > input = ' ' + '\t' + 'hello\n' + > '\t' + 'world' > > output = textwrap.dedent(input) > > will yield all of the leading whitespace stripped, which IMHO is a > violation of its stated function. In this case, nothing should be > stripped, because the leading whitespace in these two lines does not > /actually/ match. Sure, it visually matches, but that's not the point > (although I can understand that that's a point of contention in the > interpreter anyway, I would have no problem with it not accepting "1 tab > = 8 spaces" for indentation... But that's another holy war. > > >> If I understand your problem, you want to restore the dedented line to >> its original composition if spaces and tabs are mixed and this doesn't >> work because the information doesn't survive dedent (). >> > > Sure, although would there be a case to be made to simply not strip the > tabs in the first place? > > Like this, keeping current functionality and everything... (although I > would think if someone wanted tabs expanded, they'd call expandtabs on > the input before calling the function!): > > def dedent(text, expand_tabs=True): > """dedent(text : string, expand_tabs : bool) -> string > > Remove any whitespace than can be uniformly removed from the left > of every line in `text`, optionally expanding tabs before altering > the text. > > This can be used e.g. to make triple-quoted strings line up with > the left edge of screen/whatever, while still presenting it in the > source code in indented form. > > For example: > > def test(): > # end first line with \ to avoid the empty line! > s = '''\ > hello > \t world > ''' > print repr(s) # prints ' hello\n \t world\n ' > print repr(dedent(s)) # prints ' hello\n\t world\n' > """ > if expand_tabs: > text = text.expandtabs() > lines = text.split('\n') > > margin = None > for line in lines: > if margin is None: > content = line.lstrip() > if not content: > continue > indent = len(line) - len(content) > margin = line[:indent] > elif not line.startswith(margin): > if len(line) < len(margin): > content = line.lstrip() > if not content: > continue > while not line.startswith(margin): > margin = margin[:-1] > > if margin is not None and len(margin) > 0: > margin = len(margin) > for i in range(len(lines)): > lines[i] = lines[i][margin:] > > return '\n'.join(lines) > > import unittest > > class DedentTest(unittest.TestCase): > def testBasicWithSpaces(self): > input = "\n Hello\n World" > expected = "\nHello\n World" > self.failUnlessEqual(expected, dedent(input)) > > def testBasicWithTabLeadersSpacesInside(self): > input = "\n\tHello\n\t World" > expected = "\nHello\n World" > self.failUnlessEqual(expected, dedent(input, False)) > > def testAllTabs(self): > input = "\t\tHello\n\tWorld" > expected = "\tHello\nWorld" > self.failUnlessEqual(expected, dedent(input, False)) > > def testFirstLineNotIndented(self): > input = "Hello\n\tWorld" > expected = input > self.failUnlessEqual(expected, dedent(input, False)) > > def testMixedTabsAndSpaces(self): > input = " \t Hello\n \tWorld" > expected = "\t Hello\n \tWorld" > self.failUnlessEqual(expected, dedent(input, False)) > > if __name__ == '__main__': > unittest.main() > -tom! > > It this works, good for you. I can't say I understand your objective. (You dedent common leading tabs, except if preceded by common leading spaces (?)). Neither do I understand the existence of indentations made up of tabs mixed with spaces, but that is another topic. I have been wasting a lot of time with things of this nature coding away before forming a clear conception in my mind of what my code was supposed to accomplish. Sounds stupid. But many problems seem trivial enough at first sight to create the illusion of perfect understanding. The encounter with the devil in the details can be put off but not avoided. Best to get it over with from the start and write an exhaustive formal description of the problem. Follows an exhaustive formal description of the rules for its solution. The rules can then be morphed into code in a straightforward manner. In other words, coding should be the translation of a logical system into a language a machine understands. It should not be the construction of the logical system. This, anyway, is the conclusion I have arrived at, to my advantage I believe. Frederic From fredrik at pythonware.com Wed Dec 20 13:23:45 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 19:23:45 +0100 Subject: PIL broken on win32? In-Reply-To: <4866bea60612201013w7eaa5115k85ea74daad4db72c@mail.gmail.com> References: <4866bea60612201013w7eaa5115k85ea74daad4db72c@mail.gmail.com> Message-ID: Chris Mellon wrote: > PIL 1.1.5 and 1.1.6 both seem to be broken, in different ways, on win32. > > 1.1.5 will load and access images, but ImageDraw fails: > i = Image.open("good.jpg") > d = ImageDraw.Draw(i) > d.line((10,10,20,20)) > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\Lib\site-packages\PIL\ImageDraw.py", line 199, in line > self.draw.draw_lines(xy, ink, width) > TypeError: function takes exactly 2 arguments (3 given) > > 1.1.6 is just broken in general - any access to image data fails: > i = Image.open("good.jpg") > d = i.getdata() > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\Lib\site-packages\PIL\Image.py", line 860, in getdata > self.load() > File "C:\Python24\Lib\site-packages\PIL\ImageFile.py", line 217, in load > return Image.Image.load(self) > File "C:\Python24\Lib\site-packages\PIL\Image.py", line 599, in load > return self.im.pixel_access(self.readonly) > AttributeError: pixel_access looks like you're using a 1.1.5 core DLL with 1.1.6. look for multiple copies of _imaging.pyd under c:\python24. From gagsl-py at yahoo.com.ar Wed Dec 13 20:12:12 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 13 Dec 2006 22:12:12 -0300 Subject: Password, trust and user notification In-Reply-To: <364538570612131644l604930b9l861b94457bc1183@mail.gmail.com > References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> <1165917102.008439.146400@16g2000cwy.googlegroups.com> <1166053509.270409.46390@f1g2000cwa.googlegroups.com> <7.0.1.0.0.20061213210006.04005d80@yahoo.com.ar> <364538570612131644l604930b9l861b94457bc1183@mail.gmail.com> Message-ID: <7.0.1.0.0.20061213220018.03fb7bf8@yahoo.com.ar> At Wednesday 13/12/2006 21:44, Aidan Steele wrote: >While what you said is technically correct, I think you misread >their original question. They want to send email *from* the Gmail >account *to* the work account. I suggested that he use Gmail's SMTP >server to send the email. They were concerned about putting sensitive information (password) inside the script, in order to connect to Gmail to send the mail notifications. I say that there is no need to use Gmail smtp services: to send mail *to* anyone at anywhere.com, you only have to connect to the right SMTP server for anywhere.com. The *from* email address is irrelevant and can even be faked. Of course a spam filter could block such mails, but you have to test it. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From robert.hundt at gmail.com Tue Dec 26 13:56:25 2006 From: robert.hundt at gmail.com (robert.hundt at gmail.com) Date: 26 Dec 2006 10:56:25 -0800 Subject: Google Custom Search Engine Message-ID: <1167159385.300459.286410@h40g2000cwb.googlegroups.com> Hi, I created a Google Custom Search Engine for searching on: "Software / Compilers / Optimization" This is basically a regular full Google search giving preference to technical sites such as IEEE, ACM, citeseer, the Universities, news-group (this one included), commercial sites such as Intel, Microsoft, HP, Sun, IBM, and others. The search results are further biased towards software development, programming languages, and optimizing compilers The results are indeed much more specific than the regular Google search. Try ity out! Additionally, if you are interested, please send me an email and you can contribute to this search engine and add sites you believe should be given preference to. Over time, it should become better and better... I "donated" a no-nonsense URL: www.codeopt.com Check it out - and let me know what you think (no rants, please)! Cheers -- Robert Hundt HP From sjmachin at lexicon.net Sat Dec 16 21:20:56 2006 From: sjmachin at lexicon.net (John Machin) Date: 16 Dec 2006 18:20:56 -0800 Subject: How to test if two strings point to the same file or directory? In-Reply-To: References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: <1166322055.964611.214030@f1g2000cwa.googlegroups.com> Tim Chase wrote: [snip] > I'd suggest os.path.samefile which should handle case-sensitive > (non-win32) vs case-insensitive (win32) filenames, soft-links, > and hard-links. Not sure it's prescient enough to know if you > have two remote shares, it will unwind them to their full > server-path name. Works here on my various boxes (Linux, MacOS-X > and OpenBSD) here. I'd assume it's the same functionality on Win32. > Assume nothing. Read the manual. From Roberto.Bonvallet at cern.ch Wed Dec 6 11:53:52 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Wed, 6 Dec 2006 16:53:52 +0000 (UTC) Subject: dict.has_key(x) versus 'x in dict' References: <1165418932.582377.312200@79g2000cws.googlegroups.com> <1165423559.858684.227930@16g2000cwy.googlegroups.com> Message-ID: Andy Dingley wrote: > Out of interest, whats the Pythonic way to simply cast (sic) the set to > a list, assuming I don't need it sorted? The list comprehension? mySet = set(myList) myList = list(mySet) -- Roberto Bonvallet From tdelaney at avaya.com Thu Dec 7 17:06:50 2006 From: tdelaney at avaya.com (Delaney, Timothy (Tim) ) Date: Fri, 8 Dec 2006 09:06:50 +1100 Subject: dict.has_key(x) versus 'x in dict' Message-ID: <2773CAC687FD5F4689F526998C7E4E5F074450@au3010avexu1.global.avaya.com> skip at pobox.com wrote: > Hendrik> why? - the main point is actually that the code worked, > and was Hendrik> stable - that should make you proud, not > embarrassed. that Hendrik> there is far too much emphasis on > doing things the quickest way Hendrik> - as long as it works, and > is fast enough, its not broken, so Hendrik> don't fix it... > > That's the rub. It wasn't fast enough. I only realized that had > been a problem once I fixed it though. Yep - it's so often the case that scaling problems don't turn up in developer testing, but only in the field ... and sometimes in much less obvious ways than Skip's case. I had one where the particulars of the data I was using meant that what was meant to be an O(1) HashMap lookup (yes, Java - boo) was essentially an O(n) lookup much of the time. For a lot of the data, the key chosen ended up being the same (resulting in the hashmap having very long chains). By using additional data in the key as a tie-breaker, I got back my normal-case O(1) behaviour. In this particular case though ... dict.has_key(x) x in dict.keys() one is obviously clearer than the other, as well as being faster. Of course (getting back to the original question), in current python: x in dict is obviously the clearest, and fastest method, and should always be preferred over either of the above. Tim Delaney From gabriel.becedillas at gmail.com Thu Dec 14 16:57:10 2006 From: gabriel.becedillas at gmail.com (gabriel.becedillas at gmail.com) Date: 14 Dec 2006 13:57:10 -0800 Subject: Wrapping classes with pure virtual functions Message-ID: <1166133429.969921.131400@80g2000cwy.googlegroups.com> Hi, I'm having problems wrapping a hierarchy of classes, actually having problems wrapping the base class. I don't need to use the WrapClass mechanism since I don't want to override classes in Python. My code boils down to: class Base { public: virtual ~Base() {} virtual void f() = 0; }; class Derived : public Base { public: virtual void f() {} void g() {} }; int main() { boost::python::class_ class_base("Base"); boost::python::class_ class_derived("Derived"); return 0; } The first line inside main (the one exporting Base) is causing the compile time error: error C2259: 'Base' : cannot instantiate abstract class... The probem seems to be that struct value_holder holds a Base member instance by value, and this is not possible since Base can't be instantiated. I'm using Visual Studio 2005 and boost 1.33.1. Thanks From gert.cuykens at gmail.com Wed Dec 20 18:32:45 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Thu, 21 Dec 2006 00:32:45 +0100 Subject: def index(self): In-Reply-To: <45891cb7$0$16994$426a34cc@news.free.fr> References: <4587017b$0$22957$426a34cc@news.free.fr> <458807cc$0$19743$426a74cc@news.free.fr> <45891cb7$0$16994$426a34cc@news.free.fr> Message-ID: > > class HelloWorld(object): > > @cherrypy.exposed > > def index(self): > > return "Hello World" do i have to write @cherrypy.exposed before every def or just once for all the def's ? and why not write something like @index.exposed ? in other words i have no idea what @ actually does i only know i have too write it to make it work :) Am guessing @ is something like prototyping in javascript but then def index is not a object but a method ? So that would not make sense ? oh and self stands more or less for private method right ? From bj_666 at gmx.net Wed Dec 20 07:11:22 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 20 Dec 2006 13:11:22 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <1166394345_23949@sp6iad.superfeed.net> <1166442477.818748.324370@f1g2000cwa.googlegroups.com> Message-ID: In , Sebastian 'lunar' Wiesner wrote: > Gabriel Genellina schrieb >> A similar function exists on Linux too. But even if a file has the >> right file format, if it does not have the execute bit set, won't run. >> And you could set that bit on a JPG image too - and nothing good would >> happen, I presume. > > Really? I don't think so. Afaik on Linux executable binary files need an > ELF header. There are other executable loaders for `a.out` and `COFF` in the kernel, and with the `binfmt_misc` module you can make anything with a "magic" header executable, including Python scripts/bytecode and even JPEG images. http://www.tat.physik.uni-tuebingen.de/~rguenth/linux/binfmt_misc.html Ciao, Marc 'BlackJack' Rintsch From rridge at csclub.uwaterloo.ca Sun Dec 10 00:49:13 2006 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: 9 Dec 2006 21:49:13 -0800 Subject: len() and PEP 3000 References: <4tnqlkF13bbqeU1@mid.individual.net> <5HSdh.15210$P04.6844@tornado.fastwebnet.it> <1165693115.007835.160250@j72g2000cwa.googlegroups.com> Message-ID: <1165729753.864860.82650@f1g2000cwa.googlegroups.com> Colin J. Williams wrote: > __len__ is not very special and the > property len eliminates the redundant parentheses. tac-tics wrote: > One might say the current syntax eliminates the redundant dot. Make "len" an operator, like C's "sizeof", and eliminate the (hypothetical) dot, parenthesises and a name lookup. Ross Ridge From fredrik at pythonware.com Fri Dec 15 11:25:26 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 17:25:26 +0100 Subject: skip last line in loops In-Reply-To: <1166182692.041668.218730@f1g2000cwa.googlegroups.com> References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> <1166182692.041668.218730@f1g2000cwa.googlegroups.com> Message-ID: eight02645999 at yahoo.com wrote: >> do it lazily: >> >> last_line = None >> for line in open("file): >> if last_line: >> print last_line >> last_line = line >> >> or just gobble up the entire file, and slice off the last item: >> >> for line in list(open("file"))[:-1]: >> print line >> >> > > would it be a problem with these methods if the file is like 20Gb in > size...? not with the lazy version, of course. the "gobble up" version will load the entire file into memory. but cutting off a single line from a 20 gigabyte file by looping over it sounds like a bit contrived, really. if you're really doing this (why?), maybe you should just truncate the file in place instead. From jon at ffconsultancy.com Sun Dec 10 04:39:32 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 09:39:32 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <1165731005.529088.227360@j44g2000cwa.googlegroups.com> <457bc963$0$8747$ed2619ec@ptn-nntp-reader02.plus.net> <7xac1wrtgu.fsf@ruckus.brouhaha.com> Message-ID: <457bd673$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: > Jon Harrop writes: >> # cond 2 >> [( = ) 1, "one"; >> ( = ) 2, "two"; >> ( = ) 3, "three"] >> "neither one, two nor three";; >> - : string = "two" > > I'm missing something. Doesn't Ocaml have strict evaluation? Yes. > That means if you use function calls instead of string constants in those > values, they all get called. True. > You haven't really done what cond does. Good point. How about this: # let rec cond x rules default = match rules with | [] -> default | f :: t -> match f x with | Some e -> e | None -> cond x t default;; val cond : 'a -> ('a -> 'b option) list -> 'b -> 'b = # cond 2 [(fun n -> if n=1 then Some "one" else None); (fun n -> if n=2 then Some "two" else None); (fun n -> if n=3 then Some "three" else None)] "neither one, two nor three";; - : string = "two" The 'Some "one"' is only called if its predicate matched. Anyway, you don't need macros to write COND and you don't need COND if you have pattern matching. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From jeanmarc.pouchoulon at free.fr Tue Dec 12 14:56:50 2006 From: jeanmarc.pouchoulon at free.fr (jean-marc pouchoulon) Date: Tue, 12 Dec 2006 20:56:50 +0100 Subject: py-ldap question In-Reply-To: References: <457EA2BA.6000401@designaproduct.biz> Message-ID: <457f0982$0$25923$ba4acef3@news.orange.fr> and this set option ? ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_NEVER) HTH Laszlo Nagy a ?crit : > By the way, I already tried the set_option function, but I still get the > same error. > > > import ldap > import local > > ldap.set_option(ldap.OPT_X_TLS_ALLOW,1) > ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,0) > ldap.set_option(ldap.OPT_X_TLS_CERTFILE,local.LDAP_CACERTFILE) > ldap.set_option(ldap.OPT_X_TLS_CACERTFILE,local.LDAP_CACERTFILE) > > def getnewconnection(logindc,password): > conn = ldap.initialize(local.LDAP_SERVER_URL) > conn.simple_bind_s(logindc,password) > return conn > > if __name__ == '__main__': > conn = getnewconnection(local.LDAP_MANAGER_DC,local.LDAP_MANAGER_PWD) > print conn > > > From yao1337 at gmail.com Sun Dec 3 10:27:39 2006 From: yao1337 at gmail.com (purple) Date: 3 Dec 2006 07:27:39 -0800 Subject: How to realize the interactive python in Eclipse? In-Reply-To: <1165150554.391050.51300@n67g2000cwd.googlegroups.com> References: <1165068796.417513.86280@n67g2000cwd.googlegroups.com> <1165150554.391050.51300@n67g2000cwd.googlegroups.com> Message-ID: <1165159659.645854.218770@j44g2000cwa.googlegroups.com> Thanks so much for your concern~~ In the preferences for pydev, I have added the python.exe in the python interpreters, and also the system PYTHONPATH, Forced built-in libs. I am not sure whether you mean it? I am sorry because I am a green hand on the eclipse. And for the external tools, I have include the "-i" as an argument for the python interpreter and there is no other argument. Is there any other argument? Thanks so much~~ > > Do you not want to run python from eclipse? If so, go to preferences > for pydev and show pydev where your python executable is. Then you can > use the debug function to look at variables. > > For the external tools problem with python interactive, did you include > "-i" as an argument for the python interpreter? From bbrown at speakeasy.net Mon Dec 11 22:25:59 2006 From: bbrown at speakeasy.net (Robert Brown) Date: Mon, 11 Dec 2006 22:25:59 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> <7xwt4yju5e.fsf@ruckus.brouhaha.com> <7x1wn57voq.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Espen Vestre writes: >> > Can you redefine CLOS methods without calling CLOS functions that tell >> > the object system what to expect (so it can do things like update the >> > MRO cache)? I.e. can you redefine them by poking some random >> > dictionary? You can in Python. I don't claim that's a good thing. >> >> Just as I said: Less managable, but not more dynamic. > > I'm not getting through to you. Yes, you could create a Python-like > object system in Lisp that's separate from CLOS, but nobody would use > it .... I think you are not understanding the point that Espen is trying to make. He is not suggesting a different object system for Lisp. Espen is saying that Common Lisp often offers the same dynamic feature as Python has, such as the ability to redefining a method at runtime. Lisp, however, forces you to call a CLOS function or use an well defined interface when redefining a method. You can't just change a value in a hash table. Does this make Lisp "less dynamic" than Python? Espen would say it's not less dynamic, but rather that a similar level of dynamism is achieved in Common Lisp via well defined interfaces. The compiler knows the interfaces, so it can do a better job optimizing the code. From jfabiani at yolo.com Fri Dec 29 06:30:00 2006 From: jfabiani at yolo.com (johnf) Date: Fri, 29 Dec 2006 03:30:00 -0800 Subject: INSERT statements not INSERTING when using mysql from python References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> Message-ID: <507lh.334$c46.83@newsfe05.lga> Ben wrote: > I don't know whether anyone can help, but I have an odd problem. I have > a PSP (Spyce) script that makes many calls to populate a database. They > all work without any problem except for one statement. > > I first connect to the database... > > self.con = MySQLdb.connect(user=username, passwd =password) > self.cursor = self.con.cursor() > self.cursor.execute("SET max_error_count=0") > > All the neccesary tables are created... > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > self.cursor.execute("USE "+name) > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > varchar(20)) > > Then I execute many insert statements in various different loops on > various tables, all of which are fine, and result in multiple table > entries. The following one is executed many times also. and seems > identical to the rest. The print statements output to the browser > window, and appear repeatedly, so the query must be being called > repeatedly also: > > print "

SQL query executing

" > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > ','c','2','e','f','g')") > print "

SQL query executed

" > > I have, for debugging, set "i" up as a counter variable. > > No errors are given, but the only entry to appear in the final database > is that from the final execution of the INSERT statement (the last > value of i) > > I suspect that this is to vague for anyone to be able to help, but if > anyone has any ideas I'd be really grateful :-) > > It occured to me that if I could access the mysql query log that might > help, but I was unsure how to enable logging for MysQL with python. > > Cheers, > > Ben Not sure this will help but where is the "commit"? I don't use MySQL but most SQL engines require a commit. Johnf From gert.cuykens at gmail.com Fri Dec 22 17:56:27 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Fri, 22 Dec 2006 23:56:27 +0100 Subject: attribute decorators Message-ID: would it not be nice if you could assign decorators to attributes too ? for example class C: @staticattribute data='hello' or class C: @privateattribute data='hello' From udodenko at users.sourceforge.net Sat Dec 9 04:30:56 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sat, 9 Dec 2006 11:30:56 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <7xodqdj2dn.fsf@ruckus.brouhaha.com> Message-ID: <457a8251$0$49201$14726298@news.sunsite.dk> (message (Hello 'Paul) (you :wrote :on '(08 Dec 2006 17:15:32 -0800)) ( PR> Huh? Are you saying Lisp systems never release new versions? And you PR> can't implement Python generators as Lisp macros in any reasonable PR> way. You could do them in Scheme using call-with-current-continuation PR> but Lisp doesn't have that. we can implement Scheme's call-with-current-continuation first :) it's relatively easy -- just a code walker that coverts everyting into CPS. i've used one for a web application development. ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From david at boddie.org.uk Tue Dec 19 09:14:20 2006 From: david at boddie.org.uk (David Boddie) Date: 19 Dec 2006 06:14:20 -0800 Subject: Using DCOP from Python References: Message-ID: <1166537659.996278.285250@79g2000cws.googlegroups.com> Jeffrey Barish wrote: > The package python-dcop makes it possible to use DCOP from Python. Does > anyone know of a tutorial for this package or an example of its use? I > would like to use it to read a journal entry in Korganizer. I got as far > as figuring out that DCOP offers the interface > korganizer.CalendarIface.openJournalEditor(QString text, QDate date) > but I'm having trouble figuring out how to call this function from Python. > And will it become clear how to control whether I am reading or writing the > journal? You might find an answer in the archives of the PyKDE mailing list: http://mats.imk.fraunhofer.de/mailman/listinfo/pykde There are probably people reading that list who can give you hints and tips, at the very least. You might also want to take a look at the documentation at http://www.riverbankcomputing.com/Docs/PyKDE3/dcopext.html This may be enough to get you started. David From fredrik at pythonware.com Wed Dec 20 03:04:24 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 09:04:24 +0100 Subject: python script terminating In-Reply-To: <13B4D38ED7B116429C3A426A2C3998D90290D805@blrexmb01.efi.internal> References: <13B4D38ED7B116429C3A426A2C3998D90290D805@blrexmb01.efi.internal> Message-ID: Aditya Vaish wrote: > Using perl ","",data) > > > >> will not cut out all javascript code if it's spread on many lines. > > >> I could use something like /s from perl which treats . as all signs > > >> (including new line). How can i do that ? > > > >> Maybe there is other way to achieve the same results ? > > > >> Thanx > > > > Take a look at Chapter 8 of 'Dive Into Python.' > > >http://diveintopython.org/toc/index.htmliread whole regexp chapter - but there was no solution for my problem. > > Example: > > > re.sub("","",htmldata) > > would remove only comments which are in one line. > > If comment is in many lines like this: > > > > > it would not work. It's because '.' sign does not matches '\n' sign. > > > Does anybody knows solution for this particular problem ? > > > Thanx- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text - From fredrik at pythonware.com Tue Dec 5 03:22:53 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 09:22:53 +0100 Subject: Opening colour BMPs with PIL In-Reply-To: <1165270585.753466.62440@l12g2000cwl.googlegroups.com> References: <1165270585.753466.62440@l12g2000cwl.googlegroups.com> Message-ID: Craig wrote: > I'm trying to open colour BMPs using PIL and I'm getting the following > errors. what program did you use to produce those BMP files? can you prepare reasonably small samples using the same program and post them somewhere? From basti.wiesner at gmx.net Sat Dec 30 05:11:52 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Sat, 30 Dec 2006 11:11:52 +0100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: Paul McNett

typed > Steven D'Aprano wrote: >> But I think we all agree that mixing tabs and spaces is A Very Bad >> Thing. > > I like mixing tabs and spaces, actually. Tabs for indentation, and > additional spaces to make the code "look pretty". Somebody please tell > me why this is bad and I'll stop. > > class Apple(object): > def contrived_example_function(self, argument1, argument2, > argument3, argument4): > print "hello, world" > > Apparently, emacs in python mode follows this convention, too. That doesn't seem like a standard settings to me. I can't remember changing the indentation settings for python, nonetheless my gnu emacs uses four spaces for indentation. Placing wrapped lines into ordered columns is done by inserting additional spaces. This all happens automatically; you never need to insert spaces manually... > I like it because I get the best of both worlds: the only thing > against using tabs-only-indentation is that wrapping long lines can be > quite ugly, while space-only-indentation allows for beautifying it > somewhat by lining up the columns to match. Did you try to open your code files with another editor, which has a different length for tabulator chars? It would look quite ugly, I guess... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From nagle at animats.com Fri Dec 15 02:04:47 2006 From: nagle at animats.com (John Nagle) Date: Fri, 15 Dec 2006 07:04:47 GMT Subject: MySQLdb windows binaries for Python 2.5?? Yes, but from a World of Warcraft guild. In-Reply-To: References: <1162408100.985370.148650@m7g2000cwm.googlegroups.com> <1163238145.257490.144410@b28g2000cwb.googlegroups.com> <1166144355.616642.127080@n67g2000cwd.googlegroups.com> Message-ID: John Nagle wrote: > What's happened is that Python fell through the cracks here. MySQL > themselves support Java, Microsoft ".NET", PHP, and a C interface. > The Perl interface to MySQL is part of the supported Perl distribution. > But for for Python, everybody is running on glue code from one > guy on Sourceforge, and he's having problems keeping up. > > Oops. > > John Nagle As a workaround, I went back to Python 2.4 on the Windows machine. Works fine. Looks like 2.5 isn't ready for prime time yet, until MySQLdb is fixed. John Nagle Animats From pavlovevidence at gmail.com Fri Dec 22 14:52:32 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 22 Dec 2006 11:52:32 -0800 Subject: One module per class, bad idea? References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> Message-ID: <1166817152.414154.151390@42g2000cwt.googlegroups.com> Kent Johnson wrote: > Carl Banks wrote: > > Now, I think this is the best way to use modules, but you don't need to > > use modules to do get higher-level organization; you could use packages > > instead. It's a pain if you're working on two different classes in the > > same system you have to keep switching files; but I guess some people > > prefer to switch files rather than to scroll for some reason. > > That would be me. I strongly prefer to switch files rather than scroll. > I use an editor that makes it easy to switch files. For me it is much > easier to switch between files than to scroll between two parts of a > file, and I don't lose my place when I switch back. I like to be able to > see things side by side. Man, I don't know you do it. Say I'm sitting there concentrating on programming something, and I see that I'll have to make a change in another file. All of a sudden, I have to recall some filename out of thin air. Totally breaks my train of thought, sometimes I space out trying to think of it because I have to cold-start an entirely different part of my brain. It's less of a mental distraction to just scroll. I'm in the habit of changing things as soon as the need arises. If I'm editing A and I see that I'll have to make a change in B, I stop editing A, change B, then come back to A. For me, it results in MUCH fewer forgotten changes (YMMV). But it also means a lot of switching. Consequently, trying to minimize distraction during switches is important to me. Maybe it isn't if you switch less frequently, and rarely while in the middle of somthing. I wonder if there's any correlation between how often one switches location, and preferrence (tolerance) for file size. I bet the more often one switches location, the more likely they are to prefer larger files. (BTW, any decent editor will let you view different positions of the same file side-by-side.) > So I do tend to put classes in separate modules. Not always - when two > or more classes are closely related or a class has one or more helper > classes they may share a module - but in general my major classes are > each to a module. > > It does make the imports look funny - I tend to give the module the same > name as the class, Java style, so I have > from foo.bar.MyClass import MyClass > but that is a minor point IMO. I'd consider using all lowercase for the module. Of course it doesn't make sense to come up with a unique name for modules when they're mostly one-to-one with classes, but it's still nice to give users a clue whether they object they're looking at is a class or a module. Carl Banks From duncan.booth at invalid.invalid Thu Dec 7 08:33:15 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 7 Dec 2006 13:33:15 GMT Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> Message-ID: "Stephen Eilert" wrote: > I've always used has_key(), thinking it was the only way to do it. > Given that Python says that "There Should Be Only One Way to Do It", I > didn't bother searching for alternatives. The full quote is actually: There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. It might be more accurate to add a third line: And the one true way may change with new versions of Python In this case, dict objects used to not support the 'in' operator, but at some point it was added. I believe it wasn't there originally because Guido wasn't sure whether people would expect it should match keys or keys and values. > > Is there a list somewhere listing those not-so-obvious-idioms? I've > seen some in this thread (like the replacement for .startswith). > The release notes for each new version. Unfortunately the rest of the documentation sometimes lags behind the release notes. > I do think that, if it is faster, Python should translate > "x.has_key(y)" to "y in x". Python doesn't know whether x has a __contains__ method until it tries to call it. In particular there may be user-defined dictionary-like objects in your program which support has_key but not 'in'. e.g. in at least some versions of Zope HTTPRequest objects support has_key but not __contains__. From danb_83 at yahoo.com Thu Dec 14 23:55:50 2006 From: danb_83 at yahoo.com (Dan Bishop) Date: 14 Dec 2006 20:55:50 -0800 Subject: automatically grading small programming assignments In-Reply-To: References: <1166129734.888298.210830@l12g2000cwl.googlegroups.com> <1166131842.963017.206130@79g2000cws.googlegroups.com> Message-ID: <1166158550.874904.109000@80g2000cwy.googlegroups.com> On Dec 14, 8:36 pm, Brian Blais wrote: > commander.co... at hotmail.com wrote: > > bearophileH... at lycos.com wrote: > > Then on your PC you can > >> run a script that loads each of such programs, and runs a good series > >> of tests, to test their quality... > > What happens if someone-- perhaps not even someone in the class-- does > > some version of os.system('rm -Rf /') ?I was thinking of including a dummy os.py and sys.py, so import os, and import sys > would fail. Would this work? How would they access their command-line arguments without sys.argv? From http Mon Dec 11 00:06:56 2006 From: http (Paul Rubin) Date: 10 Dec 2006 21:06:56 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> <457c42a3$0$49196$14726298@news.sunsite.dk> <7xodqbpqun.fsf@ruckus.brouhaha.com> <457c92c7$0$49195$14726298@news.sunsite.dk> Message-ID: <7x1wn7vx5b.fsf@ruckus.brouhaha.com> "Alex Mizrahi" writes: > PR> I don't see how to implement coroutines with CL macros. Maybe I'm > PR> missing something. > > read the book. Which book? > but once you convert it to CPS, you just operate with closures. stack is > just a lexical variables caught into closure. > do you know what does CPS mean at all?? I once understood the basic notion but confess to have never been clear on the fine points. However, I don't see how you can do it with CL closures since CL semantics do not guarantee tail recursion optimization. If you code a loop with closures and CPS, you will blow the stack. From chris.cavalaria at free.fr Wed Dec 13 05:30:23 2006 From: chris.cavalaria at free.fr (Christophe) Date: Wed, 13 Dec 2006 11:30:23 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1165984694.264366.261250@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> Message-ID: <457fd653$0$4340$426a74cc@news.free.fr> josephoswaldgg at hotmail.com a ?crit : > Bjoern Schliessmann wrote: >> Robert Uhl wrote: >> >>> Because it's the language for which indentation is automatically >>> determinable. That is, one can copy/paste a chunk of code, hit a >>> key and suddenly everything is nicely indented. >> Cool, so in other languages I need to set block marks like () and {} >> and also indent the code for readability, and in Python I indent >> only. From my POV that's less work. > > Try reading again. In Lisp, you use () and *your editor* automatically > indents according to the universal standard, or you leave it sloppy > until other folks reading your code convince you to get a proper > programming editor. Indentation does not get out of sync with semantics > because the editor virtually never misses parentheses that the Lisp > compiler sees. Expressions keep the same meaning even if you have to > start breaking them across lines, etc. > > In Python, you group in your mind, and press indentation keys to make > it happen in your editor. The editor cannot help that much, because it > cannot read your mind. White space screwups in copy-paste cannot be > fixed by the editor automatically, because it cannot read the original > programmer's mind, and you have to fix it manually, and risk screwing > it up. Call us when you have an editor that reads your mind and writes the () for you. From Thomas.Ploch at gmx.net Wed Dec 20 13:03:16 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Wed, 20 Dec 2006 19:03:16 +0100 Subject: perl better than python for users with disabilities? In-Reply-To: <458977b7$0$326$e4fe514c@news.xs4all.nl> References: <87slfalf8h.fsf@jidanni.org> <458977b7$0$326$e4fe514c@news.xs4all.nl> Message-ID: <45897AE4.8010007@gmx.net> Martin P. Hellwig schrieb: > Quite punny title though I assume you are really serious and mean people > with a physical disability, I won't comment any further on this subject > :-), if I already offended anyone, please excuse me, since I'm original > from Germany I'm not supposed to be funny. Argh, I am writing to President Horst K?hler to take away your German citizenship. You _need_ to stay true to German attributes (like not being funny, what you have been...)! This is the last warning! :-D Regarding the topic: I can't see where Perl should be more accessible than Python. Thomas From grue at mail.ru Wed Dec 13 03:39:44 2006 From: grue at mail.ru (Timofei Shatrov) Date: Wed, 13 Dec 2006 08:39:44 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> <1165857526.721489.322470@73g2000cwn.googlegroups.com> <1165975429.053195.95700@j72g2000cwa.googlegroups.com> Message-ID: <457fbb4f.5829983@news.readfreenews.net> On 12 Dec 2006 18:03:49 -0800, "Paddy" tried to confuse everyone with this message: >There are a lot of people that use Wikipedia. I think some of them >might want to learn to program. I think you misunderstood the goal of Wikipedia. It is not to teach people programming. >I make it easier for them to find >Python by helping to maintain Python within Wikipedia. If someone wants to find Python, he types "Python" in the search bar and works from there. He certainly wouldn't end up in "doctest" article. >Some people dislike Wikipedia which is fine. Some people dislike >Wikipedia and deliberately sabotage it, which is vandalism. Writing vanity articles about non-notable things is not much better. -- |Don't believe this - you're not worthless ,gr---------.ru |It's us against millions and we can't take them all... | ue il | |But we can take them on! | @ma | | (A Wilhelm Scream - The Rip) |______________| From jjl at pobox.com Wed Dec 27 17:05:21 2006 From: jjl at pobox.com (John J. Lee) Date: Wed, 27 Dec 2006 22:05:21 GMT Subject: urllib.urlopen unwanted password prompts - documentation problem References: <%tBkh.7619$yC5.4192@newssvr27.news.prodigy.net> Message-ID: <87bqlp9erf.fsf@pobox.com> John Nagle writes: > If you try to open a password protected page with "urllib.urlopen()", you get > > "Enter username for EnterPassword at example.com:" > > on standard output, followed by a read for input! This seems to be an > undocumented feature, if not a bug. Definitely the documentation for > "urllib" should mention this. The effects of this in a CGI program > are not good. > > A workaround is described here: "http://cis.poly.edu/cs912/urlopen.txt" > "URLopener" and "FancyURLopener" in urllib have many overrideable > functions, none of which are documented at python.org and should be. [...] Bug reports tend not to result in a fix being applied unless the reporter him/herself actually goes to the trouble of filing a patch at sourceforge.net : http://sourceforge.net/tracker/?group_id=5470&atid=305470 John From gandalf at designaproduct.biz Wed Dec 13 08:28:15 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Wed, 13 Dec 2006 14:28:15 +0100 Subject: Validate XML against a set of XSD files, with Python In-Reply-To: <1165962804.855630.222240@79g2000cws.googlegroups.com> References: <1165962804.855630.222240@79g2000cws.googlegroups.com> Message-ID: <457FFFEF.2060707@designaproduct.biz> > Fast google query, uncheked, leads to: > > - XSV: http://www.ltg.ed.ac.uk/~ht/xsv-status.html > I tried this before. Unfortunately, xsv is not officially supported on my system (FreeBSD 6.1) :-( > - libxml : http://codespeak.net/lxml/ > Probably this is what I need to use. (However, I see in the mailing lists that there are problems with this part of libxml2.) Thank you, Laszlo From salvatore.difazio at gmail.com Tue Dec 5 12:44:35 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 5 Dec 2006 09:44:35 -0800 Subject: Thread error In-Reply-To: References: <1165177861.653112.325020@73g2000cwn.googlegroups.com> <1165268591.054043.9580@j44g2000cwa.googlegroups.com> Message-ID: <1165340675.851175.272840@f1g2000cwa.googlegroups.com> Dennis Lee Bieber ha scritto: > Ah, sorry... Warned you that I didn't test... > > Duplicate the block of lines with the .join() calls. Put this block > just before them, but after the threading.Thread calls, and change the > .join() to .start() Tnx Dennis I resolved yesterday after the post. I tried to delete the post :) Anyway tnx From grante at visi.com Thu Dec 28 12:24:42 2006 From: grante at visi.com (Grant Edwards) Date: Thu, 28 Dec 2006 17:24:42 -0000 Subject: Some basic newbie questions... References: <1167324002.516960.319870@79g2000cws.googlegroups.com> <1167325306.545679.185300@48g2000cwx.googlegroups.com> Message-ID: <12p7veqbmuga1ea@corp.supernews.com> On 2006-12-28, jonathan.beckett wrote: >> > Given the code below, why does the count method return what it does? >> > How *should* you call the count method? >> > a = [] >> > a.append(1) >> > print a.count >> >> print a.count(). Which will cause an exception, BTW, since the count method requires one parameter telling it what you want to count occurrences of. >> There's a "Python for VB programmers" out there somewhere, see >> if you can find it. In python, functions (and methods which >> are special cases of functions) are first class objects, so >> you're printing the function object, not calling it. > I'm not a VB programmer :) He assumed you were because you were trying to call a function without using parens. VB is probably the most common language where you call something by writing functionName rather than functionName() IIRC Pascal precedures are called w/o parens, but if you pick Joe Random off the 'net he's more likely to know VB than Pascal. > I normally work with PHP, C#, Javascript, and the odd bit of C++, Do any of them call functions w/o parens? -- Grant Edwards grante Yow! VICARIOUSLY at experience some reason visi.com to LIVE!! From cyberco at gmail.com Sun Dec 31 06:44:44 2006 From: cyberco at gmail.com (cyberco) Date: 31 Dec 2006 03:44:44 -0800 Subject: Progress Box or Bar in Windows In-Reply-To: References: Message-ID: <1167565484.032607.142850@n51g2000cwc.googlegroups.com> Go for wxPython, it'll fulfill all your GUI needs. Handsdown the best GUI toolkit I ever ran into. It can't get much simpler than: wx.MessageBox('hi') And there are tons of readymade dialogs and progressbars in the library. Check out the demo.py under the wxPython installation dir to see demos (and source) of the enormous list of controls. From istvan.albert at gmail.com Wed Dec 13 11:06:52 2006 From: istvan.albert at gmail.com (Istvan Albert) Date: 13 Dec 2006 08:06:52 -0800 Subject: Large files uploading References: <1165949410.458162.38300@79g2000cws.googlegroups.com> Message-ID: <1166026012.139478.89210@16g2000cwy.googlegroups.com> Lad wrote: > Or is there another way( besides FTP) how to upload large files to > server? You can upload via http. The primary problem is that the browser don't work well with large uploads (give little feedback on the process, IE may hang etc). You can workaround some limitations by using applets such as JUpload http://www.jupload.biz/ i. From tayssir.john at googlemail.com Fri Dec 8 17:18:31 2006 From: tayssir.john at googlemail.com (tayssir.john at googlemail.com) Date: 8 Dec 2006 14:18:31 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: <1165616311.901535.249780@l12g2000cwl.googlegroups.com> Aahz wrote: > I would say that your statement about Lisp syntax is wrong. Not that it > is technically inaccurate, but that it completely misses the point, so > much so that it is wrong to say it. One of the key goals of Python is > readability, and while it is indeed easy to learn the rules for Lisp > syntax, observational experience indicates that many people (perhaps even > the vast majority of people) find it difficult to learn to read Lisp > programs. I think this holds true for experienced programmers, who often report a difficult unlearning process with Lisp. However, for people without preconceptions, the difference is likely less -- after all, many have painful memories of poorly-taught math and computer classes in school. So Python's similarity to gradeschool math may not be such a plus. Richard Stallman explained about a Lisp variant: "Multics Emacs proved to be a great success -- programming new editing commands was so convenient that even the secretaries in his office started learning how to use it. They used a manual someone had written which showed how to extend Emacs, but didn't say it was a programming. So the secretaries, who believed they couldn't do programming, weren't scared off. They read the manual, discovered they could do useful things and they learned to program." But of course this is anecdotal evidence. > Consider this: Lisp has had years of development, it has had millions of > dollars thrown at it by VC firms -- and yet Python is winning over Lisp > programmers. Think about it. Even now, Lisp still contains radical concepts (as in latin's radix meaning "root"), and overly radical ideas tend not to dominate in the marketplace. So we see an incremental progression towards Lisp ideas. Guy Steele, a central figure in Java, claimed: "And you're right: we were not out to win over the Lisp programmers; we were after the C++ programmers. We managed to drag a lot of them about halfway to Lisp. Aren't you happy?" But speaking of the marketplace, there's at least one Lisp company sustaining itself by asking for a cut of its customers' revenues... The last Lisp implementation I used "merely" asked for thousands per head per platform. ;) (Personally, I used Python before being aware of Lisp. Now I use Common Lisp all the time, though I will recommend Python when I consider it more appropriate. A few months ago, I missed the Condition System most when using Python, and also lexical scope. However, it is nice to work with friends, who know Python and not Lisp.) Tayssir From bj_666 at gmx.net Sun Dec 10 10:38:29 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sun, 10 Dec 2006 16:38:29 +0100 Subject: problem using lambdas for deferred callbacks References: <1165764662.462927.147010@79g2000cws.googlegroups.com> Message-ID: In <1165764662.462927.147010 at 79g2000cws.googlegroups.com>, edd wrote: > I was hoping that the following code would print "Hello, world!", one > character per line. But instead it prints an exclamation mark for each > character of the string. I'm sure it's no coincidence that the last > value of c is '!', but beyond that I don't understand what's happening. If you call the lambda function the name `c` is looked up in the "environment". It's not local to the function. > # --- begin code --- > def callback(arg): > print arg > > funcs = [] > for c in 'Hello, world!': > funcs.append(lambda: callback(c)) Change this line to: funcs.append(lambda x=c: callback(x)) Now the `c` is bound to the default argument `x` at definition time. Ciao, Marc 'BlackJack' Rintsch From kentilton at gmail.com Fri Dec 15 10:10:54 2006 From: kentilton at gmail.com (Ken Tilton) Date: Fri, 15 Dec 2006 10:10:54 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4ufeniF17of60U7@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> <4ufeniF17of60U7@mid.individual.net> Message-ID: <2Wygh.5$LY.0@newsfe12.lga> greg wrote: > Ken Tilton wrote: > >> The last example showed the macro inserting code to magically produce >> a binding inside the reverse function. > > > Are you sure? It looked to me like it was adding code *around* > the reverse function, not inside it. I posted a Python function > that achieves the same thing by calling the existing reverse > function. You are thinking about the results iteration, where you broke encapsulation. I just reminded you of the magical "signed-value" binding in a reply to another post of yours. btw, when looking back at the rest of the code I was reminded I had done something even wilder (well, maybe as wild) in the transforming code itself. I say "wilder" in the sense of it being waaaaay cool, having a flying-without-a-net feeling, yet making coding of dozens and dozens of these transformations simpler, terser, and less buggy. Someone had me laughing when they said the actual application of a macro was nice and simple, but the macro itself was scary. It reminded me of a cranky but sweet old guy on a project who was outraged upon learning I was using a finite state machine to handle a shaky exchange between two processes. He maintained that I was "foisting a crazy scheme on the bank" which no one would be able to maintain. He actually forced me to defend it in a group code review, the first they ever had, so don't think it was a normal process for them, this was war. After my demonstration on how the FSM would react to either or both processes going south at any point in the exchange, the crank pronounced his satisfaction with the approach and said, "OK, that is simple. The infinite-state thing is complicated, but the way it works is simple." That really made the whole thing worthwhile. :) > I'm still trying, but some of the code you posted is rather > impenetrable without knowing a lot more about the details of > your system. I'm doing my best to show some Python demonstrating > the gist of what could be done. Great. That's the spirit. But how do we move forward if you just express global confusion? See if you can understand the magical binding of the parameter "signed-value". The reverse function will be called by the engine to reverse a mathematical transformation, in this case simply taking the absolute value. The generic engine has no way of knowing out of all the targets, results, and operands (targets from a "before" expression relocated in their incarnation in the expression operated on) recorded by a transformation to pass in that position. When I code that reverse function, I just want to work on the signed-value, as identified in hard-code fashion by the transformation. ie, All I need do is coordiate the TF and its reverser. If the reverser needs something else, say the "coefficient" (this would be a add-like-terms TF), I just go to the add-like-terms and have it tag the coefficients with the symbol 'coefficient, then I can code: (reverse (coefficient literal-part)...) Ah. Time to refactor. I will have multiple coefficients, and when multiples are expected I want all the input math forms searched for those tagged coefficient. Any ideas out there? :) It is so tempting to add an s and have the macroexpansion look for a trailing s in the symbol-name, but then I am bound to have some singular and in s. Ah, grep to the rescue: (reverse (literal-part coefficient+)...) Sweet. By using + I can even have the macroexpansion insert an assertion that there is at least one. Of course there should be at least two or this TF would not fire. And so it goes... :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From roy at panix.com Thu Dec 7 10:24:54 2006 From: roy at panix.com (Roy Smith) Date: Thu, 07 Dec 2006 10:24:54 -0500 Subject: A Call to Arms for Python Advocacy References: Message-ID: In article , Jeff Rush wrote: > As the Python Advocacy Coordinator, I've put up some wiki pages on the Python > website for which I'm soliciting ideas, writing and graphics. Some of the > material exists scattered about and just needs locating and organizing. > > http://wiki.python.org/moin/Advocacy I think it also appears to need faster hardware. It's running glacially slow. From dborne at gmail.com Tue Dec 26 10:17:51 2006 From: dborne at gmail.com (Dave Borne) Date: Tue, 26 Dec 2006 09:17:51 -0600 Subject: Formatting a string to be a columned block of text In-Reply-To: <6e42ec490612260702g39630f98q2cae89067b40c6e5@mail.gmail.com> References: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> <6e42ec490612260702g39630f98q2cae89067b40c6e5@mail.gmail.com> Message-ID: <6e42ec490612260717w5c3d0a12o562b8b29444c29aa@mail.gmail.com> Thanks, Paul. I didn't know about textwrap, that's neat. Leon, so in my example change > data1= [testdata[x:x+colwidth] for x in range(0,len(testdata),colwidth)] to > data1 = textwrap.wrap(testdata,colwidth) > data1 = [x.ljust(colwidth) for x in data1] oh and I made a mistake that double spaces it. the "print '\n'" line needs to be either print '' or print '\n', (with a comma) -dave From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 23:32:13 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 15:32:13 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> Message-ID: On Sat, 09 Dec 2006 22:06:29 -0500, Ken Tilton wrote: > As I type each right parens I eyeball > its partner as the editor highlights it to make sure I have not missed > anything, Er, weren't you one of the people claiming that you don't notice parens when you're reading or writing Lisp code? Oh yes, there is this: [quote] Subject: Re: merits of Lisp vs Python From: Ken Tilton Newsgroups: comp.lang.lisp,comp.lang.python Date: Sat, 09 Dec 2006 02:29:56 -0500 Yeah, you are, you just did not use it heads down for a month. The way to tell if you spent enough time on Lisp is to look at Lisp code. If you see any parentheses, you have not spent enough time. They disappear in a month. [end quote] So, if you're still seeing parentheses, does that mean you've been coding Lisp for less than a month? -- Steven. From felipe.lessa at gmail.com Fri Dec 1 16:53:03 2006 From: felipe.lessa at gmail.com (Felipe Almeida Lessa) Date: Fri, 1 Dec 2006 19:53:03 -0200 Subject: What are python closures realy like? In-Reply-To: References: Message-ID: On 12/1/06, Karl Kofnarson wrote: [snip] > def fun_basket(f): > common_var = [0] > def f1(): > print common_var[0] > common_var[0]=1 > def f2(): > print common_var[0] > common_var[0]=2 > if f == 1: > return f1 > if f == 2: > return f2 Everytime you call fun_basket you create another common_var. > However, calling f1=fun_basket(1); f2 = fun_basket(2) and > then f1(); f2() returns 0 and 0. Two calls to fun_basket, two different common_var's, two f1's and two f2's. Each f1/f2 pair have access to a different common_var, so it's working as expected. To work as you expected, fun_basket should be on the same block common_var is defined. -- Felipe. From jordan.taylor2 at gmail.com Wed Dec 13 12:39:09 2006 From: jordan.taylor2 at gmail.com (Jordan) Date: 13 Dec 2006 09:39:09 -0800 Subject: How to manage two (different) sockets without using threads? In-Reply-To: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> References: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> Message-ID: <1166031548.903831.320450@f1g2000cwa.googlegroups.com> Why are you trying to make this asynchronous? I think part of the point of ftp using two sockets was to make it multithreaded. If you're going to make it asynchronous, It's probably going to be easier to do the "select"ing yourself, instead of relying on asyncore or asynchat. Unless you have an insanely fast connection and/or really small files on the server, using asynchronous socket handling is going to stop up the server b/c select won't check the other sockets until the current one is done with whatever it's doing. billie wrote: > Hi all. > I'm (re)writing an FTP server application by using asyncore/asynchat > modules. > FTP tipically got two different channels: command and data. > I'm succesfully managing command channel through asynchat framework, > but I'm not sure about how to manage data channel without using a > thread/subprocess. > Is there an optimal to do that? > Can anyone point me in the right direction? From konrad.hinsen at laposte.net Tue Dec 12 08:37:19 2006 From: konrad.hinsen at laposte.net (Konrad Hinsen) Date: Tue, 12 Dec 2006 14:37:19 +0100 Subject: About alternatives to Matlab In-Reply-To: <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <4A8660E1-666D-4F1E-B557-C851F84D48D0@laposte.net> On Dec 11, 2006, at 14:21, Jon Harrop wrote: > F# runs under Linux with Mono. Well, then it should also run on my Mac... Do you have any experience with performance of numerical code under Mono, or, for that matter, under .NET? I suspect that the JIT compilers were not written with number crunching in mind, but perhaps I am wrong. Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Centre de Biophysique Mol?culaire, CNRS Orl?ans Synchrotron Soleil - Division Exp?riences Saint Aubin - BP 48 91192 Gif sur Yvette Cedex, France Tel. +33-1 69 35 97 15 E-Mail: hinsen at cnrs-orleans.fr --------------------------------------------------------------------- From gagsl-py at yahoo.com.ar Sat Dec 16 18:19:39 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 16 Dec 2006 15:19:39 -0800 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> Message-ID: <1166311179.311427.190330@n67g2000cwd.googlegroups.com> On 16 dic, 04:47, Tim Roberts wrote: > > os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH >This will tell you that "x.exe" is executable, even if "x.exe" contains > nothing but zeros. Isn't the same with any other recipe, portable or not? Unless the OS actually tries to load and examine the file contents, which the OS's I'm aware of, don't do. -- Gabriel Genellina From gagsl-py at yahoo.com.ar Tue Dec 12 15:49:20 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 12:49:20 -0800 Subject: One module per class, bad idea? In-Reply-To: <1165951049.090837.145390@73g2000cwn.googlegroups.com> References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> Message-ID: <1165956560.715818.170180@j44g2000cwa.googlegroups.com> On 12 dic, 16:17, "Isaac Rodriguez" wrote: > > Yes, it would be a bad idea. =)Saying it is a bad idea and not explaining why will not help anyone. I > would like you to elaborate on why it is a bad idea to have one file > per class. The HyperText package (http://dustman.net/andy/python/HyperText) has a lot of classes (about 90 in HTML40.py); one class per HTML tag. Most of them are oneliners with "pass" alone. All are public. It would be nonsense to split them on one file per class just because you have a rule that says so. On the other hand, it would be nonsense too to mix a bunch of unrelated classes all inside a single module, just because you can do that. Common sense is hard to measure, but required as any other programming skills. (Anyone knows the story of Epaminondas and his auntie?) -- Gabriel Genellina From tundra at tundraware.com Sun Dec 17 18:35:17 2006 From: tundra at tundraware.com (Tim Daneliuk) Date: Sun, 17 Dec 2006 17:35:17 -0600 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: <1166394345_23949@sp6iad.superfeed.net> References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <1166394345_23949@sp6iad.superfeed.net> Message-ID: Roger Upole wrote: > Gabriel Genellina wrote: >> On 16 dic, 04:47, Tim Roberts wrote: >>>> os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH >>> This will tell you that "x.exe" is executable, even if "x.exe" contains >>> nothing but zeros. >> Isn't the same with any other recipe, portable or not? Unless the OS >> actually tries to load and examine the file contents, which the OS's >> I'm aware of, don't do. >> >> -- >> Gabriel Genellina >> > > On windows, you can use win32file.GetBinaryType to check if a file is actually > a binary executable. > > Roger > Yabut ... what about things like batch files? Does it return them as executable as well? -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From exarkun at divmod.com Mon Dec 18 09:57:42 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 18 Dec 2006 09:57:42 -0500 Subject: Shed Skin - Does it break any Python assumptions? In-Reply-To: <17798.41151.547934.689629@montanaro.dyndns.org> Message-ID: <20061218145742.20948.1897040075.divmod.quotient.79734@ohm> On Mon, 18 Dec 2006 08:07:59 -0600, skip at pobox.com wrote: >I just noticed the announcement of Shed Skin 0.0.16 on Freshmeat with this >(partial) change announcement: > > Changes: frozenset was added. time.sleep now works on Win32. > >Given Python's highly dynamic nature it's unclear to me how Shed Skin could >know enough about the semantics of time.sleep to know whether or not it's >broken on Win32. Actually, this could just mean that on Windows, there is no suitable implementation of the stdlib function time.sleep, and so attempts to use it will result in bad behavior of some sort. It does not necessarily mean that ShedSkin is doing anything which might prevent the attribute `sleep' from being rebound on a module importable as `time' to some other function which behaves differently. Of course, what is not necessarily the case may still be the case. ;) >This suggests that to gain speedups it probably implements >a more static language than Python. For example, does Shed Skin handle a >case like this? > > >>> import time > >>> time.sleep(1) > >>> def _sleep(n): > ... print "sleeping for", n, "seconds" > ... time._sleep(n) > ... > >>> time._sleep = time.sleep > >>> time.sleep = _sleep > >>> time.sleep(1) > sleeping for 1 seconds > >What does this phrase in the announcement mean? "... pure but implicitly >statically typed Python ...". Where does the static typing begin and end? >Can one module tweak another module's attributes? Can a class's attributes >be modified from outside the class? What about the attributes of a class >instance? >From the ShedSkin README: Do not use: ... -reflection (getattr, hasattr), eval, or other really dynamic stuff ... I would say that the example you presented above falls into the "really dynamic stuff" category. ;) And in fact, attempting to compile a program somewhat like the one above results in this: exarkun at charm:~/Scratch/Source/shedskin-0.0.16$ make g++ -O3 -I./lib ./lib/builtin.cpp ./lib/time.cpp foo.cpp -lgc -o foo foo.cpp: In function ?int __foo__::__main()?: foo.cpp:6: error: assignment of function ?void __time__::sleep(double)? foo.cpp:6: error: cannot convert ?unsigned int ()(unsigned int)? to ?void ()(double)? in assignment make: *** [foo] Error 1 exarkun at charm:~/Scratch/Source/shedskin-0.0.16$ So yes, it seems that what ShedSkin supports is pretty distant from what a seasoned Python developer might expect, aside from syntactic constructs. Jean-Paul From gonzlobo at gmail.com Tue Dec 26 18:50:06 2006 From: gonzlobo at gmail.com (gonzlobo) Date: Tue, 26 Dec 2006 16:50:06 -0700 Subject: Noobie: Open file -> read characters & multiply Message-ID: I've been using Python for a few days. It's such the perfect language for parsing data! I really like it so far, but I'm having a hard time reading a file, reading the first few hex characters & converting them to an integer. Once the characters are converted to an integer, I'd like to write the data to another file. Here's the code snipped to the bare minimum: --- # Open File AP_File= open("AP.txt", "r") decoded_File= open("decoded.txt", "w") # read & process data line by line for line in AP_File: time = int(hex(line[0:8]), 16) * 0.0001 # this line is completely hosed! decodedFile.write(time) #close files AP_File.close() decoded_File.close() --- AP.txt 000000d5 26 0600 80 00 ec 80 02 03 7d db 02 33 000000d5 26 0601 80 00 80 00 02 37 fe 54 01 09 000000d5 06 0602 80 00 e0 00 01 29 fe d2 69 99 000000d5 06 0603 80 00 e0 00 02 29 fe d2 6a 99 000000d5 26 0604 80 00 fe 54 02 09 80 00 01 5d 000000d5 06 0605 80 00 e0 00 02 15 fc 71 ca 0b 000000d5 4a 0610 81 00 86 00 02 26 12 00 02 a6 000000d5 4f 0611 00 00 00 50 00 00 00 00 07 00 000000d5 06 0612 80 00 e0 00 01 15 fc 71 c9 0b 000000d5 0a 0613 08 5c 04 88 08 98 00 00 00 00 000000d5 06 0614 80 00 e0 00 02 01 60 79 82 2b 000000d5 0a 0615 08 00 00 00 00 00 00 00 00 00 000000d5 26 0616 80 00 80 00 02 5d 04 22 3a 88 (actual files are 250MB!) decodedTime.txt (should be) 0.0213 26 0600 80 00 ec 80 02 03 7d db 02 33 ... My boss and I are trying to complete the same task (he figured out how to do it, but his code uses a while != "" loop and doesn't look pythony (it looks too 'c'). Not that there's anything wrong with that! Any help is really appreciated. From jon at ffconsultancy.com Thu Dec 14 05:36:37 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Thu, 14 Dec 2006 10:36:37 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> <1166035311.357588.115070@80g2000cwy.googlegroups.com> Message-ID: <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> Filip Wasilewski wrote: > Jon Harrop wrote: >> Filip Wasilewski wrote: >> > Jon, both Python and Matlab implementations discussed here use the >> > lifting scheme, while yours is a classic convolution based approach. >> >> I've done both in OCaml. The results are basically the same. > > Have you tried taking advantage of the 50% reduction of arithmetic > operations for the lifting scheme? Yes. The time taken is dominated by memory accesses. The amount of arithmetic is almost irrelevant. >> It makes sense because they solve the same problem. When you're comparing >> non-trivial problems between disparate languages you are not likely to >> use the same algorithms. Using built-in hash functions is an obvious >> example. > > I don't even ask if you have checked the output result coefficients > because I'm pretty sure you have not. I checked the coefficients against other DWTs from the web. > They solve similar problem but in > different ways and give a bit different results, for example the > layout of coefficients in the memory is different as well as border > distortion handling. Please don't tell me it's better to do something > else instead of presenting a relevant solution. I used a more efficient approach because I could. Using a compiled language gave me that choice. We should compare both approaches in both languages. >> No. The effects you are talking about are swamped by the interpreted vs >> compiled effect. > > Have I already mentioned it was observed with low-level C > implementation on x86? I would really appreciate you took some time on > exploring the unfortunate topic of this benchmark before posting > another comment like that. We are talking about this Python implementation, not some "low-level C implementation on x86". With Python, it is the overhead of the interpreter that makes it slow and encourages you to obfuscate your code in order to make it run in a reasonable amount of time. > What I would really like to see is a lifting scheme > implementation that can take 1- to 10-dimensional arrays I believe that is just a case of abstracting get/set. > (single and double precision floats, That is also a case of abstracting get/set. > convert on the fly from integer types when necessary That is dynamic typing. > and handle strided, non-contiguous arrays), That is also an abstraction of get/set. > axis and maximum decomposition level as input I don't know what that is. > and return list of views (or arrays if necessary) Probably just a closure. > with transform coefficients for every level of > decomposition. Can do? Sure. Sounds like a lot of work though. This would be best done in F# because you can make your own IList derivatives with get_Item and set_Item that provide views but look like arrays. > Are you telling I have to define a different operator for every > arithmetic operation for every two types? In OCaml, yes. Not in F#. > That definitely does not look > like a quick, flexible and clear solution to start with. Any working > example I could type into OCamlWinPlus of the following would be very > appreciated. I'm fairly new to this and would really like to see how to > handle differently shaped arrays and data types in the interactive mode > without much hassle: > > from numpy import ones, arange, reshape, int32 > a = ones((2,3,4,5)) > b = ones(a.shape, dtype=int32) > c = ones((3,4,5)) > d = 2*a + 2.5*(3*b + 3.3) > d[0] = d[0] + 5 > d[1] *= c * (2+3*1.2) > d[:,2,...] = reshape(arange(d[:,2,...].size), d[:,2,...].shape) > print d[...,1] I can't get that to work in Python. What do I need to do? >>> import numpy >>> a = ones((2,3,4,5)) Traceback (most recent call last): File "", line 1, in ? NameError: name 'ones' is not defined > The ray tracer example is really nice, however the sudoku solver is not > so impressive when compared to the K thingy ;-) - > http://markbyers.com/moinmoin/moin.cgi/ShortestSudokuSolver. Well, OCaml does ok on the sudoku but K does awfully on the ray tracer. >> > I was also unable to run your OCaml example for n >= 2^21 (win32, out >> > of the box OCaml installation). Is there some 16MB memory limit imposed >> > on Array? >> > # let q = Array.make (1 lsl 21) 0.0;; >> > Exception: Invalid_argument "Array.make". >> >> On 32-bit, yes. You'd either have to use a different data structure >> (Bigarrays), upgrade or switch to F#. > > That renders the Array type almost useless for me. Where can I find > documentation or tutorial on using Bigarrays? http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html You probably want to use F# though. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From tdelaney at avaya.com Thu Dec 21 18:29:50 2006 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Fri, 22 Dec 2006 10:29:50 +1100 Subject: Fall of Roman Empire Message-ID: <2773CAC687FD5F4689F526998C7E4E5FF1EC5B@au3010avexu1.global.avaya.com> Hendrik van Rooyen wrote: > naaah - you don't have to worry - for real control He uses assembler. > with jump statements. > so the loops are closed. > > Unfortunately its not open source. Yet. People are working hard on reverse-engineering it though. I hope no one slaps them with a DMCA-style lawsuit ... Tim Delaney From pwatson at redlinepy.com Fri Dec 15 23:56:42 2006 From: pwatson at redlinepy.com (Paul Watson) Date: Fri, 15 Dec 2006 22:56:42 -0600 Subject: convert from date string to epoch In-Reply-To: References: Message-ID: <4uhckaF17ivldU1@mid.individual.net> Stefan Antonelli wrote: > Hi, > > i have to convert several timestamps. The given format, eg "yyyy-mm-dd hh:mm:ss" > has to be converted to an epoch string. Is there any proper way to do this? > > If not, i have to split the given string and resolve this by a calculation? > > Thanks for help. > > Stefan. I saw some code on the net. ASPB I think. I whacked a few more lines to be an example. #!/usr/bin/env python import httplib import time ht = httplib.HTTP('www.python.org') fich='/index.html' print fich, ht.putrequest('GET', fich) ht.endheaders() errcode, errmsg, headers = ht.getreply() print headers.dict print headers.dict['server'] textoFecha=headers.dict['date'] print textoFecha fecha = time.strptime(textoFecha,'%a, %d %b %Y %H:%M:%S %Z') print fecha print time.asctime(fecha) print time.mktime(fecha) print "===" fecha = time.strptime('2006-12-15 19:42','%Y-%m-%d %H:%M') print fecha print time.asctime(fecha) print time.mktime(fecha) From ejatsomewhere.com Wed Dec 27 20:04:56 2006 From: ejatsomewhere.com (Erik Johnson) Date: Wed, 27 Dec 2006 18:04:56 -0700 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: <4593185f$1@nntp.zianet.com> "Ben Finney" wrote in message news:mailman.2061.1167261027.32031.python-list at python.org... > "Sebastian 'lunar' Wiesner" writes: > > > Just a tip for you: In python you never use tabs for indentation. > > For some value of "you". > > > The python style guide [1] recommends four spaces per indentation > > level. > > > > [1] http://www.python.org/dev/peps/pep-0008/ > > It's not quite absolute on the topic: > > For new projects, spaces-only are strongly recommended over tabs. Even if were, read the Introduction. This is a coding standard intended to apply to code which is going to checked in as part of the core python build, not all Python! It's probably a pretty good standard to be following in general, but come on... If Guido really wanted this enforced across the board he could simply call anything that doesn't meet this standard to the letter a SyntaxError and just stop there. For example, the standard states: - Imports should usually be on separate lines, e.g.: Yes: import os import sys No: import sys, os >>> import sys, os Traceback (most recent call last): File "", line 1, in ? ImportError: Sorry, only one module per import line! I'm sure that's not Guido's intention. ;) -ej From paul.rudin at ntlworld.com Tue Dec 5 08:59:55 2006 From: paul.rudin at ntlworld.com (Paul Rudin) Date: Tue, 05 Dec 2006 13:59:55 +0000 Subject: Ensure a variable is divisible by 4 References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> <1165323726.255327.11530@j72g2000cwa.googlegroups.com> <457578D6.9080902@mxm.dk> Message-ID: <87r6ve8muc.fsf@rudin.co.uk> Max M writes: > geskerrett at hotmail.com skrev: >> Nick Craig-Wood wrote: >>> geskerrett at hotmail.com wrote: >>>> I am sure this is a basic math issue, but is there a better way to >>>> ensure an int variable is divisible by 4 than by doing the following; >>>> >>>> x = 111 >>>> x = (x /4) * 4 > > X *= 4 > > ;-) > x=4 :) From pkarjala at paju.oulu.fi Mon Dec 11 14:16:40 2006 From: pkarjala at paju.oulu.fi (Pekka Karjalainen) Date: Mon, 11 Dec 2006 19:16:40 +0000 (UTC) Subject: alternate language References: <12nr93mis39tu45@corp.supernews.com> Message-ID: In article , Aahz wrote: >In article <12nr93mis39tu45 at corp.supernews.com>, >Grant Edwards wrote: >>On 2006-12-11, Aahz wrote: >>> >>> Um... I think the original poster is saying that he already knows Python >>> and wants to learn another language. He particularly wants opinions from >>> other people who have learned these languages *after* learning Python. >> >>There are people who learn another language after learning Python?? > >Heh. Taking your post more seriously than it deserves, don't you think >someone ought to learn at least SQL if they don't already know it when >they learn Python? >-- >Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ > >Member of the Groucho Marx Fan Club From pavlovevidence at gmail.com Wed Dec 27 17:27:32 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 27 Dec 2006 14:27:32 -0800 Subject: Getting unicode escape sequence from unicode character? In-Reply-To: References: Message-ID: <1167258452.762117.13300@48g2000cwx.googlegroups.com> Kenneth McDonald wrote: > Given a Python unicode character (string of length one), how would I > find out the \uXXXX escape sequence for it? This isn't obvious from the > docs I've been looking through. You can use the ord builtin, or the encode method with "unicode_escape": >>> a = u'\u1234' >>> a u'\u1234' >>> print a ? >>> ord(a) 4660 >>> hex(ord(a)) '0x1234' >>> a.encode('unicode_escape') '\\u1234' Carl Banks From irmen.NOSPAM at xs4all.nl Wed Dec 6 16:00:04 2006 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 06 Dec 2006 22:00:04 +0100 Subject: newb: Can I use PYRO In-Reply-To: <1165435114.572787.34010@n67g2000cwd.googlegroups.com> References: <1165435114.572787.34010@n67g2000cwd.googlegroups.com> Message-ID: <45772f5f$0$332$e4fe514c@news.xs4all.nl> johnny wrote: > What I want to do is the following: > > Web user uploads a word doc (web app written in php), and I need it to > move the uploaded word > doc, on to another machine and conver it to pdf. Then update the > database and allow immediate pdf download. I am thinking of using ftp > from machine 1 -> machine 2, then convert doc to pdf on machine 2, > using process or thread. What is the best way to go about doing this, > process or threads or pyro? Pdf is created by calling commands on the > command line, through python script. Even though you are using Python on the machine that converts things to PDF, you're stuck with PHP on the web server. You cannot use Pyro with PHP. --Irmen From pavlovevidence at gmail.com Tue Dec 12 18:09:28 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 12 Dec 2006 15:09:28 -0800 Subject: One module per class, bad idea? References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> Message-ID: <1165964967.940454.74490@73g2000cwn.googlegroups.com> Carl J. Van Arsdall wrote: > Isaac Rodriguez wrote: > >> Yes, it would be a bad idea. =) > >> > > > > Saying it is a bad idea and not explaining why will not help anyone. I > > would like you to elaborate on why it is a bad idea to have one file > > per class. > > > A module per class makes a lot of sense in some cases, or rather, make > your module your class (look at the singleton pattern). I actually like > to structure all of my code like this, it helps me keep things organized > and separated. I don't understand. Are you saying you organize your code to be a bunch of modules masquerading as singleton classes? (When I was a young'n, we called that "procedure oriented programming" :) > I guess i'm not sure why it would ever be a really bad > idea, maybe if you had really small classes? Or maybe you have really big classes. The potential problem with one module per class is one of missed opportunity: namely the missed opportunity for a higher-level organization. Classes are rarely, probably never, a good way to organize code at the highest levels. It's better to organize code into subsystems of some sort. It's very rare that each class is an independent subsystem unto itself; most high-level subsystems would encompass many classes (as well as other code). When you strictly obey a one class per module rule, you lose the possibility of using the module as a means of organizing subsystems (and subsubsystems, and so on). Now, I think this is the best way to use modules, but you don't need to use modules to do get higher-level organization; you could use packages instead. It's a pain if you're working on two different classes in the same system you have to keep switching files; but I guess some people prefer to switch files rather than to scroll for some reason. I'd say as long as you use package system, and not just a flat modulespace, it's not fundamentally disorganized to use a one class per module rule. In the end, it probably comes down to what you prefer, but I think most people would prefer not to obey a one class per module rule. Carl Banks From frank at chagford.com Wed Dec 6 08:48:14 2006 From: frank at chagford.com (Frank Millman) Date: 6 Dec 2006 05:48:14 -0800 Subject: reloading modules In-Reply-To: <1165406976.641077.45350@f1g2000cwa.googlegroups.com> References: <1165406976.641077.45350@f1g2000cwa.googlegroups.com> Message-ID: <1165412894.280486.215710@79g2000cws.googlegroups.com> aine_canby at yahoo.com wrote: > I'm using python.exe to execute my modules. I have a music.py module > which contains my classes and a main.py module which uses these > classes. In python.exe, I call "import main" to execute my program. The > problem is that I have to close python and reopen it everytime i change > music.py or main.py. What should I be doing. > > Thanks, > > Aine. Instead of calling 'import', use the 'imp' module and call 'find_module' followed by 'load_module'. As the docs explain, one of the differences between this and 'import' is that it loads the module every time, even if it is already imported. HTH Frank Millman From timr at probo.com Sat Dec 30 02:44:47 2006 From: timr at probo.com (Tim Roberts) Date: Sat, 30 Dec 2006 07:44:47 GMT Subject: File write() problem References: <1167207703.803035.277720@42g2000cwt.googlegroups.com> Message-ID: apriebe47 at gmail.com wrote: >Alright, I realize this is probably very basic to be posted on this >newsgroup but I cannot figure out what is causing my problem. Here is >the code I am using below: > >from getpass import getpass > >configfile = file('config.txt', 'w') >serverPassword = configfile.readline() > if serverPassword == '': > print "Server warning: No password has been set!" > pwd1 = getpass("New Password: ") > pwd2 = getpass("Confirm Password: ") > while pwd1 != pwd2: > print "Passwords did not match." > pwd1 = getpass("New Password: ") > pwd2 = getpass("Confirm Password: ") > print "Password set. Storing to file" > configfile.write(pwd2) > serverPassword = configfile.readline() > configfile.close() > >Now when I look at the file, I can see the password that I had typed >in, but there are also a bunch of symbols that are added to the text >file as well. My question is how can I write just the password to the >text file and not any extra 'garbage'. Thanks! You want every file access to start at the beginning of the file. So, there is really no point in maintaining a persistent file object at all: FN = 'config.txt' serverPassword = open(FN, 'r').readline() if not serverPassword: print "Server warning: No password has been set" pwd1 = getpass("New Password: ") pwd2 = getpass("Confirm Password: ") while pwd1 != pwd2: print "Passwords did not match" pwd1 = getpass("New Password: ") pwd2 = getpass("Confirm Password: ") open(FN, 'w').write(pwd2+'\n') serverPassword = open(FN, 'r').readline() -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kentilton at gmail.com Wed Dec 13 14:13:23 2006 From: kentilton at gmail.com (Ken Tilton) Date: Wed, 13 Dec 2006 14:13:23 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> Message-ID: Robert Uhl wrote: > Christophe writes: > >>Robert Uhl a ?crit : >> >> >>>The argument from popularity is invalid. French units have overtaken >>>standard units, >> >>Never heard of that French unit thing. Unless you talk about that >>archaic unit system that was in use before the metric system was >>created. > > > I use 'French units' instead of the term 'metric system' because the > latter means 'measurement system,' and of course could validly be > applied to _any_ system. > Now we know how one contractor ended up using English units when the other was using French units and an entire Mars mission was lost: they were both using the metric system. [cue NASA aopologist Ron (or his sidekick Al) for some scenery-chewing outrage over my condescension and arrogance.] ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From sjmachin at lexicon.net Fri Dec 1 22:35:26 2006 From: sjmachin at lexicon.net (John Machin) Date: 1 Dec 2006 19:35:26 -0800 Subject: strange problems with code generation In-Reply-To: <1165028063.205065.75360@n67g2000cwd.googlegroups.com> References: <1165022658.313170.134140@79g2000cws.googlegroups.com> <1165025792.522242.281730@l12g2000cwl.googlegroups.com> <1165028063.205065.75360@n67g2000cwd.googlegroups.com> Message-ID: <1165030526.354684.143270@j72g2000cwa.googlegroups.com> You say "I am sure the readlines code is crashing it." I can't imagine how you can be sure of anything, but yes, it is a possibility that sys.stdin.readlines() might behave strangely when called from a GUI kit. Why from sys.stdin anyway? You have two *known* definite problems (not closing your output files, and no such attribute as "writeline") -- *fix* them, and try again. Do try to test that function in isolation. Put print statements in as I suggested. Comment out the .bat file invocation. Try calling the function from the interactive interpteter. Check if the files are being created, with the right size. If it works, add back the .bat file invocation. If that works, try it from your GUI. IOW, try to attack your problem methodically. AND try to answer at least some of the questions that helpers might ask you, like what does "print(data)" produce -- they're not asked out of idle curiosity. HTH, John From fossilx at gmail.com Fri Dec 1 12:39:49 2006 From: fossilx at gmail.com (TonyM) Date: 1 Dec 2006 09:39:49 -0800 Subject: client/server design and advice In-Reply-To: <4tauodF120o5fU1@mid.uni-berlin.de> References: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> <4tauodF120o5fU1@mid.uni-berlin.de> Message-ID: <1164994789.168555.302490@f1g2000cwa.googlegroups.com> > Don't use sqlite, use a "real" RDBMS. sqlite is cool, but not really suited > for large amounts of data, and the concurrent access aspects that are dealt > with with an RDBMS for free are not to be underestimated. Would PostgreSQL be suitable in this situation? I hadn't even thought about the possible problems that could arise with concurrency but i do recall it being an issue the last time i worked with sqlite. I have also looked into mysql given my extensive experience with it...however postgresql seems to be faster from what ive read. Either way i'll work on writing something to convert and insert the data so that it can process while im working on the gui and client/server apps. > Pyro rocks for that. Awesome, ill look into it in greater detail and will most likely use it. Given what ive seen so far it looks like it will make the client/server interface fairly easy to write. Now...if only i could master python gui programming and development ;) I'm not entirely sure which gui lib im going to end up using, but as of now im leaning more towards tkinter as i know it will work where i need and it seems to be one of the more documented. Ive looked at used wxpython a little but had trouble figure out a few minor things while playing around with it initially. I've also thought about pygtk although I haven't taken the time to play with it quite yet as i assumed it was primarily for linux (id be running the majority of these on windows pcs). Thanks for the suggestions :) Tony From mo3749 at gmail.com Sat Dec 23 01:17:58 2006 From: mo3749 at gmail.com (mo3749 at gmail.com) Date: 22 Dec 2006 22:17:58 -0800 Subject: Python and AltiVec Message-ID: <1166854678.528699.283020@h40g2000cwb.googlegroups.com> Hi, Is there any library or linkings or compatibilities of Python with AltiVec(r). I KNOW, It is all very OLD stuff, but I just want to know???? From harry.g.george at boeing.com Mon Dec 4 09:08:08 2006 From: harry.g.george at boeing.com (Harry George) Date: Mon, 4 Dec 2006 14:08:08 GMT Subject: Pimping the 'cgi' module References: <1164306918.845529.95820@f16g2000cwb.googlegroups.com> Message-ID: robert writes: > Harry George wrote: > > When I came from Perl, I too missed perl-isms and specifically CGI.pm, so wrote my own: > > http://www.seanet.com/~hgg9140/comp/index.html > > http://www.seanet.com/~hgg9140/comp/pyperlish/doc/manual.html > > http://www.seanet.com/~hgg9140/comp/cgipm/doc/index.html > > Others on this newsgroup said I'd be better off just doing it in raw > > python. After a while, I realized that was true. You do > > triple-quoted templates with normal python idioms. Throw in > > some persistence mechanisms to deal with maintaining state across > > transactions, and you are in business. > > Since then I've looked at Zope, Plone, TurboGears, Django, and (for > > standalone apps) Dabo. TurboGears is mostly a set of recommendations > > on what 3rd party packages to use, with a wee bit of glueware. So far > > nothing feels as simple as just doing it in python. > > > Thats the fragmented journey, almost any web programmer has to go when coming to python. A clear standard, even a clear intro, for simple tasks, like doing state mng, db, error handling, etc. is not there on an easy path. > > For a level above cgi, what do you think about cherrypy ? http://docs.cherrypy.org/ > > Robert I have only done "hello, world" stuff in cherrypy. We do everything from apache, so the server part of cherrypy wouldn't be needed, and getting to it from a mod_rewrite would just be extra hassle. Mostly we do model-view-controller, were the "view" may be batch, commandline, desktop gui, GUI, SOAP, etc. If it works with a simple coded-by-hand CGI, that's all we do. -- Harry George PLM Engineering Architecture From jm.suresh at gmail.com Tue Dec 12 01:20:06 2006 From: jm.suresh at gmail.com (jm.suresh@no.spam.gmail.com) Date: 11 Dec 2006 22:20:06 -0800 Subject: namespace question Message-ID: <1165904406.053883.129610@l12g2000cwl.googlegroups.com> Hi , class Test: a = 1 b = 2 c = 1+2 Now, all a,b and c would be directly visible to the user from the instance of Test. I am looking for a way to make only c directly visible from the instance. -- Suresh From scumitchell at gmail.com Fri Dec 8 12:16:54 2006 From: scumitchell at gmail.com (scum) Date: 8 Dec 2006 09:16:54 -0800 Subject: Problem in reading a URL In-Reply-To: References: Message-ID: <1165598214.547781.125240@j44g2000cwa.googlegroups.com> This is not a python problem. That is the text of the site when you go to it. The site uses cookies to store a session of your visit. Using python bypasses that cookie and throws an error. You will be better served using teh mechanize library. http://wwwsearch.sourceforge.net/mechanize/ Even though you may not get far, since the site you are attempting to search prevents robots from scouring their site. >>> import mechanize >>> from mechanize import Browser >>> br= Browser() >>> br.open("http://www.ncbi.nlm.nih.gov/entrez/") Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/mechanize-0.1.4b-py2.4.egg/mechanize/_mechanize.py", line 156, in open File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/mechanize-0.1.4b-py2.4.egg/mechanize/_mechanize.py", line 214, in _mech_open mechanize._response.httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt From mystilleef at gmail.com Sun Dec 10 10:54:22 2006 From: mystilleef at gmail.com (mystilleef) Date: 10 Dec 2006 07:54:22 -0800 Subject: merits of Lisp vs Python In-Reply-To: <87irgjkbl6.fsf@killalla.dreaming> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165764570.956203.223370@16g2000cwy.googlegroups.com> <87irgjkbl6.fsf@killalla.dreaming> Message-ID: <1165766062.705304.306220@16g2000cwy.googlegroups.com> Bj?rn Lindstr?m wrote: > Encapsulation isn't so much a property of the language as of your data > types. "Modern" and well designed object oriented languages provide sane mechanisms for encapsulation, at least when implementing new types. > Python also lacks encapsulation, in the sense you probably mean. > That's news to me. How so? From eadmund42 at NOSPAMgmail.com Tue Dec 12 10:56:14 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 08:56:14 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> Message-ID: Mathias Panzenboeck writes: > > I do not know much about Lisp. What I know is: > > Python is a imperative, object oriented dynamic language with duck > typing, List is a declarative, functional dynamic language -> those > two languages have different scopes. Common Lisp is an object oriented language too, and while it has more declarative features than Python, I don't think that it's really fair to call it declarative in the same sense as, say, SQL. Language-feature-wise, Lisp is a superset of Python: there's nothing one can do in Python that cannot be done in Lisp, although there are some things one would need to write oneself (e.g. generators) and some stuff would be more of a pain (e.g. Python provides iterators, which means that for can understand new objects; CL LOOP is not extensible, unless I have missed something big, but it's simple enough to write a map-new-object or loop-new-object or whatever). Library-wise, Python is pretty much a superset of Lisp, and in fact many of the things Lisp was criticised for providing as a standard part of the language are also standard parts of Python. -- Robert Uhl The problem with 'post-modern' society is there are too many people with nothing meaningful to do, building 'careers' around controlling the lives of others and generally making social nuisances of themselves. --Graham Strachan From raphael.marvie at gmail.com Fri Dec 15 08:38:54 2006 From: raphael.marvie at gmail.com (raphael.marvie at gmail.com) Date: 15 Dec 2006 05:38:54 -0800 Subject: Problem comparing object graphs and trees Message-ID: <1166189934.686619.56720@16g2000cwy.googlegroups.com> Dear all, I am trying to compare graphes of object through the use of the __cmp__ operator. Before managing the problem of recursive comparison, I have tried a simple test which result surprises me. Here is the simplest code I can write that presents my problem: $ cat cmp.py class A: def __init__(self, b): self.b = b def __cmp__(self, other): return self.b == other.b class B: pass if __name__ == '__main__': b = B() a1 = A(b) a2 = A(b) print a1 == a2 print a1 == a1 $ python cmp.py False False I swear I am not drunk, but why isn't a1 == a2 and worse why isn't a1 == a1? Does someone have a clue and can explain to me this suprising behavior? (python 2.4.3 on Ubuntu 6.06). Cheers, r. From pydecker at gmail.com Fri Dec 1 16:29:19 2006 From: pydecker at gmail.com (Peter Decker) Date: Fri, 1 Dec 2006 16:29:19 -0500 Subject: client/server design and advice In-Reply-To: <1164998259.046246.323140@l12g2000cwl.googlegroups.com> References: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> <4tauodF120o5fU1@mid.uni-berlin.de> <1164994789.168555.302490@f1g2000cwa.googlegroups.com> <1164998259.046246.323140@l12g2000cwl.googlegroups.com> Message-ID: On 1 Dec 2006 10:37:39 -0800, John Henry wrote: > > Now...if only i could master python gui programming and development ;) > You would short change yourself if you don't check out the other > packages such as Pythoncard, and Dabo. FWIW, Dabo has all of the database connectivity stuff built-in. With PythonCard, you have to roll your own. -- # p.d. From beliavsky at aol.com Mon Dec 11 12:57:26 2006 From: beliavsky at aol.com (Beliavsky) Date: 11 Dec 2006 09:57:26 -0800 Subject: About alternatives to Matlab In-Reply-To: <1163711343.870829.110030@h48g2000cwc.googlegroups.com> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> Message-ID: <1165859846.878169.111000@n67g2000cwd.googlegroups.com> I came across SAGE "Software for Algebra and Geometry Experimentation" http://sage.math.washington.edu/sage/ , which includes Python and Numeric and consists of Group theory and combinatorics -- GAP Symbolic computation and Calculus -- Maxima Commutative algebra -- Singular Number theory -- PARI, MWRANK, NTL Graphics -- Matplotlib Numerical methods -- GSL and Numeric Mainstream programming language -- Python Interactive shell -- IPython Graphical User Interface -- The SAGE Notebook Versioned Source Tracking -- Mercurial HG Maybe people who has tried this could give their impressions. From tomas at fancy.org Tue Dec 12 15:23:48 2006 From: tomas at fancy.org (Tom Plunket) Date: Tue, 12 Dec 2006 12:23:48 -0800 Subject: Problem understanding how closures work Message-ID: ...at least, I think that I'm having a problem understanding the way closures work. I'm trying to define a function for an object which will take certain objects from the parent scope at the time that function is defined. For some reason, if I do this function definition in a loop, the locals given by that function (is this a closure?) are changed each iteration of the loop, whereas if the function definition is isn't looped over, I get the behavior I desire. Can anyone provide any insight for me? thanks, -tom! First, the output: Test 1 doesn't work the way I would expect: Test 4 says, "Test 0" Test 4 says, "Test 1" Test 4 says, "Test 2" Test 4 says, "Test 3" Test 4 says, "Test 4" ...but test 2 does? Test 0 says, "Test 0" Test 1 says, "Test 1" Test 2 says, "Test 2" Test 3 says, "Test 3" Test 4 says, "Test 4" Next, the program: class Test: def __init__(self, name): self.name = name def DoCall(self): self.ExternalCall(self.name) # The first test. def CreateTests1(count): tests = [] for i in xrange(count): name = 'Test %d' % i t = Test(name) tests.append(t) def ExCall(text): print '%s says, "%s"' % (name, text) t.ExternalCall = ExCall return tests # The second test. def CreateTests2(count): tests = [] for i in xrange(count): t = CreateTest(i) tests.append(t) return tests def CreateTest(index): name = 'Test %d' % index t = Test(name) def ExCall(text): print '%s says, "%s"' % (name, text) t.ExternalCall = ExCall return t print 'Test 1 doesn\'t work the way I would expect:' for t in CreateTests1(5): t.DoCall() print '\n...but test 2 does?' for t in CreateTests2(5): t.DoCall() From slawomir.nowaczyk.847 at student.lu.se Wed Dec 13 17:00:29 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Wed, 13 Dec 2006 23:00:29 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: Message-ID: <20061213225450.57B0.SLAWOMIR.NOWACZYK.847@student.lu.se> On Sun, 10 Dec 2006 10:11:37 -0500 Ken Tilton wrote: #> Lisp has all the cool qualities you like in your pets, plus native #> compilation in most implementations, plus maturity and a standard, plus #> a better OO, plus macros, plus a dozen more small wins. Including #> automatic indentation. :) Automatic indentation? Wow, that's cool... we in Python need to press RET and sometimes even use this ugly ":" or "" key to get proper indentation. Oh, wait, you mean you need to type "(" and ")" in Lisp? What's automatic about *that*??? -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) Grossman's Law: Complex problems have simple, easy-to-understand, wrong answers. From hg at nospam.org Mon Dec 4 05:43:50 2006 From: hg at nospam.org (hg) Date: Mon, 04 Dec 2006 04:43:50 -0600 Subject: RAD for python References: <1165214291.653950.200420@j72g2000cwa.googlegroups.com> Message-ID: progman wrote: > > is there a VB-alike tool for python to create forms?? http://wxglade.sourceforge.net/ http://boa-constructor.sourceforge.net/ http://www.activestate.com/Products/Komodo/ http://www.roebling.de/ hg From roy at panix.com Tue Dec 12 09:14:55 2006 From: roy at panix.com (Roy Smith) Date: Tue, 12 Dec 2006 09:14:55 -0500 Subject: What are python closures realy like? References: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> Message-ID: John Nagle wrote: > Most of the examples given here are kind of silly, but closures have > real uses. I used one today in Javascript because I was writing an > AJAX application, and I was using an API, the standard XMLHttpRequestObject, > which required a callback function with no arguments. A closure allowed > the code to pass relevant information with the callback function, which > would be called when a request to the server completed. A global > variable wouldn't have worked, because multiple instances of the object > making the callback are possible. As another example, from a large C++ project I'm currently working on, we use closures in many places to push actions onto queues. One kind of queue we have is a timed queue. You push a closure and a time onto it, and it executes the closure at the appointed time. Another kind of queue is for inter-thread communication. You push a closure onto a thread's input queue when you want it to do something. The thread just keeps popping closures off the other end of the queue and executing them. Think of a closure as a way of saying "do this". You can say, "At 5:00, do this", or "Do this as soon as you get a chance". # pseudocode class husband (spouse): def pickUpGroceries(): etc def addToQueue(): etc c = makeClosure (husband.pickUpGroceries, [milk, eggs, bread]) h = husband() h.addToQueue (c) From juanrgonzaleza at canonicalscience.com Mon Dec 11 09:44:39 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 11 Dec 2006 06:44:39 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165845397.504922.121720@j44g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xac1wr7t9.fsf@ruckus.brouhaha.com> <1165768221.753809.4270@f1g2000cwa.googlegroups.com> <1165826008.371063.293080@73g2000cwn.googlegroups.com> <1165845397.504922.121720@j44g2000cwa.googlegroups.com> Message-ID: <1165848279.487520.14610@l12g2000cwl.googlegroups.com> philip.armitage at gmail.com ha escrito: > Juan R. wrote: > > philip.armitage at gmail.com ha escrito: > > > - Lisp is hard to learn (because of all those parenthesis) > > > > I cannot understand why. It is like if you claim that packaging things > > in boxes is difficult to learn. > > > > HTML and XML have more brackets than LISP (usually double) for > > structuring data and everyone has learned HTML. > > I think maybe you missed the point I was making. Yes i did, sorry > To make it clearer I'm saying that the arguments that are being made > over and over again against Lisp in this thread have been the > antithesis of my experience since moving from Python to Lisp. > > I just prefer personal experience to popular misconceptions :-) I often count 'parentheses' used in other approaches. E.g. the LISP-based [HTML [@:XMLNS http://www.w3.org/1999/xhtml] [HEAD [TITLE Test page]] [BODY]] is SLiP (Python) html(xmlns="http://www.w3.org/1999/xhtml"): head(): title(): "Test page" body(): LISP-based: 5 ( 5 ) 1 @ 1 : Python: 4 ( 4 ) 1 = 4 " 4 : From reverseyorkage at david.com Fri Dec 15 05:44:33 2006 From: reverseyorkage at david.com (dyork) Date: Fri, 15 Dec 2006 10:44:33 GMT Subject: Roundtrip SQL data especially datetime Message-ID: When getting data from a database using the dbapi and an SQL query, how do you in general round trip the data? Especially date-time? An SQL datetime column translates nicely into a Python datetime (surprise), which then translates into a string like '2005-08-03 07:32:48'. No problem with that -- all works quite nicely, until you try to put data back the other way. There is no obvious way to parse that string back into a datetime, and having done so no obvious way to push that back into a SQL datetime column. Am I missing something? [I would particularly like to avoid getting trapped by SQL "local settings" too.] DavidY From sjmachin at lexicon.net Mon Dec 11 00:32:48 2006 From: sjmachin at lexicon.net (John Machin) Date: 10 Dec 2006 21:32:48 -0800 Subject: Newbie Question - Checkboxes In-Reply-To: <1165737399.895450.85620@f1g2000cwa.googlegroups.com> References: <1165737399.895450.85620@f1g2000cwa.googlegroups.com> Message-ID: <1165815168.464198.322250@79g2000cws.googlegroups.com> Leanne wrote: > I have been using Python for only a few months part-time and have > recently had my first encounter with retrieving user input from > checkboxes. I have a problem with the way Python reads the input > values from a set of checkboxes on a webpage. > > The values assigned to the checkboxes are integers. I first of all > check for a key of CHK_CHILDREN to see if any checkboxes have been > checked. That works fine. > > I then use a 'for x in CHK_CHILDREN' loop to get all the values from > the returned list. This works for most cases except one. If the user > only checks 1 checkbox, Python reads a scalar, not a list, and if this > scalar is a double digit integer (eg 11), then the loop goes through > each digit and retrieves these values, eg retrieves 1 and then > retrieves 1 again. > You evidently mean that the scalar you are getting is e.g. "11" and your loop is returning "1" then "1" again. So there are two possibilities: a string (either str or unicode) or a list (or some other sequence). I'd try this: if isinstance(returned_value, basestring): returned_value = [returned_value] for item in returned_value: do_something_with(item) HTH, John From liuwensui at gmail.com Sat Dec 30 22:44:58 2006 From: liuwensui at gmail.com (Wensui Liu) Date: Sat, 30 Dec 2006 22:44:58 -0500 Subject: Wow, Python much faster than MatLab In-Reply-To: <1167534599.274429.58550@i12g2000cwa.googlegroups.com> References: <5bdf5$45969f9c$d443bb3a$14067@news.speedlinq.nl> <1167534599.274429.58550@i12g2000cwa.googlegroups.com> Message-ID: <1115a2b00612301944h64c107dfg7062f84f885febc0@mail.gmail.com> Sturla, I am working in the healthcare and seeing people loves to use excel / spss as database or statistical tool without know what he/she is doing. However, that is not the fault of excel/spss itself but of people who is using it. Things, even include SAS/R, would look stupid, when it has been misused. In the hospitals, people don't pray God. They pray MD. :-) On 30 Dec 2006 19:09:59 -0800, sturlamolden wrote: > > Stef Mientki wrote: > > > I always thought that SPSS or SAS where th? standards. > > Stef > > As far as SPSS is a standard, it is in the field of "religious use of > statistical procedures I don't understand (as I'm a math retard), but > hey p<0.05 is always significant (and any other value is proof of the > opposite ... I think)." > > SPSS is often used by scientists that don't understand maths at all, > often within the fields of social sciences, but regrettably also within > biology and medicine. I know of few program that have done so much harm > as SPSS. It's like handing an armed weapon to a child. Generally one > should stay away from the things that one don't understand, > particularly within medicine where a wrong result can have dramatic > consequences. SPSS encourages the opposite. Copy and paste from Excel > to SPSS is regrettably becoming the de-facto standard in applied > statistics. The problem is not the quality of Excel or SPSS, but rather > the (in)competence of those conducting the data analysis. This can and > does regrettably lead to serious misinterpretation of the data, in > either direction. When a paper is submitted, these errors are usually > not caught in the peer review process, as peer review is, well, exactly > what is says: *peer* review. > > Thus, SPSS makes it easy to shoot your self in the foot. In my > experience students in social sciences and medicine are currently > thought to do exact that, in universities and colleges all around the > World. And it is particularly dangerous within medical sciences, as > peoples' life and health may be affected by it. I pray God something is > done to prohibit or limit the use of these statistical toys. > > > Sturla Molden > PhD > > -- > http://mail.python.org/mailman/listinfo/python-list > -- WenSui Liu A lousy statistician who happens to know a little programming (http://spaces.msn.com/statcompute/blog) From een-niet-bestaande-kleineaap at xs4all.nl Wed Dec 6 05:56:09 2006 From: een-niet-bestaande-kleineaap at xs4all.nl (Kleine Aap) Date: Wed, 06 Dec 2006 11:56:09 +0100 Subject: py2exe / Tkinter problem References: <1165336205.947540.235890@80g2000cwy.googlegroups.com> Message-ID: <4576a221$0$10161$e4fe514c@dreader30.news.xs4all.nl> maryannj at gmail.com wrote: > I've got a python GUI working with Tkinter, and I need to package it as > an executable file, preferably a single file. Why not use an installer to bundle the python interpreter (with TKinter) and your code in a single executable file? If you don't want to distribute source code then .pyc or .pyo files can be used? An example of (freeware) installer software: http://www.jrsoftware.org/isinfo.php From sonibergraj at youjoy.org Wed Dec 6 22:30:06 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Thu, 07 Dec 2006 04:30:06 +0100 Subject: Need Help Parsing From File In-Reply-To: References: Message-ID: <45778ABE.9070804@youjoy.org> John Frame wrote: > How would I read this data from the file into a two dimensional array in > Python? Like: [x.split() for x in open('myfile.txt')] Or if you need integers: [[int(a) for a in x.split()] for x in open('myfile.txt')] ;) -- Soni Bergraj http://www.YouJoy.org/ From python at hope.cz Mon Dec 18 07:47:14 2006 From: python at hope.cz (Lad) Date: 18 Dec 2006 04:47:14 -0800 Subject: How to replace a comma Message-ID: <1166446034.406136.225770@80g2000cwy.googlegroups.com> In a text I need to add a blank(space) after a comma but only if there was no blank(space) after the comman If there was a blank(space), no change is made. I think it could be a task for regular expression but can not figure out the correct regular expression. Can anyone help, please? Thank you L. From __peter__ at web.de Fri Dec 15 07:02:03 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 Dec 2006 13:02:03 +0100 Subject: Property error References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> <1166179622.872556.312810@n67g2000cwd.googlegroups.com> <1166181267.949316.197360@16g2000cwy.googlegroups.com> Message-ID: Peter Otten wrote: > @decorator > def f(): > #?... > > is the same as > > def f(): > #?... > f = decorator(f()) > > What happens when your age() function is invoked? There is no explicit > return statement, so None is implicitly returned, and > > age = property(age()) > > is the same as age = property(None) As Georg pointed out, this is all wrong. As age is not called the age function becomes the getter. Peter From pavlovevidence at gmail.com Sun Dec 17 13:14:07 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 17 Dec 2006 10:14:07 -0800 Subject: Wrapping classes with pure virtual functions In-Reply-To: <1166374199.521017.103220@f1g2000cwa.googlegroups.com> References: <1166133429.969921.131400@80g2000cwy.googlegroups.com> <1166374199.521017.103220@f1g2000cwa.googlegroups.com> Message-ID: <1166379247.531004.140770@16g2000cwy.googlegroups.com> gabriel.becedillas at gmail.com wrote: > Chris Lambacher wrote: > > On Thu, Dec 14, 2006 at 01:57:10PM -0800, gabriel.becedillas at gmail.com wrote: > > > Hi, > > > I'm having problems wrapping a hierarchy of classes, actually having > > > problems wrapping the base class. I don't need to use the WrapClass > > > mechanism since I don't want to override classes in Python. My code > > > boils down to: > > > > > > class Base > > > { > > > public: > > > virtual ~Base() > > > {} > > > > > > virtual void f() = 0; > > > }; > > > > > > class Derived : > > > public Base > > > { > > > public: > > > virtual void f() > > > {} > > > > > > void g() > > > {} > > > }; > > > > > > int main() > > > { > > > boost::python::class_ class_base("Base"); > > Why are you trying to make this type visible to python? It is pure virtual, > > you can never instantiate it. > > Because I want to use subclasses of Base polymorphically from Python. > Python will receive an instance of some Base subclass through a another > exported function. I don't know much about Boost. Does it have anything like boost::python::pointer_? You can't get polymorphism by direct access to a class. C++ compiler always knows the exact type of a direct, non-pointer-accessed object. So even if you could create a class_, it would only ever be a Base, and never a derived class. You have to use pointers to get polymorphism. As an alternative, consider wrapping the derived classes instead. It might not be much more work if Boost wraps everything nicely. Carl Banks From bdesth.quelquechose at free.quelquepart.fr Thu Dec 14 09:20:10 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 14 Dec 2006 15:20:10 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <457f1a42$0$8414$426a74cc@news.free.fr> Message-ID: <458157fd$0$2119$426a34cc@news.free.fr> Andr? Thieme a ?crit : > Bruno Desthuilliers schrieb: > (snip) >> Both are highly dynamic. Neither are declarative. > > > Well, Lisp does support some declarative features in the ansi standard. If you go that way, there are declarative stuff in Python too... But neither Lisp nor Python are close to, say, SQL. From george.sakkis at gmail.com Sat Dec 2 13:52:21 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 2 Dec 2006 10:52:21 -0800 Subject: global name 'self' is not defined References: <1165084948.125632.121260@79g2000cws.googlegroups.com> Message-ID: <1165085541.624528.150990@79g2000cws.googlegroups.com> Evan wrote: > Hi > > I have a short script that makes 2 calls to methods in another script > as follows: > > import canPlaces as canp > > callOne=canp.addMe(3,5) > callTwo=canp.estocStn() > > The 2 methods in the second script are: > > def addMe(a,b) > sumAb=a+b > return sumAb > > def estocStn(): > estoc={'lat':29.15,'lon':-15.667,'place':'ESTOC'} > return estoc > > Why is it that the first call works fine, but the second tells me > 'global name 'self' is not defined'? What I want is to have the > dictionary 'estoc' available in my calling script. > > Thanks, Evan Please post examples that reproduce the error; what you posted doesn't even refer to "self" at all. George From larry.bates at websafe.com Thu Dec 21 14:42:46 2006 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 21 Dec 2006 13:42:46 -0600 Subject: query In-Reply-To: <1166728656.830042.147690@79g2000cws.googlegroups.com> References: <1166728656.830042.147690@79g2000cws.googlegroups.com> Message-ID: libintr at gmail.com wrote: > can anyone help me on indentation in python and tell me some nice text > editors used for a beginner in python? > You MUST tell us what platform you run on for us to make a recommendation. Remember Python runs on Windows, Linux, Mac, ... On Windows my current favorite is PyScripter available at: http://mmm-experts.com/Products.aspx?ProductId=4 Another good choice is Eclipse with Python plug-in but it is a very large application. If you do Java and other development as well as Python that might be an excellent choice. -Larry From kentilton at gmail.com Sat Dec 9 04:26:02 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 04:26:02 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Message-ID: Steven D'Aprano wrote: > It is a good thing that not every > hare-brained idea that some random programmer comes up with can be > implemented as part of the core language. Well, that's the FUD/strawman, but nothing more. Just a hobgoblin to keep the Pythonistas from straying. But you have an excuse: Lispniks always /talk/ about macros giving us the ability to create a DSL. But no one does. :) Macros mostly hide implementation -- always a good thing -- where functions cannot. This, btw, is why Norvig brushing off macros with the ability to use regex to parse a DSL was so disappointing. I guess your other excuse is that your BDFL says the same thing. All in all, this is getting pretty funny. I am starting to picture you all (including GvR) running around with your hands over your ears going woo-woo so you cannot hear what we are saying. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From grante at visi.com Wed Dec 6 17:36:58 2006 From: grante at visi.com (Grant Edwards) Date: Wed, 06 Dec 2006 22:36:58 -0000 Subject: Windows installer for Scientific Python for Python 2.4? Message-ID: <12nehgaak7mte4@corp.supernews.com> Can anybody point me to a windows installer for scientific python that will work with Python 2.4? The Scientific python download page only has an installer for Python 2.3. -- Grant Edwards grante Yow! Yow! I like my new at DENTIST... visi.com From riklaunim at gmail.com Mon Dec 4 13:19:05 2006 From: riklaunim at gmail.com (riklaunim at gmail.com) Date: 4 Dec 2006 10:19:05 -0800 Subject: Python bindings for RCS apps Message-ID: <1165256344.935217.229680@j72g2000cwa.googlegroups.com> There is pySVN for subversion but does other revision control system systems have some good python bindings/apis ? with good docs and some examples. From gigs at hi.t-com.hr Fri Dec 15 07:00:30 2006 From: gigs at hi.t-com.hr (Gigs_) Date: Fri, 15 Dec 2006 13:00:30 +0100 Subject: beginner, thread & else In-Reply-To: References: Message-ID: Fredrik Lundh wrote: > did you write that yourself, or did you find it in some book or article? This is the example from programming python 2nd book, I use this just for learning From eldorado at io.com Wed Dec 27 12:48:11 2006 From: eldorado at io.com (eldorado) Date: Wed, 27 Dec 2006 11:48:11 -0600 Subject: getting a process's PID In-Reply-To: <4592abf1$1@nntp.zianet.com> References: <20061227102939.L20663@eris.io.com> <4592abf1$1@nntp.zianet.com> Message-ID: <20061227113158.J21223@eris.io.com> On Wed, 27 Dec 2006, Erik Johnson wrote: > "eldorado" wrote in message > news:20061227102939.L20663 at eris.io.com... >> Hello, >> >> I am trying to get python to give me the PID of a process (in this case >> HUB). I have it working, except for the fact that the output includes >> \012 (newline). Is there a way to ask python not to give me a newline? >> >> Python 1.4 (Oct 14 1997) [C] >> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>>> import os >>>>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") >>>>> h = g.readlines() >>>>> g.close() >>>>> h >> ['87334\012'] > > > There's more than one way to do it! (Oh, sorry, that's Perl...) > > The two most standard ways would be to call strip() on your string to get > one sans both leading and trialing whitespace > > print h.strip() > > or if you know exactly what you've got (i.e., the newline you don't want is > just the last character), you can just get rid of it: > > h = h[:-1] > Thanks for the help, however it doesnt look like those two solutions quite work: >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") >>> h = g.readlines() >>> g.close() >>> h ['87334\012'] >>> h = h[:-1] >>> h [] >>> >>> import string >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") >>> h = g.readlines() >>> g.close() >>> print h.strip() File "", line 1 print h.strip() ^ SyntaxError: invalid syntax I looked up the syntax for print and it looks correct (at least to me ;) -- Randomly generated signature You can go anywhere you want if you look serious and carry a clipboard. From pgarrone at acay.com.au Tue Dec 19 06:03:04 2006 From: pgarrone at acay.com.au (pgarrone at acay.com.au) Date: 19 Dec 2006 03:03:04 -0800 Subject: Adding an instance to a data tree In-Reply-To: <1166520893.870234.283220@79g2000cws.googlegroups.com> References: <1166520893.870234.283220@79g2000cws.googlegroups.com> Message-ID: <1166526184.157551.118230@a3g2000cwd.googlegroups.com> And of course the solution occurs to me about 30 minutes after posting, to have the add method return an instance which then invokes setup. self.add(name, child_type, other_info).setup(child-setup-parameters) From kibleur.christophe at gmail.com Thu Dec 14 16:53:05 2006 From: kibleur.christophe at gmail.com (Tool69) Date: 14 Dec 2006 13:53:05 -0800 Subject: need clarification with import statements Message-ID: <1166133185.363843.120090@80g2000cwy.googlegroups.com> Hi, I've got the following hierarchy: mainprog/ __init__.py prog.py utils/ __init__.py myutils.py others/ __init__.py myothers.py Inside prog.py I need to have full access to myutils.py and myothers.py; Inside myutils.py, I need to access two classes from myothers.py (ie myotherClass1 and myotherClass2); Inside myothers.py, I need some functions of myutils.py (ie myutils_func1 and myutils_func2); Do you have some hints please ? I'm trying to avoid name conflicts, so I haven't used "from ... import *". I suspect ther's something wrong, but I think I really don't understand what's going on internally (no errors (for the moment !)) Inside prog.py : from utils.myutils import myotherClass1, myotherClass2 + some functions of myutils I need Inside myutils.py : from other.myothers import myotherClass1, myotherClass2 Inside others.py : import utils.myutils Thanks. From Amateur.N7TZG at gmail.com Fri Dec 15 23:40:05 2006 From: Amateur.N7TZG at gmail.com (Rob) Date: 15 Dec 2006 20:40:05 -0800 Subject: Serial port failure In-Reply-To: <1166225659.526259.199890@73g2000cwn.googlegroups.com> References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> <1166225659.526259.199890@73g2000cwn.googlegroups.com> Message-ID: <1166244005.621249.155820@79g2000cws.googlegroups.com> Leo, I like your tuple idea. I will implement it. The ack and nak both have the same format, namely: "Id Ack" or "Id Nak" rob On Dec 15, 4:34 pm, "Leo Kislov" wrote: > Rob wrote: > > Hi all, > > > I am fairly new to python, but not programming and embedded. I am > > having an issue which I believe is related to the hardware, triggered > > by the software read I am doing in pySerial. I am sending a short > > message to a group of embedded boxes daisy chained via the serial port. > > When I send a 'global' message, all the connected units should reply > > with their Id and Ack in this format '0 Ack' To be certain that I > > didn't miss a packet, and hence a unit, I do the procedure three times, > > sending the message and waiting for a timeout before I run through the > > next iteration. Frequently I get through the first two iterations > > without a problem, but the third hangs up and crashes, requiring me to > > remove the Belkin USB to serial adapter, and then reconnect it. Here > > is the code: > > > import sys, os > > import serial > > import sret > > import time > > > from serial.serialutil import SerialException > > #################################################################### > > #### GetAck Procedure > > #################################################################### > > def GetAck(p): > > response = "" > > > try: > > response = p.readline() > > except SerialException: > > print ">>>>>Timed out<<<<<" > > return -1 > > res = response.split() > > > #look for ack in the return message > > reslen = len(response) > > if reslen > 5: > > if res[1] == 'Ack': > > return res[0] > > elif res[1] == 'Nak': > > return 0x7F > > else: > > return -1 > > > >>>>> Snip <<<<<< > > #################################################################### > > #### GetNumLanes Procedure > > #################################################################### > > def GetNumLanes(Lanes): > > print "Looking for connected units" > > # give a turn command and wait for responses > > msg = ".g t 0 336\n" > > > for i in range(3): > > port = OpenPort() > > time.sleep(3) > > print port.isOpen() > > print "Request #%d" % (i+1) > > try: > > port.writelines(msg) > > except OSError: > > print "Serial port failure. Power cycle units" > > port.close() > > sys.exit(1) > > > done = False > > # Run first connection check > > #Loop through getting responses until we get a -1 from GetAck > > while done == False: > > # lane will either be -1 (timeout), 0x7F (Nak), > > # or the lane number that responded with an Ack > > lane = GetAck(port) > > if lane >= '0':Your GetAck returns either string or number and then you compare it > with a string. If you compare string with a number python currently > returns result you probably don't expect > > >>> -1 >= '0' > False > >>> 0x7f >= '0'False > > This is a wart and it will be fixed in python 3.0 (it will raise > exception) I think you should rewrite GetAck to return a tuple (state, > lane) > > def GetAck(p): > response = "" > > try: > response = p.readline() > except SerialException: > print ">>>>>Timed out<<<<<" > return 'Timeout', 'NoID' > res = response.split() > > #look for ack in the return message > reslen = len(response) > if reslen > 5: > if res[1] == 'Ack': > return 'Ack', res[0] > elif res[1] == 'Nak': > return 'Nak', Does Nak response contain lane id? > else: > return 'Unknown', 'NoID' > > And then instead of > > lane = GetAck(port) > if lane >= '0': > > use > > state, lane = GetAck(port) > if state == 'Ack': > > -- Leo From jamesthiele.usenet at gmail.com Sun Dec 31 14:13:03 2006 From: jamesthiele.usenet at gmail.com (James Thiele) Date: 31 Dec 2006 11:13:03 -0800 Subject: looking for a better way to call a file. References: <1167541855.474814.53370@v33g2000cwv.googlegroups.com> Message-ID: <1167592383.820352.54340@48g2000cwx.googlegroups.com> This probably will meet your needs: import os os.system("csound play.orc play.sco") If you need more control try the subprocess module. Eric_Dexter at msn.com wrote: > I have been auto-generating .bat files and then running > os.startfile('whatever.bat'). I don't > seem to be having much luck when I try other methods. All of a sudden > I am stuck in a > situation where I need the program that is calling to end and a new > program to start (because otherwise I get several uneeded copies). > > csoundgrid4.csgrid(arrg1, """;""", filename) > > with this by executing the main function > > os3.execvp('python', 'csoundgrid4.py', arrg1, """;""", > filename) > > and the program just ends. I would also be glad to get rid of all the > bats that I generate when I > run an external program like csound. The command line I run is > somthing like > > csound play.orc play.sco > > I haven't had much luck using os.startfile with arguments > > Hopefully this is an easy question and any help would be apreaceated > (befour my computer gets rabies) > > http://www.dexrow.com From mail at microcorp.co.za Thu Dec 7 02:35:28 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 7 Dec 2006 09:35:28 +0200 Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net> <17783.32458.730462.8403@montanaro.dyndns.org> Message-ID: <024f01c719d3$deff0fc0$03000080@hendrik> wrote: > Peter> Bjoern Schliessmann wrote: > >> Wouldn't be "if k in d.keys()" be the exact replacement? > > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less > Peter> (constant) overhead for the function call. 'k in d.keys()' on the > Peter> other hand creates a list of keys which is then searched linearly > Peter> -- about the worst thing you can do about both speed and memory > Peter> footprint. > > I will admit that way back when (maybe 8 yrs ago) I actually did this in a > piece of frequently executed code that's been stable for a looong time. I > have no idea why I might have written it that way. Brain fart I suppose. I > only noticed my mistake a couple months ago during a trip into the > containing function for some other stuff. Man, was I embarrassed... why? - the main point is actually that the code worked, and was stable - that should make you proud, not embarrassed. I think that there is far too much emphasis on doing things the quickest way - as long as it works, and is fast enough, its not broken, so don't fix it... - Hendrik From tundra at tundraware.com Tue Dec 19 17:02:46 2006 From: tundra at tundraware.com (Tim Daneliuk) Date: Tue, 19 Dec 2006 16:02:46 -0600 Subject: [ANN]: 'twander' 3.210 Released And Available Message-ID: (Apologies for two releases in less than a week. It was, um... necessary. This should be it for quite a while barring any notable bug reports.) 'twander' Version 3.210 is now released and available for download at: http://www.tundraware.com/Software/twander The last public release was 3.204. If you are unfamiliar with this pure-Python program, see the end of this message for a brief description or see the website above. --------------------------------------------------------------------- NEW FEATURES - Implemented Association exclusions. You can now exclude the named file types from being associated with an application: ASSOC ! *.txt *.ps *.pdf This is handy if you want to use a default association for most things, but have a select group of files not be affected by the default and thereby passed down to the OS for normal processing. - Any association (normal, default, exclusion) can be removed by leaving the right-hand-side blank: ASSOC *.foo ASSOC * ASSOC ! This is useful within conditional blocks when you want to define 'twander' behavior differently based on some condition you're checking. Another use is to undefine an Association that was put in place in a global configuration you .included into your setup. CHANGES - All association checks are now case-insensitive under Windows. - Association "types" now support filename "globbing" meta- characters. This means that association statements supported in the previous release need to be changed slightly. This: ASSOC .txt ... Need to be changed to this: ASSOC *.txt .... This feature enables far more complete filename type specification than was previously possible with just the "filename ends with .." semantic. - If a file is selected and the user double-clicks or hits "Enter", and that file is not executable AND has no applicable association defined, 'twander' will present an error message. It does this only on the Unix-like systems. On Windows, the request is handed down to the underlying OS without comment because Windows itself may have an applicable association. DOCUMENTATION - The manual has been updated and corrected in several places. - Documentation for the new features has been added. ------------------------------------------------------------------------ Complete details of all fixes, changes, and new features can be found in the WHATSNEW.txt and documentation files included in the distribution. Users are strongly encouraged to join the twander-users mailing list as described in the documentation. A FreeBSD port has been submitted as well. What Is 'twander'? ------------------ 'twander' is a macro-programmable Filesystem Browser that runs on both Unix-like systems as well as Win32 systems. It embraces the best ideas of both similar GUI-driven programs (Konqueror, Windows Explorer) as well as text-based interfaces (Midnight Commander, List, Sweep). Or, If You Prefer The "Elevator Pitch" -------------------------------------- 'twander' is: - A better file browser for Unix and Win32. (Tested on FreeBSD, Linux, Win32. Probably works on Mac OS/X, but not tested.) - A way to make browsing the same on all the OSs you use. - A macro-programmable tool that lets *you* define the features. - A GUI navigation front-end for your shell. - A way to "can" workflows for your technically-challenged colleagues. - A way to free yourself from the shackles of the mouse. - A way to significantly speed up your day-to-day workflow. - A Python/Tkinter application - about 5000 lines of code/comments - A RCT (Really Cool Tool) that will have you addicted in a day or two See the web page for more information, a screen shot, and the complete documentation. twander at tundraware.com From rampeters at gmail.com Tue Dec 5 09:26:13 2006 From: rampeters at gmail.com (johnny) Date: 5 Dec 2006 06:26:13 -0800 Subject: Multiple FTP download using Muliti thread In-Reply-To: <1165328384.929172.16750@j44g2000cwa.googlegroups.com> References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> <1165277324.677203.107650@l12g2000cwl.googlegroups.com> <1165284311.911998.151460@l12g2000cwl.googlegroups.com> <1165328384.929172.16750@j44g2000cwa.googlegroups.com> Message-ID: <1165328772.865339.212000@n67g2000cwd.googlegroups.com> It places the ftp downloaded contents on the same folder as the this ftp python script. How do I set a diffrent download folder location? johnny wrote: > It works using ftp.microsoft.com. But where does it put the downloaded > files? can I specify a download folder location? > > Justin Ezequiel wrote: > > johnny wrote: > > > When I run the following script, with host and password and username > > > changed, I get the following errors: > > > raise error_temp, resp > > > error_temp: 421 Unable to set up secure anonymous FTP > > > > > > Dose the host should allow 4 simultaneous login at a time? > > > > > > > does it work using ftp.microsoft.com? > > > > post your code From rthorpe at realworldtech.com Wed Dec 13 13:56:59 2006 From: rthorpe at realworldtech.com (Rob Thorpe) Date: 13 Dec 2006 10:56:59 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> Message-ID: <1166036218.993990.320740@f1g2000cwa.googlegroups.com> Robert Uhl wrote: > Christophe writes: > > Robert Uhl a ?crit : > > > >> The argument from popularity is invalid. French units have overtaken > >> standard units, > > > > Never heard of that French unit thing. Unless you talk about that > > archaic unit system that was in use before the metric system was > > created. > > I use 'French units' instead of the term 'metric system' because the > latter means 'measurement system,' and of course could validly be > applied to _any_ system. A good term to use, if your audience is likely to understand it, is "SI units". The current units used in science and for most measurements are "Systeme International d'unites" Units. The original metric system is not really used anymore, SI is slightly different. From huayang.xia at gmail.com Mon Dec 18 15:22:13 2006 From: huayang.xia at gmail.com (Huayang Xia) Date: 18 Dec 2006 12:22:13 -0800 Subject: When Closure get external variable's value? Message-ID: <1166473333.593246.238580@73g2000cwn.googlegroups.com> What will the following piece of code print? (10 or 15) def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest() print testClosure(10) My question is when the closure function gets value for maxindex? Run time or compile time? Thanks. From python at hope.cz Wed Dec 13 07:56:53 2006 From: python at hope.cz (Lad) Date: 13 Dec 2006 04:56:53 -0800 Subject: YouTube written in Python In-Reply-To: <1166008066.618948.28200@79g2000cws.googlegroups.com> References: <457f58e5$0$27424$4d3efbfe@news.sover.net> <1166008066.618948.28200@79g2000cws.googlegroups.com> Message-ID: <1166014613.707945.189130@j44g2000cwa.googlegroups.com> Speaking of YouTube, does anyone know how they uploads big files( 100MB) I need to solve that problem ( in Python of course) and YouTube is a good sample of that. Lad. From bcannon at gmail.com Wed Dec 20 13:26:46 2006 From: bcannon at gmail.com (bcannon at gmail.com) Date: 20 Dec 2006 10:26:46 -0800 Subject: new Python-Ideas mailing list Message-ID: At Guido's suggestion, a new mailing list has been created named Python-Ideas (http://mail.python.org/mailman/listinfo/python-ideas). This list is meant as a place for speculative, pie-in-the-sky language design ideas to be discussed and honed to the point of practically being a PEP before being presented to python-dev or python-3000. This allows both python-dev and python-3000 to focus more on implementation work or final approval/denial of ideas instead of being flooded with long threads where people discuss ideas that are too nebulous to be considered for inclusion into Python. Like python-dev and python-3000, Python-Ideas requires you subscribe before you can post, but there is no moderator approval required to subscribe. If you are interested in helping me out by being an administrator or moderator for the list, please let me know. -Brett From richard at nospam.com Sat Dec 23 10:07:19 2006 From: richard at nospam.com (Richard Townsend) Date: Sat, 23 Dec 2006 15:07:19 +0000 Subject: [ANN] pyparsing 1.4.5 released References: <1166846392.920361.196990@73g2000cwn.googlegroups.com> Message-ID: <9ehrgmg8ye62$.157mjsdys1jgm.dlg@40tude.net> On 22 Dec 2006 19:59:53 -0800, Paul McGuire wrote: > > Download pyparsing 1.4.5 at http://pyparsing.sourceforge.net. The > pyparsing Wiki is at http://pyparsing.wikispaces.com > When I click on the sourceforge link above, I get redirected to the wiki. However, http://sourceforge.net/projects/pyparsing/ seems to work. -- Richard From rthorpe at realworldtech.com Fri Dec 8 12:24:26 2006 From: rthorpe at realworldtech.com (Rob Thorpe) Date: 8 Dec 2006 09:24:26 -0800 Subject: merits of Lisp vs Python In-Reply-To: <45799841$0$49201$14726298@news.sunsite.dk> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> <1165593798.079105.144060@80g2000cwy.googlegroups.com> <45799841$0$49201$14726298@news.sunsite.dk> Message-ID: <1165598665.981048.147330@80g2000cwy.googlegroups.com> Alex Mizrahi wrote: > (message (Hello 'Kay) > (you :wrote :on '(8 Dec 2006 08:03:18 -0800)) > ( > > KS> http://www.sbcl.org/manual/Handling-of-Types.html#Handling-of-Types > > KS> If you'd read the docs of the tools you admire you might find the > KS> answers yourself. > > SBCL is a COMPILER that explains everything. it's interesting why > INTERPRETER like CLISP is faster. > well, it can be type declarations as well, but maybe something other too.. I agree with your other points. Python allows the programmer to override absolutely anything, including things like addition. This entails extra work. It's also worth mentioning that Clisp is an hugely optimized interpreter. A much work has been put in to making it's bytecode interpreting inner loops as fast as possible. From python at hope.cz Wed Dec 13 07:59:07 2006 From: python at hope.cz (Lad) Date: 13 Dec 2006 04:59:07 -0800 Subject: Large files uploading In-Reply-To: References: <1165949410.458162.38300@79g2000cws.googlegroups.com> Message-ID: <1166014746.923171.38110@f1g2000cwa.googlegroups.com> > to use any communications protocol (including HTTP), both ends must have > programs that can talk that protocol... > Sure, but browsers have FTP support. But how to call the FTP API from Python? Lad. From nmm1 at cus.cam.ac.uk Thu Dec 14 10:52:05 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 14 Dec 2006 15:52:05 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: In article , "Fredrik Lundh" writes: |> Nick Maclaren wrote: |> |> > If lists are intended to be homogeneous, then they should be checked |> > for that, and an exception raised when an attempt is to make them |> > non-homogeneous. |> |> so how would that check work, given that Python's type model is based on |> duck typing |> |> http://en.wikipedia.org/wiki/Duck_typing See my response to Georg Brandl (specifically the memo. to myself). Regards, Nick Maclaren. From sjmachin at lexicon.net Sat Dec 2 20:00:15 2006 From: sjmachin at lexicon.net (John Machin) Date: 2 Dec 2006 17:00:15 -0800 Subject: converting dict to object In-Reply-To: References: <7649225.post@talk.nabble.com> <1165090584.103366.198220@l12g2000cwl.googlegroups.com> Message-ID: <1165107615.027458.199840@80g2000cwy.googlegroups.com> Steven D'Aprano wrote: > On Sat, 02 Dec 2006 12:16:24 -0800, John Machin wrote: > > > The OP might consider adding code to the __init__ method to check for > > cases where the dictionary key is not a string containing a valid > > Python identifier (not a keyword). > [snip] > But if he's doing something like this: > > attributes = fetch_user_dict() > # attribute names aren't known until runtime > obj.__dict__.update(attributes) > for key in attributes: > print getattr(obj, key) > > then it is also redundant to check for valid identifiers, since getattr() > doesn't need them. but getattr() needs strings. From pyenos at pyenos.org Wed Dec 27 19:28:38 2006 From: pyenos at pyenos.org (Pyenos) Date: 28 Dec 2006 11:28:38 +1100 Subject: can't instantiate following inner class Message-ID: <87mz586eyx.fsf@pyenos.pyenos.org> class One: Two() #can't instantiate class Two: Three() #can't instantiate class Three:pass From gagsl-py at yahoo.com.ar Wed Dec 27 00:27:49 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 27 Dec 2006 02:27:49 -0300 Subject: module with a threading-like api that uses processes? In-Reply-To: <17809.64900.778410.770633@montanaro.dyndns.org> References: <17809.64900.778410.770633@montanaro.dyndns.org> Message-ID: <7.0.1.0.0.20061227022539.04025ab0@yahoo.com.ar> At Wednesday 27/12/2006 01:58, skip at pobox.com wrote: >I could have sworn someone was working on a module recently with a >threading-like API that used subprocesses under the covers, but 10 minutes >or so of googling didn't yield anything. Pointers appreciated. Perhaps this project? I just wrote rthread library that makes distributed computing look like writing multi-threaded programs. The only thing required from remote hosts is ssh server and executable rthread_server (included in the package) in PATH. (The library executes "ssh -C -c blowfish remotehost 'rthread_server'", and uses stdin and stdout of that process as a communication channel.) There is no need for interface definitions, no need to open communication ports, no need to copy remotely run function code to remote hosts. http://www.cs.tut.fi/~ask/rthread/index.html -- 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 From fredrik at pythonware.com Mon Dec 4 13:10:41 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 19:10:41 +0100 Subject: decorators question In-Reply-To: <1165254977.903936.83180@16g2000cwy.googlegroups.com> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> Message-ID: king kikapu wrote: > It will load all the module, all the functions and when it sees that > some function(s) are decorating, then it will start execute respectives > decorators ? @decorator def func(): pass is *exactly* the same thing as: def func(): pass func = decorator(func) > And this will do it for all decorated functions ?? Even if we do not > have any references to these functions ? Python calls the decorator, not the decorated function. additional reading: http://www.python.org/doc/2.4.4/whatsnew/node6.html http://www.python.org/dev/peps/pep-0318 and the relevant chapters in the tutorial and the language reference. From martin at v.loewis.de Mon Dec 11 04:35:14 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 11 Dec 2006 10:35:14 +0100 Subject: sys.stdin.encoding In-Reply-To: <1165825571.435369.150110@79g2000cws.googlegroups.com> References: <1165825571.435369.150110@79g2000cws.googlegroups.com> Message-ID: <457D2652.7080200@v.loewis.de> aine_canby at yahoo.com schrieb: > The following line in my code is failing because sys.stdin.encoding is > Null. This has only started happening since I started working with > Pydef in Eclipse SDK. Any ideas? > > uni=unicode(word,sys.stdin.encoding) That's a problem with pydev, where the standard machinery to determine the terminal's encoding fail. I have no idea yet how to fix this. Regards, Martin From rdiaz02 at gmail.com Sun Dec 10 08:24:33 2006 From: rdiaz02 at gmail.com (Ramon Diaz-Uriarte) Date: Sun, 10 Dec 2006 14:24:33 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7xfybpb9pe.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <7xfybpb9pe.fsf@ruckus.brouhaha.com> Message-ID: <624934630612100524x68e91de3yece3e66c4e31cfc4@mail.gmail.com> On 09 Dec 2006 03:16:45 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Ramon Diaz-Uriarte" writes: > > a) "old-fashioned"? Is that supposed to be an argument? I guess > > addition and multiplication are old-fashioned, and so is calculus;so? > > I think "old-fashioned" should only carry a negative connotation in > > the fashion world, not in programming. > > If someone handed you a calculus book written in Latin, you'd probably > find it undesirably old-fashioned too. > I think the "reasoning by analogy" is clearly showing its weakness here (truth is, it was me who used the analogy to begin with). However since (and this is no cynicism) I do really respect and find thought provoking most of what you write, how is Lisp similar to a calculus book written in Latin (or to the Latin in the calculus book, or whatever)? What exactly is "old-fashioned" supposed to mean here, and how does it carry a truly negative connotation? R. P.D. I am only now starting with Lisp, after having written a lot of Python for the last two years. -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From sjmachin at lexicon.net Sun Dec 10 00:30:32 2006 From: sjmachin at lexicon.net (John Machin) Date: 9 Dec 2006 21:30:32 -0800 Subject: ooopy: newbie cannot get basic functionality to work In-Reply-To: References: Message-ID: <1165728632.133298.117130@73g2000cwn.googlegroups.com> Andrew Sackville-West wrote: > Hi list, > > I am new to python and old to coding (as in I did it a long time > ago). I've got a task that cries out for a scripted solution -- > importing chunks of ASCII data dumps from a point-of-sale system into > an openoffice.org spreadsheet. What a great chance for me to get my > coding skills back and learn python too! > > I have attempted to get ooopy to work for me and have run into > problems at the first step. Google returns not much on ooopy and the > common example, from help (OOoPy) is: > > | from OOoPy import OOoPy > | >>> o = OOoPy (infile = 'test.sxw', outfile = 'out.sxw') > | >>> e = o.read ('content.xml') > | >>> e.write () > | >>> o.close () > > okay here goes: > > >>> from OOoPy import OOoPy > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named OOoPy > > hmm... okay how about: > > >>> from ooopy import OOoPy > >>> dir (OOoPy) > ['ElementTree', 'OOoElementTree', 'OOoPy', 'StringIO', 'VERSION', > 'ZIP_DEFLATED', 'ZipFile', '__builtins__', '__doc__', '__file__', > '__name__', '_autosuper', 'autosuper', 'fromstring', 'mkstemp', 'os'] > > okay that works. now: > > >>> o = OOoPy (infile='/home/andrew/monthly.ods') > Traceback (most recent call last): > File "", line 1, in ? > TypeError: 'module' object is not callable > >>> OK, so that tells you that ooopy.OOoPy is a *module*, and it contains *another* gizmoid named OOoPy. [snip] > >>> sys.modules [snip] > 'ooopy.OOoPy': '/usr/lib/python2.4/ooopy/OOoPy.py'>, Uh-huh. Confirmation that ooopy.OOoPy is a module. Try: from ooopy import OOoPy o = OOoPy.OOoPy(infile='/home/andrew/monthly.ods') BTW, is that package being maintained? Did you ask the maintainer? Any response? HTH, John From no-spam at no-spam-no-spam.invalid Tue Dec 26 13:34:30 2006 From: no-spam at no-spam-no-spam.invalid (robert) Date: Tue, 26 Dec 2006 19:34:30 +0100 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> Message-ID: Ben Sizer wrote: > I've installed several different versions of Python across several > different versions of MS Windows, and not a single time was the Python > directory or the Scripts subdirectory added to the PATH environment > variable. Every time, I've had to go through and add this by hand, to > have something resembling a usable Python installation. No such > problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or > Kubuntu. So why is the Windows install half-crippled by default? I just > rediscovered this today when trying to run one of the Turbogears > scripts, but this has puzzled me for years now. > That would put together a great mix-up if app installations add to the PATH. Think of multiple installations etc. ( Note: this is also _NOT_ done on *nix - just a sym link is possibly put into /usr/local/bin or so ) To have something similar on Win I have a C:\bin folder where I put all my small .exe's / installations and all the start vectors (.exe, .bat's....). The python.exe on Win is very small and just loads the pythonXX.dll. It also finds the right default DLL due to the version engraved in python.exe. Thus I just copy the small python.exe from my favorite/default Python installation (2.3) into my C:\bin. Thats probably next to what you obviously want - a "default link". The Test&Fun-Pythons ( ... 2.2 2.4 2.5 2.6 ) - I have them renamed as e.g. python25.exe also in C:\bin . I make similar links on *nix also. Perhaps in the future the Python Windows installer should create such pythonXX.exe "links" and maybe even a default python.exe (upon Checkbox in Installer!) into the Windows\system32 ? Robert From fizziroy at yahoo.com Mon Dec 18 13:31:44 2006 From: fizziroy at yahoo.com (Charles Bishop) Date: Mon, 18 Dec 2006 10:31:44 -0800 (PST) Subject: psp 2 game list Message-ID: <973557.99639.qm@web60711.mail.yahoo.com> could you send me a list of games you have __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From meesters at uni-mainz.de Tue Dec 19 09:14:51 2006 From: meesters at uni-mainz.de (Christian Meesters) Date: Tue, 19 Dec 2006 15:14:51 +0100 Subject: permutations - fast & with low memory consumption? Message-ID: Hi, I'd like to hack a function which returns all possible permutations as lists (or tuples) of two from a given list. So far, I came up with this solution, but it turned out to be too slow for the given problem, because the list passed ("atomlist") can be some 1e5 items long: def permute(atomlist, size = 2): """ returns a list of atoms grouped by two """ if not size or not atomlist: return [atomlist[:0]] else: result = list() for i in xrange(len(atomlist)): pick = atomlist[i:i+1] # sequence slice remainder = atomlist[:i] + atomlist[i+1:] # keep [:i] part for x in __permute(remainder, size = size - 1): result.append(pick + x) return result Does anybody know a solution which consumes less memory and is possibly faster, perhaps using generator expressions? All my attempts so far failed. Any help appreciated! TIA Christian From vo.sinh at gmail.com Fri Dec 15 21:22:28 2006 From: vo.sinh at gmail.com (Michele) Date: Sat, 16 Dec 2006 03:22:28 +0100 Subject: Designing a cancellable function In-Reply-To: <4ugvvfF18hlf1U1@mid.individual.net> References: <4ugvvfF18hlf1U1@mid.individual.net> Message-ID: Hi Leo, what about one (or more) thread(s) which run the eat() method of FilesEater object with inheriths from a superclass what's needed to update the progress attribute (for example a _inc_progress() private method)? (So you can have a UrlEater class and so on, them all knowing how to update their progress) Then you give FilesEater (or maybe a better name) a reference to a config dict at init time. You can have multiple FilesEater with different configurations and you can handle the problem of stopping execution with a stopEating() public method which sets an internal flag (a Lock object) and you check it inside the object runloop with something like: def eat(self): for f in self.files: do_some_stuff() self._eat_for_real() do_some_other_stuff() def _eat_for_real(): # you should use the with statement inside here =) self._eatLock.acquire() do_the_processing _write_the_result() # ! self._eatLock.release() with this you can pause and restart the execution by calling pause/restart methods that acquire and release the eatLock. It writes the result before releasing it so you know it finishes the last chunk when you suspend it. If then you want to abord, just call the pause() on every *Eater object and exit. If you want to exit immediately just exit and design the code that reads the output of the eat() processing in a way that it can recognize broken chunks, delete them and go on (if they are written on-disk obviously). Hope this helps, Michele On 16 Dec 2006 01:20:47 GMT, Leo Breebaart wrote: > I have written a function foo() that iterates over and processes > a large number of files. The function should be available to the > user as library function, via a command-line interface, and > through a GUI. > > So, I added a 'config' object as a parameter to foo() that can be > used by the caller to explicitly pass in user-defined settings. > Because the processing foo() does can take such a long time, the > next thing I did was add an 'update_function' callback parameter > that foo() will call regularly, so that the GUI can update a > progress bar, and the command-line version can print dots, etc. > > I now would also like to add the possibility to allow the user to > *cancel* the execution of foo() during the processing, and I am > wondering what the best / most Pythonic way to design this is. > > One obvious approach seems to me to turn the 'config' object into > something more dynamic, and have foo() regularly inspect it to > see if somebody in the main thread has set e.g. config.abort to > True. > > Another approach would be to turn foo() into a proper (threaded) > class with distinct run() and abort() methods. But the caller > would still need to register the update callback somehow, and I > am wondering if this way the whole API for foo() won't become to > complex and overdesigned. > > I was wondering if anybody has any insights or best practice > recommendations for me here. Do I keep the function interface? Do > I use a class? Any other solution I am overlooking? > > Many thanks in advance for your advice. > > -- > Leo Breebaart > -- > http://mail.python.org/mailman/listinfo/python-list > From sjmachin at lexicon.net Mon Dec 11 06:31:25 2006 From: sjmachin at lexicon.net (John Machin) Date: 11 Dec 2006 03:31:25 -0800 Subject: Avoiding "invalid literal for int()" exception In-Reply-To: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> References: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> Message-ID: <1165836685.023929.197850@f1g2000cwa.googlegroups.com> aine_canby at yahoo.com wrote: > >>> v = raw_input("Enter: ") > Enter: kjjkj > >>> int(v) > Traceback (most recent call last): > File "", line 1, in > ValueError: invalid literal for int() with base 10: 'kjjkj' > > In my program I need to be able to enter char strings or int strings on > the command line. Then I use an if-elif structure to establish which is > which. For example - > > if uniList[0].lower() in ("e","exit"): # uniList stores a unicode > string origionally taken from stdin > return > elif uniList[0].lower() in ("h","help"): > verb.PrintVerb() > elif uniList[0].lower() in ("p","pass"): > break > elif int(uniList[0]) in range(0,10): > verb.SetImportance(int(uniList[0])) > break > else: > verb.AddNewVerb((uniList[0]) > > How could I avoid the ValueError exception if uniList[0] == "?ker"? I > was thinking of having something like - > > formatError = False > try: > iVal = int(uniList[0]) > if iVal not in range range(0,10): > formatError = True > catch ValueError: Perhaps you meant except ValueError: :-) > iVal = -1 > Consider using uniList[0].isdigit() -- see http://docs.python.org/lib/string-methods.html HTH, John From researchbase at gmail.com Sun Dec 3 14:41:30 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Mon, 4 Dec 2006 01:11:30 +0530 Subject: problem formatting dates from text fields. Message-ID: hello all. thanks for the help and for pointing me to the proper url for wxpython related issues. I am so happy that I now have a very easy gui library that can do practically every thing with such ease (no flames intended but I was never at so much ease with java swing ). I however have a problem with dates. I am tired searching for some good tutorial that can explain the basic functionality of wx.datetime class and the datetime picker. I want to display the date in dd/mm/yyyy format and allow the user to change the dates. I then will like to take the value (the entire date) and put into a database. now this is my first question. the other problem is even more tough to solve with my given knowledge of wx.datetime and related classes. unfortunately the database given to me has a text field for date and the data is neetly entered. but when I get the data back from that text field I some how want to convert it back to actual date in the same dd/mm/yyyy format and send this as a value to my date time picker. how can I achieve this? thanking all. Krishnakant. From gagsl-py at yahoo.com.ar Fri Dec 15 13:42:24 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 15 Dec 2006 10:42:24 -0800 Subject: Restrictive APIs for Python In-Reply-To: <1166201174.540742.242670@f1g2000cwa.googlegroups.com> References: <1166193072.925721.52780@80g2000cwy.googlegroups.com> <1166197755.103495.234230@16g2000cwy.googlegroups.com> <1166201174.540742.242670@f1g2000cwa.googlegroups.com> Message-ID: <1166208144.913514.138390@t46g2000cwa.googlegroups.com> On 15 dic, 13:46, "Will Ware" wrote: > Gabriel Genellina wrote: > > In Python, the usual way of saying "don't play with me" is prepending > > an underscore: _private > Thanks, I am familiar with that. So enforce it instead of going against the nature of the language. > > BTW, have you *ever* tested your code? > Yes, we have a QA process. > The problem is not that the code doesn't > work, it does. Does it? >>> c = ClassUnderTest(1) >>> print c Traceback (most recent call last): File "", line 1, in ? File "", line 22, in __getattr__ KeyError: 'self' >>> Even if you try to correct this, c is no more an instance of the intended class, it's a "newklas" now, so isinstance() wont work anymore. It has lost his docstring so you don't know its purpose and intended usage anymore; you cannot inspect its methods using dir() so editors and other tools can't help you writting and documenting code. And a lot of other things upon which a lot of Python programs relies on. Don't go *against* the language, learn to use it the right way on your own advantage. > It was developed by a mix of more and less experienced > programmers, and early in the code's history, some hadn't been trained > on the benefits of complying to an API, or Pythonic idioms like the > leading underscore. So the code varies in its clarity, and some > maintenance chores aren't as pleasant as they might be. You can use tools like pylint or pychecker to try to detect and fix those issues. > I have found that the work of more experienced programmers often > includes improving the quality of code written by less experienced > programmers. Is this inconsistent with your own experience? If the less experienced guys get the feedback, I feel that's Ok. Just cut them a finger phalanx each time someone breaks the rules and see how well your programmers behave :) -- Gabriel Genellina From g.brandl-nospam at gmx.net Thu Dec 7 11:54:26 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Thu, 07 Dec 2006 16:54:26 +0000 Subject: funcs without () like print In-Reply-To: <1165502180.715192.195240@j72g2000cwa.googlegroups.com> References: <1165502180.715192.195240@j72g2000cwa.googlegroups.com> Message-ID: iwl wrote: > Hello can I make funktions callable without () like print > at time the interpreter seems to printout the adres when I type the > function without () print is not a function, it's a statement, and as such equivalent to raise or assert. Georg From tony_ha2002 at yahoo.co.uk Tue Dec 19 10:16:09 2006 From: tony_ha2002 at yahoo.co.uk (TonyHa) Date: 19 Dec 2006 07:16:09 -0800 Subject: Need Help on IDLE start up Message-ID: <1166541369.723012.145490@a3g2000cwd.googlegroups.com> Hello I have install Python 2.5 under an user directory "/user/dtgtools/packages/python/2.5" after installation python works ok. but when I try "idle" I have the following Error message: ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** I have read the README file it mentions the setup.py script should take care of the TCl/TK setup. but I wonder because our TCL/TCL is install under "/user/dtgtools/packages/TCL/8.4" how can I let ./configure know where to find Tcl/TK ? when installing Python. Thanks in advance! Tony Ha. From nick at craig-wood.com Tue Dec 5 05:30:05 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 05 Dec 2006 04:30:05 -0600 Subject: how to invoke the shell command and then get the result in python References: <1165303175.523129.154400@j72g2000cwa.googlegroups.com> <1165306945.315445.303490@80g2000cwy.googlegroups.com> Message-ID: petercable at gmail.com wrote: > Also, for a wrapper around popen, try commands: > > import commands > > pattern = raw_input('pattern to search? ') > print commands.getoutput('grep %s *.txt' % pattern) What if I entered "; rm -rf * ;" as my pattern? Don't ever pass user input (from file/web/raw_input) to the shell if you want to write a secure program! If you use subprocess then you can use a sequence of args to bypass the shell rather than a string to be passed to the shell. That will get over lots of shell escaping problems too. Eg from subprocess import Popen, PIPE from glob import glob pattern = raw_input('pattern to search? ') files = glob("*.txt") output = Popen(["grep", pattern] + files, stdout=PIPE).communicate()[0] print output You can also use subprocess to read the return code of the command and its stderr both of which you'll need if you are programming defensively! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From nmm1 at cus.cam.ac.uk Wed Dec 13 17:51:22 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 13 Dec 2006 22:51:22 GMT Subject: Defining classes References: Message-ID: In article , Duncan Booth writes: |> > |> > I am defining a class, and I need to refer to that class when |> > setting up its static data - don't ask - like this: |> > |> > Class weeble : |> > wumpus = brinjal(weeble) |> |> You cannot refer to weeble until it has been created which isn't until |> after all of the statements in the class body have executed. The usual way |> to achieve what you want is to assign the static member from outside the |> class. |> |> class weeble: |> pass |> |> weeble.wumpus = brinjal(weeble) Thanks (and to Gabriel Genellina). That is what I am doing, but it is not ideal in other respects - for example, I want to make that item read-only! It would be much cleaner not to have to fiddle with static members after the class is initialised. |> Alternatively you can play tricks with metaclasses for a similar effect. Well, I am already doing that, and regretting the fact that Python doesn't seem to allow a class instantiation to return a new class :-) What I am trying to do is very simple, but is somewhat unusual. That is the story of my life, so I am used to having problems. Regards, Nick Maclaren. From nick at craig-wood.com Fri Dec 29 10:30:04 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 29 Dec 2006 09:30:04 -0600 Subject: Convert Perl to Python References: <66b602900612282350ic0d4630x44640f90c0c774ca@mail.gmail.com> Message-ID: Emilio Sa?udo wrote: > ???????? ?????? wrote: > > How can I convert a perl script to Python? > > > http://www.crazy-compilers.com/bridgekeeper/ Very interesting until this bit :- The bad news: Unfortunatly, there is no way to 'try out' bridgekeeper. It's simply not available for puchasing. The good news:But we can offer you consultancy for this conversion (where we will use bridgekeeper as a mighty tool). If you are interested in hireing me for a project, please drop me a note I've done quite a lot of pl->py conversions by hand. It is a bit tedious but a good editor with macros will let you fly through the job. I used emacs. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From _karlo_ at _mosor.net_ Mon Dec 18 22:54:50 2006 From: _karlo_ at _mosor.net_ (Karlo Lozovina) Date: Tue, 19 Dec 2006 03:54:50 +0000 (UTC) Subject: SQLAlchemy, py2exe and Python 2.5 problem? Message-ID: I've just upgraded to Python 2.5, SQLAlchemy 0.3.3, and py2exe 0.6.5 (the py2.5 version, yes). Simple: --- import sqlalchemy print 'Test' --- works when interpreted by Python, but when running it from compiled py2exe binary, it fails with this error: Traceback (most recent call last): File "main.py", line 1, in File "sqlalchemy\__init__.pyc", line 10, in File "sqlalchemy\orm\__init__.pyc", line 12, in File "sqlalchemy\orm\mapper.pyc", line 7, in File "sqlalchemy\logging.pyc", line 30, in ImportError: No module named logging Ofcourse, library.zip (in the dist directory) contains 'sqlalchemy \logging.pyc'. After I copy logging.pyc to library.zips' root, I get this error: Traceback (most recent call last): File "main.py", line 1, in File "sqlalchemy\__init__.pyc", line 10, in File "sqlalchemy\orm\__init__.pyc", line 12, in File "sqlalchemy\orm\mapper.pyc", line 7, in File "sqlalchemy\logging.pyc", line 30, in File "sqlalchemy\logging.pyc", line 33, in AttributeError: 'module' object has no attribute 'getLogger' Does anyone have a clue why this happens? And what is responsible for this? SQLAlchemy, or py2exe? Thanks in advance... -- _______ Karlo Lozovina - Mosor | | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_____|_____| From kent at kentsjohnson.com Fri Dec 22 10:56:05 2006 From: kent at kentsjohnson.com (Kent Johnson) Date: Fri, 22 Dec 2006 15:56:05 GMT Subject: One module per class, bad idea? In-Reply-To: <1165964967.940454.74490@73g2000cwn.googlegroups.com> References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> Message-ID: Carl Banks wrote: > Now, I think this is the best way to use modules, but you don't need to > use modules to do get higher-level organization; you could use packages > instead. It's a pain if you're working on two different classes in the > same system you have to keep switching files; but I guess some people > prefer to switch files rather than to scroll for some reason. That would be me. I strongly prefer to switch files rather than scroll. I use an editor that makes it easy to switch files. For me it is much easier to switch between files than to scroll between two parts of a file, and I don't lose my place when I switch back. I like to be able to see things side by side. So I do tend to put classes in separate modules. Not always - when two or more classes are closely related or a class has one or more helper classes they may share a module - but in general my major classes are each to a module. It does make the imports look funny - I tend to give the module the same name as the class, Java style, so I have from foo.bar.MyClass import MyClass but that is a minor point IMO. Kent From rtw at freenet.co.uk Mon Dec 25 07:31:42 2006 From: rtw at freenet.co.uk (Rob Williscroft) Date: Mon, 25 Dec 2006 06:31:42 -0600 Subject: method names in __slots__ ?? References: <1167008799.074885.250770@73g2000cwn.googlegroups.com> Message-ID: John Machin wrote in news:1167008799.074885.250770@ 73g2000cwn.googlegroups.com in comp.lang.python: > Given a = Adder(), > a.tally = 0 > gets AttributeError: 'Adder' object attribute 'tally' is read-only > a.notinslots = 1 > gets AttributeError: 'Adder' object attribute 'notinslots' is read-only > > So is there some magic class-fu going down here, or is this just a > waste of memory space in the instances? > Haven't you, with your 2 examples above, answered your own question ? Clearly from your example it doesn't make any difference if you add a class attribute to the slots, one way or another its as if you hadn't put it in there in the first place. This will give the same error, which shows its about class attributes and not just methods: class Adder(object): __slots__ = [ 'class_name' ] class_name = 3 a = Adder() a.class_name = 2 It would seem that the interpreter removes any names it finds as class attribute names from the list it finds in __slots__ before it creates the instance. Of course if my guessing above isn't good enough, we could look at the documentation: http://docs.python.org/ref/slots.html#l2h-218 __slots__ are implemented at the class level by creating descriptors (3.4.2) for each variable name. As a result, class attributes cannot be used to set default values for instance variables defined by __slots__; otherwise, the class attribute would overwrite the descriptor assignment. So its that the __slots__ assignment makes the descriptors and then the subsiquent method defenitions and class attribute bindings remove them. Rob. -- http://www.victim-prime.dsl.pipex.com/ From rNOSPAMon at flownet.com Fri Dec 1 02:36:49 2006 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 30 Nov 2006 23:36:49 -0800 Subject: Is there a reason not to do this? References: Message-ID: In article , "Hendrik van Rooyen" wrote: > "Ron Garret" wrote: > > > > > > One of the things I find annoying about Python is that when you make a > > change to a method definition that change is not reflected in existing > > instances of a class (because you're really defining a new class when > > you reload a class definition, not actually redefining it). So I came > > up with this programming style: > > I would have thought that not changing yesterday was the very essence of > dynamism (dynamicness ??) - but that when you change something - it applies > from that point in time forwards... I don't want to get into a philosophical debate. I'll just point you to CLOS as an example of an object system that already works this way. > What do you propose to do about the outputs from such classes that have > already happened? The ability to change methods on the fly will be used mainly for debugging I expect. rg From michele.simionato at gmail.com Wed Dec 6 11:34:29 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 6 Dec 2006 08:34:29 -0800 Subject: About the 79 character line recommendation In-Reply-To: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> References: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> Message-ID: <1165422869.301082.91000@j72g2000cwa.googlegroups.com> Steve Bergman wrote: > > So, I was wondering what more accomplished Python programmers thought > about this. I *hate* people using more than 79 chars per line! ;) They look horrible in emacs and horrible on print. I never found the need for longer lines. The limit also acts as a deterrent against extra-large one-liners. Finally, notice that you can alwasys aliases if you are a lazy typist: shortcut = LongClassName.LongAttributeName This also saves an attribute access and gives you some additional speed, which may be useful in some cases. Michele Simionato From epost2 at gmail.com Tue Dec 19 09:33:20 2006 From: epost2 at gmail.com (Bruce) Date: 19 Dec 2006 06:33:20 -0800 Subject: update attribute - (newbie) Message-ID: <1166538800.915433.38680@79g2000cws.googlegroups.com> >>> class A: ... def __init__(self): ... self.t = 4 ... self.p = self._get_p() ... def _get_p(self): ... return self.t ... >>> a = A() >>> a.p 4 >>> a.t += 7 >>> a.p 4 I would like to have it that when I ask for p, method _get_p is always called so that attribute can be updated. How can I have this functionality here? thanks From greg at cosc.canterbury.ac.nz Fri Dec 15 01:49:14 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 15 Dec 2006 19:49:14 +1300 Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: <1166078696.227746.165750@j72g2000cwa.googlegroups.com> References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> <1166078696.227746.165750@j72g2000cwa.googlegroups.com> Message-ID: <4582456A.7040704@cosc.canterbury.ac.nz> rich murphy wrote: > So, I assumed "the current directory" is C:\Python25 which did not > work... What directory does it mean then? It means the current directory of the process running the Python interpreter, which, unless you've done something to change it, will be the same as the current directory of the command shell that you ran the Python interpreter from. That, in turn, will be whatever you set it to using the "cd" command. However, it's important to understand that this only applies when using the Python interpreter *interactively*, which means just typing "python" and entering Python statements at the >>> prompt. If you tell the interpreter to run a .py file, e.g. python some\dir\myfile.py then it does *not* look in the current directory of the process for imported files -- instead, it looks in the directory containing the "main" .py file, i.e. the one you passed on the command line. This is more useful, since it allows you to keep the main file and the modules it uses together, and not have to worry about cd'ing to the directory in order to run it. Also, if you're using an IDE such as IDLE or PythonWin instead of running the interpreter from a command shell, relying on the "current directory" isn't very useful, since it's hard to predict what it will be. Again, just put the files to be imported alongside your main .py file and you should be all right. There are various ways of specifying additional places to look for imported modules, but that should be enough to get you going. -- Greg From webmaster at cacradicalgrace.org Tue Dec 19 13:24:59 2006 From: webmaster at cacradicalgrace.org (J. Clifford Dyer) Date: Tue, 19 Dec 2006 11:24:59 -0700 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: Nick Maclaren wrote: > In article , > "J. Clifford Dyer" writes: > |> > |> How about: "A heterogenous sequence is one in which each element plays a > |> unique role, specific to its position in the sequence. A homogenous > |> sequence is one in which position is determinative of nothing > |> significant other than (perhaps) order." > > Nope. Sorry. Consider the old model where an I/O list is an ordered > sequence of strings and agents (effectively procedure calls), with no > constraints on how those are ordered. With your specification, that > is neither heterogenous nor homogenous :-) On the contrary, I think that example fits perfectly with my definition of homogenous. If there is no constraint on position, then what is the position determinative of? Order in the queue. Nothing more. By my definition, homogeneous. QED. I'll grant, it's not exactly the most intuitive definition of homogenous, but I think it is the most accurate for this situation. Perhaps homogenous and heterogenous aren't the best possible words here, but I think they work. > > |> I doubt the python interpreter will ever try to enforce > |> homogeneity/heterogeneity on lists/tuples, in part because there no good > |> ways of definining it syntactically, and in part because there are > |> certainly good reasons for breaking the rules. As someone said: passing > |> lists to untrustworthy functions. And as someone else said, *args > |> passes a tuple, even though it is frequently just a homogenous list of > |> more arguments. > > It's a complete delusion, because even the claimed assumption of list > homogeneity is tantmount to saying that Python doesn't encourage (or, > arguably, support) ANY way of using mutable heterogenous sequences > (such as the example above). To claim that they are inherently an > undesirable programming practice is a clear descent into religion! > > I would be amused to know what Python type the "lists are intended to > be homogenous" people use to implement mutable heterogenous sequences, > or whether they claim that wanting such a feature is heresy :-) > By my definition, how can it be mutable AND heterogenous? If the first element is a name, the second element is a phone number, and the third element is an email address, and you insert an element in between the first two elements, do you mean to tell me that the phone number, which has moved to the third slot, is now an email address? It doesn't make sense. Maybe the words are wrong. I'm not sure. But I think the distinction is valid. Furthermore, I think we "lists are intended to be homogenous" people would say that you are perfectly welcome to use lists for other purposes, if it suits you. Just as you can use a string as a list. We don't have to be rigid to appreciate the difference. :) > > Regards, > Nick Maclaren. > > Blessings, Cliff From rpdooling at gmail.com Wed Dec 13 19:32:11 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 13 Dec 2006 16:32:11 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1166047661.729792.208130@73g2000cwn.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> <1166046193.734274.124160@73g2000cwn.googlegroups.com> <1166047661.729792.208130@73g2000cwn.googlegroups.com> Message-ID: <1166056331.453308.189440@n67g2000cwd.googlegroups.com> jay graves wrote: > > Do you have any *.pth files in the C:\Python24 directory? > No. From kay.schluehr at gmx.net Fri Dec 8 11:03:18 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Dec 2006 08:03:18 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> Message-ID: <1165593798.079105.144060@80g2000cwy.googlegroups.com> Alex Mizrahi schrieb: > it's also > interesting, that python, perl, php and ruby show very similar peformance, > while lisp and scheme implementations show large improvements -- it makes me > think that there's something "pathalogically scripting" in their > specifications (maybe some obligatory use of strings for method dispatch?). "The most unusual features of the SBCL compiler (which is very similar to the original CMUCL compiler, also known as Python) is its unusually sophisticated understanding of the Common Lisp type system and its unusually conservative approach to the implementation of type declarations. These two features reward the use of type declarations throughout development, even when high performance is not a concern. Also, as discussed in the chapter on performance (see Efficiency), the use of appropriate type declarations can be very important for performance as well." http://www.sbcl.org/manual/Handling-of-Types.html#Handling-of-Types If you'd read the docs of the tools you admire you might find the answers yourself. From JShrager at gmail.com Mon Dec 11 23:16:19 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 11 Dec 2006 20:16:19 -0800 Subject: merits of Lisp vs Python In-Reply-To: <4u6mf2F161jbqU2@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> <1165876294.938323.233380@80g2000cwy.googlegroups.com> <4u6mf2F161jbqU2@mid.individual.net> Message-ID: <1165896979.850909.140700@79g2000cws.googlegroups.com> greg wrote: > JShrager at gmail.com wrote: > > So if you guys would just fix > > your language by adding homogeneous syntax and all that it brings with > > it (macros, compilers, etc) we'd be happy to use your version of Lisp, > > and all its great libraries, instead of ours! :-) > > But if we did that, it wouldn't be Python any > more, it'd be Lisp. And then all those great > libraries wouldn't work with it, because they're > for Python, not Lisp. :-( Does the word "TRONDANT" hold some special meaning for you? From hardcoded.software at gmail.com Tue Dec 5 15:00:10 2006 From: hardcoded.software at gmail.com (Virgil Dupras) Date: 5 Dec 2006 12:00:10 -0800 Subject: About the 79 character line recommendation References: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> Message-ID: <1165348808.807516.201860@j72g2000cwa.googlegroups.com> Steve Bergman wrote: > As I study Python, I am trying to develop good, Pythonic, habits. For > one thing, I am trying to keep Guido's the style guide in mind. > > And I know that it starts out saying that it should not be applied in > an absolute fashion. > > However, I am finding that the 79 character line prescription is not > optimal for readability. > > Certainly, cutting back from the length of lines that I used to use has > *helped* readability. But if I triy very hard to apply 79, I think > readability suffers. If this were just something that was an issue > occasionally, I would just put it off to "know when to break the > rules". However, find myself going to 90 to 100 characters very > frequently. Now, if it were just me, I'd shoot for < 100. However, > the Python philosophy includes making code easier for others to read, > as well. > > So, I was wondering what more accomplished Python programmers thought > about this. > > While I'm on this general topic, the guide mentions a pet peeve about > inserting more than one space to line up the "=" in assignment > statements. To me, lining them up, even if it requires quite a few > extra spaces, helps readability quite a bit. Comments? > > Thanks, > Steve Bergman I also think that limiting code to 80 columns often hinders readability. I personally try to limit my code to 100 columns. The end result is pretty nice. However, I'm all for the "flat is better than nested" philosophy, even when nested is under 100 columns. From ejatsomewhere.com Thu Dec 28 14:13:29 2006 From: ejatsomewhere.com (Erik Johnson) Date: Thu, 28 Dec 2006 12:13:29 -0700 Subject: xml bug? References: <4594130c$0$318$426a74cc@news.free.fr> Message-ID: <45941780$1@nntp.zianet.com> "Imbaud Pierre" wrote in message news:4594130c$0$318$426a74cc at news.free.fr... > Now my points are: > - how do I spot the version of a given library? There is a __version__ > attribute of the module, is that it? Yes, the module maintainer should be incrementing this version for each new release and so it should properly correspond to the actual revision of code. > - How do I access to a given library buglist? Maybe this one is known, > about to be fixed, it would then be useless to report it. Not exactly sure, but this is probably a good place to start: http://docs.python.org/modindex.html > - How do I report bugs, on a standard lib? I found this link: http://sourceforge.net/tracker/?group_id=5470&atid=105470 by looking under the "help" item at www.python.org (an excellent starting place for all sorts of things). > - I tried to copy the lib somewhere, put it BEFORE the official lib in > "the path" (that is:sys.path), the stack shown by the traceback > still shows the original files being used. Is there a special > mechanism bypassing the sys.path search, for standard libs? (I may > be wrong on this, it seems hard to believe...) My understanding is sys.path is searched in order. The first entry is usually the empty string, interpreted to mean the current directory. If you modify sys.path to put the directory containing your modified code in front of where the standard library is found, your code should be the one used. That is not the case? > - does someone know a good tool to validate an xml file? Typing "XML validator" into google returns a bunch. I think I would start with the one at w3.org: http://validator.w3.org/ From simone.leo at gmail.com Thu Dec 14 12:04:40 2006 From: simone.leo at gmail.com (Tekkaman) Date: 14 Dec 2006 09:04:40 -0800 Subject: Logging module: problem with some mapping keys In-Reply-To: References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166106298.176199.301190@f1g2000cwa.googlegroups.com> <1166113691.753244.189350@f1g2000cwa.googlegroups.com> Message-ID: <1166115880.772291.108740@n67g2000cwd.googlegroups.com> Peter Otten wrote: > Tekkaman wrote: > > > Peter Otten wrote: > >> Tekkaman wrote: > >> > >> > Thanks for the hint, but it's not a symlink > >> > >> What does logging._srcfile contain? Should be > >> > >> >>> import logging > >> >>> logging._srcfile > >> '/usr/lib/python2.4/logging/__init__.py' > >> > >> on your machine, but probably isn't. > > > '/usr/lib64/python2.4/logging/__init__.py' > > And neither /usr/lib nor /usr/lib/python2.4 are symlinks? > > Peter > > PS: Please don't top-post Sry for the top-post, I noticed the PS a moment too late! From basti.wiesner at gmx.net Thu Dec 21 07:15:44 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Thu, 21 Dec 2006 13:15:44 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Fredrik Lundh schrieb > Sebastian 'lunar' Wiesner wrote: > >>> you're confusing the shell's "is this file executable" check with >>> the loader's "can I execute this file" check: >>> >>> $ export PATH=.:$PATH >>> $ dd if=/dev/zero of=ls count=1 >>> 1+0 records in >>> 1+0 records out >>> $ ls -l ls >>> -rw-rw-r-- 1 slab slab 512 Dec 20 03:33 ls >>> $ chmod a+x ls >>> $ ls >>> -bash: ./ls: cannot execute binary file >> >> ??? >> Am I blind or is there really no difference between you shell example >> an mine? >> As far as I can see, you are doing exactly the same thing as I did... > > no, I'm showing that a local file marked as executable overrides a > shared one, even if the local file isn't actually an executable. Well, that doesn't tell us anything about, whether a file executable or not. But anyway: you admit, that the local file "ls" is __not__ actually executable, although it has the x-bit set? >> So what are trying to proof? > > that you're wrong when you claim that the contents of the file matters > when using the usual Unix conventions to check if a file is > executable. Let me ask you a question: [lunar at nargond]-[13:09:52] >> ~/test --> cat test.sh #!/bin/bash if [ "$1" ]; then echo "Hello $1" else echo "Hello world" fi [lunar at nargond]-[13:09:54] >> ~/test --> ll test.sh -rw-r--r-- 1 lunar lunar 76 2006-12-21 13:09 test.sh Is test.sh now executable or not? Bye lunar -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From maksim.kasimov at gmail.com Thu Dec 14 10:06:11 2006 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Thu, 14 Dec 2006 17:06:11 +0200 Subject: Non greedy regex In-Reply-To: <1166107546.537991.165970@t46g2000cwa.googlegroups.com> References: <1166107546.537991.165970@t46g2000cwa.googlegroups.com> Message-ID: > print re.sub( 'a.*?b', '', 'ababc' ) > > gives: 'c' you've forgot "^" at the begging of the pattern (there is another 'ab' before 'c') print re.sub( '^a.*?b', '', 'ababc' ) tibetan.houdini at gmail.com wrote: > Can someone please explain why these expressions both produce the same > result? Surely this means that non-greedy regex does not work? > > print re.sub( 'a.*b', '', 'ababc' ) > > gives: 'c' > > Understandable. But > > print re.sub( 'a.*?b', '', 'ababc' ) > > gives: 'c' > > NOT, understandable. Surely the answer should be: 'abc' > -- Maksim Kasimov From jstroud at mbi.ucla.edu Fri Dec 22 20:55:16 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 23 Dec 2006 01:55:16 GMT Subject: Retrieve Tkinter listbox item by string, not by index In-Reply-To: <44e1e$458c40af$4275d90a$22798@FUSE.NET> References: <44e1e$458c40af$4275d90a$22798@FUSE.NET> Message-ID: <800jh.36786$wP1.8889@newssvr14.news.prodigy.net> Kevin Walzer wrote: > I'm trying to set the active item in a Tkinter listbox to my > application's currently-defined default font. > > Here's how I get the fonts loaded into the listbox: > > self.fonts=list(tkFont.families()) > self.fonts.sort() > > for item in self.fonts: > self.fontlist.insert(END, item) #self.fontlist is the > ListBox instance > > > So far, so good. But I don't know how to set the active selection in the > listbox to the default font. All the methods for getting or setting a > selection in the listbox are based on index, not a string. And using > standard list search methods like this: > > if "Courier" in self.fontlist: > print "list contains", value > else: > print value, "not found" > > returns an error: > > TypeError: cannot concatenate 'str' and 'int' objects > > So I'm stuck. Can someone point me in the right direction? I would keep a separate data structure for the fonts and update the scrollbar when the list changed. This would help to separate the representation from the data represented. Here is a pattern I have found most useful and easy to maintain: # untested class FontList(Frame): def __init__(self, *args, **kwargs): Frame.__init__(self, *args, **kwargs) self.pack() self.fonts = list(kwargs['fonts']) self.default = self.fonts.index(kwargs['default_font']) self.lb = Listbox(self) # add scrollbar for self.lb, pack scrollbar # pack self.lb self.set_bindings() self.update() def set_bindings(self): # put your bindings and behavior here for FontList components def update(self): self.lb.delete(0, END) for f in self.fonts: self.lb.insert(f) self.highlight() def highlight(self): index = self.default self.lb.see(index) self.lb.select_clear() self.lb.select_adjust(index) self.lb.activate(index) def change_font(self, fontname): self.default = self.fonts.index(fontname) self.highlight() def add_font(self, fontname, index=None): if index is None: self.fonts.append(fontname) else: self.fonts.insert(index, fontname) self.update() # other methods for adding multiple fonts or removing them, etc. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From rNOSPAMon at flownet.com Fri Dec 1 12:53:41 2006 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 01 Dec 2006 09:53:41 -0800 Subject: Is there a reason not to do this? References: <1164963978.876893.129800@79g2000cws.googlegroups.com> Message-ID: In article <1164963978.876893.129800 at 79g2000cws.googlegroups.com>, "Michele Simionato" wrote: > Ron Garret wrote: > > One of the things I find annoying about Python is that when you make a > > change to a method definition that change is not reflected in existing > > instances of a class (because you're really defining a new class when > > you reload a class definition, not actually redefining it). So I came > > up with this programming style: > > > > def defmethod(cls): > > return lambda (func): type.__setattr__(cls, func.func_name, func) > > Why not just ``return lambda func: setattr(cls, func.func_name, func)`` > ? Because I'm an idiot. (i.e. yes, that is obviously the right way to do it.) > The only thing I don't like is that all your > functions/methods will end up begin 'None'. > > I'd rather to be able to use > the help, so I would write > > def defmethod(cls): > def decorator(func): > setattr(cls, func.func_name, func) > return func > return decorator > > @defmethod(C) > def m1(self, x):pass > > help(m1) > > > BTW, for people with a Lisp background I recommend using IPython with > emacs and the > ipython.el mode. It is pretty good, even if not comparable to Slime. > > Michele Simionato Good tips. Thanks! rg From fredrik at pythonware.com Mon Dec 18 03:01:12 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 18 Dec 2006 09:01:12 +0100 Subject: dealing with special characters in Python and MySQL In-Reply-To: <1166426105.495305.173690@73g2000cwn.googlegroups.com> References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> <1166423874.304873.218020@t46g2000cwa.googlegroups.com> <0Yqhh.20400$wc5.8435@newssvr25.news.prodigy.net> <1166426105.495305.173690@73g2000cwn.googlegroups.com> Message-ID: ronrsr wrote: > now, I can't do any string operations, I get the error msg: > > descriptor 'lower' requires a 'str' object but received a 'unicode' > args = ("descriptor 'lower' requires a 'str' object but received > a 'unicode'",) what's a "string operation" in this context? are you trying to call string methods by explicit calls to class methods in the str class: >>> str.upper(u"foo") Traceback (most recent call last): File "", line 1, in TypeError: descriptor 'upper' requires a 'str' object but received a 'unicode' instead of calling methods on the string object: >>> u"foo".upper() u'FOO' ? if so, what did you get that idea from? From cenyongh at gmail.com Tue Dec 19 00:35:25 2006 From: cenyongh at gmail.com (cenyongh at gmail.com) Date: 18 Dec 2006 21:35:25 -0800 Subject: Is there any python-twisted tutorial or texts? In-Reply-To: <1166496307.681933.247810@t46g2000cwa.googlegroups.com> References: <1166496307.681933.247810@t46g2000cwa.googlegroups.com> Message-ID: <1166506525.334030.234420@48g2000cwx.googlegroups.com> The doc in the twisted web site is a good starting point. Also there is a book . Jia Lu wrote: > Hi all > I want to study twisted of python . But I donot know how to start. > Any suggistions? > > Thank you From thompson.marisa at gmail.com Wed Dec 20 15:26:35 2006 From: thompson.marisa at gmail.com (thompson.marisa at gmail.com) Date: 20 Dec 2006 12:26:35 -0800 Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects In-Reply-To: References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> Message-ID: <1166646395.697496.227010@48g2000cwx.googlegroups.com> I've had a lot of replies suggesting different things. These are the results: When I change while Townshps !="": to while Townshp is not None: and when I change while Townshps !="": to for Townshp in iter(gp.ListFeatureClasses().next, None): They both work perfectly, and it solved my problem. Thank you all so much. Marisa On Dec 20, 2:22 pm, Fredrik Lundh wrote: > thompson.mar... at gmail.com wrote: > > I'm extremely new to Python and programming as a whole. I have written > > a python script with the assistance of ESRI ArcGIS 9.2, which uses > > Python 2.4.1, however, it gives me this error when I try to run it. > > I've already posted at ESRI support, and I was hoping that Python > > people could help me more. > > > I hope there is something simple I could do to be able to define the > > object that it thinks is NoneType.that would be the None object. > > http://effbot.org/pyref/None > > which is often used as a placeholder in Python. > > my guess is that it's the next() call that returns None when you've > reached the end of the shapefile list; try changing > > while Townshps !="": > > to > > while Townshps is not None: > > and see if the problem goes away. > > if you still get an exception, please post the full traceback; see > > http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-p... > > for details. > > From paul at floorball-flamingos.nl Wed Dec 6 07:17:53 2006 From: paul at floorball-flamingos.nl (Paul Melis) Date: Wed, 06 Dec 2006 13:17:53 +0100 Subject: dict.has_key(x) versus 'x in dict' Message-ID: Hello, I've always been using the has_key() method to test if a dictionary contains a certain key. Recently I tried the same using 'in', e.g. d = { ... } if k in d: ... and found that it seems to perform a lot better when lots of key-tests are to be performed. I also noticed that has_key() is scheduled to be removed from future (C)Python versions. Does the 'in' way of testing have an optimized implementation compared to has_key()? Is that the reason has_key() is being phased out? Thanks, Paul From g.brandl-nospam at gmx.net Wed Dec 20 13:36:49 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Wed, 20 Dec 2006 19:36:49 +0100 Subject: perl better than python for users with disabilities? In-Reply-To: References: <87slfalf8h.fsf@jidanni.org> <458977b7$0$326$e4fe514c@news.xs4all.nl> Message-ID: Thomas Ploch schrieb: > Martin P. Hellwig schrieb: >> Quite punny title though I assume you are really serious and mean people >> with a physical disability, I won't comment any further on this subject >> :-), if I already offended anyone, please excuse me, since I'm original >> from Germany I'm not supposed to be funny. > > Argh, I am writing to President Horst K?hler to take away your German > citizenship. You _need_ to stay true to German attributes (like not > being funny, what you have been...)! This is the last warning! I don't think he'd have the time for that. I heard he's busy planning his lawsuit to enforce his claim for more pension. > Regarding the topic: > > I can't see where Perl should be more accessible than Python. Well, not really. But your $, @, %, {, }, ! etc. keys should be accessible very fast if you want to write Perl. Georg From dwhall256 at gmail.com Wed Dec 20 08:57:12 2006 From: dwhall256 at gmail.com (dwhall) Date: 20 Dec 2006 05:57:12 -0800 Subject: python-hosting.com projects: dead? In-Reply-To: <1166544069.898631.4310@a3g2000cwd.googlegroups.com> References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> <1166542383.019580.185960@73g2000cwn.googlegroups.com> <1166544069.898631.4310@a3g2000cwd.googlegroups.com> Message-ID: <1166623032.616757.216560@f1g2000cwa.googlegroups.com> My project was temporarily disabled as well even though I had taken measures to block spam and had committed to svn and edited the trac wiki one day before. I was a bit concerned that maybe webfaction had lost my trac and svn during their house cleaning. But I emailed Remi and he had it going again promptly. They provide a great service for free and they give back to the Python community. They deserve our thanks and our patronage. With regard to how they handled it, I think they chose an effective method. Why should they support projects (for free) that aren't active? So just disable the project to see if anyone cares enough to find out why it's gone. Ever so slightly draconian, but good for keeping a clean house. I'm glad they have done this cleaning work, the server seems much more responsive now; no more errors from trac. !!Dean jpellerin+nose at gmail.com wrote: > Fredrik Lundh wrote: > > jpellerin+nose at gmail.com wrote: > > > > > my svn repository and tickets again. I'm sure you can understand why I > > > was dismayed by this and why, unfortunately, I'll never be comfortable > > > trusting my data to them again. > > > > not really, but maybe I've just worked with computers and human beings > > long enough not to treat every little hiccup as if it were the end of > > the world as we know it. > > You're misreading me very badly, or I'm expressing myself very poorly. > Either way, you've inferred some kind of spittle-flecked freakout where > I did not mean to imply one. > > JP From ronrsr at gmail.com Mon Dec 18 01:35:02 2006 From: ronrsr at gmail.com (ronrsr) Date: 17 Dec 2006 22:35:02 -0800 Subject: dealing with special characters in Python and MySQL In-Reply-To: <8rqhh.956$X72.39@newsread3.news.pas.earthlink.net> References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> <8rqhh.956$X72.39@newsread3.news.pas.earthlink.net> Message-ID: <1166423702.885345.30460@80g2000cwy.googlegroups.com> structure for the DB: CREATE TABLE `zingers` ( `zid` int(9) unsigned NOT NULL auto_increment, `keywords` varchar(255) default NULL, `citation` text, `quotation` text, PRIMARY KEY (`zid`) ) ENGINE=MyISAM DEFAULT CHARSET=UTF8 AUTO_INCREMENT=422 ; code for storing to database: querystring = "update zingers set keywords = '%s', citation = '%s', quotation = %s' where zid = %d" % (keywords,citation,quotation,zid) ; cursor.execute(querystring) at this point, querystring = update zingers set keywords = ' aaaaaa;Action', citation = ''''''''' ', quotation = ''''''''''''' ' where zid = 422 where '''' are an assortment of apostrophes and single quotes copied and pasted from a Word Document. > > And where is the actual code... What you've supplied doesn't show > how you are generating the SQL... > -- From seberino at spawar.navy.mil Thu Dec 7 14:53:36 2006 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 7 Dec 2006 11:53:36 -0800 Subject: Can't 'register' to Cheese Shop from command line..only web + egg dependency question Message-ID: <1165521216.869978.151290@16g2000cwy.googlegroups.com> I seem to be able to register and upload from web site but not command line. Command line register attempts keep giving " Server response (401): Authorization Required" Any ideas? & What must I do to make installation of my egg also install dependencies? I did an install and noticed other eggs didn't come along for the ride. Chris From grante at visi.com Wed Dec 6 18:15:23 2006 From: grante at visi.com (Grant Edwards) Date: Wed, 06 Dec 2006 23:15:23 -0000 Subject: Mirror imaging binary numbers References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> <1165445569.287552.266120@j44g2000cwa.googlegroups.com> <1165446077.584437.206310@73g2000cwn.googlegroups.com> Message-ID: <12nejobbq32hm15@corp.supernews.com> On 2006-12-06, Craig wrote: > Thanks so much for the response. I have an array of > individual bytes which will eventually make up a binary bitmap > image that is loaded onto an LCD screen (1 = black dot, 0 = > white dot). At the moment each byte is reversed to what it > should be (completely reverse the bit order): e.g 00111101 > should be 10111100, 11001100 should be 00110011, etc. It is > not an int problem as such, it is more a bit level swap if you > get what I mean. If you could help that would be great. He's already told you 90% of the answer: use the bit operators & | ~ ^ >> <<. Here's the remaining 10% of the answer (done a couple different ways): def showbits8(b): mask = 0x80 while mask: print "01"[(b & mask) != 0], mask >>= 1 print def bitswap8a(b): r = 0 mask = 0x80 while mask: r >>= 1 if b & mask: r |= 0x80 mask >>= 1 return r def bitswap8b(b): r = 0 for m1,m2 in ((0x80,0x01),(0x40,0x02),(0x20,0x04),(0x10,0x08),(0x01,0x80),(0x02,0x40),(0x04,0x20),(0x08,0x10)): if b & m1: r |= m2 return r def testit(b): showbits8(b) showbits8(bitswap8a(b)) showbits8(bitswap8b(b)) print testit(0xc1) testit(0x55) testit(0xe2) -- Grant Edwards grante Yow! Is this "BOOZE"? at visi.com From steve at REMOVE.THIS.cybersource.com.au Sat Dec 30 21:30:58 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 31 Dec 2006 13:30:58 +1100 Subject: Question concerning this list References: Message-ID: On Sun, 31 Dec 2006 02:03:34 +0100, Thomas Ploch wrote: > Hello fellow pythonists, > > I have a question concerning posting code on this list. > > I want to post source code of a module, which is a homework for > university (yes yes, I know, please read on...). So long as you understand your university's policy on collaborations. > It is a web crawler (which I will *never* let out into the wide world) If you post it on Usenet, you will have let it out into the wide world. People will see it. Some of those people will download it. Some of them will run it. And some of them will run it, uncontrolled, on the WWW. Out of curiosity, if your web crawler isn't going to be used on the web, what were you intending to use it on? > which uses regular expressions (and yes, I know, thats not good, too). Regexes are just a tool. Sometimes they are the right tool for the job. Sometimes they aren't. > I have finished it (as far as I can), but since I need a good mark to > actually finish the course, I am wondering if I can post the code, and I > am wondering if anyone of you can review it and give me possible hints > on how to improve things. That would be collaborating. What's your university's policy on collaborating? Are you allowed to do so, if you give credit? Is it forbidden? It probably isn't a good idea to post a great big chunk of code and expect people to read it all. If you have more specific questions than "how can I make this better?", that would be good. Unless the code is fairly short, it might be better to just post a few extracted functions and see what people say about them, and then you can extend that to the rest of your code. -- Steven. From adam at atlas.st Sat Dec 23 22:34:11 2006 From: adam at atlas.st (Adam Atlas) Date: 23 Dec 2006 19:34:11 -0800 Subject: Getting the name of an assignment In-Reply-To: <6b6dnZveubZ8dhDYnZ2dnUVZ_ua3nZ2d@comcast.com> References: <1166913499.494219.250440@48g2000cwx.googlegroups.com> <6b6dnZveubZ8dhDYnZ2dnUVZ_ua3nZ2d@comcast.com> Message-ID: <1166931251.020269.93440@48g2000cwx.googlegroups.com> Thanks, Steven and Steven. @Bethard: Isn't it a bit convoluted to use metaclasses? someinstance.__class__.__name__ does the same thing. @D'Aprano: Thanks for the advice to rethink my data model. I'm doing so right now, and I've already come up with a way that makes more sense. :) From john.thingstad at chello.no Tue Dec 12 20:37:00 2006 From: john.thingstad at chello.no (John Thingstad) Date: Wed, 13 Dec 2006 02:37:00 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4579c4f4$0$49201$14726298@news.sunsite.dk> <1165971298.617221.59450@n67g2000cwd.googlegroups.com> Message-ID: On Wed, 13 Dec 2006 01:54:58 +0100, Paddy wrote: > > Robert Uhl wrote: > >> Steven D'Aprano writes: >> > >> > Speaking as somebody who programmed in FORTH for a while, that doesn't >> > impress me much. Prefix/postfix notation is, generally speaking, more >> > of a pain in the rear end than it is worth, even if it saves you a >> > tiny bit of thought when pasting code. >> >> Of course, you use prefix notation all the time in Python: >> >> for x in range(0,len(y)): >> dosomething(x) > > In Python, most containers are directly iterable so we are much more > likely to arrange our program to use: > for a in y: > dosomethingwith(a) > > -Paddy. > In lisp: (loop for a in y do (do-something a)) There is one difference.. There is no iterator so you have different pronouns for each sequence type: list: (loop for a in y .. array: (loop for a across y .. hash: (loop for a over y .. hardly ideal, but workable. Still it is a lot simpler to change the declaration in the start of the loop than having to changing the access to all references to a variable as you might have to with recursion. Consider (defun func-iter (list) (func (first list))) (when (not (endp list)) (func-iter (rest list))) (You could write (mapc #'(lambda (e) (func e)) list) but that is beside the point.) or something like that. What happens if you change the type to a array? Total rewrite.. From a software engineering point of view iteration is preferable to recursion because maintenance and aggregation is simpler. (Sorry about the digression.) -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From fredrik at pythonware.com Mon Dec 11 08:30:35 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Dec 2006 14:30:35 +0100 Subject: Pb ReportLab (ttfonts.py) In-Reply-To: <457d4ba5$0$5067$ba4acef3@news.orange.fr> References: <457d4ba5$0$5067$ba4acef3@news.orange.fr> Message-ID: M?ta-MCI wrote: > I try to generate PDF from Python 2.5 + ReporLab_lib, and, I have: > > C:\Python25\reportlab\pdfbase\ttfonts.py:407: DeprecationWarning: struct > integer overflow masking is deprecated > stm.write(pack(">LLL", checksum, offset, len(data))) > C:\Python25\reportlab\pdfbase\ttfonts.py:419: DeprecationWarning: struct > integer overflow masking is deprecated > stm.write(pack('>L', checksum)) > > (note : the same script run Ok with Python 2.4.3) > > One idea? it's a deprecation warning. the code runs under Python 2.5, but will probably break in future releases. check with the reportlab folks for updates. if you want to turn the messages off, use the filterwarnings function in the warnings module (see the docs for details). From fredrik at pythonware.com Thu Dec 14 01:40:01 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 07:40:01 +0100 Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: <1166063774.460600.17650@80g2000cwy.googlegroups.com> References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> <1166063774.460600.17650@80g2000cwy.googlegroups.com> Message-ID: rich murphy wrote: > Thank you both for responding. > > Yes of course the file has the ".py" extension and yes I went through > the tutorial. since everyone on this forum is importing modules successfully hundreds of times every day, that's not obvious at all. try running the interpreter as python -vv and see what it prints when you type import python_script From matt.hancock at jenrickcpi.co.uk Mon Dec 4 05:40:14 2006 From: matt.hancock at jenrickcpi.co.uk (Matt H) Date: 4 Dec 2006 02:40:14 -0800 Subject: Python Jobs Message-ID: <1165228814.663155.138260@f1g2000cwa.googlegroups.com> I'm writing from an IT Recruitment consultancy, I have an opportunity for either an experienced Python developer or someone looking to cross train in to Python in a permanent role. The role is based in the Amersham, Buckinghamshire for a small but well established software house. You will be required to develop a range of bespoke Web applications using a range of Object Orientated languages - Mainly Python. Candidates should be skilled in one or more of the following: OO, PHP, SQL/SQL Server Database Development Integration, XML. More information on application. Excellent opportunity to cross train in other development languages such as PostgreSQL and Python. Training provided. Call for more details - 01932 245500 Matt Hancock - Recruitment Consultant. matt.hancock at jenrickcpi.co.uk www.jenrickcpi.co.uk 01932 245500 From kentilton at gmail.com Mon Dec 11 14:08:19 2006 From: kentilton at gmail.com (Ken Tilton) Date: Mon, 11 Dec 2006 14:08:19 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> Message-ID: Harry George wrote: > "JShrager at gmail.com" writes: > > >>Kay Schluehr wrote: >> >> >>>is rapidly replacing Perl, and Ruby is simultaneously and even more >>>rapidly replacing Python. > > > Really? Given its small base, the percentage increases in Ruby use > (for any reason) can look quite impressive. I've see data suggesting > Ruby is replacing Perl and maybe Java. But I've yet to see data which > shows people dropping Python and moving to Ruby. Where do I find that > data? You missed it? Google fight: http://www.googlefight.com/index.php?lang=en_GB&word1=Python&word2=Ruby Python wins, 74 to 69.3. And there is no Monty Ruby to help. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From shejo284 at gmail.com Sun Dec 17 05:01:12 2006 From: shejo284 at gmail.com (Sheldon) Date: 17 Dec 2006 02:01:12 -0800 Subject: Core dump revisited Message-ID: <1166349672.479548.4460@80g2000cwy.googlegroups.com> Hi, I have a python script that uses a C extention. I keep getting a recurring problem that causes a core dump a few lines after the C extention return data back tp python. I tried using pbd and gdb but I have not succeeded in understanding what went wrong and where. I post the python script here is the error message and gdb output after reading the core file: ..... printout from with C extention.... Completed freeing 2D arrays. Now freeing 1D arrays freed 1D arrays freeing 15km arrays Complete Returning data back to Python! In python: assigning tuple data to numeric arrays! Time to do the coastal effects Segmentation fault (core dumped) ...... Now there next step after "Time to do the coastal effects" was never executed. And even if I put another print statement there the same thing happens. I am using python 2.3 and I have set my stacksize to unlimited. When reading the core dump file with gdb I get: gdb msgppscomp.py core.3203 GNU gdb 6.0-2mdk (Mandrake Linux) Copyright 2003 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i586-mandrake-linux-gnu"..."/data/proj_ns1/safworks/sheldon/msgppscomp.py": not in executable format: File format not recognized Core was generated by `python msgppscomp.py'. Program terminated with signal 11, Segmentation fault. #0 0x40079dfa in ?? () (gdb) ................. I am not very familiar with using gdb with python and C extentions. I would like to get some ideas about where the problem might be. I have made sure that all the arrays in the C extention are freed before exiting so I doubt that this might be the problem. Here is the python script: #!/usr/bin/env python #!-*-coding: UTF-8 -*- class WriteHdfFile: def __init__(self,outfile): self.outfile = outfile self.COMPRESS_LVL = 6 def writeAreainfo(self): import _pyhl import sys sys.float_output_precision = 2 aList = _pyhl.nodelist() aNode = _pyhl.node(_pyhl.GROUP_ID,"/PPS_MSG_COMP") aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/LAT") aNode.setArrayValue(1,lat.shape,lat,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/LON") aNode.setArrayValue(1,lon.shape,lon,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/VALCONCEN") aNode.setArrayValue(1,valconcen.shape,valconcen,"int",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/LIGHTCON") aNode.setArrayValue(1,lightcon.shape,lightcon,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS100") aNode.setArrayValue(1,bias100.shape,bias100,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS75") aNode.setArrayValue(1,bias75.shape,bias75,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS50") aNode.setArrayValue(1,bias50.shape,bias50,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS25") aNode.setArrayValue(1,bias25.shape,bias25,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/COAST") aNode.setArrayValue(1,coast.shape,coast,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/STATISTICS") aNode.setArrayValue(1,stats.shape,stats,"int",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/PERCENTAGE") aNode.setArrayValue(1,percentage.shape,percentage,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/VA_vs_BIAS") aNode.setArrayValue(1,va_area.shape,va_area,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/VANUM") aNode.setArrayValue(1,vanum.shape,vanum,"float",-1) aList.addNode(aNode) aNode = _pyhl.node(_pyhl.ATTRIBUTE_ID,"/NSCENES") aNode.setScalarValue(-1,areascenes,"int",-1) aList.addNode(aNode) aNode = _pyhl.node(_pyhl.ATTRIBUTE_ID,"/SATELLITE") aNode.setScalarValue(-1,satid,"string",-1) aList.addNode(aNode) self.status = aList.write(self.outfile,self.COMPRESS_LVL) return self.status #--------------------------------------------------------------------------------------------------------------------------- if __name__ == "__main__": from Numeric import * import sys, os, string, math, glob import msgppsarea,msgppscoast import shelve date = str(200510) #date = sys.argv[1] #s = sys.argv[2] cp = 'cfc' global valconcen,bias100,bias75,lightcon,bias50,bias25,percentage,va_area,lat,lon global stats,areascenes,satid,vanum,coast valconcen = zeros((324,243),'i') bias100 = zeros((324,243),'f') bias75 = zeros((324,243),'f') lightcon = zeros((324,243),'f') bias50 = zeros((324,243),'f') bias25 = zeros((324,243),'f') coast = zeros((324,243),'f') percentage = zeros((60,1),'f') va_area = zeros((90,1),'f') vanum = zeros((90,1),'f') lat = zeros((324,243),'f') lon = zeros((324,243),'f') stats = zeros((60,1), 'i') d = shelve.open("/data/proj/safworks/sheldon/MSG_PPS_COMP/c_codes/"+"_"+date+".shelve") msglist = d["Area.msglist"] tilescenes = d["Area.tilescenes"] tiles = d["Area.tiles"] ppslist = d["Area.ppslist"] lllist = d["Area.lllist"] areascenes = d["Area.areascenes"] d.close() print "Deleting file pointer and calling C function" RES = msgppsarea.msgppsarea(tilescenes,tiles,msglist,ppslist,lllist,int(date),areascenes) print "In python: assigning tuple data to numeric arrays!" for x in range(324): bias100[x] = (RES[0])[x*243:x*243+243] bias75[x] = (RES[1])[x*243:x*243+243] bias50[x] = (RES[2])[x*243:x*243+243] bias25[x] = (RES[3])[x*243:x*243+243] lat[x] = (RES[4])[x*243:x*243+243] lon[x] = (RES[5])[x*243:x*243+243] lightcon[x] = (RES[6])[x*243:x*243+243] valconcen[x] = (RES[7])[x*243:x*243+243] for x in range(90): va_area[x] = (RES[10])[x] vanum[x] = (RES[11])[x] for x in range(60): stats[x] = (RES[8])[x] percentage[x] = (RES[9])[x] print "Time to do the coastal effects" RES = msgppscoast.msgppscoast(ravel(bias100),tiles) for x in range(324): coast[x] = (RES[0])[x*243:x*243+243] outfile = "/data/proj/safworks/sheldon/MSG_PPS_COMP/results/"+'CFC'+'_'+ '_' + date + '.h5' print outfile chk = WriteHdfFile(outfile) res = chk.writeAreainfo() print "File written!" print "Complete!" ******************************** The C extention is very large so I will include it if anyone wants to see it. Thanks for any advice, Sheldon From erich.pul at blackbox.net Fri Dec 15 05:49:22 2006 From: erich.pul at blackbox.net (EHC) Date: 15 Dec 2006 02:49:22 -0800 Subject: concatenating strings Message-ID: <1166179761.991744.89630@j72g2000cwa.googlegroups.com> hello! since i am a py noob, please bear with me ; ) how is it possible to concat a string and an integer in a print-command? i've tried print "This robot is named %s. The current speed setting is %d, and %s has a lifetime of %d" % (self.name , self.speed , self.name) as well as print "This robot is named %s. The current speed setting is %d, and %s has a lifetime of %d" & self.name % self.speed % self.name though nothing works out... background is a class named Robot with members speed, name, etc... tia, Erich From steve at REMOVE.THIS.cybersource.com.au Sun Dec 10 11:44:11 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 11 Dec 2006 03:44:11 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165596641.245385.113090@f1g2000cwa.googlegroups.com> <1165704007.887869.192290@16g2000cwy.googlegroups.com> Message-ID: On Sun, 10 Dec 2006 14:35:07 +0000, Kirk Sluder wrote: > In article > , > Steven D'Aprano wrote: > >> And here I was thinking that languages fell from the sky like donuts! >> Gosh, thank you for explaining that too me. What a fool I must seem! > > Certainly that is what you wrote. If you had not meant that English > enforces restrictions on expressiveness, perhaps you should not have > written it. Okay, I'm trying to meet a common ground here, but you're not making it easy. Of course English, like all languages, restricts what can be said in that language. I'm talking about grammar and syntax, not semantics, just like I said at the beginning. I don't expect that there are concepts that can't be expressed in English (although some linguists disagree -- see the Sapir-Whorf hypothesis). But there are many restrictions on *how* we express things. That means that some concepts can't be expressed as briefly and succinctly in English as in other languages (and, naturally, vice versa). Oh, you might also like to look up what a straw-man argument is before continuing to accuse people of making it. There seems to be this myth on the Internet and Usenet that a straw-man argument is "any argument I don't like, or don't understand, or can't refute". > If we both agree that the rules of languages are social, then we > should both agree that in the case of programming language, > communities of language users help to constrain how the language is > used by rejecting extensions that are not lispy/pythonic, and > accepting extensions that converge with accepted style. That might be true in the case of public code which is open to the entire community, but it isn't true of all code. Not all code is open to the wider programmer community to inspect. Code gets written in small teams, or by individuals, and then it gets used by potentially millions of people who never got to review the code but have to suffer the consequences of any bugs in it. (I'm not saying this is uniquely a problem caused by Lisp macros. Don't misinterpret what I'm saying.) -- Steven. From rene at korteklippe.de Sun Dec 31 07:53:08 2006 From: rene at korteklippe.de (Rene Fleschenberg) Date: Sun, 31 Dec 2006 13:53:08 +0100 Subject: Are all classes new-style classes in 2.4+? In-Reply-To: <1167566224.439844.267250@42g2000cwt.googlegroups.com> References: <1167566224.439844.267250@42g2000cwt.googlegroups.com> Message-ID: <4597b2b4$0$18845$9b4e6d93@newsspool4.arcor-online.net> Isaac Rodriguez wrote: > I declare property members in both and it seems to work the exact same > way. I am using Python 2.4, and I was wondering if by default, all > classes are assumed to be derived from "object". No, they are not. It's just that the "basic functionality" seems to work the same at first glance (i.e. you don't need to learn alot of new syntax in order to switch from old-style to new-style classes). Play around with things like dir() and type() on old-style and new-style classes, and you will soon see differences. > If not, can someone > point me to some place where I can learn more about new-style classes > and their advantages? All the documentation I've found is very vague. http://www.python.org/download/releases/2.2.3/descrintro/ http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html -- Ren? OpenPGP key id: 0x63B1F5DB JID: rene.fleschenberg at jabber.ccc.de -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 204 bytes Desc: OpenPGP digital signature URL: From zondo42 at googlemail.com Thu Dec 14 09:24:38 2006 From: zondo42 at googlemail.com (Glenn Hutchings) Date: 14 Dec 2006 06:24:38 -0800 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> Message-ID: <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Fredrik Lundh wrote: > if you don't want to understand the design, nobody can force you. but arguing > that the people behind the design "don't get it" isn't very practical. I'm not arguing that at all. What I'm saying is that from the perspective of someone not interested in design issues, it seems like an omission for tuples to be missing the non-modifying methods that lists have. Glenn From john106henry at hotmail.com Mon Dec 25 10:45:08 2006 From: john106henry at hotmail.com (John Henry) Date: 25 Dec 2006 07:45:08 -0800 Subject: How to stop program when threads is sleeping In-Reply-To: <1167029711.446218.133930@f1g2000cwa.googlegroups.com> References: <1167029711.446218.133930@f1g2000cwa.googlegroups.com> Message-ID: <1167061507.974925.261420@73g2000cwn.googlegroups.com> many_years_after wrote: > Hi, pythoners: > > There is a problem I couldn't dispose. I start a thread in the my > program. The thread will do something before executing time.sleep(). > When the user give a signal to the main thread (such as click the 'end' > button or close the window), the thread should end it's running. But > how to end the threading when it's sleeping? I set an flag to the > thread, but it doesn't work. > > I also thought to put 'time.sleep()' to the main thread. But I > think the main thread will not response to user's action because it is > executing sleep(). > > Any ideas? > Thanks. The thread should not "sleep" - just take short "cat naps". The main should then set some kind of counter, and the thread check the counter between naps... From ratchetgrid at googlemail.com Fri Dec 15 17:34:40 2006 From: ratchetgrid at googlemail.com (Nathan Harmston) Date: Fri, 15 Dec 2006 22:34:40 +0000 Subject: Metaclass uses? Message-ID: <676224240612151434k12eccc5bh9f8efe419749886b@mail.gmail.com> Hi, Recently I posted a question about the factory pattern in python. I ve implemented this following one of the ideas posted. After some reading I ve seem a lot of Aspect Oriented Programming mentioned but I m not really sure what it is. Can anyone help me understand how metaclasses can improve the quality of my code and let me do better things. Also is there anymore interesting OO stuff that Python has apart from Java. Many Thanks Nathan From pgarrone at acay.com.au Tue Dec 19 04:34:53 2006 From: pgarrone at acay.com.au (pgarrone at acay.com.au) Date: 19 Dec 2006 01:34:53 -0800 Subject: Adding an instance to a data tree Message-ID: <1166520893.870234.283220@79g2000cws.googlegroups.com> Hi, I have a data tree. A node in the tree "assembles" itself when called upon to do so by the level-of-detail algorithm. It creates and adds its children to itself using a base class method called "add". However in the pseudo-constructor called "setup", the child node needs to be already linked into the tree in order to obtain configuration information. So the "add" method creates the child, optionally positions it within the parents frame of reference, then invokes the child's setup method which has variable length arguments. Here is an example of code in an assemble method. self.add("Reservoir", (Reservoir, r, r + self.inner_tank_thickness)) self.add("End_tank", (End_tank, r, self.outer_tank_radius), 0.5*self.payload_length + 0.5*self.outer_tank_thickness) self.add("Inner_end_tank", (End_tank, r, self.outer_tank_radius), -0.5*self.payload_length -0.5*self.outer_tank_thickness) self.add("Zero_G_port", Zero_G_port, 0.5*self.payload_length -0.5*self.zg_length) self.add("Hangar-floor", Hangar) self.add("herc", Hercules_shuttle, (0.5*self.payload_length - 25, R3d(180.0,V3d(0,1,0)))) self.add("herc1", Hercules_shuttle, (V3d(0,-12.5,0.5*self.payload_length - 25), R3d(180.0,V3d(0,1,0)))) The add method takes the parameters "name", child-information, and optional location-information. The child information is either a class, or a tuple whose first member is a class. The remaining members of the tuple are parameters to the class setup method. The problem is this: Sometimes the setup method parameters are quite numerous, leading to problems when the order is misjudged. If invoked directly, then naming parameters minimises the problems with missed parameters. However the indirect creation via the "add" method means the parameters are passed in a tuple, so the parameters cannot be named. How can I "pre-construct" the children with parent id and optional location information, and also implement the advantages of named function parameters? Looking for all suggestions. From Thomas.Ploch at gmx.net Wed Dec 20 07:32:54 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Wed, 20 Dec 2006 13:32:54 +0100 Subject: Fall of Roman Empire In-Reply-To: <873b7b6one.fsf@benfinney.id.au> References: <20061220054657.7CEEA1E4006@bag.python.org> <1166595864.797404.260570@n67g2000cwd.googlegroups.com> <873b7b6one.fsf@benfinney.id.au> Message-ID: <45892D76.2050002@gmx.net> Ben Finney schrieb: > "John Machin" writes: > >> Ben Finney wrote: >> >>> \ "...one of the main causes of the fall of the Roman Empire was | >>> `\ that, lacking zero, they had no way to indicate successful | >>> _o__) termination of their C programs." -- Robert Firth | >> An amusing .sig, but it doesn't address the root cause: As they had no >> way of testing for the end of a string, in many cases successful >> termination of their C programs would have been unlikely. > > Yet historically proven: the 'imperium' process they were running > terminated many centuries ago. > > Or did it fork and exec a different process? > And what about the C-Programs running in the middle of the sun or earth making them spinning around or having nuclear reactions controlled. I hope they won't terminate in the near future with exit status != 0 From basti.wiesner at gmx.net Wed Dec 20 04:26:10 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 20 Dec 2006 10:26:10 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Tim Roberts schrieb > "Gabriel Genellina" wrote: > >>On 16 dic, 04:47, Tim Roberts wrote: >>> > os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH >> >>>This will tell you that "x.exe" is executable, even if "x.exe" >>>contains >>> nothing but zeros. >> >>Isn't the same with any other recipe, portable or not? Unless the OS >>actually tries to load and examine the file contents, which the OS's >>I'm aware of, don't do. > > Yes, of course, you're right. I was about to delve into a > philosophical discussion about the difference in handling this between > Linux and Windows, but they're both just conventions. One is based on > an arbitrary flag, one is based on a file extension. Contents are > irrelevant. No, they aren't! Try this: [lunar at nargond]-[10:24:44] >> ~/test --> dd if=/dev/zero of=test.sh count=1 1+0 records in 1+0 records out 512 bytes (512 B) copied, 6.5e-05 seconds, 7.9 MB/s [lunar at nargond]-[10:24:46] >> ~/test --> chmod a+x test.sh [lunar at nargond]-[10:24:55] >> ~/test --> ./test.sh bash: ./test.sh: cannot execute binary file A file containing only zeros isn't executed... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From greg at cosc.canterbury.ac.nz Mon Dec 11 22:35:00 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 12 Dec 2006 16:35:00 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> Message-ID: <4u6meeF161jbqU1@mid.individual.net> Bill Atkins wrote: > You're missing Ken's point, which is that in Lisp an s-expression > represents a single concept - I can cut out the second form of an IF > and know that I'm cutting the entire test-form. For selecting a single form, that's true. For more than one form (such as selecting some, but not all, of the statements in a loop body) it's not much different. But my point was that I don't find "manually reindenting the lines" to be a chore. He made it sound like you have to laboriously go through and adjust the lines one by one, but it's not like that at all. You shift them all at once in a block. >>Having edited both Lisp and Python code fairly >>extensively, > > How extensively? Enough to know what I'm talking about. Tens of thousands of lines of Lisp and Scheme, and hundreds of thousands of lines of Python, I would estimate. Seeing as you asked, how much Python code have you or Ken edited? -- Greg From tomas at fancy.org Sat Dec 30 01:12:58 2006 From: tomas at fancy.org (Tom Plunket) Date: Fri, 29 Dec 2006 22:12:58 -0800 Subject: Starting a child process and getting its stdout? References: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> <7vl9p2h7f7adsbn6d6tfpmluera3njnb6g@4ax.com> <1167405767.308530.308800@48g2000cwx.googlegroups.com> Message-ID: Gabriel Genellina wrote: > Did you *actually* tried what Tom Plunket posted? Two tiny chars make > a difference. The sad irony is that before taking off for vacation I was struggling at work with the same problem in some sense. I couldn't figure out why for some processes I got all of the output right away and for others it all got queued up 'til the process ended. Working out a simple example for this thread showed the light: my calling of my_process.stdout.read() was blocking 'til EOF. Oops. -tom! -- From kay.schluehr at gmx.net Wed Dec 13 09:54:13 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 13 Dec 2006 06:54:13 -0800 Subject: Iterating over several lists at once References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> Message-ID: <1166021653.758763.14780@n67g2000cwd.googlegroups.com> Gal Diskin schrieb: > Hi, > I am writing a code that needs to iterate over 3 lists at the same > time, i.e something like this: > > for x1 in l1: > for x2 in l2: > for x3 in l3: > print "do something with", x1, x2, x3 > > What I need to do is go over all n-tuples where the first argument is > from the first list, the second from the second list, and so on... Heard about recursion? def collect(L,*lists): if not lists: return [(x,) for x in L] collection = [] for x in L: for y in collect(lists[0],*lists[1:]): collection.append((x,)+y) return collection for item in collect( l1, l2, l3): func(*item) Here is the same in generator form def collect(L,*lists): if not lists: for x in L: yield (x,) else: for x in L: for y in collect(lists[0],*lists[1:]): yield (x,)+y ( o.k - it required two nested for-loops in each implementation :) From slawomir.nowaczyk.847 at student.lu.se Tue Dec 12 19:07:09 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Wed, 13 Dec 2006 01:07:09 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165867527.389209.80660@f1g2000cwa.googlegroups.com> Message-ID: <20061213000024.5743.SLAWOMIR.NOWACZYK.847@student.lu.se> On Tue, 12 Dec 2006 10:30:40 -0700 Robert Uhl wrote: #> Imagine if one could write this in Python: #> #> defsyntax unless(condition, commands): #> if not condition: #> commands #> #> And use it like this: #> #> unless day == 'Sunday': #> work() #> #> That'd be pretty cool, right? Left... What is cool in this? Sure, I love "unless" in Lisp, where it save me a whole one pair of parentheses, but in Python both of those are equally readable if not day == 'Sunday' unless day == 'Sunday' and the first one is standard, while the second is not. #> As mentioned above, macros can make one's life significantly nicer. Sure. I sometimes (when writing code) wish we had macros in Python. I do know they can be useful. But then, when reading code, I am actually glad we do not have them. Their benefits in a language like Python would hardly pay off. #> Wouldn't it be nice to have a macro with-open-file? #> #> filefor line in path: #> foo(line) #> bar(line) #> baz(line) Not really. *If* this code bothers you, just do def with-open-file(path,fun): file = open(path,"r") for line in file: fun(line) file.close() def handle-line(line): foo(line) bar(line) baz(line) with-open-file("path",handle-line) Sure, it takes some time to get used to this, and at the beginning you really miss full-blown lambda, but it does have its own benefits. #> o Speed #> #> Lisp interpreters are several orders of magnitude faster than Python, #> and Lisp compilers are faster yet. Speed's not the most important #> thing, but it is _an_ important thing; all other things being equal, #> the faster solution is better. Sure. But in 20-30 years, Python might get there. #> o Symbols #> #> In Lisp, a symbol is essentially a hashed string; two symbols are alike #> if their names are alike, but comparison of symbols is a constant-time #> operation. Thus where in Python I have lots of string comparisons for #> constants, and in C I have #defined integers, in Lisp I have symbols. #> It's not just a performance hack--symbols are part of why macros and #> packages work--but when I miss them, I miss them for the performance #> side of things Well, you could fake symbols for most of the typical uses pretty easily... It won't look as good as it does in Lisp, but it will solve most problems. OTOH, if dictionary of strings is too slow, than maybe you are not using the right tool. #> o CLOS #> #> The Common Lisp Object System is a really remarkable piece of work. #> Among other things, it has generic functions instead of methods. E.g. #> in Python or most other OO languages object.method(arg1, arg2) is #> really just a fancy piece of syntactic sugar for method(object, arg1, #> arg2); method does different things depending on the type of object, #> its first argument. #> #> Wouldn't it be nice to be able to specialise a method on _any_ subset #> of its arguments, not just its first one? Well, CLOS offers that. #> (method object1 object2) could be specialised on the first argument, #> the second or both. This can be very powerful. There are modules for Python offering exactly that. However, the Pythonic solution is not to rely on types too much anyway, in the first place. #> Wouldn't it be nice to specify that some action be taken before or #> after a superclass's method, rather than over-riding that method #> entirely? Sure, one can over-ride the method and then call it within #> one's own code, but that obscures the meaning of what one's doing. You can easily create a decorator which will do just that. I suppose you could also create a metaclass which would do that, but it's too late for me to be sure ;) -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) The nice thing about standards is that there are so many of them to choose from. From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Tue Dec 12 15:32:05 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Tue, 12 Dec 2006 21:32:05 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> Message-ID: <4u8hu5F177u11U1@mid.individual.net> Robert Uhl wrote: > Because it's the language for which indentation is automatically > determinable. That is, one can copy/paste a chunk of code, hit a > key and suddenly everything is nicely indented. Cool, so in other languages I need to set block marks like () and {} and also indent the code for readability, and in Python I indent only. From my POV that's less work. Regards, Bj?rn Xpost cll,clp -- BOFH excuse #431: Borg implants are failing From fredrik at pythonware.com Thu Dec 21 07:34:12 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 21 Dec 2006 13:34:12 +0100 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Sebastian 'lunar' Wiesner wrote: >>>>>> no, I'm showing that a local file marked as executable overrides a >>>>>> shared one, even if the local file isn't actually an executable. >>>>> >>>>> Only if you have your system set up badly. The current directory >>>>> should not be in the search path, and it especially shouldn't have >>>>> higher priority than the regular bin locations. >>>> >>>> and the award for completely missing the context of this subthread >>>> goes to... >>>> >>> Nevertheless his comment was absolutely correct... >> >> nope. a Unix system uses the same flag to determine if a file is >> executable no matter how I've set up my path. > > Paul didn't even mention the word "executable". He was referring to > completely different thing: The fact, that whether a local executable > overrides a shared on, is matter of how you set your PATH. The local > file would be executable, whether it is in the PATH or not... are you trying to win some kind of award? From chandrasekar.kanagaraj at gmail.com Wed Dec 13 06:07:46 2006 From: chandrasekar.kanagaraj at gmail.com (chandrasekar.kanagaraj at gmail.com) Date: 13 Dec 2006 03:07:46 -0800 Subject: YouTube written in Python In-Reply-To: <457f58e5$0$27424$4d3efbfe@news.sover.net> References: <457f58e5$0$27424$4d3efbfe@news.sover.net> Message-ID: <1166008066.618948.28200@79g2000cws.googlegroups.com> Leif K-Brooks wrote: > Terry Reedy wrote: > > In a thread on the PyDev list, Guido van Rossum today wrote: > >> And I just found out (after everyone else probably :-) that YouTube is > >> almost entirely written in Python. (And now I can rub shoulders with > >> the developers since they're all Googlers now... :-) > > Interesting. I wonder what they're using for a Web framework? Of course, > sites that size generally use lots of custom stuff, but it would > presumably be based on something. awesome.Could you give the link where guido told this -Chandru From steve at rueb.com Tue Dec 5 12:55:20 2006 From: steve at rueb.com (Steve Bergman) Date: 5 Dec 2006 09:55:20 -0800 Subject: About the 79 character line recommendation Message-ID: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> As I study Python, I am trying to develop good, Pythonic, habits. For one thing, I am trying to keep Guido's the style guide in mind. And I know that it starts out saying that it should not be applied in an absolute fashion. However, I am finding that the 79 character line prescription is not optimal for readability. Certainly, cutting back from the length of lines that I used to use has *helped* readability. But if I triy very hard to apply 79, I think readability suffers. If this were just something that was an issue occasionally, I would just put it off to "know when to break the rules". However, find myself going to 90 to 100 characters very frequently. Now, if it were just me, I'd shoot for < 100. However, the Python philosophy includes making code easier for others to read, as well. So, I was wondering what more accomplished Python programmers thought about this. While I'm on this general topic, the guide mentions a pet peeve about inserting more than one space to line up the "=" in assignment statements. To me, lining them up, even if it requires quite a few extra spaces, helps readability quite a bit. Comments? Thanks, Steve Bergman From g.brandl-nospam at gmx.net Wed Dec 20 12:15:27 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Wed, 20 Dec 2006 18:15:27 +0100 Subject: Fall of Roman Empire In-Reply-To: References: <20061220054657.7CEEA1E4006@bag.python.org> <1166595864.797404.260570@n67g2000cwd.googlegroups.com> <873b7b6one.fsf@benfinney.id.au> <45892D76.2050002@gmx.net> Message-ID: Felix Benner schrieb: >> Sorry, somehow had to do this. Please slap me (i like it, don't worry) >> if it's totally stupid >> >> > > soooo totally stupid! You forgot the main function! (not to mention you > returned universe instead of everything) > > static int main(int argc, char **argv) { > char *god_name; > if (argc) > god_name = argv[1]; > else > god_name = "YHWH"; > metaPower God = getGodByName(god_name); > universe *everything = makeUniverse(God); > while (simulatePhysics(everything)); > return 0; > } Well, I'd expect God to be more clever as to do it that way. Could you imagine toying around with your universe in C? No, it must have been static PyObject * create_universe(char *god_name) { PyObject *universe; universe = PyObject_New(universetype, PyUniverse_Type); if (!universe) { PyErr_SetString(PyExc_CreationError, "Out of spacetime, or BDFL is too busy hacking " "on web-based collaboration tools"); return NULL; } universe->un_god = PyGod_FromName(god_name); universe->un_size = 0; universe->un_expand_rate = COSMOLOGICAL_CONSTANT; return universe; } Georg From aboudouvas at panafonet.gr Thu Dec 28 10:45:23 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 28 Dec 2006 07:45:23 -0800 Subject: db access Message-ID: <1167320723.501187.98810@h40g2000cwb.googlegroups.com> Hi to all, is there a way to use an RDBMS (in my case, SQL Server) from Python by using some built-in module of the language (v. 2.5) and through ODBC ?? I saw some samples that use statements like "import dbi" or "import odbc" but neither modules (dbi, odbc) are present on my system... Any hint(s) ?? Thanks in advance From tinodb at gmail.com Fri Dec 29 14:51:49 2006 From: tinodb at gmail.com (TiNo) Date: Fri, 29 Dec 2006 14:51:49 -0500 Subject: Help on installing Easy_Install Message-ID: <435b46e50612291151u5f36813ei1f70d26b7cafd0a9@mail.gmail.com> Hi, I'm having problems installing easy_install. When I run python ez_setup.py I get: G:\python>python ez_setup.py 'import site' failed; use -v for traceback Downloading http://cheeseshop.python.org/packages/2.5/s/setuptools/setuptools-0. 6c3-py2.5.egg Processing setuptools-0.6c3-py2.5.egg Copying setuptools-0.6c3-py2.5.egg to g:\python25\lib\site-packages Adding setuptools 0.6c3 to easy-install.pth file Traceback (most recent call last): File "ez_setup.py", line 217, in main(sys.argv[1:]) File "ez_setup.py", line 152, in main return main(list(argv)+[egg]) # we're done here File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1588, in main File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1577, in with_ei_usage File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1592, in File "F:\Python25\lib\distutils\core.py", line 151, in setup File "F:\Python25\lib\distutils\dist.py", line 974, in run_commands File "F:\Python25\lib\distutils\dist.py", line 994, in run_command File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 211, in run File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 427, in easy_install File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 473, in install_item File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 497, in process_distribution File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 373, in install_egg_scripts File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 569, in install_wrapper_scripts File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1480, in get_script_args File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1412, in get_script_header LookupError: no codec search functions registered: can't find encoding ?? What to do? thanks, TiNo From waldemar.osuch at gmail.com Sat Dec 23 15:58:18 2006 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: 23 Dec 2006 12:58:18 -0800 Subject: PyExcelerator: how to set colours? References: <1166801432.240441.178000@i12g2000cwa.googlegroups.com> Message-ID: <1166907498.063087.115480@42g2000cwt.googlegroups.com> Gerry wrote: > I'd like some cell to be a Blue "ABCDE". > > Here's come code thatv tries various values for pattern_for_colour and > font.colour_index, to no avail. > > Can anyone suggest the right way to set colours? > > Thanks! > > Gerry > > ====================== > > from pyExcelerator import * > > w = Workbook() > ws = w.add_sheet('alpha') > > style = XFStyle() > fore_colour = style.pattern.pattern_fore_colour > back_colour = style.pattern.pattern_back_colour > > ws.write (1, 1, "fore_colour") > ws.write (1, 2, fore_colour) > > ws.write (2, 1, "back_colour") > ws.write (2, 2, back_colour) > > text = "ABCDE" > > row = 5 > > > > for offset in range(-32,512): > > row += 1 > > style.font.colour_index = fore_colour + offset > > ws.write(row,3, fore_colour + offset, style) > > ws.write(row,5,text, style) > > style.pattern.pattern_fore_colour = fore_colour + offset > > ws.write(row,6,text, style) > > w.save('test.xls') > > ===================== > > shows no colour variation for any of these values of offset. Is this what you were after? -------------------------------------------------------------- from pyExcelerator import * w = Workbook() ws = w.add_sheet('boo') style = XFStyle() fore_colour = style.pattern.pattern_fore_colour back_colour = style.pattern.pattern_back_colour ws.write (1, 1, "fore_colour") ws.write (1, 2, fore_colour) ws.write (2, 1, "back_colour") ws.write (2, 2, back_colour) text = "ABCDE" row = 5 for offset in range(-32,512): row += 1 fnt = Font() fnt.colour_index = fore_colour + offset style.font = fnt ws.write(row, 3, offset, style) ws.write(row, 5, text, style) p = Pattern() p.pattern_fore_colour = fore_colour + offset p.pattern = style.pattern.SOLID_PATTERN style.pattern = p ws.write(row, 6, text, style) w.save('test.xls') -------------------------------------------------------------------------------- Waldemar From http Sat Dec 9 03:56:35 2006 From: http (Paul Rubin) Date: 09 Dec 2006 00:56:35 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> Message-ID: <7xodqdtpks.fsf@ruckus.brouhaha.com> Ken Tilton writes: > Not sure I understand why, unless you mean folks were raving about > Lisp in the 60s. Today's raving is about a much different language, > though the core elegance remains, and is as much about the contrast > with other languages as it is about the pleasure of Lisp itself. Those > raving about Lisp are quite accomplished at all those other languages, > and know about what they are talking. I doubt the Pythonistas weighing > in on this thread ever got far at all with Lisp, so... should they > really be offering comparative analysis? I've used and implemented Lisp but am not a real expert. Some other Python newsgroup regulars are very knowledgeable (more than me) about it. Peter Norvig (author of that comparison page) wrote a Lisp book, if I remember correctly. > > Personally, I never like Lisp syntax; Clearly some people, some > > fanatic judging by this thread :) think easily in prefix. I am not > > one of them. The syntax is a pretty superficial thing. The reaction from outsiders to Lisp's parentheses and Python's indentation-based structure is about the same. You get used to it either way. > The typical Pythonista values clean code but trembles in the face of > macros, which exist to hide boilerplate. That means the only thing > showing in any given block of code is exactly the interesting variable > and function names. Talk about readability. There is just not that much boilerplate in Python code, so there's not so much need to hide it. > Much of Lisp's power would be lost on a non-programmer, but Lisp might > make a programmer out of a non-programmer if they had it in them. You > might have the right language for you because what Python does have is > lotsa libraries, and if you are just hacking scripts to glue together > libraries the expressiveness of Lisp is more than offset by the better > library support in Python. Python is more expressive than Lisp in the sense that its built-in datatypes and simple syntax for using them has to be done through kludgy macros and libraries with Lisp. I would say Lisp's facilities for developing very large programs are better, and (for now) Lisp has much more serious compilers. See the PyPy project for what's happening in that direction with Python. From olsongt at verizon.net Fri Dec 1 12:56:09 2006 From: olsongt at verizon.net (olsongt at verizon.net) Date: 1 Dec 2006 09:56:09 -0800 Subject: good documentation about win32api ?? In-Reply-To: <1164988151.675036.308920@j44g2000cwa.googlegroups.com> References: <1164988151.675036.308920@j44g2000cwa.googlegroups.com> Message-ID: <1164995768.963594.206030@73g2000cwn.googlegroups.com> __schronos__ wrote: > Hi all. > > Recently I've to developed a project in python that made operation > under win32 platform and I found a lot of problema to find good > information. The only one documentation is in ActivePython page > (http://aspn.activestate.com/ASPN/docs/ASPNTOC-APYTH2.4.0) but it is > not very good and finally I had to turn to the newsgroups (it was very > nice). > > And the question is: ?Anybody knows where can I find good > documentation about win32api? > > Thanks in advanced. > > ScnS. http://msdn.microsoft.com covers the API itself, although you need to transliterate from the C code to python. From nagle at animats.com Wed Dec 27 16:22:03 2006 From: nagle at animats.com (John Nagle) Date: Wed, 27 Dec 2006 21:22:03 GMT Subject: urllib.urlopen unwanted password prompts - documentation problem Message-ID: <%tBkh.7619$yC5.4192@newssvr27.news.prodigy.net> If you try to open a password protected page with "urllib.urlopen()", you get "Enter username for EnterPassword at example.com:" on standard output, followed by a read for input! This seems to be an undocumented feature, if not a bug. Definitely the documentation for "urllib" should mention this. The effects of this in a CGI program are not good. A workaround is described here: "http://cis.poly.edu/cs912/urlopen.txt" "URLopener" and "FancyURLopener" in urllib have many overrideable functions, none of which are documented at python.org and should be. There was once documentation at http://epydoc.sourceforge.net/stdlib/public/urllib.FancyURLopener-class.html but its current status is: An error has been encountered in accessing this page. 1. Server: epydoc.sourceforge.net 2. URL path: /stdlib/public/urllib.FancyURLopener-class.html 3. Error notes: File does not exist: /home/groups/e/ep/epydoc/htdocs/stdlib/public/urllib.FancyURLopener-class.html 4. Error type: 404 5. Request method: GET 6. Request query string: 7. Time: 2006-12-27 13:18:11 PST (1167254291) Reporting this problem: The problem you have encountered is with a project web site hosted by SourceForge.net. This issue should be reported to the SourceForge.net-hosted project (not to SourceForge.net). John Nagle From paddy3118 at netscape.net Wed Dec 6 01:59:29 2006 From: paddy3118 at netscape.net (Paddy) Date: 5 Dec 2006 22:59:29 -0800 Subject: What are python closures realy like? References: Message-ID: <1165388369.552194.215440@79g2000cws.googlegroups.com> Karl Kofnarson wrote: > > Karl, > > > > Usually when using this idiom, fun_basket would return a tuple of all of the > > defined functions, rather than one vs. the other. So in place of: > >> if f == 1: > >> return f1 > >> if f == 2: > >> return f2 > > Just do > >> return f1, f2 > > (For that matter, the argument f is no longer needed either.) > > > > Then your caller will get 2 functions, who share a common var. You don't > > call fun_basket any more, you've already created your two "closures". Call > > fun_basket using something like: > > > > z1,z2 = fun_basket(None) > > > > And then call z1() and z2() at your leisure - they should have the desired > > behavior. > > > > -- Paul > > Thanks a lot Paul and for the other answers. The things are now > clear to me. In fact, in the Lisp example that I mentioned, you > get a list (or let it be association list) of the internal > functions. Then you can call them separately and they work as > you expect but it's due to the fact only that you got them created > at the same time. I played around a bit. The following is a 'borg' version in that there is only one counter shared between all calls of the outer function: >>> def fun_borg_var(initial_val=0): ... def borg_var_inc(x=1): ... fun_borg_var._n += x ... return fun_borg_var._n ... def borg_var_dec(x=1): ... fun_borg_var._n -= x ... return fun_borg_var._n ... try: ... fun_borg_var._n = fun_borg_var._n ... except: ... fun_borg_var._n = initial_val ... return (borg_var_inc, borg_var_dec) ... >>> up1, dn1 = fun_borg_var() # get an inc/decrementer >>> up1(0) 0 >>> up1() 1 >>> up1() 2 >>> dn1() 1 >>> dn1() 0 >>> dn1() -1 >>> up2, dn2 = fun_borg_var() # get another inc/decrementer >>> up2(0) # looks like the same _n -1 >>> up2(3) 2 >>> up1(3) 5 >>> - Paddy. From een-niet-bestaande-kleineaap at xs4all.nl Sun Dec 17 07:49:33 2006 From: een-niet-bestaande-kleineaap at xs4all.nl (Kleine Aap) Date: Sun, 17 Dec 2006 13:49:33 +0100 Subject: Control-C alternative in Windows References: <1166349442.480528.104810@f1g2000cwa.googlegroups.com> Message-ID: <45853d4d$0$19019$e4fe514c@dreader21.news.xs4all.nl> Vlad Dogaru wrote: > I've written a simple, standalone wiki server in Python. It runs a > BaseHTTPServer's serve_forever() method until a KeyboardInterrupt is > caught, at which point it writes changes to a file and exits. This > works as expected in Linux. However, in Windows I cannot stop the > script with Control-C. I've only been able to stop it with Ctrl-Break, > which does not send KeyboardInterrupt. This means no saving to the file > and effectively a useless script. Any ideas as to how I might make this > work in Windows? (http://www.python.org/download/releases/2.2.2/NEWS.txt): The signal module now supports SIGBREAK on Windows, thanks to Steven Scott. Note that SIGBREAK is unique to Windows. The default SIGBREAK action remains to call Win32 ExitProcess(). This can be changed via signal.signal(). For example: # Make Ctrl+Break raise KeyboardInterrupt, like Python's default Ctrl+C # (SIGINT) behavior. import signal signal.signal(signal.SIGBREAK, signal.default_int_handler) try: while 1: pass except KeyboardInterrupt: # We get here on Ctrl+C or Ctrl+Break now; if we had not changed # SIGBREAK, only on Ctrl+C (and Ctrl+Break would terminate the # program without the possibility for any Python-level cleanup). print "Clean exit" From noway at ask.me Wed Dec 13 09:58:58 2006 From: noway at ask.me (Giovanni Bajo) Date: Wed, 13 Dec 2006 15:58:58 +0100 Subject: Conditional iteration In-Reply-To: <4580149c$0$321$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> Message-ID: at wrote: > THE PROBLEM > > I have a lot times the following code: > > for x in [-2, -1, 0, 1, 2, 3, 4]: > if x > 0: > ... more code... > > > It is not the addional line containing 'if x > 0:' that bothers me, but the > additional indentation. for x in ...: if not x > 0: continue ... more code ... -- Giovanni Bajo From http Wed Dec 13 20:58:29 2006 From: http (Paul Rubin) Date: 13 Dec 2006 17:58:29 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> Message-ID: <7xac1r6xx6.fsf@ruckus.brouhaha.com> Ken Tilton writes: > pps. How would Python do this? Is it possible to avoid committing to > an implementation mechanism? Compare and contrast. k You'd just write a function. Python's expression syntax is comparable to a Lisp reader (you can have nested values of mixed types etc.) so you can use Python expressions to initialize pretty much anything. From hg at nospam.org Mon Dec 4 07:37:45 2006 From: hg at nospam.org (hg) Date: Mon, 04 Dec 2006 06:37:45 -0600 Subject: get script path References: <%7Uch.38012$1w6.17240@newsfe16.lga> Message-ID: hg wrote: > Hi, > > must I parse argv[0] to get it, or is there an easier way (that works > under Windows and *nix)? > > Ex: > > python /home/hg/test/test.py ==> test.py #knows it is in /home/hg/test > > Thanks, > > hg got it: os.path.dirname(sys.argv [0]) From bjourne at gmail.com Mon Dec 4 14:48:18 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 4 Dec 2006 19:48:18 +0000 Subject: Why not just show the out-of-range index? In-Reply-To: <45745C9E.9050500@v.loewis.de> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> <45745C9E.9050500@v.loewis.de> Message-ID: <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> On 12/4/06, "Martin v. L?wis" wrote: > Russ schrieb: > > I love Python, but every time I get an out-of-range error message, I > > wonder why it didn't just tell me what the out-of-range index was and > > what the allowable range was. Certainly that information must be > > available to the exception handler, or how would it know that it is out > > of range? > > Yes, that is true. The information is readily available. > > It's not true that it is "trivial" to fix, though: for every fix, there > ought to be a new test case also, and you have to run the test suite. > Depending on how fast a developer is, it may take between 30min and > 1hour to get a fix implemented (for the list case alone, not counting > all the other sequences). Maybe it is not as trivial as the OP thought, but it can't be that hard. It could be implemented as a utility function that does the index checking: bool PyObject_IsIndexOutOfBounds(PyObject *o, const char *ob_name, int i) { if (i < 0 || i >= o->ob_size) { char buf[256]; const char fmt[] = "%s index %d not in range(%d)" snprintf(buf, fmt, ob_name, i, o->ob_size); PyErr_SetString(PyExc_IndexError, buf); return true; } return false; } Then replace all code like: if (i < 0 || i >= a->ob_size) { PyErr_SetString(PyExc_IndexError, "string index out of range"); return NULL; } with: if (PyObject_IsOutOfBounds((PyObject *)a, "string", i) return NULL; Or maybe add "index" and "length" attributes to the PyExc_IndexError? "index" and "length" would of course be the invalid index and "length" the length of the container. That would be harder and probably involve some API change or something. Sorry I haven't thought this through 100%, but I don't see how actually _implementing it_ (getting it through the layers of bureaucracy may be harder) could be so difficult. > Even though I could fix it, I don't feel tempted to do so: I never had > this problem; in most cases of IndexError, it was very clear what the > problem was so I didn't need the additional information. For you yes, for a newbie the extra information would certainly be helpful. -- mvh Bj?rn From gagsl-py at yahoo.com.ar Fri Dec 1 20:41:59 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 01 Dec 2006 22:41:59 -0300 Subject: Thread help In-Reply-To: <4tbhffF13bmgrU1@mid.individual.net> References: <1164999221.679348.221000@16g2000cwy.googlegroups.com> <12n0v9l4ssfd7fc@corp.supernews.com> <4tbhffF13bmgrU1@mid.individual.net> Message-ID: <7.0.1.0.0.20061201223054.047f6528@yahoo.com.ar> At Friday 1/12/2006 17:26, Bjoern Schliessmann wrote: > >> I would make 3 threads for a client application. > > > You should use 4. > >I vote for just 1. We all know that the correct answer is, and always has been, 42 -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From craigtw.online at gmail.com Wed Dec 6 21:23:03 2006 From: craigtw.online at gmail.com (Craig) Date: 6 Dec 2006 18:23:03 -0800 Subject: Mirror imaging binary numbers In-Reply-To: References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> <1165446077.584437.206310@73g2000cwn.googlegroups.com> Message-ID: <1165458183.460029.182090@j72g2000cwa.googlegroups.com> Terry Reedy wrote: > "Craig" wrote in message > news:1165446077.584437.206310 at 73g2000cwn.googlegroups.com... > > Thanks so much for the response. I have an array of individual bytes > > which will eventually make up a binary bitmap image that is loaded onto > > an LCD screen (1 = black dot, 0 = white dot). At the moment each byte > > is reversed to what it should be (completely reverse the bit order): > > e.g 00111101 should be 10111100, 11001100 should be 00110011, etc. It > > is not an int problem as such, it is more a bit level swap if you get > > what I mean. If you could help that would be great. > > Using any of the solutions posted by others, I would first make a 256 byte > string in which each byte was the bit reversed version of its index. > > IE, bitrev = "\x00\x80\x40\xC0.....\xFF" > > Then your actual image processing is a simple, quick lookup for each byte. > > Terry Jan Reedy Thanks for all your great help guys. They work great. From webraviteja at gmail.com Tue Dec 5 01:41:18 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 4 Dec 2006 22:41:18 -0800 Subject: How to compile omniORBpy on Windows? In-Reply-To: <1165285769.974998.59740@73g2000cwn.googlegroups.com> References: <1165285769.974998.59740@73g2000cwn.googlegroups.com> Message-ID: <1165300878.091356.150670@73g2000cwn.googlegroups.com> OlafMeding at gmail.com wrote: > How do I compile omniORBpy 3.0 on Windows? The readme.txt file seems > to talk only about how to do this on Unix. Unfortenuately, I can not > use the binary because I need to use Python 2.3.5. (and the binary > requires that I use Python 2.4). > > I tried to copy the omniORBpy 3.0 source code to top\src\lib of omniORB > 4.1 and then tried to execute a "make export" in top\src (this did not > compile omniORBpy). I also tried a "make export" in > top\src\lib\omniORBpy-3.0 and this fails. > > Note, I was able to compile omniORB 4.1 on Windows w/o a problem. I am > using VS .NET 2003 (VC 7) on W2K. > > Many thanks for your help. This is certainly not the best advice. But how about just downloading an older release which did support Python 2.3 (unless you want the latest and greatest)? http://downloads.sourceforge.net/omniorb/omniORBpy-2.6-win32-python2.3.zip?modtime=1115987834&big_mirror=1 Hopefully you will get a more pertinent reply from the OmniORB mailing list :-). From timr at probo.com Thu Dec 7 01:20:04 2006 From: timr at probo.com (Tim Roberts) Date: Thu, 07 Dec 2006 06:20:04 GMT Subject: [Python] SMTP server based on Python? References: <1165440698.846121.318110@j44g2000cwa.googlegroups.com> Message-ID: <8icfn21alt4r2d6gqe6u852482p3uv1ptd@4ax.com> "Peter Smith [gjfc]" wrote: > >I have sendmail working on my linux box. > >Since I can use sendmail to send e-mails, would it be easy to write a >simple Python class which listens for data on port 25? > >Then, if it gets some data, it just passes it to sendmail. Ummm, I'm rather confused as to why you don't just have sendmail do this. After all, that is its primary function: to run as a daemon, listening on port 25, and delivering incoming messages to local mailboxes. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From paul at boddie.org.uk Fri Dec 8 11:30:16 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 8 Dec 2006 08:30:16 -0800 Subject: Subprocess with a Python Session? References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> <1165577596.239341.47550@16g2000cwy.googlegroups.com> Message-ID: <1165595416.086428.204710@l12g2000cwl.googlegroups.com> Fredrik Lundh wrote: > Paul Boddie wrote: > > > This is one of the more reliable methods since upon receiving a packet > > "delimiter" the receiver knows that the data is complete. > > and for people who want RELIABLE and not just "at least > not entirely unreliable", there's always: > > http://cr.yp.to/proto/netstrings.txt That's why I hedged my bets and put "one of the more" rather than "the most" in that sentence. ;-) I've been using netstrings myself, although I didn't know that they had that particular name. > (if you control both ends, there's hardly ever any reason not to use > netstrings. they're trivial to generate from Python, and pretty simple > to parse.). Indeed. Paul From nono at hotmail.com Thu Dec 28 02:48:53 2006 From: nono at hotmail.com (Osiris) Date: Thu, 28 Dec 2006 08:48:53 +0100 Subject: Combining C and Python References: Message-ID: <5mt6p25dip5r59d10cu6e847r4614mv9lh@4ax.com> On Wed, 27 Dec 2006 16:12:02 +0100, Osiris wrote: >I found this text about combining C-code with Pyton scripting on the >P2P networks in PDF: > >Python Scripting for Computational Science >Hans Petter Langtangen >Simula Research Laboratory >and >Department of Informatics >University of Oslo > > >amazon and others have it in print. >software for the text is here: >http://folk.uio.no/hpl/scripting/ > >if you want to download the 1st edition from >http://folk.uio.no/hpl/scripting/ >the password (first word on page 92) is "leads" (no quotes) > and for the second edition the password is "function" From vivainio at gmail.com Thu Dec 7 15:00:37 2006 From: vivainio at gmail.com (Ville Vainio) Date: 7 Dec 2006 12:00:37 -0800 Subject: IPython 0.7.3 beta 2 is out! Message-ID: Yes, next version of IPython is closing in on final release around the years end, with lots of new exiting features (full list TBD, but it *does* include proper python 2.5 support if that's what you've been waiting for). Get the 0.7.3 beta 2 it at http://projects.scipy.org/ipython/ipython/wiki/Release/0.7.3 And remember to run %upgrade if you are already using an older version. From martin at v.loewis.de Mon Dec 4 17:13:22 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 04 Dec 2006 23:13:22 +0100 Subject: Why not just show the out-of-range index? In-Reply-To: <1165258556.021281.51440@79g2000cws.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> <1165250963.660087.58410@n67g2000cwd.googlegroups.com> <45745F24.2010406@v.loewis.de> <1165258556.021281.51440@79g2000cws.googlegroups.com> Message-ID: <45749D82.4040301@v.loewis.de> rurpy at yahoo.com schrieb: >>> Rather, they (like I) will encourage to OP to submit >>> a patch that fixes the problem. >> Now, that would be rather silly. I would have to familiarize >> myself with the code for the Python interpreter, > > Seems to me he called the suggestion (made without any > knowlage of the OP's abilities regarding C and Python's > internals) that he summit a patch, silly. > > I aggree. > > His response was well within the bounds of normal > usenet discourse. Maybe I'm unusually picky, but I also feel insulted if my suggestions are called silly - this is just like calling myself silly. I rarely make silly suggestions deliberately (and try to mark them as ironic in usenet if I do); so if somebody puts them down as "silly", I'll feel insulted. I personally don't think it is silly to suggest that an IT professional becomes familiar with the implementation of the Python interpreter. That code is well-written, well-documented, so it should be feasible (rather than being silly) for anybody with a programming background and sufficient determination to familiarize with that code. I take the same position for about any open-source software: you *can* get into Apache, Mozilla, the Linux kernel, and now the Java virtual machine if you want to. If you don't, it's not because you can't, but because you don't want to. It would be unrealistic (but not silly) to suggest that if the source code weren't available at all. It is *not* silly to suggest that people should make efforts to contribute to open source software. Regards, Martin From gagsl-py at yahoo.com.ar Thu Dec 7 22:47:05 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 08 Dec 2006 00:47:05 -0300 Subject: Logging output from python In-Reply-To: References: <1165543315.696699.291910@j44g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061208004227.04048ee8@yahoo.com.ar> At Thursday 7/12/2006 23:21, Cameron Walsh wrote: > > Here is my problem. I want to log everything displayed in the screen > > after I start the main python script. Things include unhandled > > exceptions , message from print statement and other sources. > > Basically, if it is displayed on the screen, I want to log it.. > >If it's on linux you can just redirect the screen output to a file: > >python initialfile.py 1>stdout.txt 2>stderr.txt >[...] > >As for windows, I'll test it now... > >It turns out you can at least redirect the output to a file, I'm not >sure what it does with standard error or even if it exists or not. > >python initialfile.py > output.txt It's the same syntax as noted for linux above. 1> is the same as > alone. If ALL the testing is done on a single program (that is, no os.system or spawn or subprocess...) then you could just replace sys.stdout and sys.stderr with another open file (or file-like) object. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From duncan.booth at invalid.invalid Tue Dec 19 11:11:36 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Dec 2006 16:11:36 GMT Subject: Core dump revisited References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> <1166474110.001428.137260@80g2000cwy.googlegroups.com> <1166476940.590579.133460@73g2000cwn.googlegroups.com> <1166542176.142415.305720@48g2000cwx.googlegroups.com> Message-ID: "Sheldon" wrote: > I am new to this and copied this code from a colleague. So, it > corrupts the pointer. How do I do this properly? > Here is at least part of your problem: msgop = PyList_GetItem(work.msgobj, i); work.msg_scenes[i] = PyString_AsString(msgop); ppsop = PyList_GetItem(work.ppsobj, i); work.pps_scenes[i] = PyString_AsString(ppsop); ... free(work.pps_scenes[i]); free(work.msg_scenes[i]); You initialised msg_scenes and pps_scenes with a malloc'ed block but you then just overwrote the pointer with the result of PyString_AsString. You don't own the memory for the string returned from PyString_AsString, so freeing it will cause a corruption. You should copy the string data into the malloc'ed block (with appropriate length checks). From grahn+nntp at snipabacken.dyndns.org Fri Dec 15 10:53:38 2006 From: grahn+nntp at snipabacken.dyndns.org (Jorgen Grahn) Date: 15 Dec 2006 15:53:38 GMT Subject: One module per class, bad idea? References: Message-ID: On Tue, 12 Dec 2006 09:29:17 +0100, Matias Jansson wrote: > I come from a background of Java and C# where it is common practise to have > one class per file in the file/project structure. As I have understood it, > it is more common practice to have many classes in a Python module/file. > What is the motivation behind it, would it be a bad idea to have a guideline > in your project that promotes a one class per file structure (assuming most > of the programmers a background similar to mine)? Never mind their background; think about their future ;-) Besides, I think you have plenty of C and C++ hackers around, too. Seriously, I agree with what F Lundh wrote elsewhere in the thread; no need to repeat it here. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From mail at microcorp.co.za Sat Dec 16 00:18:23 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 16 Dec 2006 07:18:23 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> <87lklcrt00.fsf@thalassa.informatimago.com> <457fdb92$0$13245$426a74cc@news.free.fr> <45812f4c$0$26482$426a74cc@news.free.fr> <4ufelrF17of60U1@mid.individual.net> Message-ID: <019601c720db$0f2729e0$03000080@hendrik> "greg" > > I once heard mention of a system of units in use at > one time with the odd feature that capacitance came > out in units of length. > > Picture the scene: Hobbyist walks into Dick Smith > store and says "I'd like a 5cm capacitor, please." > This is correct - think of it as the number of electrons that can dance on the surface of a sphere of radius r. So your hobbyist will be handed a copper ball of 10cm diameter... Seriously, in electrostatic units, capacitance is measured in length. (or it was when they were trying to teach me Physics) - Hendrik From sonibergraj at youjoy.org Mon Dec 11 16:13:00 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Mon, 11 Dec 2006 22:13:00 +0100 Subject: How to do a Http HEAD requests Message-ID: <457DC9DC.9070803@youjoy.org> Hello list, I was just wondering if there is a more convenient way of doing a Http HEAD requests then the socket module? Any ideas? Cheers, -- Soni Bergraj http://www.YouJoy.org/ From Thomas.Ploch at gmx.net Sat Dec 23 17:54:34 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Sat, 23 Dec 2006 23:54:34 +0100 Subject: Fall of Roman Empire In-Reply-To: <2773CAC687FD5F4689F526998C7E4E5FF1EC5B@au3010avexu1.global.avaya.com> References: <2773CAC687FD5F4689F526998C7E4E5FF1EC5B@au3010avexu1.global.avaya.com> Message-ID: <458DB3AA.4090608@gmx.net> Delaney, Timothy (Tim) wrote: > Hendrik van Rooyen wrote: > >> naaah - you don't have to worry - for real control He uses assembler. >> with jump statements. >> so the loops are closed. >> >> Unfortunately its not open source. Yet. > > People are working hard on reverse-engineering it though. I hope no one > slaps them with a DMCA-style lawsuit ... > > Tim Delaney I heard Steve Ballmer recently made an offer to the pope for purchasing the license for an apple and an egg (Apfel und Ei). Thomas From bj_666 at gmx.net Wed Dec 6 09:42:16 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 06 Dec 2006 15:42:16 +0100 Subject: Am I stupid or is 'assert' broken in Python 2.5?? References: <1165415689.347819.129680@73g2000cwn.googlegroups.com> Message-ID: In <1165415689.347819.129680 at 73g2000cwn.googlegroups.com>, antred wrote: > Run the following code in your Python interpreter: > > myString = None > > assert( myString, 'The string is either empty or set to the None type!' > ) > assert( myString ) > > > > You'll notice that the first assert doesn't do anything, whereas the > second assert correctly recognizes that myString does not evaluate to > true. That doesn't seem right. Surely Python should have raised an > assertion error on the first assert statement, right?? ``assert`` is a statement, not a function. And non-empty tuples are "true": assert (False, 'boink') This is equivalent to ``assert True``. Ciao, Marc 'BlackJack' Rintsch From fredrik at pythonware.com Thu Dec 14 10:28:42 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 16:28:42 +0100 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: Nick Maclaren wrote: > If lists are intended to be homogeneous, then they should be checked > for that, and an exception raised when an attempt is to make them > non-homogeneous. so how would that check work, given that Python's type model is based on duck typing http://en.wikipedia.org/wiki/Duck_typing ? From ldo at geek-central.gen.new_zealand Mon Dec 25 00:52:55 2006 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 25 Dec 2006 18:52:55 +1300 Subject: Unescaping URLs in Python References: Message-ID: In message , John Nagle wrote: > Here's a URL from a link on the home page of a major company. > > About Us > > What's the appropriate Python function to call to unescape a URL > which might contain things like that? Just use any HTML-parsing library. I think the standard Python HTMLParser will do the trick, provided there aren't any errors in the HTML. > Will this interfere with the usual "%" type escapes in URLs? No. Just think of it as an HTML attribute value; the fact that it's a URL is a question of later interpretation, nothing to do with the fact that it comes from an HTML attribute. From tjreedy at udel.edu Mon Dec 4 16:32:56 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 4 Dec 2006 16:32:56 -0500 Subject: Why not just show the out-of-range index? References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com><1165210093.570351.288220@n67g2000cwd.googlegroups.com><1165211562.329647.164170@f1g2000cwa.googlegroups.com><45745C9E.9050500@v.loewis.de><740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> <1165264641.125857.85980@80g2000cwy.googlegroups.com> Message-ID: "Russ" wrote in message news:1165264641.125857.85980 at 80g2000cwy.googlegroups.com... > > Fredrik Lundh wrote: > >> > Sorry I haven't thought this through 100% >> >> obviously not. > > And you didn't like the "tone" of some of my earlier posts? While Fredrik's reply is a bit short, as is sometimes his habit, here are some things that appear to me to not have been thought through enough: 1. some negative indexes are legal. 2. replacing short inline code with a function call on *every* index lookup will slow down the interpreter a bit. 3. will the same check code work for even all built-in sequences? 4. how does index checking fit in with slice checking? By the way, it is already understood that error messages could be better, and I have thought about this one myself. You are not the first to notice, and improvements occasionally get submitted (and later accepted) by people with both the knowledge and motivation to do so. But insulting such people is not helpful. Terry Jan Reedy From sarcasticzombie at gmail.com Thu Dec 14 13:11:11 2006 From: sarcasticzombie at gmail.com (Sarcastic Zombie) Date: 14 Dec 2006 10:11:11 -0800 Subject: Over my head with descriptors Message-ID: <1166119871.508417.239060@n67g2000cwd.googlegroups.com> Code included below. Basically, I've created a series of "question" descriptors, which each hold a managed value. This is so I can implement validation, and render each field into html automatically for forms. My problem is this: every instance of my "wizard" class has unique self values, but they share the exact same descriptor values. Meaning, if t = Test("ar") y = Test("ar") t is y False t.age is y.age True t.age = 9 y.age 9 Code below. What am I not understanding? ----------------------------------------- import datetime, re class Question(object): def __init__(self, qtext, name, default=None, required=False, max_length=None, choices=None): self._name = name self._qtext = qtext self._value = default self._error = None self._max_length = max_length self._required = required self._choices = choices def __get__(self, instance, owner): return self def __set__(self, instance, value): error = self.validate(value) if not error: self._value = self.cast(value) self._error = None else: self._value = value self._error = error print error def __str__(self): return str(self._value) def __repr__(self): return str(self._value) def cast(self, value): return value def validate(self, value): return True def html(self): #ugly html renderer removed; irrelevant to problem return html def error(self): if self._error: return True class Q_Integer(Question): def validate(self, value): if self._required and not value: return "Field is required." elif not value: return None try: int(value) return None except: return "Answer must be a whole number." def cast(self, value): if value: return int(value) class Q_Float(Question): def validate(self, value): if self._required and not value: return "Field is required." elif not value: return None try: float(value) return None except: return "Answer must be a decimal number." def cast(self, value): if value: return float(value) class Q_Chars(Question): def validate(self, value): try: if self._required and not value: return "Field is required." elif not value: return None if self._max_length: if len(value) > self._max_length: return "Too many characters; max of %s allowed." % self._max_length return None except: return "Invalid entry." def cast(self, value): if value: return str(value) class Q_Long(Question): def validate(self, value): try: if self._required and not value: return "Field is required." elif not value: return None except: return "Invalid entry." def cast(self, value): if value: return str(value) def html(self): #ugly html renderer removed; irrelevant to problem return html class Q_Bool(Question): def validate(self, value): return None def cast(self, value): return bool(value) def html(self): #ugly html renderer removed; irrelevant to problem return html class Q_Phone(Question): def validate(self, value): try: if self._required and not value: return "Field is required." elif not value: return None pieces = value.split("-") if len(pieces[0]) == 3 and len(pieces[1]) == 3 and len(pieces[2]) == 4: int(pieces[0]) int(pieces[1]) int(pieces[2]) return None else: return "Requires Valid Phone Number in XXX-XXX-XXXX format." except: return "Requires Valid Phone Number in XXX-XXX-XXXX format." class Q_Date(Question): def validate(self, value): try: if self._required and not value: return "Field is required." elif not value: return None r = re.compile(r"\d{1,2}[-/.]\d{1,2}[-/.]\d{1,4}") month, day, year = r.findall(value)[0].replace("/","-").replace(".","-").split("-") date = datetime.date(year=int(year), month=int(month), day=int(day) ) return None except: return "Requires valid date in mm-dd-yy format." def cast(self, value): if value: r = re.compile(r"\d{1,2}[-/.]\d{1,2}[-/.]\d{1,4}") month, day, year = r.findall(value)[0].replace("/","-").replace(".","-").split("-") year = int(year) if year < 70: year += 2000 elif year < 100: year += 1000 date = datetime.date(year=int(year), month=int(month), day=int(day) ) return date def __str__(self): date = self._value return "%s/%s/%s" % (date.month, date.day, date.year) ## Wizard Base Object class Wizard(object): def __init__(self, action): self.action = action self.init_time = datetime.datetime.now() pagediv = "box" title = "A Dynamic Wizard" instructions = "There are no real instructions here. Sorry." grouping = [ ] def render_form(self): #ugly html renderer removed; irrelevant to problem return form def flatten(self, post): for key in post: if not key == "command": errors = "" cblock = "self.%s = '%s'\n" % (key, post[key]) ab_save = compile( cblock, errors, 'exec') exec(ab_save) def errorcheck(self): error = 0 for section in self.grouping: for question in section: t = eval( "self.%s.validate(self.%s._value)" % (question, question) ) if t: error = 1 return error C_CHOICES = ( ("red", "Red"), ("blue", "Blue"), ("green", "Green"), ) class Test(Wizard): grouping = [ [ 'age', 'weight' ], [ 'feet', 'inches' ], ['name', 'cash', 'fav_color', 'happy', 'birthday'] ] def __new__(self): age = Q_Integer("Your Age:", "age", 99) weight = Q_Integer("Your Weight:", "weight", 200) feet = Q_Integer("Feet tall:", "feet", 6) inches = Q_Integer("Inches Tall:", "inches", 0) name = Q_Chars("Your Name:", "name", max_length=15, required=True) cash = Q_Float("Money in hand?", "cash", required=True, default=55.50) fav_color = Q_Chars("Your favorite color?", "fav_color", required=True, max_length=50, choices=C_CHOICES) homezip = Q_Zip("Your zip code?", "homezip", required=True, ) happy = Q_Bool("Are you happy?", "happy", default=False) birthday = Q_Date("Your Birthday:", "birthday") From ejatwellkeeperdotcom Wed Dec 27 12:35:34 2006 From: ejatwellkeeperdotcom (Erik Johnson) Date: Wed, 27 Dec 2006 10:35:34 -0700 Subject: persistant gloabl vars (very newbie) ? References: Message-ID: <4592af12$1@nntp.zianet.com> "Stef Mientki" wrote in message news:bdff8$45929445$d443bb3a$5918 at news.speedlinq.nl... > Is there a way to run the initialization code from a script(file) once, > to achieve the same effect ? Certainly. This is what Python modules are all about. You should probably read up on those a bit here: http://docs.python.org/tut/node8.html But briefly, probably what you want to do is put some code in a file, say init.py: # init.py X = 3 Y = 5 # A bunch of other stuff And then in your main program, execute from init import * That will take all the module-scoped variables defined in init.py and place them in the namespace of the import statement (whcih could be global, the interactive interpreter, or otherwise) See also the 'global' statement as it relates to modifying global variables in an inner scope. Good luck, -ej From stefan.behnel-n05pAM at web.de Thu Dec 14 13:41:20 2006 From: stefan.behnel-n05pAM at web.de (Stefan Behnel) Date: Thu, 14 Dec 2006 19:41:20 +0100 Subject: subversion revision number string within an application packaged with distutils? In-Reply-To: <1165542556.714372.193340@n67g2000cwd.googlegroups.com> References: <1165542556.714372.193340@n67g2000cwd.googlegroups.com> Message-ID: <45819AD0.2050604@web.de> Jim Tittsler wrote: > Is there a standard recipe for getting the subversion revision number > into my Python-based application each time I package it up with > distutils? (Not just the package name, but also a string that I will > display in my app's "About" dialog.) Here's how we do it in lxml: https://codespeak.net/svn/lxml/trunk/versioninfo.py Stefan From steve at REMOVE.THIS.cybersource.com.au Tue Dec 26 19:06:49 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Wed, 27 Dec 2006 11:06:49 +1100 Subject: Persistent variables in python References: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> <1167174100.432143.163760@i12g2000cwa.googlegroups.com> Message-ID: On Tue, 26 Dec 2006 15:01:40 -0800, buffi wrote: >> def doStuff(some, arguments, may, *be, **required): >> try: >> doStuff.timesUsed += 1 >> except AttributeError: >> doStuff.timesUsed = 1 >> # ... special case for first call ... >> # ...common code... > > True, the recursivity is not needed there I guess :) > > It just feels so ugly to use try/except to enable the variable but I've > found it useful at least once. That's a matter of taste. Try replacing the try...except block with hasattr: def doStuff(): if hasattr(doStuff, timesUsed): doStuff.timesUsed += 1 else: doStuff.timesUsed = 1 do_common_code Here is another alternative, using the fact that Python creates default values for arguments once when the function is compiled, not each time it is run: def doStuff(some, *arguments, # don't mess with the following private argument __private={'timesUsed': 0, 'otherData': 'Norwegian Blue'}): """ Do stuff with some arguments. Don't pass the __private argument to the function unless you know what you are doing, it is for private use only. """ __private['timesUsed'] += 1 do_common_code -- Steven. From kentilton at gmail.com Sat Dec 9 22:41:12 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 22:41:12 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <7xejr8r86m.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > On Sat, 09 Dec 2006 14:55:13 -0800, Paul Rubin wrote: > > >>Steven D'Aprano writes: >> >>>Now, if you want to tell me that, despite all the talk, Lisp coders don't >>>actually create new syntax or mini-languages all that often, that they >>>just use macros as functions, then the question becomes: why do you need >>>macros then if you are just using them as functions? Why not use functions? >> >>Macros let you write what amounts to functions that don't evaluate >>their arguments. Think of the endless clpy wars over the ternary >>conditional operator. > > [snip] > >>That is trivial to do with a macro > > > I know that. It was more of a rhetorical question -- Lispers are either > trying to emphasis the radical nature of what you can do with macros, or > understate it and make them seem just like functions. Yep, both. The first is rare. CLOS is one, my Cells (ported this summer to PyCells as part of SoC 2006) is another. The latter is the norm. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From bedouglas at earthlink.net Fri Dec 1 13:27:00 2006 From: bedouglas at earthlink.net (bruce) Date: Fri, 1 Dec 2006 10:27:00 -0800 Subject: client/server design and advice In-Reply-To: <45706ec3$0$330$e4fe514c@news.xs4all.nl> Message-ID: <001901c71576$4b213460$0301a8c0@tmesa.com> hi irmen... happened to come across this post. haven't looked at pyro. regarding your 'work packets' could these essentially be 'programs/apps' that that are requested by the client apps, and are then granted by the dispatch/server app? i'm considering condor (univ of wisconsin) but am curious as to if pyro might also work. i'm looking to create a small distributed crawling app for crawling/scraping of targeted websites.... thanks -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net at python.org [mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf Of Irmen de Jong Sent: Friday, December 01, 2006 10:05 AM To: python-list at python.org Subject: Re: client/server design and advice TonyM wrote: > Lastly, as far as the networking goes, i have seen posts and such about > something called Pyro (http://pyro.sourceforge.net) and wondered if > that was worth looking into for the client/server interaction. I'm currently busy with a new version of Pyro (3.6) and it already includes a new 'distributed computing' example, where there is a single dispatcher service and one or more 'worker' clients. The clients request work 'packets' from the dispatcher and process them in parallel. Maybe this is a good starting point of your system? Current code is available from Pyro's CVS repository. --Irmen -- http://mail.python.org/mailman/listinfo/python-list From pyenos at pyenos.org Fri Dec 22 21:46:24 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 13:46:24 +1100 Subject: let me simplify my question on scope of vars References: <877iwjcttj.fsf@pyenos.pyenos.org> <87vek3be9e.fsf@pyenos.pyenos.org> <87ejqrqu8n.fsf@pyenos.pyenos.org> Message-ID: <87ac1fqqgv.fsf@pyenos.pyenos.org> Gabriel Genellina writes: > At Friday 22/12/2006 22:24, Pyenos wrote: > > > > > "code" > > > > var=1 > > > > class CLASS: > > > > def METHOD1: > > > > def METHOD2: > > > > var+=var > > > > return var > > > > METHOD2() #line8 > > > > return var > > > > METHOD1() #line10 > > > > "end code" > > > > > > > > Q1: does class CLASS inherit var=0 from line1? > > > yes. > > > > Q2: does def METHOD1 inherit var=0 from line1? > > > no. > > > > Q3: does def METHOD2 inherit var=0 from line1? > > > no. > > > > Q3: does line8 return '2'? > > > no. will get unreferenced var error. > > > > Q4: does line10 return '2\n2'? > > > no. will get unreferenced var error. > > > >Now I know that Q1 is also no, since var=1 from line 2 is a global > >variable and I have not declared it as global inside def METHOD2. so > >var within def METHOD2 is a different variable to the global variable var. > > Read the Python Pitfalls I've send some minutes ago, and the tutorial > (specially http://docs.python.org/tut/node11.html#scopes) and then > re-answer your own questions. > > > -- > 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 thanks for the helpful links. after consideration i think the code should be more sensible if it is written in this way: "code" var=1 def METHOD1(): METHOD2(): global var var+=var "end code" so that it is more clear which var it is using, which in this case should be from global var and not local var. From khemkaamit at gmail.com Sat Dec 16 01:04:12 2006 From: khemkaamit at gmail.com (Amit Khemka) Date: Sat, 16 Dec 2006 11:34:12 +0530 Subject: convert from date string to epoch In-Reply-To: References: Message-ID: <1360b7230612152204y44fa022fj2466a6e54e5b656f@mail.gmail.com> On 12/16/06, Stefan Antonelli wrote: > Hi, > > i have to convert several timestamps. The given format, eg "yyyy-mm-dd hh:mm:ss" > has to be converted to an epoch string. Is there any proper way to do this? > > If not, i have to split the given string and resolve this by a calculation? > > Thanks for help. > > Stefan. Check out timegm function in calendar module. The following function converts "mm/dd/yyyy" formats into epoch value, you can hack it for your date formats. def convertToEpoch(date): tup = map(int,date.split('/')) l = (tup[2], tup[0], tup[1], 0, 0, 0) epochs = calendar.timegm(l) return (int(epochs)) HTH, amit. -- ---- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. From gagsl-py at yahoo.com.ar Wed Dec 13 19:53:12 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 13 Dec 2006 21:53:12 -0300 Subject: speed of python vs matlab. In-Reply-To: <1166054840.646029.265880@73g2000cwn.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> Message-ID: <7.0.1.0.0.20061213213845.057a8a98@yahoo.com.ar> At Wednesday 13/12/2006 21:07, Chao wrote: >I've been trying to develop some numerical codes with python, however >got disappointed. > >A very simple test, > >a = 1.0 > >for i in range(1000): > for j in range(1000): > a = a+1 > >unfortunately, it took 4.5 seconds to finish(my machines is fine. P4 >3.0G, 1G RAM, it varies according to machine configuration, but should >be in the same level) How do you measure it? 4.5 secs is far too much. Anyway, try using xrange instead of range. This is the standard way to do timings: --- cut --- def test(): a = 1.0 for i in xrange(1000): for j in xrange(1000): a = a+1 if __name__=='__main__': from timeit import Timer t = Timer("test()", "from __main__ import test") print t.repeat(repeat=3,number=1) --- cut --- I got about 0.24 secs with far less hardware. For vector-oriented operations the NumArray package is well suited. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From chris at kateandchris.net Thu Dec 7 16:37:04 2006 From: chris at kateandchris.net (Chris Lambacher) Date: Thu, 7 Dec 2006 16:37:04 -0500 Subject: SOAP Server with WSDL? In-Reply-To: <45787179$0$15498$88260bb3@free.teranews.com> References: <45787179$0$15498$88260bb3@free.teranews.com> Message-ID: <20061207213704.GB19400@kateandchris.net> On Thu, Dec 07, 2006 at 12:49:09PM -0800, tobiah wrote: > I'm having trouble finding information > about writing a SOAP server. I get the client > part. There is much information about writing > a client, but not so much about writing the server. > Are there some good tutorials? > > I'm checking out: > > http://pywebsvcs.sourceforge.net/ > > But I'm a little confused. Do I want ZSI or SOAPY? You want ZSI. If you already have a wsdl you then use wsdl2py and wsdl2dispatch to create your server classes. The server classes get used with ZSI.ServiceContainer. Unfortunately there is not much documentation about this. I figured it out by playing with the tests that ship with ZSI. You might also want to check out ZSI the mailing list/archives which you can get to from the above link. > The site says: > > SOAPpy: A second web services toolkit which is getting > functionally integrated into the ZSI toolkit. In the > future, the Python Web Services Project will only support > one merged web services toolkit, under the ZSI name. > > This make me think that I will use ZSI in the future, > but what about now? Do I need both now? You only need ZSI. > > Thanks, > > Toby > > -- > Posted via a free Usenet account from http://www.teranews.com > > -- > http://mail.python.org/mailman/listinfo/python-list From rampeters at gmail.com Sun Dec 10 16:15:14 2006 From: rampeters at gmail.com (johnny) Date: 10 Dec 2006 13:15:14 -0800 Subject: mySql and multiple connection for threads In-Reply-To: References: <1165602188.976489.74760@j44g2000cwa.googlegroups.com> Message-ID: <1165785314.702238.274310@79g2000cws.googlegroups.com> Another question I have is, let say you get an exception and I want to write all exception into a log file. There is one log file, and 5 threads will be sharing. I need a way to lock it, write the log, and release the log file, so other threads can write to the logs. Can some one give me some pointers? From claird at lairds.us Fri Dec 8 11:29:50 2006 From: claird at lairds.us (Cameron Laird) Date: Fri, 8 Dec 2006 16:29:50 +0000 Subject: Window, Windows, Linux, client and server... References: <1165538336.320243.22740@l12g2000cwl.googlegroups.com> Message-ID: In article <1165538336.320243.22740 at l12g2000cwl.googlegroups.com>, MRAB wrote: . . . >I think he wants to be able to show the server desktop on a client (for >example, to show a user how to do something) and also be able to see a >client desktop on the server (for example, to see whether the user is >doing it correctly). > >Is there and easy way to switch between showing the server on a client >and seeing a client on the server? > Now I don't understand use of "server" and "client" in this thread. Would teleconferencing software that allows two users to see each others' desktops, or portions of them, suffice? I'll also repeat: in what ways does VNC fail to meet the requirements? From tinodb at gmail.com Fri Dec 29 14:28:10 2006 From: tinodb at gmail.com (TiNo) Date: Fri, 29 Dec 2006 14:28:10 -0500 Subject: bad marshal data in site.py in fresh 2.5 install win Message-ID: <435b46e50612291128m41d84b20oabac08d8af314f4a@mail.gmail.com> Hi, I have installed python two days ago on a USB memory stick (I am on the move and have no laptop.) I am on windows computers, mostly XP, all the time. Now, after pluging it in to a different computer, I get the following message when I run pyhthon: 'import site' failed; use -v for traceback python -v gives: ------------------------------------------------------------------------ G:\Python25>python -v # installing zipimport hook import zipimport # builtin # installed zipimport hook # G:\Python25\lib\site.pyc matches G:\Python25\lib\site.py import site # precompiled from G:\Python25\lib\site.pyc # G:\Python25\lib\os.pyc matches G:\Python25\lib\os.py import os # precompiled from G:\Python25\lib\os.pyc import nt # builtin # G:\Python25\lib\ntpath.pyc matches G:\Python25\lib\ntpath.py import ntpath # precompiled from G:\Python25\lib\ntpath.pyc # G:\Python25\lib\stat.pyc matches G:\Python25\lib\stat.py import stat # precompiled from G:\Python25\lib\stat.pyc # G:\Python25\lib\UserDict.pyc matches G:\Python25\lib\UserDict.py import UserDict # precompiled from G:\Python25\lib\UserDict.pyc # G:\Python25\lib\copy_reg.pyc matches G:\Python25\lib\copy_reg.py import copy_reg # precompiled from G:\Python25\lib\copy_reg.pyc # G:\Python25\lib\types.pyc matches G:\Python25\lib\types.py import types # precompiled from G:\Python25\lib\types.pyc import _types # builtin # zipimport: found 74 names in G:\Python25\lib\site-packages\setuptools-0.6c3-py 2.5.egg # G:\Python25\lib\locale.pyc matches G:\Python25\lib\locale.py import locale # precompiled from G:\Python25\lib\locale.pyc import encodings # directory G:\Python25\lib\encodings # G:\Python25\lib\encodings\__init__.pyc matches G:\Python25\lib\encodings\__ini t__.py import encodings # precompiled from G:\Python25\lib\encodings\__init__.pyc # G:\Python25\lib\codecs.pyc matches G:\Python25\lib\codecs.py import codecs # precompiled from G:\Python25\lib\codecs.pyc import _codecs # builtin # G:\Python25\lib\encodings\aliases.pyc matches G:\Python25\lib\encodings\aliase s.py 'import site' failed; traceback: Traceback (most recent call last): File "G:\Python25\lib\site.py", line 415, in main() File "G:\Python25\lib\site.py", line 406, in main aliasmbcs() File "G:\Python25\lib\site.py", line 356, in aliasmbcs import locale, codecs File "G:\Python25\lib\locale.py", line 14, in import sys, encodings, encodings.aliases File "F:\Python25\lib\encodings\__init__.py", line 32, in ValueError: bad marshal data # G:\Python25\lib\warnings.pyc matches G:\Python25\lib\warnings.py import warnings # precompiled from G:\Python25\lib\warnings.pyc # G:\Python25\lib\linecache.pyc matches G:\Python25\lib\linecache.py import linecache # precompiled from G:\Python25\lib\linecache.pyc Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> --------------------------------------------------------- What can I do about this? Thanks, TiNo From gagsl-py at yahoo.com.ar Tue Dec 26 17:47:08 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Tue, 26 Dec 2006 19:47:08 -0300 Subject: Persistent variables in python In-Reply-To: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> References: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061226193550.0201e480@yahoo.com.ar> At Tuesday 26/12/2006 19:13, buffi wrote: >def doStuff(): > try: > #Will throw exception if not set > doStuff.timesUsed > >Is this concidered bad coding practice since I guess persistent >variables in functions are not meant to be? I don't think so, since Python proudly says that functions are first-class objects. CherryPy does a similar thing to mark a method as "exposed". But perhaps I'd write the code this way to avoid an unneeded and risky recursive call: def doStuff(some, arguments, may, *be, **required): try: doStuff.timesUsed += 1 except AttributeError: doStuff.timesUsed = 1 # ... special case for first call ... # ...common code... If you need to code something special for the 2nd and following calls, add an else: clause -- 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 From bronger at physik.rwth-aachen.de Sun Dec 10 18:02:17 2006 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Mon, 11 Dec 2006 00:02:17 +0100 Subject: distutils: trouble with data_files + RPM Message-ID: <87mz5vpd6u.fsf@wilson.homeunix.com> Hall?chen! I try to distribute a Python application with i18n files (.mo). My setup.py says: ... data_files = [('share/locale/de/LC_MESSAGES', ['po/de/felo.mo'])], packages = ['felo'], package_dir = {'felo': 'src'}, The directory structure seen from setup.py is: ./setup.py po/ src/ This works perfectly with the bdist_dumb command. However, when I try to generate an RPM, it says: ... running install_data creating /var/tmp/Felo-1.0-1-buildroot/usr/share creating /var/tmp/Felo-1.0-1-buildroot/usr/share/locale creating /var/tmp/Felo-1.0-1-buildroot/usr/share/locale/de creating /var/tmp/Felo-1.0-1-buildroot/usr/share/locale/de/LC_MESSAGES error: can't copy 'po/de/felo.mo': doesn't exist or not a regular file error: Bad exit status from /var/tmp/rpm-tmp.6388 (%install) RPM build errors: Bad exit status from /var/tmp/rpm-tmp.6388 (%install) error: command 'rpmbuild' failed with exit status 1 What can I do about it? Thank you! Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646 (See http://ime.webhop.org for Jabber, MSN, etc.) From steve at REMOVE.THIS.cybersource.com.au Sat Dec 2 21:10:04 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 03 Dec 2006 13:10:04 +1100 Subject: converting dict to object References: <7649225.post@talk.nabble.com> <1165090584.103366.198220@l12g2000cwl.googlegroups.com> <1165107615.027458.199840@80g2000cwy.googlegroups.com> Message-ID: On Sat, 02 Dec 2006 17:00:15 -0800, John Machin wrote: > > Steven D'Aprano wrote: >> On Sat, 02 Dec 2006 12:16:24 -0800, John Machin wrote: >> >> > The OP might consider adding code to the __init__ method to check for >> > cases where the dictionary key is not a string containing a valid >> > Python identifier (not a keyword). >> > [snip] >> But if he's doing something like this: >> >> attributes = fetch_user_dict() >> # attribute names aren't known until runtime >> obj.__dict__.update(attributes) >> for key in attributes: >> print getattr(obj, key) >> >> then it is also redundant to check for valid identifiers, since getattr() >> doesn't need them. > > but getattr() needs strings. Well, that's true, but if the dict is being read from a file or with raw_input, the keys will naturally be strings. But even if it is some arbitrary dict, the keys still don't need to be checked for valid identifiers, merely checked for strings. And again, keeping the keys/values in a dict instead of converting to object attributes naturally solves that problem -- or rather, it isn't a problem that needs to be solved. Either way, I see no advantage to taking an arbitrary dict and converting it into object attributes. It sounds to me like "when the only tool you have is Java, everything looks like an object attribute" coding :-) I'd suggest that the "right" answer to the OP's original question "How do I convert a dict to object attributes?" is "Don't do that", regardless that it is technically possible. Maybe I'm wrong and there are lots of really handy uses for such a tactic. Can anyone suggest any? -- Steven. From nagle at animats.com Sun Dec 17 17:10:07 2006 From: nagle at animats.com (John Nagle) Date: Sun, 17 Dec 2006 22:10:07 GMT Subject: trees In-Reply-To: References: Message-ID: <3fjhh.34587$wP1.7292@newssvr14.news.prodigy.net> Delaney, Timothy (Tim) wrote: > vertigo wrote: > > >>Hello >> >>What library/functions/classes could i use to create trees ? SpeedTree, of course. http://www.speedtree.com They have great downloadable demos. John Nagle From gregm-xyzpdq3 at toadmail.com Sat Dec 9 07:21:49 2006 From: gregm-xyzpdq3 at toadmail.com (Greg Menke) Date: 09 Dec 2006 07:21:49 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > rpw3 at rpw3.org (Rob Warnock) writes: > > Weird. This is exactly why I use *Lisp* -- because it stays > > completely readable even if you don't use it on a daily basis!!! > > Hmm. I haven't used Lisp in a while and no longer find it so > readable. I haven't used Python in a while and don't find it especially readable. A number of years ago I was looking for a high level alternative to C++, I ran screaming from Perl. Python was better but I ended up preferring Lisp. Like Python's space indents, Lisp's parens disappear into the background once you learn how they work. Whats left is the language itself and I found Lisp worked more easily. > Lisp just seems hopelessly old-fashioned to me these days. A > modernized version would be cool, but I think the more serious > Lisp-like language designers have moved on to newer ideas. The trick is separating new ideas from fads or things that look new but are really incomplete reimplementations of older ideas. Frankly I have yet to find some language "feature" that doesn't exist in Common Lisp or one of the implementations- OTOH I use it to write software to get things done so my requirements are essentially practical rather than doctrinal. Gregm From jon at ffconsultancy.com Sun Dec 10 02:30:39 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 07:30:39 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> Message-ID: <457bb83f$0$8753$ed2619ec@ptn-nntp-reader02.plus.net> Ken Tilton wrote: > Steven D'Aprano wrote: >> Er, weren't you one of the people claiming that you don't notice parens >> when you're reading or writing Lisp code? > > Steve, you seem to be doing everything you can to make what is basically > a decent cultural exchange unpleasant... He has a point. Lispers always say that you can't see the superfluous parentheses after a month of staring at them, yet you must match them. I do prefer autoindenting though. Giving whitespace meaning seems like a second-rate alternative to me... -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From bearophileHUGS at lycos.com Tue Dec 26 07:45:50 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 26 Dec 2006 04:45:50 -0800 Subject: some OT: how to solve this kind of problem in our program? In-Reply-To: <1166974469.681026.101070@42g2000cwt.googlegroups.com> References: <458e4426$0$5286$4c368faf@roadrunner.com> <1166958490.785728.52430@h40g2000cwb.googlegroups.com> <1166974469.681026.101070@42g2000cwt.googlegroups.com> Message-ID: <1167137150.277210.110670@a3g2000cwd.googlegroups.com> For people that will read the posts in the future, there is a little bug (it doesn't change the output of this program): items = alist[:] Has to be: alist = alist[:] Sorry, bye, bearophile From agriff at tin.it Sat Dec 9 05:08:34 2006 From: agriff at tin.it (Andrea Griffini) Date: Sat, 09 Dec 2006 11:08:34 +0100 Subject: merits of Lisp vs Python In-Reply-To: <457a7ee5$0$49195$14726298@news.sunsite.dk> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> <1165593798.079105.144060@80g2000cwy.googlegroups.com> <45799841$0$49201$14726298@news.sunsite.dk> <1165609509.370461.122170@73g2000cwn.googlegroups.com> <457a7ee5$0$49195$14726298@news.sunsite.dk> Message-ID: <457a89f4$0$4242$4fafbaef@reader1.news.tin.it> Alex Mizrahi wrote: ... > so we can see PyDict access. moreover, it's inlined, since it's very > performance-critical function. > but even inlined PyDict access is not fast at all. ma_lookup is a long and > hairy function containing the loop. I once had a crazy idea about the lookup speed problem; can't the lookup result be cached in the bytecode ? I am thinking to something like saving a naked pointer to the value together with a timestamp of the dictionary. With timestamp I mean an integer (may be 64 bit) that is incremented and stamped in the dictionary every time the dictionary is modified; this counter can be shared among all dictionaries. The use of a naked pointer would be IMO safe because to invalidate the object you would also need to touch the dictionary. Using this approach the lookup for a constant string could be if (bytecode_timestamp == dict->timestamp) { // just use the stored result } else { // do standard lookup and store // result and dict->timestamp } I'd expect that this would be a big win for a lot of lookup as the problem with python speed is the *potential* dynamism... hopefully people don't keep changing what math.sin is during the execution so the vast majority of lookups at module level will find the timestamp being valid. This invalidation is not "optimal" as changing math.sin would also invalidate any lookup on math, but IMO a lot of lookups happen in *fixed* dictionaries and the the overhead of checking the cached result first should be small. What it would break is code that actually dynamically changes the string being looked up in the dictionary in the bytecode, but I hope those places are few if the exist at all. Is this worth investigation or it has already been suggested/tried ? Andrea From steve at REMOVEME.cybersource.com.au Thu Dec 28 04:40:17 2006 From: steve at REMOVEME.cybersource.com.au (Steven D'Aprano) Date: Thu, 28 Dec 2006 20:40:17 +1100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <4593185f$1@nntp.zianet.com> Message-ID: On Thu, 28 Dec 2006 09:26:28 +0100, Sebastian 'lunar' Wiesner wrote: > It is, and especially the problems with tabs shows you, why it is good > practice to follow the standard in your own code, too... I don't know what "problems" with tabs you are talking about. I never have problems with tabs. *Other people* who choose to use software that doesn't understand tabs have problems. I've spent a lot of time reading both sides of the tabs versus spaces argument, and I haven't found anything yet that explains why tabs are, in and of themselves, bad. -- Steven D'Aprano From mensanator at aol.com Sun Dec 3 22:01:19 2006 From: mensanator at aol.com (mensanator at aol.com) Date: 3 Dec 2006 19:01:19 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: <1165199260.872922.7420@j44g2000cwa.googlegroups.com> References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165194171.257951.89040@j44g2000cwa.googlegroups.com> <1165198036.545819.77820@79g2000cws.googlegroups.com> <1165199260.872922.7420@j44g2000cwa.googlegroups.com> Message-ID: <1165201279.200779.228440@79g2000cws.googlegroups.com> John Machin wrote: > mensanator at aol.com wrote: > > John Machin wrote: > > > Add "Syntax Error: invalid syntax" to the list ... > > > > But at least if you're using IDLE, the point of syntax error > > is highlighted. > > > > Same when using the interactive interpreter, the point of syntax error > is highlighted with a caret. However the highlighting of WHERE is > useless to people who don't have a clue WHAT the error is, and it needs > a forensic guru to suss it out as for example Peter Otten did, only > yesterday: > """ > Are you perhaps mixing tabs and spaces? > > >>> def f(): > > ... print "hello" # four spaces before 'print' > ... return 42 # one tab before 'return' > File "", line 3 > return 42 > ^ > SyntaxError: invalid syntax > """ Well, more information would be better, but at least it's not as bad as Windows: Application xxx could not be started because a required file could not be found. I know the name of the file but I am not going to tell you what it is. From fredrik at pythonware.com Mon Dec 4 17:27:51 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 23:27:51 +0100 Subject: decorators question In-Reply-To: <1165269784.394649.7940@l12g2000cwl.googlegroups.com> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> <457476E6.5000603@youjoy.org> <1165269784.394649.7940@l12g2000cwl.googlegroups.com> Message-ID: king kikapu wrote: > At first, i am coming from another (language) programming world (C# > mainly) and i hope you understand my wonders. > > Ok then, you tell me that the interpreter always execute the code in a > module...If there are only def declarations in the module and no code > to invoke them it does not execute anything. you're not listening. "def" is not a declaration, it's an executable statement, just like "print" and ordinary assignments and "import" and "class" and all the others. the "def" statement itself is *executed* to define the function; it takes the argument specification and the function code body, and creates a new function object. the resulting object is assigned to an ordinary variable. the only thing that differs if you add a decorator to the mix is that the function object is passed to the decorator function *before* it's assigned to a variable. From k04jg02 at gmail.com Fri Dec 8 22:41:58 2006 From: k04jg02 at gmail.com (k04jg02 at gmail.com) Date: 8 Dec 2006 19:41:58 -0800 Subject: How to create a global hotkey? References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com> <1165515363.838887.109720@80g2000cwy.googlegroups.com> <1165596216.573871.259350@l12g2000cwl.googlegroups.com> <1165598376.346246.137520@j44g2000cwa.googlegroups.com> Message-ID: <1165635718.819660.212170@j44g2000cwa.googlegroups.com> Paul Boddie wrote: > k04jg02 at gmail.com wrote: > > Sorry, I should have mentioned that I'm running Linux, and I only will > > be running this app while X is running. > > Global "hot keys" are typically the domain of the desktop environment > (or window manager for archaic desktops). Yep, that's why my first thought was to use PyQT or PyGTK. Unfortunately neither seems to have the ability. > So programmatically setting hot keys may be something that requires > communication with the desktop environment, and it would appear that on > KDE you have to put hot key definitions in a file and then import them, > the latter possibly being achieved using the DCOP interprocess > communications mechanism provided in the environment (try "dcop > khotkeys khotkeys" at the shell). This is really annoying to setup and would be a KDE specific solution. Ideally this would work under Gnome or KDE. Applications do this all the time -- Amarok for example adds global shortcuts for playing, pausing, jumping to next track, etc. that work whether or not you're in KDE or Gnome. > I suppose you could just plug in at the X level and have something > define and intercept a hot key before the desktop environment has a > chance to process it, but I doubt that this would be a particularly > nice solution. Why not? If I had to guess at this point I'd say it's the 'right' way to do it. I'm going to be dealing with keypresses that no other apps or the desktop environments have bound to anything, so I'm not sure it really qualifies as 'intercepting'. If multiple apps have registered to receive global keypresses, and the first app that looks at a keypress doesn't know how to handle it, shouldn't it just get passed on to the next app? From http Mon Dec 11 08:30:51 2006 From: http (Paul Rubin) Date: 11 Dec 2006 05:30:51 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <7xhcw2d0fo.fsf@ruckus.brouhaha.com> Jon Harrop writes: > F# runs under Linux with Mono. Interesting, where do I get it, and is there source? I've never been interested in Mono but maybe this is a reason. How does the compiled code compare to OCaml or MLton code? From bj_666 at gmx.net Sun Dec 3 10:50:19 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sun, 03 Dec 2006 16:50:19 +0100 Subject: Deleting from a list while iterating References: <1165160235.282030.96610@79g2000cws.googlegroups.com> Message-ID: In <1165160235.282030.96610 at 79g2000cws.googlegroups.com>, Rhamphoryncus wrote: > My approach is to make a set of indexes to removed while iterating, > then use a list comprehension to filter them out after. Timings of > this and two other common approaches follow: > > setapproach = """\ > def func(count): > from random import random > items = [random() for i in xrange(count)] > remove = set() > for index, x in enumerate(items): > #...do something... > if x < 0.5: > remove.add(index) > items = [x for index, x in enumerate(items) if index not in remove] > """ Why do you make it that complicated? If you are going to build a new list anyway, this can be done without the `set()` and just one listcomp: items = [x for x in items if x < 0.5] No need to iterate twice over the `items`. The two other approaches you gave are just needed if it's important that the elements are deleted "in place", i.e. that you don't rebind `items` to a new object. Ciao, Marc 'BlackJack' Rintsch From robert.kern at gmail.com Fri Dec 1 18:08:54 2006 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 01 Dec 2006 17:08:54 -0600 Subject: How do I print a numpy array? In-Reply-To: <12n1b51i11rhv5e@corp.supernews.com> References: <12n1b51i11rhv5e@corp.supernews.com> Message-ID: Grant Edwards wrote: > How do you print a numpy array? > > I tried the obvious print a, print `a`, and print str(a), but > none of them work on anything other than trivially small > arrays. Most of my real data is elided and replaced with > ellipses. You might want to ask numpy questions on the numpy list: http://www.scipy.org/Mailing_Lists Use numpy.set_printoptions(threshold=sys.maxint) to disable all summarization. -- 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 From guettli.usenet at thomas-guettler.de Wed Dec 6 07:16:52 2006 From: guettli.usenet at thomas-guettler.de (Thomas Guettler) Date: 6 Dec 2006 12:16:52 GMT Subject: len() and PEP 3000 Message-ID: <4tnqlkF13bbqeU1@mid.individual.net> Hi, The function len() is not mentioned in the Python 3000 PEPs. I suggest that at least lists, tupples, sets, dictionaries and strings get a len() method. I think the len function can stay, removing it would break to much code. But adding the method, would bu usefull. Yes, I know, that I can call .__len__() but that is ugly. I have read the FAQ to the len function: http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list -- Thomas G?ttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: niemand.leermann at thomas-guettler.de From sjmachin at lexicon.net Thu Dec 7 13:44:47 2006 From: sjmachin at lexicon.net (John Machin) Date: 7 Dec 2006 10:44:47 -0800 Subject: Need Help Parsing From File In-Reply-To: References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> Message-ID: <1165517086.976152.216270@16g2000cwy.googlegroups.com> Gabriel Genellina wrote: > At Thursday 7/12/2006 02:51, John Machin wrote: > > >Gabriel Genellina wrote: > > > > > > ftxt=open(filename,"rt") > > > >Never seen that done before. It's not in the docs. > > A remnant of my MSDOS+C background... > > >FWIW: > > > >Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > >(Intel)] on win > >32 > >Type "help", "copyright", "credits" or "license" for more information. > > >>> f = open('foo.txt', 'rt') > > >>> f = open('foo.txt', 'rs') > > >>> f = open('foo.txt', 'ratsdroppings') > ># Nary an exception raised, not the slightest murmur > > > >Is this a bug or a feature? Or is it one of those good old "unspecified > >behaviour" cases? MSVC rtl only? > > The Python docs say only that the initial letter is checked. And the > ANSI 89 C says that other characters may follow after r, r+, etc. > "rt" is useless for an ANSI C compiler, since the default stream mode > is "text" -on systems which differentiate between text and binary- > and irrelevant on systems which don't do such distinction. > (And since I got used to write "rt", Why did you do that? (1) Text mode is was and ever shall be the default, even with MS. (2) Seeing we're referring to docs and standards: Microsoft C 5.0 Optimizing Compiler, Run-Time Library Reference manual says "The t option is not part of the ANSI standard for open, but is a Microsoft extension and should not be used where ANSI portability is required". > you can infer something about > *when* I began to write C programs...) Youngster :-) Cheers, John From chris.cavalaria at free.fr Sun Dec 17 19:23:10 2006 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Mon, 18 Dec 2006 01:23:10 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> Message-ID: <4585df6e$0$11500$426a74cc@news.free.fr> Vincent Delporte wrote: > On Sun, 17 Dec 2006 09:37:04 +0100, luc at honk-honk.com (Luc Heinrich) > wrote: >>Crossplatform toolkits/frameworks suck. All of them. No exception. If >>you want your app to look *AND* feel great on all platform, abstract the >>core of your application and embed it in platform native GUI code. > > +1. Applications beyond very basic GUI's are better off rewriting the > GUI for each application, while keeping the business logic separate. > Even something as basic as QuickTime sucks on Windows. Read my second reply before reading that part again ;) > I'd be curious to see the source code to Skype: I just installed the > Linux version, and it looks very nice. Maybe it was recompiled with > Kylix. They use QT. Back to read the first part of your post. From furman at knology.net Sun Dec 31 08:50:21 2006 From: furman at knology.net (Furman Smith) Date: Sun, 31 Dec 2006 07:50:21 -0600 Subject: request for code : Py Tic Tac Toe in action Message-ID: <000001c72ce2$a232fcb0$6401a8c0@deskfurman> Hi elainejackson7355_at_home.com, I read "I played against your script and got a win, which, as you know, is not possible with optimal play by the opponent. A while ago I wrote a script that plays optimal tic-tac-toe. Let me know if you want to look at it." I would certainly appreciate the code. --furman === === === extra of little or no interest: I'm learning Python in order to analyze a game that I invented (the last article listed at http://www.integers-ejcnt.org/vol2.html ) called naught or cross. Neither player "owns" a symbol -- "x" or "o" -- but wins when achieving three of the same symbol in a tic-tac-toe line. When you place your symbol on the board you tell me which symbol I am to place. I place the assigned symbol where-ever I choose and then tell you which symbol to place. I started a hand analysis yesterday and it took hours to determine part of the game tree. I estimated, assuming other parts of the tree would take as much work, that I had about 750 times as much work left to do. So it is time to program -- which I love and I've been intending to learn Python anyway. I've taught Fortran and Pascal (and BASIC, AWK, Logo, etc) years ago and need to learn the object oriented approach. Perhaps your work will make it make sense. So far I'm thinking of a game position as a tuple where the first component shows the locations occupied by the symbol which is to be placed and the second component shows the locations of the other symbol. I'm using the following scheme for cell locations in order to simplify translating a position to a standard position (rotating by adding mod 8 to the outside cells and flipping by subtracting the outside cells from 8): 0 1 2 7 8 3 6 5 4 This is already more than you probably want to know but let me give an example. If you have just placed the piece that I've named and the board looks like o . . x o . x . . and you tell me to place an "x" (which is position (67,08) with x's specified in the first component, which is equivalent to standard position (12,08)) then I might place the x in the middle right and tell you to place an x on your move. Therefore the board looks like o . . x o x x . . and you are to place an x (this is equivalent to (367,08)). Since you wrote a Python program to play tic-tac-toe optimally, I bet that you will place your x in the lower right and tell me to place an o. So the position is o . . x o x x . x and I am to place an o. (a position equivalent to (08,3467)). You have me. No matter where I place the o and no matter whether I tell you to place an x or an o after that, you will be able to make three in a line. I found a neat Web page which was cached by Google, http://209.85.165.104/search?q=cache:jyTWvS7w5asJ:en.literateprograms.org/Ti c_Tac_Toe_(Python)+Py+Tic+Tac+Toe&hl=en&gl=us&ct=clnk&cd=10 , and I'm enjoying reading it but I'd appreciate seeing your approach also. From Leo.Kislov at gmail.com Sun Dec 17 21:05:50 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 17 Dec 2006 18:05:50 -0800 Subject: writing serial port data to the gzip file References: <1166403993.201955.63290@l12g2000cwl.googlegroups.com> Message-ID: <1166407550.026704.324080@79g2000cws.googlegroups.com> Petr Jakes wrote: > I am trying to save data it is comming from the serial port continually > for some period. > (expect reading from serial port is 100% not a problem) > Following is an example of the code I am trying to write. It works, but > it produce an empty gz file (0kB size) even I am sure I am getting data > from the serial port. It looks like g.close() does not close the gz > file. > I was reading in the doc: > > Calling a GzipFile object's close() method does not close fileobj, > since you might wish to append more material after the compressed > data... > > so I am completely lost now... > > thanks for your comments. > Petr Jakes > ==== snippet of the code ==== > def dataOnSerialPort(): > data=s.readLine() > if data: > return data > else: > return 0 > > while 1: > g=gzip.GzipFile("/root/foofile.gz","w") > while dataOnSerialPort(): > g.write(data) > else: g.close() Your while loop is discarding result of dataOnSerialPort, so you're probably writing empty string to the file many times. Typically this kind of loop are implemented using iterators. Check if your s object (is it from external library?) already implements iterator. If it does then for data in s: g.write(data) is all you need. If it doesn't, you can use iter to create iterator for you: for data in iter(s.readLine, ''): g.write(data) -- Leo From roman.yakovenko at gmail.com Thu Dec 21 07:45:34 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 21 Dec 2006 14:45:34 +0200 Subject: [ANN] pygccxml - 0.8.5 Message-ID: <7465b6170612210445l121932efobc62964c1f071a1f@mail.gmail.com> Hello! I'm pleased to announce the 0.8.5 release of pygccxml. What is pygccxml? ================= "...The purpose of the GCC-XML extension is to generate an XML description of a C++ program from GCC's internal representation. " -- Introduction to GCC-XML The purpose of pygccxml is to read a generated file and provide a simple framework to navigate C++ declarations, using Python classes. Where is pygccxml? ================== Site: http://language-binding.net/pygccxml/pygccxml.html Download: http://language-binding.net/pygccxml/download.html What's new? =========== Features -------- * Added new functionality: "I depend on them". Every declaration can report types and declarations it depends on. This functionality helps code generators. For example, Py++, the Boost.Python code generator, uses it to verify that all relevant declarations were exposed. * Declarations, read from GCC-XML generated file, could be saved in cache. Small features -------------- * New type traits have been added: * is_bool * Small improvement to algorithm, which extracts value_type ( mapped_type ) from "std" containers. * Few aliases to long method name were introduced. Bug fixes --------- * "signed char" and "char" are two different types. This bug was fixed and now pygccxml treats them right. Many thanks to Gaetan Lehmann for reporting the bug. * Fixing bug related to array size and cache. For a more complete list, please see the news: http://language-binding.net/pygccxml/history/history.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From gagsl-py at yahoo.com.ar Fri Dec 8 07:46:45 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 8 Dec 2006 04:46:45 -0800 Subject: why is this different? In-Reply-To: References: Message-ID: <1165582005.677639.292990@16g2000cwy.googlegroups.com> On 7 dic, 22:53, Sch?le Daniel wrote: > In [38]: f = [lambda:i for i in range(10)] > In [39]: ff = map(lambda i: lambda : i, range(10)) > In [40]: f[0]() > Out[40]: 9 > In [41]: f[1]() > Out[41]: 9 > In [42]: ff[0]() > Out[42]: 0 > In [43]: ff[1]() > Out[43]: 1 > > I don't understand why in the first case f[for all i in 0..9]==9 In the first case, i is a free variable. That means that Python will get it from other place (the global namespace, likely [surely?]) >>> f=[lambda:i for i in range(10)] >>> f[0]() 9 >>> i=123 >>> f[0]() 123 >>> print f[0].func_closure None In the second case, the inner i is a free variable, but local to its enclosing scope (outer lambda). It's a closure: >>> ff = map(lambda i: lambda : i, range(10)) >>> ff[4]() 4 >>> ff[4].func_closure (,) >>> i=321 >>> ff[4]() 4 > what is different from (more usefull) > > In [44]: f = ["%i" % i for i in range(10)] > In [45]: f > Out[45]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] This is a simple expression evaluated at each iteration > doing it like this works again > > In [54]: def d(x): > ....: return lambda:x > ....: x inside lambda is a free variable, but since it's local to d, this becomes a closure: >>> d(1) at 0x00A35EF0> >>> d(1).func_closure (,) > In [55]: f = [d(i) for i in range(10)] > In [56]: f[0]() > Out[56]: 0 > In [57]: f[1]() > Out[57]: 1 This is similar to the ff example above > in a C programmer sence I would say there seems to be no "sequence > point" which would separate "now" from "next" No, the problem is that C has no way to express a closure; this is a functional concept absolutely extraneous to the C language. -- Gabriel Genellina From gagsl-py at yahoo.com.ar Fri Dec 15 05:03:47 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 15 Dec 2006 07:03:47 -0300 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1166176004.011535.157230@f1g2000cwa.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> <1166046193.734274.124160@73g2000cwn.googlegroups.com> <1166176004.011535.157230@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061215065312.0541c5a0@yahoo.com.ar> At Friday 15/12/2006 06:46, mohan wrote: >To revert back to my question, I wanted to add a new path to my >PythonWin IDE to access modules which are in folders other than normal >python paths. Here, I need to put my modules in different folders >since it is a request of the user. I tried to create a new PYTHONPATH >in the environmental variables section, which did not work . You can do that directly inside PythonWin, using the Tools menu. >So, is there any way where I can temporarily append the new path/s, >where the PythonWin interpreter would look during run time and discard >after the interpreter is closed. You could modify sys.path at runtime, appending directories if needed. But the package solution below is much better. >For example, my main program "ATS.py" will be put in the folder >D:\\dSPACE\ATS\ and my modules will be put in other folders inside the >folder ATS, D:\\dSPACE\ATS\ Level Regulation, D:\\dSPACE\ATS\ Curve >Detection and so on. > >So, I would like to tell the interpreter to look in to these folders to >import the modules. First, remove all spaces from directory names. Then make them normal packages (an empty __init__.py may be enough) so you can write, in ATS.py: from LevelRegulation import whatever from CurveDetection.MyModuleName import MyClass etc. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From greg at cosc.canterbury.ac.nz Tue Dec 12 22:06:03 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 13 Dec 2006 16:06:03 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1165913743.943676.5910@79g2000cws.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <1165913743.943676.5910@79g2000cws.googlegroups.com> Message-ID: <4u9948F16igllU1@mid.individual.net> Juan R. wrote: > I see no dinamism on your example, just static overloading. There's nothing static about it: q = raw_input() if q == "A": a = 1 b = 2 else: a = "x" b = "y" c = a + b There is no way that the compiler can statically determine what the + operator needs to do here. -- Greg From gagsl-py at yahoo.com.ar Tue Dec 5 16:27:57 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Tue, 05 Dec 2006 18:27:57 -0300 Subject: Does this always go right In-Reply-To: References: Message-ID: <7.0.1.0.0.20061205182010.03eba038@yahoo.com.ar> At Tuesday 5/12/2006 12:04, Carl.Wolff at imtech.nl wrote: >question about copy vs deepcopy used in multithreaded context: > >suppose the following program below: > >the original dictionary is modified after the thread is started, the >thread works on a copied and deepcopied version of the original >dictionary. Is the dictionary named "originalcopy" isolated from >changes in original in multithreaded context? > >The program reports no errors but I want to be really sure about this For your simple test dictionary, copy and deepcopy behaves identically. If you wish, you should test using values that are containers themselves. With or without threads, modifying original (with the current contents) would never modify originalcopy neither originaldeepcopy, so you aren't testing anything here. Try rewriting your test. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From nick at craig-wood.com Tue Dec 19 14:30:05 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 19 Dec 2006 13:30:05 -0600 Subject: Core dump revisited References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> <1166474110.001428.137260@80g2000cwy.googlegroups.com> <1166476940.590579.133460@73g2000cwn.googlegroups.com> <1166542176.142415.305720@48g2000cwx.googlegroups.com> Message-ID: Sheldon wrote: > Man. You are good. This is most insight I have had from anyone. :-) > I did initialize the arrays with PyObjects and today, after hours of > debugging and now with your insight, I think the problem lies here: Good! You need to release some python references otherwise you'll have a memory leak and copy some strings you don't own It is worth reading the definitions for those functions in the Python API docs http://docs.python.org/api/api.html In particular read about reference counts. With the Python C API you have to know at all time (by reading the doc) whether you own the reference or not, and whether you own the memory or not. > /* here a python list of strings is read into a C string array */ > static int readPythonObject(void) { > > int i; > PyObject *msgop; > PyObject *ppsop; > PyObject *tileop; > PyObject *sceneop; > > for (i = 0; i < work.sumscenes; i++) { > msgop = PyList_GetItem(work.msgobj, i); > work.msg_scenes[i] = PyString_AsString(msgop); work.msg_scenes[i] = strdup(PyString_AsString(msgop)); Py_DECREF(msgop); > ppsop = PyList_GetItem(work.ppsobj, i); > work.pps_scenes[i] = PyString_AsString(ppsop); work.pps_scenes[i] = strdup(PyString_AsString(ppsop)); Py_DECREF(ppsop); > } > for (i = 0; i < NumberOfTiles; i++) { > tileop = PyList_GetItem(work.tileobj, i); > work.tiles[i] = PyString_AsString(tileop); work.tiles[i] = strdup(PyString_AsString(tileop)); Py_DECREF(tileop); > sceneop = PyList_GetItem(work.nscenesobj, i); > work.nscenes[i] = PyInt_AsLong(sceneop); Py_DECREF(sceneop); > } > return 1; > } /*end readPythonObject*/ You free() the strings later which is fine. The above ignores errors which PyList_GetItem may return and strdup() returning 0, but it should get you out of trouble hopefully. ... I've written lots of quite similar code, here is a snippet. Note the comments about who owns the reference, and the error checking. Also note xstrdup() which is a strdup() which blows up if no memory is available. [snip] PyObject *item = PySequence_GetItem(value, i); /* real ref */ if (item == 0) { fprintf(stderr, "Failed to read '%s[%d]' attribute\n", name, i); goto err; } item_cstr = PyString_AsString(item); /* borrowed */ if (item_cstr == 0) { fprintf(stderr, "Failed to read '%s[%d]' as string\n", name, i); goto err; } label[i] = xstrdup(item_cstr); Py_DECREF(item); item = 0; [snip] err:; PyErr_Print(); out:; if (value) Py_DECREF(value); if (item) Py_DECREF(item); return rc; -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ptmcg at austin.rr._bogus_.com Tue Dec 26 17:24:21 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 26 Dec 2006 16:24:21 -0600 Subject: some OT: how to solve this kind of problem in our program? References: <458e4426$0$5286$4c368faf@roadrunner.com><1166958490.785728.52430@h40g2000cwb.googlegroups.com><1166974469.681026.101070@42g2000cwt.googlegroups.com><45906bab$0$27094$4c368faf@roadrunner.com> Message-ID: <4591a11a$0$8949$4c368faf@roadrunner.com> "Gabriel Genellina" wrote in message news:mailman.2030.1167165642.32031.python-list at python.org... > At Monday 25/12/2006 21:24, Paul McGuire wrote: > >>For example, for all the complexity in writing Sudoku solvers, there are >>fewer than 3.3 million possible permutations of 9 rows of the digits 1-9, >>and far fewer permutations that match the additional column and box >>constraints. Why not just compute the set of valid solutions, and compare >>an input mask with these? > > Are you sure? There are 9!=362880 rows of digits 1-9; taking 9 of these at > random gives about 10**50 possibilities. Of course just a few match the > additional constraints. Maybe you can trivially reduce them (just looking > for no dupes on the first column) but anyway its a laaaaarge number... (Or > I'm wrong computing the possibilities...) > > > -- > Gabriel Genellina > Softlab SRL Der, I was thinking 9 times 362880, not 326880 P 9. Thanks for straightening me out! 10**50 was a good ballpark guess. My permutation calculator says that 362880 items taken 9 at a time yields 109099864394915605737486658299863377337267988480000 permutations (~10**50). I assume the smaller Wikipedia number (6.7*10**21) factors in the additional column and box constraints. So I guess we can rule out brute force as a viable strategy after all. -- Paul From martin at v.loewis.de Mon Dec 4 12:44:36 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 04 Dec 2006 18:44:36 +0100 Subject: Why not just show the out-of-range index? In-Reply-To: <1165223084.558617.9570@79g2000cws.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> Message-ID: <45745E84.40101@v.loewis.de> Russ schrieb: > My suggestion that it would be much easier for the Python maintainers > than for me to implement the requested feature is just basic common > sense. I would have to spend many hours or days just to familiarize > myself with the code, but they are obviously already very familiar with > it. That is all true. However, you seem to be implying that therefore, it is the Python maintainers who ought to fix this. That implication is faulty. Not everything that somebody could do better than you should be done by that other person - some things you have to do yourself if you want to see them done. All Python contributors (including the maintainers) are volunteers, none of us is paid. Volunteers tend to do what they have fun doing or what scratches their own itches. This is just how free software works. > And they would probably have to spend nearly as much time checking > my patch as they would writing it themselves anyway. No: if you already have done the testing, and provided test cases to test it, this is fairly easy to review. Regards, Martin From carsten at uniqsys.com Mon Dec 25 11:22:55 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 25 Dec 2006 11:22:55 -0500 Subject: How to stop program when threads is sleeping In-Reply-To: <1167029711.446218.133930@f1g2000cwa.googlegroups.com> References: <1167029711.446218.133930@f1g2000cwa.googlegroups.com> Message-ID: <1167063775.3389.12.camel@dot.uniqsys.com> On Sun, 2006-12-24 at 22:55 -0800, many_years_after wrote: > Hi, pythoners: > > There is a problem I couldn't dispose. I start a thread in the my > program. The thread will do something before executing time.sleep(). > When the user give a signal to the main thread (such as click the 'end' > button or close the window), the thread should end it's running. But > how to end the threading when it's sleeping? I set an flag to the > thread, but it doesn't work. Is the thread supposed to do some additional work after being woken up? If not, there is no point in going to sleep in the first place and the thread should just terminate when it has completed its task. If yes, I'd use a threading.Event object to .wait() on in the sub-thread rather than putting it to sleep, and then .set() the event object in the main thread when it's time to wake up the sub-thread. Hope this helps, Carsten. From http Tue Dec 19 04:03:48 2006 From: http (Paul Rubin) Date: 19 Dec 2006 01:03:48 -0800 Subject: trouble getting google through urllib References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> Message-ID: <7xpsagz28b.fsf@ruckus.brouhaha.com> "Dr. Locke Z2A" writes: > Does anyone know how I would get the bot to have permission to get the url? That's what this was for: http://code.google.com/apis/soapsearch/ From dingbat at codesmiths.com Tue Dec 12 06:06:45 2006 From: dingbat at codesmiths.com (Andy Dingley) Date: 12 Dec 2006 03:06:45 -0800 Subject: One module per class, bad idea? In-Reply-To: References: Message-ID: <1165921605.934475.71560@16g2000cwy.googlegroups.com> Matias Jansson wrote: > I come from a background of Java and C# where it is common practise to have > one class per file in the file/project structure. Don't confuse packages and files. Java commonly splits a package across many files, Python binds a module to a single file. If you see "Java package" as more comparable to "Python module" then the difference in how many classes are in a file becomes unimportant. Java also puts many classes in the same source file, if they're tightly coupled (e.g. Swing UI). It spits them out into separate .class files though. From address.good.until.2006.dec.22 at justmail.de Fri Dec 15 13:27:03 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=) Date: Fri, 15 Dec 2006 19:27:03 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> Message-ID: Neil Cerutti schrieb: > That's not a real difficulty, is it? > > CL-USER> (mapcar #'(lambda (x) > (funcall (nif x p z n))) > '(0 2.5 -8)) Didn't you forget the #' before p, z and n? >> CL-USER> (mapcar #'(lambda (x) >> (nif x (p) (z) (n))) >> '(0 2.5 -8)) >> >> "no no" >> "very positive" >> "very negative" >> ("zero" "positive" "negative") >> >> And the first example also still works the same way. > > That's the part that Python doesn't naturally provide, and I > believe, Python programmers don't usually want. Then I have the solution: they can build their own functional if. Instead of if x > 10: do() something() else: foo() They can say: def blah1(): do() something() def blah2(): foo() pythonIF(x > 10, # then blah1, # else blah) I personally thought the first version was the Python way. Now let's admit that nif number: pos_then: p() zero_then: z() neg_then: n() is also the Python way. With just one problem: they can't have it. Andr? -- From pyenos at pyenos.org Fri Dec 22 19:39:49 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 11:39:49 +1100 Subject: Spyce vs mod_python PSP References: <1166834137.313625.245860@73g2000cwn.googlegroups.com> Message-ID: <87lkkzcune.fsf@pyenos.pyenos.org> frankly, i don't konw anything about mod_python nor spyce, but i wish you good luck. From listas at flavioribeiro.com Thu Dec 28 17:25:26 2006 From: listas at flavioribeiro.com (=?ISO-8859-1?Q?Fl=E1vio_Ribeiro?=) Date: Thu, 28 Dec 2006 19:25:26 -0300 Subject: problems with socket In-Reply-To: <873b128e0612271336l79ceb120u9d1ecbdf3b99625d@mail.gmail.com> References: <873b128e0612271336l79ceb120u9d1ecbdf3b99625d@mail.gmail.com> Message-ID: <873b128e0612281425n7f2b6e38w1911cb08374b525d@mail.gmail.com> any help? dammit :(( 2006/12/27, Fl?vio Ribeiro : > > Hi all, > > I will try to explain my problem, and wait for someone here give me > solutions: (sorry for the bad, bad english) > > I have a server application that talks with another client > applications using socket. The problem isnt this, i did and works very > well. > The problem is open the router port. The person who will use the > server application wouldn't know how to open and configure the port using > the modem web panel, and this job isnt for users, right? > Anyone knows if i can do this remotely? Or have any solutions? > > Im thinking about make a central server application configured and > hosted by me that will interact with the server and client application.. > what do you think about?! have another solution? > > I hope that someone understand and help me.. > > thanks! > -- > Fl?vio Ribeiro > listas at flavioribeiro.com > www.flavioribeiro.com > (83) 9952.1444 -- Fl?vio Ribeiro listas at flavioribeiro.com www.flavioribeiro.com (83) 9952.1444 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jframe at vt.edu Wed Dec 6 22:20:48 2006 From: jframe at vt.edu (John Frame) Date: Wed, 06 Dec 2006 22:20:48 -0500 Subject: Need Help Parsing From File Message-ID: Hi, I've got a Python program that I'm trying to edit, and I need some help. If I would like to read a matrix from a previously created text file into a two dimensional array, how would I do that? Like, if in the txt file, I had the following matrix formatted numbers with 5 rows and 10 columns, and each number is separated by a single space: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 How would I read this data from the file into a two dimensional array in Python? From nagle at animats.com Sun Dec 31 12:44:06 2006 From: nagle at animats.com (John Nagle) Date: Sun, 31 Dec 2006 17:44:06 GMT Subject: Question concerning this list [WebCrawler] In-Reply-To: References: Message-ID: Thomas Ploch wrote: > Marc 'BlackJack' Rintsch schrieb: > >>In , Thomas Ploch >>wrote: >>>Alright, my prof said '... to process documents written in structural >>>markup languages using regular expressions is a no-no.' Very true. HTML is LALR(0), that is, you can parse it without looking ahead. Parsers for LALR(0) languages are easy, and work by repeatedly getting the next character and using that to drive a single state machine. The first character-level parser yields tokens, which are then processed by a grammar-level parser. Any compiler book will cover this. Using regular expressions for LALR(0) parsing is a vice inherited from Perl, in which regular expressions are easy and "get next character from string" is unreasonably expensive. In Python, at least you can index through a string. John Nagle From S.Mientki-nospam at mailbox.kun.nl Thu Dec 28 10:03:35 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Thu, 28 Dec 2006 16:03:35 +0100 Subject: persistant gloabl vars (very newbie) ? In-Reply-To: <459307ec$1@nntp.zianet.com> References: <4592af12$1@nntp.zianet.com> <411f8$4592c9fe$d443bb3a$30198@news.speedlinq.nl> <459307ec$1@nntp.zianet.com> Message-ID: <61b27$4593dcb6$d443bb3a$7053@news.speedlinq.nl> Erik Johnson wrote: >> but it's still not quit handy >> >> # initialization file (init1.py) >> import time; >> xx = 44 >> >> # main file was >> print xx >> x=time.time() >> >> # main file should become >> print init1.xx >> x=init1.time.time() >> >> so even for the "standard" functions like "time" I've to include the >> preceeding module "init1" :-( > > > Ummm... does this help? > > /src/python/Foo> cat init.py > #! /usr/local/bin/python > > from time import time > xx = 44 > > /src/python/Foo> python > Python 2.3.4 (#1, Feb 7 2005, 15:50:45) > [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from init import * >>>> dir() > ['__builtins__', '__doc__', '__file__', '__name__', 'time', 'xx'] >>>> xx > 44 >>>> time > >>>> time() > 1167262478.6845641 >>>> xx = 42 # this does not change the init module's value! >>>> import init >>>> init.xx > 44 > > As Piet points out, you get a copy of variables defined in a module when > using the from module import * syntax (as is demonstrated by the assignment > above). (And I stand corrected on the notion that you could execute "from > module import *" in other than module level scope.) > > If it is your intention to use those variables defined in init to > communicate with other modules making the same sort of import, then you > probably don't want to use "from module import *" syntax. In that case, > you can import just the module, and make assignments into that module's > namespace. (e.g., init.xx = 3) > > If all you care about is getting some "stuff" into your global namespace > in a convenient and repeatable way, then I think what I showed both above > and originally is fine. > thanks Erik, I think I'm slowly getting the picture: always use "import", which is the most unambiguous approach. Life is sometimes difficult for a MatLab user, see my next post ;-) Stef From fredrik at pythonware.com Sun Dec 17 14:43:04 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Dec 2006 20:43:04 +0100 Subject: trees In-Reply-To: References: Message-ID: vertigo wrote: > What library/functions/classes could i use to create trees ? what kind of trees? using lists, tuples, or a class with child pointers is so extremely simple so it has to be something else you're after... From skip at pobox.com Fri Dec 29 09:11:38 2006 From: skip at pobox.com (skip at pobox.com) Date: Fri, 29 Dec 2006 08:11:38 -0600 Subject: Question about the "new" module In-Reply-To: <1167397054.487644.138650@k21g2000cwa.googlegroups.com> References: <1167397054.487644.138650@k21g2000cwa.googlegroups.com> Message-ID: <17813.8730.39301.236054@montanaro.dyndns.org> Gabriele> I'm using Python 2.5 to develop a simple MVC framework based Gabriele> on mod_python. To load my controllers, I create new modules Gabriele> using the "new" module like this: Gabriele> # .... Gabriele> my_module = new.module("random_name") Gabriele> my_module.__file__ = module_path Gabriele> exec open(module_path, "r") in my_module.__dict__ Gabriele> then I initialize the class defined inside the module and call Gabriele> a method of this class based on the HTTP request. Why use the new module? Why not call __import__() or execfile()? Details on their use are here: http://docs.python.org/dev/lib/built-in-funcs.html Skip From NO_Kroeger at gmx.de Thu Dec 21 05:28:10 2006 From: NO_Kroeger at gmx.de (=?iso-8859-1?Q?=22Nils_Oliver_Kr=F6ger=22?=) Date: Thu, 21 Dec 2006 11:28:10 +0100 Subject: calling a class instance of function In-Reply-To: <87zm9i5cub.fsf@pyenos.pyenos.org> References: <87zm9i5cub.fsf@pyenos.pyenos.org> Message-ID: <20061221102810.96510@gmx.net> Hi, Methods i.e functions bound to a class instance (or object) the self argument in their definition: [code] class pid: def add(self, toadd): pass #or some sensible code [/code] If you want to define a method without that implicit self argument you'll have to make this method a static: [code] class pid: @staticmethod def staticadd (param1, param2): pass #or some sensible code [/code] Furthermore, your test() seems to be rather a function than a class: You want to use this function to test the pid class but what you do with your code below is to define a class test which inherits pid. I'm not really sure what the following lines do ... this would usually be the place to introduce class variables. Hope that Helps! Greetings Nils -------- Original-Nachricht -------- Datum: 21 Dec 2006 11:09:32 +1100 Von: Pyenos An: python-list at python.org Betreff: calling a class instance of function > > class pid: > "pid" > def add(original_pid,toadd): > "add pid" > original_pid.append(toadd) > return original_pid > def remove(something_to_remove_from,what): > "remove pid" > something_to_remove_from.remove(what) > return something_to_remove_from > def modify(source,element,changewiththis): > "modify pid" > source[source.index(element)]=changewiththis > return source > > class test(pid): > pid.original=[1,2,3] > pid.toadd=4 > pid.add(pid.original,pid.toadd) # error here says that > # it expects pid instance as first arg > # not a list that it got. > > why do i get an error? > -- > http://mail.python.org/mailman/listinfo/python-list -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal f?r Modem und ISDN: http://www.gmx.net/de/go/smartsurfer From wesleyhenwood at hotmail.com Fri Dec 1 10:43:53 2006 From: wesleyhenwood at hotmail.com (Wesley Henwood) Date: 1 Dec 2006 07:43:53 -0800 Subject: Is python memory shared between theads? Message-ID: <1164987833.233073.265170@80g2000cwy.googlegroups.com> So I declare a variable named A in thread1, in script1.py. I assign the value of 2.5 to A. I then run script2.py in thread2. Script2.py assigns the value of 5.5 to a variable named A. Now, when thread1 resums execution, I see that A = 5.5, rather than 2.5 as I expected. Is this normal behavior? Based on the little documentation I have been able to find on this topic, it is normal behavior. The only way to use same-named variables in scripts is to have them run in a different process, rather than different threads. From mike.klaas at gmail.com Wed Dec 6 14:09:20 2006 From: mike.klaas at gmail.com (Klaas) Date: 6 Dec 2006 11:09:20 -0800 Subject: What are python closures realy like? In-Reply-To: <1165423166.511274.24350@n67g2000cwd.googlegroups.com> References: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> <1165423166.511274.24350@n67g2000cwd.googlegroups.com> Message-ID: <1165432160.784113.270470@80g2000cwy.googlegroups.com> Michele Simionato wrote: > I believe decorators are in large part responsible for that. A callable > object does not work > as a method unless you define a custom __get__, so in decorator > programming it is > often easier to use a closure. OTOH closures a not optimal if you want > persistency > (you cannot pickle a closure) so in that case I use a callable object > instead. Note that it isn't necessary to write the descriptor yourself. The 'new' module takes care of it: In [1]: class A(object): ...: pass In [2]: a = A() In [3]: class Method(object): ...: def __call__(mself, oself): ...: print mself, oself In [4]: import new In [5]: a.method = new.instancemethod(Method(), a, A) In [6]: a.method() <__main__.Method object at 0xb7ab7f6c> <__main__.A object at 0xb7ab79ec> -Mike From paul at boddie.org.uk Sun Dec 10 10:02:05 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 10 Dec 2006 07:02:05 -0800 Subject: How to create a global hotkey? References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com> <1165515363.838887.109720@80g2000cwy.googlegroups.com> <1165596216.573871.259350@l12g2000cwl.googlegroups.com> <1165598376.346246.137520@j44g2000cwa.googlegroups.com> <1165635718.819660.212170@j44g2000cwa.googlegroups.com> Message-ID: <1165762925.778029.104380@80g2000cwy.googlegroups.com> k04jg02 at gmail.com wrote: > Paul Boddie wrote: [DCOP] > This is really annoying to setup and would be a KDE specific solution. Searching for "PyKDE global shortcut" produced something at the PyQt level: http://lists.kde.org/?l=pykde&m=115451566321878&w=2 I don't know whether that is useful in this context, however. > Ideally this would work under Gnome or KDE. Applications do this all > the time -- Amarok for example adds global shortcuts for playing, > pausing, jumping to next track, etc. that work whether or not you're in > KDE or Gnome. The source code for Amarok is available, so if you're not afraid of looking at C++ code there may be an answer somewhere in there. > > I suppose you could just plug in at the X level and have something > > define and intercept a hot key before the desktop environment has a > > chance to process it, but I doubt that this would be a particularly > > nice solution. > > Why not? If I had to guess at this point I'd say it's the 'right' way > to do it. I'm going to be dealing with keypresses that no other apps or > the desktop environments have bound to anything, so I'm not sure it > really qualifies as 'intercepting'. If multiple apps have registered to > receive global keypresses, and the first app that looks at a keypress > doesn't know how to handle it, shouldn't it just get passed on to the > next app? I'm not that familiar with the event model involved, but one disadvantage of handling things at the X level is that people may not be able to inspect or override any shortcuts or hot keys that your application defines within their desktop environment's configuration dialogues. That's why it may be best going through the desktop environment, even though that might mean dealing with different mechanisms in different cases. Unfortunately, the freedesktop.org people haven't introduced standards for global shortcuts, as far as I can tell. Here are some documents I found (by searching for "global shortcut freedesktop standard"): http://www.freedesktop.org/wiki/Standards_2fdefault_2dkeys_2dspec http://portland.freedesktop.org/wiki/IntegrationTasks Paul From robert.kern at gmail.com Mon Dec 4 05:22:18 2006 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 04 Dec 2006 04:22:18 -0600 Subject: Inheritance doesn't work In-Reply-To: References: Message-ID: zefciu wrote: > I have a problem with inheritance under python. The class definition is > longer, but the troublesome thing is: > > from PIL import Image > class MandelbrotImage (Image): > pass > > I am getting the following error: > Traceback (most recent call last): > File "", line 1, in ? > File "mandelimage.py", line 3, in ? > class MandelImage (Image): > TypeError: Error when calling the metaclass bases > module.__init__() takes at most 2 arguments (3 given) > > > I am using python 2.4 from the Debian (Sid) packages. > > Is it a bug, or am I doing something wrong? You're doing something wrong. PIL.Image is a module, not a class. -- 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 From ironfroggy at gmail.com Wed Dec 6 12:52:42 2006 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 6 Dec 2006 12:52:42 -0500 Subject: how to get all the "variables" of a string formating? In-Reply-To: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> References: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> Message-ID: <76fd5acf0612060952k27e52894k7b3d7c3efe32e73a@mail.gmail.com> On 6 Dec 2006 09:41:36 -0800, GHUM wrote: > imagine: > > > template=""" Hello %(name)s, how are you %(action)s""" > > > we can use it to do things like: > > print template % dict (name="Guido", action="indenting") > > > Is there an easy (i.e.: no regex) way to do get the names of all > parameters? > > get_parameters(template) should return ["name", "action"] > > > Python has to do this somewhere internally..... how to access this > knowledge? > > Harald > > -- > http://mail.python.org/mailman/listinfo/python-list > I am not aware of anything in the stdlib to do this easily, but its pretty easy to get them. See this example: class format_collector(object): def __init__(self): self.names = [] def __getitem__(self, name): self.names.append(name) return '' collector = format_collector() "%(foo)s %(bar)s" % collector assert collector.names == ['foo', 'bar'] Of course, wrapping this functionality into a simple function is straightforward and will look better. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ From http Sat Dec 9 18:48:18 2006 From: http (Paul Rubin) Date: 09 Dec 2006 15:48:18 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165703407.362890.23780@l12g2000cwl.googlegroups.com> Message-ID: <7xirgkpr5p.fsf@ruckus.brouhaha.com> Bill Atkins writes: > Lest anyone interpret that list as exhaustive: http://www.cl-user.net/ What have you got for concurrency? How would you write a multi-threaded web server in Lisp? From beliavsky at aol.com Fri Dec 29 22:35:22 2006 From: beliavsky at aol.com (Beliavsky) Date: 29 Dec 2006 19:35:22 -0800 Subject: Wow, Python much faster than MatLab In-Reply-To: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl> References: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl> Message-ID: <1167449722.106162.93380@k21g2000cwa.googlegroups.com> Stef Mientki wrote: > hi All, > > instead of questions, > my first success story: > > I converted my first MatLab algorithm into Python (using SciPy), > and it not only works perfectly, > but also runs much faster: > > MatLab: 14 msec > Python: 2 msec For times this small, I wonder if timing comparisons are valid. I do NOT think SciPy is in general an order of magnitude faster than Matlab for the task typically performed with Matlab. > > After taking the first difficult steps into Python, > all kind of small problems as you already know, > it nows seems a piece of cake to convert from MatLab to Python. > (the final programs of MatLab and Python can almost only be > distinguished by the comment character ;-) > > Especially I like: > - more relaxed behavior of exceeded the upper limit of a (1-dimensional) > array Could you explain what this means? In general, I don't want a programming language to be "relaxed" about exceeding array bounds. From tomas at fancy.org Tue Dec 12 18:22:42 2006 From: tomas at fancy.org (Tom Plunket) Date: Tue, 12 Dec 2006 15:22:42 -0800 Subject: Problem understanding how closures work References: Message-ID: <2ceun2lgcftorm4rsi9r9vc1e3enr8qbl9@4ax.com> Rob Williscroft wrote: > "name" in the above code is bound to a an entry in "CreateTests1"'s > locals, and ExCall has a (hidden) reference to that locals, so > by the time ExCall is finally called the value associated > with "name" has been replaced by (count - 1). Ah, I got it. Thanks. Thanks too to Gabriel. -tom! From duncan.booth at invalid.invalid Tue Dec 19 13:59:34 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Dec 2006 18:59:34 GMT Subject: Core dump revisited References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> <1166474110.001428.137260@80g2000cwy.googlegroups.com> <1166476940.590579.133460@73g2000cwn.googlegroups.com> <1166542176.142415.305720@48g2000cwx.googlegroups.com> <1166547398.787589.177590@f1g2000cwa.googlegroups.com> Message-ID: "Sheldon" wrote: > > Duncan Booth skrev: > >> "Sheldon" wrote: >> >> > I am new to this and copied this code from a colleague. So, it >> > corrupts the pointer. How do I do this properly? >> > >> Here is at least part of your problem: >> >> msgop = PyList_GetItem(work.msgobj, i); >> work.msg_scenes[i] = PyString_AsString(msgop); >> ppsop = PyList_GetItem(work.ppsobj, i); >> work.pps_scenes[i] = PyString_AsString(ppsop); >> ... >> free(work.pps_scenes[i]); >> free(work.msg_scenes[i]); >> >> You initialised msg_scenes and pps_scenes with a malloc'ed block but >> you then just overwrote the pointer with the result of >> PyString_AsString. You don't own the memory for the string returned >> from PyString_AsString, so freeing it will cause a corruption. You >> should copy the string data into the malloc'ed block (with >> appropriate length checks). > > Do you mean with: PyString_FromStringAndSize() and > PyString_Size(PyObject *string) > If you wish, or even just strlen() if you aren't concerned about embedded nulls. From timr at probo.com Sat Dec 30 02:46:33 2006 From: timr at probo.com (Tim Roberts) Date: Sat, 30 Dec 2006 07:46:33 GMT Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <1167244483.792673.132220@42g2000cwt.googlegroups.com> <12p5ffrsdo6v088@corp.supernews.com> <1167245005.678672.196280@73g2000cwn.googlegroups.com> Message-ID: "Ben" wrote: > >Great - that worked.Thanks! >Is that a general method in linux you can always use to redirect >standard output to a file? Works in Windows, too. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From notontheweb at noisp.com Sat Dec 16 20:43:03 2006 From: notontheweb at noisp.com (Jive Dadson) Date: Sun, 17 Dec 2006 01:43:03 GMT Subject: wxPython help please In-Reply-To: <1166317186.248833.266220@79g2000cws.googlegroups.com> References: <1166317186.248833.266220@79g2000cws.googlegroups.com> Message-ID: Sandra-24 wrote: > Try the wxPython mailing list, which you can find on their site. And > the best wxPython reference is the book (also available as an e-book) > by Robin Dunn, who created wxPython. Seeing wxPython from his > perspective is well worth the money. If I recall correctly he devoted > an entire chapter to drawing with a canvas widget. > > -Sandra > I bought the ebook. Searching for "pixel", all I came up with was a method called GetPixel in a "device context." I know there must be a device context buried in there somewhere, so now I need to winkle it out. From tomas at fancy.org Fri Dec 29 03:22:56 2006 From: tomas at fancy.org (Tom Plunket) Date: Fri, 29 Dec 2006 00:22:56 -0800 Subject: how to serve image files without disk use? References: Message-ID: Ray Schumacher wrote: > But, how can I avoid disk writes? wx's *.SaveFile() needs a string > file name (no objects). > I'm going to investigate PIL's im.save(), as it appears to allow > file-objects. Take a look at the img2*.py files in wx.tools. They're sorta sketchy imo, but they do the trick. encode_bitmaps.py, with the wx demo app, is used to generate all of the bitmap data that's in Python files embedded into the app, and following the chain of logic from there might yield you something interesting. Mind, I haven't tried it myself, but it's where I'd start looking. Good luck, -tom! -- From hong.file at gmail.com Sun Dec 3 00:29:41 2006 From: hong.file at gmail.com (progman) Date: 2 Dec 2006 21:29:41 -0800 Subject: db.commit() to take effect Message-ID: <1165123781.350370.308320@79g2000cws.googlegroups.com> I was testing the python+mysql here are my sample codes: ------------------------ import MySQLdb from pprint import pprint db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="database") cursor = db.cursor() cursor.execute('update promo set date=100") ------------------------ i was expecting the cursor.execute will update my db immediately. it wasn't. not until i run db.commit(), then only i see the value changes. it that the right way to update db? From rachele.defelice at gmail.com Wed Dec 13 09:00:54 2006 From: rachele.defelice at gmail.com (ardief) Date: 13 Dec 2006 06:00:54 -0800 Subject: newbie - HTML character codes Message-ID: <1166018453.981657.33780@79g2000cws.googlegroups.com> Hi sorry if I'm asking something very obvious but I'm stumped. I have a text that looks like this: Sentence 401 4.00pm — We set off again; this time via Tony's home to collect a variety of possessions, finally arriving at hospital no.3. Sentence 402 4.55pm — Tony is ushered into a side ward with three doctors and I stay outside with Mum. And I want the HTML char codes to turn into their equivalent plain text. I've looked at the newsgroup archives, the cookbook, the web in general and can't manage to sort it out. I thought doing something like this - file = open('filename', 'r') ofile = open('otherfile', 'w') done = 0 while not done: line = file.readline() if 'THE END' in line: done = 1 elif '—' in line: line.replace('—', '--') ofile.write(line) else: ofile.write(line) would do it but it isn't....where am I going wrong? many thanks rachele From bignose+hates-spam at benfinney.id.au Wed Dec 6 22:15:33 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 07 Dec 2006 14:15:33 +1100 Subject: newb: What is the purpose of if __name__ == "__main__": References: <1165460385.607830.277220@n67g2000cwd.googlegroups.com> Message-ID: <87irgopfai.fsf@benfinney.id.au> "johnny" writes: > What is the purpose of > if __name__ == "__main__": -- \ "He that would make his own liberty secure must guard even his | `\ enemy from oppression." -- Thomas Paine | _o__) | Ben Finney From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 02:39:30 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 09 Dec 2006 18:39:30 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> Message-ID: On Fri, 08 Dec 2006 16:50:01 +0200, Alex Mizrahi wrote: > (message (Hello 'Istvan) > (you :wrote :on '(8 Dec 2006 06:11:20 -0800)) > ( > > ??>> seems to show that Python is a cut down (no macros) version of Lisp > ??>> with a worse performance. > > IA> or maybe it shows that Lisp is an obfuscated version of Python > > hell no, lisp's syntax is much easier than python's since it's homogenous By that "logic" "BrainF*ck" should be even easier still, since it is even more homogeneous, with even less syntax. http://www.muppetlabs.com/~breadbox/bf/ Here's "Hello World" in Brainf*ck: ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++ ..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. Actually, yes, it is "easier" syntax, if by easier you mean "easier for the compiler to parse". If you mean "easier for most human beings to read", then Lisp is easier than Brainf*ck and Python is easier than Lisp. -- Steven. From sjmachin at lexicon.net Fri Dec 15 14:45:49 2006 From: sjmachin at lexicon.net (John Machin) Date: 15 Dec 2006 11:45:49 -0800 Subject: Roundtrip SQL data especially datetime References: Message-ID: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> dyork wrote: > When getting data from a database using the dbapi and an SQL query, how do > you in general round trip the data? Especially date-time? > > An SQL datetime column translates nicely into a Python datetime (surprise), > which then translates into a string like '2005-08-03 07:32:48'. It doesn't translate itself. You translated it. As Gabriel has said, don't do that. > No problem > with that -- all works quite nicely, until you try to put data back the > other way. > There is no obvious way to parse that string back into a datetime, I suppose it all depends on your definition of obvious :-) The constructor is datetime.datetime(year, ....., second) so the following (which works all the way back to Python 2.3) seems not too obscure to me: | >>> import datetime | >>> s = '2005-08-03 07:32:48' | >>> a = map(int, s.replace('-', ' ').replace(':', ' ').split()) | >>> a | [2005, 8, 3, 7, 32, 48] | >>> dt = datetime.datetime(*a) | >>> dt | datetime.datetime(2005, 8, 3, 7, 32, 48) If you have, as you should, Python 2.5, you can use this: | >>> datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S') | datetime.datetime(2005, 8, 3, 7, 32, 48) > and > having done so no obvious way to push that back into a SQL datetime column. How do you push a str or float object back into an SQL column of appropriate type? What's the difference? Your DB API should handle this quite transparently. Try it and see what happens. HTH, John From dixkey at gmail.com Sun Dec 10 20:10:49 2006 From: dixkey at gmail.com (dixkey at gmail.com) Date: 10 Dec 2006 17:10:49 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165689545.676886.289150@j44g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> Message-ID: <1165799449.888040.28140@73g2000cwn.googlegroups.com> mystilleef wrote: > Advantages of Python: > > 1). More and better mature standard libraries (Languages don't matter, > libraries do). Right. > 2). Multiple programming paradigms (including functional style > programming see itertools, functools, operator modules (lambda, map, > filter, reduce, sum etc builtins), higher order functions, list > comprehension, blah, blah) Either you meant this to go under "advantges of Lisp" or you know nothing about Lisp. > 3). Better OO implementation. (I used to hate OO until I started using > Python) Better than what? Lisp's OO? Same comment as number 2. > 4). Ultimate glue language (Plays well with C, C++, Java, .NET. nuff > said. Bindings for almost any lib worth using, at least on *nix) Plays well with C - correct. But who does not? C++, really, you sure about that? Java and .NET? Sure. Separtely. How about some of the above at the same time? Oh, sorry, no advatage here... Also, when you say "plays well" you mean the necessity to hand-craft a C wrapper, compile and debug it *in C*? Or do you mean the easy and "pythonish" way, the ctypes thing, that even IIRC was even included in python 2.5 (I switched to Lisp before 2.5) which allows to create the bindings without leaving the comfort of your host language? Yeah, the praise for ctypes was well-earned, it was a very nice development, great for python world. Now, that said, wanna make a wild guess how exactly the foreign-function interfaces in Lisp have been working? ;) > 5). Clearer syntax. Sometimes. Sometimes not. class aaa: def mmm() ... mmm=staticmethod(mmm) > 6). Better namespace management. (nobody ever talks about this, but > Python seems to be one of the few languages that gets symbol management > right from a users perspective) Maybe, yes. Subject for discussion. > 7). Easier packaging and distribution system. Oh which one do you mean? the <=2.4 style, which is a tar.gz with a setup.py inside, and that setup.py knows how to compile the library? Kina like ASDF in Lisp, only not handling dependencies, recompilation etc? Or the new 2.5+ style, that can also download stuff from the net... Kinda like ASDF-INSTALL? (I'm using version numbers here as time designators, mybe the new system works with 2.4, I don't know) > 8). Ubiquity! Python is everywhere. Lisp, bleh. You're probably right. Still, are you able to name without doing a research three-five platforms that support python, but don't support Lisp? And how many of them are you using? > 9). Relatively good docs (PHP has better). "Relatively" is a keyword here. > 10). Fewer perceived community assholes. I thought so before (although it didn't bother me). But this thread somewhat readjusted my perception of the amount of pythonistassholes. > Large community. Right. > 11). Less fragmentation. Not sure what you mean here. Are you referring to multiple Lisp implementations? Do you think they differ much more that python vs. jython? > Advantages of Lisp: > > Learning a functional language can improve your programming range and > depth. And today, I wouldn't even recommend Lisp (it's rather archaic), Right, you know nothing about Lisp. > I think they are overrated, and in general cause more harm than good. > It's the reason I find [...] programs difficult to grok, maintain > and extend. Cos every smart ass wants to needlessly write his own mini > language to the point of absolute obfuscation. Naturally, I'm supposed > to be awed by his mischievous cleverness. Substitute, for example, python metaclasses for [...] You've got a point about the libraries though. From shane at hathawaymix.org Tue Dec 5 14:49:03 2006 From: shane at hathawaymix.org (Shane Hathaway) Date: Tue, 05 Dec 2006 12:49:03 -0700 Subject: Subprocess with a Python Session? In-Reply-To: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> Message-ID: <4575CD2F.6000809@hathawaymix.org> Calvin Spealman wrote: > No matter what I do I cant get the following code to do what I expect. > I hadn't used subprocess t o read and write to pipes of a > still-running app, and I just can't seem to get it right. What gives? > > import subprocess > > p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE) > p.stdin.write('print 10\n') > assert p.stdout.readline() == '10\n' Make sure the pipes are unbuffered. Launch the process with "python -u" and flush() the streams after writing. (That's the issue I've encountered when doing this before.) Shane From ldo at geek-central.gen.new_zealand Sun Dec 24 18:37:20 2006 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 25 Dec 2006 12:37:20 +1300 Subject: Multi-line docstrings References: Message-ID: In message , Duncan Booth wrote: > Lawrence D'Oliveiro wrote: > >> The Python docs recommend the use of triple-quoted string literals for >> docstrings, e.g. >> >> def Meet(Alice, Bob) : >> """arranges a meeting between Alice and Bob. >> Returns a reference to the meeting booking object.""" >> ... >> #end Meet >> However, these tend to get messed up by indentation whitespace, which >> gets spuriously included as part of the string. > > Not spuriously included: included by design, but sometimes annoying. The problem is that the treatment of indentation whitespace in triple-quoted strings is at odds with its use for syntax purposes elsewhere in the language. Instead of preserving all included whitespace, a better rule for triple-quoted strings might be to strip whitespace up to the current indentation level from each continuation line. That is, each line _must_ begin with at least that amount of whitespace, otherwise it's an error; any extra whitespace is preserved. E.g. a = """two lines of text""" being equivalent to a = "two lines\n of text" Or, a simpler rule might be to strip _all_ whitespace at the start of each continuation line, regardless of indentation level. So the triple-quoted example above becomes equivalent to a = "two lines\nof text" If you _want_ to include some whitespace at the start of a continuation line, simply precede it by something that isn't literal whitespace: a = """two lines \x20 of text""" becomes equivalent to a = "two lines\n of text" (It might be nice if "\ " was recognized as equivalent to "\x20" for this purpose.) From kentilton at gmail.com Sat Dec 9 03:53:42 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 03:53:42 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165653338.110788.62580@n67g2000cwd.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165653338.110788.62580@n67g2000cwd.googlegroups.com> Message-ID: tmh wrote: > Time for some more wine. ...and then just cut and paste the snipped bit into: http://wiki.alu.org/The_Road_to_Lisp_Survey ...if you are not there already. The survey questions are optional and what you wrote is perfect as is. Tough call on what goes in: http://wiki.alu.org/RtL_Highlight_Film Candidates: "If you use it for a year, you won't want to use anything else." "I've gained more insight into coding in the last 6 months then in the previous 15 years." I'd go with: "Yet again, that could be the wine." :) kt -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From paul at boddie.org.uk Wed Dec 6 17:53:07 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 6 Dec 2006 14:53:07 -0800 Subject: Mod_python vs. application server like CherryPy? References: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> <33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com> Message-ID: <1165445587.254054.175190@n67g2000cwd.googlegroups.com> Vincent Delporte wrote: > On 5 Dec 2006 17:05:06 -0800, "fumanchu" wrote: > >In a nutshell, mod_python gives you > >access from Python to the Apache API, whereas CherryPy and friends give > >you their own API. > > I didn't know Apache had an API of its own, or that it was even needed > when writing a web application in Python. What does it provide in > addition to Python/mod_python? mod_python provides different layers of APIs, with the lowest levels being those dealing with things like connections and requests - see the apache module for details: http://www.modpython.org/live/current/doc-html/module-apache.html Other layers involve things like cookies, sessions and Python server pages, and there are also things like the publisher handler which are less to do with Apache itself and more to do with Python: http://www.modpython.org/live/current/doc-html/hand-pub.html Paul From http Fri Dec 15 23:16:14 2006 From: http (Paul Rubin) Date: 15 Dec 2006 20:16:14 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <7xbqm4d97d.fsf@ruckus.brouhaha.com> <7xodq4mule.fsf@ruckus.brouhaha.com> Message-ID: <7xvekcbhm9.fsf@ruckus.brouhaha.com> Kirk Sluder writes: > Personally, I've always preferred use the imperative to describe > basic math rather than the passive. This would seem to map better to > RPN than infix. For writing down complicated, nested expressions too? That's very unusual. E.g. n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ... vs. the same thing in Lisp notation, and that's not even so complicated. From david at cypherspace.info Thu Dec 28 23:09:30 2006 From: david at cypherspace.info (cypher543) Date: 28 Dec 2006 20:09:30 -0800 Subject: Starting a child process and getting its stdout? Message-ID: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> This has been driving me insane for the last hour or so. I have search everywhere, and nothing works. I am trying to use the subprocess module to run a program and get its output line by line. But, it always waits for the process to terminate and then return the output all at once. Can someone please show me some code that actually works for this sort of thing? It doesn't even have to use the subprocess module. Don't worry if the code isn't compatible with Windows. My program is targeted at Linux/UNIX users. Thanks! From michele.simionato at gmail.com Fri Dec 22 01:54:46 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 21 Dec 2006 22:54:46 -0800 Subject: How a script can know if it has been called with the -i command lineoption? In-Reply-To: References: <1166720012.798260.6670@80g2000cwy.googlegroups.com> Message-ID: <1166770486.116238.58390@a3g2000cwd.googlegroups.com> Hendrik van Rooyen wrote: > "Michele Simionato" wrote: > > > > The subject says it all, I would like a script to act differently when > > called as > > $ python script.py and when called as $ python -i script.py. I looked > > at the sys module > > but I don't see a way to retrieve the command line flags, where should > > I look? > > sys.argv() ? > > - Hendrik No, read what Carsten said: """ That doesn't answer the question. The OP wants to inspect the options passed to the interpreter, not the options passed to the script. optparse aids in parsing sys.argv, which only contains the options that are passed to the script. """ From kentilton at gmail.com Sun Dec 10 02:19:42 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sun, 10 Dec 2006 02:19:42 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165732072.056289.274460@79g2000cws.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165627684.709241.86340@16g2000cwy.googlegroups.com> <1165685950.758858.18960@n67g2000cwd.googlegroups.com> <1165732072.056289.274460@79g2000cws.googlegroups.com> Message-ID: George Sakkis wrote: > JShrager at gmail.com wrote: > > >>1. Lisp is the only industrial strength language > > ^^^^^^^^^^^^^^^^^^^ > You keep using that phrase. I don't think it means what you think it > means. To me in part it means "no one can decide to take away lambda because they decided they should not have put it in in the first place and then change their mind and leave it in after I already put a few people on de-lambdifying our 100kloc system because...", and in part it means compilation. And it /has/ to have macros. :) > Perhaps it does in some programming language theory research groups. haha, the same old straw man, Is it not embarrassing to have to resort to the same defeated argument again and again? > In > the real world, superiority has to do with far more than technical > merits alone, let alone obscure metaprogramming features ... Metaprogramming by definition cannot be obscure. Metaprogramming means programming at a higher level. A higher level means "more productive". More productive is the essence of pragmatism. QED. > ...which are > irrelevant to the vast majority of programmers. You insult them by suggesting they cannot concieve at a higher level. Mebbe they could if their language aupported it. Yours does not. > I don't know if other lispers > would join you in your feeble attempt to steal a bite from Ruby's > current glory... Of course we would. You do not get it. The only thing you guys are bleating about is greater popularity. Now someone is about to eat your lunch popularity-wise. Live by the poll, die by the poll. And you held first place for like a week in language geologic time, taken down merely because... > (mostly thanks to the admirable marketing around the > overhyped Rails framework) ... a little hype came along? Wow, your fundamental advantage must have been about zip, and all derived from things unrelated to syntax. , but Ruby is much closer to Python than > either of them is to lisp. In fact, if Python suddenly disappeared, > Ruby would probably be my next stop. Both Ruby and Python are high > level dynamic languages with an emphasis on pragmatic needs, not being > the language of the God(s) (see, I can bring up stupid slogans of > languages too). As Graham said, if some pretty good programmers are jumping up and down about X, mebbe you should take a look at X. Even if assholes like me piss you off. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From rNOSPAMon at flownet.com Fri Dec 1 02:49:42 2006 From: rNOSPAMon at flownet.com (Ron Garret) Date: Thu, 30 Nov 2006 23:49:42 -0800 Subject: Is there a reason not to do this? References: <4t96ujF134nv7U1@mid.uni-berlin.de> <1164942311.945476.147100@f1g2000cwa.googlegroups.com> Message-ID: In article , "Paul McGuire" wrote: > "Carl Banks" wrote in message > news:1164942311.945476.147100 at f1g2000cwa.googlegroups.com... > > > > A straightforward, Pythonic way to do it would be to create an > > intermediate representation that understands both the existing class > > interfaces and the RDB stuff, but that could lead to synchronizing > > problems and a big hit in performance. And it's probably a lot of work > > compared to tacking on methods. OTOH, it could help with hairiness you > > mention. (I recently did something similar in one of my projects, > > though the intermediary was transient.) > > > I would second Carl's recommendation that you find some way to persist an > interim version of these expensive-to-create objects, so you can quickly > load debuggable instances to accelerate your development process. With > luck, you can get by with out-of-the-box marshal/unmarshal using the pickle > module. We've done this several times in my office with objects that an > application creates only after some extensive GUI interaction - it just > slows down development too much without some quick import of debuggable > instances. > > Even though this seems like a sidetrack, it's a pretty direct shortcut, > without too much unusual technology or design work. These objects can be parts of huge networks of massively linked data structures. They are in constant flux. It is not uncommon to hit a bug after many minutes, sometimes hours, of computation. Having to store the whole shlemobble after every operation would slow things down by orders of magnitude. And writing code to be clever and only store the dirty bits would be a pain in the ass. I think I'll stick with Plan A. rg From mark.m.mcmahon at gmail.com Thu Dec 14 14:04:50 2006 From: mark.m.mcmahon at gmail.com (Mark) Date: 14 Dec 2006 11:04:50 -0800 Subject: pwinauto to remote automate a GUI ? In-Reply-To: References: Message-ID: <1166123090.510437.274140@n67g2000cwd.googlegroups.com> Hi, Tim Golden wrote: > [baitelli] > > | pywinauto is a set of python modules to automate the > | Microsoft Windows GUI. > | With the lines below we start and atomates the apllication Notepad: > | > | from pywinauto import application > | app = application.Application() > | app.start('C:\Notepad.exe') > | ... pywinauto automation code > | > | Question: Is it possible to start and automate a remote GUI > | using Python? > > One way might be to have something like > Pyro (http://pyro.sf.net) running on the > remote machine linked to a proxy on the local > machine. > > TJG People have been doing this before... if you do a search for pywinauto on google code search the 2nd link will be... http://www.google.com/codesearch?hl=en&q=+pywinauto+show:SFnFI9XuSEk:FSZQBcwvc98:VkWgdDuEj0U&sa=N&cd=2&ct=rc&cs_p=http://codespeak.net/download/pypy/pypy-0.9.0.tar.gz&cs_f=pypy-0.9.0/py/documentation/talk/pytest-overview.txt#a0 It seems that integration wth PyTest might allow you to do what you want. I think it works something like: - You have python installed on the test machine - It is listening on a port? - You send over code that you want executed - and you get the data returned by the code. But other then that - I don't really know - I am no python Guru (especially not networking!) Glad that you are looking at pywinauto though :-) Mark From paul at eventuallyanyway.com Thu Dec 28 10:28:38 2006 From: paul at eventuallyanyway.com (Paul Hummer) Date: Thu, 28 Dec 2006 15:28:38 +0000 Subject: How to return a simple variable from a function (still newbie) ? In-Reply-To: References: Message-ID: <4593E2A6.6030804@eventuallyanyway.com> How about restructuring your function like this: def some_function( z,y ): z = 2 y[2] = 'global ?' return z And then you'll have to react to the returning variable, like this in your code: x = 5 y = [1,2,3,4] print x,y print some_function( x, y ) print x,y Now, it appears like you want some_function() to change x and y. It doesn't really work that way. You'd have to either pass the variables by reference into the function, or overwrite the existing values with whatever the function returns. That might be beyond your scope now though. Keep plugging, and welcome to Python! Stef Mientki wrote: > I want to return a "simple" variable from a function, > not using the function result. > Is that in any way possible ?? > > The code below is from O'Reilly, "Learning Python", > and there seems no way > to return a simple var like "z" in the example below. > Is that true ? > > thanks, > Stef Mientki > > > def some_function (z, y): > z = 2 > y[2] = 'global ?' > > > x = 5 > y = [1,2,3,4] > print x,y > some_function(x,y) > print x,y > > From seberino at spawar.navy.mil Fri Dec 8 14:47:30 2006 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 8 Dec 2006 11:47:30 -0800 Subject: Snake references just as ok as Monty Python jokes/references in python community? :) Message-ID: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> I'm semi-seriously wondering if snake jokes are valid in the Python community since technically, Python came from Monty Python, not slithery animals. Problem is I don't know that anyone born after Elvis died gets any of these Monty Python jokes. Is it kosher to make snake jokes/references even though officially they don't have anything to do with the name of our favorite language? (*Everyone* gets snake jokes! :) Chris From michele.simionato at gmail.com Wed Dec 6 11:39:26 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 6 Dec 2006 08:39:26 -0800 Subject: What are python closures realy like? In-Reply-To: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> References: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> Message-ID: <1165423166.511274.24350@n67g2000cwd.googlegroups.com> Paul Boddie wrote: > I'm not pointing the finger at you here, Karl, since you seem to be > experimenting with closures, but why are they suddenly so fashionable? > Haven't the features supporting them existed in Python for a few > versions now? Don't people want to write classes any more? > > Intrigued, > > Paul I believe decorators are in large part responsible for that. A callable object does not work as a method unless you define a custom __get__, so in decorator programming it is often easier to use a closure. OTOH closures a not optimal if you want persistency (you cannot pickle a closure) so in that case I use a callable object instead. Michele Simionato From aahz at pythoncraft.com Sun Dec 24 14:07:44 2006 From: aahz at pythoncraft.com (Aahz) Date: 24 Dec 2006 11:07:44 -0800 Subject: Use a Thread to reload a Module? References: <1166846551.460203.242690@h40g2000cwb.googlegroups.com> Message-ID: In article , =?ISO-8859-1?Q?Gregory_Pi=F1ero?= wrote: > >That module deals with accessing data from QuickBooks, marshaling it, >and providing methods to access the marshaled data. Having the server >program keep that module and all of its data in memory makes the >server run really fast, but yeah, it does get complicated now that >it's storing 100's of MB of data. I guess most people go to a >database at this point? Very, very yes. Try using a SQLite in-memory database, maybe? >It's just so easy to store the data in the Python objects I already >need them in instead of converting to tables in a DB and then >converting back. So maybe this threading will work for me. You might well run into problems with the import lock. I strongly advise against your current approach. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I support family values -- Addams family values" --www.nancybuttons.com From duncan.booth at invalid.invalid Wed Dec 6 12:45:10 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Dec 2006 17:45:10 GMT Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net> <4to8neF157i8fU1@mid.individual.net> Message-ID: Paul Melis wrote: >> Ah, thx. Thought the "x in d" syntax might search in d.values() too. > > I don't think it does > > Python 2.4.3 (#1, Nov 19 2006, 13:16:36) > [GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> d={1:'a',2:'b'} >>>> 1 in d > True >>>> 'a' in d > False > It is easy enough to to check if you remember that 'in' maps to the __contains__ method: >>> help({}.__contains__) Help on built-in function __contains__: __contains__(...) D.__contains__(k) -> True if D has a key k, else False From at at tuko.nl Thu Dec 14 13:03:16 2006 From: at at tuko.nl (at) Date: Thu, 14 Dec 2006 19:03:16 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> Message-ID: <458191df$0$322$e4fe514c@news.xs4all.nl> Dear Duncan, Points taken. Its just a workaround for a specific case, I know. Maybe I just love the elegance of new_list = [x for x in some_list if some_cond] and like to see it extended... I got I nice tip on generators however which would allow me to something similar without consuming too much additional resources. Kind regards, Arjan Duncan Booth wrote: > at wrote: > >> By the way, >> >> I think by approving >> >> a = b if condition else c >> >> used to avloind >> >> if condition: >> a = b >> else: >> a = c > > Neither of those is much of an improvement over the other, and in fact if > b or c are complex expressions I would definitely favour the longhand > form. The benefit of having a conditional expression though is that in > some situations it can make the code clearer by allowing you to avoid > creating a name at all. e.g. if 'a' was then used as a parameter in a > function call: > > d = fn(b if condition else c) > > and a has disappeared entirely. > >> >> which is dealing with same psychological problem, Guido also >> recognizes some need... >> >> Is it redundant according to your criteria, yes I would say: >> >> a = {True: a, False: c}[condition] >> >> or >> >> a = [c, a][condition] >> >> would yield exactly the same even in one sentence.... > > You do realise, I hope, that neither of these last two gives the same > results as the inline 'if'? > >>>> x = 0 >>>> print 3/x if x != 0 else -1 > -1 >>>> print {True: 3/x, False: -1}[x != 0] > > Traceback (most recent call last): > File "", line 1, in > print {True: 3/x, False: -1}[x != 0] > ZeroDivisionError: integer division or modulo by zero >>>> print [-1, 3/x][x != 0] > > Traceback (most recent call last): > File "", line 1, in > print [-1, 3/x][x != 0] > ZeroDivisionError: integer division or modulo by zero >>>> > > and before you suggest the good old standby and/or technique, that fails > for other values: > >>>> print x != 0 and 3/x or -1 > -1 >>>> x=5 >>>> print x != 0 and 3/x or -1 > -1 >>>> > > You need to use the messy: > >>>> print (x != 0 and (3/x,) or (-1,))[0] > 0 > > to get exactly the same effect as the inline if with loss of both > readability and performance. From aahz at pythoncraft.com Mon Dec 11 23:55:47 2006 From: aahz at pythoncraft.com (Aahz) Date: 11 Dec 2006 20:55:47 -0800 Subject: alternate language References: <12nr93mis39tu45@corp.supernews.com> <12ns5pea5d84f4a@corp.supernews.com> Message-ID: In article <12ns5pea5d84f4a at corp.supernews.com>, Grant Edwards wrote: >On 2006-12-11, Aahz wrote: >> Grant Edwards wrote: >>> >>>There are people who learn another language after learning Python?? >> >> Heh. Taking your post more seriously than it deserves, > >It was intended as a joke. :) Yeah, yeah, that's what they all say. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Member of the Groucho Marx Fan Club From aine_canby at yahoo.com Mon Dec 11 05:22:20 2006 From: aine_canby at yahoo.com (aine_canby at yahoo.com) Date: 11 Dec 2006 02:22:20 -0800 Subject: Avoiding "invalid literal for int()" exception Message-ID: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> >>> v = raw_input("Enter: ") Enter: kjjkj >>> int(v) Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: 'kjjkj' In my program I need to be able to enter char strings or int strings on the command line. Then I use an if-elif structure to establish which is which. For example - if uniList[0].lower() in ("e","exit"): # uniList stores a unicode string origionally taken from stdin return elif uniList[0].lower() in ("h","help"): verb.PrintVerb() elif uniList[0].lower() in ("p","pass"): break elif int(uniList[0]) in range(0,10): verb.SetImportance(int(uniList[0])) break else: verb.AddNewVerb((uniList[0]) How could I avoid the ValueError exception if uniList[0] == "?ker"? I was thinking of having something like - formatError = False try: iVal = int(uniList[0]) if iVal not in range range(0,10): formatError = True catch ValueError: iVal = -1 if uniList[0].lower() in ("e","exit"): # uniList stores a unicode string origionally taken from stdin return elif uniList[0].lower() in ("h","help"): verb.PrintVerb() elif uniList[0].lower() in ("p","pass"): break elif iVal != -1 and not formatError: verb.SetImportance(iVal) break elif not formatError: verb.VerbEntered((uniList[0]) else: print "Enter numbers between 0 and 10..." Is this the correct way to do this in your opinion? Sorry, I'm totally new to python and exceptions. Thanks, Aine. From sjmachin at lexicon.net Thu Dec 14 21:39:51 2006 From: sjmachin at lexicon.net (John Machin) Date: 14 Dec 2006 18:39:51 -0800 Subject: need clarification with import statements In-Reply-To: <1166133185.363843.120090@80g2000cwy.googlegroups.com> References: <1166133185.363843.120090@80g2000cwy.googlegroups.com> Message-ID: <1166150391.600161.12920@l12g2000cwl.googlegroups.com> Tool69 wrote: > Hi, > I've got the following hierarchy: > > mainprog/ > __init__.py > prog.py > utils/ > __init__.py > myutils.py > others/ > __init__.py > myothers.py > > Inside prog.py I need to have full access to myutils.py and > myothers.py; > Inside myutils.py, I need to access two classes from myothers.py (ie > myotherClass1 and myotherClass2); > Inside myothers.py, I need some functions of myutils.py (ie > myutils_func1 and myutils_func2); > > Do you have some hints please ? 1. Your directory/package hierarchy is far too complicated. Flatten it. 2. You have circular references: the others module will import from utils, but utils wants to import from others. This is prima facie evidence that your modules are not structured properly. Rule 1: Modules should contain /related/ classes and functions. Rule 2: A graph of what imports what should not have loops. Consider combining others and utils -- does that make sense? Another alternative: split out those "some functions of myutils.py (ie myutils_func1 and myutils_func2)" into a fourth module. This module might be the nucleus of a tool-kit of miscellaneous functions that you might import in /any/ app -- in that case, move it outside the current package. HTH, John From pillsbury at gmail.com Mon Dec 11 14:28:52 2006 From: pillsbury at gmail.com (Pillsy) Date: 11 Dec 2006 11:28:52 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165764570.956203.223370@16g2000cwy.googlegroups.com> Message-ID: <1165865332.799254.41670@79g2000cws.googlegroups.com> Andr? Thieme wrote: [...] > What do you mean with "encapsulation" in this context? Presumably that CLOS makes no attempt to enforce the distinction between "private" and "public" methods or class slots. I suppose you can indicate that certain classes, generic functions et c. are "private" by not exporting the symbols associated with them from the relevant package, but even then you merely have a way to communicate your intent to the user, not a way to force them to keep their hands off. ISTR that it's easy to get at "private" things in Python, too, so I'd be surprised if this were a make-or-break issue for Pythonistas. Cheers, Pillsy From orca_cs at hotmail.com Wed Dec 6 23:37:02 2006 From: orca_cs at hotmail.com (Peerumporn Jiranantanagorn) Date: Thu, 07 Dec 2006 04:37:02 +0000 Subject: Liboobs for python Message-ID: Dear All, Is there any python module that work like liboobs or use to ease programming tasks like gnome-system-tools ? Thank you Orca _________________________________________________________________ Stay up-to-date with your friends through the Windows Live Spaces friends list. http://clk.atdmt.com/MSN/go/msnnkwsp0070000001msn/direct/01/?href=http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mk From smallpond at juno.com Fri Dec 8 17:24:36 2006 From: smallpond at juno.com (smallpond at juno.com) Date: 8 Dec 2006 14:24:36 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165616676.381566.91390@79g2000cws.googlegroups.com> Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. > > Mark cmp `which clisp` `which python` /usr/bin/clisp /usr/bin/python differ: byte 25, line 1 HTH --S From nono at hotmail.com Sat Dec 23 08:03:31 2006 From: nono at hotmail.com (Osiris) Date: Sat, 23 Dec 2006 14:03:31 +0100 Subject: Newbie: what is a usefull IDE for Python on Windows ? Message-ID: what is a usefull IDE for Python on Windows ? I saw Eric mentioned.. is that WinXP or Linux ? What does "everybody" use ? I was considering using old and very stable C-code in a new web application via Python/Plone/Zope. From smithj at rpath.com Tue Dec 5 23:55:17 2006 From: smithj at rpath.com (Jonathan Smith) Date: Tue, 05 Dec 2006 23:55:17 -0500 Subject: Ensure a variable is divisible by 4 In-Reply-To: <1165362386.721515.319360@l12g2000cwl.googlegroups.com> References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> <1165362386.721515.319360@l12g2000cwl.googlegroups.com> Message-ID: <45764D35.3010509@rpath.com> MRAB wrote: >> if ( x % 4 ) == 0: >> whatever # x is divisible by 4 >> >> modulus is your friend :) >> >> -smithj > > > It's "modulo"; "modulus" is a different operation. > > Wikipedia says "modulus may refer to... %, the modulo operator of various programming languages" http://en.wikipedia.org/wiki/Modulus That being said, you may be right and it may just be a common mistake. -smithj From atkinw at rpi.edu Sat Dec 9 18:04:30 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 18:04:30 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165703407.362890.23780@l12g2000cwl.googlegroups.com> Message-ID: "mystilleef" writes: >> Macros are not a substitute for libraries, nor are libraries a >> substitute for macros. Having macros lets you build more powerful and >> more expressive libraries. >> > And not having them helps you build less powerful and expressive > libraries? If you told me a turbocharger makes a car accelerate faster, and I said, "So not having a turbochanger helps your car accelerate slower?" what would be your reaction? >> > How's this a good thing? I don't need a Python environment to grok >> > Python code. >> >> Nor do you need it to grok Lisp code. The environment is there to >> make your life better. I was merely responding to your original claim >> that it's impossible to make sense of code that uses macros. >> > > Not impossible, just painstaking. No more so than seeing a function you don't understand. Please be realistic here. Read through the other posts in this thread, where this same issue is refuted ad nauseam. >> Hmm. Anecdotal evidence about Scheme (a vastly and fundamentally >> different language from Common Lisp). Again, you've clinched it for >> me. >> > > I don't believe my experience would have been marginally different had > I used Common Lisp. Well, believe it. The languages are very different, although they appear superficially similar to anyone who isn't familiar with both. The similarity is much like that between Python and Ruby. The two appear to have very similar syntax, but anyone who knows both knows that they're quite different underneath. >> I do believe that the "squealing and whining about macros" was a >> response to Pythonistas claiming that macros are not useful. This was >> in turn in response to a foolishly (trollishly?) cross-posted >> question. It is not as if we have invaded your newsgroup. > > Pythonistas are not saying macros are not useful. They are saying their > usefulness in overrated, exaggerated and needless in the context of > Python. They are saying they don't see what they are missing and along > with the rest of the world couldn't give a damn whether or not it is > ever implemented in Python. Okay, I can't speak for all Pythonistas, > but that's what I'm saying. Of course they're overrated - *because you don't have them*. It would be amusing to see how Python's collective tune would change if Guido issued a royal edict that "Python 3000" (hehehehe) will support syntactic extensions. If Python had macros, would you really complain, or would you appreciate the extra expressive power? On the other hand, I am willing to agree with all of you Pythoners that Python is winning in the library department. So are Perl and Ruby. It would be silly for me to claim that libraries are "overrated," just because other languages have more of them. The truth is that I would like to have macros, libraries, and Lisp's interactive development model, all at once. But your claim upthread that Lisp doesn't have libraries because it's not "worthwhile" is unfounded. When all of the AI companies collapsed in the late 80's and early 90's, Lisp went comatose by association. The revival of Lisp as a tool for doing modern programming dates back only to about 2000 or so. So six years along, we are behind other languages that have had active communities for ten years (Ruby), fifteen years (Python), and nearly twenty years (Perl). I am not worried about the future of Lisp libraries. We already have some: - CL-PPCRE, a pure-Lisp regular expression package that is faster than Perl's - Hunchentoot, a complete web server and web development framework - CAPI, a proprietary but excellent GUI library - CommonSQL (and CLSQL, its open-source offspring) - parenscript, an embeddable Lisp that compiles to Javascript, letting you use macros in your Javascript code - assorted useful libraries, like MD5, base64, SDL, XML parsers, web page fetchers, testing frameworks - bindings to the common C libraries, like GD, Tk, Gtk+ We will get there, in time. Lisp is still the only language in history to linger in "mostly dead" status for a decade and then be resurrected; it is capable of more surprises yet. From spam at spam.pl Sun Dec 17 12:19:20 2006 From: spam at spam.pl (vertigo) Date: Sun, 17 Dec 2006 18:19:20 +0100 Subject: length of multidimensional table Message-ID: Hello i have: x = zeros([3,4],Float) how can i check how many rows and columns x have ? (what is the X and Y size of that table) ? Thanx From grante at visi.com Mon Dec 4 10:49:51 2006 From: grante at visi.com (Grant Edwards) Date: Mon, 04 Dec 2006 15:49:51 -0000 Subject: Parsing data from pyserial, an (inefficient) solution References: <2SQch.10070$P04.1856@tornado.fastwebnet.it> Message-ID: <12n8gsvq48os48f@corp.supernews.com> On 2006-12-04, Giovanni Bajo wrote: [...] >> This should result in complete packets (from the "M" to a "\r") > > Oh well. readline(eol="\r") will do that much better. Yup. Using readline() has been suggested several times. It sure seems like the obvious solution to me as well. > while 1: > data = ser.readline(eol="\r") > args = data.split() > if args[0] == "M": > # command M; do something with args[1:] > elif args[0] == "KK": > # command KK; do something with args[1:] > [.. process other commands ..] > else: > # Invalid command: might be an incomplete > # packet. Just ignore it. > pass -- Grant Edwards grante Yow! Hmmm... A hash-singer at and a cross-eyed guy were visi.com SLEEPING on a deserted island, when... From greg at cosc.canterbury.ac.nz Wed Dec 6 02:33:17 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 06 Dec 2006 20:33:17 +1300 Subject: ANN: Albow - A simple widget library for Pygame Message-ID: ALBOW - A Little Bit of Widgetry for PyGame ------------------------------------------- Version 1.0 This is a very basic, no-frills widget set for creating a GUI using PyGame. It was originally developed for my PyWeek 3 competition entry, Sneak. I am documenting and releasing it as a separate package so that others may benefit from it, and so that it will be permissible for use in future PyGame entries. The download includes HTML documentation and an example program demonstrating most of the library's features. http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/ -- Gregory Ewing greg.ewing at canterbury.ac.nz From pavlovevidence at gmail.com Fri Dec 29 23:17:24 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 29 Dec 2006 20:17:24 -0800 Subject: probably a stupid question: MatLab equivalent of "diff" ? In-Reply-To: References: Message-ID: <1167452244.257878.241800@n51g2000cwc.googlegroups.com> Stef Mientki wrote: > Does anyone know the equivalent of the MatLab "diff" function. > The "diff" functions calculates the difference between 2 succeeding > elements of an array. > I need to detect (fast) the falling edge of a binary signal. Using numpy (or predecessors), you can do this easily with slicing: a[1:] - a[:-1] Slicing shares data, so the slices above don't create new arrays, but new views into the old array, so it avoids that overhead. For Python lists you'd have to use a list comprehension or some such thing like that. For example: [ x-y for (x,y) in zip(a[1:],a[:-1]) ] Or, to avoid creating two new arrays, use iterators: import itertools [ x-y for (x,y) in itertools.izip(itertools.islice(a,0,-1),itertools.islice(a,1)) ] Carl From carsten at uniqsys.com Fri Dec 1 23:22:50 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Fri, 01 Dec 2006 23:22:50 -0500 Subject: [ANN] InformixDB-2.4 released Message-ID: <1165033370.3304.3.camel@localhost.localdomain> I am pleased to announce a new release of InformixDB, the DB-API 2.0 module for connecting to IBM Informix database engines. The list of changes since version 2.3 is short but sweet: - Implement 'named' parameter style to optionally bind query parameters by name - Implement option to retrieve opaque types in their binary representation Downloads and info at http://informixdb.sourceforge.net Best regards, Carsten Haese From ycollet at freesurf.fr Tue Dec 26 07:43:32 2006 From: ycollet at freesurf.fr (ycollet at freesurf.fr) Date: 26 Dec 2006 04:43:32 -0800 Subject: embedded python : can't get or set a variable Message-ID: <1167137011.992310.101990@f1g2000cwa.googlegroups.com> Hello, I'm trying to write a program to send python statements to a python server via tcp and then get back results via a tcp connection. It nearly works ... but I'm totally lost with the embedded dictionary (I'm quite new to python). The first part of the server start the python interpreter via Py_Initialize() and then waits for python statements. To send command, I get some strings and evaluate them through PyRun_String. To get value, I try to build a dictionary and get the result via PyDictGetItem. Here is a sum-up of the c++ python part: Py_Initialize(); pDictionary = PyDict_New(); .... PyRun_String(PyCommand.str().c_str(),Py_file_input,pDictionary,pDictionary); ... PyDict_SetItemString(pDictionary, "__name__", PyEval_GetBuiltins()); pResult = PyDict_GetItemString(pDictionary, "a"); ... if (!PyArg_Parse(pResult, "i", &intValue)) { cout << "tcp-server: wrong type" << endl; } When I send a statement, here is a log of the messages I get : ./tcp-client 2100 send a=15 Parameter 0 : ./tcp-client Parameter 1 : 2100 Parameter 2 : send Parameter 3 : a=15 line to send : send a=15 tcp-client: send or stop command Quit: tcp-client connected to 127.0.0.1:45577 -- send a=15 send command: line = a=15 Traceback (most recent call last): File "", line 1, in ? NameError: name 'a' is not defined Waiting for TCP connection on port 2100 ... When I get a statement, here is a log of the message I get: Parameter 0 : ./tcp-client Parameter 1 : 2100 Parameter 2 : get Parameter 3 : a line to send : get a tcp-client: get command connected to 127.0.0.1:45578 -- get a get command - variable to get : a . Dictionary size = 2 DEBUG: print a print type(a ) DEBUG: pResult = 0x804fd08 DEBUG: pDictionary = 0xb7c44d74 Traceback (most recent call last): File "", line 1, in ? NameError: name 'a' is not defined ['__builtins__', '__doc__', '__name__'] DEBUG: intValue = 15 tcp-server: get = 15 tcp-client: result = 15 Quit: tcp-client My question is: how to get a global variables via PyDict_* ? Why does the python interpreter prints an error message when I send my command "a=15" ? Why does it finally accepts my command "a=15" ? Your sincerely, Yann COLLETTE From JShrager at gmail.com Mon Dec 11 12:18:46 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 11 Dec 2006 09:18:46 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165821773.670192.288860@79g2000cws.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> Message-ID: <1165857526.721489.322470@73g2000cwn.googlegroups.com> > > > Python has this unsung module called doctest that neatly shows some of > > > the strengths of python: http://en.wikipedia.org/wiki/Doctest > > Now I'm *certain* that you're just pulling my leg: You guys document > > all your random ten-line hacks in Wikipedia?!?! What a brilliant idea! > Python is newbie-friendly. Part of that is being accessible. > Doctest is about a novel way of using a feature shared by Lisp, that is > docstrings. Testing is important, usually not done enough, and doctests > are a way to get people to write more tests by making it easier. Does > Lisp have similar? Seems like a trivial commonality between the languages, and a trivial library, but that's not at all what I was laughing at... > > Hey, you even have dead vaporware projects like uuu documented in > > Wikipedia! Cool! (Actually, I don't know that doctest is ten lines in > > Python, but it'd be about ten lines of Lisp, if that, so I'm just > > guessing here.) > Does Lisp have a doctest-like module as part of its standard > distribution? Or are you saying that If you ever needed it, then it would be > trivial to implement in Lisp, and you would 'roll your own'? There are > advantages to doctest being one of Pythons standard modules. Actually, I don't care what you put into your library -- to some exent, the more the merrier (as I've said elsewhere, I wish we had your community of busy ... um ... beavers :-) to create libraries full of stuff, trivial or not!) The wheat will rise from the chaff. (Some Lispers might disagree with me here.) But anyway, what I was laughing at had nothing to do with doctest -- but that you use wikipedia to document your libraries. Elsewhere I have aregued that Wikipedia is a stupid marketing document -- *many* Lispers disagree with me here, so let's no go down this road, please as it's soooooooo OT! So, I'm mostly laughing at the laughability of the concept of the Wikipedia as somehow a source of all wisdom, not doctest per se. Random ten-line Python libraries (as well as dead vaporware python projects, as well as a whole bunch of other useless crap, and the very occassionally useful crap) being in Wikiperdia just makes me smile, that's all. From http Sun Dec 17 22:26:42 2006 From: http (Paul Rubin) Date: 17 Dec 2006 19:26:42 -0800 Subject: merits of Lisp vs Python References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> Message-ID: <7xlkl5khot.fsf@ruckus.brouhaha.com> Bill Atkins writes: > Whatever do you mean? The portion of memory used for memory-mapped > registers is simply excluded from GC; everything else works as normal. Well ok, if the peek and poke functions validate the addresses. > All modern Lisps (yes, *Common* Lisps) support a foreign-function > interface to talk to C libraries. Data involved with these kinds of > interface is ignored by the GC, for obvious reasons. Do you claim > that these implementations are not truly Lisps? I think usually those objects are simply treated as opaque by the GC and the contents are inaccessible except through FFI calls. You can't have the Lisp code running amuck trampling things through naked pointers. Obviously the foreign function can trample things but it's not written in Lisp. From aidan at aidans.org Wed Dec 13 19:23:28 2006 From: aidan at aidans.org (Aidan Steele) Date: Thu, 14 Dec 2006 11:23:28 +1100 Subject: Password, trust and user notification In-Reply-To: <1166053509.270409.46390@f1g2000cwa.googlegroups.com> References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> <1165917102.008439.146400@16g2000cwy.googlegroups.com> <1166053509.270409.46390@f1g2000cwa.googlegroups.com> Message-ID: <364538570612131623g1bb31328r7ea850814ae9133e@mail.gmail.com> On 13 Dec 2006 15:45:09 -0800, placid wrote: > > > Gabriel Genellina wrote: > > > > You DON'T need the password for the receiving account just to send him > > an email! > > And you don't even need that special Gmail library, smtplib should be > > fine. > > Yes you dont need a password to receive email, but to access Gmail and > send an email you do. Yes you do need the Gmail library to access Gmail > because the script will run on a computer that doesnt have a smtp > server. > > Is there other way's of notifying the user? > > > Cheers > > -- > http://mail.python.org/mailman/listinfo/python-list What Gabriel said was correct. You can use smtplib to connect to Gmail's SMTP server as the library supports SSL/TLS required by Gmail (see here: http://mail.google.com/support/bin/answer.py?answer=13287&topic=1556) You do not need a local SMTP server to use smtplib, just use the values found in that provided URL. Hope this helps, Aidan Steele. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.cavalaria at free.fr Thu Dec 14 07:04:17 2006 From: chris.cavalaria at free.fr (Christophe) Date: Thu, 14 Dec 2006 13:04:17 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1166092000.715620.50040@f1g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <457fd653$0$4340$426a74cc@news.free.fr> <1166092000.715620.50040@f1g2000cwa.googlegroups.com> Message-ID: <45813dc6$0$22501$426a74cc@news.free.fr> josephoswaldgg at hotmail.com a ?crit : > Christophe wrote: >> Call us when you have an editor that reads your mind and writes the () >> for you. > > This is an irrelevancy. Typos that drop printing characters in either > language will generally cause changes to the semantics. Lisp > programmers, incidentally, will see that their editor indented things > in a funky way and recognize "hey, I dropped a paren somewhere in that > copy-paste." (And, if so, it is usually at the end, and can be > recovered using automatic matching when typing the ')' ). And, > honestly, the punctuation is no harder to type in Lisp than in other > languages, they just occur in different (and more consistent) places. > > The point of Python is that changing white-space to > different-white-space changes the semantics. At best an editor can > notice "hey, funky white-space here, please correct" as IDLE did when I > wrote my first Python in a non-Python-aware editor, and somehow had > swapped tabs and spaces; when I moved it to IDLE---the indentation > *looked fine* but was invisibly weird. At worst, an editor can go > "sure, I'll let you change your program." > > I'm not saying the worst case is typical. The annoying case is more > likely. I will even admit that white-space significance does not > materially increase errors among experienced Pythonistas. What it isn't > is some kind of miraculous invention that saves programmers from ever > making mistakes that are common in other languages, or that reduces > effort in copy-paste, as Bjoern seemed to be claiming. So, you are more or less saying that, using a smart Lisp editor, you'll easily catch block errors when you misplace a bracket, but using dumb Python editors allows inconsistent tab-space usage to go unnoticed? Yeah, nothing wrong in what you said but hardly relevant I say :) For the Python side, I just hope that -tt becomes the default option one day ( interpreter causes errors when mixing spaces and tabs ) From nospam at foo.com Mon Dec 18 13:04:36 2006 From: nospam at foo.com (jayessay) Date: 18 Dec 2006 13:04:36 -0500 Subject: merits of Lisp vs Python References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > xscottg at gmail.com writes: > > I should assume you meant Common Lisp, but there isn't really any > > reason you couldn't > > > > (poke destination (peek source)) > > That breaks the reliability of GC. I'd say you're no longer writing > in Lisp if you use something like that. Please note: GC is not part of CL's definition. It is likely not part of any Lisp's definition (for reasons that should be obvious), and for the same reasons likely not part of any language's definition. So, your point here is actually a category error... /Jon -- 'j' - a n t h o n y at romeo/charley/november com From sjmachin at lexicon.net Sat Dec 9 23:59:43 2006 From: sjmachin at lexicon.net (John Machin) Date: 9 Dec 2006 20:59:43 -0800 Subject: ATTRIBUTE ERROR: 'module' object has no attribute 'ssl' In-Reply-To: <1165720787.910338.118940@j44g2000cwa.googlegroups.com> References: <1165720787.910338.118940@j44g2000cwa.googlegroups.com> Message-ID: <1165726783.411321.36430@73g2000cwn.googlegroups.com> johnny wrote: > I am getting the following errors: That is *one* error. > > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in > _send_output > self.send(msg) > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send > self.connect() > File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in > connect > ssl = socket.ssl(sock, self.key_file, self.cert_file) > AttributeError: 'module' object has no attribute 'ssl' > > Thank You in Advance Thanks for what? We can't help you if you don't supply the full traceback, plus what version of Python you are running, on what platform [yeah, Windows, but which?] By the way, how did you manage to get Python installed in a path like "H:\xampp\xampp\xampp" ? Cheers, John From bj_666 at gmx.net Thu Dec 28 05:14:27 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Thu, 28 Dec 2006 11:14:27 +0100 Subject: Feasible in Python ? list of object , with two exeptional objects References: <6eo5p2di7lrcs5smouhg8ju83901b4hld0@4ax.com> <4592f3cc$0$17164$4c368faf@roadrunner.com> <8vv6p29lqjl24bkcge3iv66vflvt683akc@4ax.com> Message-ID: In <8vv6p29lqjl24bkcge3iv66vflvt683akc at 4ax.com>, Osiris wrote: > Would I put all the stuff that is the same in both classes in the base > class and only the differing stuff in the subclasses ? Yes that's the intent of base/sub class relationships. Baseclasses contain the behavior common to all their subclasses and subclasses implement just the different or additional behavior. > Could I move the normal length method to the superclass, and override > it in the special class, like this: Yes that can be done and makes perfectly sense if the `length()` in the baseclass is the "normal" behavior and that baseclass can be instantiated and used directly. Ciao, Marc 'BlackJack' Rintsch From rampeters at gmail.com Fri Dec 8 13:23:09 2006 From: rampeters at gmail.com (johnny) Date: 8 Dec 2006 10:23:09 -0800 Subject: mySql and multiple connection for threads Message-ID: <1165602188.976489.74760@j44g2000cwa.googlegroups.com> How do you create multiple connection in the treads. Lets say I will have at most 5 threads and I want to create at most 5 connections. If I create a connection in the "worker method", does it create connection for each threads. def worker(tq): while True: host, e = tq.get() c = ftplib.FTP(host) c.connect() try: c.login() p = os.path.basename(e) download_dir = r'H:/ftp_download/' ps_dir = r'H:/ftp_download/' filename = download_dir+p fp = open(filename, 'wb') try: c.retrbinary('RETR %s' % e, fp.write) finally: fp.close() finally: c.close() if (p.lower().endswith('.ps') ): partFileName = p.split('.', 1) movedFile = download_dir + p #movedFile = p finalFile = ps_dir + partFileName[0]+'.pdf' encode_cmd = r'ps2pdf '+ movedFile + ' '+ finalFile os.system(encode_cmd) conn = adodb.NewADOConnection('mysql') conn.Connect('localhost', 'temp', 'temp', 'temp') sql = r"update file where file_path='"+p+"' set pdf_file_path='" +finalFile+"'" cursor = conn.Execute(sql) rows = cursor.Affected_Rows() tq.task_done() From gagsl-py at yahoo.com.ar Wed Dec 27 18:30:40 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 27 Dec 2006 20:30:40 -0300 Subject: getting a process's PID In-Reply-To: <20061227142637.A23890@eris.io.com> References: <20061227102939.L20663@eris.io.com> <20061227135600.O21223@eris.io.com> <20061227142637.A23890@eris.io.com> Message-ID: <7.0.1.0.0.20061227202746.046bdf58@yahoo.com.ar> At Wednesday 27/12/2006 17:33, eldorado wrote: >Yes, I was running this on a box that had 1.4 - I just tested it on a box >that has 2.3.5 and it runs perfect. Your changes also allow it to be run >on the boxes that still have 1.4 Ouch! 1.4 is really really ancient! Even the most conservative libraries -like PIL- require at least 1.5 -- 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 From bj_666 at gmx.net Mon Dec 4 03:24:55 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Mon, 04 Dec 2006 09:24:55 +0100 Subject: algorithm for sorting functional expressions References: <1165215032.749560.171530@16g2000cwy.googlegroups.com> Message-ID: In <1165215032.749560.171530 at 16g2000cwy.googlegroups.com>, chrisguest wrote: > So I suspect that this is a common problem for those familiar with > partially ordered sets or directed graphs. I'm wondering if anyone else > is familiar with this problem and knows an efficient algorithm that > will solve it. It would be good if any such algorithm would be able to > check for circular definitions in the input. You are looking for "topological sort". Feed a search engine with that term. :-) Ciao, Marc 'BlackJack' Rintsch From tleeuwenburg at gmail.com Sun Dec 3 18:08:57 2006 From: tleeuwenburg at gmail.com (tleeuwenburg at gmail.com) Date: 3 Dec 2006 15:08:57 -0800 Subject: evaluating gui modules, any experience on tkinter? In-Reply-To: References: <0qkch.2229$YI1.1130@newsfe15.lga> <4571ffec$0$19245$4fafbaef@reader4.news.tin.it> Message-ID: <1165187337.503183.189180@16g2000cwy.googlegroups.com> Tkinter is lame, but it works everywhere and is what I keep coming back to despite my many complaints about it. If youre application can be fit into a web porgramming framework, that may well be the best way to go. Your browser can probably render a better gui than any of the other frameworks can. Cheers, -T From erinhouston at gmail.com Fri Dec 15 11:45:52 2006 From: erinhouston at gmail.com (ina) Date: 15 Dec 2006 08:45:52 -0800 Subject: re pattern for matching JS/CSS In-Reply-To: <1166194075.458179.275520@79g2000cws.googlegroups.com> References: <1166194075.458179.275520@79g2000cws.googlegroups.com> Message-ID: <1166201152.916044.14930@t46g2000cwa.googlegroups.com> i80and wrote: > I'm working on a program to remove tags from a HTML document, leaving > just the content, but I want to do it simply. I've finished a system > to remove simple tags, but I want all CSS and JS to be removed. What > re pattern could I use to do that? > > I've tried > '' > but that didn't work properly. I'm fairly basic in my knowledge of > Python, so I'm still trying to learn re. > What pattern would work? I use re.compile("",re.DOTALL) for scripts. I strip this out first since my tag stripping re will strip out script tags as well hope this was of help. From kylotan at gmail.com Sun Dec 24 20:16:45 2006 From: kylotan at gmail.com (Ben Sizer) Date: 24 Dec 2006 17:16:45 -0800 Subject: Why does Python never add itself to the Windows path? Message-ID: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> I've installed several different versions of Python across several different versions of MS Windows, and not a single time was the Python directory or the Scripts subdirectory added to the PATH environment variable. Every time, I've had to go through and add this by hand, to have something resembling a usable Python installation. No such problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or Kubuntu. So why is the Windows install half-crippled by default? I just rediscovered this today when trying to run one of the Turbogears scripts, but this has puzzled me for years now. -- Ben Sizer From Roberto.Bonvallet at cern.ch Fri Dec 15 10:06:55 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Fri, 15 Dec 2006 15:06:55 +0000 (UTC) Subject: AI library References: <7CAC08AF-8C32-11DB-AD4B-000D93463186%felix.benner@imail.de> Message-ID: Felix Benner wrote: [...] > def a-star(self, nodeFrom, nodeTo): > """searches the shortest path (minimal weight) from > nodeFrom to nodeTo.""" > pass >>> def a-star(self, nodeFrom, nodeTo): File "", line 1 def a-star(self, nodeFrom, nodeTo): ^ SyntaxError: invalid syntax -- Roberto Bonvallet From sjmachin at lexicon.net Fri Dec 22 04:43:28 2006 From: sjmachin at lexicon.net (John Machin) Date: 22 Dec 2006 01:43:28 -0800 Subject: Decorator for Enforcing Argument Types In-Reply-To: References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166741966.242087.192390@n67g2000cwd.googlegroups.com> <1166767205.559937.185260@f1g2000cwa.googlegroups.com> <1166773847.368709.299960@48g2000cwx.googlegroups.com> Message-ID: <1166780607.921591.248000@f1g2000cwa.googlegroups.com> Duncan Booth wrote: > "John Machin" wrote: > > >> > if isinstance(.... > >> > action_for_type1(... > >> > # big snip > >> > elif isinstance(... > >> > action_typeN( ... > >> > # no else statement > >> > >> Ouch.. someone must have skipped his/her OO class... > > > > Quite possibly :-) but that's not the problem here. > > > > The method in question might be called say emit_generic(self, > > any_type_of obj) and so one bunch of isinstance calls is actually > > needed, but not two bunches. So: lose the decorator and add an else and > > a raise at the end. > > > > There is a secondary problem: annoying the crap out of callers who > > often know what type they have and want an emit_real which would take > > an int, a long, or a float and an emit_strg and ... (yes, almost all > > the possible types are that simple) which wouldn't go through even one > > chain of isinstance calls. > > > > I think the point that was being made was that the method's body should be > something like: > > actions[type(arg)](...) > > which not only avoids all of the isinstance calls but also the else and the > raise at the end. You are saying that you think that George thinks that they are teaching efficient coding methods in OO classes?? From h0leforfun at gmail.com Mon Dec 18 10:33:00 2006 From: h0leforfun at gmail.com (Hole) Date: 18 Dec 2006 07:33:00 -0800 Subject: Strange error with getattr() function Message-ID: <1166455980.365984.296680@l12g2000cwl.googlegroups.com> Hi There! I'm trying to use Zope and the product OpenFlow. I got the following error while I was using the built-in function getattr() to retrieve an OpenFlow object: attribute name must be string Actually, I surely pass a string as attribute name to getattr() The code: #following instruction returns me the string "WorkFlowTest" openflow_id=container.aq_parent.id if (hasattr(container,openflow_id): #the interpreter enter in this block, so #it's sure that container has an attribute called WorkFlowTest openflow=getattr(container,openflow_id) At this point, I got the error: attribute name must be string The *strange* is that I get the same error even if I pass the attribute name to the getattr() function as pure string: getattr(container,"WorkFlowTest") (sic!!!!!) I'm a lot confused! Thanks in advance. -- H0le From exarkun at divmod.com Wed Dec 20 10:20:11 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 20 Dec 2006 10:20:11 -0500 Subject: Support of IPv6 extension headers In-Reply-To: <1166627222.868166.123710@a3g2000cwd.googlegroups.com> Message-ID: <20061220152011.20948.484348741.divmod.quotient.83639@ohm> On 20 Dec 2006 07:07:02 -0800, cychong wrote: >Hi, > >There is no probleming in programming the basic IPv6 socket program >with the python. >Then how about the IPv6 extension header? The RFC 2292 and man pages >from the unix/linux advise >to use the sendmsg to send the packet with the extension header. >Does python support the extension header processing? Python doesn't expose sendmsg. There are several third-party modules which do, though. Googling for "python sendmsg" turns up some useful links. Jean-Paul From stuart at bmsi.com Fri Dec 8 22:53:18 2006 From: stuart at bmsi.com (Stuart D. Gathman) Date: Fri, 08 Dec 2006 22:53:18 -0500 Subject: Driver selection Message-ID: The pyspf package [http://cheeseshop.python.org/pypi/pyspf/] can use either pydns, or dnspython. The pyspf module has a simple driver function, DNSLookup(), that defaults to the pydns version. It can be assigned to a dnspython version, or to a test driver for in memory DNS. Or you can modify the source to "from drivermodule import DNSLookup". What is the friendliest way to make this configurable? Currently, users are modifying the source to supply the desired driver. Yuck. I would like to supply several drivers, and have a simple way to select one at installation or run time. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From bj_666 at gmx.net Mon Dec 11 10:15:07 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Mon, 11 Dec 2006 16:15:07 +0100 Subject: Automatic debugging of copy by reference errors? References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165645676.694401.193580@16g2000cwy.googlegroups.com> <1165666093.996141.244760@n67g2000cwd.googlegroups.com> <1165672702.406793.320500@79g2000cws.googlegroups.com> <1165816097.869936.79780@j72g2000cwa.googlegroups.com> <1165846864.970968.78750@79g2000cws.googlegroups.com> Message-ID: In <1165846864.970968.78750 at 79g2000cws.googlegroups.com>, Beliavsky wrote: >> ISTM the big catch for Fortran programmers is when a mutable container >> is referenced from multiple places; thus a change via one reference >> will confusingly show up via the other one. > > As a Fortranner, I agree. Is there an explanation online of why Python > treats lists the way it does? I did not see this question in the Python > FAQs at http://www.python.org/doc/faq/ . This question sounds as if lists are treated somehow special. They are treated like any other object in Python. Any assignment binds an object to a name or puts a reference into a "container" object. Ciao, Marc 'BlackJack' Rintsch From deets at nospam.web.de Thu Dec 14 03:56:56 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 14 Dec 2006 09:56:56 +0100 Subject: variables with dynamicly generated names In-Reply-To: References: Message-ID: <4uchulF17cg5iU1@mid.uni-berlin.de> avlee schrieb: > Hello > > Is it possible to use in python variables with dynamicly created names ? > How ? In such cases, use a dictionary: vars = {} for some_name, some_value in some_values_generating_thing(): vars[some_name] = some_value Diez From steven.bethard at gmail.com Mon Dec 11 15:08:26 2006 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 11 Dec 2006 13:08:26 -0700 Subject: How can I get involved In-Reply-To: References: <1165856767.477175.276380@80g2000cwy.googlegroups.com> Message-ID: Steven Bethard wrote: > .. _python-dev list: One really simple way to contribute that would be Sorry, copy-paste error. This should have been: .. _python-dev list: http://mail.python.org/mailman/listinfo/python-dev STeVe From gagsl-py at yahoo.com.ar Fri Dec 8 03:57:24 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 08 Dec 2006 05:57:24 -0300 Subject: Need Help Parsing From File In-Reply-To: References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> <1165517086.976152.216270@16g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061208054416.040846d8@yahoo.com.ar> At Friday 8/12/2006 05:30, Duncan Booth wrote: > > For the Borland C++ 3.1 help (about 1991): > > If "t" or "b" is not given in the string, the mode is governed by > > _fmode. > > If _fmode is set to O_BINARY, files are opened in binary mode. > > If _fmode is set to O_TEXT, they are opened in text mode. > > MSC used to have a similar flag (perhaps using the same name). >I assume you are using 'used to have' in the sense of 'still have, although >it is now deprecated in favour of the functions _get_fmode and _set_fmode'. I meant "I have no idea whether it's still the case or not" - thanks for the info. And I was talking about the old MSC compiler, a quite different product from the current MSVC. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From moqtar at gmail.com Mon Dec 4 23:09:43 2006 From: moqtar at gmail.com (Moqtar) Date: 4 Dec 2006 20:09:43 -0800 Subject: Filename too long error Message-ID: <1165291783.150259.229520@79g2000cws.googlegroups.com> I am trying to walk a directory and print the file and its modified time. When the path is longer then 259 characters i get an error "Filename too long". I guess these is because windows limitation on path length. My code: import os import time for root,dirs,files in os.walk(directory): for file in files: fullpath=os.path.join(root,file) print fullpath print 'Length',len(fullpath) ModifiedTime=os.path.getmtime(fullpath) print ModifiedTime Ouput Error: D:\2\users\1111111111111111111111111111111111111111111111111111111111111111111111111111 \22222222222222222222222222222222222222222222222222 \33333333333333333333333333333333333333333333333333 \4444444444444444444444444444444444444444444444444 \5555555555555\1111111.txt Length 265 Traceback (most recent call last): File "C:\Python24\hello.py", line 17, in -toplevel- ModifiedTime=os.path.getmtime(fullpath) File "C:\Python24\lib\ntpath.py", line 233, in getmtime return os.stat(filename).st_mtime OSError: [Errno 38] Filename too long Is there a way to find the modified time of long path? From shuanyu at gmail.com Mon Dec 25 01:55:11 2006 From: shuanyu at gmail.com (many_years_after) Date: 24 Dec 2006 22:55:11 -0800 Subject: How to stop program when threads is sleeping Message-ID: <1167029711.446218.133930@f1g2000cwa.googlegroups.com> Hi, pythoners: There is a problem I couldn't dispose. I start a thread in the my program. The thread will do something before executing time.sleep(). When the user give a signal to the main thread (such as click the 'end' button or close the window), the thread should end it's running. But how to end the threading when it's sleeping? I set an flag to the thread, but it doesn't work. I also thought to put 'time.sleep()' to the main thread. But I think the main thread will not response to user's action because it is executing sleep(). Any ideas? Thanks. From john106henry at hotmail.com Fri Dec 1 17:33:29 2006 From: john106henry at hotmail.com (John Henry) Date: 1 Dec 2006 14:33:29 -0800 Subject: Thread help In-Reply-To: <4tbhffF13bmgrU1@mid.individual.net> References: <1164999221.679348.221000@16g2000cwy.googlegroups.com> <12n0v9l4ssfd7fc@corp.supernews.com> <4tbhffF13bmgrU1@mid.individual.net> Message-ID: <1165012409.569588.264600@79g2000cws.googlegroups.com> Why stop there? Bjoern Schliessmann wrote: > Grant Edwards wrote: > > On 2006-12-01, Salvatore Di Fazio > > >> I would make 3 threads for a client application. > > > You should use 4. > > I vote for just 1. > > Regards, > > > Bj?rn > > -- > BOFH excuse #236: > > Fanout dropping voltage too much, try cutting some of those little > traces From tjreedy at udel.edu Thu Dec 14 14:24:12 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Dec 2006 14:24:12 -0500 Subject: YouTube written in Python References: Message-ID: "John Nagle" wrote in message news:vZ7gh.5789$Gr2.2427 at newssvr21.news.prodigy.net... >> (Guido) YouTube is almost entirely written in Python. > Probably just the web page maintenance system is in Python. I am sure that that is pretty much all he meant. > I doubt that actual video passes through Python at any point. > Transcoding in Python would take forever. I would expect that the video files are stored in a ready-to-send format. And that they wrote or perhaps adapted a pre-written compilable video library. Ditto for the backend database. And CPython makes it relatively easy to call such add-ons. tjr From michele.simionato at gmail.com Mon Dec 11 12:01:15 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 11 Dec 2006 09:01:15 -0800 Subject: alternate language In-Reply-To: References: Message-ID: <1165856474.895402.313050@f1g2000cwa.googlegroups.com> Bryan wrote: > what is a good alternate language to learn? i just want something to expand > my mind and hopefully reduce or delay any chance of alzheimer's. i would > especially like to hear from those of you who learned python _before_ these > languages. > > haskell, erlang, ocaml, mozart/oz, rebel, etc. > > i don't require any of these features, but extra browny points for any of > the following: > > interactive interpreter > batteries included > can integrate with c > compiles to native code > can use a gui toolkit such as wx > doesn't take 60 hour weeks over years to master > Chicken Scheme: http://www.call-with-current-continuation.org (not sure about wx, but there are various GUI wrappers available) Michele Simionato From beliavsky at aol.com Mon Dec 11 09:21:05 2006 From: beliavsky at aol.com (Beliavsky) Date: 11 Dec 2006 06:21:05 -0800 Subject: Automatic debugging of copy by reference errors? References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165645676.694401.193580@16g2000cwy.googlegroups.com> <1165666093.996141.244760@n67g2000cwd.googlegroups.com> <1165672702.406793.320500@79g2000cws.googlegroups.com> <1165816097.869936.79780@j72g2000cwa.googlegroups.com> Message-ID: <1165846864.970968.78750@79g2000cws.googlegroups.com> Carl Banks wrote: > Niels L Ellegaard wrote: > > Marc 'BlackJack' Rintsch wrote: > > > In <1165666093.996141.244760 at n67g2000cwd.googlegroups.com>, Niels L > > > Ellegaard wrote: > > > > I have been using scipy for some time now, but in the beginning I made > > > > a few mistakes with copying by reference. > > > But "copying by reference" is the way Python works. Python never copies > > > objects unless you explicitly ask for it. So what you want is a warning > > > for *every* assignment. > > > > Maybe I am on the wrong track here, but just to clarify myself: > > > > I wanted a each object to know whether or not it was being referred to > > by a living object, and I wanted to warn the user whenever he tried to > > change an object that was being refered to by a living object. > > This really wouldn't work, trust us. Objects do not know who > references them, and are not notified when bound to a symbol or added > to a container. However, I do think you're right about one thing: it > would be nice to have a tool that can catch errors of this sort, even > if it's imperfect (as it must be). > > ISTM the big catch for Fortran programmers is when a mutable container > is referenced from multiple places; thus a change via one reference > will confusingly show up via the other one. As a Fortranner, I agree. Is there an explanation online of why Python treats lists the way it does? I did not see this question in the Python FAQs at http://www.python.org/doc/faq/ . Here is a short Python code and a Fortran 95 equivalent. a = [1] c = a[:] b = a b[0] = 10 print a,b,c output: [10] [10] [1] program xalias implicit none integer, target :: a(1) integer :: c(1) integer, pointer :: b(:) a = [1] c = a b => a b(1) = 10 print*,a,b,c end program xalias output: 10 10 1 It is possible to get similar behavior when assigning an array (list) in Fortran as in Python, but one must explicitly use a pointer and "=>" instead of "=". This works well IMO, causing fewer surprises, and I have never heard Fortranners complain about it. Another way of writing the Fortran code so that "a" and "b" occupy the same memory is to use EQUIVALENCE. program xequivalence implicit none integer :: a(1),b(1) integer :: c(1) equivalence (a,b) a = [1] c = a b = a b(1) = 10 print*,a,b,c end program xequivalence output: 10 10 1 EQUIVALENCE is considered a "harmful" feature of early FORTRAN http://www.ibiblio.org/pub/languages/fortran/ch1-5.html . From rNOSPAMon at flownet.com Fri Dec 1 12:39:22 2006 From: rNOSPAMon at flownet.com (Ron Garret) Date: Fri, 01 Dec 2006 09:39:22 -0800 Subject: Functions, callable objects, and bound/unbound methods References: <457065D6.7060406@kentsjohnson.com> Message-ID: In article <457065D6.7060406 at kentsjohnson.com>, Kent Johnson wrote: > Ron Garret wrote: > > The reason I want to do this is that I want to implement a trace > > facility that traces only specific class methods. I want to say: > > > > trace(c1.m1) > > > > and have c1.m1 be replaced with a wrapper that prints debugging info > > before actually calling the old value of m1. The reason I want that to > > be an instance of a callable class instead of a function is that I need > > a place to store the old value of the method so I can restore it, and I > > don't want to start building a global data structure because that gets > > horribly ugly, and a callable class is the Right Thing -- if there's a > > way to actually make it work. > > If the only reason for a callable class is to save a single value (the > original function), you could instead store it as an attribute of the > wrapper function. I considered that, and I may yet fall back on it, but 1) I wanted to understand how these things worked and 2) I need a way to tell when a method has been traced, and isinstance(method, tracer) seems less hackish to me than hasattr(method, 'saved_function'). rg From rampeters at gmail.com Thu Dec 7 15:36:46 2006 From: rampeters at gmail.com (johnny) Date: 7 Dec 2006 12:36:46 -0800 Subject: Multithreaded python script calls the COMMAND LINE Message-ID: <1165523805.955071.246310@80g2000cwy.googlegroups.com> I have python script does ftp download in a multi threaded way. Each thread downloads a file, close the file, calls the comman line to convert the .doc to pdf. Command line should go ahead and convert the file. My question is, when each thread calls the command line, does one command line process all the request, or each thread creates a one command line process for themselves and executes the command? For some reason I am getting "File '1' is alread exists, Do you want to overwrite [y/n]?" I have to manually enter 'y' or 'n' for the python script to complete. From bg_ie at yahoo.com Fri Dec 29 09:23:47 2006 From: bg_ie at yahoo.com (bg_ie at yahoo.com) Date: 29 Dec 2006 06:23:47 -0800 Subject: Python Wrapper for C# Com Object In-Reply-To: <1167313715.296081.133170@n51g2000cwc.googlegroups.com> References: <1167297178.937748.91790@79g2000cws.googlegroups.com> <1167313715.296081.133170@n51g2000cwc.googlegroups.com> Message-ID: <1167402227.920435.3340@a3g2000cwd.googlegroups.com> bg_ie at yahoo.com skrev: > bg_ie at yahoo.com skrev: > > > Hi, > > > > I wish to write a Python wrapper for my C# COM object but am unsure > > where to start. I have a dll and a tlb file, and I can use this object > > in C via the following code - > > > > // ConsolApp.cpp : Defines the entry point for the console application. > > // > > #include "stdafx.h" > > #include "windows.h" > > #include "stdio.h" > > #import "C:\Documents and Settings\X\Mina dokument\Visual Studio > > 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb" > > using namespace X_COMObject; > > > > int _tmain(int argc, _TCHAR* argv[]) > > { > > CoInitialize(NULL); > > > > X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class)); > > XCOM_Interface *X_com_ptr ; > > X_com_ptr = p ; > > X_com_ptr->SetID(10); > > int x = X_com_ptr->GetID(); > > printf("%d",x); > > getchar(); > > > > return 0; > > } > > > > Can anyone offer me some tips as to how to do this in Python? > > > > Thanks very much for your help, > > > > Barry. > > This is what I've done so far, but I know I'm not doing this correctly. > Can anyone help me out? > > #import pythoncom > #pythoncom.CoInitialize() > > from comtypes.client import GetModule, CreateObject > > module = GetModule("C:\\Documents and Settings\\X\\Mina > dokument\\Visual Studio > 2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb") > > dir(module) > > interface = module.XCOM_Interface() > > dir(interface) > > interface.SetID() > > #pythoncom.CoUnitialize() > > > Traceback (most recent call last): > File "C:/Python25/test.py", line 14, in > interface.SetID() > TypeError: Expected a COM this pointer as first argument Can anyone help me with this? Thanks, Barry. From rpdooling at gmail.com Wed Dec 13 19:25:59 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 13 Dec 2006 16:25:59 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> <1166046193.734274.124160@73g2000cwn.googlegroups.com> Message-ID: <1166055959.498100.116240@79g2000cws.googlegroups.com> Fredrik Lundh wrote: > what do you get if you do: > > python -S > ... >>> import sys >>> sys.path ['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\ \Python24'] > and then >>> import site >>> sys.path ['d:\\python', 'C:\\WINDOWS\\system32\\python24.zip', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Pyt hon24', 'C:\\Python24\\lib\\site-packages', 'C:\\Python24\\lib\\site-packages\\win32', 'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\Python24\\lib\\site-packa ges\\Pythonwin', 'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi'] rd From atkinw at rpi.edu Tue Dec 12 23:55:25 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Tue, 12 Dec 2006 23:55:25 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> <4u6meeF161jbqU1@mid.individual.net> Message-ID: greg writes: >>>Having edited both Lisp and Python code fairly >>>extensively, >> >> How extensively? > > Enough to know what I'm talking about. Tens > of thousands of lines of Lisp and Scheme, and > hundreds of thousands of lines of Python, I > would estimate. > > Seeing as you asked, how much Python code have > you or Ken edited? To be honest, very little Python code. But I have manually indented and rearranged enough code in other line-based languages to appreciate the convenience of s-expression-based commands. From pecora at anvil.nrl.navy.mil Mon Dec 11 11:57:05 2006 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Mon, 11 Dec 2006 11:57:05 -0500 Subject: alternate language References: Message-ID: In article , aahz at pythoncraft.com (Aahz) wrote: > In article , > Lou Pecora wrote: > >In article , > > Bryan wrote: > >> > >> what is a good alternate language to learn? i just want something to expand > >> my mind and hopefully reduce or delay any chance of alzheimer's. i would > >> especially like to hear from those of you who learned python _before_ these > >> languages. > >> > >> haskell, erlang, ocaml, mozart/oz, rebel, etc. > > > >I have no experience with any of these. Of course, now I will give my > >opinions. :-) Just based on my experience with Python, C, C++, BASIC > >(several flavors), Fortran 77 (mostly). > > > >> i don't require any of these features, but extra browny points for any of > >> the following: > >> > >> interactive interpreter > > > >Python has several. > > Um... I think the original poster is saying that he already knows Python > and wants to learn another language. He particularly wants opinions from > other people who have learned these languages *after* learning Python. Oh...never mind. :-) -- Lou Pecora (my views are my own) REMOVE THIS to email me. From fredrik at pythonware.com Fri Dec 22 18:55:32 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Dec 2006 00:55:32 +0100 Subject: scopes of local and global variable In-Reply-To: <87tzzncx59.fsf@pyenos.pyenos.org> References: <87tzzncx59.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > #############################CODE############################## > t_len=0 > class WORK: > def getwork(self): > def formattable(table_to_process,type): > TYPE=["p","t","T","s","i"] #list of types to format > if type==TYPE[1]: > def format_t(): > row=[] > for col in table_to_process: > > ####################### > # ERROR PRONE PART # > ####################### > if len(str(col))>t_len: > t_len=len(str(col)) > ####################### > # Error message says: # > # UnboundLocalError: local variable 't_len' referenced before assignment# > > row+=col > if (table_to_process.index(col)+1)%7==0: > t_temp.append(row) > row=[] > format_t() > ################################################################# wow. > Interpreter says that t_len is local variable although i have > specified t_len=0 in line 1. Also, although i've stated t_len=0 in > line 1, it says that t_len is referenced before assignment. each function introduces a new scope. From george.sakkis at gmail.com Tue Dec 12 19:18:10 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 12 Dec 2006 16:18:10 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> Message-ID: <1165969090.648421.177130@16g2000cwy.googlegroups.com> Bill Atkins wrote: > greg writes: > > > When moving a set of statements in Python, you > > are usually selecting a set of complete lines, > > cutting them out and then pasting them in > > between two other lines somewhere else. > > You're missing Ken's point, which is that in Lisp an s-expression > represents a single concept - I can cut out the second form of an IF > and know that I'm cutting the entire test-form. I don't have to > choose the correct "set of complete lines" to correctly move code > around. Why is selecting a valid s-expression easier than selecting a python block ? If you mistakenly select an extra parenthesis or omit one, it's the same thing. Having said that, I find this problem is mostly academic in both languages with modern editors... there are less trivial excuses to keep the flamewar raging ;-) George From bjorn.kempen at gmail.com Tue Dec 26 18:01:40 2006 From: bjorn.kempen at gmail.com (buffi) Date: 26 Dec 2006 15:01:40 -0800 Subject: Persistent variables in python In-Reply-To: References: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> Message-ID: <1167174100.432143.163760@i12g2000cwa.googlegroups.com> > I don't think so, since Python proudly says that functions are > first-class objects. > CherryPy does a similar thing to mark a method as "exposed". > > But perhaps I'd write the code this way to avoid an unneeded and > risky recursive call: > > def doStuff(some, arguments, may, *be, **required): > try: > doStuff.timesUsed += 1 > except AttributeError: > doStuff.timesUsed = 1 > # ... special case for first call ... > # ...common code... True, the recursivity is not needed there I guess :) It just feels so ugly to use try/except to enable the variable but I've found it useful at least once. /buffi (buffis.com) From ptmcg at austin.rr._bogus_.com Fri Dec 1 09:33:04 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 01 Dec 2006 14:33:04 GMT Subject: Win32 Excel Generation Slow References: Message-ID: "Daniel Bowett" wrote in message news:mailman.928.1164969844.32031.python-list at python.org... >I am trying to create an excel document that displays a table of data. It >does exactly what I want but takes a long time. I am writing around 1000 >rows and it takes around a second to do each row. > > Is there a quicker way to write this? The reason I want excel is this > needs to read and manipulated by management. > Are there many many formulas in your worksheet? Try setting calculate to manual, and turn off screenupdating while creating your rows. Then when done, do a manual calculate, and turn auto calc and screenupdating back on. (These are all open to the COM interface, although I don't recall the exact function names.) -- Paul From fumanchu at amor.org Thu Dec 7 00:32:19 2006 From: fumanchu at amor.org (fumanchu) Date: 6 Dec 2006 21:32:19 -0800 Subject: Mod_python vs. application server like CherryPy? References: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> <33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com> <1165445758.342163.37650@f1g2000cwa.googlegroups.com> Message-ID: <1165469539.212818.62670@j72g2000cwa.googlegroups.com> Graham Dumpleton wrote: > For example, consider an extreme case such as WSGI. > Through a goal of WSGI being portability it effectively > ignores practically everything that Apache has to offer. > Thus although Apache offers support for authentication > and authorisation, a WSGI user would have to implement > this functionality themselves or use a third party WSGI > component that does it for them. Another example is > Apache's support for enabling compression of content > returned to a client. The WSGI approach is again to > duplicate that functionality. Similarly with other Apache > features such as URL rewriting, proxying, caching etc etc. Well, almost. I use Auth* directives for authentication (and the Require directive for authorization) with my CherryPy apps. Many other CP users use mod_rewrite and mod_proxy. So the WSGI user doesn't *have* to implement that functionality themselves. Any sufficiently-messianic framework will probably do so ;), but even the best admit there are always alternatives. Robert Brewer System Architect Amor Ministries fumanchu at amor.org From effigies at gmail.com Sat Dec 23 07:23:09 2006 From: effigies at gmail.com (Chris Johnson) Date: 23 Dec 2006 04:23:09 -0800 Subject: Generating all permutations from a regexp In-Reply-To: References: Message-ID: <1166876589.669302.315740@f1g2000cwa.googlegroups.com> BJ?rn Lindqvist wrote: > With regexps you can search for strings matching it. For example, > given the regexp: "foobar\d\d\d". "foobar123" would match. I want to > do the reverse, from a regexp generate all strings that could match > it. > > The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000", > "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999". > > Is this possible to do? Obviously, for some regexps the set of matches > is unbounded (a list of everything that matches "*" would be very > unpractical), but how would you do it for simple regexps like the one > above? For a very small number of characters, it would be feasible. For any finite number of characters, it would be possible (though it wouldn't take much to take longer than the age of the universe). For reference, in your simple example, you have 17,576,000 matching strings. I'm curious as to why you would wish to do this. I certainly understand considering hard problems for their own sake, but when I formulate them, there's always some impetus that makes me say "Huh. Now I wonder..." From ntoronto at cs.byu.edu Sun Dec 10 23:29:30 2006 From: ntoronto at cs.byu.edu (Neil Toronto) Date: Sun, 10 Dec 2006 21:29:30 -0700 Subject: Quake 3 and the Python interpreter Message-ID: <457CDEAA.3020302@cs.byu.edu> So I've recently had a stroke of insanity, deciding that what the open-source Quake III engine *really* needs is a good, healthy dose of Python. Here's the quick version: The Q3 engine is split into the engine (responsible for rendering, sound, networking, input, and collision detection) and the game logic. Currently, the game logic can be loaded as a shared object file (usually for development) or this crazy thing called a QVM: a bytecode file which is either interpreted or JIT-compiled. Using ioquake3 (ioquake3.org) as a base, I added Python to the list. Frankly, I'm not amazed at how much easier it is to code game logic in Python, but some people might be. :D I'm working on the client game, and I'm about 30% done with that part. It looks like it's going to work out very well. It's the coolest thing to be able to pull down the console and type "/py print cg.data.pps.origin" and have it print out your current position. Now that the background is out of the way, I have two questions: 1) Is there a good guide for distributing applications with embedded Python? I'm planning (so far) on putting libpython2.4.so in the executable directory, along with everything from /usr/lib/python2.4 that the interpreter complains about not having. (I'll try to put them in a zip file - sans zipfile.py - if I possibly can.) Is there a nicer way to do this? 2) Is there any way to restrict Python modules from accessing files outside of a sandbox? One of the nice things about Quake 3's QVM files is that they are very, very restricted. They have no concept of a standard C library. This makes some things rather tricky, but also very secure: if the engine doesn't support it, you can't do it. If you download a Quake 3 mod from someone, you can be fairly sure it won't hose your system. In particular, it won't let you access files outside of the game directory. Is there a way I can accomplish something similar in an embedded Python application? I probably only have to make it secure on systems that don't have Python installed. Neil From vasudevram at gmail.com Wed Dec 6 11:25:18 2006 From: vasudevram at gmail.com (vasudevram) Date: 6 Dec 2006 08:25:18 -0800 Subject: Book recommendations In-Reply-To: References: <1165413344.654740.247000@79g2000cws.googlegroups.com> Message-ID: <1165422317.851999.112780@j44g2000cwa.googlegroups.com> >Can someone recommend a Python book for a newbie and perhaps you have a used one for sale? Thank you. A Byte of Python is supposed to be good for beginners too. See http://www.byteofpython.info/ Its also a recommended book on the main Python site www.python.org >From the preface: "This book serves as a guide or tutorial to the Python programming language. It is mainly targeted at newbies (those who are new to computers). It is also useful for experienced programmers who are new to Python. The aim is: If all you know about computers is how to open and save text files, then you should be able to learn Python from this book. If you have previous programming experience, then this book should be useful to get you up to speed on Python. " HTH Vasudev ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vasudev Ram Software consulting and training Dancing Bison Enterprises http://www.dancingbison.com http://jugad.livejournal.com http://dancingbison.blogspot.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~ From eadmund42 at NOSPAMgmail.com Tue Dec 12 14:03:08 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 12:03:08 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Neil Cerutti writes: > >> http://www.gigamonkeys.com/book > > I got stuck (last year) in that book: > > http://www.gigamonkeys.com/book/practical-a-portable-pathname-library.html > > The author didn't do Common Lisp (or me) any favors by drawing my > attention to the pathname library. Yeah, I think his intent was for it to be a nice little practicum to demonstrate how to use the language--unfortunately it dealt with one of the uglier bits of CL. The fact that pathnames are really cool doesn't fix the problem that they are at once overspecified and underspecified. If the standard were revised, that'd be a good candidate right there. This is where having a benevolent dictator for life comes in handy. > I suppose I missed whatever the point was supposed to be in the midst > of the mind-boggling. I meant to get back to it but haven't yet. I pretty much skipped that chapter. The bit where it gets mind-boggling is where he creates ID3-tag reading classes from binary-reading primitives and ends up with a complete ID3 library in very few lines of code. -- Robert Uhl I won't insult your intelligence by suggesting that you really believe what you just said. --William F. Buckley, Jr. From felix.benner at imail.de Thu Dec 28 06:53:54 2006 From: felix.benner at imail.de (Felix Benner) Date: Thu, 28 Dec 2006 12:53:54 +0100 Subject: DOS, UNIX and tabs In-Reply-To: <4593a01b$0$1073$426a74cc@news.free.fr> References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <4593185f$1@nntp.zianet.com> <4593a01b$0$1073$426a74cc@news.free.fr> Message-ID: Christophe Cavalaria schrieb: > Steven D'Aprano wrote: > You gave the reason in your post : because other people who are using > software that doesn't understand tabs as YOU expect them to have problems > with your code. > > Tabs aren't a problem at all as long as nobody else than you edit your code. Sorry, but that's a silly argument. With the same argument we should stop using python alltogether since the usual MBA will understand nothing but VBA. From sjmachin at lexicon.net Sun Dec 3 13:40:54 2006 From: sjmachin at lexicon.net (John Machin) Date: 3 Dec 2006 10:40:54 -0800 Subject: Parsing data from pyserial References: <12n5nt138bcb109@corp.supernews.com> Message-ID: <1165171254.109294.281020@80g2000cwy.googlegroups.com> Grant Edwards wrote: > When something odd seems to be happening with strings, always > print `whatever` rather than whatever > :-) Unholy perlism, Batman! For the benefit of gentle readers who are newish and might not have seen the ` character in Python code outside a string literal, or for those who'd forgotten, there is a cure: | >>> re.sub(r"`(.*?)`", r"repr(\1)", "print `whatever`, `foo`, `bar`") | 'print repr(whatever), repr(foo), repr(bar)' :-) From researchbase at gmail.com Fri Dec 1 13:49:08 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Sat, 2 Dec 2006 00:19:08 +0530 Subject: good documentation about win32api ?? In-Reply-To: <1164995768.963594.206030@73g2000cwn.googlegroups.com> References: <1164988151.675036.308920@j44g2000cwa.googlegroups.com> <1164995768.963594.206030@73g2000cwn.googlegroups.com> Message-ID: On 1 Dec 2006 09:56:09 -0800, olsongt at verizon.net wrote: > http://msdn.microsoft.com covers the API itself, although you need to > transliterate from the C code to python. Exactly! that's where the problem lyes. I am pritty well to do with windows API, I am an a good python programmer, but I can't find the link between the two. there are modules but no good documentation. krishnakant. From pavlovevidence at gmail.com Wed Dec 13 21:10:30 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 13 Dec 2006 18:10:30 -0800 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> Message-ID: <1166062230.798520.135790@f1g2000cwa.googlegroups.com> at wrote: > Well, all I can say that for me as a user it would make sense... Which is, like, step one out of a hundred for getting a syntax change into the language. > Curiosity: in what sense is it redundant? It creates syntactical support for two different ways to do something. If your plan were adopted, then we'd have two different spellings for the same thing: for i in a: if i != 0: use(i) for i in a if i != 0: use(i) Now, redundant syntax isn't a deal breaker by itself. You have to ask what is buys you. In this case, all it does is save you a single level of indentation--that's it. There's no performance benefit. It doesn't simplify logic. It doesn't make the code any more readable of clear. It's only a minor improvement in conciseness. It hardly saves any typing (unless you indent by hand). Even its one clear benefit, saving indentation, is something you can already get with "if not x: continue". Considering how little this syntax change buys, it really doesn't make a lot of sense for a language that places high emphasis on avoiding redundancy. > All solution/workarounds I have seen so far involve creation of new lists > (subsets) adding to more processing/computation/memory usage. Redundant > suggests that you know alternatives that don't do that. > > Does Guido ever change his mind? Yes, but I guarantee "it makes sense for me" isn't going to convince him. By the way, I'd suggest when posting to comp.lang.python and/or python-list in the future, you put your replies beneath the quoted text for the benefit of any future readers (not to mention present readers). Carl Banks From NO_Kroeger at gmx.de Sun Dec 10 05:42:58 2006 From: NO_Kroeger at gmx.de (=?ISO-8859-1?Q?Nils_Oliver_Kr=F6ger?=) Date: Sun, 10 Dec 2006 11:42:58 +0100 Subject: oo problem In-Reply-To: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> Message-ID: <457BE4B2.4000409@gmx.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, many class libraries use a parent attribute for this purpose: class Rectangle (object): __init__(self, parent): #Use the parent as "private": nobody except your own #class should mess around with it ... self._parent = parent The parent of course needs to be an existing Paper instance. You might check whether the given value for parent is indeed a Paper instance in your Rectangle's __init__, otherwise you might get strange AttributeError exceptions when using the parent later. Hope that helps! Nils -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFe+SyRQeuB6ws8wERAuTOAKCPKe8m9BNP7Vf/aFpJSWTfOkF8pQCgvkxG +xmcU+UB7fT0fi8/Jz+o15E= =pW+u -----END PGP SIGNATURE----- From surekap at gmail.com Thu Dec 14 03:00:36 2006 From: surekap at gmail.com (Prateek) Date: 14 Dec 2006 00:00:36 -0800 Subject: how to determine Operating System in Use? In-Reply-To: <1166083112.525809.138860@79g2000cws.googlegroups.com> References: <1166056094.751283.122760@79g2000cws.googlegroups.com> <2006121323105016807-jameshcunningham@gmailcom> <1166083112.525809.138860@79g2000cws.googlegroups.com> Message-ID: <1166083236.920097.323390@80g2000cwy.googlegroups.com> eeps! typo. > if sys.platform == "darwin": > macStuff() > elif sys.platform == "win32": > winStuff() > Not sure what the string is on linux. Just fire up the interpreter and try it. Prateek Prateek wrote: > also try: > > sys.platform > > if sys.platform == "darwin": > macStuff() > elif sys.platform == "win32": > linuxStuff() > > > James Cunningham wrote: > > On 2006-12-13 19:28:14 -0500, nanjundi at gmail.com said: > > > > > > > > > > > On Dec 13, 6:32 pm, "Ian F. Hood" wrote: > > >> Hi > > >> In typically windows environments I have used: > > >> if 'Windows' in os.environ['OS']... > > >> to prove it, but now I need to properly support different environments. > > >> To do so I must accurately determine what system the python instance is > > >> running on (linux, win, mac, etc). > > >> Is there a best practises way to do this? > > >> TIA > > >> Ian > > > > > > I would do this: > > > -------------------- > > > if os.name == ''posix': > > > linuxStuff() > > > elif os.name == 'nt': > > > windowsStuff() > > > elif os.name == 'os2': ... > > > ------------------- > > > os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' > > > > > > -N > > > > Bearing in mind, of course, that Mac will return "posix", too. And > > Cygwin might. Erg. > > > > Best, > > James From bj_666 at gmx.net Fri Dec 15 07:30:58 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Fri, 15 Dec 2006 13:30:58 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <1166176294.981549.309770@73g2000cwn.googlegroups.com> Message-ID: In , Gabriel Genellina wrote: > Be aware that map, filter, and reduce may be dropped in Python 3000. > http://www.artima.com/weblogs/viewpost.jsp?thread=98196 > (and I won't miss them if gone) There are `imap` and `ifilter` in the `itertools` module. I guess/hope they will stay in Python?3000. And Guido already said that ``lambda`` will stay, so maybe he changes his mind about `map` and `filter` too. :-) Ciao, Marc 'BlackJack' Rintsch From steve at rueb.com Tue Dec 5 16:28:22 2006 From: steve at rueb.com (Steve Bergman) Date: 5 Dec 2006 13:28:22 -0800 Subject: About the 79 character line recommendation In-Reply-To: References: <1165348808.807516.201860@j72g2000cwa.googlegroups.com> Message-ID: <1165354102.742108.99490@80g2000cwy.googlegroups.com> Thanks for the responses. The point about 132 columns is good. Pretty much any printer will handle that today, though I reserve the right to change my mind about the utility of 17cpi print after I'm 50. Hopefully, all printers will be at least 1200dpi by then. ;-) --- Yes, I dislike "\" for continuation, and use the implicit continuation between parentheses, braces, etc. wherever possible. I don't mind breaking up comma separated values like function method arguments, but I very much dislike breaking at an "=" sign. (BigLong VariableName = BigLongMethodCallWithALotOfArguments) Come to think of it, though, I'm working mostly in TurboGears (web devel framework) which may not represent python code in general all that well wrt line length. Lot's of lines that are harder to break up than in some other environments, perhaps. --- I'm finding 100 to be a nice balance. It forces me not to be lazy and allow really long lines, but allows me to format so as to make the meaning most clear. From greg at cosc.canterbury.ac.nz Fri Dec 15 01:16:29 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 15 Dec 2006 19:16:29 +1300 Subject: Conditional iteration In-Reply-To: <4580f7f4$0$331$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> Message-ID: <4uet0qF178j3fU2@mid.individual.net> at wrote: > With the current Python syntax, I can create for every two lines of code a > dozen alternative implementations: The "one way to do it" rule seems to be widely misquoted and misunderstood. Of course any Turing-complete programming language is going to provide infinitely many ways of expressing anything. What the "one way" rule is saying is that there is no point in the language going out of its way to provide two syntaxes for something with no clear reason to prefer one or the other in any given situation. Like, for instance, Perl having both "if (condition) statement" and "statement if (condition)". That's exactly the sort of thing you're proposing here, and that's why the "one way" rule-of-thumb suggests it's not a good idea. It's not a hard-and-fast rule; one could argue that list comprehensions violate it, and many people did. Ultimately Guido decided that LCs were a big enough win in certain situations, probably because they bring something from the realm of statements into the realm of expressions. Your proposal doesn't do that -- it just rewrites a pair of statements very slightly to give another statement, and opinions differ on whether it would improve or hurt readability. Furthermore, Guido has considered this exact idea before, promoted using the same arguments, and rejected it, so it's unlikely he would change his mind this time around. -- Greg From nick at craig-wood.com Wed Dec 6 01:33:24 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 06 Dec 2006 00:33:24 -0600 Subject: Subprocess with a Python Session? References: Message-ID: Calvin Spealman wrote: > No matter what I do I cant get the following code to do what I expect. > I hadn't used subprocess t o read and write to pipes of a > still-running app, and I just can't seem to get it right. What gives? > > import subprocess > > p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE) > p.stdin.write('print 10\n') > assert p.stdout.readline() == '10\n' To read and write to a still running app, you'll want to use pexpect probably. http://pexpect.sourceforge.net/ >>> import pexpect >>> p = pexpect.spawn("python") >>> p.expect(">>>") 0 >>> p.sendline("print 10\n") 10 >>> p.readline() ' print 10\r\n' >>> p.readline() '10\r\n' >>> Note that running python under pexpect puts it into interactive mode. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ghashsnaga at gmail.com Sat Dec 2 12:22:28 2006 From: ghashsnaga at gmail.com (Ara Kooser) Date: Sat, 2 Dec 2006 10:22:28 -0700 Subject: text adventure question Message-ID: <2107481c0612020922g1d2ca036t304c10b59590623@mail.gmail.com> I am working on a text adventure game for python to get back into python programming. My version 0.1 used only functions so I could get familiar with how those work. I want to move beyond that. I am not sure what would be a good Python way of handling this. I was wondering if classes would help? What things should be included in the main program? A couple of my goals are: 1) Remove the rooms (or areas) from the main program and have them called in as needed. 2) Remove NPC's and monsters from the main program and have them called in as needed. 3) A way of keeping track of time passing in the game 4) Having the main character info stored somewhere else. Below is pasted a section of my code. Each room is a function that is later called. I included only one room to keep this short. Thanks you for suggestions and your time. Code: #A sample text adventure game #Version 0.1 #By Ara Kooser import random import sys import string #Using global variables for the character #Want to use a function instead stre = 9 con = 8 inte = 11 agl = 14 app = 10 mag = 6 sz = 9 hp = 17 reputation = 0 stealth = False quest1 = False quest2 = False cruse = False poison = False diseased = False ducats = 50 lira = 25 florin = 80 equipment = {'Sword': 1, 'Dagger': 1, 'Walking staff': 1, 'Leather Armor':1} backpack = {'Flint and steel': 1, 'Rations': 7, 'dressing kit': 6, 'waterskin': 2} belt_pouch = {} ##################################################################################### day = False ### Global variables for items ### #grass blades in meadow_1 getGrass_m1 = 0 #mushroom in edge_forest1 getMushroom_ef1 = 0 #orc in forest2 aliveOrc = 0 ##################################################################################### # help function that will give you a list of commands def help(): print "look, examine (object), n, w, e, s, take (item)" print "climb, stealth, fishing, herbalism, forage, haggle" print "field dressing" print "wield (object), attack, flee, close, withdraw, maintain" print "backpack, belt pouch, cs" print "Example: examine book, take ducats, attack orc" def character_sheet(): print """\ ============================================================================ Name: Profession: Social Class: Race: ============================================================================ Strength Constitution Intelligence Agility Appearance Magic Size ============================================================================ Ducats: Lira: Florin: Skills: Forage, Haggle, Stealth, Fishing, Herbalism, Climb, Sword, Staff, Dagger, Field Dressing Equipment: Backpack, Belt Pouch, Run of the Mill Sword, Dagger, Flint&Steel 1 week food, 2 waterskins, walking stick, dressing kit ============================================================================ """ def start(): print ''' SAMPLE TEXT ADVENTURE V0.1 You are the last person to leave the small village of Hommlet. The wooden gate closes behind you and twilight reaches across the land. A dense mist creeps up out of the ground, only to be kept at bay by the watchmens torches. Somewhere deep in the woods lies the foul orcs you have tracked for several days. ''' print def outside1(): global hp global reputation print " Current Hit Points = ",hp print " Current Reputation = ",reputation print ''' You are outside the town gates. The dirt road heads (N)orth to another town several days away. The forest lies (E)ast and (W)est through the meadows. The rumors you heard in town describe the orcs as being to the west. The town's gate is to the (S)outh but it is locked for the night. Type 'help' for a full list of commands.''' print prompt_out1() def out1_desc(): print ''' The fog is growing denser as the sun sets on the meadows. The exits are (N)orth, (E)ast and (W)est.''' print prompt_out1() def prompt_out1(): global day prompt_o1 = raw_input("Type a command: ").lower() try: if prompt_o1 == "help": help() print prompt_out1() elif prompt_o1 == "cs": character_sheet() print prompt_out1() elif prompt_o1 == "status": print " Current Hit Points = ",hp print " Current Reputation = ",reputation prompt_out1() elif prompt_o1 == "backpack": print backpack prompt_out1() elif prompt_o1 == "belt pouch": print belt_pouch prompt_out1() elif prompt_o1 == "equipment": print equipment prompt_out1() ######################################################################################## elif prompt_o1 == "examine fog": print "The fog seems natural enough for this time of year." print prompt_out1() elif prompt_o1 == "examine road": print ''' The road is a well travelled dirt road winding many leagues''' print prompt_out1() elif prompt_o1 == "look": out1_desc() ####################################################################################### elif prompt_o1 == "w": meadow1() elif prompt_o1 == "e": meadow2() elif prompt_o1 == "s": #if day = False print "The town's gate is closed for the night" print prompt_out1() #elif # town_1 elif prompt_o1 == "n": n_road1() ###################################################################################### elif prompt_o1 == "haggle": print "There is no one to haggle with here." promt_out1() elif prompt_o1 == "stealth": print "You try and be stealthy" prompt_out1() else: print "Please choose another command. That command is invalid" print prompt_out1() except ValueError: print "Please choose another command. That command is invalid" print prompt_out1() #there are 5 more rooms that follow using functions start() outside1() -- Quis hic locus, quae regio, quae mundi plaga. Ubi sum. Sub ortu solis an sub cardine glacialis ursae. From Thomas.Ploch at gmx.net Sun Dec 31 06:15:05 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Sun, 31 Dec 2006 12:15:05 +0100 Subject: Question concerning this list [WebCrawler] In-Reply-To: References: Message-ID: <45979BB9.3040407@gmx.net> Marc 'BlackJack' Rintsch schrieb: > In , Thomas Ploch > wrote: > >> Alright, my prof said '... to process documents written in structural >> markup languages using regular expressions is a no-no.' (Because of >> nested Elements? Can't remember) So I think he wants us to use regexes >> to learn them. He is pointing to HTMLParser though. > > Problem is that much of the HTML in the wild is written in a structured > markup language but it's in many cases broken. If you just search some > words or patterns that appear somewhere in the documents then regular > expressions are good enough. If you want to actually *parse* HTML "from > the wild" better use the BeautifulSoup_ parser. > > .. _BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/ Yes, I know about BeautifulSoup. But as I said it should be done with regexes. I want to extract tags, and their attributes as a dictionary of name/value pairs. I know that most of HTML out there is *not* validated and bollocks. This is how my regexes look like: import re class Tags: def __init__(self, sourceText): self.source = sourceText self.curPos = 0 self.namePattern = "[A-Za-z_][A-Za-z0-9_.:-]*" self.tagPattern = re.compile("<(?P%s)(?P[^>]*)>" % self.namePattern) self.attrPattern = re.compile( r"\s+(?P%s)\s*=\s*(?P\"[^\"]*\"|'[^']*')" % self.namePattern) >> You are probably right. For me it boils down to these problems: >> - Implementing a stack for large queues of documents which is faster >> than list.pop(index) (Is there a lib for this?) > > If you need a queue then use one: take a look at `collections.deque` or > the `Queue` module in the standard library. Which of the two would you recommend for handling large queues with fast response times? Thomas From simon at brunningonline.net Thu Dec 14 08:35:58 2006 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 14 Dec 2006 13:35:58 +0000 Subject: Multiple inheritance and __slots__ In-Reply-To: <1166102613.814641.109490@80g2000cwy.googlegroups.com> References: <1166102613.814641.109490@80g2000cwy.googlegroups.com> Message-ID: <8c7f10c60612140535t77c87b4fl8521cc22eb446@mail.gmail.com> On 14 Dec 2006 05:23:33 -0800, jm.suresh at no.spam.gmail.com wrote: > Hi all, > >From the google search, it seems its not possible to do the following. > > >>> class Test1(object): > ... __slots__ = ['a'] > ... > >>> class Test2(object): > ... __slots__ = ['b'] > ... > >>> class Test3(Test1,Test2): > ... __slots__ = ['c'] > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: Error when calling the metaclass bases > multiple bases have instance lay-out conflict > > I just want to make sure that I am using only the attributes a,b and c > from the instances of Test3 . Is there any other hack that could be > done. Difficulty with subclassing is the price you pay for abusing slots. Slots are intended as a performance tweak only, to minimise the memory footprint of classes of which you are going to have a great number of instances. In short - don't do that. -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From scott.daniels at acm.org Tue Dec 26 17:26:42 2006 From: scott.daniels at acm.org (Scott David Daniels) Date: Tue, 26 Dec 2006 14:26:42 -0800 Subject: Splitting lines from a database query In-Reply-To: <45919a3f$0$29329$afc38c87@news.optusnet.com.au> References: <45910d4d$0$16553$afc38c87@news.optusnet.com.au> <459183eb$0$9775$afc38c87@news.optusnet.com.au> <45917f40$1@nntp0.pdx.net> <45919a3f$0$29329$afc38c87@news.optusnet.com.au> Message-ID: <4591975c$1@nntp0.pdx.net> Peter Machell wrote: > I can almost do it this way: > > for x in bar: > fname = x[0] > if fname == "": > fname == "None" > sname = x[1] > if sname == "": > sname == "None" > > print ""+fname+""+""+sname+"" for this: for row in bar: print "%s%s" % ( row[0] or 'None', row[1] or 'None') > Except that I should be using a list and loop to do the null checking, > and it still stops when (I think) it hits a blank value: > TypeError: cannot concatenate 'str' and 'NoneType' objects What's the data and program that does that? --Scott David Daniels scott.daniels at acm.org From mark.dufour at gmail.com Sun Dec 17 06:59:00 2006 From: mark.dufour at gmail.com (Mark Dufour) Date: Sun, 17 Dec 2006 12:59:00 +0100 Subject: Shed Skin 0.0.15 In-Reply-To: <8180ef690612090325x5357080fi2a33b570437358cc@mail.gmail.com> References: <8180ef690612090325x5357080fi2a33b570437358cc@mail.gmail.com> Message-ID: <8180ef690612170359s2863f3a0t10ec27877fa3b24b@mail.gmail.com> Thanks to those that sent in bug reports. This is really, really useful. I already released 0.0.16, with the following improvements: -added frozenset -time.sleep now works on WIN32 -constant-string expressions and __doc__ attributes are made into nice C++ comments -added --nowrap optimization option to ss.py (disables checking for negative indices) -several minor bug-fixes reported by users of 0.0.15 Thanks, Mark. On 12/9/06, Mark Dufour wrote: > Hi all, > > After getting bogged down with work for a few months, I'm finally back > to Shed Skin development. I have just released 0.0.15, with the > following changes: > > -python2.5 support/compatibility > -any, all, conditional expression support > -moved libs to 'lib' dir; made it easier to add modules (see README) > -os.stat, os.path.{split, splitext, isfile, isdir, islink, exists} > compiled from PyPy source > -os.{chdir, rename, stat, lstat} added > -fnmatch module added > -random.{sample, seed} added > -several important bugfixes (e.g. except getopt.GetoptError) > > There's more information about this release and the current state of > Shed Skin on my blog: > > http://shed-skin.blogspot.com/ > > I also started a page on Wikipedia. Maybe a text like this should > replace the one on the Shed Skin website: > > http://en.wikipedia.org/wiki/Shed_Skin > > Projects for the near future are getting 'shuffle-db' working (a > 600-line program to rebuild the database on an ipod shuffle; see my > blog), and converting the 're' module from the PyPy implementation to > C++ using Shed Skin. > > Please try out the new release, and let me know about any > problems/wishes/successes. As always, I am very happy with minimized > pieces of code that fail to compile or should produce a (better) error > or warning message. > > http://mark.dufour.googlepages.com > > > Mark. > -- > "One of my most productive days was throwing away 1000 lines of code" > - Ken Thompson > -- "One of my most productive days was throwing away 1000 lines of code" - Ken Thompson From george.sakkis at gmail.com Fri Dec 8 18:30:27 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 8 Dec 2006 15:30:27 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165617885.632226.104370@j72g2000cwa.googlegroups.com> Message-ID: <1165620627.735304.298500@f1g2000cwa.googlegroups.com> Ken Tilton wrote: > George Sakkis wrote: > > JShrager at gmail.com wrote: > > > >>Okay, since everyone ignored the FAQ, I guess I can too... > >> > >>Mark Tarver wrote: > >> > >>>How do you compare Python to Lisp? What specific advantages do you > >>>think that one has over the other? > >> > >>(Common) Lisp is the only industrial strength language with both pure > >>compositionality and a real compiler. What Python has is stupid slogans > >>("It fits your brain." "Only one way to do things.") and an infinite > >>community of flies that, for some inexplicable reason, believe these > >>stupid slogns. These flies are, however, quite useful because they > >>produce infinite numbers of random libraries, some of which end up > >>being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python > >>is rapidly replacing Perl, and Ruby is simultaneously and even more > >>rapidly replacing Python. Each is closer to Lisp than the last; the > >>world is returning to Lisp and is dragging the flies with it. > >>Eventually the flies will descend upon Lisp itself and will bring with > >>them their infinite number of random libraries, and then things will be > >>where they should have been 20 years ago, but got sidetracked by Tcl > >>and other line noise. > > > > > > I know we shouldn't feed the trolls, but this one was particularly > > amusing to resist the urge. The joke about lisp's world domination in > > some unspecified point in the future never fails to bring a good > > chuckle. I heard it's scheduled right after strong AI and before time > > travel, is this still the plan? A quick look at > > http://www.tiobe.com/tpci.htm may be helpful as a reality check before > > you go back to your ivory tower (interesting how close in ratings and > > growth is the "Lisp/Scheme" entry with another dinosaur, Cobol). > > > > And it interesting that VB is almost three times "better" than Python, > and that a Honda could kick a Lamboghini's ass for it at Laguna Seca: Didn't say better, not even in quotes (and btw, if you're only doing GUI apps in MS, VB is the path of least resistance in many cases, as is PHP for quick'n'dirty web apps). What was funny in the GP's post was the pomposity about "flies eventually descending upon Lisp itself", as if language popularity (or any popularity for that matter) is determined solely by theoretical computer science metrics. George From void.no.spam.com at gmail.com Wed Dec 20 19:19:30 2006 From: void.no.spam.com at gmail.com (void.no.spam.com at gmail.com) Date: 20 Dec 2006 16:19:30 -0800 Subject: TypeError: unbound method must be called with class instance 1st argument Message-ID: <1166660370.705628.30360@79g2000cws.googlegroups.com> I'm a novice at Python, and found some code samples on how to use threads. My script is being run by a product that contains a Jython interpreter. Can someone please explain why I get the following error: Traceback (innermost last): File "/full/path/to/file/GenerateData.py", line 104, in ? File "/full/path/to/file/GenerateData.py", line 34, in __init__ TypeError: unbound method must be called with class instance 1st argument Here are the important pieces of my GenerateData.py script. Note that "scriptinterface" is something provided by the product to allow my script to interface with it. Line 104 is the last line -- the one that creates a GenThread and calls start() on it. import sys # need this section otherwise the import random won't work if sys.path.count('/usr/local/lib/python2.2/') == 0: sys.path.append('/usr/local/lib/python2.2/') import random import time import threading from java.lang import String from jarray import array class GenThread(threading.Thread): def __init__(self, ipAddress, port): threading.Thread.__init__() self.ipAddress = ipAddress self.port = str(port) def run(self): # # code # GenThread(scriptinterface.getSnmpIPAddress(), scriptinterface.getSnmpPort()).start() From address.good.until.2006.dec.22 at justmail.de Sat Dec 9 19:28:36 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Sun, 10 Dec 2006 01:28:36 +0100 Subject: merits of Lisp vs Python In-Reply-To: <%TBeh.331$tv5.155@newsfe11.lga> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: Ken Tilton schrieb: > The last time we went thru this a Pythonista finally said, Oh, I get it. > These five lines of code I have to write all the time (two setup, one > func call, two cleanup) can be collapsed into one or two. The thread > will be hard to miss in Google groups (two years back?) and the epiphany > appears right at the end of the thread. Functional programming is the solution here, not Lisp. You could make that with a new function (in Python), that takes a function (and its args, don't remember the correct syntax). def foo(function, args): setup(1) setup(2) function(args) cleanup(1) cleanup(2) The nice thing in Lisp would now be to save a lambda with the macro. In Python one would fill the name space with throw away functions that get called only one time. Andr? -- From fredrik at pythonware.com Sat Dec 23 08:09:59 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Dec 2006 14:09:59 +0100 Subject: Newbie: what is a usefull IDE for Python on Windows ? In-Reply-To: References: Message-ID: Osiris wrote: > what is a usefull IDE for Python on Windows ? > > I saw Eric mentioned.. is that WinXP or Linux ? > > What does "everybody" use ? http://effbot.org/pyfaq/tutor-whats-the-best-editor-ide-for-python From mcbooczech at gmail.com Mon Dec 18 17:19:21 2006 From: mcbooczech at gmail.com (Petr Jakes) Date: 18 Dec 2006 14:19:21 -0800 Subject: writing serial port data to the gzip file In-Reply-To: <1166407550.026704.324080@79g2000cws.googlegroups.com> References: <1166403993.201955.63290@l12g2000cwl.googlegroups.com> <1166407550.026704.324080@79g2000cws.googlegroups.com> Message-ID: <1166480361.100154.308570@l12g2000cwl.googlegroups.com> Maybe I am missing something. Expect data is comming continually to the serial port for the period say 10min. (say form the GPS), than it stops for 1 minute and so on over and over. I would like to log such a data to the different gzip files. My example was written just for the simplicity (I was trying to demonstrate the problem, it was not the real code and I was really tired trying to solve it by myself, sorry for the bugy example) the better way how to write such a infinite loop can be probably: ===== 8< ===== g=0 x=0 while 1: if not g: x+=1 g=gzip.GzipFile("/root/foofile%s.gz" % x,"w") data=dataOnSerialPort() while data: myFlag=1 g.write(data) data=dataOnSerialPort(): else: if myFlag: g.close() pring g myFlag=0 But it looks like g.close() method does not close the file (while trying to print the g object, it still exists) > Your while loop is discarding result of dataOnSerialPort, so you're > probably writing empty string to the file many times. Typically this > kind of loop are implemented using iterators. Check if your s object > (is it from external library?) already implements iterator. If it does > then > > for data in s: > g.write(data) > > is all you need. If it doesn't, you can use iter to create iterator for > you: > > for data in iter(s.readLine, ''): > g.write(data) > > -- Leo From walter at livinglogic.de Tue Dec 19 08:27:15 2006 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Tue, 19 Dec 2006 14:27:15 +0100 Subject: Is htmlGen still alive? In-Reply-To: <1166474264.348556.118510@n67g2000cwd.googlegroups.com> References: <1166474264.348556.118510@n67g2000cwd.googlegroups.com> Message-ID: <4587E8B3.9080107@livinglogic.de> kgmuller at gmail.com wrote: > Does anybody know whether htmlGen, the Python-class library for > generating HTML, is still being maintained? Or from where it can be > downloaded? The Starship site where it used to be hosted is dead. I don't know if HTMLgen is still alive, but if you're looking for alternatives, you might give XIST a try (http://www.livinglogic.de/Python/xist) Servus, Walter From laurent.pointal at limsi.fr Fri Dec 15 05:53:57 2006 From: laurent.pointal at limsi.fr (Laurent Pointal) Date: Fri, 15 Dec 2006 11:53:57 +0100 Subject: concatenating strings In-Reply-To: <1166179761.991744.89630@j72g2000cwa.googlegroups.com> References: <1166179761.991744.89630@j72g2000cwa.googlegroups.com> Message-ID: EHC a ?crit : > hello! > > since i am a py noob, please bear with me ; ) > > how is it possible to concat a string and an integer in a > print-command? i've tried > > print "This robot is named %s. The current speed setting is %d, and %s > has a lifetime of %d" % (self.name , self.speed , self.name) Four % formating with only three arguments to format. It cannot work... print "This robot is named %s. The current speed setting is %d, and %s has a lifetime of %d" % (self.name , self.speed , self.name, self.lifetime) ... > background is a class named Robot with members speed, name, etc... May try this too: print "This robot is named %(name)s. The current speed setting is %(speed)d, and %(name)s has a lifetime of %(lifetime)d" % self.__dict__ [note: liftefime may be a dynamically calculated value, and should be providen via an accessor attribute] From fredrik at pythonware.com Wed Dec 20 07:33:20 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 13:33:20 +0100 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Sebastian 'lunar' Wiesner wrote: >> you're confusing the shell's "is this file executable" check with the >> loader's "can I execute this file" check: >> >> $ export PATH=.:$PATH >> $ dd if=/dev/zero of=ls count=1 >> 1+0 records in >> 1+0 records out >> $ ls -l ls >> -rw-rw-r-- 1 slab slab 512 Dec 20 03:33 ls >> $ chmod a+x ls >> $ ls >> -bash: ./ls: cannot execute binary file > > ??? > Am I blind or is there really no difference between you shell example an > mine? > As far as I can see, you are doing exactly the same thing as I did... no, I'm showing that a local file marked as executable overrides a shared one, even if the local file isn't actually an executable. > So what are trying to proof? that you're wrong when you claim that the contents of the file matters when using the usual Unix conventions to check if a file is executable. maybe you should read Tim's post and the post he replied to again? From python at hope.cz Mon Dec 11 10:29:27 2006 From: python at hope.cz (Lad) Date: 11 Dec 2006 07:29:27 -0800 Subject: SSH File Transfer Protocol or SFTP Message-ID: <1165850967.059239.109890@j72g2000cwa.googlegroups.com> Is there a module in Python available that I can use for uploading files via SFTP (SSH File Transfer Protocol)? Or do you think that FTP protocol for files uploading is OK? Thank you for replies Lad. From robin at reportlab.com Wed Dec 6 13:30:07 2006 From: robin at reportlab.com (Robin Becker) Date: Wed, 06 Dec 2006 18:30:07 +0000 Subject: Printing Barcodes from webapp? In-Reply-To: References: <1165040626.505772.312350@j72g2000cwa.googlegroups.com> <1165063816.365760.264300@73g2000cwn.googlegroups.com> Message-ID: <45770C2F.9070008@chamonix.reportlab.co.uk> Dennis Lee Bieber wrote: > On Tue, 05 Dec 2006 18:19:58 GMT, Dennis Lee Bieber > declaimed the following in comp.lang.python: > >> Aye, just the Postnet scheme... The difficult part was working out >> the spacing for the dot-matrix printer; the rest was just using the >> Zipcode digits as an index into byte-strings of MX-80 codes. > > I've recently downloaded the 4-state spec from USPS... That thing is > obscene... At least Postnet could be decoded visually with a simple > chart. 4-state distributes bits all over! well the code in reportlab/graphics/barcodes that deals with it should be adaptable if you're interested (only around 300 lines). I have a feeling that the UK/AU 4state codes aren't as exotic, but not having actually implemented them it's hard to say. -- Robin Becker From craigtw.online at gmail.com Wed Dec 6 16:20:14 2006 From: craigtw.online at gmail.com (Craig) Date: 6 Dec 2006 13:20:14 -0800 Subject: Mirror imaging binary numbers Message-ID: <1165440014.762774.167950@73g2000cwn.googlegroups.com> Hi there, I'm trying to switch binary numbers around so that the MSB becomes the LSB etc. Is there an easy way of doing this as I can't seem to find anything. If you could help that would be great. Thanks and good luck. Craig From jan.dries at dcube-resource.be Mon Dec 11 10:51:41 2006 From: jan.dries at dcube-resource.be (Jan Dries) Date: Mon, 11 Dec 2006 16:51:41 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> Message-ID: <457D7E8D.7090108@dcube-resource.be> Bill Atkins wrote: > greg writes: >> On the plus side, Python makes less demands on the >> capabilities of the editor. All you really need >> is block-shifting commands. Bracket matching is >> handy for expressions but not vital, and you >> certainly don't need bracket-based auto-indenting. > > Oh, please. So we should restrict the power of the languages we > choose just to make sure that our code can be edited in Notepad? Perhaps not. The use of a decent editor seems a fair requirement for any language. But one of the things that I dislike about Java, .NET and to some extent XML (XML Schema for instance), is that the only way to really be productive in these languages/environments is to use tools that generate or otherwise manage huge amounts of code for you based on whatever GUI settings. If the language is so complex or verbose that you can't really use it without a GUI tool, then why bother having a language in the first place. Furthermore these tools are typically expensive and to run comfortably they require more processing power and memory than the lightweight ultra-portable type laptops that I like so much can provide. I can't speak about Lisp, but the great thing about Python, IMHO, is that you can get quite far with not much more than Notepad. I find this important because I find GUIs a very tedious and ineffective way to describe whatever it is that I am trying to implement. Perhaps I'm just getting old ... Regards, Jan From stas at legche.net Mon Dec 18 08:53:52 2006 From: stas at legche.net (=?UTF-8?B?0KHRgtCw0L3QuNGB0LvQsNCyINCv0LPQu9C+?=) Date: Mon, 18 Dec 2006 16:53:52 +0300 Subject: How to get a substring with variable indices In-Reply-To: <45869A11.2000709@tim.thechases.com> References: <45868B86.6010804@legche.net> <45869A11.2000709@tim.thechases.com> Message-ID: <45869D70.3040705@legche.net> Tim Chase wrotes: >> I have a string named text. I need to extract a substring from it >> starting by variable 's' and ending by 'e'. >> >> text[s:e] generates the following error: >> >> TypeError: slice indices must be integers or None > > Your syntax is correct...the error you get back is the clue: either > "s" or "e" fails to meet the criteria of being "integers or None". > Check your values/types of those two variables before this call and > you'll likely find that one or both is some other data-type. > > >>> text="hello world" > >>> s = 4 > >>> e = 5 > >>> text[s:e] > 'o' > > Darn those error messages that give away the answer... ;) > > -tkc > > > > > Yeah, you're right! I've already found that stupid error. I've entagled variable names. From jstroud at mbi.ucla.edu Sun Dec 3 19:55:21 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 04 Dec 2006 00:55:21 GMT Subject: Why not just show the out-of-range index? In-Reply-To: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: Russ wrote: > Every Python programmer gets this message occasionally: > > IndexError: list index out of range > > The message tells you where the error occurred, but it doesn't tell you > what the range and the offending index are. Why does it force you to > determine that information for yourself when it could save you a step > and just tell you? This seems like a "no-brainer" to me. Am I missing > something? > I think you have a point. I am curious to see how far people are willing to go to defend this omission. It promises to be entertaining. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From nospam at nospam.com Sun Dec 24 10:56:15 2006 From: nospam at nospam.com (Rad [Visual C# MVP]) Date: Sun, 24 Dec 2006 18:56:15 +0300 Subject: regular expression References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> <4587dc54$0$18460$e4fe514c@dreader31.news.xs4all.nl> <1166967692.801622.295830@n51g2000cwc.googlegroups.com> Message-ID: On Sun, 24 Dec 2006 16:36:31 +0100, Stef Mientki wrote: > Dustan wrote: >> Kleine Aap wrote: >>> Asper Faner wrote: >>> >>>> I seem to always have hard time understaing how this regular expression >>>> works, especially how on earth do people bring it up as part of >>>> computer programming language. Natural language processing seems not >>>> enough to explain by the way. Why no eliminate it ? >>> I.M.H.O. anyone that is not capable to grasp the concept of regular >>> expressions should not attempt to write computer programs at all! My >>> suggestion to you would be to find a job that involves working with your >>> hands... >> >> Your humble opinion doesn't get much ruder... >> >> Perhaps you meant "anyone that is not capable to grasp the concept of >> regular expressions after some experience with programming should not >> attempt to write computer programs at all!" Then at least newbies would >> have a leg to stand on. >> >> Otherwise, you're practically cutting off all entrances into the world >> of programming! The concept of regular expressions isn't exactly the >> simplest one out there. Just because you understood it immediately >> (which I'm guessing you did, considering your harsh response), doesn't >> mean others find the concept that simple. >> > I agree, and in addition: > > (large) regular expressions are easy to write, > but can be almost impossible to read back ! > > I once had a program to generate and evaluate regular expressions, > but can't find it anymore :-( > > If someone has links to regex generators/evaluators, > I'ld be much obliged. > > cheers. > Stef Mientki A good tool to write, test and analyse regexes is the Regulator, available here http://sourceforge.net/projects/regulator/ A good reference site is http://www.regular-expressions.info/, with tutorials, examples and tools -- Bits.Bytes http://bytes.thinkersroom.com From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 22:16:39 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 14:16:39 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <7xejr8r86m.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 09 Dec 2006 14:55:13 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> Now, if you want to tell me that, despite all the talk, Lisp coders don't >> actually create new syntax or mini-languages all that often, that they >> just use macros as functions, then the question becomes: why do you need >> macros then if you are just using them as functions? Why not use functions? > > Macros let you write what amounts to functions that don't evaluate > their arguments. Think of the endless clpy wars over the ternary > conditional operator. [snip] > That is trivial to do with a macro I know that. It was more of a rhetorical question -- Lispers are either trying to emphasis the radical nature of what you can do with macros, or understate it and make them seem just like functions. > but can't be done with a function. *shrug* You can't get to Sydney from Melbourne via Hobart by bicycle either. You either change the requirements (why does it have to be by bicycle?) or the path (why go through Hobart?) or change the infrastructure (build a long, long bridge connecting Hobart to the mainland). That's three tactics for solving the problem of "go from Sydney to Melbourne". It is just not true that the only "correct" solution is to build the bridge. In the case of the ternary operator, changing the language is like building the bridge. It's *a* solution. Maybe it is even the best solution. But it is ludicrous to say that "change the language" is the only solution. (I know you didn't say that -- but so many people seem to think that adding new syntactic support for their pet feature is the only solution to their problem, no matter what the problem. Those people would, I imagine, wet themselves in excitement if Python ever got macros. "Now at last I can make Python look just like the bastard love-child of Perl and Java!" *wink*) -- Steven. From bdesth.quelquechose at free.quelquepart.fr Mon Dec 18 06:02:31 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 18 Dec 2006 12:02:31 +0100 Subject: merits of Lisp vs Python In-Reply-To: <4581a225$0$12642$3b214f66@tunews.univie.ac.at> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <1165593283.523163.71730@16g2000cwy.googlegroups.com> <457b3ca2$0$28520$3b214f66@tunews.univie.ac.at> <457f1b8c$0$7962$426a74cc@news.free.fr> <4581a225$0$12642$3b214f66@tunews.univie.ac.at> Message-ID: <45866f91$0$11026$426a74cc@news.free.fr> Mathias Panzenboeck a ?crit : > Bruno Desthuilliers wrote: > >>Mathias Panzenboeck a ?crit : >> >>>Rob Thorpe wrote: >>> >>> >>>>Mathias Panzenboeck wrote: >>>> >>>> >>>>>Mark Tarver wrote: >>>>> >>>>> >>>>>>How do you compare Python to Lisp? What specific advantages do you >>>>>>think that one has over the other? >>>>>> >>>>>>Note I'm not a Python person and I have no axes to grind here. >>>>>>This is >>>>>>just a question for my general education. >>>>>> >>>>>>Mark >>>>>> >>>>> >>>>>I do not know much about Lisp. What I know is: >>>>>Python is a imperative, object oriented dynamic language with duck >>>>>typing, >>>> >>>>Yes, but Python also supports the functional style to some extent. >>>> >>> >>> >>>I currently visit a course about functional programming at the >>>university of technology vienna: >>>python implements only a small subset of things needed to be called a >>>functional language (list >>>comprehension). >> >>Python has functions as first-class objects (you can pass functions as >>arguments to functions, return functions from functions, and bind >>functions to identifiers), and that's the only thing you need to use a >>functional approach. > > > You mean like function pointers in C and C++? Absolutely not. Python's functions are normal Python objects, instances of the (builtin) class 'function'. FWIW, any object implementing the __call__ method can behave as a function. Python functions can take functions as arguments, and return functions - this is how 'decorators' work. > I think this should be possible in assembler, too. > I thought functional languages have to be declarative? For what definition of 'declarative' ? > The boost C++ library has even lambdas! So does Python - even if in a restricted way. From udodenko at users.sourceforge.net Sat Dec 9 04:16:20 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sat, 9 Dec 2006 11:16:20 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <45797a0c$0$49204$14726298@news.sunsite.dk> <1165593798.079105.144060@80g2000cwy.googlegroups.com> <45799841$0$49201$14726298@news.sunsite.dk> <1165609509.370461.122170@73g2000cwn.googlegroups.com> Message-ID: <457a7ee5$0$49195$14726298@news.sunsite.dk> (message (Hello 'Kay) (you :wrote :on '(8 Dec 2006 12:25:09 -0800)) ( KS> O.K. I agree with what you said about the generic function vs per KS> object dictionary dispatch. KS> But do the performance differences vanish when only builtin types and KS> functions are used to express Python algorithms? no. language semantics require python to do dict lookup on each access to some global function (or builtin) or variable. i don't have enough time for in-depth analysis, but here's what's it. suppose we have def Fib(n): if n < 2: return 1 else: return Fib(n -2) + Fib(n-1) import dis dis.dis(Fib) you will see this: ... 21 LOAD_GLOBAL 1 (Fib) 24 LOAD_FAST 0 (n) 27 LOAD_CONST 2 (1) 30 BINARY_SUBTRACT 31 CALL_FUNCTION 1 34 LOAD_GLOBAL 1 (Fib) 37 LOAD_FAST 0 (n) 40 LOAD_CONST 1 (2) 43 BINARY_SUBTRACT 44 CALL_FUNCTION 1 47 BINARY_ADD 48 RETURN_VALUE now let's check what is LOAD_GLOBAL in ceval.c (i have Python 2.4.1 sources): case LOAD_GLOBAL: w = GETITEM(names, oparg); if (PyString_CheckExact(w)) { /* Inline the PyDict_GetItem() calls. WARNING: this is an extreme speed hack. Do not try this at home. */ long hash = ((PyStringObject *)w)->ob_shash; if (hash != -1) { PyDictObject *d; d = (PyDictObject *)(f->f_globals); x = d->ma_lookup(d, w, hash)->me_value; if (x != NULL) { Py_INCREF(x); PUSH(x); continue; } d = (PyDictObject *)(f->f_builtins); x = d->ma_lookup(d, w, hash)->me_value; if (x != NULL) { Py_INCREF(x); PUSH(x); continue; } goto load_global_error; } } /* This is the un-inlined version of the code above */ x = PyDict_GetItem(f->f_globals, w); if (x == NULL) { x = PyDict_GetItem(f->f_builtins, w); if (x == NULL) { load_global_error: format_exc_check_arg( PyExc_NameError, GLOBAL_NAME_ERROR_MSG, w); break; } } Py_INCREF(x); PUSH(x); continue; so we can see PyDict access. moreover, it's inlined, since it's very performance-critical function. but even inlined PyDict access is not fast at all. ma_lookup is a long and hairy function containing the loop. moreover, we can see that there are two dict lookups -- into globals and builins. lookup into a global hash should about order of magnitude slower than simple table fetch, so here's the root of python's slowness. how lisp can be faster here? lisp has SYMBOLs and well-defined semantics of source code parsing. first source code is processed by reader, that outputs trees of code. each variable or function name becomes a SYMBOL object. symbols are typically interned into packages, but they don't need to be looked-up in the packages in runtime -- in fact, it's not possible at all. i can read a piece of code and then unintern some symbol from package -- that will not make that code invalid. packages are used mostly by reader. (also, i can have many symbols with same name, if they are not interned -- and they will be all different objects) in runtime, lisp has to lookup symbol's function -- but symbol can be implemented as a structure, and symbol-function can be just it's field access. one more thing -- you can see lookup into builins, so they are in dict too! and you can see that builtins dict is checked only if name is not found in globals, so builtins are even slower than globals. that's a reason for performance slowdowns too. one can say that it's the only way to change builtins in runtime. yes, but dict lookup is a big price for it (well, if python use symbols, it would be faster). in fact, Common Lisp also allows to redefine "built-in" function -- you can define a symbol with a same name as builtin in some package and use it, it will "shadow" symbol in the common-lisp package (common-lisp:+). you can change symbol-function of this symbol in runtime and do whatever you want. but symbols in common-lisp package are immutable. that makes it possible to optimize code. and there's inlining. for example, in fib definition: (defun fib (n) (if (< n 2) 1 (+ (fib (- n 2)) (fib (- n 1))))) CLISP does not even use symbol FIB in function bytecodes -- it notes that it's a recursive function calls, so instead of normal function call it does a local jump. ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From george.sakkis at gmail.com Fri Dec 22 12:45:17 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 22 Dec 2006 09:45:17 -0800 Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166741966.242087.192390@n67g2000cwd.googlegroups.com> <1166767205.559937.185260@f1g2000cwa.googlegroups.com> <1166773847.368709.299960@48g2000cwx.googlegroups.com> Message-ID: <1166809517.005569.152950@f1g2000cwa.googlegroups.com> Duncan Booth wrote: > "John Machin" wrote: > > >> > if isinstance(.... > >> > action_for_type1(... > >> > # big snip > >> > elif isinstance(... > >> > action_typeN( ... > >> > # no else statement > >> > >> Ouch.. someone must have skipped his/her OO class... > > > > Quite possibly :-) but that's not the problem here. > > > > The method in question might be called say emit_generic(self, > > any_type_of obj) and so one bunch of isinstance calls is actually > > needed, but not two bunches. So: lose the decorator and add an else and > > a raise at the end. > > > > There is a secondary problem: annoying the crap out of callers who > > often know what type they have and want an emit_real which would take > > an int, a long, or a float and an emit_strg and ... (yes, almost all > > the possible types are that simple) which wouldn't go through even one > > chain of isinstance calls. > > > > I think the point that was being made was that the method's body should be > something like: > > actions[type(arg)](...) > > which not only avoids all of the isinstance calls but also the else and the > raise at the end. Actually my first thought was that the objects being typechecked belong (or could be refactored so that they belong) in a hierarchy so that each action_type_i() could be just an action() method of a subclass (I've actually seen C++ code - apparently from [ex-]C programmers - that uses a private 'kind' field and then builds long switch statements based on 'kind' instead of proper subclassing). But you're right, if the objects in question don't have (and cannot or should not grow) an action() method (e.g. builtins), a dict dispatch based on type is a reasonable choice, at least if you don't care about handling automatically the derived classes. Otherwise you have to simulate the mro(), using something like: class TypeDispatcher(dict): def __call__(self, obj, *args, **kwds): try: # handle both old and new style classes objtype = obj.__class__ except AttributeError: objtype = type(obj) for t in itermro(objtype): if t in self: return self[t](obj, *args, **kwds) raise TypeError('No handler for %r' % objtype.__name__) def itermro(cls): from collections import deque visited = set() queue = deque([cls]) while queue: cls = queue.popleft() yield cls for cls in cls.__bases__: if cls not in visited: visited.add(cls) queue.append(cls) if __name__ == '__main__': class A(object): def foo(self, *args, **kwds): return "A.foo dispatcher(%s,%s)" % (args,kwds) class B(A): def foo(self, *args, **kwds): return "B.foo dispatcher(%s,%s)" % (args,kwds) d = TypeDispatcher() d[A] = lambda self,*args,**kwds: self.foo(*args,**kwds) d[int] = lambda self,*args,**kwds: "int dispatcher(%s, %s, %s)" % (self, args, kwds) for obj in A(), B(), 3: print d(obj, "hello", "world", x=3, y=3.5) George From pavlovevidence at gmail.com Wed Dec 13 14:20:59 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 13 Dec 2006 11:20:59 -0800 Subject: Conditional iteration In-Reply-To: <45804584$0$334$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> Message-ID: <1166037659.362222.290520@t46g2000cwa.googlegroups.com> at wrote: > I am not looking for a work around but more interest if other people might > judge this syntax would come in handy? Of course people have expressed interest in this in the past, but it's not going to happen. There's a way to nest for and if statements, and a different way to nest for and if clauses in listcomps, and the two methods are considered distinct. Although Guido has said that saving indentation levels is important, he hasn't said anything (that I'm aware of) that suggests it's important enough to add this complexity and redundancy to the language. Sorry. Carl Banks From vasudevram at gmail.com Sat Dec 23 10:30:04 2006 From: vasudevram at gmail.com (vasudevram) Date: 23 Dec 2006 07:30:04 -0800 Subject: Elliptic Curve Library In-Reply-To: <1166886752.656666.287470@80g2000cwy.googlegroups.com> References: <1166886752.656666.287470@80g2000cwy.googlegroups.com> Message-ID: <1166887804.668087.128500@48g2000cwx.googlegroups.com> Mike Tammerman wrote: > Hi, > > I need an elliptic curve library that can be used by python. I googled > but couldn't find a one. I'll appreciate, if you could show me. > > Mike What is the library you need supposed to do? Vasudev Ram Dancing Bison Enterprises www.dancingbison.com From jonc at icicled.net Tue Dec 19 14:37:38 2006 From: jonc at icicled.net (Jonathan Curran) Date: Tue, 19 Dec 2006 13:37:38 -0600 Subject: regexp In-Reply-To: References: Message-ID: <200612191337.38625.jonc@icicled.net> On Tuesday 19 December 2006 13:15, vertigo wrote: > Hello > > I need to use some regular expressions for more than one line. > And i would like to use some modificators like: /m or /s in perl. > For example: > re.sub(".*","",data) > > will not cut out all javascript code if it's spread on many lines. > I could use something like /s from perl which treats . as all signs > (including new line). How can i do that ? > > Maybe there is other way to achieve the same results ? > > Thanx Take a look at Chapter 8 of 'Dive Into Python.' http://diveintopython.org/toc/index.html You can modify the code there and get the results that you need. Buy the book if you can :) It has lots of neat examples. - Jonathan Curran From kw at codebykevin.com Wed Dec 20 17:44:43 2006 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 20 Dec 2006 17:44:43 -0500 Subject: Tkinter, StringVar and dict Message-ID: <147e6$4589bcdd$4275d90a$6123@FUSE.NET> I'm trying to manage user preferences in a Tkinter application by initializing some values that can then be configured from a GUI. The values are set up as a dict, like so: self.prefs= { 'interface': '-en1', 'verbose': '-v', 'fontname': 'Courier', 'point': 12, } To link these values to the appropriate Tkinter variables, I'm using code like this: self.prefs['interface'] = StringVar() self.prefs['interface'].set("-en0") # initialize This raises an error in Tkinter: Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__ return self.func(*args) File "/Users/kevin/Programming/packetstream/packetstream-classes.py", line 293, in setPrefs self.prefs['interface'] = StringVar() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 3237, in __setitem__ self.tk.call(self.name, 'configure', '-'+key, value) TclError: unknown option "-interface" Can someone help me smooth this out--to get dict key-values into a Tkinter variable like StringVar()? Thanks. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From jstroud at mbi.ucla.edu Mon Dec 18 05:54:10 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 18 Dec 2006 10:54:10 GMT Subject: Why there isn't a sort method for array ? In-Reply-To: <1166399935.226971.38680@n67g2000cwd.googlegroups.com> References: <1166399935.226971.38680@n67g2000cwd.googlegroups.com> Message-ID: John Machin wrote: > Tim Roberts wrote: >> "fdu.xiaojf at gmail.com" wrote: >>> It seems that an array acts like an list very much, except it doesn't >>> have a method sort. >> What do you mean by "array"? There is no such beast in the Python >> language. Do you mean the library module "array"? >> > > Indubitably the OP means objects created by the array function in the > array module. Does that help you answer his question? > > Cheers, > John > Yep. Seems like there should be a sort() for array.array objects, especially since they implement pop(), insert(), extend(), etc. Also, all data types corresponding to array typecodes can be compared in a sort: . In the mean time, try my_sorted_array = array.array(my_array.typecode, sorted(my_array)) James From kentilton at gmail.com Fri Dec 8 14:48:50 2006 From: kentilton at gmail.com (Ken Tilton) Date: Fri, 08 Dec 2006 14:48:50 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4ttqsoF15ld61U3@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> Message-ID: Bjoern Schliessmann wrote: > Alex Mizrahi wrote: > >>(message (Hello 'Bjoern) > > >>> BS> Can you give an example? I cannot imagine how homogenity >>> always BS> results in easiness. > > > >>homogenity means that i can cut any expression and paste in any >>other expression, and as long as lexical variables are ok, i'll >>get correct results -- i don't have to reindent it or whatever. > > > Ah, so *that's* what you meant ... but I don't really understand the > ease of it. Code in the abstract exists as a tree of trees. With parens, we now have textual markers delimiting these trees. That means I can point to any arbitrary subtree by pointing to its left or right parens, and tell the editor to copy or delete "that chunk of logic". And now I am manipulating chunks of program logic instead of text. One simple but hopefully illustrative example: suppose I have an if statement with two big branches. My code then looks like: (if (condition) (big-branch-1)(big-branch-2)) Please remember that any of those fakes can be arbitrarily deep nested expressions. Now during refactoring, I decide bb-2 processing goes elsewhere, maybe somewhere "upstream" in the logic. So I double-click and then drag-and-drop, or cut and paste. Then I double-click on the entire if statement, and then do a control-click on the "then" condition, control-click happening to mean "paste what I am clicking". Suddenly the "then" is the whole form. (And, yes, this means my vendor took away from me the normal copy-and-drop associated with control click , but I could modify things to get it back if I really cared.) Of course the next question has to be, how often does that come up? When refactoring it sometimes feels like I do nothing else. :) It turns out that this is an insanely natural way to work with code. Note also that after any amount of dicing I simply hit a magic key combo and the editor reindents everything. In a sense, Lisp is the language that handles indentation best. hth, ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From grante at visi.com Mon Dec 11 21:42:54 2006 From: grante at visi.com (Grant Edwards) Date: Tue, 12 Dec 2006 02:42:54 -0000 Subject: alternate language References: <12nr93mis39tu45@corp.supernews.com> Message-ID: <12ns5pea5d84f4a@corp.supernews.com> On 2006-12-11, Aahz wrote: > Grant Edwards wrote: >>> Um... I think the original poster is saying that he already knows Python >>> and wants to learn another language. He particularly wants opinions from >>> other people who have learned these languages *after* learning Python. >> >>There are people who learn another language after learning Python?? > > Heh. Taking your post more seriously than it deserves, It was intended as a joke. :) > don't you think someone ought to learn at least SQL if they > don't already know it when they learn Python? More seriously, I would have suggested Scheme, Prolog, Smalltalk, and possibly APL -- but those are all pretty old-school. -- Grant Edwards grante at visi.com From skip at pobox.com Tue Dec 26 23:58:44 2006 From: skip at pobox.com (skip at pobox.com) Date: Tue, 26 Dec 2006 22:58:44 -0600 Subject: module with a threading-like api that uses processes? Message-ID: <17809.64900.778410.770633@montanaro.dyndns.org> I could have sworn someone was working on a module recently with a threading-like API that used subprocesses under the covers, but 10 minutes or so of googling didn't yield anything. Pointers appreciated. Thx, Skip From fredrik at pythonware.com Thu Dec 14 12:29:47 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 18:29:47 +0100 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: Nick Maclaren wrote: > Guido's response is fine - we didn't because we didn't think that it > was worth doing. One can dissent, but it makes perfect sense. so which Guido should you trust more? the "tuples should not be used for arrays of homogeneous data" and "searching tuples doesn't make sense" guy seen e.g here: http://mail.python.org/pipermail/python-dev/2002-January/019664.html http://mail.python.org/pipermail/python-dev/2003-March/033964.html http://mail.python.org/pipermail/python-dev/2003-March/033972.html or that "we didn't add list methods to tuples because we're lazy" guy? From llee4131 at users.sourceforge.net Thu Dec 28 15:41:16 2006 From: llee4131 at users.sourceforge.net (Pyenos) Date: 29 Dec 2006 07:41:16 +1100 Subject: answers.py v0.0.1 - source References: <87bqloz3fy.fsf@pyenos.pyenos.org> Message-ID: <87hcvfda8j.fsf@pyenos.pyenos.org> #!/usr/bin/python ################################################################ # answers.py --- A simple answer-bot. # Copyright 2006 Logan Lee # # RELEASE NOTES: # # - I have fixed an error where the program crashes on query of #+unknown string to answers dictionary. # - Rephrased 'Do you have a problem?' message in menu to #+"What is your problem?" # # MESSAGE: # # Now the program is perfectly usable to an extent that was #+intended! Previous advice on the code v0.01 is by in large #+not implemented in this version, but I will learn from it. #+Thanks. # ################################################################ ################################################################ # IMPORTANT: DON'T FORGET TO SET ANSWER_PATH TO YOUR PREFERENCE! global ANSWER_PATH ANSWER_PATH="" ################################################################ VERSION="0.01001" class Problem: def __init__(self):self.problem="" def set(self,problem):self.problem=problem def get(self):return self.problem class Solution: def __init__(self):self.solution="" def set(self,solution):self.solution=solution def get(self):return self.solution class Storage: def add(self,problem,solution): self.answers[problem]=solution def save(self): import pickle try: pickle.dump(self.answers,file(ANSWER_PATH+".answers","w"));print "Answers saved" except: print "Couldn't save answers. Something went wrong" def load(self): import pickle try: self.answers=pickle.load(file(ANSWER_PATH+".answers"));print "Answers loaded" except: print "Couldn't load answers. Something went wrong or this may be your first time running" def getAnswer(self,problem): answer="" try: answer=self.answers[problem] except: print "I don't have the answer to that problem" return answer def __init__(self,answers={}): self.answers=answers class Console: class Menu: global storage storage=Storage() class Level0: def do(self): import sys action=sys.exit() class Level1: def do(self): problem=Problem();solution=Solution() text=("What is your problem? $ ","Do you have the solution? $ ","no idea","Try again with your common sense") commands=("answer","load(disabled, already loaded)","quit","help") problem.set(raw_input(text[0])) if problem.get()==commands[0]:return 4 #elif problem.get()==commands[1]:storage.load();return 1 elif problem.get()==commands[2]:return 0 elif problem.get()==commands[3]:print commands;return 1 solution.set(raw_input(text[1])) if solution.get()==text[2]:print text[3];solution.set(raw_input(text[1])) if raw_input("Your solution to '%s' is '%s', correct? $ " % (problem.get(),solution.get()))=="yes":storage.add(problem.get(),solution.get());print "Answer confirmed";return 2 else: return 1 class Level2: def do(self): if raw_input("Should I save the answer? $ ")=="yes": storage.save() return 3 else: return 1 class Level3: def do(self): text=("Do you have another problem?"+" $ ","Do you want to quit?"+" $ ") if raw_input(text[0])=="yes": return 1 elif raw_input(text[1])=="yes":return 0 else: return 3 class Level4: def do(self): text=("What answer do you seek? $ ","Do you want to ask again? $ ") problem=raw_input(text[0]);answer=storage.getAnswer(problem) print "Answer to '%s' is '%s'" % (problem,answer) if raw_input(text[1])=="yes":return 4 else: return 1 def start(self): storage.load() level=1 while 1: if level==0: Console.Menu.Level0().do() if level==1: level=Console.Menu.Level1().do() if level==2: level=Console.Menu.Level2().do() if level==3: level=Console.Menu.Level3().do() if level==4: level=Console.Menu.Level4().do() def start(self):Console.Menu().start() if __name__=="__main__": Console().start() -- Logan Lee aka Pyenos From m.sloyko at gmail.com Fri Dec 8 06:24:17 2006 From: m.sloyko at gmail.com (Maxim Sloyko) Date: 8 Dec 2006 03:24:17 -0800 Subject: apache & mod_python References: <4579472d$0$5066$ba4acef3@news.orange.fr> Message-ID: <1165577057.325812.47140@f1g2000cwa.googlegroups.com> m.banaouas wrote: > Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent > versions) without facing any known major issue ? Works fine for me. The only "known major issue" you can face is general non-threadsafety of Python interpreter. So, if you are using Apache MPM, you have to allow for it, or use framework that does it for you. From lepto.python at gmail.com Sat Dec 23 23:39:11 2006 From: lepto.python at gmail.com (oyster) Date: Sun, 24 Dec 2006 12:39:11 +0800 Subject: some OT: how to solve this kind of problem in our program? Message-ID: <6a4f17690612232039r4c8b5f99r6985885ebaba062e@mail.gmail.com> 1. first of all, what is the English jargon (Optimize? But I think this is not a very good keyword :( )for this problem? So I can use it to search on the internet 2. is there any free/open lib for this? 3. I know for some questions(case 1, case 2, and sudoku), we can use bundles of "FOR...NEXT" loop to program. however I think it is clumsy and inconvenient, especially when there is many vars 4. I don't know how to deal with case 3 and case 4 case: 1. choose x0~x9 from 1~9, and must use all of 1~9, let x0/(10*x1+x2)+x3/(10*x4+x5)+x6/(10*x7+x8)=1/2 2. choose x0~x15 from 1~16, and must use all of 1~16, let +-----+-----+-----+-----+ | x0 | x1 | x2 | x3 | +-----+-----+-----+-----+ | x4 | x5 | x6 | x7 | +-----+-----+-----+-----+ | x8 | x9 | x10 | x11 | +-----+-----+-----+-----+ | x12 | x13 | x14 | x15 | +-----+-----+-----+-----+ sum of every column =sum of of every row = x0+x5+x10+x11 =x3+x6+x9+x12 3: calculate the minimum of sin((z*x-0.5)^2 + x*2*y^2-z/10)*exp(-((x-0.5-exp(-y+z))^2 + y^2-z/5+3)) where x in [-1,7], y in [-2,2] 4: calculate the root [x,y,z], let (x-0.3)^y^z+x/y/z-x*y*sin(z)+(x+y-z)^cos(x-1) = 1 (y-0.2)^z^x+y/z/x-y*z*sin(x)+(y+z-x)^cos(y-2) = 2 (z-0.1)^x^y+z/x/y-z*x*sin(y)+(z+x-y)^cos(z-3) = 3 I have written the case 1 in python, it needs 90 seconds on my pc, and the same approach in www.freebasic.net takes less than 1 seconds [code for python] import sets import time try: import psyco psyco.full() except: pass d0, d1=1, 2 st=time.time() result=[] for a0 in range(1,10): for a1 in sets.Set(range(1,10))-sets.Set([a0]): for a2 in sets.Set(range(1,10))-sets.Set([a0,a1]): a1a2=a1*10+a2 if 2*a0< a1a2: for b0 in sets.Set(range(1,10))-sets.Set([a0,a1,a2]): for b1 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0]): for b2 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1]): b1b2=b1*10+b2 if 2*a0*b1b2 + 2*b0*a1a2 < a1a2*b1b2: for c0 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1, b2]): for c1 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1, b2, c0]): for c2 in sets.Set(range(1,10))-sets.Set([a0,a1,a2,b0, b1, b2, c0, c1]): c1c2=c1*10+c2 if d1*a0*b1b2*c1c2 + d1*b0*a1a2*c1c2 + d1*c0*a1a2*b1b2 == d0*a1a2*b1b2*c1c2: aresult=[[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] aresult.sort() if aresult not in result: result.append(aresult) et=time.time() print 'time elapsed: %s s' % (et-st) for [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] in result: print ' %0d %0d %0d %0d' % (a0, b0, c0, d0) print '--- + --- + --- = ---' print ' %0d%0d %0d%0d %0d%0d %0d' %(a1, a2, b1, b2, c1,c2, d1) print [/code] From joncle at googlemail.com Fri Dec 1 17:37:28 2006 From: joncle at googlemail.com (Jon Clements) Date: 1 Dec 2006 14:37:28 -0800 Subject: route planning In-Reply-To: References: Message-ID: <1165012648.716909.39820@16g2000cwy.googlegroups.com> It's not really what you're after, but I hope it might give some ideas (useful or not, I don't know). How about considering a vertex as a point in space (most libraries will allow you to decorate a vertex with additonal information), then creating an edge between vertices, which will be your 'path'. You can then decorate the edge with information such as distance/maximum speed etc... Then all you need to do is use an A* path algorithm or shortest path search to get the shortest / most efficient route.... You might need a custom visitor to suit the 'weight'/'score' of how efficient the path is. I know this probably isn't of much help, but I hope it comes in useful; I've only ever used Boost.Graph (which is C++, but I believe it has a Python binding) and that was for something else -- although I do recall it had examples involving Kevin Bacon and dependency tracking etc... so a good old Google might do you some good -- ie, it's not completely related, but it might give you a few extra things to search on... All the best with the search. Jon. PS. If you do find a library, can you let me know? I'd be interested in having a play with it... From grahamd at dscpl.com.au Wed Dec 6 19:32:14 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 6 Dec 2006 16:32:14 -0800 Subject: Mod_python vs. application server like CherryPy? References: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> <33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com> <1165445758.342163.37650@f1g2000cwa.googlegroups.com> Message-ID: <1165451534.184166.78080@80g2000cwy.googlegroups.com> Vincent Delporte wrote: > On 6 Dec 2006 14:55:58 -0800, "Graham Dumpleton" > wrote: > >Although WSGI is an extreme case because of the level it pitches at, > >other systems such as CherryPy and Django aren't much different as they > >effectively duplicate a lot of stuff that could be achieved using more > >basic functionality of Apache as well. > > Mmm... So how can I use those goodies from Apache? Just through their > configuration files, or do I have to somehow call them from Python? > > Is the fact that Python developers tend to ignore resources in Apach > due to difficulties in making calls from Python, making the scripts > unpythonic? It depends on what you are doing. For example, if you need to do URL rewriting, you use the mod_rewrite module for Apache, not that it is the most pleasant thing to use. If you need to proxy through some subset of requests to a downstream web server, use mod_proxy. If you need to compress content going back to clients, use mod_deflate. If you need to do caching you use mod_cache. How to configure each of these from the Apache configuration files, you need to look at the Apache httpd documentation at httpd.apache.org. Some, like mod_proxy and mod_deflate can be triggered from within mod_python although finding the magic required isn't always straight forward. How you setup responses can also control mod_cache. If anything, the reason that Python developers tend to ignore a lot of what Apache has to offer is that it means understanding Apache. The Apache documentation isn't always the easiest thing to understand and for some things it even requires looking at the Apache source code to work out how to do things. The mod_python documentation at the moment doesn't help either, as it doesn't provide much in the way of recipes for doing things. The new mod_python wiki will hopefully address that over time, but right now the mod_python mailing lists are the best it gets. In terms of whether it is 'unpythonic', what should be more important is whether it gets the job done in a way that makes best use of what is available. If you want something to be 'pythonic', then using Apache as a framework probably isn't what you want, as as I said previously it becomes more about integrating things rather than writing pure Python code. Getting perhaps back to the answer you were seeking right back at the start, that is if you are new to web application and development and Python, then you may well be better of just using a higher level framework as they will make it easier and isolate you from any pains in understanding Apache and how to use it properly. Graham From gagsl-py at yahoo.com.ar Wed Dec 13 16:35:13 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 13 Dec 2006 18:35:13 -0300 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1166015447.721253.9680@80g2000cwy.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061213180238.05812638@yahoo.com.ar> At Wednesday 13/12/2006 10:10, BartlebyScrivener wrote: > > Python does *not* use the Path when searching for modules; sys.path is > > initialized based on the contents of PYTHONPATH, the location of the > > Python executable (or PYTHONHOME), some heuristics, and certain registry > > entries. > >Now I'm stumped. Unless it's heuristics. The registry entry for >PythonPath does NOT reference the location of my Python scripts >(d:/Python). And Python is installed in the usual place on C:\Python24. >The only place that I can see where I've told it the location of my >scripts is in the Path variable. > >I have no doubt that you're correct. Just confused as usual. import sys print sys.path and see what's there. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From felipe.lessa at gmail.com Sat Dec 2 13:53:42 2006 From: felipe.lessa at gmail.com (Felipe Almeida Lessa) Date: Sat, 2 Dec 2006 16:53:42 -0200 Subject: global name 'self' is not defined In-Reply-To: <1165084948.125632.121260@79g2000cws.googlegroups.com> References: <1165084948.125632.121260@79g2000cws.googlegroups.com> Message-ID: On 2 Dec 2006 10:42:28 -0800, Evan wrote: > Why is it that the first call works fine, but the second tells me > 'global name 'self' is not defined'? What I want is to have the > dictionary 'estoc' available in my calling script. Well, you have not posted the code that is causing the problem, nowhere in your mail there's a reference to "self". -- Felipe. From john106henry at hotmail.com Wed Dec 13 17:49:44 2006 From: john106henry at hotmail.com (John Henry) Date: 13 Dec 2006 14:49:44 -0800 Subject: Iterating over several lists at once In-Reply-To: <1166035250.709872.135350@t46g2000cwa.googlegroups.com> References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> <1166021513.479174.113630@80g2000cwy.googlegroups.com> <1166035250.709872.135350@t46g2000cwa.googlegroups.com> Message-ID: <1166050184.791028.52610@j72g2000cwa.googlegroups.com> Carl Banks wrote: > > The function can be extended to allow arbitrary arguments. Here's a > non-minmal recursive version. > > def cartesian_product(*args): > if len(args) > 1: > for item in args[0]: > for rest in cartesian_product(*args[1:]): > yield (item,) + rest > elif len(args) == 1: > for item in args[0]: > yield (item,) > else: > yield () > > Very nice. From kbk at shore.net Fri Dec 22 00:14:17 2006 From: kbk at shore.net (Kurt B. Kaiser) Date: Fri, 22 Dec 2006 00:14:17 -0500 (EST) Subject: Weekly Python Patch/Bug Summary Message-ID: <200612220514.kBM5EH59004389@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 420 open ( +6) / 3510 closed (+12) / 3930 total (+18) Bugs : 944 open ( -5) / 6391 closed (+15) / 7335 total (+10) RFE : 249 open ( +2) / 245 closed ( +0) / 494 total ( +2) New / Reopened Patches ______________________ cp720 encoding map (2006-12-16) http://python.org/sf/1616979 opened by Alexander Belchenko urllib HTTPS Basic authentication fix (2006-12-17) CLOSED http://python.org/sf/1617413 opened by Dug Song The ability to keep configuration files intact (2006-12-17) CLOSED http://python.org/sf/1617496 opened by Roman Kurakin extended slicing for bytes objects (2006-12-18) CLOSED http://python.org/sf/1617678 opened by Thomas Wouters slice-object support for sre_parse.SubPattern (2006-12-18) CLOSED http://python.org/sf/1617680 opened by Thomas Wouters specialcase simple sliceobj in tuple/str/unicode (2006-12-18) http://python.org/sf/1617682 opened by Thomas Wouters specialcase simple sliceobj in list (and bugfixes) (2006-12-18) http://python.org/sf/1617687 opened by Thomas Wouters Extended slicing for UserString (2006-12-18) http://python.org/sf/1617691 opened by Thomas Wouters Extended slicing for array objects (2006-12-18) http://python.org/sf/1617698 opened by Thomas Wouters slice-object support for ctypes Pointer/Array (2006-12-18) http://python.org/sf/1617699 opened by Thomas Wouters slice-object support for mmap (2006-12-18) http://python.org/sf/1617700 opened by Thomas Wouters extended slicing for structseq (2006-12-18) http://python.org/sf/1617701 opened by Thomas Wouters extended slicing for buffer objects (2006-12-18) http://python.org/sf/1617702 opened by Thomas Wouters add None values in SimpleXMLRPCServer (2006-12-19) http://python.org/sf/1618485 opened by Maximiliano Curia sys.intern() 2to3 fixer (2006-12-19) CLOSED http://python.org/sf/1619049 opened by Georg Brandl fix urllib to raise IOError correctly (2006-12-20) CLOSED http://python.org/sf/1619247 opened by Dug Song Bug fixes for int unification branch (2006-12-20) http://python.org/sf/1619846 opened by Adam Olsen Improve platform.py usability on Windows (2006-12-21) http://python.org/sf/1620174 opened by Luke Dunstan Patches Closed ______________ urllib HTTPS Basic authentication fix (2006-12-17) http://python.org/sf/1617413 closed by akuchling The ability to keep configuration files intact (2006-12-17) http://python.org/sf/1617496 closed by loewis extended slicing for bytes objects (2006-12-18) http://python.org/sf/1617678 closed by twouters slice-object support for sre_parse.SubPattern (2006-12-18) http://python.org/sf/1617680 closed by twouters BZ2File.seek() fails for large files (2006-12-14) http://python.org/sf/1615868 closed by akuchling 1572210 doc patch (2006-11-21) http://python.org/sf/1600491 closed by akuchling cookielib: lock acquire/release try..finally protected (2006-10-30) http://python.org/sf/1587139 closed by akuchling sys.intern() (2006-11-23) http://python.org/sf/1601678 closed by gbrandl sys.intern() 2to3 fixer (2006-12-19) http://python.org/sf/1619049 closed by gbrandl tarfile.py fix for #1471427 and updates (2006-05-09) http://python.org/sf/1484695 closed by gbrandl encoding directive -- more examples (2006-12-11) http://python.org/sf/1613352 closed by gbrandl fix urllib to raise IOError correctly (2006-12-20) http://python.org/sf/1619247 closed by gbrandl New / Reopened Bugs ___________________ Wrong pathname value in logging output (2006-12-15) http://python.org/sf/1616422 reopened by simleo Wrong pathname value in logging output (2006-12-15) http://python.org/sf/1616422 reopened by simleo Wrong pathname value in logging output (2006-12-15) http://python.org/sf/1616422 opened by Tekkaman Vague description of generator close() method (2006-12-15) CLOSED http://python.org/sf/1616726 opened by Lenard Lindstrom Instance methods compare equal when their self's are equal (2006-12-16) http://python.org/sf/1617161 opened by Frank Niessink test_logging hangs on cygwin (2006-04-06) http://python.org/sf/1465643 reopened by tebeka missing word in "sqlite3-Module-Contents"-documentation? (2006-12-18) CLOSED http://python.org/sf/1618083 opened by lgvienna HMAC can get a 6x performance increase easily (2006-12-18) CLOSED http://python.org/sf/1618455 opened by Ben Maurer bisect on presorted list (2006-12-19) http://python.org/sf/1619060 opened by Jeffrey C. Jacobs 64-bit Universal Binary build broken (2006-12-19) http://python.org/sf/1619130 opened by Thomas Treadway format error in 2.5 ref.pdf in section 5.3.4 Calls (2006-12-20) http://python.org/sf/1619641 opened by cwm42 htonl, ntohl don't handle negative longs (2006-12-20) http://python.org/sf/1619659 opened by Adam Olsen Minor error in sum() docs (2006-12-20) CLOSED http://python.org/sf/1619674 opened by Kent Johnson ctypes in_dll documented with wrong argument order (2006-12-20) CLOSED http://python.org/sf/1619680 opened by Lenard Lindstrom Bugs Closed ___________ Wrong pathname value in logging output (2006-12-15) http://python.org/sf/1616422 closed by vsajip Vague description of generator close() method (2006-12-15) http://python.org/sf/1616726 closed by akuchling AttributesImpl does not implement __contains__ on Linux (2006-12-13) http://python.org/sf/1614387 closed by gbrandl IA64/AMD64/x64 confusion (2006-12-15) http://python.org/sf/1616109 closed by loewis Python socket library confused by IPV6 notation in /etc/host (2006-11-27) http://python.org/sf/1603527 closed by loewis missing word in "sqlite3-Module-Contents"-documentation? (2006-12-18) http://python.org/sf/1618083 closed by akuchling HMAC can get a 6x performance increase easily (2006-12-18) http://python.org/sf/1618455 closed by akuchling recv_into not documented (2006-12-11) http://python.org/sf/1613651 closed by akuchling random.randrange don't return correct value for big number (2006-11-05) http://python.org/sf/1590891 closed by rhettinger Minor error in sum() docs (2006-12-20) http://python.org/sf/1619674 closed by akuchling ctypes in_dll documented with wrong argument order (2006-12-20) http://python.org/sf/1619680 closed by akuchling Problem with tapedevices and the tarfile module (2005-11-21) http://python.org/sf/1362587 closed by esshenrik resolver not thread safe (2002-04-04) http://python.org/sf/539175 closed by dustin New / Reopened RFE __________________ Improve list comprehensions to Language Integrated Query? (2006-12-19) http://python.org/sf/1618676 opened by JettLogic From gagsl-py at yahoo.com.ar Mon Dec 18 13:30:34 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 18 Dec 2006 15:30:34 -0300 Subject: Script to upload Files via http/cgi In-Reply-To: References: Message-ID: <7.0.1.0.0.20061218153011.0400fb38@yahoo.com.ar> At Monday 18/12/2006 12:30, Richard Konrad wrote: >Does anyone know about a python-script to upload Files via http/cgi? See the urllib2 module. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From ddvlad at gmail.com Sun Dec 17 04:57:22 2006 From: ddvlad at gmail.com (Vlad Dogaru) Date: 17 Dec 2006 01:57:22 -0800 Subject: Control-C alternative in Windows Message-ID: <1166349442.480528.104810@f1g2000cwa.googlegroups.com> Hello, I've written a simple, standalone wiki server in Python. It runs a BaseHTTPServer's serve_forever() method until a KeyboardInterrupt is caught, at which point it writes changes to a file and exits. This works as expected in Linux. However, in Windows I cannot stop the script with Control-C. I've only been able to stop it with Ctrl-Break, which does not send KeyboardInterrupt. This means no saving to the file and effectively a useless script. Any ideas as to how I might make this work in Windows? Thanks in advance, Vlad From significants at gmail.com Wed Dec 13 01:14:20 2006 From: significants at gmail.com (Simon Schuster) Date: Tue, 12 Dec 2006 22:14:20 -0800 Subject: not a big deal or anything, but, curiously: Message-ID: <5c1d2d910612122214w22220f3fk6c5acfd1cfca7d6b@mail.gmail.com> following this tutorial, I copied and pasted: from string import * cds = """atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaaa tttcgggtgccgacctgacgcgcccgttaagcgataatcagtttgaacagctttaccatgcggtg ctgcgccatcaggtggtgtttctacgcgatcaagctattacgccgcagcagcaacgcgcgctggc ccagcgttttggcgaattgcatattcaccctgtttacccgcatgccgaaggggttgacgagatca tcgtgctggatacccataacgataatccgccagataacgacaactggcataccgatgtgacattt attgaaacgccacccgcaggggcgattctggcagctaaagagttaccttcgaccggcggtgatac gctctggaccagcggtattgcggcctatgaggcgctctctgttcccttccgccagctgctgagtg ggctgcgtgcggagcatgatttccgtaaatcgttcccggaatacaaataccgcaaaaccgaggag gaacatcaacgctggcgcgaggcggtcgcgaaaaacccgccgttgctacatccggtggtgcgaac gcatccggtgagcggtaaacaggcgctgtttgtgaatgaaggctttactacgcgaattgttgatg tgagcgagaaagagagcgaagccttgttaagttttttgtttgcccatatcaccaaaccggagttt caggtgcgctggcgctggcaaccaaatgatattgcgatttgggataaccgcgtgacccagcacta tgccaatgccgattacctgccacagcgacggataatgcatcgggcgacgatccttggggataaac cgttttatcgggcggggtaa""".replace("\n","") gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds) print gc -fin- which should yield: 0.54460093896713613.. but when I ran it I got: 0.544600938967 looking now I see it's truncating after a certain number of decimal places. any ideas why? From een-niet-bestaande-kleineaap at xs4all.nl Wed Dec 6 20:46:21 2006 From: een-niet-bestaande-kleineaap at xs4all.nl (Kleine Aap) Date: Thu, 07 Dec 2006 02:46:21 +0100 Subject: True Division in Python References: <1165448464.077200.128340@n67g2000cwd.googlegroups.com> Message-ID: <457772ca$0$21170$e4fe514c@dreader28.news.xs4all.nl> kermit at polaris.net wrote: > Use ./ for true division. syntax error... From mirandacascade at yahoo.com Sun Dec 24 12:16:41 2006 From: mirandacascade at yahoo.com (mirandacascade at yahoo.com) Date: 24 Dec 2006 09:16:41 -0800 Subject: terminology question - "foreign function library" Message-ID: <1166980601.668105.256770@a3g2000cwd.googlegroups.com> I am prompted to make these inquiries after seeing the following link to ctypes: http://docs.python.org/lib/module-ctypes.html in which ctypes is described as a foreign function library. What is the definition of "foreign function library"? Is the concept different from a "package"? Is the concept different from a "module"? Thank you. From kentilton at gmail.com Sun Dec 10 10:56:47 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sun, 10 Dec 2006 10:56:47 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165764570.956203.223370@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165764570.956203.223370@16g2000cwy.googlegroups.com> Message-ID: <47Weh.356$z_7.350@newsfe08.lga> mystilleef wrote: > Ken Tilton wrote: > >>Lisp has all the cool qualities you like in your pets, plus native >>compilation in most implementations, plus maturity and a standard, plus >>a better OO, plus macros, plus a dozen more small wins. Including >>automatic indentation. :) >> > > > Better OO? You mean the one that doesn't support basic encapsulation > and is retardedly cumbersome to use? There's a reason I said, I'd never > use Lisp for OO not even when I'm high. Gimme Python, Eiffel or > Smalltalk anyday, not the retarded add-on package bolted on CL. > > >>It is just a matter of critical mass. At some very low threshold Lisp >>becomes "OK". I get the feeling that has already begun, but it is not >>quite there yet. Certainly it gets mentioned now when language names get >>bandied about, if only to be dismissed. That is a step up for us. :) >> > > > Bahahahaha! You lispers and your fairy little macros world. > I admire your knack for self-refuting discourse. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From gagsl-py at yahoo.com.ar Wed Dec 27 23:29:28 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 28 Dec 2006 01:29:28 -0300 Subject: socket.gaierror: (-2, 'Name or service not known') Message-ID: <7.0.1.0.0.20061228011955.05df3888@yahoo.com.ar> >It may be a bug in Python, or in the sockets implementation, or >somewhere. Anyway, choose_boundary() should be robust enough to >catch the possible exception and act accordingly, I think. The underlying bug was already reported and solved: http://sourceforge.net/tracker/index.php?func=detail&aid=1250170&group_id=5470&atid=105470 Should work on Python 2.4.4 and later. -- 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 From sjmachin at lexicon.net Fri Dec 22 06:56:55 2006 From: sjmachin at lexicon.net (John Machin) Date: 22 Dec 2006 03:56:55 -0800 Subject: Decorator for Enforcing Argument Types In-Reply-To: References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166741966.242087.192390@n67g2000cwd.googlegroups.com> <1166767205.559937.185260@f1g2000cwa.googlegroups.com> <1166773847.368709.299960@48g2000cwx.googlegroups.com> <1166780607.921591.248000@f1g2000cwa.googlegroups.com> Message-ID: <1166788615.366859.251880@42g2000cwt.googlegroups.com> Duncan Booth wrote: > "John Machin" wrote: > > You are saying that you think that George thinks that they are > > teaching efficient coding methods in OO classes?? > > > No, but I hope they teach how to recognise patterns, and I imagine they > also teach something about refactoring to remove switches or long if/elif > chains. (My imagination may not, of course, bear any resemblance to real > life.) My point is that efficent coding methods, recognition of patterns and refactoring are *general* comp sci concepts, they are not special to OO. Why do you hope / imagine such things about OO classes? From gagsl-py at yahoo.com.ar Tue Dec 12 16:41:57 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 13:41:57 -0800 Subject: Problem understanding how closures work In-Reply-To: References: Message-ID: <1165959717.567679.118530@l12g2000cwl.googlegroups.com> On 12 dic, 17:23, Tom Plunket wrote: > ...at least, I think that I'm having a problem understanding the way > closures work. > > I'm trying to define a function for an object which will take certain > objects from the parent scope at the time that function is defined. > def CreateTests1(count): > tests = [] > for i in xrange(count): > name = 'Test %d' % i > t = Test(name) > tests.append(t) > > def ExCall(text): > print '%s says, "%s"' % (name, text) > > t.ExternalCall = ExCall > > return tests name, inside ExCall, is a free variable. Python builds a closure including the string whose name is "name" in the enclosing scope. Not the *value* which happens to have at this momment. When you execute ExCall, the reference to name yields its last, current, value. If you want "the value at the moment the function is created" you can use a default argument: def ExCall(text, name=name): ... Your second test works because you don't modify "name" between the original definition and its execution. -- Gabriel Genellina From felipe.lessa at gmail.com Tue Dec 26 11:07:27 2006 From: felipe.lessa at gmail.com (Felipe Almeida Lessa) Date: Tue, 26 Dec 2006 14:07:27 -0200 Subject: BeautifulSoup vs. loose & chars In-Reply-To: <1167135758.005112.67350@73g2000cwn.googlegroups.com> References: <1167135758.005112.67350@73g2000cwn.googlegroups.com> Message-ID: On 26 Dec 2006 04:22:38 -0800, placid wrote: > So do you want to remove "&" or replace them with "&" ? If you want > to replace it try the following; I think he wants to replace them, but just the invalid ones. I.e., This & this & that would become This & this & that No, i don't know how to do this efficiently. =/... I think some kind of regex could do it. -- Felipe. From grahamd at dscpl.com.au Wed Dec 13 19:15:11 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 13 Dec 2006 16:15:11 -0800 Subject: mod_python.so is garbled mod_python.so is garbled References: <1166051896.607771.29030@16g2000cwy.googlegroups.com> Message-ID: <1166055311.306055.311900@j72g2000cwa.googlegroups.com> blbmdsmith wrote: > Has anyone seen the following error while starting httpd: > > Starting httpd: httpd: Syntax error on line 54 of > /usr/local/apache2/conf/httpd.conf: API module structure > `python_module' in file /usr/local/apache/modules/mod_python.so is > garbled - perhaps this is not an Apache module DSO > > I am running python2.5 with apache server 2.2.3, using > mod_python-3.2.10 > I ran mod_python configure ----with-apxs= /usr/local/apache/bin/apxs > --with-python=/usr/bin/python > > I have configured httpd.conf with the follwing lines: > > LoadModule python_module /usr/local/apache/modules/mod_python.so > > > AllowOverride FileInfo > AddHandler mod_python .py > PythonHandler mptest > PythonDebug On > > > Thanks, > Bill > > I have posted the same message on the mod_python group. Is this a > better group to post his message? The "mod_python" Google group doesn't get used. You should be subscribing to and posting on the mod_python mailing list for best chances of a response. Mailing list details are on the mod_python web site. Should you have perhaps used: --with-apxs=/usr/local/apache2/bin/apxs Ie., is the version of Apache you compiled for actually the version you are running it with? Do you have multiple versions of Apache installed on your system? Graham From jackson at hotmail.com Thu Dec 7 17:27:07 2006 From: jackson at hotmail.com (Bill Jackson) Date: Thu, 07 Dec 2006 14:27:07 -0800 Subject: Why does wx.Window.CaptureMouse() send EVT_PAINT Message-ID: It seems that the CaptureMouse method sends an EVT_PAINT handler. The documentation does not mention this...is it somewhere else? Could someone explain why this handler is sent out? Also, I've seen: def OnMouseDown(self, evt): self.CaptureMouse() self.x, self.y = self.lastx, self.lasty = evt.GetPosition() self.Refresh(False) Given that CaptureMouse initiates a repaint, isn't self.Refresh(False) moot at the point. Thanks. The doc for CaptureMouse are below. --------- CaptureMouse(self) Directs all mouse input to this window. Call wx.Window.ReleaseMouse to release the capture. Note that wxWindows maintains the stack of windows having captured the mouse and when the mouse is released the capture returns to the window which had had captured it previously and it is only really released if there were no previous window. In particular, this means that you must release the mouse as many times as you capture it, unless the window receives the wx.MouseCaptureLostEvent event. Any application which captures the mouse in the beginning of some operation must handle wx.MouseCaptureLostEvent and cancel this operation when it receives the event. The event handler must not recapture mouse. From fredrik at pythonware.com Wed Dec 20 09:10:39 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 15:10:39 +0100 Subject: trouble getting google through urllib In-Reply-To: <740c3aec0612200549u47c73a4cy89b1fbdccce6fceb@mail.gmail.com> References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> <45879f2f$0$32025$fa0fcedb@news.zen.co.uk> <1166537585.709708.223250@i12g2000cwa.googlegroups.com> <740c3aec0612200549u47c73a4cy89b1fbdccce6fceb@mail.gmail.com> Message-ID: BJ?rn Lindqvist wrote: > For Google, that load must be piss in the ocean. I bet for Google to > even notice the abuse, it must be something really, really severe. like, say, business? http://scripting.wordpress.com/2006/12/19/scripting-news-for-12192006/#comment-25891 From mike.klaas at gmail.com Fri Dec 8 17:14:45 2006 From: mike.klaas at gmail.com (Klaas) Date: 8 Dec 2006 14:14:45 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: <1165616085.455887.264300@j44g2000cwa.googlegroups.com> Aahz wrote: > As for your claims about speed, they are also nonsense; I doubt one > would find an order of magnitude increase of speed for production > programs created by a competent Lisp programmer compared to programs > created by a competent Python programmer. Lisp can be compiled into an executable that has c-like speeds. It can be much faster than python. -MIke From fredrik at pythonware.com Thu Dec 14 03:27:20 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 09:27:20 +0100 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1166055959.498100.116240@79g2000cws.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> <1166046193.734274.124160@73g2000cwn.googlegroups.com> <1166055959.498100.116240@79g2000cws.googlegroups.com> Message-ID: BartlebyScrivener wrote: >> what do you get if you do: > >>> python -S >> ... >>>> import sys >>>> sys.path > > ['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python', > 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', > 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\ > \Python24'] since it appears *after* the ZIP archive, but before the standard path, it should be either a registry setting or a custom-built interpreter (is this an ActiveState build?). or maybe you could get this effect if you have a copy of "python.exe" in d:\python, but I'm pretty sure that the directory should end up at the *end* of the path in that case. have you searched the *entire* registry for the "PythonCore" key? (python looks under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER) what's sys.prefix and sys.exec_prefix set to on your machine, btw? From godson.g at gmail.com Fri Dec 1 04:04:29 2006 From: godson.g at gmail.com (Godson) Date: Fri, 1 Dec 2006 14:34:29 +0530 Subject: How can I change the icon In-Reply-To: <1164920723.810868.8320@l12g2000cwl.googlegroups.com> References: <1164920447.562855.159040@h54g2000cwb.googlegroups.com> <1164920723.810868.8320@l12g2000cwl.googlegroups.com> Message-ID: On 30 Nov 2006 13:05:23 -0800, Boneh wrote: > > > Boneh wrote: > > Is it possible to change the icon "Tk" of the windows popped up ? > > I am using tkinter for widgets, thanks :-) > > -- > http://mail.python.org/mailman/listinfo/python-list > user iconbitmap method to change the icon of the window, this method works on all root or Toplevel windows iconbitmap(path of the ico file) Example from Tkinter import* root=TK() root.iconbitmap("c:/python25/smiley.ico") Godson Gera http://godson.auroinfo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From huayang.xia at gmail.com Tue Dec 19 14:27:38 2006 From: huayang.xia at gmail.com (Huayang Xia) Date: 19 Dec 2006 11:27:38 -0800 Subject: When Closure get external variable's value? In-Reply-To: References: <1166473333.593246.238580@73g2000cwn.googlegroups.com> <1166474513.700608.201760@48g2000cwx.googlegroups.com> <1166542026.913912.82880@t46g2000cwa.googlegroups.com> <1166544951.721977.281100@t46g2000cwa.googlegroups.com> Message-ID: <1166556458.780265.147420@80g2000cwy.googlegroups.com> I'm confused. What is the definition of closure. I'm not sure if it's correct, I get the definition from wikipedia: "A closure typically comes about when one function is declared entirely within the body of another, and the inner function refers to local variables of the outer function. At runtime, when the outer function executes, a closure is formed. It consists of the inner function's code and references to any variables in the outer function's scope that the closure needs." I agree it is not declaration, it's definition. However it's closure based on the above definition. It uses free variable. Or you mean it's a closure only when the outer function returns it and be exposed to external world? The code snippet was just for test purpose. My question was how the free variable inside inner function (the closure) binds with object. That was answered by Fredrik perfectly. From whumeniu+anti+spam at telus.net Fri Dec 8 10:12:37 2006 From: whumeniu+anti+spam at telus.net (Wade Humeniuk) Date: Fri, 08 Dec 2006 15:12:37 GMT Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > Since the late 1950's Lisp has participated in the development of modern (present day) programming practises. It has shaped and been shaped by the minds of just not programmers, but people involved in dealing with the larger impacts and possibilities. Its been there, is here, and will continue to be there in the future. Lisp is a human construct that is a force to be reckoned with. Its construction reflects something very deep and fundamental about computing. So, it depends on what you want. What do you want? W From greg at cosc.canterbury.ac.nz Sat Dec 16 19:35:33 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 17 Dec 2006 13:35:33 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <4uhl73F108ri8U1@mid.individual.net> Message-ID: <4ujhpiF16s5d4U1@mid.individual.net> Ken Tilton wrote: > How does a generic engine that sees only a solution (a > list of mathematical expressions and for each the transformations, > results, and opnds logged by individual TF functions) build up this > environment such that it has named attributes such as signed-value? How did your macro know that the user's reverse function needed a signed_value parameter in that particular case? > Assume that it can examine all those opnds and results looking > for tagged values such that it then knows the name of those values > that have been named. You might be able to handle this using a general method that searches the tree for a specified tag, e.g. env.find_tag("signed_value") -- Greg From fredrik at pythonware.com Fri Dec 22 18:27:05 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Dec 2006 00:27:05 +0100 Subject: attribute decorators In-Reply-To: References: Message-ID: Gert Cuykens wrote: > would it not be nice if you could assign decorators to attributes too ? > for example > > class C: > @staticattribute > data='hello' > > or > > class C: > @privateattribute > data='hello' and that would do what? From steve at REMOVE.THIS.cybersource.com.au Thu Dec 28 17:16:09 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Fri, 29 Dec 2006 09:16:09 +1100 Subject: dictionary containing instances of classes behaving oddly References: <1167326178.386764.300200@n51g2000cwc.googlegroups.com> Message-ID: On Thu, 28 Dec 2006 09:16:18 -0800, Ben wrote: > Hello... > > I have a dictionary, where each value is a seperate instance of the > same class: > > self.mop_list[record_number]=record(self.mops[:]) Others have already solved the immediate problem, but I'd just like to make a brief comment about self-documenting code, in particular misleading self-documenting code. The O.P. says he has a DICTIONARY called mop_LIST. [raises eyebrow] -- Steven. From python.sam at googlemail.com Thu Dec 7 20:38:33 2006 From: python.sam at googlemail.com (sam) Date: 7 Dec 2006 17:38:33 -0800 Subject: problems caused by very large for-loop In-Reply-To: References: Message-ID: <1165541913.588123.202760@l12g2000cwl.googlegroups.com> thanks, i'll remember that. it makes sense that there should be a way of doing it... sam From Amateur.N7TZG at gmail.com Fri Dec 15 16:52:08 2006 From: Amateur.N7TZG at gmail.com (Rob) Date: 15 Dec 2006 13:52:08 -0800 Subject: Serial port failure In-Reply-To: References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> Message-ID: <1166219528.807953.308840@80g2000cwy.googlegroups.com> Here is OpenPort #################################################################### #### OpenPort procedure #################################################################### def OpenPort(name): BRate = 19200 Tout = 3 try: # Initialize the port p = serial.Serial(name) # handle failures gracefully except SerialException: print "The serial port is unavailable." print "Disconnect your USB to Serial adapter, Then" print "reconnect it and try again." sys.exit(1) p.setBaudrate(19200) p.setTimeout(3) #set timeout to 1.5 seconds # finish opening the port and assign a file handle p.open() return p On Dec 15, 1:07 pm, hg wrote: > Rob wrote: > > Hi all, > > > I am fairly new to python, but not programming and embedded. I am > > having an issue which I believe is related to the hardware, triggered > > by the software read I am doing in pySerial. I am sending a short > > message to a group of embedded boxes daisy chained via the serial port. > > When I send a 'global' message, all the connected units should reply > > with their Id and Ack in this format '0 Ack' To be certain that I > > didn't miss a packet, and hence a unit, I do the procedure three times, > > sending the message and waiting for a timeout before I run through the > > next iteration. Frequently I get through the first two iterations > > without a problem, but the third hangs up and crashes, requiring me to > > remove the Belkin USB to serial adapter, and then reconnect it. Here > > is the code: > > > import sys, os > > import serial > > import sret > > import time > > > from serial.serialutil import SerialException > > #################################################################### > > #### GetAck Procedure > > #################################################################### > > def GetAck(p): > > response = "" > > > try: > > response = p.readline() > > except SerialException: > > print ">>>>>Timed out<<<<<" > > return -1 > > res = response.split() > > > #look for ack in the return message > > reslen = len(response) > > if reslen > 5: > > if res[1] == 'Ack': > > return res[0] > > elif res[1] == 'Nak': > > return 0x7F > > else: > > return -1 > > >>>>>> Snip <<<<<< > > #################################################################### > > #### GetNumLanes Procedure > > #################################################################### > > def GetNumLanes(Lanes): > > print "Looking for connected units" > > # give a turn command and wait for responses > > msg = ".g t 0 336\n" > > > for i in range(3): > > port = OpenPort() > > time.sleep(3) > > print port.isOpen() > > print "Request #%d" % (i+1) > > try: > > port.writelines(msg) > > except OSError: > > print "Serial port failure. Power cycle units" > > port.close() > > sys.exit(1) > > > done = False > > # Run first connection check > > #Loop through getting responses until we get a -1 from GetAck > > while done == False: > > # lane will either be -1 (timeout), 0x7F (Nak), > > # or the lane number that responded with an Ack > > lane = GetAck(port) > > if lane >= '0': > > if False == Lanes.has_key(lane): > > Lanes[lane] = True > > else: > > done = True > > port.close() > > time.sleep(3) > > > # Report number of lanes found > > NumLanes = len(Lanes) > > if NumLanes == 1: > > print "\n\nFound 1 unit connected" > > else: > > print "\n\nFound %d units connected" % NumLanes > > > return NumLanes > > >>>>>>> Snip <<<<<< > > #################################################################### > > #### Main Program Code Section > > #################################################################### > > > #open the serial port > > # capture serial port errors from trying to open the port > > > port = OpenPort() > > > # If we got to here, the port exists. Set the baud rate and timeout > > values > > > # I need to determine how many lanes are on this chain > > # First send a turn command > > > #Create a dictionary of lanes so I can check each lane's responses > > Lanes = {} > > #<><><><><><><><><><><><><><><><> > > # Call the lane finder utility > > NumLanes = GetNumLanes(Lanes) > > #<><><><><><><><><><><><><><><><> > > > #if no lanes responded, exit from the utility > > if 0 == NumLanes: > > print "I can't find any units connected." > > print "Check your connections and try again" > > sys.exit(1) > > > # list the lanes we have in our dictionary > > for n in Lanes: > > print "Lane - %s" % n > > > Now, here is the error message that I get > > > dad at nb29:~/py$ ./Thex.py > > Looking for connected units > > True > > Request #1 > > True > > Request #2 > > Serial port failure. Power cycle units > > dad at nb29:~/py$ ./Thex.py > > The serial port is unavailable. > > Disconnect your USB to Serial adapter, Then > > reconnect it and try again. > > dad at nb29:~/py$ > > > Does anyone have any ideas? > > > Thanks, > > > rob < Amateur.N7... at gmail.com >Where is OpenPort ? > > hg From harry.g.george at boeing.com Mon Dec 11 09:57:33 2006 From: harry.g.george at boeing.com (Harry George) Date: Mon, 11 Dec 2006 14:57:33 GMT Subject: Pyparsing troubles References: <1165711142.191071.45620@l12g2000cwl.googlegroups.com> Message-ID: poromenos at gmail.com writes: > Hello, > I have written a small pyparsing parser to recognize dates in the style > "november 1st". I wrote something to the effect of: > > expression = task + date > > and tried to parse "Doctor's appointment on november 1st", hoping that > task would be "Doctor's appointment" and date would be "on november > 1st" (the parser does match "on november 1st" to "date"). I have set > task as Regex(".*?"), ZeroOrMore(Word(alphas)), etc, but I can't get it > to match, it matches everything to task and ignores date until it gets > to the end of the string. > > Can anyone help? > As described, this is a Natural Language Programming (NLP) problem, which means you will have a lot more trouble with understanding what you want to do than in coding it. Also, dates are notoriously tough to parse, because of so many variants, so there are libraries to do just that. If you want to tackle it systematically: 1. Get a "corpus" of texts which illustrate the ways the users might state the date. E.g., "2006-11-01", "1-Nov-06", "November 1", "Nov. first", "first of November", "10 days prior to Veterans Day", "next week", ..... 2. If you can control the input, much better. Either by a form which forces specific values for day, month, year, hour, minute, or by requiring IETF format (yyyy-mm-ddThh:mm:ss). 3. Determine the syntax rules for each example. If possible, abstract these to general rules which work on more than one example. 4. At this point, you should know enough to decide if it is a: a) Regular expression, parseable with a regexp engine b) Context Free Grammar (CFG), parseable with a LL(1) or LALR(1) parser. c) Context Dependent Grammar, parseable with an ad hoc parser with special rules. d) Free text, not parseable in the normal sense, but perhaps understandable with statistical analysis NLP techniques. f) Hodgepodge not amenable to machine analysis. 5. Then we could look at using pyparser. But we'd have to see the pyparser code you tried. -- Harry George PLM Engineering Architecture From ironfroggy at gmail.com Wed Dec 20 18:04:33 2006 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 20 Dec 2006 18:04:33 -0500 Subject: what is wrong with my code? In-Reply-To: <874prq6wmd.fsf@pyenos.pyenos.org> References: <874prq6wmd.fsf@pyenos.pyenos.org> Message-ID: <76fd5acf0612201504s19711afx73d352c0683da26a@mail.gmail.com> It is hard to determine what is wrong with your code without you telling anyone why it is you believe something is wrong with it. Did you get an exception? Did it simply not do what it was expected to do? There seems to be some apparent indenting problems, but maybe that is just from pushing it through the e-mail. I see some general stylistic problems as well, but without know what you are actually asking, I won't know what questions to answer. "What is wrong with my code?" is a container of many many smaller questions, and you need to focus your questions better. On 21 Dec 2006 09:16:58 +1100, Pyenos wrote: > import cPickle, shelve > > could someone tell me what things are wrong with my code? > > class progress: > > PROGRESS_TABLE_ACTIONS=["new","remove","modify"] > DEFAULT_PROGRESS_DATA_FILE="progress_data" > PROGRESS_OUTCOMES=["pass", "fail"] > > > def unpickleProgressTable(pickled_progress_data_file): > > return unpickled_progress_table > > def pickleProgressTable(progress_table_to_pickle): > > return pickled_progress_data_file > > # Of course, you get progress_table is unpickled progress table. > def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]): > pid_column_list=progress_table[0] > task_column_list=progress_table[1] > outcome_column_list=progress_table[2] > > # But a task must also come with an outcome! > def newEntry(new_task, new_outcome): > new_pid=len(task_column_list) > > pid_column_list.extend(new_pid) > task_column_list.extend(new_task) > outcome_column_list.extend(new_outcome) > > def removeEntry(pid_to_remove, task_to_remove): > > if pid_column_list.index(pid_to_remove)==task_column_list.index(task_to_remove): > # Must remove all columns for that task > index_for_removal=pid_column_list.index(pid_to_remove) > > pid_column_list.remove(index_for_removal) > task_column_list.remove(index_for_removal) > outcome_column_list.remove(index_for_removal) > > # Default action is to modify to pass > def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]): > index_for_modifying=pid_column_list.index(pid_to_modify) > > # Modify the outcome > outcome_column_list[index_for_modifying]=outcome_to_modify > -- > http://mail.python.org/mailman/listinfo/python-list > -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ From bjourne at gmail.com Wed Dec 20 08:49:43 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Wed, 20 Dec 2006 14:49:43 +0100 Subject: trouble getting google through urllib In-Reply-To: <1166537585.709708.223250@i12g2000cwa.googlegroups.com> References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> <45879f2f$0$32025$fa0fcedb@news.zen.co.uk> <1166537585.709708.223250@i12g2000cwa.googlegroups.com> Message-ID: <740c3aec0612200549u47c73a4cy89b1fbdccce6fceb@mail.gmail.com> > > > Google doesnt like Python scripts. You will need to pretend to be a > > > browser by setting the user-agent string in the HTTP header. > > > > > and possibly also run the risk of having your system blocked by Google if > > they figure out you are lying to them? > > It is possible. I wrote a 'googlewhack' (remember them?) script a while > ago, which pretty much downloaded as many google pages as my adsl could > handle. And they didn't punish me for it. Although apparently they do > issue short term bans on IP's that abuse their service. For Google, that load must be piss in the ocean. I bet for Google to even notice the abuse, it must be something really, really severe. -- mvh Bj?rn From matias.jansson at carmenconsulting.com Tue Dec 12 03:29:17 2006 From: matias.jansson at carmenconsulting.com (Matias Jansson) Date: Tue, 12 Dec 2006 09:29:17 +0100 Subject: One module per class, bad idea? Message-ID: I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many classes in a Python module/file. What is the motivation behind it, would it be a bad idea to have a guideline in your project that promotes a one class per file structure (assuming most of the programmers a background similar to mine)? From python-url at phaseit.net Mon Dec 18 13:46:45 2006 From: python-url at phaseit.net (Paul Boddie) Date: Mon, 18 Dec 2006 18:46:45 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Dec 18) Message-ID: QOTW: "c.l.python is just a small speck at the outer parts of the python universe. most python programmers don't even read this newsgroup, except, perhaps, when they stumble upon it via a search engine." -- Fredrik Lundh (on comp.lang.python, prompting the editor to offer greetings to those of you who are not reading Python-URL! via that channel) http://groups.google.com/group/comp.lang.python/msg/4d73a2da72c87226 "That's the kind of features I have in mind, and the best thing is that conceptually a lot of the work consists of connecting dots that already out there. But as there are so many of them, a few extra pencils would be quite welcome " -- Willem Broekema (on comp.lang.python, referring to the ongoing CLPython - Python in Common Lisp - project) http://groups.google.com/group/comp.lang.python/msg/b72788cc5569d778 http://trac.common-lisp.net/clpython/ Registration for PyCon (the North American Python conference) is now open: http://pycon.blogspot.com/2006/12/registration-for-pycon-2007-is-now.html http://us.pycon.org/TX2007/Registration Meanwhile, the EuroPython planners get ahead of themselves, thinking about conference venues as far in the future as 2010, if not 20010! http://mail.python.org/pipermail/europython/2006-December/006158.html http://mail.python.org/pipermail/europython/2006-December/006161.html PyMite - the embedded Python interpreter - gets an update: http://groups.google.com/group/comp.lang.python.announce/msg/b335a476d4033292 http://pymite.python-hosting.com/ This week's Python advocacy discovery had to be the revelation that YouTube runs on Python, helping to diminish concerns about Python's suitability for large scale Internet applications and services: http://sayspy.blogspot.com/2006/12/youtube-runs-on-python.html http://www.python.org/about/quotes/#youtube-com Of related things "flexible and fast", development in the Cherokee Web server community produces the 100% Python implementation of SCGI: the logically named PySCGI. http://www.alobbs.com/news/1193 And on the advocacy front, volunteers are sought to write informative materials (flyers, whitepapers) promoting Python in different domains: http://wiki.python.org/moin/AdvocacyWritingTasks Video conferencing on the OLPC (One Laptop Per Child) prototype takes shape with a mixture of technologies and "a few lines of Python": http://www.robot101.net/2006/12/12/telepathy-and-olpc/ After an influx of competing XML technologies and now drifting free without an appointed maintainer, is the era of PyXML over? http://mail.python.org/pipermail/xml-sig/2006-December/011620.html On a more administrative level, the Python Software Foundation (PSF) invites nominations for new directors: http://pyfound.blogspot.com/2006/12/call-for-nominations-of-psf-directors.html The PSF also suggests that you might consider a donation towards their work of protecting the Python copyrights and trademarks: http://pyfound.blogspot.com/2006/12/remember-psf-in-your-year-end.html ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html The Python Papers aims to publish "the efforts of Python enthusiats". http://pythonpapers.org/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html Steve Bethard continues the marvelous tradition early borne by Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim Lesher of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/python/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topic/python/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From luc at honk-honk.com Tue Dec 19 02:36:06 2006 From: luc at honk-honk.com (Luc Heinrich) Date: Tue, 19 Dec 2006 08:36:06 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> Message-ID: <1hql1xl.oz7gsvwz9w1qN%luc@honk-honk.com> Paul McNett

wrote: > It looks/feels like a native app on OS X. I'm sorry, but the screenshots I'm seeing on the Dabo website all look like ugly Windows ports (when they don't look like straight X11 crap). I can't comment on the feel of course, but I wouldn't hold my breath. I'm downloading the screencasts as we "speak", but I'm not holding my breath either. [UPDATE] I have watched three of the Dabo screencasts and the presented application are *very* far from looking/feeling like native OS X applications. Sorry. > Why not use the best crossplatform native toolkit (wxPython) and then if > you need native features that aren't provided, use ctypes or something > to get access to the native GUI? Nothing in wxPython or Dabo prevents > you from doing that. Eh, funny, I have used wx thingy for quite some time (when it was actually still called wxWindows and then when they switched to wxWidgets) and it's probably the worst of all crossplatform toolkits I have ever used. So I'm not sure you'll be able to convince me here :D Ok, now here's a question for you: if crossplatform toolkits/frameworks are sooooo great and automagically allow to produce superlickable and native-looking/feeling applications on all three major platforms, why is there so few of those applications on OS X ? "Because Mac users are elitists assholes" is not the good answer by the way :) -- Luc Heinrich From heikki at osafoundation.org Thu Dec 21 00:41:25 2006 From: heikki at osafoundation.org (Heikki Toivonen) Date: Wed, 20 Dec 2006 21:41:25 -0800 Subject: ANN: M2Crypto 0.17 Message-ID: M2Crypto is the most complete Python wrapper for OpenSSL. Homepage: http://wiki.osafoundation.org/bin/view/Projects/MeTooCrypto Changes in 0.17: - setup.py has new test command to run unit tests (requires setuptools) - Added m2urllib2, by James Bowes (python 2.4 and later, at least for now) - Added CONNECT proxy for httpslib and m2urllib2, by James Bowes - Added PKey.get_modulus, X509.get_fingerprint, X509_Name.as_der and m2.bn_to_hex, by Thomas Uram - Prevent Connection.makefile from freeing bio redundantly, by Thomas Uram - Added Err.peek_error_code, by Thomas Uram - Fixed m2urllib.open_https to return the response headers, otherwise code that relied on that would break (for example msnlib-3.5), by Arno Bakker - Fixed twisted wrapper to work with >16kb BIO buffers, by Martin Paljak - Added support for remaining ECs, by Larry Bugbee - Fixed DSA.save_key and DSA_.save_pub_key, by Larry Bugbee - SSL.Context.load_verify_locations raises ValueError if cafile and capath are both None - Fixed X509.check_purpose() (was always raising exceptions) - smime_read_pkcs7 was changed to automatically call BIO_set_mem_eof_return on memory BIOs because otherwise the read would fail with "SMIME_Error: not enough data" - X509.new_extension('subjectKeyIdentifier', 'hash') raises ValueError instead of crashing Python -- Heikki Toivonen From reverseyorkage at david.com Sun Dec 17 08:26:40 2006 From: reverseyorkage at david.com (dyork) Date: Sun, 17 Dec 2006 13:26:40 GMT Subject: Roundtrip SQL data especially datetime References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: "Carsten Haese" wrote in message news:mailman.1683.1166244629.32031.python-list at python.org... > Python is a typed language, too, and "this thing" works just fine, > provided that you are using a reasonable DB-API implementation, and > provided that you're actually binding objects as parameters instead of > just sticking literal strings into your query. I'm currently using MySQLdb, but I'm looking for solutions that work universally. Binding objects is no different from literal strings. Since there is no portable underlying type for an SQL date, the interface will AFAIK always finish up using strings. At some point the SQL parser has to convert a literal string, either embedded in the query or bound as a parameter, into the equivalent date. I really hope the dbapi will know how to choose the right string format so I don't have to, but so far that's not at all certain. > When reading stuff from the database, keep the results in whatever form > they come. Convert to strings for display purposes if you must, but > don't overwrite the object you got from the database if you intend to > save it back into the database. That's not feasible. For Web stuff, the object from the database got thrown away after the page was rendered. We're dealing with a whole new request, with little or no previous state, and all the dates coming in with the request are strings, using formatting that depends on what the user wanted to see. I need to package that into a form ready for either an INSERT or UPDATE query. The user might have typed in dd-mmm-yy order, but the database interface might use mm/dd/yyyy. It needs two conversion layers, and I would rather use someone else's than write my own. Lazy, I guess. DY From mccredie at gmail.com Wed Dec 20 19:27:37 2006 From: mccredie at gmail.com (Matimus) Date: 20 Dec 2006 16:27:37 -0800 Subject: TypeError: unbound method must be called with class instance 1st argument References: <1166660370.705628.30360@79g2000cws.googlegroups.com> Message-ID: <1166660856.886262.293100@i12g2000cwa.googlegroups.com> > Can someone please explain why I get the following error: The following line: threading.Thread.__init__() Should be written as: threading.Thread.__init__(self) From simon at brunningonline.net Fri Dec 15 10:28:45 2006 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 15 Dec 2006 15:28:45 +0000 Subject: tuple.index() In-Reply-To: References: Message-ID: <8c7f10c60612150728o20b7e4bcl49afbd9ca3d5bf39@mail.gmail.com> On 12/15/06, Christoph Zwerschke wrote: > Maybe there would be less dispute if this dogma/convention(?) "Tuples > are for heterogeneous data, list are for homogeneous data" would be > written down somewhere in the tutorial, reference or in PEP8, so people > would be aware of it. It's not a dogma. It's just that it explains the intention behind the designs of the tuple and list APIs. If you use them for thier intended purposes, naturally you'll find the APIs more helpful. But you won't find the data-structure police breaking down your doors in the small hours if you choose to go your own way[1]. I can use a spreadsheet to write a letter if I want to - but it would be foolish to complain that the word wrapping was a bit dodgy. -- Cheers, Simon B simon at brunningonline.net [1] The PSU, on the other hand, Mi%_$@-?+%( From g.franzkowiak at onlinehome.de Sat Dec 16 11:09:41 2006 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Sat, 16 Dec 2006 17:09:41 +0100 Subject: win32 service In-Reply-To: References: Message-ID: <45841A45.1060100@onlinehome.de> Tim Williams schrieb: > On 16/12/06, g.franzkowiak wrote: >> Hi everybody, >> >> have a little problem with a service on Win32. >> >> I use a TCP server as service, but can't access from an other machine. >> Only local access is possible. >> >> The service starts like this: >> >> -> myService.py --username user --password password install <- >> >> followed by start >> >> The user is member in "Log on as service", but... only local access :-( >> >> What is wrong or what can I do ? >> > > Have you checked that your firewall isn't causing the problem, and > that the servers IP address is accessible from other machines to start > with ? Yes, is checked. The server class operates as normal console program. From bdesth.quelquechose at free.quelquepart.fr Tue Dec 12 18:17:19 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 13 Dec 2006 00:17:19 +0100 Subject: oo problem In-Reply-To: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> Message-ID: <457f32ed$0$13615$426a74cc@news.free.fr> Tool69 a ?crit : > Hi, > I've got a simple but difficult problem : > > Suppose I've got a Paper class, on wich I can draw i.e a rectangle, a > circle or whatever. > > class Paper(...): > def __init__(self, paperx, papery): > self.paperx = paperx > self.papery = papery > .... > def draw(self, Primitive_Object): > .... > class Rectangle( ): <--- a Primitive_Object > ... > > Now, inside my Rectangle class, I need to recover the Paper instance > who called it (because I need the paper sizes to calculate something). > I now I can use a global variable, say " _paper" and then, inside my > Paper.__init__() write something like this : > > global _paper > _paper = [paperx,papery] > > But it has drawbacks : Indeed... > what if I've got several Paper instances ? class Paper(...): > .... def draw(self, drawable): drawable.draw(self) class Rectangle( ): <--- a drawable ... def draw(self, drawing_surface): ... Now consider whether you really need Paper.draw... HTH From Tim.Golden at viacom-outdoor.co.uk Fri Dec 8 12:16:51 2006 From: Tim.Golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri, 8 Dec 2006 17:16:51 -0000 Subject: Text Encoding - Like Wrestling Oiled Pigs In-Reply-To: <1165595168.337197.235040@80g2000cwy.googlegroups.com> Message-ID: [apotheos at gmail.com] | I've got a database of information that is encoded in Windows/CP1252. | What I want to do is dump this to a UTF-8 encoded text file (a RSS | feed). | "UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position | 163: ordinal not in range(128)" | | So somewhere I'm missing an implicit conversion to ASCII which is | completely aggrivating my brain. [... snip ...] descript = each[2] + '

' + each[1] | output.write(u'' + unicode(descript) + | u'\n') # this is the line that causes the error. Well, if the columns in the "each" row you're using are unicode objects then that unicode(descript) is redundant because descript will already be a unicode object. If the columns are returned as encoded strings then you're not giving the unicode converter function any clues as to what that encoding is. You said above that the data is stored as cp1252, so why not try unicode (descript, "cp1252")? unicode ("\x92") unicode ("\x92", "cp1252") gives >>> unicode ("\x92") Traceback (most recent call last): File "", line 1, in ? UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 0: ordinal not in range(128) >>> unicode ("\x92", "cp1252") u'\u2019' Or am *I* missing something more obvious? TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From __peter__ at web.de Wed Dec 27 11:05:59 2006 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Dec 2006 17:05:59 +0100 Subject: newbie question: any better way to write this code? References: <1167232702.061737.25610@42g2000cwt.googlegroups.com> Message-ID: neoedmund wrote: > i want to let a byte array to be xor with some value. > but code show below i wrote seems not so .. good..., any better way to > write such function? thanks. > [code] > def xor(buf): > ????????bout=[] > ????????for i in range(len(buf)): > ????????????????x = ord(buf[i]) > ????????????????x ^= 123 > ????????????????bout.append(chr(x)) > ????????return "".join(buf) 'bout' not 'buf', I think. A simple improvement: loop over the characters: def xor2(buf): #... for c in buf: x = ord(c) #... If you want to xor always with the same value you can prepare a lookup map once for every possible input value: _map = dict((chr(i), chr(i ^ 123)) for i in range(256)) def xor3(buf, _map=_map): return "".join(_map[c] for c in buf) However, you still have to loop over the characters of buf in Python. Here's a way to move that loop (in the generator expression) into the str.translate() method which is coded in C: _map = "".join(chr(i^123) for i in range(256)) def xor4(buf): return buf.translate(_map) Now let's do some measurements: $ python2.5 -m timeit -s"from xor import xor; s = 'alpha ' * 10" "xor(s)" 10000 loops, best of 3: 87.9 usec per loop $ python2.5 -m timeit -s"from xor import xor2; s = 'alpha ' * 10" "xor2(s)" 10000 loops, best of 3: 78.4 usec per loop $ python2.5 -m timeit -s"from xor import xor3; s = 'alpha ' * 10" "xor3(s)" 10000 loops, best of 3: 38.5 usec per loop $ python2.5 -m timeit -s"from xor import xor4; s = 'alpha ' * 10" "xor4(s)" 1000000 loops, best of 3: 1.15 usec per loop But what if you don't know the value to xor with in advance? def xor5(buf, n=123): map = "".join(chr(i^123) for i in range(256)) return buf.translate(map) $ python2.5 -m timeit -s"from xor import xor5; s = 'alpha ' * 10" "xor5(s)" 1000 loops, best of 3: 221 usec per loop There goes our speed-up. I can think of various ways to remedy that, but if your input strings are long you might not even care: $ python2.5 -m timeit -s"from xor import xor2; s = 'alpha ' * 1000" "xor (s)" 100 loops, best of 3: 7.93 msec per loop $ python2.5 -m timeit -s"from xor import xor5; s = 'alpha ' * 1000" "xor (s)" 1000 loops, best of 3: 242 usec per loop Peter From sjmachin at lexicon.net Thu Dec 7 02:26:35 2006 From: sjmachin at lexicon.net (John Machin) Date: 6 Dec 2006 23:26:35 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> <1165298691.474503.184480@16g2000cwy.googlegroups.com> Message-ID: <1165473230.906787.232150@16g2000cwy.googlegroups.com> OKB (not okblacke) wrote: > John Machin wrote: > > > Can you give a real example from your code where the location of > > such a human error (you cause a variable to bound to a value of > > inappropriate type) would be difficult to find, plus an estimate of > > how often you would make such an error? > > Here is an example: > > self.outFile.write(str(len(self.hits)) + ' in ' + searchInfo.recordName > + '\t' + ']['.join((a. group() for a in self.hits)) + '\n') > > This is from a text-searching tool I have written to search > linguistic corpora. This statement writes a summary line to the output > file indicating how many hits were found in that file. > > The problem in this line was that I'd forgotten to put str() around > the len(). Now, it's not impossible to find the problem, because given > my knowledge of the program I know that that's the only part of the line > that would reasonably contain the number, but I still think it would be > a lot easier if there were a caret in the error message pointing to the > offending summand. It should be extremely easy (rather than "not impossible") for anybody with half a clue to find the problem given only the offending statement (rather than your "knowledge of the program"). There are 6 possibilities; 3 are string constants. That leaves us with len(something), searchInfo.recordName, and "][".join(something). len() very definitely returns an integer (unless some lunatic has bound the name to something else) and it's the *first* of the possibilities -- one can normally expect execution to proceed from left to right. recordName smells like a string. "][".join(blahblah) likewise unless the rebinding mania is pandemic. Sheesh. > > I'm glad you asked this question, though, because in searching for > examples in my code, I discovered that most of my beefs aren't actually > of this type. A lot of them are things like this: > > someStr.split(someList) > > Here I meant to write someList[0] (say), but have inadvertently > passed the list instead of one of its elements. > > In this case I receive an error message that says "TypeError: > expected a character buffer object". My question is: why can this error > message not say what was encountered INSTEAD of a character buffer > object? > > A similar situation occurs when I do someVar[0] and get an > "unsubscriptable object" error. The error does not even tell me the > type of the offending value, just that it is unsubscriptable. > > So my conclusion from this is: is there a reason that every error > message of the form "expected foo" or "this object cannot be frotzed" > cannot be changed to something like "expected foo but found bar" or > "this FooType object cannot be frotzed"? And despite your use of RHN (Reverse Hungarian Notation) you don't know that someList is a list? From martin at v.loewis.de Fri Dec 29 19:49:03 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 30 Dec 2006 01:49:03 +0100 Subject: Minor problem with configure (2.4.4) In-Reply-To: <1167355805.609659.62920@73g2000cwn.googlegroups.com> References: <1167355805.609659.62920@73g2000cwn.googlegroups.com> Message-ID: <4595B77F.1080204@v.loewis.de> sndive at gmail.com schrieb: > configure.in:273: error: possibly undefined macro: AC_UNDEFINE > If this token and others are legitimate, please use > m4_pattern_allow. > See the Autoconf documentation. > > Ideas? RTFM (autoconf documentation, in this case). There is no AC_UNDEFINE. Regards, Martin From shb*NO*SPAM* at comporium.net Sun Dec 3 10:15:07 2006 From: shb*NO*SPAM* at comporium.net (Si Ballenger) Date: Sun, 03 Dec 2006 15:15:07 GMT Subject: Parsing data from pyserial References: Message-ID: <4572e860.53134312@news.comporium.net> On Sat, 2 Dec 2006 23:02:06 -0500, Lone Wolf wrote: >I'm trying to get data through my serial port from a CMUcam. >This gizmo tracks a color and returns a packet of data. The >packet has nine data points (well, really eight since the first >point is just a packet header) separated by spaces as follows: M >xxx xxx xxx xxx xxx xxx xxx xxx > >Here is the code I am using (python v24): > >import serial > >ser=serial.Serial('com1',baudrate=115200, bytesize=8, >parity='N', stopbits=1,xonxoff=0, timeout=1) > >ser.write("PM 1") #This sets the CMUcam to poll mode > >for i in range(0,100,1): > ser.write("TC 016 240 100 240 016 240\r\n") > reading = ser.read(40) > print reading > components = reading.split() > print components >ser.close In my dealing with serial gizmos I have to put a delay between the request sent to the gizmo and the reading of the serial input buffer for returned data. Serial ports and gizmos need some time to do their thing. From cliff at develix.com Mon Dec 11 14:50:45 2006 From: cliff at develix.com (Cliff Wells) Date: Mon, 11 Dec 2006 11:50:45 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165853477.104769.325440@n67g2000cwd.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> <1165853477.104769.325440@n67g2000cwd.googlegroups.com> Message-ID: <1165866645.3425.12.camel@portableevil> On Mon, 2006-12-11 at 08:11 -0800, sjdevnull at yahoo.com wrote: > Bill Atkins wrote: > > > On the plus side, Python makes less demands on the > > > capabilities of the editor. All you really need > > > is block-shifting commands. Bracket matching is > > > handy for expressions but not vital, and you > > > certainly don't need bracket-based auto-indenting. > > > > Oh, please. So we should restrict the power of the languages we > > choose just to make sure that our code can be edited in Notepad? > > In the real world, it's a non-negligible consideration, IMO. I find > myself needing to write code on machines that aren't my usual dev > machine at least a couple of times a year, and not having to install a > particular editor is nice (especially in terms of keeping the > modifications to someone else's machine down to a minimum). > > It's hardly a dealbreaker for a particular language, but it's far from > worthless. For the most part, editing Python isn't an issue, but I think it's a fallacy to claim that significant whitespace has no impact on editing and refactoring. There's a reason indent-region doesn't work for Python code in Emacs (and probably never will - I consider the hopefully uncommon practice of putting "pass" statements at the end of blocks marginally silly). There was a time (many years ago) when I used this feature of Emacs to catch indentation errors in C code. Just run indent-region on the entire file and you get a fast visual indication of where you misplaced a brace. Trying this on Python code would require you to restore from a backup file. Another example is copying and pasting from external sources (web pages for instance) where the indentation gets totally screwed. In a language with block delimiters this is fixed with a couple keystrokes in Emacs. In Python it requires manually comparing each line with the original (or typing it in manually to begin with). I *like* the significant whitespace in Python but let's not pretend there isn't at least a small penalty. And I strongly suspect Python's varied syntactical rules impose far more of a "load" on code editors than Lisp does (it certainly offers more opportunity for the editor to do the wrong thing). Regards, Cliff > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ejatwellkeeperdotcom Wed Dec 27 12:22:17 2006 From: ejatwellkeeperdotcom (Erik Johnson) Date: Wed, 27 Dec 2006 10:22:17 -0700 Subject: getting a process's PID References: <20061227102939.L20663@eris.io.com> Message-ID: <4592abf1$1@nntp.zianet.com> "eldorado" wrote in message news:20061227102939.L20663 at eris.io.com... > Hello, > > I am trying to get python to give me the PID of a process (in this case > HUB). I have it working, except for the fact that the output includes > \012 (newline). Is there a way to ask python not to give me a newline? > > Python 1.4 (Oct 14 1997) [C] > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >>> import os > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] There's more than one way to do it! (Oh, sorry, that's Perl...) The two most standard ways would be to call strip() on your string to get one sans both leading and trialing whitespace print h.strip() or if you know exactly what you've got (i.e., the newline you don't want is just the last character), you can just get rid of it: h = h[:-1] HTH, -ej From ihatespam at hotmail.com Thu Dec 14 20:20:34 2006 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Fri, 15 Dec 2006 01:20:34 GMT Subject: I'm looking for a pythonic red-black tree... Message-ID: I need a red-black tree in Python and I was wondering if there was one built in or if there's a good implementation out there. Something that, lets face it, does whatever the C++ std::map<> allows you to do... Thank you... From exarkun at divmod.com Sun Dec 3 23:31:56 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Sun, 3 Dec 2006 23:31:56 -0500 Subject: Why not just show the out-of-range index? In-Reply-To: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> Message-ID: <20061204043156.20948.1778473369.divmod.quotient.56857@ohm> On 3 Dec 2006 17:23:49 -0800, Russ wrote: > >> Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. > >Now, that would be rather silly. I would have to familiarize myself >with the code for the Python interpreter, then send a patch to the >maintainers (and hope they notice it in their inboxes), while the >maintainers themselves could probably "fix" the problem in two minutes >flat. No thanks! And I have some laundry that I would like you to do for me. Let me know when a convenient time for you to pick it up would be. Jean-Paul From fredrik at pythonware.com Tue Dec 5 11:24:14 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 17:24:14 +0100 Subject: Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 In-Reply-To: <1165335542.402398.193100@f1g2000cwa.googlegroups.com> References: <1165335542.402398.193100@f1g2000cwa.googlegroups.com> Message-ID: etaoinbe wrote: > I have added advapi32 &user32. This is my current result : > > I am quite surprised there are so many issues with the solution file > that comes with python25. > I remember py23 built out of the box :( python 2.5 also builds out of the box, if you're using an ordinary visual studio installation, instead of an incomplete "express" edition of unknown quality. From lorenlightng at gmail.com Fri Dec 1 17:18:15 2006 From: lorenlightng at gmail.com (g4rlik) Date: Fri, 1 Dec 2006 14:18:15 -0800 (PST) Subject: v2.3, 2.4, and 2.5's GUI is slow for me In-Reply-To: References: <7630074.post@talk.nabble.com> Message-ID: <7647276.post@talk.nabble.com> It is always slow, even when I first start it up and do not enter in any code. This is really bugging me, maybe I have OCD >__> I turned off my anti-virus and that didn't help. Oh well. I'm just glad to know that other people have this problem too. Duncan Booth-2 wrote: > > g4rlik wrote: > >> No one can help? This is seriously bugging me to no end. > >>> My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run >>> very sluggishly. When I type in them or move them around my desktop, >>> it's very slow. I have figured out that this is because of the >>> subprocesses running. > > Always slow or just sometimes? Idle can get very slow if you have > generated > a lot of output in the shell window, but usually it performs just fine. If > you've accidentally printed "range(100000)" then your best best is to kill > it and restart. > > Use idle for development and testing: its best if you run actual scripts > outside the development environment. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/v2.3%2C-2.4%2C-and-2.5%27s-GUI-is-slow-for-me-tf2735011.html#a7647276 Sent from the Python - python-list mailing list archive at Nabble.com. From eadmund42 at NOSPAMgmail.com Tue Dec 12 13:02:38 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 11:02:38 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: aahz at pythoncraft.com (Aahz) writes: > > Consider this: Lisp has had years of development, it has had millions of > dollars thrown at it by VC firms -- and yet Python is winning over Lisp > programmers. Think about it. The argument from popularity is invalid. French units have overtaken standard units, yet they are technically worse. Windows has overtaken Unix, yet it is technically worse. The market does not select the technically best (although it may select what is best when all factors are taken into account; e.g. Windows may be better when dealing with an ignorant workforce, and French units may be better when dealing with users thereof). -- Robert Uhl Traditionally, there are only three classes of people who use 'we' in describing themselves: Royalty (which you aren't), editors (no evidence that this applies) and people with tapeworms. Please let us know when you've been cured. --Hal Heydt, to Dennis O'Connor From pyenos at pyenos.org Fri Dec 22 20:23:28 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 12:23:28 +1100 Subject: scopes of local and global variable References: <87tzzncx59.fsf@pyenos.pyenos.org> <87psabcvlc.fsf@pyenos.pyenos.org> <1166836721.486427.111520@h40g2000cwb.googlegroups.com> Message-ID: <87irg3qub3.fsf@pyenos.pyenos.org> "Max Wilson" writes: > Pyenos wrote: > > does class WORK inherit t_len=0 from line1? > > > > does def getwork() inherit t_len=0 from line1? > > > > does def formattable(table_to_process,type) inherit t_len=0 from line1? > > > > does def format_t() inherit t_len=0 from line1? > > Not really, no. The global t_len is different than the local t_len--two > variables with the same name. You need to declare "global t_len" inside > your function so it knows that "t_len=..." is assigning to the old, > global variable instead of creating a new one. > > See #6 here: http://zephyrfalcon.org/labs/python_pitfalls.html > > -Max so, based on your advice, i think the answers are all no. From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 23:49:44 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 15:49:44 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: On Sun, 10 Dec 2006 03:37:26 +0000, Kirk Sluder wrote: >> But at least you know that foolib is a module or package. You know what >> from and import do, and that can't change. And you know that bar is an >> object with a method also called bar, it is being called, and the >> argument is a string "somefile". Those things can't change. Imagine a >> hypothetical language where those two lines could mean *anything*. > > But as was pointed out earlier in the thread, those keywords can be > overshadowed by custom functions in python as well. Really? >>> def import(): File "", line 1 def import(): ^ SyntaxError: invalid syntax Nope, can't shadow or change keywords. (And yes, the error message could be better.) > The only reason > that we don't assume those two python lines could mean *anything* is > because those mechanisms are not well advertised, and most people > don't have a need to shadow "import." Or because they can't mean just anything. > Of course, it is possible to abstract away all of the lisp in such a > way that you have a completely new programming language. But is this > really a problem? Perl5 and bash are abstractions of C. Python has > been implemented on both C and java, and chunks of perl6 have been > implemented on top of Haskell. That depends. If somebody smart is designing a new programming language, then no, you get a new programming language. If somebody not-so-smart is merely hammering the round peg of Lisp into the square hole of not-quite-Lisp-and-not-quite-anything-else, then yes, that will be a problem. But apparently, despite the talk of using macros to implement anything in Lisp, nobody actually does that. >> My point isn't whether or not their claims are correct (a "couple" of >> macros? really?) but that things like this feed the perception that Lisp >> is close to that hypothetical language where anything could be anything. >> If anything could be anything, do you really know what (+ 1 2) means >> without reading every line of code? > > How do you know that operator has not been shadowed or overloaded in > python? Because the tokens 1 and 2 cannot be anything but ints, and + with two int args cannot be anything but addition. >> Or maybe it is only an advantage while Lisp programmers are a >> self-selected group of above-average skill. Wait until fifty million VB >> code monkeys start writing Lisp macros and maybe, just maybe, you'll wish >> they were using a less powerful and more restrictive language. > > Perhaps it's because I'm a social scientist and not a programmer by > training, but I find many arguments for *technical* solutions to > *human performance* problems to be rather weak as a general > practice. In some cases, using a very restrictive language may be > the best solution for the problem. I don't know about you, but I'm not talking about VERY restrictive languages -- I'm using Python, which isn't very restrictive at all. But even Lisp has some restrictions -- you can't jump to an arbitrary memory location and treat whatever random bytes are there as executable code, can you? -- Steven. From danielkleinad at gmail.com Fri Dec 29 09:08:57 2006 From: danielkleinad at gmail.com (Daniel Klein) Date: Fri, 29 Dec 2006 14:08:57 GMT Subject: popen on windows References: <1167239813.187357.206240@73g2000cwn.googlegroups.com> Message-ID: On 27 Dec 2006 09:16:53 -0800, "hubritic" wrote: >I am trying to set off commands on Windows 2003 from python. >Specifically, I am trying to use diskpart with a script file (pointed >to with path). > > cmd = ["diskpart", "/s", path] > p = Popen(cmd, shell=True) > >The script is meant to loop through twice. It will do so if I comment >out the Popen call and print cmd instead. But when Popen is called, one >disk will be formated, but not the next. What is the value of 'path' ? Does the command work from a Windows command prompt ? Dan From lone_wolf at ureach.com Sun Dec 3 21:19:00 2006 From: lone_wolf at ureach.com (Lone Wolf) Date: Sun, 3 Dec 2006 21:19:00 -0500 Subject: Parsing data from pyserial, an (inefficient) solution Message-ID: <200612040219.VAA23282@www23.ureach.com> I want to thank everybody who tried to help me, and also to post my solution, even though I don?t think it is a very good one. Many of you correctly guessed that there was an ?\r? included with the packet from the CUMcam, and you were correct. The actual format of the packet is: M xxx xxx xxx xxx xxx xxx xxx xxx\r. Unfortunately, splitting the packet using \r wouldn?t help because the format of the data stream that I get with the components variable (after I split the reading file according to ?M?) generally doesn?t include a complete packet at first. For example, I get: [xxx xxx xxx\r, yyy yyy yyy yyy yyy yyy yyy yyy/r, zzz zzz zzz] Therefore, data from before the first \r (which I have shown as xxx) generally is incomplete and I need to go on to the second packet. Also, for those of you who suggested some kind of delay before reading the serial port, you were right. The first packet from the CMUcam is always a null. Anyway, here is my code: ################################################################ # This program reads a serial port hookup up to a CMUcam version 1. # It tracks the middle of a green object and provides a confidence estimate import serial ser=serial.Serial('com1',baudrate=115200, bytesize=8, parity='N', stopbits=1,xonxoff=0, timeout=1) ser.write("TC 016 240 100 240 016 240\r\n") #This line orders the CMUcam to track green reading = ser.read(40) # CMUcam's first data packet is null, so this line gets it out of the way for i in range(0,100,1): reading = ser.read(40) components = reading.split("M") components = components[1] if len(components) > 23: # If shorter than 24 it won't have enough data for a full packet subcomponents = components.split() mx = int(subcomponents[0]) my = int(subcomponents[1]) confidence = int(subcomponents[7]) print mx, my, confidence ser.close The really sad thing is that I get a perfectly constructed packet from the reading variable, and that gets butchered when I try to slice it up to pick out individual elements. Since pyserial doesn?t do anything to rearrange the data, then the CMUcam must do the heavy lifting of extracting a perfect packet from the data stream. It?s a real shame I couldn?t use it because the program would be more efficient. FWIW, this code will analyze 2-3 frames per second on my computer, which is enough for my purposes. In case you couldn?t tell from the questions/code, I am a total beginner, and I really appreciate this list. All I needed was a hand, not a handout. Wolves are willing to hunt for their supper. ________________________________________________ Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag From bj_666 at gmx.net Thu Dec 28 10:28:35 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Thu, 28 Dec 2006 16:28:35 +0100 Subject: How to return a simple variable from a function (still newbie) ? References: Message-ID: In , Stef Mientki wrote: > I want to return a "simple" variable from a function, not using the > function result. Why? > The code below is from O'Reilly, "Learning Python", and there seems no > way to return a simple var like "z" in the example below. Is that true ? To return objects the ``return`` statement is used. > def some_function (z, y): > z = 2 > y[2] = 'global ?' Add: return z The string content seems to be a question. No `y` is not global here but you modify the content of the object that's bound to the local name `y`. Modifying an object is different from binding a name to a new object. ``y = ['uno', 'dos', 'tres']`` would not be visible outside the function. > x = 5 > y = [1,2,3,4] > print x,y > some_function(x,y) Change to: x = some_function(x, y) Ciao, Marc 'BlackJack' Rintsch From bdesth.quelquechose at free.quelquepart.fr Mon Dec 18 06:21:39 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 18 Dec 2006 12:21:39 +0100 Subject: Dictionary, iterate & update objects In-Reply-To: <1166302637.147669.266480@f1g2000cwa.googlegroups.com> References: <1166302637.147669.266480@f1g2000cwa.googlegroups.com> Message-ID: <4586740d$0$7960$426a34cc@news.free.fr> jansenh a ?crit : > hi comp.lang.python. > > I need some newbe advice on idiomatic use of Python dictionaries. > > I have service with a dictionary which holds a bunch of objects as > values, and an ID as key to each object. Then I want to change an > objects state based on its key. class MyObj(object): def __init__(self, foo): self.foo = foo objs = { 'foo': MyObj('foo'), 'bar', MyObj('bar'), } objs['foo'].foo = 42 for key, obj in objs: print "%s : %s" % (key, obj.foo) > The way I am doing this now is by using > 'fromkeys' and copying my object over in a temporary dictionary, then > manipulating the object, and then I do an 'update' back to the main > dictionary.. :-0 My my my... > There has to be a smarter way? Indeed. Usually, with Python, "smarter" => "simplest" HTH From reverseyorkage at david.com Sun Dec 17 08:46:55 2006 From: reverseyorkage at david.com (dyork) Date: Sun, 17 Dec 2006 13:46:55 GMT Subject: Roundtrip SQL data especially datetime References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: "Dennis Lee Bieber" wrote in message news:mailman.1686.1166257834.32031.python-list at python.org... > If you actually look at what the various DB-API adapters produce > when sending to the database engine, floats, bools, etc. are all sent as > string representations; about the only source for problems would be > involved in the number of significant digits transferred for a float > (you might feed 15 digits in, and only get 7 or 10 back) Having written adapters myself, I would not be confident that is true. It's convenient to use native formats for floats and ints, and strings for everything else. Regardless, you get trouble with (a) nulls (b) dates/times (c) decimal/currency (d) precision mismatches (e) collation mismatches (f) blobs (g) Unicode (h) special values like NaN. It takes great attention to detail to be sure it all works, and I really don't want to write it (again). I'd just like to choose some product X and "It Just Works"! DY From kay.schluehr at gmx.net Sun Dec 10 04:04:10 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 10 Dec 2006 01:04:10 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165616311.901535.249780@l12g2000cwl.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <1165616311.901535.249780@l12g2000cwl.googlegroups.com> Message-ID: <1165741450.601489.321550@73g2000cwn.googlegroups.com> tayssir.john at googlemail.com schrieb: > A few months ago, I missed the Condition System most > when using Python, and also lexical scope. However, it is nice to work > with friends, who know Python and not Lisp.) Could you explain in which way Python lacks lexical scoping? From ekozlowski1 at gmail.com Wed Dec 27 18:14:08 2006 From: ekozlowski1 at gmail.com (Edward Kozlowski) Date: 27 Dec 2006 15:14:08 -0800 Subject: failing to instantiate an inner class because of order of inner classes In-Reply-To: <87wt4dos3i.fsf@pyenos.pyenos.org> References: <87wt4dos3i.fsf@pyenos.pyenos.org> Message-ID: <1167261247.982957.308820@a3g2000cwd.googlegroups.com> Pyenos wrote: > class model:pass > class view: > model() > class controller: > model() > > I can instantiate clsss model from inside class view but I can't > instantiate class model from inside controller, due to the nature of > python interpreter. > > I wish to circumvent this restriction by: > > class model:pass > class view: > parent_class.model() > class controller: > parent_class.model() > > but, I don't know the built-in variable that points to the parent > class. Could someone tell me how can I instantiate class model from > inside controller AND instantiate class model from inside view? I would try the following: class model: def printFoo(self): print "foo" class view: def __init__(self): self.model = model() class controller: def __init__(self): self.model = model() Then you can do: vObj = view() vObj.model.printFoo() And: cObj = controller() cObj.model.printFoo() From aboudouvas at panafonet.gr Mon Dec 4 12:56:17 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 4 Dec 2006 09:56:17 -0800 Subject: decorators question Message-ID: <1165254977.903936.83180@16g2000cwy.googlegroups.com> Hi, i am new to python and i have a question about how decorators are working. I have understand HOW they do their magic but i am trying to figure out WHEN they do it... I have the following simple example: #----------------------------------------- def author(author_name): def decorator(func): func.author_name = author_name return func return decorator @author("some author") def F(): pass # print F.author_name #----------------------------------------- I am using Eclipse/PyDev and when i run this snippet from the PyDev debugger, i see that even though i do not call F() (or reference F.author_name), the decorator and all this stuff is executed and updates F.autor_name variable. How is this thing really working ?? I mean, if we run this .py file (pythn test.py) from the command prompt, what the runtime will do, even if we do not have ane commands to execute, only functions as above ? It will load all the module, all the functions and when it sees that some function(s) are decorating, then it will start execute respectives decorators ? And this will do it for all decorated functions ?? Even if we do not have any references to these functions ? Shouldn't this code called when we actually DO call it ? Thanks a lot for any enlightment on this, objectref From sjmachin at lexicon.net Sat Dec 16 21:31:09 2006 From: sjmachin at lexicon.net (John Machin) Date: 16 Dec 2006 18:31:09 -0800 Subject: How to test if two strings point to the same file or directory? In-Reply-To: References: <1166317324.791635.274550@79g2000cws.googlegroups.com> <1166319494.222385.232890@t46g2000cwa.googlegroups.com> Message-ID: <1166322669.722451.183510@80g2000cwy.googlegroups.com> Tim Chase wrote: > >>> Comparing file system paths as strings is very brittle. Is there a > >>> better way to test if two paths point to the same file or directory > >>> (and that will work across platforms?) > >> os.path.samefile(filename1, filename2) > >> os.path.sameopenfile(fileobject1, fileobject2) > > > > Nice try, but they don't "work across platforms". > > Okay...double-checking the docs.python.org writeup, it apparently > does "work across platforms" (Mac & Unix), just not "across *all* > platforms", with Win32 being the obvious outlier. My bet would be that it really works on Unix only (OS/X qualifying as Unix) and not on older Mac setups. > It seems a > strange omission from Win32 python, even if it were filled in > with only a stub...something like > > def samefile(f1, f2): > return abspath(f1.lower()) == abspath(f2.lower()) > > it might not so gracefully handle UNC-named files, or SUBST'ed > file-paths, but at least it provides an attempt at providing the > functionality on win32. As it currently stands, it would be > entirely too easy for a [Mac|*nix] programmer to see that there's > a samefile() function available, use it successfully based on its > docstring, only to have it throw an exception or silently fail > when run on win32. The current setup will not "silently fail when run on win32". How could it? It doesn't exist; it can't be run. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. | >>> import os | >>> os.path.samefile Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'samefile' The only way it could "silently fail when run on win32" would be to have a "stub" which gave the wrong answer. From gagsl-py at yahoo.com.ar Fri Dec 22 22:46:33 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Sat, 23 Dec 2006 00:46:33 -0300 Subject: One module per class, bad idea? In-Reply-To: <1166839110.281352.138630@79g2000cws.googlegroups.com> References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> <458c489c$1@nntp.zianet.com> <1166823140.827296.92960@h40g2000cwb.googlegroups.com> <1166829929.511423.110970@h40g2000cwb.googlegroups.com> <1166839110.281352.138630@79g2000cws.googlegroups.com> Message-ID: <7.0.1.0.0.20061223004150.01dd7cc8@yahoo.com.ar> At Friday 22/12/2006 22:58, Carl Banks wrote: > > Usually no other files need to change. Ex: you have BigOldModule > > including ClassA, ClassB and FunctionC. Move each one onto its own > > module, perhaps including a subset of the original imports of BigOldModule. > > Shrink BigOldModule to just: > > > > from ClassA import ClassA > > from ClassB import ClassB > > from functionC import functionC > > > > and maybe a few other things, so all imports from the outside remain > > the same. That's all - most of the time. > >I wouldn't recommend this unless it's important not to change the >external usage. If you're doing it just to save work in refactoring, >it's a partial solution hack that'll lead to more confusion and delay a >real solution even more. In some cases you may consider the fact that ClassA is contained in its own module, just an implementation detail, and not part of the package public interfase. -- 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 From juanrgonzaleza at canonicalscience.com Tue Dec 12 03:49:52 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 12 Dec 2006 00:49:52 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165889854.421656.117720@l12g2000cwl.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165857489.067258.27160@j44g2000cwa.googlegroups.com> <1165874781.930864.26750@16g2000cwy.googlegroups.com> <1165889854.421656.117720@l12g2000cwl.googlegroups.com> Message-ID: <1165913392.734929.290910@f1g2000cwa.googlegroups.com> Kaz Kylheku ha escrito: > Kay Schluehr wrote: > > Juan R. wrote: > > > A bit ambiguous my reading. What is not feasible in general? Achieving > > > compositionality? > > > > Given two languages L1 = (G1,T1), L2 = (G2, T2 ) where G1, G2 are > > grammars and T1, T2 transformers that transform source written in L1 or > > L2 into some base language > > L0 = (G0, Id ). Can G1 and G2 be combined to create a new grammar G3 > > s.t. the transformers T1 and T2 can be used also to transform L3 = (G3 > > = G1(x)G2, T3 = T1(+)T2) ? In the general case G3 will be ambigous and > > the answer is NO. But it could also be YES in many relevant cases. So > > the question is whether it is necessary and sufficient to check whether > > the "crossing" between G1 and G2 is feasible i.e. doesn't produce > > ambiguities. > > See, we don't have this problem in Lisp, unless some of the transfomers > in T1 have names that clash with those in T2. That problem can be > avoided by placing the macros in separate packages, or by renaming. Or simply namespacing! foo from package alpha --> alpha:foo foo from package beta --> beta:foo But what composition of different languages? E.g. LISP and Fortran in the same source. > In > In the absence of naming conflicts, the two macro languages L1 and L2 > combine seamlessly into L3, because the transformers T are defined on > structure, not on lexical grammar. The read grammar doesn't change (and > is in fact irrelevant, since the whole drama is played out with > objects, not text). In L1, the grammar is nested lists. In L2, the > grammar is, again, nested lists. And in L3: nested lists. So that in > fact, at one level, you don't even recognize them as being different > languages, but on a different level you can. > > The problems you are grappling with are in fact created by the > invention of an unsuitable encoding. You are in effect solving a puzzle > that you or others created for you. From sam1 at honeypot.spam Thu Dec 21 06:03:38 2006 From: sam1 at honeypot.spam (sam1) Date: Thu, 21 Dec 2006 12:03:38 +0100 Subject: rsync for python? In-Reply-To: References: Message-ID: nienfeng wrote: > Hi, everyone > > I want to build rsync server that can run in linux and windows, and > configure by python. So I'm looking for something like rsync for python. > I find rsync.py and pysync. But rsync.py looks like a client mode, it > can't be a rsync server, is it? Can pysync be a rsync server? > > Thanks.... by nienfeng This one for Windows and Linux is all in Python and its configuration is also Python scripting : http://www.xellsoft.com/SynchronEX.html#features GUI wizards can create starting script templates for more complex tasks. You'd not need to run an extra server as it directly uses SFTP, DAV (HTTP(S)), FTP(S), Local-Filesystem/NFS, Windows-Network .. standards for WAN/LAN transfer. Sam From richardjones at optushome.com.au Tue Dec 12 16:18:07 2006 From: richardjones at optushome.com.au (Richard Jones) Date: Wed, 13 Dec 2006 08:18:07 +1100 Subject: Can't register to CheeseShop at command line...only on web?!.. References: <1165882269.932773.317580@j44g2000cwa.googlegroups.com> <457e7000$0$9775$afc38c87@news.optusnet.com.au> <1165942871.142337.247700@73g2000cwn.googlegroups.com> Message-ID: <457f1c90$0$29167$afc38c87@news.optusnet.com.au> seberino at spawar.navy.mil wrote: >> > Here is what happens when I try to register at command line with >> > .pypirc above... >> > >> > Using PyPI login from /home/seb/.pypirc >> > Server response (401): Authorization Required >> >> Do you use a proxy to access the web? > > Not that I'm aware of unless my job uses one without my knowing about > it. > If I am..is there a workaround for proxies? Please follow the "Get help" link on the Cheese Shop site to continue this conversation. Richard From carsten at uniqsys.com Tue Dec 26 07:57:18 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Tue, 26 Dec 2006 07:57:18 -0500 Subject: How to stop program when threads is sleeping In-Reply-To: <1167112215.615162.106500@h40g2000cwb.googlegroups.com> References: <1167029711.446218.133930@f1g2000cwa.googlegroups.com> <1167112215.615162.106500@h40g2000cwb.googlegroups.com> Message-ID: <20061226124849.M84430@uniqsys.com> On 25 Dec 2006 21:50:15 -0800, many_years_after wrote > While , there is something wrong in my expression. What I mean is the > thread will wait some time after doing some tasks. I want to know is > there any method to end the thread or make it out of execution of > waiting. I use time.sleep() to let the thread wait. We can't help you if you don't tell us what you need. It's still not quite clear what exactly you need, but one thing you should know is that you can't stop a thread while it's sleep()ing, so using sleep() is probably the wrong approach. The wait() method of the threading.Event object from my previous response can take an optional timeout argument. This will make your thread wait until the timeout elapses or until the event is .set() by another thread, whichever comes first. Hope this helps. If this doesn't help, please tell us exactly what you need and maybe show us some code. Carsten. From http Tue Dec 12 19:49:48 2006 From: http (Paul Rubin) Date: 12 Dec 2006 16:49:48 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> <7xodqczf1h.fsf@ruckus.brouhaha.com> <7xk60zjl1e.fsf@ruckus.brouhaha.com> <7xk60x7wka.fsf@ruckus.brouhaha.com> <7x64chuig6.fsf@ruckus.brouhaha.com> <4u8kibF15vhn5U1@mid.individual.net> Message-ID: <7xwt4wtyab.fsf@ruckus.brouhaha.com> Pascal Costanza writes: > It's funny: Language designers have been spending a lot of effort over > the decades on designing language constructs that help to improve the > opportunities to reuse of software libraries. Yet every five years, or > so, new languages and technologies come up that require everyone to > start from scratch. Starting from scratch is even being applauded, due > to some mythical belief that "this time, we are going to get it all right." What leads to the best work in language research is not necessarily what leads immediately to the most useful tools for software developers. From juanrgonzaleza at canonicalscience.com Mon Dec 11 03:33:28 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 11 Dec 2006 00:33:28 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165768221.753809.4270@f1g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xac1wr7t9.fsf@ruckus.brouhaha.com> <1165768221.753809.4270@f1g2000cwa.googlegroups.com> Message-ID: <1165826008.371063.293080@73g2000cwn.googlegroups.com> philip.armitage at gmail.com ha escrito: > - Lisp is hard to learn (because of all those parenthesis) I cannot understand why. It is like if you claim that packaging things in boxes is difficult to learn. HTML and XML have more brackets than LISP (usually double) for structuring data and everyone has learned HTML. From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 12:24:43 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 04:24:43 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> Message-ID: On Sat, 09 Dec 2006 14:00:10 +0000, Timofei Shatrov wrote: > On Sat, 09 Dec 2006 20:36:02 +1100, Steven D'Aprano > tried to confuse everyone with this > message: > >>On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote: >> >>> if Common Lisp didn't have CLOS, its object system, I could write my own >>> as a library and it would be just as powerful and just as easy to use as >>> the system Common Lisp already provides. Stuff like this is impossible >>> in other languages. >> >>Dude. Turing Complete. Don't you Lisp developers know anything about >>computer science? > > Here, you've basically shot yourself in the ass. Appealing to Turing > completeness when talking about programming language features is about the > dumbest thing you can make. In Turing sense, a program is simply a function that > takes an argument and returns a value. It doesn't say anything about how this > function was implemented. It could be Turing machine, lambda calculus, Markov > chains or whatever else. All these methods produce the same set of programs, but > that doesn't mean you could implement lambda in Turing machine for example. What exactly are you trying to say here? Is this a comment about the relative practicality of writing code in a Turing machine versus high-level languages, or are you implying that lambda calculus is "bigger" than any Turing-complete language? If you're talking about practicality, then of course you're correct, not all languages are equally expressive. Some languages are not expressive enough. Some languages are too expressive. No language is optimal for all people for all tasks. > Is is time for someone to read his computer science books again? Probably. Would you like to borrow mine? Look, all snarkiness aside, it just isn't true that "stuff like this is impossible in other languages". If Wolfram Fenske had said "stuff like this isn't easy in many other languages" he would have been right. And if he had said "and stuff like this carries risks as well as benefits" he would have come across as less of a language fanatic. One of the risks with Python is the ease with which you can modify the built-ins. An expression like list(2, 3, 4) doesn't necessarily create a list from 2, 3, and 4, because the built-in list could be redefined. (In practice, that's not often a real problem, because experienced Python developers simply learn not to needlessly or confusingly shadow built-ins. It's not the best system, but it works well enough in practice.) But at least the basic syntax and keywords of the language are known to be constant. With Lisp macros, even that isn't guaranteed. Now, if Lispers would say "Oh yes, macros give you great power, and with great power comes great responsibility. Be careful." then, no doubt, we'd take you guys more seriously. But we don't hear that -- we hear Lispers going on and on about how great it is that they can easily redefine every corner of the language. Do you blame people for *believing them* and imagining that reading Lisp code is like following some ghostly will-o-the-wisp across a swamp, where nothing is what it seems and the landscape is forever shifting? Now, if you want to tell me that, despite all the talk, Lisp coders don't actually create new syntax or mini-languages all that often, that they just use macros as functions, then the question becomes: why do you need macros then if you are just using them as functions? Why not use functions? -- Steven. From bdesth.quelquechose at free.quelquepart.fr Wed Dec 20 15:17:38 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 20 Dec 2006 21:17:38 +0100 Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects In-Reply-To: <458993ff$0$26521$426a74cc@news.free.fr> References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> <458993ff$0$26521$426a74cc@news.free.fr> Message-ID: <4589949b$0$26521$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > thompson.marisa at gmail.com a ?crit : > > 4/ the Python 'for' loop is meant to iterate over an iterable and taking > care of boundaries, so you'd be better using it: > > townships = gp.ListFeatureClasses ("*") > for township in townships: > doSomethingWith(township) Actually, forget the for loop (cf Fredrik's post - looks like gp.ListFeatureClasses() doesn't return an iterable...) From mail at microcorp.co.za Tue Dec 12 00:39:25 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 12 Dec 2006 07:39:25 +0200 Subject: alternate language References: Message-ID: <034701c71dc2$cf3b9d40$03000080@hendrik> "Bryan" wrote: > what is a good alternate language to learn? i just want something to expand > my mind and hopefully reduce or delay any chance of alzheimer's. i would > especially like to hear from those of you who learned python _before_ these > languages. > > haskell, erlang, ocaml, mozart/oz, rebel, etc. > > i don't require any of these features, but extra browny points for any of > the following: > > interactive interpreter > batteries included > can integrate with c > compiles to native code > can use a gui toolkit such as wx > doesn't take 60 hour weeks over years to master Here's a skewed alternative, that has none of the features you are looking for: 1) Buy a development kit for a pic, 8031, avr or arm. 2) Read the documentation for the processor 3) Write a "hello world" in Assembler, simultaneously flickering an LED. It will give more satisfaction, and delay the onset of Alzheimer's, far more effectively than any of the higher level languages you are contemplating. And if you really want a challenge, don't use the assembler, hand code the hex. Just once. Just so that you can appreciate what an assembler, and by extension, a compiler, does for you. - Happy hacking ;-) - Hendrik From paddy3118 at netscape.net Tue Dec 12 20:15:12 2006 From: paddy3118 at netscape.net (Paddy) Date: 12 Dec 2006 17:15:12 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> Message-ID: <1165972511.961406.100360@79g2000cws.googlegroups.com> Jes?s Carrete Monta?a wrote: > > Fast. Very fast! > > > > - Paddy. > > > Well, Python certainly is faster than most people doing floating-point > arithmetic by hand, but I don't think this is the correct argument to use > against Lisp :-P. Why not! Lispers can indeed roll-their-own anything, many do it seems do just that. But others look at the *time saving* libraries available to users of Python and think hmm... -Paddy. From greg at cosc.canterbury.ac.nz Mon Dec 11 06:09:48 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 12 Dec 2006 00:09:48 +1300 Subject: Automatic debugging of copy by reference errors? In-Reply-To: <1165808664.074268.114910@l12g2000cwl.googlegroups.com> References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165808664.074268.114910@l12g2000cwl.googlegroups.com> Message-ID: <4u4smqF1691oiU1@mid.individual.net> Russ wrote: > The copy by reference semantics of Python give it great > efficiency but are also its achille's heel for tough-to-find bugs. You need to stop using the term "copy by reference", because it's meaningless. Just remember that assignment in Python is always reference assignment. If you want something copied, you need to be explicit about it. > I later discovered that a > particularly nasty bug was due to the fact that my constructor "copied" > the initializing list by reference. The reason you made that mistake was that you were using the wrong mental model for how assignment works in Python -- probably one that you brought over from some other language. When you become more familiar with Python, you won't make mistakes like that anywhere near as often. And if you do, you'll be better at recognising the symptoms, so the cause won't be hard to track down. > So a fundamental question in Python, it seems to me, is when to take > the performance hit and use "copy" or "deepcopy." Again, this is something you'll find easier when you've had more experience with Python. Generally, you only need to copy something when you want an independent object that you can manipulate without affecting anything else, although that probably doesn't sound very helpful. In your vector example, it depends on whether you want your vectors to be mutable or immutable. It sounds like you were treating them as mutable, i.e. able to be modified in-place. In that case, each vector obviously needs to be a new object with the initial values copied into it. The alternative would be to treat your vectors as immutable, i.e. once created you never change their contents, and any operation, such as adding two vectors, produces a new vector holding the result. In that case, two vectors could happily share a reference to a list of values (as long as there is nothing else that might modify the contents of the list). -- Greg From andre.roberge at gmail.com Fri Dec 15 06:59:00 2006 From: andre.roberge at gmail.com (=?iso-8859-1?B?QW5kcuk=?=) Date: 15 Dec 2006 03:59:00 -0800 Subject: automatically grading small programming assignments In-Reply-To: References: <1166129734.888298.210830@l12g2000cwl.googlegroups.com> <1166131842.963017.206130@79g2000cws.googlegroups.com> <1166158550.874904.109000@80g2000cwy.googlegroups.com> Message-ID: <1166183940.286391.325190@j72g2000cwa.googlegroups.com> Brian Blais wrote: > Dan Bishop wrote: > > On Dec 14, 8:36 pm, Brian Blais wrote: > >> commander.co... at hotmail.com wrote: > >>> bearophileH... at lycos.com wrote: > >>> Then on your PC you can > >>>> run a script that loads each of such programs, and runs a good series > >>>> of tests, to test their quality... > >>> What happens if someone-- perhaps not even someone in the class-- does > >>> some version of os.system('rm -Rf /') ?I was thinking of including a dummy os.py and sys.py, so import os, and import sys > >> would fail. Would this work? > > > > How would they access their command-line arguments without sys.argv? > > > > the types of assignments that I am envisioning (finding the maximum in a list, > parsing strings, etc.) will not need anything offered in os or sys. Certainly, if > they were needed, another solution would need to be found. > > If you do a search on the web, you will find that there are many other security problems in Python that can not be prevented by simply including dummy modules for os and sys. Brett Cannon's PhD thesis is, afaik, based on looking at ways of creating a secure Python environment. Other suggestions mentioned before (like running in a virtual environment) might be the best way to go for now. Having the user run the program on their own machine (like would be done with the current version of Crunchy already mentioned in this thread) would keep yours safe. Crunchy's doctest feature could be "easily" modified so that it logs the number of attempts and mail the results to a given address. Andr? From rampeters at gmail.com Tue Dec 5 18:50:12 2006 From: rampeters at gmail.com (johnny) Date: 5 Dec 2006 15:50:12 -0800 Subject: newb: Join two string variables Message-ID: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> How do I join two string variables? I want to do: download_dir + filename. download_dir=r'c:/download/' filename =r'log.txt' I want to get something like this: c:/download/log.txt From rachele.defelice at gmail.com Wed Dec 13 10:06:32 2006 From: rachele.defelice at gmail.com (ardief) Date: 13 Dec 2006 07:06:32 -0800 Subject: newbie - HTML character codes In-Reply-To: References: <1166018453.981657.33780@79g2000cws.googlegroups.com> Message-ID: <1166022391.933704.178190@80g2000cwy.googlegroups.com> thank you both - in the end I used recode, which I wasn't aware of. Fredrik, I had come across your script while googling for solutions, but failed to make it work.... On Dec 13, 2:21 pm, "Fredrik Lundh" wrote: > "ardief" wrote: > > sorry if I'm asking something very obvious but I'm stumped. I have a > > text that looks like this: > > > Sentence 401 > > 4.00pm — We set off again; this time via Tony's home to collect > > a variety of possessions, finally arriving at hospital no.3. > > Sentence 402 > > 4.55pm — Tony is ushered into a side ward with three doctors and > > I stay outside with Mum. > > > And I want the HTML char codes to turn into their equivalent plain > > text. I've looked at the newsgroup archives, the cookbook, the web in > > general and can't manage to sort it out. > > file = open('filename', 'r') > > ofile = open('otherfile', 'w') > > > done = 0 > > > while not done: > > line = file.readline() > > if 'THE END' in line: > > done = 1 > > elif '—' in line: > > line.replace('—', '--')this returns a new line; it doesn't update the line in place. > > > ofile.write(line) > > else: > > ofile.write(line)for a more general solution to the actual replace problem, see: > > http://effbot.org/zone/re-sub.htm#unescape-html > > you may also want to lookup the "fileinput" module in the library reference > manual. > > From gagsl-py at yahoo.com.ar Mon Dec 18 06:24:09 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 18 Dec 2006 03:24:09 -0800 Subject: Core dump revisited In-Reply-To: <1166349672.479548.4460@80g2000cwy.googlegroups.com> References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> Message-ID: <1166441048.981964.150110@t46g2000cwa.googlegroups.com> On 17 dic, 07:01, "Sheldon" wrote: > I have a python script that uses a C extention. I keep getting a > recurring problem that causes a core dump a few lines after the C > extention return data back tp python. I tried using pbd and gdb but I Most probably the error is inside the C extension, not in Python code. Contact the author. -- Gabriel Genellina From ejatwellkeeperdotcom Fri Dec 22 16:04:54 2006 From: ejatwellkeeperdotcom (Erik Johnson) Date: Fri, 22 Dec 2006 14:04:54 -0700 Subject: One module per class, bad idea? References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> Message-ID: <458c489c$1@nntp.zianet.com> There are arguments of preference to be made on both sides. I think the question largely comes down to what is "workable" and "maintainable". To answer the original question, I think it is not necessarily a bad idea to have one class per file. But if your classes are small, or certain classes are logically related to other classes (e.g., one class is a subclass of another, or one class is implemented in terms of another, or the two classes work together to accomplish some task and it wouldn't make much sense to be using just one of the classes), it makes a lot of sense to keep them together in the same file. If your classes are only a few dozen lines, making lots of files may be more of a pain than having the code together in one file. Where I work, we started with a set of classes that provided a layer of abstraction and encapsulation to accessing our database tables. An object was basically just a loaded DB record and generally didn't provide a lot else. As time went on, we started to code more and more logic into these classes that provided various functions to make it easy to load records, do certain kinds of computations and filtering with them, to generate the SQL to do the insert for the record, etc. The file has now grown into a 6800 line beast (including docstring, whitespace, and CVS history). Pretty much any time we implement some new functionality, there are at least a few changes in that file. When you have multiple developers working on different projects, and they all need to be making changes to that file, the chances for someone making a merge error goes up. So, we are obviously at a point where that file needs to be split up, but there are lots of other files that import and use the one file, so it is a task that has been put off. In retrospect, I wish I has started things under a one class per file strategy, but at the time, it didn't make a lot of sense to split those things up and I didn't anticipate the code getting that big. So... there's no magic "one size fits all" answer here - do what makes sense. As Carl points out, decent editors should be able to handle dispaying different files. I use vim and know I can split the window (both horizontally and vertically), editing either different sections of the same file or different files and can cut and paste between the two windows. In practice, I usually just jump between places in the same file under a single window, or I textually cut and paste between two separate vim sessions, but if that's something you need to do a lot, you might want to invest a bit in learning how to use split windows in your editor. Some of the documentation for doing this under vim can be found here: http://vimdoc.sourceforge.net/htmldoc/windows.html#:split and here: http://vimdoc.sourceforge.net/htmldoc/usr_08.html (I'm sure emacs can do this as well, but I don't know emacs.) If your editor can't handle similar tasks, you might want to consider getting a better editor. HTH, -ej "Carl Banks" wrote in message news:1166817152.414154.151390 at 42g2000cwt.googlegroups.com... > Kent Johnson wrote: > > Carl Banks wrote: > > > Now, I think this is the best way to use modules, but you don't need to > > > use modules to do get higher-level organization; you could use packages > > > instead. It's a pain if you're working on two different classes in the > > > same system you have to keep switching files; but I guess some people > > > prefer to switch files rather than to scroll for some reason. > > > > That would be me. I strongly prefer to switch files rather than scroll. > > I use an editor that makes it easy to switch files. For me it is much > > easier to switch between files than to scroll between two parts of a > > file, and I don't lose my place when I switch back. I like to be able to > > see things side by side. > > Man, I don't know you do it. > > Say I'm sitting there concentrating on programming something, and I see > that I'll have to make a change in another file. All of a sudden, I > have to recall some filename out of thin air. Totally breaks my train > of thought, sometimes I space out trying to think of it because I have > to cold-start an entirely different part of my brain. It's less of a > mental distraction to just scroll. > > I'm in the habit of changing things as soon as the need arises. If I'm > editing A and I see that I'll have to make a change in B, I stop > editing A, change B, then come back to A. For me, it results in MUCH > fewer forgotten changes (YMMV). But it also means a lot of switching. > Consequently, trying to minimize distraction during switches is > important to me. Maybe it isn't if you switch less frequently, and > rarely while in the middle of somthing. I wonder if there's any > correlation between how often one switches location, and preferrence > (tolerance) for file size. I bet the more often one switches location, > the more likely they are to prefer larger files. > > (BTW, any decent editor will let you view different positions of the > same file side-by-side.) > > > > So I do tend to put classes in separate modules. Not always - when two > > or more classes are closely related or a class has one or more helper > > classes they may share a module - but in general my major classes are > > each to a module. > > > > It does make the imports look funny - I tend to give the module the same > > name as the class, Java style, so I have > > from foo.bar.MyClass import MyClass > > but that is a minor point IMO. > > I'd consider using all lowercase for the module. Of course it doesn't > make sense to come up with a unique name for modules when they're > mostly one-to-one with classes, but it's still nice to give users a > clue whether they object they're looking at is a class or a module. > > > Carl Banks > From roy at panix.com Thu Dec 7 10:43:29 2006 From: roy at panix.com (Roy Smith) Date: Thu, 07 Dec 2006 10:43:29 -0500 Subject: A Call to Arms for Python Advocacy References: <1165505473.337157.104320@j72g2000cwa.googlegroups.com> Message-ID: In article <1165505473.337157.104320 at j72g2000cwa.googlegroups.com>, "Istvan Albert" wrote: > Roy Smith wrote: > > > I think it also appears to need faster hardware. It's running glacially > > slow. > > runs fine here > > i. Maybe it was a transient thing -- it's running fine here too now. From http Wed Dec 13 10:47:23 2006 From: http (Paul Rubin) Date: 13 Dec 2006 07:47:23 -0800 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> Message-ID: <7xwt4vn6gk.fsf@ruckus.brouhaha.com> at writes: > I have a lot times the following code: > > for x in [-2, -1, 0, 1, 2, 3, 4]: > if x > 0: > ... more code... Use: for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x > 0): ... more code ... From rschroev_nospam_ml at fastmail.fm Fri Dec 1 04:47:24 2006 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 01 Dec 2006 09:47:24 GMT Subject: PIL throws exception when reading bitmap/pnm data In-Reply-To: References: Message-ID: Dennis Lee Bieber schreef: > Send a complaint to M$ requesting them to open document the NTFS > format... I've been out of the loop for a while, but the last time I > checked, NTFS was something that should be treated as read-only from > LINUX -- the recommendation was to make a small FAT-32 partition for any > data that needed to be shared. Going off-topic, but there's another way nowadays: if your Linux partitions use ext2 or ext3, you can use read/write them from Windows with the file system drivers from http://www.fs-driver.org/ -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From gert.cuykens at gmail.com Tue Dec 19 17:35:53 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Tue, 19 Dec 2006 23:35:53 +0100 Subject: Http server In-Reply-To: References: <1166563266.178045.251540@73g2000cwn.googlegroups.com> Message-ID: > > The cute secretary's name is "cherrypy.tools.staticdir". > > Check out her resume at http://www.cherrypy.org/wiki/StaticContent > > I think i am in love :) Cant believe this just works out import os.path import cherrypy pwd = os.path.dirname(os.path.abspath(__file__)) class Http: _cp_config = {'tools.sessions.on': True} @cherrypy.expose def index(self): f = open(os.path.join(pwd, '../htm/index.htm')) xml = f.read() f.close() return xml if __name__ == '__main__': cherrypy.config.update({'server.socket_port': 8080, 'server.thread_pool': 10, 'environment': 'production', 'log.screen': True}) conf = {'/': {'tools.staticdir.root': os.path.join(pwd, '../htm')}, '/css': {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(pwd, '../css')}, '/js': {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(pwd, '../js')}} cherrypy.quickstart(Http(), '/', config=conf) From Benjamin.Barker at gmail.com Fri Dec 22 19:39:40 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 22 Dec 2006 16:39:40 -0800 Subject: Spyce vs mod_python PSP In-Reply-To: <1166834137.313625.245860@73g2000cwn.googlegroups.com> References: <1166834137.313625.245860@73g2000cwn.googlegroups.com> Message-ID: <1166834380.544273.163610@80g2000cwy.googlegroups.com> ..or any of the many other embedded python solutions that seem to be out thee... Ben wrote: > Hi, > > I have just tarted trying to transfer some of my knowledge of python to > server side applications. I stated off using mod_python PSP because it > was what I found first. I then found spyce, which seems a better > solution. It avoids the problem of keeping indentation correct when > writing code embedded in HTML, and seems to make things like dealing > with forms simpler. Having said that it doesn't seem to appear in the > standard ubuntu repositories, while mod_python PSP does,which would > seemto be a vote against it? > > What do peopl here think? Any suggestions? > > Cheers (and happy christmas), > > Ben From hong.file at gmail.com Sun Dec 3 09:24:56 2006 From: hong.file at gmail.com (progman) Date: 3 Dec 2006 06:24:56 -0800 Subject: cursor.executemany() float error Message-ID: <1165155896.161125.186490@j72g2000cwa.googlegroups.com> Data Struct: from (string), to (string), rate (float) when i run this: cursor.executemany('insert into promo (`From`,`To`, `RATE`) \ values (%s,%s,%f)', [ ('AA','BB',10.2), ('CC','DD',10.3) ] ) i got this error: TypeError: float argument required i checked, 10.2 & 10.3 , there are at the right loc. what went wrong?? From vedran at v-programs.com Fri Dec 8 11:43:15 2006 From: vedran at v-programs.com (Croteam) Date: 8 Dec 2006 08:43:15 -0800 Subject: py2exe install script problem Message-ID: <1165596195.274124.258010@l12g2000cwl.googlegroups.com> Hello, I using py2exe for my script installing,and I have one problem about it,actually the real problem is tkinter window iconbitmap: import Tkinter root=Tkinter.Tk() root.iconbitmap('myicon.ico') # I was try and with myicon.bmp Then after I install myscript in .exe,and when I run it I got error in some strange window: window title: Error occurred window message: See the logfile 'c:\Python24\Lib\site-packages\dist\myscript.exe' for details and tad and in that error "make" in install directory one log file, and that file I run with notepad and in that notepad file write error: Traceback (most recent call last): File "myscript.py", line 3, in ? File "Tkinter.pyc", line 1448, in wm_iconbitmap _tkinter.TclError: bitmap "myicon.ico" not defined Thanks!!!!!!!!! From http Mon Dec 18 08:30:07 2006 From: http (Paul Rubin) Date: 18 Dec 2006 05:30:07 -0800 Subject: How to get a substring with variable indices References: Message-ID: <7xy7p5z600.fsf@ruckus.brouhaha.com> ????????? ???? writes: > text[s:e] generates the following error: > TypeError: slice indices must be integers or None > > How to be? :) s and e both have to be integers or None. Try printing them out just before your slice to see if their values are reasonable. >>> s = 2 >>> e = 4 >>> "python"[s:e] 'th' From sjmachin at lexicon.net Thu Dec 7 00:51:36 2006 From: sjmachin at lexicon.net (John Machin) Date: 6 Dec 2006 21:51:36 -0800 Subject: Need Help Parsing From File In-Reply-To: References: Message-ID: <1165470696.899710.119250@16g2000cwy.googlegroups.com> Gabriel Genellina wrote: > > ftxt=open(filename,"rt") Never seen that done before. It's not in the docs. FWIW: Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> f = open('foo.txt', 'rt') >>> f = open('foo.txt', 'rs') >>> f = open('foo.txt', 'ratsdroppings') # Nary an exception raised, not the slightest murmur Is this a bug or a feature? Or is it one of those good old "unspecified behaviour" cases? MSVC rtl only? Cheers, John From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Wed Dec 13 12:42:23 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Wed, 13 Dec 2006 18:42:23 +0100 Subject: How to manage two (different) sockets without using threads? References: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> Message-ID: <4uasbvF17i4p5U1@mid.individual.net> billie wrote: > I'm (re)writing an FTP server application by using > asyncore/asynchat modules. > FTP tipically got two different channels: command and data. > I'm succesfully managing command channel through asynchat > framework, but I'm not sure about how to manage data channel > without using a thread/subprocess. > Is there an optimal to do that? I don't know much about asynchat, but I think it's been done for this. But if you want to save pain, try the Twisted framework. Regards, Bj?rn -- BOFH excuse #2: solar flares From fredrik at pythonware.com Tue Dec 19 16:26:28 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 22:26:28 +0100 Subject: When Closure get external variable's value? In-Reply-To: <4588505d$0$26434$426a74cc@news.free.fr> References: <1166473333.593246.238580@73g2000cwn.googlegroups.com> <1166474513.700608.201760@48g2000cwx.googlegroups.com> <1166542026.913912.82880@t46g2000cwa.googlegroups.com> <1166544951.721977.281100@t46g2000cwa.googlegroups.com> <1166556458.780265.147420@80g2000cwy.googlegroups.com> <4588505d$0$26434$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> You skipped the first and most important sentence: > "In programming languages, a closure is a function that refers to free > variables in its lexical context." > > IOW, a closure is a function that carry it's own environment. in contrast to functions that don't know what environment they belong to, you mean ? can you identify such a construct in Python ? From grante at visi.com Thu Dec 28 11:48:17 2006 From: grante at visi.com (Grant Edwards) Date: Thu, 28 Dec 2006 16:48:17 -0000 Subject: Some basic newbie questions... References: <1167324002.516960.319870@79g2000cws.googlegroups.com> Message-ID: <12p7tah6gbtq53d@corp.supernews.com> On 2006-12-28, jonathan.beckett wrote: > Hi all, > > While working on support at work, I have been picking away at Python - > because I think it could be a valuable scripting tool for building > utilities from. I have been reading the python.org tutorials, and > playing around with some basic code, but I have ended up with a few > questions that probably have straightforward answers - any quick > explanations or assistance would be fantastic... > > > Question 1... > Given the code below, why does the count method return what it does? > How *should* you call the count method? > a = [] > a.append(1) > print a.count a.count(1) a.count(2) > Question 2... > What is the correct way of looping through a list object in a class via > a method of it? (I've hit all sorts of errors picking away at this, and > none of the tutorials I've found so far cover it very well) - apologies > for the arbitrary class - it's the first example I thought up... > > class Gun: > Shells = 10 What you wrote created a class variable: there's only a single "Shells" object and it's shared by all instances of the class. Based on the way you're using it, I presume you want each gun to have it's own Shells value. You probably want something like this: class Gun: def __init__(self): self.Shells = 10 > class Battleship: > Gun1 = Gun() > Gun2 = Gun() > Guns = [Gun1,Gun2] > > def getShellsLeft(self): > NumShells = 0 > for aGun in Guns: > NumShells = NumShells + aGun.Shells > return NumShells > > Bizmark = Battleship() > > print Bizmark.getShellsLeft() > > > In the above code, I guess I'm just asking for the *correct* way to do > these simple kinds of things... -- Grant Edwards grante Yow! Give them at RADAR-GUIDED SKEE-BALL visi.com LANES and VELVEETA BURRITOS!! From JohnRoth1 at jhrothjr.com Thu Dec 7 10:20:27 2006 From: JohnRoth1 at jhrothjr.com (John Roth) Date: 7 Dec 2006 07:20:27 -0800 Subject: Best way to split up lines - RE: About the 79 character linerecommendation In-Reply-To: References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com> <012601c719f7$9e719990$0d7d12ac@kearfott.com> Message-ID: <1165504827.929064.189040@79g2000cws.googlegroups.com> Fredrik Lundh wrote: > Michael Yanowitz wrote: > > > What would be the best way to split the following line (Python doesn't like > > me to split it up between the comma-separated parameters): > > > > top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, > > utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, > > st2, st3, st4, st5, st6, numberOfLabels, dataWord = > > struct.unpack("!H4BH20BHI", strMessage) > > data = struct.unpack("!H4BH20BHI", strMessage) > > (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, > dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, > utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, > numberOfLabels, dataWord) = data > > Or simply put parentheses around the tuple on the left, and use the ending parenthesis to get to the last line: (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, numberOfLabels, dataWord ) = struct.unpack("!H4BH20BHI", strMessage) John Roth From eight02645999 at yahoo.com Mon Dec 11 23:36:11 2006 From: eight02645999 at yahoo.com (eight02645999 at yahoo.com) Date: 11 Dec 2006 20:36:11 -0800 Subject: paramiko public key Message-ID: <1165898171.088807.100360@j44g2000cwa.googlegroups.com> hi i downloaded paramiko and was trying to create private/pub key pairs from the docs, i use this method to create private key import paramiko k = paramiko.RSAKey.generate(1024) k.write_private_key_file("test_priv") How do i generate the public key for this ? thanks From istvan.albert at gmail.com Thu Dec 7 10:30:08 2006 From: istvan.albert at gmail.com (Istvan Albert) Date: 7 Dec 2006 07:30:08 -0800 Subject: Initializing with the correct type References: <1165496163.392526.322700@f1g2000cwa.googlegroups.com> Message-ID: <1165505407.924693.174480@73g2000cwn.googlegroups.com> aine_canby at yahoo.com wrote: > Hi all, > > I'm new to Python and I'm just wordering if my approch is correct. > Here's an example. I'm making sure that the length and types are > correct. Don't worry much about the type of parameters, it turns out passing wrong data into a constructor is a problem that is both easy to avoid and catch once it happens. Here is also an alternative to your code try: assert len(data) in (1, size), 'incorrect size' assert len(data)==len( [ x for x in data if type(x)==int ] ), 'noninteger data in the list' except Exception, exc: raise FormatError('Data error: %s' % exc) i. From andrew at farwestbilliards.com Tue Dec 19 19:26:20 2006 From: andrew at farwestbilliards.com (Andrew Sackville-West) Date: Tue, 19 Dec 2006 16:26:20 -0800 Subject: MySQLdb, lots of columns and newb-ness Message-ID: <20061220002620.GA9142@localhost.localdomain> Hi list, I've tried, lots of interpreter testing and google grepping to figure this out and I think I'm missing something fundamental. I have an ascii data dump from a POS system that has 131 fields in a single column in a flat file. I can easily open the file, read in the data and assemble it into various formats. okay. what I *want* to do is insert each of these fields into a mysql database that has 132 columns that correspond to the 131 fields in the ascii file (plus one for the date). I can successfully connect to mysql and do stuff to my tables my specific problem is how to efficiently put those 132 fields into the thing. All I have been able to figure out is really ugly stuff like: build the mysql statement out of various pieces with appropriate commas and quote included. stuff like (not tested) for field in f.read(): row+=field[:-2]+", " stmt="insert into daily values "+row")" cursor.execute(stmt) (the slice is to kill a cr/lf on each one) that seems really kludgey to me. I've also tried building tuples and lists and then using this cursor.execute("insert into daily values (%s)", values) with no luck. it appears to me that I have to put in all 132 '%s' in order to make that work and that just seems stupid. I suppose I could build a list of the column names: columns=('Asales', 'Bsales', 'Csales' ...) and bring in the data as a list and then for col in range(len(columns)): cursor.execute("insert into daily (%s) values (%s)", (columns[col], data[col])) but again, that doesn't seem too pythonic. any suggestions are greatly appreciated. A -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From jwickard at gmail.com Thu Dec 28 10:28:49 2006 From: jwickard at gmail.com (jmw) Date: 28 Dec 2006 07:28:49 -0800 Subject: Fuzzy string comparison In-Reply-To: References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> <1167167314.463288.98960@48g2000cwx.googlegroups.com> Message-ID: <1167319729.158222.25820@h40g2000cwb.googlegroups.com> Gabriel Genellina wrote: > At Tuesday 26/12/2006 18:08, John Machin wrote: > > > > I'm looking for a module to do fuzzy comparison of strings. [...] > Other alternatives: trigram, n-gram, Jaro's distance. There are some > Python implem. available. Quick question, you mentioned the data you need to run comparisons on is stored in a database. Is this string comparison a one-time processing kind of thing to clean up the data, or are you going to have to continually do fuzzy string comparison on the data in the database? There are some papers out there on implementing n-gram string comparisons completely in SQL so that you don't have to pull back all the data in your tables in order to do fuzzy comparisons. I can drum up some code I did a while ago and post it (in java). From steve at REMOVE.THIS.cybersource.com.au Thu Dec 7 17:45:14 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Fri, 08 Dec 2006 09:45:14 +1100 Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> <1165500649.129625.213300@j44g2000cwa.googlegroups.com> <1165528352.978586.248960@16g2000cwy.googlegroups.com> Message-ID: On Thu, 07 Dec 2006 13:52:33 -0800, George Sakkis wrote: > I'm surprized that none of these pages mentions the incompatible type > comparison gotcha: > >>>> 5 < "4" > True > > I'm sure this has bitten many folks, particularly (ex) Perl'ers. Why is this a gotcha? I can't speak for others, but except for sorting, I've never been tempted to compare ints to strings like that, but thinking about the code I've written, I can't think of any bad consequences that would have happened if I had. I'm not saying that there are never bad consequences for comparing incompatible types, but I'm questioning that it is a gotcha, let alone a common gotcha. What do others think? Ever been bitten by 5 < "4"? -- Steven. From jonc at icicled.net Tue Dec 19 21:15:44 2006 From: jonc at icicled.net (Jonathan Curran) Date: Tue, 19 Dec 2006 20:15:44 -0600 Subject: regexp In-Reply-To: References: Message-ID: <200612192015.44986.jonc@icicled.net> On Tuesday 19 December 2006 15:32, Paul Arthur wrote: > On 2006-12-19, vertigo wrote: > > Hello > > > >> Take a look at Chapter 8 of 'Dive Into Python.' > >> http://diveintopython.org/toc/index.html > > > > i read whole regexp chapter - > > Did you read Chapter 8? Regexes are 7; 8 is about processing HTML. > Regexes are not well suited to this type of processing. > > > but there was no solution for my problem. > > Example: > > > > re.sub("","",htmldata) > > would remove only comments which are in one line. > > If comment is in many lines like this: > > > > > > it would not work. It's because '.' sign does not matches '\n' sign. > > > > Does anybody knows solution for this particular problem ? > > Yes. Use DOTALL mode. Paul, I mentioned Chapter 8 so that the HTML processing section would be taken a look at. What Vertigo wants can be done with relative ease with SGMLlib. Anyway, if you (Vertigo) want to use regular expressions to do this, you can try and use some regular expression testing programs. I'm not quite sure of the name but there is one that comes with KDE. - Jonathan Curran From __peter__ at web.de Fri Dec 1 05:01:22 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Dec 2006 11:01:22 +0100 Subject: Slicing versus loops, was Re: for i in range() anti-pattern References: <1164812827.653386.323320@80g2000cwy.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Thu, 30 Nov 2006 11:17:17 +0100, Peter Otten wrote: > >> Steven D'Aprano wrote: >> >>> And remember that if alist is truly huge, you may take a performance hit >>> due to duplicating all those megabytes of data when you slice it. >> >> Having the same object in two lists simultaneously does not double the >> total amount of memory; you just need space for an extra pointer. > > Sure. But if you have millions of items in a list, the pointers themselves > take millions of bytes -- otherwise known as megabytes. I don't know the exact layout of an int, but let's assume 4 bytes for the class, the value, the refcount and the initial list entry -- which gives you 16 bytes per entry for what is probably the class with the smallest footprint in the python universe. For the range(N) example the slicing approach then needs an extra 4 bytes or 25 percent. On the other hand, if you are not dealing with unique objects (say range(100) * (N//100)) the amount of memory for the actual objects is negligable and consequently the total amount doubles. You should at least take that difference into account when you choose the swapping algorithm. >> That example was chosen to prove your point. > Well, I thought about choosing an example that disproved my point, but I > couldn't think of one :-) Lack of fantasy :-) >> The real contender for the "swap items" problem are slices. >> >> def swap_slice(items): >> left = items[::2] >> items[::2] = items[1::2] >> items[1::2] = left >> return items > > I always forget that extended slices can be assigned to as well as > assigned from! Nice piece of code... if only it worked. > >>>> def swap_slice(items): > ... left = items[::2] > ... items[::2] = items[1::2] > ... items[1::2] = left > ... return items > ... >>>> alist > [0, 1, 2, 3, 4] >>>> swap_slice(alist) > Traceback (most recent call last): > File "", line 1, in ? > File "", line 3, in swap_slice > ValueError: attempt to assign sequence of size 2 to extended slice of size > 3 > > Everybody always forgets corner cases... like lists with odd number of > items... *wink* True in general, but on that one I'm with Duncan. Here is another implementation that cuts maximum memory down from 100 to 50%. from itertools import islice def swap(items): items[::2], items[1::2] = islice(items, 1, None, 2), items[::2] return items Peter From Roberto.Bonvallet at cern.ch Wed Dec 6 10:12:35 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Wed, 6 Dec 2006 15:12:35 +0000 (UTC) Subject: dict.has_key(x) versus 'x in dict' References: Message-ID: Fredrik Lundh wrote: [...] > this is why e.g. > > string[:len(prefix)] == prefix > > is often a lot faster than > > string.startswith(prefix) This is interesting. In which cases does the former form perform better? [I won't stop using str.startswith anyway :) ] Regards. -- Roberto Bonvallet From jon at ffconsultancy.com Sun Dec 10 05:23:17 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 10:23:17 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> Message-ID: <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> Konrad Hinsen wrote: > The lack of polymorphism, particularly in operators, makes OCaml code > a pain to write and read in my opinion. F# addresses this by adding operator overloading. However, you have to add more type annotations... > Interfacing to C and Fortran code is important because that's what > most libraries are written in. While it is possible in principle with > OCaml, it is (or at least was at the time I looked) a pain to > interface typical array-handling code, for lack of a compatible data > structure on the OCaml side. You want bigarrays, they are just C/Fortran arrays. Look at the bindings to FFTW/LAPACK, for example. > Native code compilation is obviously important for speed. While many > popular processors are supported by ocamlopt, scientific users are > notorious for grabbing whatever fast hardware they can lay their > hands on. It seems safe to count on the GNU suite being ported > rapidly to any new platform. OCaml already supports 9 architectures and optimised to AMD64 earlier than gcc. How many do you want? -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From johnzenger at gmail.com Wed Dec 20 15:25:57 2006 From: johnzenger at gmail.com (johnzenger at gmail.com) Date: 20 Dec 2006 12:25:57 -0800 Subject: perl better than python for users with disabilities? In-Reply-To: <87slfalf8h.fsf@jidanni.org> References: <87slfalf8h.fsf@jidanni.org> Message-ID: <1166646357.752922.258050@73g2000cwn.googlegroups.com> Blind programmers can use braille displays, which let them perceive indentation as easily as sighted programmers can. http://xrl.us/tydj As for people with physical disabilities that have trouble typing, a Python-aware editor does the identation for you, so all you have to do is type a colon and an enter, then a backspace when you are done being indented. But it's an interesting question, and I'd like to hear from blind programmers about how program language design can make their lives easier or more difficult. On Dec 20, 11:11 am, Dan Jacobson wrote: > Can I feel even better about using perl vs. python, as apparently > python's dependence of formatting, indentation, etc. vs. perl's > "(){};" etc. makes writing python programs perhaps very device > dependent. Whereas perl can be written on a tiny tiny screen, and can > withstand all kinds of users with various disabilities, etc.? > Also perl is easier to squeeze into makefiles. From tibetan.houdini at gmail.com Thu Dec 14 09:45:46 2006 From: tibetan.houdini at gmail.com (tibetan.houdini at gmail.com) Date: 14 Dec 2006 06:45:46 -0800 Subject: Non greedy regex Message-ID: <1166107546.537991.165970@t46g2000cwa.googlegroups.com> Can someone please explain why these expressions both produce the same result? Surely this means that non-greedy regex does not work? print re.sub( 'a.*b', '', 'ababc' ) gives: 'c' Understandable. But print re.sub( 'a.*?b', '', 'ababc' ) gives: 'c' NOT, understandable. Surely the answer should be: 'abc' From gagsl-py at yahoo.com.ar Mon Dec 11 19:37:46 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 21:37:46 -0300 Subject: Encapsulating conditional execution based on list membership - how do you do it? In-Reply-To: <1165850602.011794.159370@j44g2000cwa.googlegroups.com> References: <1165850602.011794.159370@j44g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061211211923.03eab320@yahoo.com.ar> At Monday 11/12/2006 12:23, metaperl wrote: >ok, so I'm thinking of adding a method to the storage class so I can do >this: > >self.storage.archive_has(f, print_msg=True) and sys.exit() > >but really there is no need to hardcode which storage directory. So I'm >thinking: > >self.storage.memberof('archive', f, print_msg=Tree) and sys.exit() > > >Is that the best solution you can think of? This is just _my_ opinion, of course. I don't like the construct "blablabla() and sys.exit()" or "blablabla() or sys.exit()", I prefer an explicit check "if not blablabla(): exit()" I'm not sure what you mean by "archive" but instead of a string, make it an object so you can write self.storage.archive.has_file(f). The check should do just *that*, return a boolean without side effects; if you want to print a message, make the caller print it. If you alias .has_file as .__contains__, you could also write: if f in self.storage.archive, which looks even better. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From jonc at icicled.net Mon Dec 18 23:17:14 2006 From: jonc at icicled.net (Jonathan Curran) Date: Mon, 18 Dec 2006 22:17:14 -0600 Subject: Is there any python-twisted tutorial or texts? In-Reply-To: <1166496307.681933.247810@t46g2000cwa.googlegroups.com> References: <1166496307.681933.247810@t46g2000cwa.googlegroups.com> Message-ID: <200612182217.14159.jonc@icicled.net> On Monday 18 December 2006 20:45, Jia Lu wrote: > Hi all > I want to study twisted of python . But I donot know how to start. > Any suggistions? > > Thank you There is a book about using Twisted. It's called 'Twisted Network Programming Essentials.' It is an entry-level book at best, but it does go over quite a lot of things that the Twisted library is capable of. Available at amazon.com: http://www.amazon.com/Twisted-Network-Programming-Essentials-Fettig/dp/0596100329/sr=8-1/qid=1166501681/ref=sr_1_1/102-5086830-3709707?ie=UTF8&s=books - Jonathan Curran From at at tuko.nl Thu Dec 14 13:09:11 2006 From: at at tuko.nl (at) Date: Thu, 14 Dec 2006 19:09:11 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> <1166118715.306793.122570@l12g2000cwl.googlegroups.com> Message-ID: <45819342$0$322$e4fe514c@news.xs4all.nl> I am not claiming that it was THE motivation, but it solves my problem... Carl Banks wrote: > > at wrote: >> By the way, >> >> I think by approving >> >> a = b if condition else c >> >> used to avloind >> >> if condition: >> a = b >> else: >> a = c >> >> which is dealing with same psychological problem, Guido also recognizes >> some need... > > If you think that this change was made for "psychological" reasons, you > are terribly deluded. > > > Carl Banks From daniel.dittmar at sap.com Fri Dec 1 12:21:21 2006 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Fri, 01 Dec 2006 18:21:21 +0100 Subject: Is python memory shared between theads? In-Reply-To: <1164987833.233073.265170@80g2000cwy.googlegroups.com> References: <1164987833.233073.265170@80g2000cwy.googlegroups.com> Message-ID: Wesley Henwood wrote: > So I declare a variable named A in thread1, in script1.py. I assign > the value of 2.5 to A. I then run script2.py in thread2. Script2.py > assigns the value of 5.5 to a variable named A. Now, when thread1 > resums execution, I see that A = 5.5, rather than 2.5 as I expected. > > Is this normal behavior? Not if this is all you are doing. A variable A in script1.py and a variable A in script2.py are completely different, even when running in the same thread. But if you're running script1.py and script2.py by calling execfile or exec and you pass the same dictionary as the globals argument to execfile, then the two scripts would share the global namespace. Variables of the same name would really be the same variable. Daniel From mail at timgolden.me.uk Thu Dec 14 05:54:12 2006 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 14 Dec 2006 10:54:12 +0000 (UTC) Subject: open a directory in widows References: <2387F0EED10A4545A840B231BBAAC722F116D4@slcimail1.slcgov.com> Message-ID: Bell, Kevin slcgov.com> writes: > > If I want "C:\temp" to pop open on screen, how do I do it? import os os.startfile (r"c:\temp") From nick at craig-wood.com Wed Dec 6 05:30:04 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Wed, 06 Dec 2006 04:30:04 -0600 Subject: how to invoke the shell command and then get the result in python References: <1165303175.523129.154400@j72g2000cwa.googlegroups.com> <1165306945.315445.303490@80g2000cwy.googlegroups.com> <1165373054.386217.231750@l12g2000cwl.googlegroups.com> Message-ID: Fredrik Lundh wrote: > petercable at gmail.com wrote: > > > Assuming the script isn't setuid, this would do no more damage than the > > user could do directly on the command line. > > except that when the user is typing things into the command line, he > *knows* that he's typing things into the command line. Aye! Who is to say that this script won't get re-used innocently in a web application? And in this particular example we were talking about typing regular expressions into the shell, which have many of the same metacharacters as the shell. So even an innocent use of the above can cause problems. Just say no to passing user input (from anywhere at all) via the shell! That (along with SQL injection attacks which are very similar in concept) is one of the most common security attacks for scripting languages like Python when used in a web environment. -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gandalf at designaproduct.biz Fri Dec 8 11:27:54 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Fri, 08 Dec 2006 17:27:54 +0100 Subject: IMAP4 SEARCH question In-Reply-To: <45798DA6.7050607@designaproduct.biz> References: <4579882E.7080905@designaproduct.biz> <45798DA6.7050607@designaproduct.biz> Message-ID: <4579928A.8050303@designaproduct.biz> Laszlo Nagy wrote: > Sorry, I found it: > > date = date-text / DQUOTE date-text DQUOTE > date-day = 1*2DIGIT ; Day of month > date-day-fixed = (SP DIGIT) / 2DIGIT ; Fixed-format version of date-day > date-month = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" / > "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec" > date-text = date-day "-" date-month "-" date-year > > > > Is there a standard way to convert a datetime to this special, format or > should I write my own function? If anyone is interested. Keywords: IMAP, RFC3501, date format, search -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: IMAPDate.py URL: From kylotan at gmail.com Mon Dec 25 17:26:40 2006 From: kylotan at gmail.com (Ben Sizer) Date: 25 Dec 2006 14:26:40 -0800 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167019940.036406.23980@79g2000cws.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> <1167018067.659291.276020@79g2000cws.googlegroups.com> <1167019940.036406.23980@79g2000cws.googlegroups.com> Message-ID: <1167085600.819692.8910@48g2000cwx.googlegroups.com> Eric_Dexter at msn.com wrote: > I don't seem to have any problem running python programs regardless of > where they are. My platform is windows xp and I have run both 2.4 and > 2.5 more details about what version of windows you are running might be > helpfull I don't think the Windows version is relevant. I did point out that this happens across different incarnations of Windows (98SE and XP the 2 I have on hand to test), and that the problem wasn't specifically about "running python programs". Basically if you go to a command prompt and type "python", it won't do anything on a plain Python install on Windows. Try it on Linux, and probably Mac too, and it'll do something useful. Similarly, if you install a Python package that adds to the scripts directory, you can typically expect to run those scripts from the command line without having to use the full path - not on Windows. -- Ben Sizer From justin.mailinglists at gmail.com Thu Dec 28 22:15:03 2006 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: 28 Dec 2006 19:15:03 -0800 Subject: Comparing files in a zip to files on drive References: <1167359715.387219.250660@73g2000cwn.googlegroups.com> Message-ID: <1167362103.430509.199480@i12g2000cwa.googlegroups.com> kj7ny wrote: > compare a file on a hard drive to a file in a python created zip file > to tell if the file has changed? >>> fileondisk = r'C:\Documents and Settings\power\Desktop\ES3dc+Template.3f' >>> zipondisk = r'C:\Documents and Settings\power\Desktop\temps.zip' >>> import zipfile >>> z = zipfile.ZipFile(zipondisk) >>> z.namelist() ['ES1+Template.3f', 'ES3sc+Template.3f', 'ES3dc+Template.3f'] >>> info = z.getinfo('ES3dc+Template.3f') >>> info.CRC 1620938006 >>> import binascii >>> checksum = 0 >>> fp = open(fileondisk, 'rb') >>> while 1: ... data = fp.read(32*1024) ... if not data: break ... checksum = binascii.crc32(data, checksum) ... >>> checksum 1620938006 >>> From greg at cosc.canterbury.ac.nz Wed Dec 13 22:35:07 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 14 Dec 2006 16:35:07 +1300 Subject: Conditional iteration In-Reply-To: <4580149c$0$321$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> Message-ID: <4ubv67F17ggcuU1@mid.individual.net> at wrote: > It is not the addional line containing 'if x > 0:' that bothers me, but the > additional indentation. I don't find the additional indentation bothersome. In fact I think it's helpful, because it makes it obvious that there is something else going on besides just a loop. -- Greg From een-niet-bestaande-kleineaap at xs4all.nl Fri Dec 15 14:38:52 2006 From: een-niet-bestaande-kleineaap at xs4all.nl (Kleine Aap) Date: Fri, 15 Dec 2006 20:38:52 +0100 Subject: (newbie) class with a single instance ?! References: Message-ID: <4582fa37$0$6982$847b8a7a@dreader19> Andrea Tomadin wrote: > This works, but isn't it weird to define a class if I know from the > very beginning that there will be no more than an instance of that > class? Singleton http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52558 From sjmachin at lexicon.net Fri Dec 8 00:23:07 2006 From: sjmachin at lexicon.net (John Machin) Date: Fri, 08 Dec 2006 16:23:07 +1100 Subject: Need Help Parsing From File In-Reply-To: <7.0.1.0.0.20061207230730.03e40c38@yahoo.com.ar> References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> <1165517086.976152.216270@16g2000cwy.googlegroups.com> <7.0.1.0.0.20061207230730.03e40c38@yahoo.com.ar> Message-ID: <4578F6BB.4050204@lexicon.net> On 8/12/2006 1:53 PM, Gabriel Genellina wrote: > At Thursday 7/12/2006 15:44, John Machin wrote: > >> > > > ftxt=open(filename,"rt") >> > > >> > >Is this a bug or a feature? Or is it one of those good old >> "unspecified >> > >behaviour" cases? MSVC rtl only? >> > >> > The Python docs say only that the initial letter is checked. And the >> > ANSI 89 C says that other characters may follow after r, r+, etc. >> > "rt" is useless for an ANSI C compiler, since the default stream mode >> > is "text" -on systems which differentiate between text and binary- >> > and irrelevant on systems which don't do such distinction. >> > (And since I got used to write "rt", >> >> Why did you do that? >> (1) Text mode is was and ever shall be the default, even with MS. > > No, there used to be a flag in the stdio library, giving the default > value when neither t or b was specified. > For the Borland C++ 3.1 help (about 1991): > If "t" or "b" is not given in the string, the mode is governed by _fmode. > If _fmode is set to O_BINARY, files are opened in binary mode. > If _fmode is set to O_TEXT, they are opened in text mode. > MSC used to have a similar flag (perhaps using the same name). Indeed, and their docs say that the default for _fmode is text mode. > All of this predates wide usage of ANSI C 89, which made the "t" flag > obsolete. > >> (2) Seeing we're referring to docs and standards: Microsoft C 5.0 >> Optimizing Compiler, Run-Time Library Reference manual says "The t >> option is not part of the ANSI standard for open, but is a Microsoft >> extension and should not be used where ANSI portability is required". > > A "t" after the initial recognized characters should be ignored by any > conforming compiler. I think the idea was to allow for extensions like > fopen(fn, "rt;reclen=128") but except esoteric platforms I doubt anyone > is using that. So it should be ignored. So, back to the question: why did you get into the habit of writing "rt" when it was pointless? From seberino at spawar.navy.mil Tue Dec 12 12:01:11 2006 From: seberino at spawar.navy.mil (seberino at spawar.navy.mil) Date: 12 Dec 2006 09:01:11 -0800 Subject: Can't register to CheeseShop at command line...only on web?!.. In-Reply-To: <457e7000$0$9775$afc38c87@news.optusnet.com.au> References: <1165882269.932773.317580@j44g2000cwa.googlegroups.com> <457e7000$0$9775$afc38c87@news.optusnet.com.au> Message-ID: <1165942871.142337.247700@73g2000cwn.googlegroups.com> > > Here is what happens when I try to register at command line with > > .pypirc above... > > > > Using PyPI login from /home/seb/.pypirc > > Server response (401): Authorization Required > > Do you use a proxy to access the web? Not that I'm aware of unless my job uses one without my knowing about it. If I am..is there a workaround for proxies? cs From paddy3118 at netscape.net Tue Dec 12 20:27:03 2006 From: paddy3118 at netscape.net (Paddy) Date: 12 Dec 2006 17:27:03 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xwt50zf56.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165700999.744643.207110@73g2000cwn.googlegroups.com> <7xvekkps2r.fsf@ruckus.brouhaha.com> <1165713635.140913.164060@l12g2000cwl.googlegroups.com> <7xwt50zf56.fsf@ruckus.brouhaha.com> Message-ID: <1165973223.422167.316250@80g2000cwy.googlegroups.com> Paul Rubin wrote: > "Paddy" writes: > > Python can be used as a glue language. It is not solely a glue > > language. > > A lot of people find using Python to script libraries written in other > > languages > > a way to get things done. Ask the scipy guys or the biopython guys. > > Sure, connecting together programs and libraries that were written in other > languages is what a glue language is. > > > You don't always wrap a module in Python for reasons of speed of > > execution. > > > > Software testing may well be easier to do in Python than in the > > native language of the wrapped library. ... > > That's the thing, those modules are written in languages other than > Python because Python is not attractive for coding those functions > directly in Python. That is a real weakness of Python and glossing > over it by saying to write the functions in other languages and then > wrap them in the C API is not a very impressive answer. For example, > Lisp is routinely used for writing scientific and numerical code > directly with performance comparable to C or whatever. There is no > need to mess with wrapping modules written in other languages, an > operation which should not be trivialized. You failed to see that Python accepts that useful work is out their, already written, and some of it is not written in Python. Would you say that All useful code is only written in Lisp? Or that all future useful code will only be written in Lisp? You could waste a lot of time re-writing what is already available, in Lisp. - Paddy. From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Sat Dec 9 06:49:09 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Sat, 09 Dec 2006 12:49:09 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> Message-ID: <4tvm5mF15g127U1@mid.individual.net> Ken Tilton wrote: > Note also that after any amount of dicing I simply hit a magic key > combo and the editor reindents everything. In a sense, Lisp is the > language that handles indentation best. Erm ... because there's an editor for it that indents automatically? Or did I miss the point? Regards, Bj?rn Xpost cll,clp -- BOFH excuse #235: The new frame relay network hasn't bedded down the software loop transmitter yet. From spam at spam.pl Sun Dec 31 12:25:19 2006 From: spam at spam.pl (vertigo) Date: Sun, 31 Dec 2006 18:25:19 +0100 Subject: trees, iterations and adding leaves Message-ID: Hello I have trees like this: >>> from nltk_lite.parse.tree import Tree >>> tree6 = Tree('main', ['sub1', 'sub2']) >>> tree6 ('main': 'sub1' 'sub2') I use nltk package - but it should not matter here. I could change it's lafes (add node) like this: >>> tree6[0] = Tree('newsub',[]) >>> tree6 ('main': ('newsub': ) 'sub2') But my tree has many levels and it's imposibble to address it like: tree6[0][1][0][1][1][1][0].......... So i wanted to 'travel thru my tree' to last node which should be changed: >>> tree6 = Tree('main', ['sub1', 'sub2']) >>> subtree = tree6[0] >>> subtree 'sub1' >>> subtree = Tree('newsub',[]) >>> subtree ('newsub': ) >>> tree6 ('main': 'sub1' 'sub2') The problem is that subtree is some kind of a new variable (not pointer) so changing it i will not alter tree6. How to alter tree6 while 'travelling along it's nodes', without messy referencing as tree6[0][1][0][1][1][1][0].......... ? Thanx From S.Mientki-nospam at mailbox.kun.nl Thu Dec 28 10:14:51 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Thu, 28 Dec 2006 16:14:51 +0100 Subject: How to return a simple variable from a function (still newbie) ? Message-ID: I want to return a "simple" variable from a function, not using the function result. Is that in any way possible ?? The code below is from O'Reilly, "Learning Python", and there seems no way to return a simple var like "z" in the example below. Is that true ? thanks, Stef Mientki def some_function (z, y): z = 2 y[2] = 'global ?' x = 5 y = [1,2,3,4] print x,y some_function(x,y) print x,y From aine_canby at yahoo.com Mon Dec 11 03:26:11 2006 From: aine_canby at yahoo.com (aine_canby at yahoo.com) Date: 11 Dec 2006 00:26:11 -0800 Subject: sys.stdin.encoding Message-ID: <1165825571.435369.150110@79g2000cws.googlegroups.com> The following line in my code is failing because sys.stdin.encoding is Null. This has only started happening since I started working with Pydef in Eclipse SDK. Any ideas? uni=unicode(word,sys.stdin.encoding) Thanks, Aine. From mail at microcorp.co.za Mon Dec 4 00:43:52 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 4 Dec 2006 07:43:52 +0200 Subject: problem formatting dates from text fields. References: <6eHch.7012$1s6.5812@newsread2.news.pas.earthlink.net> <1165181725.414417.266170@79g2000cws.googlegroups.com> Message-ID: <014601c71767$4cda6540$03000080@hendrik> "John Machin" wrote: > Dennis Lee Bieber wrote: 8<-------------------------------------------------- > > Simplest is probably to do what many web-sites use for credit card > > expiration dates... Ignore any pre-built date-time modules... > > > > Create three integer fields, make the first two drop-down lists > > pre-populated with days and months. And validate the results later (just > > to cover someone putting in 31 02 xxxx). > > > > My 2 cents worth: > > (1) this annoys the bejaysus out of data inputters who can type > "31\t12" a lot faster than they can pick it out of two drop-down lists. > > (2) this would annoy the bejaysus out of data users if they were aware > of the extent of off-by-one errors caused by using drop-down lists. > > Cheers, > John This annoyance can be maximised if, after the selection, a pop up dialog window is displayed showing what was chosen, along with the following text: "This is what you have chosen - Please indicate whether or not you wish to re try" - with the focus on the "yes" button. and then, when "yes" is chosen, to start again without any attempt to remember the previously entered values - Hendrik From sjmachin at lexicon.net Sun Dec 17 11:41:48 2006 From: sjmachin at lexicon.net (John Machin) Date: 17 Dec 2006 08:41:48 -0800 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: Message-ID: <1166373708.115088.113880@l12g2000cwl.googlegroups.com> dyork wrote: > "Carsten Haese" wrote in message > news:mailman.1699.1166304628.32031.python-list at python.org... > > This may come as a shock to you, but MySQL is not the only database > > engine on the planet. Your recommendation may apply to MySQL, but it is > > not true for all databases in general. I can name at least two examples > > (Informix and Oracle) of database engines that are supported under > > Python 2.5, and if I were less lazy I could probably find more. > > Of course, no question about it. > > However, the database is currently in MySQL and it's convenient to keep > working with it, given the other apps and other tools I'm using. > > This would be the first time I've been told: don't use that database, the > language doesn't like it. > Simple fact: mySQLdb is not yet available for Python 2.5. Nobody has said (or even hinted) that "the language doesn't like it." From salvatore.difazio at gmail.com Fri Dec 1 13:53:41 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 1 Dec 2006 10:53:41 -0800 Subject: Thread help Message-ID: <1164999221.679348.221000@16g2000cwy.googlegroups.com> Hi guys, I would make 3 threads for a client application. Tnx From 3dbernard at gmail.com Mon Dec 11 17:12:51 2006 From: 3dbernard at gmail.com (Bernard Lebel) Date: Mon, 11 Dec 2006 17:12:51 -0500 Subject: Restricting import file lookup for pyd, dll, ... In-Reply-To: <61d0e2b40612111411n5f9faackf8f52fa348c731cb@mail.gmail.com> References: <61d0e2b40610191438w9ba0693y8896bebc3441069a@mail.gmail.com> <7.0.1.0.0.20061019184812.05aafe78@yahoo.com.ar> <61d0e2b40612111411n5f9faackf8f52fa348c731cb@mail.gmail.com> Message-ID: <61d0e2b40612111412kd6a0fdar2a86f363e95c5f92@mail.gmail.com> Oops, sorry for the inconsistency. The pth file rather looks like this: d:\bernard\work\workgroups\workgroup_animation\data\scripts d:\bernard\work\workgroups\mt_workgroup\data\scripts d:\bernard\work\workgroups\ts_workgroup\data\scripts \\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE c:\users\blebel\Softimage\XSI_5.11\Data\Scripts Bernard On 12/11/06, Bernard Lebel <3dbernard at gmail.com> wrote: > Hello, > > It's been almost two months since I last investigated this issue, so > now I wish to revive this conversation. > > To answer some of the questions raised by contributors.... > > > [Gabriel Genellina] Try to shorten the PYTHONPATH to the really > required directories > (deleting those locations "that don't make sense"). > > [Bernard] I customized the PYTHONPATH using a pth file. The pth file > contains this: > \\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\Data\Scripts > \\Linuxserver\ANIMATION\DB\MT\MT_WORKGROUP\Data\Scripts > \\Linuxserver\ANIMATION\DB\TS\TS_WORKGROUP\Data\Scripts > \\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE > > That's it. I could hardly shorten these paths, unless the ressources > exposed through these paths were copied locally on every computer. Atm > I do not have management tools at my disposal to handle such a setup. > > When print the paths: > > C:\WINDOWS\system32\python24.zip > C:\Documents and Settings\blebel > C:\Python24\DLLs > C:\Python24\lib > C:\Python24\lib\plat-win > C:\Python24\lib\lib-tk > C:\Python24 > d:\bernard\work\workgroups\workgroup_animation\data\scripts > d:\bernard\work\workgroups\mt_workgroup\data\scripts > d:\bernard\work\workgroups\ts_workgroup\data\scripts > \\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE > c:\users\blebel\Softimage\XSI_5.11\Data\Scripts > C:\Python24\lib\site-packages > C:\Python24\lib\site-packages\win32 > C:\Python24\lib\site-packages\win32\lib > C:\Python24\lib\site-packages\Pythonwin > > If by "shortening the PYTHONPATH" you meant having less paths, I > hardly see how I could do less than what I do with the pth. All these > paths seem to be built in. > > Now what would be REALLY nice is to have the ability to specify in the > paths the location of *specific files*. Is this possible? What happens > is that Python is visiting all kinds of locations to find some files, > like os, ntpath, and many more. If I could tell Python right away > where are these files located, I hope I could gain something. > > > > > [Fredrik Lundh] a plain Python 2.4 interpreter can start, execute a > command, and shut > down in about 0.13 seconds on my machine. 2.5 does the same thing in > 0.10 seconds. > > [Bernard] The problem is not firing up the standalone Python > interpreter. The problem is firing the application that embeds a > Python interpreter. > > As explained above, when I start this application, many files are > looked in many different places. All PYTHONPATH locations are > traversed, where pyd-dll-py-pyw-pyc files are searched. Many of these > files are searched in highly improbable locations. > > > > > [Fredrik Lundh] are you sure you're benchmarking *Python's* start up > time, and not the > time it takes to load all the modules used by your application, or the > time it takes for "filemon" to print all those 4500 requests to the > monitor window? > > [Bernard] The Filemon overhead consistently clocks at 1 second, not > matter the test I perform. Since I ran all tests with Filemon running, > I feel safe to ignore this constant. > > Now, as to the first sentence, to be fair, no, I'm not exactly sure. I > don't know all the details of the Python's embedding in this software, > and this knowledge is out of my reach atm. > > Here is the relevant Filemon log: > http://www.bernardlebel.com/img_remote/3D/XSI/python/Filemon_XSIPython.LOG > (710k file) > > > > [Magnus Lycka] Sounds like a broken (networked?) file system. The only time I've > had that kind of problems with python startup is when I've had really > slow anti-virus programs that scanned all the files I opened. But then > it wasn't file requests that mattered, but actually opening them... > It still wasn't anywhere near 9 seconds though... > > [Bernard] This is not entirely impossible, but I get similar results > on every computer I perform this test. By "every computer", I mean > different locations, with different hardwares and different network > setups. Even when the files are all local on the computer I get this. > > > > Thanks > Bernard > > > > On 10/28/06, Fredrik Lundh wrote: > > Magnus Lycka wrote: > > > > >> That's because I'm using Python through another application, via the > > >> pywin32 extensions. When that other application starts, it performs > > >> several thousands of file requests (we're talking 4,500, roughly) in > > >> the Python installation, locations where there are Python files, and > > >> in some other locations that don't make sense. This adds considerable > > >> time to the startup time of the application, we're talking between 2 > > >> and 9 seconds. > > > > > > Sounds like a broken (networked?) file system. The only time I've > > > had that kind of problems with python startup is when I've had really > > > slow anti-virus programs that scanned all the files I opened. But then > > > it wasn't file requests that mattered, but actually opening them... > > > It still wasn't anywhere near 9 seconds though... > > > > if anyone finds out more about this issue, feel free to add a note to > > this FAQ entry: > > > > http://www.effbot.org/pyfaq/why-does-python-sometimes-take-so-long-to-start.htm > > > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > From amichail at gmail.com Sat Dec 2 17:08:32 2006 From: amichail at gmail.com (Amir Michail) Date: 2 Dec 2006 14:08:32 -0800 Subject: python vs java & eclipse References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> Message-ID: <1165097312.717026.122820@j72g2000cwa.googlegroups.com> Hi, Here's a blog post that is relevant to this discussion: http://sixthandredriver.typepad.com/river_of_code/2006/01/automated_refac.html Amir From marika5000 at gmail.com Sun Dec 24 12:33:12 2006 From: marika5000 at gmail.com (marika) Date: 24 Dec 2006 09:33:12 -0800 Subject: consequence and life In-Reply-To: <1166953680.366942.96730@48g2000cwx.googlegroups.com> References: <1166953680.366942.96730@48g2000cwx.googlegroups.com> Message-ID: <1166981592.102912.177970@42g2000cwt.googlegroups.com> Lester Mosley wrote: > I alway wondered if you are smelling a flower in a dream while on some > crazy herbal medication. are you smelling the flower that is in the > drug or a a flower that you once smelled when you were three years old > on your daddy's knee ofr when you were bent over in the park looking > for your lost keys. > > that can easily be answered by viewing the movie Brainstorm. Christopher Foof Walken was on TV today,as a matter of fact. mk5000 "If he is, he's in the vast minority."--george w From evanmason at gmail.com Sun Dec 17 13:25:31 2006 From: evanmason at gmail.com (Evan) Date: 17 Dec 2006 10:25:31 -0800 Subject: first and last index as in matlab Message-ID: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> In matlab I can do the following: >> ind = [3,5,7,2,4,7,8,24] ind = 3 5 7 2 4 7 8 24 >> ind(1) ans = 3 >> ind(end) ans = 24 >> ind([1 end]) ans = 3 24 but I can't get the last line in python: In [690]: ind = [3,5,7,2,4,7,8,24] In [691]: ind[0] Out[691]: 3 In [692]: ind[-1:] Out[692]: [24] In [693]: ?? How do I pull out multiple indices as in matlab? Thanks, Evan From nick at craig-wood.com Thu Dec 7 05:30:04 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Thu, 07 Dec 2006 04:30:04 -0600 Subject: Use of factory pattern in Python? References: <676224240612070028y7be5e8b5h8f860bc505da53c0@mail.gmail.com> Message-ID: Gabriel Genellina wrote: > The basic idea is the same, but instead of a long series of > if...elif...else you can use a central registry (a dictionary will > do) and dispatch on the name. Classes act as their own factories. > > registry = {} > > class Base(object): > kind = "Unknown" > register(Base) > > class Gene(Base): > kind = "gene" > def __init__(self, *args, **kw): pass > register(Gene) > > class Intron(Base): > kind = "intron" > def __init__(self, *args, **kw): pass > register(Intron) > > def register(cls): > registry[cls.kind] = cls > > def factory(kind, *args, **kw): > return registry[kind](*args, **kw) > > If some arguments are always present, you can name them, you're not > limited to use the generic *args and **kw. If you don't want to use a register() function on each class you could introspect like this (untested) to make the registry :- registry = {} for obj in sys.modules[__name__].__dict__.values(): try: if issubclass(obj, Base): registry[kind] = obj except TypeError: pass There might be a neater way of writing the above! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From steven.bethard at gmail.com Wed Dec 27 00:20:58 2006 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 26 Dec 2006 22:20:58 -0700 Subject: module with a threading-like api that uses processes? In-Reply-To: References: Message-ID: <_oGdneJGV_5cnw_YnZ2dnUVZ_ragnZ2d@comcast.com> skip at pobox.com wrote: > I could have sworn someone was working on a module recently with a > threading-like API that used subprocesses under the covers, but 10 minutes > or so of googling didn't yield anything. Pointers appreciated. http://www.python.org/dev/summary/2006-10-01_2006-10-15/#processes-and-threading-module-api STeVe From fredrik at pythonware.com Mon Dec 18 03:02:46 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 18 Dec 2006 09:02:46 +0100 Subject: dealing with special characters in Python and MySQL In-Reply-To: <1166423702.885345.30460@80g2000cwy.googlegroups.com> References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> <8rqhh.956$X72.39@newsread3.news.pas.earthlink.net> <1166423702.885345.30460@80g2000cwy.googlegroups.com> Message-ID: ronrsr wrote: > querystring = "update zingers set keywords = '%s', citation = > '%s', quotation = %s' where zid = %d" % > (keywords,citation,quotation,zid) that's not a good way to pass strings to the database. for the right way to do this, see: http://effbot.org/pyfaq/how-do-i-escape-sql-values-when-using-the-db-api From aidan at aidans.org Wed Dec 13 19:16:38 2006 From: aidan at aidans.org (Aidan Steele) Date: Thu, 14 Dec 2006 11:16:38 +1100 Subject: speed of python vs matlab. In-Reply-To: <1166054840.646029.265880@73g2000cwn.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> Message-ID: <364538570612131616p5f44812bjc2089c105226521f@mail.gmail.com> On 13 Dec 2006 16:07:20 -0800, Chao wrote: > > I've been trying to develop some numerical codes with python, however > got disappointed. > > A very simple test, > > a = 1.0 > > for i in range(1000): > for j in range(1000): > a = a+1 > > unfortunately, it took 4.5 seconds to finish(my machines is fine. P4 > 3.0G, 1G RAM, it varies according to machine configuration, but should > be in the same level) > > for matlab, the same operation took 0.1 seconds, > > I use numpy & scipy, they solve the problem most of the times, but > there are cases you can't avoid loops by vectors. I appreciate the > elegancy of python so much, but I guess I have to gave it up in these > numerical codes.(image processing algorithms), for application > dev/scripting, it's still my first choice. > > A good news is that the same code takes ruby 9.8 seconds. > > -- > http://mail.python.org/mailman/listinfo/python-list Have you considered looking into Psyco? (http://psyco.sourceforge.net/) For all the numeric operations that image processing algorithms entail, such a tool will probably make a tremendous difference in terms of speed of execution for you. Do yourself a favour and check it out. Hope this helps, Aidan Steele. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Holger.Joukl at LBBW.de Wed Dec 13 05:48:05 2006 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Wed, 13 Dec 2006 11:48:05 +0100 Subject: call of __del__ non-deterministic in python 2.4 (cpython)? In-Reply-To: Message-ID: python-list-bounces+holger.joukl=lbbw.de at python.org schrieb am 13.12.2006 11:09:13: > Holger Joukl wrote: > > > Anyway: Is relying on __del__ getting called immediately when the refcount > > drops to 0 a no-no? > > yes, but more importantly, relying on the refcount dropping to 0 when > something goes out of scope is a major no-no. In my particular use case I think can rule out the problematic situations, except for the object being referenced in the stack trace, but that won't put me into problems (and there were no exceptions at all when I ran into the deadlocks) > > If so should that maybe be prominently stated in the docs? > > is it perhaps the color that made you miss the big bold boxes in the > documentation? > > http://docs.python.org/ref/customization.html#l2h-177 > > I did read this but didn't think it applied to my situation. I'm quite sure that the refcount of the local variable is 1 before the local scope is left. So let me rephrase the question: Even if I can make sure that non of the problematic situtions apply, might it _still_ happen that __del__ gets called after some other code has already been "entered"? Thanks, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From __peter__ at web.de Mon Dec 4 05:22:36 2006 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Dec 2006 11:22:36 +0100 Subject: Multiple FTP download using Muliti thread References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> <1165226921.418634.169700@80g2000cwy.googlegroups.com> Message-ID: Justin Ezequiel wrote: > Fredrik Lundh wrote: >> Justin Ezequiel wrote: >> >> > from TaskQueue import TaskQueue >> >> what Python version is this ? >> >> > > oops. forgot to note... > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475160 Also noteworthy: "This recipe was accepted for inclusion in Py2.5.", i. e. in Python 2.5 you can use Queue instead of TaskQueue. Peter From lone_wolf at ureach.com Tue Dec 5 21:13:56 2006 From: lone_wolf at ureach.com (Lone Wolf) Date: Tue, 5 Dec 2006 21:13:56 -0500 Subject: Parsing data from pyserial (final resolution) Message-ID: <200612060213.VAA00404@www22.ureach.com> After going back and reading everybody's suggestions, I finally got a simple, efficient solution. As was pointed out to me in several posts, I needed to use readline rather than read. That's obvious to me now ... but isn't everything obvious once you understand it :) Anyway, I am posting my code on the (slim) chance that someone new to python and interested in robotics might find it useful: ######################################################### # This program reads a serial port hookup up to a CMUcam1. # It tracks the middle of a green object and provides a confidence estimate import serial ser=serial.Serial('com1',baudrate=115200, bytesize=8, parity='N', stopbits=1,xonxoff=0, timeout=1) ser.write("TC 016 240 100 240 016 240\r\n") #This line orders the CMUcam to track green for i in range(0,100,1): reading = ser.readline(eol="\r") components = reading.split() mx = int(components[1]) my = int(components[2]) confidence = int(components[8]) print mx, my, confidence ser.close ######################################################## This code will read 5-6 frames per second, which should be plenty for most vision processing applications. Once again, I really want to thank those who took the time to help me. The good news is that I learned something from all my mistakes. Happy Hunting Wolf ________________________________________________ Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag From i80and at gmail.com Fri Dec 15 10:04:45 2006 From: i80and at gmail.com (i80and) Date: 15 Dec 2006 07:04:45 -0800 Subject: cxfrozen linux binaries run on FreeBSD? In-Reply-To: References: Message-ID: <1166195085.128464.294050@t46g2000cwa.googlegroups.com> I haven't personally used freeze (Kubuntu doesn't seem to install it with the python debs), but based on what I know of it, it makes make files. I'm not a make expert, but if FreeBSD has GNU tools, freeze's output _should_ be able to be compiled on FreeBSD. On Dec 15, 5:52 am, robert wrote: > When i freeze a python app (simple - no strange sys calls) for x86 Linux, does this stuff run well also on x86 FreeBSD? > > Robert From http Thu Dec 14 04:03:03 2006 From: http (Paul Rubin) Date: 14 Dec 2006 01:03:03 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7xpsankoc6.fsf@ruckus.brouhaha.com> <7xpsangcs8.fsf@ruckus.brouhaha.com> <7N7gh.574$n34.527@newsfe09.lga> Message-ID: <7xr6v2alyw.fsf@ruckus.brouhaha.com> Ken Tilton writes: > Again, that is precisely the point of macrology (in cases like > this). When a pattern will repeat a sufficient number of times, and a > function cannot handle the job, But this is not a case where a function can't handle the job. > Check out the latest, plz. The example has grown now beyond what a > function can do, I think. meanwhile, I have not seen how Python lets > you avoid revisiting dozens of instances when changes to a mechanism > are required. I'm missing what the difficulty is. From kentilton at gmail.com Thu Dec 14 03:01:46 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 03:01:46 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7x4przt22g.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Ken Tilton writes: > >>>>Man that whole thing is messy. >> >>I do not see much difference, except that the character count is 25% >>less in the macro version: > > > The macro calls aren't so bad, but the macro definition is pretty > horrendous. (a) /Precisely/ :) (b) Omigod, that macro is trivial (except I forgot how to reach out two levels of backquote to get a parameter and had to kludge it!). You just aren't used to thinking at a level where one is writing code to write code. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From webmaster at cacradicalgrace.org Mon Dec 18 18:50:42 2006 From: webmaster at cacradicalgrace.org (J. Clifford Dyer) Date: Mon, 18 Dec 2006 16:50:42 -0700 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4583ED06.5000104@mbi.ucla.edu> Message-ID: James Stroud wrote: > Christoph Zwerschke wrote: >> "Inhomogenous" in some meaning of the word --> tuple > > I think that you have nailed it here. I don't think anyone on this list > is capable of giving a "concrete" (as you have put it) operational > definition of "inhomogenous". They will resort to use cases and thus > cloud the definition with programming philosophy. > How about: "A heterogenous sequence is one in which each element plays a unique role, specific to its position in the sequence. A homogenous sequence is one in which position is determinative of nothing significant other than (perhaps) order." I'm not exactly sure what you mean by "programming philosophy." I suspect it does enter into the choice of which to use, (as programming philosophy determines whether a database will have a "name" field, or "lastname", "firstname", and "middlename" fields) but I don't see that this clouds the definitions, necessarily. > So, programming philosophy, whether it will be admitted or not, is fully > responsible for the exclusion of index() from the tuple interface. > No. Because as pointed out in another subthread, the exclusion of index() from the tuple interface is in many ways orthogonal to the issue of homogeneity/heterogeneity. It's partly that, and partly that The Maintainers have decreed that the workarounds (list(mytuple).index()) are trivial enough to obviate the need for making all the changes to the source code, and hacking something ugly (a linear search has been suggested) into all unsuspecting hand-rolled subscriptable objects. > But perhaps we could take "not necessarily homogenous" to be the > operational definition of "inhomogenous". Of course then we would have > to define necessary... > > James I doubt the python interpreter will ever try to enforce homogeneity/heterogeneity on lists/tuples, in part because there no good ways of definining it syntactically, and in part because there are certainly good reasons for breaking the rules. As someone said: passing lists to untrustworthy functions. And as someone else said, *args passes a tuple, even though it is frequently just a homogenous list of more arguments. Forgive me for referencing throughout the threads without proper citation. I've been ill all weekend, and I just don't feel like doing it right. Cheers, Cliff From Bulkan at gmail.com Mon Dec 11 23:16:31 2006 From: Bulkan at gmail.com (placid) Date: 11 Dec 2006 20:16:31 -0800 Subject: Password, trust and user notification Message-ID: <1165896991.676350.118670@16g2000cwy.googlegroups.com> Hi all, I was going to write this script for a friend that notifies him via logging onto his Gmail account and sending him an email to his work email about some events occurring in the execution of the script. If you enter your password into a script as input how can someone trust the programmer that he will not send a email to himself containing his password? Assuming this person does not know anything about programming and this person knows nothing about programming ethics. This is coming from the fact that i need to notify the user in someway that does not require her to constantly watch the execution of the script, for example when a user signs in to Windows Live Messenger pop up. Cheers 1. http://libgmail.sourceforge.net/ This is the library i use to access a Gmail account via Python From nick at craig-wood.com Sat Dec 23 01:32:46 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 23 Dec 2006 00:32:46 -0600 Subject: Generating all permutations from a regexp References: Message-ID: Fredrik Lundh wrote: > Nick Craig-Wood wrote: > > > A regular expression matcher uses a state machine to match strings. > > unless it's the kind of regular expression matcher that doesn't use a > state machine, like the one in Python. Ah! Well that is outside of my experience then... I've only really studied the matchers produced by flex before. Apologies for the mis-information! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From mystilleef at gmail.com Sun Dec 10 10:29:31 2006 From: mystilleef at gmail.com (mystilleef) Date: 10 Dec 2006 07:29:31 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165764570.956203.223370@16g2000cwy.googlegroups.com> Ken Tilton wrote: > > Lisp has all the cool qualities you like in your pets, plus native > compilation in most implementations, plus maturity and a standard, plus > a better OO, plus macros, plus a dozen more small wins. Including > automatic indentation. :) > Better OO? You mean the one that doesn't support basic encapsulation and is retardedly cumbersome to use? There's a reason I said, I'd never use Lisp for OO not even when I'm high. Gimme Python, Eiffel or Smalltalk anyday, not the retarded add-on package bolted on CL. > It is just a matter of critical mass. At some very low threshold Lisp > becomes "OK". I get the feeling that has already begun, but it is not > quite there yet. Certainly it gets mentioned now when language names get > bandied about, if only to be dismissed. That is a step up for us. :) > Bahahahaha! You lispers and your fairy little macros world. From int2k at gmx.net Sun Dec 10 03:03:11 2006 From: int2k at gmx.net (Wolfram Fenske) Date: 10 Dec 2006 00:03:11 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <1165737791.744375.190080@l12g2000cwl.googlegroups.com> Steven D'Aprano writes: > On Sat, 09 Dec 2006 14:57:08 -0500, Bill Atkins wrote: > >> Paul Rubin writes: >> >>> There is just not that much boilerplate in Python code, so there's >>> not so much need to hide it. >> >> Well, of course there is. There are always going to be patterns in >> the code you write that could be collapsed. Language has nothing to >> do with it; Lisp without macros would still be susceptible to >> boilerplate. >> >> Here's a concrete example: >> >> (let ((control-code (read-next-control-code connection))) >> (ecase control-code >> (+break+ >> (kill-connection connection) >> (throw :broken-by-client)) >> (+status+ >> (send-status-summary connection)) >> ((+noop+ +keep-alive+)))) >> ;; +X+ indicates a constant > > Eight lines, excluding the comment, and it doesn't handle the case where > control-code is not one of +break+, +status+, +noop+ or +keep-alive+, > although the ecase macro does. And how many lines of code is ecase? Doesn't matter because it only has to be written once. For Common Lisp it's already part of the language. It would of course be bad to write a macro if pattern comes up only a few times. But that's not how macros are used. >> All of that boilerplate is handled by the macro. In Python, I >> would need to do something like: >> >> control_code = connection.read_next_control_code() >> if control_code == +break+: >> connection.kill() >> throw blah >> else if control_code == +status+: >> connection.send_status_summary() >> else if control_code == +noop+ || control_code == +keep_alive+: >> else: >> error "CONTROL_CODE fell through conditional cascade; was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+" [...] > Saving one line of code, at the expense of having another block of code to > write or understand -- is that really the best example of what macros are > used for in practice? You don't really save writing any boilerplate code, > except for else clause, unless you're claiming that "if" and "elif" is > boilerplate. No, all the "if control_code == SOME_STATUS:" are boilerplate: --8<---------------cut here---------------start------------->8--- if control_code == STATUS1: action_1 else if control_code == STATUS2: action_2 ... else if control_code == STATUSN: action_n else: Exception(...) --8<---------------cut here---------------end--------------->8--- The pattern is that one value is compared against several possible values and depending on which one matches, the appropriate action is taken. Common Lisp's CASE and ECASE macros and the "switch" statements of C or Java make this pattern explicit and arguably easier to recognize. In Python you have to type it out yourself. [...] > Okay, I'm impressed that ecase can pick up on the four constants being > tested against, and feed their names (rather than merely their values) > into an error message. Python has nothing like that, and if you only have > three or four things to test against, *and* they have names, that could be > a useful thing to do. And if I've understood correctly, that's more a > feature of Lisp's symbols than of macros. > > But if you're testing against fifty different values, well, is it really > useful for your error message to list all fifty names? Or do you have > another macro ecase-with-lots-of-tests? Now you're being silly. [...] > If that's the best example of what macros can be used for, frankly I'm > unimpressed. Yes, I can see some benefit. But I don't see that the benefit > is worth the added complexity. Maybe there are more complex tasks that > macros are better suited for. Here's another example. I had to use a database in one of my Python programs. Everytime I used the database I had write something like this: --8<---------------cut here---------------start------------->8--- self.lock.acquire() try: connection = sqlite.connect(self.dbFile) connection.row_factory = dictFactory try: # do something with the connection finally: connection.close() finally: self.lock.release() --8<---------------cut here---------------end--------------->8--- In Lisp, I could just write a macro "WITH-CONNECTION" that takes the name of the connection variable and the code for "do something with the connection" as arguments. Actually, I ended up writing something like it as a function in Python: --8<---------------cut here---------------start------------->8--- def withConnection(self, fun): self.lock.acquire() try: connection = sqlite.connect(self.dbFile) connection.row_factory = dictFactory try: return fun(connection) finally: connection.close() finally: self.lock.release() --8<---------------cut here---------------end--------------->8--- What would have been the body in the Lisp macro has to be supplied as function. It's basically a macro, but it still requires more typing because you have to define a local function eveytime it is used. Also, there are things you can do with Lisp macros where this mechanism isn't applicable. -- Wolfram Fenske A: Yes. >Q: Are you sure? >>A: Because it reverses the logical flow of conversation. >>>Q: Why is top posting frowned upon? From jjl at pobox.com Thu Dec 21 19:26:18 2006 From: jjl at pobox.com (John J. Lee) Date: Fri, 22 Dec 2006 00:26:18 GMT Subject: python-hosting.com projects: dead? References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> <1166542383.019580.185960@73g2000cwn.googlegroups.com> Message-ID: <87lkl0hj3o.fsf@pobox.com> "jpellerin+nose at gmail.com" writes: [...] > As of this morning my project is back online, so my thanks to python > hosting/webfaction for that. I'm very grateful to them for the great > free service they have provided. I'm sorry that they are getting killed > with spam, but I'm also sorry that they chose to handle the problem in > the way that they did. I had no way of knowing when I'd have access to > my svn repository and tickets again. I'm sure you can understand why I > was dismayed by this and why, unfortunately, I'll never be comfortable > trusting my data to them again. As a user of webfaction's commercial web hosting services, I'm glad that they took the responsible action they did to stop spammers affecting those services. Frankly, as a user of a free service, I don't think you have the right to demand an instant response -- though it seems they provided just that to some such users. What you wrote above is a fairly drastic over-reaction. If you need more reliable service, then pay for hosting. Worse, your words would not be much different if they had been calculated to punish the very people trying to help you (I don't say for a moment that was your intent of course!). Like all of us who post messages on the internet , I'm sure you'll now go and think about it for a day before hitting 'reply' again. John From roman.yakovenko at gmail.com Thu Dec 21 12:55:51 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 21 Dec 2006 19:55:51 +0200 Subject: boost::python and automatic conversion for const std::string& In-Reply-To: <1166715041.198271.292170@f1g2000cwa.googlegroups.com> References: <1166715041.198271.292170@f1g2000cwa.googlegroups.com> Message-ID: <7465b6170612210955x7d837311pffe810d06525d859@mail.gmail.com> On 21 Dec 2006 07:30:41 -0800, gabriel.becedillas at gmail.com wrote: > I have a lot of functions returning "const std::string&". Every time I > wrap one of those I have to do it like this: > > class_.def("name", &someclass::bla, > boost::python::return_value_policy() > ); > > Is there a way to register a return value conversion for "const > std::string&" so I can omit it every time I have to wrap functions > returning "const std::string&" ? I wan't those strings to be copied to > python as new strings (I don't want to hold a pointer to them). I am not sure, you'd better ask this question o Boost.Python mailing list: http://mail.python.org/mailman/listinfo/c++-sig/ Py++, Boost.Python code generator, does it for you: http://tinyurl.com/ygwdkz -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pavlovevidence at gmail.com Tue Dec 26 19:24:14 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 26 Dec 2006 16:24:14 -0800 Subject: How to depress the output of an external module ? In-Reply-To: References: <459117EE.6070205@gmail.com> Message-ID: <1167179054.176478.254090@42g2000cwt.googlegroups.com> fdu.xiaojf at gmail.com wrote: > After some trials I found that put "os.close(1)" before calling the > function will depress the output. In fact, "os.close(1)" closed > standard output, but I don't know how to open it again after the function's > execution. Try this: fd = os.dup(1) os.close(1) sys.stdout = os.fdopen(fd) It's poor design and extremely inconsiderate for a library to print to stdout except as an overridable default. (Not to mention it gives ammo to people who want dynamically scoped globals.) A long term solution might be to haggle the author to stop being such a jerk. Carl Banks From http Sun Dec 10 03:01:34 2006 From: http (Paul Rubin) Date: 10 Dec 2006 00:01:34 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> Message-ID: <7xhcw4gowx.fsf@ruckus.brouhaha.com> "Wolfram Fenske" writes: > > If Common Lisp didn't have lexically scoped variables (most Lisp > > dialects before Scheme didn't have them) then it would be very > > difficult to add that with macros. > > Alex Mizrahi already took care of that one. I'm not persuaded, I haven't examined his example carefully yet but it looks like basically a reader hack. Lexical scope in Lisp means among other things lexical closures and (maybe I'm mistaken) it seemed to me Alex's example didn't supply that. I'm also unconvinced (so far) of his description of call/cc as a Lisp macro but that's going to take me some head scratching. > > I just don't see a non-messy way to simulate Python generators in CL. > > They can be done in Scheme using call/cc though. > > Scheme is also a Lisp. So? No I don't buy that, you can't say Scheme is Lisp when it suits you to do so and that it isn't Lisp at other times. I'd say you can map most of Python's semantics onto Scheme reasonably straightforwardly, but mapping them to CL is considerably harder, macros or no macros. > > http://www.math.chalmers.se/~rjmh/Papers/whyfp.html > > > > The examples in it are pretty easy to do in Python or Scheme, but I > > think not so easy in CL. > > Anything in particular? I'd be surprised if the solutions in Scheme > and CL would differ very much I took it back, I think you can do it in CL with closures (call/cc not needed) similar to how it's done in SICP. You could do something similar in Python but the natural way is with generators. From notontheweb at noisp.com Sat Dec 16 20:08:04 2006 From: notontheweb at noisp.com (Jive Dadson) Date: Sun, 17 Dec 2006 01:08:04 GMT Subject: wxPython help please In-Reply-To: <1166317186.248833.266220@79g2000cws.googlegroups.com> References: <1166317186.248833.266220@79g2000cws.googlegroups.com> Message-ID: Sandra-24 wrote: > Try the wxPython mailing list, which you can find on their site. And > the best wxPython reference is the book (also available as an e-book) > by Robin Dunn, who created wxPython. Seeing wxPython from his > perspective is well worth the money. If I recall correctly he devoted > an entire chapter to drawing with a canvas widget. > > -Sandra > Thanks. I'll give it a look see. You understand that what I want to do is get the pixel that's under the cursor when I click, right? I don't really need to draw things, only load an image from a file. But since this program already did so much of what I wanted, I decided to try it. It is frustrating that after a couple of hours I still can't figure out how to read a danged pixel. From sweetmelon at gmail.com Sun Dec 24 07:33:08 2006 From: sweetmelon at gmail.com (sweetmelon at gmail.com) Date: 24 Dec 2006 04:33:08 -0800 Subject: [pyOpenGL]Demo cannot run on Python2.5 Message-ID: <1166963588.436707.87450@n51g2000cwc.googlegroups.com> (I'm a newbie in Python and pyOpenGL.) Environment: WinXP SP2 Python ver. 2.5 WingIDE easy_install is installed PIL, pyNum is installed Download PyOpenGL-3.0.0a5-py2.5.egg run: easy_install PyOpenGL-3.0.0a5-py2.5.egg pyOpenGL is installed in D:\Python25\Lib\site-packages\PyOpenGL-3.0.0a5-py2.5.egg\ I tried to run a example ".\OpenGL\Demo\da\dots.py", but it fails in the line: from OpenGL.GL import * with errors: AttributeError: 'WinFunctionType' object has no attribute 'returnValues' Traceback (innermost last): File "OpenGL\Demo\da\dots.py", line 1, in #!/usr/bin/python File "OpenGL\Demo\da\dots.py", line 24, in from OpenGL.GL import * File "OpenGL\GL\__init__.py", line 3, in from OpenGL.raw.GL.annotations import * File "OpenGL\raw\GL\annotations.py", line 19, in 'textures', File "OpenGL\arrays\arrayhelpers.py", line 68, in setInputArraySizeType if not hasattr( function, 'returnValues' ): File "OpenGL\wrapper.py", line 64, in __getattr__ return getattr( self.wrappedOperation, key ) It seems that pyOpenGL reimplements the module "ctypes" internally, but not finished.... I cannot find "self.wrappedOperation" with any attribute with the name of 'returnValues'. How to go through this problem? Did I make some simple mistakes at the beginning of the installation of pyOpenGL? Thank you! ShenLei From nagle at animats.com Mon Dec 25 13:12:39 2006 From: nagle at animats.com (John Nagle) Date: Mon, 25 Dec 2006 18:12:39 GMT Subject: Unescaping URLs in Python In-Reply-To: References: Message-ID: Lawrence D'Oliveiro wrote: > In message , John Nagle > wrote: > > >>Here's a URL from a link on the home page of a major company. >> >>About Us >> >>What's the appropriate Python function to call to unescape a URL >>which might contain things like that? > > > Just use any HTML-parsing library. I think the standard Python HTMLParser > will do the trick, provided there aren't any errors in the HTML. I'm using BeautifulSoup, because I need to process real world HTML. At least by default, it doesn't unescape URLs like that. Nor, on the output side, does it escape standalone "&" characters, as in text like "Sales & Advertising Department". But there are various BeautifulSoup options; more on this later. John Nagle From kkylheku at gmail.com Wed Dec 13 17:15:40 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 13 Dec 2006 14:15:40 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165969090.648421.177130@16g2000cwy.googlegroups.com> <2006121302412950073-raffaelcavallaro@pasdespamsilvousplaitmaccom> Message-ID: <1166048140.833255.237550@73g2000cwn.googlegroups.com> Rob Warnock wrote: > And for any of you who are rejecting this because you don't want to > learn or use Emacs, Raffael's point is even true in the Vi family of > editors ("nvi" & "vim", at least). The "y%" command yanks (copies) > everything through the matching paren into the anonymous buffer; > "d%" deletes likewise [and saves in the anonymous buffer]; "p" (or "P") > pastes after (or before) the current location. All can be prefixed > with a buffer ("Q-register") name for more flexibility. If you're on Vim, you also have the "ib" and "ab" commands that work under visual selection. You repeat them to broaden the selection to the next level of nesting. From webmaster at cacradicalgrace.org Mon Dec 4 12:40:54 2006 From: webmaster at cacradicalgrace.org (J. Clifford Dyer) Date: Mon, 04 Dec 2006 10:40:54 -0700 Subject: Inheritance doesn't work References: <45745286$0$32597$c3e8da3@news.astraweb.com> Message-ID: Fredrik Lundh wrote: > John Salerno wrote: > >> How do you get that error with that code? > > $ python > >>>> import os >>>> class foo(os): > .... pass > .... > Traceback (most recent call last): > File "", line 1, in > TypeError: Error when calling the metaclass bases > module.__init__() takes at most 2 arguments (3 given) > > > Sure, but I think the question was more about how code that references "MandelbrotImage could yield a stack that references MandelImage. From goodjobfastcar at gmail.com Wed Dec 6 16:31:38 2006 From: goodjobfastcar at gmail.com (Peter Smith [gjfc]) Date: 6 Dec 2006 13:31:38 -0800 Subject: [Python] SMTP server based on Python? Message-ID: <1165440698.846121.318110@j44g2000cwa.googlegroups.com> People, I have sendmail working on my linux box. Since I can use sendmail to send e-mails, would it be easy to write a simple Python class which listens for data on port 25? Then, if it gets some data, it just passes it to sendmail. Do any of you know if such a simple script is floating around somewhere on the net? ...Peter http://GoodJobFastCar.com From grahn+nntp at snipabacken.dyndns.org Fri Dec 15 11:01:02 2006 From: grahn+nntp at snipabacken.dyndns.org (Jorgen Grahn) Date: 15 Dec 2006 16:01:02 GMT Subject: I'm looking for a pythonic red-black tree... References: Message-ID: On Fri, 15 Dec 2006 01:20:34 GMT, Just Another Victim of the Ambient Morality wrote: > I need a red-black tree in Python and I was wondering if there was one > built in or if there's a good implementation out there. Something that, > lets face it, does whatever the C++ std::map<> allows you to do... Nitpick: std::map is implemented using RB-trees, but it isn't one, interface-wise. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From josephoswald at gmail.com Wed Dec 20 13:15:00 2006 From: josephoswald at gmail.com (josephoswaldgg@hotmail.com) Date: 20 Dec 2006 10:15:00 -0800 Subject: merits of Lisp vs Python In-Reply-To: <45897266$0$4158$ba624c82@nntp02.dk.telia.net> References: <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <45897266$0$4158$ba624c82@nntp02.dk.telia.net> Message-ID: <1166638500.535236.34530@48g2000cwx.googlegroups.com> Anders J. Munch wrote: > jayessay wrote: > > Please note: GC is not part of CL's definition. It is likely not part > > of any Lisp's definition (for reasons that should be obvious), and for > > the same reasons likely not part of any language's definition. > > Really? So how do you write a portable program in CL, that is to run > for unbounded lengths of time? > > - Anders Write it, and depend on the implementation to do its job well, and complain to the implementors if it doesn't. How do you write a portable program in C that is to run for unbounded lengths of time? Even if you religiously call free() on every malloc()'d block, you could eventually fragment memory enough that the allocator might eventually fail. You can exceed the VM capacity. The OS could decide to crash periodically. The power supply could fail, the sun could progress to the red giant phase... The real answer is that these are not issues for the language definition, but for the implementor. From gagsl-py at yahoo.com.ar Mon Dec 11 20:50:59 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 22:50:59 -0300 Subject: Restricting import file lookup for pyd, dll, ... In-Reply-To: <61d0e2b40612111411n5f9faackf8f52fa348c731cb@mail.gmail.com > References: <61d0e2b40610191438w9ba0693y8896bebc3441069a@mail.gmail.com> <7.0.1.0.0.20061019184812.05aafe78@yahoo.com.ar> <61d0e2b40612111411n5f9faackf8f52fa348c731cb@mail.gmail.com> Message-ID: <7.0.1.0.0.20061211221600.03ef9e98@yahoo.com.ar> At Monday 11/12/2006 19:11, Bernard Lebel wrote: >If by "shortening the PYTHONPATH" you meant having less paths, I >hardly see how I could do less than what I do with the pth. All these >paths seem to be built in. I mean, delete the ones that actually don't exist. sys.path is a simple list; you can traverse it (perhaps backwards is easier) in site.py or sitecustomize.py and delete unexistant entries. Moving the network related paths (\\linuxserver\...) towards the end may help (if you don't get conflicts by finding the wrong module in the wrong place) [Fredrik Lundh] a plain Python 2.4 interpreter can start, execute a >command, and shut >down in about 0.13 seconds on my machine. 2.5 does the same thing in >0.10 seconds. > >[Bernard] The problem is not firing up the standalone Python >interpreter. The problem is firing the application that embeds a >Python interpreter. > >As explained above, when I start this application, many files are >looked in many different places. All PYTHONPATH locations are >traversed, where pyd-dll-py-pyw-pyc files are searched. Many of these >files are searched in highly improbable locations. But the whole process takes about 3sec - as seen on your log. (enabling ms resolution on FileMon may help too, because the timing is now too much rough) >[Fredrik Lundh] are you sure you're benchmarking *Python's* start up >time, and not the >time it takes to load all the modules used by your application, or the >time it takes for "filemon" to print all those 4500 requests to the >monitor window? > >[Bernard] The Filemon overhead consistently clocks at 1 second, not >matter the test I perform. Since I ran all tests with Filemon running, >I feel safe to ignore this constant. > >Now, as to the first sentence, to be fair, no, I'm not exactly sure. I >don't know all the details of the Python's embedding in this software, >and this knowledge is out of my reach atm. Have you tried running the interpreter alone? Not your embedded application. Try invoking python with the -v flag. For an embedded application, define PYTHONVERBOSE=1 in the environment before running. Perhaps it's not Python which slows down your startup, but other parts of the app. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From jimmy at retzlaff.com Sun Dec 31 08:27:27 2006 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Sun, 31 Dec 2006 05:27:27 -0800 Subject: py2exe 0.6.6 released Message-ID: py2exe 0.6.6 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation. Console and Windows (GUI) applications, Windows NT services, exe and dll COM servers are supported. Changes in 0.6.6: * Better support for Python 2.5. * Experimental support for 64-bit builds of Python on win64. * Better ISAPI support. * New samples for ISAPI and COM servers. * Support for new "command-line styles" when building Windows services. Changes in 0.6.5: * Fixed modulefinder / mf related bugs introduced in 0.6.4. This will be most evident when working with things like win32com.shell and xml.xpath. * Files no longer keep read-only attributes when they are copied as this was causing problems with the copying of some MS DLLs. Changes in 0.6.4: * New skip-archive option which copies the Python bytecode files directly into the dist directory and subdirectories - no archive is used. * An experimental new custom-boot-script option which allows a boot script to be specified (e.g., --custom-boot-script=cbs.py) which can do things like installing a customized stdout blackhole. See py2exe's boot_common.py for examples of what can be done. The custom boot script is executed during startup of the executable immediately after boot_common.py is executed. * Thomas Heller's performance improvements for finding needed modules. * Mark Hammond's fix for thread-state errors when a py2exe created executable tries to use a py2exe created COM DLL. Changes in 0.6.3: * First release assembled by py2exe's new maintainer, Jimmy Retzlaff. Code changes in this release are from Thomas Heller and Gordon Scott. * The dll-excludes option is now available on the command line. It was only possible to specify that in the options argument to the setup function before. The dll-excludes option can now be used to filter out dlls like msvcr71.dll or even w9xpopen.exe. * Fix from Gordon Scott: py2exe crashed copying extension modules in packages. Changes in 0.6.2: * Several important bugfixes: - bundled extensions in packages did not work correctly, this made the wxPython single-file sample fail with newer wxPython versions. - occasionally dlls/pyds were loaded twice, with very strange effects. - the source distribution was not complete. - it is now possible to build a debug version of py2exe. Changes in 0.6.1: * py2exe can now bundle binary extensions and dlls into the library-archive or the executable itself. This allows to finally build real single-file executables. The bundled dlls and pyds are loaded at runtime by some special code that emulates the Windows LoadLibrary function - they are never unpacked to the file system. This part of the code is distributed under the MPL 1.1, so this license is now pulled in by py2exe. * By default py2exe now includes the codecs module and the encodings package. * Several other fixes. Homepage: Download from the usual location: Enjoy, Jimmy From address.good.until.2006.dec.22 at justmail.de Fri Dec 8 11:36:14 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=) Date: Fri, 08 Dec 2006 17:36:14 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1165594621.136524.198600@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> Message-ID: hankhero schrieb: > Some clever details, like using minus to index vectors from the right. > (aref "hello" -1) gives an error on Lisp, but the character o on Python. It would not be difficult to add this feature to Lisp. > Another detail I like is that you can choose how to quote strings, in > Python you can write three double-quotes to start a string that can > include anything, quotes, doublequotes and newlines. > You can use double-quote if you want to embed single-quotes "john's" or > single-quote if you want to embed double-quotes ''. You could add a reader macro in Lisp that allows you to do the same. At the moment I would say that one could pretty much add most Python features to Lisp. Be it slicing, list comprehension, or, if one wants, Pythons object system. On the other hand can I see difficulties in adding macros to Python, or inventing a new object system, or adding new keywords without changing the sources of Python itself. Andr? -- From xscottg at gmail.com Sat Dec 30 01:17:34 2006 From: xscottg at gmail.com (xscottg at gmail.com) Date: 29 Dec 2006 22:17:34 -0800 Subject: Anyone persuaded by "merits of Lisp vs Python"? References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> Message-ID: <1167459454.002991.64260@48g2000cwx.googlegroups.com> Paddy3118 wrote: > This month there was/is a 1000+ long thread called: > "merits of Lisp vs Python" > In comp.lang.lisp. > > If you followed even parts of the thread, AND previously > used only one of the languages AND (and this is the > crucial bit), were persuaded to have a more positive view > of the other language; (deep breath, this is a long, as > well as grammatically incorrect sentence), THEN WHY NOT > POST ON WHAT ARGUMENTS PERSUADED YOU. > I fail two thirds of your requirements - at least now. However, several years ago, I knew Python and was only passingly familiar with Lisp. To me, at that time, Lisp was a language where the compiler/interpreter writers were too lazy to write a real parser. "I object to doing things that computers can do" [1]. I wasn't completely happy with Python though. It does threads poorly (no concurrency unless you release the GIL in a C extension). The buffer protocol has issues (particularly if you release the GIL) [2]. The Numpy stuff is bogged down with it's own backward compatible history. Tkinter leaks memory if you're not careful with it. Adding a C extension is non-trivial and takes your application from being a collection of scripts to a distutils driven thing. These are real issues that I still bump my head on (because I still use Python a lot of the time). For those reasons, I'm still searching for a better language for my needs. Anyway, at that time, I saw an article about adding Hygienic Macros to Python. The term caught my attention, and it was shot down in the Python world. Of course, malcontent that I am, I had to go find out what that was about. I had already seen how in Tcl you could create new constructs. [3] Turns out Scheme and Common Lisp take that idea to a new and higher place. I found out the reason Lispers [4] stuck with their lazily written parsers is that in exchange for infix operators, they can pretty much assimilate any other language. Here is an easily readable piece of Python: def doit(n): for i in xrange(n): print i With very little effort, here it is in Scheme: (def doit(n) (for i in (xrange n) (print i))) Don't any other Pythonistas find that interesting? Scheme could suck in all of Python's beloved semantics with an incredibly similar syntax in a couple days. [5] It was an interesting revelation to me. Then if you wanted to add new features (Python 2.5 "with" for example), you could do it yourself. Moreover, you could steal good features from other languages too. The point to all of this is that the cross pollination is arguably a good thing. [6] If the Schemer's had stuck in their camp, I would never had known that they had something worth looking at. This is the same way that I was happily using Perl in college, and some Perl/Python exchange got me to look at Python. > OTHERWISE LET THIS POST WITHER AND DIE ALONE. It will die on it's own. Add it to your killfile, ignore it in Google Groups whatever. More bandwidth was wasted by Paris Hilton and Britney Spears than in this winding thread... Cheers. [1] A quote from Olin Shivers, and apparently he likes Lisp. That struck me as ironic at first. [2] Interestingly, Jython handles threads and buffers much better because it's built on a virtual machine that considers those important. Of course with Jython, you have to embrace the rest of the Java environment... [3] I thought it was particularly cool how Tcl could bolt on a class based object oriented system as a library. The word "class" isn't built into the language, but that kind of evaluator lets you add it. [4] I don't consider myself a Lisper or Schemer. I'm just exploring the programming language space trying to learn new ideas. [5] Incidently, I haven't found the version of Scheme that gives me concurrent threads, efficient buffers, C FFI, and numeric arrays the way I want, but I'm still looking. [6] Kenny Tilton pointed that out several times in the other thread. There are many more lurkers looking and learning than posters posting. From bluejump at mac.com Thu Dec 28 05:53:41 2006 From: bluejump at mac.com (Kajsa Anka) Date: Thu, 28 Dec 2006 11:53:41 +0100 Subject: Scaling pictures Message-ID: <0001HW.C1B960C5006E7E2DF0488648@News.Individual.DE> I would like some advice, I'm going to build a small app that will, among other things, scale images so that they can be published on a web site. I've never done any image processing in python before so I would like to ask what is the best way of doing this, I will not do anything else than scaling the images. I found the Python Imaging Library but before I dive into that I would like to know if there is a better way of doing this. From manstey at csu.edu.au Fri Dec 8 03:38:13 2006 From: manstey at csu.edu.au (manstey) Date: 8 Dec 2006 00:38:13 -0800 Subject: autoadd class properties Message-ID: <1165567093.167813.109000@j44g2000cwa.googlegroups.com> I have a ClassWrapper that wraps around a third party database object. Each database object has a set of properties, like columns in a relational database. I want my wrapper to generate a property for each database object and load its value into it. Thus, in my database (which is an oodbms) say I have a MyDbaseClass with MyProperty1, MyProperty2, etc, after it is loaded, I have: dbase_object = LoadMyDbaseClass PythonDbaseClass = PythonWrapper(dbase_object) I can then load in a list of ['MyProperty1','MyProperty2', etc]. But how can I turn these list elements into PythonDbaseClass properties, so that I could then simply have: print PythonDbaseClass.MyProperty1 PythonDbaseClass.MyProperty2="4" Is this clear? From fredrik at pythonware.com Thu Dec 7 09:37:08 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 7 Dec 2006 15:37:08 +0100 Subject: Initializing with the correct type References: <1165496163.392526.322700@f1g2000cwa.googlegroups.com> Message-ID: aine_canby at yahoo.com wrote: > I'm new to Python and I'm just wordering if my approch is correct. > Here's an example. I'm making sure that the length and types are > correct. This is in case I use such a class and accidently pass it the > wrong object. if you go with the language instead of against it, you'll soon find that if you do accidentally pass in the wrong thing, you'll notice that pretty quickly: http://effbot.org/pytut/glossary#eafp http://effbot.org/pytut/glossary#duck-typing From gandalf at designaproduct.biz Fri Dec 8 11:07:02 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Fri, 08 Dec 2006 17:07:02 +0100 Subject: IMAP4 SEARCH question In-Reply-To: <4579882E.7080905@designaproduct.biz> References: <4579882E.7080905@designaproduct.biz> Message-ID: <45798DA6.7050607@designaproduct.biz> Sorry, I found it: date = date-text / DQUOTE date-text DQUOTE date-day = 1*2DIGIT ; Day of month date-day-fixed = (SP DIGIT) / 2DIGIT ; Fixed-format version of date-day date-month = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" / "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec" date-text = date-day "-" date-month "-" date-year Is there a standard way to convert a datetime to this special, format or should I write my own function? From anthra.norell at vtxmail.ch Fri Dec 29 07:49:20 2006 From: anthra.norell at vtxmail.ch (Frederic Rentsch) Date: Fri, 29 Dec 2006 13:49:20 +0100 Subject: textwrap.dedent replaces tabs? In-Reply-To: References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> <232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com> Message-ID: <45950ED0.3080407@vtxmail.ch> Tom Plunket wrote: > Frederic Rentsch wrote: > > >> Your rules seem incomplete. >> > > Not my rules, the stated documentation for dedent. "My" understanding > of them may not be equivalent to yours, however. It's not about understanding, It's about the objective. Let us consider the difference between passing a driving test and riding a bicycle in city traffic. The objective of passing the test is getting the license and the means is knowing the rules. The objective of riding the bicycle is surviving and the means is anticipating all possible breaches of rules on he part of motorists. > What if common tabs remain after stripping common white space? > What if we just go with, "[r]emove any whitespace than can be uniformly > removed from the left of every line in `text`." ? > >> Does this never happen? Or can we hope it doesn't happen? >> > > "Hope" has no place in programming software that is to be used by > others. > > That's exactly what I am saying. That's exactly why it may be a good idea to provide preventive measures for rules being breached be those others over whom we have no control. >> To err on the side of caution I complete your rules and this is my >> (tested) attempt at expressing them pythonically. >> > > Inasmuch as "my" rules have been expressed via tests, the provided code > fails four of the five tests provided. > > toms_test_data = ( ( "\n Hello\n World", # Do this "\nHello\n World", ), # Expect this ( "\n\tHello\n\t World", "\nHello\n World", ), ( "\t\tHello\n\tWorld", "\tHello\nWorld", ), ( "Hello\n\tWorld", "Hello\n\tWorld", ), ( " \t Hello\n \tWorld", "\t Hello\n \tWorld", ), ) >>> for dedent_this, expect_this in toms_test_data: done = '\n'.join (dedent (dedent_this.splitlines ())) if done == expect_this: print 'BRAVO!!!' else: print 'SHAME ON YOU!!!' BRAVO!!! BRAVO!!! BRAVO!!! BRAVO!!! BRAVO!!! You seem to have plugged my function into your tester. I wasn't concerned about your testing interface but about the dedentation. >> (I admit it does look awfully sevety-ish. Just a vulgar little >> function.) >> > > Seventys-ish is as much a statement about the lack of statement about > how you actually tested it as it is that an implementation was made > apparently without understanding of the requirements. > > > -tom! > > Best regards Frederic From david at boddie.org.uk Sat Dec 2 13:01:08 2006 From: david at boddie.org.uk (David Boddie) Date: 2 Dec 2006 10:01:08 -0800 Subject: evaluating gui modules, any experience on tkinter? References: Message-ID: <1165082468.880993.23400@16g2000cwy.googlegroups.com> krishnakant Mane wrote: > I seam to have noticed this a bit late but it appears to me that > tkinter is being used very widely for gui development on all platform? > is that right? Tkinter is bundled with Python on all platforms that support Tcl/Tk. As a result there's a low "barrier to entry" to Tkinter programming, so people tend to use it, at least when they start with GUI development. > 3. I don't know if I need any thing else as dependencies on my > windows machine. I am using python24 and I did not find any thing > about installation in the introduction to tkinter. can some one give > me the process of installing tkinter and all necessary things? It's been a long time since I installed Python on Windows, and I think I used ActivePython: http://www.activestate.com/Products/ActivePython/ I believe that this package includes Tkinter, so you shouldn't have to do anything else to install it. > so I am confused between wxpython pyqt and now tkinter. > out of the 3 I only found qt talking extencively about accessibility, > but did not find a way to install qt in the first place. I could not > compile qt nor did I find any run-time dlls for mingw so that I can > use it out of the box. I believe there should be a package which includes pre-built Qt libraries as well as source code, all licensed under the GNU GPL. It may not help you get started with MinGW, though the information on the download page indicates that the package "will also download and install the MinGW compiler, if needed". Take a look at the following page for more information: http://www.trolltech.com/developer/downloads/qt/windows If you're unable to license your own code under the GNU GPL then you'll have to look at commercial licenses for Qt and PyQt. David From manstey at csu.edu.au Fri Dec 8 19:01:04 2006 From: manstey at csu.edu.au (manstey) Date: 8 Dec 2006 16:01:04 -0800 Subject: autoadd class properties In-Reply-To: <1165569502.811830.157900@73g2000cwn.googlegroups.com> References: <1165567093.167813.109000@j44g2000cwa.googlegroups.com> <1165569502.811830.157900@73g2000cwn.googlegroups.com> Message-ID: <1165622463.975932.323830@j72g2000cwa.googlegroups.com> Hi, Cache is a pure OO dbase, so no ORM is required. Cache provides a python equivalent for the Cache class, but not for the Cache properties. Instead, the programmer has to know in advance the properties and their type to get and set them. I want to wrap the Python-cache class and add the Cache properties into the class, but I don't know how to do this. Any ideas? George Sakkis wrote: > manstey wrote: > > > I have a ClassWrapper that wraps around a third party database object. > > Each database object has a set of properties, like columns in a > > relational database. > > > > I want my wrapper to generate a property for each database object and > > load its value into it. > > > > Thus, in my database (which is an oodbms) say I have a MyDbaseClass > > with MyProperty1, MyProperty2, etc, after it is loaded, I have: > > > > dbase_object = LoadMyDbaseClass > > PythonDbaseClass = PythonWrapper(dbase_object) > > > > I can then load in a list of ['MyProperty1','MyProperty2', etc]. > > > > But how can I turn these list elements into PythonDbaseClass > > properties, so that I could then simply have: > > > > print PythonDbaseClass.MyProperty1 > > PythonDbaseClass.MyProperty2="4" > > > > Is this clear? > > Sounds as if you're reinventing a part of an ORM. Have you checked out > SQLAlchemy or Django's ORM, in case they provide what you want out of > the box ? > > George From pyenos at pyenos.org Fri Dec 22 08:40:37 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 00:40:37 +1100 Subject: Confusion over calling a nested function inside a parent function References: <877iwkdpsb.fsf@pyenos.pyenos.org> <1166794524.504018.240630@h40g2000cwb.googlegroups.com> Message-ID: <87y7p0calm.fsf@pyenos.pyenos.org> "MacDonald" writes: > Pyenos wrote: > > [code] > > class WORK: > > def getwork(self): > > def choosetable(self):pass > > choosetable() #TypeError: choosetable() takes exactly 1 > > #argument (0 given) > > [/code] > > > > Calling choosetable() at the above location gives me the error > > described above. > > Although choosetable is a memeber of an instance method, it is not one > itself. It should not have self as it's first formal parameter. [code] class WORK: def getwork(self): def choosetable():pass choosetable() [/code] like this? thank you! ;-) From at at tuko.nl Thu Dec 14 02:06:32 2006 From: at at tuko.nl (at) Date: Thu, 14 Dec 2006 08:06:32 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> Message-ID: <4580f7f4$0$331$e4fe514c@news.xs4all.nl> My comments below. Kind regards, @ Carl Banks wrote: > at wrote: >> Well, all I can say that for me as a user it would make sense... > > Which is, like, step one out of a hundred for getting a syntax change > into the language. > >> Curiosity: in what sense is it redundant? > > It creates syntactical support for two different ways to do something. > If your plan were adopted, then we'd have two different spellings for > the same thing: > > for i in a: > if i != 0: > use(i) > > for i in a if i != 0: > use(i) With the current Python syntax, I can create for every two lines of code a dozen alternative implementations: # example 1 a = {} a['b'] = 'c' versus: a = {'b': 'c'} # example 2 l = [] for l in some_list: if some_condition: l.append(l) versus: l = [] for x in some_list: if some_condition: l = l + [x] or: l = [x for x in some_list if some_condition] (the beautiful one) So your argument doesn't mean much I would say! > > Now, redundant syntax isn't a deal breaker by itself. You have to ask > what is buys you. In this case, all it does is save you a single level > of indentation--that's it. There's no performance benefit. It doesn't > simplify logic. It doesn't make the code any more readable of clear. > It's only a minor improvement in conciseness. It hardly saves any > typing (unless you indent by hand). Even its one clear benefit, saving > indentation, is something you can already get with "if not x: > continue". Well there is a clear performance benefit, or more precisely a productivity benefit. And -please- do not underestimate this for a language like Python, which has many supporters due to its perceived and high productivity and challenged on this point by languages like Ruby. 'for x in some_list if some_condition:' is psychological very strong, because the brain will most likely treat the in the same way as : for every apple in the fruitbasket take one if green Basically upon reading this first line you know exactly to what list of items your next section of code applies. But again everything is a matter of taste and I assume that's why the change control body is put into the hand of one person. > Considering how little this syntax change buys, it really doesn't make > a lot of sense for a language that places high emphasis on avoiding > redundancy. > > >> All solution/workarounds I have seen so far involve creation of new lists >> (subsets) adding to more processing/computation/memory usage. Redundant >> suggests that you know alternatives that don't do that. >> >> Does Guido ever change his mind? > > Yes, but I guarantee "it makes sense for me" isn't going to convince > him. By the way, I'd suggest when posting to comp.lang.python and/or > python-list in the future, you put your replies beneath the quoted text > for the benefit of any future readers (not to mention present readers). > I hope this this thread will support the "it makes sense for me" with arguments. Again it is not my intention to fight windmills, but to see if there are strong arguments against it on one hand and if there supporters on the other hand. > > Carl Banks From greg at cosc.canterbury.ac.nz Mon Dec 11 22:35:48 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 12 Dec 2006 16:35:48 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> Message-ID: <4u6mffF161jbqU3@mid.individual.net> Bill Atkins wrote: > greg writes: > > > There's no way you could compile Python to efficient > > machine code just by macro expansion. You'd also need > > some very heavy-duty type inferencing. > > A compiler shifts a lot of decisions that an > interpreter would have to make at runtime to compile-time. There is > no reason a dynamic language can't enjoy this efficiency. I'm not saying that it's impossible to compile Python, only that's there's a lot more to it than just macro expansion. The OP was saying something like "If you added macros, you might get a compiler for free", which is clearly far from true. > if Python is doing a hash lookup on every function call, > as Alex Mizrahi claims, compilation may not do much to smooth over > such awkwardness. As currently implemented, CPython does a dictionary lookup or two every time a module global or builtin (which most stand-alone functions are) is referenced. It would actually be relatively easy to optimise this into an array lookup in most cases, but most calls in Python code tend to be *method* calls, which are rather harder to deal with. Possibly cacheing of method lookups would help, although I don't know of anyone having tried it. > > Python is extremely dynamic, even more so than Lisp. > > Uh huh. "More so than Lisp"? Just making stuff up now? When a Lisp compiler sees (setq c (+ a b)) it can reasonably infer that the + is the built-in numeric addition operator. But a Python compiler seeing c = a + b can't tell *anything* about what the + means without knowing the types of a and b. They might be numbers, or strings, or lists, or some user-defined class with its own definition of addition. From another angle, think about what a hypothetical Python-to-Lisp translator would have to do. It couldn't just translate "a + b" into "(+ a b)". It would have to be something like "(*python-add* a b)" where *python-add* is some support function doing all the dynamic dispatching that the Python interpreter would have done. That's what I mean by Python being more dynamic than Lisp. > Despite its dynamism, Lisp is quite compilable. Please correct me if I'm wrong, but as I understand, getting efficient code out of a Lisp compiler requires putting type declarations into the source. If you put the same declarations into a piece of Python code, then of course it would be fairly straightforward to compile it efficiently. But it wouldn't really be dynamic Python any more. Python may end up going this way -- there are currently plans to make room for attaching optional annotations to function arguments, which could be used to convey type information to a compiler (although that's not currently the main intended use). The alternative is whole-program analysis and huge amounts of type inferencing, which the PyPy people are working on. Maybe something practical will come out of that. Whichever, it's nowhere near a simple as just "adding macros"! -- Greg From greg at cosc.canterbury.ac.nz Tue Dec 12 22:06:32 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 13 Dec 2006 16:06:32 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> <7xwt4yju5e.fsf@ruckus.brouhaha.com> <7x1wn57voq.fsf@ruckus.brouhaha.com> <7xirghy7pu.fsf@ruckus.brouhaha.com> <7xvekhxscq.fsf@ruckus.brouhaha.com> Message-ID: <4u994kF16pm7hU1@mid.individual.net> Espen Vestre wrote: > Paul Rubin writes: > > there is a huge amount of > > state scattered all through a running Python program, that the > > application can modify at random > > That's what I call /kludgy/, not /dynamic/ ;-) I think "kludgy" is a bit unfair, since this is a result of doing things in a very simple and uniform way -- rather a Lispy concept, I would have thought. :-) -- Greg From michele.petrazzoDELETE at DELETEunipex.it Fri Dec 22 13:08:52 2006 From: michele.petrazzoDELETE at DELETEunipex.it (Michele Petrazzo) Date: Fri, 22 Dec 2006 18:08:52 GMT Subject: optparser question In-Reply-To: References: Message-ID: Steven Bethard wrote: > You can try using argparse_, which doesn't make these weird > inferences, and generally assumes that your action will take a single > argument unless you specify otherwise:: > <-cut-> > Not sure exactly what your callback was trying to do though -- it > seems like you're just duplicating the 'store' action (which is the > default anyway). I made only a copy from the python docs for show the "problem". Ok, I have not understand the "trickle" for transform the action="callback" and provide a callback to a new action. I believe, however, that the doc has to be more explicit about this strange behavior, because a not so expert dev (like me :) ), can don't understand at the first time, it. > STeVe Thanks, Michele From HDoran at air.org Fri Dec 29 08:20:36 2006 From: HDoran at air.org (Doran, Harold) Date: Fri, 29 Dec 2006 08:20:36 -0500 Subject: Beginner question on text processing Message-ID: <2323A6D37908A847A7C32F1E3662C80E6B0E38@dc1ex01.air.org> I am beginning to use python primarily to organize data into formats needed for input into some statistical packages. I do not have much programming experience outside of LaTeX and R, so some of this is a bit new. I am attempting to write a program that reads in a text file that contains some values and it would then output a new file that has manipulated this original text file in some manner. To illustrate, assume I have a text file, call it test.txt, with the following information: X11 .32 X22 .45 My goal in the python program is to manipulate this file such that a new file would be created that looks like: X11 IPB = .32 X22 IPB = .45 Here is what I have accomplished so far. ##### Python code below for sample program called 'test.py' # Read in a file with the item parameters filename = raw_input("Please enter the file you want to open: ") params = open(filename, 'r') for i in params: print 'IPB = ' ,i # end code This obviously results in the following: IPB = x11 .32 IPB = x22 .45 So, my questions may be trivial, but: 1) How do I print the 'IPB = ' before the numbers? 2) Is there a better way to prompt the user to open the desired file rather than the way I have it above? For example, is there a built-in function that would open a windows dialogue box such that a user who does not know about path names can use windows to look for the file and click on it. 3) Last, what is the best way to have the output saved as a new file called 'test2.txt'. The only way I know how to do this now is to do something like: python test.py > test2.txt Thank you for any help -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomas at fancy.org Thu Dec 28 13:49:58 2006 From: tomas at fancy.org (Tom Plunket) Date: Thu, 28 Dec 2006 10:49:58 -0800 Subject: getting a process's PID References: <20061227102939.L20663@eris.io.com> <4592abf1$1@nntp.zianet.com> <20061227113158.J21223@eris.io.com> Message-ID: eldorado wrote: > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] > >>> h = h[:-1] > >>> h > [] > >>> I understand you're probably set, but instead of using readlines() you could also do this: g = os.... h = g.read().split('\n') and then your 'h' list would not have newlines. -tom! -- From greg at cosc.canterbury.ac.nz Wed Dec 13 22:16:36 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 14 Dec 2006 16:16:36 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> Message-ID: <4ubu3nF16kv7aU1@mid.individual.net> Ken Tilton wrote: > pps. How would Python do this? Here's one way it could look: defskill("absolute-value", title = "Absolute Value", annotations = [ "Take the absolute value of #op#.", "The vertical bars around #op# mean 'the absolute value of' #op#.", "Absolute value of #strn# is the 'distance' of #strn# from zero.", "Absolute value is always zero or positive: #str|n|=n#, and #str|-n|=n#." ], hints = [ "What do those vertical bars around #op# mean?", "Have you learned about 'absolute value'?", """Absolute value can be thought of as the 'distance' of a value from zero on the number line, and distance is always positive.""", "The rule is:#str|-n|=|n|##str=n#. Can you apply that to #op#?", "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#.", """To get the absolute value of a number such as #op#, we simply drop any minus sign.""" ] ) > Is it possible to avoid committing to an > implementation mechanism? The defskill function could do just about anything with this. Here's one possibility: skills = {} class Skill: pass # fill in whatever methods you need here def defskill(name, title, annotations, hints): skill = Skill() skill.title = title skill.annotations = annotations skill.hints = hints skills[name] = skill This gives you a dictionary of Skill instances indexed by name, each one having a title and lists of annotation and hint strings. The rest of the system can process this however required. -- Greg From metawilm at gmail.com Sat Dec 16 06:54:26 2006 From: metawilm at gmail.com (metawilm at gmail.com) Date: 16 Dec 2006 03:54:26 -0800 Subject: CLPython (was Re: merits of Lisp vs Python) References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <7xejr5y755.fsf@ruckus.brouhaha.com> <1166038096.200379.286830@80g2000cwy.googlegroups.com> <1166048301.513012.245480@73g2000cwn.googlegroups.com> <1166122900.477201.316320@73g2000cwn.googlegroups.com> <7xr6v2i3ay.fsf@ruckus.brouhaha.com> <1166210609.555804.304380@t46g2000cwa.googlegroups.com> <7x3b7gd8y0.fsf@ruckus.brouhaha.com> Message-ID: <1166270066.126349.201650@j72g2000cwa.googlegroups.com> Paul Rubin wrote: > metawilm at gmail.com writes: > > > a = 'hello' > > > a[0] = 'H' # attempt to change first letter to upper case > > > > As CLPython mirrors Python semantics, this results in a TypeError. The > > internal representation of an immutable Python string is a mutable Lisp > > string, but there is no way you can actually modify it from within CLPython. > > How do you manage that? The compiler can't check. Is there some kind > of special dispatch on the assignment statement instead of turning it > into a setf? Indeed, the assignment of subitems is dynamically dispatched, and always goes via __setitem__ methods, as specified in the language. The __setitem__ methods for strings and tuples raise exceptions. The ones for lists and vectors could be translated into a simple (setf (aref ..) ..) and (setf (nth ..) ..), unless the index is actually a slice and actually a subsequence must be replaced. Now, the above description using __setitem__ methods is how it apparently works, as observed from the outside. Internally there is a generic function (setf py-subs) that does the work itself, skipping the lookup and calling of __setitem__, if the object is a vector or dict. (The user can call x.__setitem__ explicitly, so that method must exist internally.) Maybe you were thinking that CLPython, given Python code, outputs a big pile of self-contained equivalent Lisp code that can be run independently, and then CLPython is finished. Instead, only a small amount of Lisp code is generated, but that code can only be run when the CLPython environment is loaded. The generated code refers to that environment, e.g. s[0] = 'x' is translated into a call to (setf (py-subs ..) ..), and function (setf py-subs) is part of the CLPython environment that must be loaded at run-time. If you compile a Python function, the result is a (mostly) normal Lisp function - its origin from the Python world does not really matter. Also, all Python data structures are first-class Lisp data. Thus CLPython objects live happily together with "normal" Lisp objects in the same image. And now we arrive at the most exciting part: other Lisp libraries can be loaded in the same image, and we can create connections. Like, after loading CLIM and defining how CLPython objects should be presented, we should get a Python interpreter where classes are displayed graphically and where you can inspect and modify them by mouse. Imagine that you have interactively added a method to a class by dragging a function to a class, then being able to right-click and select "write method", which will write the definition of the method in the right place in the class definition source code in your Climacs (CLIM-based Emacs) buffer. That's the kind of features I have in mind, and the best thing is that conceptually a lot of the work consists of connecting dots that already out there. But as there are so many of them, a few extra pencils would be quite welcome - Willem From robert.kern at gmail.com Mon Dec 4 03:22:11 2006 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 04 Dec 2006 02:22:11 -0600 Subject: Why not just show the out-of-range index? In-Reply-To: <1165219968.619509.147990@73g2000cwn.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> Message-ID: Russ wrote: > And > excuuuuuuuuuuuuuse me for suggesting a minor new feature to enhance the > productivity of Python without implementing it myself! Geez! Like I said, no one is castigating you for making the request. It's been your attitude afterwards that is the problem. You've been pointed to the productive things you can do to resolve the issue that you have: 1. Submit a bug report. 2. Submit a patch. Nothing is going to happen until you do one of these two things. Being more rude (and yes, you are being incredibly rude and insulting) won't move things along. -- 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 From george.sakkis at gmail.com Tue Dec 12 10:52:03 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 12 Dec 2006 07:52:03 -0800 Subject: object data member dumper? References: Message-ID: <1165938723.529980.234270@16g2000cwy.googlegroups.com> tom arnall wrote: > >object data member dumper? > >George Sakkis george.sakkis at gmail.com > >Wed Nov 8 03:42:47 CET 2006 > > > tom arnall wrote: > > > > > Bruno Desthuilliers wrote: > > > > > > > tom arnall a ?crit : > > > >> does anyone know of a utility to do a recursive dump of object data > > > >> members? > > > >> > > > > > > > > What are "object data members" ? (hint: in Python, everything is an > > > > object - even functions and methods). > > > > > > > > What is your real use case ? > > > > > > something like: > > > > > > class A: > > > def __init__(self, p1): > > > self.p1 = p1 > > > > > > class B: > > > def __init__(self,p1, p2): > > > self.a = A(p1) > > > self.p2 = p2 > > > self.v1 = '3' > > > > > > class C: > > > def __init__(self): > > > self.b = B(3,4) > > > self.p3 = 5 > > > > > > class D: > > > def __init__(self): > > > self.v2=2 > > > self.o1 = C() > > > self.o2 = B(11,12) > > > > > > > > > d = D() > > > objectDataDumper(d) > > > > > > > > > would produce something like: > > > > > > object of class D with: > > > o1(C)->b(B)->a(A)->p1=3 > > > o1(C)->b(B)->p2=4 > > > o1(C)->b(B)->v1=3 > > > o1(C)->p3=5 > > > o2(B)->a(A)->p1=11 > > > o2(B)->p2=12 > > > o2(B)->v1=3 > > > v2=2 > > > > > > > > > tom arnall > > > north spit, ca > > > usa > > > > At first I thought pickle would be what you're looking for, because > > that's exactly what it does; it dumps arbitrary objects, without > > choking on recursive references. Only problem is, it's not human > > readable (even in its ascii form).If you want it to be human readable, > > you may check the gnosis.xml.pickle module > > (http://cheeseshop.python.org/pypi/Gnosis_Utils/1.2.1-a). That's the > > output of gnosis.xml.pickle.XML_Pickler(d).dumps() on your example: > > > > > > > > > > > > > class="B"> > > > class="A"> > > > > > > > > > > > > > class="C"> > > > > > class="B"> > > > class="A"> > > > > > > > > > > > > > > > > > > > > I've also written a similar but less verbose xml dumper. The gnosis.xml > > package provides a bidirectional mapping between objects and xml > > (objects -> xml and xml->object) and therefore has to be precise; mine > > simply generates a nice xml dump of the object which isn't necessarily > > reversible. Here's the output for your example: > > > > > > > > > > > > 3 > > > > 4 > > 3 > > > > 5 > > > > > > > > 11 > > > > 12 > > 3 > > > > 2 > > > > > > > > If you find it suits you better, I'll try to make it available > > somewhere (probably in the cookbook). > > > > George > > > > > George, > > did you ever put up your object dumper on the net? Here it is: http://rafb.net/paste/results/C0NHBp27.html Mostly undocumented but works for most common types. Most methods are overridable so you can customize the dumping for a specific type (or types) in a subclass. George From derek.libby at gmail.com Mon Dec 25 17:53:58 2006 From: derek.libby at gmail.com (derekl00) Date: 25 Dec 2006 14:53:58 -0800 Subject: Website Capture In-Reply-To: References: <1167029844.360539.138940@f1g2000cwa.googlegroups.com> Message-ID: <1167087238.283977.147800@i12g2000cwa.googlegroups.com> Not sure what OS you are on, but a2ps is one way you could probably do this: http://www.infres.enst.fr/~demaille/a2ps/delegations.html That will get you as far as PostScript and I imagine it is pretty straightforward from there to get things into a gif. Jonathan Curran wrote: > On Monday 25 December 2006 00:57, yoring at gmail.com wrote: > > Hi, > > > > I want to capture a web site into gif image using Python. > > I installed the PIL if it can help. > > It can't be done with just Python & PIL, that much is for sure. First of all > you need some sort of module/program/(whatever you want to call it) that can > render a given webpage. Then you would proceed to capturing the graphical > output of that module/program/... > > Maybe what you should look into are graphical toolkits that possibly provide a > HTML widget from which you can get a graphical display. WxWidgets/WxPython is > one option, and the only other I can think of is GTK/pyGTK. > > I hope this helps a little, and Merry Christmas! > > - Jonathan Curran From researchbase at gmail.com Sat Dec 2 14:02:19 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Sun, 3 Dec 2006 00:32:19 +0530 Subject: wxpython worked out but can't find api docs for download. Message-ID: hello all. finally I got the accessibility issue out from wxpython. actually almost got it out, but that's another story. now my problem is that I can't gind a downloadable version of wxpython api reference for the latest version or the latest api reference at least. I found the on-line version so please don't provide the same link. when I opened it on line, it took about 8 minuts to get the wx package come up on screen with over 600 links. I need to have some off line reference for the wxpython api. I have enough documentation to get started but I don't have the extencive api references for events and other methods, properties and attributes. can some one point me to a .zip or .tar.gz version of the api docs for wxpython? thanking all. Krishnakant. From shansen at advpubtech.com Tue Dec 5 13:45:26 2006 From: shansen at advpubtech.com (Stephen Hansen) Date: Tue, 5 Dec 2006 10:45:26 -0800 Subject: About the 79 character line recommendation In-Reply-To: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> References: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> Message-ID: <7a9c25c20612051045u1061fj5654514d1958ae48@mail.gmail.com> On 5 Dec 2006 09:55:20 -0800, Steve Bergman wrote: > However, I am finding that the 79 character line prescription is not > optimal for readability. For me, 79 characters per line... would basically make my code a LOT harder for me to read and manage. I mean, a basic structure for a LOT of the code I end up working on is: class foo: def myMethod(self, arg1): try: try: connection = ConnectionQueue.get() ... finally: ConnectionQueue.put(connection) except: logging.exception("foo::myMethod(%s) unknown error" % arg1) At that point, i've lost 17-characters before I even start... Even some with just a very simple SQL statement ends up with text at 85ish characters. I might be biased, but my screen goes otu to about 200 characters-- and I'm not writing an open source app :) If I was, I might be more inclined to doing things in a more generally-readable way... but in my office scenario, I don't have to worry about people who are only reading to 79 characters. You have to evaluate your environment/audience, both current and of what it may be in the future. As a rule, if it's over about 125 characters, I try to split it up into different lines. While I'm on this general topic, the guide mentions a pet peeve about > inserting more than one space to line up the "=" in assignment > statements. To me, lining them up, even if it requires quite a few > extra spaces, helps readability quite a bit. Comments? I like lining up the equal statements/other punctuation for things that are all the "same". Like, if I'm using building up an event table w/ wxWidgets, I'll have all the arguments in the self.Bind(...) line up because then it's easier to scan for me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From istvan.albert at gmail.com Thu Dec 7 10:06:21 2006 From: istvan.albert at gmail.com (Istvan Albert) Date: 7 Dec 2006 07:06:21 -0800 Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: <1165503981.646812.320720@j72g2000cwa.googlegroups.com> Russ wrote: > The message tells you where the error occurred, but it doesn't tell you > what the range and the offending index are. So here is a scenario, what should happen if by accident one uses a 50Mb string as an index? Should it be displayed? i. From mystilleef at gmail.com Wed Dec 13 05:00:19 2006 From: mystilleef at gmail.com (mystilleef) Date: 13 Dec 2006 02:00:19 -0800 Subject: One module per class, bad idea? In-Reply-To: References: Message-ID: <1166004019.621972.309180@80g2000cwy.googlegroups.com> Matias Jansson wrote: > I come from a background of Java and C# where it is common practise to have > one class per file in the file/project structure. As I have understood it, > it is more common practice to have many classes in a Python module/file. > What is the motivation behind it, would it be a bad idea to have a guideline > in your project that promotes a one class per file structure (assuming most > of the programmers a background similar to mine)? It's a good idea. And I encourage it in my project. It makes sense for us because we document classes and methods copiously. However, use whatever works for your project. From roberth+news at ifi.uio.no Tue Dec 5 20:03:44 2006 From: roberth+news at ifi.uio.no (Robert Bauck Hamar) Date: Wed, 06 Dec 2006 02:03:44 +0100 Subject: newb: Join two string variables References: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> <1165366572.644641.73460@73g2000cwn.googlegroups.com> Message-ID: johnny wrote: Please don't top post. Arrange your answer so that your comments follow what you comment. > In my code, I have the following: > > p = posixpath.basename(e).strip make this: p = posixpath.basename(e).strip() > filename = download_dir+p > > I am getting the following error: > > filename = download_dir+p > TypeError: cannot concatenate 'str' and 'builtin_function_or_method' > objects > Which is correct. Because you forgot to _call_ strip, you just stored (a reference to) strip itself in p, and not its return value. (rest of message deleted, because I don't comment on it.) -- Robert Bauck Hamar Der er to regler for suksess: 1. Fortell aldri alt du vet. - Roger H. Lincoln From pavlovevidence at gmail.com Mon Dec 18 13:43:05 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 18 Dec 2006 10:43:05 -0800 Subject: Dictionary, iterate & update objects In-Reply-To: References: <1166302637.147669.266480@f1g2000cwa.googlegroups.com> <1166305376.376842.36270@16g2000cwy.googlegroups.com> <1166309359.764862.62110@l12g2000cwl.googlegroups.com> Message-ID: <1166467385.496046.20610@n67g2000cwd.googlegroups.com> Dennis Lee Bieber wrote: > On 16 Dec 2006 14:49:19 -0800, "jansenh" > declaimed the following in comp.lang.python: > > > Yes. > > [... the temp object is by ref, and any manipulation of the temp object > > is to the object itself..? It really simplifies my first attempt] > > > For all practical purposes, everything in Python is "by ref" and the > difference is whether the object itself is mutable (dictionaries, lists, > class instances, modules) or immutable (strings, tuples, numbers). A > mutable object is basically something that contains references to other > objects Not at all. It's not even generally true of Python. Mutability is orthogonal to containership. arrays, files, cStringIO objects, mmap objects, thread locks, some iterator types, etc., are mutable but do not contain Python objects (__dict__ excepted). tuples, frozensets, instancemethods, are immutable but do contain Python objects. Carl Banks From ihatespam at hotmail.com Wed Dec 6 00:02:03 2006 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Wed, 06 Dec 2006 05:02:03 GMT Subject: Looking for a decent HTML parser for Python... References: Message-ID: "Just Another Victim of the Ambient Morality" wrote in message news:Gordh.303466$tl2.18227 at fe10.news.easynews.com... > > Okay, I think I found what I'm looking for in HTMLParser in the > HTMLParser module. Except it appears to be buggy or, at least, not very robust. There are websites for which it falsely terminates early in the parsing. I have a sneaking feeling the sgml parser will be more robust, if only it had that one feature I am looking for. Can someone help me out here? Thank you... From nick at craig-wood.com Sun Dec 17 09:30:14 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sun, 17 Dec 2006 08:30:14 -0600 Subject: Serial port failure References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> <1166220402.505731.11150@l12g2000cwl.googlegroups.com> Message-ID: Rob wrote: > Craig, > > In the embedded firmware, the each box re-transmits after it finishes > reading the packet. This is a very rudimentary system, and uses no > flow control. The topology is that each embedded box has a master and > a slave port. The master is used to receive data from the upstream > box, and send acks or naks back to the upstream box. The slave is > connected to the master of the next downstream box. > > Does that clear up the picture a little bit? Sure! I suggest you run with the rest of my post and see what happens... I've seen dozens of broken serial port drivers over the years! ... My advice is to try a different serial port hardware. I've found ones based on the PL2303 chip to be very reliable both under windows and linux. Eg this one :- http://www.scan.co.uk/Products/ProductInfo.asp?WebProductID=98192 Or one of these (which were based on PL2303 last time I bought one) http://www.comtrol.com/products/catalog.asp?group=usbserialhubs I don't think anything you can do from python/user-space should be able to lock up the kernel mode serial driver. If it does lock up it is a driver bug. Here you'll find a little program I wrote which, with the help of a loopback connector, you can check your serial port out http://www.craig-wood.com/nick/pub/cambert.exe Run the program from a cmd prompt and it will tell you how to use it. I've broken a lot of serial port drivers with that program ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From sturlamolden at yahoo.no Fri Dec 15 14:53:04 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 15 Dec 2006 11:53:04 -0800 Subject: About alternatives to Matlab In-Reply-To: <4582d456$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> <1166035311.357588.115070@80g2000cwy.googlegroups.com> <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> <1166107026.581075.129010@t46g2000cwa.googlegroups.com> <4582d456$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1166212384.668729.186280@16g2000cwy.googlegroups.com> Jon Harrop wrote: > Yes. Non-sequential access is hugely expensive these days, and bounds > checking is virtually free. So that's one less reason to use C/C++... ;-) The lifiting scheme is sequential. From http Sat Dec 9 08:31:05 2006 From: http (Paul Rubin) Date: 09 Dec 2006 05:31:05 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <7xodqd9ox2.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > I don't agree. Syntax is significant for human readers, who are the vast > majority of programmers. > > Yes, people will get used to most syntax, eventually. But "used to" > doesn't necessarily mean "can read it efficiently". I did a lot of FORTH > coding in my youth, far more lines of code than Pascal, but Pascal was > always easier to read than FORTH for me. Now, I can look at a page of > Pascal code and it is still readable, but the FORTH... urgh. Forth was always unreadable to me but I never did much. I thought its aficionados were silly. Yes if you have a complicated math expression in Lisp, you have to sit there for a moment rearranging it in infix in your mind to figure out what it says. The point is that such expressions aren't all that common in typical Lisp code. Anyway, you know this song? I don't think it could have been written for Python, which is what I mean about Lisp being primordial: http://www.songworm.com/db/songworm-parody/EternalFlame.html words http://www.prometheus-music.com/audio/eternalflame.mp3 audio > But that isn't to say that the syntax of Lisp is for everybody. Far from > it -- I'd be willing to bet that Lisp developers are a self-selected group > of far above average intelligence. That would explain why so many of them > seem to be so much more comfortable with higher-order functions than most > other people -- even intelligent people. Nah, try Haskell for that. From sturlamolden at yahoo.no Mon Dec 4 21:08:48 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 4 Dec 2006 18:08:48 -0800 Subject: About alternatives to Matlab In-Reply-To: <45748f97$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <1165246753.867457.204270@79g2000cws.googlegroups.com> <45748f97$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165284528.002927.164330@16g2000cwy.googlegroups.com> Jon Harrop wrote: > So the super-fast BLAS routines are now iterating over the arrays many times > instead of once and the whole program is slower than a simple loop written > in C. Yes. And the biggest overhead is probably Python's function calls. Little is as efficient as well-written ISO C99 (not to be confused with C++ or ANSI C). The only thing I can think of is hand-written assembly. But whether a single loop is faster than several BLAS calls does not only depend on how many times the memory is traversed. It also depends a lot on cache prefetching. So I assume you make sure that the cache is prefetched and exploited optimally for your CPU in your C code? And you are presumably also inlining assembly to use SSE and other SIMD opcodes? After all, SSE can speed up floating point performance by a factor of four if the computations can be carried out in parallel. At one point, one has to stop and ask a very important question: How fast is fast enough? And how much suffering am I willing to endure to achieve that speed? Bad Fortran 95 can easily be 25% lower than well-tuned C99. But how much time was saved writing and debugging the code? I value my own time more than a few extra CPU cycles. With Fortran 95, it is easy to write numerical code that runs reasonably fast. It is only a little bit harder to write numerical code that runs very fast. There is nothing in Fortran that prevents you from writing loops that are equally fast or faster than ANSI C loops. If you have several subsequent slicing operations, a good Fortran compiler can detect that and fuse them into a single loop. Never underestimate the ability of a modern Fortran compiler to generate efficient machine code, even if array slicing is used heavily. Also never underestimate the truth in Knuth's claim that premature optimization is the root of all evil in computer programming. It is a lot smarter to write a pure Python/NumPy solution, and if its too slow, run the profiler, identify the worst bottlenecks, and translate them to Fortran. The result will probably not be as fast as a pure C solution. But if it is still too slow, money is better spent buying better hardware than attempting a major rewrite in C/C99/C++. NumPy can be slower than equivalent C by an order of magnitude. But still, that may be more than fast enough. The beauty of NumPy is really the way it allows arrays of numerical data to be created and manipulated within Python, not the speed of python code using NumPy objects. We have already seen that NumPy is faster than the most recent version of Matlab, the most expensive commercial tool on the marked; which means, it is as fast as you can expect a numerical scripting tool to be, but sure, there is still room for improvement. In a numerical scripting language it is certainly not true that several slicing operations is slower than a single big for-loop. That is due to the overhead involved when the interpreter is invoked. The performance is to a large extent determined by the amount of interpreter invocations. That is why it is preferred to "vectorize" NumPy code using slicing, repmat, reshapes, etc., rather than looping with a pythonic for-loop. Even if you have to iterate over the memory several times, array slicing will still be a lot faster than a pythonic for-loop. > Indeed, this algorithm could be written concisely using pattern matching > over linked lists. I wonder if that would be as fast as using BLAS from > Python. Pattern matching on linked lists? For wavelet transforms? Seriously? From scott.daniels at acm.org Fri Dec 8 01:05:53 2006 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 07 Dec 2006 22:05:53 -0800 Subject: funcs without () like print In-Reply-To: <1165502180.715192.195240@j72g2000cwa.googlegroups.com> References: <1165502180.715192.195240@j72g2000cwa.googlegroups.com> Message-ID: <4578f701$1@nntp0.pdx.net> iwl wrote: > Hello can I make funktions callable without () like print > at time the interpreter seems to printout the adres when I type the > function without () As everyone else has already told you, print is a statement, not a function. If you want your source code to use these "self-calling- functions," you should change your wishes. If, however, you are talking solely about the interactive prompt and ease of typing, you might want to check out ipython (find via your favorite search tool). Its flexibility may well be to your taste. --Scott David Daniels scott.daniels at acm.org From spam at spam.pl Sun Dec 17 08:42:15 2006 From: spam at spam.pl (vertigo) Date: Sun, 17 Dec 2006 14:42:15 +0100 Subject: Changing variable to integer Message-ID: Hello I receive such error: File "p4.py", line 24, in PrintWordCountFloat print "%s %f" % (word,words[word]) TypeError: list indices must be integers i call PrintWordCountFloat with hash table, keys are words(string) and values float. This part of the code: def PrintWordCountFloat(words): number = 0 for word in words: print "%s %f" % (word,words[word]) #line 24 number = number + 1 print "Total words: %d" %(number) My function displays whole table correctly, and after that i receive mentioned error. Why ? Where is the problem ? Thanx From pyenos at pyenos.org Wed Dec 27 18:32:21 2006 From: pyenos at pyenos.org (Pyenos) Date: 28 Dec 2006 10:32:21 +1100 Subject: failing to instantiate an inner class because of its order References: <87fyb16icw.fsf@pyenos.pyenos.org> Message-ID: <877iwc7w56.fsf@pyenos.pyenos.org> Pyenos writes: > class Model: > Controller() #problem > > class View: > Model() > > class Controller:pass > > > Python interpreter complains that 'Name Error: Controller()' not defined. > Following Edward Kozlowski's advice I can suggest to myself a solution: class Model:pass class View: Model() #this part is fine class Controller: def __init__(self): self.Model=Model() Controller.Model.Controller() #solution From james_w77 at yahoo.com Fri Dec 22 15:14:18 2006 From: james_w77 at yahoo.com (james_w77 at yahoo.com) Date: 22 Dec 2006 12:14:18 -0800 Subject: stoppable child thread Message-ID: <1166818458.906757.269840@i12g2000cwa.googlegroups.com> I am trying to use Peter's StoppableThread(threading.Thread). What I want to do is to start 5 child threads, then do something, then when got ^C keyboard exception, stop the child thread. For some reason (apparently strange for me :) ), the child threads can NOT be stopped. See the enclosed code for more info, Thanks and have a nice Xmas. Jimmy ============ #!/usr/bin/env python import threading, thread from time import sleep, ctime class StoppableThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self._running = True def stop(self): self._running = False def run(self): while self._running: # do stuff here that loops periodically to allow # the flag to be checked print 'start loop at:', ctime() sleep(4) def main(): threads = [] try: for i in range(5): t = StoppableThread() t.start() sleep(0.001) threads.append(t) except KeyboardInterrupt: for t in threads: t.stop() t.join() del threads[:] print 'child thread exiting...'+'/n/n' if __name__ == '__main__': main() From bdesth.quelquechose at free.quelquepart.fr Sat Dec 23 08:38:39 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 23 Dec 2006 14:38:39 +0100 Subject: Decorator for Enforcing Argument Types In-Reply-To: <1166825148.058212.58390@a3g2000cwd.googlegroups.com> References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166807792.176011.170950@h40g2000cwb.googlegroups.com> <1166819094.554972.89360@48g2000cwx.googlegroups.com> <1166825148.058212.58390@a3g2000cwd.googlegroups.com> Message-ID: <458d2b86$0$11618$426a74cc@news.free.fr> George Sakkis a ?crit : > John Machin wrote: > > >>Peter Wang wrote: >> >>>Bruno Desthuilliers wrote: >>> >>>> >>>>Python is dynamic, and fighting against the language is IMHO a really >>>>bad idea. The only places where theres a real need for this kind of >>>>stuff are when dealing with the "outside world" (IOW : inputs and >>>>outputs). And then packages like formencode can do much more than mere >>>>type-checking >>>> >>> (snip) > I have also a very recent real-world example to share, from the other > side of the fence this time. It's even worse because it's an error that > passes silently. Cut-down version follows: > > @cherrypy.expose > def retrieve(self, **kwds): > queries = kwds['q'] > rows = self._selectRows(*queries) > # more stuff > > 'q' here is a multiselect field that is binded to a list of selected > strings. Or so I thought, until someone noticed bizarre results in some > cases. Turns out that if you select a single item from the select box, > 'q' is binded to a string instead of a list of length 1, so instead of > retrieving 'apple', she got back the results for 'a', 'p', 'p', > 'l','e'. This is a typical case of converting/validating data from the "outside world" - something well covered by formencode. > Bottom line, type checking is a tricky business. Indeed. In fact, proper "type checking" would first require some agreement on what's a "type"... From cvanarsdall at mvista.com Thu Dec 14 17:25:09 2006 From: cvanarsdall at mvista.com (Carl J. Van Arsdall) Date: Thu, 14 Dec 2006 14:25:09 -0800 Subject: automatically grading small programming assignments In-Reply-To: <1166131842.963017.206130@79g2000cws.googlegroups.com> References: <1166129734.888298.210830@l12g2000cwl.googlegroups.com> <1166131842.963017.206130@79g2000cws.googlegroups.com> Message-ID: <4581CF45.1040504@mvista.com> commander.coder at hotmail.com wrote: > bearophileHUGS at lycos.com wrote: > Then on your PC you can > >> run a script that loads each of such programs, and runs a good series >> of tests, to test their quality... >> > What happens if someone-- perhaps not even someone in the class-- does > some version of os.system('rm -Rf /') ? > > The system administrator should make sure that student user accounts (or the auto testing account) doesn't have access to that. Probably should make sure that user applications only get a limited amount of memory too. -- Carl J. Van Arsdall cvanarsdall at mvista.com Build and Release MontaVista Software From Thomas.Ploch at gmx.net Wed Dec 20 13:21:06 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Wed, 20 Dec 2006 19:21:06 +0100 Subject: Does any one know of any good folder/directory modules In-Reply-To: <1166638399.367667.28410@48g2000cwx.googlegroups.com> References: <1166638399.367667.28410@48g2000cwx.googlegroups.com> Message-ID: <45897F12.7020302@gmx.net> moishyyehuda at gmail.com schrieb: > Hi > > Does any one know of any good folder/directory modules. I need to be > able to see what files and directories are in a folder, I also need to > be able to see the size of the directory content. > > Thanks > You should have a look here: http://docs.python.org/lib/os-file-dir.html#os-file-dir Thomas (This could have been done by yourself, but I am in a christmasly mood) From jonc at icicled.net Mon Dec 18 14:19:17 2006 From: jonc at icicled.net (Jonathan Curran) Date: Mon, 18 Dec 2006 13:19:17 -0600 Subject: Windows Authetication vs seperate process In-Reply-To: <1166459095.924198.62170@n67g2000cwd.googlegroups.com> References: <1166459095.924198.62170@n67g2000cwd.googlegroups.com> Message-ID: <200612181319.17383.jonc@icicled.net> On Monday 18 December 2006 10:24, imageguy1206 at gmail.com wrote: > I was wondering of someone could steer me in the right direction. > > We have a package that we would like to "secure" so that only specific > individuals can access specific portions of the application. Our > wxPython application will revolve around updating a central database > with information submitted from the app. We will eventually have a web > front end fo rsome aspects of the app. > > With several packages I have seen options to "Use Windows > Authentication", which seems to mean that "If the user has > authenticated and signed onto Windows, then our application will use > their windows userid and we will just focus on the the tasks within our > application the user is authorized to perform" > > Does anyone have any experience using this type of authentication > scheme ? > > Any related tips or suggestions ? > > I have found a few wikipedia entries, but they seem to be more related > to webpages, etc. > > Thanks. Using windows authentication IMHO should only be used if there is an Active Directory/LDAP server set up against which the users are authenticated. I googled for 'active directory python' and came across http://tgolden.sc.sabren.com/python/ad_cookbook.html It seems to be very simple to use. If I were to implement an authentication system like you want. I would: 1. Check to see if the local machine was part of a domain. If not then inform the user that they need to be. 2. Check to see if the user who ran the application is part of a specific group in AD. I would assign each group a certain 'level' of privilege and accordingly let the user do what they should be able to do. I hope this is a good starting point. - Jonathan Curran From david.stephed at googlemail.com Thu Dec 21 11:51:37 2006 From: david.stephed at googlemail.com (MiguelS) Date: 21 Dec 2006 08:51:37 -0800 Subject: Displaying contents of a file using PyWin In-Reply-To: References: <1166706266.025197.199620@79g2000cws.googlegroups.com> <1166716722.937893.297670@79g2000cws.googlegroups.com> Message-ID: <1166719897.867134.323000@80g2000cwy.googlegroups.com> Sorry, the code I posted was wrong. I tried import win32ui from pywin.mfc import docview t = docview.DocTemplate() t.OpenDocumentFile("d:/temp/music.log", True) This caused windows to close PythonWin. From gagsl-py at yahoo.com.ar Sat Dec 16 19:23:52 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 16 Dec 2006 16:23:52 -0800 Subject: Package vs. module In-Reply-To: References: <1165642541.222433.162640@l12g2000cwl.googlegroups.com> Message-ID: <1166315032.169022.179330@79g2000cws.googlegroups.com> On 16 dic, 12:28, "Stuart D. Gathman" wrote: > NOW, this is all very nice and modular. BUT, the original module was a > single file, which could be run as a script as well as imported as a > module. The script features provided useful command line functionality. > (Using if __name__ == '__main__':). Now that 'spf' is a package, the > command line feature is gone! Even using -m, I get: Yes, a little sacrifice... > Looking at getpass.py as advised, I see they put all the drivers in the > module. I could do that with spf.py, I suppose. But I like how with the > package, the driver code is not loaded unless needed. That's good. > One other idea I had was an arrangement like this: > > SPF/ > pydns.py > dnspython.py > > spf.py > > This would keep the module as a single file usable from the command line, > but still make driver available as separately loaded modules. > > So which of the three options, > > 1) single file module with all drivers, ala getpass You've already seen that it's not a good option. getpass is different in the sense that only one version should be available in a given system, so it keeps trying alternatives until a candidate is found. > 2) package that cannot be run directly from command line > 3) single file module with associated driver package I think that keeping demo/application code separate from the library would be a good thing. So, keep your library inside a package, and provide some external scripts as example, demo, whatever. You can instruct distutils to install each thing in the right place. -- Gabriel Genellina From gagsl-py at yahoo.com.ar Wed Dec 27 22:56:30 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 28 Dec 2006 00:56:30 -0300 Subject: socket.gaierror: (-2, 'Name or service not known') In-Reply-To: <1167275481.268174.168910@f1g2000cwa.googlegroups.com> References: <1167275481.268174.168910@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061228004338.05df24b0@yahoo.com.ar> At Thursday 28/12/2006 00:11, flamesrock wrote: >The problem is that, while the login opener works, the >update_city_params opener does not. It returns the following error: >flamesrock at tux ~/send $ python send.py >Traceback (most recent call last): > File "send.py", line 14, in ? > opener.open(url, update_city_params) > File "/usr/lib/python2.4/urllib2.py", line 356, in open > req = meth(req) > File "/home/flamesrock/asdf/MultipartPostHandler.py", line 75, in >http_request > boundary, data = self.multipart_encode(v_vars, v_files) > File "/home/flamesrock/asdf/MultipartPostHandler.py", line 87, in >multipart_encode > boundary = mimetools.choose_boundary() > File "/usr/lib/python2.4/mimetools.py", line 130, in choose_boundary > hostid = socket.gethostbyname(socket.gethostname()) >socket.gaierror: (-2, 'Name or service not known') MultipartPostHandler uses mimetools.choose_boundary; it relies on socket.gethostbyname returning a sensible result for your machine. But sometimes it fails: http://mail.python.org/pipermail/python-list/2003-October/232722.html It may be a bug in Python, or in the sockets implementation, or somewhere. Anyway, choose_boundary() should be robust enough to catch the possible exception and act accordingly, I think. In the meantime, you may put this near the top of your script: mimetools._prefix = "some-random-string-you-like" -- 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 From jmcmonagle at velseis.com.au Mon Dec 11 18:17:29 2006 From: jmcmonagle at velseis.com.au (John McMonagle) Date: Tue, 12 Dec 2006 09:17:29 +1000 Subject: No output from popen in Tkinter text widget In-Reply-To: References: Message-ID: <457DE709.8010805@velseis.com.au> Kevin Walzer wrote: > I'm trying to display the output of an external process (invoked via > popen) in a Tkinter text widget. I successfully start the process (based > on what I'm seeing in my terminal output), but I can't get the output to > display in the Tkinter widget. It seems to block. > > Any ideas? My code is below: > > def runDump(self): > > self.password.destroy() > > self.passtext = self.passtext.get() > > file = os.popen('echo %s | sudo -S /usr/sbin/tcpdump -v -i > en1' % self.passtext, 'r') > > for line in file: > self.t.insert(END, line) > self.t.update() -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From tech-hr at smartcharter.com Tue Dec 19 15:47:32 2006 From: tech-hr at smartcharter.com (Tech HR) Date: Tue, 19 Dec 2006 12:47:32 -0800 Subject: Lisp/Python programmers (among others) wanted Message-ID: Smart Charter Inc. is a dynamic new startup company whose goal is to revolutionize the charter jet industry. If you are looking for a stable 9-5 job, look elsewhere. If you are ready for a challenging ground-floor opportunity with significant upside potential you've come to the right place. We are not your typical dotcom. We have a razor-sharp focus on an existing multi-billion-dollar market. We also have the connections and the technical expertise we need to revolutionize an industry. If that sounds like something you'd like to be part of, drop us a line. We are currently hiring for the following positions: Web developer: We are a principally a LAMP shop with P=Python, with some of our more advanced development currently taking place using Common Lisp. We are more interested in brains and motivation than formal credentials, though a degree in CS can't hurt. But if we have to choose between a passionate high school dropout and and an apathetic Ph.D. we'll take the dropout. If your main expertise is Java you are probably not a good fit. We are currently hiring for the following positions: Windows developer: Although we are primarily a Linux shop, we have to interface with some existing Windows legacy applications whose vendors may or may not be cooperative. We need someone who is a wizard at reverse-engineering Windows applications and data file formats, and building interfaces to them by whatever means necessary. System administrator: Our production environment is currently Linux, but we also have OS X and Windows machines at the corporate office. Ideally we'd like to find someone with experience in all three environments, but if we have to choose we would prefer Linux expertise over the other two. Senior applications developer: Our advanced applications work is currently being done in Common Lisp, but that could change depending on who we find to fill this position. If you are the sort of person who has always wanted an opportunity to prove that Haskell or OCaml is the Best Way to write software, this could be your chance. But CL is currently our first choice. These four positions do not necessarily have to be filled by four distinct people. A breadth of experience and expertise is highly desirable. A passion for flying wouldn't hurt either. Smart Charter is located in the Los Angeles area. Telecommuting is a possibility, but would not be our first choice. Contact us at tech-hr at smartcharter dot com. From klaus at seistrup.dk Fri Dec 1 00:03:28 2006 From: klaus at seistrup.dk (Klaus Alexander Seistrup) Date: Fri, 1 Dec 2006 05:03:28 +0000 (UTC) Subject: UTF8 & HTMLParser References: <456faf5e$1@griseus.its.uu.se> Message-ID: Jan Danielsson wrote: > However, I would like to convert the "text" (which is utf8) > to latin-1. How do I do that? How about: latin = unicode(text, 'utf-8').encode('iso-8859-1') Please see help(u''.encode) for details about error handling. You might also want to trap errors in a try-except statement. Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ From pydecker at gmail.com Mon Dec 18 17:33:33 2006 From: pydecker at gmail.com (Peter Decker) Date: Mon, 18 Dec 2006 17:33:33 -0500 Subject: Good Looking UI for a stand alone application In-Reply-To: <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> Message-ID: On 12/18/06, Luc Heinrich wrote: > > You're full of it. I routinely write GUI apps in Dabo for both Windows > > and Linux users, and they look just fine on both platforms. > > Oh, I'm sure you do. Now go try to run one of your Dabo apps on a Mac > and see how it looks/feels... :> I don't have a Mac, although I would certainly like one. But one of the two authors of Dabo is a Mac user, and says that he does all his development on a Mac, and then tests it on the other platforms. Look at the screencasts on the Dabo site - most of them are recorded on OS X. > Here's a hint directly taken from the Dabo homepage: "It also suffers > from the same display limitations on some platforms (most notably OS X), > but these should improve as the underlying toolkits improve." OK, it's true: you don't have 100% access to the lickable Aqua stuff that a Cocoa app might be able to use. But paged controls use native Aqua tabs; progress bars are native Aqua bars, buttons are native Aqua buttons... Perfect? Of course not. But stating that it sucks is a load of crap. > > Using sizers is the key; layouts just 'look right' no matter what the native > > fonts and control sizes are. > > No, sizers are a tiny part of a much bigger problem. Sizers might be the > key to solve parts of the "look" problem, they don't address any of the > "feel" problem. Huh? Based on what I've seen on the screencasts, the apps look better on the Mac than they do on XP. How should I judge how they "feel"? SIzers automatically take care of font metric differences and native control size differences. > But you clearly have a point here, so let me rephrase: "Crossplatform > toolkits/frameworks suck. All of them. No exception. UNLESS you only > target the lowest common denominator, aka Windows and its Linux > followers". > > Now, the OP *explicitely* said that "[his] requirement is that the > application needs to look as good on Windows as on the Apple Mac", so > the rephrasing does not apply in this case. So here's a last try: Well, I don't think *anything* looks as good on Windows as it does on a Mac, whether it is from a platform-specific toolkit such as Winforms or a cross-platform toolkit like wxPython. If you want it to look as good on Windows, you'll have to use VNC or something like that. > "Crossplatform toolkits/frameworks suck. All of them. No exception. > ESPECIALLY if one of your target is Mac OS". Such self-important pronouncements would be better received if you brought them down the mountain on stone tablets. -- # p.d. From larry.bates at websafe.com Fri Dec 29 09:20:22 2006 From: larry.bates at websafe.com (Larry Bates) Date: Fri, 29 Dec 2006 08:20:22 -0600 Subject: I want to see all the variables In-Reply-To: References: Message-ID: <45952426.1080800@websafe.com> johnf wrote: > Hi, > When I use dir() I don't see the __ underscore items. Is there anything > that will show all the private vars and functions? > > johnf The idea of the underscore items is that they aren't to be used by you. If you wish to access private variables and functions you will almost certainly have to look at the source code to make sure of what they are and how they can be utilized. -Larry From pavlovevidence at gmail.com Wed Dec 20 21:17:07 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 20 Dec 2006 18:17:07 -0800 Subject: what is wrong with my code? In-Reply-To: <87vek65cne.fsf@pyenos.pyenos.org> References: <874prq6wmd.fsf@pyenos.pyenos.org> <87vek65cne.fsf@pyenos.pyenos.org> Message-ID: <1166667427.238372.150240@t46g2000cwa.googlegroups.com> Pyenos wrote: > "Calvin Spealman" writes: > > On 21 Dec 2006 09:16:58 +1100, Pyenos wrote: > > > import cPickle, shelve > > > > > > could someone tell me what things are wrong with my code? > > > > > > class progress: > > > > > > PROGRESS_TABLE_ACTIONS=["new","remove","modify"] > > > DEFAULT_PROGRESS_DATA_FILE="progress_data" > > > PROGRESS_OUTCOMES=["pass", "fail"] > > > > > > > > > def unpickleProgressTable(pickled_progress_data_file): > > > > > > return unpickled_progress_table > > > > > > def pickleProgressTable(progress_table_to_pickle): > > > > > > return pickled_progress_data_file > > > > > > # Of course, you get progress_table is unpickled progress table. > > > def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]): > > > pid_column_list=progress_table[0] > > > task_column_list=progress_table[1] > > > outcome_column_list=progress_table[2] > > > > > > # But a task must also come with an outcome! > > > def newEntry(new_task, new_outcome): > > > new_pid=len(task_column_list) > > > > > > pid_column_list.extend(new_pid) > > > task_column_list.extend(new_task) > > > outcome_column_list.extend(new_outcome) > > > > > > def removeEntry(pid_to_remove, task_to_remove): > > > > > > if pid_column_list.index(pid_to_remove)==task_column_list.index(task_to_remove): > > > # Must remove all columns for that task > > > index_for_removal=pid_column_list.index(pid_to_remove) > > > > > > pid_column_list.remove(index_for_removal) > > > task_column_list.remove(index_for_removal) > > > outcome_column_list.remove(index_for_removal) > > > > > > # Default action is to modify to pass > > > def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]): > > > index_for_modifying=pid_column_list.index(pid_to_modify) > > > > > > # Modify the outcome > > > outcome_column_list[index_for_modifying]=outcome_to_modify > > > > It is hard to determine what is wrong with your code without you > > telling anyone why it is you believe something is wrong with it. Did > > you get an exception? Did it simply not do what it was expected to do? > > There seems to be some apparent indenting problems, but maybe that is > > just from pushing it through the e-mail. I see some general stylistic > > problems as well, but without know what you are actually asking, I > > won't know what questions to answer. "What is wrong with my code?" is > > a container of many many smaller questions, and you need to focus your > > questions better. > > it says that progress_table is not defined. i don't know why. It looks like you have bigger problems than an undefined variable. Python does not have implicit access to methods and attributes (members) like C++ and Java do. Methods must accept an explicit self parameter that refers to the object (analogous to this in C++ and Java) to access attributes. Your code defines a class, but self is nowhere to be found. I suggest getting a good book and/or reading the tutorial (http://docs.python.org/tut/) and making sure you can do easy stuff first. Carl Banks From jon at ffconsultancy.com Sun Dec 10 03:43:47 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 08:43:47 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <1165731005.529088.227360@j44g2000cwa.googlegroups.com> Message-ID: <457bc963$0$8747$ed2619ec@ptn-nntp-reader02.plus.net> Wolfram Fenske wrote: > Sure, you can shoot yourself in the foot with macros. But you can do > that in any language of any degree of expressiveness [3]. Come to > think of it, the whole reason why we use high level languages is > because of their expressiveness: We get stuff done faster and > introduce less errors. So "the more expressive, the better," right? > But according to you, there's a point when a language gets "too > expressive". I don't see why. Is Qi Lisp? There are several problems: 1. Language design is so hard that most people get it wrong (e.g. Python). What do you do when you find that your proprietary syntax extension was a bad idea? 2. There is a trade-off between being expressive and sacrificing syntax. Lisp is very verbose because you must write the AST for your code by hand, even if you aren't exploiting s-exprs, EVAL and macros. 3. One could argue that every syntax extension in Lisp makes a new language. So Lisp is a heavily forked language. Is that a good? Maybe if you're a lone coder and an expert in language design then you can knock up a DSL and halve your working time using Lisp. In industry, you're more likely to hire four people with half the expertise each and restrict them to a well-known C-like syntax. >> Now, if Lispers would say "Oh yes, macros give you great power, and >> with great power comes great responsibility. Be careful." then, no >> doubt, we'd take you guys more seriously. > > Sure, it's a powerful tool but it's not *that* hard to use. Look at all the threads in c.l.l where people have gotten confused by their own macros. Look at the unboxing macro that Juho Snellman used to try to get competitive performance for Lisp on my ray tracer benchmark: (defmacro def ((name params &body body) (mname &rest mparams) (wname &rest wparams)) `(progn (declaim (inline ,name ,wname)) (defun ,name ,params (declare (type double-float , at params)) , at body) (defmacro ,mname ,(mapcar #'car mparams) ,(loop with inner = (list name) with body = ``,',inner with all-names = nil for (form count) in (reverse mparams) for names = (loop repeat count collect (gensym)) do (setf all-names (append all-names names)) (setf body ``(multiple-value-bind ,',(reverse names) ,,form ,,body)) finally (setf (cdr inner) (reverse all-names)) (return body))) (defun ,wname ,(mapcar #'car wparams) (,mname ,@(mapcar #'cadr wparams))))) Note that this page of magic does something done by the compiler in most other languages. > Maybe you're afraid of it because that it's something that's unique to > Lisp? It isn't unique to Lisp. OCaml has camlp4, for example. It is very rarely used, perhaps because the OCaml community is wary of syntax extensions or perhaps because it is even harder to use than Lisp's macros. > But IMO the reason for that is not that they're too powerful. IMO it > has mostly to do with the fact that other languages' syntaxes make it > too difficult to implement Lisp-style macros. I agree. However, the fact that other languages ship with sophisticated syntax can also be a good thing: it can make them more concise, it can make them more expressive (e.g. pattern matching). I get the impression that Lispers use macros when they could use HOFs. >> But we don't hear that -- we hear Lispers going on and on about how >> great it is that they can easily redefine every corner of the >> language. Do you blame people for *believing them* and imagining >> that reading Lisp code is like following some ghostly >> will-o-the-wisp across a swamp, where nothing is what it seems and >> the landscape is forever shifting? > > Come on! You're telling me people don't learn Lisp because they are > afraid of it? Python allows you to redefine built-in functions, as > you said, Ruby allows you to attach new methods to live objects, but > Lisp is simply going too far? The biggest activation barrier to using Lisp for me is having to write ASTs for everything by hand. Perhaps it would be a good idea to include an editor that allowed newbies to use a more familiar syntax and have it converted to s-exprs for them, so they can see the correspondence and learn how to write s-exprs themselves? >> Now, if you want to tell me that, despite all the talk, Lisp coders >> don't actually create new syntax or mini-languages all that often, >> that they just use macros as functions, then the question becomes: >> why do you need macros then if you are just using them as functions? >> Why not use functions? > > Easy because macros are not functions. Functions allow you abstract > functionality, macros allow you abstract syntax. While that is true, you've provided two examples to back up his point. In another post you use the example of wrapping try .. finally which can be done with a HOF instead of a macro. Next, you use the example of COND, which can also be written as a HOF instead of as a macro: > Look at the examples > above. How would you implement conditional expressions as a function? > Answer: You can't, it's syntax. That is not true. You can implement conditional expressions without extending the syntax: # let rec cond x rules default = match rules with | [] -> default | (f, e) :: _ when f(x) -> e | _ :: t -> cond x t default;; val cond : 'a -> (('a -> bool) * 'b) list -> 'b -> 'b = For example: # cond 2 [( = ) 1, "one"; ( = ) 2, "two"; ( = ) 3, "three"] "neither one, two nor three";; - : string = "two" Of course, this is pointless in OCaml because the built-in pattern matcher is more expressive, powerful and faster than COND: # match 2 with | 1 -> "one" | 2 -> "two" | 3 -> "three" | _ -> "neither one, two nor three";; - : string = "two" -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From rampeters at gmail.com Mon Dec 4 19:08:44 2006 From: rampeters at gmail.com (johnny) Date: 4 Dec 2006 16:08:44 -0800 Subject: Multiple FTP download using Muliti thread In-Reply-To: <1165226193.934418.36660@l12g2000cwl.googlegroups.com> References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> Message-ID: <1165277324.677203.107650@l12g2000cwl.googlegroups.com> When I run the following script, with host and password and username changed, I get the following errors: raise error_temp, resp error_temp: 421 Unable to set up secure anonymous FTP Dose the host should allow 4 simultaneous login at a time? Justin Ezequiel wrote: > import ftplib, posixpath, threading > from TaskQueue import TaskQueue > > def worker(tq): > while True: > host, e = tq.get() > > c = ftplib.FTP(host) > c.connect() > try: > c.login() > p = posixpath.basename(e) > fp = open(p, 'wb') > try: c.retrbinary('RETR %s' % e, fp.write) > finally: fp.close() > finally: c.close() > > tq.task_done() > > if __name__ == '__main__': > q = TaskQueue() > host = 'ftp.microsoft.com' > > c = ftplib.FTP(host) > c.connect() > try: > c.login() > folder = '/deskapps/kids/' > for n in c.nlst(folder): > if n.lower().endswith('.exe'): > q.put((host, n)) > finally: c.close() > > numworkers = 4 > for i in range(numworkers): > t = threading.Thread(target=worker, args=(q,)) > t.setDaemon(True) > t.start() > > q.join() > print 'Done.' From george.sakkis at gmail.com Fri Dec 1 10:07:06 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 1 Dec 2006 07:07:06 -0800 Subject: More elegant to get a name: o.__class__.__name__ References: <1164896740.696013.5390@j72g2000cwa.googlegroups.com> Message-ID: <1164985626.204989.124410@73g2000cwn.googlegroups.com> Carl Banks wrote: > alf wrote: > > Hi, > > is there a more elegant way to get o.__class__.__name__. For instance I > > would imagine name(o). > > def name_of_type(o): > return o.__class__.__name__ > > name_of_type(o) > > > Carl Banks > > P.S. name(o) suggests it's the name of the object, not the type > P.P.S. you could use type(o).__name__ but it doesn't work for old-style > classes You mean it doesn't work for old-style instances; OTOH __class__ doesn't work for old style classes: >>> class X: pass ... >>> X.__class__ AttributeError: class X has no attribute '__class__' So to handle all cases, you'd have to go with: def typename(o): try: cls = o.__class__ except AttributeError: cls = type(o) return cls.__name__ # or for fully qualified names # return '%s.%s' % (cls.__module__, cls.__name__) George From ptmcg at austin.rr._bogus_.com Mon Dec 4 18:36:12 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 04 Dec 2006 23:36:12 GMT Subject: Execution time of lines within a function References: <1165240166.203915.115460@n67g2000cwd.googlegroups.com> Message-ID: "monkeyboy" wrote in message news:1165240166.203915.115460 at n67g2000cwd.googlegroups.com... > Hello, > > I have a function that hotshot says is very slow. I can get the > aggregate execution time, but is there a way to get the execution time > of each line so I can find the bottleneck? > > Thank you > The PythonDecoratorLibrary page on the Python wiki has a link to a @profile decorator, that I have used to profile the contents of targeted functions (only just now, I don't seem to be able to get to the wiki to get the exact link). -- Paul From triska at gmx.at Tue Dec 12 21:56:54 2006 From: triska at gmx.at (Markus Triska) Date: Wed, 13 Dec 2006 03:56:54 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7x3b7lccjn.fsf@ruckus.brouhaha.com> Message-ID: <87r6v4cxl5.fsf@gmx.at> Ken Tilton writes: > I think all-rules-all-the-time Prolog is the poster boy for paradigm > slavery. (I did try for a famous two months to use Prolog as a > general-purpose programming language.) Don't expect to learn Prolog properly in so little time. To your previous question whether the ~180 lines of Lisp code in some online book constitute an "industrial strength" Prolog: only if the following ~180 lines of Prolog code implement an "industrial strength" Lisp. ws --> [W], { W =< 0' }, ws. ws --> []. open_paren --> ws, "(", ws. close_paren --> ws, ")", ws. parse(String, Expr) :- phrase(expressions(Expr), String). list(Es) --> open_paren, expressions(Es), close_paren. expressions([E|Es]) --> expression(E), ws, !, % single solution: longest input match expressions(Es). expressions([]) --> []. expression(symbol(A)) --> symbol(A0), { name(A, A0) }. expression(number(N)) --> number(N0), { name(N, N0) }. expression(List) --> list(List). expression([symbol(quote),Q]) --> "'", expression(Q). number([D|Ds]) --> digit(D), number(Ds). number([D]) --> digit(D). digit(D) --> [D], {0'0 =< D, D =< 0'9 }. symbol([A|As]) --> [A], { memberchk(A, "+/-*><=abcdefghijklmnopqrstuvwxyz") }, symbolr(As). symbolr([A|As]) --> [A], { memberchk(A, "+/-*><=abcdefghijklmnopqrstuvwxyz0123456789") }, symbolr(As). symbolr([]) --> []. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Interpretation -------------- Declaratively, execution of a Lisp form establishes a relation between the (function and variable) binding environment before its execution and the environment after its execution. A Lisp program is a sequence of Lisp forms, and its result is the sequence of their results. Initially, the environment is empty. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ run(Program, Values) :- parse(Program, Forms0), empty_assoc(E), compile_all(Forms0, Forms), eval_all(Forms, E, _, E, _, Values). fold([], _, V, V). fold([F|Fs], Op, V0, V) :- E =.. [Op,V0,F], V1 is E, fold(Fs, Op, V1, V). compile_all(Fs0, Fs) :- maplist(compile, Fs0, Fs). /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - compile/2 marks (with "user/1") calls of user-defined functions. This eliminates an otherwise defaulty representation of function calls and thus allows for first argument indexing in eval/7. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ compile(F0, F) :- ( F0 = number(_) -> F = F0 ; F0 = symbol(t) -> F = t ; F0 = symbol(nil) -> F = nil ; F0 = symbol(_) -> F = F0 ; F0 = [] -> F = [] ; F0 = [symbol(quote)|Args] -> F = [quote|Args] ; F0 = [symbol(setq),symbol(Var),Val0] -> compile(Val0, Val), F = [setq,Var,Val] ; F0 = [symbol(Op)|Args0], memberchk(Op, [+,-,*,equal,if,>,<,=,progn,eval,list,car,cons, cdr,while,not]) -> compile_all(Args0, Args), F = [Op|Args] ; F0 = [symbol(defun),symbol(Name),Args0|Body0] -> compile_all(Body0, Body), maplist(un_symbol, Args0, Args), F = [defun,Name,Args|Body] ; F0 = [symbol(Op)|Args0] -> compile_all(Args0, Args), F = [user(Op)|Args] ). un_symbol(symbol(S), S). eval_all([], Fs, Fs, Vs, Vs, []). eval_all([A|As], Fs0, Fs, Vs0, Vs, [B|Bs]) :- eval(A, Fs0, Fs1, Vs0, Vs1, B), eval_all(As, Fs1, Fs, Vs1, Vs, Bs). eval(number(N), Fs, Fs, Vs, Vs, N). eval(t, Fs, Fs, Vs, Vs, t). eval(nil, Fs, Fs, Vs, Vs, nil). eval(symbol(A), Fs, Fs, Vs, Vs, V) :- get_assoc(A, Vs, V). % variable lookup eval([L|Ls], Fs0, Fs, Vs0, Vs, Value) :- eval(L, Ls, Fs0, Fs, Vs0, Vs, Value). eval(+, Args0, Fs0, Fs, Vs0, Vs, Value) :- eval_all(Args0, Fs0, Fs, Vs0, Vs, Args), fold(Args, (+), 0, Value). eval(-, [V0|Rest], Fs0, Fs, Vs0, Vs, Value) :- eval(V0, Fs0, Fs1, Vs0, Vs1, V1), eval_all(Rest, Fs1, Fs, Vs1, Vs, Vals), fold(Vals, (-), V1, Value). eval(*, Args0, Fs0, Fs, Vs0, Vs, Value) :- eval_all(Args0, Fs0, Fs, Vs0, Vs, Args), fold(Args, (*), 1, Value). eval(equal, [A0,B0], Fs0, Fs, Vs0, Vs, Value) :- eval(A0, Fs0, Fs1, Vs0, Vs1, A), eval(B0, Fs1, Fs, Vs1, Vs, B), ( A == B -> Value = t ; Value = nil ). eval(if, [Cond,Then|Else], Fs0, Fs, Vs0, Vs, Value) :- eval(Cond, Fs0, Fs1, Vs0, Vs1, V), ( V = nil -> eval_all(Else, Fs1, Fs, Vs1, Vs, Values), last(Values, Value) ; eval(Then, Fs1, Fs, Vs1, Vs, Value) ). eval(not, [Arg], Fs0, Fs, Vs0, Vs, Value) :- eval(Arg, Fs0, Fs, Vs0, Vs, V), ( V == nil -> Value = t ; Value = nil ). eval(>, [Arg1,Arg2], Fs0, Fs, Vs0, Vs, Value) :- eval(Arg1, Fs0, Fs1, Vs0, Vs1, V1), eval(Arg2, Fs1, Fs, Vs1, Vs, V2), ( V1 > V2 -> Value = t ; Value = nil ). eval(<, [Arg1,Arg2], Fs0, Fs, Vs0, Vs, Value) :- eval(Arg1, Fs0, Fs1, Vs0, Vs1, V1), eval(Arg2, Fs1, Fs, Vs1, Vs, V2), ( V1 < V2 -> Value = t ; Value = nil ). eval(=, [Arg1,Arg2], Fs0, Fs, Vs0, Vs, Value) :- eval(Arg1, Fs0, Fs1, Vs0, Vs1, V1), eval(Arg2, Fs1, Fs, Vs1, Vs, V2), ( V1 =:= V2 -> Value = t ; Value = nil ). eval(progn, Ps, Fs0, Fs, Vs0, Vs, Value) :- eval_all(Ps, Fs0, Fs, Vs0, Vs, Values), last(Values, Value). eval(eval, [Form0], Fs0, Fs, Vs0, Vs, V) :- eval(Form0, Fs0, Fs1, Vs0, Vs1, Form1), compile(Form1, Form2), eval(Form2, Fs1, Fs, Vs1, Vs, V). eval(quote, [Q], Fs, Fs, Vs, Vs, Q). eval(setq, [Var,V0], Fs0, Fs, Vs0, Vs, V) :- eval(V0, Fs0, Fs, Vs0, Vs1, V), put_assoc(Var, Vs1, V, Vs). eval(defun, [Func,Args|Body], Fs0, Fs, Vs, Vs, Func) :- put_assoc(Func, Fs0, Args-Body, Fs). eval(list, Ls0, Fs0, Fs, Vs0, Vs, Ls) :- eval_all(Ls0, Fs0, Fs, Vs0, Vs, Ls). eval(cons, [Car0,Cdr0], Fs0, Fs, Vs0, Vs, [Car|Cdr]) :- eval(Car0, Fs0, Fs1, Vs0, Vs1, Car), eval(Cdr0, Fs1, Fs, Vs1, Vs, Cdr). eval(car, [Ls0], Fs0, Fs, Vs0, Vs, Car) :- eval(Ls0, Fs0, Fs, Vs0, Vs, [Car|_]). eval(cdr, [Ls0], Fs0, Fs, Vs0, Vs, Cdr) :- eval(Ls0, Fs0, Fs, Vs0, Vs, [_|Cdr]). eval(while, [Cond|Body], Fs0, Fs, Vs0, Vs, Value) :- eval(Cond, Fs0, Fs1, Vs0, Vs1, V), ( V == nil -> Value = nil, Fs = Fs0, Vs = Vs0 ; eval_all(Body, Fs1, Fs2, Vs1, Vs2, _), eval(while, [Cond|Body], Fs2, Fs, Vs2, Vs, Value) ). eval(user(F), Args0, Fs0, Fs, Vs0, Vs, Value) :- eval_all(Args0, Fs0, Fs, Vs0, Vs, Args), get_assoc(F, Fs, As-Body), empty_assoc(E), bind_arguments(As, Args, E, Bindings), eval_all(Body, Fs, _, Bindings, _, Results), last(Results, Value). bind_arguments([], [], Bs, Bs). bind_arguments([A|As], [V|Vs], Bs0, Bs) :- put_assoc(A, Bs0, V, Bs1), bind_arguments(As, Vs, Bs1, Bs). They give you a simple Lisp and, in contrast to some online books claiming to give you "Prolog" (an ISO-standardised language) and then failing to even parse a single proper Prolog term, also let you write it in its natural form. Example queries tested with SWI Prolog: "append": ?- run("(defun append (x y) (if (equal x '()) y (cons (car x) (append (cdr x) y)))) (append '(1 2 3) '(4 5))", V). ==> V = [append, [number(1), number(2), number(3), number(4), number(5)]] ; Fibonacci, naive version: ?- time(run("(defun fib (n) (if (= 0 n) 0 (if (= 1 n) 1 (+ (fib (- n 1)) (fib (- n 2)))))) (fib 24)", V)). ==> V = [fib, 46368] ; 9,567,271 inferences, 3.42 CPU in 3.50 seconds (98% CPU, 2797448 Lips) Different version: ?- time(run("(defun fib (n) (if (= 0 n) 0 (fib1 0 1 1 n))) (defun fib1 (f1 f2 i to) (if (= i to) f2 (fib1 f2 (+ f1 f2) (+ i 1) to))) (fib 100)", V)). ==> 16,275 inferences, 0.01 CPU in 0.01 seconds (163% CPU, 1627500 Lips) V = [fib, fib1, 354224848179261915075] ; Using a while loop: ?- time((run("(defun fib (n) (setq f (cons 0 1)) (setq i 0) (while (< i n) (setq f (cons (cdr f) (+ (car f) (cdr f)))) (setq i (+ i 1))) (car f)) (fib 200)", V))). ==> 20,509 inferences, 0.02 CPU in 0.01 seconds (239% CPU, 1025450 Lips) V = [fib, 280571172992510140037611932413038677189525] ; Showing "eval" and "map": ?- run("(defun map (f xs) (if (equal xs '()) '() (cons (eval (list f (car xs))) (map f (cdr xs))))) (defun plus1 (x) (+ 1 x)) (map 'plus1 '(1 2 3))", Vs). ==> Vs = [map, plus1, [2, 3, 4]] ; Prolog's analogon to Lisp's macros is term_expansion/2 by the way. All the best! Markus Triska From surekap at gmail.com Thu Dec 14 18:25:57 2006 From: surekap at gmail.com (Prateek) Date: 14 Dec 2006 15:25:57 -0800 Subject: How can I get involved In-Reply-To: References: <1165856767.477175.276380@80g2000cwy.googlegroups.com> <1165867719.421812.101400@l12g2000cwl.googlegroups.com> Message-ID: <1166138757.227242.167000@t46g2000cwa.googlegroups.com> Hey all, As promised, I'm releasing v0.1 of JUnpickler - an unpickler for Python pickle data (currently Protocol 2 only) for Java. http://code.brainwavelive.com/unpickler Do check it out and let me have your comments. Prateek Sureka Fredrik Lundh wrote: > Paul Boddie wrote: > > > I find it interesting that you've been using Python for so long and yet > > haven't posted to this group before. > > c.l.python is just a small speck at the outer parts of the python > universe. most python programmers don't even read this newsgroup, > except, perhaps, when they stumble upon it via a search engine. > > From aboudouvas at panafonet.gr Mon Dec 4 14:10:28 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 4 Dec 2006 11:10:28 -0800 Subject: decorators question In-Reply-To: References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> Message-ID: <1165259428.106492.44020@16g2000cwy.googlegroups.com> > def func(): > pass > > is *exactly* the same thing as: > > def func(): > pass > func = decorator(func) Yes, i know that but i thought that it is so when I call the function, not when the runtime just loads the module... >Python calls the decorator, not the decorated function. Hmmm...ok...it calls the decorator but when ?? It (the runtime) loads the .py file and start to call every decorator it finds on it, regardless of the existance of code that actually calls the decorated functions ?? I understand thet Python does not call the decoratated functiond but it ends up this way... > > additional reading: > > http://www.python.org/doc/2.4.4/whatsnew/node6.html > http://www.python.org/dev/peps/pep-0318 > > and the relevant chapters in the tutorial and the language reference. > I will have a lokk also thera, thanks! > From pavlovevidence at gmail.com Fri Dec 22 20:51:55 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 22 Dec 2006 17:51:55 -0800 Subject: One module per class, bad idea? In-Reply-To: <1166829929.511423.110970@h40g2000cwb.googlegroups.com> References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> <458c489c$1@nntp.zianet.com> <1166823140.827296.92960@h40g2000cwb.googlegroups.com> <1166829929.511423.110970@h40g2000cwb.googlegroups.com> Message-ID: <1166838715.321441.20470@i12g2000cwa.googlegroups.com> Paddy wrote: > Carl Banks wrote: > > Erik Johnson wrote: > > > The file has now grown into a 6800 line beast (including docstring, > > > whitespace, and CVS history). Pretty much any time we implement some new > > > functionality, there are at least a few changes in that file. When you have > > > multiple developers working on different projects, and they all need to be > > > making changes to that file, the chances for someone making a merge error > > > goes up. So, we are obviously at a point where that file needs to be split > > > up, but there are lots of other files that import and use the one file, so > > > it is a task that has been put off. In retrospect, I wish I has started > > > things under a one class per file strategy, but at the time, it didn't make > > > a lot of sense to split those things up and I didn't anticipate the code > > > getting that big. > > > > Refactor NOW. > > Are there tools out their to help with the refactoring task of > splitting a module into two or more sections then showing what other > files need to change? I don't know what spiffy tools there are. If all I'm doing is moving a class from one module to another, then a simple interactive search and replace suffices for me; I modify import lines by hand. Carl Banks From kofnarson at gmail.com Sat Dec 2 03:23:58 2006 From: kofnarson at gmail.com (Karl Kofnarson) Date: Sat, 02 Dec 2006 09:23:58 +0100 Subject: What are python closures realy like? References: Message-ID: > Karl, > > Usually when using this idiom, fun_basket would return a tuple of all of the > defined functions, rather than one vs. the other. So in place of: >> if f == 1: >> return f1 >> if f == 2: >> return f2 > Just do >> return f1, f2 > (For that matter, the argument f is no longer needed either.) > > Then your caller will get 2 functions, who share a common var. You don't > call fun_basket any more, you've already created your two "closures". Call > fun_basket using something like: > > z1,z2 = fun_basket(None) > > And then call z1() and z2() at your leisure - they should have the desired > behavior. > > -- Paul Thanks a lot Paul and for the other answers. The things are now clear to me. In fact, in the Lisp example that I mentioned, you get a list (or let it be association list) of the internal functions. Then you can call them separately and they work as you expect but it's due to the fact only that you got them created at the same time. From mike.klaas at gmail.com Sat Dec 2 18:39:45 2006 From: mike.klaas at gmail.com (Klaas) Date: 2 Dec 2006 15:39:45 -0800 Subject: Possible to assure no "cyclic"/"uncollectible" memory leaks? In-Reply-To: References: Message-ID: <1165102785.621754.70760@f1g2000cwa.googlegroups.com> Joe Peterson wrote: > I've been doing a lot of searching on the topic of one of Python's more > disturbing issues (at least to me): the fact that if a __del__ finalizer > is defined and a cyclic (circular) reference is made, the garbage > collector cannot clean it up. It is a somewhat fundamental limitation of GCs, if you want to support: 1. __del__ that can resurrect objects and is deterministically called when objects are destroyed 2. the "view" of alive objects by __del__ methods is consistent 3. no crashing If there is a cycle of objects containing __del__ methods, there is clearly no way of knowing a safe order of invoking them. > First of all, it seems that it's best to avoid using __del__. So far, I > have never used it in my Python programming. So I am safe there. Or am > I? Also, to my knowledge, I have never created a cyclic reference, but > we do not typically create bugs intentionally either (and there are > certainly times when it is an OK thing to do). It is good practice to avoid __del__ unless there is a compelling reason to do so. weakref resource management is much safer. Note that it is pretty much impossible to avoid creating reference cycles--they have a tendency to sneak into unsuspecting places (for instance, bound methods can be a subtle source of cycles). > Still, it's not comforting to know that it is possible to create a > situation that would create a memory leak using a language that is > supposed to relieve us of that worry. I understand the problem, but it > would be nice to know that as a programmer, I could be assured that > Python would always deal with memory management and that memory leaks > were not something I had to think about. It is unrealistic to ever be completely relieved of such worry, since it is always possible to accidently hold on to a strong reference to data that should actually be "garbage". But your question is perhaps precluding these kinds of memory leak. In that case, it is a matter of providing to the programmer sufficiently-fine-grained abstractions such that the compiler can reason about their safety. For instance, an included weakref-based resource cleanup scheme has been discussed and would cover many of the current uses of __del__. It would also be nice to remove some of the hidden "gotchas" that are inherent in CPython, like the integer and float object freelist (not necessarily removing those features, but providing some mechanism for reclaiming them when they get out of hand). These things can reduce the possibility of a problem, but (IMO) can never completely obviate it. > So here's a question: if I write Python software and never use __del__, > can I guarantee that there is no way to create a memory leak? What > about system libraries - do any of them use __del__, and if so, are they > written in such a way that it is not possible to create a cyclic reference? It is always possible to create a cyclic reference by monkeypatching a class. Here are the stdlib modules which use __del__: $ find -name \*.py | xargs grep __del__ | grep -v test ./Mac/Demo/sound/morselib.py: def __del__(self): ./Lib/telnetlib.py: def __del__(self): ./Lib/plat-mac/EasyDialogs.py: def __del__(self): ./Lib/plat-mac/FrameWork.py: def __del__(self): ./Lib/plat-mac/MiniAEFrame.py: def __del__(self): ./Lib/plat-mac/Audio_mac.py: def __del__(self): ./Lib/plat-mac/videoreader.py: def __del__(self): ./Lib/fileinput.py: def __del__(self): ./Lib/subprocess.py: def __del__(self): ./Lib/gzip.py: def __del__(self): ./Lib/wave.py: def __del__(self): ./Lib/wave.py: def __del__(self): ./Lib/popen2.py: def __del__(self): ./Lib/lib-tk/Tkdnd.py: def __del__(self): ./Lib/lib-tk/tkFont.py: def __del__(self): ./Lib/lib-tk/Tkinter.py: def __del__(self): ./Lib/lib-tk/Tkinter.py: def __del__(self): ./Lib/urllib.py: def __del__(self): ./Lib/tempfile.py: # __del__ is called. ./Lib/tempfile.py: def __del__(self): ./Lib/tarfile.py: def __del__(self): ./Lib/socket.py: def __del__(self): ./Lib/zipfile.py: fp = None # Set here since __del__ checks it ./Lib/zipfile.py: def __del__(self): ./Lib/httplib.py: def __del__(self): ./Lib/bsddb/dbshelve.py: def __del__(self): ./Lib/bsddb/dbshelve.py: def __del__(self): ./Lib/bsddb/__init__.py: def __del__(self): ./Lib/bsddb/dbtables.py: def __del__(self): ./Lib/idlelib/MultiCall.py: def __del__(self): ./Lib/idlelib/MultiCall.py: def __del__(self): ./Lib/idlelib/MultiCall.py: def __del__(self): ./Lib/sunau.py: def __del__(self): ./Lib/sunau.py: def __del__(self): ./Lib/poplib.py: #__del__ = quit ./Lib/_threading_local.py: def __del__(self): ./Lib/aifc.py: def __del__(self): ./Lib/dumbdbm.py: # gets called. One place _commit() gets called is from __del__(), ./Lib/dumbdbm.py: # be called from __del__(). Therefore we must never reference a ./Lib/dumbdbm.py: __del__ = close ./Lib/wsgiref/validate.py: def __del__(self): ./Lib/shelve.py: def __del__(self): ./Lib/cgi.py: terminates, try defining a __del__ method in a derived class ./Lib/platform.py: __del__ = close ./Lib/audiodev.py: def __del__(self): ./Lib/audiodev.py: def __del__(self): -Mike From greg at cosc.canterbury.ac.nz Thu Dec 14 16:25:50 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 15 Dec 2006 10:25:50 +1300 Subject: Multiple inheritance and __slots__ In-Reply-To: References: <1166102613.814641.109490@80g2000cwy.googlegroups.com> Message-ID: <4udttrF17pofrU1@mid.individual.net> Simon Brunning wrote: > Difficulty with subclassing is the price you pay for abusing slots. Although you could have the same difficulty even if you weren't abusing them. It's just a limitation of the implementation. The use of __slots__ forces a particular layout im memory, and you can only do that for one base class at a time. -- Greg From jonc at icicled.net Mon Dec 18 13:26:25 2006 From: jonc at icicled.net (Jonathan Curran) Date: Mon, 18 Dec 2006 12:26:25 -0600 Subject: connecting webservers through HTTP port using python In-Reply-To: <86a272920612180428p49c89c43wf19fa5e9dccb15f6@mail.gmail.com> References: <86a272920612180428p49c89c43wf19fa5e9dccb15f6@mail.gmail.com> Message-ID: <200612181226.25152.jonc@icicled.net> On Monday 18 December 2006 06:28, pradeep kumar wrote: > hii iam working on socket programming, > i've to connect webservers through HTTP port and send/receive data.. > so currently i'm installed apache server and trying to connect that server > using python. > so any tell me how to connect the apache server by python code. > give suggestions.. Pradeep, first of all you might want to formulate your sentences properly so that it is understandable by the people who read it. Secondly, take the time to describe what your question/goal is. From what I've read & possibly misunderstood, it seems that you want to be able to retreive data from a web page. If so you might want to glance at http://diveintopython.org/http_web_services/ and also take a look at the SGML section that is mentioned earlier on in the book. - Jonathan Curran From at at tuko.nl Wed Dec 13 13:57:42 2006 From: at at tuko.nl (at) Date: Wed, 13 Dec 2006 19:57:42 +0100 Subject: Iterating over several lists at once References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> <1166021513.479174.113630@80g2000cwy.googlegroups.com> Message-ID: <45804d23$0$332$e4fe514c@news.xs4all.nl> Sorry for breaking into this thread, but I agree completely that any unnecessary indentations should be avoided. For the same reason I advocate that the following syntax should work: for x in some_list if some_condition: ... code ... in stead of for x in some_list if some_condition: ... code ... All the best! @ PS: maybe using 'sets' can help you out for a particular problem. Gal Diskin wrote: > Nothing seriously wrong, but it's not too elegent. Especially when the > number of lists you want to iterate over gets bigger (especially > because of the indentation in python). As you noticed (an phrased > better than me), what I was wondering is if there is a way to iterate > over the cartesian product, but without actually doing all n for loops > but using a single "for" loop. > > Thanks for replying me. > > > On Dec 13, 3:58 pm, Roberto Bonvallet > wrote: >> Gal Diskin wrote: >> > Hi, >> > I am writing a code that needs to iterate over 3 lists at the same >> > time, i.e something like this: >> >> > for x1 in l1: >> > for x2 in l2: >> > for x3 in l3: >> > print "do something with", x1, x2, x3What's wrong with this? >> >> [...] >> >> > I'd be very happy to receive ideas about how to do this in one loop and >> > with minimal initialization (if at all required).def >> > cartesian_product(l1, l2, l3): >> for i in l1: >> for j in l2: >> for k in l3: >> yield (i, j, k) >> >> for (i, j, k) in cartesian_product(l1, l2, l3): >> print "do something with", i, j, k >> >> -- >> Roberto Bonvallet From ldo at geek-central.gen.new_zealand Sun Dec 31 06:07:28 2006 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 01 Jan 2007 00:07:28 +1300 Subject: a question on python dict References: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> Message-ID: In message , Tim Peters wrote: > [Tim Peters] >>> You should also note that copying a dict key or value (no matter of >>> what type) consists in its entirety of copying one machine address (a >>> 4- or 8-byte pointer, depending on platform). > > [Lawrence D'Oliveiro] >> Actually, no. It also consists of updating reference counts as well. > > Not in context: dict resizing is refcount-neutral... The question wasn't about resizing, it was about "copying a dict key or value". From gagsl-py at yahoo.com.ar Fri Dec 15 05:11:23 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 15 Dec 2006 07:11:23 -0300 Subject: Conditional iteration In-Reply-To: <1166176294.981549.309770@73g2000cwn.googlegroups.com> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <1166176294.981549.309770@73g2000cwn.googlegroups.com> Message-ID: <7.0.1.0.0.20061215070630.05419bb0@yahoo.com.ar> At Friday 15/12/2006 06:51, mystilleef wrote: >This why I prefer functional programming constructs for my >list/sequence processing needs. > >------------------------------------------------------------------------ >is_true = lambda x: x > 0 >map(process_list, filter(is_true, [-2, -1, 0, 1, 2, 3, 4])) >------------------------------------------------------------------------ Be aware that map, filter, and reduce may be dropped in Python 3000. http://www.artima.com/weblogs/viewpost.jsp?thread=98196 (and I won't miss them if gone) -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From dr.mtarver at ukonline.co.uk Fri Dec 8 07:57:35 2006 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: 8 Dec 2006 04:57:35 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xejrah9on.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> Message-ID: <1165582654.974945.173700@79g2000cws.googlegroups.com> Paul Rubin wrote: > "Mark Tarver" writes: > > How do you compare Python to Lisp? What specific advantages do you > > think that one has over the other? > > Thanks; a quick read of your reference to Norvig's analysis http://norvig.com/python-lisp.html seems to show that Python is a cut down (no macros) version of Lisp with a worse performance. The only substantial advantage I can see is that GUI, and Web libraries are standard. This confirms my suspicion that Lisp is losing out to newbies because of its lack of standard support for the things many people want to do. Mark From anton.vredegoor at gmail.com Tue Dec 19 10:28:11 2006 From: anton.vredegoor at gmail.com (Anton Vredegoor) Date: Tue, 19 Dec 2006 16:28:11 +0100 Subject: permutations - fast & with low memory consumption? In-Reply-To: <1166540709.095851.97120@a3g2000cwd.googlegroups.com> References: <1166540709.095851.97120@a3g2000cwd.googlegroups.com> Message-ID: Gerard Flanagan wrote: > No claims with respect to speed, but the kslice function here: > > http://gflanagan.net/site/python/utils/sequtils/ > > will give the 'k-subsets' which then need to be permuted - > alternatively Google. Maybe the function below could then do these permutations. Anton. def _sorted(seq): """ Return a sorted copy of seq, preserving the type. """ res = seq[0:0] decorated = ((x,i) for i,x in enumerate(seq)) for x,i in sorted(decorated): res += seq[i:i+1] return res def _swap_and_reverse_tail(R,i,j): """ Swap R[i] and R[j], reverse R[i+1:]. Returns a copy, preserving the type. """ a,b,c,d,e = R[:i],R[i:i+1],R[i+1:j],R[j:j+1],R[j+1:] return a+d+(c+b+e)[::-1] def permutations(seq): """ Generate sorted permutations of any sequence that can be indexed and sliced, preserving the type. e.g. seq can be a string, list, tuple or array. """ n = len(seq) if n == 1: yield seq[:] elif n >= 2: R = _sorted(seq) while True: yield R i,j = n-2,n-1 while R[i] >= R[i+1] : i -= 1 if i == -1: return while R[i] >= R[j]: j -= 1 R = _swap_and_reverse_tail(R,i,j) def test(): seq = 'gkDr217sKGMNLPsrtqeiczxyqqqqq' P = permutations(seq) for i,x in enumerate(P): print '%s' %(x) if i == 10: break if __name__ == '__main__': test() From python at hope.cz Mon Dec 4 00:57:42 2006 From: python at hope.cz (Lad) Date: 3 Dec 2006 21:57:42 -0800 Subject: Video feature In-Reply-To: <1ot4n2dmkflrci1bus94vovpsoisbd1m64@4ax.com> References: <1165048406.302509.122060@16g2000cwy.googlegroups.com> <1ot4n2dmkflrci1bus94vovpsoisbd1m64@4ax.com> Message-ID: <1165211862.716073.175940@f1g2000cwa.googlegroups.com> Hello Tim, Thank you for your reply. Yes, my site uses Python. Do you have any idea how to add video playing ( video streaming feature)to my webiste? Thank you for help L. Tim Roberts wrote: > "Lad" wrote: > > > >I would like to add on my website a possibility for visitors to > >upload video and watch other user's video. How much difficult would it > >be with Python? > > It's not all that hard, although you can probably download something that > will do most of the job, probably in PHP. Is your website already using > Python? > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. From exarkun at divmod.com Mon Dec 4 20:34:17 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Mon, 4 Dec 2006 20:34:17 -0500 Subject: Monitoring number of smtp bytes sent through python e-mail socket In-Reply-To: <4574C8D0.8060603@dodo.com.au> Message-ID: <20061205013417.20948.404983754.divmod.quotient.58082@ohm> On Tue, 05 Dec 2006 12:18:08 +1100, William Connery wrote: >Hi, > >I have a small python program with e-mail capabilities that I have >pieced together from code snippets found on the internet. > >The program uses the smtplib module to successfully send an e-mail with >an attachment. > >I want to give users an indication of the percentage of the e-mail that >has already been sent so as to avoid frustration when dealing with large >attachments or a slow smtp server. But the smtplib module doesn't seem >to provide access to the number of bytes that have already been sent. > >Can anyone help, or provide a working example of sending an e-mail >attachment using basic python sockets whilst having access to the number >of bytes that have already been sent through the socket? You could probably hack something up with smtplib, but it's a lot easier to do this with Twisted's SMTP client. Twisted's sendmail function takes a file-like object instead of a string. You can wrap a real file and present a read method which keeps track of how many bytes have been read and updates some UI with this information. You can find a simple example of using Twisted's SMTP client here: http://twistedmatrix.com/trac/browser/trunk/doc/mail/examples/smtpclient_tls.py Jean-Paul From stephen.dover at onetel.co.uk Wed Dec 13 05:57:23 2006 From: stephen.dover at onetel.co.uk (meridian) Date: 13 Dec 2006 02:57:23 -0800 Subject: slices - handy summary Message-ID: <1166007443.489814.171340@j72g2000cwa.googlegroups.com> If, like me, you're always forgetting which way around your list/seq slices need to go then worry no more. Just put my handy "slice lookupper" (TM) ) on a (large!) PostIt beside your screen and, Hey Presto! no more tediously typing a 1-9 seq into your interpreter and then getting a slice just to check what you get.. (Yes you. You know you do that !) ... Cheers Steve x = '0123456789' x[-10: ] 0123456789 x[ 0: ] x[ -9: ] 123456789 x[ 1: ] x[ -8: ] 23456789 x[ 2: ] x[ -7: ] 3456789 x[ 3: ] x[ -6: ] 456789 x[ 4: ] x[ -5: ] 56789 x[ 5: ] x[ -4: ] 6789 x[ 6: ] x[ -3: ] 789 x[ 7: ] x[ -2: ] 89 x[ 8: ] x[ -1: ] 9 x[ 9: ] x[ :-9 ] 0 x[ :1 ] x[ :-8 ] 01 x[ :2 ] x[ :-7 ] 012 x[ :3 ] x[ :-6 ] 0123 x[ :4 ] x[ :-5 ] 01234 x[ :5 ] x[ :-4 ] 012345 x[ :6 ] x[ :-3 ] 0123456 x[ :7 ] x[ :-2 ] 01234567 x[ :8 ] x[ :-1 ] 012345678 x[ :9 ] 0123456789 x[ :10 ] From udodenko at users.sourceforge.net Sat Dec 9 05:35:24 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sat, 9 Dec 2006 12:35:24 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Message-ID: <457a916f$0$49198$14726298@news.sunsite.dk> (message (Hello 'Ken) (you :wrote :on '(Sat, 09 Dec 2006 04:26:02 -0500)) ( KT> keep the Pythonistas from straying. But you have an excuse: Lispniks KT> always /talk/ about macros giving us the ability to create a DSL. But KT> no one does. :) certainly there's no reason to make a new DSL each day, but sometimes they are good. i've recently posted an example of DSL to do queries to RDF data base -- i find it's very helpful. ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From steven.bethard at gmail.com Sun Dec 24 00:25:46 2006 From: steven.bethard at gmail.com (Steven Bethard) Date: Sat, 23 Dec 2006 22:25:46 -0700 Subject: Getting the name of an assignment In-Reply-To: <1166931251.020269.93440@48g2000cwx.googlegroups.com> References: <1166913499.494219.250440@48g2000cwx.googlegroups.com> <6b6dnZveubZ8dhDYnZ2dnUVZ_ua3nZ2d@comcast.com> <1166931251.020269.93440@48g2000cwx.googlegroups.com> Message-ID: Adam Atlas wrote: > Isn't it a bit convoluted to use metaclasses? Yep. It's a well known fact that putting "convoluted" and "metaclasses" in the same sentence is repetitively redundant. ;-) > someinstance.__class__.__name__ does the same thing. No, not really:: >>> class C(object): ... def __init__(self, name): ... self.name = name ... @classmethod ... def from_class_block(cls, name, bases, blockdict): ... return cls(name) ... >>> c = C('foo') >>> c.name 'foo' >>> type(c) >>> c.__class__.__name__ 'C' >>> class foo: ... __metaclass__ = C.from_class_block ... >>> foo.name 'foo' >>> type(foo) >>> foo.__class__.__name__ 'C' Note that the ``class foo`` statement is not creating a class. It's creating an instance of ``C``. So it really is doing something pretty different. STeVe From bearophileHUGS at lycos.com Thu Dec 28 08:55:21 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 28 Dec 2006 05:55:21 -0800 Subject: answers.py v0.0.1 - source In-Reply-To: References: <87bqloz3fy.fsf@pyenos.pyenos.org> Message-ID: <1167314121.664522.106480@48g2000cwx.googlegroups.com> Marc 'BlackJack' Rintsch: You give lot of comments and I agree with most of them. > One idiom to solve this is: > def __init__(self, answers=None): > self.answers = answers or dict() I suggest to avoid such usage of or/and (expecially for newbies), that is triky and can produce bugs, and to use a more explicit if: def __init__(self, answers=None): if answers is None: self.answers = {} else: self.answers = answers If you are sure you can use 2.5+ (the enclosing of the if is optional, but helps readability): def __init__(self, answers=None): self.answers = ({} if answers is None else answers) Bye, bearophile From hg at nospam.org Fri Dec 15 17:02:28 2006 From: hg at nospam.org (hg) Date: Fri, 15 Dec 2006 16:02:28 -0600 Subject: Serial port failure References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> <1166219528.807953.308840@80g2000cwy.googlegroups.com> Message-ID: Rob wrote: > Here is OpenPort > > #################################################################### > #### OpenPort procedure > #################################################################### > def OpenPort(name): > BRate = 19200 > Tout = 3 > > try: > # Initialize the port > p = serial.Serial(name) > # handle failures gracefully > except SerialException: > print "The serial port is unavailable." > print "Disconnect your USB to Serial adapter, Then" > print "reconnect it and try again." > sys.exit(1) > > p.setBaudrate(19200) > p.setTimeout(3) #set timeout to 1.5 seconds > > # finish opening the port and assign a file handle > p.open() > return p > > > > On Dec 15, 1:07 pm, hg wrote: >> Rob wrote: >> > Hi all, >> >> > I am fairly new to python, but not programming and embedded. I am >> > having an issue which I believe is related to the hardware, triggered >> > by the software read I am doing in pySerial. I am sending a short >> > message to a group of embedded boxes daisy chained via the serial port. >> > When I send a 'global' message, all the connected units should reply >> > with their Id and Ack in this format '0 Ack' To be certain that I >> > didn't miss a packet, and hence a unit, I do the procedure three times, >> > sending the message and waiting for a timeout before I run through the >> > next iteration. Frequently I get through the first two iterations >> > without a problem, but the third hangs up and crashes, requiring me to >> > remove the Belkin USB to serial adapter, and then reconnect it. Here >> > is the code: >> >> > import sys, os >> > import serial >> > import sret >> > import time >> >> > from serial.serialutil import SerialException >> > #################################################################### >> > #### GetAck Procedure >> > #################################################################### >> > def GetAck(p): >> > response = "" >> >> > try: >> > response = p.readline() >> > except SerialException: >> > print ">>>>>Timed out<<<<<" >> > return -1 >> > res = response.split() >> >> > #look for ack in the return message >> > reslen = len(response) >> > if reslen > 5: >> > if res[1] == 'Ack': >> > return res[0] >> > elif res[1] == 'Nak': >> > return 0x7F >> > else: >> > return -1 >> >> >>>>>> Snip <<<<<< >> > #################################################################### >> > #### GetNumLanes Procedure >> > #################################################################### >> > def GetNumLanes(Lanes): >> > print "Looking for connected units" >> > # give a turn command and wait for responses >> > msg = ".g t 0 336\n" >> >> > for i in range(3): >> > port = OpenPort() >> > time.sleep(3) >> > print port.isOpen() >> > print "Request #%d" % (i+1) >> > try: >> > port.writelines(msg) >> > except OSError: >> > print "Serial port failure. Power cycle units" >> > port.close() >> > sys.exit(1) >> >> > done = False >> > # Run first connection check >> > #Loop through getting responses until we get a -1 from GetAck >> > while done == False: >> > # lane will either be -1 (timeout), 0x7F (Nak), >> > # or the lane number that responded with an Ack >> > lane = GetAck(port) >> > if lane >= '0': >> > if False == Lanes.has_key(lane): >> > Lanes[lane] = True >> > else: >> > done = True >> > port.close() >> > time.sleep(3) >> >> > # Report number of lanes found >> > NumLanes = len(Lanes) >> > if NumLanes == 1: >> > print "\n\nFound 1 unit connected" >> > else: >> > print "\n\nFound %d units connected" % NumLanes >> >> > return NumLanes >> >> >>>>>>> Snip <<<<<< >> > #################################################################### >> > #### Main Program Code Section >> > #################################################################### >> >> > #open the serial port >> > # capture serial port errors from trying to open the port >> >> > port = OpenPort() >> >> > # If we got to here, the port exists. Set the baud rate and timeout >> > values >> >> > # I need to determine how many lanes are on this chain >> > # First send a turn command >> >> > #Create a dictionary of lanes so I can check each lane's responses >> > Lanes = {} >> > #<><><><><><><><><><><><><><><><> >> > # Call the lane finder utility >> > NumLanes = GetNumLanes(Lanes) >> > #<><><><><><><><><><><><><><><><> >> >> > #if no lanes responded, exit from the utility >> > if 0 == NumLanes: >> > print "I can't find any units connected." >> > print "Check your connections and try again" >> > sys.exit(1) >> >> > # list the lanes we have in our dictionary >> > for n in Lanes: >> > print "Lane - %s" % n >> >> > Now, here is the error message that I get >> >> > dad at nb29:~/py$ ./Thex.py >> > Looking for connected units >> > True >> > Request #1 >> > True >> > Request #2 >> > Serial port failure. Power cycle units >> > dad at nb29:~/py$ ./Thex.py >> > The serial port is unavailable. >> > Disconnect your USB to Serial adapter, Then >> > reconnect it and try again. >> > dad at nb29:~/py$ >> >> > Does anyone have any ideas? >> >> > Thanks, >> >> > rob < Amateur.N7... at gmail.com >Where is OpenPort ? >> >> hg I don't get it: you never pass any parameter to OpenPort The second thing I wonder about is whether you need to reinit serial every time . hg From shejo284 at gmail.com Tue Dec 19 16:34:30 2006 From: shejo284 at gmail.com (Sheldon) Date: 19 Dec 2006 13:34:30 -0800 Subject: Core dump revisited In-Reply-To: References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> <1166474110.001428.137260@80g2000cwy.googlegroups.com> <1166476940.590579.133460@73g2000cwn.googlegroups.com> <1166542176.142415.305720@48g2000cwx.googlegroups.com> Message-ID: <1166564070.500318.135300@t46g2000cwa.googlegroups.com> Nick Craig-Wood skrev: > Sheldon wrote: > > Man. You are good. This is most insight I have had from anyone. > > :-) > > > I did initialize the arrays with PyObjects and today, after hours of > > debugging and now with your insight, I think the problem lies here: > > Good! > > You need to release some python references otherwise you'll have a > memory leak and copy some strings you don't own > > It is worth reading the definitions for those functions in the Python > API docs > > http://docs.python.org/api/api.html > > In particular read about reference counts. > > With the Python C API you have to know at all time (by reading the > doc) whether you own the reference or not, and whether you own the > memory or not. > > > /* here a python list of strings is read into a C string array */ > > static int readPythonObject(void) { > > > > int i; > > PyObject *msgop; > > PyObject *ppsop; > > PyObject *tileop; > > PyObject *sceneop; > > > > for (i = 0; i < work.sumscenes; i++) { > > msgop = PyList_GetItem(work.msgobj, i); > > work.msg_scenes[i] = PyString_AsString(msgop); > > work.msg_scenes[i] = strdup(PyString_AsString(msgop)); > Py_DECREF(msgop); > > > ppsop = PyList_GetItem(work.ppsobj, i); > > work.pps_scenes[i] = PyString_AsString(ppsop); > > work.pps_scenes[i] = strdup(PyString_AsString(ppsop)); > Py_DECREF(ppsop); > > > } > > for (i = 0; i < NumberOfTiles; i++) { > > tileop = PyList_GetItem(work.tileobj, i); > > work.tiles[i] = PyString_AsString(tileop); > > work.tiles[i] = strdup(PyString_AsString(tileop)); > Py_DECREF(tileop); > > > sceneop = PyList_GetItem(work.nscenesobj, i); > > work.nscenes[i] = PyInt_AsLong(sceneop); > > Py_DECREF(sceneop); > > > } > > return 1; > > } /*end readPythonObject*/ > > You free() the strings later which is fine. > > The above ignores errors which PyList_GetItem may return and strdup() > returning 0, but it should get you out of trouble hopefully. > > ... > > I've written lots of quite similar code, here is a snippet. Note the > comments about who owns the reference, and the error checking. Also > note xstrdup() which is a strdup() which blows up if no memory is > available. > > [snip] > PyObject *item = PySequence_GetItem(value, i); /* real ref */ > if (item == 0) > { > fprintf(stderr, "Failed to read '%s[%d]' attribute\n", name, i); > goto err; > } > item_cstr = PyString_AsString(item); /* borrowed */ > if (item_cstr == 0) > { > fprintf(stderr, "Failed to read '%s[%d]' as string\n", name, i); > goto err; > } > label[i] = xstrdup(item_cstr); > Py_DECREF(item); > item = 0; > [snip] > err:; > PyErr_Print(); > out:; > if (value) > Py_DECREF(value); > if (item) > Py_DECREF(item); > return rc; > > > -- > Nick Craig-Wood -- http://www.craig-wood.com/nick Thanks Nick! Man, I really appreciate this. I did dereference before but the program crashed and I did understand why so I kept on learning. Now I have your snip. Much obliged. I will be adding Numpy to my new PC in Jan and there I can pass arrays instead of list. Still, I would like to save your email address i case I have some mre questions later - if that ok with you? I will make the changes and try to run the code. /S From rald86 at yahoo.fr Sat Dec 2 04:16:15 2006 From: rald86 at yahoo.fr (Robert R.) Date: 2 Dec 2006 01:16:15 -0800 Subject: best way to align words? In-Reply-To: References: <1164925391.696612.64860@80g2000cwy.googlegroups.com> Message-ID: <1165050975.684944.232250@j44g2000cwa.googlegroups.com> Hello, thanks for all your replies, i'm now looking to dynamic programming... sorry for forgetting to say that i wanted the words to be ordered, thus : s1 = "hello there dudes" s2 = "dudes hello there" s3 = "there dudes hello" will not return anything while sharing all three words. Bearophile your solution with graph looks interesting although i still do not understand how it works, but yes there is definitively something with drawing path around words. i have tried SequenceMatcher from difflib after using combinations of all sentences as i need to process much more than the 3 of my first example. best. From smartbei at gmail.com Sun Dec 24 11:54:25 2006 From: smartbei at gmail.com (smartbei) Date: 24 Dec 2006 08:54:25 -0800 Subject: Help with small program In-Reply-To: References: <1166966360.384179.101400@48g2000cwx.googlegroups.com> Message-ID: <1166979265.284345.173840@48g2000cwx.googlegroups.com> Felix Benner wrote: > smartbei schrieb: > > Hello, I am a newbie with python, though I am having a lot of fun using > > it. Here is one of the excersizes I am trying to complete: > > the program is supposed to find the coin combination so that with 10 > > coins you can reach a certain amoung, taken as a parameter. Here is the > > current program: > > > > coins = (100,10,5,1,0.5) > > anslist = [] > > def bar(fin, hist = {100:0,10:0,5:0,1:0,0.5:0}): > > s = sum(x*hist[x] for x in hist) > > l = sum(hist.values()) > > if s < fin and l < 10: > > for c in coins: > > if (s+c) <= fin: > > hist[c] += 1 > > bar(fin, hist) > > hist[c] -= 1 > > elif l==10 and s==fin and not hist in anslist: > > #p1 > > anslist.append(hist) > > > > bar(50) > > print anslist > > > > The problem is that if I run it, anslist prints as [{0.5: 0, 1: 0, 10: > > 0, 100: 0, 5: 0}], which doesnt even add up to 50. When I check how > > many times the program has reached the #p1 by sticking a print there, > > it only reaches it once, and it comes out correct. why is it that this > > result is replaced by the incorrect final one? > > > > hist is stored in anslist as a pointer only, therfore the hist[c] -= 1 > operates on the same dict as is stored in the anslist. Try the following > in the python interpreter: > > a = { 'key' : 1 } > l = [a] > l[0]['key'] -= 1 > a > > instead use: > > anslist.append(dict(hist.items)) > > which will copy the dict. Thanks! BTW - its hist.items(), after that it worked. From tim.one at comcast.net Sun Dec 31 07:27:44 2006 From: tim.one at comcast.net (Tim Peters) Date: Sun, 31 Dec 2006 06:27:44 -0600 Subject: a question on python dict References: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> Message-ID: [Tim Peters] >>>> You should also note that copying a dict key or value (no matter of >>>> what type) consists in its entirety of copying one machine address (a >>>> 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] >>> Actually, no. It also consists of updating reference counts as well. [Tim Peters] >> Not in context: dict resizing is refcount-neutral... [Lawrence D'Oliveiro] > The question wasn't about resizing, it was about "copying a dict key or > value". Then you misunderstood the OP. He was asking about dict resizing: ... When there are more and more items being added to the hashtable, it increase its buckets and copy the old items into the new one and re-calculate the hash value of each item. I think this will waste some time doing the increasing-copying thing. Taking my response out of context to begin with doesn't really change that I answered the question he asked ;-) From jon at ffconsultancy.com Tue Dec 12 10:28:23 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 15:28:23 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> <7xodqczf1h.fsf@ruckus.brouhaha.com> <7xk60zjl1e.fsf@ruckus.brouhaha.com> Message-ID: <457ecb33$0$8719$ed2619ec@ptn-nntp-reader02.plus.net> jayessay wrote: > Fair enough. But really, I don't see any of these things as > particularly "modern" (whatever that means) or groundbreaking. > Certainly not at this point. Performance and type theory are modern in the context of FPLs. Both have been retrofitted to Lisp with varying results. > Also, there is the issue of whether there even is a "continual > progression", as in "moving up some ladder" towards something > "better", in the context of programming languages. All of that is > pretty fuzzy stuff, and plenty of CogSci work has shown these value > judgements in this context to be less than obvious in any meaning. If you look over a long period of time (e.g. back to the last major change to Lisp) then language research has had clear overall directions. > There is also a question about "old/new" wrt these value judgements. > Since Lisp is (admittedly some hand waving here) more or less lambda > calculus embodied, is it closer to say The Calculus or Group Theory > than to some random piece of technology?[1] If Lisp is "old > fashioned", then The Calculus and Group Theory are like _really_ old > fashioned. But does that lessen them in some way? What would that > be? Is some random "new" technique (say brute force iterative > techniques for calculus problems with computers) somehow "better"? Again, just read research papers to learn what's new. For example, we're going multicore whether you like it or not, so concurrent GCs will become much more important over the next few years. F# adds that to OCaml. That's new and its better. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From massi_srb at msn.com Wed Dec 20 07:37:13 2006 From: massi_srb at msn.com (Massi) Date: 20 Dec 2006 04:37:13 -0800 Subject: wxGrid: Problem with unicode mathematical symbols Message-ID: <1166618233.179068.283100@t46g2000cwa.googlegroups.com> Hi everyone, I'm trying to build (on windows environment) a grid in which every cell contains a mathematical formula, the problem is the following: when I try to put in the cells some mathematical symbol (such as those for "belong to", "for all" or "exists") with the method SetCellValue I always see "?" as the value of the cells, even if I use both the unicode wx version and the right unicode strings for the symbols (such as u'\u2208' for "belong to" ). In fact if I do (on IDLE): print u'\u2208' everything works fine. I can't understand why I am wrong. I also tried to change the font of the cells in "Arial Unicode MS", but the result was the same. Have you got any idea about?. Thanks in advance, Massi From rjagodic at gmail.com Tue Dec 12 11:03:13 2006 From: rjagodic at gmail.com (Ratko Jagodic) Date: Tue, 12 Dec 2006 10:03:13 -0600 Subject: comparing two IP addresses and the underlying machine In-Reply-To: <457EC040.5080105@tim.thechases.com> References: <1eb708be0612111355u6c9c51a2u796fdb5aa44b01d9@mail.gmail.com> <457EC040.5080105@tim.thechases.com> Message-ID: <1eb708be0612120803o16c4c017t95ee5b9eed01d511@mail.gmail.com> By the same physical machine I meant one OS using two interfaces and multiple IP addresses mapped to different interfaces. I figured there wouldn't be a direct solution to this so each time I will send all IP addresses to the "match maker" so I can make comparisons and that should work. Thanks for the help. Ratko On 12/12/06, Tim Chase wrote: > > > I've been trying to figure this one out for some time but > > with no success. I have a machine with two network > > interfaces, each with their own IP address and it's own > > domain, for example: > > - ipA on machineA.domainA > > - ipB on machineB.domainB > > > > Given any pair of IPs or hostnames (or a mix of them), how > > can I figure whether they belong to the same physical > > machine or not? Of course, this is trivial if my python > > program is running the given machine but what if a remote > > machine is trying to figure this out (but that machine has > > access to both domains/IPs). > > Appreciate and ideas. > > > I have a feeling that you're trying to attempt the > impossible. What do you mean by "the same physical > machine"? The same case? What happens if there are two > virtual OSes on the machine, each using its own NIC? > > Unless you have a client application running on "the > physical machine" that can respond to queries on each NIC, > you're pretty much out of luck. You could write something > like a "same_ping" program that would listen on both NICs, > and respond with a "yeah, I'm the same machine" > confirmation. There are all sorts of ways to do this, > depending on how sure you need to be that nobody can spoof > it...ranging from simple "here's a random number on one IP > address followed by asking the other IP if it's seen that > random number before" to having the physical machine sign > one request on each port and confirm that their signatures > are the same. > > -tkc > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwatch at gmail.com Tue Dec 26 15:55:48 2006 From: kwatch at gmail.com (kwatch at gmail.com) Date: 26 Dec 2006 12:55:48 -0800 Subject: Q: How to generate code object from bytecode? In-Reply-To: References: <1167160509.839311.230090@73g2000cwn.googlegroups.com> <1167162539.3394.18.camel@dot.uniqsys.com> Message-ID: <1167166548.231082.268650@79g2000cws.googlegroups.com> Thanks Fredrik and Carsten, I'll try marshal module. > * Your code snippet is a statement, actually, a suite of statements. You > need to exec it, not eval it. > * You seem to think that eval'ing or exec'ing a code object will > magically capture its output stream. It won't. Oh, it's my mistake. > What do you actually want to accomplish? I'm now developping embedded python text converter. ex. example.pyhtml

title

  • ${item}
ex. converted python code _buf = []; _buf.append('''

title

    \n'''); for item in items: _buf.append('''
  • '''); _buf.append(escape(to_str(item))); _buf.append('''
  • \n'''); #end _buf.append('''
\n'''); -- regards, kwatch From martin at v.loewis.de Mon Dec 11 16:50:06 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 11 Dec 2006 22:50:06 +0100 Subject: Tarfile .bz2 In-Reply-To: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> References: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> Message-ID: <457DD28E.3090509@v.loewis.de> Jordan schrieb: > When using python to create a tar.bz2 archive, and then using winrar to > open the archive, it can't tell what the compressed size of each > individual file in the archive is. Is this an issue with winrar or is > there something that needs to be set when making the archive that isn't > there by default. I believe it's an issue of the file format (tar.bz2). You don't compress individual files, but you compress the entire tar file. So it is not meaningful to talk about the compressed size of an individual archive member - they are all uncompressed. Regards, Martin From robin at NOSPAMreportlab.com Sat Dec 30 07:47:32 2006 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Sat, 30 Dec 2006 12:47:32 +0000 Subject: per interpreter storage for C extensions In-Reply-To: <4595b573$0$25466$9b622d9e@news.freenet.de> References: <4595b573$0$25466$9b622d9e@news.freenet.de> Message-ID: <45965FE4.5080807@jessikat.plus.net> Martin v. L?wis wrote: > Robin Becker schrieb: >> Is there a simple/cheap way for C code to cache these sorts of module >> level globals on a per interpreter basis? Is there even a way to tell >> which interpreter I'm being called in? > > There is no cheap way to add to the interpreter state. As Chris Mellon > explains, you can use PyThreadState_Get()->interp to find the > interpreter state. I recommend to do the caching only in the > single-interpreter case (i.e. for the first interpreter). > > Notice that comparing interpreter states by identity is somewhat > dangerous: the interpreter may have been deleted with you still > holding a pointer to it, and a new interpreter may get allocated > at the same address, making you believe it is the same interpreter. .... I can eliminate most of the problems by not keeping private pointers to the cache variables. What is worrying is that in the extension init we're creating an exception and version string etc and holding a pointer to them in C; is it safe to use the same exception in different interpeters? Currently the exception is added to the module at init time, but my reading of the documentation implies that all interpreters will see that exception as it is copied from the first. -- Robin Becker From simon at rendermania.com Thu Dec 7 07:52:21 2006 From: simon at rendermania.com (simon at rendermania.com) Date: 7 Dec 2006 04:52:21 -0800 Subject: per instance descriptors In-Reply-To: <1165467481.033283.118340@f1g2000cwa.googlegroups.com> References: <45777908_4@mk-nntp-2.news.uk.tiscali.com> <1165467481.033283.118340@f1g2000cwa.googlegroups.com> Message-ID: <1165495941.777701.255580@79g2000cws.googlegroups.com> George Sakkis wrote: > Simon Bunker wrote: > > > Hi I have code similar to this: > > > > class Input(object): > > > > def __init__(self, val): > > self.value = val > > > > def __get__(self, obj, objtype): > > return self.value > > > > def __set__(self, obj, val): > > # do some checking... only accept floats etc > > self.value = val > > > > class Node(object): > > > > a = Input(1) > > b = Input(2) > > > > I realise that a and b are now class attributes - however I want to do this: > > > > node1 = Node() > > node2 = Node() > > > > node1.a = 3 > > node.b = 4 > > > > And have them keep these values per instance. However now node1.a is 4 > > when it should be 3. > > > > Basically I want to have the Input class as a gateway that does lots of > > checking when the attibute is assigned or read. > > > > I have had a look at __getattribute__(), but this gets very ugly as I > > have to check if the attribute is an Input class or not. > > > > Also I don't think property() is appropriate is it? All of the > > attributes will essentially be doing the same thing - they should not > > have individual set/get commands. > > > > Is there any way of doing this nicely in Python? > > What about __setattr__ ? At least from your example, checking happens > only when you set an attribute. If not, post a more representative > sample of what you're trying to do. > > George Yes, but I am setting it in the Node class aren't I? Wouldn't I need to define __setattr__() in class Node rather than class Input? I don't want to do this. Or am I getting confused here? thanks Simon From nelson1977 at gmail.com Thu Dec 7 03:28:02 2006 From: nelson1977 at gmail.com (nelson -) Date: Thu, 7 Dec 2006 09:28:02 +0100 Subject: Window, Windows, Linux, client and server... Message-ID: hi all! i'm trying to implement an appllication with this two requirements. I have a server and some clients. I want to be able to launch an application (openoffice impress, for example) and display what i'm doing on the server on the client. Conversely, I want to be able to have a picture of the desktop client. Is it a thing that i can do in python? any advice? I googled but i can't find something too useful... II know i can use vnc, but i want a pure python solution... if it's possibile... Doing it using VNC it seems not so "clear"... :) thanks, nelson From spedrosa at gmail.com Thu Dec 7 07:08:18 2006 From: spedrosa at gmail.com (Stephen Eilert) Date: 7 Dec 2006 04:08:18 -0800 Subject: Common Python Idioms In-Reply-To: References: <17783.32458.730462.8403@montanaro.dyndns.org> Message-ID: <1165493298.205945.162430@n67g2000cwd.googlegroups.com> Hendrik van Rooyen escreveu: > wrote: > > > Peter> Bjoern Schliessmann wrote: > > >> Wouldn't be "if k in d.keys()" be the exact replacement? > > > > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less > > Peter> (constant) overhead for the function call. 'k in d.keys()' on the > > Peter> other hand creates a list of keys which is then searched linearly > > Peter> -- about the worst thing you can do about both speed and memory > > Peter> footprint. I've always used has_key(), thinking it was the only way to do it. Given that Python says that "There Should Be Only One Way to Do It", I didn't bother searching for alternatives. Is there a list somewhere listing those not-so-obvious-idioms? I've seen some in this thread (like the replacement for .startswith). I do think that, if it is faster, Python should translate "x.has_key(y)" to "y in x". Stephen From geskerrett at hotmail.com Mon Dec 4 12:05:51 2006 From: geskerrett at hotmail.com (geskerrett at hotmail.com) Date: 4 Dec 2006 09:05:51 -0800 Subject: Using win32gui.SendMessage and SysListView32 control In-Reply-To: <1165176116.034632.58270@f1g2000cwa.googlegroups.com> References: <1165176116.034632.58270@f1g2000cwa.googlegroups.com> Message-ID: <1165251951.901171.217570@j44g2000cwa.googlegroups.com> Thanks for your help. I will check them out. From johnzenger at gmail.com Wed Dec 20 15:29:43 2006 From: johnzenger at gmail.com (johnzenger at gmail.com) Date: 20 Dec 2006 12:29:43 -0800 Subject: error with IDLE on debian In-Reply-To: References: Message-ID: <1166646582.901874.273850@73g2000cwn.googlegroups.com> Just a guess, but I think you need to be using at least Python 2.4 if you are going to use IDLE version 2.4.4-2. On Dec 20, 1:16 pm, altern wrote: > Hi > > when i try to run IDLE on my debian laptop I get this error. > > $ idle > Traceback (most recent call last): > File "/usr/bin/idle", line 5, in ? > main() > File "idlelib/PyShell.py", line 1359, in main > File "idlelib/FileList.py", line 44, in new > File "idlelib/PyShell.py", line 105, in __init__ > File "idlelib/EditorWindow.py", line 111, in __init__ > File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 2764, in __init__ > Widget.__init__(self, master, 'text', cnf, kw) > File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1865, in __init__ > self.tk.call( > _tkinter.TclError: expected integer but got "`100" > > I am not sure about what could cause the problem because I didnt use my > laptop for python programming for couple of weeks. Before that it worked > fine. And on that period i might have installed few things. > > I am running Debian unstable with python 2.2.4, tcl8.4, tk8.4, python-tk > 24.4-1 and IDLE 2.4.4-2. I already tried to reinstall IDLE, tk and tcl > and python-tk but that did not solve anything, i keep getting the same > error. > > any ideas? > > thanks > > enrike From sturlamolden at yahoo.no Sun Dec 17 18:10:48 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 17 Dec 2006 15:10:48 -0800 Subject: first and last index as in matlab In-Reply-To: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> References: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> Message-ID: <1166397048.401143.71480@16g2000cwy.googlegroups.com> It's quite straight forward, actually. What you need to know is that -1 is the index of the last element in a sequence, and that slicing excludes the 'end' value in 'start:end'. So if you type arr[0:N], you get the subsequence [arr[0], arr[1], arr[2], ..., arr[N-1]] When comparing with Matlab, Python slicing works like this: arr(1:end) -> arr[:] or arr[0:] arr(1:end-1) -> arr[:-1] or arr[0:-1] arr(1:end-N) -> arr[:-N] or arr[0:-N] arr(end) -> arr[-1] arr(1) -> arr[0] arr(1:2:end) -> arr[::2] or arr[0::2] arr(1:2:end-1) -> arr[:-1:2] or arr[0:-1:2] Python slicing is not completely like Matlab, because it was adoped from Haskell. It can do the same as Matlab's indexing, but the syntax is different. If you think Matlab's indexing is more intuitive it is just because you are more used to it. From fumanchu at amor.org Mon Dec 18 02:04:32 2006 From: fumanchu at amor.org (fumanchu) Date: 17 Dec 2006 23:04:32 -0800 Subject: dealing with special characters in Python and MySQL References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> <8rqhh.956$X72.39@newsread3.news.pas.earthlink.net> <1166423702.885345.30460@80g2000cwy.googlegroups.com> Message-ID: <1166425472.594604.297430@t46g2000cwa.googlegroups.com> ronrsr wrote: > code for storing to database: > > querystring = "update zingers set keywords = '%s', citation = > '%s', quotation = %s' where zid = %d" % > (keywords,citation,quotation,zid) You're missing a single quote in there around the quotation %s. Are you also replacing "\\" with r"\\" ? You should be. Robert Brewer System Architect Amor Ministries fumanchu at amor.org From roy at panix.com Thu Dec 7 13:47:02 2006 From: roy at panix.com (Roy Smith) Date: Thu, 07 Dec 2006 13:47:02 -0500 Subject: Best way to split up lines - RE: About the 79 character linerecommendation References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com> <012601c719f7$9e719990$0d7d12ac@kearfott.com> Message-ID: In article , "Fredrik Lundh" wrote: > Michael Yanowitz wrote: > > > What would be the best way to split the following line (Python doesn't like > > me to split it up between the comma-separated parameters): > > > > top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, > > utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, > > st2, st3, st4, st5, st6, numberOfLabels, dataWord = > > struct.unpack("!H4BH20BHI", strMessage) > > data = struct.unpack("!H4BH20BHI", strMessage) > > (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, > dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, > utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, > numberOfLabels, dataWord) = data > > My general rule of thumb for formatting things like argument lists is either they all fit on one line, or they go one item per line. So, I would do it: (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, numberOfLabels, dataWord) = data All one one line, it's just a mess of text to read through. Formatting like this, it immediately (at least to my eyes) jumps out that you've got a bunch of ips, a few other things, a bunch of utcs, a bunch of sts, and then some more random data. Much easier to read. The downside, of course, it it takes up mumble lines instead of 4. I'm cool with that, but I could see how it might annoy some people. It would be nice if struct.unpack() had a way to specify unpacking repeated items as a list, ie: data = struct.unpack ("! H 4(B) H 2B 12(B) 6(B) H I", strMessage) (top, ip, messageCounter, ackRequired, dataType, utc, st, numberOfLables, dataWord) = data and you'd end up with ip, utc, and st being lists. Hmmm, maybe that's worth a PEP? From gagsl-py at yahoo.com.ar Thu Dec 7 00:13:50 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 02:13:50 -0300 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> <1165298691.474503.184480@16g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061207020101.05442938@yahoo.com.ar> At Thursday 7/12/2006 01:17, OKB (not okblacke) wrote: > So my conclusion from this is: is there a reason that every error >message of the form "expected foo" or "this object cannot be frotzed" >cannot be changed to something like "expected foo but found bar" or >"this FooType object cannot be frotzed"? Some arguments from my head: - because error messages should be short - because error messages are not debugging tools (better use unit tests to avoid most common errors) - because it's a lot of work to actually obtain such information in each posible case, and sometimes, it may not be posible. - because none of the core developers has interest on it - because nobody else cares to submit a patch -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From skip at pobox.com Tue Dec 19 16:49:45 2006 From: skip at pobox.com (skip at pobox.com) Date: Tue, 19 Dec 2006 15:49:45 -0600 Subject: regexp In-Reply-To: References: <1166562917.353088.227780@73g2000cwn.googlegroups.com> <1166563001.129918.195400@a3g2000cwd.googlegroups.com> Message-ID: <17800.24185.194184.197847@montanaro.dyndns.org> vertigo> i noticed that while matching regexp python tries to match as wide as it's vertigo> possible, vertigo> for example: vertigo> re.sub("","",htmldata) vertigo> would cut out everything before first "" in the vertigo> document. vertigo> Can i force re to math as narrow as possible ? http://docs.python.org/lib/re-syntax.html Search for "greedy". Skip From jeffrey.aylesworth at gmail.com Fri Dec 8 18:39:45 2006 From: jeffrey.aylesworth at gmail.com (jeff) Date: 8 Dec 2006 15:39:45 -0800 Subject: Anyone use GD with pyhton? In-Reply-To: References: <1165616227.906934.306860@n67g2000cwd.googlegroups.com> Message-ID: <1165621185.675655.318090@79g2000cws.googlegroups.com> thanks, it works :D Jonathan Curran wrote: > On Friday 08 December 2006 16:17, jeff wrote: > > could somebody explain to me how to install (or compile) GD for linux, > > so that it works in pyhton? > > Jefff, the gd-library's website is at http://www.boutell.com/gd/ and they have > a link there for download as well. It is highly likely that your linux > distribution already has a gd library package ready to install. Use your > package manager to search for 'gd' and you should get something. > > Now that you have that installed, you will need to get the python binding to > it. A quick google search revealed gdmodule @ > http://newcenturycomputers.net/projects/gdmodule.html > > Hope this helps, > > Jonathan From rthorpe at realworldtech.com Thu Dec 21 12:57:26 2006 From: rthorpe at realworldtech.com (Rob Thorpe) Date: 21 Dec 2006 09:57:26 -0800 Subject: merits of Lisp vs Python In-Reply-To: <458ac5d4$0$4156$ba624c82@nntp02.dk.telia.net> References: <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <45897266$0$4158$ba624c82@nntp02.dk.telia.net> <1166637630.367729.279830@n67g2000cwd.googlegroups.com> <45899b0a$0$4169$ba624c82@nntp02.dk.telia.net> <1166647406.816210.166750@i12g2000cwa.googlegroups.com> <458ac5d4$0$4156$ba624c82@nntp02.dk.telia.net> Message-ID: <1166723846.548460.281060@80g2000cwy.googlegroups.com> Anders J. Munch wrote: > Rob Thorpe wrote: > > Anders J. Munch wrote: > >> Let u(t) be the actual memory used by the program at time t. > >> Let r(t) be the size of reachable memory at time t. > >> > >> Require that u(t) is a member of O(t -> max{t'<=t: r(t')}) > >> > >> There. That wasn't so hard, was it? > > > > That's quite a clever definition actually. > > But, let's say I have a lisp machine. It has an unusual architecture, > > it's made entirely of SRAM cells of ~9bits. Sometimes these cells are > > used as storage, sometimes their contents represent logic circuits and > > the routing between them is configured to form them into a processor. > > Please tell me what reachable memory is ;). (The above processor is > > not science fiction, it could easily be done with FPGAs) > > Reachable memory is the set of interpreter objects (conses, closures, scopes, > atoms and what have you) reachable from from some appropriately defined root > set. It can be unambiguously defined with respect to a virtual machine, with no > regard to how actual implementations represent these things. Yes. > For actual memory use, a simple byte count would do fine. If code and data are > intermingled, just use the combined size of both of them. Well, in my example the code, the data and the processor are intermingled. Still you could do it this way. But, what would happen for example if on a normal machine someone wrote a program that generated lots of functions that it never used, would it have to be detected by the GC. This is hard to do. The solution is probably to define the root set only in terms of data. > If you're worried about comparing incompatible units, don't be: apples and > oranges compare just fine under big-Oh. Yes. Thank you for comprehensively out-arguing me. I'll give one last reason why it may not be a good thing to define: reference counting. Some people want to use refcounts, and believe that under certain circumstances they provide better performance than GC. I don't know if they're right, I suspect they are for some limited circumstances. A normal ref-count system can't be gauranteed to have no memory holes introduced by loops in the data. But, if the programmer causes no loops to come into being then he/she is safe. An implementation that used refcounting might not be of much general use, but for specific purposes, embedded programming for example, it might be useful. From gerold.penz at tirol.utanet.at Thu Dec 7 09:49:27 2006 From: gerold.penz at tirol.utanet.at (Gerold Penz) Date: Thu, 07 Dec 2006 15:49:27 +0100 Subject: How to create a global hotkey? In-Reply-To: <1165492421.317438.237350@j72g2000cwa.googlegroups.com> References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com> Message-ID: > I want my function to execute when the user presses the > hotkey anywhere. Hi! - XLib unter Linux: http://python-xlib.sourceforge.net/ - wxPython unter Windows: http://wxpython.org/docs/api/wx.Window-class.html#RegisterHotKey regards, Gerold :-) -- ________________________________________________________________________ Gerold Penz - bcom - Programmierung gerold.penz at tirol.utanet.at | http://gerold.bcom.at | http://sw3.at Ehrliche, herzliche Begeisterung ist einer der wirksamsten Erfolgsfaktoren. Dale Carnegie From jstroud at mbi.ucla.edu Fri Dec 22 20:02:45 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 23 Dec 2006 01:02:45 GMT Subject: scopes of local and global variable In-Reply-To: <87psabcvlc.fsf@pyenos.pyenos.org> References: <87tzzncx59.fsf@pyenos.pyenos.org> <87psabcvlc.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > Fredrik Lundh writes: > > >>Pyenos wrote: >> >> >>>#############################CODE############################## >>>t_len=0 >>>class WORK: >>> def getwork(self): >>> def formattable(table_to_process,type): >>>TYPE=["p","t","T","s","i"] #list of types to format >>> if type==TYPE[1]: >>> def format_t(): >>> row=[] >>> for col in table_to_process: >>> ####################### >>> # ERROR PRONE PART # >>> ####################### >>> if len(str(col))>t_len: >>> t_len=len(str(col)) >>> ####################### >>># Error message says: # >>># UnboundLocalError: local variable 't_len' referenced before assignment# >>> row+=col >>> if (table_to_process.index(col)+1)%7==0: >>> t_temp.append(row) >>> row=[] >>> format_t() >>>################################################################# >> >>wow. >> >> >>>Interpreter says that t_len is local variable although i have >>>specified t_len=0 in line 1. Also, although i've stated t_len=0 in >>>line 1, it says that t_len is referenced before assignment. >> >>each function introduces a new scope. >> >> > > > does class WORK inherit t_len=0 from line1? > > does def getwork() inherit t_len=0 from line1? > > does def formattable(table_to_process,type) inherit t_len=0 from line1? > > does def format_t() inherit t_len=0 from line1? > > thanks. > Yes and no, depending. The rule of thumb I use is that if you assign in a function, the name is not taken from the enclosing scope. For example, compare: # example 1 def doit(): t_len = 42 def nested(): print t_len nested() doit() # will print 42 # example 2 def doit(): t_len = 42 def nested(): if t_len > 0: print t_len else: t_len = 1 nested() doit() # will get "referenced before assignment" error You could make use of your WORK class here, depending on whether t_len makes sense as a member of the WORK class: class WORK: t_len = 0 def getwork(self): def formattable(table_to_process,type): # etc., etc. WORK.t_len = len(str(col)) James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From will.ware at gmail.com Fri Dec 15 11:46:14 2006 From: will.ware at gmail.com (Will Ware) Date: 15 Dec 2006 08:46:14 -0800 Subject: Restrictive APIs for Python In-Reply-To: <1166197755.103495.234230@16g2000cwy.googlegroups.com> References: <1166193072.925721.52780@80g2000cwy.googlegroups.com> <1166197755.103495.234230@16g2000cwy.googlegroups.com> Message-ID: <1166201174.540742.242670@f1g2000cwa.googlegroups.com> Gabriel Genellina wrote: > In Python, the usual way of saying "don't play with me" is prepending > an underscore: _private Thanks, I am familiar with that. > BTW, have you *ever* tested your code? Yes, we have a QA process. The problem is not that the code doesn't work, it does. It was developed by a mix of more and less experienced programmers, and early in the code's history, some hadn't been trained on the benefits of complying to an API, or Pythonic idioms like the leading underscore. So the code varies in its clarity, and some maintenance chores aren't as pleasant as they might be. I have found that the work of more experienced programmers often includes improving the quality of code written by less experienced programmers. Is this inconsistent with your own experience? From bborcic at gmail.com Thu Dec 14 08:03:09 2006 From: bborcic at gmail.com (Boris Borcic) Date: Thu, 14 Dec 2006 14:03:09 +0100 Subject: Routine for prefixing '>' before every line of a string In-Reply-To: <1166097838.257731.297110@l12g2000cwl.googlegroups.com> References: <1166097838.257731.297110@l12g2000cwl.googlegroups.com> Message-ID: <45814bb7_7@news.bluewin.ch> Sanjay wrote: > Hi All, > > Is somewhere a routine useful to convert a string to lines of maxsize, > each prefixed with a '>'. This is a typical requirement for 'keeping > existing text while replying to a post in a forum'. > > It can be developed, but if something obvious is already there(I being > new to python might not be aware), than it would be great just to reuse > it! > > thanks > sanjay > def fixlines(stuff) : for line in stuff.split(line_separator) : for chunkstart in range(0,len(line),maxsize) : yield prefix + line[chunkstart:chunkstart+maxsize] From david at david-steuber.com Fri Dec 15 04:57:21 2006 From: david at david-steuber.com (David Steuber) Date: 15 Dec 2006 04:57:21 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165737791.744375.190080@l12g2000cwl.googlegroups.com> <7x7ix0godv.fsf@ruckus.brouhaha.com> <1165741455.889300.327100@j44g2000cwa.googlegroups.com> <7xwt50qejd.fsf@ruckus.brouhaha.com> <1165802561.539960.174180@80g2000cwy.googlegroups.com> Message-ID: <87tzzxa3cu.fsf@david-steuber.com> "Wolfram Fenske" writes: > Paul Rubin writes: > > > "Wolfram Fenske" writes: > >> Yes, I wrote about it in another post. It was introduced in Python > >> 2.5. And if it hadn't been I'd still have to write code like this. > > > > You could do something with decorators that's not too bad. You'd end > > up writing: > > > > @withConnection > > def some_func(): > > do_whatever_stuff () > > Yes, now I can. But I had to wait until Python 2.4 to be able to > that. What I like so much about Lisp macros is that they allow me to > make these changes myself. Besides, who wants to write production code in a language that keeps changing? It's enough work just keeping up with new libraries. -- This post uses 100% post consumer electrons and 100% virgin photons. At 2.6 miles per minute, you don't really have time to get bored. --- Pete Roehling on rec.motorcycles I bump into a lot of veteran riders in my travels. --- David Hough: Proficient Motorcycling From jjl at pobox.com Tue Dec 5 05:04:13 2006 From: jjl at pobox.com (John J. Lee) Date: 05 Dec 2006 10:04:13 +0000 Subject: Printing Barcodes from webapp? References: <1165040626.505772.312350@j72g2000cwa.googlegroups.com> <1165063816.365760.264300@73g2000cwn.googlegroups.com> Message-ID: Dennis Lee Bieber writes: > On 04 Dec 2006 12:41:59 +0000, jjl at pobox.com (John J. Lee) declaimed the > following in comp.lang.python: > > > digits, through complicated encodings (my colleague Robin tells me US > > postal bar codes were a particular pain), up to funny-looking 2D "bar" > > Really? I seem to recall coding a GW-BASIC/Epson MX-80 compatible > routine to take a zip-code and produce the bar-code for it, on a TRS-80 > Mod 4. Wasn't for my use -- a co-worker wanted it (and had the "manual" > of markings allowed on an envelope). Apparently there's a new US postal barcode, a "four state" barcode. Presumably you drew the older simpler ones back when you were using the TRS-80... John From kentilton at gmail.com Mon Dec 11 23:24:07 2006 From: kentilton at gmail.com (Ken Tilton) Date: Mon, 11 Dec 2006 23:24:07 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4u6meeF161jbqU1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> <4u6meeF161jbqU1@mid.individual.net> Message-ID: greg wrote: > Bill Atkins wrote: > >> You're missing Ken's point, which is that in Lisp an s-expression >> represents a single concept - I can cut out the second form of an IF >> and know that I'm cutting the entire test-form. > > > For selecting a single form, that's true. For > more than one form (such as selecting some, but > not all, of the statements in a loop body) it's > not much different. > > But my point was that I don't find "manually > reindenting the lines" to be a chore. He made it > sound like you have to laboriously go through > and adjust the lines one by one, but it's not > like that at all. You shift them all at once > in a block. It is a gray area. Manually maintaining indentation does not have to be a "laborious chore" to slow down development. I believe it was in the mid 1980s when I turned to the developer sitting next to me and said, "I wonder how much time I spend re-tabbing my code?" That was probably Vax Basic or COBOL. I /think/ the editor had a block-tab capability, and I think I used same in some C IDES, but to be honest retabbling a few lines was not such a laborious chore that I would first do the select operation to be able to use it. Also, Python does not support a functional style of programming so the line is the only meaningful textual entity. In this sense the primitiveness of Python makes editing easier. Finally, Python is just a (fine) scripting language. Which means one does not tackle hard problems with it, the kind one figures out as one goes. That means less refactoring, and less refactoring means less slicing and dicing of the code. > Seeing as you asked, how much Python code have > you or Ken edited? See above. Not Python, but out the wazoo in other languages. Remember, we are not Lisp-only aliens, we program all the languages you program, plus one. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From timr at probo.com Tue Dec 12 01:41:19 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 12 Dec 2006 06:41:19 GMT Subject: possible php convert References: <880dece00612100436v1051977fk966b77eecb4296cd@mail.gmail.com> <880dece00612100436v1051977fk966b77eecb4296cd@mail.gmail.co m> Message-ID: Gabriel Genellina wrote: > >At Sunday 10/12/2006 09:36, Dotan Cohen wrote: > >>Hi all, I've been contemplating the switch to python from php. I'm no >>wiz, but I can get my way around with help form the online docs. I see >>that python has much less documentation available, so expect to hear >>from me a bit in the next few weeks. :) > >Uhm, have you looked at http://www.python.org/doc/ ? Personally, I really like the wiki-style user-aided documentation used for the PHP docs. They do get a certain amount of garbage, but it also gives you some great real-world examples of virtually every function. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From brenNOSPAMbarn at NObrenSPAMbarn.net Wed Dec 6 23:17:52 2006 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Thu, 07 Dec 2006 04:17:52 GMT Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> <1165298691.474503.184480@16g2000cwy.googlegroups.com> Message-ID: John Machin wrote: > Firstly, you may say that you want to look only at the ONE that is > actually bound to THE incorrect value, but the interpreter has in > general no way of telling which one is bad. For example: > > foo = "a" > bar = [1] > baz= "z" > goo = [26] > x = foo + bar > > This causes: "TypeError: cannot concatenate 'str' and 'list' > objects" > > Which ONE out of foo and bar is actually bound to THE "incorrect" > value? Did you mean to write "foo + baz", or did you mean to write > "goo + bar"? My amended proposal handles this, because the error message should point to the line position of the operand. (Or if it points to one of the operands, that's fine too, at least I know what's going on.) > Secondly, if you have so many variables referenced in one statement > all with the same operator (e.g. +) that you have difficulty in > working out where the problem is, I'd say that you have a statement > that is far too long, and you have far too many variables in your > function. See my example below. > Can you give a real example from your code where the location of > such a human error (you cause a variable to bound to a value of > inappropriate type) would be difficult to find, plus an estimate of > how often you would make such an error? Here is an example: self.outFile.write(str(len(self.hits)) + ' in ' + searchInfo.recordName + '\t' + ']['.join((a. group() for a in self.hits)) + '\n') This is from a text-searching tool I have written to search linguistic corpora. This statement writes a summary line to the output file indicating how many hits were found in that file. The problem in this line was that I'd forgotten to put str() around the len(). Now, it's not impossible to find the problem, because given my knowledge of the program I know that that's the only part of the line that would reasonably contain the number, but I still think it would be a lot easier if there were a caret in the error message pointing to the offending summand. I'm glad you asked this question, though, because in searching for examples in my code, I discovered that most of my beefs aren't actually of this type. A lot of them are things like this: someStr.split(someList) Here I meant to write someList[0] (say), but have inadvertently passed the list instead of one of its elements. In this case I receive an error message that says "TypeError: expected a character buffer object". My question is: why can this error message not say what was encountered INSTEAD of a character buffer object? A similar situation occurs when I do someVar[0] and get an "unsubscriptable object" error. The error does not even tell me the type of the offending value, just that it is unsubscriptable. So my conclusion from this is: is there a reason that every error message of the form "expected foo" or "this object cannot be frotzed" cannot be changed to something like "expected foo but found bar" or "this FooType object cannot be frotzed"? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From beliavsky at aol.com Fri Dec 1 18:50:00 2006 From: beliavsky at aol.com (Beliavsky) Date: 1 Dec 2006 15:50:00 -0800 Subject: How do I print a numpy array? In-Reply-To: References: <12n1b51i11rhv5e@corp.supernews.com> Message-ID: <1165017000.500270.188540@73g2000cwn.googlegroups.com> Robert Kern wrote: > Grant Edwards wrote: > > How do you print a numpy array? > > > > I tried the obvious print a, print `a`, and print str(a), but > > none of them work on anything other than trivially small > > arrays. Most of my real data is elided and replaced with > > ellipses. > > You might want to ask numpy questions on the numpy list: > > http://www.scipy.org/Mailing_Lists > > Use numpy.set_printoptions(threshold=sys.maxint) to disable all summarization. When I print an array in any language, I (and I think most programmers) expect by default to have all elements displayed. Matlab, R, and Fortran 95 have somewhat similar arrays to numpy, and that is what they do. I don't remember Numeric summarizing arrays by default. R has a "summary" function as well as a "print" function. From antroy at gmail.com Mon Dec 4 10:58:55 2006 From: antroy at gmail.com (Ant) Date: 4 Dec 2006 07:58:55 -0800 Subject: Printing unix Line endings from Windows. Message-ID: <1165247935.679325.242850@80g2000cwy.googlegroups.com> Hi all, I've got a problem here which has me stumped. I've got a python script which does some text processing on some files and writes it back out to the same file using the fileinput module with inplace set to True. The script needs to run from Windows, but the files need to be written with Unix line endings. Is there any way of doing this without having to post-process the file in binary mode (a-la the crlf.py script) Cheers, From gagsl-py at yahoo.com.ar Wed Dec 6 22:05:36 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 00:05:36 -0300 Subject: extension programing with c In-Reply-To: <20061206164142.99700.qmail@web53614.mail.yahoo.com> References: <20061206164142.99700.qmail@web53614.mail.yahoo.com> Message-ID: <7.0.1.0.0.20061206234411.0542f6d0@yahoo.com.ar> At Wednesday 6/12/2006 13:41, mahdieh saeed wrote: >I want to define extention module that connect to berkeley db. You know support for Berkeley DB comes with the standard library, don't you? Look at the bsddb module. >--------------------------------------------------------------------------------------------------------------- >function for define extention module is like this: >name=importBDB.c >------------------------------------------------------------------------ >#include >#include >CreateDatabase(char *); >static PyObject >*insert_data(PyObject *self,PyObject *args) { >char *databasename; >if (!PyArg_ParseTuple(args, "s", &databasename)) { >return NULL; >} >CreateDatabase(databasename); >Py_RETURN_NONE; >} >static PyMethodDef data_methods[] = { >{ "data", (PyCFunction)insert_data, METH_VARARGS, NULL }, >{ NULL, NULL, 0, NULL } >}; >PyMODINIT_FUNC initdata() { >Py_InitModule3("data", data_methods, "My first extension module."); >} >---------------------------------------------------------------------------------------------------------- Given that code, the source should be called data.c (not an absolute requisite, but at least it's easier that way). >my compiler is gcc and compiling it with this command: > >gcc -shared -I/usr/local/include/python2.4 >-I/usr/local/BerkeleyDB.4.5/include \ importBDB.c BDB.c \ >-L/usr/local/BerkeleyDB.4.5/lib -ldb-4.5 -o insert.so > >there is an error occurs like this: >gcc: importBDB.c: No such file or directory >gcc: -L/usr/local/BerkeleyDB.4.5/lib: No such file or directory >I know problem for compiler please help me What are those \ for? gcc is trying to compile something with a space in front of the name... Remove them and try again. Why insert.so? Note that this has nothing to do with Python... -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From aine_canby at yahoo.com Mon Dec 11 04:26:51 2006 From: aine_canby at yahoo.com (aine_canby at yahoo.com) Date: 11 Dec 2006 01:26:51 -0800 Subject: sys.stdin.encoding In-Reply-To: References: <1165825571.435369.150110@79g2000cws.googlegroups.com> Message-ID: <1165829211.214261.307740@n67g2000cwd.googlegroups.com> Duncan Booth skrev: > aine_canby at yahoo.com wrote: > > > The following line in my code is failing because sys.stdin.encoding is > > Null. > > I'll guess you mean None rather than Null. > > > This has only started happening since I started working with > > Pydef in Eclipse SDK. Any ideas? > > > > uni=unicode(word,sys.stdin.encoding) > > > You could give it a fallback value: > > uni = unicode(word, sys.stdin.encoding or sys.getdefaultencoding()) > > or even just: > > uni = unicode(word, sys.stdin.encoding or 'ascii') > > which should be the same in all reasonable universes (although I did get > bitten recently when someone had changed the default encoding in a system). Thanks for your help. The problem now is that I cant enter the Swedish characters ??? etc without getting the following error - Enter word> P?e Traceback (most recent call last): File "C:\Documents and Settings\workspace\simple\src\main.py", line 25, in archive.Test() File "C:\Documents and Settings\workspace\simple\src\verb.py", line 192, in Test uni=unicode(word,sys.stdin.encoding or sys.getdefaultencoding()) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128) The call to sys.getdefaultencoding() returns ascii. Since I can enter the characters ??? on the command line in Pydef/Eclipse doesn't that mean that the stdin is not ascii? What should I do? Thanks again, Aine. From python.list at tim.thechases.com Thu Dec 7 06:40:31 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 07 Dec 2006 05:40:31 -0600 Subject: how to get all the "variables" of a string formating? In-Reply-To: References: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> <1165431536.162899.15730@j72g2000cwa.googlegroups.com> Message-ID: <4577FDAF.2000709@tim.thechases.com> > I'd like to see this regex. And make sure it works correctly with this > format string: > > """%(key)s > %%(this is not a key)d > %%%(but this is)f > %%%%%%%(%(and so is this)%()%%)u > and don't forget the empty case %()c > but not %%%%%%()E > and remember to handle %(new > lines)X correctly > and %(percentages)%.""" > > It should list the keys as: > > 'key' > 'but this is' > '%(and so is this)%()%%' > '' > 'new\nlines' > 'percentages' > > > I love easy regexes :-) >>> r = re.compile(r'(?>> print r.sub(lambda x: '@@@%s@@@' % x.group(0), s) @@@%(key)@@@s %%(this is not a key)d @@@%%%(but this is)@@@f @@@%%%%%%%(%(and so is this)@@@@@@%()@@@%%)u and don't forget the empty case @@@%()@@@c but not %%%%%%()E and remember to handle @@@%(new lines)@@@X correctly and @@@%(percentages)@@@%. >>> keys = r.findall(s) >>> keys ['key', 'but this is', '%(and so is this', '', '', 'new\nlines', 'percentages'] The extra empty item (keys[3]) is from that pathological case. Otherwise, it seems to do the trick. -tkc ps: you're a cruel, cruel fellow for throwing out such a mind-bender this early in my morning. :) Thanks for the fun! From cjw at sympatico.ca Sat Dec 9 11:37:51 2006 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 09 Dec 2006 11:37:51 -0500 Subject: len() and PEP 3000 In-Reply-To: <5HSdh.15210$P04.6844@tornado.fastwebnet.it> References: <4tnqlkF13bbqeU1@mid.individual.net> <5HSdh.15210$P04.6844@tornado.fastwebnet.it> Message-ID: Giovanni Bajo wrote: > Thomas Guettler wrote: > >> I have read the FAQ to the len function: >> http://www.python.org/doc/faq/general/#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list > > Outdated. You want to read the new FAQ, here: > http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm Why not replace the __len__ method with a len property for strings, lists, tuples, dictionaries etc. __len__ is not very special and the property len eliminates the redundant parentheses. Colin W. From aboudouvas at panafonet.gr Tue Dec 5 11:30:51 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 5 Dec 2006 08:30:51 -0800 Subject: decorators question In-Reply-To: References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> <457476E6.5000603@youjoy.org> <1165269784.394649.7940@l12g2000cwl.googlegroups.com> Message-ID: <1165336251.552181.241750@80g2000cwy.googlegroups.com> >you're not listening. Be sure that i do...The fact that i come from another world does not mean that i am not listening, just that i find as strange some (new) things. Thank you all guys, i know what is happening now... Thanks again! kikapu From gagsl-py at yahoo.com.ar Thu Dec 28 22:43:23 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 29 Dec 2006 00:43:23 -0300 Subject: A stupid question In-Reply-To: <1167362866.807346.73510@73g2000cwn.googlegroups.com> References: <1167362866.807346.73510@73g2000cwn.googlegroups.com> Message-ID: <7.0.1.0.0.20061229003727.05a180f8@yahoo.com.ar> At Friday 29/12/2006 00:27, luxnoctis at gmail.com wrote: >I bought a floor model computer, and it came with all sorts of >ridiculousness on it that I promptly uninstalled. However, now whenever >I start windows I get a message saying "LoadLibrary (pythondll >) failed." It also says this when I try to download into a bittorrent >client, and it keeps it from downloading. What does this mean, and how >can I make it go away? Please copy the *exact* message that you see. python24.dll (or 23, or 25) is a shared component, installed on the system directory. If you delete it, you break all applications depending on it, like the bittorrent client. -- 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 From gagsl-py at yahoo.com.ar Wed Dec 20 09:11:10 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 20 Dec 2006 11:11:10 -0300 Subject: update attribute - (newbie) In-Reply-To: <4587FC12.2090806@websafe.com> References: <1166538800.915433.38680@79g2000cws.googlegroups.com> <4587FC12.2090806@websafe.com> Message-ID: <7.0.1.0.0.20061220110808.032b3950@yahoo.com.ar> At Tuesday 19/12/2006 11:49, Larry Bates wrote: > > I would like to have it that when I ask for p, method _get_p is always > > called so that attribute can be updated. How can I have this > > functionality here? thanks > > >Something like this? > >class A: > def __init__(self): > self.t=4 > return > > def __getattr__(self, name): > if name == 'p': return self.t > else: return self.__dict__[name] __getattr__ is called *after* normal lookup has failed, so using __dict__ here is useless (and wrong, because this method should raise AttributeError but will raise KeyError instead) A property is more convenient in this case. -- 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 From Thomas.Ploch at gmx.net Sun Dec 31 13:16:18 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Sun, 31 Dec 2006 19:16:18 +0100 Subject: Question concerning this list [WebCrawler] In-Reply-To: References: Message-ID: <4597FE72.5030909@gmx.net> John Nagle schrieb: > > Very true. HTML is LALR(0), that is, you can parse it without > looking ahead. Parsers for LALR(0) languages are easy, and > work by repeatedly getting the next character and using that to > drive a single state machine. The first character-level parser > yields tokens, which are then processed by a grammar-level parser. > Any compiler book will cover this. > > Using regular expressions for LALR(0) parsing is a vice inherited >>from Perl, in which regular expressions are easy and "get next > character from string" is unreasonably expensive. In Python, at least > you can index through a string. > > John Nagle I take it with LALR(0) you mean that HTML is a language created by a Chomsky-0 (regular language) Grammar? Thomas From eadmund42 at NOSPAMgmail.com Tue Dec 12 21:39:53 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 19:39:53 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165773218.686683.46640@16g2000cwy.googlegroups.com> Message-ID: "JShrager at gmail.com" writes: > > I have the code here (probably not the latest bcs I left the company > when it was acquired), let's do a little experiment, for what it's > worth: 89727 lines of Lisp code in 131 modules (lisp code files), 3306 > "(defun" (by grep|wc), and 261 "(defmacro". [We did NOT use macros as > functions!] [Note that lines of code doesn't really matter in Lisp.] Wow--my emacs install has 1,152,598 lines of code in 1,570 files, 29,244 defuns and 1,393 defmacros. This really doesn't prove anything whatsoever (as I imagine that your stuff was a _lot_ more complex), except maybe how great the FSF is for giving away this sort of thing for free. -- Robert Uhl `We're ten parsecs from Regina, we've got a full tank of LH-two, a half pack of cigarettes, I've dimmed the lights, and we're wearing sunglasses.' `Let's jump.' --Leslie Bates From pavlovevidence at gmail.com Sat Dec 16 21:57:49 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 16 Dec 2006 18:57:49 -0800 Subject: Has comparison of instancemethods changed between python 2.5 and 2.4? References: <4582CFA3.5040305@niessink.com><4583367D.7090508@niessink.com> <1166283262.352367.61610@t46g2000cwa.googlegroups.com> Message-ID: <1166324269.005315.199730@16g2000cwy.googlegroups.com> Frank Niessink wrote: > Ziga Seilnacht: > > This method was changed in Python 2.5. Previously, two instancemethods > > compared equal if their im_self attributes were *identical* and their > > im_func attributes were equal. Now, they compare equal if their im_self > > attributes are *equal* and their im_func attributes are equal. > > Thanks Ziga, that explains very clearly why I get the behavior I see. > > > If you think this is a bug, you should report it to the bugtracker: > > http://sourceforge.net/bugs/?group_id=5470 > > Well, from where I am it sure feels like a bug in python, so I've > submitted a bug report: > http://sourceforge.net/tracker/index.php?func=detail&aid=1617161&group_id=5470&atid=105470 In the interests of practicality beating purity, I would agree that the 2.4 behavior is better. (I don't know if it would be classified as a bug; the behavior of methods under == isn't documented AFAICT.) There's no question that the 2.5 behavior is purer, but I can't imagine a single use case for it. In the meanwhile, you could work around it by using this function instead: def same_method(a,b): return a.im_class is b.im_class and a.im_func is b.im_func and a.im_self is b.im_self Carl Banks From bbrown at speakeasy.net Sat Dec 9 16:09:49 2006 From: bbrown at speakeasy.net (Robert Brown) Date: Sat, 09 Dec 2006 16:09:49 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <87d56tkxp2.fsf@snobis.de> <7xpsatb1l2.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > For a long time Scheme had no macros, and Scheme developers who were > exceedingly familiar with Common Lisp were nonetheless willing to get > by without them. So I have to think macros aren't all THAT important. > Scheme did eventually get macros, but somewhat different from CL's. Macros are important enough that all the old Scheme implementations I used offered macros in the style of Lisp's defmacro. Lisp hackers did not have to suffer without them when writing Scheme code. Relatively recently, the Scheme standard was augmented with hygenic macros, a different beast. Scheme standardizes something only when there's nearly universal support for it, so features appear in the language standard very slowly. bob From http Sun Dec 10 03:13:00 2006 From: http (Paul Rubin) Date: 10 Dec 2006 00:13:00 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165737791.744375.190080@l12g2000cwl.googlegroups.com> Message-ID: <7x7ix0godv.fsf@ruckus.brouhaha.com> "Wolfram Fenske" writes: > In Lisp, I could just write a macro "WITH-CONNECTION" that takes the > name of the connection variable and the code for "do something with > the connection" as arguments. Actually, I ended up writing something > like it as a function in Python: > > --8<---------------cut here---------------start------------->8--- > def withConnection(self, fun): > self.lock.acquire() # ... Do you know about Python's "with" statement? You'd define a class for those db connections, that acquire the lock on entry, and release it on exit. From int2k at gmx.net Sun Dec 10 04:04:16 2006 From: int2k at gmx.net (Wolfram Fenske) Date: 10 Dec 2006 01:04:16 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7x7ix0godv.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165737791.744375.190080@l12g2000cwl.googlegroups.com> <7x7ix0godv.fsf@ruckus.brouhaha.com> Message-ID: <1165741455.889300.327100@j44g2000cwa.googlegroups.com> Paul Rubin writes: > "Wolfram Fenske" writes: >> In Lisp, I could just write a macro "WITH-CONNECTION" that takes the >> name of the connection variable and the code for "do something with >> the connection" as arguments. Actually, I ended up writing something >> like it as a function in Python: >> >> --8<---------------cut here---------------start------------->8--- >> def withConnection(self, fun): >> self.lock.acquire() # ... > > Do you know about Python's "with" statement? You'd define a class for > those db connections, that acquire the lock on entry, and release it > on exit. Yes, I wrote about it in another post. It was introduced in Python 2.5. And if it hadn't been I'd still have to write code like this. -- Wolfram Fenske A: Yes. >Q: Are you sure? >>A: Because it reverses the logical flow of conversation. >>>Q: Why is top posting frowned upon? From nick at craig-wood.com Mon Dec 4 06:30:04 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 04 Dec 2006 05:30:04 -0600 Subject: os.mkdir and mode References: <1165043870.135812.232530@73g2000cwn.googlegroups.com> <4571C5F1.4080209@v.loewis.de> Message-ID: Martin v. L?wis wrote: > Nick Craig-Wood schrieb: > > So it looks like python mkdir() is applying the umask where as > > /bin/mkdir doesn't. From man 2 mkdir > > Actually, mkdir(1) has no chance to not apply the umask: it also > has to use mkdir(2), which is implemented in the OS kernel, and > that applies the umask. Try Yes you are right of course. I didn't think that statment through did I! > strace mkdir -m770 test > > to see how mkdir solves this problem; the relevant fragment > is this: > > umask(0) = 022 > mkdir("test", 0770) = 0 > chmod("test", 0770) = 0 > > So it does *both* set the umask to 0, and then apply chmod. > > Looking at the source, I see that it invokes umask(0) not to > clear the umask, but to find out what the old value was. > It then invokes chmod to set any "special" bits (s, t) that > might be specified, as mkdir(2) isn't required (by POSIX spec) > to honor them. That makes sense - the odd sequence above is one of those Unix workarounds then... -- Nick Craig-Wood -- http://www.craig-wood.com/nick From vinjvinj at gmail.com Wed Dec 6 15:05:36 2006 From: vinjvinj at gmail.com (vj) Date: 6 Dec 2006 12:05:36 -0800 Subject: I'm looking to learn pyqt Message-ID: <1165435536.605407.112930@79g2000cws.googlegroups.com> Is there a a tutorial or a sample application I can start with (that works with qt4 and pyqt4)? Thanks, VJ From amichail at gmail.com Fri Dec 1 04:24:47 2006 From: amichail at gmail.com (Amir Michail) Date: 1 Dec 2006 01:24:47 -0800 Subject: python vs java & eclipse Message-ID: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> Hi, It seems to me that measuring productivity in a programming language must take into account available tools and libraries. Eclipse for example provides such an amazing IDE for java that it is no longer obvious to me that one would be much more productive in python for medium sized projects. Sure, all that Java static typing can be painful, but Eclipse takes some of that pain away. Moreover, static typing can result in better on-the-fly error detection and refactoring support. Any thoughts on this? Amir From kentilton at gmail.com Fri Dec 8 09:55:55 2006 From: kentilton at gmail.com (Ken Tilton) Date: Fri, 08 Dec 2006 09:55:55 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <02feh.18$yP7.17@newsfe08.lga> Mark Tarver wrote: > How do you compare Python to Lisp? Lisp programmers are smarter and better looking. And better programmers. Not sure if that is what you were after, though. > What specific advantages do you > think that one has over the other? http://www.googlefight.com/index.php?lang=en_GB&word1=parentheses&word2=white+space Ouch. hth,kt -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From michele.simionato at gmail.com Sat Dec 2 09:47:47 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 2 Dec 2006 06:47:47 -0800 Subject: Is there a reason not to do this? In-Reply-To: References: <1164983226.620035.218790@l12g2000cwl.googlegroups.com> Message-ID: <1165070867.201879.200070@80g2000cwy.googlegroups.com> Ron Garret wrote: > > Doesn't work for me: > > >>> c2 > <__main__.C2 instance at 0x51e850> > >>> c2.m1() > G > >>> class C2: > ... __metaclass__ = modify_in_place > ... def m1(self): print 'Q' > ... > >>> c2.m1() > G > >>> C2().m1() > Q I assume your original C2 class was defined in a different module, not in the current global namespace. What do you get from c.__class__.__module__ ? It should be __name__ for this approach to work. class C2: def m1(self): return 'G' c = C2() def modify_in_place(name,bases,clsdict): cls = globals()[name] for attr,val in clsdict.iteritems(): setattr(cls,attr,val) return cls # Replace second C2 class above with this class C2: __metaclass__ = modify_in_place def m1(self): return 'Q' assert c.m1() == 'Q' assert c.__class__.__module__ == __name__ # make sure c.__class__ is defined in the current module Michele Simionato From georgi at molgen.mpg.de Mon Dec 18 06:06:43 2006 From: georgi at molgen.mpg.de (Benjamin Georgi) Date: Mon, 18 Dec 2006 12:06:43 +0100 Subject: parsing a dictionary from a string In-Reply-To: References: <4582B45E.6000405@molgen.mpg.de> Message-ID: <45867643.2070702@molgen.mpg.de> Fredrik Lundh wrote: > Benjamin Georgi wrote: > >> I could use some help extracting the keys/values of a list of >> dictionaries from a string that is just the str() representation of the >> list (the problem is related to some flat file format I'm using for file >> IO). >> >> Example: >> >>> s = str(dict_list) >> >>> s >> '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]' >> >> Then, what I want to do is to reconstruct dict_list given s. >> Now, one possible solution would be >> >> >>> dict_list = eval(s) >> >> but since the content of s cannot be blindly trusted I`d rather not do >> it that way. Basically my question is whether there is another solution >> which is simpler than using regular expressions. > > here are a couple of cut-and-paste alternatives: > > use the tokenizer and a simple parser pattern: > > http://groups.google.com/group/comp.lang.python/msg/a34397ba74892b4e > > use the compiler module and analyze the parse tree: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 > > note that you cannot parse Python's expression syntax with plain regular > expressions; RE's are only good enough for lexical analysis. > > > Problem solved. Thanks to everybody who answered. Benjamin From google at mrabarnett.plus.com Tue Dec 12 17:55:03 2006 From: google at mrabarnett.plus.com (MRAB) Date: 12 Dec 2006 14:55:03 -0800 Subject: Lookup caching In-Reply-To: <457dd837$0$4242$4fafbaef@reader1.news.tin.it> References: <457b69ec$0$16153$4fafbaef@reader3.news.tin.it> <457dd837$0$4242$4fafbaef@reader1.news.tin.it> Message-ID: <1165964103.102679.63130@l12g2000cwl.googlegroups.com> Andrea Griffini wrote: > Gabriel Genellina wrote: > > At Saturday 9/12/2006 23:04, Andrea Griffini wrote: > > > >> I implemented that crazy idea and seems working... in its > >> current hacked state can still pass the test suite (exluding > > > > What crazy idea? And what is this supposed to do? > > > The idea is to avoid looking up constants several times > into dictionaries that didn't change (e.g. builtins). > > Reading a bit about other optimization proposals I didn't > find a similar one so I decided to invest some spare time > in it. The idea is > > 1) Add a "timestamp" to dictionaries, so when a dictionary > is changed the timestamp gets updated > > 2) Store a cached lookup for constants; the cached lookup > is stored as a timestamp value and a naked pointer to > the result. The algorithm for the lookup of a given > constant is: > > if ( <> == d->timestamp) > { > x = <>; > } > else > { > x = PyDict_GetItem(d, key); > <> = d->timestamp; > <> = x; > } > > using a naked pointer is safe because it will be used > only if the dictionary wasn't touched, hence the value > is surely still alive. > > The original place I thought about where to store the > cached lookup was the bytecode, however after reading > python sources I resorted instead to a dedicated space > inside the code object. The code for LOAD_GLOBAL uses > something like > > if (co->co_cachedtstamps[oparg] == d->timestamp) > ... > > i.e. I used an array indexed by the index of the co_name > used for lookups. > > The patched code is currently working, however I found > that while the hit/miss ratios are impressive (as I > expected) the speedup is simply absent. Moreover there > is no difference at all between paying for the timestamp > handling and NOT using the cached lookups or instead > paying AND using the cached lookups (!). > Absurdely python on my PC runs faster if I in addition > to the cached lookup code also leave in place the > hit/miss statistics (a few static ints increment and > a static atexit-ed output function). > Also it made a lot of difference about where the > timestamp was placed inside the dictobject structure... > > In addition to the not impressive results (my patched > python now is just a bit *slower* than original one :-D) > there is also another complication. The LOAD_GLOBAL > actually needs TWO lookups, so I used two cached results > (one for globals, one for builtins). > The ideal solution however IMO would be in this case > to have two timestamps and one cached value instead... > (if neither dict was touched since last lookup then the > result will be the cached one). > [snip] What are you using for the timestamp? Are you calling a function to read a timer? If so, you could try something that's 'cheaper' like a modification counter instead, ie a counter that's incremented each time the dict is modified. From nagron at sbcglobal.net Sat Dec 30 13:38:00 2006 From: nagron at sbcglobal.net (Neil Agron) Date: Sat, 30 Dec 2006 10:38:00 -0800 Subject: Chris Akre Message-ID: <000e01c72c41$a2bf2240$1a1afea9@DDQWJG31> Chris, If my name is familiar, please contact me. -Neil -------------- next part -------------- An HTML attachment was scrubbed... URL: From webraviteja at gmail.com Wed Dec 27 09:39:16 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 27 Dec 2006 06:39:16 -0800 Subject: Xah's Edu Corner: Introduction to 3D Graphics Programing In-Reply-To: <1167208399.089326.213540@a3g2000cwd.googlegroups.com> References: <1166836083.084101.25870@73g2000cwn.googlegroups.com> <458d7899$0$8725$ed2619ec@ptn-nntp-reader02.plus.net> <1167208399.089326.213540@a3g2000cwd.googlegroups.com> Message-ID: <1167230356.551596.193550@73g2000cwn.googlegroups.com> Xah Lee wrote: > Regarding VisualPython... i saw a demo in 2002 by a professor > friend. I think it is good. Though, why is its licensing not GPL or > otherwise Open Source? That's kinda odd since Pyhton is. You are confusing VPython with Activestate's Visual Python IDE plugin for Visual Studio. >From VPython's home page in very bold font - "VPython is free and open-source" http://www.vpython.org/ From isaac.rodriguez at comcast.net Sun Dec 31 06:57:04 2006 From: isaac.rodriguez at comcast.net (Isaac Rodriguez) Date: 31 Dec 2006 03:57:04 -0800 Subject: Are all classes new-style classes in 2.4+? Message-ID: <1167566224.439844.267250@42g2000cwt.googlegroups.com> Hi, This is probably a very basic question, but I've been playing with new style classes, and I cannot see any difference in behavior when a declare a class as: class NewStyleClass(object): or class NewStyleClass: I declare property members in both and it seems to work the exact same way. I am using Python 2.4, and I was wondering if by default, all classes are assumed to be derived from "object". If not, can someone point me to some place where I can learn more about new-style classes and their advantages? All the documentation I've found is very vague. Thanks, - Isaac. From robert.kern at gmail.com Mon Dec 4 20:30:55 2006 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 04 Dec 2006 19:30:55 -0600 Subject: Why not just show the out-of-range index? In-Reply-To: <1165279745.267190.288060@80g2000cwy.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165264641.125857.85980@80g2000cwy.googlegroups.com> <1165270969.942437.302020@n67g2000cwd.googlegroups.com> <1165279745.267190.288060@80g2000cwy.googlegroups.com> Message-ID: rurpy at yahoo.com wrote: > Robert Kern wrote: >> rurpy at yahoo.com wrote: >>> I saw no posts where there OP insulted anybody without being >>> insulted first. It is ironic the Mr. Kern was the most consistent >>> insulter while at the same time accusing the OP of rudeness. >> As I said, insult is in the ear of the listener, so I apologize if anyone >> construed my comments as insults. However, facts are facts, and I stated them as >> I believe them. If you can pick out the precise comments that you felt were >> insulting, I will be happy to attempt clarifying them in a way that you do not >> find insulting. > > Facts? > > As I explained in another post, "encouraging" someone to submit > a patch without a clue about the poster's abilities or resources > is offensive. I can't even begin to fathom that. I pointed him to the one path that will (nearly) ensure that he gets the fix that he wants. >> "begging for a fix on comp.lang.python is ..." > I didn't see the OP "begging" for anything. As you wish. I'll admit that the choice of words had more emotional baggage than perhaps the situation warranted. But you can't tell me that his choice of words had any less. Or yours. >> "His suggestion that his time is worth more than that of anyone else..." > again (as the OP pointed out) no such claim was > made. In your words, his "meaning is clear". >> "and yes, you are being incredibly rude and insulting" > By responding in kind? I thought he was quite restrained > given the provocation. Given that I don't understand how pointing him to appropriate actions to take to get his feature request implemented is a provocation, I don't buy this one, either. >> "The way that you have been acting..." > Funny, I thought he was posting to c.l.p. Sounds like > he is a petulant 6 year old child. Pick any synonym you like, but I do believe that adults are capable of "acting". I thought "act" was the least emotional and most appropriate of the bunch. Perhaps I was wrong. > In virtually every one of your posts you said things that > I certainly would have been offended by. I'll admit that you do seem easily offended. >> "You're also missing that *I'm trying to help you*" > > I hope you understand that I'm trying to help *you*? Yes, thank you. I specifically asked for clarification, and you provided it. I'm not sure why you think that I wouldn't understand that. As Russ has been fighting every practical suggestion (which I hope he can separate out from what he believes are insults), I have no way of knowing that he understands that. -- 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 From steve at REMOVE.THIS.cybersource.com.au Sun Dec 31 08:28:21 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 01 Jan 2007 00:28:21 +1100 Subject: Are all classes new-style classes in 2.4+? References: <1167566224.439844.267250@42g2000cwt.googlegroups.com> Message-ID: On Sun, 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez wrote: > Hi, > > This is probably a very basic question, but I've been playing with new > style classes, and I cannot see any difference in behavior when a > declare a class as: > > class NewStyleClass(object): > > or > > class NewStyleClass: > > I declare property members in both and it seems to work the exact same > way. Then you aren't looking very closely. Try with a calculated property. >>> class New(object): ... def __init__(self): ... self._n = 1 ... def getter(self): ... return "spam " * self._n ... def setter(self, n): ... self._n = n ... spam = property(getter, setter, None, None) ... >>> obj = New() >>> obj.spam 'spam ' >>> obj.spam = 3 >>> obj.spam 'spam spam spam ' >>> obj.spam = 7 >>> obj.spam 'spam spam spam spam spam spam spam ' Now try with an old-style class. >>> class Old: ... def __init__(self): ... self._n = 1 ... def getter(self): ... return "spam " * self._n ... def setter(self, n): ... self._n = n ... spam = property(getter, setter, None, None) ... >>> obj = Old() >>> obj.spam 'spam ' >>> obj.spam = 3 >>> obj.spam 3 Properties should not be used with old-style classes because they just don't work correctly. -- Steven. From kibleur.christophe at gmail.com Sun Dec 10 04:46:22 2006 From: kibleur.christophe at gmail.com (Tool69) Date: 10 Dec 2006 01:46:22 -0800 Subject: oo problem Message-ID: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> Hi, I've got a simple but difficult problem : Suppose I've got a Paper class, on wich I can draw i.e a rectangle, a circle or whatever. class Paper(...): def __init__(self, paperx, papery): self.paperx = paperx self.papery = papery .... def draw(self, Primitive_Object): .... class Rectangle( ): <--- a Primitive_Object ... Now, inside my Rectangle class, I need to recover the Paper instance who called it (because I need the paper sizes to calculate something). I now I can use a global variable, say " _paper" and then, inside my Paper.__init__() write something like this : global _paper _paper = [paperx,papery] But it has drawbacks : what if I've got several Paper instances ? I don't know if I'm clear enought, Thanks for your help : 6TooL9 From larry.bates at websafe.com Wed Dec 27 19:41:18 2006 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 27 Dec 2006 18:41:18 -0600 Subject: can't instantiate following inner class In-Reply-To: <87mz586eyx.fsf@pyenos.pyenos.org> References: <87mz586eyx.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > class One: > Two() #can't instantiate > class Two: > Three() #can't instantiate > class Three:pass > > > You keep posting examples with the same problems that others have addressed. It appears you are trying to write Python in a way that some "other" language works. You really should see the posted solutions and go through the tutorial before posting again. Note the following is "normally" not used Python: Two() This would instantiate a Two class that wouldn't be bound to anything so you could never access it again in the future. It would then be thrown away by garbage collection. Proper way is: class One: def __init__(self): self.Two=Two() Of course Two must be a proper class definition also. class Two: def __init__(self): self.Three=Three() class Three: pass -Larry From tjreedy at udel.edu Tue Dec 12 20:18:44 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Dec 2006 20:18:44 -0500 Subject: Inconsistency in dictionary behaviour: dict(dict) not calling__setitem__ References: <1165948261.745137.88540@j72g2000cwa.googlegroups.com> Message-ID: "Almad" wrote in message news:1165948261.745137.88540 at j72g2000cwa.googlegroups.com... > Hello, > > I discovered this behaviour in dictionary which I find confusing ... > However, when constructing dictionary with dictionary in constructor > like d = RegisterMap({'k':'v'}), __setitem__ is not called, d.__setitem__(k,v) is the internal translation of d[k] = v (when such is explicitly written in this code). d.__init__(otherdict) need not go thru that interface if a more direct means is available. >so workaround is needed: Your 'workaround' seems to be the proper solution. > Am I doing something wrong Denigrating a solution because it does not meet your expectation. Your are not the first to do this ;-). tjr From http Thu Dec 14 04:04:57 2006 From: http (Paul Rubin) Date: 14 Dec 2006 01:04:57 -0800 Subject: variables with dynamicly generated names References: Message-ID: <7xmz5qalvq.fsf@ruckus.brouhaha.com> avlee writes: > Is it possible to use in python variables with dynamicly created names ? Yes, but don't. > How ? You almost certainly want to use something like a dictionary instead. From andrew at farwestbilliards.com Wed Dec 20 00:20:01 2006 From: andrew at farwestbilliards.com (Andrew Sackville-West) Date: Tue, 19 Dec 2006 21:20:01 -0800 Subject: MySQLdb, lots of columns and newb-ness In-Reply-To: <1166585698.732087.100750@79g2000cws.googlegroups.com> References: <1166585698.732087.100750@79g2000cws.googlegroups.com> Message-ID: <20061220052000.GB14968@localhost.localdomain> On Tue, Dec 19, 2006 at 07:34:58PM -0800, Todd Neal wrote: > Andrew Sackville-West wrote: > > > > I can successfully connect to mysql and do stuff to my tables my > > specific problem is how to efficiently put those 132 fields into the > > thing. All I have been able to figure out is really ugly stuff like: > > build the mysql statement out of various pieces with appropriate > > commas and quote included. stuff like (not tested) > > > > I just started looking into Python myself, so someone can probably > clean this up or suggest a better way, but this may work: okay, let me run through this and see if I understand: > > > import MySQLdb > > fields = ["field1\r\n","field2\r\n","field3\r\n"] build a list of data fields to be inserted (whatever method) > > def escapeAndQuote(x): > return "\"%s\"" % MySQLdb.escape_string(x) not at the right machine to read up on this but obviously it cleans up the strings and inserts the quotes around each field. > > values = ", ".join([escapeAndQuote(f[:-2]) for f in fields]) crap. I knew about .join. that was really the part I was missing. > q = "insert into daily values(%s)" % values > make the query statement. > > In testing I got: > > >>> fields = ["field1\r\n","field2\r\n","field3\r\n"] > >>> values = ", ".join([escapeAndQuote(f[:-2]) for f in fields]) > >>> values > '"field1", "field2", "field3"' > >>> q = "insert into daily values(%s)" % values > 'insert into daily values("field1", "field2", "field3")' > cool! thanks Todd. A > > > Todd > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From hg at nospam.org Mon Dec 4 07:47:32 2006 From: hg at nospam.org (hg) Date: Mon, 04 Dec 2006 06:47:32 -0600 Subject: get script path References: <%7Uch.38012$1w6.17240@newsfe16.lga> <1165236740.983496.307140@f1g2000cwa.googlegroups.com> Message-ID: Rob Wolfe wrote: > > hg wrote: >> Hi, >> >> must I parse argv[0] to get it, or is there an easier way (that works >> under Windows and *nix)? >> >> Ex: >> >> python /home/hg/test/test.py ==> test.py #knows it is in /home/hg/test > > IMHO it is easy enough: > >>>> dname, fname = os.path.split("/home/hg/test/test.py") >>>> dname > '/home/hg/test' > > -- > HTH, > Rob thanks From jstroud at mbi.ucla.edu Fri Dec 15 01:55:08 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 15 Dec 2006 06:55:08 GMT Subject: skip last line in loops In-Reply-To: References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: James Stroud wrote: > eight02645999 at yahoo.com wrote: >> hi, >> how can i skip printing the last line using loops (for /while) >> >> eg >> >> for line in open("file): >> print line. >> >> I want to skip printing last line of the file.thanks >> > > afile = open(filename) > > xlines = afile.xreadlines() > > aline = xlines.next > for nextline in xlines: > print aline > aline = nextline > > James Shoule be aline = xlines.next() From m_tayseer82 at yahoo.com Sun Dec 3 15:10:38 2006 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Sun, 3 Dec 2006 12:10:38 -0800 (PST) Subject: please provide urls for some python success stories. In-Reply-To: Message-ID: <20061203201038.87330.qmail@web31107.mail.mud.yahoo.com> Hello Krishnakant There is a book "Python success stories". Download the 2 volumes from here http://pythonology.org/success If you want to convince java programmers to use python, show them this presentation from PyCon2003 "The seven habits of highly effective technology disruption" www.infoether.com/~rich/pycon2003.pdf It shows how to use MSAgent technology in java. Don't forget to tell them about Jython --------------------------------- Everyone is raving about the all-new Yahoo! Mail beta. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pyenos at pyenos.org Wed Dec 27 18:37:12 2006 From: pyenos at pyenos.org (Pyenos) Date: 28 Dec 2006 10:37:12 +1100 Subject: failing to instantiate an inner class because of its order References: <87fyb16icw.fsf@pyenos.pyenos.org> <877iwc7w56.fsf@pyenos.pyenos.org> Message-ID: <873b707vx3.fsf@pyenos.pyenos.org> Pyenos writes: > Pyenos writes: > > > class Model: > > Controller() #problem > > > > class View: > > Model() > > > > class Controller:pass > > > > > > Python interpreter complains that 'Name Error: Controller()' not defined. > > > > Following Edward Kozlowski's advice I can suggest to myself a solution: > > class Model:pass > > class View: > Model() #this part is fine > > class Controller: > def __init__(self): > self.Model=Model() > > Controller.Model.Controller() #solution class Model: def fuck(self):print "fuck!" class View: Model() #this part is fine class Controller: def __init__(self): self.Model=Model() Controller().Model.fuck() #actually slight problem in previous solution Has to call in this way. I have confirmed this works. From caleb.hattingh at gmail.com Fri Dec 15 03:53:35 2006 From: caleb.hattingh at gmail.com (Caleb Hattingh) Date: 15 Dec 2006 00:53:35 -0800 Subject: automatically grading small programming assignments In-Reply-To: References: Message-ID: <1166172815.068281.65710@16g2000cwy.googlegroups.com> Hi Brian You could make great use of XML-RPC here. XML-RPC is /really/ easy to use. Here is a simple example: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81549 You put procedures on the server that will check the args against a the required result, and report back to the student whether it passes or fails. Here is another example using xml-rpc over https, for security: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496786 So, the idea is that the student calls a procedure on the xml-rpc server (which you set up), and passes his results as an argument, and your server procedure can return True or False. One benefit is that if you change the input to the tests, you need only update the server. Actually, you could let the procedures on the server accept test input and student results, and return True or False. This would be cool :) Caleb On Dec 14, 6:27 pm, Brian Blais wrote: > Hello, > > I have a couple of classes where I teach introductory programming using Python. What > I would love to have is for the students to go through a lot of very small programs, > to learn the basic programming structure. Things like, return the maximum in a list, > making lists with certain patterns, very simple string parsing, etc. Unfortunately, > it takes a lot of time to grade such things by hand, so I would like to automate it > as much as possible. > > I envision a number of possible solutions. In one solution, I provide a function > template with a docstring, and they have to fill it in to past a doctest. Is there a > good (and safe) way to do that online? Something like having a student post code, > and the doctest returns. I'd love to allow them to submit until they get it, logging > each attempt. > > Or perhaps there is a better way to do this sort of thing. How do others who teach > Python handle this? > > thanks, > > Brian Blais > > -- > ----------------- > > bbl... at bryant.edu > http://web.bryant.edu/~bblais From grisha at apache.org Mon Dec 25 13:07:56 2006 From: grisha at apache.org (Gregory (Grisha) Trubetskoy) Date: Mon, 25 Dec 2006 13:07:56 -0500 Subject: ANNOUNCE: Mod_python 3.3.0b (Beta) Message-ID: <20061225130442.O61514@grisha.dyndns.org> The Apache Software Foundation and The Apache HTTP Server Project are pleased to announce the 3.3.0b (Beta) release of mod_python. Version 3.3.0b of mod_python features several new functions and attributes providing better access to apache internals, as well as many bug fixes and various performance and security improvements. A detailed description of the changes is available in Appendix A of the mod_python manual, also available here http://www.modpython.org/live/mod_python-3.3.0b/doc-html/app-changes-from-3.2.10.html Beta releases are NOT considered stable and usually contain bugs. This release is intended to solicit widespread testing of the code. We strongly recommend that you try out your existing applications and experiment with new features in a non-production environment using this version and report any problems you may encounter so that they can be addressed before the final release. Preferred method of reporting problems is the mod_python user list mod_python at modpython.org. Mod_python 3.3.0b is available for download from: http://httpd.apache.org/modules/python-download.cgi For more information about mod_python visit http://www.modpython.org/ Regards, The Apache mod_python team. From researchbase at gmail.com Fri Dec 1 06:19:04 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Fri, 1 Dec 2006 16:49:04 +0530 Subject: python vs java & eclipse In-Reply-To: <8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com> References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com> Message-ID: just used the py dev plugin for eclipse. it is great. auto indentation and intellisence. and all other things. so now how does it look from this end? python + productivity and eclipse + productivity = double productivity! only problem with the plugin is that I find it difficult to manage the script running. I open a command prompt and run the scripts manually. any suggestion for this. for example I had name = raw_input("please enter your name") and the moment I type the first letter on the keyboard the code execution moves over to the next statement. should it not wait for the return key as it always does? Krishnakant. From python at hope.cz Tue Dec 26 01:10:17 2006 From: python at hope.cz (Lad) Date: 25 Dec 2006 22:10:17 -0800 Subject: Can Python help? Message-ID: <1167113417.061901.287410@73g2000cwn.googlegroups.com> On my website I allow users to upload files. I would like a user to see how much time is left before a file is uploaded. So, I would like to have a progress bar during a file uploading. Can Python help me with that?Or how can be a progress bar made? Thank you for ideas. La. From rupole at hotmail.com Wed Dec 20 07:42:06 2006 From: rupole at hotmail.com (Roger Upole) Date: Wed, 20 Dec 2006 07:42:06 -0500 Subject: Windows Authetication vs seperate process References: <1166459095.924198.62170@n67g2000cwd.googlegroups.com> Message-ID: <1166618733_4145@sp6iad.superfeed.net> imageguy1206 at gmail.com wrote: >I was wondering of someone could steer me in the right direction. > > We have a package that we would like to "secure" so that only specific > individuals can access specific portions of the application. Our > wxPython application will revolve around updating a central database > with information submitted from the app. We will eventually have a web > front end fo rsome aspects of the app. > > With several packages I have seen options to "Use Windows > Authentication", which seems to mean that "If the user has > authenticated and signed onto Windows, then our application will use > their windows userid and we will just focus on the the tasks within our > application the user is authorized to perform" > > Does anyone have any experience using this type of authentication > scheme ? > > Any related tips or suggestions ? > > I have found a few wikipedia entries, but they seem to be more related > to webpages, etc. > > Thanks. > The pywin32 package includes the functions needed to do this type of authentication. See \win32\Demos\security\sspi for some examples that work out of the box with NTLM. Roger ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From webraviteja at gmail.com Mon Dec 11 06:01:32 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 11 Dec 2006 03:01:32 -0800 Subject: merits of Lisp vs Python In-Reply-To: <457d2b13.3849154@news.readfreenews.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165824471.730090.153530@j72g2000cwa.googlegroups.com> <1165825648.930965.208130@j72g2000cwa.googlegroups.com> <457d2b13.3849154@news.readfreenews.net> Message-ID: <1165834892.338714.34850@16g2000cwy.googlegroups.com> Timofei Shatrov wrote: > But, you have to admit that it looks horrible (at least at the first glance). If > there's some programming style that I absolutely can't stand, it would be the > one where programmer writes a huge block of commentary describing what a > function does, followed by one-liner of code You Sir, are no fan of Literate Programming :-). > information in itself. With doctest it is even worse, because examples also > contain superfluous information. Everyone can just copy-paste the code in REPL > and see what happens when you execute it. And doctest automates such REPL tests. Like macros, don't knock it till you try it. > Besides that, there are many reasons > why tests should be stored in a separate file, or at least not in the same > function that they are testing. You need not have doctest as a part of source code. You can also create a separate documentation file that contains prose as well as tests intervening. http://www.python.org/doc/lib/doctest-simple-testfile.html Combine it with ReStructured Text and you have a wonderful documentation and testing solution in one place. Personally, I like this a lot better than Javadoc style documentation where usage examples are often absent. > Also Wikipedia article contains some "Cons of doctest" that look pretty nasty: Of course, doctest is hardly the ultimate testing solution. But it does an admirable job for many cases where you don't need to setup elaborate tests. > It's not surprising that no one uses this stuff for serious work. I have seen enough libraries that use doctest. Zope, Twisted and Paste are some of the popular Python projects in that use it. Epydoc supports it as well. From i at me.net.nz Sun Dec 3 18:18:16 2006 From: i at me.net.nz (Jonathan Hunt) Date: Mon, 4 Dec 2006 12:18:16 +1300 Subject: Python library for reading ODF Spreadsheets Message-ID: <200612041218.26444.i@me.net.nz> Hi all, I have had a look on google/freshmeat etc. so please forgive me if I've missed an obvious answer. Can someone point me to a simple library to read/write ODF spreadsheets (i.e. OpenOffice Calc 2). I know I can interface with OOo but this is running on a server where I would rather avoid a full-on library. Something like http://sourceforge.net/projects/pyexcelerator/ but for reading ODF. I have found write only solutions - but no read library except for the full Monte OOo/UNO which I want to avoid. Please, please help. Or the pragmatist in me will be forced to use XLS to get this job done. Thanks in advance for any help. Jonny (I'm not on the list. Please CC me answers). -- Jonathan Hunt Website: http://www.me.net.nz (PGP Public Key available there) Ph: +6463535975 Mob: +64212106185 Work: +6463505799x3529 "He is no fool who gives what he cannot keep to gain what he cannot lose." Jim Elliot -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From michele.simionato at gmail.com Thu Dec 14 09:29:32 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 14 Dec 2006 06:29:32 -0800 Subject: Multiple inheritance and __slots__ In-Reply-To: <1166105572.377006.305950@80g2000cwy.googlegroups.com> References: <1166102613.814641.109490@80g2000cwy.googlegroups.com> <1166105572.377006.305950@80g2000cwy.googlegroups.com> Message-ID: <1166106572.242334.136720@73g2000cwn.googlegroups.com> jm.suresh at no.spam.gmail.com wrote: > OK. But is there any other way to do what __slots__ does as a 'side > effect' i.e. forcing me to think about the list of attributes my class > is going to have upfront and raising error whenever I violate it. IMHO > this is a very good thing to have even if one does not care about > memory. See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 (how to freeze Python classes) Michele Simionato From fredrik at pythonware.com Tue Dec 12 02:10:39 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Dec 2006 08:10:39 +0100 Subject: namespace question In-Reply-To: <1165906663.732484.203200@73g2000cwn.googlegroups.com> References: <1165904406.053883.129610@l12g2000cwl.googlegroups.com> <1165906663.732484.203200@73g2000cwn.googlegroups.com> Message-ID: jm.suresh at no.spam.gmail.com wrote: > This one works. But I suppose there must be a way to artificially > create a new block of code, some thing like this, > > class Test: > c = None > <>: > # Objects created here are local to this scope > a = 1 > b = 2 > global c > c = a + b if you want a local scope, use a function: class Test: c = do_calculation(1, 2) From grante at visi.com Thu Dec 28 12:27:37 2006 From: grante at visi.com (Grant Edwards) Date: Thu, 28 Dec 2006 17:27:37 -0000 Subject: Some basic newbie questions... References: <1167324002.516960.319870@79g2000cws.googlegroups.com> <12p7tah6gbtq53d@corp.supernews.com> <1167326253.557372.124110@a3g2000cwd.googlegroups.com> Message-ID: <12p7vk9qltqci3c@corp.supernews.com> On 2006-12-28, jonathan.beckett wrote: > I'm just finding it a bit weird that some of the built in functions are > static, rather than methods of objects (such as len() being used to > find the length of a list). Well, they actually are methods of objects (at least they are now -- maybe they didn't used to be). len(foo) is just syntactic sugar for foo.__len__() I think. -- Grant Edwards grante Yow! Yow! STYROFOAM... at visi.com From udodenko at users.sourceforge.net Mon Dec 11 07:59:44 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Mon, 11 Dec 2006 14:59:44 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> <457c42a3$0$49196$14726298@news.sunsite.dk> <7xodqbpqun.fsf@ruckus.brouhaha.com> <457c92c7$0$49195$14726298@news.sunsite.dk> <7x1wn7vx5b.fsf@ruckus.brouhaha.com> <457d3cdc$0$49205$14726298@news.sunsite.dk> <7xodqa7hpf.fsf@ruckus.brouhaha.com> Message-ID: <457d5645$0$49208$14726298@news.sunsite.dk> (message (Hello 'Paul) (you :wrote :on '(11 Dec 2006 04:14:20 -0800)) ( ??>> optimizing language. i think it's called trampolined style. ??>> example can be found in PAIP book: interpreter of Scheme is implemented in PR> This book doesn't seem to be online. But anyway I think you mean, PR> compile the Scheme code into one giant CL function, which is no longer PR> really a clean mapping of Scheme to CL, it's just writing an PR> interpreter. And I think that interpreter has to do its own PR> management of environments rather than letting the CL runtime do it. PR> So basically it says CL is turing-complete and can do everything, PR> which we already knew ;-). point is that writting some custom interpreter in CL is very easy AND you can still use all other features of CL AND communicate with other DSLs. PR> the different macros being used. But I think I understand one part of PR> what was confusing me before: your call/cc macros depend on a PR> nonstandard feature of some CL implementations. no, it's standard Common Lisp. it's an ARNESI library. it's very standard -- i was able to run non-modified code in Armed Bear Common Lisp implementation (it's running on JVM), that is very new and does not fully support the standard -- but nevertheless, CPS code runs out of the box on it. PR> You can't write a call/cc macro in standard CL--you instead have to PR> write something that transforms the entire program. yes, i cannot write just call/cc -- i should wrap code into with-call/cc. with-call/cc macro performs transformation of the code to CPS -- and then call/cc is enabled. i can enable call/cc for specific functions -- i define them with defun/cc instead of defun. so, i can define both normal CL functions and call/cc enabled functions. typically, call/cc is required only in a few pieces of program where interrupts come, so it's OK. if i'm going to support generators, i only need to run CPS tranformation on the body of generator function -- that will tear it in yield points. PR> I think even with TCO though, you still can't do coroutines with CL PR> macros (but you can do them with real call/cc). The point is that you PR> have to do something like TCO on calls that are not tail calls and PR> actually have to return. You again have to transform the whole PR> program, not just expand a call/cc macro locally inside functions that PR> use it. i think only functions that are coroutines should be fully transformed. ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From bignose+hates-spam at benfinney.id.au Tue Dec 5 02:35:04 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Tue, 05 Dec 2006 18:35:04 +1100 Subject: Submitting change requests through correct channels (was: Why not just show the out-of-range index?) References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165298191.987140.176550@f1g2000cwa.googlegroups.com> Message-ID: <877ix6re1j.fsf_-_@benfinney.id.au> "Russ" writes: > At this point I don't even plan to submit a formal request. I have too > many accounts and passwords already. If the implication here (that submitting a change request requires an account on the server) is true, then I must concur with Russ that it's a significant barrier to entry against a user who has one suggestion to make. We all use software from many different vendors (or projects, or whatever), so requiring separate, rarely-used accounts on each one's tracking system is plenty enough to ensure that a great deal of suggestions never go through that channel. I hope that, instead, it's possible to perform the research needed to describe the requested change, submit it as an email or online form, and never have to care about an account and password on a server that likely will never be visited again. This way, the mechanics of submitting the request are a low enough burden that it's reasonable to encourage people to go through that channel. -- \ "I know you believe you understood what you think I said, but I | `\ am not sure you realize that what you heard is not what I | _o__) meant." -- Robert J. McCloskey | Ben Finney From thenightblogger at gmail.com Sat Dec 16 15:22:20 2006 From: thenightblogger at gmail.com (The Night Blogger) Date: Sat, 16 Dec 2006 21:22:20 +0100 Subject: Good Looking UI for a stand alone application Message-ID: <4584531c$0$13533$426a74cc@news.free.fr> Can someone recommend me a good API for writing a sexy looking (Rich UI like WinForms) shrink wrap application My requirement is that the application needs to look as good on Windows as on the Apple Mac From limodou at gmail.com Mon Dec 4 00:31:50 2006 From: limodou at gmail.com (limodou) Date: Mon, 4 Dec 2006 13:31:50 +0800 Subject: class property methods getting called only once In-Reply-To: <1165209843.332368.257980@16g2000cwy.googlegroups.com> References: <1165209843.332368.257980@16g2000cwy.googlegroups.com> Message-ID: <505f13c0612032131n6f037773m81692ec8b0172f81@mail.gmail.com> >On 3 Dec 2006 21:24:03 -0800, jm.suresh at no.spam.gmail.com wrote: > In the following code, I could not find out why the set and get methods > are not called once I set the property. > > > >>> class Test: > ... def __init__(self): > ... self._color = 12 > ... def _setcolor(self,value): > ... print 'setting' > ... self._color = value > ... def _getcolor(self): > ... print 'getting' > ... return self._color > ... color = property(_getcolor,_setcolor) > ... > >>> a = Test() > >>> a.color > getting > 12 > >>> a.color = 22 > >>> a.color > 22 > > For some reason the set method is not getting called at all, Anybody > has any clue? > > thanks. property can only be used in New Style Class. So you should write your Test as: class Test(object): And try again. -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou From trash at willeboordse.demon.nl Fri Dec 15 12:47:52 2006 From: trash at willeboordse.demon.nl (Okko Willeboordse) Date: Fri, 15 Dec 2006 18:47:52 +0100 Subject: Pychecker Message-ID: <12o5nu8mjoank79@corp.supernews.com> I execfile some script from another script like below i = 5 execfile(script) script uses i Running script standalone as well as running script through pychecker is not possible because script expects i I still need to run script through pychecker. I must do that from the calling script since it provides i (and lots more actually) Any ideas? Thanks, From george.sakkis at gmail.com Fri Dec 15 10:54:44 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 15 Dec 2006 07:54:44 -0800 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <1166187479.167471.169270@n67g2000cwd.googlegroups.com> Message-ID: <1166198084.509346.317180@f1g2000cwa.googlegroups.com> Christoph Zwerschke wrote: > The statement "if you are looking for index() or count() for your > tuples, you're using the wrong container type" is too extreme I think. I > would agree with "it *may indicate* that you should better use lists". And also if that statement was correct, I would argue that Python uses the wrong container type for storing positional arguments. More often that not, when ones uses *varargs, he expects a homogeneous container of extra arguments. There are exceptions of course (e.g. range()) where each of the expected *varargs has distinct semantics, but from my experience these are far less common than the unlimited-extra-arguments case. George From jjl at pobox.com Sat Dec 30 16:49:26 2006 From: jjl at pobox.com (John J. Lee) Date: Sat, 30 Dec 2006 21:49:26 GMT Subject: No way to set a timeout in "urllib". References: <%hglh.1141$ji1.1051@newssvr12.news.prodigy.net> Message-ID: <87lkkpf41j.fsf@pobox.com> John Nagle writes: > There's no way to set a timeout if you use "urllib" to open a URL. > "HTTP", which "urllib" uses, supports this, but the functionality > is lost at the "urllib" level. > > It's not available via "class URLopener" or "FancyURLopener", either. > > There is a non-thread-safe workaround from 2003 at > > http://mail.python.org/pipermail/python-bugs-list/2003-September/020405.html > > but it was rejected as a feature at > > https://sourceforge.net/tracker/?func=detail&atid=105470&aid=803634&group_id=5470 > > without anything better going in. Despite this, current documentation > recommends that approach: > > http://svn.python.org/projects/python/trunk/Doc/howto/urllib2.rst And...? What specifically are you complaining about? Just as a matter of fact (I'm not grumpy about it): I see from your message that you already know that there is not a shortage of people who spot the lack of this kind of feature. The shortage is of people who will actually do the job of adding the feature -- most importantly, people who will contribute high quality patches, including tests and docs, and people who will review other people's patches. > Someone proposed to fix this > > http://mail.python.org/pipermail/python-dev/2006-July/066967.html > > but was discouraged from doing so. [...] While it might be discouraging to be confronted with tiresome realities of schedules and resources, those are the realities. The flip side is that you can make a real difference by putting in some work. Looking forward to your patch :-) John From __peter__ at web.de Fri Dec 15 06:46:46 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 Dec 2006 12:46:46 +0100 Subject: Missing __length_hint__ in __getitem__ iterator References: Message-ID: Giovanni Bajo wrote: > Hello, > > given the following object: > > >>> class A(object): > ... def __getitem__(self, idx): > ... if idx >= 10: raise IndexError > ... return idx > ... def __len__(self): > ... return 10 > ... > > I noticed that the iterator that Python constructs: > > >>> a = A() > >>> i = iter(a) > >>> dir(i) > ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', > '__init__', '__iter__', '__len__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'next'] > > does not have a __length_hint__ method. > > Is this just a missing optimization, or there is a deep semantic reason > for which a __length_hint__ could not be constructed out of the __len__ > result? It's there, just not doctored into the dir() output: >>> class A(object): ... def __getitem__(self, index): return index ... def __len__(self): return 42 ... >>> iter(A()).__length_hint__ >>> iter(A()).__length_hint__() 42 Peter From pavlovevidence at gmail.com Sat Dec 9 17:12:57 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 9 Dec 2006 14:12:57 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165685950.758858.18960@n67g2000cwd.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165627684.709241.86340@16g2000cwy.googlegroups.com> <1165685950.758858.18960@n67g2000cwd.googlegroups.com> Message-ID: <1165702377.897545.22510@79g2000cws.googlegroups.com> JShrager at gmail.com wrote: > Carl Banks wrote: > > JShrager at gmail.com wrote: > > > Okay, since everyone ignored the FAQ, I guess I can too... > > [snip] > > > What Python has is stupid slogans > > > ("It fits your brain." "Only one way to do things.") and an infinite > > > community of flies that, for some inexplicable reason, believe these > > > stupid slogns. > > > > IOW, you posted the FAQ so you could appear to have highest moral > > ground, then you ignore your own advice and promptly head to the very > > lowest ground with ad hominem insults. > > You're right, in part: My implicitly linking Python's pros or cons with > its stupid marketing hype is, I think, an ad hominem argument. Ahem. Calling Python programmers "flies". > But I > don't see a moral issue here; the purpose of posting the FAQ was merely > to try to stop the fight. It failed. GMAB. If you were really interested in not fighting you would have shut up. > Regardless, there was some content in my post which you have not > addressed: > > To wit: > > 1. Lisp is the only industrial strength language with pure > compositionality, and that this makes it suprior to Python. We don't > have to debate this because it's being debated elsewhere in this > thread. > > 2. Ruby, which is closer to Lisp than Python, is beginning to eat > Python's lunch. We don't have to debate this either because George has > kindly gave support to it through posting a survey that made this point > quite nicely; Thanks, George! :-) > > BTW, for the record, I don't have anything particularly against Python > aside from its stupid marketing hype and a bit of jealousy over those > flies building libraries which I wish we had in Lisp. I've made the > choice uncountable times between PERL, Python, and Tcl when I didn't > have Lisp as an option, and I have always chosen Python in these cases, > even though I can program in any of these. (Although I'm probably going > to start using Ruby instead of Python in these cases, but I'm not > really expert in it yet.) > > (Actually, in many cases I can get away with Emacs keyboard macros > where others would program in PERL or Python, although not always.) Whatever, fanboy. Carl Banks From duncan.booth at invalid.invalid Thu Dec 21 04:06:11 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 21 Dec 2006 09:06:11 GMT Subject: a question on python dict References: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> <1166686648.342966.78920@n67g2000cwd.googlegroups.com> Message-ID: could.net at gmail.com wrote: > Thank you very much for your explanation! > > I made a mistake that I said the hash value should be recalculated > each time the dict resize, what I wanted to say was that the position > of each item should be recalculated. > > Maybe I should take a look at the source code of python dict some day. > I'll some here for help then. > In your original message you said: > I think this will waste some time doing the increasing-copying thing. > If I know I'm going to handle about 20000 items, I can set the size of > hashtable to 30000. Have you actually tried timing how much time is wasted doing this? 20000 items really isn't very many for a dictionary to handle. I ran a quick test to see how long it takes to create a dictionary with 20000 items. Remember, as has been explained to you, the items are not copied, nor are the hash values recalculated when the dictionary is resized, so if your dictionary takes much longer to create than the test below gives you (on your machine that is rather than mine), then the problem lies elsewhere. e.g. a slow hash function, or the time taken to create whatever you are storing in the dictionary. Just creating the dictionary with no other Python overhead: timeit.py -s "import random; r = [ random.random() for i in range(20000)]" "d = dict.fromkeys(r)" 100 loops, best of 3: 11.3 msec per loop Creating the dictionary using a Python for loop: timeit.py -s "import random; r = [ random.random() for i in range(20000)]" "d={}" "for k in r: d[k] = None" 100 loops, best of 3: 11.7 msec per loop Assigning to the elements in a pre-populated (and therefore the right size) dictionary: timeit.py -s "import random; r = [ random.random() for i in range(20000)]; d=dict.fromkeys(r)" "for k in r: d[k] = None" 100 loops, best of 3: 10.1 msec per loop How many times do you create this dictionary that shaving 1.5 milliseconds off 11 millseconds matters to you? FWIW, for a 2,000,000 element dictionary the times are 2.5s and 1.48s respectively so the situation does get progressively worse as dictionaries get very large. From basti.wiesner at gmx.net Wed Dec 20 04:19:52 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 20 Dec 2006 10:19:52 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <1166394345_23949@sp6iad.superfeed.net> <1166442477.818748.324370@f1g2000cwa.googlegroups.com> Message-ID: Gabriel Genellina schrieb > On 17 dic, 19:21, "Roger Upole" wrote: > >> >> > os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH >> >> >>This will tell you that "x.exe" is executable, even if "x.exe" >> >>contains >> >> nothing but zeros. >> >> > Isn't the same with any other recipe, portable or not? Unless the >> > OS actually tries to load and examine the file contents, which the >> > OS's I'm aware of, don't do. >> >> On windows, you can use win32file.GetBinaryType to check if a file is >> actually a binary executable. > > A similar function exists on Linux too. But even if a file has the > right file format, if it does not have the execute bit set, won't run. > And you could set that bit on a JPG image too - and nothing good would > happen, I presume. Really? I don't think so. Afaik on Linux executable binary files need an ELF header. [lunar at nargond]-[10:15:43] >> ~/Bilder --> chmod a+x VM-Background.png [lunar at nargond]-[10:15:46] >> ~/Bilder --> ./VM-Background.png bash: ./VM-Background.png: cannot execute binary file As you can see, binary files without such a header are not executed... Bye lunar -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From qual at tiscali.de Sat Dec 30 16:30:19 2006 From: qual at tiscali.de (Uwe Hoffmann) Date: Sat, 30 Dec 2006 22:30:19 +0100 Subject: find login name of user? In-Reply-To: <1167511677.250618.285250@v33g2000cwv.googlegroups.com> References: <1167511677.250618.285250@v33g2000cwv.googlegroups.com> Message-ID: rattan at cps.cmich.edu schrieb: > Is there a function/module to find the login name of the user under > UNIX environment? http://docs.python.org/lib/os-procinfo.html http://docs.python.org/lib/module-pwd.html From rdiaz02 at gmail.com Sat Dec 30 20:29:22 2006 From: rdiaz02 at gmail.com (Ramon Diaz-Uriarte) Date: Sun, 31 Dec 2006 02:29:22 +0100 Subject: Wow, Python much faster than MatLab In-Reply-To: References: <5bdf5$45969f9c$d443bb3a$14067@news.speedlinq.nl> <87r6uhf4zf.fsf@pobox.com> Message-ID: <624934630612301729u3cca9da4r2d440d1aaaab82dc@mail.gmail.com> On 12/31/06, gblais at cox.net wrote: > R is the free version of the S language. S-PLUS is a commercial version. > Both are targeted at statisticians per se. Their strengths are in > exploratory data analysis (in my opinion). > > SAS has many statistical featues, and is phenomenally well-documented and > supported. One of its great strengths is the robustness of its data model > -- very well suited to large sizes, repetitive inputs, industrial-strength > data processing with a statistics slant. Well over 200 SAS books,for > example. > > I think of SAS and R as being like airliners and helicopters -- airlines get > the job done, and well, as long as it's well-defined and nearly the same job > all the time. Helicopters can go anywhere, do anything, but a moment's > inattention leads to a crash. > -- inattention leading to a crash? I don't get it. I used SAS for about 3 or 4 years, and have used S-Plus and then R for 10 years (R for 8 years now). I've never noticed inattention leading to a crash. I've noticed I cannot get away in R without a careful definition of what I want (which is good), and the immediate interactivity of R is very helpful with mistakes. And of course, programming in R is, well, programming in a reasonable language. Programming in SAS is ... well, programming in SAS (which is about as fun as programming in SPSS). (Another email somehow suggested that the stability/instability analogy of airplanes vs. helicopters does apply to SAS vs. R. Again, I don't really get it. Sure, SAS is very stable. But so is R ---one common complaint is getting seg faults because package whatever has memory leaks, but that is not R's fault, but rather the package's fault). But then, this might start looking a lot like a flame war, which is actually rather off-topic for this list. Anyway, for a Python programmer, picking up R should be fairly easy. And rpy is really a great way of getting R and Python to talk to each other. We do this sort of thing quite a bit on our applications. And yes, R is definitely available for both Linux and Windows (and Mac), has excellent support from several editors in those platforms (e.g., emacs + ess, tinn-R, etc), and seems to be becoming a de facto standard at least in statistical research and is extremely popular in bioinformatics and among statisticians who do bioinformatics (look at bioconductor.org). Ramon -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From JShrager at gmail.com Fri Dec 8 12:03:53 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 8 Dec 2006 09:03:53 -0800 Subject: *** C.L.L README/FAQ *** (Was: merits of Lisp vs Python) In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165597433.446903.305750@73g2000cwn.googlegroups.com> Sounds like it's time for: A Beginners' Meta FAQ for comp.lang.lisp: http://nostoc.stanford.edu/jeff/llisp/cllfaq.html The purpose of this page is to help those new to Lisp (aka. "newbies") gain some background before they enter the fray of comp.lang.lisp (c.l.l). This is not a complete Lisp FAQ! Once you have a sense of Lisp and of how c.l.l operates you should have no trouble finding all the additional information you need, either by your own search efforts or by asking the community. If you have issues with any of the below please do not send me email. Rather, post on c.l.l in the weekly thread where this is announced (heading: "*** C.L.L README/FAQ ***"). From pc at p-cos.net Tue Dec 12 12:01:55 2006 From: pc at p-cos.net (Pascal Costanza) Date: Tue, 12 Dec 2006 18:01:55 +0100 Subject: merits of Lisp vs Python In-Reply-To: <1165941373.636485.95400@j44g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <1165941373.636485.95400@j44g2000cwa.googlegroups.com> Message-ID: <4u85k4F1731j6U1@mid.individual.net> Pillsy wrote: > Ken Tilton wrote: > [...] >> That was my stance for about seven years of intense Lisp. Then the >> author of Practical Common Lisp did a nice job of breaking the whole >> mess up into sensible chunks and I picked it up. If one programs Lisp, >> one should learn Loop -- it is definitely worth the bother. I def regret >> not learning it sooner. > > When I first read PCL (which was my introduction to Lisp) I thought > LOOP was really neato. Once I actually started using it for things that > weren't so simple, I began to really hate it. I think that having a > specialized mini-language for iteration is a superb idea, but I don't > think LOOP is it. > > That being said, there's a portable alternatives out there that I like > way better, and I still use LOOP for dashing stuff off one-liners at > the REPL. If you hate LOOP then you don't have to use it. There's an important lesson to learn here: Not all language constructs are supposed to be loved by everyone. ;) Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From gert.cuykens at gmail.com Thu Dec 21 18:07:45 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Fri, 22 Dec 2006 00:07:45 +0100 Subject: def index(self): In-Reply-To: References: <4587017b$0$22957$426a34cc@news.free.fr> <458807cc$0$19743$426a74cc@news.free.fr> <45891cb7$0$16994$426a34cc@news.free.fr> <1166659483.225301.48550@t46g2000cwa.googlegroups.com> Message-ID: On 21 Dec 2006 09:44:48 GMT, Duncan Booth wrote: > "George Sakkis" wrote: > > @expr > def fn(...): ... > > is exactly equivalent to: > > def fn(...): ... > fn = (expr)(fn) > ok i did my homework reading about decorators http://www.python.org/doc/2.4.4/whatsnew/node6.html could it be the example above needs to be like @expr def fn(...): ... is exactly equivalent to: def fn(...): ... fn = expr(fn) > > oh and self stands more or less for private method right ? > > if you have to ask that question about 'self' you really do need to read > some introductory texts on Python. > > Methods get passed their instance as their first parameter (usually this is > implicit in the call, but it is always explicitly shown in the method) and > self is simply the conventional name. Many other languages use 'this' > instead of self and make the passing of 'this' implicit inside the method > as well as outside. There are good reasons why it is explicit in Python, > but just remember that the first parameter a method receives is always the > instance and you won't go far wrong. in all the things i every read about self i end up with blablabla scoping blabla blabla self:: blablabla public static methods blablabla :) So when reading 'self' is the same as 'this' it was worth asking the question for confusion sake :) From tleeuwenburg at gmail.com Sun Dec 3 21:20:00 2006 From: tleeuwenburg at gmail.com (tleeuwenburg at gmail.com) Date: 3 Dec 2006 18:20:00 -0800 Subject: trouble with matplotlib In-Reply-To: <1165196461.231013.199670@j44g2000cwa.googlegroups.com> References: <1165196461.231013.199670@j44g2000cwa.googlegroups.com> Message-ID: <1165198800.112595.113780@79g2000cws.googlegroups.com> One hack could be to reload the module on each pass. Cheers, -T lisa.engblom at gmail.com wrote: > Hi, > > I am using matplotlib with python to generate a bunch of charts. My > code works fine for a single iteration, which creates and saves 4 > different charts. The trouble is that when I try to run it for the > entire set (about 200 items) it can run for 12 items at a time. On the > 13th, I get an error from matplotlib that says it can't access data. > However, if I start the program at the point it failed before it works > fine and will create the charts for the next 12 before failing. I > assume that I am not closing the files properly somehow or otherwise > misallocating memory. This is the function that creates a chart: > > #create and save the figure > def CreateFigure(state, facility, unit, SO2, increment, year, P99): > size = len(SO2) > > #Create Plot > figure(1, figsize=(10,8)) > bar(range(1, size+2), SO2, width=0.1, color='k') > grid(True) > xlim(0,size) > ylim(0, 1.1*SO2[-1]) > ylabel('SO2 [lb/hr]') > heading = ConstructFigName(state, facility, unit, increment, year) > title(heading) > > #set handles > xticklines = getp(gca(), 'xticklines') > xgridlines = getp(gca(), 'xgridlines') > xticklabels = getp(gca(), 'xticklabels') > yticklines = getp(gca(), 'yticklines') > > #set properties > setp(xticklines, visible=False) > setp(xgridlines, visible=False) > setp(xticklabels, visible=False) > setp(yticklines, visible=False) > > axhspan(P99, P99, lw=3, ec='r', fc='r') > ax = gca() > #P99 = str(P99) > P99 = '%0.1f' % P99 > text(0.01, 0.95, '99th Percentile: '+P99+' lb/hr', > transform=ax.transAxes) > > figpath = ConstructFigPath(state, facility, unit, increment, year) > savefig(figpath) > close() > > > Can you see the problem? > > thanks, > -Lisa From ptmcg at austin.rr._bogus_.com Mon Dec 4 17:53:12 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 04 Dec 2006 22:53:12 GMT Subject: Ensure a variable is divisible by 4 References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: wrote in message news:1165252238.866708.293510 at j72g2000cwa.googlegroups.com... >I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. > All numbers are divisible by 4. (cf. Little Man Tate) -- Paul From kkylheku at gmail.com Sun Dec 10 23:45:28 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 10 Dec 2006 20:45:28 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165812328.619812.234340@j72g2000cwa.googlegroups.com> Steven D'Aprano wrote: > I'd love to say it has been fun, but it has been more frustrating than > enjoyable. I don't mind an honest disagreement between people who Honest disagreement requires parties who are reasonably informed, and who are willing not to form opinions about things that they have no experience with. > So now I have an even better understanding for why Lispers have a reputation for being difficult and > arrogant. Whereas, for instance, lecturing a Lisp newsgroup (of all places) in the following manner isn't arrogant, right? ``Turing Complete. Don't you Lisp developers know anything about computer science? '' If that had been intended to be funny, you should have made that more clear by choosing, say, lambda calculus as the subject. > But I also gained a little more insight into why Lispers love their > language. I've learnt that well-written Lisp code isn't as hard to read as > I remembered, so I'd just like to withdraw a comment I made early in the > piece. You /think/ you learned that, but in reality you only read some /opinions/ that Lisp isn't as hard to read as was maintained by your previously held opinions. Second-hand opinions are only little better than spontaneous opinions. It's, at best, a slightly favorable trade. > I no longer believe that Lisp is especially strange compared to natural languages. Natural languages are far less completely understood than any programming language. Only your own, and perhaps some others in nearby branches of the language tree do not appear strange to you. From tomas at fancy.org Fri Dec 29 03:27:26 2006 From: tomas at fancy.org (Tom Plunket) Date: Fri, 29 Dec 2006 00:27:26 -0800 Subject: A stupid question References: <1167362866.807346.73510@73g2000cwn.googlegroups.com> <1167365141.757827.43670@48g2000cwx.googlegroups.com> Message-ID: luxnoctis wrote: > It says exactly: > > The specified module could not be found. > LoadLibrary(pythondll) failed > > Don't know if that helps at all. There's something installed on Compaq computers that uses the Python stuff too, but I never figured out what it was. I figured it may have been some of the preloaded games, 'cause when I restored a roommate's machine from the restore image the Python22 folder was among the things that appeared on the fresh machine. It was actually pretty exciting for me since I needed to write a little utility to do something on this machine, but it was slow as death and only had dialup and I really didn't want to deal with downloading and installing that stuff myself. ...of course your first problem is buying a machine with a ton of shovelware on it. Second problem is uninstalling stuff without knowing what it's for. -tom! -- From roopesh.raj at gmail.com Fri Dec 29 01:20:03 2006 From: roopesh.raj at gmail.com (Roopesh) Date: 28 Dec 2006 22:20:03 -0800 Subject: RotatingFileHandler Error Message-ID: <1167373203.150085.91270@i12g2000cwa.googlegroups.com> Hi I am trying to use RotatingFileHandler, in the foll way : rootLogger = logging.getLogger('') rootLogger.setLevel(logging.DEBUG) rotatingHandler = logging.handlers.RotatingFileHandler(self.logobj_path.name,"a", 1000, 10) rotatingHandler.doRollover() rotatingHandler.emit() rootLogger.addHandler(rotatingHandler) logging.info('info') self.logger = logging.getLogger('myapp.area1') It results in the foll error : lne 86, in __init__ rotatingHandler.doRollover() File "c:\python24\lib\logging\handlers.py", line 131, in doRollover os.rename(self.baseFilename, dfn) OSError: [Errno 13] Permission denied Error in atexit._run_exitfuncs: Traceback (most recent call last): File "c:\python24\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "c:\python24\lib\logging\__init__.py", line 1351, in shutdown h.flush() File "c:\python24\lib\logging\__init__.py", line 731, in flush self.stream.flush() ValueError: I/O operation on closed file Error in sys.exitfunc: Traceback (most recent call last): File "c:\python24\lib\atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "c:\python24\lib\logging\__init__.py", line 1351, in shutdown h.flush() File "c:\python24\lib\logging\__init__.py", line 731, in flush self.stream.flush() ValueError: I/O operation on closed file Can anyone tell me, w hat is wrong with my code. Roopesh From gagsl-py at yahoo.com.ar Thu Dec 28 19:59:52 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 28 Dec 2006 21:59:52 -0300 Subject: xml bug? In-Reply-To: <4594130c$0$318$426a74cc@news.free.fr> References: <4594130c$0$318$426a74cc@news.free.fr> Message-ID: <7.0.1.0.0.20061228214546.03fe0ec0@yahoo.com.ar> At Thursday 28/12/2006 15:58, Imbaud Pierre wrote: >The offending part is the one that goes: xmpPLUS='....' >it triggers an exception: ValueError: too many values to unpack, >in _parse_ns_name. Some debugging showed an obvious mistake >in the scanning of the name argument, that goes beyond the closing >" ' ". > >Now my points are: >- how do I spot the version of a given library? There is a __version__ > attribute of the module, is that it? Usually, yes. But it's not required at all, and may have another name. Look at the offending module. >- I tried to copy the lib somewhere, put it BEFORE the official lib in > "the path" (that is:sys.path), the stack shown by the traceback > still shows the original files being used. Is there a special > mechanism bypassing the sys.path search, for standard libs? (I may > be wrong on this, it seems hard to believe...) When the module is inside a package -as in this case- it's a bit harder. Code says `import xml.dom.modulename`, not `import modulename`. So even if you put modulename.py earlier in the path, it won't be found. Some alternatives: - modify the library in-place. It's the easiest way if you don't redistribute your code. - same as above but using an installer (checking version numbers, of course) - "monkey patching". That is, in a new module of your own, imported early on your application, write the corrected version of the offending method: def _parse_ns_name(...): ...doing the right thing... from xml.dom import modulename modulename._parse_ns_name = _parse_ns_name (maybe checking version numbers too) -- 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 From paul at boddie.org.uk Fri Dec 1 13:07:11 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 1 Dec 2006 10:07:11 -0800 Subject: python vs java & eclipse References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com> <1164974627.554596.300240@l12g2000cwl.googlegroups.com> <1164991907.911276.221250@80g2000cwy.googlegroups.com> Message-ID: <1164996431.806879.51400@16g2000cwy.googlegroups.com> Stephen Eilert wrote: > > The support for Java is light-years ahead. Sometimes I feel that > Eclipse is coding for me (quickfix, for instance). Eclipse may be quite a technical achievement, but I found it irritating. Aside from the misuse of screen real-estate, I found that typing two characters and having what seemed like half my source file underlined in red, with multiple messages telling me that I had yet to define or import something or other when what I was about to do was to write the declaration, all conspired to make me want to scream, "WTF do you think I was going to type in about five seconds time? Work it out and autocomplete it if you're so damned clever!" So, Eclipse certainly has its share of detractors, too. ;-) [...] > That said, the code completion for Python is still in its early stages. > There is a lot of room for improvement, even for a dynamic language. Agreed. I don't believe in endless refactoring, and I think that's frequently a symptom of using an overly inflexible statically typed language (where it's more like "Refactoring" - the big R symbolising the seriousness and heavy lifting involved), but there are often times when I've wondered whether something could alert me to obvious breakage, especially after fairly big changes, acting possibly within the editing environment. I suppose pylint and similar tools have been working towards that goal, but I often wonder about producing something more subtle: something which is more clever than looking at modules and globals, and yet doesn't nag you continously about things which you'll discover almost immediately anyway. Paul From harry.g.george at boeing.com Fri Dec 8 09:03:09 2006 From: harry.g.george at boeing.com (Harry George) Date: Fri, 8 Dec 2006 14:03:09 GMT Subject: I think Python is a OO and lite version of matlab References: <1165564104.379172.272890@l12g2000cwl.googlegroups.com> <1165569793.031978.121190@n67g2000cwd.googlegroups.com> <1165571840.060859.16530@j44g2000cwa.googlegroups.com> Message-ID: Fredrik Lundh writes: > Allen wrote: > > > It is not make sense to compare earth and basketball. > > why not? they're both round, so surely they must have been inspired > by each other. the question is if humanity invented balls before we > figured out that the earth is round, or if it's the other way around... > > > In keeping with the computer science flavor, we can say that no one invented earth or balls to be round. Rouindness is an emergent behavior of a substance which has shape-forming adhesion and shape-changing fluidity, and is subject to radially symmetric shape-impacting processes. Magma and gravity for the earth, leather and air pressure for inflated balls, sand and accretion for beach "cannonballs", and snow and hand pressure for snowballs. -- Harry George PLM Engineering Architecture From martin at v.loewis.de Fri Dec 29 19:25:56 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 30 Dec 2006 01:25:56 +0100 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> Message-ID: <4595B214.3070405@v.loewis.de> Ben Sizer schrieb: > I've installed several different versions of Python across several > different versions of MS Windows, and not a single time was the Python > directory or the Scripts subdirectory added to the PATH environment > variable. Every time, I've had to go through and add this by hand, to > have something resembling a usable Python installation. No such > problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or > Kubuntu. So why is the Windows install half-crippled by default? For several reasons: 1. Python can be used just fine without being on PATH. Python scripts run fine both when double-clicked and when invoked in the command line, and if you want to use an interactive interpreter, you can find it readily on the Start menu. 2. Many windows users (including myself) dislike setup routines that manipulate PATH. I believe that the PATH environment variable is "owned" by the user; if Python is to be found in PATH, it should rather be installed to a directory that is known to live on PATH (or where CreateProcess searches, anyway, such as system32). So if the installer had such a feature, it should be optional, and it should default to "off". 3. Most importantly: it is difficult to implement, and nobody has contributed code to make it work. Regards, Martin From godson.g at gmail.com Fri Dec 8 10:41:09 2006 From: godson.g at gmail.com (Godson) Date: Fri, 8 Dec 2006 21:11:09 +0530 Subject: I think Python is a OO and lite version of matlab In-Reply-To: <1165571840.060859.16530@j44g2000cwa.googlegroups.com> References: <1165564104.379172.272890@l12g2000cwl.googlegroups.com> <1165569793.031978.121190@n67g2000cwd.googlegroups.com> <1165571840.060859.16530@j44g2000cwa.googlegroups.com> Message-ID: On 8 Dec 2006 01:57:20 -0800, Allen wrote: > > > > Sure, and earth is a heavy version of a basketball. If all you have is > > a hammer... > > > > It is not make sense to compare earth and basketball. > I think Python introduced many idea of matlab. > > If you have used matlab, you will say that they are very very similar, > except that matlab was born years earlier and is used mainly in the > area > of matrix calculation. > > I do not mean Python shall feel ashamed for it. We will be pleased that > Python > does absorb many successful ideas of computer languages. > > -- > http://mail.python.org/mailman/listinfo/python-list > Yes starting from the prompt '>>>' to concept of name spaces, they are alike, I came to know python first later Matlab in college. The scope of matlab is very narrow ,scientific computations and nothing else, To me matlab seems to be a subset of python, and python being light weight, cause it swallows what ever comes in it way!!! [ http://www.ibiblio.org/Dave/Dr-Fun/df200004/df20000406.jpg ] -- Godson Gera, http://godson.auroinfo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ogbash at gmail.com Sat Dec 2 08:08:55 2006 From: ogbash at gmail.com (Oleg Batrashev) Date: 2 Dec 2006 05:08:55 -0800 Subject: best way to align words? In-Reply-To: <1165050975.684944.232250@j44g2000cwa.googlegroups.com> References: <1164925391.696612.64860@80g2000cwy.googlegroups.com> <1165050975.684944.232250@j44g2000cwa.googlegroups.com> Message-ID: <1165064935.816780.291770@j44g2000cwa.googlegroups.com> > thanks for all your replies, i'm now looking to dynamic programming... Id better warn you before you go further. "Notice that LCS is often defined to be finding all common subsequences of a maximum length. This problem inherently has higher complexity, as the number of such subsequences is exponential in the worst case" This means that if you have 10 sentences with 5 words in each there is 5^10 space and time complexity. Definitelly, there are better algorithms from dynamic programming, but you should review your needs: how many sentences, words you have. There can be easier way than dynamic programming. Oleg From http Mon Dec 11 20:05:41 2006 From: http (Paul Rubin) Date: 11 Dec 2006 17:05:41 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> <7xodqczf1h.fsf@ruckus.brouhaha.com> <7xk60zjl1e.fsf@ruckus.brouhaha.com> Message-ID: <7xk60x7wka.fsf@ruckus.brouhaha.com> jayessay writes: > Also, there is the issue of whether there even is a "continual > progression", as in "moving up some ladder" towards something > "better", in the context of programming languages. All of that is > pretty fuzzy stuff, and plenty of CogSci work has shown these value > judgements in this context to be less than obvious in any meaning. It's simply that newer language designs by definition have more of an experience base to build on than older ones, if the designers care to make use of it. ML's designers were quite aware of what it was like to write Lisp code. Lisp (like anything else) has good and bad points, and ML's designers were able to examine these in retrospect and try to improve on them. Are there any Lisp devotees who have done serious development in ML? From john.thingstad at chello.no Wed Dec 13 05:51:34 2006 From: john.thingstad at chello.no (John Thingstad) Date: Wed, 13 Dec 2006 11:51:34 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> <1165857526.721489.322470@73g2000cwn.googlegroups.com> <1165975429.053195.95700@j72g2000cwa.googlegroups.com> <457fbb4f.5829983@news.readfreenews.net> Message-ID: On Wed, 13 Dec 2006 09:39:44 +0100, Timofei Shatrov wrote: > On 12 Dec 2006 18:03:49 -0800, "Paddy" tried to > confuse > everyone with this message: > >> There are a lot of people that use Wikipedia. I think some of them >> might want to learn to program. > > I think you misunderstood the goal of Wikipedia. It is not to teach > people > programming. > >> I make it easier for them to find >> Python by helping to maintain Python within Wikipedia. > > If someone wants to find Python, he types "Python" in the search bar and > works > from there. He certainly wouldn't end up in "doctest" article. > >> Some people dislike Wikipedia which is fine. Some people dislike >> Wikipedia and deliberately sabotage it, which is vandalism. > > Writing vanity articles about non-notable things is not much better. > You are being silly. Wikipedia has for instance the best coverage of math of any encyclopedia (if you can call it that). This is how I came in touch with it. If you want trivia you get trivia. If you want Phd. level math it has that as well. It is as diverse as the people that use it. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From eldorado at io.com Wed Dec 27 15:33:58 2006 From: eldorado at io.com (eldorado) Date: Wed, 27 Dec 2006 14:33:58 -0600 Subject: getting a process's PID In-Reply-To: References: <20061227102939.L20663@eris.io.com> <20061227135600.O21223@eris.io.com> Message-ID: <20061227142637.A23890@eris.io.com> On Wed, 27 Dec 2006, Sebastian 'lunar' Wiesner wrote: > eldorado typed > > Strange!? On my system with Python 2.4 I don't get this error. It is > likely to be a problem of your really ancient python version. Do I > guess correctly from your previous postings, that you're still using > version 1.4?. Sebastian, Yes, I was running this on a box that had 1.4 - I just tested it on a box that has 2.3.5 and it runs perfect. Your changes also allow it to be run on the boxes that still have 1.4 Thanks for all your help. -- Randomly generated signature "I have opinions of my own -- strong opinions --but I don't always agree with them."-G.W.Bush From sebastien.ramage at gmail.com Wed Dec 6 09:48:42 2006 From: sebastien.ramage at gmail.com (=?iso-8859-1?q?S=E9bastien_Ramage?=) Date: 6 Dec 2006 06:48:42 -0800 Subject: Python Plugin for Web Browser In-Reply-To: References: <1165389943.093365.20590@80g2000cwy.googlegroups.com> <1165391969.824391.174140@l12g2000cwl.googlegroups.com> Message-ID: <1165416520.077655.58540@16g2000cwy.googlegroups.com> oui COM je connais et ?a fonctionne bien mais ce n'est pas portable d'un navigateur ? l'autre et ce n'est pas ce que je cherche ? faire. Mon but serait d'avoir un plugin qui permettrait d'embarquer des applets ?crient en python dans les pages html ? l'image de Java ou Flash, etc Pour le moment j'essaie de g?n?rer un plugin pour firefox avec le Gecko SDK fourni par Mozilla (car bizarrement je ne trouve rien cot? IE...) mais ce n'est pas gagn? vu mon niveau en C++... Je n'arrive pas ? compiler l'exemple. As-tu des connaissances en C++ ? avec Visual C++ ? Seb Michel Claveau a ?crit : > Re ! > > Je ne sais pas quel est ton objectif, mais il est possible de couplet > Python & Javascript, de mani?re ? g?n?rer/modifier/piloter le contenu > HTML de pages Web depuis Python. Je fais ?a tous les jours (avec IE) > > Pour cela je passe par COM. > > Malheureusement, ? cause de la parano?a s?curitaire ambiante, il y a de > plus en plus de contraintes et d'obtacles. > > Ainsi, s'il n'y a pas (encore) trop de probl?mes tant que l'on est en > local (avec les .HTA, par exemple), d?s que l'on est distant (Intranet, > Extranet, Web), il y a maintenant des confirmations ? tout bout de > champ, des avertissements peu utiles, mais devenus incontournables, des > bo?te de dialogues intempestives, etc. > > Donc, si c'est pour utiliser comme interface pour des applis sur le > disque (ou le r?seau local), OK ; sinon, ?a posera des probl?mes. > > C'en est ? tel point que je me demande si l'utilisation de frontaux > HTML comme GUI est toujours int?ressante. > Et le probl?me ne touche pas que Python. Par exemple, j'ai un client > qui utilise un logiciel de gestion de l'assurance qualit?, utilisant > des navigateurs comme interface. Du coup, ils ont des patchs 2 fois par > mois, et les utilisateurs ont toujours plus choses ? valider... > > -- > @-salutations > > Michel Claveau From niels.ellegaard at gmail.com Sat Dec 9 00:22:53 2006 From: niels.ellegaard at gmail.com (Niels L Ellegaard) Date: 8 Dec 2006 21:22:53 -0800 Subject: Automatic debugging of copy by reference errors? Message-ID: <1165641773.903394.295300@80g2000cwy.googlegroups.com> Is there a module that allows me to find errors that occur due to copy by reference? I am looking for something like the following: >>> import mydebug >>> mydebug.checkcopybyreference = True >>> a=2 >>> b=[a] >>> a=4 Traceback (most recent call last): File "", line 1, in ? CopyByReferenceError: Variable b refers to variable a, so please do not change variable a. Does such a module exist? Would it be possible to code such a module? Would it be possible to add the functionality to array-copying in numpy? What would be the extra cost in terms of memory and CPU power? I realize that this module would disable some useful features of the language. On the other hand it could be helpful for new python users. Niels From tartifola at gmail.com Mon Dec 11 13:31:04 2006 From: tartifola at gmail.com (Tartifola) Date: Mon, 11 Dec 2006 19:31:04 +0100 Subject: Sorting Multidimesional array(newbie) Message-ID: <20061211193104.40fe7985.tartifola@gmail.com> Hi, how can I sort an array like array([[5, 2], [1, 3]]) along the first column to obtain array([[1, 3], [5, 2]]) i.e. keeping track of the ordered couples? Thanks, A From larry.bates at websafe.com Thu Dec 14 16:56:05 2006 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 14 Dec 2006 15:56:05 -0600 Subject: Multiple inheritance and __slots__ In-Reply-To: <1166105572.377006.305950@80g2000cwy.googlegroups.com> References: <1166102613.814641.109490@80g2000cwy.googlegroups.com> <1166105572.377006.305950@80g2000cwy.googlegroups.com> Message-ID: <4581C875.2070201@websafe.com> jm.suresh at no.spam.gmail.com wrote: > Simon Brunning wrote: >> On 14 Dec 2006 05:23:33 -0800, jm.suresh at no.spam.gmail.com >> wrote: >>> Hi all, >>> >From the google search, it seems its not possible to do the following. >>> >>>>>> class Test1(object): >>> ... __slots__ = ['a'] >>> ... >>>>>> class Test2(object): >>> ... __slots__ = ['b'] >>> ... >>>>>> class Test3(Test1,Test2): >>> ... __slots__ = ['c'] >>> ... >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: Error when calling the metaclass bases >>> multiple bases have instance lay-out conflict >>> >>> I just want to make sure that I am using only the attributes a,b and c >>> from the instances of Test3 . Is there any other hack that could be >>> done. >> Difficulty with subclassing is the price you pay for abusing slots. >> Slots are intended as a performance tweak only, to minimise the memory >> footprint of classes of which you are going to have a great number of >> instances. >> >> In short - don't do that. > OK. But is there any other way to do what __slots__ does as a 'side > effect' i.e. forcing me to think about the list of attributes my class > is going to have upfront and raising error whenever I violate it. IMHO > this is a very good thing to have even if one does not care about > memory. > > -- > Suresh > >> -- >> Cheers, >> Simon B >> simon at brunningonline.net >> http://www.brunningonline.net/simon/blog/ > Sounds a lot like you are coming from another programming language and are trying to make Python act like it did. Hey I did the same thing when I first took up Python as a language. Python is not Java (or any other language that puts you in a straight jacket). IMHO if you embrace the dynacism of Python and you will be much happier writing code in it. Don't worry if someone will try to assign to some attribute in your class that "is illegal". They may be doing if for some reason you can't fathom at the outset. -Larry From tdelaney at avaya.com Thu Dec 14 16:59:59 2006 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Fri, 15 Dec 2006 08:59:59 +1100 Subject: merits of Lisp vs Python Message-ID: <2773CAC687FD5F4689F526998C7E4E5FF1EC34@au3010avexu1.global.avaya.com> Ken Tilton wrote: >> But this is not a case where a function can't handle the job. > > Is, too. And Ken moves one step closer towards Python ... http://www.google.com.au/search?q=monty+python+argument+sketch Tim Delaney From bearophileHUGS at lycos.com Thu Dec 28 10:45:05 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 28 Dec 2006 07:45:05 -0800 Subject: __getattr__ possible loop In-Reply-To: References: <1167314779.170915.145680@48g2000cwx.googlegroups.com> Message-ID: <1167320704.931970.175330@42g2000cwt.googlegroups.com> Maksim Kasimov: > how to improve the situation depends on what do you expect to get by calling "T().method()" You are right, sorry for being cryptic. I think that's a kind of bug of Python (produced maybe by an infinite loop), so an improvement can be a traceback or some automatic breaking of that loop. Note that my problem comes from using Psyco that segfaults in that situation (if you have Psyco installed you can decomment two lines to see that). I think that using normal code Python+Psyco don't have to segfault, but I know this is tricky situation, so if no simple "solutions" can be found, then it's not a important thing and it can be ignored. Bye, bearophile From DocZ2A at gmail.com Tue Dec 19 19:12:59 2006 From: DocZ2A at gmail.com (Dr. Locke Z2A) Date: 19 Dec 2006 16:12:59 -0800 Subject: trouble getting google through urllib In-Reply-To: <1166537585.709708.223250@i12g2000cwa.googlegroups.com> References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> <45879f2f$0$32025$fa0fcedb@news.zen.co.uk> <1166537585.709708.223250@i12g2000cwa.googlegroups.com> Message-ID: <1166573578.904000.133950@n67g2000cwd.googlegroups.com> I looked at those APIs and it would appear that SOAP isn't around anymore and there are no APIs for google translate :( Can anyone tell me how to set the user-agent string in the HTTP header? From Leo.Kislov at gmail.com Mon Dec 18 03:06:54 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 18 Dec 2006 00:06:54 -0800 Subject: dealing with special characters in Python and MySQL References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> <1166423874.304873.218020@t46g2000cwa.googlegroups.com> <0Yqhh.20400$wc5.8435@newssvr25.news.prodigy.net> <1166426105.495305.173690@73g2000cwn.googlegroups.com> Message-ID: <1166429214.778645.147940@j72g2000cwa.googlegroups.com> ronrsr wrote: > > > > > Try putting "use_unicode=True" in the MySQLdb "connect" call. > > tried that, and also added charset="utf8" - > > now, I can't do any string operations, I get the error msg: > > descriptor 'lower' requires a 'str' object but received a 'unicode' > args = ("descriptor 'lower' requires a 'str' object but received > a 'unicode'",) > > > or similar, on every string operation. What is string operation? Every time you say "I get error" please provide source code where this error occurs. And by the way, do you know that for non-ascii characters you should use unicode type, not str type? -- Leo From luc at honk-honk.com Wed Dec 27 04:32:50 2006 From: luc at honk-honk.com (Luc Heinrich) Date: Wed, 27 Dec 2006 10:32:50 +0100 Subject: loose methods : Smalltalk asPython References: Message-ID: <1hr021w.rkl9eu1r6s33cN%luc@honk-honk.com> Jan Theodore Galkowski wrote: > Comments? Suggestions? -- Luc Heinrich From gagsl-py at yahoo.com.ar Thu Dec 7 17:32:44 2006 From: gagsl-py at yahoo.com.ar (gagsl-py at yahoo.com.ar) Date: 7 Dec 2006 14:32:44 -0800 Subject: SOAP Server with WSDL? In-Reply-To: <4578806e$0$15511$88260bb3@free.teranews.com> References: <45787179$0$15498$88260bb3@free.teranews.com> <4578806e$0$15511$88260bb3@free.teranews.com> Message-ID: <1165530763.862012.235530@l12g2000cwl.googlegroups.com> On 7 dic, 18:52, tobiah wrote: > Actually, do I have to make a WSDL? Do people hand write these, or > are there tools? I don't really need to publish an interface. I just > want some in house apps to communicate. > > I can't figure out if I want SOAP, or CORBA, or would it just be > easier if I just starting opening sockets and firing data around > directly. Ideally, I'd like to share complex objects. That's why > I thought that I needed one of the above standards. A few alternatives: xml-rpc Pros: multiplatform, multilanguage, standard, available in python std lib, very simple to use Cons: simple function calls only, limited argument types, no objects as argument Pyro Pros: object based, multiplatform, full python language support (argument list, keyword arguments...) Cons: only Python supported, non standard CORBA is a big beast and if you don't actually need it, don't use it... -- Gabriel Genellina From uymqlp502 at sneakemail.com Thu Dec 7 08:44:31 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 7 Dec 2006 05:44:31 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> <1165298691.474503.184480@16g2000cwy.googlegroups.com> Message-ID: <1165499071.246557.125710@79g2000cws.googlegroups.com> > - because error messages are not debugging tools (better use unit Then what are they? Machine-generated poetry? From blair.houghton at gmail.com Sat Dec 9 10:36:13 2006 From: blair.houghton at gmail.com (Blair P. Houghton) Date: 9 Dec 2006 07:36:13 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165678573.712504.266960@j44g2000cwa.googlegroups.com> Python doesn't annoyingly rip you out of the real world to code in it. Anyone looking at a python script can get a sense of where it's going. --Blair From greg at cosc.canterbury.ac.nz Wed Dec 20 19:30:17 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 21 Dec 2006 13:30:17 +1300 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4uslgfF18sq18U1@mid.individual.net> Message-ID: <4589D599.6010704@cosc.canterbury.ac.nz> Nick Maclaren wrote: > Not at all. I didn't say that they came in pairs. Consider: > > [str1, str2, agent1, str3, agent2, agent3, agent4, str4, ...] That's homogeneous. Any item of the list can be either a string or an agent, and the only thing the position in the list affects is what order the strings and agents are processed in. -- Greg From basti.wiesner at gmx.net Tue Dec 26 09:32:21 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Tue, 26 Dec 2006 15:32:21 +0100 Subject: How to depress the output of an external module ? References: <459117EE.6070205@gmail.com> Message-ID: fdu.xiaojf at gmail.com wrote > fdu.xiaojf at gmail.com wrote: >> >> I have tried your method, but I found it didn't work as expected. >> >> The output produced by the external function couldn't be depressed, >> but the "print " statement i wrote in python is depressed. It seems >> make cStringIO.StringIO() as a temporary replacement of sys.stdout >> has no effect on the external function. >> >> Here is an example to make myself clear(actually it's modified >> version of Steven's code): >> >> def run_without_stdout(*args, **kwargs): >> function = args[0] >> args = args[1:] >> savestdout = sys.stdout >> sys.stdout = cStringIO.StringIO() >> print "something" >> result = None >> try: >> result = function(*args, **kwargs) >> finally: >> # don't forget to restore stdout, or you >> # really will regret it... >> sys.stdout = savestdout >> print "some other thing" >> return result >> >> When run_without_stdout() is called, the "print" statements wrote in >> python don't produce output, but function() produces output to the >> standard output just as before:( >> >> I have tried to replace sys.stdout globally with cStringIO.StringIO() >> in my program(I mean, make "sys.stdout = cStringIO.StringIO()" as a >> globall statement), but it worked just as previous version did. >> > After some trials I found that put "os.close(1)" before calling the > function will depress the output. In fact, "os.close(1)" closed > standard output, but I don't know how to open it again after the > function's execution. > > Still trying... On Linux systems you may try os.open('/dev/stdout', os.O_WRONLY'). This will connect to lowest available file descriptor to standard output. If you're lucky and no files have been opened after closing standard output, sys.stdout will point to standard output again. Bye Sebastian 'lunar' Wiesner -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From martin at v.loewis.de Thu Dec 14 18:31:47 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 15 Dec 2006 00:31:47 +0100 Subject: Obtaining SSL certificate info from SSL object - proposal In-Reply-To: References: <453D95EA.1020602@animats.com> Message-ID: <4581DEE3.7050101@v.loewis.de> John Nagle schrieb: > SSL certificates are trees, represented in a format, "ASN.1", which > allows storing numbers, strings, and flags. > Fields are identified by names or by assigned "OID numbers" > (see RFC 2459). > > The tree is returned as tuples. The first element of the tuple > is always a string giving the name of the field, and the second > element is a string, Boolean, or number giving the value, or > a list of more tuples. The result is a tree, which will > resemble the tree typically displayed by browsers displaying > SSL certificates. That looks like a bad choice of interface to me. If you want to expose the entire certificate, you should do that using as a single byte string, encoded in DER. The way you are representing it, you are losing information (e.g. whether the string type was IA5String, PrintableString, UTF8String), and I thought your complaint was that the current interfaces lose information, so you should not add an interface that makes the same mistake it tries to overcome. Regards, Martin From Geert.Van.Muylem at skynet.be Mon Dec 18 16:50:44 2006 From: Geert.Van.Muylem at skynet.be (Geert Van Muylem) Date: Mon, 18 Dec 2006 22:50:44 +0100 Subject: Crash in PyImport_Import() Message-ID: <200612182150.kBILoW9L025745@outmx006.isp.belgacom.be> Hi, The following script works fine when I call it from the python interpreter but not when I call it from a c application (embedded python) It crashes in the PyImport_Import() import ldap import distutils.sysconfig def TestInit(): l = ldap.open("192.168.1.2") l.simple_bind_s("","") l.search_s("c=BE", ldap.SCOPE_SUBTREE, "objectclass=*") s = distutils.sysconfig.get_config_var('LINKFORSHARED') -> Python (2.5) and python-ldap (2.2.1) are recompiled for my environment (hardened linux.) Here is part of my makefile: VERSION = Python-2.5 VERSION_LDAP = python-ldap-2.2.1 compile: .python .python-ldap .python: makefile.python .glibc $(VERSION).Setup.local $(EXTRACT_PACKAGE) && \ $(CP) ../$(VERSION).Setup.local Modules/Setup.local && \ ./configure --prefix=/usr --enable-shared=no && \ make && \ make install cp $(VERSION)/libpython2.5.a /usr/lib/libpython.a (cd /usr/include; $(LN) -sf python2.5 python ) touch .python .python-ldap: makefile.python .python .sasl .glibc .openldap python-ldap.setup.cfg (rm -rf $(VERSION_LDAP) || /bin/true) && \ tar xjf $(ARCHIVE_PACKAGES)/$(VERSION_LDAP).tar.bz2 && \ cd $(VERSION_LDAP) && \ $(CP) ../python-ldap.setup.cfg setup.cfg && \ python setup.py build && \ python setup.py install rm -rf $(VERSION_LDAP) touch .python-ldap And my setup.cfg # Example for setup.cfg # You have to edit this file to reflect your system configuation # $Id: setup.cfg.suse-linux,v 1.1 2003/08/20 10:04:34 stroeder Exp $ [_ldap] # Section for compiling the C extension module # for wrapping OpenLDAP 2 libs library_dirs = /usr/lib/ /usr/lib/sasl2/ include_dirs = /usr/include/sasl/ /usr/include/sasl2/ extra_compile_args = extra_objects = # Example for full-featured SuSE build: # Support for StartTLS/LDAPS, SASL bind and reentrant libldap_r. # This needs recent OpenLDAP 2.0.26+ or 2.1.3+ built with #./configure --with-cyrus-sasl --with-tls libs = python ldap_r lber sasl2 ssl crypto resolv dl db m util pthread [install] # Installation options compile = 1 optimize = 1 Everything is done in a chroot-ed environment...when building python-ldap, it uses the newly installed python includes.... The test application is linked against the static version libpython.a int CPyLDAP::Init() { m_iPython = 1; printf ("Before Py_Initialize...\n"); Py_Initialize(); printf ("After Py_Initialize...\n"); PyObject *pName = PyString_FromString("PyTest"); if ( pName != NULL ) { // Load the Python module printf ("Before Import...\n"); m_pModule = PyImport_Import(pName); printf ("After Import...\n"); if (m_pModule != NULL) { m_iPython = 0; m_pDictionary = PyModule_GetDict(m_pModule); } } return (m_iPython); } Hope someone can give me a hint? thanks, Geert -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Wed Dec 6 12:16:25 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Wed, 06 Dec 2006 18:16:25 +0100 Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net> <4to8neF157i8fU1@mid.individual.net> Message-ID: <4toc79F1530e0U1@mid.individual.net> Paul Melis wrote: > I don't think it does Thanks for trying, I was too lazy ;) Regards, Bj?rn -- BOFH excuse #52: Smell from unhygienic janitorial staff wrecked the tape heads From horpner at yahoo.com Thu Dec 7 10:22:56 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 7 Dec 2006 16:22:56 +0100 Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> <1165298691.474503.184480@16g2000cwy.googlegroups.com> <1165499071.246557.125710@79g2000cws.googlegroups.com> Message-ID: On 2006-12-07, Tim Chase wrote: >>> - because error messages are not debugging tools (better use unit >> >> Then what are they? Machine-generated poetry? > > >>> me.__cmp__(gruntbuggly['freddled'].micturations, > bee[LURGID].gabbleblotchits[PLURDLED]) == 0 > > Traceback (most recent call last): > File "", line 1, in ? > VogonPoetryException: Bleem miserable venchit! Bleem forever > mestinglish asunder frapt! You should warn people before posting something that dangerous. I would at least have had time to pull the babelfish out of my ear, and so I could have avoided the nosebleed. -- Neil Cerutti From carsten at uniqsys.com Wed Dec 20 14:39:36 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Wed, 20 Dec 2006 14:39:36 -0500 Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects In-Reply-To: References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> Message-ID: <1166643576.3353.36.camel@dot.uniqsys.com> On Wed, 2006-12-20 at 20:22 +0100, Fredrik Lundh wrote: > thompson.marisa at gmail.com wrote: > > > I'm extremely new to Python and programming as a whole. I have written > > a python script with the assistance of ESRI ArcGIS 9.2, which uses > > Python 2.4.1, however, it gives me this error when I try to run it. > > I've already posted at ESRI support, and I was hoping that Python > > people could help me more. > > > > I hope there is something simple I could do to be able to define the > > object that it thinks is NoneType. > > that would be the None object. > > http://effbot.org/pyref/None > > which is often used as a placeholder in Python. > > my guess is that it's the next() call that returns None when you've > reached the end of the shapefile list; try changing > > while Townshps !="": > > to > > while Townshps is not None: > > and see if the problem goes away. Actually those will both lead to an infinite loop, since you're comparing the entire list, which is unlikely to ever become "" or None. You should compare Townshp, not Townshps, to "" or None, whichever the .next() method actually returns to signal the end of the list. Then again, I have the sneaking suspicion that you didn't post the actual code that you're running. The code you posted looks like it should raise a NameError in the line that says "Townshp = Townshps.next()". -Carsten From chrysain at gmail.com Sun Dec 24 05:37:40 2006 From: chrysain at gmail.com (=?ISO-8859-7?B?1/H189zt6Ocgwfrt4eve?=) Date: Sun, 24 Dec 2006 12:37:40 +0200 Subject: Connection python with C Message-ID: <66b602900612240237t3ba7cb71lc859f55d1d2f143c@mail.gmail.com> Hi.. I want to connect a script in python with a source code in C. Any ideas about it? Thank you! Chrysanthi From __peter__ at web.de Wed Dec 6 11:53:09 2006 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Dec 2006 17:53:09 +0100 Subject: dict.has_key(x) versus 'x in dict' References: <1165418932.582377.312200@79g2000cws.googlegroups.com> <1165423559.858684.227930@16g2000cwy.googlegroups.com> Message-ID: Andy Dingley wrote: >> sorted(setBugsChanged) > Out of interest, whats the Pythonic way to simply cast (sic) the set to > a list, assuming I don't need it sorted? The list comprehension? list(setBugsChanged) Peter From nil at dev.nul Mon Dec 4 03:27:27 2006 From: nil at dev.nul (Christian Stapfer) Date: Mon, 4 Dec 2006 09:27:27 +0100 Subject: algorithm for sorting functional expressions References: <1165215032.749560.171530@16g2000cwy.googlegroups.com> Message-ID: <81424$4573dbf5$544829d7$21010@news.hispeed.ch> wrote in message news:1165215032.749560.171530 at 16g2000cwy.googlegroups.com... >I am trying to write some code that will take a list of functional > expressions, and order them so that those with primitive terms appear > at the beginning of the list and those that are defined by other terms > appear last. > > eg: > getSortedEquations(['b = w + z','a = z - y','w = 2*z + v','z = e + > f','y = p + l']) = > ['w = 2*z + v', 'z = e + f', 'y = p + l', 'b = w + z', 'a = z - y'] > > It is easy enough to tokenise each of the equations and produce a list > like: > ['b', ['w','z']], ['a': ['z','y']], ['w':'z','v'] , ['z', ['e','f']], > ['y',['p','l']] > > But I'd like to find an algorithm that can handle the sorting problem. > > So I suspect that this is a common problem for those familiar with > partially ordered sets or directed graphs. Right. > I'm wondering if anyone else > is familiar with this problem and knows an efficient algorithm that > will solve it. It would be good if any such algorithm would be able to > check for circular definitions in the input. Read http://en.wikipedia.org/wiki/Topological_sorting or just search for "topological sorting" on the net. Regards, Christian From jon at ffconsultancy.com Tue Dec 12 09:16:05 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 14:16:05 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> Message-ID: <457eba42$0$8736$ed2619ec@ptn-nntp-reader02.plus.net> Stephen Eilert wrote: > So, let's suppose I now want to learn LISP (I did try, on several > occasions). What I would like to do would be to replace Python and code > GUI applications. Yes, those boring business-like applications that > have to access databases and consume those new-fangled web-services and > whatnot. Heck, maybe even code games using DirectX. > > So, how would I do that? You may also be interested in related languages. I've written several interesting programs in OCaml: http://www.ffconsultancy.com/free/ocaml/examples.html http://www.ffconsultancy.com/products/ocaml_for_scientists/visualisation More recently, I've been writing F# examples: http://www.ffconsultancy.com/dotnet/fsharp You can probably translate the F# demos into a Lisp for .NET without too much difficulty. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From tomas at fancy.org Thu Dec 28 13:57:28 2006 From: tomas at fancy.org (Tom Plunket) Date: Thu, 28 Dec 2006 10:57:28 -0800 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <4593185f$1@nntp.zianet.com> Message-ID: Steven D'Aprano wrote: > I don't know what "problems" with tabs you are talking about. I never have > problems with tabs. *Other people* who choose to use software that doesn't > understand tabs have problems. > > I've spent a lot of time reading both sides of the tabs versus spaces > argument, and I haven't found anything yet that explains why tabs are, in > and of themselves, bad. Indeed. In fact, I came to the conclusion several years ago that tabs are in better for formatting code because then different people on the team can have their preferred tabstop width, be it 8, 4, or 2 spaces. Ironically, it has always seemed to me then that tabs are superior for python editing, since mixing tabs and spaces in an environment like this means that stuff won't run, whereas in C it'll still compile even if the code looks awful. -tom! -- From frank at niessink.com Sat Dec 16 16:37:44 2006 From: frank at niessink.com (Frank Niessink) Date: Sat, 16 Dec 2006 22:37:44 +0100 Subject: Has comparison of instancemethods changed between python 2.5 and 2.4? In-Reply-To: <1166283262.352367.61610@t46g2000cwa.googlegroups.com> References: <4582CFA3.5040305@niessink.com> <4583367D.7090508@niessink.com> <1166283262.352367.61610@t46g2000cwa.googlegroups.com> Message-ID: <45846728.4070007@niessink.com> Ziga Seilnacht: > This method was changed in Python 2.5. Previously, two instancemethods > compared equal if their im_self attributes were *identical* and their > im_func attributes were equal. Now, they compare equal if their im_self > attributes are *equal* and their im_func attributes are equal. Thanks Ziga, that explains very clearly why I get the behavior I see. > If you think this is a bug, you should report it to the bugtracker: > http://sourceforge.net/bugs/?group_id=5470 Well, from where I am it sure feels like a bug in python, so I've submitted a bug report: http://sourceforge.net/tracker/index.php?func=detail&aid=1617161&group_id=5470&atid=105470 Thanks for your help, Frank From mail at microcorp.co.za Sat Dec 9 04:11:47 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 9 Dec 2006 11:11:47 +0200 Subject: Snake references just as ok as Monty Python jokes/references inpython community? :) References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> Message-ID: <030a01c71b72$3305fa80$03000080@hendrik> wrote: > Problem is I don't know that anyone born after Elvis died gets any of > these Monty Python jokes. But hey - Elvis is not dead! - that is just a conspiracy theory that was originated by the Cliff Richard's fan club... - Hendrik From omelnyk at gmail.com Wed Dec 6 18:58:20 2006 From: omelnyk at gmail.com (Olexandr Melnyk) Date: Thu, 7 Dec 2006 01:58:20 +0200 Subject: True Division in Python In-Reply-To: <1165448464.077200.128340@n67g2000cwd.googlegroups.com> References: <1165448464.077200.128340@n67g2000cwd.googlegroups.com> Message-ID: 6 Dec 2006 15:41:04 -0800, kermit at polaris.net : > > However, today I reviewed the method to be used in Python to get true > division, and this gave > me an idea how true division could be implemented without interferring > with the use of > > / for integer division. > > Use / for integer division > > single slash is the operator for integer division. > > Use ./ for true division. > > period slash is the operator for true division. > Such idea was already proposed: http://www.python.org/dev/peps/pep-0238/ ------------------------------------------------ Olexandr "Kynlem" Melnyk, http://omelnyk.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jelka.rom at amis.net Fri Dec 29 18:10:58 2006 From: jelka.rom at amis.net (Janez ROM) Date: Sat, 30 Dec 2006 00:10:58 +0100 Subject: mmmmmmmmmmm Message-ID: <4595A082.3050202@amis.net> From kentilton at gmail.com Mon Dec 11 14:44:28 2006 From: kentilton at gmail.com (Ken Tilton) Date: Mon, 11 Dec 2006 14:44:28 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165764570.956203.223370@16g2000cwy.googlegroups.com> Message-ID: Andr? Thieme wrote: > mystilleef schrieb: > >> Ken Tilton wrote: >> >>> Lisp has all the cool qualities you like in your pets, plus native >>> compilation in most implementations, plus maturity and a standard, plus >>> a better OO, plus macros, plus a dozen more small wins. Including >>> automatic indentation. :) >>> >> >> Better OO? You mean the one that doesn't support basic encapsulation >> and is retardedly cumbersome to use? There's a reason I said, I'd never >> use Lisp for OO not even when I'm high. Gimme Python, Eiffel or >> Smalltalk anyday, not the retarded add-on package bolted on CL. > > > What do you mean with "encapsulation" in this context? Mr. mystilleef's remarks struck me as needlessly contentious and perhaps unavoidably ignorant, hence unworthy of response. YMMV. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From fredrik at pythonware.com Mon Dec 18 01:24:24 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 18 Dec 2006 07:24:24 +0100 Subject: dealing with special characters in Python and MySQL In-Reply-To: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> Message-ID: ronrsr wrote: > I have an MySQL database called zingers. The structure is: > > zid - integer, key, autoincrement > keyword - varchar > citation - text > quotation - text > > the encoding and collation is utf-8 > > I am having trouble storing text, as typed in last two fields. Special > characters and punctuation all seem not to be stored and retrieved > correctly. are you passing in the strings as Unicode strings, or as something else? if you're using something else, what have you done to tell the database what it is? From jon at ffconsultancy.com Tue Dec 12 09:52:37 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 14:52:37 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <7xslfmju4g.fsf@ruckus.brouhaha.com> <87mz5ufl4z.fsf@colinux.pc-mlivshin-ibm.cadence.com.cmm> Message-ID: <457ec2d1$0$8719$ed2619ec@ptn-nntp-reader02.plus.net> Michael Livshin wrote: > Paul Rubin writes: >> Nobody seems to concerned that Haskell lacks macros. What's up with >> that? > > Haskell is lazy, so it doesn't need macros Outside Lisp, macros are for syntax. Evaluation semantics (e.g. lazy evaluation) then have nothing to do with macros. So Haskell being lazy doesn't obviate macros. You might still want to extend the syntax of Haskell, i.e. want macros. However, this is much less desirable than Lisp because Haskell already provides a wealth of powerful features and related syntax (e.g. pattern matching, comprehensions). I think this is an important point often missed by Lispers. > lazyness has a nontrivial cost, however, both runtime and cognitive. The main problem with lazy evaluation is unpredictable memory use. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From cychong at gmail.com Wed Dec 20 10:07:02 2006 From: cychong at gmail.com (cychong) Date: 20 Dec 2006 07:07:02 -0800 Subject: Support of IPv6 extension headers Message-ID: <1166627222.868166.123710@a3g2000cwd.googlegroups.com> Hi, There is no probleming in programming the basic IPv6 socket program with the python. Then how about the IPv6 extension header? The RFC 2292 and man pages from the unix/linux advise to use the sendmsg to send the packet with the extension header. Does python support the extension header processing? Googling told me that there is no one to try this one with the python.Is it true? From horpner at yahoo.com Fri Dec 8 14:30:39 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 8 Dec 2006 20:30:39 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: ["Followup-To:" header set to comp.lang.python.] On 2006-12-08, Mark Tarver wrote: > I'm looking at Python and I see that the syntax would appeal to > a newbie. Its clearer than ML which is a mess syntactically. And if you stew it like applesauce, it tastes more like prunes than rhubarb does. > But I don't see where the action is in Python. Not yet > anyway. Lisp syntax is easy to learn. And giving up an order > of magnitude is a high price to pay for using it over Lisp. I find it easier to learn syntax than special forms. But either system comes naturally enough with practice. -- Neil Cerutti From robert.kern at gmail.com Thu Dec 14 11:22:59 2006 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 14 Dec 2006 08:22:59 -0800 Subject: speed of python vs matlab. In-Reply-To: <1166112365.993234.3130@l12g2000cwl.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> <1166059648.320257.187310@j72g2000cwa.googlegroups.com> <1166107064.994343.266890@l12g2000cwl.googlegroups.com> <1166112365.993234.3130@l12g2000cwl.googlegroups.com> Message-ID: Chao wrote: > While trying this another question comes up, > psyco seems to be able to optimize built-in functions & user's code, if > I call a function from an external library, it seems doesn't help. > A simple thing is I placed a = numpy.sin(a) in the loop rather than a = > a+1, in this case, > psyco doesn't have any improvement(or very little). if I put a = > math.sin(a) which is from an built-in function, it can achieve a > improvement around 3~4. Could the reason be that numpy.sin is > actually calling a C library ? The reason for the difference is that psyco recognizes math.sin() and replaces it with equivalent machine code to call the standard C library function sin(). It does not recognize numpy.sin(), and it is implemented in C, not Python, so it does not do optimization. > Actually Python does show comparable/better performance than other > scripting languages. but I'm just surprised that matlab does a great > job compared to python/perl, since matlab is also a interpreted > language, I'm expecting it has silimar performance with python. Matlab uses a JIT compiler along the lines of psyco for simple operations like the one you are doing. -- 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 From greg at cosc.canterbury.ac.nz Mon Dec 11 22:35:35 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 12 Dec 2006 16:35:35 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1165876294.938323.233380@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> <1165876294.938323.233380@80g2000cwy.googlegroups.com> Message-ID: <4u6mf2F161jbqU2@mid.individual.net> JShrager at gmail.com wrote: > So if you guys would just fix > your language by adding homogeneous syntax and all that it brings with > it (macros, compilers, etc) we'd be happy to use your version of Lisp, > and all its great libraries, instead of ours! :-) But if we did that, it wouldn't be Python any more, it'd be Lisp. And then all those great libraries wouldn't work with it, because they're for Python, not Lisp. :-( -- Greg From Benjamin.Barker at gmail.com Wed Dec 27 13:12:20 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 27 Dec 2006 10:12:20 -0800 Subject: DOS, UNIX and tabs Message-ID: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Hi, I have a python script on a unix system that runs fine. I have a python script on a windows system that runs fine. Both use tabs to indent sections of the code. I now want to run them on the same system, actually in the same script by combining bits and pieces. But whatever I try my windows tabs get converted to spaces when I transfer it to the unix system and the interpreter complains that the indentation style is not consistent throughout the file. Short of going through 350 lines of code and manually replacing spaces with tabs what an I do? I'm thinking there surely must be a simple solution I have missed here! Cheers, Ben From bj_666 at gmx.net Wed Dec 27 03:57:07 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 27 Dec 2006 09:57:07 +0100 Subject: File write() problem References: <1167207703.803035.277720@42g2000cwt.googlegroups.com> Message-ID: In <1167207703.803035.277720 at 42g2000cwt.googlegroups.com>, apriebe47 wrote: > configfile = file('config.txt', 'w') > serverPassword = configfile.readline() Here you open a file for writing and try to read a line. This raises an exception: In [1]: configfile = file('test.txt', 'w') In [2]: configfile.readline() --------------------------------------------------------------------------- exceptions.IOError Traceback (most recent call last) /home/marc/ IOError: [Errno 9] Bad file descriptor Please post the exact code you have trouble with. Don't retype it -- copy and paste it. Ciao, Marc 'BlackJack' Rintsch From bj_666 at gmx.net Sun Dec 17 12:54:25 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sun, 17 Dec 2006 18:54:25 +0100 Subject: length of multidimensional table References: Message-ID: In , vertigo wrote: > i have: > x = zeros([3,4],Float) > > how can i check how many rows and columns x have ? > (what is the X and Y size of that table) ? Try `x.getshape()`. Ciao, Marc 'BlackJack' Rintsch From kbk at shore.net Thu Dec 7 00:14:15 2006 From: kbk at shore.net (Kurt B. Kaiser) Date: Thu, 7 Dec 2006 00:14:15 -0500 (EST) Subject: Weekly Python Patch/Bug Summary Message-ID: <200612070514.kB75EF59004829@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 413 open ( +6) / 3489 closed ( +5) / 3902 total (+11) Bugs : 943 open ( +7) / 6364 closed ( +1) / 7307 total ( +8) RFE : 246 open ( +0) / 244 closed ( +0) / 490 total ( +0) New / Reopened Patches ______________________ popen() slow on AIX due to large FOPEN_MAX value (2006-12-01) http://python.org/sf/1607087 opened by John L. Allen bug# 1607041: Condition.wait timeout fails on clock change (2006-12-01) http://python.org/sf/1607149 opened by BC Optional Argument Syntax (2006-12-02) http://python.org/sf/1607548 opened by Tony Lownds Makefile fix (2006-12-03) http://python.org/sf/1608267 opened by Hasan Diwan Race condition in os.makedirs (2006-12-04) http://python.org/sf/1608579 opened by James Bowes Fix pickle doc typo "date", should be "data" (2006-12-04) CLOSED http://python.org/sf/1608758 opened by Graham Horler Py_FileSystemDefaultEncoding can be non-canonical (2006-12-04) http://python.org/sf/1608805 opened by Stephan R.A. Deibel Docstring support for ctypesgen (2006-12-05) CLOSED http://python.org/sf/1609108 opened by David Remahl #1603424 subprocess.py wrongly claims 2.2 compatibility. (2006-12-05) http://python.org/sf/1609282 opened by Robert Carr traceback on exit if syslog handler fails to initialize (2006-12-05) http://python.org/sf/1609407 opened by Jeremy Katz tarfile.py: Fix for bug #1609958 (2006-12-06) CLOSED http://python.org/sf/1610437 opened by Lars Gust?bel Patches Closed ______________ Socket module is not thread-safe (2006-08-22) http://python.org/sf/1544279 closed by loewis ConfigParser to accept a custom dict to allow ordering (2005-12-01) http://python.org/sf/1371075 closed by loewis Fix pickle doc typo "date", should be "data" (2006-12-05) http://python.org/sf/1608758 closed by quiver Docstring support for ctypesgen (2006-12-05) http://python.org/sf/1609108 closed by theller tarfile.py: Fix for bug #1609958 (2006-12-06) http://python.org/sf/1610437 closed by gbrandl New / Reopened Bugs ___________________ Condition.wait timeout fails when system clock changes (2006-12-01) http://python.org/sf/1607041 opened by BC Incorrect use of 'int' and 'long' descriptions (2006-12-01) CLOSED http://python.org/sf/1607061 opened by John logging %(module)s reporting wrong modules (2006-11-29) http://python.org/sf/1605110 reopened by mad-marty segfault in python24.dll (2006-12-03) http://python.org/sf/1607759 opened by joe mailbox.Maildir re-reads directory too often (2006-12-03) http://python.org/sf/1607951 opened by Matthias Klose Sloppy error checking in listdir() for Posix (2006-12-04) http://python.org/sf/1608818 opened by Stephan R.A. Deibel PyThread_release_lock with pthreads munges errno (2006-12-04) http://python.org/sf/1608921 opened by Stephan R.A. Deibel tarfile archive paths limited to less than 100 chars (2006-12-06) CLOSED http://python.org/sf/1609958 opened by Frank Rehberger GUI for Python 2.3, 2.4, and 2.5 is very sluggish (2006-12-06) http://python.org/sf/1610485 opened by g4rlik Bugs Closed ___________ Incorrect use of 'int' and 'long' descriptions (2006-12-01) http://python.org/sf/1607061 closed by gbrandl not configured for tk (2006-10-18) http://python.org/sf/1579931 closed by sf-robot tarfile archive paths limited to less than 100 chars (2006-12-06) http://python.org/sf/1609958 closed by gbrandl From python at hope.cz Wed Dec 6 05:44:02 2006 From: python at hope.cz (Lad) Date: 6 Dec 2006 02:44:02 -0800 Subject: PyMedia - some questions Message-ID: <1165401842.073048.50410@j44g2000cwa.googlegroups.com> Hi, Can anyone answer the following questions? Question 1. Can pyMedia create/convert FLV format? I explain in details. As I would like to publish videos for viewing in a browser , I need a good video format. I learned that FLV (Flash(tm) Video) format could be a good choice. Or does anybody suggest a better format??? Question 2 . So, I need to convert a file captured from a video camera into that FLV (Flash(tm) Video) format . Can pyMedia do that or must I use ffmpeg directly like this( to convert from avi to FLV ) ffmpeg -i [sourcefile.avi] -acodec mp3 -ar 22050 -ab 32 -f flv -s 320?240 [destfile.flv] Question 3, This command creates a simple FLV format file, containing the video and audio streams. In addition, FLV files need meta-information such as duration, frames, etc. FLV movie players use this information to calculate progress bar sliders and allow the user to fast-forward or reverse through the video. Can PyMedia add such meta- information? Thank you for help Lad. From tjreedy at udel.edu Mon Dec 4 18:13:42 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 4 Dec 2006 18:13:42 -0500 Subject: Factory pattern implementation in Python References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> <1165263327.407166.276160@l12g2000cwl.googlegroups.com> Message-ID: wrote in message news:1165263327.407166.276160 at l12g2000cwl.googlegroups.com... > Dennis Lee Bieber: >> Presuming the is a type code I'd just set up a list of >> functions: >> Then create a dictionary of them, keyed by the code >> processors = { "1" : process_1, >> "2" : process_2, >> .... >> "x" : process_x } > > Just a dict of functions was my solution too, I think avoiding more > complex solutions is positive. If the event codes start at 0 and run sequentially, a tuple or list would be even easier. From beliavsky at aol.com Thu Dec 14 13:00:53 2006 From: beliavsky at aol.com (Beliavsky) Date: 14 Dec 2006 10:00:53 -0800 Subject: automatically grading small programming assignments In-Reply-To: References: Message-ID: <1166119253.711972.260480@80g2000cwy.googlegroups.com> Brian Blais wrote: > Hello, > > I have a couple of classes where I teach introductory programming using Python. What > I would love to have is for the students to go through a lot of very small programs, > to learn the basic programming structure. Things like, return the maximum in a list, > making lists with certain patterns, very simple string parsing, etc. Unfortunately, > it takes a lot of time to grade such things by hand, so I would like to automate it > as much as possible. > > I envision a number of possible solutions. In one solution, I provide a function > template with a docstring, and they have to fill it in to past a doctest. Is there a > good (and safe) way to do that online? Something like having a student post code, > and the doctest returns. I'd love to allow them to submit until they get it, logging > each attempt. On a different matter, coding style, you could run something such as Pylint on submitted codes and penalize them based on the number of warnings emitted. Maybe some adjustments would be necessary -- my experience with picky compilers is that most but not ALL warnings indicate problems. From atkinw at rpi.edu Sun Dec 10 02:12:29 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 02:12:29 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano writes: > Rightly or wrongly, people fear that Lisp's macros push Lisp closer to > that hypothetical anything-goes language than is healthy. Maybe that's a Wrongly. And do they? To paraphrase Brian Griffin: "Are you sure it was people? Are you sure it wasn't...nothing?" > My point isn't whether or not their claims are correct (a "couple" of > macros? really?) but that things like this feed the perception that Lisp > is close to that hypothetical language where anything could be anything. > If anything could be anything, do you really know what (+ 1 2) means > without reading every line of code? Jesus H Christ. Didn't you just get through talking about how easily someone can redefine built-ins in Python? > Even something simple like file I/O can be abused. Example: I've seen Agreed. This is why I've always argued that I/O should never have been included in programming languages. Too dangerous. And, let's face it, pretty old-fashioned these days. > (This is an interesting demonstration that any language that allows file > I/O and importing of external program files can always treat functions > as data, even if the language doesn't directly support it. An alternative > would be to keep the strings in memory instead of writing to a module, > then use exec on them instead of importing the module.) No, it treats code as text. See the difference? > Honest to god, the code really was like that! Holy cow! How incredible! > Is that an argument against factory functions? Damn straight it is: > they are a powerful tool, and in the hands of morons, they can be > dangerous. Does that mean that languages shouldn't permit higher-order > functions? Not necessarily: all programming tools can be misused, but some > can be misused more easily than others. Power and risk is often a > trade-off, and language designers can't eliminate all risk of stupid > behaviour, but they can design the language to allow whatever level of > risk they believe is acceptable. (E.g. there is no doubt that C's raw > pointers are powerful, but many languages deliberately don't use them.) Could you please calm down? > The risk of stupid factory functions is small compared to the benefit, but > maybe there is some domain somewhere where the ideal solution is a > language that DOESN'T treat functions as first class objects, deliberately > weakening the language so that a particular class of errors (or stupid > behaviour) just cannot happen. But that language isn't Python. Could you calm down? > When it comes to Lisp's macros, the perception is that the power is NB: here, "the" means "Steven D'Aprano's" (the number of meanings "the" can assume in different contexts is quite surprising). > correspondingly greater, and the risk of abuse even more so. The safe Don't you get tired of making the same arguments? Because I'm getting tired of making the same counterpoints. From larry.bates at websafe.com Thu Dec 14 12:16:55 2006 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 14 Dec 2006 11:16:55 -0600 Subject: run a script and supply commands from a python cgi script In-Reply-To: <1166115122.154349.78730@j72g2000cwa.googlegroups.com> References: <1166115122.154349.78730@j72g2000cwa.googlegroups.com> Message-ID: moishyyehuda at gmail.com wrote: > Hi > > #1 How do I open a script from another script. Use subprocess or popen > #2 when I run the script how can I supply commands to the script. See documentation on subprocess or popen > #3 how do I find the what commands the script needs. See documentation that comes with the script you wish to run > > The thing is like this. I need to set up a module on my server, but i > cant access the server with a comand line. So I want to run setup.py > script (I nead to run setup.py to setup up the module) from a python > cgi script, and supply commands from the script. So if any one can help > me with this I would appreciate it. > > Moishy > This is most likely not going to work. You aren't going to have adequate rights for the setup.py script to write to the places that it will need to write to. You probably need to switch to an ISP that allows you shell access to your server instance or one that will install python modules for you on your sever. -Larry Bates From michele.simionato at gmail.com Fri Dec 1 04:06:18 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 1 Dec 2006 01:06:18 -0800 Subject: Is there a reason not to do this? In-Reply-To: References: Message-ID: <1164963978.876893.129800@79g2000cws.googlegroups.com> Ron Garret wrote: > One of the things I find annoying about Python is that when you make a > change to a method definition that change is not reflected in existing > instances of a class (because you're really defining a new class when > you reload a class definition, not actually redefining it). So I came > up with this programming style: > > def defmethod(cls): > return lambda (func): type.__setattr__(cls, func.func_name, func) Why not just ``return lambda func: setattr(cls, func.func_name, func)`` ? Your approach is certainly uncommon, but for your use case it seems to me a pretty much decent solution. The only thing I don't like is that all your functions/methods will end up begin 'None'. I'd rather to be able to use the help, so I would write def defmethod(cls): def decorator(func): setattr(cls, func.func_name, func) return func return decorator @defmethod(C) def m1(self, x):pass help(m1) BTW, for people with a Lisp background I recommend using IPython with emacs and the ipython.el mode. It is pretty good, even if not comparable to Slime. Michele Simionato From gagsl-py at yahoo.com.ar Fri Dec 8 16:43:12 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 8 Dec 2006 13:43:12 -0800 Subject: why is this different? In-Reply-To: References: Message-ID: <1165581861.238866.45310@80g2000cwy.googlegroups.com> On 7 dic, 22:53, Sch?le Daniel wrote: > In [38]: f = [lambda:i for i in range(10)] > In [39]: ff = map(lambda i: lambda : i, range(10)) > In [40]: f[0]() > Out[40]: 9 > In [41]: f[1]() > Out[41]: 9 > In [42]: ff[0]() > Out[42]: 0 > In [43]: ff[1]() > Out[43]: 1 > > I don't understand why in the first case f[for all i in 0..9]==9 In the first case, i is a free variable. That means that Python will get it from other place (the global namespace, likely [surely?]) >>> f=[lambda:i for i in range(10)] >>> f[0]() 9 >>> i=123 >>> f[0]() 123 >>> print f[0].func_closure None In the second case, the inner i is a free variable, but local to its enclosing scope (outer lambda). It's a closure: >>> ff = map(lambda i: lambda : i, range(10)) >>> ff[4]() 4 >>> ff[4].func_closure (,) >>> i=321 >>> ff[4]() 4 > what is different from (more usefull) > > In [44]: f = ["%i" % i for i in range(10)] > In [45]: f > Out[45]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] This is a simple expression evaluated at each iteration > doing it like this works again > > In [54]: def d(x): > ....: return lambda:x > ....: x inside lambda is a free variable, but since it's local to d, this becomes a closure: >>> d(1) at 0x00A35EF0> >>> d(1).func_closure (,) > In [55]: f = [d(i) for i in range(10)] > In [56]: f[0]() > Out[56]: 0 > In [57]: f[1]() > Out[57]: 1 This is similar to the ff example above > in a C programmer sence I would say there seems to be no "sequence > point" which would separate "now" from "next" No, the problem is that C has no way to express a closure; this is a functional concept absolutely extraneous to the C language. -- Gabriel Genellina From kylotan at gmail.com Sat Dec 30 19:55:09 2006 From: kylotan at gmail.com (Ben Sizer) Date: 30 Dec 2006 16:55:09 -0800 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <4595B214.3070405@v.loewis.de> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> <4595B214.3070405@v.loewis.de> Message-ID: <1167526509.471697.320750@v33g2000cwv.googlegroups.com> Martin v. L?wis wrote: > Ben Sizer schrieb: > > I've installed several different versions of Python across several > > different versions of MS Windows, and not a single time was the Python > > directory or the Scripts subdirectory added to the PATH environment > > variable. Every time, I've had to go through and add this by hand, to > > have something resembling a usable Python installation. No such > > problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or > > Kubuntu. So why is the Windows install half-crippled by default? > > For several reasons: > 1. Python can be used just fine without being on PATH. Python > scripts run fine both when double-clicked and when invoked in > the command line, and if you want to use an interactive > interpreter, you can find it readily on the Start menu. Yet many scripts and applications require parameters, or to be executed from a certain directory. For example, setup.py. Or the various turbogears scripts. Or easy_install. > 2. Many windows users (including myself) dislike setup routines that > manipulate PATH. My opinion is that this is not as big a problem as some may feel that it is. Unlike Unix systems, the PATH variable is rarely used. Most applications are launched via the Start Menu, which uses absolute paths, or via file associations, also done via absolute paths. The chance of a naming collision only really arises when you start using the command line, which most people don't do. However, among those who will use the command line, are some people new to Python, who will come across instructions like this: "As described in section 1.2, building and installing a module distribution using the Distutils is usually one simple command: python setup.py install On Unix, you'd run this command from a shell prompt; on Windows, you have to open a command prompt window (``DOS box'') and do it there; " Pretty much none of the instructions in that part of the docs will work without you altering your path beforehand. Python's cross-platform nature means people rightly expect the same instructions to work on Linux and Windows from a standard installation. Right now, they don't. > if Python is to be found in PATH, it > should rather be installed to a directory that is known to live > on PATH (or where CreateProcess searches, anyway, such > as system32). So if the installer had such a feature, it should > be optional, and it should default to "off". It's a lot more anti-social to install to system32 than to modify the PATH variable. How easy is it to temporarily undo an installation to a system directory like that? What if you still want Python in your path but with less precedence than some other user directory? > 3. Most importantly: it is difficult to implement, and nobody has > contributed code to make it work. There appears to be a freely-available binary at this address that may suffice: http://legroom.net/modules.php?op=modload&name=Open_Source&file=index&page=software&app=modpath -- Ben Sizer From address.good.until.2007.feb.05 at justmail.de Fri Dec 15 21:10:47 2006 From: address.good.until.2007.feb.05 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Sat, 16 Dec 2006 03:10:47 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7x7iwsd932.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> <1166102108.129051.166580@73g2000cwn.googlegroups.com> <4ufenbF17of60U6@mid.individual.net> <7x7iwsd932.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin schrieb: > Andr? Thieme writes: >> Lisp has no parens. An editor could support a mode where code >> is displayed in written in trees. There wouldn't be a single paren. > > But there would be even more tokens, the lines going between the nodes > in the trees, for example. These are painted by the editor. I also don't count the number of pixels ouf of which a letter consists as tokens. The nodes in the source tree can be one counting method which a lot of people could accept. For Python I also wouldn't count the number of spaces of indentation. Andr? -- From ed at leafe.com Thu Dec 7 16:48:02 2006 From: ed at leafe.com (Ed Leafe) Date: Thu, 7 Dec 2006 16:48:02 -0500 Subject: Execution time of lines within a function In-Reply-To: References: <1165240166.203915.115460@n67g2000cwd.googlegroups.com> Message-ID: On Dec 4, 2006, at 11:36 PM, Paul McGuire wrote: > The PythonDecoratorLibrary page on the Python wiki has a link to a > @profile > decorator, that I have used to profile the contents of targeted > functions > (only just now, I don't seem to be able to get to the wiki to get > the exact > link). http://mg.pov.lt/blog/profilehooks-1.0.html Note that the license has been changed from GPL to MIT, making it distributable with non-GPL projects. -- Ed Leafe -- http://leafe.com -- http://dabodev.com From martin at v.loewis.de Fri Dec 8 01:30:41 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 08 Dec 2006 07:30:41 +0100 Subject: subversion revision number string within an application packaged with distutils? In-Reply-To: <1165542556.714372.193340@n67g2000cwd.googlegroups.com> References: <1165542556.714372.193340@n67g2000cwd.googlegroups.com> Message-ID: <45790691.2090404@v.loewis.de> Jim Tittsler schrieb: > Is there a standard recipe for getting the subversion revision number > into my Python-based application each time I package it up with > distutils? (Not just the package name, but also a string that I will > display in my app's "About" dialog.) You can't really use subversion's keyword substitution for that (contrary to what Gabriel Genellina suggested): a $Revision$ field will only be updated to the revision in which the file containing it changed. If you want the repository version at the time of the packaging, you can use the svnversion tool. On Windows, you can alternatively also use the subwcrev.exe tool that comes with Tortoise. If you don't want to invoke an external tool, you could also retrieve the same information with the subversion Python bindings. Regards, Martin From nmm1 at cus.cam.ac.uk Sun Dec 17 12:16:07 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 17 Dec 2006 17:16:07 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4584E986.10502@cosc.canterbury.ac.nz> Message-ID: In article <4584E986.10502 at cosc.canterbury.ac.nz>, greg writes: |> |> > A collection is inhomogeneous if, for some attribute that is needed |> > for at least one action on at least one element of the collection, |> > the attribute is not shared by all elements of the collection. |> |> If you mean "attribute" in the Python sense, then this |> is wrong, because you're just defining it in terms of |> concrete types again. No, I am not. I am using it in the normal English sense. |> There is no rigorous definition in Python terms, because |> Python doesn't formally embody the concept. But that |> doesn't mean the concept isn't real. Of course the concept is real, but the point is that Python doesn't embody the concept of homogeneity in lists, formally or informally, as far as I know or anyone has pointed out. Regards, Nick Maclaren. From duncan.booth at invalid.invalid Thu Dec 28 07:35:27 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Dec 2006 12:35:27 GMT Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: Felix Benner wrote: > So what's the point in typing four spaces for indentation instead of one > tab? So long as you always use only tabs there is no problem. So long as you only use spaces there is no problem. If you mix tabs and spaces you can introduce bugs. In particular, some people set their editor up to expand 1 tab to the next multiple of 4 spaces on their screen, but the usual convention for tabs (and one that Python follows internally) is that tabs expand to the next multiple of 8 spaces. Usually when you mix spaces and tabs what you get either works the way you intend, or it generates a syntax error. Once however when this recurring question popped up I did a search through a load of Python files and actually found once instance of some code which had been released and ran whether tabs were expanded to 4 or 8 space boundaries. Reading that code it was apparent that it had been written using 4 space tabs on the screen, but that when it ran it did something different than had been intended. So, given that mixing tabs and spaces is deadly choose one or the other and stick to it. If you intend to work with other people then choose the same convention as they use. If you are never going to work with others then use whichever scheme makes you most comfortable. Be careful as not all open source projects use the same convention: in previous discussions on this newsgroup there were people arguing quite strongly for using the tab convention. A straw poll indicated that there was 1 open source project with 3 developers using tabs, and all other open source projects use spaces only as the stated (but not always strictly enforced) convention. Your experience may of course differ. Of course nobody in their right minds actually types 4 spaces for indentation: they use an editor where if the automatic indentation isn't correct then hitting the tab key inserts the correct number of spaces (and with luck where hitting the backspace key deletes back to the previous tabstop). From address.good.until.2006.dec.22 at justmail.de Sat Dec 9 19:53:50 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Sun, 10 Dec 2006 01:53:50 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: Ken Tilton schrieb: > > > Andr? Thieme wrote: >> Ken Tilton schrieb: >> >>> The last time we went thru this a Pythonista finally said, Oh, I get >>> it. These five lines of code I have to write all the time (two setup, >>> one func call, two cleanup) can be collapsed into one or two. The >>> thread will be hard to miss in Google groups (two years back?) and >>> the epiphany appears right at the end of the thread. >> >> >> Functional programming is the solution here, not Lisp. > > No, you do not understand. The Pythonista figured it out: a function > would not do. What do you mean? >> You could make that with a new function (in Python), that takes a >> function (and its args, don't remember the correct syntax). >> >> def foo(function, args): >> setup(1) >> setup(2) >> function(args) >> cleanup(1) >> cleanup(2) >> >> >> The nice thing in Lisp would now be to save a lambda with the macro. >> In Python one would fill the name space with throw away functions that >> get called only one time. > > Omigod. Is that what you meant? You think macros are unnecessary because > one could hard-code their expansions as separate functions? And that > would constitute hiding the boilerplate? What happens when the > boilerplate changes? Well, macros are unnecessary from a mathematical point of view: 0 and 1 are enough. But of course they have the potential to be a real time saver. What I want to say is: the situation you gave as an example is not the place where macros shine, because 1st class functions can take over. You could maybe give another example: how would one realize something like (memoize function) in Python? Or (defmethod name :after ..)? Andr? -- From bj_666 at gmx.net Fri Dec 8 10:46:07 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Fri, 08 Dec 2006 16:46:07 +0100 Subject: why is this different? References: <1165582005.677639.292990@16g2000cwy.googlegroups.com> Message-ID: In , Sch?le Daniel wrote: > I have two more examples, but now I understand the difference > > In [70]: x = [eval("lambda:i") for i in range(10)] > In [71]: y = [eval("lambda:%i" % i) for i in range(10)] > > I think [71] is most obvious what the programmer intends But unnecessary use of `eval()` is evil. You can spell it this way: z = [lambda x=i: x for i in range(10)] The `x` is a local name and default values are evaluated and bound when the function is created. Ciao, Marc 'BlackJack' Rintsch From marco.wahl at gmail.com Sun Dec 17 11:16:50 2006 From: marco.wahl at gmail.com (Marco Wahl) Date: 17 Dec 2006 08:16:50 -0800 Subject: Class and instance question In-Reply-To: References: Message-ID: <1166372210.881802.318730@f1g2000cwa.googlegroups.com> rzed writes: To simplify take > class T(object): > def __new__(self): > self.a = 1 and t = T() and then you get >>> print t.a > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'NoneType' object has no attribute 'a' While T.a is 1. > So what the heck is 'T'? It seems that I can't instantiate it or > derive from it, so I guess it isn't a proper class. But it's > something; it has an attribute. What is it? I don't know. > How would it be used > (or, I guess, how should the __new__() method be used)? Any hints? The __new__ method should return the class. In your case return is None. Further the parametername for the __new__ method should be better cls to have a distinction to the usual self for instances. See http://www.python.org/doc/2.4.4/ref/customization.html Best wishes From not-a-real-email-address at not-a-real-domain.com Mon Dec 18 03:29:52 2006 From: not-a-real-email-address at not-a-real-domain.com (Bill Atkins) Date: Mon, 18 Dec 2006 03:29:52 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: This is not a response to any particular post, but rather to the general argument that macros are not as useful as we Lispers claim. Here is a fairly complete GUI RSS reader in 90 lines of Lisp (the GUI code itself is 90 lines, but it makes use of some RSS reading/writing code I had laying around and two public CL libraries: s-xml and trivial-http). The code employs a handy macro called DEFINE-INTERFACE that LispWorks provides with their CAPI toolkit. I hope this will be useful as an illustration of what macros (and Lisp in general) can do, and as an example of what a moderately practical CL application looks like. The application presents a list of feeds and allows the user to add new feeds or to delete existing feeds. The feeds are presented as a tree, with each channel acting as a parent to several items. The user can refresh all of the feeds with the "Refresh All" button. Double-clicking on any item will display its description field (as in the screenshot). Each channel shows the number of unread articles and the articles are arranged so that the unseen articles appear before the articles that have already been read. Important things to note: 1) the DEFINE-INTERFACE syntax closely resembles the syntax of the standard DEFCLASS macro, so newcomers have a basic idea of what DEFINE-INTERFACE is going to do 2) the expansion ( http://galoot.org/~bill/code/rss-reader/expanded.lisp ) of just the DEFINE-INTERFACE is quite involved, a testament to the amount of work the macro saves 3) much of the GUI can be specified declaratively because of the DEFINE-INTERFACE syntactic abstraction, and this declarativeness makes it very easy for maintainers to understand what's going on 4) even without knowing the implementation of DEFINE-INTERFACE and even without prior experience with it, one can make good guesses about what it does 5) the GUI code is stunningly concise Here is the GUI code alone: < http://galoot.org/~bill/code/rss-reader/rss-gui.lisp > Here is a screenshot of the application in development: < http://galoot.org/~bill/code/rss-reader/development.png > and two screenshots of the application in use < http://galoot.org/~bill/code/rss-reader/in%20action.png > < http://galoot.org/~bill/code/rss-reader/in%20action%202.png > Here are the support files: < http://galoot.org/~bill/code/rss-reader/ > Here is an OS X universal binary (run at your own risk; I've only done very basic testing): < http://galoot.org/~bill/code/rss-reader/BarebonesRSS.app.tar.gz > Enjoy. From pavlovevidence at gmail.com Thu Dec 14 12:51:55 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 14 Dec 2006 09:51:55 -0800 Subject: Conditional iteration In-Reply-To: <45810516$0$338$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> <1166062230.798520.135790@f1g2000cwa.googlegroups.com> <4580f7f4$0$331$e4fe514c@news.xs4all.nl> <45810516$0$338$e4fe514c@news.xs4all.nl> Message-ID: <1166118715.306793.122570@l12g2000cwl.googlegroups.com> at wrote: > By the way, > > I think by approving > > a = b if condition else c > > used to avloind > > if condition: > a = b > else: > a = c > > which is dealing with same psychological problem, Guido also recognizes some > need... If you think that this change was made for "psychological" reasons, you are terribly deluded. Carl Banks From stdazi at gmail.com Sun Dec 17 06:18:13 2006 From: stdazi at gmail.com (stdazi) Date: 17 Dec 2006 03:18:13 -0800 Subject: skip last line in loops In-Reply-To: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: <1166354293.574574.73110@73g2000cwn.googlegroups.com> lines = open('blah').readlines() for i in range(0, len(lines)-1) : print lines[i] eight02645999 at yahoo.com wrote: > hi, > how can i skip printing the last line using loops (for /while) > > eg > > for line in open("file): > print line. > > I want to skip printing last line of the file.thanks From juho.schultz at pp.inet.fi Fri Dec 8 16:57:11 2006 From: juho.schultz at pp.inet.fi (Juho Schultz) Date: 8 Dec 2006 13:57:11 -0800 Subject: I think Python is a OO and lite version of matlab In-Reply-To: <1165564104.379172.272890@l12g2000cwl.googlegroups.com> References: <1165564104.379172.272890@l12g2000cwl.googlegroups.com> Message-ID: <1165615031.591209.188890@n67g2000cwd.googlegroups.com> Allen wrote: > Does anyone agree with me? > If you have used Matlab, welcome to discuss it. Matlab is a tool for scientists and engineers. Python is a tool for programmers. I think you are looking at Python from the scientist perspective. Python's numpy and matplotlib modules would probably feel familiar to anyone with some matlab experience. But these are not a part of the language - it is not even a part of the standard library. I will not go deep into the programmer perspective. Some more programmer tools: Java, Tcl, Perl, PHP, Lisp, Ruby. Comparing Python to these makes sense. I think comparing Matlab to any of those would be absurd. Have a look at modpython.org - is there a need for a similar modmatlab? Now, back to the scientist perspective. In 1999, I was starting my M.Sc. in astrophysics and had to select my data analysis tools. I needed the standard scientific tools: scripting, numerics, graphics - Matlab + shell is good enough for this. But I also needed a library for FITS file processing, which was not available in Matlab. So Matlab alone was not enough. Matlab + IRAF + shell was one alternative. Shell + IDL (Interactive Data Language) was another. There were also other possibilities (Fortran for numerics, C or Ftools for FITS). To cut it short, after a while I ended up with shell + IDL as my main tools, occasionally using the others. About two years later my scripts were so complex I decided to learn a scripting language. I was lucky enough to choose Python. Soon I found pyraf, pyfits and numarray, later gnuPlot.py and matplotlib - IDL was no longer needed. Python was enough. Then one day I was looking for a postdoc position. I found something else, and now I do text mining. I still need the science tools: scripting, numerics, graphics. I also need: 1) Regular expressions 2) XML library 3) Database interface Python covers it all. I think Matlab has a Database interface, but how about the others? -- Juho Schultz From f.braennstroem at gmx.de Sat Dec 2 13:07:32 2006 From: f.braennstroem at gmx.de (Fabian Braennstroem) Date: Sat, 2 Dec 2006 19:07:32 +0100 Subject: python 2.5 install from source problem References: <45714acb$0$8594$9b622d9e@news.freenet.de> Message-ID: Hi Martin, * Martin v. L?wis wrote: > Fabian Braennstroem schrieb: >> I just tried to install python 2.5 from source on my >> ScienticLinux (Redhat Clone) machine. It seems to work >> without any problem, at least I am able to run some of my >> old scripts. I installed it with './configure >> --prefix=/opt/python make make altinstall', but now for a >> 'vtk' installation which needs the python libraries I am not >> able to find a file like 'libpython2.5.so.*', which I think >> should be produced (at least at my office's machine (redhat) >> it is there). I just can find a 'libpython2.5.a' file ... >> >> Do I do something wrong? > > I'd say it is a bug in vtk that it requires libpython2.5.so.*. > However, to work-around, you can configure Python with > --enable-shared. Make sure to set LD_LIBRARY_PATH or LD_RUN_PATH > appropriately. Thanks a lot! Greetings! Fabian From mail at microcorp.co.za Fri Dec 8 00:27:55 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 8 Dec 2006 07:27:55 +0200 Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net><17783.32458.730462.8403@montanaro.dyndns.org><024f01c719d3$deff0fc0$03000080@hendrik> <17784.7961.898760.712605@montanaro.dyndns.org> Message-ID: <027001c71a93$409575c0$03000080@hendrik> wrote: > Hendrik> - as long as it works, and is fast enough, its not broken, so > Hendrik> don't fix it... > > That's the rub. It wasn't fast enough. I only realized that had been a > problem once I fixed it though. LOL - this is kind of weird - it was working, nobody complained, you fiddled with it to make it faster, (just because you could, not because you had to, or were asked to), it became faster, and then, suddenly, retrospectively, it became a problem ???? Would it have been no problem if it so happened that you were unable to make it go faster? I don't really follow that logic - but then I have never believed that I could change yesterday... ;-) - Hendrik From deets at nospam.web.de Sun Dec 17 08:59:42 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 17 Dec 2006 14:59:42 +0100 Subject: Changing variable to integer In-Reply-To: References: Message-ID: <4ul0qeF18ih37U1@mid.uni-berlin.de> vertigo schrieb: > > Hello > > I receive such error: > File "p4.py", line 24, in PrintWordCountFloat > print "%s %f" % (word,words[word]) > TypeError: list indices must be integers > > i call PrintWordCountFloat with hash table, keys are words(string) and > values float. > This part of the code: > > def PrintWordCountFloat(words): > number = 0 > for word in words: > print "%s %f" % (word,words[word]) #line 24 > number = number + 1 > print "Total words: %d" %(number) > > My function displays whole table correctly, and after that i receive > mentioned error. > Why ? Where is the problem ? words is a list. If your variable names mean anything, I presume that word is ... well, a word, thus a string. But you can't do [1,2,4]['some_word'] That only works on dictionaries, like this: {'some_word' : 100}['some_word'] Diez From caleb.hattingh at gmail.com Sat Dec 16 16:42:56 2006 From: caleb.hattingh at gmail.com (Caleb Hattingh) Date: 16 Dec 2006 13:42:56 -0800 Subject: Dictionary, iterate & update objects In-Reply-To: <1166302637.147669.266480@f1g2000cwa.googlegroups.com> References: <1166302637.147669.266480@f1g2000cwa.googlegroups.com> Message-ID: <1166305376.376842.36270@16g2000cwy.googlegroups.com> jansenh wrote: > hi comp.lang.python. > > I need some newbe advice on idiomatic use of Python dictionaries. > > I have service with a dictionary which holds a bunch of objects as > values, and an ID as key to each object. Then I want to change an > objects state based on its key. The way I am doing this now is by using > 'fromkeys' and copying my object over in a temporary dictionary, then > manipulating the object, and then I do an 'update' back to the main > dictionary.. :-0 It would be easier to help if you post a short snippet of code that demonstrates the essence of the issue, but I made an attempt at coding what you describe: >>> d = {} >>> class o(object): ... def __init__(self): ... self.x = 0 ... >>> i = o() >>> d[12345]=i >>> temp=d[12345] >>> temp.x = 5 >>> d[12345].x 5 >>> i.x 5 >>> After I assign the object to the dict with ID=12345, I can easily get the object by its key and manipulate its state. The last 4 lines show that the state changed for all the active references to the created object. Is this what you wanted? If you are this Henning Jansen: http://www.henning-jansen.com/ you may get a lot much more accurate help from others in this group by mentioning that you have some Ruby experience. That way, the guys in here who also know Ruby (not me :) can quickly point out the differences in behaviour for your specific question. Regards Caleb From misterwang at gmail.com Fri Dec 22 12:16:32 2006 From: misterwang at gmail.com (Peter Wang) Date: 22 Dec 2006 09:16:32 -0800 Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> Message-ID: <1166807792.176011.170950@h40g2000cwb.googlegroups.com> Bruno Desthuilliers wrote: > > Python is dynamic, and fighting against the language is IMHO a really > bad idea. The only places where theres a real need for this kind of > stuff are when dealing with the "outside world" (IOW : inputs and > outputs). And then packages like formencode can do much more than mere > type-checking > I don't think proper use of type checking is "fighting against the language". The goal of any language is to enable programmers to express their intent in a form that executes correctly. Python is extremely expressive but there is a trade-off with correctness - you can easily say something that you don't mean. Unit testing is sometimes sufficient, but it can never span the infinite space of potential errors. Type-checking method signatures guarantees a certain amount of low-level correctness, and most type-checking mechanisms also serve as documentation aids. I think that with a sufficiently sophisticated type checking syntax, one can get the best of both worlds. If the type checker understood interfaces (like PyProtocols) and its syntax had the flexibility to indicate sets of allowed arguments and aggregates of allowed types/interfaces, it would cover the majority of cases without limiting expressive power. I understand that we're all adults, but it's still nice to have the computer tell us when we're being childish. :) -peter From udodenko at users.sourceforge.net Sat Dec 9 09:24:58 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Sat, 9 Dec 2006 16:24:58 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <7xodqdj2dn.fsf@ruckus.brouhaha.com> <457a8251$0$49201$14726298@news.sunsite.dk> <7xk611baoa.fsf@ruckus.brouhaha.com> Message-ID: <457ac73c$0$49202$14726298@news.sunsite.dk> (message (Hello 'Paul) (you :wrote :on '(09 Dec 2006 02:55:49 -0800)) ( PR> "Alex Mizrahi" writes: ??>> we can implement Scheme's call-with-current-continuation first :) ??>> it's relatively easy -- just a code walker that coverts everyting into ??>> CPS. PR> It's not enough to convert to CPS, you have to be able to actually PR> save the continuation when you switch to another one, so you can go PR> back to the first one later. Maybe I'm missing something but I just PR> don't see how to do that in the Lisp execution model. once you convert code to CPS, you can save continuation -- that would be a simple closure. let's check how it works using CPS from ARNESI library. (setq *cc* (with-call/cc (print 1) (let/cc cc cc) (print 3))) that prints 1 and returns continuation. when we call that contination: (funcall *cc* nil) it prints 3. we can do a generator now: (defun gen1 () (let (state) (setf state (lambda (ignored) (with-call/cc (loop for i upfrom 1 do (let/cc cc (setf state cc) i))))) (lambda () (funcall state nil)))) (setq *gen* (gen1)) (funcall *gen*) => 1 (funcall *gen*) => 2 (funcall *gen*) => 3 then we can make a defgenerator macro so it will look like: (defgenerator gen1 () (loop for i upfrom 1 do (yield i)) certainly yield is (let/cc cc (setf state cc) value) PR> I guess you could write an interpreter in Lisp that simulates it all, PR> but it might as well be a Python interpreter ;-). no, we can just transform code, and it can be then compiled or whatever. there is only additional overhead (lambda and friends) for each call/cc. all "continuous" forms can be efficiently compiled. ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From grante at visi.com Thu Dec 7 10:38:09 2006 From: grante at visi.com (Grant Edwards) Date: Thu, 07 Dec 2006 15:38:09 -0000 Subject: Windows installer for Scientific Python for Python 2.4? References: <12nehgaak7mte4@corp.supernews.com> Message-ID: <12ngdb1a484ek3e@corp.supernews.com> On 2006-12-07, konrad.hinsen at laposte.net wrote: > On 06.12.2006, at 23:36, Grant Edwards wrote: > >> Can anybody point me to a windows installer for scientific >> python that will work with Python 2.4? The Scientific python >> download page only has an installer for Python 2.3. > > If you find one, please send me a copy so that I can put it on > the download page! No luck. I think I'm going to have to uninstall everything and start over with Enthought Python. God I hate working with MS-Windows... -- Grant Edwards grante Yow! Give them at RADAR-GUIDED SKEE-BALL visi.com LANES and VELVEETA BURRITOS!! From bjourne at gmail.com Thu Dec 28 12:16:59 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Thu, 28 Dec 2006 18:16:59 +0100 Subject: keypressed() function In-Reply-To: <1167139552.235499.167090@48g2000cwx.googlegroups.com> References: <1167139552.235499.167090@48g2000cwx.googlegroups.com> Message-ID: <740c3aec0612280916o704a8096v73df6176a2ad051f@mail.gmail.com> > I know that this probably does not exist in the Python library already > as a platform-independant abstraction (even though it probably could), > but then I would at least like solutions that works on Windows and on > Linux. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892 But it is blocking. -- mvh Bj?rn From gagsl-py at yahoo.com.ar Wed Dec 27 21:22:33 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 27 Dec 2006 23:22:33 -0300 Subject: Hooking any/all 'calls' In-Reply-To: References: Message-ID: <7.0.1.0.0.20061227232110.046879d0@yahoo.com.ar> At Wednesday 27/12/2006 23:07, Kevin Little wrote: >In Python 2.4 or 2.5, what is the easiest way to hook any and all >callables such that designated code is executed at the very start and >end of each call? (Yes, I'm trying to come up with a little debugging >tool!:) Is there a single metaclass who's "__call__" method can be >wrapped to do this? See Stain Soiland's site http://soiland.no/software/decorator for his logging decorator and logging metaclass. -- 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 From leo at lspace.org Fri Dec 15 20:20:47 2006 From: leo at lspace.org (Leo Breebaart) Date: 16 Dec 2006 01:20:47 GMT Subject: Designing a cancellable function Message-ID: <4ugvvfF18hlf1U1@mid.individual.net> I have written a function foo() that iterates over and processes a large number of files. The function should be available to the user as library function, via a command-line interface, and through a GUI. So, I added a 'config' object as a parameter to foo() that can be used by the caller to explicitly pass in user-defined settings. Because the processing foo() does can take such a long time, the next thing I did was add an 'update_function' callback parameter that foo() will call regularly, so that the GUI can update a progress bar, and the command-line version can print dots, etc. I now would also like to add the possibility to allow the user to *cancel* the execution of foo() during the processing, and I am wondering what the best / most Pythonic way to design this is. One obvious approach seems to me to turn the 'config' object into something more dynamic, and have foo() regularly inspect it to see if somebody in the main thread has set e.g. config.abort to True. Another approach would be to turn foo() into a proper (threaded) class with distinct run() and abort() methods. But the caller would still need to register the update callback somehow, and I am wondering if this way the whole API for foo() won't become to complex and overdesigned. I was wondering if anybody has any insights or best practice recommendations for me here. Do I keep the function interface? Do I use a class? Any other solution I am overlooking? Many thanks in advance for your advice. -- Leo Breebaart From schoon at amgt.com Tue Dec 19 21:45:25 2006 From: schoon at amgt.com (Mark Schoonover) Date: Tue, 19 Dec 2006 18:45:25 -0800 Subject: regexp Message-ID: <26845D561256D3428A862700DAF69B581AEF26@AG-EX1> Jonathan Curran wrote: > On Tuesday 19 December 2006 15:32, Paul Arthur wrote: >> On 2006-12-19, vertigo wrote: >>> Hello >>> >>>> Take a look at Chapter 8 of 'Dive Into Python.' >>>> http://diveintopython.org/toc/index.html >>> >>> i read whole regexp chapter - >> >> Did you read Chapter 8? Regexes are 7; 8 is about processing HTML. >> Regexes are not well suited to this type of processing. >> >>> but there was no solution for my problem. >>> Example: >>> >>> re.sub("","",htmldata) >>> would remove only comments which are in one line. >>> If comment is in many lines like this: >>> >>> >>> it would not work. It's because '.' sign does not matches '\n' sign. >>> >>> Does anybody knows solution for this particular problem ? >> >> Yes. Use DOTALL mode. > > Paul, I mentioned Chapter 8 so that the HTML processing section would > be taken a look at. What Vertigo wants can be done with relative ease > with SGMLlib. > > Anyway, if you (Vertigo) want to use regular expressions to do this, > you can try and use some regular expression testing programs. I'm not > quite sure of the name but there is one that comes with KDE. > > - Jonathan Curran You have to pay for this one, but I do like Komodo just for the regex feature. I'm rather new to Python, coming over from 10 years of Perl, and it's nice to have Komodo stay consistant. Can't wait for 4.0, so I can get back to having VI key commands.... Back into "Learning Python", and DIP... Thanks! Mark Schoonover IS Manager American Geotechnical V: 858-450-4040 - F: 714-685-3909 - C: 858-472-3816 "Stop the Earth!! I want off!!" From Eric_Dexter at msn.com Fri Dec 1 23:00:38 2006 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: 1 Dec 2006 20:00:38 -0800 Subject: strange problems with code generation In-Reply-To: <1165030526.354684.143270@j72g2000cwa.googlegroups.com> References: <1165022658.313170.134140@79g2000cws.googlegroups.com> <1165025792.522242.281730@l12g2000cwl.googlegroups.com> <1165028063.205065.75360@n67g2000cwd.googlegroups.com> <1165030526.354684.143270@j72g2000cwa.googlegroups.com> Message-ID: <1165032038.223695.180870@80g2000cwy.googlegroups.com> I never see anything from print(data). The example I tried to adapt using readlines may be a little old or something. I did close all the files to prevent problems when I figure out what is wrong with what I have. John Machin wrote: > You say "I am sure the readlines code is crashing it." I can't imagine > how you can be sure of anything, but yes, it is a possibility that > sys.stdin.readlines() might behave strangely when called from a GUI > kit. Why from sys.stdin anyway? > > You have two *known* definite problems (not closing your output files, > and no such attribute as "writeline") -- *fix* them, and try again. > > Do try to test that function in isolation. > Put print statements in as I suggested. Comment out the .bat file > invocation. > Try calling the function from the interactive interpteter. Check if the > files are being created, with the right size. If it works, add back the > .bat file invocation. If that works, try it from your GUI. > > IOW, try to attack your problem methodically. > > AND try to answer at least some of the questions that helpers might ask > you, like what does "print(data)" produce -- they're not asked out of > idle curiosity. > > HTH, > John From kentilton at gmail.com Fri Dec 15 09:42:58 2006 From: kentilton at gmail.com (Ken Tilton) Date: Fri, 15 Dec 2006 09:42:58 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4ufemoF17of60U3@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> Message-ID: greg wrote: > Ken Tilton wrote: > >> The reason I post macro expansions along with examples of the macro >> being applied is so that one can see what code would have to be >> written if I did not have the defskill macro to "write" them for me. > > > It seems to me your brain is somewhat stuck on the use > of macros. You're looking at the expansion of your > macro and assuming that you'd have to write all that > code by hand if you didn't have macros. You're not > thinking about alternative approaches,... I think your brain is stuck on flaming. I am not thinking about Python approaches, I am sking Pythonistas to do that. After understanding my examples. Unfortunately I do not see the latter really happening, so we are about done here. > Unless there's something very subtle that I'm missing > (I can't claim to follow exactly what all the code > you posted does in detail) I haven't seen anything > that couldn't be done quite reasonably with an > appropriate data structure and ordinary functions > and methods operating on that data structure. I did explain the last little fun bit (where reverse code miraculously got a case-specific "signed-value" parameter bound to exactly the right bit of math structure). This process works only if you then ask specifically about that (if anything was unclear--my guess is you did not try all that hard since you are in argue-mode). The other reason you may not have understodd is that that is waaaaay meta-cool, so meta I do understand if it went over your head and I would (have been) happy to explain had you asked. Time to put the game on, I think. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From simone.leo at gmail.com Thu Dec 14 12:01:54 2006 From: simone.leo at gmail.com (Tekkaman) Date: 14 Dec 2006 09:01:54 -0800 Subject: Logging module: problem with some mapping keys In-Reply-To: References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166106298.176199.301190@f1g2000cwa.googlegroups.com> <1166113691.753244.189350@f1g2000cwa.googlegroups.com> Message-ID: <1166115714.082561.87420@t46g2000cwa.googlegroups.com> lib is a symlink to lib64 Peter Otten wrote: > Tekkaman wrote: > > > Peter Otten wrote: > >> Tekkaman wrote: > >> > >> > Thanks for the hint, but it's not a symlink > >> > >> What does logging._srcfile contain? Should be > >> > >> >>> import logging > >> >>> logging._srcfile > >> '/usr/lib/python2.4/logging/__init__.py' > >> > >> on your machine, but probably isn't. > > > '/usr/lib64/python2.4/logging/__init__.py' > > And neither /usr/lib nor /usr/lib/python2.4 are symlinks? > > Peter > > PS: Please don't top-post From tayssir.john at googlemail.com Sun Dec 10 14:50:08 2006 From: tayssir.john at googlemail.com (tayssir.john at googlemail.com) Date: 10 Dec 2006 11:50:08 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165780208.497031.62320@73g2000cwn.googlegroups.com> Steven D'Aprano wrote: > I'd love to say it has been fun, but it has been more frustrating than > enjoyable. I don't mind an honest disagreement between people who > genuinely are trying to see the other's point of view, but I don't think > that was the case here. What was especially frustrating was that the more > I tried to understand certain Lispers' positions by asking questions, the > more nasty and insulting they became. So now I have an even better > understanding for why Lispers have a reputation for being difficult and > arrogant. This is only because they openly disagree with your beliefs. Note that you appear the same way to your Lisp-using flamewarrior counterparts. We might look in the mirror: Maybe Lisp users are singled out as particularly arrogant because they claim that the last 20 or so years of the software profession have been something of a fraud. Tayssir From m.yanowitz at kearfott.com Mon Dec 18 07:37:47 2006 From: m.yanowitz at kearfott.com (Michael Yanowitz) Date: Mon, 18 Dec 2006 07:37:47 -0500 Subject: Can a Tkinter GUI check for abort script: Message-ID: <004401c722a1$52cdda50$0d7d12ac@kearfott.com> Hello: I have successfully implemented a Tkinter GUI which has this (simplified here for explanation): +-------------------------------------+ | filename: [ ./test3.py] | | | | [Run Script] | +-------------------------------------+ But, now what I would like to do while the script is running, is replace the "Run Script" with "Abort Script". +-------------------------------------+ | filename: [ ./test3.py] | | | | [Abort Script] | +-------------------------------------+ So, every tenth of a seconds or ??? better time, I would like to 'return' to the GUI and check if the "Abort Script" button has been pressed. How do I do this? Or is there a better way to implement this? Thanks in advance: Michael Yanowitz From david at boddie.org.uk Wed Dec 6 12:44:24 2006 From: david at boddie.org.uk (David Boddie) Date: 6 Dec 2006 09:44:24 -0800 Subject: PyQt, designer, and directional flow References: <1165380360.285089.94980@16g2000cwy.googlegroups.com> Message-ID: <1165427064.861889.85250@l12g2000cwl.googlegroups.com> borntonetwork wrote: > I am creating a simple form using designer (qt4) on Ubuntu. I use pyuic > to create a python script from the form. I run the script and the form > shows up fine. The idiosyncrasy occurs when I try to type text into a > QTextEntry widget. The text is right-aligned, not left-aligned as I had > set it up in the property editor in designer. > > This behavior is not limited to alignment in text fields. If I insert a > QTableWidget and add items to it, the items appear from right to left, > not left to right. For example, if I create a 4-column table and use > setItem() to insert the numbers 1, 2, 3, and 4 into columns 0, 1, 2, 3 > respectively, I get this: > > 4 3 2 1 > > The same thing goes with the headers. I create a QStringList ("1", "2", > "3", "4") and add it using setHorizontalHeaderLabels() then the headers > show up as 4 3 2 1. This sounds like something to do with right-to-left layouts for internationalisation rather than just "normal" right-aligned text and layouts. > This is my first qt app using python instead of C++, so I may be doing > something wrong. Not necessarily, though we should probably run through some checks. :-) * Do Qt applications written in C++ work fine on your system? * Is your system configured to use a right-to-left language, such as Arabic or Hebrew? * Have you tried previewing the form in Qt Designer and entering text, just to see if it behaves the same way there? > I am grateful for any ideas someone might have. Well, it sounds like a strange bug or configuration issue, but we can probably figure out what's happening. David From mail at microcorp.co.za Thu Dec 21 00:51:58 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 21 Dec 2006 07:51:58 +0200 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4uslgfF18sq18U1@mid.individual.net> Message-ID: <01f501c724cb$8fa58960$03000080@hendrik> "Nick Maclaren" wrote: > Not at all. I didn't say that they came in pairs. Consider: > > [str1, str2, agent1, str3, agent2, agent3, agent4, str4, ...] > > See Algol 68 for an example of this. When I looked at the above, I went "tilt" - If you had no a priori knowledge about how many strings are associated with an agent - (or agents with a string), then you could only identify an agent because it was not a string, or if it had some other magic property... I cannot imagine a use case for this that would not be better done with a dict using the agents as keys - or are the strings the keys? If the strings are "inputs" and the agents "routines" - is the idea to call the agents one after the other all with the same input, or is agent3 called with the return value of agent2 like a systolic array arrangement? What would be the reason for doing it like this? I am confused - Hendrik From chris.cavalaria at free.fr Sun Dec 17 04:59:29 2006 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sun, 17 Dec 2006 10:59:29 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> <1166325882.434177.313730@80g2000cwy.googlegroups.com> Message-ID: <45851501$0$18425$426a34cc@news.free.fr> Sandra-24 wrote: > On 12/16/06, The Night Blogger wrote: >> Can someone recommend me a good API for writing a sexy looking (Rich UI >> like WinForms) shrink wrap application > >> My requirement is that the application needs to look as good on Windows >> as on the Apple Mac > > wxPython or something layered on it would be the way to go. I tried all > the popular toolkits (except qt) and nothing else comes close for cross > platform gui work. Don't let people persuade you otherwise, that caused > me a lot of trouble. Well, you should try qt too ;) BTW, does wxWindow/wxPython have something that allows you to switch the OK and Cancel button position according to the current machine GUI guidelines? From philip.armitage at gmail.com Fri Dec 15 11:30:36 2006 From: philip.armitage at gmail.com (philip.armitage at gmail.com) Date: 15 Dec 2006 08:30:36 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xodq5tboy.fsf@ruckus.brouhaha.com> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> Message-ID: <1166200235.110121.172160@f1g2000cwa.googlegroups.com> Paul Rubin wrote: > Andr? Thieme writes: > which isn't purely a matter of token count. And if (+ 2 3) were > really as easy to read as 2+3, mathematics would have been written > that way all along. Maybe I am a "mutant" as Ken suggests but while mathematicians may think in terms of infix, programmers have got very used to: function (arg, arg, ...) So when I see (+ 2 3) I just think function 'add' with arguments 2 and 3. Yep, I've moved the parens and removed the comma but that just makes it even clearer. Then bring in more statement and you either have to remember precedence rules (I can never remember those) or add some parenthesis (oops!). This may sounds paper thin to some people but if you appreciate consistency then you'll appreciate the syntax. Phil From podi.ex at gmail.com Wed Dec 13 15:33:08 2006 From: podi.ex at gmail.com (Podi) Date: 13 Dec 2006 12:33:08 -0800 Subject: Windows SetLocalTime In-Reply-To: References: <1166040733.947268.80050@16g2000cwy.googlegroups.com> Message-ID: <1166041988.571906.244570@j72g2000cwa.googlegroups.com> Yes, thank you. I found the function SetLocalTime or SetSystemTime to set the time from MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am having trouble passing parameter to the functions in Python. Rob Williscroft wrote: > > Google will usually find the documentation of anything in the > Windows API however sometimes it also helps to add "msdn" to > your search as in: > From address.good.until.2006.dec.22 at justmail.de Fri Dec 15 10:22:34 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=) Date: Fri, 15 Dec 2006 16:22:34 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7x7iwtjk3a.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin schrieb: > Andr? Thieme writes: >> def nif(num, pos, zero, neg): >> if num > 0: >> return pos >> else: >> if num == 0: >> return zero >> else: >> return neg > > def nif(num, pos, zero, neg): > return (neg, zero, pos)[cmp(num, 0)+1] That is a nice idea. I can do the same in Lisp, but have to do it without syntactic sugar which makes it longer, characterwise: (defun nif2 (num pos zero neg) (nth (1+ (truncate (signum num))) (list pos zero neg))) What Python has is cmp. That is doing what truncate+signum do in Lisp. So that makes the biggest difference. Another one is that Lisps signum keeps the datatype: cmp(5.3, 0) => 1 (signum 5.3) => 1.0 Or also with complex numbers [syntax #C(real, img)]: (signum #C(10 4)) => #C(0.9284767 0.37139067) Anyway, from the complexity the Lisp version is a bit better. The Python version has 11 tokens: return, tuple-reference, comma, neg, zero, pos, +, 1, cmp, num, 0 and the Lisp version has only 9: nth, 1+, truncate, signum, num, list, pos, zero, neg (I didn't count the function head, because both have the same token count). >> The messages were printed in each case. >> To stop that I need lazy evaluation: >> CL-USER> (mapcar #'(lambda (x) >> (funcall >> (nif x >> #'(lambda () (p)) >> #'(lambda () (z)) >> #'(lambda () (n))))) >> '(0 2.5 -8)) > > in Python: > > def lazy_nif(num, pos, zero, neg): > return (neg, zero, pos)[cmp(num, 0)+1]() # the () at the end means funcall > > map(lambda x: lazy_nif(x, p, z, n), (0, 2.5, -8)) We could do the same in Lisp: (defun lazy-nif (num pos zero neg) (funcall (nth (1+ (truncate (signum num))) (list pos zero neg)))) Here the token count is 12py vs 10cl. CL-USER> (mapcar #'(lambda (x) (lazy-nif2 x #'p #'z #'n)) '(0 2.5 -8)) "no no" "very negative" "very positive" ("zero" "negative" "positive") But there is a disadvantage: >>> lazy_nif(0, "p", "z", "n") Traceback (most recent call last): File "", line 1, in ? File "", line 2, in lazy_nif TypeError: 'str' object is not callable I don't know how I can fix that. Maybe you could tell me. In Lisp I would just go with the macro. That works for all cases. > "nif" is even cleaner in Haskell, if I have this right: > > nif x p z n | (x < 0) = n > | (x == 0) = z > | (x > 0) = p > > All Haskell evaluation is automatically lazy, so no lambdas etc. needed. Yes, that was what I already supposed. Do you also know how I can "deactivate" lazyness? Andr? -- From george.sakkis at gmail.com Wed Dec 13 10:03:13 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 13 Dec 2006 07:03:13 -0800 Subject: Frame hacking References: <1165956409.786690.150240@79g2000cws.googlegroups.com> <1165957786.424433.236650@79g2000cws.googlegroups.com> <1165960590.466033.172030@l12g2000cwl.googlegroups.com> Message-ID: <1166022193.628689.182050@j72g2000cwa.googlegroups.com> George Sakkis wrote: > Gabriel Genellina wrote: > > On 12 dic, 17:46, "George Sakkis" wrote: > > > > > I wonder if the following is possible: > > > > > > def inject_n_call(func, **kwds): > > > '''Call func by first updating its locals with kwds.''' > > > > > > def f(): > > > return x*y > > > > > > > >>> eval(f.func_code, dict(x=3,y=4)) > > 12 > > Sweet! I think I just reinvented what eval does in this case by > fiddling with sys.settrace and frame.f_globals. Glad to trash my > 20-line function for an one-liner :) Actually I thought about this and it would be more convenient in my case if I could change the "signature" of f to "def f(x,y)" so that I can pass positional arguments instead of a keywords (don't ask why). I've tried creating a new code object by tweaking co_varnames, co_argcount, co_nlocals and making a new function out of it but it doesn't work.. does co_code have to be changed as well, and if so, how? George From nick at craig-wood.com Sat Dec 30 01:32:53 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 30 Dec 2006 00:32:53 -0600 Subject: Can I beat perl at grep-like processing speed? References: Message-ID: js wrote: > Just my curiosity. > Can python beats perl at speed of grep-like processing? > > $ wget http://www.gutenberg.org/files/7999/7999-h.zip > $ unzip 7999-h.zip > $ cd 7999-h > $ cat *.htm > bigfile > $ du -h bigfile > du -h bigfile > 8.2M bigfile > > #!/usr/local/bin/perl > open(F, 'bigfile') or die; > > while() { > s/[\n\r]+$//; > print "$_\n" if m/destroy/oi; > } > #!/usr/bin/env python > import re > r = re.compile(r'destroy', re.IGNORECASE) > > for s in file('bigfile'): > if r.search(s): print s.rstrip("\r\n") > > $ time perl grep.pl > pl.out; time python grep.py > py.out > real 0m0.168s > user 0m0.149s > sys 0m0.015s > > real 0m0.450s > user 0m0.374s > sys 0m0.068s > # I used python2.5 and perl 5.8.6 Playing for the other side temporarily, this is nearly twice as fast... $ time perl -lne 'print if m/destroy/oi' bigfile >pl.out real 0m0.133s user 0m0.120s sys 0m0.012s vs $ time ./z.pl >pl.out.orig real 0m0.223s user 0m0.208s sys 0m0.016s Which gives the same output modulo a few \r -- Nick Craig-Wood -- http://www.craig-wood.com/nick From arkanes at gmail.com Mon Dec 4 12:27:45 2006 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 4 Dec 2006 11:27:45 -0600 Subject: Factory pattern implementation in Python In-Reply-To: <1165250357.794022.87520@16g2000cwy.googlegroups.com> References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> Message-ID: <4866bea60612040927j1a6b1e88q7a7ef480ef035a9b@mail.gmail.com> On 4 Dec 2006 08:39:17 -0800, googlegroups at romulo.e4ward.com wrote: > Hi, > > I need to parse a binary file produced by an embedded system, whose > content consists in a set of events laid-out like this: > > ... > > Every "event" is a single byte in size, and it indicates how long is > the associated "data". Thus, to parse all events in the file, I need to > take it like a stream and read one event at a time, consuming bytes > according to the event value, and jumping to the next event, until an > EOF is reached. > > Since there are dozens of almost completely heterogeneous events and > each one of them may imply different actions on the program parsing the > file, I thought it would be convenient to have one class encapsulating > the logic for every event. The parser would then sit in a loop, > creating objects of different classes and calling a method (say > "execute"). That method (different in every class) is responsible for > consuming the bytes associated with the event. > > Hence, as the class the parser needs to instantiate in each iteration > is not known in advance, a factory should be implemented. Somehow the > factory should know how to map an event to a class. I don't know of the > best way I should do that in Python. I made an attempt along the > following lines: > > 1. Create a base class for the events; > 2. For every descendant class declare (in the class body) a public > attribute "eventNum" and assign it the value of the event it will be > responsible for; > 3. At runtime, the factory constructor scans the event class hierarchy > and builds a dictionary mapping "eventNum"'s to classes. > > A draft of the implementation follows: > > ################################# > > ##### ##### > > class EvtBase: > def __init__(self, file): > self.file = file > > def execute(self): > pass > > class Evt1(EvtBase): > eventNum = 1 > def execute(self): > ... > > class Evt2(EvtBase): > eventNum = 2 > def execute(self): > ... > > ... > > class EvtN(EvtBase): > eventNum = N > def execute(self): > ... > > > ##### ##### > > import inspect > import events > > class Factory: > def __isValidEventClass(self, obj): > if inspect.isclass(obj) and obj != events.EvtBase and \ > events.EvtBase in inspect.getmro(obj): > for m in inspect.getmembers(obj): > if m[0] == 'eventNum': > return True > return False > > def __init__(self): > self.__eventDict = {} > for m in inspect.getmembers(events, self.__isValidEventClass): > cls = m[1] > self.__eventDict.update({cls.eventNum: cls}) > > def parseEvents(self, file): > while not file.eof(): > ev = file.read(1) > self.__eventDict[ev](file).execute() > > ################################# > > I'm using the inspect module to find the event classes. One drawback of > this approach is the need to keep the event classes in a module > different from that of the factory, because the getmembers method > expects an already parsed object or module. (The advantage is keeping > the event number near the class declaration.) I've already had to make > the solution generic and I found it was not straightforward to separate > the common logic while avoiding the need to keep the factory and the > events in two distinct modules. > > Is there anything better I can do? I don't have enough experience with > Python, then I don't know whether it offers a more obvious way to > address my problem. > I'd have the classes register themselves rather than trying to find them. This removes the need to have a common base class (preserves duck typing) and lets everything communicate via the factory module. #in module Factory.py EventMap = {} #in module events.py import Factory class EventHandler: Factory.EventMap[1] = EventHandler #in module parser.py import Factory handler = Factory.EventMap[event]() handler.handleEvent(data) There's probably some way to wrap the registration up in a metaclass so it's handled implicitly, but I prefer the explicit approach. > Thanks in advance. > > -- > Romulo A. Ceccon > 'romulo%s\x40yahoo.com.br' % 'ceccon' > > -- > http://mail.python.org/mailman/listinfo/python-list > From Michael.Schummacher at gmail.com Tue Dec 19 14:12:52 2006 From: Michael.Schummacher at gmail.com (MohF1) Date: 19 Dec 2006 11:12:52 -0800 Subject: Star-P Anyone? Message-ID: <1166555572.610455.274510@n67g2000cwd.googlegroups.com> I was wondering if some power users of Python would be willing to pay money to benefit from doing a lot of their scientific/engineering/financial modeling and simulation from running their programs on high powered computing HPC. HPC would essentially mean that you run on a cluster or group of computers. The problem is, it takes forever to parallelize code and as such many people are uninterested in running their simulations, models, etc. on a parallel platform. If one were to use the Star-P platform they could be using their desktop client (MATLAB, Maple, R, Python, etc.) and the Star-P software could automatically code their programs in a parallel manner. The main benefit of Star-P would be that the time it would take a user to run a simulation, model, etc. would take far less time due to the parallelizing of the code and being able to run on more machines. Granted Star-P is probably more suited towards individuals who are in the fields of academia, financial services, aerospace, etc. where your models take hours to run and execute... If you have any further questions about this feel free to PM me or goto http://www.interactivesupercomputing.com P.S. If you folks know of any other Python forums where I can find such people (academics etc) I would appreciate it if you could tell me... Thanks From eric.pederson at gmail.com Sat Dec 30 04:37:42 2006 From: eric.pederson at gmail.com (Eric Pederson) Date: Sat, 30 Dec 2006 01:37:42 -0800 Subject: Why does Python never add itself to the Windows path? In-Reply-To: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com> Message-ID: <45963366.7010809@gmail.com> Ben Sizer wrote: >I've installed several different versions of Python across several >different versions of MS Windows, and not a single time was the Python >directory or the Scripts subdirectory added to the PATH environment >variable. Every time, I've had to go through and add this by hand, to >have something resembling a usable Python installation. No such >problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or >Kubuntu. So why is the Windows install half-crippled by default? I just >rediscovered this today when trying to run one of the Turbogears >scripts, but this has puzzled me for years now. > +1 It is a pain for me because it is something I need to remember to do maybe once a year or less. It seems best practice with Windows is to throw away the machine every 2 years - so much crap gets automatically installed in places and ways not solicited I'd think only cybermonks get away clean. That the Python install is a good citizen in this regard is noble, but does it really make a difference in regard to the overall Windows installation? And is that difference worth the recurring pain of not having Python on the path automatically? There must be hundreds of programs on the PATH of the machine I type on, its ugly. And lets not even talk about the Registry. Time to throw away the machine. That's what I get for being a cheap slut for any interesting program. Windows will never be UNIX, invest in penicillin. From gagsl-py at yahoo.com.ar Mon Dec 18 19:50:42 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 18 Dec 2006 21:50:42 -0300 Subject: No subject In-Reply-To: <20061218064100.ADD3A1E400C@bag.python.org> References: <20061218064100.ADD3A1E400C@bag.python.org> Message-ID: <7.0.1.0.0.20061218214734.05e8c8d0@yahoo.com.ar> At Monday 18/12/2006 03:34, Divya Prakash wrote: > I would like to parse java files and detect class name's, > attributes name's type's and visibility (and or list of > methods). > Is there any module who can parse easily a java file using jython? You could try javadoc (the java package), it is easier to use than a pure reflection approach. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From webraviteja at gmail.com Wed Dec 13 16:28:34 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 13 Dec 2006 13:28:34 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165878559.036906.35680@80g2000cwy.googlegroups.com> Message-ID: <1166045314.177121.10420@16g2000cwy.googlegroups.com> Robert Uhl wrote: > "Ravi Teja" writes: > > > Mark Tarver wrote: > >> > >> seems to show that Python is a cut down (no macros) version of Lisp > >> with a worse performance. > > > > By that standard, every other mainstream dynamically typed language > > for you is a cut-down version of Lisp with worse performance. > > Pretty much;-) > > Fewer features, worse performance. Why use 'em? Usability. Especially when users quote a very significant difference here. From fredrik at pythonware.com Thu Dec 14 13:20:39 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 19:20:39 +0100 Subject: tuple.index() In-Reply-To: References: <1166103409.199435.290670@79g2000cws.googlegroups.com> <1166118142.144177.78790@l12g2000cwl.googlegroups.com> Message-ID: Nick Maclaren wrote: > Indeed. The code to sort out the problem was trivial. I was curious > as to the reason, since there was no technical or mathematical one you still haven't explained what your solution to the technical issues is, though. if simply repeating that something is trivial would make the real issues go away, the Py3K developers would have made a lot more progress over the last year. > seem to have accidentally committed one of Python's Seven > Unforgiveable Heresies duck-typing applies to usenet posters too, you know. if you look like a ... From markandeya at sriaurobindoashram.com Tue Dec 26 11:11:20 2006 From: markandeya at sriaurobindoashram.com (mark) Date: Tue, 26 Dec 2006 21:41:20 +0530 Subject: Stani's Python Editor is looking for a new webhost Message-ID: <000201c72908$7c576d10$fa00a8c0@asc> Dear Stani, Very much wishing you a new and great web host for the new year. I feel and read also from so many that you are doing a great service for Python users an d being an example of the Free software movement. i thank you very much and hope you will be back on the web soon. What help do you need now and what kind and level of contributions ( in expertise or lack of it) can we offer. All the best for the new year. markandeya From tomas at fancy.org Thu Dec 28 23:51:47 2006 From: tomas at fancy.org (Tom Plunket) Date: Thu, 28 Dec 2006 20:51:47 -0800 Subject: textwrap.dedent replaces tabs? References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> <232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com> Message-ID: Frederic Rentsch wrote: > Your rules seem incomplete. Not my rules, the stated documentation for dedent. "My" understanding of them may not be equivalent to yours, however. > What if common tabs remain after stripping common white space? What if we just go with, "[r]emove any whitespace than can be uniformly removed from the left of every line in `text`." ? > Does this never happen? Or can we hope it doesn't happen? "Hope" has no place in programming software that is to be used by others. > To err on the side of caution I complete your rules and this is my > (tested) attempt at expressing them pythonically. Inasmuch as "my" rules have been expressed via tests, the provided code fails four of the five tests provided. > (I admit it does look awfully sevety-ish. Just a vulgar little > function.) Seventys-ish is as much a statement about the lack of statement about how you actually tested it as it is that an implementation was made apparently without understanding of the requirements. -tom! -- From michele.simionato at gmail.com Thu Dec 14 03:21:44 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 14 Dec 2006 00:21:44 -0800 Subject: Defining classes In-Reply-To: References: Message-ID: <1166084504.874234.61380@80g2000cwy.googlegroups.com> Nick Maclaren wrote: > It would be much cleaner not to have to fiddle with static > members after the class is initialised. You can hide the fiddling, for instance with the trick explained here: http://www.phyast.pitt.edu/~micheles/python/classinitializer.html Michele Simionato From dr.mtarver at ukonline.co.uk Fri Dec 8 06:07:09 2006 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: 8 Dec 2006 03:07:09 -0800 Subject: merits of Lisp vs Python Message-ID: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for my general education. Mark From caleb.hattingh at gmail.com Fri Dec 22 11:19:59 2006 From: caleb.hattingh at gmail.com (Caleb Hattingh) Date: 22 Dec 2006 08:19:59 -0800 Subject: rsync for python? In-Reply-To: References: Message-ID: <1166804399.302184.277290@h40g2000cwb.googlegroups.com> > I want to build rsync server that can run in linux and windows, and > configure by python. So I'm looking for something like rsync for python. > I find rsync.py and pysync. But rsync.py looks like a client mode, > it can't be a rsync server, is it? Can pysync be a rsync server? Hi nienfeng As file synchronizers go, I have had very good experience with Unison: http://www.cis.upenn.edu/~bcpierce/unison/ which supports unix and windows, but does not run as a server and is not directly python-enabled. You can set it up to run automatically using cron (linux) or Scheduled Tasks (windows), if that was the functionality you wanted in a server implementation of such a tool. regards Caleb From CRhode at LacusVeris.com Wed Dec 6 00:02:34 2006 From: CRhode at LacusVeris.com (Chuck Rhode) Date: Tue, 5 Dec 2006 23:02:34 -0600 Subject: PythonTidy In-Reply-To: References: <20061205150527.GA3854@loki> Message-ID: <20061206050234.GB18642@loki> Thomas Heller wrote this on Tue, Dec 05, 2006 at 07:06:30PM +0100. My reply is below. > I suggest you open the file with open(input-file, "rU"). This doesn't work so pretty good while reading from sys.stdin, so I'm still at the drawing board. -- .. Chuck Rhode, Sheboygan, WI, USA .. 1979 Honda Goldwing GL1000 (Geraldine) .. Weather: http://LacusVeris.com/WX .. 27? ? Wind S 15 mph ? Sky overcast. From bblais at bryant.edu Thu Dec 14 21:36:24 2006 From: bblais at bryant.edu (Brian Blais) Date: Thu, 14 Dec 2006 21:36:24 -0500 Subject: automatically grading small programming assignments In-Reply-To: <1166131842.963017.206130@79g2000cws.googlegroups.com> References: <1166129734.888298.210830@l12g2000cwl.googlegroups.com> <1166131842.963017.206130@79g2000cws.googlegroups.com> Message-ID: <45820A28.6080708@bryant.edu> commander.coder at hotmail.com wrote: > bearophileHUGS at lycos.com wrote: > Then on your PC you can >> run a script that loads each of such programs, and runs a good series >> of tests, to test their quality... > What happens if someone-- perhaps not even someone in the class-- does > some version of os.system('rm -Rf /') ? > I was thinking of including a dummy os.py and sys.py, so import os, and import sys would fail. Would this work? Is there anything else obvious. I can have student authentication, that's not a problem. bb -- ----------------- bblais at bryant.edu http://web.bryant.edu/~bblais From mauriceling at acm.org Sun Dec 3 01:53:51 2006 From: mauriceling at acm.org (Maurice LING) Date: Sun, 03 Dec 2006 06:53:51 GMT Subject: db.commit() to take effect In-Reply-To: <1165124503.182532.16170@79g2000cws.googlegroups.com> References: <1165123781.350370.308320@79g2000cws.googlegroups.com> <1165124503.182532.16170@79g2000cws.googlegroups.com> Message-ID: <4572747b$1@news.unimelb.edu.au> John Machin wrote: > progman wrote: > >>I was testing the python+mysql >> >>here are my sample codes: >>------------------------ >>import MySQLdb >>from pprint import pprint >>db = MySQLdb.connect(host="localhost", user="root", passwd="password", >>db="database") >>cursor = db.cursor() >>cursor.execute('update promo set date=100") >> >> >>------------------------ >> >>i was expecting the cursor.execute will update my db immediately. >>it wasn't. not until i run db.commit(), then only i see the value >>changes. >> >>it that the right way to update db? > > > Short answer: yes > > Longer answer: In most non-trivial db apps, to carry out a given > real-world transaction, you will need to do multiple updates/inserts, > and you want them all to happen, or none to happen. The database would > be inconsistent if your app or server crashed half-way through. Imagine > you are transferring some money to someone else's bank account. The > money gets deducted from your account but not added to theirs -- not > good. [A real banking system would not be that simple, but you should > get the general idea.] So you do db.commit() after the last > insert/update. > > HTH, > John > Adding to that, PEP 249 specified that if a DBMS has auto-commit feature, it should be set to "off", implying that cursor.execute() and cursor.executemany() methods do not commit the database. Database commit is defined as .commit() method in connect object. Cheers ML From duncan.booth at invalid.invalid Fri Dec 1 03:36:43 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 1 Dec 2006 08:36:43 GMT Subject: v2.3, 2.4, and 2.5's GUI is slow for me References: <7630074.post@talk.nabble.com> Message-ID: g4rlik wrote: > No one can help? This is seriously bugging me to no end. >> My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run >> very sluggishly. When I type in them or move them around my desktop, >> it's very slow. I have figured out that this is because of the >> subprocesses running. Always slow or just sometimes? Idle can get very slow if you have generated a lot of output in the shell window, but usually it performs just fine. If you've accidentally printed "range(100000)" then your best best is to kill it and restart. Use idle for development and testing: its best if you run actual scripts outside the development environment. From Carl.Wolff at imtech.nl Wed Dec 6 04:51:50 2006 From: Carl.Wolff at imtech.nl (Carl.Wolff at imtech.nl) Date: Wed, 6 Dec 2006 10:51:50 +0100 Subject: Copy vs Deepcopy in multithreaded contexts Message-ID: Hello, this issue is solved, no help needed. Gtx Carl. ----- Forwarded by Carl Wolff/IT/NL/Imtech on 06-12-2006 10:51 ----- Carl Wolff/IT/NL/Imtech wrote on 05-12-2006 22:55:20: > Hello > > question about copy vs deepcopy used in multithreaded context: > > suppose the following program below: > > the original dictionary is modified after the thread is started, the > thread works on a copied and deepcopied version of the original > dictionary. Is the dictionary named "originalcopy" isolated from > changes in original in multithreaded context? > > The program reports no errors but I want to be really sure about this > > Thanks > Carl. > > > > > > > original = {} > originalcopy = {} > originaldeepcopy = {} > > class checker(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > pass > def run(self): > while True: > for i in originaldeepcopy: > if originalcopy[i] == originaldeepcopy[i]: > pass > else: > print "error", originalcopy[i], "Not equal to", originaldeepcopy[i] > > i = 0 > while i<1000: > original[i] = i > i = i + 1 > > originalcopy = copy.copy(original) > originaldeepcopy = copy.deepcopy(original) > > test = checker() > test.start() > > time.sleep(0.5) > > while True: > i = 0 > while i<1000: > original[i] = i*2 > i = i + 1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Fri Dec 1 03:30:09 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 1 Dec 2006 08:30:09 GMT Subject: Functions, callable objects, and bound/unbound methods References: Message-ID: Ron Garret wrote: > I want to say: > > trace(c1.m1) > > and have c1.m1 be replaced with a wrapper that prints debugging info > before actually calling the old value of m1. The reason I want that > to be an instance of a callable class instead of a function is that I > need a place to store the old value of the method so I can restore it, > and I don't want to start building a global data structure because > that gets horribly ugly, and a callable class is the Right Thing -- if > there's a way to actually make it work. > > Is there? I tried the obvious things (like making callable inherit > from function, and adding im_func and im_self attribuetes) but they > didn't work. Read "Functions and Methods" in http://users.rcn.com/python/download/Descriptor.htm You need to implement a __get__ method on your class. From nagle at animats.com Fri Dec 29 17:04:43 2006 From: nagle at animats.com (John Nagle) Date: Fri, 29 Dec 2006 22:04:43 GMT Subject: No way to set a timeout in "urllib". Message-ID: <%hglh.1141$ji1.1051@newssvr12.news.prodigy.net> There's no way to set a timeout if you use "urllib" to open a URL. "HTTP", which "urllib" uses, supports this, but the functionality is lost at the "urllib" level. It's not available via "class URLopener" or "FancyURLopener", either. There is a non-thread-safe workaround from 2003 at http://mail.python.org/pipermail/python-bugs-list/2003-September/020405.html but it was rejected as a feature at https://sourceforge.net/tracker/?func=detail&atid=105470&aid=803634&group_id=5470 without anything better going in. Despite this, current documentation recommends that approach: http://svn.python.org/projects/python/trunk/Doc/howto/urllib2.rst Someone proposed to fix this http://mail.python.org/pipermail/python-dev/2006-July/066967.html but was discouraged from doing so. The code was forked by Zope as a workaround in 2003: http://pywebsvcs.sourceforge.net/apidocs/wstools/Utility.html but that's not in the mainstream Python tree. The correct fix would probably be to add methods to class URLopener to control this; that's the usual way of handling special URL opening situations. John Nagle From fredrik at pythonware.com Wed Dec 13 05:37:03 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Dec 2006 11:37:03 +0100 Subject: inconvenient unicode conversion of non-string arguments In-Reply-To: References: <1166004150.866538.299670@j72g2000cwa.googlegroups.com> Message-ID: Holger Joukl wrote: > Ok, but I still don't see why these arguments shouldn't simply be silently > ignored >>> import this From drake at ultech.com Fri Dec 15 13:47:29 2006 From: drake at ultech.com (drake at ultech.com) Date: 15 Dec 2006 10:47:29 -0800 Subject: Serial port failure References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> Message-ID: <1166208449.351731.136780@73g2000cwn.googlegroups.com> Rob wrote: > Hi all, > > I am fairly new to python, but not programming and embedded. I am > having an issue which I believe is related to the hardware, triggered > by the software read I am doing in pySerial. I am sending a short > message to a group of embedded boxes daisy chained via the serial port. > When I send a 'global' message, all the connected units should reply > with their Id and Ack in this format '0 Ack' To be certain that I > didn't miss a packet, and hence a unit, I do the procedure three times, > sending the message and waiting for a timeout before I run through the > next iteration. Frequently I get through the first two iterations > without a problem, but the third hangs up and crashes, requiring me to > remove the Belkin USB to serial adapter, and then reconnect it. Here > is the code: > > import sys, os > import serial > import sret > import time > > from serial.serialutil import SerialException > #################################################################### > #### GetAck Procedure > #################################################################### > def GetAck(p): > response = "" > > try: > response = p.readline() > except SerialException: > print ">>>>>Timed out<<<<<" > return -1 > res = response.split() > > #look for ack in the return message > reslen = len(response) > if reslen > 5: > if res[1] == 'Ack': > return res[0] > elif res[1] == 'Nak': > return 0x7F > else: > return -1 > > > >>>>> Snip <<<<<< > #################################################################### > #### GetNumLanes Procedure > #################################################################### > def GetNumLanes(Lanes): > print "Looking for connected units" > # give a turn command and wait for responses > msg = ".g t 0 336\n" > > for i in range(3): > port = OpenPort() > time.sleep(3) > print port.isOpen() > print "Request #%d" % (i+1) > try: > port.writelines(msg) > except OSError: > print "Serial port failure. Power cycle units" > port.close() > sys.exit(1) > > done = False > # Run first connection check > #Loop through getting responses until we get a -1 from GetAck > while done == False: > # lane will either be -1 (timeout), 0x7F (Nak), > # or the lane number that responded with an Ack > lane = GetAck(port) > if lane >= '0': > if False == Lanes.has_key(lane): > Lanes[lane] = True > else: > done = True > port.close() > time.sleep(3) > > # Report number of lanes found > NumLanes = len(Lanes) > if NumLanes == 1: > print "\n\nFound 1 unit connected" > else: > print "\n\nFound %d units connected" % NumLanes > > return NumLanes > > > >>>>>> Snip <<<<<< > #################################################################### > #### Main Program Code Section > #################################################################### > > #open the serial port > # capture serial port errors from trying to open the port > > port = OpenPort() > > # If we got to here, the port exists. Set the baud rate and timeout > values > > # I need to determine how many lanes are on this chain > # First send a turn command > > #Create a dictionary of lanes so I can check each lane's responses > Lanes = {} > #<><><><><><><><><><><><><><><><> > # Call the lane finder utility > NumLanes = GetNumLanes(Lanes) > #<><><><><><><><><><><><><><><><> > > #if no lanes responded, exit from the utility > if 0 == NumLanes: > print "I can't find any units connected." > print "Check your connections and try again" > sys.exit(1) > > # list the lanes we have in our dictionary > for n in Lanes: > print "Lane - %s" % n > > Now, here is the error message that I get > > dad at nb29:~/py$ ./Thex.py > Looking for connected units > True > Request #1 > True > Request #2 > Serial port failure. Power cycle units > dad at nb29:~/py$ ./Thex.py > The serial port is unavailable. > Disconnect your USB to Serial adapter, Then > reconnect it and try again. > dad at nb29:~/py$ > > Does anyone have any ideas? > > Thanks, > > rob < Amateur.N7TZG at gmail.com > In the second iteration of your loop, you appear to be opening a port that is already open: for i in range(3): port = OpenPort() thus the error message: "the serial port is unavailable". --Drake Smith From fredrik at pythonware.com Thu Dec 7 03:08:15 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 07 Dec 2006 09:08:15 +0100 Subject: The del statement In-Reply-To: References: Message-ID: Marco Aschwanden wrote: > I am not convinced though that del should also remove elements > from a container/sequence. in today's Python, you can use "del" on all targets that you can assign to. I'm not sure how breaking this consistency would somehow improve things... From sjmachin at lexicon.net Wed Dec 27 05:52:42 2006 From: sjmachin at lexicon.net (John Machin) Date: 27 Dec 2006 02:52:42 -0800 Subject: Fuzzy string comparison In-Reply-To: References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> <1167167314.463288.98960@48g2000cwx.googlegroups.com> Message-ID: <1167216761.936519.118380@n51g2000cwc.googlegroups.com> Duncan Booth wrote: > "John Machin" wrote: > > > To compare two strings, take copies, and: > > Taking a copy of a string seems kind of superfluous in Python. You are right, I really meant don't do: original = original.strip().replace(....).replace(....) (a strange way of doing things which I see occasionally in other folks' code) Cheers, John From jimmyetouma at earthlink.net Tue Dec 12 21:08:59 2006 From: jimmyetouma at earthlink.net (Jimmy E Touma) Date: Wed, 13 Dec 2006 02:08:59 GMT Subject: test Message-ID: <%gJfh.9257$ql2.3050@newsread3.news.pas.earthlink.net> please ignore From ahaas at airmail.net Wed Dec 20 12:01:53 2006 From: ahaas at airmail.net (Art Haas) Date: Wed, 20 Dec 2006 11:01:53 -0600 Subject: [PythonCAD] [ANNOUNCE] Thirty-fifth release of PythonCAD now available In-Reply-To: <20061220163832.GC15224@artsapartment.org> References: <20061220163832.GC15224@artsapartment.org> Message-ID: <20061220170153.GD15224@artsapartment.org> Hi again. In addition to the thirty-fifth release of PythonCAD finally seeing the light of day, the PythonCAD website was given a long overdue makeover. I'd like to thank Jose Antonio Martin for doing the stylesheet and artwork. The new look is an vast improvement from the plain text layout the site has always had. Art Haas -- Man once surrendering his reason, has no remaining guard against absurdities the most monstrous, and like a ship without rudder, is the sport of every wind. -Thomas Jefferson to James Smith, 1822 From http Sat Dec 9 18:03:14 2006 From: http (Paul Rubin) Date: 09 Dec 2006 15:03:14 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <7xac1wr7t9.fsf@ruckus.brouhaha.com> Ken Tilton writes: > yeah, I think it is. Folks don't vary that much. If every Lisp > programmer also reports parens disappearing at about thirty days, any > given non-Lispnik can pretty much bet on the same experience. I think an editing program that balances parens automatically is near indispensible for writing Lisp code. I can't stand writing Lisp without Emacs. > My suspicion goes the other way, and is based not on punctuation, > rather on imperative vs functional. In Lisp every form returns a > value, so I do not have all these local variables around that, in the > strecth of an interesting function, take on a stream of values and > transformations to finally come up with some result, meaning to > understand code I have to jump back and forth thru the code to see the > lineage of a value and figure out its net semantics. Too much like work. Python has been steadily getting better in this regard. From ejatsomewhere.com Thu Dec 28 14:25:57 2006 From: ejatsomewhere.com (Erik Johnson) Date: Thu, 28 Dec 2006 12:25:57 -0700 Subject: dictionary containing instances of classes behaving oddly References: <1167326178.386764.300200@n51g2000cwc.googlegroups.com> <4594102d$1@nntp.zianet.com> <1167333218.447246.236960@h40g2000cwb.googlegroups.com> Message-ID: <45941a6b$1@nntp.zianet.com> "Ben" wrote in message news:1167333218.447246.236960 at h40g2000cwb.googlegroups.com... > class record: > my_list =[] > mops=[] > > def __init__(self,mops): > self.mops=mops Similar to the example I gave, the lists my_list and mops shown above are executed just once: when your class definition is first parsed. The statement: def __init__(self,mops): is also executed just once, and the value for mops at that time is the value assigned to object attributes during object construction - a reference to record.mops, in your case. So, there are really only two lists here, class attributes record.my_list and record.mops. Each of your constructed objects is assigned a reference to record.mops. They all share that list. If you want a record object to have it's own list, give it a new, empty one and then populate it appropriately. From steve at REMOVE.THIS.cybersource.com.au Sat Dec 16 07:32:03 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 16 Dec 2006 23:32:03 +1100 Subject: catching exceptions References: <1166270092.297610.19890@n67g2000cwd.googlegroups.com> Message-ID: On Sat, 16 Dec 2006 03:54:52 -0800, jm.suresh at no.spam.gmail.com wrote: > Hi, In the following program, I have a class Test which has a property > x. Its setx function gets a string value and converts it into a float > and stores into it. [snip code] Python isn't Java. Are you sure you need properties? > I am looking for a way to call func1's exception handler also. > Basically I want to have the class's error handler as the basic text > based one, and in the calling side, If I have gui, I will pop-up a > window and say the error message. > One solution is to remove the exception handling inside the class and > leave the entire thing to the caller (software people call this > client?) side -- if the caller has access to gui it will use gui or > else will print the message. Any other way? The exception is consumed by the try...except block inside the class, so func1 never sees the exception. It might as well not exist. Generally, you should keep your class as simple as possible. It shouldn't try to manage any exception it can't recover from. In your case, the class can't recover from a failure of float(strvalue), so it shouldn't consume the exception. Two ways of doing that: def _setx(self, strvalue): self._x = float(strvalue) # just let the exception propagate or def _setx(self, strvalue): try: self._x = float(strvalue) except ValueError: raise SomeError('could not set x attribute to %s' % strvalue) where SomeError should be either ValueError or possibly some custom exception (say, MyClassException). In either case, the error handling is separate from the object that generates the error. And that is as it should be. Now your class can remain the same, no matter how the rest of your program handles the exception. By the way, if you want your class to generate warnings, perhaps you should investigate the Warnings module: import warnings help(warnings) -- Steven. From deets at nospam.web.de Wed Dec 6 18:04:01 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 07 Dec 2006 00:04:01 +0100 Subject: Module Indexing In-Reply-To: <1165445933.933648.286730@j44g2000cwa.googlegroups.com> References: <1165445933.933648.286730@j44g2000cwa.googlegroups.com> Message-ID: <4tp0j0F14t555U1@mid.uni-berlin.de> JKPeck schrieb: > We are interested in building a module index for our libraries similar > to the global module index on the Python site. Is there a tool/script > available that builds something similar to that automatically? We > would probably want the result to be an html document. Several, e.g. epydoc Diez From vedran at v-programs.com Sun Dec 10 11:52:40 2006 From: vedran at v-programs.com (Croteam) Date: 10 Dec 2006 08:52:40 -0800 Subject: TreeWidget and ftputil question Message-ID: <1165769560.303383.128410@73g2000cwn.googlegroups.com> Hello, I trying to make a ftp software,and I have one question about it. After user connect to his ftp account, command e.g. ftp._dir('') must insert folder and files (from that ftp host) in Listbox widget and that files in listbox must look like (look example) : C:\Python24\Lib\site-packages\idlelib\ObjectBrowser.py How to I create that?? If anybody have any idea please tell me I will really appreciate that Thanks!!! From tundra at tundraware.com Fri Dec 15 12:04:29 2006 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 15 Dec 2006 11:04:29 -0600 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> Message-ID: <061b54-1c21.ln1@eskimo.tundraware.com> Tim Golden wrote: > [Tim Daneliuk] >> I have a program wherein I want one behavior when a file is >> set as executable and a different behavior if it is not. Is >> there a simple way to determine whether a given named file is >> executable that does not resort to all the lowlevel ugliness >> of os.stat() AND that is portable across Win32 and *nix? > > I'm fairly certain the answer is no. What follows is a > relatively low-level and certainly not portable discussion. > > The last couple of times this question came up on the list > I looked into the implementation and experimented a bit > but in short I would say that os.stat / os.access were > near enough useless for determining executablility under > Windows. That's not down to Python as such; it's simply > passing back what the crt offers. > > Of course that raises the slightly wider issue of: should > the Python libs do more than simply call the underlying > crt especially when that's known to give, perhaps misleading > results? But I'm in no position to answer that. > > I suggest that for Windows, you either use the PATHEXT > env var and determine whether a given file ends with > one of its components. Or -- and this depends on your > definition of executable under Windows -- use the > FindExecutable win32 API call (exposed in the win32api > module of pywin32 and available via ctypes) which will > return the "executable" for anything which has an > association defined. So the "executable" for a Word > doc is the winword.exe program. The "executable" for > an .exe is itself. > > TJG > This seems to work, at least approximately: os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH It probably does not catch every single instance of something that could be considered "executable" because this is a sort of fluid thing in Windows (as you point out). -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From tim at tdw.net Fri Dec 15 13:12:03 2006 From: tim at tdw.net (Tim Williams) Date: Fri, 15 Dec 2006 18:12:03 +0000 Subject: parsing a dictionary from a string In-Reply-To: References: Message-ID: <9afea2ac0612151012v49f4ca7fl280443a37196d2cd@mail.gmail.com> On 15/12/06, Benjamin Georgi wrote: > Hello list, > > I could use some help extracting the keys/values of a list of > dictionaries from a string that is just the str() representation of the > list (the problem is related to some flat file format I'm using for file > IO). > > Example: > >>> s = str(dict_list) > >>> s > '[{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}]' > > Then, what I want to do is to reconstruct dict_list given s. > Now, one possible solution would be > > >>> dict_list = eval(s) > > but since the content of s cannot be blindly trusted I`d rather not do > it that way. Basically my question is whether there is another solution > which is simpler than using regular expressions. I'm sure I'll get flamed for the following !! LOL You could check that the string contains at least part of what you are expecting. if s[0] == '[' : dict_list = eval(s) or if s[:2] == '[{' : dict_list = eval(s) if s[:2] == '[{' and s[-2:] == '}]' : dict_list = eval(s) etc I doubt it is perfect, but it is quick and simple and much safer than a straight eval() *or* try: dict_list = [eval(x+'}') for x in s.replace('[{','{').replace('}]','').split('},')] except: print "file may be compromised" From aine_canby at yahoo.com Wed Dec 6 07:09:36 2006 From: aine_canby at yahoo.com (aine_canby at yahoo.com) Date: 6 Dec 2006 04:09:36 -0800 Subject: reloading modules Message-ID: <1165406976.641077.45350@f1g2000cwa.googlegroups.com> I'm using python.exe to execute my modules. I have a music.py module which contains my classes and a main.py module which uses these classes. In python.exe, I call "import main" to execute my program. The problem is that I have to close python and reopen it everytime i change music.py or main.py. What should I be doing. Thanks, Aine. From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 02:44:56 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 09 Dec 2006 18:44:56 +1100 Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> <1165518199.729518.112450@79g2000cws.googlegroups.com> Message-ID: On Fri, 08 Dec 2006 17:42:56 +0100, Daniel Dittmar wrote: > Marc 'BlackJack' Rintsch wrote: >> If ``in`` shouldn't work with dictionaries, either `__contains__()` must >> be implemented to throw an exception or dictionaries shouldn't be iterable. > > I agree completely (in the sense that dictionaries shouldn't be iterable > directly). Why on earth not??? > Probably even more strongly, at least every time I see some > code where someone iterates over the keys, only to use the key to look > up the value (instead if using iteritms). Is there really that much difference between the two? >>> D = dict(zip(xrange(10000), xrange(10000))) >>> def d1(D): ... for key in D: ... value = D[key] ... >>> def d2(D): ... for key, value in D.iteritems(): ... pass ... >>> timeit.Timer("d1(D)", "from __main__ import d1, d2, D").timeit(1000) 5.9806718826293945 >>> timeit.Timer("d2(D)", "from __main__ import d1, d2, D").timeit(1000) 4.7772250175476074 Using iteritems is slightly faster, and probably more Pythonic, but the difference isn't so great to argue that "for key in dict" is always the wrong thing to do. One could argue until the cows come home whether "for x in dict" should iterate over keys, values or key/value pairs, but it really doesn't matter. All three possibilities are available, all three values are useful, and having to copy the keys/values into a list in order to iterate over them is just wasteful. -- Steven. From steve at REMOVEME.cybersource.com.au Thu Dec 21 00:48:24 2006 From: steve at REMOVEME.cybersource.com.au (Steven D'Aprano) Date: Thu, 21 Dec 2006 16:48:24 +1100 Subject: list1.append(list2) returns None References: <87mz5hexf7.fsf@pyenos.pyenos.org> Message-ID: On Thu, 21 Dec 2006 16:29:01 +1100, Ben Finney wrote: > Pyenos writes: > >> def enlargetable(table,col): >> return table.append(col) >> >> def removecolfromtable(table,col): >> return table.remove(col) >> >> print enlargetable([[1],[2],[3]],[4]) # returns None >> >> Why does it return None instead of [[1],[2],[3],[4]] which I expected? > > The answer is both "because that's what it's documented to do": Documentation is a funny thing... help([].append) Help on built-in function append: append(...) L.append(object) -- append object to end Sometimes it is hard to tell when you've read enough documentation. However, as a general rule, "None whatsoever" is rarely enough. -- Steven From inq1ltd at verizon.net Sat Dec 2 12:24:15 2006 From: inq1ltd at verizon.net (jim-on-linux) Date: Sat, 02 Dec 2006 12:24:15 -0500 Subject: Python, PostgreSQL, What next? In-Reply-To: References: <1165043076.979652.201730@16g2000cwy.googlegroups.com> Message-ID: <200612021224.16020.inq1ltd@verizon.net> Before commiting to a RDBMS take a look at Gadfly. Depending on what you need a RDB for, (light duty), or (heavy duty) take a look at gadfly. Gadfly is made from all python code. Use stardard SQL statements like Select, Create and Drop Tables, etc. Newest version GadflyB5 http://gadfly.sourceforge.net/ jim-on-linux http://www.inqvista.com On Saturday 02 December 2006 11:33, Thomas Bartkus wrote: > On Fri, 01 Dec 2006 23:04:37 -0800, vbgunz wrote: > > Hello all, > > > > I've studied Python and studied PostgreSQL. > > What is the absolute next best step to take > > to merge these two finely together? I've > > heard of SQLAlchemy and some others but > > before I dive in, I would really like the > > opinion of those who tried it and other > > toolkits. > > > > My main concern is, I would like to > > completely work with a database from Python. > > What would you suggest I look into? > > Let me venture that the biggest problem most > people seem to have is that they endure great > pain just to avoid learning SQL. SQL is a > complete programming language in and of itself > with a breadth and depth that most people miss. > And it covers much terrain missed by Python. > Which is a good thing because SQL and Python > are perfect together. With this language mix > you've got darn near everything licked. > > Get SQL in your head and all you will need > would be the db-api interface with Postgres > that Frederick Lundh pointed you to. All you > want to do is throw SQL commands at Postgres > and recover result sets into Python. > > It's a cinch. > Thomas Bartkus From address.good.until.2006.dec.22 at justmail.de Mon Dec 11 09:04:17 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Mon, 11 Dec 2006 15:04:17 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> Message-ID: Steven D'Aprano schrieb: > With Lisp macros, even that isn't guaranteed. Now, if Lispers would say > "Oh yes, macros give you great power, and with great power comes great > responsibility. Be careful." Well, macros are one (big) thing that Lisp has and which many other languages don't have. Their are other things too, and some of them are in Python as well, which is a very nice scripting language. Often macros save just some bits of code. Saving one loc is not much you might say. But think about it the other way around. How would you like it to call doodleShooble() each time before you use the if statement? Of course you would not like it. The good thing about Lisp is, that you can eliminate this pattern. Apropos pattern.. most design patterns are not (very) visible in Lisp. Many of them can be abstracted away with macros+functional programming. Andr? -- From gagsl-py at yahoo.com.ar Wed Dec 13 19:35:32 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Wed, 13 Dec 2006 21:35:32 -0300 Subject: Password, trust and user notification In-Reply-To: <1166053509.270409.46390@f1g2000cwa.googlegroups.com> References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> <1165917102.008439.146400@16g2000cwy.googlegroups.com> <1166053509.270409.46390@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061213210006.04005d80@yahoo.com.ar> At Wednesday 13/12/2006 20:45, placid wrote: > > You DON'T need the password for the receiving account just to send him > > an email! > > And you don't even need that special Gmail library, smtplib should be > > fine. > >Yes you dont need a password to receive email, but to access Gmail and >send an email you do. Yes you do need the Gmail library to access Gmail >because the script will run on a computer that doesnt have a smtp >server. > >Is there other way's of notifying the user? Use the standard SMTP class to connect to the destination SMTP server. To determine the right server, issue a DNS request for MX records on the destination domain. (You may have to search for any suitable DNS module since none is available in the standard Python distribution). If you are really too lazy and you *know* the destination will *always* be a gmail account and you don't bother if things go wrong tomorrow, these are some current MX records for gmail.com: - Name=gmail.com Preference=5, Mail Exchange=gmail-smtp-in.l.google.com Preference=10, Mail Exchange=alt1.gmail-smtp-in.l.google.com Preference=10, Mail Exchange=alt2.gmail-smtp-in.l.google.com Preference=50, Mail Exchange=gsmtp163.google.com Preference=50, Mail Exchange=gsmtp183.google.com -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From address.good.until.2006.dec.22 at justmail.de Fri Dec 15 09:16:16 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=) Date: Fri, 15 Dec 2006 15:16:16 +0100 Subject: merits of Lisp vs Python In-Reply-To: <4ufemoF17of60U3@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> Message-ID: greg schrieb: > Ken Tilton wrote: > >> The reason I post macro expansions along with examples of the macro >> being applied is so that one can see what code would have to be >> written if I did not have the defskill macro to "write" them for me. > > It seems to me your brain is somewhat stuck on the use of macros. That you see it this way is normal. A BASIC programmer would tell you the same thing. He can show you solutions that don't use classes, methods or functions. Some sweet gotos and gosubs are enough. The idea is that macros save you tokens and allow you to experess in a clearer way what you want to do. But in no case one "needs" them to solve a programming problem. All what Kenny showed could be done without his macro. It would just be a bit more complicated and the resulting code wouldn't look good. > You're looking at the expansion of your > macro and assuming that you'd have to write all that > code by hand if you didn't have macros. You're not > thinking about alternative approaches, which could > just as well be used in Lisp as well as Python, that > are just as compact yet don't make use of macros. He wouldn't have to write the full expansion. With functional programming he could also solve it, but then he would need a funcall here, a lambda there. And his code would not look so understandable anymore, because it is filled up with some low level details. I will take one of the first macro examples form "On Lisp". Let's say for some reason you want to analyse some numbers and do something depending on their sign. We want a function "numeric if": def nif(num, pos, zero, neg): if num > 0: return pos else: if num == 0: return zero else: return neg In Lisp very similar: (defun nif (num pos zero neg) (case (truncate (signum num)) (1 pos) (0 zero) (-1 neg))) Now one example Graham gives is: (mapcar #'(lambda (x) (nif x 'p 'z 'n)) '(0 2.5 -8)) which results in the list (Z P N). You can do the same thing in Python. But it gets hairier if we want to make function calls that have side effects. Let me add these three functions: (defun p () (print "very positive") "positive") (defun z () (print "no no") "zero") (defun n () (print "very negative") "negative") And now see what happens: CL-USER> (mapcar #'(lambda (x) (nif x (p) (z) (n))) '(0 2.5 -8)) "very positive" "no no" "very negative" "very positive" "no no" "very negative" "very positive" "no no" "very negative" ("zero" "positive" "negative") The messages were printed in each case. To stop that I need lazy evaluation: CL-USER> (mapcar #'(lambda (x) (funcall (nif x #'(lambda () (p)) #'(lambda () (z)) #'(lambda () (n))))) '(0 2.5 -8)) "no no" "very positive" "very negative" ("zero" "positive" "negative") I put the calls to the functions p, z and n into a function object. In some languages it would look a bit cleaner, for example Ruby. They have a single name space and don't need funcall and lambda is shorter. But still, we need to add several tokens. Maybe Haskell has built in support for that. Now with nif as a macro: (defmacro nif (expr pos zero neg) `(case (truncate (signum ,expr)) (1 ,pos) (0 ,zero) (-1 ,neg))) It is a bit more complex as the function. It has one ` and 4 ,s extra. But now we can express the problem very well: CL-USER> (mapcar #'(lambda (x) (nif x (p) (z) (n))) '(0 2.5 -8)) "no no" "very positive" "very negative" ("zero" "positive" "negative") And the first example also still works the same way. Now the expansion shows more code than we would have need to write ourself. However, now we can write code that matches much better how we think. No need for "low level" details like embedding the code inside of anon functions. This represents what most macros do. Save one or more lambdas and/or funcalls. One consequence is that development time gets cut down. Andr? -- From howardrh at westerncom.net Wed Dec 6 23:26:42 2006 From: howardrh at westerncom.net (hrh1818) Date: 6 Dec 2006 20:26:42 -0800 Subject: Windows installer for Scientific Python for Python 2.4? References: <12nehgaak7mte4@corp.supernews.com> <1165449476.969662.218990@n67g2000cwd.googlegroups.com> Message-ID: <1165465602.600021.86450@80g2000cwy.googlegroups.com> How right you are. Thanks for the correctikon, Howard Robert Kern wrote: > hrh1818 wrote: > > How did you come to your conclusion? The scipy page at > > http://www.scipy.org/Download shows the following: > > "Install SciPy 0.5.1 for Python 2.4 or SciPy 0.5.1 for Python 2.3" > > ScientificPython != scipy > > http://dirac.cnrs-orleans.fr/ScientificPython/ > http://sourcesup.cru.fr/projects/scientific-py/ > > -- > 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 From ihatespam at hotmail.com Tue Dec 5 22:25:10 2006 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Wed, 06 Dec 2006 03:25:10 GMT Subject: Looking for a decent HTML parser for Python... Message-ID: I'm trying to parse HTML in a very generic way. So far, I'm using SGMLParser in the sgmllib module. The problem is that it forces you to parse very specific tags through object methods like start_a(), start_p() and the like, forcing you to know exactly which tags you want to handle. I want to be able to handle the start tags of any and all tags, like how one would do in the Xerces C++ XML parser. In other words, I would like a simple start() method that is called whenever any tag is encountered. How may I do this? Thank you... From mail at microcorp.co.za Sat Dec 9 03:31:29 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 9 Dec 2006 10:31:29 +0200 Subject: Snake references just as ok as Monty Python jokes/references inpython community? :) References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> <1165611937.587808.91890@j72g2000cwa.googlegroups.com> Message-ID: <030901c71b72$3265c2e0$03000080@hendrik> "John Machin" wrote: > Ah yes, exposure to Blackadder helps enormously ... after some hours > spent trying to understand things like metaclasses, it's helpful to > know what to do: put a pencil or chopstick up each nostril, wear your > underpants on your head, and sit there muttering "wibble wibble" until > they come to take you away. Alternatively, you are allowed to sing Flanders and Swan's "Happy Song", in order to achieve the same end. - Hendrik From python at hope.cz Wed Dec 27 10:01:56 2006 From: python at hope.cz (Lad) Date: 27 Dec 2006 07:01:56 -0800 Subject: Mod_python In-Reply-To: <1167212317.836419.162730@42g2000cwt.googlegroups.com> References: <1167161288.802707.64220@h40g2000cwb.googlegroups.com> <1167212317.836419.162730@42g2000cwt.googlegroups.com> Message-ID: <1167231716.145292.293930@73g2000cwn.googlegroups.com> Maxim Sloyko wrote: > Lad wrote: > > In my web application I use Apache and mod_python. > > I allow users to upload huge files( via HTTP FORM , using POST method) > > I would like to store the file directly on a hard disk and not to > > upload the WHOLE huge file into server's memory first. > > Can anyone suggest a solution? > > The only solution you need is Apache and mod_python :) > I mean, Apache won't load a huge POST request into its memory no > matter what. All file uploads will be stored in temporary files. Under > mod_python (provided you use FieldStorage) you'll need to deal only > with 'file' objects. Maxim , Thank you for your reply. Here is an example: If a user uploads 100MB file , what will be a consumption of memory, when the upload is complete? Or does it mean that Apache will read a part of a file , store it in a temporary file, then read another part and adds this part to the temporary file and so on until the whole uploaded file is read? Thank you for the reply. Lad From tjreedy at udel.edu Thu Dec 14 00:22:40 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Dec 2006 00:22:40 -0500 Subject: job posting: Sr Systems Programmer needed References: <1166069696.859817.18450@73g2000cwn.googlegroups.com> Message-ID: wrote in message news:1166069696.859817.18450 at 73g2000cwn.googlegroups.com... > View the Job Descriptions: www.myspace.com/agcocorp I did and it has nothing to do with Python. So in the context of this newgroup, this announcement is spam. Please desist in the future. If everyone else with an unreleated programmer job posted here, the newsgroup would become useless. tjr From robert.kern at gmail.com Sun Dec 17 17:42:48 2006 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 17 Dec 2006 16:42:48 -0600 Subject: first and last index as in matlab In-Reply-To: <1166393830.272016.160560@t46g2000cwa.googlegroups.com> References: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> <1166393830.272016.160560@t46g2000cwa.googlegroups.com> Message-ID: Beliavsky wrote: > Evan wrote: >> In matlab I can do the following: >> >>>> ind = [3,5,7,2,4,7,8,24] >> ind = 3 5 7 2 4 7 8 24 >>>> ind(1) ans = 3 >>>> ind(end) ans = 24 >>>> ind([1 end]) ans = 3 24 >> but I can't get the last line in python: >> >> In [690]: ind = [3,5,7,2,4,7,8,24] >> In [691]: ind[0] Out[691]: 3 >> In [692]: ind[-1:] Out[692]: [24] >> In [693]: ?? >> >> How do I pull out multiple indices as in matlab? > > If you want functionality similar to Matlab in Python, you should use > Numpy, which has the "take" function to do what you want. Actually, in numpy, we also have "fancy indexing" similar to Matlab's: In [1]: from numpy import * In [2]: ind = array([3,5,7,2,4,7,8,24]) In [3]: ind[[0, -1]] Out[3]: array([ 3, 24]) -- 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 From http Thu Dec 14 16:19:01 2006 From: http (Paul Rubin) Date: 14 Dec 2006 13:19:01 -0800 Subject: CLPython (was Re: merits of Lisp vs Python) References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <7xejr5y755.fsf@ruckus.brouhaha.com> <1166038096.200379.286830@80g2000cwy.googlegroups.com> <1166048301.513012.245480@73g2000cwn.googlegroups.com> <1166122900.477201.316320@73g2000cwn.googlegroups.com> Message-ID: <7xr6v2i3ay.fsf@ruckus.brouhaha.com> "Willem Broekema" writes: > I guess in part it's because there are not that many people really into > both Python and Lisp, and those who are might not find this an > interesting project because there is nothing "wow" to show, yet. I thought it was of some interest though I'm a little surprise by the choice of CL rather than Scheme as a target. I'm still not sure about the mapping of Python strings to Lisp strings. What happens with the following in CLPython? a = 'hello' a[0] = 'H' # attempt to change first letter to upper case From deets at nospam.web.de Mon Dec 11 15:50:35 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 11 Dec 2006 21:50:35 +0100 Subject: Python Operating System In-Reply-To: <457cc95e$0$16553$afc38c87@news.optusnet.com.au> References: <1165790496.985266.221160@f1g2000cwa.googlegroups.com> <4u3jutF15ru88U1@mid.uni-berlin.de> <457cc95e$0$16553$afc38c87@news.optusnet.com.au> Message-ID: <4u5ukrF16tp0kU1@mid.uni-berlin.de> Richard Jones schrieb: > Diez B. Roggisch wrote: >> Python has no notion of pointers > > See: > > http://docs.python.org/lib/module-ctypes.html > > In particular: > > http://docs.python.org/lib/ctypes-pointers.html Certainly cool, yet not too helpful for writing an interrupt handler that needs to run lightning fast & without prior GIL acquisition. Also PyPy with RPython might someday add much to the low-level programming capabilities, but a pure Python OS isn't feasible IMHO right now. Diez From siona at chiark.greenend.org.uk Wed Dec 20 12:26:13 2006 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 20 Dec 2006 17:26:13 +0000 (GMT) Subject: Fall of Roman Empire References: <20061220054657.7CEEA1E4006@bag.python.org> <1166595864.797404.260570@n67g2000cwd.googlegroups.com> Message-ID: Ben Finney wrote: >"John Machin" writes: >> Ben Finney wrote: >> > \ "...one of the main causes of the fall of the Roman Empire was | >> > `\ that, lacking zero, they had no way to indicate successful | >> > _o__) termination of their C programs." -- Robert Firth | >> [ ... ] in many cases successful >> termination of their C programs would have been unlikely. >Yet historically proven: the 'imperium' process they were running >terminated many centuries ago. > >Or did it fork and exec a different process? Pretty much. Except they would argue that the child process (Byzantium) never exec'd. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From anthra.norell at vtxmail.ch Sun Dec 17 09:35:05 2006 From: anthra.norell at vtxmail.ch (Frederic Rentsch) Date: Sun, 17 Dec 2006 15:35:05 +0100 Subject: textwrap.dedent replaces tabs? In-Reply-To: References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> Message-ID: <45855599.9070201@vtxmail.ch> Tom Plunket wrote: > CakeProphet wrote: > > >> Hmmm... a quick fix might be to temporarily replace all tab characters >> with another, relatively unused control character. >> >> MyString = MyString.replace("\t", chr(1)) >> MyString = textwrap.dedent(MyString) >> MyString = MyString.replace(chr(1), "\t") >> >> Of course... this isn't exactly safe, but it's not going to be fatal, >> if it does mess something up. As long as you don't expect receiving any >> ASCII 1 characters. >> > > Well, there is that small problem that there are leading tabs that I > want stripped. I guess I could manually replace all tabs with eight > spaces (as opposed to 'correct' tab stops), and then replace them when > done, but it's probably just as easy to write a non-destructive dedent. > > It's not that I don't understand /why/ it does it; indeed I'm sure it > does this so you can mix tabs and spaces in Python source. Why anyone > would intentionally do that, though, I'm not sure. ;) > > -tom! > > This should do the trick: >>> Dedent = re.compile ('^\s+') >>> for line in lines: print Dedent.sub ('', line) Frederic ----------------------------------------------------------------------- Testing: >>> text = s = ''' # Dedent demo No indent Three space indent \tOne tab indent \t\tThree space, two tab indent \t \tOne tab, two space, one tab indent with two tabs here >\t\t<''' >>> print text print s # Dedent demo No indent Three space indent One tab indent Three space - two tab indent One tab - two spaces - one tab indent with two tabs here > < >>> for line in text.splitlines (): print Dedent.sub ('', line) # Dedent demo No indent Three space indent One tab indent Three space - two tab indent One tab - two spaces - one tab indent with two tabs here > < ----------------------------------------------------------------------- From simone.leo at gmail.com Fri Dec 15 05:09:03 2006 From: simone.leo at gmail.com (Tekkaman) Date: 15 Dec 2006 02:09:03 -0800 Subject: Logging module: problem with some mapping keys In-Reply-To: References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166106298.176199.301190@f1g2000cwa.googlegroups.com> <1166113691.753244.189350@f1g2000cwa.googlegroups.com> <1166115714.082561.87420@t46g2000cwa.googlegroups.com> Message-ID: <1166177343.040931.91100@n67g2000cwd.googlegroups.com> On Dec 14, 6:41 pm, Peter Otten <__pete... at web.de> wrote: > Tekkaman wrote: >> lib is a symlink to lib64 > So my initial diagnosis was correct. Unfortunately I can no longer recommend > that you remove the symlink... > Yes. What I really meant in my first reply was "it's not a symlink in the script's own directory": I didn't suspect that a symlink at any level in the path between the script and the logging module would break findCaller(). > Putting /usr/lib64/python2.4 as the first entry into your > > PYTHONPATH > > environment variable might fix the problem (the idea is > that /usr/lib64/python2.4 precedes /usr/lib/python2.4 in sys.path and is > therefore used for the import of the logging package). > Thanks, I'll check it out. Anyway, since this is a hack, you think this behaviour should be reported as a bug? > Peter T. From fredrik at pythonware.com Fri Dec 8 12:02:42 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 08 Dec 2006 18:02:42 +0100 Subject: Common Python Idioms In-Reply-To: References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> <1165518199.729518.112450@79g2000cws.googlegroups.com> Message-ID: Daniel Dittmar wrote: > I agree completely (in the sense that dictionaries shouldn't be iterable > directly). Probably even more strongly, at least every time I see some > code where someone iterates over the keys, only to use the key to look > up the value (instead if using iteritms). so? that's the original Python way of doing things, and is both very readable and surprisingly efficient: $ timeit -s "d = vars()" "for k in d: v = d[k]" 1000000 loops, best of 3: 0.472 usec per loop $ timeit -s "d = vars()" "for k, v in d.iteritems(): pass" 1000000 loops, best of 3: 0.663 usec per loop From eadmund42 at NOSPAMgmail.com Tue Dec 12 22:07:17 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 20:07:17 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> Message-ID: "Stephen Eilert" writes: > > So, let's suppose I now want to learn LISP (I did try, on several > occasions). What I would like to do would be to replace Python and > code GUI applications. Yes, those boring business-like applications > that have to access databases and consume those new-fangled > web-services and whatnot. Heck, maybe even code games using DirectX. GUIs are a weak point, or were last I looked. There are at least three GTK+ interfaces. Database access is handled very nicely with CLSQL, which does OR mapping right. I've not written code to 'consume web-services,' but I daresay that NET.HTML.CLIENT (believe that's the name) would do the trick. -- Robert Uhl If anybody can show me in the Bible the command, 'Thou shalt not smoke,' I am ready to keep it; but I haven't found it yet. I find ten commandments, and it's as much as I can do to keep them; and I've no desire to make them into eleven or twelve. --C. H. Spurgeon From wilson.max at gmail.com Wed Dec 20 14:12:42 2006 From: wilson.max at gmail.com (Max Wilson) Date: 20 Dec 2006 11:12:42 -0800 Subject: Boost Python tutorial needs MSVC? In-Reply-To: <1166641605.308616.58070@n67g2000cwd.googlegroups.com> References: <1166641605.308616.58070@n67g2000cwd.googlegroups.com> Message-ID: <1166641962.542776.272100@f1g2000cwa.googlegroups.com> Cancel that--I found the answer. http://groups.google.com/group/boost-list/browse_frm/thread/5a17077679a33dca/7360f2038d6e6cca?lnk=gst&q=bjam+mingw&rnum=3#7360f2038d6e6cca Short answer: bjam.exe should not be in /bin or /usr/bin because MinGW treats programs in there differently. In my case I simply copied bjam.exe to my working directory, for now. -Max Wilson From nagle at animats.com Sat Dec 16 01:10:22 2006 From: nagle at animats.com (John Nagle) Date: Sat, 16 Dec 2006 06:10:22 GMT Subject: Roundtrip SQL data especially datetime In-Reply-To: References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: dyork wrote: > "John Machin" wrote in message > news:1166211949.065578.292600 at f1g2000cwa.googlegroups.com... > I was looking for a constructor that was the complement of str(). Most/many > languages would provide that. Sometimes it's called parse(). > > >>The constructor is datetime.datetime(year, ....., second) so the >>following (which works all the way back to Python 2.3) seems not too >>obscure to me: > >>If you have, as you should, Python 2.5, you can use this: Actually, MySQLdb isn't released for Python 2.5 yet, so for anything with a database, you need an older version of Python. If you really want to change the conversions for TIMESTAMP, add the "conv" argument to "connect". Make a copy of "MySQLdb.converters.conversions", then replace the key "MySQLdb.FIELD_TYPE.TIMESTAMP", which normally has the value 'mysql_timestamp_converter' with your own converter. You can then get the interface to emit a "datetime" object. Routinely converting MySQL DATETIME objects to Python "datetime" objects isn't really appropriate, because the MySQL objects have a year range from 1000 to 9999, while Python only has the UNIX range of 1970 to 2038. Remember, a database may have DATETIME dates which reflect events in the distant past or future. None of this will help performance; dates and times are sent over the connection to a MySQL database as strings. John Nagle From kbk at shore.net Sat Dec 30 00:41:03 2006 From: kbk at shore.net (Kurt B. Kaiser) Date: Sat, 30 Dec 2006 00:41:03 -0500 (EST) Subject: Weekly Python Patch/Bug Summary Message-ID: <200612300541.kBU5f359027319@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 413 open ( -7) / 3521 closed (+11) / 3934 total ( +4) Bugs : 946 open ( +2) / 6400 closed ( +9) / 7346 total (+11) RFE : 248 open ( -1) / 246 closed ( +1) / 494 total ( +0) New / Reopened Patches ______________________ Auto-completion list placement (2006-12-23) http://python.org/sf/1621265 opened by Tal Einat normalize namespace from minidom (2006-12-23) http://python.org/sf/1621421 opened by Paul Pacheco Allow __class __ assignment for classes with __slots__ (2006-12-28) http://python.org/sf/1623563 opened by TH fast subclasses of builtin types (2006-12-28) http://python.org/sf/1624059 opened by Neal Norwitz Patches Closed ______________ add direct access to MD5 compression function to md5 module (2003-03-16) http://python.org/sf/704676 closed by akuchling pty.fork() compatibility code wrong? (2003-08-04) http://python.org/sf/783050 closed by akuchling for i in range(N) optimization (2003-05-15) http://python.org/sf/738094 closed by gvanrossum Add --remove-source option to setup.py (2003-08-22) http://python.org/sf/793070 closed by akuchling SimpleHTTPServer directory-indexing "bug" fix (2003-10-21) http://python.org/sf/827559 closed by akuchling Remove unncessary NLST from ftp transfers (2004-10-12) http://python.org/sf/1045783 closed by akuchling add Bunch type to collections module (2005-01-02) http://python.org/sf/1094542 closed by akuchling HMAC hexdigest and general review (2005-04-13) http://python.org/sf/1182394 closed by akuchling tarfile.py: ExFileObject\'s tell() is wrong after readline() (2005-06-30) http://python.org/sf/1230446 closed by gustaebel tarfile: fix for bug #1257255 (2005-08-17) http://python.org/sf/1262036 closed by gustaebel Patch for 1496501 tarfile opener order (2006-06-10) http://python.org/sf/1504073 closed by gustaebel New / Reopened Bugs ___________________ minor inconsistency in socket.close (2006-12-22) http://python.org/sf/1620945 opened by Jonathan Ellis IDLE crashes on OS X 10.4 when "Preferences" selected (2006-12-23) http://python.org/sf/1621111 opened by Mick L random import works? (2006-12-23) CLOSED http://python.org/sf/1621367 opened by Msword this module (Zen of Python) docs list broken URL (2006-12-24) http://python.org/sf/1621660 opened by Calvin Spealman Tcl/Tk auto-expanding window (2006-12-25) http://python.org/sf/1622010 opened by Fabian_M null bytes in docstrings (2006-12-26) http://python.org/sf/1622533 opened by Fredrik Lundh language reference index links are broken (2006-12-26) http://python.org/sf/1622664 opened by Drew Perttula Exception when compressing certain data with bz2 (2006-12-27) http://python.org/sf/1622896 opened by Alex Gontmakher preferred diff format should be mentioned as "unified". (2006-12-27) http://python.org/sf/1623153 opened by Raghuram Devarakonda module docstring for subprocess is wrong (2006-12-28) CLOSED http://python.org/sf/1623890 opened by Neal Norwitz updating a set in a list of sets will update all of them (2006-12-29) CLOSED http://python.org/sf/1624534 opened by Amir Reza Khosroshahi webbrowser.open_new() suggestion (2006-12-30) http://python.org/sf/1624674 opened by Imre P?ntek Bugs Closed ___________ gethostbyaddr lag (2002-07-19) http://python.org/sf/583975 closed by nnorwitz CGIHTTPServer does not handle scripts in sub-dirs (2003-05-13) http://python.org/sf/737202 closed by akuchling MacOS9: test_uu fails (2003-07-23) http://python.org/sf/776202 closed by akuchling Mode argument of dumbdbm does not work (2003-09-07) http://python.org/sf/802128 closed by akuchling random import works? (2006-12-23) http://python.org/sf/1621367 closed by rhettinger tarfile local name is local, should be abspath (2005-08-12) http://python.org/sf/1257255 closed by gustaebel Dictionary ordering docs are too unclear of dangers (2006-12-09) http://python.org/sf/1612113 closed by sf-robot logging %(module)s reporting wrong modules (2006-11-29) http://python.org/sf/1605110 closed by sf-robot array.array borks on deepcopy (2006-08-24) http://python.org/sf/1545837 closed by twouters tarfile.py: dict order dependency (2006-05-28) http://python.org/sf/1496501 closed by gustaebel module docstring for subprocess is wrong (2006-12-28) http://python.org/sf/1623890 closed by nnorwitz updating a set in a list of sets will update all of them (2006-12-29) http://python.org/sf/1624534 deleted by amir_reza Immediate Crash on Open (2006-11-20) http://python.org/sf/1599931 closed by sf-robot python-logging compatability with Zope. (2006-12-12) http://python.org/sf/1614460 closed by sf-robot RFE Closed __________ Promote list comprehensions to Language Integrated Query? (2006-12-19) http://python.org/sf/1618676 closed by jettlogic From Bulkan at gmail.com Wed Dec 13 18:45:09 2006 From: Bulkan at gmail.com (placid) Date: 13 Dec 2006 15:45:09 -0800 Subject: Password, trust and user notification In-Reply-To: <1165917102.008439.146400@16g2000cwy.googlegroups.com> References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> <1165917102.008439.146400@16g2000cwy.googlegroups.com> Message-ID: <1166053509.270409.46390@f1g2000cwa.googlegroups.com> Gabriel Genellina wrote: > You DON'T need the password for the receiving account just to send him > an email! > And you don't even need that special Gmail library, smtplib should be > fine. Yes you dont need a password to receive email, but to access Gmail and send an email you do. Yes you do need the Gmail library to access Gmail because the script will run on a computer that doesnt have a smtp server. Is there other way's of notifying the user? Cheers From scott.daniels at acm.org Tue Dec 19 00:16:45 2006 From: scott.daniels at acm.org (Scott David Daniels) Date: Mon, 18 Dec 2006 21:16:45 -0800 Subject: catching exceptions In-Reply-To: <1166270092.297610.19890@n67g2000cwd.googlegroups.com> References: <1166270092.297610.19890@n67g2000cwd.googlegroups.com> Message-ID: <45876baf$1@nntp0.pdx.net> jm.suresh at no.spam.gmail.com wrote: > > class Test(object): > ... > def _setx(self,strvalue): > try: > self._x = float(strvalue) > except ValueError: > print 'Warning : could not set x attribute to %s' % strvalue > ... I think what you are looking for is: class Test(object): ... def _setx(self, strvalue): try: self._x = float(strvalue) except ValueError: print 'Warning : could not set x attribute to %s' % ( strvalue) raise # re-raise the exception that got us here. ... --Scott David Daniels scott.daniels at acm.org From kentilton at gmail.com Sat Dec 9 18:46:00 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 18:46:00 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7xac1wr7t9.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <7xac1wr7t9.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Ken Tilton writes: > >>yeah, I think it is. Folks don't vary that much. If every Lisp >>programmer also reports parens disappearing at about thirty days, any >>given non-Lispnik can pretty much bet on the same experience. > > > I think an editing program that balances parens automatically is near > indispensible for writing Lisp code. I would say indispensible full stop. > I can't stand writing Lisp > without Emacs. Emacs or an Emacs-like editor (or at least Lisp-ware editor) provided by the Lisp environment. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From maxerickson at gmail.com Sun Dec 10 20:09:07 2006 From: maxerickson at gmail.com (Max Erickson) Date: Mon, 11 Dec 2006 01:09:07 +0000 (UTC) Subject: Barry Warsaw Python Webcast at GSFC References: <87fybncmp3.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > William Allison writes: > >> http://isandtcolloq.gsfc.nasa.gov/webcasts.html >> It's at the bottom of the page. > > In WMV format, and thus not viewable with free software :-( > Um, http://www.videolan.org/vlc/features.html Or any other ffmpeg based player for that matter. There is a chance that it is encoded in a wmv format which ffmpeg won't deal with(newer ones), but not a very big one considering that the nasa site lists Windows Media Player 4.0 as a minimum requirement, and that isn't, shall we say, modern. max From chris.cavalaria at free.fr Wed Dec 13 05:52:46 2006 From: chris.cavalaria at free.fr (Christophe) Date: Wed, 13 Dec 2006 11:52:46 +0100 Subject: merits of Lisp vs Python In-Reply-To: <87lklcrt00.fsf@thalassa.informatimago.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> <87lklcrt00.fsf@thalassa.informatimago.com> Message-ID: <457fdb92$0$13245$426a74cc@news.free.fr> Pascal Bourguignon a ?crit : > Christophe writes: > >> Robert Uhl a ?crit : >>> aahz at pythoncraft.com (Aahz) writes: >>>> Consider this: Lisp has had years of development, it has had millions of >>>> dollars thrown at it by VC firms -- and yet Python is winning over Lisp >>>> programmers. Think about it. >>> The argument from popularity is invalid. French units have overtaken >>> standard units, >> Never heard of that French unit thing. Unless you talk about that >> archaic unit system that was in use before the metric system was >> created. > > Who invented the metric system? That system is called the metric system, not French units. French units refer to the archaic system used before the metric system was invented ( at least according to google ) So, let's admit that French Units refer to the metric system. I suppose then that the so called "standard" units refer to the imperial system. Saying that the French units are technically worse than standard units is a troll of very poor quality and a very weak argument. From chrisspen at gmail.com Thu Dec 21 15:49:40 2006 From: chrisspen at gmail.com (Chris) Date: 21 Dec 2006 12:49:40 -0800 Subject: Decorator for Enforcing Argument Types Message-ID: <1166734180.455471.164910@79g2000cws.googlegroups.com> I'm not sure if this has been done before, but I couldn't easily find any prior work on Google, so here I present a simple decorator for documenting and verifying the type of function arguments. Feedback/suggestions/criticism is welcome. ''' 2006.12.21 Created. ''' import unittest import inspect def arguments(*args): '''A simple decorator for formally documenting and verifying argument types. usage: @arguments(type1, type2, [type3.1, type3.2, ..., type3.N], type4, ..., typeN) def somefunc(arg1, arg2, arg3, arg4, ..., argN): do stuff return ''' return lambda f:_Arguments(f, *args) class _Arguments(object): # todo: extend to verify Zope interfaces def __init__(self, fn, *args): self.fn = fn # create argument type list self.arguments = [] for arg in args: if not isinstance(arg, list): arg = list([arg]) arg = set(arg) self.arguments.append(arg) # create name-to-index lookup argNames, varArgName, varkwName, defaults = inspect.getargspec(fn) assert len(argNames) == len(self.arguments), 'list of argument types must match the number of arguments' self.argNameToIndex = {} for i,name in enumerate(argNames): self.argNameToIndex[name] = i if defaults and i >= len(self.arguments)-len(defaults): # add default type to allowable types self.arguments[i].add(type(defaults[i-(len(self.arguments)-len(defaults))])) def verify(self, value, i): '''Returns true if the value matches the allowable types for the ith argument.''' if not isinstance(i, int): if i not in self.argNameToIndex: raise Exception, 'unknown argument name: %s' % i i = self.argNameToIndex[i] return type(value) in self.arguments[i] def verifyAll(self, *values, **kvalues): '''Returns true if all values matche the allowable types for their corresponding arguments.''' for i,value in enumerate(values): if not self.verify(value, i): return False for name,value in kvalues.iteritems(): if not self.verify(value, name): return False return True def __call__(self, *args, **kargs): assert self.verifyAll(*args, **kargs), 'argument types must be in the form of %s' % self.arguments return self.fn(*args, **kargs) class Test(unittest.TestCase): def test(self): @arguments(str, [int, float], list) def foo(abc, xyz, big=None): return '%s %s' % (abc, xyz) self.assertEqual(type(foo), _Arguments) self.assertEqual(len(foo.arguments), 3) self.assertEqual(foo.arguments[2], set([list, type(None)])) self.assertEqual(foo.verify('how', 0), True) self.assertEqual(foo.verify(123, 0), False) self.assertEqual(foo.verify(123, 1), True) self.assertEqual(foo.verify(1.23, 1), True) self.assertEqual(foo.verifyAll('how',123), True) self.assertEqual(foo.verifyAll(123,'how'), False) self.assertEqual(foo.verifyAll(abc='how',xyz=123), True) self.assertEqual(foo.verifyAll('how',xyz=123), True) self.assertEqual(foo.verifyAll('how',xyz='oeuuo'), False) self.assertEqual(foo.verifyAll('how',xyz=123,big=None), True) self.assertEqual(foo.verifyAll('how',xyz=123,big=[1,2,3]), True) self.assertEqual(foo.verifyAll('how',123,[1,2,3]), True) self.assertEqual(foo.verifyAll('how',123,'asoenhuas'), False) self.assertTrue(foo('how',123)) self.assertTrue(foo(abc='how',xyz=123,big=None)) if __name__ == '__main__': unittest.main() From a10990370 at 163.com Tue Dec 12 22:36:02 2006 From: a10990370 at 163.com (a10990370 at 163.com) Date: 12 Dec 2006 19:36:02 -0800 Subject: I find a good shop online! Message-ID: <1165980962.656933.63520@80g2000cwy.googlegroups.com> This is a network store, specializes in selling each kind of international well-known brand, for example: ADIDAS, NIKE, CD, DG, EVISU, ATINK and so on. My MSN is a10990370 at 163.com www.loveinfashion.com From fredrik at pythonware.com Thu Dec 14 06:58:35 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 12:58:35 +0100 Subject: error: Error -5 while decompressing data from struct.unpack In-Reply-To: <20061205115954.007721.5d3758e6@goombah.com> References: <20061205115954.007721.5d3758e6@goombah.com> Message-ID: Gary Robinson wrote: > One of our users received an exception, "error: Error -5 while > decompressing data from struct.unpack," in the course of a > struct.unpack operation. I haven't been able to discern what Error -5 > is in this context. In experiments here I wasn't able to elicit that > exception. > > There's a system exception EINTR which is 5 -- but that's 5, not -5. > > Any help on this would be most appreciated. from what I can tell, the word "decompressing" is only used in the zlib sources in Python. are you sure the user didn't mean "zlib.decompress" instead of "struct.unpack" ? From langstefan at gmx.at Sun Dec 10 09:51:21 2006 From: langstefan at gmx.at (hit_the_lights) Date: 10 Dec 2006 06:51:21 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165762281.579645.56990@l12g2000cwl.googlegroups.com> Steven D'Aprano schrieb: > >>> def import(): > File "", line 1 > def import(): > ^ > SyntaxError: invalid syntax > > > Nope, can't shadow or change keywords. (And yes, the error message could > be better.) I have a very interesting Python module. Look what it does: ======= python ==================== >>> import a >>> import b You sucker thought I'd import b for you. Instead I'm going to erase your hard drive. ================================ Somehow the meaning of "import" changed between the first and the second line. Doesn't it frighten you? (BTW: Do you know how that works, or should a Lisper show you?) It seems that Phytonistas, including Guido, don't trust each other. Guido always provides half assed restrictive solutions instead of decent meta programming. Examples include "lambda", the new "with" syntax and decorators. From grahamd at dscpl.com.au Sat Dec 9 20:35:06 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 9 Dec 2006 17:35:06 -0800 Subject: Mod_python vs. application server like CherryPy? References: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> <33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com> <1165445758.342163.37650@f1g2000cwa.googlegroups.com> <457a0c8d$0$49208$14726298@news.sunsite.dk> Message-ID: <1165714506.869766.112050@n67g2000cwd.googlegroups.com> Damjan wrote: > > For example, consider an extreme case such as WSGI. Through a goal of > > WSGI being portability it effectively ignores practically everything > > that Apache has to offer. Thus although Apache offers support for > > authentication and authorisation, a WSGI user would have to implement > > this functionality themselves or use a third party WSGI component that > > does it for them. > > OTOH > WSGI auth middleware already supports more auth methods than apache2 itself. A distinction needs to be made here. HTTP supports Basic and Digest authentication mechanisms, both of which are in Apache by default. The authentication mechanism though needs to be seen as distinct from the auth provider, that is, who actually validates that a user is valid. Apache 2.2 separates these two things with there being a pluggable auth provider facility with backend implementations for such things as passwd like files, dbm database, ldap and using mod_dbd various SQL databases. Because it is pluggable it can be extended to support any sort of auth provider implementation you want. It is even technically possibly to write an auth provider which makes used of Python to perform the check using some custom system, although mod_python itself doesn't provide this yet, so you need to roll your own auth module to do it. Even as far as authentication mechanisms go, you aren't limited to just those as the fact that you can provide a complete authentication and/or authorisation handler means you can implement other as well. You might for example build on top of SSL and use client certificates to control access, or you could use HTTP forms based login and sessions. These custom mechanisms could also use the auth provider plugin system so that they aren't dependent on one particular user validation mechanism. Now, when you say that WSGI already supports more auth methods than Apache 2 itself, are you referring to how the login/authentication is handled over HTTP, or how client validation is handled, ie., auth providers. I am not being critical here, asking more to build my knowledge of WSGI and what capabilities it does have. > > Similarly with other Apache features > > such as URL rewriting, proxying, caching etc etc. > > Well, not everybody can use Apache ... and again there's already WSGI > middleware that's more flexible than the Apache modules for most of the > features you mention. > > It's not that I think mod_python doesn't have uses.. I just think it's not > practical to make python web applications targeted solely to mod_python. For what you are doing that may not be practical, but in a lot of other places it would be a more than reasonable way of going about it. To clarify though, I am not talking about building something which is completed implemented within the context of mod_python alone and not even something that is written in Python exclusively. What I have been talking about is using Apache as a whole as the platform. Thus, taking authentication as an example, for basic forms of authentication it is best to use the standard mod_auth and auth provider facilities of Apache to do it. For more complicated mechanisms such as using HTTP form, more customisation is usually required and this might be implemented using Python under mod_python but could just as well be implemented in mod_perl. A main thing to note though is that if Apache authentication handlers are written properly, it can be used to span not just mod_python but apply to static files served by Apache, as well as handlers which serve up content using other languages modules such as PHP, mod_perl. This is where I said it can be more about integration rather than writing pure Python code, because if you use Apache and mod_python properly, you don't end having to write code within a monoculture consisting of one implementation language as you are if you use WSGI. Instead, you can pick and choose the modules and languages which make the most sense as far as allowing you to implement something in the easiest way possible given what you have and the environment you are operating in All I can say is that since this is a Python language list, that many here will be here because they want to program specifically in Python and nothing else. Others though may well see the bigger picture and the realities of working with big systems, especially in a corporate environment, where one doesn't have a choice but to deal with code developed over time and in different languages with a result that most of the time you are writing more glue and than actual application code. Thus, in an ideal world you might be able to write in Python and nothing else, but it isn't always an ideal world. Graham From paul at boddie.org.uk Fri Dec 8 09:29:35 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 8 Dec 2006 06:29:35 -0800 Subject: Video stream server References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> <1165218527.632366.290350@j44g2000cwa.googlegroups.com> <1165221764.002660.197600@16g2000cwy.googlegroups.com> <1165444039.489227.32780@80g2000cwy.googlegroups.com> <1165565558.661663.38020@j44g2000cwa.googlegroups.com> Message-ID: <1165588175.043743.22970@j44g2000cwa.googlegroups.com> Lad wrote: > I checked your video strem server.It seems interesting for me. It's not my software, I'm afraid. I just read enough of Planet GNOME to have become aware of the activities of various people, including people who work at Fluendo [1] - the principal developers of that software. > Can you please answer these questions? > 1. What is a price? I guess you can get the different components at no cost from the site I mentioned [2]. > 2.Do you support FLV format files, if not, why? > 3. How many users do already use the server? > 4. Can you name any of your customers ? You would need to ask Fluendo all these questions. I was just telling you what I've read about myself. Paul [1] http://www.fluendo.com/ [2] http://www.flumotion.net/ From gagsl-py at yahoo.com.ar Mon Dec 18 13:17:32 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 18 Dec 2006 15:17:32 -0300 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: <0vsi54-1vf2.ln1@eskimo.tundraware.com> References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <1166394345_23949@sp6iad.superfeed.net> <1166442477.818748.324370@f1g2000cwa.googlegroups.com> <0vsi54-1vf2.ln1@eskimo.tundraware.com> Message-ID: <7.0.1.0.0.20061218151118.03ff75c0@yahoo.com.ar> At Monday 18/12/2006 13:41, Tim Daneliuk wrote: >I was working on a new release and wanted to add file associations >to it. That is, if the user selected a file and double clicked or >pressed Enter, I wanted the following behavior (in the following >steps, "type" means nothing more than "a file whose name ends with >a particular string"): > >1) If an association for that file type exists, run the associated program. > >2) If an association for that file type does not exist: > > a) If the file is not "executable", see if there is a "default" > association defined and run that program if there is. > > b) If the file *is* "executable", run it. This is what os.startfile does. The underlying Win32 functions would be ShellExecute, FindExecutable & their variants. Will you maintain your own registry for associations? -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From uymqlp502 at sneakemail.com Mon Dec 4 19:10:06 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 4 Dec 2006 16:10:06 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> <1165250963.660087.58410@n67g2000cwd.googlegroups.com> <45745F24.2010406@v.loewis.de> <1165258556.021281.51440@79g2000cws.googlegroups.com> <45749D82.4040301@v.loewis.de> Message-ID: <1165277406.806371.181620@79g2000cws.googlegroups.com> Fredrik Lundh wrote: > you're forgetting that you're dealing with "squeaky wheel contributors" > here, not the kind of nice and helpful persons that actually make open > source work. Please refrain from dishing out gratutious insults until you have a clue what you are talking about. It just so happens that I *have* made significant contributions to open-source software. A few years ago, I spent several man-months of my own time developing a free, open-source, full-featured GUI for voting: http://russp.org/GVI.htm GVI, The Graphical Voter Interface, is a GUI (Graphical User Interface) for voting, suitable for use in private or public elections. Although it could be adapted for online voting, it is currently intended only for conventional "precinct" voting. For security reasons, GVI does not require that the voter have access to a keyboard. It can handle write-ins and multi-language elections, and it can automate voting along party lines. GVI can be used for Condorcet Voting and Instant Runoff Voting, which allow voters to rank the candidates in order of preference. It can also be used for Approval Voting, which allows voters to select more than one candidate. More recently, I developed a free, open-source Python package for dealing with physical scalars. It has an innovative feature that preserves the efficiency of built-in numerical types with an optional switch: http://russp.org/scalar.htm A Python class was designed to represent physical scalars and to eliminate errors involving implicit physical units (e.g., confusing angular degrees and radians). The standard arithmetic operators are overloaded to provide syntax identical to that for built-in numeric types. The scalar class comes with a complete implementation of the standard metric system of units and many standard non-metric units. It also allows the user to easily define a specialized or reduced set of appropriate physical units for any particular application or domain. Once an application has been developed and tested, the units can easily be switched off, if desired, to achieve the execution efficiency of operations on built-in numeric types (which can be two orders of magnitude faster). The scalar class can also be used for discrete units to enforce type checking of integer counts, thereby enhancing the built-in dynamic type checking of Python. From sjatkins at gmail.com Sat Dec 9 00:18:23 2006 From: sjatkins at gmail.com (samantha) Date: 8 Dec 2006 21:18:23 -0800 Subject: merits of Lisp vs Python In-Reply-To: <4ttiadF15dam8U1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> Message-ID: <1165641503.331698.174270@j72g2000cwa.googlegroups.com> What are you? A pointy haired boss? - s Bjoern Schliessmann wrote: > Alex Mizrahi wrote: > > > hell no, lisp's syntax is much easier than python's since it's > > homogenous > > Can you give an example? I cannot imagine how homogenity always > results in easiness. > > > (and certainly lisp was invented much 30 years before > > Python, so that's Python uses Lisp features) > > I think you acknowledged that the syntax is different and not > borrowed? > > [many parentheses] > > that make logic more explicit > > Can you give an example? > > Regards, > > > Bj?rn > > Xpost cll,clp > > -- > BOFH excuse #166: > > /pub/lunch From moishyyehuda at gmail.com Thu Dec 14 11:52:02 2006 From: moishyyehuda at gmail.com (moishyyehuda at gmail.com) Date: 14 Dec 2006 08:52:02 -0800 Subject: run a script and supply commands from a python cgi script Message-ID: <1166115122.154349.78730@j72g2000cwa.googlegroups.com> Hi #1 How do I open a script from another script. #2 when I run the script how can I supply commands to the script. #3 how do I find the what commands the script needs. The thing is like this. I need to set up a module on my server, but i cant access the server with a comand line. So I want to run setup.py script (I nead to run setup.py to setup up the module) from a python cgi script, and supply commands from the script. So if any one can help me with this I would appreciate it. Moishy From rampeters at gmail.com Wed Dec 6 14:58:34 2006 From: rampeters at gmail.com (johnny) Date: 6 Dec 2006 11:58:34 -0800 Subject: newb: Can I use PYRO Message-ID: <1165435114.572787.34010@n67g2000cwd.googlegroups.com> What I want to do is the following: Web user uploads a word doc (web app written in php), and I need it to move the uploaded word doc, on to another machine and conver it to pdf. Then update the database and allow immediate pdf download. I am thinking of using ftp from machine 1 -> machine 2, then convert doc to pdf on machine 2, using process or thread. What is the best way to go about doing this, process or threads or pyro? Pdf is created by calling commands on the command line, through python script. Thank you in advance. John From evan at binarymanipulations.com Thu Dec 28 04:25:16 2006 From: evan at binarymanipulations.com (Evan Carmi) Date: Thu, 28 Dec 2006 09:25:16 +0000 (UTC) Subject: Unexpected output while walking dirs Message-ID: hi, i am creating a program to go through a directory structure recursively (including directories below it) and move all files that end in .msf to a directory above the current level. the code i have so far is as follows: #!/usr/bin/python #Author: Evan Carmi #Date: 20061101 #Purpose: To uncorrupt Mozilla Thunderbird mail index files. #Version: 2.04 top = 'f:\\test\\mail' import os, time, itertools #walk and find all files allfiles = [] for root, dirs, files in os.walk(top, topdown=False): for name in files: allfiles.append(os.path.join(root, name)) #remove all non .msf files index = [] for match in allfiles: if match.endswith('.msf'): index.append(match) print index #need to fix the problem with adding folders to thunderbird indexdest = [] indexdest = ['%s\\..\\..\\%s\\%s\\%s' % (x , time.strftime('%Y%m%d%H%M%S'), os.path.basename(os.path.normpath(x+'\\..')), os.path.basename(x)) for x in index] #\\.. to remove the ending and than basename to add it back on indexdest = [os.path.normpath(i) for i in indexdest] indexdest = [i.replace('Mail', 'backups-msf') for i in indexdest] for a, b in itertools.izip(index, indexdest): os.renames(a, b) if the directory structure is: -test -Mail -Local Folders -mail.binarymanipulations.com and there are no additional directories inside of Local Folders than everything works and the script moves the .msf files to a directory on the same level as -Mail named backups-msf. the problem occurs when the directory structure: -test -Mail -Local Folders -mail.binarymanipulations.com has additional directories inside of Local Folders. This results in very odd behavior and the directory structure looks like: -test -Mail -Local Folders -mail.binarymanipulations.com -20061228005643 -Local Folders -mail.binarymanipulations.com after running the script. i hope that my problem is clear now, if you have any other information that would be helpful please tell me. I am testing this on a w2k machine with python 2.4 thanks, Evan From Amateur.N7TZG at gmail.com Fri Dec 15 17:06:42 2006 From: Amateur.N7TZG at gmail.com (Rob) Date: 15 Dec 2006 14:06:42 -0800 Subject: Serial port failure In-Reply-To: References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> Message-ID: <1166220402.505731.11150@l12g2000cwl.googlegroups.com> Craig, In the embedded firmware, the each box re-transmits after it finishes reading the packet. This is a very rudimentary system, and uses no flow control. The topology is that each embedded box has a master and a slave port. The master is used to receive data from the upstream box, and send acks or naks back to the upstream box. The slave is connected to the master of the next downstream box. Does that clear up the picture a little bit? Rob On Dec 15, 11:30 am, Nick Craig-Wood wrote: > Rob wrote: > > I am fairly new to python, but not programming and embedded. I am > > having an issue which I believe is related to the hardware, triggered > > by the software read I am doing in pySerial. I am sending a short > > message to a group of embedded boxes daisy chained via the serial port. > > When I send a 'global' message, all the connected units should reply > > with their Id and Ack in this format '0 Ack'What is to stop all the embedded boxes talking at once? > > I suspect that the embedded boxes all taking at once is confusing the > serial port driver. Maybe it is creating a break condition that it > doesn't deal with properly? Or perhaps I've misunderstood the > topology! > > What sort of flow control are you using? Could it have got out of > step with XON-XOFF? > > Assuming the driver is locking up then it looks like a serial port > driver bug. In my day job I do a lot of stuff with serial ports and > I've found that drivers vary wildly in quality! > > My advice is to try a different serial port hardware. I've found ones > based on the PL2303 chip to be very reliable both under windows and > linux. > > Eg this one :- > > http://www.scan.co.uk/Products/ProductInfo.asp?WebProductID=98192 > > Or one of these (which were based on PL2303 last time I bought one) > > http://www.comtrol.com/products/catalog.asp?group=usbserialhubs > > I don't think anything you can do from python/user-space should be > able to lock up the kernel mode serial driver. If it does lock up it > is a driver bug. > > Here you'll find a little program I wrote which, with the help of a > loopback connector, you can check your serial port out > > http://www.craig-wood.com/nick/pub/cambert.exe > > Run the program from a cmd prompt and it will tell you how to use it. > > I've broken a lot of serial port drivers with that program ;-) > > -- > Nick Craig-Wood --http://www.craig-wood.com/nick From simone.leo at gmail.com Thu Dec 14 09:17:39 2006 From: simone.leo at gmail.com (Tekkaman) Date: 14 Dec 2006 06:17:39 -0800 Subject: Logging module: problem with some mapping keys In-Reply-To: <1166033372.240310.299860@73g2000cwn.googlegroups.com> References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166033372.240310.299860@73g2000cwn.googlegroups.com> Message-ID: <1166105859.450403.135640@79g2000cws.googlegroups.com> sim.sim wrote: > Hi, i've check documentation, and found that logging.basicConfig takes > no arguments (probably we have different versions of logging package), Your Python version is < 2.4. Now basicConfig takes optional keyword args: basicConfig([**kwargs]) Does basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger. The functions debug(), info(), warning(), error() and critical() will call basicConfig() automatically if no handlers are defined for the root logger. In my real application (not the small test script!) This behaviour is very useful since I can call basicConfig only once in the main file and then all I have to do in the other files is: import logging self.logger = logging.getLogger("myClass") Everything works smoothly except for not being able to get file and line number info. > and i've never used it. > > just try this: > > > fileName = 'testlog.log' > logName = 'LOG' > iHandler = logging.FileHandler(fileName) > iHandler.setFormatter( > logging.Formatter("%(levelname)-8s|%(asctime)s|%(pathname)s,%(name)s, > line %(lineno)s|%(message)s") ) > > iLog = logging.getLogger(logName) > iLog.addHandler(iHandler) > iLog.setLevel(logging.DEBUG) > > iLog.info('hello logging') > > > > it gives me: > > INFO |2006-12-13 19:57:33,575|test.py,LOG, line 12|hello logging > > > On 13 Dec., 19:02, "Tekkaman" wrote: > > I'm getting a strange behaviour from the "pathname" and "lineno" > > formatter mapping keys. Instead of my file and my line number I get: > > > > /usr/lib/python2.4/logging/__init__.py > > > > as the file, and 1072 as the line number. I set up my config as > > follows: > > > > logBaseConf = { > > 'level' : logging.DEBUG, > > 'format' : "%(levelname)-8s|%(asctime)s|%(pathname)s, > > %(name)s, line %(lineno)s|%(message)s", > > 'datefmt ': '%d %b %Y, %H:%M:%S', > > 'filename': 'logtest.log', > > 'filemode': 'a' > > } > > logging.basicConfig(**logBaseConf) > > > > I'm not using any executable-generating tools such as cx_Freeze or > > Psyco. In fact, I'm getting this error on a very basic script with the > > specific purpose of testing the logging module capabilities. > > > > Thanks in advance for any contribution. > > > > T. > > -- > Maksim Kasimov From nagle at animats.com Sat Dec 16 15:48:25 2006 From: nagle at animats.com (John Nagle) Date: Sat, 16 Dec 2006 20:48:25 GMT Subject: Roundtrip SQL data especially datetime In-Reply-To: References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> <1166258893.044093.196820@79g2000cws.googlegroups.com> Message-ID: Marc 'BlackJack' Rintsch wrote: > In , John Nagle wrote: > >>John Machin wrote: >> >>>John Nagle wrote: >>> >>>>dyork wrote: >>>> >>>>>"John Machin" wrote in message >>>>>news:1166211949.065578.292600 at f1g2000cwa.googlegroups.com... >>>>> >>>>> >>>>> >>>>>>If you have, as you should, Python 2.5, you can use this: >>>> >>>> Actually, MySQLdb isn't released for Python 2.5 yet >>> >>> >>>Actually, that's interesting information [why should it take so long?], >>>but the OP didn't actually say what brand of database he was actually >>>using :-) >> >> True. >> >> Why should it take so long? The Python people don't support the >>MySQL interface, and the MySQL people don't support the Python interface. >>There's one guy on Sourceforge doing the MySQLdb glue code. And he's busy. > > > AFAIK there's no MySQLdb module for Python 2.5 on *Windows* yet, because > the author of the module doesn't use Windows anymore and he don't want to > maintain a binary he can't test. The SourceForge page http://sourceforge.net/project/showfiles.php?group_id=22307 says "MySQL versions 3.23-5.0; and Python versions 2.3-2.4 are supported." Last release was April, 2006. There's no binary for Python 2.5 yet. See the help discussions for the project. Apparently you can build it for Python 2.5 from the SVN repository and it can be made to work, but just building it may not work on your platform. Some edits may be required. Problems have been reported with the Windows version and the 64-bit Linux version. These are all normal development issues. But they're not fully resolved yet. So users should hold off from using Python 2.5 in production database applications. John Nagle From bj_666 at gmx.net Fri Dec 8 04:57:48 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Fri, 08 Dec 2006 10:57:48 +0100 Subject: Best way to split up lines - RE: About the 79 character linerecommendation References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com> <012601c719f7$9e719990$0d7d12ac@kearfott.com> <1165519627.247663.165610@73g2000cwn.googlegroups.com> Message-ID: In , Gabriel Genellina wrote: > At Thursday 7/12/2006 16:46, Roy Smith wrote: > >>I see your point. Actually, I think you want to force the sequences to be >>lists (regardless of what syntax we end up with), on the theory that tuples >>are for heterogeneous sequences and lists are for homogeneous ones. > > Any rationale for this theory? The BDFL says so. Don't question him. ;-) Ciao, Marc 'BlackJack' Rintsch From S.Mientki-nospam at mailbox.kun.nl Sun Dec 24 17:13:30 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Sun, 24 Dec 2006 23:13:30 +0100 Subject: file/directory format/size help In-Reply-To: References: <1166975132.276914.77430@n51g2000cwc.googlegroups.com> Message-ID: >> #1 What type of file is the file? Is it a movie, image, or text >> document? > > In the Windows world, one simply looks at the file extension (e.g. .gif, > .avi, .txt, etc.) and hopes that it is correct. or simply use TRID: http://mark0.net/soft-trid-e.html Stef Mientki From kirk at nospam.jobsluder.net Sat Dec 16 14:05:06 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sat, 16 Dec 2006 14:05:06 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <7xbqm4d97d.fsf@ruckus.brouhaha.com> <7xodq4mule.fsf@ruckus.brouhaha.com> <7xvekcbhm9.fsf@ruckus.brouhaha.com> Message-ID: In article , Kirk Sluder wrote: > In article <7xvekcbhm9.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: > > > n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ... > > If computer languages were to mimic natural languages on this point, > they would support both forms of expression and be sensitive to mode > and mood. And ok, bringing this around to lisp, many complex expressions such as polynomials can be viewed as lists of sub-expressions. So in this case, the expression can be re-written as: (* (subexp1) (subexp2) (subexp3) (subexp4)) Which is probably how I'd solve the expression if I was using paper and pencil: simplify and combine. And there is something that is missing here in arguing about computer language notations in relationship to human language readability, or correspondence to spoken language. I'm not writing code for another human, I'm writing code for a machine. Often, the optimum expression of an mathematical concept for a machine is relatively baroque compared to the optimum expression for a human being. From manstey at csu.edu.au Tue Dec 19 01:02:26 2006 From: manstey at csu.edu.au (manstey) Date: 18 Dec 2006 22:02:26 -0800 Subject: Class property with value and class Message-ID: <1166508146.304422.198590@a3g2000cwd.googlegroups.com> Hi, Is is possible to have two classes, ClassA and ClassB, and setattr(ClassA, 'xx',ClassB), AND to then have ClassA.xx store an integer value as well, which is not part of ClassB? e.g. If ClassB has two properties, name and address: ClassA.xx=10 ClassA.xx.name = 'John' ClassA.xx.address = 'Sydney'. etc? I've no idea if this is possible or desirable. thanks, matthew From bj_666 at gmx.net Wed Dec 27 17:40:49 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 27 Dec 2006 23:40:49 +0100 Subject: loose methods: Smalltalk asPython References: Message-ID: In , Jan Theodore Galkowski wrote: >>Guido was opposed to modifying builtin types before Java existed. It's >>similar to his opposition to dynamic syntax. > > The other is placing those builtins at the top of their own object > hierarchy. Is "int", properly speaking, a descendent of "object"? In [108]: issubclass(int, object) Out[108]: True > In any case, as respectful of Mr/Dr van Rossum as I am, simply because > so-and-so says something is bad and therefore it must be true is a > fallacious response. I don't think the response was meant to say that it must be bad but that it won't show up as feature in Python as long as the BDFL thinks it's bad. Ciao, Marc 'BlackJack' Rintsch From sturlamolden at yahoo.no Mon Dec 4 10:39:13 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 4 Dec 2006 07:39:13 -0800 Subject: About alternatives to Matlab In-Reply-To: <1165241895.291617.143380@80g2000cwy.googlegroups.com> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> Message-ID: <1165246753.867457.204270@79g2000cws.googlegroups.com> Filip Wasilewski wrote: > So why not use C++ instead of all others if the speed really matters? > What is your point here? If speed matters, one should consider using hand-coded assembly. Nothing really beats that. But it's painful and not portable. So lets forget about that for a moment. Contrary to what most computer scientists think, C++ is not the tool of choice if speed really matters. Numeric computing is typically done in Fortran 90/95. That is not without reason. There are aspects of the C++ language that makes certain numerical optimizations impossible, e.g. the potential for pointer aliasing within tight loops, which hampers register allocation. For example: for(i=0; i <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165700999.744643.207110@73g2000cwn.googlegroups.com> <1165707169.300567.84700@f1g2000cwa.googlegroups.com> Message-ID: <1165707564.952088.240940@79g2000cws.googlegroups.com> tayssir.j... at googlemail.com wrote > Further, Lisp is not a functional > language like Scheme; it has unusually powerful iteration and array > facilities. Excuse me, I mean to say it is not a pure functional language. Tayssir From gagsl-py at yahoo.com.ar Fri Dec 15 01:32:20 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 15 Dec 2006 03:32:20 -0300 Subject: Is it good to create a thread in a non gui thread? In-Reply-To: <45822F67.7030008@gmail.com> References: <45820E89.4050702@gmail.com> <7.0.1.0.0.20061215005803.05a08b10@yahoo.com.ar> <45822F67.7030008@gmail.com> Message-ID: <7.0.1.0.0.20061215031621.03225f10@yahoo.com.ar> At Friday 15/12/2006 02:15, Lialie - KingMax wrote: Please keep your posting on the list. >Gabriel Genellina wrote: > > At Thursday 14/12/2006 23:55, Lialie - KingMax wrote: > > > >> I create a thread in a non gui thread, and it does well. But it seems > >> strange. Somebody told me better not for it may cause something hard to > >> imagine. > >> Is there any different between them? > > > > I'm not sure if I understand the question. You can have a non gui > > application -an HTTP server by example- using many threads with no > > problems. > > > > >Thank you for your reply. > >I wrote a simple application with GUI. I create a thread to calculate >data which may cost much time. So during the calculation, the interface >can response. But one thread ONLY uses up half of my CPU(dual core) >resource, I need more than two. >The question is coming: where to create the thread? Create one more from >GUI as the previous brother or as the child. >----------- >GUI thread >| >+------ First one ---> >| >+------- start_new_thread --> >--------------- >GUI thread >| >+--------First one ---> >| >+--------start_new_thread ----> > >------------ >In my opinion, creating another thread from GUI thread or non gui thread >are the same. Am I right? Yes. Conceptually all threads are "brothers", it doesn't matter which thread created it, there is no parent/child relationship between them. The only difference being the "main" thread who is responsible for the lifetime of the application. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From dominis at idi.caib.es Tue Dec 12 02:07:13 2006 From: dominis at idi.caib.es (dominis at idi.caib.es) Date: Tue, 12 Dec 2006 09:07:13 +0200 Subject: Error Message-ID: Your message was undeliverable due to the following reason: Your message was not delivered because the destination server was unreachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message could not be delivered within 2 days: Host 216.78.202.45 is not responding. The following recipients did not receive this message: Please reply to postmaster at python.org if you feel this message to be in error. From Thomas.Ploch at gmx.net Thu Dec 7 20:27:31 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Fri, 08 Dec 2006 02:27:31 +0100 Subject: A Call to Arms for Python Advocacy In-Reply-To: <4578BF20.9020602@gmx.net> References: <4578BF20.9020602@gmx.net> Message-ID: <4578BF83.4000508@gmx.net> Thomas Ploch schrieb: > Roy Smith schrieb: >> In article , >> Jeff Rush wrote: >> >>> As the Python Advocacy Coordinator, I've put up some wiki pages on the Python >>> website for which I'm soliciting ideas, writing and graphics. Some of the >>> material exists scattered about and just needs locating and organizing. >>> >>> http://wiki.python.org/moin/Advocacy >> >> I think it also appears to need faster hardware. It's running glacially >> slow. > > I hope you are _not_ using IE... > > > > (Sorry, I didn't want to offend you, but it's fine with me ,too.) > > :-) > > Thomas Well, I should have not answered right the first of 107 messages without reading further... Thomas From noway at ask.me Thu Dec 21 19:39:03 2006 From: noway at ask.me (Giovanni Bajo) Date: Fri, 22 Dec 2006 01:39:03 +0100 Subject: [ANN] PyInstaller 1.3 released In-Reply-To: References: <4589AEE8.8070600@jessikat.plus.net> Message-ID: Robin Becker wrote: > OK I found the problem. First off I still see this message about > msvcr71.dll could not be extracted! > > in the debug output. > > Secondly I found that the icon I specified in the Makespec.py invocation > is actually being added to the distribution exe. I actually want to put > the icon onto the running Tk app. > > We're using this code to do that > > self.tk.call('wm','iconbitmap', self._w, '-default', 'rptlabw.ico') > > ie it's assumed that the icon has been extracted into the runtime folder. > > I guess I either need to put the icon in as a resource or figure out > some way to find the original exe and extract the icon from it. If you specify it as icon (--icon to Makespec), it means you want it as icon of the executable. If you just want to add it as an additional data file, read the manual about that. It will be extracted to the runtime directory and you should be able to access it through _MEIPASS2 (manual should be clear about that). You can't just read it from the "current directory" because the current directory is where your exectuable is run (which could even be off a CDROM...). -- Giovanni Bajo From Leo.Kislov at gmail.com Fri Dec 29 08:20:41 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 29 Dec 2006 05:20:41 -0800 Subject: INSERT statements not INSERTING when using mysql from python References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> <1167393801.950199.197830@48g2000cwx.googlegroups.com> <1167394098.642975.78350@73g2000cwn.googlegroups.com> <1167394662.665220.185680@a3g2000cwd.googlegroups.com> <1167395368.387567.283250@48g2000cwx.googlegroups.com> <1167396303.259891.144210@n51g2000cwc.googlegroups.com> Message-ID: <1167398441.102456.275730@n51g2000cwc.googlegroups.com> Ask Ben, he might know, although he's out to lunch. Ben wrote: > I'll try it after lunch. Does anyoone know whether this might be the > problem? > > Ben > > > Ben wrote: > > I have found the problem, but not the cause. > > > > I tried setting the database up manually before hand, which let me get > > rid of the "IF NOT EXISTS" lines, and now it works! > > > > But why the *** should it not work anyway? The first time it is run, no > > database or tables, so it creates them. That works. But apparentlyu on > > subsequent runs it decides the tables it created arent' actually there, > > and overwrites them. Grrrrrrrrrrrrr. > > > > > > Ben > > > > > > > > Ben wrote: > > > Well, I've checked the SQL log, and my insert statements are certainly > > > being logged. The only option left open is that the table in question > > > is being replaced, but I can't see why it should be... > > > > > > > > > Ben wrote: > > > > Nope... that can't be it. I tried running those commands manually and > > > > nothing went wrong. > > > > But then again when I execute the problematic command manually nothing > > > > goes wrong. Its just not executing until the last time, or being > > > > overwritten. > > > > > > > > > > > > Ben wrote: > > > > > Each time my script is run, the following is called: > > > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > > self.cursor.execute("USE "+name) > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( .... > > > > > > > > > > The idea being that stuf is only created the first time the script is > > > > > run, and after that the original tables and database is used. This > > > > > might explain my pronblem if for some reason the old tables are being > > > > > replaced... can anyone see anything wrong with the above? > > > > > > > > > > Ben > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Ben wrote: > > > > > > One partial explanation might be that for some reason it is recreating > > > > > > the table each time the code runs. My code says "CREATE TABLE IF NOT > > > > > > EXISTS" but if for some reason it is creating it anyway and dropping > > > > > > the one before that could explain why there are missing entires. > > > > > > > > > > > > It wouldn't explain why the NOT EXISTS line is being ignored though... > > > > > > > > > > > > Ben > > > > > > > > > > > > > > > > > > Ben wrote: > > > > > > > I initially had it set up so that when I connected to the database I > > > > > > > started a transaction, then when I disconnected I commited. > > > > > > > > > > > > > > I then tried turning autocommit on, but that didn't seem to make any > > > > > > > difference (althouh initially I thought it had) > > > > > > > > > > > > > > I'll go back and see what I can find... > > > > > > > Cheers, > > > > > > > Ben > > > > > > > > > > > > > > > > > > > > > johnf wrote: > > > > > > > > Ben wrote: > > > > > > > > > > > > > > > > > I don't know whether anyone can help, but I have an odd problem. I have > > > > > > > > > a PSP (Spyce) script that makes many calls to populate a database. They > > > > > > > > > all work without any problem except for one statement. > > > > > > > > > > > > > > > > > > I first connect to the database... > > > > > > > > > > > > > > > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > > > > > > > > self.cursor = self.con.cursor() > > > > > > > > > self.cursor.execute("SET max_error_count=0") > > > > > > > > > > > > > > > > > > All the neccesary tables are created... > > > > > > > > > > > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > > > > > > self.cursor.execute("USE "+name) > > > > > > > > > > > > > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > > > > > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > > > > > > > > varchar(20)) > > > > > > > > > > > > > > > > > > Then I execute many insert statements in various different loops on > > > > > > > > > various tables, all of which are fine, and result in multiple table > > > > > > > > > entries. The following one is executed many times also. and seems > > > > > > > > > identical to the rest. The print statements output to the browser > > > > > > > > > window, and appear repeatedly, so the query must be being called > > > > > > > > > repeatedly also: > > > > > > > > > > > > > > > > > > print "

SQL query executing

" > > > > > > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > > > > > > > > ','c','2','e','f','g')") > > > > > > > > > print "

SQL query executed

" > > > > > > > > > > > > > > > > > > I have, for debugging, set "i" up as a counter variable. > > > > > > > > > > > > > > > > > > No errors are given, but the only entry to appear in the final database > > > > > > > > > is that from the final execution of the INSERT statement (the last > > > > > > > > > value of i) > > > > > > > > > > > > > > > > > > I suspect that this is to vague for anyone to be able to help, but if > > > > > > > > > anyone has any ideas I'd be really grateful :-) > > > > > > > > > > > > > > > > > > It occured to me that if I could access the mysql query log that might > > > > > > > > > help, but I was unsure how to enable logging for MysQL with python. > > > > > > > > > > > > > > > > > > Cheers, > > > > > > > > > > > > > > > > > > Ben > > > > > > > > > > > > > > > > Not sure this will help but where is the "commit"? I don't use MySQL but > > > > > > > > most SQL engines require a commit. > > > > > > > > Johnf From vito.detullio at gmail.com Tue Dec 26 07:25:19 2006 From: vito.detullio at gmail.com (ZeD) Date: Tue, 26 Dec 2006 12:25:19 GMT Subject: Splitting lines from a database query References: <45910d4d$0$16553$afc38c87@news.optusnet.com.au> Message-ID: Peter Machell wrote: > I have an application where I need to take a query from an existing > database and send it to a web api. [...] > There are always 5 values, but some are blank and some are 'None'. > I'd like to split the lines so I get something resembling XML, like this: > Frank > Spencer > > Dr I Feelgood > quick and dirty solution: bar = ( ("Jane Mary","SIMPSON","0411231234","Dr I Feelgood","2006-12-27 15:00:00"), ("John","DOE","None","Dr I Feelgood","2006-12-27 15:30:00"), ("Frank","SPENCER","","Dr I Feelgood","2006-12-27 16:00:00") ) spam ="FNAME", "SNAME", "PHONE", "DR","TIME" for x in bar: i=0 while i<5: if x[i] != 'None': print "<%s>%s" % (spam[i], x[i], spam[i]) else: print "<%s>" % (spam[i], spam[i]) i+=1 print -- Under construction From researchbase at gmail.com Mon Dec 4 00:18:39 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Mon, 4 Dec 2006 10:48:39 +0530 Subject: problem formatting dates from text fields. In-Reply-To: References: <6eHch.7012$1s6.5812@newsread2.news.pas.earthlink.net> Message-ID: is there a soft copy of wxpython in action available for free download? I saw the book on my book store but since I am totally blind, I have to depend on soft copies. Krishnakant. From robert.kern at gmail.com Wed Dec 6 19:18:55 2006 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 06 Dec 2006 18:18:55 -0600 Subject: Windows installer for Scientific Python for Python 2.4? In-Reply-To: <1165449476.969662.218990@n67g2000cwd.googlegroups.com> References: <12nehgaak7mte4@corp.supernews.com> <1165449476.969662.218990@n67g2000cwd.googlegroups.com> Message-ID: hrh1818 wrote: > How did you come to your conclusion? The scipy page at > http://www.scipy.org/Download shows the following: > "Install SciPy 0.5.1 for Python 2.4 or SciPy 0.5.1 for Python 2.3" ScientificPython != scipy http://dirac.cnrs-orleans.fr/ScientificPython/ http://sourcesup.cru.fr/projects/scientific-py/ -- 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 From f.braennstroem at gmx.de Fri Dec 1 05:15:17 2006 From: f.braennstroem at gmx.de (Fabian Braennstroem) Date: Fri, 1 Dec 2006 11:15:17 +0100 Subject: python 2.5 install from source problem Message-ID: Hi, I just tried to install python 2.5 from source on my ScienticLinux (Redhat Clone) machine. It seems to work without any problem, at least I am able to run some of my old scripts. I installed it with './configure --prefix=/opt/python make make altinstall', but now for a 'vtk' installation which needs the python libraries I am not able to find a file like 'libpython2.5.so.*', which I think should be produced (at least at my office's machine (redhat) it is there). I just can find a 'libpython2.5.a' file ... Do I do something wrong? Greetings! Fabian From michax at gmail.com Sat Dec 9 10:38:46 2006 From: michax at gmail.com (Michax) Date: 9 Dec 2006 07:38:46 -0800 Subject: py2exe Problem with cairo Message-ID: <1165678726.572724.27000@79g2000cws.googlegroups.com> Hi, I have problem with my py2exe. When I want to run my compiled exe, then i get error information like that: Trackback (most recent call last): File "mysql_gui.py", line 2 in ? File "gtk\__int__.pyc", line 12, in ? File "gtk\_gtk.pyc", line 12, in ? File "gtk\_gtk.pyc", line 10, in __load ImportError: No module named cairo I have similar problem with all compiled .exe using gtk library. I want to add, that when I launch *.py file directly , everything works great. Detailed information : System : Windows 2003 with SP1 Python 2.4.4 gtk-2.10.6-win32-1 gtk-dev-2.10.6-win32-1 py2exe-0.6.5.win32.py.2.4 pycairo-1.0.2-1.win32.py.2.4 pygtk-2.8.6-1.win32-py2.4 MySQL-python.exe-1.2.1_p2.win32-py2.4 And most important thing , I'm newbie :) My source code http://www.moha.pl/mysql_gui.py Thanks in advance for any suggestion -- Micha? Kuli?ski Poland From sandravandale at yahoo.com Sat Dec 16 22:24:42 2006 From: sandravandale at yahoo.com (Sandra-24) Date: 16 Dec 2006 19:24:42 -0800 Subject: Good Looking UI for a stand alone application In-Reply-To: References: <4584531c$0$13533$426a74cc@news.free.fr> Message-ID: <1166325882.434177.313730@80g2000cwy.googlegroups.com> On 12/16/06, The Night Blogger wrote: > Can someone recommend me a good API for writing a sexy looking (Rich UI like > WinForms) shrink wrap application > My requirement is that the application needs to look as good on Windows as > on the Apple Mac wxPython or something layered on it would be the way to go. I tried all the popular toolkits (except qt) and nothing else comes close for cross platform gui work. Don't let people persuade you otherwise, that caused me a lot of trouble. -Sandra From arkanes at gmail.com Thu Dec 28 11:25:09 2006 From: arkanes at gmail.com (Chris Mellon) Date: Thu, 28 Dec 2006 10:25:09 -0600 Subject: __getattr__ possible loop In-Reply-To: <1167320704.931970.175330@42g2000cwt.googlegroups.com> References: <1167314779.170915.145680@48g2000cwx.googlegroups.com> <1167320704.931970.175330@42g2000cwt.googlegroups.com> Message-ID: <4866bea60612280825r58ac878avf2615c799ef5384@mail.gmail.com> On 28 Dec 2006 07:45:05 -0800, bearophileHUGS at lycos.com wrote: > Maksim Kasimov: > > how to improve the situation depends on what do you expect to get by calling "T().method()" > > You are right, sorry for being cryptic. I think that's a kind of bug of > Python (produced maybe by an infinite loop), so an improvement can be a > traceback or some automatic breaking of that loop. Note that my problem > comes from using Psyco that segfaults in that situation (if you have > Psyco installed you can decomment two lines to see that). I think that > using normal code Python+Psyco don't have to segfault, but I know this > is tricky situation, so if no simple "solutions" can be found, then > it's not a important thing and it can be ignored. > What I find most interesting is that you don't crash out because of hitting the recursion limit. My brief testing shows something odd going on - when the stack depth gets to almost 1000 (the recursion limit on my system) it knocks some stuff off the stack and the stack limit never gets to the limit. Some sort of built in tail recursion? From richard.charts at gmail.com Mon Dec 11 13:50:38 2006 From: richard.charts at gmail.com (Richard Charts) Date: 11 Dec 2006 10:50:38 -0800 Subject: need guidance on sending emails with attachment with python. In-Reply-To: References: <1165841644.575882.98390@16g2000cwy.googlegroups.com> Message-ID: <1165863038.458912.279290@j72g2000cwa.googlegroups.com> krishnakant Mane wrote: > On 11 Dec 2006 04:54:04 -0800, Bernard wrote: > > here's the function I've been using for while :P > > > thanks indeed for the function Bernard. > I will have a windows machine up tomorrow. but do I need to install > any thing over and above the python libraries needed? > is it necessary that I install outlook or do I need to install any > server/ client on the machine where your function is to be used? > > import smtplib > > from email.MIMEMultipart import MIMEMultipart > > from email.MIMEBase import MIMEBase > > from email.MIMEText import MIMEText > > from email.Utils import COMMASPACE, formatdate > > from email import Encoders > > > > def sendMail(arrRecipients, sender, subject, message, files=[]): > > """ Sends email with attachements """ > > # SMTP address > > smtpserver = '' # provide a smtp here in string format > > # authentification section > > AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1 > > smtpuser = '' # for SMTP AUTH, set SMTP username here > > smtppass = '' # for SMTP AUTH, set SMTP password here > > > > # Building the body of the email > > mssg = MIMEMultipart() > > mssg['From'] = sender > > mssg['To'] = COMMASPACE.join(arrRecipients) > > mssg['Date'] = formatdate(localtime=True) > > mssg['Subject'] = subject > > mssg.attach( MIMEText(message) ) > > > > # attachments > > for file in files: > > part = MIMEBase('application', "octet-stream") > > part.set_payload( open(file,"rb").read() ) > > Encoders.encode_base64(part) > > part.add_header('Content-Disposition', 'attachment; > > filename="%s"' % os.path.basename(file)) > > mssg.attach(part) > > > > session = smtplib.SMTP(smtpserver) > > if AUTHREQUIRED: > > session.login(smtpuser, smtppass) > > smtpresult = session.sendmail(sender, arrRecipients, > > mssg.as_string()) > > > > if smtpresult: > > errstr = "" > > for recip in smtpresult.keys(): > > errstr = """Could not delivery mail to: %s > > > > Server said: %s > > %s > > > > %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr) > > raise smtplib.SMTPException, errstr > > > > krishnakant Mane a ?crit : > > > > > hello, > > > I am a bit confused. > > > I want to make a program that will take some data from a database and > > > make a string of text. and send it to the respective email id of a > > > person. > > > next I also want to send an attachment of a photo along with the email. > > > I will be required to make this program run on windows xp. > > > can some one guide me as to how I can achieve this? > > > what I will need on windows to send emails? > > > I believe yahoo, gmail, rediff and msn supports pop3 and smtp? > > > correct me if I am wrong on this. > > > secondly what library is used on windows to do this? > > > I know there must be python libraries to do this, > > > but apart from that I don't know what all I will need on my windows > > > machine to send emails to mostly yahoo, gmail and msn. > > > Please give me some idea about it. > > > Krishnakant. > > > > > > You will need some working email account. It could be a server on your local machine or it could be a gmail account. If you don't have an email account that you want to send from, then you will have to either obtain one or create your own server. From bdesth.quelquechose at free.quelquepart.fr Tue Dec 19 11:04:26 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 19 Dec 2006 17:04:26 +0100 Subject: def index(self): In-Reply-To: References: <4587017b$0$22957$426a34cc@news.free.fr> Message-ID: <458807cc$0$19743$426a74cc@news.free.fr> Gert Cuykens a ?crit : >> FWIW, the first version raises an exception (unless of course the name >> 'index' is already bound in the enclosing scope). And the second won't >> probably work as expected with CherryPy. > > > > class HelloWorld: > def index(self): > return "Hello world!" > index.exposed = True #DOOOOOOH! And the winner is.... > > > i skipped reading the chapter about 2.1.8 Indentation. Guess how many > hours it took to realize 2 spaces isn't the same as 1 space lol Hint: - use a good code editor with auto(de)indentation (emacs + python-mode is quite nice) - use 4 spaces for indentation > Any other chapters i should read horizontal instead of vertical for a > php5 htm jso wane be snake user :) The whole thing, I guess. While Python is quite easy to get started with, there are a few gotchas. You're above snippet should be: class HelloWorld(object): def index(self): return "Hello World" index.exposed = True From researchbase at gmail.com Mon Dec 11 13:47:55 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Tue, 12 Dec 2006 00:17:55 +0530 Subject: issues with making a package. where do classes link? Message-ID: hello all, I am struggling a bit in making python packages. when I am doing a project I want to create all my python modules inside a single package. I want to know when I make a package, what are the basic things I must generally do in the __init__.py file? and how do I link all the modules in my project with each other? like when I make a compilation unit in java under a package, the first like of that file will read "package mypackage". I did not find any such thing in python that can say that this xyz file is in the abc package. if I want to use one module into another in my same package I can't figure how python figures it out? I want every thing in a single package. so that's my confusion. thanks. Krishnakant. From rw at smsnet.pl Mon Dec 4 07:52:21 2006 From: rw at smsnet.pl (Rob Wolfe) Date: 4 Dec 2006 04:52:21 -0800 Subject: get script path In-Reply-To: <%7Uch.38012$1w6.17240@newsfe16.lga> References: <%7Uch.38012$1w6.17240@newsfe16.lga> Message-ID: <1165236740.983496.307140@f1g2000cwa.googlegroups.com> hg wrote: > Hi, > > must I parse argv[0] to get it, or is there an easier way (that works under > Windows and *nix)? > > Ex: > > python /home/hg/test/test.py ==> test.py #knows it is in /home/hg/test IMHO it is easy enough: >>> dname, fname = os.path.split("/home/hg/test/test.py") >>> dname '/home/hg/test' -- HTH, Rob From jonc at icicled.net Sat Dec 9 15:03:34 2006 From: jonc at icicled.net (Jonathan Curran) Date: Sat, 9 Dec 2006 14:03:34 -0600 Subject: Interacting with keyboard LEDs In-Reply-To: <1165689183.812932.56980@80g2000cwy.googlegroups.com> References: <1165641507.187794.115360@l12g2000cwl.googlegroups.com> <1165689183.812932.56980@80g2000cwy.googlegroups.com> Message-ID: <200612091403.34218.jonc@icicled.net> Chris, I googled for {xlib caps led} and the first link was to a forum post: http://forums.whirlpool.net.au/forum-replies-archive.cfm/619126.html The third post down, the guy made a program to set the LED of his scroll lock key. The C source is at http://members.optusnet.com.au/foonly/hddled.c If you can manage to convert his code into python w/python-xlib you will be set. When you do, e-mail me the snippet will you ;) - Jonathan From max at alcyone.com Sun Dec 17 00:30:45 2006 From: max at alcyone.com (Erik Max Francis) Date: Sat, 16 Dec 2006 21:30:45 -0800 Subject: How to test if two strings point to the same file or directory? In-Reply-To: <4584d3fe$0$27423$4d3efbfe@news.sover.net> References: <1166317324.791635.274550@79g2000cws.googlegroups.com> <4584d3fe$0$27423$4d3efbfe@news.sover.net> Message-ID: <_rmdnRYBCZqBSxnYnZ2dnUVZ_vfinZ2d@speakeasy.net> Leif K-Brooks wrote: > ~ is interpreted as "my home directory" by the shell, but when it's used > in a path, it has no special meaning. open('~/foo.txt') tries to open a > file called foo.txt in a subdirectory of the current directory called '~'. That's what os.path.expanduser is for. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis It is much safer to obey than to rule. -- Thomas a Kempis From mail at microcorp.co.za Wed Dec 13 01:05:57 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 13 Dec 2006 08:05:57 +0200 Subject: Is anyone using Python for embedded applications? References: <457EEC35.3090104@mvista.com> Message-ID: <02c201c71e81$74476940$03000080@hendrik> "Carl J. Van Arsdall" wrote: > I'm aware of a couple python projects for embedded systems. I am > currently considering using Python on an embedded platform to develop a > simple application as a personal project, mostly to see if it will > work. I was wondering if anyone here was using python for anything of > that nature? For those that are involved in these types of projects, > how does development in python differ for embedded projects versus a > non-embedded project? Is there a community standard technique or style > for this type of development (i.e. heavy in OO design? commonly used > patterns?) Are there any good tools to assist for this type of > development environment? > > Oh, and if anyone has opinions/facts on why python should not be used in > an embedded platform, I'd like to know that too. I'm somewhat familiar > with pythons needs on a system, but there are a number of things I am > not aware of. > > Thanks to everyone for their input! > It depends a *lot* on what is meant by "embedded" : This definition seems to cover everything from: - a cut down PC in a non standard box, through - a processor in a Washing Machine, to - a bare PIC processor in a Burglar Alarm... I think the main hassles are that you need something big enough to run a reasonable OS in, and it must support being programmed in C, (which most things do), and it must have some MegaBytes of RAM loose for the Python. (where more is merrier) Trying to run this on say an AVR or 8031 with a 64k address space and a scarcity of RAM, will, to say the least, be a bit of a challenge... As far as the OS goes, Linux is probably the best bet, if you can get it to fit in your hardware - It has been ported to ARM type processors from various companies (Atmel springs to mind), and is free, which is a help in a personal project. You could of course also roll your own kernel, which will be good practice, as with a limited set of peripherals its not THAT hard to do, but its a bit far away from Python - :- ) What display device are you going to use, or is it going to be a webserver sitting on a power over ethernet link? I haven't actually taken the plunge myself yet to put Python on any of the hardware we make, as it seems to add a lot of overhead to a simple device - but I come from the bottom up, as it were, and the idea is intriguing, as I in fact discovered Python because it is embedded in a GPS module we were evaluating for building into a device - so I will follow your progress with interest... - Hendrik From duncan.booth at invalid.invalid Tue Dec 19 03:49:37 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Dec 2006 08:49:37 GMT Subject: should I distribute .pyc files? References: <1166514538.607571.89020@n67g2000cwd.googlegroups.com> Message-ID: "akbar" wrote: > I am creating not-so-important opensource application written in python > for Linux. I have two files python source in src directory, named > blabla1.py and blabla2.py. There are byte compiled files too, named > blabla1.pyc and blabla2.pyc. Should I distribute these files (pyc > files) to users? If I don't distribute them, and user installed my > application into /usr (not writable by normal user) then run it as > normal user, off course, the python cannot make byte-compiled version. > Will my program runs slower in user computer then in my computer > because I have byte compiled version? Short answer: use distutils or build a python egg. These will automate most of the distribution process. Longer answer: distutils (standard in Python) will build you a variety of installation packages such as zip, tar, rpm, or windows .exe (even from linux). The installation step will do all necessary compiling from .py to .pyc (and also builds extension modules although that can be problematic for a windows distribution where the correct compiler almost certainly isn't available). setuptools (http://cheeseshop.python.org/pypi/setuptools) is a collection of enhancements to distutils which let you build .egg files. Once you start using egg files you can include dependencies between package versions and if your product requires a bunch of other packages the installation step will download and install the appropriate versions. See http://peak.telecommunity.com/DevCenter/EasyInstall for instructions on installing packages built in this way, but in short, the user has to run ez_setup.py from the EasyInstall page, and then a command like: easy_install http://example.com/path/to/MyPackage-1.2.3.tgz would download and install your package and all the other products it depends on. If at a later stage they want to upgrade to a more recent version then all they need to do is to run: easy_install --upgrade MyPackage Installed eggs usually exist in a single file (importable zip) which makes uninstalling especially easy: just one file to delete. From shb*NO*SPAM* at comporium.net Sun Dec 3 13:27:23 2006 From: shb*NO*SPAM* at comporium.net (Si Ballenger) Date: Sun, 03 Dec 2006 18:27:23 GMT Subject: Parsing data from pyserial References: <4572e860.53134312@news.comporium.net> <12n606he7k5uhb3@corp.supernews.com> Message-ID: <4573145a.64392531@news.comporium.net> On Sun, 03 Dec 2006 16:52:33 -0000, Grant Edwards wrote: >On 2006-12-03, Si Ballenger wrote: > >> In my dealing with serial gizmos I have to put a delay between >> the request sent to the gizmo and the reading of the serial input >> buffer for returned data. Serial ports and gizmos need some time >> to do their thing. > >I doubt that's the issue. He's reading with a 1-second timeout >value. I would think a time delay would be needed between the below two lines in the code if he expects to get a useable data string back from the gizmo for the command sent to it. ser.write("TC 016 240 100 240 016 240\r\n") reading = ser.read(40) From steve at REMOVE.THIS.cybersource.com.au Sat Dec 16 19:16:49 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 17 Dec 2006 11:16:49 +1100 Subject: catching exceptions References: <1166270092.297610.19890@n67g2000cwd.googlegroups.com> <1166275468.140672.275010@t46g2000cwa.googlegroups.com> Message-ID: On Sat, 16 Dec 2006 05:24:28 -0800, jm.suresh at no.spam.gmail.com wrote: >> > Hi, In the following program, I have a class Test which has a property >> > x. Its setx function gets a string value and converts it into a float >> > and stores into it. >> >> [snip code] >> >> Python isn't Java. Are you sure you need properties? > > I do not know Java. But, object.x = value looks much better than > object.set_x(value) . Is there any harm in doing it, provided I have to > do more than just storing the value. Why write set_x in the first place if all it does is set x? Why not just have an attribute x and just write obj.x = value? What advantage are you gaining? One good use of properties is when you need attribute x to be calculated on the fly. But there are costs as well: accessing a property is more expensive than just accessing an attribute (accessing a property means that not only do you access an attribute, but you also run a method). That might not matter if your getter and setter are simple enough. Another cost is that you have to write the code in the first place, and then you have to test it: your class becomes bigger and more complicated. One reason why getters and setters are looked at suspiciously is that in the Java world, they frequently lead to bloated code. If you gain no benefit from that complexity, why pay for it? I'm not telling you "don't use properties" -- I'm merely telling you to think about why you are using getters and setters in the first place, and be sure that you are gaining benefit from them. I'm suspicious about your example, because your getter simply looks up a private attribute and returns it. Your setter does barely more work: it calls float. I'm guessing that your intention is to try to ensure that obj.x is only ever a float. But Python isn't designed for that sort of strong type checking. It is very, very hard (possibly impossible) to ensure calling code can't abuse your classes, and type-checking languages only protect against one small set of potential abuse anyway. The usual Python philosophy is not to bother, and instead rely on good unit testing to test for all bugs, not just type bugs. Your class as a tool. All tools can be used or misused. It isn't the responsibility of the tool to protect you from misusing the tool (because it can't, even if you wanted it to -- the best it can do is protect you from some misuses). It is the responsibility of whoever uses the tool to not misuse it. In practice, what that often (but not always) means is that if you have an attribute x that needs to be a float, your class is entitled to assume it will always be a float, and the code that uses your class is responsible for making sure that it never stuffs a non-float into x. If it does, that's a bug in the caller, not in your class, and is best caught by unit testing. (But does x really need to be a float? Maybe it only needs to be an object that acts like a float.) That's just something for you to think about. -- Steven. From duncan.booth at invalid.invalid Wed Dec 27 13:38:57 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Dec 2006 18:38:57 GMT Subject: BeautifulSoup bug when ">>>" found in attribute value References: Message-ID: John Nagle wrote: > It's worse than that. Look at the last line of BeautifulSoup > output: > > &linkurl;=/Europe/Spain/Madrid/Apartments/Offer/2408" /> > > That "/>" doesn't match anything. We're outside a tag at that point. > And it was introduced by BeautifulSoup. That's both wrong and > puzzling; given that this was created from a parse tree, that type > of error shouldn't ever happen. This looks like the parser didn't > delete a string item after deciding it was actually part of a tag. The /> was in the original input that you gave it: You don't actually *have* to escape > when it appears in html. As I said before, it looks like BeautifulSoup decided that the tag ended at the first > although it took text beyond that up to the closing " as the value of the attribute. The remaining text was then simply treated as text content of the unclosed param tag. Finally it inserted a to close the unclosed param tag. ... some time later ... Ok, it looks like I was wrong and this is a bug in BeautifulSoup: it seems that it *is* legal to have an unescaped > in an attribute value, although it should (not must) be escaped: >From the HTML 4.01 spec: > Similarly, authors should use ">" (ASCII decimal 62) in text > instead of ">" to avoid problems with older user agents that > incorrectly perceive this as the end of a tag (tag close delimiter) > when it appears in quoted attribute values. Thank you, it looks like I just learned something new. Mind you, the sentence before that says 'should' for quoting < characters which is just plain silly. From ronrsr at gmail.com Mon Dec 18 01:37:54 2006 From: ronrsr at gmail.com (ronrsr) Date: 17 Dec 2006 22:37:54 -0800 Subject: dealing with special characters in Python and MySQL In-Reply-To: References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com> Message-ID: <1166423874.304873.218020@t46g2000cwa.googlegroups.com> > > are you passing in the strings as Unicode strings, or as something else? > if you're using something else, what have you done to tell the > database what it is? > not at all sure what I'm passing it as. The database default encoding is utf-8 the database collation is utf-8 the page encoding of the page is utf-8 what else do I have to tell the database? From george.sakkis at gmail.com Fri Dec 22 01:00:05 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 21 Dec 2006 22:00:05 -0800 Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166741966.242087.192390@n67g2000cwd.googlegroups.com> Message-ID: <1166767205.559937.185260@f1g2000cwa.googlegroups.com> John Machin wrote: > Bruno Desthuilliers wrote: > > > > > Python is dynamic, and fighting against the language is IMHO a really > > bad idea. The only places where theres a real need for this kind of > > stuff are when dealing with the "outside world" (IOW : inputs and > > outputs). And then packages like formencode can do much more than mere > > type-checking > > > > Agreed. The worst case I have seen: > > An elaborate decorator (similar to the OP's) laboriously checks arg > types. That's IMHO not "consenting adults" territory. But it gets a > whole lot worse when it's applied to a method whose body is like this: > > if isinstance(.... > action_for_type1(... > # big snip > elif isinstance(... > action_typeN( ... > # no else statement Ouch.. someone must have skipped his/her OO class... From mail at microcorp.co.za Fri Dec 22 00:49:51 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 22 Dec 2006 07:49:51 +0200 Subject: Question about Tkinter windows References: Message-ID: <01b801c7258d$1870a380$03000080@hendrik> Manuel Malo de Molina wrote: >Hi everyone, this is the first time I use Python. I'm working on an application >using Tkinter and I would like that >the windows could only be opened once, is >there any option to get that? > >I don't know if I've explained myself: what I want is that if the user clicks >on "Options", for example, and he >doesn't close the options window, even if he >clicks again on the same button the window doesn't open again. > >Oh, I forgot, the windows are toplevel. Welcome to the wonderful world of Python hacking. 1) you can disable the button (at the start of the command bound to the button) or, 2) in the same place, you can use configure to change the button's command binding to a routine that does nothing and just returns Don't forget to reverse whatever changes you have made when the user closes the window, or it will be a "one-shot" system. -HTH - Hendrik From aahz at pythoncraft.com Fri Dec 29 12:47:44 2006 From: aahz at pythoncraft.com (Aahz) Date: 29 Dec 2006 09:47:44 -0800 Subject: Anyone persuaded by "merits of Lisp vs Python"? References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> <1167372073.541929.57370@48g2000cwx.googlegroups.com> <1167391935.980609.279850@79g2000cws.googlegroups.com> Message-ID: [x-post removed] In article <1167391935.980609.279850 at 79g2000cws.googlegroups.com>, Paddy wrote: >Carl Banks wrote: >> >> If you were so keen on avoiding a flame war, the first thing you should >> have done is to not cross-post this. > >I want to cover Pythonistas looking at Lisp and Lispers looking at >Python because of the thread. The cross posting is not as flame bait. If a Lisper is looking at Python, zie will be reading c.l.py, no? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "I support family values -- Addams family values" --www.nancybuttons.com From steve at REMOVE.THIS.cybersource.com.au Wed Dec 20 17:03:26 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Thu, 21 Dec 2006 09:03:26 +1100 Subject: perl better than python for users with disabilities? References: <87slfalf8h.fsf@jidanni.org> Message-ID: On Thu, 21 Dec 2006 00:11:10 +0800, Dan Jacobson wrote: > Can I feel even better about using perl vs. python, as apparently > python's dependence of formatting, indentation, etc. vs. perl's > "(){};" etc. makes writing python programs perhaps very device > dependent. I can't think of what sort of computer device you are thinking of that can't handle indented text. Wait -- my old HP-48C programmable calculator perhaps? As for perl and () {} etc, I would have thought that for anyone with poor eyesight, or using a tiny screen, they would be difficult to tell apart. > Whereas perl can be written on a tiny tiny screen, and can > withstand all kinds of users with various disabilities, etc.? "Withstand all kinds of users"? I can't imagine what you mean by that. > Also perl is easier to squeeze into makefiles. Perhaps you are right. In eight years of writing Python code, I've never once needed to squeeze Python into a makefile, so I don't know how hard it will be. -- Steven. From pavlovevidence at gmail.com Mon Dec 25 13:40:46 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 25 Dec 2006 10:40:46 -0800 Subject: One module per class, bad idea? In-Reply-To: References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> Message-ID: <1167072046.517498.91790@48g2000cwx.googlegroups.com> Kent Johnson wrote: > Carl Banks wrote: > > Kent Johnson wrote: > >> Carl Banks wrote: > >>> Now, I think this is the best way to use modules, but you don't need to > >>> use modules to do get higher-level organization; you could use packages > >>> instead. It's a pain if you're working on two different classes in the > >>> same system you have to keep switching files; but I guess some people > >>> prefer to switch files rather than to scroll for some reason. > >> That would be me. I strongly prefer to switch files rather than scroll. > >> I use an editor that makes it easy to switch files. For me it is much > >> easier to switch between files than to scroll between two parts of a > >> file, and I don't lose my place when I switch back. I like to be able to > >> see things side by side. > > > > Man, I don't know you do it. > > > > Say I'm sitting there concentrating on programming something, and I see > > that I'll have to make a change in another file. All of a sudden, I > > have to recall some filename out of thin air. Totally breaks my train > > of thought, sometimes I space out trying to think of it because I have > > to cold-start an entirely different part of my brain. It's less of a > > mental distraction to just scroll. > > But then to go back to where you were, you have to scroll back and find > your place. See, I find that to be a lot less of a mental disruption than recalling a filename on the spot. > For me, just a click or keystroke to restore the last file > with the cursor or selection exactly where I left it. And if I am going > back and forth between the two, each switch is equally easy after the > first (opening the file). Ok, but doesn't your editor have bookmarks? (I don't use them, because remembering a bookmark name is the same mental disruption for me as remembering a filename. Sometimes I use an interactive search will get me to where I want to go if it's more than a screen or two.) > > (BTW, any decent editor will let you view different positions of the > > same file side-by-side.) > > Right, at a cost of showing you half as much of the one you care about. I presume if you're looking at two different files side-by-side it's at the same cost? > Anyway, I'm not trying to convince anyone to change, just pointing out > that there are different styles of editing that make sense to those who > use them, if not to outside observers ;-) That's fine; I'm not knocking anyone's style. But maybe you should just leave it at, "I just prefer small files", and cease with the editor-based arguments. To be sure, there are probably editors out there that can load several files into the same buffer, which would mean I could avoid recalling filenames even when editing multiple files. (In fact, I think I'll look for such a solution the next time I find myself editing Java.) It's really not about the editor; I just think that the module is the best place for higher-level organization. But the package will do. Carl Banks From vasudevram at gmail.com Sat Dec 23 10:35:07 2006 From: vasudevram at gmail.com (vasudevram) Date: 23 Dec 2006 07:35:07 -0800 Subject: How a script can know if it has been called with the -i command line option? In-Reply-To: <1166887758.351581.189940@h40g2000cwb.googlegroups.com> References: <1166720012.798260.6670@80g2000cwy.googlegroups.com> <1166805005.943645.193860@48g2000cwx.googlegroups.com> <1166887758.351581.189940@h40g2000cwb.googlegroups.com> Message-ID: <1166888107.428277.123890@79g2000cws.googlegroups.com> vasudevram wrote: > Peter Wang wrote: > > Michele Simionato wrote: > > > The subject says it all, I would like a script to act differently when > > > called as > > > $ python script.py and when called as $ python -i script.py. I looked > > > at the sys module > > > but I don't see a way to retrieve the command line flags, where should > > > I look? > > > > I realize this is quite a hack, but the entire command line is > > preserved in the process's entry in the OS's process table. if you do > > "ps -ax" you will see that the interpreter was invoked with -i. I > > didn't test this under windows, but it works on Mac and Linux. > > That hack might not work - at least, as described, and on Linux or Mac > OS if the UNIX-based one, i.e. OS X). Because there could be other > users who ran python command lines with or without the -i option. As > described, there's no way for this user to know which python invocation > is his/hers, and which are of other users. There might be a way, > though, if we can get this user's python instance's process id and then > grep for a line containing that id (in the appropriate column) in the > ps output. > > Vasudev Ram > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > Dancing Bison Enterprises > http://www.dancingbison.com > http://dancingbison.blogspot.com > ~~~~~~~~~~~~~~~~~~~~~~~~~~ > Check out the cool Snap.com preview feature on my web site. > Free signup for anyone at www.snap.com > I'm not affiliated with it. Just realized: getting the python process's process id is possible from the Python program itself, using os.getpid(). Vasudev From bearophileHUGS at lycos.com Fri Dec 8 19:49:54 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 8 Dec 2006 16:49:54 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165623284.242403.295140@l12g2000cwl.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Message-ID: <1165625394.780517.310990@73g2000cwn.googlegroups.com> JShrager at gmail.com: > Sorry, I missed something here. Why do you need a release to have these > sorts of things? Can't you just expand the language via macros to > create whatever facility of this sort you need... Oh, sorry. You CAN'T > expand the language.... Too bad. I guess waiting for Guido to figure > out what Fits Your Mind is part of The Python Way. There are few programmers that are very intelligent and know how very well how to design languages, so they can invent such things. They are able to manage and appreciate the more freedom Lisp gives them. But *most* other programmers aren't intelligent enough for that, or they don't know enough language design to produce something working or something nice. So maybe Lisp is for the more intelligent people, or for really difficult programs (or for dynamic and flexible programs that have to run quite faster than Python+Psyco code), where having a bit simpler language isn't an advantage. All the other people use Python that contains things already well designed for them, such language constructs are the same for everybody, they are standards of the language, like generators, so reading each other code is simpler and faster too. Bye, bearophile From fsenkel at lynx.neu.edu Mon Dec 4 13:03:20 2006 From: fsenkel at lynx.neu.edu (monkeyboy) Date: 4 Dec 2006 10:03:20 -0800 Subject: Execution time of lines within a function In-Reply-To: References: <1165240166.203915.115460@n67g2000cwd.googlegroups.com> <1165249456.148956.217940@n67g2000cwd.googlegroups.com> Message-ID: <1165255400.497254.248780@n67g2000cwd.googlegroups.com> The output was from print_callees(). It appears as though print_stats() and print_callees() return the same data, just in a different orangization. There is supposed to be a "lineevents=1" option in hotshot.Profile, for line timings, but it doesn't seem to work in Python 2.4. Thanks for your help Neil Cerutti wrote: > On 2006-12-04, monkeyboy wrote: > > Thanks Neil, > > > > I looked at that, but maybe I don't understand the output. I > > was hoping to see the cummulative time for the function and > > then the time associated with each statement (line) within the > > function. > > > > Any suggestions? > > I don't think the Python Profiler goes down to that level. The > next step might be to analyze the function yourself and try to > understand why it is so slow. Post the code here and let the > readers pick it apart. > > > In the hotshot output below, I can see the function being > > called 100 times, which is correct, but the rest seems at too > > low a level for me to understand which statements are causing > > the slow execution. > > > > > > hw6r3.py:276(main) hw6r3.py:73(findw)(100) 26700.865 > > Is this the print_callees output? > > -- > Neil Cerutti From gagsl-py at yahoo.com.ar Mon Dec 4 21:37:12 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 04 Dec 2006 23:37:12 -0300 Subject: Best way for inter-process communication in Python Message-ID: <7.0.1.0.0.20061204233654.047bfe20@yahoo.com.ar> At Monday 4/12/2006 21:41, Hugo Ferreira wrote: Please keep posting on the Python list. >Thx for your reply. >Are you able to point me out to some documentation over that process? The primary source is the Microsoft documentation http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/interprocess_synchronization.asp You should read at least the basics from the documentation - at least to know which keywords to use for searching! :) - Most of the API is covered by the pywin32 package. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From jonathan.beckett at gmail.com Thu Dec 28 12:01:46 2006 From: jonathan.beckett at gmail.com (jonathan.beckett) Date: 28 Dec 2006 09:01:46 -0800 Subject: Some basic newbie questions... In-Reply-To: References: <1167324002.516960.319870@79g2000cws.googlegroups.com> Message-ID: <1167325306.545679.185300@48g2000cwx.googlegroups.com> Chris Mellon wrote: > On 28 Dec 2006 08:40:02 -0800, jonathan.beckett > wrote: > > Hi all, > > > > While working on support at work, I have been picking away at Python - > > because I think it could be a valuable scripting tool for building > > utilities from. I have been reading the python.org tutorials, and > > playing around with some basic code, but I have ended up with a few > > questions that probably have straightforward answers - any quick > > explanations or assistance would be fantastic... > > > > > > Question 1... > > Given the code below, why does the count method return what it does? > > How *should* you call the count method? > > a = [] > > a.append(1) > > print a.count > > > > print a.count(). There's a "Python for VB programmers" out there > somewhere, see if you can find it. In python, functions (and methods > which are special cases of functions) are first class objects, so > you're printing the function object, not calling it. > > > > > Question 2... > > What is the correct way of looping through a list object in a class via > > a method of it? (I've hit all sorts of errors picking away at this, and > > none of the tutorials I've found so far cover it very well) - apologies > > for the arbitrary class - it's the first example I thought up... > > > > class Gun: > > Shells = 10 > > > > class Battleship: > > Gun1 = Gun() > > Gun2 = Gun() > > Guns = [Gun1,Gun2] > > > > def getShellsLeft(self): > > NumShells = 0 > > for aGun in Guns: > > NumShells = NumShells + aGun.Shells > > return NumShells > > > > Bizmark = Battleship() > > > > print Bizmark.getShellsLeft() > > > > > > In the above code, I guess I'm just asking for the *correct* way to do > > these simple kinds of things... > > > > You have the right idea but you've got your object instantiation > wrong. As I write this, I see an email from Grant Edwards that sums > things up nicely, I'll let him explain it. > > I suggest working through the Python tutorial and Dive Into Python, > which will introduce you to the concepts you're getting wrong here. > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > I'm not a VB programmer :) I'm just tooling around with Python while I have time, figuring out how the syntax hangs together before I start trying to do anything remotely clever with it. I normally work with PHP, C#, Javascript, and the odd bit of C++, but find myself doing christmas support, so am looking for something to pick away at until the phone rings :) One thing I would like to do is play with pySQLite, which looks like it might be very handy indeed for making migration tools... From fred at adventistcare.org Wed Dec 6 13:55:05 2006 From: fred at adventistcare.org (Sells, Fred) Date: Wed, 6 Dec 2006 13:55:05 -0500 Subject: Async callback in python Message-ID: <1A4BF05172023E468CB6E867923BC90402B6E3CC@accmail2.sunbelt.org> the standard print gets "delayed" somewhere inside python, however if you use print >>sys.stderr, "whatever", 3, 4 5 that prints immediately, or so it seems to me. -----Original Message----- From: python-list-bounces+frsells=adventistcare.org at python.org [mailto:python-list-bounces+frsells=adventistcare.org at python.org]On Behalf Of Linan Sent: Monday, December 04, 2006 11:18 PM To: python-list at python.org Subject: Async callback in python Hi, In javascript, code could be written like this: ... var _p=XMLHttpRequest(); _p.open('GET',url,true); _p.send(null); _p.onreadystateChange=function(){ if(_p.readyState==4) cb(_p.responseText); } ... This basic AJAX code allows function to be called when it's invoked, without blocking the main process. There is same library asyncore in python. However, I can't validate it's asynchronous through code: class T(asyncore.dispatcher): def __init__(self,host,url): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((host,80)) self.url='GET %s HTTP/1.0\r\n\r\n' % url def handle_connect(self): pass def handle_close(self): self.close() def handle_read(self): print 'READING.....' print self.recv(256) def handle_write(self): sent=self.send(self.url) self.url=self.url[sent:] t=T('aVerySlowSite','/') asyncore.loop() for i in range(0,10): print '%d in main process' % i time.sleep(1) Suppose it's asynchronous, couple of '%d in main process' lines should be mixed in the output of T.handle_read(), right? But I found that actually main process was blocked at asyncore.loop(), until the the socket was closed. My questions: 1, Did I do anything wrong? 2, Is it real asynchronous? 3, If not, where to get the real one(s)? Any comment is welcome :) -- http://mail.python.org/mailman/listinfo/python-list From bugs at almad.net Tue Dec 12 13:31:01 2006 From: bugs at almad.net (Almad) Date: 12 Dec 2006 10:31:01 -0800 Subject: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__ Message-ID: <1165948261.745137.88540@j72g2000cwa.googlegroups.com> Hello, I discovered this behaviour in dictionary which I find confusing. In SneakyLang, I've tried to extend dictionary so it visits another class after something is added: class RegisterMap(dict): def __setitem__(self, k, v): dict.__setitem__(self, k,v) self[k].visit_register_map(self) However, when constructing dictionary with dictionary in constructor like d = RegisterMap({'k':'v'}), __setitem__ is not called, so workaround is needed: class RegisterMap(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) for k in self: self.__after_add(k) def __after_add(self, k): self[k].visit_register_map(self) def __setitem__(self, k, v): dict.__setitem__(self, k,v) self.__after_add(k) What is the reason for this behavior? Am I doing something wrong and better approach is needed? Or should this be considered as minor bug in Python? (tried this only in 2.4 so far) Thank You, Almad From exhuma at gmail.com Thu Dec 14 03:10:24 2006 From: exhuma at gmail.com (exhuma.twn) Date: 14 Dec 2006 00:10:24 -0800 Subject: Survey environment for Python? Message-ID: <1166083824.927340.102530@73g2000cwn.googlegroups.com> Hi, Just recently I had to take over support for legacy software written in Blaise (www.cbs.nl). As I did not know of this "Programming Language" until one year ago I started to learn it. Well.... more like "read it" as it's very very easy/simple. However, I don't feel comfortable in that language. As far not as comfy as in python ;) So I wanted to see if anyone knows of any surveying system written in or usable with python. For those that do not know Blaise: First of all, it's a simplified syntax of Pascal so the syntax is quite readable. And here is what you do with it: You define variables, then define "routes". Those routes are simply definitions in which order those variables should be processed, and if some variables should be skipped. In addition to that it can perform a series of data-validation tests and some simple computations. It then uses these fields and routes to automatically generate a user-interface to fill in those fields. And that's about it. I am aware that something like this should be doable in python. Also, I think that a solid User Interface is very important for this task. Qt would be nice, but I still have trouble getting it to run properly with python. But that's a different story. And to avoid installing third-party libraries (on windows), Tk or a HTML-Interface seem to be the only choices. Is there anything like that around? If no, would anyone be interested in giving me a hand for this sort of project? Somebody that understands Tk would be useful, as I am mostly fluent in HTML&co. From udodenko at users.sourceforge.net Fri Dec 8 15:02:59 2006 From: udodenko at users.sourceforge.net (Alex Mizrahi) Date: Fri, 8 Dec 2006 22:02:59 +0200 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> Message-ID: <4579c4f4$0$49201$14726298@news.sunsite.dk> (message (Hello 'Bjoern) (you :wrote :on '(Fri, 08 Dec 2006 19:57:28 +0100)) ( ??>> also, there's no need for operator precendence to be taken in ??>> accound -- order is explicitly defined. expressions are ??>> homogenous, they do not depend on other expressions near them ??>> (except lexical variables and side effects). BS> Sorry, I don't get it ;) Where does Python have things like BS> nonexplicit defined operator order? you have an expression 3 + 4 which yields 7. you have an expression 4 * 1 which yields 4. if you paste 3 + 4 in place of 1, you'll have 4 * 3 + 4 = 16. as we know, * is commutative, but 3 + 4 * 4 = 19. so result depends on implicit operator precendence rules. in lisp, if you paste (+ 3 4) in (* 4 1), you'll have (* 4 (+ 3 4)), and it does not depend on order of operands, (* (+ 3 4) 4) yields same results. you do not have to remember precendence rules -- * and + are not anyhow special from other functions. all you need to remember is how to call functions. certainly it's a very simple example, but it shows that generally, homogeous lisp syntax make expressions much less dependant on context, and there are much less rules affecting it. thus, work require by brain to understand and write code can be reduced -- that way it's easier. Common Lisp specification define internal languages that are not in homogenous s-expr syntax -- that is formatter and loop macro. like (loop for i from 1 to 20 collect i) or (loop for e in list maximizing e into max minimizing e into min finally (return (values min max))) remarkable thing about that is that it's the only place which i cannot remember and need to lookup quite frequently in the reference. although it looks almost like plain english and looks quite easy, it's much harder than other parts of lisp that use uniform syntax. but certainly this uniform syntax doesn't worth much without macro facilities. i'll show an example from my recent experiments. in this example we want to perform a query into a RDF database (triplestore), SPARQL-style query, and then we format results as HTML. here's how it looks in the SPARQL (i'm not fluent in it, so it can be buggy). basically, we want to query information (firstname, lastname, salary) or all users in specified departament. PREFIX myapp: SELECT ?fname, ?lname, ?salary WHERE { ?user myapp:name ?uname. ?uname myapp:first-name ?fname. ?uname myapp:last-name ?lname. ?user myapp:salary ?salary. ?user myapp:department ?dept. } we should feed this text to the query-builder. then we should bind ?dept to our variable departament (i'm not sure how this is done in SPARQL, but there should be a way). then we should iterate over results and output HTML. a python-like pseudocode: query = BuildQuery(query_str) query.bind("?dept", departament) results = query.execute() for each rs in results: print "" + htmlesc(rs.get("?fname")) + "" + htmlesc(rs.get("?lname")) + "" + rs.get("?salary") + "" so how uniform syntax and macros can help here? we can make a macro rdf:do-query that will both programmatically create query, bind input variables and then bind results into local variables. also we can wrap HTML output in a macro too. so here's a code: (rdf:do-query ((?user :name ?uname) (?uname :first-name ?fname) (?uname :last-name ?lname) (?user :salary ?salary) (?user :department department)) (html (:tr (:td (:princ ?fname)) (:td (:princ ?lname)) (:td (:princ ?salary))))) as you can find, it's two times less code, it's less clumsy, and there's even less quotes and parentheses there -- who says that lisp has more parentheses? also, this code is less error-prone, because some part of correctless can be checked during compilation time by macros, because it operates with symbols on semantic level, but not with simple strings. for example, if i make a type and write ?fnme instead of ?fname in the HTML output, compiler will report a warning about unbound variable, but if this variable will be in string-form, compiler will not be able to. there are other benefits: RDF query language is transparently integrated into Lisp, there's no need to learn some other language (SPARQL) syntax additionally. and it strains my brain less when i don't have to switch between different languages. is it possible to construct such helper functions (or whatever) to simplify code in Python? ) (With-best-regards '(Alex Mizrahi) :aka 'killer_storm) "People who lust for the Feel of keys on their fingertips (c) Inity") From kentilton at gmail.com Sat Dec 9 20:13:27 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 20:13:27 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: Andr? Thieme wrote: > Ken Tilton schrieb: > >> >> >> Andr? Thieme wrote: >> >>> Ken Tilton schrieb: >>> >>>> The last time we went thru this a Pythonista finally said, Oh, I get >>>> it. These five lines of code I have to write all the time (two >>>> setup, one func call, two cleanup) can be collapsed into one or two. >>>> The thread will be hard to miss in Google groups (two years back?) >>>> and the epiphany appears right at the end of the thread. >>> >>> >>> >>> Functional programming is the solution here, not Lisp. >> >> >> No, you do not understand. The Pythonista figured it out: a function >> would not do. > > > What do you mean? I am saying use Google groups to find the thread and find out the use case contributed by a Pythonista in the midddle of a similar thread that conveyed to his satisfaction the value of macros. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From Roka100 at gmail.com Fri Dec 1 04:41:31 2006 From: Roka100 at gmail.com (Jia Lu) Date: 1 Dec 2006 01:41:31 -0800 Subject: How to turn AUTOCOMMIT ON with cx_Oracle In-Reply-To: References: <1164964822.037946.172490@79g2000cws.googlegroups.com> Message-ID: <1164966091.557726.322390@n67g2000cwd.googlegroups.com> Paul McGuire ??????: > AUTOCOMMIT is a dangerous crutch, beware. Ok for single record updates, but > if you need to update 2 records in synch, AUTOCOMMIT leaves you open to > hard-to-debug bugs (will work ok in development under light load, then fail > intermittently with concurrent users). Thanx. But I am doing an exception test to Servers. So I have to work without commit, but I need a autocommit environment of DB. From not at valid.com Wed Dec 27 13:10:51 2006 From: not at valid.com (yomgui) Date: Wed, 27 Dec 2006 18:10:51 GMT Subject: how can I modify an imported variable ? References: Message-ID: actually, it is not linked to threading but to the scope. the second attempt to access MyPackage.aVariable is inside the __init__ of a class and this seems to be the problem. I believe it is a genuine python bug. yomgui From pavlovevidence at gmail.com Wed Dec 20 21:30:13 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 20 Dec 2006 18:30:13 -0800 Subject: what is wrong with my code? In-Reply-To: <87mz5i56j7.fsf@pyenos.pyenos.org> References: <874prq6wmd.fsf@pyenos.pyenos.org> <87vek65cne.fsf@pyenos.pyenos.org> <1166667427.238372.150240@t46g2000cwa.googlegroups.com> <87mz5i56j7.fsf@pyenos.pyenos.org> Message-ID: <1166668213.260870.187580@48g2000cwx.googlegroups.com> Pyenos wrote: > thanks for your point. so because i have said class blah: i must > explicitly say self for every instantiation of object? http://docs.python.org/tut/ Carl Banks From justask at acme.com Wed Dec 6 22:48:23 2006 From: justask at acme.com (Vincent Delporte) Date: Thu, 07 Dec 2006 04:48:23 +0100 Subject: Mod_python vs. application server like CherryPy? References: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> <33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com> <1165445758.342163.37650@f1g2000cwa.googlegroups.com> <1165451534.184166.78080@80g2000cwy.googlegroups.com> Message-ID: On 6 Dec 2006 16:32:14 -0800, "Graham Dumpleton" wrote: >Getting perhaps back to the answer you were seeking right back at the >start, that is if you are new to web application and development and >Python, then you may well be better of just using a higher level >framework as they will make it easier and isolate you from any pains in >understanding Apache and how to use it properly. Thanks a lot for the feedback. It's beginning to make sense :-) From carsten at uniqsys.com Wed Dec 27 13:53:38 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Wed, 27 Dec 2006 13:53:38 -0500 Subject: Passing variable number of named arguments In-Reply-To: <1167244665.250901.129020@79g2000cws.googlegroups.com> References: <1167244665.250901.129020@79g2000cws.googlegroups.com> Message-ID: <1167245618.3388.44.camel@dot.uniqsys.com> On Wed, 2006-12-27 at 10:37 -0800, Ramashish Baranwal wrote: >[...] > def fun2(**kwargs): > # get id param > id = kwargs.pop('id', '') > # pass on remaining to fun1 > fun1(kwargs) > > When I try to call fun2 I get the following error- > > TypeError: fun1() takes exactly 0 arguments (1 given) > > It seems that the arguments are not passed to fun1 as named arguments. You have to call fun1 like this: fun1(**kwargs). -Carsten From horpner at yahoo.com Fri Dec 1 11:30:58 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 1 Dec 2006 17:30:58 +0100 Subject: Detecting recursion loops References: <1164815293.529674.109850@l39g2000cwd.googlegroups.com> Message-ID: On 2006-12-01, robert wrote: > Ben Finney wrote: >> robert writes: >> >>> Carl Banks wrote: >>>> 2. Consider whether you're unwittingly trying to cover up a bug. >>>> ISTM no matter how problematic the input is, you should at least >>>> be able to make progress on it. Are you getting this error >>>> because, say, you're not incrementing a counter somewhere, and >>>> thus recalling a function with the same arguments again? >>> the "bug" comes in from the I/O input. >> >> If a program doesn't gracefully deal with bad input, that's a bug in >> the program. You should be designing your input handler so that it >> will do something helpful (even if that's to stop immediately with an >> informative error message) in the event of bad input, rather than >> allowing that bad data to send your program into an endless loop. > > > Yet that detection is what the asked alg should do. Example: > When a HTML-(content)-relaying sends you around in a circle > through a complex handler chain. Being in a cycle doesn't actually prove your program will never halt for that particular input, does it? -- Neil Cerutti Customers who consider our waitresses uncivil ought to see the manager --sign at New York restaurant From rhamph at gmail.com Sun Dec 3 11:11:38 2006 From: rhamph at gmail.com (Rhamphoryncus) Date: 3 Dec 2006 08:11:38 -0800 Subject: Deleting from a list while iterating In-Reply-To: References: <1165160235.282030.96610@79g2000cws.googlegroups.com> Message-ID: <1165162289.610285.126530@73g2000cwn.googlegroups.com> Marc 'BlackJack' Rintsch wrote: > Why do you make it that complicated? If you are going to build a new list > anyway, this can be done without the `set()` and just one listcomp: Fredrik Lundh wrote: > your set approach doesn't modify the list in place, though; it creates > a new list, in a rather roundabout way. if modification in place isn't > important, the normal way is of course to create a *new* list: > > items = [i for i in items if not i < 0.5] > > on my machine, that's about two orders of magnitude faster than your > "fast" approach for n=100000. Sorry, I should have clarified that the original post assumed you needed info from the "do something" phase to determine if an element is removed or not. As you say, a list comprehension is superior if that is not necessary. -- Adam Olsen, aka Rhamphoryncus From Sebastien.Boisgerault at gmail.com Tue Dec 19 04:36:10 2006 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 19 Dec 2006 01:36:10 -0800 Subject: ElementTree and utf-16 encoding Message-ID: <1166520970.118514.195040@80g2000cwy.googlegroups.com> Hi, ET being ElementTree in the following code, could anyone explain why it fails ? >>> xml = ET.tostring(ET.Element("root"), "UTF-16") >>> xml "\n<\xff\xfer\x00o\x00o\x00t\x00 />" >>> ET.fromstring(xml) Traceback (most recent call last): ... xml.parsers.expat.ExpatError: encoding specified in XML declaration is incorrect: line 1, column 30 I s it related to the lack of BOM in the xml string ? I tried to add some "\xff\xfe" or "\xfe\xff" at the start of the xml string without much sucess with fromstring so far ... Cheers, SB From horpner at yahoo.com Mon Dec 4 09:17:18 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 4 Dec 2006 15:17:18 +0100 Subject: Execution time of lines within a function References: <1165240166.203915.115460@n67g2000cwd.googlegroups.com> Message-ID: On 2006-12-04, monkeyboy wrote: > I have a function that hotshot says is very slow. I can get the > aggregate execution time, but is there a way to get the > execution time of each line so I can find the bottleneck? Try 'print_callees' on the stats object for your bottleneck. That may help. -- Neil Cerutti From gagsl-py at yahoo.com.ar Fri Dec 22 15:26:39 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 22 Dec 2006 12:26:39 -0800 Subject: How to distribute an additional DLL to site-packages? In-Reply-To: References: Message-ID: <1166819199.840464.96380@48g2000cwx.googlegroups.com> Bo Peng ha escrito: > > I am writing a python extension module that needs to link with a > > third-party DLL. How can I copy this DLL to the site-packages directory > > along with my extension modules? It seems that data_files parameter can > > do this, but I do not know how to get the absolute destination > > directory. After all, this directory is configurable. > > So nobody has ever done this??? Use the package_data option. setup(..., packages=['yyy'], package_data={'yyy':['xxx.dll']}, ...) (Distutils documentation may be arcane sometimes, but this is easily found at http://docs.python.org/dist/node12.html) Absolute dirs are almost never necesary, usually all distutils commands operate on relative paths (relative to location of setup.py for source files, relative to some meaningful directory for targets). -- Gabriel Genellina From fuzzyman at gmail.com Tue Dec 19 13:35:15 2006 From: fuzzyman at gmail.com (Fuzzyman) Date: 19 Dec 2006 10:35:15 -0800 Subject: [ANN] rest2web 0.5.1 Message-ID: <1166553312.713207.231930@f1g2000cwa.googlegroups.com> `rest2web 0.5.1 `_ is now available. This is a minor feature enhancement release. * `Download rest2web-0.5.1.zip `_ * `Download rest2web-0.5.1.tar.gz `_ What Is rest2web? ============= Maintaining websites or project documentation in HTML is a pain. **rest2web** takes out the pain, and brings back the joy. {sm;:wink:} **rest2web** is a simple tool that lets you build your website from a single template (or as many as you want), and keep the contents in `ReStructured Text `_. (You can still keep pages in HTML if needed.) It has an easy to us templating system, with embedded Python for unlimited flexibility and no new templating language to learn. It has built in functions or creating sidebars and navigation elements of a site. What's New in 0.5.1 ? ================ Added some extra debugging info to syntax errors in the templates. Fixed odict and pathutils for Python 2.5 compatibility. Added the 'promote_headers' option to the `config file `_. Added the ``sortpages`` method to the ``sections``. This sorts the pages in a section (or all sections) alphabetically. You can also pass in a custom sort function. From python at hope.cz Mon Dec 11 14:31:00 2006 From: python at hope.cz (Lad) Date: 11 Dec 2006 11:31:00 -0800 Subject: SSH File Transfer Protocol or SFTP In-Reply-To: References: <1165850967.059239.109890@j72g2000cwa.googlegroups.com> Message-ID: <1165865460.124384.71200@16g2000cwy.googlegroups.com> Avell Diroll wrote: > Lad wrote: > > Is there a module in Python available that I can use for uploading > > files via > > SFTP (SSH File Transfer Protocol)? > > Or do you think that FTP protocol for files uploading is OK? > > Thank you for replies > > Lad. > > > > I believe there are many of those, personally i am using paramiko : > > http://www.lag.net/paramiko/ > Thank you ALL for help. Paramiko seems the best for my needs. Lad. From rjagodic at gmail.com Mon Dec 11 16:55:01 2006 From: rjagodic at gmail.com (Ratko Jagodic) Date: Mon, 11 Dec 2006 15:55:01 -0600 Subject: comparing two IP addresses and the underlying machine Message-ID: <1eb708be0612111355u6c9c51a2u796fdb5aa44b01d9@mail.gmail.com> Hi all, I've been trying to figure this one out for some time but with no success. I have a machine with two network interfaces, each with their own IP address and it's own domain, for example: - ipA on machineA.domainA - ipB on machineB.domainB Given any pair of IPs or hostnames (or a mix of them), how can I figure whether they belong to the same physical machine or not? Of course, this is trivial if my python program is running the given machine but what if a remote machine is trying to figure this out (but that machine has access to both domains/IPs). Appreciate and ideas. Ratko -------------- next part -------------- An HTML attachment was scrubbed... URL: From nono at hotmail.com Sat Dec 23 08:21:52 2006 From: nono at hotmail.com (Osiris) Date: Sat, 23 Dec 2006 14:21:52 +0100 Subject: Newbie: what is a usefull IDE for Python on Windows ? References: Message-ID: ok, thnx. Thread closed :-) From tjreedy at udel.edu Wed Dec 6 21:29:33 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Dec 2006 21:29:33 -0500 Subject: Where does a class closure live? References: <45773BBC.5020301@andrew.cmu.edu> Message-ID: "Gerard Brunick" wrote in message news:45773BBC.5020301 at andrew.cmu.edu... > Consider: > > ### Function closure example > > def outer(s): > ... def inner(): > ... print s > ... return inner > ... > >>> f = outer(5) > >>> f() > 5 > >>> dir(f) > ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', > '__get__', '__getattribute__', '__hash__', '__init__', '__module__', > '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', > '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', > 'func_dict', 'func_doc', 'func_globals', 'func_name'] > > ### Class instance closure example > > >>> def outer2(s): > ... class Inner(object): > ... def __call__(self): > ... print s > ... return Inner() > ... > >>> f = outer2(10) > >>> f() > 10 > >>> dir(f) > ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', > '__weakref__'] > > ##### Class closure example > > >>> def outer3(s): > ... class Inner(object): > ... def __call__(self): > ... print s > ... return Inner > ... > >>> F = outer3(15) > >>> f = F() > >>> f() > 15 > >>> dir(F) > ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', > '__getattribute__', '__hash__', '__init__', '__module__', '__new__', > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', > '__weakref__'] > > > Now the closure for the function live in func_name. I don't understand this, but > I've even done the > exercise where I build a dummy inner function that returns its closed > variable, so that I can use that thing to reach through "cells" and > check out the variables living in the closure object. Where are the > closure variables for the class instance, and the class? Can I get my > hands on them in Python? [not tested but fairly sure correct...] There is no closure variable for the class or the instance, only for the __call__ function, which should have a func_closure attribute just as your first example did. Access that as Inner.__dict__['__call__'], where 'Inner' is either F or f.__class__. Terry Jan Reedy From p at ulmcnett.com Sat Dec 30 17:33:12 2006 From: p at ulmcnett.com (Paul McNett) Date: Sat, 30 Dec 2006 17:33:12 -0500 Subject: DOS, UNIX and tabs In-Reply-To: References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: <4596E928.1090507@ulmcnett.com> Sebastian 'lunar' Wiesner wrote: > Paul McNett

typed > >> Steven D'Aprano wrote: >>> But I think we all agree that mixing tabs and spaces is A Very Bad >>> Thing. >> I like mixing tabs and spaces, actually. Tabs for indentation, and >> additional spaces to make the code "look pretty". Somebody please tell >> me why this is bad and I'll stop. >> >> class Apple(object): >> def contrived_example_function(self, argument1, argument2, >> argument3, argument4): >> print "hello, world" >> >> Apparently, emacs in python mode follows this convention, too. > > That doesn't seem like a standard settings to me. I can't remember > changing the indentation settings for python, nonetheless my gnu emacs > uses four spaces for indentation. Placing wrapped lines into ordered > columns is done by inserting additional spaces. This all happens > automatically; you never need to insert spaces manually... I never tried emacs, but somebody once told me that if you have set indentation-by-tab, it will indent with tabs but insert additional spaces in wrapped lines to look pretty. >> I like it because I get the best of both worlds: the only thing >> against using tabs-only-indentation is that wrapping long lines can be >> quite ugly, while space-only-indentation allows for beautifying it >> somewhat by lining up the columns to match. > > Did you try to open your code files with another editor, which has a > different length for tabulator chars? It would look quite ugly, I > guess... Actually, no. Everyone can choose their own number of spaces-per-tab and it'll look right, as long as everyone uses a monospace font. -- pkm ~ http://paulmcnett.com From address.good.until.2007.feb.05 at justmail.de Fri Dec 15 21:27:44 2006 From: address.good.until.2007.feb.05 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Sat, 16 Dec 2006 03:27:44 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7xbqm4d97d.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <7xbqm4d97d.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin schrieb: > Andr? Thieme writes: >> And I didn't count the indentation level and \n in Python code. >> Why should I? They are editor commands. > > No they're part of Python syntax. A change in indent level is > recognized by Python's lexical scanner as a token and you should count > it. You wouldn't count the indent and \n separately though. > >> > Anyway, token count doesn't mean much, you have to instead go by the >> > user's cognitive effort in dealing with the prefix notation etc., >> >> How complicated ss it to say "cmp(a, b)" compared to "a cmp b"? > > It gets worse when the expressions are nested. So instead of cmp(foo(a, b, c), bar(x, y, z)) you would prefer foo(a, b, c) cmp bar(x, y, z) ? for x in 0 range len(s): ... Maybe make single-digit functions postfix? for x in 0 range (s)len: ... >> Imagine Python would have an "anaphoric if", "aif". Then: >> >> aif timeConsumingCalculation(): >> use(it) > > Well, it's not really in the Pythonic style to add obscurity like > that, but you could certainly write something like: > > def aif(func): > it = func() > if it: use(it) > > aif(timeConsumingCalculation) This isn't doing the same. This hardencodes the call to use() inside aif. if timeConsumingCalculation(): foo(it) bar(it) But "if" is already taken for the standard if. Instead we add a new keyword to Python, "aif". Then we can say: aif timeConsumingCalculation(): foo(it) bar(it) You can pass anonymous functions around etc, but it will become ugly - no Pythoniast would ever do it in production code. If there was an aif built into Python we would find it every now and then. Andr? -- From gagsl-py at yahoo.com.ar Fri Dec 1 21:08:09 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 01 Dec 2006 23:08:09 -0300 Subject: converting dict to object In-Reply-To: <7649225.post@talk.nabble.com> References: <7649225.post@talk.nabble.com> Message-ID: <7.0.1.0.0.20061201230546.0480a628@yahoo.com.ar> At Friday 1/12/2006 22:48, rieh25 wrote: >If I have a dictionary such as: > >d = {'a' : 1, 'b' : 2} > >is there a way to convert it into an object o, such as: > >o.a = 1 >o.b = 2 >>> class X(object): ... def __init__(self, d): self.__dict__.update(d) ... >>> d = {'a' : 1, 'b' : 2} >>> o=X(d) >>> o.a 1 >>> o.b 2 >>> -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From robert.kern at gmail.com Thu Dec 21 23:42:46 2006 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 21 Dec 2006 22:42:46 -0600 Subject: Problem in using Pulp In-Reply-To: <1166761918.461234.167610@h40g2000cwb.googlegroups.com> References: <1166759609.366064.124360@f1g2000cwa.googlegroups.com> <1166761918.461234.167610@h40g2000cwb.googlegroups.com> Message-ID: amitsoni.1984 at gmail.com wrote: > Thanks, now I am not getting that error, but now I am getting a > different error: > ---------------------error------------------------------- > GLPK("C:\Documents and > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob) > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114, > in solve > return lp.solve(self) > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line > 1740, in solve > status = solver.actualSolve(self) > File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188, > in actualSolve > raise "PuLP: cannot execute "+self.path > PuLP: cannot execute C:\Documents and > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples" > ------------------------------------------------------------- > can anyone tell me where the problem is? I am using following code. > GLPK("C:\Documents and > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob) The last character in that string is a double quote. You don't want that. What you want to do is escape all of the backslashes (or use raw strings to avoid the escaping altogether). E.g. "C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\" or r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\" -- 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 From oviedo96 at gmail.com Sat Dec 2 07:56:26 2006 From: oviedo96 at gmail.com (patkinson) Date: 2 Dec 2006 04:56:26 -0800 Subject: Python 2.5 bindings for Subversion 1.4.2 on Win32 binary In-Reply-To: <45717457.60003@v.loewis.de> References: <1165062123.881400.55200@n67g2000cwd.googlegroups.com> <45717457.60003@v.loewis.de> Message-ID: <1165064186.951775.257200@n67g2000cwd.googlegroups.com> Yes Martin, You are right. I'm not trying to threat any one. My excuses to you with that (infortunated) paragraph. Thanks anyway for your suggestion. My intention was to motivate other people with the same interests, or to find another way or patch, to keep Trac working. Regards P. Atkinson Martin v. L?wis ha escrito: > patkinson schrieb: > > Great python Projects like TRAC or DJANGO are the "keys" to a wide > > acceptance of python. Making this easy to the final users is (in my > > opinion) a survival question for the future of Python. > > Please note that threatening is useless most of the time in free > software. Very few people will agree that the future of Python depends > on provision of a subversion module for Python 2.5 on Win32, anyway. > > If you need this, you would work on making it happen yourself, or > you should hire somebody to make it for you if you can't do it > yourself. > > Regards, > Martin From barrywang at gmail.com Thu Dec 7 21:01:56 2006 From: barrywang at gmail.com (Barry) Date: 7 Dec 2006 18:01:56 -0800 Subject: Logging output from python Message-ID: <1165543315.696699.291910@j44g2000cwa.googlegroups.com> Hi, guys Basiclly, it is automated testing system. There is a main python script that handles the testing campagin. This main script will call another script that will in turn runs a few hundered individual python scripts. Here is my problem. I want to log everything displayed in the screen after I start the main python script. Things include unhandled exceptions , message from print statement and other sources. Basically, if it is displayed on the screen, I want to log it.. It might not be a pythons specific problem. Does anyone know a small tool does that job? Thanks. From grahamd at dscpl.com.au Thu Dec 28 16:57:14 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 28 Dec 2006 13:57:14 -0800 Subject: per interpreter storage for C extensions References: <4593E44C.9000502@chamonix.reportlab.co.uk> Message-ID: <1167343034.749502.131240@79g2000cws.googlegroups.com> Chris Mellon wrote: > I'm not that familiar with > mod_python but I'm surely each python interpreter is in a different > thread (if not process) than the others. No. In mod_python there can be multiple distinct interpreter instances in each Apache child process. If using a multithreaded Apache MPM, there can be multiple active threads in each Apache child process and more than one thread can be executing within any one particular interpreter instance within a process at the same time. For more details about the Apache/mod_python process/interpreter models read: http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel Graham From grante at visi.com Wed Dec 20 17:30:45 2006 From: grante at visi.com (Grant Edwards) Date: Wed, 20 Dec 2006 22:30:45 -0000 Subject: glibc detected double free or corruption Message-ID: <12ojecl8dhb8p37@corp.supernews.com> When I try to run pycadia I get the following error message as soon as I click "start game" *** glibc detected *** python: double free or corruption (out): 0xbff43b10 *** Then the program locks up and has to be killed with a SIGKILL. pycadia is a pure-python program that uses pygame, pygtk, and gtk.glade. Any ideas on how to troubleshoot this problem? -- Grant Edwards grante Yow! I've been WRITING at to SOPHIA LOREN every 45 visi.com MINUTES since JANUARY 1ST!! From http Sat Dec 9 04:16:07 2006 From: http (Paul Rubin) Date: 09 Dec 2006 01:16:07 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> Message-ID: <7xbqmdtoo8.fsf@ruckus.brouhaha.com> Paul Rubin writes: > http://www.math.chalmers.se/~rjmh/Papers/whyfp.html > > The examples in it are pretty easy to do in Python or Scheme, but I > think not so easy in CL. Hmm, well I guess they can be done in CL too, about the same way as in Scheme, but I'd say you have to be more careful. From http Thu Dec 14 16:13:51 2006 From: http (Paul Rubin) Date: 14 Dec 2006 13:13:51 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <1165593283.523163.71730@16g2000cwy.googlegroups.com> <457b3ca2$0$28520$3b214f66@tunews.univie.ac.at> <457f1b8c$0$7962$426a74cc@news.free.fr> <1166116337.983471.298630@16g2000cwy.googlegroups.com> Message-ID: <7xwt4ui3jk.fsf@ruckus.brouhaha.com> "Rob Thorpe" writes: > Once you can do the above then you can phrase programs entirely in > terms of composition of functions, which is what functional programming > is about. > > Getting good performance though is problematic without being able to > evaluate parts at compile time. This is why almost all functional > languages provide that feature in some form. I'm not aware of any special features in Haskell for that purpose, or in Scheme until maybe with the more recent versions. I thought the main feature needed for functional programming besides first-class functions was guaranteed tail call optimization. From sjmachin at lexicon.net Mon Dec 25 12:28:34 2006 From: sjmachin at lexicon.net (John Machin) Date: 25 Dec 2006 09:28:34 -0800 Subject: method names in __slots__ ?? In-Reply-To: References: <1167008799.074885.250770@73g2000cwn.googlegroups.com> Message-ID: <1167067714.627280.76420@n51g2000cwc.googlegroups.com> Rob Williscroft wrote: > John Machin wrote in news:1167008799.074885.250770@ > 73g2000cwn.googlegroups.com in comp.lang.python: > > > Given a = Adder(), > > a.tally = 0 > > gets AttributeError: 'Adder' object attribute 'tally' is read-only > > a.notinslots = 1 > > gets AttributeError: 'Adder' object attribute 'notinslots' is read-only > > > > So is there some magic class-fu going down here, or is this just a > > waste of memory space in the instances? > > > > Haven't you, with your 2 examples above, answered your own question ? No. > > Clearly from your example it doesn't make any difference if you add > a class attribute to the slots, one way or another its as if you > hadn't put it in there in the first place. Clearly? Not so. It takes up memory. A list of 1 million Adder instances takes up about 68 Mb (Python 2.5 on Windows XP). With the method names removed from the __slots__, it takes only about 44 Mb. [For comparison: with no __slots__ at all, it takes about 180 Mb] > > This will give the same error, which shows its about class attributes > and not just methods: > > class Adder(object): > > __slots__ = [ > 'class_name' > ] > > class_name = 3 > > > a = Adder() > > a.class_name = 2 > > It would seem that the interpreter removes any names it finds as class > attribute names from the list it finds in __slots__ before it creates > the instance. It doesn't seem so to me. If it did that, the memory usage would not increase. > > Of course if my guessing above isn't good enough, we could look at > the documentation: > > http://docs.python.org/ref/slots.html#l2h-218 > > __slots__ are implemented at the class level by creating descriptors > (3.4.2) for each variable name. As a result, class attributes cannot be > used to set default values for instance variables defined by __slots__; > otherwise, the class attribute would overwrite the descriptor assignment. I have read that, before I posted. Asides: (1) It would be useful if it stated the empirically determined fact that the result is that the class attribute is thusly made read-only. (2) The second sentence is not a model of clarity. In any case I can't see how the paragraph gives any support for your next statement: > > So its that the __slots__ assignment makes the descriptors and then the > subsiquent method defenitions and class attribute bindings remove them. Errrmmm ... if the descriptors are removed, how is it that the behaviour is read-only? Cheers, John From steve at REMOVE.THIS.cybersource.com.au Tue Dec 26 19:20:02 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Wed, 27 Dec 2006 11:20:02 +1100 Subject: Noobie: Open file -> read characters & multiply References: Message-ID: On Tue, 26 Dec 2006 16:50:06 -0700, gonzlobo wrote: > I've been using Python for a few days. It's such the perfect language > for parsing data! > > I really like it so far, but I'm having a hard time reading a file, > reading the first few hex characters & converting them to an integer. > Once the characters are converted to an integer, I'd like to write the > data to another file. > > Here's the code snipped to the bare minimum: > --- > # Open File > AP_File= open("AP.txt", "r") > decoded_File= open("decoded.txt", "w") > > # read & process data line by line > for line in AP_File: > time = int(hex(line[0:8]), 16) * 0.0001 # this line is completely hosed! > decodedFile.write(time) What does "this line is completely hosed!" mean? Does it crash your PC? Does it raise an exception? Do the wrong thing? Try this: for line in AP_File: # Typical line looks like this: # 000000d5 26 0600 80 00 ec 80 02 03 7d db 02 33 # This should convert to: # 0.0213 26 0600 80 00 ec 80 02 03 7d db 02 33 time = int(line[0:8], 16) * 0.0001 line = str(time) + line[8:] decodedFile.write(line) You might need to think about how many decimal places you want the time to store. > My boss and I are trying to complete the same task (he figured out how > to do it, but his code uses a while != "" loop and doesn't look > pythony (it looks too 'c'). Not that there's anything wrong with that! You can convert this: AP_File= file("AP.txt", "r") # file is recommended over "open" line = AP_File.readline() while line != "": do_something_with_line line = AP_File.readline() AP_File.close() into this: AP_File= file("AP.txt", "r") for line in AP_File: do_something_with_line AP_File.close() You need to look at what your boss does with the lines, not how he does the loop. -- Steven. From fredrik at pythonware.com Tue Dec 19 04:49:32 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 10:49:32 +0100 Subject: ElementTree and utf-16 encoding In-Reply-To: <1166520970.118514.195040@80g2000cwy.googlegroups.com> References: <1166520970.118514.195040@80g2000cwy.googlegroups.com> Message-ID: S?bastien Boisg?rault wrote: > ET being ElementTree in the following code, could anyone explain > why it fails ? I'm afraid the standard serializer in 1.2 only supports ASCII-compatible encodings. this will be fixed in 1.3. as a workaround, you can do: tostring(elem).decode("utf-8").encode("utf-16") From skip at pobox.com Thu Dec 28 21:08:28 2006 From: skip at pobox.com (skip at pobox.com) Date: Thu, 28 Dec 2006 20:08:28 -0600 Subject: module with a threading-like api that uses processes? In-Reply-To: <_oGdneJGV_5cnw_YnZ2dnUVZ_ragnZ2d@comcast.com> References: <_oGdneJGV_5cnw_YnZ2dnUVZ_ragnZ2d@comcast.com> Message-ID: <17812.30876.815142.439371@montanaro.dyndns.org> >> I could have sworn someone was working on a module recently with a >> threading-like API that used subprocesses under the covers, but 10 >> minutes or so of googling didn't yield anything. >> appreciated. Steve> http://www.python.org/dev/summary/2006-10-01_2006-10-15/#processes-and-threading-module-api Thank you. Exactly what I was thinking of. I had even replied to the thread!!! Skip From eric_brunel at despammed.com Thu Dec 21 03:16:55 2006 From: eric_brunel at despammed.com (Eric Brunel) Date: Thu, 21 Dec 2006 09:16:55 +0100 Subject: tkFileDialog closes main application References: <3qadnUMGb7pa6RTYnZ2dnUVZ_tyinZ2d@comcast.com> Message-ID: On Wed, 20 Dec 2006 18:37:10 +0100, mdmdmd wrote: > Hello, > > I wish to collect 4 files from a user. So I have decided to use > tkFileDialog askopenfilename. My problem is that after a few file > selections the root window is destroyed (the whole program just > dissappears) I tested the code below on Linux with Python 2.1 and tcl/tk 8.3.4 and it works perfectly. > I have created a simple example and was able to reproduce the same thing > with this. I've just started using tkinter so I have no idea what I may > be doing wrong. If anyone has any ideas please let me know. > > If you run the following code, just click the Browse button, and select > a file. Do this repeatedly and for me after the sixth or seventh time > the window shuts down. Is there any error when this happens? Have you tried running your script from a DOS command window? > BTW, I'm using python 2.4 on Windows XP. Thank you for any help. How do you select your files? I occasionally see problems on Windows when a window is closed via a double-click: the last 'button release' event for the double-click is not consumed by the dialog, but sent to the window behind it. Could it be what happens? If you select your files with a double-click and if the mouse cursor just happens to be on the close button for your main window behind it, you may involuntarily close the main window when selecting the file. Please try to select the files and then press the 'Open' button to see if the problem still happens. Here is a tiny modification to your code to print a message when the window is closed via its close button: > ################################################################################ > > from Tkinter import * > import Pmw > import tkFileDialog > import os.path > > filepath = 'C:\\Documents and Settings\\admin\\Desktop\\' > > class App(Frame): > def __init__(self,master): > Frame.__init__(self, master, bg='gray') > self.enttxt = StringVar() > > lbl = Label(self,text='File 1:') > lbl.grid(row = 0,column = 0,sticky = W,padx = 5,pady = 5) > > self.e1 = Entry(self,textvariable = self.enttxt,width = 50) > self.e1.grid(row = 0,column = 1,columnspan = 3,sticky = W,padx > = 5,pady = 5) > > btn = Button(self,text='Browse ...',width = 12, > command = self.browse) > btn.grid(row = 0,column = 4,sticky=W,padx=5,pady=5) master.protocol('WM_DELETE_WINDOW', self.doQuit) def doQuit(self): print 'Closed by the WM!' self.quit() > > def browse(self): > fileformats = [('Text File ','*.csv'), > ('All Files ','*.*')] > > retval = tkFileDialog.askopenfilename(title='Choose File', > initialdir=filepath, > filetypes=fileformats, > parent = self) > if retval: > self.enttxt.set(os.path.abspath(retval)) > > def main(): > root = Tk() > root.withdraw() > root.title('test') > root.configure(bg='gray') > app = App(root) > app.pack() > root.update() > root.deiconify() > > root.mainloop() > > > if __name__ == '__main__': > main() BTW, why do you create a sub-class of Frame for your application? Why not create a sub-class of Tk instead? HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" From nyamatongwe+thunder at gmail.com Sun Dec 3 16:37:30 2006 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 03 Dec 2006 21:37:30 GMT Subject: Using win32gui.SendMessage and SysListView32 control In-Reply-To: <1165176116.034632.58270@f1g2000cwa.googlegroups.com> References: <1165176116.034632.58270@f1g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com: > This page seems to imply that the control can be queried with messages, > however, my problem seems to be that pywin32.win32con does not define a > constant for the LVM series of messages. These are defined in win32/lib/commctrl.py in my installation. Neil From kwatch at gmail.com Tue Dec 26 14:15:09 2006 From: kwatch at gmail.com (kwatch at gmail.com) Date: 26 Dec 2006 11:15:09 -0800 Subject: Q: How to generate code object from bytecode? Message-ID: <1167160509.839311.230090@73g2000cwn.googlegroups.com> Hi, It is possible to get bytecode from code object. Reversely, is it possible to create code object from bytecode? ex. ## python code (not a module) pycode = '''\ print "

    \n" for item in items: print "
  • %s
  • \n" % item print "
\n" ''' ## compile it and get bytecode code = compile(pycode, kind='exec') bytecode = code.co_code open('hoge.pyc', 'wb').write(bytecode) ## load bytecode and eval it bytecode = open('hoge.pyc', 'rb').read() code = create_code(bytecode) ## how to ????? output = eval(code, globals, {'items': ['A', 'B', 'C']}) -- regards, kwatch From http Sun Dec 17 21:32:46 2006 From: http (Paul Rubin) Date: 17 Dec 2006 18:32:46 -0800 Subject: merits of Lisp vs Python References: <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> Message-ID: <7x3b7ekk6p.fsf@ruckus.brouhaha.com> "Kaz Kylheku" writes: > > Incorrect, I believe. The above is like saying Lisp's lack of > > optional manual storage allocation and machine pointers makes Lisp > > less powerful. > > That is true. By itself, that feature makes Lisp less poweful for > real-world software dev, which is why we have implementation-defined > escape hatches for that sort of thing. > ... > This is a bad analogy to the bondage-and-discipline of purely > functional languages. [/] The removal for the need for manual object > lifetime computation does not cause a whole class of useful programs > to be rejected. Did you just say two conflicting things? It's that very rejection that necessitates the escape hatches. > In fact, all previously correct programs continue to work as before, > and in addition, some hitherto incorrect programs become correct. > That's an increase in power: new programs are possible without losing > the old ones. There's more to power than making more programs possible. We also want to be able to distinguish correct programs from incorrect ones. Lisp has the power to eliminate a large class of pointer-related errors that are common in C programs, so Lisp is more powerful than C in that regard. Increasing the number of programs one can write in the unfounded hope that they might be correct is just one way to increase power. You can sometimes do that by adding features to the language. Increasing the number of programs you can write that are demonstrably free of large classes of errors is another way to increase power. You can sometimes do that by REMOVING features. That's what the Lisp holdouts don't seem to understand. > Right. GC gets rid of /program errors/. Pure functional programming > gets rid of /programs/. GC also gets rid of programs. There are programs you can write in C but not in Lisp, like device drivers that poke specific machine addresses. > /Pure/ functional programming isn't about adding the feature of > functional programming. It's about eliminating other features which > are not functional programming. It seems to me that Haskell does some mumbo-jumbo to be purely functional only in some theoretical sense. In practice, its purity is enforced only in functions with a certain class of type signatures (i.e. most functions). You can write impure code when needed, by adding certain monads to the type signature of your function. The point is Haskell's static type system can then tell exactly which parts of your code are pure and which are impure. If you do something impure in a funciton with the wrong signature, you get a compile time error. You can choose to write in a style that separates pure from impure functional code in a Lisp program, but the compiler can't check it for you. If you get it wrong and call an impure function from your "pure" code (say in a lock-free concurrent program), all kinds of obscure bugs can result, like pointer errors in a C program. From raphael.marvie at gmail.com Fri Dec 15 09:07:48 2006 From: raphael.marvie at gmail.com (raphael.marvie at gmail.com) Date: 15 Dec 2006 06:07:48 -0800 Subject: Problem comparing object graphs and trees In-Reply-To: References: <1166189934.686619.56720@16g2000cwy.googlegroups.com> Message-ID: <1166191668.569306.120010@79g2000cws.googlegroups.com> I am not drunk but should have rtfm. Sorry and Thanks. r. On Dec 15, 3:04 pm, Peter Otten <__pete... at web.de> wrote: > raphael.mar... at gmail.com wrote: > > > > $ cat cmp.py > > > class A: > > def __init__(self, b): > > self.b = b > > def __cmp__(self, other): > > return self.b == other.b > > > class B: > > pass > > > if __name__ == '__main__': > > b = B() > > a1 = A(b) > > a2 = A(b) > > print a1 == a2 > > print a1 == a1 > > > $ python cmp.py > > False > > False > > > > > I swear I am not drunk, but why isn't a1 == a2 and worse why isn't a1 > > == a1? Does someone have a clue and can explain to me this suprising > > behavior? (python 2.4.3 on Ubuntu 6.06).__cmp__() must return 0 for equal objects: > > >>> 1 .__cmp__(0), 1 .__cmp__(1), 1 .__cmp__(2)(1, 0, -1) > > You might have a look at rich comparison before you proceed: > > >>> class A(object):... def __init__(self, b): > ... self.b = b > ... def __eq__(self, other): > ... return self.b == other.b > ...>>> A(1) == A(1) > True > >>> A(1) == A(42)False > > Peter From lepto.python at gmail.com Wed Dec 20 03:35:58 2006 From: lepto.python at gmail.com (oyster) Date: Wed, 20 Dec 2006 16:35:58 +0800 Subject: Any easy-to-use email send module? Message-ID: <6a4f17690612200035g30f78be9j2178fdfa3085671c@mail.gmail.com> I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import easyemail smtpserver=easyemail.server('something') smtpserver.login('usr at gmail.com', pwd) newletter=smtpsever.letter(smtpserver) newletter.sendto=['to1 at 1.com', 'to2 at 2.com'] newletter.sendcc=['cc1 at 111.com', 'cc2 at 222.com'] newletter.sendbcc=['bcc1 at 111.com', 'bcc2 at 222.com'] newletter.body='this is the body\nline 2' newletter.att=['c:/file1.txt', 'd:/program files/app/app.exe'] if (newletter.send()==True): print 'send ok' smtpserver.close() Thanx. From crystalattice at gmail.com Tue Dec 12 23:13:45 2006 From: crystalattice at gmail.com (crystalattice) Date: 12 Dec 2006 20:13:45 -0800 Subject: Tkinter button doesn't appear in OS X In-Reply-To: <1165953879.140827.317120@79g2000cws.googlegroups.com> References: <1165798158.199702.217180@79g2000cws.googlegroups.com> <457CC308.1080801@codebykevin.com> <1165893733.852293.229190@f1g2000cwa.googlegroups.com> <5de3b$457eba18$4275d90a$12544@FUSE.NET> <1165953879.140827.317120@79g2000cws.googlegroups.com> Message-ID: <1165983225.844161.112330@73g2000cwn.googlegroups.com> I downloaded your file and got it working. Thanks for the hint and the code. I really appreciate it. From john106henry at hotmail.com Thu Dec 21 21:05:40 2006 From: john106henry at hotmail.com (John Henry) Date: 21 Dec 2006 18:05:40 -0800 Subject: PythonCard Auto Placement In-Reply-To: References: Message-ID: <1166753140.202420.242450@79g2000cws.googlegroups.com> Brandon McGinty wrote: > Hi All, > I'm getting started with pythoncard. > I'm wondering if there is any way to auto-place the gui elements that I > use, so that they are all visible, and aligned? > I would use the "layout/resource" editors, but I'm blind, so I can't see > where the elements end up, and the controls for moving don't show up as > usable controls in my screen reader. > Any help is appreciated. > > Thanks Much, > Brandon McGinty The first part to your quesion is easy. Pythoncard uses a very simple resource file format (just a plain vanilla Python dictionary) and so one can simply write a Python that outputs the resource file and automate the process. The second part to your question might be harder. Are you saying the Pythoncard controls don't show up as usable controls in your screen reader, or the ones in the resource editor? If it's the latter, you can simply use the method I described and automatically create the resource file. I am very familiar with Pythoncard and don't mind helping if I can but I don't have any experience with screen reader. From address.good.until.2006.dec.22 at justmail.de Mon Dec 11 14:23:54 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Mon, 11 Dec 2006 20:23:54 +0100 Subject: merits of Lisp vs Python In-Reply-To: <457d970b$0$31552$426a74cc@news.free.fr> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> Message-ID: Christophe schrieb: > Andr? Thieme a ?crit : >> You don't even need to say 'function >> (memoize function) would be enough. >> And yes, you can memoize functions while the program is running. >> And you don't need a tool like slime for it. Lisp already offers ways >> for doing that. > > In Python while the program is running : > > import module > module.function = memoize(module.function) Yes, I mentioned that a bit earlier in this thread (not about the "during runtime" thing). I also said that many macros only save some small bits of code. Your python example contains 4 tokens / brain units. The Lisp version only has 2. In the first moment one might want to say: "Hey, just 10-15 more characters to type in Python". But this sums up. If someone *really* thinks this extra typing is not bad, why doesn't this person add some functions like: def foobar(): pass and call them from time to time? If a bit of extra typing is not bad one could call this function each time before one uses the built in * operator. Why not? Andr? -- From kentilton at gmail.com Tue Dec 12 22:12:57 2006 From: kentilton at gmail.com (Ken Tilton) Date: Tue, 12 Dec 2006 22:12:57 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <1165855222.367374.163170@80g2000cwy.googlegroups.com> <1165868422.964826.52840@80g2000cwy.googlegroups.com> <1165873130.318729.298260@j72g2000cwa.googlegroups.com> <1165875324.171765.176660@80g2000cwy.googlegroups.com> Message-ID: <0dKfh.75$nP7.70@newsfe09.lga> Robert Uhl wrote: > "Stephen Eilert" writes: > >>So, let's suppose I now want to learn LISP (I did try, on several >>occasions). What I would like to do would be to replace Python and >>code GUI applications. Yes, those boring business-like applications >>that have to access databases and consume those new-fangled >>web-services and whatnot. Heck, maybe even code games using DirectX. > > > GUIs are a weak point, or were last I looked. LW comes with CAPI, portable across the big 3. ACL has Common Graphics on win32, and I think they have Gtk bindings elsewhere (just guessing, really). Everyone has Ltk, Cells-Gtk, and Celtk. (Two Tks, one Gtk if that is not clear). ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From arkanes at gmail.com Wed Dec 6 14:42:42 2006 From: arkanes at gmail.com (Chris Mellon) Date: Wed, 6 Dec 2006 13:42:42 -0600 Subject: Async callback in python In-Reply-To: <76fd5acf0612042115u62b8f49dq2ba9678257690918@mail.gmail.com> References: <1165292302.454012.118540@n67g2000cwd.googlegroups.com> <76fd5acf0612042115u62b8f49dq2ba9678257690918@mail.gmail.com> Message-ID: <4866bea60612061142nbbf9047h91473b9a81d98e7c@mail.gmail.com> On 12/4/06, Calvin Spealman wrote: > On 4 Dec 2006 20:18:22 -0800, Linan wrote: > > Hi, > > > > In javascript, code could be written like this: > > > > ... > > > > var _p=XMLHttpRequest(); > > _p.open('GET',url,true); > > _p.send(null); > > _p.onreadystateChange=function(){ > > if(_p.readyState==4) > > cb(_p.responseText); > > } > > ... > > > > This basic AJAX code allows function to be called when it's invoked, > > without blocking the main process. There is same library asyncore in > > python. However, I can't validate it's asynchronous through code: > > class T(asyncore.dispatcher): > > def __init__(self,host,url): > > asyncore.dispatcher.__init__(self) > > self.create_socket(socket.AF_INET, socket.SOCK_STREAM) > > self.connect((host,80)) > > self.url='GET %s HTTP/1.0\r\n\r\n' % url > > > > def handle_connect(self): > > pass > > > > def handle_close(self): > > self.close() > > > > def handle_read(self): > > print 'READING.....' > > print self.recv(256) > > > > def handle_write(self): > > sent=self.send(self.url) > > self.url=self.url[sent:] > > > > t=T('aVerySlowSite','/') > > asyncore.loop() > > for i in range(0,10): > > print '%d in main process' % i > > time.sleep(1) > > > > Suppose it's asynchronous, couple of '%d in main process' lines should > > be mixed in the output of T.handle_read(), right? But I found that > > actually main process was blocked at asyncore.loop(), until the the > > socket was closed. My questions: > > 1, Did I do anything wrong? > > 2, Is it real asynchronous? > > 3, If not, where to get the real one(s)? > > > > Any comment is welcome :) > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > You seem to be confusing the terms "asyncronous" and "threaded". > Although multi-threading is a way to implement asyncronous software, > it is not the only or the best way to get those results. Usually the > term "asyncronous" is attached to non-threaded methods, because > "multi-threading" is usually just used for those threaded methods. > > Thus, solutions like asyncore are ways to allow asyncronous code > without threading, and usually this involves a loop, as with asyncore, > and until all the asyncronous operations running in the loop are > complete, the loop does not end. > > If you wanted to have these prints interlaced in the http download, > you might schedule them as a seperate asyncronous operation. > > I hope that helped. > > PS - Another, more complete asyncronous framework is the Twisted > project (http://www.twistedmatrix.com/) > In addition to the above, you misinterpret the way the posted JavaScript works. JavaScript uses a "run to completion" model and, in browsers, is purely event-based. There is no "main process" to block, and if you simulate one via a loop, the code you posted won't work. Except in IE, because it violates the ecmascript standard and will 'call back' from the implementation to the javascript environment without regard for the current state of that environment. From salvatore.difazio at gmail.com Fri Dec 1 15:09:50 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 1 Dec 2006 12:09:50 -0800 Subject: Thread help In-Reply-To: <12n11hf9su7idca@corp.supernews.com> References: <1164999221.679348.221000@16g2000cwy.googlegroups.com> <12n0v9l4ssfd7fc@corp.supernews.com> <1165001388.156041.79030@f1g2000cwa.googlegroups.com> <12n11hf9su7idca@corp.supernews.com> Message-ID: <1165003789.884371.79890@73g2000cwn.googlegroups.com> Grant Edwards ha scritto: > http://docs.python.org/lib/module-threading.html > http://linuxgazette.net/107/pai.html > http://www.wellho.net/solutions/python-python-threads-a-first-example.html > http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf Thank Edward, I didn't find the linuxgazette tutorial before the post. Tnx From beliavsky at aol.com Sun Dec 17 17:17:10 2006 From: beliavsky at aol.com (Beliavsky) Date: 17 Dec 2006 14:17:10 -0800 Subject: first and last index as in matlab In-Reply-To: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> References: <1166379931.054933.77450@j72g2000cwa.googlegroups.com> Message-ID: <1166393830.272016.160560@t46g2000cwa.googlegroups.com> Evan wrote: > In matlab I can do the following: > > >> ind = [3,5,7,2,4,7,8,24] > ind = 3 5 7 2 4 7 8 24 > >> ind(1) ans = 3 > >> ind(end) ans = 24 > >> ind([1 end]) ans = 3 24 > > but I can't get the last line in python: > > In [690]: ind = [3,5,7,2,4,7,8,24] > In [691]: ind[0] Out[691]: 3 > In [692]: ind[-1:] Out[692]: [24] > In [693]: ?? > > How do I pull out multiple indices as in matlab? If you want functionality similar to Matlab in Python, you should use Numpy, which has the "take" function to do what you want. From gagsl-py at yahoo.com.ar Wed Dec 20 22:55:34 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 20 Dec 2006 19:55:34 -0800 Subject: calling a class instance of function In-Reply-To: <87zm9i5cub.fsf@pyenos.pyenos.org> References: <87zm9i5cub.fsf@pyenos.pyenos.org> Message-ID: <1166673334.329403.187020@73g2000cwn.googlegroups.com> On 20 dic, 21:09, Pyenos wrote: > class pid: > "pid" > def add(original_pid,toadd): > "add pid" > original_pid.append(toadd) > return original_pid For a method, you have to include an *explicit* first parameter (usually called "self") that refers to the instance on which you call the method (like "this" on other languages, but you have to be explicit in Python). Read the Python tutorial: http://docs.python.org/tut/ -- Gabriel Genellina From http Fri Dec 15 10:20:55 2006 From: http (Paul Rubin) Date: 15 Dec 2006 07:20:55 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <4582b61c$0$8164$426a74cc@news.free.fr> Message-ID: <7xwt4ttcbs.fsf@ruckus.brouhaha.com> Christophe Cavalaria writes: > def nif(num, pos, zero, neg): > return (zero, pos, neg)[cmp(num, 0)] Owwoooooooooo!!! From grante at visi.com Thu Dec 28 10:17:35 2006 From: grante at visi.com (Grant Edwards) Date: Thu, 28 Dec 2006 15:17:35 -0000 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <4593185f$1@nntp.zianet.com> Message-ID: <12p7o0fcba6mn14@corp.supernews.com> On 2006-12-28, Steven D'Aprano wrote: > I've spent a lot of time reading both sides of the tabs versus spaces > argument, and I haven't found anything yet that explains why tabs are, in > and of themselves, bad. They aren't. Using tabs isn't bad. Using both tabs and spaces is bad, so the people managing the official Python source tree picked one. Maybe they've got reasons for liking spaces over tabs. Maybe they just flipped a coin. It doens't matter. What matters is picking one and sticking with it. -- Grant Edwards grante Yow! YOU'D cry too if it at happened to YOU!! visi.com From michele.simionato at gmail.com Mon Dec 18 05:45:30 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 18 Dec 2006 02:45:30 -0800 Subject: Metaclass uses? In-Reply-To: References: Message-ID: <1166438730.363251.108090@f1g2000cwa.googlegroups.com> Nathan Harmston wrote: > Hi, > > Recently I posted a question about the factory pattern in python. I ve > implemented this following one of the ideas posted. After some reading > I ve seem a lot of Aspect Oriented Programming mentioned but I m not > really sure what it is. > > Can anyone help me understand how metaclasses can improve the quality > of my code and let me do better things. Have you read the two papers in IBMDeveloperWorks about metaclasses? There is also a third one, about avoiding metaclasses, which is waiting for publication. Here is the draft: http://www.phyast.pitt.edu/~micheles/python/classinitializer.html Michele Simionato From at at tuko.nl Wed Dec 13 13:29:48 2006 From: at at tuko.nl (at) Date: Wed, 13 Dec 2006 19:29:48 +0100 Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> Message-ID: <45804699$0$334$e4fe514c@news.xs4all.nl> Forget 'pythonic'. I just need to get work done and I see this type of conditional iteration showing up many times obscuring my code because of the additional indentation. In line with previous syntax improvements made in Python my proposal (or obvious variants) seems a logical next step. Unless of course nobody appreciates it. That's the discussion I'd like to have here in the forum. All the best @ Roberto Bonvallet wrote: > at wrote: >> More pythonic in view would be: >> >> for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0: >> ... more code ... > > Pythonic? Do you realize that Python hasn't even adopted well-known > statements like 'switch' and 'do while' because they would be redundant? > > This could be more convenient to you, but certainly not pythonic. > Cheers, From nmm1 at cus.cam.ac.uk Wed Dec 20 06:31:45 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 20 Dec 2006 11:31:45 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> lrqjl$j4s$1@newwwwwwwwwwwwwwww elrrgs$8p6$1@geeini.csx.cam.ac.... .1166111433.32001.python-list@ppppppppppp 2$a95$1@gemini............... ailman.1607.1166112864.32031.pyyhon-list@pythonnnnnn $1@gemini.csx.cccccccccc <4587506D.50808@cosc.canterbury.ac.nz> <458919DD.40901@cosc.canterbury.ac.nz> Message-ID: In article <458919DD.40901 at cosc.canterbury.ac.nz>, greg writes: |> |> > It does explain why you think of lists as homogeneous, but the |> > analogy doesn't hold water on closer inspection. There doesn't seem |> > to be ANYTHING in the specification or implementation that assumes |> > lists are homogeneous. |> |> Then what do you think is suggested by the fact |> that lists have an index() method but tuples don't? Eh? Nothing relevant to homogeneity, to be sure. See the Library reference, 2.3.3. It starts by saying "Comparison operations are supported by all objects." and the first paragraph after the table says that == is defined to return False for different types (except numeric and string). 2.3.6 (Mutable Sequence Types) says that index returns the smallest value such that == returns True. So index finds a match among compatible types. That is an old specification of searching heterogeneous lists that I have been using for over 30 years - I can't now remember which languages include it. What's the problem? |> That's how this whole discussion got started -- |> someone wanted an explanation of why that is so. |> The explanation is that tuples and lists were |> designed for different use cases. The problem is that the homogeneity argument is irrational (which does NOT necessarily mean either wrong or undesirable), IS NOT DOCUMENTED IN THE REFERENCES, and Python is not generally irrational. My mental model of Guido is that he thinks fairly rationally. Python isn't Perl or C, after all. |> You don't *have* to use them that way, but if |> you use them differently, you're on your own |> and can't complain if they don't have all the |> features you want. Which is tantamount to saying that Python doesn't support mutable heterogeneous sequences, even though they are not locked out. That is more than just odd - it is almost unbelievable. They are a very basic data structure, after all! Regards, Nick Maclaren, University of Cambridge Computing Service, New Museums Site, Pembroke Street, Cambridge CB2 3QH, England. Email: nmm1 at cam.ac.uk Tel.: +44 1223 334761 Fax: +44 1223 334679 From sjmachin at lexicon.net Tue Dec 5 06:34:49 2006 From: sjmachin at lexicon.net (John Machin) Date: 5 Dec 2006 03:34:49 -0800 Subject: win32 com problem In-Reply-To: <1165317133.730386.193290@l12g2000cwl.googlegroups.com> References: <1165316228.944095.116310@79g2000cws.googlegroups.com> <1165316825.234187.322900@73g2000cwn.googlegroups.com> <1165317133.730386.193290@l12g2000cwl.googlegroups.com> Message-ID: <1165318486.142658.248590@f1g2000cwa.googlegroups.com> Mike P wrote: > Thanks for the quick reply, > > the code i am running is the following > > import win32com.client > xl = win32com.client.Dispatch("Excel.Application") > ppt = win32com.client.Dispatch("PowerPoint.Application") > ppt.Visible = 1 #open MS Powerpoint > xl.Visible = 1 #open MS Excel > xl.Workbooks.Open('%s/working_output.xls' % (working_dir)) > xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic > files\\CTP.xla') Does this file contain a sheet named "sheet1"? Maybe it should be "Sheet1"; I can never remember what is case-sensitive and what's not :-) If so, does that sheet contain a macro called "CTP"? > ppt.Presentations.Open('Z:\\projects\\surveys\\SPSS - Generic > files\\Basic Template.ppt') > xl.Application.Workbooks("working_output").Activate > xl.Application.Run("CTP.xla!sheet1.CTP") See above questions. > > I'm running via SPSS V15 which has a python plugin, i was previousky > running in V14 using the exact same code with no problems? Have you asked SPSS about the CTP.xla file (which I guess is supplied by them)? Don't expect so fast a response this time -- it's sleep time in this timezone :-) Cheers, John From gmkrishn.uofc at gmail.com Thu Dec 7 13:21:32 2006 From: gmkrishn.uofc at gmail.com (Murali) Date: 7 Dec 2006 10:21:32 -0800 Subject: how to delete matplotlib data between ploting In-Reply-To: <1165512954.226086.125080@j44g2000cwa.googlegroups.com> References: <1165512954.226086.125080@j44g2000cwa.googlegroups.com> Message-ID: <1165515692.909028.285360@79g2000cws.googlegroups.com> pylab.clf() or some such thing clears the current canvas. riklaunim at gmail.com wrote: > I want to make few plots from CSV files. I have the code below - it > works - the first plot is ok, the second one has the first and the > current data set and so on - I can't delete the plot data between > plots. > ########################################## > # -*- coding: utf-8 -*- > from pylab import * > from os import listdir > > i = listdir('dane/') > > # list folders with CSV files > for di in i: > # list files in folders > csv = listdir('dane/' + di + '/') > for datafile in csv: > # open each CSV file > file = open('dane/' + di + '/' + datafile, 'r').readlines() > x = [] > y = [] > # get the data > for row in file: > if row.find(',') != -1: > r = row.split(',') > if len(r[0]) > 0 and len(r[1]) > 0: > x.append(float(r[0])) > y.append(float(r[1])) > xlabel('czas') > ylabel('Moc') > title(di.replace('.', ' ')) > #plot > plot(x, y) > savefig('dane/' + di + '/' + datafile + '.png') > del x > del y > del file From kirk at nospam.jobsluder.net Sat Dec 9 15:45:49 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sat, 09 Dec 2006 20:45:49 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> Message-ID: In article <1165689545.676886.289150 at j44g2000cwa.googlegroups.com>, "mystilleef" wrote: > 1). More and better mature standard libraries (Languages don't matter, > libraries do). .... > On Lisp Macros: > > I think they are overrated, and in general cause more harm than good. > It's the reason I find Lisp-like programs difficult to grok, maintain > and extend. Cos every smart ass wants to needlessly write his own mini > language to the point of absolute obfuscation. Naturally, I'm supposed > to be awed by his mischievous cleverness. I've not seen a convincing explanation as to why imported macros from some library are so much more evil than imported functions. In both cases one might have to dig into documentation and/or comments to understand exactly what that imported snippit is doing. From olanglois at quazal.com Tue Dec 5 15:16:30 2006 From: olanglois at quazal.com (Olivier Langlois) Date: Tue, 5 Dec 2006 15:16:30 -0500 Subject: About the 79 character line recommendation In-Reply-To: <1165348808.807516.201860@j72g2000cwa.googlegroups.com> Message-ID: <400BDC416E2A0042AA35DF3919BB8A516399C3@mail.mtl.proksim.com> Hi, There was a coding standard where I worked and the intention behind this requirement was to make the code printer friendly. Printing code source with lines longer than 80 chars greatly hinder readability on paper. Greetings, Olivier Langlois http://www.olivierlanglois.net > > I also think that limiting code to 80 columns often hinders > readability. I personally try to limit my code to 100 columns. The end > result is pretty nice. > > However, I'm all for the "flat is better than nested" philosophy, even > when nested is under 100 columns. > > -- > http://mail.python.org/mailman/listinfo/python-list From andrew-newspost at areilly.bpc-users.org Tue Dec 12 00:28:02 2006 From: andrew-newspost at areilly.bpc-users.org (Andrew Reilly) Date: 12 Dec 2006 05:28:02 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> Message-ID: <4u6sv2F16p8fdU2@mid.individual.net> On Tue, 12 Dec 2006 16:35:48 +1300, greg wrote: > When a Lisp compiler sees > > (setq c (+ a b)) > > it can reasonably infer that the + is the built-in numeric > addition operator. But a Python compiler seeing > > c = a + b > > can't tell *anything* about what the + means without > knowing the types of a and b. They might be numbers, or > strings, or lists, or some user-defined class with its > own definition of addition. That may be true, but lisp's numeric addition operator knows how to add fixnums, bignums, rationals and whatever the lisp name for floating points is (imprecise?) -- something that not many (if any) processor instruction sets can manage. So that's still type-dependent dispatch, which isn't going to get us to the speeds that we actually see reported unless there's extra stuff going on. Type inference? Declarations? Cheers, -- Andrew From mt_nich at yahoo.com Wed Dec 20 12:37:10 2006 From: mt_nich at yahoo.com (mdmdmd) Date: Wed, 20 Dec 2006 10:37:10 -0700 Subject: tkFileDialog closes main application Message-ID: <3qadnUMGb7pa6RTYnZ2dnUVZ_tyinZ2d@comcast.com> Hello, I wish to collect 4 files from a user. So I have decided to use tkFileDialog askopenfilename. My problem is that after a few file selections the root window is destroyed (the whole program just dissappears) I have created a simple example and was able to reproduce the same thing with this. I've just started using tkinter so I have no idea what I may be doing wrong. If anyone has any ideas please let me know. If you run the following code, just click the Browse button, and select a file. Do this repeatedly and for me after the sixth or seventh time the window shuts down. BTW, I'm using python 2.4 on Windows XP. Thank you for any help. ################################################################################ from Tkinter import * import Pmw import tkFileDialog import os.path filepath = 'C:\\Documents and Settings\\admin\\Desktop\\' class App(Frame): def __init__(self,master): Frame.__init__(self, master, bg='gray') self.enttxt = StringVar() lbl = Label(self,text='File 1:') lbl.grid(row = 0,column = 0,sticky = W,padx = 5,pady = 5) self.e1 = Entry(self,textvariable = self.enttxt,width = 50) self.e1.grid(row = 0,column = 1,columnspan = 3,sticky = W,padx = 5,pady = 5) btn = Button(self,text='Browse ...',width = 12, command = self.browse) btn.grid(row = 0,column = 4,sticky=W,padx=5,pady=5) def browse(self): fileformats = [('Text File ','*.csv'), ('All Files ','*.*')] retval = tkFileDialog.askopenfilename(title='Choose File', initialdir=filepath, filetypes=fileformats, parent = self) if retval: self.enttxt.set(os.path.abspath(retval)) def main(): root = Tk() root.withdraw() root.title('test') root.configure(bg='gray') app = App(root) app.pack() root.update() root.deiconify() root.mainloop() if __name__ == '__main__': main() From http Sun Dec 10 04:29:17 2006 From: http (Paul Rubin) Date: 10 Dec 2006 01:29:17 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <457bb4cf$0$8756$ed2619ec@ptn-nntp-reader02.plus.net> <7xbqmcgola.fsf@ruckus.brouhaha.com> <457bcc7e$0$8739$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <7x64ckrtea.fsf@ruckus.brouhaha.com> Jon Harrop writes: > > Nothing stops you from re-using the same internal function name in > > your Python code, like you might use "i" as a throwaway loop index in > > several places in the same function. It's just like in Scheme... > > It is not "just like in Scheme" if you don't have anonymous functions in > Python. Python has anonymous functions (what they can do is somewhat limited by syntax) but the similarity mentioned with Scheme was about the data objects. Anyway you don't need to pollute the namespace with lots of (i.e. more than one) different temporary function name even if you use non-anonymous functions. From greg at cosc.canterbury.ac.nz Fri Dec 15 06:18:52 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:18:52 +1300 Subject: CLPython (was Re: merits of Lisp vs Python) In-Reply-To: <1166122900.477201.316320@73g2000cwn.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> <7xejr5y755.fsf@ruckus.brouhaha.com> <1166038096.200379.286830@80g2000cwy.googlegroups.com> <1166048301.513012.245480@73g2000cwn.googlegroups.com> <1166122900.477201.316320@73g2000cwn.googlegroups.com> Message-ID: <4ufenpF17of60U8@mid.individual.net> Willem Broekema wrote: > I guess in part it's because there are not that many people really into > both Python and Lisp, and those who are might not find this an > interesting project because there is nothing "wow" to show, yet. Another reason (or maybe the reason for the reason) is that people are usually interested in Python because it's a relatively simple and lightweight thing. Having to install a complex and heavyweight thing like a Common Lisp system just to be able to program in Python doesn't seem like a good deal. It might become a good deal if you could then compile the Lisp and get a lean, efficient binary executable out of it. But that's going to require much more than just a straightforward translation from Python to Lisp. If CLPython starts to show signs of making progress in that direction, then it could start to get interesting. Although I think I'd rather target Scheme than CL if I were doing it -- cleaner language, small yet still extremely good implementations available. -- Greg From dkinakin at gmail.com Sun Dec 31 03:11:11 2006 From: dkinakin at gmail.com (dkinakin at gmail.com) Date: 31 Dec 2006 00:11:11 -0800 Subject: Progress Box or Bar in Windows In-Reply-To: References: Message-ID: <1167552671.006087.150720@k21g2000cwa.googlegroups.com> Not that I want to suggest a completely different solution; however, I have used: http://www.averdevelopment.com/python/EasyDialogs.html to add simple file open dialogs, message boxes, and progress bars to many of my scripts. You may want to have a look at it. It's easy to install and really simple to use. tubby wrote: > Hi guys, > > I have a Python script that I've prettied-up for Windows users by adding > things like shell.SHBrowseForFolder and win32gui.MessageBox, etc. In > short, it looks like this: > > 1. Pretty window where user can browse for folder. (instead of typing > path into cmd prompt) > > 2. win32gui.MessageBox informing user the script will now begin. > > 3. > > 4. win32gui.MessageBox informing user the script has finished. > > I left 3 blank. This is where I'd like to use some sort of progress > indicator (a box that says 'processing 3 of 30 files... 4 of 30, etc' or > a progress bar that moves across the screen as the script does its job. > Any ideas on how to do this quickly and easily (less than 20 lines of code)? > > I'd prefer to stick with the win32 extensions, but I'd be willing to use > TK too if that would be simpler... and it looks like TK would be much > simpler :) > > Thanks! From gagsl-py at yahoo.com.ar Thu Dec 21 21:52:42 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 21 Dec 2006 23:52:42 -0300 Subject: removing the header from a gzip'd string In-Reply-To: References: <1166735512.435837.60080@42g2000cwt.googlegroups.com> Message-ID: <7.0.1.0.0.20061221231422.03e796e0@yahoo.com.ar> At Thursday 21/12/2006 18:32, Fredrik Lundh wrote: > > Hi, I have some code that takes a string and obtains a compressed > > version using zlib.compress > > > > Does anybody know how I can remove the header portion of the compressed > > bytes, such that I only have the compressed data remaining? > >what makes you think there's a "header portion" in the data you get >from zlib.compress ? it's just a continuous stream of bits, all of >which are needed by the decoder. No. The first 2 bytes (or more if using a preset dictionary) are header information. The last 4 bytes are for checksum. In-between lies the encoded bit stream. Using the default options ("deflate", default compression level, no custom dictionary) will make those first two bytes 0x78 0x9c. If you want to encrypt a compressed text, you must remove redundant information first. Knowing part of the clear message is a security hole. Using an structured container (like a zip/rar/... file) gets worse because the fixed (or "guessable") part is longer, but anyway, 2 bytes may be bad enough. See RFC1950 -- 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 From fuzzyman at gmail.com Sat Dec 23 16:55:04 2006 From: fuzzyman at gmail.com (Fuzzyman) Date: 23 Dec 2006 13:55:04 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1166909742.176850.233910@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1166906310.452197.185700@48g2000cwx.googlegroups.com> <1166909742.176850.233910@80g2000cwy.googlegroups.com> Message-ID: <1166910904.680412.110090@a3g2000cwd.googlegroups.com> defcon8 wrote: > All of you are nazis! Hmmm... that might work. :-) Fuzzyman http://www.voidspace.org.uk/python/articles.shtml From g.brandl-nospam at gmx.net Thu Dec 21 03:20:58 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Thu, 21 Dec 2006 09:20:58 +0100 Subject: list1.append(list2) returns None In-Reply-To: <87irg5ek9m.fsf@pyenos.pyenos.org> References: <87mz5hexf7.fsf@pyenos.pyenos.org> <1166672931.481388.121730@f1g2000cwa.googlegroups.com> <87irg5ek9m.fsf@pyenos.pyenos.org> Message-ID: Pyenos schrieb: > i rewrote the code following the advices from subdir of the parent thread: > > # well, table is composed of a list of columns. > # so let's stick them together > def enlargetable(table,col): > table.append(col) # the code won't return sorted lists :-o Why should it sort the list? > return_the_fucking_table_bitch=table # assign it to a new variable to return it > return return_the_fucking_table_bitch # :-| That isn't necessary. A simple "return table" is fine. > > def removecolfromtable(table,col): > return table.remove(col) table.remove() also returns None. > print enlargetable([[1],[2],[3]],[4]) > > # and this code works. Georg From horpner at yahoo.com Mon Dec 4 12:56:02 2006 From: horpner at yahoo.com (Neil Cerutti) Date: 4 Dec 2006 18:56:02 +0100 Subject: Execution time of lines within a function References: <1165240166.203915.115460@n67g2000cwd.googlegroups.com> <1165249456.148956.217940@n67g2000cwd.googlegroups.com> Message-ID: On 2006-12-04, monkeyboy wrote: > Thanks Neil, > > I looked at that, but maybe I don't understand the output. I > was hoping to see the cummulative time for the function and > then the time associated with each statement (line) within the > function. > > Any suggestions? I don't think the Python Profiler goes down to that level. The next step might be to analyze the function yourself and try to understand why it is so slow. Post the code here and let the readers pick it apart. > In the hotshot output below, I can see the function being > called 100 times, which is correct, but the rest seems at too > low a level for me to understand which statements are causing > the slow execution. > > hw6r3.py:276(main) hw6r3.py:73(findw)(100) 26700.865 Is this the print_callees output? -- Neil Cerutti From kkylheku at gmail.com Sun Dec 17 03:03:26 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 17 Dec 2006 00:03:26 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xac1nfmyb.fsf@ruckus.brouhaha.com> References: <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> Message-ID: <1166342606.141406.137000@f1g2000cwa.googlegroups.com> Paul Rubin wrote: > Raffael Cavallaro writes: > > For example, a common lisp with optional static typing on demand would > > be strictly more expressive than common lisp. But, take say, haskell; > > haskell's static typing is not optional (you can work around it, but > > you have to go out of your way to do so); haskell's pure functional > > semantics are not optional (again, workarounds possible to a limited > > extent). This requires you to conceive your problem solution (i.e., > > program) within the framework of a particular paradigm. This lock-in > > to a particular paradigm, however powerful, is what makes any such > > language strictly less expressive than one with syntactic abstraction > > over a uniform syntax. > > Incorrect, I believe. The above is like saying Lisp's lack of > optional manual storage allocation and machine pointers makes Lisp > less powerful. That is true. By itself, that feature makes Lisp less poweful for real-world software dev, which is why we have implementation-defined escape hatches for that sort of thing. > It's in fact the absence of those features that lets > garbage collection work reliably. This is a bad analogy to the bondage-and-discipline of purely functional languages. The removal for the need for manual object lifetime computation does not cause a whole class of useful programs to be rejected. In fact, all previously correct programs continue to work as before, and in addition, some hitherto incorrect programs become correct. That's an increase in power: new programs are possible without losing the old ones. Wheas programs can't be made to conform to the pure functional paradigm by adjusting the semantics of some API function. Programs which don't conform have to be rejected, > Reliable GC gets rid of a large and > important class of program errors and makes possible programming in a > style that relies on it. Right. GC gets rid of /program errors/. Pure functional programming gets rid of /programs/. > You can make languages more powerful by removing features as well as by adding them. Note that changing the storage liberation request from an imperative to a hint isn't the removal of a feature. It's the /addition/ of a feature. The new feature is that objects can still be reliably used after the implementation was advised by the program that they are no longer needed. Programs which do this are no longer buggy. Another new feature is that programs can fail to advise the implementation that some objects are no longer needed, without causing a leak, so these programs are no longer buggy. The pool of non-buggy programs has increased without anything being rejected. Okay, that is not quite true, which brings me back to my very first point. GC does (effectively) reject programs which do nasty things with pointers. For instance, hiding pointers from being visible to GC. However, such things can be made to coexist with GC. GC and non-GC stuff /can/ and does, for pragmatic reasons, live in the same image. Likewise, functional programming and imperative programming can also coexist in the same image. /Pure/ functional programming isn't about adding the feature of functional programming. It's about eliminating other features which are not functional programming. From david.golden at oceanfree.net Sat Dec 9 11:36:07 2006 From: david.golden at oceanfree.net (David Golden) Date: Sat, 09 Dec 2006 16:36:07 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <7xodqd9ox2.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Forth was always unreadable to me but I never did much. I thought its > aficionados were silly. Yes if you have a complicated math expression > in Lisp, you have to sit there for a moment rearranging it in infix in > your mind to figure out what it says. The point is that such > expressions aren't all that common in typical Lisp code. > I find Lisp, Forth and classic funny-symbol APL relatively readable (well, once you've learned the funny symbols in the APL case) That spans prefix/postfix/infix... The commonality is simple evaluation order, no damn precedence rules. I can _cope_ with precedence rules, I'm not a moron, but I prefer languages that don't make heavy use of them. Well, more accurately, sources that don't, but most coders in communities of languages-with-lots-of-precedence-rules consider reliance on those precedence rules in source code idiomatic. And precedence rules, once you get beyond a few (sometimes rather misleading) similarities to the ones that most people are made to learn early on for arithmetic notation, can vary a lot from computer language to computer language. From apotheos at gmail.com Fri Dec 8 11:26:08 2006 From: apotheos at gmail.com (apotheos at gmail.com) Date: 8 Dec 2006 08:26:08 -0800 Subject: Text Encoding - Like Wrestling Oiled Pigs Message-ID: <1165595168.337197.235040@80g2000cwy.googlegroups.com> So I've got a problem. I've got a database of information that is encoded in Windows/CP1252. What I want to do is dump this to a UTF-8 encoded text file (a RSS feed). While the overall problem seems to be related to the conversion, the only error I'm getting is a "UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 163: ordinal not in range(128)" So somewhere I'm missing an implicit conversion to ASCII which is completely aggrivating my brain. So, what fundamental issue am I completely overlooking? Code follows. def GenerateNoticeRSS(): output = codecs.open(FILEBASE + 'noticeboard.xml','w','utf-8') conn = psycopg.connect(DSN) curs = conn.cursor() sql_query = "select story.subject as subject, story.content as content, story.summary as summary, story.sid as sid, posts.bid as board, posts.date_to_publish as date from story$ curs.execute(sql_query) rows = curs.fetchall() output.write('\n') output.write('\n') output.write('\n') output.write('U of L Notice Board\n') output.write('http://www.uleth.ca/notice\n') output.write('University of Lethbridge News and Events\n') for each in rows: output.write('\n') output.write('' + rssTitlePrefix(each[4]) + unicode(each[0]) + '\n') output.write('http://www.uleth.ca/notice/display.html?b=' + str(each[4]) + '&s=' + str(each[3]) + '\n') output.write('http://www.uleth.ca/notice/display.html?b=' + str(each[4]) + '&s=' + str(each[3]) + '\n') descript = each[2] + '

' + each[1] output.write(u'' + unicode(descript) + u'\n') # this is the line that causes the error. output.write('
\n') output.write('
\n') output.write('
\n') output.close() return 0 From noway at ask.me Wed Dec 20 05:41:39 2006 From: noway at ask.me (Giovanni Bajo) Date: Wed, 20 Dec 2006 11:41:39 +0100 Subject: [ANN] PyInstaller 1.3 released Message-ID: Hello, PyInstaller 1.3 is out! Grab latest version at: http://pyinstaller.python-hosting.com/ Description ----------- PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux and Irix. Its main advantages over similar tools are that PyInstaller works with any version of Python since 1.5, it builds smaller executables thanks to transparent compression, it is multi-platform (so you can build one-file binaries also under Linux), and use the OS support to load the dynamic libraries, thus ensuring full compatibility. Features -------- * Packaging of Python programs into standard executables, that work on computers without Python installed. * Multiplatform: works under Windows, Linux and Irix. (Mac port in development. See /branches/mac on SVN) * Multiversion: works under any version of Python since 1.5. * Dual packaging mode: o Single directory: build a directory containing an executable plus all the external binary modules (.dll, .pyd, .so) used by the program. o Single file: build a single executable file, totally self-contained, which runs without any external dependency. * Support for automatic binary packing through the well-known UPX compressor. * Optional console mode (see standard output and standard error at runtime). * Selectable executable icon (Windows only). * Fully configurable version resource section in executable (Windows only). * Support for building COM servers (Windows only). ChangeLog --------- + Fix bug with user-provided icons disappearing from built executables when these were compressed with UPX. + Fix problems with packaging of applications using PIL (that was broken because of a bug in Python's import machinery, in recent Python versions). Also add a workaround including Tcl/Tk with PIL unless ImageTk is imported. + (Windows) When used under Windows XP, packaged programs now have the correct look & feel and follow user's themes (thanks to the manifest file being linked within the generated executable). This is especially useful for applications using wxPython. + Fix a buffer overrun in the bootloader (which could lead to a crash) when the built executable is run from within a deep directory (more than 70-80 characters in the pathname). * Bootstrap modules are now compressed in the executable (so that they are not visible in plaintext by just looking at it with a hex editor). * Fixed a regression introduced in 1.1: under Linux, the bootloader does not depend on libpythonX.X.so anymore. We've moved ----------- PyInstaller has a new home: http://pyinstaller.python-hosting.com/ (thanks to the guys at webfaction.com for top-notch free hosting!) We also own a domain name (http://pyinstaller.org) which can be used as a permanent redirector to our home. The mailing list moved as well, it's now at http://groups.google.com/group/PyInstaller. Join us for discussion! -- Giovanni Bajo From tactics40 at gmail.com Fri Dec 29 10:25:09 2006 From: tactics40 at gmail.com (tac-tics) Date: 29 Dec 2006 07:25:09 -0800 Subject: Slowdown in Jython In-Reply-To: <4595145B.1090803@kentsjohnson.com> References: <1167322474.724142.210440@a3g2000cwd.googlegroups.com> <4595145B.1090803@kentsjohnson.com> Message-ID: <1167405909.600808.135370@h40g2000cwb.googlegroups.com> > Jython is a Java application That was the intellectual leap I needed to solve the problem. I forgot that I have total access to Java memory management. It turns out at the point of slowdown, Java was continually running full GC, causing the awful loss of performance. I figured out that I was not releasing a very large chunk of memory right before the script, so I effectively had a duplicate of every record in memory. I'm still not sure why my memory usage is increasing during the script, but with the removal of the duplicates in memory, it runs just fine now. Problem solved for now. From ahaas at airmail.net Wed Dec 20 11:38:32 2006 From: ahaas at airmail.net (Art Haas) Date: Wed, 20 Dec 2006 10:38:32 -0600 Subject: [ANNOUNCE] Thirty-fifth release of PythonCAD now available Message-ID: <20061220163832.GC15224@artsapartment.org> Hi. I'm pleased to announce the thirty-fifth development release of PythonCAD, a CAD package for open-source software users. As the name implies, PythonCAD is written entirely in Python. The goal of this project is to create a fully scriptable drafting program that will match and eventually exceed features found in commercial CAD software. PythonCAD is released under the GNU Public License (GPL). PythonCAD requires Python 2.2 or newer. The interface is GTK 2.0 based, and uses the PyGTK module for interfacing to GTK. The design of PythonCAD is built around the idea of separating the interface from the back end as much as possible. By doing this, it is hoped that both GNOME and KDE interfaces can be added to PythonCAD through usage of the appropriate Python module. Addition of other PythonCAD interfaces will depend on the availability of a Python module for that particular interface and developer interest and action. The thirty-fifth release contains several improvements dealing with the storage and adjustment of user preferences and image settings. The global user preferences are now saved into a file kept in the user home directory, so the settings are now preserved between PythonCAD sessions. Individual drawing settings can be examined and adjusted via a new set of menus and dialogs. These new dialogs are more complete than the single dialog previously used as well as easier to use. In addition to the preference and setting changes, a variety of bug fixes and miscellaneous code improvements are also present in this new release. A mailing list for the development and use of PythonCAD is available. Visit the following page for information about subscribing and viewing the mailing list archive: http://mail.python.org/mailman/listinfo/pythoncad Visit the PythonCAD web site for more information about what PythonCAD does and aims to be: http://www.pythoncad.org/ Come and join me in developing PythonCAD into a world class drafting program! Art Haas -- Man once surrendering his reason, has no remaining guard against absurdities the most monstrous, and like a ship without rudder, is the sport of every wind. -Thomas Jefferson to James Smith, 1822 From anders.u.persson at gmail.com Fri Dec 1 07:13:47 2006 From: anders.u.persson at gmail.com (anders) Date: 1 Dec 2006 04:13:47 -0800 Subject: How to read the directory which the actively running python file is located in? In-Reply-To: References: Message-ID: <1164975227.723029.52250@80g2000cwy.googlegroups.com> in os module there is many funktion/methods to extract this information to ask the path to the current running pythonprogram you can do likes this ----- CUT----------- import os print os.getcwd() ----- CUT ------ // Anders Michael Malinowski skrev: > Is there a way to read the directory that the currently running python file > is located in? > Cheers > Mike. From nagle at animats.com Tue Dec 26 16:36:14 2006 From: nagle at animats.com (John Nagle) Date: Tue, 26 Dec 2006 13:36:14 -0800 Subject: BeautifulSoup bug when ">>>" found in attribute value Message-ID: This, which is from a real web site, went into BeautifulSoup: And this came out, via prettify: >>&linkurl;=/Europe/Spain/Madrid/Apartments/Offer/2408" /> BeautifulSoup seems to have become confused by the ">>>" within a quoted attribute value. It first parsed it right, but then stuck in an extra, totally bogus line. Note the entity "&linkurl;", which appears nowhere in the original. It looks like code to handle a missing quote mark did the wrong thing. John Nagle From jonc at icicled.net Sun Dec 10 14:28:44 2006 From: jonc at icicled.net (Jonathan Curran) Date: Sun, 10 Dec 2006 13:28:44 -0600 Subject: need guidance on sending emails with attachment with python. In-Reply-To: References: Message-ID: <200612101328.44156.jonc@icicled.net> 1. you will need an accessible smtp server 2. use google, its a great search engine. 3. search a little before trying to get someone to spoon feed you the answers You will be surprised when you use Google to search for 'python email attachment' Sorry for being so blunt/rude/whatever you want to call it. - Jonathan From fsenkel at lynx.neu.edu Mon Dec 4 11:24:16 2006 From: fsenkel at lynx.neu.edu (monkeyboy) Date: 4 Dec 2006 08:24:16 -0800 Subject: Execution time of lines within a function In-Reply-To: References: <1165240166.203915.115460@n67g2000cwd.googlegroups.com> Message-ID: <1165249456.148956.217940@n67g2000cwd.googlegroups.com> Thanks Neil, I looked at that, but maybe I don't understand the output. I was hoping to see the cummulative time for the function and then the time associated with each statement (line) within the function. In the hotshot output below, I can see the function being called 100 times, which is correct, but the rest seems at too low a level for me to understand which statements are causing the slow execution. Any suggestions? hw6r3.py:276(main) hw6r3.py:73(findw)(100) 26700.865 hw6r3.py:126(findphi)(100) 6153.585 hw6r3.py:173(findu)(100) 1823.852 hw6r3.py:197(findv)(100) 2392.977 numeric.py:31(zeros_like)(3) 0.072 numeric.py:286(array_str)(1) 0.677 rpc.py:545(__getattr__)(13) 0.197 rpc.py:589(__call__)(12) 51.334 rpc.py:319(putmessage) :1(fileno)(12) 0.039 rpc.py:149(debug)(12) 0.126 rpc.py:236(asyncreturn) rpc.py:149(debug)(24) 0.126 rpc.py:242(decoderesponse)(12) 0.015 rpc.py:277(getresponse)(12) 48.166 Regards, Frank Neil Cerutti wrote: > On 2006-12-04, monkeyboy wrote: > > I have a function that hotshot says is very slow. I can get the > > aggregate execution time, but is there a way to get the > > execution time of each line so I can find the bottleneck? > > Try 'print_callees' on the stats object for your bottleneck. That > may help. > > -- > Neil Cerutti From evanmason at gmail.com Thu Dec 14 06:21:33 2006 From: evanmason at gmail.com (Evan) Date: 14 Dec 2006 03:21:33 -0800 Subject: remove matching pairs Message-ID: <1166095293.445275.64850@73g2000cwn.googlegroups.com> Is there a simple way to to identify and remove matching pairs from 2 lists? For example: I have a=[2, 5, 3, 4, 7, 2, 2, 4, 8, 1] b=[7, 3, 5, 8, 1, 7, 4, 8, 2, 6] and I want to get this: a=[2, 5, 3, 4, 7, 2, 8, 1] b=[7, 3, 5, 8, 1, 4, 2, 6] There are recurring pairs of (2, 7) and (4, 8), and so I want to remove one of each pair. Many thanks, Evan From luis at geodynamics.org Tue Dec 26 06:21:57 2006 From: luis at geodynamics.org (Luis Armendariz) Date: Tue, 26 Dec 2006 03:21:57 -0800 Subject: How to depress the output of an external module ? In-Reply-To: References: Message-ID: <20061226112157.GA2244@geodynamics.org> On Tuesday, 26.12.06 at 21:28, Steven D'Aprano wrote: > > # WARNING: untested > def run_without_stdout(*args, **kwargs): > function = args[0] > args = args[1:] > savestdout = sys.stdout > sys.stdout = cStringIO.StringIO() > result = None > try: > result = function(*args, **kwargs) > finally: > # don't forget to restore stdout, or you > # really will regret it... > sys.stdout = savestdout > return result > There's no need for savestdout. There's a backup copy in sys.__stdout__ -Luis From xah at xahlee.org Fri Dec 22 20:08:03 2006 From: xah at xahlee.org (Xah Lee) Date: 22 Dec 2006 17:08:03 -0800 Subject: Xah's Edu Corner: Introduction to 3D Graphics Programing Message-ID: <1166836083.084101.25870@73g2000cwn.googlegroups.com> Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet utilities that allows you to view them with live rotation in a web browser. Also, it includes a introductory tutorial to POV-Ray. Once you understand any one of these pages, you can use your favorite programing language to start doing 3D Graphics Programing. In the coming months, i will also introduce the .obj format that are used by many geometric modeling programs. And, a tutorial on how to use Python (or Perl, lisp) to do 3D Graphics programing, by setting up functions that spits out any of 3D-Geometry Formats (such as Mathematica Graphics or POV-Ray or .inc). These are the imminent plans for the coming weeks. Other potential subjects are introduction or tutorials on various utilities or programing lang libraries that does conversion between different 3D graphics formats, dedicated tutorial on how to generate mathematical surfaces, more elaborate study on POV-Ray's abilities and sample cases, etc. The focus of these pages, will be 3D-Graphics programing with the goal of Algorithmic Mathematical Art. (see http://xahlee.org/Periodic_dosage_dir/t1/20040113_cmaci_larcu.html ) In particular, we focus on creating geometric objects and their arrangement that are esthetic in a mathematical way. (for example, regular tilings in 3D, nested structures in 3D, symmetric structures in 3D, elaborate 3D maze tunnels, beehive sculpting, regular polyhedrons and their decorations, projection and slices of higher dimensional symmetries, 3D-manifolds ... etc.) This mathematical esthetic is opposed to, for example, rendering techniques or technologies (e.g. fogs, sceneries, fast algorithms...etc) that are quite common in computer graphics literatures. Xah xah at xahlee.org ? http://xahlee.org/ From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Wed Dec 6 11:19:24 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Wed, 06 Dec 2006 17:19:24 +0100 Subject: len() and PEP 3000 References: <4tnqlkF13bbqeU1@mid.individual.net> <4to00aF14cki5U2@mid.individual.net> <1165416241.852026.325820@j44g2000cwa.googlegroups.com> Message-ID: <4to8scF157i8fU2@mid.individual.net> Kay Schluehr wrote: > Pro: Because it makes the API more monotonous and more aligned > with all other OO languages that exist now and in future. It also > helps any written and unwritten IDE providing a method by means of > autocompletion. It ends endless debates with Java/C++/C# etc. and > newbie Python programmers about this minor issue. Contra: It makes the API more aligned with some other OO languages and moves the focus from "the python way" to "the way it's always been done". Regards, Bj?rn -- BOFH excuse #308: CD-ROM server needs recalibration From Dennis.Benzinger at gmx.net Sun Dec 17 14:24:16 2006 From: Dennis.Benzinger at gmx.net (Dennis Benzinger) Date: Sun, 17 Dec 2006 20:24:16 +0100 Subject: url filtering References: Message-ID: <20061217202416.624efe0b@dennis-laptop> Am Sun, 17 Dec 2006 20:14:32 +0100 schrieb vertigo : > Hello > > I want to do some text analysis based on html documents grabbed from > internet. > Is there any library which could allow me easily getting text from > html documents > (cutting javascript, html tags and other not nececary data) ? > > Thanx Try Beautiful Soup: http://www.crummy.com/software/BeautifulSoup/ Dennis From xscottg at gmail.com Fri Dec 15 04:43:24 2006 From: xscottg at gmail.com (xscottg at gmail.com) Date: 15 Dec 2006 01:43:24 -0800 Subject: merits of Lisp vs Python References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> Message-ID: <1166175804.202131.54070@l12g2000cwl.googlegroups.com> Ken Tilton wrote: > Andrew Reilly wrote: > > > That all looks like data. > > No, not reverse, the part you did not understand. I do not mean what the > code was doing, I meant that it was code. > Code is data is code - even in Python: skills_table = [ { "title": "Absolute Value", "annotations": ["Bleah bleah", "ho hum", "etc..."], "hints": ["and so on", "etc..."], "reverse" : (lambda x: whatever(x)) }, { "title": "Square Root", "annotations": ["Bleah bleah", "ho hum", "etc..."], "hints": ["and so on", "etc..."], "reverse" : (lambda x: someother(x)) }, # etc... ] Of course those lambdas are crippled in Python (and not really necessary in this bogus example)... But that's without trying to be clever: class AbsoluteValue: title="Absolute Value" annotations=["Some list", "goes here"] @classmethod def reverse(cls, *args): # I didn't understand what your code was doing pass defskill(AbsoluteValue) That would be a reasonable place for a "pie decorator" on a class, but I guess that's not allowed. I doubt this second example would be considered "Pythonic" in any case... > > Couldn't you do that with a table > > containing those fields, and key it off the defskill argument (or even the > > title?) at startup? > > Not the code. In reverse. > Why not? Python has plenty of other flaws that I can't happily work around, and I do think Lisp is more flexible. However, I think your example is readable enough with a data driven algorithm in most any popular language. All of the data is visible to the reverse(...) method. Maybe I missed something in your example, but I think you aren't trying hard enough. :-) The one I liked was: http://ll1.ai.mit.edu/shriram-talk.pdf If I ever fill in your RtL survey, I'll be citing that one as a turning point for me. > > Interpolation does not mean what you think it means. I'm sure he meant "string interpolation", which is a common enough term in scripting languages nowdays. > It would be easier to compare and > contrast with the Python equivalent if someone had posted such, but your > troops have fallen back to Fort So What? and pulled up the drawbridge. > Oh God! Is it just me out here? And I'm not even a believer. Cheers. From george.sakkis at gmail.com Fri Dec 8 04:23:13 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 8 Dec 2006 01:23:13 -0800 Subject: I think Python is a OO and lite version of matlab References: <1165564104.379172.272890@l12g2000cwl.googlegroups.com> Message-ID: <1165569793.031978.121190@n67g2000cwd.googlegroups.com> Allen wrote: > Does anyone agree with me? > If you have used Matlab, welcome to discuss it. Sure, and earth is a heavy version of a basketball. If all you have is a hammer... George From chenal at naritech.cn Fri Dec 8 02:48:24 2006 From: chenal at naritech.cn (Allen) Date: 7 Dec 2006 23:48:24 -0800 Subject: I think Python is a OO and lite version of matlab Message-ID: <1165564104.379172.272890@l12g2000cwl.googlegroups.com> Does anyone agree with me? If you have used Matlab, welcome to discuss it. From orsenthil at gmail.com Sat Dec 2 14:34:54 2006 From: orsenthil at gmail.com (Phoe6) Date: 2 Dec 2006 11:34:54 -0800 Subject: problem occurs with replaced values using fileinput Message-ID: <1165088094.730395.49710@j44g2000cwa.googlegroups.com> Hi All, I am able to use urlib2 through proxy. I give proxy credentials and use # Set the Proxy Address proxy_ip = "10.0.1.1:80" proxy_user = 'senthil_or' proxy_password_orig='password' proxy_password = urllib.quote(proxy_password_orig,"") # Setup the Proxy with urllib2 proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' + PROXY_IP #proxy_url = urllib.quote(proxy_url_add) proxy_support = urllib2.ProxyHandler({"http":proxy_url}) opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler) urllib2.install_opener(opener) -- Now, I have decided in my program, I shall give a Configfile.txt to users who can enter the proxy details and I shall substitute the details in the script; #FILE: Configfile.txt # Provide the Proxy Details PROXY_IP: 10.0.1.1 PROXY_PORT: 80 PROXY_USER: senthil_or PROXY_PASSWORD: password #Config Parsing function. def configParsed(): """Parse the Configfile.txt""" configparser = ConfigParser() configparser.read('ConfigFile.txt') settings = {} settings['PROXY_IP'] = configparser.get('PROXY','PROXY_IP') settings['PROXY_PORT'] = configparser.get('PROXY','PROXY_PORT').strip() settings['PROXY_USER'] = configparser.get('PROXY','PROXY_USER') settings['PROXY_PASSWORD'] = configparser.get('PROXY','PROXY_PASSWORD') return settings Now, in my script I do a replacement of values in the script: FILE BEFORE Replacement: # Set the Proxy Address proxy_ip = "PROXY_IP:PROXY_PORT" proxy_user = 'PROXY_USER' proxy_password_orig='PROXY_PASSWORD' proxy_password = urllib.quote(proxy_password_orig,"") # Setup the Proxy with urllib2 proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' + proxy_ip #proxy_url = urllib.quote(proxy_url_add) proxy_support = urllib2.ProxyHandler({"http":proxy_url}) opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler) urllib2.install_opener(opener) # Replacing Functions: def replaceProxy(settings): '''Replace the Proxy Credential values''' for k,v in settings.items(): for line in fileinput.input('src' + os.sep+'file.py',inplace=1): print line.replace(k,v), return The problem, I am facing is, when I use a script to replace certain variables with config file based values, the urllib2 is failing!! It is not able to get the correct credentials to open the proxy! I debuged and derived at the conclusion at there is something wrong with replaceProxy(settings) function I am using: 1) Either with for k,v in settings.items() 2) OR with fileinput.input and print line.replace(k,v), The output file with replaced values looks perfectly fine to human eyes! I dont know what is happening with automatic replacement of values which is failing my program. Has anyone faced this kind of scenario before? Need your help in solving this. Thanks, Senthil From rupole at hotmail.com Sat Dec 2 13:20:01 2006 From: rupole at hotmail.com (Roger Upole) Date: Sat, 2 Dec 2006 13:20:01 -0500 Subject: Security Descriptor and CoInitializeSecurity References: <1164998859.758138.27080@80g2000cwy.googlegroups.com> Message-ID: <1165084377_27069@sp6iad.superfeed.net> Huayang Xia wrote: > I'd like to call pythoncom.CoInitializeSecurity with a > PySecurityDescriptor object to set the process-wide security values. > But I'm not able to find a way to let the code go through. > > I have read MSDN and searched web, I've not been able to find answer. I > cooked a security descriptor like this (assume aces is a tuple of tuple > (access, sid) : > > > > sd = win32security.SECURITY_DESCRIPTOR() > sd.Initialize() > sd.SetSecurityDescriptorOwner(sid_owner, False) > sd.SetSecurityDescriptorGroup(sid_group, False) > > > # create DACL > dacl = win32security.ACL() > dacl.Initialize() > for (access, acc_sid) in aces: > # Add ACE which is access and SID > dacl.AddAccessAllowedAce(win32security.ACL_REVISION, access, > isinstance(acc_sid, (unicode, str)) and > win32security.ConvertStringSidToSid(acc_sid) or acc_sid) > > sd.SetDacl(True, dacl, False) # SetSecurityDescriptorDacl > print sd.IsSelfRelative() # result is 1 > > The sd is a self relative one. > >>From MSDN, after calling InitializeSecurityDescriptor, the sd is > absolute sd, and CoInitializeSecurity needs absolute sd. Pythonwin has > not wrapped function like 'MakeAbsoluteSD'. > > Has someone ever had same problem. Could you give a hint for solving > the problem. Thanks. > > Regards PySECURITY_DESCRIPTOR's are always stored in self-relative format. They should be converted automatically in the few places that require an absolute SD, but looks like this one was missed. Could you file a bug report on SourceForge ? http://sourceforge.net/projects/pywin32/ Roger ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From jurgenex at hotmail.com Sat Dec 23 15:20:28 2006 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sat, 23 Dec 2006 20:20:28 GMT Subject: Xah's Edu Corner: Introduction to 3D Graphics Programing References: <1166836083.084101.25870@73g2000cwn.googlegroups.com> <458d1a96$1_3@news.bluewin.ch> Message-ID: Boris Borcic wrote: > Xah Lee wrote: >> Of Interest: > > to which of comp.lang.perl.misc, comp.lang.python, comp.lang.lisp, > comp.lang.java.programmer, comp.lang.functional ? You must be new. Otherwise you would be familiar with this troll already. jue From jeremy+complangpython at jeremysanders.net Fri Dec 1 06:49:37 2006 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Fri, 01 Dec 2006 11:49:37 +0000 Subject: How to read the directory which the actively running python file islocated in? References: Message-ID: Michael Malinowski wrote: > Nevermind, I got it using the sys.argv[0] That doesn't always work, as on unix the path isn't prepended onto sys.argv[0] necessarily. import os.path ... os.path.dirname(os.path.abspath(__file__)) may be better. -- Jeremy Sanders http://www.jeremysanders.net/ From uymqlp502 at sneakemail.com Mon Dec 4 00:08:21 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 3 Dec 2006 21:08:21 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> Message-ID: <1165208901.674998.176090@n67g2000cwd.googlegroups.com> Jean-Paul Calderone wrote: > And I have some laundry that I would like you to do for me. Let me know > when a convenient time for you to pick it up would be. What that has to do with this thread escapes me, but since you apparently have nothing better to do than track down information that should have been provided to you, it's no wonder you don't have enough time to do your own laundry. When you call information to get a phone number, do you first ask if they have the number, then call back a second time to get it if the answer is yes? If a policemen gives you a speeding ticket, do you expect him to tell you how fast he thinks you were going, or are you content to wait for the court date? Get your mother to do your laundry -- after she dresses you in the morning. From Ingo.Wolf at gmx.de Thu Dec 7 09:33:51 2006 From: Ingo.Wolf at gmx.de (iwl) Date: 7 Dec 2006 06:33:51 -0800 Subject: Embedded python adding variables linking to C++-Variables / callbacks References: <1165488494.074166.169240@79g2000cws.googlegroups.com> <1165493047.575426.274630@j72g2000cwa.googlegroups.com> Message-ID: <1165502031.078706.184080@j72g2000cwa.googlegroups.com> gagsl-py at yahoo.com.ar schrieb: > > Write some C functions -callable from Python- which will be used to get > and set the variable value. > >From inside Python, declare a property with getter and setter which > will call your C functions. > This works fine for object attributes. If you want to trap references > to local or global "variables", I think you could provide customized > dictionaries for locals and globals, but I'm not sure if it works > really. > Thank you I will try this. What I found out up to now is to create a class inherited from an fitting type and overwrite the __setitem__ and __getitem__ method but haven't test this yet, something like that: class test(int): __setitem(self, value)__: C-Set-Func(value) __getitem(self)__: return C-Get-Func() x=test() x= -> C-Set-Func called y=x -> C-Get-Func called something seems not yet correct From dixkey at gmail.com Sun Dec 10 21:09:05 2006 From: dixkey at gmail.com (dixkey at gmail.com) Date: 10 Dec 2006 18:09:05 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165800527.225633.84180@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> Message-ID: <1165802945.392579.143070@16g2000cwy.googlegroups.com> JShrager at gmail.com wrote: > > Talk to these guys: > > http://en.wikipedia.org/wiki/PyPy they have an interesting take on > > No, actually maybe you should talk to them since you seem to think that > making Python run fast is dangerous, or at least unnecessary. > I find it amusing that most of the arguments that python-people are making in this thread are actually the arguments that C++ and Java make against Python. "Who needs dynamic typing?", "Who needs closures?", "The idea of using whitespace for syntax is beyond stupid"... Now the python guys obviouly see that that those arguments are bogus, but they keep the same reasoning against lisp. I switched to learning Lisp after Python and knowing Python helped me greatly. And not only the fact that many features were already familiar from Python (I've already known Smalltalk, Prolog and Mozart-Oz for example, as the more weird ones, besides of course the whole array of standard ones like FORTRAN, Pascal, C, Modula-2,C++, etc), but mostly it was the fact that even if something looks weird and unreadable/useless/dangerous/whatever at first sight, it might turn out different when you get used to it. For example I started to learn Python three times. The first two - I've read about whitespace syntax, exclaimed "how stupid some people are" and threw the book away. The third time I've managed to pass that barrier and found the experience rewarding. And that was the *real* knowledge - when faced with Lisp's parentheses I would've probably have the same reaction, but I've remembered my experience with Python and decided to give it a try. So, thanks to Python for making me more open to unconventional concepts and guiding me to learning Lisp! I still find Python a nice language and have warm feelings towards it, although I don't think that given a choce I'd ever pick it over Lisp. From Benjamin.Barker at gmail.com Fri Dec 29 06:44:40 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 03:44:40 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <507lh.334$c46.83@newsfe05.lga> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> Message-ID: <1167392680.358395.317220@h40g2000cwb.googlegroups.com> I initially had it set up so that when I connected to the database I started a transaction, then when I disconnected I commited. I then tried turning autocommit on, but that didn't seem to make any difference (althouh initially I thought it had) I'll go back and see what I can find... Cheers, Ben johnf wrote: > Ben wrote: > > > I don't know whether anyone can help, but I have an odd problem. I have > > a PSP (Spyce) script that makes many calls to populate a database. They > > all work without any problem except for one statement. > > > > I first connect to the database... > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > self.cursor = self.con.cursor() > > self.cursor.execute("SET max_error_count=0") > > > > All the neccesary tables are created... > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > self.cursor.execute("USE "+name) > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > varchar(20)) > > > > Then I execute many insert statements in various different loops on > > various tables, all of which are fine, and result in multiple table > > entries. The following one is executed many times also. and seems > > identical to the rest. The print statements output to the browser > > window, and appear repeatedly, so the query must be being called > > repeatedly also: > > > > print "

SQL query executing

" > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > ','c','2','e','f','g')") > > print "

SQL query executed

" > > > > I have, for debugging, set "i" up as a counter variable. > > > > No errors are given, but the only entry to appear in the final database > > is that from the final execution of the INSERT statement (the last > > value of i) > > > > I suspect that this is to vague for anyone to be able to help, but if > > anyone has any ideas I'd be really grateful :-) > > > > It occured to me that if I could access the mysql query log that might > > help, but I was unsure how to enable logging for MysQL with python. > > > > Cheers, > > > > Ben > > Not sure this will help but where is the "commit"? I don't use MySQL but > most SQL engines require a commit. > Johnf From timr at probo.com Sat Dec 9 23:27:15 2006 From: timr at probo.com (Tim Roberts) Date: Sun, 10 Dec 2006 04:27:15 GMT Subject: Why does wx.Window.CaptureMouse() send EVT_PAINT References: Message-ID: Bill Jackson wrote: > >It seems that the CaptureMouse method sends an EVT_PAINT handler. The >documentation does not mention this...is it somewhere else? Could >someone explain why this handler is sent out? The source code could answer that question for sure, but I doubt that it is CaptureMouse doing it, and I know the SetCapture API (which it eventually calls) does not. Is it possible that your clicking caused some part of the app to become unhidden, or caused some button to change state? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From franz.steinhaeusler at gmx.at Thu Dec 21 04:50:00 2006 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Thu, 21 Dec 2006 10:50:00 +0100 Subject: Stani's Python Editor - questions References: Message-ID: <7llko29d3nfg1bmm010js14r4av3ohm2uf@4ax.com> On Wed, 20 Dec 2006 15:45:01 +0100, Laszlo Nagy wrote: > > Hello, > >I was trying to get answers for these. SPE homepage was down. Then I >found it on berlios >(http://developer.berlios.de/forum/forum.php?forum_id=12695) but no one >answered since 5 days. In fact nobody seems to write in anything to that >forum, I presume it is dead. I have no other choice than ask it here. I >apologize in advance, they may be silly questions. > >1. How can I navigate between opened files? Usually I open 10 or more >files at the same time. There is no way to quickly scroll the tabs and >select the one that I want. Tabs simply run out of my screen. Normally with ctrl-tab, ctrl-shift-tab, ctrl-f6 ctrl-shift-f6 (at least on windows) >2. I tried to use the "Browser" for navigation but it tells me "file is >already open" and it won't switch to the file. Annoying. What version do you have? on 0.8.0b on Windows, it jumps to the tab, if the file is already open. >[...] >I did not find any options/preferences to change the above things. Some >of the above might be new feature requests. I recently switched from >DrPython to SPE. SPE has more functions and it could be much much better >than DrPython, but it has big problems. Now the interesting part of your post begins for me. :) >For example, I like that SPE >saves the workspace automatically for me. In DrPython you have a plugin Sessions or SessionsLight for that. on the sf project page and the SessionsLight on: http://mitglied.lycos.de/drpython/ It saves all open file plus last editing position. >But it takes two minutes to >start up SPE, because I have to press the "OK" button on the ISO8859-1 >message for each file that is re-opened. >I very like the Browser window, >but I cannot use it for navigation. I like the new style save file >dialog, but I cannot use it because it is small. I like the code >completion. (dot) :-) > In DrPython, there is also a Code Completions plugin. It is not perfect, but still useful. I don't want to persuade to use this or that, but a closer look to the plugins will reveal the "hidden" features of DrPython, and plugins prevent DrPython to become to bloated. >Thanks, > > Laszlo From rpw3 at rpw3.org Sat Dec 9 07:49:47 2006 From: rpw3 at rpw3.org (Rob Warnock) Date: Sat, 09 Dec 2006 06:49:47 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: Steven D'Aprano wrote: +--------------- | Wolfram Fenske wrote: | > if Common Lisp didn't have CLOS, its object system, I could write my own | > as a library and it would be just as powerful and just as easy to use as | > the system Common Lisp already provides. Stuff like this is impossible | > in other languages. | | Dude. Turing Complete. Don't you Lisp developers know anything about | computer science? | | Anything any language can do is possible in any other language, | if you are willing to write your own libraries. And debug them. +--------------- Yes, true, but by then you've effectively reimplemented Lisp! ;-} http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule Greenspun's Tenth Rule of Programming [...]: "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp." -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From rzantow at gmail.com Sun Dec 17 10:49:50 2006 From: rzantow at gmail.com (rzed) Date: Sun, 17 Dec 2006 10:49:50 -0500 Subject: Class and instance question Message-ID: I'm confused (not for the first time). I create these classes: class T(object): def __new__(self): self.a = 1 class X(T): def __init__(self): self.a = 4 class Y: def __init__(self): self.a = 4 class Z(object): def __init__(self): self.a = 4 ... and these instances: t = T() x = X() y = Y() z = Z() and I want to examine the 'a' attributes. >>> print T.a 1 >>> print y.a 4 >>> print z.a 4 So far, it's as I expect, but: >>> print x.a Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'a' >>> print t.a Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'a' So what the heck is 'T'? It seems that I can't instantiate it or derive from it, so I guess it isn't a proper class. But it's something; it has an attribute. What is it? How would it be used (or, I guess, how should the __new__() method be used)? Any hints? -- rzed From pyenos at pyenos.org Wed Dec 20 22:32:28 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 14:32:28 +1100 Subject: list1.append(list2) returns None Message-ID: <87mz5hexf7.fsf@pyenos.pyenos.org> def enlargetable(table,col): return table.append(col) def removecolfromtable(table,col): return table.remove(col) print enlargetable([[1],[2],[3]],[4]) # returns None Why does it return None instead of [[1],[2],[3],[4]] which I expected? From bearsprite at gmail.com Tue Dec 12 04:04:36 2006 From: bearsprite at gmail.com (bearsprite) Date: 12 Dec 2006 01:04:36 -0800 Subject: how can I block a thread until some other thread finished? Message-ID: <1165914276.392210.272830@73g2000cwn.googlegroups.com> I start a thread A. In A, I start thread B,C,D,... How can I block A until B,C,D,...(All the thread started by A) finished? From fredrik at pythonware.com Thu Dec 14 07:21:04 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 13:21:04 +0100 Subject: tuple.index() In-Reply-To: References: Message-ID: Nick Maclaren wrote: > My understanding of the difference between a tuple and a list is > PRECISELY that the former is immutable and the latter mutable. while tuples can be used as "frozen lists", that's definitely not what they are, from a design perspective. just like in math [1], a Python tuple is a heterogeneous sequence where the position implies type and usage. in contrast, a list is a homo- geneous collection where all the items are "the same" in some sense, no matter where they are. if you sort or otherwise reorder a list of things, it's still a list of the same things. if you sort a tuple, you'll break it. in other words, you're supposed to know what the individual items are in a tuple; if you feel the need to search for things by value in a tuple, you're using the wrong container type. 1) http://en.wikipedia.org/wiki/Tuple From kentilton at gmail.com Sat Dec 9 12:07:26 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 12:07:26 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4tvm5mF15g127U1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> Message-ID: Bjoern Schliessmann wrote: > Ken Tilton wrote: > > >>Note also that after any amount of dicing I simply hit a magic key >>combo and the editor reindents everything. In a sense, Lisp is the >>language that handles indentation best. > > > Erm ... because there's an editor for it that indents automatically? > Or did I miss the point? I think so, but you did not say enough for me to understand /your/ point. It sounded like you were using sarcasm to point out to me exactly what I had just said. We might want to punt on this. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From gagsl-py at yahoo.com.ar Fri Dec 8 22:57:10 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 8 Dec 2006 19:57:10 -0800 Subject: autoadd class properties In-Reply-To: <1165622366.780227.41870@79g2000cws.googlegroups.com> References: <1165567093.167813.109000@j44g2000cwa.googlegroups.com> <1165569502.811830.157900@73g2000cwn.googlegroups.com> <1165622366.780227.41870@79g2000cws.googlegroups.com> Message-ID: <1165636630.192755.156350@73g2000cwn.googlegroups.com> On 8 dic, 20:59, "manstey" wrote: > We've looked at them a little. Cache is a native OO dbase, so there is > no ORM required. Cache does that for you behind the scenes if you need > it to. What I want is to translate Cache classes and properties into > Python classes and properties. We can only use class wrappers, because > cache uses old style python objects, but this still works. > > Because I am not an experienced programmer, the problem I face is how > to load ANY Cache class, whose properties the wrapper doesn't know in > advance, and turn the class properties into python properties. > > So in Cache, I might have Name = String, Age = Integer, Colours = List, > in the class Person. The python binding provided by Cache creates a > Person class in Python, but it provides none of its properties, so I > want to write a wrapping class that adds the properties. Can you advise > me on how to do this? Still unclear... Don't you have a way to iterate over all the properties? Have you tried using dir() on the generated class? BTW, do you know ZODB? It's an OO database written in Python and mostly transparent for the user. You just write and use your objects as always and the persistence mechanism does the rest. -- Gabriel Genellina From felipe.lessa at gmail.com Sun Dec 31 08:30:44 2006 From: felipe.lessa at gmail.com (Felipe Almeida Lessa) Date: Sun, 31 Dec 2006 11:30:44 -0200 Subject: A question about unicode() function In-Reply-To: <1167571210.084436.311610@48g2000cwx.googlegroups.com> References: <1167571210.084436.311610@48g2000cwx.googlegroups.com> Message-ID: On 31 Dec 2006 05:20:10 -0800, JTree wrote: > def funUrlFetch(url): > lambda url:urllib.urlopen(url).read() This function only creates a lambda function (that is not used or assigned anywhere), nothing more, nothing less. Thus, it returns None (sort of "void") no matter what is its argument. Probably you meant something like def funUrlFetch(url): return urllib.urlopen(url).read() or funUrlFetch = lambda url:urllib.urlopen(url).read() > objUrl = raw_input('Enter the Url:') > content = funUrlFetch(objUrl) content gets assigned None. Try putting "print content" before the unicode line. > content = unicode(content,"gbk") This, equivalent to unicode(None, "gbk"), leads to > TypeError: coercing to Unicode: need string or buffer, NoneType found None's are not strings nor buffers, so unicode() complains. See ya, -- Felipe. From kentilton at gmail.com Sat Dec 9 12:29:24 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 12:29:24 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > > But Lisp's syntax is so unlike most written natural languages that that it > is a whole different story. Yes, the human brain is amazingly flexible, > and people can learn extremely complex syntax and grammars (especially if > they start young enough) so I'm not surprised that there are thousands, > maybe tens or even hundreds of thousands of Lisp developers who find the > language perfectly readable. > > But that isn't to say that the syntax of Lisp is for everybody. yeah, I think it is. Folks don't vary that much. If every Lisp programmer also reports parens disappearing at about thirty days, any given non-Lispnik can pretty much bet on the same experience. And since no one can produce a witness who worked fulltime on Lisp for thirty days and gave up on it because it was a great language but they could not handle the syntax, or a witness who stayed with Lisp because it is a great language even though to this day they have trouble reading the synatx... > Far from > it -- I'd be willing to bet that Lisp developers are a self-selected group > of far above average intelligence. I think the early adopter is distinguished not so much by greater intelligence as by restlessness and rebelliousness and a little lunacy. We lack the knack of happiness. Many of the stories on the RtL reveal folks who sought A Better Way after mastering other languages. And by Better Way, sorry, we mean "why do I have to forever worry about the damn paper tape on this Turing machine!". We do not really like programming, we like thinking about problems and using a computer to solve them. > That would explain why so many of them > seem to be so much more comfortable with higher-order functions than most > other people -- even intelligent people. > > (Looking back, I'm embarrassed about my first reaction to factory > functions all those years ago. Hiss hiss spit. But even with added > familiarity, there comes a time where one has to question the benefit of > sufficiently high-order functions. If you are writing a factory function > that returns factory functions that return factory functions that return > the functions that you needed in the first place, chances are you really > need to rethink your tactics.) > > If I'm right, then maybe Lisp is "better" in some absolute sense, *for > those who can use it*. For those who can't, it isn't just a matter of > (say) the syntax being hard to read because it is unfamiliar, but it > being objectively harder to use. > > An interesting study would be to track people's eyeballs as they read > code, ... I spend about 90% of my time thinking and writing code, and read it only to understand how something works or why it broke. And then I am looking at parentheses no more than you are looking at the lines of resolution on a TV when watching Baywatch. I am looking at a mechanism and how it works. > ...or look at how much oxygen their brain uses. Do Lisp coders do more > work to read Lisp than Python coders do to read Python? I suspect they do, > but successful Lisp coders don't notice. My suspicion goes the other way, and is based not on punctuation, rather on imperative vs functional. In Lisp every form returns a value, so I do not have all these local variables around that, in the strecth of an interesting function, take on a stream of values and transformations to finally come up with some result, meaning to understand code I have to jump back and forth thru the code to see the lineage of a value and figure out its net semantics. Too much like work. > Everybody else does, and > gravitate to languages which might not be "better" but are "good enough". No, they gravitated to a language that was closer to what they already knew, C or Java (which also mimicked C to pick up those users). Later charms of Python were a great community and library support. Lisp simply does not have the latter, one is forever rolling one's own bindings to C libs. > (If my post leads to any Lisp developer's already swollen head exploding > from pride, my job here is done *wink*) They can't get any bigger. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From devincyu at gmail.com Wed Dec 13 19:07:20 2006 From: devincyu at gmail.com (Chao) Date: 13 Dec 2006 16:07:20 -0800 Subject: speed of python vs matlab. Message-ID: <1166054840.646029.265880@73g2000cwn.googlegroups.com> I've been trying to develop some numerical codes with python, however got disappointed. A very simple test, a = 1.0 for i in range(1000): for j in range(1000): a = a+1 unfortunately, it took 4.5 seconds to finish(my machines is fine. P4 3.0G, 1G RAM, it varies according to machine configuration, but should be in the same level) for matlab, the same operation took 0.1 seconds, I use numpy & scipy, they solve the problem most of the times, but there are cases you can't avoid loops by vectors. I appreciate the elegancy of python so much, but I guess I have to gave it up in these numerical codes.(image processing algorithms), for application dev/scripting, it's still my first choice. A good news is that the same code takes ruby 9.8 seconds. From mike at nospam.com Fri Dec 8 00:53:54 2006 From: mike at nospam.com (Mike) Date: Thu, 7 Dec 2006 21:53:54 -0800 Subject: raw strings in regexps Message-ID: I've been having trouble with a regular expression, and I finally simplified things down to the point that (a) my example is very simple, and (b) I'm totally confused. There are those who would say (b) is normal, but that's another thread. I finally simplified my problem down to this simple case: re.match(r'\\this', r'\\this') Both the pattern and the string to match are identical raw strings, yet they don't match. What does match is this: re.match(r'\\\\this', r'\\this') Below are outputs from two versions of Python on two different machines, with identical outputs, so it's probably not a compiler problem or a version bug. What's going on here? Am I missing something obvious? linux25> python Python 2.2.3 (#1, Feb 2 2005, 12:22:48) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> print re.match(r'\\this', r'\\this') None >>> print re.match(r'\\\\this', r'\\this') <_sre.SRE_Match object at 0x6bf0e0> >>> C:\Dev\python>python ActivePython 2.4.2 Build 10 (ActiveState Corp.) based on Python 2.4.2 (#67, Jan 17 2006, 15:36:03) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> print re.match(r'\\this', r'\\this') None >>> print re.match(r'\\\\this', r'\\this') <_sre.SRE_Match object at 0x009DA058> >>> -- Mike -- From jhmark at xenops.com Thu Dec 21 16:50:53 2006 From: jhmark at xenops.com (Jonathan Mark) Date: Thu, 21 Dec 2006 13:50:53 -0800 Subject: 13 second delay using select() with Popen3() Message-ID: <458B01BD.9040407@xenops.com> hi all... I wrote a seemingly simple function (below) to use Popen3() and select() to run a program and capture its exit status, stdout output, and stderr output. It worked fine until the box was upgraded to Debian sarge. Now the call to select() always takes about 13 seconds before returning the first time. The delay only occurs when the function is running within a CGI program invoked by Apache (v2.2). If I run the same thing from a shell in the same environment, there is no delay. The correct result is always returned; the only problem is the 13-second delay. The command passed as "cmd" runs a bash script which looks at some local files and prints one line of output and then does "exit 0". Python is v2.4.4 (can't use 2.5 because I am using Zope which doesn't support it yet). I would appreciate any suggestions or advice about whether I got the select loop wrong somehow, or what else might be wrong. Thanks!! Jonathan Mark ------- import os, popen2, select def execCommand(cmd, mergeErrors = False): popen3 = popen2.Popen3(cmd, capturestderr = True) popen3.tochild.close() strOutput = '' strErrors = '' fdOutputFrom = popen3.fromchild.fileno() fdlistFrom = [fdOutputFrom, popen3.childerr.fileno()] while fdlistFrom: fdlistReadable, fdlistWriteable, fdlistError = select.select( fdlistFrom, [], fdlistFrom) for fd in fdlistError: raise AssertionError('file I/O error with child process') for fd in fdlistReadable: data = os.read(fd, 8192) if data: if mergeErrors or fd is fdOutputFrom: strOutput += data else: strErrors += data else: fdlistFrom.remove(fd) popen3.fromchild.close() popen3.childerr.close() return popen3.wait(), strOutput, strErrors From mark.dufour at gmail.com Sat Dec 30 11:24:27 2006 From: mark.dufour at gmail.com (mark.dufour at gmail.com) Date: 30 Dec 2006 08:24:27 -0800 Subject: some OT: how to solve this kind of problem in our program? In-Reply-To: <1166974469.681026.101070@42g2000cwt.googlegroups.com> References: <458e4426$0$5286$4c368faf@roadrunner.com> <1166958490.785728.52430@h40g2000cwb.googlegroups.com> <1166974469.681026.101070@42g2000cwt.googlegroups.com> Message-ID: <1167495866.956934.91480@n51g2000cwc.googlegroups.com> bearophileHUGS at lycos.com wrote: > Using Psyco this version is much faster, you can test it on your PC > compared to the other one (the whole running time, Psyco compilation > too): FWIW, the CVS version of Shed Skin optimizes this exact program a bit further than Psyco: Psyco: 0.66 s Shed Skin: 0.30 s Thanks, Mark Dufour. -- Shed Skin author, http://mark.dufour.googlepages.com From gert.cuykens at gmail.com Mon Dec 18 14:40:13 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Mon, 18 Dec 2006 20:40:13 +0100 Subject: def index(self): Message-ID: Is there a difference between class HelloWorld: def index(self): index.exposed = True return "Hello world!" and class HelloWorld: def index(self): self.exposed = True return "Hello world!" From Roberto.Bonvallet at cern.ch Fri Dec 15 06:51:40 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Fri, 15 Dec 2006 11:51:40 +0000 (UTC) Subject: skip last line in loops References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> <1166182692.041668.218730@f1g2000cwa.googlegroups.com> Message-ID: eight02645999 at yahoo.com wrote: >> do it lazily: >> >> last_line = None >> for line in open("file): >> if last_line: >> print last_line >> last_line = line >> >> or just gobble up the entire file, and slice off the last item: >> >> for line in list(open("file"))[:-1]: >> print line >> >> > > hi > would it be a problem with these methods if the file is like 20Gb in > size...? The second one would be a problem, since it creates a list containing all the lines of the file. Use the lazy approach. -- Roberto Bonvallet From nick at craig-wood.com Fri Dec 15 13:30:04 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Fri, 15 Dec 2006 12:30:04 -0600 Subject: Serial port failure References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> Message-ID: Rob wrote: > I am fairly new to python, but not programming and embedded. I am > having an issue which I believe is related to the hardware, triggered > by the software read I am doing in pySerial. I am sending a short > message to a group of embedded boxes daisy chained via the serial port. > When I send a 'global' message, all the connected units should reply > with their Id and Ack in this format '0 Ack' What is to stop all the embedded boxes talking at once? I suspect that the embedded boxes all taking at once is confusing the serial port driver. Maybe it is creating a break condition that it doesn't deal with properly? Or perhaps I've misunderstood the topology! What sort of flow control are you using? Could it have got out of step with XON-XOFF? Assuming the driver is locking up then it looks like a serial port driver bug. In my day job I do a lot of stuff with serial ports and I've found that drivers vary wildly in quality! My advice is to try a different serial port hardware. I've found ones based on the PL2303 chip to be very reliable both under windows and linux. Eg this one :- http://www.scan.co.uk/Products/ProductInfo.asp?WebProductID=98192 Or one of these (which were based on PL2303 last time I bought one) http://www.comtrol.com/products/catalog.asp?group=usbserialhubs I don't think anything you can do from python/user-space should be able to lock up the kernel mode serial driver. If it does lock up it is a driver bug. Here you'll find a little program I wrote which, with the help of a loopback connector, you can check your serial port out http://www.craig-wood.com/nick/pub/cambert.exe Run the program from a cmd prompt and it will tell you how to use it. I've broken a lot of serial port drivers with that program ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From robin at reportlab.com Wed Dec 20 08:51:14 2006 From: robin at reportlab.com (Robin Becker) Date: Wed, 20 Dec 2006 13:51:14 +0000 Subject: [ANN] PyInstaller 1.3 released In-Reply-To: References: Message-ID: <45893FD2.90802@chamonix.reportlab.co.uk> Giovanni Bajo wrote: > Hello, > > PyInstaller 1.3 is out! > > Grab latest version at: > http://pyinstaller.python-hosting.com/ ...... I just tried this on something which we currently use py2exe+nsis to package and it certainly seems to produce a small exe, but when run I see a cryptic message on two message boxes ! msvcr71.dll ! could not be extracted the program then exits. When run with -X I saw output from the upx process Ultimate Packer for eXecutables Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006 UPX 2.03w Markus Oberhumer, Laszlo Molnar & John Reiser Nov 7th 2006 File size Ratio Format Name -------------------- ------ ----------- ----------- 348160 -> 165888 47.65% win32/pe MSVCR71.dll Packed 1 file. So I'm just guessing there might be a case sensitivity issue in the unpacking somewhere. -- Robin Becker From fossilx at gmail.com Fri Dec 1 09:52:37 2006 From: fossilx at gmail.com (TonyM) Date: 1 Dec 2006 06:52:37 -0800 Subject: client/server design and advice Message-ID: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> I recently completed the general guidelines for a future project that I would like to start developing...but I've sort of hit a wall with respect to how to design it. In short, I want to run through approximately 5gigs of financial data, all of which is stored in a large number of text files. Now as far as formatting and data integrity...I would go through and ensure that each file had the required setup so thats not really the issue. The problem I am having is with respect to speed. The languages I knew the best when coming into this project includes c++ and php. However, I then thought about how long it would take one PC to iterate through everything and figured it would probably take a significant amount of time. As such, I started looking into various languages and python caught my interest the most due to its power and what seems to be ease of use. I was going to initially just use python as a means of creating various indicators (i.e. calculations that would be performed on the data in the file)...however I am leaning towards moving to python entirely mostly due to its gui support. First off, i was wondering if this is a reasonable setup: The entire process would involve a server which manages which pc is processing which set of data (which may be a given text file or the like), and a client application which i would run on a few pc's locally when they aren't in use. I would have a database (sqlite) holding all calculated data of significance. Each client will basically login/connect with the server, request a time interval (i.e. does anything need processed? if so what data should i look at), and then it would update its status with the server which would place a lock on that data set. One thing i was wondering is if it would be worth it to use c++ for the actual iteration through the text file or should i simply use python? While i'm sure that c++ would be faster i am not entirely sure its worth the headache if its not going to save me significant processing time. Another thing is...if i was going to work with python instead of c++, would it be worth it to import all of the data into an sqlite database before hand (for speed issues)? Lastly, as far as the networking goes, i have seen posts and such about something called Pyro (http://pyro.sourceforge.net) and wondered if that was worth looking into for the client/server interaction. I apologize if any of these questions are more lower level, this is simply the first client/server application ive created and am doing so in a language ive never used before ;) Thanks for the help -Tony From gagsl-py at yahoo.com.ar Thu Dec 7 04:51:28 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 06:51:28 -0300 Subject: PyRun_SimpleString no sys.argv[0] In-Reply-To: <20061207091611.139800@gmx.net> References: <1165418630.840841.136290@n67g2000cwd.googlegroups.com> <7.0.1.0.0.20061206231609.04cc8c98@yahoo.com.ar> <20061207091611.139800@gmx.net> Message-ID: <7.0.1.0.0.20061207064523.03e40fd0@yahoo.com.ar> Please keep posting on this list, surely other people can help more than I. At Thursday 7/12/2006 06:16, Ingo Wolf wrote: > > At Wednesday 6/12/2006 12:23, iwl wrote: > > > > >I'm just starting with Python - would like to embed it in my > > >windows-programm as an script-processor. For tests I use easygui some > > >easy-wrapper for the py-tck-stuff. > > > > Looks a bit strange for me. If the GUI will be in Python, I think you > > could do things the other way, *extending* your main Python program > > with your own C code, not *embedding* Python inside your main C program. > > I'm not sure if Tk can run without a mainloop. > > >No I have an Borland C++ GUI Windows App and should make it scriptable >I tryed using MS ScriptControl first but have only Problems with now I >try phyton which also have more posibillities. >May bee I find a way to also access my script engine from outside >my programm. Open and connecting some kind of terminal for my embedded >phyton would also be fine. Embedding Python into your app seems fine - but in this case, your example (using Tk) is not a good starting point, since python wont use a GUI (your App is the GUI). -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From fabri16 at inwind.it Mon Dec 11 04:24:32 2006 From: fabri16 at inwind.it (fabri16 at inwind.it) Date: 11 Dec 2006 01:24:32 -0800 Subject: sovrascrivere Message-ID: <1165829072.305054.62910@16g2000cwy.googlegroups.com> ciao.. ho creato i tasti con le immagini def creaImmagine(self): img = tk.PhotoImage(file=self.ico1) b = tk.Button(root, image=img, command=self.allaPressione) b.pack(side='left',padx=25) b.configure (width=80, height=80) b.image = img mi resta solo un problema.. questo metodo viene richamato pi? volte, ma i tasti non vengono sovrasritti bens? aggiunti (a sinistra). come faccio per sovrascriverli? ho provato con destroy, ma finisce che non mi crea neppure l'immagine. oppure senza sovrascriverli mi basterebbe cambiare l'immagine all'interno (ma credo che il modo migliore sia sovrascriverli). ah...prima che mi scordi.. windows e tkinter. grazie fabri From klappnase at web.de Tue Dec 19 20:43:22 2006 From: klappnase at web.de (klappnase) Date: 19 Dec 2006 17:43:22 -0800 Subject: Tkdnd--does anyone use it? In-Reply-To: <1166548136.995570.27980@79g2000cws.googlegroups.com> References: <1ae21$458725a9$4275d90a$29101@FUSE.NET> <1166548136.995570.27980@79g2000cws.googlegroups.com> Message-ID: <1166579002.792943.33070@a3g2000cwd.googlegroups.com> > I use it in phonoripper > (http://klappnase.zexxo.net/phonoripper.index.html) to drag files from > Oops, wrong link address, should be: http://klappnase.zexxo.net/phonoripper/index.html Apologies Michael From kentilton at gmail.com Thu Dec 14 09:36:46 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 09:36:46 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4ucmndF17nmp0U1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> Message-ID: Andrew Reilly wrote: >> Each skill seems to have a title, a > list of annotations, and a list of hints (and a reverse, which I don't > understand). There's the problem. > That all looks like data. No, not reverse, the part you did not understand. I do not mean what the code was doing, I meant that it was code. > Couldn't you do that with a table > containing those fields, and key it off the defskill argument (or even the > title?) at startup? Not the code. In reverse. > Then you don't have to worry about re-factoring the > code: there's only going to be one piece of code, driven by a table. What if it turns into an SQL lookup during refactoring? > > I only mentioned interpolation because it seemed likely that you might > want to be mutating these strings to be more specific to what your student > was actually doing. Interpolation does not mean what you think it means. :) That's OK, I figgered it out. Yes, that is what the program does, it substitutes terms from the student's problem to produce a hint or annotation. The function is called "expand". Because the text is like a macro. :) > I didn't expect that "42" was necessarily the right > answer... No, but it so happens any #STR...# token is a literal bit of math encoded as an ascii string. That gets translated to proper math notation (by which I mean, what you would see in tex output). During template conversion. So this hint is just saying to the kid, "Dude, |-42|=42, |42|=42, get over it." > > To back out a bit, here, and get back to the meat of the matter: if one is > using Python, then it's because one doesn't much care about performance, I'll try again: this has nothing to do with performance. > and it's reasonable to do expansions, pattern matching and domain specific > language creation/use at run-time. After all, that's how the language > itself works, mostly. The last example showed the macro inserting code to magically produce a binding inside the reverse function. It would be easier to compare and contrast with the Python equivalent if someone had posted such, but your troops have fallen back to Fort So What? and pulled up the drawbridge. Peace. Out. Ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From DustanGroups at gmail.com Wed Dec 13 06:11:41 2006 From: DustanGroups at gmail.com (Dustan) Date: 13 Dec 2006 03:11:41 -0800 Subject: slices - handy summary In-Reply-To: <1166007443.489814.171340@j72g2000cwa.googlegroups.com> References: <1166007443.489814.171340@j72g2000cwa.googlegroups.com> Message-ID: <1166008301.672308.155140@n67g2000cwd.googlegroups.com> meridian wrote: > If, like me, you're always forgetting which way around your list/seq > slices need to go then worry no more. Just put my handy "slice > lookupper" (TM) ) on a (large!) PostIt beside your screen and, Hey > Presto! no more tediously typing a 1-9 seq into your interpreter and > then getting a slice just to check what you get.. (Yes you. You know > you do that !) ... Cheers Steve Actually, I don't. I just remember that, for a natural (positive nonzero) number y: x[:y] is the first y elements x[-y:] is the last y elements As shown here: >>> x = range(5) >>> x [0, 1, 2, 3, 4] >>> x[:2] [0, 1] >>> x[-2:] [3, 4] >>> And I just work it out from there. Just my method for remembering slices, that happens to work pretty well for me. > x = '0123456789' > > x[-10: ] 0123456789 x[ 0: ] > x[ -9: ] 123456789 x[ 1: ] > x[ -8: ] 23456789 x[ 2: ] > x[ -7: ] 3456789 x[ 3: ] > x[ -6: ] 456789 x[ 4: ] > x[ -5: ] 56789 x[ 5: ] > x[ -4: ] 6789 x[ 6: ] > x[ -3: ] 789 x[ 7: ] > x[ -2: ] 89 x[ 8: ] > x[ -1: ] 9 x[ 9: ] > > x[ :-9 ] 0 x[ :1 ] > x[ :-8 ] 01 x[ :2 ] > x[ :-7 ] 012 x[ :3 ] > x[ :-6 ] 0123 x[ :4 ] > x[ :-5 ] 01234 x[ :5 ] > x[ :-4 ] 012345 x[ :6 ] > x[ :-3 ] 0123456 x[ :7 ] > x[ :-2 ] 01234567 x[ :8 ] > x[ :-1 ] 012345678 x[ :9 ] > 0123456789 x[ :10 ] From greg at cosc.canterbury.ac.nz Tue Dec 19 04:54:19 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Tue, 19 Dec 2006 22:54:19 +1300 Subject: python-hosting.com projects: dead? In-Reply-To: <1166499671.678929.25180@n67g2000cwd.googlegroups.com> References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> <1166499192.027000.151290@j72g2000cwa.googlegroups.com> <1166499671.678929.25180@n67g2000cwd.googlegroups.com> Message-ID: <4upr9dF197g6cU1@mid.individual.net> jpellerin+nose at gmail.com wrote: > I certainly hope so, but this is what I'm reacting to (from > http://www.webfaction.com/freetrac): > > "We're sorry, we're not longer accepting applications for free trac/svn > accounts. People have left their Trac sites unattended and as a result > our server is being flooded with spam. We need to do some serious > cleanup and when that's done we'll accept new applications again (that > might take weeks, if not months though). " Um, that sounds to me like they're not accepting *new* projects, not that they're shutting down existing ones. Unless *my* reading comprehension skills have completely abandoned me. -- Greg From exarkun at divmod.com Sun Dec 17 23:46:39 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Sun, 17 Dec 2006 23:46:39 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165834892.338714.34850@16g2000cwy.googlegroups.com> Message-ID: <20061218044639.20948.284189755.divmod.quotient.78931@ohm> On 11 Dec 2006 03:01:32 -0800, Ravi Teja wrote: >Timofei Shatrov wrote: > > [snip] > >Of course, doctest is hardly the ultimate testing solution. But it does >an admirable job for many cases where you don't need to setup elaborate >tests. > >> It's not surprising that no one uses this stuff for serious work. > >I have seen enough libraries that use doctest. Zope, Twisted and Paste >are some of the popular Python projects in that use it. Epydoc supports >it as well. Just as a factual correction, Twisted does not use doctests. Jean-Paul From m.sloyko at gmail.com Wed Dec 27 04:38:37 2006 From: m.sloyko at gmail.com (Maxim Sloyko) Date: 27 Dec 2006 01:38:37 -0800 Subject: Mod_python References: <1167161288.802707.64220@h40g2000cwb.googlegroups.com> Message-ID: <1167212317.836419.162730@42g2000cwt.googlegroups.com> Lad wrote: > In my web application I use Apache and mod_python. > I allow users to upload huge files( via HTTP FORM , using POST method) > I would like to store the file directly on a hard disk and not to > upload the WHOLE huge file into server's memory first. > Can anyone suggest a solution? The only solution you need is Apache and mod_python :) I mean, Apache won't load a huge POST request into its memory no matter what. All file uploads will be stored in temporary files. Under mod_python (provided you use FieldStorage) you'll need to deal only with 'file' objects. -- Maxim Sloyko From snobis at gmx.de Sat Dec 9 08:45:25 2006 From: snobis at gmx.de (Stefan Nobis) Date: Sat, 09 Dec 2006 14:45:25 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> Message-ID: <878xhhkwsq.fsf@snobis.de> Paul Rubin writes: > Python is more readable than Lisp because it stays readable even if > you don't use it on a daily basis. Girls, this is really bullshit! None programming language is readable. I teach programming to complete beginners and I tried some languages -- maybe some are a little bit worse for the uneducated, but all languages are really unreadable. Intuitive interfaces (GUI, languages,...) are an urban legend, pure illusion. You have to do hard work and practice to understand them. -- Stefan. From gagsl-py at yahoo.com.ar Mon Dec 11 18:18:58 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 20:18:58 -0300 Subject: doubt in curses module In-Reply-To: <86a272920612110017t58f77ae6jaa47f0d09739bd67@mail.gmail.co m> References: <86a272920612110017t58f77ae6jaa47f0d09739bd67@mail.gmail.com> Message-ID: <7.0.1.0.0.20061211201556.03eb4d70@yahoo.com.ar> At Monday 11/12/2006 05:17, pradeep kumar wrote: >iam new to python. i want to use function keys in my program, so i >went through the curses module, but in that module it shows a >different window object and after pressing the our desired function >key in it, that will return the ascii value of that key to the command prompt. >so, i want to hide or dissable the window object, can anyone tell me >how it will be possible... >it is very urgent Sorry but I don't understand your problem. Can you provide a *minimal* example, telling what actually happens and what you expect to happen? If the program aborts with an error, provide the full traceback too. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From aine_canby at yahoo.com Mon Dec 11 06:40:42 2006 From: aine_canby at yahoo.com (aine_canby at yahoo.com) Date: 11 Dec 2006 03:40:42 -0800 Subject: Avoiding "invalid literal for int()" exception In-Reply-To: <1165836685.023929.197850@f1g2000cwa.googlegroups.com> References: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> <1165836685.023929.197850@f1g2000cwa.googlegroups.com> Message-ID: <1165837241.981684.228390@f1g2000cwa.googlegroups.com> John Machin skrev: > aine_canby at yahoo.com wrote: > > >>> v = raw_input("Enter: ") > > Enter: kjjkj > > >>> int(v) > > Traceback (most recent call last): > > File "", line 1, in > > ValueError: invalid literal for int() with base 10: 'kjjkj' > > > > In my program I need to be able to enter char strings or int strings on > > the command line. Then I use an if-elif structure to establish which is > > which. For example - > > > > if uniList[0].lower() in ("e","exit"): # uniList stores a unicode > > string origionally taken from stdin > > return > > elif uniList[0].lower() in ("h","help"): > > verb.PrintVerb() > > elif uniList[0].lower() in ("p","pass"): > > break > > elif int(uniList[0]) in range(0,10): > > verb.SetImportance(int(uniList[0])) > > break > > else: > > verb.AddNewVerb((uniList[0]) > > > > How could I avoid the ValueError exception if uniList[0] == "?ker"? I > > was thinking of having something like - > > > > formatError = False > > try: > > iVal = int(uniList[0]) > > if iVal not in range range(0,10): > > formatError = True > > catch ValueError: > > Perhaps you meant > except ValueError: > :-) > > > > iVal = -1 > > > > Consider using uniList[0].isdigit() -- see > http://docs.python.org/lib/string-methods.html > > HTH, > John Yes, thanks for your help. From dudds at netspace.net.au Sat Dec 23 20:51:31 2006 From: dudds at netspace.net.au (dudds) Date: 23 Dec 2006 17:51:31 -0800 Subject: Help please using telnetlib module Message-ID: <1166925091.055161.8090@f1g2000cwa.googlegroups.com> Hi Guys, I just started learning Python a couple of days ago and to put some of what I learnt into practice. As such I thought I might try and write a simple program (based on examples I had seen) that would allow me to log into a Cisco router, enter configuration mode, change an interface description and also grab a snapshot of the running configuration. So far I've managed to be able to log in and change the interface configuration. The tn.read_until() function seems to work pretty much as I expected however for the life of me I cannot get the running configuration to display with any of the read functions. Suggestion please........my code thus far follows: import getpass import sys import telnetlib #This can actually log in and change an interface description on a router HOST = "xxx.xxx.xxx.xxx" #user = raw_input("Enter your remote account: ") #password = getpass.getpass() password = "tacis345int" tn = telnetlib.Telnet(HOST) #tn.interact() tn.read_until("Password:") tn.write(password + "\n") #if password: # tn.read_until("Password: ") # tn.write(password + "\n") tn.read_until("port>") #tn.write("show version\n") #tn.write("\n\n") #tn.read_until("port>") tn.write("enable\n") tn.read_until("assword: ") tn.write("tacis345int\n") tn.read_until("port#") tn.write("conf t\n") tn.read_until("config)#") tn.write("int ethernet0\n") tn.read_until("config") tn.write("desc This was written by my script\n") tn.write("show run\n") print tn.read_very_lazy() tn.write("exit\n") tn.read_until("#") tn.write("quit\n") tn.close() print tn.read_all() The only output I get from this is: -if)# show I have tried the other read options but nothing seems to work for me. I'm obviously missing something, so if anyone could shed some light that would be great. From RichardTRMurphy at yahoo.com Wed Dec 13 20:16:39 2006 From: RichardTRMurphy at yahoo.com (rich murphy) Date: 13 Dec 2006 17:16:39 -0800 Subject: The Famous Error Message: "ImportError: No module named python_script" Message-ID: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> I am studying Python language. I have Python 2.5 installed in my PC which is running on Windows XP. I placed the the script called "python_script" in C:\Python25 directory where all the other Python files are. When I tried to import the script called "python_script", it kept printing the famous error message: "ImportError: No module named python_script". I took the file out of "C:\Python25" directory, placed it in 'C:\PythonTests'. The error message kept coming. The "import" commnand will not work at all. >>> import python_script Traceback (most recent call last): File "", line 1, in ImportError: No module named python_script >>> import sys >>> sys.path ['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\ \lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25 ', 'C:\\Python25\\lib\\site-packages'] >>> sys.path ['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\ \lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25 ', 'C:\\Python25\\lib\\site-packages'] >>> sys.path.append('C:\PythonTests') >>> sys.path ['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\ \lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25 ', 'C:\\Python25\\lib\\site-packages', 'C:\\PythonTests'] I uninstall Python2.5, installed Python2.4: the result is the same. The result is the same with older versions of Python also. Does anybody know a remedy for this??? From http Mon Dec 11 20:06:39 2006 From: http (Paul Rubin) Date: 11 Dec 2006 17:06:39 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> Message-ID: <7xfybl7wio.fsf@ruckus.brouhaha.com> jayessay writes: > > If you say foo.frob() in Python, that's supposed to look up 'frob' in > > a dictionary hanging off of foo. You can modify the contents of this > > dictionary any time you want. > > Unless I'm missing something this looks absolutely dead easy to > implement in Lisp and with a very little macrology you would have the > syntax as well. I'm not sure how this makes one or the other "more > dynamic". I'm talking about the way Lisp is actually used, not what contortions one can do with macros. The way one does OOP in Lisp is with CLOS. From __peter__ at web.de Thu Dec 28 08:10:27 2006 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Dec 2006 14:10:27 +0100 Subject: answers.py v0.0.1 - source References: <87bqloz3fy.fsf@pyenos.pyenos.org> Message-ID: Marc 'BlackJack' Rintsch wrote: > >?????def?__init__(self,answers={}): > >?????????self.answers=answers > > Default arguments are only evaluated once when the ``def`` is executed, > so all your `Storage` classes share the same dictionary.??One?idiom?to > solve this is: > > ????def?__init__(self,?answers=None): > ????????self.answers?=?answers?or?dict() Nitpick: the expression 'answers or dict()' is false economy. It may provoke even subtler errors, because an empty dict is False in a boolean context. Example: # here the answers are shared: shared_answers = {"question": "answer"} first = Storage(shared_answers) second = Storage(shared_answers) print second.answers is first.answers # True # here the answers aren't shared:" shared_answers = {} first = Storage(shared_answers) second = Storage(shared_answers) shared_answers["question"] = "answer" print second.answers is first.answers # False To avoid the confusion I recommend the following: def __init__(self, answers=None): if answers is None: answers = {} self.answers = answers Peter From sonibergraj at youjoy.org Mon Dec 4 17:24:33 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Mon, 04 Dec 2006 23:24:33 +0100 Subject: Convert PNG files to BMP files using PIL In-Reply-To: <1165270056.488786.210090@n67g2000cwd.googlegroups.com> References: <1165270056.488786.210090@n67g2000cwd.googlegroups.com> Message-ID: <4574A021.8060800@youjoy.org> Craig wrote: > Can this be done using PIL or is there another library that can be used > to fulfil the task. If you could let me know that would be great. > Thanks and good luck. Not sure if this solves your particular problem, but have you considered ImageMagick? There are python bindings at http://www.imagemagick.org/script/api.phpm Cheers, -- Soni Bergraj http://www.YouJoy.org/ From greg at cosc.canterbury.ac.nz Thu Dec 14 16:48:13 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 15 Dec 2006 10:48:13 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> Message-ID: <4udv7sF17tlp4U1@mid.individual.net> Ken Tilton wrote: > How close can Python get when code is involved? The reverse function > signature is fixed, so can lambda help? Lambda can be used if the body can be written as a single expression. Otherwise you need to write the function as a separate def. When the body is more than a line or two, this is not usually much of a problem, and is arguably more readable anyway. -- Greg From george.sakkis at gmail.com Sun Dec 10 03:37:58 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 10 Dec 2006 00:37:58 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165627684.709241.86340@16g2000cwy.googlegroups.com> <1165685950.758858.18960@n67g2000cwd.googlegroups.com> <1165732072.056289.274460@79g2000cws.googlegroups.com> Message-ID: <1165739878.421439.193030@f1g2000cwa.googlegroups.com> Ken Tilton wrote: > George Sakkis wrote: > > JShrager at gmail.com wrote: > > > > > >>1. Lisp is the only industrial strength language > > > > ^^^^^^^^^^^^^^^^^^^ > > You keep using that phrase. I don't think it means what you think it > > means. > > To me in part it means "no one can decide to take away lambda because > they decided they should not have put it in in the first place and then > change their mind and leave it in after I already put a few people on > de-lambdifying our 100kloc system because..." Funny, coming from the guy with an inclination in discovering straw man arguments in others. Python 3.0 should be at least a year away from now, let alone the time of discussions about lambda. If you're changing a working system based on brainstorms and speculations about a backwards incompatible version to appear after two years or three, I can't feel sorry for you :) > , and in part it means > compilation. And it /has/ to have macros. :) Oh, and I had the vague impression that it was somehow related to standards about bleeding-edge technologies, such as sockets. But then, I could be wrong :) > Metaprogramming by definition cannot be obscure. Metaprogramming means > programming at a higher level. Check. > A higher level means "more productive". *Segfault* *core dump* *kernel panic* :) No, it is more productive only if you (and the other 5, 10, 100 people in your group) can understand, implement, debug, test and maintain code in that higher level of abstraction. The rest of the proof is therefore irrelevant ;-) > > ...which are > > irrelevant to the vast majority of programmers. > > You insult them by suggesting they cannot concieve at a higher level. > Mebbe they could if their language aupported it. Yours does not. Actually it does. Metaclasses, descriptors, decorators are some high level Python concepts. Most people are productive in Python for years without ever having to write a custom metaclass, or even know their existence (although a library or framework they use daily might in fact use all of the above). Ever heard of Zope ? Even though it's written in Python, it is criticised for its steep learning curve, one main reason being its high level of abstraction. > > I don't know if other lispers > > would join you in your feeble attempt to steal a bite from Ruby's > > current glory... > > Of course we would. You do not get it. The only thing you guys are > bleating about is greater popularity. Now someone is about to eat your > lunch popularity-wise. Live by the poll, die by the poll. And you held > first place for like a week in language geologic time, taken down merely > because... > > > (mostly thanks to the admirable marketing around the > > overhyped Rails framework) > > ... a little hype came along? Wow, your fundamental advantage must have > been about zip, and all derived from things unrelated to syntax. Well, for one thing we never held the first place anyway. Second, what appears to be the big boost for Ruby today maybe its death sentence tomorrow, ending up as a niche language for web apps, like PHP today. With a large crowd undoubtly, but I bet most Pythonistas would prefer lower popularity than ending up in a corner of the application spectrum. > , but Ruby is much closer to Python than > > either of them is to lisp. In fact, if Python suddenly disappeared, > > Ruby would probably be my next stop. Both Ruby and Python are high > > level dynamic languages with an emphasis on pragmatic needs, not being > > the language of the God(s) (see, I can bring up stupid slogans of > > languages too). > > As Graham said, if some pretty good programmers are jumping up and down > about X, mebbe you should take a look at X. Even if assholes like me > piss you off. :) Change that to "amuse me"; nothing better than a sense of self-knowledge :) If you mean the same Graham that wrote http://paulgraham.com/pypar.html, perhaps we don't disagree that much after all :) George From kentilton at gmail.com Sat Dec 9 11:17:44 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 11:17:44 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote: > > >>if Common Lisp didn't have CLOS, its object system, I could write my own >>as a library and it would be just as powerful and just as easy to use as >>the system Common Lisp already provides. Stuff like this is impossible >>in other languages. > > > Dude. Turing Complete. Don't you Lisp developers know anything about > computer science? > > Anything any language can do is possible in any other language, if you are > willing to write your own libraries. I do not think you know what are macros. You are talking about functionality, macros are about the syntax. To achieve what Lisp developers do with macros you would need to write a preprocessor (and indeed this has been done when the need was great enough) to run thru the code expanding all the uses of the preprocessor language. But then your edit-run cycle is broken unless your IDE will let you specify a preprocessor and take care of seamlessly running it, but then what do you debug? And then you cannot just toss off a macro, it becomes an exercise in compiler development and now you have dozens of preprocessors running on each cycle. Ewwwww. > And debug them. Let's not forget the > debugging and testing, unless you'd like us to believe that Lisp code > never contains bugs. Lisp developers so often gloss over that: "Oh, > feature X is *easy*, I could write it in a couple of macros. Two or three. > Maybe thirty. Or forty, max. And they would work the right way first time. Do you really talk to a lot of Lisp developers, or were you making that up? :) Of course implementing an object system is a big job. Your fantasy about Lisp programmers misses the point to which you respond: after they had done all the work to implement an object system, they were able to make it look like Lisp had always had CLOS, without changing the compiler. Keep those fat pitches coming. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From paul at boddie.org.uk Wed Dec 6 06:18:00 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 6 Dec 2006 03:18:00 -0800 Subject: What are python closures realy like? References: Message-ID: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> Karl Kofnarson wrote: > > I wanted to have a function which would, depending on > some argument, return other functions all having access to > the same variable. An OO approach would do but why not > try out closures... I know that everyone will say that Python is a "multi-paradigm" language and that one should feel free to use whatever technique seems appropriate to solve the problem at hand, but it seems to me that there's been an explosion in nested function usage recently, with lots of code snippets showing them off either in the context of a debugging exercise or as a proposed solution to a problem, and yet in many cases their usage seems frivolous in comparison to plain old object-oriented techniques. I'm not pointing the finger at you here, Karl, since you seem to be experimenting with closures, but why are they suddenly so fashionable? Haven't the features supporting them existed in Python for a few versions now? Don't people want to write classes any more? Intrigued, Paul From rschroev_nospam_ml at fastmail.fm Fri Dec 8 05:54:26 2006 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 08 Dec 2006 10:54:26 GMT Subject: dict.has_key(x) versus 'x in dict' In-Reply-To: References: <4tnvstF14cki5U1@mid.individual.net><17783.32458.730462.8403@montanaro.dyndns.org><024f01c719d3$deff0fc0$03000080@hendrik> <17784.7961.898760.712605@montanaro.dyndns.org> Message-ID: Hendrik van Rooyen schreef: > wrote: > >> Hendrik> - as long as it works, and is fast enough, its not broken, so >> Hendrik> don't fix it... >> >> That's the rub. It wasn't fast enough. I only realized that had been a >> problem once I fixed it though. > > LOL - this is kind of weird - it was working, nobody complained, you fiddled > with it to make it faster, (just because you could, not because you had to, or > were asked to), it became faster, and then, suddenly, retrospectively, > it became a problem ???? > > Would it have been no problem if it so happened that you were unable to make it > go faster? > > I don't really follow that logic - but then I have never believed that I could > change yesterday... Have you never experienced the following: A customer reports a bug. Upon investaging you find the source of the problem, but from studying the code you don't understand anymore how it has ever been able to function correctly. From that moment, it indeed stops working even on computers where it always have worked correctly. You fix the bug and all is well again. Very strange, but it has happened to me on a few occasions. There's probably a perfectly logical explanation for what happened, but I never found it. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Fri Dec 8 11:31:08 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Fri, 08 Dec 2006 17:31:08 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> Message-ID: <4ttiadF15dam8U1@mid.individual.net> Alex Mizrahi wrote: > hell no, lisp's syntax is much easier than python's since it's > homogenous Can you give an example? I cannot imagine how homogenity always results in easiness. > (and certainly lisp was invented much 30 years before > Python, so that's Python uses Lisp features) I think you acknowledged that the syntax is different and not borrowed? [many parentheses] > that make logic more explicit Can you give an example? Regards, Bj?rn Xpost cll,clp -- BOFH excuse #166: /pub/lunch From laurent.pointal at limsi.fr Mon Dec 4 03:38:01 2006 From: laurent.pointal at limsi.fr (Laurent Pointal) Date: Mon, 04 Dec 2006 09:38:01 +0100 Subject: RAD for python In-Reply-To: <1165214291.653950.200420@j72g2000cwa.googlegroups.com> References: <1165214291.653950.200420@j72g2000cwa.googlegroups.com> Message-ID: progman a ?crit : > is there a VB-alike tool for python to create forms?? Maybe take a look at DaboDev http://dabodev.com/ From gagsl-py at yahoo.com.ar Mon Dec 18 06:47:57 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 18 Dec 2006 03:47:57 -0800 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: <1166394345_23949@sp6iad.superfeed.net> References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <1166394345_23949@sp6iad.superfeed.net> Message-ID: <1166442477.818748.324370@f1g2000cwa.googlegroups.com> On 17 dic, 19:21, "Roger Upole" wrote: > >> > os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH > > >>This will tell you that "x.exe" is executable, even if "x.exe" contains > >> nothing but zeros. > > > Isn't the same with any other recipe, portable or not? Unless the OS > > actually tries to load and examine the file contents, which the OS's > > I'm aware of, don't do. > > On windows, you can use win32file.GetBinaryType to check if a file is actually > a binary executable. A similar function exists on Linux too. But even if a file has the right file format, if it does not have the execute bit set, won't run. And you could set that bit on a JPG image too - and nothing good would happen, I presume. So one must determine first what means "the file is executable". -- Gabriel Genellina From henning.jansen at gmail.com Sat Dec 16 15:57:17 2006 From: henning.jansen at gmail.com (jansenh) Date: 16 Dec 2006 12:57:17 -0800 Subject: Dictionary, iterate & update objects Message-ID: <1166302637.147669.266480@f1g2000cwa.googlegroups.com> hi comp.lang.python. I need some newbe advice on idiomatic use of Python dictionaries. I have service with a dictionary which holds a bunch of objects as values, and an ID as key to each object. Then I want to change an objects state based on its key. The way I am doing this now is by using 'fromkeys' and copying my object over in a temporary dictionary, then manipulating the object, and then I do an 'update' back to the main dictionary.. :-0 There has to be a smarter way? Thankful for any piece of enlightenment... regards, Henning From jon at ffconsultancy.com Thu Dec 14 04:59:00 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Thu, 14 Dec 2006 09:59:00 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <7xhcw2d0fo.fsf@ruckus.brouhaha.com> Message-ID: <458120ff$0$8730$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: > Interesting, where do I get it, and is there source? I've never been > interested in Mono but maybe this is a reason. How does the compiled > code compare to OCaml or MLton code? GC intensive code is 2-4x slower than OCaml or 4-8x slower than MLton. Floating point intensive code is as fast as OCaml and MLton. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From jeff at taupro.com Thu Dec 14 17:23:36 2006 From: jeff at taupro.com (Jeff Rush) Date: Thu, 14 Dec 2006 16:23:36 -0600 Subject: [Edu-sig] automatically grading small programming assignments In-Reply-To: <4581896B.2020504@bryant.edu> References: <4581896B.2020504@bryant.edu> Message-ID: <4581CEE8.4080502@taupro.com> Brian Blais wrote: > > I envision a number of possible solutions. In one solution, I provide a function > template with a docstring, and they have to fill it in to past a doctest. Is there a > good (and safe) way to do that online? Something like having a student post code, > and the doctest returns. I'd love to allow them to submit until they get it, logging > each attempt. Crunchy Frog (now called Crunchy, as I understand). I just researched and presented on it this past weekend and was impressed with its abilities, including that of the instructor providing a doctest and the student working to write code that lets it pass. Very cool. There is not however currently any logging of progress, counts to get it right, etc. But I would imagine that would not be hard to add to the Crunchy Frog backend. It is just an HTTP proxy with some template expansion to get a Python interpreter inside the browser window. Safety -- ehh. Each Python interpreter is running inside that HTTP proxy with full access to the underlying system, as whatever user it is running as. The design is to have each student run it locally, so they can only trash their own system. However, I could imagine you could set it up to run on a private classroom server, where the attempt records would be kept, and still be safe. http://crunchy.sourceforge.net/index.html For another solution, I wonder whether you could make use of the new Abstract Syntax Tree (AST) in Python 2.5, where you convert the source of an attempt into an abstract data structure, anonymize the method/variable/class names and compare the tree against a correct solution. It would let you quickly handle those students who solved it in a conformist way, and then you'd need to manually review the rest for creatively solving it another way. ;-) But I think Crunchy is the most classroom-friendly way to quickly solve this. A weekend's work at most. -Jeff From gagsl-py at yahoo.com.ar Thu Dec 14 17:40:12 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 14 Dec 2006 19:40:12 -0300 Subject: logging In-Reply-To: <20061206200451.6fca5e68.l.steinborn@4c-ag.de> References: <20061206200451.6fca5e68.l.steinborn@4c-ag.de> Message-ID: <7.0.1.0.0.20061214192322.059b78b8@yahoo.com.ar> At Wednesday 6/12/2006 16:04, Lutz Steinborn wrote: >I need to log each and only this loglevel to a different file. >So for example all INFO to info.log and all ERROR to error.log. > >And I need a master logfile with all messages. > >How can I do this ? >Any example ? Define a handler for each logfile you want, setting the *minimum* level you want to get there. Define a new Filter class: class LevelFilter(Filter): def __init__(self, levelmin, levelmax): Filter.__init__(self) self.levelmin = levelmin self.levelmax = levelmax def filter(self, record): return (record.levelno >= self.levelmin and record.levelno <= self.levelmax) and add an instance of LevelFilter to each handler. (Untested) -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From fredrik at pythonware.com Sat Dec 23 03:38:48 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Dec 2006 09:38:48 +0100 Subject: attribute decorators In-Reply-To: <1166831492.610717.307890@i12g2000cwa.googlegroups.com> References: <1166831492.610717.307890@i12g2000cwa.googlegroups.com> Message-ID: Doug Holton wrote: > Don't mind Fredrik's trolling. Your examples are perfectly clear if you understand how they would work, can you explain the semantics? > however, a similar call for extending the use of decorators to other > structures besides functions was rejected: > http://lambda-the-ultimate.org/node/1389 class objects and class attributes are two rather different things. and given how decorators work, that difference is rather important. can you perhaps figure out why ? From bjourne at gmail.com Mon Dec 4 18:49:30 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 4 Dec 2006 23:49:30 +0000 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> <45745C9E.9050500@v.loewis.de> <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> <1165264641.125857.85980@80g2000cwy.googlegroups.com> Message-ID: <740c3aec0612041549u7898872bte8d9b552f7181f4a@mail.gmail.com> On 12/4/06, Terry Reedy wrote: > While Fredrik's reply is a bit short, as is sometimes his habit, > here are some things that appear to me to not have been thought through > enough: > 1. some negative indexes are legal. That could be fixed. Just substract len(L) from i if i < 0. > 2. replacing short inline code with a function call on *every* index lookup > will slow down the interpreter a bit. I can't notice any difference. On my machine, Python is compiled with -O3 which probably inlines the function. > 3. will the same check code work for even all built-in sequences? Atleast for tuple, string and list, they can be downcasted to PyVarObjects. So yes. > 4. how does index checking fit in with slice checking? When does slicing throw IndexErrors? > with both the knowledge and motivation to do so. But insulting such people > is not helpful. Agreed. I don't think insulting people is helpful at all, but I don't think "Russ" is the only one in this thread that should learn that. -- mvh Bj?rn From paul at boddie.org.uk Sun Dec 10 16:11:53 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 10 Dec 2006 13:11:53 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <1165762281.579645.56990@l12g2000cwl.googlegroups.com> <1165767334.350312.36020@l12g2000cwl.googlegroups.com> <1165777915.940969.205700@f1g2000cwa.googlegroups.com> Message-ID: <1165785112.923267.8280@l12g2000cwl.googlegroups.com> hit_the_lights wrote: > > I should have added some lines: > > ==== python ==================== > >>> import a > >>> import b > You sucker thought I'd import b for you. > Instead I'm going to erase your hard drive. > >>> a > > >>> b > >>> > ============================== > > I was suprised that b was defined at all. Well, I've done all sorts of things with Python's import machinery, and I'd prefer not to stare too long at its implementation, but both import statements by their very nature in Python are still import statements. Of course you can always argue that some undesirable effect of redefining the keyword via a macro is also achievable by misusing the import machinery, that both things are therefore just as dangerous, and that macros are inherently no more dangerous than exposed library mechanisms employed by the virtual machine. I'd agree generally with that reasoning, and you can see in various features of Python that lots of covert side-effects can be introduced which would prove surprising to the casual developer when he or she uses some seemingly harmless construct. (Interestingly, some of the newer features in Python could have been introduced using macros, and perhaps EasyExtend already demonstrates this.) Ultimately, I think that the main point of contention is little to do with macros or their absence from Python. Instead, it's more about people coming to an agreement about form and behaviour guarantees for Python programs - in other words, what you can expect when you open a Python source file and start reading the code. It should be noted that attitudes are generally negative towards careless redefinition of fundamental or common concepts or mechanisms of the language, just as I imagine it would be with Lisp, and one only needs to consider reactions to various Ruby-related advocacy to see where the many in the Python community supposedly draw the line at things like pervasive monkey-patching of built-in classes. To bring that maligned natural language analogy back into repute, I'd argue that Python and its apparent restrictions act a lot like the specialised vocabularies and familiar structures employed when presenting material in various scientific disciplines: one could argue, upon reading a paper, that it would have been a lot easier for the author to have structured the paper differently and to have defined a one-off vocabulary, but issues of convenient communication are highly likely to override such considerations, especially in disciplines where conventions in communication are already very strictly defined. Paul From sjdevnull at yahoo.com Fri Dec 1 16:31:22 2006 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 1 Dec 2006 13:31:22 -0800 Subject: Is python memory shared between theads? In-Reply-To: <1164987833.233073.265170@80g2000cwy.googlegroups.com> References: <1164987833.233073.265170@80g2000cwy.googlegroups.com> Message-ID: <1165008682.015968.227800@f1g2000cwa.googlegroups.com> Wesley Henwood wrote: > So I declare a variable named A in thread1, in script1.py. I assign > the value of 2.5 to A. I then run script2.py in thread2. Script2.py > assigns the value of 5.5 to a variable named A. Now, when thread1 > resums execution, I see that A = 5.5, rather than 2.5 as I expected. > > Is this normal behavior? Yes. In fact, sharing memory is the whole reason threads exist. Use processes in the (more common) case where you don't want memory sharing, use threads when you do. From grante at visi.com Mon Dec 4 10:48:24 2006 From: grante at visi.com (Grant Edwards) Date: Mon, 04 Dec 2006 15:48:24 -0000 Subject: Parsing data from pyserial References: <4572e860.53134312@news.comporium.net> <12n606he7k5uhb3@corp.supernews.com> <4573145a.64392531@news.comporium.net> <12n66nnm8ri1sd4@corp.supernews.com> <45737310.88637718@news.comporium.net> <1165196039.802469.77510@f1g2000cwa.googlegroups.com> <45738635.93539421@news.comporium.net> <1165206356.156819.72540@80g2000cwy.googlegroups.com> Message-ID: <12n8gq8i3pbpm58@corp.supernews.com> On 2006-12-04, John Machin wrote: > Try reading previous posts. The OP reported that to be returned from > the cam, based on print forty_bytes, not print repr(forty_bytes). I > think everybody (including possibly even the OP) is willing to believe > that the cam is *generating* correct parseable stuff, followed by '\r' > -- the problem now is how to get as many samples per second as is > reasonable in the face of problems like lack of buffering, What lack of buffering? -- Grant Edwards grante Yow! RELATIVES!! at visi.com From steve at REMOVE.THIS.cybersource.com.au Sun Dec 3 00:28:58 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 03 Dec 2006 16:28:58 +1100 Subject: text adventure question References: Message-ID: On Sat, 02 Dec 2006 22:19:53 +0000, Dennis Lee Bieber wrote: > Suggest you try to go back and reread some of the responses to such > a subject from whenever (Unfortunately, I suspect my responses are no > longer available as I run with x-noarchive active). That seems horribly anti-social, not to mention counter-productive. What's the point of writing to the newsgroup if your response won't be around by the time they go to read it? After all, what's the point of treating a newsgroup like comp.lang.python as a chat group? -- Steven. From greg at cosc.canterbury.ac.nz Mon Dec 11 05:36:21 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Mon, 11 Dec 2006 23:36:21 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1165769504.098173.101860@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> Message-ID: <4u4qo3F15uds8U1@mid.individual.net> JShrager at gmail.com wrote: > compilers are GREATLY facilitated by having a > macro facility because (at first blush) all you need to do is to > macro-expand down to something you know how to turn into code. There's no way you could compile Python to efficient machine code just by macro expansion. You'd also need some very heavy-duty type inferencing. Python is extremely dynamic, even more so than Lisp. That's why compiling Python is hard, not because it doesn't have macros. -- Greg From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 21:04:03 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 13:04:03 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: On Sat, 09 Dec 2006 21:55:19 +0000, Kirk Sluder wrote: > The question I have is why do critics > single out macros and not other forms of abstraction such as > objects, packages, libraries, and functions? Who says they do? All forms of abstraction have been criticized. Sometimes the criticism is valid. Sometimes it warns against abuses of the abstraction. Just because a feature is useful sometimes doesn't necessarily mean the benefit outweighs the cost. > just as an example: > from foolib import * > bar.bar("somefile") > > What does this program do? I have no idea. Its functionality is > hidden behind multiple layers of abstraction (function, object, > library.) Sure. But at least you know that foolib is a module or package. You know what from and import do, and that can't change. And you know that bar is an object with a method also called bar, it is being called, and the argument is a string "somefile". Those things can't change. Imagine a hypothetical language where those two lines could mean *anything*. Rightly or wrongly, people fear that Lisp's macros push Lisp closer to that hypothetical anything-goes language than is healthy. Maybe that's a problem of perception rather than a problem of fact, but you have to ask, why do people perceive Lisp that way? Could it be because of people like J Shrager who writes things like this? "Can't you just expand the language via macros to create whatever facility of this sort [major new features with new syntax] you need..." (This thread, dated 8 Dec 2006 16:14:44 -0800) Or Wolfram Fenske: "All the interesting features that haven't originated from Lisp (e. g. OO from Smalltalk) could in turn easily be implemented in Lisp with a couple of macros." (This thread, dated 8 Dec 2006 23:38:02 -0800) To someone outside of Lisp, that looks like "I can make Lisp look like any language I like in just a few lines." And that implies that to read a Lisp program, one might need to be able to read code that looks like Lisp, or Smalltalk, or Prolog, or Fortran, or all of those, or whatever bizarre syntax the developer wanted it to look like. My point isn't whether or not their claims are correct (a "couple" of macros? really?) but that things like this feed the perception that Lisp is close to that hypothetical language where anything could be anything. If anything could be anything, do you really know what (+ 1 2) means without reading every line of code? And it isn't really that much comfort to be told that good Lisp developers know not to do stupid things with macros. Sure. But in the real world of programming, most developers aren't good developers, they are merely average -- in fact fifty percent of them are below average. And the bottom 30% can't be trusted with facilities like Lisp's macros, because they WILL do stupid things with them and turn your code base into a morass of shifting syntax, buggy DSLs and other maintenance nightmares. The damage they can do with operator overloading is minor by comparison. Even something simple like file I/O can be abused. Example: I've seen *real* code where somebody needed a dict with ten million keys. (Well, he thought he needed that dict, I never worked out exactly why. Maybe he thought he was pre-allocating memory as an optimization.) So he started off with something like this: def make_dict(): mydict = {} mydict[0] = 0 mydict[1] = 0 mydict[2] = 0 and realised that it would take him forever to write that much code. So he wrote a C program to create the make_dict function for him! Translated into Python: def make_dict_factory(): code = open('makedict.py', 'w') code.write("def make_dict():\n") code.write(" mydict = {}\n") for i in range(10000000): code.write(" mydict[%d] = 0\n" % i) code.write(" return mydict\n") code.close() from makedict import make_dict return make_dict (This is an interesting demonstration that any language that allows file I/O and importing of external program files can always treat functions as data, even if the language doesn't directly support it. An alternative would be to keep the strings in memory instead of writing to a module, then use exec on them instead of importing the module.) Honest to god, the code really was like that! Maybe I've got the precise details wrong, it was a long time ago, but if it wasn't just as I've got it, the consequences were the same: he built a single function that was so large that loading it caused his machine to thrash for twenty minutes trying to free enough memory. Is that an argument against factory functions? Damn straight it is: they are a powerful tool, and in the hands of morons, they can be dangerous. Does that mean that languages shouldn't permit higher-order functions? Not necessarily: all programming tools can be misused, but some can be misused more easily than others. Power and risk is often a trade-off, and language designers can't eliminate all risk of stupid behaviour, but they can design the language to allow whatever level of risk they believe is acceptable. (E.g. there is no doubt that C's raw pointers are powerful, but many languages deliberately don't use them.) The risk of stupid factory functions is small compared to the benefit, but maybe there is some domain somewhere where the ideal solution is a language that DOESN'T treat functions as first class objects, deliberately weakening the language so that a particular class of errors (or stupid behaviour) just cannot happen. But that language isn't Python. When it comes to Lisp's macros, the perception is that the power is correspondingly greater, and the risk of abuse even more so. The safe examples of what macros can be used for don't seem to provide any over-whelming advantage (that's not to say they provide NO advantage, merely that if you use macros safely, the advantage seems small, but if you use them to their full potential, the risk of abuse is too high). That's the perspective of many people, and maybe it is wrong. Maybe you really need to be immersed in Lisp for a while to see the advantages of macros. Or maybe it is only an advantage while Lisp programmers are a self-selected group of above-average skill. Wait until fifty million VB code monkeys start writing Lisp macros and maybe, just maybe, you'll wish they were using a less powerful and more restrictive language. -- Steven. From aj108778 at gmail.com Fri Dec 22 18:51:32 2006 From: aj108778 at gmail.com (DH) Date: 22 Dec 2006 15:51:32 -0800 Subject: attribute decorators In-Reply-To: References: Message-ID: <1166831492.610717.307890@i12g2000cwa.googlegroups.com> Fredrik Lundh wrote: > Gert Cuykens wrote: > > > would it not be nice if you could assign decorators to attributes too ? > > for example > > > > class C: > > @staticattribute > > data='hello' > > > > or > > > > class C: > > @privateattribute > > data='hello' > > and that would do what? > > Don't mind Fredrik's trolling. Your examples are perfectly clear, however, a similar call for extending the use of decorators to other structures besides functions was rejected: http://lambda-the-ultimate.org/node/1389 I'm not sure if that decision still stands with Python 3000, however, Guido has changed his mind before: http://www.artima.com/weblogs/viewpost.jsp?thread=87182 From slawomir.nowaczyk.847 at student.lu.se Tue Dec 12 18:12:09 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Wed, 13 Dec 2006 00:12:09 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: Message-ID: <20061212233435.5736.SLAWOMIR.NOWACZYK.847@student.lu.se> On Tue, 12 Dec 2006 00:21:48 -0800 I V wrote: #> On Mon, 11 Dec 2006 23:24:07 -0500, Ken Tilton wrote: #> > Also, Python does not support a functional style of programming so #> > the line is the only meaningful textual entity. In this sense the #> > primitiveness of Python makes editing easier. #> #> Why do you say that? Wouldn't a block in python be a "meaningful #> textual entity" in the same way a lisp form would be? No, it wouldn't, because that would make the argument false ;) -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) Monday is an awful way to spend 1/7th of your life. From nmm1 at cus.cam.ac.uk Thu Dec 14 10:44:28 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 14 Dec 2006 15:44:28 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: In article , Georg Brandl writes: |> > |> > If lists are intended to be homogeneous, then they should be checked |> > for that, and an exception raised when an attempt is to make them |> > non-homogeneous. At least as a Python checking option. |> |> There you have the "consenting adults" philosophy again: You know what lists |> are for, so you can use them for it. You can also use them for something else, |> but in that case it's moot to complain about missing features. One of the places where Cobol, Ada and Python are superior to C and Perl is that they regard checking as a part of the language. |> > If tuples are intended to be bags, then it makes no sense to allow |> > them to be subscripted OR indexed. Mathematically, 'x = a[i]' and |> > 'i = a.index(x)' have dual properties - and are true duals if you |> > include the constraint of no duplicate elements. |> |> You're describing sets. Tuples are not sets. Sets are not indexable and have |> unique elements. Actually, I was describing bags - like sets, but with element multiplicity. See http://en.wikipedia.org/wiki/Multiset |> Indexing is the *vital* point of tuples. They are an ordered collection of |> values, and you are supposed to know which data is found at which index. Memo to self: you really MUST remember NEVER to use reductio ad absurdum on Usenet. The point is that an index method makes sense on ANY data structure that can be subscripted by an integer value but, for reasons that aren't at all clear, is not defined for Python tuples. There is no technical or mathematical reason why it shouldn't be. Regards, Nick Maclaren. From bobjohnson11 at gmail.com Tue Dec 26 11:13:56 2006 From: bobjohnson11 at gmail.com (RobJ) Date: 26 Dec 2006 08:13:56 -0800 Subject: PySchool Phase II Message-ID: <1167149636.601673.204030@a3g2000cwd.googlegroups.com> PySchool Phase II I just wanted to thank everyone for filling out the survey a few months back for my PySchool graduate school project. I was able to capture a lot of good information from the community. For the people who mentioned to me that I should expand the "What Linux Operating System do you use" question, unfortunately it was too late to make any additions to the survey. However, I will be gathering this information in the future, so I will make sure to incorporate this request. I have completed the fall semester and I have my complete plan of action for how I will be constructing my on-line training environment for Python web frameworks. I am in the process of finalizing the framework(s) that I will use and the technology that I will use to deliver the instruction. The current schedule that I have submitted to my professor has the instruction running from the beginning of February until the middle of March. If you are interested in participating in this free on-line course; send me an email (bobjohnson11 [at] gmail {Dot} com). Please remember that the on-line course is a work in progress, which means that when you have completed the material I would appreciate any constructive feedback that you can give me. I want the instruction to be as effective as possible and to serve as a complementary educational vehicle to the documentation, tutorials and books that are available. I also want to mention that I will be Blogging about this whole experience. I have not had a chance to update my Blog for some time but I plan to start today given the fact that I have a lot more time. Once again, I would like to thank all of the people who filled out the survey and who gave me feedback about my project. You have help me tremendously!!! Thanks Rob Johnson (MAIT Candidate) Blog: http://pyschool.blogspot.com/ From kentilton at gmail.com Sat Dec 9 23:11:03 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 23:11:03 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > If that's the best example of what macros can be used for, frankly I'm > unimpressed. We're shocked. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From nick at craig-wood.com Sat Dec 2 05:30:05 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Sat, 02 Dec 2006 04:30:05 -0600 Subject: os.mkdir and mode References: <1165043870.135812.232530@73g2000cwn.googlegroups.com> Message-ID: Peter Otten <__peter__ at web.de> wrote: > vj wrote: > > > How do I do the following unix command: > > > > mkdir -m770 test > > > > with the os.mkdir command. Using os.mkdir(mode=0770) ends with the > > incorrect permissions. > > mkdir() works just like its C equivalent, see > http://docs.python.org/dev/lib/os-file-dir.html: > > "Where it is used, the current umask value is first masked out." > > Use os.chmod() after os.mkdir() to get the desired permissions. I think you meant use os.umask(0) before the os.mkdir() ? -- Nick Craig-Wood -- http://www.craig-wood.com/nick From DustanGroups at gmail.com Wed Dec 13 20:44:37 2006 From: DustanGroups at gmail.com (Dustan) Date: 13 Dec 2006 17:44:37 -0800 Subject: newb: Creating Exception In-Reply-To: References: <1165881722.928958.81490@79g2000cws.googlegroups.com> <1165954233.519919.107940@l12g2000cwl.googlegroups.com> <1166010331.697359.46400@n67g2000cwd.googlegroups.com> <1166010769.505973.41640@j72g2000cwa.googlegroups.com> Message-ID: <1166060677.580470.269540@n67g2000cwd.googlegroups.com> Dennis Lee Bieber wrote: > On 13 Dec 2006 03:52:49 -0800, "Dustan" > declaimed the following in gmane.comp.python.general: > > > > > I didn't complete my thought. If you run into a situation like this, > > then you might want to look to the python documentation on the web for > > help; think of the web documentation as a reference manual rather than > > a tutorial, even though it does provide a tutorial. > > I believe it was stated that the installation was using the > ActiveState build. The documentation is supplied in Windows CHM format, > which is likely much faster to search/read locally than loading a chain > of web pages. I couldn't think of a better word to describe the 'official' documentation. > Including, last time I checked, an electronic copy of "Dive into > Python" From etaoinbe at yahoo.com Tue Dec 5 03:16:04 2006 From: etaoinbe at yahoo.com (f rom) Date: Tue, 5 Dec 2006 00:16:04 -0800 (PST) Subject: Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Message-ID: <20061205081605.62681.qmail@web50901.mail.yahoo.com> ----- Forwarded Message ---- From: Josiah Carlson To: f rom ; wxpython-users at lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA at 24 referenced in function _make_buildinfo2 Ask on python-list at python.org . - Josiah f rom wrote: > I am trying to debug a segfault which I can not pin down with a simple pytjon script. > For this I have downloaded the free Microsoft visual express c++. > However I am having problems building python2.5. > Anyone have experience with this ? > > 1>------ Rebuild All started: Project: make_buildinfo, Configuration: Debug Win32 ------ > 1>Deleting intermediate and output files for project 'make_buildinfo', configuration 'Debug|Win32' > 1>Compiling... > 1>make_buildinfo.c > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(43) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(47) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(63) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(66) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(69) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(72) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(73) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(81) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(83) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(84) : warning C4996: 'strcat' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(88) : warning C4996: 'unlink' was declared deprecated > 1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(290) : see declaration of 'unlink' > 1> Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.' > 1>Compiling manifest to resources... > 1>Linking... > 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA at 24 referenced in function _make_buildinfo2 > 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegOpenKeyA at 12 referenced in function _make_buildinfo2 > 1>./make_buildinfo.exe : fatal error LNK1120: 2 unresolved externals > 1>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-release\make_buildinfo\BuildLog.htm" > 1>make_buildinfo - 3 error(s), 11 warning(s) > ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== > > > > > > > ____________________________________________________________________________________ > Want to start your own business? > Learn how on Yahoo! Small Business. > http://smallbusiness.yahoo.com/r-index > > --------------------------------------------------------------------- > To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org > For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org ____________________________________________________________________________________ Cheap talk? Check out Yahoo! Messenger's low PC-to-Phone call rates. http://voice.yahoo.com From ray_usenet at yahoo.com Thu Dec 28 21:03:59 2006 From: ray_usenet at yahoo.com (Ray) Date: 28 Dec 2006 18:03:59 -0800 Subject: Anyone persuaded by "merits of Lisp vs Python"? In-Reply-To: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> References: <1167324666.002153.27570@a3g2000cwd.googlegroups.com> Message-ID: <1167357838.969945.15190@48g2000cwx.googlegroups.com> Paddy3118 wrote: > This month there was/is a 1000+ long thread called: > "merits of Lisp vs Python" > In comp.lang.lisp. > (I suspect this thread to be very short - even the > original poster seems to have given up on the day he > started the thread). I use both. And Java, and C++ too. Can one really survive knowing just one language these days, anyway? > > - Paddy. From Benjamin.Barker at gmail.com Fri Dec 29 06:53:16 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 03:53:16 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167392680.358395.317220@h40g2000cwb.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> Message-ID: <1167393196.618932.104550@a3g2000cwd.googlegroups.com> One partial explanation might be that for some reason it is recreating the table each time the code runs. My code says "CREATE TABLE IF NOT EXISTS" but if for some reason it is creating it anyway and dropping the one before that could explain why there are missing entires. It wouldn't explain why the NOT EXISTS line is being ignored though... Ben Ben wrote: > I initially had it set up so that when I connected to the database I > started a transaction, then when I disconnected I commited. > > I then tried turning autocommit on, but that didn't seem to make any > difference (althouh initially I thought it had) > > I'll go back and see what I can find... > Cheers, > Ben > > > johnf wrote: > > Ben wrote: > > > > > I don't know whether anyone can help, but I have an odd problem. I have > > > a PSP (Spyce) script that makes many calls to populate a database. They > > > all work without any problem except for one statement. > > > > > > I first connect to the database... > > > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > > self.cursor = self.con.cursor() > > > self.cursor.execute("SET max_error_count=0") > > > > > > All the neccesary tables are created... > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > self.cursor.execute("USE "+name) > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > > varchar(20)) > > > > > > Then I execute many insert statements in various different loops on > > > various tables, all of which are fine, and result in multiple table > > > entries. The following one is executed many times also. and seems > > > identical to the rest. The print statements output to the browser > > > window, and appear repeatedly, so the query must be being called > > > repeatedly also: > > > > > > print "

SQL query executing

" > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > > ','c','2','e','f','g')") > > > print "

SQL query executed

" > > > > > > I have, for debugging, set "i" up as a counter variable. > > > > > > No errors are given, but the only entry to appear in the final database > > > is that from the final execution of the INSERT statement (the last > > > value of i) > > > > > > I suspect that this is to vague for anyone to be able to help, but if > > > anyone has any ideas I'd be really grateful :-) > > > > > > It occured to me that if I could access the mysql query log that might > > > help, but I was unsure how to enable logging for MysQL with python. > > > > > > Cheers, > > > > > > Ben > > > > Not sure this will help but where is the "commit"? I don't use MySQL but > > most SQL engines require a commit. > > Johnf From rpw3 at rpw3.org Fri Dec 8 16:17:07 2006 From: rpw3 at rpw3.org (Rob Warnock) Date: Fri, 08 Dec 2006 15:17:07 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165604171.448549.192640@j44g2000cwa.googlegroups.com> Message-ID: Pillsy wrote: +--------------- | hankhero wrote: | > Pythons advantages are: | > Faster startup-time which makes it a good scripting language. | | ... but on my machine, SBCL starts up and runs a "Hello World" | program a bit faster than Python, and CLisp really blows its doors off. +--------------- On my various machines, CMUCL startup is *slightly* faster than CLISP, but both are under 20 ms... I use Common Lisp for scripting a *lot*! -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From xah at xahlee.org Tue Dec 5 10:40:09 2006 From: xah at xahlee.org (Xah Lee) Date: 5 Dec 2006 07:40:09 -0800 Subject: logo design Message-ID: <1165333204.582656.325850@80g2000cwy.googlegroups.com> Logo LISP Xah Lee, 2006-12 Ken Tilton wrote: ?Small problem. You forget that Ron Garret wants us to change the name of Common Lisp as the sure-fire way to make it more popular (well, hang on, he says it is necessary, not sufficient. Anyway...) I do not think we can safely pick a new logo until we have our new name.? Changing a language's name is not something that can be easily done, and is unnatural and takes concerted effort, and is very difficult for it to be successful. However, creating a (universally recognized) logo for the language, is easily done, and in fact the use of a logo or some representative image is inevitable and wide-spread, willy-nilly. For example, although there are no official logos for lisp, but as you know, there are several logos or images of various forms that are already used widely, either to represent lisp the language family, or to represent the Common Lisp language. And, for various Scheme implementation, they almost all had a logo of their own. Example: above: The ?twisty AI font? LISP logo. Used by http://lisp.org/ as early is 2001. above: The ?earth in parenthesis? logo, used by http://lisp.org/ as of 2006-12. above: Conrad Barski's ?alien technology? lisp web-badges (source ?), which appeared in 2005. above: Manfred Spiller's ?lizard? lisp web-badge (source ?), which appeared in 2005. As these examples shows, that the use of a logo is needed in practice. However, it wouldn't help if there are one hundred different logos to represent the same thing. The point of logos, is to have a memorable, graphical representation. In modern, capitalistic, societies filled with information, the use of logos is inevitable. Just look around you at this very moment, you probably can identify tens of logos, and for each logo, you probably recognize what they represent. Logos, is merely a graphical representation of a entity, whose textual analogous counterpart are names. Since there is a need for logos, we might as well get together and agree to have one official logo for lisp the language. That way, it solidifies the purpose of the logos in use. Note that, although we have the beautiful ?lisp lizard? and ?alien technology? graphics, but because of their graphic content and in particular the embedded slogan, they do not fit as a logo, but more as web-badges. Web-badges serve slightly different purpose than logos. It is more for the purpose of promotion, than representation. For the same reason, there are mascots. For example, Java the language, has a official logo of a smoking coffee cup, but also has a mascot of a penguin named ?Duke?. above: The official Java logo, and its mascot. The World Wide Consortium organization (http://www.w3.org/) also has a logo, and it has various web-badges for its various web technology validation services. above: The official logo of the The World Wide Consortium organization, and the web-badge of its XHTML validation. The history of Python community's logo is a good example of the eventual recognition of a need for a unified, official logo. above: Old, widely used but not officially blessed logo for Python, used up to 2005. above: Various logos, application icon, and badges that has been used for Python. above: Official Python logo of ?double snakes?, inaugurated in 2005. ---- This post is archived at: http://xahlee.org/UnixResource_dir/writ/logo_lisp.html Xah xah at xahlee.org ? http://xahlee.org/ From basti.wiesner at gmx.net Wed Dec 27 15:20:06 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 27 Dec 2006 21:20:06 +0100 Subject: getting a process's PID References: <20061227102939.L20663@eris.io.com> <20061227135600.O21223@eris.io.com> Message-ID: eldorado typed [snip] > This looks cleaner than the way I was going. I created a file > called ps.py > > #!/usr/local/bin/python > import os > g = os.popen("ps -e -o pid,command") > for line in g.readlines(): > if 'HUB' in line: > pid = line.strip().split(' ')[0] > break > print pid > > When I run ps.py I get the following error. > > Traceback (innermost last): > File "./ps.py", line 5, in ? > if 'HUB' in line: > TypeError: string member test needs char left operand Strange!? On my system with Python 2.4 I don't get this error. It is likely to be a problem of your really ancient python version. Do I guess correctly from your previous postings, that you're still using version 1.4?. The only thing, you could advice you to, is to replace the line with the following code, which should do very much the same thing: >>>> if line.find('HUB') > -1: If you are really using version 1.4, you should replace the next line, too, because string methods came after 1.4: >>>> pid = string.split(string.strip(line), ' ')[0] Bye Sebastian Wiesner -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From kkylheku at gmail.com Mon Dec 11 03:07:51 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 11 Dec 2006 00:07:51 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165793825.487994.52430@f1g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> Message-ID: <1165824471.730090.153530@j72g2000cwa.googlegroups.com> Paddy wrote: > http://en.wikipedia.org/wiki/Doctest I pity the hoplelessly anti-intellectual douche-bag who inflicted this undergraduate misfeature upon the programming language. This must be some unofficial patch that still has a hope of being shot down in flames, right? From http Mon Dec 11 20:24:37 2006 From: http (Paul Rubin) Date: 11 Dec 2006 17:24:37 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> <7xwt4yju5e.fsf@ruckus.brouhaha.com> Message-ID: <7x1wn57voq.fsf@ruckus.brouhaha.com> Espen Vestre writes: > > Can you redefine CLOS methods without calling CLOS functions that tell > > the object system what to expect (so it can do things like update the > > MRO cache)? I.e. can you redefine them by poking some random > > dictionary? You can in Python. I don't claim that's a good thing. > > Just as I said: Less managable, but not more dynamic. I'm not getting through to you. Yes, you could create a Python-like object system in Lisp that's separate from CLOS, but nobody would use it. It wouldn't matter whether you could compile it efficiently or not, since nobody would care. What matters is that you can compile CLOS efficiently. Python's object system is used in every Python program and it has those properties and if you try to remove them, you don't have Python any more. A Python compiler has to deal with that. So compiled Python code is necessarily going to suffer compared with compiled Lisp code. From no-spam at no-spam-no-spam.invalid Fri Dec 1 11:38:22 2006 From: no-spam at no-spam-no-spam.invalid (robert) Date: Fri, 01 Dec 2006 17:38:22 +0100 Subject: Pimping the 'cgi' module In-Reply-To: References: <1164306918.845529.95820@f16g2000cwb.googlegroups.com> Message-ID: Harry George wrote: > When I came from Perl, I too missed perl-isms and specifically CGI.pm, so wrote my own: > http://www.seanet.com/~hgg9140/comp/index.html > http://www.seanet.com/~hgg9140/comp/pyperlish/doc/manual.html > http://www.seanet.com/~hgg9140/comp/cgipm/doc/index.html > > Others on this newsgroup said I'd be better off just doing it in raw > python. After a while, I realized that was true. You do > triple-quoted templates with normal python idioms. Throw in > some persistence mechanisms to deal with maintaining state across > transactions, and you are in business. > > Since then I've looked at Zope, Plone, TurboGears, Django, and (for > standalone apps) Dabo. TurboGears is mostly a set of recommendations > on what 3rd party packages to use, with a wee bit of glueware. So far > nothing feels as simple as just doing it in python. Thats the fragmented journey, almost any web programmer has to go when coming to python. A clear standard, even a clear intro, for simple tasks, like doing state mng, db, error handling, etc. is not there on an easy path. For a level above cgi, what do you think about cherrypy ? http://docs.cherrypy.org/ Robert From eadmund42 at NOSPAMgmail.com Wed Dec 13 13:49:07 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Wed, 13 Dec 2006 11:49:07 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> Message-ID: Christophe writes: > Robert Uhl a ?crit : > >> The argument from popularity is invalid. French units have overtaken >> standard units, > > Never heard of that French unit thing. Unless you talk about that > archaic unit system that was in use before the metric system was > created. I use 'French units' instead of the term 'metric system' because the latter means 'measurement system,' and of course could validly be applied to _any_ system. -- Robert Uhl Due to an obsessive book-buying habit, and less time to read than I would like, my to-read pile now has its own bookcase. --stevo From john.thingstad at chello.no Wed Dec 13 05:44:03 2006 From: john.thingstad at chello.no (John Thingstad) Date: Wed, 13 Dec 2006 11:44:03 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4579c4f4$0$49201$14726298@news.sunsite.dk> <1165971298.617221.59450@n67g2000cwd.googlegroups.com> <1165976006.329013.54380@73g2000cwn.googlegroups.com> Message-ID: On Wed, 13 Dec 2006 03:13:26 +0100, Paddy wrote: > Not even close. > > In my example above: > for a in y: > dosomethingwith(a) > y could be a lot of built-in types such as an array, list, tuple, dict, > file, or set. > - Paddy. > I was refering to the recursive Lisp example. Did you even read the post? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From http Fri Dec 8 21:22:15 2006 From: http (Paul Rubin) Date: 08 Dec 2006 18:22:15 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: <7x1wn9st9k.fsf@ruckus.brouhaha.com> Bill Atkins writes: > This is a silly claim. What observational experience are you talking > about? Lisp is delightfully readable. In fact, I find it more > readable than any other language. Why do you think that is? Could it > be because I use Lisp on a daily basis? Could that also explain why > Python seems more readable than Lisp to you? Python is more readable than Lisp because it stays readable even if you don't use it on a daily basis. From Dennis.Benzinger at gmx.net Thu Dec 14 16:37:06 2006 From: Dennis.Benzinger at gmx.net (Dennis Benzinger) Date: Thu, 14 Dec 2006 22:37:06 +0100 Subject: automatically grading small programming assignments References: Message-ID: <20061214223706.6bf4a45d@dennis-laptop> Am Thu, 14 Dec 2006 12:27:07 -0500 schrieb Brian Blais : > Hello, > > I have a couple of classes where I teach introductory programming > using Python. What I would love to have is for the students to go > through a lot of very small programs, to learn the basic programming > structure. Things like, return the maximum in a list, making lists > with certain patterns, very simple string parsing, etc. > Unfortunately, it takes a lot of time to grade such things by hand, > so I would like to automate it as much as possible. > > I envision a number of possible solutions. In one solution, I > provide a function template with a docstring, and they have to fill > it in to past a doctest. Is there a good (and safe) way to do that > online? Something like having a student post code, and the doctest > returns. I'd love to allow them to submit until they get it, logging > each attempt. > > Or perhaps there is a better way to do this sort of thing. How do > others who teach Python handle this? > > > thanks, > > > Brian Blais > Perhaps the Sphere Online Judge can help you: https://www.spoj.pl/info/ Dennis From filipwasilewski at gmail.com Thu Dec 14 18:10:39 2006 From: filipwasilewski at gmail.com (Filip Wasilewski) Date: 14 Dec 2006 15:10:39 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> <1166035311.357588.115070@80g2000cwy.googlegroups.com> <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1166137839.139465.280830@16g2000cwy.googlegroups.com> Jon Harrop wrote: > Filip Wasilewski wrote: > > Jon Harrop wrote: > >> Filip Wasilewski wrote: > >> > Jon, both Python and Matlab implementations discussed here use the > >> > lifting scheme, while yours is a classic convolution based approach. > >> > >> I've done both in OCaml. The results are basically the same. > > > > Have you tried taking advantage of the 50% reduction of arithmetic > > operations for the lifting scheme? > > Yes. The time taken is dominated by memory accesses. The amount of > arithmetic is almost irrelevant. I can say from my experience, that this depends much on the input size and the CPU cache size. For arrays of about n^18 or less and 2MB cache the speedup for the straightforward C lifting implementation is around 50%, while all operations are done in-place. For bigger arrays traversing memory several times becomes too expensive, at least until the input size is so big that the memory gets swapped and the inplace method becomes faster again. I suppose that such behavior should be quite similar for other low-level implementations as well. Actually I started to wonder if I could automate conversion of multi-loop lifting schemes [1] into one-pass loop. This could be done by delaying computation of the "coming next" step just by few units, until values from the preceding step are ready to use. This should reduce the random memory access effect for several cases and make the timings quite stable. [1] http://en.wikipedia.org/wiki/Lifting_scheme > >> It makes sense because they solve the same problem. When you're comparing > >> non-trivial problems between disparate languages you are not likely to > >> use the same algorithms. Using built-in hash functions is an obvious > >> example. > > > > I don't even ask if you have checked the output result coefficients > > because I'm pretty sure you have not. > > I checked the coefficients against other DWTs from the web. > > > They solve similar problem but in > > different ways and give a bit different results, for example the > > layout of coefficients in the memory is different as well as border > > distortion handling. Please don't tell me it's better to do something > > else instead of presenting a relevant solution. > > I used a more efficient approach because I could. Using a compiled language > gave me that choice. We should compare both approaches in both languages. I am getting a bit tired of this discussion. I am not arguing which approach is faster, because it very much depends on the use case. I just ask you to do fair comparison using the original algorithm presented here instead of forcing your arguments with the not-so-relevant variant convenient for you. Every language (or at least vast majority of them) that has loops and basic arithmetic gives you such choice, no matter compiled or not. These are pretty simple algorithms when limited to single D4 case, but the D4 is not the only wavelet transform known to mankind and there are situations when you do not have such choice, because some problems just can't be expressed using the classic approach. If the OCaml is so superior as you claim, please show me how to do the lifting scheme (preferably in the http://groups.google.com/group/comp.lang.python/msg/a71a5bf00a88ad57 form with features described in my previous post) so I could actually learn something new and maybe even start to consider it as a possible alternative to C-ish language family. As far as the DWT only is concerned, well, If I were to choose the most efficient approach (in both the CPU time and the development time terms) for Python I would use a ready extension instead of developing the wheel once again. Let me think, that should go something like this: import pywt coeffs = pywt.wavedec(x, 'db2', 'per') > >> No. The effects you are talking about are swamped by the interpreted vs > >> compiled effect. > > > > Have I already mentioned it was observed with low-level C > > implementation on x86? I would really appreciate you took some time on > > exploring the unfortunate topic of this benchmark before posting > > another comment like that. > > We are talking about this Python implementation, not some "low-level C > implementation on x86". With Python, it is the overhead of the interpreter > that makes it slow and encourages you to obfuscate your code in order to > make it run in a reasonable amount of time. I was talking about why you should not limit your benchmarks to the very single case and gave example how the choice of parameters can influence the results. It has nothing to do with the interpreted vs. compiled harangue. Would you argue that some O(n^2) algorithm is always better than it's O(n) alternative just because it has lower call overhead and performs better under some limited circumstances? > > What I would really like to see is a lifting scheme > > implementation that can take 1- to 10-dimensional arrays > > I believe that is just a case of abstracting get/set. > > > (single and double precision floats, > > That is also a case of abstracting get/set. > > > convert on the fly from integer types when necessary > > That is dynamic typing. > > > and handle strided, non-contiguous arrays), > > That is also an abstraction of get/set. Oh my, are all these abstractions to be put into reality every time from a scratch? > > axis and maximum decomposition level as input > > I don't know what that is. When doing 1D operations on a multidimensional array it is often convenient to be able to specify along which axis these operations should be performed, for example: >>> x = numpy.ones((2,4)) >>> x.sum(axis=0) array([ 2., 2., 2., 2.]) >>> x.sum(axis=1) array([ 4., 4.]) The maximum level denotes how many decomposition steps should be performed for multilevel transform. Just like described on http://www.mathworks.com/access/helpdesk/help/toolbox/wavelet/wavedec.html > > and return list of views (or arrays if necessary) > > Probably just a closure. > > > with transform coefficients for every level of > > decomposition. Can do? > > Sure. Sounds like a lot of work though. See. It's for sure pretty much work to create a general solution in C. It is a lot easier to focus on the real problem when using Python (and NumPy or other package from a wide range of available extensions) and save yourself getting much into implementation details while still maintaining reasonable performance. That is one of the most important reasons I prefer to use high-level language for most of my tasks. I also try to avoid doing premature optimizations that could spare some CPU cycles, just to see in a few moments that the performance gain is completely swallowed by I/O overhead on some remote data access point. For the rest of intensive number crunching, if there is no specialized extension available yet, I still prefer to use the Python/Pyrex/C or similar combo to get solution that can be easily integrated with other parts of a bigger system (like networking, databases, reports, web, etc. - wow, how many things the transition from C++ and Java few years ago made just so accessible) or just used to play in the interactive mode. > This would be best done in F# > because you can make your own IList derivatives with get_Item and set_Item > that provide views but look like arrays. > > > Are you telling I have to define a different operator for every > > arithmetic operation for every two types? > > In OCaml, yes. Not in F#. > > > That definitely does not look > > like a quick, flexible and clear solution to start with. Any working > > example I could type into OCamlWinPlus of the following would be very > > appreciated. I'm fairly new to this and would really like to see how to > > handle differently shaped arrays and data types in the interactive mode > > without much hassle: > > > > from numpy import ones, arange, reshape, int32 > > a = ones((2,3,4,5)) > > b = ones(a.shape, dtype=int32) > > c = ones((3,4,5)) > > d = 2*a + 2.5*(3*b + 3.3) > > d[0] = d[0] + 5 > > d[1] *= c * (2+3*1.2) > > d[:,2,...] = reshape(arange(d[:,2,...].size), d[:,2,...].shape) > > print d[...,1] > > I can't get that to work in Python. What do I need to do? Type exactly as presented above, starting from the very first line. The `from module import ...` imports chosen identifiers into current namespace, so you don't have to prefix them with module name. > >>> import numpy > >>> a = ones((2,3,4,5)) > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'ones' is not defined > > > The ray tracer example is really nice, however the sudoku solver is not > > so impressive when compared to the K thingy ;-) - > > http://markbyers.com/moinmoin/moin.cgi/ShortestSudokuSolver. > > Well, OCaml does ok on the sudoku but K does awfully on the ray tracer. That's pretty natural. Different languages are designed to solve different tasks. I hope your point is not to convince people to use OCaml to solve (or complicate) every possible problem. > > Where can I find > > documentation or tutorial on using Bigarrays? > > http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html Yes, I found this before but it is not very helpful to start with. Any doc with basic use cases and examples would be much better. Think of it as a possible restraint for people trying to learn the language. > You probably want to use F# though. On the other hand, I wonder how this integrates with other .net languages like C# or IronPython. cheers, fw From mail at microcorp.co.za Fri Dec 29 00:38:38 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 29 Dec 2006 07:38:38 +0200 Subject: (PyGTK) Disabling ToolButton when no TreeView item is selected? References: <1167325052.790540.121810@42g2000cwt.googlegroups.com> Message-ID: <012601c72b0b$97abc5c0$03000080@hendrik> "cypher543" wrote: > I have a TreeView and a ToolButton. The ToolButton should only be > active if the user has selected an item in the TreeView. What signal > should I use to achieve this? you can try using the configure method on the toolbutton in the command that is executed when the tree view is selected/deselected - Hendrik From mail at microcorp.co.za Thu Dec 21 00:13:16 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 21 Dec 2006 07:13:16 +0200 Subject: SQLALCHEMY - Method to have the last word, by Michael Bayer References: <1166543077.605993.276770@80g2000cwy.googlegroups.com><4uqgeuF19khhgU1@mid.uni-berlin.de> <4use11F19cameU1@mid.uni-berlin.de> Message-ID: <01f401c724cb$8eece7c0$03000080@hendrik> "Diez B. Roggisch" wrote: > Hendrik van Rooyen wrote: > > > Wearing skull socks makes you mean. > > Ahh, I guess you're right - that twitching in my feet.... I should get rid > of them, wear cherubim socks instead and take a more relaxed stance towards > Ilias and his kind. > > If only I manage to really do this until "they" convince me to keep them, > wearing them even in my sleep... > Is there some of way of suppressing the deadly information in this thread before the Spanish Inquisition sees it ? - Hendrik From webraviteja at gmail.com Sun Dec 10 19:39:39 2006 From: webraviteja at gmail.com (Ravi Teja) Date: 10 Dec 2006 16:39:39 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165596641.245385.113090@f1g2000cwa.googlegroups.com> <1165704007.887869.192290@16g2000cwy.googlegroups.com> Message-ID: <1165797579.456875.275420@l12g2000cwl.googlegroups.com> > Why? The benefit of expressiveness and power isn't monotonically > increasing. Look at us: we're all communicating in a common language, > English, and we all agree on syntax and grammar. I think we all agree that with flexibility comes abuse "potential". But if that potential will actually be likely realized or that we are just being scared of a phantom can only be determined by empirical evidence. While, reliable empirical evidence is hard to get in programming languages, we can only ask the people who use the languages which support features like macros and tell us what they feel about them rather than make arguments based on hypothetical possibilities. So far I am hearing a near unanimous statement from users of these languages that while there is abuse potential, they do not use it in that manner and that they are glad that the feature is available than not. Of course, people tend to defend the languages (or just about any skill) that they have invested in. Especially when they are not aware of the alternatives. But this does not seem to be the case with these people. Macros continue to be incorporated in the latest languages (OCaml, Boo, Nemerle) with no reports of abuse. But then again, Python may not be the right language for macros. We try to have a language that is easy for beginners while having sufficient richness for advanced users. The abuse potential could potentially be higher with excess expressiveness as we have seen with Perl. That might be a good argument to not make Macros a part of language but not so much as to not have external support. I doubt that Logix did not catch on because people thought it was too dangerous to use. 3 likely reasons are. 1. They did not hear about it. 2. They did not understand it. 3. The current implementation is slow. > Now, I could be a lot > more expressive, and language could be a lot more powerful, if I could > define my own language where "You are a poopy-head" was in fact a detailed > and devastatingly accurate and complete explanation for why Python was a > better language than Lisp. This is exactly what I meant by a phantom. Could you show me some any Lisp macros in the wild that show this kind of abuse? You could just as egregiously abuse Python's dynamic typing and metaclasses. And it is likely that some do that. But I have not seen any Python library worth mentioning with such abuse. All the Python programmers I have seen, seem a lot more sensible than you seem to give credit. And that is the whole point of "We are all adults here" argument that you seem to side step. From jtgalkowski at alum.mit.edu Wed Dec 27 11:49:20 2006 From: jtgalkowski at alum.mit.edu (Jan Theodore Galkowski) Date: Wed, 27 Dec 2006 11:49:20 -0500 Subject: Smalltalk asPython Message-ID: <1167238160.5578.282146039@webmail.messagingengine.com> On Tue, 26 Dec 2006 22:49:30 -0500, Jan Theodore Galkowski wrote: >> Hi. >> >> One of the things I'd like to do with Python is find a way to >> consistently implement Smalltalk's "loose methods". This is a >> capability whereby additional methods can be added dynamically to >> existing classes. > >You can't modify the built-in classes. I'm not sure that it is a good >idea to allow built-ins to be modified. When I see an int, I like the >fact that I know what the int can do, and I don't have to worry about >whether it has been modified by some piece of code elsewhere. Yes, that's the usual reaction on the part of Smalltalk newbies, too. But the point is that the inserting of loose methods are just as much a part of the current module as any other part of it, so the behavior of the classes in the module needs to be understood in the context of the amendments provided by the loose methods. Similarly, the amendment of these fundamental classes by a new class is an effect of the module and if the module is used is understood to be something it does. Also, sometimes adding such a loose method to a built-in class let things be done with reflection easily, such as for "int": Perhaps there's an application context where the ordinal nature of "int"s is more important than their cardinal nature, and such a reflection would allow it to be easily implemented: int.ordinalQuizzle( self ) : return SpecialOrdinalQuizzleClass.ordinalQuizzleRealizer( self ) ; It is considered bad form to amend the behavior of *existing* methods in built-in classes of the class library. Usually, loose methods *add* new function only. >But custom classes can be modified (the risk of some other code >modifying it is the price you pay for being able to customise the class >in the first place): Yes, thank you, Steven, that was the point of my "isFoo" illustration. [snip] >Why not just say isinstance(x, Foo)? And, yes, i know about "isinstance(.,.)". I was using it purely for easy illustration. >> Like, then, what of other classes which descend from object and not >> MutableObject? You'd love to be able to set methods and attributes >> within them. Can you? >Yes you can. Did you bother to try it? Yes, I did, as illustrated above, with the MutableObject class. The point is that you'd like all the intervening classes to inherit the amendment at the root of the hierarchy within having to touch all the lateral intervening classes or without having to redefine the intervening classes. Thus, my concern is probably overstated. All that needs to be done in practice is *know* what are the classes which derive directly from, say, "int" in a system and insert the loose methods into those, and the rest will follow. It's just that if you can augment "object" or "int", you don't even need to know that. [snip] Thanks for the thoughts. - Jan From raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com Sat Dec 16 14:37:56 2006 From: raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com (Raffael Cavallaro) Date: Sat, 16 Dec 2006 14:37:56 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45844272$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <2006121614375650878-raffaelcavallaro@pasdespamsilvousplaitmaccom> On 2006-12-16 13:58:37 -0500, Jon Harrop said: > Why do you think that uniform syntax is necessary to provide new paradigms > when it is equivalent to infix syntax? Because it doesn't require one to write a parser for each new syntax for each new paradigm. > In what way is Haskell's support for imperative programming limited? It requires one to frame everything in functional terms or to jump through the hoop of monads. > Can you give an example of a Lisp macro that does something useful that you > can't do in these other languages? It isn't a question of "can't do in these other languages," it's a matter of "can't do as easily in these other languages." Look at kenny tilton's cells. Its a dataflow paradigm built largely of macros. It goes completely against the semantics of haskell - cells is all about the eager evaluation of side effecting state mutation. Could you do it in haskell? Yes, in the greenspun/turing-completeness sense, but not nearly as easily as in common lisp, because the very paradigm - eager evaluation combined with side effecting state mutation - goes against the basic semantics of haskell. You'd have to jump through extra hoops to build a system whose very nature contradicts two of the semantic foundations of haskell - laziness and absense of side effects. Then there's the issue of the new syntax. Easy to build in lisp without learning another language - lisp macros use lisp. What little I've seen of caml4p looks like perlesque line noise. Ultimately I think that the defaults of both haskell and ocaml - functional, static typing, non-uniform syntax - are things I don't want as defaults, but as options for later in the development of only certain pieces of code. I don't want to be required to jump through the pure-functional, must-use-monads-for-any-side-effects, static-type, non-uniform-syntax hoops to express my ideas. It makes me less flexible in dealing with individual parts of a program differently. From sjmachin at lexicon.net Mon Dec 4 00:28:13 2006 From: sjmachin at lexicon.net (John Machin) Date: 3 Dec 2006 21:28:13 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> Message-ID: <1165210093.570351.288220@n67g2000cwd.googlegroups.com> Jean-Paul Calderone wrote: > On 3 Dec 2006 17:23:49 -0800, Russ wrote: > > > >> Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. > > > >Now, that would be rather silly. I would have to familiarize myself > >with the code for the Python interpreter, then send a patch to the > >maintainers (and hope they notice it in their inboxes), while the > >maintainers themselves could probably "fix" the problem in two minutes > >flat. No thanks! > > And I have some laundry that I would like you to do for me. Let me know > when a convenient time for you to pick it up would be. > > Jean-Paul Perhaps a better analogy is that the OP has observed (correctly IMHO) that the robes of *all* Pythonistas, including those not yet born and those not yet converted from heathen languages, could be whiter than what they are. There are others whose capability to implement an enhancement is likely to be much greater than his. IOW, apart from being somewhat impolite, he may: * not be able to write C * not understand that apart from listobject.c, he might have to patch (OTTOMH) stringobject.c, tupleobject.c, arraymodule.c and who knows what else [see below] * not come up with a good message Would the following be acceptable, BTW? | >>> [4, 5, 6][10] | IndexError: list index 10 out of range(3) | >>> [4, 5, 6][-4] | IndexError: list index -4 out of range(3) or would something like ... out of range; len is 3 be better? Footnote: Based on 2.4.3 source, quite a few files, many with multiple lines to patch: C:\Python_source\Python-2.4.3\Objects>grep -n "index out of range" *.c File bufferobject.c: 406 PyErr_SetString(PyExc_IndexError, "buffer index out of range"); 450 "buffer assignment index out of range"); File listobject.c: 144 "list index out of range"); 165 "list assignment index out of range"); 389 "list index out of range"); 693 "list assignment index out of range"); 881 PyErr_SetString(PyExc_IndexError, "pop index out of range"); File rangeobject.c: 143 "xrange object index out of range"); File stringobject.c: 1041 PyErr_SetString(PyExc_IndexError, "string index out of range"); File structseq.c: 62 PyErr_SetString(PyExc_IndexError, "tuple index out of range"); File tupleobject.c: 104 PyErr_SetString(PyExc_IndexError, "tuple index out of range"); 123 "tuple assignment index out of range"); 310 PyErr_SetString(PyExc_IndexError, "tuple index out of range"); File unicodeobject.c: 5241 PyErr_SetString(PyExc_IndexError, "string index out of range"); C:\Python_source\Python-2.4.3\Modules>grep -n "index out of range" *.c File arraymodule.c: 599 PyErr_SetString(PyExc_IndexError, "array index out of range"); 767 "array assignment index out of range"); 997 PyErr_SetString(PyExc_IndexError, "pop index out of range"); File collectionsmodule.c: 399 "deque index out of range"); 461 "deque index out of range"); File mmapmodule.c: 648 PyErr_SetString(PyExc_IndexError, "mmap index out of range"); 736 PyErr_SetString(PyExc_IndexError, "mmap index out of range"); File regexmodule.c: 181 PyErr_SetString(RegexError, "group() index out of range"); File _heapqmodule.c: 19 PyErr_SetString(PyExc_IndexError, "index out of range"); 58 PyErr_SetString(PyExc_IndexError, "index out of range"); 136 PyErr_SetString(PyExc_IndexError, "index out of range"); 173 PyErr_SetString(PyExc_IndexError, "index out of range"); 310 PyErr_SetString(PyExc_IndexError, "index out of range"); 349 PyErr_SetString(PyExc_IndexError, "index out of range"); Cheers, John From fredrik at pythonware.com Fri Dec 1 01:50:47 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 01 Dec 2006 07:50:47 +0100 Subject: Python25.zip In-Reply-To: References: Message-ID: Colin J. Williams wrote: > As part of the Python initialization, C:\Windows\System32\Python25.zip > is set up in the path. > > I haven't seen any documentation on the use or purpose of the zip file. http://docs.python.org/lib/module-zipimport.html http://www.python.org/peps/pep-0273.html From kentilton at gmail.com Fri Dec 15 10:47:51 2006 From: kentilton at gmail.com (Ken Tilton) Date: Fri, 15 Dec 2006 10:47:51 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1166175804.202131.54070@l12g2000cwl.googlegroups.com> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> <1166175804.202131.54070@l12g2000cwl.googlegroups.com> Message-ID: xscottg at gmail.com wrote: > Ken Tilton wrote: > >>Andrew Reilly wrote: >> >> >>> That all looks like data. >> >>No, not reverse, the part you did not understand. I do not mean what the >>code was doing, I meant that it was code. >> > > > Code is data is code I was hoping no one would make that mistake. :) macros are all about code is data, but code is not data in Python* so the two words code and data serve to differentiate them for Pythonistas. * Taking questions after a keynote to ILC200? where he reiterated that Python was the same as Lisp for all intents and purposes: Norvig: "Yes, John?" McCarthy: "Is code also data in Python?" Norvig: "No." End of exchange. :) >- even in Python: This could be tougher than I thought. > > skills_table = [ > { > "title": "Absolute Value", > "annotations": ["Bleah bleah", "ho hum", "etc..."], > "hints": ["and so on", "etc..."], > "reverse" : (lambda x: whatever(x)) That does not demonstrate that code is data, that demonstrates that a lambda is a first-class object (and, yes, Python's lambda is lame). You will know you have code as data when you can write Python code that takes apart "whatever(x)" and produces "oh-now-I-get-it(y)". As part of the language, such that Python applies your transforming code for you whenever it sees whatever. (Hell, even C has a preprocessor.) > }, > { > "title": "Square Root", > "annotations": ["Bleah bleah", "ho hum", "etc..."], > "hints": ["and so on", "etc..."], > "reverse" : (lambda x: someother(x)) > }, > # etc... > ] > > Of course those lambdas are crippled in Python (and not really > necessary in this bogus example)... But that's without trying to be > clever: > > class AbsoluteValue: > title="Absolute Value" > annotations=["Some list", "goes here"] > @classmethod > def reverse(cls, *args): > # I didn't understand what your code was doing yeah, and god forbid you should ask. :) this is the crux of the matter! Actually, it is kinda cool that you and Greg are semi-identifying the crux by saying "this is the only bit I do not get, I'll skip this, move on, nothing to see here". > pass > defskill(AbsoluteValue) > > That would be a reasonable place for a "pie decorator" on a class, but > I guess that's not allowed. Hmmm. Actually, that is the whole point, all of Python is allowed. decorators were used in PyCells, but I never got much of an idea what they did. Is there a moral equivalent of a macroexpansion for decorators so you can show the before and after? > I doubt this second example would be > considered "Pythonic" in any case... exactly what we are looking for in this cultural exchange: how would Python handle what I am doing with macros in the reverse functions? Make it as slick and programmer-friendly (cuz I may get to a hundred of these before I am done with Algebra I) as possible. When all the Pythonistas proclaim it optimal, then we compare and contrast. This, btw, is the Tilton Test for language comparison: Not measurements of programmer effort, rather examination of perfect equivalent code. PyCells vs Cells would be an amazing case, because that is some hairy functionality. >>Not the code. In reverse. >> > Why not? Is, too! (ie, I am kinda looking for a specific question that conveys understanding of the use case.) > Python has plenty of other flaws that I can't happily work around, and > I do think Lisp is more flexible. However, I think your example is > readable enough with a data driven algorithm in most any popular > language. All of the data is visible to the reverse(...) method. > Maybe I missed something in your example, but I think you aren't trying > hard enough. :-) Precisely. I am not trying at all. I am coding between visits to Usenet. This use case just popped up and was pretty simple (at first, before I got to the reverse function) so I dropped it off. This is a wild macro, not farm-bred, deliberately crafted to embarrass macro. A real live natural comes up all the time working wouldn't want to code without it macro. I could have searched my code base to find more brutal cases, but this is short and sweet and unforced and uncontrived and wheres my thesaurus? ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From wconnery at dodo.com.au Mon Dec 4 20:18:08 2006 From: wconnery at dodo.com.au (William Connery) Date: Tue, 05 Dec 2006 12:18:08 +1100 Subject: Monitoring number of smtp bytes sent through python e-mail socket Message-ID: <4574C8D0.8060603@dodo.com.au> Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an e-mail with an attachment. I want to give users an indication of the percentage of the e-mail that has already been sent so as to avoid frustration when dealing with large attachments or a slow smtp server. But the smtplib module doesn't seem to provide access to the number of bytes that have already been sent. Can anyone help, or provide a working example of sending an e-mail attachment using basic python sockets whilst having access to the number of bytes that have already been sent through the socket? Many thanks. William Connery #!/usr/bin/python import wx import smtplib from email import Encoders from email.MIMEMultipart import MIMEMultipart from email.Utils import COMMASPACE, formatdate from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText import os # set a few variables to make testing less tedious # you need to set your smtp server domain name smtp_server = 'smtp.your_isp_domain.com' toemail = 'toemail at somedomain.org' fromemail = 'fromemail at anotherdomain.org' subject = 'Testing python smtplib module' emailmsg = 'How do I determine the number of bytes that ' +\ 'have been forwarded whilst the e-mail is being sent ?\n\n' +\ 'Sending large (or many) attachments may take some ' +\ 'time, and I\'d like to use a gauge control to give users ' +\ 'an indication of the percentage of the e-mail that has ' +\ 'already been sent.\n\nThe smtplib module relies on ' +\ 'sockets, but I don\'t know how to use python sockets ' +\ 'to send an e-mail with attachments and concurrently ' +\ 'monitor the number of bytes that have already been ' +\ 'sent.\n\nHelp !' # attachment file attachment = 'C:\\Documents and Settings\\-\\Desktop\\test.zip' #attachment = '/home/user1/Desktop/test.zip' # variable to hold bytes that have been sent bytes_sent = 0 class MainFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.SetSize(wx.Size(750,550)) self.SetTitle('Monitoring the number of bytes sent during ' +\ 'a python e-mail send - How ?') panel = wx.Panel(self) vertsizer = wx.BoxSizer(wx.VERTICAL) flexsizer = wx.FlexGridSizer(rows=8, cols=2, hgap=10, \ vgap=10) flexsizer.AddGrowableCol(1) flexsizer.AddGrowableRow(4) tolabel = wx.StaticText(panel, -1, "To E-mail Address:") flexsizer.Add(tolabel,0,wx.ALIGN_RIGHT|\ wx.ALIGN_CENTER_VERTICAL) self.toemailaddress = wx.TextCtrl(panel) flexsizer.Add(self.toemailaddress,0,wx.EXPAND) fromlabel = wx.StaticText(panel, -1, "From E-mail Address:") flexsizer.Add(fromlabel,0,wx.ALIGN_RIGHT|\ wx.ALIGN_CENTER_VERTICAL) self.fromemailaddress = wx.TextCtrl(panel) flexsizer.Add(self.fromemailaddress,0,wx.EXPAND) attachmentbutton = wx.Button(panel, 1001, "File Attachment") attachmentbutton.Bind(wx.EVT_BUTTON, \ self.SelectAttachmentFile) flexsizer.Add(attachmentbutton,0,wx.ALIGN_RIGHT|\ wx.ALIGN_CENTER_VERTICAL) self.attachmenteditbox = wx.TextCtrl(panel,\ style = wx.TE_CENTRE) self.attachmenteditbox.Disable() flexsizer.Add(self.attachmenteditbox,0,wx.EXPAND) subjectlabel = wx.StaticText(panel, -1, "Subject:") flexsizer.Add(subjectlabel,0,wx.ALIGN_RIGHT|\ wx.ALIGN_CENTER_VERTICAL) self.subject = wx.TextCtrl(panel) flexsizer.Add(self.subject,0,wx.EXPAND) messagelabel = wx.StaticText(panel, -1, "E-mail Message:") flexsizer.Add(messagelabel,0,wx.ALIGN_RIGHT) self.emailmessage = wx.TextCtrl(panel, \ style = wx.TE_MULTILINE) flexsizer.Add(self.emailmessage,1,wx.EXPAND) flexsizer.AddSpacer(wx.Size(1,1)) self.gauge = wx.Gauge(panel) self.gauge.SetRange(100) self.gauge.SetValue(30) sendbutton = wx.Button(panel, 1001, "Send E-mail") sendbutton.Bind(wx.EVT_BUTTON, self.SendTheEmail) hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.Add(self.gauge,1,wx.RIGHT,15) hsizer.Add(sendbutton,0,wx.ALIGN_CENTER_VERTICAL) flexsizer.Add(hsizer,0,wx.EXPAND) byteslabel1 = wx.StaticText(panel, -1, "Bytes to Send:") self.bytestosend = wx.StaticText(panel, -1, "0") flexsizer.Add(byteslabel1,0,wx.ALIGN_RIGHT) flexsizer.Add(self.bytestosend,0,wx.EXPAND) byteslabel2 = wx.StaticText(panel, -1, "Bytes Sent:") self.bytessent = wx.StaticText(panel, -1, "0") flexsizer.Add(byteslabel2,0,wx.ALIGN_RIGHT) flexsizer.Add(self.bytessent,0,wx.EXPAND) vertsizer.Add(flexsizer,1, wx.EXPAND|wx.ALL,30) # place values into appropriate text fields # (these values can be initialized at the top of this script) self.toemailaddress.SetValue(toemail) self.fromemailaddress.SetValue(fromemail) self.subject.SetValue(subject) self.emailmessage.SetValue(emailmsg) if os.path.exists(os.path.abspath(attachment)): self.attachmenteditbox.SetValue(\ os.path.split(os.path.abspath(attachment))[1]) panel.SetSizer(vertsizer) self.bytestosend.SetLabel(str(self.GetMimeSize())) # select an attachment file for the e-mail def SelectAttachmentFile(self, event): filedlgbox = wx.FileDialog(self,\ message="Select an Attachment File", \ defaultDir=os.getcwd(), \ defaultFile='', \ wildcard="Any File (*.*)|*.*", \ style=wx.OPEN | wx.CHANGE_DIR | \ wx.HIDE_READONLY) if filedlgbox.ShowModal() == wx.ID_OK: global attachment attachment = filedlgbox.GetFilenames()[0].strip() self.attachmenteditbox.SetValue(\ os.path.split(attachment)[1]) filedlgbox.Destroy() self.bytestosend.SetLabel(str(self.GetMimeSize())) event.Skip() def GetMimeSize(self): # get size of current e-mail mime object tempmime = MIMEMultipart() tempmime['To'] = self.toemailaddress.GetValue().strip() tempmime['From'] = self.fromemailaddress.GetValue().strip() tempmime['Subject'] = self.subject.GetValue().strip() # add the e-mail message to the mime object tempmime.attach(MIMEText(self.emailmessage.GetValue())) # add an attachment file to the mime object if selected if attachment.strip() != '': thisfile = os.path.abspath(attachment) if os.path.exists(thisfile): attachmentmime = MIMEBase('application', \ "octet-stream") attachmentmime.set_payload(\ open(thisfile,"rb").read()) Encoders.encode_base64(attachmentmime) attachmentmime.add_header('Content-Disposition',\ 'attachment; filename="%s"' % \ os.path.basename(thisfile)) tempmime.attach(attachmentmime) mimesize = len(tempmime.as_string()) tempmime = None return mimesize # send the e-mail using python's smtplib module def SendTheEmail(self, event): # how can I determine the number of bytes that have # been forwarded whilst the e-mail is being sent ? global bytes_sent bytes_sent = 0 # set gauge value to zero - max value = 100 (%) self.gauge.SetValue(0) self.bytestosend.SetLabel(str(self.GetMimeSize())) self.bytessent.SetLabel('0') # create a multi-part mime object for the # e-mail message and file attachment thismime = MIMEMultipart() thismime['To'] = self.toemailaddress.GetValue().strip() thismime['From'] = self.fromemailaddress.GetValue().strip() thismime['Subject'] = self.subject.GetValue().strip() # add the e-mail message to the mime object thismime.attach(MIMEText(self.emailmessage.GetValue())) # add an attachment file to the mime object if selected if attachment.strip() != '': thisfile = os.path.abspath(attachment) if os.path.exists(thisfile): attachmentmime = MIMEBase('application', \ "octet-stream") attachmentmime.set_payload(\ open(thisfile,"rb").read()) Encoders.encode_base64(attachmentmime) attachmentmime.add_header('Content-Disposition',\ 'attachment; filename="%s"' % \ os.path.basename(thisfile)) thismime.attach(attachmentmime) else: dlg = wx.MessageDialog(self,\ message='Attachment file ' + thisfile + ' is missing.',\ caption='Attachment Missing',style=wx.OK|\ wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() # send the e-mail smtpobj = smtplib.SMTP(smtp_server) smtpobj.sendmail(self.fromemailaddress.GetValue().strip(), \ self.toemailaddress.GetValue().strip(), \ thismime.as_string()) smtpobj.close() event.Skip() if __name__ == '__main__': app = wx.App() theframe = MainFrame(None) theframe.Show() app.MainLoop() From __peter__ at web.de Thu Dec 14 11:18:27 2006 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Dec 2006 17:18:27 +0100 Subject: Logging module: problem with some mapping keys References: <1166029343.340490.163490@79g2000cws.googlegroups.com> <1166106298.176199.301190@f1g2000cwa.googlegroups.com> Message-ID: Tekkaman wrote: > Thanks for the hint, but it's not a symlink What does logging._srcfile contain? Should be >>> import logging >>> logging._srcfile '/usr/lib/python2.4/logging/__init__.py' on your machine, but probably isn't. Peter From raNOsky at deveSPAMler.com Fri Dec 15 09:44:24 2006 From: raNOsky at deveSPAMler.com (Giovanni Bajo) Date: Fri, 15 Dec 2006 15:44:24 +0100 Subject: Missing __length_hint__ in __getitem__ iterator References: Message-ID: Peter Otten wrote: > It's there, just not doctored into the dir() output: > >>>> class A(object): > ... def __getitem__(self, index): return index > ... def __len__(self): return 42 > ... >>>> iter(A()).__length_hint__ > >>>> iter(A()).__length_hint__() > 42 > > Peter Ah well, actually it's there also in dir(), you just need to use Python 2.5 of course ;) -- Giovanni Bajo From deepusdreamz at gmail.com Mon Dec 11 03:17:58 2006 From: deepusdreamz at gmail.com (pradeep kumar) Date: Mon, 11 Dec 2006 13:47:58 +0530 Subject: doubt in curses module Message-ID: <86a272920612110017t58f77ae6jaa47f0d09739bd67@mail.gmail.com> hii, iam new to python. i want to use function keys in my program, so i went through the curses module, but in that module it shows a different window object and after pressing the our desired function key in it, that will return the ascii value of that key to the command prompt. so, i want to hide or dissable the window object, can anyone tell me how it will be possible... it is very urgent -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstroud at mbi.ucla.edu Wed Dec 20 20:14:14 2006 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 21 Dec 2006 01:14:14 GMT Subject: Tkinter, StringVar and dict In-Reply-To: <147e6$4589bcdd$4275d90a$6123@FUSE.NET> References: <147e6$4589bcdd$4275d90a$6123@FUSE.NET> Message-ID: Kevin Walzer wrote: > I'm trying to manage user preferences in a Tkinter application by > initializing some values that can then be configured from a GUI. The > values are set up as a dict, like so: > > self.prefs= { > 'interface': '-en1', > 'verbose': '-v', > 'fontname': 'Courier', > 'point': 12, > } > > To link these values to the appropriate Tkinter variables, I'm using > code like this: > > self.prefs['interface'] = StringVar() > self.prefs['interface'].set("-en0") # initialize > > This raises an error in Tkinter: > > Exception in Tkinter callback > Traceback (most recent call last): > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", > line 1403, in __call__ > return self.func(*args) > File "/Users/kevin/Programming/packetstream/packetstream-classes.py", > line 293, in setPrefs > self.prefs['interface'] = StringVar() > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", > line 3237, in __setitem__ > self.tk.call(self.name, 'configure', '-'+key, value) > TclError: unknown option "-interface" > > Can someone help me smooth this out--to get dict key-values into a > Tkinter variable like StringVar()? > > Thanks. > Actually, even more succinctly: # somewhere in self defaults = { 'interface' : '-en1', 'verbose' : '-v', 'fontname' : 'Courier', 'point' : 12 } self.prefs = dict((d,StringVar(value=v)) for (d,v) in defaults.items()) James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From ask at me Sat Dec 9 00:16:52 2006 From: ask at me (alf) Date: Fri, 08 Dec 2006 23:16:52 -0600 Subject: More elegant to get a name: o.__class__.__name__ In-Reply-To: References: Message-ID: <-_KdnfoCR4xZ2-fYnZ2dnUVZ_q7inZ2d@comcast.com> alf wrote: > Hi, > is there a more elegant way to get o.__class__.__name__. For instance I > would imagine name(o). > decided to stick to o.__class__.__name__ for readibility. -- alfz1 From int2k at gmx.net Sun Dec 10 21:02:41 2006 From: int2k at gmx.net (Wolfram Fenske) Date: 10 Dec 2006 18:02:41 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xwt50qejd.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165737791.744375.190080@l12g2000cwl.googlegroups.com> <7x7ix0godv.fsf@ruckus.brouhaha.com> <1165741455.889300.327100@j44g2000cwa.googlegroups.com> <7xwt50qejd.fsf@ruckus.brouhaha.com> Message-ID: <1165802561.539960.174180@80g2000cwy.googlegroups.com> Paul Rubin writes: > "Wolfram Fenske" writes: >> Yes, I wrote about it in another post. It was introduced in Python >> 2.5. And if it hadn't been I'd still have to write code like this. > > You could do something with decorators that's not too bad. You'd end > up writing: > > @withConnection > def some_func(): > do_whatever_stuff () Yes, now I can. But I had to wait until Python 2.4 to be able to that. What I like so much about Lisp macros is that they allow me to make these changes myself. -- Wolfram Fenske A: Yes. >Q: Are you sure? >>A: Because it reverses the logical flow of conversation. >>>Q: Why is top posting frowned upon? From paulsendave at yahoo.com Tue Dec 19 15:48:16 2006 From: paulsendave at yahoo.com (paulsendave) Date: 19 Dec 2006 12:48:16 -0800 Subject: Newbie: What are the rules wrt constructing PYDOC keywords Message-ID: <1166561296.831122.103230@a3g2000cwd.googlegroups.com> Still learning python (2.4) and have instructions that all of our python scripts should be SelfDoc'ing via pydoc standards. One thing that isn't clear to me is how pydoc searches for keywords. I believe that there might be certain rules for putting keywords together under the SYNOPSIS and search paths that "pydoc -k" uses that aren't obvious to me. (Of course, it'd be a good training exercise to read through pydoc.py itself and figure it out for myself, and I might just do that, but for the moment, there are other priorities.) :^) djp From exhuma at gmail.com Thu Dec 14 08:10:49 2006 From: exhuma at gmail.com (exhuma.twn) Date: 14 Dec 2006 05:10:49 -0800 Subject: Survey environment for Python? References: <1166083824.927340.102530@73g2000cwn.googlegroups.com> <1166087528.068107.234480@n67g2000cwd.googlegroups.com> Message-ID: <1166101849.115581.315800@f1g2000cwa.googlegroups.com> Kay Schluehr wrote: > exhuma.twn schrieb: > > > Hi, > > > > Just recently I had to take over support for legacy software written in > > Blaise (www.cbs.nl). > > I don't understand the meaning of the link. Do you mean this language? > > http://blaise.sourceforge.net/ Not quite ;) Sorry for being too vague. This is the correct link: http://www.cbs.nl/en-GB/menu/informatie/onderzoekers/blaise-software/default.htm From e0427417 at student.tuwien.ac.at Wed Dec 13 18:45:25 2006 From: e0427417 at student.tuwien.ac.at (Mathias Panzenboeck) Date: Thu, 14 Dec 2006 00:45:25 +0100 Subject: call of __del__ non-deterministic in python 2.4 (cpython)? In-Reply-To: References: Message-ID: <45808fcf$0$11868$3b214f66@tunews.univie.ac.at> Anthony Baxter wrote: > On 12/13/06, Holger Joukl wrote: >> I did read this but didn't think it applied to my situation. I'm quite >> sure that the refcount of the local variable is 1 before the local scope >> is left. >> So let me rephrase the question: Even if I can make sure that non of the >> problematic situtions apply, might it _still_ happen that __del__ gets >> called >> after some other code has already been "entered"? > > You shouldn't rely on __del__ being called exactly when you expect it, > particularly in a threaded application. Make explicit cleanup calls, > instead. a nice way to do such things in python 2.5 is using the with statement. this ensures to call a __exit__ (cleanup) function after a __enter__ function was called, no matter if there is a exception or something other in between. with open("foo.txt","w") as fp: fp.write("foo") translates to: mgr = open("foo.txt","w") # well, in the case of files, __enter__ just returns self fp = mgr.__enter__() try: fp.write("foo") finally: mgr.__exit__() # this calls fp.close() this of course is a simplified translation of the with statement. see more details here: http://www.python.org/dev/peps/pep-0343/ with is also cool for using it in combination with mutexes and similar stuff. it would also be possible to write a transaction manager which calls commit() or abort() automatically, so you can just write: with new_transaction(): # if do_stuff() returns, commit() will be called # if it raises an exception abort() will be called do_stuff() But if you can't use python 2.5, there is no other way then: try: do_stuff() finally: cleanup() From arkanes at gmail.com Tue Dec 26 15:54:53 2006 From: arkanes at gmail.com (Chris Mellon) Date: Tue, 26 Dec 2006 14:54:53 -0600 Subject: some OT: how to solve this kind of problem in our program? In-Reply-To: <7.0.1.0.0.20061226164403.03e6e568@yahoo.com.ar> References: <458e4426$0$5286$4c368faf@roadrunner.com> <1166958490.785728.52430@h40g2000cwb.googlegroups.com> <1166974469.681026.101070@42g2000cwt.googlegroups.com> <45906bab$0$27094$4c368faf@roadrunner.com> <7.0.1.0.0.20061226164403.03e6e568@yahoo.com.ar> Message-ID: <4866bea60612261254q5c0ec8b9ob298cd046ae6d21@mail.gmail.com> On 12/26/06, Gabriel Genellina wrote: > At Monday 25/12/2006 21:24, Paul McGuire wrote: > > >For example, for all the complexity in writing Sudoku solvers, there are > >fewer than 3.3 million possible permutations of 9 rows of the digits 1-9, > >and far fewer permutations that match the additional column and box > >constraints. Why not just compute the set of valid solutions, and compare > >an input mask with these? > > Are you sure? There are 9!=362880 rows of digits 1-9; taking 9 of > these at random gives about 10**50 possibilities. Of course just a > few match the additional constraints. Maybe you can trivially reduce > them (just looking for no dupes on the first column) but anyway its a > laaaaarge number... (Or I'm wrong computing the possibilities...) > According to Wikipedia, there are 6,670,903,752,021,072,936,960 possible classical Sudoku layouts. Ref. http://www.research.att.com/~njas/sequences/A107739 From nono at hotmail.com Wed Dec 27 16:33:35 2006 From: nono at hotmail.com (Osiris) Date: Wed, 27 Dec 2006 22:33:35 +0100 Subject: Feasible in Python ? list of object , with two exeptional objects Message-ID: <6eo5p2di7lrcs5smouhg8ju83901b4hld0@4ax.com> Is the following intuitively feasible in Python: I have an array (I come from C) of identical objects, called sections. These sections have some feature, say a length, measured in mm, which is calculated by a method A_length of the instantiation of the Section's class. Only, two elements in the array (or list ?) have a length that must be calculated according to a totally different procedure, a different function or method. After calculation of ALL the lengths, they must be added together and output. The calculation procedure screams for a FOR or a WHILE loop allong the list of sections, only those two sections mentioned make life difficult. I was thinking along the line of building a class Section, instantiate a list of objects of this class, and then replace 2 of the elements of the list by instantiations of the special class... Or maybe replace only the method in question by the special method... It would be neat, if I could just walk the FOR loop, constructing the list and calculate the total length in one go... Concretely, the situation is a Plone site that passes user "section" data to a Python / C server-side to do calculations on the section data and return the result over the web. From dotancohen at gmail.com Mon Dec 11 17:47:32 2006 From: dotancohen at gmail.com (Dotan Cohen) Date: Tue, 12 Dec 2006 00:47:32 +0200 Subject: possible php convert In-Reply-To: <7.0.1.0.0.20061211183111.03640ee0@yahoo.com.ar> References: <880dece00612100436v1051977fk966b77eecb4296cd@mail.gmail.com> <7.0.1.0.0.20061211183111.03640ee0@yahoo.com.ar> Message-ID: <880dece00612111447m6c3d6be9h94d5fcf24a936b11@mail.gmail.com> On 11/12/06, Gabriel Genellina wrote: > At Sunday 10/12/2006 09:36, Dotan Cohen wrote: > > >Hi all, I've been contemplating the switch to python from php. I'm no > >wiz, but I can get my way around with help form the online docs. I see > >that python has much less documentation available, so expect to hear > >from me a bit in the next few weeks. :) > > Uhm, have you looked at http://www.python.org/doc/ ? Yes, of course. That's naturally the first place I'd go. I won't start a flame war by comparing them to docs that I am familiar with from a competing product :) > >One concern that I have is that my current host does not support > >python, and for a very technical reason (money) I'd rather not switch. > >I've googled the possibility of installing python in my user's home > >directory (RHEL server), and this seems possible. Can anyone enlighten > >me as to how I could do this? Thanks in advance. > > I guess you want to use Python to provide dynamic content for a web site. > There are several alternatives: Apache with mod_python, or Django, > TurboGears, CherryPy. There was a recent discussion on this list some > days ago about these frameworks. It'd have to be right before I signed up! I'll STFA a bit more, as I had really just skimmed them due to my unfamiliarity with the python community. Thanks. Dotan Cohen http://what-is-what.com/what_is/text_editor.html http://lyricslist.com/lyrics/artist_albums/272/jackson_janet.php From paul at boddie.org.uk Wed Dec 20 08:05:47 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 20 Dec 2006 05:05:47 -0800 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> <4587506D.50808@cosc.canterbury.ac.nz> <458919DD.40901@cosc.canterbury.ac.nz> Message-ID: <1166619947.121755.138380@n67g2000cwd.googlegroups.com> Nick Maclaren wrote: > > Which is tantamount to saying that Python doesn't support mutable > heterogeneous sequences, even though they are not locked out. That > is more than just odd - it is almost unbelievable. They are a very > basic data structure, after all! What a fuss about something so intangible! :-) If I were you, I'd not worry about taking what people say with regard to the philosophy as a starting point. Instead, it may be more illustrative to consider things from the ground up... * You can put any combination of things into both tuples and lists. * Tuples are immutable, lists are mutable. * You can test both tuples and lists for element membership (x in seq). * You can iterate over both tuples and lists. The contentious issue is why you can't ask where something is in a tuple (the position of an element) whereas you can in a list or even in a string (albeit only with substrings in that particular case). This is where you have to consider how you'd use an immutable sequence like a tuple rather than a mutable sequence like a list. With a tuple, since you can't append to it, you already need to have decided its size and its contents (mutable elements notwithstanding) when you create it. Although it's possible to have thousands of elements in a tuple, you would in most situations need to build such long tuples up either by concatenating existing ones - this is not likely to be particularly efficient due to the need to construct a new tuple for each concatenation of existing ones - or by converting a list into a tuple (questioning the need for a tuple, anyway). So it's unlikely that you'd lightly consider using tuples as an ad-hoc sequence for recording long collections of objects, or that the structure of any tuple you've created is consequently going to be unknown to your program. Even if you were dealing with totally unknown tuples from other sources, the need to query the location of specific elements would probably be much less than just iterating over the tuple or asking whether something is present in it. Of course, one can still argue that querying for the presence of an element is no real substitute for knowing its position. In a program where you define the structure of a tuple in such a way that it makes little sense for a particular element to appear in more than one place - which is where the heterogeneous assertion comes in - knowing the presence of an element is as good as knowing its position (since the program has knowledge of the position implicitly). In a program where you don't define the structure in such a way, the problem situation seems to be as narrow as needing short tuples (as opposed to lists, possibly for use as dictionary keys, for example) whose elements' locations are efficiently discoverable, and where such location information is significantly useful for other purposes. Since tuples are immutable, you can't replace those elements using such location information, leaving fewer and fewer compelling reasons for needing that information in the first place, I would have thought. Perhaps the notion of heterogeneous is best defined in the most general case as a selection of objects unlikely to be considered equal or equivalent, in such a way that the standard test for presence (x in seq) employs such a measure of equality and can suggest (with contextual information) the location of an object by just knowing whether it is present. Paul From nagle at animats.com Thu Dec 14 17:31:01 2006 From: nagle at animats.com (John Nagle) Date: Thu, 14 Dec 2006 22:31:01 GMT Subject: MySQLdb windows binaries for Python 2.5?? Yes, but from a World of Warcraft guild. In-Reply-To: References: <1162408100.985370.148650@m7g2000cwm.googlegroups.com> <1163238145.257490.144410@b28g2000cwb.googlegroups.com> Message-ID: Jan Dries wrote: > Henk.van.Asselt at gmail.com wrote: > >> I'm also looking for a MySQLdb binary for windows. This is holding me >> from upgrading from Python 2.4 to Python 2.5 ! >> > > If you search the Help Forum of the MySQLdb project on SourceForge, you > will find a couple of people who have successfully built MySQLdb on > Windows for 2.5, and are willing to share their installers. > That's how I got my binaries. > > Regards, > Jan Yes, see http://sourceforge.net/forum/forum.php?thread_id=1571110&forum_id=70461 for an untested version created by a World of Warcraft guild: http://www.guildmanus.com/uploaded/MySQL-python.exe-1.2.2b2.win32-py2.5.exe This, apparently, is the extent of current Python support for MySQL. Want to install that executable, as root, on your production machines? This is embarassing for the Python community. Perl and PHP come with MySQL support built in. Python is out to lunch on this. John Nagle Animats From borntonetwork at gmail.com Tue Dec 5 23:46:00 2006 From: borntonetwork at gmail.com (borntonetwork) Date: 5 Dec 2006 20:46:00 -0800 Subject: PyQt, designer, and directional flow Message-ID: <1165380360.285089.94980@16g2000cwy.googlegroups.com> I am creating a simple form using designer (qt4) on Ubuntu. I use pyuic to create a python script from the form. I run the script and the form shows up fine. The idiosyncrasy occurs when I try to type text into a QTextEntry widget. The text is right-aligned, not left-aligned as I had set it up in the property editor in designer. This behavior is not limited to alignment in text fields. If I insert a QTableWidget and add items to it, the items appear from right to left, not left to right. For example, if I create a 4-column table and use setItem() to insert the numbers 1, 2, 3, and 4 into columns 0, 1, 2, 3 respectively, I get this: 4 3 2 1 The same thing goes with the headers. I create a QStringList ("1", "2", "3", "4") and add it using setHorizontalHeaderLabels() then the headers show up as 4 3 2 1. This is my first qt app using python instead of C++, so I may be doing something wrong. I am grateful for any ideas someone might have. By the way I've compiled pyqt and qt4 from the latest stable sources. From rays at blue-cove.com Thu Dec 28 18:18:11 2006 From: rays at blue-cove.com (Ray Schumacher) Date: Thu, 28 Dec 2006 15:18:11 -0800 Subject: how to serve image files without disk use? Message-ID: <6.2.3.4.2.20061228131600.05c410b0@blue-cove.com> I'm trying to make a small camera server using VideoCapture.py and socket. I needed to construct a complete image file with headers etc for a browser to recognize it, but I couldn't find a combination of StringIO and wx image methods to avoid disk saves, without PIL. If I save a temp.jpg file to disk I can serve the image easily: ... self.cam = VideoCapture.Device(devnum=0, showVideoWindow=0) buff, width, height = self.cam.dev.getbuffer() im = wx.EmptyImage(width, height) im.SetData(buff) im.Mirror().SaveFile('temp.jpg', wx.BITMAP_TYPE_JPEG) ... s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() while 1: data = conn.recv(1024) if data[:3] == 'GET': conn.send("HTTP/1.0 200 OK"+"\015\012") conn.send("Server: RJS_video/0.0.1"+"\015\012") conn.send("Content-type: image/bmp"+"\015\012") conn.send("Content-Length: "+str(352*288*3+256)+"\015\012") conn.send("\015\012") fh = file('temp.jpg', 'rb') conn.send(fh.read()) fh.close() else: break But, how can I avoid disk writes? wx's *.SaveFile() needs a string file name (no objects). I'm going to investigate PIL's im.save(), as it appears to allow file-objects. Ray From moogyd at yahoo.co.uk Sun Dec 17 05:08:24 2006 From: moogyd at yahoo.co.uk (moogyd at yahoo.co.uk) Date: 17 Dec 2006 02:08:24 -0800 Subject: OT : Bug/Issue tracking systems In-Reply-To: References: <1166338246.113948.320240@l12g2000cwl.googlegroups.com> Message-ID: <1166350104.375187.287820@16g2000cwy.googlegroups.com> Marc 'BlackJack' Rintsch wrote: > In <1166338246.113948.320240 at l12g2000cwl.googlegroups.com>, moogyd wrote: > > > The requirements I have come up with > > > > [...] > > > > - Ideally via text files, a bit of perl/tcl/python OK. I'd rather > > avoid SQL > > You should drop that requirement. The tracker will be used concurrently > and this is handled very efficiently and reliable by a database backend. > > Ciao, > Marc 'BlackJack' Rintsch Hi Marc, I am aware that I will probably need a database (probably supporting SQL), but I would like to avoid having to write SQL queries myself (i.e. It should all be transparent to me). Thanks, Steven From rurpy at yahoo.com Mon Dec 4 13:55:56 2006 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: 4 Dec 2006 10:55:56 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: <45745F24.2010406@v.loewis.de> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> <1165250963.660087.58410@n67g2000cwd.googlegroups.com> <45745F24.2010406@v.loewis.de> Message-ID: <1165258556.021281.51440@79g2000cws.googlegroups.com> Martin v. L?wis wrote: > rurpy at yahoo.com schrieb: > > Thanks for explaining why the OP was rude. Having been > > reading and listening to english for only a few decades > > probably, I am sure the OP (and me too!) appreciates your > > explanation of rudeness > > You mean, you don't feel insulted if somebody calls you > silly? This is a hypothetical question, right? Since the OP didn't call you or anyone else silly. O.P. wrote: > > Rather, they (like I) will encourage to OP to submit > > a patch that fixes the problem. > Now, that would be rather silly. I would have to familiarize > myself with the code for the Python interpreter, Seems to me he called the suggestion (made without any knowlage of the OP's abilities regarding C and Python's internals) that he summit a patch, silly. I aggree. His response was well within the bounds of normal usenet discourse. From kentilton at gmail.com Thu Dec 14 03:53:55 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 03:53:55 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4uch8cF17smt9U1@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> Message-ID: Andrew Reilly wrote: > On Thu, 14 Dec 2006 03:01:46 -0500, Ken Tilton wrote: > > >>You just >>aren't used to thinking at a level where one is writing code to write code. > > > Firstly, I'm looking into lisp because my current python project is too > full of boilerplate :-) and too slow. Coming from a C and assembler > background, I'm *used* to meta-programming, and do it all the time. I > even use python, Matlab and bash to write C, sometimes :-) > > However, in this particular instance, I'm inclined to wonder why > meta-programming is the right answer, rather than just doing all of the > interpolation and what-not at run-time, based on a big table of your > algebra rules? I am afraid I do not see what alternative you are suggesting. I especially do not see how interpolation is in play. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From sschwarzer at sschwarzer.net Sun Dec 24 18:48:12 2006 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 24 Dec 2006 23:48:12 +0000 (UTC) Subject: [ANN] ftputil 2.2 released Message-ID: ftputil 2.2 is now available from http://ftputil.sschwarzer.net/download . Changes since version 2.1 ------------------------- - Results of stat calls (also indirect calls, i. e. listdir, isdir/isfile/islink, exists, getmtime etc.) are now cached and reused. This results in remarkable speedups for many use cases. Thanks to Evan Prodromou for his permission to add his lrucache module under ftputil's license. - The current directory is also locally cached, resulting in further speedups. - It's now possible to write and plug in custom parsers for directory formats which ftputil doesn't support natively. - File-like objects generated via ``FTPHost.file`` now support the iterator protocol (for line in some_file: ...). - The documentation has been updated accordingly. Read it under http://ftputil.sschwarzer.net/trac/wiki/Documentation . Possible incompatibilities: - This release requires at least Python 2.3. (Previous releases worked with Python versions from 2.1 up.) - The method ``FTPHost.set_directory_format`` has been removed, since the directory format (Unix or MS) is set automatically. (The new method ``set_parser`` is a different animal since it takes a parser object to parse "foreign" formats, not a string.) What is ftputil? ---------------- ftputil is a high-level FTP client library for the Python programming language. ftputil implements a virtual file system for accessing FTP servers, that is, it can generate file-like objects for remote files. The library supports many functions similar to those in the os, os.path and shutil modules. ftputil has convenience functions for conditional uploads and downloads, and handles FTP clients and servers in different timezones. License ------- ftputil 2.2 is Open Source software, released under the revised BSD license (see http://www.opensource.org/licenses/bsd-license.php ). Stefan -- Dr.-Ing. Stefan Schwarzer SSchwarzer.com - Softwareentwicklung f??r Technik und Wissenschaft http://sschwarzer.com From chris.lasher at gmail.com Sat Dec 9 13:33:03 2006 From: chris.lasher at gmail.com (Chris Lasher) Date: 9 Dec 2006 10:33:03 -0800 Subject: Interacting with keyboard LEDs In-Reply-To: References: <1165641507.187794.115360@l12g2000cwl.googlegroups.com> Message-ID: <1165689183.812932.56980@80g2000cwy.googlegroups.com> Jonathan Curran wrote: > Spur of the moment answer: call setleds program from within your program > > better answer (fox X11): > http://python-xlib.sourceforge.net/doc/html/python-xlib_16.html > > Take a look at get_keyboard_control() and change_keyboard_control(). As far as > knowing how to properly invoke them, I have no idea, maybe you could google > for examples or take a look at the setleds source? > > - Jonathan Thanks for your reply, Jonathan. The difficulty with setleds is that only works from a virtual console (e.g., tty, CTRL+ALT+F1 through F6, etc.), not from a terminal emulator inside X (e.g., pts, Xterm, Gnome Terminal, Konsole, etc.), which is the environment where I'd like to interact with the LEDs. The xlib package looks promising, though. One thing I don't understand is the 32-bit mask. How does this represent the LED states? I profess my ignorance. Thanks! Chris From richardjones at optushome.com.au Tue Dec 19 16:15:38 2006 From: richardjones at optushome.com.au (Richard Jones) Date: Wed, 20 Dec 2006 08:15:38 +1100 Subject: python-hosting.com projects: dead? References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> <1166499192.027000.151290@j72g2000cwa.googlegroups.com> <1166499671.678929.25180@n67g2000cwd.googlegroups.com> <4upr9dF197g6cU1@mid.individual.net> <1166536534.892544.95850@73g2000cwn.googlegroups.com> Message-ID: <4588567a$0$5744$afc38c87@news.optusnet.com.au> Remi wrote: > We had to do some serious cleanup and we disabled a lot of Trac sites > that looked abandoned (people left their Trac sites open to spammers > and our server was crawling under the load caused by these spammers). Actually, to clarify the DEFAULT configuration for Trac is to leave it open to spam. I don't even use the Trac instance for my project hosted on that server. Richard From fredrik at pythonware.com Sun Dec 24 06:15:34 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 24 Dec 2006 12:15:34 +0100 Subject: removing the header from a gzip'd string In-Reply-To: <1166895890.297135.144990@i12g2000cwa.googlegroups.com> References: <1166735512.435837.60080@42g2000cwt.googlegroups.com> <4v0f53F1afe47U1@mid.individual.net> <1166895890.297135.144990@i12g2000cwa.googlegroups.com> Message-ID: debarchana.ghosh at gmail.com wrote: > Essentially, they note that the NCD does not always bevave like a > metric and one reason they put forward is that this may be due to the > size of the header portion (they were using the command line gzip and > bzip2 programs) compared to the strings being compressed (which are on > average 48 bytes long). gzip datastreams have a real header, with a file type identifier, optional filenames, comments, and a bunch of flags. but even if you strip that off (which is basically what happens if you use zlib.compress instead of gzip), I doubt you'll get representative "compressability" metrics on strings that short. like most other compression algorithms, those algorithms are designed for much larger datasets. From fredrik at pythonware.com Mon Dec 4 17:35:37 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 23:35:37 +0100 Subject: Why not just show the out-of-range index? In-Reply-To: <45749D82.4040301@v.loewis.de> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> <1165250963.660087.58410@n67g2000cwd.googlegroups.com> <45745F24.2010406@v.loewis.de> <1165258556.021281.51440@79g2000cws.googlegroups.com> <45749D82.4040301@v.loewis.de> Message-ID: Martin v. L?wis wrote: > It would be unrealistic (but not silly) to suggest that > if the source code weren't available at all. It is *not* > silly to suggest that people should make efforts to > contribute to open source software. you're forgetting that you're dealing with "squeaky wheel contributors" here, not the kind of nice and helpful persons that actually make open source work. From gagsl-py at yahoo.com.ar Fri Dec 15 07:51:56 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 15 Dec 2006 04:51:56 -0800 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: Message-ID: <1166187115.915310.66810@l12g2000cwl.googlegroups.com> On 15 dic, 07:44, "dyork" wrote: > When getting data from a database using the dbapi and an SQL query, how do > you in general round trip the data? Especially date-time? > > An SQL datetime column translates nicely into a Python datetime (surprise), > which then translates into a string like '2005-08-03 07:32:48'. No problem > with that -- all works quite nicely, until you try to put data back the > other way. Dont convert to string and keep the datetime object. -- Gabriel Genellina From durumdara at gmail.com Fri Dec 22 06:30:37 2006 From: durumdara at gmail.com (durumdara) Date: Fri, 22 Dec 2006 12:30:37 +0100 Subject: Regexp Neg. set of chars HowTo? In-Reply-To: <1166702058.983049.261870@79g2000cws.googlegroups.com> References: <1166702058.983049.261870@79g2000cws.googlegroups.com> Message-ID: <458BC1DD.8020100@gmail.com> Hi! Thanks for this! I'll use that! I found a solution my question in regexp way too: import re testtext = " minion battalion nation dion sion wion alion" m = re.compile("[^t^l]ion") print m.findall(testtext) I search for all text that not lion and tion. dd Paul McGuire wrote: > It looks like you are trying to de-hyphenate words that have been > broken across line breaks. > > Well, this isn't a regexp solution, it uses pyparsing instead. But > I've added a number of other test cases which may be problematic for an > re. > > -- Paul > From robert.kern at gmail.com Fri Dec 1 19:37:37 2006 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 01 Dec 2006 18:37:37 -0600 Subject: How do I print a numpy array? In-Reply-To: <1165017000.500270.188540@73g2000cwn.googlegroups.com> References: <12n1b51i11rhv5e@corp.supernews.com> <1165017000.500270.188540@73g2000cwn.googlegroups.com> Message-ID: Beliavsky wrote: > When I print an array in any language, I (and I think most programmers) > expect by default to have all elements displayed. Matlab, R, and > Fortran 95 have somewhat similar arrays to numpy, and that is what they > do. I don't remember Numeric summarizing arrays by default. R has a > "summary" function as well as a "print" function. There are pretty serious problems with interactive use and large arrays. Formatting the string for a very large array can take a fair bit of time, often much more than the computation that generated it. This has been a long-standing frustration of many Numeric users. At the interactive prompt, if the statement you just entered is taking a long time to execute and you Ctrl-C, odds are, the traceback points you right in the middle of array2string(), not anything in the actual computation itself. Since the interactive prompt prints things out without the user explicitly asking for it, it's not enough simply to have two functions available. numarray set the default to summarize, and numpy kept numarray's choice. -- 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 From nospam at domain.tld Thu Dec 21 07:44:55 2006 From: nospam at domain.tld (Stephan Kuhagen) Date: Thu, 21 Dec 2006 13:44:55 +0100 Subject: What am I supposed to do with an egg?! References: Message-ID: Sebastian 'lunar' Wiesner wrote: > Morpheus wrote > >> So, what am I supposed to do here now? > > That's easy: Breed it... Since two days I'm fighting with myself not to make this joke. Thanks for relieving me... Regards Stephan From greg at cosc.canterbury.ac.nz Sat Dec 9 21:13:48 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 10 Dec 2006 15:13:48 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <4u18tpF166u62U1@mid.individual.net> Bill Atkins wrote: > And mistakes in nesting show up as mistakes in > indenting. Er, hang on a moment... how do you *know* when you've got a mistake in indending? You must be visually verifying the indentation... rather like one does with Python code... -- Greg From gagsl-py at yahoo.com.ar Wed Dec 20 23:52:41 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 20 Dec 2006 20:52:41 -0800 Subject: Using difflib to compare text ignoring whitespace differences In-Reply-To: References: Message-ID: <1166676761.416554.273970@48g2000cwx.googlegroups.com> On 19 dic, 11:53, Neilen Marais wrote: > Hi > > I'm trying to compare some text to find differences other than whitespace. > I seem to be misunderstanding something, since I can't even get a basic > example to work: > > In [104]: d =difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) > > In [105]: list(d.compare([' a'], ['a'])) > Out[105]: ['- a', '+ a'] > > Surely if whitespace characters are being ignored those two strings should > be marked as identical? What am I doing wrong? The docs for Differ are a bit terse and misleading. compare() does a two-level matching: first, on a *line* level, considering only the linejunk parameter. And then, for each pair of similar lines found on the first stage, it does a intraline match considering only the charjunk parameter. Also note that junk!=ignored, the algorithm tries to "find the longest contiguous matching subsequence that contains no ``junk'' elements" Using a slightly longer text gets closer to what you want, I think: d=difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) for delta in d.compare([' a larger line'],['a longer line']): print delta - a larger line ? --- ^^ + a longer line ? ^^ -- Gabriel Genellina From nmm1 at cus.cam.ac.uk Mon Dec 18 04:43:38 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 18 Dec 2006 09:43:38 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> lrqjl$j4s$1@newwwwwwwwwwwwwwww elrrgs$8p6$1@geeini.csx.cam.ac.... .1166111433.32001.python-list@ppppppppppp 2$a95$1@gemini............... ailman.1607.1166112864.32031.pyyhon-list@pythonnnnnn $1@gemini.csx.cccccccccc In article <4um6tgF18l1srU1 at mid.individual.net>, greg writes: |> Roy Smith wrote: |> |> > The struct does lookup by name, the tuple is inherently index based. |> |> I was trying to help people understand the distinction |> we're talking about by showing an example of the same |> distinction in another language where it's much clearer. |> |> There are a great many ways in which C structs are |> different from Python tuples, and C arrays are different |> from Python lists. But they're not the aspects I'm |> drawing an analogy between. Unfortunately, you are confusing the issue, because there are far more extraneous aspects than relevant ones, and your view of the similarities requires looking at the issue in a very strange way. I think that I can see what you mean, but only just. Regards, Nick Maclaren. From grante at visi.com Mon Dec 4 13:57:05 2006 From: grante at visi.com (Grant Edwards) Date: Mon, 04 Dec 2006 18:57:05 -0000 Subject: Ensure a variable is divisible by 4 References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: <12n8rs1th949f9e@corp.supernews.com> On 2006-12-04, geskerrett at hotmail.com wrote: > I am sure this is a basic math issue, but is there a better > way to ensure an int variable is divisible by 4 if x & 3: print "not divisible by 4" x &= ~3 print "it is now: x = %d" If you want to round to nearest power of 4 rather than truncate: x = (x+2) & ~3 -- Grant Edwards grante Yow! An INK-LING? Sure -- at TAKE one!! Did you BUY any visi.com COMMUNIST UNIFORMS?? From usenet at kvr.at Sat Dec 16 15:51:50 2006 From: usenet at kvr.at (Christian Kastner) Date: Sat, 16 Dec 2006 21:51:50 +0100 Subject: Over my head with descriptors In-Reply-To: <1166119871.508417.239060@n67g2000cwd.googlegroups.com> References: <1166119871.508417.239060@n67g2000cwd.googlegroups.com> Message-ID: <5bec0$45845c67$534197b5$6181@news.inode.at> Sarcastic Zombie wrote: > Code included below. > > Basically, I've created a series of "question" descriptors, which each > hold a managed value. This is so I can implement validation, and render > each field into html automatically for forms. > > My problem is this: every instance of my "wizard" class has unique self > values, but they share the exact same descriptor values. That's because descriptors only work as class attributes, not instance attributes. > Meaning, if > > t = Test("ar") > y = Test("ar") > > t is y > False > > t.age is y.age > True As an attribute of the owner class, the descriptor is instantiated once for the class itself, and not for every instance of the owner class: class Foo(object): # Class attribute desc = Descriptor() def __init__(self, value): # Instance attributes go here self.value = somevalue > Code below. What am I not understanding? > ----------------------------------------- ... > class Question(object): ... > def __get__(self, instance, owner): > return self If you want to do per-instance stuff, use the "instance" argument: # Warning: simplified class Descriptor(object): def __get__(self, instance, owner): return instance._desc def __set__(self, instance, value): instance._desc = value Chris From robert.kern at gmail.com Mon Dec 4 02:02:59 2006 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 04 Dec 2006 01:02:59 -0600 Subject: Why not just show the out-of-range index? In-Reply-To: <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> Message-ID: Bill Maxwell wrote: > On Sun, 3 Dec 2006 23:31:56 -0500, Jean-Paul Calderone > wrote: > >> On 3 Dec 2006 17:23:49 -0800, Russ wrote: >>>> Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. >>> Now, that would be rather silly. I would have to familiarize myself >>> with the code for the Python interpreter, then send a patch to the >>> maintainers (and hope they notice it in their inboxes), while the >>> maintainers themselves could probably "fix" the problem in two minutes >>> flat. No thanks! >> And I have some laundry that I would like you to do for me. Let me know >> when a convenient time for you to pick it up would be. >> >> Jean-Paul > > Are you saying that you place such low value on feedback from Python > users that you don't even want them to try and ask questions that might > help to improve the language? > > In other words, if I'm not skilled or knowledgeable enough to improve > something myself, I shouldn't even mention it? No one is castigating the OP for bringing up the issue. His suggestion that his time is worth more than that of anyone else, though, is drawing some ire. Fortunately, he seems to have backed off this position and seems amenable to doing something more productive than posting here. -- 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 From IanFHood at gmail.com Wed Dec 13 18:32:46 2006 From: IanFHood at gmail.com (Ian F. Hood) Date: Wed, 13 Dec 2006 15:32:46 -0800 Subject: how to determine Operating System in Use? Message-ID: Hi In typically windows environments I have used: if 'Windows' in os.environ['OS']... to prove it, but now I need to properly support different environments. To do so I must accurately determine what system the python instance is running on (linux, win, mac, etc). Is there a best practises way to do this? TIA Ian From jan.dries at dcube-resource.be Thu Dec 7 04:31:06 2006 From: jan.dries at dcube-resource.be (Jan Dries) Date: Thu, 07 Dec 2006 10:31:06 +0100 Subject: Use of factory pattern in Python? In-Reply-To: <7.0.1.0.0.20061207053648.03d14538@yahoo.com.ar> References: <676224240612070028y7be5e8b5h8f860bc505da53c0@mail.gmail.com> <7.0.1.0.0.20061207053648.03d14538@yahoo.com.ar> Message-ID: <4577DF5A.3010106@dcube-resource.be> Gabriel Genellina wrote: > At Thursday 7/12/2006 05:28, Nathan Harmston wrote: >> so I was thinking of having a factory class to return the individual >> objects for each row......ie >> >> class Factory(): >> # if passed a gene return a gene object >> # if passed an intron return an intron object >> # if passed an exom return an exon object >> >> Is this a good way of doing this, or is there a better way to do this >> in Python, this is probably the way I d do it in Java. > > The basic idea is the same, but instead of a long series of > if...elif...else you can use a central registry (a dictionary will do) > and dispatch on the name. Classes act as their own factories. > > registry = {} > > class Base(object): > kind = "Unknown" > register(Base) > > class Gene(Base): > kind = "gene" > def __init__(self, *args, **kw): pass > register(Gene) > > class Intron(Base): > kind = "intron" > def __init__(self, *args, **kw): pass > register(Intron) > > def register(cls): > registry[cls.kind] = cls > > def factory(kind, *args, **kw): > return registry[kind](*args, **kw) > And by using a metaclass on Base you can add the wizardry to have the register-function called automatically whenever a class is derived from Base. I also tend to use the class name instead of a separate "kind" attribute. registry = {} class MetaBase(type): def __init__(cls, name, bases, dict): registry[name] = cls class Base(object): __metaclass__ = MetaBase class Gene(Base): def __init__(self, *args, **kw): pass class Intron(Base): def __init__(self, *args, **kw): pass def factory(kind, *args, **kw): return registry[kind](*args, **kw) That way you don't have to think about calling the register-function each time you derive a new class. Regards, Jan From no-sp at m-from.net Mon Dec 4 17:34:23 2006 From: no-sp at m-from.net (Giuseppe Di Martino) Date: Mon, 04 Dec 2006 23:34:23 +0100 Subject: python + database book References: <1165122005.291219.81170@73g2000cwn.googlegroups.com> Message-ID: Il Sat, 02 Dec 2006 21:00:05 -0800, progman ha scritto: > new to python. > i work with db heavily. > > any good book for python + database????? Evaluate http://www.sqlalchemy.org/ and his documentation Giuseppe From belred at gmail.com Sun Dec 10 13:31:24 2006 From: belred at gmail.com (Bryan) Date: Sun, 10 Dec 2006 10:31:24 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <5ojeh.41$_t3.21@newsfe12.lga> Message-ID: Steven D'Aprano wrote: > > I wonder, how many people gave up trying to learn Lisp because the > language was too hard for them to read? Anyone like to bet that the number > was more than zero? > > steven, you bring back awful memories :( in my college days, we had already learned fortran, pascal, c, snobol, prolog and some assembly. then we took a lisp class. what a complete nightmare!!! except for that one brainiac kid who was on "another planet", the rest of the class (about 30 people) could not grasp lisp at all. the teacher was always pissed off. he kept telling us it was such an easy language and it's so powerful and kept saying our lisp code looked like pascal. so, for the final he intentionally gave us problems that if you don't think in a lisp way you couldn't solve the problem within the time given. of course everyone failed or got a D. my point is i know at least 30 people that could code in other languages just fine, but not lisp. i've tried to learn it on my own several times since then, but it's just too difficult for me. my brain just doesn't work that way i guess. with python, my brain doesn't hurt. i can program in a very relaxed way and it seems that whatever i'm thinking, i can just write it naturally in python. for me personally that's how i define "expressiveness" eventhough others here would disagree on what "expressiveness" means. bryan From 3dbernard at gmail.com Mon Dec 11 17:11:54 2006 From: 3dbernard at gmail.com (Bernard Lebel) Date: Mon, 11 Dec 2006 17:11:54 -0500 Subject: Restricting import file lookup for pyd, dll, ... In-Reply-To: References: <61d0e2b40610191438w9ba0693y8896bebc3441069a@mail.gmail.com> <7.0.1.0.0.20061019184812.05aafe78@yahoo.com.ar> Message-ID: <61d0e2b40612111411n5f9faackf8f52fa348c731cb@mail.gmail.com> Hello, It's been almost two months since I last investigated this issue, so now I wish to revive this conversation. To answer some of the questions raised by contributors.... [Gabriel Genellina] Try to shorten the PYTHONPATH to the really required directories (deleting those locations "that don't make sense"). [Bernard] I customized the PYTHONPATH using a pth file. The pth file contains this: \\Linuxserver\ANIMATION\XSI\WORKGROUP_ANIMATION\Data\Scripts \\Linuxserver\ANIMATION\DB\MT\MT_WORKGROUP\Data\Scripts \\Linuxserver\ANIMATION\DB\TS\TS_WORKGROUP\Data\Scripts \\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE That's it. I could hardly shorten these paths, unless the ressources exposed through these paths were copied locally on every computer. Atm I do not have management tools at my disposal to handle such a setup. When print the paths: C:\WINDOWS\system32\python24.zip C:\Documents and Settings\blebel C:\Python24\DLLs C:\Python24\lib C:\Python24\lib\plat-win C:\Python24\lib\lib-tk C:\Python24 d:\bernard\work\workgroups\workgroup_animation\data\scripts d:\bernard\work\workgroups\mt_workgroup\data\scripts d:\bernard\work\workgroups\ts_workgroup\data\scripts \\Linuxserver\ANIMATION\FARM\PYTHON\RELEASE c:\users\blebel\Softimage\XSI_5.11\Data\Scripts C:\Python24\lib\site-packages C:\Python24\lib\site-packages\win32 C:\Python24\lib\site-packages\win32\lib C:\Python24\lib\site-packages\Pythonwin If by "shortening the PYTHONPATH" you meant having less paths, I hardly see how I could do less than what I do with the pth. All these paths seem to be built in. Now what would be REALLY nice is to have the ability to specify in the paths the location of *specific files*. Is this possible? What happens is that Python is visiting all kinds of locations to find some files, like os, ntpath, and many more. If I could tell Python right away where are these files located, I hope I could gain something. [Fredrik Lundh] a plain Python 2.4 interpreter can start, execute a command, and shut down in about 0.13 seconds on my machine. 2.5 does the same thing in 0.10 seconds. [Bernard] The problem is not firing up the standalone Python interpreter. The problem is firing the application that embeds a Python interpreter. As explained above, when I start this application, many files are looked in many different places. All PYTHONPATH locations are traversed, where pyd-dll-py-pyw-pyc files are searched. Many of these files are searched in highly improbable locations. [Fredrik Lundh] are you sure you're benchmarking *Python's* start up time, and not the time it takes to load all the modules used by your application, or the time it takes for "filemon" to print all those 4500 requests to the monitor window? [Bernard] The Filemon overhead consistently clocks at 1 second, not matter the test I perform. Since I ran all tests with Filemon running, I feel safe to ignore this constant. Now, as to the first sentence, to be fair, no, I'm not exactly sure. I don't know all the details of the Python's embedding in this software, and this knowledge is out of my reach atm. Here is the relevant Filemon log: http://www.bernardlebel.com/img_remote/3D/XSI/python/Filemon_XSIPython.LOG (710k file) [Magnus Lycka] Sounds like a broken (networked?) file system. The only time I've had that kind of problems with python startup is when I've had really slow anti-virus programs that scanned all the files I opened. But then it wasn't file requests that mattered, but actually opening them... It still wasn't anywhere near 9 seconds though... [Bernard] This is not entirely impossible, but I get similar results on every computer I perform this test. By "every computer", I mean different locations, with different hardwares and different network setups. Even when the files are all local on the computer I get this. Thanks Bernard On 10/28/06, Fredrik Lundh wrote: > Magnus Lycka wrote: > > >> That's because I'm using Python through another application, via the > >> pywin32 extensions. When that other application starts, it performs > >> several thousands of file requests (we're talking 4,500, roughly) in > >> the Python installation, locations where there are Python files, and > >> in some other locations that don't make sense. This adds considerable > >> time to the startup time of the application, we're talking between 2 > >> and 9 seconds. > > > > Sounds like a broken (networked?) file system. The only time I've > > had that kind of problems with python startup is when I've had really > > slow anti-virus programs that scanned all the files I opened. But then > > it wasn't file requests that mattered, but actually opening them... > > It still wasn't anywhere near 9 seconds though... > > if anyone finds out more about this issue, feel free to add a note to > this FAQ entry: > > http://www.effbot.org/pyfaq/why-does-python-sometimes-take-so-long-to-start.htm > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From bearophileHUGS at lycos.com Sun Dec 24 10:34:29 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 24 Dec 2006 07:34:29 -0800 Subject: some OT: how to solve this kind of problem in our program? In-Reply-To: <1166958490.785728.52430@h40g2000cwb.googlegroups.com> References: <458e4426$0$5286$4c368faf@roadrunner.com> <1166958490.785728.52430@h40g2000cwb.googlegroups.com> Message-ID: <1166974469.681026.101070@42g2000cwt.googlegroups.com> Using Psyco this version is much faster, you can test it on your PC compared to the other one (the whole running time, Psyco compilation too): Psyco is unable to speed up generator functions, so you have to return true lists. Giving the func to the permutation function, you can avoid lot of list copying and unpacking. try: import psyco psyco.full() except ImportError: pass d0, d1 = 1, 2 def func(p): a0,a1,a2,b0,b1,b2,c0,c1,c2 = p # do application evaluation here b1b2 = 10*b1+b2 a1a2 = 10*a1+a2 c1c2 = 10*c1+c2 if d1*a0*b1b2*c1c2 + d1*b0*a1a2*c1c2 + d1*c0*a1a2*b1b2 \ == d0*a1a2*b1b2*c1c2: return sorted( [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] ) else: return None def accepted_permutations(alist, func): # func must return None for the unacceptable results # Algoritm from Phillip Paul Fuchs, modified result = [] items = alist[:] n = len(alist) p = range(n+1) i = 1 r = func(alist) if r is not None: result.append(r) while i < n: p[i] -= 1 if i & 1: j = p[i] else: j = 0 alist[j], alist[i] = alist[i], alist[j] r = func(alist) if r is not None: result.append(r) i = 1 while p[i] == 0: p[i] = i i += 1 return result def main(): result = [] for aresult in accepted_permutations(range(1, 10), func): if aresult not in result: result.append(aresult) [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] = aresult print ' %0d %0d %0d %0d' % (a0, b0, c0, d0) print '--- + --- + --- = ---' print ' %0d%0d %0d%0d %0d%0d %0d'%(a1,a2,b1,b2,c1,c2,d1) print main() Bye, bearophile From duncan.booth at invalid.invalid Tue Dec 19 03:54:38 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Dec 2006 08:54:38 GMT Subject: trouble getting google through urllib References: <1166514020.056880.44640@f1g2000cwa.googlegroups.com> <45879f2f$0$32025$fa0fcedb@news.zen.co.uk> Message-ID: Will McGugan wrote: > Dr. Locke Z2A wrote: > >> Does anyone know how I would get the bot to have permission to get the >> url? When I put the url in on firefox it works fine. I noticed that in >> the output html that google gave me it replaced some of the characters >> in the url with different stuff like the "&" and "%7C", so I'm >> thinking thats the problem, does anyone know how I would make it keep >> the url as I intended it to be? >> > > Google doesnt like Python scripts. You will need to pretend to be a > browser by setting the user-agent string in the HTTP header. > and possibly also run the risk of having your system blocked by Google if they figure out you are lying to them? From filipwasilewski at gmail.com Wed Dec 13 13:41:51 2006 From: filipwasilewski at gmail.com (Filip Wasilewski) Date: 13 Dec 2006 10:41:51 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1166035311.357588.115070@80g2000cwy.googlegroups.com> Jon Harrop wrote: > Filip Wasilewski wrote: > > Jon, both Python and Matlab implementations discussed here use the > > lifting scheme, while yours is a classic convolution based approach. > > I've done both in OCaml. The results are basically the same. Have you tried taking advantage of the 50% reduction of arithmetic operations for the lifting scheme? > > These are two *different* algorithms for computing wavelet transforms. > > Although they have similar names and give similar results, it does not > > mean you can use them interchangeably in one benchmark! It just does > > not make sense. > > It makes sense because they solve the same problem. When you're comparing > non-trivial problems between disparate languages you are not likely to use > the same algorithms. Using built-in hash functions is an obvious example. I don't even ask if you have checked the output result coefficients because I'm pretty sure you have not. They solve similar problem but in different ways and give a bit different results, for example the layout of coefficients in the memory is different as well as border distortion handling. Please don't tell me it's better to do something else instead of presenting a relevant solution. By the way, how do you think why there are both implementations included in Matlab Wavelet Toolbox and there are people paying lots of money for it? > > What's more, taking only very big input 'n' gives only very limited > > information about true performance. > > I've presented times for 2 different "n". I agree that it would be better to > present infinite different "n" but I only had finite time. A simple loglog plot with 25 or so dyadic lengths would be just fine. I don't expect you to measure times for non-dyadic lengths because neither of the solutions presented here so far support this. [...] > > This will > > also give you some idea about call overhead and possible memory > > bandwidth influence. For example, the 4-tap db2 lifting transform > > should be about 50% faster than the one using subband filtering. That's > > theory. In practice, due to specific memory usage, the speedup gained > > with reduction of number of arithmetic operations is easily wasted by > > huge cache miss overhead (C implementation, measured on x86 > > architecture) for arrays which don't fit entirely in the CPU cache. See > > my point? > > No. The effects you are talking about are swamped by the interpreted vs > compiled effect. Have I already mentioned it was observed with low-level C implementation on x86? I would really appreciate you took some time on exploring the unfortunate topic of this benchmark before posting another comment like that. > >> 1.88s C++ (816 non-whitespace bytes) > >> 2.00s OCaml (741 b) > >> 2.33s F# (741 b) > >> 9.83s Your Python (1,002 b) > >> > >> The original python was 789 bytes. > > > > Is the byte count a standard measure you apply to describe code > > quality? > > You can use bytes, lines, words, tokens or just look at the code. Whatever > you do, Python loses on this benchmark in terms of brevity, clarity and > performance. Jon, as I have already said, you did not even show a fully comparable example yet. What I would really like to see is a lifting scheme implementation that can take 1- to 10-dimensional arrays (single and double precision floats, convert on the fly from integer types when necessary and handle strided, non-contiguous arrays), axis and maximum decomposition level as input and return list of views (or arrays if necessary) with transform coefficients for every level of decomposition. Can do? > > I don't think you would be much happier to see totally > > obfuscated golf one-liners. > > That doesn't even make sense. Squeezing code onto one line doesn't improve > byte count. Yeah, right ;-) > >> It is probably just as easy. Instead of dynamic typing you have > >> parametric polymorphism. If you want to make your function generic over > >> arithmetic type then you can pass in the arithmetic operators. > > > > Probably? Using the interactive interpreter, how can I easily create > > two n-dimensional arrays of arbitrary data type, add them and multiply > > by 17? > > In F#: > > open Math.Matrix.Generic > let a = init n m (fun i j -> ...) > let b = init n m (fun i j -> ...) > 17. $* (a + b) > > In OCaml you'd either use an array of arrays and define your own functions > over them, or you'd use the built-in Bigarray.Array2 and define some > functions over that. Either way, you have to use different operator names > for different types. You'd end up with something like: > > open Array2 > let a = init n m (fun i j -> ...) > let b = init n m (fun i j -> ...) > 17. $* (a +: b) Are you telling I have to define a different operator for every arithmetic operation for every two types? That definitely does not look like a quick, flexible and clear solution to start with. Any working example I could type into OCamlWinPlus of the following would be very appreciated. I'm fairly new to this and would really like to see how to handle differently shaped arrays and data types in the interactive mode without much hassle: from numpy import ones, arange, reshape, int32 a = ones((2,3,4,5)) b = ones(a.shape, dtype=int32) c = ones((3,4,5)) d = 2*a + 2.5*(3*b + 3.3) d[0] = d[0] + 5 d[1] *= c * (2+3*1.2) d[:,2,...] = reshape(arange(d[:,2,...].size), d[:,2,...].shape) print d[...,1] > > I just prefer fair > > comparisons and clean use cases instead of marketing like that and I > > don't believe anyone will buy your story about OCaml superior brevity > > after seeing one fairly irrelevant loop with few arithmetic operations > > as a killer argument. > > Sure. There are lots of other examples of OCaml's brevity out there: > > http://www.ffconsultancy.com/free/ocaml > http://www.ffconsultancy.com/free/sudoku > http://www.ffconsultancy.com/free/maze > http://www.ffconsultancy.com/free/ray_tracer The ray tracer example is really nice, however the sudoku solver is not so impressive when compared to the K thingy ;-) - http://markbyers.com/moinmoin/moin.cgi/ShortestSudokuSolver. [...] > > I was also unable to run your OCaml example for n >= 2^21 (win32, out > > of the box OCaml installation). Is there some 16MB memory limit imposed > > on Array? > > # let q = Array.make (1 lsl 21) 0.0;; > > Exception: Invalid_argument "Array.make". > > On 32-bit, yes. You'd either have to use a different data structure > (Bigarrays), upgrade or switch to F#. That renders the Array type almost useless for me. Where can I find documentation or tutorial on using Bigarrays? best, fw From atkinw at rpi.edu Sun Dec 10 03:19:47 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 03:19:47 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Bill Atkins writes: > maintenance. Brackets are no more boilerplate than the significant Ack. Of course I mean "parentheses." From fredrik at pythonware.com Wed Dec 20 13:02:10 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 19:02:10 +0100 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Paul Arthur wrote: >> no, I'm showing that a local file marked as executable overrides a >> shared one, even if the local file isn't actually an executable. > > Only if you have your system set up badly. The current directory should > not be in the search path, and it especially shouldn't have higher > priority than the regular bin locations. and the award for completely missing the context of this subthread goes to... From tjreedy at udel.edu Fri Dec 22 21:33:02 2006 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 Dec 2006 21:33:02 -0500 Subject: attribute decorators References: Message-ID: "Gert Cuykens" wrote in message news:ef60af090612221456v49f3c4abo7ac7e42a6c47aad1 at mail.gmail.com... | would it not be nice if you could assign decorators to attributes too ? | for example | | class C: | @staticattribute | data='hello' | | or | | class C: | @privateattribute | data='hello' No. @g def f(): pass is equivalent to and an abbreviation fo def f(): pass f = g(f) The rationale for the abbreviation is 1. let the human reader know immediately that the function will get special treatment 2. (related) put the notation about the function at the top with other header stuff 3. avoid retyping really_long_function_names three times (and there are uses of Python where long, multicomponent names are sensible and useful). But nothing is gained and something is lost by writing clear code like data = staticattribute('hello') # or privateattribute('hello') in two lines. Terry Jan Reedy From steve at REMOVE.THIS.cybersource.com.au Sat Dec 2 22:12:14 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 03 Dec 2006 14:12:14 +1100 Subject: text adventure question References: Message-ID: On Sat, 02 Dec 2006 10:22:28 -0700, Ara Kooser wrote: > I am working on a text adventure game for python to get back into > python programming. My version 0.1 used only functions so I could get > familiar with how those work. I want to move beyond that. I am not > sure what would be a good Python way of handling this. I was > wondering if classes would help? What things should be included in the > main program? Think about nouns and verbs. Verbs, "doing words", are functions and methods. Nouns, "things", are classes and objects. You should model nouns in your game with classes and objects, and verbs (actions) with functions and methods. Here is a simple example: a room. A room is a thing. So we might define a room like this: class Room: def __init__(self, name): self.name = name Now we create a new room, and fill it: bedroom = Room("King's Bedroom") bedroom.description = "You are in a fancy bedroom." self.contents.append("crown") Now we create a function for looking around: def look(here): "Look around the place you are in" print here.description And when you are in the King's bedroom, you (the programmer) would call the look function like this: look(bedroom) But look above: I said that the King's bedroom contains a "crown", using only a built-in object (str). Maybe that's all you need. Or perhaps you need something more fancy: class Object: # note: not "object", lower case, as that is a built-in type def __init__(self, name, value, description): self.name = name self.value = value self.description = description crown = Object("King's crown", 15000, "a gold crown with many jewels") scepter = Object("King's scepter", 10000, "a silver scepter") vorpel_sword = Object("vorpel sword", 200, "a strange looking sword") bedpan = Object("bedpan", 3, "a smelly metal bowl") Now you can write a function to look at any object: def look_at(something): print something.description and it will work for both objects and rooms. Let's put some more things in the King's bedroom: bedroom.contents.extend([crown, bedpan, vorpel_sword, scepter]) Rooms also need doors: bedroom.north = "wall" bedroom.south = "wall" bedroom.west = "wall" bedroom.east = Room("corridor") # a corridor is just a long, empty room Perhaps that's not the best way to do it, because now the King's bedroom has an exit into the corridor, but the corridor has no exit into the bedroom! Perhaps you need to think about a better way to map the world. But for now, we can make a really simple fix for that: corridor = bedroom.east corridor.west = bedroom corridor.north = "wall" corridor.south = "wall" corridor.east = Room('kitchen') Hmmm... we're doing a lot of unnecessary typing here. Better to create rooms with four walls already! Go back and change the definition of a room: class Room: def __init__(self, name): self.name = name self.north = "wall" self.south = "wall" self.east = "wall" self.west = "wall" and now you only need to change the directions that AREN'T walls. Now you have defined the rooms and objects in your text adventure. You should do something similar for monsters, and any other thing in the game. Then create functions for verbs: def fight(what): if type(what) == Room: print "Mindlessly attacking the room doesn't " \ "accomplish anything except bruising your fists." elif type(what) == Object: print "My, you have a bad temper. You pummel the object. " \ "It doesn't notice." elif type(what) == Monster: fight_monster() # you have to write this function elif type(what) == Royalty: print "You try to punch the King. His bodyguards leap " \ "out from the shadows and kick the bejeebus out of you, " \ "then drag you into the deepest dungeon. You have a long, "\ long LONG time to consider what you did wrong as the rats " \ "nibble at your toes." end_game() else: print "You don't know how to fight", what def say(words, what): """Say to .""" if "poot" in words: print "Do you kiss your mommy with that potty-mouth?" if type(what) == Room: print "The room doesn't answer." elif type(what) == Monster: print "The monster doesn't understand English." # and you can write the rest One suggested improvement: if you find yourself writing lots of code like the above, testing "if type(what) == Room" etc., there is a better way of doing it. Move that block of code into a method of Room: class Room: # def __init__ stays the same as before def hears(words): """The player says to the Room, and the Room responds.""" print "The room doesn't answer." and then your function becomes much simpler: def say(words, what): """Say to .""" if "poot" in words: print "Do you kiss your mommy with that potty-mouth?" else: # the player talks, so hears and responds. what.hears(words) There is more that you can do too. You need a variable to store the player's current position: start = Room("the village") position = start And you need a function that understands written commands. Here is one suggestion: define a class for commands: commandlist = {} class Command: def __init__(self, name): self.name = name commandlist[name] = self then define commands themselves: Command("go") Command("eat") Command("sleep") Command("fight") (There is a lot more to it that that, I leave the rest to you.) -- Steven. From rpdooling at gmail.com Wed Dec 13 16:43:13 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 13 Dec 2006 13:43:13 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> Message-ID: <1166046193.734274.124160@73g2000cwn.googlegroups.com> Gabriel Genellina wrote: > > import sys > print sys.path > and see what's there. Yup. Did that before. That's what I mean. The d:\\python is there and it doesn't come from the PythonPath in my windows registry. Maybe it scans for any directory with python in the name? ['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 'C:\\Python24\\Lib\\site-packages\\pythonwin', 'C:\\Python24', 'C:\\Python24\\lib\\site-packages', 'C:\\Python24\\lib\\site-packages\\win32', 'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi'] rd From S.Mientki-nospam at mailbox.kun.nl Sat Dec 30 12:19:36 2006 From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki) Date: Sat, 30 Dec 2006 18:19:36 +0100 Subject: Wow, Python much faster than MatLab In-Reply-To: References: Message-ID: <5bdf5$45969f9c$d443bb3a$14067@news.speedlinq.nl> Doran, Harold wrote: > R is the open-source implementation of the S language developed at Bell > laboratories. It is a statistical programming language that is becoming > the de facto standard among statisticians. Thanks for the information I always thought that SPSS or SAS where th? standards. Stef From bjourne at gmail.com Mon Dec 4 18:35:37 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Mon, 4 Dec 2006 23:35:37 +0000 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> <45745C9E.9050500@v.loewis.de> <740c3aec0612041148t6e2b5b15p6421ae2bd86531e2@mail.gmail.com> <740c3aec0612041307o5785d3c2vaade5378cb50a849@mail.gmail.com> Message-ID: <740c3aec0612041535g73101746kc93aaa22bfe54153@mail.gmail.com> On 12/4/06, Fredrik Lundh wrote: > BJ?rn Lindqvist wrote: > > >> > Sorry I haven't thought this through 100% > >> > >> obviously not. > > > > And you're not helping. > > I've already explained why something like PyObject_IsIndexOutOfBounds > cannot work earlier in this thread. Maybe so, but that doesn't mean that it is not possible to make the IndexError messages Pythons sequence objects throws better. You don't need to change the semantics of x[i]. -- mvh Bj?rn From basti.wiesner at gmx.net Thu Dec 28 11:04:32 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Thu, 28 Dec 2006 17:04:32 +0100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: Marc 'BlackJack' Rintsch typed > In , Felix Benner wrote: > >> I like using tabs. And the style guide doesn't give a reason why one >> shouldn't and neither does the thread >> http://www.python.org/search/hypermail/python-1994q2/0198.html in the >> archive. > This is a religious issue It is, because god itself used four spaces for indentation when he wrote his "world" project in seven days ;) -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From fredrik at pythonware.com Wed Dec 6 04:54:02 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 6 Dec 2006 10:54:02 +0100 Subject: What are python closures realy like? References: <1165388369.552194.215440@79g2000cws.googlegroups.com> Message-ID: "Paddy" wrote: > I played around a bit. The following is a 'borg' version in that there > is only one counter shared between all calls of the outer function: > >>>> def fun_borg_var(initial_val=0): > ... def borg_var_inc(x=1): > ... fun_borg_var._n += x a drawback with the function attribute approach compared to a real closure is that the function is no longer a self-contained callable: def fun_borg_var(initial_val=0): def borg_var_inc(x=1): fun_borg_var._n += x return fun_borg_var._n def borg_var_dec(x=1): fun_borg_var._n -= x return fun_borg_var._n try: fun_borg_var._n = fun_borg_var._n except: fun_borg_var._n = initial_val return (borg_var_inc, borg_var_dec) up1, dn1 = fun_borg_var() del fun_borg_var # won't need this any more print up1() # oops! so you might as well use a good old global variable, and initialize it as usual. From dixkey at gmail.com Sun Dec 10 19:37:34 2006 From: dixkey at gmail.com (dixkey at gmail.com) Date: 10 Dec 2006 16:37:34 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165797454.159855.270310@j44g2000cwa.googlegroups.com> Steven D'Aprano wrote: > > from foolib import * > > bar.bar("somefile") > > > > What does this program do? I have no idea. Its functionality is > > hidden behind multiple layers of abstraction (function, object, > > library.) > > Sure. > > But at least you know that foolib is a module or package. You know what > from and import do, and that can't change. And you know that bar is an > object with a method also called bar, it is being called, and the > argument is a string "somefile". Those things can't change. Imagine a > hypothetical language where those two lines could mean *anything*. Oh, you mean imagining a hypothetical language like Python? Where bar might not have a method bar at all? Where it might be a property set to an intance of a class with __call__ method? Oh where a metaclass for bar can intercept a request for "bar" property, do *anything* and call sys.exit() without even getting to the ("somefile") part? Thanks, it was fun to hear about Python being hypothetical. From kenneth.m.mcdonald at sbcglobal.net Tue Dec 19 00:20:01 2006 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Mon, 18 Dec 2006 23:20:01 -0600 Subject: Lightweight embedding of Firefox Gecko into application whose top level is Python--possible? Message-ID: <45877681.8060904@sbcglobal.net> Sorry for crossposting to several lists, but from what I can tell, what I want to do may involve several different areas of expertise. (None of which I have :-( ) I'd like to use Gecko as the UI for an application mostly implemented in Python. Ideally, I'd like to somehow come up with a Python module that wraps the Gecko, so that I can: 1) Create windows whose content is drawn by Gecko. 1) Dynamically manipulate what is shown by Gecko. 2) Respond to mouse events and keypresses occurring on the window Gecko is in. I really don't need, or want, anything beyond this. Presumably Gecko does have some notion of the DOM, since it handles CSS (which I do want) and CSS needs the DOM to be meaningful. And I'm also assuming that Gecko has or requires JavaScript, in order to actually do things with the DOM, or at least to handle DOM events. (Or at the very least to handle mouse events, since key events could in theory be handled outside of the layout engine.) But I'd like to be able to build something with _just_ those features. Given the above, using Firefox or even Xulrunner seems to be very heavyweight and unnecessary. It would be somewhat nice to be able to manipulate a XUL DOM to created panes, menus, etc. But even that is not necessary--so far as I can tell, DOM manipulation+CSS has the ability right now to do menus, scrollable sidebars, panes, etc. I'd like to get away from the rest of the FF/Mozilla baggage (especially XPCOM) because: 1) I don't want to have to deal with XPCOM, chrome stuff, XUL, make details, XPIDL (or whatever it is), etc. etc. My brain is already too full. :-) 2) Even if I did want to deal with the above, I find the documentation for it disorganized and, more often than not, out of date. Not a criticism, just an unavoidable weakness of open source development with a large number of developers. Given that the _only_ thing I really want to use is the Gecko layout engine with some sort of relatively rudimentary keyboard and mouse handling (I'll do all of the sophisticated handling in Python), it'd just be nice to be able to dispense with all of the rest of the stuff. For the record, I do know that PyXPCOM is still being developed, and what little I've been able to glean suggests it's been going reasonably well. However, I'm not sure it will do what I want it to. It appears to be a way to write XPCOM components in Python, and I have no idea if that will allow me to just use Python in the same way JavaScript is used right now, which is what I want. From what little I've been able to track down it seems that PyXPCOM may only be the starting point for moving towards using Python for DOM scripting. Also, I'm not sure when it will actually be done. Up-to-date online info about PyXPCOM (aside from bug tracking) seems very sparse. Given all of that, answers to the following questions (or suggestions related to the whole endeavour) would be appreciated. 1) Does this even seem feasible? Can Gecko be 'broken out' from the other Moz technologies to this extent? 2) Does anyone know of similar projects? 3) Can anyone point out a simple example of encapsulating Gecko in a small C/C++ app, and then running/communicating with Gecko from that code? (i.e. a Gecko embedding "Hello world") This is in some sense what I'd be doing, since using Gecko from Python would involve (I assume) wrapping Gecko in a Python-compatible C wrapper. I've come across a number of embedding Gecko tutorials, but nothing that starts at such a basic level. 4) Do I need to somehow provide/link in a windowing system of some sort, or do I get that with the version of Gecko appropriate for the target platform? 5) Will PyXPCOM let me do what I want? And is it close enough that I should just wait for it? (It doesn't bother me if all of the rest of the Moz/FF stuff is included in my app, just as long as I don't have to deal with it.) Many thanks, Ken McDonald From rokkamraja at gmail.com Sun Dec 3 07:14:08 2006 From: rokkamraja at gmail.com (Raja) Date: 3 Dec 2006 04:14:08 -0800 Subject: WxPython Message-ID: <1165148048.517865.156840@f1g2000cwa.googlegroups.com> Hi, I am trying to develop an application which would mainly do the following 2 things . I would like to know how it can be achieved and also the libraries needed for it . i) active window tracking In this substate, the application records the title bar contents of the active/foreground window and how long, in seconds, that that window is active/in the foreground. If the same window remains in the foreground but the title bar changes (as happens with a web browser application) then a new record is created for each new window title. If a window title is recorded that was previously recorded (on the same date -- see "Data Structures" info in section 4.4), then the time should be added to the previously recorded active time for that window title. -- Example -- 1) User clicks "Start" -> app enters "recording" state. 2) User opens window titled "Window 1" -> app looks for any prior records for "Window 1" on current date. Finding none, it creates a new record. 3) User opens another window titled "Window 2" -> app records total time spent in "Window 1", then looks for any prior records for "Window 2" on current date. Finding none, it creates a new record. 4) User re-raises/re-activates previous window "Window 1" -> app records total time spent in "Window 2", then looks for any prior records for "Window 1" on current date. It finds the record created earlier, so no new record is created. 5) User clicks "Stop" (or "Exit") -> the app adds the time just spent in "Window 1" to the previously recorded time spent in "Window 1". App then returns to "ready" state. ii) idle In this substate, the app has detected that the computer's screensaver is active and no time will be recorded for the active/foreground window. This substate is entered automatically (from the active window tracking state) when the screensaver activates and exited automatically (returning to the active window tracking state) when the screensaver is deactivated. Note that this substate should only be entered if the app was in the active window tracking state when the screensaver activated. Awaiting Your Reply, Thank You , Raja. From paddy3118 at netscape.net Tue Dec 12 21:03:49 2006 From: paddy3118 at netscape.net (Paddy) Date: 12 Dec 2006 18:03:49 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165857526.721489.322470@73g2000cwn.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> <1165857526.721489.322470@73g2000cwn.googlegroups.com> Message-ID: <1165975429.053195.95700@j72g2000cwa.googlegroups.com> JShrager at gmail.com wrote: > > > > Python has this unsung module called doctest that neatly shows some of > > > > the strengths of python: http://en.wikipedia.org/wiki/Doctest > > > > Now I'm *certain* that you're just pulling my leg: You guys document > > > all your random ten-line hacks in Wikipedia?!?! What a brilliant idea! > > > Python is newbie-friendly. Part of that is being accessible. > > Doctest is about a novel way of using a feature shared by Lisp, that is > > docstrings. Testing is important, usually not done enough, and doctests > > are a way to get people to write more tests by making it easier. Does > > Lisp have similar? > > Seems like a trivial commonality between the languages, and a trivial > library, but that's not at all what I was laughing at... Yep, doctest is trivial to use. Its part of its power ;-) > > > > Hey, you even have dead vaporware projects like uuu documented in > > > Wikipedia! Cool! (Actually, I don't know that doctest is ten lines in > > > Python, but it'd be about ten lines of Lisp, if that, so I'm just > > > guessing here.) > > > Does Lisp have a doctest-like module as part of its standard > > distribution? Or are you saying that If you ever needed it, then it would be > > trivial to implement in Lisp, and you would 'roll your own'? There are > > advantages to doctest being one of Pythons standard modules. > > Actually, I don't care what you put into your library -- to some exent, > the more the merrier (as I've said elsewhere, I wish we had your > community of busy ... um ... beavers :-) to create libraries full of > stuff, trivial or not!) The wheat will rise from the chaff. (Some > Lispers might disagree with me here.) Its not so much the library creation. You also need the organisation, and the willingness to accept that others can write good code too, (in whatever language), and hold off from that first impulse to roll-your-own library. > > But anyway, what I was laughing at had nothing to do with doctest -- > but that you use wikipedia to document your libraries. Elsewhere I have > aregued that Wikipedia is a stupid marketing document -- *many* Lispers > disagree with me here, so let's no go down this road, please as it's > soooooooo OT! So, I'm mostly laughing at the laughability of the > concept of the Wikipedia as somehow a source of all wisdom, not doctest > per se. Random ten-line Python libraries (as well as dead vaporware > python projects, as well as a whole bunch of other useless crap, and > the very occassionally useful crap) being in Wikiperdia just makes me > smile, that's all. Oh, you don't like Wikipedia. There are a lot of people that use Wikipedia. I think some of them might want to learn to program. I make it easier for them to find Python by helping to maintain Python within Wikipedia. If I am researching anything then I like to cross check with information from multiple sites. that's just good practice. Some people dislike Wikipedia which is fine. Some people dislike Wikipedia and deliberately sabotage it, which is vandalism. -Paddy. From hg at nospam.org Tue Dec 12 08:55:50 2006 From: hg at nospam.org (hg) Date: Tue, 12 Dec 2006 07:55:50 -0600 Subject: paramiko public key References: <1165898171.088807.100360@j44g2000cwa.googlegroups.com> Message-ID: eight02645999 at yahoo.com wrote: > paramiko http://www.lag.net/paramiko/docs/ __str__ ? From enleverlesX.XmcX at XmclaveauX.com Mon Dec 11 14:58:32 2006 From: enleverlesX.XmcX at XmclaveauX.com (Méta-MCI) Date: Mon, 11 Dec 2006 20:58:32 +0100 Subject: Pb ReportLab (ttfonts.py) References: <457d4ba5$0$5067$ba4acef3@news.orange.fr> Message-ID: <457dbae4$0$5092$ba4acef3@news.orange.fr> Hi! >>> Does the PDF generation work? Those are just warnings. Yes, it run. Yes it's only warning But, it's wincing... @-salutations MCI From yuxi at ece.gatech.edu Tue Dec 12 03:48:04 2006 From: yuxi at ece.gatech.edu (Yu-Xi Lim) Date: Tue, 12 Dec 2006 03:48:04 -0500 Subject: Tarfile .bz2 In-Reply-To: <457E4667.5080703@v.loewis.de> References: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> <1165887178.775792.142820@80g2000cwy.googlegroups.com> <457E4667.5080703@v.loewis.de> Message-ID: Martin v. L?wis wrote: > Well, .jpg files are already compressed in a lossy way (.jpg is > inherently lossy); to compress it further, you need to increase > the loss. PNG is also compressed already, see Not really. Stuffit has a JPEG compressor which takes advantage of the fact that the JPEG algorithm isn't as optimal as it can be. It converts JPEG images to its own more compact representation which then can be converted back to JPEG as needed, without any loss. It is sadly not free. From stuart at bmsi.com Sat Dec 9 11:47:13 2006 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sat, 09 Dec 2006 11:47:13 -0500 Subject: Automatic debugging of copy by reference errors? References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165645676.694401.193580@16g2000cwy.googlegroups.com> <1165666093.996141.244760@n67g2000cwd.googlegroups.com> <1165672702.406793.320500@79g2000cws.googlegroups.com> Message-ID: On Sat, 09 Dec 2006 05:58:22 -0800, Niels L Ellegaard wrote: > I wanted a each object to know whether or not it was being referred to > by a living object, and I wanted to warn the user whenever he tried to > change an object that was being refered to by a living object. As far > as I can see the garbage collector module would allow to do some of > this, but one would still have to edit the assignment operators of each > of the standard data structures: I think what you want is a namespace that requires each object to have exactly one reference - the namespace. Of course, additional references will be created during evaluation of expressions. So the best you can do is provide a function that checks reference counts for a namespace when called, and warns about objects with multiple references. If that could be called for every statement (i.e. not during expression evaluation - something like C language "sequence points"), it would probably catch the type of error you are looking for. Checking such a thing efficiently would require deep changes to the interpreter. The better approach is to revel in the ease with which data can be referenced rather than copied. I'm not sure it's worth turning python into fortran - even for selected namespaces. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From kentilton at gmail.com Sat Dec 9 21:59:58 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 21:59:58 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano wrote: > Rightly or wrongly, people fear... So when people fear wrongly we burn whatever witches we must to reassure them? > that Lisp's macros push Lisp closer to > that hypothetical anything-goes language than is healthy. Maybe that's a > problem of perception rather than a problem of fact, but you have to ask, > why do people perceive Lisp that way? > > Could it be because of people like J Shrager who writes things like this? > > "Can't you just expand the language via macros to create whatever facility > of this sort [major new features with new syntax] you need..." The context was CLOS. Something that big needs new syntax. But what you do not know is that the syntax is Lispy, so learning it is tantamount to understanding new function names, as even Pythonistas must do (tho a few of you seem to think Pythonistas are incapable of learning ). > > (This thread, dated 8 Dec 2006 16:14:44 -0800) > > Or Wolfram Fenske: > > "All the interesting features that haven't originated from Lisp (e. g. OO > from Smalltalk) could in turn easily be implemented in Lisp with a couple > of macros." Right, something big like an OO. > > (This thread, dated 8 Dec 2006 23:38:02 -0800) > > To someone outside of Lisp, that looks like "I can make Lisp look like any > language I like in just a few lines." On the contrary, on the rare case when it happens (CLOS, my Cells package) one is obliged by exactly the hobgoblins you fear to remain true to lisp patterns when extending Lisp. And there are patterns in macro usage as well: (my-macro +) Your hands must be getting sore from banging that drum so hard and so long -- has it ever occurred to you that good programmers concerned with power do not obfuscate code? And now you have read a dozen messages from serious Lispniks trying to tell you that that is not the case, and you persist. We love the chance to preach to the unsaved, so we are indebted to you for the many chances to clarify, but something tells me I should check the c.l.p archives to make sure I am not chatting away happily with the village idiot. :) > And that implies that to read a Lisp > program, one might need to be able to read code that looks like Lisp, or > Smalltalk, or Prolog, or Fortran, or all of those, or whatever bizarre > syntax the developer wanted it to look like. "I don't want to think, I just want to bang on de drum all day. I don't want to learn, just want to bang on de drum all day." > > My point isn't whether or not their claims are correct (a "couple" of > macros? really?) but that things like this feed the perception... Ah, well at least you are copping to witch-burning. Thx. > And it isn't really that much comfort to be told that good Lisp > developers know not to do stupid things with macros. Hmm, didn't we see that as a comforter for some powerful Python mechanism earlier in this thread? > Sure. But in the real > world of programming, most developers aren't good developers, they are > merely average Two questions: do you really voluntarily use libraries from crappy developers? Second, you think a language can stop people from writing bad code? Java tried, and look where that got the language. Elsewhere a Pythonista (Mr. Rubin?) bemoaned this thread's appearance of Pythonistas shrinking from power... could you two get together? :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From paul at boddie.org.uk Sat Dec 16 19:03:01 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 16 Dec 2006 16:03:01 -0800 Subject: Is there a way to push data into Microsoft Excel & Word from Python ? References: <458455f2$0$8219$426a74cc@news.free.fr> <1166303981.857285.156670@n67g2000cwd.googlegroups.com> Message-ID: <1166313781.213299.100610@16g2000cwy.googlegroups.com> Caleb Hattingh wrote: > Paul Boddie has written a great tutorial---which includes some Outlook > examples, btw---over here: > > http://thor.prohosting.com/~pboddie/Python/COM.html Thanks for the kind words! The most current location of this tutorial is here: http://www.boddie.org.uk/python/COM.html I don't use Windows any more, but I suppose it's still relevant to at least some people. Paul From __peter__ at web.de Fri Dec 15 06:39:16 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 Dec 2006 12:39:16 +0100 Subject: Property error References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> <1166179622.872556.312810@n67g2000cwd.googlegroups.com> <1166181267.949316.197360@16g2000cwy.googlegroups.com> Message-ID: king kikapu wrote: > Your example Dennis, work as expected. I understand the mistake i have > made. But when i try to fix the original code usihn @property now, it > gives me the same error. > So, here it is: > > class Person(object): > _age = 0 > > @property > def age(): > def fget(self): > return self._age > def fset(self, value): > self._age = value > > me = Person() > me.age = 34 > print me.age > > > I am sure it is something very obvious but my skills does not (yet) > enable me to figure this out,,, @decorator def f(): # ... is the same as def f(): # ... f = decorator(f()) What happens when your age() function is invoked? There is no explicit return statement, so None is implicitly returned, and age = property(age()) is the same as age = property(None) i. e. you get a property with None as the getter. What you want is >>> def star_property(f): ... return property(**f()) ... >>> class Person(object): ... _age = "unknown" ... @star_property ... def age(): ... def fget(self): ... return self._age ... def fset(self, value): ... self._age = value ... return locals() ... >>> person = Person() >>> person.age 'unknown' >>> person.age = 42 >>> person.age 42 However, that is rather hackish, and I recommend that you stick with the standard approach given by Dennis and limit the use of property as a decorator to read-only attributes: >>> class Forever42(object): ... @property ... def age(self): return 42 ... >>> Forever42().age 42 Peter From pavlovevidence at gmail.com Wed Dec 13 13:40:50 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 13 Dec 2006 10:40:50 -0800 Subject: Iterating over several lists at once In-Reply-To: <1166021513.479174.113630@80g2000cwy.googlegroups.com> References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> <1166021513.479174.113630@80g2000cwy.googlegroups.com> Message-ID: <1166035250.709872.135350@t46g2000cwa.googlegroups.com> Gal Diskin wrote: > On Dec 13, 3:58 pm, Roberto Bonvallet > wrote: > > Gal Diskin wrote: > > > Hi, > > > I am writing a code that needs to iterate over 3 lists at the same > > > time, i.e something like this: > > > > > for x1 in l1: > > > for x2 in l2: > > > for x3 in l3: > > > print "do something with", x1, x2, x3What's wrong with this? > > > > [...] > > > > > I'd be very happy to receive ideas about how to do this in one loop and > > > with minimal initialization (if at all required).def cartesian_product(l1, l2, l3): > > for i in l1: > > for j in l2: > > for k in l3: > > yield (i, j, k) > > > > for (i, j, k) in cartesian_product(l1, l2, l3): > > print "do something with", i, j, k > > Nothing seriously wrong, but it's not too elegent. I wonder why you think that. Many people here would consider it the height of elegance to take some complicated logic, writing a function encompassing the complicated parts, and ending up with simpler logic. That's what happens here. The cartesian_product solution above is not much longer than this syntax you proposed: for (i,j,k) in (a,b,c): use(i,j,k) (You can make the function name shorter if you want.) What is it that you find inelegant about this solution? Is it that you don't like extra function sitting there? Just put it in a module and import it. > Especially when the > number of lists you want to iterate over gets bigger (especially > because of the indentation in python). The function can be extended to allow arbitrary arguments. Here's a non-minmal recursive version. def cartesian_product(*args): if len(args) > 1: for item in args[0]: for rest in cartesian_product(*args[1:]): yield (item,) + rest elif len(args) == 1: for item in args[0]: yield (item,) else: yield () > As you noticed (an phrased > better than me), what I was wondering is if there is a way to iterate > over the cartesian product, but without actually doing all n for loops > but using a single "for" loop. Even if Python had a special syntax for it, it would still be looping internally. And there's almost no chance of there ever being a special syntax for it. First of all, it's very straightforward to do with functional solutions, as we've shown here. Second, compare the case of zip. Iteration in parallel (such as you would do with zip) is a lot more common than nested iteration (cartesian_product), but even parallel iteration doesn't have a special syntax, and th BDFL had declared that won't in Python 3.0. The best you could hope for is a built in function like zip, and that's doubtful. OTOH, something like this has decent shot of appearing in a standard functional or iterator module of some sort. > Thanks for replying me. You're welcome in advance. Also, one note about comp.lang.python and/or python-list: it's conventional here to put replies beneath the quoted text. This is for the benefit of future readers, so they don't have read conversations in reverse order. Carl Banks From felix.benner at imail.de Wed Dec 20 00:57:17 2006 From: felix.benner at imail.de (Felix Benner) Date: Wed, 20 Dec 2006 06:57:17 +0100 Subject: MySQLdb, lots of columns and newb-ness In-Reply-To: References: Message-ID: Andrew Sackville-West schrieb: > I have an ascii data dump from a POS system that has 131 fields in a > single column in a flat file. I can easily open the file, read in the > data and assemble it into various formats. okay. what I *want* to do > is insert each of these fields into a mysql database that has 132 > columns that correspond to the 131 fields in the ascii file (plus one > for the date). > > I can successfully connect to mysql and do stuff to my tables my > specific problem is how to efficiently put those 132 fields into the > thing. All I have been able to figure out is really ugly stuff like: > build the mysql statement out of various pieces with appropriate > commas and quote included. stuff like (not tested) Haven't tested it, but maybe http://dev.mysql.com/doc/refman/5.0/en/load-data.html is your friend. From kkylheku at gmail.com Tue Dec 12 00:26:15 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 11 Dec 2006 21:26:15 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xwt4y6j57.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> <7xwt4y6j57.fsf@ruckus.brouhaha.com> Message-ID: <1165901175.925057.56000@n67g2000cwd.googlegroups.com> Paul Rubin wrote: > Andr? Thieme writes: > > > import module > > > module.function = memoize(module.function) > > > > Yes, I mentioned that a bit earlier in this thread (not about the > > "during runtime" thing). > > I also said that many macros only save some small bits of code. > > Your python example contains 4 tokens / brain units. > > The Lisp version only has 2. > > You shouldn't count the import statement, since you'd need the > equivalent in Lisp as well. > > Contrast the much more common > > a[i] = b[n] > > with > > (setf (aref a i) (aref b n)) > > and the attractions of Python may make more sense. Actual Lisp session transcript: [1]> (load "infix.cl") ;; Loading file infix.cl ... ;;; ************************************************************************* ;;; Infix notation for Common Lisp. ;;; Version 1.3 28-JUN-96. ;;; Written by Mark Kantrowitz, CMU School of Computer Science. ;;; Copyright (c) 1993-95. All rights reserved. ;;; May be freely redistributed, provided this notice is left intact. ;;; This software is made available AS IS, without any warranty. ;;; ************************************************************************* ;; Loaded file infix.cl T [2]> #i( if x < y then a[i] = b[j] else a[i] = c[j,j] ^^ w ) *** - EVAL: variable X has no value The following restarts are available: USE-VALUE :R1 You may input a value to be used instead of X. STORE-VALUE :R2 You may input a new value for X. ABORT :R3 ABORT Break 1 [3]> :a [4]> (quote #i( if x < y then a[i] = b[j] else a[i] = c[j,j] ^^ w )) (IF (< X Y) (SETF (AREF A I) (AREF B J)) (SETF (AREF A I) (EXPT (AREF C J J) W))) In spite of such possibilities, things like this just don't catch on in Lisp programming. Once people know that they /can/ get it if they want, they no longer want it. What doesn't make sense is writing entire language implementations from scratch in order to experiment with notations. I think someone may have been working on a Python interface built on Common Lisp. Ah, here! http://trac.common-lisp.net/clpython/wiki/WikiStart From dakman at gmail.com Tue Dec 12 13:55:56 2006 From: dakman at gmail.com (dakman at gmail.com) Date: 12 Dec 2006 10:55:56 -0800 Subject: Forking in windows. Possible? Message-ID: <1165949756.863476.57870@73g2000cwn.googlegroups.com> I know under mac/*nix it's possible to fork the proccess to the background and exit the parent process. I have used this on a couple of my projects, but right now I am working on a project that will be required to run in the background, I have considered using the .pyw extension on my files, but there will be parts of the program that will be required to show the console. So if anyone has an ideas... -Thanks From justask at acme.com Tue Dec 5 18:58:46 2006 From: justask at acme.com (Vincent Delporte) Date: Wed, 06 Dec 2006 00:58:46 +0100 Subject: Mod_python vs. application server like CherryPy? Message-ID: Hi I'm still a newbie when it comes to web applications, so would like some help in choosing a solution to write apps with Python: What's the difference between using running it through mod_python vs. building an application server using Python-based tools like CherryPy, Quixote, Draco, etc.? Thanks. From bumtool at gmail.com Sun Dec 3 07:55:54 2006 From: bumtool at gmail.com (kilnhead) Date: 3 Dec 2006 04:55:54 -0800 Subject: How to realize the interactive python in Eclipse? In-Reply-To: <1165068796.417513.86280@n67g2000cwd.googlegroups.com> References: <1165068796.417513.86280@n67g2000cwd.googlegroups.com> Message-ID: <1165150554.391050.51300@n67g2000cwd.googlegroups.com> purple wrote: > I have installed the Eclipse and the plug-in Pydev. Also, I have add an > python program in the external tools. When I run the python program in > the external tools, i can type python command just like in the python > shell.But when I finished running a python file, in the console, I > could not type any command to check some argument generated in the > process. Is there any way I can make it? > thank you~~ Do you not want to run python from eclipse? If so, go to preferences for pydev and show pydev where your python executable is. Then you can use the debug function to look at variables. For the external tools problem with python interactive, did you include "-i" as an argument for the python interpreter? From jtgalkowski at alum.mit.edu Wed Dec 27 22:22:23 2006 From: jtgalkowski at alum.mit.edu (Jan Theodore Galkowski) Date: Wed, 27 Dec 2006 22:22:23 -0500 Subject: loose methods: Smalltalk asPython Message-ID: <1167276143.23970.282210691@webmail.messagingengine.com> [snipness] >I don't think the response was meant to say that it must be bad but >that it won't show up as feature in Python as long as the BDFL thinks >it's bad. [snipness] oh, i was not proposing any change to the language. it's fine as it is. i would be reluctant to change it. i want it changed only as absolutely necessary. my point and idea is that within any good language, like Python -- and especially if it is a dynamic language -- there are many styles of development possible, some based upon other-than-conventional interpretations of the language's Dark Corners. what i was really seeking was to tap the experience of people who, being familiar with loose methods, had tried to realize them in Python in some way. particularly in connection with reflection, i think they are slick. anyway, Python is the coolest damn language i've seen since Smalltalk. and i was a big time LISP hacker once. Python obviously includes a lot of things which Smalltalk did not and does not have, simply because it's culture is more modern and Python's community is so much more vibrant. and it don't hurt that it has good numerical support. -- Jan -- Jan Theodore Galkowski (o?) jtgalkowski at alum.mit.edu http://tinyurl.com/qty7d From skip at pobox.com Sun Dec 31 14:23:15 2006 From: skip at pobox.com (skip at pobox.com) Date: Sun, 31 Dec 2006 13:23:15 -0600 Subject: Missing erf() In-Reply-To: <1167592158.085766.45140@48g2000cwx.googlegroups.com> References: <1167592158.085766.45140@48g2000cwx.googlegroups.com> Message-ID: <17816.3619.126136.486222@montanaro.dyndns.org> rrenaud> Is there a reason why erf() is not included in the math rrenaud> package? According to the following URL it looks like it has rrenaud> been standard C since 1999. Python is implemented in the C89 dialect. Maybe Python 3.0 will be implemented using C99. Skip From fredrik at pythonware.com Fri Dec 8 12:45:24 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 08 Dec 2006 18:45:24 +0100 Subject: Using Py_InitModule3 -> [Linker Error] Unresolved external '_Py_InitModule4TraceRefs' In-Reply-To: <1165599265.119546.194850@j44g2000cwa.googlegroups.com> References: <1165599265.119546.194850@j44g2000cwa.googlegroups.com> Message-ID: iwl wrote: > I copied the code from the Extending Embedded Python section in the > Python 2.5 but get an linker Error Unresolved external > _Py_InitModule4TraceRefs. > Who knows what's wrong? you've mixed components compiled with Py_TRACE_REFS with components that aren't compiled with Py_TRACE_REFS. don't do that. (what is it with you C programmers these days, btw? have they stopped teaching how to how use "grep" and library inspection tools when they teach C and C++ ?) From mohan.us2010 at gmail.com Tue Dec 12 03:38:24 2006 From: mohan.us2010 at gmail.com (mohan) Date: 12 Dec 2006 00:38:24 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> Message-ID: <1165912704.390252.184260@n67g2000cwd.googlegroups.com> BartlebyScrivener wrote: > mohan wrote: > > > I had created my own modules (.py files) in > > drives and folders other than the python root. > > Probably easiest if you keep them all in one place. Then add that > "place" to your path by going into Control > Panel|System|Advanced|Environment Variables and adding the path to the > path variable. > > Hope that helps. > > rd Thanks rd, I tried your advice, by adding a new path to the "System Variable" section. It still does not work. I don't understand how could PythonWin interpreter would look for new folders when we have not yet updated the path in the interpreter. I'm sorry I might be mising something here as i'm not too familiar with these things. Any further ideas?? Regards, Mohan. From ihatespam at hotmail.com Fri Dec 29 14:15:41 2006 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Fri, 29 Dec 2006 19:15:41 GMT Subject: Getting VideoCapture to work with Python 2.5 Message-ID: I can't seem to get VideoCapture (http://videocapture.sourceforge.net/) to work with my version of Python (2.5). Why is that? I've followed the instructions which made it look easy but, as it happens all too often, it simply doesn't work. The error I get is that the .py interface file can't find an expected module (using the "import" keyword) but that module exists as a DLL in the correct directory. Why doesn't it recognize it? Has anyone else used this library with Python 2.5 successfully? Any theories as to what might be going wrong? Thank you... From cpl.19.ghum at spamgourmet.com Sat Dec 2 06:23:35 2006 From: cpl.19.ghum at spamgourmet.com (Armin) Date: 02 Dec 2006 11:23:35 GMT Subject: Python, PostgreSQL, What next? References: <1165043076.979652.201730@16g2000cwy.googlegroups.com> Message-ID: > I've studied Python and studied PostgreSQL. Good. >What is the absolute next best step to take to merge these two finely >together? I've heard of Just download psycopg2. Python and PostgreSQL are a match made in heavan. Make your connection, do querys, get data, earn profits. Object-Relational-Mappers are to direct SQL as phone sex is to the real thing. Harald From dimitri.pater at gmail.com Wed Dec 6 19:15:33 2006 From: dimitri.pater at gmail.com (dimitri pater) Date: Thu, 7 Dec 2006 01:15:33 +0100 Subject: SPE (Stani's Python Editor) web site? In-Reply-To: References: <1164748601.099263.98060@l12g2000cwl.googlegroups.com> <1165280800.147167.108670@73g2000cwn.googlegroups.com> Message-ID: Hi, You would do me and other gurus a great favour if you put it on a server > somewhere. I can put it on my server (serpia.org) if you want to, just email it to me and you can download it from serpia.org/spe --- You can't have everything. Where would you put it? -- Steven Wright --- please visit www.serpia.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From bjourne at gmail.com Sun Dec 24 06:52:59 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sun, 24 Dec 2006 12:52:59 +0100 Subject: some OT: how to solve this kind of problem in our program? In-Reply-To: <6a4f17690612232039r4c8b5f99r6985885ebaba062e@mail.gmail.com> References: <6a4f17690612232039r4c8b5f99r6985885ebaba062e@mail.gmail.com> Message-ID: <740c3aec0612240352r3f524ef0g40a575545f74802@mail.gmail.com> On 12/24/06, oyster wrote: > 1. first of all, what is the English jargon (Optimize? But I think > this is not a very good keyword :( )for this problem? So I can use it > to search on the internet The first problem is a magic square. The general term for all your problems are constraint satisfaction problems. > 2. is there any free/open lib for this? Yes, this for example: http://labix.org/python-constraint > 3. I know for some questions(case 1, case 2, and sudoku), we can use > bundles of "FOR...NEXT" loop to program. however I think it is clumsy > and inconvenient, especially when there is many vars Yes. I think it is also very much unoptimal. For solving problems such as magic squares and sudoku puzzles you want a recursive backtracking constraint solver. > case: > 1. choose x0~x9 from 1~9, and must use all of 1~9, let > x0/(10*x1+x2)+x3/(10*x4+x5)+x6/(10*x7+x8)=1/2 Using the linked to constraint solver, you could write something like this: p = Problem() # Ten variables named 0..9 all with values in the domain 0..9 p.addVariables(range(10), range(10)) p.addConstraint(AllDifferentConstraint(), range(10)) def eqConstraint(*x): t = x[0]/(10*x[1] + x[2]) + x[3]/(10 * x[4] + x[5]) + x[5](10 * x[7] + x[8]) # Convert to int to get rid of rounding errors t = int(t * 2) return t == 1 p.addConstraint(eqConstraint, range(10)) p.getSolutions() > 2. choose x0~x15 from 1~16, and must use all of 1~16, let > +-----+-----+-----+-----+ > | x0 | x1 | x2 | x3 | > +-----+-----+-----+-----+ > | x4 | x5 | x6 | x7 | > +-----+-----+-----+-----+ > | x8 | x9 | x10 | x11 | > +-----+-----+-----+-----+ > | x12 | x13 | x14 | x15 | > +-----+-----+-----+-----+ > > sum of every column =sum of of every row > = x0+x5+x10+x11 =x3+x6+x9+x12 Similar to above, just enter all the constraints and let the library do the hard work: def lineConstraint(*l): s1 = sum(l[:4]) s2 = sum(l[4:]) return s1 == s2 # For magic squares, recursive backtracking solves are the best p = Problem(RecursiveBacktrackingSolver()) p.addConstraint(AllDifferentConstraint()) p.addConstraint(lineConstraint, [0, 5, 10, 11, 3, 6, 9, 12]) ... add more constraints... p.getSolution() HTH -- mvh Bj?rn From deets at nospam.web.de Tue Dec 19 06:34:41 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 19 Dec 2006 12:34:41 +0100 Subject: Class property with value and class References: <1166508146.304422.198590@a3g2000cwd.googlegroups.com> Message-ID: <4uq12hF194eqsU1@mid.uni-berlin.de> manstey wrote: > Hi, > > Is is possible to have two classes, ClassA and ClassB, and > setattr(ClassA, 'xx',ClassB), AND to then have ClassA.xx store an > integer value as well, which is not part of ClassB? > > e.g. If ClassB has two properties, name and address: > > ClassA.xx=10 > ClassA.xx.name = 'John' > ClassA.xx.address = 'Sydney'. > > etc? I've no idea if this is possible or desirable. It's neither of both options. If you must, you can subclass int, and have additional properties. But then you can't do it like above, but instead must do: ClassA.xx = MyAddressInt(10) Diez From tomas at fancy.org Sun Dec 17 01:45:35 2006 From: tomas at fancy.org (Tom Plunket) Date: Sat, 16 Dec 2006 22:45:35 -0800 Subject: textwrap.dedent replaces tabs? References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> Message-ID: CakeProphet wrote: > Hmmm... a quick fix might be to temporarily replace all tab characters > with another, relatively unused control character. > > MyString = MyString.replace("\t", chr(1)) > MyString = textwrap.dedent(MyString) > MyString = MyString.replace(chr(1), "\t") > > Of course... this isn't exactly safe, but it's not going to be fatal, > if it does mess something up. As long as you don't expect receiving any > ASCII 1 characters. Well, there is that small problem that there are leading tabs that I want stripped. I guess I could manually replace all tabs with eight spaces (as opposed to 'correct' tab stops), and then replace them when done, but it's probably just as easy to write a non-destructive dedent. It's not that I don't understand /why/ it does it; indeed I'm sure it does this so you can mix tabs and spaces in Python source. Why anyone would intentionally do that, though, I'm not sure. ;) -tom! -- From bearophileHUGS at lycos.com Mon Dec 4 15:15:27 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 4 Dec 2006 12:15:27 -0800 Subject: Factory pattern implementation in Python In-Reply-To: References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> Message-ID: <1165263327.407166.276160@l12g2000cwl.googlegroups.com> Dennis Lee Bieber: > Presuming the is a type code I'd just set up a list of functions: > Then create a dictionary of them, keyed by the code > processors = { "1" : process_1, > "2" : process_2, > .... > "x" : process_x } Just a dict of functions was my solution too, I think avoiding more complex solutions is positive. Bye, bearophile From rampeters at gmail.com Mon Dec 11 21:49:40 2006 From: rampeters at gmail.com (johnny) Date: 11 Dec 2006 18:49:40 -0800 Subject: newb: SENDING os.system(encode_cmd) output to a logging file In-Reply-To: References: <1165880879.620563.287790@l12g2000cwl.googlegroups.com> Message-ID: <1165891780.262871.200130@79g2000cws.googlegroups.com> I am doing the os.system(encode_cmd) within a thread. So you are saying, have each thread create a subprocess module. Did you mean, "Popen" (os.popen)? Like os.popen(encode_cmd) , not os.system(encode_cmd)? Gabriel Genellina wrote: > At Monday 11/12/2006 20:47, johnny wrote: > > >How do I pipe the output, generated from os.system(some_command), to > >the logging file? > > Use the subprocess module to run the command instead. > > > -- > Gabriel Genellina > Softlab SRL > > __________________________________________________ > Correo Yahoo! > Espacio para todos tus mensajes, antivirus y antispam ?gratis! > ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From pyenos at pyenos.org Fri Dec 22 08:27:16 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 00:27:16 +1100 Subject: Confusion over calling a nested function inside a parent function Message-ID: <877iwkdpsb.fsf@pyenos.pyenos.org> [code] class WORK: def getwork(self): def choosetable(self):pass choosetable() #TypeError: choosetable() takes exactly 1 #argument (0 given) [/code] Calling choosetable() at the above location gives me the error described above. From fumanchu at amor.org Tue Dec 19 16:21:06 2006 From: fumanchu at amor.org (fumanchu) Date: 19 Dec 2006 13:21:06 -0800 Subject: Http server In-Reply-To: References: Message-ID: <1166563266.178045.251540@73g2000cwn.googlegroups.com> Gert Cuykens wrote: > so far this works > > > import cherrypy > import os.path > > class Http: > > def index(self): > f = open(os.path.join(os.path.dirname(__file__), '../htm/index.htm')) > xml = f.read() > f.close() > return xml > index.exposed = True > > cherrypy.tree.mount(Http()) > > if __name__ == '__main__': > cherrypy.config.update(os.path.join(os.path.dirname(__file__), > 'server.conf')) > cherrypy.server.quickstart() > cherrypy.engine.start() > > > I would like a cute secretary for Christmas but i dont think i will > get one. So i need to find a way to scan a directory. And map all > files inside the directory and generate a class member like > > > def filename(self): > f = open(os.path.join(os.path.dirname(__file__), '../htm/filename')) > xml = f.read() > f.close() > return xml > filename.exposed = True > > > Any idea or cute secretary maybe ? The cute secretary's name is "cherrypy.tools.staticdir". Check out her resume at http://www.cherrypy.org/wiki/StaticContent Robert Brewer System Architect Amor Ministries fumanchu at amor.org From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Wed Dec 6 11:16:46 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Wed, 06 Dec 2006 17:16:46 +0100 Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net> Message-ID: <4to8neF157i8fU1@mid.individual.net> Peter Otten wrote: > No, 'k in d' is equivalent to 'd.has_key(k)', only with less > (constant) overhead for the function call. Ah, thx. Thought the "x in d" syntax might search in d.values() too. Regards, Bj?rn -- BOFH excuse #12: dry joints on cable plug From http Fri Dec 15 21:25:11 2006 From: http (Paul Rubin) Date: 15 Dec 2006 18:25:11 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> <1166102108.129051.166580@73g2000cwn.googlegroups.com> <4ufenbF17of60U6@mid.individual.net> <7x7iwsd932.fsf@ruckus.brouhaha.com> Message-ID: <7x4prw4lx4.fsf@ruckus.brouhaha.com> Andr? Thieme writes: > > But there would be even more tokens, the lines going between the > > nodes > > in the trees, for example. > > These are painted by the editor. If you have to tell the editor where to put them, they are tokens. From gagsl-py at yahoo.com.ar Mon Dec 11 21:09:58 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 23:09:58 -0300 Subject: AttributeError: Logger instance has no attribute 'setFormatter' In-Reply-To: <1165887128.688715.284320@f1g2000cwa.googlegroups.com> References: <1165887128.688715.284320@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061211230510.03f07dc0@yahoo.com.ar> At Monday 11/12/2006 22:32, johnny wrote: >def setupLogging(): > global log > log = logging.getLogger("ftp") Also, there is no need to use a global here. The logging machinery will return always the same logger given the same name. So logging.getLogger("ftp") will be always the same. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From defcon8 at gmail.com Sat Dec 23 16:35:42 2006 From: defcon8 at gmail.com (defcon8) Date: 23 Dec 2006 13:35:42 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1166906310.452197.185700@48g2000cwx.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1166906310.452197.185700@48g2000cwx.googlegroups.com> Message-ID: <1166909742.176850.233910@80g2000cwy.googlegroups.com> All of you are nazis! From jan.dries at dcube-resource.be Wed Dec 13 04:20:31 2006 From: jan.dries at dcube-resource.be (Jan Dries) Date: Wed, 13 Dec 2006 10:20:31 +0100 Subject: merits of Lisp vs Python In-Reply-To: <457fc327$0$1038$426a74cc@news.free.fr> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> Message-ID: <457FC5DF.9090309@dcube-resource.be> Christophe wrote: > Robert Uhl a ?crit : >> aahz at pythoncraft.com (Aahz) writes: >>> Consider this: Lisp has had years of development, it has had millions of >>> dollars thrown at it by VC firms -- and yet Python is winning over Lisp >>> programmers. Think about it. >> The argument from popularity is invalid. French units have overtaken >> standard units, > Never heard of that French unit thing. Unless you talk about that > archaic unit system that was in use before the metric system was created. And who do you think created the metric system? Regards, Jan From larry.bates at websafe.com Mon Dec 4 12:20:42 2006 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 04 Dec 2006 11:20:42 -0600 Subject: Printing unix Line endings from Windows. In-Reply-To: <1165247935.679325.242850@80g2000cwy.googlegroups.com> References: <1165247935.679325.242850@80g2000cwy.googlegroups.com> Message-ID: Ant wrote: > Hi all, > > I've got a problem here which has me stumped. I've got a python script > which does some text processing on some files and writes it back out to > the same file using the fileinput module with inplace set to True. > > The script needs to run from Windows, but the files need to be written > with Unix line endings. > > Is there any way of doing this without having to post-process the file > in binary mode (a-la the crlf.py script) > > Cheers, > You can write to a new file and create your own line endings. When done, delete the original file and rename the output file. -Larry From eldorado at io.com Wed Dec 27 14:21:36 2006 From: eldorado at io.com (eldorado) Date: Wed, 27 Dec 2006 13:21:36 -0600 Subject: getting a process's PID In-Reply-To: <4592b4bd$1@nntp.zianet.com> References: <20061227102939.L20663@eris.io.com> <4592abf1$1@nntp.zianet.com> <20061227113158.J21223@eris.io.com> <4592b4bd$1@nntp.zianet.com> Message-ID: <20061227130942.W21223@eris.io.com> On Wed, 27 Dec 2006, Erik Johnson wrote: > > "eldorado" wrote in message > news:20061227113158.J21223 at eris.io.com... > >>>>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") >>>>> h = g.readlines() >>>>> g.close() >>>>> h >> ['87334\012'] >>>>> h = h[:-1] >>>>> h >> [] > > Oh, sorry... h is a list here because you are using readlines(). > I am used to doing this: > > fd = os.popen('ps -ef | grep python') > s = fd.read() > > to get a single string. You can do something like > > s = h[0] > > and then operate on s, or you can use read() in place of readlines() to get > h as a single string, or you can operate on the first element of h: > >>>> h = ['87334\012'] >>>> h[0][:-1] > '87334' >>>> h[0].rstrip('\n') > '87334' > > All the error handling to do in the case where you actually have multiple > processes being matched is up to you. ;) Erik, Thank you very much. Works perfect. I am now off to work on the multiple process issue. -- Randomly generated signature Claiming that your operating system is the best in the world because more people use it is like saying McDonalds makes the best food in the world. From gdamjan at gmail.com Thu Dec 21 22:29:54 2006 From: gdamjan at gmail.com (Damjan) Date: Fri, 22 Dec 2006 04:29:54 +0100 Subject: Is there any python-twisted tutorial or texts? References: <1166496307.681933.247810@t46g2000cwa.googlegroups.com> Message-ID: <458b5130$0$49207$14726298@news.sunsite.dk> >> I want to study twisted of python . But I donot know how to start. >> Any suggistions? >> > > There is a book about using Twisted. It's called 'Twisted Network > Programming Essentials.' It is an entry-level book at best, but it does go > over quite a lot of things that the Twisted library is capable of. Well, the book is not that good. It completely fails to explain deferreds which are a central concept in Twisted. I only understood deferreds when watching Bob Ippolitos screencast about Mochikit which implements the same API as Twisted... Then I got back to the Twisted book. I think it needs more work. -- damjan From belred at gmail.com Sun Dec 10 02:33:03 2006 From: belred at gmail.com (Bryan) Date: Sat, 09 Dec 2006 23:33:03 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> Message-ID: Harry George wrote: > It would probably be fair to say that the more you know > about a variety of languages, the more you appreciate Python. +1 QOTW From thomas at mindz-i.co.nz Mon Dec 4 18:30:25 2006 From: thomas at mindz-i.co.nz (Thomas Thomas) Date: Tue, 5 Dec 2006 12:30:25 +1300 Subject: mapped drive missing when run as a service Message-ID: <005301c717fc$2f72f950$3d6ea8c0@eformswin2> Hi All, I have a python application which i run as a service.. import win32api,string drives=win32api.GetLogicalDriveStrings() drives=string.splitfields(drives,'\000') print drives in the list of drives my mapped network drive is not showing when i run the application as a service. I tried running the service as an administrator but with similar results.. any work around for this situation.. All i want is to access network files when run the application as a service.. Cheers Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Sat Dec 16 02:47:30 2006 From: timr at probo.com (Tim Roberts) Date: Sat, 16 Dec 2006 07:47:30 GMT Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> Message-ID: Tim Daneliuk wrote: > >This seems to work, at least approximately: > > os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH > >It probably does not catch every single instance of something >that could be considered "executable" because this is a sort >of fluid thing in Windows (as you point out). This will tell you that "x.exe" is executable, even if "x.exe" contains nothing but zeros. On the other hand, I'm not convinced that any other solution is better. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From zondo42 at googlemail.com Thu Dec 14 08:36:49 2006 From: zondo42 at googlemail.com (Glenn Hutchings) Date: 14 Dec 2006 05:36:49 -0800 Subject: tuple.index() In-Reply-To: References: Message-ID: <1166103409.199435.290670@79g2000cws.googlegroups.com> Simon Brunning wrote: > It's because, philosophically, a Python tuple isn't just a read-only list. But there are situations where you might want to treat it as a read-only list. E.g., an argument to a function, so that you can guarantee the function won't modify it. In that case, it makes sense for the non-modifying methods (index() and count()) to be available. From kloro2006 at gmail.com Sun Dec 10 12:46:09 2006 From: kloro2006 at gmail.com (tom arnall) Date: Sun, 10 Dec 2006 09:46:09 -0800 Subject: object data member dumper? Message-ID: <200612100946.09546.kloro2006@gmail.com> >object data member dumper? >George Sakkis george.sakkis at gmail.com >Wed Nov 8 03:42:47 CET 2006 > tom arnall wrote: > > > Bruno Desthuilliers wrote: > > > > > tom arnall a ?crit : > > >> does anyone know of a utility to do a recursive dump of object data > > >> members? > > >> > > > > > > What are "object data members" ? (hint: in Python, everything is an > > > object - even functions and methods). > > > > > > What is your real use case ? > > > > something like: > > > > class A: > > def __init__(self, p1): > > self.p1 = p1 > > > > class B: > > def __init__(self,p1, p2): > > self.a = A(p1) > > self.p2 = p2 > > self.v1 = '3' > > > > class C: > > def __init__(self): > > self.b = B(3,4) > > self.p3 = 5 > > > > class D: > > def __init__(self): > > self.v2=2 > > self.o1 = C() > > self.o2 = B(11,12) > > > > > > d = D() > > objectDataDumper(d) > > > > > > would produce something like: > > > > object of class D with: > > o1(C)->b(B)->a(A)->p1=3 > > o1(C)->b(B)->p2=4 > > o1(C)->b(B)->v1=3 > > o1(C)->p3=5 > > o2(B)->a(A)->p1=11 > > o2(B)->p2=12 > > o2(B)->v1=3 > > v2=2 > > > > > > tom arnall > > north spit, ca > > usa > > At first I thought pickle would be what you're looking for, because > that's exactly what it does; it dumps arbitrary objects, without > choking on recursive references. Only problem is, it's not human > readable (even in its ascii form).If you want it to be human readable, > you may check the gnosis.xml.pickle module > (http://cheeseshop.python.org/pypi/Gnosis_Utils/1.2.1-a). That's the > output of gnosis.xml.pickle.XML_Pickler(d).dumps() on your example: > > > > > > class="B"> > class="A"> > > > > > > class="C"> > > class="B"> > class="A"> > > > > > > > > > > I've also written a similar but less verbose xml dumper. The gnosis.xml > package provides a bidirectional mapping between objects and xml > (objects -> xml and xml->object) and therefore has to be precise; mine > simply generates a nice xml dump of the object which isn't necessarily > reversible. Here's the output for your example: > > > > > > 3 > > 4 > 3 > > 5 > > > > 11 > > 12 > 3 > > 2 > > > > If you find it suits you better, I'll try to make it available > somewhere (probably in the cookbook). > > George > George, did you ever put up your object dumper on the net? tom arnall north spit, ca usa Make cyberspace pretty: stamp out curly brackets and semicolons. From espen at vestre.net Tue Dec 12 06:54:34 2006 From: espen at vestre.net (Espen Vestre) Date: 12 Dec 2006 12:54:34 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> <7xwt4yju5e.fsf@ruckus.brouhaha.com> <7x1wn57voq.fsf@ruckus.brouhaha.com> <7xirghy7pu.fsf@ruckus.brouhaha.com> <7xvekhxscq.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > I think the Lispies see "more dynamism" as a good thing Sure... > I mean "dynamic" in a less good way-- there is a huge amount of > state scattered all through a running Python program, that the > application can modify at random and whose contents the working of > really fundamental operations like method invocation. That's what I call /kludgy/, not /dynamic/ ;-) > How about if I say Python and Lisp are both dynamic, but Lisp does a > better job of keeping its dynamism's potentially chaotic effects > contained. Does that help? Yes, that's fine with me! -- (espen) From silverbeach06 at gmail.com Thu Dec 14 14:36:56 2006 From: silverbeach06 at gmail.com (susan) Date: 14 Dec 2006 11:36:56 -0800 Subject: how to bind a command to the open button In-Reply-To: References: <1165945038.464128.43320@j44g2000cwa.googlegroups.com> Message-ID: <1166125016.895791.209820@16g2000cwy.googlegroups.com> Thank you very much, after I asked the question, I realized it has a simple answer, exactly in your reply:) hg wrote: > susan wrote: > > > Hi, > > Anybody knows how to bind a command to the open button at a file > > browser dialog? I want to add selected files to a scrolllist. > > > > Like this: > > > > def browseFile(self): > > > > file = askopenfilename(filetypes = [("TDF Files", "*.TDF"), > > ("All Files", "*.*")],multiple=1) > > > > ?..... > > > > Thanks! > > why don't you add the result "file" to the list ? From bj_666 at gmx.net Fri Dec 29 11:15:15 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Fri, 29 Dec 2006 17:15:15 +0100 Subject: Can I beat perl at grep-like processing speed? References: Message-ID: In , Tim Smith wrote: > also, if you replace the regex with a test like lambda x: > x.lower().find("destroy") != -1, you will get really close to the speed > of perl's Testing for ``'destroy' in x.lower()`` should even be a little bit faster. Ciao, Marc 'BlackJack' Rintsch From binary.chen at gmail.com Tue Dec 5 02:19:35 2006 From: binary.chen at gmail.com (Bin Chen) Date: 4 Dec 2006 23:19:35 -0800 Subject: how to invoke the shell command and then get the result in python Message-ID: <1165303175.523129.154400@j72g2000cwa.googlegroups.com> Hi, I want to do following: get a user input regex, then pass this as a parameter to grep, and then get the result from grep. Any code snip to implement the similar function? I am a python newbie. Thanks a lot. Bin From reverseyorkage at david.com Fri Dec 15 23:27:54 2006 From: reverseyorkage at david.com (dyork) Date: Sat, 16 Dec 2006 04:27:54 GMT Subject: Roundtrip SQL data especially datetime References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> Message-ID: "John Machin" wrote in message news:1166211949.065578.292600 at f1g2000cwa.googlegroups.com... > I suppose it all depends on your definition of obvious :-) I was looking for a constructor that was the complement of str(). Most/many languages would provide that. Sometimes it's called parse(). > The constructor is datetime.datetime(year, ....., second) so the > following (which works all the way back to Python 2.3) seems not too > obscure to me: But unobvious in a different way :). Thanks, I'll use that. > If you have, as you should, Python 2.5, you can use this: I would like to do that, but the tools I need are not released in 2.5 yet. RSN! > How do you push a str or float object back into an SQL column of > appropriate type? What's the difference? Your DB API should handle this > quite transparently. Try it and see what happens. Most values tend to work, but only because the SQL string representation happens to be the same as the Python representation. That may not apply to some float values, bool, perhaps others. I had hoped the tools would have solved those problems so I don't have to. In typed languages (Java, C#) those things tend to just work. DY From Leo.Kislov at gmail.com Fri Dec 15 04:38:01 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 15 Dec 2006 01:38:01 -0800 Subject: connect from windows to linux using ssh References: <1166174294.248266.68040@79g2000cws.googlegroups.com> Message-ID: <1166175481.298518.93140@t46g2000cwa.googlegroups.com> puttaramakrishna at gmail.com wrote: > Hi Folks, > > How to connect from windows to linux using ssh without username/passwd. > > With this scenario, i need to write a program on python. Use ssh library http://cheeseshop.python.org/pypi/paramiko -- Leo From moogyd at yahoo.co.uk Sun Dec 17 01:50:46 2006 From: moogyd at yahoo.co.uk (moogyd at yahoo.co.uk) Date: 16 Dec 2006 22:50:46 -0800 Subject: OT : Bug/Issue tracking systems Message-ID: <1166338246.113948.320240@l12g2000cwl.googlegroups.com> Hi, (Off-topic) I am looking to put an open-source bug/issue tracking system in place for our current project (eventually expanded for all projects), and would appreciate any experiences/comments/suggestions. Note the project is encompasses embedded hardware (ASIC plus firmware) plus application software. The easiest method is using a spreadsheet, but this is not very expandable. The requirements I have come up with - Free ;-) - Easy to setup and maintain (I want this to be an engieering tool, not an IT project) - A non linux expert should be able to download and install (rpms OK, deep understanding of makefiles and linux kernel not OK) - Ideally via text files, a bit of perl/tcl/python OK. I'd rather avoid SQL - Prove the system and then hand-off to IT for maintenance - Easy use - Browser UI - Mail ? - Linux - Flexible reporting/search - User/admin accounts - Initially internal network access only, eventually external (customer, partner) access - Cover HDL, H/W, F/W, Documentation, Change requests. Both ASIC and FPGA. - Eventually production issues (Yeild, Test programs?) - Maybe allow project deadlines included. - We use CVS, so any loose coupling useful - We have per project repositories, plus and repository containing common IP's (i.e a project will always use 2) - Medium size projects (upto 15-20 people) - Possible migration to other system in future (which I guess means a well supported database) Googling provided with lots of names - Bugzilla (seems to be in widest use for S/W projects) - GNATS (I recall using this in a previous job) - IssueTrackerSystem (ZOPE, Python) - Trac (Python) - Plus lots of others Any suggestions, comments, recommendations or pointers to papers/tutorals greatly appreciated. Steven From jaywgraves at gmail.com Wed Dec 13 17:07:41 2006 From: jaywgraves at gmail.com (jay graves) Date: 13 Dec 2006 14:07:41 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1166046193.734274.124160@73g2000cwn.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> <1166046193.734274.124160@73g2000cwn.googlegroups.com> Message-ID: <1166047661.729792.208130@73g2000cwn.googlegroups.com> BartlebyScrivener wrote: > Yup. Did that before. That's what I mean. The d:\\python is there and > it doesn't come from the PythonPath in my windows registry. Maybe it > scans for any directory with python in the name? Do you have any *.pth files in the C:\Python24 directory? ... jay From pavlovevidence at gmail.com Fri Dec 22 23:09:33 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 22 Dec 2006 20:09:33 -0800 Subject: One module per class, bad idea? In-Reply-To: References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> <458c489c$1@nntp.zianet.com> <1166823140.827296.92960@h40g2000cwb.googlegroups.com> <1166829929.511423.110970@h40g2000cwb.googlegroups.com> <1166839110.281352.138630@79g2000cws.googlegroups.com> Message-ID: <1166846973.499754.123160@a3g2000cwd.googlegroups.com> Gabriel Genellina wrote: > At Friday 22/12/2006 22:58, Carl Banks wrote: > > > > Usually no other files need to change. Ex: you have BigOldModule > > > including ClassA, ClassB and FunctionC. Move each one onto its own > > > module, perhaps including a subset of the original imports of BigOldModule. > > > Shrink BigOldModule to just: > > > > > > from ClassA import ClassA > > > from ClassB import ClassB > > > from functionC import functionC > > > > > > and maybe a few other things, so all imports from the outside remain > > > the same. That's all - most of the time. > > > >I wouldn't recommend this unless it's important not to change the > >external usage. If you're doing it just to save work in refactoring, > >it's a partial solution hack that'll lead to more confusion and delay a > >real solution even more. > > In some cases you may consider the fact that ClassA is contained in > its own module, just an implementation detail, and not part of the > package public interfase. Yes, I would say that falls under the "important not to change the external usage" exception I gave. Carl Banks From mail at microcorp.co.za Thu Dec 21 01:04:34 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 21 Dec 2006 08:04:34 +0200 Subject: Fall of Roman Empire References: <20061220054657.7CEEA1E4006@bag.python.org> <1166595864.797404.260570@n67g2000cwd.googlegroups.com><873b7b6one.fsf@benfinney.id.au> <45892D76.2050002@gmx.net> Message-ID: <01f601c724cb$90875de0$03000080@hendrik> "Thomas Ploch" wrote: > Ben Finney schrieb: > > "John Machin" writes: > > > >> Ben Finney wrote: > >> > >>> \ "...one of the main causes of the fall of the Roman Empire was | > >>> `\ that, lacking zero, they had no way to indicate successful | > >>> _o__) termination of their C programs." -- Robert Firth | > >> An amusing .sig, but it doesn't address the root cause: As they had no > >> way of testing for the end of a string, in many cases successful > >> termination of their C programs would have been unlikely. > > > > Yet historically proven: the 'imperium' process they were running > > terminated many centuries ago. > > > > Or did it fork and exec a different process? > > > > And what about the C-Programs running in the middle of the sun or earth > making them spinning around or having nuclear reactions controlled. I > hope they won't terminate in the near future with exit status != 0 naaah - you don't have to worry - for real control He uses assembler. with jump statements. so the loops are closed. Unfortunately its not open source. Yet. - Hendrik From sjmachin at lexicon.net Sun Dec 3 18:36:41 2006 From: sjmachin at lexicon.net (John Machin) Date: Mon, 04 Dec 2006 10:36:41 +1100 Subject: Python library for reading ODF Spreadsheets In-Reply-To: References: Message-ID: <45735F89.7070507@lexicon.net> On 4/12/2006 10:18 AM, Jonathan Hunt wrote: > Hi all, > > I have had a look on google/freshmeat etc. so please forgive me if I've missed > an obvious answer. > > Can someone point me to a simple library to read/write ODF spreadsheets (i.e. > OpenOffice Calc 2). I know I can interface with OOo but this is running on a > server where I would rather avoid a full-on library. > > Something like > http://sourceforge.net/projects/pyexcelerator/ > but for reading ODF. > > I have found write only solutions - but no read library except for the full > Monte OOo/UNO which I want to avoid. > > Please, please help. Or the pragmatist in me will be forced to use XLS to get > this job done. Thanks in advance for any help. There is no such library as you describe. > > Jonny > > (I'm not on the list. Please CC me answers). Such a request is usually considered to be impertinent bludging and is likely to get you *no* answers. Consider subscribing to the list and reading it. Alternatively you could use a newsreader pointed at news:comp.lang.python or a browser pointed at http://groups.google.com/group/comp.lang.python. HTH, John From mhammond at skippinet.com.au Thu Dec 21 22:28:13 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 22 Dec 2006 14:28:13 +1100 Subject: [python-win32] Displaying contents of a file using PyWin In-Reply-To: <7.0.1.0.0.20061221224139.03e71a50@yahoo.com.ar> Message-ID: <024101c72579$371bd570$160a0a0a@enfoldsystems.local> Hi Gabriel, > [Forwarded from python-list at ...] > > At Thursday 21/12/2006 13:51, MiguelS wrote: > > >import win32ui > >from pywin.mfc import docview > > > >t = docview.DocTemplate() > >t.OpenDocumentFile("d:/temp/music.log", True) > > > >This caused windows to close PythonWin. > > This appears to be a problem with pywin32. > Using release 209 for Python 2.4 I get an Access Violation. It was attempting to set a Python error without the GIL held. I've fixed that - it now results in: win32ui: PyCDocument::OnOpenDocument handler does not exist. >>> Using: >>> t.OpenDocumentFile(None) Opens a document - I'm afraid I can't recall the MFC semantics here at the moment. > Also I've noticed that this idiom: > > try: > win32ui.GetApp().RemoveDocTemplate(template) > except NameError: > # haven't run this before - that's ok > pass > > doesn't work anymore because RemoveDocTemplate raises a different > exception now. I can't recall any change I made that would account for that. I'm assuming that the NameError comes from 'template' which is yet to be assigned - but in that case RemoveDocTemplate should not be called as the NameError happens before. I don't recall (and grep doesn't show) that pythonwin ever raises this exception. Mark From python at hope.cz Mon Dec 4 02:48:47 2006 From: python at hope.cz (Lad) Date: 3 Dec 2006 23:48:47 -0800 Subject: Video stream server In-Reply-To: References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> Message-ID: <1165218527.632366.290350@j44g2000cwa.googlegroups.com> Fredrik, Thank you for your reply. If I use the YOUTUBE.com server , I would have to connect to THEIR computers whenever a user will come to MY website to play a video stream on MY website. Is it so? Regards, L. Lundh wrote: > Lad wrote: > > > Does anybody know about a video stream server that > > serves up HTML pages with links to video files, and then serving out > > those video files. > > http://www.youtube.com/ seems to match your specification pretty well. > > From pyenos at pyenos.org Thu Dec 21 03:16:37 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 19:16:37 +1100 Subject: list1.append(list2) returns None References: <87mz5hexf7.fsf@pyenos.pyenos.org> <1166672931.481388.121730@f1g2000cwa.googlegroups.com> Message-ID: <87irg5ek9m.fsf@pyenos.pyenos.org> i rewrote the code following the advices from subdir of the parent thread: # well, table is composed of a list of columns. # so let's stick them together def enlargetable(table,col): table.append(col) # the code won't return sorted lists :-o return_the_fucking_table_bitch=table # assign it to a new variable to return it return return_the_fucking_table_bitch # :-| def removecolfromtable(table,col): return table.remove(col) print enlargetable([[1],[2],[3]],[4]) # and this code works. From leonhard.vogt at gmx.ch Sat Dec 9 06:46:31 2006 From: leonhard.vogt at gmx.ch (Leonhard Vogt) Date: Sat, 09 Dec 2006 12:46:31 +0100 Subject: Logging output from python In-Reply-To: References: <1165543315.696699.291910@j44g2000cwa.googlegroups.com> Message-ID: <457aa20a$1_1@news.bluewin.ch> Cameron Walsh schrieb: > > If it's on linux you can just redirect the screen output to a file: > > python initialfile.py 1>stdout.txt 2>stderr.txt > As for windows, I'll test it now... > > It turns out you can at least redirect the output to a file, I'm not > sure what it does with standard error or even if it exists or not. > > python initialfile.py > output.txt > > should work. >cmd Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. >type output.py import sys print 'This is print.' sys.stdout.write('This is stdout.write()\n') sys.stderr.write('This is stderr.write()\n') >python output.py 1>stdout.txt 2>stderr.txt >type stdout.txt This is print. This is stdout.write() >type stderr.txt This is stderr.write() Seems on XP it works too. Leonhard From ironfroggy at gmail.com Wed Dec 6 13:53:11 2006 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 6 Dec 2006 13:53:11 -0500 Subject: how to get all the "variables" of a string formating? In-Reply-To: References: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> Message-ID: <76fd5acf0612061053kca9f12fqda462e1ac497320f@mail.gmail.com> On 6 Dec 2006 18:33:26 GMT, Duncan Booth wrote: > "Calvin Spealman" wrote: > > > I am not aware of anything in the stdlib to do this easily, but its > > pretty easy to get them. See this example: > > > > class format_collector(object): > > def __init__(self): > > self.names = [] > > def __getitem__(self, name): > > self.names.append(name) > > return '' > > > > collector = format_collector() > > "%(foo)s %(bar)s" % collector > > assert collector.names == ['foo', 'bar'] > > > > Of course, wrapping this functionality into a simple function is > > straightforward and will look better. > > You should return a value like 0 instead of ''. > > >>> collector = format_collector() > >>> "%(foo)s %(bar)d" % collector > > Traceback (most recent call last): > File "", line 1, in > "%(foo)s %(bar)d" % collector > TypeError: int argument required > > -- > http://mail.python.org/mailman/listinfo/python-list > Good thinking with returning 0 and using a set. Maybe something added to the stdlib would be welcome instead of anyone needing it writing this little class? -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ From rpdooling at gmail.com Wed Dec 20 08:56:55 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 20 Dec 2006 05:56:55 -0800 Subject: python poetry? In-Reply-To: References: <1166524579.271548.32560@a3g2000cwd.googlegroups.com> Message-ID: <1166623015.452764.215530@f1g2000cwa.googlegroups.com> Michael Spencer wrote: > I wrote the following in response to Steve Holden's limerick challenge a > couple of years ago: Thanks! I found some of these searching the clp google group. rd From duncan.booth at invalid.invalid Fri Dec 8 03:30:34 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Dec 2006 08:30:34 GMT Subject: Need Help Parsing From File References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> <1165517086.976152.216270@16g2000cwy.googlegroups.com> Message-ID: Gabriel Genellina wrote: > For the Borland C++ 3.1 help (about 1991): > If "t" or "b" is not given in the string, the mode is governed by > _fmode. > If _fmode is set to O_BINARY, files are opened in binary mode. > If _fmode is set to O_TEXT, they are opened in text mode. > MSC used to have a similar flag (perhaps using the same name). I assume you are using 'used to have' in the sense of 'still have, although it is now deprecated in favour of the functions _get_fmode and _set_fmode'. John Machin wrote: > Indeed, and their docs say that the default for _fmode is text mode. Quite apart from the scope for the program to change the value at runtime, the default may also be changed to binary mode by linking the program with binmode.obj. From vasudevram at gmail.com Mon Dec 25 13:03:17 2006 From: vasudevram at gmail.com (vasudevram) Date: 25 Dec 2006 10:03:17 -0800 Subject: Elliptic Curve Library In-Reply-To: References: <1166886752.656666.287470@80g2000cwy.googlegroups.com> Message-ID: <1167069797.318347.61930@i12g2000cwa.googlegroups.com> Jaap Spies wrote: > Mike Tammerman wrote: > > > I need an elliptic curve library that can be used by python. I googled > > but couldn't find a one. I'll appreciate, if you could show me. > > > > You could look at http://sage.scipy.org/sage/ > http://sage.scipy.org/sage/features.html > > Jaap Sorry, don't know about those areas. Hope the other reply is of help. Vasudev www.dancingbison.com From shejo284 at gmail.com Tue Dec 19 11:56:38 2006 From: shejo284 at gmail.com (Sheldon) Date: 19 Dec 2006 08:56:38 -0800 Subject: Core dump revisited In-Reply-To: References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> <1166474110.001428.137260@80g2000cwy.googlegroups.com> <1166476940.590579.133460@73g2000cwn.googlegroups.com> <1166542176.142415.305720@48g2000cwx.googlegroups.com> Message-ID: <1166547398.787589.177590@f1g2000cwa.googlegroups.com> Duncan Booth skrev: > "Sheldon" wrote: > > > I am new to this and copied this code from a colleague. So, it > > corrupts the pointer. How do I do this properly? > > > Here is at least part of your problem: > > msgop = PyList_GetItem(work.msgobj, i); > work.msg_scenes[i] = PyString_AsString(msgop); > ppsop = PyList_GetItem(work.ppsobj, i); > work.pps_scenes[i] = PyString_AsString(ppsop); > ... > free(work.pps_scenes[i]); > free(work.msg_scenes[i]); > > You initialised msg_scenes and pps_scenes with a malloc'ed block but you > then just overwrote the pointer with the result of PyString_AsString. You > don't own the memory for the string returned from PyString_AsString, so > freeing it will cause a corruption. You should copy the string data into > the malloc'ed block (with appropriate length checks). Do you mean with: PyString_FromStringAndSize() and PyString_Size(PyObject *string) /S From michael.pearmain at tangozebra.com Tue Dec 5 06:12:13 2006 From: michael.pearmain at tangozebra.com (Mike P) Date: 5 Dec 2006 03:12:13 -0800 Subject: win32 com problem In-Reply-To: <1165316825.234187.322900@73g2000cwn.googlegroups.com> References: <1165316228.944095.116310@79g2000cws.googlegroups.com> <1165316825.234187.322900@73g2000cwn.googlegroups.com> Message-ID: <1165317133.730386.193290@l12g2000cwl.googlegroups.com> Thanks for the quick reply, the code i am running is the following import win32com.client xl = win32com.client.Dispatch("Excel.Application") ppt = win32com.client.Dispatch("PowerPoint.Application") ppt.Visible = 1 #open MS Powerpoint xl.Visible = 1 #open MS Excel xl.Workbooks.Open('%s/working_output.xls' % (working_dir)) xl.Workbooks.Open('Z:\\projects\\surveys\\SPSS - Generic files\\CTP.xla') ppt.Presentations.Open('Z:\\projects\\surveys\\SPSS - Generic files\\Basic Template.ppt') xl.Application.Workbooks("working_output").Activate xl.Application.Run("CTP.xla!sheet1.CTP") I'm running via SPSS V15 which has a python plugin, i was previousky running in V14 using the exact same code with no problems? Thanks again Mike From blbmdsmith at comcast.net Wed Dec 13 18:18:16 2006 From: blbmdsmith at comcast.net (blbmdsmith) Date: 13 Dec 2006 15:18:16 -0800 Subject: mod_python.so is garbled mod_python.so is garbled Message-ID: <1166051896.607771.29030@16g2000cwy.googlegroups.com> Has anyone seen the following error while starting httpd: Starting httpd: httpd: Syntax error on line 54 of /usr/local/apache2/conf/httpd.conf: API module structure `python_module' in file /usr/local/apache/modules/mod_python.so is garbled - perhaps this is not an Apache module DSO I am running python2.5 with apache server 2.2.3, using mod_python-3.2.10 I ran mod_python configure ----with-apxs= /usr/local/apache/bin/apxs --with-python=/usr/bin/python I have configured httpd.conf with the follwing lines: LoadModule python_module /usr/local/apache/modules/mod_python.so AllowOverride FileInfo AddHandler mod_python .py PythonHandler mptest PythonDebug On Thanks, Bill I have posted the same message on the mod_python group. Is this a better group to post his message? From pyenos at pyenos.org Wed Dec 20 19:09:32 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 11:09:32 +1100 Subject: calling a class instance of function Message-ID: <87zm9i5cub.fsf@pyenos.pyenos.org> class pid: "pid" def add(original_pid,toadd): "add pid" original_pid.append(toadd) return original_pid def remove(something_to_remove_from,what): "remove pid" something_to_remove_from.remove(what) return something_to_remove_from def modify(source,element,changewiththis): "modify pid" source[source.index(element)]=changewiththis return source class test(pid): pid.original=[1,2,3] pid.toadd=4 pid.add(pid.original,pid.toadd) # error here says that # it expects pid instance as first arg # not a list that it got. why do i get an error? From banaouas.medialog at wanadoo.fr Sun Dec 10 20:01:22 2006 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Mon, 11 Dec 2006 02:01:22 +0100 Subject: apache & mod_python In-Reply-To: <1165785873.832130.317230@f1g2000cwa.googlegroups.com> References: <4579472d$0$5066$ba4acef3@news.orange.fr> <1165577057.325812.47140@f1g2000cwa.googlegroups.com> <1165712433.927674.323000@f1g2000cwa.googlegroups.com> <457c0eb2$0$25909$ba4acef3@news.orange.fr> <1165785873.832130.317230@f1g2000cwa.googlegroups.com> Message-ID: <457cad79$0$5077$ba4acef3@news.orange.fr> Graham Dumpleton a ?crit : > m.banaouas wrote: >> thanks for your answers >> The plateform I target is Windows XP (no body is perferct ...). >> >> Concerning multithread , is simultaneous multi http client calls can >> present any problem ? I don't think because usually http server fires a >> different process for each client call, while Threading is discussed >> within the same process, isn't it? > > The use of a separate process to handle each request only applies to > the 'prefork' MPM on UNIX systems. Being on Windows, the 'winnt' MPM is > used and concurrent requests are always handled within different > threads within the same Apache process. The referenced article should > have made that clear. Ok, obviously, i will be concerned by thread architecture under win32. >> I'm still looking for mod_python 3.2.10 to install it with apache 2.2.3 >> It seems like I must "build" it before use it. >> If there is no other mean I will do it but usually I retrieve "ready to >> use" kits. > > See: > > http://nicolas.lehuen.com/download/mod_python/ I found it too on http://apache.fastorama.com/dist/httpd/modpython/win/ I would like to warn users about a trick while testing this code (widely proposed): # # helloworld.py # from mod_python import apache # def handler(req): req.content_type = ?text/plain? req.write("Hello World!") return apache.OK ?text/plain? don't use regular string delimiters (' and "). so python interpretter is not happy at all ... From george.sakkis at gmail.com Fri Dec 15 10:46:32 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 15 Dec 2006 07:46:32 -0800 Subject: Property error References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> <1166179622.872556.312810@n67g2000cwd.googlegroups.com> <1166181267.949316.197360@16g2000cwy.googlegroups.com> Message-ID: <1166197592.226740.49900@80g2000cwy.googlegroups.com> king kikapu wrote: > Your example Dennis, work as expected. I understand the mistake i have > made. But when i try to fix the original code usihn @property now, it > gives me the same error. > So, here it is: > > class Person(object): > _age = 0 > > @property > def age(): > def fget(self): > return self._age > def fset(self, value): > self._age = value > > me = Person() > me.age = 34 > print me.age > > > I am sure it is something very obvious but my skills does not (yet) > enable me to figure this out,,, As others have already replied, the default property doesn't work this way. In your example, it is possible to write it in one line using lambda: class Person(object): age = property(fget=lambda self: self._age, fset=lambda self, value: setattr(self,'_age',value)) If any of fget,fset,fdel cannot be written as lambda or you'd rather write them as functions, you may use the recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698. HTH, George From tdelaney at avaya.com Sun Dec 10 18:23:53 2006 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Mon, 11 Dec 2006 10:23:53 +1100 Subject: dict.has_key(x) versus 'x in dict' Message-ID: <2773CAC687FD5F4689F526998C7E4E5F074453@au3010avexu1.global.avaya.com> Hendrik van Rooyen wrote: > So the weirdness for me was that you called a piece of perfectly good > working code a problem, just because it was faster after you fixed > it, even though you had no prior knowledge of the offending line that > was doing the right thing, albeit slowly. - I would only have called > such a piece of code a problem if I had been inundated with prior > requests to fix the slow-running dog... I agree with Skip - it was a problem, and should have been fixed (then extensively tested, including performance tests to find the new limits ...). It's a "problem" IMO because it will scale badly. Chances are you'll never see it scale badly in the lab, unless you *really* try. But then some customer goes and puts it into production in an environment you hadn't considered, and suddenly you're running at 100% CPU continuously, and end up losing data, failing to provide service, etc. Tim Delaney From fredrik at pythonware.com Tue Dec 12 11:52:52 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Dec 2006 17:52:52 +0100 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1165935598.701360.101390@f1g2000cwa.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> Message-ID: BartlebyScrivener wrote: > Perhaps your way works also, but I have no PythonPath defined in system > variables on Windows XP. > > I keep my Python scripts and modules in d:\Python. I added d:\Python to > the Path variable and I can call and import the scripts and modules > from anywhere I please. Python does *not* use the Path when searching for modules; sys.path is initialized based on the contents of PYTHONPATH, the location of the Python executable (or PYTHONHOME), some heuristics, and certain registry entries. there used to be a page about this on python.org, but it seems to have disappeared; here's the SVN copy: https://svn.python.org/www/trunk/pydotorg/windows/registry.ht From noway at ask.me Wed Dec 20 15:46:22 2006 From: noway at ask.me (Giovanni Bajo) Date: Wed, 20 Dec 2006 21:46:22 +0100 Subject: [ANN] PyInstaller 1.3 released In-Reply-To: References: Message-ID: Robin Becker wrote: > I just tried this on something which we currently use py2exe+nsis to > package and it certainly seems to produce a small exe, but when run I > see a cryptic message on two message boxes > > ! msvcr71.dll > > ! could not be extracted > > the program then exits. yeah that's pretty cryptic. It's a known bug which I need to come around and fix it. Anyway, the message itself is harmless: if the program then exits, there is *another* problem. If you want to help with that, you could enable the console+debug mode and see what the traceback is. I'd be very glad to fix the problem for you. -- Giovanni Bajo From jon at ffconsultancy.com Sun Dec 10 04:08:26 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 09:08:26 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <1165740467.112594.303950@l12g2000cwl.googlegroups.com> Message-ID: <457bcf29$0$8739$ed2619ec@ptn-nntp-reader02.plus.net> Wolfram Fenske wrote: > It must have been right about a lot of things to still be alive and > kicking after all this time. No. Fortran and Lisp are just old, not better. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From juho.schultz at pp.inet.fi Sun Dec 17 11:00:46 2006 From: juho.schultz at pp.inet.fi (Juho Schultz) Date: 17 Dec 2006 08:00:46 -0800 Subject: Changing variable to integer In-Reply-To: References: <1166363925.520719.39180@80g2000cwy.googlegroups.com> Message-ID: <1166371246.910428.290480@t46g2000cwa.googlegroups.com> vertigo wrote: > > Perhaps you meant something more along the lines of this: > > > >>>> def PrintWordCountFloat(words): > > number = 0 > > for index, word in enumerate(words): > > print "%s %f" % (index, word) > > number = number + 1 > > print "Total words: %d" %(number) > >>>> PrintWordCountFloat(range(10)) > > 0 0.000000 > > 1 1.000000 > > 2 2.000000 > > 3 3.000000 > > 4 4.000000 > > 5 5.000000 > > 6 6.000000 > > 7 7.000000 > > 8 8.000000 > > 9 9.000000 > > Total words: 10 > > > > Or similar; I can't read your mind. Just know that enumerate(iterable) > > yields (index, value) for each item in iterable. > > > sorry, i was not precise. words is a dictionary. > 1. How can i show it's all variable (with key and value) ? > 2. How can i show sorted dictionary (by key) ? > 3. Is there any function which could do fast iteration on elements of > sorted dictionary ? > > Thanx I hope this helps a bit: >>> words = {"help":20, "copyright":25, "credits":35} # show dictionary >>> for w, s in words.iteritems(): print w, s ... credits 35 help 20 copyright 25 # show sorted dictionary # dicts are not ordered, so you have to sort them. >>> for w, s in sorted(words.iteritems()): print w, s ... copyright 25 credits 35 help 20 -- Juho Schultz From hg at nospam.org Mon Dec 11 12:57:47 2006 From: hg at nospam.org (hg) Date: Mon, 11 Dec 2006 11:57:47 -0600 Subject: can I download Python Imaging Library (PIL) for linux. References: <1165858918.771531.126560@j44g2000cwa.googlegroups.com> Message-ID: moishyyehuda at gmail.com wrote: > can I download Python Imaging Library (PIL) for linux. http://effbot.org/downloads/Imaging-1.1.6.tar.gz From scott.daniels at acm.org Thu Dec 28 17:08:19 2006 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 28 Dec 2006 14:08:19 -0800 Subject: Some basic newbie questions... In-Reply-To: <1167330938.386057.96870@a3g2000cwd.googlegroups.com> References: <1167324002.516960.319870@79g2000cws.googlegroups.com> <4594005c$1@nntp0.pdx.net> <1167330938.386057.96870@a3g2000cwd.googlegroups.com> Message-ID: <459435fe$1@nntp0.pdx.net> jonathan.beckett wrote: >> ... >> class Battleship(object): >> ... >> def getShellsLeft(self): >> numShells = 0 >> for aGun in self.guns: >> numShells += aGun.shells >> return numShells >> ... > > Excellent example - once upon a time I used to write very neat code > indeed, but exposure to C# had pretty much knackered that (where all > the framework object methods are capitalized). Here's an improvement: For Python 2.3: # using the "sum" primitive ... def getShellsLeft(self): return sum([aGun.shells for aGun in self.guns]) ... For Python 2.4 or later: # allows generator expressions ... def getShellsLeft(self): return sum(aGun.shells for aGun in self.guns) ... --Scott David Daniels scott.daniels at acm.org From luc at honk-honk.com Mon Dec 18 15:49:35 2006 From: luc at honk-honk.com (Luc Heinrich) Date: Mon, 18 Dec 2006 21:49:35 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> Message-ID: <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> Peter Decker wrote: > You're full of it. I routinely write GUI apps in Dabo for both Windows > and Linux users, and they look just fine on both platforms. Oh, I'm sure you do. Now go try to run one of your Dabo apps on a Mac and see how it looks/feels... :> Here's a hint directly taken from the Dabo homepage: "It also suffers from the same display limitations on some platforms (most notably OS X), but these should improve as the underlying toolkits improve." > Using sizers is the key; layouts just 'look right' no matter what the native > fonts and control sizes are. No, sizers are a tiny part of a much bigger problem. Sizers might be the key to solve parts of the "look" problem, they don't address any of the "feel" problem. But you clearly have a point here, so let me rephrase: "Crossplatform toolkits/frameworks suck. All of them. No exception. UNLESS you only target the lowest common denominator, aka Windows and its Linux followers". Now, the OP *explicitely* said that "[his] requirement is that the application needs to look as good on Windows as on the Apple Mac", so the rephrasing does not apply in this case. So here's a last try: "Crossplatform toolkits/frameworks suck. All of them. No exception. ESPECIALLY if one of your target is Mac OS". -- Luc Heinrich From evanmason at gmail.com Sat Dec 2 13:42:28 2006 From: evanmason at gmail.com (Evan) Date: 2 Dec 2006 10:42:28 -0800 Subject: global name 'self' is not defined Message-ID: <1165084948.125632.121260@79g2000cws.googlegroups.com> Hi I have a short script that makes 2 calls to methods in another script as follows: import canPlaces as canp callOne=canp.addMe(3,5) callTwo=canp.estocStn() The 2 methods in the second script are: def addMe(a,b) sumAb=a+b return sumAb def estocStn(): estoc={'lat':29.15,'lon':-15.667,'place':'ESTOC'} return estoc Why is it that the first call works fine, but the second tells me 'global name 'self' is not defined'? What I want is to have the dictionary 'estoc' available in my calling script. Thanks, Evan From m_tayseer82 at yahoo.com Mon Dec 18 10:40:01 2006 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Mon, 18 Dec 2006 07:40:01 -0800 (PST) Subject: Can a Tkinter GUI check for abort script: In-Reply-To: <00be01c722a9$482bdcc0$03000080@hendrik> Message-ID: <605346.38535.qm@web31112.mail.mud.yahoo.com> To view a button & hide the other, call .pack_forget() on the button you want to hide & pack() on the button you want to show test3.py should contains a main() function that returns the new window. if you press 'Abort script' button you should call new_window.destroy(), pack_forget() the current button & pack() the 'run script' button __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rampeters at gmail.com Wed Dec 6 21:59:45 2006 From: rampeters at gmail.com (johnny) Date: 6 Dec 2006 18:59:45 -0800 Subject: newb: What is the purpose of if __name__ == "__main__": Message-ID: <1165460385.607830.277220@n67g2000cwd.googlegroups.com> What is the purpose of if __name__ == "__main__": If you have a module, does it get called automatically? From DustanGroups at gmail.com Sun Dec 17 08:58:45 2006 From: DustanGroups at gmail.com (Dustan) Date: 17 Dec 2006 05:58:45 -0800 Subject: Changing variable to integer In-Reply-To: References: Message-ID: <1166363925.520719.39180@80g2000cwy.googlegroups.com> vertigo wrote: > Hello > > I receive such error: > File "p4.py", line 24, in PrintWordCountFloat > print "%s %f" % (word,words[word]) > TypeError: list indices must be integers > > i call PrintWordCountFloat with hash table, keys are words(string) and > values float. > This part of the code: > > def PrintWordCountFloat(words): > number = 0 > for word in words: > print "%s %f" % (word,words[word]) #line 24 > number = number + 1 > print "Total words: %d" %(number) > > My function displays whole table correctly, and after that i receive > mentioned error. > Why ? Where is the problem ? Perhaps you meant something more along the lines of this: >>> def PrintWordCountFloat(words): number = 0 for index, word in enumerate(words): print "%s %f" % (index, word) number = number + 1 print "Total words: %d" %(number) >>> PrintWordCountFloat(range(10)) 0 0.000000 1 1.000000 2 2.000000 3 3.000000 4 4.000000 5 5.000000 6 6.000000 7 7.000000 8 8.000000 9 9.000000 Total words: 10 Or similar; I can't read your mind. Just know that enumerate(iterable) yields (index, value) for each item in iterable. > Thanx From jfabiani at yolo.com Fri Dec 29 15:04:11 2006 From: jfabiani at yolo.com (johnf) Date: Fri, 29 Dec 2006 12:04:11 -0800 Subject: I want to see all the variables References: <45952426.1080800@websafe.com> Message-ID: <8yelh.90$Q4.82@newsfe02.lga> Steven D'Aprano wrote: > On Fri, 29 Dec 2006 08:20:22 -0600, Larry Bates wrote: > >> johnf wrote: >>> Hi, >>> When I use dir() I don't see the __ underscore items. Is there anything >>> that will show all the private vars and functions? >>> >>> johnf >> >> The idea of the underscore items is that they aren't to be used by >> you. > > Double leading+trailing underscore attributes are NOT private, they are > *special* but public (e.g. __dict__, __class__, __str__, etc.). If you > don't believe me, have a look at dir(int) and count the underscored > attributes listed. Then try to find __dict__, __name__, __bases__, > __base__ or __mro__ within the list. Why are they suppressed? > > But even if underscored attributes were private, the Python philosophy is > that private attributes are private by convention only -- even > name-mangled __private methods can be reached if you know how. > > >> If you wish to access private variables and functions you will >> almost certainly have to look at the source code to make sure of >> what they are and how they can be utilized. > > Not so. > >>>> class Parrot(object): > ... def _private(self): > ... """Private method, returns a magic string.""" > ... return "Don't touch!!!" > ... >>>> Parrot._private.__doc__ > "Private method, returns a magic string." > > > Ok then how do debug when I have something like "__source" and I need to know what is available for the object? John From gert.cuykens at gmail.com Tue Dec 19 16:40:36 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Tue, 19 Dec 2006 22:40:36 +0100 Subject: Http server In-Reply-To: <1166563266.178045.251540@73g2000cwn.googlegroups.com> References: <1166563266.178045.251540@73g2000cwn.googlegroups.com> Message-ID: > The cute secretary's name is "cherrypy.tools.staticdir". > Check out her resume at http://www.cherrypy.org/wiki/StaticContent I think i am in love :) From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 04:26:30 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 09 Dec 2006 20:26:30 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> Message-ID: On Sat, 09 Dec 2006 02:29:56 -0500, Ken Tilton wrote: > > > David Lees wrote: > Those raving about > Lisp are quite accomplished at all those other languages, and know about > what they are talking. Such a sweeping generalization. Every person who raves about Lisp is also accomplished with other languages. Yeah, right. I believe you, even if millions wouldn't. > I doubt the Pythonistas weighing in on this > thread ever got far at all with Lisp, so... should they really be > offering comparative analysis? I hit my hand with a hammer once. I didn't keep going until I was an expert in hitting-own-hand-with-hammer before deciding that hitting my hand with a hammer was not for me. Did I do the wrong thing? Should I have kept going until I was an expect at it? (Of course, writing Lisp isn't precisely like hitting one's hand with a hammer. With the hammer, the endorphins kick in eventually, and it can become quite pleasant...) >> Personally, I never like Lisp syntax; >> Clearly some people, some fanatic judging by this thread :) think easily >> in prefix. I am not one of them. > > Yeah, you are, you just did not use it heads down for a month. The sheer arrogance of this claim is astounding. Actually, this is comp.lang.lisp. It isn't astounding at all. I don't know, maybe lisp coders actually are more intelligent than ordinary mortals, but it has been my experience that they have absolutely no grasp whatsoever of the way most (many? some?) people think. And I'm not talking about can't-walk-and-think-at-the-same-time people either, I'm talking about bright, intelligent people who, nevertheless, don't agree with lisp coders. > The way > to tell if you spent enough time on Lisp is to look at Lisp code. If you > see any parentheses, you have not spent enough time. They disappear in a > month. If the parentheses are that meaningless, why do you need them? > The typical Pythonista values clean code but trembles in the face of > macros, which exist to hide boilerplate. Funny, when I write code, I try to remove boilerplate, not hide it. > That means the only thing > showing in any given block of code is exactly the interesting variable > and function names. Talk about readability. Yes. And your point is? >> Computer languages are tools and >> everyone should pick the ones that they are most comfortable and >> productive with. > > No, languages are not interchangeable. Perhaps you should consider what the term "Turing complete" implies. > Python is a fine language, but > Lisp is much more expressive/powerful. Maybe so. A bulldozer is a lot more powerful than a tack-hammer, but if somebody suggested using a bulldozer to lay carpet, I'd politely show them to the door. Sometimes more power isn't better. -- Steven. From franz.steinhaeusler at gmx.at Thu Dec 21 07:03:25 2006 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Thu, 21 Dec 2006 13:03:25 +0100 Subject: Stani's Python Editor - questions References: <7llko29d3nfg1bmm010js14r4av3ohm2uf@4ax.com> Message-ID: On Thu, 21 Dec 2006 11:58:48 +0100, Laszlo Nagy wrote: > >>> 1. How can I navigate between opened files? Usually I open 10 or more >>> files at the same time. There is no way to quickly scroll the tabs and >>> select the one that I want. Tabs simply run out of my screen. >>> >> >> Normally with ctrl-tab, ctrl-shift-tab, ctrl-f6 ctrl-shift-f6 (at least >> on windows) >> >This does not work for me. I'm using these: > >OS: FreeBSD 6.1-RELEASE >Python: 2.4.3 >wxPython: 2.6.3.3 >SPE: 0.8.2a I also saw big problems with DrPython on wxPython: 2.6.3.3 and Ubuntu. > >Maybe I should use 0.8.0, but this would be difficult. My SPE was >installed using the "ports" system of my OS and I do not want to screw >it up. >>> 2. I tried to use the "Browser" for navigation but it tells me "file is >>> already open" and it won't switch to the file. Annoying. >>> >> >> What version do you have? on 0.8.0b on Windows, it jumps to the tab, >> if the file is already open. >> >Does not work for me! I'm getting messages like this: > >python:3255): Gtk-CRITICAL **: gtk_container_remove: assertion >`GTK_IS_TOOLBARcontainer) || widget->parent == GTK_WIDGETcontainer)' failed >python:3255): Gtk-CRITICAL **: gtk_container_remove: assertion >`GTK_IS_TOOLBARcontainer) || widget->parent == GTK_WIDGETcontainer)' failed Same similar error messages with DrPy. I would try to update to a higher wxPython version and/or reporting this to the wxPython user mailing list. > >I'm not sure what it means, but maybe the problem is not in SPE or >DrPython - it is with wxWidgets or GTK ? I suspect so. >> In DrPython you have a plugin Sessions or SessionsLight for that. >> >Okay, I know that DrPython has lots of plugins. I tried to install some >of them but the important ones did not work and I gave up. >>> But it takes two minutes to >>> start up SPE, because I have to press the "OK" button on the ISO8859-1 >>> message for each file that is re-opened. >>> >This must be a problem with wxHtmlWindow because I get the same message >when I start the wxPython demo. I'm upgrading wxPython right now, but >I'm not sure if it will help. SPE requires 2.6.1 and I already have a >newer version. (DrPython does not use wxHtmlWindow, this is why it does >not throw error messages.) I would comment out the wxPython versions check in spe for trying out. >> In DrPython, there is also a Code Completions plugin. >> It is not perfect, but still useful. >> >I tried to install it on FreeBSD but it did not work. I tried it on >Windows and turned out that code completion in DrPython it is much worse >than in SPE. Yes, I know! :( This is also a future task. >I'm missing code folding as well. DrPython is better for me >right now, because it works. :-) Code folding should work in DrPython. Preferences => File types and click folding check box, then the folding menu in View menu should work. It is on "our" todo list for Drpython. I plan on January or February to make a thorough test on Linux. BTW: For that I'm (we're) looking for tester and developer for all that things. >But none of them are practical nor easy >to use. SPE would be better if it worked. I wanted to buy the Wing IDE, >but their support team said it is not available for FreeBSD. They allow >me to compile it from sources but it is a mess. I would have to sign an >NDA and spend hours with compiling it, and it would still not be a >supported platform. It is just too much work. Komodo does not work on >FreeBSD at all. Also tried boaconstructor, but it was very unstable. If >I would like to have a good IDE for Python that knows a lot (code >completion, code folding, class browser, integrated debugger, call tips, >subversion integration etc.) then what choices I have? Did you try already Eric3 (with PyQt). Looks very nice and stable and has a lot of features. > >> I don't want to persuade to use this or that, >> but a closer look to the plugins will reveal >> the "hidden" features of DrPython, and plugins >> prevent DrPython to become to bloated. >> > >I'm sorry, I do not want to be offensive. No, no problem at all! :) >DrPython is good, but it is >not a complete IDE. I see, it isn't intended to be that also. >I would happily pay for a good IDE but I cannot find >one (not for FreeBSD). Maybe the problem is with my mind and I should >replace my OS immediately. :-) Good Luck for finding your preferred editor and IDE. > >Best, > > Laszlo Cheers, From david at cypherspace.info Sat Dec 30 12:28:31 2006 From: david at cypherspace.info (cypher543) Date: 30 Dec 2006 09:28:31 -0800 Subject: Managing a queue of subprocesses? In-Reply-To: <401cp296ljt2ch1kl94l1l4gvdjf1m84kh@4ax.com> References: <1167442004.174070.71490@k21g2000cwa.googlegroups.com> <401cp296ljt2ch1kl94l1l4gvdjf1m84kh@4ax.com> Message-ID: <1167499710.954221.176710@h40g2000cwb.googlegroups.com> That was a very good answer, and it sure sounds like it would work. However, I failed at implementing it. :( My updated runQueue() function is: def runQueue(self): self.buildProcess = None count = 1 # current position in the queue while True: if self.buildProcess is None: self.execute(self.cmdQueue[count][2], self.cmdQueue[count][0], self.cmdQueue[count][1]) count = count + 1 else: # I'm not really sure what to put here I pretty sure I did all of that wrong. ;) Also, how exactly would I redirect stderr to another place? On Dec 30, 12:22 am, Tom Plunket wrote: > cypher543 wrote: > > self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)Instead of calling it self.buildPID, you might just call it > self.buildProcess or something. It's actually a Popen object that gets > returned. > > So yes you can do what you want: > > __init__ self.buildProcess to None. Then, in execute(), if > (self.buildProcess is None) or (self.buildProcess.poll() is not None) > start the next process. > > You've got to wait for one process to end before starting the next one, > it's really that easy. So, don't just go ahead and fire them all > instantly. Possibly what you want to do instead is have runQueue() do > the check somehow that there's no active process running. > > What I would do, have runQueue() check to see if self.buildProcess is > None. If it is None, fire the next process in the queue. If it isn't > None, then check to see if it's ended. If it has ended, then set > self.buildProcess to None. Next UI update the next step in the queue > gets done. Mind that you'll have to modify the queue as you go, e.g. > self.queue = self.queue[1:]. > > Finally, consider piping stderr separately, and direct its output to a > different window in your GUI. You could even make that window pop open > on demand, if errors occur. > > good luck, > -tom! > > -- From fredrik at pythonware.com Tue Dec 19 04:05:45 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 10:05:45 +0100 Subject: urllib.unquote and unicode In-Reply-To: <1166497058.109088.53120@80g2000cwy.googlegroups.com> References: <1166497058.109088.53120@80g2000cwy.googlegroups.com> Message-ID: George Sakkis wrote: > The following snippet results in different outcome for (at least) the > last three major releases: > >>>> import urllib >>>> urllib.unquote(u'%94') > > # Python 2.3.4 > u'%94' > > # Python 2.4.2 > UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0: > ordinal not in range(128) > > # Python 2.5 > u'\x94' > > Is the current version the "right" one or is this function supposed to > change every other week ? why are you passing non-ASCII Unicode strings to a function designed for fixing up 8-bit strings in the first place? if you do proper encoding before you quote things, it'll work the same way in all Python releases. From mohan.us2010 at gmail.com Fri Dec 15 04:46:44 2006 From: mohan.us2010 at gmail.com (mohan) Date: 15 Dec 2006 01:46:44 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> <1165935598.701360.101390@f1g2000cwa.googlegroups.com> <1166015447.721253.9680@80g2000cwy.googlegroups.com> <1166046193.734274.124160@73g2000cwn.googlegroups.com> Message-ID: <1166176004.011535.157230@f1g2000cwa.googlegroups.com> BartlebyScrivener wrote: > Gabriel Genellina wrote: > > > > import sys > > print sys.path > > and see what's there. > > Yup. Did that before. That's what I mean. The d:\\python is there and > it doesn't come from the PythonPath in my windows registry. Maybe it > scans for any directory with python in the name? > > ['', 'C:\\WINDOWS\\system32\\python24.zip', 'd:\\python', > 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', > 'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', > 'C:\\Python24\\Lib\\site-packages\\pythonwin', 'C:\\Python24', > 'C:\\Python24\\lib\\site-packages', > 'C:\\Python24\\lib\\site-packages\\win32', > 'C:\\Python24\\lib\\site-packages\\win32\\lib', > 'C:\\Python24\\lib\\site-packages\\wx-2.7.1-msw-ansi'] > > rd Hi rd, To revert back to my question, I wanted to add a new path to my PythonWin IDE to access modules which are in folders other than normal python paths. Here, I need to put my modules in different folders since it is a request of the user. I tried to create a new PYTHONPATH in the environmental variables section, which did not work . So, is there any way where I can temporarily append the new path/s, where the PythonWin interpreter would look during run time and discard after the interpreter is closed. For example, my main program "ATS.py" will be put in the folder D:\\dSPACE\ATS\ and my modules will be put in other folders inside the folder ATS, D:\\dSPACE\ATS\ Level Regulation, D:\\dSPACE\ATS\ Curve Detection and so on. So, I would like to tell the interpreter to look in to these folders to import the modules. Is that possible??? Regards, Mohan From mike.klaas at gmail.com Wed Dec 6 17:32:37 2006 From: mike.klaas at gmail.com (Klaas) Date: 6 Dec 2006 14:32:37 -0800 Subject: len() and PEP 3000 In-Reply-To: <1165441974.734443.16760@j72g2000cwa.googlegroups.com> References: <4tnqlkF13bbqeU1@mid.individual.net> <1165441974.734443.16760@j72g2000cwa.googlegroups.com> Message-ID: <1165444357.434505.173270@16g2000cwy.googlegroups.com> Beliavsky wrote: > Thomas Guettler wrote: > > Hi, > > > > The function len() is not mentioned in the Python 3000 PEPs. > > > > I suggest that at least lists, tupples, sets, dictionaries and strings > > get a len() method. I think the len function can stay, removing it > > would break to much code. But adding the method, would bu usefull. > > > > Yes, I know, that I can call .__len__() but that is ugly. > > I agree with you -- a.__len__() is ugly compared to len(a) . I am > surprised that such common idioms as len(a) may be going away. It is a > virtue of Python that it supports OOP without forcing OOP syntax upon > the user. How can one be confident that Python code one writes now has > a future? len() is not going away. -MIke From gagsl-py at yahoo.com.ar Mon Dec 18 13:24:30 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 18 Dec 2006 15:24:30 -0300 Subject: connecting webservers through HTTP port using python In-Reply-To: <86a272920612180428p49c89c43wf19fa5e9dccb15f6@mail.gmail.co m> References: <86a272920612180428p49c89c43wf19fa5e9dccb15f6@mail.gmail.com> Message-ID: <7.0.1.0.0.20061218152406.038ac148@yahoo.com.ar> At Monday 18/12/2006 09:28, pradeep kumar wrote: >hii iam working on socket programming, >i've to connect webservers through HTTP port and send/receive data.. >so currently i'm installed apache server and trying to connect that >server using python. >so any tell me how to connect the apache server by python code. >give suggestions.. See the httplib module -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From gandalf at designaproduct.biz Wed Dec 20 09:45:01 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Wed, 20 Dec 2006 15:45:01 +0100 Subject: Stani's Python Editor - questions Message-ID: <45894C6D.4090504@designaproduct.biz> Hello, I was trying to get answers for these. SPE homepage was down. Then I found it on berlios (http://developer.berlios.de/forum/forum.php?forum_id=12695) but no one answered since 5 days. In fact nobody seems to write in anything to that forum, I presume it is dead. I have no other choice than ask it here. I apologize in advance, they may be silly questions. 1. How can I navigate between opened files? Usually I open 10 or more files at the same time. There is no way to quickly scroll the tabs and select the one that I want. Tabs simply run out of my screen. 2. I tried to use the "Browser" for navigation but it tells me "file is already open" and it won't switch to the file. Annoying. 3. I also tried to go to the file using Ctrl+Enter (when the name of the file is written under the cursor). The same problem: it tells "file is already open", and it will not switch to the (already opened) file. 4. While running a program from inside SPE, the output window display everything in HTML, including the stdout of the program. I have a program that produces a very nice output when I run it from a terminal. But it is unbelievable what it looks like when I run it from SPE. :-) Especially if you print messages like they will silently disappear from the output screen because they look like an invalid HTML tag. Frustrating. 5. There should be a an option to clear the output panel before running the program anyway. I see no way to clear it at all. 6. When I create a new file and select File/Save as, the dialog window comes up. It is so small that I cannot see the names of the shortest files and it is not resizeable. 7. Whenever I open a file or start a program inside SPE, I get a "Failed to display HTML document in ISO-8859-1 encoding" error message. 8. The "Explore" panel on the left comes up for every file that I open. I do not want it to come up by default, because I have screen resolution problems. I did not find any options/preferences to change the above things. Some of the above might be new feature requests. I recently switched from DrPython to SPE. SPE has more functions and it could be much much better than DrPython, but it has big problems. For example, I like that SPE saves the workspace automatically for me. But it takes two minutes to start up SPE, because I have to press the "OK" button on the ISO8859-1 message for each file that is re-opened. I very like the Browser window, but I cannot use it for navigation. I like the new style save file dialog, but I cannot use it because it is small. I like the code completion. (dot) :-) Thanks, Laszlo From gagsl-py at yahoo.com.ar Thu Dec 7 15:54:16 2006 From: gagsl-py at yahoo.com.ar (gagsl-py at yahoo.com.ar) Date: 7 Dec 2006 12:54:16 -0800 Subject: Embedded python adding variables linking to C++-Variables / callbacks In-Reply-To: <1165502031.078706.184080@j72g2000cwa.googlegroups.com> References: <1165488494.074166.169240@79g2000cws.googlegroups.com> <1165493047.575426.274630@j72g2000cwa.googlegroups.com> <1165502031.078706.184080@j72g2000cwa.googlegroups.com> Message-ID: <1165524856.458079.162510@73g2000cwn.googlegroups.com> On 7 dic, 11:33, "iwl" wrote: > What I found out up to now is to create a class inherited from an > fitting type > and overwrite the __setitem__ and __getitem__ method but haven't test > this > yet, something like that: > > class test(int): > __setitem(self, value)__: C-Set-Func(value) > __getitem(self)__: return C-Get-Func() > > x=test() > x= -> C-Set-Func called > y=x -> C-Get-Func called Python doesn't work that way: http://effbot.org/zone/python-objects.htm From editor at methodsandtools.com Tue Dec 5 07:18:26 2006 From: editor at methodsandtools.com (editormt) Date: 5 Dec 2006 04:18:26 -0800 Subject: Coding standards without control? Message-ID: <1165321106.614601.95530@79g2000cws.googlegroups.com> A recent poll asked if programming standards are used by development organisations... and if they are controlled. None: 20% Yes, but without control: 49% Yes, with control: 31% Participants: 369 Source: Methods & Tools (http://www.methodsandtools.com) A majority of the participating organisations have coding standards... and a majority does not control them ;o) What is the situation at your location? Does this lack of control really hurt? From python.list at tim.thechases.com Sun Dec 17 08:13:17 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 17 Dec 2006 07:13:17 -0600 Subject: How to test if two strings point to the same file or directory? In-Reply-To: <1166322669.722451.183510@80g2000cwy.googlegroups.com> References: <1166317324.791635.274550@79g2000cws.googlegroups.com> <1166319494.222385.232890@t46g2000cwa.googlegroups.com> <1166322669.722451.183510@80g2000cwy.googlegroups.com> Message-ID: <4585426D.4000008@tim.thechases.com> > The current setup will not "silently fail when run on win32". How could > it? It doesn't exist; it can't be run. Ah...didn't know which it did (or didn't do) as I don't have a win32 box at hand on which to test it. In chasing the matter further, the OP mentioned that their particular problem was related to tilde-expansion/compression which python doesn't seem to distinguish. To take this into consideration, there's some advice at http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee559c99d54d970b/b71cb7ac1b7be105 where Chris Tismer has an example function/module that uses Win32 API calls to normalize a path/filename to the short-name equiv. It looks like this could be integrated into the previous code I posted, so you'd have something like os.path.samefile = lambda f1, f2: ( LongToShort(abspath(f1)).lower() == LongToShort(abspath(f2)).lower() ) As stated, it's a bit fly-by-the-seat-of-the-pants as I don't have any boxes running Win32 here at home, but that would be the general gist of the idea. It would be handy to add it, as the semantic meaning is the same across platforms, even if the implementation details are vastly different. One of the reasons I use python is because it usually crosses platform boundaries with nary a blink. Just a few more ideas, -tkc From larsnostdal at gmail.com Fri Dec 22 12:36:06 2006 From: larsnostdal at gmail.com (=?iso-8859-1?q?Lars_Rune_N=F8stdal?=) Date: Fri, 22 Dec 2006 18:36:06 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: On Fri, 08 Dec 2006 03:07:09 -0800, Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. > > Mark Kill this frakkin thread; Lisp rules -- while Python is boring (but better than many other alternatives). E.O.F. -- Lars Rune N?stdal http://nostdal.org/ From spedrosa at gmail.com Fri Dec 8 15:06:54 2006 From: spedrosa at gmail.com (Stephen Eilert) Date: 8 Dec 2006 12:06:54 -0800 Subject: Common Python Idioms In-Reply-To: References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> Message-ID: <1165608414.402845.90520@16g2000cwy.googlegroups.com> Ben Finney escreveu: > "Stephen Eilert" writes: > > > Is there a list somewhere listing those not-so-obvious-idioms? > > They're only not-so-obvious to those who learn one version of Python > and then ignore release notes on future versions. The "k in some_dict" > was a wonderful thing to read in the release notes, and I was glad > enough that I never forgot it :-) > > Hmm, that sounds rather snarky. I guess I'm only saying that one's > duty to oneself as a programmer is to keep up with the improved idioms > as they appear in new releases of one's language of choice. That's fine. I do need to read those release notes retroactively, though. Stephen From spedrosa at gmail.com Fri Dec 8 15:23:54 2006 From: spedrosa at gmail.com (Stephen Eilert) Date: 8 Dec 2006 12:23:54 -0800 Subject: merits of Lisp vs Python In-Reply-To: <4579c4f4$0$49201$14726298@news.sunsite.dk> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4579c4f4$0$49201$14726298@news.sunsite.dk> Message-ID: <1165609434.129037.308390@f1g2000cwa.googlegroups.com> Alex Mizrahi escreveu: > > we should feed this text to the query-builder. > then we should bind ?dept to our variable departament (i'm not sure how this > is done in SPARQL, but there should be a way). > then we should iterate over results and output HTML. a python-like > pseudocode: > > query = BuildQuery(query_str) > query.bind("?dept", departament) > results = query.execute() > for each rs in results: > print "" + htmlesc(rs.get("?fname")) + "" + > htmlesc(rs.get("?lname")) + "" + rs.get("?salary") + "" I just want to add that this kind of HTML mixed with code is something that should be avoided, no matter what language is used. Stephen From JShrager at gmail.com Wed Dec 13 00:43:46 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 12 Dec 2006 21:43:46 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <4u6mffF161jbqU3@mid.individual.net> Message-ID: <1165988626.008085.199000@16g2000cwy.googlegroups.com> > greg writes: > > >> A compiler shifts a lot of decisions that an > >> interpreter would have to make at runtime to compile-time. There is > >> no reason a dynamic language can't enjoy this efficiency. > > > > I'm not saying that it's impossible to compile > > Python, only that's there's a lot more to it than > > just macro expansion. The OP was saying something > > like "If you added macros, you might get a compiler > > for free", which is clearly far from true. Speaking as the OP, let's see what the OP really said: >... compilers are GREATLY facilitated by having a > macro facility because (at first blush) all you need to do is to > macro-expand down to something you know how to turn into code. > This isn't the only, nor perhaps the best way to get a compiler, but it's > a step in that direction. Later on you can learn the other great > features offered by homogeneous syntax, like being able to write code > walkers, which help improve over the "first blush" compiler.... So, "If you added macros, you might get a compiler for free" is not a fair paraphrase of this. (Another way, BTW, that macros improve efficiency is by replacing function calls with in-line code. Another cheap improvement facilitated by macros.) From jon at ffconsultancy.com Sat Dec 16 13:58:37 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat, 16 Dec 2006 18:58:37 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> Message-ID: <45844272$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> Raffael Cavallaro wrote: > Of course it does - Thats why we try ocaml and haskell etc. It's just > that we don't see the useful features of these languages as being > sufficiently useful to compensate for their lack of the ability to > easily do syntactic abstractions over a uniform syntax. That applies to the Lispers who've tried other languages and stayed with Lisp. > There's no > question that other languages have some features that common lisp does > not (and vice versa). Lispers just can't abide being locked into a > particular paradigm because a language doesn't have the basic features > (macros and uniform syntax) necessary to provide new paradigms for > ourselves when needed or wanted. Why do you think that uniform syntax is necessary to provide new paradigms when it is equivalent to infix syntax? > For example, a common lisp with optional static typing on demand would > be strictly more expressive than common lisp. But, take say, haskell; > haskell's static typing is not optional (you can work around it, but > you have to go out of your way to do so); haskell's pure functional > semantics are not optional (again, workarounds possible to a limited > extent). In what way is Haskell's support for imperative programming limited? > This requires you to conceive your problem solution (i.e., > program) within the framework of a particular paradigm. This lock-in to > a particular paradigm, however powerful, is what makes any such > language strictly less expressive than one with syntactic abstraction > over a uniform syntax. Can you give an example of a Lisp macro that does something useful that you can't do in these other languages? -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From juanrgonzaleza at canonicalscience.com Sun Dec 10 10:25:26 2006 From: juanrgonzaleza at canonicalscience.com (Juan R.) Date: 10 Dec 2006 07:25:26 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <1165764326.194172.170390@j44g2000cwa.googlegroups.com> Ken Tilton ha escrito: > It is just a matter of critical mass. At some very low threshold Lisp > becomes "OK". I get the feeling that has already begun, but it is not > quite there yet. Sometime in the past LISP got an increased 'popularity' (i suspect because LISP natural fit into web services). However, i also noticed that since some months ago, the TIOBE index for LISP decreases and decreases and decreases... whereas Python, Ruby, and company increase. Last December index, Ruby increases ranking by 9 positions to 11th, Python 1 to 7th, whereas LISP decreases to 17th from 13th. From gbrunick at andrew.cmu.edu Thu Dec 7 08:39:26 2006 From: gbrunick at andrew.cmu.edu (Gerard Brunick) Date: Thu, 07 Dec 2006 08:39:26 -0500 Subject: problem with closures In-Reply-To: <1165425782.031642.71070@f1g2000cwa.googlegroups.com> References: <1165425782.031642.71070@f1g2000cwa.googlegroups.com> Message-ID: <4578198E.8000200@andrew.cmu.edu> I can't solve your problem, but I can at least explain why I think its hard. foo doesn't have any closed over variables. Some of its locals have to live in cells, so that pre and post can see them in their closures. >>> foo.func_code.co_cellvars ('x', 'y') Now the only way that I know of to get a local variable to be put in a cell, where you can then plug it into a func_closure, it to write a function which a contains a function with a closure. Moreover, this requires that the function signatures really match to work. Consider >>> def test(*arg, **args): ... def inner(): ... print x ... return inner ... >>> f = test(x=5) >>> f() Traceback (most recent call last): File "", line 1, in ? File "", line 3, in inner NameError: global name 'x' is not defined Since x isn't a named argument of test, the compiler just assumes that its a global. This means that your contract function is going to have to build a string and exec to make the newf so its arguments match foo exactly. Of course the compiler is really finicky about exec, when there are free variables around, and I don't claim to understand the rules. alain wrote: > Hi, > > I have a problem with closures. > I am trying to implement yet another design by contract decorator which > would look like the following: >

> def contract(f):
> 	def newf(*args, **kw):
> 		import new
> 	        precondition =  new.function(f.func_code.co_consts[1],
> 							f.func_globals,'pre',
> 							f.func_defaults,
> 							f.func_closure)
> 		precondition()
> 		result=f(*args, **kw)
> 		postcondition=new.function(f.func_code.co_consts[2],globals())
> 		postcondition(result)
> 		return result
> 	return newf
> @contract
> def foo(x,y,g=2,z=1):
> 	def pre():
> 		assert x>1 and 0 	def post(result):
> 		assert result >0
> 	print 'main'
> 	return x+y+z*g
>
> print foo(2,5,4,69)
> 
>
> The problem is that i get the following error message on line 7:
> TypeError: arg 5 (closure) must be tuple
>
> f.func_closure is indeed empty while
> f.func_code.co_consts[1].co_freevars is logically equal to ('x','y').
>
> Thanks for responding
>
> Alain
>



From toolmaster at 163.com  Thu Dec 28 20:14:34 2006
From: toolmaster at 163.com (WaterWalk)
Date: 28 Dec 2006 17:14:34 -0800
Subject: I'm having trouble understanding scope of a variable in a subclass
In-Reply-To: <87bqloej4x.fsf@pyenos.pyenos.org>
References: <87bqloej4x.fsf@pyenos.pyenos.org>
Message-ID: <1167354874.753942.181700@i12g2000cwa.googlegroups.com>


Pyenos wrote:
> Approach 1:
>
> class Class1:
>         class Class2:
>                 def __init__(self):self.variable="variable"
>
>                 class Class3:
>                         def method():print Class1().Class2().variable #problem
>
> Approach 1.1:
>
> class Class1:
>         class Class2:
>                 def __init__(self):self.variable="variable"
>
>                 class Class3:
>                         def method():print Class1.Class2.variable #problem

> Approach 2:
>
> class Class1:
>         class Class2:
>                 variable="variable"
>
>                 class Class3:
>                         def method():print Class1().Class2().variable #problem
> Approach 2.1:
>
> class Class1:
>         class Class2:
>                 variable="variable"
>
>                 class Class3:
>                         def method():print Class1.Class2.variable #problem
>
> Is there a correct solution in the above? Or, what is the solution?

Your definition of Class3.method() shall have a 'self' argument, then
the above will all be ok.



From CRhode at LacusVeris.com  Tue Dec  5 22:41:24 2006
From: CRhode at LacusVeris.com (Chuck Rhode)
Date: Tue, 5 Dec 2006 21:41:24 -0600
Subject: PythonTidy
In-Reply-To: 
References: 
	
Message-ID: <20061206034123.GD16395@loki>

rzed wrote this on Tue, Dec 05, 2006 at 08:19:28PM -0500.  My reply is
below.

> I ran PythonTidy on a wxPython sample, and found that wx.CONSTANTS 
> were being translated to wx.Constants, which won't do at all.

Find the first line in the PythonTidy code where the following global
variables are declared and change them as follows:

PERSONAL = False  # This eliminates case manipulation.

> The idea of PythonTidy is not bad, but there should be a minimal
> option that essentially reindents and nothing more. ... For example,
> I don't necessarily need a shebang or coding line for my purposes,
> but without going into the code and commenting out lines, I can't
> readily suppress them.

Yes, it's too bad that PythonTidy doesn't have an *.rc file or a *.cfg
file or an *.ini file or an *.xml file or a Registry entry or a Gnome
configuration or its own graphical front end or a gob of command-line
options, but that's just the way it is.

SHEBANG = ''  # This removes the shebang line from the output.
CODING_SPEC = ''  # This removes the coding specification from the output.

> As it stands now, I can't trust PythonTidy to do the right thing on
> unfamiliar code, and I can't readily try out various options by
> simply activating or deactivating them; if I could, it would be much
> more useful to me.

PythonTidy should be run only on code that is already familiar or that
will rapidly become so in the near future.

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 25? ? Wind SSW 20 mph ? Sky overcast. Precipitation.


From horpner at yahoo.com  Wed Dec 13 10:30:04 2006
From: horpner at yahoo.com (Neil Cerutti)
Date: Wed, 13 Dec 2006 15:30:04 GMT
Subject: Conditional iteration
References: <4580149c$0$321$e4fe514c@news.xs4all.nl>
	
Message-ID: <00Vfh.2190$eb5.20@newsreading01.news.tds.net>

On 2006-12-13, Roberto Bonvallet  wrote:
> at wrote:
>> More pythonic in view would be:
>> 
>> for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0:
>>        ... more code ...
>
> Pythonic?  Do you realize that Python hasn't even adopted
> well-known statements like 'switch' and 'do while' because they
> would be redundant?
>
> This could be more convenient to you, but certainly not
> pythonic.  Cheers,

I tried it once myself. It seemed like a feasible thing that
might work in Python. It didn't annoy me that it didn't work, but
it did seem natural to me given the syntax of comprehensions.

-- 
Neil Cerutti


From tjreedy at udel.edu  Tue Dec 12 21:17:52 2006
From: tjreedy at udel.edu (Terry Reedy)
Date: Tue, 12 Dec 2006 21:17:52 -0500
Subject: YouTube written in Python
References: 
	<1165972697.387673.274570@j72g2000cwa.googlegroups.com>
Message-ID: 


 wrote in message 
news:1165972697.387673.274570 at j72g2000cwa.googlegroups.com...
> Really?
> It's awful!

Awesome?

> Terry Reedy wrote:
>> In a thread on the PyDev list, Guido van Rossum today wrote:
>> > And I just found out (after everyone else probably :-) that YouTube is
>> > almost entirely written in Python. (And now I can rub shoulders with
>> > the developers since they're all Googlers now... :-)
>>
>> In reply, Simon Brunning noted:
>> > That'll put to bed any "Does Python scale" discussions.
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





From fsenkel at lynx.neu.edu  Mon Dec  4 08:49:26 2006
From: fsenkel at lynx.neu.edu (monkeyboy)
Date: 4 Dec 2006 05:49:26 -0800
Subject: Execution time of lines within a function
Message-ID: <1165240166.203915.115460@n67g2000cwd.googlegroups.com>

Hello,

I have a function that hotshot says is very slow. I can get the
aggregate execution time, but is there a way to get the execution time
of each line so I can find the bottleneck?

Thank you



From bignose+hates-spam at benfinney.id.au  Wed Dec 20 01:56:53 2006
From: bignose+hates-spam at benfinney.id.au (Ben Finney)
Date: Wed, 20 Dec 2006 17:56:53 +1100
Subject: Fall of Roman Empire
References: <20061220054657.7CEEA1E4006@bag.python.org>
	
	<1166595864.797404.260570@n67g2000cwd.googlegroups.com>
Message-ID: <873b7b6one.fsf@benfinney.id.au>

"John Machin"  writes:

> Ben Finney wrote:
>
> >  \      "...one of the main causes of the fall of the Roman Empire was |
> >   `\        that, lacking zero, they had no way to indicate successful |
> > _o__)               termination of their C programs."  -- Robert Firth |
>
> An amusing .sig, but it doesn't address the root cause: As they had no
> way of testing for the end of a string, in many cases successful
> termination of their C programs would have been unlikely.

Yet historically proven: the 'imperium' process they were running
terminated many centuries ago.

Or did it fork and exec a different process?

-- 
 \     "I wish there was a knob on the TV to turn up the intelligence. |
  `\      There's a knob called 'brightness' but it doesn't work."  -- |
_o__)                                              Eugene P. Gallagher |
Ben Finney



From greg at cosc.canterbury.ac.nz  Tue Dec 12 22:07:01 2006
From: greg at cosc.canterbury.ac.nz (greg)
Date: Wed, 13 Dec 2006 16:07:01 +1300
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	
	<1165867527.389209.80660@f1g2000cwa.googlegroups.com>
	
Message-ID: <4u995gF16pm7hU4@mid.individual.net>

Robert Uhl wrote:

> o Symbols
> 
> In Lisp, a symbol is essentially a hashed string;

Are you aware that strings can be interned in Python?
Furthermore, any string literal in the source that
is a syntactically valid identifier is automatically
interned, and you can intern any string explicitly
if you need. This gives you exactly the same
capabilities as symbols in Lisp.

For example, due to the automatic interning, the
string comparison in the following is just a pointer
comparison:

    fred = 'hello'
    if fred == 'hello':
       print 'Greetings'

--
Greg


From Sebastien.Boisgerault at gmail.com  Fri Dec 15 04:25:46 2006
From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=)
Date: 15 Dec 2006 01:25:46 -0800
Subject: Validate XML against a set of XSD files, with Python
References: 
	<1165962804.855630.222240@79g2000cws.googlegroups.com>
	
	<45819DA8.6050604@web.de>
Message-ID: <1166174746.404563.171750@16g2000cwy.googlegroups.com>


Stefan Behnel wrote:

> RelaxNG support in libxml2 is pretty much perfect, BTW.

The *potential* issue I mentioned before with Relax NG
validation in libxml2 does *NOT* exist.

I double-checked with Jing and my RelaxNG file was
indeed incorrect ... (the "recursive reference outside
elements" kind of mistake). Jing more detailled
error reports helped ...

Mea Maxima Culpa. Wouldn't like to spread FUD :)

Cheers

SB



From pjb at informatimago.com  Sat Dec  9 15:49:02 2006
From: pjb at informatimago.com (Pascal Bourguignon)
Date: Sat, 09 Dec 2006 21:49:02 +0100
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
Message-ID: <874ps423sx.fsf@thalassa.informatimago.com>

Kirk  Sluder  writes:

> In article <1165689545.676886.289150 at j44g2000cwa.googlegroups.com>,
>  "mystilleef"  wrote:
>
>> 1). More and better mature standard libraries (Languages don't matter,
>> libraries do).
> ....
>> On Lisp Macros:
>> 
>> I think they are overrated, and in general cause more harm than good.
>> It's the reason I find Lisp-like programs difficult to grok, maintain
>> and extend. Cos every smart ass wants to needlessly write his own mini
>> language to the point of absolute obfuscation. Naturally, I'm supposed
>> to be awed by his mischievous cleverness.
>
> I've not seen a convincing explanation as to why imported macros 
> from some library are so much more evil than imported functions. In 
> both cases one might have to dig into documentation and/or comments 
> to understand exactly what that imported snippit is doing.

And the difference with a library function is?

(defpackage "LIBRARY" (:export "THIS-IS-A-FUNCTION"))

(library:this-is-a-function ???) ; ???

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"This statement is false."            In Lisp: (defun Q () (eq nil (Q)))


From greg at cosc.canterbury.ac.nz  Sat Dec 16 02:21:50 2006
From: greg at cosc.canterbury.ac.nz (greg)
Date: Sat, 16 Dec 2006 20:21:50 +1300
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	
	
	
	
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	 
	<4ubu3nF16kv7aU1@mid.individual.net> 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
Message-ID: <4uhl7cF108ri8U2@mid.individual.net>

Andr? Thieme wrote:
>  (aif (timeConsumingCalculation)
>      (use it))

I think the answer is that you just wouldn't do
that in Python at all. Having magic variables
spring into existence in your local namespace
as a side effect of calling something is just
not Pythonic. (It is very Perlish, on the other
hand.)

The closest you might come is using the new
"with" statement like this:

   with aif(timeConsumingCalculation()) as it:
     use(it)

where the object returned by aif(x) has an
__enter__ method that raises an exception which
aborts the whole with statement if x is None,
thus avoiding executing the body. But that's
so horribly convoluted that any sane programmer
would just write it out the straightforward
way to begin with.

>  > There's a Haskell builtin called 'seq' which forces evaluation but
>  > again I'm not sure precisely how to apply it here.
> 
> So in some languages that support functional programming one needs to do
> extra work to get lazyness, while in Haskell one gets extra work if one
> doesn't want it.

Sort of, but it's more so that you can write code
that does things like I/O in what looks like a
procedural style, even though it's still purely
functional. Read about "monads" if you want to
know more -- it's truly mind-expanding (and
possibly head-exploding:-) stuff...

--
Greg


From martin at v.loewis.de  Fri Dec 29 19:46:20 2006
From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=)
Date: Sat, 30 Dec 2006 01:46:20 +0100
Subject: xml bug?
In-Reply-To: <4594130c$0$318$426a74cc@news.free.fr>
References: <4594130c$0$318$426a74cc@news.free.fr>
Message-ID: <4595B6DC.4030408@v.loewis.de>

Imbaud Pierre schrieb:
> - how do I spot the version of a given library? There is a __version__
>   attribute of the module, is that it?

Contrary to what others have said: for modules included in the standard
library (and if using these modules, rather than using PyXML), you
should use sys.version_info to identify a version.

> - How do I access to a given library buglist? Maybe this one is known,
>   about to be fixed, it would then be useless to report it.

Others have already pointed you to SF.

> - How do I report bugs, on a standard lib?

Likewise.

> - I tried to copy the lib somewhere, put it BEFORE the official lib in
>   "the path" (that is:sys.path), the stack shown by the traceback
>   still shows the original files being used. Is there a special
>   mechanism bypassing the sys.path search, for standard libs? (I may
>   be wrong on this, it seems hard to believe...)

Which lib? "minidom.py"? Well, you are likely importing
"xml.dom.minidom", not "minidom". So adding another minidom.py
to a directory in sys.path won't help.

Regards,
Martin


From jstroud at mbi.ucla.edu  Fri Dec 15 22:54:27 2006
From: jstroud at mbi.ucla.edu (James Stroud)
Date: Sat, 16 Dec 2006 03:54:27 GMT
Subject: tuple.index()
In-Reply-To: 
References: 
	
Message-ID: 

Simon Brunning wrote:
 > So, you can infer no semantic meaning from an items position in the list.
[...]
 > The fact that an item is the nth item is a tuple *means* something.

Wouldn't it be nice, then, to find out where something is in a tuple so 
that one could infer semantic meaning from its position and make 
inferences about the tuple object searched, /philosophically/ speaking? 
Or is the logic conveniently one-way?

James


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/


From bdesth.quelquechose at free.quelquepart.fr  Tue Dec 12 16:37:34 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Tue, 12 Dec 2006 22:37:34 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <457b3ca2$0$28520$3b214f66@tunews.univie.ac.at>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<45794fc2$0$11094$3b214f66@tunews.univie.ac.at>
	<1165593283.523163.71730@16g2000cwy.googlegroups.com>
	<457b3ca2$0$28520$3b214f66@tunews.univie.ac.at>
Message-ID: <457f1b8c$0$7962$426a74cc@news.free.fr>

Mathias Panzenboeck a ?crit :
> Rob Thorpe wrote:
> 
>>Mathias Panzenboeck wrote:
>>
>>>Mark Tarver wrote:
>>>
>>>>How do you compare Python to Lisp?  What specific advantages do you
>>>>think that one has over the other?
>>>>
>>>>Note I'm not a Python person and I have no axes to grind here.  This is
>>>>just a question for my general education.
>>>>
>>>>Mark
>>>>
>>>
>>>I do not know much about Lisp. What I know is:
>>>Python is a imperative, object oriented dynamic language with duck typing,
>>
>>Yes, but Python also supports the functional style to some extent.
>>
> 
> 
> I currently visit a course about functional programming at the university of technology vienna:
> python implements only a small subset of things needed to be called a functional language (list
> comprehension).

Python has functions as first-class objects (you can pass functions as 
arguments to functions, return functions from functions, and bind 
functions to identifiers), and that's the only thing you need to use a 
functional approach.


From ptmcg at austin.rr._bogus_.com  Sun Dec  3 05:27:53 2006
From: ptmcg at austin.rr._bogus_.com (Paul McGuire)
Date: Sun, 03 Dec 2006 10:27:53 GMT
Subject: wxpython worked out but can't find api docs for download.
References: 
Message-ID: 

"krishnakant Mane"  wrote in message 
news:mailman.982.1165086141.32031.python-list at python.org...
> hello all.
> finally I got the accessibility issue out from wxpython.  actually
> almost got it out, but that's another story.
> now my problem is that I can't gind a downloadable version of wxpython
> api reference for the latest version or the latest api reference at
> least.
> I found the on-line version so please don't provide the same link.
> when I opened it on line, it took about 8 minuts to get the wx package
> come up on screen with over 600 links.
> I need to have some off line reference for the wxpython api.
> I have enough documentation to get started but I don't have the
> extencive api references for events and other methods, properties and
> attributes.
> can some one point me to a .zip or .tar.gz version of the api docs for 
> wxpython?
> thanking all.
> Krishnakant.

I am just now learning wxPython, and I used epydoc to generate HTML doc for 
the classes.  To do this:
1. download and install epydoc
2. Fix bug in html.py of epydoc - line 2179 "inherit" should be "inherited"
3. Run epydoc against wx/ package directory.

You will get numerous INTERNAL ERROR: messages and "indentation error" 
messages, but you will end up with a directory of HTML reference docs for 
the Python classes.

-- Paul 




From ptmcg at austin.rr.com  Sat Dec 23 10:40:48 2006
From: ptmcg at austin.rr.com (Paul McGuire)
Date: 23 Dec 2006 07:40:48 -0800
Subject: pyparsing 1.4.5 released
In-Reply-To: <9ehrgmg8ye62$.157mjsdys1jgm.dlg@40tude.net>
References: <1166846392.920361.196990@73g2000cwn.googlegroups.com>
	<9ehrgmg8ye62$.157mjsdys1jgm.dlg@40tude.net>
Message-ID: <1166888448.017137.55660@i12g2000cwa.googlegroups.com>

On Dec 23, 9:07 am, Richard Townsend  wrote:
> On 22 Dec 2006 19:59:53 -0800, Paul McGuire wrote:
>
>
>
> > Download pyparsing 1.4.5 athttp://pyparsing.sourceforge.net.  The
> > pyparsing Wiki is athttp://pyparsing.wikispaces.comWhen I click on the sourceforge link above, I get redirected to the wiki.
>
> However,http://sourceforge.net/projects/pyparsing/
>
> seems to work.
>
> --
> Richard

Thanks, I'll update my announcement template.

-- Paul



From bdesth.quelquechose at free.quelquepart.fr  Tue Dec 12 18:21:07 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Wed, 13 Dec 2006 00:21:07 +0100
Subject: Snake references just as ok as Monty Python jokes/references
	in python community? :)
In-Reply-To: <1165607250.544331.124360@j72g2000cwa.googlegroups.com>
References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com>
Message-ID: <457f33d1$0$13615$426a74cc@news.free.fr>

seberino at spawar.navy.mil a ?crit :
> I'm semi-seriously wondering if snake jokes are valid in the Python
> community since technically, Python came from Monty Python, not
> slithery animals.
> 
> Problem is I don't know that anyone born after Elvis died gets any of
> these Monty Python jokes.
> 
> Is it kosher to make snake jokes/references even though officially they
> don't have anything to do with the name of our favorite language?
> (*Everyone* gets snake jokes! :)
> 
The answer is 42.


From stdazi at gmail.com  Tue Dec  5 08:27:43 2006
From: stdazi at gmail.com (stdazi)
Date: 5 Dec 2006 05:27:43 -0800
Subject: Why not just show the out-of-range index?
In-Reply-To: 
References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com>
	
	<97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com>
	
	<1165216880.864158.256730@80g2000cwy.googlegroups.com>
	
	<1165219968.619509.147990@73g2000cwn.googlegroups.com>
	
Message-ID: <1165325263.656851.87980@l12g2000cwl.googlegroups.com>

Usually, when I make some coding mistake (index out of range - in this
case) I just care to fix the mistake and I usually don't mind to
inspect by how much the index was overflowed. It really seems like a
feature that should be embedded in some Python debugger than a feature
in the interpreter itself.



From jackson at hotmail.com  Tue Dec 12 15:23:25 2006
From: jackson at hotmail.com (Bill Jackson)
Date: Tue, 12 Dec 2006 12:23:25 -0800
Subject: Why does wx.Window.CaptureMouse() send EVT_PAINT
In-Reply-To: 
References: 
	
Message-ID: 

Tim Roberts wrote the following on 12/09/2006 08:27 PM:
> The source code could answer that question for sure, but I doubt that it is
> CaptureMouse doing it, and I know the SetCapture API (which it eventually
> calls) does not.  Is it possible that your clicking caused some part of the
> app to become unhidden, or caused some button to change state?

Indeed. The EVT_PAINT came from self.Refresh(False).  I mistakenly 
thought that False implied that it would not refresh, but the docs 
clearly state (which I had not read) otherwise.  To reiterate, 
CaptureMouse does not send an EVT_PAINT.


From Stephane.Muller at uhp-nancy.fr  Fri Dec 15 10:22:45 2006
From: Stephane.Muller at uhp-nancy.fr (=?ISO-8859-1?Q?St=E9phane_Muller?=)
Date: Fri, 15 Dec 2006 16:22:45 +0100
Subject: aggdraw for 2.5 on WinXP?
In-Reply-To: 
References: 
Message-ID: 

rzed a ?crit :
> Has anyone generated an aggdraw installer or aggdraw.pyd for Python 
> 2.5 (WinXP)? If so, could it be made available for those of us who 
> don't have a working compiler?
> 
Hello,

You can try

http://c.python.free.fr/aggdraw-1.2a3-20060212.win32-py2.5.exe

without any express or implied warranty.

Stephane.


From nick at craig-wood.com  Mon Dec 18 10:30:05 2006
From: nick at craig-wood.com (Nick Craig-Wood)
Date: Mon, 18 Dec 2006 09:30:05 -0600
Subject: Core dump revisited
References: <1166349672.479548.4460@80g2000cwy.googlegroups.com>
Message-ID: 

Sheldon  wrote:
>  gdb msgppscomp.py core.3203

Run

  gdb python

Then type

  run msgppscomp.py

at the gdb prompt.

When it crashes, type "bt" for a back trace.  This will pinpoint
exactly where it crashes.

Hopefully that will make things clearer.  If not post the output.

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick


From sndive at gmail.com  Thu Dec 28 20:30:05 2006
From: sndive at gmail.com (sndive at gmail.com)
Date: 28 Dec 2006 17:30:05 -0800
Subject: Minor problem with configure (2.4.4)
Message-ID: <1167355805.609659.62920@73g2000cwn.googlegroups.com>

configure expands
  AC_DEFINE(_POSIX_C_SOURCE, 200112L, Define to activate features from
IEEE Stds 1003.1-2001)

to

#define _POSIX_C_SOURCE 200112L

that causes problems because _POSIX_C_SOURCE is defined by system
headers and I get hideous
warnings during compilation.

I tried to fix it by adding AC_UNDEFINE(_POSIX_C_SOURCE);
before AC_DEFINE but autoconf 2.59 won't take it:

configure.in:273: error: possibly undefined macro: AC_UNDEFINE
      If this token and others are legitimate, please use
m4_pattern_allow.
      See the Autoconf documentation.

Ideas?



From tgrav at mac.com  Tue Dec 12 09:19:00 2006
From: tgrav at mac.com (Tommy Grav)
Date: Tue, 12 Dec 2006 09:19:00 -0500
Subject: Updating variables indirectly
Message-ID: <9C6A0EC3-EFCA-4108-A96D-BF50B05E158E@mac.com>

I have a little problem that look something like this:

Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> class test: pass
...
 >>> test.a = 1
 >>> test.b = 2
 >>> for x in [test.a,test.b]:
...   x = x + 1
...
 >>> print test.a
1
 >>> print test.b
2
 >>>

However, what I am after is a way to increment the variables in the  
list,
e.q. I want test.a to be 2 and test.b to be 3.

Is there a way of doing this?

Cheers
    Tommy

tgrav at mac.com
http://homepage.mac.com/tgrav/
------------------------------------------------------------
"Any intelligent fool can make things bigger,
more complex, and more violent. It takes a
touch of genius -- and a lot of courage -- to
move in the opposite direction"
                                                  -- Albert Einstein




-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From mtammerman at gmail.com  Sat Dec 23 10:12:32 2006
From: mtammerman at gmail.com (Mike Tammerman)
Date: 23 Dec 2006 07:12:32 -0800
Subject: Elliptic Curve Library
Message-ID: <1166886752.656666.287470@80g2000cwy.googlegroups.com>

Hi,

I need an elliptic curve library that can be used by python. I googled
but couldn't find a one. I'll appreciate, if you could show me.

Mike



From justin.mailinglists at gmail.com  Mon Dec  4 04:56:33 2006
From: justin.mailinglists at gmail.com (Justin Ezequiel)
Date: 4 Dec 2006 01:56:33 -0800
Subject: Multiple FTP download using Muliti thread
References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com>
Message-ID: <1165226193.934418.36660@l12g2000cwl.googlegroups.com>

import ftplib, posixpath, threading
from TaskQueue import TaskQueue

def worker(tq):
    while True:
        host, e = tq.get()

        c = ftplib.FTP(host)
        c.connect()
        try:
            c.login()
            p = posixpath.basename(e)
            fp = open(p, 'wb')
            try: c.retrbinary('RETR %s' % e, fp.write)
            finally: fp.close()
        finally: c.close()

        tq.task_done()

if __name__ == '__main__':
    q = TaskQueue()
    host = 'ftp.microsoft.com'

    c = ftplib.FTP(host)
    c.connect()
    try:
        c.login()
        folder = '/deskapps/kids/'
        for n in c.nlst(folder):
            if n.lower().endswith('.exe'):
                q.put((host, n))
    finally: c.close()

    numworkers = 4
    for i in range(numworkers):
        t = threading.Thread(target=worker, args=(q,))
        t.setDaemon(True)
        t.start()

    q.join()
    print 'Done.'



From pc at p-cos.net  Sat Dec  9 06:00:39 2006
From: pc at p-cos.net (Pascal Costanza)
Date: Sat, 09 Dec 2006 12:00:39 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <7xk611baoa.fsf@ruckus.brouhaha.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<7xslfqar7v.fsf@ruckus.brouhaha.com>
	<1165623284.242403.295140@l12g2000cwl.googlegroups.com>
	<7xodqdj2dn.fsf@ruckus.brouhaha.com>
	<457a8251$0$49201$14726298@news.sunsite.dk>
	<7xk611baoa.fsf@ruckus.brouhaha.com>
Message-ID: <4tvjanF15r8b0U3@mid.individual.net>

Paul Rubin wrote:
> "Alex Mizrahi"  writes:
>> we can implement Scheme's call-with-current-continuation first :)
>> it's relatively easy -- just a code walker that coverts everyting into CPS.
> 
> It's not enough to convert to CPS, you have to be able to actually
> save the continuation when you switch to another one, so you can go
> back to the first one later.  

You get this for free once your program is in CPS. (This is true for any 
language, btw. It's just that it's easier to abstract away from the 
details of CPS in Lisp.)


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/


From andre.roberge at gmail.com  Thu Dec 14 13:41:34 2006
From: andre.roberge at gmail.com (Andre Roberge)
Date: Thu, 14 Dec 2006 14:41:34 -0400
Subject: [Edu-sig] automatically grading small programming assignments
In-Reply-To: <4581896B.2020504@bryant.edu>
References: <4581896B.2020504@bryant.edu>
Message-ID: <7528bcdd0612141041g78345aa7y34b0803c8284fa8d@mail.gmail.com>

Hello Brian,

I do not teach (much to my regrets) but I have been thinking about what you
describe.
See below.

On 12/14/06, Brian Blais < bblais at bryant.edu> wrote:
>
> Hello,
>
> I have a couple of classes where I teach introductory programming using
> Python.  What
> I would love to have is for the students to go through a lot of very small
> programs,
> to learn the basic programming structure.  Things like, return the maximum
> in a list,
> making lists with certain patterns, very simple string parsing,
> etc.  Unfortunately,
> it takes a lot of time to grade such things by hand, so I would like to
> automate it
> as much as possible.


I envision a number of possible solutions.  In one solution, I provide a
> function
> template with a docstring, and they have to fill it in to past a
> doctest.  Is there a
> good (and safe) way to do that online?  Something like having a student
> post code,
> and the doctest returns.  I'd love to allow them to submit until they get
> it, logging
> each attempt.


I may have a partial solution.  I (co-)wrote a program called Crunchy
(crunchy.sf.net)
which, among other features, allow automated correction of code that has to
satisfy a given docstring. As it stands, it only allows self-evaluation i.e.
there's no login required nor is the solution forwarded to someone else.
(This has been requested by others and may, eventually, be incorporated in
Crunchy.)  So, as a tool for learning, it's working; the grading component
is simply not there.  However, the code is open-source and you could adopt
it to your needs ;-)

Andr?


Or perhaps there is a better way to do this sort of thing.  How do others
> who teach
> Python handle this?
>
>
>                         thanks,
>
>
>                                 Brian Blais
>
> --
> -----------------
>
>               bblais at bryant.edu
>               http://web.bryant.edu/~bblais
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From evanmason at gmail.com  Thu Dec 14 07:35:43 2006
From: evanmason at gmail.com (Evan)
Date: 14 Dec 2006 04:35:43 -0800
Subject: remove matching pairs
References: <1166095293.445275.64850@73g2000cwn.googlegroups.com>
	
Message-ID: <1166099743.515208.16770@j72g2000cwa.googlegroups.com>

That's great, thank you, the caveats are no matter!

-Evan



From horpner at yahoo.com  Wed Dec  6 22:53:09 2006
From: horpner at yahoo.com (Neil Cerutti)
Date: Thu, 07 Dec 2006 03:53:09 GMT
Subject: Am I stupid or is 'assert' broken in Python 2.5??
References: <1165415689.347819.129680@73g2000cwn.googlegroups.com>
	
	<1165416379.784513.51620@16g2000cwy.googlegroups.com>
	
Message-ID: 

On 2006-12-07, Gabriel Genellina  wrote:
>>Yeah, it hit me seconds after I had posted my message. =0 Why
>>didn't I think of it during the 30 minutes I spent banging my
>>head against the keyboard going nuts over this 'bug' ...
>
> The same reason you can sometimes find what's wrong just by
> explaining the symptoms to another guy... Having to put things
> sorted and simple to understand by another, just makes you
> think clearly on the problem...

I read a story (was it by Brian Kernighan?) the they required
programmers to tell their problem to a stuffed animal first
before bothering another programmer who might be in the middle of
something. The stuffed animal often provided all the assistance
that was needed.

-- 
Neil Cerutti


From gagsl-py at yahoo.com.ar  Mon Dec 11 16:41:03 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Mon, 11 Dec 2006 18:41:03 -0300
Subject: possible php convert
In-Reply-To: <880dece00612100436v1051977fk966b77eecb4296cd@mail.gmail.co
 m>
References: <880dece00612100436v1051977fk966b77eecb4296cd@mail.gmail.com>
Message-ID: <7.0.1.0.0.20061211183111.03640ee0@yahoo.com.ar>

At Sunday 10/12/2006 09:36, Dotan Cohen wrote:

>Hi all, I've been contemplating the switch to python from php. I'm no
>wiz, but I can get my way around with help form the online docs. I see
>that python has much less documentation available, so expect to hear
>from me a bit in the next few weeks. :)

Uhm, have you looked at http://www.python.org/doc/ ?

>One concern that I have is that my current host does not support
>python, and for a very technical reason (money) I'd rather not switch.
>I've googled the possibility of installing python in my user's home
>directory (RHEL server), and this seems possible. Can anyone enlighten
>me as to how I could do this? Thanks in advance.

I guess you want to use Python to provide dynamic content for a web site.
There are several alternatives: Apache with mod_python, or Django, 
TurboGears, CherryPy. There was a recent discussion on this list some 
days ago about these frameworks.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From bpeng at rice.edu  Thu Dec 21 16:43:09 2006
From: bpeng at rice.edu (Bo Peng)
Date: Thu, 21 Dec 2006 16:43:09 -0500
Subject: Building python C++ extension modules using MS VC++ 2005?
Message-ID: 

Dear list,

I have been using mingw to build a python extension module. I had to 
jump through a number of hooks like the _ctype problem caused by the use 
of msvcr71.dll, but the module was mostly usable.

Things become complicated when I use more and more boost libraries and 
mingw can not work well with some of the modules. I am trying to switch 
to VC but I was suggested that I need to use the identical version of VC 
that is used to build python, which means VC7.1, 2003. However, 
microsoft seems to stop distributing this version of VC, and its website 
points me to VC expression 2005... 
 
(http://msdn2.microsoft.com/en-us/visualc/aa336490.aspx)

Can I use the 2005 version to build python extension? What is the 
official or recommended way to build python extension module under windows?

Many thank in advance.
Bo


From webraviteja at gmail.com  Sat Dec  9 17:40:07 2006
From: webraviteja at gmail.com (webraviteja at gmail.com)
Date: 9 Dec 2006 14:40:07 -0800
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165594621.136524.198600@80g2000cwy.googlegroups.com>
	
	<1165596641.245385.113090@f1g2000cwa.googlegroups.com>
	
	
Message-ID: <1165704007.887869.192290@16g2000cwy.googlegroups.com>

> The other possibility is that he is just trying to justify not doing it
> because it would be so hard without the regular syntax of Lisp,
> including parens, and with the JIT module resolution problem discussed
> earlier in his remarks. Understandable.

I am surprised that no one brought up Logix yet.
http://livelogix.net/logix/

Macros are perfectly doable in Python while still preserving the white
space syntax. And Python is sufficiently pliable with it's dynamism to
implement this without changing the compiler. And yet, no one cares
about this project and it is effectively dead.

So it is not about technical difficulties. It is not about Python
community not having the opportunity to try out the power of macros.
The Python community on the whole does not think macros as useful.
Personally, I find it strange that we, who argued so many times for
dynamic typing, the need for expressiveness and that it is OK to trust
the programmer with power ("we are all adults here" argument) while
arguing against relatively restrictive languages like Java find macros,
a chaotic and disruptive concept.



From david.stephed at googlemail.com  Thu Dec 21 10:58:42 2006
From: david.stephed at googlemail.com (MiguelS)
Date: 21 Dec 2006 07:58:42 -0800
Subject: Displaying contents of a file using PyWin
In-Reply-To: 
References: <1166706266.025197.199620@79g2000cws.googlegroups.com>
	
Message-ID: <1166716722.937893.297670@79g2000cws.googlegroups.com>


import win32ui
from pywin.mfc import docview

t = object_template()
d = t.OpenDocumentFile("d:/temp/music.log", True)

Crashes PythonWin



From jon at ffconsultancy.com  Tue Dec 19 03:29:11 2006
From: jon at ffconsultancy.com (Jon Harrop)
Date: Tue, 19 Dec 2006 08:29:11 +0000
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<45794fc2$0$11094$3b214f66@tunews.univie.ac.at>
	<1165593283.523163.71730@16g2000cwy.googlegroups.com>
	<457b3ca2$0$28520$3b214f66@tunews.univie.ac.at>
	<457f1b8c$0$7962$426a74cc@news.free.fr>
	<1166116337.983471.298630@16g2000cwy.googlegroups.com>
Message-ID: <4587a36d$0$8731$ed2619ec@ptn-nntp-reader02.plus.net>

Rob Thorpe wrote:
> Once you can do the above then you can phrase programs entirely in
> terms of composition of functions, which is what functional programming
> is about.

There are many aspects to functional programming. Some languages (like Lisp
and Python) are very impure and hardly encourage functional programming.
Other languages (like OCaml, SML, F# and Scheme) are impure but make
functional programming easy (e.g. higher-order functions, currying,
continuation passing style are all concise and statically checked). Some
languages (like Haskell) are purely functional, so everything must be
immutable.

> Getting good performance though is problematic without being able to
> evaluate parts at compile time.  This is why almost all functional
> languages provide that feature in some form.

Actually the languages that don't provide compile-time execution (OCaml, SML
and F#) are typically much faster than those that do (Lisp, Scheme, Dylan).

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet


From duncan.booth at invalid.invalid  Fri Dec 22 03:40:18 2006
From: duncan.booth at invalid.invalid (Duncan Booth)
Date: 22 Dec 2006 08:40:18 GMT
Subject: def index(self):
References: 
	<4587017b$0$22957$426a34cc@news.free.fr>
	
	<458807cc$0$19743$426a74cc@news.free.fr>
	
	<45891cb7$0$16994$426a34cc@news.free.fr>
	
	<1166659483.225301.48550@t46g2000cwa.googlegroups.com>
	
	
Message-ID: 

"Gert Cuykens"  wrote:

> On 21 Dec 2006 09:44:48 GMT, Duncan Booth
>  wrote: 
>> "George Sakkis"  wrote:
>>
>> @expr
>> def fn(...): ...
>>
>> is exactly equivalent to:
>>
>> def fn(...): ...
>> fn = (expr)(fn)
>>
> 
> ok i did my homework reading about decorators
> http://www.python.org/doc/2.4.4/whatsnew/node6.html
> 
> could it be the example above needs to be like
> 
> @expr
> def fn(...): ...
> 
> is exactly equivalent to:
> 
> def fn(...): ...
> fn = expr(fn)

no it doesn't *need* to be like that, but it *could* be written like that. 
It is true that the parentheses I used are redundant (I thought they made 
my point clearer), but removing redundant parentheses doesn't actually 
change the meaning at all.

In any case, either of these rewrites is an approximation. There is no 
Python code you can write which is exactly equivalent to, but doesn't use, 
the decorator syntax. A closer approximation would be:

If you consider:

    def fn(...): ...

is equivalent to writing:

    fn = new.function(somecodeobject, globals(), 'fn', (...default argument 
expressions...), ...and maybe a closure...)

then:

   @expr
   def fn(...): ...

is equivalent to writing:

   __anonymous_temp_1 = expr
   __anonymous_temp_2 = new.function(somecodeobject, globals(), 'fn', 
(...default argument expressions...), ...and maybe a closure...)
   fn = __anonymous_temp_1(__anonymous_temp_2)

but I don't think that is really any clearer.

It does perhaps indicate the order in which things happen more clearly: 
decorator expression is evaluated, then default arguments, then function is 
created, then decorator is called, then finally the result is assigned to a 
variable with the same name as the function.


From gagsl-py at yahoo.com.ar  Mon Dec  4 19:25:13 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Mon, 04 Dec 2006 21:25:13 -0300
Subject: Python spam?
In-Reply-To: <457476B7.20508@webcrunchers.com>
References: 
	<02a401c71513$282936a0$03000080@hendrik>
	<457476B7.20508@webcrunchers.com>
Message-ID: <7.0.1.0.0.20061204210436.04514a98@yahoo.com.ar>

At Monday 4/12/2006 16:27, John Draper wrote:

>I'm ALWAYS getting python spam.... but what worries me, is the spammers
>Know my personal home address, and I NEVER EVER fill out any forms pages
>with my personal info - I think I'm being harrassed by hackers or
>something...

- UserA creates an account on SiteA. They ask for an email address 
for validation purposes, or perhaps they use that email address as 
login name, which is fine so one doesn't have to remember another 
login. So, UserA fills in his Hotmail/Yahoo/whatever email.
- UserA provides the *same* password on the site as used on his email 
address. Which is fine so one doesn't have to remember many passwords.
- Now, SiteA has full access to UserA's address book (and inbox, 
and... but usually they're not interested on that).

Notice that SiteA actually is not "hacking" UserA Hotmail account, 
nor is a virus involved, nothing is installed on UserA's PC, there is 
no vulnerability exploited on Hotmail's code, no 
antivirus/antispyware will help, nothing. It's just UserA silly 
enough to let others know his webmail password.

So if a friend of yours has played the role of UserA above, that's 
how some spammers got your email address.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From horpner at yahoo.com  Thu Dec 14 13:30:37 2006
From: horpner at yahoo.com (Neil Cerutti)
Date: 14 Dec 2006 19:30:37 +0100
Subject: WHAT is [0] in subprocess.Popen(blah).communicate()[0]
References: <1166118046.514892.85360@16g2000cwy.googlegroups.com>
	
Message-ID: 

On 2006-12-14, Fredrik Lundh  wrote:
> johnny wrote:
>
>> Can someone tell me what is the reason "[0]" appears after
>> ".communicate()"
>> 
>> For example:
>> last_line=subprocess.Popen([r"tail","-n 1", "x.txt"],
>> stdout=subprocess.PIPE).communicate()[0]
>
> as explained in the documentation, communication() returns two
> values, as a tuple.  [0] is used to pick only the first one.
>
> see the Python tutorial for more on indexing and slicing.

I like using pattern matching in these simple cases:

  last_line, _ = subprocess.Popen([r"tail","-n 1", "x.txt"],
          stdout=subprocess.PIPE).communicate()

-- 
Neil Cerutti


From grante at visi.com  Wed Dec 27 13:39:55 2006
From: grante at visi.com (Grant Edwards)
Date: Wed, 27 Dec 2006 18:39:55 -0000
Subject: DOS, UNIX and tabs
References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com>
	<1167244483.792673.132220@42g2000cwt.googlegroups.com>
Message-ID: <12p5ffrsdo6v088@corp.supernews.com>

On 2006-12-27, Ben  wrote:
> I've found the unexpand command, which seems to do the trick. However,
> it outputs to standard output, and I haven't worked out yet how to
> capture that output to a file...

unexpand file2

-- 
Grant Edwards                   grante             Yow!  Hey, LOOK!! A pair of
                                  at               SIZE 9 CAPRI PANTS!! They
                               visi.com            probably belong to SAMMY
                                                   DAVIS, JR.!!


From fredrik at pythonware.com  Thu Dec 14 12:32:45 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Thu, 14 Dec 2006 18:32:45 +0100
Subject: tuple.index()
In-Reply-To: 
References: 	<1166104987.884566.126710@n67g2000cwd.googlegroups.com>		<1166106278.106832.278240@n67g2000cwd.googlegroups.com>						
	
Message-ID: 

Fredrik Lundh wrote:

> so which Guido should you trust more?

not to mention the "If you have a need for using count() or index() on 
tuples, you're using them the wrong way" guy:

     http://mail.python.org/pipermail/patches/2001-February/004071.html





From bdesth.quelquechose at free.quelquepart.fr  Wed Dec 20 15:15:00 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Wed, 20 Dec 2006 21:15:00 +0100
Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects
In-Reply-To: <1166641701.439766.253290@f1g2000cwa.googlegroups.com>
References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com>
Message-ID: <458993ff$0$26521$426a74cc@news.free.fr>

thompson.marisa at gmail.com a ?crit :
> Hi.
> 
> I'm extremely new to Python and programming as a whole.  I have written
> a python script with the assistance of ESRI ArcGIS 9.2, which uses
> Python 2.4.1, however, it gives me this error when I try to run it.

Please post the full traceback. It's meant to help finding out what went 
wrong, you know...

> I've already posted at ESRI support, and I was hoping that Python
> people could help me more.
> 
> I hope there is something simple I could do to be able to define the
> object that it thinks is NoneType.

That's certainly not the solution...

>  Please when someone responds,
> please treat me as an absolute novice.
> 
> Thank you,
> Marisa
> 
> Here is my code:
> 
(snip)
> #Get list of Town Shapefiles
> Townshp = gp.ListFeatureClasses ("*")
(snip)
> 
> Townshp = Townshps.next()
> while Townshps !="":

1/ where does this "Townshps" comes from ?
2/ naming conventions are to use either all_lower (preferred) or at 
least mixedCase names for variables. And by all mean be consistent.
3/ if Townshp is a shortcut for Township, then it would be better to 
keep the full word
4/ the Python 'for' loop is meant to iterate over an iterable and taking 
care of boundaries, so you'd be better using it:

townships = gp.ListFeatureClasses ("*")
for township in townships:
   doSomethingWith(township)


From mike.klaas at gmail.com  Fri Dec 22 22:01:55 2006
From: mike.klaas at gmail.com (Klaas)
Date: 22 Dec 2006 19:01:55 -0800
Subject: pyparsing announcement?
In-Reply-To: <458c944d$0$16944$4c368faf@roadrunner.com>
References: <458c944d$0$16944$4c368faf@roadrunner.com>
Message-ID: <1166842915.380116.239490@80g2000cwy.googlegroups.com>

Paul McGuire wrote:
> I have tried a couple of times now to post an announcement of the latest
> version of pyparsing, but it does not seem to be making it past the news
> server, neither through my local ISP's server nor through GoogleGroups.
> Could it be because I am also posting to comp.lang.python.announce, and this
> moderated group is holding up posts to all groups?  (Doesn't really make
> sense to me, but it's all I can come up with.)

Moderated usenet is implemented by emailing the post to the moderator,
who then posts the message to usenet with special headers.  A
cross-posted message is a single message, so yes, it will get held up
until the moderator approves it for _all_ groups.

-Mike



From paddy3118 at netscape.net  Sat Dec  9 20:53:00 2006
From: paddy3118 at netscape.net (Paddy)
Date: 9 Dec 2006 17:53:00 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
Message-ID: <1165715580.731398.131690@f1g2000cwa.googlegroups.com>

Mark Tarver wrote:

> How do you compare Python to Lisp?  What specific advantages do you
> think that one has over the other?
>
> Note I'm not a Python person and I have no axes to grind here.  This is
> just a question for my general education.
>
> Mark

NOBODY expects the Lispers Inquisition!
Our chief weapon is age... age and macros...
...macros and age.
Our two weapons are age and macros....
And mathematical rigour...
Our THREE weapons are age, macros, and mathematical rigour...
...And an almost fanatical belief in Lisps superiority.
Our *four* ...no.
AMONGST our weapons...
Amongst our weaponry...
...Are such elements as fear, surprise.... I'll come in again.



Python is fun to use.
Easy to read.
Simple and powerful.
Easy to test.
Easy to maintain.
Fast. Very fast!

- Paddy.
.



From http  Sat Dec  9 18:18:54 2006
From: http (Paul Rubin)
Date: 09 Dec 2006 15:18:54 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
Message-ID: <7x4ps4r735.fsf@ruckus.brouhaha.com>

"mystilleef"  writes:
> Advantages of Python:
> 
> 1). More and better mature standard libraries (Languages don't matter,
> libraries do).

Erm, somewhat true, but Python's library is overrated.  Lisp's on the
other hand is out of date.

> 2). Multiple programming paradigms (including functional style
> programming see itertools, functools, operator modules (lambda, map,
> filter, reduce, sum etc builtins), higher order functions, list
> comprehension, blah, blah)

Getting there but still full of warts.

> 3). Better OO implementation. (I used to hate OO until I started using
> Python)

Have you used CLOS?  Flavors?

> 4). Ultimate glue language (Plays well with C, C++, Java, .NET. nuff
> said. Bindings for almost any lib worth using, at least on *nix)

Hmm, Python's C API is awful compared with the FFI's in reasonable
Lisp implementations or to Java's JNI.

> 5). Clearer syntax.

OK.

> 6). Better namespace management. (nobody ever talks about this, but
> Python seems to be one of the few languages that gets symbol management
> right from a users perspective)

I dunno, Python gets some things completely wrong in this regard.

> 7). Easier packaging and distribution system.

Because there's basically just one Python implementation (CPython).

> 8). Ubiquity! Python is everywhere. Lisp, bleh.

Not so sure of this, unless you're limiting to Common Lisp.  There are
Lisp systems out there that use as little as 20k of memory, running
inside cellular phones etc.  By comparison an attempt to shoehorn
Python into the 1 megabyte Palm handheld computer was abandoned.

> 9). Relatively good docs (PHP has better).

Lisp's docs are far superior to Python's.  This is one of the areas
where I bag on Python all the time. 

> 10). Fewer perceived community assholes. Large community.
> 11). Less fragmentation.

True and true.

> Advantages of Lisp:
> 
> Learning a functional language can improve your programming range and
> depth. And today, I wouldn't even recommend Lisp (it's rather archaic),
> when there's mind bending Haskell. I'd go as far as saying I believe
> Haskell has a better fate than Lisp.

I don't really of think Lisp as a functional language; its data
representation is what makes it worth knowing.  Despite years of
experience with Lisp and Python I'm still having trouble wrapping my
head around Haskell, and that tells me Haskell is really doing stuff
that Lisp does not.

> On Lisp Macros:
> 
> I think they are overrated, and in general cause more harm than good.
> It's the reason I find Lisp-like programs difficult to grok, maintain
> and extend. Cos every smart ass wants to needlessly write his own mini
> language to the point of absolute obfuscation. Naturally, I'm supposed
> to be awed by his mischievous cleverness.

There is certainly the possibility of writing Lisp code that way, but
it's not all that big a problem when the code is written tastefully.

> Conclusion:
> 
> The semantics or features of a language is almost irrelevant today.
> Developers want to put the lego pieces together, they don't want to
> make lego. Rewriting the sun and moon, or needlessly reinvent the wheel
> was popular in the 70s, but it's boring and expensive today. Today,
> when a developer needs to solve a problem, the question they ask is,
> "Is there a library for that?". 

But it seems to me that Java crushes Python in this regard.


From pc at p-cos.net  Tue Dec 12 06:56:11 2006
From: pc at p-cos.net (Pascal Costanza)
Date: Tue, 12 Dec 2006 12:56:11 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <7xmz5txs4x.fsf@ruckus.brouhaha.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	
	
	<4u7g1kF17436jU1@mid.individual.net>
	<7xmz5txs4x.fsf@ruckus.brouhaha.com>
Message-ID: <4u7jmsF175jh0U1@mid.individual.net>

Paul Rubin wrote:
> Pascal Costanza  writes:
>> May you have tried the wrong Lisp dialects so far:
>>
>> (loop for i from 2 to 10 by 2
>>        do (print i))
> 
> The loop language is so complicated and confusing that I never
> bothered trying to learn it.

You can start with loop by using only the simple and straightforward 
constructs, and slowly move towards the more complicated cases when 
necessary. The nice thing about loop is that with some practice, you can 
write code that more or less reads like English.

 > I always used simpler primitives to
 > write loops and it was always enough.

No language construct is so simple that it cannot be replaced with a 
combination of simpler primitives.

>> This is Common Lisp. (Many Lisp and Scheme tutorials teach you that
>> you should implement this using recursion, but you really don't have
>> to. ;)
> 
> You can't really use that much recursion in Lisp because of the lack
> of guaranteed TCO.  I think that makes it reasonable to say that
> Scheme is a functional language but Lisp is not.  ("Functional" = it's
> reasonable to code in a style where the only way to connect variables
> to values is lambda binding (maybe through syntax sugar), so all loops
> are implemented with recursion).

All Common Lisp implementations that I am aware of provide ways to 
enable TCO, so it's definitely possible to program in a functional style 
if you want to. It's just that the ANSI Common Lisp specification 
doesn't guarantee this, but this doesn't matter much. The only downside 
is that there is no common interface to enable TCO - that would indeed 
be an improvement. The upside is that you can switch TCO off if you want 
to, which for example may improve debugging.

It's correct that Scheme has a stronger tendency towards functional 
programming than Lisp has.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/


From address.good.until.2006.dec.22 at justmail.de  Mon Dec 11 09:17:42 2006
From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=)
Date: Mon, 11 Dec 2006 15:17:42 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <7xejr8r86m.fsf@ruckus.brouhaha.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06>
	<1165649882.563957.87770@n67g2000cwd.googlegroups.com>
	
	<457abf83.18014323@news.readfreenews.net>
	
	<7xejr8r86m.fsf@ruckus.brouhaha.com>
Message-ID: 

Paul Rubin schrieb:
> Steven D'Aprano  writes:
>> Now, if you want to tell me that, despite all the talk, Lisp coders don't
>> actually create new syntax or mini-languages all that often, that they
>> just use macros as functions, then the question becomes: why do you need
>> macros then if you are just using them as functions? Why not use functions?
> 
> Macros let you write what amounts to functions that don't evaluate
> their arguments.  Think of the endless clpy wars over the ternary
> conditional operator.  You want to write something like
> 
>    def ternary(test, iftrue, iffalse):
>       if test: return iftrue
>       else iffalse
> 
> but because of side effects, you don't want
> 
>    a = cond(test, f(x), g(x)) 
> 
> to evaluate both f and g.  That is trivial to do with a macro but
> can't be done with a function.

I think you could do that with functional programming.
You can protect the evaluation by encapsulating the args in a function
object?


def f_Args(x):
   return x

def g_Args(x):
   return x


and then
a = cond(test, f, g, f_Args(x), g_Args(x))

if you adopt cond. But of course it is getting ugly.
So a macro can free you from this extra code.


Andr?
-- 


From rampeters at gmail.com  Sun Dec 10 12:31:57 2006
From: rampeters at gmail.com (johnny)
Date: 10 Dec 2006 09:31:57 -0800
Subject: mySql and multiple connection for threads
In-Reply-To: 
References: <1165602188.976489.74760@j44g2000cwa.googlegroups.com>
	
Message-ID: <1165771916.968044.307570@16g2000cwy.googlegroups.com>

Thank you VERY MUCH Dennis, for taking the time to explain to me.



From kay.schluehr at gmx.net  Wed Dec  6 09:44:01 2006
From: kay.schluehr at gmx.net (Kay Schluehr)
Date: 6 Dec 2006 06:44:01 -0800
Subject: len() and PEP 3000
References: <4tnqlkF13bbqeU1@mid.individual.net>
	<4to00aF14cki5U2@mid.individual.net>
Message-ID: <1165416241.852026.325820@j44g2000cwa.googlegroups.com>

Bjoern Schliessmann schrieb:

> Thomas Guettler wrote:
>
> > I suggest that at least lists, tupples, sets, dictionaries and
> > strings get a len() method.
>
> Why?

Pro: Because it makes the API more monotonous and more aligned with all
other OO languages that exist now and in future. It also helps any
written and unwritten IDE providing a method by means of
autocompletion. It ends endless debates with Java/C++/C# etc. and
newbie Python programmers about this minor issue.

Contra: Having both __len__ ( for providing a generic function by
duality ) and len in the API is unpleasant.

But maybe one can drop all __special__ methods and use a decorator to
express duality between methods and functions?

class M:
    @generic
    def foo(self):
         print "foo"

>>> foo(M())  #  equals M().foo()
"foo"

And since we are at it. Why not also dropping __add__, __radd__,
__plus__ etc. for:

class M:
    def binary+(self, other):   # replaces __add__
         ...

    def r_binary+(self, other): # replaces __radd__
         ...

    def unary+(self, other):    # replaces __plus__
         ...



From fredrik at pythonware.com  Tue Dec 12 04:51:49 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 12 Dec 2006 10:51:49 +0100
Subject: One module per class, bad idea?
In-Reply-To: 
References: 
Message-ID: 

Matias Jansson wrote:

> I come from a background of Java and C# where it is common practise to have 
> one class per file in the file/project structure. As I have understood it, 
> it is more common practice to have many classes in a Python module/file. 

even more important is that in Python, you don't use classes for every-
thing; if you need factories, singletons, multiple ways to create 
objects, polymorphic helpers, etc, you use plain functions, not classes 
or static methods.

once you've gotten over the "it's all classes", use modules to organize 
things in a way that makes sense to the code that uses your components. 
  make the import statements look good.





From magoldfish at gmail.com  Fri Dec 29 15:21:20 2006
From: magoldfish at gmail.com (Marcus Goldfish)
Date: Fri, 29 Dec 2006 15:21:20 -0500
Subject: probably a stupid question: MatLab equivalent of "diff" ?
In-Reply-To: 
References: 
Message-ID: <5e183f3d0612291221t1d8c5b11h615e7bffb9ceb72e@mail.gmail.com>

On 12/29/06, Stef Mientki  wrote:
>
> Does anyone know the equivalent of the MatLab "diff" function.
> The "diff" functions calculates the difference between 2 succeeding
> elements of an array.
> I need to detect (fast) the falling edge of a binary signal.
>
> There's derivate function in Python diff,
> but when you use an binary (true/false) input,
> it also detects rising edges.
>
> Probably a stupid question,
> but I still have troubles,
> digging to huge amount of information about Python.
>
> thanks,
> Stef Mientki
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Stef,

Can you provide more context on your use-- are you receiving binary data
sequentially, or do you have a list or array of binary values?  Are you
using numpy/scipy?

Marcus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From kay.schluehr at gmx.net  Mon Dec 11 15:20:24 2006
From: kay.schluehr at gmx.net (Kay Schluehr)
Date: 11 Dec 2006 12:20:24 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>
	<1165769504.098173.101860@j72g2000cwa.googlegroups.com>
	<1165849055.492230.119310@n67g2000cwd.googlegroups.com>
	<1165855222.367374.163170@80g2000cwy.googlegroups.com>
Message-ID: <1165868422.964826.52840@80g2000cwy.googlegroups.com>

JShrager at gmail.com wrote:

> I've already admitted that this was both a poor choice of words and, as
> pointed out by Carl, an ad hominem argument. However, if you read the
> whole thing you'll see that I'm really railing against the silly "It
> fits your brain" and "Only one way to do things" marketing hype, and
> programmers who seem to swallow and repeat it, not programmers in
> general, nor even python programmers in general.

Yes, but these are community symbols or tribe marks. They don't have
much meaning per se, just like the language name or a corporate
identity. However they express an attitude ( being easy and free from
language design redundancy ) that can be measured at least subjectively
by the user. If Ruby "fits the brain" better, then people will simply
drop Python in future or right now. There is nothing deep about it.

I'm not precisely sure when programming languages have turned into pop
culture and language designers stopped to name them "Algol", "Scheme"
or "A Programming Language" but "Joy", "Perl" or "Java". Even the small
lambda symbol is a pop fetish nowadays that is printed on the T-shirts
of Haskellians. Obviously language communities need some emotional glue
to grow even when they are constituted mainly by CS PhDs. I don't find
this necessarily a bad thing. In case of Lisp I don't think Paul Graham
made a bad job in constructing the imagery of a libertarian macho
hacker with a high end tool. Meanwhile all the flies are sitting on
Blubb that means on a heap of shit. A bit archaic and more cowboy than
Michelangelo but even Hegel is more famous for ending history, over 150
years before F. Fukuyama repeated this act, then for his intricate
systems theory created by idealist speculation. Some things end as pop
cult while others fill the archives of university libraries.



From __peter__ at web.de  Thu Dec 14 08:15:52 2006
From: __peter__ at web.de (Peter Otten)
Date: Thu, 14 Dec 2006 14:15:52 +0100
Subject: Routine for prefixing '>' before every line of a string
References: <1166097838.257731.297110@l12g2000cwl.googlegroups.com>
Message-ID: 

Sanjay wrote:

> Is somewhere a routine useful to convert a string to lines of maxsize,
> each prefixed with a '>'. This is a typical requirement for 'keeping
> existing text while replying to a post in a forum'.

>>> import textwrap
>>> format = textwrap.TextWrapper(20, initial_indent="] ",
subsequent_indent="] ").fill
>>> print format("alpha beta gamma delta\nepsilon zeta eta theta")
] alpha beta gamma
] delta epsilon zeta
] eta theta

Peter



From ZeeGeek at gmail.com  Wed Dec 13 14:22:26 2006
From: ZeeGeek at gmail.com (Ning)
Date: 13 Dec 2006 11:22:26 -0800
Subject: pycrypto 3DES keysize
Message-ID: <1166037746.409807.266750@n67g2000cwd.googlegroups.com>

I'm trying to write an IM client which sends encrypted messages to the
server.  I tried to use pycrypto library, but when I came to 3DES
cypher I was confused about the keysize to use.  In the standard it
said that it should be either 112 bits or 168 bits, whereas it's 16
bytes or 24 bytes in pycrypto.  If I use 16 bytes key to encrypt and
send this key to the server which is expecting a 112 bits key, there'll
be a problem.  How I should solve this?



From tony at PageDNA.com  Fri Dec 29 20:08:02 2006
From: tony at PageDNA.com (Tony Lownds)
Date: Fri, 29 Dec 2006 17:08:02 -0800
Subject: PEP 3107 Function Annotations for review and comment
In-Reply-To: <740c3aec0612291609w65f8becco5cf5b833d21c17da@mail.gmail.com>
References: 
	<740c3aec0612291609w65f8becco5cf5b833d21c17da@mail.gmail.com>
Message-ID: <991F26F5-67D6-4540-B08A-94C38D572C4D@PageDNA.com>


On Dec 29, 2006, at 4:09 PM, BJ?rn Lindqvist wrote:
>
> I think this rationale is very lacking and to weak for such a big
> change to Python. I definitely like to see it expanded.
>
> The reference links to two small libraries implementing type checking
> using decorators and doc strings. None of which to seem to be very
> popular in the Python community. Surely, those two libraries *alone*
> can't be enough of a motivation for this? To me, it is far from
> self-evident what purpose function annotations would serve.
>
> I also wonder why a very obtrusive syntax addition is needed when it
> clearly is possible to annotate functions in today's Python. Why is
> syntax better than just adding a function annotation decorator to the
> standard library?
>
>     @annotate(a = int, b = dict, c = int)
>     def foo(a, b, c = 5):
>         ...
>
> Are decorators to ugly?

The syntax does look better than a decorator. The syntax also provides
a notation for documentation to follow. Even a standard decorator won't
help with that. I am surprised you think the syntax is more  
obstrusive than the
decorator.

-Tony

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From gagsl-py at yahoo.com.ar  Thu Dec 28 03:56:54 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Thu, 28 Dec 2006 05:56:54 -0300
Subject: I'm having trouble understanding scope of a variable in a subclass
In-Reply-To: <87lkksmtlg.fsf@pyenos.pyenos.org>
References: <87bqloej4x.fsf@pyenos.pyenos.org>
	
	<87lkksmtlg.fsf@pyenos.pyenos.org>
Message-ID: <7.0.1.0.0.20061228055022.039b8720@yahoo.com.ar>

At Thursday 28/12/2006 03:18, Pyenos wrote:

>class Class1:
>     class Class2:
>         class Class3:
>             def __init__(self):
>                 self.var="var"
>             class Class4:
>                 print Class1.Class2.Class3.var
>
>This code gives me the error:
>Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 2, in Class1
>   File "", line 3, in Class2
>   File "", line 6, in Class3
>   File "", line 7, in Class4
>NameError: name 'Class1' is not defined

- put your print statement inside a method
- as I've said, try to grab the difference between an instance 
attribute and a class attribute.

var is an attribute of Class3 instances (because you wrote self.var = 
something), so you need a Class3 instance to access it.
Class3 is a class attribute of Class2. Class2 is an instance 
attribute of Class1. Putting all this together, you can refer to such 
"var" as Class1.Class2.Class3().var


-- 
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 



From researchbase at gmail.com  Mon Dec 11 12:45:07 2006
From: researchbase at gmail.com (krishnakant Mane)
Date: Mon, 11 Dec 2006 23:15:07 +0530
Subject: need guidance on sending emails with attachment with python.
In-Reply-To: <1165841644.575882.98390@16g2000cwy.googlegroups.com>
References: 
	<1165841644.575882.98390@16g2000cwy.googlegroups.com>
Message-ID: 

On 11 Dec 2006 04:54:04 -0800, Bernard  wrote:
> here's the function I've been using for while :P
>
thanks indeed for the function Bernard.
I will have a windows machine up tomorrow.  but do I need to install
any thing over and above the python libraries needed?
is it necessary that I install outlook or do I need to install any
server/ client on the machine where your function is to be used?
> import smtplib
> from email.MIMEMultipart import MIMEMultipart
> from email.MIMEBase import MIMEBase
> from email.MIMEText import MIMEText
> from email.Utils import COMMASPACE, formatdate
> from email import Encoders
>
> def sendMail(arrRecipients, sender, subject, message, files=[]):
>     """ Sends email with attachements """
>     # SMTP address
>     smtpserver = '' # provide a smtp here in string format
>     # authentification section
>     AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1
>     smtpuser = ''  # for SMTP AUTH, set SMTP username here
>     smtppass = ''  # for SMTP AUTH, set SMTP password here
>
>     # Building the body of the email
>     mssg = MIMEMultipart()
>     mssg['From'] = sender
>     mssg['To'] = COMMASPACE.join(arrRecipients)
>     mssg['Date'] = formatdate(localtime=True)
>     mssg['Subject'] = subject
>     mssg.attach( MIMEText(message) )
>
>     # attachments
>     for file in files:
>         part = MIMEBase('application', "octet-stream")
>         part.set_payload( open(file,"rb").read() )
>         Encoders.encode_base64(part)
>         part.add_header('Content-Disposition', 'attachment;
> filename="%s"' % os.path.basename(file))
>         mssg.attach(part)
>
>     session = smtplib.SMTP(smtpserver)
>     if AUTHREQUIRED:
>         session.login(smtpuser, smtppass)
>     smtpresult = session.sendmail(sender, arrRecipients,
> mssg.as_string())
>
>     if smtpresult:
>         errstr = ""
>         for recip in smtpresult.keys():
>             errstr = """Could not delivery mail to: %s
>
>     Server said: %s
>     %s
>
>     %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
>         raise smtplib.SMTPException, errstr
>
> krishnakant Mane a ?crit :
>
> > hello,
> > I am a bit confused.
> > I want to make a program that will take some data from a database and
> > make a string of text.  and send it to the respective email id of a
> > person.
> > next I also want to send an attachment of a photo along with the email.
> > I will be required to make this program run on windows xp.
> > can some one guide me as to how I can achieve this?
> > what I will need on windows to send emails?
> > I believe yahoo, gmail, rediff and msn supports pop3 and smtp?
> > correct me if I am wrong on this.
> > secondly what library is used on windows to do this?
> > I know there must be python libraries to do this,
> > but apart from that I don't know what all I will need on my windows
> > machine to send emails to mostly yahoo, gmail and msn.
> > Please give me some idea about it.
> > Krishnakant.
>
>
>


From gdamjan at gmail.com  Fri Dec  8 20:08:47 2006
From: gdamjan at gmail.com (Damjan)
Date: Sat, 09 Dec 2006 02:08:47 +0100
Subject: Mod_python vs. application server like CherryPy?
References: 
	<1165367106.268299.240650@l12g2000cwl.googlegroups.com>
	<33gen2ls04mj8t46piih5bg342ehbbh06h@4ax.com>
	<1165445758.342163.37650@f1g2000cwa.googlegroups.com>
Message-ID: <457a0c8d$0$49208$14726298@news.sunsite.dk>

> For example, consider an extreme case such as WSGI. Through a goal of
> WSGI being portability it effectively ignores practically everything
> that Apache has to offer. Thus although Apache offers support for
> authentication and authorisation, a WSGI user would have to implement
> this functionality themselves or use a third party WSGI component that
> does it for them. 

OTOH 
WSGI auth middleware already supports more auth methods than apache2 itself.

> Another example is Apache's support for enabling 
> compression of content returned to a client. The WSGI approach is again
> to duplicate that functionality. 

the gzip middleware is really just an example... nobody would use that in
production.

> Similarly with other Apache features 
> such as URL rewriting, proxying, caching etc etc.

Well, not everybody can use Apache ... and again there's already WSGI
middleware that's more flexible than the Apache modules for most of the
features you mention.

It's not that I think mod_python doesn't have uses.. I just think it's not
practical to make python web applications targeted solely to mod_python.



-- 
damjan


From carsten at uniqsys.com  Thu Dec 28 10:35:50 2006
From: carsten at uniqsys.com (Carsten Haese)
Date: Thu, 28 Dec 2006 10:35:50 -0500
Subject: How to return a simple variable from a function (still newbie) ?
In-Reply-To: 
References: 
Message-ID: <1167320150.3394.17.camel@dot.uniqsys.com>

On Thu, 2006-12-28 at 16:14 +0100, Stef Mientki wrote:
> I want to return a "simple" variable from a function,
> not using the function result.
> Is that in any way possible ??
> 
> The code below is from O'Reilly, "Learning Python",
> and there seems no way
> to return a simple var like "z" in the example below.
> Is that true ?
> 
> thanks,
> Stef Mientki
> 
> 
> def some_function (z, y):
>    z = 2
>    y[2] = 'global ?'
> 
> 
> x = 5
> y = [1,2,3,4]
> print x,y
> some_function(x,y)
> print x,y
> 

Please reset your brain and read
http://effbot.org/zone/python-objects.htm , paying particular attention
to the section called "Assignment".

You should also think long and hard about *why* you want to return a
value from a function by modifying an input parameter instead of just
using the return statement. The "return by modifying an input parameter"
approach comes from C where that's the only way to return more than one
value from a function. In Python, no such crutch is necessary or
desirable.

With this in mind, the following quote seems appropriate:
"Trying to write C code using Python isn't going to be fun or
productive." -- Grant Edwards, comp.lang.python, 13 Sep 2006.

Hope this helps,

Carsten.




From mcbooczech at gmail.com  Mon Dec 18 18:26:55 2006
From: mcbooczech at gmail.com (Petr Jakes)
Date: 18 Dec 2006 15:26:55 -0800
Subject: writing serial port data to the gzip file
In-Reply-To: 
References: <1166403993.201955.63290@l12g2000cwl.googlegroups.com>
	
Message-ID: <1166484415.663396.75560@80g2000cwy.googlegroups.com>

Hi Dennis,
thanks for your reply.
Dennis Lee Bieber napsal:
> > def dataOnSerialPort():
> >     data=s.readLine()
>
> 	Unless you are using a custom serial port module, that should be
> s.readline()
sorry for the typo
>
> >     if data:
> >         return data
> >     else:
> >         return 0
>
> 	This if statement is meaningless -- if "data" evaluates to false,
> return a numeric value that evaluates to false.
I see, it is OK just to return data (or an empty string "")
>
> >
> > while 1:
> >     g=gzip.GzipFile("/root/foofile.gz","w")
> >     while dataOnSerialPort():
> >         g.write(data)
>
> 			"data" is an uninitialized value here
> >     else: g.close()
>
> 	And what is the purpose of closing the file if you immediately turn
> around and create it again (assuming gzip.GzipFile() behaves as open()
> does, a mode of "w" means delete the old file and create a new one.
> There is NO exit from the above.
>
> 	Since I can't read your mind with regards to some of your looping...
>
> s = ... #somewhere you had to open the serial port
>
> g = gzip.GzipFile("/root/foofile.gz", "w")
> while True:
> 	data = s.readline()
> 	if not data: break
> 	g.write(data)
> g.close()

what I am trying to say is g.close() does not close the g file (try to
add the line "print g" after g.close())
Petr



From mike.klaas at gmail.com  Fri Dec  8 14:06:31 2006
From: mike.klaas at gmail.com (Klaas)
Date: 8 Dec 2006 11:06:31 -0800
Subject: I think Python is a OO and lite version of matlab
In-Reply-To: <1165564104.379172.272890@l12g2000cwl.googlegroups.com>
References: <1165564104.379172.272890@l12g2000cwl.googlegroups.com>
Message-ID: <1165604790.756993.195220@l12g2000cwl.googlegroups.com>



On Dec 7, 11:48 pm, "Allen"  wrote:
> Does anyone agree with me?
> If you have used Matlab, welcome to discuss it.

Numpy definitely was inspired in its extended array syntax by matlab.
Besides that, I don't think two languages could be more different.
Philosophically, matlab is closer to perl.

-Mike



From roy at panix.com  Wed Dec 27 14:45:40 2006
From: roy at panix.com (Roy Smith)
Date: Wed, 27 Dec 2006 14:45:40 -0500
Subject: Iterating over several lists at once
References: <1166017627.699257.166740@16g2000cwy.googlegroups.com>
Message-ID: 

In article <1166017627.699257.166740 at 16g2000cwy.googlegroups.com>,
 "Gal Diskin"  wrote:

> Hi,
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
> 
> for x1 in l1:
>     for x2 in l2:
>         for x3 in l3:
>             print "do something with", x1, x2, x3
> 
> What I need to do is go over all n-tuples where the first argument is
> from the first list, the second from the second list, and so on...

Take a look at 
http://mail.python.org/pipermail/python-list/2001-September/104983.html

or

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/159975

There's nothing magic about either -- fundamentally, you're still doing an 
N^3 operation and it's going to be slow.  You might want to stop and think 
if there's some better algorithm than an exhaustive search of the entire 
domain space for whatever it is that you're trying to do.


From tkpmep at hotmail.com  Fri Dec 29 07:52:30 2006
From: tkpmep at hotmail.com (tkpmep at hotmail.com)
Date: 29 Dec 2006 04:52:30 -0800
Subject: list looping error
References: 
Message-ID: <1167396750.422149.305660@a3g2000cwd.googlegroups.com>


What you really want to write is
for i in x:
    for j in i:
        print j

The outer loop iterates over the tuples in the list, while the inner
loop iterates over the elements of each tuple. So j (in your example)
is always an integer, and is therefore unsubscriptable, which is
exactly what the error message says.

Thomas Philips



From kay.schluehr at gmx.net  Sat Dec 16 05:58:06 2006
From: kay.schluehr at gmx.net (Kay Schluehr)
Date: 16 Dec 2006 02:58:06 -0800
Subject: merits of Lisp vs Python
References: 
	
	
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	 
	<4ubu3nF16kv7aU1@mid.individual.net> 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net> 
	 <4ufemoF17of60U3@mid.individual.net>
	 <4uhl73F108ri8U1@mid.individual.net>
	
Message-ID: <1166266686.683646.282840@80g2000cwy.googlegroups.com>

Ken Tilton schrieb:

> Looks promising. How does a generic engine that sees only a solution (a
> list of mathematical expressions and for each the transformations,
> results, and opnds logged by individual TF functions) build up this
> environment such that it has named attributes such as signed-value?

Most likely it doesn't since there is no such engine. Instead local
rules and combinators are encoded in classes. Hence there is nothing
but an object tree and actions are threaded through recursive method
calls.

This implies that the generic reverse function is just the dual of a
method call:

def reverse(expr):
     return expr.reverse()

What expr does depends on the internal representation encoded in the
class of expr. This also implies that not only the form of the
expression is significant but also its ( dynamic ) type.



From hjebbers at gmail.com  Fri Dec 22 08:43:07 2006
From: hjebbers at gmail.com (henk-jan ebbers)
Date: Fri, 22 Dec 2006 14:43:07 +0100
Subject: add encoding to standard encodings works different in python 2.5?
 
Message-ID: <458BE0EB.4070303@gmail.com>

Greetings,

I use an encoding that is not available in the std python-encodings, say 
encoding 'flup';
under different circumstances a user might wish different version of 
'flup': a strict one or a more relaxed encoding.
(yes I know, this is  terrible, but this is how it is)

in python2.4, I managed this by:
    made flup_strict.py and flup_relaxed.py (coping an encoding from 
python std encodings; using a encoding/decoding map as in CP1252.py, 
with changes in the mapping).
    placed flup_strict.py and flup_relaxed.py  in my 'main'-directory 
(the dir from which the my-python-source starts)
    at start of my python-source: add an alias for the encoding:   
encodings.aliases.aliases['flup']='flup_relaxed'   (if user wishes 
relaxed encoding)
this works; the encoding 'flup' is recognized and used.

when testing with python 2.5, this does not work.
my questions are:
-   should this work in 2.5?
-   how can i get this to work in 2.5 (nice if it would work in both 2.4 
and 2.5)

btw, I use ubuntu linux edgy, with both python 2.4 and 2.5 installed

thanks, Henk-Jan




From bj_666 at gmx.net  Wed Dec 13 08:31:39 2006
From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch)
Date: Wed, 13 Dec 2006 14:31:39 +0100
Subject: [unicode] inconvenient unicode conversion of non-string arguments
References: 
Message-ID: 

In , Holger Joukl
wrote:

> Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
> Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde,
> verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail
> sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht
> gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht
> garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte
> den Inhalt der E-Mail als Hardcopy an.
> 
> The contents of this  e-mail are confidential. If you are not the named
> addressee or if this transmission has been addressed to you in error,
> please notify the sender immediately and then delete this e-mail.  Any
> unauthorized copying and transmission is forbidden. E-Mail transmission
> cannot be guaranteed to be secure. If verification is required, please
> request a hard copy version.

Maybe you should rethink if it really makes sense to add this huge block
of "nonsense" to a post to a newsgroup or public mailing list.  If it's
confidential, just keep it secret.  ;-)

Ciao,
	Marc 'BlackJack' Rintsch


From skip at pobox.com  Fri Dec 29 22:14:23 2006
From: skip at pobox.com (skip at pobox.com)
Date: Fri, 29 Dec 2006 21:14:23 -0600
Subject: No way to set a timeout in "urllib".
In-Reply-To: <%hglh.1141$ji1.1051@newssvr12.news.prodigy.net>
References: <%hglh.1141$ji1.1051@newssvr12.news.prodigy.net>
Message-ID: <17813.55695.46187.511560@montanaro.dyndns.org>


    John> There's no way to set a timeout if you use "urllib" to open a URL.
    John> "HTTP", which "urllib" uses, supports this, but the functionality
    John> is lost at the "urllib" level.

    John>     It's not available via "class URLopener" or "FancyURLopener",
    John>     either.

    John> There is a non-thread-safe workaround from 2003 at

    ...

This topic has come up several times since timeouts were added to socket.
Each time we've asked for a patch that adds timeouts in a rational manner to
all the stuff layered on top of the socket module (httplib, ftplib, etc). As
far as I know it's apparently never been important enough for anyone to rise
to the challenge.  If I remember next spring perhaps I'll submit it as a
possible Google Summer of Code proposal.

    John> The correct fix would probably be to add methods to class
    John> URLopener to control this; that's the usual way of handling
    John> special URL opening situations.

The correct way would be to deal with it at the httplib level, then
percolate it up to urllib2.  Urllib should probably not be extended any
further.

Skip



From http  Tue Dec 12 19:51:09 2006
From: http (Paul Rubin)
Date: 12 Dec 2006 16:51:09 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<7xslfqar7v.fsf@ruckus.brouhaha.com>
	<1165623284.242403.295140@l12g2000cwl.googlegroups.com>
	<7xodqdj2dn.fsf@ruckus.brouhaha.com>
	
Message-ID: <7xslfkty82.fsf@ruckus.brouhaha.com>

Robert Uhl  writes:
> > And you can't implement Python generators as Lisp macros in any
> > reasonable way.
> I'm pretty certain it could be done with conditions.

It's worse than that, there was a big sub-thread about it, conclusion
seems to be it can be done but you need a code walker.  I'd consider
that pretty messy, but at least slightly within the scope of
"reasonable".


From paul at boddie.org.uk  Sun Dec 10 10:55:58 2006
From: paul at boddie.org.uk (Paul Boddie)
Date: 10 Dec 2006 07:55:58 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
Message-ID: <1165766158.683896.228860@79g2000cws.googlegroups.com>

mystilleef wrote:
> Rewriting the sun and moon, or needlessly reinvent the wheel
> was popular in the 70s, but it's boring and expensive today. Today,
> when a developer needs to solve a problem, the question they ask is,
> "Is there a library for that?". If the answer is no, they a more likely
> to switch to a language that provides a library that solves their
> problem.

Indeed. Software development is not a purely technical discipline:
combinations of issues such as the ability to reuse components, the
availability of such components, economics, project organisation, the
skills of participants, and so on, all start to weigh against the
benefits of being able to roll one's own elegant solutions over and
over again.

> The challenge for developers today is software architecture,
> robustness and scalability, not language purity or semantics. The Lisp,
> and to an extent Haskell, community will never ever ever grok this.

I'm not sure that you're correct about the Haskell community: there
appears to be a fair amount of relevant new work emerging from that
direction which may not only help Haskell developers to deal with the
harder problems of developing scalable and robust systems, but also
might affect the evolution of a number of other languages. However, I'd
agree that with the emergence of languages like Erlang, people want
solutions focused on particular systems engineering problems - it's all
very well arguably having the toolbox to create such solutions, but
most software developers just want to be handed the right tool.

> They'll continue to wonder why an "inferior" language like Python keeps
> getting popular. It will always escape them that it might be because
> Python is actually easier to use for most people to write "real world"
> applications. It has good usability.

And with regard to the remark about having access to libraries, it's
worth remembering that there's a lot of envy about things like CPAN -
an extensive collection of libraries for an even more "inferior"
language. When it is said that "CPAN is the language, Perl 6 is the
syntax", the remark should not be a surprise - it's a trend that was
observed at least twenty or thirty years ago, if not before.

Paul



From chenal at naritech.cn  Fri Dec  8 04:57:20 2006
From: chenal at naritech.cn (Allen)
Date: 8 Dec 2006 01:57:20 -0800
Subject: I think Python is a OO and lite version of matlab
In-Reply-To: <1165569793.031978.121190@n67g2000cwd.googlegroups.com>
References: <1165564104.379172.272890@l12g2000cwl.googlegroups.com>
	<1165569793.031978.121190@n67g2000cwd.googlegroups.com>
Message-ID: <1165571840.060859.16530@j44g2000cwa.googlegroups.com>


> Sure, and earth is a heavy version of a basketball. If all you have is
> a hammer...
>

It is not make sense to compare earth and basketball.
I think Python introduced many idea of matlab.

If you have used matlab, you will say that they are very very similar,
except that matlab was born years earlier and is used mainly in the
area
of matrix calculation.

I do not mean Python shall feel ashamed for it. We will be pleased that
Python 
does absorb many successful ideas of computer languages.



From nogradi at gmail.com  Sat Dec 16 12:44:42 2006
From: nogradi at gmail.com (Daniel Nogradi)
Date: Sat, 16 Dec 2006 18:44:42 +0100
Subject: module wide metaclass for new style classes
Message-ID: <5f56302b0612160944i6f3d8c4cye5a970a15a07f312@mail.gmail.com>

I used to have the following code to collect all (old style) class
names defined in the current module to a list called reg:


def meta( reg ):
    def _meta( name, bases, dictionary ):
        reg.append( name )
    return _meta

reg = [ ]
__metaclass__ = meta( reg )

class c1:
    pass

class c2:
    pass

print reg


This would correctly print [ 'c1', 'c2' ]. Now I would like to switch
to new style classes but replacing class c1: and class c2: by class
c1(object): and class c2(object): doesn't work because the metaclass
associated with object will be called and not mine. Of course if I
would add __metaclass__ = meta(reg)  to all class definitions that
would work, but how do I do this on the module level?


From noway at ask.me  Thu Dec  7 06:21:24 2006
From: noway at ask.me (Giovanni Bajo)
Date: Thu, 07 Dec 2006 12:21:24 +0100
Subject: Subprocess with a Python Session?
In-Reply-To: 
References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com>
	
Message-ID: 

Fredrik Lundh wrote:

>> No matter what I do I cant get the following code to do what I expect.
>> I hadn't used subprocess t o read and write to pipes of a
>> still-running app, and I just can't seem to get it right. What gives?
>>
>> import subprocess
>>
>> p = subprocess.Popen("python", stdout=subprocess.PIPE, 
>> stdin=subprocess.PIPE)
>> p.stdin.write('print 10\n')
> 
> + p.stdin.close()
> 
>> assert p.stdout.readline() == '10\n'

Yeah, but WHY was the API designed like this? Why can't I read and write 
freely from a pipe connected to a process as many times as I want?
-- 
Giovanni Bajo


From andrew at farwestbilliards.com  Sun Dec 10 01:06:57 2006
From: andrew at farwestbilliards.com (Andrew Sackville-West)
Date: Sat, 9 Dec 2006 22:06:57 -0800
Subject: ooopy: newbie cannot get basic functionality to work
In-Reply-To: <1165728632.133298.117130@73g2000cwn.googlegroups.com>
References: 
	<1165728632.133298.117130@73g2000cwn.googlegroups.com>
Message-ID: <20061210060657.GA6105@localhost.localdomain>

On Sat, Dec 09, 2006 at 09:30:32PM -0800, John Machin wrote:
> 
> Andrew Sackville-West wrote:
> >
> > >>> o = OOoPy (infile='/home/andrew/monthly.ods')
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > TypeError: 'module' object is not callable
> > >>>
> 
> OK, so that tells you that ooopy.OOoPy is a *module*, and it contains
> *another* gizmoid named OOoPy.

ah ha! I knew it was something fundamental. its those technical terms
that throw me ;-) (gizmoid).
> 
> [snip]
> > >>> sys.modules
> [snip]
> > 'ooopy.OOoPy':  > '/usr/lib/python2.4/ooopy/OOoPy.py'>,
> 
> Uh-huh. Confirmation that ooopy.OOoPy is a module.
> 
> Try:
> 
> from ooopy import OOoPy
> o = OOoPy.OOoPy(infile='/home/andrew/monthly.ods')
> 
> BTW, is that package being maintained? Did you ask the maintainer? Any
> response?
> 

I wondered about that when I was looking at it. It was last updated
about a year ago which isn't bad as far as some projects go... heh. No
I didn't go after the maintainer. I'm also looking at maybe using
ElementTree directly as ooopy is a pretty thin wrapper anyway. 

anyway, thanks for the help. I can now do fun things like for n in
o.getiterator(): and so forth.

A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: 

From CRhode at LacusVeris.com  Sat Dec  2 14:10:25 2006
From: CRhode at LacusVeris.com (Chuck Rhode)
Date: Sat, 2 Dec 2006 13:10:25 -0600
Subject: PythonTidy
In-Reply-To: 
References: <20061130024509.GA8961@loki> 
	<20061201025240.GE799@loki> 
Message-ID: <20061202191025.GA14624@loki>

Thomas Heller wrote this on Fri, Dec 01, 2006 at 10:12:38PM +0100.  My reply is below.

> Chuck Rhode schrieb:

> > o Command-line args: Please give an example of a standard command that
> > I might emulate w.r.t. standard argument use.

> Well, at least it would be nice if I could call
> 'PythonTidy.py mymodule.py' to tidy up the mymodule.py file.

I've uploaded a new version of PythonTidy:

o  http://www.lacusveris.com/PythonTidy/PythonTidy-1.4.python  

It fixes several problems.  Also it allows file names as arguments.

> Here is part of a diff before and after running PythonTidy on it:

> 
> -        def comptr_setitem(self, index, value):
> -            # We override the __setitem__ method of the
> -            # POINTER(POINTER(interface)) type, so that the COM
> -            # reference count is managed correctly.
> +        def comptr_setitem(self, index, value):  # We override the __setitem__ method of the
> +                                                 # POINTER(POINTER(interface)) type, so that the COM
> +                                                 # reference count is managed correctly.

> Can this be customized?

This problem has been fixed I think.  No customization should be
required to keep block comments from being rendered as in-line
comments.

Wolfgang Grafen reported that PythonTidy crashed in Python-2.4 because
new Abstract Syntax Tree node types introduced in Python-2.5 weren't
available.  It was trivial to check availability, so PythonTidy should
now run in Python-2.4.  However, this has not been thoroughly tested
and is not guaranteed.

PythonTidy can now recode string literals if required, although this
capability is turned off by default.  See RECODE_STRINGS.

Docstrings will henceforward be enclosed in double quotes when
feasible.

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 30? ? Wind WSW 10 mph ? Sky overcast.


From mike.klaas at gmail.com  Fri Dec  1 18:53:56 2006
From: mike.klaas at gmail.com (Klaas)
Date: 1 Dec 2006 15:53:56 -0800
Subject: Fun with with
Message-ID: <1165017236.409300.171950@l12g2000cwl.googlegroups.com>

Occasionally I find myself wanting a block that I can break out of at
arbitrary depth--like java's named break statements.  Exceptions can
obviously be used for this, but it doesn't always look nice.

The with statement can be used to whip up something quite usable:

class ExitBlock(object):
    """ A context manager that can be broken out of at an arbitrary
depth,
    using .exit() """
    def __init__(self):
        class UniqueException(BaseException):
            pass
        self.breakExc = UniqueException
    def exit(self):
        raise self.breakExc()
    def __enter__(self):
        return self
    def __exit__(self, t, v, tb):
        return t is self.breakExc

Now the most important thing here is that each exit block creates a
unique exception type.  If you have philosophical issues with creates
unboundedly many type objects, you can use unique instances too.

This allows named break-out-able blocks:

        with ExitBlock() as ex1:
            with ExitBlock() as ex2:
                with ExitBlock() as ex3:
                    while True:
                        ex2.exit()
                print 'not displayed'
            print 'execution proceeds here from ex2.exit()'
            while True:
                for x in xrange(sys.maxint):
                    while True:
                        ex1.exit()
            print 'not displayed'
        print 'execution proceeds here from ex1.exit()'

The only danger is bare except (or except BaseException) inside the
block.

-Mike



From jkrukoff at ltgc.com  Tue Dec 26 15:58:46 2006
From: jkrukoff at ltgc.com (John Krukoff)
Date: Tue, 26 Dec 2006 13:58:46 -0700
Subject: some OT: how to solve this kind of problem in our program?
In-Reply-To: <7.0.1.0.0.20061226164403.03e6e568@yahoo.com.ar>
References: 
	<458e4426$0$5286$4c368faf@roadrunner.com>
	<1166958490.785728.52430@h40g2000cwb.googlegroups.com>
	<1166974469.681026.101070@42g2000cwt.googlegroups.com>
	<45906bab$0$27094$4c368faf@roadrunner.com>
	<7.0.1.0.0.20061226164403.03e6e568@yahoo.com.ar>
Message-ID: <1167166726.10841.12.camel@localhost>

On Tue, 2006-12-26 at 17:39 -0300, Gabriel Genellina wrote:
> At Monday 25/12/2006 21:24, Paul McGuire wrote:
> 
> >For example, for all the complexity in writing Sudoku solvers, there are
> >fewer than 3.3 million possible permutations of 9 rows of the digits 1-9,
> >and far fewer permutations that match the additional column and box
> >constraints.  Why not just compute the set of valid solutions, and compare
> >an input mask with these?
> 
> Are you sure? There are 9!=362880 rows of digits 1-9; taking 9 of 
> these at random gives about 10**50 possibilities. Of course just a 
> few match the additional constraints. Maybe you can trivially reduce 
> them (just looking for no dupes on the first column) but anyway its a 
> laaaaarge number... (Or I'm wrong computing the possibilities...)
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Fortunately, somebody has already written a paper on the subject:
http://www.afjarvis.staff.shef.ac.uk/sudoku/sudoku.pdf

It looks like the number is actually rather large, and I'd expect even
with a specialized data structure for compression (probably some kind of
tree with bitwise digit packing?) would not fit in memory on any box I
own.

I would wonder if loading that much data isn't slower than solving the
puzzle.
-- 
John Krukoff 
Land Title Guarantee Company



From fredrik at pythonware.com  Tue Dec 19 17:36:09 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 19 Dec 2006 23:36:09 +0100
Subject: When Closure get external variable's value?
In-Reply-To: <1166565727.745236.26120@a3g2000cwd.googlegroups.com>
References: <1166473333.593246.238580@73g2000cwn.googlegroups.com>	<1166474513.700608.201760@48g2000cwx.googlegroups.com>		<1166542026.913912.82880@t46g2000cwa.googlegroups.com>		<1166544951.721977.281100@t46g2000cwa.googlegroups.com>		<1166556458.780265.147420@80g2000cwy.googlegroups.com>	<4588505d$0$26434$426a74cc@news.free.fr>
	<1166565727.745236.26120@a3g2000cwd.googlegroups.com>
Message-ID: 

Huayang Xia wrote:

> I don't understand why while a nested function perfectly matches the
> definition of closure, it is not closure simply because it is not used
> by external world.

Like so many other computing terms, the word "closure" is used in 
different ways by different people.

Strictly speaking, a closure is simply a function with free variables, 
where the bindings for all such variables are known in advance.  Some 
early languages didn't have "closed" functions; the bindings for free 
variables were left open, and was determined at runtime.  And languages 
that had both "open" and "closed" functions needed some way to 
distinguish between the two, so people started referring to the latter 
as "closures".

But in Python, as well as in most other modern languages, all functions 
are "closed" -- i.e. there are no "open" free variables -- so the use of 
the term has morphed from "a function for which all free variables have 
a known binding" to "a function that can refer to environments that are 
no longer active" (such as the local namespace of an outer function, 
even after that function has returned).  And since *that* is somewhat 
difficult to implement, and programmers don't like to hide things that 
are hard to implement, people still like to use the term to distinguish 
between closed functions of kind 1 and closed functions of kind 2.  As 
in this thread, they sometimes argue that when you're using a closed 
function of kind 2 in a specific way, it's not quite as much of a 
closure as when you use it in another way.  Heck, some people even argue 
that languages that don't support closed functions of kind 3 (a kind 
that Python currently doesn't support) don't really have closures at all.

But as a language user, you can actually forget about all this -- all 
you need to know is that in Python, all functions are closed, and free 
variables bind to *variable names* in lexically nested outer scopes.





From tjgolden at gmail.com  Thu Dec 14 05:09:22 2006
From: tjgolden at gmail.com (Tim Golden)
Date: 14 Dec 2006 02:09:22 -0800
Subject: pwinauto to remote automate a GUI ?
In-Reply-To: 
References: 
	
Message-ID: <1166090962.886844.151220@j72g2000cwa.googlegroups.com>

Tim Golden wrote:

[... snip horrendous company-generated sig/disclaimer ...]

Sorry about that, folks. We've started using a new
server-based sig generation thing so I'll have to start
not sending via company email!

TJG



From jonc at icicled.net  Fri Dec  8 23:33:09 2006
From: jonc at icicled.net (Jonathan Curran)
Date: Fri, 8 Dec 2006 22:33:09 -0600
Subject: How to create a global hotkey?
In-Reply-To: <1165492421.317438.237350@j72g2000cwa.googlegroups.com>
References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com>
Message-ID: <200612082233.10206.jonc@icicled.net>

On Thursday 07 December 2006 05:53, k04jg02 at gmail.com wrote:
> I want to make a Python app that runs in the background, and when a
> user hits a key combination, for a function to run. This sounds simple
> enough, but all of the keypress detecting libraries I can find count on
> you creating a window and then detecting keypresses while that window
> has focus. I want my function to execute when the user presses the
> hotkey anywhere. I searched the PyGTK documentation and found an old
> newsgroup post where someone mentioned the C GTK+ library has it but
> PyGTK does not, PyQT showed no results, not sure where else I should
> look. I'd be willing to use a library that isn't a windowing toolkit --
> I just want to be able to be able to globally detect a keypress. Any
> ideas?

A little bit of googling revealed:

XGrabKey: http://tronche.com/gui/x/xlib/input/XGrabKey.html
Example: http://tigerdyr.wheel.dk/ctwm-archive/1328.html

It's done here in C, hopefully you can do the same with the python module for 
xlib that was mentioned earlier.

- Jonathan

Google = best friend


From fredrik at pythonware.com  Tue Dec 12 14:00:22 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 12 Dec 2006 20:00:22 +0100
Subject: Large files uploading
In-Reply-To: <1165949410.458162.38300@79g2000cws.googlegroups.com>
References: <1165949410.458162.38300@79g2000cws.googlegroups.com>
Message-ID: 

Lad wrote:

> If a user will  upload large files via FTP protocol, must  the  user
> have an FTP client on his computer or is it possible to use a similar
> way to "http form" comunication?

to use any communications protocol (including HTTP), both ends must have 
programs that can talk that protocol...





From robert.kern at gmail.com  Tue Dec 12 09:00:02 2006
From: robert.kern at gmail.com (Robert Kern)
Date: Tue, 12 Dec 2006 08:00:02 -0600
Subject: Sorting Multidimesional array(newbie)
In-Reply-To: 
References: <20061211193104.40fe7985.tartifola@gmail.com>	<1165863508.967414.70350@73g2000cwn.googlegroups.com>		<1165907463.624180.7990@79g2000cws.googlegroups.com>
	
Message-ID: 

Fredrik Lundh wrote:
> also note the OP didn't specify what to do for records where the first 
> column was identical, so I guess a plain sort() call, without any custom 
> compares or mappings, would work as well as the fancier alternatives...

If the OP had lists of lists, yes. However, he seems to be using one of (numpy,
numarray, Numeric). Because of rich comparisons, just using sorted() won't work.
The cheap and cheerful approach would be to convert to lists of lists using
.tolist(), .sort() the list, and then reconstruct the array object. Depending on
the size of the array, that may be just fine.

numpy (and maybe numarray, I'd have to check) has a function lexsort(), which
unfortunately has a confusing interface.


In [2]: lexsort?
Type:           builtin_function_or_method
Base Class:     
Namespace:      Interactive
Docstring:
    lexsort(keys=, axis=-1) -> array of indices. argsort with list of keys.

    Return an array of indices similar to argsort, except the sorting is
    done using the provided sorting keys.  First the sort is done using
    key[0], then the resulting list of indices is further manipulated by
    sorting on key[1], and so forth. The result is a sort on multiple
    keys.  If the keys represented columns of a spreadsheet, for example,
    this would sort using multiple columns (the last key being used for the
    primary sort order, the second-to-last key for the secondary sort order,
    and so on).  The keys argument must be a sequence of things that can be
    converted to arrays of the same shape.


This is the idiomatic way to lexicographically sort an array by columns
equivalent to the .tolist() approach I give above. I usually wrap lexsort() with
these operations so my brain doesn't explode.


In [15]: from numpy import *

In [16]: a = array([[5, 2], [1, 3], [1, 2]])

In [17]: a[lexsort(keys=a.transpose()[::-1])]
Out[17]:
array([[1, 2],
       [1, 3],
       [5, 2]])

-- 
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



From fredrik at pythonware.com  Wed Dec 13 17:02:44 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Wed, 13 Dec 2006 23:02:44 +0100
Subject: How do I edit a PythonWin path to import custom built modules???
In-Reply-To: <1166046193.734274.124160@73g2000cwn.googlegroups.com>
References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com>	<1165850571.131438.185940@l12g2000cwl.googlegroups.com>	<1165912704.390252.184260@n67g2000cwd.googlegroups.com>	<1165917988.141401.195050@16g2000cwy.googlegroups.com>	<1165935598.701360.101390@f1g2000cwa.googlegroups.com>		<1166015447.721253.9680@80g2000cwy.googlegroups.com>	
	<1166046193.734274.124160@73g2000cwn.googlegroups.com>
Message-ID: 

BartlebyScrivener wrote:


> Yup. Did that before. That's what I mean. The d:\\python is there and
> it doesn't come from the PythonPath in my windows registry.

what do you get if you do:

 > python -S
...
 >>> import sys
 >>> sys.path

and then

 >>> import site
 >>> sys.path

?





From Thomas.Ploch at gmx.net  Tue Dec  5 09:55:28 2006
From: Thomas.Ploch at gmx.net (Thomas Ploch)
Date: Tue, 05 Dec 2006 15:55:28 +0100
Subject: Why not just show the out-of-range index?
In-Reply-To: <1165325263.656851.87980@l12g2000cwl.googlegroups.com>
References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com>		<97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com>		<1165216880.864158.256730@80g2000cwy.googlegroups.com>		<1165219968.619509.147990@73g2000cwn.googlegroups.com>	
	<1165325263.656851.87980@l12g2000cwl.googlegroups.com>
Message-ID: <45758860.8040200@gmx.net>

stdazi wrote:
> Usually, when I make some coding mistake (index out of range - in this
> case) I just care to fix the mistake and I usually don't mind to
> inspect by how much the index was overflowed. It really seems like a
> feature that should be embedded in some Python debugger than a feature
> in the interpreter itself.
> 

I read the whole thread and this is more or less the first post which
actually has a good thing to say without saying any bad thing about anyone.

Thomas


From Leo.Kislov at gmail.com  Tue Dec 19 00:02:58 2006
From: Leo.Kislov at gmail.com (Leo Kislov)
Date: 18 Dec 2006 21:02:58 -0800
Subject: urllib.unquote and unicode
References: <1166497058.109088.53120@80g2000cwy.googlegroups.com>
Message-ID: <1166504578.169707.154900@n67g2000cwd.googlegroups.com>


George Sakkis wrote:
> The following snippet results in different outcome for (at least) the
> last three major releases:
>
> >>> import urllib
> >>> urllib.unquote(u'%94')
>
> # Python 2.3.4
> u'%94'
>
> # Python 2.4.2
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0:
> ordinal not in range(128)
>
> # Python 2.5
> u'\x94'
>
> Is the current version the "right" one or is this function supposed to
> change every other week ?

IMHO, none of the results is right. Either unicode string should be
rejected by raising ValueError or it should be encoded with ascii
encoding and result should be the same as
urllib.unquote(u'%94'.encode('ascii')) that is '\x94'. You can consider
current behaviour as undefined just like if you pass a random object
into some function you can get different outcome in different python
versions.

  -- Leo



From rampeters at gmail.com  Tue Dec  5 13:21:58 2006
From: rampeters at gmail.com (johnny)
Date: 5 Dec 2006 10:21:58 -0800
Subject: Multiple FTP download using Muliti thread
In-Reply-To: <1165284311.911998.151460@l12g2000cwl.googlegroups.com>
References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com>
	<1165226193.934418.36660@l12g2000cwl.googlegroups.com>
	<1165277324.677203.107650@l12g2000cwl.googlegroups.com>
	<1165284311.911998.151460@l12g2000cwl.googlegroups.com>
Message-ID: <1165342918.083063.150690@j44g2000cwa.googlegroups.com>

I am getting the following error:

    raise error_temp, resp
error_temp: 421 Unable to set up secure anonymous FTP

Here is the code:

import ftplib, posixpath, threading
from TaskQueue import TaskQueue

def worker(tq):
    while True:
        host, e = tq.get()

        c = ftplib.FTP(host)
        c.connect()
        try:
            c.login()
            p = posixpath.basename(e)
            fp = open('H:/eclipse/workspace/src/ftp_download/' + p,
'wb')
            try: c.retrbinary('RETR %s' % e, fp.write)
            finally: fp.close()
        finally: c.close()

        tq.task_done()

if __name__ == '__main__':
    q = TaskQueue()
    #host = 'ftp.microsoft.com'
    host = 'mysite.com'
    c = ftplib.FTP(host)
    c.connect()
    try:
        #c.login()
        c.login("temp at mysite.com","temppass" )

        #folder = '/deskapps/kids/'
        folder = ''
        for n in c.nlst(folder):
            #if n.lower().endswith('.exe'):
            #    q.put((host, n))
             if n.lower().endswith('.jpg'):
                q.put((host, n))
             elif n.lower().endswith('.jpeg'):
                q.put((host, n))

    finally: c.close()

    numworkers = 4
    for i in range(numworkers):
        t = threading.Thread(target=worker, args=(q,))
        t.setDaemon(True)
        t.start()

    q.join()
    print 'Done.'


Justin Ezequiel wrote:
> johnny wrote:
> > When I run the following script, with host and password and username
> > changed, I get the following errors:
> > raise error_temp, resp
> > error_temp: 421 Unable to set up secure anonymous FTP
> >
> > Dose the host should allow 4 simultaneous login at a time?
> > 
> 
> does it work using ftp.microsoft.com?
> 
> post your code



From philip.armitage at gmail.com  Mon Dec 11 08:56:37 2006
From: philip.armitage at gmail.com (philip.armitage at gmail.com)
Date: 11 Dec 2006 05:56:37 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <1165826008.371063.293080@73g2000cwn.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	
	 <7xac1wr7t9.fsf@ruckus.brouhaha.com>
	
	<1165768221.753809.4270@f1g2000cwa.googlegroups.com>
	<1165826008.371063.293080@73g2000cwn.googlegroups.com>
Message-ID: <1165845397.504922.121720@j44g2000cwa.googlegroups.com>

Juan R. wrote:
> philip.armitage at gmail.com ha escrito:
> > - Lisp is hard to learn (because of all those parenthesis)
>
> I cannot understand why. It is like if you claim that packaging things
> in boxes is difficult to learn.
>
> HTML and XML have more brackets than LISP (usually double) for
> structuring data and everyone has learned HTML.

I think maybe you missed the point I was making.

To make it clearer I'm saying that the arguments that are being made
over and over again against Lisp in this thread have been the
antithesis of my experience since moving from Python to Lisp.

I just prefer personal experience to popular misconceptions :-)

Phil



From sjmachin at lexicon.net  Fri Dec  1 14:03:01 2006
From: sjmachin at lexicon.net (John Machin)
Date: 1 Dec 2006 11:03:01 -0800
Subject: String formatters with variable argument length
In-Reply-To: 
References: 
	<1164932769.210948.289560@f1g2000cwa.googlegroups.com>
	
	<1164936827.570682.325260@j72g2000cwa.googlegroups.com>
	
Message-ID: <1164999781.097741.105830@j72g2000cwa.googlegroups.com>


Peter Otten wrote:
> John Machin wrote:
>
> >> > Fredrik Tolf wrote:
>
> >> > > The thing is, I want to get format strings from the user, and I don't
> >> > > want to require the user to consume all the arguments.
>
> > what's ugly about this:
> > [untested]:
> >
> > def count_format_args(s):
> >     pending = False
> >     count = 0
> >     for c in s:
> >         if c == "%":
> >             # doubled % chars aren't counted
> >             pending = not pending
> >         elif pending:
> >             count += 1
> >             pending = False
> >     return count
> >
> > output = format % arglist[:count_format_args(format)]
>
> Keep in mind, though, that it doesn't take '*' into account:
>
> >>> count_format_args("%*.*f")
> 1
> >>> "%*.*f" % (3,2,1)
> '1.00'

A good point. Adding checking for "*" would make it rather ugly, as "*"
is special only inside a conversion specifier.

>
> And just because I don't think I've seen it before:
>
> >>> count_format_args("%42%")
> 1
> >>> "%42%" % ()
> '                                         %'

Hmmm ... I hadn't seen that before either. I would have said if shown
that input that I could have put in an error check that pending was not
true at the end of the loop, but was relying instead on an exception
from the formatting operator.

Even better: >>> "%-42%" % ()
 '%                                         '

:-)
Before gentle readers consider nominating the Python core dev team to
thedailyWTF.com, they might wish to:
(1) read the Python documentation
(http://docs.python.org/lib/typesseq-strings.html)
[it is not a simple escape mechanism; the second % is a "conversion
type"]
(2) compare those docs carefully with K&R v2 section B1.2 Formatted
Output (pp 243-245)
(3) note that not everything that emanated from Murray Hill NJ obeyed
the Law of Least Astonishment
:-)

Cheers,
John



From cito at online.de  Sun Dec 17 12:12:47 2006
From: cito at online.de (Christoph Zwerschke)
Date: Sun, 17 Dec 2006 18:12:47 +0100
Subject: No latin9 in Python?
In-Reply-To: <458336c2$0$26013$9b622d9e@news.freenet.de>
References:  <457710EE.4090704@v.loewis.de>
	<458299D9.4010503@online.de>
	<458336c2$0$26013$9b622d9e@news.freenet.de>
Message-ID: 

Martin v. L?wis schrieb:
> Christoph Zwerschke schrieb:
>> Shall I proceed writing such a patch? Shall I also add latin0 and l0
>> which are other inofficial aliases?
> 
> Sure, go ahead. I see no need for the latin0/l0 aliases, though: they
> predate the formal adoption of iso-8859-15, and should be phased out
> by now (I'm sure that somebody will provide an example of a software
> that still uses it, but I likely won't find that single example
> convincing).

Ok, I'll add the alias for latin9, the completely missing latin10, and 
will also have a look whether some other things are missing. But 
probably I'll only get round to doing so after the Christmas holidays.

-- Christoph


From mail at microcorp.co.za  Tue Dec 19 00:10:56 2006
From: mail at microcorp.co.za (Hendrik van Rooyen)
Date: Tue, 19 Dec 2006 07:10:56 +0200
Subject: Can a Tkinter GUI check for abort script:
References: <006901c722be$04c74f90$0d7d12ac@kearfott.com>
Message-ID: <012401c72330$d3226ec0$03000080@hendrik>

 Michael Yanowitz  top posted:

>   Presently what happens is that the script takes over and all the buttons on
the GUI disappear
>as the GUI is not given any cpu time to refresh or check if any activity in the
dialog.

Yuk!

you may have to run the script in a thread then, to preserve the GUI mainloop.

Check out the Threading and Thread modules

- Hendrik



From rampeters at gmail.com  Mon Dec 11 20:32:08 2006
From: rampeters at gmail.com (johnny)
Date: 11 Dec 2006 17:32:08 -0800
Subject: AttributeError: Logger instance has no attribute 'setFormatter'
Message-ID: <1165887128.688715.284320@f1g2000cwa.googlegroups.com>

I am getting a log error.  I am running ActiveState Python 2.4.3.  Any
help greatly appreciated.  Here is my code:

file.py
---------

def main()
     setupLogging()
     blah....

def setupLogging():
    global log
    log = logging.getLogger("ftp")
    formatter = logging.Formatter('%(name)-12s: %(levelname)-8s
%(message)s')

    log.setFormatter(formatter)
    log.setLevel(logging.DEBUG)

    fhnd = logging.FileHandler('py_mybase.log')
    fhnd.setLevel(logging.DEBUG)
    log.addHandler(fhnd)

My Error:
    log.setFormatter(formatter)
AttributeError: Logger instance has no attribute 'setFormatter'



From nick at craig-wood.com  Sat Dec  2 05:30:05 2006
From: nick at craig-wood.com (Nick Craig-Wood)
Date: Sat, 02 Dec 2006 04:30:05 -0600
Subject: os.mkdir and mode
References: <1165043870.135812.232530@73g2000cwn.googlegroups.com>
Message-ID: 

vj  wrote:
>  How do I do the following unix command:
> 
>  mkdir -m770 test
> 
>  with the os.mkdir command. Using os.mkdir(mode=0770) ends with the
>  incorrect permissions. 

You mean :-

$ python -c 'import os; os.mkdir("test", 0770)'
$ stat test/
  File: `test/'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 806h/2054d      Inode: 2453906     Links: 2
Access: (0750/drwxr-x---)  Uid: (  518/     ncw)   Gid: (  518/     ncw)
Access: 2006-12-02 09:42:59.000000000 +0000
Modify: 2006-12-02 09:42:59.000000000 +0000
Change: 2006-12-02 09:42:59.000000000 +0000

vs

$ rmdir test
$ mkdir -m770 test
$ stat test/
  File: `test/'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 806h/2054d      Inode: 2453906     Links: 2
Access: (0770/drwxrwx---)  Uid: (  518/     ncw)   Gid: (  518/     ncw)
Access: 2006-12-02 09:43:23.000000000 +0000
Modify: 2006-12-02 09:43:23.000000000 +0000
Change: 2006-12-02 09:43:23.000000000 +0000
$ umask
0022
$

So it looks like python mkdir() is applying the umask where as
/bin/mkdir doesn't.  From man 2 mkdir

       mkdir() attempts to create a directory named pathname.

       The  parameter mode specifies the permissions to use. It is modified by
       the process's umask in the usual way: the permissions  of  the  created
       directory  are  (mode & ~umask & 0777).  Other mode bits of the created
       directory depend on the operating system.  For Linux, see below.

So python follows C rather than shell.  Seems reasonable.

To fix your problem, reset your umask thus :-

$ rmdir test
$ python -c 'import os; os.umask(0); os.mkdir("test", 0770)'
$ stat test
  File: `test'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 806h/2054d      Inode: 2453906     Links: 2
Access: (0770/drwxrwx---)  Uid: (  518/     ncw)   Gid: (  518/     ncw)
Access: 2006-12-02 09:48:04.000000000 +0000
Modify: 2006-12-02 09:48:04.000000000 +0000
Change: 2006-12-02 09:48:04.000000000 +0000
$

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick


From fredrik at pythonware.com  Fri Dec 15 01:36:15 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 15 Dec 2006 07:36:15 +0100
Subject: WHAT is [0] in subprocess.Popen(blah).communicate()[0]
In-Reply-To: <7.0.1.0.0.20061214204357.05993da0@yahoo.com.ar>
References: <1166118046.514892.85360@16g2000cwy.googlegroups.com>		
	<7.0.1.0.0.20061214204357.05993da0@yahoo.com.ar>
Message-ID: 

Gabriel Genellina wrote:


>> I like using pattern matching in these simple cases:
>>
>>   last_line, _ = subprocess.Popen([r"tail","-n 1", "x.txt"],
>>           stdout=subprocess.PIPE).communicate()
> 
> pattern matching???

http://www.haskell.org/tutorial/patterns.html

(the syntax's called "target lists" in Python)





From kay.schluehr at gmx.net  Sun Dec 10 05:56:55 2006
From: kay.schluehr at gmx.net (Kay Schluehr)
Date: 10 Dec 2006 02:56:55 -0800
Subject: oo problem
References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com>
Message-ID: <1165748214.955631.220080@f1g2000cwa.googlegroups.com>

Tool69 schrieb:

> Hi,
> I've got a simple but difficult problem :
>
> Suppose I've got a Paper class, on wich I can draw i.e a rectangle, a
> circle or whatever.
>
> class Paper(...):
>     def __init__(self, paperx, papery):
>         self.paperx = paperx
>         self.papery = papery
>         ....
>     def draw(self, Primitive_Object):
>         ....
> class Rectangle(  ): <--- a Primitive_Object
>     ...
>
> Now, inside my Rectangle class, I need to recover the Paper instance
> who called it (because I need the paper sizes to calculate something).

You can simply pass a paper reference to a rectangle object. But better
you pass only the information to the rectangle that is necessary,
because you decouple the objects this way:

class Rectangle:
    def __init__(self):
         self.paper_coordinates = [0,0]  # default value

class Paper:
     ...
    def draw(self, shape):
         shape.paper_coordinates = self.x, self.y
         shape.draw()
         ...



From atkinw at rpi.edu  Sat Dec  9 22:37:53 2006
From: atkinw at rpi.edu (Bill Atkins)
Date: Sat, 09 Dec 2006 22:37:53 -0500
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>
Message-ID: 

"Paddy"  writes:

> Fast. Very fast!

You hit it on the head.  Interpreted langauges were the efficiency
breakthrough we've all been waiting for.


From atkinw at rpi.edu  Sat Dec  9 15:21:46 2006
From: atkinw at rpi.edu (Bill Atkins)
Date: Sat, 09 Dec 2006 15:21:46 -0500
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06>
	<1165649882.563957.87770@n67g2000cwd.googlegroups.com>
	
	<457abf83.18014323@news.readfreenews.net>
	
	
Message-ID: 

Bill Atkins  writes:

> "every corner of the language"?  Please.  Why are you so post-happy
> when it's quite obvious that you don't know enough about Lisp to
> attack it?

In addition to macros that define classes or methods, a common macro
is the WITH-* macro, which sets up some kind of context, runs the body
inside that context, and then does some cleanup.

For example, my Lisp vendor, LispWorks, provides the macro MP:WITH-LOCK :

(mp:with-lock (*the-big-lock*)
  (do-something-atomic)
  (something-else)
  (almost-odone))

The generated first seizes a process lock called *THE-BIG-LOCK*, runs
the code in the body and then releases the lock.  I never have to
worry that I've taken a lock without releasing it, because LispWorks
has encoded that behaviour into MP:WITH-LOCK (and if they handn't,
this macro is trivial to write).

Now I can tell if I'm keeping a lock around too long because all the
code that appears inside this WITH-LOCK is all the code that I'm
locking.  Further, the generated code is surrounded by an
UNWIND-PROTECT, which means that if an error is raised or anything
abnormal happens in the dynamic scope of the UNWIND-PROTECT, Lisp will
run cleanup code as it flees back up the stack.  So if there is an
error in my code, it does not prevent other processes from seizing
that lock, because it will be released as the error is signaled.

Here is the expansion:

CL-USER 7 > (write (macroexpand '(mp:with-lock (*the-big-lock*)
                                   (do-something-atomic)
                                   (something-else)
                                   (almost-odone)))
                   :pretty t :case :downcase)
(let ((#:g17553 *the-big-lock*))
  (when (mp:process-lock #:g17553)
    (unwind-protect
        (progn (do-something-atomic) (something-else) (almost-odone))
      (mp::in-process-unlock #:g17553))))


From Michael.Coll-Barth at VerizonWireless.com  Fri Dec  1 13:23:17 2006
From: Michael.Coll-Barth at VerizonWireless.com (Michael.Coll-Barth at VerizonWireless.com)
Date: Fri, 1 Dec 2006 13:23:17 -0500
Subject: v2.3, 2.4, and 2.5's GUI is slow for me
In-Reply-To: 
Message-ID: <20061201183349.B5B7A1E400E@bag.python.org>



> -----Original Message-----
> From: John Salerno

> 
> I don't use IDLE too much anymore, just for quick tests, but 

Just curious.  I have tried IDLE, but stopped using it after going through a few of the tutorials.  I just type things in at the 'python' prompt, regardless of which platform I am working on; Linux, AIX or Windows.  But, then again, my code winds up in a batch process or part of a web app.  

Is there something cool I am missing?
















The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.



From bearsprite at gmail.com  Tue Dec 12 23:47:35 2006
From: bearsprite at gmail.com (bearsprite)
Date: 12 Dec 2006 20:47:35 -0800
Subject: how can i write a hello world in chinese with python
In-Reply-To: <1165982024.978824.146920@n67g2000cwd.googlegroups.com>
References: <1165982024.978824.146920@n67g2000cwd.googlegroups.com>
Message-ID: <1165985255.490054.290680@80g2000cwy.googlegroups.com>

try unicode?

"kernel1983 ???
"
> I'm try to build a bundle on OS X, so I write a simple python script
> for a test:
>
> #!/usr/bin/env python
> import EasyDialogs
> EasyDialogs.Message("Hello,Mac!")
>
>
> This runs OK,but when I try to replace "Hello,Mac!" with chinese, it
> can't be display rightly.
> Then I tried some way else:
>
> #!/usr/bin/env python
> import EasyDialogs
> EasyDialogs.Message("\xe4\xb8\xad")
>
> It doesn't work!
>
> As I know mac is unicode based,how can I display chinese on the screen?



From justask at acme.com  Sun Dec 17 21:57:09 2006
From: justask at acme.com (Vincent Delporte)
Date: Mon, 18 Dec 2006 03:57:09 +0100
Subject: Good Looking UI for a stand alone application
References: <4584531c$0$13533$426a74cc@news.free.fr>
	<1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com>
	
	<4585df6e$0$11500$426a74cc@news.free.fr>
Message-ID: 

On Mon, 18 Dec 2006 01:23:10 +0100, Christophe Cavalaria
 wrote:
>They use QT. Back to read the first part of your post.

It doesn't make much difference: 
- QT is big, so even small apps carry a lot of baggage
- by not using the native widgets, you're dependent on that layer to
keep up with changes in the look & feel of the platform (eg. XP's
widgets that look different from previous widgets).

Bottom line: GUI apps are better off extracting the maximum amount of
logic into OS-agnostic code, and then rewrite the GUI for each
platform.

Even better: Considering that Windows has a 95% market share, make
doubly-sure that it makes financial sense to provide a cross-platform
GUI application (the server can be written in text mode, and can then
be available for multiple OS's with no major problem).


From gagsl-py at yahoo.com.ar  Fri Dec 22 20:38:35 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Fri, 22 Dec 2006 22:38:35 -0300
Subject: let me simplify my question on scope of vars
In-Reply-To: <87ejqrqu8n.fsf@pyenos.pyenos.org>
References: <877iwjcttj.fsf@pyenos.pyenos.org>
	<87vek3be9e.fsf@pyenos.pyenos.org>
	<87ejqrqu8n.fsf@pyenos.pyenos.org>
Message-ID: <7.0.1.0.0.20061222223643.05cd6c10@yahoo.com.ar>

At Friday 22/12/2006 22:24, Pyenos wrote:

> > > "code"
> > > var=1
> > > class CLASS:
> > >         def METHOD1:
> > >                 def METHOD2:
> > >                         var+=var
> > >                 return var
> > >                 METHOD2()       #line8
> > >         return var
> > > METHOD1()                       #line10
> > > "end code"
> > >
> > > Q1: does class CLASS inherit var=0 from line1?
> > yes.
> > > Q2: does def METHOD1 inherit var=0 from line1?
> > no.
> > > Q3: does def METHOD2 inherit var=0 from line1?
> > no.
> > > Q3: does line8 return '2'?
> > no. will get unreferenced var error.
> > > Q4: does line10 return '2\n2'?
> > no. will get unreferenced var error.
>
>Now I know that Q1 is also no, since var=1 from line 2 is a global
>variable and I have not declared it as global inside def METHOD2. so
>var within def METHOD2 is a different variable to the global variable var.

Read the Python Pitfalls I've send some minutes ago, and the tutorial 
(specially http://docs.python.org/tut/node11.html#scopes) and then 
re-answer your own questions.


-- 
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 



From george.sakkis at gmail.com  Fri Dec  8 11:50:41 2006
From: george.sakkis at gmail.com (George Sakkis)
Date: 8 Dec 2006 08:50:41 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165594621.136524.198600@80g2000cwy.googlegroups.com>
	
Message-ID: <1165596641.245385.113090@f1g2000cwa.googlegroups.com>

Andr? Thieme wrote:

> On the other hand can I see difficulties in adding macros to Python,
> or inventing a new object system, or adding new keywords without
> changing the sources of Python itself.

Actually, an even bigger difficulty is the rejection of programmable
syntax by Guido, both for the near and distant future:

"Programmable syntax is not in Python's future -- or at least it's not
for Python 3000. The problem IMO is that everybody will abuse it to
define their own language. And the problem with that is that it will
fracture the Python community because nobody can read each other's code
any more."

http://mail.python.org/pipermail/python-3000/2006-April/000286.html.


George



From cameron.walsh at gmail.com  Thu Dec  7 21:21:49 2006
From: cameron.walsh at gmail.com (Cameron Walsh)
Date: Fri, 08 Dec 2006 11:21:49 +0900
Subject: Logging output from python
In-Reply-To: <1165543315.696699.291910@j44g2000cwa.googlegroups.com>
References: <1165543315.696699.291910@j44g2000cwa.googlegroups.com>
Message-ID: 

Barry wrote:
> Hi, guys
> 
> Basiclly, it is automated testing system. There is a main python script
> that handles the testing campagin. This main script will call another
> script that will in turn runs a few hundered individual python scripts.
> 
> 
> Here is my problem. I want to log everything displayed in the screen
> after I start the main python script. Things include unhandled
> exceptions , message from print statement and other sources.
> Basically, if it is displayed on the screen, I want to log it..
> 
> 
> It might not be a pythons specific problem. Does anyone know a small
> tool does that job?
> 
> 
> Thanks.
> 

If it's on linux you can just redirect the screen output to a file:

python initialfile.py 1>stdout.txt 2>stderr.txt

or if you want standard out and standard error to go to the same file:

python initialfile.py 1>output.txt 2>output.txt

or if you don't want to see anything on standard error:

python initialfile.py 1>output.txt 2>/dev/null


As for windows, I'll test it now...

It turns out you can at least redirect the output to a file, I'm not
sure what it does with standard error or even if it exists or not.

python initialfile.py > output.txt

should work.


Hope it helps,

Cameron.


From ptmcg at austin.rr.com  Thu Dec 21 06:54:19 2006
From: ptmcg at austin.rr.com (Paul McGuire)
Date: 21 Dec 2006 03:54:19 -0800
Subject: Regexp Neg. set of chars HowTo?
In-Reply-To: 
References: 
Message-ID: <1166702058.983049.261870@79g2000cws.googlegroups.com>


On Dec 20, 7:40 am, durumdara  wrote:
> Hi!
>
> I want to replace some seqs. in a html.
> Let:
> a-
> b
> = ab
>
> but:
> xxx -
> b
> must be unchanged, because it is not word split.
>
> I want to search and replace with re, but I don't know how to neg. this
> set ['\ \n\t'].
>
> This time I use full set without these chars, but neg. is better and
> shorter.
>
> Ok, I can use [^\s], but I want to know, how to neg. set of chars.
> sNorm1= '([^[\ \t\n]]{1})\-\\n' - this is not working.
>
> Thanks for the help:
> dd
>
> sNorm1= '([%s]{1})\-\\n'
> c = range(0, 256)
> c.remove(32)
> c.remove(13)
> c.remove(10)
> c.remove(9)
> s = ["\\%s" % (hex(v).replace('00x', '')) for v in c]
> sNorm1 = sNorm1 % ("".join(s))
> print sNorm1
>
> def Normalize(Text):
>
>     rx = re.compile(sNorm1)
>     def replacer(match):
>         return match.group(1)
>     return rx.sub(replacer, Text)
>
> print Normalize('a -
\nb') > print Normalize('a-
\nb') > sys.exit() It looks like you are trying to de-hyphenate words that have been broken across line breaks. Well, this isn't a regexp solution, it uses pyparsing instead. But I've added a number of other test cases which may be problematic for an re. -- Paul from pyparsing import makeHTMLTags,Literal,Word,alphas,Suppress brTag,brEndTag = makeHTMLTags("br") hyphen = Literal("-") hyphen.leaveWhitespace() # don't skip whitespace before matching this collapse = Word(alphas) + Suppress(hyphen) + Suppress(brTag) \ + Word(alphas) # define action to replace expression with the word before hyphen # concatenated with the word after the
tag collapse.setParseAction(lambda toks: toks[0]+toks[1]) print collapse.transformString('a -
\nb') print collapse.transformString('a-
\nb') print collapse.transformString('a-
\nb') print collapse.transformString('a-
\nb') print collapse.transformString('a-
\nb') From michele.simionato at gmail.com Mon Dec 11 07:35:52 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 11 Dec 2006 04:35:52 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xodqa7hpf.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> <457c42a3$0$49196$14726298@news.sunsite.dk> <7xodqbpqun.fsf@ruckus.brouhaha.com> <457c92c7$0$49195$14726298@news.sunsite.dk> <7x1wn7vx5b.fsf@ruckus.brouhaha.com> <457d3cdc$0$49205$14726298@news.sunsite.dk> <7xodqa7hpf.fsf@ruckus.brouhaha.com> Message-ID: <1165840551.975418.117360@j44g2000cwa.googlegroups.com> Paul Rubin wrote: > "Alex Mizrahi" writes: > > > "Programming Languages:Application and Interpretation" > > Shriram Krishnamurthi > > Brown University > This book doesn't seem to be online. http://cs.brown.edu/~sk/Publications/Books/ProgLangs/ Michele Simionato From sjmachin at lexicon.net Tue Dec 5 14:26:49 2006 From: sjmachin at lexicon.net (John Machin) Date: 5 Dec 2006 11:26:49 -0800 Subject: Ensure a variable is divisible by 4 In-Reply-To: <87r6ve8muc.fsf@rudin.co.uk> References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> <1165323726.255327.11530@j72g2000cwa.googlegroups.com> <457578D6.9080902@mxm.dk> <87r6ve8muc.fsf@rudin.co.uk> Message-ID: <1165346809.134538.313600@79g2000cws.googlegroups.com> Paul Rudin wrote: > Max M writes: > > > geskerrett at hotmail.com skrev: > >> Nick Craig-Wood wrote: > >>> geskerrett at hotmail.com wrote: > >>>> I am sure this is a basic math issue, but is there a better way to > >>>> ensure an int variable is divisible by 4 than by doing the following; > >>>> > >>>> x = 111 > >>>> x = (x /4) * 4 > > > > X *= 4 > > > > ;-) > > > > > x=4 > > :) Ensure x is divisible by *any* non-zero integer: x = 0 :-O From __peter__ at web.de Sat Dec 2 03:52:39 2006 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Dec 2006 09:52:39 +0100 Subject: os.mkdir and mode References: <1165043870.135812.232530@73g2000cwn.googlegroups.com> Message-ID: vj wrote: > How do I do the following unix command: > > mkdir -m770 test > > with the os.mkdir command. Using os.mkdir(mode=0770) ends with the > incorrect permissions. mkdir() works just like its C equivalent, see http://docs.python.org/dev/lib/os-file-dir.html: "Where it is used, the current umask value is first masked out." Use os.chmod() after os.mkdir() to get the desired permissions. Peter From basti.wiesner at gmx.net Wed Dec 27 14:41:11 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 27 Dec 2006 20:41:11 +0100 Subject: getting a process's PID References: <20061227102939.L20663@eris.io.com> Message-ID: eldorado typed > Hello, > > I am trying to get python to give me the PID of a process (in this > case > HUB). I have it working, except for the fact that the output includes > \012 (newline). Is there a way to ask python not to give me a > newline? > > Python 1.4 (Oct 14 1997) [C] > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>> import os >>>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 >>>> }'") h = g.readlines() >>>> g.close() >>>> h > ['87334\012'] > > Thanks in advanced for any guidance. Well, you could do everything in python itself, without using grep and awk at all: >>>> g = os.popen("ps -e -o pid,command") >>>> for line in g.readlines(): >>>> if 'HUB' in line: >>>> pid = line.strip().split(' ')[0] >>>> break >>>> print pid -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From Carl.Wolff at imtech.nl Tue Dec 5 16:55:20 2006 From: Carl.Wolff at imtech.nl (Carl.Wolff at imtech.nl) Date: Tue, 5 Dec 2006 22:55:20 +0100 Subject: Copy vs Deepcopy in multithreaded contexts Message-ID: An HTML attachment was scrubbed... URL: From hong.file at gmail.com Mon Dec 4 01:38:11 2006 From: hong.file at gmail.com (progman) Date: 3 Dec 2006 22:38:11 -0800 Subject: RAD for python Message-ID: <1165214291.653950.200420@j72g2000cwa.googlegroups.com> is there a VB-alike tool for python to create forms?? From scott.daniels at acm.org Tue Dec 26 15:43:50 2006 From: scott.daniels at acm.org (Scott David Daniels) Date: Tue, 26 Dec 2006 12:43:50 -0800 Subject: Splitting lines from a database query In-Reply-To: <459183eb$0$9775$afc38c87@news.optusnet.com.au> References: <45910d4d$0$16553$afc38c87@news.optusnet.com.au> <459183eb$0$9775$afc38c87@news.optusnet.com.au> Message-ID: <45917f40$1@nntp0.pdx.net> Peter Machell wrote: > ZeD wrote: > > Thanks very much ZeD. This will do what I need to. > The next step is to do some regex on the phone number to ensure it's > local and correct. How can I split these up so each value has a key? Well, you should try that, unless you intend to get the newsgroup to write your code for you. Come back with your efforts and any problems you have with them. --Scott David Daniels scott.daniels at acm.org From g.brandl-nospam at gmx.net Thu Dec 7 08:17:12 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Thu, 07 Dec 2006 13:17:12 +0000 Subject: Common Python Idioms In-Reply-To: <1165493298.205945.162430@n67g2000cwd.googlegroups.com> References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> Message-ID: Stephen Eilert wrote: > Hendrik van Rooyen escreveu: > >> wrote: >> >> > Peter> Bjoern Schliessmann wrote: >> > >> Wouldn't be "if k in d.keys()" be the exact replacement? >> > >> > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less >> > Peter> (constant) overhead for the function call. 'k in d.keys()' on the >> > Peter> other hand creates a list of keys which is then searched linearly >> > Peter> -- about the worst thing you can do about both speed and memory >> > Peter> footprint. > > I've always used has_key(), thinking it was the only way to do it. > Given that Python says that "There Should Be Only One Way to Do It", I > didn't bother searching for alternatives. > > Is there a list somewhere listing those not-so-obvious-idioms? I've > seen some in this thread (like the replacement for .startswith). > > I do think that, if it is faster, Python should translate > "x.has_key(y)" to "y in x". How and when should it do that? Georg From joshbloom at gmail.com Fri Dec 1 12:04:43 2006 From: joshbloom at gmail.com (Josh Bloom) Date: Fri, 1 Dec 2006 10:04:43 -0700 Subject: client/server design and advice In-Reply-To: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> References: <1164984757.891987.46210@n67g2000cwd.googlegroups.com> Message-ID: You may also want to take a look at Erlang http://www.erlang.org/ for some ideas of how to do distributed programming. -------------- next part -------------- An HTML attachment was scrubbed... URL: From JShrager at gmail.com Sat Dec 9 12:39:10 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 9 Dec 2006 09:39:10 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165627684.709241.86340@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165627684.709241.86340@16g2000cwy.googlegroups.com> Message-ID: <1165685950.758858.18960@n67g2000cwd.googlegroups.com> Carl Banks wrote: > JShrager at gmail.com wrote: > > Okay, since everyone ignored the FAQ, I guess I can too... > [snip] > > What Python has is stupid slogans > > ("It fits your brain." "Only one way to do things.") and an infinite > > community of flies that, for some inexplicable reason, believe these > > stupid slogns. > > IOW, you posted the FAQ so you could appear to have highest moral > ground, then you ignore your own advice and promptly head to the very > lowest ground with ad hominem insults. You're right, in part: My implicitly linking Python's pros or cons with its stupid marketing hype is, I think, an ad hominem argument. But I don't see a moral issue here; the purpose of posting the FAQ was merely to try to stop the fight. It failed. Regardless, there was some content in my post which you have not addressed: To wit: 1. Lisp is the only industrial strength language with pure compositionality, and that this makes it suprior to Python. We don't have to debate this because it's being debated elsewhere in this thread. 2. Ruby, which is closer to Lisp than Python, is beginning to eat Python's lunch. We don't have to debate this either because George has kindly gave support to it through posting a survey that made this point quite nicely; Thanks, George! :-) BTW, for the record, I don't have anything particularly against Python aside from its stupid marketing hype and a bit of jealousy over those flies building libraries which I wish we had in Lisp. I've made the choice uncountable times between PERL, Python, and Tcl when I didn't have Lisp as an option, and I have always chosen Python in these cases, even though I can program in any of these. (Although I'm probably going to start using Ruby instead of Python in these cases, but I'm not really expert in it yet.) (Actually, in many cases I can get away with Emacs keyboard macros where others would program in PERL or Python, although not always.) From Thomas.Ploch at gmx.net Sun Dec 24 11:22:36 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Sun, 24 Dec 2006 17:22:36 +0100 Subject: Merry Christmas and a happy new year! Message-ID: <458EA94C.5010101@gmx.net> I wish everybody a merry Christmas and a happy new year. Have a good and beautiful new year. Thomas From bj_666 at gmx.net Mon Dec 11 08:23:00 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Mon, 11 Dec 2006 14:23:00 +0100 Subject: Pb ReportLab (ttfonts.py) References: <457d4ba5$0$5067$ba4acef3@news.orange.fr> Message-ID: In <457d4ba5$0$5067$ba4acef3 at news.orange.fr>, M?ta-MCI wrote: > Hi! > > I try to generate PDF from Python 2.5 + ReporLab_lib, and, I have: > > C:\Python25\reportlab\pdfbase\ttfonts.py:407: DeprecationWarning: struct > integer overflow masking is deprecated > stm.write(pack(">LLL", checksum, offset, len(data))) > C:\Python25\reportlab\pdfbase\ttfonts.py:419: DeprecationWarning: struct > integer overflow masking is deprecated > stm.write(pack('>L', checksum)) Does the PDF generation work? Those are just warnings. Ciao, Marc 'BlackJack' Rintsch From george.sakkis at gmail.com Mon Dec 4 13:11:48 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 4 Dec 2006 10:11:48 -0800 Subject: Factory pattern implementation in Python References: <1165250357.794022.87520@16g2000cwy.googlegroups.com> <1165252406.405431.294040@79g2000cws.googlegroups.com> <1165253685.341911.60170@79g2000cws.googlegroups.com> Message-ID: <1165255908.636770.108420@l12g2000cwl.googlegroups.com> Romulo A. Ceccon wrote: > George Sakkis wrote: > > > If you actually intend to > > 1) name your Event subclasses Evt1, Evt2, ... EvtN and not give more > > descriptive (but unrelated to the magic event number) names > > No, those names are just an example. The actual classes have > descriptive names. Even then, I'd prefer a naming convention plus a global Event registry than relying on inspect, both for implementation and (mostly) documentation reasons. It's good if a human can browse through a list of a few dozen names and immediately know that CamelCasedNameEndingWithEvent is an Event subclass. It's also good to be able to find in one place the explicit mapping of magic numbers to classes rather than searching in the whole file (or worse, multiple files) for it. YMMV. George From martin at v.loewis.de Fri Dec 29 19:47:45 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 30 Dec 2006 01:47:45 +0100 Subject: xml bug? In-Reply-To: <45943b34$0$302$426a74cc@news.free.fr> References: <4594130c$0$318$426a74cc@news.free.fr> <45941780$1@nntp.zianet.com> <45943b34$0$302$426a74cc@news.free.fr> Message-ID: <4595B731.6040204@v.loewis.de> Imbaud Pierre schrieb: > But python.org was the right entry point, it sent me to the bug > tracker: http://sourceforge.net/tracker/?group_id=5470&atid=105470 > Its a bit short on explanations... And I found unsolved issues, > 3 years old! That's true, and likely to grow. Contributions are welcome! Regards, Martin From devincyu at gmail.com Wed Dec 13 20:27:28 2006 From: devincyu at gmail.com (Chao) Date: 13 Dec 2006 17:27:28 -0800 Subject: speed of python vs matlab. In-Reply-To: References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> Message-ID: <1166059648.320257.187310@j72g2000cwa.googlegroups.com> My Bad, the time used by python is 0.46~0.49 sec, I tried xrange, but it doesn't make things better. import time tic = time.time() a = 1.0 array = range(1000) for i in array: for j in array: a = a + 0.1 toc = time.time() print toc-tic,' has elapsed' used by matlab is 0.012sec tic a = 1; for i=1:1000 for j=1:1000 a = a + 1; end end toc used by ruby is 0.94~0.96sec a = 1 start = Time.now() 1000.times do 1000.times do a = a + 1 end end finish = Time.now() puts finish - start Andrew Sackville-West wrote: > On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote: > > I've been trying to develop some numerical codes with python, however > > got disappointed. > > > > A very simple test, > > > > a = 1.0 > > > > for i in range(1000): > > for j in range(1000): > > a = a+1 > > > > unfortunately, it took 4.5 seconds to finish(my machines is fine. P4 > > 3.0G, 1G RAM, it varies according to machine configuration, but should > > be in the same level) > > somethings not right there. > > andrew at debian:~$ cat pytimetest.py > a=1.0 > for i in range (1000): > for j in range (1000): > a=a+1 > > > andrew at debian:~$ time python pytimetest.py > > real 0m0.534s > user 0m0.528s > sys 0m0.000s > > > andrew at debian:~$ cat /proc/cpuinfo | grep name > model name : Intel(R) Celeron(R) CPU 2.53GHz > > andrew at debian:~$ uname -a > Linux debian 2.6.18-3-686 #1 SMP Mon Dec 4 16:41:14 UTC 2006 i686 > GNU/Linux > > A > > --7AUc2qLy4jB3hD7Z > Content-Type: application/pgp-signature > Content-Disposition: inline; > filename="signature.asc" > Content-Description: Digital signature > X-Google-AttachSize: 190 From kent at kentsjohnson.com Mon Dec 25 11:17:21 2006 From: kent at kentsjohnson.com (Kent Johnson) Date: Mon, 25 Dec 2006 16:17:21 GMT Subject: One module per class, bad idea? In-Reply-To: <1166817152.414154.151390@42g2000cwt.googlegroups.com> References: <1165916254.499121.62470@73g2000cwn.googlegroups.com> <1165951049.090837.145390@73g2000cwn.googlegroups.com> <1165964967.940454.74490@73g2000cwn.googlegroups.com> <1166817152.414154.151390@42g2000cwt.googlegroups.com> Message-ID: Carl Banks wrote: > Kent Johnson wrote: >> Carl Banks wrote: >>> Now, I think this is the best way to use modules, but you don't need to >>> use modules to do get higher-level organization; you could use packages >>> instead. It's a pain if you're working on two different classes in the >>> same system you have to keep switching files; but I guess some people >>> prefer to switch files rather than to scroll for some reason. >> That would be me. I strongly prefer to switch files rather than scroll. >> I use an editor that makes it easy to switch files. For me it is much >> easier to switch between files than to scroll between two parts of a >> file, and I don't lose my place when I switch back. I like to be able to >> see things side by side. > > Man, I don't know you do it. > > Say I'm sitting there concentrating on programming something, and I see > that I'll have to make a change in another file. All of a sudden, I > have to recall some filename out of thin air. Totally breaks my train > of thought, sometimes I space out trying to think of it because I have > to cold-start an entirely different part of my brain. It's less of a > mental distraction to just scroll. But then to go back to where you were, you have to scroll back and find your place. For me, just a click or keystroke to restore the last file with the cursor or selection exactly where I left it. And if I am going back and forth between the two, each switch is equally easy after the first (opening the file). > (BTW, any decent editor will let you view different positions of the > same file side-by-side.) Right, at a cost of showing you half as much of the one you care about. Anyway, I'm not trying to convince anyone to change, just pointing out that there are different styles of editing that make sense to those who use them, if not to outside observers ;-) Kent From bernard.chhun at gmail.com Mon Dec 11 07:54:04 2006 From: bernard.chhun at gmail.com (Bernard) Date: 11 Dec 2006 04:54:04 -0800 Subject: need guidance on sending emails with attachment with python. In-Reply-To: References: Message-ID: <1165841644.575882.98390@16g2000cwy.googlegroups.com> here's the function I've been using for while :P import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.Utils import COMMASPACE, formatdate from email import Encoders def sendMail(arrRecipients, sender, subject, message, files=[]): """ Sends email with attachements """ # SMTP address smtpserver = '' # provide a smtp here in string format # authentification section AUTHREQUIRED = 0 # if you need to use SMTP AUTH set to 1 smtpuser = '' # for SMTP AUTH, set SMTP username here smtppass = '' # for SMTP AUTH, set SMTP password here # Building the body of the email mssg = MIMEMultipart() mssg['From'] = sender mssg['To'] = COMMASPACE.join(arrRecipients) mssg['Date'] = formatdate(localtime=True) mssg['Subject'] = subject mssg.attach( MIMEText(message) ) # attachments for file in files: part = MIMEBase('application', "octet-stream") part.set_payload( open(file,"rb").read() ) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file)) mssg.attach(part) session = smtplib.SMTP(smtpserver) if AUTHREQUIRED: session.login(smtpuser, smtppass) smtpresult = session.sendmail(sender, arrRecipients, mssg.as_string()) if smtpresult: errstr = "" for recip in smtpresult.keys(): errstr = """Could not delivery mail to: %s Server said: %s %s %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr) raise smtplib.SMTPException, errstr krishnakant Mane a ?crit : > hello, > I am a bit confused. > I want to make a program that will take some data from a database and > make a string of text. and send it to the respective email id of a > person. > next I also want to send an attachment of a photo along with the email. > I will be required to make this program run on windows xp. > can some one guide me as to how I can achieve this? > what I will need on windows to send emails? > I believe yahoo, gmail, rediff and msn supports pop3 and smtp? > correct me if I am wrong on this. > secondly what library is used on windows to do this? > I know there must be python libraries to do this, > but apart from that I don't know what all I will need on my windows > machine to send emails to mostly yahoo, gmail and msn. > Please give me some idea about it. > Krishnakant. From aboudouvas at panafonet.gr Mon Dec 4 17:03:04 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 4 Dec 2006 14:03:04 -0800 Subject: decorators question In-Reply-To: References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> <457476E6.5000603@youjoy.org> Message-ID: <1165269784.394649.7940@l12g2000cwl.googlegroups.com> At first, i am coming from another (language) programming world (C# mainly) and i hope you understand my wonders. Ok then, you tell me that the interpreter always execute the code in a module...If there are only def declarations in the module and no code to invoke them it does not execute anything. It must have a body (a call to a(some) method(s)) so it can execute something, right ?? In Soni's example (Soni thanks for the code), it indeed prints "called foo" but if i remove the @foo statement, as i see right now in the debugger, it does not execute anything. I recap: if i put only functions declarations on a .py file, like these: def A(): print "a" def B(): print "b" def C(): print "c" and run the program, nothing happens, nothing executed. I have to put a statment like print A() or b() to cause code execution. But if i simple declare a decorator for one function, like the one that Soni gave me, then it caused the deco function to execute. Why is that ?? On Dec 4, 9:46 pm, Soni Bergraj wrote: > There was a copy-and-paste error with my last message. Better try this > for foobar.py: > > def foo(f): > print "called foo" > return 'some text' > @foo > def bar(): > print "called bar" > > -- > Soni Bergrajhttp://www.YouJoy.org/ From jpellerin at gmail.com Tue Dec 19 10:33:03 2006 From: jpellerin at gmail.com (jpellerin+nose@gmail.com) Date: 19 Dec 2006 07:33:03 -0800 Subject: python-hosting.com projects: dead? References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> Message-ID: <1166542383.019580.185960@73g2000cwn.googlegroups.com> Fredrik Lundh wrote: > have you tried mailing webfaction instead of ranting on the usenet? I did. I didn't get a reply within minutes (indeed not until this morning), so I posted a public message to try to find out if anyone knew what was going on -- and also to warn other people whose projects might have suddenly disappeared. As of this morning my project is back online, so my thanks to python hosting/webfaction for that. I'm very grateful to them for the great free service they have provided. I'm sorry that they are getting killed with spam, but I'm also sorry that they chose to handle the problem in the way that they did. I had no way of knowing when I'd have access to my svn repository and tickets again. I'm sure you can understand why I was dismayed by this and why, unfortunately, I'll never be comfortable trusting my data to them again. JP From chris.cavalaria at free.fr Mon Dec 4 12:17:46 2006 From: chris.cavalaria at free.fr (Christophe) Date: Mon, 04 Dec 2006 18:17:46 +0100 Subject: python Noob - basic setup question / problem In-Reply-To: References: Message-ID: <45745849$0$26318$426a74cc@news.free.fr> Lilavivat a ?crit : > Running SUSE 10.1 on an AMD64. When I try and run a python program I get > the following error: > > /usr/bin/python2: bad interpreter: No such file or directory > > "which python" gives me "/usr/local/bin/python" > > "which python2.4" gives me "/usr/local/bin/python2.4" > > But /usr/bin/python is symlinked to python2.4 "python -> python2.4" > > "which python2" and nothing comes up. > > Basically I have no idea what's going on... help please! > > Thanks, > SETH Fault of the Python program : it hardcodes that the Python interpreter is /usr/bin/python2 Check the first line of the executable ( I bet it is a simple text file so go away and edit it with emacs/vim/joe/ed ... ). It should be ( with maybe a few spaces here and there ) : #!/usr/bin/python2 replace it with : #!/usr/bin/python From piet at cs.uu.nl Mon Dec 25 17:20:56 2006 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 25 Dec 2006 23:20:56 +0100 Subject: Elliptic Curve Library References: <1166886752.656666.287470@80g2000cwy.googlegroups.com> Message-ID: >>>>> "Mike Tammerman" (MT) wrote: >MT> Hi, >MT> I need an elliptic curve library that can be used by python. I googled >MT> but couldn't find a one. I'll appreciate, if you could show me. OpenSSL contains elliptic curve stuff (donated by SUN). M2Crypto is a Python interface to SSL. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From bdesth.quelquechose at free.quelquepart.fr Thu Dec 14 12:31:55 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 14 Dec 2006 18:31:55 +0100 Subject: Writing and reading variables to/from flat file In-Reply-To: <84548$45816e6c$4275d90a$16465@FUSE.NET> References: <84548$45816e6c$4275d90a$16465@FUSE.NET> Message-ID: <458184ed$0$22013$426a74cc@news.free.fr> Kevin Walzer a ?crit : > I want to write some variables (user preferences, specifically) to a > text file and then read the values from that file. http://docs.python.org/lib/module-ConfigParser.html From address.good.until.2006.dec.22 at justmail.de Mon Dec 11 13:52:17 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Mon, 11 Dec 2006 19:52:17 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano schrieb: > Yes. But you can't redefine 1+2 in Python, at least not without hacking > the interpreter. Can you redefine (+ 1 2) in Lisp? It is possible as was pointed out. If anyone would do it, he/she would do it inside a package. Then you would write: (package:+ 1 2) So in real world programs there is no danger. In Python I could just say def list(): return 30 and won't get a warning. In Lisp I would at least have to shadow + explicitely. In Python it can't happen because + is not a function. And what do you do if you want to pass + as a HOF? Andr? -- From kkylheku at gmail.com Wed Dec 13 01:32:03 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 12 Dec 2006 22:32:03 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <1165991523.013767.224630@73g2000cwn.googlegroups.com> Bill Atkins wrote: > (Why are people from c.l.p calling parentheses "brackets"?) Because that's what they are often called outside of the various literate fields. From sjdevnull at yahoo.com Fri Dec 1 20:17:00 2006 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 1 Dec 2006 17:17:00 -0800 Subject: python vs java & eclipse In-Reply-To: <1165008943.818877.315360@80g2000cwy.googlegroups.com> References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <45701422.4050206@gmx.net> <1165008224.116326.36580@79g2000cws.googlegroups.com> <1165008943.818877.315360@80g2000cwy.googlegroups.com> Message-ID: <1165022220.677130.104030@l12g2000cwl.googlegroups.com> Amir Michail wrote: > sjdevnull at yahoo.com wrote: > > ... > > > > Is there anything _useful_ that it'll bring that a good editor doesn't? > > e.g. in vim I do get > > * automatic syntax checking (if I type "if a=1:" and hit enter, it'll > > immediately highlight the syntax error) > > * omni-completion (because Intellisense is trademarked) > > * refactoring (with BicycleRepairMan integration) > > * folding (which is more important than the above 3 combined, IMO) > > * online help (typing cmp( gives me the docstring for cmp in the status > > line, F1 to view the whole thing) > > > > As well as all the basics (tags/class browser/good regex support/syntax > > highlighting/autoindent/source control integration/etc). > > > > I'm not trolling here, I'm looking for interesting new features I can > > steal. > > How about we try to find some papers on the subject? Thanks. Seems a bit high-level to be very useful, and the plethora of examples around "self encapsulate field" seem inapplicable, but it makes me wonder if there's anything to be gained by integrating the vim refactoring support with the Vim 7 undo branches. From andrea.gavana at gmail.com Fri Dec 1 08:13:57 2006 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Fri, 1 Dec 2006 18:13:57 +0500 Subject: PythonWin And Excel Problem Message-ID: Hi All, I am having some problems in running a very simple python script, which prints some numbers in an Excel spreadsheet. The numbers are stored in a list. I know that the numbers are different (random generated), but when I open the Excel file I get a column of data with all the numbers equal to the first item in the python list. I attach a very simple script that reproduces the problem. I am using Python 2.5, PythonWin build 210, Windows XP. Am I missing something? Thank you for every hint. import os import random from win32com.client import Dispatch therand = [] for ii in xrange(10): therand.append(random.random()) xlsapp = Dispatch("Excel.Application") wb = xlsapp.Workbooks.Add() xlsapp.Worksheets.Item(2).Delete() xlsapp.Worksheets.Item(1).Delete() sheet = wb.Sheets[0] sheet.Name = "Data" sheet.Range("A1:A10").Value = therand excelfile = "C:/HelloWin32.xls" wb.SaveAs(excelfile) wb.Close() xlsapp.Quit() os.startfile(excelfile) Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77/ From tdelaney at avaya.com Sun Dec 17 16:44:10 2006 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Mon, 18 Dec 2006 08:44:10 +1100 Subject: trees Message-ID: <2773CAC687FD5F4689F526998C7E4E5FF1EC3A@au3010avexu1.global.avaya.com> vertigo wrote: > Hello > > What library/functions/classes could i use to create trees ? I would suggest either a horticultural or religious class. I'm sure that any library will contain functional texts on both. Or you could just read the following: http://www.catb.org/~esr/faqs/smart-questions.html Tim Delaney From timr at probo.com Sun Dec 17 16:47:18 2006 From: timr at probo.com (Tim Roberts) Date: Sun, 17 Dec 2006 21:47:18 GMT Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> Message-ID: <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> "Gabriel Genellina" wrote: >On 16 dic, 04:47, Tim Roberts wrote: >> > os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH > >>This will tell you that "x.exe" is executable, even if "x.exe" contains >> nothing but zeros. > >Isn't the same with any other recipe, portable or not? Unless the OS >actually tries to load and examine the file contents, which the OS's >I'm aware of, don't do. Yes, of course, you're right. I was about to delve into a philosophical discussion about the difference in handling this between Linux and Windows, but they're both just conventions. One is based on an arbitrary flag, one is based on a file extension. Contents are irrelevant. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVE.THIS.cybersource.com.au Sun Dec 10 08:54:02 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 11 Dec 2006 00:54:02 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <7xejr8r86m.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 10 Dec 2006 02:00:02 -0500, Ken Tilton wrote: > Steven D'Aprano wrote: >> On Sat, 09 Dec 2006 22:41:12 -0500, Ken Tilton wrote: >> >> >>>>I know that. It was more of a rhetorical question -- Lispers are either >>>>trying to emphasis the radical nature of what you can do with macros, or >>>>understate it and make them seem just like functions. >>> >>>Yep, both. The first is rare. CLOS is one, my Cells (ported this summer >>>to PyCells as part of SoC 2006) is another. The latter is the norm. >> >> >> If macros' advanced usage is rare, > > Hunh? I have tons of them. Of coure at your level of discourse you will > want to know if those are metric tons or... Stop playing games Ken. You said they were rare. Not me. You. The fact that you personally make lots of use of the more radical macros doesn't come into it. As you said, the norm across the wider Lisp community is the less radical macro, the ones that are basically just functions. That's what you said -- or are you changing your mind? -- Steven. From steve at REMOVE.THIS.cybersource.com.au Sat Dec 16 20:30:15 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 17 Dec 2006 12:30:15 +1100 Subject: How to test if two strings point to the same file or directory? References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: On Sat, 16 Dec 2006 17:02:04 -0800, Sandra-24 wrote: > Comparing file system paths as strings is very brittle. Why do you say that? Are you thinking of something like this? /home//user/somedirectory/../file /home/user/file Both point to the same file. > Is there a > better way to test if two paths point to the same file or directory > (and that will work across platforms?) How complicated do you want to get? If you are thinking about aliases, hard links, shortcuts, SMB shares and other complications, I'd be surprised if there is a simple way. But for the simple case above: >>> import os >>> path = '/home//user/somedirectory/../file' >>> os.path.normpath(path) '/home/user/file' -- Steven. From sjmachin at lexicon.net Sun Dec 3 00:24:08 2006 From: sjmachin at lexicon.net (John Machin) Date: 2 Dec 2006 21:24:08 -0800 Subject: Parsing data from pyserial In-Reply-To: References: Message-ID: <1165123448.798241.233930@80g2000cwy.googlegroups.com> Lone Wolf wrote: > I'm trying to get data through my serial port from a CMUcam. > This gizmo tracks a color and returns a packet of data. The > packet has nine data points (well, really eight since the first > point is just a packet header) separated by spaces as follows: M > xxx xxx xxx xxx xxx xxx xxx xxx > > Here is the code I am using (python v24): > > import serial > > ser=serial.Serial('com1',baudrate=115200, bytesize=8, > parity='N', stopbits=1,xonxoff=0, timeout=1) > > ser.write("PM 1") #This sets the CMUcam to poll mode > > for i in range(0,100,1): > ser.write("TC 016 240 100 240 016 240\r\n") > reading = ser.read(40) You are asking for 40 bytes of data. You will get 40 bytes of data. However your packets are (presumably) variable length, (presumably) terminated by CR and/or LF. What does the documentation for the device tell you? > print reading What you see from the print statement is not necessarily what you've got. Change that to print repr(reading) and show us what you then see. > components = reading.split() > print components > ser.close > > Here is an example output: > > M 37 79 3 4 59 124 86 25 > ['59', '123', '87', '25', 'M', '37', '79', '3', '4', '59', > '124', '86', '25', 'M > '] > M 38 77 3 2 59 124 86 25 > ['39', '85', '26', 'M', '38', '77', '3', '2', '59', '124', '86', > '25', 'M', '38' > , '7'] > Let's try to reconstruct "reading": | >>> a = ['59', '123', '87', '25', 'M', '37', '79', '3', '4', '59', | ... '124', '86', '25', 'M'] | >>> astrg = ' '.join(a) | >>> astrg | '59 123 87 25 M 37 79 3 4 59 124 86 25 M' | >>> len(astrg) | 39 <<<<<==== ooh! almost 40!! | >>> b = ['39', '85', '26', 'M', '38', '77', '3', '2', '59', '124', '86', | ... '25', 'M', '38' | ... , '7'] | >>> bstrg = ' '.join(b) | >>> bstrg | '39 85 26 M 38 77 3 2 59 124 86 25 M 38 7' | >>> len(bstrg) | 40 <<<<<==== ooh! exactly 40!!! My guess: the device is pumping out packets faster than you can handle them. So you are getting 40-byte snatches of bytes. A snatch is long enough to cover a whole packet with possible fragments of packets at each end. You will need to discard the fragments. If you need all the data, you'd better get some help on how to implement flow control -- I've never used pyserial and I'm not going to read _all_ the docs for you :-) I'm very interested to see what print repr(reading) actually shows. I'm strongly suspecting there is a CR (no LF) at the end of each packet; in the two cases shown, this would cause the "print reading" to appear as only one packet ... think about it: carriage return, with no linefeed, would cause overwriting. It is a coincidence with those two samples that the first part of the line doesn't appear strange, with a 4, 5, or 6-digit number showing up where the trailing fragment ends > My problem is that I am trying to get each data point of the > packet into a separate variable. Ordinarily, this would be easy, > as I would just parse the packet, read the array and assign each > element to a variable eg. mx = components[1]. better would be: mx, foo, bar, ......, eighth_vbl = components[start:start + 8] once you have worked out what start should be, e.g. start = components.index('M') + 1 > However, that > doesn't work here because the original packet and the array that > I got from using the split() method are different. If I were to > try read the array created in the first example output, mx would > be 123 instead of 37 like it is in the packet. In the second > example, the array is 85 while the packet is 38. > > As near as I can figure out, pyserial is reading a stream of > data and helpfully rearranging it so that it fits the original > packet format M xxx xxx xxx xxx xxx xxx xxx xxx. How, if you've read the docstring for the Serial.read() method, did you come to that conclusion? pyserial knows nothing about your packet format. > I would have > thought the split() method that I used on original packet (ie > the "reading" variable) would have just returned an array with > nine elements like the packet has. This is not the case, and I > am at a loss about how to fix this. > > I've searched the archive here and elsewhere with no luck. Any > help REALLY appreciated! > With a bit of repr() and a bit of RTFM, one can often manage without help :-) Cheers, John From conveycj at npt.nuwc.navy.mil Thu Dec 28 12:25:02 2006 From: conveycj at npt.nuwc.navy.mil (Christian Convey) Date: Thu, 28 Dec 2006 12:25:02 -0500 Subject: Python 2.4/2.5 hang on bad reference? Message-ID: <4593FDEE.5020701@npt.nuwc.navy.mil> Has anyone seen the following? I've got a somewhat complicated program that includes pygtk, some C/C++ code, and lots of Python code. My problem is that when some code tries to use a global variable that hasn't yet been created, or tries to invoke a method/function that doesn't exist in another module, the entire python program hangs. Ctrl-C doesn't kill it; I need to whack it from another terminal using the kill command. Using print statements, it basically looks like execution of the Python interpreter simply hangs when it goes to the problem statement. The code involved is straight, single-threaded Python code. The code is running on the Gtk's event-handling thread. I'm using a clean install of Ubuntu 6.10, and I see the same problem in both 2.4 and 2.5. I've tried wrapping the offending code with a try/catch block, so that in case there's an exception it will get printed to stdout, but as far as I can tell my exception handler is never getting invoked. (Perhaps I'm accidentally crafting my "except" statements too narrowly?) Any ideas? Thanks very much, Christian -- Christian Convey Computer Scientist, Naval Undersea Warfare Centers Newport, RI (401) 832-6824 conveycj at npt.nuwc.navy.mil From kw at codebykevin.com Fri Dec 8 16:14:04 2006 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 08 Dec 2006 16:14:04 -0500 Subject: test Message-ID: <47e63$4579d59d$4275d90a$19877@FUSE.NET> please disregard -- Kevin Walzer Code by Kevin http://www.codebykevin.com From anthra.norell at vtxmail.ch Fri Dec 1 15:05:17 2006 From: anthra.norell at vtxmail.ch (Frederic Rentsch) Date: Fri, 01 Dec 2006 21:05:17 +0100 Subject: Python spam? In-Reply-To: <02a401c71513$282936a0$03000080@hendrik> References: <02a401c71513$282936a0$03000080@hendrik> Message-ID: <45708AFD.8020408@vtxmail.ch> Hendrik van Rooyen wrote: > "Aahz" wrote: > > >> Anyone else getting "Python-related" spam? So far, I've seen messages >> "from" Barry Warsaw and Skip Montanaro (although of course header >> analysis proves they didn't send it). >> -- >> > > not like that - just the normal crud from people giving me get rich quick tips > on the stock market that is aimed at mobilising my money to follow theirs to > help influence the price of a share... > > - Hendrik > > > ...which I noticed works amazingly well in many cases, looking at the charts. which, again, means that the trick isn't likely to fizzle out soon as others have with victims getting wise to it. Getting feathers plucked in this game isn't a turn-off. It's an opportunity to join the pluckers by speeding up one's turnover at the expense of the slowpokes. Like pyramid sales this it is a self-generating market. This game, at least, isn't unethical, other than clogging the internet with reckless traffic. I've been asking myself why it seems so difficult to backtrace such obtrusive, if not criminal, traffic to the source and squash it there. Perhaps some knowledgeable volunteer would share his insights. Perhaps stalking con artists could be another interest group. Frederic From xscottg at gmail.com Sun Dec 17 22:23:14 2006 From: xscottg at gmail.com (xscottg at gmail.com) Date: 17 Dec 2006 19:23:14 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xy7p5kixi.fsf@ruckus.brouhaha.com> References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> Message-ID: <1166412194.206364.73270@f1g2000cwa.googlegroups.com> Paul Rubin wrote: > xscottg at gmail.com writes: > > I should assume you meant Common Lisp, but there isn't really any > > reason you couldn't > > > > (poke destination (peek source)) > > That breaks the reliability of GC. I'd say you're no longer writing > in Lisp if you use something like that. Writing in this "augmented > Lisp" can be ok if well-localized and done carefully, but you no > longer have the guarantees that you get from unaugmented Lisp. By > adding one feature you've removed another. I don't agree. The addresses (mapped registers or DMA or whatever) you peak and poke in a device driver aren't going to be managed by the garbage collector. Even regarding interupts, I don't see a problem without a solution: (with-interupts-and-garbage-collection-disabled (poke destination (peek source)) You could even allocate memory (cons cells for instance) with the interupts disabled, but it would be considered the same bad practice that it would be if you did that in C. Cheers, -Scott From gal.diskin at gmail.com Wed Dec 13 09:57:01 2006 From: gal.diskin at gmail.com (Gal Diskin) Date: 13 Dec 2006 06:57:01 -0800 Subject: Iterating over several lists at once In-Reply-To: References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> Message-ID: <1166021821.006925.138190@80g2000cwy.googlegroups.com> Thanks, that's an improvment (your first way). But I still wish I could find an even shorter (or more elegent) way of doing it. (Well, I guess if I expect every wish I have to come true I should at least wish for something more valuable.) Thanks again, Gal On Dec 13, 3:58 pm, "Fredrik Lundh" wrote: > "Gal Diskin" wrote: > > I am writing a code that needs to iterate over 3 lists at the same > > time, i.e something like this: > > > for x1 in l1: > > for x2 in l2: > > for x3 in l3: > > print "do something with", x1, x2, x3 > > > What I need to do is go over all n-tuples where the first argument is > > from the first list, the second from the second list, and so on... > > > I was wondering if one could write this more easily in some manner > > using only 1 for loop. > > What I mean is something like this: > > > for (x1,x2,x3) in (l1,l2,l3): > > print "do something with", x1, x2, x3how about > > for x1, x2, x3 in func(l1, l2, l3): > print x1, x2, x3 > > where func is defined as, say, > > def func(l1, l2, l3): > return ((x1, x2, x3) for x1 in l1 for x2 in l2 for x3 in l3) > > or if you prefer > > def helper(l1, l2, l3): > for x1 in l1: > for x2 in l2: > for x3 in l3: > yield x1, x2, x3 > > From l.steinborn at 4c-ag.de Wed Dec 6 14:04:48 2006 From: l.steinborn at 4c-ag.de (Lutz Steinborn) Date: Wed, 6 Dec 2006 20:04:48 +0100 (MET) Subject: logging Message-ID: <20061206200451.6fca5e68.l.steinborn@4c-ag.de> Hello, I need to log each and only this loglevel to a different file. So for example all INFO to info.log and all ERROR to error.log. And I need a master logfile with all messages. How can I do this ? Any example ? Kindly regards Lutz http://www.4c-wohnen.de http://www.4c-parfum.de From arkanes at gmail.com Thu Dec 14 11:11:37 2006 From: arkanes at gmail.com (Chris Mellon) Date: Thu, 14 Dec 2006 10:11:37 -0600 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> Message-ID: <4866bea60612140811j6b796802j6f9d3ecc01093ab4@mail.gmail.com> On 12/14/06, Ken Tilton wrote: > > > Andrew Reilly wrote: > >> Each skill seems to have a title, a > > list of annotations, and a list of hints (and a reverse, which I don't > > understand). > > There's the problem. > > > That all looks like data. > > No, not reverse, the part you did not understand. I do not mean what the > code was doing, I meant that it was code. > > > Couldn't you do that with a table > > containing those fields, and key it off the defskill argument (or even the > > title?) at startup? > > Not the code. In reverse. > > > Then you don't have to worry about re-factoring the > > code: there's only going to be one piece of code, driven by a table. > > What if it turns into an SQL lookup during refactoring? > > > > > I only mentioned interpolation because it seemed likely that you might > > want to be mutating these strings to be more specific to what your student > > was actually doing. > > Interpolation does not mean what you think it means. :) That's OK, I > figgered it out. Yes, that is what the program does, it substitutes > terms from the student's problem to produce a hint or annotation. The > function is called "expand". Because the text is like a macro. :) > > > I didn't expect that "42" was necessarily the right > > answer... > > No, but it so happens any #STR...# token is a literal bit of math > encoded as an ascii string. That gets translated to proper math notation > (by which I mean, what you would see in tex output). During template > conversion. So this hint is just saying to the kid, "Dude, |-42|=42, > |42|=42, get over it." > > > > > To back out a bit, here, and get back to the meat of the matter: if one is > > using Python, then it's because one doesn't much care about performance, > > I'll try again: this has nothing to do with performance. > > > and it's reasonable to do expansions, pattern matching and domain specific > > language creation/use at run-time. After all, that's how the language > > itself works, mostly. > > The last example showed the macro inserting code to magically produce a > binding inside the reverse function. It would be easier to compare and > contrast with the Python equivalent if someone had posted such, but your > troops have fallen back to Fort So What? and pulled up the drawbridge. > > Peace. Out. Ken > I think this specific sub-thread is a great example of what a lot of people roll their eyes about when Lispers start talking, and it's a great contrast to the foot stomping earlier where all the Lispers were swearing that macros didn't complicate anything. You start out with a fairly simple task, and use a macro instead of a function even though you don't need to. That's "Arguments against LISP 101" right there. Then, you're (by your own indication - I find the lisp code unreadably idiomatic) overly clever and spend several iterations walking around in circles making your macro more clever, rather than fixing your problem (spending too much time creating clever genericness is a trap I'm sure many programmers have fallen in, I've done it myself, but I have a feeling that Lispers are more susceptible than most). You finally have your macro doing all the cleverness you need, and (again by your own account, I can't judge the code on any merit other than "this looks like garbage to me") it's getting nasty and contrived. So you went from "look how simple and powerful this macro is", in a trivial case that didn't even need a macro to "well, it's ugly and nasty and idiomatic, but look how powerful this macro is!". This is exactly the sort of thing that I (and, in my experience, many Python programmers) strive to avoid in our work, and the readability and clarity (more than simple character counts) of Python is a tool that helps me achieve this goal. I'd produce an equivalent Python version, but since you're totally unclear in why you're adding these changes, and I can't read the lisp well enough to see what it's doing, you're going to have to back up a few steps if you want a Python implementation of your final solution. I expect, however, that I wouldn't use a function at all = I'd make it a data driven solution, because it (seems to be) a data oriented problem. > -- > Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm > > "Well, I've wrestled with reality for thirty-five > years, Doctor, and I'm happy to state I finally > won out over it." -- Elwood P. Dowd > > "I'll say I'm losing my grip, and it feels terrific." > -- Smiling husband to scowling wife, New Yorker cartoon > -- > http://mail.python.org/mailman/listinfo/python-list > From Benjamin.Barker at gmail.com Fri Dec 29 07:45:03 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 04:45:03 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167395368.387567.283250@48g2000cwx.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> <1167393801.950199.197830@48g2000cwx.googlegroups.com> <1167394098.642975.78350@73g2000cwn.googlegroups.com> <1167394662.665220.185680@a3g2000cwd.googlegroups.com> <1167395368.387567.283250@48g2000cwx.googlegroups.com> Message-ID: <1167396303.259891.144210@n51g2000cwc.googlegroups.com> Perhaps when I'm checking for table existance using mysql through python I have to be more explicit: Where I did have: USE database; IF NOT EXISTS CREATE table(..... Perhaps I need: USE database; IF NOT EXISTS CREATE database.table(..... I'll try it after lunch. Does anyoone know whether this might be the problem? Ben Ben wrote: > I have found the problem, but not the cause. > > I tried setting the database up manually before hand, which let me get > rid of the "IF NOT EXISTS" lines, and now it works! > > But why the *** should it not work anyway? The first time it is run, no > database or tables, so it creates them. That works. But apparentlyu on > subsequent runs it decides the tables it created arent' actually there, > and overwrites them. Grrrrrrrrrrrrr. > > > Ben > > > > Ben wrote: > > Well, I've checked the SQL log, and my insert statements are certainly > > being logged. The only option left open is that the table in question > > is being replaced, but I can't see why it should be... > > > > > > Ben wrote: > > > Nope... that can't be it. I tried running those commands manually and > > > nothing went wrong. > > > But then again when I execute the problematic command manually nothing > > > goes wrong. Its just not executing until the last time, or being > > > overwritten. > > > > > > > > > Ben wrote: > > > > Each time my script is run, the following is called: > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > self.cursor.execute("USE "+name) > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( .... > > > > > > > > The idea being that stuf is only created the first time the script is > > > > run, and after that the original tables and database is used. This > > > > might explain my pronblem if for some reason the old tables are being > > > > replaced... can anyone see anything wrong with the above? > > > > > > > > Ben > > > > > > > > > > > > > > > > > > > > > > > > > > > > Ben wrote: > > > > > One partial explanation might be that for some reason it is recreating > > > > > the table each time the code runs. My code says "CREATE TABLE IF NOT > > > > > EXISTS" but if for some reason it is creating it anyway and dropping > > > > > the one before that could explain why there are missing entires. > > > > > > > > > > It wouldn't explain why the NOT EXISTS line is being ignored though... > > > > > > > > > > Ben > > > > > > > > > > > > > > > Ben wrote: > > > > > > I initially had it set up so that when I connected to the database I > > > > > > started a transaction, then when I disconnected I commited. > > > > > > > > > > > > I then tried turning autocommit on, but that didn't seem to make any > > > > > > difference (althouh initially I thought it had) > > > > > > > > > > > > I'll go back and see what I can find... > > > > > > Cheers, > > > > > > Ben > > > > > > > > > > > > > > > > > > johnf wrote: > > > > > > > Ben wrote: > > > > > > > > > > > > > > > I don't know whether anyone can help, but I have an odd problem. I have > > > > > > > > a PSP (Spyce) script that makes many calls to populate a database. They > > > > > > > > all work without any problem except for one statement. > > > > > > > > > > > > > > > > I first connect to the database... > > > > > > > > > > > > > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > > > > > > > self.cursor = self.con.cursor() > > > > > > > > self.cursor.execute("SET max_error_count=0") > > > > > > > > > > > > > > > > All the neccesary tables are created... > > > > > > > > > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > > > > > self.cursor.execute("USE "+name) > > > > > > > > > > > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > > > > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > > > > > > > varchar(20)) > > > > > > > > > > > > > > > > Then I execute many insert statements in various different loops on > > > > > > > > various tables, all of which are fine, and result in multiple table > > > > > > > > entries. The following one is executed many times also. and seems > > > > > > > > identical to the rest. The print statements output to the browser > > > > > > > > window, and appear repeatedly, so the query must be being called > > > > > > > > repeatedly also: > > > > > > > > > > > > > > > > print "

SQL query executing

" > > > > > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > > > > > > > ','c','2','e','f','g')") > > > > > > > > print "

SQL query executed

" > > > > > > > > > > > > > > > > I have, for debugging, set "i" up as a counter variable. > > > > > > > > > > > > > > > > No errors are given, but the only entry to appear in the final database > > > > > > > > is that from the final execution of the INSERT statement (the last > > > > > > > > value of i) > > > > > > > > > > > > > > > > I suspect that this is to vague for anyone to be able to help, but if > > > > > > > > anyone has any ideas I'd be really grateful :-) > > > > > > > > > > > > > > > > It occured to me that if I could access the mysql query log that might > > > > > > > > help, but I was unsure how to enable logging for MysQL with python. > > > > > > > > > > > > > > > > Cheers, > > > > > > > > > > > > > > > > Ben > > > > > > > > > > > > > > Not sure this will help but where is the "commit"? I don't use MySQL but > > > > > > > most SQL engines require a commit. > > > > > > > Johnf From fumanchu at amor.org Tue Dec 5 20:05:06 2006 From: fumanchu at amor.org (fumanchu) Date: 5 Dec 2006 17:05:06 -0800 Subject: Mod_python vs. application server like CherryPy? References: Message-ID: <1165367106.268299.240650@l12g2000cwl.googlegroups.com> Vincent Delporte wrote: > I'm still a newbie when it comes to web applications, so would like > some help in choosing a solution to write apps with Python: What's the > difference between using running it through mod_python vs. building an > application server using Python-based tools like CherryPy, Quixote, > Draco, etc.? Well, let me start by saying that anything you can build with CherryPy, you can build with mod_python. In a nutshell, mod_python gives you access from Python to the Apache API, whereas CherryPy and friends give you their own API. I joined the CherryPy development team because I liked CherryPy's API better, and at the time, needed to deploy my site on IIS, not Apache. I continue to use the same site, written with CherryPy, but now using Apache (and even mod_python!) to serve it. CherryPy allows me to focus on the application layer and leave the server/deployment layer for another day. In other words, there's nothing about mod_python that leaves it out of the "application server" category per se. The publisher handler, in particular, is an example of an "application server" built on top of mod_python's base API, and has some strong similarities to CherryPy's traversal and invocation mechanisms. But IMO CherryPy has a cleaner API for process control (engines and servers), application composition (via the object tree and via WSGI), and plugins (like gzip, static content, and header management). Robert Brewer System Architect Amor Ministries fumanchu at amor.org From olakh at walla.co.il Sat Dec 9 17:19:26 2006 From: olakh at walla.co.il (Ola K) Date: 9 Dec 2006 14:19:26 -0800 Subject: Search & Replace in MS Word Puzzle Message-ID: <1165702766.581612.45610@n67g2000cwd.googlegroups.com> Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here, the string at the beginning explains what it does: '''A script for MS Word which does the following: 1) Assigns all Hebrew italic characters "Italic" character style. 2) Assigns all Hebrew bold characters "Bold" character style. 2) Assign all English US characters "English Text" (can be regular, Italic, or Bold) ''' import win32com.client #setting up shortcuts word = win32com.client.Dispatch("Word.Application") doc = word.ActiveDocument find = doc.Content.Find w=win32com.client.constants #creating the needed styles if not there already if "Italic" not in doc.Styles: doc.Styles.Add("Italic",w.wdStyleTypeCharacter) #"ItalicBi" is the same as "Italic", but for languages that go Right to Left. doc.Styles("Italic").Font.ItalicBi = True print "Italic style was created" if "Bold" not in doc.Styles: doc.Styles.Add("Bold",w.wdStyleTypeCharacter) doc.Styles("Bold").Font.BoldBi = True print "Bold style was created" if "English Text" not in doc.Styles: doc.Styles.Add("English Text", w.wdStyleTypeCharacter) doc.Styles("English Text").Font.Scaling = 80 print "English Text style was created" if "English Text Italic" not in doc.Styles: doc.Styles.Add("English Text Italic", w.wdStyleTypeCharacter) doc.Styles("English Text Italic").BaseStyle = "English Text" doc.Styles("English Text").Font.Italic = True print "English Text Italic style was created" if "English Text Bold" not in doc.Styles: doc.Styles.Add("English Text Bold", w.wdStyleTypeCharacter) doc.Styles("English Text Bold").BaseStyle = "English Text" doc.Styles("English Text").Font.Bold = True print "English Text Bold style was created" #Search & Replacing Hebrew Italics find.ClearFormatting() find.Font.Italic = True find.Format = True find.LanguageID = w.wdHebrew find.Replacement.ClearFormatting() find.Replacement.Style = doc.Styles("Italic") find.Execute(Forward=True, Replace=w.wdReplaceAll, FindText='', ReplaceWith='') print "Italic style was checked" #Search & Replacing Hebrew Bolds find.ClearFormatting() find.Font.Bold = True find.Format = True find.LanguageID = w.wdHebrew find.Replacement.ClearFormatting() find.Replacement.Style = doc.Styles("Bold") find.Execute(Forward=True, Replace=w.wdReplaceAll, FindText='', ReplaceWith='') print "Bold style was checked" #Search & Replacing English Regulars find.ClearFormatting() find.LanguageID = w.wdEnglishUS find.Font.Italic = False find.Font.Bold = False find.Replacement.ClearFormatting() find.Replacement.Style = doc.Styles("English Text") find.Execute(Forward=True, Replace=w.wdReplaceAll, FindText='', ReplaceWith='') print "English Text style was checked" #Search & Replacing English Italics find.ClearFormatting() find.LanguageID = w.wdEnglishUS find.Font.Italic = True find.Replacement.ClearFormatting() find.Replacement.Style = doc.Styles("English Text Italic") find.Execute(Forward=True, Replace=w.wdReplaceAll, FindText='', ReplaceWith='') print "English Text Italic style was checked" #Search & Replacing English Bolds find.ClearFormatting() find.LanguageID = w.wdEnglishUS find.Font.Bold = True find.Replacement.ClearFormatting() find.Replacement.Style = doc.Styles("English Text Bold") find.Execute(Forward=True, Replace=w.wdReplaceAll, FindText='', ReplaceWith='') print "English Text Bold style was checked" print "We are done." word.Visible=1 ----------Code end here So generally speaking this script works quite nicely, BUT: 1. Despite this sort of conditions: " if "Italic" not in doc.Styles: " if this style already exists I get an error, and the program stops. Any idea how can that be?... 2. The replacement of the English characters doesn't seem to work very well. It either assigns all English characters "English Text Bold", or "English Text Italic" and with no apparent reason. ?.... 3. The command " word.Visible=1 " doesn't work anymore. I say "anymore" because it used to work, but later I ran "COM Makepy Utility" on "Microsoft Word 10 Object Library (8.2)" and since then it stopped working. On Excel, for example, I never ran Makepy and this commands works fine for it. Any idea on this one?... 4. In the end of this long weekend I was pretty satisfied with my script (even if not fully functioning) and used PY2EXE to make it an .exe file so that I can use it in my work place. But alas, that .exe file does not work because it doesn't recognize any of win32com client constants. Such as "wdStyleTypeCharacter", or "wdEnglishUS" How can I solve this one? Advice will be very appreciated. --Ola From samschul at pacbell.net Tue Dec 5 13:12:41 2006 From: samschul at pacbell.net (sam) Date: 5 Dec 2006 10:12:41 -0800 Subject: About the 79 character line recommendation In-Reply-To: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> References: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> Message-ID: <1165342360.485363.238240@73g2000cwn.googlegroups.com> Steve Bergman wrote: > As I study Python, I am trying to develop good, Pythonic, habits. For > one thing, I am trying to keep Guido's the style guide in mind. > > And I know that it starts out saying that it should not be applied in > an absolute fashion. > > However, I am finding that the 79 character line prescription is not > optimal for readability. > > Certainly, cutting back from the length of lines that I used to use has > *helped* readability. But if I triy very hard to apply 79, I think > readability suffers. If this were just something that was an issue > occasionally, I would just put it off to "know when to break the > rules". However, find myself going to 90 to 100 characters very > frequently. Now, if it were just me, I'd shoot for < 100. However, > the Python philosophy includes making code easier for others to read, > as well. > > So, I was wondering what more accomplished Python programmers thought > about this. > > While I'm on this general topic, the guide mentions a pet peeve about > inserting more than one space to line up the "=" in assignment > statements. To me, lining them up, even if it requires quite a few > extra spaces, helps readability quite a bit. Comments? > > Thanks, > Steve Bergman I prefer to use 132 char per line, and like you I line up the = sign for readability. The reason for this convention arises from the fact that I am Dyslexic, and this convention helps me double check my typing. Sam Schulenburg From Roberto.Bonvallet at cern.ch Wed Dec 6 10:46:05 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Wed, 6 Dec 2006 15:46:05 +0000 (UTC) Subject: dict.has_key(x) versus 'x in dict' References: <1165418932.582377.312200@79g2000cws.googlegroups.com> Message-ID: Andy Dingley wrote: > I need to generate a set (lots of intersections involved), but then I > need to display it sorted > > lstBugsChanged = [ bugId for bugId in setBugsChanged ] > lstBugsChanged.sort() In Python > 2.4: sorted(setBugsChanged) -- Roberto Bonvallet From rurpy at yahoo.com Mon Dec 4 11:49:23 2006 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: 4 Dec 2006 08:49:23 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> Message-ID: <1165250963.660087.58410@n67g2000cwd.googlegroups.com> Carsten Haese wrote: > On Mon, 2006-12-04 at 01:04 -0800, Russ wrote: > > Robert Kern wrote: > > > > > Nothing is going to happen until you do one of these two things. Being more rude > > > (and yes, you are being incredibly rude and insulting) won't move things along. > > > > I re-read the thread, and I don't see anywhere where I was rude > > Please allow me to break it down for you: > > Your first reply on this thread, or second message, said: > > """ > Now, that [submitting a patch that fixes the problem] would be rather > silly. I would have to familiarize myself > with the code for the Python interpreter, then send a patch to the > maintainers (and hope they notice it in their inboxes), while the > maintainers themselves could probably "fix" the problem in two minutes > flat. No thanks! > > My suggestion is trivial to implement and would benefit every Python > programmer (even if only slightly), so I don't think it is too much to > ask for. > """ > > You may not have meant this to be rude, but it does come off as rude and > arrogant, and I'll explain to you why: In your first post you stated > that the feature seems like a no-brainer to you. That implies to the > reader that you might have the necessary skill to implement the feature > yourself, hence Robert's suggestion to submit a patch was, in the > context you gave yourself, neither unreasonable nor silly. I can see how > your calling a reasonable suggestion by a valuable community member > "silly" would be construed as rude and arrogant. Thanks for explaining why the OP was rude. Having been reading and listening to english for only a few decades probably, I am sure the OP (and me too!) appreciates your explanation of rudeness. It was really hard for me to see it until you explained it so well. The great thing about c.l.p. is how much one learns about non-Python things here. (oops, I hope I wasn't rude by saying there were non-Python things? I didn't mean to diminish Python in any way.) Russ, Please rememer that learning Python is not done overnight -- there are many different levels of knowlage and only the most elite Pythonists have reached True Understanding. Since there are many things you don't understand, it is best you (and me too!) do not make suggrestions publically. Infidels could read them and inplying that Python is not perfect and you will undermine the spritual growth of many other newbies.. Such dangerous sugggestions should be made privately at the alter of Sourceforge, with a lot of deep self-reflection and piety. Until you achive greater understanding it is best if in public you make sure that you write with the following in mind: Python is perfect Perl sucks Static typing sucks Python is faster than C Quoting frequently from the holy Zen of Python is also helpful. Please remember that many regulars here are members of the holy priesthood because they have spent many years studying the Python scriptures. Be as circumspect in addressing them as you would be a medival knight or Japanese samurai. Only by following their guidance with complete devoutness and faith will you be able to achive the deepest level of Python appreciation. Hope this helps. From fredrik at pythonware.com Tue Dec 5 14:16:22 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 20:16:22 +0100 Subject: Subprocess with a Python Session? In-Reply-To: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> Message-ID: Calvin Spealman wrote: > No matter what I do I cant get the following code to do what I expect. > I hadn't used subprocess t o read and write to pipes of a > still-running app, and I just can't seem to get it right. What gives? > > import subprocess > > p = subprocess.Popen("python", stdout=subprocess.PIPE, stdin=subprocess.PIPE) > p.stdin.write('print 10\n') + p.stdin.close() > assert p.stdout.readline() == '10\n' From manuel.reil at googlemail.com Fri Dec 1 07:41:42 2006 From: manuel.reil at googlemail.com (manuel.reil at googlemail.com) Date: 1 Dec 2006 04:41:42 -0800 Subject: recover/extract content from html with help of cheetah templates Message-ID: <1164976902.674378.123880@j72g2000cwa.googlegroups.com> Hello, currently i am developing a very small cms using python and cheetah. very early i have noticed that i was lacking the method to extract/recover the contents (html,text) from the html that is generated by cheetah and delivered to the site viewer. to explain it further: during the output processing by cheetah placeholders are replaced with my text/html input. to edit/alter the page i have to extract my personal input out of the delivered html again, like a diff of output html and the template. is there a method integrated in cheetah which i have not noticed so far to do this? or have i to write a own "diff" method? thanks in advance, manuel From gregpinero at gmail.com Fri Dec 22 18:16:51 2006 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 22 Dec 2006 18:16:51 -0500 Subject: Use a Thread to reload a Module? Message-ID: <312cfe2b0612221516x295949b5ka3f422d8bb41d5b@mail.gmail.com> Hi Python Experts, I hope I can explain this right. I'll try. Background: I have a module that I leave running in a server role. It has a module which has data in it that can change. So every nth time a function in the server gets called, I want to reload the module so it has the freshest data. But there's a lot of data so it takes 5-10 seconds to do a reload. My question is: Would I be able to launch a seperate thread to reload the module while the server does it work? Hopefully it would be using the old module data right up until the thread was finished reloading. Thanks in advance, Greg Here's some psuedo code that might illustrate what I'm talking about: import lotsa_data def serve(): reload(lotsa_data) #can this launch a thread so "do_stuff" runs right away? do_stuff(lotsa_data.data) while 1: listen_for_requests() From fredrik at pythonware.com Wed Dec 13 08:58:33 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Dec 2006 14:58:33 +0100 Subject: Iterating over several lists at once References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> Message-ID: "Gal Diskin" wrote: > I am writing a code that needs to iterate over 3 lists at the same > time, i.e something like this: > > for x1 in l1: > for x2 in l2: > for x3 in l3: > print "do something with", x1, x2, x3 > > What I need to do is go over all n-tuples where the first argument is > from the first list, the second from the second list, and so on... > > I was wondering if one could write this more easily in some manner > using only 1 for loop. > What I mean is something like this: > > for (x1,x2,x3) in (l1,l2,l3): > print "do something with", x1, x2, x3 how about for x1, x2, x3 in func(l1, l2, l3): print x1, x2, x3 where func is defined as, say, def func(l1, l2, l3): return ((x1, x2, x3) for x1 in l1 for x2 in l2 for x3 in l3) or if you prefer def helper(l1, l2, l3): for x1 in l1: for x2 in l2: for x3 in l3: yield x1, x2, x3 From grahamd at dscpl.com.au Tue Dec 19 18:34:15 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 19 Dec 2006 15:34:15 -0800 Subject: Page layouts in mod_python? References: <1166563784.948936.253950@80g2000cwy.googlegroups.com> <45886568$0$31043$426a74cc@news.free.fr> Message-ID: <1166571254.954865.43430@73g2000cwn.googlegroups.com> Bruno Desthuilliers wrote: > Michael a ?crit : > > Hey everyone, > > > > Is it possible to automatically insert headers/footers using > > mod_python? > > I will be not be using PSP's, so I cannot use the PSP/include solution. > > Furthermore, the header will be dynamic; it won't be a static HTML > > page. > > > > In short, I've been looking for a page layout facility using > > mod_python. > > (Similar to the layout capability in Ruby on Rails.) > > mod_python is mainly a librairy exposing the apache API to Python - not > a full-stack db-to-web framework. What you want here is a HTML > templating system. There are quite a lot available in Python - look for > SimpleTAL, Genshi, Myghty, Jinja, Cheetah, etc... Contrary to the above advise, you could actually use mod_python to do what you want and you do not need a full stack to do it. Whether you would want to use just mod_python is another question and the answer would depend on a bit on what form the HTML files you want to modify are in or what is generating them. The first option available is to write an Apache output filter using mod_python which takes the content of the page and searches for the and tags and inserts at those points the appropriate header/footer. Using this scheme, because you are looking for tags already within the HTML page, you do not need to modify the original HTML source files. Because it is an output filter, the technique will work on both static files and on files which have been generated dynamically by PHP, mod_perl, mod_python or any other Apache response handler capable of generating dynamic pages. For this first technique, you do not even have to use mod_python if you didn't want to, as there are other Apache modules which have been designed to specifically use this technique to insert headers and footers in pages. These other modules are written in C and so are probably going to be quicker as well as more flexible without you having to do too much hard work. The second option, although not strictly mod_python specific, is to enable server side include processing for HTML files. For this to work you would need to modify the original HTML source files or what is generating them to add in appropriate SSI directives to include the header/footer. Again, because SSI is performed as an output filter, source files can be static or dynamically generated. If using basic SSI, the include of the header/footer to get dynamic information would be done as a virtual include. That is, it generates an Apache subrequest to a handler which generates the header/footer. This handler could be implemented as a CGI script, mod_python handler, mod_perl handler or even PHP. Alternatively, in mod_python 3.3 (soon to be released), one can use the new ability to use Python code in conjunction with SSI. For dynamic header/footer snippets, this would involve adding callouts to pages to Python code setup using mod_python. For an example of header/footer generation using Python code, see: http://www.dscpl.com.au/wiki/ModPython/Articles/BasicsOfServerSideIncludes If you particularly want to use mod_python, for further discussion on this topic and what may be best for what you want to do, I would suggest you might take the conversation over to the mod_python user mailing list. Details for the list are on the mod_python web site. Graham From uymqlp502 at sneakemail.com Tue Dec 5 12:05:38 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 5 Dec 2006 09:05:38 -0800 Subject: Why not just show the out-of-range index? References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165325263.656851.87980@l12g2000cwl.googlegroups.com> Message-ID: <1165338338.644318.62360@80g2000cwy.googlegroups.com> stdazi wrote: > Usually, when I make some coding mistake (index out of range - in this > case) I just care to fix the mistake and I usually don't mind to > inspect by how much the index was overflowed. It really seems like a > feature that should be embedded in some Python debugger than a feature > in the interpreter itself. Then why have the interpreter generate error messages at all? I think it makes sense to make the interpreter as self-contained as possible, within reason, so you don't depend on a debugger any more than necessary. And it's not that I care "how much the index was overflowed." It's that something unexpected happened, and I want a clue what it was. I'll need to find out somehow anyway. What is the next logical step if not to find out what the out-of-range index was? Having said that, I reiterate that I don't know the implementation difficulty, so I defer on the decision as to whether it is worth implementing or not. From nmm1 at cus.cam.ac.uk Thu Dec 14 06:56:59 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 14 Dec 2006 11:56:59 GMT Subject: tuple.index() References: Message-ID: In article , Fredrik Lundh writes: |> |> > Why doesn't the tuple type have an index method? It seems such a |> > bizarre restriction that there must be some reason for it. |> |> hah! not being able to remove or add things to tuples is an even |> bizarrer restriction! Eh? Why? My understanding of the difference between a tuple and a list is PRECISELY that the former is immutable and the latter mutable. But an index method makes precisely as much sense on an immutable sequence as it does on a mutable one. Regards, Nick Maclaren. From jonc at icicled.net Mon Dec 25 02:53:06 2006 From: jonc at icicled.net (Jonathan Curran) Date: Mon, 25 Dec 2006 01:53:06 -0600 Subject: Website Capture In-Reply-To: <1167029844.360539.138940@f1g2000cwa.googlegroups.com> References: <1167029844.360539.138940@f1g2000cwa.googlegroups.com> Message-ID: <200612250153.06153.jonc@icicled.net> On Monday 25 December 2006 00:57, yoring at gmail.com wrote: > Hi, > > I want to capture a web site into gif image using Python. > I installed the PIL if it can help. It can't be done with just Python & PIL, that much is for sure. First of all you need some sort of module/program/(whatever you want to call it) that can render a given webpage. Then you would proceed to capturing the graphical output of that module/program/... Maybe what you should look into are graphical toolkits that possibly provide a HTML widget from which you can get a graphical display. WxWidgets/WxPython is one option, and the only other I can think of is GTK/pyGTK. I hope this helps a little, and Merry Christmas! - Jonathan Curran From aboudouvas at panafonet.gr Thu Dec 28 11:09:09 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 28 Dec 2006 08:09:09 -0800 Subject: db access In-Reply-To: <4593eb66$0$322$e4fe514c@news.xs4all.nl> References: <1167320723.501187.98810@h40g2000cwb.googlegroups.com> <4593eb66$0$322$e4fe514c@news.xs4all.nl> Message-ID: <1167322149.728456.204540@79g2000cws.googlegroups.com> Hey Martin, thanks for the fast reply! I have already seen that link and i just downloaded the pyodbc module but isn't Python already containing a "built-in" odbc module so to allow for db communication ?? On Dec 28, 6:06 pm, "Martin P. Hellwig" wrote: > king kikapu wrote: > > Hi to all, > > > is there a way to use an RDBMS (in my case, SQL Server) from Python by > > using some built-in module of the language (v. 2.5) and through ODBC ?? > > I saw some samples that use statements like "import dbi" or "import > > odbc" but neither modules (dbi, odbc) are present on my system... > > > Any hint(s) ?? > > > Thanks in advanceHey there, > > Take a look at this:http://www.python.org/doc/topics/database/ > > Cheers, > > -- > mph From Leo.Kislov at gmail.com Mon Dec 11 05:04:28 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 11 Dec 2006 02:04:28 -0800 Subject: sys.stdin.encoding References: <1165825571.435369.150110@79g2000cws.googlegroups.com> <1165829211.214261.307740@n67g2000cwd.googlegroups.com> Message-ID: <1165831468.040775.136460@79g2000cws.googlegroups.com> aine_canby at yahoo.com wrote: > Duncan Booth skrev: > > > aine_canby at yahoo.com wrote: > > > > > The following line in my code is failing because sys.stdin.encoding is > > > Null. > > > > I'll guess you mean None rather than Null. > > > > > This has only started happening since I started working with > > > Pydef in Eclipse SDK. Any ideas? > > > > > > uni=unicode(word,sys.stdin.encoding) > > > > > You could give it a fallback value: > > > > uni = unicode(word, sys.stdin.encoding or sys.getdefaultencoding()) > > > > or even just: > > > > uni = unicode(word, sys.stdin.encoding or 'ascii') > > > > which should be the same in all reasonable universes (although I did get > > bitten recently when someone had changed the default encoding in a system). > > > Thanks for your help. The problem now is that I cant enter the Swedish > characters ??? etc without getting the following error - > > Enter word> P?e > Traceback (most recent call last): > File "C:\Documents and Settings\workspace\simple\src\main.py", line > 25, in > archive.Test() > File "C:\Documents and Settings\workspace\simple\src\verb.py", line > 192, in Test > uni=unicode(word,sys.stdin.encoding or sys.getdefaultencoding()) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: > ordinal not in range(128) > > The call to sys.getdefaultencoding() returns ascii. Since I can enter > the characters ??? on the command line in Pydef/Eclipse doesn't that > mean that the stdin is not ascii? What should I do? The workaround in your case is: in the beginning of your program: import sys if hasattr(sys.stdin, 'encoding'): console_encoding = sys.stdin.encoding else: import locale locale_name, console_encoding = locale.getdefaultlocale() and later: uni = unicode(word, console_encoding) But don't think it's portable, if you use other IDE or OS, it may not work. It would be better if PyDev implemented sys.stdin.encoding -- Leo From Benjamin.Barker at gmail.com Fri Dec 29 07:29:28 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 04:29:28 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167394662.665220.185680@a3g2000cwd.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> <1167393801.950199.197830@48g2000cwx.googlegroups.com> <1167394098.642975.78350@73g2000cwn.googlegroups.com> <1167394662.665220.185680@a3g2000cwd.googlegroups.com> Message-ID: <1167395368.387567.283250@48g2000cwx.googlegroups.com> I have found the problem, but not the cause. I tried setting the database up manually before hand, which let me get rid of the "IF NOT EXISTS" lines, and now it works! But why the *** should it not work anyway? The first time it is run, no database or tables, so it creates them. That works. But apparentlyu on subsequent runs it decides the tables it created arent' actually there, and overwrites them. Grrrrrrrrrrrrr. Ben Ben wrote: > Well, I've checked the SQL log, and my insert statements are certainly > being logged. The only option left open is that the table in question > is being replaced, but I can't see why it should be... > > > Ben wrote: > > Nope... that can't be it. I tried running those commands manually and > > nothing went wrong. > > But then again when I execute the problematic command manually nothing > > goes wrong. Its just not executing until the last time, or being > > overwritten. > > > > > > Ben wrote: > > > Each time my script is run, the following is called: > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > self.cursor.execute("USE "+name) > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( .... > > > > > > The idea being that stuf is only created the first time the script is > > > run, and after that the original tables and database is used. This > > > might explain my pronblem if for some reason the old tables are being > > > replaced... can anyone see anything wrong with the above? > > > > > > Ben > > > > > > > > > > > > > > > > > > > > > Ben wrote: > > > > One partial explanation might be that for some reason it is recreating > > > > the table each time the code runs. My code says "CREATE TABLE IF NOT > > > > EXISTS" but if for some reason it is creating it anyway and dropping > > > > the one before that could explain why there are missing entires. > > > > > > > > It wouldn't explain why the NOT EXISTS line is being ignored though... > > > > > > > > Ben > > > > > > > > > > > > Ben wrote: > > > > > I initially had it set up so that when I connected to the database I > > > > > started a transaction, then when I disconnected I commited. > > > > > > > > > > I then tried turning autocommit on, but that didn't seem to make any > > > > > difference (althouh initially I thought it had) > > > > > > > > > > I'll go back and see what I can find... > > > > > Cheers, > > > > > Ben > > > > > > > > > > > > > > > johnf wrote: > > > > > > Ben wrote: > > > > > > > > > > > > > I don't know whether anyone can help, but I have an odd problem. I have > > > > > > > a PSP (Spyce) script that makes many calls to populate a database. They > > > > > > > all work without any problem except for one statement. > > > > > > > > > > > > > > I first connect to the database... > > > > > > > > > > > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > > > > > > self.cursor = self.con.cursor() > > > > > > > self.cursor.execute("SET max_error_count=0") > > > > > > > > > > > > > > All the neccesary tables are created... > > > > > > > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > > > > self.cursor.execute("USE "+name) > > > > > > > > > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > > > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > > > > > > varchar(20)) > > > > > > > > > > > > > > Then I execute many insert statements in various different loops on > > > > > > > various tables, all of which are fine, and result in multiple table > > > > > > > entries. The following one is executed many times also. and seems > > > > > > > identical to the rest. The print statements output to the browser > > > > > > > window, and appear repeatedly, so the query must be being called > > > > > > > repeatedly also: > > > > > > > > > > > > > > print "

SQL query executing

" > > > > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > > > > > > ','c','2','e','f','g')") > > > > > > > print "

SQL query executed

" > > > > > > > > > > > > > > I have, for debugging, set "i" up as a counter variable. > > > > > > > > > > > > > > No errors are given, but the only entry to appear in the final database > > > > > > > is that from the final execution of the INSERT statement (the last > > > > > > > value of i) > > > > > > > > > > > > > > I suspect that this is to vague for anyone to be able to help, but if > > > > > > > anyone has any ideas I'd be really grateful :-) > > > > > > > > > > > > > > It occured to me that if I could access the mysql query log that might > > > > > > > help, but I was unsure how to enable logging for MysQL with python. > > > > > > > > > > > > > > Cheers, > > > > > > > > > > > > > > Ben > > > > > > > > > > > > Not sure this will help but where is the "commit"? I don't use MySQL but > > > > > > most SQL engines require a commit. > > > > > > Johnf From robert.kern at gmail.com Fri Dec 22 18:16:40 2006 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 22 Dec 2006 17:16:40 -0600 Subject: Problem in using Pulp In-Reply-To: <1166828788.439508.291820@48g2000cwx.googlegroups.com> References: <1166759609.366064.124360@f1g2000cwa.googlegroups.com> <1166761918.461234.167610@h40g2000cwb.googlegroups.com> <1166828788.439508.291820@48g2000cwx.googlegroups.com> Message-ID: MRAB wrote: > Robert Kern wrote: >> The last character in that string is a double quote. You don't want that. What >> you want to do is escape all of the backslashes (or use raw strings to avoid the >> escaping altogether). E.g. >> >> "C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\" >> >> or >> >> r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\" >> > The second example won't work: you can't have a final backslash in a > raw string! My apologies. You are correct. -- 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 From salvatore.difazio at gmail.com Mon Dec 4 16:43:11 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 4 Dec 2006 13:43:11 -0800 Subject: Thread error In-Reply-To: References: <1165177861.653112.325020@73g2000cwn.googlegroups.com> Message-ID: <1165268591.054043.9580@j44g2000cwa.googlegroups.com> Hi Dennis, I have another little problem with your source: Traceback (most recent call last): File "main.py", line 86, in kdi.join() # wait for kdi thread to exit NO CPU HOG BUSY LOOPS File "d:\programmi\python25\lib\threading.py", line 549, in join assert self.__started, "cannot join thread before it is started" AssertionError: cannot join thread before it is started I don't know what this means. Now I try some experiment. Tnx From will.ware at gmail.com Fri Dec 15 09:31:12 2006 From: will.ware at gmail.com (Will Ware) Date: 15 Dec 2006 06:31:12 -0800 Subject: Restrictive APIs for Python Message-ID: <1166193072.925721.52780@80g2000cwy.googlegroups.com> Python has no inherent provision for a restrictive API that blocks accesses to methods and variables outside an allowed set. Inexperienced Python programmers may fail to adhere to an agreed-upon API, directly accessing the private internals of a class. Adherence to defined APIs is a good thing. This function allows a class to specify its API, and raise AttributeErrors for disallowed accesses. def restrictiveApi(klas): class newklas: def __init__(self, *args): self.__inst = apply(klas, args) def __getattr__(self, attr): # If the attribute is in the permitted API, then return # the correct thing, no matter who asks for it. # if attr in self.__inst._PUBLIC: return getattr(self.__inst, attr) # If the attribute is outside the permitted API, then # return it only if the calling class is in the list of # friends. Otherwise raise an AttributeError. # elif hasattr(self.__inst, '_FRIENDS'): # find the class of the method that called us try: raise Exception except: import sys tb = sys.exc_info()[2] callerClass = tb.tb_frame.f_back.\ f_locals['self'].__class__ # if it's a friend class, return the requested thing if callerClass.__name__ in self.__inst._FRIENDS: return getattr(self.__inst, attr) # if not a friend, raise an AttributeError raise AttributeError, attr return newklas To use this, a class needs to define two class variables, _PUBLIC and _FRIENDS, both being lists (or tuples) of strings. The _PUBLIC list gives the names of all methods and variables that should be considered public, i.e. any other class may use them. The _FRIENDS list gives the names of classes that are allowed free access to all methods and variables in the protected class. The _FRIENDS list is optional. Having defined _PUBLIC and optionally _FRIENDS, use something like the following to protect your class. Restricting the API will incur a performance overhead, so it's best to do it under the control of some sort of debug flag. if debug_flag: from restrictive import restrictiveApi MyClass = restrictiveApi(MyClass) ======== Examples ========== class ClassUnderTest: # This class has a private variable called privateX. It can be # set using the setX() method or gotten using the x() method. # If another class appears in the _FRIENDS list, that class # can access privateX directly. # _PUBLIC = ('x', 'setX') _FRIENDS = ('FriendClass',) def __init__(self, x): # __init__ is always callable by anybody self.setX(x) def x(self): # callable by anybody return self.privateX def setX(self, x): # callable by anybody self.privateX = x ClassUnderTest = restrictiveApi(ClassUnderTest) class FriendClass: def getX(self, cut): return cut.privateX # this works fine class StrangerClass: def getX(self, cut): return cut.privateX # this raises an AttributeError From e0427417 at student.tuwien.ac.at Thu Dec 14 14:15:59 2006 From: e0427417 at student.tuwien.ac.at (Mathias Panzenboeck) Date: Thu, 14 Dec 2006 20:15:59 +0100 Subject: merits of Lisp vs Python In-Reply-To: <457f1b8c$0$7962$426a74cc@news.free.fr> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <1165593283.523163.71730@16g2000cwy.googlegroups.com> <457b3ca2$0$28520$3b214f66@tunews.univie.ac.at> <457f1b8c$0$7962$426a74cc@news.free.fr> Message-ID: <4581a225$0$12642$3b214f66@tunews.univie.ac.at> Bruno Desthuilliers wrote: > Mathias Panzenboeck a ?crit : >> Rob Thorpe wrote: >> >>> Mathias Panzenboeck wrote: >>> >>>> Mark Tarver wrote: >>>> >>>>> How do you compare Python to Lisp? What specific advantages do you >>>>> think that one has over the other? >>>>> >>>>> Note I'm not a Python person and I have no axes to grind here. >>>>> This is >>>>> just a question for my general education. >>>>> >>>>> Mark >>>>> >>>> >>>> I do not know much about Lisp. What I know is: >>>> Python is a imperative, object oriented dynamic language with duck >>>> typing, >>> >>> Yes, but Python also supports the functional style to some extent. >>> >> >> >> I currently visit a course about functional programming at the >> university of technology vienna: >> python implements only a small subset of things needed to be called a >> functional language (list >> comprehension). > > Python has functions as first-class objects (you can pass functions as > arguments to functions, return functions from functions, and bind > functions to identifiers), and that's the only thing you need to use a > functional approach. You mean like function pointers in C and C++? I think this should be possible in assembler, too. I thought functional languages have to be declarative? The boost C++ library has even lambdas! From duncan.booth at invalid.invalid Wed Dec 20 04:12:17 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Dec 2006 09:12:17 GMT Subject: urllib.unquote and unicode References: <1166497058.109088.53120@80g2000cwy.googlegroups.com> <1166504578.169707.154900@n67g2000cwd.googlegroups.com> <4588507E.20602@v.loewis.de> Message-ID: "Martin v. L?wis" wrote: > Duncan Booth schrieb: >> The way that uri encoding is supposed to work is that first the input >> string in unicode is encoded to UTF-8 and then each byte which is not >> in the permitted range for characters is encoded as % followed by two >> hex characters. > > Can you back up this claim ("is supposed to work") by reference to > a specification (ideally, chapter and verse)? I'm not sure I have time to read the various RFC's in depth right now, so I may have to come back on this thread later. The one thing I'm convinced of is that the current implementations of urllib.quote and urllib.unquote are broken in respect to their handling of unicode. In particular % encoding is defined in terms of octets, so when given a unicode string urllib.quote should either encoded it, or throw a suitable exception (not KeyError which is what it seems to throw now). My objection to urllib.unquote is that urllib.unquote(u'%a3') returns u'\xa3' which is a character not an octet. I think it should always return a byte string, or it should calculate a byte string and then decode it according to some suitable encoding, or it should throw an exception [choose any of the above]. Adding an optional encoding parameter to quote/unquote be one option, although since you can encode/decode the parameter it doesn't add much. > No, the http scheme is defined by RFC 2616 instead. It doesn't really > talk about encodings, but hints an interpretation in 3.2.3: The applicable RFC is 3986. See RFC2616 section 3.2.1: > For definitive information on URL syntax and semantics, see "Uniform > Resource Identifiers (URI): > Generic Syntax and Semantics," RFC 2396 [42] (which replaces RFCs > 1738 [4] and RFC 1808 [11]). and RFC 2396: > Obsoleted by: 3986 > Now, RFC 2396 already says that URIs are sequences of characters, > not sequences of octets, yet RFC 2616 fails to recognize that issue > and refuses to specify a character set for its scheme (which > RFC 2396 says that it could). and RFC2277, 3.1 says that it MUST identify which charset is used (although that's just a best practice document not a standard). (The block capitals are the RFC's not mine.) > The conventional wisdom is that the choice of URI encoding for HTTP > is a server-side decision; for that reason, IRIs were introduced. Yes, I know that in practice some systems use other character sets. From david at cypherspace.info Sat Dec 30 12:49:05 2006 From: david at cypherspace.info (cypher543) Date: 30 Dec 2006 09:49:05 -0800 Subject: Starting a child process and getting its stdout? In-Reply-To: References: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> <7vl9p2h7f7adsbn6d6tfpmluera3njnb6g@4ax.com> <1167405767.308530.308800@48g2000cwx.googlegroups.com> Message-ID: <1167500945.330498.112360@i12g2000cwa.googlegroups.com> Yes, I did try your example. But, after talking on the #python IRC channel, I realized that it wasn't the process that was blocking, it was my GUI. I had to fire an event using gobject.io_add_watch() whenever data was received from the child process. The event then read from the process and added a line to my gtk.TextView. Thank you for your suggestions, though. On Dec 30, 12:12 am, Tom Plunket wrote: > Gabriel Genellina wrote: > > Did you *actually* tried what Tom Plunket posted? Two tiny chars make > > a difference.The sad irony is that before taking off for vacation I was struggling at > work with the same problem in some sense. I couldn't figure out why for > some processes I got all of the output right away and for others it all > got queued up 'til the process ended. Working out a simple example for > this thread showed the light: my calling of my_process.stdout.read() was > blocking 'til EOF. Oops. > > -tom! > > -- From cptnwillard at gmail.com Sun Dec 3 13:14:20 2006 From: cptnwillard at gmail.com (cptnwillard at gmail.com) Date: 3 Dec 2006 10:14:20 -0800 Subject: wxpython worked out but can't find api docs for download. References: Message-ID: <1165169660.539522.285560@79g2000cws.googlegroups.com> Go to: http://wxpython.org/download.php#binaries and in the documentation part, download both "wxPython-docs" and "wxPython-newdocs". Hope this helps. From sanxiyn at gmail.com Fri Dec 15 22:34:31 2006 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Sat, 16 Dec 2006 12:34:31 +0900 Subject: [ANN] IronPython Community Edition r5 Message-ID: <5b0248170612151934v6bd84621u6337e139e8f03829@mail.gmail.com> This is the fifth release of IronPython Community Edition (IPCE). You can download it from SourceForge. http://sourceforge.net/projects/fepy FePy project aims to provide enhancements and add-ons for IronPython. Visit the project homepage for more informations. http://fepy.sourceforge.net/ Binary is built with Mono 1.2.2.1. It is strongly recommended to use Mono versions above 1.2.2, as it fixes GC.CollectionCount issue properly. You may meet unexplained NotImplementedError in the long-running process otherwise. (Thanks Paolo Molaro.) There's not much updates, but I figured that releasing early & often would be better... Changes in this release follow. New IronPython Updated to IronPython 1.1a1. FePy options The way site.py is (ab)used by FePy has changed. Documentation here: http://fepy.sourceforge.net/doc/fepy-options.html Libraries Improved array module. Support for CherryPy 3. Experimental AST support. Bundles code and ihooks are included from Python Standard Library. paramiko 1.6.4. Patches You can read the summary of applied patches here. http://fepy.sourceforge.net/patches.html Removed in this release, fixed in 1.1a1: patch-ironpython-file-canseek patch-ironpython-open-unknown-mode patch-ironpython-re-lastgroup New in this release, for IronPython: patch-ironpython-compile-co-filename patch-ironpython-set-func-name New in this release, for Mono: patch-ironpython-mono-socket-buffersize patch-ironpython-tabcomplete-by-default New in this release, for Python Standard Library: patch-stdlib-codeop (Anthony Baxter) -- Seo Sanghyeon From paul at boddie.org.uk Wed Dec 6 17:27:19 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 6 Dec 2006 14:27:19 -0800 Subject: Video stream server References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> <1165218527.632366.290350@j44g2000cwa.googlegroups.com> <1165221764.002660.197600@16g2000cwy.googlegroups.com> Message-ID: <1165444039.489227.32780@80g2000cwy.googlegroups.com> Lad wrote: > > I love Python so I would like to implement video support in Python. > That is how it is related to Python only I'm not sure if this is too low-level, but there's always the Flumotion platform [1]: an open source streaming solution based on Python, GStreamer and Twisted, and there's a Java applet for viewing in Web pages (I'll save my rant about Flash for another time). This PyCon 2005 presentation slide takes you to the key points: http://www.flumotion.net/doc/flumotion/presentation/pycon2005/html/img4.html Of course, this is more about streaming than just video uploads and downloads, but if you're considering streaming (or if anyone else reading is), it's probably worth looking into. Paul [1] http://www.flumotion.net/ From w_a_x_man at yahoo.com Fri Dec 15 13:25:52 2006 From: w_a_x_man at yahoo.com (William James) Date: 15 Dec 2006 10:25:52 -0800 Subject: merits of Lisp vs Python References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> Message-ID: <1166207152.706475.76020@t46g2000cwa.googlegroups.com> Andr? Thieme wrote: > greg schrieb: > > Ken Tilton wrote: > > > >> The reason I post macro expansions along with examples of the macro > >> being applied is so that one can see what code would have to be > >> written if I did not have the defskill macro to "write" them for me. > > > > It seems to me your brain is somewhat stuck on the use of macros. > > That you see it this way is normal. > A BASIC programmer would tell you the same thing. He can show you > solutions that don't use classes, methods or functions. > Some sweet gotos and gosubs are enough. > The idea is that macros save you tokens and allow you to experess > in a clearer way what you want to do. But in no case one "needs" > them to solve a programming problem. All what Kenny showed could > be done without his macro. It would just be a bit more complicated > and the resulting code wouldn't look good. > > > > You're looking at the expansion of your > > macro and assuming that you'd have to write all that > > code by hand if you didn't have macros. You're not > > thinking about alternative approaches, which could > > just as well be used in Lisp as well as Python, that > > are just as compact yet don't make use of macros. > > He wouldn't have to write the full expansion. With functional > programming he could also solve it, but then he would need > a funcall here, a lambda there. And his code would not look > so understandable anymore, because it is filled up with some > low level details. > > > I will take one of the first macro examples form "On Lisp". > Let's say for some reason you want to analyse some numbers > and do something depending on their sign. We want a function > "numeric if": > > def nif(num, pos, zero, neg): > if num > 0: > return pos > else: > if num == 0: > return zero > else: > return neg > > > In Lisp very similar: > (defun nif (num pos zero neg) > (case (truncate (signum num)) > (1 pos) > (0 zero) > (-1 neg))) > > > Now one example Graham gives is: > (mapcar #'(lambda (x) > (nif x 'p 'z 'n)) > '(0 2.5 -8)) > > which results in the list (Z P N). > You can do the same thing in Python. > But it gets hairier if we want to make function calls that > have side effects. > Let me add these three functions: > > (defun p () > (print "very positive") > "positive") > > (defun z () > (print "no no") > "zero") > > (defun n () > (print "very negative") > "negative") > > > And now see what happens: > > CL-USER> (mapcar #'(lambda (x) > (nif x (p) (z) (n))) > '(0 2.5 -8)) > > "very positive" > "no no" > "very negative" > "very positive" > "no no" > "very negative" > "very positive" > "no no" > "very negative" > ("zero" "positive" "negative") > > The messages were printed in each case. > To stop that I need lazy evaluation: > CL-USER> (mapcar #'(lambda (x) > (funcall > (nif x > #'(lambda () (p)) > #'(lambda () (z)) > #'(lambda () (n))))) > '(0 2.5 -8)) > > "no no" > "very positive" > "very negative" > ("zero" "positive" "negative") > > > I put the calls to the functions p, z and n into a function object. > In some languages it would look a bit cleaner, for example Ruby. > They have a single name space and don't need funcall and lambda is > shorter. But still, we need to add several tokens. Maybe Haskell has > built in support for that. def p puts "very positive" "positive" end def z puts "no no" "zero" end def n puts "very negative" "negative" end def nif num, pos, zero, neg send( num>0 ? pos : (num==0 ? zero : neg) ) end [0, 2.5, -8].map{|x| nif x, :p, :z, :n} ### Another way ##### p = proc { puts "very positive" "positive" } z = proc { puts "no no" "zero" } n = proc { puts "very negative" "negative" } def nif num, pos, zero, neg ( num>0 ? pos : (num==0 ? zero : neg) ).call end [0, 2.5, -8].map{|x| nif x, p, z, n} From pyenos at pyenos.org Wed Dec 20 21:27:36 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 13:27:36 +1100 Subject: pickle fun References: <87r6uu56qf.fsf@pyenos.pyenos.org> Message-ID: <87irg656g7.fsf@pyenos.pyenos.org> Pyenos writes: > class pickle_service: > import cPickle as p > > # accept list as arg then serialize it to a file > def serialize(some_list,picklefile): > f=file(picklefile,"w") > p.dump(some_list,f) # so dumped this shit to the file > f.close() > # which one is the pickle? the file? no. just need the string of the name of file. > > # unserialize what? picklefile of course ;) > def unserialize(some_pickle): > f= file(some_pickle) # wtf is going on here: open file for unpickling > return p.load(f) # unpickled: store it somewhere > > class testpickleservice: > import pickle_service as p > > p.serialize(["f","u","c","k"," ",["you"]],"testpickle") > print p.unserialize("testpickle") > > AHAHAHAHA. funny. just remove class and save them as separate files. i was too dumb to realize that i need to do self explicitly here. :-| From no-spam at no-spam-no-spam.invalid Tue Dec 26 14:14:44 2006 From: no-spam at no-spam-no-spam.invalid (robert) Date: Tue, 26 Dec 2006 20:14:44 +0100 Subject: keypressed() function In-Reply-To: <1167139552.235499.167090@48g2000cwx.googlegroups.com> References: <1167139552.235499.167090@48g2000cwx.googlegroups.com> Message-ID: pinkfloydhomer at gmail.com wrote: > I need a function (blocking or non-blocking) that tells me if a key has > been pressed (even before it has been released etc.). Also, I would of > course like to know _which_ key has been pressed. > > I know that this probably does not exist in the Python library already > as a platform-independant abstraction (even though it probably could), > but then I would at least like solutions that works on Windows and on > Linux. > > /David > Its a terminal I/O function - not a platform function. E.g. On Win only in a rough console msvcrt.kbhit() does it. In PythonWin, IPython, Crust ... things are of course different. On regular Unix terminals you have the sys.stdin file: sys.stdin.read(1) #maybe in a thread and interthread-pass it to your main loop or possibly trick with fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NDELAY|os.O_NONBLOCK) when nothing is on sys.stdin - you get immediately an IOError: >>> sys.stdin.read(1) Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 11] Resource temporarily unavailable And see also other ioctl, termios, tty, cbreak, curses .. functions to get things early before \n buffering depending on the terminal mode ) Robert From nono at hotmail.com Sun Dec 31 03:31:15 2006 From: nono at hotmail.com (Osiris) Date: Sun, 31 Dec 2006 09:31:15 +0100 Subject: python , Boost and straight (but complex) C code References: <0d2dnZZ8as4TSgvYnZ2dnUVZ_q_inZ2d@speakeasy.net> <4596fdd9$0$293$426a74cc@news.free.fr> Message-ID: <4vsep2d2b3pdd2ubn5hjr98d7j30u916fe@4ax.com> On Sun, 31 Dec 2006 01:01:29 +0100, Christophe Cavalaria wrote: >Osiris wrote: > >> On Sat, 30 Dec 2006 13:19:28 -0800, Erik Max Francis >> wrote: >> >>>Osiris wrote: >>> >>>> I have these pieces of C-code (NOT C++ !!) I want to call from Python. >>>> I found Boost. >>>> I have MS Visual Studio 2005 with C++. >>>> >>>> is this the idea: >>>> I write the following C source file: >>>> ============================ >>>> #include >>>> #include >>>> >>>> namespace { // Avoid cluttering the global namespace. >>> >>>iostream and namespaces are both most definitely C++ features, not C. >> >> yes, but C can be compiled with a C++ compiler, One can put C code in >> C++ source.... Boost should not complain... should it ? >> Boost text is all about C++.. so... C should not be a problem... > >Not all C code can be compiled by a C++ compiler. And anyway, this is >definitively NOT C code. ok ok, but the examples of the application of boost only show how to do C++. So I followed those examples and try to embed my C code in the framework of the examples... Which seems not to be without merit, because my example here compiles ok, but the linking into a DLL goes wrong, looking at the log. I told VC where the boost libs are, and still.... From robert.kern at gmail.com Sun Dec 3 20:05:38 2006 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 03 Dec 2006 19:05:38 -0600 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: James Stroud wrote: > Russ wrote: >> Every Python programmer gets this message occasionally: >> >> IndexError: list index out of range >> >> The message tells you where the error occurred, but it doesn't tell you >> what the range and the offending index are. Why does it force you to >> determine that information for yourself when it could save you a step >> and just tell you? This seems like a "no-brainer" to me. Am I missing >> something? > > I think you have a point. I am curious to see how far people are willing > to go to defend this omission. It promises to be entertaining. I'm not sure that anybody is going to defend it as a deliberate omission. Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. -- 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 From brenNOSPAMbarn at NObrenSPAMbarn.net Fri Dec 29 21:00:01 2006 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Sat, 30 Dec 2006 02:00:01 GMT Subject: textwrap.dedent replaces tabs? References: Message-ID: Frederic Rentsch wrote: > (You dedent common leading tabs, except if preceded by common leading > spaces (?)). There cannot be common leading tabs if they are preceded by anything. If they were preceded by something, they wouldn't be "leading". -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From mirandacascade at yahoo.com Sat Dec 16 17:36:34 2006 From: mirandacascade at yahoo.com (mirandacascade at yahoo.com) Date: 16 Dec 2006 14:36:34 -0800 Subject: inquiry about installing Python 2.5 Message-ID: <1166308594.341370.8580@j72g2000cwa.googlegroups.com> Apologies in advance for what I'm sure seems like a trivial question. Operating system: Win XP Current version of Python: 2.4 If possible, I would like to have both Python 2.4 and Python 2.5 installed on my workstaiton. I downloaded the .msi for Python 2.5 from the python.org site. If I run the 2.5 installer, will it give me the option of keeping Python 2.4 installed on my workstation? Thank you. From pyenos at pyenos.org Wed Dec 20 19:13:41 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 11:13:41 +1100 Subject: what is wrong with my code? References: <874prq6wmd.fsf@pyenos.pyenos.org> Message-ID: <87vek65cne.fsf@pyenos.pyenos.org> "Calvin Spealman" writes: > It is hard to determine what is wrong with your code without you > telling anyone why it is you believe something is wrong with it. Did > you get an exception? Did it simply not do what it was expected to do? > There seems to be some apparent indenting problems, but maybe that is > just from pushing it through the e-mail. I see some general stylistic > problems as well, but without know what you are actually asking, I > won't know what questions to answer. "What is wrong with my code?" is > a container of many many smaller questions, and you need to focus your > questions better. > > On 21 Dec 2006 09:16:58 +1100, Pyenos wrote: > > import cPickle, shelve > > > > could someone tell me what things are wrong with my code? > > > > class progress: > > > > PROGRESS_TABLE_ACTIONS=["new","remove","modify"] > > DEFAULT_PROGRESS_DATA_FILE="progress_data" > > PROGRESS_OUTCOMES=["pass", "fail"] > > > > > > def unpickleProgressTable(pickled_progress_data_file): > > > > return unpickled_progress_table > > > > def pickleProgressTable(progress_table_to_pickle): > > > > return pickled_progress_data_file > > > > # Of course, you get progress_table is unpickled progress table. > > def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]): > > pid_column_list=progress_table[0] > > task_column_list=progress_table[1] > > outcome_column_list=progress_table[2] > > > > # But a task must also come with an outcome! > > def newEntry(new_task, new_outcome): > > new_pid=len(task_column_list) > > > > pid_column_list.extend(new_pid) > > task_column_list.extend(new_task) > > outcome_column_list.extend(new_outcome) > > > > def removeEntry(pid_to_remove, task_to_remove): > > > > if pid_column_list.index(pid_to_remove)==task_column_list.index(task_to_remove): > > # Must remove all columns for that task > > index_for_removal=pid_column_list.index(pid_to_remove) > > > > pid_column_list.remove(index_for_removal) > > task_column_list.remove(index_for_removal) > > outcome_column_list.remove(index_for_removal) > > > > # Default action is to modify to pass > > def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]): > > index_for_modifying=pid_column_list.index(pid_to_modify) > > > > # Modify the outcome > > outcome_column_list[index_for_modifying]=outcome_to_modify > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Read my blog! I depend on your acceptance of my opinion! I am interesting! > http://ironfroggy-code.blogspot.com/ it says that progress_table is not defined. i don't know why. From sebastien.ramage at gmail.com Wed Dec 6 02:25:43 2006 From: sebastien.ramage at gmail.com (=?iso-8859-1?q?S=E9bastien_Ramage?=) Date: 5 Dec 2006 23:25:43 -0800 Subject: Python Plugin for Web Browser Message-ID: <1165389943.093365.20590@80g2000cwy.googlegroups.com> I've an idea and I've made some search but I found nothing really interesting. There is somebody who have (or can help me to) try to developp a python plugin for web browser just like java ?? I search an how-to for creating a plugin for Firefox and only find how create extension... I've find some informations about Python Active Scripting but this is not what I want. Seb From http Sat Dec 9 20:57:41 2006 From: http (Paul Rubin) Date: 09 Dec 2006 17:57:41 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165700999.744643.207110@73g2000cwn.googlegroups.com> <7xvekkps2r.fsf@ruckus.brouhaha.com> <1165713635.140913.164060@l12g2000cwl.googlegroups.com> Message-ID: <7xwt50zf56.fsf@ruckus.brouhaha.com> "Paddy" writes: > Python can be used as a glue language. It is not solely a glue > language. > A lot of people find using Python to script libraries written in other > languages > a way to get things done. Ask the scipy guys or the biopython guys. Sure, connecting together programs and libraries that were written in other languages is what a glue language is. > You don't always wrap a module in Python for reasons of speed of > execution. > > Software testing may well be easier to do in Python than in the > native language of the wrapped library. ... That's the thing, those modules are written in languages other than Python because Python is not attractive for coding those functions directly in Python. That is a real weakness of Python and glossing over it by saying to write the functions in other languages and then wrap them in the C API is not a very impressive answer. For example, Lisp is routinely used for writing scientific and numerical code directly with performance comparable to C or whatever. There is no need to mess with wrapping modules written in other languages, an operation which should not be trivialized. From slawomir.nowaczyk.847 at student.lu.se Tue Dec 12 18:12:09 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Wed, 13 Dec 2006 00:12:09 +0100 Subject: merits of Lisp vs Python In-Reply-To: <457a8ba2$0$8714$ed2619ec@ptn-nntp-reader02.plus.net> References: <457a8ba2$0$8714$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <20061212233214.572E.SLAWOMIR.NOWACZYK.847@student.lu.se> On Sat, 09 Dec 2006 10:08:01 +0000 Jon Harrop wrote: #> Steven D'Aprano wrote: #>> Anything any language can do is possible in any other language #> #> Not true. Concurrency, for example. As in, say, not being able to implement concurrency in assembler? -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From address.good.until.2006.dec.22 at justmail.de Wed Dec 13 06:18:47 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Wed, 13 Dec 2006 12:18:47 +0100 Subject: merits of Lisp vs Python In-Reply-To: <87r6v4cxl5.fsf@gmx.at> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7x3b7lccjn.fsf@ruckus.brouhaha.com> <87r6v4cxl5.fsf@gmx.at> Message-ID: Markus Triska schrieb: > Ken Tilton writes: > >> I think all-rules-all-the-time Prolog is the poster boy for paradigm >> slavery. (I did try for a famous two months to use Prolog as a >> general-purpose programming language.) > > Don't expect to learn Prolog properly in so little time. To your > previous question whether the ~180 lines of Lisp code in some online > book constitute an "industrial strength" Prolog: only if the following > ~180 lines of Prolog code implement an "industrial strength" Lisp. Hallo, you are of course right. There are some prolog implementations for Lisp that implement some parts of Prolog. To get the full thing one would of course need a big lot more of work. The idea is to get the basic constructs of Prolog available for Lisp. And with 2k LOC there are already some nice things that one can do. Those who know the paradigm of logical programming can recognize that a problem falls into this domain and then use inside of Lisp some tools that allow to express the problem in this domain specific language. If one really wants/needs Prolog then one should use it ;) The Prolog implementations are much more efficient and very stable. But often even 60% of Prolog are so expressive, that it can be a real productivity booster. Andr? -- From bernard.chhun at gmail.com Mon Dec 4 20:06:40 2006 From: bernard.chhun at gmail.com (Bernard) Date: 4 Dec 2006 17:06:40 -0800 Subject: SPE (Stani's Python Editor) web site? In-Reply-To: References: <1164748601.099263.98060@l12g2000cwl.googlegroups.com> Message-ID: <1165280800.147167.108670@73g2000cwn.googlegroups.com> yes sir should I send them to you? John DeRosa a ?crit : > On 28 Nov 2006 13:16:41 -0800, "Bernard" > wrote: > > > > >I can send you the latest tar.gz ( SPE-0.8.3.c-wx2.6.1.0.tar ) file if > >you want it :) > > I'm looking for SPE for Python 2.5 and wxPython 2.7.2.0, on Windows. > Do you have that? From gagsl-py at yahoo.com.ar Tue Dec 12 14:27:50 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 11:27:50 -0800 Subject: Emulate @classmethod using decorator and descriptor In-Reply-To: <1165924003.681613.62790@80g2000cwy.googlegroups.com> References: <1165924003.681613.62790@80g2000cwy.googlegroups.com> Message-ID: <1165951670.859050.178540@j44g2000cwa.googlegroups.com> On 12 dic, 08:46, "WaterWalk" wrote: > Hello, I was recently learning python decorator and descriptor and > emulated a @classmethod decorator: > class EmuClassMethod(object): > def __init__(self, f=None): > self.f = f > def __get__(self, obj, klass=None): > if klass is None: > klass = type(obj) > def wrapped(*args): > return self.f(klass, *args) > return wrapped > > class Test(object): > @EmuClassMethod > def t(cls): > print "I'm %s" % cls.__name__ Basically you're right. But note that @classmethod does some additional work to keep the details: the function name is now "wrapped", no docstring, no argument names, no defaults, wrong type... >>> class Test2(object): ... @EmuClassMethod ... def t2(cls, arg1, arg2=2): ... "t2 docstring" ... print "I'm %s arg1=%s arg2=%s" % (cls.__name__, arg1, arg2) ... >>> print Test2.t2 >>> print Test2.t2.func_name wrapped >>> print Test2.t2.__doc__ None >>> print Test2.t2.func_defaults None >>> Test2.t2(100) I'm Test2 arg1=100 arg2=2 >>> Test2.t2(arg1=100) Traceback (most recent call last): File "", line 1, in ? TypeError: wrapped() got an unexpected keyword argument 'arg1' -- Gabriel Genellina From aahz at pythoncraft.com Mon Dec 11 11:14:31 2006 From: aahz at pythoncraft.com (Aahz) Date: 11 Dec 2006 08:14:31 -0800 Subject: alternate language References: Message-ID: In article , Lou Pecora wrote: >In article , > Bryan wrote: >> >> what is a good alternate language to learn? i just want something to expand >> my mind and hopefully reduce or delay any chance of alzheimer's. i would >> especially like to hear from those of you who learned python _before_ these >> languages. >> >> haskell, erlang, ocaml, mozart/oz, rebel, etc. > >I have no experience with any of these. Of course, now I will give my >opinions. :-) Just based on my experience with Python, C, C++, BASIC >(several flavors), Fortran 77 (mostly). > >> i don't require any of these features, but extra browny points for any of >> the following: >> >> interactive interpreter > >Python has several. Um... I think the original poster is saying that he already knows Python and wants to learn another language. He particularly wants opinions from other people who have learned these languages *after* learning Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Member of the Groucho Marx Fan Club From vertilka at gmail.com Sun Dec 31 10:01:04 2006 From: vertilka at gmail.com (Vertilka) Date: 31 Dec 2006 07:01:04 -0800 Subject: C app and Python Message-ID: <1167577264.741127.284630@48g2000cwx.googlegroups.com> Hi, I need to create an application that the user ask for python script to run. this script will call the C application functions (in my app. the function will draw on screen). Do I need to create an extension ? Note that this is not a DLL, but a C application. or I need to embed Python in my C application. Thanks, Vertilka From j.spies at hccnet.nl Sat Dec 23 13:58:53 2006 From: j.spies at hccnet.nl (Jaap Spies) Date: Sat, 23 Dec 2006 19:58:53 +0100 Subject: Elliptic Curve Library In-Reply-To: <1166886752.656666.287470@80g2000cwy.googlegroups.com> References: <1166886752.656666.287470@80g2000cwy.googlegroups.com> Message-ID: Mike Tammerman wrote: > I need an elliptic curve library that can be used by python. I googled > but couldn't find a one. I'll appreciate, if you could show me. > You could look at http://sage.scipy.org/sage/ http://sage.scipy.org/sage/features.html Jaap From paddy3118 at netscape.net Sat Dec 9 20:20:35 2006 From: paddy3118 at netscape.net (Paddy) Date: 9 Dec 2006 17:20:35 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xvekkps2r.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> <1165700999.744643.207110@73g2000cwn.googlegroups.com> <7xvekkps2r.fsf@ruckus.brouhaha.com> Message-ID: <1165713635.140913.164060@l12g2000cwl.googlegroups.com> Paul Rubin wrote: > "mystilleef" writes: > > Slow for users who aren't familiar with Psyco, Pyrex and C extensions, > > sure. > > > Anyway it's pretty lousy advocacy for a language to say "well if the > language is too slow, don't use it, use another langauge like C instead". Python can be used as a glue language. It is not solely a glue language. A lot of people find using Python to script libraries written in other languages a way to get things done. Ask the scipy guys or the biopython guys. The Python community actively encourages groups writing useful libraries to maintain a Python port, or Python users might wrap libraries themselves. You don't always wrap a module in Python for reasons of speed of execution. Software testing may well be easier to do in Python than in the native language of the wrapped library. The library itself may be better used in the dynamic environment of Pythons command line; or used together with other libraries already wrapped for/accessible from Python. - Paddy. From robert.kern at gmail.com Wed Dec 6 22:10:56 2006 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 06 Dec 2006 21:10:56 -0600 Subject: newb: What is the purpose of if __name__ == "__main__": In-Reply-To: <1165460385.607830.277220@n67g2000cwd.googlegroups.com> References: <1165460385.607830.277220@n67g2000cwd.googlegroups.com> Message-ID: johnny wrote: > What is the purpose of > if __name__ == "__main__": > > If you have a module, does it get called automatically? http://docs.python.org/lib/module-main.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 From huayang.xia at gmail.com Mon Dec 18 15:41:53 2006 From: huayang.xia at gmail.com (Huayang Xia) Date: 18 Dec 2006 12:41:53 -0800 Subject: When Closure get external variable's value? In-Reply-To: <1166473333.593246.238580@73g2000cwn.googlegroups.com> References: <1166473333.593246.238580@73g2000cwn.googlegroups.com> Message-ID: <1166474513.700608.201760@48g2000cwx.googlegroups.com> It will print 15. The closure gets the value at run time. Could we treat closure as part of the external function and it shares the local variable with its holder function? From duncan.booth at invalid.invalid Wed Dec 27 04:11:33 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Dec 2006 09:11:33 GMT Subject: Persistent variables in python References: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> Message-ID: "buffi" wrote: > Is this concidered bad coding practice since I guess persistent > variables in functions are not meant to be? > There is a problem that this trick only works for functions and not for methods as it assumes that there is a global name through which you can access the function. I think that more significantly is the question how you initialize the value (Lee Harr's decorator does that quite nicely though) or reset it, or have multiple instances each with their own saved value. As soon as you start asking those types of questions it is time to switch to using a class. So in short, yes it is a plausible trick in some situations as a lightweight alternative to a class which has only static state and one method, but if you want a second method or multiple instances you'll want a real class. (And yes, I do realise that by embedding the function with state inside a factory function you can create multiple instances.) Python also provides another lightweight way of saving state between calls. Consider whether your particular use can be written as a generator: def dostuff(): timesused = 0 print "First call!" while 1: timesused += 1 print "Function call", timesused yield timesused >>> fn = dostuff() >>> fn.next() First call! Function call 1 1 >>> fn.next() Function call 2 2 >>> fn.next() Function call 3 3 >>> timesused = fn.next() Function call 4 >>> print timesused 4 From pythonusr at gmail.com Sun Dec 10 17:41:37 2006 From: pythonusr at gmail.com (PythonUsr) Date: 10 Dec 2006 14:41:37 -0800 Subject: Python Operating System Message-ID: <1165790496.985266.221160@f1g2000cwa.googlegroups.com> Although I know for a fact that an Operating System can be written in Python, I need to ask some questions to the more advanced users of Python. Uuu and Cleese are two operating systems that were / are written in Python. Does anyone use them? If so, how do they function / feel? Do they have a graphical mode and a command line mode, such as Linux does? How hard would it be to write a full blown bootable operating system in Python? With a command line and a GUI in all? Would the books you see on the shelves at, say, Barnes and Noble, do the trick? Or do you need to dig deeper into the language than what is taught in the 1,000 page books? Thanks in advance, and I am truly sorry if this has been a discussion before in this group! -- Alex (PythonUsr) From jurgen.defurne at pandora.be Thu Dec 14 03:26:10 2006 From: jurgen.defurne at pandora.be (jurgen_defurne) Date: 14 Dec 2006 00:26:10 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165617885.632226.104370@j72g2000cwa.googlegroups.com> Message-ID: <1166084770.322063.150700@j72g2000cwa.googlegroups.com> Ken Tilton wrote: > George Sakkis wrote: > > JShrager at gmail.com wrote: > > > >>Okay, since everyone ignored the FAQ, I guess I can too... > >> > >>Mark Tarver wrote: > >> > >>>How do you compare Python to Lisp? What specific advantages do you > >>>think that one has over the other? > >> > >>(Common) Lisp is the only industrial strength language with both pure > >>compositionality and a real compiler. What Python has is stupid slogans > >>("It fits your brain." "Only one way to do things.") and an infinite > >>community of flies that, for some inexplicable reason, believe these > >>stupid slogns. These flies are, however, quite useful because they > >>produce infinite numbers of random libraries, some of which end up > >>being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python > >>is rapidly replacing Perl, and Ruby is simultaneously and even more > >>rapidly replacing Python. Each is closer to Lisp than the last; the > >>world is returning to Lisp and is dragging the flies with it. > >>Eventually the flies will descend upon Lisp itself and will bring with > >>them their infinite number of random libraries, and then things will be > >>where they should have been 20 years ago, but got sidetracked by Tcl > >>and other line noise. > > > > > > I know we shouldn't feed the trolls, but this one was particularly > > amusing to resist the urge. The joke about lisp's world domination in > > some unspecified point in the future never fails to bring a good > > chuckle. I heard it's scheduled right after strong AI and before time > > travel, is this still the plan? A quick look at > > http://www.tiobe.com/tpci.htm may be helpful as a reality check before > > you go back to your ivory tower (interesting how close in ratings and > > growth is the "Lisp/Scheme" entry with another dinosaur, Cobol). > > > > And it interesting that VB is almost three times "better" than Python, > and that a Honda could kick a Lamboghini's ass for it at Laguna Seca: > > http://www.googlefight.com/index.php?lang=en_GB&word1=lamborghini&word2=ford > > Come on, COBOL is a great language, even has macros (copy ... replacing) > and the worlds greatest case statement, evaluate. We are proud to be its > neightbor. > > ken > > -- > Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm > > "Well, I've wrestled with reality for thirty-five > years, Doctor, and I'm happy to state I finally > won out over it." -- Elwood P. Dowd > > "I'll say I'm losing my grip, and it feels terrific." > -- Smiling husband to scowling wife, New Yorker cartoon Well, Cobol still has the largest and most easy to comprehend system for doing decimal arithmetic. Jurgen From kentilton at gmail.com Thu Dec 14 09:14:34 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 09:14:34 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7xr6v2alyw.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7xpsankoc6.fsf@ruckus.brouhaha.com> <7xpsangcs8.fsf@ruckus.brouhaha.com> <7N7gh.574$n34.527@newsfe09.lga> <7xr6v2alyw.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Ken Tilton writes: > >>Again, that is precisely the point of macrology (in cases like >>this). When a pattern will repeat a sufficient number of times, and a >>function cannot handle the job, > > > But this is not a case where a function can't handle the job. Is, too. > > >>Check out the latest, plz. The example has grown now beyond what a >>function can do, I think. meanwhile, I have not seen how Python lets >>you avoid revisiting dozens of instances when changes to a mechanism >>are required. > > > I'm missing what the difficulty is. Your terse response does not provide enough for me to. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From jon at ffconsultancy.com Tue Dec 12 10:02:18 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 15:02:18 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7xhcw1l0sn.fsf@ruckus.brouhaha.com> <4u7q10F16153dU1@mid.individual.net> Message-ID: <457ec516$0$8737$ed2619ec@ptn-nntp-reader02.plus.net> Pascal Costanza wrote: > Paul Rubin wrote: >> Yes; I'd rather go by what the standard says than rely on >> implementation-dependent hacks. > > You shouldn't limit yourself to what some standard says. You shouldn't ignore previous work and standards can embody decades of programming language research. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From metaperl at gmail.com Mon Dec 11 10:23:22 2006 From: metaperl at gmail.com (metaperl) Date: 11 Dec 2006 07:23:22 -0800 Subject: Encapsulating conditional execution based on list membership - how do you do it? Message-ID: <1165850602.011794.159370@j44g2000cwa.googlegroups.com> I have a series of scripts which retrieve files. None of these scripts should continue if the file to be retrieved already exists in the archive. Here is the code: if f in path(self.storage.archive).files('*'): print f, "exists in archive. Not continuing" sys.exit() self.storage is a class which gives me object-oriented access to the filesystem directories that will be manipulated by the script. E.g. self.storage.archive is a string which refers to a certain directory. Initializing this object initializes all the members (input, archive, output, workfiles) and makes all the correct directories. ok, so I'm thinking of adding a method to the storage class so I can do this: self.storage.archive_has(f, print_msg=True) and sys.exit() but really there is no need to hardcode which storage directory. So I'm thinking: self.storage.memberof('archive', f, print_msg=Tree) and sys.exit() Is that the best solution you can think of? From python.list at tim.thechases.com Fri Dec 8 15:00:35 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 08 Dec 2006 14:00:35 -0600 Subject: Snake references just as ok as Monty Python jokes/references in python community? :) In-Reply-To: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> Message-ID: <4579C463.4040200@tim.thechases.com> > I'm semi-seriously wondering if snake jokes are valid in the Python > community since technically, Python came from Monty Python, not > slithery animals. > > Problem is I don't know that anyone born after Elvis died gets any of > these Monty Python jokes. I protest...Elvis isn't dead... ;-) Every good geekling has surely been brought up with a staple diet of MP (as well as Hitchhikers, Black Adder, etc)... > Is it kosher to make snake jokes/references even though officially they > don't have anything to do with the name of our favorite language? > (*Everyone* gets snake jokes! :) They may get snake jokes, but all they do is boo and *hiss*. Sorry...that word play was made in cold-blood so I won't boa you with any more -tkc From vivainio at gmail.com Wed Dec 20 03:16:09 2006 From: vivainio at gmail.com (Ville Vainio) Date: 20 Dec 2006 00:16:09 -0800 Subject: IPython 0.7.3 is out Message-ID: Hi all, The IPython team is happy to release version 0.7.3, with a lot of new enhancements, as well as many bug fixes (including full Python 2.5 support). We hope you all enjoy it, and please report any problems as usual. WHAT is IPython? ---------------- 1. An interactive shell superior to Python's default. IPython has many features for object introspection, system shell access, and its own special command system for adding functionality when working interactively. 2. An embeddable, ready to use interpreter for your own programs. IPython can be started with a single call from inside another program, providing access to the current namespace. 3. A flexible framework which can be used as the base environment for other systems with Python as the underlying language. 4. A shell for interactive usage of threaded graphical toolkits. IPython has support for interactive, non-blocking control of GTK, Qt and WX applications via special threading flags. The normal Python shell can only do this for Tkinter applications. Where to get it --------------- IPython's homepage is at: http://ipython.scipy.org and downloads are at: http://ipython.scipy.org/dist We've provided: - Source download (.tar.gz) - A Python Egg (http://peak.telecommunity.com/DevCenter/PythonEggs). - A native win32 installer. We note that IPython is now officially part of most major Linux and BSD distributions, so packages for this version should be coming soon, as the respective maintainers have the time to follow their packaging procedures. Many thanks to Jack Moffit, Norbert Tretkowski, Andrea Riciputi, Dryice Liu and Will Maier for the packaging work, which helps users get IPython more conveniently. Many thanks to Enthought for their continued hosting support for IPython. Release notes ------------- See http://projects.scipy.org/ipython/ipython/wiki/Release/0.7.3/Features for notable new features in this release. Enjoy, and as usual please report any problems. The IPython team. From meyer at acm.org Wed Dec 6 03:05:29 2006 From: meyer at acm.org (Andre Meyer) Date: Wed, 6 Dec 2006 09:05:29 +0100 Subject: Python Plugin for Web Browser In-Reply-To: <1165391969.824391.174140@l12g2000cwl.googlegroups.com> References: <1165389943.093365.20590@80g2000cwy.googlegroups.com> <1165391969.824391.174140@l12g2000cwl.googlegroups.com> Message-ID: <7008329d0612060005q7c35c54aic6ad64acbff75103@mail.gmail.com> Hi I was looking for something similar in the past and could not find it. It would be very useful to have Python applets in web pages. What would you use them for? kind regards Andr? On 5 Dec 2006 23:59:29 -0800, S?bastien Ramage wrote: > > des exemples de plugins pour IE oui mais qui ne sont pas embarqu? dans > une page Web > je souhaiterai cr?er qqchose qui ressemble vraiment ? Java VM ou > Flash > J'ai trouv? un d?but de r?ponse pour Firefox en t?l?charger le > GeckoSDK > mais je n'arrive pas ? compiler les exemples pour le moment... > > merci > > > MC a ?crit : > > > Bonjour ! > > > > Pour IE, il y a des exemples de plugins, fournis avec PyWin32. > > Pour FF (comme pour Opera), je ne sais pas. > > > > -- > > @-salutations > > > > Michel Claveau > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Dr. Andre P. Meyer http://python.openspace.nl/meyer TNO Defence, Security and Safety http://www.tno.nl/ Delft Cooperation on Intelligent Systems http://www.decis.nl/ Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams -------------- next part -------------- An HTML attachment was scrubbed... URL: From silverbeach06 at gmail.com Tue Dec 12 12:37:18 2006 From: silverbeach06 at gmail.com (susan) Date: 12 Dec 2006 09:37:18 -0800 Subject: how to bind a command to the open button Message-ID: <1165945038.464128.43320@j44g2000cwa.googlegroups.com> Hi, Anybody knows how to bind a command to the open button at a file browser dialog? I want to add selected files to a scrolllist. Like this: def browseFile(self): file = askopenfilename(filetypes = [("TDF Files", "*.TDF"), ("All Files", "*.*")],multiple=1) ?..... Thanks! From snobis at gmx.de Sun Dec 10 09:05:04 2006 From: snobis at gmx.de (Stefan Nobis) Date: Sun, 10 Dec 2006 15:05:04 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165596641.245385.113090@f1g2000cwa.googlegroups.com> <1165704007.887869.192290@16g2000cwy.googlegroups.com> Message-ID: <87ejr7yhgv.fsf@snobis.de> Steven D'Aprano writes: > Look at us: we're all communicating in a common language, English, > and we all agree on syntax and grammar. Now, I could be a lot more > expressive, and language could be a lot more powerful, if I could > define my own language where "You are a poopy-head" was in fact a > detailed and devastatingly accurate and complete explanation for why > Python was a better language than Lisp. > So it is good that English restricts the expressiveness and power of > the syntax and grammar. While we're talking English, we can both > understand each other, and in fact people who redefine words and > ignore the common meaning of them are often covering weaknesses in > their arguments. Uh, you don't talk often to non-programmers, do you? Talk a bit to non-programmers about your programming habits, why you prefer which programming language and so on. Everything in english. How much do they understand? Ever talked to skateboarders? Other people of different scenes? They are creating new, specialized languages every day. Here in Germany a study was published a little time ago, how few people understand commercials and their slogans. Do you know how many jokes work? Yes, by misunderstandings. Why is this? Because (natural) languages have macros, operator overloading and all this fuss. I'm no expert, I not really studied linguistics, but I would say, you are completley wrong. -- Stefan. From hg at nospam.org Tue Dec 12 12:56:59 2006 From: hg at nospam.org (hg) Date: Tue, 12 Dec 2006 11:56:59 -0600 Subject: how to bind a command to the open button References: <1165945038.464128.43320@j44g2000cwa.googlegroups.com> Message-ID: susan wrote: > Hi, > Anybody knows how to bind a command to the open button at a file > browser dialog? I want to add selected files to a scrolllist. > > Like this: > > def browseFile(self): > > file = askopenfilename(filetypes = [("TDF Files", "*.TDF"), > ("All Files", "*.*")],multiple=1) > > ?..... > > Thanks! why don't you add the result "file" to the list ? From jon at ffconsultancy.com Mon Dec 11 08:21:31 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Mon, 11 Dec 2006 13:21:31 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165332936.164364.190860@73g2000cwn.googlegroups.com> <457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> konrad.hinsen at laposte.net wrote: > On 10.12.2006, at 11:23, Jon Harrop wrote: >> F# addresses this by adding operator overloading. However, you have >> to add more type annotations... > > That sounds interesting, but I'd have to see this in practice to form > an opinion. As long as F# is a Windows-only language, I am not > interested in it anyway. F# runs under Linux with Mono. >> OCaml already supports 9 architectures and optimised to AMD64 >> earlier than gcc. How many do you want? > > It's not a matter of number, it's a matter of availability when new > processors appear on the market. How much time passes on average > between the availability of a new processor type and the availability > of a native code compiler for OCaml? OCaml had AMD64 support before many other language. It had a better optimiser before gcc... -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From kentilton at gmail.com Sat Dec 16 01:43:01 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 16 Dec 2006 01:43:01 -0500 Subject: merits of Lisp vs Python In-Reply-To: <4uhfo9F17usriU1@mid.individual.net> References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> <1166175804.202131.54070@l12g2000cwl.googlegroups.com> <4uhfo9F17usriU1@mid.individual.net> Message-ID: greg wrote: > Ken Tilton wrote: > >> McCarthy: "Is code also data in Python?" >> Norvig: "No." > > > I don't think that was the right answer. Norvig is a smart guy. He was talking to John McCarthy. He gave the right answer. :) > He should have > said "Yes", and then shown McCarthy eval() and exec. No, in those cases the Python interpreter is still dealing with the code, not the user's application code. As a meta-developer (to coin a word) I want to be able to write code that takes apart other code I write to do useful things with it /without writing a parser for my chosen language/. I just found a bug in ACL that might be instructive. The defskill macro I have been writing might be coded like this: (defskill abs-value (category "Algebra I" "Real Numbers") ....) (I am kinda mirroring defclass here, which looks like: (defclass * (*) ...and then optional sub-specs each keyed by the first symbol.. (:documentation "chya") (:metaclass...) (:default-initargs))) Come to think of it, I might have made /my/ options :keywords just to make the resemblance stronger (and yes I am digressing into the bit about how Lispniks by convention stay recognizable with new syntax). Anyway, I decided to do a little auto QA and add an assertion to make sure I did not inadvertently leave out the category option (long story, I am not usually so anal), so defskill starts like this: (defmacro defskill (id &body skill-info) (assert (find 'category skill-info :key 'car))... That is just normal list code. The macro signature destructures the code I write inside the defskill invocation into an id and a list of following code ("&body skill-info" says "bind the rest of the code to the local variable skill-info as a list"). the (find ... :key 'car) walks down the list taking the car (first) of each list and comparing against that which is being sought. Simple ol' Lisp. I then expand the (somewhat) validated data/code: (loop with sub-id = id for (q . q-def) in skill-info collecting (ecase q (category ) ...etc...) q for "quality" or "attribrute". Not "o" for option. :) Again, using standard loop destructuring on the option code/data. Y'all need to get over it: we really are writing code that eats code/data to produce code. Unaided by any parser other than the same destructuring mechanisms we use on data. ken ps. I forgot the bug. I coded in the end: (defskill |Absolute Value| ...etc..) Where |absolute value| should be treated as a single symbol, and is by the ACL compiler. An interactive macroexpand, however, misses that that is one symbol and defskill (if you followed the Lisp) dies trying to take the car of the atom VALUE (a symbol). k From jon at ffconsultancy.com Sun Dec 10 05:25:48 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 10:25:48 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165169117.866499.181520@73g2000cwn.googlegroups.com> <45732974$0$8758$ed2619ec@ptn-nntp-reader02.plus.net> <1165183970.832303.323350@73g2000cwn.googlegroups.com> <45735876$0$8750$ed2619ec@ptn-nntp-reader02.plus.net> <1165252920.329341.284910@j44g2000cwa.googlegroups.com> <1165255758.967262.226400@73g2000cwn.googlegroups.com> <1165267711.364076.292000@79g2000cws.googlegroups.com> Message-ID: <457be14b$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> Carl Banks wrote: > I doubt it would work too well. What about translating the current Python interpreter into a language with a GC, like MLton-compiled SML? That would probably make it much faster, more reliable and easier to develop. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From podi.ex at gmail.com Wed Dec 13 17:17:31 2006 From: podi.ex at gmail.com (Podi) Date: 13 Dec 2006 14:17:31 -0800 Subject: Windows SetLocalTime In-Reply-To: References: <1166040733.947268.80050@16g2000cwy.googlegroups.com> <1166041988.571906.244570@j72g2000cwa.googlegroups.com> Message-ID: <1166048251.411640.69940@n67g2000cwd.googlegroups.com> Thank you. It works :-) P Rob Williscroft wrote: > Ok I see, you will probably need these 2 bits of the ctypes > documentation: > > http://docs.python.org/lib/ctypes-structures-unions.html > http://docs.python.org/lib/ctypes-pointers.html > > From there on geting to this is farly straight forward: From thompson.marisa at gmail.com Wed Dec 20 14:08:21 2006 From: thompson.marisa at gmail.com (thompson.marisa at gmail.com) Date: 20 Dec 2006 11:08:21 -0800 Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects Message-ID: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> Hi. I'm extremely new to Python and programming as a whole. I have written a python script with the assistance of ESRI ArcGIS 9.2, which uses Python 2.4.1, however, it gives me this error when I try to run it. I've already posted at ESRI support, and I was hoping that Python people could help me more. I hope there is something simple I could do to be able to define the object that it thinks is NoneType. Please when someone responds, please treat me as an absolute novice. Thank you, Marisa Here is my code: # --------------------------------------------------------------------------- # towntab92.py # Created on: Wed Dec 20 2006 11:09:59 AM # (generated by ArcGIS/ModelBuilder) # Created by Marisa Thompson # --------------------------------------------------------------------------- # Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create() # Check out any necessary licenses gp.CheckOutExtension("spatial") # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") # Define workspace gp.workspace = "F:/Marisa/inputfolder" # Define Variables raster = "F:/Marisa/outputfolder_72/mss-72-spf.img" #Get list of Town Shapefiles Townshp = gp.ListFeatureClasses ("*") #Store path to output folder outputPath = "F:/Marisa/outputfolder_72" # Begin going through the loop Townshp = Townshps.next() while Townshps !="": #Set the output name to be the same as input outName = outputPath + "/" + Townshp + "land" + ".img" Output_table = outputPath + "/" + Townshp + "table" + ".dbf" #For each extract by Mask gp.ExtractbyMask_sa (raster, Townshp, outName) #For each tabluate area gp.TabulateArea_sa (Townshp, "RITOWN5K_", outName, "VALUE", Output_table, "98.425") Townshp = Townshps.next() From colinlandrum at gmail.com Wed Dec 6 11:50:27 2006 From: colinlandrum at gmail.com (hubritic) Date: 6 Dec 2006 08:50:27 -0800 Subject: Looking for a decent HTML parser for Python... In-Reply-To: References: Message-ID: <1165423827.282061.224520@j44g2000cwa.googlegroups.com> Agreed that the web sites are probably broken. Try running the HTML though HTMLTidy (http://tidy.sourceforge.net/). Doing that has allowed me to parse where I had problem such as yours. I have also had luck with BeautifulSoup, which also includes a tidy function in it. Just Another Victim of the Ambient Morality wrote: > "Just Another Victim of the Ambient Morality" wrote > in message news:Gordh.303466$tl2.18227 at fe10.news.easynews.com... > > > > Okay, I think I found what I'm looking for in HTMLParser in the > > HTMLParser module. > > Except it appears to be buggy or, at least, not very robust. There are > websites for which it falsely terminates early in the parsing. I have a > sneaking feeling the sgml parser will be more robust, if only it had that > one feature I am looking for. > Can someone help me out here? > Thank you... From chrisspen at gmail.com Thu Dec 21 16:06:33 2006 From: chrisspen at gmail.com (Chris) Date: 21 Dec 2006 13:06:33 -0800 Subject: Decorator for Enforcing Argument Types In-Reply-To: <458af55a$0$2251$4c368faf@roadrunner.com> References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458af55a$0$2251$4c368faf@roadrunner.com> Message-ID: <1166735193.253430.43110@42g2000cwt.googlegroups.com> On Dec 21, 3:57 pm, "Paul McGuire" wrote: > "Chris" wrote in messagenews:1166734180.455471.164910 at 79g2000cws.googlegroups.com... > > > I'm not sure if this has been done before, but I couldn't easily find > > any prior work on Google, so here I present a simple decorator for > > documenting and verifying the type of function arguments. > > Feedback/suggestions/criticism is welcome.They Python wiki has a page for decorator ideas/submissions, compare yours > to this one:http://wiki.python.org/moin/PythonDecoratorLibrary#head-308f2b3507ca9... Thanks, I was unaware of that page. I designed mine allow for introspection, so the program can explicitly "see" what types a function takes and test argument combinations if need be, which that example doesn't seem to allow. Mine also supports multiple types per argument. However, I like how that one also checks the return value. Chris From smartbei at gmail.com Sun Dec 24 08:19:20 2006 From: smartbei at gmail.com (smartbei) Date: 24 Dec 2006 05:19:20 -0800 Subject: Help with small program Message-ID: <1166966360.384179.101400@48g2000cwx.googlegroups.com> Hello, I am a newbie with python, though I am having a lot of fun using it. Here is one of the excersizes I am trying to complete: the program is supposed to find the coin combination so that with 10 coins you can reach a certain amoung, taken as a parameter. Here is the current program: coins = (100,10,5,1,0.5) anslist = [] def bar(fin, hist = {100:0,10:0,5:0,1:0,0.5:0}): s = sum(x*hist[x] for x in hist) l = sum(hist.values()) if s < fin and l < 10: for c in coins: if (s+c) <= fin: hist[c] += 1 bar(fin, hist) hist[c] -= 1 elif l==10 and s==fin and not hist in anslist: #p1 anslist.append(hist) bar(50) print anslist The problem is that if I run it, anslist prints as [{0.5: 0, 1: 0, 10: 0, 100: 0, 5: 0}], which doesnt even add up to 50. When I check how many times the program has reached the #p1 by sticking a print there, it only reaches it once, and it comes out correct. why is it that this result is replaced by the incorrect final one? From http Sun Dec 10 07:33:36 2006 From: http (Paul Rubin) Date: 10 Dec 2006 04:33:36 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <7xfybpb9pe.fsf@ruckus.brouhaha.com> <457bd1a5$0$8740$ed2619ec@ptn-nntp-reader02.plus.net> <7xslfoqedm.fsf@ruckus.brouhaha.com> <457bdbba$0$8730$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <7xirgkhqvz.fsf@ruckus.brouhaha.com> Jon Harrop writes: > Yes. My point is that I only had to add four locks in 15kLOC of F# code > because my code was almost entirely pure. But that's like saying you only had to call malloc in 4 different places, which means dealing with freeing, buffer overruns, etc. As soon as you use any locks at all, you're susceptable to all the headaches of dealing with locks. Anyway this is turning into ML vs. Haskell, maybe an improvement on Lisp vs. Python but still OT. > So F# is a long way towards that Haskell ideal whilst having many > other advantages over Haskell, like predictable memory usage. F# is pretty similar to ML, right? Hmm. Haskell's memory usage issues stem more from laziness than purity. One could imagine a strict Haskell dialect that was still pure (I think ML is heading in that direction) but that would throw out a lot of Haskell coolness. Does OCaml support parallel threads at all? I mean using multiple cpu's simultaneously. I thought it didn't and this was one of the factors that got me to make the leap into Haskell. From brenNOSPAMbarn at NObrenSPAMbarn.net Mon Dec 4 13:52:34 2006 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Mon, 04 Dec 2006 18:52:34 GMT Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: Russ wrote: > Every Python programmer gets this message occasionally: > > IndexError: list index out of range > > The message tells you where the error occurred, but it doesn't tell > you what the range and the offending index are. Why does it force > you to determine that information for yourself when it could save > you a step and just tell you? This seems like a "no-brainer" to me. > Am I missing something? I think the same could be said of virtually all exceptions. What I think would be ideal is that whenever an exception is raised, the traceback tells you: 1) What the exception is 2) The names of the variables involved in the offending expression (or their character position in the line) 3) The values of those variables This would be especially useful in cases where you have some long expression and you get a "cannot concatenate str and list" or whatever. The irritating thing about this as it is is that you cannot tell which variables in the expression are causing the problem. I realize that in some cases the offending expression may not be a single variable, but I am curious whether it would be possible for something like this: "1" + "2" + "3" + "4" + 5 + "6" To point to the actual addition that raises the exception (somewhat like it does for a syntax error), instead of just saying "there is an error somewhere in this line". -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From aboudouvas at panafonet.gr Fri Dec 29 04:39:45 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 29 Dec 2006 01:39:45 -0800 Subject: db access In-Reply-To: References: <1167320723.501187.98810@h40g2000cwb.googlegroups.com> Message-ID: <1167385185.221916.44010@i12g2000cwa.googlegroups.com> Hi Johnf, are you referring to this ? http://www.freetds.org/ And how i can get psmssql.py so i can get a shot on it, is it included in FreeTDS ?? On Dec 29, 12:12 am, johnf wrote: > king kikapu wrote: > > Hi to all, > > > is there a way to use an RDBMS (in my case, SQL Server) from Python by > > using some built-in module of the language (v. 2.5) and through ODBC ?? > > I saw some samples that use statements like "import dbi" or "import > > odbc" but neither modules (dbi, odbc) are present on my system... > > > Any hint(s) ?? > > > Thanks in advanceAlthough others have suggested using ODBC or ADO I have a different > solution. If you wanted a multi-platform I would use FreeTDS with > psmssql.py. psmssql.py does support the DB API 2.0 although it does not > support any of the extendsions. Works with Linux, Mac and Windows. > > Johnf From george.sakkis at gmail.com Wed Dec 20 19:04:43 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 20 Dec 2006 16:04:43 -0800 Subject: def index(self): References: <4587017b$0$22957$426a34cc@news.free.fr> <458807cc$0$19743$426a74cc@news.free.fr> <45891cb7$0$16994$426a34cc@news.free.fr> Message-ID: <1166659483.225301.48550@t46g2000cwa.googlegroups.com> Gert Cuykens wrote: > > > class HelloWorld(object): > > > @cherrypy.exposed > > > def index(self): > > > return "Hello World" > > do i have to write @cherrypy.exposed before every def or just once for > all the def's ? and why not write something like @index.exposed ? > > in other words i have no idea what @ actually does i only know i have > too write it to make it work :) Am guessing @ is something like > prototyping in javascript but then def index is not a object but a > method ? So that would not make sense ? > > oh and self stands more or less for private method right ? Ouch. Do you really expect to learn a language from scratch by Q&A in a malining list ? That's a very inefficient way to spend both yours and others' time. Do your homework first by reading one of the several free tutorials online and come back when you have trouble with something specific you didn't understand. George From simon at renderIHATESPAMmania.com Thu Dec 7 18:25:14 2006 From: simon at renderIHATESPAMmania.com (Simon Bunker) Date: Thu, 07 Dec 2006 23:25:14 +0000 Subject: per instance descriptors In-Reply-To: <1165501121.478553.124220@j72g2000cwa.googlegroups.com> References: <45777908_4@mk-nntp-2.news.uk.tiscali.com> <1165467481.033283.118340@f1g2000cwa.googlegroups.com> <1165495941.777701.255580@79g2000cws.googlegroups.com> <1165501121.478553.124220@j72g2000cwa.googlegroups.com> Message-ID: <4578A2DA.1090700@renderIHATESPAMmania.com> George Sakkis wrote: > simon at rendermania.com wrote: > > >>George Sakkis wrote: >> >>>Simon Bunker wrote: >>> >>> >>>>Hi I have code similar to this: >>>> >>>>class Input(object): >>>> >>>> def __init__(self, val): >>>> self.value = val >>>> >>>> def __get__(self, obj, objtype): >>>> return self.value >>>> >>>> def __set__(self, obj, val): >>>> # do some checking... only accept floats etc >>>> self.value = val >>>> >>>>class Node(object): >>>> >>>> a = Input(1) >>>> b = Input(2) >>>> >>>>I realise that a and b are now class attributes - however I want to do this: >>>> >>>>node1 = Node() >>>>node2 = Node() >>>> >>>>node1.a = 3 >>>>node.b = 4 >>>> >>>>And have them keep these values per instance. However now node1.a is 4 >>>>when it should be 3. >>>> >>>>Basically I want to have the Input class as a gateway that does lots of >>>>checking when the attibute is assigned or read. >>>> >>>>I have had a look at __getattribute__(), but this gets very ugly as I >>>>have to check if the attribute is an Input class or not. >>>> >>>>Also I don't think property() is appropriate is it? All of the >>>>attributes will essentially be doing the same thing - they should not >>>>have individual set/get commands. >>>> >>>>Is there any way of doing this nicely in Python? >>> >>>What about __setattr__ ? At least from your example, checking happens >>>only when you set an attribute. If not, post a more representative >>>sample of what you're trying to do. >>> >>>George >> >>Yes, but I am setting it in the Node class aren't I? Wouldn't I need to >>define __setattr__() in class Node rather than class Input? I don't >>want to do this. Or am I getting confused here? > > > Yes, __setattr__ would be defined in Node and Input would go. It seems > to me that the only reason you introduced Input was to implement this > controlled attribute access, and as you see it doesn't work as you want > it to. Why not define Node.__setattr__ ? > > George > The __setattr__ approach is what I am hoping to avoid. Having the input class means that I just need to assign a class to an attribute rather than having to filter each attribute name - really annoying as there will be several classes similar to Node with different attributes, but which should be handled in the same way. Frankly descriptors seems exactly what I want - but having them as class attributes makes them completely useless! Simon From whiterabbott at gmail.com Sun Dec 3 20:59:30 2006 From: whiterabbott at gmail.com (Dawn Abbott) Date: Sun, 3 Dec 2006 17:59:30 -0800 Subject: Joining data from three different files to be written into three Columns In-Reply-To: References: Message-ID: Everything works in my program except for when it prints out the number is surrounded by brackets but I need to print the number without the brackets. Does anyone know an easy way to do this? #!/usr/bin/env python import array fin = open('relative_x.INT32','rb') fin1=open('relative_y.INT32','rb') fin2=open('income.INT32','rb') outfile=open('test.txt','w') data=[] data1=[] data2=[] while True: try: myInts=array.array('l') myInts.fromfile(fin,1) data.append(myInts.tolist()) myInts1=array.array('l') myInts1.fromfile(fin1,1) data1.append(myInts1.tolist()) myInts2=array.array('l') myInts2.fromfile(fin2,1) data2.append(myInts2.tolist()) data3=zip(data,data1,data2) except EOFError: break for record in data: print record[0],record[1],record[2] thanks Dawn -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py at yahoo.com.ar Thu Dec 14 21:25:17 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 14 Dec 2006 23:25:17 -0300 Subject: merits of Lisp vs Python In-Reply-To: <45812f4c$0$26482$426a74cc@news.free.fr> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> <87lklcrt00.fsf@thalassa.informatimago.com> <457fdb92$0$13245$426a74cc@news.free.fr> <45812f4c$0$26482$426a74cc@news.free.fr> Message-ID: <7.0.1.0.0.20061214225635.05a04e68@yahoo.com.ar> Warning: absolutely off topic! At Thursday 14/12/2006 08:02, Christophe wrote: >Well, I spent some time on Wikipedia looking up metric systems and >things like that because of you, and I found a page that shows how to >improve the current SI system by reducing the number of fundamental >units to only two ( S for space and T for time ), and it was a great >read. It even went so far as give a theory for the disapearance of the >dinosaurs! You can even make S = cT (c=ligth of speed in void space). The choice of fundamental units is rather arbitrary, and can be reduced further to only 1 fundamental unit and even NO fundamental units. There is a nice book about this subject by L. A. Sena: Units of physical quantities and their dimensions (or similar, I don't have it at hand to check the title). -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From jonathan.beckett at gmail.com Thu Dec 28 12:32:06 2006 From: jonathan.beckett at gmail.com (jonathan.beckett) Date: 28 Dec 2006 09:32:06 -0800 Subject: Some basic newbie questions... In-Reply-To: <12p7veqbmuga1ea@corp.supernews.com> References: <1167324002.516960.319870@79g2000cws.googlegroups.com> <1167325306.545679.185300@48g2000cwx.googlegroups.com> <12p7veqbmuga1ea@corp.supernews.com> Message-ID: <1167327126.640045.300380@48g2000cwx.googlegroups.com> > > I normally work with PHP, C#, Javascript, and the odd bit of C++, > > Do any of them call functions w/o parens? That's a really good point :) From max at alcyone.com Sat Dec 30 18:22:04 2006 From: max at alcyone.com (Erik Max Francis) Date: Sat, 30 Dec 2006 15:22:04 -0800 Subject: python , Boost and straight (but complex) C code In-Reply-To: References: <0d2dnZZ8as4TSgvYnZ2dnUVZ_q_inZ2d@speakeasy.net> Message-ID: Osiris wrote: > yes, but C can be compiled with a C++ compiler, One can put C code in > C++ source.... Boost should not complain... should it ? > Boost text is all about C++.. so... C should not be a problem... That you're dealing with a `boost` namespace below clearly indicates that you're dealing with C++ code throughout, not C, contrary to what you had claimed. C and C++ are not the same language. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis The enemy of my enemy is my friend. -- (an Arab proverb) From robert.kern at gmail.com Mon Dec 4 04:55:35 2006 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 04 Dec 2006 03:55:35 -0600 Subject: Why not just show the out-of-range index? In-Reply-To: <1165223084.558617.9570@79g2000cws.googlegroups.com> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> Message-ID: Russ wrote: > Robert Kern wrote: > >> Nothing is going to happen until you do one of these two things. Being more rude >> (and yes, you are being incredibly rude and insulting) won't move things along. > > I re-read the thread, and I don't see anywhere where I was rude except > in reply to rudeness by others. Sorry, but I haven't mastered the "turn > the other cheek" thing yet. Learn quickly if you are going to keep asking for other people's help. > My suggestion that it would be much easier for the Python maintainers > than for me to implement the requested feature is just basic common > sense. I would have to spend many hours or days just to familiarize > myself with the code, but they are obviously already very familiar with > it. And they would probably have to spend nearly as much time checking > my patch as they would writing it themselves anyway. You're still missing the other side of the balance: how much the person wants the feature. I simply don't care enough about the issue to put in the effort that it would take me. You don't care enough, either, to put in the effort that it would take you. That's fine. That's your judgment to make. What's disrespectful is your expectation that you can make that judgment call for other people. Just because it might take me less time to do it doesn't mean that I am obliged to want it as much as you do. > By the way, your parenthical assertion that I am "being incredibly rude > and insulting" is itself an unwarranted and devious insult, and I will > not let you get away with it without being called on it. As you wish. Insults are in the ear of the listener, not the speaker. With that rule in mind, however, what I said is a simple statement of fact. If the statement of facts insults you, I'm sorry. You are going to have a very difficult time here. You're also missing that *I'm trying to help you*. The way that you have been acting, regardless of whether you think it is rude or not, will not convince anyone to solve your problem. In short, you've asked for a feature in the hope that someone will think it important enough to do it themselves. No one who has read the thread does. At least, not in the time frame since you've posted. That may change; in which case, you should submit the bug report so that the core developers who didn't read this thread (i.e. nearly all of them) will see it. Maybe they will be in a small-feature-implementing mood and will want to implement it. If you don't submit the bug report, odds are everyone will forget all about it. Or you can take this as a learning opportunity, and make the fix yourself. Then the next time you run into something like this (and I imagine that you will), you can take the two minutes to fix it. > But I'm > willing to forget about it and move on, and I'll assume you are too. Submit the bug report, and I will. -- 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 From banaouas.medialog at wanadoo.fr Sun Dec 10 08:43:55 2006 From: banaouas.medialog at wanadoo.fr (m.banaouas) Date: Sun, 10 Dec 2006 14:43:55 +0100 Subject: apache & mod_python In-Reply-To: <1165712433.927674.323000@f1g2000cwa.googlegroups.com> References: <4579472d$0$5066$ba4acef3@news.orange.fr> <1165577057.325812.47140@f1g2000cwa.googlegroups.com> <1165712433.927674.323000@f1g2000cwa.googlegroups.com> Message-ID: <457c0eb2$0$25909$ba4acef3@news.orange.fr> thanks for your answers The plateform I target is Windows XP (no body is perferct ...). Concerning multithread , is simultaneous multi http client calls can present any problem ? I don't think because usually http server fires a different process for each client call, while Threading is discussed within the same process, isn't it? I'm still looking for mod_python 3.2.10 to install it with apache 2.2.3 It seems like I must "build" it before use it. If there is no other mean I will do it but usually I retrieve "ready to use" kits. Graham Dumpleton a ?crit : > Maxim Sloyko wrote: >> m.banaouas wrote: >> >>> Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent >>> versions) without facing any known major issue ? > > Only that to use Apache 2.2 you must have mod_python 3.2.10 or later, > older versions of mod_python do not work with the more recent version > of Apache. > >> Works fine for me. >> The only "known major issue" you can face is general non-threadsafety >> of Python interpreter. So, if you are using Apache MPM, you have to >> allow for it, or use framework that does it for you. > > You answer here is a bit misleading. There are no issues with the > thread safety of the Python interpreter per-se. However, as with any > Python application, whether mod_python is used or not, if multiple > threads are being used your application code may have to be written so > as to cope with access to code/data from multiple threads at the same > time. This is not anything unique to mod_python. > > Whether this will be an issue or not is dependent on which Apache MPM > is used, not that the Apache MPM is used as one will always be used. > The specific Apache MPMs where multithreading has to be taken into > consideration are "winnt" on Windows platforms and "worker" on UNIX > platforms. What this all means is that when these MPMs are used there > can be concurrent request handlers executing in distinct threads within > the same Apache processes. Thus, where common data is accessed, it has > to be adequately protected. > > For further details on the Apache/mod_python process/interpreter/thread > model, see: > > > http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel > > That said, there are sometimes threading issues with mod_python but it > is more to do with the fact that mod_python can use multiple > interpreter instances within a single process. Also, the problems are > not a problem in mod_python, but result from third party C modules for > Python being used which take the simple path of using the simplified > thread API for working with the GIL. Such modules often will not work > properly when used from secondary Python interpreter instances. In > these cases it is a simple matter of telling mod_python to handle > requests which are dependent on those modules within the main Python > interpreter, ie., the very first one which gets created. Where third > party C modules use the full thread API for Python properly, it doesn't > matter which interpreter instance they are used from. > > Graham > From greg at cosc.canterbury.ac.nz Fri Dec 15 06:18:13 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:18:13 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7xpsankoc6.fsf@ruckus.brouhaha.com> Message-ID: <4ufemiF17of60U2@mid.individual.net> Ken Tilton wrote: > So this: > (defmethod tf-reverse (id (eql ',sub-id)) resx (drv-opnds tf drv)) > , at reverser) > > becomes this: > > (defmethod tf-reverse ((id (eql ',sub-id)) tf drv > &aux (opnds (drv-opnds tf drv))) > (loop for resx in (results drv) > , at reverser)) I don't see why you can't just write a function that loops over the results and calls the user's reversal function for each one. def reverse_multiple(skill, resx_list, opnds): for resx in rex_list: skill.reverse(resx, opnds) There's no need to macro-expand this code into every reversal function, when it can be done once as part of the framework that calls the reversal functions. -- Greg From larry.bates at websafe.com Mon Dec 4 12:16:57 2006 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 04 Dec 2006 11:16:57 -0600 Subject: Ensure a variable is divisible by 4 In-Reply-To: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com> Message-ID: geskerrett at hotmail.com wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. > Use modulo operator '%' if not x % 4: # # Arrive here if x is modulo 4 divisable # -Larry Bates From gagsl-py at yahoo.com.ar Thu Dec 14 04:13:21 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 14 Dec 2006 06:13:21 -0300 Subject: variables with dynamicly generated names In-Reply-To: References: Message-ID: <7.0.1.0.0.20061214061202.05332d20@yahoo.com.ar> At Thursday 14/12/2006 05:50, avlee wrote: >Is it possible to use in python variables with dynamicly created names ? >How ? Use a dictionary: d = {} d[almost_arbitrary_key] = value -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From eadmund42 at NOSPAMgmail.com Tue Dec 12 12:30:40 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 10:30:40 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165867527.389209.80660@f1g2000cwa.googlegroups.com> Message-ID: "HowiPepper" writes: > I have checked out Lisp several times in the past, but I always get > turned off completely by the parenthesis you have to use for > everything. What's up with that anyway? It's no different from having to use newlines and spaces and square brackets and parentheses in Python. E.g. the Lisp (f x y) is exactly equivalent to the Python f(x, y); the Lisp (if x y z) is exactly equivalent to the Python: if x: y else: z There is, though, an advantage: (f x y) and (if x y z) aren't just parts of programs--they're also lists. That means that one can use all the list-manipulation primitives on a program, and thus that it's very easy to write programs which manipulate programs. This in turn leads to being able to extend the syntax of the language. Imagine if one could write this in Python: defsyntax unless(condition, commands): if not condition: commands And use it like this: unless day == 'Sunday': work() That'd be pretty cool, right? After all, 'unless day is Sunday' conveys the sense of what you're doing a little better than 'if days is not Sunday.' But in Python it's not possible--even my defsyntax example is absurd: how would the compiler know the difference between pre-colon argument and the command block? What if I wanted multiple blocks (e.g. as with an else:)? Whereas with Lisp one might simply write: (defmacro unless (condition &body commands) `(if (not ,condition) , at commands)) When used as: (unless (equal day "Sunday") (work)) The compiler transforms it into: (if (not (equal day "Sunday")) (work)) This is a _really_ simple example (unless is nice, but it's hardly vital); but what one can do is end up making a much more declarative program by creating new syntax to describe stuff. > With Python's ease of learning and use, availability of a large number > of libraries, extremely active development community and large > user-base, I'd say the question to ask is what specific advantages > over Python does Lisp offer, to make people switch to it? Well, these come to mind; they're in no order and are just my own particular thoughts. No doubt more reflective commentators can come up with a better list. o Macros As mentioned above, macros can make one's life significantly nicer. I use Python a lot (it's currently a better choice than Lisp for many of the problems I face), and I find myself missing macros all the time. The ability to take some frequently-used idiom and wrap it up in a macro is wonderful. E.g. a common idiom in Python is: file = open(path, 'r') for line in file.readlines(): foo(line) bar(line) baz(line) Even this isn't much nicer: for line in open(path, 'r').readlines(): foo(line) bar(line) baz(line) Wouldn't it be nice to have a macro with-open-file? filefor line in path: foo(line) bar(line) baz(line) o Speed Lisp interpreters are several orders of magnitude faster than Python, and Lisp compilers are faster yet. Speed's not the most important thing, but it is _an_ important thing; all other things being equal, the faster solution is better. o Symbols In Lisp, a symbol is essentially a hashed string; two symbols are alike if their names are alike, but comparison of symbols is a constant-time operation. Thus where in Python I have lots of string comparisons for constants, and in C I have #defined integers, in Lisp I have symbols. It's not just a performance hack--symbols are part of why macros and packages work--but when I miss them, I miss them for the performance side of things o CLOS The Common Lisp Object System is a really remarkable piece of work. Among other things, it has generic functions instead of methods. E.g. in Python or most other OO languages object.method(arg1, arg2) is really just a fancy piece of syntactic sugar for method(object, arg1, arg2); method does different things depending on the type of object, its first argument. Wouldn't it be nice to be able to specialise a method on _any_ subset of its arguments, not just its first one? Well, CLOS offers that. (method object1 object2) could be specialised on the first argument, the second or both. This can be very powerful. Wouldn't it be nice to specify that some action be taken before or after a superclass's method, rather than over-riding that method entirely? Sure, one can over-ride the method and then call it within one's own code, but that obscures the meaning of what one's doing. o CLSQL An OR mapper which actually works. 'Nuff said. OTOH, here's what Python offers which Lisp doesn't: o A capable standard library Lisp's standard library was considered large once upon a time--why, it included lists and hashes! But that's not a big deal nowadays. Right now there are a plethora of choices, but it's not clear which choices are blessed or particularly good. Sure, once could use a different MIME library than Python offers as standard, but it's good to know that there _is_ a standard. o A large, friendly community Lisp's community is small and exceedingly bright; it doesn't suffer fools gladly. Python's is larger and friendlier, realising that we were all fools once and that with education many of us get better. o Top-notch Web frameworks Pylons and Django are nice to use and take care of a lot of the boilerplate one would otherwise have to write. While Webactions is a very cool framework, it lives at a lower level and there's a lot more one has to add to it for a complete app. -- Robert Uhl People who are willing to rely on the government to keep them safe are pretty much standing on Darwin's mat, pounding on the door, screaming, `Take me, take me!' --Carl Jacobs From frank at niessink.com Fri Dec 15 11:38:59 2006 From: frank at niessink.com (Frank Niessink) Date: Fri, 15 Dec 2006 17:38:59 +0100 Subject: Has comparison of instancemethods changed between python 2.5 and 2.4? Message-ID: <4582CFA3.5040305@niessink.com> Hi, I'm trying to get an application working with Python 2.5 that works fine with Python 2.4. This issue occurs both on Windows XP as well as on Mac OSX. Some context: I use the publisher/subscribe pattern. Observers can register a callback with a central 'Publisher' like this: def registerObserver(self, observer, eventType): ''' Register an observer for an event type. The observer is a callback method that should expect one argument, an instance of class Event defined above. The eventType can be anything hashable, typically a string. ''' observerList = self.__observers.setdefault(eventType, []) if observer not in observerList: observerList.append(observer) Now, with Python 2.5 (and not with Python 2.4) I have a callback that is not being added to the list because, apparently, it compares equal to some of the callbacks already in the list. However, the instance the two methods belong to are different, i.e. id(callback) returns different values for the two methods. Both callbacks are of type . Further investigation shows that "observer == observerList[1]" is True. Has instancemethod.__cmp__ changed between python 2.4 and 2.5? Thanks, Frank From paul at boddie.org.uk Mon Dec 4 14:49:32 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 4 Dec 2006 11:49:32 -0800 Subject: Python bindings for RCS apps References: <1165256344.935217.229680@j72g2000cwa.googlegroups.com> Message-ID: <1165261772.483822.136010@f1g2000cwa.googlegroups.com> riklaunim at gmail.com wrote: > There is pySVN for subversion but does other revision control system > systems have some good python bindings/apis ? with good docs and some > examples. Here are some starting points for some different systems: Bazaar ------ Something about the structure of bzrlib: http://bazaar-vcs.org/Classes Writing plugins: http://bazaar-vcs.org/WritingPlugins Mercurial --------- Writing extensions: http://www.selenic.com/mercurial/wiki/index.cgi/ExtensionHowto CVS/RCS ------- The ViewVC project deals with CVS repositories and RCS files: http://www.viewvc.org/ The cvs2svn tool might be useful: http://cvs2svn.tigris.org/ You might also want to search for repository converters, especially if your interest is focused on CVS, since many people seem to have been interested in migrating from CVS at some point. Paul From tomas at fancy.org Fri Dec 29 04:38:47 2006 From: tomas at fancy.org (Tom Plunket) Date: Fri, 29 Dec 2006 01:38:47 -0800 Subject: Starting a child process and getting its stdout? References: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> <7vl9p2h7f7adsbn6d6tfpmluera3njnb6g@4ax.com> Message-ID: Tom Plunket wrote: > while p.poll() == None: > data = p.stdout.readline() > if data: > print data, If you change that print to something more decorated, like, print 'process said:', data, Then it might be more obvious where/how the print statements are getting routed. Keep in mind that readline() will return one line at a time, and that line will end with a newline, although the last line you get (at EOF) may not have one. again, good luck. Hope this helps, -tom! -- From george.sakkis at gmail.com Thu Dec 7 16:52:33 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 7 Dec 2006 13:52:33 -0800 Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> <1165500649.129625.213300@j44g2000cwa.googlegroups.com> Message-ID: <1165528352.978586.248960@16g2000cwy.googlegroups.com> Danny Colligan wrote: > > Is there a list somewhere listing those not-so-obvious-idioms? > > I don't know about lists of not-so-obvious idioms, but here's some > gotchas (there may be some overlap with what you're asking about): > > http://zephyrfalcon.org/labs/python_pitfalls.html > http://www.ferg.org/projects/python_gotchas.html > http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html > > Danny I'm surprized that none of these pages mentions the incompatible type comparison gotcha: >>> 5 < "4" True I'm sure this has bitten many folks, particularly (ex) Perl'ers. George From tomas at fancy.org Mon Dec 25 20:29:19 2006 From: tomas at fancy.org (Tom Plunket) Date: Mon, 25 Dec 2006 17:29:19 -0800 Subject: textwrap.dedent replaces tabs? References: <1166310662.825674.128700@l12g2000cwl.googlegroups.com> <232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com> Message-ID: Frederic Rentsch wrote: > It this works, good for you. I can't say I understand your objective. > (You dedent common leading tabs, except if preceded by common leading > spaces (?)). I dedent common leading whitespace, and tabs aren't equivalent to spaces. E.g. if some text is indented exclusively with tabs, then the leading tabs are stripped appropriately. If some other text is indented with common leading spaces, those are stripped appropriately. If the text to be stripped has some lines starting with spaces and others starting with tabs, there are no /common/ leading whitespace characters, and thus nothing is stripped. > Neither do I understand the existence of indentations made up of tabs > mixed with spaces, but that is another topic. At one point it was a fairly common cry in the How To Indent Python discussions. Maybe that cry has faded. > I have been wasting a lot of time with things of this nature coding > away before forming a clear conception in my mind of what my code was > supposed to accomplish. Sounds stupid. Doesn't sound stupid, but there are in fact some fairly straight forward methods that can be put in place to alleviate that problem. > The encounter with the devil in the details can be put off but not > avoided. Best to get it over with from the start and write an exhaustive > formal description of the problem. Follows an exhaustive formal > description of the rules for its solution. Good lord, that's an amazingly 1970s way to look at programming! Modern software engineering practices have in some ways made these problems go away. > In other words, coding should be the translation of a logical system > into a language a machine understands. It should not be the construction > of the logical system. This, anyway, is the conclusion I have arrived > at, to my advantage I believe. To each their own, eh? I've been doing this a long time and have found that it is by far superior (for me) to refine the logical system as it is being implemented, as long as the business rules are encoded in such a way as to disallow the programmer from straying beyond them. My unit tests are far from exhaustive, but with code this simple it didn't seem terribly important since I was doing it more as a proof of concept, proving that I could do this sort of thing in not-many-more- lines-than-the-original-code-that-does-not-operate-to-its-published- specification. -tom! -- From sebastian.hilbert at gmx.net Thu Dec 21 16:04:51 2006 From: sebastian.hilbert at gmx.net (Sebastian Hilbert) Date: Thu, 21 Dec 2006 22:04:51 +0100 Subject: GNUmed - new version released Message-ID: <200612212204.51571.sebastian.hilbert@gmx.net> Hello, Today we are releasing a new GNUmed version. GNUmed is a package to manage medical offices. Version is up to 0.2.3 Version features and bug fixes are explained in our Wiki http://wiki.gnumed.de/bin/view/Gnumed/ReleaseStatus http://wiki.gnumed.de/bin/view/Gnumed/RoadMap Packages available as usual for GNU/Linux and MS Windows als well as Debian packages MacOSX packages didn't make it yet due to unexplained problems with the Mac port. In general it looks like the code is getting much more stable and easier to fix and extent. Bug reports are appreciated. -- Sebastian Hilbert Leipzig / Germany [www.gnumed.de] -> PGP welcome, HTML ->/dev/null From http Sun Dec 10 04:39:01 2006 From: http (Paul Rubin) Date: 10 Dec 2006 01:39:01 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <7xfybpb9pe.fsf@ruckus.brouhaha.com> <457bd1a5$0$8740$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <7xslfoqedm.fsf@ruckus.brouhaha.com> Jon Harrop writes: > I discovered this recently with F#. Although F# (as a dialect of OCaml) is > impure like Lisp, it does make purely functional programming easy and > provides many purely functional data structures. I translated 15kLOC of > mostly-functional OCaml code into F# and only had to add four locks to make > the whole library concurrent. The idea of the composable-STM stuff is to not add locks at all, just mark sections as atomic and the right stuff happens automagically (i.e. you never have to worry about deadlock), including when you nest such sections. Its performance also exceeds traditional locking. But it relies on Haskell's purity. From bearophileHUGS at lycos.com Wed Dec 20 06:44:25 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 20 Dec 2006 03:44:25 -0800 Subject: array, a better shell Message-ID: <1166615065.807704.12480@48g2000cwx.googlegroups.com> For array.array "B" means unsigned char, and such arrays accept to be initialized from (str) strings too, this is quite useful: >>> from array import array >>> a = array("B", "hello") But it seems such capability isn't shared with the append: >>> a.extend("hello") Traceback (most recent call last): File "", line 1, in TypeError: an integer is required ------------------------ I like a lot the Python shell, it helps me in many different situations. I have tried some Python shells: - the vanilla one from DOS - the one from ActivePython IDE - the one from SPE - ipython from a DOS shell But none of them has what I'd like. ipython tries to be a better shell, but I don't want more complexity and more commands/tricks to remember, I want something more interactive, that's simpler and more powerful to use, and not something (much) more complex. Much less things, but the important ones. Beside the vanilla one, I end using the SPE one (because it has colours on Windows too, and it allows you to paste a piece of interactive shell with the leading >>>, SPE removes them automatically. This is very handy). I have also used the shell of Mathematica. It's quite powerful and it can show graphics too inlined, but globally I don't like it fully because it makes editing small programs a pain (for me). Even if I globally don't like the Mathematica shell, it has a capability that I'd like to have in a basic Python shell too. (NOTE: often when dealing with GUI subtle details make a *big* difference, and it's not easy to use words to describe such interaction details.) This Mathematica shell allows you to edit small programs (like 1-15 lines of code) as input blocks, and later you can click on them and edit them. When you press shift-enter inside a block, that small program runs and its output goes just below it (and not at the end of the current shell log). All the Input Blocks can be edited and run again like that (an Input/Output number tag helps to keep things sorted enough). So it's a cross between a normal stupid shell that's essentially an I/O + visual log, and a bare-bone text editor that allows you to edit one script and run it too. Such capability probably needs a Tk/Wx/Gtk window... ------- (Such interactive sessions can be saved too, and loaded again (they become complex documents), but such ability isn't necessary into a bare-bone shell that I am describing now. I am describing something as simple as possible). Beside that (new) basic shell capability I think I can appreciate two other capabilities: - Automatically saves the last 20 MBytes of textual input/output log inside a "queue" file. Material older than the last 20 MB is removed from the top. - Ability to break the computation (or the printing of VERY long things!) without exiting the shell and the kernel (this is from Mathematica too). Bye, bearophile From ggrp1.20.martineau at dfgh.net Sat Dec 23 19:40:34 2006 From: ggrp1.20.martineau at dfgh.net (Martin Miller) Date: 23 Dec 2006 16:40:34 -0800 Subject: Class constant for extension References: <1166525531.028424.15010@t46g2000cwa.googlegroups.com> Message-ID: <1166920834.281699.142190@f1g2000cwa.googlegroups.com> Yue.Nicholas at gmail.com wrote: > Hi, > > I have written a small prototype Python extension for a C-library. > > I have the methods all sorted out and it is working fine. > > In the C-library, they are various constants of types like string, > integer, float and matrix. I'd like to expose them as READONLY values. > > Is the use of PyMemberDefs a suitable way to provide such access? > > I'd like the user of the extension to be able to do something like > the follow > > import MyExtension > > MyExtension.begin() > mv = MyExtension.minValue > MyExtension.process(MyExtension.versionStr) > MyExtension.end() > > Is someone able to point me to an example code of how I can write my > extension so that the references to those constants can be used in the > above way. > > Regards A couple of years ago I wanted to do something similar for a project I was working on. Below is a snippet of some sample C code from the module's initialization function which should give you an idea of the approach used. It's a limited example and only creates module identifiers for simple integer values, not the more complex types you are interested in, nor does it do anything to make them read only, but it might help get you started. If you find something that addresses these deficiencies, please post your findings. Best, -Martin // snippet #include "Python.h" enum METAtags { kMETA_MojikumiX4051 = 0, kMETA_UNIUnifiedBaseChars = 1, kMETA_BaseFontName = 2 } void initPyExtension() { PyObject *m, *d, *o; m = Py_InitModule4("PyExtension", pyis_methods, PySING_module_documentation, (PyObject*)NULL, PYTHON_API_VERSION); // Add some symbolic constants to the module d = PyModule_GetDict(m); // get modules dictionary PyObject* o = PyInt_FromLong(kMETA_MojikumiX4051); PyDict_SetItemString(d, "idMojikumiX4051", o); Py_INCREF(o); // for dictionary ref PyObject* o = PyInt_FromLong(kMETA_UNIUnifiedBaseChars); PyDict_SetItemString(d, "idUNIUnifiedBaseChars", obj); Py_INCREF(o); PyObject* o = PyInt_FromLong(kMETA_BaseFontName); PyDict_SetItemString(d, "idBaseFontName", obj); Py_INCREF(o); . . . From richardjones at optushome.com.au Sun Dec 10 21:58:38 2006 From: richardjones at optushome.com.au (Richard Jones) Date: Mon, 11 Dec 2006 13:58:38 +1100 Subject: Python Operating System References: <1165790496.985266.221160@f1g2000cwa.googlegroups.com> <4u3jutF15ru88U1@mid.uni-berlin.de> Message-ID: <457cc95e$0$16553$afc38c87@news.optusnet.com.au> Diez B. Roggisch wrote: > Python has no notion of pointers See: http://docs.python.org/lib/module-ctypes.html In particular: http://docs.python.org/lib/ctypes-pointers.html Richard From ptmcg at austin.rr._bogus_.com Sun Dec 24 04:11:02 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 24 Dec 2006 03:11:02 -0600 Subject: some OT: how to solve this kind of problem in our program? References: Message-ID: <458e4426$0$5286$4c368faf@roadrunner.com> "oyster" wrote in message news:mailman.1995.1166935152.32031.python-list at python.org... > 1. first of all, what is the English jargon (Optimize? But I think > this is not a very good keyword :( )for this problem? So I can use it > to search on the internet > 2. is there any free/open lib for this? > 3. I know for some questions(case 1, case 2, and sudoku), we can use > bundles of "FOR...NEXT" loop to program. however I think it is clumsy > and inconvenient, especially when there is many vars > 4. I don't know how to deal with case 3 and case 4 > > > case: > 1. choose x0~x9 from 1~9, and must use all of 1~9, let > x0/(10*x1+x2)+x3/(10*x4+x5)+x6/(10*x7+x8)=1/2 > Since you are working with permutations of [1..9], here is a general framework for problems using those permutations - put your problem definition in the function func, which is successively passed each of the 362880 permutations of the numbers 1-9. On my system, your original code ran in about 11 seconds, and after factoring out invariants, got down to about 1.8 seconds. This little framework takes about 4.5 seconds, but with psyco, cuts down to about 1.3 seconds. -- Paul import time try: import psyco psyco.full() except: pass def prod(lst): return reduce(lambda a,b:a*b,lst,1) def perms(setSize, sampleSize): return prod(xrange(setSize-sampleSize+1,setSize+1)) def permutation(k, s): fact = 1 s = s[:] for j in xrange( 2, len(s)+1): fact = fact * (j-1) idx1 = j - ((k / fact) % j)-1 idx2 = j-1 s[idx1],s[idx2] = s[idx2],s[idx1] return s def permutations(s,sampleSize=None): if sampleSize is None: sampleSize = len(s) k = perms(len(s),sampleSize) for i in xrange(k): yield permutation(i,s) d0,d1 = 1,2 def func(p): a0,a1,a2,b0,b1,b2,c0,c1,c2 = p # do application evaluation here b1b2 = 10*b1+b2 a1a2 = 10*a1+a2 c1c2 = 10*c1+c2 if d1*a0*b1b2*c1c2 + d1*b0*a1a2*c1c2 + d1*c0*a1a2*b1b2 == d0*a1a2*b1b2*c1c2: return sorted( [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] ) else: return None st = time.time() result = [] for p in permutations(range(1,10)): aresult = func(p) if aresult is not None and aresult not in result: result.append(aresult) et=time.time() print 'time elapsed: %.4f s' % (et-st) for [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] in result: print ' %0d %0d %0d %0d' % (a0, b0, c0, d0) print '--- + --- + --- = ---' print ' %0d%0d %0d%0d %0d%0d %0d' %(a1, a2, b1, b2, c1,c2, d1) print From vasudevram at gmail.com Wed Dec 13 10:49:10 2006 From: vasudevram at gmail.com (vasudevram) Date: 13 Dec 2006 07:49:10 -0800 Subject: Sybase module 0.38pre1 released In-Reply-To: References: Message-ID: <1166024950.493236.78590@l12g2000cwl.googlegroups.com> S?bastien Sabl? wrote: > By the way, I forgot to say that new releases can now be downloaded > from this page: > > https://sourceforge.net/project/showfiles.php?group_id=184050 > > regards > > -- > S?bastien Sabl? > Thanks. Vasudev From allison.william at gmail.com Sun Dec 10 17:16:19 2006 From: allison.william at gmail.com (William Allison) Date: Sun, 10 Dec 2006 17:16:19 -0500 Subject: Barry Warsaw Python Webcast at GSFC Message-ID: If anyone is interested, here's a link to it http://isandtcolloq.gsfc.nasa.gov/webcasts.html It's at the bottom of the page. From jfabiani at yolo.com Fri Dec 29 06:35:43 2006 From: jfabiani at yolo.com (johnf) Date: Fri, 29 Dec 2006 03:35:43 -0800 Subject: I want to see all the variables Message-ID: Hi, When I use dir() I don't see the __ underscore items. Is there anything that will show all the private vars and functions? johnf From tactics40 at gmail.com Wed Dec 27 15:13:05 2006 From: tactics40 at gmail.com (tac-tics) Date: 27 Dec 2006 12:13:05 -0800 Subject: Superclass for Errors? Message-ID: <1167250385.193546.125700@h40g2000cwb.googlegroups.com> I have a program which has a GUI front-end which that runs a separate thread to handle all the important stuff. However, if there is a problem with the important stuff, I want the GUI to raise a MessageBox alert to indicate this. For exceptions, I can simply use a catch-all except statement like: try: ... except Exception, error: JOptionPane.showMessageDialog(self, "Error: %s" % error) Only, I want it to catch Errors as well. Right now, I'm using: try: ... except (Exception, TypeError, NameError, RuntimeError, AttributeError), error: JOptionPane.showMessageDialog(self, "Error: %s" % error) I was wondering if there is a superclass for TypeError, NameError, RuntimeError, AttributeError, etc. Normally, I could simply use a regular except: .... but then I don't have access to the error message. So what's the best solution to this problem? From effigies at gmail.com Sat Dec 23 17:58:57 2006 From: effigies at gmail.com (Chris Johnson) Date: 23 Dec 2006 14:58:57 -0800 Subject: Generating all permutations from a regexp In-Reply-To: References: Message-ID: <1166914737.263879.130810@73g2000cwn.googlegroups.com> Thomas Ploch wrote: > Fredrik Lundh wrote: > > Nick Craig-Wood wrote: > > > >> A regular expression matcher uses a state machine to match strings. > > > > unless it's the kind of regular expression matcher that doesn't use a > > state machine, like the one in Python. > > > > > > > > How is the matching engine implemented then? > > I thought regular languages can be described by deterministic / > non-deterministic finite state machines. I am just curious ... Regular expressions are described by N?DFAs, but Perl-compatible regular expressions (which pretty much every language implements now) are not true regular expressions. They are actually Turing complete, and thus have features that cannot be implemented in N?DFAs. From http Tue Dec 12 19:59:58 2006 From: http (Paul Rubin) Date: 12 Dec 2006 16:59:58 -0800 Subject: Is anyone using Python for embedded applications? References: Message-ID: <7xfybktxtd.fsf@ruckus.brouhaha.com> "Carl J. Van Arsdall" writes: > Oh, and if anyone has opinions/facts on why > python should not be used in an embedded platform, I'd like to know > that too. I'm somewhat familiar with pythons needs on a system, but > there are a number of things I am not aware of. Thanks to everyone for > their input! I haven't done it myself but have considered it. For one project (cancelled before a real choice had to be made) I basically decided CPython was too big for the application, both in memory footprint and the amount of code in the interpreter that would have to be audited and maintained. Among other candidates, one of my favorites was Hedgehog Lisp: http://hedgehog.oliotalo.fi/ It's much smaller and simpler as Python, though with nowhere near as many creature comforts. Another possibility was a small JVM. From manstey at csu.edu.au Tue Dec 19 04:29:37 2006 From: manstey at csu.edu.au (manstey) Date: 19 Dec 2006 01:29:37 -0800 Subject: wrapping problem with old-style class Message-ID: <1166520577.085402.263580@48g2000cwx.googlegroups.com> I have a problem I would like some advice on. We have a Python binding to the Intersystems Cache OO database. It provides an old style class in Python as an in memory instance of a Cache class, and this is a intersystems.pythonbind.object type (= ipo). The ipo class has three basic methods, namely, get, set, and run_obj_method (which takes the Cache class method, as its first argument, and the list of its arguments as the second argument) e.g. >>> CacheClass=ipo() >>> CacheClass.set('Name','John') >>> valName = CacheClass.get('Name') >>> print valName 'John' I want to add functionality to ipo, so I have wrapped a new style class (MyWrapper class, very basic) around it. PythonCacheClass=MyWrapper(CacheClass) Now, I want to make PythonCacheClass more pythonic, so I have a dictionary of all the properties and values of each ipo. Eg dicCacheProperties = {'Name':'John', 'Address':'The Strand'} etc for key, val in dicCacheProperties.iteritems(): setattr(PythonCacheClass, key, val) So now I have: >>>print PythonCacheClass.Name 'John' My problem is this: how do I link the set and get methods of the ipo class with the set and get methods in the wrapper class PythonCacheClass? So, I would like the following code: >>> PythonCacheClass.Name='Alexander' to execute automatically CacheClass.set('Name','Alexander') etc My thinking is that inside the PythonCacheClass, I can reference the ipo class by self.get() - is this right? If so, how then do I set the set attribute of the PythonCacheClass to automatically run self.get().set('Name','Alexander') I hope this is sufficiently clear. Am I tackling the problem the right way? From guxing203 at gmail.com Sun Dec 24 04:27:56 2006 From: guxing203 at gmail.com (Riquelme) Date: 24 Dec 2006 01:27:56 -0800 Subject: Newbie: what is a usefull IDE for Python on Windows ? In-Reply-To: <1166898949.688988.285430@f1g2000cwa.googlegroups.com> References: <1166898949.688988.285430@f1g2000cwa.googlegroups.com> Message-ID: <1166952475.932417.223610@73g2000cwn.googlegroups.com> Eclipse + Editplus From Roberto.Bonvallet at cern.ch Wed Dec 6 10:47:32 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Wed, 6 Dec 2006 15:47:32 +0000 (UTC) Subject: dict.has_key(x) versus 'x in dict' References: <1165418932.582377.312200@79g2000cws.googlegroups.com> Message-ID: I wrote: > In Python > 2.4: lastline.replace(">", ">=") -- Roberto Bonvallet From uymqlp502 at sneakemail.com Sun Dec 3 20:23:49 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 3 Dec 2006 17:23:49 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> > Rather, they (like I) will encourage to OP to submit a patch that fixes the problem. Now, that would be rather silly. I would have to familiarize myself with the code for the Python interpreter, then send a patch to the maintainers (and hope they notice it in their inboxes), while the maintainers themselves could probably "fix" the problem in two minutes flat. No thanks! My suggestion is trivial to implement and would benefit every Python programmer (even if only slightly), so I don't think it is too much to ask for. From fredrik at pythonware.com Tue Dec 12 02:44:03 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Dec 2006 08:44:03 +0100 Subject: What are python closures realy like? In-Reply-To: References: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> Message-ID: John Nagle wrote: > Most of the examples given here are kind of silly, but closures have > real uses. I used one today in Javascript because I was writing an > AJAX application, and I was using an API, the standard XMLHttpRequestObject, > which required a callback function with no arguments. A closure allowed > the code to pass relevant information with the callback function, which > would be called when a request to the server completed. A global > variable wouldn't have worked, because multiple instances of the object > making the callback are possible. the usual way of handling multiple callback context instances in Python is of course to create multiple instances of the class that implements the behaviour, and use a bound method as the callback. From paul at boddie.org.uk Fri Dec 8 06:33:16 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 8 Dec 2006 03:33:16 -0800 Subject: Subprocess with a Python Session? References: <76fd5acf0612051110y65d0503fq482132c16df5ff46@mail.gmail.com> Message-ID: <1165577596.239341.47550@16g2000cwy.googlegroups.com> Hendrik van Rooyen wrote: > "Giovanni Bajo" > > > > Yeah, but WHY was the API designed like this? Why can't I read and write > > freely from a pipe connected to a process as many times as I want? > > you can - all you have to do is to somehow separate the "records" - else how is > the receiving side to know that there is not more data to follow? This is one of the more reliable methods since upon receiving a packet "delimiter" the receiver knows that the data is complete. It shouldn't attempt to process anything which isn't yet complete. > The simplest way is to use newline as separator, and to use readline() on the > receiving side. Agreed. Using the readline method on file objects created from sockets is a tried and trusted approach. > Or you can use read(1) and roll your own... Indeed. There are a few tricks in this department: use select or poll to test the status of file descriptors (which is what the standard library asyncore module, Medusa and Twisted do), attempt to examine the buffer status of sockets using the MSG_PEEK flag (something which didn't prove to be appropriate for some work I've done since I was using pipes, although more investigation may be required), or set timeouts on the underlying sockets (reliable only in certain kinds of communications, I would assert). > To make sure the stuff is written from memory on the transmitting side, use > flush(), if you want to do many records, or close() as Fredrik said if only one > thing is to be transferred. Also good advice. However, as was mentioned elsewhere, if you're invoking Python as a subprocess it can help to invoke it in unbuffered mode (the -u option), otherwise flush and close don't always seem to do their magic. Paul From kay.schluehr at gmx.net Sun Dec 10 04:28:09 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 10 Dec 2006 01:28:09 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165739878.421439.193030@f1g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <1165627684.709241.86340@16g2000cwy.googlegroups.com> <1165685950.758858.18960@n67g2000cwd.googlegroups.com> <1165732072.056289.274460@79g2000cws.googlegroups.com> <1165739878.421439.193030@f1g2000cwa.googlegroups.com> Message-ID: <1165742889.208943.142280@16g2000cwy.googlegroups.com> George Sakkis schrieb: > Well, for one thing we never held the first place anyway. Second, what > appears to be the big boost for Ruby today maybe its death sentence > tomorrow, ending up as a niche language for web apps, like PHP today. > With a large crowd undoubtly, but I bet most Pythonistas would prefer > lower popularity than ending up in a corner of the application > spectrum. Who really wants to write web apps? Web apps are just an excuse for Pythonistas to write web frameworks. From address.good.until.2006.dec.22 at justmail.de Fri Dec 15 15:12:30 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Fri, 15 Dec 2006 21:12:30 +0100 Subject: merits of Lisp vs Python In-Reply-To: <4ufenbF17of60U6@mid.individual.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> <1166102108.129051.166580@73g2000cwn.googlegroups.com> <4ufenbF17of60U6@mid.individual.net> Message-ID: greg schrieb: > josephoswaldgg at hotmail.com wrote: >> Adding parentheses ... all this is a >> burden specific to Python. > > As opposed to Lisp, where all you have to do is > use parentheses... oh, er... Lisp has no parens. An editor could support a mode where code is displayed in written in trees. There wouldn't be a single paren. >> By the way, you guys seem fixate on the parentheses of Lisp without >> having the experience > > I don't know about the other Pythonistas in this > discussion, but personally I do have experience with > Lisp, and I understand what you're saying. I have > nothing against Lisp parentheses, I just don't agree > that the Lisp way is superior to the Python way in > all respects, based on my experience with both. Lisp is not superior in all respects. As soon you decide to use a language you decide against other features. Python is especially strong as a scripting language as that is the domain of it. Andr? -- From simon at brunningonline.net Fri Dec 15 10:42:47 2006 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 15 Dec 2006 15:42:47 +0000 Subject: tuple.index() In-Reply-To: References: <1166187479.167471.169270@n67g2000cwd.googlegroups.com> Message-ID: <8c7f10c60612150742q3349162ep6e9fcf01acfa0b96@mail.gmail.com> On 12/15/06, Christoph Zwerschke wrote: > > If you have a tuple containing, say, a 2d coordinate pair, > > and remove something from it, it's no longer a coordinate pair. > > Now here comes the ambiguity. If you interpret "x" as "coordinate tuple" > it would be still one (a 1-tuple), but if you interpret "x" as > "coordinate pair" then it would indeed not be an "x" any more. So that > definition is not really helpful. But the new 1-tuple is no longer usable in the same contexts as the coordinate pair. In the coordinate pair, you can infer the item's meaning from its position. > > A typical example of their combined use is a set of > > rows returned from a database: each row is a tuple > > of fields, the same as all other such rows, and removing > > or adding a field would make no sense. However, add > > a new row to the list and it remains a list of rows. > > Sounds plausible. But when I read a row with the name and forename of a > person, I might want to collapse the name and forename into one element > before I hand it over to a function that will display it as a table. Or > I may want to delete certain elements which are not important. In such > cases, having each row as list may also make sense. Sure, you can translate the tuple into a different tuple for a different purpose, but in terms of the database, only the original tuple (or other with the same structure) is meaningful. > The statement "if you are looking for index() or count() for your > tuples, you're using the wrong container type" is too extreme I think. I > would agree with "it *may indicate* that you should better use lists". Oh, absolutely, it's not a hard and fast rule. But I find that if I try to decide whether to use a tuple or a list based on lists for homogeneous collections and tuples for heterogeneous collections where position carries semantic meaning, then I end up using the type that does what I need. Homogeneous collections often need to be sorted or searched, wheras heterogeneous collections are often used as dictionary keys. -- Cheers, Simon B simon at brunningonline.net From gagsl-py at yahoo.com.ar Thu Dec 7 03:47:35 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 07 Dec 2006 05:47:35 -0300 Subject: Use of factory pattern in Python? In-Reply-To: <676224240612070028y7be5e8b5h8f860bc505da53c0@mail.gmail.co m> References: <676224240612070028y7be5e8b5h8f860bc505da53c0@mail.gmail.com> Message-ID: <7.0.1.0.0.20061207053648.03d14538@yahoo.com.ar> At Thursday 7/12/2006 05:28, Nathan Harmston wrote: >chr1 SGD gene 5 8 id=1 name=3 dbref=6 >chr1 SGD intron 5 6 id=5 notes="spam" >chr1 SGD exon 7 8 id=5 > >so I was thinking of having a factory class to return the individual >objects for each row......ie > >class Factory(): > # if passed a gene return a gene object > # if passed an intron return an intron object > # if passed an exom return an exon object > >Is this a good way of doing this, or is there a better way to do this >in Python, this is probably the way I d do it in Java. The basic idea is the same, but instead of a long series of if...elif...else you can use a central registry (a dictionary will do) and dispatch on the name. Classes act as their own factories. registry = {} class Base(object): kind = "Unknown" register(Base) class Gene(Base): kind = "gene" def __init__(self, *args, **kw): pass register(Gene) class Intron(Base): kind = "intron" def __init__(self, *args, **kw): pass register(Intron) def register(cls): registry[cls.kind] = cls def factory(kind, *args, **kw): return registry[kind](*args, **kw) If some arguments are always present, you can name them, you're not limited to use the generic *args and **kw. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From basti.wiesner at gmx.net Sat Dec 30 08:16:50 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Sat, 30 Dec 2006 14:16:50 +0100 Subject: python , Boost and straight (but complex) C code References: Message-ID: Osiris typed > I have these pieces of C-code (NOT C++ !!) I want to call from Python. > I found Boost. > I have MS Visual Studio 2005 with C++. > > is this the idea: > I write the following C source file: > ============================ > #include iostream is a C++ header file... > #include > > namespace { // Avoid cluttering the global namespace. C doesn't know about namespaces. They are a C++ thing, too. > int my_int; /* a global integer: or outside namespace ? */ > double calc ( double f) > { > my_int = (int) (f/2); > printf( "Half of %f is %d\n", f, my_int ); You include a C++ IO header, but use traditional C IO functions here. Either you use C++ streams here, or you replace with . > return f/2; > } > > } > > #include > using namespace boost::python; > > BOOST_PYTHON_MODULE( half ) > { > def("calc", calc ); > } > > ================================ > > Which I put in a VC project and compile into a .DLL > This DLL I put somewhere on my disk, where Python 2.4 can find it. > then I write the following Python source: > ===================== > from half import * > calc(34655.0) > > et voila ? > > Can I acces my_int too, this way ? May be... Didn't you try it? It may also be, that you have to create a PyObject first... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From jcigar at ulb.ac.be Wed Dec 27 17:27:59 2006 From: jcigar at ulb.ac.be (Julien Cigar) Date: 27 Dec 2006 22:27:59 GMT Subject: dbm Message-ID: <4592f36f$0$1131$ba620e4c@news.skynet.be> Hello list, I have a dbm "database" which needs to be accessed/writed by multiple processes. At the moment I do something like : @with_lock def _save(self): f = shelve.open(self.session_file, 'c') try: f[self.sid] = self.data finally: f.close() the with_lock() decorator create a .lock file which is deleted when the function exit, so every operation did the following: - acquire .lock file - open the dbm file - do the operation (save, load, ...) - close the dbm file - delete the .lock file I made some tests and following my results the open() / close() add some overhead (about 5 times slower). I read that the gdbm module should be safe against multiple processes (I saw the "'u' -- Do not lock database." in the doc, so I presume it's locked by default ?). Does it mean that two (or more) processes can open the dbm file and write in the same time without errors/corruptions/segfaults/... ? Thanks, Julien From python-url at phaseit.net Mon Dec 11 12:52:45 2006 From: python-url at phaseit.net (Paul Boddie) Date: Mon, 11 Dec 2006 17:52:45 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Dec 11) Message-ID: QOTW: "I still want to keep compile time type checking to make sure I don't make any mistakes." "Sounds like you want two wives, but I'm pretty sure polygamy gets a checkbox in the naughty category on Santa's list" -- George Jempty (commenting on "Dear Open Source Santa," by Paul Browne) http://www.oreillynet.com/onjava/blog/2006/12/dear_open_source_santa.html#comment-384244 "But if you care to give it a closer look, you may understand that Python's main advantage is not seizable by feature and performance charts." -- Soni Bergraj (on comp.lang.python, responding to a cross-posted Lisp vs. Python inquiry) http://groups.google.com/group/comp.lang.python/msg/3112282696d61bb8 "Have you programmed in Python ? The standard libraries are a bit disorganised but there is clear documentation, most things that one wants are provided, and if there is more than one of anything then all but one are explicitly deprecated with a reference to the preferred interface. (I'm not a fan of Python, by the way, but like any programmer in the larger world I deal with it occasionally.)" -- Ian Jackson (on comp.lang.lisp, showing that even Python's non-fans can say good things about the language) http://groups.google.com/group/comp.lang.lisp/msg/011ffd16e6364e8f "It would probably be fair to say that the more you know about a variety of languages, the more you appreciate Python." -- Harry George (on comp.lang.python, providing a quote of the week by "popular demand") http://groups.google.com/group/comp.lang.python/msg/7c41f6c78e882b6e It's the final public PyPy sprint in PyPy's EU-funded era: http://groups.google.com/group/comp.lang.python/browse_frm/thread/270d99cd4ca3d387 On another "performant Python" front, Shed Skin's author gets back to development on that particular Python-to-C++ compiler... http://shed-skin.blogspot.com/2006/12/shed-skin-0015.html ... and discovers an interesting Python-powered tool for subverting certain Apple-branded music devices: http://shuffle-db.sourceforge.net/ Employing the previously mentioned pyplus in a game development setting, "Galcon was originally created for the April 2006 Ludum Dare competition. It won the contest with first places in four categories and second place in the fifth." http://www.pygame.org/projects/20/340/ The industrious Martin v. L=F6wis reports back on possible Linux Standard Base (LSB) inclusion for Python: http://mail.python.org/pipermail/python-dev/2006-December/070186.html Although PyCon is still some time away (late February), lots of work has already been done reviewing talk proposals (as mentioned in the previous Python-URL!). Here are the hard-working reviewers: http://pycon.blogspot.com/2006/12/notes-on-proposal-selection.html And a recent Ron Stephens Python411 podcast seeks to prepare us for the event: http://www.awaretek.com/plf.html Meanwhile, a real Python-related event took place at the time of writing; that was OSDC 2006 in Melbourne, Australia: http://www.mechanicalcat.net/richard/log/Python/OSDC_2006_report_so_far http://www.mechanicalcat.net/richard/log/Python/OSDC_2006_wrapup Barry Warsaw's recent NASA-sited Python talk becomes generally available. http://isandtcolloq.gsfc.nasa.gov/webcasts.html Diez B. Roggisch talks CORBA, or at least takes issue with notions of its complexity, adding a link to an amusing imagined dialogue between a Web Services architect and a developer: http://groups.google.com/group/comp.lang.python/msg/cd31fafd0fdc8609 Contrary to popular belief, CORBA implementations remain vital - Duncan Grisby announces omniORB 4.1.0 and omniORBpy 3.0: http://groups.google.com/group/comp.lang.python.announce/browse_frm/thread/6fed82468151315c/ And for the obligatory Web programming item, awareness of the decentralised identity system OpenID seems to be growing in the different Web framework communities, with many mentions of the Python-OpenID libraries: http://www.openidenabled.com/openid/libraries/python/ Good luck to the many Users Groups focused on Python, including, in particular, nation-wide ones: http://groups.yahoo.com/group/iranianpythonprogrammers ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html Steve Bethard continues the marvelous tradition early borne by Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim Lesher of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/python/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topic/python/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From nanjundi at gmail.com Wed Dec 13 19:28:14 2006 From: nanjundi at gmail.com (nanjundi at gmail.com) Date: 13 Dec 2006 16:28:14 -0800 Subject: how to determine Operating System in Use? In-Reply-To: References: Message-ID: <1166056094.751283.122760@79g2000cws.googlegroups.com> On Dec 13, 6:32 pm, "Ian F. Hood" wrote: > Hi > In typically windows environments I have used: > if 'Windows' in os.environ['OS']... > to prove it, but now I need to properly support different environments. > To do so I must accurately determine what system the python instance is > running on (linux, win, mac, etc). > Is there a best practises way to do this? > TIA > Ian I would do this: -------------------- if os.name == ''posix': linuxStuff() elif os.name == 'nt': windowsStuff() elif os.name == 'os2': ... ------------------- os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' -N From salvatore.difazio at gmail.com Fri Dec 1 14:29:48 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 1 Dec 2006 11:29:48 -0800 Subject: Thread help In-Reply-To: <12n0v9l4ssfd7fc@corp.supernews.com> References: <1164999221.679348.221000@16g2000cwy.googlegroups.com> <12n0v9l4ssfd7fc@corp.supernews.com> Message-ID: <1165001388.156041.79030@f1g2000cwa.googlegroups.com> Grant Edwards ha scritto: > You should use 4. Yes, but I don't know how can I make a thread :) From kgmuller at gmail.com Mon Dec 18 15:37:44 2006 From: kgmuller at gmail.com (kgmuller at gmail.com) Date: 18 Dec 2006 12:37:44 -0800 Subject: Is htmlGen still alive? Message-ID: <1166474264.348556.118510@n67g2000cwd.googlegroups.com> Does anybody know whether htmlGen, the Python-class library for generating HTML, is still being maintained? Or from where it can be downloaded? The Starship site where it used to be hosted is dead. Thanks for your help! Klaus Muller From nagle at animats.com Tue Dec 26 13:26:54 2006 From: nagle at animats.com (John Nagle) Date: Tue, 26 Dec 2006 10:26:54 -0800 Subject: BeautifulSoup vs. loose & chars In-Reply-To: References: <1167135758.005112.67350@73g2000cwn.googlegroups.com> Message-ID: <1qdkh.9706$ZT3.6008@newssvr19.news.prodigy.com> Felipe Almeida Lessa wrote: > On 26 Dec 2006 04:22:38 -0800, placid wrote: > >> So do you want to remove "&" or replace them with "&" ? If you want >> to replace it try the following; > > > I think he wants to replace them, but just the invalid ones. I.e., > > This & this & that > > would become > > This & this & that > > > No, i don't know how to do this efficiently. =/... > I think some kind of regex could do it. Yes, and the appropriate one is: krefindamp = re.compile(r'&(?!(\w|#)+;)') ... xmlsection = re.sub(krefindamp,'&',xmlsection) This will replace an '&' with '&' if the '&' isn't immediately followed by some combination of letters, numbers, and '#' ending with a ';' Admittedly this would let something like '&xx#2;', which isn't a legal entity, through unmodified. There's still a potential problem with unknown entities in the output XML, but at least they're recognized as entities. John Nagle From Benjamin.Barker at gmail.com Fri Dec 29 07:17:42 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 04:17:42 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167394098.642975.78350@73g2000cwn.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> <1167393801.950199.197830@48g2000cwx.googlegroups.com> <1167394098.642975.78350@73g2000cwn.googlegroups.com> Message-ID: <1167394662.665220.185680@a3g2000cwd.googlegroups.com> Well, I've checked the SQL log, and my insert statements are certainly being logged. The only option left open is that the table in question is being replaced, but I can't see why it should be... Ben wrote: > Nope... that can't be it. I tried running those commands manually and > nothing went wrong. > But then again when I execute the problematic command manually nothing > goes wrong. Its just not executing until the last time, or being > overwritten. > > > Ben wrote: > > Each time my script is run, the following is called: > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > self.cursor.execute("USE "+name) > > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( .... > > > > The idea being that stuf is only created the first time the script is > > run, and after that the original tables and database is used. This > > might explain my pronblem if for some reason the old tables are being > > replaced... can anyone see anything wrong with the above? > > > > Ben > > > > > > > > > > > > > > Ben wrote: > > > One partial explanation might be that for some reason it is recreating > > > the table each time the code runs. My code says "CREATE TABLE IF NOT > > > EXISTS" but if for some reason it is creating it anyway and dropping > > > the one before that could explain why there are missing entires. > > > > > > It wouldn't explain why the NOT EXISTS line is being ignored though... > > > > > > Ben > > > > > > > > > Ben wrote: > > > > I initially had it set up so that when I connected to the database I > > > > started a transaction, then when I disconnected I commited. > > > > > > > > I then tried turning autocommit on, but that didn't seem to make any > > > > difference (althouh initially I thought it had) > > > > > > > > I'll go back and see what I can find... > > > > Cheers, > > > > Ben > > > > > > > > > > > > johnf wrote: > > > > > Ben wrote: > > > > > > > > > > > I don't know whether anyone can help, but I have an odd problem. I have > > > > > > a PSP (Spyce) script that makes many calls to populate a database. They > > > > > > all work without any problem except for one statement. > > > > > > > > > > > > I first connect to the database... > > > > > > > > > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > > > > > self.cursor = self.con.cursor() > > > > > > self.cursor.execute("SET max_error_count=0") > > > > > > > > > > > > All the neccesary tables are created... > > > > > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > > > self.cursor.execute("USE "+name) > > > > > > > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > > > > > varchar(20)) > > > > > > > > > > > > Then I execute many insert statements in various different loops on > > > > > > various tables, all of which are fine, and result in multiple table > > > > > > entries. The following one is executed many times also. and seems > > > > > > identical to the rest. The print statements output to the browser > > > > > > window, and appear repeatedly, so the query must be being called > > > > > > repeatedly also: > > > > > > > > > > > > print "

SQL query executing

" > > > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > > > > > ','c','2','e','f','g')") > > > > > > print "

SQL query executed

" > > > > > > > > > > > > I have, for debugging, set "i" up as a counter variable. > > > > > > > > > > > > No errors are given, but the only entry to appear in the final database > > > > > > is that from the final execution of the INSERT statement (the last > > > > > > value of i) > > > > > > > > > > > > I suspect that this is to vague for anyone to be able to help, but if > > > > > > anyone has any ideas I'd be really grateful :-) > > > > > > > > > > > > It occured to me that if I could access the mysql query log that might > > > > > > help, but I was unsure how to enable logging for MysQL with python. > > > > > > > > > > > > Cheers, > > > > > > > > > > > > Ben > > > > > > > > > > Not sure this will help but where is the "commit"? I don't use MySQL but > > > > > most SQL engines require a commit. > > > > > Johnf From ldo at geek-central.gen.new_zealand Sun Dec 31 02:21:09 2006 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 31 Dec 2006 20:21:09 +1300 Subject: a question on python dict References: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> Message-ID: In message , Tim Peters wrote: > You should also note that copying a dict key or value (no matter of > what type) consists in its entirety of copying one machine address (a > 4- or 8-byte pointer, depending on platform). Actually, no. It also consists of updating reference counts as well. From martin at v.loewis.de Sat Dec 2 04:41:53 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 02 Dec 2006 10:41:53 +0100 Subject: Python25.zip In-Reply-To: References: Message-ID: <45714a61$0$8594$9b622d9e@news.freenet.de> Colin J. Williams schrieb: > The role of Python25.zip is not clear. Is it required in the path just > to enable the import X.zip capability? To rephrase Georg's explanation: it allows Python distributors (e.g. Linux distributors, or ActiveState) to put all of the Python library (including site.py) into a single zip file, instead of requiring a Lib directory with many files in it. E.g. on Windows, a complete Python installation could consist of three files: python.exe, python25.dll, and python25.zip. To make that possible, you can't tell people that they have to edit site.py to put a zip file on sys.path, instead, the distributed interpreter must already look for a file even though this file will usually not be present. Regards, Martin From geoffrey.clementsNO at SPAMbaesystems.com Thu Dec 14 11:36:15 2006 From: geoffrey.clementsNO at SPAMbaesystems.com (Geoffrey Clements) Date: Thu, 14 Dec 2006 16:36:15 -0000 Subject: Writing and reading variables to/from flat file References: <84548$45816e6c$4275d90a$16465@FUSE.NET> Message-ID: <45817a71$1_1@glkas0286.greenlnk.net> "Kevin Walzer" wrote in message news:84548$45816e6c$4275d90a$16465 at FUSE.NET... >I want to write some variables (user preferences, specifically) to a > text file and then read the values from that file. > > Here is my code to write the data: > > verbosemodes= """ > Detailed = "-vv" > Basic = "-q" > """ > > file = open('prefs', 'w') > > file.writelines(verbosemodes) > > file.close() > > And here is my code, in a separate module, to read the file and display > the variable values: > > readfile = open('prefs').readlines() > > for line in readfile: > print line > > print Basic > > > Running the second module yields this error: > > Detailed = "-vv" > > Basic = "-q" > > > Traceback (most recent call last): > File "readprefs.py", line 6, in > print Basic > NameError: name 'Basic' is not defined > > Clearly the data is getting read (the lines are being printed), but the > variable itself ("Basic") is not being initialized properly. I'm not > sure what I'm doing wrong here--can anyone point me in the right > direction? Thanks. > All you've done is print two strings with the contentents of the two lines from the file, this does not execute the code in these strings. Try this: readfile = open('prefs').readlines() for line in readfile: print line eval(line) print Basic -- Geoff From aidan at aidans.org Mon Dec 11 23:35:46 2006 From: aidan at aidans.org (Aidan Steele) Date: Tue, 12 Dec 2006 15:35:46 +1100 Subject: Password, trust and user notification In-Reply-To: <1165896991.676350.118670@16g2000cwy.googlegroups.com> References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> Message-ID: <364538570612112035m717dcde2k8e57cf1211ce9e2c@mail.gmail.com> Hi, As you said yourself -- it's all about trust. If this person knows nothing of programming, then (s)he is obviously at the mercy of the programmers, which is why we have warranties in commerical software, reputuations to uphold in the open source arena and malware elsewhere. ;-) Sure, there will always be people that will abuse your trust and we should all do whatever we can to avoid such people, but realistically the only people writing open-source software of any notability will usually be fairly trustworthy people, even if only out of necessity as their reputation is on the line. Failing that, there's no reason one could not pay an independent third-party code auditor to inspect the code. Such auditors will usually guarantee the safety of products they've investigated, but this comes at a cost. Hope this helps. On 11 Dec 2006 20:16:31 -0800, placid wrote: > > Hi all, > > I was going to write this script for a friend that notifies him via > logging onto his Gmail account and sending him an email to his work > email about some events occurring in the execution of the script. > If you enter your password into a script as input how can someone trust > the programmer that he will not send a email to himself containing his > password? Assuming this person does not know anything about programming > and this person knows nothing about programming ethics. > > This is coming from the fact that i need to notify the user in someway > that does not require her to constantly watch the execution of the > script, for example when a user signs in to Windows Live Messenger pop > up. > > > Cheers > > > 1. http://libgmail.sourceforge.net/ This is the library i use to > access a Gmail account via Python > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at gmail.com Fri Dec 1 17:22:09 2006 From: fuzzyman at gmail.com (Fuzzyman) Date: 1 Dec 2006 14:22:09 -0800 Subject: Detecting recursion loops In-Reply-To: References: Message-ID: <1165011729.439676.229540@79g2000cws.googlegroups.com> robert wrote: > My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. > What would be a good method to detect recursion loops and stop it by user-Exception (after N passes or some complex criteria) without passing a recursion counter parameter through all the funcs? > Could you not store a set/list of nodes/points already visited and do an early return if they recur ? Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Robert From greg at cosc.canterbury.ac.nz Fri Dec 15 01:28:05 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 15 Dec 2006 19:28:05 +1300 Subject: speed of python vs matlab. In-Reply-To: <1166112365.993234.3130@l12g2000cwl.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> <1166059648.320257.187310@j72g2000cwa.googlegroups.com> <1166107064.994343.266890@l12g2000cwl.googlegroups.com> <1166112365.993234.3130@l12g2000cwl.googlegroups.com> Message-ID: <4uetmmF17m6r4U1@mid.individual.net> Chao wrote: > I did some search, in previous discussion, people has compared > python/numpy vs matlab, > but it is actually comparison between numpy(which is implemented in c) > vs matlab. Yes, matlab is operating on whole arrays at a time, like numpy. So it's not surprising that they have comparable performance. -- Greg From greg at cosc.canterbury.ac.nz Fri Dec 15 06:18:19 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:18:19 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> Message-ID: <4ufemoF17of60U3@mid.individual.net> Ken Tilton wrote: > The reason I post macro expansions along with examples of the macro > being applied is so that one can see what code would have to be written > if I did not have the defskill macro to "write" them for me. It seems to me your brain is somewhat stuck on the use of macros. You're looking at the expansion of your macro and assuming that you'd have to write all that code by hand if you didn't have macros. You're not thinking about alternative approaches, which could just as well be used in Lisp as well as Python, that are just as compact yet don't make use of macros. Unless there's something very subtle that I'm missing (I can't claim to follow exactly what all the code you posted does in detail) I haven't seen anything that couldn't be done quite reasonably with an appropriate data structure and ordinary functions and methods operating on that data structure. -- Greg From gagsl-py at yahoo.com.ar Sat Dec 9 19:01:50 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 9 Dec 2006 16:01:50 -0800 Subject: Automatic debugging of copy by reference errors? In-Reply-To: <1165666093.996141.244760@n67g2000cwd.googlegroups.com> References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165645676.694401.193580@16g2000cwy.googlegroups.com> <1165666093.996141.244760@n67g2000cwd.googlegroups.com> Message-ID: <1165708910.736372.270320@j72g2000cwa.googlegroups.com> On 9 dic, 09:08, "Niels L Ellegaard" wrote: > Now some of my fortran-using friends would like to use python to > analyze their data files. I wanted them to avoid making the same > mistakes as I did so I thought it would be good if they could get some > nanny-like warnings saying: "Watch out young man. If do this, then > python will behave differently from fortran and matlab". That could > teach them to do things the right way. Best bet is to learn to use python the right way. It's not so hard... > I am not an expert on all this, but I guessed that it would be possible > to make a set of constraints that could catch a fair deal of simple > errors such as the one above, but still allow for quite a bit of > programming. The problem is, it's an error only becasuse it's not the *intent* of the programmer - but it's legal Python code, and useful. It's hard for the computer to guess the intent of the programmer -yet!...- -- Gabriel Genellina From sschwarzer at sschwarzer.net Tue Dec 26 09:33:47 2006 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Tue, 26 Dec 2006 15:33:47 +0100 Subject: How to depress the output of an external module ? In-Reply-To: References: Message-ID: <459132CB.7020807@sschwarzer.net> Hi Luis, Luis Armendariz wrote: > There's no need for savestdout. There's a backup copy in sys.__stdout__ Depending on the code that ran before the call to the function run_without_stdout, sys.stdout may not be the same as sys.__stdout__ . Of course, you also have to be careful regarding threads which also use sys.stdout, perhaps implicitly via print statements. Stefan From no at spam.com Mon Dec 4 19:32:28 2006 From: no at spam.com (Farshid Lashkari) Date: Mon, 04 Dec 2006 16:32:28 -0800 Subject: sending string or list to a function In-Reply-To: <1165278026.064172.147770@l12g2000cwl.googlegroups.com> References: <1165278026.064172.147770@l12g2000cwl.googlegroups.com> Message-ID: manstey wrote: > Is there a neat way to write a function that can receive either a > string or a list of strings, and then if it receives a string it > manipulates that, otherwise it manipulates each string in the list? The following code shows one way you can accomplish this. I don't consider it bad programming style to allow your functions to accept multiple data types. def MyFunction(val): if isinstance(val,basestring): val = [val] for s in val: #Process string -Farshid From gagsl-py at yahoo.com.ar Mon Dec 4 19:58:47 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 04 Dec 2006 21:58:47 -0300 Subject: sending string or list to a function In-Reply-To: <1165278026.064172.147770@l12g2000cwl.googlegroups.com> References: <1165278026.064172.147770@l12g2000cwl.googlegroups.com> Message-ID: <7.0.1.0.0.20061204214032.047b48b8@yahoo.com.ar> At Monday 4/12/2006 21:20, manstey wrote: >Is there a neat way to write a function that can receive either a >string or a list of strings, and then if it receives a string it >manipulates that, otherwise it manipulates each string in the list? > >That is, rather than having to send a list of one member >MyFunction(['var1']), I can send > >MyFunction('var1') or MyFunction(['var1','var2',var3']) That depends a bit on what you do with the argument. Sometimes it's more clear to have two different methods, one for lists and another for single items, specially when processing a list is *not* the same as processing each item sequentially. Another reason to have separate methods would be if you expect much more calls to the single-item version than the list version. If you want a combined version which accepts both strings and lists, notice that unfortunately (or not!) strings and lists share a lot of functionality. So you have to check for strings in your code, else the first call would process 'v','a','r','1'. That is, you usually write something like this: def MyFunction(arg): if isinstance(arg, basestring): arg = [arg] # or perhaps arg, ... process ... So, if you *will* construct a list anyway, using MyFunction(['var1']) in the first place would be better. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From fredrik at pythonware.com Tue Dec 5 02:14:08 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 08:14:08 +0100 Subject: algorithm for sorting functional expressions In-Reply-To: <1165274312.053036.319810@80g2000cwy.googlegroups.com> References: <1165215032.749560.171530@16g2000cwy.googlegroups.com> <1165274312.053036.319810@80g2000cwy.googlegroups.com> Message-ID: MRAB wrote: > It's left as an exercise for the reader as to how it works. :-) *if* it works, you mean. should the following script really print anything? import random, sys # input variables replaced with zeros L = [ ['b', ['w','z']], ['a', ['z','y']], ['w', ['z','0']], ['z', ['0','0']], ['y', ['0','0']] ] def Compare(X, Y): if X[0] in Y[1]: return -1 elif Y[0] in X[1]: return 1 else: return 0 while 1: random.shuffle(L) L.sort(cmp=Compare) # check that all steps only use known values i = set("0") for d, s in L: if s[0] not in i or s[1] not in i: print L print d, s, i i.add(d) From Eric_Dexter at msn.com Fri Dec 1 20:24:18 2006 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: 1 Dec 2006 17:24:18 -0800 Subject: strange problems with code generation Message-ID: <1165022658.313170.134140@79g2000cws.googlegroups.com> I am writing out zero byte files with this (using python 2.5). I have no idea why I am having that problem, I am also looking for an example of readlines where I can choose a number of lines say lines 12 to 14 and then write them back to disk. any help would be apreaceted. import sys as sys2 import os as os2 def playscoreinrange(from_file, fromline, toline): "untested way to play a series of lines from a orc, sco combination line 14 may not be correct" print(from_file) fromfile = os2.path.basename(from_file) print(fromfile) orcfilename = fromfile[:-4] + '.orc' print(orcfilename) infile2 = open(orcfilename, 'r') outfile2 = open('temp.orc', 'w') for line in infile2: outfile2.write(line) infile = open(fromfile, 'r') outfile = open('temp.sco','w') data = sys2.stdin.readlines() print(data) for linenumber in range(fromline, toline): outfile.writeline(data[linenumber]) https://sourceforge.net/projects/dex-tracker http://www.dexrow.com os2.startfile('temp.bat') From pavlovevidence at gmail.com Wed Dec 27 18:01:32 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 27 Dec 2006 15:01:32 -0800 Subject: loose methods: Smalltalk asPython In-Reply-To: References: Message-ID: <1167260492.174445.98470@n51g2000cwc.googlegroups.com> Jan Theodore Galkowski wrote: > > We've not had > > an excellent dynamic OO language since Smalltalk, IMO. I would say that "excellence" in object oriented programming is not a strong design goal of Python. Python tries to support OOP well, but not to enhance OOP to the detriment of other, more important goals. [snip] > >Guido was opposed to modifying builtin types before Java existed. It's > >similar to his opposition to dynamic syntax. > > Opposition or not, the language definition is there. Surely Smalltalk's > OO style can be respected. Smalltalkers have been doing OO in a dynamic > context longer than many. There are things to learn there. Well, that Smalltalk and Ruby do this at least suggests that it won't be the end of the world as we know it if it were to happen in Python. Personally, I'm with Guido here. Allowing this might make Python's OOP more "excellent", but it would be to the detriment of other, more important goals, like minimizing surprise. > There are two things here that need to be kept straight, I think. > > One is the primacy of builtin types. > > The other is placing those builtins at the top of their own object > hierarchy. Is "int", properly speaking, a descendent of "object"? No, > it's the root of its own tree. Are you saying that it shouldn't be a descendant of "object", or that it isn't? "int" is certainly a subclass of "object" in Python (as are all objects). > Smalltalk has "int" as well, as a > *subclass* of Number. It's primitive. Number is primitive? I thought all types in Smalltalk had a common base type. Anyways, Python 3000 is exploring the idea of an abstract hierarchy that has classes (interfaces?) like Number and Sequence. In fact, I even saw some talk about somehow being able to retrofit classes to support one of these interfaces/ABCs, though it was pretty conjectural. > In any case, as respectful of Mr/Dr van Rossum as I am, simply because > so-and-so says something is bad and therefore it must be true is a > fallacious response. The same could be said of Smalltalk, i.e., because Smalltalk does it therefore it is good is just as fallacious. Regardless, whatever Guido pronounces is what happens. If he's adamantly against something, it's pretty much an academic discussion. Carl Banks From rpw3 at rpw3.org Wed Dec 13 05:54:55 2006 From: rpw3 at rpw3.org (Rob Warnock) Date: Wed, 13 Dec 2006 04:54:55 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165773218.686683.46640@16g2000cwy.googlegroups.com> Message-ID: Robert Uhl wrote: +--------------- | "JShrager at gmail.com" writes: | > I have the code here (probably not the latest bcs I left the company | > when it was acquired), let's do a little experiment, for what it's | > worth: 89727 lines of Lisp code in 131 modules (lisp code files), 3306 | > "(defun" (by grep|wc), and 261 "(defmacro". [We did NOT use macros as | > functions!] [Note that lines of code doesn't really matter in Lisp.] | | Wow--my emacs install has 1,152,598 lines of code in 1,570 files, | 29,244 defuns and 1,393 defmacros. +--------------- Wow, indeed! The entire CMUCL-19c distribution is "only" 592081 lines of source code in 1192 files, with 10699 DEFUNs and 1839 DEFMACROs. I didn't realize CMUCL was so "small" compared to Emacs. ;-} [Of course, that doesn't include the number of DEFUNs & DEFMACROs which are defined *by* macros, or the total of 2809 DEFINE-VOPs in the various flavors of the compiler...] -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From atkinw at rpi.edu Sun Dec 10 03:18:07 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 03:18:07 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano writes: >> something like: >> >> control_code = connection.read_next_control_code() >> if control_code == +break+: >> connection.kill() >> throw blah >> else if control_code == +status+: >> connection.send_status_summary() >> else if control_code == +noop+ || control_code == +keep_alive+: >> else: >> error "CONTROL_CODE fell through conditional cascade; was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+" > > Your Python syntax is rather wonky, but that's incidental. What is wonky about it? The use of +foo+ symbols from the Lisp? Is there some particular bit of wonkiness you can point out that will make me think you've done anything but intentionally misunderstand my post? > Nine lines, including handling the case where control_code is none of the > four constants. Ten if you add the "pass" statement that it actually > needs. And it is completely self-contained, with no external functions or > macros to understand. > > Saving one line of code, at the expense of having another block of code to > write or understand -- is that really the best example of what macros are > used for in practice? You don't really save writing any boilerplate code, > except for else clause, unless you're claiming that "if" and "elif" is > boilerplate. Fine, you claim them as boilerplate. I'm going to claim all > those unnecessary brackets as boilerplate. We're not counting lines here, you goon. We're talking about how expressive constructs are and how closely they match your concept of what you want to do. The conditional example is lower-level; you're talking to the interpreter instead of saying what you want to achieve. You're having to repeat things because that's what the language asks of you, instead of describing in a higher-level way what you're actually doing. > Yes, I know the parser needs them. But as so many people keep telling me, > once you've been writing Lisp code for a month, you don't even notice the > brackets. That makes them unnecessary for the developer, and therefore > something the computer should handle on its own. You've already split > expressions with whitespace, why should you have to use brackets as well? > That's just boilerplate. This simply means that the parentheses do not stand out. It doesn't mean that they *literally* cease to become visible (unless I have perhaps missed out on Lisp enlightenment). Obviously, this doesn't mean that they are "unnecessary." They are necessary to give Lisp its regular structure, which 1) makes macros possible, 2) allows easy movement through and automatic indentation of code and 3) is aesthetically pleasant, which leads to easier maintenance. Brackets are no more boilerplate than the significant whitespace in Python is boilerplate (that is, they're not boilerplate at all). > Okay, I'm impressed that ecase can pick up on the four constants being > tested against, and feed their names (rather than merely their values) > into an error message. Python has nothing like that, and if you only have > three or four things to test against, *and* they have names, that could be > a useful thing to do. And if I've understood correctly, that's more a > feature of Lisp's symbols than of macros. But you haven't understood it correctly, of course. The only reason this works is that the macro is passed the unevaluated code, which still has the original symbols that the programmer used. It can insert these into the generated code as it pleases. I feel that should be clear to someone who claims to know as much Lisp as you do. > But if you're testing against fifty different values, well, is it really > useful for your error message to list all fifty names? Or do you have > another macro ecase-with-lots-of-tests? Is it really useful? Yes, it is. > If that's the best example of what macros can be used for, frankly I'm > unimpressed. Yes, I can see some benefit. But I don't see that the benefit > is worth the added complexity. Maybe there are more complex tasks that > macros are better suited for. Did you read the DEFINE-BINARY-CLASS macro I mentioned elsewhere? Where did you get the notion that ECASE was the best example of where macros can be used? Why am I responding to another of your absurd posts? From gagsl-py at yahoo.com.ar Thu Dec 14 18:44:59 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 14 Dec 2006 20:44:59 -0300 Subject: WHAT is [0] in subprocess.Popen(blah).communicate()[0] In-Reply-To: References: <1166118046.514892.85360@16g2000cwy.googlegroups.com> Message-ID: <7.0.1.0.0.20061214204357.05993da0@yahoo.com.ar> At Thursday 14/12/2006 15:30, Neil Cerutti wrote: >I like using pattern matching in these simple cases: > > last_line, _ = subprocess.Popen([r"tail","-n 1", "x.txt"], > stdout=subprocess.PIPE).communicate() pattern matching??? -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From clajo04 at mac.com Sun Dec 10 08:38:26 2006 From: clajo04 at mac.com (John Clark) Date: Sun, 10 Dec 2006 05:38:26 -0800 Subject: New York City Python Users Group meeting is planned for Dec. 12th @ 6pm - please RSVP! Message-ID: <22EED86B-010F-1000-8700-AC749965897E-Webmail-10014@mac.com> Greetings! The next New York City Python Users Group meeting is this Tuesday, Dec. 12th, 6pm at at the Millennium Partners office at 666 Fifth Avenue on the 8th Floor. We welcome all those in the NYC area who are interested in Python to attend. However, we need a list of first and last names to give to building security to make sure you can gain access to the building. If you would please RSVP to clajo04ATmacDOTcom to add your name to the list. More information can be found on the yahoo group page: http://tech.groups.yahoo.com/group/nycpython/ Hope to see you there! -John From DustanGroups at gmail.com Wed Dec 13 06:45:31 2006 From: DustanGroups at gmail.com (Dustan) Date: 13 Dec 2006 03:45:31 -0800 Subject: newb: Creating Exception In-Reply-To: <1165954233.519919.107940@l12g2000cwl.googlegroups.com> References: <1165881722.928958.81490@79g2000cws.googlegroups.com> <1165954233.519919.107940@l12g2000cwl.googlegroups.com> Message-ID: <1166010331.697359.46400@n67g2000cwd.googlegroups.com> johnny wrote: > Thank you Dennis, > So when line 2, gets executed, its exception goes to do_some1_error. > And when line 3, gets executed, its exception goes to do_some2_error > and so on. > > line 1: try > line 2: do_some1 > line 3: do_some2 > line 4: do_some3 > line 5: except do_some1_error: > line 6: whatever1 > line 7: except do_some2_error: > line 8: whatever2 > line 9: except do_some3_error: > line 10: whatever3 > > Documentation is not written for newbs, it's written by guys with 6yrs > of experience FOR guys with 6yrs of experience. You might want to get a book on python, rather than depend on the documentation, which is, as you say, written for more experienced programmers. http://wiki.python.org/moin/IntroductoryBooks I started with a book, and reading the tutorial now, am quite glad I did. One thing that did bug me, at least briefly, is sometimes beginner books don't explain what a line of code is actually doing - not necessarily how it works, but as much information as is necessary to actually be able to use the code shown. > Dennis Lee Bieber wrote: > > On 11 Dec 2006 16:02:02 -0800, "johnny" declaimed > > the following in gmane.comp.python.general: > > > > > I want to print individual exception for database connection, sql > > > execution, database closing, closing the cursor. Can I do it with one > > > try..catch or I need a nested try...catch? > > > > Python does not have a "catch" instruction. > > > > You could do: > > > > try: > > make connection #though that should, in my mind, be done > > #as part of the initialization of the thread > > #and not as part of any processing loop > > make cursor > > execute sql > > fetch results if any > > close cursor > > commit transaction > > close connection #which I'd make part of the termination > > #of the thread > > except Exception1, msg: > > do something > > except Exception2, msg: > > do something2 > > ... > > > > IF each step raises a different exception type -- if all the database > > returns is "DatabaseError", then there is nothing to separate them by. > > Also note that if an exception happens in the "execute sql" stage, your > > handler may need to do a rollback, and the closes. > > > > -- > > Wulfraed Dennis Lee Bieber KD6MOG > > wlfraed at ix.netcom.com wulfraed at bestiaria.com > > HTTP://wlfraed.home.netcom.com/ > > (Bestiaria Support Staff: web-asst at bestiaria.com) > > HTTP://www.bestiaria.com/ From rampeters at gmail.com Tue Dec 5 09:19:45 2006 From: rampeters at gmail.com (johnny) Date: 5 Dec 2006 06:19:45 -0800 Subject: Multiple FTP download using Muliti thread In-Reply-To: <1165284311.911998.151460@l12g2000cwl.googlegroups.com> References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> <1165277324.677203.107650@l12g2000cwl.googlegroups.com> <1165284311.911998.151460@l12g2000cwl.googlegroups.com> Message-ID: <1165328384.929172.16750@j44g2000cwa.googlegroups.com> It works using ftp.microsoft.com. But where does it put the downloaded files? can I specify a download folder location? Justin Ezequiel wrote: > johnny wrote: > > When I run the following script, with host and password and username > > changed, I get the following errors: > > raise error_temp, resp > > error_temp: 421 Unable to set up secure anonymous FTP > > > > Dose the host should allow 4 simultaneous login at a time? > > > > does it work using ftp.microsoft.com? > > post your code From rridge at csclub.uwaterloo.ca Sun Dec 10 08:40:55 2006 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: 10 Dec 2006 05:40:55 -0800 Subject: len() and PEP 3000 References: <4tnqlkF13bbqeU1@mid.individual.net> <5HSdh.15210$P04.6844@tornado.fastwebnet.it> <1165693115.007835.160250@j72g2000cwa.googlegroups.com> <1165729753.864860.82650@f1g2000cwa.googlegroups.com> <1165741437.119066.85600@16g2000cwy.googlegroups.com> Message-ID: <1165758054.947270.64920@f1g2000cwa.googlegroups.com> Klaas wrote: > We can think of arbitrarily-stupid ways of changing the perfectly > functional len(), but since it isn't going to change, why not drop this > topic? I dunno, why didn't you? Ross Ridge From george.sakkis at gmail.com Fri Dec 15 12:02:55 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 15 Dec 2006 09:02:55 -0800 Subject: Property error References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> <1166179622.872556.312810@n67g2000cwd.googlegroups.com> <1166181267.949316.197360@16g2000cwy.googlegroups.com> Message-ID: <1166195768.916219.14900@l12g2000cwl.googlegroups.com> king kikapu wrote: > Your example Dennis, work as expected. I understand the mistake i have > made. But when i try to fix the original code usihn @property now, it > gives me the same error. > So, here it is: > > class Person(object): > _age = 0 > > @property > def age(): > def fget(self): > return self._age > def fset(self, value): > self._age = value > > me = Person() > me.age = 34 > print me.age > > > I am sure it is something very obvious but my skills does not (yet) > enable me to figure this out,,, As others have already replied, the default property doesn't work this way. In your example, it is possible to write it in one line using lambda: class Person(object): age = property(fget=lambda self: self._age, fset=lambda self, value: setattr(self,'_age',value)) If any of fget,fset,fdel cannot be written as lambda or you'd rather write them as functions, you may use the recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698. HTH, George From fredrik at pythonware.com Thu Dec 14 09:15:23 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 15:15:23 +0100 Subject: tuple.index() References: <1166103409.199435.290670@79g2000cws.googlegroups.com> <1166104987.884566.126710@n67g2000cwd.googlegroups.com> Message-ID: Glenn Hutchings wrote: > Python is first and foremost a practical language; what lists and > tuples are supposedly "for" strikes me as being irrelevant. if you don't want to understand the design, nobody can force you. but arguing that the people behind the design "don't get it" isn't very practical. and if you want random hacks and no design philosophy, use PHP. From fredrik at pythonware.com Tue Dec 26 14:31:46 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 26 Dec 2006 20:31:46 +0100 Subject: Q: How to generate code object from bytecode? In-Reply-To: <1167160509.839311.230090@73g2000cwn.googlegroups.com> References: <1167160509.839311.230090@73g2000cwn.googlegroups.com> Message-ID: kwatch at gmail.com wrote: > It is possible to get bytecode from code object. > Reversely, is it possible to create code object from bytecode? > > ex. > ## python code (not a module) > pycode = '''\ > print "

    \n" > for item in items: > print "
  • %s
  • \n" % item > print "
\n" > ''' > > ## compile it and get bytecode > code = compile(pycode, kind='exec') > bytecode = code.co_code > open('hoge.pyc', 'wb').write(bytecode) > > ## load bytecode and eval it > bytecode = open('hoge.pyc', 'rb').read() > code = create_code(bytecode) ## how to ????? > output = eval(code, globals, {'items': ['A', 'B', 'C']}) use the marshal module; see the last script on this page for an example: http://effbot.org/librarybook/marshal From sjmachin at lexicon.net Tue Dec 5 14:20:22 2006 From: sjmachin at lexicon.net (John Machin) Date: 5 Dec 2006 11:20:22 -0800 Subject: About the 79 character line recommendation References: <1165341320.094491.55480@n67g2000cwd.googlegroups.com> Message-ID: <1165346422.382091.293960@l12g2000cwl.googlegroups.com> Steve Bergman wrote: [snip] > However, I am finding that the 79 character line prescription is not > optimal for readability. > > Certainly, cutting back from the length of lines that I used to use has > *helped* readability. But if I triy very hard to apply 79, I think > readability suffers. If this were just something that was an issue > occasionally, I would just put it off to "know when to break the > rules". However, find myself going to 90 to 100 characters very > frequently. Now, if it were just me, I'd shoot for < 100. However, > the Python philosophy includes making code easier for others to read, > as well. > Are you taking advantage of all the various options for line continuation besides \ that exist in Python, like (a) automatic concatenation of adjacent string literals (b) automatic continuation until () [] or {} are balanced? Example using both: fprintf(self.logfile, "WARNING *** Conflict between " "std format code %d and its format string %r\n", fmtcode, unistrg) Aside: In this most noble of languages, fprintf() has a one-line implementation: def fprintf(f, fmt, *args): f.write(fmt % args) > > While I'm on this general topic, the guide mentions a pet peeve about > inserting more than one space to line up the "=" in assignment > statements. To me, lining them up, even if it requires quite a few > extra spaces, helps readability quite a bit. Comments? Merely aligning the = would annoy the crap out of me. However if the RHS of a bunch of *related* assignments could be made clearer by inserting extra space, *and* they were more complicated than the following trivial example of what I mean, I'd do it. red = c & 0xff green = (c >> 8) & 0xff blue = (c >> 16) & 0xff c.f. red = c & 0xff green = (c >> 8) & 0xff blue = (c >> 16) & 0xff Cheers, John From fredrik at pythonware.com Sat Dec 23 11:41:21 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Dec 2006 17:41:21 +0100 Subject: Add/Remove Channels in Asyncore? In-Reply-To: <1166889458.844414.87500@42g2000cwt.googlegroups.com> References: <1166889458.844414.87500@42g2000cwt.googlegroups.com> Message-ID: Chris wrote: > I've implemented a real basic IRC client class in 100 lines using > asynchat (yes I know about Twisted). The problem I'm having is > arbitrarily starting and stopping multiple instances of this class > after I call loop(). > > The asyncore docs seem to imply everything's fixed in stone once loop() > is called, where they say, "Once the initial channel(s) is(are) > created, calling the loop() function activates channel service, which > continues until the last channel (including any that have been added to > the map during asynchronous service) is closed." > > After I call asyncore.loop(), I'd like to be able to add/remove clients > ("channels"?) to/from execution by asyncore. Is this possible? the usual way to do that is to add new channels in callbacks, in response to other server activities. if you want to deal with this from the program calling asyncore.loop, use the "count" option to tell loop to return after N events. e.g: while 1: asyncore.loop(0.05, count=20) # wait for max 1 second add/remove channels here From kentilton at gmail.com Thu Dec 14 04:06:26 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 04:06:26 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> Message-ID: Ken Tilton wrote: > > > Andrew Reilly wrote: > >> On Thu, 14 Dec 2006 03:01:46 -0500, Ken Tilton wrote: >> >> >>> You just aren't used to thinking at a level where one is writing code >>> to write code. >> >> >> >> Firstly, I'm looking into lisp because my current python project is too >> full of boilerplate :-) and too slow. Coming from a C and assembler >> background, I'm *used* to meta-programming, and do it all the time. I >> even use python, Matlab and bash to write C, sometimes :-) >> >> However, in this particular instance, I'm inclined to wonder why >> meta-programming is the right answer, rather than just doing all of the >> interpolation and what-not at run-time, based on a big table of your >> algebra rules? > > > I am afraid I do not see what alternative you are suggesting. I > especially do not see how interpolation is in play. [Guessing pending your clarification] "Interpolation" does happen at runtime. This not about the actually quite rare use of macrology to move certain calculations to compile time, this is about getting dozens of transformation-specifc rules written to fit into a larger mechanism (by having the right arguments and returning the right kinds of results, with a minimum of boilerplate and a maximum of resiliency in the face of refactoring. The reason I post macro expansions along with examples of the macro being applied is so that one can see what code would have to be written if I did not have the defskill macro to "write" them for me. I sugest one start there, by comparing before and after. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From maxm at mxm.dk Mon Dec 18 15:30:26 2006 From: maxm at mxm.dk (Max M) Date: Mon, 18 Dec 2006 21:30:26 +0100 Subject: Is there a way to push data into Ical from Python ? In-Reply-To: <1166459924.298273.82290@t46g2000cwa.googlegroups.com> References: <4584591b$0$29324$426a74cc@news.free.fr> <1166364160.192126.123420@n67g2000cwd.googlegroups.com> <1166459924.298273.82290@t46g2000cwa.googlegroups.com> Message-ID: <4586FA62.6040307@mxm.dk> has skrev: > dwhall wrote: > >> One way would be to use >> Python's tie-ins to Applescript_ and apple events (AE). As you will >> read, this support isn't as strong as it used to be. > > What gave you that impression, if you don't mind my asking? http://www.google.dk/search?q=python+icalendar -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From shuanyu at gmail.com Tue Dec 26 00:50:15 2006 From: shuanyu at gmail.com (many_years_after) Date: 25 Dec 2006 21:50:15 -0800 Subject: How to stop program when threads is sleeping In-Reply-To: References: <1167029711.446218.133930@f1g2000cwa.googlegroups.com> Message-ID: <1167112215.615162.106500@h40g2000cwb.googlegroups.com> Carsten Haese wrote: > On Sun, 2006-12-24 at 22:55 -0800, many_years_after wrote: > > Hi, pythoners: > > > > There is a problem I couldn't dispose. I start a thread in the my > > program. The thread will do something before executing time.sleep(). > > When the user give a signal to the main thread (such as click the 'end' > > button or close the window), the thread should end it's running. But > > how to end the threading when it's sleeping? I set an flag to the > > thread, but it doesn't work. > > Is the thread supposed to do some additional work after being woken up? > If not, there is no point in going to sleep in the first place and the > thread should just terminate when it has completed its task. If yes, I'd > use a threading.Event object to .wait() on in the sub-thread rather than > putting it to sleep, and then .set() the event object in the main thread > when it's time to wake up the sub-thread. > > Hope this helps, > > Carsten. While , there is something wrong in my expression. What I mean is the thread will wait some time after doing some tasks. I want to know is there any method to end the thread or make it out of execution of waiting. I use time.sleep() to let the thread wait. Thanks. From grahamd at dscpl.com.au Fri Dec 29 20:24:05 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 29 Dec 2006 17:24:05 -0800 Subject: Question about the "new" module References: <1167397054.487644.138650@k21g2000cwa.googlegroups.com> Message-ID: <1167441845.407695.212610@s34g2000cwa.googlegroups.com> skip at pobox.com wrote: > Gabriele> I'm using Python 2.5 to develop a simple MVC framework based > Gabriele> on mod_python. To load my controllers, I create new modules > Gabriele> using the "new" module like this: > > Gabriele> # .... > Gabriele> my_module = new.module("random_name") > Gabriele> my_module.__file__ = module_path > Gabriele> exec open(module_path, "r") in my_module.__dict__ > > Gabriele> then I initialize the class defined inside the module and call > Gabriele> a method of this class based on the HTTP request. > > Why use the new module? Why not call __import__() or execfile()? Details > on their use are here: > > http://docs.python.org/dev/lib/built-in-funcs.html Or why not use mod_python.apache.import_module() from mod_python itself. It is designed as a way of users importing specific modules, including the capability for modules to be reloaded if they have been changed. See: http://www.dscpl.com.au/wiki/ModPython/Articles/BasicsOfModuleImporting as well as the mod_python documentation. Is recommended though to use mod_python 3.3 as soon as you can though if you want the module reloading to always work. You can find descriptions of problems with the module reloading in older versions of mod_python at: http://www.dscpl.com.au/wiki/ModPython/Articles/ModuleImportingIsBroken Note that module importer in mod_python 3.3 has been enhanced some what over prior versions in addition to fixing problems. An important new feature is being able to load modules based on their path with modules with same names in different directories being properly distinguished, something which is quite useful where modules are used in web applications to represent pages. You may want to look at documentation for it at: http://www.modpython.org/live/mod_python-3.3.0b/doc-html/pyapi-apmeth.html Graham From ccurvey at gmail.com Mon Dec 4 13:00:19 2006 From: ccurvey at gmail.com (Chris Curvey) Date: 4 Dec 2006 10:00:19 -0800 Subject: ISAPI filter Message-ID: <1165255219.807125.97400@16g2000cwy.googlegroups.com> Hi all, I'm trying to write an ISAPI filter in Python, using the examples that come in the "isapi" directory of the win32com package. The installation program itself runs fine, but when I examine the properties of my web server, my filter has a big red down arrow next to it. But I can't seem to figure out where I should be looking to find the trouble. If anyone can point me to the right place (or see an obvious error in the code below), I'd appreciate it. -Chris from isapi import isapicon, threaded_extension from isapi.simple import SimpleFilter import sys import traceback import urllib ########################################################################## class ImageProtectFilter(SimpleFilter): "Image Protection Filter" filter_flags = isapicon.SF_NOTIFY_AUTHENTICATION def HttpFilterProc(self, fc): return isapicon.SF_STATUS_REQ_HANDLED_NOTIFICATION ######################################################################### # The entry points for the ISAPI filter. def __FilterFactory__(): return ImageProtectFilter() if __name__=='__main__': # If run from the command-line, install ourselves. from isapi.install import * params = ISAPIParameters() # Setup all filters - these are global to the site. params.Filters = [ FilterParameters(Name="ImageProtectFilter", Description=ImageProtectFilter.__doc__), ] HandleCommandLine(params) From kentilton at gmail.com Tue Dec 12 09:02:47 2006 From: kentilton at gmail.com (Ken Tilton) Date: Tue, 12 Dec 2006 09:02:47 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7xhcw1l0sn.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7xhcw1l0sn.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Pascal Costanza writes: > >>You can start with loop by using only the simple and straightforward >>constructs, and slowly move towards the more complicated cases when >>necessary. The nice thing about loop is that with some practice, you >>can write code that more or less reads like English. > > > Yeah, but I'd also get English-like imprecision. Anyway, If I wanted > to write code that reads like English, I'd write in Cobol. That was my stance until.... There /is/ a second Lispy syntax for LOOP, btw. But the goofier syntax is also where lies part of the "win", so learn that. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From arkanes at gmail.com Fri Dec 8 16:08:00 2006 From: arkanes at gmail.com (Chris Mellon) Date: Fri, 8 Dec 2006 15:08:00 -0600 Subject: merits of Lisp vs Python In-Reply-To: <1165609434.129037.308390@f1g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4579c4f4$0$49201$14726298@news.sunsite.dk> <1165609434.129037.308390@f1g2000cwa.googlegroups.com> Message-ID: <4866bea60612081308y5fa1f626h8e67f9f38efbe717@mail.gmail.com> On 8 Dec 2006 12:23:54 -0800, Stephen Eilert wrote: > > Alex Mizrahi escreveu: > > > > > > we should feed this text to the query-builder. > > then we should bind ?dept to our variable departament (i'm not sure how this > > is done in SPARQL, but there should be a way). > > then we should iterate over results and output HTML. a python-like > > pseudocode: > > > > query = BuildQuery(query_str) > > query.bind("?dept", departament) > > results = query.execute() > > for each rs in results: > > print "" + htmlesc(rs.get("?fname")) + "" + > > htmlesc(rs.get("?lname")) + "" + rs.get("?salary") + "" > > I just want to add that this kind of HTML mixed with code is something > that should be avoided, no matter what language is used. > results = doQuery(department="Accounting") for row in results: for field in ["fname","lname","salary"]: print "%s" % htmlesc(row[field]) I hide away the binding etc in doQuery as the lisp version does. Note that in any kind of real code most of the literals that take up the space are likely to come from elsewhere. Note how much more trivial it is to change the HTML output of this version that the lisp - it's a matter of creating a format string, which you can retrieve from just about anywhere, rather than requiring a code refactoring. Just because you have macros doesn't mean it makes sense to use them. > > Stephen > > -- > http://mail.python.org/mailman/listinfo/python-list > From pjb at informatimago.com Wed Dec 20 13:22:49 2006 From: pjb at informatimago.com (Pascal Bourguignon) Date: Wed, 20 Dec 2006 19:22:49 +0100 Subject: merits of Lisp vs Python References: <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <45897266$0$4158$ba624c82@nntp02.dk.telia.net> <1166637630.367729.279830@n67g2000cwd.googlegroups.com> Message-ID: <871wmu5sw6.fsf@thalassa.informatimago.com> "Rob Thorpe" writes: > Anders J. Munch wrote: >> jayessay wrote: >> > Please note: GC is not part of CL's definition. It is likely not part >> > of any Lisp's definition (for reasons that should be obvious), and for >> > the same reasons likely not part of any language's definition. >> >> Really? So how do you write a portable program in CL, that is to run >> for unbounded lengths of time? > > You can't. You can. Just use reversible operations. Or use pre-allocated objects. Yes, that means that you implement your own memory management or garbage collector, but this would be portable. -- __Pascal Bourguignon__ http://www.informatimago.com/ "Do not adjust your mind, there is a fault in reality" -- on a wall many years ago in Oxford. From mail at microcorp.co.za Fri Dec 1 01:00:43 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Fri, 1 Dec 2006 08:00:43 +0200 Subject: Python Worship References: <1164906960.585165.64570@j44g2000cwa.googlegroups.com> <456F1A47.3000906@gmx.net> Message-ID: <02a201c71513$269661a0$03000080@hendrik> "Thomas Ploch" wrote: > Nick schrieb: > > http://www.sciencedaily.com/releases/2006/11/061130081347.htm > > > > World's Oldest Ritual Discovered -- Worshipped The Python 70,000 Years > > Ago > > > > Nick > > > > That's really interesting since there is an indio tribe in the amazonas > jungle which also worships python. > > That just tells me Python is right. Whatever angle you look at it. > > :-D > > Thomas Not too sure about this - in fact I find it worrying that there can be 70 000 years of continuous Python worship and not a wheel to be seen. There may be a message on the sinister side here... ;-) - Hendrik From true911m at gmail.com Wed Dec 6 21:08:19 2006 From: true911m at gmail.com (true911) Date: 6 Dec 2006 18:08:19 -0800 Subject: newb: Join two string variables In-Reply-To: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> References: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> Message-ID: <1165457299.817493.105860@73g2000cwn.googlegroups.com> johnny wrote: > How do I join two string variables? > I want to do: download_dir + filename. > download_dir=r'c:/download/' > filename =r'log.txt' > > I want to get something like this: > c:/download/log.txt pathfn = download_dir+filename From 2huggie at gmail.com Sat Dec 23 05:23:58 2006 From: 2huggie at gmail.com (Timothy Wu) Date: Sat, 23 Dec 2006 18:23:58 +0800 Subject: Gdmodule Message-ID: Hi, Is Gdmodule used much at all in the Python community or are there alternative packages more suitable for the purpose? I seem to find documentation for Gdmodule ( http://newcenturycomputers.net/projects/gd-ref.html) to require prior experience with the GD library in another language. Or at least, it's too difficult for me to grasp. Timothy -------------- next part -------------- An HTML attachment was scrubbed... URL: From wojciech_mula at poczta.null.onet.pl.invalid Tue Dec 26 13:23:46 2006 From: wojciech_mula at poczta.null.onet.pl.invalid (Wojciech =?ISO-8859-2?Q?Mu=B3a?=) Date: Tue, 26 Dec 2006 18:23:46 +0000 (UTC) Subject: Fuzzy string comparison References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> Message-ID: Steve Bergman wrote: > I'm looking for a module to do fuzzy comparison of strings. [...] Check module difflib, it returns difference between two sequences. From sjmachin at lexicon.net Sat Dec 2 21:47:43 2006 From: sjmachin at lexicon.net (John Machin) Date: 2 Dec 2006 18:47:43 -0800 Subject: converting dict to object In-Reply-To: <5wqch.1502$eb5.995@newsreading01.news.tds.net> References: <7649225.post@talk.nabble.com> <1165090584.103366.198220@l12g2000cwl.googlegroups.com> <5wqch.1502$eb5.995@newsreading01.news.tds.net> Message-ID: <1165114063.404791.205480@j72g2000cwa.googlegroups.com> Neil Cerutti wrote: > > Thanks for the pointer to keyword module. I hadn't noticed it > yet. Bonus: you got an extremely fresh, scarcely used pointer -- I wasn't aware of it myself till today :-) Cheers, John From jm.suresh at gmail.com Sat Dec 16 06:54:52 2006 From: jm.suresh at gmail.com (jm.suresh@no.spam.gmail.com) Date: 16 Dec 2006 03:54:52 -0800 Subject: catching exceptions Message-ID: <1166270092.297610.19890@n67g2000cwd.googlegroups.com> Hi, In the following program, I have a class Test which has a property x. Its setx function gets a string value and converts it into a float and stores into it. class Test(object): def _getx(self): return self._x def _setx(self,strvalue): try: self._x = float(strvalue) except ValueError: print 'Warning : could not set x attribute to %s' % strvalue x = property(_getx,_setx) def func1(value): a = Test() try: a.x = value except ValueError: #Pop up a error window. print 'This is second catch' func1('12') func1('12e1') func1('a') func1('12') func1('12e1') func1('a') >>> func1('a') Warning : could not set x attribute to a I am looking for a way to call func1's exception handler also. Basically I want to have the class's error handler as the basic text based one, and in the calling side, If I have gui, I will pop-up a window and say the error message. One solution is to remove the exception handling inside the class and leave the entire thing to the caller (software people call this client?) side -- if the caller has access to gui it will use gui or else will print the message. Any other way? -- Suresh From tiedon_jano at hotmail.com Wed Dec 13 09:35:41 2006 From: tiedon_jano at hotmail.com (Jussi Salmela) Date: Wed, 13 Dec 2006 14:35:41 GMT Subject: Large files uploading In-Reply-To: <1166014746.923171.38110@f1g2000cwa.googlegroups.com> References: <1165949410.458162.38300@79g2000cws.googlegroups.com> <1166014746.923171.38110@f1g2000cwa.googlegroups.com> Message-ID: <1dUfh.160$_z6.128@read3.inet.fi> Lad kirjoitti: >> to use any communications protocol (including HTTP), both ends must have >> programs that can talk that protocol... >> > Sure, but browsers have FTP support. But how to call the FTP API from > Python? > Lad. > See Python Library Reference for documentation on 'ftplib -- FTP protocol client'. It has an example to get you started. HTH, Jussi Salmela From larsnostdal at gmail.com Sat Dec 9 09:23:00 2006 From: larsnostdal at gmail.com (=?iso-8859-1?q?Lars_Rune_N=F8stdal?=) Date: Sat, 09 Dec 2006 15:23:00 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: On Sat, 09 Dec 2006 20:36:02 +1100, Steven D'Aprano wrote: > On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote: > >> if Common Lisp didn't have CLOS, its object system, I could write my own >> as a library and it would be just as powerful and just as easy to use as >> the system Common Lisp already provides. Stuff like this is impossible >> in other languages. > > Dude. Turing Complete. Don't you Lisp developers know anything about > computer science? > > Anything any language can do is possible in any other language, if you are > willing to write your own libraries. *lol* Good luck with that attitude: http://redwing.hutman.net/~mreed/warriorshtm/troglodyte.htm ..or did you forget to add "in theory"; which is of course what everyone already knows as they see their compilers do it every day. -- Lars Rune N?stdal http://nostdal.org/ From greg at cosc.canterbury.ac.nz Wed Dec 20 06:02:48 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 21 Dec 2006 00:02:48 +1300 Subject: python-hosting.com projects: dead? In-Reply-To: <4588567a$0$5744$afc38c87@news.optusnet.com.au> References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> <1166499192.027000.151290@j72g2000cwa.googlegroups.com> <1166499671.678929.25180@n67g2000cwd.googlegroups.com> <4upr9dF197g6cU1@mid.individual.net> <1166536534.892544.95850@73g2000cwn.googlegroups.com> <4588567a$0$5744$afc38c87@news.optusnet.com.au> Message-ID: <4usjloF19hma3U2@mid.individual.net> Richard Jones wrote: > Actually, to clarify the DEFAULT configuration for Trac is to leave it open > to spam. That sounds like a really bad choice of default. A bit like the way Windows comes with all the "let anyone in the world send me a virus" options turned on... -- Greg From peter at gradylevkov.com Thu Dec 21 11:20:24 2006 From: peter at gradylevkov.com (Peter Isaacs) Date: Thu, 21 Dec 2006 11:20:24 -0500 Subject: Strong Unix Developers wanted to work on OO-Database at Major Bank Message-ID: <5CFCAE3D-777A-4D5A-B12E-44AB63DB0CD9@gradylevkov.com> A premier bank in New York City is looking for strong unix developers to work on their homegrown OO-database. The ideal developer will have significant experience with one or more of a variety of languages including, Python, Perl, C++ or C. It is very important to have deep knowledge of unix and good understanding of databases. The role is focused more on exceptionally technical developers with less interest on obscure syntax or buzzword technologies. The company will happily help people relocate from anywhere in the country. Compensation will be quite good. If you are interested in the role feel free to contact me at Peter at Gradylevkov.com Thanks in advance. Best, Peter ________________________ Peter Isaacs, Vice President Grady Levkov & Company, Inc. 580 Broadway, Suite 1100 New York, NY 10012 v: 212-925-0900 x 106 f: 212-925-0200 peter at gradylevkov.com http://www.gradylevkov.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From misterwang at gmail.com Fri Dec 22 11:30:06 2006 From: misterwang at gmail.com (Peter Wang) Date: 22 Dec 2006 08:30:06 -0800 Subject: How a script can know if it has been called with the -i command line option? In-Reply-To: <1166720012.798260.6670@80g2000cwy.googlegroups.com> References: <1166720012.798260.6670@80g2000cwy.googlegroups.com> Message-ID: <1166805005.943645.193860@48g2000cwx.googlegroups.com> Michele Simionato wrote: > The subject says it all, I would like a script to act differently when > called as > $ python script.py and when called as $ python -i script.py. I looked > at the sys module > but I don't see a way to retrieve the command line flags, where should > I look? I realize this is quite a hack, but the entire command line is preserved in the process's entry in the OS's process table. if you do "ps -ax" you will see that the interpreter was invoked with -i. I didn't test this under windows, but it works on Mac and Linux. From kentilton at gmail.com Sun Dec 10 02:00:02 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sun, 10 Dec 2006 02:00:02 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <7xejr8r86m.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > On Sat, 09 Dec 2006 22:41:12 -0500, Ken Tilton wrote: > > >>>I know that. It was more of a rhetorical question -- Lispers are either >>>trying to emphasis the radical nature of what you can do with macros, or >>>understate it and make them seem just like functions. >> >>Yep, both. The first is rare. CLOS is one, my Cells (ported this summer >>to PyCells as part of SoC 2006) is another. The latter is the norm. > > > If macros' advanced usage is rare, Hunh? I have tons of them. Of coure at your level of discourse you will want to know if those are metric tons or... ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From fredrik at pythonware.com Sat Dec 9 10:53:06 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 09 Dec 2006 16:53:06 +0100 Subject: py2exe Problem with cairo In-Reply-To: <1165678800.276619.236140@n67g2000cwd.googlegroups.com> References: <1165678800.276619.236140@n67g2000cwd.googlegroups.com> Message-ID: Michax wrote: > Hi, > > I have problem with my py2exe. When I want to run my compiled exe, then > i get error information like that: > > Trackback (most recent call last): > File "mysql_gui.py", line 2 in ? > File "gtk\__int__.pyc", line 12, in ? > File "gtk\_gtk.pyc", line 12, in ? > File "gtk\_gtk.pyc", line 10, in __load > ImportError: No module named cairo > > I have similar problem with all compiled .exe using gtk library. seen this: http://www.py2exe.org/index.cgi/Py2exeAndPyGTK ? From bblais at bryant.edu Thu Dec 14 21:36:31 2006 From: bblais at bryant.edu (Brian Blais) Date: Thu, 14 Dec 2006 21:36:31 -0500 Subject: automatically grading small programming assignments In-Reply-To: <1166123772.726309.138790@16g2000cwy.googlegroups.com> References: <1166123772.726309.138790@16g2000cwy.googlegroups.com> Message-ID: <45820A2F.5030204@bryant.edu> Paddy wrote: > It might turn out to be a poor substitute for the personal touch, > especially If they are just starting to program. Oh, I didn't mean it to completely replace me grading things, but I think it would be useful if there were a lot of little assignments that could be done automatically, and then some larger ones that I would grade by hand. The little ones could be set up so that they can submit as many times as they want, until they get it right. bb -- ----------------- bblais at bryant.edu http://web.bryant.edu/~bblais From bignose+hates-spam at benfinney.id.au Wed Dec 6 23:21:00 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 07 Dec 2006 15:21:00 +1100 Subject: newb: How to call one modue from other References: <1165450007.504080.327490@80g2000cwy.googlegroups.com> <1165458032.135595.321240@f1g2000cwa.googlegroups.com> <1165464211.416352.26540@80g2000cwy.googlegroups.com> Message-ID: <87ejrcpc9f.fsf@benfinney.id.au> "johnny" writes: > Gabriel Genellina wrote: > > > Reading the Python Tutorial helps a lot. > > > I did read "Dive Into Python", one week ago. It's a good book, but > it didn't cover this kind of situation. Yes, it is good. It's also not the Python tutorial. The Python tutorial is this document: It's very beneficial to *work through* the tutorial, executing and understanding each example before moving onto the next. (This is more than "read the tutorial" that others sometimes suggest.) -- \ "A man must consider what a rich realm he abdicates when he | `\ becomes a conformist." -- Ralph Waldo Emerson | _o__) | Ben Finney From RichardTRMurphy at yahoo.com Wed Dec 13 21:36:14 2006 From: RichardTRMurphy at yahoo.com (rich murphy) Date: 13 Dec 2006 18:36:14 -0800 Subject: The Famous Error Message: "ImportError: No module named python_script" In-Reply-To: References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> Message-ID: <1166063774.460600.17650@80g2000cwy.googlegroups.com> Thank you both for responding. Yes of course the file has the ".py" extension and yes I went through the tutorial. Gabriel Genellina wrote: > At Wednesday 13/12/2006 22:16, rich murphy wrote: > > >I am studying Python language. I have Python 2.5 installed in my PC > >which is running on Windows XP. I placed the the script called > >"python_script" in C:\Python25 directory where all the other Python > >files are. > > Verify the file name, should be "python_script.py" > > You may want to un-select "Hide extensions for known file types" in > Windows Explorer options. > > > -- > Gabriel Genellina > Softlab SRL > > __________________________________________________ > Correo Yahoo! > Espacio para todos tus mensajes, antivirus y antispam ?gratis! > ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From Benjamin.Barker at gmail.com Wed Dec 27 13:43:25 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 27 Dec 2006 10:43:25 -0800 Subject: DOS, UNIX and tabs In-Reply-To: <12p5ffrsdo6v088@corp.supernews.com> References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> <1167244483.792673.132220@42g2000cwt.googlegroups.com> <12p5ffrsdo6v088@corp.supernews.com> Message-ID: <1167245005.678672.196280@73g2000cwn.googlegroups.com> Great - that worked.Thanks! Is that a general method in linux you can always use to redirect standard output to a file? Cheers, Ben Grant Edwards wrote: > On 2006-12-27, Ben wrote: > > I've found the unexpand command, which seems to do the trick. However, > > it outputs to standard output, and I haven't worked out yet how to > > capture that output to a file... > > unexpand file2 > > -- > Grant Edwards grante Yow! Hey, LOOK!! A pair of > at SIZE 9 CAPRI PANTS!! They > visi.com probably belong to SAMMY > DAVIS, JR.!! From skpatel20 at gmail.com Thu Dec 14 07:03:58 2006 From: skpatel20 at gmail.com (Sanjay) Date: 14 Dec 2006 04:03:58 -0800 Subject: Routine for prefixing '>' before every line of a string Message-ID: <1166097838.257731.297110@l12g2000cwl.googlegroups.com> Hi All, Is somewhere a routine useful to convert a string to lines of maxsize, each prefixed with a '>'. This is a typical requirement for 'keeping existing text while replying to a post in a forum'. It can be developed, but if something obvious is already there(I being new to python might not be aware), than it would be great just to reuse it! thanks sanjay From ptmcg at austin.rr._bogus_.com Fri Dec 22 21:28:27 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 22 Dec 2006 20:28:27 -0600 Subject: pyparsing announcement? Message-ID: <458c944d$0$16944$4c368faf@roadrunner.com> I have tried a couple of times now to post an announcement of the latest version of pyparsing, but it does not seem to be making it past the news server, neither through my local ISP's server nor through GoogleGroups. Could it be because I am also posting to comp.lang.python.announce, and this moderated group is holding up posts to all groups? (Doesn't really make sense to me, but it's all I can come up with.) Or is the announcement getting out, and my newsreader just not showing it for some reason? -- Paul From martin at v.loewis.de Tue Dec 19 15:50:06 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 19 Dec 2006 21:50:06 +0100 Subject: urllib.unquote and unicode In-Reply-To: References: <1166497058.109088.53120@80g2000cwy.googlegroups.com> <1166504578.169707.154900@n67g2000cwd.googlegroups.com> Message-ID: <4588507E.20602@v.loewis.de> Duncan Booth schrieb: > The way that uri encoding is supposed to work is that first the input > string in unicode is encoded to UTF-8 and then each byte which is not in > the permitted range for characters is encoded as % followed by two hex > characters. Can you back up this claim ("is supposed to work") by reference to a specification (ideally, chapter and verse)? In URIs, it is entirely unspecified what the encoding is of non-ASCII characters, and whether % escapes denote characters in the first place. > Unfortunately RFC3986 isn't entirely clear-cut on this issue: > >> When a new URI scheme defines a component that represents textual >> data consisting of characters from the Universal Character Set [UCS], >> the data should first be encoded as octets according to the UTF-8 >> character encoding [STD63]; then only those octets that do not >> correspond to characters in the unreserved set should be percent- >> encoded. For example, the character A would be represented as "A", >> the character LATIN CAPITAL LETTER A WITH GRAVE would be represented >> as "%C3%80", and the character KATAKANA LETTER A would be represented >> as "%E3%82%A2". This is irrelevant, it talks about new URI schemes only. > I think it leaves open the possibility that existing URI schemes which do > not support unicode characters can use other encodings, but given that the > original posting started by decoding a unicode string I think that utf-8 > should definitely be assumed in this case. No, the http scheme is defined by RFC 2616 instead. It doesn't really talk about encodings, but hints an interpretation in 3.2.3: # When comparing two URIs to decide if they match or not, a client # SHOULD use a case-sensitive octet-by-octet comparison of the entire # URIs, [...] # Characters other than those in the "reserved" and "unsafe" sets (see # RFC 2396 [42]) are equivalent to their ""%" HEX HEX" encoding. Now, RFC 2396 already says that URIs are sequences of characters, not sequences of octets, yet RFC 2616 fails to recognize that issue and refuses to specify a character set for its scheme (which RFC 2396 says that it could). The conventional wisdom is that the choice of URI encoding for HTTP is a server-side decision; for that reason, IRIs were introduced. Regards, Martin From pc at p-cos.net Tue Dec 12 05:53:39 2006 From: pc at p-cos.net (Pascal Costanza) Date: Tue, 12 Dec 2006 11:53:39 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <4u7g1kF17436jU1@mid.individual.net> I V wrote: > One of the things I've always found off-putting about lisp as that all the > syntax looks the same. In Algol-derived languages, each syntactic > construct has a fairly distinctive appearance, so when, for instance, I > encounter a for loop, I can quickly recognize that that's what it is, and > bracket out the "scaffolding" and pick out the details that interest me. > With lisp, I can't do that, I have to read through the sexp, decide on > what syntax it is, and then remind myself where to look for the relevant > specific details. May you have tried the wrong Lisp dialects so far: (loop for i from 2 to 10 by 2 do (print i)) This is Common Lisp. (Many Lisp and Scheme tutorials teach you that you should implement this using recursion, but you really don't have to. ;) Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From jordan.taylor2 at gmail.com Mon Dec 11 20:32:58 2006 From: jordan.taylor2 at gmail.com (Jordan) Date: 11 Dec 2006 17:32:58 -0800 Subject: Tarfile .bz2 In-Reply-To: References: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> Message-ID: <1165887178.775792.142820@80g2000cwy.googlegroups.com> So that would explain why a tar.bz2 archive can't be appended to wouldn't it... And also explain why winrar was so slow to open it (not something I mentioned before, but definitely noticed). I had wondered what it was that made bz2 so much better at compression than zip and rar. Not really on topic anymore but what's the method for tar.gz? And even more off the topic, does anyone know a good lossless compression method for images (mainly .jpg and .png)? Cheers, Jordan Wolfgang Draxinger wrote: > Jordan wrote: > > > When using python to create a tar.bz2 archive, and then using > > winrar to open the archive, it can't tell what the compressed > > size of each > > individual file in the archive is. Is this an issue with > > winrar or is there something that needs to be set when making > > the archive that isn't there by default. > > When compressing a tar archive all files in the archive are > compressed as a whole, i.e. you can only specify a compression > ration for the whole archive and not just for a single file. > > Technically a tar.bz2 is actually a aggregation of multiple files > into a single tar file, which is then compressed. > > This is different to e.g. PKZip in which each file is compressed > individually and the compressed files are then merged into an > archive. > > The first method has better compression ratio, since redundancies > among files are compressed, too, whereas the latter is better if > you need random access to the individual files. > > Wolfgang Draxinger > -- > E-Mail address works, Jabber: hexarith at jabber.org, ICQ: 134682867 From fredrik at pythonware.com Tue Dec 5 01:25:04 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 07:25:04 +0100 Subject: MySQL from python - dropping a database IF EXISTS In-Reply-To: <1165275827.837861.173270@73g2000cwn.googlegroups.com> References: <1165271835.671807.200480@79g2000cws.googlegroups.com> <1165275827.837861.173270@73g2000cwn.googlegroups.com> Message-ID: Ben wrote: > Ah well - I turned off warnings as a solution. Its a bit f a bodge, but > it works :-) according to the documentation, the database does generate a "note" when you do this: http://dev.mysql.com/doc/refman/5.0/en/drop-table.html and notes can be turned off independently of warnings, it seems: http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html From anthonybaxter at gmail.com Sat Dec 30 05:37:52 2006 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 30 Dec 2006 21:37:52 +1100 Subject: Looking for python SIP/MGCP stacks In-Reply-To: <1ECA23B17E8AB54C859FA0449B729F0E034284DA@xmb-sjc-235.amer.cisco.com> References: <1ECA23B17E8AB54C859FA0449B729F0E034284DA@xmb-sjc-235.amer.cisco.com> Message-ID: > I am using python to write a testing tools, currently this tool only > supports skinny protocol. I am planning to add SIP and MGCP support as well, > wondering if you have written these protocol stacks before which can be > leveraged from. There's two I know of - shtoom and Divmod Sine. The latter is a more complete implementation of SIP and probably what you want to use. From sjmachin at lexicon.net Sun Dec 3 22:01:57 2006 From: sjmachin at lexicon.net (John Machin) Date: 3 Dec 2006 19:01:57 -0800 Subject: Parsing data from pyserial, an (inefficient) solution In-Reply-To: References: Message-ID: <1165201317.849665.56870@l12g2000cwl.googlegroups.com> Lone Wolf wrote: Your code has a problem when the first character of reading is 'M': you will miss the full packet and pick up a fragment. The length test that you are doing to reject the fragment is a kludge. If the average length of a packet is say 25, then you are throwing away 4% of all packets on average. Try this [untested]: reading = ser.read(40) # components = reading.split("M") # components = components[1] # if len(components) > 23: # If shorter than 24 it won't have enough data for a full packet # subcomponents = components.split() pos_past_m = reading.index('M') + 1 subcomponents = reading[pos_past_m:].split() mx = int(subcomponents[0]) my = int(subcomponents[1]) confidence = int(subcomponents[7]) print mx, my, confidence > > The really sad thing is that I get a perfectly constructed > packet from the reading variable, What we tell you three times is true, you are *NOT* getting a perfectly formed packet from the reading variable; you are getting 40 bytes of guff which will be long enough to contain a packet with possible stray fragments at either end. Do this: print len(reading) print repr(reading) and see for yourself. > and that gets butchered when I > try to slice it up to pick out individual elements. Since > pyserial doesn't do anything to rearrange the data, then the > CMUcam must do the heavy lifting of extracting a perfect packet > from the data stream. Huh? I thought the CMUcam was *creating* the data stream -- how could it be *extracting* a "perfect packet" from it? > It's a real shame I couldn't use it > because the program would be more efficient. Somebody else gave you a clue: use the readline method instead of the read method; have you tried that? It's more likely to stop on a packet boundary that what you are doing. As far as starting on a packet boundary is concerned, have you explored your options with buffering and flow control? > FWIW, this code > will analyze 2-3 frames per second on my computer, which is > enough for my purposes. > > In case you couldn't tell from the questions/code, I am a total > beginner, and I really appreciate this list. All I needed was a > hand, not a handout. Wolves are willing to hunt for their > supper. Independence is one thing. Ignoring plausible truth told to you by multiple independent people with no axe to grind is another :-) HTH, John From fredrik at pythonware.com Fri Dec 22 13:46:45 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 22 Dec 2006 19:46:45 +0100 Subject: Generating all permutations from a regexp In-Reply-To: References: Message-ID: Nick Craig-Wood wrote: > A regular expression matcher uses a state machine to match strings. unless it's the kind of regular expression matcher that doesn't use a state machine, like the one in Python. From fredrik at pythonware.com Tue Dec 5 03:41:28 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 09:41:28 +0100 Subject: how to invoke the shell command and then get the result in python In-Reply-To: <1165306945.315445.303490@80g2000cwy.googlegroups.com> References: <1165303175.523129.154400@j72g2000cwa.googlegroups.com> <1165306945.315445.303490@80g2000cwy.googlegroups.com> Message-ID: petercable at gmail.com wrote: > Also, for a wrapper around popen, try commands: > > import commands > > pattern = raw_input('pattern to search? ') > print commands.getoutput('grep %s *.txt' % pattern) that's not quite as portable as the other alternatives, though. "grep" is at least available for non-Unix platforms, but "commands" requires a unix shell. for Python 2.5 and later, you could use: def getoutput(cmd): from subprocess import Popen, PIPE, STDOUT p = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=isinstance(cmd, basestring)) return p.communicate()[0] print getoutput(["grep", pattern, glob.glob("*.txt")]) which, if given a list instead of a string, passes the arguments right through to the underlying process, without going through the shell (consider searching for "-" or ";rm" with the original code). From gagsl-py at yahoo.com.ar Wed Dec 13 14:03:21 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 13 Dec 2006 11:03:21 -0800 Subject: Conditional iteration In-Reply-To: <45804699$0$334$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <45804699$0$334$e4fe514c@news.xs4all.nl> Message-ID: <1166036601.305267.234040@l12g2000cwl.googlegroups.com> > I just need to get work done and I see this type of conditional iteration > showing up many times obscuring my code because of the additional > indentation. Me too. When I don't like the additional indentation I usually have: if not condition: continue at the beginning of the block > In line with previous syntax improvements made in Python my proposal (or > obvious variants) seems a logical next step. Unless of course nobody > appreciates it. That's the discussion I'd like to have here in the forum. Looks good to me. -- Gabriel Genellina From amichail at gmail.com Fri Dec 1 16:35:43 2006 From: amichail at gmail.com (Amir Michail) Date: 1 Dec 2006 13:35:43 -0800 Subject: python vs java & eclipse In-Reply-To: <1165008224.116326.36580@79g2000cws.googlegroups.com> References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <45701422.4050206@gmx.net> <1165008224.116326.36580@79g2000cws.googlegroups.com> Message-ID: <1165008943.818877.315360@80g2000cwy.googlegroups.com> sjdevnull at yahoo.com wrote: > ... > > Is there anything _useful_ that it'll bring that a good editor doesn't? > e.g. in vim I do get > * automatic syntax checking (if I type "if a=1:" and hit enter, it'll > immediately highlight the syntax error) > * omni-completion (because Intellisense is trademarked) > * refactoring (with BicycleRepairMan integration) > * folding (which is more important than the above 3 combined, IMO) > * online help (typing cmp( gives me the docstring for cmp in the status > line, F1 to view the whole thing) > > As well as all the basics (tags/class browser/good regex support/syntax > highlighting/autoindent/source control integration/etc). > > I'm not trolling here, I'm looking for interesting new features I can > steal. How about we try to find some papers on the subject? Here's one to start things off: http://pag.csail.mit.edu/~akiezun/companion.pdf Amir From frank at chagford.com Sat Dec 16 00:58:39 2006 From: frank at chagford.com (Frank Millman) Date: 15 Dec 2006 21:58:39 -0800 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: Message-ID: <1166248719.007543.134370@j72g2000cwa.googlegroups.com> dyork wrote: > When getting data from a database using the dbapi and an SQL query, how do > you in general round trip the data? Especially date-time? > This is what I do. I am posting this partly because I hope it helps, partly because it is a bit clunky and I would appreciate suggestions for improvements. I have two constraints. 1. I support PostgreSQL using psycopg, which handles datetime objects very well, and MS SQL Server using pywin32.odbc, which does not handle datetime objects at all. 2. PostgreSQL has datatypes for 'timestamp' and for 'date'. I use the former for things like 'time/date record was created', and the latter for things like 'invoice date'. However, internally in my app, I only want to use datetime.datetime objects. I agree with the principle that dates should only be stored internally as datetime objects, but I also allow None where the database value is null. To achieve this I use the following - import datetime as dt def dbToDate(date): if date is None: return date if isinstance(date,dt.datetime): # psycopg can return this type return date # already in datetime format if isinstance(date,dt.date): # psycopg can return this type return dt.datetime.combine(date,dt.time(0)) # convert to datetime return dt.datetime.fromtimestamp(int(date)) # win32/odbc returns type DbiDate When writing the date back to the database, I cannot pass the datetime object directly, as pywin32.odbc does not recognise this. I have found that str(date) - where date is a datetime object - converts it into a string that is acceptable to both PostgreSQL and MS SQL Server. HTH Frank Millman From jordan.taylor2 at gmail.com Mon Dec 11 16:08:55 2006 From: jordan.taylor2 at gmail.com (Jordan) Date: 11 Dec 2006 13:08:55 -0800 Subject: Tarfile .bz2 Message-ID: <1165871335.386540.29770@l12g2000cwl.googlegroups.com> When using python to create a tar.bz2 archive, and then using winrar to open the archive, it can't tell what the compressed size of each individual file in the archive is. Is this an issue with winrar or is there something that needs to be set when making the archive that isn't there by default. example archive: #Note, the tabs on this are not really tabs, so good luck copying it correctly import os, tarfile archive = tarfile.open("archive.tar.bz2","w:bz2") for thing in os.listdir(somepath): nthing = somepath+thing if os.path.isfile(nthing): # somepath must end in "\\" for this to work info = archive.gettarinfo(nthing) archive.addfile(info,file(nthing,'rb')) archive.close() --- Thanks, Jordan From kgmuller at gmail.com Wed Dec 20 08:16:37 2006 From: kgmuller at gmail.com (Klaus Muller) Date: Wed, 20 Dec 2006 14:16:37 +0100 Subject: Is htmlGen still alive? In-Reply-To: <7.0.1.0.0.20061219164056.054aa028@yahoo.com.ar> Message-ID: <458937bb.555596ec.0789.fffff0d3@mx.google.com> Thank you for this input. I was primarily looking for a download site. I downloaded HyperText and definitely will give it a try. It looks good. Klaus > -----Original Message----- > From: Gabriel Genellina [mailto:gagsl-py at yahoo.com.ar] > Sent: Tuesday, December 19, 2006 8:49 PM > To: kgmuller at gmail.com > Cc: python-list at python.org > Subject: Re: Is htmlGen still alive? > > At Monday 18/12/2006 17:37, kgmuller at gmail.com wrote: > > >Does anybody know whether htmlGen, the Python-class library for > >generating HTML, is still being maintained? Or from where it can be > >downloaded? The Starship site where it used to be hosted is dead. > > *active* in what sense? HTML std doesn't change all days, and > being a python only library, the only changes would be due to > compatibility issues or adopting new language features of new > python versions. > BTW, I like HyperText more than htmlgen. > > > -- > Gabriel Genellina > Softlab SRL > > > > > > > __________________________________________________ > Pregunta. Respondi. Descubrm. > Todo lo que quermas saber, y lo que ni imaginabas, > esta en Yahoo! Respuestas (Beta). > !Probalo ya! > http://www.yahoo.com.ar/respuestas > > From fredrik at pythonware.com Tue Dec 19 08:12:19 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 14:12:19 +0100 Subject: python-hosting.com projects: dead? In-Reply-To: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> Message-ID: jpellerin+nose at gmail.com wrote: > It looks to me like python hosting, aka webfaction, have shut down > access to all projects hosted under their free hosting for open source > python projects program. Including mine (nose). With no notice -- at > least none that I received. > > Surprised doesn't quite cover it. Perhaps someone from python hosting > can explain why this was done, why no notice was given (if it wasn't), > and how those of us trying to restart our projects elsewhere can get > access to our subversion repositories and trac data. have you tried mailing webfaction instead of ranting on the usenet? my account was temporarily disabled as well, during an attempt to clean out seemingly abandoned trac instances, but was back online in less than fifteen minutes after I'd mailed them. you'll find the contact info in the mail you got when you signed up. From haraldarminmassa at gmail.com Mon Dec 18 05:16:30 2006 From: haraldarminmassa at gmail.com (GHUM) Date: 18 Dec 2006 02:16:30 -0800 Subject: Roundtrip SQL data especially datetime In-Reply-To: References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> <1166258893.044093.196820@79g2000cws.googlegroups.com> Message-ID: <1166436990.570027.237260@t46g2000cwa.googlegroups.com> > One side effect of this being third party code is that hosting > services may not have it available, even when they have both Python > and MySQL up. This is never a problem with Perl or PHP, so that's > a negative for Python. I for one think it is a good thing to not have MySQL adapters integrated into Python core. Neither the philopsophie, nor the licence of the two products fit together. But maybe that's because I am a PostgreSQL zealot - and PostgreSQL and Python is really a match made in heaven. Harald From jussij at zeusedit.com Tue Dec 26 22:12:29 2006 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: 26 Dec 2006 19:12:29 -0800 Subject: Newbie: what is a usefull IDE for Python on Windows ? References: Message-ID: <1167189149.409122.154180@48g2000cwx.googlegroups.com> Osiris wrote: > what is a usefull IDE for Python on Windows ? The Zeus IDE: http://www.zeusedit.com/python.html Jussi From pjb at informatimago.com Wed Dec 13 05:26:55 2006 From: pjb at informatimago.com (Pascal Bourguignon) Date: Wed, 13 Dec 2006 11:26:55 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> <457fc327$0$1038$426a74cc@news.free.fr> Message-ID: <87lklcrt00.fsf@thalassa.informatimago.com> Christophe writes: > Robert Uhl a ?crit : >> aahz at pythoncraft.com (Aahz) writes: >>> Consider this: Lisp has had years of development, it has had millions of >>> dollars thrown at it by VC firms -- and yet Python is winning over Lisp >>> programmers. Think about it. >> >> The argument from popularity is invalid. French units have overtaken >> standard units, > Never heard of that French unit thing. Unless you talk about that > archaic unit system that was in use before the metric system was > created. Who invented the metric system? -- __Pascal Bourguignon__ http://www.informatimago.com/ Wanna go outside. Oh, no! Help! I got outside! Let me back inside! From etaoinbe at yahoo.com Tue Dec 5 11:19:02 2006 From: etaoinbe at yahoo.com (etaoinbe) Date: 5 Dec 2006 08:19:02 -0800 Subject: Fw: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 In-Reply-To: References: Message-ID: <1165335542.402398.193100@f1g2000cwa.googlegroups.com> I have added advapi32 &user32. This is my current result : I am quite surprised there are so many issues with the solution file that comes with python25. I remember py23 built out of the box :( 1>------ Build started: Project: make_versioninfo, Configuration: Debug Win32 ------ 2>------ Build started: Project: make_buildinfo, Configuration: Debug Win32 ------ 1>Linking... 2>Linking... 1>Embedding manifest... 2>Embedding manifest... 2>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-release\make_buildinfo\BuildLog.htm" 2>make_buildinfo - 0 error(s), 0 warning(s) 1>Performing Custom Build Step 1>Performing Post-Build Event... 1>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\make_versioninfo\BuildLog.htm" 1>make_versioninfo - 0 error(s), 0 warning(s) 3>------ Build started: Project: python, Configuration: Debug Win32 ------ 3>Linking... 3>Embedding manifest... 4>------ Build started: Project: pythoncore, Configuration: Debug Win32 ------ 3>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\python\BuildLog.htm" 3>python - 0 error(s), 0 warning(s) 4>generate buildinfo 4>cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL -D_DEBUG -MDd ..\Modules\getbuildinfo.c -Fogetbuildinfo.o -I..\Include -I..\PC 4>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86 4>Copyright (C) Microsoft Corporation. All rights reserved. 4>getbuildinfo.c 4>Linking... 4> Creating library .\./python25_d.lib and object .\./python25_d.exp 5>------ Build started: Project: w9xpopen, Configuration: Debug Win32 ------ 5>Linking... 4>config.obj : error LNK2001: unresolved external symbol _init_types 4>getversion.obj : error LNK2019: unresolved external symbol _Py_GetBuildInfo referenced in function _Py_GetVersion 4>posixmodule.obj : error LNK2019: unresolved external symbol __imp__ShellExecuteA at 24 referenced in function _win32_startfile 4>posixmodule.obj : error LNK2019: unresolved external symbol __imp__ShellExecuteW at 24 referenced in function _win32_startfile 4>sysmodule.obj : error LNK2019: unresolved external symbol __Py_svnversion referenced in function _svnversion_init 4>./python25_d.dll : fatal error LNK1120: 5 unresolved externals 4>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\pythoncore\BuildLog.htm" 4>pythoncore - 6 error(s), 0 warning(s) 5>Embedding manifest... 5>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\w9xpopen\BuildLog.htm" 5>w9xpopen - 0 error(s), 0 warning(s) 6>------ Build started: Project: _ctypes, Configuration: Debug Win32 ------ 7>------ Build started: Project: _msi, Configuration: Debug Win32 ------ 7>Linking... 6>Linking... 7> Creating library .\./_msi.lib and object .\./_msi.exp 7>_msi.obj : error LNK2019: unresolved external symbol __imp__RpcStringFreeA at 4 referenced in function _uuidcreate 7>_msi.obj : error LNK2019: unresolved external symbol __imp__UuidToStringA at 8 referenced in function _uuidcreate 7>_msi.obj : error LNK2019: unresolved external symbol __imp__UuidCreate at 4 referenced in function _uuidcreate 6> Creating library .\./_ctypes_d.lib and object .\./_ctypes_d.exp 7>_msi.obj : error LNK2019: unresolved external symbol _FCIDestroy referenced in function _fcicreate 7>_msi.obj : error LNK2019: unresolved external symbol _FCIFlushCabinet referenced in function _fcicreate 7>_msi.obj : error LNK2019: unresolved external symbol _FCIAddFile referenced in function _fcicreate 7>_msi.obj : error LNK2019: unresolved external symbol _FCICreate referenced in function _fcicreate 7>_msi.obj : error LNK2019: unresolved external symbol _MsiCloseHandle at 4 referenced in function _msiobj_dealloc 7>_msi.obj : error LNK2019: unresolved external symbol _MsiRecordGetFieldCount at 4 referenced in function _record_getfieldcount 7>_msi.obj : error LNK2019: unresolved external symbol _MsiRecordClearData at 4 referenced in function _record_cleardata 7>_msi.obj : error LNK2019: unresolved external symbol _MsiFormatRecordA at 16 referenced in function _msierror 7>_msi.obj : error LNK2019: unresolved external symbol _MsiRecordGetInteger at 8 referenced in function _msierror 7>_msi.obj : error LNK2019: unresolved external symbol _MsiGetLastErrorRecord at 0 referenced in function _msierror 7>_msi.obj : error LNK2019: unresolved external symbol _MsiRecordSetStringA at 12 referenced in function _record_setstring 7>_msi.obj : error LNK2019: unresolved external symbol _MsiRecordSetStreamA at 12 referenced in function _record_setstream 7>_msi.obj : error LNK2019: unresolved external symbol _MsiRecordSetInteger at 12 referenced in function _record_setinteger 7>_msi.obj : error LNK2019: unresolved external symbol _MsiSummaryInfoGetPropertyA at 28 referenced in function _summary_getproperty 7>_msi.obj : error LNK2019: unresolved external symbol _MsiSummaryInfoGetPropertyCount at 8 referenced in function _summary_getpropertycount 7>_msi.obj : error LNK2019: unresolved external symbol _MsiSummaryInfoSetPropertyA at 24 referenced in function _summary_setproperty 7>_msi.obj : error LNK2019: unresolved external symbol _MsiSummaryInfoPersist at 4 referenced in function _summary_persist 7>_msi.obj : error LNK2019: unresolved external symbol _MsiViewExecute at 8 referenced in function _view_execute 7>_msi.obj : error LNK2019: unresolved external symbol _MsiViewFetch at 8 referenced in function _view_fetch 7>_msi.obj : error LNK2019: unresolved external symbol _MsiViewGetColumnInfo at 12 referenced in function _view_getcolumninfo 7>_msi.obj : error LNK2019: unresolved external symbol _MsiViewModify at 12 referenced in function _view_modify 7>_msi.obj : error LNK2019: unresolved external symbol _MsiViewClose at 4 referenced in function _view_close 7>_msi.obj : error LNK2019: unresolved external symbol _MsiDatabaseOpenViewA at 12 referenced in function _msidb_openview 7>_msi.obj : error LNK2019: unresolved external symbol _MsiDatabaseCommit at 4 referenced in function _msidb_commit 7>_msi.obj : error LNK2019: unresolved external symbol _MsiGetSummaryInformationA at 16 referenced in function _msidb_getsummaryinformation 7>_msi.obj : error LNK2019: unresolved external symbol _MsiOpenDatabaseA at 12 referenced in function _msiopendb 7>_msi.obj : error LNK2019: unresolved external symbol _MsiCreateRecord at 4 referenced in function _createrecord 7>./_msi.pyd : fatal error LNK1120: 30 unresolved externals 6>callproc.obj : error LNK2019: unresolved external symbol __imp__SysFreeString at 4 referenced in function _GetComError 6>cfield.obj : error LNK2001: unresolved external symbol __imp__SysFreeString at 4 6>callproc.obj : error LNK2019: unresolved external symbol __imp__ProgIDFromCLSID at 8 referenced in function _GetComError 6>callproc.obj : error LNK2019: unresolved external symbol __imp__GetErrorInfo at 8 referenced in function _GetComError 6>cfield.obj : error LNK2019: unresolved external symbol __imp__SysAllocStringLen at 8 referenced in function _BSTR_set 6>cfield.obj : error LNK2019: unresolved external symbol __imp__SysStringLen at 4 referenced in function _BSTR_get 6>./_ctypes_d.pyd : fatal error LNK1120: 5 unresolved externals 7>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\_msi\BuildLog.htm" 7>_msi - 31 error(s), 0 warning(s) 6>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\_ctypes\BuildLog.htm" 6>_ctypes - 7 error(s), 0 warning(s) 8>------ Build started: Project: _sqlite3, Configuration: Debug Win32 ------ 8>Compiling... 8>util.c 8>d:\python-2.5\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 8>statement.c 8>d:\python-2.5\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 8>row.c 9>------ Build started: Project: _ctypes_test, Configuration: Debug Win32 ------ 8>d:\python-2.5\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 9>Linking... 8>module.c 9> Creating library .\./_ctypes_test_d.lib and object .\./_ctypes_test_d.exp 9>_ctypes_test.obj : error LNK2019: unresolved external symbol __imp__SysAllocString at 4 referenced in function _GetString 9>./_ctypes_test_d.pyd : fatal error LNK1120: 1 unresolved externals 9>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\_ctypes_test\BuildLog.htm" 9>_ctypes_test - 2 error(s), 0 warning(s) 8>d:\python-2.5\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 8>microprotocols.c 10>------ Build started: Project: pythoncore_pgo, Configuration: Release Win32 ------ 8>d:\python-2.5\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 8>cursor.c 10>Performing Custom Build Step 8>d:\python-2.5\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 8>connection.c 10>File not found - python.exe* 10>0 File(s) copied 10>Compiling resources... 10>..\PC\python_nt.rc(12) : fatal error RC1015: cannot open include file 'pythonnt_rc.h'. 10>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-release\pythoncore_pgo\BuildLog.htm" 10>pythoncore_pgo - 1 error(s), 0 warning(s) 8>d:\python-2.5\modules\_sqlite\connection.h(33) : fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory 8>Generating Code... 8>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\_sqlite3\BuildLog.htm" 8>_sqlite3 - 7 error(s), 0 warning(s) 11>------ Build started: Project: _elementtree, Configuration: Debug Win32 ------ 11>Linking... 11> Creating library .\./_elementtree_d.lib and object .\./_elementtree_d.exp 11>Embedding manifest... 12>------ Build started: Project: winsound, Configuration: Debug Win32 ------ 11>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\_elementtree\BuildLog.htm" 11>_elementtree - 0 error(s), 0 warning(s) 12>Linking... 12> Creating library .\./winsound_d.lib and object .\./winsound_d.exp 12>winsound.obj : error LNK2019: unresolved external symbol __imp__PlaySoundA at 12 referenced in function _sound_playsound 12>./winsound_d.pyd : fatal error LNK1120: 1 unresolved externals 12>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\winsound\BuildLog.htm" 12>winsound - 2 error(s), 0 warning(s) 13>------ Build started: Project: unicodedata, Configuration: Debug Win32 ------ 13>Linking... 13> Creating library .\./unicodedata_d.lib and object .\./unicodedata_d.exp 13>Embedding manifest... 14>------ Build started: Project: select, Configuration: Debug Win32 ------ 14>Linking... 14> Creating library .\./select_d.lib and object .\./select_d.exp 14>selectmodule.obj : error LNK2019: unresolved external symbol _WSAGetLastError at 0 referenced in function _select_select 14>selectmodule.obj : error LNK2019: unresolved external symbol _select at 20 referenced in function _select_select 14>selectmodule.obj : error LNK2019: unresolved external symbol ___WSAFDIsSet at 8 referenced in function _set2list 14>./select_d.pyd : fatal error LNK1120: 3 unresolved externals 14>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\select\BuildLog.htm" 14>select - 4 error(s), 0 warning(s) 13>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\unicodedata\BuildLog.htm" 13>unicodedata - 0 error(s), 0 warning(s) 15>------ Build started: Project: pythonw, Configuration: Debug Win32 ------ 15>Linking... 15>Embedding manifest... 15>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-debug\pythonw\BuildLog.htm" 15>pythonw - 0 error(s), 0 warning(s) ========== Build: 7 succeeded, 8 failed, 0 up-to-date, 0 skipped ========== f rom schreef: > ----- Forwarded Message ---- > From: Josiah Carlson > To: f rom ; wxpython-users at lists.wxwidgets.org > Sent: Monday, December 4, 2006 10:03:28 PM > Subject: Re: [wxPython-users] 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA at 24 referenced in function _make_buildinfo2 > > > Ask on python-list at python.org . > > - Josiah > > f rom wrote: > > I am trying to debug a segfault which I can not pin down with a simple pytjon script. > > For this I have downloaded the free Microsoft visual express c++. > > However I am having problems building python2.5. > > Anyone have experience with this ? > > > > 1>------ Rebuild All started: Project: make_buildinfo, Configuration: Debug Win32 ------ > > 1>Deleting intermediate and output files for project 'make_buildinfo', configuration 'Debug|Win32' > > 1>Compiling... > > 1>make_buildinfo.c > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(43) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(47) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(63) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(66) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(69) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(72) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(73) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(81) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(83) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(84) : warning C4996: 'strcat' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\string.h(78) : see declaration of 'strcat' > > 1> Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > 1>d:\python-2.5\pcbuild8\make_buildinfo.c(88) : warning C4996: 'unlink' was declared deprecated > > 1> c:\program files\microsoft visual studio 8\vc\include\stdio.h(290) : see declaration of 'unlink' > > 1> Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _unlink. See online help for details.' > > 1>Compiling manifest to resources... > > 1>Linking... > > 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA at 24 referenced in function _make_buildinfo2 > > 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegOpenKeyA at 12 referenced in function _make_buildinfo2 > > 1>./make_buildinfo.exe : fatal error LNK1120: 2 unresolved externals > > 1>Build log was saved at "file://d:\Python-2.5\PCbuild8\x86-temp-release\make_buildinfo\BuildLog.htm" > > 1>make_buildinfo - 3 error(s), 11 warning(s) > > ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== > > > > > > > > > > > > > > ____________________________________________________________________________________ > > Want to start your own business? > > Learn how on Yahoo! Small Business. > > http://smallbusiness.yahoo.com/r-index > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org > > For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org > > > > > > > > ____________________________________________________________________________________ > Cheap talk? > Check out Yahoo! Messenger's low PC-to-Phone call rates. > http://voice.yahoo.com From basti.wiesner at gmx.net Thu Dec 21 07:17:33 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Thu, 21 Dec 2006 13:17:33 +0100 Subject: What am I supposed to do with an egg?! References: Message-ID: Morpheus wrote > So, what am I supposed to do here now? That's easy: Breed it... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From missive at frontiernet.net Tue Dec 26 18:11:02 2006 From: missive at frontiernet.net (Lee Harr) Date: Tue, 26 Dec 2006 23:11:02 GMT Subject: Persistent variables in python References: <1167171213.220928.131330@f1g2000cwa.googlegroups.com> Message-ID: > Found out a quite fun way to store persistent variables in functions in > python. > > Is this concidered bad coding practice since I guess persistent > variables in functions are not meant to be? I am using is in one of my recent projects. I was thinking of it sort of like "static" variables in C. I use a decorator to create the variables ... def static(**kw): ''' Used to create a decorator function that will add an attribute to a function and initialize it. >>> @static(foo=5) ... def bar(): ... print bar.foo ... bar.foo += 1 ... >>> bar() 5 >>> bar() 6 ''' def decorator(f): f.__dict__.update(kw) return f return decorator From fuzzyman at gmail.com Sat Dec 23 15:38:30 2006 From: fuzzyman at gmail.com (Fuzzyman) Date: 23 Dec 2006 12:38:30 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1166906310.452197.185700@48g2000cwx.googlegroups.com> Lars Rune N?stdal wrote: > On Fri, 08 Dec 2006 03:07:09 -0800, Mark Tarver wrote: > > > How do you compare Python to Lisp? What specific advantages do you > > think that one has over the other? > > > > Note I'm not a Python person and I have no axes to grind here. This is > > just a question for my general education. > > > > Mark > > Kill this frakkin thread; Lisp rules -- while Python is boring (but better > than many other alternatives). E.O.F. > Perhaps only with the addendum that although 'Lisp roolz', no-one uses for anything of relevance anymore and it is continuing it's geriatric decline into obscurity. ;-) Python is dull, except to the ever increasing group of programmers who use it for practical purposes. Hmm... a fitting. EOF. Fuzzyman http://www.voidspace.org.uk/python/articles.shtml > -- > Lars Rune N?stdal > http://nostdal.org/ From atkinw at rpi.edu Sun Dec 10 01:59:57 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 01:59:57 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: Ken Tilton writes: > Steven D'Aprano wrote: >> If that's the best example of what macros can be used for, frankly I'm >> unimpressed. > > We're shocked. We are. (Counting lines? Come on.) From Spiercyanna at aol.com Thu Dec 7 10:28:36 2006 From: Spiercyanna at aol.com (Spiercyanna at aol.com) Date: Thu, 7 Dec 2006 10:28:36 EST Subject: Jerry Brewster's new email address Message-ID: hey this is arnie franks you got any tractors for sale -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sun Dec 3 13:05:17 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 3 Dec 2006 10:05:17 -0800 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165169117.866499.181520@73g2000cwn.googlegroups.com> Jon Harrop wrote: > I had thought that all of the array operations were allocating new arrays at > first but it seems that at least assignment to a slice does not. > > Does: > > a[:] = b[:] + c[:] > > allocate a temporary for b[:] + c[:]? Yep. [snip] > Not only is that shorter than the Python, it is much faster: > > 0.56s C++ (direct arrays) > 0.61s F# (direct arrays) > 0.62s OCaml (direct arrays) > 1.38s OCaml (slices) > 2.38s Python (slices) > 10s Mathematica 5.1 [snip] > 1.57s Python (in-place) So, optimized Python is roughly the same speed as naive Ocaml optimized Ocaml is roughly the same speed as C++ > >> > It seems to > >> > me a big help is the ability to fold multiple array operations into a > >> > single loop, which is optimization a dynamically-typed language like > >> > Python can't easily make. (It'd require are really smart JIT compiler > >> > or some concessions in dynamicity.) > >> > >> Writing a JIT to compile this kind of stuff is easy. > > > > Eh, getting a JIT to do the optimization I spoke of in Python is not > > easy. It would be relatively easy in a statically typed language. In > > Python, it'd be tantamount to rewriting a dynamically reconfigurable > > version of numpy--you'd have to duplicate numpy's complex > > type-dispatching rules. > > There aren't any complicated types in the above code. In fact, there are > only two types: float and float array. You're vastly underestimating the complexity of numpy objects. They have an awful lot going on under the covers to make it look simple on the surface. There's all kinds of type-checking and type-conversions. A JIT that folds loops together would have to have knowledge of that process, and it's a lot of knowledge to have. That is not easy. > Type checking is easy in this case, > compilation to C is also easy, then you just dispatch to the compiled C > code when the types are ok. You would want to write your Python code like C > code but that is shorter in this case. You may also want to flag code for > compilation manually in order to avoid the overhead of compiling code > unnecessarily. > > >> My point is that this is fundamentally bad code, > > > > Whoa, there. I realize that for people who prefer functional > > programming, with their recursively reductionist way of thinking, it > > might seem as if leaving any sort of reducibility in final result is > > "fundamentally bad", but that's a pretty strong thing to say. > > I was referring to the slicing specifically, nothing to do with functional > programming. My F# and OCaml code are now basically identical to the C++ > code. It is pretty strong thing to say that anything is fundamentally bad just because it's not fast as something else. Fundamental badness ought to run deeper than some superficial, linear measure. > >> so why bother trying to write a Python JIT? Why > >> not just write in a better language for this task? Optimising within a > >> fundamentally slow language seems silly to me. > > > > Because, for most people, language choice is not a greedy maximizing of > > a single issue. Nobody who uses numpy is under the impression that it > > can match a statically-typed language that is compiled to machine code > > in peak performance. (Matlab is fair game, of course.) But speed is > > not the only important thing. > > In this specific context (discrete wavelet transform benchmark), I'd have > said that speed was the most important thing after correctness. So let's say I'm planning to write this complicated graphical program, that does all sorts of stuff. I/O, networking, database, etc. It's a medium throughput program, and a slow language like Python is sufficient to run it, except for this one tiny part where I have to transform of wave data. Now, I was going to write the program in Python, and use the very convenient numpy to do the transformation part. No problem, numpy will be fast enough for my needs. But wait! It's silly try to optimize code in a fundamentally slow language! It's vanity to even try! I guess for the sake of getting this little D4 transform to double in speed I'll scrap Python and write the whole thing in OCaml. (Or I can begrudingly admit that it's not really silly to try to optimize a slow language.) [snip] > This is really great work but I can't help but wonder why the authors chose > to use Python when other languages seem better suited. I'd like to work on > raising people's awareness of these alternatives, and probably create some > useful tools in the process. So I'm keen to learn what Python programmers > would want/expect from F# and OCaml. > > What would it take to make you convert? Them not being functional would be a good start.... Carl Banks From Herr.Karthik at gmail.com Sat Dec 30 08:42:45 2006 From: Herr.Karthik at gmail.com (Tilde_karthik) Date: 30 Dec 2006 05:42:45 -0800 Subject: Installing python.org distro over ActivePython? In-Reply-To: References: Message-ID: <1167486164.990764.314730@48g2000cwx.googlegroups.com> I tried too and works sweet. only dont try to run it in pythomWin Karthik Tom Plunket wrote: > Hey gang- > > I just ran into the fabled "Secure Sockets not enabled in ActivePython," > and the ActiveState FAQ says I should just grab _ssl.pyd from > "somewhere", offering up the python.org distribution as a possible > source. > > I'm on 2.4 at this time, and python.org has what appears to be a > considerably newer release than ActiveState in the first place, so I was > wondering if I could just install this entire package right over the > ActiveState installation, and everything would Just Work? > > thanks, > -tom! > > -- From jason.meiers at gmail.com Tue Dec 5 00:37:13 2006 From: jason.meiers at gmail.com (jason.meiers at gmail.com) Date: 4 Dec 2006 21:37:13 -0800 Subject: No module named _db2 Message-ID: <1165297033.417956.190750@j44g2000cwa.googlegroups.com> For some reason the _db2 module cannot be imported. Have you had this issue before? [root at server1test]# python test_basic.py Traceback (most recent call last): File "test_basic.py", line 2, in ? import DB2 File "/home/itmuser/scripts/lib/PyDB2-1.1.0/test/DB2.py", line 10, in ? import _db2 ImportError: No module named _db2 From george.sakkis at gmail.com Thu Dec 7 16:34:40 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 7 Dec 2006 13:34:40 -0800 Subject: A Call to Arms for Python Advocacy References: Message-ID: <1165527280.347369.117540@80g2000cwy.googlegroups.com> Jeff Rush wrote: > These works are to be formed into advocacy kits for various audiences. So far > we have the following ideas for kits: > > - College Student's Python Advocacy Kit > - IT Department Python Advocacy Kit > - University Educator's Python Advocacy Kit > - K-12 Educator's Python Advocacy Kit > - Research Lab Python Advocacy Kit > > The table of contents for the various kits can be found at: > > http://wiki.python.org/moin/Advocacy#AdvocacyKits > > Did we miss your kit? And what would you include in any of these? [coming_from[lang].advocacy_kit for lang in ('C/C++', 'Java', 'Perl', 'PHP', 'Visual Basic')] (the six more popular than Python according to http://www.tiobe.com/tpci.htm) George From blah at blahdeblah Fri Dec 1 15:02:43 2006 From: blah at blahdeblah (bill ramsay) Date: Sat, 02 Dec 2006 09:02:43 +1300 Subject: detecting that a SQL db is running References: <783tm2dmb6brnptr91hsfnc1t38u1utbi8@4ax.com> <1164924313.495569.311330@80g2000cwy.googlegroups.com> Message-ID: <8g21n2tms1otvenfnurpia7pochq29458h@4ax.com> Dennis none of this matters, all i am trying to find out is whether or not the local MSDE is actually running. I put all the other bits in there to try and put some background to it. kind regards bill From ralf at schoenian-online.de Mon Dec 11 23:11:07 2006 From: ralf at schoenian-online.de (=?UTF-8?B?UmFsZiBTY2jDtm5pYW4=?=) Date: Tue, 12 Dec 2006 05:11:07 +0100 Subject: problem while going through a tutorial In-Reply-To: References: Message-ID: <457e2bd1@news.arcor-ip.de> Simon Schuster schrieb: [..] >>>> x = "fljshfjh" >>>> x > 'fljshfjh' >>>> count(x, 'h') > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'count' is not defined > > I'm not sure what changed, because it used to work. anyhow thanks a lot! You forgot to import the string module: from string import * Regards, Ralf Schoenian From aboudouvas at panafonet.gr Fri Dec 15 05:47:02 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 15 Dec 2006 02:47:02 -0800 Subject: Property error In-Reply-To: References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> Message-ID: <1166179622.872556.312810@n67g2000cwd.googlegroups.com> > What version of Python? Most recent versions don't need the Hi, thanks for the help! I am using 2.5 version and i think i like more the @property decorator instead of the property(...) syntax. Is the code changing much using @property ?? Thanks again! From python.list at tim.thechases.com Fri Dec 15 11:52:40 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 15 Dec 2006 10:52:40 -0600 Subject: re pattern for matching JS/CSS In-Reply-To: <1166201152.916044.14930@t46g2000cwa.googlegroups.com> References: <1166194075.458179.275520@79g2000cws.googlegroups.com> <1166201152.916044.14930@t46g2000cwa.googlegroups.com> Message-ID: <4582D2D8.5080007@tim.thechases.com> >> I've tried >> '' >> but that didn't work properly. I'm fairly basic in my knowledge of >> Python, so I'm still trying to learn re. >> What pattern would work? > > I use re.compile("",re.DOTALL) > for scripts. I strip this out first since my tag stripping re will > strip out script tags as well hope this was of help. This won't catch various alterations of < script > doEvil() < / script > which is valid html/xhtml. For less valid html, but still attemptable, one might find something like haht>doEvil() which, if you nuke your pattern, leaves the valid but unwanted I'd propose that it's better to use something such as BeautifulSoup that actually parses the HTML, and then skim through it whitelisting the tags you plan to allow, and skipping the emission of any tags that don't make the whitelist. -tkc From Carl.Wolff at imtech.nl Tue Dec 5 10:04:31 2006 From: Carl.Wolff at imtech.nl (Carl.Wolff at imtech.nl) Date: Tue, 5 Dec 2006 16:04:31 +0100 Subject: Does this always go right Message-ID: Hello question about copy vs deepcopy used in multithreaded context: suppose the following program below: the original dictionary is modified after the thread is started, the thread works on a copied and deepcopied version of the original dictionary. Is the dictionary named "originalcopy" isolated from changes in original in multithreaded context? The program reports no errors but I want to be really sure about this Thanks Carl. original = {} originalcopy = {} originaldeepcopy = {} class checker(threading.Thread): def __init__(self): threading.Thread.__init__(self) pass def run(self): while True: for i in originaldeepcopy: if originalcopy[i] == originaldeepcopy[i]: pass else: print "error", originalcopy[i], "Not equal to", originaldeepcopy[i] i = 0 while i<1000: original[i] = i i = i + 1 originalcopy = copy.copy(original) originaldeepcopy = copy.deepcopy(original) test = checker() test.start() time.sleep(0.5) while True: i = 0 while i<1000: original[i] = i*2 i = i + 1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Sat Dec 2 15:56:23 2006 From: sjmachin at lexicon.net (John Machin) Date: 2 Dec 2006 12:56:23 -0800 Subject: global name 'self' is not defined In-Reply-To: <1165087301.512807.289200@16g2000cwy.googlegroups.com> References: <1165084948.125632.121260@79g2000cws.googlegroups.com> <1165087301.512807.289200@16g2000cwy.googlegroups.com> Message-ID: <1165092983.472428.219040@j72g2000cwa.googlegroups.com> Evan wrote: > In answer to the 2 replies, I had no references anywhere to 'self'. In > order to post my code I rewrote 2 scripts containing just the relevant > parts of the problem; these work. However, they are identical to my > original code. This is (putting it mildly) somewhat difficult to believe. If true, it would indicate a rather severe bug in Python. Identical as determined how? When you ran your original code and it gave an error, Python would have told you where the error occurred, on which line of which file, as in the following example: C:\junk>copy con noself.py def foo(): return self ^Z 1 file(s) copied. C:\junk>\python25\python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. | >>> import noself | >>> noself.foo() Traceback (most recent call last): File "", line 1, in File "noself.py", line 2, in foo <<<=== location of error-causing line return self <<<=== contents of error-causing line NameError: global name 'self' is not defined And you could have told us that information. No, should. Adding to what others have already said: When asking a question about an error message: (a) Provide code (abbreviated if necessary) that causes the error. Don't retype it; copy/paste the code that you actually ran. (b) Show the full traceback and error message. Again, use copy/paste. > So I have deleted the 'old' script2 and renamed the new > one, and no problem. I don't know why it worked with one and not the > other when they are identical, but I have what I want now. No problem? Sorry, it just transformed itself. Here is a precise definition of the transformed problem: "I don't know why it worked with one and not the other". And what you want now doesn't include enlightenment? Thrashing madly at problems with a sledgehammer may sometimes (but not always) make them appear to go away faster than a methodical problem-solving approach would take, but it's rather a short-tem "gain". HTH, John From fuzzyman at gmail.com Tue Dec 5 19:02:36 2006 From: fuzzyman at gmail.com (Fuzzyman) Date: 5 Dec 2006 16:02:36 -0800 Subject: newb: Join two string variables In-Reply-To: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> References: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> Message-ID: <1165363356.609151.74810@j72g2000cwa.googlegroups.com> johnny wrote: > How do I join two string variables? > I want to do: download_dir + filename. That should do it. :-) You can concatenate strings using the plus operator. For large number of strings it is very inefficient. (Particularly in versions of Python pre 2.4 or in IronPython.) For these situations it is better to collect the strings in a list and then join them using : ''.join(list_of_strings) But for just two strings, plus is fine. Fuzzyman http://www.voidspace.org.uk/python/index.shtml > download_dir=r'c:/download/' > filename =r'log.txt' > > I want to get something like this: > c:/download/log.txt From XX.XmcX at XX.XmclaveauX.com Wed Dec 6 13:15:40 2006 From: XX.XmcX at XX.XmclaveauX.com (MC) Date: Wed, 06 Dec 2006 19:15:40 +0100 Subject: Python Plugin for Web Browser References: <1165389943.093365.20590@80g2000cwy.googlegroups.com> <1165391969.824391.174140@l12g2000cwl.googlegroups.com> <1165416520.077655.58540@16g2000cwy.googlegroups.com> Message-ID: Bonsoir ! > As-tu des connaissances en C++ ? avec Visual C++ ? Ben, non, je ne pratique pas ces machins. Par contre, je pense qu'il existe une autre d?marche, qui consiste ? g?n?rer, ? la vol?e, en Python, des sortes d'applets java/javascript. Avantages : rien ? installer ; milti-navigateurs Inconv?nient : ?a se programme c?t? serveur. Voir : Pyjamas (http://pyjamas.pyworks.org/FR/overview/) -- @-salutations Michel Claveau From duncan.booth at invalid.invalid Sat Dec 23 07:19:48 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Dec 2006 12:19:48 GMT Subject: Multi-line docstrings References: Message-ID: Lawrence D'Oliveiro wrote: > The Python docs recommend the use of triple-quoted string literals for > docstrings, e.g. > > def Meet(Alice, Bob) : > """arranges a meeting between Alice and Bob. > Returns a reference to the meeting booking object.""" > ... > #end Meet > However, these tend to get messed up by indentation whitespace, which > gets spuriously included as part of the string. Not spuriously included: included by design, but sometimes annoying. If you are just printing __doc__ in interactive mode then live with the extra whitespace. If you are printing out lots of docstrings as part of some documentation tool then use textwrap.dedent to remove the common leading spaces. > > Another possibility is to use implicit concatenation of string > literals, e.g. > > This includes no spurious whitespace, or even any newlines; if you > want these, you must put them explicitly in the string: ... which is why the triple-quoted format is recommended. BTW, you missed this way of doing it which ensures that all lines, even the first one have the same indentation (and therefore textwrap.dedent will strip it quite nicely): def Meet(Alice, Bob) : '''\ arranges a meeting between Alice and Bob. Returns a reference to the meeting booking object. ''' and if you want to do string concatenation you can always get rid of those pesky backslashes: def Meet(Alice, Bob) : ("arranges a meeting between Alice and Bob.\n" "Returns a reference to the meeting booking object.") From ptmcg at austin.rr._bogus_.com Mon Dec 25 19:24:11 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 25 Dec 2006 18:24:11 -0600 Subject: some OT: how to solve this kind of problem in our program? References: <458e4426$0$5286$4c368faf@roadrunner.com> <1166958490.785728.52430@h40g2000cwb.googlegroups.com> <1166974469.681026.101070@42g2000cwt.googlegroups.com> Message-ID: <45906bab$0$27094$4c368faf@roadrunner.com> wrote in message news:1166974469.681026.101070 at 42g2000cwt.googlegroups.com... > Using Psyco this version is much faster, you can test it on your PC > compared to the other one (the whole running time, Psyco compilation > too): > Psyco is unable to speed up generator functions, so you have to return > true lists. > Giving the func to the permutation function, you can avoid lot of list > copying and unpacking. > > > try: > import psyco > psyco.full() > except ImportError: > pass > > d0, d1 = 1, 2 > > > def func(p): > a0,a1,a2,b0,b1,b2,c0,c1,c2 = p > # do application evaluation here > b1b2 = 10*b1+b2 > a1a2 = 10*a1+a2 > c1c2 = 10*c1+c2 > if d1*a0*b1b2*c1c2 + d1*b0*a1a2*c1c2 + d1*c0*a1a2*b1b2 \ > == d0*a1a2*b1b2*c1c2: > return sorted( [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] ) > else: > return None > > > def accepted_permutations(alist, func): > # func must return None for the unacceptable results > # Algoritm from Phillip Paul Fuchs, modified > result = [] > items = alist[:] > n = len(alist) > p = range(n+1) > i = 1 > r = func(alist) > if r is not None: result.append(r) > while i < n: > p[i] -= 1 > if i & 1: > j = p[i] > else: > j = 0 > alist[j], alist[i] = alist[i], alist[j] > r = func(alist) > if r is not None: result.append(r) > i = 1 > while p[i] == 0: > p[i] = i > i += 1 > return result > > > def main(): > result = [] > for aresult in accepted_permutations(range(1, 10), func): > if aresult not in result: > result.append(aresult) > [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]] = aresult > print ' %0d %0d %0d %0d' % (a0, b0, c0, d0) > print '--- + --- + --- = ---' > print ' %0d%0d %0d%0d %0d%0d > %0d'%(a1,a2,b1,b2,c1,c2,d1) > print > > main() > > Bye, > bearophile > Nice and neat. I guess what appeals to me is that this is essentially a brute force approach. Instead of a goal-seeking constraint solver, this just brute force tries every possible permutation. Of course, this breaks down quickly when the size of the input list grows large, but the OP was trying to work with permutations of the digits 1-9 using an unwieldy nesting of for loops and set manipulations. Using permutations is no more or less smart of an algorithm than in the original post, it just cleans up the for loops and the set arithmetic. For example, for all the complexity in writing Sudoku solvers, there are fewer than 3.3 million possible permutations of 9 rows of the digits 1-9, and far fewer permutations that match the additional column and box constraints. Why not just compute the set of valid solutions, and compare an input mask with these? -- Paul From address.good.until.2006.dec.22 at justmail.de Thu Dec 14 09:27:51 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=) Date: Thu, 14 Dec 2006 15:27:51 +0100 Subject: merits of Lisp vs Python In-Reply-To: <458157fd$0$2119$426a34cc@news.free.fr> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <457f1a42$0$8414$426a74cc@news.free.fr> <458157fd$0$2119$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers schrieb: > Andr? Thieme a ?crit : >> Bruno Desthuilliers schrieb: >> > (snip) >>> Both are highly dynamic. Neither are declarative. >> >> >> Well, Lisp does support some declarative features in the ansi standard. > > If you go that way, there are declarative stuff in Python too... But > neither Lisp nor Python are close to, say, SQL. While this is absolutely right one can make Lisp coming much closer, by going into the direction of, say, Prolog: http://bc.tech.coop/blog/040919.html Andr? -- From liujzus at gmail.com Tue Dec 5 12:42:46 2006 From: liujzus at gmail.com (Jianzhong Liu) Date: Tue, 5 Dec 2006 12:42:46 -0500 Subject: Linear regression in NumPy Message-ID: <000401c71894$c8dcf9e0$28b2ea40@crux> Hello, Guys, I have a question about the linear_least_squares in Numpy. My linear_least_squares cannot give me the results. I use Numpy1.0. The newest version. So I checked online and get your guys some examples. I did like this. [john at crux 77] ~ >> py Python 2.4.3 (#1, May 18 2006, 07:40:45) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> from Numeric import * >>> from LinearAlgebra import linear_least_squares >>> from Matrix import * >>> y = Matrix([[1], [2], [4]]) >>> x = Matrix([[1, 1], [1, 2], [1, 3]]) >>> print y Matrix([[1], [2], [4]]) >>> x Matrix([[1, 1], [1, 2], [1, 3]]) >>> print linear_least_squares(x, y) Here my Numpy stops. and never give me a result. THis is the problem of Numpy or sth wrong. Can you guys give me a LinearAlgebra.py so that I can have a try? Thanks, John From python at hope.cz Tue Dec 12 07:11:34 2006 From: python at hope.cz (Lad) Date: 12 Dec 2006 04:11:34 -0800 Subject: How to upload a file Message-ID: <1165925494.589658.148370@80g2000cwy.googlegroups.com> Users needs to upload big files upto 100MB.So I think that FTP protocol would be a solution, but how can I allow users to select the right file ,on their local disk, via a file dialog ? Thank you for your ideas L. From cfriedalek at gmail.com Fri Dec 15 00:37:03 2006 From: cfriedalek at gmail.com (cfriedalek at gmail.com) Date: 14 Dec 2006 21:37:03 -0800 Subject: How does python handle VBS "Nothing" keyword Message-ID: <1166161023.400594.145350@16g2000cwy.googlegroups.com> I'm writing a python script using win32com to call a 3rd party program via its VBS based API. In VBS a query to get some plot data goes like this: Plot.QueryBegin datacode, Nothing What is this in python? Plot.QueryBegin(datacode, None) does not work. I get a type mismatch error as follows: com_error: (-2147352571, 'Type mismatch.', None, 2) I've tried "", False, 0 as alternative to None but these don't work either. So what is mapped to "Nothing"? tia From sjmachin at lexicon.net Tue Dec 5 04:00:25 2006 From: sjmachin at lexicon.net (John Machin) Date: 5 Dec 2006 01:00:25 -0800 Subject: Printing unix Line endings from Windows. In-Reply-To: <1165307391.447055.210020@n67g2000cwd.googlegroups.com> References: <1165247935.679325.242850@80g2000cwy.googlegroups.com> <1165307391.447055.210020@n67g2000cwd.googlegroups.com> Message-ID: <1165309224.097576.66600@79g2000cws.googlegroups.com> Ant wrote: > Larry Bates wrote: > > > Ant wrote: > ... > > > Is there any way of doing this without having to post-process the file > > > in binary mode (a-la the crlf.py script) > ... > > You can write to a new file and create your own line endings. > > When done, delete the original file and rename the output file. > > How can I create my own line endings? I've tried setting os.linesep = > "\n", (and to \x0a). I've tried things like: > > print "xxx yyy \n", > print "xxx uuu \x0a", > filehandle.write("xxx \n") > filehandle.write("xxx \x0a") > > and all of these give me a nice windows-style crlf! > > Surely there must be a way to do this ... and there is: open your output file in binary mode; then it won't convert every \n to \r\n. writing: | >>> f = open('unixlf.txt', 'wb') | >>> f.write('foo\n') | >>> f.write('bar\n') | >>> f.close() checking: | >>> f = open('unixlf.txt', 'rb') | >>> x = f.read() | >>> x | 'foo\nbar\n' | >>> len(x) | 8 BTW: | >>> '\n' is '\x0a' | True HTH, John From justinbeijing at yahoo.com Sun Dec 3 10:01:42 2006 From: justinbeijing at yahoo.com (JustStand) Date: 3 Dec 2006 07:01:42 -0800 Subject: A mail from Steve Ballmer. See what Microsoft will do and follow. Message-ID: <1165158102.058961.138390@n67g2000cwd.googlegroups.com> "During the last decade, technology has been the catalyst for incredible change. Ten years ago, the PC was just beginning to achieve broad acceptance. Today, the PC, the Internet, and mobile phones and mobile devices have all reached critical mass, creating fantastic opportunities for hundreds of millions of people and hundreds of thousands of companies around the globe. In many ways, it was the launch of Windows 95 and Office 95 eleven years ago that signaled the start of this transformation. ..." For detail, view http://www.homeoftester.com/viewtopic.php?t=281 __________________________________ I have a dream, I hope I can be as strong as Enter key. From grante at visi.com Fri Dec 1 21:08:49 2006 From: grante at visi.com (Grant Edwards) Date: Sat, 02 Dec 2006 02:08:49 -0000 Subject: How do I print a numpy array? References: <12n1b51i11rhv5e@corp.supernews.com> <12n1fm121p9sv93@corp.supernews.com> Message-ID: <12n1o1ho6kbs7a4@corp.supernews.com> On 2006-12-02, Robert Kern wrote: > Grant Edwards wrote: >> On 2006-12-01, Robert Kern wrote: >>> Grant Edwards wrote: >>>> How do you print a numpy array? >> >>> You might want to ask numpy questions on the numpy list: >>> >>> http://www.scipy.org/Mailing_Lists >> >> I tried, but it doesn't seem to be available through gmane.org. > > Yes, it is. > > http://dir.gmane.org/gmane.comp.python.numeric.general I was looking for the "numpy-discussion" mailing list. It didn't occur to me that it was spelled "numeric.general". -- Grant Edwards grante Yow! Th' MIND is the Pizza at Palace of th' SOUL visi.com From duncan.booth at invalid.invalid Wed Dec 6 09:35:14 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Dec 2006 14:35:14 GMT Subject: Windows: get owner and group of a file References: <1165409197.710500.159430@j44g2000cwa.googlegroups.com> Message-ID: "kai rosenthal" wrote: > Hello, > > with ls -l on windows I get > -rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile > > How can I get on windows with a standard python 2.2 (without windows > extensions) the information "500" and "everyone" (owner and group)? > Also I cannot use popen('ls -l'). > > With > import stat > stat_info = os.lstat(myfile) > owner = "%-8s" % stat_info.st_uid > group = "%-8s" % stat_info.st_gid > I get 0 for owner and group. > > Thanks for your hints, Kai > You can get the owner by doing os.popen('dir /q') and parsing the output, but it is a string not a number (which I guess is why stat/lstat can't return a value). Internally the ownber and primary group are stored as security identifier (SID) values: a SID is a variable length structure. Running the CACLS command on a file will give you the full permission settings for that file. They are a lot more complex than the simple rwx settings from unix. e.g. C:\temp>cacls t.py C:\temp\t.py BUILTIN\Administrators:F NT AUTHORITY\SYSTEM:F MYPC\Duncan:F BUILTIN\Users:R C:\temp>cacls . C:\temp BUILTIN\Administrators:F BUILTIN\Administrators:(OI)(CI)(IO)F NT AUTHORITY\SYSTEM:F NT AUTHORITY\SYSTEM:(OI)(CI)(IO)F MYPC\Duncan:F CREATOR OWNER:(OI)(CI)(IO)F BUILTIN\Users:R BUILTIN\Users:(OI)(CI)(IO)(special access:) GENERIC_READ GENERIC_EXECUTE BUILTIN\Users:(CI)(special access:) FILE_APPEND_DATA BUILTIN\Users:(CI)(special access:) FILE_WRITE_DATA So far as I know, to get the primary group for a file you will need to call the win32 function GetSecurityInfo asking for the GROUP_SECURITY_INFORMATION. This will give you an appropriate security descriptor. See http://msdn2.microsoft.com/en-us/library/aa379561.aspx From pc at p-cos.net Sat Dec 9 05:57:01 2006 From: pc at p-cos.net (Pascal Costanza) Date: Sat, 09 Dec 2006 11:57:01 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165653338.110788.62580@n67g2000cwd.googlegroups.com> <7xfybptow1.fsf@ruckus.brouhaha.com> Message-ID: <4tvj3tF15r8b0U2@mid.individual.net> Ken Tilton wrote: > What is up the power continuum from Lisp? 3-Lisp. ;) Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From crazymykl at gmail.com Fri Dec 22 08:35:24 2006 From: crazymykl at gmail.com (MacDonald) Date: 22 Dec 2006 05:35:24 -0800 Subject: Confusion over calling a nested function inside a parent function In-Reply-To: <877iwkdpsb.fsf@pyenos.pyenos.org> References: <877iwkdpsb.fsf@pyenos.pyenos.org> Message-ID: <1166794524.504018.240630@h40g2000cwb.googlegroups.com> Pyenos wrote: > [code] > class WORK: > def getwork(self): > def choosetable(self):pass > choosetable() #TypeError: choosetable() takes exactly 1 > #argument (0 given) > [/code] > > Calling choosetable() at the above location gives me the error > described above. Although choosetable is a memeber of an instance method, it is not one itself. It should not have self as it's first formal parameter. From andrew-newspost at areilly.bpc-users.org Thu Dec 14 05:18:23 2006 From: andrew-newspost at areilly.bpc-users.org (Andrew Reilly) Date: 14 Dec 2006 10:18:23 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> Message-ID: <4ucmndF17nmp0U1@mid.individual.net> On Thu, 14 Dec 2006 04:06:26 -0500, Ken Tilton wrote: > Ken Tilton wrote: >> Andrew Reilly wrote: >>> However, in this particular instance, I'm inclined to wonder why >>> meta-programming is the right answer, rather than just doing all of the >>> interpolation and what-not at run-time, based on a big table of your >>> algebra rules? >> >> I am afraid I do not see what alternative you are suggesting. I >> especially do not see how interpolation is in play. > > [Guessing pending your clarification] "Interpolation" does happen at > runtime. This not about the actually quite rare use of macrology to move > certain calculations to compile time, this is about getting dozens of > transformation-specifc rules written to fit into a larger mechanism (by > having the right arguments and returning the right kinds of results, > with a minimum of boilerplate and a maximum of resiliency in the face of > refactoring. > > The reason I post macro expansions along with examples of the macro > being applied is so that one can see what code would have to be written > if I did not have the defskill macro to "write" them for me. I sugest > one start there, by comparing before and after. Please pardon my woeful grasp of lisp: that's probably why I'm off-beam here. It seemed to me that the bulk of your macro-ified/templated version was taking some text and a "reverse" operation and creating the methods of an object, or generic functions or ?? Each skill seems to have a title, a list of annotations, and a list of hints (and a reverse, which I don't understand). That all looks like data. Couldn't you do that with a table containing those fields, and key it off the defskill argument (or even the title?) at startup? Then you don't have to worry about re-factoring the code: there's only going to be one piece of code, driven by a table. I only mentioned interpolation because it seemed likely that you might want to be mutating these strings to be more specific to what your student was actually doing. I didn't expect that "42" was necessarily the right answer... To back out a bit, here, and get back to the meat of the matter: if one is using Python, then it's because one doesn't much care about performance, and it's reasonable to do expansions, pattern matching and domain specific language creation/use at run-time. After all, that's how the language itself works, mostly. When one finds that one *does* care about performance, that doesn't leave much wriggle room, though... -- Andrew From steve at REMOVE.THIS.cybersource.com.au Sun Dec 10 09:59:15 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 11 Dec 2006 01:59:15 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165737791.744375.190080@l12g2000cwl.googlegroups.com> Message-ID: On Sun, 10 Dec 2006 00:03:11 -0800, Wolfram Fenske wrote: [snip] > Doesn't matter because it only has to be written once. For Common > Lisp it's already part of the language. It would of course be bad to > write a macro if pattern comes up only a few times. But that's not how > macros are used. So you say. I've heard it be said that anytime you do anything more than once, you should abstract it away into a function or macro. Of course, that was the same person who told me that no function should ever be more than five lines of code, so perhaps you might consider him prone to over-stating his case. [snip] >> Saving one line of code, at the expense of having another block of code >> to write or understand -- is that really the best example of what >> macros are used for in practice? You don't really save writing any >> boilerplate code, except for else clause, unless you're claiming that >> "if" and "elif" is boilerplate. > > No, all the "if control_code == SOME_STATUS:" are boilerplate: You still have to include SOME_STATUS in the Lisp example. Calling it boilerplate for Python is unfair. [snip] > The pattern is that one value is compared against several possible > values and depending on which one matches, the appropriate action is > taken. Common Lisp's CASE and ECASE macros and the "switch" statements > of C or Java make this pattern explicit and arguably easier to > recognize. In Python you have to type it out yourself. Yes, Python doesn't have a case/switch statement. It may get one in the future. There are advantages to a case statement, but they aren't overwhelming, and there are costs to implementing it. >> Okay, I'm impressed that ecase can pick up on the four constants being >> tested against, and feed their names (rather than merely their values) >> into an error message. Python has nothing like that, and if you only >> have three or four things to test against, *and* they have names, that >> could be a useful thing to do. And if I've understood correctly, that's >> more a feature of Lisp's symbols than of macros. >> >> But if you're testing against fifty different values, well, is it >> really useful for your error message to list all fifty names? Or do you >> have another macro ecase-with-lots-of-tests? > > Now you're being silly. How am I being silly? Do you not believe that people write case blocks with fifty tests? Okay, how about twenty? Ten? Eight? One of the advantages of Lisp's ecase macro was specifically stated to be that it gave you the error message for free, without the coder having to add new terms to the message as they add new comparisons. Why is it "silly" to question whether that feature is always useful? [snip] > Here's another example. I had to use a database in one of my Python > programs. Everytime I used the database I had write something like > this: [snip] > In Lisp, I could just write a macro "WITH-CONNECTION" that takes the > name of the connection variable and the code for "do something with the > connection" as arguments. Actually, I ended up writing something like > it as a function in Python: > > --8<---------------cut here---------------start------------->8--- > def withConnection(self, fun): > self.lock.acquire() > try: > connection = sqlite.connect(self.dbFile) > connection.row_factory = dictFactory > try: > return fun(connection) > finally: > connection.close() > finally: > self.lock.release() > --8<---------------cut here---------------end--------------->8--- > > What would have been the body in the Lisp macro has to be supplied as > function. It's basically a macro, but it still requires more typing > because you have to define a local function eveytime it is used. Hang on -- why can't you just call the function again? If you're talking about calling withConnection with different functions, then of course you have to define a different function each time. How is that different from the Lisp macro? You still have to write that. And these functions -- shouldn't they be tested? If they were just anonymous blocks, won't they be hard to test? These aren't rhetorical questions. -- Steven. From alainpoint at yahoo.fr Wed Dec 6 12:23:02 2006 From: alainpoint at yahoo.fr (alain) Date: 6 Dec 2006 09:23:02 -0800 Subject: problem with closures Message-ID: <1165425782.031642.71070@f1g2000cwa.googlegroups.com> Hi, I have a problem with closures. I am trying to implement yet another design by contract decorator which would look like the following:
def contract(f):
	def newf(*args, **kw):
		import new
	        precondition =  new.function(f.func_code.co_consts[1],
							f.func_globals,'pre',
							f.func_defaults,
							f.func_closure)
		precondition()
		result=f(*args, **kw)
		postcondition=new.function(f.func_code.co_consts[2],globals())
		postcondition(result)
		return result
	return newf
@contract
def foo(x,y,g=2,z=1):
	def pre():
		assert x>1 and 00
	print 'main'
	return x+y+z*g

print foo(2,5,4,69)

The problem is that i get the following error message on line 7:
TypeError: arg 5 (closure) must be tuple

f.func_closure is indeed empty while
f.func_code.co_consts[1].co_freevars is logically equal to ('x','y').

Thanks for responding

Alain



From afaNOSPAM at neuf.fr  Thu Dec 28 03:09:07 2006
From: afaNOSPAM at neuf.fr (Amaury Forgeot d'Arc)
Date: Thu, 28 Dec 2006 09:09:07 +0100
Subject: I'm having trouble understanding scope of a variable in a subclass
In-Reply-To: <87lkksmtlg.fsf@pyenos.pyenos.org>
References: <87bqloej4x.fsf@pyenos.pyenos.org>
	
	<87lkksmtlg.fsf@pyenos.pyenos.org>
Message-ID: 

Hello,

Pyenos a ?crit :
> Thanks for clarifying the definitions of nested class and
> subclass. However, it did not solve my original problem, and I have
> redefined my question:
> 
> class Class1:
>     class Class2:
>         class Class3:
>             def __init__(self):
>                 self.var="var"
>             class Class4:
>                 print Class1.Class2.Class3.var
> 
> This code gives me the error:
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 2, in Class1
>   File "", line 3, in Class2
>   File "", line 6, in Class3
>   File "", line 7, in Class4
> NameError: name 'Class1' is not defined
> 
> I have tried:
> 
> class Class1:
>         class Class2:
>                 def __init__(self):
>                         var="var"
> print Class1.Class2().var #this works
> 
> And, this worked. It is very strange that nested loop somehow fails to
> work when the innermost class has indentation level greater than two.

This has nothing to do with the indentation level.
But please try to copy exactly the code that you actually executed.

- Your first example fails, but with a different error message
(hint: the "print" statement is not inside a function, so it is executed 
as soon as the interpreter sees it - before it defines the classes.)
And it differs with your second example because the parentheses are 
missing after the name "Class3".

- Your second example does not work as you say. 'var' is a local 
variable and cannot be accessed from the outside. I suppose you actually 
entered something like:
                       self.var="var"
which works indeed.

Again, it is difficult to guess what you are trying to do.

-- 
Amaury


From duncan.booth at invalid.invalid  Wed Dec 20 08:35:26 2006
From: duncan.booth at invalid.invalid (Duncan Booth)
Date: 20 Dec 2006 13:35:26 GMT
Subject: What am I supposed to do with an egg?!
References: 
	<1166562334.101514.36350@t46g2000cwa.googlegroups.com>
	<35aca$45893898$c2d0d373$30325@news.hispeed.ch>
Message-ID: 

"F. GEIGER"  wrote:

> Sorry for not being clear. I did exec easy_install - no errors so far.
> But the egg was still there. I'd expected, that it was converted into
> .py-files somehow, which could be imported by my modules.

The .egg file should have been copied into your site-packages. Python can 
import directly from a .egg file (it is a zip archive containing .py 
files), or you can give easy_install an --always-unzip argument in which 
case it creates a folder with the same name (including the .egg extension) 
in site-packages and unzips the egg there.

Forcing an unzip can be useful if you want to use tools like pydoc which 
don't understand imports from zip files.

If you run python interactively and "print sys.path" then you should see 
any egg files you have installed have been added to the path.


From bjourne at gmail.com  Fri Dec 22 04:49:33 2006
From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=)
Date: Fri, 22 Dec 2006 10:49:33 +0100
Subject: python-hosting.com projects: dead?
In-Reply-To: <4usjloF19hma3U2@mid.individual.net>
References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com>
	<1166499192.027000.151290@j72g2000cwa.googlegroups.com>
	<1166499671.678929.25180@n67g2000cwd.googlegroups.com>
	<4upr9dF197g6cU1@mid.individual.net>
	<1166536534.892544.95850@73g2000cwn.googlegroups.com>
	<4588567a$0$5744$afc38c87@news.optusnet.com.au>
	<4usjloF19hma3U2@mid.individual.net>
Message-ID: <740c3aec0612220149i777ca77er592ed8addb123d28@mail.gmail.com>

On 12/20/06, greg  wrote:
> Richard Jones wrote:
>
> > Actually, to clarify the DEFAULT configuration for Trac is to leave it open
> > to spam.
>
> That sounds like a really bad choice of default.
>
> A bit like the way Windows comes with all the
> "let anyone in the world send me a virus"
> options turned on...

Not really, Trac's default to be open is great for intranet
installations. It is Webfactions own fault that they haven't been able
to shield themself from spam by changing Trac's default to something
more restrictive.

-- 
mvh Bj?rn


From fredrik at pythonware.com  Tue Dec  5 03:16:00 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 05 Dec 2006 09:16:00 +0100
Subject: The del statement
In-Reply-To: 
References: 
Message-ID: 

Marco Aschwanden wrote:

> Where
> 
> list.del(elem)
> map.del(elem)
> 
> would achieve the same result (and I think, this is what happens in the  
> backend).

so what about

     del x

?

> The same discussion was done for the "external" len-function (list.len()  
> vs. len(list)).

for the curious, guido's rationale for len() can be found here:

   http://preview.tinyurl.com/y6vavp





From jm.suresh at gmail.com  Mon Dec  4 00:24:03 2006
From: jm.suresh at gmail.com (jm.suresh@no.spam.gmail.com)
Date: 3 Dec 2006 21:24:03 -0800
Subject: class property methods getting called only once
Message-ID: <1165209843.332368.257980@16g2000cwy.googlegroups.com>

In the following code, I could not find out why the set and get methods
are not called once I set the property.


>>> class Test:
...     def __init__(self):
...         self._color = 12
...     def _setcolor(self,value):
...         print 'setting'
...         self._color = value
...     def _getcolor(self):
...         print 'getting'
...         return self._color
...     color = property(_getcolor,_setcolor)
...
>>> a = Test()
>>> a.color
getting
12
>>> a.color = 22
>>> a.color
22

For some reason the set method is not getting called at all, Anybody
has any clue?

thanks.
--
Suresh



From steve at REMOVE.THIS.cybersource.com.au  Sun Dec 10 00:37:29 2006
From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
Date: Sun, 10 Dec 2006 16:37:29 +1100
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165594621.136524.198600@80g2000cwy.googlegroups.com>
	
	<1165596641.245385.113090@f1g2000cwa.googlegroups.com>
	
	
	<1165704007.887869.192290@16g2000cwy.googlegroups.com>
	
	
Message-ID: 

On Sun, 10 Dec 2006 04:03:25 +0000, Kirk Sluder wrote:

> In article 
> ,
>  Steven D'Aprano  wrote:
> 
>> So it is good that English restricts the expressiveness and power of the
>> syntax and grammar. While we're talking English, we can both understand
>> each other, and in fact people who redefine words and ignore the common
>> meaning of them are often covering weaknesses in their arguments.
> 
> Ohh, can the guy who does discourse analysis for a (meager) living 
> respond to this?
> 
> To start with, English does not restrict the expressiveness and 
> power of the syntax and grammar.

Really? There are no restrictions whatsoever in English syntax and
grammar? None at all? 

So, when I say "sits cat rat" it is not only legal English, but you can
tell which animal is sitting on which?

And if I write "i helped my uncle jack off a horse" with no punctuation or
capitalisation, you can tell which of the two meanings I mean?

Although it isn't strictly syntax or grammar, you also understand
precisely what I mean when I say "the gostak distims the doshes" --
because, as you say, English has no restrictions.

And if I write "You are an idiot", you'll understand that in *my* version
of English "You" means watermelon, "are" means to grow, "an" means best,
and "idiot" means in the summertime, and naturally you won't be offended.

But I'm belaboring the point. Of course English has restrictions in
grammar and syntax -- otherwise one could write something in Latin or
Thai or Mongolian and call it English. There are RULES of grammar and
syntax in English, which means that there are possible expressions which
break those rules -- hence there are expressions which one can't write in
legal English.

That doesn't mean that there are concepts which one can't express in legal
English (although there may be). But we can communicate in English because
when I write "Fred hit Barney with a stick" we both agree that it was Fred
who did the hitting, not Barney or the stick, and Barney was the victim.
If English had no grammatical restrictions, we couldn't agree who hit whom
with what.



-- 
Steven.



From rrenaud at gmail.com  Sun Dec 31 14:09:18 2006
From: rrenaud at gmail.com (rrenaud at gmail.com)
Date: 31 Dec 2006 11:09:18 -0800
Subject: Missing erf()
Message-ID: <1167592158.085766.45140@48g2000cwx.googlegroups.com>

Is there a reason why erf() is not included in the math package?

According to the following URL it looks like it has been standard C
since 1999.

http://www.opengroup.org/onlinepubs/000095399/functions/erf.html



From chris.cavalaria at free.fr  Sat Dec 16 05:59:22 2006
From: chris.cavalaria at free.fr (Christophe Cavalaria)
Date: Sat, 16 Dec 2006 11:59:22 +0100
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
	<7xbqm4d97d.fsf@ruckus.brouhaha.com>
	
	<7xodq4mule.fsf@ruckus.brouhaha.com>
	
	<7xvekcbhm9.fsf@ruckus.brouhaha.com>
Message-ID: <4583d18a$0$29379$426a74cc@news.free.fr>

Paul Rubin wrote:

> Kirk  Sluder  writes:
>> Personally, I've always preferred use the imperative to describe
>> basic math rather than the passive. This would seem to map better to
>> RPN than infix.
> 
> For writing down complicated, nested expressions too?  That's very
> unusual.  E.g.
> 
>   n! = (n/e)**n * sqrt(2*pi*n) * (1 + (1/12n)) * ...
> 
> vs. the same thing in Lisp notation, and that's not even so complicated.

Yes, infix is better ( and note that Math uses primarly infix notation for
common operators ) because you have a clear view of the evaluation tree
that way. With prefix or postfix notation, you need to parse the full
expression to find what goes to the first parameter of that +, and what
goes to the second parameter.

I would say that prefix/postfix is somewhat easier to write, but that infix
is far far far easier to read.



From scott.daniels at acm.org  Sat Dec 30 12:47:20 2006
From: scott.daniels at acm.org (Scott David Daniels)
Date: Sat, 30 Dec 2006 09:47:20 -0800
Subject: How to suppress the output of an external module ?
In-Reply-To: <1167251179.543231.157740@79g2000cws.googlegroups.com>
References: 
	<4591b56a$1@nntp0.pdx.net>
	<1167251179.543231.157740@79g2000cws.googlegroups.com>
Message-ID: <45969bc6$1@nntp0.pdx.net>

MRAB wrote:
> Scott David Daniels wrote:
>> fdu.xiaojf at gmail.com wrote:
> In Windows the null device is, strictly speaking, "nul" or "nul:", not
> "nul.txt", but the latter appears to work too.

Although I find the windows design and reasoning to be a mistake, I
believe the use of file names NUL, PRN, and CON (at least) are diverted
to the corresponding device (data sink, printer, console) regardless of
directory and/or extension.  The idea, I believe, was that too many
programs take a name from the user and slap the extension they intend to
use on the end, and even put a directory on the front.  So, the OS
ignores those parts and switches to the chosen device.  I use .txt for
two reasons: to remind me to avoid those names, and to indicate I am
doing straight text output.

--Scott David Daniels
scott.daniels at acm.org


From kw at codebykevin.com  Thu Dec 14 10:31:56 2006
From: kw at codebykevin.com (Kevin Walzer)
Date: Thu, 14 Dec 2006 10:31:56 -0500
Subject: Writing and reading variables to/from flat file
Message-ID: <84548$45816e6c$4275d90a$16465@FUSE.NET>

I want to write some variables (user preferences, specifically) to a
text file and then read the values from that file.

Here is my code to write the data:

verbosemodes= """
    Detailed = "-vv"
    Basic = "-q"
    """

file = open('prefs', 'w')

file.writelines(verbosemodes)

file.close()

And here is my code, in a separate module, to read the file and display
the variable values:

readfile = open('prefs').readlines()

for line in readfile:
	print line

print Basic


Running the second module yields this error:

    Detailed = "-vv"

    Basic = "-q"


Traceback (most recent call last):
  File "readprefs.py", line 6, in 
    print Basic
NameError: name 'Basic' is not defined

Clearly the data is getting read (the lines are being printed), but the
variable itself ("Basic") is not being initialized properly. I'm not
sure what I'm doing wrong here--can anyone point me in the right
direction?  Thanks.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


From jmcmonagle at velseis.com.au  Thu Dec 14 17:21:33 2006
From: jmcmonagle at velseis.com.au (John McMonagle)
Date: Fri, 15 Dec 2006 08:21:33 +1000
Subject: Need Simple Way To Determine If File Is Executable
In-Reply-To: 
References: 
Message-ID: <4581CE6D.1040302@velseis.com.au>

Tim Daneliuk wrote:
> I have a program wherein I want one behavior when a file is set as executable
> and a different behavior if it is not.  Is there a simple way to determine
> whether a given named file is executable that does not resort to all the
> lowlevel ugliness of os.stat() AND that is portable across Win32 and *nix?
> 

os.access(pathToFile, os.X_OK)

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



From edd at nunswithguns.net  Sun Dec 10 12:01:05 2006
From: edd at nunswithguns.net (edd at nunswithguns.net)
Date: 10 Dec 2006 09:01:05 -0800
Subject: problem using lambdas for deferred callbacks
In-Reply-To: <1165764662.462927.147010@79g2000cws.googlegroups.com>
References: <1165764662.462927.147010@79g2000cws.googlegroups.com>
Message-ID: <1165770065.545597.112080@f1g2000cwa.googlegroups.com>

Many thanks to you both!

Edd



From atkinw at rpi.edu  Sat Dec  9 15:00:56 2006
From: atkinw at rpi.edu (Bill Atkins)
Date: Sat, 09 Dec 2006 15:00:56 -0500
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06>
	<1165649882.563957.87770@n67g2000cwd.googlegroups.com>
	
	<457abf83.18014323@news.readfreenews.net>
	
Message-ID: 

Steven D'Aprano  writes:

> With Lisp macros, even that isn't guaranteed. Now, if Lispers would say
> "Oh yes, macros give you great power, and with great power comes great
> responsibility. Be careful." then, no doubt, we'd take you guys more
> seriously. But we don't hear that -- we hear Lispers going on and on about

And, of course, we do say that.  Nobody wants people running around
writing incomprehensible macros.  How does that help anyone?
Fortunately, it's not a problem in practice, because most macros map
quite straightforwardly to Lisp constructs and almost no one has the
time or the intelligence to write the mini-languages that seem to be
terrifying you so much.

> how great it is that they can easily redefine every corner of the
> language. Do you blame people for *believing them* and imagining that
> reading Lisp code is like following some ghostly will-o-the-wisp across a
> swamp, where nothing is what it seems and the landscape is forever
> shifting?

"every corner of the language"?  Please.  Why are you so post-happy
when it's quite obvious that you don't know enough about Lisp to
attack it?

Most programmers do not write macros that are incredibly difficult to
understand.  Beginners might, but beginners might also write
incomprehensible code in Java or Python.  As you learn Lisp, you learn
to keep your macros tied to the underlying Lisp.  You learn to make
the expansions into function or method defintions, instead of
reinventing the wheel.  You leverage what Lisp offers, instead of
redefining it.

The only times you are really going to find completely alien semantics
are in textbooks (like Prolog in Lisp), in very ambitious and large
projects where the new semantics are the only reason you'd use the
code in the first place (like Franz's AllegroProlog or Marco
Baringer's CPS transformer), or in code written by beginners.  Please
stop spreading FUD about this.  In real life, macros make coding more
pleasant and make your code more maintainable.  They are something to
embrace, not something to fear.

To provide a more solid example, Peter Seibel's book _Practical Common
Lisp_ (full text at http://www.gigamonkeys.com/book) provides a set of
classes for parsing binary files.  Some user code provided in the
book:

(define-binary-class id3v2.3-tag (id3-tag)
  ((extended-header-size (optional :type 'u4 :if (extended-p flags)))
   (extra-flags          (optional :type 'u2 :if (extended-p flags)))
   (padding-size         (optional :type 'u4 :if (extended-p flags)))
   (crc                  (optional :type 'u4 :if (crc-p flags extra-flags)))
   (frames               (id3-frames :tag-size size :frame-type 'id3v2.3-frame))))

This code very closely mirrors the standard DEFCLASS in Common Lisp,
so a maintainer knows right away what to expect.  The macro expands
into DEFCLASS and DEFMETHOD forms.  There's nothing mysterious going
on here; the macro is just a friendlier syntax for expressing an idea.
What I get from this are methods that read binary data into objects of
the class that I've just defined (*).  That's all - methods and a
class.  There is no mind-bending going on at all here.  It's true of
course that I have to understand how the macro works.  But without it,
I'd have to write and/or read through a lot of similar-looking code
for handling binary data.  Which would you prefer?

Without a macro like this, the code required would be the definition
of boilerplate.  Instead of specifying declaratively the order and
type of fields in the binary file, I would write code to read each
field from the file and then store the result in an object.  I'd also
have to take into account fields that are optional.  This is ugly and
boring code.  Did I mention that DEFINE-BINARY-CLASS also defines
methods to save these objects back to binary files?  Because it does.

So why not write this code once and then take advantage of it in the
future to get more expressive, less boring programs?



*  If you don't believe me, here is the expansion of the code I cited above:

http://paste.lisp.org/display/31799

Just methods and a class.


From tim.peters at gmail.com  Wed Dec 13 01:31:07 2006
From: tim.peters at gmail.com (Tim Peters)
Date: Wed, 13 Dec 2006 01:31:07 -0500
Subject: not a big deal or anything, but, curiously:
In-Reply-To: <5c1d2d910612122214w22220f3fk6c5acfd1cfca7d6b@mail.gmail.com>
References: <5c1d2d910612122214w22220f3fk6c5acfd1cfca7d6b@mail.gmail.com>
Message-ID: <1f7befae0612122231r53e056a2v64be108c83f9c098@mail.gmail.com>

[Simon Schuster]
> following this tutorial,

Which tutorial?

> I copied and pasted:
>
> from string import *
>
> cds = """atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaaa
> tttcgggtgccgacctgacgcgcccgttaagcgataatcagtttgaacagctttaccatgcggtg
> ctgcgccatcaggtggtgtttctacgcgatcaagctattacgccgcagcagcaacgcgcgctggc
> ccagcgttttggcgaattgcatattcaccctgtttacccgcatgccgaaggggttgacgagatca
> tcgtgctggatacccataacgataatccgccagataacgacaactggcataccgatgtgacattt
> attgaaacgccacccgcaggggcgattctggcagctaaagagttaccttcgaccggcggtgatac
> gctctggaccagcggtattgcggcctatgaggcgctctctgttcccttccgccagctgctgagtg
> ggctgcgtgcggagcatgatttccgtaaatcgttcccggaatacaaataccgcaaaaccgaggag
> gaacatcaacgctggcgcgaggcggtcgcgaaaaacccgccgttgctacatccggtggtgcgaac
> gcatccggtgagcggtaaacaggcgctgtttgtgaatgaaggctttactacgcgaattgttgatg
> tgagcgagaaagagagcgaagccttgttaagttttttgtttgcccatatcaccaaaccggagttt
> caggtgcgctggcgctggcaaccaaatgatattgcgatttgggataaccgcgtgacccagcacta
> tgccaatgccgattacctgccacagcgacggataatgcatcgggcgacgatccttggggataaac
> cgttttatcgggcggggtaa""".replace("\n","")
>
> gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds)
>
> print gc
>
> -fin-
>
> which should yield: 0.54460093896713613..
>
> but when I ran it I got: 0.544600938967
>
> looking now I see it's truncating after a certain number of decimal
> places. any ideas why?

Read the Python Tutorial appendix on floating-point issues:

    http://docs.python.org/tut/node16.html

As it says, str(a_float) rounds to 12 significant digits, and
repr(a_float) to 17.  The `print` statement implicitly applies str()
to each item it prints.


From atkinw at rpi.edu  Wed Dec 13 00:16:12 2006
From: atkinw at rpi.edu (Bill Atkins)
Date: Wed, 13 Dec 2006 00:16:12 -0500
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	
	
Message-ID: 

I V  writes:

> On Sun, 10 Dec 2006 03:18:07 -0500, Bill Atkins wrote:
>> We're not counting lines here, you goon.  We're talking about how
>> expressive constructs are and how closely they match your concept of
>> what you want to do.  The conditional example is lower-level; you're
>> talking to the interpreter instead of saying what you want to achieve.
>> You're having to repeat things because that's what the language asks
>> of you, instead of describing in a higher-level way what you're
>> actually doing.
>
> To be a little provocative, I wonder if the idea that you're "talking to
> the interpreter" doesn't apply more to lisp than to python; you can have
> any syntax you like, as long as it looks like an AST. 

Uhhh?

> One of the things I've always found off-putting about lisp as that all the
> syntax looks the same. In Algol-derived languages, each syntactic
> construct has a fairly distinctive appearance, so when, for instance, I
> encounter a for loop, I can quickly recognize that that's what it is, and
> bracket out the "scaffolding" and pick out the details that interest me.
> With lisp, I can't do that, I have to read through the sexp, decide on
> what syntax it is, and then remind myself where to look for the relevant
> specific details.

"Decide on what syntax it is"?  Examples?

> Now, this might well be just due to my comparative lack of familiarity
> with lisp; I'd be interested to hear if you lisp people find different
> lisp constructs as visually distinctive as constructs in python (or other
> similar languages). But I think what people are getting at when they
> complain about "all the brackets" in lisp may actually be this issue of
> a visual distinction between different constructs (this is also a reason
> why having a limited number of syntactic constructs can be helpful - there
> are a probably a  limited number of stereotypical layouts a programmer can
> keep in their mind at once).

We rely on indentation for readability just as you guys do.  Lisp
programs are not chaotic arrangements of parentheses and symbols; code
structure is made apparent through indentation.

(Why are people from c.l.p calling parentheses "brackets"?)


From http  Tue Dec 12 06:36:46 2006
From: http (Paul Rubin)
Date: 12 Dec 2006 03:36:46 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	
	
	<4u7g1kF17436jU1@mid.individual.net>
Message-ID: <7xmz5txs4x.fsf@ruckus.brouhaha.com>

Pascal Costanza  writes:
> May you have tried the wrong Lisp dialects so far:
> 
> (loop for i from 2 to 10 by 2
>        do (print i))

The loop language is so complicated and confusing that I never
bothered trying to learn it.  I always used simpler primitives to
write loops and it was always enough.

> This is Common Lisp. (Many Lisp and Scheme tutorials teach you that
> you should implement this using recursion, but you really don't have
> to. ;)

You can't really use that much recursion in Lisp because of the lack
of guaranteed TCO.  I think that makes it reasonable to say that
Scheme is a functional language but Lisp is not.  ("Functional" = it's
reasonable to code in a style where the only way to connect variables
to values is lambda binding (maybe through syntax sugar), so all loops
are implemented with recursion).


From anthra.norell at vtxmail.ch  Fri Dec 22 16:23:26 2006
From: anthra.norell at vtxmail.ch (Frederic Rentsch)
Date: Fri, 22 Dec 2006 22:23:26 +0100
Subject: textwrap.dedent replaces tabs?
In-Reply-To: <232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com>
References: 	<1166310662.825674.128700@l12g2000cwl.googlegroups.com>		
	<232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com>
Message-ID: <458C4CCE.6070602@vtxmail.ch>

Tom Plunket wrote:
> Frederic Rentsch wrote:
>
>   
>>> Well, there is that small problem that there are leading tabs that I
>>> want stripped.  I guess I could manually replace all tabs with eight
>>> spaces (as opposed to 'correct' tab stops), and then replace them when
>>> done, but it's probably just as easy to write a non-destructive dedent.
>>>       
>> This should do the trick:
>>
>>  >>> Dedent = re.compile ('^\s+')
>>  >>> for line in lines: print Dedent.sub ('', line)
>>     
>
> The fact that this doesn't do what dedent() does makes it not useful.
> Stripping all leading spaces from text is as easy as calling lstrip() on
> each line:
>   

My goodness! How right your are.
> text = '\n'.join([line.lstrip() for line in text.split('\n')])
>
> alas, that isn't what I am looking for, nor is that what
> textwrap.dedent() is intended to do.
>
> -tom!
>
>   
Following a call to dedent () it shouldn't be hard to translate leading 
groups of so many spaces back to tabs. But this is probably not what you 
want. If I understand your problem, you want to restore the dedented 
line to its original composition if spaces and tabs are mixed and this 
doesn't work because the information doesn't survive dedent (). Could 
the information perhaps be passed around dedent ()? Like this: make a 
copy of your lines and translate the copy's tabs to so many (8?) marker 
bytes (e.g. ascii 0). Dedent  the originals. Left-strip each of the 
marked line copies to the length of its dedented original and translate 
the marked groups back to tabs.

Frederic




From fredrik at pythonware.com  Sat Dec  9 15:20:44 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Sat, 09 Dec 2006 21:20:44 +0100
Subject: len() and PEP 3000
In-Reply-To: 
References: <4tnqlkF13bbqeU1@mid.individual.net>	<5HSdh.15210$P04.6844@tornado.fastwebnet.it>		<1165693115.007835.160250@j72g2000cwa.googlegroups.com>
	
Message-ID: 

Colin J. Williams wrote:

> On the other hand, one can argue that, since len is intimately 
> associated with an object, it's better treated as an attribute/property 
> than to have an unconnected function out in namespace.

"unconnected" ???





From michael at guerrilla-games.com  Fri Dec  1 03:06:49 2006
From: michael at guerrilla-games.com (Michael Malinowski)
Date: Fri, 1 Dec 2006 09:06:49 +0100
Subject: How to read the directory which the actively running python file is
	located in?
In-Reply-To: 
Message-ID: <00a801c7151f$a76d0de0$a8e7ca2b@guerrillagames.com>

Is there a way to read the directory that the currently running python file
is located in?
Cheers
Mike.



From lialie at gmail.com  Thu Dec 14 21:55:05 2006
From: lialie at gmail.com (Lialie - KingMax)
Date: Fri, 15 Dec 2006 10:55:05 +0800
Subject: Is it good to create a thread in a non gui thread?
Message-ID: <45820E89.4050702@gmail.com>

Hi,
I create a thread in a non gui thread, and it does well. But it seems
strange. Somebody told me better not for it may cause something hard to
imagine.
Is there any different between them?

THX


From gagsl-py at yahoo.com.ar  Fri Dec 22 20:03:31 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Fri, 22 Dec 2006 22:03:31 -0300
Subject: One module per class, bad idea?
In-Reply-To: 
References: 
	<1165916254.499121.62470@73g2000cwn.googlegroups.com>
	<1165951049.090837.145390@73g2000cwn.googlegroups.com>
	
	<1165964967.940454.74490@73g2000cwn.googlegroups.com>
	
Message-ID: <7.0.1.0.0.20061222215636.033e7d78@yahoo.com.ar>

At Friday 22/12/2006 12:56, Kent Johnson wrote:

>It does make the imports look funny - I tend to give the module the same
>name as the class, Java style, so I have
>from foo.bar.MyClass import MyClass
>but that is a minor point IMO.

You can always arrange things at the module level (inside 
__init__.py) so from "outside", people can say:
from foo.bar import MyClass
if you consider MyClass being in its own module an implementation 
detail that should be hidden.
Module layout is an important design concept


-- 
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 



From grue at mail.ru  Sat Dec  9 08:46:25 2006
From: grue at mail.ru (Timofei Shatrov)
Date: Sat, 09 Dec 2006 13:46:25 GMT
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<1165587080.038533.47910@80g2000cwy.googlegroups.com>
	<45797b9b$0$49206$14726298@news.sunsite.dk>
	<4ttiadF15dam8U1@mid.individual.net>
	<1165641503.331698.174270@j72g2000cwa.googlegroups.com>
	<4tvlr6F15jl45U1@mid.individual.net>
Message-ID: <457abe00.17627436@news.readfreenews.net>

On Sat, 09 Dec 2006 12:43:34 +0100, Bjoern Schliessmann
 tried to confuse everyone with
this message:

>samantha wrote:
>
>> What are you? A pointy haired boss?
>
>What are you? A 12 year old that has just learned to use Google
>Groups? 8)

Says a person with a 13-line sig.

-- 
|Don't believe this - you're not worthless              ,gr---------.ru
|It's us against millions and we can't take them all... |  ue     il   |
|But we can take them on!                               |     @ma      |
|                       (A Wilhelm Scream - The Rip)    |______________|


From grahamd at dscpl.com.au  Tue Dec 19 04:56:06 2006
From: grahamd at dscpl.com.au (Graham Dumpleton)
Date: 19 Dec 2006 01:56:06 -0800
Subject: Apache 2.2.3 and mod_python 3.2.10
References: <4587ab8e$0$5114$ba4acef3@news.orange.fr>
	<4587ac3e$0$5114$ba4acef3@news.orange.fr>
Message-ID: <1166522166.719092.268830@j72g2000cwa.googlegroups.com>


m.banaouas wrote:
> sorry, I give here the right paths:
>
> I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform
> I configured mod_python via httpd.conf:
> LoadModule python_module modules/mod_python.so
>
> but my script folder configuration doesn't work correctely:
>
> Alias /myfolder D:/myfolder
>
> 
>      Order allow,deny
>      Allow from all
>      AddHandler mod_python .py
>      PythonHandler mod_python.publisher
>      PythonDebug On
> 
>
> for test, this is a sample script d:\myfolder\test.py
> # test.py
> #
> from mod_python import apache
> #
> def hello(name=None):
>      if name:
>          return 'Hello, %s!' % name.capitalize()
>      else:
>          return 'Hello there!'
> #
> def handler(req):
>    req.content_type = 'text/plain'
>    req.write("from handler test, Hello World!")
>    return apache.OK
>
> when I access to the url  http://localhost/myfolder/test.py,
> I obtain source test.py listing but not the rendering of handler or
> hello method.
>
> with url http://localhost/myfolder/test.py/hello, I obtain :
> =>The requested URL /myfolder/test.py/hello was not found on this server.
>
> It seems like something is missing ... but what ?
>
> thanks for any help

Get it working for a normal handler first and don't use
mod_python.publisher.

For a set of instructions on how to get a simple handler working,
including descriptions of common problems and how to debug it, see:


http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking

Once you have confirmed that your installation works, then consider
looking at mod_python.publisher.

I'd also suggest that you get yourself on the mod_python user mailing
list and seek help there as the mod_python community there is much
larger. Mailing list details are on the mod_python web site.

BTW, don't you mean:

  

if that is what Alias uses?

Also, don't mix normal handlers and mod_python.publisher functions in
the same module, and don't use files called 'test.py' as there is a
standard Python module by the same name and if things aren't set up
right you can be picking up the wrong module.

Graham



From gagsl-py at yahoo.com.ar  Thu Dec  7 00:20:49 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Thu, 07 Dec 2006 02:20:49 -0300
Subject: per instance descriptors
In-Reply-To: <1165467481.033283.118340@f1g2000cwa.googlegroups.com>
References: <45777908_4@mk-nntp-2.news.uk.tiscali.com>
	<1165467481.033283.118340@f1g2000cwa.googlegroups.com>
Message-ID: <7.0.1.0.0.20061207021521.05445218@yahoo.com.ar>

At Thursday 7/12/2006 01:58, George Sakkis wrote:

>Simon Bunker wrote:
>
> > Basically I want to have the Input class as a gateway that does lots of
> > checking when the attibute is assigned or read.
> >
> > I have had a look at __getattribute__(), but this gets very ugly as I
> > have to check if the attribute is an Input class or not.
> >
> > Also I don't think property() is appropriate is it? All of the
> > attributes will essentially be doing the same thing - they should not
> > have individual set/get commands.
> >
> > Is there any way of doing this nicely in Python?
>
>What about __setattr__ ? At least from your example, checking happens
>only when you set an attribute. If not, post a more representative
>sample of what you're trying to do.

Or search the Python Cookbook - there are zillions of variants on how 
to manage properties (using inner classes, using decorators, using 
closures, using ...). Traits (code.enthought.com) may be useful too.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From gert.cuykens at gmail.com  Sun Dec 17 19:05:48 2006
From: gert.cuykens at gmail.com (Gert Cuykens)
Date: Mon, 18 Dec 2006 01:05:48 +0100
Subject: import
Message-ID: 

I would like to lauch a server from outside the side package directory
how do i specify a path with import

#/home/gert/Desktop/www/db/py/start-server.py
import cherrypy

class HelloWorld:
 def index(self):
  return #external htm file Hello world!
 index.exposed = True

if __name__ == '__main__':  # ??? dont know what is this for
 import os.path
 conf = os.path.join(os.path.dirname(__file__), 'conf-server.py')
 cherrypy.config.update(conf)
 cherrypy.quickstart(HelloWorld())
else:
 cherrypy.tree.mount(HelloWorld()) # ??? dont know what is this for

#/home/gert/Desktop/www/db/py/conf-server.py
[global]

server.socket_port = 8080

server.thread_pool = 10


From nono at hotmail.com  Sun Dec 31 11:45:18 2006
From: nono at hotmail.com (Osiris)
Date: Sun, 31 Dec 2006 17:45:18 +0100
Subject: Do You Want To Be An Internet Millionaire?
References: <1167581253.297389.275830@n51g2000cwc.googlegroups.com>
Message-ID: 

On 31 Dec 2006 08:07:33 -0800, "FREEDOM"  wrote:

>Dumb question, right?
>

yeah, very...
cause that time is long over, idiot.
Ever heard of the internet hyp ? being over ?



>Of course you do!
>
>Problem is, who is going to help you do it?

No doubt you are, and you will be the millionaire, from other ppls
money, sucker.

>
>That's where Worldprofit's Millionaire Mentoring Magic Millionaire
>Playbook comes in.

Yeah, and you're going to sell it to me ?


>
>It's produced by three self-made MULTI-Millionaires with over 36
>combined years of Internet experience -- George Kosch, Sandi Hunter and
>Dr. Jeffrey Lant.

Who ???

>
>These 100% client-centered experts have produced the detailed,

what is client-centered ????

>step-by-step playbook you've been waiting for with EVERYTHING you need
>to become an online Millionaire!
>
>The Millionaire Playbook -- Millionaire Mentoring Magic -- is a unique

Magic ????


>combination of videos, written instructions, and live and recorded
>webcasts -- all designed to give you what you need to know and do to

all designed to get YOU what YOU want

>profit online -- whatever business you're in, whatever level of
>business expertise and experience you have.

so you would support idiots and monkeys....

>
>IMPORTANT! Unlike traditional books and information products, once you
>have acquired the Millionaire Playbook you get ALL subsequent edits and
>enhancements FREE forever! 

If there are any...

>That means you permanently have three of the
>Internet's leading authorities -- George Kosch, Sandi Hunter, and Dr.
>Lant -- on your team FOREVER.
>

Oh my God ! forever ??? sucking me empty ???


>Get ALL the details on this incredible step-by-step guide to maximizing
>your online income by clicking below and learning more about
>MILLIONAIRE MENTORING MAGIC.
>
>That's where you'll find complete details and a detailed video by Dr.
>Jeffrey Lant.
>

Dr. who ???


>Click Here: http://wealthcaptains.com/default.cfm?pageid=28401
>
>
>HAPPY NEW YEAR!
>
>
>P.S.  You won't believe these websites I found:
>http://www.DesktopLightning.com/letshare
>http://www.agloco.com/r/BBBD6685

No I won't


From dakman at gmail.com  Wed Dec  6 14:02:21 2006
From: dakman at gmail.com (dakman at gmail.com)
Date: 6 Dec 2006 11:02:21 -0800
Subject: Am I stupid or is 'assert' broken in Python 2.5??
In-Reply-To: <1165416379.784513.51620@16g2000cwy.googlegroups.com>
References: <1165415689.347819.129680@73g2000cwn.googlegroups.com>
	
	<1165416379.784513.51620@16g2000cwy.googlegroups.com>
Message-ID: <1165431740.987270.323400@n67g2000cwd.googlegroups.com>

The reason why it won't raise the AssertionError is because the
condition in the assert statement is a non-empty tuple, and its boolean
value would be True, not False, which is required to raise an assertion
error.

antred wrote:
> Yeah, it hit me seconds after I had posted my message. =0 Why didn't I
> think of it during the 30 minutes I spent banging my head against the
> keyboard going nuts over this 'bug' ...



From mahs at telcopartners.com  Wed Dec 13 18:24:14 2006
From: mahs at telcopartners.com (Michael Spencer)
Date: Wed, 13 Dec 2006 17:24:14 -0600
Subject: Defining classes
In-Reply-To: 
References: 	
	
Message-ID: 

Nick Maclaren wrote:
> 
> Well, I am already doing that, and regretting the fact that Python
> doesn't seem to allow a class instantiation to return a new class :-)
> 

  >>> class Fake(object):
  ...     def __new__(cls):
  ...         return 42
  ...
  >>> Fake()
  42
  >>>

"instantiation" (i.e., calling the __new__ method) of new-style classes 
can return whatever you like, but I'm not sure how that helps.

One way of having a class member refer to the class, is to use the 
descriptor protocol, e.g.,:

  >>> def brinjal(cls): return cls.__name__
  ...
   >>> class Brinjal(object): # must be new-style
  ...     def __get__(self, obj, cls):
              return brinjal(cls)

  ...
  >>> class Weeble(object): # should be new-style
  ...     wumpus = Brinjal()
  ...
  >>> Weeble.wumpus
  'Weeble'
  >>> Weeble().wumpus
  'Weeble'
  >>>


Michael



From address.good.until.2007.feb.05 at justmail.de  Mon Dec 18 05:59:30 2006
From: address.good.until.2007.feb.05 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=)
Date: Mon, 18 Dec 2006 11:59:30 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <7x3b7ekk6p.fsf@ruckus.brouhaha.com>
References:  <7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
	<4uhl7cF108ri8U2@mid.individual.net>
	
	<7xslfgou14.fsf@ruckus.brouhaha.com>
	<2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom>
	<7xac1nfmyb.fsf@ruckus.brouhaha.com>
	<1166342606.141406.137000@f1g2000cwa.googlegroups.com>
	<7x3b7ekk6p.fsf@ruckus.brouhaha.com>
Message-ID: 

Paul Rubin schrieb:

> GC also gets rid of programs.  There are programs you can write in C
> but not in Lisp, like device drivers that poke specific machine
> addresses.

You are talking about an ANSI Common Lisp implementation.
But nothing stops a vendor to deliver its CL with libs that support
the writing of device drivers.
When Naughty Dog programmed games for the Play Station 2 the used
Common Lisp to develop a Lisp called "GOAL" (Game Oriented Assembly
Lisp) that was specialized for writing PS2 games.


Andr?
-- 


From agriff at tin.it  Tue Dec 12 19:37:52 2006
From: agriff at tin.it (Andrea Griffini)
Date: Wed, 13 Dec 2006 01:37:52 +0100
Subject: Inconsistency in dictionary behaviour: dict(dict) not calling
	__setitem__
In-Reply-To: 
References: <1165948261.745137.88540@j72g2000cwa.googlegroups.com>
	
	
Message-ID: <457f4a2b$0$19089$4fafbaef@reader4.news.tin.it>

Mitja Trampus wrote:

...
> At least, I know it surprised me when I first met this behavior. Or is 
> my reasoning incorrect?

Why len() doesn't call iteritems() ? :-)

Kidding apart for example it would be ok for __setitem__
to call either an internal "insert_new_item" or
"update_existing_item" depending on if the key is
already present in the dictionary.
In this case I suppose you agree it would make a lot
of sense to go directly for "insert_new_item" in the
constructor from a dict instead of calling the public
__setitem__...

The key point is that you're not authorized to assume
constructing a dictionary from a dictionary will use
__setitem__ unless this is explicitly stated in the
interface.

...

> What I find an even nastier surprise is that dict.update behaves this 
> way as well:
...
> The docstring is, at best, misguiding on this particular point:
> 
>  >>> print d.update.__doc__
> D.update(E, **F) -> None.  Update D from E and F: for k in E: D[k] = E[k]
> (if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = 
> F[k]

I cannot understand this doc string at all.

The explanation in the manual however just talks about
"updating", with no reference to assignments. The manual
of 2.3 instead was using a code example and I'd say this
would qualify as a binding to actually implement calls
to __setitem__. This kind of error (i.e. over-specifying
by providing actual code that implies specific side-effects)
was also present in the C++ standard, and in at least
one case an implementation would have to be very
inefficient to comply on the issue (this fortunately is
not what happened, the standard was "fixed" instead).

If there is a bug in this case is IMO a docstring bug.

Andrea


From __peter__ at web.de  Tue Dec  5 03:49:14 2006
From: __peter__ at web.de (Peter Otten)
Date: Tue, 05 Dec 2006 09:49:14 +0100
Subject: sending string or list to a function
References: <1165278026.064172.147770@l12g2000cwl.googlegroups.com>
	
	<1165285263.762430.245600@80g2000cwy.googlegroups.com>
Message-ID: 

tleeuwenburg at gmail.com wrote:

> Or, just always send the function a list. If you have one string, send
> it a list containing that one string.

Or, if a single string is more common and the lists are short or generated
only for the function call, have the function accept a variable number of
arguments:

>> def my_function(*items):
...     print " ".join(items)
...
>>> my_function("alpha")
alpha
>>> my_function("alpha", "beta")
alpha beta
>>> items = ["alpha", "beta", "gamma"]
>>> my_function(*items)
alpha beta gamma

Peter


From kay.schluehr at gmx.net  Tue Dec 12 04:47:16 2006
From: kay.schluehr at gmx.net (Kay Schluehr)
Date: 12 Dec 2006 01:47:16 -0800
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	
	
Message-ID: <1165916836.251432.267370@j72g2000cwa.googlegroups.com>

I V schrieb:

> One of the things I've always found off-putting about lisp as that all the
> syntax looks the same. In Algol-derived languages, each syntactic
> construct has a fairly distinctive appearance, so when, for instance, I
> encounter a for loop, I can quickly recognize that that's what it is, and
> bracket out the "scaffolding" and pick out the details that interest me.

I guess towards the intentional programming guys around Charles Simonyi
also all Algol languages look roughly the same. I remember how annoyed
I was as a math student that no PL supported my familiar notations
directly. I don't even try to speculate what chemists think about ASCII.



From bdesth.quelquechose at free.quelquepart.fr  Mon Dec 18 06:11:12 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Mon, 18 Dec 2006 12:11:12 +0100
Subject: import
In-Reply-To: 
References: 
Message-ID: <4586719a$0$29378$426a74cc@news.free.fr>

Gert Cuykens a ?crit :
> I would like to lauch a server from outside the side package directory
> how do i specify a path with import

http://docs.python.org/tut/node8.html#SECTION008110000000000000000

(snip)


> if __name__ == '__main__':  # ??? dont know what is this for

When a module is used as a program (ie python myprog.py), the 
module-level magic variable '__name__' is set to main. If the module is 
imported by another  one, this variable is set to the name of the 
module. This allow a module to have different behaviours according to 
how it is used.


From commander.coder at hotmail.com  Thu Dec 14 16:36:38 2006
From: commander.coder at hotmail.com (commander.coder at hotmail.com)
Date: 14 Dec 2006 13:36:38 -0800
Subject: automatically grading small programming assignments
In-Reply-To: <1166129734.888298.210830@l12g2000cwl.googlegroups.com>
References: 
	<1166129734.888298.210830@l12g2000cwl.googlegroups.com>
Message-ID: <1166131808.568578.47000@80g2000cwy.googlegroups.com>


bearophileHUGS at lycos.com wrote:
Then on your PC you can
> run a script that loads each of such programs, and runs a good series
> of tests, to test their quality...
What happens if someone-- perhaps not even someone in the class-- does
some version of os.system('rm -Rf /') ?



From bjourne at gmail.com  Mon Dec 25 19:12:15 2006
From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=)
Date: Tue, 26 Dec 2006 00:12:15 +0000
Subject: Generating all permutations from a regexp
In-Reply-To: <1166876589.669302.315740@f1g2000cwa.googlegroups.com>
References: 
	<1166876589.669302.315740@f1g2000cwa.googlegroups.com>
Message-ID: <740c3aec0612251612w41443b7eoc4214ffb63f2f10a@mail.gmail.com>

On 23 Dec 2006 04:23:09 -0800, Chris Johnson  wrote:
>
> BJ?rn Lindqvist wrote:
> > With regexps you can search for strings matching it. For example,
> > given the regexp: "foobar\d\d\d". "foobar123" would match. I want to
> > do the reverse, from a regexp generate all strings that could match
> > it.
> >
> > The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000",
> > "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999".
> >
> > Is this possible to do? Obviously, for some regexps the set of matches
> > is unbounded (a list of everything that matches "*" would be very
> > unpractical), but how would you do it for simple regexps like the one
> > above?
>
> For a very small number of characters, it would be feasible. For any
> finite number of characters, it would be possible (though it wouldn't
> take much to take longer than the age of the universe). For reference,
> in your simple example, you have 17,576,000 matching strings.
>
> I'm curious as to why you would wish to do this. I certainly understand
> considering hard problems for their own sake, but when I formulate
> them, there's always some impetus that makes me say "Huh. Now I
> wonder..."

I have a thousand use cases in mind. For example:

1. Generate sentences for a bot:

ipermute("(I|You|He|She|It|They) do( not)? (dis)?like (you|him|her|me|they)"):

Generates many grammatically incorrect sentences but you get the point.

2. Generate URL:s to web resources:

The following should generate URL:s to all c.l.p digests from the mail archive:

def download_clp():
    year_re = "(199\d|200[0-6])"
    months = ["January",
              "February",
              "March",
              "April",
              "May",
              "June",
              "July",
              "August",
              "September",
              "October",
              "November",
              "December"]
    month_re = '(' + '|'.join(months) + ')'
    fmt = "http://mail\.python\.org/pipermail/python-list/%s-%s\.txt"
    url_re = fmt % (year_re, month_re)
    for x in ipermute(url_re):
        print "Downloading", x
        code to download here

The same approach could be used to download all threads in a forum for
example, or all articles on Slashdot.

3. "Visualising" regular expressions. I think it would be easier to
write regular expressions if you could see what kind of data they
would match.

4. Port scanning:

ip_tuple = "(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])"
for x in ipermute("192\.168\." + "\.".join([ip_tuple] * 2)):
    scan_ip(x)

-- 
mvh Bj?rn


From kay.schluehr at gmx.net  Mon Dec 18 14:59:54 2006
From: kay.schluehr at gmx.net (Kay Schluehr)
Date: 18 Dec 2006 11:59:54 -0800
Subject: Python-URL! - weekly Python news and links (Dec 18)
References: 
Message-ID: <1166471994.876115.245430@j72g2000cwa.googlegroups.com>

Paul Boddie wrote:

>     Meanwhile, the EuroPython planners get ahead of themselves, thinking about
>     conference venues as far in the future as 2010, if not 20010!

Python 20010. It was a nice conference although a bit lame on the first
day. My favourite talks were:

Trevor Stent: "Whitespace as a universal constant"
Mathais Fendro: "Snake gods and how they tamed chaons and simili"
Taumaturg 7: "Technologia inversa. A short history of holistic
semantics"

There was also some interesting short talk about wormhole calculus.
Unfortunetely I've forgotten the name of the lecturer. Maybe I was just
too fascinated by his appeal as a small spinning bubble, shining in
rainbow colors.



From will at willNOmcguganSPAM.com  Thu Dec  7 17:04:42 2006
From: will at willNOmcguganSPAM.com (Will McGugan)
Date: Thu, 07 Dec 2006 22:04:42 +0000
Subject: write an update manager in python/wxPython
In-Reply-To: <1165522027.874287.206150@16g2000cwy.googlegroups.com>
References: <1165522027.874287.206150@16g2000cwy.googlegroups.com>
Message-ID: <45788ffc$0$2448$db0fefd9@news.zen.co.uk>

m.errami at gmail.com wrote:
> Hello all
> I have a small application for which I would like to write an update
> manager. I assume that the basics of it is to compare versions of the
> user's current application and a new one store in a new file on a
> particular URL.
> Now is there any standard way to do that. I am sure I can figure out
> something. But instead of designing something new from scratch that may
> end up to be full of bugs, maybe some existing classes in python,
> wxPython or within the win32com package exist.
> Any thoughts?

Dont think there is a standard way of doing it. The way I have done it 
in my applications is to keep an ini file containing the version number, 
  which is downloaded and compared against the version of the app. That 
part is trivial to implement in python with urllib. I just point the 
user at the download url when there is a new version. It would require a 
little more effort if you want to have some kind of automatic update...


Will McGugan
-- 
blog: http://www.willmcgugan.com


From jfabiani at yolo.com  Thu Dec 28 17:12:32 2006
From: jfabiani at yolo.com (johnf)
Date: Thu, 28 Dec 2006 14:12:32 -0800
Subject: db access
References: <1167320723.501187.98810@h40g2000cwb.googlegroups.com>
Message-ID: 

king kikapu wrote:

> Hi to all,
> 
> is there a way to use an RDBMS (in my case, SQL Server) from Python by
> using some built-in module of the language (v. 2.5) and through ODBC ??
> I saw some samples that use statements like "import dbi" or "import
> odbc" but neither modules (dbi, odbc) are present on my system...
> 
> Any hint(s) ??
> 
> Thanks in advance
Although others have suggested using ODBC or ADO I have a different
solution.  If you wanted a multi-platform I would use FreeTDS with
psmssql.py.  psmssql.py does support the DB API 2.0 although it does not
support any of the extendsions.  Works with Linux, Mac and Windows.

Johnf




From p at ulmcnett.com  Fri Dec  1 15:33:14 2006
From: p at ulmcnett.com (Paul McNett)
Date: Fri, 01 Dec 2006 12:33:14 -0800
Subject: detecting that a SQL db is running
In-Reply-To: <8g21n2tms1otvenfnurpia7pochq29458h@4ax.com>
References: <783tm2dmb6brnptr91hsfnc1t38u1utbi8@4ax.com>		<1164924313.495569.311330@80g2000cwy.googlegroups.com>	
	<8g21n2tms1otvenfnurpia7pochq29458h@4ax.com>
Message-ID: <4570918A.6030506@ulmcnett.com>

bill ramsay wrote:
> none of this matters,  all i am trying to find out is whether or not
> the local MSDE is actually running.

If it is a local MSDE then you may be able to rely on the connection
being refused if the server isn't running.

#-- begin
import socket

host = "127.0.0.1"
port = 1433  ## replace with msde_port, if it differs

s = socket.socket(socket.AF_INET)
try:
	s.connect((host, port))
	print "Server on %s is running" % port
except socket.error, e:
	print "Server on %s appears to be down (%s)" % (port, e)

#-- end

Please note that this is untested and not very well thought through. But
try it and see if it gets you on the right track. If this isn't run
locally, you'll probably need to set the timeout low enough for the
connect call not to appear to hang before returning the timeout error.

-- 
pkm ~ http://paulmcnett.com




From malaclypse2 at gmail.com  Fri Dec  8 16:42:39 2006
From: malaclypse2 at gmail.com (Jerry Hill)
Date: Fri, 8 Dec 2006 16:42:39 -0500
Subject: ERROR CLOSING CONNECTION: mysql connection close
In-Reply-To: <1165613585.887732.182740@j72g2000cwa.googlegroups.com>
References: <1165613585.887732.182740@j72g2000cwa.googlegroups.com>
Message-ID: <16651e80612081342q4a5520cfu5628dcd37c409c25@mail.gmail.com>

On 8 Dec 2006 13:33:05 -0800, johnny  wrote:
> I am getting following connection error from my python script:
>
>     conn.close()
> AttributeError: adodb_mysql instance has no attribute 'close'

>From the sample code on the adodb documentation page, that should be
spelled "conn.Close()" (note the capital C in Close()).

-- 
Jerry


From http  Mon Dec 11 19:42:48 2006
From: http (Paul Rubin)
Date: 11 Dec 2006 16:42:48 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>
	<1165769504.098173.101860@j72g2000cwa.googlegroups.com>
	<1165849055.492230.119310@n67g2000cwd.googlegroups.com>
	
	<7xslfmju4g.fsf@ruckus.brouhaha.com>
	<87mz5ufl4z.fsf@colinux.pc-mlivshin-ibm.cadence.com.cmm>
Message-ID: <7xslfm6j1z.fsf@ruckus.brouhaha.com>

Michael Livshin  writes:
> > Nobody seems to concerned that Haskell lacks macros.  What's up with
> > that?
> 
> Haskell is lazy, so it doesn't need macros (well, it would be more
> accurate to say that by not evaluating function arguments until they
> are needed it makes many of the usual macro usecases moot).
> 
> lazyness has a nontrivial cost, however, both runtime and cognitive.
> 
> hoping he's not answering a rhetorical question,

It's a reasonable answer.  Does SML have a macro system?


From steve at REMOVE.THIS.cybersource.com.au  Tue Dec 26 05:28:02 2006
From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
Date: Tue, 26 Dec 2006 21:28:02 +1100
Subject: How to depress the output of an external module ?
References: 
Message-ID: 

On Tue, 26 Dec 2006 15:49:10 +0800, fdu.xiaojf at gmail.com wrote:

> Hi,
> 
> I'm writing a program which imports an external module writing in C and
> calls a function provided by the module to do my job. But the method 
> produces
> a lot of output to the stdout, and this consumes most of the running time.
> 
> My question is, is there a way to depress the output produced by the
> function and hence make my program run faster? It's too complicated for me
> to modify the source code and recompile the external module.

Try something like this:

# WARNING: untested
def run_without_stdout(*args, **kwargs):
    function = args[0]
    args = args[1:]
    savestdout = sys.stdout
    sys.stdout = cStringIO.StringIO()
    result = None
    try:
        result = function(*args, **kwargs)
    finally:
        # don't forget to restore stdout, or you 
        # really will regret it...
        sys.stdout = savestdout
    return result



-- 
Steven.



From eric.pederson at gmail.com  Thu Dec 14 02:16:04 2006
From: eric.pederson at gmail.com (Eric Pederson)
Date: Wed, 13 Dec 2006 23:16:04 -0800
Subject: The Famous Error Message: "ImportError: No module
	named	python_script"
In-Reply-To: <1166078696.227746.165750@j72g2000cwa.googlegroups.com>
References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com>	
	<1166078696.227746.165750@j72g2000cwa.googlegroups.com>
Message-ID: <4580FA34.5060707@gmail.com>

rich murphy wrote:

>So, I assumed "the current directory" is C:\Python25 which did not
>work. Then I placed the fibo.py file in C: director. That did not work
>either. What directory does it mean then?
>
OK, forgive me for using 2.4...  Can you import "sys"?  Assuming you've 
got python_script.py at path:  "C:\\python_script.py" you might try this 
quick test:
  
 >>> import sys
 >>> sys.path
['C:\\Python24\\Lib\\idlelib', 'C:\\windows\\system32\\python24.zip', 
'C:\\Python24', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 
'C:\\Python24\\lib\\site-packages', 
'C:\\Python24\\lib\\site-packages\\win32', 
'C:\\Python24\\lib\\site-packages\\win32\\lib']   ## your ouput may be 
different
 >>> sys.path.append("C:\\")
 >>> sys.path
['C:\\Python24\\Lib\\idlelib', 'C:\\windows\\system32\\python24.zip', 
'C:\\Python24', 'C:\\Python24\\DLLs', 'C:\\Python24\\lib', 
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk', 
'C:\\Python24\\lib\\site-packages', 
'C:\\Python24\\lib\\site-packages\\win32', 
'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\']
 >>> import python_script


    6.1.1 The Module Search Path

When a module named spam is imported, the interpreter searches for a 
file named spam.py in the current directory [...]

Actually, modules are searched in the list of directories given by the 
variable |sys.path| which is initialized from the directory containing 
the input script (or the current directory), PYTHONPATH and the 
installation-dependent default. This allows Python programs that know 
what they're doing to modify or replace the module search path. Note 
that because the directory containing the script being run is on the 
search path, it is important that the script not have the same name as a 
standard module, or Python will attempt to load the script as a module 
when that module is imported. This will generally be an error. See 
section 6.2 <#standardModules>, ``Standard Modules,'' for more information.




From no-spam at no-spam-no-spam.invalid  Fri Dec  1 12:05:56 2006
From: no-spam at no-spam-no-spam.invalid (robert)
Date: Fri, 01 Dec 2006 18:05:56 +0100
Subject: Detecting recursion loops
In-Reply-To: 
References: 
	<1164815293.529674.109850@l39g2000cwd.googlegroups.com>
	
	
	
	
Message-ID: 

Neil Cerutti wrote:
> On 2006-12-01, robert  wrote:
>> Ben Finney wrote:
>>> robert  writes:
>>>
>>>> Carl Banks wrote:
>>>>> 2. Consider whether you're unwittingly trying to cover up a bug.
>>>>> ISTM no matter how problematic the input is, you should at least
>>>>> be able to make progress on it.  Are you getting this error
>>>>> because, say, you're not incrementing a counter somewhere, and
>>>>> thus recalling a function with the same arguments again?
>>>> the "bug" comes in from the I/O input.
>>> If a program doesn't gracefully deal with bad input, that's a bug in
>>> the program. You should be designing your input handler so that it
>>> will do something helpful (even if that's to stop immediately with an
>>> informative error message) in the event of bad input, rather than
>>> allowing that bad data to send your program into an endless loop.
>>
>> Yet that detection is what the asked alg should do. Example:
>> When a HTML-(content)-relaying sends you around in a circle
>> through a complex handler chain.
> 
> Being in a cycle doesn't actually prove your program will never
> halt for that particular input, does it?

not. but its not about a theoretical prove. in practice with same state it goes through the same function here.. I had simply had situations where a server looped my client on to a Python (long through a couple of func-calls) recursion error .

thus, either I fiddle a recursion/counter parameter through my calls, or I do complex state detection as e.g. to copy that of cherrypy was recommend in other post.
Or: I simply throw a hammer at an n-th recursion, wereby I programm the counter locally  as simple counter in a "global" thread-local-storage as I wrote.(also possible to use the same counter/limit in multiple functions!) 
There were just 2 lines of code to add.


Robert


 


From carsten at uniqsys.com  Thu Dec 21 14:45:18 2006
From: carsten at uniqsys.com (Carsten Haese)
Date: Thu, 21 Dec 2006 14:45:18 -0500
Subject: How a script can know if it has been called with the -i
	command line option?
In-Reply-To: <1166728967.099050.128290@a3g2000cwd.googlegroups.com>
References: <1166720012.798260.6670@80g2000cwy.googlegroups.com>
	<1166728967.099050.128290@a3g2000cwd.googlegroups.com>
Message-ID: <1166730318.3357.49.camel@dot.uniqsys.com>

On Thu, 2006-12-21 at 11:22 -0800, commander.coder at hotmail.com wrote:
> Michele Simionato wrote:
> > The subject says it all, I would like a script to act differently when
> > called as
> > $ python script.py and when called as $ python -i script.py. I looked
> > at the sys module
> > but I don't see a way to retrieve the command line flags, where should
> > I look?
> In the optparse module.

That doesn't answer the question. The OP wants to inspect the options
passed to the interpreter, not the options passed to the script.
optparse aids in parsing sys.argv, which only contains the options that
are passed to the script.

-Carsten




From fredrik at pythonware.com  Fri Dec  8 10:22:00 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 8 Dec 2006 16:22:00 +0100
Subject: Python's email module - problem with umlauts in some email clients
References: <457981FB.9030107@gmail.com>
Message-ID: 

Nico Grubert wrote:

> + On a solaris machine running thunderbird 1.5.0.8 and on a macintosh
>   machine running eudora umlauts are *not* displayed properly.
>   The email header does not contain any "Content-type". If I manually
>   switch the email client's character encoding to "Unicode (UTF-8)", the
>   umlauts are displayed properly. Therefore, I guess it has something to
>   do with the missing "Content-type: text/plain; charset=utf-8"
>   information in the email header.
>
> Any idea why the "Content-type: text/plain; charset=utf-8" is missing?

a misconfigured mail transfer agent ?

 





From bigblueswope at gmail.com  Tue Dec  5 11:06:16 2006
From: bigblueswope at gmail.com (BJ Swope)
Date: Tue, 5 Dec 2006 11:06:16 -0500
Subject: Monitoring number of smtp bytes sent through python e-mail socket
In-Reply-To: <4574C8D0.8060603@dodo.com.au>
References: <4574C8D0.8060603@dodo.com.au>
Message-ID: 

BTW, I noticed a bunch of new line characters in your test message.

If you ever send mail to a qmail server it will be rejected because rfc 821
says that new line characters cannot occur without a carriage return.  So
change all those \n's to \r\n's ;)
-- 
We are all slave to our own paradigm. -- Joshua Williams
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From grante at visi.com  Thu Dec 28 10:18:51 2006
From: grante at visi.com (Grant Edwards)
Date: Thu, 28 Dec 2006 15:18:51 -0000
Subject: DOS, UNIX and tabs
References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com>
	
	
Message-ID: <12p7o2rgnmtnf2c@corp.supernews.com>

On 2006-12-28, Felix Benner  wrote:

> I like using tabs. And the style guide doesn't give a reason
> why one shouldn't and neither does the thread
> http://www.python.org/search/hypermail/python-1994q2/0198.html
> in the archive. So what's the point in typing four spaces for
> indentation instead of one tab?

So that the whole Python source tree is consistent.

-- 
Grant Edwards                   grante             Yow!  What I want to find
                                  at               out is -- do parrots know
                               visi.com            much about Astro-Turf?


From Benjamin.Barker at gmail.com  Thu Dec 28 14:18:52 2006
From: Benjamin.Barker at gmail.com (Ben)
Date: 28 Dec 2006 11:18:52 -0800
Subject: dictionary containing instances of classes behaving oddly
In-Reply-To: <1167333218.447246.236960@h40g2000cwb.googlegroups.com>
References: <1167326178.386764.300200@n51g2000cwc.googlegroups.com>
	<4594102d$1@nntp.zianet.com>
	<1167333218.447246.236960@h40g2000cwb.googlegroups.com>
Message-ID: <1167333531.988660.154220@73g2000cwn.googlegroups.com>

Ah - I have been very silly indeed!

I had not realised that by creating my lists outside of the
def__init___() constructor they would always be class rather than
instance variables, and so there was only one of them when I referred
to it. Thanks to Erik and Chris for your help!

Ben


Ben wrote:

> Ah - ok. In fact I simply had:
>
> class record:
>         my_list =[]
>         mops=[]
>
>         def __init__(self,mops):
>                 self.mops=mops
>
> Where mops is something I pass in when i create the instance. I had
> thought that then each time I created an instance of the record class
> as an element of my dictionary:
>
> self.mop_list[record_number]=record(self.mops[:])
>
> I would create a brand new instance of the record class.It would have a
> mops list initialized with mops (because the def__init__ constructor is
> called when the class is instantiated), and an empty, individual list
> my_list.
>
> I could then access each individual list by doing:
>
> self.mop_list[x].my_list[y]=something
>
> But in fact the same my_list is being accessed for all values of x, so
> a change to one list is in fact a change to them all. I think you might
> be right, but can't quite work it out myself! I'll keep trying :-)
>
> Thanks for your help,
>
> Ben
>
>
>
>
>
> Erik Johnson wrote:
>
> > "Ben"  wrote in message
> > news:1167326178.386764.300200 at n51g2000cwc.googlegroups.com...
> >
> > 
> >
> > > This seems to work without any errors. But bizzarely I find that
> > > whatever my record number, the instance of "my_class" is appended to
> > > every list. So in this case
> > >
> > > self.mop_list[0].my_list.append(my_class(Some data for the
> > > constructor))
> > >
> > > I would expect to append an instance of my_class to
> > > self.mop_list[0].my_list
> > >
> > > But annoyingly
> > >
> > > self.mop_list[0].my_list
> > > self.mop_list[3].my_list
> > > self.mop_list[7].my_list
> > >
> > > all have an instance of my_class created and appended to them. This is
> > > really confusing and quite annoying - I don't know whether anyone out
> > > there can make head or tail of what I'm doing wrong?
> >
> > Well, it's a little bit difficult, but I think I actually know what's going
> > on. You probably need some code that looks something like this, to ensure
> > each object has it's own, independent list:
> >
> > class record:
> >     def __init__(self, init_list=None):
> >         self.my_list = []
> >         if init_list is not None:
> >             self.my_list.extend(init_list)
> >
> >
> > Here's what I think you are doing, and below should make it clear why that
> > doesn't work:
> >
> > class record:
> >     def __init__(self, init_list=[]):
> >
> > That list above, the default initializer is constructed just once (when the
> > def statement executes)!
> >
> > >>> class record:
> > ...   def __init__(self, init_list=[]):
> > ...     self.my_list = init_list
> > ...
> > >>> r1 = record()
> > >>> r1.my_list
> > []
> > >>> r2 = record()
> > >>> r2.my_list
> > []
> > >>> r2.my_list.append('boo!')
> > >>> r1.my_list
> > ['boo!']
> > >>>
> > >>> l1 = range(1, 4)
> > >>> l1
> > [1, 2, 3]
> > >>> r1 = record(l1)
> > >>> r2 = record(l1)
> > >>> r1.my_list
> > [1, 2, 3]
> > >>> r2.my_list
> > [1, 2, 3]
> > >>> r1.my_list.append(42)
> > >>> l1
> > [1, 2, 3, 42]
> > >>> r1.my_list
> > [1, 2, 3, 42]
> > >>> r2.my_list
> > [1, 2, 3, 42]
> > >>>



From Roka100 at gmail.com  Fri Dec  1 04:20:22 2006
From: Roka100 at gmail.com (Jia Lu)
Date: 1 Dec 2006 01:20:22 -0800
Subject: How to turn AUTOCOMMIT ON with cx_Oracle
Message-ID: <1164964822.037946.172490@79g2000cws.googlegroups.com>

Hi all.
 I use cx_Oracle to connect to an Oracle9i DB. And I want to turn on
AUTOCOMMIT function.
 I see that cur.execute("SET AUTOCOMMIT ON") cannot work. Is there any
method to do that ??

 Thanks a lot!



From aine_canby at yahoo.com  Wed Dec  6 05:29:27 2006
From: aine_canby at yahoo.com (aine_canby at yahoo.com)
Date: 6 Dec 2006 02:29:27 -0800
Subject: Novice: replacing strings with unicode variables in a list
In-Reply-To: <1165400671.935351.19190@f1g2000cwa.googlegroups.com>
References: <1165397220.491511.159310@f1g2000cwa.googlegroups.com>
	<4tnhghF14nrt7U1@mid.uni-berlin.de>
	
	<1165400671.935351.19190@f1g2000cwa.googlegroups.com>
Message-ID: <1165400967.672374.226590@80g2000cwy.googlegroups.com>


aine_ca... at yahoo.com skrev:

> Fredrik Lundh skrev:
>
> > Diez B. Roggisch wrote:
> >
> > > Please provide the full script, and the desired input - then we might be
> > > able to help you.
> >
> > the full *traceback* would pretty useful, too:
> >
> > http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do.htm
> >
> > my guess is that the OP left out the print statement that causing the error, and the
> > traceback lines that pointed to that print statement:
> >
> > > more test.py
> > uni = u"p\x95l"
> > print uni
> >
> > > python test.py
> > Traceback (most recent call last):
> >   File "test.py", line 2, in 
> >     print uni
> >   File "C:\python25\lib\encodings\cp850.py", line 12, in encode
> >     return codecs.charmap_encode(input,errors,encoding_map)
> > UnicodeEncodeError: 'charmap' codec can't encode character u'\x95' in position 1
> > : character maps to 
> >
> > 
>
> Thanks for the replies. OK heres the full code I'm using now -
>
> compare = u"?is"
> print compare
>
> str = raw_input("Enter music:")
> words = str.split()
>
> uniList=[]
> for word in words:
> 	uni=unicode(word,'latin-1')
> 	uniList.append(uni)
>
> print uniList[0]
>
> if(compare!=uniList[0]):
> 	print "Not the same: " + compare + " " + uniList[0]
>
> This gives the following error -
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "test.py", line 14, in 
>     print uniList[0]
>   File "C:\Python25\lib\encodings\cp850.py", line 12, in encode
>     return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\x8e' in
> position 0
> : character maps to 
>
> How come I can print compare but not uniList[0]? What encoding is being
> used to store compare? How can I print out the raw bytes stored in
> compare and uniList[0]?
>
> Thanks again for your help,
>
> Aine.

Cool. It works for me now.

import sys

compare = u"?is"
print compare

str = raw_input("Enter music:")
words = str.split()

uniList=[]
for word in words:
	uni=unicode(word,sys.stdin.encoding)
	uniList.append(uni)

print uniList[0]

if(compare!=uniList[0]):
	print "Not the same: " + compare + " " + uniList[0]



From rNOSPAMon at flownet.com  Fri Dec  1 03:03:34 2006
From: rNOSPAMon at flownet.com (Ron Garret)
Date: Fri, 01 Dec 2006 00:03:34 -0800
Subject: Functions, callable objects, and bound/unbound methods
Message-ID: 

If I do this:

def f(self): print self

class c1: pass

setattr(c1, 'm1', f)

Then f is automagically transmogrified into the appropriate sort of 
method depending on how it is used:

>>> c1.m1

>>> c1().m1
>
>>> c1().m1()
<__main__.c1 instance at 0x51ec60>

Note that m1 gets passed a self argument.

The same automatic transmogrification does not happen if I use an 
callable instance instead of an actual function object:

class callable:
  def __call__(self, *args, **kw): return args, kw

>>> setattr(c1, 'm2', callable())
>>> c1.m2
<__main__.callable instance at 0x51e738>
>>> c1().m2
<__main__.callable instance at 0x51e738>
>>> c1().m2()
((), {})

Note that no selfarg has been passed to m2.

The reason I want to do this is that I want to implement a trace 
facility that traces only specific class methods.  I want to say:

trace(c1.m1)

and have c1.m1 be replaced with a wrapper that prints debugging info 
before actually calling the old value of m1.  The reason I want that to 
be an instance of a callable class instead of a function is that I need 
a place to store the old value of the method so I can restore it, and I 
don't want to start building a global data structure because that gets 
horribly ugly, and a callable class is the Right Thing -- if there's a 
way to actually make it work.

Is there?  I tried the obvious things (like making callable inherit from 
function, and adding im_func and im_self attribuetes) but they didn't 
work.

Thanks,
rg


From fredrik at pythonware.com  Fri Dec  1 02:15:54 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 01 Dec 2006 08:15:54 +0100
Subject: Why are slice indices the way they are in python?
In-Reply-To: <1164946752.12347.0.camel@enterprise>
References: <1164860915.349821.309920@14g2000cws.googlegroups.com>	<1164905936.794174.299200@l12g2000cwl.googlegroups.com>
	<1164946752.12347.0.camel@enterprise>
Message-ID: 

Michael Torrie wrote:

> Forgive me for my ignorance, but isn't "2006-12-31 23:59:59" actually
> one entire second earlier than "2007-01-01 00:00:00"?  Hence they are
> two different dates are they not?

given the context, maybe the poster meant that he's storing date 
*ranges* as [start, stop) (i.e. including start but not including
stop).





From grante at visi.com  Fri Dec  1 10:54:32 2006
From: grante at visi.com (Grant Edwards)
Date: Fri, 01 Dec 2006 15:54:32 -0000
Subject: Is python memory shared between theads?
References: <1164987833.233073.265170@80g2000cwy.googlegroups.com>
Message-ID: <12n0k1o3tab9nec@corp.supernews.com>

On 2006-12-01, Wesley Henwood  wrote:

> So I declare a variable named A in thread1, in script1.py.  I assign
> the value of 2.5 to A.  I then run script2.py in thread2.  Script2.py
> assigns the value of 5.5 to a variable named A.  Now, when thread1
> resums execution, I see that A = 5.5, rather than 2.5 as I expected.
>
> Is this normal behavior?

Yes.  Threads share global namespace.  From a CPU point of
view, they share a single address space.

> Based on the little documentation I have been able to find on
> this topic, it is normal behavior.  The only way to use
> same-named variables in scripts is to have them run in a
> different process, rather than different threads.

Or make them local variables.

-- 
Grant Edwards                   grante             Yow!  If I felt any more
                                  at               SOPHISTICATED I would DIE
                               visi.com            of EMBARRASSMENT!


From bdesth.quelquechose at free.quelquepart.fr  Tue Dec 12 16:32:05 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Tue, 12 Dec 2006 22:32:05 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <45794fc2$0$11094$3b214f66@tunews.univie.ac.at>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<45794fc2$0$11094$3b214f66@tunews.univie.ac.at>
Message-ID: <457f1a42$0$8414$426a74cc@news.free.fr>

Mathias Panzenboeck a ?crit :
> Mark Tarver wrote:
> 
>>How do you compare Python to Lisp?  What specific advantages do you
>>think that one has over the other?
>>
>>Note I'm not a Python person and I have no axes to grind here.  This is
>>just a question for my general education.
>>
>>Mark
>>
> 
> 
> I do not know much about Lisp. What I know is:
> Python is a imperative, object oriented dynamic language with duck typing,

Python is a dynamic multi-paradigm language which is mostly OO but has 
support for procedural and functional programming

> List

s/s/p/

> is a declarative,
> functional dynamic language -> those two languages have different scopes.

Lisp is a multi-paradigm language which is mostly functional but has 
support for procedural and OO programming.

Both are highly dynamic. Neither are declarative.


From cliff at develix.com  Mon Dec 11 05:16:01 2006
From: cliff at develix.com (Cliff Wells)
Date: Mon, 11 Dec 2006 02:16:01 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <1165742889.208943.142280@16g2000cwy.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<1165627684.709241.86340@16g2000cwy.googlegroups.com>
	<1165685950.758858.18960@n67g2000cwd.googlegroups.com>
	<1165732072.056289.274460@79g2000cws.googlegroups.com>
	
	<1165739878.421439.193030@f1g2000cwa.googlegroups.com>
	<1165742889.208943.142280@16g2000cwy.googlegroups.com>
Message-ID: <1165832162.20491.108.camel@portableevil>

On Sun, 2006-12-10 at 01:28 -0800, Kay Schluehr wrote:


> Who really wants to write web apps? Web apps are just an excuse for
> Pythonistas to write web frameworks.


I've been lurking, waiting for the right moment to toss in my two cents,
and finally, and here it is.

I've been using Python heavily for many years (since late 1.5.1) and
frankly I've gotten a bit bored with it.  I think your statement
indirectly (and unintentionally I'm sure) sums up why.   Python is
certainly pragmatic.  Python has *everything* you'd want for writing
applications: extensive libraries, flexibility, etc.  

Unfortunately, writing applications is boring. 

The way I like to overcome this boredom (and hence stay productive) is
by writing clever code.  I don't mean obfuscated one-liners (although
I'm guilty of that too), rather I mean generalizing code, creating
frameworks and then developing the application in that framework, that
sort of thing.  Python has been pretty good for me so far in keeping the
ceiling high enough that I could stretch but not bump my head too often.
I suspect I'm not alone in this need (hence the unusual number of web
frameworks written in Python).   

However lately I've noticed that the ceiling is quite apparent: Python
programmers are free to define DSL's via functions, classes, clever
operator overloading, etc, but not in the one way that actually makes
them really interesting: macros.    
It might be true that macros would make it more difficult for someone
else to understand my code (although I doubt much more than say, Zope or
Twisted, or any of the popular ORMs floating about).   Regardless, let's
take a moment to consider another point of view: I. DON'T. CARE.  That's
right.  I don't care if anyone else can read it.  Frankly I may not even
care if *I* can read it in a year.   Every year I look back at what I've
written the previous year and think about how much better I could have
done it *this* year.  This has gone on for over twenty years now and I
suspect that if that fact ever changed it would probably be time for me
to retire from programming as I'd have stopped learning (or would at
least be bored out of my mind).

The majority of code is throwaway.  That is, whatever need it was
written to fulfill will cease to exist, the coder will think of some
brilliant new approach that requires a major rewrite, another programmer
with different ideas will rewrite it from the ground up (probably in a
new language), a library will appear that renders it moot, etc, etc.
While I'm sure there is a huge base of ancient code out there somewhere,
faithfully powering our banks and dams and pushing fractions of pennies
about, I simply don't care.  Someone may have to read it, please god
don't let it be me.  I don't care about old application code.  It's
effing boring.  I don't just program because it pays the bills.  I
program because I *like to program*.   That means not having arbitrary
limits to what I can express so that some hypothetical 8th grader can
come along in some future decade and grok some one-off program I hacked
together over a weekend.   If I write code during a drunken binge, then
dammit, I'll run that code in another drunken binge.  If not, then I'll
damn well rewrite it when I'm sober.   I neither want nor need moral
programming imperatives handed down from above.   I will write crappy
code whenever I damn well feel like it.  If I learn something from it,
all the better.  If not, well that's my choice as an adult to take that
path.

There is lots of talk about how, if Python had macros, everyone would
create their own mini-languages and it would be a virtual Tower of
Babel, etc, etc.  Perhaps.  But of course, given how much syntax Python
has grown since 1.5 (most of which is there to compensate for
statement-oriented syntax and lack of macros) I'd suggest that perhaps
the tower is already being built directly into the language.

As an aside, it's pretty sad when many of the c.l.lisp folks on this
thread seem more polite in general than the c.l.py crowd.   Lisp may
have expression-based syntax and macros, but it's also got Eric Naggum.
If we can't have the nice features of Lisp, let's at least not adopt its
downsides.

Regards,
Cliff

P.S.  As a disclaimer, I *have* had a few beers tonight already and
have, in fact, been binge-coding, so if this seems like a rant, I
reserve the right to deny all knowledge of anything I may have written
up to this point. 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From mail at microcorp.co.za  Fri Dec  8 01:03:41 2006
From: mail at microcorp.co.za (Hendrik van Rooyen)
Date: Fri, 8 Dec 2006 08:03:41 +0200
Subject: Best way to split up lines - RE: About the 79
	characterlinerecommendation
References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com><012601c719f7$9e719990$0d7d12ac@kearfott.com>
	<1165515096.287635.252360@79g2000cws.googlegroups.com>
Message-ID: <027201c71a93$41d45e60$03000080@hendrik>

"John Machin"  wrote:

8<-------------------

> >     data = struct.unpack("!H4BH20BHI", strMessage)
> >
> >     (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired,
> >     dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8,
> >     utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6,
> >     numberOfLabels, dataWord) = data
> >
>
> Those utc1, ..., utc12 etc inspire a suggestion: a mild addition to the
> syntax to allow specifying that the following repeat count should be
> interpreted as the expected dimension of a tuple (unpack) or any
> indexable object with a __len__ method (pack):
>
> (top, ip, messageCounter, ackRequired,
> dataType, utc, st, numberOfLabels, dataWord,
> ) = struct.unpack("! H /4B H B B /12B /6B H I", strMessage)
>
> Apropos of a recent thread: I don't need pointing at the suggestion box
> and the patch submission gizmoid on Sourceforge -- I'd be happy to do a
> patch, just wondering if anybody's interested in having that, besides
> me and Pat Malone :-)

just a comment - it took me a while to figure out what you were on about.

The relationship between the sources and targets are not immediately obvious
(not to me, at least)

I wonder if it would not be better to leave the struct stuff alone, and to
"dimension"
the left hand side - something like ip(4) and utc(12) ? or ip*4, or whatever...

- Hendrik




From __peter__ at web.de  Sat Dec  9 12:28:54 2006
From: __peter__ at web.de (Peter Otten)
Date: Sat, 09 Dec 2006 18:28:54 +0100
Subject: Error: unbound method in Tkinter class
References: <6d3e0$457aefa4$4275d90a$12235@FUSE.NET>
Message-ID: 

Kevin Walzer wrote:

> I am trying to structure a Tkinter application with classes instead of
> just with simple functions, but I'm not sure how to call methods from my
> main class.
> 
> My main class is packetstreamApp(). Within that class I call various
> methods, including drawGUI() and authorizeDump(). My problem comes when
> I try to call authorizeDump from the Tkinter menu. Here is the code that
> calls authorizeDump():
> 
> self.packetmenu.add_command(label="Start Network Monitor",
> command=packetstreamApp.authorizeDump())

If that code is inside a method of packetstreamApp:

self.packetmenu.add_command(label="...", command=self.authorizeDump)

i. e. you have to pass a bound method (a method that knows about "its"
instance) and you must not call authorizeDump here (no trailing '()').

Of course I'm only guessing...

Peter


From kw at codebykevin.com  Tue Dec 12 09:17:56 2006
From: kw at codebykevin.com (Kevin Walzer)
Date: Tue, 12 Dec 2006 09:17:56 -0500
Subject: Tkinter button doesn't appear in OS X
In-Reply-To: <1165893733.852293.229190@f1g2000cwa.googlegroups.com>
References: <1165798158.199702.217180@79g2000cws.googlegroups.com>
	<457CC308.1080801@codebykevin.com>
	<1165893733.852293.229190@f1g2000cwa.googlegroups.com>
Message-ID: <5de3b$457eba18$4275d90a$12544@FUSE.NET>

crystalattice wrote:
> Kevin Walzer wrote:
>> What version of Tk are you running? I've seen this bug on old versions
>> of Tk (i.e. 8.4.7) but not recently.
>>
>> --
>> Kevin Walzer
>> Code by Kevin
>> http://www.codebykevin.com
> 
> I'm using Python 2.4.2, which I believe is the default version for OS
> X.  How do I check the Tk version?  Can I force my programs to use a
> different version of Python, e.g. if I installed Python 2.5?
> 
When you run your program on OS X, there should be a menu item next to
the Apple menu that says "about Tcl/Tk," which you access from the
"Python" menu item. That will give you the version number.

Python 2.3.5 and Tcl/Tk 8.4.7 ship with OS X 10.4. Python 2.4.2 is a
separate installation, but probably accesses the system Tcl/Tk unless
you have installed a more recent version. Using the official Mac build
of Python 2.5 will update your Python, but not Tcl/Tk--you'll need to
install something more recent.

You can install ActiveTcl for a "batteries-included" distro of
Tcl/Tk--it has the latest and greatest of everything. Or, you can
install a slightly older (8.4.13) version of Tcl/Tk at
http://tk-components.sourceforge.net. (This is a version of Tcl/Tk Aqua
that I use in my own programs and I made the build available for others
to use.)

Hope that helps,
Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


From george.sakkis at gmail.com  Fri Dec  8 04:18:22 2006
From: george.sakkis at gmail.com (George Sakkis)
Date: 8 Dec 2006 01:18:22 -0800
Subject: autoadd class properties
References: <1165567093.167813.109000@j44g2000cwa.googlegroups.com>
Message-ID: <1165569502.811830.157900@73g2000cwn.googlegroups.com>

manstey wrote:

> I have a ClassWrapper that wraps around a third party database object.
> Each database object has a set of properties, like columns in a
> relational database.
>
> I want my wrapper to generate a property for each database object and
> load its value into it.
>
> Thus, in my database (which is an oodbms) say I have a MyDbaseClass
> with MyProperty1, MyProperty2, etc, after it is loaded, I have:
>
> dbase_object = LoadMyDbaseClass
> PythonDbaseClass = PythonWrapper(dbase_object)
>
> I can then load in a list of ['MyProperty1','MyProperty2', etc].
>
> But how can I turn these list elements into PythonDbaseClass
> properties, so that I could then simply have:
>
> print PythonDbaseClass.MyProperty1
> PythonDbaseClass.MyProperty2="4"
>
> Is this clear?

Sounds as if you're reinventing a part of an ORM. Have you checked out
SQLAlchemy or Django's ORM, in case they provide what you want out of
the box ?

George



From gagsl-py at yahoo.com.ar  Fri Dec 22 20:21:24 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Fri, 22 Dec 2006 22:21:24 -0300
Subject: One module per class, bad idea?
In-Reply-To: <1166829929.511423.110970@h40g2000cwb.googlegroups.com>
References: 
	<1165916254.499121.62470@73g2000cwn.googlegroups.com>
	<1165951049.090837.145390@73g2000cwn.googlegroups.com>
	
	<1165964967.940454.74490@73g2000cwn.googlegroups.com>
	
	<1166817152.414154.151390@42g2000cwt.googlegroups.com>
	<458c489c$1@nntp.zianet.com>
	<1166823140.827296.92960@h40g2000cwb.googlegroups.com>
	<1166829929.511423.110970@h40g2000cwb.googlegroups.com>
Message-ID: <7.0.1.0.0.20061222221601.01e09a78@yahoo.com.ar>

At Friday 22/12/2006 20:25, Paddy wrote:

>Are there tools out their to help with the refactoring task of
>splitting a module into two or more sections then showing what other
>files need to change?

Usually no other files need to change. Ex: you have BigOldModule 
including ClassA, ClassB and FunctionC. Move each one onto its own 
module, perhaps including a subset of the original imports of BigOldModule.
Shrink BigOldModule to just:

from ClassA import ClassA
from ClassB import ClassB
from functionC import functionC

and maybe a few other things, so all imports from the outside remain 
the same. That's all - most of the time.


-- 
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 



From bbands at gmail.com  Tue Dec 19 10:49:34 2006
From: bbands at gmail.com (BBands)
Date: 19 Dec 2006 07:49:34 -0800
Subject: Reduced invective
Message-ID: <1166543373.998192.215800@f1g2000cwa.googlegroups.com>

My fat-fingered alter ego typed
    delete from iv where date > '2006-01-01';
instead of
    delete from iv where date > '2006-12-01';
leaving me with 50 tables to reload. :(

estimated time to fix > several hours
estimated invective dispensed during fix = classified

Python to the rescue!

import os
import MySQLdb

files = os.listdir("d:\\hedge\\old data\\")

conn = MySQLdb.connect(host = 'host',
                       user = 'user',
                       passwd = 'pass',
                       db = 'db')
curs = conn.cursor()

for line in files:
    if line[-4:] == "2006":
        SQL = "LOAD DATA "
        SQL += "INFILE 'd:/hedge/old data/" + line
        SQL += "' INTO TABLE iv "
        SQL += "FIELDS TERMINATED BY ',' "
        SQL += "(symbol, date, iv, pv, cv);"
        curs.execute(SQL)

time to execute = 5 mins
invective dispensed while executing = 0

A hearty thank you and Happy Holidays to all in the Python community.

     jab



From mark.dufour at gmail.com  Sat Dec  9 06:25:39 2006
From: mark.dufour at gmail.com (Mark Dufour)
Date: Sat, 9 Dec 2006 12:25:39 +0100
Subject: Shed Skin 0.0.15
Message-ID: <8180ef690612090325x5357080fi2a33b570437358cc@mail.gmail.com>

Hi all,

After getting bogged down with work for a few months, I'm finally back
to Shed Skin development. I have just released 0.0.15, with the
following changes:

-python2.5 support/compatibility
-any, all, conditional expression support
-moved libs to 'lib' dir; made it easier to add modules (see README)
-os.stat, os.path.{split, splitext, isfile, isdir, islink, exists}
compiled from PyPy source
-os.{chdir, rename, stat, lstat} added
-fnmatch module added
-random.{sample, seed} added
-several important bugfixes (e.g. except getopt.GetoptError)

There's more information about this release and the current state of
Shed Skin on my blog:

http://shed-skin.blogspot.com/

I also started a page on Wikipedia. Maybe a text like this should
replace the one on the Shed Skin website:

http://en.wikipedia.org/wiki/Shed_Skin

Projects for the near future are getting 'shuffle-db' working (a
600-line program to rebuild the database on an ipod shuffle; see my
blog), and converting the 're' module from the PyPy implementation to
C++ using Shed Skin.

Please try out the new release, and let me know about any
problems/wishes/successes. As always, I am very happy with minimized
pieces of code that fail to compile or should produce a (better) error
or warning message.

http://mark.dufour.googlepages.com


Mark.
-- 
"One of my most productive days was throwing away 1000 lines of code"
- Ken Thompson


From ronrsr at gmail.com  Mon Dec 18 02:15:05 2006
From: ronrsr at gmail.com (ronrsr)
Date: 17 Dec 2006 23:15:05 -0800
Subject: dealing with special characters in Python and MySQL
In-Reply-To: <0Yqhh.20400$wc5.8435@newssvr25.news.prodigy.net>
References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com>
	
	<1166423874.304873.218020@t46g2000cwa.googlegroups.com>
	<0Yqhh.20400$wc5.8435@newssvr25.news.prodigy.net>
Message-ID: <1166426105.495305.173690@73g2000cwn.googlegroups.com>


> >
>     Try putting "use_unicode=True" in the MySQLdb "connect" call.

tried that, and also added charset="utf8" -

now, I can't do any string operations, I get the error msg:

descriptor 'lower' requires a 'str' object but received a 'unicode'
      args = ("descriptor 'lower' requires a 'str' object but received
a 'unicode'",)


or similar, on every string operation.

many thanks,

-0rsr-


>
>     See
>
> http://sourceforge.net/tracker/index.php?func=detail&aid=1559350&group_id=22307&atid=374932
>
> and look at other charset related bugs at
>
> http://sourceforge.net/tracker/?atid=374932&group_id=22307&func=browse
>
> Also note that MySQLdb didn't support this until recently, so check
> your version of MySQLdb.  There still seem to be problems in that area.
> 
> 				John Nagle
> 				Animats



From sandravandale at yahoo.com  Sat Dec 16 20:02:04 2006
From: sandravandale at yahoo.com (Sandra-24)
Date: 16 Dec 2006 17:02:04 -0800
Subject: How to test if two strings point to the same file or directory?
Message-ID: <1166317324.791635.274550@79g2000cws.googlegroups.com>

Comparing file system paths as strings is very brittle. Is there a
better way to test if two paths point to the same file or directory
(and that will work across platforms?)

Thanks,
-Sandra



From chrisguest at gmail.com  Mon Dec  4 01:50:32 2006
From: chrisguest at gmail.com (chrisguest at gmail.com)
Date: 3 Dec 2006 22:50:32 -0800
Subject: algorithm for sorting functional expressions
Message-ID: <1165215032.749560.171530@16g2000cwy.googlegroups.com>

I am trying to write some code that will take a list of functional
expressions, and order them so that those with primitive terms appear
at the beginning of the list and those that are defined by other terms
appear last.

	eg:
	getSortedEquations(['b = w + z','a = z - y','w = 2*z + v','z = e +
f','y = p + l']) =
		['w = 2*z + v', 'z = e + f', 'y = p + l', 'b = w + z', 'a = z - y']

It is easy enough to tokenise each of the equations and produce a list
like:
	 ['b', ['w','z']], ['a': ['z','y']], ['w':'z','v'] , ['z', ['e','f']],
['y',['p','l']]

But I'd like to find an algorithm that can handle the sorting problem.

So I suspect that this is a common problem for those familiar with
partially ordered sets or directed graphs. I'm wondering if anyone else
is familiar with this problem and knows an efficient algorithm that
will solve it. It would be good if any such algorithm would be able to
check for circular definitions in the input.



From http  Sun Dec 10 01:15:04 2006
From: http (Paul Rubin)
Date: 09 Dec 2006 22:15:04 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
	<1165698244.563344.62270@73g2000cwn.googlegroups.com>
	
	
	<7xk610a0kl.fsf@ruckus.brouhaha.com>
	
	
Message-ID: <7xfybo1dlj.fsf@ruckus.brouhaha.com>

Kirk  Sluder  writes:
> Another common macro use is the "WITH-STREAM" family which opens a 
> stream for IO and closes it at the end.  
> (with-open-file (file-handle "filename" :direction :output)
>    (format file-handle "Hello world.~%")
> ) 
> 
> The pythonic way to do this would be to create a class that 
> implements file-like behaviors:
> 
> output = fileLike.open()
> output.write("Hello world\n")
> output.close()

Actually the Python example can lose (e.g. leak a file descriptor
temporarily) if output.write raises an exception (prevents
output.close from running).  For this reason Python recently
introduced the "with" statement:

    with output as fileLike.open():
       output.write("Hello world\n")

Here the file gets closed automatically (by running an exit method in
the fileLike class) when the "with" block exits, whether normally or
through an exception.


From bernard.chhun at gmail.com  Mon Dec  4 09:02:41 2006
From: bernard.chhun at gmail.com (Bernard)
Date: 4 Dec 2006 06:02:41 -0800
Subject: please provide urls for some python success stories.
In-Reply-To: 
References: 
Message-ID: <1165240961.075756.150820@j72g2000cwa.googlegroups.com>

http://pythonology.org/success

this should be enough...but why don't you write a solid app in python
and show it to them?
Seeing is believing.

Bernard

krishnakant Mane a ?crit :

> hello all.
> actually I have been recently appointed as a technology consulltent at
> a huge company.
> and I have couple more such projects in the pypeline.
> unfortunately the officials out here are too much in favour of java
> and I have personally worked with both and find that python is heaven
> in syntax and makes it very easy to do complex things.  on speed?  I
> think experts on this list can give better answer, but efficiency and
> maintainance wise there is nothing like python I believe.
> the problem here is that I am from India and all indians on this list
> can correct me if I am wrong, very few people know about python here.
> infact a vast majority of programmers ask me "python? what is that!"
> they don't even know that it is a programming language, let alone using it.
> but I am amongst the very few who have actually used both java and python.
> I need some strong evidence to prove to these stupid and java oriented
> officials that there is some thing better than java called python.
> can some one provide me some urls or may be share some personal
> experience on this issue?
> I saw a couple of blogs and a few success stories on the python web site itself.
> but the common answer I am getting is "y! even java can do this and
> java is much faster!"
> I am really adicted to python due to its superiority and efficiency
> and the  amount of libraries.
> but I need some strong official efidence.
> Please help me, I don't want to leave python.
> Krishnakant.



From jon at ffconsultancy.com  Tue Dec 12 11:18:18 2006
From: jon at ffconsultancy.com (Jon Harrop)
Date: Tue, 12 Dec 2006 16:18:18 +0000
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	
	<%TBeh.331$tv5.155@newsfe11.lga>
	
	
	
	
	
	<7xfybnjkz4.fsf@ruckus.brouhaha.com>
	
	
	<457d970b$0$31552$426a74cc@news.free.fr>
	
	<7xwt4y6j57.fsf@ruckus.brouhaha.com>
	
Message-ID: <457ed6e7$0$8747$ed2619ec@ptn-nntp-reader02.plus.net>

Andr? Thieme wrote:
>> Contrast the much more common
>> 
>>   a[i] = b[n]
>> 
>> with
>> 
>>   (setf (aref a i) (aref b n))
>> 
>> and the attractions of Python may make more sense.
> 
> Here Python and Lisp are equal, 7 tokens vs 7 tokens, but in Python
> one has to write less since "[]" are 2 chars while "aref" are 4, plus
> the setf.

Why are you not counting Lisp's superfluous parentheses but you are counting
the brackets in the Python? I get 9 tokens for Python vs 13 for Lisp.

> But from counting the brain units which I regard as an important factor
> they are both equal.

Python is clearly more succinct in this case. I also think it is worth
counting chars or LOC as well as tokens. Lisp has unnecessarily long
built-in tokens...

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet


From timr at probo.com  Sat Dec 16 02:42:37 2006
From: timr at probo.com (Tim Roberts)
Date: Sat, 16 Dec 2006 07:42:37 GMT
Subject: Over my head with descriptors
References: <1166119871.508417.239060@n67g2000cwd.googlegroups.com>
Message-ID: 

"Sarcastic Zombie"  wrote:
>
>Code included below.
>
>Basically, I've created a series of "question" descriptors, which each
>hold a managed value. This is so I can implement validation, and render
>each field into html automatically for forms.
>
>My problem is this: every instance of my "wizard" class has unique self
>values, but they share the exact same descriptor values.
>
>...
>class Test(Wizard):
>	grouping = [
>		[ 'age', 'weight' ],
>		[ 'feet', 'inches' ],
>		['name', 'cash', 'fav_color', 'happy', 'birthday'] ]
>
>	def __new__(self):
>		age = Q_Integer("Your Age:", "age", 99)
>		weight = Q_Integer("Your Weight:", "weight", 200)
>		feet = Q_Integer("Feet tall:", "feet", 6)
>		inches = Q_Integer("Inches Tall:", "inches", 0)
>		name = Q_Chars("Your Name:", "name", max_length=15, required=True)
>		cash = Q_Float("Money in hand?", "cash", required=True,
>default=55.50)
>		fav_color = Q_Chars("Your favorite color?", "fav_color",
>required=True, max_length=50, choices=C_CHOICES)
>		homezip = Q_Zip("Your zip code?", "homezip", required=True, )
>		happy = Q_Bool("Are you happy?", "happy", default=False)
>		birthday = Q_Date("Your Birthday:", "birthday")

The __new__ method is called with the CLASS as its first argument, not the
new instance.  __new__ is supposed to RETURN the new instance.  So, when
you set "age", you are setting a CLASS attribute that will be shared by all
instances.

Is there a reason you don't just use __init__ instead of __new__, and use
"self.age" and "self.weight" and so on?
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.


From rpdooling at gmail.com  Mon Dec 11 10:22:51 2006
From: rpdooling at gmail.com (BartlebyScrivener)
Date: 11 Dec 2006 07:22:51 -0800
Subject: How do I edit a PythonWin path to import custom built modules???
In-Reply-To: <1165834567.956266.24480@j72g2000cwa.googlegroups.com>
References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com>
Message-ID: <1165850571.131438.185940@l12g2000cwl.googlegroups.com>

mohan wrote:

> I had created my own modules (.py files) in
> drives and folders other than the python root.

Probably easiest if you keep them all in one place. Then add that
"place" to your path by going into Control
Panel|System|Advanced|Environment Variables and adding the path to the
path variable.

Hope that helps.

rd



From caleb.hattingh at gmail.com  Tue Dec 12 18:48:48 2006
From: caleb.hattingh at gmail.com (Caleb Hattingh)
Date: 12 Dec 2006 15:48:48 -0800
Subject: And now for something completely different...
Message-ID: <1165967328.030329.311690@n67g2000cwd.googlegroups.com>

I spent way too much time reading the recent massive ">500-messages"
thread, and then spent even more time (perhaps better spent) reading
wider on some aspects of the debate.

This recently-found link sets out (from one possibly-biased POV, I
guess) how the rift between GNU Emacs and XEmacs occurred:

http://www.jwz.org/doc/lemacs.html

After reading the page, and in light of much of the
"your-syntax-is-obscure/mine-is-clear/easy-to-read/hard-to-read"
discussion on said ">500-messages" thread, I found the last line on the
above lemacs.html page very funny, and wanted to share it.

Not saying that such a thing couldn't ever be said about some given
implementation of something complex in python (or any language, for
that matter), but I still had a good chuckle.

Caleb



From Holger.Joukl at LBBW.de  Wed Dec 13 05:56:32 2006
From: Holger.Joukl at LBBW.de (Holger Joukl)
Date: Wed, 13 Dec 2006 11:56:32 +0100
Subject: inconvenient unicode conversion of non-string arguments
In-Reply-To: 
Message-ID: 

python-list-bounces+holger.joukl=lbbw.de at python.org schrieb am 13.12.2006
11:37:03:

> Holger Joukl wrote:
>
> > Ok, but I still don't see why these arguments shouldn't simply be
silently
> > ignored
>
>  >>> import this
>
> 
>

You probably refer to "Explicit is better than implicit.".
In that particular case I still think it wouldn't hurt
to allow the encoding/errors arguments to keep the unicode()
signature consistent for all types of the first argument.

I'd go with "Although practicality beats purity."
;-)

Holger
(But maybe I'm not aware of tricky-implementation issues...)

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde,
verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht
gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.




From fredrik at pythonware.com  Sun Dec 24 06:07:11 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Sun, 24 Dec 2006 12:07:11 +0100
Subject: Connection python with C
In-Reply-To: <66b602900612240237t3ba7cb71lc859f55d1d2f143c@mail.gmail.com>
References: <66b602900612240237t3ba7cb71lc859f55d1d2f143c@mail.gmail.com>
Message-ID: 

???????? ?????? wrote:

> I want to connect a script in python with a source code in C. Any
> ideas about it?

http://docs.python.org/lib/module-ctypes.html
http://docs.python.org/ext/ext.html
http://effbot.org/pyfaq/extending-index.htm





From vo.sinh at gmail.com  Wed Dec 20 12:47:41 2006
From: vo.sinh at gmail.com (Michele)
Date: Wed, 20 Dec 2006 18:47:41 +0100
Subject: perl better than python for users with disabilities?
In-Reply-To: <87slfalf8h.fsf@jidanni.org>
References: <87slfalf8h.fsf@jidanni.org>
Message-ID: 

What about indenting with a single space?
This does not seem a problem to me, even on tiny tiny screens =)

On 12/20/06, Dan Jacobson  wrote:
>
> Can I feel even better about using perl vs. python, as apparently
> python's dependence of formatting, indentation, etc. vs. perl's
> "(){};" etc. makes writing python programs perhaps very device
> dependent. Whereas perl can be written on a tiny tiny screen, and can
> withstand all kinds of users with various disabilities, etc.?
> Also perl is easier to squeeze into makefiles.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From tjgolden at gmail.com  Fri Dec 15 11:50:21 2006
From: tjgolden at gmail.com (Tim Golden)
Date: 15 Dec 2006 08:50:21 -0800
Subject: I'm looking for an intelligent date conversion module
In-Reply-To: <1166199318.637236.256190@t46g2000cwa.googlegroups.com>
References: <1166199318.637236.256190@t46g2000cwa.googlegroups.com>
Message-ID: <1166201418.615810.149160@79g2000cws.googlegroups.com>

mthorley wrote:
> Greetings, I'm looking for a python module that will take a datetime
> obj and convert it into relative time in english.
> For example: 10 minutes ago, 1 Hour ago, Yesterday, A few day ago, Last
> Week, etc

For the very little it's worth, I offer the following:

http://timgolden.me.uk/python/datediff.py

It doesn't do everything you want, but it should
be a starting point.

TJG



From juanrgonzaleza at canonicalscience.com  Sat Dec 16 12:58:33 2006
From: juanrgonzaleza at canonicalscience.com (Juan R.)
Date: 16 Dec 2006 09:58:33 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom>
References: <4ubu3nF16kv7aU1@mid.individual.net>
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net> 
	 <4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
	<4uhl7cF108ri8U2@mid.individual.net>
	
	<7xslfgou14.fsf@ruckus.brouhaha.com>
	<2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom>
Message-ID: <1166291913.321725.20950@16g2000cwy.googlegroups.com>

Using LISP-like syntax for everything would be so stupid as using
quantum mechanics for billiards.

Claiming that LISP parens are Stupid, Superfluous, or Silly just
because you do not need them in your limited field of discourse, would
be so stupid as those people thinking that just because they use
classical mechanics at the macro scale and works for them, then
classical mechanics would also work at the atomic scale [*].

[*] Even today, after 100 years some people think that quantum
mechanics is Stupid, Superfluous, or Silly and some classical
formulation will replace.



From google at mrabarnett.plus.com  Fri Dec 22 18:06:28 2006
From: google at mrabarnett.plus.com (MRAB)
Date: 22 Dec 2006 15:06:28 -0800
Subject: Problem in using Pulp
In-Reply-To: 
References: <1166759609.366064.124360@f1g2000cwa.googlegroups.com>
	
	<1166761918.461234.167610@h40g2000cwb.googlegroups.com>
	
Message-ID: <1166828788.439508.291820@48g2000cwx.googlegroups.com>


Robert Kern wrote:
> amitsoni.1984 at gmail.com wrote:
> > Thanks, now I am not getting that error, but now I am getting a
> > different error:
> > ---------------------error-------------------------------
> >    GLPK("C:\Documents and
> > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
> >   File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114,
> > in solve
> >     return lp.solve(self)
> >   File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line
> > 1740, in solve
> >     status = solver.actualSolve(self)
> >   File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188,
> > in actualSolve
> >     raise "PuLP: cannot execute "+self.path
> > PuLP: cannot execute C:\Documents and
> > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples"
> > -------------------------------------------------------------
> > can anyone tell me where the problem is? I am using following code.
>
> > GLPK("C:\Documents and
> > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
>
> The last character in that string is a double quote. You don't want that. What
> you want to do is escape all of the backslashes (or use raw strings to avoid the
> escaping altogether). E.g.
>
>    "C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\"
>
> or
>
>    r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\"
>
The second example won't work: you can't have a final backslash in a
raw string!



From hg at nospam.org  Mon Dec 11 14:25:00 2006
From: hg at nospam.org (hg)
Date: Mon, 11 Dec 2006 13:25:00 -0600
Subject: merits of Lisp vs Python
References: 
Message-ID: 

Michael.Coll-Barth at VerizonWireless.com wrote:

> 
> After 394 postings in this thread, you all have convinced me.  I am
> dropping all of my python code and switching to Lisp.
> 
> thank-you
> 
> 
> The information contained in this message and any attachment may be
> proprietary, confidential, and privileged or subject to the work
> product doctrine and thus protected from disclosure.  If the reader
> of this message is not the intended recipient, or an employee or
> agent responsible for delivering this message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify me
> immediately by replying to this message and deleting it and all
> copies and backups thereof.  Thank you.

Welcome



From Benjamin.Barker at gmail.com  Fri Dec 22 19:35:37 2006
From: Benjamin.Barker at gmail.com (Ben)
Date: 22 Dec 2006 16:35:37 -0800
Subject: Spyce vs mod_python PSP
Message-ID: <1166834137.313625.245860@73g2000cwn.googlegroups.com>

Hi,

I have just tarted trying to transfer some of my knowledge of python to
server side applications. I stated off using mod_python PSP because it
was what I found first. I then found spyce, which seems a better
solution. It avoids the problem of keeping indentation correct when
writing code embedded in HTML, and seems to make things like dealing
with forms simpler. Having said that it doesn't seem to appear in the
standard ubuntu repositories, while mod_python PSP does,which would
seemto be a vote against it?

What do peopl here think? Any suggestions?

Cheers (and happy christmas),

Ben



From stuart at bmsi.com  Sat Dec 16 10:28:06 2006
From: stuart at bmsi.com (Stuart D. Gathman)
Date: Sat, 16 Dec 2006 10:28:06 -0500
Subject: Package vs. module
References: 
	<1165642541.222433.162640@l12g2000cwl.googlegroups.com>
	
	
Message-ID: 

On Mon, 11 Dec 2006 20:59:27 -0300, Gabriel Genellina wrote:

> The above code *almost* works, but DNSLookup is a local name inside 
> the function. Use the global statement.
> As an example, see how getpass.py (in the standard library) manages 
> the various getpass implementations.

Ok, I have a working package:

spf/
  __init__.py
  pyspf.py
  pydns.py
  dnspython.py

__init__.py:
from pyspf import *
from pyspf import __author__,__email__,__version__ 

def set_dns_driver(f):
  global DNSLookup
  DNSLookup = f
  pyspf.DNSLookup = f

def DNSLookup(name,qtype,strict=True):
  import pydns
  return DNSLookup(name,qtype,strict)

set_dns_driver(DNSLookup)

Importing a driver module activates that driver.
For instance, in pydns.py:

import DNS    # http://pydns.sourceforge.net
import spf

...
def DNSLookup(...):
  ...

spf.set_dns_driver(DNSLookup)

NOW, this is all very nice and modular. BUT, the original module was a
single file, which could be run as a script as well as imported as a
module. The script features provided useful command line functionality.
(Using if __name__ == '__main__':).  Now that 'spf' is a package, the
command line feature is gone!  Even using -m, I get:

python2.4 -m spf
python2.4: module spf has no associated file

Looking at getpass.py as advised, I see they put all the drivers in the
module.  I could do that with spf.py, I suppose.  But I like how with the
package, the driver code is not loaded unless needed.

One other idea I had was an arrangement like this:

SPF/
  pydns.py
  dnspython.py

spf.py

This would keep the module as a single file usable from the command line,
but still make driver available as separately loaded modules.

So which of the three options,

1) single file module with all drivers, ala getpass
2) package that cannot be run directly from command line
3) single file module with associated driver package

is the most pythonic?


-- 
	      Stuart D. Gathman 
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.



From daniel.dittmar at sap.com  Thu Dec  7 08:49:34 2006
From: daniel.dittmar at sap.com (Daniel Dittmar)
Date: Thu, 07 Dec 2006 14:49:34 +0100
Subject: Common Python Idioms
In-Reply-To: 
References: 
	<17783.32458.730462.8403@montanaro.dyndns.org>
	
	<1165493298.205945.162430@n67g2000cwd.googlegroups.com>
	
Message-ID: 

Duncan Booth wrote:
> In this case, dict objects used to not support the 'in' operator, but at 
> some point it was added. I believe it wasn't there originally because Guido 
> wasn't sure whether people would expect it should match keys or keys and 
> values.

And he was right:

import sys
'sys' in sys.modules => True
sys in sys.modules => False

Doesn't this look wrong?

Daniel


From gbrunick at andrew.cmu.edu  Wed Dec  6 16:53:00 2006
From: gbrunick at andrew.cmu.edu (Gerard Brunick)
Date: Wed, 06 Dec 2006 16:53:00 -0500
Subject: Where does a class closure live?
Message-ID: <45773BBC.5020301@andrew.cmu.edu>

Consider:

###  Function closure example

def outer(s):
...     def inner():
...         print s
...     return inner
...
 >>> f = outer(5)
 >>> f()
5
 >>> dir(f)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', 
'__get__', '__getattribute__', '__hash__', '__init__', '__module__', 
'__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 
'func_dict', 'func_doc', 'func_globals', 'func_name']

###  Class instance closure example

 >>> def outer2(s):
...     class Inner(object):
...         def __call__(self):
...             print s
...     return Inner()
...
 >>> f = outer2(10)
 >>> f()
10
 >>> dir(f)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', 
'__getattribute__', '__hash__', '__init__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 
'__weakref__']

##### Class closure example

 >>> def outer3(s):
...     class Inner(object):
...         def __call__(self):
...             print s
...     return Inner
...
 >>> F = outer3(15)
 >>> f = F()
 >>> f()
15
 >>> dir(F)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', 
'__getattribute__', '__hash__', '__init__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 
'__weakref__']


Now the closure for the function live in func_name.   I've even done the 
exercise where I build a dummy  inner function that returns its closed 
variable, so that I can use that thing to reach through "cells" and 
check out the variables living in the closure object.  Where are the 
closure variables for the class instance, and the class?  Can I get my 
hands on them in Python?
-Gerard


From udodenko at users.sourceforge.net  Fri Dec  8 11:52:15 2006
From: udodenko at users.sourceforge.net (Alex Mizrahi)
Date: Fri, 8 Dec 2006 18:52:15 +0200
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	
	<45797a0c$0$49204$14726298@news.sunsite.dk>
	<1165593798.079105.144060@80g2000cwy.googlegroups.com>
Message-ID: <45799841$0$49201$14726298@news.sunsite.dk>

(message (Hello 'Kay)
(you :wrote  :on '(8 Dec 2006 08:03:18 -0800))
(

 KS> http://www.sbcl.org/manual/Handling-of-Types.html#Handling-of-Types

 KS> If you'd read the docs of the tools you admire you might find the
 KS> answers yourself.

SBCL is a COMPILER that explains everything. it's interesting why 
INTERPRETER like CLISP is faster.
well, it can be type declarations as well, but maybe something other too..

for example, in languages like Python, PHP and JavaScript, as i understand, 
by semantics of the language interpreter MUST use dict to call objects 
method -- at any time it can be changed, for any object instance. i'm not 
sure whether it has to dynamically resolve package's methods doing lookup in 
packages dict.

however, in Common Lisp object methods are dispatched on object types, that 
is a special language entity, so as long as new types are not introduced, 
interpreter can optimize calls how it wants to. the difference is that while 
it's still dynamic, dispatch over types are more controlled/optimizable than 
dispatch using dict.
then, symbols in common-lisp package cannot be changed according to spec, 
thus compiler/interpreter is safe to do optimizations it wants when sees 
that symbols (if we want symbols with same names, we can make other package 
with them).

then, Common Lisp standard defines what inlining is. i bet most 
optimizations in dynamic languages are not possible if inlining is not 
enabled -- since any symbol that is not inlined can change it's meaning in 
any time.

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 




From nmm1 at cus.cam.ac.uk  Tue Dec 19 13:58:19 2006
From: nmm1 at cus.cam.ac.uk (Nick Maclaren)
Date: 19 Dec 2006 18:58:19 GMT
Subject: tuple.index()
References: 
	<1166104987.884566.126710@n67g2000cwd.googlegroups.com>
	
	<1166106278.106832.278240@n67g2000cwd.googlegroups.com>
	
	
	
	
	
	  
Message-ID: 


In article ,
"J. Clifford Dyer"  writes:
|> 
|> On the contrary, I think that example fits perfectly with my definition
|> of homogenous.  If there is no constraint on position, then what is the
|> position determinative of?  Order in the queue.  Nothing more.  By my
|> definition, homogeneous.  QED.
|> 
|> I'll grant, it's not exactly the most intuitive definition of
|> homogenous, but I think it is the most accurate for this situation.
|> Perhaps homogenous and heterogenous aren't the best possible words here,
|> but I think they work.

Grrk.  I see what you mean.  The homogeneity is referring to the order
and not to the types :-)

|> By my definition, how can it be mutable AND heterogenous?  If the first
|> element is a name, the second element is a phone number, and the third
|> element is an email address, and you insert an element in between the
|> first two elements, do you mean to tell me that the phone number, which
|> has moved to the third slot, is now an email address?  It doesn't make
|> sense.

Well, I could provide an example, but they are a bit weird.  More
seriously, consider changing a structure consisting of a name and
telephone number, and then changing the value of the latter (not
exactly an unreasonable requirement!)  With tuples that can't be done,
but it makes perfect sense, and it is a mutable heterogeneous sequence
with your definition.
 
|> Maybe the words are wrong.  I'm not sure.  But I think the distinction
|> is valid.  Furthermore, I think we "lists are intended to be homogenous"
|> people would say that you are perfectly welcome to use lists for other
|> purposes, if it suits you.  Just as you can use a string as a list.  We
|> don't have to be rigid to appreciate the difference.  :)

Nope.  That is DEFINITELY wrong.  If you write code that abuses a
language construct in a way that is discouraged but just happens to
work, a couple of decades down the line it will stop working, because
someone will change the feature.  Been there - been caught by that :-(


Regards,
Nick Maclaren.


From S.Mientki-nospam at mailbox.kun.nl  Fri Dec 29 17:14:19 2006
From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki)
Date: Fri, 29 Dec 2006 23:14:19 +0100
Subject: Wow, Python much faster than MatLab
Message-ID: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl>

hi All,

instead of questions,
my first success story:

I converted my first MatLab algorithm into Python (using SciPy),
and it not only works perfectly,
but also runs much faster:

MatLab: 14 msec
Python:  2 msec

After taking the first difficult steps into Python,
all kind of small problems as you already know,
it nows seems a piece of cake to convert from MatLab to Python.
(the final programs of MatLab and Python can almost only be 
distinguished by the comment character ;-)

Especially I like:
- more relaxed behavior of exceeded the upper limit of a (1-dimensional) 
  array
- much more functions available, like a simple "mean"
- reducing datatype if it's allowed (booleans of 1 byte)

thanks for all your help,
probably need some more in the future,
cheers,
Stef Mientki


From joel.wilsson at gmail.com  Sun Dec 10 12:23:14 2006
From: joel.wilsson at gmail.com (Joel Wilsson)
Date: 10 Dec 2006 09:23:14 -0800
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165594621.136524.198600@80g2000cwy.googlegroups.com>
	
	<1165596641.245385.113090@f1g2000cwa.googlegroups.com>
	
	
	<1165704007.887869.192290@16g2000cwy.googlegroups.com>
	
	<87ejr7yhgv.fsf@snobis.de>
	
Message-ID: <1165771394.452028.261260@l12g2000cwl.googlegroups.com>

Steven D'Aprano wrote:
> On Sun, 10 Dec 2006 15:05:04 +0100, Stefan Nobis wrote:
> > Ever talked to skateboarders? Other people of different scenes? They
> > are creating new, specialized languages every day.
>
> Yes, that's right. And if they insist on using their specialist language
> where "that's bad" means "that is best quality", and I insist on using
> my language where "that's bad" means "that is worst quality", how much
> successful communication are we going to have?

Having such a specialist language, which goes against common
practice, would be stupid. There nothing to gain from doing so,
so it's not done.

The same is true for macros. Redefining everything and programming
in your own special way just to be different would be stupid, and
it's not done.
Everyone keeps telling you this but you keep ignoring it.

Wonder why.

Macros are used where they must be used, to do things that are not
possible with functions. Functions have benefits that macros don't
have, and for most things (but not all things), those benefits are
more useful than the benefits provided by macros.

I will also note that Ken Tilton was right about analogies, and
far too much of this discussion is now about English language, not
the merits of Lisp vs Python. Sad, because there is some good
stuff in here.



From not at valid.com  Wed Dec 27 09:50:18 2006
From: not at valid.com (yomgui)
Date: Wed, 27 Dec 2006 14:50:18 GMT
Subject: how can I modify an imported variable ?
Message-ID: 

I've tried this:

import MyPackage
if MyPackage.aVariable is None:
     MyPackage.aVariable = True

but when I tried to access MyPackage.aVariable from another file
(ie through an other import) the value is still None.


how can I do this

thanks

yomgui


From anthonybaxter at gmail.com  Sat Dec 30 05:43:22 2006
From: anthonybaxter at gmail.com (Anthony Baxter)
Date: Sat, 30 Dec 2006 21:43:22 +1100
Subject: Python 2.4.4 vs. 2.3.6
In-Reply-To: <1167271370.527125.197900@h40g2000cwb.googlegroups.com>
References: <1167271370.527125.197900@h40g2000cwb.googlegroups.com>
Message-ID: 

On 27 Dec 2006 18:02:50 -0800, sndive at gmail.com  wrote:
> My top priority is stability of the interpreter. With that in mind
> which version should I get: 2.4.4, 2.3.6
> or something else.
>
> I will be using gcc 2.3.2(x86), 3.3(arm) and 3.4.3(arm) to cross
> compile it depending on the (embedded) platform.

I'd recommend 2.4.4 over 2.3.6. 2.4 hasn't got much in the way of
major likely-to-cause-bugs changes over 2.3, and it's had a heck of a
lot more time to have bugs fixed. Once 2.4(.0) came out, work on the
2.3 maintenance series effectively stopped in favour of working on the
2.4 series. There's been a lot of bugs fixed since then that weren't
applied back to 2.3. See the 2.4.4 release notes, available at the
2.4.4 webpage, for more.

Anthony


From jan.dries at dcube-resource.be  Mon Dec 11 22:53:46 2006
From: jan.dries at dcube-resource.be (Jan Dries)
Date: Tue, 12 Dec 2006 04:53:46 +0100
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>	<1165769504.098173.101860@j72g2000cwa.googlegroups.com>	<4u4qo3F15uds8U1@mid.individual.net>		<7xd56qbgx7.fsf@ruckus.brouhaha.com>		<7xwt4yju5e.fsf@ruckus.brouhaha.com>
		<7x1wn57voq.fsf@ruckus.brouhaha.com>
	
Message-ID: <457E27CA.8010406@dcube-resource.be>

Robert Brown wrote:
> Paul Rubin  writes:
>> Espen Vestre  writes:
>>>> Can you redefine CLOS methods without calling CLOS functions that tell
>>>> the object system what to expect (so it can do things like update the
>>>> MRO cache)?  I.e. can you redefine them by poking some random
>>>> dictionary?  You can in Python.  I don't claim that's a good thing.
>>> Just as I said: Less managable, but not more dynamic.
>> I'm not getting through to you.  Yes, you could create a Python-like
>> object system in Lisp that's separate from CLOS, but nobody would use
>> it ....
> 
> I think you are not understanding the point that Espen is trying to make.
> He is not suggesting a different object system for Lisp.
> 
> Espen is saying that Common Lisp often offers the same dynamic feature as
> Python has, such as the ability to redefining a method at runtime.  Lisp,
> however, forces you to call a CLOS function or use an well defined interface
> when redefining a method.  You can't just change a value in a hash table.
> Does this make Lisp "less dynamic" than Python?  Espen would say it's not
> less dynamic, but rather that a similar level of dynamism is achieved in
> Common Lisp via well defined interfaces.  The compiler knows the interfaces,
> so it can do a better job optimizing the code.

Isn't that the same as saying "less dynamic" by the very meaning of the 
word in this context? The more the compiler knows or can deduce at 
compile time, the more static. At least that has always been my view on it.

Regards,
Jan



From cito at online.de  Fri Dec 15 07:18:52 2006
From: cito at online.de (Christoph Zwerschke)
Date: Fri, 15 Dec 2006 13:18:52 +0100
Subject: tuple.index()
In-Reply-To: 
References: 	<1166104987.884566.126710@n67g2000cwd.googlegroups.com>		<1166106278.106832.278240@n67g2000cwd.googlegroups.com>						
	
Message-ID: 

Maybe there would be less dispute if this dogma/convention(?) "Tuples 
are for heterogeneous data, list are for homogeneous data" would be 
written down somewhere in the tutorial, reference or in PEP8, so people 
would be aware of it.

And can somebody explain what is exactly meant with "homogenous data"? 
That the type of the elements is the same in some technical or 
philosophical meaning? Concretely speaking, which data type should I use 
for coordinate tuples? Usually, tuples are used. Does this mean that I 
should better use lists from now on because all the components have the 
same type?

-- Christoph


From nagle at animats.com  Wed Dec 13 18:00:36 2006
From: nagle at animats.com (John Nagle)
Date: Wed, 13 Dec 2006 23:00:36 GMT
Subject: Obtaining SSL certificate info from SSL object - proposal
In-Reply-To: 
References: <453D95EA.1020602@animats.com> 
	
Message-ID: 

John Nagle wrote:
> Michael Str?der wrote:
> 
>> John Nagle wrote:
>>
>>>    The Python SSL object offers two methods from obtaining
>>> the info from an SSL certificate, "server()" and "issuer()".
>>> The actual values in the certificate are a series of name/value
>>> pairs in ASN.1 binary format.  But what "server()" and "issuer()"
>>> return are strings, with the pairs separated by "/".  The
>>> documentation at "http://docs.python.org/lib/ssl-objects.html"
>>> says "Returns a string containing the ASN.1 distinguished name
>>> identifying the server's certificate. (See below for an example showing
>>> what distinguished names look like.)"  There is, however, no "below".

    Since I really need this, I'm looking at modifying the Python SSL
interface to SSL objects by adding a function "certificate()" which
returns an X.509 certificate in the following format:

	SSL certificates are trees, represented in a format, "ASN.1", which
	allows storing numbers, strings, and flags.
	Fields are identified by names or by assigned "OID numbers"
	(see RFC 2459).

	The tree is returned as tuples.  The first element of the tuple
	is always a string giving the name of the field, and the second
	element is a string, Boolean, or number giving the value, or
	a list of more tuples.  The result is a tree, which will
	resemble the tree typically displayed by browsers displaying
	SSL certificates.

	The top tuple's field name is the domain for which the certificate
	applies.

	Note that it is straightforward to implement "issuer" and "subject"
	using "certificate", which provides a way out of the current problems
	with those fields.

	Example:

(   'www.google.com',
     (   'Certificate',
         [   ('Version', 3),
             (   'Serial Number',
                 '4B:A5:AE:59:DE:DD:1C:C7:80:7C:89:22:91:F0:E2:43'),
             (   'Certificate Signature Algorithm',
                 'PKCS #1 MD5 With RSA Encryption'),
             (   'Issuer',
                 [   ('CN', 'Thawte SGC CA'),
                     ('O', 'Thawte Consulting (Pty) Ltd.'),
                     ('C', 'ZA')]),
             (   'Validity',
                 [   ('Not Before', '5/15/2006 23:18:11 PM GMT'),
                     ('Not After', '5/15/2007 23:18:11 PM GMT')]),
             (   'Subject',
                 [   ('CN', 'www.google.com'),
                     ('O', 'Google Inc'),
                     ('L', 'Mountain View'),
                     ('ST', 'California'),
                     ('C', 'US')]),
             (   'Subject Public Key Info',
                 [   (   'Subjects Public Key Algorithm',
                         'PKCS #1 RSA Encryption'),
                     (   'Subjects Public Key',
                         '30 81 89 02 81 81 00 e6 c5 c6 8d cd 0b a3 03 
04dc ae cc 			c9 46 be bd cc 9d bc 73 34 48 fe d3 7564 d0 c9 c9 7
6 27 72 0f a9 96 1a 3b 81 f3 14 f6ae 90 56 e7 19 d2 73
68 a7 85 a4 ae ca 24 14 3000 ba e8 36 5d 81 73 3a 71 05 8f b1 af 11 87 da5c f
1 3e bf 53 51 84 6f 44 0e b7 e8 26 d7 2f b26f f2 f2 5d df a7 cf 8c a5 e9 1e 6f 
30 48 94 210b 01 ad ba 0e 71 01 0d 10 ef bf ee 2c d3
8d fe54 a8 fe d3 97 8f cb 02 03 01 00 01')]),
             (   'Certificate Signature Algorithm',
                 'PKCS #1 MD5 With RSA Encryption'),
             (   'Certificate Signature Value',
                 '57 4b bc a4 43 e7 e0 01 92 a0 96 35 f9 18 08 881d 7b 70 19 8f 
f9 36 b2 05 3a 05 ca 14 59 4d 240e e5 8a af 4e 87 5a
f7 1c 2a 96 8f cb 61 40 9ed2 b4 38 40 21 24 c1 4f 1f cb 13 4a 8f 95 02 df91 3d 
d6 40 eb 11 6f 9b 10 a1 6f ce 91 5e 30 f66d 13 5e 15
a4 2e c2 18 9e 00 c3 d8 32 67 47 fcb8 1e 9a d9 9a 8e cc ff 7c 12 b7 03 bf 52 20 
cf21 f4 f3 77 dd 12 15 f0 94 fa 90 d5 e3 59 68 81')]
))

     Comments?

				John Nagle




From fredrik at pythonware.com  Wed Dec 20 14:39:52 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Wed, 20 Dec 2006 20:39:52 +0100
Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects
In-Reply-To: 
References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com>
	
Message-ID: 

Fredrik Lundh wrote:

>      while Townshps is not None:

or rather,

     while Townshp is not None:

since that's the variable you're using later on.





From martin at v.loewis.de  Wed Dec  6 13:50:22 2006
From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=)
Date: Wed, 06 Dec 2006 19:50:22 +0100
Subject: No latin9 in Python?
In-Reply-To: 
References: 
Message-ID: <457710EE.4090704@v.loewis.de>

Christoph Zwerschke schrieb:
> Is there anything speaking against adding these as aliases? If no, I
> would submit a patch. (Also, Python does not support the
> latin10=iso8859-16 charset. I could try to add that as well.)

Python tries to follow the IANA charset registry.

http://www.iana.org/assignments/character-sets

If you submit a patch, it would be good if you checked all names and
determined which aliases are missing.

While you are at it, you'll notice that the current version of the
character-sets database lists

Name: ISO-8859-15
MIBenum: 111
Source: ISO
        Please see:

Alias: ISO_8859-15
Alias: Latin-9

so the "official" alias is "Latin-9", not "latin9". You may
want to ask the submitter of that entry why this inconsistency
was introduced.

Regards,
Martin


From http  Mon Dec 11 19:40:52 2006
From: http (Paul Rubin)
Date: 11 Dec 2006 16:40:52 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	
	<%TBeh.331$tv5.155@newsfe11.lga>
	
	
	
	
	
	<7xfybnjkz4.fsf@ruckus.brouhaha.com>
	
	
	<457d970b$0$31552$426a74cc@news.free.fr>
	
Message-ID: <7xwt4y6j57.fsf@ruckus.brouhaha.com>

Andr? Thieme  writes:
> > import module
> > module.function = memoize(module.function)
> 
> Yes, I mentioned that a bit earlier in this thread (not about the
> "during runtime" thing).
> I also said that many macros only save some small bits of code.
> Your python example contains 4 tokens / brain units.
> The Lisp version only has 2.

You shouldn't count the import statement, since you'd need the
equivalent in Lisp as well.

Contrast the much more common

  a[i] = b[n]

with

  (setf (aref a i) (aref b n))

and the attractions of Python may make more sense.


From rupole at hotmail.com  Fri Dec  1 09:02:52 2006
From: rupole at hotmail.com (Roger Upole)
Date: Fri, 1 Dec 2006 09:02:52 -0500
Subject: PythonWin And Excel Problem
References: 
Message-ID: <1164981991_16179@sp6iad.superfeed.net>

"Andrea Gavana"  wrote:
> Hi All,
>
>    I am having some problems in running a very simple python script,
> which prints some numbers in an Excel spreadsheet. The numbers are
> stored in a list. I know that the numbers are different (random
> generated), but when I open the Excel file I get a column of data with
> all the numbers equal to the first item in the python list.
> I attach a very simple script that reproduces the problem.
>
> I am using Python 2.5, PythonWin build 210, Windows XP. Am I missing
> something? Thank you for every hint.
>
> import os
> import random
>
> from win32com.client import Dispatch
>
> therand = []
> for ii in xrange(10):
>    therand.append(random.random())
>
> xlsapp = Dispatch("Excel.Application")
> wb = xlsapp.Workbooks.Add()
>
> xlsapp.Worksheets.Item(2).Delete()
> xlsapp.Worksheets.Item(1).Delete()
> sheet = wb.Sheets[0]
> sheet.Name = "Data"
> sheet.Range("A1:A10").Value = therand
>
> excelfile = "C:/HelloWin32.xls"
>
> wb.SaveAs(excelfile)
> wb.Close()
> xlsapp.Quit()
>
> os.startfile(excelfile)
>

Each row you insert into the Range need to be a
sequence:

therand.append((random.random(),))

        Roger




----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


From fredrik at pythonware.com  Fri Dec  8 12:16:17 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Fri, 08 Dec 2006 18:16:17 +0100
Subject: *** C.L.L README/FAQ *** (Was: merits of Lisp vs Python)
In-Reply-To: <1165597433.446903.305750@73g2000cwn.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165597433.446903.305750@73g2000cwn.googlegroups.com>
Message-ID: 

JShrager at gmail.com wrote:

> Sounds like it's time for:
> 
> A Beginners' Meta FAQ for comp.lang.lisp:
> 
>   http://nostoc.stanford.edu/jeff/llisp/cllfaq.html
> 
> The purpose of this page is to help those new to Lisp (aka. "newbies")
> gain some background before they enter the fray of comp.lang.lisp

so why are you posting this to comp.lang.python ?





From dwhall256 at gmail.com  Sun Dec 17 09:02:40 2006
From: dwhall256 at gmail.com (dwhall)
Date: 17 Dec 2006 06:02:40 -0800
Subject: Is there a way to push data into Ical from Python ?
In-Reply-To: <4584591b$0$29324$426a74cc@news.free.fr>
References: <4584591b$0$29324$426a74cc@news.free.fr>
Message-ID: <1166364160.192126.123420@n67g2000cwd.googlegroups.com>

You could save your calendar_ to a .ics file which is in the VCal_ file
format; but that requires the extra step of manually saving your
calendar to a file or accessing the files that iCal creates behind the
scenes in ~/Library/Application Support/iCal/Sources/ which is unclear
and potentially hazardous to your data.

I'm guessing you would prefer to access the calendar data directly from
the script, like an Applescript would.  One way would be to use
Python's tie-ins to Applescript_ and apple events (AE).  As you will
read, this support isn't as strong as it used to be.

Another idea that would require more effort, but earn you some hacker
points, is to use PyObjC_ and access iCal's public programming
interface.

But by far the easiest is to google for what you want (my search was
for: "ical api"), find the iCalModule_ and try to make that work for
you.  Although that module appears to only read the data and is
targeted toward 3rd-party calendars that are stored in
~/Library/Calendars.

share and enjoy,

!!Dean

.. _calendar: http://en.wikipedia.org/wiki/ICalendar
.. _VCal: http://en.wikipedia.org/wiki/VCal
.. _Applescript: http://pythonmac.org/wiki/AppleScript
.. _PyObjC: http://pyobjc.sourceforge.net/
.. _iCalModule: http://www.devoesquared.com/Software/iCal_Module

The Night Blogger wrote:
> Is there a way to pull & push data into (Apple Mac OS X Calendar) Ical from
> Python ?



From eadmund42 at NOSPAMgmail.com  Tue Dec 12 12:34:26 2006
From: eadmund42 at NOSPAMgmail.com (Robert Uhl)
Date: Tue, 12 Dec 2006 10:34:26 -0700
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<7xslfqar7v.fsf@ruckus.brouhaha.com>
	<1165623284.242403.295140@l12g2000cwl.googlegroups.com>
	<7xodqdj2dn.fsf@ruckus.brouhaha.com>
Message-ID: 

Paul Rubin  writes:
>> 
>> Sorry, I missed something here. Why do you need a release to have these
>> sorts of things? Can't you just expand the language via macros to
>> create whatever facility of this sort you need... 
>
> Huh?  Are you saying Lisp systems never release new versions?

The Common Lisp standard hasn't been updated in over a decade.
Moreover, one doesn't need to wait for a standard to add syntax--one
just adds it and gets on with solving the problem at hand.

> And you can't implement Python generators as Lisp macros in any
> reasonable way.

I'm pretty certain it could be done with conditions.

-- 
Robert Uhl 
We're going to Moe's.  If we're not back, avenge our deaths.
                                            --Homer Simpson


From klappnase at web.de  Tue Dec 19 11:52:55 2006
From: klappnase at web.de (klappnase)
Date: 19 Dec 2006 08:52:55 -0800
Subject: New os.path.exists() behavior - bug or feature?
In-Reply-To: <45867D04.8010300@v.loewis.de>
References: <1166401777.533652.208840@n67g2000cwd.googlegroups.com>
	<45867D04.8010300@v.loewis.de>
Message-ID: <1166547175.715504.259120@i12g2000cwa.googlegroups.com>


Martin v. L?wis schrieb:
>
> Neither, nor. In both cases, the operating system is asked, and gives
> this answer. However, in the Windows API, there is no "exists" function
> (nor is there on Unix); instead, exists is implemented by calling
> several underlying functions. The precise set of functions used did
> change between 2.4 and 2.5.
>
> It is quite difficult to investigate the precise nature of the change
> that leads to this change in observable behavior. If you think this is
> a bug, it would be best if you could also investigate a patch.
>

I don't know if it is a bug; at least it is backwards incompatible,
which I think is never a good thing.
Unfortunately, I am afraid writing a patch is beyond my expertise :(

Regards

Michael



From JShrager at gmail.com  Sun Dec 10 20:28:47 2006
From: JShrager at gmail.com (JShrager at gmail.com)
Date: 10 Dec 2006 17:28:47 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <1165793825.487994.52430@f1g2000cwa.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>
	<1165769504.098173.101860@j72g2000cwa.googlegroups.com>
	<1165793825.487994.52430@f1g2000cwa.googlegroups.com>
Message-ID: <1165800527.225633.84180@80g2000cwy.googlegroups.com>

> Python has to rely more on using the right algorithm...

This sound familiar: "Macros are dangerous!" "Compilers make you lazy."
"Worse is better!" (I have a Russian friend -- a mathematician -- who
jokes that the reason the Soviets were great mathematicians because
their computers sucked, so they had to use extensive formal
manipulation to get things to run fast enough to get anything done. He
was joking (I think); you don't appear to be.)

> Talk to these guys:
> http://en.wikipedia.org/wiki/PyPy they have an interesting take on

No, actually maybe you should talk to them since you seem to think that
making Python run fast is dangerous, or at least unnecessary.

> Python has this unsung module called doctest that neatly shows some of
> the strengths of python:   http://en.wikipedia.org/wiki/Doctest

Now I'm *certain* that you're just pulling my leg: You guys document
all your random ten-line hacks in Wikipedia?!?! What a brilliant idea!
Hey, you even have dead vaporware projects like uuu documented in
Wikipedia! Cool! (Actually, I don't know that doctest is ten lines in
Python, but it'd be about ten lines of Lisp, if that, so I'm just
guessing here.)



From snobis at gmx.de  Sun Dec 10 08:33:27 2006
From: snobis at gmx.de (Stefan Nobis)
Date: Sun, 10 Dec 2006 14:33:27 +0100
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
	<874ps423sx.fsf@thalassa.informatimago.com>
	
	
Message-ID: <87irgjyixk.fsf@snobis.de>

Steven D'Aprano  writes:

> Is that an argument against factory functions? Damn straight it is:
> they are a powerful tool, and in the hands of morons, they can be
> dangerous. Does that mean that languages shouldn't permit
> higher-order functions? Not necessarily: all programming tools can
> be misused, but some can be misused more easily than others. Power
> and risk is often a trade-off, and language designers can't
> eliminate all risk of stupid behaviour, but they can design the
> language to allow whatever level of risk they believe is
> acceptable. (E.g. there is no doubt that C's raw pointers are
> powerful, but many languages deliberately don't use them.)

I understand your point, I understand the Java folks. But I think this
point of view is really wrong. The right solution would be to better
train people, to give more good examples or even to not employ those,
who don't grasp it.

You point of view is that of (big) companies: Every developer should
be equal, exchangable. I'm very sure this is only an illusion. And I
think this point of view leads to many failures of (big)
projects. Each project has it's working horse(s) and these are quite
more equal than the others. :)

To deny the good developers, the working horses the power they need
isn't a good idea. Give them all the tools they need and let others
learn from them -- so (nearly) everybody becomes a good to great
developer.

Am I naive? Maybe...

> The risk of stupid factory functions is small compared to the
> benefit, but maybe there is some domain somewhere where the ideal
> solution is a language that DOESN'T treat functions as first class
> objects, deliberately weakening the language so that a particular
> class of errors (or stupid behaviour) just cannot happen.

And with Lisp macros the good developers may easily create these DSLs
to be used by the not so good developers. :)

> That's the perspective of many people, and maybe it is wrong. Maybe
> you really need to be immersed in Lisp for a while to see the
> advantages of macros.

Yes, I think this perspective is wrong. Some time ago I wondered about
the hype of LinQ -- with Lisp macros it's already there. These things,
embedded languages (like embedded SQL, embedded Prolog, ...) are
really great. I also hate the amount of boilerplate code nesseccary in
Java -- yes, in Python it's muss less, but in Lisp it really vanished.

If you use a really good designed language which don't assume every
programmer to be dumb and equal, yes, maybe macros would be not that
big a bonus. But hey, they are not worse than operator overloading and
the like, so why not include them? (Answer: In most cases it's hard to
add macros because of non-homogenous syntax.) :)

-- 
Stefan.


From robin at reportlab.com  Thu Dec 28 10:35:40 2006
From: robin at reportlab.com (Robin Becker)
Date: Thu, 28 Dec 2006 15:35:40 +0000
Subject: per interpreter storage for C extensions
Message-ID: <4593E44C.9000502@chamonix.reportlab.co.uk>

As part of some django usage I need to get some ReportLab C extensions into a 
state where they can be safely used with mod_python.

Unfortunately we have C code that seems incompatible with mod_python and I'm 
looking for ways to improve the situation.

Basically the main things that are wrong are all privately cached copies of 
python variables. This sample code


static PyObject *_pdfmetrics_fonts = NULL;
static PyObject *_pdfmetrics_ffar = NULL;

..........
     if(!_pdfmetrics_fonts){
         res = PyImport_ImportModule("reportlab.pdfbase.pdfmetrics");
         if(!res) ERROR_EXIT();
         _o1 = _GetAttrString(res,"_fonts");
         if(!_o1) ERROR_EXIT();
         _o2 = _GetAttrString(res,"findFontAndRegister");
         if(!_o2) ERROR_EXIT();
         _pdfmetrics_fonts = _o1;
         _pdfmetrics_ffar = _o2;
         Py_DECREF(res); _o1 = _o2 = res = NULL;
         }
     if((res = PyObject_GetItem(_pdfmetrics_fonts,fontName))) return res;
...........

illustrates the general problem. If called first by interpreter A I'll get the 
values from interpreter A. When later called by interpreter B I'll be using the 
wrong values and _pdfmetrics_ffar can alter the wrong interpreter's data.


The functions themselves are fairly small, but may be called many times so 
they're worth speeding up.

Is there a simple/cheap way for C code to cache these sorts of module level 
globals on a per interpreter basis? Is there even a way to tell which 
interpreter I'm being called in?

Anything too costly will probably bust any speedup. Luckily I don't think we 
have too many of these cached variables so it's possible we may be able to get 
away with just dropping the caching for some and eliminating others.
-- 
Robin Becker



From sjmachin at lexicon.net  Thu Dec  7 02:11:55 2006
From: sjmachin at lexicon.net (John Machin)
Date: 6 Dec 2006 23:11:55 -0800
Subject: Why not just show the out-of-range index?
References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com>
	
	<1165267626.293073.288180@79g2000cws.googlegroups.com>
	
	<1165298691.474503.184480@16g2000cwy.googlegroups.com>
	
Message-ID: <1165473561.314640.247010@j72g2000cwa.googlegroups.com>

OKB (not okblacke) wrote:
> John Machin wrote:
>
> > Can you give a real example from your code where the location of
> > such a human error (you cause a variable to bound to a value of
> > inappropriate type) would be difficult to find, plus an estimate of
> > how often you would make such an error?
>
>     	Here is an example:
>
> self.outFile.write(str(len(self.hits)) + ' in ' + searchInfo.recordName
> + '\t' + ']['.join((a. group() for a in self.hits)) + '\n')
>
>     	This is from a text-searching tool I have written to search
> linguistic corpora.  This statement writes a summary line to the output
> file indicating how many hits were found in that file.
>
>     	The problem in this line was that I'd forgotten to put str() around
> the len().  Now, it's not impossible to find the problem, because given
> my knowledge of the program I know that that's the only part of the line
> that would reasonably contain the number, but I still think it would be
> a lot easier if there were a caret in the error message pointing to the
> offending summand.

It should be extremely easy (rather than "not impossible") for anybody
with half a clue to find the problem given only the offending statement
(rather than your "knowledge of the program"). There are 6
possibilities; 3 are string constants. That leaves us with
len(something), searchInfo.recordName, and "][".join(something). len()
very definitely returns an integer (unless some lunatic has bound the
name to something else) and it's the *first* of the possibilities --
one can normally expect execution to proceed from left to right.
recordName smells like a string. "][".join(blahblah) likewise unless
the rebinding mania is pandemic.

Sheesh.


>
>     	I'm glad you asked this question, though, because in searching for
> examples in my code, I discovered that most of my beefs aren't actually
> of this type.  A lot of them are things like this:
>
>     	someStr.split(someList)
>
>     	Here I meant to write someList[0] (say), but have inadvertently
> passed the list instead of one of its elements.
>
>     	In this case I receive an error message that says "TypeError:
> expected a character buffer object".  My question is: why can this error
> message not say what was encountered INSTEAD of a character buffer
> object?
>
>     	A similar situation occurs when I do someVar[0] and get an
> "unsubscriptable object" error.  The error does not even tell me the
> type of the offending value, just that it is unsubscriptable.
>
>     	So my conclusion from this is: is there a reason that every error
> message of the form "expected foo" or "this object cannot be frotzed"
> cannot be changed to  something like "expected foo but found bar" or
> "this FooType object cannot be frotzed"?

And despite your use of RHN (Reverse Hungarian Notation) you don't know
that someList is a list?



From robert.kern at gmail.com  Mon Dec  4 17:36:16 2006
From: robert.kern at gmail.com (Robert Kern)
Date: Mon, 04 Dec 2006 16:36:16 -0600
Subject: Why not just show the out-of-range index?
In-Reply-To: <1165270969.942437.302020@n67g2000cwd.googlegroups.com>
References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com>	<1165264641.125857.85980@80g2000cwy.googlegroups.com>	
	<1165270969.942437.302020@n67g2000cwd.googlegroups.com>
Message-ID: 

rurpy at yahoo.com wrote:
> I saw no posts where there OP insulted anybody without being
> insulted first.  It is ironic the Mr. Kern was the most consistent
> insulter while at the same time accusing the OP of rudeness.

As I said, insult is in the ear of the listener, so I apologize if anyone
construed my comments as insults. However, facts are facts, and I stated them as
I believe them. If you can pick out the precise comments that you felt were
insulting, I will be happy to attempt clarifying them in a way that you do not
find insulting.

-- 
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



From fredrik at pythonware.com  Tue Dec  5 03:00:47 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 05 Dec 2006 09:00:47 +0100
Subject: Submitting change requests through correct channels
In-Reply-To: <877ix6re1j.fsf_-_@benfinney.id.au>
References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com>			<1165195429.928771.148400@j44g2000cwa.googlegroups.com>	<1165298191.987140.176550@f1g2000cwa.googlegroups.com>
	<877ix6re1j.fsf_-_@benfinney.id.au>
Message-ID: 

Ben Finney wrote:

> I hope that, instead, it's possible to perform the research needed to
> describe the requested change, submit it as an email or online form

are you perhaps volunteering to help setup and monitoring such a sub- 
mission channel ?

it's a certain amount of work to keep out the spammers and scammers, as 
should be obvious for anyone who's looked at an unmonitored wiki or bug 
tracker (or looked at his mail program's spam folder), but nothing that 
cannot be fit into a reasonably structured developer's daily routine.





From duncan.booth at invalid.invalid  Tue Dec 26 12:05:11 2006
From: duncan.booth at invalid.invalid (Duncan Booth)
Date: 26 Dec 2006 17:05:11 GMT
Subject: BeautifulSoup vs. loose & chars
References: 
	<1167135758.005112.67350@73g2000cwn.googlegroups.com>
	
Message-ID: 

"Felipe Almeida Lessa"  wrote:

> On 26 Dec 2006 04:22:38 -0800, placid  wrote:
>> So do you want to remove "&" or replace them with "&" ? If you
>> want to replace it try the following;
> 
> I think he wants to replace them, but just the invalid ones. I.e.,
> 
> This & this & that
> 
> would become
> 
> This & this & that
> 
> 
> No, i don't know how to do this efficiently. =/...
> I think some kind of regex could do it.
> 

Since he's asking for valid xml as output, it isn't sufficient just to
ignore entity definitions: HTML has a lot of named entities such as
  but xml only has a very limited set of predefined named entities.
The safest technique is to convert them all to numeric escapes except
for the very limited set also guaranteed to be available in xml. 

Try this:

from cgi import escape
import re
from htmlentitydefs import name2codepoint
name2codepoint = name2codepoint.copy()
name2codepoint['apos']=ord("'")

EntityPattern =
re.compile('&(?:#(\d+)|(?:#x([\da-fA-F]+))|([a-zA-Z]+));') 

def decodeEntities(s, encoding='utf-8'): 
    def unescape(match):
	code = match.group(1)
        if code:
            return unichr(int(code, 10))
        else:
            code = match.group(2)
            if code:
                return unichr(int(code, 16))
	    else:
                return unichr(name2codepoint[match.group(3)])
    return EntityPattern.sub(unescape, s)

>>> escape(
    decodeEntities("This & this & that é")).encode(
        'ascii', 'xmlcharrefreplace') 
'This & this & that é'


P.S. apos is handled specially as it isn't technically a
valid html entity (and Python doesn't include it in its entity
list), but it is an xml entity and recognised by many browsers so some
people might use it in html.
 


From http  Sat Dec  9 04:11:26 2006
From: http (Paul Rubin)
Date: 09 Dec 2006 01:11:26 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165653338.110788.62580@n67g2000cwd.googlegroups.com>
Message-ID: <7xfybptow1.fsf@ruckus.brouhaha.com>

"tmh"  writes:
> I've been writing code for engineering solutions for 15 years in
> various languages. I've gained more insight into coding in the last 6
> months then in the previous 15 years. Since lisp allows you to employ
> any and every programming technique, it actually requires you to
> understand the techniques well enough to apply them when appropriate.

You might try Mozart, .

> You should study lisp for at least a year, use it for some decent size
> projects. At the end of the day, even if you decide not to continue
> using it, you will be a much better coder. My bet, though, is that if
> you use it for a year, you won't want to use anything else. 

I've used Lisp for a long time and I've implemented it from scratch
(small dialects, not full CL) more than once.  There's something
primordial about it that is very satisfying to the inner urges.  But
there are higher forms of life out there these days too.

Do you know the Paul Graham piece "Beating the Averages"?  It's at:

   http://www.paulgraham.com/avg.html

The error in it is that Lisp is really just another Blub.

  http://weblog.raganwald.com/2006/10/are-we-blub-programmers.html



From xmlhacker at gmail.com  Mon Dec 18 01:57:10 2006
From: xmlhacker at gmail.com (M. David Peterson)
Date: Sun, 17 Dec 2006 23:57:10 -0700
Subject: [IronPython] [ANN] IronPython Community Edition r5
In-Reply-To: <5b0248170612151934v6bd84621u6337e139e8f03829@mail.gmail.com>
References: <5b0248170612151934v6bd84621u6337e139e8f03829@mail.gmail.com>
Message-ID: 

SWEET!  Caught this release before the news was no longer news,
http://www.oreillynet.com/windows/blog/2006/12/seo_sanghyeonipce_ironpython_c_1.html

Thanks, Seo! :)

On 12/15/06, Sanghyeon Seo  wrote:
>
> This is the fifth release of IronPython Community Edition (IPCE).
>
> You can download it from SourceForge.
> http://sourceforge.net/projects/fepy
>
> FePy project aims to provide enhancements and add-ons for IronPython.
> Visit the project homepage for more informations.
> http://fepy.sourceforge.net/
>
> Binary is built with Mono 1.2.2.1. It is strongly recommended to use
> Mono versions above 1.2.2, as it fixes GC.CollectionCount issue properly.
> You may meet unexplained NotImplementedError in the long-running
> process otherwise. (Thanks Paolo Molaro.)
>
> There's not much updates, but I figured that releasing early & often
> would be better...
>
> Changes in this release follow.
>
> New IronPython
>
> Updated to IronPython 1.1a1.
>
> FePy options
>
> The way site.py is (ab)used by FePy has changed. Documentation here:
> http://fepy.sourceforge.net/doc/fepy-options.html
>
> Libraries
>
> Improved array module.
> Support for CherryPy 3.
> Experimental AST support.
>
> Bundles
>
> code and ihooks are included from Python Standard Library.
> paramiko 1.6.4.
>
> Patches
>
> You can read the summary of applied patches here.
> http://fepy.sourceforge.net/patches.html
>
> Removed in this release, fixed in 1.1a1:
> patch-ironpython-file-canseek
> patch-ironpython-open-unknown-mode
> patch-ironpython-re-lastgroup
>
> New in this release, for IronPython:
> patch-ironpython-compile-co-filename
> patch-ironpython-set-func-name
>
> New in this release, for Mono:
> patch-ironpython-mono-socket-buffersize
> patch-ironpython-tabcomplete-by-default
>
> New in this release, for Python Standard Library:
> patch-stdlib-codeop (Anthony Baxter)
>
> --
> Seo Sanghyeon
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



-- 
/M:D

M. David Peterson
http://mdavid.name | http://www.oreillynet.com/pub/au/2354
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From benjaminster at gmail.com  Sat Dec 16 23:53:49 2006
From: benjaminster at gmail.com (BenjaMinster)
Date: 16 Dec 2006 20:53:49 -0800
Subject: Smarter way to do this? Unicode + stdin, stdout
Message-ID: <1166331229.618202.16890@n67g2000cwd.googlegroups.com>

I want to read and write unicode on stdin and stdout.  I can't seem to
find any way to force sys.stdin.encoding and sys.stdout.encoding to be
utf-8, so I've got the following workaround:

import codecs, sys
out = codecs.getwriter("utf-8")(sys.stdout)

def tricky(): return sys.stdin.readline().decode("utf-8").[:-1]

That is, I wrap sys.stdout in a utf-8 writer and I read utf-8 input
from stdin as normal characters then convert it to
unicode and chop off the newline.  Wrapping stdin with
codecs.getreader() doesn't work for some reason--when I call readline()
on the resulting wrapped stream, it won't return until I send it Ctrl+d
twice!  Then stdin is closed which is of course not helpful.



From kent at kentsjohnson.com  Fri Dec 15 12:55:15 2006
From: kent at kentsjohnson.com (Kent Johnson)
Date: Fri, 15 Dec 2006 17:55:15 GMT
Subject: Common Python Idioms
In-Reply-To: 
References: <17783.32458.730462.8403@montanaro.dyndns.org>	<1165493298.205945.162430@n67g2000cwd.googlegroups.com>
	
Message-ID: <7kBgh.2357$eb5.1049@newsreading01.news.tds.net>

Fredrik Lundh wrote:
> Stephen Eilert wrote:
> 
>> I do think that, if it is faster, Python should translate
>> "x.has_key(y)" to "y in x".
> 
> http://svn.python.org/view/sandbox/trunk/2to3/fix_has_key.py?view=markup

Seems to have moved to here:
http://svn.python.org/view/sandbox/trunk/2to3/fixes/fix_has_key.py?view=markup

> 
>  
> 
> 
> 


From toolmaster at 163.com  Tue Dec 26 20:18:34 2006
From: toolmaster at 163.com (WaterWalk)
Date: 26 Dec 2006 17:18:34 -0800
Subject: Noobie: Open file -> read characters & multiply
In-Reply-To: 
References: 
Message-ID: <1167182314.180326.204340@i12g2000cwa.googlegroups.com>


gonzlobo wrote:
> I've been using Python for a few days. It's such the perfect language
> for parsing data!
>
> I really like it so far, but I'm having a hard time reading a file,
> reading the first few hex characters & converting them to an integer.
> Once the characters are converted to an integer, I'd like to write the
> data to another file.
>
> Here's the code snipped to the bare minimum:
> ---
> # Open File
> AP_File= open("AP.txt", "r")
> decoded_File= open("decoded.txt", "w")
>
> # read & process data line by line
> for line in AP_File:
>    time = int(hex(line[0:8]), 16) * 0.0001     # this line is completely hosed!
>    decodedFile.write(time)
>
> #close files
> AP_File.close()
> decoded_File.close()
> ---
> AP.txt
> 000000d5 26 0600 80 00 ec 80 02 03 7d db 02 33
> 000000d5 26 0601 80 00 80 00 02 37 fe 54 01 09
> 000000d5 06 0602 80 00 e0 00 01 29 fe d2 69 99
> 000000d5 06 0603 80 00 e0 00 02 29 fe d2 6a 99
> 000000d5 26 0604 80 00 fe 54 02 09 80 00 01 5d
> 000000d5 06 0605 80 00 e0 00 02 15 fc 71 ca 0b
> 000000d5 4a 0610 81 00 86 00 02 26 12 00 02 a6
> 000000d5 4f 0611 00 00 00 50 00 00 00 00 07 00
> 000000d5 06 0612 80 00 e0 00 01 15 fc 71 c9 0b
> 000000d5 0a 0613 08 5c 04 88 08 98 00 00 00 00
> 000000d5 06 0614 80 00 e0 00 02 01 60 79 82 2b
> 000000d5 0a 0615 08 00 00 00 00 00 00 00 00 00
> 000000d5 26 0616 80 00 80 00 02 5d 04 22 3a 88
> (actual files are 250MB!)
>
> decodedTime.txt (should be)
> 0.0213 26 0600 80 00 ec 80 02 03 7d db 02 33
> ...
>
> My boss and I are trying to complete the same task (he figured out how
> to do it, but his code uses a while != "" loop and doesn't look
> pythony (it looks too 'c'). Not that there's anything wrong with that!
>
> Any help is really appreciated.

Use the built-in int(). It has an optional argument "radix" which
specifies the base for the conversion. For example:
>>> int("0x0A", 16)
>>> 10



From sjmachin at lexicon.net  Fri Dec 22 15:24:54 2006
From: sjmachin at lexicon.net (John Machin)
Date: 22 Dec 2006 12:24:54 -0800
Subject: Decorator for Enforcing Argument Types
References: <1166734180.455471.164910@79g2000cws.googlegroups.com>
	<458b0e0b$0$9768$426a74cc@news.free.fr>
	<1166807792.176011.170950@h40g2000cwb.googlegroups.com>
Message-ID: <1166819094.554972.89360@48g2000cwx.googlegroups.com>

Peter  Wang wrote:
> Bruno Desthuilliers wrote:
> > 
> > Python is dynamic, and fighting against the language is IMHO a really
> > bad idea. The only places where theres a real need for this kind of
> > stuff are when dealing with the "outside world" (IOW : inputs and
> > outputs). And then packages like formencode can do much more than mere
> > type-checking
> > 
>
> I don't think proper use of type checking is "fighting against the
> language".  The goal of any language is to enable programmers to
> express their intent in a form that executes correctly.
>
> Python is extremely expressive but there is a trade-off with
> correctness - you can easily say something that you don't mean.  Unit
> testing is sometimes sufficient, but it can never span the infinite
> space of potential errors.  Type-checking method signatures guarantees
> a certain amount of low-level correctness, and most type-checking
> mechanisms also serve as documentation aids.
>
> I think that with a sufficiently sophisticated type checking syntax,
> one can get the best of both worlds.  If the type checker understood
> interfaces (like PyProtocols) and its syntax had the flexibility to
> indicate sets of allowed arguments and aggregates of allowed
> types/interfaces, it would cover the majority of cases without limiting
> expressive power.
>
> I understand that we're all adults, but it's still nice to have the
> computer tell us when we're being childish. :)

Your comments on the following cut-down and disguised version of a
*real-world* example would be appreciated:

    @accepts(object, (int, float))
    def tally(self, anobj):
        self.total += anobj

I assure you that the comments of a caller whose code did this:
    fubar.tally(someobj)
and got this:
    AssertionError: arg 12345678901L does not match (,
)
are definitely *not* repeatable in front of the children.



From gagsl-py at yahoo.com.ar  Thu Dec  7 21:56:50 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Thu, 07 Dec 2006 23:56:50 -0300
Subject: Best way to split up lines - RE: About the 79 character
	linerecommendation
In-Reply-To: 
References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com>
	<012601c719f7$9e719990$0d7d12ac@kearfott.com>
	
	
	<1165519627.247663.165610@73g2000cwn.googlegroups.com>
	
Message-ID: <7.0.1.0.0.20061207235537.04043368@yahoo.com.ar>

At Thursday 7/12/2006 16:46, Roy Smith wrote:

>I see your point.  Actually, I think you want to force the sequences to be
>lists (regardless of what syntax we end up with), on the theory that tuples
>are for heterogeneous sequences and lists are for homogeneous ones.

Any rationale for this theory?


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From apriebe47 at gmail.com  Wed Dec 27 04:19:44 2006
From: apriebe47 at gmail.com (apriebe47 at gmail.com)
Date: 27 Dec 2006 01:19:44 -0800
Subject: File write() problem
In-Reply-To: 
References: <1167207703.803035.277720@42g2000cwt.googlegroups.com>
	
Message-ID: <1167211184.714069.142290@h40g2000cwb.googlegroups.com>

Marc 'BlackJack' Rintsch wrote:

> > configfile = file('config.txt', 'w')
> > serverPassword = configfile.readline()

Hrm. When I run the code that I posted I don't seem to get those
errors.

> Please post the exact code you have trouble with.  Don't retype it -- copy
> and paste it.

from getpass import getpass

configfile = file('config.txt', 'w')
serverPassword = configfile.readline()
if serverPassword == '':
   print "Server warning: No password has been set!"
   pwd1 = getpass("New Password: ")
   pwd2 = getpass("Confirm Password: ")
   while pwd1 != pwd2:
       print "Passwords did not match."
       pwd1 = getpass("New Password: ")
       pwd2 = getpass("Confirm Password: ")
   print "Password set. Storing to admin/config..."
   configfile.write(pwd2)
   serverPassword = configfile.readline()
   configfile.close()

Again I tested the code before I posted and I get no errors, just not
the result I am looking for in the text file. Thanks for taking the
time to look at it.

Andrew



From S.Mientki-nospam at mailbox.kun.nl  Thu Dec 28 16:49:47 2006
From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki)
Date: Thu, 28 Dec 2006 22:49:47 +0100
Subject: How to return a simple variable from a function (still newbie) ?
In-Reply-To: 
References: 	<4593E2A6.6030804@eventuallyanyway.com>		<8059c$459411c0$d443bb3a$4279@news.speedlinq.nl>
	
Message-ID: <878ce$45943beb$d443bb3a$13693@news.speedlinq.nl>


 I'll hope to understand that later on !

  You can achieve the
> same result without side-effects by returning more than one return value
> from your function.
> 
> Hope this helps,
Wow this certainly helps,
thanks very much Carsten!

Why is the obvious sometimes so far away ;-)

cheers,
Stef Mientki


From grante at visi.com  Wed Dec 27 13:50:23 2006
From: grante at visi.com (Grant Edwards)
Date: Wed, 27 Dec 2006 18:50:23 -0000
Subject: DOS, UNIX and tabs
References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com>
	<1167244483.792673.132220@42g2000cwt.googlegroups.com>
	<12p5ffrsdo6v088@corp.supernews.com>
	<1167245005.678672.196280@73g2000cwn.googlegroups.com>
Message-ID: <12p5g3f5ee04a53@corp.supernews.com>

On 2006-12-27, Ben  wrote:

>>> I've found the unexpand command, which seems to do the trick. However,
>>> it outputs to standard output, and I haven't worked out yet how to
>>> capture that output to a file...
>>
>> unexpand file2

> Great - that worked.Thanks!
>
> Is that a general method in linux you can always use to redirect
> standard output to a file?

Yup.  The "<" operator redirects stdin, the ">" operator
redirects stdout.  "2>" redirects stderr.

-- 
Grant Edwards                   grante             Yow!  Let's go to CHURCH!
                                  at               
                               visi.com            


From gagsl-py at yahoo.com.ar  Wed Dec  6 23:02:08 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Thu, 07 Dec 2006 01:02:08 -0300
Subject: Need Help Parsing From File
In-Reply-To: 
References: 
Message-ID: <7.0.1.0.0.20061207005223.0542ea60@yahoo.com.ar>

At Thursday 7/12/2006 00:20, John Frame wrote:

>Like, if in the txt file, I had the following matrix formatted numbers
>with 5 rows and 10 columns, and each number is separated by a single space:
>
>11 12 13 14 15 16 17 18 19 20
>21 22 23 24 25 26 27 28 29 30
>31 32 33 34 35 36 37 38 39 40
>41 42 43 44 45 46 47 48 49 50
>51 52 53 54 55 56 57 58 59 60
>
>How would I read this data from the file into a two dimensional array in
>Python?

If "two dimensional array" means "a list of 5 elements each one being 
a list of 10 integers" you can do this:

ftxt=open(filename,"rt")
arr = []
for line in ftxt:
     arr.append([int(number) for number in line.split()])
ftxt.close()

or, not so legible but more compact:

ftxt=open(filename,"rt")
arr2 = [[int(number) for number in line.split()] for line in ftxt]
ftxt.close()

or using Python 2.5:

with open(filename,"rt") as ftxt:
     arr3 = [[int(number) for number in line.split()] for line in ftxt]


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From Amateur.N7TZG at gmail.com  Fri Dec 15 12:01:58 2006
From: Amateur.N7TZG at gmail.com (Rob)
Date: 15 Dec 2006 09:01:58 -0800
Subject: Serial port failure
Message-ID: <1166202118.779153.191170@16g2000cwy.googlegroups.com>

Hi all,

I am fairly new to python, but not programming and embedded.  I am
having an issue which I believe is related to the hardware, triggered
by the software read I am doing in pySerial.  I am sending a short
message to a group of embedded boxes daisy chained via the serial port.
 When I send a 'global' message, all the connected units should reply
with their Id and Ack in this format '0 Ack'  To be certain that I
didn't miss a packet, and hence a unit, I do the procedure three times,
sending the message and waiting for a timeout before I run through the
next iteration.  Frequently I get through the first two iterations
without a problem, but the third hangs up and crashes, requiring me to
remove the Belkin USB to serial adapter, and then reconnect it.  Here
is the code:

import sys, os
import serial
import sret
import time

from serial.serialutil import SerialException
####################################################################
#### GetAck Procedure
####################################################################
def GetAck(p):
    response = ""

    try:
        response = p.readline()
    except SerialException:
	print ">>>>>Timed out<<<<<"
	return -1
    res = response.split()

    #look for ack in the return message
    reslen = len(response)
    if reslen > 5:
        if res[1] == 'Ack':
	    return res[0]
	elif res[1] == 'Nak':
	    return 0x7F
	else:
	    return -1


>>>>> Snip <<<<<<
####################################################################
#### GetNumLanes Procedure
####################################################################
def GetNumLanes(Lanes):
	print "Looking for connected units"
# give a turn command and wait for responses
	msg = ".g t 0 336\n"

	for i in range(3):
	    port = OpenPort()
	    time.sleep(3)
	    print port.isOpen()
	    print "Request #%d" % (i+1)
	    try:
	        port.writelines(msg)
	    except OSError:
		print "Serial port failure.  Power cycle units"
		port.close()
		sys.exit(1)

            done = False
# Run first connection check
	    #Loop through getting responses until we get a -1 from GetAck
            while done == False:
	        # lane will either be -1 (timeout), 0x7F (Nak),
	        # or the lane number that responded with an Ack
	        lane = GetAck(port)
	        if lane >= '0':
                    if False == Lanes.has_key(lane):
                        Lanes[lane] = True
	        else:
	            done = True
	    port.close()
	    time.sleep(3)

# Report number of lanes found
        NumLanes = len(Lanes)
	if NumLanes == 1:
    		print "\n\nFound 1 unit connected"
	else:
    		print "\n\nFound %d units connected" % NumLanes

	return NumLanes


>>>>>> Snip <<<<<<
####################################################################
#### Main Program Code Section
####################################################################

#open the serial port
# capture serial port errors from trying to open the port

port = OpenPort()

# If we got to here, the port exists.  Set the baud rate and timeout
values

# I need to determine how many lanes are on this chain
# First send a turn command

#Create a dictionary of lanes so I can check each lane's responses
Lanes = {}
#<><><><><><><><><><><><><><><><>
# Call the lane finder utility
NumLanes = GetNumLanes(Lanes)
#<><><><><><><><><><><><><><><><>

#if no lanes responded, exit from the utility
if 0 == NumLanes:
    print "I can't find any units connected."
    print "Check your connections and try again"
    sys.exit(1)

# list the lanes we have in our dictionary
for n in Lanes:
    print "Lane - %s" % n

Now, here is the error message that I get

dad at nb29:~/py$ ./Thex.py
Looking for connected units
True
Request #1
True
Request #2
Serial port failure.  Power cycle units
dad at nb29:~/py$ ./Thex.py
The serial port is unavailable.
Disconnect your USB to Serial adapter, Then
reconnect it and try again.
dad at nb29:~/py$

Does anyone have any ideas?

Thanks,

rob < Amateur.N7TZG at gmail.com >



From andrea.gavana at gmail.com  Fri Dec  1 08:46:13 2006
From: andrea.gavana at gmail.com (Andrea Gavana)
Date: Fri, 1 Dec 2006 18:46:13 +0500
Subject: PythonWin And Excel Problem
Message-ID: 

Hi Michael,

> First of all you should call the random.seed()
> function. That was at least what I?ve always done.
> seed([x])

Thanks for your suggestion, but it doesn't matter whether you call
seed() or not. The random number generator can *not* return 10 equal
values if called 10 times, irrespective of the fact that it is
initalized or not. You can try by simply doing:

import random
print random.random()
print random.random()
print random.random()

And you'll see that the numbers are different.

Moreover, I can populate that list by hand with 10 values like:

therand = [ii for ii in xrange(1, 11)]

And the result in Excel will be the same. All the cells will have the value 1.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/


From grue at mail.ru  Sat Dec  9 09:00:10 2006
From: grue at mail.ru (Timofei Shatrov)
Date: Sat, 09 Dec 2006 14:00:10 GMT
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06>
	<1165649882.563957.87770@n67g2000cwd.googlegroups.com>
	
Message-ID: <457abf83.18014323@news.readfreenews.net>

On Sat, 09 Dec 2006 20:36:02 +1100, Steven D'Aprano
 tried to confuse everyone with this
message:

>On Fri, 08 Dec 2006 23:38:02 -0800, Wolfram Fenske wrote:
>
>> if Common Lisp didn't have CLOS, its object system, I could write my own
>> as a library and it would be just as powerful and just as easy to use as
>> the system Common Lisp already provides.  Stuff like this is impossible
>> in other languages.
>
>Dude. Turing Complete. Don't you Lisp developers know anything about
>computer science?

Here, you've basically shot yourself in the ass. Appealing to Turing
completeness when talking about programming language features is about the
dumbest thing you can make. In Turing sense, a program is simply a function that
takes an argument and returns a value. It doesn't say anything about how this
function was implemented. It could be Turing machine, lambda calculus, Markov
chains or whatever else. All these methods produce the same set of programs, but
that doesn't mean you could implement lambda in Turing machine for example.

Is is time for someone to read his computer science books again?

-- 
|Don't believe this - you're not worthless              ,gr---------.ru
|It's us against millions and we can't take them all... |  ue     il   |
|But we can take them on!                               |     @ma      |
|                       (A Wilhelm Scream - The Rip)    |______________|


From arkanes at gmail.com  Fri Dec 29 16:12:44 2006
From: arkanes at gmail.com (Chris Mellon)
Date: Fri, 29 Dec 2006 15:12:44 -0600
Subject: Python-list Digest, Vol 39, Issue 465
In-Reply-To: <6.2.3.4.2.20061229105452.032fcaf0@rjs.org>
References: 
	<6.2.3.4.2.20061229105452.032fcaf0@rjs.org>
Message-ID: <4866bea60612291312r1e525257v51698beae28c273b@mail.gmail.com>

On 12/29/06, Ray Schumacher  wrote:
>
>  At 10:50 AM 12/29/2006, you wrote:
>
> In addition to what Chris said, is there a reason why you're reinventing
>  the wheel instead of using available components?
>  Hi Carsten,
>  The eventual goal here is towards a streaming two-way server, which
> wouldn't use the http, but something more like RTP/RTCP/H.323/ which I'm
> learning. It's also a general socket  learning exercise for me, as I haven't
> used them very much.
>  I was also using PyDShowCam before, and have switched to VideoCapture since
> I'll need to recompile PyDShowCam for py2.4.
>  I will look into the wx Chris suggested this weekend; more stuff I haven't
> used...
>
>  Thanks,
>  Ray
>
>  For anyone interested, I attached a quick wx I made last night that
> monitors a USB webcam, will create "dark" frames (a la astronomy), and serve
> up images to web browsers (thus the question). The browser/monitor would
> actually work nicely with a web page that has a JavaScript function to
> reload the image x times/second. I'll try replacing the PIL with the wx
> function(s) and benchmark if they work.
>

I just double-checked my documentation and wx.Image.GetData() is not
what you want - that's the RGB pixel data, and you want the encoded
stream.

Using pil to save directly to the output buffer is probably the most
efficient mechanism - it doesn't look like wxPython provides
SaveStream (or SaveBuffer). Those probably could be implemented (the
C++ wxImage object supports saving to streams, and SWIG can make a
python FLO look like a stream), you might want to post a feature
request.


From bpeng at rice.edu  Fri Dec 22 12:59:14 2006
From: bpeng at rice.edu (Bo Peng)
Date: Fri, 22 Dec 2006 12:59:14 -0500
Subject: Building python C++ extension modules using MS VC++ 2005?
In-Reply-To: <1166749253.206471.238680@73g2000cwn.googlegroups.com>
References: 
	<1166749253.206471.238680@73g2000cwn.googlegroups.com>
Message-ID: 

Sandra-24 wrote:
> You can use 2005 to build extensions for Python 2.5. I've done this
> with several extensions, both my own and others. I do not know if you
> can use it for Python 2.4, so I won't advise you on that. I thought
> Microsoft made its C/C++ compiler, version 7.1 (2003) freely available
> as a command line tool. If you can't find it on their site, ask around,
> I'm sure a lot of people have it. Probably you'll also find someone has
> put it up somewhere if you search on google. Try 2005 first and see
> what happens though.

But how exactly should I do it? I installed VC8 and get the all-familiar 
error message: Python was built with Visual Stuidio 2003 ....

Actually, I get a copy of VC6/2003 but this compiler can not compile 
boost 1.33.1/serialization so it can not be used to compile my extension 
module.

Bo


From DustanGroups at gmail.com  Tue Dec 12 07:12:41 2006
From: DustanGroups at gmail.com (Dustan)
Date: 12 Dec 2006 04:12:41 -0800
Subject: Emulate @classmethod using decorator and descriptor
In-Reply-To: <1165924003.681613.62790@80g2000cwy.googlegroups.com>
References: <1165924003.681613.62790@80g2000cwy.googlegroups.com>
Message-ID: <1165925561.294037.205280@n67g2000cwd.googlegroups.com>


WaterWalk wrote:
> Hello, I was recently learning python decorator and descriptor and
> emulated a @classmethod decorator:
> class EmuClassMethod(object):
>     def __init__(self, f=None):
>         self.f = f
>     def __get__(self, obj, klass=None):
>         if klass is None:
>            klass = type(obj)
>         def  wrapped(*args):
>            return self.f(klass, *args)
>         return wrapped
>
> class Test(object):
>     @EmuClassMethod
>     def t(cls):
>         print "I'm %s" % cls.__name__
>
> It worked, and seems that a function decorator works as follows:
> # decf is a decorator
> @decf
> def func():
>     print 'func'
>
> will be "converted" to:
>
> def func():
>     print 'func'
> func = decf(func)
>
> Is this really the case? Or correct me if i'm wrong. Thanks in advance.

Yes, the two are equivalent. The documentation is found here:
http://docs.python.org/ref/function.html

But I personally found the explanation for decorators a bit confusing.



From fredrik at pythonware.com  Thu Dec  7 07:04:53 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Thu, 7 Dec 2006 13:04:53 +0100
Subject: Best way to split up lines - RE: About the 79 character
	linerecommendation
References: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com>
	<012601c719f7$9e719990$0d7d12ac@kearfott.com>
Message-ID: 

Michael Yanowitz wrote:

> What would be the best way to split the following line (Python doesn't like
> me to split it up between the comma-separated parameters):
>
>    top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1,
> utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1,
> st2, st3, st4, st5, st6, numberOfLabels, dataWord =
> struct.unpack("!H4BH20BHI", strMessage)

    data = struct.unpack("!H4BH20BHI", strMessage)

    (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired,
    dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8,
    utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6,
    numberOfLabels, dataWord) = data

 





From nmm1 at cus.cam.ac.uk  Thu Dec 14 10:54:54 2006
From: nmm1 at cus.cam.ac.uk (Nick Maclaren)
Date: 14 Dec 2006 15:54:54 GMT
Subject: tuple.index()
References: 
	<1166104987.884566.126710@n67g2000cwd.googlegroups.com>
	
	<1166106278.106832.278240@n67g2000cwd.googlegroups.com>
	
	<1166111379.421958.112140@t46g2000cwa.googlegroups.com>
Message-ID: 


In article <1166111379.421958.112140 at t46g2000cwa.googlegroups.com>,
"Glenn Hutchings"  writes:
|>
|> > I remain baffled.  I accept the explanations, but what I am now
|> > confused by is the reason for the explanations ....
|> 
|> Maybe this archive posting, straight from the horse's mouth, will clear
|> things up once and for all...
|> 
|> http://www.python.org/search/hypermail/python-1992/0285.html

Wonderful!  Thanks.  Yes, that does.  It makes perfect sense.  I did
say that I thought it would be a rarely used feature :-)


Regards,
Nick Maclaren.


From johnzenger at gmail.com  Tue Dec 19 22:42:44 2006
From: johnzenger at gmail.com (johnzenger at gmail.com)
Date: 19 Dec 2006 19:42:44 -0800
Subject: regexp
In-Reply-To: 
References: 
	
	
	<1166562917.353088.227780@73g2000cwn.googlegroups.com>
	<1166563001.129918.195400@a3g2000cwd.googlegroups.com>
	
Message-ID: <1166586164.504619.96310@i12g2000cwa.googlegroups.com>

Not just Python, but every Regex engine works this way.  You want a ?
after your *, as in <--(.*?)--> if you want it to catch the first
available "-->".

At this point in your adventure, you might be wondering whether regular
expressions are more trouble than they are worth.  They are.  There are
two libraries you need to take a look at, and soon:  BeautifulSoup for
parsing HTML, and PyParsing for parsing everything else.  Take the time
you were planning to spend on deciphering regexes like
"(\d{1,3}\.){3}\d{1,3}" and spend it learning the basics of those
libraries instead -- you will not regret it.

On Dec 19, 4:39 pm, vertigo  wrote:
> Hello
>
> Thanx for help, i have one more question:
>
> i noticed that while matching regexp python tries to match as wide as it's
> possible,
> for example:
> re.sub("","",htmldata)
> would cut out everything before first "" in the
> document.
> Can i force re to math as narrow as possible ?
> (to match first "" after the "", "", htmldata)

Explanation:  To make the dot match all characters, including newlines,
you need to set the DOTALL flag.  You can set the flag using the (?_)
syntax, which is explained in section 4.2.1 of the Python Library
Reference.

A more readable way to do this is:

obj = re.compile("", re.DOTALL)
re.sub("", htmldata)


On Dec 19, 3:59 pm, vertigo  wrote:
> Hello
>
>
>
>
>
> > On Tuesday 19 December 2006 13:15, vertigo wrote:
> >> Hello
>
> >> I need to use some regular expressions for more than one line.
> >> And i would like to use some modificators like: /m or /s in perl.
> >> For example:
> >> re.sub(".*","",data)
>
> >> will not cut out all javascript code if it's spread on many lines.
> >> I could use something like /s from perl which treats . as all signs
> >> (including new line). How can i do that ?
>
> >> Maybe there is other way to achieve the same results ?
>
> >> Thanx
>
> > Take a look at Chapter 8 of 'Dive Into Python.'
> >http://diveintopython.org/toc/index.htmli read whole regexp chapter - but there was no solution for my problem.
> Example:
>
> re.sub("","",htmldata)
> would remove only comments which are in one line.
> If comment is in many lines like this:
> 
>
> it would not work. It's because '.' sign does not matches '\n' sign.
>
> Does anybody knows solution for this particular problem ?
> 
> Thanx- Hide quoted text -- Show quoted text -



From frank at niessink.com  Sat Dec 16 07:19:57 2006
From: frank at niessink.com (Frank Niessink)
Date: Sat, 16 Dec 2006 13:19:57 +0100
Subject: Has comparison of instancemethods changed between python 2.5
	and 2.4?
In-Reply-To: <4583367D.7090508@niessink.com>
References: <4582CFA3.5040305@niessink.com> 
	<4583367D.7090508@niessink.com>
Message-ID: <4583E46D.8020002@niessink.com>

Frank Niessink:
> OK, so that explains why the id of (two references to the same) 
> instancemethod(s) may differ. But I'm still confused why two 
> instancemethods of two different instances can compare as equal.

I tried to lookup the python source code where the actual comparison 
happens. I think it is in methodobject.c (I'm not familiar with the 
python source so please correct me if I'm wrong), meth_compare. That 
function did not change between python 2.4.4 and 2.5. Moreover, the 
implementation suggests that the only way for two methods to be equal is 
that their instances point to the same object and their method 
definitions are the same. Am I interpreting that correctly?

static int
meth_compare(PyCFunctionObject *a, PyCFunctionObject *b)
{
	if (a->m_self != b->m_self)
		return (a->m_self < b->m_self) ? -1 : 1;
	if (a->m_ml->ml_meth == b->m_ml->ml_meth)
		return 0;
	if (strcmp(a->m_ml->ml_name, b->m_ml->ml_name) < 0)
		return -1;
	else
		return 1;
}

I'll dig some deeper in my own code, maybe I have two instances that are 
somehow different with python 2.4 and equal with python 2.5 and that 
register the same method as callback.

Cheers, Frank


From Bulkan at gmail.com  Wed Dec 13 21:38:09 2006
From: Bulkan at gmail.com (placid)
Date: 13 Dec 2006 18:38:09 -0800
Subject: Password, trust and user notification
In-Reply-To: 
References: <364538570612131644l604930b9l861b94457bc1183@mail.gmail.com >
	<1165896991.676350.118670@16g2000cwy.googlegroups.com>
	<1165917102.008439.146400@16g2000cwy.googlegroups.com>
	<1166053509.270409.46390@f1g2000cwa.googlegroups.com>
	<7.0.1.0.0.20061213210006.04005d80@yahoo.com.ar>
	<364538570612131644l604930b9l861b94457bc1183@mail.gmail.com>
	
Message-ID: <1166063889.162843.54540@73g2000cwn.googlegroups.com>


Gabriel Genellina wrote:
> At Wednesday 13/12/2006 21:44, Aidan Steele wrote:
>
> >While what you said is technically correct, I think you misread
> >their original question. They want to send email *from* the Gmail
> >account *to* the work account. I suggested that he use Gmail's SMTP
> >server to send the email.

This is correct.

> They were concerned about putting sensitive information (password)
> inside the script, in order to connect to Gmail to send the mail notifications.
> I say that there is no need to use Gmail smtp services: to send mail
> *to* anyone at anywhere.com, you only have to connect to the right SMTP
> server for anywhere.com. The *from* email address is irrelevant and
> can even be faked.
> Of course a spam filter could block such mails, but you have to test it.

I was concerned that how does the person who will enter her password
trust the script or the developer in that the script will not create an
email containing her details i.e password and send it off to himself?
(See the assumptions i also posted above in my original post)

Is there any other way of notifying the user of events occurring in the
script which will run as a daemon process.


Cheers



From nmm1 at cus.cam.ac.uk  Thu Dec 14 14:01:51 2006
From: nmm1 at cus.cam.ac.uk (Nick Maclaren)
Date: 14 Dec 2006 19:01:51 GMT
Subject: tuple.index()
References: 
	
	<1166103409.199435.290670@79g2000cws.googlegroups.com>
	<1166118142.144177.78790@l12g2000cwl.googlegroups.com>
	
	<1166122540.017590.64460@16g2000cwy.googlegroups.com>
Message-ID: 


In article <1166122540.017590.64460 at 16g2000cwy.googlegroups.com>,
"Carl Banks"  writes:
|> 
|> > It isn't a misplaced fear, but the extra protection
|> > provided by doing that only for tuples is like locking one door out of
|> > ten to deter burglars - good practice, if there is no downside, but not
|> > worth putting much effort into.
|> 
|> Maybe "inconsistent" fear is a better word.  It's like when people are
|> deathly afraid to get on an airplane, but think nothing of riding in a
|> car without a seatbelt.

I agree with that.  I consider the difficulty of adding a reliable
immutable attribute in most languages to be a serious piece of
misdesign, but there isn't a huge amount of point unless it is done
properly.  Unreliable safety devices are as likely to increase
errors as reduce them, at least in the hands of the naive.


Regards,
Nick Maclaren.


From grante at visi.com  Thu Dec 14 10:24:11 2006
From: grante at visi.com (Grant Edwards)
Date: Thu, 14 Dec 2006 15:24:11 -0000
Subject: job posting: nothing about Python there
References: <1166069696.859817.18450@73g2000cwn.googlegroups.com>
	<7xy7pb1241.fsf@ruckus.brouhaha.com>
Message-ID: <12o2r4rqqnje623@corp.supernews.com>

On 2006-12-14, Paul Rubin  wrote:
> Looks like a generic Windows weenie gig:
>
>  Will serve as a programmer in the following program languages:
>  RPGIII, RPGILE,

Those two are IBM aren't they? (AS-400 and the like?)

>  Microsoft Access, SQL, Microsoft SQL Server, XML, Cold Fusion,
>  and other web development tools.

-- 
Grant Edwards                   grante             Yow!  I know th'MAMBO!! I
                                  at               have a TWO-TONE CHEMISTRY
                               visi.com            SET!!


From eastera at gmail.com  Sun Dec 31 08:20:10 2006
From: eastera at gmail.com (JTree)
Date: 31 Dec 2006 05:20:10 -0800
Subject: A question about  unicode() function
Message-ID: <1167571210.084436.311610@48g2000cwx.googlegroups.com>

Hi,all
     I encountered a problem when using unicode() function to fetch a
webpage, I don't know why this happenned.
     My codes and error messages are:


Code:
#!/usr/bin/python
#Filename: test.py
#Modified: 2006-12-31

import cPickle as p
import urllib
import htmllib
import re
import sys

def funUrlFetch(url):
    lambda url:urllib.urlopen(url).read()

objUrl = raw_input('Enter the Url:')
content = funUrlFetch(objUrl)
content = unicode(content,"gbk")
print content
content.close()


error message:

C:\WINDOWS\system32\cmd.exe /c python test.py
Enter the Url:http://www.msn.com
Traceback (most recent call last):
  File "test.py", line 16, in ?
    content = unicode(content,"gbk")
TypeError: coercing to Unicode: need string or buffer, NoneType found
shell returned 1
Hit any key to close this window...

Any suggestions would be appreciated!

Thanks!



From g.brandl-nospam at gmx.net  Thu Dec 14 10:28:52 2006
From: g.brandl-nospam at gmx.net (Georg Brandl)
Date: Thu, 14 Dec 2006 16:28:52 +0100
Subject: tuple.index()
In-Reply-To: 
References: 
	<1166104987.884566.126710@n67g2000cwd.googlegroups.com>
	
	<1166106278.106832.278240@n67g2000cwd.googlegroups.com>
	
Message-ID: 

Nick Maclaren schrieb:
> In article <1166106278.106832.278240 at n67g2000cwd.googlegroups.com>,
> "Glenn Hutchings"  writes:
> |> Fredrik Lundh wrote:
> |> 
> |> > if you don't want to understand the design, nobody can force you.  but arguing
> |> > that the people behind the design "don't get it" isn't very practical.
> |> 
> |> I'm not arguing that at all.  What I'm saying is that from the
> |> perspective of someone not interested in design issues, it seems like
> |> an omission for tuples to be missing the non-modifying methods that
> |> lists have.
> 
> And, from the perspective of someone VERY interested in design issues,
> from the viewpoint of program validation (a.k.a mathematical models,
> a.k.a. 'program proving' a.k.a. 'software engineering') it also seems
> like one!
> 
> If lists are intended to be homogeneous, then they should be checked
> for that, and an exception raised when an attempt is to make them
> non-homogeneous.  At least as a Python checking option.

There you have the "consenting adults" philosophy again: You know what lists
are for, so you can use them for it. You can also use them for something else,
but in that case it's moot to complain about missing features.

> If tuples are intended to be bags, then it makes no sense to allow
> them to be subscripted OR indexed.  Mathematically, 'x = a[i]' and
> 'i = a.index(x)' have dual properties - and are true duals if you
> include the constraint of no duplicate elements.

You're describing sets. Tuples are not sets. Sets are not indexable and have
unique elements.

Indexing is the *vital* point of tuples. They are an ordered collection of
values, and you are supposed to know which data is found at which index.
Don't tell me that tuples in maths are sets.

For a mathematical example, take

A = { (x,y) : 0 < x < 1, 0 < y < 1 }

Here, (x,y) is a 2-tuple, and you know that at index 0 there's the x-coordinate
of a point contained in the square A, and at index 1 there's the y-coordinate.

Georg


From sable.sungard at gmail.com  Tue Dec 12 10:25:47 2006
From: sable.sungard at gmail.com (=?ISO-8859-1?Q?S=E9bastien_Sabl=E9?=)
Date: Tue, 12 Dec 2006 16:25:47 +0100
Subject: Sybase module 0.38pre1 released
Message-ID: 

WHAT IS IT:

The Sybase module provides a Python interface to the Sybase relational
database system.  It supports all of the Python Database API, version
2.0 with extensions.

MAJOR CHANGES SINCE 0.37:

* This release works with python 2.5

* It also works with sybase 15

* It works with 64bits clients

* It can be configured to return native python datetime objects

* The bug "This routine cannot be called because another command
structure has results pending." which appears in various cases has
been corrected

* It includes a unitary test suite based on the dbapi2.0 compliance
test suite


From skpatel20 at gmail.com  Sat Dec 16 08:29:08 2006
From: skpatel20 at gmail.com (Sanjay)
Date: 16 Dec 2006 05:29:08 -0800
Subject: Routine for prefixing '>' before every line of a string
In-Reply-To: 
References: <1166097838.257731.297110@l12g2000cwl.googlegroups.com>
	
	
Message-ID: <1166275748.395417.105040@80g2000cwy.googlegroups.com>

Thanks a lot, guys!

sanjay



From usenet-mail-0306.20.chr0n0ss at spamgourmet.com  Mon Dec  4 17:01:02 2006
From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann)
Date: Mon, 04 Dec 2006 23:01:02 +0100
Subject: python Noob - basic setup question / problem
References: 
Message-ID: <4tjk4uF142mrtU1@mid.individual.net>

Lilavivat wrote:

> /usr/bin/python2: bad interpreter: No such file or directory
> 
> "which python" gives me "/usr/local/bin/python"
> 
> "which python2.4" gives me "/usr/local/bin/python2.4"
> 
> But /usr/bin/python is symlinked to python2.4 "python ->
> python2.4"

Try to understand what "which" does. It says which file it calls if
you input the parameter into the shell. So if this happens

$ which python
/usr/local/bin/python
 
there's no point looking at /usr/bin/python.

What does "ls -l /usr/local/bin/python" say? I bet it's a dangling
symlink.

Regards,


Bj?rn

-- 
BOFH excuse #255:

Standing room only on the bus.



From sjmachin at lexicon.net  Sun Dec  3 21:27:40 2006
From: sjmachin at lexicon.net (John Machin)
Date: 3 Dec 2006 18:27:40 -0800
Subject: Why not just show the out-of-range index?
In-Reply-To: <1165198036.545819.77820@79g2000cws.googlegroups.com>
References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com>
	
	<1165194171.257951.89040@j44g2000cwa.googlegroups.com>
	<1165198036.545819.77820@79g2000cws.googlegroups.com>
Message-ID: <1165199260.872922.7420@j44g2000cwa.googlegroups.com>


mensanator at aol.com wrote:
> John Machin wrote:
> > Add "Syntax Error: invalid syntax" to the list ...
>
> But at least if you're using IDLE, the point of syntax error
> is highlighted.
>

Same when using the interactive interpreter, the point of syntax error
is highlighted with a caret. However the highlighting of WHERE is
useless to people who don't have a clue WHAT the error is, and it needs
a forensic guru to suss it out as for example Peter Otten did, only
yesterday:
"""
Are you perhaps mixing tabs and spaces?

>>> def f():

...     print "hello" # four spaces before 'print'
...     return 42     # one tab before 'return'
  File "", line 3
    return 42
    ^
SyntaxError: invalid syntax 
"""



From meyer at acm.org  Thu Dec  7 11:16:22 2006
From: meyer at acm.org (Andre Meyer)
Date: Thu, 7 Dec 2006 17:16:22 +0100
Subject: funcs without () like print
In-Reply-To: 
References: <1165502180.715192.195240@j72g2000cwa.googlegroups.com>
	
Message-ID: <7008329d0612070816h2fa6da6bld87639d557d80fb5@mail.gmail.com>

print is supposed to become a function in Py3k, though.


On 12/7/06, Georg Brandl  wrote:
>
> iwl wrote:
> > Hello can I make funktions callable without () like print
> > at time the interpreter seems to printout the adres when I type the
> > function without ()
>
> print is not a function, it's a statement, and as such equivalent to
> raise or assert.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From pavlovevidence at gmail.com  Tue Dec 12 18:13:37 2006
From: pavlovevidence at gmail.com (Carl Banks)
Date: 12 Dec 2006 15:13:37 -0800
Subject: One module per class, bad idea?
In-Reply-To: 
References: 
Message-ID: <1165965217.063548.208270@80g2000cwy.googlegroups.com>

Matias Jansson wrote:
> I come from a background of Java and C# where it is common practise to have
> one class per file in the file/project structure. As I have understood it,
> it is more common practice to have many classes in a Python module/file.
> What is the motivation behind it, would it be a bad idea to have a guideline
> in your project that promotes a one class per file structure (assuming most
> of the programmers a background similar to mine)?

One class per module is like having a filing system where you limit
yourself to one piece of paper per file.

(I think it's just convention, really.  You don't have to use one class
per module in Python, and given that freedom, most Python programmers
didn't.)


Carl Banks



From noway at ask.me  Fri Dec 15 06:38:36 2006
From: noway at ask.me (Giovanni Bajo)
Date: Fri, 15 Dec 2006 12:38:36 +0100
Subject: Missing __length_hint__ in __getitem__ iterator 
Message-ID: 

Hello,

given the following object:

 >>> class A(object):
...     def __getitem__(self, idx):
...             if idx >= 10: raise IndexError
...             return idx
...     def __len__(self):
...             return 10
...

I noticed that the iterator that Python constructs:

 >>> a = A()
 >>> i = iter(a)
 >>> dir(i)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', 
'__init__', '__iter__', '__len__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__setattr__', '__str__', 'next']

does not have a __length_hint__ method.

Is this just a missing optimization, or there is a deep semantic reason for 
which a __length_hint__ could not be constructed out of the __len__ result?
-- 
Giovanni Bajo


From rpdooling at gmail.com  Tue Dec 19 10:57:20 2006
From: rpdooling at gmail.com (BartlebyScrivener)
Date: 19 Dec 2006 07:57:20 -0800
Subject: python poetry?
In-Reply-To: <45880942$0$8996$426a74cc@news.free.fr>
References: <1166524579.271548.32560@a3g2000cwd.googlegroups.com>
	<45880942$0$8996$426a74cc@news.free.fr>
Message-ID: <1166543840.677643.198960@t46g2000cwa.googlegroups.com>


Bruno Desthuilliers wrote:
> You of course already know . . . and "BOFH" (aka the
> Bastard Operator From Hell') ?

Didn't know this one. It's funny!

Thanks

rd



From kentilton at gmail.com  Tue Dec 12 08:59:24 2006
From: kentilton at gmail.com (Ken Tilton)
Date: Tue, 12 Dec 2006 08:59:24 -0500
Subject: merits of Lisp vs Python
In-Reply-To: <4u7jmsF175jh0U1@mid.individual.net>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	
	
	<4u7g1kF17436jU1@mid.individual.net>
	<7xmz5txs4x.fsf@ruckus.brouhaha.com>
	<4u7jmsF175jh0U1@mid.individual.net>
Message-ID: 



Pascal Costanza wrote:
> Paul Rubin wrote:
> 
>> Pascal Costanza  writes:
>>
>>> May you have tried the wrong Lisp dialects so far:
>>>
>>> (loop for i from 2 to 10 by 2
>>>        do (print i))
>>
>>
>> The loop language is so complicated and confusing that I never
>> bothered trying to learn it.

That was my stance for about seven years of intense Lisp. Then the 
author of Practical Common Lisp did a nice job of breaking the whole 
mess up into sensible chunks and I picked it up. If one programs Lisp, 
one should learn Loop -- it is definitely worth the bother. I def regret 
not learning it sooner.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


From duncan.booth at invalid.invalid  Fri Dec 22 04:29:48 2006
From: duncan.booth at invalid.invalid (Duncan Booth)
Date: 22 Dec 2006 09:29:48 GMT
Subject: Decorator for Enforcing Argument Types
References: <1166734180.455471.164910@79g2000cws.googlegroups.com>
	<458b0e0b$0$9768$426a74cc@news.free.fr>
	<1166741966.242087.192390@n67g2000cwd.googlegroups.com>
	<1166767205.559937.185260@f1g2000cwa.googlegroups.com>
	<1166773847.368709.299960@48g2000cwx.googlegroups.com>
Message-ID: 

"John Machin"  wrote:

>> > if isinstance(....
>> >     action_for_type1(...
>> > # big snip
>> > elif isinstance(...
>> >     action_typeN( ...
>> > # no else statement
>>
>> Ouch.. someone must have skipped his/her OO class...
> 
> Quite possibly :-) but that's not the problem here.
> 
> The method in question might be called say emit_generic(self,
> any_type_of obj) and so one bunch of isinstance calls is actually
> needed, but not two bunches. So: lose the decorator and add an else and
> a raise at the end.
> 
> There is a secondary problem: annoying the crap out of callers who
> often know what type they have and want an emit_real which would take
> an int, a long, or a float and an emit_strg and ... (yes, almost all
> the possible types are that simple) which wouldn't go through even one
> chain of isinstance calls.
> 

I think the point that was being made was that the method's body should be 
something like:

   actions[type(arg)](...)

which not only avoids all of the isinstance calls but also the else and the 
raise at the end.


From deets at nospam.web.de  Tue Dec  5 13:30:26 2006
From: deets at nospam.web.de (Diez B. Roggisch)
Date: Tue, 05 Dec 2006 19:30:26 +0100
Subject: logo design
References: <1165333204.582656.325850@80g2000cwy.googlegroups.com>
Message-ID: <4tls63F151fc5U1@mid.uni-berlin.de>

> 
> Web-badges serve slightly different purpose than logos. It is more for
> the purpose of promotion, than representation. For the same reason,
> there are mascots. For example, Java the language, has a official logo
> of a smoking coffee cup, but also has a mascot of a penguin named
> ?Duke?.

http://java.sun.com/features/1999/05/duke_gallery.html

"""
Duke doesn't like bad code, working out, or being called a troll, a tooth,
or a penguin.
"""

As usual a shining example of Xah Lee not getting even the most basic facts
right.

Diez


From pyenos at pyenos.org  Fri Dec 22 18:45:54 2006
From: pyenos at pyenos.org (Pyenos)
Date: 23 Dec 2006 10:45:54 +1100
Subject: scopes of local and global variable
Message-ID: <87tzzncx59.fsf@pyenos.pyenos.org>

#############################CODE##############################
t_len=0
class WORK:
    def getwork(self):
        def formattable(table_to_process,type):                                               
            TYPE=["p","t","T","s","i"] #list of types to format
            if type==TYPE[1]:
                def format_t():
                    row=[]
                    for col in table_to_process:

                        #######################
                        # ERROR PRONE PART    #
                        #######################
                        if len(str(col))>t_len:
                            t_len=len(str(col))
                        #######################
# Error message says:                                                   #
# UnboundLocalError: local variable 't_len' referenced before assignment#

                        row+=col
                        if (table_to_process.index(col)+1)%7==0:
                            t_temp.append(row)
                            row=[]
                format_t()
#################################################################

Interpreter says that t_len is local variable although i have
specified t_len=0 in line 1. Also, although i've stated t_len=0 in
line 1, it says that t_len is referenced before assignment.


From gagsl-py at yahoo.com.ar  Thu Dec 14 20:49:41 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Thu, 14 Dec 2006 22:49:41 -0300
Subject: I'm looking for a pythonic red-black tree...
In-Reply-To: 
References: 
Message-ID: <7.0.1.0.0.20061214224905.059a21f0@yahoo.com.ar>

At Thursday 14/12/2006 22:20, Just Another Victim of the Ambient 
Morality wrote:

>     I need a red-black tree in Python and I was wondering if there was one
>built in or if there's a good implementation out there.  Something that,
>lets face it, does whatever the C++ std::map<> allows you to do...

There are several implementations, try google...


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From borntonetwork at gmail.com  Thu Dec  7 17:21:03 2006
From: borntonetwork at gmail.com (borntonetwork)
Date: 7 Dec 2006 14:21:03 -0800
Subject: PyQt, designer, and directional flow
In-Reply-To: 
References: <1165380360.285089.94980@16g2000cwy.googlegroups.com>
	
Message-ID: <1165530063.007620.194420@l12g2000cwl.googlegroups.com>

Something simple, of course. I must have errantly clicked the field in
the property editor.

Thanks very much for you help.

On 12/7/06, Phil Thompson wrote:

    On Wednesday 06 December 2006 11:41 pm, you wrote:
    > I meant QLineEdit in my original post. Sorry about that. Every
single one
    > of them in the ui file exibits the same behavior on my machine.

    It's because you have set the layout direction on the QTabWidget.
Normally you
    would only set this explicitly if you wanted part of your GUI in a
left to
    right language (like Engish) and part it a right to left language
(like
    Arabic).

    Phil



From fredrik at pythonware.com  Tue Dec  5 00:59:42 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 05 Dec 2006 06:59:42 +0100
Subject: Why not just show the out-of-range index?
In-Reply-To: <1165277406.806371.181620@79g2000cws.googlegroups.com>
References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com>		<97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com>		<1165216880.864158.256730@80g2000cwy.googlegroups.com>		<1165219968.619509.147990@73g2000cwn.googlegroups.com>		<1165223084.558617.9570@79g2000cws.googlegroups.com>		<1165250963.660087.58410@n67g2000cwd.googlegroups.com>	<45745F24.2010406@v.loewis.de>	<1165258556.021281.51440@79g2000cws.googlegroups.com>	<45749D82.4040301@v.loewis.de>	
	<1165277406.806371.181620@79g2000cws.googlegroups.com>
Message-ID: 

Russ wrote:

>> you're forgetting that you're dealing with "squeaky wheel contributors"
>> here, not the kind of nice and helpful persons that actually make open
>> source work.
> 
> Please refrain from dishing out gratutious insults until you have a
> clue what you are talking about. It just so happens that I *have* made
> significant contributions to open-source software.

     http://sourceforge.net/tracker/?group_id=5470&atid=355470





From http  Mon Dec 11 11:05:19 2006
From: http (Paul Rubin)
Date: 11 Dec 2006 08:05:19 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>
	<1165769504.098173.101860@j72g2000cwa.googlegroups.com>
	<1165849055.492230.119310@n67g2000cwd.googlegroups.com>
	
Message-ID: <7xslfmju4g.fsf@ruckus.brouhaha.com>

Marc 'BlackJack' Rintsch  writes:
> FYI: Here's how Nemerle does macros: http://nemerle.org/Macros
> 
> I guess you can't really transform Nemerle into a completely different
> language, but it is at least interesting to see such a feature in language
> with a more complex syntax than Lisp.

Nobody seems to concerned that Haskell lacks macros.  What's up with that?


From bignose+hates-spam at benfinney.id.au  Wed Dec  6 23:24:15 2006
From: bignose+hates-spam at benfinney.id.au (Ben Finney)
Date: Thu, 07 Dec 2006 15:24:15 +1100
Subject: Am I stupid or is 'assert' broken in Python 2.5??
References: <1165415689.347819.129680@73g2000cwn.googlegroups.com>
	
	<1165416379.784513.51620@16g2000cwy.googlegroups.com>
	
	
Message-ID: <87ac20pc40.fsf@benfinney.id.au>

Neil Cerutti  writes:

> On 2006-12-07, Gabriel Genellina  wrote:
> > The same reason you can sometimes find what's wrong just by
> > explaining the symptoms to another guy... Having to put things
> > sorted and simple to understand by another, just makes you think
> > clearly on the problem...
>
> I read a story (was it by Brian Kernighan?) the they required
> programmers to tell their problem to a stuffed animal first before
> bothering another programmer who might be in the middle of
> something. The stuffed animal often provided all the assistance that
> was needed.

This is now known as "rubber ducking", and it was indeed documented in
"The Pragmatic Programmer", a highly recommended tome.

    

-- 
 \       "Even if the voices in my head are not real, they have pretty |
  `\                                        good ideas."  -- Anonymous |
_o__)                                                                  |
Ben Finney



From daniel.dittmar at sap.com  Fri Dec  8 07:11:20 2006
From: daniel.dittmar at sap.com (Daniel Dittmar)
Date: Fri, 08 Dec 2006 13:11:20 +0100
Subject: Common Python Idioms
In-Reply-To: <1165518199.729518.112450@79g2000cws.googlegroups.com>
References: 
	<17783.32458.730462.8403@montanaro.dyndns.org>
	
	<1165493298.205945.162430@n67g2000cwd.googlegroups.com>
	
	
	<1165518199.729518.112450@79g2000cws.googlegroups.com>
Message-ID: 

John Machin wrote:
> No it doesn't look wrong to anyone who has read the docs on
> sys.modules. 

My point was really that there is no obvious implementation for 'in' on 
dictionaries, so it should have been left out. And that GvR thought so 
for quite some time as well (until he got mixed up with a crowd of ex 
C++ programmers).

Daniel


From uymqlp502 at sneakemail.com  Mon Dec  4 00:52:42 2006
From: uymqlp502 at sneakemail.com (Russ)
Date: 3 Dec 2006 21:52:42 -0800
Subject: Why not just show the out-of-range index?
In-Reply-To: <1165210093.570351.288220@n67g2000cwd.googlegroups.com>
References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com>
	
	<1165210093.570351.288220@n67g2000cwd.googlegroups.com>
Message-ID: <1165211562.329647.164170@f1g2000cwa.googlegroups.com>

John Machin wrote:

> Perhaps a better analogy is that the OP has observed (correctly IMHO)
> that the robes of *all* Pythonistas, including those not yet born and
> those not yet converted from heathen languages, could be whiter than
> what they are. There are others whose capability to implement an
> enhancement is likely to be much greater than his.

I love Python, but every time I get an out-of-range error message, I
wonder why it didn't just tell me what the out-of-range index was and
what the allowable range was. Certainly that information must be
available to the exception handler, or how would it know that it is out
of range? And no, it's not a big deal, maybe it's even trivial, but
after about the 100th time I finally decided to suggest that it be
fixed. I started with comp.lang.python because I had no idea whether
this issue had been dealt with already, but I am certainly willing to
file a feature request if necessary.

> Would the following be acceptable, BTW?
>
> | >>> [4, 5, 6][10]
> | IndexError: list index 10 out of range(3)
> | >>> [4, 5, 6][-4]
> | IndexError: list index -4 out of range(3)

That seems fine to me.

> Footnote: Based on 2.4.3 source, quite a few files, many with multiple
> lines to patch:

Holy cow! I can't believe that many changes would be necessary unless
the IndexError exception is scattered all over the place. I would hope
that one well-placed change could fix the bulk of cases.

Oh, and thanks for bringing your attention to this matter. This is one
of those little issues that comes up so often that I think fixing it
could make a significant difference in the overall efficiency of Python
programming.



From belred at gmail.com  Mon Dec 11 02:13:25 2006
From: belred at gmail.com (Bryan)
Date: Sun, 10 Dec 2006 23:13:25 -0800
Subject: alternate language
Message-ID: 

what is a good alternate language to learn? i just want something to expand
my mind and hopefully reduce or delay any chance of alzheimer's. i would
especially like to hear from those of you who learned python _before_ these
languages.

haskell, erlang, ocaml, mozart/oz, rebel, etc.

i don't require any of these features, but extra browny points for any of
the following:

interactive interpreter
batteries included
can integrate with c
compiles to native code
can use a gui toolkit such as wx
doesn't take 60 hour weeks over years to master


thanks,

bryan






From aidan at aidans.org  Mon Dec 11 22:49:43 2006
From: aidan at aidans.org (Aidan Steele)
Date: Tue, 12 Dec 2006 14:49:43 +1100
Subject: Tarfile .bz2
In-Reply-To: <1165887178.775792.142820@80g2000cwy.googlegroups.com>
References: <1165871335.386540.29770@l12g2000cwl.googlegroups.com>
	
	<1165887178.775792.142820@80g2000cwy.googlegroups.com>
Message-ID: <364538570612111949k58383c8dv6252f502f2af37b8@mail.gmail.com>

As far as I know, tar.gz and tar.bz2 files work in exactly the same way, but
use different algorithms. That is to say, all the files are 'tarballed'
together, then the resulting very long string is run through the gz bz2
algorithm and out pops the compressed file. (These compression algorithms
work on arbitrary strings, not files per se.)

Why are you trying to losslessly compress JPG and PNG files? Chances are you
won't be able to compress them any more, but if you're trying to free space,
take a looksy at "pngcrush". You'll find it on Google - I don't want to put
any hyperlinks in this email lest it is marked as spam.

Hope I've helped,
Aidan.

On 11 Dec 2006 17:32:58 -0800, Jordan  wrote:
>
> So that would explain why a tar.bz2 archive can't be appended to
> wouldn't it...  And also explain why winrar was so slow to open it (not
> something I mentioned before, but definitely noticed).  I had wondered
> what it was that made bz2 so much better at compression than zip and
> rar.  Not really on topic anymore but what's the method for tar.gz? And
> even more off the topic, does anyone know a good lossless compression
> method for images (mainly .jpg and .png)?
>
> Cheers,
> Jordan
>
>
> Wolfgang Draxinger wrote:
> > Jordan wrote:
> >
> > > When using python to create a tar.bz2 archive, and then using
> > > winrar to open the archive, it can't tell what the compressed
> > > size of each
> > > individual file in the archive is.  Is this an issue with
> > > winrar or is there something that needs to be set when making
> > > the archive that isn't there by default.
> >
> > When compressing a tar archive all files in the archive are
> > compressed as a whole, i.e. you can only specify a compression
> > ration for the whole archive and not just for a single file.
> >
> > Technically a tar.bz2 is actually a aggregation of multiple files
> > into a single tar file, which is then compressed.
> >
> > This is different to e.g. PKZip in which each file is compressed
> > individually and the compressed files are then merged into an
> > archive.
> >
> > The first method has better compression ratio, since redundancies
> > among files are compressed, too, whereas the latter is better if
> > you need random access to the individual files.
> >
> > Wolfgang Draxinger
> > --
> > E-Mail address works, Jabber: hexarith at jabber.org, ICQ: 134682867
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From p at ulmcnett.com  Fri Dec 29 23:35:22 2006
From: p at ulmcnett.com (Paul McNett)
Date: Fri, 29 Dec 2006 23:35:22 -0500
Subject: DOS, UNIX and tabs
In-Reply-To: 
References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com>	
	
Message-ID: <4595EC8A.8080403@ulmcnett.com>

Steven D'Aprano wrote:
> But I think we all agree that mixing tabs and spaces is A Very Bad Thing.

I like mixing tabs and spaces, actually. Tabs for indentation, and 
additional spaces to make the code "look pretty". Somebody please tell 
me why this is bad and I'll stop.

class Apple(object):
	def contrived_example_function(self, argument1, argument2,
	                               argument3, argument4):
		print "hello, world"

Apparently, emacs in python mode follows this convention, too. I like it 
because I get the best of both worlds: the only thing against using 
tabs-only-indentation is that wrapping long lines can be quite ugly, 
while space-only-indentation allows for beautifying it somewhat by 
lining up the columns to match. Tabs+spaces allows the "lining up" with 
spaces to be explicitly separate from indentation.

-- 
pkm ~ http://paulmcnett.com



From ljelmore at verizon.spammenot.net  Sat Dec  9 20:26:11 2006
From: ljelmore at verizon.spammenot.net (Larry Elmore)
Date: Sun, 10 Dec 2006 01:26:11 GMT
Subject: merits of Lisp vs Python
In-Reply-To: <1165700999.744643.207110@73g2000cwn.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
	<1165698244.563344.62270@73g2000cwn.googlegroups.com>
	
	<1165700999.744643.207110@73g2000cwn.googlegroups.com>
Message-ID: 

mystilleef wrote:
> John Thingstad wrote:
>> You are just being silly.
>> Lisp's OO environment CLOS is vastly superior to Python classes.
>> Both in terms of expressive power and flexibility.
>> You might even find out if you ever learnt how to use it.
>>
> 
> Donkeys have wings.

And thus you think you can fly?

>> In the windows world the best way to access system libraries are
>> via .NET. Thus each language inventing it's own libraries is quickly
>> becoming
> 
> You're only proving my point. Why do you think most windows developers
> use .NET?

I didn't realize .NET is a *language*.

>> Python is fine if you approach programming as Lego, simply gluing together
>> libraries.
> 
> You mean it's fine for what 90% of programmers do?
> 
>> But if you want to do some serious algorithmic's you may find that it is
>> just to slow.
> 
> Slow for users who aren't familiar with Psyco, Pyrex and C extensions,
> sure.
> 


From S.Mientki-nospam at mailbox.kun.nl  Wed Dec 27 14:31:25 2006
From: S.Mientki-nospam at mailbox.kun.nl (Stef Mientki)
Date: Wed, 27 Dec 2006 20:31:25 +0100
Subject: persistant gloabl vars (very newbie) ?
In-Reply-To: 
References: 
	<4592af12$1@nntp.zianet.com> 
Message-ID: <411f8$4592c9fe$d443bb3a$30198@news.speedlinq.nl>

> other module that has done 'from init import *'.
> 
> If you want that kind of behaviour it is better to use: 'import init' and
> refer to the variables as init.X and init.Y so that you can change them.
> Whether that is a good idea is another matter.
> 
> There are other reasons for not using the from init import * form, as you
> might overwrite bindings in the module in an unforseen way. from init
> import X,Y explicitely is probably safer. And, by the way, from init import
> * can only be used at module level, not in inner namespaces.

thank you guys,
but it's still not quit handy

# initialization file (init1.py)
import time;
xx = 44

# main file was
print xx
x=time.time()

# main file should become
print init1.xx
x=init1.time.time()

so even for the "standard" functions like "time" I've to include the 
preceeding module "init1" :-(

cheers,
Stef Mientki


From robert.kern at gmail.com  Sat Dec 30 23:30:02 2006
From: robert.kern at gmail.com (Robert Kern)
Date: Sat, 30 Dec 2006 23:30:02 -0500
Subject: Wow, Python much faster than MatLab
In-Reply-To: <1167537081.949722.306510@h40g2000cwb.googlegroups.com>
References: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl>
	<1167537081.949722.306510@h40g2000cwb.googlegroups.com>
Message-ID: 

sturlamolden wrote:
> array3[:] = array1[:] + array2[:]

OT, but why are you slicing array1 and array2? All that does is create new array
objects pointing to the same data.

> Now for my question: operator overloading is (as shown) not the
> solution to efficient scientific computing. It creates serious bloat
> where it is undesired. Can NumPy's performance be improved by adding
> the array types to the Python language it self? Or are the dynamic
> nature of Python preventing this?

Pretty much. Making the array types builtin rather than from a third party
module doesn't really change anything. However, if type inferencing tools like
psyco are taught about numpy arrays like they are already taught about ints,
then one could do make it avoid temporaries.

-- 
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



From tayssir.john at googlemail.com  Sat Dec  9 14:00:19 2006
From: tayssir.john at googlemail.com (tayssir.john at googlemail.com)
Date: 9 Dec 2006 11:00:19 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06>
	<1165649882.563957.87770@n67g2000cwd.googlegroups.com>
	
	<457abf83.18014323@news.readfreenews.net>
	
Message-ID: <1165690819.904549.29680@j44g2000cwa.googlegroups.com>

Steven D'Aprano wrote:
> With Lisp macros, even that isn't guaranteed. Now, if Lispers would say
> "Oh yes, macros give you great power, and with great power comes great
> responsibility. Be careful." then, no doubt, we'd take you guys more
> seriously.

Who are "we"? I was a heavy Python and Java user before being aware of
Lisp. I knew even then that there was something wrong with the
programming world, because there were too many programming patterns I
could not automate away within the language. It's ironic to be a
programmer who can't automate her own work.

I told people that programming was just "glorified accounting." I
shrugged when reading about how complexity was exploding, because that
was the language designers' job to manage it.

Upon hearing of Lisp, I taught it to myself alone, because it was
important. Despite all the FUD, despite all the people who presumed
that a language designer was smarter than his users. I came to realize
that the programming world was full of users who repeated "conventional
wisdom" based on generalities they heard from a friend of a friend of
an evangelist of a corporation -- and worse yet, I was part of that
culture and picked up those poor habits.


> Now, if you want to tell me that, despite all the talk, Lisp coders don't
> actually create new syntax or mini-languages all that often, that they
> just use macros as functions, then the question becomes: why do you need
> macros then if you are just using them as functions? Why not use functions?

You may wish to read the following:


Perhaps Lisp becomes clearer once you see its syntactic similarity with
a very mainstream language -- XML. (But sexps are far more lucid than
XML.) Then we can seriously talk about the real-world engineering
implications of macros, and other powerful features which aren't so
hyped as macros.


Tayssir



From usenet-mail-0306.20.chr0n0ss at spamgourmet.com  Mon Dec 11 11:39:49 2006
From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann)
Date: Mon, 11 Dec 2006 17:39:49 +0100
Subject: wxPython: Icon aus base64 decoded Image
References: <1165829936.372334.53740@79g2000cws.googlegroups.com>
Message-ID: <4u5fulF16h08rU1@mid.individual.net>

Roland Rickborn wrote:

> Wo ist der Fehler und was muss ich machen, damit das Icon
> angezeigt wird?

I'm sorry that I can't help you, but you'll probably get more
answers if you write again in English (this is comp.lang.python).

Gr??e,


Bj?rn

-- 
BOFH excuse #126:

it has Intel Inside



From kuantiko at escomposlinux.org  Sun Dec 10 11:01:18 2006
From: kuantiko at escomposlinux.org (=?ISO-8859-15?Q?Jes=FAs_Carrete_Monta=F1a?=)
Date: Sun, 10 Dec 2006 17:01:18 +0100
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>
Message-ID: 

> Fast. Very fast!
> 
> - Paddy.


Well, Python certainly is faster than most people doing floating-point
arithmetic by hand, but I don't think this is the correct argument to use
against Lisp :-P.



From fredrik at pythonware.com  Mon Dec  4 17:17:24 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Mon, 04 Dec 2006 23:17:24 +0100
Subject: Convert PNG files to BMP files using PIL
In-Reply-To: <1165270056.488786.210090@n67g2000cwd.googlegroups.com>
References: <1165270056.488786.210090@n67g2000cwd.googlegroups.com>
Message-ID: 

Craig wrote:

> I'm trying to convert some PNG files to bitmap files which can then be
> converted to X11 bitmaps using the im.tobitmap() function.  But the
> error I get when using the im.tobitmap() function on the PNG files I
> get the following error:
> 
>>>> im.tobitmap()

tobitmap() only works for mode "1" images.  if you have something else, 
you need to map it to black & white first, e.g.

 >>> im.convert("1").tobitmap()
 >>> im.convert("1", dither=Image.NONE).tobitmap()
 >>> im.point(table, "1").tobitmap()

etc.





From carsten at uniqsys.com  Wed Dec 20 14:52:40 2006
From: carsten at uniqsys.com (Carsten Haese)
Date: Wed, 20 Dec 2006 14:52:40 -0500
Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects
In-Reply-To: <1166643197.329196.44220@t46g2000cwa.googlegroups.com>
References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com>
	<1166643197.329196.44220@t46g2000cwa.googlegroups.com>
Message-ID: <1166644360.3353.45.camel@dot.uniqsys.com>

On Wed, 2006-12-20 at 11:33 -0800, Mark Peters wrote:
> Warning: I know nothing about the Python ArcGIS stuff.
> 
> The first thing that jumps out at me is your while condition.  You are
> testing "Townshps" when it seems from the code that you should be
> testing "Townshp".  However, the typical Python way to iterate through
> a list for be to use a for loop.
> Perhaps replace the while statement with:
> for Townshp in Townshps:

I was considering suggesting this, but I'm not sure there is much hope
that this would work. The posted code suggests that Townshps.next()
returns "" or None when the end of the list is reached. In order for the
for loop to work, it would have to raise StopIteration instead. (I
suppose it is conceivable that iter(Townshps) would return an object
that does behave in the required manner, but I wouldn't bet a lot of
money on that.)

Of the course if Townshps does not support the iteration protocol, the
for loop could still be written using the iter(callable,sentinel)
pattern, but let's not confuse this poor newbie more than necessary ;)

-Carsten




From Steve.Coates at smiths-aerospace.com  Fri Dec  1 02:50:36 2006
From: Steve.Coates at smiths-aerospace.com (Coates, Steve (ACHE))
Date: Fri, 1 Dec 2006 00:50:36 -0700
Subject: Python Worship
Message-ID: <3082C9F9373DAD43918C64BAC1CF038C02903E5A@COSSMGMBX04.EMAIL.CORP.TLD>


Wow! That must have been a pretty early beta. 

> -----Original Message-----
> From: Nick [mailto:nickle at gmail.com] 
> Sent: 30 November 2006 17:16
> To: python-list at python.org
> Subject: Python Worship
> 
> http://www.sciencedaily.com/releases/2006/11/061130081347.htm
> 
> World's Oldest Ritual Discovered -- Worshipped The Python 70,000 Years
> Ago
> 
> Nick
> 
> 
> 

******************************************
The information contained in, or attached to, this e-mail, may contain confidential information and is intended solely for the use of the individual or entity to whom they are addressed and may be subject to legal privilege.  If you have received this e-mail in error you should notify the sender immediately by reply e-mail, delete the message from your system and notify your system manager.  Please do not copy it for any purpose, or disclose its contents to any other person.  The views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company.  The recipient should check this e-mail and any attachments for the presence of viruses.  The company accepts no liability for any damage caused, directly or indirectly, by any virus transmitted in this email.
******************************************


From DustanGroups at gmail.com  Tue Dec  5 07:14:43 2006
From: DustanGroups at gmail.com (Dustan)
Date: 5 Dec 2006 04:14:43 -0800
Subject: The del statement
In-Reply-To: 
References: 
	 
	
Message-ID: <1165320883.272468.39910@16g2000cwy.googlegroups.com>


Marco Aschwanden wrote:
> > do you find the x[i] syntax for calling the getitem/setitem methods a
> > bit awkward too?  what about HTTP's use of "GET" and "POST" for most
> > about everything ? ;-)
>
> No. I like the x[i] syntax. I use it in every second row of my code and
> getting an item like:
>
> x.getitem(i)

That's spelled "x.__getitem__(i)". Still prefer the method call?

> would be a viable (in this case clumsy) way but here I find the introduced
> syntax justified.
> del on the other hand is used sparingly througout my code. If no del
> keyword would exist, it wouldn't disturb me.

"del x[i]" calls "x.__delitem__(i)". I can't say specifically what
list.__delitem__ does, but looking it up in IDLE (l is an instance of
list):

>>> l.remove

>>> l.__getitem__

>>> l.__delitem__


It seems that list.__delitem__ is a different type than the rest,
called method-wrapper. I can only guess from this point; someone else
is bound to know about this.

> Marco

I can see some builtin functions leaving, but the del keyword isn't
exactly unimportant. Looking at the documentation on the del statement:

http://docs.python.org/ref/del.html

There is no note saying that del is deprecated. That really doesn't
mean anything; it could always become deprecated in the future, but it
doesn't seem likely.



From gal.diskin at gmail.com  Wed Dec 13 08:47:07 2006
From: gal.diskin at gmail.com (Gal Diskin)
Date: 13 Dec 2006 05:47:07 -0800
Subject: Iterating over several lists at once
Message-ID: <1166017627.699257.166740@16g2000cwy.googlegroups.com>

Hi,
I am writing a code that needs to iterate over 3 lists at the same
time, i.e something like this:

for x1 in l1:
    for x2 in l2:
        for x3 in l3:
            print "do something with", x1, x2, x3

What I need to do is go over all n-tuples where the first argument is
from the first list, the second from the second list, and so on...


I was wondering if one could write this more easily in some manner
using only 1 for loop.
What I mean is something like this:

for (x1,x2,x3) in (l1,l2,l3):
    print "do something with", x1, x2, x3

Or maybe like this:

for x1 in l1, x2 in l2, x3 in l3:
    print "do something with", x1, x2, x3

However, this code obviously doesn't work...


I'd be very happy to receive ideas about how to do this in one loop and
with minimal initialization (if at all required).

Thanks in advance,
Gal



From rene at korteklippe.de  Sat Dec 30 21:39:52 2006
From: rene at korteklippe.de (Rene Fleschenberg)
Date: Sun, 31 Dec 2006 03:39:52 +0100
Subject: I want to see all the variables
In-Reply-To: 
References:  <45952426.1080800@websafe.com>
	
	<8yelh.90$Q4.82@newsfe02.lga>
	
	
Message-ID: <459722fc$0$30313$9b4e6d93@newsspool1.arcor-online.net>

johnf wrote:
> Very detailed.  But I was attempting to debug some code which subclassed
> other code. I got a traceback that something like "no
> mySubClass.__source.query() did not exist".  

By (strong) convention, "__" means "not to be accessed from outside the
class, not even from subclasses". The author of the original class does
not want you to access that attribute.

> The superclass had something
> like "myClass.__source.query(sql)" which worked
> but "mySubClass.__source.query(sql)" did not work.  So I tried to debug
> using "dir(myClass.__source)" and got an error.  

"dir(myClass._myClass__source)" should work, as should
"dir(mySubClass._myClass__source)" and "mySubClass._myClass__source".

But remember that it is usually really bad style to do this and that
there is probably a reason why the author of myClass does not want you
to do that. If myClass was written by yourself, simply do not use "__".
Only use "__" when you really know why you are doing it. Otherwise, just
use "_".
See also: http://docs.python.org/ref/atom-identifiers.html

> And I also got error when
> I "dir(mySubClass.__source". So how could I have debugged the problem if
> dir() will not display information on the __source?  I hope that explains
> my issue.

A simple dir() on myClass could have given you a hint on what happens
with __source.

-- 
Ren?
OpenPGP key id: 0x63B1F5DB
JID: rene.fleschenberg at jabber.ccc.de

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: OpenPGP digital signature
URL: 

From remi at cherrypy.org  Tue Dec 19 08:55:35 2006
From: remi at cherrypy.org (Remi)
Date: 19 Dec 2006 05:55:35 -0800
Subject: python-hosting.com projects: dead?
In-Reply-To: <4upr9dF197g6cU1@mid.individual.net>
References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com>
	<1166499192.027000.151290@j72g2000cwa.googlegroups.com>
	<1166499671.678929.25180@n67g2000cwd.googlegroups.com>
	<4upr9dF197g6cU1@mid.individual.net>
Message-ID: <1166536534.892544.95850@73g2000cwn.googlegroups.com>

> > I certainly hope so, but this is what I'm reacting to (from
> > http://www.webfaction.com/freetrac):
> >
> > "We're sorry, we're not longer accepting applications for free trac/svn
> > accounts. People have left their Trac sites unattended and as a result
> > our server is being flooded with spam. We need to do some serious
> > cleanup and when that's done we'll accept new applications again (that
> > might take weeks, if not months though). "
>
> Um, that sounds to me like they're not accepting *new*
> projects, not that they're shutting down existing ones.
> Unless *my* reading comprehension skills have completely
> abandoned me.

Your reading comprehension skills are fine :)

We're not accepting *new* projects anymore (for now), but we certainly
continue to support existing ones. We would never take down the sites
without at least a one month warning ... not that we have any plan to
do so anyway...

We had to do some serious cleanup and we disabled a lot of Trac sites
that looked abandoned (people left their Trac sites open to spammers
and our server was crawling under the load caused by these spammers).

If your site got disabled by mistake just e-mail us and we'll re-enable
it within minutes ...

Remi.



From bjourne at gmail.com  Mon Dec 25 18:48:24 2006
From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=)
Date: Mon, 25 Dec 2006 23:48:24 +0000
Subject: Generating all permutations from a regexp
In-Reply-To: <740c3aec0612220630l39be117fu7977a7a2fb6e9998@mail.gmail.com>
References: <740c3aec0612220630l39be117fu7977a7a2fb6e9998@mail.gmail.com>
Message-ID: <740c3aec0612251548k1284eae7rbdbcc3ec397ee298@mail.gmail.com>

With some help from the sre_parse module (and the Python Cookbook),
here is the completed module:

# -*- coding: utf-8 -*-
import itertools
from sre_constants import *
import sre_parse
import string

category_chars = {
    CATEGORY_DIGIT : string.digits,
    CATEGORY_SPACE : string.whitespace,
    CATEGORY_WORD  : string.digits + string.letters + '_'
    }

def unique_extend(res_list, list):
    for item in list:
        if item not in res_list:
            res_list.append(item)

def handle_any(val):
    """
    This is different from normal regexp matching. It only matches
    printable ASCII characters.
    """
    return string.printable

def handle_branch((tok, val)):
    all_opts = []
    for toks in val:
        opts = permute_toks(toks)
        unique_extend(all_opts, opts)
    return all_opts

def handle_category(val):
    return list(category_chars[val])

def handle_in(val):
    out = []
    for tok, val in val:
        out += handle_tok(tok, val)
    return out

def handle_literal(val):
    return [chr(val)]

def handle_max_repeat((min, max, val)):
    """
    Handle a repeat token such as {x,y} or ?.
    """
    subtok, subval = val[0]

    if max > 5000:
        # max is the number of cartesian join operations needed to be
        # carried out. More than 5000 consumes way to much memory.
        raise ValueError("To many repetitions requested (%d)" % max)

    optlist = handle_tok(subtok, subval)

    iterlist = []
    for x in range(min, max + 1):
        joined = join([optlist] * x)
        iterlist.append(joined)

    return (''.join(it) for it in itertools.chain(*iterlist))

def handle_range(val):
    lo, hi = val
    return (chr(x) for x in range(lo, hi + 1))

def handle_subpattern(val):
    return list(permute_toks(val[1]))

def handle_tok(tok, val):
    """
    Returns a list of strings of possible permutations for this regexp
    token.
    """
    handlers = {
        ANY        : handle_any,
        BRANCH     : handle_branch,
        CATEGORY   : handle_category,
        LITERAL    : handle_literal,
        IN         : handle_in,
        MAX_REPEAT : handle_max_repeat,
        RANGE      : handle_range,
        SUBPATTERN : handle_subpattern}
    try:
        return handlers[tok](val)
    except KeyError, e:
        fmt = "Unsupported regular expression construct: %s"
        raise ValueError(fmt % tok)

def permute_toks(toks):
    """
    Returns a generator of strings of possible permutations for this
    regexp token list.
    """
    lists = [handle_tok(tok, val) for tok, val in toks]
    return (''.join(it) for it in join(lists))

def join(iterlist):
    """
    Cartesian join as an iterator of the supplied sequences. Borrowed
    from:
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302478
    """
    def rloop(seqin, comb):
        if seqin:
            for item in seqin[0]:
                newcomb = comb + [item]
                for item in rloop(seqin[1:], newcomb):
                    yield item
        else:
            yield comb
    return rloop(iterlist, [])

########## PUBLIC API ####################

def ipermute(p):
    toks = [tok_n_val for tok_n_val in sre_parse.parse(p)]
    return permute_toks(toks)

def permute(p):
    return list(ipermute(p))

Used like this:

from permute import ipermute

for s in ipermute('[A-Z]\d'):
    print s

Almost all regular expression constructs are supported except for '*'
(which in the Python sre_parse implementation matches 0 to 65535
times), '+' and '^'. Non-ASCII characters doesn't work, but I think
that is a limitation in the sre_parse module. It works by first
parsing the regexp to string sequences so that [A-Z] becomes ['A',
'B', ... 'Z'], \d becomes ['1', ... , '9']. Then a Cartesian join is
applied on all string sequences to get all possible permutations of
them all.

Suggestions for improvements very much appreciated.

-- 
mvh Bj?rn


From xscottg at gmail.com  Sat Dec 16 14:18:34 2006
From: xscottg at gmail.com (xscottg at gmail.com)
Date: 16 Dec 2006 11:18:34 -0800
Subject: merits of Lisp vs Python
References: 
	
	
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	 
	<4ubu3nF16kv7aU1@mid.individual.net> 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net> 
	 <4ucmndF17nmp0U1@mid.individual.net>
	
	<1166175804.202131.54070@l12g2000cwl.googlegroups.com>
	
Message-ID: <1166296713.967467.44490@73g2000cwn.googlegroups.com>

Ken Tilton wrote:
> xscottg at gmail.com wrote:
> >
> > Code is data is code
>
> I was hoping no one would make that mistake. :) macros are all about
> code is data, but code is not data in Python* so the two words code and
> data serve to differentiate them for Pythonistas.
>

I disagree.  I frequently write data-driven algorithms in C and Python
(data is code).  I occasionally write code-generators too (code is
data).  Just because the representation is different between code and
data in those languages doesn't mean that you can't use data as code
(interpreter style) or generate code as data (compiler style).  (I
won't bother boring you with the Python bytecode hacks or the parser
module, because I think those are not terribly practical.)

It's very elegant that Lisp makes the representations between code and
data so similar, but it looks like you know the mantra and not the
meaning if you can't apply that principle in other languages.

BTW...  Even in Scheme, I have to use syntax-object->datum and it's
inverse to switch between the two.  I suspect this has something to do
with the other context that must be associated with the data to turn it
into code.  Probably at least the enclosing environment for lexical
scoping and the line numbers for debugging or exception handling.  Does
Common Lisp maintain this information with it's macro expansions?  If
so, you have a slight difference between code and data too.  If not,
how do you get the line number when a problem happens in a nested
macro?

Moreover, if you really want to be pedantic about what "is" means in
"code is data", then you have to acknowledge that data is a superset of
code, since all code is obviously data, but there are plenty of types
of data that aren't used as code.  Or are they?  :-)


> *  Taking questions after a keynote to ILC200? where he reiterated that
> Python was the same as Lisp for all intents and purposes:
>
> Norvig: "Yes, John?"
> McCarthy: "Is code also data in Python?"
> Norvig: "No."
>
> End of exchange. :)
>

Really?  You're relying on an appeal to authority?  Ok, I'm going to
start arguing by analogy then...



> >    def reverse(cls, *args):
> >      # I didn't understand what your code was doing
>
> yeah, and god forbid you should ask. :) this is the crux of the matter!
>
> Actually, it is kinda cool that you and Greg are semi-identifying the
> crux by saying "this is the only bit I do not get, I'll skip this, move
> on, nothing to see here".
>

Ok, I'll bite.  What does it do?  I read through it, and it looks the
code you're passing to the macro does some things like calculating the
number of decimal digits and generating a 2 + a random number of that
many digits to find a divisor or something.  It also looks like you
have some "string interpolation" to substitute names in your text, but
as a whole, I really don't have any clue what it's all about.

It looks like the macro itself is building some names on the fly and
defining methods (new specializations for multimethods?) with those
names.

So I'm sure I'm missing something, but there is almost certainly a
readable equivalent in Python (and even C).  If you really want to
generate dynamic names for functions, you can do that in Python by
modifying the class or globals hash or whatever.  A more standard way
might be to be have members in the base class.

There is even a multi-methods module in Python, but I've never used it.
 I'd guess you could add to that dynamically too.


> >
> > That would be a reasonable place for a "pie decorator" on a class, but
> > I guess that's not allowed.
>
> Hmmm. Actually, that is the whole point, all of Python is allowed.
> decorators were used in PyCells, but I never got much of an idea what
> they did. Is there a moral equivalent of a macroexpansion for decorators
> so you can show the before and after?
>

It's Python that doesn't allow you to decorate classes.  (You can
decorate functions, but not classes...)  I made this comment as a
criticism of Python since it seems like a non-orthogonal corner...  It
would have fit in this case.

Decorators are pretty simple:

    @foo
    def bar(): pass

is equivalent to:

    def bar(): pass
    bar = foo(bar)

The callable foo can use whatever it wants to inspect, modify, or wrap
the function bar.

but:

    @foo
    class bar: pass

is not currently allowed, so you have to do

    class bar: pass
    bar = foo(bar)



>
> exactly what we are looking for in this cultural exchange: how would
> Python handle what I am doing with macros in the reverse functions? Make
> it as slick and programmer-friendly (cuz I may get to a hundred of these
> before I am done with Algebra I) as possible. When all the Pythonistas
> proclaim it optimal, then we compare and contrast.
>
> This, btw, is the Tilton Test for language comparison: Not measurements
> of programmer effort, rather examination of perfect equivalent code.
> PyCells vs Cells would be an amazing case, because that is some hairy
> functionality.
>

That seems like a fine strategy.  I fall more on the programmer effort
side.  I want to write as little code as possible in a readable way
such that it meets the requirements.

I'm not a particularly good ambassador for Python.  I know Python much
better than Lisp (Scheme), but I already think Scheme is a better
language.  Macros are part of that.  I'm mostly playing devil's
advocate here because I don't think your example really brings it home.
 I've got limited time that I'm willing to invest in learning your
algebra system, but I haven't seen (understood, if you insist) anything
yet that couldn't be done readably in Python.  If you want Common Lisp
to win in your language battle against the Pythonistas, you're going to
need to break out with something stronger.  Then again, you're probably
pissing into the wind anyway.


Cheers,
    -Scott



From nospam at domain.tld  Wed Dec  6 00:17:40 2006
From: nospam at domain.tld (Stephan Kuhagen)
Date: Wed, 06 Dec 2006 06:17:40 +0100
Subject: Coding standards without control?
References: <1165321106.614601.95530@79g2000cws.googlegroups.com>
	
Message-ID: 

Soni Bergraj wrote:

> editormt wrote:
>> A majority of the participating organisations have coding standards...
>> and a majority does not control them ;o) What is the situation at your
>> location? Does this lack of control really hurt?
> 
> """A Foolish Consistency is the Hobgoblin of Little Minds"""
> 
> from: http://www.python.org/dev/peps/pep-0008/
> 
> Python makes coding standards obsolete;)

No, it does not. If you have a team of, say, 50 programmers, everyone
following his own mind-to-ascii-mapping, you are very soon in a situation,
where code is completely unmaintainable.

But Python has the advantage, that your coding standards can concentrate on
the important things and skip most of the formatting rules, that are often
part of other languages coding standards.

To the control part: this is where Python comes in for general coding
standards. Many rules of coding standards can be tested automatically and
Python is a good choice for text processing and checking source code
against the rules of a coding standard. I wrote a Python package for a
subset of our coding standards and that is a very useful tool to check some
100k files.

Regards
Stephan


From paul at boddie.org.uk  Tue Dec  5 05:34:46 2006
From: paul at boddie.org.uk (Paul Boddie)
Date: 5 Dec 2006 02:34:46 -0800
Subject: Python-URL! - weekly Python news and links (Dec 4)
References: 
	
Message-ID: <1165314886.042138.28310@f1g2000cwa.googlegroups.com>

Terry Reedy wrote:
> "Paul Boddie"  wrote in message
> news:el1ru1$gql$1 at lairds.us...
> >    The One Laptop Per Child developers and testers briefly consider Python
> >    development environments (in the context of things Alan Kay presented at
> >    EuroPython 2006):
> >
> > http://mailman.laptop.org/pipermail/devel/2006-November/003176.html
>
> But the only thing about Python here is "(Is somebody going
> to write a Python development environment for children?)"

Yes, it's a bit tenuous, but the context and further discussion is
where the interesting stuff is. At EuroPython, Alan Kay gave a keynote
which focused a lot on the Etoys and Squeak body of work, which is
where users (with children particularly in mind) can experiment with
different ideas in an interactive graphical environment based on
autonomous objects with editable behaviour. Since Squeak is an
image-based environment, a lot of the "view source" functionality comes
for free, whereas Python, despite its apparent similarities with
Smalltalk and Lisp, doesn't appear to have quite the same level of
convenient support for both live editing of objects and process
persistence.

The next message in the thread referenced above mentions Pygame, which
is where a lot of people believe such work should be done with Python.
Perhaps the Python density in that thread isn't great - it's not a
bunch of core developers agonising over C API minutiae - but the
significance of the project along with the issues involved is certainly
worth exploring.

> >    E..and the best way to try the latest Python-related developments
> >    in the OLPC project:
> >        http://mail.python.org/pipermail/edu-sig/2006-December/007441.html
>
> And this has no obvious relation to its description

The Sugar environment is the user interface for the OLPC project. If
you look at the "human interface guidelines", you'll see the following:

"To enable such layered exploration, OLPC has written much of what can
be in Python, a scripting language, to enable children to view the
source code."

One of the more discussed topics in various places outside the Python
"mainstream" recently was whether it was convenient to try out the
Sugar environment without having the OLPC hardware. The referenced
message attempts to provide some clarity in the matter, but once again
it's the further discussion that adds extra value, I think.

Paul



From david.golden at oceanfree.net  Wed Dec 13 17:28:35 2006
From: david.golden at oceanfree.net (David Golden)
Date: Wed, 13 Dec 2006 22:28:35 +0000
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	
	
	
	<1165991523.013767.224630@73g2000cwn.googlegroups.com>
	<1165998270.742602.23610@f1g2000cwa.googlegroups.com>
	<1166002627.186672.183730@73g2000cwn.googlegroups.com>
Message-ID: 

Actually, in English, "parenthesis" means the bit in between the
brackets.

The various kinds of brackets (amongst other punctuation marks
including, in most english texts, commas) *demarcate* parentheses.

Wikipedia's "Parenthesis (rhetoric)" is, at time of writing, the correct
British English definition, citing the OED:
http://en.wikipedia.org/wiki/Parenthesis_%28rhetoric%29

"An explanatory or qualifying word, clause, or sentence inserted into a
passage with which it has not necessarily any grammatical connection,
and from which it is usually marked off by round or square brackets,
dashes, or commas"

The use of round brackets to demarcate parentheses in america eventually
somehow led to round brackets themselves being called parentheses in
america, but that usage still makes little sense to many native
speakers of British (or Hiberno-) English outside the computing field.

It's like calling a quotation mark a "quote" instead of a "quotation
mark".  And lo, guess who does that too...

Calling round brackets "parenthesis marks" would be acceptable but
perhaps ambiguous in British English, probably needing further
qualification like "double quotation mark", "single quotation mark".














From metaperl at gmail.com  Fri Dec  8 11:42:34 2006
From: metaperl at gmail.com (metaperl)
Date: 8 Dec 2006 08:42:34 -0800
Subject: shell command needs whitespace characters escaped
Message-ID: <1165596153.961003.285080@16g2000cwy.googlegroups.com>

I downloaded a file which has a space in the filename. I want to run a
shell unzip on it, but it fails in my current code:

        syscmd = "cd %s ; unzip %s" % (self.storage.input,
file.basename())
        os.system(syscmd)

because no escaping was done.

Is there a more principled way to construct a shell command and execute
it so that all necessary characters are escaped?



From pavlovevidence at gmail.com  Thu Dec 14 02:57:10 2006
From: pavlovevidence at gmail.com (Carl Banks)
Date: 13 Dec 2006 23:57:10 -0800
Subject: Conditional iteration
References: <4580149c$0$321$e4fe514c@news.xs4all.nl>
	<7xwt4vn6gk.fsf@ruckus.brouhaha.com>
	<45804584$0$334$e4fe514c@news.xs4all.nl>
	<1166037659.362222.290520@t46g2000cwa.googlegroups.com>
	<4580821a$0$334$e4fe514c@news.xs4all.nl>
	<1166062230.798520.135790@f1g2000cwa.googlegroups.com>
	<4580f7f4$0$331$e4fe514c@news.xs4all.nl>
Message-ID: <1166083030.124212.58460@73g2000cwn.googlegroups.com>

at wrote:
> Carl Banks wrote:
>
> > at wrote:
> >> Well, all I can say that for me as a user it would make sense...
> >
> > Which is, like, step one out of a hundred for getting a syntax change
> > into the language.
> >
> >> Curiosity: in what sense is it redundant?
> >
> > It creates syntactical support for two different ways to do something.
> > If your plan were adopted, then we'd have two different spellings for
> > the same thing:
> >
> > for i in a:
> >     if i != 0:
> >         use(i)
> >
> > for i in a if i != 0:
> >     use(i)
>
> With the current Python syntax, I can create for every two lines of code a
> dozen alternative implementations:
>
> # example 1
> a = {}
> a['b'] = 'c'
>
> versus:
> a = {'b': 'c'}
>
>
> # example 2
> l = []
> for l in some_list:
>         if some_condition:
>                 l.append(l)
>
> versus:
> l = []
> for x in some_list:
>         if some_condition:
>                 l = l + [x]
>
> or:
> l = [x for x in some_list if some_condition]
>
> (the beautiful one)
>
> So your argument doesn't mean much I would say!

That's a pretty asinine and/or stupid thing for you to say, since you
took my argument completely out of context.  In particular, you ignored
the following paragraph, where I weighed the benefits of the new syntax
versus the cost of redundancy.

Have you done that in your counterexamples?  Did you weigh the
benefits, and somehow conclude that what different the syntaxes in the
counterexamples buy is just as little as what your proposal buys?  No,
you didn't.

Next time, wait till I've actually made my argument before passing
judgment on whether it means anything.


> > Now, redundant syntax isn't a deal breaker by itself.  You have to ask
> > what is buys you.  In this case, all it does is save you a single level
> > of indentation--that's it.  There's no performance benefit.  It doesn't
> > simplify logic.  It doesn't make the code any more readable of clear.
> > It's only a minor improvement in conciseness.  It hardly saves any
> > typing (unless you indent by hand).  Even its one clear benefit, saving
> > indentation, is something you can already get with "if not x:
> > continue".
>
>
> Well there is a clear performance benefit, or more precisely a productivity
> benefit.

Performance and productivity aren't the same thing.  There is no
peformance benefit of your syntax.  Productivity is not so clear cut.
You might be able to argue that there's some marginal productivity
benefit to using your syntax, but I can't imagine it'd be anything
substantial.


> And -please- do not underestimate this for a language like Python,
> which has many supporters due to its perceived and high productivity and
> challenged on this point by languages like Ruby.
>
> 'for x in some_list if some_condition:'
>
> is psychological very strong, because the brain will most likely treat the
> in the same way as :
>
>         for every apple in the fruitbasket take one if green
>
>
> Basically upon reading this first line you know exactly to what list of
> items your next section of code applies.

I don't understand why this wouldn't also apply if the if statement
happens to be on the following line.  I still think all this is is
whining about the extra indentation.


> But again everything is a matter of taste and I assume that's why the change
> control body is put into the hand of one person.
[snip]
> >> Does Guido ever change his mind?
> >
> > Yes, but I guarantee "it makes sense for me" isn't going to convince
> > him.  By the way, I'd suggest when posting to comp.lang.python and/or
> > python-list in the future, you put your replies beneath the quoted text
> > for the benefit of any future readers (not to mention present readers).
>
> I hope this this thread will support the "it makes sense for me" with
> arguments. Again it is not my intention to fight windmills,

I would just stop right now, then.  It's not going to change.

> but to see if
> there are strong arguments against it on one hand and if there supporters
> on the other hand.


Carl Banks



From gerard.blais at gmail.com  Mon Dec 18 16:28:08 2006
From: gerard.blais at gmail.com (Gerry)
Date: 18 Dec 2006 13:28:08 -0800
Subject: pyExcelerator question
Message-ID: <1166477288.063934.221390@t46g2000cwa.googlegroups.com>


I'd like to word wrap some cells, but not others, in an Excel
spreadsheet, using pyExcelerator and Excel 2003, SP1, under XP.

The code below creates the spreadsheet, but both cells are
word-wrapped.

As far as I can tell, the second call to XFStyle() overwrites a GLOBAL
wrap setting, and affects even cells written before the call to
XFStyle.

Can anyone shed any light?

Thanks,

Gerry

============================
from pyExcelerator import *


w   = Workbook()
ws  = w.add_sheet("alpha")

style                   = XFStyle()
style.alignment.wrap    = Alignment.NOT_WRAP_AT_RIGHT
ws.write(1,1,"Not wrapped" + "-" * 50, style)

style2                   = XFStyle()
style2.alignment.wrap    = Alignment.WRAP_AT_RIGHT
ws.write(2,1,"Wrapped" + "-" * 50, style2)

w.save("test.xls")



From jm.suresh at gmail.com  Thu Dec 14 08:23:33 2006
From: jm.suresh at gmail.com (jm.suresh@no.spam.gmail.com)
Date: 14 Dec 2006 05:23:33 -0800
Subject: Multiple inheritance and __slots__
Message-ID: <1166102613.814641.109490@80g2000cwy.googlegroups.com>

Hi all,
>From the google search, it seems its not possible to do the following.

>>> class Test1(object):
...     __slots__ = ['a']
...
>>> class Test2(object):
...     __slots__ = ['b']
...
>>> class Test3(Test1,Test2):
...     __slots__ = ['c']
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict

I just want to make sure that I am using only the attributes a,b and c
from the instances of Test3 . Is there any other hack that could be
done.

--
Suresh



From rpw3 at rpw3.org  Mon Dec 18 06:08:20 2006
From: rpw3 at rpw3.org (Rob Warnock)
Date: Mon, 18 Dec 2006 05:08:20 -0600
Subject: merits of Lisp vs Python
References: <1166342606.141406.137000@f1g2000cwa.googlegroups.com>
	<7x3b7ekk6p.fsf@ruckus.brouhaha.com>
	<1166410256.785907.69140@73g2000cwn.googlegroups.com>
Message-ID: 

 wrote:
+---------------
| Paul Rubin wrote:
| > [...]  There are programs you can write in C but not in Lisp,
| > like device drivers that poke specific machine addresses.
| 
| I should assume you meant Common Lisp, but there isn't really any
| reason you couldn't
|      (poke destination (peek source))
| in some version of Lisp that was meant for writing device drivers
| (perhaps under a Lisp machine or something).
+---------------

I do this kind of thing *every day* in CMUCL!! It's my primary
user-mode hardware debugging tool. Here's a typical utility function:

    ;;; Used for things like polling for a "done" flag.
    ;;; BUG: Assumes contents of ADDR will change within fixnum polls.
    (defun spin-until-change (addr)
      (declare (optimize (speed 3) (debug 0) (safety 0)))
      (loop with v0 of-type (unsigned-byte 32) = (r32 addr)
	    with counts fixnum = 0
	    while (= v0 (r32 addr))
	 do (setf counts (the fixnum (1+ counts)))
	 finally (return counts)))

+---------------
| SIOD actually has (%%% memref address) for peek.
+---------------

CMUCL has SYSTEM:SAP-REF-{8,16,32} and SETFs of same. The R32
above is just my convenience wrapper around SYSTEM:SAP-REF-32:

    (declaim (inline r32))

    (defun r32 (addr)
      (declare (optimize (speed 3) (debug 0) (safety 0)))
      (system:sap-ref-32 (system:int-sap addr) 0))

    (defun w32 (addr &rest values)
      (declare (optimize (speed 3) (debug 0) (safety 0)))
      (loop for i fixnum from 0 by 4
	    and v of-type (unsigned-byte 32) in values
	do (setf (system:sap-ref-32 (system:int-sap addr) i) v))
      (values))

Most other Common Lisp implementations surely have something similar.


-Rob

-----
Rob Warnock			
627 26th Avenue			
San Mateo, CA 94403		(650)572-2607



From address.good.until.2006.dec.22 at justmail.de  Fri Dec 15 13:55:41 2006
From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=)
Date: Fri, 15 Dec 2006 19:55:41 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <1166207152.706475.76020@t46g2000cwa.googlegroups.com>
References: 
	
	
	
	
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	 
	<4ubu3nF16kv7aU1@mid.individual.net> 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<1166207152.706475.76020@t46g2000cwa.googlegroups.com>
Message-ID: 

William James schrieb:

> def nif num, pos, zero, neg
>   send( num>0 ? pos : (num==0 ? zero : neg) )
> end

btw, your nif body is built out of 13 tokens, so more
complicated than the Python version.


Andr?
-- 


From e0427417 at student.tuwien.ac.at  Sat Dec 30 08:23:59 2006
From: e0427417 at student.tuwien.ac.at (Mathias Panzenboeck)
Date: Sat, 30 Dec 2006 14:23:59 +0100
Subject: Wow, Python much faster than MatLab
In-Reply-To: 
References: <2c132$45959329$d443bb3a$19792@news.speedlinq.nl>
	<1167449722.106162.93380@k21g2000cwa.googlegroups.com>
	
Message-ID: <45966848$0$11868$3b214f66@tunews.univie.ac.at>

A other great thing: With rpy you have R bindings for python.
So you have the power of R and the easy syntax and big standard lib of python! :)


From horpner at yahoo.com  Tue Dec 12 23:13:30 2006
From: horpner at yahoo.com (Neil Cerutti)
Date: Wed, 13 Dec 2006 04:13:30 GMT
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	
	<%TBeh.331$tv5.155@newsfe11.lga>
	
	
	
	
	
	<7xfybnjkz4.fsf@ruckus.brouhaha.com>
	
	
	<457d970b$0$31552$426a74cc@news.free.fr>
	
	<7xwt4y6j57.fsf@ruckus.brouhaha.com>
	
	
	<1165973114.451146.295110@j72g2000cwa.googlegroups.com>
Message-ID: 

On 2006-12-13, hit_the_lights  wrote:
> Neil Cerutti schrieb:
>
>> >>   a[i] = b[n]
>> >>
>> >> with
>> >>
>> >>   (setf (aref a i) (aref b n))
>> >>
>> >> and the attractions of Python may make more sense.
>> >
>> > Here Python and Lisp are equal, 7 tokens vs 7 tokens, but in
>> > Python one has to write less since "[]" are 2 chars while
>> > "aref" are 4, plus the setf.  But from counting the brain
>> > units which I regard as an important factor they are both
>> > equal.
>>
>> A comparison of brain units of the above snippets is
>> irrelevant, since the snippets are not equivalent.
>>
>> The Python snippet will work for any object a that provides
>> __setitem__ and any object b that provides __getitem__.
>>
>> I don't know what an equivalent Lisp snippet would be (or even
>> exactly how close the above snippet comes to matching the
>> Python code), but whatever it is would be a better foundation
>> for comparing brain units with the above Python.
>
> It would be exactly like the example given, just "aref"
> replaced with something else. An example implementation:
>
>==========================================
> (defgeneric $ (container key))
> (defgeneric (setf $) (value container key))
>
> ;;; Implementation for arrays
>
> (defmethod $ ((container array) (key integer))
>   (aref container key))
>
> (defmethod (setf $) (value (container array) (key integer))
>   (setf (aref container key) value))
>==========================================
>
> And usage:
>
>==========================================
> CL-USER(3): (defparameter a (vector 1 2 3 4 5))
> A
> CL-USER(4): ($ a 0)
> 1
> CL-USER(5): (setf ($ a 0) 9)
> 9
> CL-USER(6): a
> #(9 2 3 4 5)
>==========================================
>
> The nice thing is, that you *can* dispatch on the container,
> the key and the value.

That's cool. Thanks for posting the code.

Is the above 'duck-typing' idiom considered very useful to a
Lisper? It seems logical to me that duck-typing works best in an
environment where it is ubiquitous. If users have to implement
accessors specifically to use your library, it is not as good as
if they had already implemented one as a matter of routine.

-- 
Neil Cerutti


From steve at REMOVE.THIS.cybersource.com.au  Sun Dec 10 11:30:18 2006
From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano)
Date: Mon, 11 Dec 2006 03:30:18 +1100
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165594621.136524.198600@80g2000cwy.googlegroups.com>
	
	<1165596641.245385.113090@f1g2000cwa.googlegroups.com>
	
	
	<1165704007.887869.192290@16g2000cwy.googlegroups.com>
	
	<87ejr7yhgv.fsf@snobis.de>
Message-ID: 

On Sun, 10 Dec 2006 15:05:04 +0100, Stefan Nobis wrote:

> Steven D'Aprano  writes:
> 
>> Look at us: we're all communicating in a common language, English,
>> and we all agree on syntax and grammar. Now, I could be a lot more
>> expressive, and language could be a lot more powerful, if I could
>> define my own language where "You are a poopy-head" was in fact a
>> detailed and devastatingly accurate and complete explanation for why
>> Python was a better language than Lisp.
> 
>> So it is good that English restricts the expressiveness and power of
>> the syntax and grammar. While we're talking English, we can both
>> understand each other, and in fact people who redefine words and
>> ignore the common meaning of them are often covering weaknesses in
>> their arguments.
> 
> Uh, you don't talk often to non-programmers, do you?

Oh, if you only knew!


> Talk a bit to
> non-programmers about your programming habits, why you prefer which
> programming language and so on. Everything in english. How much do
> they understand?

That depends on how much jargon I use. Jargon, I should point out, is not
necessarily a pejorative term. It can just mean vocabulary used
only in a specialist field, and as such, jargon is very, very important.


> Ever talked to skateboarders? Other people of different scenes? They
> are creating new, specialized languages every day. 

Yes, that's right. And if they insist on using their specialist language
where "that's bad" means "that is best quality", and I insist on using
my language where "that's bad" means "that is worst quality", how much
successful communication are we going to have? 

> Here in Germany a
> study was published a little time ago, how few people understand
> commercials and their slogans.

Which just proves my point. If people don't share the same language
constructs, the same words, the same grammar, etc, they can't understand
each other.

> Do you know how many jokes work? Yes, by misunderstandings. 

http://en.wikipedia.org/wiki/Humour



-- 
Steven.



From fredrik at pythonware.com  Tue Dec 19 11:22:56 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 19 Dec 2006 17:22:56 +0100
Subject: SQLALCHEMY - Method to have the last word, by Michael Bayer
In-Reply-To: <1166544760.081480.44920@n67g2000cwd.googlegroups.com>
References: <1166543077.605993.276770@80g2000cwy.googlegroups.com>	<4uqgeuF19khhgU1@mid.uni-berlin.de>
	<1166544760.081480.44920@n67g2000cwd.googlegroups.com>
Message-ID: 

Ilias Lazaridis wrote:

> How can one contribute?

you can't.





From eadmund42 at NOSPAMgmail.com  Tue Dec 12 11:53:04 2006
From: eadmund42 at NOSPAMgmail.com (Robert Uhl)
Date: Tue, 12 Dec 2006 09:53:04 -0700
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<1165587080.038533.47910@80g2000cwy.googlegroups.com>
	<45797b9b$0$49206$14726298@news.sunsite.dk>
	<4ttiadF15dam8U1@mid.individual.net>
	<45799bf6$0$49202$14726298@news.sunsite.dk>
	<4ttqsoF15ld61U3@mid.individual.net>
	<4579c4f4$0$49201$14726298@news.sunsite.dk>
	
Message-ID: 

Steven D'Aprano  writes:
>
> Speaking as somebody who programmed in FORTH for a while, that doesn't
> impress me much. Prefix/postfix notation is, generally speaking, more
> of a pain in the rear end than it is worth, even if it saves you a
> tiny bit of thought when pasting code.

Of course, you use prefix notation all the time in Python:

  for x in range(0,len(y)):
    dosomething(x)

In the example, 'for,' 'range,' 'len' and 'dosomething' all use
prefix notation.  In Lisp the example might look like this, assuming the
proper functions and macros to make it work:

  (for ((x (range 0 (length y))))
     (dosomething x))

Slightly more idiomatic would be:

  (loop for x in (range 0 (length y))
        do (dosomething x))

Even more idiomatic would be:

  (loop for x below (length y)
        do (dosomething x))

Which doesn't seem particularly more or less prefixy or infixy than the
Python version.

Infix is really only used in arithmetic--and there are Lisp macros which
give one infix notation if wanted, so one could write:

  (infix 1 + x / 4)

-- 
Robert Uhl 
Give a man a fish and you feed him for a day; give him a freshly-charged
Electric Eel and chances are he won't bother you for anything ever again.
                                                --Tanuki the Raccoon-dog


From jjbegin at rightbrainnetworks.com  Tue Dec 19 02:04:40 2006
From: jjbegin at rightbrainnetworks.com (Jamie J. Begin)
Date: Tue, 19 Dec 2006 02:04:40 -0500
Subject: How would I create an class with a "Person.Address.City" property?
Message-ID: <0E551087F64EFF42882BE78F0EAB611404B68F@nexus.rbn.rightbrainnetworks.com>

I'm very new to the world of Python and am trying to wrap my head around
it's OOP model. Much of my OOP experience comes from VB.Net, which is
very different.

Let's say I wanted to create an object that simply outputted something
like this:

>>> import employees
>>> person = employee("joe") # Get Joe's employment file
>>> print employee.Title # What does Joe do?
Developer
>>> print person.Address.City # Which city does Joe live in?
Detroit
>>> print person.Address.State # Which state?
Michigan

To do this would I create nested "Address" class within the "employee"
class? Would it make more sense to just use "print
person.Address('City')" instead?

Thanks for your help!


From kay.schluehr at gmx.net  Mon Dec 11 02:36:57 2006
From: kay.schluehr at gmx.net (Kay Schluehr)
Date: 10 Dec 2006 23:36:57 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165715580.731398.131690@f1g2000cwa.googlegroups.com>
	<1165769504.098173.101860@j72g2000cwa.googlegroups.com>
	<1165793825.487994.52430@f1g2000cwa.googlegroups.com>
	<1165800527.225633.84180@80g2000cwy.googlegroups.com>
	<1165802945.392579.143070@16g2000cwy.googlegroups.com>
Message-ID: <1165822617.347628.113880@73g2000cwn.googlegroups.com>

dixkey at gmail.com schrieb:

> I find it amusing that most of the arguments that python-people are
> making in this thread are actually the arguments that C++ and Java make
> against Python. "Who needs dynamic typing?", "Who needs closures?",
> "The idea of using whitespace for syntax is beyond stupid"... Now the
> python guys obviouly see that that those arguments are bogus, but they
> keep the same reasoning against lisp.

Yes, this structure of argument is the same in *any* discussion about
language design and feature integration. The solution could be laissez
faire but then you have to counteract creating standards for a minimal
contract social. In either way you cut down language feature diversity
and feature implementation redundancy, something macros strongly
encourage. So Lisp is always the right language to start with but what
is the right language to end with? The answer is BASIC and although the
reference to the historical BASIC language is not accidental, I
actually mean all kind of general purpose languages that aim to
facilitate programming in the first place. That's why Python = BASIC or
more accurately Python = ABC. Of course you can start with BASIC too,
instead of Lisp, or Ruby and quote Yukihiro Matsumoto who just wants
happy users - from the very beginning and not just after one month,
when one starts looking through the jungle of parens ( Ken Tilton ) or
perform any other cognitive transformation to ease the pain.

While Pythonistas might defend their language with all kind of typical
nerdish idiocy, Lispers try to convince Pythonistas to be unhappy,
because they lack X, Y and Z and recommend Lisp as the cure. But just
like a beautifull woman, Pythonistas stay unimpressed and do respond:
no, I don't lack anything, I am complete; stay away from me with your
weirdness!



From roman.yakovenko at gmail.com  Thu Dec 21 07:58:41 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Thu, 21 Dec 2006 14:58:41 +0200
Subject: [ANN] Py++ - 0.8.5
In-Reply-To: <7465b6170612210455i71e690c6r3a47f9d337a100dc@mail.gmail.com>
References: <7465b6170612210455i71e690c6r3a47f9d337a100dc@mail.gmail.com>
Message-ID: <7465b6170612210458n3c14722qb621286825128e94@mail.gmail.com>

Hello!

I'm pleased to announce the 0.8.5 release of Py++.

What is Py++?
=============

Py++ is an object-oriented framework for creating a code generator for
Boost.Python library.

Where is Py++?
==============

Site: http://language-binding.net/pyplusplus/pyplusplus.html

Download: http://language-binding.net/pyplusplus/download.html

What's new?
===========

Features
--------

* Added "Function Transformation" feature. This feature allows you to
describe function
  wrapper and Py++ will do the rest.
  Example could be found here:  http://tinyurl.com/y3ec24

* Added new functionality, which allows you to control messages and warnings.

* Adding new algorithm, which controls the registration order of the functions.

* Added new "Py++" defined "return_pointee_value" call policy

* Opaque types are fully supported

* Py++ will check the "completeness" of the bindings. It will check
for you that the exposed
  declarations don't have references to unexposed ones.

Small features
--------------

* It is possible to configure "Py++" to generate faster ( compilation time )
  code for indexing suite version 2.

* The algorithm, which finds all class properties was improved. Now it provides
  a better way to control properties creation. A property that would
hide another
  exposed declaration will not be registered\\created.

* Work around for "custom smart pointer as member variable" Boost.Python bug
  was introduced.

For a more complete list, please see the news:
http://language-binding.net/pyplusplus/history/history.html

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/


From pyenos at pyenos.org  Fri Dec 22 02:42:27 2006
From: pyenos at pyenos.org (Pyenos)
Date: 22 Dec 2006 18:42:27 +1100
Subject: Confusion with calling function of a subclass
Message-ID: <873b78cr6k.fsf@pyenos.pyenos.org>

class TREE:
    def gettree(self):print self
TREE.gettree() # I get an error saying 
               # TypeError: unbound method gettree() must be called
               # with TREE instance as first argument (got nothing instead


I still don't understand how to solve this simple code. 


From niels.ellegaard at gmail.com  Sat Dec  9 07:08:14 2006
From: niels.ellegaard at gmail.com (Niels L Ellegaard)
Date: 9 Dec 2006 04:08:14 -0800
Subject: Automatic debugging of copy by reference errors?
In-Reply-To: <1165645676.694401.193580@16g2000cwy.googlegroups.com>
References: <1165641773.903394.295300@80g2000cwy.googlegroups.com>
	<1165645676.694401.193580@16g2000cwy.googlegroups.com>
Message-ID: <1165666093.996141.244760@n67g2000cwd.googlegroups.com>

Gabriel Genellina wrote:
> I think you got in trouble with something and you're trying to avoid it
> again - but perhaps this is not the right way. Could you provide some
> example?

I have been using scipy for some time now, but in the beginning I made
a few mistakes with copying by reference. The following example is
exagerated
for clarity, but the principle is the same:

import os
output=[]
firstlines =[0,0]
for filename in os.listdir('.'):
    try:
        firstlines[0] = open(filename,"r").readlines()[0]
        firstlines[1] = open(filename,"r").readlines()[1]
       output.append((filename,firstlines))
    except:continue
print output

Now some of my fortran-using friends would like to use python to
analyze their data files. I wanted them to avoid making the same
mistakes as I did so I thought it would be good if they could get some
nanny-like warnings saying: "Watch out young man. If do this, then
python will behave differently from fortran and matlab". That could
teach them to do things the right way.

I am not an expert on all this, but I guessed that it would be possible
to make a set of constraints that could catch a fair deal of simple
errors such as the one above, but still allow for quite a bit of
programming.

                                  Niels



From schronos at yahoo.com  Fri Dec  1 10:49:11 2006
From: schronos at yahoo.com (__schronos__)
Date: 1 Dec 2006 07:49:11 -0800
Subject: good documentation about win32api ??
Message-ID: <1164988151.675036.308920@j44g2000cwa.googlegroups.com>

Hi all.

  Recently I've to developed a project in python that made operation
under win32 platform and I found a lot of problema to find good
information. The only one documentation is in ActivePython page
(http://aspn.activestate.com/ASPN/docs/ASPNTOC-APYTH2.4.0) but it is
not very good and finally I had to turn to the newsgroups (it was very
nice).

  And the question is: ?Anybody knows where can I find good
documentation about win32api?

Thanks in advanced.

  ScnS.



From bdesth.quelquechose at free.quelquepart.fr  Tue Dec 19 16:14:05 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Tue, 19 Dec 2006 22:14:05 +0100
Subject: When Closure get external variable's value?
In-Reply-To: <1166556458.780265.147420@80g2000cwy.googlegroups.com>
References: <1166473333.593246.238580@73g2000cwn.googlegroups.com>
	<1166474513.700608.201760@48g2000cwx.googlegroups.com>
	
	<1166542026.913912.82880@t46g2000cwa.googlegroups.com>
	
	<1166544951.721977.281100@t46g2000cwa.googlegroups.com>
	
	<1166556458.780265.147420@80g2000cwy.googlegroups.com>
Message-ID: <4588505d$0$26434$426a74cc@news.free.fr>

Huayang Xia a ?crit :
> I'm confused. What is the definition of closure.
 >
> I'm not sure if it's correct, I get the definition from wikipedia:
> 
> "A closure typically comes about when one function is declared entirely
> within the body of another, and the inner function refers to local
> variables of the outer function. At runtime, when the outer function
> executes, a closure is formed. It consists of the inner function's code
> and references to any variables in the outer function's scope that the
> closure needs."

You skipped the first and most important sentence:
"In programming languages, a closure is a function that refers to free 
variables in its lexical context."

IOW, a closure is a function that carry it's own environment. In the 
following code, the function returned by make_adder is a closure :

def make_adder(adding):
   def adder(num):
     return num + adding
   return adder


add_three = make_adder(3)
print add_three(4)
=> 7

> I agree it is not declaration, it's definition. However it's closure
> based on the above definition. It uses free variable.

Actually, it uses a variable defined in the enclosing scope. But as long 
as it's also executed in the same enclosing scope, it's just a nested 
function.

> Or you mean it's
> a closure only when the outer function returns it and be exposed to
> external world?

Bingo.


From scott.daniels at acm.org  Tue Dec 26 19:34:56 2006
From: scott.daniels at acm.org (Scott David Daniels)
Date: Tue, 26 Dec 2006 16:34:56 -0800
Subject: How to suppress the output of an external module ?
In-Reply-To: 
References: 
Message-ID: <4591b56a$1@nntp0.pdx.net>

fdu.xiaojf at gmail.com wrote:
> Hi,
> 
> I'm writing a program which uses an external module written in C
> and calls a function provided by the module to do my job.  The
 > function produces a lot of output to the stdout.
> 
> Is there a way to suppress the output produced by the function and 
 > hence make my program run faster?

 > It's too complicated for me to modify the source code and recompile
 > the external module.
This would be the best method, you could define printf and fprintf
macros that would eliminate the output code altogether.

> Any hints will be greatly appreciated.
Well, it will depend on your OS, but the trick is to essentially
replace the C stdout channel with a file which has been opened to
write to "/dev/null" or "NUL.txt" (unix and Windows respectively).
You'll need to first copy the channel to another so you can use
it again after the function is done (a system call). Next do the
raw open (which should get the available channel), and the C stdout
stuff is successfully redirected.  Once done w/ your function,
close your new stdout and copy the channel back.

--Scott David Daniels
scott.daniels at acm.org


From gagsl-py at yahoo.com.ar  Wed Dec 20 17:46:28 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Wed, 20 Dec 2006 19:46:28 -0300
Subject: what is wrong with my code?
In-Reply-To: <874prq6wmd.fsf@pyenos.pyenos.org>
References: <874prq6wmd.fsf@pyenos.pyenos.org>
Message-ID: <7.0.1.0.0.20061220193755.032b04b0@yahoo.com.ar>

At Wednesday 20/12/2006 19:16, Pyenos wrote:

>could someone tell me what things are wrong with my code?

My crystal ball is at the repair shop - could you please tell us:
- what do you expect the code to do?
- what do you get instead?
- any compiler error messages you see?
- in case of an exception, full traceback as printed by the interpreter?
- Python version in use?


-- 
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 



From stesch at no-spoon.de  Sun Dec  3 12:30:18 2006
From: stesch at no-spoon.de (Stefan Scholl)
Date: Sun, 3 Dec 2006 18:30:18 +0100
Subject: A mail from Steve Ballmer. See what Microsoft will do and follow.
References: <1165158102.058961.138390@n67g2000cwd.googlegroups.com>
Message-ID: <0T3m1mduI4g3Nv8%stesch@parsec.no-spoon.de>

JustStand  wrote:
> In many ways, it was the launch of Windows 95 and Office 95 eleven
> years ago that signaled the start of this transformation. ..."

Right. 11 years ago I switched from Amiga to Linux.


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/


From reverseyorkage at david.com  Sun Dec 17 08:13:40 2006
From: reverseyorkage at david.com (dyork)
Date: Sun, 17 Dec 2006 13:13:40 GMT
Subject: Roundtrip SQL data especially datetime
References: 
	<1166187115.915310.66810@l12g2000cwl.googlegroups.com>
	
	<1166286611.692347.67070@80g2000cwy.googlegroups.com>
Message-ID: <8obhh.9610$HU.5260@news-server.bigpond.net.au>


"fumanchu"  wrote in message 
news:1166286611.692347.67070 at 80g2000cwy.googlegroups.com...
> Here's the web adaptation layer I use:
> http://projects.amor.org/misc/browser/alamode.py
> Have a look at the coerce_in and coerce_out functions.

Thanks! Plenty of useful ideas there.

My web framework already does all the HTML stuff, so I don't need that. 
Also, I note that alamode has hard coded dates in MDY order, which is 
surprising given the Unicode support, and a real problem.

DY 




From bearophileHUGS at lycos.com  Sat Dec 23 08:12:36 2006
From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com)
Date: 23 Dec 2006 05:12:36 -0800
Subject: Multi-line docstrings
In-Reply-To: 
References: 
	
Message-ID: <1166879556.524218.96490@h40g2000cwb.googlegroups.com>

Duncan Booth:
> Not spuriously included: included by design, but sometimes annoying.

Then it's a design decision I don't understand...

Bye,
bearophile



From tgrav at mac.com  Tue Dec  5 08:24:14 2006
From: tgrav at mac.com (Tommy Grav)
Date: Tue, 5 Dec 2006 08:24:14 -0500
Subject: memory error with matplot
In-Reply-To: <1165324360.959614.55970@j72g2000cwa.googlegroups.com>
References: <1165324360.959614.55970@j72g2000cwa.googlegroups.com>
Message-ID: <3FE51B17-B803-4867-BD2B-210CA8D8BE0A@mac.com>

It is hard to know what is wrong when we do not know how the
wrapper around the function works. The error could also be in
ConstructFigName or ConstructFigPath. Also please send the
specific error message when asking for help as that significantly
helps in tracking down the error.

Cheers
    Tommy

tgrav at mac.com
http://homepage.mac.com/tgrav/
------------------------------------------------------------------------ 
-----------------
"Any intelligent fool can make things bigger, more complex, and
more violent. It takes a touch of genius -- and a lot of courage --
to move in the opposite direction" -- Albert Einstein




On Dec 5, 2006, at 8:12 AM, lisa.engblom at gmail.com wrote:

> Hi,
>
> I am using matplotlib with python to generate a bunch of charts.  My
> code works fine for a single iteration, which creates and saves 4
> different charts.  The trouble is that when I try to run it for the
> entire set (about 200 items) it can run for 12 items at a time.  On  
> the
> 13th, I get an error from matplotlib that says it can't access data.
> However, if I start the program at the point it failed before it works
> fine and will create the charts for the next 12 before failing.  I
> assume that I am not closing the files properly somehow or otherwise
> misallocating memory.  I tried just reimporting pylab each iteration,
> but that didn't help.  This is the function that creates a chart:
>
> #create and save the figure
> def CreateFigure(state, facility, unit, SO2, increment, year, P99):
>     size = len(SO2)
>
>     #Create Plot
>     figure(1, figsize=(10,8))
>     bar(range(1, size+2), SO2, width=0.1, color='k')
>     grid(True)
>     xlim(0,size)
>     ylim(0, 1.1*SO2[-1])
>     ylabel('SO2 [lb/hr]')
>     heading = ConstructFigName(state, facility, unit, increment, year)
>     title(heading)
>
>     #set handles
>     xticklines = getp(gca(), 'xticklines')
>     xgridlines = getp(gca(), 'xgridlines')
>     xticklabels = getp(gca(), 'xticklabels')
>     yticklines = getp(gca(), 'yticklines')
>
>     #set properties
>     setp(xticklines, visible=False)
>     setp(xgridlines, visible=False)
>     setp(xticklabels, visible=False)
>     setp(yticklines, visible=False)
>
>     axhspan(P99, P99, lw=3, ec='r', fc='r')
>     ax = gca()
>     #P99 = str(P99)
>     P99 = '%0.1f' % P99
>     text(0.01, 0.95, '99th Percentile: '+P99+' lb/hr',
> transform=ax.transAxes)
>
>     figpath = ConstructFigPath(state, facility, unit, increment, year)
>     savefig(figpath)
>     close()
>
> Can you see the problem?
>
> thanks,
> -Lisa
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list





-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From paddy3118 at netscape.net  Thu Dec 28 11:51:06 2006
From: paddy3118 at netscape.net (Paddy3118)
Date: 28 Dec 2006 08:51:06 -0800
Subject: Anyone persuaded by "merits of Lisp vs Python"?
Message-ID: <1167324666.002153.27570@a3g2000cwd.googlegroups.com>

This month there was/is a 1000+ long thread called:
 "merits of Lisp vs Python"
In comp.lang.lisp.

If you followed even parts of the thread, AND previously
used only one of the languages AND (and this is the
crucial bit), were persuaded to have a more positive view
of the other language; (deep breath, this is a long, as
well as grammatically incorrect sentence), THEN WHY NOT
POST ON WHAT ARGUMENTS PERSUADED YOU.

OTHERWISE LET THIS POST WITHER AND DIE ALONE.

(I suspect this thread to be very short - even the
original poster seems to have given up on the day he
started the thread).

- Paddy.



From fredrik at pythonware.com  Tue Dec 19 10:59:40 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Tue, 19 Dec 2006 16:59:40 +0100
Subject: python poetry?
In-Reply-To: <1166524579.271548.32560@a3g2000cwd.googlegroups.com>
References: <1166524579.271548.32560@a3g2000cwd.googlegroups.com>
Message-ID: 

BartlebyScrivener wrote:

> First, can anybody recommend any other such books? And second is there
> a repository of Python poetry, poems translated into Python, or
> humorous Python pseudo code limericks anywhere?  I'm making my way
> through "The Larch," but if there's more elsewhere please point me to
> it.

Aroldo Souza-Leite did "Sonnets from Pythia" presentations/workshops at 
EuroPython in 2004 and 2005, but I don't know if he's ever published the 
material.  google is your friend.





From mfmorss at aep.com  Mon Dec 11 14:29:07 2006
From: mfmorss at aep.com (Mark Morss)
Date: 11 Dec 2006 11:29:07 -0800
Subject: About alternatives to Matlab
In-Reply-To: <1165861882.340331.200170@j72g2000cwa.googlegroups.com>
References: 
	<45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165080056.083648.207580@16g2000cwy.googlegroups.com>
	<45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165161532.686060.78860@73g2000cwn.googlegroups.com>
	<45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165241895.291617.143380@80g2000cwy.googlegroups.com>
	<4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165332936.164364.190860@73g2000cwn.googlegroups.com>
	
	<457be0b7$0$8727$ed2619ec@ptn-nntp-reader02.plus.net>
	
	<457d5bf9$0$8754$ed2619ec@ptn-nntp-reader02.plus.net>
	<7xhcw2d0fo.fsf@ruckus.brouhaha.com>
	<1165861882.340331.200170@j72g2000cwa.googlegroups.com>
Message-ID: <1165865346.951502.42610@79g2000cws.googlegroups.com>

> The [F#] source is avaliable, but it's under Microsoft's Shared Source
> license, which isn't quite an open source license.  There are some
> restrictions on commercial usage.
>

You can call me a bigot, but it will be engraved upon my tombstone that
I never used a proprietary Microsoft language.


olsongt at verizon.net wrote:
> Paul Rubin wrote:
> > Jon Harrop  writes:
> > > F# runs under Linux with Mono.
> >
> > Interesting, where do I get it, and is there source?  I've never been
> > interested in Mono but maybe this is a reason.  How does the compiled
> > code compare to OCaml or MLton code?
>
> The source is avaliable, but it's under Microsoft's Shared Source
> license, which isn't quite an open source license.  There are some
> restrictions on commercial usage.
> 
> http://research.microsoft.com/fsharp/fsharp-license.txt



From scott.daniels at acm.org  Tue Dec 26 19:21:06 2006
From: scott.daniels at acm.org (Scott David Daniels)
Date: Tue, 26 Dec 2006 16:21:06 -0800
Subject: Noobie: Open file -> read characters & multiply
In-Reply-To: 
References: 
Message-ID: <4591b22b$1@nntp0.pdx.net>

gonzlobo wrote:
> I've been using Python for a few days. It's such the perfect language
> for parsing data!
> 
> I really like it so far, but I'm having a hard time reading a file,
> reading the first few hex characters & converting them to an integer.
> Once the characters are converted to an integer, I'd like to write the
> data to another file.
> 
> Here's the code snipped to the bare minimum:
> ---
> # Open File
> AP_File= open("AP.txt", "r")
> decoded_File= open("decoded.txt", "w")
> 
> # read & process data line by line
> for line in AP_File:
>   time = int(hex(line[0:8]), 16) * 0.0001     # this line is completely 
> hosed!
>   decodedFile.write(time)
> 
> #close files
> AP_File.close()
> decoded_File.close()
> ---
> AP.txt
> 000000d5 26 0600 80 00 ec 80 02 03 7d db 02 33
> 000000d5 26 0601 80 00 80 00 02 37 fe 54 01 09
> 000000d5 06 0602 80 00 e0 00 01 29 fe d2 69 99
> 000000d5 06 0603 80 00 e0 00 02 29 fe d2 6a 99
> 000000d5 26 0604 80 00 fe 54 02 09 80 00 01 5d
> 000000d5 06 0605 80 00 e0 00 02 15 fc 71 ca 0b
> 000000d5 4a 0610 81 00 86 00 02 26 12 00 02 a6
> 000000d5 4f 0611 00 00 00 50 00 00 00 00 07 00
> 000000d5 06 0612 80 00 e0 00 01 15 fc 71 c9 0b
> 000000d5 0a 0613 08 5c 04 88 08 98 00 00 00 00
> 000000d5 06 0614 80 00 e0 00 02 01 60 79 82 2b
> 000000d5 0a 0615 08 00 00 00 00 00 00 00 00 00
> 000000d5 26 0616 80 00 80 00 02 5d 04 22 3a 88
> (actual files are 250MB!)
> 
> decodedTime.txt (should be)
> 0.0213 26 0600 80 00 ec 80 02 03 7d db 02 33
> ...
> 
> My boss and I are trying to complete the same task (he figured out how
> to do it, but his code uses a while != "" loop and doesn't look
> pythony (it looks too 'c'). Not that there's anything wrong with that!
> 
> Any help is really appreciated.
for line in AP_file:
     print >>decoded_File, '%s.%04d' % divmod(int(line[:8], 16), 10000
                                              ), line[9:].rstrip()

or:

for line in AP_file:
     print >>decoded_File, '%.4f' % (int(line[:8], 16) * .0001
                                              ), line[9:].rstrip()


--Scott David Daniels
scott.daniels at acm.org


From slawomir.nowaczyk.847 at student.lu.se  Tue Dec 12 18:12:10 2006
From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk)
Date: Wed, 13 Dec 2006 00:12:10 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <7xr6v5xsab.fsf@ruckus.brouhaha.com>
References: 
	<7xr6v5xsab.fsf@ruckus.brouhaha.com>
Message-ID: <20061212235758.573E.SLAWOMIR.NOWACZYK.847@student.lu.se>

On Tue, 12 Dec 2006 03:33:32 -0800
Paul Rubin <"http://phr.cx"@NOSPAM.invalid> wrote:

#> I V  writes:
#> > > Also, Python does not support a functional style of programming so the 
#> > > line is the only meaningful textual entity. In this sense the 
#> > > primitiveness of Python makes editing easier.
#> > 
#> > Why do you say that? Wouldn't a block in python be a "meaningful textual
#> > entity" in the same way a lisp form would be?
#> 
#> You normally wouldn't refactor Python code by moving an indented block
#> to the inside of an expression.  That is done all the time in Lisp.

You mean, you actually take something like else-form from an if and put
it inside, say, a multiplication? Sure, that is something you don't do
in Python often.

What you do in Python is take a block from one branch of "if" statement
and put it somewhere else (in a for loop, for example).

Sure, this requires you indent the block properly, although I am 100%
sure that I could teach emacs to adjust indentation automatically has I
needed to. I just never felt the need.

-- 
 Best wishes,
   Slawomir Nowaczyk
     ( Slawomir.Nowaczyk at cs.lth.se )

Programming:  The art of debugging a blank sheet of paper
(or, in these days of on-line editing, the art of debugging an empty file).



From gagsl-py at yahoo.com.ar  Thu Dec 28 19:27:16 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Thu, 28 Dec 2006 21:27:16 -0300
Subject: Slowdown in Jython
In-Reply-To: <1167322474.724142.210440@a3g2000cwd.googlegroups.com>
References: <1167322474.724142.210440@a3g2000cwd.googlegroups.com>
Message-ID: <7.0.1.0.0.20061228212351.03fd9e40@yahoo.com.ar>

At Thursday 28/12/2006 13:14, tac-tics wrote:

>I have an application written in jython which has to process a number
>of records. It runs fine until it gets to about 666 records (and maybe
>that's a sign), and then, it's performance and responsiveness goes down
>the toilet. It looks like it's running out of memory and is being
>forced to use extended memory, but I do not know enough about the

Only a standard advise: try not to load all the records together, 
instead, if possible, process them one record at a time. This way 
you're not bound by available memory.


-- 
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 



From fredrik at pythonware.com  Mon Dec  4 02:22:15 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Mon, 04 Dec 2006 08:22:15 +0100
Subject: Video stream server
In-Reply-To: <1165216465.101749.227330@n67g2000cwd.googlegroups.com>
References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com>
Message-ID: 

Lad wrote:

> Does anybody know about a video stream server that
> serves up HTML pages with links to video files, and then serving out
> those video files.

http://www.youtube.com/ seems to match your specification pretty well.





From rurpy at yahoo.com  Mon Dec  4 17:22:49 2006
From: rurpy at yahoo.com (rurpy at yahoo.com)
Date: 4 Dec 2006 14:22:49 -0800
Subject: Why not just show the out-of-range index?
In-Reply-To: 
References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com>
	<1165264641.125857.85980@80g2000cwy.googlegroups.com>
	
Message-ID: <1165270969.942437.302020@n67g2000cwd.googlegroups.com>


Terry Reedy wrote:
> "Russ"  wrote in message
> news:1165264641.125857.85980 at 80g2000cwy.googlegroups.com...
> >
> > Fredrik Lundh wrote:
> >
> >> > Sorry I haven't thought this through 100%
> >>
> >> obviously not.
> >
> > And you didn't like the "tone" of some of my earlier posts?
>
> While Fredrik's reply is a bit short, as is sometimes his habit,
> here are some things that appear to me to not have been thought through
> enough:
> 1. some negative indexes are legal.
> 2. replacing short inline code with a function call on *every* index lookup
> will slow down the interpreter a bit.
> 3. will the same check code work for even all built-in sequences?
> 4. how does index checking fit in with slice checking?
>
> By the way, it is already understood that error messages could be better,
> and I have thought about this one myself.  You are not the first to notice,
> and improvements occasionally get submitted (and later accepted) by people
> with both the knowledge and motivation to do so.  But insulting such people
> is not helpful.

I saw no posts where there OP insulted anybody without being
insulted first.  It is ironic the Mr. Kern was the most consistent
insulter while at the same time accusing the OP of rudeness.

Your own post would have been more helpful (or at least less
devisive) had you left off that last sentence.



From deets at nospam.web.de  Sat Dec 30 09:20:32 2006
From: deets at nospam.web.de (Diez B. Roggisch)
Date: Sat, 30 Dec 2006 15:20:32 +0100
Subject: PEP 3107 Function Annotations for review and comment
References: 
	
Message-ID: <4vnatgF1cg3n2U1@mid.uni-berlin.de>

BJ?rn Lindqvist wrote:

> On 12/29/06, Tony Lownds  wrote:
>> Rationale
>> =========
>>
>> Because Python's 2.x series lacks a standard way of annotating a
>> function's parameters and return values (e.g., with information about
>> what type a function's return value should be), a variety of tools
>> and libraries have appeared to fill this gap [#tailexamp]_.  Some
>> utilise the decorators introduced in "PEP 318", while others parse a
>> function's docstring, looking for annotations there.
>>
>> This PEP aims to provide a single, standard way of specifying this
>> information, reducing the confusion caused by the wide variation in
>> mechanism and syntax that has existed until this point.
> 
> I think this rationale is very lacking and to weak for such a big
> change to Python. I definitely like to see it expanded.
> 
> The reference links to two small libraries implementing type checking
> using decorators and doc strings. None of which to seem to be very
> popular in the Python community. Surely, those two libraries *alone*
> can't be enough of a motivation for this? To me, it is far from
> self-evident what purpose function annotations would serve.
> 
> I also wonder why a very obtrusive syntax addition is needed when it
> clearly is possible to annotate functions in today's Python. Why is
> syntax better than just adding a function annotation decorator to the
> standard library?
> 
>     @annotate(a = int, b = dict, c = int)
>     def foo(a, b, c = 5):
>         ...
> 
> Are decorators to ugly?

I prefer the proposed syntax - it is much more concise and. modeled after
well-known declaration syntaxes in other languages. Additionally, it spares
us the doubled parameter list as your example above - and that is important
here I'd say.

Typing is a difficult and controversial subject. However, sooner or later
python will grow JIT-compilers that will take advantage of such
declarations, and I think it is better to have one accepted way of doing it
hardwired than several concurring self-baked implementations.

Diez


From murdokd at gmail.com  Sun Dec  3 16:47:04 2006
From: murdokd at gmail.com (Murdok Petrovsky)
Date: Sun, 3 Dec 2006 18:47:04 -0300
Subject: Interface Designer
Message-ID: <32f2725f0612031347x79b21d3fkbf8cde9f6c4bbab9@mail.gmail.com>

Hi list!

I'm starting to program in python, i need a soft  "interface designer" and
adapt this interface to python. Somebody can help me with this?


Sorry, my english is very bad.


Regards to all.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From roy at panix.com  Fri Dec  8 14:56:46 2006
From: roy at panix.com (Roy Smith)
Date: Fri, 08 Dec 2006 14:56:46 -0500
Subject: Snake references just as ok as Monty Python jokes/references in
	python community? :)
References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com>
Message-ID: 

In article <1165607250.544331.124360 at j72g2000cwa.googlegroups.com>,
 "seberino at spawar.navy.mil"  wrote:

> I'm semi-seriously wondering if snake jokes are valid in the Python
> community since technically, Python came from Monty Python, not
> slithery animals.
> 
> Problem is I don't know that anyone born after Elvis died gets any of
> these Monty Python jokes.
> 
> Is it kosher to make snake jokes/references even though officially they
> don't have anything to do with the name of our favorite language?
> (*Everyone* gets snake jokes! :)
> 
> Chris

It's people like you wot cause unrest!


From thermate at india.com  Fri Dec  1 21:24:21 2006
From: thermate at india.com (thermate at india.com)
Date: 1 Dec 2006 18:24:21 -0800
Subject: Molten Metal Pools in WTC after weeks,
	only micronuke could have produced so much heat
Message-ID: <1165026261.579383.57050@16g2000cwy.googlegroups.com>

W88 warhead design

http://www.thepriceofliberty.org/06/09/25/wardpics-5.htm

http://www.thepriceofliberty.org/06/09/25/wardpics-4.htm

Bali bomb was possibly a micronuke from Dimona Israel - the land of
milk and honey ;)

http://www.vialls.com/nuke/bali_micro_nuke.htm  <------------ Excellent
analysis with photo evidence

You guys in tex/c++/python/physics/math can now analyse the
observations based on your expertise, but the facts are facts, an
acceptable theory must explain them all.

More micronuke analysis:
http://groups.google.com/group/total_truth_sciences/browse_thread/thread/93ea1025953b8064/e1f3b031f5dca83d?lnk=st&q=%22thermate%22+million&rnum=40&hl=en#e1f3b031f5dca83d

The following synopsis comes from a Military Expert in Finland. See all
of this posting Here
http://www.government-propaganda.com/911-why-towers-collasped.html
<---- EXCELLENT ILLUSTRATIVE PHOTOS

Please, congratulate and send loves and affections to our ZIONIST
brothers in US Government and Israel for giving us such a nice nuclear
gift.



From grahamd at dscpl.com.au  Wed Dec 27 17:38:19 2006
From: grahamd at dscpl.com.au (Graham Dumpleton)
Date: 27 Dec 2006 14:38:19 -0800
Subject: Mod_python
References: <1167161288.802707.64220@h40g2000cwb.googlegroups.com>
	<1167212317.836419.162730@42g2000cwt.googlegroups.com>
Message-ID: <1167259099.025401.277190@42g2000cwt.googlegroups.com>


Maxim Sloyko wrote:
> Lad wrote:
> > In my web application I use Apache and mod_python.
> > I allow users to upload huge files( via HTTP FORM , using POST method)
> > I would like to store the file directly on a hard disk and not to
> > upload the WHOLE huge file into  server's memory first.
> > Can anyone suggest a solution?
>
> The only solution you need is Apache and mod_python :)
> I mean,  Apache won't load a huge POST request into its memory no
> matter what. All file uploads will be stored in temporary files. Under
> mod_python (provided you use FieldStorage) you'll need to deal only
> with 'file' objects.

Note though that the default behaviour of FieldStorage is to store
files in whatever directory the 'tempfile' module uses. This may not
always be acceptable, especially with very large files, as the user may
want to have the files actually reside elsewhere in some special
directory and having to make a copy of the file, if a different file
system, may in itself cause issues.

Thus, provided you are using a recent version of mod_python, you still
may have to customise how files are handled using the FieldStorage file
callbacks to have the file stored in the desired location from the
outside.

The other alternative to FieldStorage is to write a custom
Apache/mod_python input filter to process uploads. An example of this
is Tramline (http://www.infrae.com/products/tramline).

Graham



From christian_wenz at arcor.de  Mon Dec 18 04:20:27 2006
From: christian_wenz at arcor.de (Christian Wenz)
Date: Mon, 18 Dec 2006 09:20:27 +0000
Subject: undefined symbol: libxml_xmlDocPtrWrap
Message-ID: 

Hello, 

I try to install "listen" on my amd64-gentoo-box. The programm 
tries to import the gst-package and throws the following trace:

Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/gst-0.10/gst/__init__.py", 
    line 108, in ?
    from _gst import *
ImportError: /usr/lib64/python2.4/site-packages/gst-0.10/gst/_gst.so:
    undefined symbol: libxml_xmlDocPtrWrap

Does anybody know this problem? 

Greetings Chris



From __peter__ at web.de  Fri Dec  8 05:10:15 2006
From: __peter__ at web.de (Peter Otten)
Date: Fri, 08 Dec 2006 11:10:15 +0100
Subject: how to remove the blank lines?
References: 
Message-ID: 

boyeestudio wrote:

> The following program have the same function as the linux's command:tail
> -f logfile.log
> But it print a lot of blank lines while showing on the stdout.
> How to fix this problem and let it go ahead always
> showing the end line as the log file's increasing.
> 
> #tail.py:
> 
> import os
> import sys
> 
> class Tail:
>     def __init__(self,inputstream):
>         self.inputstream=inputstream
> 
>     def tail(self):
>         self.inputstream.seek(0,2)     ???Maybe this is where I'll need
> fixed,But I don't know how to....

You probably want to move to the end of the file once at the
beginning of the script, not before every attempt to read from it...

>         line=self.inputstream.readline().strip()

Don't strip() so fast. You lose the information whether you have reached the
(current) end of file or a blank line (readline() returns "" or "\n"
respectively).

>         print line
> 
> if __name__=="__main__":
>     if len(sys.argv)<=1:
>         print "You must type a log file name"
>         sys.exit()
>     arg=file(sys.argv[1],'r+')
>     while(arg):

That's always true, I think.

>         try:
>             t=Tail(arg)
>              t.tail()
>         except KeyboardInterrupt:
>             arg.close()
>             print "File closed"

A no-fluff version might be

filename = sys.argv[1]
infile = open(filename, "r")
infile.seek(0, 2)
while True:
    while True:
        line = infile.readline()
        if not line: # an empty string indicates eof 
            break 
        print line,
    time.sleep(1) # give the writing program a chance to write more lines


The inner loop can also be written

for line in iter(infile.readline, ""):
    print line,

Peter



From lisa.engblom at gmail.com  Sun Dec  3 20:41:01 2006
From: lisa.engblom at gmail.com (lisa.engblom at gmail.com)
Date: 3 Dec 2006 17:41:01 -0800
Subject: trouble with matplotlib
Message-ID: <1165196461.231013.199670@j44g2000cwa.googlegroups.com>

Hi,

I am using matplotlib with python to generate a bunch of charts.  My
code works fine for a single iteration, which creates and saves 4
different charts.  The trouble is that when I try to run it for the
entire set (about 200 items) it can run for 12 items at a time.  On the
13th, I get an error from matplotlib that says it can't access data.
However, if I start the program at the point it failed before it works
fine and will create the charts for the next 12 before failing.  I
assume that I am not closing the files properly somehow or otherwise
misallocating memory.  This is the function that creates a chart:

#create and save the figure
def CreateFigure(state, facility, unit, SO2, increment, year, P99):
    size = len(SO2)

    #Create Plot
    figure(1, figsize=(10,8))
    bar(range(1, size+2), SO2, width=0.1, color='k')
    grid(True)
    xlim(0,size)
    ylim(0, 1.1*SO2[-1])
    ylabel('SO2 [lb/hr]')
    heading = ConstructFigName(state, facility, unit, increment, year)
    title(heading)

    #set handles
    xticklines = getp(gca(), 'xticklines')
    xgridlines = getp(gca(), 'xgridlines')
    xticklabels = getp(gca(), 'xticklabels')
    yticklines = getp(gca(), 'yticklines')

    #set properties
    setp(xticklines, visible=False)
    setp(xgridlines, visible=False)
    setp(xticklabels, visible=False)
    setp(yticklines, visible=False)

    axhspan(P99, P99, lw=3, ec='r', fc='r')
    ax = gca()
    #P99 = str(P99)
    P99 = '%0.1f' % P99
    text(0.01, 0.95, '99th Percentile: '+P99+' lb/hr',
transform=ax.transAxes)

    figpath = ConstructFigPath(state, facility, unit, increment, year)
    savefig(figpath)
    close()
    

Can you see the problem?

thanks,
-Lisa



From python at hope.cz  Thu Dec  7 08:39:16 2006
From: python at hope.cz (Lad)
Date: 7 Dec 2006 05:39:16 -0800
Subject: Video stream server
In-Reply-To: 
References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com>
	
	<1165218527.632366.290350@j44g2000cwa.googlegroups.com>
	
	<1165221764.002660.197600@16g2000cwy.googlegroups.com>
	
Message-ID: <1165498756.854498.95600@n67g2000cwd.googlegroups.com>


Fredrik Lundh wrote:
> Lad wrote:
>
> > I love Python so I would like to implement video support  in Python.
>
> maybe this might be helpful?
>
> http://blog.go4teams.com/archives/video-blogging-using-django-and-flashtm-video-flv/56
> 
> 

Yes, it is very good link.
Thank you



From Geert.Van.Muylem at skynet.be  Tue Dec 19 10:34:19 2006
From: Geert.Van.Muylem at skynet.be (Geert Van Muylem)
Date: Tue, 19 Dec 2006 16:34:19 +0100
Subject: FW: Crash in PyImport_Import()
Message-ID: <200612191534.kBJFY5pq005339@outmx022.isp.belgacom.be>

Hi,

 

And everything works fine if I link with the shared version of python.

The ldap extension works fine in the interpreter, as well as with embedded
python.

 

Does anyone knows why it seems to be needed that extension modules have to
be linked against the shared version 

of python?

 

Regards,

Geert

 

  _____  

From: python-list-bounces+geert.van.muylem=skynet.be at python.org
[mailto:python-list-bounces+geert.van.muylem=skynet.be at python.org] On Behalf
Of Geert Van Muylem
Sent: maandag 18 december 2006 22:51
To: python-list at python.org
Subject: Crash in PyImport_Import()

 

Hi, 

The following script works fine when I call it from the python interpreter 
but not when I call it from a c application (embedded python) 
It crashes in the PyImport_Import() 

import ldap 
import distutils.sysconfig 

def TestInit(): 

   l = ldap.open("192.168.1.2") 
   l.simple_bind_s("","") 
   l.search_s("c=BE", ldap.SCOPE_SUBTREE, "objectclass=*") 

   s = distutils.sysconfig.get_config_var('LINKFORSHARED') 


-> Python (2.5) and python-ldap (2.2.1) are recompiled for my environment
(hardened linux.)

Here is part of my makefile: 

VERSION = Python-2.5 

VERSION_LDAP = python-ldap-2.2.1 

compile: .python .python-ldap 

.python:        makefile.python .glibc $(VERSION).Setup.local 
                $(EXTRACT_PACKAGE) && \ 
                        $(CP) ../$(VERSION).Setup.local Modules/Setup.local
&& \ 
                        ./configure --prefix=/usr --enable-shared=no && \ 
                        make && \ 
                        make install 
                cp $(VERSION)/libpython2.5.a /usr/lib/libpython.a 
                (cd /usr/include; $(LN) -sf python2.5 python ) 
                touch .python 


.python-ldap: makefile.python .python .sasl .glibc .openldap
python-ldap.setup.cfg 
        (rm -rf $(VERSION_LDAP)  ||  /bin/true)  && \ 
        tar xjf $(ARCHIVE_PACKAGES)/$(VERSION_LDAP).tar.bz2  && \ 
        cd $(VERSION_LDAP) && \ 
                $(CP) ../python-ldap.setup.cfg setup.cfg && \ 
                python setup.py build && \ 
                python setup.py install 
        rm -rf $(VERSION_LDAP) 
        touch .python-ldap 


And my setup.cfg 

# Example for setup.cfg 
# You have to edit this file to reflect your system configuation 
# $Id: setup.cfg.suse-linux,v 1.1 2003/08/20 10:04:34 stroeder Exp $ 

[_ldap] 
# Section for compiling the C extension module 
# for wrapping OpenLDAP 2 libs 

library_dirs = /usr/lib/ /usr/lib/sasl2/ 
include_dirs = /usr/include/sasl/ /usr/include/sasl2/ 
extra_compile_args = 
extra_objects = 

# Example for full-featured SuSE build: 
# Support for StartTLS/LDAPS, SASL bind and reentrant libldap_r. 
# This needs recent OpenLDAP 2.0.26+ or 2.1.3+ built with 
#./configure --with-cyrus-sasl --with-tls 
libs = python ldap_r lber sasl2 ssl crypto resolv dl db m util pthread 

[install] 
# Installation options 
compile = 1 
optimize = 1 

Everything is done in a chroot-ed environment...when building python-ldap,
it uses 
the newly installed python includes.... 
The test application is linked against the static version libpython.a

 

int 

CPyLDAP::Init()

{

    m_iPython = 1;

 

    printf ("Before Py_Initialize...\n");

    Py_Initialize();

    printf ("After Py_Initialize...\n");

 

    PyObject *pName = PyString_FromString("PyTest");

    if ( pName != NULL )

    {

        // Load the Python module

                printf ("Before Import...\n");

        m_pModule = PyImport_Import(pName);

                printf ("After Import...\n");

        if (m_pModule != NULL)

        {

                m_iPython = 0;

                m_pDictionary = PyModule_GetDict(m_pModule);

        }

    }

    

    return (m_iPython);

}


Hope someone can give me a hint? 

thanks, 
Geert

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ATT00080.txt
URL: 

From nagle at animats.com  Mon Dec 18 01:55:56 2006
From: nagle at animats.com (John Nagle)
Date: Mon, 18 Dec 2006 06:55:56 GMT
Subject: dealing with special characters in Python and MySQL
In-Reply-To: <1166423874.304873.218020@t46g2000cwa.googlegroups.com>
References: <1166421731.032421.124600@t46g2000cwa.googlegroups.com>
	
	<1166423874.304873.218020@t46g2000cwa.googlegroups.com>
Message-ID: <0Yqhh.20400$wc5.8435@newssvr25.news.prodigy.net>

ronrsr wrote:
>>are you passing in the strings as Unicode strings, or as something else?
>>  if you're using something else, what have you done to tell the
>>database what it is?
>>
> 
> 
> 
> not at all sure what I'm passing it as.
> 
> The database default  encoding is utf-8
> the database collation is utf-8
> the page encoding of the page is utf-8
> 
> what else do I have to tell the database?
> 
    Try putting "use_unicode=True" in the MySQLdb "connect" call.

    See
 
http://sourceforge.net/tracker/index.php?func=detail&aid=1559350&group_id=22307&atid=374932

and look at other charset related bugs at

http://sourceforge.net/tracker/?atid=374932&group_id=22307&func=browse

Also note that MySQLdb didn't support this until recently, so check
your version of MySQLdb.  There still seem to be problems in that area.

				John Nagle
				Animats


From Benjamin.Barker at gmail.com  Thu Dec 28 14:37:39 2006
From: Benjamin.Barker at gmail.com (Ben)
Date: 28 Dec 2006 11:37:39 -0800
Subject: dictionary containing instances of classes behaving oddly
In-Reply-To: <45941a6b$1@nntp.zianet.com>
References: <1167326178.386764.300200@n51g2000cwc.googlegroups.com>
	<4594102d$1@nntp.zianet.com>
	<1167333218.447246.236960@h40g2000cwb.googlegroups.com>
	<45941a6b$1@nntp.zianet.com>
Message-ID: <1167334659.073835.223040@73g2000cwn.googlegroups.com>

Yes- I can see that  my_list and mops, being outside def __init__()
only get created once, hence the confusion.

Surely def __init__() gets called each time an instance is created
however? But the snag is that if they have default values set these are
shared between all instances, even if they are, for instance, lists...?

Cheers,

Ben


Thanks.
Erik Johnson wrote:

> "Ben"  wrote in message
> news:1167333218.447246.236960 at h40g2000cwb.googlegroups.com...
>
> > class record:
> >         my_list =[]
> >         mops=[]
> >
> >         def __init__(self,mops):
> >                 self.mops=mops
>
> Similar to the example I gave, the lists my_list and mops shown above are
> executed just once: when your class definition is first parsed.
> The statement:
>
> def __init__(self,mops):
>
> is also executed just once, and the value for mops at that time is the value
> assigned to object attributes during object construction - a reference to
> record.mops, in your case.  So, there are really only two lists here, class
> attributes record.my_list and record.mops.  Each of your constructed objects
> is assigned a reference to record.mops.  They all share that list.  If you
> want a record object to have it's own list, give it a new, empty one and
> then populate it appropriately.



From pavlovevidence at gmail.com  Thu Dec 14 13:55:40 2006
From: pavlovevidence at gmail.com (Carl Banks)
Date: 14 Dec 2006 10:55:40 -0800
Subject: tuple.index()
In-Reply-To: 
References: 
	
	<1166103409.199435.290670@79g2000cws.googlegroups.com>
	<1166118142.144177.78790@l12g2000cwl.googlegroups.com>
	
Message-ID: <1166122540.017590.64460@16g2000cwy.googlegroups.com>


Nick Maclaren wrote:
> It isn't a misplaced fear, but the extra protection
> provided by doing that only for tuples is like locking one door out of
> ten to deter burglars - good practice, if there is no downside, but not
> worth putting much effort into.

Maybe "inconsistent" fear is a better word.  It's like when people are
deathly afraid to get on an airplane, but think nothing of riding in a
car without a seatbelt.


Carl Banks



From R.Brodie at rl.ac.uk  Fri Dec  8 09:08:09 2006
From: R.Brodie at rl.ac.uk (Richard Brodie)
Date: Fri, 8 Dec 2006 14:08:09 -0000
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
Message-ID: 


"Mark Tarver"  wrote in message 
news:1165582654.974945.173700 at 79g2000cws.googlegroups.com...

> seems to show that Python is a cut down (no macros) version of Lisp
> with a worse performance.

Performance claims are always controversial. So, Python is much slower
doing array multiplication, when you hand roll it, instead of using the
standard numerical packages available.

I see that the effbot has already responded the first part.





From bdesth.quelquechose at free.quelquepart.fr  Fri Dec 22 05:50:09 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Fri, 22 Dec 2006 11:50:09 +0100
Subject: Decorator for Enforcing Argument Types
In-Reply-To: <1166767205.559937.185260@f1g2000cwa.googlegroups.com>
References: <1166734180.455471.164910@79g2000cws.googlegroups.com>
	<458b0e0b$0$9768$426a74cc@news.free.fr>
	<1166741966.242087.192390@n67g2000cwd.googlegroups.com>
	<1166767205.559937.185260@f1g2000cwa.googlegroups.com>
Message-ID: <458bb290$0$25902$426a74cc@news.free.fr>

George Sakkis a ?crit :
> John Machin wrote:
> 
>>Bruno Desthuilliers wrote:
>>
>>
>>>
>>>Python is dynamic, and fighting against the language is IMHO a really
>>>bad idea. The only places where theres a real need for this kind of
>>>stuff are when dealing with the "outside world" (IOW : inputs and
>>>outputs). And then packages like formencode can do much more than mere
>>>type-checking
>>>
>>
>>Agreed. The worst case I have seen:
>>
>>An elaborate decorator (similar to the OP's) laboriously checks arg
>>types. That's IMHO not "consenting adults" territory. But it gets a
>>whole lot worse when it's applied to a method whose body is like this:
>>
>>if isinstance(....
>>    action_for_type1(...
>># big snip
>>elif isinstance(...
>>    action_typeN( ...
>># no else statement
> 
> 
> Ouch.. someone must have skipped his/her OO class...
> 
Depends... I've sometimes had to write such kind of horrors - at least 
once: a wrapper class to ensure that all strings accessible directly *or 
indirectly* (via a dict, list, method call, whatever...) would be 
unicode strings...

But of course I didn't use decorators to type-check annything !-)


From debl2NoSpam at verizon.net  Sat Dec  9 01:37:47 2006
From: debl2NoSpam at verizon.net (David Lees)
Date: Sat, 09 Dec 2006 06:37:47 GMT
Subject: merits of Lisp vs Python
In-Reply-To: <1165613280.584178.36470@16g2000cwy.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
Message-ID: <%Qseh.77$495.67@trnddc06>

JShrager at gmail.com wrote:
> Okay, since everyone ignored the FAQ, I guess I can too...
> 
> Mark Tarver wrote:
>> How do you compare Python to Lisp?  What specific advantages do you
>> think that one has over the other?
> 
> (Common) Lisp is the only industrial strength language with both pure
> compositionality and a real compiler. What Python has is stupid slogans
> ("It fits your brain." "Only one way to do things.") and an infinite
> community of flies that, for some inexplicable reason, believe these
> stupid slogns. These flies are, however, quite useful because they
> produce infinite numbers of random libraries, some of which end up
> being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python
> is rapidly replacing Perl, and Ruby is simultaneously and even more
> rapidly replacing Python. Each is closer to Lisp than the last; the
> world is returning to Lisp and is dragging the flies with it.
> Eventually the flies will descend upon Lisp itself and will bring with
> them their infinite number of random libraries, and then things will be
> where they should have been 20 years ago, but got sidetracked by Tcl
> and other line noise.
> 

Hmmm.  The last time I fooled around with Lisp was 1966 from the Lisp 
1.5 Manual Published by MIT in cloth.  It was interesting and different 
from the other languages I was using, Algol 60, Basic and Macro 
assembler for the GE-235 and GE-635.  When I read some of the over the 
top type hype by Lisp enthusiasts (like the stuff above) it feels like a 
flash back to the mid 60's.  Personally, I never like Lisp syntax; 
Clearly some people, some fanatic judging by this thread :) think easily 
in prefix.  I am not one of them.  Computer languages are tools and 
everyone should pick the ones that they are most comfortable and 
productive with.

Six years ago, when I drifted back into programming, I had to learn 
about Object Oriented programming and C++.  I used Python as a means to 
update my programming skills (limited though they are) by 30 years or 
so.  It was a wonderful intro to OO and served me well.  I ended up 
writing all kinds of little things for work (simple HTTP servers for 
load testing, ECAD hacks for the ASIC guys, even a register level chip 
simulator) Even better, I find it a pleasure to write small utilities, 
to prototype C code and generally do things quickly.  I use it by choice 
to get things done, not because it is mandated.  At my current job as a 
Systems Engineer for a large aerospace firm, I do not program daily, but 
when I need to write a quick hack, I always use Python.

david


From Eric_Dexter at msn.com  Sat Dec  2 03:52:33 2006
From: Eric_Dexter at msn.com (Eric_Dexter at msn.com)
Date: 2 Dec 2006 00:52:33 -0800
Subject: strange problems with code generation
In-Reply-To: 
References: <1165022658.313170.134140@79g2000cws.googlegroups.com>
	
Message-ID: <1165049553.644725.54930@80g2000cwy.googlegroups.com>

I changed that and the writelines and I am very close now.  thanks.


Dennis Lee Bieber wrote:
> On 1 Dec 2006 17:24:18 -0800, "Eric_Dexter at msn.com"
>  declaimed the following in comp.lang.python:
>
> >     data = sys2.stdin.readlines()
>
> 	And what do you expect to read from stdin? Do you even have an
> attached console to read?
> --
> 	Wulfraed	Dennis Lee Bieber		KD6MOG
> 	wlfraed at ix.netcom.com		wulfraed at bestiaria.com
> 		HTTP://wlfraed.home.netcom.com/
> 	(Bestiaria Support Staff:		web-asst at bestiaria.com)
> 		HTTP://www.bestiaria.com/



From andelys at riddergarn.dk  Tue Dec 26 13:19:25 2006
From: andelys at riddergarn.dk (Andreas Lysdal)
Date: Tue, 26 Dec 2006 19:19:25 +0100
Subject: SPAM-LOW:  Re: BeautifulSoup vs. loose & chars
In-Reply-To: 
References: 	<1167135758.005112.67350@73g2000cwn.googlegroups.com>	
	
Message-ID: <459167AD.7060601@riddergarn.dk>



Duncan Booth skrev:
> "Felipe Almeida Lessa"  wrote:
>
>   
>> On 26 Dec 2006 04:22:38 -0800, placid  wrote:
>>     
>>> So do you want to remove "&" or replace them with "&" ? If you
>>> want to replace it try the following;
>>>       
>> I think he wants to replace them, but just the invalid ones. I.e.,
>>
>> This & this & that
>>
>> would become
>>
>> This & this & that
>>
>>
>> No, i don't know how to do this efficiently. =/...
>> I think some kind of regex could do it.
>>
>>     
>
> Since he's asking for valid xml as output, it isn't sufficient just to
> ignore entity definitions: HTML has a lot of named entities such as
>   but xml only has a very limited set of predefined named entities.
> The safest technique is to convert them all to numeric escapes except
> for the very limited set also guaranteed to be available in xml. 
>
> Try this:
>
> from cgi import escape
> import re
> from htmlentitydefs import name2codepoint
> name2codepoint = name2codepoint.copy()
> name2codepoint['apos']=ord("'")
>
> EntityPattern =
> re.compile('&(?:#(\d+)|(?:#x([\da-fA-F]+))|([a-zA-Z]+));') 
>
> def decodeEntities(s, encoding='utf-8'): 
>     def unescape(match):
> 	code = match.group(1)
>         if code:
>             return unichr(int(code, 10))
>         else:
>             code = match.group(2)
>             if code:
>                 return unichr(int(code, 16))
> 	    else:
>                 return unichr(name2codepoint[match.group(3)])
>     return EntityPattern.sub(unescape, s)
>
>   
>>>> escape(
>>>>         
>     decodeEntities("This & this & that é")).encode(
>         'ascii', 'xmlcharrefreplace') 
> 'This & this & that é'
>
>
> P.S. apos is handled specially as it isn't technically a
> valid html entity (and Python doesn't include it in its entity
> list), but it is an xml entity and recognised by many browsers so some
> people might use it in html.
>   
Hey i fund this site: 
http://www.htmlhelp.com/reference/html40/entities/symbols.html

I hope that its what you mean.

/Scripter47


 




From bdesth.quelquechose at free.quelquepart.fr  Tue Dec 12 13:22:29 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Tue, 12 Dec 2006 19:22:29 +0100
Subject: python vs java & eclipse
In-Reply-To: <1164965087.525503.104930@j72g2000cwa.googlegroups.com>
References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com>
Message-ID: <457eedd4$0$11482$426a74cc@news.free.fr>

Amir Michail a ?crit :
> Hi,
> 
> It seems to me that measuring productivity in a programming language
> must take into account available tools and libraries.
> 
> Eclipse for example provides such an amazing IDE for java that it is no
> longer obvious to me that one would be much more productive in python
> for medium sized projects.
> 
> Sure, all that Java static typing can be painful, but Eclipse takes
> some of that pain away. Moreover, static typing can result in better
> on-the-fly error detection and refactoring support.
> 
> Any thoughts on this?

Yes : Python's productivity does not only comes from dynamic typing.



From ptmcg at austin.rr._bogus_.com  Wed Dec  6 12:03:43 2006
From: ptmcg at austin.rr._bogus_.com (Paul McGuire)
Date: Wed, 06 Dec 2006 17:03:43 GMT
Subject: dict.has_key(x) versus 'x in dict'
References: 
	<1165418932.582377.312200@79g2000cws.googlegroups.com>
	
	<1165423559.858684.227930@16g2000cwy.googlegroups.com>
	
Message-ID: 

"Peter Otten" <__peter__ at web.de> wrote in message 
news:el6sfu$ord$02$1 at news.t-online.com...
> Andy Dingley wrote:
>
>>>     sorted(setBugsChanged)
>
>> Out of interest, whats the Pythonic way to simply cast (sic) the set to
>> a list, assuming I don't need it sorted?  The list comprehension?
>
> list(setBugsChanged)
>
> Peter

Note that this is not really a "cast" in the C sense of the word. 
list(setBugsChanged) constructs and returns a new list containing the 
elements of setBugsChanges, and leaves setBugsChanged unchanged.

-- Paul 




From h0leforfun at gmail.com  Tue Dec 19 08:01:38 2006
From: h0leforfun at gmail.com (Hole)
Date: 19 Dec 2006 05:01:38 -0800
Subject: Strange error with getattr() function
In-Reply-To: 
References: <1166455980.365984.296680@l12g2000cwl.googlegroups.com>
	<1166459121.661107.251700@73g2000cwn.googlegroups.com>
	
Message-ID: <1166533298.191517.128880@t46g2000cwa.googlegroups.com>


Gabriel Genellina ha scritto:

> At Monday 18/12/2006 13:25, Hole wrote:
>
> > > At this point, I got the error: attribute name must be string
> >
> >I'm wondering if the exception is raised in a hidden function and not
> >in the explicit call to getattr(). How can I view the traceback in a
> >script running in zope??
>
> (Which Zope version?)
> If you don't catch the exception, an error page will be displayed,
> pointing to the error_log object.
>
>

Hi Gabriel,

thanks a lot for your replies.

I've resolved the problem catching the exception and printing the
traceback in a file.

The problem was, indeed, in a getattr() call performed in another
function, to which I passed an int rather than a string.

Bye!

-- 
DN



From deets at nospam.web.de  Sun Dec  3 08:52:38 2006
From: deets at nospam.web.de (Diez B. Roggisch)
Date: Sun, 03 Dec 2006 14:52:38 +0100
Subject: Resource cleanup
In-Reply-To: <4572BF6A.6000005@jessikat.plus.net>
References: <4572BF6A.6000005@jessikat.plus.net>
Message-ID: <4tg356F131072U1@mid.uni-berlin.de>

> but am wondering exactly what 'resources' are left available when the 
> r.close method is called in the __del__ method of  RealTypeResourceCleaner.
> 
> In particular, can I rely on the module globals of r still being present 
> if the RealType instance is going away because the main script has 
> terminated, ie if the r.close method refers to a global function is it 
> guaranteed to be available when the close is called?
> 
> I guess I must be asking if referring to a global in a method is 
> actually a reference to that global or does the reference only occur 
> when the code is executed?
> 
> I have a vague feeling that I came across problems in the past about the 
> order in which modules were finalized.

I'm a bit on unsure ground here - so take it with a grain of salt.

It is for sure that only executing code will refer to a global - the 
mere mention of anything can't possibly create a reference (in python at 
least) - consider this simple example:

import random

def foo():
     print schroedingers_cat

if random.random() > .5:
     schroedingers_cat = "I'm alive!"

foo()


So I presume it can very well happen that you will lose a module when 
trying to finalize.

So most probably it is the cleverest solution to make the cleaner as 
self-contained as possible, by storing explicit references to things you 
might need in the instance itself. But I'm not sure if the transitivity 
of dependencies might not kick your ass somewhere anyhow.

All in all an interesting topic - I'd be looking forward to more 
insights, and very much liked the link you gave us.


Diez


From Sebastien.Boisgerault at gmail.com  Mon Dec 11 10:24:43 2006
From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=)
Date: 11 Dec 2006 07:24:43 -0800
Subject: ElementTree, XML and Unicode -- C0 Controls
Message-ID: <1165850683.430603.6500@79g2000cws.googlegroups.com>

Hi all,

The unicode code points in the 0000-001F range --
except newline, tab, carriage return -- are not legal
XML 1.0 characters.

Attempts to serialize and deserialize such strings
with ElementTree will fail:

>>> elt = Element("root", char=u"\u0000")
>>> xml = tostring(elt)
>>> xml
''
>>> fromstring(xml)
   [...]
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1,
column 12

Good ! But I was expecting a failure *earlier*, in
the "tostring" function -- I basically assumed that
ElementTree would refuse to generate a XML
fragment that is not well-formed.

Could anyone comment on the rationale behind
the current behavior ? Is it a performance issue,
the search for non-valid unicode code points being
too expensive ?

Cheers,

SB



From ycollet at freesurf.fr  Sun Dec 31 08:55:33 2006
From: ycollet at freesurf.fr (ycollet at freesurf.fr)
Date: 31 Dec 2006 05:55:33 -0800
Subject: Python embedded interpreter: how to initialize the interpreter ?
Message-ID: <1167573333.723607.199480@v33g2000cwv.googlegroups.com>

Hello,

I've written a C embedded application. I want to open a python gui
application in my C program but when I do :

PyRun_String( "import gui.py", file_input, pDictionary, pDictionary );

the interpreter emits an error: tkinter module not defined

What script must I load to initialize the embedded python interpreter
so as I have the same modules in the python command line and in the
python embedded interpreter ? /usr/lib/python2.4/*.py ??

Yann COLLETTE



From fuzzyman at gmail.com  Tue Dec 12 05:57:52 2006
From: fuzzyman at gmail.com (Fuzzyman)
Date: 12 Dec 2006 02:57:52 -0800
Subject: One module per class, bad idea?
In-Reply-To: 
References: 
Message-ID: <1165921072.836774.17350@73g2000cwn.googlegroups.com>


Matias Jansson wrote:
> I come from a background of Java and C# where it is common practise to have
> one class per file in the file/project structure. As I have understood it,
> it is more common practice to have many classes in a Python module/file.
> What is the motivation behind it, would it be a bad idea to have a guideline
> in your project that promotes a one class per file structure (assuming most
> of the programmers a background similar to mine)?

It's not a bad general guideline.

We try and use one class per file unless they are really trivial or
tightly coupled to another.

It allows you to be very specific in the naming of files and isolate
functionality.

We also have files with 'helper functions', which often have several
functions.

Fuzzyman
http://www.voidspace.org.uk/index2.shtml



From wescpy at gmail.com  Thu Dec 21 04:41:27 2006
From: wescpy at gmail.com (wesley chun)
Date: Thu, 21 Dec 2006 01:41:27 -0800
Subject: FYA: python cell phone is ruby-less
Message-ID: <78b3a9580612210141m11ab1ac6l4724eba4322f579a@mail.gmail.com>

(mostly off-topic)

vertu makes a $310,000US cell phone which has rubies on it. i thought
it was quite interesting that they have a "cheaper" phone ($115,000)
called Python which *doesn't* have rubies:

http://money.cnn.com/popups/2006/biz2/cellphone

better order yours now since only 26 will be made.  ;-)

happy holidays everyone!
-- 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


From sjmachin at lexicon.net  Sat Dec 16 03:48:13 2006
From: sjmachin at lexicon.net (John Machin)
Date: 16 Dec 2006 00:48:13 -0800
Subject: Roundtrip SQL data especially datetime
In-Reply-To: 
References: 
	<1166211949.065578.292600@f1g2000cwa.googlegroups.com>
	
	
Message-ID: <1166258893.044093.196820@79g2000cws.googlegroups.com>


John Nagle wrote:
> dyork wrote:
> > "John Machin"  wrote in message
> > news:1166211949.065578.292600 at f1g2000cwa.googlegroups.com...
> >
> >>If you have, as you should, Python 2.5, you can use this:
>
>     Actually, MySQLdb isn't released for Python 2.5 yet

Actually, that's interesting information [why should it take so long?],
but the OP didn't actually say what brand of database he was actually
using :-)

Cheers,
John



From http  Fri Dec 15 18:35:02 2006
From: http (Paul Rubin)
Date: 15 Dec 2006 15:35:02 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<874ps423sx.fsf@thalassa.informatimago.com>
	
	
	
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	 
	<4ubu3nF16kv7aU1@mid.individual.net> 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
Message-ID: <7xbqm4d97d.fsf@ruckus.brouhaha.com>

Andr? Thieme  writes:
> And I didn't count the indentation level and \n in Python code.
> Why should I? They are editor commands.

No they're part of Python syntax.  A change in indent level is
recognized by Python's lexical scanner as a token and you should count
it.  You wouldn't count the indent and \n separately though.

>  > Anyway, token count doesn't mean much, you have to instead go by the
>  > user's cognitive effort in dealing with the prefix notation etc.,
> 
> How complicated ss it to say "cmp(a, b)" compared to  "a cmp b"?

It gets worse when the expressions are nested.

> Imagine Python would have an "anaphoric if", "aif". Then:
> 
> aif timeConsumingCalculation():
>    use(it)

Well, it's not really in the Pythonic style to add obscurity like
that, but you could certainly write something like:

    def aif(func):
       it = func()
       if it: use(it)

    aif(timeConsumingCalculation)

> So in some languages that support functional programming one needs
> to do extra work to get lazyness, while in Haskell one gets extra
> work if one doesn't want it. But maybe someone can correct me here...
> In Lisp one could build some features to get lazyness as well.

I think that is essentially correct.  But it's not so easy to do extra
work to get Haskell-like laziness in languages that don't have it, not
because laziness itself is difficult, but non-lazy languages usually
end up giving up referential transparency.

http://lambda-the-ultimate.org/classic/message5750.html


From gkkvishnu at gmail.com  Sat Dec  9 19:57:54 2006
From: gkkvishnu at gmail.com (kiran kumar)
Date: Sun, 10 Dec 2006 01:57:54 +0100
Subject: Is there a memory leakage in this embedded python code?
Message-ID: 

Hi All,
I am working on embedded python on C these days. I feel there is a
memory leakage in this code. I have used our own memory pool and all
the python code will use the heap from this memory pool.
RunScript(pScriptName,pFuncName,...)
{
PyEval_AcquireLock()
threadState = Py_NewInterpreter();
PyThreadState_Swap(threadState);

/* Import the script module and run the fnc in that script module */
Pyobject *pModule = PyImport_Import(pScriptName);
PyObject *pFunc = PyObject_GetAttrString(pModule, pFuncName);
....
/* End running the script and calling the script fnc */
Py_EndInterpreter(threadState);
PyEval_ReleaseLock();
}

Befor running this code i checked my memory heap pool available
memory. Then i called the above function to run my script script1.py.
Script ran succesfully, but after completion of the above fnc, when i
checked the memory there is a huge KB of memory is used by this code.
I have no doubt on my memory pool implementation, bcoz it isworking
from many years.
Now, My doubt is, when i call Py_EndInterpreter at the end does it not
clear the whole memory which was used in executing the script?  Or
still the imported stuff from the script1.py is in memory only?

Would greatly appreciate the help....

vishnu


From bjourne at gmail.com  Fri Dec 22 09:30:11 2006
From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=)
Date: Fri, 22 Dec 2006 15:30:11 +0100
Subject: Generating all permutations from a regexp
Message-ID: <740c3aec0612220630l39be117fu7977a7a2fb6e9998@mail.gmail.com>

With regexps you can search for strings matching it. For example,
given the regexp: "foobar\d\d\d". "foobar123" would match. I want to
do the reverse, from a regexp generate all strings that could match
it.

The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000",
"AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999".

Is this possible to do? Obviously, for some regexps the set of matches
is unbounded (a list of everything that matches "*" would be very
unpractical), but how would you do it for simple regexps like the one
above?

-- 
mvh Bj?rn


From paul at boddie.org.uk  Wed Dec 13 06:10:31 2006
From: paul at boddie.org.uk (Paul Boddie)
Date: 13 Dec 2006 03:10:31 -0800
Subject: Is anyone using Python for embedded applications?
References: <457EEC35.3090104@mvista.com>
	
Message-ID: <1166008231.413891.180380@73g2000cwn.googlegroups.com>

Hendrik van Rooyen wrote:
>
> It depends a *lot* on what is meant by "embedded" :

Indeed.

> This definition seems to cover everything from:
>     - a cut down PC in a non standard box, through
>     - a processor in a Washing Machine, to
>     - a bare PIC processor in a Burglar Alarm...

CPython doesn't span all these situations, but there are a few
different strategies involving Python:

  * A cut-down build of CPython, or perhaps just a recompiled or
    cross-compiled build; this is good enough for some of the more
    "luxurious" embedded devices. The Gumstix hardware is a
    reasonable example:
    http://www.gumstix.org/

  * A re-engineered version of CPython with things taken out or
    optimised for simpler hardware. An example of this approach is
    PyMite:
    http://wiki.python.org/moin/PyMite

  * Software which isn't actually running in Python on the device but
    which has been designed using Python. Projects like MyHDL and
    WhatOS at least allow you to prototype things in Python:
    http://myhdl.jandecaluwe.com/doku.php
    http://www.sticlete.com/whatos/

[...]

> as I in fact discovered Python because it is embedded in a GPS module
> we were evaluating for building into a device - so I will follow your
> progress with interest...

Interesting! Any links, or is it related to the Telit hardware already
discussed?

Paul



From grante at visi.com  Fri Dec  1 14:06:29 2006
From: grante at visi.com (Grant Edwards)
Date: Fri, 01 Dec 2006 19:06:29 -0000
Subject: Thread help
References: <1164999221.679348.221000@16g2000cwy.googlegroups.com>
Message-ID: <12n0v9l4ssfd7fc@corp.supernews.com>

On 2006-12-01, Salvatore Di Fazio  wrote:

> I would make 3 threads for a client application.

You should use 4.

-- 
Grant Edwards                   grante             Yow!  My TOYOTA is built
                                  at               like a... BAGEL with CREAM
                               visi.com            CHEESE!!


From kentilton at gmail.com  Sat Dec  9 03:23:47 2006
From: kentilton at gmail.com (Ken Tilton)
Date: Sat, 09 Dec 2006 03:23:47 -0500
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165594621.136524.198600@80g2000cwy.googlegroups.com>
	
	<1165596641.245385.113090@f1g2000cwa.googlegroups.com>
	
Message-ID: 



Steven D'Aprano wrote:
> On Fri, 08 Dec 2006 08:50:41 -0800, George Sakkis wrote:
> 
> 
>>Andr? Thieme wrote:
>>
>>
>>>On the other hand can I see difficulties in adding macros to Python,
>>>or inventing a new object system, or adding new keywords without
>>>changing the sources of Python itself.
>>
>>Actually, an even bigger difficulty is the rejection of programmable
>>syntax by Guido, both for the near and distant future:
> 
> 
> Why is that a difficulty? Like Guido, I think that's an ADVANTAGE.
> 
> 
>>"Programmable syntax is not in Python's future -- or at least it's not
>>for Python 3000. The problem IMO is that everybody will abuse it to
>>define their own language. And the problem with that is that it will
>>fracture the Python community because nobody can read each other's code
>>any more."
>>
>>http://mail.python.org/pipermail/python-3000/2006-April/000286.html.
> 
> 
> I couldn't have said it better myself.

No, but you could have quoted it more completely :

> But please save your breath. Programmable syntax is not in Python's
> future -- or at least it's not for Python 3000. The problem IMO is
> that everybody will abuse it to define their own language. And the
> problem with that is that it will fracture the Python community
> because nobody can read each other's code any more.

The last time c.l.l and c.l.p went to friendly war over macros we kept 
wondering why macros were any less comprehensible than functions or 
classes. Here it is!:

> 
> It's one thing to read code that calls an external function whose
> meaning you have to guess from its name. It's quite another thing to
> realize that you can't even know for sure where the function calls
> are. Let's not go there.

GvR seems to be thinking of something like the loop macro, which in its 
most commonly used syntax (it has two!) constitutes a distinct and 
unlispy language. If that is how macros were normally used (LOOP is 
quite abnormal) then, yikes, every macro could introduce a new language 
to be mastered.

Uhhhh, that is not how macros are used normally. And it is a helluva lot 
of work to erect a new syntax as LOOP does, so it is not exactly 
tempting. So... is GvR being scared off by a straw man?

The other possibility is that he is just trying to justify not doing it 
because it would be so hard without the regular syntax of Lisp, 
including parens, and with the JIT module resolution problem discussed 
earlier in his remarks. Understandable.

A final good reason is, hey, we already /have/ Lisp, Python needs to be 
different in order not to get absorbed into the mother of all languages.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


From __peter__ at web.de  Wed Dec  6 05:10:16 2006
From: __peter__ at web.de (Peter Otten)
Date: Wed, 06 Dec 2006 11:10:16 +0100
Subject: Novice: replacing strings with unicode variables in a list
References: <1165397220.491511.159310@f1g2000cwa.googlegroups.com>
Message-ID: 

aine_canby at yahoo.com wrote:

> Im totally new to Python so please bare with me.

That's no problem, really. I don't use a spellchecker, either, and it
wouldn't have protected you from that particular typo...
 
> Data is entered into my program using the folling code -
> 
> str = raw_input(command)
> words = str.split()
> 
> for word in words:
>   word = unicode(word,'latin-1')
>   word.encode('utf8')
> 
> This gives an error:
> 
>   File "C:\Python25\lib\encodings\cp850.py", line 12, in encode
>     return codecs.charmap_encode(input,errors,encoding_map)
> UnicodeEncodeError: 'charmap' codec can't encode character u'\x94' in
> position 0
> : character maps to 
> 
> but the following works.
> 
> str = raw_input(command)
> words = str.split()
> 
> for word in words:
>   uni = u""
>   uni = unicode(word,'latin-1')
>   uni.encode('utf8')

Here you show us the same code twice, as the 

uni = u""

assignment has no effect, and a traceback that is probably generated when
you try to

print uni

Here's my guess: The encoding you actually need is cp850, the same that your
Python interpreter is trying to use, but in which unichr(0x94) is
undefined. In general, you are not free to use a random encoding; rather,
you have to use what your console expects.

import sys

s = raw_input(command)
s = unicode(s, sys.stdin.encoding) # trust python to find out the proper 
                                   # encoding. If that fails use a constant,
                                   # probably "cp850"
words = s.split():
for word in words:
   print word # trust python, but if it doesn't work out:
   # word = word.encode("cp850")
   # print word

By the way, strings are immutable (cannot be altered once created), so the
following 

> word.encode('utf8')
> print word

is actually spelt

word = word.encode("utf8")
print word

If your data is not read from the console and it contains characters that
cannot be printed, unicode.encode() accepts a second parameter to deal with
it, see

>>> help(u"".encode)

Peter


From evanmason at gmail.com  Tue Dec  5 05:27:01 2006
From: evanmason at gmail.com (Evan)
Date: 5 Dec 2006 02:27:01 -0800
Subject: global name 'self' is not defined
In-Reply-To: 
References: <1165084948.125632.121260@79g2000cws.googlegroups.com>
	
	<1165087301.512807.289200@16g2000cwy.googlegroups.com>
	<4teiqfF13krd9U1@mid.individual.net>
	<1165235129.405963.73860@73g2000cwn.googlegroups.com>
	
Message-ID: <1165314421.354880.74380@j72g2000cwa.googlegroups.com>

Hi Dennis, to answer your questions:

1) So far as I can see ipython generates .pyc files.
2) This morning I ran the scripts, and got the same problem using
ipython as in my earlier post.  I then deleted the .pyc file, ran the
calling script and this time it works.  I then replaced the .pyc file I
had deleted, expecting to have the problem again, but no.
3) I've tried your suggestion, and it works fine.

A few questions: Why does python use the double underscore (__main__ or
if __name__)?  I've only been using python for about 3 weeks, and I see
this syntax a lot, but haven't found an explanation for it so far?
Also, as I understand , the .pyc files should be updated every time you
change and run the equivalent .py file?

Thanks, Evan



From e0427417 at student.tuwien.ac.at  Fri Dec  1 18:13:33 2006
From: e0427417 at student.tuwien.ac.at (Mathias Panzenboeck)
Date: Sat, 02 Dec 2006 00:13:33 +0100
Subject: type(foo) == function ?
In-Reply-To: 
References: 
	
Message-ID: <4570b689$0$11868$3b214f66@tunews.univie.ac.at>

Chris Mellon wrote:
> On 11/29/06, Tom Plunket  wrote:
>> I'd like to figure out if a given parameter is a function or not.
>>
>> E.g.
>>
>> >>> type(1)
>> 
>> >>> type(1) == int
>> True
>>
>> implies:
>>
>> >>> def foo():
>> ...   pass
>> ...
>> >>> type(foo)
>> 
>> >>> type(foo) == function
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>> NameError: name 'function' is not defined
>>
>> Is there a way I can know if 'foo' is a function?
>>
> 
>>>> def foo():
> ...     pass
> ...
>>>> from inspect import isfunction
>>>> isfunction(foo)
> True
>>>>
> 
> 
> But you probably want the callable() builtin instead.
> 

This builtin will be removed in python 3.0!

>> thanks,
>> -tom!
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>>


From address.good.until.2007.feb.05 at justmail.de  Fri Dec 15 17:19:38 2006
From: address.good.until.2007.feb.05 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=)
Date: Fri, 15 Dec 2006 23:19:38 +0100
Subject: merits of Lisp vs Python
In-Reply-To: <1166217335.432132.162750@l12g2000cwl.googlegroups.com>
References: 
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	 
	<4ubu3nF16kv7aU1@mid.individual.net> 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
	<1166217335.432132.162750@l12g2000cwl.googlegroups.com>
Message-ID: 

mikael.jansson at gmail.com schrieb:
William James schrieb:
 >>> How would you solve this in Python?
 >>> You could embed it inside a lambda and must somehow make the
 >>> variable "it" visible in it, because in the context of aif this
 >>> "it" gets bound to the result.In Ruby:
 >> def aif val
 >>   yield val   if val
 >> end
 >>
 >> def complex_calc n
 >>   if n % 2 == 1
 >>     n**n
 >>   else
 >>     nil
 >>   end
 >> end
 >>
 >> aif( complex_calc( 9 ) ) {|x| puts "hello, #{x}"}
 >> aif( complex_calc( 8 ) ) {|x| puts "hello, #{x}"}
 >>
 >> ---  output  -----
 >> hello, 387420489
 >>
 > Okay, so it's certainly _doable_. I think the question is more if it's
 > usable. Regular if:s don't like that in Ruby/Python/similar, and adding
 > such a construct would mean extending the syntax.
 >
 > In Lisp, all (well, almost) functions are equal, so an (if ...) would
 > look the same like the (aif ...).  I think that's the point here.

Exactly that is the point.
*Of course* it is doable.
And what William shows us is maybe one of the best solutions
in Ruby. He used advanced abstractions that made it possible.
The thing with most (if not all) programming languages other than Lisp
is: these abstractions are leaky.
They have a low level knowledge leak. Users of aif need to know how to
pass in arguments. As you see he had do embed the code that needs execution
into a block (anon function) and then use this special syntax for x.


Andr?
-- 


From robert.kern at gmail.com  Sun Dec 10 20:04:01 2006
From: robert.kern at gmail.com (Robert Kern)
Date: Sun, 10 Dec 2006 19:04:01 -0600
Subject: Barry Warsaw Python Webcast at GSFC
In-Reply-To: <87fybncmp3.fsf@benfinney.id.au>
References: 
	<87fybncmp3.fsf@benfinney.id.au>
Message-ID: 

Ben Finney wrote:
> William Allison  writes:
> 
>> http://isandtcolloq.gsfc.nasa.gov/webcasts.html
>> It's at the bottom of the page.
> 
> In WMV format, and thus not viewable with free software :-(

I can view the stream with mplayer 1.0rc1-4.0.1 with ffmpeg's libavcodec

[~]$ mplayer mms://128.183.174.165/pubpublish/Colloquia/IST/2006/IST20061108.wmv
MPlayer 1.0rc1-4.0.1 (C) 2000-2006 MPlayer Team
CPU: Intel(R) Core(TM)2 CPU         T7600  @ 2.33GHz (Family: 6, Model: 15,
Stepping: 6)
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2
97 audio & 210 video codecs

...

==========================================================================
Requested video codec family [wmv9dmo] (vfm=dmo) not available.
Enable it at compilation.
Requested video codec family [wmvdmo] (vfm=dmo) not available.
Enable it at compilation.
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffwmv3] vfm: ffmpeg (FFmpeg M$ WMV3/WMV9)
==========================================================================
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 44100 Hz, 1 ch, s16le, 32.0 kbit/4.54% (ratio: 4006->88200)
Selected audio codec: [ffwmav2] afm: ffmpeg (DivX audio v2 (FFmpeg))
==========================================================================

-- 
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



From dannycolligan at gmail.com  Thu Dec  7 09:10:49 2006
From: dannycolligan at gmail.com (Danny Colligan)
Date: 7 Dec 2006 06:10:49 -0800
Subject: Common Python Idioms
In-Reply-To: <1165493298.205945.162430@n67g2000cwd.googlegroups.com>
References: 
	<17783.32458.730462.8403@montanaro.dyndns.org>
	
	<1165493298.205945.162430@n67g2000cwd.googlegroups.com>
Message-ID: <1165500649.129625.213300@j44g2000cwa.googlegroups.com>

> Is there a list somewhere listing those not-so-obvious-idioms?

I don't know about lists of not-so-obvious idioms, but here's some
gotchas (there may be some overlap with what you're asking about):

http://zephyrfalcon.org/labs/python_pitfalls.html
http://www.ferg.org/projects/python_gotchas.html
http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html

Danny



From justin.mailinglists at gmail.com  Fri Dec 22 04:37:35 2006
From: justin.mailinglists at gmail.com (Justin Ezequiel)
Date: 22 Dec 2006 01:37:35 -0800
Subject: Script Error
References: <1166510370.819303.94750@79g2000cws.googlegroups.com>
	<1166773002.418760.50940@42g2000cwt.googlegroups.com>
Message-ID: <1166780255.694242.319040@48g2000cwx.googlegroups.com>

ie.Navigate ('URL')
ie.SetTextBox(username,'txtUserId',0)

not sure but shouldn't you be waiting for navigate to actually
finish loading the page before setting fields?

see the ie.Busy or ie.readyState properties/methods



From gagsl-py at yahoo.com.ar  Wed Dec 27 19:53:51 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Wed, 27 Dec 2006 21:53:51 -0300
Subject: failing to instantiate an inner class because of its order
In-Reply-To: <873b707vx3.fsf@pyenos.pyenos.org>
References: <87fyb16icw.fsf@pyenos.pyenos.org>
	<877iwc7w56.fsf@pyenos.pyenos.org>
	<873b707vx3.fsf@pyenos.pyenos.org>
Message-ID: <7.0.1.0.0.20061227213731.05ae0c30@yahoo.com.ar>

At Wednesday 27/12/2006 20:37, Pyenos wrote:

>class Model:
>     def fuck(self):print "fuck!"
>
>class View:
>         Model() #this part is fine
>
>class Controller:
>         def __init__(self):
>                 self.Model=Model()
>
>Controller().Model.fuck() #actually slight problem in previous solution
>
>
>Has to call in this way. I have confirmed this works.

The Model() inside View is *not* fine - you construct a Model 
instance just to discard it! Besides some side effects that 
constructing a Model() might have, this is useless.
If you are trying to implement a real MVC, usually the model exists 
by itself even before you need the view, so usually the view 
constructor gets the model as an argument.
I prefer to use lowercase attribute names: self.model = Model(), this 
way there is no confusion between model (an instance) and Model (a class).


-- 
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 



From kw at codebykevin.com  Sat Dec  9 12:17:19 2006
From: kw at codebykevin.com (Kevin Walzer)
Date: Sat, 09 Dec 2006 12:17:19 -0500
Subject: Error: unbound method in Tkinter class
Message-ID: <6d3e0$457aefa4$4275d90a$12235@FUSE.NET>

I am trying to structure a Tkinter application with classes instead of
just with simple functions, but I'm not sure how to call methods from my
main class.

My main class is packetstreamApp(). Within that class I call various
methods, including drawGUI() and authorizeDump(). My problem comes when
I try to call authorizeDump from the Tkinter menu. Here is the code that
calls authorizeDump():

self.packetmenu.add_command(label="Start Network Monitor",
command=packetstreamApp.authorizeDump())

Here is the code for authorizeDump():

 def authorizeDump(self):
	##do stuff here

And here is the error message that comes when I try to call authorizeDump():

Traceback (most recent call last):
  File "/Users/kevin/Programming/packetstream/packetstream-classes.py",
line 257, in 
    app = packetstreamApp()
  File "/Users/kevin/Programming/packetstream/packetstream-classes.py",
line 19, in __init__
    self.drawGUI()
  File "/Users/kevin/Programming/packetstream/packetstream-classes.py",
line 49, in drawGUI
    self.packetmenu.add_command(label="Start Network Monitor",
command=packetstreamApp.authorizeDump())
TypeError: unbound method authorizeDump() must be called with
packetstreamApp instance as first argument (got nothing instead)

I don't know how to interpret this error message, and so can't implement
a fix. Can anyone shed light on what I'm doing wrong?

Thanks.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


From Roberto.Bonvallet at cern.ch  Thu Dec 14 08:52:24 2006
From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet)
Date: Thu, 14 Dec 2006 13:52:24 +0000 (UTC)
Subject: tuple.index()
References: 
	
	<1166103409.199435.290670@79g2000cws.googlegroups.com>
Message-ID: 

Glenn Hutchings wrote:
> But there are situations where you might want to treat it as a
> read-only list.  E.g., an argument to a function, so that you can
> guarantee the function won't modify it.  In that case, it makes sense
> for the non-modifying methods (index() and count()) to be available.

list(my_arg).index(...)

-- 
Roberto Bonvallet


From rpdooling at gmail.com  Thu Dec 14 08:19:33 2006
From: rpdooling at gmail.com (BartlebyScrivener)
Date: 14 Dec 2006 05:19:33 -0800
Subject: How do I edit a PythonWin path to import custom built modules???
In-Reply-To: 
References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com>
	<1165850571.131438.185940@l12g2000cwl.googlegroups.com>
	<1165912704.390252.184260@n67g2000cwd.googlegroups.com>
	<1165917988.141401.195050@16g2000cwy.googlegroups.com>
	<1165935598.701360.101390@f1g2000cwa.googlegroups.com>
	
	<1166015447.721253.9680@80g2000cwy.googlegroups.com>
	
	<1166046193.734274.124160@73g2000cwn.googlegroups.com>
	
	<1166055959.498100.116240@79g2000cws.googlegroups.com>
	
Message-ID: <1166102373.233436.182320@73g2000cwn.googlegroups.com>

Fredrik Lundh wrote:

> is this an ActiveState build?

Yes, I think I mentioned it further up the thread.

> what's sys.prefix and sys.exec_prefix set to on your machine, btw?

'C:\\Python24'

No big deal. I always just assumed that it found my scripts via the
path variable. As long as it finds them. I'm happy.

But you got me thinking. I just did the commands you suggested on my
laptop, after installing python.org 2.5. With 'd:\python' in the path
environmental variable there also, it does NOT appear when I do plain
old:

>>>sys.path

but does appear when I import site first.

rd



From gagsl-py at yahoo.com.ar  Thu Dec  7 22:16:34 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Fri, 08 Dec 2006 00:16:34 -0300
Subject: Common Python Idioms
In-Reply-To: 
References: 
	<17783.32458.730462.8403@montanaro.dyndns.org>
	
	<1165493298.205945.162430@n67g2000cwd.googlegroups.com>
	<1165500649.129625.213300@j44g2000cwa.googlegroups.com>
	<1165528352.978586.248960@16g2000cwy.googlegroups.com>
	
Message-ID: <7.0.1.0.0.20061208001033.0404b9f8@yahoo.com.ar>

At Thursday 7/12/2006 19:45, Steven D'Aprano wrote:

> > I'm surprized that none of these pages mentions the incompatible type
> > comparison gotcha:
> >
> >>>> 5 < "4"
> > True
> >
> > I'm sure this has bitten many folks, particularly (ex) Perl'ers.
>
>Why is this a gotcha?
>
>I can't speak for others, but except for sorting, I've never been tempted
>to compare ints to strings like that, but thinking about the code I've
>written, I can't think of any bad consequences that would have happened if
>I had.
>
>I'm not saying that there are never bad consequences for comparing
>incompatible types, but I'm questioning that it is a gotcha, let alone a
>common gotcha. What do others think? Ever been bitten by 5 < "4"?

Yes. By example, on a web application. If you forget to convert the 
form or query values to their correct type, you could mix things 
inadvertidely like that.
Of course, not exactly as written, but

def test(self, value):
     if value>self.value: self.value=value

(when self.value is an int, but value comes as a string)

As always, once you know that, you make sure it wont happen again...


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From paddy3118 at netscape.net  Sun Dec 17 02:59:05 2006
From: paddy3118 at netscape.net (Paddy)
Date: 16 Dec 2006 23:59:05 -0800
Subject: OT : Bug/Issue tracking systems
In-Reply-To: <1166338246.113948.320240@l12g2000cwl.googlegroups.com>
References: <1166338246.113948.320240@l12g2000cwl.googlegroups.com>
Message-ID: <1166342345.860327.186410@73g2000cwn.googlegroups.com>


moogyd at yahoo.co.uk wrote:
> Hi,
>
> (Off-topic)
>
> I am looking to put an open-source bug/issue tracking system in place
> for our current project (eventually expanded for all projects), and
> would appreciate any experiences/comments/suggestions.
>
> Note the project is encompasses embedded hardware (ASIC plus firmware)
> plus application software.
> The easiest method is using a spreadsheet, but this is not very
> expandable.
>
> The requirements I have come up with
>
> - Free ;-)
> - Easy to setup and maintain (I want this to be an engieering tool, not
> an IT project)
>   - A non linux expert should be able to download and install (rpms OK,
> deep understanding of makefiles and linux kernel not OK)
>   - Ideally via text files, a bit of perl/tcl/python OK. I'd rather
> avoid SQL
>   - Prove the system and then hand-off to IT for maintenance
> - Easy use
>   - Browser UI
>   - Mail ?
> - Linux
> - Flexible reporting/search
> - User/admin accounts
>   - Initially internal network access only, eventually external
> (customer, partner) access
> - Cover HDL, H/W, F/W, Documentation, Change requests. Both ASIC and
> FPGA.
> - Eventually production issues (Yeild, Test programs?)
> - Maybe allow project deadlines included.
> - We use CVS, so any loose coupling useful
>   - We have per project repositories, plus and repository containing
> common IP's (i.e a project will always use 2)
> - Medium size projects (upto 15-20 people)
> - Possible migration to other system in future (which I guess means a
> well supported database)
>
> Googling provided with lots of names
> - Bugzilla (seems to be in widest use for S/W projects)
> - GNATS (I recall using this in a previous job)
> - IssueTrackerSystem (ZOPE, Python)
> - Trac (Python)
> - Plus lots of others
>
> Any suggestions, comments, recommendations or pointers to
> papers/tutorals greatly appreciated.
>
> Steven
Hi Steven,
We mainly do ASIC design and the Verification team installed RT for
local issue tracking at work. I would have suggested Trak, but I was on
a different project at the time and they were doing the work.
RT (http://www.bestpractical.com/rt) does the Job. They have got the IT
team to install it on the compute farm somewhere and after an initial
learning period, they got it to do what they want.
I have used gnats in the past. It worked.
Trac seems to me to have a lot going for it, but, alas, I have not had
a chance to try it.

i notice that you are using CVS. You might want to look into the
facilities available with tools like mercurial
http://blog.arabx.com.au/?p=254,
http://www.selenic.com/mercurial/wiki/index.cgi,
http://www.opensolaris.org/os/community/tools/scm/
http://video.google.co.uk/videoplay?docid=-7724296011317502612&q=mercurial


At work we pay for clearcase and it does the revision control job very
well, but in another company that were using CVS or RCS I would
re-evaluate the source control needs.

- Paddy.



From wrongbad at gmail.com  Tue Dec 12 03:21:48 2006
From: wrongbad at gmail.com (I V)
Date: Tue, 12 Dec 2006 00:21:48 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	<4u18tpF166u62U1@mid.individual.net> 
	<4u4qoaF15uds8U2@mid.individual.net>
	
	<4u6meeF161jbqU1@mid.individual.net>
	
Message-ID: 

On Mon, 11 Dec 2006 23:24:07 -0500, Ken Tilton wrote:
> Also, Python does not support a functional style of programming so the 
> line is the only meaningful textual entity. In this sense the 
> primitiveness of Python makes editing easier.

Why do you say that? Wouldn't a block in python be a "meaningful textual
entity" in the same way a lisp form would be?


From hg at nospam.com  Fri Dec  1 06:16:02 2006
From: hg at nospam.com (hg)
Date: Fri, 01 Dec 2006 05:16:02 -0600
Subject: python vs java & eclipse
In-Reply-To: 
References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com>	<8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com>
	
Message-ID: <5kUbh.2584$Ka4.2422@newsfe14.lga>

krishnakant Mane wrote:
> just used the py dev plugin for eclipse.
> it is great.
> auto indentation and intellisence.
> and all other things.
> so now how does it look from this end?
> python + productivity and eclipse + productivity = double productivity!
> only problem with the plugin is that I find it difficult to manage the
> script running.
> I open a command prompt and run the scripts manually.
> any suggestion for this.
> for example I had name = raw_input("please enter your name") and the
> moment I type the first letter on the keyboard the code execution
> moves over to the next statement.  should it not wait for the return
> key as it always does?
> Krishnakant.
I don't know about raw_input ... my programs all go through some GUI ...
but I run / debug(although almost never) all of my applications from
pydev - no need to change project as with Visual Studio, I just
run/debug whatever I need with a few clicks ... have not touched Konsole
 in weeks.

I also, after weeks of testing, decided to invest in the pydev
extensions / the bugs it has found for me already justify the investment.

hg


From bj_666 at gmx.net  Wed Dec 27 10:46:58 2006
From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch)
Date: Wed, 27 Dec 2006 16:46:58 +0100
Subject: newbie question: any better way to write this code?
References: <1167232702.061737.25610@42g2000cwt.googlegroups.com>
Message-ID: 

In <1167232702.061737.25610 at 42g2000cwt.googlegroups.com>, neoedmund wrote:

> i want to let a byte array to be xor with some value.
> but code show below i wrote seems not so .. good..., any better way to
> write such function? thanks.
>
> def xor(buf):
> 	bout=[]
> 	for i in range(len(buf)):
> 		x = ord(buf[i])
> 		x ^= 123
> 		bout.append(chr(x))
> 	return "".join(buf)
> buf = "xxxxxxxx".encode("utf8")
> buf = xor(buf)

def xor(buf):
    return ''.join(chr(ord(x) ^ 123) for x in buf)

Ciao,
	Marc 'BlackJack' Rintsch


From jordan.taylor2 at gmail.com  Thu Dec  7 13:16:04 2006
From: jordan.taylor2 at gmail.com (Jordan)
Date: 7 Dec 2006 10:16:04 -0800
Subject: How to create a global hotkey?
In-Reply-To: 
References: <1165492421.317438.237350@j72g2000cwa.googlegroups.com>
	
Message-ID: <1165515363.838887.109720@80g2000cwy.googlegroups.com>

If you're using python 2.4, you can use the pyHook library (I don't
think it has been ported to 2.5 yet... I should email him about that),
which can hook both the mouse and keyboard, so your program can be
running in the background and still catch what keys (or mouse clicks)
are pressed.  The pyHook extension comes with some very good examples
of how to use it, but if they aren't good enough examples (I can't
imagine that would happen), you should check out pykeylogger
(sourceforge) which uses the pyHook extension (it's a really good
program. Although not like conventional keyloggers built in C/C++ which
hide themselves from the OS - the purpose was not actually to spy on
the user but to create backups of what was typed - it still does a very
good job and the latest release has a lot of options and
extendability).  If your OS is linux, unix, or mac... good luck   ;D

Cheers,
Jordan


Gerold Penz wrote:
> > I want my function to execute when the user presses the
> > hotkey anywhere.
>
> Hi!
>
> - XLib unter Linux: http://python-xlib.sourceforge.net/
> - wxPython unter Windows:
> http://wxpython.org/docs/api/wx.Window-class.html#RegisterHotKey
>
> regards,
> Gerold
> :-)
>
> --
> ________________________________________________________________________
> Gerold Penz - bcom - Programmierung
>      gerold.penz at tirol.utanet.at | http://gerold.bcom.at | http://sw3.at
> Ehrliche, herzliche Begeisterung ist einer der
>      wirksamsten Erfolgsfaktoren. Dale Carnegie



From significants at gmail.com  Mon Dec 11 22:41:05 2006
From: significants at gmail.com (Simon Schuster)
Date: Mon, 11 Dec 2006 19:41:05 -0800
Subject: problem while going through a tutorial
Message-ID: <5c1d2d910612111941m6fdf84d1v66bd8d374d40fcec@mail.gmail.com>

I'm new to python, and almost new to programming in general. I'm at
http://www.pasteur.fr/formation/infobio/python/ch04.html in that
tutorial, and my 'count' function (if it's called a function?) isn't
working suddenly.

>>> x = "fljshfjh"
>>> x
'fljshfjh'
>>> count(x, 'h')
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'count' is not defined

I'm not sure what changed, because it used to work. anyhow thanks a lot!

chris


From felipe.lessa at gmail.com  Tue Dec  5 00:24:43 2006
From: felipe.lessa at gmail.com (Felipe Almeida Lessa)
Date: Tue, 5 Dec 2006 03:24:43 -0200
Subject: Async callback in python
In-Reply-To: <1165292302.454012.118540@n67g2000cwd.googlegroups.com>
References: <1165292302.454012.118540@n67g2000cwd.googlegroups.com>
Message-ID: 

On 4 Dec 2006 20:18:22 -0800, Linan  wrote:
> 3, If not, where to get the real one(s)?

After reading Calvin's mail, you may want to see
http://twistedmatrix.com/ . It's an assynchronous library built around
the concept of deferreds (think of callbacks). You may like it =).

Cya,

-- 
Felipe.


From http  Sun Dec 17 21:59:53 2006
From: http (Paul Rubin)
Date: 17 Dec 2006 18:59:53 -0800
Subject: merits of Lisp vs Python
References:  
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
	<4uhl7cF108ri8U2@mid.individual.net>
	
	<7xslfgou14.fsf@ruckus.brouhaha.com>
	<2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom>
	<7xac1nfmyb.fsf@ruckus.brouhaha.com>
	<1166342606.141406.137000@f1g2000cwa.googlegroups.com>
	<7x3b7ekk6p.fsf@ruckus.brouhaha.com>
	<1166410256.785907.69140@73g2000cwn.googlegroups.com>
Message-ID: <7xy7p5kixi.fsf@ruckus.brouhaha.com>

xscottg at gmail.com writes:
> I should assume you meant Common Lisp, but there isn't really any
> reason you couldn't
> 
>      (poke destination (peek source))

That breaks the reliability of GC.  I'd say you're no longer writing
in Lisp if you use something like that.  Writing in this "augmented
Lisp" can be ok if well-localized and done carefully, but you no
longer have the guarantees that you get from unaugmented Lisp.  By
adding one feature you've removed another.


From fumanchu at amor.org  Wed Dec 13 11:49:40 2006
From: fumanchu at amor.org (fumanchu)
Date: 13 Dec 2006 08:49:40 -0800
Subject: Frame hacking
References: <1165956409.786690.150240@79g2000cws.googlegroups.com>
	<1165957786.424433.236650@79g2000cws.googlegroups.com>
	<1165960590.466033.172030@l12g2000cwl.googlegroups.com>
	<1166022193.628689.182050@j72g2000cwa.googlegroups.com>
Message-ID: <1166028580.436648.322730@t46g2000cwa.googlegroups.com>

George Sakkis wrote:
> Actually I thought about this and it would be more convenient in my
> case if I could change the "signature" of f to "def f(x,y)" so that I
> can pass positional arguments instead of a keywords (don't ask why).
> I've tried creating a new code object by tweaking co_varnames,
> co_argcount, co_nlocals and making a new function out of it but it
> doesn't work.. does co_code have to be changed as well, and if so, how?

Yes; since x and y then become locals and are looked up using LOAD_FAST
instead of LOAD_GLOBAL. Easiest approach: write the new function
yourself and pass it to dis.dis() and expreiment with the differences
in bytecode.

Here are some helpers I use for bytecode hacking (from the top of
http://projects.amor.org/dejavu/browser/trunk/codewalk.py):

from opcode import cmp_op, opname, opmap, HAVE_ARGUMENT
from types import CodeType, FunctionType, MethodType

from compiler.consts import *
CO_NOFREE = 0x0040


def named_opcodes(bits):
    """Change initial numeric opcode bits to their named
equivalents."""
    bitnums = []
    bits = iter(bits)
    for x in bits:
        bitnums.append(opname[x])
        if x >= HAVE_ARGUMENT:
            try:
                bitnums.append(bits.next())
                bitnums.append(bits.next())
            except StopIteration:
                break
    return bitnums

def numeric_opcodes(bits):
    """Change named opcode bits to their numeric equivalents."""
    bitnums = []
    for x in bits:
        if isinstance(x, basestring):
            x = opmap[x]
        bitnums.append(x)
    return bitnums

_deref_bytecode = numeric_opcodes(['LOAD_DEREF', 0, 0, 'RETURN_VALUE'])
# CodeType(argcount, nlocals, stacksize, flags, codestring, constants,
#          names, varnames, filename, name, firstlineno,
#          lnotab[, freevars[, cellvars]])
_derefblock = CodeType(0, 0, 1, 3, ''.join(map(chr, _deref_bytecode)),
                       (None,), ('cell',), (), '', '', 2, '',
('cell',))
def deref_cell(cell):
    """Return the value of 'cell' (an object from a func_closure)."""
    # FunctionType(code, globals[, name[, argdefs[, closure]]])
    return FunctionType(_derefblock, {}, "", (), (cell,))()


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org



From usenet-mail-0306.20.chr0n0ss at spamgourmet.com  Wed Dec  6 08:46:22 2006
From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann)
Date: Wed, 06 Dec 2006 14:46:22 +0100
Subject: dict.has_key(x) versus 'x in dict'
References: 
Message-ID: <4tnvstF14cki5U1@mid.individual.net>

Paul Melis wrote:

> I've always been using the has_key() method to test if a
> dictionary contains a certain key. Recently I tried the same using
> 'in', e.g.
> 
> d = { ... }
> if k in d:
>     ...

Wouldn't be "if k in d.keys()" be the exact replacement?

Regards,


Bj?rn

-- 
BOFH excuse #17:

fat electrons in the lines



From vbgunz at gmail.com  Sun Dec 24 22:41:07 2006
From: vbgunz at gmail.com (vbgunz)
Date: 24 Dec 2006 19:41:07 -0800
Subject: Why does Python never add itself to the Windows path?
In-Reply-To: <1167009405.771413.122790@i12g2000cwa.googlegroups.com>
References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com>
Message-ID: <1167018067.659291.276020@79g2000cws.googlegroups.com>


Ben Sizer wrote:
> I've installed several different versions of Python across several
> different versions of MS Windows, and not a single time was the Python
> directory or the Scripts subdirectory added to the PATH environment
> variable. Every time, I've had to go through and add this by hand, to
> have something resembling a usable Python installation. No such
> problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or
> Kubuntu. So why is the Windows install half-crippled by default? I just
> rediscovered this today when trying to run one of the Turbogears
> scripts, but this has puzzled me for years now.
> 
> -- 
> Ben Sizer

excellent question



From st at tobiah.org  Mon Dec 18 15:42:23 2006
From: st at tobiah.org (tobiah)
Date: Mon, 18 Dec 2006 12:42:23 -0800
Subject: skip last line in loops
In-Reply-To: <0lwgh.31271$wP1.5113@newssvr14.news.prodigy.net>
References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com>
	
	<1166182692.041668.218730@f1g2000cwa.googlegroups.com>
	<0lwgh.31271$wP1.5113@newssvr14.news.prodigy.net>
Message-ID: <4586f06a$0$15454$88260bb3@free.teranews.com>

> See the documentation for xreadlines.
> 
> James

Hmm...

This method returns the same thing as iter(f). New in version 2.1.
Deprecated since release 2.3. Use "for line in file" instead.

-- 
Posted via a free Usenet account from http://www.teranews.com



From webraviteja at gmail.com  Thu Dec  7 23:38:53 2006
From: webraviteja at gmail.com (Ravi Teja)
Date: 7 Dec 2006 20:38:53 -0800
Subject: SOAP Server with WSDL?
In-Reply-To: <4578806e$0$15511$88260bb3@free.teranews.com>
References: <45787179$0$15498$88260bb3@free.teranews.com>
	
	<4578806e$0$15511$88260bb3@free.teranews.com>
Message-ID: <1165552733.796319.17200@79g2000cws.googlegroups.com>


tobiah wrote:
> Actually, do I have to make a WSDL?  Do people hand write these, or
> are there tools?  I don't really need to publish an interface.  I just
> want some in house apps to communicate.

Java and .NET based tools can auto-generate WSDL from code. Python does
not have such because function definitions do not contain the type
information required for such a tool. However , you can grab a free
Java (Netbeans with Enterprise pack) or .NET (Visual Studio Express)
IDE (or just the respective SDK if you don't mind reading through the
docs), create a stub function, mark it as a WebMethod, let it generate
the WSDL and pass it to wsdl2py that comes with ZSI. This is a twisted
approach.

But you state that you don't need to publish an interface. If that is
the case, it can be as simple as this.

      import SOAPpy
      def hello():
	  return "Hello World"

      server = SOAP.SOAPServer(("localhost", 8080))
      server.registerFunction(hello)
      server.serve_forever()

Pasted from
http://pywebsvcs.sourceforge.net/soappy.txt

> I can't figure out if I want SOAP, or CORBA, or would it just be
> easier if I just starting opening sockets and firing data around
> directly.  Ideally, I'd like to share complex objects.  That's why
> I thought that I needed one of the above standards.

I posted a few days ago a simple guide to choosing a remoting
framework.
http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/f53221adfca5c819/58057e83c0ad7c27?rnum=1&hl=en&q=webraviteja&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2Ff53221adfca5c819%2F3f056c5c87279aca%3Flnk%3Dgst%26q%3Dwebraviteja%26rnum%3D4%26hl%3Den%26#doc_3f056c5c87279aca

For *complex* objects, you need a stateful remoting mechanism. The
choice is Pyro if both the server and all the clients are written in
Python. Else, use CORBA or ICE with DMI. All of these are simple to use
for simple remote object invocations although distributed computing in
general does have a learning curve.

Ravi Teja.



From george.sakkis at gmail.com  Fri Dec 15 12:14:46 2006
From: george.sakkis at gmail.com (George Sakkis)
Date: 15 Dec 2006 09:14:46 -0800
Subject: Property error
References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com>
	
	<1166179622.872556.312810@n67g2000cwd.googlegroups.com>
	<1166181267.949316.197360@16g2000cwy.googlegroups.com>
Message-ID: <1166196987.083476.287340@n67g2000cwd.googlegroups.com>

king kikapu wrote:

> Your example Dennis, work as expected. I understand the mistake i have
> made. But when i try to fix the original code usihn @property now, it
> gives me the same error.
> So, here it is:
>
> class Person(object):
>     _age = 0
>
>     @property
>     def age():
>         def fget(self):
>             return self._age
>         def fset(self, value):
>             self._age = value
>
> me = Person()
> me.age = 34
> print me.age
>
>
> I am sure it is something very obvious but my skills does not (yet)
> enable me to figure this out,,,

As others have already replied, the default property doesn't work this
way. In your example, it is possible to write it in one line using
lambda:

class Person(object):

    age = property(fget=lambda self: self._age,
                   fset=lambda self, value: setattr(self,'_age',value))

If any of fget,fset,fdel cannot be written as lambda or you'd rather
write them as functions, you may use the recipe at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698.

HTH,
George



From bdesth.quelquechose at free.quelquepart.fr  Wed Dec 20 06:38:30 2006
From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers)
Date: Wed, 20 Dec 2006 12:38:30 +0100
Subject: Page layouts in mod_python?
In-Reply-To: <1166571254.954865.43430@73g2000cwn.googlegroups.com>
References: <1166563784.948936.253950@80g2000cwy.googlegroups.com>
	<45886568$0$31043$426a74cc@news.free.fr>
	<1166571254.954865.43430@73g2000cwn.googlegroups.com>
Message-ID: <45891af2$0$16994$426a34cc@news.free.fr>

Graham Dumpleton a ?crit :
> Bruno Desthuilliers wrote:
> 
>>Michael a ?crit :
>>
>>>Hey everyone,
>>>
>>>Is it possible to automatically insert headers/footers using
>>>mod_python?
>>>I will be not be using PSP's, so I cannot use the PSP/include solution.
>>>Furthermore, the header will be dynamic; it won't be a static HTML
>>>page.
>>>
>>>In short, I've been looking for a page layout facility using
>>>mod_python.
>>>(Similar to the layout capability in Ruby on Rails.)
>>
>>mod_python is mainly a librairy exposing the apache API to Python - not
>>a full-stack db-to-web framework. What you want here is a HTML
>>templating system. There are quite a lot available in Python - look for
>>SimpleTAL, Genshi, Myghty, Jinja, Cheetah, etc...
> 
> 
> Contrary to the above advise, you could actually use mod_python to do
> what you want and you do not need a full stack to do it.

I never said the OP would need a full-stack framework - just that there 
are existing solutions that can solve the problem in a very simple way.


From udodenko at users.sourceforge.net  Mon Dec 11 06:11:19 2006
From: udodenko at users.sourceforge.net (Alex Mizrahi)
Date: Mon, 11 Dec 2006 13:11:19 +0200
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06>
	<1165649882.563957.87770@n67g2000cwd.googlegroups.com>
	<7xk611tpd1.fsf@ruckus.brouhaha.com>
	<1165733461.368441.94940@16g2000cwy.googlegroups.com>
	<7xhcw4gowx.fsf@ruckus.brouhaha.com>
	<457be9a6$0$49209$14726298@news.sunsite.dk>
	<7xejr8hqqs.fsf@ruckus.brouhaha.com>
	<457c42a3$0$49196$14726298@news.sunsite.dk>
	<7xodqbpqun.fsf@ruckus.brouhaha.com>
	<457c92c7$0$49195$14726298@news.sunsite.dk>
	<7x1wn7vx5b.fsf@ruckus.brouhaha.com>
Message-ID: <457d3cdc$0$49205$14726298@news.sunsite.dk>

(message (Hello 'Paul)
(you :wrote  :on '(10 Dec 2006 21:06:56 -0800))
(

 ??>> read the book.

 PR> Which book?

Paul Graham's "On Lisp".

or just refreshing your knowledge about CPS transformaction might be 
sufficient.
i've found very good explanation of CPS transformaction in the book 
"Programming Languages:Application and Interpretation"
Shriram Krishnamurthi
Brown University

it's not Common Lisp but  Scheme though, but it's very interesting since it 
shows how continuations can be used for better web programming.

both books are available online.

 ??>> but once you convert it to CPS, you just operate with closures. stack
 ??>> is just a lexical variables caught into closure. do you know what does
 ??>> CPS mean at all??

 PR> I once understood the basic notion but confess to have never been
 PR> clear on the fine points.  However, I don't see how you can do it with
 PR> CL closures since CL semantics do not guarantee tail recursion
 PR> optimization.  If you code a loop with closures and CPS, you will blow
 PR> the stack.

most CL implementation do tail call optimization, unless you're running 
debug mode -- in that case you'd prefer full stack.
however, it's possible to implement tail call optimizations in non-tail-call 
optimizing language. i think it's called trampolined style.
example can be found in PAIP book: interpreter of Scheme is implemented in 
Common Lisp.
CPS transformation found in ARNESI implements that -- you might notice on 
the macroexpansion i've showed in prev example function drive-cps. it's 
defined following way:

(defun drive-cps (cps-lambda)
  (catch 'done
    (loop for f = cps-lambda then (funcall f))))

additional (lambda () ...) is inserted in the code to delay evaluation. code 
becomes like this:

(drive-cps
  (block1)
  (lambda () (block2))

thus for each CPS tear-point it's able to throw stale stack frames away.
here's an example of CPS-transformed eternal loop

(macroexpand '(with-call/cc (loop for i upfrom 1 do (print i) do (call/cc 
(lambda (cont) cont)))))

(DRIVE-CPS
 (LET ((#:CPS-LET-I-1712 1))
   (DECLARE (TYPE NUMBER #:CPS-LET-I-1712))
   (LABELS ((#:TAGBODY-TAG-NEXT-LOOP-1713 ()
              (PROGN
               (PRINT #:CPS-LET-I-1712)
               (LAMBDA ()
                 (FUNCALL #'TOPLEVEL-K
                          (FUNCALL #'(LAMBDA (CONT) CONT)
                                   (MAKE-CALL/CC-K
                                    (LAMBDA (#:V-1717)
                                      (DECLARE (IGNORE #:V-1717))
                                      (PROGN
                                       (PROGN
                                        (SETQ #:CPS-LET-I-1712
                                                (1+ #:CPS-LET-I-1712)))
                                       (#:TAGBODY-TAG-NEXT-LOOP-1713))))))))))
     (#:TAGBODY-TAG-NEXT-LOOP-1713))))

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 




From toolmaster at 163.com  Mon Dec 25 20:15:02 2006
From: toolmaster at 163.com (WaterWalk)
Date: 25 Dec 2006 17:15:02 -0800
Subject: Why does Python never add itself to the Windows path?
In-Reply-To: <1167009405.771413.122790@i12g2000cwa.googlegroups.com>
References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com>
Message-ID: <1167095702.282730.325610@n51g2000cwc.googlegroups.com>


Ben Sizer wrote:
> I've installed several different versions of Python across several
> different versions of MS Windows, and not a single time was the Python
> directory or the Scripts subdirectory added to the PATH environment
> variable. Every time, I've had to go through and add this by hand, to
> have something resembling a usable Python installation. No such
> problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or
> Kubuntu. So why is the Windows install half-crippled by default? I just
> rediscovered this today when trying to run one of the Turbogears
> scripts, but this has puzzled me for years now.
>

Well, after Python is installed on a Windows platform, files with
extention ".py" or ".pyw" are automatically associated with python or
pythonw. If a python script is double-clicked or input something like
"sth.py" in the "cmd" box, the python interpreter is automatically
called. I don't see any proplem or inconvenience with this.



From dingbat at codesmiths.com  Sat Dec  2 07:50:16 2006
From: dingbat at codesmiths.com (Andy Dingley)
Date: 2 Dec 2006 04:50:16 -0800
Subject: Printing Barcodes from webapp?
In-Reply-To: <1165040626.505772.312350@j72g2000cwa.googlegroups.com>
References: <1165040626.505772.312350@j72g2000cwa.googlegroups.com>
Message-ID: <1165063816.365760.264300@73g2000cwn.googlegroups.com>


Burhan wrote:

>   Is there an easy way to generate barcodes using Python

Easy way for any application or language to generate barcodes is to
install a barcode font on the client machine, then just generate a
suitable text string for it. This is _very_ easy, if you can get the
font deployed.  I usually find myself using Code 39 and printing them
from a HTML document. There are plenty of free code 39 fonts around and
the string mangling to get the barcode structured correctly is just a
trivial prefix / suffix.



From int2k at gmx.net  Sat Dec  9 02:38:02 2006
From: int2k at gmx.net (Wolfram Fenske)
Date: 8 Dec 2006 23:38:02 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <%Qseh.77$495.67@trnddc06>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06>
Message-ID: <1165649882.563957.87770@n67g2000cwd.googlegroups.com>

David Lees  writes:

> JShrager at gmail.com wrote:
>> Okay, since everyone ignored the FAQ, I guess I can too...
>> Mark Tarver wrote:
>>> How do you compare Python to Lisp?  What specific advantages do you
>>> think that one has over the other?
>> (Common) Lisp is the only industrial strength language with both pure
>> compositionality and a real compiler. What Python has is stupid slogans
>> ("It fits your brain." "Only one way to do things.") and an infinite
>> community of flies that, for some inexplicable reason, believe these
>> stupid slogns. These flies are, however, quite useful because they
>> produce infinite numbers of random libraries, some of which end up
>> being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python
>> is rapidly replacing Perl, and Ruby is simultaneously and even more
>> rapidly replacing Python. Each is closer to Lisp than the last; the
>> world is returning to Lisp and is dragging the flies with it.
>> Eventually the flies will descend upon Lisp itself and will bring with
>> them their infinite number of random libraries, and then things will be
>> where they should have been 20 years ago, but got sidetracked by Tcl
>> and other line noise.
>>
>
> Hmmm.  The last time I fooled around with Lisp was 1966 from the Lisp
> 1.5 Manual Published by MIT in cloth.  It was interesting and
> different from the other languages I was using, Algol 60, Basic and
> Macro assembler for the GE-235 and GE-635.  When I read some of the
> over the top type hype by Lisp enthusiasts (like the stuff above) it
> feels like a flash back to the mid 60's.  Personally, I never like
> Lisp syntax; Clearly some people, some fanatic judging by this thread
> :) think easily in prefix.  I am not one of them.

Doesn't matter.  We are Borg.  You will be assimilated.  Resistance is
futile. :-)

But seriously, look at how features from Lisp are constantly finding
their way into mainstream programming languages and have done so for
decades (garbage colection, closures, ...).  Maybe one day prefix
notation and Lisp style macros will also find their way into other
languages and then Lisp will finally take over. :-) And here's another
thing: All the interesting features that haven't originated from Lisp
(e. g. OO from Smalltalk) could in turn easily be implemented in Lisp
with a couple of macros.  I. e. if Common Lisp didn't have CLOS, its
object system, I could write my own as a library and it would be just
as powerful and just as easy to use as the system Common Lisp already
provides.  Stuff like this is impossible in other languages.

To summarize: Lispers are not fanatics.  And if we appear to be then
it is simply because we recognize that Lisp truly is The Chosen
Language. [1]


Footnotes:
[1]  Kidding! :-)  ... or am I?

--
Wolfram Fenske

A: Yes.
>Q: Are you sure?
>>A: Because it reverses the logical flow of conversation.
>>>Q: Why is top posting frowned upon?



From john.thingstad at chello.no  Sat Dec  9 17:23:07 2006
From: john.thingstad at chello.no (John Thingstad)
Date: Sat, 09 Dec 2006 23:23:07 +0100
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
	<1165698244.563344.62270@73g2000cwn.googlegroups.com>
	
	<1165700999.744643.207110@73g2000cwn.googlegroups.com>
Message-ID: 

On Sat, 09 Dec 2006 22:49:59 +0100, mystilleef   
wrote:

>
> Donkeys have wings.
>

? You attitude towards CLOS is obviously insane.

>> In the windows world the best way to access system libraries are
>> via .NET. Thus each language inventing it's own libraries is quickly
>> becoming
>
> You're only proving my point. Why do you think most windows developers
> use .NET?
>

Lisp can also use .NET.  .NET =/= C#

>> Python is fine if you approach programming as Lego, simply gluing  
>> together
>> libraries.
>
> You mean it's fine for what 90% of programmers do?
>

Yes CRUD (Create, Read Update, Delete)..
Sure you can do that in any languge..
Not sure I would call it programming.

>> But if you want to do some serious algorithmic's you may find that it is
>> just to slow.
>
> Slow for users who aren't familiar with Psyco, Pyrex and C extensions,
> sure.
>

Even then..

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


From cychong at gmail.com  Wed Dec 20 21:12:34 2006
From: cychong at gmail.com (cychong)
Date: 20 Dec 2006 18:12:34 -0800
Subject: Support of IPv6 extension headers
In-Reply-To: 
References: <1166627222.868166.123710@a3g2000cwd.googlegroups.com>
	
Message-ID: <1166667154.702931.320270@i12g2000cwa.googlegroups.com>

Thanks for your reply.
BTW, is there any way to send the packet with the IPV6 extension header
w/o using sendmsg?

Chae-yong

Jean-Paul Calderone wrote:
> On 20 Dec 2006 07:07:02 -0800, cychong  wrote:
> >Hi,
> >
> >There is no probleming in programming the basic IPv6 socket program
> >with the python.
> >Then how about the IPv6 extension header? The RFC 2292 and man pages
> >from the unix/linux advise
> >to use the sendmsg to send the packet with the extension header.
> >Does python support the extension header processing?
>
> Python doesn't expose sendmsg.  There are several third-party
> modules which do, though.  Googling for "python sendmsg" turns
> up some useful links.
> 
> Jean-Paul



From michele.simionato at gmail.com  Fri Dec 15 03:41:37 2006
From: michele.simionato at gmail.com (Michele Simionato)
Date: 15 Dec 2006 00:41:37 -0800
Subject: Defining classes
In-Reply-To: 
References: 
	
	
	
Message-ID: <1166169721.911863.4160@80g2000cwy.googlegroups.com>

Steven Bethard wrote:
> How are you doing it currently?  Here's a sort of minimalist option:
>
>      >>> class weeble(object):
>      ...     def __metaclass__(name, bases, bodydict):
>      ...         cls = type(name, bases, bodydict)
>      ...         cls.wumpus = 'brinjal', cls
>      ...         return cls
>      ...
>      >>> weeble.wumpus
>      ('brinjal', )
>
> Of course, it still takes four lines and a metaclass...

Well, 'type' is a metaclass, yes, but not a custom metaclass, so I
would say that you are
using the metaclass hook here, but not a "real" metaclass.  Still
waiting for class decorators ...

      Michele Simionato



From kentilton at gmail.com  Sun Dec 10 11:49:01 2006
From: kentilton at gmail.com (Ken Tilton)
Date: Sun, 10 Dec 2006 11:49:01 -0500
Subject: merits of Lisp vs Python
In-Reply-To: <1165768221.753809.4270@f1g2000cwa.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	
	 <7xac1wr7t9.fsf@ruckus.brouhaha.com>
	
	<1165768221.753809.4270@f1g2000cwa.googlegroups.com>
Message-ID: <1UWeh.482$tv5.282@newsfe11.lga>



philip.armitage at gmail.com wrote:
> On Dec 10, 12:28 am, a... at pythoncraft.com (Aahz) wrote:
> 
> 
>>And that is why I will never write Lisp. I loathe Emacs.
> 
> 
> Me too. So if that's what's stopping you then you might be interested
> to hear that when I moved my free time programming from Python to Lisp
> it took only a weekend to learn enough of the language to code up a
> little Lisp editor. It's funny that I was able to do this given what
> I've now learned from this thread:
> 
> - Lisp is only used for research (but I'm not an academic)
> - Lisp is hard to learn (because of all those parenthesis)
> - There's no practical libraries available (so how did I do it so
> fast?)

Our working hypothesis is "mutant strain". We'll need some DNA.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


From kirk at nospam.jobsluder.net  Sun Dec 10 01:06:41 2006
From: kirk at nospam.jobsluder.net (Kirk Sluder)
Date: Sun, 10 Dec 2006 06:06:41 GMT
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
	<1165698244.563344.62270@73g2000cwn.googlegroups.com>
	
	
	<7xk610a0kl.fsf@ruckus.brouhaha.com>
	
Message-ID: 

In some cases lisp macros are a way of saying tomato to something 
that would be called "tomahto" in python.

One common use of macros is custom iteration constructs. In my 
social network analysis I wanted to do something to each and every 
sender-recipient pair in the header line of "mail" messages in my 
dataset. (And yes, I did have permission to use this data.) Each 
message had one sender, but possibly multiple recipients. Since I 
would be doing multiple forms of analysis, I might as well create 
one iterator to do this.

The DO-MAIL-RELATIONS macro takes the mail message (line), parses 
the sender field and assigns it to (sender), splits the recipient 
field and assigns it to (recip) and then performs the logic in the 
body which often involved looking up values in a database, and 
setting values in a matrix.

(kirk.matrix-process:do-mail-relations (message sender recip)
    ;;about 12 lines of logic snipped
    )

To be pedantic about this call. "KIRK.MATRIX-PROCESS" identifies the 
package/namespace for the macro call. "DO-MAIL-RELATIONS" names the 
macro as part of the DO family of iteration constructs which are 
basic to lisp.

Now that I think about this, in python I'd probably do this using 
object logic that returned the recipient list as an iteratable 
object:

for sender, recipient in message.relationPairs:
   #about 12 lines of logic

Would it have been possible to implement DO-MAIL-RELATIONS as a 
function? Possibly, but I found trying to compact all of that logic 
into a single-use function that could be safely passed to another 
function to be more trouble.

Another common macro use is the "WITH-STREAM" family which opens a 
stream for IO and closes it at the end.  
(with-open-file (file-handle "filename" :direction :output)
   (format file-handle "Hello world.~%")
) 

The pythonic way to do this would be to create a class that 
implements file-like behaviors:

output = fileLike.open()
output.write("Hello world\n")
output.close()

You might want to use a custom "WITH-STREAM" macro or file-like 
object if you need to format, filter, or compress the outgoing 
stream in any way.


From mail at microcorp.co.za  Fri Dec 29 00:17:55 2006
From: mail at microcorp.co.za (Hendrik van Rooyen)
Date: Fri, 29 Dec 2006 07:17:55 +0200
Subject: DOS, UNIX and tabs
References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com><4593185f$1@nntp.zianet.com>
	
	
Message-ID: <006e01c72b08$b3431840$03000080@hendrik>

"Steven D'Aprano"  wrote:

> I've spent a lot of time reading both sides of the tabs versus spaces
> argument, and I haven't found anything yet that explains why tabs are, in
> and of themselves, bad.

+1 for QOTW

Searching for the "badness" of tabs
is like searching for the holy grail.
You are doomed to failure.
You cannot find something 
that does not exist.

: - )

- Hendrik



From bpeng at rice.edu  Thu Dec 21 15:11:58 2006
From: bpeng at rice.edu (Bo Peng)
Date: Thu, 21 Dec 2006 15:11:58 -0500
Subject: How to distribute an additional DLL to site-packages?
Message-ID: 

Dear Python experts,

I am writing a python extension module that needs to link with a 
third-party DLL. How can I copy this DLL to the site-packages directory 
along with my extension modules? It seems that data_files parameter can 
do this, but I do not know how to get the absolute destination 
directory. After all, this directory is configurable.

I guess I need to determine /path/to/site-package for

setup(
     ...
     ext_modules = [...]
     data_files = [ ('/path/to/site-package', ['mydll.dll]) ]
)

using something like distutil.config.get_dest_dir().

Many thanks in advance.
Bo


From pavlovevidence at gmail.com  Fri Dec  8 11:16:33 2006
From: pavlovevidence at gmail.com (Carl Banks)
Date: 8 Dec 2006 08:16:33 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
Message-ID: <1165594593.077086.197050@80g2000cwy.googlegroups.com>

Mark Tarver wrote:
> This confirms my suspicion
> that Lisp is losing out to newbies because of its
> lack of standard support for the things many people want to do.

Whoa there, that's a pretty big logical jump there, don't you think?

Consumer choice can never be boiled down to one thing; there are so
many factors.  No one knows the whole answer.  I certainly don't.  (If
I did, I'd be courteously turning down the Nobel Prize for Economics on
account of being so rich I really didn't need the extra pocket change.)

I have no doubt that what you say is a contributing factor, but if I
had to guess the main reason why Lisp is losing out to newbies, I'd say
it's first impressions.  When newbies see Python they say, "Ok, I can
kind of follow that, it doesn't look too hard to learn."  When they see
Lisp they say, "WTF IS THAT???"

It's kind of sad, in a way, that a superficiality would be so crucial.
(Not that I think outward appearance is all superficial--I think humans
have evolved and/or learned to regard as beautiful that which minimizes
effort--but it's not the whole story and not basis for a whole
judgment.)


Carl Banks



From pillsbury at gmail.com  Tue Dec 12 12:32:18 2006
From: pillsbury at gmail.com (Pillsy)
Date: 12 Dec 2006 09:32:18 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <4u85k4F1731j6U1@mid.individual.net>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	
	
	<4u7g1kF17436jU1@mid.individual.net>
	<7xmz5txs4x.fsf@ruckus.brouhaha.com>
	<4u7jmsF175jh0U1@mid.individual.net> 
	<1165941373.636485.95400@j44g2000cwa.googlegroups.com>
	<4u85k4F1731j6U1@mid.individual.net>
Message-ID: <1165944738.163113.183540@j72g2000cwa.googlegroups.com>


Pascal Costanza wrote:
> Pillsy wrote:
[...]
> > When I first read PCL (which was my introduction to Lisp) I thought
> > LOOP was really neato. Once I actually started using it for things that
> > weren't so simple, I began to really hate it. I think that having a
> > specialized mini-language for iteration is a superb idea, but I don't
> > think LOOP is it.

> > That being said, there's a portable alternatives out there that I like
> > way better, and I still use LOOP for dashing stuff off one-liners at
> > the REPL.

> If you hate LOOP then you don't have to use it.

Indeed, I *don't* use it except for the simplest things.

> There's an important lesson to learn here: Not all language constructs
> are supposed to be loved by everyone. ;)

Especially in Common Lisp, where it's possible to have replacements
that integrate with the rest of the language as seamlessly as the
original feature they're replacing.

I don't love CL because its devoid of features I hate. I love it
because it provides so many great ways of getting around the features I
hate. If it didn't have features I hate, I might actually like it less,
because I wouldn't have anything to bitch about on USENET. :)

Cheers,
Pillsy



From josephoswald at gmail.com  Thu Dec 14 05:26:40 2006
From: josephoswald at gmail.com (josephoswaldgg@hotmail.com)
Date: 14 Dec 2006 02:26:40 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <457fd653$0$4340$426a74cc@news.free.fr>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<1165587080.038533.47910@80g2000cwy.googlegroups.com>
	<45797b9b$0$49206$14726298@news.sunsite.dk>
	<4ttiadF15dam8U1@mid.individual.net>
	<45799bf6$0$49202$14726298@news.sunsite.dk>
	<4ttqsoF15ld61U3@mid.individual.net> 
	<4tvm5mF15g127U1@mid.individual.net>
	
	<4u8hu5F177u11U1@mid.individual.net>
	<1165984694.264366.261250@80g2000cwy.googlegroups.com>
	<457fd653$0$4340$426a74cc@news.free.fr>
Message-ID: <1166092000.715620.50040@f1g2000cwa.googlegroups.com>


Christophe wrote:
> josephoswaldgg at hotmail.com a ?crit :
> > Bjoern Schliessmann wrote:
> >> Robert Uhl wrote:
> >>
> >>> Because it's the language for which indentation is automatically
> >>> determinable.  That is, one can copy/paste a chunk of code, hit a
> >>> key and suddenly everything is nicely indented.
> >> Cool, so in other languages I need to set block marks like () and {}
> >> and also indent the code for readability, and in Python I indent
> >> only. From my POV that's less work.
> >
> > Try reading again. In Lisp, you use () and *your editor* automatically
> > indents according to the universal standard, or you leave it sloppy
> > until other folks reading your code convince you to get a proper
> > programming editor. Indentation does not get out of sync with semantics
> > because the editor virtually never misses parentheses that the Lisp
> > compiler sees. Expressions keep the same meaning even if you have to
> > start breaking them across lines, etc.
> >
> > In Python, you group in your mind, and press indentation keys to make
> > it happen in your editor. The editor cannot help that much, because it
> > cannot read your mind. White space screwups in copy-paste cannot be
> > fixed by the editor automatically, because it cannot read the original
> > programmer's mind, and you have to fix it manually, and risk screwing
> > it up.
>
> Call us when you have an editor that reads your mind and writes the ()
> for you.

This is an irrelevancy. Typos that drop printing characters in either
language will generally cause changes to the semantics. Lisp
programmers, incidentally, will see that their editor indented things
in a funky way and recognize "hey, I dropped a paren somewhere in that
copy-paste." (And, if so, it is usually at the end, and can be
recovered using automatic matching when typing the ')' ). And,
honestly, the punctuation is no harder to type in Lisp than in other
languages, they just occur in different (and more consistent) places.

The point of Python is that changing white-space to
different-white-space changes the semantics. At best an editor can
notice "hey, funky white-space here, please correct" as IDLE did when I
wrote my first Python in a non-Python-aware editor, and somehow had
swapped tabs and spaces; when I moved it to IDLE---the indentation
*looked fine* but was invisibly weird. At worst, an editor can go
"sure, I'll let you change your program."

I'm not saying the worst case is typical. The annoying case is more
likely. I will even admit that white-space significance does not
materially increase errors among experienced Pythonistas. What it isn't
is some kind of miraculous invention that saves programmers from ever
making mistakes that are common in other languages, or that reduces
effort in copy-paste, as Bjoern seemed to be claiming.



From harry.g.george at boeing.com  Tue Dec 19 03:15:04 2006
From: harry.g.george at boeing.com (Harry George)
Date: Tue, 19 Dec 2006 08:15:04 GMT
Subject: on PySol's popularity
References: <857993970612190431m48de4735w24576d96ce54724b@mail.gmail.com>
	
Message-ID: 

Fredrik Lundh  writes:

> Tshepang Lekhonkhobe wrote:
> 
> > On Python docs, on faq/installed.html, it's mentioned that PySol is
> > the most common Python application.
> 
> not really; that page says that installing PySol is a common way to
> get a Python installation installed without noticing, not that PySol
> is in itself the most common Python application.
> 
> and the entire python.org FAQ is horribly outdated.  we're working on
> a replacement, which is currently hosted here:
> 
> http://effbot.org/pyfaq/installed-why-is-python-installed-on-my-machine.htm
> 
> 
> 

A plug for PySol.

My wife is totally non-techno.  She doesn't "get" the notions of
windows, or minimize/maximize, or clicking on the icon down on the
toolbar.  But she does get PySol.  When I recently upgraded, I had to
reinstall Python2.2 in order to use the old PySol binaries (couldn't
get the build-from-source to work).

Linux and Python got a fan due to PySol. It should be considered a
cultural treasure, and if a bit of funding would help keep it rolling
into the future, that might be worthwhile.

-- 
Harry George
PLM Engineering Architecture


From Roberto.Bonvallet at cern.ch  Thu Dec 14 06:50:35 2006
From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet)
Date: Thu, 14 Dec 2006 11:50:35 +0000 (UTC)
Subject: speed of python vs matlab.
References: <1166054840.646029.265880@73g2000cwn.googlegroups.com>
	
	<1166059648.320257.187310@j72g2000cwa.googlegroups.com>
Message-ID: 

Chao wrote:
> My Bad,  the time used by python is 0.46~0.49 sec,
> I tried xrange, but it doesn't make things better.

Actually it does:  it doesn't waste time and space to create a big list.

-- 
Roberto Bonvallet


From kirby.urner at gmail.com  Sun Dec 10 19:03:27 2006
From: kirby.urner at gmail.com (kirby.urner at gmail.com)
Date: 10 Dec 2006 16:03:27 -0800
Subject: Defending Computer Math in USA Public Schools
Message-ID: <1165795407.747909.135290@n67g2000cwd.googlegroups.com>

Cyber-curricula have a leveling aspect, as kids
nearer Katrina's epicenter tune in and bliss out
on 'Warriors of the Net' (why wait for stupid big
dummy textbooks to catch up?). They feel more
empowered by Python and Ubuntu than by any
King's English I'd warrant, given how the latter
has been dumbed down (slowed, degraded) by
unimaginative bankers who can't fathom open
source and its math-teaching significance to
our digitally savvy ethnicities.

       --- Kirby Urner

http://www.cs.haverford.edu/

Any of you stateside tracking our 'Math Wars' know there's
a movement afoot to legislate excellence through politicized
standards bodies, with parents encouraged to push their
"math militancy" into the foreground as a chief concern for
local politicians to grapple with.

I editorialize against this trend at my Oregon Curriculum
Network website, in part because I'm leery of state standards
becoming boring clones of one another, reaching an
apex in some National Standard that's as dangerously
obsolete and unimaginative as most pre-college math
teaching today.

Here's a link to said editorial:
http://www.4dsolutions.net/ocn/editorial.html

I'm especially suspicious of the inertia behind indefinitely
continuing this pre-college focus on climbing Calculus Mountain
(as in getting over it), with little attention given to the regional
and/or ethnic differences that might argue against such
totalitarian uniformity.  Calculus is not the be all end all
mathematical machinery in every walk of life, and I say this
as a former full time high school math teacher who taught
AP Calc proficiently, had many success stories (OK, so
I'm not famous like Jaime Escalante, who cares?
http://www.imdb.com/title/tt0094027/ )

Here in the Silicon Forest, it's the discrete math of computer
science that excites many students, is their ticket to hands-on
access to the defining toyz of our region, i.e. flatscreens,
CPUs, one computer per child, a shared classroom projector,
and with a fat bandwidth pipe to/from the Internet.

Our math students would like the option of specializing in
computer languages and algorithms rather earlier than is
traditional, as a part of that very important self-casting and
self-scripting that goes on in one's formative years.  They've
told me this to my face.  I'm not just making this up.

How are students to realistically decide if a future in computer
science is really for them, if all the schools' resources have
been diverted by narrowing requirements that coercively force
kids *away* from more experimental approaches that might
center around Python, neighboring agiles, as notations of
choice?

Here's what a college level math or philosophy course of the future
might look like, if we don't kowtow to the calculus moguls, other
vote-seeking piggybackers treating the math wars like some
private popularity contest:

def checkbucky(n):
    """
    http://www.rwgrayprojects.com/synergetics/s02/p2000.html
    """
    return 10 * sum([i**2 for i in range(1, n+1)]) + 2*(n) + 1

>>> [checkbucky(i) for i in range(10)]
[1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869]

>>> def checkoeis(n):
     """
     http://www.research.att.com/~njas/sequences/A005902
     """
     return (2*n+1)*(5*n**2+5*n+3)/3

>>> [checkoeis(i) for i in range(10)]
[1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869]

One strategy to combat the dumbing down state standards
movement is to encourage local institutions of higher learning
to reassert their ability to offer guidance.  Follow the example
of MIT and open source more curriculum materials, both as a
recruiting tools and as a models for classroom teachers seeking
ideas for lesson planning.  Faculties should advertise standards
proposals, not leave it to state governments to appropriate
the Ivory Tower's historic prerogatives.

California is a good example of where Oregon might be headed,
if we don't apply the brakes.  Given how upper level math
professors typically leave the lower levels to non-mathematician
education specialists, a few overbearing professor types, flaunting
their credentials, have managed to muscle their way in to the
legislative process, while encouraging their counterparts
across the land to do likewise.  These activist math warriors
like to fly the "anti-fuzzy math" banner as a rallying point,
but offer only "turn back the clock" solutions in case of victory,
all of them bereft of much computer language exposure,
e.g. minus any Python + VPython fractals, or vector arithmetic.

In Portland, defending our freedom to explore alternative, more
futuristic curricula, means focusing on the existing relationships
between Portland's public schools and its Portland State
University.  We also have our Institute for Science, Engineering
and Public Policy (isepp.org), a think tank with a reputation for
keeping our students ahead of the curve.

And last but not least, we have Saturday Academy -
(saturdayacademy.org), an institution created by Silicon Forest
executives in the last generation (23 years ago), and with a
similar mission:  to protect future career opportunities from
encroachment by mediocre and/or simply unsuitable curriculum
imports.  We have a knowledge-based economy to protect.
We can't afford to be "just like everyone else" when it comes
to mathematics and engineering.

Python should already be much stronger in our region, given
its many advantages, especially over calculators.  Computer
science already suffers the disadvantage of being an elective,
with its teachers dispersed to cover music or gym, required math
courses, whenever the school's budget tightens.  Further
straitjacketing the math curriculum to forever lock in some
"one size fits all" formula, will only add to the delay and further
frustrate Python's potential widespread adoption by eager
beaver students.

Kirby Urner
Oregon Curriculum Network
4dsolutions.net/ocn/



From sonibergraj at youjoy.org  Wed Dec  6 22:43:52 2006
From: sonibergraj at youjoy.org (Soni Bergraj)
Date: Thu, 07 Dec 2006 04:43:52 +0100
Subject: Coding standards without control?
In-Reply-To: 
References: <1165321106.614601.95530@79g2000cws.googlegroups.com>	
	
Message-ID: <45778DF8.1090509@youjoy.org>

>> Python makes coding standards obsolete;)
> But Python has the advantage, that your coding standards can concentrate on
> the important things and skip most of the formatting rules, that are often
> part of other languages coding standards.

Better to say, almost obsolete, i guess :D

-- 
Soni Bergraj
http://www.YouJoy.org/


From mail at microcorp.co.za  Tue Dec  5 01:22:09 2006
From: mail at microcorp.co.za (Hendrik van Rooyen)
Date: Tue, 5 Dec 2006 08:22:09 +0200
Subject: Python spam?
References: <02a401c71513$282936a0$03000080@hendrik><457476B7.20508@webcrunchers.com>
	<7.0.1.0.0.20061204210436.04514a98@yahoo.com.ar>
Message-ID: <024501c71838$16e39fc0$03000080@hendrik>

 "Gabriel Genellina"  wrote:

8<--------------------------

So if a friend of yours has played the role of UserA above, that's 
how some spammers got your email address.

+ 1 for euphemism of the month...

- Hendrik



From gagsl-py at yahoo.com.ar  Mon Dec  4 21:04:52 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Mon, 04 Dec 2006 23:04:52 -0300
Subject: Monitoring number of smtp bytes sent through python e-mail socket
In-Reply-To: <4574C8D0.8060603@dodo.com.au>
References: <4574C8D0.8060603@dodo.com.au>
Message-ID: <7.0.1.0.0.20061204225739.047abe18@yahoo.com.ar>

At Monday 4/12/2006 22:18, William Connery wrote:

>I want to give users an indication of the percentage of the e-mail that
>has already been sent so as to avoid frustration when dealing with large
>attachments or a slow smtp server. But the smtplib module doesn't seem
>to provide access to the number of bytes that have already been sent.

You should subclass from smtplib.HTML and override the send() method. 
Internally, it uses socket.sendall; replace it with discrete calls to 
socket.send where you can update the progress.
As send() is used by many commands, you may wish to enable that 
behavior only inside the data() call.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From nmm1 at cus.cam.ac.uk  Sat Dec 16 06:30:37 2006
From: nmm1 at cus.cam.ac.uk (Nick Maclaren)
Date: 16 Dec 2006 11:30:37 GMT
Subject: tuple.index()
References: 
	<1166104987.884566.126710@n67g2000cwd.googlegroups.com>
	
	<1166106278.106832.278240@n67g2000cwd.googlegroups.com>
	
	
	
	
	
	 


In article , Christoph Zwerschke  writes:
|> 
|> I just found that there is indeed some mentioning in the FAQ here:
|> http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types
|> But it is a bit vague, too, and does not mention whether there is any 
|> difference in efficiency which would be interesting to know as well.

It is a trifle bizarre, much like most of the reasons that have been
given in this thread.  I know only some of how Python is implemented,
but have a lot of relevant experience, and here is some commentry on
the FAQ.

The mutability one is the key.  See 1.4.19 for a reason.  In a less
functional language, a tuple would be a value and a list a variable.
You CAN implement dictionaries using mutable objects as keys, but
the result is to add a large amount of inefficiency, complication,
and confusion, for next to no useful function.

The homogeneity argument baffles me.  While it is relevant to some
languages, I know of nothing within either Python's design or its
implementation that makes it relevant to Python.  There may be some
abstruse aspect that I have missed, and I should be very interested
if anyone can explain it.

Both of these are orthogonal to whether tuples should support count
and index methods.  Guido has given a clear answer "We didn't think
it was worth doing."

In terms of efficiency, it is clearly possible to implement tuples
more efficiently, as there is a lot of mechanism that lists need that
they don't.  This accounts for the measurements people have made but,
as Guido says, it is EXTREMELY unlikely that any real application
will notice the difference.  The extra cost is almost entirely in the
setup, as the current implementation of list indexing is near-optimal.

It would also be possible to improve lists to make insertion an
O(log N) operation, not an O(N) one as at present, at the expense of
increasing the cost of indexing.  Not necessarily as much as from the
present O(1) to O(log N), but still significantly.  Python has chosen
not to do that.


Regards,
Nick Maclaren.


From cablepuff at hotmail.com  Fri Dec 15 15:16:35 2006
From: cablepuff at hotmail.com (chun ping wang)
Date: Fri, 15 Dec 2006 12:16:35 -0800
Subject: converting mysql db into sqlite3. 
Message-ID: 

hi, i have a simple problem of opening an existing mysql database with 
sqlite3.

Is it possible? (I have an instinct that it is), however i don';t know the 
most easiest and straight forward approach to do so. Thanks for the help.

_________________________________________________________________
View Athlete?s Collections with Live Search 
http://sportmaps.live.com/index.html?source=hmemailtaglinenov06&FORM=MGAC01



From Holger.Joukl at LBBW.de  Wed Dec 13 04:25:30 2006
From: Holger.Joukl at LBBW.de (Holger Joukl)
Date: Wed, 13 Dec 2006 10:25:30 +0100
Subject: [unicode] inconvenient unicode conversion of non-string arguments
Message-ID: 


Hi there,

I consider the behaviour of unicode() inconvenient wrt to conversion of
non-string
arguments.
While you can do:

>>> unicode(17.3)
u'17.3'

you cannot do:

>>> unicode(17.3, 'ISO-8859-1', 'replace')
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: coercing to Unicode: need string or buffer, float found
>>>

This is somehow annoying when you want to convert a mixed-type argument
list
to unicode strings, e.g. for a logging system (that's where it bit me) and
want to make sure that possible raw string arguments are also converted to
unicode without errors (although by force).
Especially as this is a performance-critical part in my application so I
really
do not like to wrap unicode() into some custom tounicode() function that
handles
such cases by distinction of argument types.

Any reason why unicode() with a non-string argument should not allow the
encoding and errors arguments?
Or some good solution to work around my problem?

(Currently running on python 2.4.3)

Regards,
Holger

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde,
verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht
gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.




From godson.g at gmail.com  Sat Dec 23 02:59:01 2006
From: godson.g at gmail.com (Godson)
Date: Sat, 23 Dec 2006 13:29:01 +0530
Subject: Retrieve Tkinter listbox item by string, not by index
In-Reply-To: <44e1e$458c40af$4275d90a$22798@FUSE.NET>
References: <44e1e$458c40af$4275d90a$22798@FUSE.NET>
Message-ID: 

On 12/23/06, Kevin Walzer  wrote:
>
> I'm trying to set the active item in a Tkinter listbox to my
> application's currently-defined default font.
>
> Here's how I get the fonts loaded into the listbox:
>
>   self.fonts=list(tkFont.families())
>   self.fonts.sort()
>
>    for item in self.fonts:
>              self.fontlist.insert(END, item)   #self.fontlist is the
> ListBox instance
>
>
> So far, so good. But I don't know how to set the active selection in the
> listbox to the default font. All the methods for getting or setting a
> selection in the listbox are based on index, not a string. And using
> standard list search methods like this:
>
>         if "Courier" in self.fontlist:
>              print "list contains", value
>          else:
>              print value, "not found"
>
> returns an error:
>
> TypeError: cannot concatenate 'str' and 'int' objects
>
> So I'm stuck. Can someone point me in the right direction?
> --
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
to me self.fontlist to be a Listbox instance so you cant do a list search on
it, to get current selection from a list box use curselection method Listbox

self.fontlist.curselection()

returns a list of index numbers of  currently selected items in a list box,
following link has more to say on this

http://effbot.org/tkinterbook/listbox.htm

-- 
Godson Gera,
http://godson.auroinfo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From quite at dial.pipex.con  Fri Dec  1 18:26:19 2006
From: quite at dial.pipex.con (Aandi Inston)
Date: Fri, 01 Dec 2006 23:26:19 GMT
Subject: Take the $million challenge: Prove 911 conspriracy theorists are
	wrong
References: <1165000252.255347.178950@73g2000cwn.googlegroups.com>
Message-ID: <4570b9f9.1242604751@read.news.uk.uu.net>

st911 at rock.com wrote:

>I found this nice dialog on the internet:

Doubtless, but why did you choose to share it with a bunch of news
groups which aren't related to the subject?
----------------------------------------
Aandi Inston  quite at dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.



From fredrik at pythonware.com  Wed Dec  6 07:30:21 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Wed, 6 Dec 2006 13:30:21 +0100
Subject: dict.has_key(x) versus 'x in dict'
References: 
Message-ID: 

Paul Melis wrote:

> I've always been using the has_key() method to test if a dictionary
> contains a certain key. Recently I tried the same using 'in', e.g.
>
> d = { ... }
> if k in d:
>    ...
>
> and found that it seems to perform a lot better when lots of key-tests
> are to be performed. I also noticed that has_key() is scheduled to be
> removed from future (C)Python versions.
>
> Does the 'in' way of testing have an optimized implementation compared
> to has_key()?

no, but full method calls are a lot slower than the under-the-hood C-level
call used by the "in" operator.

this is why e.g.

    string[:len(prefix)] == prefix

is often a lot faster than

    string.startswith(prefix)

and why

    if character in string:
        string = string.replace(character, replacement)

is faster than

    string = string.replace(character, replacement)

if the character isn't there most of the time, despite the fact that the "replace"
method doesn't actually do something if the character isn't found.

 





From george.sakkis at gmail.com  Wed Dec  6 23:58:01 2006
From: george.sakkis at gmail.com (George Sakkis)
Date: 6 Dec 2006 20:58:01 -0800
Subject: per instance descriptors
References: <45777908_4@mk-nntp-2.news.uk.tiscali.com>
Message-ID: <1165467481.033283.118340@f1g2000cwa.googlegroups.com>

Simon Bunker wrote:

> Hi I have code similar to this:
>
> class Input(object):
>
>      def __init__(self, val):
>          self.value = val
>
>      def __get__(self, obj, objtype):
>          return self.value
>
>      def __set__(self, obj, val):
>          # do some checking... only accept floats etc
>          self.value = val
>
> class Node(object):
>
> 	a = Input(1)
> 	b = Input(2)
>
> I realise that a and b are now class attributes - however I want to do this:
>
> node1 = Node()
> node2 = Node()
>
> node1.a = 3
> node.b = 4
>
> And have them keep these values per instance. However now node1.a is 4
> when it should be 3.
>
> Basically I want to have the Input class as a gateway that does lots of
> checking when the attibute is assigned or read.
>
> I have had a look at __getattribute__(), but this gets very ugly as I
> have to check if the attribute is an Input class or not.
>
> Also I don't think property() is appropriate is it? All of the
> attributes will essentially be doing the same thing - they should not
> have individual set/get commands.
>
> Is there any way of doing this nicely in Python?

What about __setattr__ ? At least from your example, checking happens
only when you set an attribute. If not, post a more representative
sample of what you're trying to do.

George



From gagsl-py at yahoo.com.ar  Tue Dec 12 23:46:53 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Wed, 13 Dec 2006 01:46:53 -0300
Subject: How to subclass sets.Set() to change intersection()
  behavior?
In-Reply-To: <1165976623.478230.164660@j72g2000cwa.googlegroups.com>
References: <1165976623.478230.164660@j72g2000cwa.googlegroups.com>
Message-ID: <7.0.1.0.0.20061213011516.057efad0@yahoo.com.ar>

At Tuesday 12/12/2006 23:23, mkppk wrote:

>I have kind of strange change I'd like to make to the sets.Set()
>intersection() method..
>
>Normally, intersection would return items in both s1 and s2 like with
>something like this:  s1.intersection(s2)
>
>I want the item matching to be a bit "looser".. that is, items in s2
>that match to just the beginning of items in s1 would be included in
>the result of intersection().
>
>I do not know how intersection() is implemented, so I just kinda
>guessed it might have something to do with how it compares set
>elements, probably using __eq__ or __cmp__. SO, I though if I override
>these methods, maybe magically that would affect the way intersection
>works.. so far, no luck =(

You got it the wrong way... That methods are used to compare two 
sets, not to compare their elements.
You don't have to modify set behavior, instead, you should modify how 
the set elements compare themselves. That is, you should inherit from 
str and implement some "fuzzy comparison" logic.

>- the lists I am working with are small, like 1-10 items each

For such small lists, perhaps the best way is to iterate along both 
lists, like in your example. But replace x.startswith(y) with 
x[:len(y)]==y which is faster. Also, don't you have to test the other 
way too? y.startswith(x)

># this is the list implementation I am trying to avoid because I am
>under the impression using set  would be faster..(??)
># please let me know if I am wrong about that assumption
>
>L1=['macys','installment','oil','beans']
>L2=['macy','oil','inst','coffee']
>
>L3=[]
>for x in L1:
>         for y in L2:
>                 if x.startswith(y):
>                         L3.append(y)
>
># prints ['macy', 'inst', 'oil']
>print L3

You can use the timeit module to measure performance.

Just for fun -because I don't think it would be better for small sets 
as you have- this is an implementation of a "fuzzystring" class which 
only compares its first character.

class fuzzystr(str):

     """A fuzzy string. Only takes its first character into account 
when comparing.
     That is, fuzzystr('abc')==fuzzystr('add')"""

     def __cmp__(self, other):
         if not isinstance(other, basestring): return -1 # always < 
any other thing
         if not self: return len(other) and -1 or 0
         if not other: return 1
         return cmp(self[0], other[0])

     def __eq__(self, other): return self.__cmp__(other)==0
     def __ne__(self, other): return self.__cmp__(other)!=0
     def __lt__(self, other): return self.__cmp__(other)<0
     def __le__(self, other): return self.__cmp__(other)<=0
     def __gt__(self, other): return self.__cmp__(other)>0
     def __ge__(self, other): return self.__cmp__(other)>=0

     def __hash__(self):
         # This must hold for all instances: x==y => hash(x)==hash(y)
         if self: return hash(self[0])
         return hash('')

try: set
except NameError: from sets import Set as set

s1=set(map(fuzzystr,['macys','installment','oil','beans']))
s2=set(map(fuzzystr,['macy','oil','inst','coffee']))
assert s1.intersection(s2) == set(map(fuzzystr,['macy','inst','oil']))


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ?gratis! 
?Abr? tu cuenta ya! - http://correo.yahoo.com.ar


From bj_666 at gmx.net  Wed Dec 13 08:24:26 2006
From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch)
Date: Wed, 13 Dec 2006 14:24:26 +0100
Subject: About alternatives to Matlab
References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com>
	<1163711343.870829.110030@h48g2000cwc.googlegroups.com>
	
	<45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165080056.083648.207580@16g2000cwy.googlegroups.com>
	<45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165161532.686060.78860@73g2000cwn.googlegroups.com>
	<45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165241895.291617.143380@80g2000cwy.googlegroups.com>
	<4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net>
	<1165941521.849053.284110@j72g2000cwa.googlegroups.com>
	<457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net>
Message-ID: 

In <457fc2f5$0$8732$ed2619ec at ptn-nntp-reader02.plus.net>, Jon Harrop
wrote:

>> I don't think you would be much happier to see totally obfuscated golf
>> one-liners.
> 
> That doesn't even make sense. Squeezing code onto one line doesn't
> improve byte count.

So you don't count line endings when counting bytes.  ;-)

Ciao,
	Marc 'BlackJack' Rintsch


From gagsl-py at yahoo.com.ar  Thu Dec 28 03:49:46 2006
From: gagsl-py at yahoo.com.ar (Gabriel Genellina)
Date: Thu, 28 Dec 2006 05:49:46 -0300
Subject: I'm having trouble understanding scope of a variable in a subclass
In-Reply-To: <877iwceis7.fsf@pyenos.pyenos.org>
References: <87bqloej4x.fsf@pyenos.pyenos.org>
	<877iwceis7.fsf@pyenos.pyenos.org>
Message-ID: <7.0.1.0.0.20061228052954.039b73b8@yahoo.com.ar>

At Thursday 28/12/2006 01:39, Pyenos wrote:

>class Class1:
>         class Class2(Class1):
>                 variable="variable"
>                 class Class3(Class2):
>                         print Class1().Class2().variable #problem
>
>Also, why is this wrong?

Again, don't write just "problem"!
What do you want do do? Writing random statements at random order and 
random indentation levels is not the best way to learn Python (nor anything!)

Defining a nested class which itself inherits from its container 
*might* make *some* sense in very specific circunstances, but 
certainly is *not* a recommended newbie practice.
It's like using the accelerator and brake at the same time when 
driving - an experienced driver *might* do that in certain 
circunstances, but if you are learning to drive, you either 
accelerate or either use the brake but NOT both.


-- 
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 



From gnewsg at gmail.com  Wed Dec 13 04:04:40 2006
From: gnewsg at gmail.com (billie)
Date: 13 Dec 2006 01:04:40 -0800
Subject: One module per class, bad idea?
In-Reply-To: <1165951049.090837.145390@73g2000cwn.googlegroups.com>
References: 
	<1165916254.499121.62470@73g2000cwn.googlegroups.com>
	<1165951049.090837.145390@73g2000cwn.googlegroups.com>
Message-ID: <1166000680.632188.142850@f1g2000cwa.googlegroups.com>


Isaac Rodriguez wrote:

> > Yes, it would be a bad idea. =)
>
> Saying it is a bad idea and not explaining why will not help anyone. I
> would like you to elaborate on why it is a bad idea to have one file
> per class.
>
> Thanks,
>
> - Isaac.

Because it's just a useless limitation.
Python lets you the freedom to decide if using one class per file or a
lot of classes per file and this, imho, is a great advantage of Python
other Java.
Personally I like to have the possibility to include multiple classes
in one module if I need them. Obviously I'll hardly mix classes having
different tasks in the same .py file.
If you come from Java feel free to use the Java approach.



From jstroud at mbi.ucla.edu  Thu Dec 21 16:37:37 2006
From: jstroud at mbi.ucla.edu (James Stroud)
Date: Thu, 21 Dec 2006 13:37:37 -0800
Subject: tkFileDialog closes main application
In-Reply-To: 
References: <3qadnUMGb7pa6RTYnZ2dnUVZ_tyinZ2d@comcast.com>
	
Message-ID: 

Eric Brunel wrote:
> BTW, why do you create a sub-class of Frame for your application? Why 
> not  create a sub-class of Tk instead?
> 

The short answer is that inhereting from Frame will allow embedding of 
the application in another application. A Tk() can not be embedded like 
this. Tk is appropriately instantiated if (and only if) __name__ == 
"__main__" here, allowing the App to run as the "main" application here.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/


From gth901c at mail.gatech.edu  Mon Dec  4 12:06:22 2006
From: gth901c at mail.gatech.edu (Lilavivat)
Date: Mon, 4 Dec 2006 12:06:22 -0500
Subject: python Noob - basic setup question / problem
Message-ID: 

Running SUSE 10.1 on an AMD64.  When I try and run a python program I get
the following error:

	/usr/bin/python2: bad interpreter: No such file or directory

	"which python" gives me "/usr/local/bin/python"

	"which python2.4" gives me "/usr/local/bin/python2.4"

	But /usr/bin/python is symlinked to python2.4 "python -> python2.4"

	"which python2" and nothing comes up.

Basically I have no idea what's going on... help please!

Thanks,
SETH


From paul at boddie.org.uk  Fri Dec  8 19:09:07 2006
From: paul at boddie.org.uk (Paul Boddie)
Date: 8 Dec 2006 16:09:07 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
Message-ID: <1165622947.614623.73920@79g2000cws.googlegroups.com>

Mark Tarver wrote:
>
> Thanks;  a quick read of your reference to Norvig's analysis
>
> http://norvig.com/python-lisp.html
>
> seems to show that Python is a cut down (no macros) version of Lisp
> with a worse performance.

I'm quite interested in Lisp, at least from the perspective of seeing
how it supports particular kinds of development activities where you'd
have to "do extra laps" with languages like Python, but while it's
possible to frame lots of languages as being Lisp with something
removed, such observations neglect the origins and objectives of those
languages (and the contributions of a number of other languages).

>  The only substantial advantage I can see is that GUI, and Web libraries are standard.

This is actually something of a running joke in the Python community.
There's one sort of de-facto GUI library which many people swap out for
one of the many other GUI libraries available, many of which are
actually very good and relate to modern, actively and heavily developed
graphical user interface environments. Meanwhile, Web standardisation
in the Python scene needs more attention, although there's so much
activity and so many end-to-end solutions to choose from that Python is
quite a reasonable choice for Web development.

>  This confirms my suspicion that Lisp is losing out to newbies because of its
> lack of standard support for the things many people want to do.

There was a thread on comp.lang.lisp recently [1] where Ian Jackson of
Debian fame attempted to raise awareness of a lack of apparent
community standards for Lisp, amongst other things, at least for those
people developing software for various Free Software platforms. I think
a re-reading of the many and varied responses will give you some ideas
about where the Lisp community stands in that and in other respects.

Paul

[1]
http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/ea994085b54de92d



From hanwen at xs4all.nl  Wed Dec 20 08:03:02 2006
From: hanwen at xs4all.nl (Han-Wen Nienhuys)
Date: Wed, 20 Dec 2006 14:03:02 +0100
Subject: [ANN] PyInstaller 1.3 released
In-Reply-To: 
References: 
Message-ID: <45893486.9070905@xs4all.nl>

Giovanni Bajo escreveu:
> Hello,
> 
> PyInstaller 1.3 is out!
> 
> Grab latest version at:
> http://pyinstaller.python-hosting.com/
> 
> 
> Description
> -----------
> PyInstaller is a program that converts (packages) Python programs into
> stand-alone executables, under Windows, Linux and Irix. Its main
> advantages over similar tools are that PyInstaller works with any
> version of Python since 1.5, it builds smaller executables thanks to
> transparent compression, it is multi-platform (so you can build one-file
> binaries also under Linux), and use the OS support to load the dynamic
> libraries, thus ensuring full compatibility.

that sounds really cool. Is it possible to use this in cross-compiling mode? Ie.
build a standalone .exe for windows on a linux machine?



From address.good.until.2006.dec.22 at justmail.de  Mon Dec 11 08:19:23 2006
From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=)
Date: Mon, 11 Dec 2006 14:19:23 +0100
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
Message-ID: 

Steven D'Aprano schrieb:
> On Sat, 09 Dec 2006 14:57:08 -0500, Bill Atkins wrote:
> 
>> Paul Rubin  writes:
>>
>>> There is just not that much boilerplate in Python code, so there's
>>> not so much need to hide it.
>> Well, of course there is.  There are always going to be patterns in
>> the code you write that could be collapsed.  Language has nothing to
>> do with it; Lisp without macros would still be susceptible to
>> boilerplate.
>>
>> Here's a concrete example:
>>
>>   (let ((control-code (read-next-control-code connection)))
>>     (ecase control-code
>>       (+break+
>>         (kill-connection connection)
>>         (throw :broken-by-client))
>>       (+status+
>>         (send-status-summary connection))
>>       ((+noop+ +keep-alive+))))
>>   ;; +X+ indicates a constant
> 
> Eight lines, excluding the comment, and it doesn't handle the case where
> control-code is not one of +break+, +status+, +noop+ or +keep-alive+,
> although the ecase macro does. And how many lines of code is ecase?
> 
>> All of that
>> boilerplate is handled by the macro.  In Python, I would need to do
>> something like:
>>
>>   control_code = connection.read_next_control_code()
>>   if control_code == +break+:
>>     connection.kill()
>>     throw blah
>>   else if control_code == +status+:
>>     connection.send_status_summary()
>>   else if control_code == +noop+ || control_code == +keep_alive+:
>>   else:
>>     error "CONTROL_CODE fell through conditional cascade; was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+"
> 
> Your Python syntax is rather wonky, but that's incidental.
> 
> Nine lines, including handling the case where control_code is none of the
> four constants. Ten if you add the "pass" statement that it actually
> needs. And it is completely self-contained, with no external functions or
> macros to understand.

Counting source lines is not the important thing. Look at the complexity
and the number of tokens.
The Lisp code is easier, because it is more abstract. You are closer in
saying what you want.

Counting tokens:
(let ((control-code (read-next-control-code connection)))   4
   (ecase control-code                                       2
     (+break+                                                1
       (kill-connection connection)                          2
       (throw :broken-by-client))                            2
     (+status+                                               1
       (send-status-summary connection))                     2
     ((+noop+ +keep-alive+))))                               2
                                                          ======
                                                            16


control_code = connection.read_next_control_code()              4
if control_code == +break+:                                     4
   connection.kill()                                             2
   throw blah                                                    2
else if control_code == +status+:                               4
   connection.send_status_summary()                              2
else if control_code == +noop+ || control_code == +keep_alive+: 8
else:                                                           1
   error "CONTROL_CODE fell through conditional cascade;         2
       was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+"
                                                              ======
                                                                29
plus a "pass", would make 30 vs 16  "Brain-units".


Andr?
-- 


From lobais at gmail.com  Fri Dec 15 16:04:36 2006
From: lobais at gmail.com (lobais at gmail.com)
Date: 15 Dec 2006 13:04:36 -0800
Subject: distutils - rpm
Message-ID: <1166216676.400073.4360@73g2000cwn.googlegroups.com>

When I try to create an rpm using distutils, I get an error like this:
error: Installed (but unpackaged) file(s) found:
   /usr/share/games/pychess/sidepanel/bookPanel.pyc
   /usr/share/games/pychess/sidepanel/bookPanel.pyo
   ...

I found this solution
http://www.mail-archive.com/distutils-sig at python.org/msg02655.html
which removed most of the lines, but besides my modules, I do also have
some .py files in a more plug-in like way, which are not stored in
modules. For these files the error still appears.

I was wondering if there was a way to not have the files created, but
simply not have them checked? I don't understand why it does that.



From dingbat at codesmiths.com  Wed Dec  6 11:45:59 2006
From: dingbat at codesmiths.com (Andy Dingley)
Date: 6 Dec 2006 08:45:59 -0800
Subject: dict.has_key(x) versus 'x in dict'
In-Reply-To: 
References: 
	<1165418932.582377.312200@79g2000cws.googlegroups.com>
	
Message-ID: <1165423559.858684.227930@16g2000cwy.googlegroups.com>


Roberto Bonvallet wrote:

> >        lstBugsChanged = [ bugId for bugId in setBugsChanged ]

> In Python > 2.4:

Hmmm. Thanks. Another reason to twist the admin's arm and get them to
upgrade the last 2.3.4 boxen


>     sorted(setBugsChanged)

Out of interest, whats the Pythonic way to simply cast (sic) the set to
a list, assuming I don't need it sorted?  The list comprehension?



From tomas at fancy.org  Sat Dec 23 14:10:33 2006
From: tomas at fancy.org (Tom Plunket)
Date: Sat, 23 Dec 2006 11:10:33 -0800
Subject: textwrap.dedent replaces tabs?
References: 	<1166310662.825674.128700@l12g2000cwl.googlegroups.com>		
	<232fo2psfdue95hrcfmigdu7m2l857097r@4ax.com>
	
Message-ID: 

Frederic Rentsch wrote:

> Following a call to dedent () it shouldn't be hard to translate leading 
> groups of so many spaces back to tabs.

Sure, but the point is more that I don't think it's valid to change to
tabs in the first place.

E.g.:

 input = ' ' + '\t' + 'hello\n' +
         '\t' + 'world'

 output = textwrap.dedent(input)

will yield all of the leading whitespace stripped, which IMHO is a
violation of its stated function.  In this case, nothing should be
stripped, because the leading whitespace in these two lines does not
/actually/ match.  Sure, it visually matches, but that's not the point
(although I can understand that that's a point of contention in the
interpreter anyway, I would have no problem with it not accepting "1 tab
= 8 spaces" for indentation...  But that's another holy war.

> If I understand your problem, you want to restore the dedented line to 
> its original composition if spaces and tabs are mixed and this doesn't 
> work because the information doesn't survive dedent ().

Sure, although would there be a case to be made to simply not strip the
tabs in the first place?

Like this, keeping current functionality and everything...  (although I
would think if someone wanted tabs expanded, they'd call expandtabs on
the input before calling the function!):

def dedent(text, expand_tabs=True):
    """dedent(text : string, expand_tabs : bool) -> string

    Remove any whitespace than can be uniformly removed from the left
    of every line in `text`, optionally expanding tabs before altering
    the text.

    This can be used e.g. to make triple-quoted strings line up with
    the left edge of screen/whatever, while still presenting it in the
    source code in indented form.

    For example:

        def test():
            # end first line with \ to avoid the empty line!
            s = '''\
             hello
            \t  world
            '''
            print repr(s)     # prints '     hello\n    \t  world\n    '
            print repr(dedent(s))  # prints ' hello\n\t  world\n'
    """
    if expand_tabs:
        text = text.expandtabs()
    lines = text.split('\n')
    
    margin = None
    for line in lines:
        if margin is None:
            content = line.lstrip()
            if not content:
                continue
            indent = len(line) - len(content)
            margin = line[:indent]
        elif not line.startswith(margin):
            if len(line) < len(margin):
                content = line.lstrip()
                if not content:
                    continue
            while not line.startswith(margin):
                margin = margin[:-1]

    if margin is not None and len(margin) > 0:
        margin = len(margin)
        for i in range(len(lines)):
            lines[i] = lines[i][margin:]

    return '\n'.join(lines)

import unittest

class DedentTest(unittest.TestCase):
    def testBasicWithSpaces(self):
        input = "\n   Hello\n      World"
        expected = "\nHello\n   World"
        self.failUnlessEqual(expected, dedent(input))

    def testBasicWithTabLeadersSpacesInside(self):
        input = "\n\tHello\n\t   World"
        expected = "\nHello\n   World"
        self.failUnlessEqual(expected, dedent(input, False))
        
    def testAllTabs(self):
        input = "\t\tHello\n\tWorld"
        expected = "\tHello\nWorld"
        self.failUnlessEqual(expected, dedent(input, False))
        
    def testFirstLineNotIndented(self):
        input = "Hello\n\tWorld"
        expected = input
        self.failUnlessEqual(expected, dedent(input, False))
        
    def testMixedTabsAndSpaces(self):
        input = "  \t Hello\n   \tWorld"
        expected = "\t Hello\n \tWorld"
        self.failUnlessEqual(expected, dedent(input, False))
        
if __name__ == '__main__':
    unittest.main()
-tom!

-- 


From rampeters at gmail.com  Sat Dec  9 22:19:47 2006
From: rampeters at gmail.com (johnny)
Date: 9 Dec 2006 19:19:47 -0800
Subject: ATTRIBUTE ERROR: 'module' object has no attribute 'ssl'
Message-ID: <1165720787.910338.118940@j44g2000cwa.googlegroups.com>

I am getting the following errors:

  File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in
_send_output
    self.send(msg)
  File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send
    self.connect()
  File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in
connect
    ssl = socket.ssl(sock, self.key_file, self.cert_file)
AttributeError: 'module' object has no attribute 'ssl'

Thank You in Advance



From josephoswald at gmail.com  Thu Dec 14 05:05:08 2006
From: josephoswald at gmail.com (josephoswaldgg@hotmail.com)
Date: 14 Dec 2006 02:05:08 -0800
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<1165587080.038533.47910@80g2000cwy.googlegroups.com>
	<45797b9b$0$49206$14726298@news.sunsite.dk>
	<4ttiadF15dam8U1@mid.individual.net>
	<45799bf6$0$49202$14726298@news.sunsite.dk>
	<4ttqsoF15ld61U3@mid.individual.net> 
	<4tvm5mF15g127U1@mid.individual.net>
	
	<4u8hu5F177u11U1@mid.individual.net>
	<1165984694.264366.261250@80g2000cwy.googlegroups.com>
	
Message-ID: <1166090708.361757.197170@l12g2000cwl.googlegroups.com>


Neil Cerutti wrote:
> On 2006-12-13, josephoswaldgg at hotmail.com
>  wrote:
> > Try reading again. In Lisp, you use () and *your editor*
> > automatically indents according to the universal standard, or
> > you leave it sloppy until other folks reading your code
> > convince you to get a proper programming editor. Indentation
> > does not get out of sync with semantics because the editor
> > virtually never misses parentheses that the Lisp compiler sees.
> > Expressions keep the same meaning even if you have to start
> > breaking them across lines, etc.
>
> Yes, it's the same way in Python. Of course, not everything is an
> expression in Python, so it's not saying quite as much.

I fail to see how it is the same in Python. I go into a Lisp buffer
white-space area, and press  and absolutely nothing changes about
my program. There are two reasons for this: I am using a dumb editor
that puts a Tab in that my compiler doesn't care about, or I am using
the moral equivalent of Emacs, which reads  as "put this line on
the standard Lisp indentation level, as determined by the
non-whitespace characters in the area."

In Python, I hit that  and the smartest editor in the world would
have to say "Oh, you want to put this line on a different indentation
level, possibly including this line as part of the if: consequences
block above. Hope that helps!"

> > In Python, you group in your mind, and press indentation keys
> > to make it happen in your editor. The editor cannot help that
> > much, because it cannot read your mind. White space screwups in
> > copy-paste cannot be fixed by the editor automatically, because
> > it cannot read the original programmer's mind, and you have to
> > fix it manually, and risk screwing it up.
>
> It is very easy a manual process, possibly as simple as selecting
> the correct s-expr and pasting it into the right place in your
> code.

How does a manual correction process come out as simple as "don't
bother fixing the indentation if you don't care."?

This is exactly the questionable math that I was questioning in the
original post.



From robin at alldunn.com  Tue Dec 12 14:14:57 2006
From: robin at alldunn.com (Robin Dunn)
Date: Tue, 12 Dec 2006 11:14:57 -0800
Subject: ANN: wxPython 2.8.0.1
Message-ID: <457EFFB1.2040907@alldunn.com>


Announcing
----------

The 2.8.0.1 release of wxPython is now available for download at
http://wxpython.org/download.php.  This is the first of the new stable
2.8.x release series and is the culmination of the massive enhancement
and stabalization effort done in the 2.7.x series.  Source code is
available, as well as binaries for both Python 2.4 and 2.5, for
Windows and Mac, as well some pacakges for various Linux distributions.
A summary of changes is listed below and also at
http://wxpython.org/recentchanges.php.


What is wxPython?
-----------------

wxPython is a GUI toolkit for the Python programming language. It
allows Python programmers to create programs with a robust, highly
functional graphical user interface, simply and easily. It is
implemented as a Python extension module that wraps the GUI components
of the popular wxWidgets cross platform library, which is written in
C++.

wxPython is a cross-platform toolkit. This means that the same program
will usually run on multiple platforms without modifications.
Currently supported platforms are 32-bit Microsoft Windows, most Linux
or other Unix-like systems using GTK2, and Mac OS X 10.3+, in most
cases the native widgets are used on each platform to provide a 100%
native look and feel for the application.


Changes in 2.8.0.1
------------------

Lots of fixes and updates to the AUI classes.

Added wx.CollapsiblePane.  On wxGTK it uses a native expander widget,
on the other platforms a regular button is used to control the
collapsed/expanded state.

Added the wx.combo module, which contains the ComboCtrl and ComboPopup
classes.  These classes allow you to implement a wx.ComboBox-like
widget where the popup can be nearly any kind of widget, and where you
have a lot of control over other aspects of the combo widget as well.
It works very well on GTK and MSW, using native renderers for drawing
the combo button, but is unfortunatly still a bit klunky on OSX...

Use system default paper size for printing instead of A4 by default.

Added wx.combo.OwnerDrawnComboBox, which is a ComboCtrl that delegates
the drawing of the items in the popup and in the control itself to
overridden methods of a derived class, similarly to how wx.VListBox
works.

Added wx.combo.BitmapComboBox which is a combobox that displays a
bitmap in front of the list items.

Added the wx.lib.mixins.inspect module.  It contains the InspectMixin
class which can be mixed with a wx.App class and provides a PyCrust
window that can be activated with a Ctrl-Alt-I keystroke (or Cmd-Alt-I
on the Mac.)

Added some modules from Riaan Booysen:

     * wx.lib.flagart:  contains icons of the flags of many countries.

     * wx.lib.art.img2pyartprov: makes images embedded in a python file
       with img2py available via the wx.ArtProvider.

     * wx.lib.langlistctrl: A wx.ListCtrl for selecting a language,
       which uses the country flag icons.

     * An I18N sample for the demo.

wx.lib.masked: Patch from Will Sadkin.  Includes Unicode fixes, plus
more helpful exceptions and ability to designate fields in mask
without intervening fixed characters.

Added wx.SearchCtrl, which is a composite of a wx.TextCtrl with optional
bitmap buttons and a drop-down menu.  Controls like this can typically
be found on a toolbar of applications that support some form of search
functionality.  On the Mac this control is implemented using the
native HISearchField control, on the other platforms a generic control
is used, although that may change in the future as more platforms
introduce native search widgets.

Added a set of button classes to wx.lib.buttons from David Hughes that
uses the native renderer to draw the button.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!



From aisaac at american.edu  Tue Dec 19 17:25:27 2006
From: aisaac at american.edu (Alan Isaac)
Date: Tue, 19 Dec 2006 22:25:27 GMT
Subject: permutations - fast & with low memory consumption?
References: 
Message-ID: 

>From pytrix:
http://www.american.edu/econ/pytrix/pytrix.py

def permutationsg(lst):
    '''Return generator of all permutations of a list.
    '''
    if len(lst)>1:
        for i in range(len(lst)):
            for x in permutationsg(lst[:i]+lst[i+1:]):
                yield [lst[i]]+x
    else:
        yield lst

hth,
Alan Isaac




From rald86 at yahoo.fr  Sun Dec  3 11:38:02 2006
From: rald86 at yahoo.fr (Robert R.)
Date: 3 Dec 2006 08:38:02 -0800
Subject: best way to align words?
In-Reply-To: <1165064935.816780.291770@j44g2000cwa.googlegroups.com>
References: <1164925391.696612.64860@80g2000cwy.googlegroups.com>
	
	
	<1165050975.684944.232250@j44g2000cwa.googlegroups.com>
	<1165064935.816780.291770@j44g2000cwa.googlegroups.com>
Message-ID: <1165163882.105329.222730@73g2000cwn.googlegroups.com>


Oleg Batrashev a ?crit :

> This means that if you have 10 sentences with 5 words in each there is
> 5^10 space and time complexity. Definitelly, there are better
> algorithms from dynamic programming, but you should review your needs:
> how many sentences, words you have.

it can be few to many, actually it depends of the words i'm looking for.



From brian at brianshirk.com  Wed Dec 20 00:36:01 2006
From: brian at brianshirk.com (brian at brianshirk.com)
Date: Tue, 19 Dec 2006 21:36:01 -0800
Subject: Working with unsigned/signed types
Message-ID: <20061220054657.7CEEA1E4006@bag.python.org>

Hi everyone-

I've been away from coding for a while (I turned into a professional

photographer)...  

So now I've taken up a project involving working with EXIF and XMP metadata in

image files (mainly JPEG and TIFF), and am having some trouble figuring out how

to handle some of the data...



Here's what I'm having to do:

Inside the files, there are various types of data which can be split apart and

organized fairly easily, given you have unsigned and signed types...  Which is

where I'm running into problems remembering how everything works.



The first part of the question is fairly basic - in C, working with signed

integers, the MSB (is that still the right term?) is used to denote positive and

negative, and the following bits increase towards positive infinity, correct? 

Such that in C, adding one to 0x7fffffff would cause the number to go around to

-0x7fffffff (or whatever that is), giving -1 for 0xffffffff?



Secondly, (and this is my weak point as a programmer) to re-insert the data

after, what would be the most efficient way to pull everything back apart into

individual characters for putting it all back into the files?  I could probably

figure out something that would work, but I wouldn't be so sure as to its

reliability.



Third, being a photographer now rather than a coder, I'd like to give back the

modules I'm writing to the community (it looks like very little of the sort

exists), but would rather not worry about them in the future...  Is there a good

way to go about this?



Thanks!

-Brian Shirk



Avalanche Photography LLC

www.AvalanchePhoto.com

McCall, Idaho



From george.sakkis at gmail.com  Sun Dec 10 01:27:52 2006
From: george.sakkis at gmail.com (George Sakkis)
Date: 9 Dec 2006 22:27:52 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<1165627684.709241.86340@16g2000cwy.googlegroups.com>
	<1165685950.758858.18960@n67g2000cwd.googlegroups.com>
Message-ID: <1165732072.056289.274460@79g2000cws.googlegroups.com>

JShrager at gmail.com wrote:

> 1. Lisp is the only industrial strength language
                      ^^^^^^^^^^^^^^^^^^^
You keep using that phrase. I don't think it means what you think it
means.

> with pure compositionality, and that this makes it suprior to Python.

Perhaps it does in some programming language theory research groups. In
the real world, superiority has to do with far more than technical
merits alone, let alone obscure metaprogramming features which are
irrelevant to the vast majority of programmers.

> 2. Ruby, which is closer to Lisp than Python, is beginning to eat
> Python's lunch. We don't have to debate this either because George has
> kindly gave support to it through posting a survey that made this point
> quite nicely; Thanks, George! :-)

AKA "if you can't beat them, join them". I don't know if other lispers
would join you in your feeble attempt to steal a bite from Ruby's
current glory (mostly thanks to the admirable marketing around the
overhyped Rails framework), but Ruby is much closer to Python than
either of them is to lisp. In fact, if Python suddenly disappeared,
Ruby would probably be my next stop. Both Ruby and Python are high
level dynamic languages with an emphasis on pragmatic needs, not being
the language of the God(s) (see, I can bring up stupid slogans of
languages too). The similarities between Python and Ruby outweigh their
differences, resulting in very few defections from one to the other, so
nobody's eating the other's lunch. They are both appealing alternatives
to different (overlapping) subsets of the Java/C++/Perl/PHP crowd, and
the choice between the two usually comes down to a subjective
preference about the syntax, the availability of libraries or other
non-technical reasons.

> BTW, for the record, I don't have anything particularly against Python
> aside from its stupid marketing hype and a bit of jealousy over those

Talk about a well-founded reason to diss a language.

George



From g.franzkowiak at onlinehome.de  Sat Dec 16 11:46:36 2006
From: g.franzkowiak at onlinehome.de (g.franzkowiak)
Date: Sat, 16 Dec 2006 17:46:36 +0100
Subject: win32 service
In-Reply-To: 
References: 
	
Message-ID: 

Tim Williams schrieb:
> On 16/12/06, g.franzkowiak  wrote:
>> Hi everybody,
>>
>> have a little problem with a service on Win32.
>>
>> I use a TCP server as service, but can't access from an other machine.
>> Only local access is possible.
>>
>> The service starts like this:
>>
>> -> myService.py --username user --password password install <-
>>
>> followed by start
>>
>> The user is member in "Log on as service", but... only local access :-(
>>
>> What is wrong or what can I do ?
>>
> 
> Have you checked that your firewall isn't causing the problem,  and
> that the servers IP address is accessible from other machines to start
> with ?

OK, now I'm connected. My adjustments in "Log on as service" were wrong.
gerd


From pyenos at pyenos.org  Wed Dec 27 18:07:45 2006
From: pyenos at pyenos.org (Pyenos)
Date: 28 Dec 2006 10:07:45 +1100
Subject: failing to instantiate an inner class because of order of inner
	classes
Message-ID: <87wt4dos3i.fsf@pyenos.pyenos.org>

class model:pass
class view:
        model()
class controller:
        model()

I can instantiate clsss model from inside class view but I can't
instantiate class model from inside controller, due to the nature of
python interpreter.

I wish to circumvent this restriction by:

class model:pass
class view:
        parent_class.model()
class controller:
        parent_class.model()

but, I don't know the built-in variable that points to the parent
class. Could someone tell me how can I instantiate class model from
inside controller AND instantiate class model from inside view?


From kevin.bell at slcgov.com  Tue Dec 12 10:20:33 2006
From: kevin.bell at slcgov.com (Bell, Kevin)
Date: Tue, 12 Dec 2006 08:20:33 -0700
Subject: wxPython, dynamically modify window
In-Reply-To: 
Message-ID: <2387F0EED10A4545A840B231BBAAC722F1170A@slcimail1.slcgov.com>

I think that you'll just need to change the frame size property when you
hit your checkbox...



-----Original Message-----
From: python-list-bounces+kevin.bell=slcgov.com at python.org
[mailto:python-list-bounces+kevin.bell=slcgov.com at python.org] On Behalf
Of Grant
Sent: Tuesday, December 12, 2006 12:02 AM
To: python-list at python.org
Subject: wxPython, dynamically modify window

Hi, I am looking for a tip.  I have a panel and a checkbox.  When I 
check the checkbox, I would like to add buttons to the panel 
(dynamically).  When the checkbox is unchecked, the buttons should not 
appear (be deleted)---all the while, the window should resize if
necessary.

If you have a simpler example, that is fine.  I just need a hint as to 
how you dynamically change the widgets and their layouts.

Looking at the wx demos, there is something close wx.lib.expando, but 
this is just modifying a particular widget.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


From __peter__ at web.de  Mon Dec 18 08:14:05 2006
From: __peter__ at web.de (Peter Otten)
Date: Mon, 18 Dec 2006 14:14:05 +0100
Subject: How to replace a comma
References: <1166446034.406136.225770@80g2000cwy.googlegroups.com>
Message-ID: 

Lad wrote:

> In a text I need to
> add a blank(space) after a comma but only if there was no blank(space)
> after the comman
> If there was a blank(space), no change is made.

>>> s = "alpha, beta,gamma,  delta"
>>> ", ".join(t.replace(",", ", ") for t in s.split(", "))
'alpha, beta, gamma,  delta'

Peter


From http  Thu Dec 14 02:26:44 2006
From: http (Paul Rubin)
Date: 13 Dec 2006 23:26:44 -0800
Subject: Conditional iteration
References: <4580149c$0$321$e4fe514c@news.xs4all.nl>
	<7xwt4vn6gk.fsf@ruckus.brouhaha.com>
	<45804584$0$334$e4fe514c@news.xs4all.nl>
	<7x64cf6wtv.fsf@ruckus.brouhaha.com>
	<4580f839$0$331$e4fe514c@news.xs4all.nl>
Message-ID: <7xlklbgcp7.fsf@ruckus.brouhaha.com>

at  writes:
> >   for x in (x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0):
> >        ... more code ...

> Do you know if this generates a new list internally (memory consumption?)

It does not.  That parenthesized expression is a called generator
expression.  It compiles to a small subroutine, more or less, that
gets invoked repeatedly as you iterate through it.

A similar expression with square brackets is called a list
comprehension and does generate a new list.


From google at mrabarnett.plus.com  Wed Dec 27 15:26:19 2006
From: google at mrabarnett.plus.com (MRAB)
Date: 27 Dec 2006 12:26:19 -0800
Subject: How to suppress the output of an external module ?
In-Reply-To: <4591b56a$1@nntp0.pdx.net>
References: 
	<4591b56a$1@nntp0.pdx.net>
Message-ID: <1167251179.543231.157740@79g2000cws.googlegroups.com>


Scott David Daniels wrote:
> fdu.xiaojf at gmail.com wrote:
> > Hi,
> >
> > I'm writing a program which uses an external module written in C
> > and calls a function provided by the module to do my job.  The
>  > function produces a lot of output to the stdout.
> >
> > Is there a way to suppress the output produced by the function and
>  > hence make my program run faster?
>
>  > It's too complicated for me to modify the source code and recompile
>  > the external module.
> This would be the best method, you could define printf and fprintf
> macros that would eliminate the output code altogether.
>
> > Any hints will be greatly appreciated.
> Well, it will depend on your OS, but the trick is to essentially
> replace the C stdout channel with a file which has been opened to
> write to "/dev/null" or "NUL.txt" (unix and Windows respectively).
> You'll need to first copy the channel to another so you can use
> it again after the function is done (a system call). Next do the
> raw open (which should get the available channel), and the C stdout
> stuff is successfully redirected.  Once done w/ your function,
> close your new stdout and copy the channel back.
>
In Windows the null device is, strictly speaking, "nul" or "nul:", not
"nul.txt", but the latter appears to work too.



From address.good.until.2006.dec.22 at justmail.de  Sat Dec  9 18:06:24 2006
From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-15?Q?Andr=E9_Thieme?=)
Date: Sun, 10 Dec 2006 00:06:24 +0100
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	
	<1165598576.650860.126740@16g2000cwy.googlegroups.com>
	
Message-ID: 

Aahz schrieb:
> In article <1165598576.650860.126740 at 16g2000cwy.googlegroups.com>,
> Mark Tarver  wrote:
>> I'm looking at Python and I see that the syntax would appeal to a
>> newbie.  Its clearer than ML which is a mess syntactically.  But I
>> don't see where the action is in Python.   Not yet anyway.  Lisp syntax
>> is easy to learn.  And giving up an order of magnitude is a high price
>> to pay for using it over Lisp.
> 
> Speaking as someone who had been programming for more than twenty years
> before learning Python (including a brief gander at Lisp), and also
> referring to many years of observations of newcomers to Python: Python's
> syntax also appeals to experienced programmers.
> 
> I would say that your statement about Lisp syntax is wrong.  Not that it
> is technically inaccurate, but that it completely misses the point, so
> much so that it is wrong to say it.  One of the key goals of Python is
> readability, and while it is indeed easy to learn the rules for Lisp
> syntax, observational experience indicates that many people (perhaps even
> the vast majority of people) find it difficult to learn to read Lisp
> programs.

If you ask a non-programmer to read programs he/she will have difficulties.
But I guess this person would not have more problems learning than any
other programming language. They are not biased because they don't know
how programs look like. If you show Lisp code to people who know C or
Java, Python or PHP they will not find as easily the structure.
They are already used to something, and we all are creatures of habit.



> As for your claims about speed, they are also nonsense; I doubt one
> would find an order of magnitude increase of speed for production
> programs created by a competent Lisp programmer compared to programs
> created by a competent Python programmer.

The Python language interpreter itself is programmed in C (biggest parts).
Lisp compilers are programmed in Lisp.
Both are mature production programs. Why do you think isn't the Python
interpreter programmed in pure Python?



> Consider this: Lisp has had years of development, it has had millions of
> dollars thrown at it by VC firms -- and yet Python is winning over Lisp
> programmers.  Think about it.

When Lisp got so many millions it was not known how to create very good
compilers. Mankind had to learn it, so these investments were needed.
Today there are open source Lisps. And while they don't get millions
of Dollars for development they can produce mature production code.


Andr?
-- 


From will at willNOmcguganSPAM.com  Mon Dec  4 12:32:26 2006
From: will at willNOmcguganSPAM.com (Will McGugan)
Date: Mon, 04 Dec 2006 17:32:26 +0000
Subject: Ensure a variable is divisible by 4
In-Reply-To: <1165252238.866708.293510@j72g2000cwa.googlegroups.com>
References: <1165252238.866708.293510@j72g2000cwa.googlegroups.com>
Message-ID: <45745bae$0$1503$db0fefd9@news.zen.co.uk>

geskerrett at hotmail.com wrote:
> I am sure this is a basic math issue, but is there a better way to
> ensure an int variable is divisible by 4 than by doing the following;
> 
> x = 111
> x = (x /4) * 4
> 
> Just seems a bit clunky to me.
> 

Depends what you mean by 'make it divisable'. Do you want to check it is 
divisible or do you want to make it divisible? And if you want to make 
it divisible do you want to go to the next multiple of 4, or the previous?


Will McGugan
--
http://www.willmcgugan.com


From XX.XmcX at XX.XmclaveauX.com  Mon Dec 25 01:18:16 2006
From: XX.XmcX at XX.XmclaveauX.com (MC)
Date: Mon, 25 Dec 2006 07:18:16 +0100
Subject: Why does Python never add itself to the Windows path?
References: <1167009405.771413.122790@i12g2000cwa.googlegroups.com>
	<1167018067.659291.276020@79g2000cws.googlegroups.com>
	<1167019940.036406.23980@79g2000cws.googlegroups.com>
Message-ID: 

Hi!

+1

-- 
@-salutations

Michel Claveau




From eadmund42 at NOSPAMgmail.com  Tue Dec 12 11:29:31 2006
From: eadmund42 at NOSPAMgmail.com (Robert Uhl)
Date: Tue, 12 Dec 2006 09:29:31 -0700
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<1165587080.038533.47910@80g2000cwy.googlegroups.com>
	<45797b9b$0$49206$14726298@news.sunsite.dk>
	<4ttiadF15dam8U1@mid.individual.net>
	<45799bf6$0$49202$14726298@news.sunsite.dk>
	<4ttqsoF15ld61U3@mid.individual.net> 
	<4tvm5mF15g127U1@mid.individual.net>
Message-ID: 

Bjoern Schliessmann  writes:
>
>> Note also that after any amount of dicing I simply hit a magic key
>> combo and the editor reindents everything. In a sense, Lisp is the
>> language that handles indentation best.
>
> Erm ... because there's an editor for it that indents automatically?

Because it's the language for which indentation is automatically
determinable.  That is, one can copy/paste a chunk of code, hit a key
and suddenly everything is nicely indented.

-- 
Robert Uhl 
Flagrant system error!  The system is down.  I dunno what you did, 
moron, but you sure screwed everything up             --Strongbad


From __peter__ at web.de  Sun Dec 17 02:53:30 2006
From: __peter__ at web.de (Peter Otten)
Date: Sun, 17 Dec 2006 08:53:30 +0100
Subject: module wide metaclass for new style classes
References: 
Message-ID: 

Daniel Nogradi wrote:

> I used to have the following code to collect all (old style) class
> names defined in the current module to a list called reg:
> 
> 
> def meta( reg ):
>     def _meta( name, bases, dictionary ):
>         reg.append( name )
>     return _meta
> 
> reg = [ ]
> __metaclass__ = meta( reg )
> 
> class c1:
>     pass
> 
> class c2:
>     pass
> 
> print reg

That code does not create classes. Here's a slightly simplified version:

>> reg = []
>>> def __metaclass__(name, bases, dict):
...     reg.append(name)
...
>>> class A: pass
...
>>> reg
['A']
>>> A is None 
True # oops!

> This would correctly print [ 'c1', 'c2' ]. Now I would like to switch
> to new style classes but replacing class c1: and class c2: by class
> c1(object): and class c2(object): doesn't work because the metaclass
> associated with object will be called and not mine. Of course if I
> would add __metaclass__ = meta(reg)  to all class definitions that
> would work, but how do I do this on the module level?

If present, __metaclass__ serves as a factory for classes without an
explicit base class. For example,

__metaclass__ = type

would turn c1 and c2 into newstyle classes (that inherit from object).
If you want side effects you can wrap the metaclass into a function:

>>> reg = []
>>> def __metaclass__(name, bases, dict):
...     reg.append(name)
...     return type(name, bases, dict)
...
>>> class A: pass
...
>>> class B: pass
...
>>> reg
['A', 'B']
>>> issubclass(A, object)
True

Peter



From nick at craig-wood.com  Fri Dec 22 13:30:05 2006
From: nick at craig-wood.com (Nick Craig-Wood)
Date: Fri, 22 Dec 2006 12:30:05 -0600
Subject: Generating all permutations from a regexp
References: 
Message-ID: 

BJ?rn Lindqvist  wrote:
>  With regexps you can search for strings matching it. For example,
>  given the regexp: "foobar\d\d\d". "foobar123" would match. I want to
>  do the reverse, from a regexp generate all strings that could match
>  it.
> 
>  The regexp: "[A-Z]{3}\d{3}" should generate the strings "AAA000",
>  "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999".
> 
>  Is this possible to do? Obviously, for some regexps the set of matches
>  is unbounded (a list of everything that matches "*" would be very
>  unpractical), but how would you do it for simple regexps like the one
>  above?

A regular expression matcher uses a state machine to match strings.

What you want to do is do a traversal through that state machine
generating all possible matches at each point.

Luckily the python regexp matcher is written in python, so you have
access to the state machine directly if you want.

Take a look at sre*.py in the python library and you might be able to
work out what to do!  I had a brief look myself, and it
looked... complicated!

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick


From luc at honk-honk.com  Wed Dec 20 05:13:42 2006
From: luc at honk-honk.com (Luc Heinrich)
Date: Wed, 20 Dec 2006 11:13:42 +0100
Subject: Good Looking UI for a stand alone application
References: <4584531c$0$13533$426a74cc@news.free.fr>
	<1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com>
	
	<1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com>
	
	<1hql1xl.oz7gsvwz9w1qN%luc@honk-honk.com>
	
Message-ID: <1hqn5b9.7y4f4r1qzf9hiN%luc@honk-honk.com>

Chris Mellon  wrote:

> FYI: OS X ships with wxWidgets installed.

For the sole purpose of providing an easy way to run existing wxPerl and
wxPython code (and possibly "pure" wxWidgets code as well). As a
*porting* aid if you will, as hinted in the "Using Traditional UNIX
Graphical Environments" of the "Porting UNIX/Linux Applications to Mac
OS X" document, here:



> How many applications built into OS X are built using it? 

I quote you: none, zero, zilch :>

> Are you sure? How would you know?

What's that ? Homework ? Oh well, here you go:

import os
import subprocess

def findLinkedWithWX(folder):
  for root, dirs, files in os.walk(folder):
    for d in list(dirs):
      if d.endswith('.app'):
        dirs.remove(d)
        exename, _ = os.path.splitext(d)
        exe = '%s/%s/Contents/MacOS/%s' % (root, d, exename)
        popen = subprocess.Popen(['otool', '-L', exe], 
                                 stdout=subprocess.PIPE)
        libs = popen.communicate()[0]
        if 'libwx' in libs:
          print d

findLinkedWithWX('/Applications')
findLinkedWithWX('/Developer')

-- 
Luc Heinrich


From gonzlobo at gmail.com  Wed Dec 27 13:01:20 2006
From: gonzlobo at gmail.com (gonzlobo)
Date: Wed, 27 Dec 2006 11:01:20 -0700
Subject: Noobie: Open file -> read characters & multiply
In-Reply-To: <4591b22b$1@nntp0.pdx.net>
References: 
	<4591b22b$1@nntp0.pdx.net>
Message-ID: 

Thanks to all that responded. I chose a modified version of Scott's
second recommendation:

time = line[:8]
decoded_File.write( '%00.4f' % (int(time, 16) * .0001) + ', ')

'print >>' added a CRLF that I didn't need, so I went with '.print' (I
need to process about 20 values from the remaining bytes).

Thank you.

On 12/26/06, Scott David Daniels  wrote:
...
> > Any help is really appreciated.
> for line in AP_file:
>      print >>decoded_File, '%s.%04d' % divmod(int(line[:8], 16), 10000
>                                               ), line[9:].rstrip()
>
> or:
>
> for line in AP_file:
>      print >>decoded_File, '%.4f' % (int(line[:8], 16) * .0001
>                                               ), line[9:].rstrip()
...


From chris.cavalaria at free.fr  Thu Dec 14 06:02:31 2006
From: chris.cavalaria at free.fr (Christophe)
Date: Thu, 14 Dec 2006 12:02:31 +0100
Subject: merits of Lisp vs Python
In-Reply-To: 
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	
	<1165598576.650860.126740@16g2000cwy.googlegroups.com>
	 
	<457fc327$0$1038$426a74cc@news.free.fr>
	<87lklcrt00.fsf@thalassa.informatimago.com>
	<457fdb92$0$13245$426a74cc@news.free.fr>
	
Message-ID: <45812f4c$0$26482$426a74cc@news.free.fr>

Robert Uhl a ?crit :
> Christophe  writes:
>> Saying that the French units are technically worse than standard units
>> is a troll of very poor quality and a very weak argument.
> 
> It was just an example that the argument from popularity is invalid.
> However, I (and many others) would argue that optimisation for unit
> conversion is the wrong choice when designing a system of measures.  But
> this is not the venue for such a discussion, so I'll stop now:-)

Well, I spent some time on Wikipedia looking up metric systems and 
things like that because of you, and I found a page that shows how to 
improve the current SI system by reducing the number of fundamental 
units to only two ( S for space and T for time ), and it was a great 
read. It even went so far as give a theory for the disapearance of the 
dinosaurs!

Thank you for that it was a great read.

Here it is : http://www.blazelabs.com/f-u-suconv.asp


From rurpy at yahoo.com  Sun Dec 10 16:51:59 2006
From: rurpy at yahoo.com (rurpy at yahoo.com)
Date: 10 Dec 2006 13:51:59 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <1165780208.497031.62320@73g2000cwn.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
	<874ps423sx.fsf@thalassa.informatimago.com>
	
	
	
	
	
	
	
	<1165780208.497031.62320@73g2000cwn.googlegroups.com>
Message-ID: <1165787518.952865.140200@l12g2000cwl.googlegroups.com>


tayssir.john at googlemail.com wrote:
> Steven D'Aprano wrote:
> > I'd love to say it has been fun, but it has been more frustrating than
> > enjoyable. I don't mind an honest disagreement between people who
> > genuinely are trying to see the other's point of view, but I don't think
> > that was the case here. What was especially frustrating was that the more
> > I tried to understand certain Lispers' positions by asking questions, the
> > more nasty and insulting they became. So now I have an even better
> > understanding for why Lispers have a reputation for being difficult and
> > arrogant.
>
> This is only because they openly disagree with your beliefs. Note that
> you appear the same way to your Lisp-using flamewarrior counterparts.
>
> We might look in the mirror:
> 
>
> Maybe Lisp users are singled out as particularly arrogant because they
> claim that the last 20 or so years of the software profession have been
> something of a fraud.

Well, having read a lot of this thread, I can see one of the
reasons why the software profession might want to avoid
lispies.  With advocacy like this, who needs detractors?



From JShrager at gmail.com  Fri Dec  8 20:32:38 2006
From: JShrager at gmail.com (JShrager at gmail.com)
Date: 8 Dec 2006 17:32:38 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <7xodqdj2dn.fsf@ruckus.brouhaha.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<7xejrah9on.fsf@ruckus.brouhaha.com>
	<1165582654.974945.173700@79g2000cws.googlegroups.com>
	<7xslfqar7v.fsf@ruckus.brouhaha.com>
	<1165623284.242403.295140@l12g2000cwl.googlegroups.com>
	<7xodqdj2dn.fsf@ruckus.brouhaha.com>
Message-ID: <1165627958.748014.101950@16g2000cwy.googlegroups.com>

> ... you can't implement Python generators as Lisp macros in any reasonable
> way.  You could do them in Scheme using call-with-current-continuation
> but Lisp doesn't have that.

Well, okay, Scheme [same thing (to me), although I realize that they
aren't, quite -- and CWCC is one place where they aren't!] But I don't
follow why you can't come very close by appropriate macrification of
closures. OTOH, this could be my lack of knowledge; it's possible that
Python has somehow gone beyond what one can reasonably do in this way.
But anyway, this wasn't the point of my post; rather, my point was that
Python can't be extended at all (or at least not in the same way that
Lisp can be), not that a given extension can or cannot be done in Lisp.



From fredrik at pythonware.com  Sat Dec  2 15:51:57 2006
From: fredrik at pythonware.com (Fredrik Lundh)
Date: Sat, 02 Dec 2006 21:51:57 +0100
Subject: converting dict to object
In-Reply-To: <1165090584.103366.198220@l12g2000cwl.googlegroups.com>
References: <7649225.post@talk.nabble.com>			
	<1165090584.103366.198220@l12g2000cwl.googlegroups.com>
Message-ID: 

John Machin wrote:

> Any experiences of keyword-bite?

creating or manipulating CSS-styled (X)HTML using an XML binding that 
exposes XML attributes as Python attributes.

(this could be viewed as an unnecessary restriction in the Python 
parser; it wouldn't be too hard to allow reserved words for keyword
argument names and for attribute access; iirc, Jython already does this, 
and Paul Svensson posted a patch for CPython a couple of years ago. 
PEP-time, anyone?)





From arkanes at gmail.com  Thu Dec 28 12:18:31 2006
From: arkanes at gmail.com (Chris Mellon)
Date: Thu, 28 Dec 2006 11:18:31 -0600
Subject: per interpreter storage for C extensions
In-Reply-To: <4593FB50.9090804@chamonix.reportlab.co.uk>
References: <4593E44C.9000502@chamonix.reportlab.co.uk>
	<4866bea60612280832ib9700e6v3f191faa7d8ea488@mail.gmail.com>
	<4593F60D.5090005@chamonix.reportlab.co.uk>
	<4593FB50.9090804@chamonix.reportlab.co.uk>
Message-ID: <4866bea60612280918s39aaffbemaabec1b93d5eb7b7@mail.gmail.com>

On 12/28/06, Robin Becker  wrote:
> Robin Becker wrote:
> > Chris Mellon wrote:
> >> On 12/28/06, Robin Becker  wrote:
> >>> As part of some django usage I need to get some ReportLab C extensions into a
> >>> state where they can be safely used with mod_python.
> > .........
> >> Just off the top of my head, I'd think that using thread-local storage
> >> instead of static would work, wouldn't it? I'm not that familiar with
> >> mod_python but I'm surely each python interpreter is in a different
> >> thread (if not process) than the others.
> >
> > I was thinking along those lines and if that were the case then I could use
> >
>
> ....... reading further along those lines it seems there may be some hope of
> storing this stuff on the extension module (probably where it should belong) as
> it seems that new interpreters share extensions, but when the extension is first
>   imported a shallow copy is made of the module dict. That would seem to imply
> the  extension's module is private to each interpreter.
> --


It looks like you can figure out which interpreter you're running
under by looking at PyThreadState_Get()->interp. You can key your
cache using this pointer and you should be fine, if you want to keep
it in C.

> Robin Becker
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


From waldemar.osuch at gmail.com  Sun Dec 10 15:36:52 2006
From: waldemar.osuch at gmail.com (Waldemar Osuch)
Date: 10 Dec 2006 12:36:52 -0800
Subject: Search & Replace in MS Word Puzzle
References: <1165702766.581612.45610@n67g2000cwd.googlegroups.com>
Message-ID: <1165783011.964346.221100@80g2000cwy.googlegroups.com>

I do not have answers for all your questions but a few remarks that may
help.

Ola K wrote:
> Hi guys,
> I wrote a script that works *almost* perfectly, and this lack of
> perfection simply puzzles me.
> I simply cannot point the whys, so any help on it will be appreciated.
> I paste it all here, the string at the beginning explains what it does:
>
> '''A script for MS Word which does the following:
>    1) Assigns all Hebrew italic characters "Italic" character style.
>    2) Assigns all Hebrew bold characters "Bold" character style.
>    2) Assign all English US characters "English Text" (can be regular,
> Italic, or Bold)
>

-- Code snipped

> So generally speaking this script works quite nicely, BUT:
>
> 1. Despite this sort of conditions:
> " if "Italic" not in doc.Styles: "
> if this style already exists I get an error, and the program stops.
> Any idea how can that be?...

doc.Styles is a container (a build in Word object) holding instances of
Styles
(another build in Word object).  One way to make the intended check
would be.
style_names = set(s.NameLocal for s in doc.Styles)
if "Italic" not in style_names:
   # create style

>
> 2. The replacement of the English characters doesn't seem to work very
> well. It either assigns all English characters "English Text Bold", or
> "English Text Italic" and with no apparent reason.
> ?....

Read about Range object in Word VBA documentation.  Range.Collapse may
explain what happens here.

>
> 3. The command
> " word.Visible=1 "
> doesn't work anymore. I say "anymore" because it used to work, but
> later I ran "COM Makepy Utility" on "Microsoft Word 10 Object Library
> (8.2)" and since then it stopped working. On Excel, for example, I
> never ran Makepy and this commands works fine for it.
> Any idea on this one?...

This should work.  If word.visible = True used to work but stopped
after running Makepy it could be explained.  Looks to me there are some
other factors in play.

>
> 4. In the end of this long weekend I was pretty satisfied with my
> script (even if not fully functioning) and used PY2EXE to make it an
> .exe file so that I can use it in my work place. But alas, that .exe
> file does not work because it doesn't recognize any of win32com client
> constants. Such as "wdStyleTypeCharacter", or "wdEnglishUS"
> How can I solve this one?

This is described in py2exe wiki.
http://www.py2exe.org/index.cgi/IncludingTypelibs

Waldemar



From nono at hotmail.com  Sat Dec 30 08:11:54 2006
From: nono at hotmail.com (Osiris)
Date: Sat, 30 Dec 2006 14:11:54 +0100
Subject: python , Boost and straight (but complex) C code
References: 
Message-ID: 

I get, from Visual C++, these linker errors, 8 in total, trying to
build the above C++ source:

C_test.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) void __cdecl
boost::python::detail::init_module(char const *,void
(__cdecl*)(void))"
(__imp_?init_module at detail@python at boost@@YAXPBDP6AXXZ at Z) referenced in
function _inithalf

C_test.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) void __cdecl
boost::python::detail::scope_setattr_doc(char const *,class
boost::python::api::object const &,char const *)"
(__imp_?scope_setattr_doc at detail@python at boost@@YAXPBDABVobject at api@23 at 0@Z)
referenced in function "void __cdecl boost::python::def(char const *,int (__cdecl*)(float))"
(??$def at P6AHM@Z at python@boost@@YAXPBDP6AHM at Z@Z)

C_test.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) class boost::python::api::object __cdecl
boost::python::objects::function_object(struct
boost::python::objects::py_function const &)"
(__imp_?function_object at objects@python at boost@@YA?AVobject at api@23 at ABUpy_function@123@@Z)
referenced in function "class boost::python::api::object __cdecl
boost::python::detail::make_function_aux >(int (__cdecl*)(float),struct
boost::python::default_call_policies const &,struct
boost::mpl::vector2 const &)"
(??$make_function_aux at P6AHM@ZUdefault_call_policies at python@boost@@U?$vector2 at HM@mpl at 3@@detail at python@boost@@YA?AVobject at api@12 at P6AHM@ZABUdefault_call_policies at 12@ABU?$vector2 at HM@mpl at 2@@Z)
C_test.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall
boost::python::objects::py_function_impl_base::py_function_impl_base(void)"
(__imp_??0py_function_impl_base at objects@python at boost@@QAE at XZ)
referenced in function "public: __thiscall
boost::python::objects::caller_py_function_impl > >::caller_py_function_impl > >(struct
boost::python::detail::caller > const &)"
(??0?$caller_py_function_impl at U?$caller at P6AHM@ZUdefault_call_policies at python@boost@@U?$vector2 at HM@mpl at 3@@detail at python@boost@@@objects at python@boost@@QAE at ABU?$caller at P6AHM@ZUdefault_call_policies at python@boost@@U?$vector2 at HM@mpl at 3@@detail at 23@@Z)
C_test.obj : error LNK2001: unresolved external symbol "public:
virtual unsigned int __thiscall
boost::python::objects::py_function_impl_base::max_arity(void)const "
(?max_arity at py_function_impl_base@objects at python@boost@@UBEIXZ)
C_test.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) public: virtual __thiscall
boost::python::objects::py_function_impl_base::~py_function_impl_base(void)"
(__imp_??1py_function_impl_base at objects@python at boost@@UAE at XZ)
referenced in function "public: virtual __thiscall
boost::python::objects::caller_py_function_impl > >::~caller_py_function_impl > >(void)"
(??1?$caller_py_function_impl at U?$caller at P6AHM@ZUdefault_call_policies at python@boost@@U?$vector2 at HM@mpl at 3@@detail at python@boost@@@objects at python@boost@@UAE at XZ)
C_test.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) struct
boost::python::converter::rvalue_from_python_stage1_data __cdecl
boost::python::converter::rvalue_from_python_stage1(struct _object
*,struct boost::python::converter::registration const &)"
(__imp_?rvalue_from_python_stage1 at converter@python at boost@@YA?AUrvalue_from_python_stage1_data at 123@PAU_object@@ABUregistration at 123@@Z)
referenced in function "public: __thiscall
boost::python::converter::arg_rvalue_from_python::arg_rvalue_from_python(struct
_object *)"
(??0?$arg_rvalue_from_python at M@converter at python@boost@@QAE at PAU_object@@@Z)
C_test.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) struct boost::python::converter::registration
const & __cdecl boost::python::converter::registry::lookup(struct
boost::python::type_info)"
(__imp_?lookup at registry@converter at python@boost@@YAABUregistration at 234@Utype_info at 34@@Z)
referenced in function "struct boost::python::converter::registration
const & __cdecl
boost::python::converter::detail::registry_lookup(float const volatile & (__cdecl*)(void))"
(??$registry_lookup@$$CDM at detail@converter at python@boost@@YAABUregistration at 123@P6AADMXZ at Z)
C:\Documents and Settings\Erik\My Documents\Visual Studio
2005\Projects\C_test\Debug\C_test.dll : fatal error LNK1120: 8
unresolved externals


From kentilton at gmail.com  Tue Dec  5 14:54:27 2006
From: kentilton at gmail.com (Ken Tilton)
Date: Tue, 05 Dec 2006 14:54:27 -0500
Subject: logo design
In-Reply-To: <1165333204.582656.325850@80g2000cwy.googlegroups.com>
References: <1165333204.582656.325850@80g2000cwy.googlegroups.com>
Message-ID: 



Xah Lee wrote:
> Logo LISP
> 
> Xah Lee, 2006-12
> 
> Ken Tilton wrote:
> 
>     ?Small problem. You forget that Ron Garret wants us to change the
> name of Common Lisp as the sure-fire way to make it more popular (well,
> hang on, he says it is necessary, not sufficient. Anyway...) I do not
> think we can safely pick a new logo until we have our new name.?
> 
> Changing a language's name is not something that can be easily done,
> and is unnatural and takes concerted effort, and is very difficult for
> it to be successful.
> 
> However, creating a (universally recognized) logo for the language, is
> easily done, and in fact the use of a logo or some representative image
> is inevitable and wide-spread, willy-nilly.
> 
> For example, although there are no official logos for lisp, but as you
> know, there are several logos or images of various forms that are
> already used widely, either to represent lisp the language family, or
> to represent the Common Lisp language. And, for various Scheme
> implementation, they almost all had a logo of their own. Example:
> 
> above: The ?twisty AI font? LISP logo. Used by http://lisp.org/ as
> early is 2001.
> 
> above: The ?earth in parenthesis? logo, used by http://lisp.org/ as
> of 2006-12.
> 
> above: Conrad Barski's ?alien technology? lisp web-badges (source
> ?), which appeared in 2005.
> 
> above: Manfred Spiller's ?lizard? lisp web-badge (source ?),
> which appeared in 2005.
> 
> As these examples shows, that the use of a logo is needed in practice.
> However, it wouldn't help if there are one hundred different logos to
> represent the same thing. The point of logos, is to have a memorable,
> graphical representation. In modern, capitalistic, societies filled
> with information, the use of logos is inevitable. Just look around you
> at this very moment, you probably can identify tens of logos, and for
> each logo, you probably recognize what they represent. Logos, is merely
> a graphical representation of a entity, whose textual analogous
> counterpart are names.
> 
> Since there is a need for logos, we might as well get together and
> agree to have one official logo for lisp the language. That way, it
> solidifies the purpose of the logos in use.
> 
> Note that, although we have the beautiful ?lisp lizard? and
> ?alien technology? graphics, but because of their graphic content
> and in particular the embedded slogan, they do not fit as a logo, but
> more as web-badges.
> 
> Web-badges serve slightly different purpose than logos. It is more for
> the purpose of promotion, than representation. For the same reason,
> there are mascots. For example, Java the language, has a official logo
> of a smoking coffee cup,..

A subtle execution of the tip of a tongue pressed against the upper 
teeth with sprays of spittle coming out either side probably is not what 
you had in mind.

Hmmm. Then we change the spelling to Lithp, and never have to hear that 
stupid joke again. Our slogan can be "Thay it loud, thay it proud."*, 
and we already have the frickin lambda.

hth,kt

Or "Out With Lithp!".

k

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


From aahz at pythoncraft.com  Mon Dec 11 13:55:35 2006
From: aahz at pythoncraft.com (Aahz)
Date: 11 Dec 2006 10:55:35 -0800
Subject: alternate language
References: 
	
	
	<12nr93mis39tu45@corp.supernews.com>
Message-ID: 

In article <12nr93mis39tu45 at corp.supernews.com>,
Grant Edwards   wrote:
>On 2006-12-11, Aahz  wrote:
>>
>> Um...  I think the original poster is saying that he already knows Python
>> and wants to learn another language.  He particularly wants opinions from
>> other people who have learned these languages *after* learning Python.
>
>There are people who learn another language after learning Python??

Heh.  Taking your post more seriously than it deserves, don't you think
someone ought to learn at least SQL if they don't already know it when
they learn Python?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Member of the Groucho Marx Fan Club  


From craigtw.online at gmail.com  Mon Dec  4 17:07:36 2006
From: craigtw.online at gmail.com (Craig)
Date: 4 Dec 2006 14:07:36 -0800
Subject: Convert PNG files to BMP files using PIL
Message-ID: <1165270056.488786.210090@n67g2000cwd.googlegroups.com>

Hi there,

I'm trying to convert some PNG files to bitmap files which can then be
converted to X11 bitmaps using the im.tobitmap() function.  But the
error I get when using the im.tobitmap() function on the PNG files I
get the following error:

>>> im.tobitmap()

Traceback (most recent call last):
  File "", line 1, in 
    im.tobitmap()
  File "C:\Python25\Lib\site-packages\PIL\Image.py", line 545, in
tobitmap
    raise ValueError("not a bitmap")
ValueError: not a bitmap
>>>

Can this be done using PIL or is there another library that can be used
to fulfil the task.  If you could let me know that would be great.
Thanks and good luck.


Craig



From kentilton at gmail.com  Sat Dec  9 22:06:29 2006
From: kentilton at gmail.com (Ken Tilton)
Date: Sat, 09 Dec 2006 22:06:29 -0500
Subject: merits of Lisp vs Python
In-Reply-To: <4u18tpF166u62U1@mid.individual.net>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165613280.584178.36470@16g2000cwy.googlegroups.com>
	<%Qseh.77$495.67@trnddc06> 
	<7xodqdtpks.fsf@ruckus.brouhaha.com>
	
	
	<4u18tpF166u62U1@mid.individual.net>
Message-ID: 



greg wrote:
> Bill Atkins wrote:
> 
>> And mistakes in nesting show up as mistakes in
>> indenting.
> 
> 
> Er, hang on a moment... how do you *know* when you've
> got a mistake in indending? You must be visually
> verifying the indentation... rather like one does
> with Python code...

Absolutely, and you are not disagreeing with Mr. Atkins, tho you seem to 
think you are.

But with Lisp one does not have to clean up the indentation manually 
after thrashing away at ones code. As I type each right parens I eyeball 
its partner as the editor highlights it to make sure I have not missed 
anything, then give the re-indent command and eyeball the result. It 
/is/ still possible to screw up because I work fast and loose, but only 
very rarely do I end up with a parens in the wrong place, and then the 
compiler finds something to whine about.

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


From wilson.max at gmail.com  Fri Dec 22 20:18:41 2006
From: wilson.max at gmail.com (Max  Wilson)
Date: 22 Dec 2006 17:18:41 -0800
Subject: scopes of local and global variable
In-Reply-To: <87psabcvlc.fsf@pyenos.pyenos.org>
References: <87tzzncx59.fsf@pyenos.pyenos.org>
	
	<87psabcvlc.fsf@pyenos.pyenos.org>
Message-ID: <1166836721.486427.111520@h40g2000cwb.googlegroups.com>

Pyenos wrote:
> does class WORK inherit t_len=0 from line1?
>
> does def getwork() inherit t_len=0 from line1?
>
> does def formattable(table_to_process,type) inherit t_len=0 from line1?
>
> does def format_t() inherit t_len=0 from line1?

Not really, no. The global t_len is different than the local t_len--two
variables with the same name. You need to declare "global t_len" inside
your function so it knows that "t_len=..." is assigning to the old,
global variable instead of creating a new one.

See #6 here: http://zephyrfalcon.org/labs/python_pitfalls.html

-Max



From roman.yakovenko at gmail.com  Sun Dec 31 06:50:37 2006
From: roman.yakovenko at gmail.com (Roman Yakovenko)
Date: Sun, 31 Dec 2006 13:50:37 +0200
Subject: python , Boost and straight (but complex) C code
In-Reply-To: 
References: 
	
	
	
Message-ID: <7465b6170612310350x4d7694f9gc059bd9a35f57169@mail.gmail.com>

On 12/31/06, Osiris  wrote:
> In short: it's all rather confusing....
>
> I think it must be like this:
>
> To use my C/C++ code with Python, add some stuff in the C/C++ source
> and compile it into a DLL, that must be combined with some boost-DLL
> to make it accessible to Python 2.4.
> Therefore I need a boost DLL from boost.org, and some headerfiles that
> belong to the boost DLL.
> (where are those boost header files )
>
> As you see, a lot of obfuscation....
> MAybe I see too many bears on the road...

Boost project is an open source, consider to contribute your
experience, knowledge
and time to make it better.

You can download pre-built binaries for Windows platform from here:
http://www.boost-consulting.com/download.html

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/


From __peter__ at web.de  Wed Dec 13 09:49:12 2006
From: __peter__ at web.de (Peter Otten)
Date: Wed, 13 Dec 2006 15:49:12 +0100
Subject: Iterating over several lists at once
References: <1166017627.699257.166740@16g2000cwy.googlegroups.com>
Message-ID: 

Gal Diskin wrote:

> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:

> for x1 in l1:
>     for x2 in l2:
>         for x3 in l3:
>             print "do something with", x1, x2, x3

> I was wondering if one could write this more easily in some manner
> using only 1 for loop.

def nested_loops(*args):
    assert args
    if len(args) == 1:
        for item in args[0]:
            yield (item,)
    else:
        gap = len(args) // 2
        for left in nested_loops(*args[:gap]):
            for right in nested_loops(*args[gap:]):
                yield left + right

if __name__ == "__main__":
    for i, k in nested_loops("abc", "12"):
        print i, k
    for i, j, k in nested_loops("ab", "123", "xyz"):
        print i, j, k

Be prepared for a significant performance hit.

Peter

PS: Did anybody say macro? No? I must be hallucinating...


From kkylheku at gmail.com  Mon Dec 11 00:22:51 2006
From: kkylheku at gmail.com (Kaz Kylheku)
Date: 10 Dec 2006 21:22:51 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <1165787518.952865.140200@l12g2000cwl.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165689545.676886.289150@j44g2000cwa.googlegroups.com>
	
	<874ps423sx.fsf@thalassa.informatimago.com>
	
	
	
	
	
	
	
	<1165780208.497031.62320@73g2000cwn.googlegroups.com>
	<1165787518.952865.140200@l12g2000cwl.googlegroups.com>
Message-ID: <1165814571.528144.65960@l12g2000cwl.googlegroups.com>

rurpy at yahoo.com wrote:
> Well, having read a lot of this thread, I can see one of the
> reasons why the software profession might want to avoid
> lispies.  With advocacy like this, who needs detractors?

And thus your plan for breaking into the software profession is ... to
develop Usenet advocacy skills.

``That guy we just interviewed, I don't know. Perfect score on the C++
test, lots of good architectural knowledge, but he seems to care more
about being correct than convincing people. He'd be fine for now, but
what does that say about his ability when the crunch comes, and he's
called upon to ... advocate?''



From jstroud at mbi.ucla.edu  Fri Dec 22 21:04:37 2006
From: jstroud at mbi.ucla.edu (James Stroud)
Date: Sat, 23 Dec 2006 02:04:37 GMT
Subject: Retrieve Tkinter listbox item by string, not by index
In-Reply-To: <800jh.36786$wP1.8889@newssvr14.news.prodigy.net>
References: <44e1e$458c40af$4275d90a$22798@FUSE.NET>
	<800jh.36786$wP1.8889@newssvr14.news.prodigy.net>
Message-ID: 

James Stroud wrote:
> Kevin Walzer wrote:
> 
>> I'm trying to set the active item in a Tkinter listbox to my 
>> application's currently-defined default font.
>>
>> Here's how I get the fonts loaded into the listbox:
>>
>>  self.fonts=list(tkFont.families())
>>  self.fonts.sort()
>>
>>   for item in self.fonts:
>>             self.fontlist.insert(END, item)   #self.fontlist is the 
>> ListBox instance
>>
>>
>> So far, so good. But I don't know how to set the active selection in 
>> the listbox to the default font. All the methods for getting or 
>> setting a selection in the listbox are based on index, not a string. 
>> And using standard list search methods like this:
>>
>>        if "Courier" in self.fontlist:
>>             print "list contains", value
>>         else:
>>             print value, "not found"
>>
>> returns an error:
>>
>> TypeError: cannot concatenate 'str' and 'int' objects
>>
>> So I'm stuck. Can someone point me in the right direction?
> 
> 
> I would keep a separate data structure for the fonts and update the 
> scrollbar when the list changed. This would help to separate the 
> representation from the data represented. Here is a pattern I have found 
> most useful and easy to maintain:
> 
> # untested
> class FontList(Frame):
>   def __init__(self, *args, **kwargs):
>     Frame.__init__(self, *args, **kwargs)
>     self.pack()
>     self.fonts = list(kwargs['fonts'])
>     self.default = self.fonts.index(kwargs['default_font'])
>     self.lb = Listbox(self)
>     # add scrollbar for self.lb, pack scrollbar
>     # pack self.lb
>     self.set_bindings()
>     self.update()
>   def set_bindings(self):
>     # put your bindings and behavior here for FontList components
>   def update(self):
>     self.lb.delete(0, END)
>     for f in self.fonts:
>       self.lb.insert(f)
>     self.highlight()
>   def highlight(self):
>     index = self.default
>     self.lb.see(index)
>     self.lb.select_clear()
>     self.lb.select_adjust(index)
>     self.lb.activate(index)
>   def change_font(self, fontname):
>     self.default = self.fonts.index(fontname)
>     self.highlight()
>   def add_font(self, fontname, index=None):
>     if index is None:
>       self.fonts.append(fontname)
>     else:
>       self.fonts.insert(index, fontname)
>     self.update()
>   # other methods for adding multiple fonts or removing them, etc.
> 
> 

I overlooked that you will actually want to remove "fonts" and 
"default_fonts" from kwargs before initializing with Frame:

# untested
class FontList(Frame):
   def __init__(self, *args, **kwargs):
     self.fonts = list(kwargs['fonts'])
     self.default = self.fonts.index(kwargs['default_font'])
     kwargs.pop('fonts')
     kwargs.pop('default_font')
     Frame.__init__(self, *args, **kwargs)
     self.pack()
     self.lb = Listbox(self):
     # etc.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/


From amitsoni.1984 at gmail.com  Thu Dec 21 23:31:58 2006
From: amitsoni.1984 at gmail.com (amitsoni.1984 at gmail.com)
Date: 21 Dec 2006 20:31:58 -0800
Subject: Problem in using Pulp
In-Reply-To: 
References: <1166759609.366064.124360@f1g2000cwa.googlegroups.com>
	
Message-ID: <1166761918.461234.167610@h40g2000cwb.googlegroups.com>

Thanks, now I am not getting that error, but now I am getting a
different error:
---------------------error-------------------------------
   GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
  File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114,
in solve
    return lp.solve(self)
  File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line
1740, in solve
    status = solver.actualSolve(self)
  File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188,
in actualSolve
    raise "PuLP: cannot execute "+self.path
PuLP: cannot execute C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples"
-------------------------------------------------------------
can anyone tell me where the problem is? I am using following code.
thanks
Amit
----------------------Code----------------------
from pulp import *

prob = LpProblem("linear", LpMinimize)

# Variables
x = LpVariable("x", 0, 4)
y = LpVariable("y", -1, 1)
z = LpVariable("z", 0)

# Objective
prob += x + 4*y + 9*z

# Constraints
prob += x+y <= 5
prob += x+z >= 10
prob += -y+z == 7

GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
------------------------------------------------------------------------------
Robert Kern wrote:
> amitsoni.1984 at gmail.com wrote:
> > Hi,
> > I am trying to run the following example which uses PULP for linear
> > optimization. But I am getting this error in the last line: "EOL while
> > scanning single quoted string".
>
> > GLPK("C:\Documents and
> > Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)
>
> Backslashes escape characters in strings. Specifically, when a string uses ""
> quotes as delimiters, then \" is the escape sequence for a double quote in the
> string itself. The parser sees your \" at the end as simply an escaped double
> quote and keeps interpreting the rest of the line as a string. Since the line
> ends before another, unescaped " comes along, it raises the exception that you see.
>
> http://docs.python.org/ref/strings.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



From http  Sat Dec 16 18:19:40 2006
From: http (Paul Rubin)
Date: 16 Dec 2006 15:19:40 -0800
Subject: merits of Lisp vs Python
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	
	
	<7x8xhf4w0d.fsf@ruckus.brouhaha.com>
	
	<4ubu3nF16kv7aU1@mid.individual.net> 
	<7x3b7j2gsr.fsf@ruckus.brouhaha.com>
	 
	<7x4przt22g.fsf@ruckus.brouhaha.com>
	
	<4uch8cF17smt9U1@mid.individual.net>
	 
	<4ufemoF17of60U3@mid.individual.net>
	
	<7x7iwtjk3a.fsf@ruckus.brouhaha.com>
	
	<7xodq5tboy.fsf@ruckus.brouhaha.com>
	
	<4uhl7cF108ri8U2@mid.individual.net>
	
	<7xslfgou14.fsf@ruckus.brouhaha.com>
	<2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom>
Message-ID: <7xac1nfmyb.fsf@ruckus.brouhaha.com>

Raffael Cavallaro  writes:
> > It never occurs to Lisp programmers that Lisp, too, might be a Blub.
> 
> Of course it does - Thats why we try ocaml and haskell etc. It's just
> that we don't see the useful features of these languages as being
> sufficiently useful to compensate for their lack of the ability to
> easily do syntactic abstractions over a uniform syntax. 

That sounds to me like a Blub programmer speaking.

> For example, a common lisp with optional static typing on demand would
> be strictly more expressive than common lisp. But, take say, haskell;
> haskell's static typing is not optional (you can work around it, but
> you have to go out of your way to do so); haskell's pure functional
> semantics are not optional (again, workarounds possible to a limited
> extent). This requires you to conceive your problem solution (i.e.,
> program) within the framework of a particular paradigm. This lock-in
> to a particular paradigm, however powerful, is what makes any such
> language strictly less expressive than one with syntactic abstraction
> over a uniform syntax.

Incorrect, I believe.  The above is like saying Lisp's lack of
optional manual storage allocation and machine pointers makes Lisp
less powerful.  It's in fact the absence of those features that lets
garbage collection work reliably.  Reliable GC gets rid of a large and
important class of program errors and makes possible programming in a
style that relies on it.  You can make languages more powerful by
removing features as well as by adding them.  This is what Haskell
does, with its functional purity.  Haskell's lazy evaluation semantics
pretty much depend on the purity.

See also SPJ's papers on composable memory transactions in Haskell:

  http://research.microsoft.com/~simonpj/papers/stm/index.htm

These transactions rely on Haskell's pure functional semantics and if
I understand correctly, can't be implemented reliably without it.  And
just like GC gets rid of a large class of pointer and storage
allocation errors, composable transactions in concurrent programs get
rid of lock-related errors, traditionally a huge source of problems in
real-world code.


From henrik.hjelte at gmail.com  Sat Dec  9 03:26:10 2006
From: henrik.hjelte at gmail.com (hankhero)
Date: 9 Dec 2006 00:26:10 -0800
Subject: merits of Lisp vs Python
In-Reply-To: <1165623830.577613.236890@16g2000cwy.googlegroups.com>
References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com>
	<1165623830.577613.236890@16g2000cwy.googlegroups.com>
Message-ID: <1165652770.265978.272670@l12g2000cwl.googlegroups.com>

I was the one mentioning triple-quotes because it was one of the few
Python features i could think of that was better than Lisps.

> For me python is 'strong OOP' scripting language in first place.
> Inheritance, generalization and every kind of abstractions togeteher
> with clean and simple syntax make python perfect language for medium
> size "scripting" projects (ie just explore the code and add your
> features, no messing with compilers).
The Common-Lisp object systems has all and more OO-features, some which
you never probably have thought of before. Here's one:
Inheritance lets you specialise a method so a rectangle and a circle
can have a different Draw method. If you wouldn't have OO you would
need a function with if statements to dispatch on thing, if
thing=rectange then drawRectangle if thing=circle then drawCircle.
What if you want a draw method that takes a thing and a backend, then
you need if statements again, draw(self,backend): if backend ==
postscript do one thing else do another.
Maybe you can solve this with multiple inheritance, creating
RectangePostscript and CirclePostscript objects. Lisp supports multiple
inheritance too, but also multimethods which allow a looser coupling
between objects and dispatching on all parameters, not only the first
parameter (self in python speak). Just define one method
draw(rectange,postscript) and another draw(rectangle, pdf)

>  Exceptions, finally/except blocks,
Lisp has a unique exception system. Say ReadHtmlTag throws an exception
deep down in your system, UnexpectedChar. In Lisp you can define
recovery strategies all over your system. the IgnoreAttribute recovery
strategy can be in the same method as ReadHtmlTag. You can have another
ways to recover, IgnoreFile, or ReparseFile higher up in your program.
When you catch the error at the highest point in you main function, you
can choose which recovery you want to use. Either IgnoreAttribute and
continue in the ReadHtmlTag method or ReparseFile in the ParseFile
method. The stack and variables will be there right as when the error
occurred. If I write a library I don't have to guess if the users of my
library wan't me to show a nice GUI error message, ignore the error or
whatever. I provide all options and let they choose.

> automatic reference counts and destructors make it easy to
> write "robust" code.
No, Lisp doesn't have anything like that. There is a thing called the
garbage collector however, I think it exists in other languages.



From greg at cosc.canterbury.ac.nz  Sun Dec 17 01:53:58 2006
From: greg at cosc.canterbury.ac.nz (greg)
Date: Sun, 17 Dec 2006 19:53:58 +1300
Subject: tuple.index()
In-Reply-To: 
References: 
	<1166104987.884566.126710@n67g2000cwd.googlegroups.com>
	
	<1166106278.106832.278240@n67g2000cwd.googlegroups.com>
	
	
	
	
	
	 
Message-ID: <4584E986.10502@cosc.canterbury.ac.nz>

Nick Maclaren wrote:

>     A collection is inhomogeneous if, for some attribute that is needed
>     for at least one action on at least one element of the collection,
>     the attribute is not shared by all elements of the collection.

If you mean "attribute" in the Python sense, then this
is wrong, because you're just defining it in terms of
concrete types again.

There is no rigorous definition in Python terms, because
Python doesn't formally embody the concept. But that
doesn't mean the concept isn't real.

There are other languages that do embody it, for example,
C. A Python tuple is like a C struct, and a Python list
is like a C array.

--
Greg


From simon at brunningonline.net  Tue Dec 19 10:05:35 2006
From: simon at brunningonline.net (Simon Brunning)
Date: Tue, 19 Dec 2006 15:05:35 +0000
Subject: permutations - fast & with low memory consumption?
In-Reply-To: 
References: 
Message-ID: <8c7f10c60612190705y37fdc84ehc9f4545d6997319e@mail.gmail.com>

On 12/19/06, Christian Meesters  wrote:
> Hi,
>
> I'd like to hack a function which returns all possible permutations as lists
> (or tuples) of two from a given list. So far, I came up with this solution,
> but it turned out to be too slow for the given problem, because the list
> passed ("atomlist") can be some 1e5 items long:

Anything here?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465

-- 
Cheers,
Simon B
simon at brunningonline.net


From carsten at uniqsys.com  Tue Dec 26 14:48:59 2006
From: carsten at uniqsys.com (Carsten Haese)
Date: Tue, 26 Dec 2006 14:48:59 -0500
Subject: Q: How to generate code object from bytecode?
In-Reply-To: <1167160509.839311.230090@73g2000cwn.googlegroups.com>
References: <1167160509.839311.230090@73g2000cwn.googlegroups.com>
Message-ID: <1167162539.3394.18.camel@dot.uniqsys.com>

On Tue, 2006-12-26 at 11:15 -0800, kwatch at gmail.com wrote:
> Hi,
> 
> It is possible to get bytecode from code object.
> Reversely, is it possible to create code object from bytecode?
> 
> ex.
>   ## python code (not a module)
>   pycode = '''\
>   print "
    \n" > for item in items: > print "
  • %s
  • \n" % item > print "
\n" > ''' > > ## compile it and get bytecode > code = compile(pycode, kind='exec') > bytecode = code.co_code > open('hoge.pyc', 'wb').write(bytecode) > > ## load bytecode and eval it > bytecode = open('hoge.pyc', 'rb').read() > code = create_code(bytecode) ## how to ????? > output = eval(code, globals, {'items': ['A', 'B', 'C']}) As Fredrik has said, you should use marshal to handle the writing and reading of the code object. I'd like to point out the following additional facts that may not be apparent to you: * Code objects come in two flavors: statements and expressions. * exec can execute a 'statement' flavored code object. * eval can evaluate an 'expression' flavored code object. * Your code snippet is a statement, actually, a suite of statements. You need to exec it, not eval it. * You seem to think that eval'ing or exec'ing a code object will magically capture its output stream. It won't. What do you actually want to accomplish? Instead of having us poke at your first attempt at a solution, it might be more helpful if you told us what problem you're actually trying to solve. -Carsten From allenjo5 at mail.northgrum.com Fri Dec 1 15:11:20 2006 From: allenjo5 at mail.northgrum.com (allenjo5 at mail.northgrum.com) Date: 1 Dec 2006 12:11:20 -0800 Subject: Python popenX() slowness on AIX? References: <1164059636.171319.121310@j44g2000cwa.googlegroups.com> <1164117707.309823.237640@j44g2000cwa.googlegroups.com> <1164119554.955532.236180@b28g2000cwb.googlegroups.com> <1164124553.907183.261220@m7g2000cwm.googlegroups.com> <1164142934.364814.191210@m73g2000cwd.googlegroups.com> <20061122000251.56e894dd.hoendech@ecc.lu> <1164387821.375946.191430@m7g2000cwm.googlegroups.com> <20061124230828.d8075dd2.hoendech@ecc.lu> Message-ID: <1165003880.448629.31820@j72g2000cwa.googlegroups.com> Stefaan A Eeckels wrote: > On 24 Nov 2006 09:03:41 -0800 > allenjo5 at mail.northgrum.com wrote: > > > Stefaan A Eeckels wrote: > > > On 21 Nov 2006 13:02:14 -0800 > > > allenjo5 at mail.northgrum.com wrote: > > > > > > > The fact that it does this in Python code instead of C is the main > > > > cause of the slowness. So, unless Python is changed to do this > > > > in C, it's always going to be slow on AIX :-( > > > > > > I guess that the reason it's slow is that there are many > > > descriptors to try and close. Reducing them using ulimit -n could > > > improve the speed. > > > > > > AIX has a fcntl command to close all open file descriptors from a > > > descriptor onwards: > > > > > > fcntl(3, F_CLOSEM); > > > > > > This of course should be used instead of the loop: > > > > > > 10 happens to be the value of F_CLOSEM (from /usr/include/fcntl.h). > > > I've currently no access to an AIX system with Python, but it could > > > be worth trying. > > > > Yes, very much worth it. F_CLOSEM is _so_ much better than the loop, > > even in C. Using your brilliant suggestion, I now have a simple > > patch to the python source that implements it for any OS that happens > > to have the fcntl F_CLOSEM option. > > The *BSDs and Solaris have "closefrom(3)" which does the same as > F_CLOSEM in AIX. As with AIX, the speedup is dramatic when there are a > lot of file descriptors to try and close. > > > It is below in its entirety. I believe I got the try: stuff correct, > > but since I'm new to Python, I'd appreciate any comments. > > I'm no great Python specialist myself. I'll leave it to those better > qualified to comment. > > > I have another patch to implement my os.rclose(x,y) method, which > > would improve the speed of popenX() for the OSes that don't have > > F_CLOSEM, by doing the close() loop in C instead of Python, but I > > don't know if it would be as likely to be accepted as this probably > > would be. > > > > Now, where do I send my proposed patch for consideration? > > The README file in the Python distribution has the following to say: > > Patches and contributions > ------------------------- > > To submit a patch or other contribution, please use the Python Patch > Manager at http://sourceforge.net/patch/?group_id=5470. Guidelines > for patch submission may be found at http://www.python.org/patches/. Thanks. I joined sourceforge, and submitted this patch: http://sourceforge.net/tracker/index.php?func=detail&aid=1607087&group_id=5470&atid=305470 For some reason, I could not submit it using Firefox 1.5, so I had to relent and use IE. John. From tjgolden at gmail.com Fri Dec 15 07:57:59 2006 From: tjgolden at gmail.com (Tim Golden) Date: 15 Dec 2006 04:57:59 -0800 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: <1166187479.167471.169270@n67g2000cwd.googlegroups.com> [Christoph Zwerschke] > And can somebody explain what is exactly meant with > "homogenous data"? This seems to have been explained a few times recently :) Basically, if you have a "list of xs" and remove one item from it, it is still a "list of xs", where "xs" might be people, coordinate-pairs, numbers or whatever made sense to you. If you have a tuple containing, say, a 2d coordinate pair, and remove something from it, it's no longer a coordinate pair. If you add one to it, it's something else as well (perhaps a 3d coord?) A typical example of their combined use is a set of rows returned from a database: each row is a tuple of fields, the same as all other such rows, and removing or adding a field would make no sense. However, add a new row to the list and it remains a list of rows. Now you can take this or leave it within Python. You can but mixed values into a list so it isn't really a list of "xs" unless "x" is just "thing". Likewise you can use a tuple to hold a list of identical things although you can't add to it or take away. > Concretely speaking, which data type should I use > for coordinate tuples? Usually, tuples are used. Does this mean that I > should better use lists from now on because all the components have the > same type? This would seem to be slightly false logic (and very possibly used tongue-in-cheek). Heterogeneous data doesn't mean that each item *has* to be different, merely that they *may* be. TJG From gert.cuykens at gmail.com Mon Dec 18 17:24:02 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Mon, 18 Dec 2006 23:24:02 +0100 Subject: def index(self): In-Reply-To: <4587017b$0$22957$426a34cc@news.free.fr> References: <4587017b$0$22957$426a34cc@news.free.fr> Message-ID: > FWIW, the first version raises an exception (unless of course the name > 'index' is already bound in the enclosing scope). And the second won't > probably work as expected with CherryPy. class HelloWorld: def index(self): return "Hello world!" index.exposed = True #DOOOOOOH! i skipped reading the chapter about 2.1.8 Indentation. Guess how many hours it took to realize 2 spaces isn't the same as 1 space lol Any other chapters i should read horizontal instead of vertical for a php5 htm jso wane be snake user :) From fredrik at pythonware.com Tue Dec 5 02:28:45 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 05 Dec 2006 08:28:45 +0100 Subject: how to invoke the shell command and then get the result in python In-Reply-To: <1165303175.523129.154400@j72g2000cwa.googlegroups.com> References: <1165303175.523129.154400@j72g2000cwa.googlegroups.com> Message-ID: Bin Chen wrote: > I want to do following: get a user input regex, then pass this as a > parameter to grep, and then get the result from grep. > > Any code snip to implement the similar function? I am a python newbie. import os for line in os.popen("grep pattern *.txt"): print line, also see os.system and subprocess. note that if you want to write portable code, you can implement your own "grep" using the "re" module: import re p = re.compile(pattern) for index, line in enumerate(open(filename)): if p.match(line): print index, line, From diesch at spamfence.net Thu Dec 14 22:52:20 2006 From: diesch at spamfence.net (Florian Diesch) Date: Fri, 15 Dec 2006 04:52:20 +0100 Subject: alternate language References: Message-ID: <20061215035220.33AD.c.NOFFLE@dieschf.news.arcor.de> Bryan wrote: > what is a good alternate language to learn? i just want something to > expand my mind and hopefully reduce or delay any chance of > alzheimer's. i would especially like to hear from those of you who > learned python _before_ these languages. > > haskell, erlang, ocaml, mozart/oz, rebel, etc. I did a little bit Haskell at university. IMHO it's a very interesting language to expand your mind. I never used it for real programming though. > i don't require any of these features, but extra browny points for any > of the following: > > interactive interpreter HUGS > batteries included Not with the standard library but AFAIK GHC comes with alot of things > can integrate with c AFAIK there are some tools > compiles to native code GHC > can use a gui toolkit such as wx AFAIK there are at least Gtk bindings > doesn't take 60 hour weeks over years to master It may take you some time get the idea of pure functional programming (no loops, no assignment, ...) Florian -- From bretthoerner at gmail.com Wed Dec 20 19:20:07 2006 From: bretthoerner at gmail.com (Brett Hoerner) Date: 20 Dec 2006 16:20:07 -0800 Subject: calling a class instance of function In-Reply-To: <87zm9i5cub.fsf@pyenos.pyenos.org> References: <87zm9i5cub.fsf@pyenos.pyenos.org> Message-ID: <1166660407.106759.78210@f1g2000cwa.googlegroups.com> Pyenos wrote: > class test(pid): > pid.original=[1,2,3] > pid.toadd=4 > pid.add(pid.original,pid.toadd) # error here says that > # it expects pid instance as first arg > # not a list that it got. > > why do i get an error? 'test' is a class here, and the pid you tried to pass it is actually the class it is inheriting from. I think you wanted to do: def test(pid): ... Also, in order to call a function without arguments you still need to use (), so you probably wanted to use pid.original() in your pid.add call. Brett Hoerner From nmarais at sun.ac.za Tue Dec 19 09:53:31 2006 From: nmarais at sun.ac.za (Neilen Marais) Date: Tue, 19 Dec 2006 16:53:31 +0200 Subject: Using difflib to compare text ignoring whitespace differences Message-ID: Hi I'm trying to compare some text to find differences other than whitespace. I seem to be misunderstanding something, since I can't even get a basic example to work: In [104]: d = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) In [105]: list(d.compare([' a'], ['a'])) Out[105]: ['- a', '+ a'] Surely if whitespace characters are being ignored those two strings should be marked as identical? What am I doing wrong? Thanks Neilen -- you know its kind of tragic we live in the new world but we've lost the magic -- Battery 9 (www.battery9.co.za) From kirk at nospam.jobsluder.net Sun Dec 10 13:12:00 2006 From: kirk at nospam.jobsluder.net (Kirk Sluder) Date: Sun, 10 Dec 2006 18:12:00 GMT Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165596641.245385.113090@f1g2000cwa.googlegroups.com> <1165704007.887869.192290@16g2000cwy.googlegroups.com> Message-ID: In article , Steven D'Aprano wrote: > On Sun, 10 Dec 2006 14:35:07 +0000, Kirk Sluder wrote: > > > In article > > , > > Steven D'Aprano wrote: > > > >> And here I was thinking that languages fell from the sky like donuts! > >> Gosh, thank you for explaining that too me. What a fool I must seem! > > > > Certainly that is what you wrote. If you had not meant that English > > enforces restrictions on expressiveness, perhaps you should not have > > written it. > > Okay, I'm trying to meet a common ground here, but you're not making it > easy. Of course English, like all languages, restricts what can be said in > that language. I'm talking about grammar and syntax, not semantics, just > like I said at the beginning. Well again, the question is exactly *what* is doing the restricting? What will happen if you make an "illegal" statement in English? If you can't define some sort of mechanism inherent in the English language that prevents the expression of "illegal" utterances, then you can't make the claim that "English. .. restricts what can be said in that language." This is a technical point, but not a trivial one. That is one heck of an active verb that you are attributing to an extremely passive noun. If you want common ground, it appears that we both agree that language practices are enforced by social communities. Is this not the case? > Oh, you might also like to look up what a straw-man argument is before > continuing to accuse people of making it. There seems to be this myth on > the Internet and Usenet that a straw-man argument is "any argument I don't > like, or don't understand, or can't refute". Certainly. A straw man is an artificially weak position that you attribute to your opponent. You chose to argue against the artificially weak position of "there are no rules." You attributed that position to me, not acknowledging my stated position. In what way is this not a straw man? You now claim to agree with the position I actually stated: language is restricted by social communities that use language. If we both agree on this position, we can move on back to the discussion on how those norms and practices discriminate against unlispy/unpythonic language extensions. > That might be true in the case of public code which is open to the entire > community, but it isn't true of all code. Not all code is open to the > wider programmer community to inspect. Code gets written in small teams, > or by individuals, and then it gets used by potentially millions of people > who never got to review the code but have to suffer the consequences of > any bugs in it. What do people who don't need to read code, or don't need access to code matter in regards to code readability? And yes, small teams do constitute a linguistic community of practice as well. But I don't know of many small teams who don't have histories as members of larger communities of practice. > (I'm not saying this is uniquely a problem caused by Lisp macros. Don't > misinterpret what I'm saying.) Which comes back around again to my constant question. Why do these threads consider macros as a way to extend the language so much more of an obfuscatory threat compared to other methods of language extension: (including libraries, operator overloading, and polymorphism?) From tim.peters at gmail.com Thu Dec 21 02:24:31 2006 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 21 Dec 2006 02:24:31 -0500 Subject: a question on python dict In-Reply-To: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> References: <1166684796.856425.235810@i12g2000cwa.googlegroups.com> Message-ID: <1f7befae0612202324v6fb07a8cve040f4d71241fabd@mail.gmail.com> [could.net at gmail.com] > Python dict is a hash table, isn't it? Yup. > I know that hashtable has the concept of "bucket size" and "min bucket > count" stuff, Some implementations of hash tables do. Python's does not. Python's uses what's called "open addressing" instead. > and they should be configurable so I can set them to the proper value > when I know how many items I'm going to handle. > > If these two values can't be set, the hashtable will give them default > values. When there are more and more items being added to the > hashtable, it increase its buckets and copy the old items into the new > one and re-calculate the hash value of each item. That's several distinct claims, each of which is true of some hash table implementations but not of others. Python's implementation has no "buckets", so all that's simply irrelevant. Python's implementation (not all do) saves the hash value of each item, so when it does need to grow (or shrink) the space allocated to the table, it does not need to recalculate the hash value of any item. You should also note that copying a dict key or value (no matter of what type) consists in its entirety of copying one machine address (a 4- or 8-byte pointer, depending on platform). > I think this will waste some time doing the increasing-copying thing. It does take time to resize. "Waste" is a value judgment ;-) > If I know I'm going to handle about 20000 items, I can set the size of > hashtable to 30000. > > So, can I do this in python? You can't. Unless you build up to 20000 items over and over (many thousands of times), it's unlikely you'd be able to measure the time difference even if you could. From __peter__ at web.de Fri Dec 1 04:24:33 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Dec 2006 10:24:33 +0100 Subject: String formatters with variable argument length References: <1164932769.210948.289560@f1g2000cwa.googlegroups.com> <1164936827.570682.325260@j72g2000cwa.googlegroups.com> Message-ID: John Machin wrote: >> > Fredrik Tolf wrote: >> > > The thing is, I want to get format strings from the user, and I don't >> > > want to require the user to consume all the arguments. > what's ugly about this: > [untested]: > > def count_format_args(s): > pending = False > count = 0 > for c in s: > if c == "%": > # doubled % chars aren't counted > pending = not pending > elif pending: > count += 1 > pending = False > return count > > output = format % arglist[:count_format_args(format)] Keep in mind, though, that it doesn't take '*' into account: >>> count_format_args("%*.*f") 1 >>> "%*.*f" % (3,2,1) '1.00' And just because I don't think I've seen it before: >>> count_format_args("%42%") 1 >>> "%42%" % () ' %' Peter From pavlovevidence at gmail.com Thu Dec 14 12:42:22 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 14 Dec 2006 09:42:22 -0800 Subject: tuple.index() References: <1166103409.199435.290670@79g2000cws.googlegroups.com> Message-ID: <1166118142.144177.78790@l12g2000cwl.googlegroups.com> Glenn Hutchings wrote: > Simon Brunning wrote: > > It's because, philosophically, a Python tuple isn't just a read-only list. > > But there are situations where you might want to treat it as a > read-only list. E.g., an argument to a function, so that you can > guarantee the function won't modify it. Seems to me a misplaced fear. Do you take steps to also protect other mutable arguments (dicts, class instances, etc.)? If not, there should be no reason why you should protect lists that way either. If so, you could do a similar thing for lists as well. For the record, I don't agree with tuple's absent count and index methods either, but for other reasons. It's a minor thing. I deal with it. > In that case, it makes sense > for the non-modifying methods (index() and count()) to be available. As I said in another thread, making sense is about step one out of a hundred for getting your change into the language. Carl Banks From sjmachin at lexicon.net Sun Dec 3 00:41:43 2006 From: sjmachin at lexicon.net (John Machin) Date: 2 Dec 2006 21:41:43 -0800 Subject: db.commit() to take effect In-Reply-To: <1165123781.350370.308320@79g2000cws.googlegroups.com> References: <1165123781.350370.308320@79g2000cws.googlegroups.com> Message-ID: <1165124503.182532.16170@79g2000cws.googlegroups.com> progman wrote: > I was testing the python+mysql > > here are my sample codes: > ------------------------ > import MySQLdb > from pprint import pprint > db = MySQLdb.connect(host="localhost", user="root", passwd="password", > db="database") > cursor = db.cursor() > cursor.execute('update promo set date=100") > > > ------------------------ > > i was expecting the cursor.execute will update my db immediately. > it wasn't. not until i run db.commit(), then only i see the value > changes. > > it that the right way to update db? Short answer: yes Longer answer: In most non-trivial db apps, to carry out a given real-world transaction, you will need to do multiple updates/inserts, and you want them all to happen, or none to happen. The database would be inconsistent if your app or server crashed half-way through. Imagine you are transferring some money to someone else's bank account. The money gets deducted from your account but not added to theirs -- not good. [A real banking system would not be that simple, but you should get the general idea.] So you do db.commit() after the last insert/update. HTH, John From pydecker at gmail.com Mon Dec 4 20:23:02 2006 From: pydecker at gmail.com (Peter Decker) Date: Mon, 4 Dec 2006 20:23:02 -0500 Subject: python + database book In-Reply-To: References: <1165122005.291219.81170@73g2000cwn.googlegroups.com> Message-ID: On 12/4/06, Giuseppe Di Martino wrote: > > new to python. > > i work with db heavily. > > > > any good book for python + database????? > > Evaluate http://www.sqlalchemy.org/ and his documentation If you are looking to work with desktop apps, you should also check out Dabo: http://dabodev.com -- # p.d. From paul at boddie.org.uk Wed Dec 6 07:04:36 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 6 Dec 2006 04:04:36 -0800 Subject: What are python closures realy like? References: <1165403880.594551.126360@n67g2000cwd.googlegroups.com> Message-ID: <1165406676.572919.26510@f1g2000cwa.googlegroups.com> Fredrik Lundh wrote: > > when doing some heavy optimization, I recently found myself writing: > > def foobar(arg1, arg2, arg3): > def helper(arg): > do something with arg1 and argument > def foo(): > do something with arg1 and arg3 and > call helper > def bar(): > do something with arg1 and arg2 > def zoo(): > do something with arg2 and arg3 and > call helper > # oops; how do I return all these? > class bag(object): > pass > bag = bag() > bag.foo = foo > bag.bar = bar > bag.zoo = zoo > return bag > > which, I think, deserves no further comment... Have I missed something deep here, or could you not have written the above as follows...? class foobar(object): def __init__(self, arg1, arg2, arg3): self.arg1, self.arg2, self.arg3 = arg1, arg2, arg3 def helper(self, arg): do something with arg1 and argument def foo(self): do something with arg1 and arg3 and call helper def bar(self): do something with arg1 and arg2 def zoo(self): do something with arg2 and arg3 and call helper There's certainly some boilerplate required (in both forms, though) and you'd have to use self in various places, but the above looks less contorted to me. I'd like to hear your further comment, however, since the principal inconvenience of making a class seems to be in the verbose initialisation and explicit self, the latter of which obviously being a feature that you won't find me complaining about, though. ;-) Paul From PPNTWIMBXFFC at spammotel.com Tue Dec 5 03:17:53 2006 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Tue, 05 Dec 2006 09:17:53 +0100 Subject: The del statement Message-ID: Hi I was wondering whether the del statment was going to stay in Python3000? It is a bit awkward to use the del statement where a method call would do the same without the need for a new keyword. del list[elem] del map[elem] Where list.del(elem) map.del(elem) would achieve the same result (and I think, this is what happens in the backend). The same discussion was done for the "external" len-function (list.len() vs. len(list)). I don't dare to say that the del-keyword is superflous, but I would like to know the pros and cons of the external keyword approach. Greetings, Marco From PPNTWIMBXFFC at spammotel.com Thu Dec 7 02:49:41 2006 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Thu, 07 Dec 2006 08:49:41 +0100 Subject: The del statement References: Message-ID: Thanks for the answers. I see that the del statement does remove an object from the namespace. And yes, it makes perfect sense to handle it from "outside" with the del command. I am not convinced though that del should also remove elements from a container/sequence. Thanks for the enlighting answers, Marco From altern2 at gmail.com Wed Dec 20 13:16:54 2006 From: altern2 at gmail.com (altern) Date: Wed, 20 Dec 2006 19:16:54 +0100 Subject: error with IDLE on debian Message-ID: <45897E16.4010309@gmail.com> Hi when i try to run IDLE on my debian laptop I get this error. $ idle Traceback (most recent call last): File "/usr/bin/idle", line 5, in ? main() File "idlelib/PyShell.py", line 1359, in main File "idlelib/FileList.py", line 44, in new File "idlelib/PyShell.py", line 105, in __init__ File "idlelib/EditorWindow.py", line 111, in __init__ File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 2764, in __init__ Widget.__init__(self, master, 'text', cnf, kw) File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1865, in __init__ self.tk.call( _tkinter.TclError: expected integer but got "`100" I am not sure about what could cause the problem because I didnt use my laptop for python programming for couple of weeks. Before that it worked fine. And on that period i might have installed few things. I am running Debian unstable with python 2.2.4, tcl8.4, tk8.4, python-tk 24.4-1 and IDLE 2.4.4-2. I already tried to reinstall IDLE, tk and tcl and python-tk but that did not solve anything, i keep getting the same error. any ideas? thanks enrike From Leo.Kislov at gmail.com Sat Dec 16 00:34:16 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 15 Dec 2006 21:34:16 -0800 Subject: Serial port failure References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> Message-ID: <1166247256.587182.158950@n67g2000cwd.googlegroups.com> Rob wrote: > try: > response = p.readline() > except SerialException: > print ">>>>>Timed out<<<<<" > try: > port.writelines(msg) > except OSError: > print "Serial port failure. Power cycle units" > port.close() > sys.exit(1) > > Does anyone have any ideas? It'd be a good idea to print all exceptions, it can help debugging the problem (if you don't like it going to the screen of an end user at least write it to a log file): except SerialException, err: print err print ">>>>>Timed out<<<<<" except OSError, err: print err print "Serial port failure. Power cycle units" and in your OpenPort function too. -- Leo From http Tue Dec 12 11:19:08 2006 From: http (Paul Rubin) Date: 12 Dec 2006 08:19:08 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> Message-ID: <7x3b7lccjn.fsf@ruckus.brouhaha.com> Ken Tilton writes: > >> The loop language is so complicated and confusing that I never > >> bothered trying to learn it. > > That was my stance for about seven years of intense Lisp. Then the > author of Practical Common Lisp did a nice job of breaking the whole > mess up into sensible chunks and I picked it up. If one programs Lisp, > one should learn Loop -- it is definitely worth the bother. I def > regret not learning it sooner. I don't really code in Lisp any more, I never felt a need for loop when I was coding in Lisp, and I'm trying to move towards a style of programming without loops (i.e. I'm playing with Haskell, which doesn't have loops), giving me even less need for a hairy loop macro. From python.list at tim.thechases.com Tue Dec 12 09:44:16 2006 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 12 Dec 2006 08:44:16 -0600 Subject: comparing two IP addresses and the underlying machine In-Reply-To: <1eb708be0612111355u6c9c51a2u796fdb5aa44b01d9@mail.gmail.com> References: <1eb708be0612111355u6c9c51a2u796fdb5aa44b01d9@mail.gmail.com> Message-ID: <457EC040.5080105@tim.thechases.com> > I've been trying to figure this one out for some time but > with no success. I have a machine with two network > interfaces, each with their own IP address and it's own > domain, for example: > - ipA on machineA.domainA > - ipB on machineB.domainB > > Given any pair of IPs or hostnames (or a mix of them), how > can I figure whether they belong to the same physical > machine or not? Of course, this is trivial if my python > program is running the given machine but what if a remote > machine is trying to figure this out (but that machine has > access to both domains/IPs). > Appreciate and ideas. I have a feeling that you're trying to attempt the impossible. What do you mean by "the same physical machine"? The same case? What happens if there are two virtual OSes on the machine, each using its own NIC? Unless you have a client application running on "the physical machine" that can respond to queries on each NIC, you're pretty much out of luck. You could write something like a "same_ping" program that would listen on both NICs, and respond with a "yeah, I'm the same machine" confirmation. There are all sorts of ways to do this, depending on how sure you need to be that nobody can spoof it...ranging from simple "here's a random number on one IP address followed by asking the other IP if it's seen that random number before" to having the physical machine sign one request on each port and confirm that their signatures are the same. -tkc From nick at craig-wood.com Tue Dec 19 05:30:05 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Tue, 19 Dec 2006 04:30:05 -0600 Subject: Core dump revisited References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> <1166474110.001428.137260@80g2000cwy.googlegroups.com> <1166476940.590579.133460@73g2000cwn.googlegroups.com> Message-ID: Sheldon wrote: > Sheldon skrev: > > Wonderful! Now I know how to used gdb with python. Good! > > The are results area posted below. Since I am new at this I could > > used some help in interpreting the problem. What I do know is > > this: my allocation of the array is good but when freeing the > > array, a problem arises. The problem is given below but since I am > > new as well to C Ambitious! > > I sure could use some help. > > > > Program received signal SIGSEGV, Segmentation fault. > > [Switching to Thread 1077321856 (LWP 32710)] > > 0x40297b83 in mallopt () from /lib/tls/libc.so.6 > > (gdb) bt > > #0 0x40297b83 in mallopt () from /lib/tls/libc.so.6 > > #1 0x402958ba in free () from /lib/tls/libc.so.6 > > #2 0x405e070a in MemoryFreeOrd () at msgppsmodule_area.c:1675 > > #3 0x405dae0a in msgppsarea (self=0x0, args=0x4042aa7c, kwargs=0x0) at > > msgppsmodule_area.c:328 > > #4 0x40073b16 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0 Typing "up" and "down" to move up and down the call stack is a good thing. Type "l" to see a list of code at the point that things went wrong. You can type "print " to see the values of variables. gdb understands most C syntax so you can use "print this->member[1].data" etc. This all assumes you compiled and linked with debugging (-g flag to compiler and linker). Turning off optimisation may make the debugger more accurate also. I can't tell exactly where your program crashed because of line wrapping it your post, but is it certainly within MemoryFreeOrd(). What I would do next is run the program under gdb, wait for it to crash then print the values of things in the MemoryFreeOrd() function. You'll find one of the pointers has been corrupted, ie doesn't point to valid memory or memory allocated with malloc() I expect. 0 or NULL is an acceptable input to most free() implementations but not all. Finding out exactly where that pointer got corrupted is harder. Maybe it was never initialised, or maybe you initialised it with a PyObject or maybe you have a memory scribble somewhere. A memory scribble is the hardest bug to find because it happened elsewhere in your program. Look at the data that was overwritten. Maybe it is a string you can identify... You'll also want to start reading the gdb manual on breakpoints and watchpoints at this moment! Find memory corruptions can be tricky and time consuming. Valgrind can help also. Good luck! -- Nick Craig-Wood -- http://www.craig-wood.com/nick From gagsl-py at yahoo.com.ar Fri Dec 8 02:19:55 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 08 Dec 2006 04:19:55 -0300 Subject: Need Help Parsing From File In-Reply-To: <4578F6BB.4050204@lexicon.net> References: <1165470696.899710.119250@16g2000cwy.googlegroups.com> <1165517086.976152.216270@16g2000cwy.googlegroups.com> <7.0.1.0.0.20061207230730.03e40c38@yahoo.com.ar> <4578F6BB.4050204@lexicon.net> Message-ID: <7.0.1.0.0.20061208041045.04084820@yahoo.com.ar> At Friday 8/12/2006 02:23, John Machin wrote: >>> > > > ftxt=open(filename,"rt") >>> >>>Why did you do that? >>>(1) Text mode is was and ever shall be the default, even with MS. >>No, there used to be a flag in the stdio library, giving the >>default value when neither t or b was specified. >>For the Borland C++ 3.1 help (about 1991): >> If "t" or "b" is not given in the string, the mode is governed by _fmode. >> If _fmode is set to O_BINARY, files are opened in binary mode. >> If _fmode is set to O_TEXT, they are opened in text mode. >>MSC used to have a similar flag (perhaps using the same name). >Indeed, and their docs say that the default for _fmode is text mode. But anyone could change that *global* flag, making "binary" the default afterwards. So if you really wanted a text file you had to be explicit. >>All of this predates wide usage of ANSI C 89, which made the "t" >>flag obsolete. >> >>>(2) Seeing we're referring to docs and standards: Microsoft C 5.0 >>>Optimizing Compiler, Run-Time Library Reference manual says "The t >>>option is not part of the ANSI standard for open, but is a Microsoft >>>extension and should not be used where ANSI portability is required". >>A "t" after the initial recognized characters should be ignored by >>any conforming compiler. I think the idea was to allow for >>extensions like fopen(fn, "rt;reclen=128") but except esoteric >>platforms I doubt anyone is using that. > >So it should be ignored. >So, back to the question: why did you get into the habit of writing >"rt" when it was pointless? Because it was *not* pointless before ANSI C. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From michael.pearmain at tangozebra.com Tue Dec 5 12:02:44 2006 From: michael.pearmain at tangozebra.com (Mike P) Date: 5 Dec 2006 09:02:44 -0800 Subject: win32 com problem In-Reply-To: <1165318486.142658.248590@f1g2000cwa.googlegroups.com> References: <1165316228.944095.116310@79g2000cws.googlegroups.com> <1165316825.234187.322900@73g2000cwn.googlegroups.com> <1165317133.730386.193290@l12g2000cwl.googlegroups.com> <1165318486.142658.248590@f1g2000cwa.googlegroups.com> Message-ID: <1165338163.886874.29200@n67g2000cwd.googlegroups.com> No Problem, Thanks for your help so far, i've sent this problem off to SPSS as it seems it doesn't work on a work colleagues machine either Thanks for your time though Mike From max at alcyone.com Sat Dec 30 16:19:28 2006 From: max at alcyone.com (Erik Max Francis) Date: Sat, 30 Dec 2006 13:19:28 -0800 Subject: python , Boost and straight (but complex) C code In-Reply-To: References: Message-ID: <0d2dnZZ8as4TSgvYnZ2dnUVZ_q_inZ2d@speakeasy.net> Osiris wrote: > I have these pieces of C-code (NOT C++ !!) I want to call from Python. > I found Boost. > I have MS Visual Studio 2005 with C++. > > is this the idea: > I write the following C source file: > ============================ > #include > #include > > namespace { // Avoid cluttering the global namespace. iostream and namespaces are both most definitely C++ features, not C. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis It's almost like / I didn't even have a choice -- India Arie From basti.wiesner at gmx.net Wed Dec 20 07:28:59 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 20 Dec 2006 13:28:59 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <1166394345_23949@sp6iad.superfeed.net> <1166442477.818748.324370@f1g2000cwa.googlegroups.com> Message-ID: Marc 'BlackJack' Rintsch schrieb > In , Sebastian 'lunar' Wiesner > wrote: > >> Gabriel Genellina schrieb >>> A similar function exists on Linux too. But even if a file has the >>> right file format, if it does not have the execute bit set, won't >>> run. And you could set that bit on a JPG image too - and nothing >>> good would happen, I presume. >> >> Really? I don't think so. Afaik on Linux executable binary files need >> an ELF header. > > There are other executable loaders for `a.out` and `COFF` in the > kernel, and with the `binfmt_misc` module you can make anything with a > "magic" header executable, including Python scripts/bytecode and even > JPEG images. Yes, I know... But ELF is actually the most common linker format on Linux systems. a.out is a legacy format, that is afaik not used by any modern distribution. Concerning COFF I'm not sure, if there is really a COFF loader in the kernel. At least I did not find any information about such a loader in the kernel configuration. It just lists elf, a.out and binfmt_misc. But basically you're right. One could even write a loader for JPEG files. But as long as such an loader is not part of a standard linux distribution, nothing bad happens when you try to execute a JPEG file, and that's what I wanted to point out. Sebastian -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From yao1337 at gmail.com Sun Dec 3 21:07:06 2006 From: yao1337 at gmail.com (purple) Date: 3 Dec 2006 18:07:06 -0800 Subject: How to realize the interactive python in Eclipse? In-Reply-To: <1165195009.650668.130470@j44g2000cwa.googlegroups.com> References: <1165068796.417513.86280@n67g2000cwd.googlegroups.com> <1165195009.650668.130470@j44g2000cwa.googlegroups.com> Message-ID: <1165198026.908008.77540@79g2000cws.googlegroups.com> Thank you for your website. I used to work with the python shell, but it is quite boring in managing the files, so I know the eclipse and pydev. I think I should focus on the documentations first. Thank you very much. > > I am beginning to wonder if you attempting to use PyDev as nothing more > than a programmer's editor. PyDev is a lot more. You need not debug > this way since it includes a visual debugger. Be sure to read the > documentation at the web site. > > http://pydev.sourceforge.net/debug.html > http://pydev.sourceforge.net/faq.html From luxnoctis at gmail.com Thu Dec 28 23:05:41 2006 From: luxnoctis at gmail.com (luxnoctis at gmail.com) Date: 28 Dec 2006 20:05:41 -0800 Subject: A stupid question In-Reply-To: References: <1167362866.807346.73510@73g2000cwn.googlegroups.com> Message-ID: <1167365141.757827.43670@48g2000cwx.googlegroups.com> It says exactly: The specified module could not be found. LoadLibrary(pythondll) failed Don't know if that helps at all. Gabriel Genellina wrote: > At Friday 29/12/2006 00:27, luxnoctis at gmail.com wrote: > > >I bought a floor model computer, and it came with all sorts of > >ridiculousness on it that I promptly uninstalled. However, now whenever > >I start windows I get a message saying "LoadLibrary (pythondll > >) failed." It also says this when I try to download into a bittorrent > >client, and it keeps it from downloading. What does this mean, and how > >can I make it go away? > > Please copy the *exact* message that you see. > python24.dll (or 23, or 25) is a shared component, installed on the > system directory. If you delete it, you break all applications > depending on it, like the bittorrent client. > > > -- > 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 From huayang.xia at gmail.com Tue Dec 19 11:15:51 2006 From: huayang.xia at gmail.com (Huayang Xia) Date: 19 Dec 2006 08:15:51 -0800 Subject: When Closure get external variable's value? In-Reply-To: References: <1166473333.593246.238580@73g2000cwn.googlegroups.com> <1166474513.700608.201760@48g2000cwx.googlegroups.com> <1166542026.913912.82880@t46g2000cwa.googlegroups.com> Message-ID: <1166544951.721977.281100@t46g2000cwa.googlegroups.com> That is a really concise and precise answer. Thanks. So the object binding can only happen explicitly at the closure declaration argument list(non-free variable). On Dec 19, 10:37 am, Fredrik Lundh wrote: > Huayang Xia wrote: > > When does the closure get the value of the maxIndex in the following > > code snippet? > > > def testClosure(maxIndex) : > > > def closureTest(): > > return maxIndex > > > maxIndex += 5 > > > return closureTest() > > > print testClosure(10) > > > I thought it should be 10 instead of 15. That was wrong.free variables in an inner scope bind to variables in the outer scope, > not objects. > > if you want to bind to objects, use explicit binding: > > def closureTest(maxIndex=maxIndex): > return maxIndex > > From aahz at pythoncraft.com Sat Dec 9 19:28:39 2006 From: aahz at pythoncraft.com (Aahz) Date: 9 Dec 2006 16:28:39 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xac1wr7t9.fsf@ruckus.brouhaha.com> Message-ID: In article <7xac1wr7t9.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > >I think an editing program that balances parens automatically is near >indispensible for writing Lisp code. I can't stand writing Lisp >without Emacs. And that is why I will never write Lisp. I loathe Emacs. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Member of the Groucho Marx Fan Club From mail at microcorp.co.za Sun Dec 10 04:29:24 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 10 Dec 2006 11:29:24 +0200 Subject: Interacting with keyboard LEDs References: <1165641507.187794.115360@l12g2000cwl.googlegroups.com> <1165689183.812932.56980@80g2000cwy.googlegroups.com> Message-ID: <029d01c71c3d$c92b7640$03000080@hendrik> "Chris Lasher" wrote: 8<------------------------------- > interact with the LEDs. The xlib package looks promising, though. One > thing I don't understand is the 32-bit mask. How does this represent > the LED states? I profess my ignorance. not sure if this will be of any use - but when you talk to the keyboard, then on the wire, the bits are in a byte as follows: LEDS EQU GBITS1 ;LEDS FOR OUTPUT TO KEYBOARD SCROLL_LOCK_BIT EQU LEDS.0 ; - least significant bit NUM_LOCK_BIT EQU LEDS.1 ; - bit 1 CAPS_LOCK_BIT EQU LEDS.2 ; - bit 2 They are set following a mode indicator command to the keyboard which is 0xED I just happen to know this because we made a funny keyboard wedge box once. Haven't a clue about how xlib achieves this, though... - Hendrik From carsten at uniqsys.com Thu Dec 28 11:02:41 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Thu, 28 Dec 2006 11:02:41 -0500 Subject: How to return a simple variable from a function (still newbie) ? In-Reply-To: <4593E2A6.6030804@eventuallyanyway.com> References: <4593E2A6.6030804@eventuallyanyway.com> Message-ID: <1167321761.3394.43.camel@dot.uniqsys.com> On Thu, 2006-12-28 at 15:28 +0000, Paul Hummer wrote: > You'd have to either pass the variables by reference into the function, [...] In Python, all function calls are call by reference. Period. The key difference between Python and other programming languages is in the behavior of the assignment statement. To paraphrase http://effbot.org/zone/python-objects.htm : In C/C++, assignments modify objects by copying the value from the right hand side into the memory allocated to the object on the left hand side. In Python, assignments modify namespaces by making the name on the left hand side become a reference to the object on the right hand side. It is irrelevant whether the name referred to some other object before the assignment, and it is irrelevant whether that object is mutable or not. The only way to achieve call-by-reference-like behavior in the "assignment modifies objects" sense is by passing a reference to a mutable object and then invoking the object's methods to mutate it. Maybe that's what you meant, but that wasn't clear from what you said. -Carsten From http Tue Dec 12 06:33:32 2006 From: http (Paul Rubin) Date: 12 Dec 2006 03:33:32 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u18tpF166u62U1@mid.individual.net> <4u4qoaF15uds8U2@mid.individual.net> <4u6meeF161jbqU1@mid.individual.net> Message-ID: <7xr6v5xsab.fsf@ruckus.brouhaha.com> I V writes: > > Also, Python does not support a functional style of programming so the > > line is the only meaningful textual entity. In this sense the > > primitiveness of Python makes editing easier. > > Why do you say that? Wouldn't a block in python be a "meaningful textual > entity" in the same way a lisp form would be? You normally wouldn't refactor Python code by moving an indented block to the inside of an expression. That is done all the time in Lisp. From __peter__ at web.de Wed Dec 13 13:13:38 2006 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Dec 2006 19:13:38 +0100 Subject: Logging module: problem with some mapping keys References: <1166029343.340490.163490@79g2000cws.googlegroups.com> Message-ID: Tekkaman wrote: > I'm getting a strange behaviour from the "pathname" and "lineno" > formatter mapping keys. Instead of my file and my line number I get: > > /usr/lib/python2.4/logging/__init__.py > > as the file, and 1072 as the line number. I set up my config as > follows: > > logBaseConf = { > 'level' : logging.DEBUG, > 'format' : "%(levelname)-8s|%(asctime)s|%(pathname)s, > %(name)s, line %(lineno)s|%(message)s", > 'datefmt ': '%d %b %Y, %H:%M:%S', > 'filename': 'logtest.log', > 'filemode': 'a' > } > logging.basicConfig(**logBaseConf) > > I'm not using any executable-generating tools such as cx_Freeze or > Psyco. In fact, I'm getting this error on a very basic script with the > specific purpose of testing the logging module capabilities. > > Thanks in advance for any contribution. An evil symlink, maybe? $ ln -s /usr/local/lib/python2.4/logging $ python [snip] >>> import logging >>> logging.basicConfig(format="%(pathname)s") >>> logging.getLogger().critical("yadda") /usr/local/lib/python2.4/logging/__init__.py >>> $ rm logging $ python [snip] >>> import logging >>> logging.basicConfig(format="%(pathname)s") >>> logging.getLogger().critical("yadda") Peter From fredrik at pythonware.com Thu Dec 7 08:59:56 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 7 Dec 2006 14:59:56 +0100 Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> Message-ID: Stephen Eilert wrote: > I do think that, if it is faster, Python should translate > "x.has_key(y)" to "y in x". http://svn.python.org/view/sandbox/trunk/2to3/fix_has_key.py?view=markup From fredrik at pythonware.com Sat Dec 23 02:43:12 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Dec 2006 08:43:12 +0100 Subject: scopes of local and global variable In-Reply-To: <87psabcvlc.fsf@pyenos.pyenos.org> References: <87tzzncx59.fsf@pyenos.pyenos.org> <87psabcvlc.fsf@pyenos.pyenos.org> Message-ID: Pyenos wrote: > does class WORK inherit t_len=0 from line1? > > does def getwork() inherit t_len=0 from line1? > > does def formattable(table_to_process,type) inherit t_len=0 from line1? > > does def format_t() inherit t_len=0 from line1? you may want to read the documentation: http://docs.python.org/ref/naming.html From rpdooling at gmail.com Tue Dec 12 09:59:58 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 12 Dec 2006 06:59:58 -0800 Subject: How do I edit a PythonWin path to import custom built modules??? In-Reply-To: <1165917988.141401.195050@16g2000cwy.googlegroups.com> References: <1165834567.956266.24480@j72g2000cwa.googlegroups.com> <1165850571.131438.185940@l12g2000cwl.googlegroups.com> <1165912704.390252.184260@n67g2000cwd.googlegroups.com> <1165917988.141401.195050@16g2000cwy.googlegroups.com> Message-ID: <1165935598.701360.101390@f1g2000cwa.googlegroups.com> Gabriel Genellina wrote: > > There was an error in a previous post, you should create a variable > called PYTHONPATH, not change the system PATH. > Or, group your modules into packages and put them below > lib\site-packages. > Perhaps your way works also, but I have no PythonPath defined in system variables on Windows XP. I keep my Python scripts and modules in d:\Python. I added d:\Python to the Path variable and I can call and import the scripts and modules from anywhere I please. I'm pretty sure that the ActiveState distribution of Python adds its paths to the Path variable also. rd From mail at microcorp.co.za Mon Dec 25 03:19:35 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Mon, 25 Dec 2006 10:19:35 +0200 Subject: Use a Thread to reload a Module? References: <312cfe2b0612221516x295949b5ka3f422d8bb41d5b@mail.gmail.com><012b01c72662$b413de80$03000080@hendrik><312cfe2b0612231704o56a6d6b8l82d8594268f0b71f@mail.gmail.com><00f801c7271d$9feb95e0$03000080@hendrik> <312cfe2b0612232226l4046d357td4770b44882dc832@mail.gmail.com> Message-ID: <000001c727fe$d637b520$03000080@hendrik> "Gregory Pi?ero" wrote: To: "Hendrik van Rooyen" On 12/24/06, Hendrik van Rooyen wrote: > "Gregory Pi?ero" wrote: ... > open( filename[,flag='c'[,protocol=None[,writeback=False[,binary=None]]]]) > > Open a persistent dictionary. The filename specified is the base filename for > the underlying database. As a side-effect, an extension may be added to the > filename and more than one file may be created. By default, the underlying > database file is opened for reading and writing. The optional flag parameter has > the same interpretation as the flag parameter of anydbm.open. > > hth - Hendrik So how is that better than using marshal as I am now? Is it faster to load? Perhaps I could do speed tests to compare. -Greg I doubt it - originally I asked the question about a persistant dict because I thought that the scheme of periodically updating your live data could fruitfully be replaced by a "trickle" updating scheme to keep the stuff in better sync, rather than taking big lumps at a time... This may or may not be feasible - depends on what you are actually doing and if it can in fact be updated a little bit at a time instead of in a large lump at longer intervals. - Hendrik From kirby.urner at gmail.com Sun Dec 10 18:52:56 2006 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: 10 Dec 2006 15:52:56 -0800 Subject: Defending Computer Math in USA Public Schools Message-ID: <1165794776.365597.78670@79g2000cws.googlegroups.com> Cyber-curricula have a leveling aspect, as kids nearer Katrina's epicenter tune in and bliss out on 'Warriors of the Net' (why wait for stupid big dummy textbooks to catch up?). They feel more empowered by Python and Ubuntu than by any King's English I'd warrant, given how the latter has been dumbed down (slowed, degraded) by unimaginative bankers who can't fathom open source and its math-teaching significance to our digitally savvy ethnicities. --- Kirby Urner http://www.cs.haverford.edu/ Any of you stateside tracking our 'Math Wars' know there's a movement afoot to legislate excellence through politicized standards bodies, with parents encouraged to push their "math militancy" into the foreground as a chief concern for local politicians to grapple with. I editorialize against this trend at my Oregon Curriculum Network website, in part because I'm leery of state standards becoming boring clones of one another, reaching an apex in some National Standard that's as dangerously obsolete and unimaginative as most pre-college math teaching today. Here's a link to said editorial: http://www.4dsolutions.net/ocn/editorial.html I'm especially suspicious of the inertia behind indefinitely continuing this pre-college focus on climbing Calculus Mountain (as in getting over it), with little attention given to the regional and/or ethnic differences that might argue against such totalitarian uniformity. Calculus is not the be all end all mathematical machinery in every walk of life, and I say this as a former full time high school math teacher who taught AP Calc proficiently, had many success stories (OK, so I'm not famous like Jaime Escalante, who cares? http://www.imdb.com/title/tt0094027/ ) Here in the Silicon Forest, it's the discrete math of computer science that excites many students, is their ticket to hands-on access to the defining toyz of our region, i.e. flatscreens, CPUs, one computer per child, a shared classroom projector, and with a fat bandwidth pipe to/from the Internet. Our math students would like the option of specializing in computer languages and algorithms rather earlier than is traditional, as a part of that very important self-casting and self-scripting that goes on in one's formative years. They've told me this to my face. I'm not just making this up. How are students to realistically decide if a future in computer science is really for them, if all the schools' resources have been diverted by narrowing requirements that coercively force kids *away* from more experimental approaches that might center around Python, neighboring agiles, as notations of choice? Here's what a college level math or philosophy course of the future might look like, if we don't kowtow to the calculus moguls, other vote-seeking piggybackers treating the math wars like some private popularity contest: def checkbucky(n): """ http://www.rwgrayprojects.com/synergetics/s02/p2000.html """ return 10 * sum([i**2 for i in range(1, n+1)]) + 2*(n) + 1 >>> [checkbucky(i) for i in range(10)] [1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869] >>> def checkoeis(n): """ http://www.research.att.com/~njas/sequences/A005902 """ return (2*n+1)*(5*n**2+5*n+3)/3 >>> [checkoeis(i) for i in range(10)] [1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869] One strategy to combat the dumbing down state standards movement is to encourage local institutions of higher learning to reassert their ability to offer guidance. Follow the example of MIT and open source more curriculum materials, both as a recruting tools and as a models for classroom teachers seeking ideas for lesson planning. Faculties should advertise standards proposals, not leave it to state governments to appropriate the Ivory Tower's historic prerogatives. California is a good example of where Oregon might be headed, if we don't apply the brakes. Given how upper level math professors typically leave the lower levels to non-mathematician education specialists, a few overbearing types, flaunting their credentials, have managed to muscle their way in to the legislative process, while encouraging their counterparts across the land to do likewise. These activist math warriors like to fly the "anti-fuzzy math" banner as a rallying point, but offer only "turn back the clock" solutions in case of victory, all of them bereft of much computer language exposure, e.g. minus any Python + VPython fractals, or vector arithmetic. In Portland, defending our freedom to explore alternative, more futuristic curricula, means focusing on the existing relationships between Portland's public schools and its Portland State University. We also have our Institute for Science, Engineering and Public Policy (isepp.org), a think tank with a reputation for keeping our students ahead of the curve. And last but not least, we have Saturday Academy (saturdayacademy.org), an institution created by Silicon Forest executives in the last generation (23 years ago), and with a similar mission: to protect future career opportunities from encroachment by mediocre and/or simply unsuitable curriculum imports. We have a knowledge-based economy to protect. We can't afford to be "just like everyone else" when it comes to mathematics and engineering. Python should already be much stronger in our region, given its many advantages, especially over calculators. Computer science already suffers the disadvantage of being an elective, with its teachers dispersed to cover music or gym, required math courses, whenever the school's budget tightens. Further straitjacketing the math curriculum to forever lock in some "one size fits all" formula, will only add to the delay and further frustrate Python's potential widespread adoption by eager beaver students. Kirby Urner Oregon Curriculum Network 4dsolutions.net/ocn/ From JShrager at gmail.com Fri Dec 8 19:14:44 2006 From: JShrager at gmail.com (JShrager at gmail.com) Date: 8 Dec 2006 16:14:44 -0800 Subject: merits of Lisp vs Python In-Reply-To: <7xslfqar7v.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> Message-ID: <1165623284.242403.295140@l12g2000cwl.googlegroups.com> Paul Rubin wrote: > "Mark Tarver" writes: > > Thanks; a quick read of your reference to Norvig's analysis > > > > http://norvig.com/python-lisp.html > > > > seems to show that Python is a cut down (no macros) version of Lisp > > with a worse performance. The only substantial advantage I can see is > > that GUI, and Web libraries are standard. This confirms my suspicion > > that Lisp is losing out to newbies because of its > > lack of standard support for the things many people want to do. > > There is (IMO) some truth to that, but the flavor of Python > programming is not that much like Lisp any more. Especially with > recent Python releases (postdating that Norvig article) using iterator > and generator objects (basically delayed evaluation streams) more > heavily, Python is getting harder to describe in Lisp terms. It's > moving more in the direction of Haskell. Sorry, I missed something here. Why do you need a release to have these sorts of things? Can't you just expand the language via macros to create whatever facility of this sort you need... Oh, sorry. You CAN'T expand the language.... Too bad. I guess waiting for Guido to figure out what Fits Your Mind is part of The Python Way. From Bulkan at gmail.com Tue Dec 26 07:52:30 2006 From: Bulkan at gmail.com (placid) Date: 26 Dec 2006 04:52:30 -0800 Subject: Formatting a string to be a columned block of text In-Reply-To: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> References: <1167135267.746094.188070@h40g2000cwb.googlegroups.com> Message-ID: <1167137549.980492.110460@i12g2000cwa.googlegroups.com> Leon wrote: > Hi, > > I'm creating a python script that can take a string and print it to the > screen as a simple multi-columned block of mono-spaced, unhyphenated > text based on a specified character width and line hight for a column. > For example, if i fed the script an an essay, it would format the text > like a newspaper on the screen. Text processing is very new to me, any > ideas on how I could achieve a multi-columned text formatter. Are there > any libraries that already do this? > > Thanks and happy holidays! > Leon I did something similar, read in text file format it to 79 characters and print it out to a multiple images of 480x272 so i could read them on my PSP. Anyway the code to handle the formatting (even though this is one column of 78 characters with one character space from the top and bottom, and sides) corpus = open("essay.txt","r") wordcount = 0 pctline = "" pctlines = [ for line in corpus.readlines(): # i dont need the newline character as it will be printed onto images line = line[:-1] # i want individual words where each word is separated by a space character words = line.split(" ") for word in words: if wordcount + len(word) + 1 < 78: wordcount = wordcount + len(word) + 1 pctline = pctline + word + " " else: wordcount = len(word) pctlines.append(pctline) pctline = None pctline = word + " " corpus.close() what it does is keeps a list of words and iterate through it and see if the length of that word and one space character and the line doesn't exceed 78, if it doesnt then add it to the pctlines, add the count to the wordcount + 1. If it does then we have one line either 78 characters long or less and add it to pctlines which is a list of all the lines. Hope this helps. Cheers From kentilton at gmail.com Sat Dec 9 15:57:24 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 15:57:24 -0500 Subject: merits of Lisp vs Python In-Reply-To: <874ps423sx.fsf@thalassa.informatimago.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Pascal Bourguignon wrote: > Kirk Sluder writes: > > >>In article <1165689545.676886.289150 at j44g2000cwa.googlegroups.com>, >> "mystilleef" wrote: >> >> >>>1). More and better mature standard libraries (Languages don't matter, >>>libraries do). >> >>.... >> >>>On Lisp Macros: >>> >>>I think they are overrated, and in general cause more harm than good. >>>It's the reason I find Lisp-like programs difficult to grok, maintain >>>and extend. Cos every smart ass wants to needlessly write his own mini >>>language to the point of absolute obfuscation. Naturally, I'm supposed >>>to be awed by his mischievous cleverness. >> >>I've not seen a convincing explanation as to why imported macros >>from some library are so much more evil than imported functions. In >>both cases one might have to dig into documentation and/or comments >>to understand exactly what that imported snippit is doing. > > > And the difference with a library function is? Uh, that was his point. And if you all dig back thru this thread you will find me quoting GvR on the difference, which is (paraphrasing) "with macros you do not even know where the function calls are". I think he is talking about a loop-like erection of a new language. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Fri Dec 1 09:31:33 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Fri, 01 Dec 2006 15:31:33 +0100 Subject: I/O Multiplexing and non blocking socket References: <1164982048.938862.228890@79g2000cws.googlegroups.com> Message-ID: <4tasm5F132egtU1@mid.individual.net> Salvatore Di Fazio wrote: > I'm looking for a tutorial to make a client with a i/o > multiplexing and non blocking socket. > > Anybody knows where is a tutorial? Perhaps a bit of an overkill, but try this: http://twistedmatrix.com/projects/core/documentation/howto/clients.html Regards, Bj?rn -- BOFH excuse #30: positron router malfunction From jonc at icicled.net Thu Dec 14 00:19:34 2006 From: jonc at icicled.net (Jonathan Curran) Date: Wed, 13 Dec 2006 23:19:34 -0600 Subject: speed of python vs matlab. In-Reply-To: <1166054840.646029.265880@73g2000cwn.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> Message-ID: <200612132319.34551.jonc@icicled.net> On Wednesday 13 December 2006 18:07, Chao wrote: > I've been trying to develop some numerical codes with python, however > got disappointed. > > A very simple test, > > a = 1.0 > > for i in range(1000): > for j in range(1000): > a = a+1 > > unfortunately, it took 4.5 seconds to finish(my machines is fine. P4 > 3.0G, 1G RAM, it varies according to machine configuration, but should > be in the same level) > > for matlab, the same operation took 0.1 seconds, > > I use numpy & scipy, they solve the problem most of the times, but > there are cases you can't avoid loops by vectors. I appreciate the > elegancy of python so much, but I guess I have to gave it up in these > numerical codes.(image processing algorithms), for application > dev/scripting, it's still my first choice. > > A good news is that the same code takes ruby 9.8 seconds. [icicled at A3200 ~]$ time python foo # where foo contained your exact code real 0m0.469s user 0m0.443s sys 0m0.017s 4.5 seconds? ouch. I've got somewhere near 1 second. Something sounds a little fishy b/c my machine is an AMD 3200+ (2.2GHz) w/ 1GB RAM. Yours is a lot faster in terms of clock speed. Anyway, do take a look at some of the available python compilers. They should help considerably. - Jonathan From tomas at fancy.org Tue Dec 26 12:40:21 2006 From: tomas at fancy.org (Tom Plunket) Date: Tue, 26 Dec 2006 09:40:21 -0800 Subject: Installing python.org distro over ActivePython? Message-ID: Hey gang- I just ran into the fabled "Secure Sockets not enabled in ActivePython," and the ActiveState FAQ says I should just grab _ssl.pyd from "somewhere", offering up the python.org distribution as a possible source. I'm on 2.4 at this time, and python.org has what appears to be a considerably newer release than ActiveState in the first place, so I was wondering if I could just install this entire package right over the ActiveState installation, and everything would Just Work? thanks, -tom! -- From stuart at bmsi.com Sat Dec 9 11:15:02 2006 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sat, 09 Dec 2006 11:15:02 -0500 Subject: Driver selection References: <1165642541.222433.162640@l12g2000cwl.googlegroups.com> Message-ID: On Fri, 08 Dec 2006 21:35:41 -0800, Gabriel Genellina wrote: > On 9 dic, 00:53, "Stuart D. Gathman" wrote: >> Or you can modify the source to "from drivermodule import DNSLookup". >> >> What is the friendliest way to make this configurable? Currently, users >> are modifying the source to supply the desired driver. Yuck. I would >> like to supply several drivers, and have a simple way to select one at >> installation or run time. > > You can store the user's choice in a configuration file (like the ones > supported by ConfigParser). > Then you can put all the logic to select and import the right function > in a separate module, and export the DNSLookup name; make all the other > parts of the application say "from mymodule import DNSLookup" pyspf is a library, not an application. It would be nasty to make it have a config file. We already have "from pydns_driver import DNSLookup" in the pyspf module. If only users could import *for* a module from *outside* the module. I suppose you can do something like this: app.py: import spf # select dnspython driver for spf module from spf.dnspython_driver import DNSLookup spf.DNSLookup = DNSLookup del DNSLookup ... That is ugly. I'm looking for better ideas. Is there a clean way to make a setdriver function? Used like this, say: app.py: import spf spf.set_driver('dnspython') ... Can a function replace itself? For instance, in spf.py, could DNSLookup do this to provide a default: def set_driver(d): if d == 'pydns': from pydns_driver import DNSLookup elif d == 'dnspython': from dnspython_driver import DNSLookup else: raise Exception('Unknown DNS driver') def DNSLookup(name,t): from pydns_driver import DNSLookup return DNSLookup(name,t) -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From riklaunim at gmail.com Mon Dec 4 15:25:03 2006 From: riklaunim at gmail.com (riklaunim at gmail.com) Date: 4 Dec 2006 12:25:03 -0800 Subject: Python bindings for RCS apps In-Reply-To: <1165261772.483822.136010@f1g2000cwa.googlegroups.com> References: <1165256344.935217.229680@j72g2000cwa.googlegroups.com> <1165261772.483822.136010@f1g2000cwa.googlegroups.com> Message-ID: <1165263903.115760.62710@79g2000cws.googlegroups.com> I want some RCS for document management which could be controlled by python :) a bit like a wiki. From justask at acme.com Sun Dec 17 19:01:04 2006 From: justask at acme.com (Vincent Delporte) Date: Mon, 18 Dec 2006 01:01:04 +0100 Subject: Good Looking UI for a stand alone application References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> Message-ID: On Sun, 17 Dec 2006 09:37:04 +0100, luc at honk-honk.com (Luc Heinrich) wrote: >Crossplatform toolkits/frameworks suck. All of them. No exception. If >you want your app to look *AND* feel great on all platform, abstract the >core of your application and embed it in platform native GUI code. +1. Applications beyond very basic GUI's are better off rewriting the GUI for each application, while keeping the business logic separate. Even something as basic as QuickTime sucks on Windows. I'd be curious to see the source code to Skype: I just installed the Linux version, and it looks very nice. Maybe it was recompiled with Kylix. From john.thingstad at chello.no Mon Dec 18 01:41:14 2006 From: john.thingstad at chello.no (John Thingstad) Date: Mon, 18 Dec 2006 07:41:14 +0100 Subject: merits of Lisp vs Python References: <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <1166412194.206364.73270@f1g2000cwa.googlegroups.com> <7xhcvtkhlc.fsf@ruckus.brouhaha.com> <1166414958.576783.149710@j72g2000cwa.googlegroups.com> <7xodq1hm3e.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 18 Dec 2006 05:19:49 +0100, > wrote: > xscottg at gmail.com writes: >> So don't (poke (random) value). That would be obvious to anyone >> capable of writing a device driver in C or Lisp or Oberon or .... > > Similarly in C programs, don't do > > *random = 0; > > Avoiding that is easier said than done. C programs suffer endless > bugs of that type. Don't know where you get that idea. I have used a bounds checker in C++ since 1990.. If I set a pointer to a space on the heap that isn't allocated I would get a error. If I forgot to deallocate it it would warn me when the program terminates. Then I just jump to the place in the file where the memory reference was allocated. Admitably it could be a great problem if such tools weren't available, but that hasn't been the case in years. Much worse are buffer overflow errors. Functions that don't check buffer constraints. But then most modern compilers can turn that on too. Wanna overwrite the return stack. A cookie at the end checks for this as well. As for old libraries like string(s) modern replacement's are available that check constraints. For that matter C++'s type checks are much stricter than C's. In fact it hasn't been much a problem for a long time. (Debugging template error's now that is a pain..) Incremental linkers and fast compiler time also makes incremental developement possible. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From maheh_saied at yahoo.com Wed Dec 6 11:41:42 2006 From: maheh_saied at yahoo.com (mahdieh saeed) Date: Wed, 6 Dec 2006 08:41:42 -0800 (PST) Subject: extension programing with c Message-ID: <20061206164142.99700.qmail@web53614.mail.yahoo.com> Hi I want to define extention module that connect to berkeley db. I define function for connection to berkeley db with c language in one file and define other function for create extention module that can import from python. function for connection to berkeley db is like this: name=BDB.c --------------------------------------------- #include void CreateDatabase(char *databasename){ DB *dbp ; int ret; DB_ENV *myEnv; u_int32_t env_flags; char *databasename; ret = db_env_create(&myEnv, 0); if (ret != 0) { fprintf(stderr, "Error creating env handle: %s\n", db_strerror(ret)); return -1; } env_flags = DB_CREATE |DB_INIT_MPOOL; if((ret = myEnv->open(myEnv,"env55", env_flags , 0))!=0){ fprintf(stderr, "Error open environment: %s\n", db_strerror(ret)); } db_create(&dbp,myEnv,0); dbp->open(dbp,NULL,"university",databasename,DB_BTREE,DB_CREATE,0); } --------------------------------------------------------------------------------------------------------------- function for define extention module is like this: name=importBDB.c ------------------------------------------------------------------------ #include #include CreateDatabase(char *); static PyObject *insert_data(PyObject *self,PyObject *args) { char *databasename; if (!PyArg_ParseTuple(args, "s", &databasename)) { return NULL; } CreateDatabase(databasename); Py_RETURN_NONE; } static PyMethodDef data_methods[] = { { "data", (PyCFunction)insert_data, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } }; PyMODINIT_FUNC initdata() { Py_InitModule3("data", data_methods, "My first extension module."); } ---------------------------------------------------------------------------------------------------------- my compiler is gcc and compiling it with this command: gcc -shared -I/usr/local/include/python2.4 -I/usr/local/BerkeleyDB.4.5/include \ importBDB.c BDB.c \ -L/usr/local/BerkeleyDB.4.5/lib -ldb-4.5 -o insert.so there is an error occurs like this: gcc: importBDB.c: No such file or directory gcc: -L/usr/local/BerkeleyDB.4.5/lib: No such file or directory I know problem for compiler please help me regards saeed __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpellerin at gmail.com Tue Dec 19 11:01:09 2006 From: jpellerin at gmail.com (jpellerin+nose@gmail.com) Date: 19 Dec 2006 08:01:09 -0800 Subject: python-hosting.com projects: dead? References: <1166498516.090144.28570@t46g2000cwa.googlegroups.com> <1166542383.019580.185960@73g2000cwn.googlegroups.com> Message-ID: <1166544069.898631.4310@a3g2000cwd.googlegroups.com> Fredrik Lundh wrote: > jpellerin+nose at gmail.com wrote: > > > my svn repository and tickets again. I'm sure you can understand why I > > was dismayed by this and why, unfortunately, I'll never be comfortable > > trusting my data to them again. > > not really, but maybe I've just worked with computers and human beings > long enough not to treat every little hiccup as if it were the end of > the world as we know it. You're misreading me very badly, or I'm expressing myself very poorly. Either way, you've inferred some kind of spittle-flecked freakout where I did not mean to imply one. JP From fredrik at pythonware.com Mon Dec 11 10:51:01 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Dec 2006 16:51:01 +0100 Subject: ElementTree, XML and Unicode -- C0 Controls References: <1165850683.430603.6500@79g2000cws.googlegroups.com> Message-ID: S?bastien Boisg?rault wrote: > Could anyone comment on the rationale behind > the current behavior ? Is it a performance issue, > the search for non-valid unicode code points being > too expensive ? the default serializer doesn't do any validation or well-formedness checks at all; it assumes that you know what you're doing. From rpw3 at rpw3.org Fri Dec 8 22:41:49 2006 From: rpw3 at rpw3.org (Rob Warnock) Date: Fri, 08 Dec 2006 21:41:49 -0600 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> Message-ID: <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> Paul Rubin wrote: +--------------- | Bill Atkins writes: | > This is a silly claim. What observational experience are you talking | > about? Lisp is delightfully readable. In fact, I find it more | > readable than any other language. Why do you think that is? Could it | > be because I use Lisp on a daily basis? Could that also explain why | > Python seems more readable than Lisp to you? | | Python is more readable than Lisp because it stays readable even if | you don't use it on a daily basis. +--------------- Weird. This is exactly why I use *Lisp* -- because it stays completely readable even if you don't use it on a daily basis!!! [That's also why I *don't* use Perl, except when forced to...] -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From lisa.engblom at gmail.com Tue Dec 5 08:12:41 2006 From: lisa.engblom at gmail.com (lisa.engblom at gmail.com) Date: 5 Dec 2006 05:12:41 -0800 Subject: memory error with matplot Message-ID: <1165324360.959614.55970@j72g2000cwa.googlegroups.com> Hi, I am using matplotlib with python to generate a bunch of charts. My code works fine for a single iteration, which creates and saves 4 different charts. The trouble is that when I try to run it for the entire set (about 200 items) it can run for 12 items at a time. On the 13th, I get an error from matplotlib that says it can't access data. However, if I start the program at the point it failed before it works fine and will create the charts for the next 12 before failing. I assume that I am not closing the files properly somehow or otherwise misallocating memory. I tried just reimporting pylab each iteration, but that didn't help. This is the function that creates a chart: #create and save the figure def CreateFigure(state, facility, unit, SO2, increment, year, P99): size = len(SO2) #Create Plot figure(1, figsize=(10,8)) bar(range(1, size+2), SO2, width=0.1, color='k') grid(True) xlim(0,size) ylim(0, 1.1*SO2[-1]) ylabel('SO2 [lb/hr]') heading = ConstructFigName(state, facility, unit, increment, year) title(heading) #set handles xticklines = getp(gca(), 'xticklines') xgridlines = getp(gca(), 'xgridlines') xticklabels = getp(gca(), 'xticklabels') yticklines = getp(gca(), 'yticklines') #set properties setp(xticklines, visible=False) setp(xgridlines, visible=False) setp(xticklabels, visible=False) setp(yticklines, visible=False) axhspan(P99, P99, lw=3, ec='r', fc='r') ax = gca() #P99 = str(P99) P99 = '%0.1f' % P99 text(0.01, 0.95, '99th Percentile: '+P99+' lb/hr', transform=ax.transAxes) figpath = ConstructFigPath(state, facility, unit, increment, year) savefig(figpath) close() Can you see the problem? thanks, -Lisa From pyenos at pyenos.org Fri Dec 22 19:50:16 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 11:50:16 +1100 Subject: let me simplify my question about scope of vars Message-ID: <87fyb7cu5z.fsf@pyenos.pyenos.org> "code" var=1 class CLASS: def METHOD1: def METHOD2: var+=var return var METHOD2() #line8 return var METHOD1() #line10 Q1: does class CLASS inherit var=0 from line1? Q2: does def METHOD1 inherit var=0 from line1? Q3: does def METHOD2 inherit var=0 from line1? Q3: does line8 return '2'? Q4: does line10 return '2\n2'? From rattan at cps.cmich.edu Sat Dec 30 15:47:57 2006 From: rattan at cps.cmich.edu (rattan at cps.cmich.edu) Date: 30 Dec 2006 12:47:57 -0800 Subject: find login name of user? Message-ID: <1167511677.250618.285250@v33g2000cwv.googlegroups.com> Is there a function/module to find the login name of the user under UNIX environment? -ishwar From DustanGroups at gmail.com Sun Dec 24 08:41:32 2006 From: DustanGroups at gmail.com (Dustan) Date: 24 Dec 2006 05:41:32 -0800 Subject: regular expression In-Reply-To: <4587dc54$0$18460$e4fe514c@dreader31.news.xs4all.nl> References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> <4587dc54$0$18460$e4fe514c@dreader31.news.xs4all.nl> Message-ID: <1166967692.801622.295830@n51g2000cwc.googlegroups.com> Kleine Aap wrote: > Asper Faner wrote: > > > I seem to always have hard time understaing how this regular expression > > works, especially how on earth do people bring it up as part of > > computer programming language. Natural language processing seems not > > enough to explain by the way. Why no eliminate it ? > > I.M.H.O. anyone that is not capable to grasp the concept of regular > expressions should not attempt to write computer programs at all! My > suggestion to you would be to find a job that involves working with your > hands... Your humble opinion doesn't get much ruder... Perhaps you meant "anyone that is not capable to grasp the concept of regular expressions after some experience with programming should not attempt to write computer programs at all!" Then at least newbies would have a leg to stand on. Otherwise, you're practically cutting off all entrances into the world of programming! The concept of regular expressions isn't exactly the simplest one out there. Just because you understood it immediately (which I'm guessing you did, considering your harsh response), doesn't mean others find the concept that simple. From chris.cavalaria at free.fr Wed Dec 13 04:08:36 2006 From: chris.cavalaria at free.fr (Christophe) Date: Wed, 13 Dec 2006 10:08:36 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: <457fc327$0$1038$426a74cc@news.free.fr> Robert Uhl a ?crit : > aahz at pythoncraft.com (Aahz) writes: >> Consider this: Lisp has had years of development, it has had millions of >> dollars thrown at it by VC firms -- and yet Python is winning over Lisp >> programmers. Think about it. > > The argument from popularity is invalid. French units have overtaken > standard units, Never heard of that French unit thing. Unless you talk about that archaic unit system that was in use before the metric system was created. From mystilleef at gmail.com Fri Dec 15 04:51:35 2006 From: mystilleef at gmail.com (mystilleef) Date: 15 Dec 2006 01:51:35 -0800 Subject: Conditional iteration In-Reply-To: <4580149c$0$321$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> Message-ID: <1166176294.981549.309770@73g2000cwn.googlegroups.com> This why I prefer functional programming constructs for my list/sequence processing needs. ------------------------------------------------------------------------ is_true = lambda x: x > 0 map(process_list, filter(is_true, [-2, -1, 0, 1, 2, 3, 4])) ------------------------------------------------------------------------ at wrote: > I would like to spark the discussion about the following syntax problem I > encounter. > > THE PROBLEM > > I have a lot times the following code: > > for x in [-2, -1, 0, 1, 2, 3, 4]: > if x > 0: > ... more code... > > > It is not the addional line containing 'if x > 0:' that bothers me, but the > additional indentation. > > > THE SOLUTION > > More pythonic in view would be: > > for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0: > ... more code ... > > > This blends basically > > [x for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0] > > and > > x = y if x > 0 else 10 > > > EXTENDING > > And maybe a few usefull variants, like: > > for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0 else -x: > ... more code ... > > In this case x will be 2, 1, 0, 1, 2, 3, 4. From http Wed Dec 13 03:04:21 2006 From: http (Paul Rubin) Date: 13 Dec 2006 00:04:21 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> <457d970b$0$31552$426a74cc@news.free.fr> <7xwt4y6j57.fsf@ruckus.brouhaha.com> <1165973114.451146.295110@j72g2000cwa.googlegroups.com> Message-ID: <7xmz5ste62.fsf@ruckus.brouhaha.com> Neil Cerutti writes: > Is the above 'duck-typing' idiom considered very useful to a > Lisper? It seems logical to me that duck-typing works best in an > environment where it is ubiquitous. If users have to implement > accessors specifically to use your library, it is not as good as > if they had already implemented one as a matter of routine. It's a little more complicated than that, the classes involved have to have special interfaces to tell setf/getf what to do, sort of a compile time equivalent of __setattr__/__getattr__ if I remember right. From python at hope.cz Mon Dec 4 02:14:25 2006 From: python at hope.cz (Lad) Date: 3 Dec 2006 23:14:25 -0800 Subject: Video stream server Message-ID: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> Hello, Does anybody know about a video stream server that serves up HTML pages with links to video files, and then serving out those video files. L. From hg at nospam.org Sat Dec 2 13:54:17 2006 From: hg at nospam.org (hg) Date: Sat, 02 Dec 2006 12:54:17 -0600 Subject: wxpython worked out but can't find api docs for download. References: Message-ID: <48kch.2223$YI1.104@newsfe15.lga> krishnakant Mane wrote: > hello all. > finally I got the accessibility issue out from wxpython. actually > almost got it out, but that's another story. > now my problem is that I can't gind a downloadable version of wxpython > api reference for the latest version or the latest api reference at > least. > I found the on-line version so please don't provide the same link. > when I opened it on line, it took about 8 minuts to get the wx package > come up on screen with over 600 links. > I need to have some off line reference for the wxpython api. > I have enough documentation to get started but I don't have the > extencive api references for events and other methods, properties and > attributes. > can some one point me to a .zip or .tar.gz version of the api docs for > wxpython? thanking all. > Krishnakant. http://www.wxpython.org/download.php From __peter__ at web.de Wed Dec 6 09:02:38 2006 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Dec 2006 15:02:38 +0100 Subject: dict.has_key(x) versus 'x in dict' References: <4tnvstF14cki5U1@mid.individual.net> Message-ID: Bjoern Schliessmann wrote: > Paul Melis wrote: > >> I've always been using the has_key() method to test if a >> dictionary contains a certain key. Recently I tried the same using >> 'in', e.g. >> >> d = { ... } >> if k in d: >> ... > > Wouldn't be "if k in d.keys()" be the exact replacement? No, 'k in d' is equivalent to 'd.has_key(k)', only with less (constant) overhead for the function call. 'k in d.keys()' on the other hand creates a list of keys which is then searched linearly -- about the worst thing you can do about both speed and memory footprint. Some numbers: $ python2.5 -m timeit -s"N = 1; d = dict.fromkeys(range(N))" "N in d.keys()" 1000000 loops, best of 3: 0.693 usec per loop $ python2.5 -m timeit -s"N = 1000; d = dict.fromkeys(range(N))" "N in d.keys()" 10000 loops, best of 3: 77.2 usec per loop # ouch! $ python2.5 -m timeit -s"N = 1; d = dict.fromkeys(range(N))" "N in d" 10000000 loops, best of 3: 0.192 usec per loop ~ $ python2.5 -m timeit -s"N = 1000; d = dict.fromkeys(range(N))" "N in d" 10000000 loops, best of 3: 0.192 usec per loop $ python2.5 -m timeit -s"N = 1; d = dict.fromkeys(range(N))" "d.has_key(N)" 1000000 loops, best of 3: 0.376 usec per loop $ python2.5 -m timeit -s"N = 1000; d = dict.fromkeys(range(N))" "d.has_key(N)" 1000000 loops, best of 3: 0.385 usec per loop Peter From bearophileHUGS at lycos.com Wed Dec 27 06:26:59 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 27 Dec 2006 03:26:59 -0800 Subject: loose methods : Smalltalk asPython In-Reply-To: References: Message-ID: <1167218819.389482.155350@f1g2000cwa.googlegroups.com> Steven D'Aprano: > You can't modify the built-in classes. I'm not sure that it is a good idea > to allow built-ins to be modified. When I see an int, I like the fact that > I know what the int can do, and I don't have to worry about whether it has > been modified by some piece of code elsewhere. I think it can be useful, there are many situations where you may need to change the behavior of built-in dicts, etc, but: - You need to keep code sorted and tidy to avoid problems. (This is true for most of Python code too today. For example ObjectPascal gives you less freedom to shoot yourself in the foot.) - Allowing the built-in objects to be dynamically modified like that may slow down the virtual machine some, if you don't design it quite carefully. Psyco can help here too. Bye, bearophile From brenNOSPAMbarn at NObrenSPAMbarn.net Mon Dec 4 23:48:46 2006 From: brenNOSPAMbarn at NObrenSPAMbarn.net (OKB (not okblacke)) Date: Tue, 05 Dec 2006 04:48:46 GMT Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> Message-ID: John Machin wrote: > 3. The OP asked only for values; you are asking for names and > values. If you have a magic flak jacket, please let me know; I'd > like to borrow it occasionally :-) On reflection I think my alternative suggestion might be just as good: the interpreter could indicate the character position within the line. This also handles cases where the operands aren't simple names. (Not that I have any idea how much harder/easier this would be to implement.) I ask for names and values because that is what I want. If I have some expression containing a bunch of variables and an exception is raised, the most helpful information for me is the source code token that is causing the error, because I can see the source code in my text editor. The value is not as important, because there may be many different variables that could be holding the same incorrect value. I only want to look at the one that is ACTUALLY holding the incorrect value. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From kentilton at gmail.com Tue Dec 12 20:28:08 2006 From: kentilton at gmail.com (Ken Tilton) Date: Tue, 12 Dec 2006 20:28:08 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7xodq8ty5e.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7x3b7lccjn.fsf@ruckus.brouhaha.com> <7xodq8ty5e.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Ken Tilton writes: > >>Oh, my. time to trot out my "hey, X is cool, let's use it for >>everything!" rant. > > > Somehow it's something other than a rant if X is Lisp? Ah, your discriminator misfired. Keep your eye on the bouncing rant: I was not espousing any language, I was espousing matching the tool to the task. That segued into my Lisp ball of mud rant, but, hell, even C offers iteration along with recursion. That observation turns the rant back on all-x-all-the-time languages, including I would note Steele's constraint programming language, which at first used a constraint to do variable assignment. Speaking of Cells... :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From nmm1 at cus.cam.ac.uk Sat Dec 16 08:24:10 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 16 Dec 2006 13:24:10 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> In article <4583ED06.5000104 at mbi.ucla.edu>, James Stroud writes: |> Christoph Zwerschke wrote: |> |> > "Inhomogenous" in some meaning of the word --> tuple |> |> I think that you have nailed it here. I don't think anyone on this list |> is capable of giving a "concrete" (as you have put it) operational |> definition of "inhomogenous". They will resort to use cases and thus |> cloud the definition with programming philosophy. Yes, I can. Here is one: A collection is inhomogeneous if, for some attribute that is needed for at least one action on at least one element of the collection, the attribute is not shared by all elements of the collection. Yes, this means that the concept of inhomogeneity depends on the use to which a collection is put, and not just on the collection. |> So, programming philosophy, whether it will be admitted or not, is fully |> responsible for the exclusion of index() from the tuple interface. Agreed. |> But perhaps we could take "not necessarily homogenous" to be the |> operational definition of "inhomogenous". Of course then we would have |> to define necessary... It's not necessary :-) Lists, in Python, are no more homogeneous than tuples in any sense that I have located. As I posted earlier, if anyone knows of one, please tell me. Regards, Nick Maclaren. From nagle at animats.com Sat Dec 30 02:36:19 2006 From: nagle at animats.com (John Nagle) Date: Fri, 29 Dec 2006 23:36:19 -0800 Subject: No way to set a timeout in "urllib". In-Reply-To: References: <%hglh.1141$ji1.1051@newssvr12.news.prodigy.net> Message-ID: skip at pobox.com wrote: > John> There's no way to set a timeout if you use "urllib" to open a URL. > John> "HTTP", which "urllib" uses, supports this, but the functionality > John> is lost at the "urllib" level. > > John> It's not available via "class URLopener" or "FancyURLopener", > John> either. > > John> There is a non-thread-safe workaround from 2003 at > > ... > > This topic has come up several times since timeouts were added to socket. > Each time we've asked for a patch that adds timeouts in a rational manner to > all the stuff layered on top of the socket module (httplib, ftplib, etc). As > far as I know it's apparently never been important enough for anyone to rise > to the challenge. If I remember next spring perhaps I'll submit it as a > possible Google Summer of Code proposal. It ought not to take more than a day or two, although it is annoying that you have to deal with the problem at several levels. If you're looking for a Summer of Code project, consider finishing the Python SSL library, which doesn't even check certificates, let alone revocation lists. It's a pure interface problem. OpenSSL does all the hard parts, but the Python glue code is crude and incomplete. John Nagle From kay.schluehr at gmx.net Mon Dec 11 09:57:35 2006 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 11 Dec 2006 06:57:35 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> Message-ID: <1165849055.492230.119310@n67g2000cwd.googlegroups.com> JShrager at gmail.com schrieb: > Now, speaking as a scientist, permit me to make a small practical > suggestion: Why not just figure out a way to simplify some brand of > Python -- make parens (or whatever) optionally replace whitespace and > line breaks as syntax -- and then add a simple macro facility -- macros > are actually a very simple extension if you have homogenous syntax, > homogenizing your syntax to the point where macros are possible is the > hard part -- and just see what happens. The problem is not so much to add a macro facility ( or source transformer ) but to soften it and make the macro facility actually *simple* to use. Note that you don't need to replace whitespaces. The Python parser is LL(1) and whitespace is almost completely abstracted away once the Python source was tokenized successfully ( there is exactly one non-terminal in the Python grammar, the "suite" NT, that uses INDENT and DEDENT as moral equivalents for left- and right parens ). Note also that a homogenous syntax is not that important when analyzing parse trees ( on the contrary, the more different structures the better ) but when synthesizing new ones by fitting different fragments of them together. There are two basic approaches. In one you start with a piece of source code ( a template ) and enhance the source description slightly with somewhat like template parameters that keep source fragments and expand them. In this case you also need an unquoting mechanism or a way to evaluate code within the template. The second approach acts with high level wrappers of more low level source trees ( just like ASTs are high level wrappers of concrete syntax trees in most languages ). In Python one might even use operator overloading to hide the AST structure and provide a more convenient syntax. But this only describes the transformational aspect. The definitional part is not less important. I try to consider a grammar description of a full programming language as as script in an own little language ( actually it is and the grammars grammar is often just an EBNF grammar description ). This however presumes that enhancing grammars to enhance languages is a reasonable approach not just in a Lex-Yacc ( or ANTLR ) setting. The next question concerns compositionality of language enhancements or composition of even completely independent language definitions and transformers both on source and on binary level. While this is not feasible in general without creating ambiguities, I believe this problem can be reduced to ambiguity detection in the underlying grammars. > One of two general things are > likely to happen: Either people will not use them, and they will > languish and die, and then at least you can say; "Been there, done > that" to the Lisp community. Or, more likely, the some subset of the > Python community will get it, and will figure out how useful they are, > although it might take some time. And then you might find yourself with > a wonderful new tool. I think so too. > You might even get a compiler out of the deal, at > a pretty low cost, too! If you get macros, and get a compiler, I'm > pretty sure that you will have no problem winning over the Lisp > community, who would LOVE to have your extensive libraries, and that > you will probably be able to maintain and improve your flagging > position wrt Ruby (which, according to Matz, is more-or-less just Lisp > w/o macros.) Just a moment ago you called programmers of other languages "flies" which I found annoying and now you offer LOVE in big letters? I don't even think the "competition" to Ruby matters. Once an easy to use metaprogramming system could be done for Python it could be ported with some adaptions to other languages with more "complicated syntax" ( non LL(1) parsable ). Kay From Thomas.Ploch at gmx.net Fri Dec 1 06:38:57 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Fri, 01 Dec 2006 12:38:57 +0100 Subject: python vs java & eclipse In-Reply-To: <45701422.4050206@gmx.net> References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <45701422.4050206@gmx.net> Message-ID: <45701451.1010707@gmx.net> Thomas Ploch schrieb: > Amir Michail schrieb: >> Hi, >> >> It seems to me that measuring productivity in a programming language >> must take into account available tools and libraries. >> >> Eclipse for example provides such an amazing IDE for java that it is no >> longer obvious to me that one would be much more productive in python >> for medium sized projects. >> >> Sure, all that Java static typing can be painful, but Eclipse takes >> some of that pain away. Moreover, static typing can result in better >> on-the-fly error detection and refactoring support. >> >> Any thoughts on this? >> >> Amir >> > > Yes, thats true, but since eclipse is resource monster (it is still > using java), and some people (like me) don't have a super fresh and new > computer, and have to run other services to test their work locally > (like mysql and apache servers), it gets pretty harsh with eclipse. I > personally tried eclipse on my laptop (which I work most with), and I > had quite a system resource problem. So I switched back to vim and > console and it hasn't been too bad, since if you know how to use a > powerful editor, it can be as productive. > > But in the end, it is up to anyone to find the best solutiion for > themselves. > > Thomas > Yes, thats true, but since eclipse is resource monster (it is still using java), and some people (like me) don't have a super fresh and new computer, and have to run other services to test their work locally (like mysql and apache servers), it gets pretty harsh with eclipse. I personally tried eclipse on my laptop (which I work most with), and I had quite a system resource problem. So I switched back to vim and console and it hasn't been too bad, since if you know how to use a powerful editor, it can be as productive. But in the end, it is up to anyone to find the best solutiion for themselves. Thomas From jon at ffconsultancy.com Sun Dec 10 03:16:35 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 08:16:35 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: <457bc302$0$8753$ed2619ec@ptn-nntp-reader02.plus.net> Wolfram Fenske wrote: > But seriously... All the interesting features that haven't originated from > Lisp (e. g. OO from Smalltalk) could in turn easily be implemented in Lisp > with a couple of macros. I was under the impression that CLOS was non-trivial to write. There are many other interesting features that haven't originated from Lisp (e.g. pattern matching in SML, OCaml, Haskell, F#, Mathematica, ...) that cannot be implemented easily in Lisp because they are intrinsically complicated. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From mail at microcorp.co.za Thu Dec 7 01:57:53 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Thu, 7 Dec 2006 08:57:53 +0200 Subject: Mirror imaging binary numbers References: <1165440014.762774.167950@73g2000cwn.googlegroups.com> Message-ID: <024e01c719d3$de1d3b40$03000080@hendrik> "Craig" wrote: > Hi there, > > I'm trying to switch binary numbers around so that the MSB becomes the > LSB etc. Is there an easy way of doing this as I can't seem to find > anything. If you could help that would be great. Thanks and good > luck. Are these Python ints, or are they "strings of bytes of known length"? And do you really want to mirror swap the binary bits or just change the byte sequence from say big to little endian? - i.e. is MSB most significant bit, or byte? assuming bit, try this: >>> num = 12345 >>> q,r = divmod(num,2) >>> q 6172 >>> r 1 >>> l = [r] >>> while q: q,r = divmod(q,2) l.append(r) >>> l [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1] >>> ans = 0 >>> for x in l: ans = ans * 2 + x >>> ans 9987 >>> and Robert is yer aunty... - Hendrik From meyer at acm.org Wed Dec 6 03:49:37 2006 From: meyer at acm.org (Andre Meyer) Date: Wed, 6 Dec 2006 09:49:37 +0100 Subject: Python Plugin for Web Browser In-Reply-To: <695a37a00612060026s6307ace4y2c364c081bf02862@mail.gmail.com> References: <1165389943.093365.20590@80g2000cwy.googlegroups.com> <1165391969.824391.174140@l12g2000cwl.googlegroups.com> <7008329d0612060005q7c35c54aic6ad64acbff75103@mail.gmail.com> <695a37a00612060026s6307ace4y2c364c081bf02862@mail.gmail.com> Message-ID: <7008329d0612060049r214f3026rae4cb6ad1ec11148@mail.gmail.com> Hi Sebastien Yes, I am a developer, but not C/C++. I have done Java (and many other languages) in the past, but use Python nowadays. So, I am no help for developing the plugin, sorry. I would want to use it though for developing richer Web sites in Python, rather than in JavaScript/Ajax. Having said that: maybe you are also interested in pyjamas (http://pyjamas.pyworks.org/). kind regards Andr? On 12/6/06, Sebastien Ramage wrote: > > Hi > > Thank you for your reply. > Yes ! It would be very useful and easy to develop (the applet not the > plugin) ! > > I don't have real project at this time but, I like Python and use it every > day. Many time I want to make an applet for game, or webcam remote control > but I don't understand and I don't want to learn Java when I know the > powerful python. > Are you a developper? C++ ? > > Seb > > > > > 2006/12/6, Andre Meyer : > > > > Hi > > > > I was looking for something similar in the past and could not find it. > > It would be very useful to have Python applets in web pages. What would you > > use them for? > > > > kind regards > > Andr? > > > > > > > > On 5 Dec 2006 23:59:29 -0800, S?bastien Ramage > > wrote: > > > > > > des exemples de plugins pour IE oui mais qui ne sont pas embarqu? dans > > > une page Web > > > je souhaiterai cr?er qqchose qui ressemble vraiment ? Java VM ou > > > Flash > > > J'ai trouv? un d?but de r?ponse pour Firefox en t?l?charger le > > > GeckoSDK > > > mais je n'arrive pas ? compiler les exemples pour le moment... > > > > > > merci > > > > > > > > > MC a ?crit : > > > > > > > Bonjour ! > > > > > > > > Pour IE, il y a des exemples de plugins, fournis avec PyWin32. > > > > Pour FF (comme pour Opera), je ne sais pas. > > > > > > > > -- > > > > @-salutations > > > > > > > > Michel Claveau > > > > > > > > > > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > > -- > > Dr. Andre P. Meyer http://python.openspace.nl/meyer > > > > TNO Defence, Security and Safety http://www.tno.nl/ > > Delft Cooperation on Intelligent Systems http://www.decis.nl/ > > > > Ah, this is obviously some strange usage of the word 'safe' that I > > wasn't previously aware of. - Douglas Adams > > > -- Dr. Andre P. Meyer http://python.openspace.nl/meyer TNO Defence, Security and Safety http://www.tno.nl/ Delft Cooperation on Intelligent Systems http://www.decis.nl/ Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams -------------- next part -------------- An HTML attachment was scrubbed... URL: From pyenos at pyenos.org Fri Dec 22 20:19:09 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 12:19:09 +1100 Subject: let me simplify my question on scope of vars References: <877iwjcttj.fsf@pyenos.pyenos.org> Message-ID: <87vek3be9e.fsf@pyenos.pyenos.org> Pyenos writes: i will try to answer my own questions(pls verify): > "code" > var=1 > class CLASS: > def METHOD1: > def METHOD2: > var+=var > return var > METHOD2() #line8 > return var > METHOD1() #line10 > "end code" > > Q1: does class CLASS inherit var=0 from line1? yes. > Q2: does def METHOD1 inherit var=0 from line1? no. > Q3: does def METHOD2 inherit var=0 from line1? no. > Q3: does line8 return '2'? no. will get unreferenced var error. > Q4: does line10 return '2\n2'? no. will get unreferenced var error. From fredrik at pythonware.com Mon Dec 4 03:36:25 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 09:36:25 +0100 Subject: algorithm for sorting functional expressions In-Reply-To: References: <1165215032.749560.171530@16g2000cwy.googlegroups.com> Message-ID: Marc 'BlackJack' Rintsch wrote: >> So I suspect that this is a common problem for those familiar with >> partially ordered sets or directed graphs. I'm wondering if anyone else >> is familiar with this problem and knows an efficient algorithm that >> will solve it. It would be good if any such algorithm would be able to >> check for circular definitions in the input. > > You are looking for "topological sort". Feed a search engine with that > term. :-) including "python" in the search request might be a good idea. here's a topsort in Python: http://mail.python.org/pipermail/python-list/1999-July/006660.html (note that most code in that module is for analyzing cycles in case the sort fails, not for the sort itself). From rurpy at yahoo.com Mon Dec 4 19:38:28 2006 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: 4 Dec 2006 16:38:28 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: <45749D82.4040301@v.loewis.de> References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <97g7n2po9rs76splq5i2r1320olpiajq1q@4ax.com> <1165216880.864158.256730@80g2000cwy.googlegroups.com> <1165219968.619509.147990@73g2000cwn.googlegroups.com> <1165223084.558617.9570@79g2000cws.googlegroups.com> <1165250963.660087.58410@n67g2000cwd.googlegroups.com> <45745F24.2010406@v.loewis.de> <1165258556.021281.51440@79g2000cws.googlegroups.com> <45749D82.4040301@v.loewis.de> Message-ID: <1165279108.042540.251560@80g2000cwy.googlegroups.com> Martin v. L?wis wrote: > rurpy at yahoo.com schrieb: > >>> Rather, they (like I) will encourage to OP to submit > >>> a patch that fixes the problem. > >> Now, that would be rather silly. I would have to familiarize > >> myself with the code for the Python interpreter, > > > > Seems to me he called the suggestion (made without any > > knowlage of the OP's abilities regarding C and Python's > > internals) that he summit a patch, silly. > > > > I aggree. > > > > His response was well within the bounds of normal > > usenet discourse. > > Maybe I'm unusually picky, but I also feel insulted if > my suggestions are called silly - this is just like calling > myself silly. I rarely make silly suggestions deliberately > (and try to mark them as ironic in usenet if I do); so if > somebody puts them down as "silly", I'll feel insulted. > > I personally don't think it is silly to suggest that an > IT professional becomes familiar with the implementation > of the Python interpreter. That code is well-written, > well-documented, so it should be feasible (rather than > being silly) for anybody with a programming background > and sufficient determination to familiarize with that code. I think you are vastly overestimating the programming abilities of many Python users. The set of IT professionals includes a large number of people who aren't programmers at all. The set of programmers includes a large number of people who don't know C. Even for someone who knows C, there are many places in the Python code that require considerable general knowlage of Python's overall architecure and way of doing things that is not obtained without a fair bit of time spent working with the code. I think your existing familiarity with it is inteferring with your ability to make an objective judgement of this. To say a Python user should learn C, understand the internals of Python sufficiently to create a patch as a prerequisite to making a suggestion about how to improve the user experience of Python, is, I personally think, silly. > I take the same position for about any open-source software: > you *can* get into Apache, Mozilla, the Linux kernel, > and now the Java virtual machine if you want to. If you > don't, it's not because you can't, but because you don't > want to. That's stretching the meaning of "want to" quite a bit. Theere are lots of constraints on people that prevent even the technically capapable of doing that. You can write them off as not being sufficiently motivated if you want, but I don't think that is being realistic. Nor is it a good reason to disregard ideas for improving Python coming from them. > It would be unrealistic (but not silly) to suggest that > if the source code weren't available at all. It is *not* > silly to suggest that people should make efforts to > contribute to open source software. "Suggestion" covers a wide range of meanings. To politely ask someone to consider submitting a patch if they are able, with no implication of sanction if they are not is one thing. To suggest that any IT professional read and understand Python's internals or be publically castigated is something else. If I had meeting at work, and person X said I think if department Y did things this way, we could save $Z/year. Should I tell that person, "implement it yourself, or be quiet". Sorry, I don't buy that. From nick at craig-wood.com Mon Dec 18 10:30:06 2006 From: nick at craig-wood.com (Nick Craig-Wood) Date: Mon, 18 Dec 2006 09:30:06 -0600 Subject: How to replace a comma References: <1166446034.406136.225770@80g2000cwy.googlegroups.com> Message-ID: Lad wrote: > In a text I need to add a blank(space) after a comma but only if > there was no blank(space) after the comman If there was a > blank(space), no change is made. > > I think it could be a task for regular expression but can not > figure out the correct regular expression. You can do it with a zero width negative lookahead assertion, eg >>> import re >>> s="One, Two,Three,Four, File" >>> re.sub(r",(?!\s)", ", ", s) 'One, Two, Three, Four, File' >>> >From the help :- (?!...) Matches if ... doesn't match next. This is a negative lookahead assertion. For example, Isaac (?!Asimov) will match 'Isaac ' only if it's not followed by 'Asimov' Or in a more straightforward but less efficient and accurate style - this matches the next character which gets added back into the string. >>> re.sub(r",([^\s])", r", \1", s) 'One, Two, Three, Four, File' >>> This shows a fundamental difference between the two methods >>> t = ",,,,," >>> re.sub(r",(?!\s)", ", ", t) ', , , , , ' >>> re.sub(r",([^\s])", r", \1", t) ', ,, ,,' >>> -- Nick Craig-Wood -- http://www.craig-wood.com/nick From ilias at lazaridis.com Tue Dec 19 10:44:37 2006 From: ilias at lazaridis.com (Ilias Lazaridis) Date: 19 Dec 2006 07:44:37 -0800 Subject: SQLALCHEMY - Method to have the last word, by Michael Bayer Message-ID: <1166543077.605993.276770@80g2000cwy.googlegroups.com> [1] - ?/? metaperl: >>> TurboEntity was quite sweet. Supposedly a complete rewrite as a new >>> product is on its way though. Ilias Lazaridis: >>the first major problem of this rewrite: >>it happens 'silently' (non-public) Michael Bayer wrote within: http://groups.google.com/group/sqlalchemy/msg/9d7a096a61abfc6f >django was not available to the public until it was fully functional >(youd go to the site and just get a "coming soon"-style splash >page)..and even then it was already in production use in earlier forms. >they knew that if you release something that wasnt polished and would >lead to user frustration, people would get disinterested and leave. >the strategy seems to have worked for them. I understand your elaborations. Possibly "sqlalchemy" should do the same, until it's fully functional and do not 'frustrate users'. And "Turbogears", too. And Django, as it's still not fully functional (mainly due to it's deficient ORM layer). Or all those projects remain open(!), allowing users and contributors to review the source(!), in order to be able to contribute requirements, ideas, patches, sources etc.! >its not your grandfather's open source community ! Please keep relatives out of discussions. - [1] Continueing a thread from "sqlalchemy group) within comp.lang.python (closest public usenet group), because "Michael Bayer" has closed the thread within google.groups (no reply possible to anyone) prior to enabling my answer to his message. http://groups.google.com/group/sqlalchemy/msg/841b3b14d8108ac0 . -- http://dev.lazaridis.com/base From bdesth.quelquechose at free.quelquepart.fr Mon Dec 18 06:34:30 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 18 Dec 2006 12:34:30 +0100 Subject: Metaclass uses? In-Reply-To: References: Message-ID: <45867710$0$19274$426a34cc@news.free.fr> Nathan Harmston a ?crit : (snip) > Also is there anymore interesting OO stuff that Python has apart from Java. Quite a lot. Everything (well, except statements and expressions...) in Python is an object, including classes, modules and functions, and Python objects are really 'dynamic', ie you can modify them at runtime - and when I say 'modify', I mean things like adding/replacing/removing attributes, including methods and class (which are attributes too...). From jtgalkowski at alum.mit.edu Tue Dec 26 22:49:30 2006 From: jtgalkowski at alum.mit.edu (Jan Theodore Galkowski) Date: Tue, 26 Dec 2006 22:49:30 -0500 Subject: loose methods : Smalltalk asPython Message-ID: <1167191370.20542.282089833@webmail.messagingengine.com> Hi. One of the things I'd like to do with Python is find a way to consistently implement Smalltalk's "loose methods". This is a capability whereby additional methods can be added dynamically to existing classes. In some respects, it's possible with Python. While "object" cannot be touched, it's possible to define class MutableObject( object ) : pass ; and derive subclasses from MutableObject instead of object. Thereafter, for instance, if devising a class class Foo( MutableObject ) : isFoo = True ; ... you can also put in its module MutableObject.isFoo = False ; So, at least for the inheritance hierarchy descending from MutableObject, for an arbitrary object instance x, x.isFoo will return whether it's a Foo or not, effectively although not transparently extending the builtin type(.). Like, then, what of other classes which descend from object and not MutableObject? You'd love to be able to set methods and attributes within them. Can you? These provide on-the-spot extensions of their capability without having to subclass them (not such a big deal) or get everyone to use the new subclass (a very big deal). Comments? Suggestions? Thanks, -- Jan From kkylheku at gmail.com Thu Dec 14 15:32:46 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 14 Dec 2006 12:32:46 -0800 Subject: merits of Lisp vs Python In-Reply-To: <458157fd$0$2119$426a34cc@news.free.fr> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <457f1a42$0$8414$426a74cc@news.free.fr> <458157fd$0$2119$426a34cc@news.free.fr> Message-ID: <1166128366.419921.166760@80g2000cwy.googlegroups.com> Bruno Desthuilliers wrote: > Andr? Thieme a ?crit : > > Bruno Desthuilliers schrieb: > > > (snip) > >> Both are highly dynamic. Neither are declarative. > > > > > > Well, Lisp does support some declarative features in the ansi standard. > > If you go that way, there are declarative stuff in Python too... But > neither Lisp nor Python are close to, say, SQL. False. Common Lisp can be made to support SQL syntax. From python-url at phaseit.net Mon Dec 4 14:12:01 2006 From: python-url at phaseit.net (Paul Boddie) Date: Mon, 4 Dec 2006 19:12:01 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Dec 4) Message-ID: QOTW: "We of all people should understand Worse Is Better. And I forgot to mention a little flash in the pan called Python, for which Tkinter (2+2 left as an exercise) is the GUI of choice." - Ken Tilton (on comp.lang.lisp, perhaps stretching the meaning of "of choice" somewhat) http://groups.google.com/group/comp.lang.lisp/msg/4d4945fb2706fc24 "It isn't that mobile platforms speak a different language to the web: they're perfectly capable of running AJAX software, from Python to JavaScript to full-blown Java and Flash." - Andrew Orlowski, The Register, "The mobile web: in praise of conv ... divergence" http://www.theregister.co.uk/2006/11/30/opera_mini_web/ Still, comp.lang.python manages to score a less than on-topic quote of the week: "> If you compare eclipse to VS, it is not that memory hungry. And if you compare Saturn to Jupiter, it's not that big." -- sjdevnull responding to hg http://groups.google.com/group/comp.lang.python/msg/13d0b24029b6e753 A provisional PyCon schedule has been made available with three... no, four lightning talk sessions: http://groups.google.com/group/comp.lang.python.announce/browse_frm/thread/7fd3fc7fbe4f7100 http://pycon.blogspot.com/2006/12/abundance-of-lightning-talks.html Python's "benevolent dictator" himself gave a talk recently, as previously mentioned in Python-URL!, and Niall Kennedy summarises the content for those not in attendance: http://www.niallkennedy.com/blog/archives/2006/11/google-mondrian.html Fof us who skimmed PEP 263 and thought that only "emacs-style" comments were allowed when telling Python about source file encodings, a careful re-reading is advised. Examples for vim users are provided in the context of a source code tidier, PythonTidy: http://groups.google.com/group/comp.lang.python/browse_frm/thread/c62220ff0f4cb30a Ravi Teja spells out communications architectures and mechanisms in the context of CORBA: http://groups.google.com/group/comp.lang.python/msg/3f056c5c87279aca The One Laptop Per Child developers and testers briefly consider Python development environments (in the context of things Alan Kay presented at EuroPython 2006): http://mailman.laptop.org/pipermail/devel/2006-November/003176.html ... while the "Python in education" special interest group mulls over the notion of a "view source" button for running programs: http://mail.python.org/pipermail/edu-sig/2006-November/007418.html E..and the best way to try the latest Python-related developments in the OLPC project: http://mail.python.org/pipermail/edu-sig/2006-December/007441.html Reconstructor is an Ubuntu Linux Live CD creator written in Python and licensed under the GNU General Public License (GPL): http://reconstructor.aperantis.com/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html Steve Bethard continues the marvelous tradition early borne by Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim Lesher of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/python/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topic/python/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From steven.bethard at gmail.com Thu Dec 14 14:52:10 2006 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 14 Dec 2006 12:52:10 -0700 Subject: Defining classes In-Reply-To: References: Message-ID: Nick Maclaren wrote: > I am defining a class, and I need to refer to that class when > setting up its static data - don't ask - like this: > > Class weeble : > wumpus = brinjal(weeble) Duncan Booth wrote: > Alternatively you can play tricks with metaclasses for a similar effect. Nick Maclaren wrote: > Well, I am already doing that, and regretting the fact that Python > doesn't seem to allow a class instantiation to return a new class :-) How are you doing it currently? Here's a sort of minimalist option: >>> class weeble(object): ... def __metaclass__(name, bases, bodydict): ... cls = type(name, bases, bodydict) ... cls.wumpus = 'brinjal', cls ... return cls ... >>> weeble.wumpus ('brinjal', ) Of course, it still takes four lines and a metaclass... STeVe From maksim.kasimov at gmail.com Thu Dec 28 10:24:23 2006 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Thu, 28 Dec 2006 17:24:23 +0200 Subject: __getattr__ possible loop In-Reply-To: <1167314779.170915.145680@48g2000cwx.googlegroups.com> References: <1167314779.170915.145680@48g2000cwx.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > I have tried this, with Psyco it segfaults, and with Python 2.5 (on > Win) hangs the interpreter, is it possible to improve the situation? > > class T(object): > def __getattr__(self, x): dir(self) > #import psyco > #psyco.full() > T().method() > > (Probably dir calls __getattr__). > > Bye, > bearophile > how to improve the situation depends on what do you expect to get by calling "T().method()" dir calls __getattr__ with the value '__members__', for example you can write: def __getattr__(self, x): if x == '__members__': return ('method1', 'field1', ) -- Maksim Kasimov From gal.diskin at gmail.com Wed Dec 13 09:51:53 2006 From: gal.diskin at gmail.com (Gal Diskin) Date: 13 Dec 2006 06:51:53 -0800 Subject: Iterating over several lists at once In-Reply-To: References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> Message-ID: <1166021513.479174.113630@80g2000cwy.googlegroups.com> Nothing seriously wrong, but it's not too elegent. Especially when the number of lists you want to iterate over gets bigger (especially because of the indentation in python). As you noticed (an phrased better than me), what I was wondering is if there is a way to iterate over the cartesian product, but without actually doing all n for loops but using a single "for" loop. Thanks for replying me. On Dec 13, 3:58 pm, Roberto Bonvallet wrote: > Gal Diskin wrote: > > Hi, > > I am writing a code that needs to iterate over 3 lists at the same > > time, i.e something like this: > > > for x1 in l1: > > for x2 in l2: > > for x3 in l3: > > print "do something with", x1, x2, x3What's wrong with this? > > [...] > > > I'd be very happy to receive ideas about how to do this in one loop and > > with minimal initialization (if at all required).def cartesian_product(l1, l2, l3): > for i in l1: > for j in l2: > for k in l3: > yield (i, j, k) > > for (i, j, k) in cartesian_product(l1, l2, l3): > print "do something with", i, j, k > > -- > Roberto Bonvallet From http Mon Dec 11 10:17:40 2006 From: http (Paul Rubin) Date: 11 Dec 2006 07:17:40 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> Message-ID: <7xd56qbgx7.fsf@ruckus.brouhaha.com> Bill Atkins writes: > > There's no way you could compile Python to efficient > > machine code just by macro expansion. You'd also need > > some very heavy-duty type inferencing. > > When I used to use Ruby a lot, I believed this line that the Ruby > community fed itself (and apparently Python feeds itself as well): > Ruby/Python has to be interpreted because it's too dynamic. I don't think you can reasonably compile Python just by what we'd usually call macro expansion. You need fancier compiler techniques. > > Python is extremely dynamic, even more so than Lisp. > > That's why compiling Python is hard, not because it > > doesn't have macros. > > Uh huh. "More so than Lisp"? Just making stuff up now? Python is more dynamic than Lisp. > Despite its dynamism, Lisp is quite compilable. Yes. Lisp is dynamic, but less so than Python. And not by coincidence, Lisp is more compilable than Python. > For example, I can redefine classes, functions, macros, etc. at > runtime and compiled code referring to the old code will still work. > You are conflating dynamism with interpretedness, and that's > incorrect. If you say foo.frob() in Python, that's supposed to look up 'frob' in a dictionary hanging off of foo. You can modify the contents of this dictionary any time you want. The Lisp equivalent would be some generic function (frob foo) that you define with CLOS in the usual way, but then there's some hashtable that lets you redefine frob at any time by modifying it (i.e. just a normal hashtable that you poke with setf, no special notification to the class system). This can happen anywhere in the code, in another thread, or whatever. You can even replace that hashtable with another hashtable. You can also insert (at any time) a __getattr__ method into foo's class, that is a user-supplied function that replaces the hash lookup. This stuff is all quite hard to optimize the way CLOS can be optimized. I'd like to hope Python tones down these aspects of its dynamism as it continues to evolve. From robert.kern at gmail.com Tue Dec 5 14:26:57 2006 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 05 Dec 2006 13:26:57 -0600 Subject: Linear regression in NumPy In-Reply-To: <000401c71894$c8dcf9e0$28b2ea40@crux> References: <000401c71894$c8dcf9e0$28b2ea40@crux> Message-ID: Jianzhong Liu wrote: > Hello, Guys, > > I have a question about the linear_least_squares in Numpy. > > My linear_least_squares cannot give me the results. > > I use Numpy1.0. The newest version. So I checked online and get your > guys some examples. The package name for numpy 1.0 is "numpy", not "Numeric". See this page for an explanation of the names and the history of the two packages: http://www.scipy.org/History_of_SciPy The examples you say are for Numeric, not numpy. You can get up-to-date examples from here: http://www.scipy.org/Documentation And please join us on numpy-discussion if you have any more questions. http://www.scipy.org/Mailing_Lists -- 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 From agriff at tin.it Mon Dec 11 17:19:20 2006 From: agriff at tin.it (Andrea Griffini) Date: Mon, 11 Dec 2006 23:19:20 +0100 Subject: Lookup caching In-Reply-To: References: <457b69ec$0$16153$4fafbaef@reader3.news.tin.it> Message-ID: <457dd837$0$4242$4fafbaef@reader1.news.tin.it> Gabriel Genellina wrote: > At Saturday 9/12/2006 23:04, Andrea Griffini wrote: > >> I implemented that crazy idea and seems working... in its >> current hacked state can still pass the test suite (exluding > > What crazy idea? And what is this supposed to do? > The idea is to avoid looking up constants several times into dictionaries that didn't change (e.g. builtins). Reading a bit about other optimization proposals I didn't find a similar one so I decided to invest some spare time in it. The idea is 1) Add a "timestamp" to dictionaries, so when a dictionary is changed the timestamp gets updated 2) Store a cached lookup for constants; the cached lookup is stored as a timestamp value and a naked pointer to the result. The algorithm for the lookup of a given constant is: if ( <> == d->timestamp) { x = <>; } else { x = PyDict_GetItem(d, key); <> = d->timestamp; <> = x; } using a naked pointer is safe because it will be used only if the dictionary wasn't touched, hence the value is surely still alive. The original place I thought about where to store the cached lookup was the bytecode, however after reading python sources I resorted instead to a dedicated space inside the code object. The code for LOAD_GLOBAL uses something like if (co->co_cachedtstamps[oparg] == d->timestamp) ... i.e. I used an array indexed by the index of the co_name used for lookups. The patched code is currently working, however I found that while the hit/miss ratios are impressive (as I expected) the speedup is simply absent. Moreover there is no difference at all between paying for the timestamp handling and NOT using the cached lookups or instead paying AND using the cached lookups (!). Absurdely python on my PC runs faster if I in addition to the cached lookup code also leave in place the hit/miss statistics (a few static ints increment and a static atexit-ed output function). Also it made a lot of difference about where the timestamp was placed inside the dictobject structure... In addition to the not impressive results (my patched python now is just a bit *slower* than original one :-D) there is also another complication. The LOAD_GLOBAL actually needs TWO lookups, so I used two cached results (one for globals, one for builtins). The ideal solution however IMO would be in this case to have two timestamps and one cached value instead... (if neither dict was touched since last lookup then the result will be the cached one). The complication is that a lot of lookups are done by the LOAD_ATTR instead and thinking to the ideal solution for new classes made my brain explode (mro, descriptor and stuff...). It would be simple to do something for classic classes, but would that be worth (i mean... aren't those going to disappear ?). Probably something can be done for using caches for LOAD_ATTR for modules (to speed up a bit things like math.sin or mod1.mod2.mod3.func). Any suggestion is welcome... Andrea From neoedmund at gmail.com Sat Dec 16 05:39:31 2006 From: neoedmund at gmail.com (neoedmund) Date: 16 Dec 2006 02:39:31 -0800 Subject: I'm looking for an intelligent date conversion module In-Reply-To: <1166199318.637236.256190@t46g2000cwa.googlegroups.com> References: <1166199318.637236.256190@t46g2000cwa.googlegroups.com> Message-ID: <1166265571.809331.84710@t46g2000cwa.googlegroups.com> I'm more familiar with java. maybe java.util.Calendar can be port to python? i donnt know. mthorley ??????: > Greetings, I'm looking for a python module that will take a datetime > obj and convert it into relative time in english. > For example: 10 minutes ago, 1 Hour ago, Yesterday, A few day ago, Last > Week, etc > > I've looked around on the web, in the docs, the cheeseshop and on this > list and have found what I'm looking for. > Am I just blind? (likely), If anyone can give me a tip on how to do > this I'd really appreciate it. > > thanks > -- > mthorley From paddy3118 at netscape.net Tue Dec 12 19:54:58 2006 From: paddy3118 at netscape.net (Paddy) Date: 12 Dec 2006 16:54:58 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4579c4f4$0$49201$14726298@news.sunsite.dk> Message-ID: <1165971298.617221.59450@n67g2000cwd.googlegroups.com> Robert Uhl wrote: > Steven D'Aprano writes: > > > > Speaking as somebody who programmed in FORTH for a while, that doesn't > > impress me much. Prefix/postfix notation is, generally speaking, more > > of a pain in the rear end than it is worth, even if it saves you a > > tiny bit of thought when pasting code. > > Of course, you use prefix notation all the time in Python: > > for x in range(0,len(y)): > dosomething(x) In Python, most containers are directly iterable so we are much more likely to arrange our program to use: for a in y: dosomethingwith(a) -Paddy. From Tim.Golden at viacom-outdoor.co.uk Wed Dec 6 09:56:54 2006 From: Tim.Golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 6 Dec 2006 14:56:54 -0000 Subject: Windows: get owner and group of a file In-Reply-To: Message-ID: [Duncan Booth] | You can get the owner by doing os.popen('dir /q') and parsing | the output, but it is a string not a number (which I guess is why | stat/lstat can't return a value). Good one; I'd forgotten about that. However, I don't know if the OP's restriction against popen ("ls- l") extends to popen ("dir /q") ! TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From rampeters at gmail.com Tue Dec 5 19:56:12 2006 From: rampeters at gmail.com (johnny) Date: 5 Dec 2006 16:56:12 -0800 Subject: newb: Join two string variables In-Reply-To: References: <1165362610.329148.6460@l12g2000cwl.googlegroups.com> Message-ID: <1165366572.644641.73460@73g2000cwn.googlegroups.com> In my code, I have the following: p = posixpath.basename(e).strip filename = download_dir+p I am getting the following error: filename = download_dir+p TypeError: cannot concatenate 'str' and 'builtin_function_or_method' objects Cameron Walsh wrote: > johnny wrote: > > How do I join two string variables? > > I want to do: download_dir + filename. > > download_dir=r'c:/download/' > > filename =r'log.txt' > > > > I want to get something like this: > > c:/download/log.txt > > > > Hi Johnny, > > This is actually two questions: > > 1.) How do I concatenate strings > 2.) How do I concatenate pathnames? > > Answers: > > 1.) > > >>> download_dir="C:/download/" > >>> filename="log.txt" > >>> path_to_file=download_dir+filename > >>> path_to_file > 'C:/download/log.txt' > > 2.) > > >>> import os > >>> filename='log.txt' > >>> path_to_file = os.path.join("C:/download",filename) > >>> path_to_file > 'C:/download/log.txt' > > > Help on function join in module posixpath: > > join(a, *p) > Join two or more pathname components, inserting '/' as needed > > > > Hope it helps, > > Cameron. From tundra at tundraware.com Mon Dec 18 14:00:35 2006 From: tundra at tundraware.com (Tim Daneliuk) Date: Mon, 18 Dec 2006 13:00:35 -0600 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <1166394345_23949@sp6iad.superfeed.net> <1166442477.818748.324370@f1g2000cwa.googlegroups.com> <0vsi54-1vf2.ln1@eskimo.tundraware.com> Message-ID: Gabriel Genellina wrote: > At Monday 18/12/2006 13:41, Tim Daneliuk wrote: > >> I was working on a new release and wanted to add file associations >> to it. That is, if the user selected a file and double clicked or >> pressed Enter, I wanted the following behavior (in the following >> steps, "type" means nothing more than "a file whose name ends with >> a particular string"): >> >> 1) If an association for that file type exists, run the associated >> program. >> >> 2) If an association for that file type does not exist: >> >> a) If the file is not "executable", see if there is a "default" >> association defined and run that program if there is. >> >> b) If the file *is* "executable", run it. > > This is what os.startfile does. The underlying Win32 functions would be And on Windows, that's exactly what I use. > ShellExecute, FindExecutable & their variants. > Will you maintain your own registry for associations? Yes, because I want common configuration syntax and runtime semantics across FreeBSD, Linux, Windows, et al. The only semantic difference is that, on Windows, if my own association is not found, then the Windows association will apply. This cannot be done in the *nix environment - at least not easily - because there is no common association repository across the various window managers, nor is there a startfile() type call in the POSIX world. This is implemented already and largely works as planned. There are a few subtleties I want to work into the next release, but things work as expected today... -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From caleb.hattingh at gmail.com Fri Dec 15 04:10:53 2006 From: caleb.hattingh at gmail.com (Caleb Hattingh) Date: 15 Dec 2006 01:10:53 -0800 Subject: Writing and reading variables to/from flat file In-Reply-To: <84548$45816e6c$4275d90a$16465@FUSE.NET> References: <84548$45816e6c$4275d90a$16465@FUSE.NET> Message-ID: <1166173852.947607.77500@j72g2000cwa.googlegroups.com> Hi Kevin The other posters helped you with configParser, which is what you wanted, i.e. text file access. However, you can also get persistance really cheaply with pickling, if you don't need the saved data to be text-editable: (from memory) verboseSettings = {} verboseSettings['Detailed'] = '-vv' verboseSettings['Basic'] = '-q' import cPickle # Save the data - Just give the dict! cPickle.dump(verboseSettings, file('prefs','w+')) # Load the data back - get the dict back verboseSettings = cPickle.load(file('prefs','r')) I recently did a ton of scientific data analysis looking for trends in 10 years of data for a petrochemical plant, and I learned just how convenient dicts and pickles can be to manage one's sanity :) Caleb On Dec 14, 4:31 pm, Kevin Walzer wrote: > I want to write some variables (user preferences, specifically) to a > text file and then read the values from that file. > > Here is my code to write the data: > > verbosemodes= """ > Detailed = "-vv" > Basic = "-q" > """ > > file = open('prefs', 'w') > > file.writelines(verbosemodes) > > file.close() > > And here is my code, in a separate module, to read the file and display > the variable values: > > readfile = open('prefs').readlines() > > for line in readfile: > print line > > print Basic > > Running the second module yields this error: > > Detailed = "-vv" > > Basic = "-q" > > Traceback (most recent call last): > File "readprefs.py", line 6, in > print Basic > NameError: name 'Basic' is not defined > > Clearly the data is getting read (the lines are being printed), but the > variable itself ("Basic") is not being initialized properly. I'm not > sure what I'm doing wrong here--can anyone point me in the right > direction? Thanks. > > -- > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com From uymqlp502 at sneakemail.com Sun Dec 10 22:44:24 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 10 Dec 2006 19:44:24 -0800 Subject: Automatic debugging of copy by reference errors? References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> Message-ID: <1165808664.074268.114910@l12g2000cwl.googlegroups.com> Niels L Ellegaard wrote: > Is there a module that allows me to find errors that occur due to copy > by reference? I am looking for something like the following: I don't have a solution for you, but I certainly appreciate your concern. The copy by reference semantics of Python give it great efficiency but are also its achille's heel for tough-to-find bugs. I once wrote a simple "vector" class in Python for doing basic vector operations such as adding and subtracting vectors and multiplying them by a scalar. (I realize that good solutions exist for that problem, but I was more or less just experimenting.) The constructor took a list as an argument to initialize the vector. I later discovered that a particularly nasty bug was due to the fact that my constructor "copied" the initializing list by reference. When I made the constructor actually make its own copy using "deepcopy," the bug was fixed. But deecopy is less efficient than copy by reference, of course. So a fundamental question in Python, it seems to me, is when to take the performance hit and use "copy" or "deepcopy." If a debugger could tell you how many references exist to an object, that would be helpful. For all I know, maybe some of them already do. I confess I don't use debuggers as much as I should. From bjourne at gmail.com Sat Dec 9 18:48:50 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sun, 10 Dec 2006 00:48:50 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: <740c3aec0612091548r1d043a67k20e22db714802a31@mail.gmail.com> > > Maybe so. But I've only ever appreciated its functional aspects. I > > wouldn't choose Lisp or its derivatives for OO related tasks even if > > I'm high. > > But CLOS is the best OO there is. The OMG said so. It can do anything > any other OO can do. Why /specifically/ would you not use it? This type Specifically it does not have name spaces. Therefore it is fundamentally flawed and cannot be used as a serious object-oriented tool for developing complex applications. However, I'll give you that it is pretty nice for pet-projects and educational purposes (counting parenthesises). But for some, that is more than enough. -- mvh Bj?rn From sjmachin at lexicon.net Sun Dec 3 20:33:59 2006 From: sjmachin at lexicon.net (John Machin) Date: 3 Dec 2006 17:33:59 -0800 Subject: Parsing data from pyserial In-Reply-To: <45737310.88637718@news.comporium.net> References: <4572e860.53134312@news.comporium.net> <12n606he7k5uhb3@corp.supernews.com> <4573145a.64392531@news.comporium.net> <12n66nnm8ri1sd4@corp.supernews.com> <45737310.88637718@news.comporium.net> Message-ID: <1165196039.802469.77510@f1g2000cwa.googlegroups.com> Si Ballenger wrote: > > Per what was posted (below), it appears that the the appropriate > data is being received. [snip] > > Here is an example output: > > M 37 79 3 4 59 124 86 25 > ['59', '123', '87', '25', 'M', '37', '79', '3', '4', '59', > '124', '86', '25', 'M > '] > M 38 77 3 2 59 124 86 25 > ['39', '85', '26', 'M', '38', '77', '3', '2', '59', '124', '86', > '25', 'M', '38' > , '7'] Based on the split() results (presumably much more reliable than the "print reading" results) what appears to me is: fragment '59', '123', '87', '25' packet 'M', '37', '79', '3', '4', '59', '124', '86', '25' fragment 'M', '39' [see note] fragment '85', '26' packet 'M', '38', '77', '3', '2', '59', '124', '86', '25', fragment 'M', '38' [note] the 39 obviously aligns with the 37 and 38s, not with the 123 and 124s. However the boundary of the 2 split() results lies before the 39, not after. Puzzling. In any case, I wouldn't call that "the appropriate data is being received" -- looks like chunks missing to me. From __peter__ at web.de Sun Dec 3 02:57:27 2006 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Dec 2006 08:57:27 +0100 Subject: Anyone understand this syntax error? References: Message-ID: Sean Hammond wrote: > > Anyone understand this? > > Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) > [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def markdown_perl(input): > ... """Send 'input' (string) to the markdown perl script, and return > the > ... output from markdown (string). > ... > ... input: a string of markdown-formatted text, including \n's at > the end > ... of lines, that will be sent to the markdown process. > ... > ... returns: a string of valid XHTML from markdown > ... """ > ... import tempfile > ... import commands > ... file = tempfile.NamedTemporaryFile() > ... file.write(input) > ... file.flush() > ... return commands.getoutput('./markdown.pl '+file.name) > File "", line 15 > return commands.getoutput('./markdown.pl '+file.name) > ^ > SyntaxError: invalid syntax >>>> > > I don't get it. Syntax seems fine to me, just a normal string > concatenation. > > -- Are you perhaps mixing tabs and spaces? >>> def f(): ... print "hello" # four spaces before 'print' ... return 42 # one tab before 'return' File "", line 3 return 42 ^ SyntaxError: invalid syntax Peter From noway at ask.me Sun Dec 3 07:01:03 2006 From: noway at ask.me (Giovanni Bajo) Date: Sun, 03 Dec 2006 13:01:03 +0100 Subject: Parsing data from pyserial In-Reply-To: References: Message-ID: Lone Wolf wrote: > reading = ser.read(40) Simply try ser.readline() here, or maybe ser.readline(eol="\r"). -- Giovanni Bajo From fredrik at pythonware.com Thu Dec 21 07:41:10 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 21 Dec 2006 13:41:10 +0100 Subject: an hex number problem In-Reply-To: <1166704431.573516.242830@n67g2000cwd.googlegroups.com> References: <1166704431.573516.242830@n67g2000cwd.googlegroups.com> Message-ID: could.net at gmail.com wrote: > I got a number 19968: >>> x = 19968 > 1. how can I change it to the hex form 0x4e00, >>> hex(x) '0x4e00' > 2. and how can I change 0x4e00 to a python unicode character u"\u4e00"? >>> unichr(x) u'\u4e00' also see: http://effbot.org/pyfaq/how-do-i-convert-a-number-to-a-string From mail at microcorp.co.za Sun Dec 3 01:08:28 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sun, 3 Dec 2006 08:08:28 +0200 Subject: Parsing data from pyserial References: <200612030402.XAA23229@www23.ureach.com> Message-ID: <016201c716a1$746d14c0$03000080@hendrik> "Lone Wolf" wrote: > I'm trying to get data through my serial port from a CMUcam. > This gizmo tracks a color and returns a packet of data. The > packet has nine data points (well, really eight since the first > point is just a packet header) separated by spaces as follows: M > xxx xxx xxx xxx xxx xxx xxx xxx 8<---------------------------- Try splitting the stuff on the "M" first to separate the records, then get rid of the newlines, carriage return, linefeed, whatever, and then use the split on whitespace... - HTH - Hendrik From roman.yakovenko at gmail.com Sun Dec 17 13:45:43 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 17 Dec 2006 20:45:43 +0200 Subject: Wrapping classes with pure virtual functions In-Reply-To: <1166133429.969921.131400@80g2000cwy.googlegroups.com> References: <1166133429.969921.131400@80g2000cwy.googlegroups.com> Message-ID: <7465b6170612171045l549ecd0dkb53d60a564ed37ef@mail.gmail.com> On 14 Dec 2006 13:57:10 -0800, gabriel.becedillas at gmail.com < gabriel.becedillas at gmail.com> wrote: > Hi, > I'm having problems wrapping a hierarchy of classes, actually having > problems wrapping the base class. I don't need to use the WrapClass > mechanism since I don't want to override classes in Python. My code > boils down to: > > class Base > { > public: > virtual ~Base() > {} > > virtual void f() = 0; > }; > > class Derived : > public Base > { > public: > virtual void f() > {} > > void g() > {} > }; > > int main() > { > boost::python::class_ class_base("Base"); > boost::python::class_ class_derived("Derived"); > return 0; > } > namespace bpl = boost::python; bpl::class_("Base", bpl::no_init ) .def( "f", bpl::pure_virtual( &Base::f ) ); bpl::class_< Derived, bpl::bases< Base > >( "Derived" ) .def( "f", &Derived::f ) .def( "g", &Derived::g ); Few comments: 1. It is better to ask Boost.Python related questions on its mailing list: http://mail.python.org/mailman/listinfo/c++-sig/ 2. If you just start with Boost.Python, try Py++ ( http://language-binding.net/pyplusplus/pyplusplus.html ) Boost.Pythoncode generator It has nice GUI ( no need to learn any API ): http://language-binding.net/pyplusplus/documentation/tutorials/pyplusplus_gui.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrosenstihl at macnews.de Sat Dec 9 19:23:44 2006 From: mrosenstihl at macnews.de (Markus Rosenstihl) Date: Sun, 10 Dec 2006 01:23:44 +0100 Subject: Need Help Parsing From File References: Message-ID: On 2006-12-07 04:20:48 +0100, John Frame said: > Hi, I've got a Python program that I'm trying to edit, and I need some help. > > If I would like to read a matrix from a previously created text file > into a two dimensional array, how would I do that? > > Like, if in the txt file, I had the following matrix formatted numbers > with 5 rows and 10 columns, and each number is separated by a single > space: > > 11 12 13 14 15 16 17 18 19 20 > 21 22 23 24 25 26 27 28 29 30 > 31 32 33 34 35 36 37 38 39 40 > 41 42 43 44 45 46 47 48 49 50 > 51 52 53 54 55 56 57 58 59 60 > > How would I read this data from the file into a two dimensional array > in Python? In case you have imported pylab: myarray = pylab.load('textfile.txt') Regards Markus From ask at me Fri Dec 8 23:03:05 2006 From: ask at me (alf) Date: Fri, 08 Dec 2006 22:03:05 -0600 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <-aKdnfuYG7fnqOfYnZ2dnUVZ_uyknZ2d@comcast.com> Mark Tarver wrote: > How do you compare Python to Lisp? A little bit OT but I can not resist it. What always impressed me with Lisp is that LOGO (any one remembers) is Lisp based yet designed to teach kids programming. I do not know Lisp but used to program a bit in LOGO - everything was so natural ... -- alfz1 From aboudouvas at panafonet.gr Thu Dec 14 17:56:27 2006 From: aboudouvas at panafonet.gr (king kikapu) Date: 14 Dec 2006 14:56:27 -0800 Subject: Property error Message-ID: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> Hi to all, i am trying to use properties in Python and i am sure i have made something wrong with the below code but i just cannot see what it is. Can anyone please help me on this ? The code is : class Person(object): age = 0 @property def age(): def fget(self): return self.age def fset(self, value): self.age = value me = Person() me.age = "34" print me.age and i am getting the error: " File "C:\projects\Python\p2.py", line 12, in me.age = "34" AttributeError: can't set attribute " What exactly i am doing wrong ?? Thanks a lot in advance. From george.sakkis at gmail.com Fri Dec 8 04:13:09 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 8 Dec 2006 01:13:09 -0800 Subject: Common Python Idioms References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> <1165500649.129625.213300@j44g2000cwa.googlegroups.com> <1165528352.978586.248960@16g2000cwy.googlegroups.com> Message-ID: <1165569189.823007.318140@j72g2000cwa.googlegroups.com> Steven D'Aprano wrote: > On Thu, 07 Dec 2006 13:52:33 -0800, George Sakkis wrote: > > > I'm surprized that none of these pages mentions the incompatible type > > comparison gotcha: > > > >>>> 5 < "4" > > True > > > > I'm sure this has bitten many folks, particularly (ex) Perl'ers. > > Why is this a gotcha? > > I can't speak for others, but except for sorting, Well, sorting alone is a big issue, don't you think ? > I've never been tempted to compare ints to strings like that, but thinking about the code I've > written, I can't think of any bad consequences that would have happened if > I had. Of course nobody (except perhaps from newbies coming from perl) would intentionally compare ints with strings. The gotcha is when you compare two values whose type you *think* you know, and since duck typing is typically preferred over explicit type checking, it's one of the very few cases that the "errors should never pass silently" rule is violated. Thankfully this will raise TypeError in 3.0. George From nospam at foo.com Wed Dec 20 18:07:32 2006 From: nospam at foo.com (jayessay) Date: 20 Dec 2006 18:07:32 -0500 Subject: merits of Lisp vs Python References: <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <7xac1nfmyb.fsf@ruckus.brouhaha.com> <1166342606.141406.137000@f1g2000cwa.googlegroups.com> <7x3b7ekk6p.fsf@ruckus.brouhaha.com> <1166410256.785907.69140@73g2000cwn.googlegroups.com> <7xy7p5kixi.fsf@ruckus.brouhaha.com> <45897266$0$4158$ba624c82@nntp02.dk.telia.net> Message-ID: "Anders J. Munch" <2006 at jmunch.dk> writes: > jayessay wrote: > > Please note: GC is not part of CL's definition. It is likely not part > > of any Lisp's definition (for reasons that should be obvious), and for > > the same reasons likely not part of any language's definition. > > Really? Really. > So how do you write a portable program in CL, that is to run > for unbounded lengths of time? Make it non-consing (like for any such program in any language). Of course, this won't guarantee success as the implementation or OS or ... may leak or other wise cons memory even if your program doesn't. I'm surprised there are people out there that find this interesting let alone surprising. /Jon -- 'j' - a n t h o n y at romeo/charley/november com From basti.wiesner at gmx.net Wed Dec 27 14:15:33 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 27 Dec 2006 20:15:33 +0100 Subject: DOS, UNIX and tabs References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: Ben typed > I have a python script on a windows system that runs fine. Both use > tabs to indent sections of the code. Just a tip for you: In python you never use tabs for indentation. The python style guide [1] recommends four spaces per indentation level. [1] http://www.python.org/dev/peps/pep-0008/ -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From smithj at rpath.com Wed Dec 27 21:12:00 2006 From: smithj at rpath.com (Jonathan Smith) Date: 27 Dec 2006 21:12:00 -0500 Subject: Python 2.4.4 vs. 2.3.6 Message-ID: <3250098727.185691@mail.rpath.com> I would say 2.4.4, since it has the latest bugfixes of the series most distros use. ----------------------- Sent with ChatterEmail+ True push email for the Treo Smartphone http://get.chatteremail.com -----Original Message----- From: sndive at gmail.com Date: Wednesday, Dec 27, 2006 9:05 pm Subject: Python 2.4.4 vs. 2.3.6 To: python-list at python.org My top priority is stability of the interpreter. With that in mind which version should I get: 2.4.4, 2.3.6 or something else. I will be using gcc 2.3.2(x86), 3.3(arm) and 3.4.3(arm) to cross compile it depending on the (embedded) platform. Thank you. -- http://mail.python.org/mailman/listinfo/python-list From jidanni at jidanni.org Wed Dec 20 11:11:10 2006 From: jidanni at jidanni.org (Dan Jacobson) Date: Thu, 21 Dec 2006 00:11:10 +0800 Subject: perl better than python for users with disabilities? Message-ID: <87slfalf8h.fsf@jidanni.org> Can I feel even better about using perl vs. python, as apparently python's dependence of formatting, indentation, etc. vs. perl's "(){};" etc. makes writing python programs perhaps very device dependent. Whereas perl can be written on a tiny tiny screen, and can withstand all kinds of users with various disabilities, etc.? Also perl is easier to squeeze into makefiles. From Benjamin.Barker at gmail.com Wed Dec 27 13:34:43 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 27 Dec 2006 10:34:43 -0800 Subject: DOS, UNIX and tabs In-Reply-To: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: <1167244483.792673.132220@42g2000cwt.googlegroups.com> I've found the unexpand command, which seems to do the trick. However, it outputs to standard output, and I haven't worked out yet how to capture that output to a file... Ben Ben wrote: > Hi, > > I have a python script on a unix system that runs fine. I have a python > script on a windows system that runs fine. Both use tabs to indent > sections of the code. I now want to run them on the same system, > actually in the same script by combining bits and pieces. But whatever > I try my windows tabs get converted to spaces when I transfer it to the > unix system and the interpreter complains that the indentation style is > not consistent throughout the file. Short of going through 350 lines of > code and manually replacing spaces with tabs what an I do? I'm thinking > there surely must be a simple solution I have missed here! > > Cheers, > > Ben From xah at xahlee.org Wed Dec 27 16:39:34 2006 From: xah at xahlee.org (Xah Lee) Date: 27 Dec 2006 13:39:34 -0800 Subject: Xah's Edu Corner: Introduction to 3D Graphics Programing In-Reply-To: <1167230356.551596.193550@73g2000cwn.googlegroups.com> References: <1166836083.084101.25870@73g2000cwn.googlegroups.com> <458d7899$0$8725$ed2619ec@ptn-nntp-reader02.plus.net> <1167208399.089326.213540@a3g2000cwd.googlegroups.com> <1167230356.551596.193550@73g2000cwn.googlegroups.com> Message-ID: <1167255574.202660.176530@48g2000cwx.googlegroups.com> Here's their license: http://www.vpython.org/webdoc/visual/license.txt I read it wrong before. Thanks for correction. This is superb! I'll be looking into vpython! Xah Ravi Teja wrote: > Xah Lee wrote: > > > Regarding VisualPython... i saw a demo in 2002 by a professor > > friend. I think it is good. Though, why is its licensing not GPL or > > otherwise Open Source? That's kinda odd since Pyhton is. > > You are confusing VPython with Activestate's Visual Python IDE plugin > for Visual Studio. > >From VPython's home page in very bold font - "VPython is free and > open-source" > http://www.vpython.org/ From arkanes at gmail.com Mon Dec 18 08:32:43 2006 From: arkanes at gmail.com (Chris Mellon) Date: Mon, 18 Dec 2006 07:32:43 -0600 Subject: Good Looking UI for a stand alone application In-Reply-To: <45851501$0$18425$426a34cc@news.free.fr> References: <4584531c$0$13533$426a74cc@news.free.fr> <1166325882.434177.313730@80g2000cwy.googlegroups.com> <45851501$0$18425$426a34cc@news.free.fr> Message-ID: <4866bea60612180532g2dec009eq5ed91b04601db3@mail.gmail.com> On 12/17/06, Christophe Cavalaria wrote: > Sandra-24 wrote: > > > On 12/16/06, The Night Blogger wrote: > >> Can someone recommend me a good API for writing a sexy looking (Rich UI > >> like WinForms) shrink wrap application > > > >> My requirement is that the application needs to look as good on Windows > >> as on the Apple Mac > > > > wxPython or something layered on it would be the way to go. I tried all > > the popular toolkits (except qt) and nothing else comes close for cross > > platform gui work. Don't let people persuade you otherwise, that caused > > me a lot of trouble. > > Well, you should try qt too ;) > > BTW, does wxWindow/wxPython have something that allows you to switch the OK > and Cancel button position according to the current machine GUI guidelines? > Yes. See wxDialog.CreateButtonSizer, which will return a sizer (probably, on some embedded platforms it might not create actual buttons, see docs) that has ok/cancel buttons in the standard position for the platform, and with the correct stock graphics and text on those platforms that have such a concept (like Gtk/GNOME). From kkeller-usenet at wombat.san-francisco.ca.us Wed Dec 27 13:52:53 2006 From: kkeller-usenet at wombat.san-francisco.ca.us (Keith Keller) Date: Wed, 27 Dec 2006 10:52:53 -0800 Subject: Xah's Edu Corner: Introduction to 3D Graphics Programing References: <1166836083.084101.25870@73g2000cwn.googlegroups.com> <458d7899$0$8725$ed2619ec@ptn-nntp-reader02.plus.net> <1167208399.089326.213540@a3g2000cwd.googlegroups.com> <4592391a$0$20812$5fc30a8@news.tiscali.it> Message-ID: <61sa64xua.ln2@goaway.wombat.san-francisco.ca.us> ["Followup-To:" header set, but it's best not to followup at all.] On 2006-12-27, Raff wrote: > Xah Lee wrote: >> I don't know OpenGL, but i think it is a low-level crap, and have done ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> the industry huge irreparable damage the same way unix has. > > OpenGL is low level, that's right, but it is not crap. Whether it is or not, Xah doesn't know and doesn't care, as he is a troll (and anyone who would say "I don't know X but it's crap" is definitely either clueless or trolling). Please don't pay attention to his rants. --keith -- kkeller-usenet at wombat.san-francisco.ca.us (try just my userid to email me) AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt see X- headers for PGP signature information From jon at ffconsultancy.com Wed Dec 13 09:05:11 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Wed, 13 Dec 2006 14:05:11 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <45800931$0$8745$ed2619ec@ptn-nntp-reader02.plus.net> Marc 'BlackJack' Rintsch wrote: > So you don't count line endings when counting bytes. ;-) You'd probably replace "\n" -> " " so it wouldn't affect the byte count. Anyway, I think I was using non-whitespace bytes, so neither "\n" nor " " is counted. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From timr at probo.com Sun Dec 3 02:05:55 2006 From: timr at probo.com (Tim Roberts) Date: Sun, 03 Dec 2006 07:05:55 GMT Subject: Video feature References: <1165048406.302509.122060@16g2000cwy.googlegroups.com> Message-ID: <1ot4n2dmkflrci1bus94vovpsoisbd1m64@4ax.com> "Lad" wrote: > >I would like to add on my website a possibility for visitors to >upload video and watch other user's video. How much difficult would it >be with Python? It's not all that hard, although you can probably download something that will do most of the job, probably in PHP. Is your website already using Python? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From george.sakkis at gmail.com Fri Dec 15 12:04:27 2006 From: george.sakkis at gmail.com (George Sakkis) Date: 15 Dec 2006 09:04:27 -0800 Subject: Property error References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> <1166179622.872556.312810@n67g2000cwd.googlegroups.com> <1166181267.949316.197360@16g2000cwy.googlegroups.com> Message-ID: <1166195860.234211.22610@l12g2000cwl.googlegroups.com> king kikapu wrote: > Your example Dennis, work as expected. I understand the mistake i have > made. But when i try to fix the original code usihn @property now, it > gives me the same error. > So, here it is: > > class Person(object): > _age = 0 > > @property > def age(): > def fget(self): > return self._age > def fset(self, value): > self._age = value > > me = Person() > me.age = 34 > print me.age > > > I am sure it is something very obvious but my skills does not (yet) > enable me to figure this out,,, As others have already replied, the default property doesn't work this way. In your example, it is possible to write it in one line using lambda: class Person(object): age = property(fget=lambda self: self._age, fset=lambda self, value: setattr(self,'_age',value)) If any of fget,fset,fdel cannot be written as lambda or you'd rather write them as functions, you may use the recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698. HTH, George From uymqlp502 at sneakemail.com Tue Dec 5 00:56:32 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 4 Dec 2006 21:56:32 -0800 Subject: Why not just show the out-of-range index? References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165195429.928771.148400@j44g2000cwa.googlegroups.com> Message-ID: <1165298191.987140.176550@f1g2000cwa.googlegroups.com> Folks, I'm truly sorry that so many feathers got ruffled in this thread. Let's see if I can put this thing to rest gracefully. Russ wrote: > My suggestion is trivial to implement and would benefit every Python > programmer (even if only slightly), so I don't think it is too much to > ask for. Apparently I was wrong about the implementation being trivial. Tasks often seem trivial -- until you actually try to do them. Yes, I should have known better. Had I not wrote that little gem, I suppose a lot of bad feelings could have been avoided. Would it be nice to get the specifics about an index error? Yes. But is it actually worth implementing? Well, since I have no intention of implementing it myself, I can't make that call. I can only hope that the Python maintainers decide that it is worth their effort to make Python more convenient for the user. But even if they don't, I still intend to continue using Python. The call is theirs to make. As I said earlier, the "issue" is hardly a major one, and I'm sorry it got blown out of proportion. At this point I don't even plan to submit a formal request. I have too many accounts and passwords already. If someone else wants to do it, please have at it. From fumanchu at amor.org Sun Dec 17 10:59:32 2006 From: fumanchu at amor.org (fumanchu) Date: 17 Dec 2006 07:59:32 -0800 Subject: Roundtrip SQL data especially datetime References: Message-ID: <1166371172.438499.264050@f1g2000cwa.googlegroups.com> dyork wrote: > "Dennis Lee Bieber" wrote in message > news:mailman.1686.1166257834.32031.python-list at python.org... > > > If you actually look at what the various DB-API adapters produce > > when sending to the database engine, floats, bools, etc. are all sent as > > string representations; about the only source for problems would be > > involved in the number of significant digits transferred for a float > > (you might feed 15 digits in, and only get 7 or 10 back) > > Having written adapters myself, I would not be confident that is true. It's > convenient to use native formats for floats and ints, and strings for > everything else. Regardless, you get trouble with (a) nulls (b) dates/times > (c) decimal/currency (d) precision mismatches (e) collation mismatches (f) > blobs (g) Unicode (h) special values like NaN. It takes great attention to > detail to be sure it all works, and I really don't want to write it (again). > > I'd just like to choose some product X and "It Just Works"! Ah. Then feel free to have a look at Dejavu, wherein I've worked all that out for you (okay, not NaN, but that wouldn't be hard). A quick look over http://projects.amor.org/dejavu/browser/trunk/storage/storemysql.py shows proper string escaping, correct handling of 1/0 for True and False, encoding, max precision, CURDATE, automatic scaling to BLOB columns for bytes > 255, and BLOB index limitations. All of the Null, date/time, decimal, unicode, and other type adaptation support is in the generic http://projects.amor.org/dejavu/browser/trunk/storage/geniusql.py The same goes for Postgres, MS Access, SQLite, and SQL Server. Firebird and sqlite3 are in the works. Simple docs at http://projects.amor.org/docs/dejavu/ Robert Brewer System Architect Amor Ministries fumanchu at amor.org From http Sun Dec 10 13:07:12 2006 From: http (Paul Rubin) Date: 10 Dec 2006 10:07:12 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> <457c42a3$0$49196$14726298@news.sunsite.dk> Message-ID: <7xodqbpqun.fsf@ruckus.brouhaha.com> "Alex Mizrahi" writes: > PR> But now you've got an interpreter and you no longer have that Lisp > PR> compiler. > > why do you think so? > if you have C compiler that translates C to assembly, and then compiles > assembly to machine language -- that's not C compiler, not asm compiler, or > what? > yes, possibly it would be sub-optimal, but at least it will work. and > normally there would be no big performance penalties. There would be terrible performance penalties dealing with the environment lookup on every lexical variable reference. That's the point. The compiler would treat those as references to slots in the call frame, would do type inference so it could use unboxed atoms where it could, etc. You'd lose all that. > PR> I think he's mistaken about being able to implement call/cc in full > PR> generality with CL macros in any reasonable way. > > why do you think so? > you know some case that does not work with call/cc? I don't see how to implement coroutines with CL macros. Maybe I'm missing something. > why are you theoretizing -- i've showed working real example of generators! > just get SBCL and ARNESI, load it, Too much hassle, I haven't used CL in many years and can't see doing the big download etc. just to try out one example. It's not like I'm going to suddenly discover the delights of CL. Been there, done that. I might re-read the LTU papers to see if I'm missing something about how CPS works. I've always been hazy on that stuff. > and then use call/cc as i've shown in > example. that's real generators. there's no need for any cond -- you can > save state as current-continuation. Fully general call/cc has to be able to switch from one execution stack to another and back. However, that is not needed for Python generators ("simple generators"), which can only yield to their direct caller. I think you might be able to do simple generators with messy macros but I don't see how you can do call/cc, jumping out to the continuation across many levels of function calls and then returning back into all those calls. The contination is not just a machine address or environment, it carries a lot of other state. From http Mon Dec 11 07:42:25 2006 From: http (Paul Rubin) Date: 11 Dec 2006 04:42:25 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <7xk611tpd1.fsf@ruckus.brouhaha.com> <1165733461.368441.94940@16g2000cwy.googlegroups.com> <7xhcw4gowx.fsf@ruckus.brouhaha.com> <457be9a6$0$49209$14726298@news.sunsite.dk> <7xejr8hqqs.fsf@ruckus.brouhaha.com> <457c42a3$0$49196$14726298@news.sunsite.dk> <7xodqbpqun.fsf@ruckus.brouhaha.com> <457c92c7$0$49195$14726298@news.sunsite.dk> <7x1wn7vx5b.fsf@ruckus.brouhaha.com> <457d3cdc$0$49205$14726298@news.sunsite.dk> <7xodqa7hpf.fsf@ruckus.brouhaha.com> <1165840551.975418.117360@j44g2000cwa.googlegroups.com> Message-ID: <7x4ps2ppse.fsf@ruckus.brouhaha.com> "Michele Simionato" writes: > > > "Programming Languages:Application and Interpretation" > > > Shriram Krishnamurthi > > > Brown University > > This book doesn't seem to be online. > > http://cs.brown.edu/~sk/Publications/Books/ProgLangs/ Thanks! From eight02645999 at yahoo.com Fri Dec 15 06:38:12 2006 From: eight02645999 at yahoo.com (eight02645999 at yahoo.com) Date: 15 Dec 2006 03:38:12 -0800 Subject: skip last line in loops In-Reply-To: References: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> Message-ID: <1166182692.041668.218730@f1g2000cwa.googlegroups.com> Fredrik Lundh wrote: > eight02645999 at yahoo.com wrote: > > > how can i skip printing the last line using loops (for /while) > > > > eg > > > > for line in open("file): > > print line. > > > > I want to skip printing last line of the file. > > do it lazily: > > last_line = None > for line in open("file): > if last_line: > print last_line > last_line = line > > or just gobble up the entire file, and slice off the last item: > > for line in list(open("file"))[:-1]: > print line > > hi would it be a problem with these methods if the file is like 20Gb in size...? From tundra at tundraware.com Fri Dec 29 03:44:23 2006 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 29 Dec 2006 02:44:23 -0600 Subject: Convert Perl to Python In-Reply-To: References: Message-ID: <341f64-rt.ln1@eskimo.tundraware.com> Marc 'BlackJack' Rintsch wrote: > In , > ???????? ?????? wrote: > >> How can I convert a perl script to Python? > > Look what the Perl script does and then rewrite it in Python. Automatic > translations between programming languages, if possible, usually result in > code that is not supposed to be read by human beings. Every language has > its idioms and a "literal" translation looks very odd to "native speakers" > of the target language. > > Ciao, > Marc 'BlackJack' Rintsch Either that or write a perl interpreter in python ;) -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From phd at phd.pp.ru Mon Dec 4 12:59:05 2006 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 4 Dec 2006 20:59:05 +0300 Subject: SQLObject release 0.7.2 Message-ID: <20061204175905.GC32211@phd.pp.ru> Hello! I'm pleased to announce the 0.7.2 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.7.2 News and changes: http://sqlobject.org/docs/News.html What's New ========== Features & Interface -------------------- * sqlbuilder.Select now supports JOINs exactly like SQLObject.select. * destroySelf() removes the object from related joins. Bug Fixes --------- * Fixed a number of unicode-related problems with newer MySQLdb. * If the DB API driver returns timedelta instead of time (MySQLdb does this) it is converted to time; but if the timedelta has days an exception is raised. * Fixed a number of bugs in InheritableSQLObject related to foreign keys. * Fixed a bug in InheritableSQLObject related to the order of tableRegistry dictionary. * A bug fix that allows to use SQLObject with DateTime from Zope. Documentation Added ------------------- * Added "How can I define my own intermediate table in my Many-to-Many relationship?" to FAQ. For a more complete list, please see the news: http://sqlobject.org/docs/News.html Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jon at ffconsultancy.com Sat Dec 9 05:50:51 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat, 09 Dec 2006 10:50:51 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <457a95ac$0$8721$ed2619ec@ptn-nntp-reader02.plus.net> Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. >From my point of view as neither a Lisp nor Python user: Lisp has some interesting features that separate it from many other programming languages. In contrast, there is nothing interesting about the Python language, AFAIK. Lisp is fairly elegant in the way that it facilitates different programming paradigms. Python is inelegant. Lisp is likely to be faster. Lisp is more mature but Python is (currently) more popular. I think that people who know more languages and more about programming will be much more inclined to use Lisp than Python. Look at the contents of the newsgroups for example, c.l.l has a thread on memoization whereas c.l.p has a thread about wrestling oiled pigs. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From rdiaz02 at gmail.com Wed Dec 6 10:23:39 2006 From: rdiaz02 at gmail.com (Ramon Diaz-Uriarte) Date: Wed, 6 Dec 2006 16:23:39 +0100 Subject: Book recommendations In-Reply-To: <1165413344.654740.247000@79g2000cws.googlegroups.com> References: <1165413344.654740.247000@79g2000cws.googlegroups.com> Message-ID: <624934630612060723q1c3b9013xce106f07fb46188b@mail.gmail.com> On 6 Dec 2006 05:55:44 -0800, Robert Hicks wrote: > On Dec 6, 7:09 am, "west" wrote: > > Can someone recommend a Python book for a newbie and perhaps you have a used > > one for sale? Thank you. I think a lot depends on your experience with other programming languages. If you are new to Python, but not to programming, I'd definitely go for "Python in a nutshell". To the point, loaded with information, and a great resource. And I'd get "Python pocket reference", which might be, for long periods, the only thing you need to open. If you do not have a lot of programming experience, you might want to look at "How to think like a computer scientist", "A byte of Python" (both freely available over the net), and then go for "Core Python Programming". > > > > Beginning Python: From Novice to Professional by Magnus Lie Hetland > Core Python Programming (2nd Edition) by Wesley Chun > > There are plenty of "Free" online ones as well. > > HTH > > Robert > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From grflanagan at yahoo.co.uk Tue Dec 19 10:05:09 2006 From: grflanagan at yahoo.co.uk (Gerard Flanagan) Date: 19 Dec 2006 07:05:09 -0800 Subject: permutations - fast & with low memory consumption? In-Reply-To: References: Message-ID: <1166540709.095851.97120@a3g2000cwd.googlegroups.com> Christian Meesters wrote: > Hi, > > I'd like to hack a function which returns all possible permutations as lists > (or tuples) of two from a given list. So far, I came up with this solution, > but it turned out to be too slow for the given problem, because the list > passed ("atomlist") can be some 1e5 items long: > > Does anybody know a solution which consumes less memory and is possibly > faster, perhaps using generator expressions? All my attempts so far failed. No claims with respect to speed, but the kslice function here: http://gflanagan.net/site/python/utils/sequtils/ will give the 'k-subsets' which then need to be permuted - alternatively Google. Gerard From morpheus at spam.no Wed Dec 20 13:48:25 2006 From: morpheus at spam.no (Morpheus) Date: Wed, 20 Dec 2006 19:48:25 +0100 Subject: What am I supposed to do with an egg?! References: <1166562334.101514.36350@t46g2000cwa.googlegroups.com> <35aca$45893898$c2d0d373$30325@news.hispeed.ch> Message-ID: On Wed, 20 Dec 2006 13:35:26 +0000, Duncan Booth wrote: > "F. GEIGER" wrote: > >> Sorry for not being clear. I did exec easy_install - no errors so far. >> But the egg was still there. I'd expected, that it was converted into >> .py-files somehow, which could be imported by my modules. > > The .egg file should have been copied into your site-packages. Python can > import directly from a .egg file (it is a zip archive containing .py > files), or you can give easy_install an --always-unzip argument in which > case it creates a folder with the same name (including the .egg extension) > in site-packages and unzips the egg there. Thanx a lot! "sudo python setup.py easy_install --always-unzip ." did the trick Kind regards Morpheus > > Forcing an unzip can be useful if you want to use tools like pydoc which > don't understand imports from zip files. > > If you run python interactively and "print sys.path" then you should see > any egg files you have installed have been added to the path. From fredrik at pythonware.com Tue Dec 12 14:50:03 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Dec 2006 20:50:03 +0100 Subject: How can I get involved In-Reply-To: <1165867719.421812.101400@l12g2000cwl.googlegroups.com> References: <1165856767.477175.276380@80g2000cwy.googlegroups.com> <1165867719.421812.101400@l12g2000cwl.googlegroups.com> Message-ID: Paul Boddie wrote: > I find it interesting that you've been using Python for so long and yet > haven't posted to this group before. c.l.python is just a small speck at the outer parts of the python universe. most python programmers don't even read this newsgroup, except, perhaps, when they stumble upon it via a search engine. From kentilton at gmail.com Tue Dec 12 14:53:05 2006 From: kentilton at gmail.com (Ken Tilton) Date: Tue, 12 Dec 2006 14:53:05 -0500 Subject: merits of Lisp vs Python In-Reply-To: <7x3b7lccjn.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7x3b7lccjn.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Ken Tilton writes: > >>>>The loop language is so complicated and confusing that I never >>>>bothered trying to learn it. >> >>That was my stance for about seven years of intense Lisp. Then the >>author of Practical Common Lisp did a nice job of breaking the whole >>mess up into sensible chunks and I picked it up. If one programs Lisp, >>one should learn Loop -- it is definitely worth the bother. I def >>regret not learning it sooner. > > > I don't really code in Lisp any more, I never felt a need for loop > when I was coding in Lisp, and I'm trying to move towards a style of > programming without loops (i.e. I'm playing with Haskell, which > doesn't have loops), giving me even less need for a hairy loop macro. Oh, my. time to trot out my "hey, X is cool, let's use it for everything!" rant. Freud may not have said, "Sometimes a cigar is just a cigar.", but sometimes (er, always) iteration is best handled with an iteration construct. Any craftsman can tell you, use the right tool for the job. the nice thing about Lisp's many paradigms is that the developer does not become a slave to any paradigm. I think all-rules-all-the-time Prolog is the poster boy for paradigm slavery. (I did try for a famous two months to use Prolog as a general-purpose programming language.) Just the sentence "I'm trying to program without loops" simply screams "category error", if you think about it. Mind you, I had great fun using a Logo which did not have iteration. Now I have fun with CL. They call it a big ball of mud, but I do not thnk there is a tool in that chest I have not used, just because that tool fit the problem best. It only looks like a ball of mud if one does not right much code, and that describes most Lispniks, so no wonder we ended up with Scheme. Oops, wrong flamewar. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From ihatespam at hotmail.com Tue Dec 5 23:10:14 2006 From: ihatespam at hotmail.com (Just Another Victim of the Ambient Morality) Date: Wed, 06 Dec 2006 04:10:14 GMT Subject: Looking for a decent HTML parser for Python... References: Message-ID: "Just Another Victim of the Ambient Morality" wrote in message news:qKqdh.303031$tl2.45967 at fe10.news.easynews.com... > I'm trying to parse HTML in a very generic way. > So far, I'm using SGMLParser in the sgmllib module. The problem is > that it forces you to parse very specific tags through object methods like > start_a(), start_p() and the like, forcing you to know exactly which tags > you want to handle. I want to be able to handle the start tags of any and > all tags, like how one would do in the Xerces C++ XML parser. In other > words, I would like a simple start() method that is called whenever any > tag is encountered. How may I do this? > Thank you... Okay, I think I found what I'm looking for in HTMLParser in the HTMLParser module. Thanks... From gagsl-py at yahoo.com.ar Sat Dec 30 00:26:58 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Sat, 30 Dec 2006 02:26:58 -0300 Subject: I want to see all the variables In-Reply-To: References: <1167407850.869640.34780@a3g2000cwd.googlegroups.com> Message-ID: <7.0.1.0.0.20061230021628.00fe22f8@yahoo.com.ar> At Friday 29/12/2006 13:17, Steven D'Aprano wrote: > >>> X.__dict__ >{'__module__': '__main__', '__doc__': None} > >>> X.__name__ >'X' > >>> X.__bases__ >() > >Now that's interesting... if __name__ and __bases__ don't live in the >class __dict__, where do they live? What other methods and attributes are >invisibly in X? They live in the C structure implementing the type; members tp_bases and tp_name respectively. Most predefined type/class attributes have an slot for storing its value, for efficiency. See include/object.h -- 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 From python at hope.cz Tue Dec 12 13:50:10 2006 From: python at hope.cz (Lad) Date: 12 Dec 2006 10:50:10 -0800 Subject: Large files uploading Message-ID: <1165949410.458162.38300@79g2000cws.googlegroups.com> If a user will upload large files via FTP protocol, must the user have an FTP client on his computer or is it possible to use a similar way to "http form" comunication? Or is there another way( besides FTP) how to upload large files to server? Thank you he help Lad. From pavlovevidence at gmail.com Fri Dec 1 18:44:40 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 1 Dec 2006 15:44:40 -0800 Subject: What are python closures realy like? References: Message-ID: <1165016680.236580.73510@80g2000cwy.googlegroups.com> Karl Kofnarson wrote: > Hi, > while writing my last program I came upon the problem > of accessing a common local variable by a bunch of > functions. > I wanted to have a function which would, depending on > some argument, return other functions all having access to > the same variable. An OO approach would do but why not > try out closures... > So here is a simplified example of the idea: > def fun_basket(f): > common_var = [0] > def f1(): > print common_var[0] > common_var[0]=1 > def f2(): > print common_var[0] > common_var[0]=2 > if f == 1: > return f1 > if f == 2: > return f2 > If you call f1 and f2 from the inside of fun_basket, they > behave as expected, so common_var[0] is modified by > whatever function operates on it. > However, calling f1=fun_basket(1); f2 = fun_basket(2) and > then f1(); f2() returns 0 and 0. It is not the way one would > expect closures to work, knowing e.g. Lisp make-counter. Lisp works the same way. * (defun fun_basket (f) (let ((common_var 0)) (defun f1 () (print common_var) (setf common_var 1)) (defun f2 () (print common_var) (setf common_var 2)) (if (eq f 1) #'f1 #'f2))) FUN_BASKET * (setf (symbol-function 'f1a) (fun_basket 1)) ; Converted F1. ; Converted F2. # * (setf (symbol-function 'f2a) (fun_basket 2)) # * (f1a) 0 1 * (f2a) 0 2 > Any ideas what's going on behind the scene? Every time you call the function, a new closure is created. Carl Banks From mail at microcorp.co.za Sat Dec 16 00:42:53 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 16 Dec 2006 07:42:53 +0200 Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com><1166187479.167471.169270@n67g2000cwd.googlegroups.com> Message-ID: <019701c720db$0fd82a60$03000080@hendrik> "Christoph Zwerschke" wrote: > I don't think it's a problem of false logic but the problem that > "homogenous data" is not defined. > > We probably agree that it usually makes perfect sense to use tuples for > coordinates. But in certain mathematical algorithms it also makes sense > to ask for the number of zero components of a coordinate tuple - the > count() method would be helpful here. > > The statement "if you are looking for index() or count() for your > tuples, you're using the wrong container type" is too extreme I think. I > would agree with "it *may indicate* that you should better use lists". >From a practical point of view, the only reason to use a tuple instead of a list for anything seems to be that you want to use it as a key in a dict... Otherwise, why bother with these recalcitrant things that you can't change or index, or append to or anything that lists allow? - Hendrik From gagsl-py at yahoo.com.ar Fri Dec 8 04:01:18 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 08 Dec 2006 06:01:18 -0300 Subject: autoadd class properties In-Reply-To: <1165567093.167813.109000@j44g2000cwa.googlegroups.com> References: <1165567093.167813.109000@j44g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061208055843.04087ff8@yahoo.com.ar> At Friday 8/12/2006 05:38, manstey wrote: >Is this clear? I'm sorry, not for me. Some code showing how things are used now and how you would like it to be, would help. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From cyberco at gmail.com Fri Dec 29 08:35:37 2006 From: cyberco at gmail.com (cyberco) Date: 29 Dec 2006 05:35:37 -0800 Subject: Scaling pictures In-Reply-To: <1167312754.991317.76370@n51g2000cwc.googlegroups.com> References: <0001HW.C1B960C5006E7E2DF0488648@News.Individual.DE> <1167312754.991317.76370@n51g2000cwc.googlegroups.com> Message-ID: <1167399337.932875.190370@s34g2000cwa.googlegroups.com> PIL is certainly a fine option, but I noticed that the scaled images (scaled with the ANTIALIAS filter) are not as good as you can get with, say, Photoshop. Maybe I'm just expecting too much, but I wish I could choose a higher quality rescaling algorithm. PIL still rocks though. On Dec 28, 2:32 pm, "Ravi Teja" wrote: > Kajsa Anka wrote: > > I would like some advice, I'm going to build a small app that will, among > > other things, scale images so that they can be published on a web site. I've > > never done any image processing in python before so I would like to ask what > > is the best way of doing this, I will not do anything else than scaling the > > images. > > > I found the Python Imaging Library but before I dive into that I would like > > to know if there is a better way of doing this.Yes. Python Imaging Library (PIL) is the preferred Python way to do > this. The example is right in the documentation.http://www.pythonware.com/library/pil/handbook/image.htm > > from PIL import Image > import glob, os > > size = 128, 128 > > for infile in glob.glob("*.jpg"): > file, ext = os.path.splitext(infile) > im = Image.open(infile) > im.thumbnail(size, Image.ANTIALIAS) > im.save(file + ".thumbnail", "JPEG") From kloro2006 at gmail.com Tue Dec 12 13:07:49 2006 From: kloro2006 at gmail.com (tom arnall) Date: Tue, 12 Dec 2006 10:07:49 -0800 Subject: object data member dumper? References: <1165938723.529980.234270@16g2000cwy.googlegroups.com> Message-ID: <457ee238$0$15522$88260bb3@free.teranews.com> George Sakkis wrote: > tom arnall wrote: >> >object data member dumper? >> >George Sakkis george.sakkis at gmail.com >> >Wed Nov 8 03:42:47 CET 2006 >> >> > tom arnall wrote: >> > >> > > Bruno Desthuilliers wrote: >> > > >> > > > tom arnall a ?crit : >> > > >> does anyone know of a utility to do a recursive dump of object >> > > >> data members? >> > > >> >> > > > >> > > > What are "object data members" ? (hint: in Python, everything is an >> > > > object - even functions and methods). >> > > > >> > > > What is your real use case ? >> > > >> > > something like: >> > > >> > > class A: >> > > def __init__(self, p1): >> > > self.p1 = p1 >> > > >> > > class B: >> > > def __init__(self,p1, p2): >> > > self.a = A(p1) >> > > self.p2 = p2 >> > > self.v1 = '3' >> > > >> > > class C: >> > > def __init__(self): >> > > self.b = B(3,4) >> > > self.p3 = 5 >> > > >> > > class D: >> > > def __init__(self): >> > > self.v2=2 >> > > self.o1 = C() >> > > self.o2 = B(11,12) >> > > >> > > >> > > d = D() >> > > objectDataDumper(d) >> > > >> > > >> > > would produce something like: >> > > >> > > object of class D with: >> > > o1(C)->b(B)->a(A)->p1=3 >> > > o1(C)->b(B)->p2=4 >> > > o1(C)->b(B)->v1=3 >> > > o1(C)->p3=5 >> > > o2(B)->a(A)->p1=11 >> > > o2(B)->p2=12 >> > > o2(B)->v1=3 >> > > v2=2 >> > > >> > > >> > > tom arnall >> > > north spit, ca >> > > usa >> > >> > At first I thought pickle would be what you're looking for, because >> > that's exactly what it does; it dumps arbitrary objects, without >> > choking on recursive references. Only problem is, it's not human >> > readable (even in its ascii form).If you want it to be human readable, >> > you may check the gnosis.xml.pickle module >> > (http://cheeseshop.python.org/pypi/Gnosis_Utils/1.2.1-a). That's the >> > output of gnosis.xml.pickle.XML_Pickler(d).dumps() on your example: >> > >> > >> > >> > >> > >> > > > class="B"> >> > > > class="A"> >> > >> > >> > >> > >> > >> > > > class="C"> >> > >> > > > class="B"> >> > > > class="A"> >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > I've also written a similar but less verbose xml dumper. The gnosis.xml >> > package provides a bidirectional mapping between objects and xml >> > (objects -> xml and xml->object) and therefore has to be precise; mine >> > simply generates a nice xml dump of the object which isn't necessarily >> > reversible. Here's the output for your example: >> > >> > >> > >> > >> > >> > 3 >> > >> > 4 >> > 3 >> > >> > 5 >> > >> > >> > >> > 11 >> > >> > 12 >> > 3 >> > >> > 2 >> > >> > >> > >> > If you find it suits you better, I'll try to make it available >> > somewhere (probably in the cookbook). >> > >> > George >> > >> >> >> George, >> >> did you ever put up your object dumper on the net? > > Here it is: http://rafb.net/paste/results/C0NHBp27.html > Mostly undocumented but works for most common types. Most methods are > overridable so you can customize the dumping for a specific type (or > types) in a subclass. > Superb! Thanks very much. tom arnall north spit, ca usa Make cyberspace pretty: stamp out curly brackets and semicolons. Loosen up: the tests extend the compiler. -- Posted via a free Usenet account from http://www.teranews.com From ptmcg at austin.rr._bogus_.com Sun Dec 3 05:50:16 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 03 Dec 2006 10:50:16 GMT Subject: wxpython worked out but can't find api docs for download. References: Message-ID: "krishnakant Mane" wrote in message news:mailman.982.1165086141.32031.python-list at python.org... > hello all. > finally I got the accessibility issue out from wxpython. actually > almost got it out, but that's another story. > now my problem is that I can't gind a downloadable version of wxpython > api reference for the latest version or the latest api reference at > least. > I found the on-line version so please don't provide the same link. > when I opened it on line, it took about 8 minuts to get the wx package > come up on screen with over 600 links. > I need to have some off line reference for the wxpython api. > I have enough documentation to get started but I don't have the > extencive api references for events and other methods, properties and > attributes. > can some one point me to a .zip or .tar.gz version of the api docs for > wxpython? > thanking all. > Krishnakant. Also, there is much info at the wxPython wiki: http://wiki.wxpython.org/index.cgi/FrontPage -- Paul From dek at oliver.lbl.gov Mon Dec 4 12:21:14 2006 From: dek at oliver.lbl.gov (David E. Konerding DSD staff) Date: Mon, 4 Dec 2006 17:21:14 +0000 (UTC) Subject: How do I print a numpy array? References: <12n1b51i11rhv5e@corp.supernews.com> <1165017000.500270.188540@73g2000cwn.googlegroups.com> Message-ID: On 2006-12-02, Robert Kern wrote: > Beliavsky wrote: >> When I print an array in any language, I (and I think most programmers) >> expect by default to have all elements displayed. Matlab, R, and >> Fortran 95 have somewhat similar arrays to numpy, and that is what they >> do. I don't remember Numeric summarizing arrays by default. R has a >> "summary" function as well as a "print" function. > > There are pretty serious problems with interactive use and large arrays. > Formatting the string for a very large array can take a fair bit of time, often > much more than the computation that generated it. This has been a long-standing > frustration of many Numeric users. At the interactive prompt, if the statement > you just entered is taking a long time to execute and you Ctrl-C, odds are, the > traceback points you right in the middle of array2string(), not anything in the > actual computation itself. Since the interactive prompt prints things out > without the user explicitly asking for it, it's not enough simply to have two > functions available. > > numarray set the default to summarize, and numpy kept numarray's choice. I 100% approve of the summarization by default. It has saved me *many* times. Dave From gagsl-py at yahoo.com.ar Mon Dec 4 18:52:54 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 04 Dec 2006 20:52:54 -0300 Subject: Best way for inter-process communication in Python In-Reply-To: <4e8efcf50612040924lad6916fi188feef885cd0822@mail.gmail.com > References: <4e8efcf50612040924lad6916fi188feef885cd0822@mail.gmail.com> Message-ID: <7.0.1.0.0.20061204204853.020688b8@yahoo.com.ar> At Monday 4/12/2006 14:24, Hugo Ferreira wrote: >The client-side of this program is a function in PostgreSQL. For the >sake of simplicity, let's assume it is another program in Python that >will be asking the resident one for results on-demand. Let's also >assume that there will be dozens of concurrent requests. > >My problem is: what is the fastest, easiest way to accomplish this >inter-process communication? The data between them will be very small: >1Kb max per request. I've thought about SOAP, sockets and named >pipes... But since I have no experience on any of them using Python, I >can't decide which way is better... xmlrpc is an easy way and portable. If it's Windows only, named pipes in message mode are easy to implement too. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From kentilton at gmail.com Sat Dec 9 17:01:15 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 17:01:15 -0500 Subject: merits of Lisp vs Python In-Reply-To: <1165698244.563344.62270@73g2000cwn.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: mystilleef wrote: > Bill Atkins wrote: > >>Are any of these not subjective? > > > Objectivity is in the eye of the beholder. > > >>Lisp is much more than a functional language. > > > Maybe so. But I've only ever appreciated its functional aspects. I > wouldn't choose Lisp or its derivatives for OO related tasks even if > I'm high. But CLOS is the best OO there is. The OMG said so. It can do anything any other OO can do. Why /specifically/ would you not use it? This type of thread has no educational value unless one is specific; we already know what the posters like and prefer, so the only added value comes from being specific about language details. And funny put-downs. :) > > >>Uh huh. Can you cite examples of this? Sounds like you're just >>making stuff up here. Contrary to popular belief, writing a Lisp >>macro that warps your mind and introduces a totally un-CL-like >>semantics is extremely difficult. Most of the people who are good >>enough at CL to do it (I'm certainly not one of them) are also >>experienced enough to know when it's the right choice. > > > Any sizable Lisp applications will make extensive use of macros. Hopefully, because any sizeable app will have its sum functionality compartmentalized into internal little sub-APIs. These five/ten data structures and functions have been created to handle this recurring problem faced by higher-order functions. Sometimes dealing with that API requires boilerplate code to be written. Set things up. Make a call. Check the return status for xyz. etc etc. That boilerplate can become a macro, such as WITHOUT-C-DEPENDENCY: (defmacro without-c-dependency (&body body) `(let (*call-stack*) , at body)) *CALL-STACK* is internal to Cells and should not be exposed. It is cool that all I need do to defeat the entire Cells engine is bind one special variable, but maybe someday that will get hairier. if so, no problem, I just change the macro. Btw, without special variables, you would need: (let ((save-stack *call-stack*) (setf *call-stack* nil) (setf *call-stack* save-stack)) If you want to use a function instead of a macro and still hide the boilerplate, it would have to be: (without-c-dependency (lambda () )) Not the end of the world and at least one Lisp legend thinks that makes macros unnecessary. > Emacs > and magic ( the web framework) come to mind. My experience has shown > that nobody but the person who writes the DSL extension can maintain > their code. You and GvR are thinking of the case where a macro is used to create a whole new syntax, like LOOP (a mildly controversial part of standard Lisp). I have written more macros than you can imagine and only once even came close to it (but the language was just a list of things to do, nothing incomprehensible). I have never seen a macro which introduced a new language. Of course, we all keep saying this and you all keep repeating the opposite, so we do appreciate the excuse to repeatedly explain how macros are really used. :) > The benefits of extending a language in a domain specific > manner are exaggerated. Careful, there are laws now against cruelty to straw men. > My observation is that macros are important to > Lisp and it's derivative because they lack libraries to begin with. Damn! Exactly which macro would have saved me creating bindings to OpenGL? (I think you have a little category error going here.) > Common problems solved using macros in Lisp and friends are solved > using specialized libraries in most other languages. Damn! Exactly which macro would have saved me creating bindings to OpenGL? (I think you have a little category error going here.) > And I like the > specialized libraries route. Damn! Exactly which macro would have saved me creating bindings to OpenGL? (I think you have a little category error going here.) > Meta-programming just doesn't tickle my > fancy. It just spells maintainance nightmare. The whole idea of meta-programming is reducing coding and simplifying maintenance, so I have to wonder how much experience you have writing macros. Could you post a few? Macros come into play when we find a pattern in out code that is a level more abstract than straight token replacement (ala C) will support. My simple example above is just about avoiding typing LAMBDA, which I hate. :) More interesting macros take a look at the input source to the acro invocation and, instead of subsituting in a fixed template as does the C preprocessor, actively assembles template bits and input bits to produce the final result. Of course one has to be clever enough to see higher-order patterns and appreciate the vast productivity increase available in return for the effort of thinking through a macro -- well, i should note that often I do not create the macro until I see also that this bit of internal API will be coming up often enough (or will be changing often enough as I come to understand it) to make the effort of carving out a macro worthwhile -- or, yes, the point of macros will be lost on you. That's OK. I once knew a guy who cut and pasted code to create tens of duplicates rather than create a function. He was not stupid, but clearly there was something wrong upstairs. I think to him it was somehow "simpler" than getting involved with these complicated function things. Sound familiar? :) >>And Lisp environments all support getting the macroexpansion, >>documentation, and source of any unfamiliar macro you might happen >>upon, so really this is not as much of a problem as you might >>fantasize it to be. > > > How's this a good thing? I don't need a Python environment to grok > Python code. How would that be a bad thing? Do you do a lot of programming without a Python environment. But I love the wall of flak you are throwing up. :) > > >>I don't agree with a lot of what you say in this paragraph, but I >>you're right that libraries are crucial. That's why I wish there were >>more people writing Lisp libraries instead of being scared away by >>sheer fabrications like the stuff that's appearing in this thread. > > > People only contribute to things they understand and appreciate. > More > people would be writing Lisp libraries if it was worthwhile. We are, now that a few application programmers have landed on her shores. Most Lispniks are just useless groupie wannabes coding Java all day to pay the bills with no energy for programming when they get home. > Apparently, it doesn't seem to be. A few years ago, I tried to write an > editor is Scheme. The experience was appalling. Damn. I wish this was the quarterly Lisp vs Scheme flamewar. > I was able to write a > fully functional prototype editor in less than a week in Python. > Shockingly, at the time, I had no experience in Python. Guess which > community I was inclined to contribute to afterwards. I hear stories > similar to mine time and again, yet the Lisp community won't take heed. > They'd rather squeal about the superiority of macros and whine about > their frustrations in Python news groups. > You seem to be the unhappy one. We are just here correcting FUD. We are ecstatic with Lisp and would not want anyone to miss out on it because of your misnformation. No one cares if you try it and decide against or do not try it based on good information. But for someone to miss out on Lisp because of your deliberate misrepresentation would be a shame. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From phd at phd.pp.ru Mon Dec 18 14:14:56 2006 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 18 Dec 2006 22:14:56 +0300 Subject: SQLObject 0.8.0b1 Message-ID: <20061218191456.GB8065@phd.pp.ru> Hello! I'm pleased to announce the 0.8.0b1 release of SQLObject. This is the first beta of the new branch. Taking into account that it is a result of rather large job the beta period will be prolonged. Meanwhile the stable 0.7 branch will be maintained, and there will be at least 0.7.3 release. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.8.0b1 News and changes: http://sqlobject.org/devel/News.html What's New ========== Features & Interface -------------------- * It is now possible to create tables that reference each other. Constraints (in the DBMSes that support constraints) are added after the tables have been created. * Added ``createSQL`` as an option for sqlmeta. Here you can add related SQL you want executed by sqlobject-admin create after table creation. createSQL expects a string, list, or dictionary. If using a dictionary the key should be a dbName value (ex. 'postgres') and the value should be a string or list. Examples in sqlobject/tests/test_sqlobject_admin.py or at * Added method ``sqlhub.doInTransaction(callable, *args, **kwargs)``, to be used like:: sqlhub.doInTransaction(process_request, os.environ) This will run ``process_request(os.environ)``. The return value will be preserved. * Added method ``.getOne([default])`` to ``SelectResults`` (these are the objects returned by ``.select()`` and ``.selectBy()``). This returns a single object, when the query is expected to return only one object. The single argument is the value to return when zero results are found (more than one result is always an error). If no default is given, it is an error if no such object exists. * Added a WSGI middleware (in ``sqlobject.wsgi_middleware``) for configuring the database for the request. Also handles transactions. Available as ``egg:SQLObject`` in Paste Deploy configuration files. * New joins! ManyToMany and OneToMany; not fully documented yet, but still more sensible and smarter. * SELECT FOR UPDATE * New module dberrors.py - a hierarchy of exceptions. Translation of DB API module's exceptions to the new hierarchy is performed for SQLite and MySQL. * SQLiteConnection got a new keyword "factory" - a name or a reference to a factory function that returns a connection class; useful for implementing functions or aggregates. See test_select.py and test_sqlite_factory.py for examples. * SQLObject now disallows columns with names that collide with existing variables and methods, such as "_init", "expire", "set" and so on. Small Features -------------- * Configurable client character set (encoding) for MySQL. * Added a close option to .commit(), so you can close the transaction as you commit it. * DecimalValidator. * Added .expireAll() methods to sqlmeta and connection objects, to expire all instances in those cases. * String IDs. * FOREIGN KEY for MySQL. * Support for sqlite3 (a builtin module in Python 2.5). * SelectResults cannot be queried for truth value; in any case it was meaningless - the result was always True; now __nonzero__() raises NotImplementedError in case one tries bool(MyTable.select()) or "if MyTable.select():..." Bug Fixes --------- * Fixed problem with sqlite and threads; connections are no longer shared between threads for sqlite (except for :memory:). * The reference loop between SQLObject and SQLObjectState eliminated using weak references. For a more complete list, please see the news: http://sqlobject.org/devel/News.html Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From spe.stani.be at gmail.com Thu Dec 14 18:21:50 2006 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 14 Dec 2006 15:21:50 -0800 Subject: SPE website down? In-Reply-To: References: Message-ID: <1166138510.082636.65180@80g2000cwy.googlegroups.com> On 14 dec, 18:35, Laszlo Nagy wrote: > The home page of SPE (Stani's editor) is not available. > > http://pythonide.stani.be/ > > Is there a mailing list for this editor? > Where should I ask questions about it? > Where can I report bugs and make suggestions? For now use: http://developer.berlios.de/projects/python/ Until I find time to choose a new host and set up a new website. Stani From gagsl-py at yahoo.com.ar Thu Dec 7 18:19:01 2006 From: gagsl-py at yahoo.com.ar (gagsl-py at yahoo.com.ar) Date: 7 Dec 2006 15:19:01 -0800 Subject: write an update manager in python/wxPython In-Reply-To: <45788ffc$0$2448$db0fefd9@news.zen.co.uk> References: <1165522027.874287.206150@16g2000cwy.googlegroups.com> <45788ffc$0$2448$db0fefd9@news.zen.co.uk> Message-ID: <1165533541.009571.26510@73g2000cwn.googlegroups.com> On 7 dic, 19:04, Will McGugan wrote: > m.err... at gmail.com wrote: > > I have a small application for which I would like to write an update > > manager. I assume that the basics of it is to compare versions of the > > user's current application and a new one store in a new file on a > > particular URL. > Dont think there is a standard way of doing it. The way I have done it > in my applications is to keep an ini file containing the version number, > which is downloaded and compared against the version of the app. That > part is trivial to implement in python with urllib. I just point the > user at the download url when there is a new version. It would require a > little more effort if you want to have some kind of automatic update... There is a sample script (in tools/versioncheck in your Python directory) you could use as a starting point. Not a big deal... -- Gabriel Genellina From craigtw.online at gmail.com Mon Dec 4 17:16:25 2006 From: craigtw.online at gmail.com (Craig) Date: 4 Dec 2006 14:16:25 -0800 Subject: Opening colour BMPs with PIL Message-ID: <1165270585.753466.62440@l12g2000cwl.googlegroups.com> Hi there, I'm trying to open colour BMPs using PIL and I'm getting the following errors. Opening a 16 colour BMP I get: >>> im = Image.open("image.bmp") Traceback (most recent call last): File "", line 1, in im = Image.open("lightbulb2.bmp") File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1901, in open return factory(fp, filename) File "C:\Python25\Lib\site-packages\PIL\ImageFile.py", line 82, in __init__ self._open() File "C:\python25\lib\site-packages\PIL\BmpImagePlugin.py", line 164, in _open self._bitmap(offset=offset) File "C:\python25\lib\site-packages\PIL\BmpImagePlugin.py", line 120, in _bitmap raise IOError("Unsupported BMP compression (%d)" % compression) IOError: Unsupported BMP compression (2) >>> Opening a 256 colour BMP I get: >>> im = Image.open("image.bmp") Traceback (most recent call last): File "", line 1, in im = Image.open("image.bmp") File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1901, in open return factory(fp, filename) File "C:\Python25\Lib\site-packages\PIL\ImageFile.py", line 82, in __init__ self._open() File "C:\python25\lib\site-packages\PIL\BmpImagePlugin.py", line 164, in _open self._bitmap(offset=offset) File "C:\python25\lib\site-packages\PIL\BmpImagePlugin.py", line 120, in _bitmap raise IOError("Unsupported BMP compression (%d)" % compression) IOError: Unsupported BMP compression (1) >>> Opening a 24 bit colour BMP I get: >>> im = Image.open("image.bmp") Traceback (most recent call last): File "", line 1, in im = Image.open("image.bmp") File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1901, in open return factory(fp, filename) File "C:\Python25\Lib\site-packages\PIL\ImageFile.py", line 82, in __init__ self._open() File "C:\python25\lib\site-packages\PIL\BmpImagePlugin.py", line 164, in _open self._bitmap(offset=offset) File "C:\python25\lib\site-packages\PIL\BmpImagePlugin.py", line 96, in _bitmap raise IOError("Unsupported BMP header type (%d)" % len(s)) IOError: Unsupported BMP header type (108) >>> I am using Windows XP with Python 2.5. I can open monochrome BMPs fine but I don't want that. If you could help that would be greatly appreciated. Thanks and good luck. Craig From atkinw at rpi.edu Sat Dec 9 22:59:29 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sat, 09 Dec 2006 22:59:29 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: Steven D'Aprano writes: >> Or (defmethod name :after ..)? > > I don't even know what that means. And yet you continue to post as if you know Common Lisp... From steve at REMOVE.THIS.cybersource.com.au Mon Dec 25 18:33:05 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Tue, 26 Dec 2006 10:33:05 +1100 Subject: regular expression References: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> <4587dc54$0$18460$e4fe514c@dreader31.news.xs4all.nl> <1166967692.801622.295830@n51g2000cwc.googlegroups.com> <1167056220.806080.3760@f1g2000cwa.googlegroups.com> Message-ID: On Mon, 25 Dec 2006 06:17:00 -0800, deviantbunnylord at gmail.com wrote: > Hi folks, fairly new to the list(Python is my first programming > language, so I'm fairly new to the world of programming too)but this is > a question I've been wondering about since I started learning about the > re module. Are regular expressions what makes mark up languages > interpretable by webbrowsers? Web browsers have to render HTML, which implies they must be able to parse and interpret at least one markup language. _How_ they parse the markup is up to the browser developers. Since regular expressions are very good at certain types of text parsing, and are widely available, it is probable that regular expressions are used in some (many? all?) markup parsers, simply because it is widely available and is a good tool for some (but not all) parsing tasks. For example, Python's xmllib module uses reg exps to parse xml. Essentially, a regular expression engine is a super-charged "find" command on steroids. But that doesn't mean that reg exps are the only tool for the job. A markup parser doesn't necessarily need to use regexes. -- Steven. From p at ulmcnett.com Mon Dec 18 17:31:30 2006 From: p at ulmcnett.com (Paul McNett) Date: Mon, 18 Dec 2006 14:31:30 -0800 Subject: Good Looking UI for a stand alone application In-Reply-To: <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> References: <4584531c$0$13533$426a74cc@news.free.fr> <1hqhgxi.ld67gk15tzsikN%luc@honk-honk.com> <1hqk92g.1bxhoyqmy6he8N%luc@honk-honk.com> Message-ID: <458716C2.70304@ulmcnett.com> Luc Heinrich wrote: > Peter Decker wrote: > >> You're full of it. I routinely write GUI apps in Dabo for both Windows >> and Linux users, and they look just fine on both platforms. > > Oh, I'm sure you do. Now go try to run one of your Dabo apps on a Mac > and see how it looks/feels... :> It looks/feels like a native app on OS X. > Here's a hint directly taken from the Dabo homepage: "It also suffers > from the same display limitations on some platforms (most notably OS X), > but these should improve as the underlying toolkits improve." That was written a long time ago, and doesn't really apply anymore as a lot of effort has gone into wxPython over the past three years getting correctly interfaced to the OS X native API. (Note to self: rewrite that (prescient) paragraph). >> Using sizers is the key; layouts just 'look right' no matter what the native >> fonts and control sizes are. > > No, sizers are a tiny part of a much bigger problem. Sizers might be the > key to solve parts of the "look" problem, they don't address any of the > "feel" problem. Admittedly, to some extent there is a lowest common denominator problem inherent in any UI toolkit that tries to be crossplatform and use the platform's native GUI. But for the most part, that just isn't the case anymore in a practical sense. Why not use the best crossplatform native toolkit (wxPython) and then if you need native features that aren't provided, use ctypes or something to get access to the native GUI? Nothing in wxPython or Dabo prevents you from doing that. > But you clearly have a point here, so let me rephrase: "Crossplatform > toolkits/frameworks suck. All of them. No exception. UNLESS you only > target the lowest common denominator, aka Windows and its Linux > followers". Absolutism sucks. Please try not to be so black and white about things, and you may find you enjoy life more. > Now, the OP *explicitely* said that "[his] requirement is that the > application needs to look as good on Windows as on the Apple Mac", so > the rephrasing does not apply in this case. So here's a last try: > > "Crossplatform toolkits/frameworks suck. All of them. No exception. > ESPECIALLY if one of your target is Mac OS". It is much more nuanced than that. -- pkm ~ http://paulmcnett.com From john.thingstad at chello.no Sat Dec 9 20:33:12 2006 From: john.thingstad at chello.no (John Thingstad) Date: Sun, 10 Dec 2006 02:33:12 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <1165701024.138305.241500@j72g2000cwa.googlegroups.com> Message-ID: On Sun, 10 Dec 2006 01:29:43 +0100, Steven D'Aprano wrote: > > > Oh my god! Lisp can echo STRINGS to the interpreter???? Why didn't > somebody somebody tell me that!!!! That *completely* changes my mind > about > the language! > > I'm especially impressed that it knew I wanted them printed in uppercase > without being told. > > > Except it is not a string. It is a list of symbols. Hence the upcase. "This is how you write a string in Lisp" and that does preserve case. (If you want symbols to be case sensitive and default case to be lower then most Lisp's allow that, but the ANSI spec dosn't give a standard way.) -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From carsten at uniqsys.com Thu Dec 14 11:15:17 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Thu, 14 Dec 2006 11:15:17 -0500 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: <1166112917.3346.13.camel@dot.uniqsys.com> On Thu, 2006-12-14 at 15:57 +0000, Nick Maclaren wrote: > In article , > "Fredrik Lundh" writes: > |> > |> > The point is that an index method makes sense on ANY data structure that > |> > can be subscripted by an integer value but, for reasons that aren't at > |> > all clear, is not defined for Python tuples. There is no technical or > |> > mathematical reason why it shouldn't be. > |> > |> so where would you put such an "index" implementation so it would work on > |> ANY data structure that can be subscripted by an integer value ? > > In the same place you put the subscription method, clearly. Clearly not, because that would force *every* object that implements __getitem__ to also implement index. And to verify the truth of your assertion that index makes sense for "ANY data structure that can be subscripted by an integer value", consider the following theoretical but conceivable examples: 1) A mailbox object that returns the i-th message on subscripting. 2) A scroll cursor in a database that returns the i-th row of the result set. 3) A prime number generator that calculates the i-th prime number. Does .index() make sense for them? How would it be implemented? -Carsten From nono at hotmail.com Sat Dec 30 18:06:53 2006 From: nono at hotmail.com (Osiris) Date: Sun, 31 Dec 2006 00:06:53 +0100 Subject: python , Boost and straight (but complex) C code References: <0d2dnZZ8as4TSgvYnZ2dnUVZ_q_inZ2d@speakeasy.net> Message-ID: On Sat, 30 Dec 2006 13:19:28 -0800, Erik Max Francis wrote: >Osiris wrote: > >> I have these pieces of C-code (NOT C++ !!) I want to call from Python. >> I found Boost. >> I have MS Visual Studio 2005 with C++. >> >> is this the idea: >> I write the following C source file: >> ============================ >> #include >> #include >> >> namespace { // Avoid cluttering the global namespace. > >iostream and namespaces are both most definitely C++ features, not C. yes, but C can be compiled with a C++ compiler, One can put C code in C++ source.... Boost should not complain... should it ? Boost text is all about C++.. so... C should not be a problem... From Eric_Dexter at msn.com Sun Dec 31 00:10:55 2006 From: Eric_Dexter at msn.com (Eric_Dexter at msn.com) Date: 30 Dec 2006 21:10:55 -0800 Subject: looking for a better way to call a file. Message-ID: <1167541855.474814.53370@v33g2000cwv.googlegroups.com> I have been auto-generating .bat files and then running os.startfile('whatever.bat'). I don't seem to be having much luck when I try other methods. All of a sudden I am stuck in a situation where I need the program that is calling to end and a new program to start (because otherwise I get several uneeded copies). csoundgrid4.csgrid(arrg1, """;""", filename) with this by executing the main function os3.execvp('python', 'csoundgrid4.py', arrg1, """;""", filename) and the program just ends. I would also be glad to get rid of all the bats that I generate when I run an external program like csound. The command line I run is somthing like csound play.orc play.sco I haven't had much luck using os.startfile with arguments Hopefully this is an easy question and any help would be apreaceated (befour my computer gets rabies) http://www.dexrow.com From nospam at nospam.com Tue Dec 12 18:44:34 2006 From: nospam at nospam.com (3c273) Date: Tue, 12 Dec 2006 15:44:34 -0800 Subject: How to upload a file References: <1165925494.589658.148370@80g2000cwy.googlegroups.com> Message-ID: "Lad" wrote in message news:1165925494.589658.148370 at 80g2000cwy.googlegroups.com... > Users needs to upload big files upto 100MB.So I think that FTP protocol > would be a solution, but how can I allow users to select the right file > ,on their local disk, via a file dialog ? > > Thank you for your ideas > L. > import tkFileDialog help(tkFileDialog) Hope this helps. Louis From ptmcg at austin.rr._bogus_.com Tue Dec 19 11:10:40 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 19 Dec 2006 16:10:40 GMT Subject: permutations - fast & with low memory consumption? References: Message-ID: <4aUhh.55069$qp1.11462@tornado.texas.rr.com> "Christian Meesters" wrote in message news:em8tlg$9ka$1 at news1.zdv.uni-mainz.de... > Hi, > > I'd like to hack a function which returns all possible permutations as > lists > (or tuples) of two from a given list. So far, I came up with this > solution, > but it turned out to be too slow for the given problem, because the list > passed ("atomlist") can be some 1e5 items long: > > def permute(atomlist, size = 2): > """ > returns a list of atoms grouped by two > """ > if not size or not atomlist: > return [atomlist[:0]] > else: > result = list() > for i in xrange(len(atomlist)): > pick = atomlist[i:i+1] # sequence slice > remainder = atomlist[:i] + atomlist[i+1:] # keep [:i] part > for x in __permute(remainder, size = size - 1): > result.append(pick + x) > return result > > Does anybody know a solution which consumes less memory and is possibly > faster, perhaps using generator expressions? All my attempts so far > failed. > > Any help appreciated! > TIA > Christian Am I correct in understanding that you want to find the permutations of a list up to 1e5 elements in length, taken 2 or more at a time? FYI, P(1e5,2) evaluates to just under 10 billion, so I would suggest some implementation other than a function that returns a list of all of the permutations (think "generator"). Wikipedia also includes a pseudocode algorithm for computing permutations (http://en.wikipedia.org/wiki/Permutation), but beware, it appears to be 1-based. -- Paul From m.yanowitz at kearfott.com Thu Dec 7 07:02:50 2006 From: m.yanowitz at kearfott.com (Michael Yanowitz) Date: Thu, 7 Dec 2006 07:02:50 -0500 Subject: Best way to split up lines - RE: About the 79 character line recommendation In-Reply-To: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com> Message-ID: <012601c719f7$9e719990$0d7d12ac@kearfott.com> Hello: I too don't like large lines. However in the following case, and multi-level indentations, I find it unavoidable. Here is one huge statement I haven't been able to split onto multiple lines. What would be the best way to split the following line (Python doesn't like me to split it up between the comma-separated parameters): top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, numberOfLabels, dataWord = struct.unpack("!H4BH20BHI", strMessage) Thanks in advance: Michael Yanowitz -----Original Message----- From: python-list-bounces+m.yanowitz=kearfott.com at python.org [mailto:python-list-bounces+m.yanowitz=kearfott.com at python.org]On Behalf Of Ramon Diaz-Uriarte Sent: Wednesday, December 06, 2006 5:12 PM To: Steve Bergman Cc: python-list at python.org Subject: Re: About the 79 character line recommendation On 5 Dec 2006 13:28:22 -0800, Steve Bergman wrote: (...) > > I'm finding 100 to be a nice balance. It forces me not to be lazy and > allow really long lines, but allows me to format so as to make the > meaning most clear. > But if you use some advanced editors (such as Emacs) that easily allow you to see/edit the same file in two buffers side by side, then going beyond 80 chars is often a bad idea, specially if you use a laptop. (And, of course, there is the eternal issue of doing a simple "a2ps" to print some code; longer than 80 and you often have hard to read pages). Best, R. -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz -- http://mail.python.org/mailman/listinfo/python-list From rzantow at gmail.com Tue Dec 5 20:19:28 2006 From: rzantow at gmail.com (rzed) Date: Tue, 05 Dec 2006 20:19:28 -0500 Subject: PythonTidy References: Message-ID: Chuck Rhode wrote in news:mailman.1125.1165331060.32031.python-list at python.org: > That went well. PythonTidy has been looked at at least 10**2 > times, and I have received a couple of complaints, which I hope > I have addressed satisfactorily -- plenty good enough for a beta > test. The basic concept stands. > > PythonTidy.py cleans up, regularizes, and reformats the text of > Python scripts: > > http://www.LacusVeris.com/PythonTidy/PythonTidy.python > > What next? Is it appropriately submitted to the Cheese Shop? > I ran PythonTidy on a wxPython sample, and found that wx.CONSTANTS were being translated to wx.Constants, which won't do at all. In general, there is very little case manipulation that should be done in a case-sensitive language; I suppose this is controllable by one or more of the options, but it wasn't clear on casual observation what would do the trick. The idea of PythonTidy is not bad, but there should be a minimal option that essentially reindents and nothing more. Adding other style preferences should (in my opinion) be something like checklist items. For example, I don't necessarily need a shebang or coding line for my purposes, but without going into the code and commenting out lines, I can't readily suppress them. As it stands now, I can't trust PythonTidy to do the right thing on unfamiliar code, and I can't readily try out various options by simply activating or deactivating them; if I could, it would be much more useful to me. -- rzed From ilias at lazaridis.com Tue Dec 19 11:12:40 2006 From: ilias at lazaridis.com (Ilias Lazaridis) Date: 19 Dec 2006 08:12:40 -0800 Subject: SQLALCHEMY - Method to have the last word, by Michael Bayer In-Reply-To: <4uqgeuF19khhgU1@mid.uni-berlin.de> References: <1166543077.605993.276770@80g2000cwy.googlegroups.com> <4uqgeuF19khhgU1@mid.uni-berlin.de> Message-ID: <1166544760.081480.44920@n67g2000cwd.googlegroups.com> ?/? Diez B. Roggisch ??????: ... (several off-topics) Please control yourself. ?/? metaperl: >>> TurboEntity was quite sweet. Supposedly a complete rewrite as a new >>> product is on its way though. Ilias Lazaridis: >>the first major problem of this rewrite: >>it happens 'silently' (non-public) 3 projects (TurboEntity, ActiveMapper, and one unpublished) join, in order to provide an better ORM layer for Python. How is the project moving on? How can one contribute? I don't know - does anyone have more information? . -- http://case.lazaridis.com/wiki/Persist From mail at microcorp.co.za Wed Dec 13 10:10:03 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Wed, 13 Dec 2006 17:10:03 +0200 Subject: Is anyone using Python for embedded applications? References: <457EEC35.3090104@mvista.com> <1166008231.413891.180380@73g2000cwn.googlegroups.com> Message-ID: <000201c71f3b$16820620$03000080@hendrik> "Paul Boddie" wrote: > Interesting! Any links, or is it related to the Telit hardware already > discussed? telit it was... - Hendrik From bignose+hates-spam at benfinney.id.au Wed Dec 13 21:01:50 2006 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Thu, 14 Dec 2006 13:01:50 +1100 Subject: The Famous Error Message: "ImportError: No module named python_script" References: <1166058999.836982.112040@n67g2000cwd.googlegroups.com> Message-ID: <878xhbb5gx.fsf@benfinney.id.au> "rich murphy" writes: > I am studying Python language. Welcome! Allow me to direct you to the Python tutorial: Please take the time to work through all the exercises in that document, understanding each one before moving on. I recommend this because: > I placed the the script called "python_script" in C:\Python25 > directory where all the other Python files are. you would not make this mistake if you had already worked through the tutorial. Enjoy! -- \ "On the other hand, you have different fingers." -- Steven | `\ Wright | _o__) | Ben Finney From aspmanualator_1234567890 at yahoo.com Mon Dec 18 23:25:32 2006 From: aspmanualator_1234567890 at yahoo.com (Asper Faner) Date: 18 Dec 2006 20:25:32 -0800 Subject: regular expression Message-ID: <1166502332.519705.298950@j72g2000cwa.googlegroups.com> I seem to always have hard time understaing how this regular expression works, especially how on earth do people bring it up as part of computer programming language. Natural language processing seems not enough to explain by the way. Why no eliminate it ? From gandalf at designaproduct.biz Tue Dec 12 10:45:32 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Tue, 12 Dec 2006 16:45:32 +0100 Subject: Validate XML against a set of XSD files, with Python Message-ID: <457ECE9C.8030901@designaproduct.biz> Do you know an open source lib that can do $subject? Thanks, Laszlo From bj_666 at gmx.net Thu Dec 21 11:13:36 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Thu, 21 Dec 2006 17:13:36 +0100 Subject: Displaying contents of a file using PyWin References: <1166706266.025197.199620@79g2000cws.googlegroups.com> <1166716722.937893.297670@79g2000cws.googlegroups.com> Message-ID: In <1166716722.937893.297670 at 79g2000cws.googlegroups.com>, MiguelS wrote: > import win32ui > from pywin.mfc import docview > > t = object_template() > d = t.OpenDocumentFile("d:/temp/music.log", True) > > Crashes PythonWin What do you mean by `crashes`? Any chance you get a name error like:: NameError: name 'object_template' is not defined ? Ciao, Marc 'BlackJack' Rintsch From arkanes at gmail.com Thu Dec 28 11:37:14 2006 From: arkanes at gmail.com (Chris Mellon) Date: Thu, 28 Dec 2006 10:37:14 -0600 Subject: __getattr__ possible loop In-Reply-To: <4866bea60612280825r58ac878avf2615c799ef5384@mail.gmail.com> References: <1167314779.170915.145680@48g2000cwx.googlegroups.com> <1167320704.931970.175330@42g2000cwt.googlegroups.com> <4866bea60612280825r58ac878avf2615c799ef5384@mail.gmail.com> Message-ID: <4866bea60612280837n66a8d6cbvef45c4fd80adef73@mail.gmail.com> On 12/28/06, Chris Mellon wrote: > On 28 Dec 2006 07:45:05 -0800, bearophileHUGS at lycos.com > wrote: > > Maksim Kasimov: > > > how to improve the situation depends on what do you expect to get by calling "T().method()" > > > > You are right, sorry for being cryptic. I think that's a kind of bug of > > Python (produced maybe by an infinite loop), so an improvement can be a > > traceback or some automatic breaking of that loop. Note that my problem > > comes from using Psyco that segfaults in that situation (if you have > > Psyco installed you can decomment two lines to see that). I think that > > using normal code Python+Psyco don't have to segfault, but I know this > > is tricky situation, so if no simple "solutions" can be found, then > > it's not a important thing and it can be ignored. > > > > What I find most interesting is that you don't crash out because of > hitting the recursion limit. My brief testing shows something odd > going on - when the stack depth gets to almost 1000 (the recursion > limit on my system) it knocks some stuff off the stack and the stack > limit never gets to the limit. Some sort of built in tail recursion? > Nothing so clever. dir() eats and ignores all exceptions, so when you hit the recursion limit it eats the RecursionLimitExceeded exception and continues merrily along the way. This is probably not good behavior... class Foo: def __getattr__(self, attr): raise SystemExit, "Don't call me, again, ever" f = Foo() f.method() #dies correctly dir(f) #continues happily From rpdooling at gmail.com Sat Dec 23 13:35:49 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 23 Dec 2006 10:35:49 -0800 Subject: Newbie: what is a usefull IDE for Python on Windows ? In-Reply-To: References: Message-ID: <1166898949.688988.285430@f1g2000cwa.googlegroups.com> in addition to the effbot link, search the group http://tinyurl.com/yyuxco From nono at hotmail.com Sat Dec 30 08:49:11 2006 From: nono at hotmail.com (Osiris) Date: Sat, 30 Dec 2006 14:49:11 +0100 Subject: python , Boost and straight (but complex) C code References: Message-ID: Visual C++ build log at: http://213.10.133.192/BuildLog.htm From bretthoerner at gmail.com Wed Dec 20 19:37:02 2006 From: bretthoerner at gmail.com (Brett Hoerner) Date: 20 Dec 2006 16:37:02 -0800 Subject: calling a class instance of function In-Reply-To: <1166660407.106759.78210@f1g2000cwa.googlegroups.com> References: <87zm9i5cub.fsf@pyenos.pyenos.org> <1166660407.106759.78210@f1g2000cwa.googlegroups.com> Message-ID: <1166661422.942044.229540@80g2000cwy.googlegroups.com> Brett Hoerner wrote: > Also, in order to call a function without arguments you still need to > use (), so you probably wanted to use pid.original() in your pid.add > call. Sorry, never mind this bit, I misread the line. But you do probably want to change the class test into a function test. Brett Hoerner From bj_666 at gmx.net Tue Dec 12 01:59:30 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Tue, 12 Dec 2006 07:59:30 +0100 Subject: Avoiding "invalid literal for int()" exception References: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> Message-ID: In , Gabriel Genellina wrote: > At Monday 11/12/2006 07:22, aine_canby at yahoo.com wrote: > >>elif int(uniList[0]) in range(0,10): > > Either of these will work to avoid an unneeded conversion: > > elif uniList[0] in "0123456789": > > elif uniList[0] in string.digits: > > elif uniList[0].isdigit(): The last does not work. Not only that it accepts numbers greater than 9 because it checks if the whole string consists of digits, it also accepts u'??' and other unicode digits. Ciao, Marc 'BlackJack' Rintsch From mpeters42 at gmail.com Wed Dec 20 14:33:17 2006 From: mpeters42 at gmail.com (Mark Peters) Date: 20 Dec 2006 11:33:17 -0800 Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects In-Reply-To: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> Message-ID: <1166643197.329196.44220@t46g2000cwa.googlegroups.com> > # Begin going through the loop > Townshp = Townshps.next() > while Townshps !="": > #Set the output name to be the same as input > outName = outputPath + "/" + Townshp + "land" + ".img" > Output_table = outputPath + "/" + Townshp + "table" + ".dbf" > #For each extract by Mask > gp.ExtractbyMask_sa (raster, Townshp, outName) > #For each tabluate area > gp.TabulateArea_sa (Townshp, "RITOWN5K_", outName, "VALUE", > Output_table, "98.425") > Townshp = Townshps.next() Warning: I know nothing about the Python ArcGIS stuff. The first thing that jumps out at me is your while condition. You are testing "Townshps" when it seems from the code that you should be testing "Townshp". However, the typical Python way to iterate through a list for be to use a for loop. Perhaps replace the while statement with: for Townshp in Townshps: and remove the "Townshp = Townshps.next()" lines If that doesn't do it, please post the entire traceback message that you are seeing (copy and paste it) and it should tell us a lot more about your error. From bjourne at gmail.com Sat Dec 23 17:58:31 2006 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sat, 23 Dec 2006 23:58:31 +0100 Subject: Getting the name of an assignment In-Reply-To: <1166913499.494219.250440@48g2000cwx.googlegroups.com> References: <1166913499.494219.250440@48g2000cwx.googlegroups.com> Message-ID: <740c3aec0612231458o2b1feb78y4d38c1b854e96d2d@mail.gmail.com> On 23 Dec 2006 14:38:19 -0800, Adam Atlas wrote: > Is it possible for an object, in its __init__ method, to find out if it > is being assigned to a variable, and if so, what that variable's name > is? I can think of some potentially ugly ways of finding out using > sys._getframe, but if possible I'd prefer something less exotic. > (Basically I have a class whose instances, upon being created, need a > 'name' property, and if it's being assigned to a variable immediately, > that variable's name would be the best value of 'name'; to make the > code cleaner and less redundant, it would be best if it knew its own > name upon creation, just like functions and classes do, without the > code having to pass it its own name as a string.) I guess you mean something like this: >>> olle = Person() >>> olle.name "olle" Instead of: >>> olle = Person("olle") >>> olle.name "olle" It is not possible without ugly hacks. What you could use instead is some kind of registry approach: reg = {} class Person: def __init__(self, name): self.name = name reg[name] = self >>> Person("olle") >>> reg["olle"].name "olle" I think there are thousand different ways you could solve it. -- mvh Bj?rn From steve at REMOVE.THIS.cybersource.com.au Sat Dec 30 21:56:20 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 31 Dec 2006 13:56:20 +1100 Subject: I want to see all the variables References: <45952426.1080800@websafe.com> <8yelh.90$Q4.82@newsfe02.lga> <459722fc$0$30313$9b4e6d93@newsspool1.arcor-online.net> Message-ID: On Sun, 31 Dec 2006 03:39:52 +0100, Rene Fleschenberg wrote: > johnf wrote: >> Very detailed. But I was attempting to debug some code which subclassed >> other code. I got a traceback that something like "no >> mySubClass.__source.query() did not exist". > > By (strong) convention, "__" means "not to be accessed from outside the > class, not even from subclasses". The author of the original class does > not want you to access that attribute. What does the author of the original class know about *my* needs and requirements? It may turn out that accessing his "private" attributes is exactly what I need to solve my problem. I'm with the Python philosophy on this one: post all the "Don't Touch This" warning signs you like, but if somebody really wants to access my private attributes, to do something I never even imagined, they should be allowed to. If they break something, well, that's their fault, not mine. I'm 100% in favour of language features which protect people from *accidentally* shooting themselves in the foot, but if somebody wants to, who am I to say they mustn't? -- Steven. From jon at ffconsultancy.com Sun Dec 3 12:01:27 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 03 Dec 2006 17:01:27 +0000 Subject: About alternatives to Matlab References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> Message-ID: <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> Carl Banks wrote: >> fill a (map3 (fun b c d -> b + c + d) b c d) >> >> which will be much faster because it doesn't generate an intermediate >> array. > > Ah, but, this wasn't about temporaries when you spoke of "eagerly > allocating arrays", was it? I had thought that all of the array operations were allocating new arrays at first but it seems that at least assignment to a slice does not. Does: a[:] = b[:] + c[:] allocate a temporary for b[:] + c[:]? > But yes, you're right, in this example > temporary arrays are created; arrays that Ocaml would not need. (I > don't exactly understand why you'd need a functional language to get > this optimization, though.) I thought that functional programming could get you both the brevity of Python's slicing and the performance of C's compilation but I was wrong. You can get the brevity of the Python approach in C. > You might have guessed that you can get rid of most temporary arrays, > at the expense of readability, with numpy. For example, replacing > > d1[:] = odd[:] - C1*even[:] > > with > > numpy.multiply(-C1,even,d1) > numpy.add(d1,odd,d1) > > eliminates the intermediate. No unnecessary array allocations; no > closures necessary. Right. Performance will probably go from 5x slower to 2x slower because you're traversing the arrays twice instead of once. > I'm curious whether this shared-slicing isn't, in some ways, > advantageous over the Ocaml way. That's exactly what I thought to start with. The author of F# is working on getting slicing into his language but the use of slicing in this Python benchmark corrupted my fragile little mind. Slicing is a terrible way to approach this problem if you're using a compiled language like F#. I first wrote an OCaml translation of the Python and wrote my own little "slice" implementation. I have since looked up a C++ solution and translated that into OCaml instead: let rec d4_aux a n = let n2 = n lsr 1 in let tmp = Array.make n 0. in for i=0 to n2-2 do tmp.(i) <- a.(i*2)*.h0+.a.(i*2+1)*.h1+.a.(i*2+2)*.h2+.a.(i*2+3)*.h3; tmp.(i+n2) <- a.(i*2)*.g0+.a.(i*2+1)*.g1+.a.(i*2+2)*.g2+.a.(i*2+3)*.g3; done; tmp.(n2-1) <- a.(n-2)*.h0 +. a.(n-1)*.h1 +. a.(0)*.h2 +. a.(1)*.h3; tmp.(2*n2-1) <- a.(n-2)*.g0 +. a.(n-1)*.g1 +. a.(0)*.g2 +. a.(1)*.g3; Array.blit tmp 0 a 0 n; if n > 4 then d4_aux a (n lsr 1) let d4 a = d4_aux a (Array.length a) Not only is that shorter than the Python, it is much faster: 0.56s C++ (direct arrays) 0.61s F# (direct arrays) 0.62s OCaml (direct arrays) 1.38s OCaml (slices) 2.38s Python (slices) 10s Mathematica 5.1 Note that all implementations are safe (e.g. C++ uses a.at(i) instead of a[i]). > I presume that in Ocaml, the way > you'd "share" array data is to create a closure can apply some > operation to selected elements of the array, returning the result. Yes. That is certainly one way of doing it. > But could this as easily modify the array in-place? Absolutely. A closure would capture a reference to the array. Arrays are mutable so you could alter the array from within the closure. In F# you could even execute the closures concurrently to alter different parts of the same array at the same time. I just tried that and it is actually slower to multithread this. > I presume a good > compiler could be able to inline the function and optimize the call to > an in-place operation, but I'm not sure how well this works in > practice. Surprisingly well it seems: F# and OCaml are almost as fast as C/C++! > Here's a version of D4_Transform that uses no temporary arrays (aside > from the work arrays s1, d1, and d2, which are allocated only once). > It's about 40% faster for me than the one with infix operations. I'd > be curious how it compares to a correct Ocaml version. (I'd still > expect Ocaml to be at least twice as fast.) I get: 1.57s Python (in-place) >> > It seems to >> > me a big help is the ability to fold multiple array operations into a >> > single loop, which is optimization a dynamically-typed language like >> > Python can't easily make. (It'd require are really smart JIT compiler >> > or some concessions in dynamicity.) >> >> Writing a JIT to compile this kind of stuff is easy. > > Eh, getting a JIT to do the optimization I spoke of in Python is not > easy. It would be relatively easy in a statically typed language. In > Python, it'd be tantamount to rewriting a dynamically reconfigurable > version of numpy--you'd have to duplicate numpy's complex > type-dispatching rules. There aren't any complicated types in the above code. In fact, there are only two types: float and float array. Type checking is easy in this case, compilation to C is also easy, then you just dispatch to the compiled C code when the types are ok. You would want to write your Python code like C code but that is shorter in this case. You may also want to flag code for compilation manually in order to avoid the overhead of compiling code unnecessarily. >> My point is that this is fundamentally bad code, > > Whoa, there. I realize that for people who prefer functional > programming, with their recursively reductionist way of thinking, it > might seem as if leaving any sort of reducibility in final result is > "fundamentally bad", but that's a pretty strong thing to say. I was referring to the slicing specifically, nothing to do with functional programming. My F# and OCaml code are now basically identical to the C++ code. >> so why bother trying to write a Python JIT? Why >> not just write in a better language for this task? Optimising within a >> fundamentally slow language seems silly to me. > > Because, for most people, language choice is not a greedy maximizing of > a single issue. Nobody who uses numpy is under the impression that it > can match a statically-typed language that is compiled to machine code > in peak performance. (Matlab is fair game, of course.) But speed is > not the only important thing. In this specific context (discrete wavelet transform benchmark), I'd have said that speed was the most important thing after correctness. > I use Python because it's a excellently designed language that fits my > overall needs, and numpy because sometimes I need more speed than > vanilla Python. Only when speed is critical (for example, 3D collision > detection) do I write an extension in a "better language for the task" > (i.e. C). Have you looked at languages like F#, OCaml, Haskell, SML and so on? They seem to offer the benefits of both worlds. > This is something that's quite popular in the numerically-intensive > computing community, BTW. Many people use Python to handle boring > stuff like file I/O, memory managment, and non-critical numerical > calculations, and write C or Fortran extensions to do the > numerically-intensive stuff. Yes, I appreciate that Python is hugely popular, I just don't understand why it is quite so popular. I found a series of lectures on VPython, showing some amazing stuff: http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries I just found some more interesting stuff here: http://www.phy.syr.edu/~salgado/software/vpython/ This is really great work but I can't help but wonder why the authors chose to use Python when other languages seem better suited. I'd like to work on raising people's awareness of these alternatives, and probably create some useful tools in the process. So I'm keen to learn what Python programmers would want/expect from F# and OCaml. What would it take to make you convert? -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists From Bulkan at gmail.com Thu Dec 14 23:26:05 2006 From: Bulkan at gmail.com (placid) Date: 14 Dec 2006 20:26:05 -0800 Subject: I'm looking for a pythonic red-black tree... In-Reply-To: References: Message-ID: <1166156765.008369.269080@16g2000cwy.googlegroups.com> Just Another Victim of the Ambient Morality wrote: > I need a red-black tree in Python and I was wondering if there was one > built in or if there's a good implementation out there. Something that, > lets face it, does whatever the C++ std::map<> allows you to do... > Thank you... try, http://py.vaults.ca/apyllo2.py/211227974 Cheers From neoedmund at gmail.com Wed Dec 27 10:18:22 2006 From: neoedmund at gmail.com (neoedmund) Date: 27 Dec 2006 07:18:22 -0800 Subject: newbie question: any better way to write this code? Message-ID: <1167232702.061737.25610@42g2000cwt.googlegroups.com> i want to let a byte array to be xor with some value. but code show below i wrote seems not so .. good..., any better way to write such function? thanks. [code] def xor(buf): bout=[] for i in range(len(buf)): x = ord(buf[i]) x ^= 123 bout.append(chr(x)) return "".join(buf) buf = "xxxxxxxx".encode("utf8") buf = xor(buf) From prouleau001 at gmail.com Tue Dec 12 13:15:35 2006 From: prouleau001 at gmail.com (Pierre Rouleau) Date: 12 Dec 2006 10:15:35 -0800 Subject: os.popen3 hangs in Windows XP SP1, SP2. Python 2.5 & 2.4. Consistent test case. In-Reply-To: <4u7v5pF15r8atU1@mid.individual.net> References: <1165857231.817280.152670@79g2000cws.googlegroups.com> <4u7v5pF15r8atU1@mid.individual.net> Message-ID: <1165947335.896741.159380@16g2000cwy.googlegroups.com> On Dec 12, 10:11 am, Thomas Guettler wrote: > Pierre Rouleau wrote: > > Hi all, > > > I have a consistent test case where os.popen3() hangs in Windows. The > > system hangs when retrieving the lines from the child process stdout. > > I know there were several reports related to os.popen3() hanging under > > Windows in this group before.I had a problem like this some time ago. But it was a problem that > would happen under any operating system. > > If there is output on stdout and stderr, you will get a dead lock sooner > or later. > > Example: The childprocess tries to write to stderr, and the > parent process reads from stdin. The buffer of stderr will > get full. The child will block. The parent will wait for ever. > > Seehttp://docs.python.org/lib/popen2-flow-control.html > > My hint: Always use popen4 > > You can get dead locks with popen4, too. But only if you > write to pipe.tochild. Thanks for replying Thomas. The reason I was using popen3() is that I need to parse the error stream and do something else with the stdout. My operation does not need to have concurrent operations of the parent and child. I could have used something file:: os.system('parent > log_stdout.txt 2> log_stderr.txt') and then parse the 2 files. I just wanted to avoid using the files to avoid having to have to deal with issues related to temporary file names if there where several process instance of the code running simultaneously. Now, from the reading of the above link, this means that If I want to be able to do what I want with pipes, avoiding deadlock means that: - In the parent program, the code should be something that looks like: stdin, stdout, stderr = os.popen3(command) stderr_value = list(stderr) stdout_value = list(stdout) pgm_exit_code = stdout.close() or 0 stdin.close() stderr.close() An the above would work only if one stream is written by the child at a time and stderr closed: for whatever: print >> sys.stderr, ' the error messages' os.close(sys.stderr.fileno()) for someother: print 'other stdout info' In my case, since I don't control the child program, I can assume that it does not follow the required order. I am launching nosetests which runs other test programs. I tried closing sys.stderr in the teardown of my test script and that removed the deadlock but caused other problems (because sys.stderr is used later by nosetests). So, in the end, it looks like I really don't have any choice: if I want to safely read both stdout and stderr in a way that is child program agnostic: I must use temporary files (or maybe use something like select). Right? Thanks again! -- Pierre Rouleau From fredrik at pythonware.com Wed Dec 6 11:27:09 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 06 Dec 2006 17:27:09 +0100 Subject: dict.has_key(x) versus 'x in dict' In-Reply-To: References: Message-ID: Roberto Bonvallet wrote: >> this is why e.g. >> >> string[:len(prefix)] == prefix >> >> is often a lot faster than >> >> string.startswith(prefix) > > This is interesting. In which cases does the former form perform better? no time to doublecheck right now, but iirc, last time we benchmarked this, slicing was faster when len(prefix) < 300 characters or so. From atkinw at rpi.edu Fri Dec 8 11:44:23 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Fri, 08 Dec 2006 11:44:23 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> Message-ID: Bjoern Schliessmann writes: > I think you acknowledged that the syntax is different and not > borrowed? Um, so does that mean that Python couldn't have borrowed other features? From jeffrey.aylesworth at gmail.com Fri Dec 8 18:40:10 2006 From: jeffrey.aylesworth at gmail.com (jeff) Date: 8 Dec 2006 15:40:10 -0800 Subject: Anyone use GD with pyhton? In-Reply-To: References: <1165616227.906934.306860@n67g2000cwd.googlegroups.com> Message-ID: <1165621210.834783.108600@73g2000cwn.googlegroups.com> thanks, it works :D Jonathan Curran wrote: > On Friday 08 December 2006 16:17, jeff wrote: > > could somebody explain to me how to install (or compile) GD for linux, > > so that it works in pyhton? > > Jefff, the gd-library's website is at http://www.boutell.com/gd/ and they have > a link there for download as well. It is highly likely that your linux > distribution already has a gd library package ready to install. Use your > package manager to search for 'gd' and you should get something. > > Now that you have that installed, you will need to get the python binding to > it. A quick google search revealed gdmodule @ > http://newcenturycomputers.net/projects/gdmodule.html > > Hope this helps, > > Jonathan From fredrik at pythonware.com Fri Dec 1 01:42:25 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 01 Dec 2006 07:42:25 +0100 Subject: Beautiful Soup Question: Filtering Images based on their width and height attributes In-Reply-To: <4866bea60611301334u6fc24f51jc202c491e5024048@mail.gmail.com> References: <1164919424.990637.98000@h54g2000cwb.googlegroups.com> <4866bea60611301334u6fc24f51jc202c491e5024048@mail.gmail.com> Message-ID: Chris Mellon wrote: >> I want to extract some image links from different html pages, in >> particular i want extract those image tags which height values are >> greater than 200. Is there an elegant way in BeautifulSoup to do this? > > Most image tags "in the wild" don't have height attributes, you have > to download the image to see what size it is. or at least a small portion of it; see the example at the bottom of this page for one way to get the size without downloading more than 1k or so: http://effbot.org/zone/pil-image-size.htm From simon at renderIHATESPAMmania.com Thu Dec 7 18:27:01 2006 From: simon at renderIHATESPAMmania.com (Simon Bunker) Date: Thu, 07 Dec 2006 23:27:01 +0000 Subject: per instance descriptors In-Reply-To: <1165470119.056918.295240@80g2000cwy.googlegroups.com> References: <45777908_4@mk-nntp-2.news.uk.tiscali.com> <1165470119.056918.295240@80g2000cwy.googlegroups.com> Message-ID: <4578A345.6050304@renderIHATESPAMmania.com> Carl Banks wrote: > Simon Bunker wrote: > >>Hi I have code similar to this: >> >>class Input(object): >> >> def __init__(self, val): >> self.value = val >> >> def __get__(self, obj, objtype): >> return self.value >> >> def __set__(self, obj, val): >> # do some checking... only accept floats etc >> self.value = val >> >>class Node(object): >> >> a = Input(1) >> b = Input(2) >> >>I realise that a and b are now class attributes - however I want to do this: >> >>node1 = Node() >>node2 = Node() >> >>node1.a = 3 >>node2.b = 4 >> >>And have them keep these values per instance. However now node1.a is 4 >>when it should be 3. > > [snip] > >>Is there any way of doing this nicely in Python? > > > The easiest way is to store the value in a hidden attribute of the > object. For instance: > > class Input(object): > def __init__(self,default,name): > self.default = default > self.name = name # or, create a name automatically > def __get__(self,obj,objtype): > return getattr(obj,self.name,self.default) > def __set__(self,obj,value): > setattr(obj,self.name,value) > > class Node(object): > a = Input(1,"_a") > b = Input(2,"_b") > > > Carl Banks > This does seem the easiest way - but also a bit of a hack. Would it work to assign to instance variables - each the class attribute sets the instance attribute with the same name? Or would that not work? Simon From soyouthinkimgonnalikethis at hotmail.com Wed Dec 13 15:40:38 2006 From: soyouthinkimgonnalikethis at hotmail.com (Eric Price) Date: Wed, 13 Dec 2006 15:40:38 -0500 Subject: test Message-ID: test _________________________________________________________________ Get the latest Windows Live Messenger 8.1 Beta version.?Join now. http://ideas.live.com From maksim.kasimov at gmail.com Wed Dec 13 11:49:27 2006 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Wed, 13 Dec 2006 18:49:27 +0200 Subject: Iterating over several lists at once In-Reply-To: <1166017627.699257.166740@16g2000cwy.googlegroups.com> References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> Message-ID: Hi, if you "needs to iterate over 3 lists at the same" and according your example > for (x1,x2,x3) in (l1,l2,l3): > print "do something with", x1, x2, x3 i has guessed that you need this (may be i was wrong): a = (1,2,3, 1) b = (4,5,6) c = (7,8,9, 2, 3) for x, y, z in zip(a, b, c): print x, y, z or this for x, y, z in map(None, a, b, c): print x,y,z Try both examples with tuples that have various length, they have difference Gal Diskin wrote: > Hi, > I am writing a code that needs to iterate over 3 lists at the same > time, i.e something like this: > > for x1 in l1: > for x2 in l2: > for x3 in l3: > print "do something with", x1, x2, x3 > > What I need to do is go over all n-tuples where the first argument is > from the first list, the second from the second list, and so on... > > > I was wondering if one could write this more easily in some manner > using only 1 for loop. > What I mean is something like this: > > for (x1,x2,x3) in (l1,l2,l3): > print "do something with", x1, x2, x3 > > Or maybe like this: > > for x1 in l1, x2 in l2, x3 in l3: > print "do something with", x1, x2, x3 > > However, this code obviously doesn't work... > > > I'd be very happy to receive ideas about how to do this in one loop and > with minimal initialization (if at all required). > > Thanks in advance, > Gal > -- Maksim Kasimov From gagsl-py at yahoo.com.ar Tue Dec 26 16:43:37 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Tue, 26 Dec 2006 18:43:37 -0300 Subject: Fuzzy string comparison In-Reply-To: <1167167314.463288.98960@48g2000cwx.googlegroups.com> References: <1167156330.915312.160320@48g2000cwx.googlegroups.com> <1167167314.463288.98960@48g2000cwx.googlegroups.com> Message-ID: <7.0.1.0.0.20061226184223.05d311b0@yahoo.com.ar> At Tuesday 26/12/2006 18:08, John Machin wrote: >Wojciech Mula wrote: > > Steve Bergman wrote: > > > I'm looking for a module to do fuzzy comparison of strings. [...] > > > > Check module difflib, it returns difference between two sequences. > >and it's intended for comparing text files, and is relatively slow. > >Google "python levenshtein". You'll probably find this a better fit for >typoed keys in a database. Other alternatives: trigram, n-gram, Jaro's distance. There are some Python implem. available. -- 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 From greg at cosc.canterbury.ac.nz Fri Dec 15 06:18:26 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:18:26 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1166090708.361757.197170@l12g2000cwl.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> Message-ID: <4ufemvF17of60U4@mid.individual.net> josephoswaldgg at hotmail.com wrote: > Neil Cerutti wrote: > >>On 2006-12-13, josephoswaldgg at hotmail.com >> wrote: >> >>>Expressions keep the same meaning even if you have to start >>>breaking them across lines, etc. >> >>Yes, it's the same way in Python. Of course, not everything is an >>expression in Python, so it's not saying quite as much. > > I fail to see how it is the same in Python. Probably what Neil is referring to is the fact that in Python, *within an expression*, indentation is not relevant. If you put parens around the whole expression, you can split it across lines however you like, and indent all the lines after the first one however you like, and it makes no difference. You could probably even use your Lisp-aware auto-indenter on the expression and it would do something reasonable. It's only *statement* nesting that's determined by relative horizontal position (which is a better way of thinking about it than "whitespace" -- the whitespace is only there to get things into the right position). And statements normally occupy one or more entire lines. > How does a manual correction process come out as simple as "don't > bother fixing the indentation if you don't care."? I think the point is that correcting indentation in Python is the equivalent of fixing misplaced parentheses in Lisp, and that they're about equally difficult. -- Greg From simon at brunningonline.net Wed Dec 13 05:43:46 2006 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 13 Dec 2006 10:43:46 +0000 Subject: YouTube written in Python In-Reply-To: References: <1165972697.387673.274570@j72g2000cwa.googlegroups.com> Message-ID: <8c7f10c60612130243o7a66a372w29156764b1f0da99@mail.gmail.com> On 12/13/06, Terry Reedy wrote: > wrote: > > Really? > > It's awful! > > Awesome? Well, it's got some pretty awful clips on it, but I don't think you can blame that on the technology. ;-) -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From kjellmf at gmail.com Wed Dec 6 08:48:14 2006 From: kjellmf at gmail.com (Kjell Magne Fauske) Date: 6 Dec 2006 05:48:14 -0800 Subject: PyMedia - some questions References: <1165401842.073048.50410@j44g2000cwa.googlegroups.com> Message-ID: <1165412893.884362.215610@79g2000cws.googlegroups.com> I'm not familiar with PyMedia, but this blog entry should be of interest: [Video Blogging using Django and Flash(tm) Video (FLV)] http://blog.go4teams.com/?p=56 It describes a toolchain for publishing AVI files as FLV on the web. ffmpeg is used together with a few other tools, but Python is used to glue it all togheter. - Kjell Magne Fauske Lad wrote: > Hi, > Can anyone answer the following questions? > > Question 1. > Can pyMedia create/convert FLV format? I explain in details. > As I would like > to publish videos for viewing in a browser , I need a good video > format. > I learned that FLV (Flash(tm) Video) format could be a good choice. > Or does anybody suggest a better format??? > > > Question 2 . > So, I need to convert a file captured from a video camera into that > FLV (Flash(tm) Video) format . > Can pyMedia do that or must I use ffmpeg directly > like this( to convert from avi to FLV ) > ffmpeg -i [sourcefile.avi] -acodec mp3 -ar 22050 -ab 32 -f flv -s > 320?240 [destfile.flv] > > > Question 3, > > This command creates a simple FLV format file, containing the video and > audio streams. In addition, FLV files need meta-information such as > duration, frames, etc. FLV movie players use this information to > calculate progress bar sliders and allow the user to fast-forward or > reverse through the video. > Can PyMedia add such meta- information? > > > Thank you for help > Lad. From rdiaz02 at gmail.com Sat Dec 9 04:45:12 2006 From: rdiaz02 at gmail.com (Ramon Diaz-Uriarte) Date: Sat, 9 Dec 2006 10:45:12 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7x64cl90xx.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> Message-ID: <624934630612090145vf1b84fdmdde9a957ffc56a@mail.gmail.com> On 08 Dec 2006 19:56:42 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: (...) > Lisp just seems hopelessly old-fashioned to me these days. A > modernized version would be cool, but I think the more serious > Lisp-like language designers have moved on to newer ideas. Paul, I find most of your comments well thought. But I don't follow these. Could you elaborate? a) "old-fashioned"? Is that supposed to be an argument? I guess addition and multiplication are old-fashioned, and so is calculus;so? I think "old-fashioned" should only carry a negative connotation in the fashion world, not in programming. b) "the more serious Lisp-like language designers have moved on to newer ideas." Can you elaborate? I am not an expert but by looking at, say, lambda the ultimate, I'd say this statement is just not true. And which are these "newer ideas"; what programming languages are incorporating them? (Scala, Mozart/Oz, Alice-ML, ...). R. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From gagsl-py at yahoo.com.ar Tue Dec 12 04:51:42 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 12 Dec 2006 01:51:42 -0800 Subject: Password, trust and user notification In-Reply-To: <1165896991.676350.118670@16g2000cwy.googlegroups.com> References: <1165896991.676350.118670@16g2000cwy.googlegroups.com> Message-ID: <1165917102.008439.146400@16g2000cwy.googlegroups.com> placid ha escrito: > I was going to write this script for a friend that notifies him via > logging onto his Gmail account and sending him an email to his work > email about some events occurring in the execution of the script. > If you enter your password into a script as input how can someone trust > the programmer that he will not send a email to himself containing his > password? Assuming this person does not know anything about programming > and this person knows nothing about programming ethics. You DON'T need the password for the receiving account just to send him an email! And you don't even need that special Gmail library, smtplib should be fine. -- Gabriel Genellina From usenet at kvr.at Sat Dec 16 16:02:02 2006 From: usenet at kvr.at (Christian Kastner) Date: Sat, 16 Dec 2006 22:02:02 +0100 Subject: Over my head with descriptors In-Reply-To: References: <1166119871.508417.239060@n67g2000cwd.googlegroups.com> Message-ID: <9ab0d$45845ecb$534197b5$23314@news.inode.at> Tim Roberts wrote: > "Sarcastic Zombie" wrote: >> Code included below. >> >> Basically, I've created a series of "question" descriptors, which each >> hold a managed value. This is so I can implement validation, and render >> each field into html automatically for forms. >> >> My problem is this: every instance of my "wizard" class has unique self >> values, but they share the exact same descriptor values. >> >> ... >> class Test(Wizard): >> grouping = [ >> [ 'age', 'weight' ], >> [ 'feet', 'inches' ], >> ['name', 'cash', 'fav_color', 'happy', 'birthday'] ] >> >> def __new__(self): >> age = Q_Integer("Your Age:", "age", 99) >> weight = Q_Integer("Your Weight:", "weight", 200) >> feet = Q_Integer("Feet tall:", "feet", 6) >> inches = Q_Integer("Inches Tall:", "inches", 0) >> name = Q_Chars("Your Name:", "name", max_length=15, required=True) >> cash = Q_Float("Money in hand?", "cash", required=True, >> default=55.50) >> fav_color = Q_Chars("Your favorite color?", "fav_color", >> required=True, max_length=50, choices=C_CHOICES) >> homezip = Q_Zip("Your zip code?", "homezip", required=True, ) >> happy = Q_Bool("Are you happy?", "happy", default=False) >> birthday = Q_Date("Your Birthday:", "birthday") > > The __new__ method is called with the CLASS as its first argument, not the > new instance. __new__ is supposed to RETURN the new instance. So, when > you set "age", you are setting a CLASS attribute that will be shared by all > instances. As long as "age" really is set on the class. In the code above, "age" is just a local variable. > Is there a reason you don't just use __init__ instead of __new__, and use > "self.age" and "self.weight" and so on? I was asking myself the same thing... Chris From eight02645999 at yahoo.com Fri Dec 15 01:47:23 2006 From: eight02645999 at yahoo.com (eight02645999 at yahoo.com) Date: 14 Dec 2006 22:47:23 -0800 Subject: skip last line in loops Message-ID: <1166165243.147217.133450@l12g2000cwl.googlegroups.com> hi, how can i skip printing the last line using loops (for /while) eg for line in open("file): print line. I want to skip printing last line of the file.thanks From sjmachin at lexicon.net Sat Dec 16 20:38:14 2006 From: sjmachin at lexicon.net (John Machin) Date: 16 Dec 2006 17:38:14 -0800 Subject: How to test if two strings point to the same file or directory? In-Reply-To: References: <1166317324.791635.274550@79g2000cws.googlegroups.com> Message-ID: <1166319494.222385.232890@t46g2000cwa.googlegroups.com> Tim Chase wrote: > > Comparing file system paths as strings is very brittle. Is there a > > better way to test if two paths point to the same file or directory > > (and that will work across platforms?) > > os.path.samefile(filename1, filename2) > os.path.sameopenfile(fileobject1, fileobject2) > Nice try, but they don't "work across platforms". From podi.ex at gmail.com Wed Dec 13 15:12:14 2006 From: podi.ex at gmail.com (Podi) Date: 13 Dec 2006 12:12:14 -0800 Subject: Windows SetLocalTime Message-ID: <1166040733.947268.80050@16g2000cwy.googlegroups.com> I am trying to set the system time on my Windows computer, but avoid using the DOS command (date, time). Does anyone know what parameter to pass to function SetLocalTime? CSharp ref http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/813b4ef504f77a43/24fc37c6c9148961?lnk=gst&q=SetLocalTime&rnum=2#24fc37c6c9148961 Thanks a bunch, P >>> import ctypes >>> import pywintypes >>> t = pywintypes.Time(time.time()) >>> ctypes.windll.kernel32.SetLocalTime(t) Traceback (most recent call last): File "", line 1, in ? ArgumentError: argument 1: exceptions.TypeError: Don't know how to convert parameter 1 >>> ctypes.windll.kernel32.SetLocalTime(ctypes.addressof(t)) Traceback (most recent call last): File "", line 1, in ? TypeError: invalid type From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 22:29:22 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 14:29:22 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: On Sat, 09 Dec 2006 17:01:15 -0500, Ken Tilton wrote: >> How's this a good thing? I don't need a Python environment to grok >> Python code. > > How would that be a bad thing? Do you do a lot of programming without a > Python environment. But I love the wall of flak you are throwing up. :) Actually, yes, sometimes it is useful to print code out and read it on the train, or in the bath, without the advantage of syntax highlighting, pretty-printing, parenthesis-balancing or code folding. Not necessarily as pleasant as having all those things, but it is nice that working Python code is, by definition, already formatted correctly for pretty printing. Even if you're stuck on some god-forsaken Windows PC with just Notepad, you can still read Python code. Now, *writing* Python code with Notepad isn't as easy, but it is still doable. How about Lisp code? That's not a criticism of Lisp exactly, but a reminder to think about not just what problem you're trying to solve, but what resources you will have to solve it. If you *know* that you're going to need to edit code by ssh-ing across an high-latency connection to a machine without Emacs, then Lisp will probably not be the best solution. The day has not yet arrived that nobody ever needs to edit code in a plain, vanilla text editor. -- Steven. From nmm1 at cus.cam.ac.uk Thu Dec 14 10:19:34 2006 From: nmm1 at cus.cam.ac.uk (Nick Maclaren) Date: 14 Dec 2006 15:19:34 GMT Subject: tuple.index() References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: In article <1166106278.106832.278240 at n67g2000cwd.googlegroups.com>, "Glenn Hutchings" writes: |> Fredrik Lundh wrote: |> |> > if you don't want to understand the design, nobody can force you. but arguing |> > that the people behind the design "don't get it" isn't very practical. |> |> I'm not arguing that at all. What I'm saying is that from the |> perspective of someone not interested in design issues, it seems like |> an omission for tuples to be missing the non-modifying methods that |> lists have. And, from the perspective of someone VERY interested in design issues, from the viewpoint of program validation (a.k.a mathematical models, a.k.a. 'program proving' a.k.a. 'software engineering') it also seems like one! If lists are intended to be homogeneous, then they should be checked for that, and an exception raised when an attempt is to make them non-homogeneous. At least as a Python checking option. If tuples are intended to be bags, then it makes no sense to allow them to be subscripted OR indexed. Mathematically, 'x = a[i]' and 'i = a.index(x)' have dual properties - and are true duals if you include the constraint of no duplicate elements. I remain baffled. I accept the explanations, but what I am now confused by is the reason for the explanations .... Regards, Nick Maclaren. From gagsl-py at yahoo.com.ar Sat Dec 23 03:29:47 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Sat, 23 Dec 2006 05:29:47 -0300 Subject: httplib and socket.getaddrinfo In-Reply-To: <1166858480.181900.255480@i12g2000cwa.googlegroups.com> References: <1166858480.181900.255480@i12g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061223051810.034ce828@yahoo.com.ar> At Saturday 23/12/2006 04:21, mirandacascade at yahoo.com wrote: >I noticed the following lines from the connect() method of the >HTTPConnection class within httplib: > > for res in socket.getaddrinfo(self.host, self.port, 0, > socket.SOCK_STREAM): > af, socktype, proto, canonname, sa = res > >This led me to the docs that describe the socket.getaddrinfo() method: > >http://www.python.org/doc/2.4.1/lib/module-socket.html > >Which leads me to these questions: >1) Is it correct to infer from the "Resolves the host/port argument, >into a sequence of 5-tuples that contain all the necessary argument for >the sockets manipulation" description in the docs (in particular the >reference to 'sequence of 5-tuples') that a single host/port >combination may be associated with multiple sets of address >information? Yes. By example, multiple addresses for the same service are used for load balancing. Or an IPv4 address plus an IPv6 address. >2) In the very limited applications on which I've used >socket.getaddrinfo(), each a host/port combination that my application >passes to socket.getaddrinfo() has always returned a 1-entry list where >the list is a 5-tuple, in other words, each host/port combination has >always been associated with one set of address information. Can >someone point me to a host/port combination that, when passed to >socket.getaddrinfo() will result in socket.getaddrinfo() returning a >list of > 1 entry, where each entry is a 5-tuple? Try to relax your restrictions. import socket host = 'www.microsoft.com' port = 'ftp' for res in socket.getaddrinfo(host, port): print res Got 8 results: (2, 1, 0, '', ('207.46.198.30', 21)) (2, 1, 0, '', ('207.46.198.60', 21)) (2, 1, 0, '', ('207.46.199.30', 21)) (2, 1, 0, '', ('207.46.225.60', 21)) (2, 1, 0, '', ('207.46.19.30', 21)) (2, 1, 0, '', ('207.46.19.60', 21)) (2, 1, 0, '', ('207.46.20.30', 21)) (2, 1, 0, '', ('207.46.20.60', 21)) -- 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 From gert.cuykens at gmail.com Tue Dec 19 18:09:02 2006 From: gert.cuykens at gmail.com (Gert Cuykens) Date: Wed, 20 Dec 2006 00:09:02 +0100 Subject: Http server In-Reply-To: References: <1166563266.178045.251540@73g2000cwn.googlegroups.com> Message-ID: Does anybody know how to redirect a post request ? i have a js file that does a post request to a /php/action.php file and i would like for the secretary to just do the action method instead that is defined in her python Http class book, so i can run both php and python without changing the static source code at 2 different ports head to head to see witch one can handle the most requests ? From fredrik at pythonware.com Mon Dec 4 17:44:40 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 04 Dec 2006 23:44:40 +0100 Subject: decorators question In-Reply-To: <1165271780.3345.72.camel@dot.uniqsys.com> References: <1165254977.903936.83180@16g2000cwy.googlegroups.com> <1165259428.106492.44020@16g2000cwy.googlegroups.com> <457476E6.5000603@youjoy.org> <1165269784.394649.7940@l12g2000cwl.googlegroups.com> <1165271780.3345.72.camel@dot.uniqsys.com> Message-ID: Carsten Haese wrote: > * The function body gets compiled into byte code (but not executed). careful: when you get as far as executing the "def" statement, the function body has already been compiled. the byte code for the function is stored as a module-level constant: >>> code = compile("def func(arg): print arg", "", "exec") >>> dis.dis(code) 1 0 LOAD_CONST 0 () 3 MAKE_FUNCTION 0 6 STORE_NAME 0 (func) ... > * A callable object with the byte code for the compiled function body is > constructed. > * The thusly constructed callable object is bound to the name A in your > current namespace. From paddy3118 at netscape.net Thu Dec 14 06:37:22 2006 From: paddy3118 at netscape.net (Paddy) Date: 14 Dec 2006 03:37:22 -0800 Subject: Survey environment for Python? In-Reply-To: <1166087528.068107.234480@n67g2000cwd.googlegroups.com> References: <1166083824.927340.102530@73g2000cwn.googlegroups.com> <1166087528.068107.234480@n67g2000cwd.googlegroups.com> Message-ID: <1166096241.998856.118390@73g2000cwn.googlegroups.com> On Dec 14, 9:12 am, "Kay Schluehr" wrote: > exhuma.twn schrieb: > > > Hi, > > > Just recently I had to take over support for legacy software written in > > Blaise (www.cbs.nl).I don't understand the meaning of the link. Do you mean this language? > > http://blaise.sourceforge.net/ http://www.cbs.nl/nl-NL/menu/_unique/_search/default.htm?querytxt=blaise From manstey at csu.edu.au Fri Dec 8 18:59:26 2006 From: manstey at csu.edu.au (manstey) Date: 8 Dec 2006 15:59:26 -0800 Subject: autoadd class properties In-Reply-To: <1165569502.811830.157900@73g2000cwn.googlegroups.com> References: <1165567093.167813.109000@j44g2000cwa.googlegroups.com> <1165569502.811830.157900@73g2000cwn.googlegroups.com> Message-ID: <1165622366.780227.41870@79g2000cws.googlegroups.com> We've looked at them a little. Cache is a native OO dbase, so there is no ORM required. Cache does that for you behind the scenes if you need it to. What I want is to translate Cache classes and properties into Python classes and properties. We can only use class wrappers, because cache uses old style python objects, but this still works. Because I am not an experienced programmer, the problem I face is how to load ANY Cache class, whose properties the wrapper doesn't know in advance, and turn the class properties into python properties. So in Cache, I might have Name = String, Age = Integer, Colours = List, in the class Person. The python binding provided by Cache creates a Person class in Python, but it provides none of its properties, so I want to write a wrapping class that adds the properties. Can you advise me on how to do this? From daniel.dittmar at sap.com Fri Dec 8 11:42:56 2006 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Fri, 08 Dec 2006 17:42:56 +0100 Subject: Common Python Idioms In-Reply-To: References: <17783.32458.730462.8403@montanaro.dyndns.org> <1165493298.205945.162430@n67g2000cwd.googlegroups.com> <1165518199.729518.112450@79g2000cws.googlegroups.com> Message-ID: Marc 'BlackJack' Rintsch wrote: > If ``in`` shouldn't work with dictionaries, either `__contains__()` must > be implemented to throw an exception or dictionaries shouldn't be iterable. I agree completely (in the sense that dictionaries shouldn't be iterable directly). Probably even more strongly, at least every time I see some code where someone iterates over the keys, only to use the key to look up the value (instead if using iteritms). For strings, the 1:1 relationship between 'in' and iteration has already been broken. But then, iteration over strings happens in my code only when a pass a string where I should have passed a list of strings. Daniel From rupole at hotmail.com Sun Dec 17 17:21:35 2006 From: rupole at hotmail.com (Roger Upole) Date: Sun, 17 Dec 2006 17:21:35 -0500 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> Message-ID: <1166394345_23949@sp6iad.superfeed.net> Gabriel Genellina wrote: > On 16 dic, 04:47, Tim Roberts wrote: >> > os.stat(selected)[ST_MODE] & (S_IXUSR|S_IXGRP|S_IXOTH > >>This will tell you that "x.exe" is executable, even if "x.exe" contains >> nothing but zeros. > > Isn't the same with any other recipe, portable or not? Unless the OS > actually tries to load and examine the file contents, which the OS's > I'm aware of, don't do. > > -- > Gabriel Genellina > On windows, you can use win32file.GetBinaryType to check if a file is actually a binary executable. Roger ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From grahamd at dscpl.com.au Sun Dec 10 16:24:33 2006 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 10 Dec 2006 13:24:33 -0800 Subject: apache & mod_python References: <4579472d$0$5066$ba4acef3@news.orange.fr> <1165577057.325812.47140@f1g2000cwa.googlegroups.com> <1165712433.927674.323000@f1g2000cwa.googlegroups.com> <457c0eb2$0$25909$ba4acef3@news.orange.fr> Message-ID: <1165785873.832130.317230@f1g2000cwa.googlegroups.com> m.banaouas wrote: > thanks for your answers > The plateform I target is Windows XP (no body is perferct ...). > > Concerning multithread , is simultaneous multi http client calls can > present any problem ? I don't think because usually http server fires a > different process for each client call, while Threading is discussed > within the same process, isn't it? The use of a separate process to handle each request only applies to the 'prefork' MPM on UNIX systems. Being on Windows, the 'winnt' MPM is used and concurrent requests are always handled within different threads within the same Apache process. The referenced article should have made that clear. > I'm still looking for mod_python 3.2.10 to install it with apache 2.2.3 > It seems like I must "build" it before use it. > If there is no other mean I will do it but usually I retrieve "ready to > use" kits. See: http://nicolas.lehuen.com/download/mod_python/ You will find Python 2.5 versions where whereas the official mod_python download site only has Python 2.3 and 2.4 versions. Make sure you grab the appropriate version for your combination of Apache and Python. Version 3.2.10 is the last stable version although 3.3.0b is in there as well and has just been put together for final testing before release for 3.3. Graham > Graham Dumpleton a ?crit : > > Maxim Sloyko wrote: > >> m.banaouas wrote: > >> > >>> Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent > >>> versions) without facing any known major issue ? > > > > Only that to use Apache 2.2 you must have mod_python 3.2.10 or later, > > older versions of mod_python do not work with the more recent version > > of Apache. > > > >> Works fine for me. > >> The only "known major issue" you can face is general non-threadsafety > >> of Python interpreter. So, if you are using Apache MPM, you have to > >> allow for it, or use framework that does it for you. > > > > You answer here is a bit misleading. There are no issues with the > > thread safety of the Python interpreter per-se. However, as with any > > Python application, whether mod_python is used or not, if multiple > > threads are being used your application code may have to be written so > > as to cope with access to code/data from multiple threads at the same > > time. This is not anything unique to mod_python. > > > > Whether this will be an issue or not is dependent on which Apache MPM > > is used, not that the Apache MPM is used as one will always be used. > > The specific Apache MPMs where multithreading has to be taken into > > consideration are "winnt" on Windows platforms and "worker" on UNIX > > platforms. What this all means is that when these MPMs are used there > > can be concurrent request handlers executing in distinct threads within > > the same Apache processes. Thus, where common data is accessed, it has > > to be adequately protected. > > > > For further details on the Apache/mod_python process/interpreter/thread > > model, see: > > > > > > http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel > > > > That said, there are sometimes threading issues with mod_python but it > > is more to do with the fact that mod_python can use multiple > > interpreter instances within a single process. Also, the problems are > > not a problem in mod_python, but result from third party C modules for > > Python being used which take the simple path of using the simplified > > thread API for working with the GIL. Such modules often will not work > > properly when used from secondary Python interpreter instances. In > > these cases it is a simple matter of telling mod_python to handle > > requests which are dependent on those modules within the main Python > > interpreter, ie., the very first one which gets created. Where third > > party C modules use the full thread API for Python properly, it doesn't > > matter which interpreter instance they are used from. > > > > Graham > > From huayang.xia at gmail.com Fri Dec 1 13:47:39 2006 From: huayang.xia at gmail.com (Huayang Xia) Date: 1 Dec 2006 10:47:39 -0800 Subject: Security Descriptor and CoInitializeSecurity Message-ID: <1164998859.758138.27080@80g2000cwy.googlegroups.com> I'd like to call pythoncom.CoInitializeSecurity with a PySecurityDescriptor object to set the process-wide security values. But I'm not able to find a way to let the code go through. I have read MSDN and searched web, I've not been able to find answer. I cooked a security descriptor like this (assume aces is a tuple of tuple (access, sid) : sd = win32security.SECURITY_DESCRIPTOR() sd.Initialize() sd.SetSecurityDescriptorOwner(sid_owner, False) sd.SetSecurityDescriptorGroup(sid_group, False) # create DACL dacl = win32security.ACL() dacl.Initialize() for (access, acc_sid) in aces: # Add ACE which is access and SID dacl.AddAccessAllowedAce(win32security.ACL_REVISION, access, isinstance(acc_sid, (unicode, str)) and win32security.ConvertStringSidToSid(acc_sid) or acc_sid) sd.SetDacl(True, dacl, False) # SetSecurityDescriptorDacl print sd.IsSelfRelative() # result is 1 The sd is a self relative one. >From MSDN, after calling InitializeSecurityDescriptor, the sd is absolute sd, and CoInitializeSecurity needs absolute sd. Pythonwin has not wrapped function like 'MakeAbsoluteSD'. Has someone ever had same problem. Could you give a hint for solving the problem. Thanks. Regards From kibleur.christophe at gmail.com Sun Dec 10 09:05:38 2006 From: kibleur.christophe at gmail.com (Tool69) Date: 10 Dec 2006 06:05:38 -0800 Subject: oo problem In-Reply-To: <8hTeh.3185$Gr2.1738@newssvr21.news.prodigy.net> References: <1165743982.241347.107830@j44g2000cwa.googlegroups.com> <8hTeh.3185$Gr2.1738@newssvr21.news.prodigy.net> Message-ID: <1165759538.026560.235810@80g2000cwy.googlegroups.com> Thanks James, It was a matter of choice : in my earlier version, all primitives know how to draw themselves, but they needed to have a parent and I found it was not good for aesthetic reasons. but I think I've been misunderstood. Let's take a concrete sample : I've got a Paper instance(-5,5,5,5) (the coordinates of lower-left and upper-right rectangle: xlowleft, ylowlef, xupright, yupright) of my paper. I want now to draw an x-axis on it with some ticks and maybe lables, I need to catch the xlowleft and xupright variables of the Paper inside my primitive, ok ? The problem lies inside my primitive, not on the draw method. Here's a simplified example, I need to retrieve paper.xll and paper.xur: class Graduate_x( primitive ): def __init__(self, orient = 'se', xorigin = 0, yorigin=0, xunit= 1.0, yunit=1.0): primitive.__init__(self) for k in range( int(math.floor(( paper.xll - xorigin)/xun)), int(math.floor((paper.xur-xorigin)/yun)) ): ...something to construct my path From sturlamolden at yahoo.no Fri Dec 15 15:07:55 2006 From: sturlamolden at yahoo.no (sturlamolden) Date: 15 Dec 2006 12:07:55 -0800 Subject: About alternatives to Matlab In-Reply-To: <4582d3ee$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> <1165241895.291617.143380@80g2000cwy.googlegroups.com> <4575687d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net> <1165941521.849053.284110@j72g2000cwa.googlegroups.com> <457fc2f5$0$8732$ed2619ec@ptn-nntp-reader02.plus.net> <1166035311.357588.115070@80g2000cwy.googlegroups.com> <458129ce$0$8757$ed2619ec@ptn-nntp-reader02.plus.net> <1166137839.139465.280830@16g2000cwy.googlegroups.com> <4582d3ee$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1166213275.844692.118200@73g2000cwn.googlegroups.com> Jon Harrop wrote: > Can convolution be implemented efficiently in Python? numpy.convolve > Functional programming makes this easy. You just compose closures from > closures instead of arrays from arrays. Indeed. But learning yet another language is too much work. > This is what I meant by optimising Python takes you in the wrong direction > (foresting). I think you're only using slice-based rewriting because it is > fast in Python, not because it is a good idea. So, is it worth adding > slicing to F#? If you only think in times of run-time speed, probably not. But it has other advantages, particularly ease of programming. > That makes perfect sense. I think F# could become a better Python but I need > to understand the relative benefits offered by Python first. When I look at F# or Lisp I see line noise, even though I know the syntax in theory. I don't get a mental image of what the code does. I spend 2/3 of the time reading code when I write a program. Second, Python is very easy to write, and complicated problems can be handled with few lines of code (compared to e.g. C). From steve at REMOVE.THIS.cybersource.com.au Sat Dec 16 07:34:41 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 16 Dec 2006 23:34:41 +1100 Subject: catching exceptions References: <1166270092.297610.19890@n67g2000cwd.googlegroups.com> Message-ID: On Sat, 16 Dec 2006 17:36:00 +0530, Amit Khemka wrote: > If I gather correctly, i guess in case of errors/exceptions in a class > function, you want to get the error string. One thing that comes > straight to my mind is, in such a case use a return statement in > functions with two arguments. > > for example: > def foo(self, value): > try: > a.x = value > return True, '' > except ValueError: return False, 'Float conversion error: %s' %(value) > > and when ever u call the function, check the first return value, It is > false then alert/print the error message. Oh lordy, that is _so_ 1980s programming practice!!! I'm not saying that it is never a good idea, but avoiding that sort of thing is one of the reasons exceptions were created! -- Steven. From timr at probo.com Sat Dec 30 03:05:30 2006 From: timr at probo.com (Tim Roberts) Date: Sat, 30 Dec 2006 08:05:30 GMT Subject: Easiest way to print from XP/DOS. References: Message-ID: jim-on-linux wrote: > >Did you run from a file or type in from keyboard? > >When the client runs the utility program the >output file is built but nothing prints and no >messages appear. When I typed from keyboard on an >xp pro at c:\, I got the message. > >Is it possible that virus detector or some >self.defense software is interacting? It is quite possible that they simply do not have a printer hooked up to their computer's parallel port. If all of your printers are from network shares, then the special file "prn" will not go anywhere. Typing to "prn" is a dreadful way to do printing on Windows. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pyenos at pyenos.org Wed Dec 20 21:21:28 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 13:21:28 +1100 Subject: pickle fun Message-ID: <87r6uu56qf.fsf@pyenos.pyenos.org> class pickle_service: import cPickle as p # accept list as arg then serialize it to a file def serialize(some_list,picklefile): f=file(picklefile,"w") p.dump(some_list,f) # so dumped this shit to the file f.close() # which one is the pickle? the file? no. just need the string of the name of file. # unserialize what? picklefile of course ;) def unserialize(some_pickle): f= file(some_pickle) # wtf is going on here: open file for unpickling return p.load(f) # unpickled: store it somewhere class testpickleservice: import pickle_service as p p.serialize(["f","u","c","k"," ",["you"]],"testpickle") print p.unserialize("testpickle") AHAHAHAHA. funny. From gagsl-py at yahoo.com.ar Fri Dec 15 08:47:57 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 15 Dec 2006 05:47:57 -0800 Subject: AI library In-Reply-To: <7CAC08AF-8C32-11DB-AD4B-000D93463186%felix.benner@imail.de> References: <7CAC08AF-8C32-11DB-AD4B-000D93463186%felix.benner@imail.de> Message-ID: <1166190477.577332.217060@73g2000cwn.googlegroups.com> On 15 dic, 08:50, Felix Benner wrote: > I thought about an AI library for python. This is the possible > structure I came up with. Are there any thoughts about it? Without commenting about the library itself: None, True and False are spelled this way. None is a singleton, compare using "x is None" or "x is not None", dont use == This is more stylish, but I prefer to use isxxx() or hasxxx() for functions that return booleans. -- Gabriel Genellina From blah at blahdeblah Sat Dec 2 14:27:11 2006 From: blah at blahdeblah (bill ramsay) Date: Sun, 03 Dec 2006 08:27:11 +1300 Subject: detecting that a SQL db is running References: <783tm2dmb6brnptr91hsfnc1t38u1utbi8@4ax.com> <1164924313.495569.311330@80g2000cwy.googlegroups.com> <8g21n2tms1otvenfnurpia7pochq29458h@4ax.com> Message-ID: <5qk3n2lqmimlvrel975fglhm690oonn5od@4ax.com> On Sat, 02 Dec 2006 07:39:51 GMT, Dennis Lee Bieber wrote: >On Sat, 02 Dec 2006 09:02:43 +1300, bill ramsay >declaimed the following in comp.lang.python: > >> Dennis >> >> none of this matters, all i am trying to find out is whether or not >> the local MSDE is actually running. >> > From my reading of your system, you have multiple "local MSDE" >server processes distributed about, and something on those distributed >systems that causes the initial problem... So I've never been clear of >just where any given application/server process actual resides... > > However, all the tests I've been able to perform on my desktop >indicate that /I/ get time-outs or failure to connect messages within 15 >seconds of a connection request when the server process is running. > > I don't get unending lock-ups... dennis it doesn't matter what is causing the lockups, it's a problem with a supposedly professionally written application package that I have no control over. I am just at this moment trying to deal with the consequences. I think that I haave found a way to deal with the issue that I have. Kind regards Bill From greg at cosc.canterbury.ac.nz Sat Dec 16 00:48:24 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 18:48:24 +1300 Subject: merits of Lisp vs Python In-Reply-To: References: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ucmndF17nmp0U1@mid.individual.net> <1166175804.202131.54070@l12g2000cwl.googlegroups.com> Message-ID: <4uhfo9F17usriU1@mid.individual.net> Ken Tilton wrote: > McCarthy: "Is code also data in Python?" > Norvig: "No." I don't think that was the right answer. He should have said "Yes", and then shown McCarthy eval() and exec. Code isn't quite as *convenient* to work with as data in Python as it is in Lisp, but that doesn't mean it can't be done. (I agree that the proffered example was not an instance of "code is data", though.) -- Greg From jon at ffconsultancy.com Sat Dec 9 05:08:01 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sat, 09 Dec 2006 10:08:01 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> Message-ID: <457a8ba2$0$8714$ed2619ec@ptn-nntp-reader02.plus.net> Steven D'Aprano wrote: > Anything any language can do is possible in any other language Not true. Concurrency, for example. > Lisp developers so often gloss over that: "Oh, > feature X is *easy*, I could write it in a couple of macros. Two or three. > Maybe thirty. Or forty, max. And they would work the right way first time. > No, I haven't actually done it myself. But I'm sure I could do it, easy." True. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From atkinw at rpi.edu Mon Dec 11 09:17:51 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Mon, 11 Dec 2006 09:17:51 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165800527.225633.84180@80g2000cwy.googlegroups.com> <1165821773.670192.288860@79g2000cws.googlegroups.com> Message-ID: "Paddy" writes: > JShrager at gmail.com wrote: > >> > Python has to rely more on using the right algorithm... >> >> This sound familiar: "Macros are dangerous!" > Yes. I changed my opinion on advocating Python having macros in one > of our long threads on the subject. Maintainance counts. Yes, it does, but that should take you to exactly the opposite conclusion. >> "Compilers make you lazy." > This is new to me. In fact, for the compiled languages available to me. > Using them *first* would be the difficult choice. These are not real sentences, but if you're saying that compiled languages make programming more difficult, then you're simply using the wrong compiled languages. Lisp is a dynamic language that also supports compilation to native code. > Unlike Lisp, Python does not have a ubiquitous compiler. It is > therefore > made to interface nicely with compiled languages. Other compiled What on earth does this mean? You're saying that because Python doesn't have a compiler, it can interface more easily to compiled languages? That's nonsense. Further, most Lisp implementations support an interface to C that doesn't require you to write and compile C code in order to use C extensions in Lisp. Can Python do the same more "nicely" than Lisp? > language users see the need for dynamic interpreted languages like > Python and maintain links Python such as the Boost Python C++ > wrapper. IronPython for .NET, Jython for Java. > Lisp is its own interpreter and compiler, which should be a great > advantage, but only if you don't make the mistake of ignoring the > wealth of code out there that is written in other languages. Um. From felix.benner at imail.de Sun Dec 24 09:21:51 2006 From: felix.benner at imail.de (Felix Benner) Date: Sun, 24 Dec 2006 15:21:51 +0100 Subject: problem with PIPE In-Reply-To: References: Message-ID: Dhika Cikul schrieb: > Hello, > > I'm new in Python, i don't know my subject is correct or wrong. I have > problem with my script. I want to change password with passwd password > in python without user submitted anything from keyboard. I get > tutorial that i must use pipe to process this. And this is my code : > > [code] > > 1. > 2. #!/usr/bin/python > 3. > 4. import os > 5. > 6. COMMAND = 'passwd' > 7. PASSWD = 'mypassword' > 8. > 9. # open a pipe to passwd program and > 10. # write the data to the pipe > 11. p = os.popen("%s" % COMMAND, 'w') > 12. p.write(PASSWD) > 13. p.write('\n') > 14. p.write(PASSWD) > 15. p.close() > 16. > [/code] > > > but i got this error : > > [output] > [cp at server cp]$ ./password > Changing password for user cp. > Changing password for cp > (current) UNIX password: passwd: Authentication token manipulation error > [/output] > > Anyone can help me how to write to pipe.. i try several method, and > always fail. > > Thank's I guess the passwd program doesn't allow changing passwords from a pipe since it is a potential security hole. From pillsbury at gmail.com Fri Dec 8 13:56:11 2006 From: pillsbury at gmail.com (Pillsy) Date: 8 Dec 2006 10:56:11 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165594621.136524.198600@80g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> Message-ID: <1165604171.448549.192640@j44g2000cwa.googlegroups.com> hankhero wrote: [...] > Pythons advantages are: > Faster startup-time which makes it a good scripting language. I agree with the others (especially the cleverness of Python's string quoting), but on my machine, SBCL starts up and runs a "Hello World" program a bit faster than Python, and CLisp really blows its doors off. Cheers, Pillsy From commander.coder at hotmail.com Thu Dec 21 14:22:47 2006 From: commander.coder at hotmail.com (commander.coder at hotmail.com) Date: 21 Dec 2006 11:22:47 -0800 Subject: How a script can know if it has been called with the -i command line option? In-Reply-To: <1166720012.798260.6670@80g2000cwy.googlegroups.com> References: <1166720012.798260.6670@80g2000cwy.googlegroups.com> Message-ID: <1166728967.099050.128290@a3g2000cwd.googlegroups.com> Michele Simionato wrote: > The subject says it all, I would like a script to act differently when > called as > $ python script.py and when called as $ python -i script.py. I looked > at the sys module > but I don't see a way to retrieve the command line flags, where should > I look? In the optparse module. Jim From paddy3118 at netscape.net Fri Dec 8 17:22:15 2006 From: paddy3118 at netscape.net (Paddy) Date: 8 Dec 2006 14:22:15 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165613280.584178.36470@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> Message-ID: <1165616535.556824.22170@j72g2000cwa.googlegroups.com> JShrager at gmail.com wrote: > Okay, since everyone ignored the FAQ, I guess I can too... > > Mark Tarver wrote: > > How do you compare Python to Lisp? What specific advantages do you > > think that one has over the other? > > (Common) Lisp is the only industrial strength language with both pure > compositionality and a real compiler. What Python has is stupid slogans > ("It fits your brain." "Only one way to do things.") and an infinite > community of flies that, for some inexplicable reason, believe these > stupid slogns. These flies are, however, quite useful because they > produce infinite numbers of random libraries, some of which end up > being useful. But consider: Tcl replaced Csh, Perl replaced Tcl, Python > is rapidly replacing Perl, and Ruby is simultaneously and even more > rapidly replacing Python. Each is closer to Lisp than the last; the > world is returning to Lisp and is dragging the flies with it. > Eventually the flies will descend upon Lisp itself and will bring with > them their infinite number of random libraries, and then things will be > where they should have been 20 years ago, but got sidetracked by Tcl > and other line noise. What is it about Lisp that despite doing everything first, way before any other language, people don't stop using anything else and automatically turn to Lisp? Maybe there is more to this everything than the Lisp community comprehends. Maybe Lisp is to science, as Python is to engineering - with a slight blurring round the edges? - Paddy. From atkinw at rpi.edu Sun Dec 10 13:38:39 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Sun, 10 Dec 2006 13:38:39 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <87slfny4wr.fsf@thalassa.informatimago.com> Message-ID: Pascal Bourguignon writes: >> This is true, but now someone >> has to intentionally and specifically import the package containing >> that shadowed + into their own package. You are never unwittingly >> using a different + than the standard CL one, although you really seem >> to want this to be the case. > > The Common Lisp standard has no provision to and indeed forbid to > modify the function binding of the COMMON-LISP:+ symbol. I'm not talking about redefining the + symbol; I'm talking about shadowing it and defining a new function on a different symbol that has the same symbol-name. From paul at boddie.org.uk Fri Dec 1 07:08:00 2006 From: paul at boddie.org.uk (Paul Boddie) Date: 1 Dec 2006 04:08:00 -0800 Subject: Python Question About Compiling. References: <1164956538.516498.14900@80g2000cwy.googlegroups.com> Message-ID: <1164974880.791030.83350@79g2000cws.googlegroups.com> Fredrik Lundh wrote: > yndesai wrote: > > > Is it that no compiling facility is hindering the growth of python > > in commercial circuit . . . ? I can see the point of people who are confused about single file executables for Python programs, who are possibly new to the technology and don't know where to look [1] or which questions to ask, and I can also see the need in various situations for people to make such executables. That said, I don't buy into the kind of hypothetical "ISVs need this and that" pontification seen on places like Planet GNOME, written by people who work at companies like Novell. The "commercial circuit" will use a technology (and, in fact, have been using Python for some time) when they recognise the genuine benefits of the technology, and if the technology doesn't deliver exactly what they had in mind, they'll either put in some effort to shape it to their liking or they'll look elsewhere. If none of this activity has any community benefit, I'd argue that there's only so much the community should be prepared to do to "fix" such commercial objections - if what a business wants is valuable enough, that business should be prepared to pay for it. > (why are you blaming you inability to use Linux installation tools on > Python, btw? most basic Python libraries are only an apt-get away if > you're using a sane Linux distribution.) This is true enough, and by packaging one's programs correctly, Python gets automatically brought into the picture when the user asks to install those programs. It's interesting to consider this in the context of the recent Linux Standard Base discussions on python-dev: LSB potentially mitigates issues with shipping executables across different distributions and would be beneficial to those wanting to deploy Python applications in such a way. I notice, however, that the discussion has taken the peanut gallery position of name-calling and mock outrage at the packaging practices of various distributions [2], presumably whilst advocating Python-only solutions like setuptools - something which really isn't going to work well with any large heterogeneous collection of software packages. Moreover, the distributions have to more urgently deal with various issues not yet sufficiently addressed by the Python core developers, particularly architecture issues [3] and licensing issues [4]. Freezing applications has been a fairly well-understood process for the last ten years, but more cooperation with heterogeneous packaging technologies would be far preferable. After all, distributions are actually responsible for a large amount of Python usage, and it would be far better if people actually tried to work with them to resolve some of the supposedly inflammatory aspects of their packaging practices rather than just shouting bad things at them from a distance [5]. A bit of "not invented here" [6] suppression would also be quite welcome, along with taking the needs of vendors [7] other than Apple Computer Inc. into account. Paul P.S. And while a frank discussion [7] did appear to result in a comprehensive exchange of views between Debian and setuptools developers, I'd like to see a bit more understanding for end-users and people who don't want to ignore their system's package management. Python "plays well with others" is a frequent claim, after all. [1] http://wiki.python.org/moin/DistributionUtilities [2] http://mail.python.org/pipermail/python-dev/2006-November/070032.html [3] http://mail.python.org/pipermail/python-dev/2006-November/070043.html [4] http://mail.python.org/pipermail/python-dev/2006-November/070054.html [5] http://mail.python.org/pipermail/python-dev/2006-November/070055.html [6] http://mail.python.org/pipermail/python-dev/2006-November/070101.html [7] http://mail.python.org/pipermail/distutils-sig/2005-November/005500.html From martin at v.loewis.de Fri Dec 22 10:33:41 2006 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Fri, 22 Dec 2006 16:33:41 +0100 Subject: add encoding to standard encodings works different in python 2.5? In-Reply-To: References: Message-ID: <458BFAD5.8070807@v.loewis.de> henk-jan ebbers schrieb: > - how can i get this to work in 2.5 (nice if it would work in both 2.4 > and 2.5) You should implement a lookup function, and register it with codecs.register. Then you can structure your modules any way you like. Regards, Martin From sjmachin at lexicon.net Mon Dec 4 16:27:06 2006 From: sjmachin at lexicon.net (John Machin) Date: 4 Dec 2006 13:27:06 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> Message-ID: <1165267626.293073.288180@79g2000cws.googlegroups.com> OKB (not okblacke) wrote: [snip] > I think the same could be said of virtually all exceptions. What I > think would be ideal is that whenever an exception is raised, the > traceback tells you: > > 1) What the exception is > 2) The names of the variables involved in the offending expression > (or their character position in the line) > 3) The values of those variables > > This would be especially useful in cases where you have some long > expression and you get a "cannot concatenate str and list" or whatever. > The irritating thing about this as it is is that you cannot tell which > variables in the expression are causing the problem. > > I realize that in some cases the offending expression may not be a single variable, > but I am curious whether it would be possible for > something like this: > > "1" + "2" + "3" + "4" + 5 + "6" A few points: 1. You have difficulty determining the "offending expression" in that example? 2. If I read your requirement properly, you want an error message that includes the following information from the source: example 1: "1" + "2" + "3" + "4" + 5 + "6" left operand name: "1" + "2" + "3" + "4" left operand value: "1234" right operand name: 5 right operand value: 5 example 2 (simple variables): str1 = "a"; list1 = ["b"]; foo = str1 + list1 left operand name: str1 left operand value: "a" right operand name: list1 right operand value: ["b"] example 3 (simple variables): str1 = "a"; str2 = "x"; list1 = ["b"]; foo = str1 + str2 + list1 left operand name: str1 + str2 left operand value: "ax" right operand name: list1 right operand value: ["b"] IMHO there would be no point in handling only "simple" cases like example 2 -- firstly, you don't need it; there's only one possible answer for "left operand name". Secondly, AFAICT, the same mechanism would handle examples of arbitrary complexity. My guesses: (a) Implementing this error reporting information in a new compiler and interpreter would add considerably to the effort required, and to the complexity and thus to the risk of error. (b) Retrofitting it to an existing compiler and interpreter would be a nightmare. Possible: yes. Cost/benefit ratio: very high. 3. The OP asked only for values; you are asking for names and values. If you have a magic flak jacket, please let me know; I'd like to borrow it occasionally :-) Cheers, John From pc at p-cos.net Tue Dec 12 08:44:00 2006 From: pc at p-cos.net (Pascal Costanza) Date: Tue, 12 Dec 2006 14:44:00 +0100 Subject: merits of Lisp vs Python In-Reply-To: <7xhcw1l0sn.fsf@ruckus.brouhaha.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> <4u7g1kF17436jU1@mid.individual.net> <7xmz5txs4x.fsf@ruckus.brouhaha.com> <4u7jmsF175jh0U1@mid.individual.net> <7xhcw1l0sn.fsf@ruckus.brouhaha.com> Message-ID: <4u7q10F16153dU1@mid.individual.net> Paul Rubin wrote: > Pascal Costanza writes: >> You can start with loop by using only the simple and straightforward >> constructs, and slowly move towards the more complicated cases when >> necessary. The nice thing about loop is that with some practice, you >> can write code that more or less reads like English. > > Yeah, but I'd also get English-like imprecision. Anyway, If I wanted > to write code that reads like English, I'd write in Cobol. That's the neat thing in Lisp: You can stay in Lisp if you want to write code in a different style. No need to switch your whole tool chain. >> All Common Lisp implementations that I am aware of provide ways to >> enable TCO, so it's definitely possible to program in a functional >> style if you want to. It's just that the ANSI Common Lisp >> specification doesn't guarantee this, > > Yes; I'd rather go by what the standard says than rely on > implementation-dependent hacks. You shouldn't limit yourself to what some standard says. Pascal -- My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ From steven.bethard at gmail.com Wed Dec 13 00:10:35 2006 From: steven.bethard at gmail.com (steven.bethard at gmail.com) Date: Wed, 13 Dec 2006 05:10:35 +0000 (GMT) Subject: python-dev Summary for 2006-11-16 through 2006-11-30 Message-ID: <20061213051036.A59BA1E400C@bag.python.org> python-dev Summary for 2006-11-16 through 2006-11-30 ++++++++++++++++++++++++++++++++++++++++++++++++++++ .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-11-16_2006-11-30] ============= Announcements ============= -------------------------- Python 2.5 malloc families -------------------------- Remember that if you find your extension module is crashing with Python 2.5 in malloc/free, there is a high chance that you have a mismatch in malloc "families". Fredrik Lundh's FAQ has more: http://effbot.org/pyfaq/why-does-my-c-extension-suddenly-crash-under-2.5.htm Contributing thread: - `2.5 portability problems `__ --------------------------------- Roundup tracker schema discussion --------------------------------- If you'd like to be involved in the discussion of the setup for the `new tracker`_, you can now file issues on the `meta tracker`_ or post to the `tracker-discuss mailing list`_. Be sure to sign up for an account so your comments don't show up as anonymous! .. _new tracker: http://psf.upfronthosting.co.za/roundup/tracker/ .. _meta tracker: http://psf.upfronthosting.co.za/roundup/meta/ .. _tracker-discuss mailing list: http://mail.python.org/mailman/listinfo/tracker-discuss Contributing thread: - `discussion of schema for new issue tracker starting `__ ========= Summaries ========= ---------------------------------------- Python and the Linux Standard Base (LSB) ---------------------------------------- Ian Murdock, the chair of the Linux Standard Base (LSB), explained that they wanted to add Python to `LSB 3.2`_. Martin v. Lowis promised to go to their meeting in Berlin and report back to python-dev. The discussion then turned to the various ways in which the different Linux variants package Python. A number of people had been troubled by Debian's handling of distutils. At one point, Debian had excluded distutils completely, requiring users to install the "python-dev" package to get distutils functionality. While current versions of Debian had put distutils back in the stdlib, they had excluded the ``config`` directory, meaning that distutils worked only for pure Python modules, not extension modules. And because Debian had no way of knowing that a computer with both gcc and Python installed would likely benefit from having the ``config`` directory installed, the user still had to install "python-dev" separately. There was also some discussion about how to handle third party modules so that updating a module didn't break some application which was expecting a different version. These kinds of problems were particularly dangerous on distributions like Gentoo and Ubuntu which relied heavily on their own system Python for the OS to work properly. Guido suggested introducing a vendor-packages directory for the third party modules required by the OS and Martin v. Lowis reopened an `earlier patch`_ suggesting this. A number of folks also thought that adding a ~/.local/lib/pythonX.X/site-packages directory for user specific (not site wide) packages could be useful. Phillip J. Eby pointed out that distutils and setuptools already allow you to install packages this way by putting:: [install] prefix = ~/.local into ./setup.cfg, ~/.pydistutils.cfg, or /usr/lib/python2.x/distutils/distutils.cfg. He also explained that setuptools could address some of the application-level problems: setuptools-generated scripts adjust their sys.path to include the specific eggs they need, and can specify these eggs with an exact version if necessary. Thus OS-level scripts would likely specify exact versions and then users could feel free to install newer eggs without worrying that the OS would try to use them instead. .. _LSB 3.2: http://www.freestandards.org/en/LSB_Roadmap .. _earlier patch: http://bugs.python.org/1298835 Contributing thread: - `Python and the Linux Standard Base (LSB) `__ ---------------------- Thread-safe operations ---------------------- Fredrik Lundh has been working on `cleaning up the Python FAQ`_ and asked about what kinds of operations could be considered "atomic" for the purposes of thread-safety. While almost any statement in Python can invoke an arbitrary special method (e.g. ``a = b`` can invoke ``a.__del__()``), Fredrik was interested in situations where the objects involved were either builtins or objects that didn't override special methods. In situations like these, you can be guaranteed things like:: * If two threads execute ``L.append(x)``, two items will be added to the list (though the order is unspecified) * If two threads execute ``x.y = z``, the field ``y`` on the ``x`` object will exist and contain one of the values assigned by one of the threads You get these guarantees mainly because the core operation in these examples involves only a single Python bytecode. However, Martin v. Lowis pointed out that even the above examples are not truly atomic in the strictest sense because they invoke bytecodes to load the values of the variables in addition to the bytecode to perform the operation. For example, if one thread does ``x = y`` while another thread does ``y = x``, at the end of the code in an "atomic" system, both ``x`` and ``y`` would have the same value. However, in Python, the values could get swapped if a context switch occurred between the loading of the values and the assignment operations. Much of this discussion was also posted to `the FAQ item`_. .. _cleaning up the Python FAQ: http://effbot.org/pyfaq/ .. _the FAQ item: http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm Contributing thread: - `PyFAQ: thread-safe interpreter operations `__ -------------------------------------------- >From an empty directory to a package on PyPI -------------------------------------------- Talin suggested that distutils/setuptools and their documentation should be updated so that new users could more easily answer the question: "What is the smoothest path from empty directory to a finished package on PyPI?" In particular, Talin thought that having to cross-reference between distutils/setuptools/unittest/etc. was confusing, and that a more stand-alone version of the documentation was necessary. A number of people agreed that the documentation could use some reorganization and the addition of some more tutorial-like sections. Mike Orr promised to put together an initial "Table of Contents" that would have links to the most important information for package distribution, and Talin made `his notes`_ available on the "baby steps" necessary to prepare a module for setuptools (e.g. create the directory structure, write a setup.py file, create source files in the appropriate directories, etc.) .. _his notes: http://wiki.python.org/moin/ExtensionTutorial Contributing thread: - `Distribution tools: What I would like to see `__ -------------------------------------------- Monitoring progress with urllib's reporthook -------------------------------------------- Martin v. Lowis looked at a `patch to urllib's reporthook`_ aimed at more accurate progress reporting. The original code in urllib was passing the ``read()`` block size as the second argument to the reporthook. The patch would have instead passed as the second argument the actual count of bytes read. Guido pointed out that the block size and the actual count would always be identical except for the last block because of how Python's ``file.read(n)`` works. Thus urllib was already giving the reporthook as accurate a progress report as possible given the implementation, and so the patch was rejected. .. _patch to urllib's reporthook: http://bugs.python.org/849407 Contributing thread: - `Passing actual read size to urllib reporthook `__ --------------------------- Infinity and NaN singletons --------------------------- Tomer Filiba asked about making the positive-infinity, negative-infinity and not-a-number (NaN) singletons available as attributes of the ``float`` type, e.g. ``float.posinf``, ``float.neginf`` and ``float.nan``. Bob Ippolito pointed him to `PEP 754`_ and the fpconst_ module which addressed some of these issues though in a separate module instead of the builtin ``float`` type. When Tomer asked why `PEP 754`_ had not been accepted, Martin v. Lowis explained that while people were interested in the feature, it was difficult to implement in general, e.g. on platforms where the double type was not IEEE-754. .. _PEP 754: http://www.python.org/dev/peps/pep-0754/ .. _fpconst: http://www.python.org/pypi/fpconst/ Contributing thread: - `infinities `__ ------------------------------------------ Line continuations and the tokenize module ------------------------------------------ Guido asked about modifying the tokenize module to allow a better round-tripping of code with line continuations. While the tokenize module was generating pseudo-tokens for things like comments and "ignored" newlines, it was not generating anything for line continuation backslashes. Adding the appropriate yield would have been trivial, but would have been a (minor) backwards incompatible change. Phillip J. Eby pointed Guido to `scale.dsl`_ which dealt with similar issues, and suggested that even though the change was small, it might cause problems for some existing tools. Guido proposed a somewhat more backwards compatible version, where a NL pseudo-token was generated with '\\\n' as its text value, and asked folks to try it out and see if it gave them any trouble. .. _scale.dsl: http://peak.telecommunity.com/DevCenter/scale.dsl#converting-tokens-back-to-text Contributing thread: - `Small tweak to tokenize.py? `__ ----------------------- Summer of Code projects ----------------------- Georg Brandl asked about the status of the Google Summer of Code projects and got a number of responses: * Nilton Volpato reported the completion of the new ziparchive_ module, which includes file-like access to zip members, support for BZIP2 compression, support for member file removal and support for encryption. He explained that he was still doing a little work to clean up the API, and that he would appreciate any feedback people had on the module. * Facundo Batista reported that the decimal Python-to-C transliteration was completed successfully, but that they learned in the process that a simple transliteration was not going to suffice and the decimal module was going to have to undergo a structural redesign to perform well in C. * Jim Jewett reported that the work to make more stdlib modules use the logging module was incomplete, and not ready for stdlib inclusion yet. .. _ziparchive: http://ziparchive.sourceforge.net/ Contributing threads: - `Summer of Code: zipfile? `__ - `Results of the SOC projects `__ - `Summer of Code: zipfile? `__ - `Results of the SOC projects `__ =============== Skipped Threads =============== - `Weekly Python Patch/Bug Summary `__ - `Python in first-year MIT core curriculum `__ - `POSIX Capabilities `__ - `[1593035] Re: readline problem with python-2.5 `__ - `DRAFT: python-dev summary for 2006-10-01 to 2006-10-15 `__ - `Suggestion/ feature request `__ - `DRAFT: python-dev summary for 2006-10-16 to 2006-10-31 `__ - `DRAFT: python-dev summary for 2006-11-01 to 2006-11-15 `__ - `ctypes and powerpc `__ - `(no subject) `__ - `Cloning threading.py using processes `__ - `Objecttype of 'locals' argument in PyEval_EvalCode `__ ======== Epilogue ======== This is a summary of traffic on the `python-dev mailing list`_ from November 16, 2006 through November 30, 2006. It is intended to inform the wider Python community of on-going developments on the list on a semi-monthly basis. An archive_ of previous summaries is available online. An `RSS feed`_ of the titles of the summaries is available. You can also watch comp.lang.python or comp.lang.python.announce for new summaries (or through their email gateways of python-list or python-announce, respectively, as found at http://mail.python.org). This python-dev summary is the 17th written by Steven Bethard. To contact me, please send email: - Steven Bethard (steven dot bethard at gmail dot com) Do *not* post to comp.lang.python if you wish to reach me. The `Python Software Foundation`_ is the non-profit organization that holds the intellectual property for Python. It also tries to advance the development and use of Python. If you find the python-dev Summary helpful please consider making a donation. You can make a donation at http://python.org/psf/donations.html . Every cent counts so even a small donation with a credit card, check, or by PayPal helps. -------------------- Commenting on Topics -------------------- To comment on anything mentioned here, just post to `comp.lang.python`_ (or email python-list at python.org which is a gateway to the newsgroup) with a subject line mentioning what you are discussing. All python-dev members are interested in seeing ideas discussed by the community, so don't hesitate to take a stance on something. And if all of this really interests you then get involved and join `python-dev`_! ------------------------- How to Read the Summaries ------------------------- This summary is written using reStructuredText_. Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo :); you can safely ignore it. We do suggest learning reST, though; it's simple and is accepted for `PEP markup`_ and can be turned into many different formats like HTML and LaTeX. .. _python-dev: http://www.python.org/dev/ .. _python-dev mailing list: http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _PEP Markup: http://www.python.org/peps/pep-0012.html .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. _Python Software Foundation: http://python.org/psf/ .. _archive: http://www.python.org/dev/summary/ .. _RSS feed: http://www.python.org/dev/summary/channews.rdf From fredrik at pythonware.com Wed Dec 20 13:48:36 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 19:48:36 +0100 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Sebastian 'lunar' Wiesner wrote: >>>> no, I'm showing that a local file marked as executable overrides a >>>> shared one, even if the local file isn't actually an executable. >>> >>> Only if you have your system set up badly. The current directory >>> should not be in the search path, and it especially shouldn't have >>> higher priority than the regular bin locations. >> >> and the award for completely missing the context of this subthread >> goes to... > > Nevertheless his comment was absolutely correct... nope. a Unix system uses the same flag to determine if a file is executable no matter how I've set up my path. From RadSurfer at yahoo.com Thu Dec 28 12:51:25 2006 From: RadSurfer at yahoo.com (RadSurfer) Date: 28 Dec 2006 09:51:25 -0800 Subject: New IRC Channel: #moderncalcs Message-ID: <1167328285.297761.319620@42g2000cwt.googlegroups.com> IRC Server: Freenode IRC Channel: #moderncalcs Purpose: #moderncalcs created December 2005 is intended as a real-time chat channel for anyone using any model of scientific/graphing/programmable calculator, especially those of modern design. However, any calculator-related topic is acceptable. The channel is set up as a self-help channel: This means that those of you who join in this real-time irc chat are expected to share your knowledge with others. Pass along any fascinating tips you have discovered on your own, or learned from others, web pages with valuable information, and the like. This is a new irc channel! It is just now getting started! Therefore, please do not be surprised if when you check it out there might not be too many present... help us get going by joining, it is ok to remain idle in the channel (as long as it does not interfear with anyone). This is to be considered a 100% family-rated channel! Under NO CIRCUMSTANCES will any unacceptable topic or material be permitted in the channel. Unlike usenet, irc chat is real time chat with other people! Everyone see's what you type and can respond to you immediately. Please use proper courtesy, punctuation, and grammer. Please remember that some users might not have English as their native language, so please lets set a good example for them. You may share this message with others to help spread the word. Please let me know from where you heard about #moderncalcs. Thank you, RadSurfer at yahoo.com RadSurfer op #moderncalcs on Freenode IRC Server. From Thomas.Ploch at gmx.net Thu Dec 7 20:25:52 2006 From: Thomas.Ploch at gmx.net (Thomas Ploch) Date: Fri, 08 Dec 2006 02:25:52 +0100 Subject: A Call to Arms for Python Advocacy In-Reply-To: References: Message-ID: <4578BF20.9020602@gmx.net> Roy Smith schrieb: > In article , > Jeff Rush wrote: > >> As the Python Advocacy Coordinator, I've put up some wiki pages on the Python >> website for which I'm soliciting ideas, writing and graphics. Some of the >> material exists scattered about and just needs locating and organizing. >> >> http://wiki.python.org/moin/Advocacy > > > I think it also appears to need faster hardware. It's running glacially > slow. I hope you are _not_ using IE... (Sorry, I didn't want to offend you, but it's fine with me ,too.) :-) Thomas From sandravandale at yahoo.com Sun Dec 17 12:14:31 2006 From: sandravandale at yahoo.com (Sandra-24) Date: 17 Dec 2006 09:14:31 -0800 Subject: How to test if two strings point to the same file or directory? In-Reply-To: References: <1166317324.791635.274550@79g2000cws.googlegroups.com> <1166319494.222385.232890@t46g2000cwa.googlegroups.com> <1166322669.722451.183510@80g2000cwy.googlegroups.com> Message-ID: <1166375671.095298.284320@n67g2000cwd.googlegroups.com> It looks like you can get a fairly good apporximation for samefile on win32. Currently I'm using the algorithm suggested by Tim Chase as it is "good enough" for my needs. But if one wanted to add samefile to the ntpath module, here's the algorithm I would suggest: If the passed files do not exist, apply abspath and normcase to both and return the result of comparing them for equality as strings. If both paths pass isfile(), try the mecahnism linked to in this thread which opens both files at the same time and compares volume and index information. Return this result. If that raises an error (maybe they will not allow us to open them) Try comparing them using the approach suggested by Tim Chase, but if that works there should be some indication given that the comparison may not be accurate (raise a warning?). If that also fails, raise an error. This should allow samfile to be used on win32 in well over 99.9% of cases with no surprises. For the rest it will either return a result that is likely correct with a warning of some kind, or it will fail entirely. It's not perfect, but you can't acheive perfection here. It would, however, have far less surprises than newbies using == to compare paths for equality. And it would also make os.path.samefile available on another platform. os.path.sameopenfile could be implemented perfectly using the comparison of volume and index information alone (assuming you can get a win32 handle out of the open file object, which I think you can) If someone would be willing to write a patch for the ntpath tests I would be willing to implement samefile as described above or as agreed upon in further discussion. Then we can submit it for inclusion in the stdlib. From Sebastien.Boisgerault at gmail.com Tue Dec 12 17:33:24 2006 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 12 Dec 2006 14:33:24 -0800 Subject: Validate XML against a set of XSD files, with Python In-Reply-To: References: Message-ID: <1165962804.855630.222240@79g2000cws.googlegroups.com> Laszlo Nagy wrote: > Do you know an open source lib that can do $subject? Fast google query, uncheked, leads to: - XSV: http://www.ltg.ed.ac.uk/~ht/xsv-status.html - libxml : http://codespeak.net/lxml/ Cheers, SB From http Tue Dec 12 06:32:05 2006 From: http (Paul Rubin) Date: 12 Dec 2006 03:32:05 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <4u4qo3F15uds8U1@mid.individual.net> <7xd56qbgx7.fsf@ruckus.brouhaha.com> <7xwt4yju5e.fsf@ruckus.brouhaha.com> <7x1wn57voq.fsf@ruckus.brouhaha.com> <7xirghy7pu.fsf@ruckus.brouhaha.com> Message-ID: <7xvekhxscq.fsf@ruckus.brouhaha.com> Espen Vestre writes: > > I'd say Python is more dynamic in the sense that the Python runtime > > system has to actually concern itself about the dynamism all the time > > in practice, i.e. on every object method invocation. > > Ok, but when you state that language A is more dynamic than language > B, most programmers would interpret that as (or so I guess) "A offers > more dynamism to the programmer than B" - not that it burdens the run > time system implementor with more dynamism... I'm sorry for any misunderstanding. Maybe I should have said that Python's dynamism is more pervasive: it can be activated in more different ways and that creates an extra burden on the runtime system. Remember that the context was whether Python could be compiled to efficient machine code. So I referred to "more dynamism" from the implementers' point of view--the runtime has to pay attention to more things and spend more resources dealing with the dynamism. I think the Lispies see "more dynamism" as a good thing and are therefore defending their language from suggestions that Python is even more dynamic than Lisp. I mean "dynamic" in a less good way-- there is a huge amount of state scattered all through a running Python program, that the application can modify at random and whose contents the working of really fundamental operations like method invocation. It's just a big mess and I'd get rid of it if I could. It reminds me of like old time Lisp programs that pervasively used property lists on symbols to attach random attributes to the symbol, instead of using something like defstruct to make multi-field data values. How about if I say Python and Lisp are both dynamic, but Lisp does a better job of keeping its dynamism's potentially chaotic effects contained. Does that help? From gandalf at designaproduct.biz Thu Dec 21 05:58:48 2006 From: gandalf at designaproduct.biz (Laszlo Nagy) Date: Thu, 21 Dec 2006 11:58:48 +0100 Subject: Stani's Python Editor - questions In-Reply-To: <7llko29d3nfg1bmm010js14r4av3ohm2uf@4ax.com> References: <7llko29d3nfg1bmm010js14r4av3ohm2uf@4ax.com> Message-ID: <458A68E8.3050505@designaproduct.biz> >> 1. How can I navigate between opened files? Usually I open 10 or more >> files at the same time. There is no way to quickly scroll the tabs and >> select the one that I want. Tabs simply run out of my screen. >> > > Normally with ctrl-tab, ctrl-shift-tab, ctrl-f6 ctrl-shift-f6 (at least > on windows) > This does not work for me. I'm using these: OS: FreeBSD 6.1-RELEASE Python: 2.4.3 wxPython: 2.6.3.3 SPE: 0.8.2a Maybe I should use 0.8.0, but this would be difficult. My SPE was installed using the "ports" system of my OS and I do not want to screw it up. >> 2. I tried to use the "Browser" for navigation but it tells me "file is >> already open" and it won't switch to the file. Annoying. >> > > What version do you have? on 0.8.0b on Windows, it jumps to the tab, > if the file is already open. > Does not work for me! I'm getting messages like this: python:3255): Gtk-CRITICAL **: gtk_container_remove: assertion `GTK_IS_TOOLBARcontainer) || widget->parent == GTK_WIDGETcontainer)' failed python:3255): Gtk-CRITICAL **: gtk_container_remove: assertion `GTK_IS_TOOLBARcontainer) || widget->parent == GTK_WIDGETcontainer)' failed I'm not sure what it means, but maybe the problem is not in SPE or DrPython - it is with wxWidgets or GTK ? > In DrPython you have a plugin Sessions or SessionsLight for that. > Okay, I know that DrPython has lots of plugins. I tried to install some of them but the important ones did not work and I gave up. >> But it takes two minutes to >> start up SPE, because I have to press the "OK" button on the ISO8859-1 >> message for each file that is re-opened. >> This must be a problem with wxHtmlWindow because I get the same message when I start the wxPython demo. I'm upgrading wxPython right now, but I'm not sure if it will help. SPE requires 2.6.1 and I already have a newer version. (DrPython does not use wxHtmlWindow, this is why it does not throw error messages.) > In DrPython, there is also a Code Completions plugin. > It is not perfect, but still useful. > I tried to install it on FreeBSD but it did not work. I tried it on Windows and turned out that code completion in DrPython it is much worse than in SPE. I'm missing code folding as well. DrPython is better for me right now, because it works. :-) But none of them are practical nor easy to use. SPE would be better if it worked. I wanted to buy the Wing IDE, but their support team said it is not available for FreeBSD. They allow me to compile it from sources but it is a mess. I would have to sign an NDA and spend hours with compiling it, and it would still not be a supported platform. It is just too much work. Komodo does not work on FreeBSD at all. Also tried boaconstructor, but it was very unstable. If I would like to have a good IDE for Python that knows a lot (code completion, code folding, class browser, integrated debugger, call tips, subversion integration etc.) then what choices I have? > I don't want to persuade to use this or that, > but a closer look to the plugins will reveal > the "hidden" features of DrPython, and plugins > prevent DrPython to become to bloated. > I'm sorry, I do not want to be offensive. DrPython is good, but it is not a complete IDE. I would happily pay for a good IDE but I cannot find one (not for FreeBSD). Maybe the problem is with my mind and I should replace my OS immediately. :-) Best, Laszlo From zondo42 at googlemail.com Thu Dec 14 10:49:39 2006 From: zondo42 at googlemail.com (Glenn Hutchings) Date: 14 Dec 2006 07:49:39 -0800 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: <1166111379.421958.112140@t46g2000cwa.googlegroups.com> Nick Maclaren wrote: > I remain baffled. I accept the explanations, but what I am now > confused by is the reason for the explanations .... Maybe this archive posting, straight from the horse's mouth, will clear things up once and for all... http://www.python.org/search/hypermail/python-1992/0285.html Glenn From scumitchell at gmail.com Fri Dec 8 11:57:55 2006 From: scumitchell at gmail.com (scum) Date: 8 Dec 2006 08:57:55 -0800 Subject: MySQL-python-1.2.1_p2, Python 2.5 and OS X Tiger In-Reply-To: <1165596973.310634.108830@j72g2000cwa.googlegroups.com> References: <1165596973.310634.108830@j72g2000cwa.googlegroups.com> Message-ID: <1165597074.994936.275270@73g2000cwn.googlegroups.com> And I know about the precompiled binary... I'm just sick of getting this warning.... Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import _mysql __main__:1: RuntimeWarning: Python C API version mismatch for module _mysql: This Python has API version 1013, module _mysql has version 1012. From bearophileHUGS at lycos.com Wed Dec 20 07:37:57 2006 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 20 Dec 2006 04:37:57 -0800 Subject: array, a better shell In-Reply-To: References: <1166615065.807704.12480@48g2000cwx.googlegroups.com> Message-ID: <1166618277.261434.194280@79g2000cws.googlegroups.com> Duncan Booth: > Later you can click on them and bring them back > to the bottom of the input buffer for further editing (so no confusing > output appearing out of order), I think that's worse, not better. You end with a messy final "document" (log), so finding things into it (during the editing too) is much more difficult. > Your point was? My point is to suggest things that can improve the Python user experience, and productivity too. I try to help, with the hope to have something that I like more too. It's very difficult to describe subtle GUI functionalities using a texual description (expecially when you aren't using your native language). If you try the Mathematica shell you may find some differences I am talking about (even if I don't globally like the Mathematica shell). Editing an input block into idle feels different from editing a small script inside an editor, there are differences that make the user experience less good. (And beside that it seems I often have problems running IDLE on Win PCs with a firewall). Bye, bearophile From tony at PageDNA.com Sat Dec 30 14:00:14 2006 From: tony at PageDNA.com (Tony Lownds) Date: Sat, 30 Dec 2006 11:00:14 -0800 Subject: PEP 3107 Function Annotations for review and comment In-Reply-To: <1167492896.292605.15040@48g2000cwx.googlegroups.com> References: <1167492896.292605.15040@48g2000cwx.googlegroups.com> Message-ID: <233DEDCD-F3BC-4A4B-AC38-C33152FBC071@PageDNA.com> > First, it only handles functions/methods. Python FIT needs > metadata on properties and assignable/readable attributes > of all kinds. So in no sense is it a replacement. Parenthetically, > neither is the decorator facility, and for exactly the same reason. > I can't argue against docstrings and maybe annotations on attributes, I'd like them myself. That should be a separate PEP because the scope of this one is Function Annotations. The syntax for function annotations has been much more thoroughly discussed than for annotations on attributes. See Guido's blog and other references in the PEP. > Second, it has the potential to make reading the function > header difficult. In the languages I'm familiar with, static type > declarations are a very few, somewhat well chosen words. > In this proposal, it can be a general expression. In Python > FIT, that could well turn into a full blown dictionary with > multiple keys. Any code can be hard to read. Having the annotation be a general expression lets authors use normal code factoring to make the function header more readable. For instance, one can change this: def f(x: some_really_long_expression): ... to this: t_X = some_really_long_expression def f(x: t_X): ... > Third, it's half of a proposal. Type checking isn't the only use > for metadata about functions/methods, classes, properties > and other objects, and the notion that there are only going to > be a small number of non-intersecting libraries out there is > an abdication of responsibility to think this thing through. > That comes from this paragraph from the PEP: There is no worry that these libraries will assign semantics at random, or that a variety of libraries will appear, each with varying semantics and interpretations of what, say, a tuple of strings means. The difficulty inherent in writing annotation interpreting libraries will keep their number low and their authorship in the hands of people who, frankly, know what they're doing. Perhaps you are right and intersecting libraries will become an issue. Designing a solution in advance of the problems being evident seems risky to me. What if the solution invented in a vacuum really is more of a hindrance? There is a clear intersection between documentation packages and type-checking or type-coercing libraries. Documentation libraries can just use repr(annotation), possibly with a little bit of special casing to represent classes and types better. I'm not sure there will be an important use for overlap of different type-checking or type-coercing libraries within the same module. What else could intersect and why can't the intersecting pieces develop an solution when it arises? More feedback from the community on this point (whether the PEP needs to take responsibility for interoperability) would be nice. Thanks for the feedback from everyone so far, -Tony From rtw at freenet.co.uk Mon Dec 25 13:00:07 2006 From: rtw at freenet.co.uk (Rob Williscroft) Date: Mon, 25 Dec 2006 12:00:07 -0600 Subject: method names in __slots__ ?? References: <1167008799.074885.250770@73g2000cwn.googlegroups.com> <1167067714.627280.76420@n51g2000cwc.googlegroups.com> Message-ID: John Machin wrote in news:1167067714.627280.76420 at n51g2000cwc.googlegroups.com in comp.lang.python: > Rob Williscroft wrote: >> John Machin wrote in news:1167008799.074885.250770@ >> 73g2000cwn.googlegroups.com in comp.lang.python: >> >> > Given a = Adder(), >> > a.tally = 0 >> > gets AttributeError: 'Adder' object attribute 'tally' is read-only >> > a.notinslots = 1 >> > gets AttributeError: 'Adder' object attribute 'notinslots' is >> > read-only >> > >> > So is there some magic class-fu going down here, or is this just a >> > waste of memory space in the instances? >> > >> >> Haven't you, with your 2 examples above, answered your own question ? > > No. > >> >> Clearly from your example it doesn't make any difference if you add >> a class attribute to the slots, one way or another its as if you >> hadn't put it in there in the first place. > > Clearly? Not so. It takes up memory. A list of 1 million Adder > instances takes up about 68 Mb (Python 2.5 on Windows XP). With the > method names removed from the __slots__, it takes only about 44 Mb. > [For comparison: with no __slots__ at all, it takes about 180 Mb] 68 - 44 = 24 24 / 4 = 6 So thats 6 pointers for 5 methods, probably 5 pointers and and 4 bytes round up to the nearest allocation unit. So the slots in the instance are staying arround, even though they are no longer accesable (see below). [snip] > It would seem that the interpreter removes any names it finds as >> class attribute names from the list it finds in __slots__ before it >> creates the instance. > > It doesn't seem so to me. If it did that, the memory usage would not > increase. It was a guess, and an incorrect guess, but thats why I quoted the docs below. > >> >> Of course if my guessing above isn't good enough, we could look at >> the documentation: >> >> http://docs.python.org/ref/slots.html#l2h-218 >> >> __slots__ are implemented at the class level by creating descriptors >> (3.4.2) for each variable name. As a result, class attributes cannot >> be used to set default values for instance variables defined by >> __slots__; otherwise, the class attribute would overwrite the >> descriptor assignment. > > I have read that, before I posted. Asides: > (1) It would be useful if it stated the empirically determined fact > that the result is that the class attribute is thusly made read-only. > (2) The second sentence is not a model of clarity. > > In any case I can't see how the paragraph gives any support for your > next statement: > >> >> So its that the __slots__ assignment makes the descriptors and then >> the subsiquent method defenitions and class attribute bindings remove >> them. > > Errrmmm ... if the descriptors are removed, how is it that the > behaviour is read-only? The descriptors are part of the class object, they are removed when the class attributes are rebound, further rebinding of the class attributes will work fine: Adder.tally = 0 They are not assignable in the instance as the class descriptors that would have forwarded the assignment to the instances slots have been replaced. The memory usage is higher because the slots in the instance are still there even though the descriptors that would allow them to be assigned have been removed. Rob. -- http://www.victim-prime.dsl.pipex.com/ From tom.and at tiscalinet.it Fri Dec 15 13:57:18 2006 From: tom.and at tiscalinet.it (Andrea Tomadin) Date: Fri, 15 Dec 2006 19:57:18 +0100 Subject: (newbie) class with a single instance ?! Message-ID: <28E93178-808C-4D33-9058-695EE9F58195@tiscalinet.it> Hi, I need a suggestion on the better implementation for a very basic task. I run a program which does some logging on files. I want to collect all the filenames and handlers in the same structure. All the files should be opened at startup, closed at exit, and easily accessed by the rest of the script. I thought of writing a class with the file handlers as objects and opening and closing operations within __init__ and __del__. Then an instance of the class is created at the beginning of the program and used. This works, but isn't it weird to define a class if I know from the very beginning that there will be no more than an instance of that class? Suggestions on this basic OOP task are very appreciated! Thank you, Andrea From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Thu Dec 14 17:15:57 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Thu, 14 Dec 2006 23:15:57 +0100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <457fd653$0$4340$426a74cc@news.free.fr> <1166092000.715620.50040@f1g2000cwa.googlegroups.com> Message-ID: <4ue0ooF17bdgeU2@mid.individual.net> josephoswaldgg at hotmail.com wrote: > What it isn't is some kind of miraculous invention that saves > programmers from ever making mistakes that are common in other > languages, or that reduces effort in copy-paste, as Bjoern seemed > to be claiming. I didn't. I just stated that the Python way is less work for me. Regards, Bj?rn Xpost cll,clp -- BOFH excuse #112: The monitor is plugged into the serial port From bdesth.quelquechose at free.quelquepart.fr Mon Dec 18 06:12:53 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 18 Dec 2006 12:12:53 +0100 Subject: trees In-Reply-To: <1166429502.182707.160730@j72g2000cwa.googlegroups.com> References: <1166429502.182707.160730@j72g2000cwa.googlegroups.com> Message-ID: <458671ff$0$29378$426a74cc@news.free.fr> Raymond Hettinger a ?crit : > vertigo wrote: > >>What library/functions/classes could i use to create trees ? > > > Start with random.seed, login as root, use svn to download the trunk > and branches, when Spring arrives, the leaves will fill-in ;-) keyboard !-) From klappnase at web.de Tue Dec 19 12:08:57 2006 From: klappnase at web.de (klappnase) Date: 19 Dec 2006 09:08:57 -0800 Subject: Tkdnd--does anyone use it? In-Reply-To: <1ae21$458725a9$4275d90a$29101@FUSE.NET> References: <1ae21$458725a9$4275d90a$29101@FUSE.NET> Message-ID: <1166548136.995570.27980@79g2000cws.googlegroups.com> Kevin Walzer schrieb: > Does anyone use the Tkdnd module that comes with Tkinter to allow > drag-and-drop of Tkinter widgets in your application? (Not the binary > extension that hooks into Xdnd and OLE-dnd on Windows.) I've looked at > the various documents for Tkdnd, and it looks somewhat complicated, > particulary if you want to use it outside of the canvas widget; I've > also found very few examples of its actual use (as opposed to sample > code snippets). I'm curious if anyone is actually using it in a > production application and, if so, what your experience with it is. > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com I use it in phonoripper (http://klappnase.zexxo.net/phonoripper.index.html) to drag files from a directory tree into a listbox. I found it to be less complicated than it looked at a first glance. If you like you can have a look at the DirTree and TrackTree modules to see how i use it. (I actually use Treectrl widgets instead of a Tkinter.Listbox and a slightly modified Tkdnd module, but the logic is the same). Regards Michael From Sebastien.Boisgerault at gmail.com Tue Dec 19 04:59:42 2006 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 19 Dec 2006 01:59:42 -0800 Subject: ElementTree and utf-16 encoding In-Reply-To: References: <1166520970.118514.195040@80g2000cwy.googlegroups.com> Message-ID: <1166522382.846453.278650@j72g2000cwa.googlegroups.com> On Dec 19, 10:49 am, Fredrik Lundh wrote: > S?bastien Boisg?rault wrote: > > ET being ElementTree in the following code, could anyone explain > > why it fails ?I'm afraid the standard serializer in 1.2 only supports ASCII-compatible > encodings. this will be fixed in 1.3. > > as a workaround, you can do: > > tostring(elem).decode("utf-8").encode("utf-16") > > OK, thanks. SB From sonibergraj at youjoy.org Fri Dec 8 12:59:14 2006 From: sonibergraj at youjoy.org (Soni Bergraj) Date: Fri, 08 Dec 2006 18:59:14 +0100 Subject: is there a tutorial for creating packages in python? In-Reply-To: References: Message-ID: <4579A7F2.3060801@youjoy.org> krishnakant Mane wrote: > I saw the official python tutorial and I think chapter 6 has quite a > bit on that. I'm not sure what you are after. There is not much to say about building python packages. I imagine that the important stuff should be in there (I have not checked!). If you are looking for ways to distribute your package look at distutils or setuptools. > but not what I could term as some thing complete in knowledge that one > needs to create libraries as huge as wxpython etc. wxPython is a C (or rather C++) extension (in contrast to a pure Python package). For C bindings there are several choices, Python C API, SWIG and ctypes come to mind. For C++ there i Boost.Python. For the usual packaging work you would use dsitutlis. http://en.wikibooks.org/wiki/Python_Programming/Extending_with_C gives a short introduction on how to getting started. Cheers, -- Soni Bergraj http://www.YouJoy.org/ From martin at v.loewis.de Sun Dec 3 11:08:00 2006 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 03 Dec 2006 17:08:00 +0100 Subject: Deleting from a list while iterating In-Reply-To: <1165160235.282030.96610@79g2000cws.googlegroups.com> References: <1165160235.282030.96610@79g2000cws.googlegroups.com> Message-ID: <4572F660.1070101@v.loewis.de> Rhamphoryncus schrieb: > setapproach = """\ > def func(count): > from random import random > items = [random() for i in xrange(count)] > remove = set() > for index, x in enumerate(items): > #...do something... > if x < 0.5: > remove.add(index) > items = [x for index, x in enumerate(items) if index not in remove] > """ This is different from the other approaches in that it doesn't modify items. If you wanted a new list, you could incrementally build one already in the first pass, no need to collect the indices first (as BlackJack explains). If you wanted in-place modification, I'd do newitems = [] for x in items: if not (x < 0.5): newitems.append(x) items[:] = newitems > copyapproach = """\ > def func(count): > from random import random > items = [random() for i in xrange(count)] > for x in items[:]: > if x < 0.5: > items.remove(x) > """ This happens to work for your example, but is incorrect in the general case: you meant to write del items[i+removed] here, as .remove(x) will search the list again, looking for the first value to remove. If your condition for removal happens to leave some items equal to x in the list, it would remove the wrong item. Because the numbering changes while the iteration is in progress, you have to count the number of removed items also. Regards, Martin From gagsl-py at yahoo.com.ar Sat Dec 9 01:27:56 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: 8 Dec 2006 22:27:56 -0800 Subject: Automatic debugging of copy by reference errors? In-Reply-To: <1165641773.903394.295300@80g2000cwy.googlegroups.com> References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> Message-ID: <1165645676.694401.193580@16g2000cwy.googlegroups.com> On 9 dic, 02:22, "Niels L Ellegaard" wrote: > Is there a module that allows me to find errors that occur due to copy > by reference? What do you mean by "copy by reference"? > I am looking for something like the following: > > >>> import mydebug > >>> mydebug.checkcopybyreference = True > >>> a=2 > >>> b=[a] > >>> a=4 > Traceback (most recent call last): > File "", line 1, in ? > CopyByReferenceError: Variable b refers to variable a, so please do not > change variable a. (I won't be pedantic to say that Python has no "variables"). What's wrong with that code? You are *not* changing "variable a", you are binding the integer 4 to the name "a". That name used previously to be bound to another integer, 2 - what's wrong with it? Anyway it has no effect on the list referred by the name "b", still holds b==[2] What do you want? Forbid the re-use of names? So once you say a=2, you can't modify it? That could be done, yes, a "write-once-read-many" namespace. But I don't see the usefullness. > Does such a module exist? No > Would it be possible to code such a module? I don't know what do you want to do exactly, but I feel it's not useful. > Would it be possible to add the functionality to array-copying in > numpy? No idea. > What would be the extra cost in terms of memory and CPU power? No idea yet. > I realize that this module would disable some useful features of the > language. Not only "some useful features", most programs would not even work! > On the other hand it could be helpful for new python users. I think you got in trouble with something and you're trying to avoid it again - but perhaps this is not the right way. Could you provide some example? -- Gabriel Genellina From gagsl-py at yahoo.com.ar Sat Dec 30 00:35:58 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Sat, 30 Dec 2006 02:35:58 -0300 Subject: Starting a child process and getting its stdout? In-Reply-To: <1167405767.308530.308800@48g2000cwx.googlegroups.com> References: <1167365370.031054.243880@h40g2000cwb.googlegroups.com> <7vl9p2h7f7adsbn6d6tfpmluera3njnb6g@4ax.com> <1167405767.308530.308800@48g2000cwx.googlegroups.com> Message-ID: <7.0.1.0.0.20061230023327.01ce6d50@yahoo.com.ar> At Friday 29/12/2006 12:22, cypher543 wrote: >Thank you for the examples, but I have tried all of that before. No >matter what I do, my program always hangs while it waits for the >process to exit and then it prints all of the output at once. I've >tried read(), readline(), readlines(), communicate(), etc and it is >always the same. Did you *actually* tried what Tom Plunket posted? Two tiny chars make a difference. -- 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 From Benjamin.Barker at gmail.com Fri Dec 29 07:03:22 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 04:03:22 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167393196.618932.104550@a3g2000cwd.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> Message-ID: <1167393801.950199.197830@48g2000cwx.googlegroups.com> Each time my script is run, the following is called: self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) self.cursor.execute("USE "+name) self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( .... The idea being that stuf is only created the first time the script is run, and after that the original tables and database is used. This might explain my pronblem if for some reason the old tables are being replaced... can anyone see anything wrong with the above? Ben Ben wrote: > One partial explanation might be that for some reason it is recreating > the table each time the code runs. My code says "CREATE TABLE IF NOT > EXISTS" but if for some reason it is creating it anyway and dropping > the one before that could explain why there are missing entires. > > It wouldn't explain why the NOT EXISTS line is being ignored though... > > Ben > > > Ben wrote: > > I initially had it set up so that when I connected to the database I > > started a transaction, then when I disconnected I commited. > > > > I then tried turning autocommit on, but that didn't seem to make any > > difference (althouh initially I thought it had) > > > > I'll go back and see what I can find... > > Cheers, > > Ben > > > > > > johnf wrote: > > > Ben wrote: > > > > > > > I don't know whether anyone can help, but I have an odd problem. I have > > > > a PSP (Spyce) script that makes many calls to populate a database. They > > > > all work without any problem except for one statement. > > > > > > > > I first connect to the database... > > > > > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > > > self.cursor = self.con.cursor() > > > > self.cursor.execute("SET max_error_count=0") > > > > > > > > All the neccesary tables are created... > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > self.cursor.execute("USE "+name) > > > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > > > varchar(20)) > > > > > > > > Then I execute many insert statements in various different loops on > > > > various tables, all of which are fine, and result in multiple table > > > > entries. The following one is executed many times also. and seems > > > > identical to the rest. The print statements output to the browser > > > > window, and appear repeatedly, so the query must be being called > > > > repeatedly also: > > > > > > > > print "

SQL query executing

" > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > > > ','c','2','e','f','g')") > > > > print "

SQL query executed

" > > > > > > > > I have, for debugging, set "i" up as a counter variable. > > > > > > > > No errors are given, but the only entry to appear in the final database > > > > is that from the final execution of the INSERT statement (the last > > > > value of i) > > > > > > > > I suspect that this is to vague for anyone to be able to help, but if > > > > anyone has any ideas I'd be really grateful :-) > > > > > > > > It occured to me that if I could access the mysql query log that might > > > > help, but I was unsure how to enable logging for MysQL with python. > > > > > > > > Cheers, > > > > > > > > Ben > > > > > > Not sure this will help but where is the "commit"? I don't use MySQL but > > > most SQL engines require a commit. > > > Johnf From felix.benner at imail.de Thu Dec 21 10:15:15 2006 From: felix.benner at imail.de (Felix Benner) Date: Thu, 21 Dec 2006 16:15:15 +0100 Subject: [ANN] Py++ - 0.8.5 In-Reply-To: References: <7465b6170612210455i71e690c6r3a47f9d337a100dc@mail.gmail.com> Message-ID: Roman Yakovenko schrieb: > Hello! > > I'm pleased to announce the 0.8.5 release of Py++. I'm just wondering why there is a comp.lang.python.announce newsgroup. Could it be for making announcements or would that be too obvious? From jon at ffconsultancy.com Sun Dec 10 05:02:02 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Sun, 10 Dec 2006 10:02:02 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <7xfybpb9pe.fsf@ruckus.brouhaha.com> <457bd1a5$0$8740$ed2619ec@ptn-nntp-reader02.plus.net> <7xslfoqedm.fsf@ruckus.brouhaha.com> Message-ID: <457bdbba$0$8730$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: > Jon Harrop writes: >> I discovered this recently with F#. Although F# (as a dialect of OCaml) >> is impure like Lisp, it does make purely functional programming easy and >> provides many purely functional data structures. I translated 15kLOC of >> mostly-functional OCaml code into F# and only had to add four locks to >> make the whole library concurrent. > > The idea of the composable-STM stuff is to not add locks at all, just > mark sections as atomic and the right stuff happens automagically > (i.e. you never have to worry about deadlock), including when you nest > such sections. Its performance also exceeds traditional locking. But > it relies on Haskell's purity. Yes. My point is that I only had to add four locks in 15kLOC of F# code because my code was almost entirely pure. So F# is a long way towards that Haskell ideal whilst having many other advantages over Haskell, like predictable memory usage. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From newptcai at gmail.com Tue Dec 19 11:51:23 2006 From: newptcai at gmail.com (=?utf-8?B?5LiA6aaW6K+X?=) Date: 19 Dec 2006 08:51:23 -0800 Subject: wxPython and activex problem. Message-ID: <1166547083.376418.3740@48g2000cwx.googlegroups.com> Hi all! Have u tried genaxmodule.py provided by wxPython to create a wrapper module for an activex control? For me, some times it works, but some times, it doesn't. ----------------------------------------------------- Traceback (most recent call last): File "genaxmodule.py", line 42, in ? main(sys.argv) File "genaxmodule.py", line 32, in main axw = wx.activex.ActiveXWindow(f, clsid) File "C:\Python23\Lib\site-packages\wx-2.6-msw-ansi\wx\activex.py", line 268, in __init__ newobj = _activex.new_ActiveXWindow(*args, **kwargs) wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in contrib\activex\wxie/wxactivex.cpp(322): m_ActiveX.CreateInstance failed ------------------------------------------------------ For some job, I do need to use activex and I have to choose languages other than python if genaxmodule doesn't work. It's really annoying. From sjmachin at lexicon.net Thu Dec 7 02:29:47 2006 From: sjmachin at lexicon.net (John Machin) Date: 6 Dec 2006 23:29:47 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165192705.112414.23200@j44g2000cwa.googlegroups.com> <1165267626.293073.288180@79g2000cws.googlegroups.com> <1165298691.474503.184480@16g2000cwy.googlegroups.com> Message-ID: <1165473321.784366.236320@16g2000cwy.googlegroups.com> OKB (not okblacke) wrote: > John Machin wrote: > > > Can you give a real example from your code where the location of > > such a human error (you cause a variable to bound to a value of > > inappropriate type) would be difficult to find, plus an estimate of > > how often you would make such an error? > > Here is an example: > > self.outFile.write(str(len(self.hits)) + ' in ' + searchInfo.recordName > + '\t' + ']['.join((a. group() for a in self.hits)) + '\n') > > This is from a text-searching tool I have written to search > linguistic corpora. This statement writes a summary line to the output > file indicating how many hits were found in that file. > > The problem in this line was that I'd forgotten to put str() around > the len(). Now, it's not impossible to find the problem, because given > my knowledge of the program I know that that's the only part of the line > that would reasonably contain the number, but I still think it would be > a lot easier if there were a caret in the error message pointing to the > offending summand. It should be extremely easy (rather than "not impossible") for anybody with half a clue to find the problem given only the offending statement (rather than your "knowledge of the program"). There are 6 possibilities; 3 are string constants. That leaves us with len(something), searchInfo.recordName, and "][".join(something). len() very definitely returns an integer (unless some lunatic has bound the name to something else) and it's the *first* of the possibilities -- one can normally expect execution to proceed from left to right. recordName smells like a string. "][".join(blahblah) likewise unless the rebinding mania is pandemic. Sheesh. > > I'm glad you asked this question, though, because in searching for > examples in my code, I discovered that most of my beefs aren't actually > of this type. A lot of them are things like this: > > someStr.split(someList) > > Here I meant to write someList[0] (say), but have inadvertently > passed the list instead of one of its elements. > > In this case I receive an error message that says "TypeError: > expected a character buffer object". My question is: why can this error > message not say what was encountered INSTEAD of a character buffer > object? > > A similar situation occurs when I do someVar[0] and get an > "unsubscriptable object" error. The error does not even tell me the > type of the offending value, just that it is unsubscriptable. > > So my conclusion from this is: is there a reason that every error > message of the form "expected foo" or "this object cannot be frotzed" > cannot be changed to something like "expected foo but found bar" or > "this FooType object cannot be frotzed"? And despite your use of RHN (Reverse Hungarian Notation) you don't know that someList is a list? From basti.wiesner at gmx.net Wed Dec 20 13:26:22 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Wed, 20 Dec 2006 19:26:22 +0100 Subject: Need Simple Way To Determine If File Is Executable References: <1166173492.915415.35690@n67g2000cwd.googlegroups.com> <061b54-1c21.ln1@eskimo.tundraware.com> <1166311179.311427.190330@n67g2000cwd.googlegroups.com> <5lebo2dfvu8fmdpbk1j2h88jbqvlgmrght@4ax.com> Message-ID: Fredrik Lundh schrieb > Paul Arthur wrote: > >>> no, I'm showing that a local file marked as executable overrides a >>> shared one, even if the local file isn't actually an executable. >> >> Only if you have your system set up badly. The current directory >> should not be in the search path, and it especially shouldn't have >> higher priority than the regular bin locations. > > and the award for completely missing the context of this subthread > goes to... Nevertheless his comment was absolutely correct... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From joshbloom at gmail.com Fri Dec 1 15:34:39 2006 From: joshbloom at gmail.com (Josh Bloom) Date: Fri, 1 Dec 2006 13:34:39 -0700 Subject: detecting that a SQL db is running In-Reply-To: <8g21n2tms1otvenfnurpia7pochq29458h@4ax.com> References: <783tm2dmb6brnptr91hsfnc1t38u1utbi8@4ax.com> <1164924313.495569.311330@80g2000cwy.googlegroups.com> <8g21n2tms1otvenfnurpia7pochq29458h@4ax.com> Message-ID: I think the main point is that your Python code should be written in such a way that when you attempt to connect to your local MSDE it will timeout correctly instead of hanging. Do you have a loop somewhere that just keeps retrying the connection instead of giving up at some point? Here are a couple of links to bits o code, that you can use to see whats running on your local machine. http://blog.dowski.com/2003/12/20/getting-at-processes-with-python-and-wmi/ http://mail.python.org/pipermail/python-win32/2001-November/000155.html Search the resulting lists for whatever name MSDE is supposed to run as. -Josh On 12/1/06, bill ramsay wrote: > > Dennis > > none of this matters, all i am trying to find out is whether or not > the local MSDE is actually running. > > I put all the other bits in there to try and put some background to > it. > > kind regards > > bill > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From yoring at gmail.com Mon Dec 25 01:57:24 2006 From: yoring at gmail.com (yoring at gmail.com) Date: 24 Dec 2006 22:57:24 -0800 Subject: Website Capture Message-ID: <1167029844.360539.138940@f1g2000cwa.googlegroups.com> Hi, I want to capture a web site into gif image using Python. I installed the PIL if it can help. From Dennis.Benzinger at gmx.net Sat Dec 16 14:53:13 2006 From: Dennis.Benzinger at gmx.net (Dennis Benzinger) Date: Sat, 16 Dec 2006 20:53:13 +0100 Subject: sha, PyCrypto, SHA-256 References: <1166296639.483483.292380@f1g2000cwa.googlegroups.com> Message-ID: <20061216205313.4083fa5d@dennis-laptop> Am 16 Dec 2006 11:17:19 -0800 schrieb mirandacascade at yahoo.com: > Operating system: Win XP > Vsn of Python: 2.4 > > Situation is this: Required to calcluate a message digest. The > process for calcluating the digest must use an SHA-256 algorithm. > > Questions: > 1) Is it correct that the sha module comes with python 2.4? > 2) Is it correct that the sha module that ships with python 2.4 does > NOT have the SHA-256 capability as part of the module? > 3) It looks like PyCrypto is a package that, among other things, > permits one to calculate a message digest using an SHA-256 > algorithm...is that correct? > 4) It looks like there are a couple couple possibilities available for > the download...either download the source code and run the setup which > (I'm assuming) compiles the various extension modules, or download the > pycrypto-2.0.1.win32-py2.4.zip which extracts out to a .exe; when one > runs the just-extracted .exe, it installs the stuff on one's > workstation. I'm leaning toward the second option because it seems > like most of the work has been done for me. A quick search on this > site didn't turn up anything that suggested there were problems with > running the installer. So, my question is this: are you aware of any > problems running the installer? > 5) Besides PyCrypto, are there any other Python packages that permit > one to calculate a message digest using an SHA-256 algorithm? > > Thank you. > Python 2.5 comes with SHA-256 in the hashlib module. So you could install Python 2.5 instead of the PyCrypto module. Dennis From scumitchell at gmail.com Mon Dec 11 11:20:14 2006 From: scumitchell at gmail.com (scum) Date: 11 Dec 2006 08:20:14 -0800 Subject: Help with install python-mysql lib on OS X Message-ID: <1165854013.991012.60720@80g2000cwy.googlegroups.com> How do you install MySQL-python on a PPC OS X 10.4 machine with MySQL 4.1? And I know about the precompiled binary at macpython.org... I'm just sick of getting this warning.... Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import _mysql __main__:1: RuntimeWarning: Python C API version mismatch for module _mysql: This Python has API version 1013, module _mysql has version 1012. From rampeters at gmail.com Mon Dec 11 19:02:02 2006 From: rampeters at gmail.com (johnny) Date: 11 Dec 2006 16:02:02 -0800 Subject: newb: Creating Exception Message-ID: <1165881722.928958.81490@79g2000cws.googlegroups.com> I want to print individual exception for database connection, sql execution, database closing, closing the cursor. Can I do it with one try..catch or I need a nested try...catch? conn = adodb.NewADOConnection('mysql') conn.Connect('localhost', 'temp', 'temp', 'temp') sql = r"update file set pdf_file_path='" +finalFile+r"' where file_path='"+p+r"'" cursor = conn.Execute(sql) rows = cursor.Affected_Rows() cursor.close() conn.close() Thank you for your FOUNTAIN OF WISDOM... From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Fri Dec 1 15:32:02 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Fri, 01 Dec 2006 21:32:02 +0100 Subject: python vs java & eclipse References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <8c7f10c60612010151g52915fcfobeb30dc5d9e5530d@mail.gmail.com> <1164974627.554596.300240@l12g2000cwl.googlegroups.com> <1164991907.911276.221250@80g2000cwy.googlegroups.com> <1164996431.806879.51400@16g2000cwy.googlegroups.com> Message-ID: <4tbhpfF13bmgrU3@mid.individual.net> Paul Boddie wrote: > Eclipse may be quite a technical achievement, but I found it > irritating. Aside from the misuse of screen real-estate, I found > that typing two characters and having what seemed like half my > source file underlined in red, with multiple messages telling me > that I had yet to define or import something or other when what I > was about to do was to write the declaration, all conspired to > make me want to scream, "WTF do you think I was going to type in > about five seconds time? Work it out and autocomplete it if you're > so damned clever!" I had exactly the same experience when trying out Eclipse :D I'll stick with "good ol' vi". Regards, Bj?rn -- BOFH excuse #227: Fatal error right in front of screen From robin at NOSPAMreportlab.com Wed Dec 20 16:44:48 2006 From: robin at NOSPAMreportlab.com (Robin Becker) Date: Wed, 20 Dec 2006 21:44:48 +0000 Subject: [ANN] PyInstaller 1.3 released In-Reply-To: References: Message-ID: <4589AED0.8010904@jessikat.plus.net> Giovanni Bajo wrote: ........ > yeah that's pretty cryptic. It's a known bug which I need to come around > and fix it. Anyway, the message itself is harmless: if the program then > exits, there is *another* problem. > > If you want to help with that, you could enable the console+debug mode > and see what the traceback is. I'd be very glad to fix the problem for you. No problem I'll give it a whirl tomorrow. -- Robin Becker From slow at slowhome.org Wed Dec 20 21:32:16 2006 From: slow at slowhome.org (Julio Biason) Date: Thu, 21 Dec 2006 00:32:16 -0200 (BRST) Subject: calling a class instance of function Message-ID: <39751.201.37.73.66.1166668336.squirrel@webmail.slowhome.org> On Wed, December 20, 2006 22:09, Pyenos wrote: > class pid: > "pid" > def add(original_pid,toadd): [...] > def remove(something_to_remove_from,what): [...] > def modify(source,element,changewiththis): [...] > why do i get an error? Did you copy'n'pasted the code here or typed it directly? My guess is that the missing "self" as first parameter in the methods could be causing the problem. -- Julio "slow" Biason From debl2NoSpam at verizon.net Thu Dec 7 00:56:07 2006 From: debl2NoSpam at verizon.net (David Lees) Date: Thu, 07 Dec 2006 05:56:07 GMT Subject: Tkinter on Silicon Graphics machine? In-Reply-To: <1165377089.017708.114300@l12g2000cwl.googlegroups.com> References: <1165377089.017708.114300@l12g2000cwl.googlegroups.com> Message-ID: petercable at gmail.com wrote: > David Lees wrote: >> Does anyone have advice on installing Tkinter on s Silicon Graphics >> machine (under IRIX 6, I think). The SysAdmin at work build Python 2.4.3 >> for me on the SGI box, but it does not have Tkinter. Are there any >> prebuilt distributions for SGI machines that include Tkinter? >> >> TIA >> >> david lees > > I don't have the disks in front of me now, but I think the freeware > disks included with Irix have Python on them. Otherwise, you could > download it from > http://freeware.sgi.com/Installable/python-2.1.1-sgipl1.html > > If you want 2.4, the sysadmin could rebuild Python after installing the > Tcl/Tk libraries (which you will need to use Tkinter anyway.) As long > as libtcl and libtk are in /usr/lib or /usr/local/lib, Tkinter will be > built automatically when Python is built. > > Pete > Pete, Thanks for the advice. This is quite helpful. I will pass this on to the sysadmin. David Lees From greg at cosc.canterbury.ac.nz Fri Dec 15 06:18:38 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:18:38 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1166102108.129051.166580@73g2000cwn.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <1166090708.361757.197170@l12g2000cwl.googlegroups.com> <1166102108.129051.166580@73g2000cwn.googlegroups.com> Message-ID: <4ufenbF17of60U6@mid.individual.net> josephoswaldgg at hotmail.com wrote: > Neil Cerutti wrote: > > > The parenthesis I added means I don't have > > to use the new-line escape character (\), either. > > Is this so unconscious that you don't recognize you are doing it, even > though you take a sentence to explain what you had to do to work around > it? Yes, it is pretty unconscious. We all do many things unconsciously in everyday life that would take at least one sentence to explain to someone else if we had to think about it. Besides, in many cases the required brackets are already there -- e.g. if it's a list, or a function call with many arguments -- in which case you don't have to add anything at all. > Adding parentheses ... all this is a > burden specific to Python. As opposed to Lisp, where all you have to do is use parentheses... oh, er... > By the way, you guys seem fixate on the parentheses of Lisp without > having the experience I don't know about the other Pythonistas in this discussion, but personally I do have experience with Lisp, and I understand what you're saying. I have nothing against Lisp parentheses, I just don't agree that the Lisp way is superior to the Python way in all respects, based on my experience with both. -- Greg From deets at nospam.web.de Mon Dec 11 14:43:48 2006 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 11 Dec 2006 20:43:48 +0100 Subject: Rinning Excel macro's with Jython? References: <1165851203.949329.231220@l12g2000cwl.googlegroups.com> Message-ID: <4u5qnkF16tehsU1@mid.uni-berlin.de> smkhalamayzer at gmail.com wrote: > Is there a way to run Excel macro's with jython? Similar to the > win32com in python? Thank you. I wish people using Jython would remember that whatever they desire the runtime to do, they should investigate the Java options for their problem - and then simply use that with a way nicer python syntax. First link for google:excel automation java http://www.devx.com/Java/Article/27463 Diez From raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com Sun Dec 17 11:38:13 2006 From: raffaelcavallaro at pas-d'espam-s'il-vous-plait-mac.com (Raffael Cavallaro) Date: Sun, 17 Dec 2006 11:38:13 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <4uhl7cF108ri8U2@mid.individual.net> <7xslfgou14.fsf@ruckus.brouhaha.com> <2006121611133827544-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45844272$0$8754$ed2619ec@ptn-nntp-reader02.plus.net> <2006121614375650878-raffaelcavallaro@pasdespamsilvousplaitmaccom> <45853e98$0$8712$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <2006121711381343042-raffaelcavallaro@pasdespamsilvousplaitmaccom> On 2006-12-17 07:54:28 -0500, Jon Harrop said: > What if eager impurity isn't the "very nature" of the problem but, rather, > is the very nature of Tilton's chosen solution? That's the whole point which you keep missing - that a programming language is expressive precisely to the extent that it allows you to express the solution in the *programmer's* chosen form, not the paradigm imposed by the language. You look down your nose at cells, but if that's the way kenny conceived of the problem - as a graph of changing state, why should he be forced to reconceptualize it according to someone else's notion of programming correctness (be that pure functional or any other paradigm)? By asking this question you've implicitly admitted that to solve it *as he thought of it* in a pure functional language would require reconceptualizing it (i.e., the aforementioned "jumping through hoops"). We don't want to reconceptualize everything according to a particular paradigm, we want the flexibility to write the solution to the problem in the terms we think and talk about it, not the procrustean bed of pure functional semantics. From gagsl-py at yahoo.com.ar Mon Dec 18 13:40:05 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 18 Dec 2006 15:40:05 -0300 Subject: Strange error with getattr() function In-Reply-To: <1166459121.661107.251700@73g2000cwn.googlegroups.com> References: <1166455980.365984.296680@l12g2000cwl.googlegroups.com> <1166459121.661107.251700@73g2000cwn.googlegroups.com> Message-ID: <7.0.1.0.0.20061218153655.03faed90@yahoo.com.ar> At Monday 18/12/2006 13:25, Hole wrote: > > At this point, I got the error: attribute name must be string > >I'm wondering if the exception is raised in a hidden function and not >in the explicit call to getattr(). How can I view the traceback in a >script running in zope?? (Which Zope version?) If you don't catch the exception, an error page will be displayed, pointing to the error_log object. -- 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 From g.tagliaretti at gmail.com Wed Dec 27 21:55:55 2006 From: g.tagliaretti at gmail.com (Gian Mario Tagliaretti) Date: Thu, 28 Dec 2006 03:55:55 +0100 Subject: can't instantiate following inner class References: <87mz586eyx.fsf@pyenos.pyenos.org> Message-ID: <45932302$0$19091$4fafbaef@reader4.news.tin.it> Larry Bates wrote: > Proper way is: > > class One: > def __init__(self): > self.Two=Two() > > Of course Two must be a proper class definition also. > > class Two: > def __init__(self): > self.Three=Three() > > class Three: > pass just as a side note probably it would be better to use new style classes in newly written code: class One(object): def __init__(self): whatever don't forget to call __init__ on new style classes otherwise you can pass arbitrary arguments when instantiating the class e.g.: one = One(a, b) but python will silently ignore them and you probably won't like it... cheers -- Gian Mario Tagliaretti From hg at nospam.org Fri Dec 15 15:07:06 2006 From: hg at nospam.org (hg) Date: Fri, 15 Dec 2006 14:07:06 -0600 Subject: Serial port failure References: <1166202118.779153.191170@16g2000cwy.googlegroups.com> Message-ID: Rob wrote: > Hi all, > > I am fairly new to python, but not programming and embedded. I am > having an issue which I believe is related to the hardware, triggered > by the software read I am doing in pySerial. I am sending a short > message to a group of embedded boxes daisy chained via the serial port. > When I send a 'global' message, all the connected units should reply > with their Id and Ack in this format '0 Ack' To be certain that I > didn't miss a packet, and hence a unit, I do the procedure three times, > sending the message and waiting for a timeout before I run through the > next iteration. Frequently I get through the first two iterations > without a problem, but the third hangs up and crashes, requiring me to > remove the Belkin USB to serial adapter, and then reconnect it. Here > is the code: > > import sys, os > import serial > import sret > import time > > from serial.serialutil import SerialException > #################################################################### > #### GetAck Procedure > #################################################################### > def GetAck(p): > response = "" > > try: > response = p.readline() > except SerialException: > print ">>>>>Timed out<<<<<" > return -1 > res = response.split() > > #look for ack in the return message > reslen = len(response) > if reslen > 5: > if res[1] == 'Ack': > return res[0] > elif res[1] == 'Nak': > return 0x7F > else: > return -1 > > >>>>>> Snip <<<<<< > #################################################################### > #### GetNumLanes Procedure > #################################################################### > def GetNumLanes(Lanes): > print "Looking for connected units" > # give a turn command and wait for responses > msg = ".g t 0 336\n" > > for i in range(3): > port = OpenPort() > time.sleep(3) > print port.isOpen() > print "Request #%d" % (i+1) > try: > port.writelines(msg) > except OSError: > print "Serial port failure. Power cycle units" > port.close() > sys.exit(1) > > done = False > # Run first connection check > #Loop through getting responses until we get a -1 from GetAck > while done == False: > # lane will either be -1 (timeout), 0x7F (Nak), > # or the lane number that responded with an Ack > lane = GetAck(port) > if lane >= '0': > if False == Lanes.has_key(lane): > Lanes[lane] = True > else: > done = True > port.close() > time.sleep(3) > > # Report number of lanes found > NumLanes = len(Lanes) > if NumLanes == 1: > print "\n\nFound 1 unit connected" > else: > print "\n\nFound %d units connected" % NumLanes > > return NumLanes > > >>>>>>> Snip <<<<<< > #################################################################### > #### Main Program Code Section > #################################################################### > > #open the serial port > # capture serial port errors from trying to open the port > > port = OpenPort() > > # If we got to here, the port exists. Set the baud rate and timeout > values > > # I need to determine how many lanes are on this chain > # First send a turn command > > #Create a dictionary of lanes so I can check each lane's responses > Lanes = {} > #<><><><><><><><><><><><><><><><> > # Call the lane finder utility > NumLanes = GetNumLanes(Lanes) > #<><><><><><><><><><><><><><><><> > > #if no lanes responded, exit from the utility > if 0 == NumLanes: > print "I can't find any units connected." > print "Check your connections and try again" > sys.exit(1) > > # list the lanes we have in our dictionary > for n in Lanes: > print "Lane - %s" % n > > Now, here is the error message that I get > > dad at nb29:~/py$ ./Thex.py > Looking for connected units > True > Request #1 > True > Request #2 > Serial port failure. Power cycle units > dad at nb29:~/py$ ./Thex.py > The serial port is unavailable. > Disconnect your USB to Serial adapter, Then > reconnect it and try again. > dad at nb29:~/py$ > > Does anyone have any ideas? > > Thanks, > > rob < Amateur.N7TZG at gmail.com > Where is OpenPort ? hg From nogradi at gmail.com Sun Dec 17 04:48:35 2006 From: nogradi at gmail.com (Daniel Nogradi) Date: Sun, 17 Dec 2006 10:48:35 +0100 Subject: module wide metaclass for new style classes In-Reply-To: References: Message-ID: <5f56302b0612170148rbc409cbyfa4ea669fe5e79aa@mail.gmail.com> > > I used to have the following code to collect all (old style) class > > names defined in the current module to a list called reg: > > > > > > def meta( reg ): > > def _meta( name, bases, dictionary ): > > reg.append( name ) > > return _meta > > > > reg = [ ] > > __metaclass__ = meta( reg ) > > > > class c1: > > pass > > > > class c2: > > pass > > > > print reg > > That code does not create classes. Here's a slightly simplified version: > > >> reg = [] > >>> def __metaclass__(name, bases, dict): > ... reg.append(name) > ... > >>> class A: pass > ... > >>> reg > ['A'] > >>> A is None > True # oops! > > > This would correctly print [ 'c1', 'c2' ]. Now I would like to switch > > to new style classes but replacing class c1: and class c2: by class > > c1(object): and class c2(object): doesn't work because the metaclass > > associated with object will be called and not mine. Of course if I > > would add __metaclass__ = meta(reg) to all class definitions that > > would work, but how do I do this on the module level? > > If present, __metaclass__ serves as a factory for classes without an > explicit base class. For example, > > __metaclass__ = type > > would turn c1 and c2 into newstyle classes (that inherit from object). > If you want side effects you can wrap the metaclass into a function: > > >>> reg = [] > >>> def __metaclass__(name, bases, dict): > ... reg.append(name) > ... return type(name, bases, dict) > ... > >>> class A: pass > ... > >>> class B: pass > ... > >>> reg > ['A', 'B'] > >>> issubclass(A, object) > True Thanks a lot, and sorry for the copy-paste error, I had the 'return type(...)' line but didn't know that this already creates new-style classes. From shejo284 at gmail.com Mon Dec 18 16:21:50 2006 From: shejo284 at gmail.com (Sheldon) Date: 18 Dec 2006 13:21:50 -0800 Subject: Core dump revisited In-Reply-To: References: <1166349672.479548.4460@80g2000cwy.googlegroups.com> Message-ID: <1166473528.013422.227310@l12g2000cwl.googlegroups.com> Nick Craig-Wood skrev: > Sheldon wrote: > > gdb msgppscomp.py core.3203 > > Run > > gdb python > > Then type > > run msgppscomp.py > > at the gdb prompt. > > When it crashes, type "bt" for a back trace. This will pinpoint > exactly where it crashes. > > Hopefully that will make things clearer. If not post the output. > > -- > Nick Craig-Wood -- http://www.craig-wood.com/nick Wonderful! Now I know how to used gdb with python. The are results area posted below. Since I am new at this I could used some help in interpreting the problem. What I do know is this: my allocation of the array is good but when freeing the array, a problem arises. The problem is given below but since I am new as well to C I sure could use some help. Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1077321856 (LWP 32710)] 0x40297b83 in mallopt () from /lib/tls/libc.so.6 (gdb) bt #0 0x40297b83 in mallopt () from /lib/tls/libc.so.6 #1 0x402958ba in free () from /lib/tls/libc.so.6 #2 0x405e070a in MemoryFreeOrd () at msgppsmodule_area.c:1675 #3 0x405dae0a in msgppsarea (self=0x0, args=0x4042aa7c, kwargs=0x0) at msgppsmodule_area.c:328 #4 0x40073b16 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0 I appreciate your help so far and could use some more. /S From mail at microcorp.co.za Sat Dec 23 02:13:53 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Sat, 23 Dec 2006 09:13:53 +0200 Subject: Retrieve Tkinter listbox item by string, not by index References: <44e1e$458c40af$4275d90a$22798@FUSE.NET> Message-ID: <011701c72661$e7a9da20$03000080@hendrik> "Kevin Walzer" wrote: > I'm trying to set the active item in a Tkinter listbox to my > application's currently-defined default font. not sure if you can mix fonts in a listbox - the font option when you create the listbox instance seems to apply globally to all the lines in the box > Here's how I get the fonts loaded into the listbox: > > self.fonts=list(tkFont.families()) > self.fonts.sort() > > for item in self.fonts: > self.fontlist.insert(END, item) #self.fontlist is the > ListBox instance > Does this actually give you different fonts on each line? or just a list of available font names, all displayed in the same font? > > So far, so good. But I don't know how to set the active selection in the > listbox to the default font. All the methods for getting or setting a > selection in the listbox are based on index, not a string. And using > standard list search methods like this: > > if "Courier" in self.fontlist: > print "list contains", value > else: > print value, "not found" > > returns an error: > > TypeError: cannot concatenate 'str' and 'int' objects > > So I'm stuck. Can someone point me in the right direction? not too sure I understand what you are trying to do - but consider: idx = self.fontlist.curselection() this is the index of the selection, (as controlled by the user's fingers) so: StringAtCurrSelection = self.fontlist.get(idx) should be the string containing the text on the selected line you can use self.fontlist.delete(idx) and self.fontlist.insert(idx,SomeString) to make changes to the text. But as to how you change this to display in a different font - no can tell - don't know how, and not sure if its possible. Only know that you can use configure to change the font for all the lines in the box by changing the box's font option... if, OTOH you are just trying to find where your default lives in the box, why don't you look for it and remember the index when you are populating the box? something like this: self.idx = 0 for item in self.fonts: if item == mydefaultfont: self.defidx = idx self.fontlist.insert(idx, item) idx += 1 then you can do whatever with the item that lives at self.defidx afterwards... hth - Hendrik From void.no.spam.com at gmail.com Wed Dec 20 19:50:09 2006 From: void.no.spam.com at gmail.com (void.no.spam.com at gmail.com) Date: 20 Dec 2006 16:50:09 -0800 Subject: TypeError: unbound method must be called with class instance 1st argument In-Reply-To: <1166660856.886262.293100@i12g2000cwa.googlegroups.com> References: <1166660370.705628.30360@79g2000cws.googlegroups.com> <1166660856.886262.293100@i12g2000cwa.googlegroups.com> Message-ID: <1166662209.334877.218680@73g2000cwn.googlegroups.com> Matimus wrote: > > Can someone please explain why I get the following error: > > The following line: > threading.Thread.__init__() > Should be written as: > threading.Thread.__init__(self) Thank you! From slawomir.nowaczyk.847 at student.lu.se Fri Dec 15 17:38:57 2006 From: slawomir.nowaczyk.847 at student.lu.se (Slawomir Nowaczyk) Date: Fri, 15 Dec 2006 23:38:57 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <7xodq5tboy.fsf@ruckus.brouhaha.com> Message-ID: <20061215214046.57E8.SLAWOMIR.NOWACZYK.847@student.lu.se> On Fri, 15 Dec 2006 17:21:12 +0100 Andr? Thieme wrote: #> And we might go further (again with an easy Graham example). #> See this typical pattern: #> #> result = timeConsumingCalculation() #> if result: #> use(result) #> #> We need this ugly temporary variable result to refer to it. #> If we could use the anaphor[1] "it" that could make situations like #> these more clean. #> #> Imagine Python would have an "anaphoric if", "aif". Then: #> #> aif timeConsumingCalculation(): #> use(it) I would spell the above like this: def timeConsumingCalculation(): pass def useit(it): pass def aif(first,second): res = first() if res: second(res) aif(timeConsumingCalculation,useit) Sure, it requires me to define function useit instead of embedding the code in aif call, but that has never been a problem for me: in reality, the code I would want to execute would be complex enough to warrant it's own function anyway. Of course, YMMV. -- Best wishes, Slawomir Nowaczyk ( Slawomir.Nowaczyk at cs.lth.se ) Real programmers can write assembly code in any language. From bj_666 at gmx.net Sat Dec 16 15:27:53 2006 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sat, 16 Dec 2006 21:27:53 +0100 Subject: Roundtrip SQL data especially datetime References: <1166211949.065578.292600@f1g2000cwa.googlegroups.com> <1166258893.044093.196820@79g2000cws.googlegroups.com> Message-ID: In , John Nagle wrote: > John Machin wrote: >> John Nagle wrote: >>>dyork wrote: >>>>"John Machin" wrote in message >>>>news:1166211949.065578.292600 at f1g2000cwa.googlegroups.com... >>>> >>>> >>>>>If you have, as you should, Python 2.5, you can use this: >>> >>> Actually, MySQLdb isn't released for Python 2.5 yet >> >> >> Actually, that's interesting information [why should it take so long?], >> but the OP didn't actually say what brand of database he was actually >> using :-) > > True. > > Why should it take so long? The Python people don't support the > MySQL interface, and the MySQL people don't support the Python interface. > There's one guy on Sourceforge doing the MySQLdb glue code. And he's busy. AFAIK there's no MySQLdb module for Python 2.5 on *Windows* yet, because the author of the module doesn't use Windows anymore and he don't want to maintain a binary he can't test. Ciao, Marc 'BlackJack' Rintsch From jtittsler at gmail.com Thu Dec 7 20:49:16 2006 From: jtittsler at gmail.com (Jim Tittsler) Date: 7 Dec 2006 17:49:16 -0800 Subject: subversion revision number string within an application packaged with distutils? Message-ID: <1165542556.714372.193340@n67g2000cwd.googlegroups.com> Is there a standard recipe for getting the subversion revision number into my Python-based application each time I package it up with distutils? (Not just the package name, but also a string that I will display in my app's "About" dialog.) From isaac.rodriguez at comcast.net Tue Dec 12 14:21:57 2006 From: isaac.rodriguez at comcast.net (Isaac Rodriguez) Date: 12 Dec 2006 11:21:57 -0800 Subject: One module per class, bad idea? In-Reply-To: References: Message-ID: <1165951317.257240.240310@l12g2000cwl.googlegroups.com> > make the import statements look good. You can still make your import statements look good and have one class per file, that's one of the __init__.py wonderful features. Also, C++ support stand alone functions and the rule is to organize classes and their interface (functions that operate in objects of the class are considered part of the interface) in their own module. I will like to understand why this will not be a good idea for python, other than to make beautiful import statements that is. Thanks, - Isaac. From gagsl-py at yahoo.com.ar Tue Dec 12 19:09:21 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Tue, 12 Dec 2006 21:09:21 -0300 Subject: newb: SENDING os.system(encode_cmd) output to a logging file In-Reply-To: <1165891780.262871.200130@79g2000cws.googlegroups.com> References: <1165880879.620563.287790@l12g2000cwl.googlegroups.com> <1165891780.262871.200130@79g2000cws.googlegroups.com> Message-ID: <7.0.1.0.0.20061212210516.057a4cd0@yahoo.com.ar> At Monday 11/12/2006 23:49, johnny wrote: >Gabriel Genellina wrote: > > At Monday 11/12/2006 20:47, johnny wrote: > > > > >How do I pipe the output, generated from os.system(some_command), to > > >the logging file? > > > > Use the subprocess module to run the command instead. > >I am doing the os.system(encode_cmd) within a thread. So you are >saying, have each thread create a subprocess module. Did you mean, >"Popen" (os.popen)? > >Like os.popen(encode_cmd) , not os.system(encode_cmd)? No, I mean the module called "subprocess" contained in the standard Python library since version 2.4: http://docs.python.org/lib/module-subprocess.html -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From greg at cosc.canterbury.ac.nz Wed Dec 20 06:34:07 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Thu, 21 Dec 2006 00:34:07 +1300 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: <4uslgfF18sq18U1@mid.individual.net> Nick Maclaren wrote: > Nope. Sorry. Consider the old model where an I/O list is an ordered > sequence of strings and agents (effectively procedure calls), with no > constraints on how those are ordered. With your specification, that > is neither heterogenous nor homogenous :-) I don't see any difficulty. This is a list (homogeneous) of two-element tuples (heterogeneous). If you're thinking of representing this as just a flat list, [str1, agent1, str2, agent2, ...], that's a borked way of doing it and you deserve whatever philosophical knots you get into as a result. > It's a complete delusion, because even the claimed assumption of list > homogeneity is tantmount to saying that Python doesn't encourage (or, > arguably, support) ANY way of using mutable heterogenous sequences > (such as the example above). It's unfortunate that Python doesn't make the homogeneous/ heterogeneous distinction orthogonal to the mutable/immutable one. Ideally, yes, there would be mutable and immutable tuples, and mutable and immutable lists. Perhaps also even fixed and variable sized versions of these as well. But that would be eight different data types, which is a lot of trouble to go to just to give you something that's precisely tailored to exactly what you want. Some might say it was overkill. Python takes a more pragmatic approach, and provides just two: the tuple, optimised for the case of heterogeneous *and* fixed size *and* immutable -- and the list, for everything else. So it's not really that lists are intended *only* for homogeneous collections, but for anything that can't be represented as a tuple for whichever reason. -- Greg From basti.wiesner at gmx.net Thu Dec 21 07:54:28 2006 From: basti.wiesner at gmx.net (Sebastian 'lunar' Wiesner) Date: Thu, 21 Dec 2006 13:54:28 +0100 Subject: What am I supposed to do with an egg?! References: Message-ID: Stephan Kuhagen wrote > Sebastian 'lunar' Wiesner wrote: > >> Morpheus wrote >> >>> So, what am I supposed to do here now? >> >> That's easy: Breed it... > > Since two days I'm fighting with myself not to make this joke. Thanks > for relieving me... No problem ;) -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) From timr at probo.com Tue Dec 5 02:08:16 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 05 Dec 2006 07:08:16 GMT Subject: Video stream server References: <1165216465.101749.227330@n67g2000cwd.googlegroups.com> <1165218527.632366.290350@j44g2000cwa.googlegroups.com> <1165221764.002660.197600@16g2000cwy.googlegroups.com> Message-ID: "Lad" wrote: > >The most important thing now is how to add a support for video files. This is not really a Python question -- it's an HTML question. You need to spend some time Googling for and tags which allow you shove a video as part of a web page. Then you can use your Python web site to create the appropriate HTML. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From carsten at uniqsys.com Fri Dec 29 14:34:16 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Fri, 29 Dec 2006 14:34:16 -0500 Subject: Getting VideoCapture to work with Python 2.5 In-Reply-To: References: Message-ID: <1167420856.3411.29.camel@dot.uniqsys.com> On Fri, 2006-12-29 at 19:15 +0000, Just Another Victim of the Ambient Morality wrote: > I can't seem to get VideoCapture (http://videocapture.sourceforge.net/) > to work with my version of Python (2.5). Why is that? I've followed the > instructions which made it look easy but, as it happens all too often, it > simply doesn't work. The error I get is that the .py interface file can't > find an expected module (using the "import" keyword) but that module exists > as a DLL in the correct directory. Why doesn't it recognize it? > Has anyone else used this library with Python 2.5 successfully? Any > theories as to what might be going wrong? Thank you... DLL extension modules have to be compiled specifically for each major Python version. The website makes no indication that the module is supposed to work on Python 2.5, and the zip file contains folders for Python 2.0 through 2.4, but 2.5 is conspicuously missing. You could downgrade to Python 2.4 or ask the author to make a version for Python 2.5 available. -Carsten From greg at cosc.canterbury.ac.nz Sat Dec 9 21:36:38 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 10 Dec 2006 15:36:38 +1300 Subject: Automatic debugging of copy by reference errors? In-Reply-To: <1165672702.406793.320500@79g2000cws.googlegroups.com> References: <1165641773.903394.295300@80g2000cwy.googlegroups.com> <1165645676.694401.193580@16g2000cwy.googlegroups.com> <1165666093.996141.244760@n67g2000cwd.googlegroups.com> <1165672702.406793.320500@79g2000cws.googlegroups.com> Message-ID: <4u1a8gF16ceopU1@mid.individual.net> Niels L Ellegaard wrote: > I wanted to warn the user whenever he tried to > change an object that was being refered to by a living object. To see how fundamentally misguided this idea is, consider that, under your proposal, the following program would produce a warning: a = 1 The reason being that the assignment is modifying the dictionary holding the namespace of the main module, which is referred to by the main module itself. So you are "changing an object that is being referred to by a living object". -- Greg From no-spam at no-spam-no-spam.invalid Fri Dec 1 11:25:44 2006 From: no-spam at no-spam-no-spam.invalid (robert) Date: Fri, 01 Dec 2006 17:25:44 +0100 Subject: Detecting recursion loops In-Reply-To: References: <1164815293.529674.109850@l39g2000cwd.googlegroups.com> Message-ID: Ben Finney wrote: > robert writes: > >> Carl Banks wrote: >>> 2. Consider whether you're unwittingly trying to cover up a bug. >>> ISTM no matter how problematic the input is, you should at least >>> be able to make progress on it. Are you getting this error >>> because, say, you're not incrementing a counter somewhere, and >>> thus recalling a function with the same arguments again? >> the "bug" comes in from the I/O input. > > If a program doesn't gracefully deal with bad input, that's a bug in > the program. You should be designing your input handler so that it > will do something helpful (even if that's to stop immediately with an > informative error message) in the event of bad input, rather than > allowing that bad data to send your program into an endless loop. Yet that detection is what the asked alg should do. Example: When a HTML-(content)-relaying sends you around in a circle through a complex handler chain. Robert From pyenos at pyenos.org Wed Dec 20 21:25:48 2006 From: pyenos at pyenos.org (Pyenos) Date: 21 Dec 2006 13:25:48 +1100 Subject: what is wrong with my code? References: <874prq6wmd.fsf@pyenos.pyenos.org> <87vek65cne.fsf@pyenos.pyenos.org> <1166667427.238372.150240@t46g2000cwa.googlegroups.com> Message-ID: <87mz5i56j7.fsf@pyenos.pyenos.org> thanks for your point. so because i have said class blah: i must explicitly say self for every instantiation of object? From duncan.booth at invalid.invalid Fri Dec 22 08:00:16 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 22 Dec 2006 13:00:16 GMT Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> <458b0e0b$0$9768$426a74cc@news.free.fr> <1166741966.242087.192390@n67g2000cwd.googlegroups.com> <1166767205.559937.185260@f1g2000cwa.googlegroups.com> <1166773847.368709.299960@48g2000cwx.googlegroups.com> <1166780607.921591.248000@f1g2000cwa.googlegroups.com> <1166788615.366859.251880@42g2000cwt.googlegroups.com> Message-ID: "John Machin" wrote: > > Duncan Booth wrote: >> "John Machin" wrote: >> > You are saying that you think that George thinks that they are >> > teaching efficient coding methods in OO classes?? >> > >> No, but I hope they teach how to recognise patterns, and I imagine >> they also teach something about refactoring to remove switches or >> long if/elif chains. (My imagination may not, of course, bear any >> resemblance to real life.) > > My point is that efficent coding methods, recognition of patterns and > refactoring are *general* comp sci concepts, they are not special to > OO. Why do you hope / imagine such things about OO classes? > Both things are applicable outside OO, but the OO community is where they evolved. The concept of design patterns was popularized by the Gang of Four in "Design Patterns: Elements of Reusable Object-Oriented Software", and I believe that the concept of refactoring also grew out of the OO community. According to Wikipedia, which is occasionally not far wrong: > The first known use of the term "refactoring" in the published > literature was in the article, Refactoring: An Aid in Designing > Application Frameworks and Evolving Object-Oriented Systems, > Proceedings of the Symposium on Object Oriented Programming > Emphasizing Practical Applications (SOOPPA) September, 1990, ACM by > William F. Opdyke and Ralph E. Johnson. From kentilton at gmail.com Sat Dec 9 22:43:06 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 22:43:06 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: Steven D'Aprano wrote: > The day has not yet arrived that nobody ever needs to edit code in a > plain, vanilla text editor. Gee, 200kloc of Lisp and I have not got there yet. Keep banging that drom, Steve. :) ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From eadmund42 at NOSPAMgmail.com Tue Dec 12 21:29:39 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 19:29:39 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: Steven D'Aprano writes: >>> >>>> Yes. But you can't redefine 1+2 in Python, at least not without hacking >>>> the interpreter. Can you redefine (+ 1 2) in Lisp? >>> >>> Not without barreling through error messages about name conflicts. >> >> Ah, nice to get a straight answer to a question for a change, and without >> an insult or a misrepresentation in sight. Thank you. > > Such a pity that answer is, apparently, wrong. > > Thank you to those who wrote back with the more accurate answer, which > apparently is "yes, it is easy and there are no error messages". Yes, you can do it if you want--but you have to explicitly say that you're doing so. In other words, it wouldn't happen by accident. And due to the package system, package A doing it wouldn't infect package B unless B allowed it to. In other words, you have to put the bullet in the chamber, take off the safety and point the gun at your foot. -- Robert Uhl What some idiot in Glasgow or NYC, what a million idiots do, has nothing at all to do with me, I can only be judged by the actions I take with my possessions. To do anything else is to spit upon my existence as an individual human. --R.D. Metcalf From NO_Kroeger at gmx.de Thu Dec 21 05:40:16 2006 From: NO_Kroeger at gmx.de (=?iso-8859-1?Q?=22Nils_Oliver_Kr=F6ger=22?=) Date: Thu, 21 Dec 2006 11:40:16 +0100 Subject: what is wrong with my code? In-Reply-To: <874prq6wmd.fsf@pyenos.pyenos.org> References: <874prq6wmd.fsf@pyenos.pyenos.org> Message-ID: <20061221104016.280350@gmx.net> Hi, this is the line that breaks your code: def progressTable(progress_table, action, task, pid=len(progress_table) your parameter progress_table is known inside the function, not inside its definition. So "pid=len(progress_table)" won't do. If you really think that it is possible that pid is anything else but "len(progress_table)", you should use for example -1 as the default value and calculate the length inside your functions if the parameter is not different. Otherwise dump this parameter. Hope that helps! Greetings Nils -------- Original-Nachricht -------- Datum: 21 Dec 2006 09:16:58 +1100 Von: Pyenos An: python-list at python.org Betreff: what is wrong with my code? > import cPickle, shelve > > could someone tell me what things are wrong with my code? > > class progress: > > PROGRESS_TABLE_ACTIONS=["new","remove","modify"] > DEFAULT_PROGRESS_DATA_FILE="progress_data" > PROGRESS_OUTCOMES=["pass", "fail"] > > > def unpickleProgressTable(pickled_progress_data_file): > > return unpickled_progress_table > > def pickleProgressTable(progress_table_to_pickle): > > return pickled_progress_data_file > > # Of course, you get progress_table is unpickled progress table. > def progressTable(progress_table, action, task, > pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]): > pid_column_list=progress_table[0] > task_column_list=progress_table[1] > outcome_column_list=progress_table[2] > > # But a task must also come with an outcome! > def newEntry(new_task, new_outcome): > new_pid=len(task_column_list) > > pid_column_list.extend(new_pid) > task_column_list.extend(new_task) > outcome_column_list.extend(new_outcome) > > def removeEntry(pid_to_remove, task_to_remove): > > if > pid_column_list.index(pid_to_remove)==task_column_list.index(task_to_remove): > # Must remove all columns for that task > index_for_removal=pid_column_list.index(pid_to_remove) > > pid_column_list.remove(index_for_removal) > task_column_list.remove(index_for_removal) > outcome_column_list.remove(index_for_removal) > > # Default action is to modify to pass > def modifyEntry(pid_to_modify, > outcome_to_modify=PROGRESS_OUTCOMES[0]): > index_for_modifying=pid_column_list.index(pid_to_modify) > > # Modify the outcome > outcome_column_list[index_for_modifying]=outcome_to_modify > -- > http://mail.python.org/mailman/listinfo/python-list -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal f?r Modem und ISDN: http://www.gmx.net/de/go/smartsurfer From manstey at csu.edu.au Mon Dec 4 19:20:26 2006 From: manstey at csu.edu.au (manstey) Date: 4 Dec 2006 16:20:26 -0800 Subject: sending string or list to a function Message-ID: <1165278026.064172.147770@l12g2000cwl.googlegroups.com> Hi, Is there a neat way to write a function that can receive either a string or a list of strings, and then if it receives a string it manipulates that, otherwise it manipulates each string in the list? That is, rather than having to send a list of one member MyFunction(['var1']), I can send MyFunction('var1') or MyFunction(['var1','var2',var3']) Or is this bad programming style? What do you think? From usenet-mail-0306.20.chr0n0ss at spamgourmet.com Fri Dec 1 15:30:07 2006 From: usenet-mail-0306.20.chr0n0ss at spamgourmet.com (Bjoern Schliessmann) Date: Fri, 01 Dec 2006 21:30:07 +0100 Subject: I/O Multiplexing and non blocking socket References: <1164982048.938862.228890@79g2000cws.googlegroups.com> <1164984877.492407.59770@n67g2000cwd.googlegroups.com> Message-ID: <4tbhluF13bmgrU2@mid.individual.net> Salvatore Di Fazio wrote: > Thank you guys, but I would like to use the standard libraries Then I suggest you read a good book about Unix programming, especially about the workings of read(), write() and select(). If you've understood this doing it with python's read/write/select will be easy. Everyone may choose to reinvent the wheel :) Regards, Bj?rn -- BOFH excuse #180: ether leak From Leo.Kislov at gmail.com Sat Dec 2 03:26:17 2006 From: Leo.Kislov at gmail.com (Leo Kislov) Date: 2 Dec 2006 00:26:17 -0800 Subject: Printing Barcodes from webapp? References: <1165040626.505772.312350@j72g2000cwa.googlegroups.com> Message-ID: <1165047976.947348.279660@f1g2000cwa.googlegroups.com> Burhan wrote: > Hello Group: > > I am in the planning stages of an application that will be accessed > over the web, and one of the ideas is to print a barcode that is > generated when the user creates a record. The application is to track > paperwork/items and uses barcodes to easily identify which paper/item > belongs to which record. > > Is there an easy way to generate barcodes using Python -- considering > the application will be printing to a printer at the client's machine? > I thought of two ways this could be done; one would be to interface > with the printing options of the browser to ensure that margins, > headers, footers are setup properly (I have done this before using > activex and IE, but with mixed results); the other would be to install > some small application at the client machine that would intercept the > print jobs and format them properly (taking the printing function away > from the browser). > > Does anyone have any experience or advice? Any links I could read up > on to help me find out how to program this? Another way (easier > hopefully) to accomplish this? I think one of the easiest ways is to install acrobat reader and redirect client browser to a generated pdf file. http://www.reportlab.org/ has support for generating barcodes (and more) in pdf documents. -- Leo From brandon.mcginty at gmail.com Thu Dec 21 13:11:16 2006 From: brandon.mcginty at gmail.com (Brandon McGinty) Date: Thu, 21 Dec 2006 11:11:16 -0700 Subject: PythonCard Auto Placement Message-ID: <458ACE44.3010005@gmail.com> Hi All, I'm getting started with pythoncard. I'm wondering if there is any way to auto-place the gui elements that I use, so that they are all visible, and aligned? I would use the "layout/resource" editors, but I'm blind, so I can't see where the elements end up, and the controls for moving don't show up as usable controls in my screen reader. Any help is appreciated. Thanks Much, Brandon McGinty From duncan.booth at invalid.invalid Tue Dec 26 13:40:34 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Dec 2006 18:40:34 GMT Subject: SPAM-LOW: Re: BeautifulSoup vs. loose & chars References: Message-ID: Andreas Lysdal wrote: >> P.S. apos is handled specially as it isn't technically a >> valid html entity (and Python doesn't include it in its entity >> list), but it is an xml entity and recognised by many browsers so some >> people might use it in html. >> > Hey i fund this site: > http://www.htmlhelp.com/reference/html40/entities/symbols.html > > I hope that its what you mean. Try http://www.w3.org/TR/html4/sgml/entities.html#entities for a more complete list. From steve at REMOVE.THIS.cybersource.com.au Sun Dec 10 12:24:28 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 11 Dec 2006 04:24:28 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> Message-ID: On Sun, 10 Dec 2006 08:51:44 -0800, JShrager at gmail.com wrote: > Since I'm probably (although I'm not certain) the only person in this > thread who has made a significant amount of money on either of these > languages (i.e., via the sale of a startup whose product was tens of > thousands of lines of Lisp code Care to tell us what the startup was, and where it is now? -- Steven. From inq1ltd at verizon.net Sat Dec 30 12:11:02 2006 From: inq1ltd at verizon.net (jim-on-linux) Date: Sat, 30 Dec 2006 12:11:02 -0500 Subject: Easiest way to print from XP/DOS. In-Reply-To: <3l1cp25h1cc1if2oi5psodll1mtu0cdfug@4ax.com> References: <3l1cp25h1cc1if2oi5psodll1mtu0cdfug@4ax.com> Message-ID: <200612301211.02698.inq1ltd@verizon.net> Thanks, However, using note to print is a problem. First, because note adds a header( file name etc.) to the printed output that is not acceptable. Next, the number of files is 200 to 300 per day. The idea of the utility is to eliminate the operator. But, if you have a virus detector that stops the operation then I think I may have to install the program as opposed to unzipping and running the exe file. On Saturday 30 December 2006 01:33, Tom Plunker wrote: > jim-on-linux wrote: > > When the client runs the utility program the > > output file is built but nothing prints and > > no messages appear. > > If the file has a '.txt' extension, you could > try os.system'ing "start ", which'll > make the file pop open with notepad (or > whatever happens to be associated with TXT > files), from which the user would need to press > Ctrl-P to make it print. > > > Is it possible that virus detector or some > > self.defense software is interacting? > > Quite. I run firewall software on my PC that > alerts me when a program is trying to launch > another program. The message that it gives is > not entirely unlike the one you gave me. > > To diagnose further, you could have the victim > send you a screenshot to see what's really > going on. With Outlook, it's as easy as > hitting the Print Screen button (when the > message is visible) and pasting the clipboard > into an email. Alternatively, they paste into > MS Paint, save the bitmap somewhere, and mail > that to you. > > Good luck, > -tom! > > -- From arkanes at gmail.com Wed Dec 20 09:51:33 2006 From: arkanes at gmail.com (Chris Mellon) Date: Wed, 20 Dec 2006 08:51:33 -0600 Subject: Fall of Roman Empire In-Reply-To: <873b7b6one.fsf@benfinney.id.au> References: <20061220054657.7CEEA1E4006@bag.python.org> <1166595864.797404.260570@n67g2000cwd.googlegroups.com> <873b7b6one.fsf@benfinney.id.au> Message-ID: <4866bea60612200651s1e836556h674d1283a9914dec@mail.gmail.com> On 12/20/06, Ben Finney wrote: > "John Machin" writes: > > > Ben Finney wrote: > > > > > \ "...one of the main causes of the fall of the Roman Empire was | > > > `\ that, lacking zero, they had no way to indicate successful | > > > _o__) termination of their C programs." -- Robert Firth | > > > > An amusing .sig, but it doesn't address the root cause: As they had no > > way of testing for the end of a string, in many cases successful > > termination of their C programs would have been unlikely. > > Yet historically proven: the 'imperium' process they were running > terminated many centuries ago. > > Or did it fork and exec a different process? > According to the C standard (16AD version), access past the end of an imperial era results in undefined behavior. From address.good.until.2006.dec.22 at justmail.de Mon Dec 11 12:34:36 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Mon, 11 Dec 2006 18:34:36 +0100 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> Message-ID: Fred Gilham schrieb: > Paul Rubin writes: > >> Andr? Thieme writes: >>> Instead of function = memoize(function) >>> one could just say: memoize(function). >> In Python you'd say >> >> @memoize >> def function(): ... > > But in Lisp you'd write the function, say, "Damn, I need to memoize > this sucker," and evaluate > > (memoize 'function) > > and the function would be memoized. > > I suspect you could even do this "while the program was running" from > something like SLIME. Basically the memoize macro changes the > function cell of the symbol, so from that point all the calls to the > function would be to the memoized version. > You don't even need to say 'function (memoize function) would be enough. And yes, you can memoize functions while the program is running. And you don't need a tool like slime for it. Lisp already offers ways for doing that. Andr? -- From fredrik at pythonware.com Sun Dec 17 09:23:23 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Dec 2006 15:23:23 +0100 Subject: Changing variable to integer In-Reply-To: References: Message-ID: vertigo wrote: > I receive such error: > File "p4.py", line 24, in PrintWordCountFloat > print "%s %f" % (word,words[word]) > TypeError: list indices must be integers please post the *entire* traceback message. see: http://effbot.org/pyfaq/tutor-i-need-help-im-getting-an-error-in-my-program-what-should-i-do From steve at REMOVE.THIS.cybersource.com.au Fri Dec 29 17:46:15 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sat, 30 Dec 2006 09:46:15 +1100 Subject: I want to see all the variables References: <45952426.1080800@websafe.com> <8yelh.90$Q4.82@newsfe02.lga> Message-ID: On Fri, 29 Dec 2006 12:04:11 -0800, johnf wrote: > Ok then how do debug when I have something like "__source" and I need to > know what is available for the object? Outside of a class, objects with two leading underscores are just ordinary objects with no special behaviour: >>> __source = 2 >>> __source 2 Objects with a single leading underscore like _source are slightly special: if you do "from module import *" any names with a single leading underscore are not imported. Class attributes with two leading underscores like __source are considered private to the class, so in general you shouldn't need to know anything about them. To enforce that, Python mangles the name so it is harder to reach. But if/when you do need to get to them, they are easy to get to: >>> class Spam: ... __attribute = 2 ... >>> Spam().__attribute Traceback (most recent call last): File "", line 1, in ? AttributeError: Spam instance has no attribute '__attribute' >>> Spam()._Spam__attribute 2 Notice that Python doesn't generally try to hide "private" attributes: >>> dir(Spam) ['_Spam__attribute', '__doc__', '__module__'] There are three other underscore conventions in use: (1) Objects with a single leading underscore like _attribute are private by convention, but Python doesn't enforce it. Starting an object with a single underscore is like writing "# Private! Don't touch!" after it. (2) By convention, if you want to create a name that is the same as a built-in object without shadowing (hiding) the built-in, put a single trailing underscore after it like "file_". That's just a style convention though, you are free to call it FiLE ,or anything else, if you prefer. (3) Last but not least, class attributes with two leading and trailing underscores are considered special but public, like __init__ and __repr__. It is probably a bad idea to invent your own. -- Steven. From rtw at freenet.co.uk Fri Dec 15 06:50:03 2006 From: rtw at freenet.co.uk (Rob Williscroft) Date: Fri, 15 Dec 2006 05:50:03 -0600 Subject: Property error References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> <1166179622.872556.312810@n67g2000cwd.googlegroups.com> <1166181267.949316.197360@16g2000cwy.googlegroups.com> Message-ID: king kikapu wrote in news:1166181267.949316.197360@ 16g2000cwy.googlegroups.com in comp.lang.python: > I am sure it is something very obvious Yes, property is *NOT* a decorator, it can only be used as a decorator in the one case that is mentioned in the docs: If given, doc will be the docstring of the property attribute. Otherwise, the property will copy fget's docstring (if it exists). This makes it possible to create read-only properties easily using property() as a decorator: class Parrot(object): def __init__(self): self._voltage = 100000 @property def voltage(self): """Get the current voltage.""" return self._voltage Note the use of "read-only" in the above description and that the decorated function (voltage) *is* the properties "fget" function. Rob. -- http://www.victim-prime.dsl.pipex.com/ From gagsl-py at yahoo.com.ar Mon Dec 11 21:04:56 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Mon, 11 Dec 2006 23:04:56 -0300 Subject: AttributeError: Logger instance has no attribute 'setFormatter' In-Reply-To: <1165887128.688715.284320@f1g2000cwa.googlegroups.com> References: <1165887128.688715.284320@f1g2000cwa.googlegroups.com> Message-ID: <7.0.1.0.0.20061211230237.03efdd48@yahoo.com.ar> At Monday 11/12/2006 22:32, johnny wrote: >def setupLogging(): > global log > log = logging.getLogger("ftp") > formatter = logging.Formatter('%(name)-12s: %(levelname)-8s >%(message)s') > > log.setFormatter(formatter) > log.setLevel(logging.DEBUG) > > fhnd = logging.FileHandler('py_mybase.log') > fhnd.setLevel(logging.DEBUG) > log.addHandler(fhnd) > >My Error: > log.setFormatter(formatter) >AttributeError: Logger instance has no attribute 'setFormatter' If you look for setFormatter in the Python docs, you find that it is an attribute of Handler instances. So, move it down to fhnd.setFormatter(...) -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From gagsl-py at yahoo.com.ar Thu Dec 14 19:36:10 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Thu, 14 Dec 2006 21:36:10 -0300 Subject: Need Simple Way To Determine If File Is Executable In-Reply-To: <4581CE6D.1040302@velseis.com.au> References: <4581CE6D.1040302@velseis.com.au> Message-ID: <7.0.1.0.0.20061214210910.059f4bc8@yahoo.com.ar> At Thursday 14/12/2006 19:21, John McMonagle wrote: > > I have a program wherein I want one behavior when a file is set > as executable > > and a different behavior if it is not. Is there a simple way to determine > > whether a given named file is executable that does not resort to all the > > lowlevel ugliness of os.stat() AND that is portable across Win32 and *nix? > > > >os.access(pathToFile, os.X_OK) That won't work on Windows. You have to define what do you mean by "a file is set as executable" on Windows. a.exe is executable and nobody would discuss that. I can supress the extension and type simply: a, on the command line, and get a.exe executed. Same for a.com What about a.bat? cmd.exe is executed and runs the batch file. I can even omit the extension. Is a.bat executable then? What about a.py? Another process starts and handles the file (python.exe). Is a.py executable then? I can type a.mdb on the command prompt and launch an Access application. Is a.mdb executable then? If I type a.doc on the command prompt, Word is executed and opens that file. Is a.doc executable then? The answer may be so narrow to just consider .exe .com and a few more, or so broad to consider all things that os.startfile can handle without error. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From http Sun Dec 10 20:09:17 2006 From: http (Paul Rubin) Date: 10 Dec 2006 17:09:17 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> <7xodqczf1h.fsf@ruckus.brouhaha.com> Message-ID: <7xk60zjl1e.fsf@ruckus.brouhaha.com> jayessay writes: > > Maybe not bleeding edge, but more modern than CL in my opinion. > Odd, caml is even older than CL. You'd have to compare (say) OCaml to CL if it's dialect against dialect. If you're going to bring in the earlier ML family you also have to bring in Lisp 1.5, which goes much further back than CL. From duncan.booth at invalid.invalid Wed Dec 6 13:33:26 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Dec 2006 18:33:26 GMT Subject: how to get all the "variables" of a string formating? References: <1165426895.317815.131270@f1g2000cwa.googlegroups.com> Message-ID: "Calvin Spealman" wrote: > I am not aware of anything in the stdlib to do this easily, but its > pretty easy to get them. See this example: > > class format_collector(object): > def __init__(self): > self.names = [] > def __getitem__(self, name): > self.names.append(name) > return '' > > collector = format_collector() > "%(foo)s %(bar)s" % collector > assert collector.names == ['foo', 'bar'] > > Of course, wrapping this functionality into a simple function is > straightforward and will look better. You should return a value like 0 instead of ''. >>> collector = format_collector() >>> "%(foo)s %(bar)d" % collector Traceback (most recent call last): File "", line 1, in "%(foo)s %(bar)d" % collector TypeError: int argument required From oviedo96 at gmail.com Sat Dec 2 07:22:03 2006 From: oviedo96 at gmail.com (patkinson) Date: 2 Dec 2006 04:22:03 -0800 Subject: Python 2.5 bindings for Subversion 1.4.2 on Win32 binary Message-ID: <1165062123.881400.55200@n67g2000cwd.googlegroups.com> Hello, I am one of those guys trying with no chance to get a working copy of TRAC for python 2.5 http://trac.edgewall.org/ is a superb Project managment tool with a wiki, control version (SVN), and a tracking bug/task system. This is a suposed place to go for a windows user: http://trac.edgewall.org/wiki/TracOnWindows/Python2.5 You are able to: - Install a subversion server 1.4.2 (like a windows service). - Install python 2.5 - Install Genshi 0.3.4 - Install Setuptools - Install Trac (0.11dev) from the last development source. But you need a Python 2.5 binding to be able to talk to a subversion repository, and this is a road to nowhere (cul de sac) issue. He is a post from Brandt, Servatius to the Subversion users list asking for this: http://svn.haxx.se/users/archive-2006-12/0041.shtml The people at TRAC and Subversion says: this is a topic not concerning their software. Please, could be any interested team o person in the python Comunity to adapt a python 2.5 interface to SVN ? Great python Projects like TRAC or DJANGO are the "keys" to a wide acceptance of python. Making this easy to the final users is (in my opinion) a survival question for the future of Python. Thanks Peter Atkinson From rpdooling at gmail.com Tue Dec 19 05:36:19 2006 From: rpdooling at gmail.com (BartlebyScrivener) Date: 19 Dec 2006 02:36:19 -0800 Subject: python poetry? Message-ID: <1166524579.271548.32560@a3g2000cwd.googlegroups.com> I'm working on a book of technology and computer programming humor. First, can anybody recommend any other such books? And second is there a repository of Python poetry, poems translated into Python, or humorous Python pseudo code limericks anywhere? I'm making my way through "The Larch," but if there's more elsewhere please point me to it. I'm looking for the Python equivalent of something like this: http://www.heavyflash.com/poetry/Shakespeare_Sonnet18.html Thank you all rd http://dooling.com From claird at lairds.us Fri Dec 1 13:55:16 2006 From: claird at lairds.us (Cameron Laird) Date: Fri, 1 Dec 2006 18:55:16 +0000 Subject: Ruby/Python/REXX as a MUCK scripting language References: <2006112418112116807-zobeid@techiecom> Message-ID: In article , Laurent Pointal wrote: >> . >> . >> . >>>>> there's the security issue that really worries me. . . I have to be >>>>> able to limit what the interpreter can execute. I can't have my users . . . >>> I Agree with F.Bayer, when reading OP post, I immediatly think about Lua. >> >> Does Lua have an appropriate security model--a sandbox or such? >> Fond though I am of Lua, such would be news to me. > >I dont think of a security model like in Java, but in the possibility to >limit the accessible libraries for interpreted code. > > http://www.lua.org/manual/5.1/manual.html#5 > >If OP just need some computation logic, he could limit external world >communication libraries (these libraries must be loaded by the C host >program before being usable by scripts). >Need to look more precisely to the minimum library set to load and to >available functions in this set. Maybe it is possible to remove some >undesired functions from Lua symbol tables just after loading libraries. > > >[note: I have still not used Lua, but I look at it for futur use in a >current development where an embedded Python would be too heavy and make >problems relative to the GIL - but I'm still a Python fan in other use >cases] . . . I agree that Lua has a nice collection of primitives, and there certainly is scope for security-related programming. There isn't a body of work or precedent for polished results in this area, though, ... Good luck with the future use you anticipate. From sjdevnull at yahoo.com Wed Dec 6 09:16:46 2006 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 6 Dec 2006 06:16:46 -0800 Subject: About the 79 character line recommendation In-Reply-To: References: <1165348808.807516.201860@j72g2000cwa.googlegroups.com> Message-ID: <1165414606.018081.4060@n67g2000cwd.googlegroups.com> Olivier Langlois wrote: > There was a coding standard where I worked and the intention behind this > requirement was to make the code printer friendly. Printing code source > with lines longer than 80 chars greatly hinder readability on paper. > I don't think I've ever seen Python code printed out other than in books. Indeed, I don't think I've seen anyone print their code in any language in a decade--it's much easier to read online with tags, class browsers, easy access to version history, etc. The 79-column limit is a hard rule most places I've worked, because pretty much all code is going to wind up with someone looking at it on an 80-column terminal at some point. From jackdied at jackdied.com Wed Dec 13 15:36:19 2006 From: jackdied at jackdied.com (Jack Diederich) Date: Wed, 13 Dec 2006 15:36:19 -0500 Subject: Mark Lutz Python interview In-Reply-To: <1159554334.170062.182720@i3g2000cwc.googlegroups.com> References: <1159554334.170062.182720@i3g2000cwc.googlegroups.com> Message-ID: <20061213203619.GJ5386@performancedrivers.com> They eventually got this once posted on the website. http://techtalk.imi-us.com/Archives/2006/20061001/ The Lutz interview starts at 10:00 minutes in. -Jack On Fri, Sep 29, 2006 at 11:25:34AM -0700, Mark Lutz wrote: > Python author and trainer Mark Lutz will be interviewed > on the radio show Tech Talk this Sunday, October 1st, > at 6PM Eastern time. He'll be answering questions about > Python, his books, and his Python training services. > > For more details about the show, see Tech Talk's website > at http://techtalk.imi-us.com. You can also listen to > the live webcast of the show on KFNX's website, > http://www.1100kfnx.com. > > --Python Training Services > http://home.earthlink.net/~python-training > > -- > http://mail.python.org/mailman/listinfo/python-list > From cjw at sympatico.ca Sat Dec 16 11:00:07 2006 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 16 Dec 2006 11:00:07 -0500 Subject: Conditional iteration In-Reply-To: <4580821a$0$334$e4fe514c@news.xs4all.nl> References: <4580149c$0$321$e4fe514c@news.xs4all.nl> <7xwt4vn6gk.fsf@ruckus.brouhaha.com> <45804584$0$334$e4fe514c@news.xs4all.nl> <1166037659.362222.290520@t46g2000cwa.googlegroups.com> <4580821a$0$334$e4fe514c@news.xs4all.nl> Message-ID: at wrote: > Dear Carl, > > Well, all I can say that for me as a user it would make sense... > > Curiosity: in what sense is it redundant? > All solution/workarounds I have seen so far involve creation of new lists > (subsets) adding to more processing/computation/memory usage. Redundant > suggests that you know alternatives that don't do that. > > Does Guido ever change his mind? Yes, he was opposed to conditional expressions at one time. I like the scheme he came up with. In the present context, Paul Rubin suggested new syntax: Use: for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x > 0): ... more code ... Colin W. > > Cheers, > > @ > > > Carl Banks wrote: > >> at wrote: >>> I am not looking for a work around but more interest if other people >>> might judge this syntax would come in handy? >> Of course people have expressed interest in this in the past, but it's >> not going to happen. There's a way to nest for and if statements, and >> a different way to nest for and if clauses in listcomps, and the two >> methods are considered distinct. Although Guido has said that saving >> indentation levels is important, he hasn't said anything (that I'm >> aware of) that suggests it's important enough to add this complexity >> and redundancy to the language. Sorry. >> >> >> Carl Banks > From greg at cosc.canterbury.ac.nz Tue Dec 12 22:06:52 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Wed, 13 Dec 2006 16:06:52 +1300 Subject: merits of Lisp vs Python In-Reply-To: <457ec2d1$0$8719$ed2619ec@ptn-nntp-reader02.plus.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165849055.492230.119310@n67g2000cwd.googlegroups.com> <7xslfmju4g.fsf@ruckus.brouhaha.com> <87mz5ufl4z.fsf@colinux.pc-mlivshin-ibm.cadence.com.cmm> <457ec2d1$0$8719$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <4u9958F16pm7hU3@mid.individual.net> Jon Harrop wrote: > Outside Lisp, macros are for syntax. Evaluation semantics (e.g. lazy > evaluation) then have nothing to do with macros. I don't think that's entirely true. With currying and lazy evaluation, there's a sense in which Haskell function definitions already *are* macros. There are limits to the degree of syntactical transformation you can reasonably achieve -- it wouldn't be easy to make Haskell code look exactly like Cobol, for example. But usually that's not what you're after -- rather you just want to devise some way to express your intent with a minimum of boilerplate. I once implemented a parser in HUGS. Using nothing but built-in language features, I was able to construct a system whereby I could more or less just write down the BNF grammar rules and feed them straight into the HUGS compiler. Achieving a similar trick in Lisp would probably have required using macros. -- Greg From brochu121 at gmail.com Thu Dec 7 10:21:40 2006 From: brochu121 at gmail.com (david brochu jr) Date: Thu, 7 Dec 2006 10:21:40 -0500 Subject: PyCon 07 Message-ID: <9583ed900612070721t122703b8md3a49fe73f0a7569@mail.gmail.com> Anyone able to register yet for PyCon07? I can't find any link online..I want to get in early to lock in on the cheaper registration rate..any ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: From simone.leo at gmail.com Wed Dec 13 12:02:23 2006 From: simone.leo at gmail.com (Tekkaman) Date: 13 Dec 2006 09:02:23 -0800 Subject: Logging module: problem with some mapping keys Message-ID: <1166029343.340490.163490@79g2000cws.googlegroups.com> I'm getting a strange behaviour from the "pathname" and "lineno" formatter mapping keys. Instead of my file and my line number I get: /usr/lib/python2.4/logging/__init__.py as the file, and 1072 as the line number. I set up my config as follows: logBaseConf = { 'level' : logging.DEBUG, 'format' : "%(levelname)-8s|%(asctime)s|%(pathname)s, %(name)s, line %(lineno)s|%(message)s", 'datefmt ': '%d %b %Y, %H:%M:%S', 'filename': 'logtest.log', 'filemode': 'a' } logging.basicConfig(**logBaseConf) I'm not using any executable-generating tools such as cx_Freeze or Psyco. In fact, I'm getting this error on a very basic script with the specific purpose of testing the logging module capabilities. Thanks in advance for any contribution. T. From jon at ffconsultancy.com Tue Dec 12 11:08:29 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 16:08:29 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <1165649882.563957.87770@n67g2000cwd.googlegroups.com> <457abf83.18014323@news.readfreenews.net> <7xejr8r86m.fsf@ruckus.brouhaha.com> Message-ID: <457ed499$0$8727$ed2619ec@ptn-nntp-reader02.plus.net> Andr? Thieme wrote: > I think you could do that with functional programming. > You can protect the evaluation by encapsulating the args in a function > object? > > def f_Args(x): > return x > > def g_Args(x): > return x > > and then > a = cond(test, f, g, f_Args(x), g_Args(x)) > > if you adopt cond. But of course it is getting ugly. > So a macro can free you from this extra code. Yes, that's just lazy evaluation. Again, you don't need macros. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From gagsl-py at yahoo.com.ar Thu Dec 14 23:05:26 2006 From: gagsl-py at yahoo.com.ar (Gabriel Genellina) Date: Fri, 15 Dec 2006 01:05:26 -0300 Subject: Is it good to create a thread in a non gui thread? In-Reply-To: <45820E89.4050702@gmail.com> References: <45820E89.4050702@gmail.com> Message-ID: <7.0.1.0.0.20061215005803.05a08b10@yahoo.com.ar> At Thursday 14/12/2006 23:55, Lialie - KingMax wrote: >I create a thread in a non gui thread, and it does well. But it seems >strange. Somebody told me better not for it may cause something hard to >imagine. >Is there any different between them? I'm not sure if I understand the question. You can have a non gui application -an HTTP server by example- using many threads with no problems. -- Gabriel Genellina Softlab SRL __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ?gratis! ?Abr? tu cuenta ya! - http://correo.yahoo.com.ar From uymqlp502 at sneakemail.com Mon Dec 4 01:52:30 2006 From: uymqlp502 at sneakemail.com (Russ) Date: 3 Dec 2006 22:52:30 -0800 Subject: Why not just show the out-of-range index? In-Reply-To: References: <1165195429.928771.148400@j44g2000cwa.googlegroups.com> <1165210093.570351.288220@n67g2000cwd.googlegroups.com> <1165211562.329647.164170@f1g2000cwa.googlegroups.com> Message-ID: <1165215150.915803.232180@79g2000cws.googlegroups.com> Dennis Lee Bieber wrote: > OTOH: IndexError is something I seldom see -- most Python statements > are intelligent enough to not need ad hoc indexing. About the only type > that I've seen is just an, almost obvious, off-by-one problem... > > for i in xrange(len(a)): > a[i] = a[i] + a[i+1] > > in which knowing the discrete values isn't that significant (to me, at > least) > > It doesn't occur in things like > > for itm in a: I agree that implicit indexing (your latter construct) is preferable to explicit indexing if the index is not needed for any other purpose. But sometimes the index itself is needed for some computation. And sometimes a list is "randomly" accessed without a loop at all. From kentilton at gmail.com Thu Dec 14 02:52:27 2006 From: kentilton at gmail.com (Ken Tilton) Date: Thu, 14 Dec 2006 02:52:27 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> Message-ID: Ken Tilton wrote: > > > Ken Tilton wrote: > >> >> >> Paul Rubin wrote: >> >>> Ken Tilton writes: >>> >>>> don't know. The point is, we need code (not just data) in defskill >>>> (apologies for nasty formatting): >>> >>> >>> >>> >>> Man that whole thing is messy. > > > I do not see much difference, except that the character count is 25% > less in the macro version: > > (defskill absolute-value > (title "Absolute Value") > (annotations > "Absolute value of #strn# is the 'distance' of #strn# from zero." > "Absolute value is always zero or positive: #str|n|=n#, and > #str|-n|=n#.") > (hints > "Some examples: #str|+42|=42#, #str|-42|=42#, and #str|0|=0#." > "To get the absolute value of a number such as #signed-value#, we > simply drop any minus sign.") > (reverse > (ensure-cloning resx > (make-instance 'mx-number > :value (loop with op1 = (car opnds) > with log = (max 1 (ceiling (log (abs (value op1)) 10))) > for n = (* (signum (value op1)) > (+ 2 (random (expt 10 log)))) > when (/= n (value op1)) > return n) > :representation (representation resx))))) > > (defmethod skill-title ((tf-id (eql 'absolute-value))) > (list "absolute value")) > > (defmethod skill-annotations ((tf-id (eql 'absolute-value))) > (list "absolute value of #strn# is the 'distance' of #strn# from zero." > "absolute value is always zero or positive: #strn=n#, and #str-n=n#.")) > > (defmethod skill-hints ((tf-id (eql 'absolute-value))) > (list "some examples: #str+42=42#, #str-42=42#, and #str0=0#." > "to get the absolute value of a number such as #signed-value#, we > simply drop any minus sign.")) > > (defmethod tf-reverse ((id (eql 'absolute-value)) resx opnds) > (declare (ignorable resx opnds)) > (ensure-cloning resx > (make-instance 'mx-number :value > (loop with op1 = (car opnds) with log = (max 1 (ceiling (log (abs > (value op1)) 10))) for n = > (* (signum (value op1)) (+ 2 (random (expt 10 log)))) when > (/= n (value op1)) return n) > :representation (representation resx))))) Even better. That "(car opnds)" up there is an unpleasant hard-coding that must align with how operands get recorded by the transformation code that built the TF log entry that is being reversed. Ewww. What the first opnds is supposed to be is the signed value of which the absolute vale is being taken. Wouldn't it be nice to just say "signed-value"?: We can just look at the reverse option now: (defskill absolute-value .... (reverse (signed-value) (ensure-cloning resx (make-instance 'mx-number :value (loop with svn = (value signed-value) with log = (max 1 (ceiling (log (abs svn) 10))) for n = (* (signum svn)(+ 2 (random (expt 10 log)))) when (/= n svn) return n) :representation (representation resx))))) A major point here is that the above (trust me) is the exact syntax of FLET and LABELS in Lisp. The big hobgoblin (and precise objection offered by GvR) is that macro use yields unrecognizably (in this case) Lisp code. But we love lisp and its patterns, and one ethic for macro writers is to follow those patterns in extending the language. Maybe that poor horse can be allowed to rest in peace, or must we flog it some more for youse people? Now operands and results get tagged at TF time with symbols. How on earth does a local variable of the same name get bound to the operand logged at TF time? Easy, look it up. But where is the code? Not outside the function; the caller of the reversal function does not know which logged operand to pass in which function parameter position. So the lookup code has to be in the reverse function source, like this: (defmethod tf-reverse ((id (eql 'absolute-value)) tf drv &aux (opnds (drv-opnds tf drv))) (declare (ignorable opnds)) (let ((signed-value (tf-drv-lookup tf drv 'signed-value))) <===== (loop for resx in (results drv) do (ensure-cloning resx (make-instance 'mx-number :value (loop with svn = (value signed-value) with log = (max 1 (ceiling (log (abs svn) 10))) for n = (* (signum svn) (+ 2 (random (expt 10 log)))) when (/= n svn) return n) :representation (representation resx)))))) WordPerfect says thats 405 characters, 64 words vs 241/38 for the actual source. Now in this case I happen to be just starting on this mechanism, so i do not really have 42 I do not have to change, but I am about to start churning these things out and I expect refinements to continue. No problem. ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From fredrik at pythonware.com Thu Dec 14 11:31:04 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 14 Dec 2006 17:31:04 +0100 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com><1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: Nick Maclaren wrote: > See my response to Georg Brandl (specifically the memo. to myself). "reductio ad absurdum" and "arbitrary handwaving" are two different things, though. From mhellwig at xs4all.nl Wed Dec 20 12:43:53 2006 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Wed, 20 Dec 2006 18:43:53 +0100 Subject: your opinion about psycopg vs pygresql Message-ID: <45897630$0$326$e4fe514c@news.xs4all.nl> Hi all, I'm playing a bit with PostgreSQL, in which I've set me the target to create a python script which with user input creates a new user role and a database with that owner (connecting to template1 since I know that at least that db exists). Ok so I installed PostGreSQL and pygresql since it looked like that this is endorsed by PG, I had some trouble with the DB-API2 (complains about there is already a connection to template1, even when I closed and deleted the connector) so I solved it by using the pg api. But I was intrigued by this problem and started googling and by that time I've noticed that python projects like Django seem to favor the psycopg module. So I installed that one (the 1.1 version, since Django uses that too) and it looked like it has the same problem of creating a user after a database, I'm sure that there is a user error in there somewhere :-) However, given the choice, what in your opinion would be the reason why someone would chose one over the other? Now I know this could easily get into a flamewar, so if you comment (but please do so) I'll still investigate that, since at this moment I don't even have a clue how they differ and on what reason, why does PostgreSQL seem to favour pygresql and Pythoneers psycopg? Thanks in advance. -- mph From mail at microcorp.co.za Tue Dec 19 00:30:29 2006 From: mail at microcorp.co.za (Hendrik van Rooyen) Date: Tue, 19 Dec 2006 07:30:29 +0200 Subject: Python-URL! - weekly Python news and links (Dec 18) References: <1166471994.876115.245430@j72g2000cwa.googlegroups.com> Message-ID: <012501c72330$d3b97ea0$03000080@hendrik> "Kay Schluehr" wrote: > Paul Boddie wrote: > > > Meanwhile, the EuroPython planners get ahead of themselves, thinking about > > conference venues as far in the future as 2010, if not 20010! > > Python 20010. It was a nice conference although a bit lame on the first > day. My favourite talks were: > > Trevor Stent: "Whitespace as a universal constant" > Mathais Fendro: "Snake gods and how they tamed chaons and simili" > Taumaturg 7: "Technologia inversa. A short history of holistic > semantics" > > There was also some interesting short talk about wormhole calculus. > Unfortunetely I've forgotten the name of the lecturer. Maybe I was just > too fascinated by his appeal as a small spinning bubble, shining in > rainbow colors. Lovely! - thanks for the update - I'm sorry I couldn't make it in time. - Hendrik From kw at codebykevin.com Wed Dec 13 13:15:25 2006 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 13 Dec 2006 13:15:25 -0500 Subject: how can i write a hello world in chinese with python In-Reply-To: <1165982024.978824.146920@n67g2000cwd.googlegroups.com> References: <1165982024.978824.146920@n67g2000cwd.googlegroups.com> Message-ID: <4580433D.9090206@codebykevin.com> kernel1983 wrote: > I'm try to build a bundle on OS X, so I write a simple python script > for a test: > > #!/usr/bin/env python > import EasyDialogs > EasyDialogs.Message("Hello,Mac!") > > > This runs OK,but when I try to replace "Hello,Mac!" with chinese, it > can't be display rightly. > Then I tried some way else: > > #!/usr/bin/env python > import EasyDialogs > EasyDialogs.Message("\xe4\xb8\xad") > > It doesn't work! > > As I know mac is unicode based,how can I display chinese on the screen? > EasyDialogs is an *ancient* module on OS X--it may not support unicode. Try posting to the MacPython list, someone there can verify this. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From ptmcg at austin.rr._bogus_.com Thu Dec 21 15:57:56 2006 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 21 Dec 2006 14:57:56 -0600 Subject: Decorator for Enforcing Argument Types References: <1166734180.455471.164910@79g2000cws.googlegroups.com> Message-ID: <458af55a$0$2251$4c368faf@roadrunner.com> "Chris" wrote in message news:1166734180.455471.164910 at 79g2000cws.googlegroups.com... > I'm not sure if this has been done before, but I couldn't easily find > any prior work on Google, so here I present a simple decorator for > documenting and verifying the type of function arguments. > Feedback/suggestions/criticism is welcome. > They Python wiki has a page for decorator ideas/submissions, compare yours to this one: http://wiki.python.org/moin/PythonDecoratorLibrary#head-308f2b3507ca91800def19d813348f78db34303e -- Paul From anthra.norell at vtxmail.ch Tue Dec 26 18:30:51 2006 From: anthra.norell at vtxmail.ch (Frederic Rentsch) Date: Wed, 27 Dec 2006 00:30:51 +0100 Subject: BeautifulSoup vs. loose & chars In-Reply-To: <1qdkh.9706$ZT3.6008@newssvr19.news.prodigy.com> References: <1167135758.005112.67350@73g2000cwn.googlegroups.com> <1qdkh.9706$ZT3.6008@newssvr19.news.prodigy.com> Message-ID: <4591B0AB.5040908@vtxmail.ch> John Nagle wrote: > Felipe Almeida Lessa wrote: > >> On 26 Dec 2006 04:22:38 -0800, placid wrote: >> >> >>> So do you want to remove "&" or replace them with "&" ? If you want >>> to replace it try the following; >>> >> I think he wants to replace them, but just the invalid ones. I.e., >> >> This & this & that >> >> would become >> >> This & this & that >> >> >> No, i don't know how to do this efficiently. =/... >> I think some kind of regex could do it. >> > > Yes, and the appropriate one is: > > krefindamp = re.compile(r'&(?!(\w|#)+;)') > ... > xmlsection = re.sub(krefindamp,'&',xmlsection) > > This will replace an '&' with '&' if the '&' isn't > immediately followed by some combination of letters, numbers, > and '#' ending with a ';' Admittedly this would let something > like '&xx#2;', which isn't a legal entity, through unmodified. > > There's still a potential problem with unknown entities in the output XML, but > at least they're recognized as entities. > > John Nagle > > > Here's another idea: >>> s = ''' htm tag should not translate > & should be & > &xx#2; isn't a legal entity and should translate > { is a legal entity and should not translate >>> import SE # http://cheeseshop.python.org/pypi/SE/2.3 >>> HTM_Escapes = SE.SE (definitions) # See definitions below the dotted line >>> print HTM_Escapes (s) htm tag should not translate > & should be & > &xx#2; isn"t a legal entity and should translate > { is a legal entity and should not translate Regards Frederic ------------------------------------------------------------------------------ definitions = ''' # Do # Don't do # " = "  == # 32 20 (34)=&dquot; &dquot;== # 34 22 &=& &== # 38 26 '=" "== # 39 27 <=< <== # 60 3c >=> >== # 62 3e ?=© ©== # 169 a9 ?=· ·== # 183 b7 ?=» »== # 187 bb ?=À À== # 192 c0 ?=Á Á== # 193 c1 ?=Â Â== # 194 c2 ?=Ã Ã== # 195 c3 ?=Ä Ä== # 196 c4 ?=Å Å== # 197 c5 ?=Æ Æ== # 198 c6 ?=Ç Ç== # 199 c7 ?=È È== # 200 c8 ?=É É== # 201 c9 ?=Ê Ê== # 202 ca ?=Ë Ë== # 203 cb ?=Ì Ì== # 204 cc ?=Í Í== # 205 cd ?=Î Î== # 206 ce ?=Ï Ï== # 207 cf ?=&Eth; &Eth;== # 208 d0 ?=Ñ Ñ== # 209 d1 ?=Ò Ò== # 210 d2 ?=Ó Ó== # 211 d3 ?=Ô Ô== # 212 d4 ?=Õ Õ== # 213 d5 ?=Ö Ö== # 214 d6 ?=Ø Ø== # 216 d8 ?=&Ugrve; &Ugrve;== # 217 d9 ?=Ú Ú== # 218 da ?=Û Û== # 219 db ?=Ü Ü== # 220 dc ?=Ý Ý== # 221 dd ?=&Thorn; &Thorn;== # 222 de ?=ß ß== # 223 df ?=à à== # 224 e0 ?=á á== # 225 e1 ?=â â== # 226 e2 ?=ã ã== # 227 e3 ?=ä ä== # 228 e4 ?=å å== # 229 e5 ?=æ æ== # 230 e6 ?=ç ç== # 231 e7 ?=è è== # 232 e8 ?=é é== # 233 e9 ?=ê ê== # 234 ea ?=ë ë== # 235 eb ?=ì ì== # 236 ec ?=í í== # 237 ed ?=î î== # 238 ee ?=ï ï== # 239 ef ?=ð ð== # 240 f0 ?=ñ ñ== # 241 f1 ?=ò ò== # 242 f2 ?=ó ó== # 243 f3 ?=&ocric; &ocric;== # 244 f4 ?=õ õ== # 245 f5 ?=ö ö== # 246 f6 ?=ø ø== # 248 f8 ?=ù ù== # 249 f9 ?=ú ú== # 250 fa ?=û û== # 251 fb ?=ü ü== # 252 fc ?=ý ý== # 253 fd ?=þ þ== # 254 fe (xff)=ÿ # 255 ff &#== # All numeric codes "~<(.|\n)*?>~==" # All HTM tags ''' If the ampersand is all you need to handle you can erase the others in the first column. You need to keep the second column though, except the last entry, because the tags don't need protection if '<' and '>' in the first column are gone. Definitions are easily edited and can be kept in text files. The SE constructor accepts a file name instead of a definitions string: >>> HTM_Escapes = SE.SE ('definition_file_name') ------------------------------------------------------------------- From g.brandl-nospam at gmx.net Fri Dec 15 07:47:45 2006 From: g.brandl-nospam at gmx.net (Georg Brandl) Date: Fri, 15 Dec 2006 12:47:45 +0000 Subject: Property error In-Reply-To: References: <1166136987.740999.53020@f1g2000cwa.googlegroups.com> <1166179622.872556.312810@n67g2000cwd.googlegroups.com> <1166181267.949316.197360@16g2000cwy.googlegroups.com> Message-ID: Peter Otten wrote: > @decorator > def f(): > # ... > > is the same as > > def f(): > # ... > f = decorator(f()) ^^ Nope, f is not called here. (Think of staticmethod). Georg From allison.william at gmail.com Thu Dec 14 15:07:32 2006 From: allison.william at gmail.com (William Allison) Date: Thu, 14 Dec 2006 15:07:32 -0500 Subject: SPE website down? In-Reply-To: References: Message-ID: Laszlo Nagy wrote: > The home page of SPE (Stani's editor) is not available. > > http://pythonide.stani.be/ > > Is there a mailing list for this editor? > Where should I ask questions about it? > Where can I report bugs and make suggestions? > > Thanks, > > Laszlo > I seem to remember he was looking for a new webhost a couple of weeks ago. Try http://sourceforge.net/projects/spe/ for now. From exarkun at divmod.com Wed Dec 27 09:28:17 2006 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Wed, 27 Dec 2006 09:28:17 -0500 Subject: loose methods : Smalltalk asPython In-Reply-To: Message-ID: <20061227142817.20948.1650293141.divmod.quotient.92622@ohm> On Wed, 27 Dec 2006 19:03:12 +1100, Steven D'Aprano wrote: > >You can't modify the built-in classes. I'm not sure that it is a good idea >to allow built-ins to be modified. When I see an int, I like the fact that >I know what the int can do, and I don't have to worry about whether it has >been modified by some piece of code elsewhere. I wonder how this is different from any other class. If you see a StringIO or a socket, don't you also expect to know what it can do? But in fact you _do_ have to worry about whether it has been modified, at least according to your argument. Do you often worry about it, though? And if not, has it ever come back to bite you? If so, perhaps more than just built-in classes should be restricted in this way? If not, why should built-ins have the restriction? Jean-Paul From bborcic at gmail.com Sat Dec 23 07:00:43 2006 From: bborcic at gmail.com (Boris Borcic) Date: Sat, 23 Dec 2006 13:00:43 +0100 Subject: Xah's Edu Corner: Introduction to 3D Graphics Programing In-Reply-To: <1166836083.084101.25870@73g2000cwn.googlegroups.com> References: <1166836083.084101.25870@73g2000cwn.googlegroups.com> Message-ID: <458d1a96$1_3@news.bluewin.ch> Xah Lee wrote: > Of Interest: to which of comp.lang.perl.misc, comp.lang.python, comp.lang.lisp, comp.lang.java.programmer, comp.lang.functional ? From pierre at saiph.com Sat Dec 30 17:32:07 2006 From: pierre at saiph.com (Imbaud Pierre) Date: Sat, 30 Dec 2006 23:32:07 +0100 Subject: xml bug? In-Reply-To: <4595B6DC.4030408@v.loewis.de> References: <4594130c$0$318$426a74cc@news.free.fr> <4595B6DC.4030408@v.loewis.de> Message-ID: <4596e8e8$0$316$426a74cc@news.free.fr> Martin v. L?wis a ?crit : > Imbaud Pierre schrieb: > >>- how do I spot the version of a given library? There is a __version__ >> attribute of the module, is that it? > > > Contrary to what others have said: for modules included in the standard > library (and if using these modules, rather than using PyXML), you > should use sys.version_info to identify a version. > > >>- How do I access to a given library buglist? Maybe this one is known, >> about to be fixed, it would then be useless to report it. > > > Others have already pointed you to SF. > > >>- How do I report bugs, on a standard lib? > > > Likewise. > > >>- I tried to copy the lib somewhere, put it BEFORE the official lib in >> "the path" (that is:sys.path), the stack shown by the traceback >> still shows the original files being used. Is there a special >> mechanism bypassing the sys.path search, for standard libs? (I may >> be wrong on this, it seems hard to believe...) > > > Which lib? "minidom.py"? Well, you are likely importing > "xml.dom.minidom", not "minidom". So adding another minidom.py > to a directory in sys.path won't help. > > Regards, > Martin I did import xml! Maybe my mistake came from copying the whole tree from the standard lib: comprising .pyc, .pyo... maybe the .pyc contained references to previous sources? Got rid of these, did reload ALL the modules, then exited/re-entered the interpreter (ipython, btw...), and it eventually accessed the new modules... Btw, I pushed debugging further, the bug seem to stem from C code, hence nothing easy to fix... Ill indeed submit a bug. Thanks for your help! I obviously screamed for help before being helpless, apologies... From kentilton at gmail.com Sat Dec 9 19:40:09 2006 From: kentilton at gmail.com (Ken Tilton) Date: Sat, 09 Dec 2006 19:40:09 -0500 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> Message-ID: Andr? Thieme wrote: > Ken Tilton schrieb: > >> The last time we went thru this a Pythonista finally said, Oh, I get >> it. These five lines of code I have to write all the time (two setup, >> one func call, two cleanup) can be collapsed into one or two. The >> thread will be hard to miss in Google groups (two years back?) and the >> epiphany appears right at the end of the thread. > > > Functional programming is the solution here, not Lisp. No, you do not understand. The Pythonista figured it out: a function would not do. > > You could make that with a new function (in Python), that takes a > function (and its args, don't remember the correct syntax). > > def foo(function, args): > setup(1) > setup(2) > function(args) > cleanup(1) > cleanup(2) > > > The nice thing in Lisp would now be to save a lambda with the macro. > In Python one would fill the name space with throw away functions that > get called only one time. Omigod. Is that what you meant? You think macros are unnecessary because one could hard-code their expansions as separate functions? And that would constitute hiding the boilerplate? What happens when the boilerplate changes? ken -- Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm "Well, I've wrestled with reality for thirty-five years, Doctor, and I'm happy to state I finally won out over it." -- Elwood P. Dowd "I'll say I'm losing my grip, and it feels terrific." -- Smiling husband to scowling wife, New Yorker cartoon From atkinw at rpi.edu Fri Dec 8 20:47:54 2006 From: atkinw at rpi.edu (Bill Atkins) Date: Fri, 08 Dec 2006 20:47:54 -0500 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <7xslfqar7v.fsf@ruckus.brouhaha.com> <1165623284.242403.295140@l12g2000cwl.googlegroups.com> <7xodqdj2dn.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Huh? Are you saying Lisp systems never release new versions? And you He's pretty clearly not saying that. From __peter__ at web.de Fri Dec 1 05:15:01 2006 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Dec 2006 11:15:01 +0100 Subject: Slicing versus loops, was Re: for i in range() anti-pattern References: <1164812827.653386.323320@80g2000cwy.googlegroups.com> Message-ID: Peter Otten wrote: > Here is another implementation that cuts maximum memory down from 100 to > 50%. > > from itertools import islice > def swap(items): > ????items[::2],?items[1::2]?=?islice(items,?1,?None,?2),?items[::2] > ????return?items Unfortunately, the following >>> a = [1, 2, 3] >>> a[::2] = iter([10, 20, 30]) Traceback (most recent call last): File "", line 1, in ? ValueError: attempt to assign sequence of size 3 to extended slice of size 2 >>> a [1, 2, 3] does not support my bold claim :-( Since the list is not changed there must be an intermediate copy. Peter From sigzero at gmail.com Wed Dec 6 08:55:44 2006 From: sigzero at gmail.com (Robert Hicks) Date: 6 Dec 2006 05:55:44 -0800 Subject: Book recommendations In-Reply-To: References: Message-ID: <1165413344.654740.247000@79g2000cws.googlegroups.com> On Dec 6, 7:09 am, "west" wrote: > Can someone recommend a Python book for a newbie and perhaps you have a used > one for sale? Thank you. > Beginning Python: From Novice to Professional by Magnus Lie Hetland Core Python Programming (2nd Edition) by Wesley Chun There are plenty of "Free" online ones as well. HTH Robert From fredrik at pythonware.com Fri Dec 15 12:49:32 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Dec 2006 18:49:32 +0100 Subject: Has comparison of instancemethods changed between python 2.5 and 2.4? In-Reply-To: References: <4582CFA3.5040305@niessink.com> Message-ID: Thomas Heller wrote: > It seems so: > > python -c "o = object(); print o.__str__ == o.__str__" > > prints True with Python 2.5, and False with Python 2.4. that's not an instance method, though: >>> o = object() >>> type(o.__str__) using a real instance method, I get the same result under both versions: >>> class foo(object): ... def bar(self): ... pass ... >>> f = foo() >>> type(f.bar) >>> f.bar == f.bar True From bblais at bryant.edu Fri Dec 15 06:11:00 2006 From: bblais at bryant.edu (Brian Blais) Date: Fri, 15 Dec 2006 06:11:00 -0500 Subject: automatically grading small programming assignments In-Reply-To: <1166158550.874904.109000@80g2000cwy.googlegroups.com> References: <1166129734.888298.210830@l12g2000cwl.googlegroups.com> <1166131842.963017.206130@79g2000cws.googlegroups.com> <1166158550.874904.109000@80g2000cwy.googlegroups.com> Message-ID: <458282C4.4030803@bryant.edu> Dan Bishop wrote: > On Dec 14, 8:36 pm, Brian Blais wrote: >> commander.co... at hotmail.com wrote: >>> bearophileH... at lycos.com wrote: >>> Then on your PC you can >>>> run a script that loads each of such programs, and runs a good series >>>> of tests, to test their quality... >>> What happens if someone-- perhaps not even someone in the class-- does >>> some version of os.system('rm -Rf /') ?I was thinking of including a dummy os.py and sys.py, so import os, and import sys >> would fail. Would this work? > > How would they access their command-line arguments without sys.argv? > the types of assignments that I am envisioning (finding the maximum in a list, parsing strings, etc.) will not need anything offered in os or sys. Certainly, if they were needed, another solution would need to be found. bb -- ----------------- bblais at bryant.edu http://web.bryant.edu/~bblais From felix.benner at imail.de Thu Dec 28 06:51:25 2006 From: felix.benner at imail.de (Felix Benner) Date: Thu, 28 Dec 2006 12:51:25 +0100 Subject: DOS, UNIX and tabs In-Reply-To: References: <1167243140.687557.93320@f1g2000cwa.googlegroups.com> Message-ID: Sebastian 'lunar' Wiesner schrieb: > Ben typed > >> I have a python script on a windows system that runs fine. Both use >> tabs to indent sections of the code. > > Just a tip for you: In python you never use tabs for indentation. The > python style guide [1] recommends four spaces per indentation level. > > [1] http://www.python.org/dev/peps/pep-0008/ > I like using tabs. And the style guide doesn't give a reason why one shouldn't and neither does the thread http://www.python.org/search/hypermail/python-1994q2/0198.html in the archive. So what's the point in typing four spaces for indentation instead of one tab? From pavlovevidence at gmail.com Fri Dec 1 09:27:06 2006 From: pavlovevidence at gmail.com (Carl Banks) Date: 1 Dec 2006 06:27:06 -0800 Subject: Is there a reason not to do this? References: Message-ID: <1164983226.620035.218790@l12g2000cwl.googlegroups.com> Ron Garret wrote: > In article , > Ron Garret wrote: > > I don't want to get into a philosophical debate. > > Actually, I changed my mind. Consider: > > def g(): print 'G' > > def h(): print 'H' > > def f(): g() > > class C1: > def m1(self): f() > > class C2: > def m1(self): g() > > c1 = C1() > c2 = C2() > > def f(): h() > > class C2: > def m1(self): h() > > c1.m1() # Prints H > c2.m1() # Prints G > > On what principled basis can you justify two different outputs in this > case? Why should I be able to change the definition of f and not have > to go back and recompile all references to it, but not m1? I see what you were asking now: you want to know why a class statement doesn't modify a previously existing class (as is the case in Ruby) rather than to create a new one. The principle behind this is pretty much "it was just a language design decision". The designers of Python felt it was generally best to have whole classes in one place, rather than spread out over many locations. I tend to agree with this. Changing classes in-place violates the "principle of least surprise"--keep in mind the "surprise" we're talking about is the reader's surprise, not the writer's. A person might be reading a class definition wondering, "WTF is happening, why doesn't it match the behavior?", not knowing that the class was modified in-place somewhere else. (That person could be you three months later.) Valid use cases like yours are exceptional, and can be done straightforwardly without changing class statement to modify in-place, so I think it was the right decision. Your opinion may differ. It doesn't seem to have wreaked havoc in Common Lisp and Ruby. But that's not how Python is. I have things I don't like about Python, too. You just deal with it. P.S. If you want to be truly evil, you could use a class hook to get the modifying in-place behavior: def modify_in_place(name,bases,clsdict): cls = globals()[name] for attr,val in clsdict.iteritems(): setattr(cls,attr,val) return cls # Replace second C2 class above with this class C2: __metaclass__ = modify_in_place def m1(self): h() Carl Banks From restccq2 at verizon.net Wed Dec 6 07:09:46 2006 From: restccq2 at verizon.net (west) Date: Wed, 06 Dec 2006 12:09:46 GMT Subject: Book recommendations Message-ID: Can someone recommend a Python book for a newbie and perhaps you have a used one for sale? Thank you. Cordially, west From address.good.until.2006.dec.22 at justmail.de Tue Dec 12 18:08:22 2006 From: address.good.until.2006.dec.22 at justmail.de (=?ISO-8859-1?Q?Andr=E9_Thieme?=) Date: Wed, 13 Dec 2006 00:08:22 +0100 Subject: merits of Lisp vs Python In-Reply-To: <457f1a42$0$8414$426a74cc@news.free.fr> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <45794fc2$0$11094$3b214f66@tunews.univie.ac.at> <457f1a42$0$8414$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers schrieb: > Mathias Panzenboeck a ?crit : >> Mark Tarver wrote: >> >>> How do you compare Python to Lisp? What specific advantages do you >>> think that one has over the other? >>> >>> Note I'm not a Python person and I have no axes to grind here. This is >>> just a question for my general education. >>> >>> Mark >>> >> >> >> I do not know much about Lisp. What I know is: >> Python is a imperative, object oriented dynamic language with duck >> typing, > > Python is a dynamic multi-paradigm language which is mostly OO but has > support for procedural and functional programming > >> List > > s/s/p/ > >> is a declarative, >> functional dynamic language -> those two languages have different scopes. > > Lisp is a multi-paradigm language which is mostly functional but has > support for procedural and OO programming. > > Both are highly dynamic. Neither are declarative. Well, Lisp does support some declarative features in the ansi standard. Think about :before or :after methods. And with some days of work (has already been done, so most Lispers could use it as a lib) you can get many parts of Prolog. See http://bc.tech.coop/blog/040919.html Andr? -- From bdesth.quelquechose at free.quelquepart.fr Wed Dec 20 06:46:03 2006 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 20 Dec 2006 12:46:03 +0100 Subject: def index(self): In-Reply-To: References: <4587017b$0$22957$426a34cc@news.free.fr> <458807cc$0$19743$426a74cc@news.free.fr> Message-ID: <45891cb7$0$16994$426a34cc@news.free.fr> Tim Roberts a ?crit : > Bruno Desthuilliers wrote: > >>Gert Cuykens a ?crit : >> >>>>FWIW, the first version raises an exception (unless of course the name >>>>'index' is already bound in the enclosing scope). And the second won't >>>>probably work as expected with CherryPy. >>> >>> >>>class HelloWorld: >>>def index(self): >>> return "Hello world!" >>>index.exposed = True #DOOOOOOH! >> >>And the winner is.... >> >> >>> >> >>The whole thing, I guess. While Python is quite easy to get started >>with, there are a few gotchas. You're above snippet should be: >> >>class HelloWorld(object): >> def index(self): >> return "Hello World" >> index.exposed = True > > > Many people find it more readable to write that as: > > class HelloWorld(object): > @cherrypy.exposed > def index(self): > return "Hello World" So do I. But this breaks compatibility with older Python versions, and is perhaps a bit confusing for someone that doesn't seem to really get some basic Python stuffs like what 'self' is... My 2 cents From detlev at die-offenbachs.de Sat Dec 23 07:30:13 2006 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sat, 23 Dec 2006 13:30:13 +0100 Subject: ANN: eric3 3.9.3 released Message-ID: Hi, this is to inform you about the availability of eric3 version 3.9.3. This release fixes a few bugs and enhances compatibility with subversion 1.4. It is available via http://sourceforge.net/project/showfiles.php?group_id=119070. What is eric3? -------------- eric3 is an IDE for Python and Ruby. It is written using Python, PyQt and QScintilla. eric3 includes debuggers for the a.m. languages, interfaces to subversion and cvs, integration of the Qt tools and many more. For details please see the eric home page at http://www.die-offenbachs.de/detlev/eric.html. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From fredrik at pythonware.com Tue Dec 19 04:09:41 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Dec 2006 10:09:41 +0100 Subject: Script to upload Files via http/cgi In-Reply-To: References: Message-ID: Richard Konrad wrote: > Does anyone know about a python-script to upload Files via http/cgi? do you want the script to do the actual upload at the client side (i.e. behave like a browser) or to handle the uploaded data on the server side? for the latter, see this: http://docs.python.org/lib/cgi-intro.html From justin.mailinglists at gmail.com Mon Dec 4 21:05:12 2006 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: 4 Dec 2006 18:05:12 -0800 Subject: Multiple FTP download using Muliti thread References: <1164933691.138083.128210@l12g2000cwl.googlegroups.com> <1165226193.934418.36660@l12g2000cwl.googlegroups.com> <1165277324.677203.107650@l12g2000cwl.googlegroups.com> Message-ID: <1165284311.911998.151460@l12g2000cwl.googlegroups.com> johnny wrote: > When I run the following script, with host and password and username > changed, I get the following errors: > raise error_temp, resp > error_temp: 421 Unable to set up secure anonymous FTP > > Dose the host should allow 4 simultaneous login at a time? > does it work using ftp.microsoft.com? post your code From sjdevnull at yahoo.com Fri Dec 1 16:23:44 2006 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 1 Dec 2006 13:23:44 -0800 Subject: python vs java & eclipse In-Reply-To: References: <1164965087.525503.104930@j72g2000cwa.googlegroups.com> <45701422.4050206@gmx.net> Message-ID: <1165008224.116326.36580@79g2000cws.googlegroups.com> hg wrote: > Thomas Ploch wrote: > > Yes, thats true, but since eclipse is resource monster (it is still > > using java), and some people (like me) don't have a super fresh and new > > computer > > If you compare eclipse to VS, it is not that memory hungry And if you compare Saturn to Jupiter, it's not that big. > Yet (I believe that) a complete > IDE can bring functions that an editor, however powerful, cannot Is there anything _useful_ that it'll bring that a good editor doesn't? e.g. in vim I do get * automatic syntax checking (if I type "if a=1:" and hit enter, it'll immediately highlight the syntax error) * omni-completion (because Intellisense is trademarked) * refactoring (with BicycleRepairMan integration) * folding (which is more important than the above 3 combined, IMO) * online help (typing cmp( gives me the docstring for cmp in the status line, F1 to view the whole thing) As well as all the basics (tags/class browser/good regex support/syntax highlighting/autoindent/source control integration/etc). I'm not trolling here, I'm looking for interesting new features I can steal. From ejatsomewhere.com Wed Dec 27 14:35:10 2006 From: ejatsomewhere.com (Erik Johnson) Date: Wed, 27 Dec 2006 12:35:10 -0700 Subject: Iterating over several lists at once References: <1166017627.699257.166740@16g2000cwy.googlegroups.com> <1167220526.849221.252410@f1g2000cwa.googlegroups.com> Message-ID: <4592cb15$1@nntp.zianet.com> "Gal Diskin" wrote in message news:1167220526.849221.252410 at f1g2000cwa.googlegroups.com... > > > On Dec 13, 3:47 pm, "Gal Diskin" wrote: > > Hi, > > I am writing a code that needs to iterate over 3 lists at the same > > time, i.e something like this: > > > > for x1 in l1: > > for x2 in l2: > > for x3 in l3: > > print "do something with", x1, x2, x3 > > > > What I need to do is go over all n-tuples where the first argument is > > from the first list, the second from the second list, and so on... I don't see your previous article. Not sure if you are still looking for a solution, but here's one: >>> [(x, y, z) for x in [1,2,3] for y in list('abc') for z in list('XY')] [(1, 'a', 'X'), (1, 'a', 'Y'), (1, 'b', 'X'), (1, 'b', 'Y'), (1, 'c', 'X'), (1, 'c', 'Y'), (2, 'a', 'X'), (2, 'a', 'Y'), (2, 'b', 'X'), (2, 'b', 'Y'), (2, 'c', 'X'), (2, 'c', 'Y'), (3, 'a', 'X'), (3, 'a', 'Y'), (3, 'b', 'X'), (3, 'b', 'Y'), (3, 'c', 'X'), (3, 'c', 'Y')] This is a bit more compact, but I don't see anything wrong with what you have. From Roberto.Bonvallet at cern.ch Wed Dec 13 10:09:18 2006 From: Roberto.Bonvallet at cern.ch (Roberto Bonvallet) Date: Wed, 13 Dec 2006 15:09:18 +0000 (UTC) Subject: Conditional iteration References: <4580149c$0$321$e4fe514c@news.xs4all.nl> Message-ID: at wrote: > More pythonic in view would be: > > for x in [-2, -1, 0, 1, 2, 3, 4] if x > 0: > ... more code ... Pythonic? Do you realize that Python hasn't even adopted well-known statements like 'switch' and 'do while' because they would be redundant? This could be more convenient to you, but certainly not pythonic. Cheers, -- Roberto Bonvallet From salvatore.difazio at gmail.com Fri Dec 1 15:09:29 2006 From: salvatore.difazio at gmail.com (Salvatore Di Fazio) Date: 1 Dec 2006 12:09:29 -0800 Subject: Thread help In-Reply-To: <12n11hf9su7idca@corp.supernews.com> References: <1164999221.679348.221000@16g2000cwy.googlegroups.com> <12n0v9l4ssfd7fc@corp.supernews.com> <1165001388.156041.79030@f1g2000cwa.googlegroups.com> <12n11hf9su7idca@corp.supernews.com> Message-ID: <1165003769.395288.73630@j44g2000cwa.googlegroups.com> Grant Edwards ha scritto: > http://docs.python.org/lib/module-threading.html > http://linuxgazette.net/107/pai.html > http://www.wellho.net/solutions/python-python-threads-a-first-example.html > http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf Thank Edward, I didn't find the linuxgazette tutorial. Tnx From rdiaz02 at gmail.com Wed Dec 6 17:11:42 2006 From: rdiaz02 at gmail.com (Ramon Diaz-Uriarte) Date: Wed, 6 Dec 2006 23:11:42 +0100 Subject: About the 79 character line recommendation In-Reply-To: <1165354102.742108.99490@80g2000cwy.googlegroups.com> References: <1165348808.807516.201860@j72g2000cwa.googlegroups.com> <1165354102.742108.99490@80g2000cwy.googlegroups.com> Message-ID: <624934630612061411o27aed60bq1486192826909eab@mail.gmail.com> On 5 Dec 2006 13:28:22 -0800, Steve Bergman wrote: (...) > > I'm finding 100 to be a nice balance. It forces me not to be lazy and > allow really long lines, but allows me to format so as to make the > meaning most clear. > But if you use some advanced editors (such as Emacs) that easily allow you to see/edit the same file in two buffers side by side, then going beyond 80 chars is often a bad idea, specially if you use a laptop. (And, of course, there is the eternal issue of doing a simple "a2ps" to print some code; longer than 80 and you often have hard to read pages). Best, R. -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From http Fri Dec 15 21:40:29 2006 From: http (Paul Rubin) Date: 15 Dec 2006 18:40:29 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x8xhf4w0d.fsf@ruckus.brouhaha.com> <4ubu3nF16kv7aU1@mid.individual.net> <7x3b7j2gsr.fsf@ruckus.brouhaha.com> <7x4przt22g.fsf@ruckus.brouhaha.com> <4uch8cF17smt9U1@mid.individual.net> <4ufemoF17of60U3@mid.individual.net> <7x7iwtjk3a.fsf@ruckus.brouhaha.com> <7xodq5tboy.fsf@ruckus.brouhaha.com> <7xbqm4d97d.fsf@ruckus.brouhaha.com> Message-ID: <7xodq4mule.fsf@ruckus.brouhaha.com> Andr? Thieme writes: > >> How complicated ss it to say "cmp(a, b)" compared to "a cmp b"? > > It gets worse when the expressions are nested. > > So instead of > cmp(foo(a, b, c), bar(x, y, z)) you would prefer > foo(a, b, c) cmp bar(x, y, z) ? Don't be silly. Some operators are more natural as infix and others as functions. It's just like in natural language. People have an innate ability to make such distinctions and it's fine for a programming language to use it. From duncan.booth at invalid.invalid Wed Dec 27 12:31:35 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Dec 2006 17:31:35 GMT Subject: getting a process's PID References: <20061227102939.L20663@eris.io.com> <4592abf1$1@nntp.zianet.com> Message-ID: "Erik Johnson" wrote: > There's more than one way to do it! (Oh, sorry, that's Perl...) > > The two most standard ways would be to call strip() on your string to > get one sans both leading and trialing whitespace > > print h.strip() > > or if you know exactly what you've got (i.e., the newline you don't > want is just the last character), you can just get rid of it: > > h = h[:-1] Or if you don't know for sure it's there, but don't want to lose other whitespace: print h.rstrip('\n') From gilham at snapdragon.csl.sri.com Mon Dec 11 11:38:54 2006 From: gilham at snapdragon.csl.sri.com (Fred Gilham) Date: Mon, 11 Dec 2006 08:38:54 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <%TBeh.331$tv5.155@newsfe11.lga> <7xfybnjkz4.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Andr? Thieme writes: >> Instead of function = memoize(function) >> one could just say: memoize(function). > > In Python you'd say > > @memoize > def function(): ... But in Lisp you'd write the function, say, "Damn, I need to memoize this sucker," and evaluate (memoize 'function) and the function would be memoized. I suspect you could even do this "while the program was running" from something like SLIME. Basically the memoize macro changes the function cell of the symbol, so from that point all the calls to the function would be to the memoized version. -- Fred Gilham gilham at csl.sri.com One of the authors of the Daniel Bell volume says, in horror and astonishment, that the radical right intends to repeal the twentieth century. Heaven forfend! Who would want to repeal the twentieth century, the century of horror, the century of collectivism, the century of mass destruction and genocide, who would want to repeal that! -- Murray Rothbard From steve at REMOVE.THIS.cybersource.com.au Sun Dec 10 08:28:43 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Mon, 11 Dec 2006 00:28:43 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165594621.136524.198600@80g2000cwy.googlegroups.com> <1165596641.245385.113090@f1g2000cwa.googlegroups.com> <1165704007.887869.192290@16g2000cwy.googlegroups.com> Message-ID: On Sun, 10 Dec 2006 06:40:46 +0000, Kirk Sluder wrote: >> > To start with, English does not restrict the expressiveness and >> > power of the syntax and grammar. >> >> Really? There are no restrictions whatsoever in English syntax and >> grammar? None at all? > > Of course I didn't say that: What I said was, "To start with, > English does not restrict the expressiveness and > power of the syntax and grammar. People who use the English language > in specific communities and in specific forms of discourse do. Hang on... are you saying that *people* create languages? *slaps head* And here I was thinking that languages fell from the sky like donuts! Gosh, thank you for explaining that too me. What a fool I must seem! By the way, that was sarcasm. Of course the English language doesn't exist in a vacuum. Of course people -- not rocks, not trees, not the Greek Furies, and especially not the Academie Francaise -- create languages. And, as an Australian in a world dominated by Americans, I know damn well that different communities of English speakers use different rules. *Slightly* different rules. That's why Standard American English and British English are both English, not different languages like Italian and German or Korean and Russian. [snip] > As an example of the context-specific nature of pragmatics at work, > if I was your reviewer or editor, I'd reject this manuscript. Perhaps you should find out what "manuscript" means before talking about rejecting one, because what I wrote was most certainly not a manuscript in any English language I'm aware of. > As a > participant on usenet, I'll just point out that you selectively > quoted the antithesis, and deleted my thesis to argue a straw-man. Look, I was arguing a really simple point: for communication to occur between two individuals, both people must agree on a set of rules for the language that they use to communicate. If they don't have a common language with agreed upon rules, communication will be feeble and weak, if not non-existent, or there will be misunderstandings and errors. Is that so hard to grasp? If you ask for "fire water", by which you mean whiskey, but I understand to be petrol (gasoline), you're going to be a very sick person indeed if you drink what I give you. > Of course there are restrictions, *enforced by users of language in > specific communities.* But the English language is quite malleable, > and includes not only the discourse we are currently engaged in, but > the clipped jargon of internet chat and amateur radio, the > chronically passive discourse of academia, the passionate chants of > protesters, and a wide variety of poetic expression. Did I say it wasn't malleable? You are attacking me for things I never said. > This is where wannabe critics of "English grammar" fail to > understand the language they claim to defend, much to the amusement > of those of us who actually do study language as it is, rather than > the mythical eternal logos we want it to be. Ho ho ho, have you ever jumped to a foolish conclusion. You think I'm one of those tiresome bores who think that just because the ancient Romans couldn't end a sentence with a preposition, English shouldn't either? Puh-lease! > Languages are (with some trivial exceptions) human creations. The > laws, rules and restrictions of languages are dynamic and dependent > on community, mode, medium and context. Of course, wannabe > grammarians frequently rise up at this point and say that if such is > the case, then there is nothing to prevent from > devolving into a babble of incomprehensible dialects. To which the > easy response is that the benefits of conformity to linguistic > communities almost always outweigh the costs of nonconformist > expression. Yes yes, you're really passionate about language, you have little respect for grammarians, blah blah blah. None of that has the slightest relevance to what I was talking about. I'm not denying that languages evolve and mutate. I'm talking about the simple fact -- and it is a fact -- that two people must share at least some common linguistic concepts in order to communicate, and the fewer common constructs they share, the worse the communication. Languages accomplish that through rules. Yes, the rules are mere conventions, and can change. They're still rules. Some languages have very strict rules, some have very flexible rules, but they all have rules and they all restrict how you use the language. English has a rule that you turn "programmer" into a plural by adding "s" to the end. If you decide to drop the -er and add -ing instead, as in "I hired a team of six programming this week", at best people will do a double-take and be forced to work out what you mean from context. If you decide to make the plural of programmer by deleting the first and last three characters, nobody will have any idea what drugs you are smoking. [snip] >> So, when I say "sits cat rat" it is not only legal English, but you can >> tell which animal is sitting on which? > > What is "legal" in English depends on the communities in which you > are currently participating. Likely there is some community in which > such clipped discourse is understood and therefore legal. Oh yes, the mythical "some community". Nope, sorry, I don't buy it. That's not legal in any English dialect I've come across, and I've dealt with -- and still do -- English speakers from all over the world. No English language or dialect typically puts the verb in front of both the object and subject for present tense expressions. It isn't just *clipped*, the word order is completely different from English. Didn't you notice that? But in fact even if there is some obscure dialect of English that would allow that, that doesn't change my point that there are some constructs which aren't legal in English (as it exists today). If not "sit cat rat", something else. No doubt you can come up with some particular idiomatic phrase in English that puts the verb first, or a different grammatical construct like the imperative tense, e.g. "Sit on the rat, cat!". Poetry, in particular, sometimes uses the verb-subject-object order. But these exceptions merely emphasis that English, unlike Gaelic, doesn't normally write verb-subject-object. A language that was so radically different from all the other English dialects as to allow "sits cat rat" as a typical construct wouldn't be English. It might be a pidgin or a creole language. But it won't be English, not now. In the indefinite future, who knows? I'm not saying that languages are carved in stone, never to change -- that would be stupid. But at any one time, languages have rules, even if those rules change over time, and if two people disagree on those rules, communication is hurt, up to the point of stopping communication completely. > If you are > talking to me, I'd express my lack of comprehension by saying > "Pardon?" and ask you to rephrase. And how unfortunate for you that in my local community, "pardon" is the worst insult imaginable and I punch you in the face. (See, you aren't the only one that can just invent local communities with implausible variations of English.) >> But I'm belaboring the point. Of course English has restrictions in >> grammar and syntax -- otherwise one could write something in Latin or >> Thai or Mongolian and call it English. There are RULES of grammar and >> syntax in English, which means that there are possible expressions which >> break those rules -- hence there are expressions which one can't write in >> legal English. > > When you make an "illegal" statement in English, exactly who or what > corrects you? > > Is it Zeus, the divine Logos, the flying spaghetti monster, some > platonic ideal? No. Your peers or your parents or your editor or your teachers correct you. Or you get a reputation for being "stupid" and people start treating you as if you were stupid -- maybe they start talk-ing ver-y slow-ly at you, using baby words. Or people just find it difficult to communicate with you, or misunderstand what you are trying to say. There is no law of physics that says that people can't say "Head on my hat I put". But English speakers just don't do it, and when somebody does, they are treated as if they aren't speaking English. But notice that semantics is important -- if I were to say "Head on my pillow I lay", chances are good that I'd be treated as speaking poetically, rather than as a non-English speaker. We commonly lay our head on our pillow, but put our hat on our head. > As you can probably tell, this kind of silliness is a bit of a sore > spot for me. So please by all means, do some basic reading of > linguistics before you continue to engage in such silliness. Or at > least learn to properly quote an argument. Before patronizing me, do make the effort to understand what I am saying. Just because you've got valid concerns about ignorant grammarians doesn't excuse your carelessness. Instead of reading what I actually wrote, you read into it what you wanted to see: another stupid wanna-be grammarian who thinks that languages are frozen, static, dead things. You couldn't be more wrong, and your repeated assumption -- and that's all it was, just an assumption -- that I know nothing about linguistics is shameful. Are you man enough to acknowledge your error, or are you going to continue this ridiculous charade of attacking me for holding views I don't have? -- Steven. From tomas at fancy.org Sat Dec 16 15:26:47 2006 From: tomas at fancy.org (Tom Plunket) Date: Sat, 16 Dec 2006 12:26:47 -0800 Subject: textwrap.dedent replaces tabs? Message-ID: The documentation for dedent says, "Remove any whitespace than can be uniformly removed from the left of every line in `text`", yet I'm finding that it's also modifying the '\t' characters, which is highly undesirable in my application. Is there any way to stop it from doing this, or alternatively, to put those tabs back in? I see that TextWrap and its member functions take an 'expand_tabs' kwarg, but dedent unfortunately does not. ...I suppose such a function (replacement dedent) isn't terribly tough to write, but it seems an odd default especially considering there's no way to turn off the undesired changes, but were the changes /not/ made, the same text could just be passed through TextWrapper and have them removed... thx, -tom! -- From ebgssth at gmail.com Fri Dec 29 10:00:35 2006 From: ebgssth at gmail.com (js ) Date: Sat, 30 Dec 2006 00:00:35 +0900 Subject: Can I beat perl at grep-like processing speed? Message-ID: Just my curiosity. Can python beats perl at speed of grep-like processing? $ wget http://www.gutenberg.org/files/7999/7999-h.zip $ unzip 7999-h.zip $ cd 7999-h $ cat *.htm > bigfile $ du -h bigfile du -h bigfile 8.2M bigfile ---------- grep.pl ---------- #!/usr/local/bin/perl open(F, 'bigfile') or die; while() { s/[\n\r]+$//; print "$_\n" if m/destroy/oi; } ---------- END ---------- ---------- grep.py ---------- #!/usr/bin/env python import re r = re.compile(r'destroy', re.IGNORECASE) for s in file('bigfile'): if r.search(s): print s.rstrip("\r\n") ---------- END ---------- $ time perl grep.pl > pl.out; time python grep.py > py.out real 0m0.168s user 0m0.149s sys 0m0.015s real 0m0.450s user 0m0.374s sys 0m0.068s # I used python2.5 and perl 5.8.6 From Sebastien.Boisgerault at gmail.com Wed Dec 13 10:05:40 2006 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 13 Dec 2006 07:05:40 -0800 Subject: Validate XML against a set of XSD files, with Python In-Reply-To: References: <1165962804.855630.222240@79g2000cws.googlegroups.com> Message-ID: <1166022340.577761.105650@n67g2000cwd.googlegroups.com> On Dec 13, 2:28 pm, Laszlo Nagy wrote: > > Fast google query, uncheked, leads to: > > > - XSV:http://www.ltg.ed.ac.uk/~ht/xsv-status.htmlI tried this before. Unfortunately, xsv is not officially supported on > my system (FreeBSD 6.1) :-(> - libxml :http://codespeak.net/lxml/Probably this is what I need to use. (However, I see in the mailing > lists that there are problems with this part of libxml2.) Yep, maybe. I suspect some issues with the validation of Relax NG documents, at least with the libxml2 that was used in my lxml build ... > Thank you, > > Laszlo From fredrik at pythonware.com Sun Dec 3 11:02:34 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 03 Dec 2006 17:02:34 +0100 Subject: Deleting from a list while iterating In-Reply-To: References: <1165160235.282030.96610@79g2000cws.googlegroups.com> Message-ID: Fredrik Lundh wrote: > on my machine, that's about two orders of magnitude faster than your > "fast" approach for n=100000. oops. forget that; it's three times faster, if you're actually creating the entire list, and not just a generator that will create it on demand ;-) From Roka100 at gmail.com Mon Dec 18 21:45:07 2006 From: Roka100 at gmail.com (Jia Lu) Date: 18 Dec 2006 18:45:07 -0800 Subject: Is there any python-twisted tutorial or texts? Message-ID: <1166496307.681933.247810@t46g2000cwa.googlegroups.com> Hi all I want to study twisted of python . But I donot know how to start. Any suggistions? Thank you From niels.ellegaard at gmail.com Mon Dec 4 02:15:38 2006 From: niels.ellegaard at gmail.com (Niels L Ellegaard) Date: 3 Dec 2006 23:15:38 -0800 Subject: About alternatives to Matlab In-Reply-To: <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> References: <1161613941.550194.204870@e3g2000cwe.googlegroups.com> <1163711343.870829.110030@h48g2000cwc.googlegroups.com> <45712f73$0$8755$ed2619ec@ptn-nntp-reader02.plus.net> <1165080056.083648.207580@16g2000cwy.googlegroups.com> <45725a88$0$8749$ed2619ec@ptn-nntp-reader02.plus.net> <1165161532.686060.78860@73g2000cwn.googlegroups.com> <45730391$0$8752$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1165216537.852779.143160@l12g2000cwl.googlegroups.com> Jon Harrop wrote: > So I'm keen to learn what Python programmers would want/expect from F# and > OCaml. I think this discussion becoming is a little misguided. The real strength of scipy is the elegant notation rather than speed. Being raised with Matlab I find scipy nicely familiar, and its fast enough for many tasks. Some would argue that the strength of scipy is the weakness of ocaml. Others would disagree. That is a question of taste. My only grudge about strongly recommending scipy to friends is the way that two arrays can share the same data. This can lead to subtle errors that I will eventually be blamed for. I don't know if arrays in Matlab (or Octave) can share data, but if they do, then everything happens behind the scenes and the user does not have to worry. I would love to see a future version of numpy that was 50% slower and had a more foolproof approach to array copying. http://www.scipy.org/Tentative_NumPy_Tutorial#head-1529ae93dd5d431ffe3a1001a4ab1a394e70a5f2 Niels From rakesh.thakrar at microcom-recruitment.com Tue Dec 5 05:53:09 2006 From: rakesh.thakrar at microcom-recruitment.com (Rakesh Thakrar) Date: Tue, 5 Dec 2006 10:53:09 -0000 Subject: Python Contractor Required Message-ID: I am looking for a Python Developer for a 1 year long contract. The role will be based in the South West - UK. I will consider candidates with either personal or commercial experience of Python. Please do not hesitate to contact if you require any further information. ___________________ Rakesh Thakrar Manager Microcom Recruitment Division 2 Adelaide Street St. Albans Herts, AL3 5BH Tel: 01727 752000 Mob: 079 7094 3227 Fax: 01727 752018 www.microcom-recruitment.com Permanent and Contract IT Recruitment Specialists ____________________________________ ************************************************************ The views expressed in this e-mail are not necessarily the views of European Recruitment Network Ltd, its directors, officers or employees make no representation or accept any liability for its accuracy or completeness unless expressly stated to the contrary. This e-mail, and any attachments are strictly confidential and intended for the addressee(s) only. The content may also contain legal, professional or other privileged information. Unless expressly stated to the contrary, no contracts may be concluded on behalf of European Recruitment Network Ltd by means of e-mail communication. You may report the matter by calling us on +44 (0) 1727 752000. Please ensure you have adequate virus protection before you open or detach any documents from this transmission. European Network Recruitment Ltd does not accept any liability for viruses. European Recruitment Network Ltd is registered in England: Company number: 5651508. Registered Office: Greener House, 66-68 Haymarket, London, SW1Y 4RF ************************************************************ -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Sun Dec 10 10:21:22 2006 From: http (Paul Rubin) Date: 10 Dec 2006 07:21:22 -0800 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <874ps423sx.fsf@thalassa.informatimago.com> Message-ID: <7x8xhf4w0d.fsf@ruckus.brouhaha.com> Ken Tilton writes: > Have you read On Lisp by Paul Graham? It is on-line. Just the preface > will do, I think, maybe also Chapter One where he raves on macros. Do > you think he is mistaken? Confused? Lying? Mutant? I remember Paul Graham's piece about macros that made him sound like someone who went nuts with them, as is certainly possible to do. In my experience, good coders write for clarity and that includes in their use of Lisp macros. All in all Lisp's macro system is something like the C preprocessor. Yes, you can obfuscate things horribly with it, but you can also use it to make things clearer, and that's what good programmers do. From Benjamin.Barker at gmail.com Fri Dec 29 07:08:18 2006 From: Benjamin.Barker at gmail.com (Ben) Date: 29 Dec 2006 04:08:18 -0800 Subject: INSERT statements not INSERTING when using mysql from python In-Reply-To: <1167393801.950199.197830@48g2000cwx.googlegroups.com> References: <1167390572.524495.318660@i12g2000cwa.googlegroups.com> <507lh.334$c46.83@newsfe05.lga> <1167392680.358395.317220@h40g2000cwb.googlegroups.com> <1167393196.618932.104550@a3g2000cwd.googlegroups.com> <1167393801.950199.197830@48g2000cwx.googlegroups.com> Message-ID: <1167394098.642975.78350@73g2000cwn.googlegroups.com> Nope... that can't be it. I tried running those commands manually and nothing went wrong. But then again when I execute the problematic command manually nothing goes wrong. Its just not executing until the last time, or being overwritten. Ben wrote: > Each time my script is run, the following is called: > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > self.cursor.execute("USE "+name) > self.cursor.execute("CREATE TABLE IF NOT EXISTS table_name ( .... > > The idea being that stuf is only created the first time the script is > run, and after that the original tables and database is used. This > might explain my pronblem if for some reason the old tables are being > replaced... can anyone see anything wrong with the above? > > Ben > > > > > > > Ben wrote: > > One partial explanation might be that for some reason it is recreating > > the table each time the code runs. My code says "CREATE TABLE IF NOT > > EXISTS" but if for some reason it is creating it anyway and dropping > > the one before that could explain why there are missing entires. > > > > It wouldn't explain why the NOT EXISTS line is being ignored though... > > > > Ben > > > > > > Ben wrote: > > > I initially had it set up so that when I connected to the database I > > > started a transaction, then when I disconnected I commited. > > > > > > I then tried turning autocommit on, but that didn't seem to make any > > > difference (althouh initially I thought it had) > > > > > > I'll go back and see what I can find... > > > Cheers, > > > Ben > > > > > > > > > johnf wrote: > > > > Ben wrote: > > > > > > > > > I don't know whether anyone can help, but I have an odd problem. I have > > > > > a PSP (Spyce) script that makes many calls to populate a database. They > > > > > all work without any problem except for one statement. > > > > > > > > > > I first connect to the database... > > > > > > > > > > self.con = MySQLdb.connect(user=username, passwd =password) > > > > > self.cursor = self.con.cursor() > > > > > self.cursor.execute("SET max_error_count=0") > > > > > > > > > > All the neccesary tables are created... > > > > > > > > > > self.cursor.execute("CREATE DATABASE IF NOT EXISTS "+name) > > > > > self.cursor.execute("USE "+name) > > > > > > > > > > self.cursor.execute("CREATE TABLE IF NOT EXISTS networks (SM > > > > > varchar(20),DMC int,DM varchar(50),NOS int,OS varchar(50),NID > > > > > varchar(20)) > > > > > > > > > > Then I execute many insert statements in various different loops on > > > > > various tables, all of which are fine, and result in multiple table > > > > > entries. The following one is executed many times also. and seems > > > > > identical to the rest. The print statements output to the browser > > > > > window, and appear repeatedly, so the query must be being called > > > > > repeatedly also: > > > > > > > > > > print "

SQL query executing

" > > > > > self.cursor.execute("INSERT INTO networks VALUES ('a',' "+i+" > > > > > ','c','2','e','f','g')") > > > > > print "

SQL query executed

" > > > > > > > > > > I have, for debugging, set "i" up as a counter variable. > > > > > > > > > > No errors are given, but the only entry to appear in the final database > > > > > is that from the final execution of the INSERT statement (the last > > > > > value of i) > > > > > > > > > > I suspect that this is to vague for anyone to be able to help, but if > > > > > anyone has any ideas I'd be really grateful :-) > > > > > > > > > > It occured to me that if I could access the mysql query log that might > > > > > help, but I was unsure how to enable logging for MysQL with python. > > > > > > > > > > Cheers, > > > > > > > > > > Ben > > > > > > > > Not sure this will help but where is the "commit"? I don't use MySQL but > > > > most SQL engines require a commit. > > > > Johnf From paddy3118 at netscape.net Thu Dec 7 12:53:20 2006 From: paddy3118 at netscape.net (Paddy) Date: 7 Dec 2006 09:53:20 -0800 Subject: funcs without () like print In-Reply-To: <1165502180.715192.195240@j72g2000cwa.googlegroups.com> References: <1165502180.715192.195240@j72g2000cwa.googlegroups.com> Message-ID: <1165514000.548199.32120@80g2000cwy.googlegroups.com> iwl wrote: > Hello can I make funktions callable without () like print > at time the interpreter seems to printout the adres when I type the > function without () Hi iwl, its one of the python fundamentals when dealing with functions. function_name without the () refers to the function object, that can be passed around like any other object. function_name() with the () calls the object referred to by the function name, attempting to execute the code within it. So no. you can't call functions without the (), but python provides an easy way to know when you are calling a function or not: just look for the (). - Paddy. From emin.shopper at gmail.com Fri Dec 22 18:02:38 2006 From: emin.shopper at gmail.com (emin.shopper at gmail.com) Date: 22 Dec 2006 15:02:38 -0800 Subject: module to implement Abstract Base Class Message-ID: <1166828558.301068.277390@79g2000cws.googlegroups.com> I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or running the actual program take a while. Comments and suggestions are welcome. Thanks, -Emin ############### Abstract Base Class Module Follows######################## """ This module provides the AbstractBaseClass class and the Abstract decorator to allow you to define abstract base classes in python. See the documentation for AbstractBaseClass for instructions. """ class _AbstractMetaClass(type): """ This is a metaclass designed to act as an AbstractBaseClass. You should rarely need to use this directly. Inheret from the class (not metaclass) AbstractBaseClass instead. Feel free to skip reading this metaclass and go on to the documentation for AbstractBaseClass. """ def __init__(cls, name, bases, dict): """Initialize the class if Abstract requirements are met. If the class is supposed to be abstract or it is concrete and implements all @Abstract methods, then instantiate it. Otherwise, an AssertionError is raised. Alternatively, if cls.__allow_abstract__ is True, then the class is instantiated and no checks are done. """ if (__debug__ and not getattr(cls,'__allow_abstract__',False) and not _AbstractMetaClass._IsSupposedToBeAbstract(cls)): abstractMethods = _AbstractMetaClass._GetAbstractMethods( cls.__bases__) for name in abstractMethods: if ( getattr(getattr(cls,name),'__abstract__',False)): klasses = _AbstractMetaClass._GetParentsRequiring(name,cls) if (len(klasses)==0): klasses = '(Unknown); all parents are %s.' % ( cls.__bases__) else: klasses = str(klasses) raise AssertionError( 'Class %s must override %s to implement:\n%s.' % (cls,name,klasses)) super(_AbstractMetaClass,cls).__init__(name,bases,dict) def __call__(self, *args, **kw): """Only allow instantiation if Abstract requirements are met. If there are methods that are still abstract and __allow_abstract__ is not set to True, raise an assertion error. Otherwise, instantiate the class. """ if (__debug__): stillAbstract = [ name for name in _AbstractMetaClass._GetAbstractMethods([self]) if (getattr(getattr(self,name),'__abstract__',False))] assert (getattr(self,'__allow_abstract__',False) or len(stillAbstract) == 0), ( """Cannot instantiate abstract base class %s because the follwoing methods are still abstract:\n%s""" % (str(self),stillAbstract)) return type.__call__(self,*args,**kw) def _IsSupposedToBeAbstract(cls): """Return true if cls is supposed to be an abstract class. A class which is ''supposed to be abstract'' is one which directly inherits from AbstractBaseClass. Due to metaclass magic, the easiest way to check this is to look for the __intended_abstract__ attribute which only AbstractBaseClass should have. """ for parent in cls.__bases__: if (parent.__dict__.get('__intended_abstract__',False)): return True @staticmethod def _GetAbstractMethods(classList,abstractMethods=None): """Returns all abstract methods in a list of classes. Takes classList which is a list of classes to look through and optinally takes abstractMethods which is a dict containing names of abstract methods already found. """ if (None == abstractMethods): abstractMethods = {} for cls in classList: for name in cls.__dict__: method = getattr(cls,name) if (callable(method) and getattr(method,'__abstract__',False)): abstractMethods[name] = True _AbstractMetaClass._GetAbstractMethods(cls.__bases__, abstractMethods) return abstractMethods.keys() @staticmethod def _GetParentsRequiring(methodName,cls): """Return list of parents that have a method defined as abstract. Arguments are methodName (string representing name of method to check) and cls (the class whose parents should be checked). """ result = [] for parent in cls.__bases__: if (getattr(parent,methodName,False) and getattr(getattr(parent,methodName),'__abstract__',False)): result.append(parent) return result class AbstractBaseClass(object): """ The AbstractBaseClass represents a class that defines some methods which must be implemented by non-abstract children. To use it, have your class inhereit from AbstractBaseClass and use the @Abstract decorator on the methods you want to be abstract. You can have many generations of abstract base classes inheriting from each other and adding @Abstract methods as long as they all inherit from AbstractBaseClass. If any class which does not DIRECTLY inherit from AbstractBaseClass, but does INDIRECTLY inherit from AbstractBaseClass must override all abstract methods. Otherwise, an AssertionError will be raised when the offending class is defined. What if you decide you want to turn of all checking and really do want to instantiate an abstract class? Just do klass.__allow_abstract__ = True and klass will no longer enforce the Abstract limitations. The following is an example of how this pattern can be used: >>> class abstract(AbstractBaseClass): # this will be the AbstractBaseClass ... @Abstract ... def foo(self,x): pass # declared abstract even though we def it here >>> try: # illustrate what happens when you don't implement @Abstract methods ... class fails(abstract): # an erroneous implementation of abstract ... pass # since it doesn't implment foo ... except AssertionError, e: ... print e Class must override foo to implement: []. >>> class concrete(abstract): # will be a concrete class implementing abstract ... def foo(self,x): ... return x+2 You can even create abstract classes that inherit from other abstract classes to gradually build up abstractions as shown below: >>> class AbstractCar(AbstractBaseClass): ... @Abstract ... def Drive(self): pass ... >>> class AbstractFastCar(AbstractCar,AbstractBaseClass):# inherit from ABC ... @Abstract # so that interpreter ... def DriveFast(self): pass # doesn't worry about ... # Drive being abstract >>> # Note that children of AbstractFastCar which are not abstract, must >>> # implement both DriveFast as requied by AbstractFastCar as well as >>> # Drive as required by AbstractCar. >>> try: # breaks since you don't implement Drive as requiered by AbstractCar ... class BadCar(AbstractFastCar): ... def DriveFast(self): pass ... except AssertionError, e: ... print str(e) Class must override Drive to implement: []. >>> try:#breaks since you don't implement DriveFast required by AbstractFastCar ... class BadCar(AbstractFastCar): ... def Drive(self): pass ... except AssertionError, e: ... print str(e) Class must override DriveFast to implement: []. >>> class FastCar(AbstractFastCar): # this works since you implement both ... def Drive(self): pass ... def DriveFast(self): pass >>> c = FastCar() If you don't like someone elses abstraction requirements, you can easily turn checking of the @Abstract requirements on and off. >>> class abstract(AbstractBaseClass): ... @Abstract ... def foo(self,x): pass >>> abstract.__allow_abstract__ = True # turn of all checking >>> class fails(abstract): pass # define a class failing requirements >>> fails().foo('ignore') # call its abstract method >>> abstract.__allow_abstract__ = False # turn checking back on >>> try: ... class bad(abstract): pass ... except AssertionError, e: ... print str(e) Class must override foo to implement: []. You can even use multiple inheritence to combine abstractions: >>> class AbstractCar(AbstractBaseClass): ... @Abstract ... def Drive(self): pass ... >>> class AbstractPlane(AbstractBaseClass): ... @Abstract ... def Fly(self): pass ... >>> class AbstractFlyingCar(AbstractCar,AbstractPlane,AbstractBaseClass): pass >>> try: ... class Car(AbstractFlyingCar): ... def Drive(self): pass ... except AssertionError, e: ... print 'not right' not right >>> class FlyingCar(AbstractFlyingCar): ... def Fly(self): pass ... def Drive(self): pass >>> # You can also define something which inherits both the car and plane >>> # abstractions without the extra layer of AbstractFlyingCar. >>> class FlyingCar(AbstractCar,AbstractPlane): ... def Fly(self): pass ... def Drive(self): pass """ __metaclass__ = _AbstractMetaClass __intended_abstract__ = True def Abstract(func): """ This is a function decorator that adds the attribute __abstract__ to a method function with the attribute having the value True. See documentation for AbstractBaseClass for how to use this decorator. """ if (__debug__): def wrapper(*_args,**_kw): result = func(*_args,**_kw) assert getattr(_args[0],'__allow_abstract__',False), ( 'Called Abstract method %s. Override %s; %s.' % ( func.__name__,func.__name__,"don't call it directly")) return result wrapper.__dict__ = func.__dict__ wrapper.__name__ = func.__name__ wrapper.__doc__ = func.__doc__ wrapper.__abstract__ = True return wrapper else: return func def _regr_test_children(): """ Regression test to make sure things work properly with more complicated inheritence for AbstractBaseClass. >>> class abstract(AbstractBaseClass): # this will be the AbstractBaseClass ... @Abstract ... def foo(self,x): # this is declared abstract even though we def it here ... raise Exception('You must override this method.') ... @Abstract ... def bar(self,x): # this is declared abstract even though we def it here ... raise Exception('You must override this method.') >>> class partial: # will be a partial implementation so don't inherit ... def foo(self,x): ... return x+2 >>> class concrete(partial,abstract): #provides concrete implementation ... def bar(self,y): ... return y+3 >>> try: ... class switch(abstract,partial): # order matters! ... pass ... except AssertionError, a: ... print 'order matters!' order matters! """ def _regr_test_wrapping(): """ Regression test to make sure that @Abstract decorator works properly. >>> class abstract(AbstractBaseClass): ... @Abstract ... def foo(self,x): ... 'docstring for foo' ... >>> assert abstract.foo.__doc__ == 'docstring for foo' >>> assert abstract.foo.__name__ == 'foo' >>> try: # verify that you can't instantiate an abstract class ... a = abstract() ... except AssertionError, e: ... print str(e) Cannot instantiate abstract base class because the follwoing methods are still abstract: ['foo'] >>> try: # even if programmer instantiate abstract, can't call abstract methods ... a = object.__new__(abstract) ... a.foo(1) ... except AssertionError, e: ... print str(e) Called Abstract method foo. Override foo; don't call it directly. >>> abstract.__allow_abstract__ = True # turn of all checking >>> class x(abstract): pass >>> y = x() >>> y.foo(1) """ def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test() print 'Test finished.' From steve at REMOVE.THIS.cybersource.com.au Sat Dec 9 23:12:46 2006 From: steve at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: Sun, 10 Dec 2006 15:12:46 +1100 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 09 Dec 2006 14:57:08 -0500, Bill Atkins wrote: > Paul Rubin writes: > >> There is just not that much boilerplate in Python code, so there's >> not so much need to hide it. > > Well, of course there is. There are always going to be patterns in > the code you write that could be collapsed. Language has nothing to > do with it; Lisp without macros would still be susceptible to > boilerplate. > > Here's a concrete example: > > (let ((control-code (read-next-control-code connection))) > (ecase control-code > (+break+ > (kill-connection connection) > (throw :broken-by-client)) > (+status+ > (send-status-summary connection)) > ((+noop+ +keep-alive+)))) > ;; +X+ indicates a constant Eight lines, excluding the comment, and it doesn't handle the case where control-code is not one of +break+, +status+, +noop+ or +keep-alive+, although the ecase macro does. And how many lines of code is ecase? > All of that > boilerplate is handled by the macro. In Python, I would need to do > something like: > > control_code = connection.read_next_control_code() > if control_code == +break+: > connection.kill() > throw blah > else if control_code == +status+: > connection.send_status_summary() > else if control_code == +noop+ || control_code == +keep_alive+: > else: > error "CONTROL_CODE fell through conditional cascade; was not one of +BREAK+, +STATUS+, +NOOP+, +KEEP_ALIVE+" Your Python syntax is rather wonky, but that's incidental. Nine lines, including handling the case where control_code is none of the four constants. Ten if you add the "pass" statement that it actually needs. And it is completely self-contained, with no external functions or macros to understand. Saving one line of code, at the expense of having another block of code to write or understand -- is that really the best example of what macros are used for in practice? You don't really save writing any boilerplate code, except for else clause, unless you're claiming that "if" and "elif" is boilerplate. Fine, you claim them as boilerplate. I'm going to claim all those unnecessary brackets as boilerplate. Yes, I know the parser needs them. But as so many people keep telling me, once you've been writing Lisp code for a month, you don't even notice the brackets. That makes them unnecessary for the developer, and therefore something the computer should handle on its own. You've already split expressions with whitespace, why should you have to use brackets as well? That's just boilerplate. Okay, I'm impressed that ecase can pick up on the four constants being tested against, and feed their names (rather than merely their values) into an error message. Python has nothing like that, and if you only have three or four things to test against, *and* they have names, that could be a useful thing to do. And if I've understood correctly, that's more a feature of Lisp's symbols than of macros. But if you're testing against fifty different values, well, is it really useful for your error message to list all fifty names? Or do you have another macro ecase-with-lots-of-tests? And how does ecase handle the more general case of testing against calculated objects rather than named constants? Or is there yet another macro for that? If that's the best example of what macros can be used for, frankly I'm unimpressed. Yes, I can see some benefit. But I don't see that the benefit is worth the added complexity. Maybe there are more complex tasks that macros are better suited for. -- Steven. From researchbase at gmail.com Sun Dec 3 02:06:18 2006 From: researchbase at gmail.com (krishnakant Mane) Date: Sun, 3 Dec 2006 12:36:18 +0530 Subject: evaluating gui modules, any experience on tkinter? In-Reply-To: <4571ffec$0$19245$4fafbaef@reader4.news.tin.it> References: <0qkch.2229$YI1.1130@newsfe15.lga> <4571ffec$0$19245$4fafbaef@reader4.news.tin.it> Message-ID: On 03/12/06, Gian Mario Tagliaretti wrote: > hg wrote: > > Tkinter is fine under *nix and Windows for a large range of applications. > I think it has drawbacks and advantage compared to other toolkits. The > major advantage being bundled with python, and the drawbacks include (I > think) ... look and feel, printing support, imaging, documentation. > well, I am looking seriously at wxpython. I found pyqt very good but can't figure out where to get dynamic run-times for qt. I don't want to compile it myself. if that is available then I could as well go for it. but talking about wxpython, I found it very easy. and after reading a few articles at devshed.com I am up and running with wxpython. but problem is that as I emailed on another thread, I am falling short of api documentation and reference for wxpython. there is the reference and all the docs for wx widgets. but what is the point in first studying the c++ version and then translating the same back to python when a library is already been translated and there to be used? Krishnakant. From kkylheku at gmail.com Tue Dec 12 18:36:31 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 12 Dec 2006 15:36:31 -0800 Subject: merits of Lisp vs Python In-Reply-To: References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165613280.584178.36470@16g2000cwy.googlegroups.com> <%Qseh.77$495.67@trnddc06> <7xodqdtpks.fsf@ruckus.brouhaha.com> Message-ID: <1165966591.547375.287360@80g2000cwy.googlegroups.com> I V wrote: > To be a little provocative, I wonder if the idea that you're "talking to > the interpreter" doesn't apply more to lisp than to python; you can have > any syntax you like, as long as it looks like an AST. Actually, that is false. You can have any syntax you like in Common Lisp. For instance, the syntax of Python: http://trac.common-lisp.net/clpython/ What thesaurus are you using which lists "provocative" as a synonym for "uninformed"? From ogbash at gmail.com Fri Dec 8 19:23:50 2006 From: ogbash at gmail.com (Oleg Batrashev) Date: 8 Dec 2006 16:23:50 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> Message-ID: <1165623830.577613.236890@16g2000cwy.googlegroups.com> Mark Tarver wrote: > How do you compare Python to Lisp? What specific advantages do you > think that one has over the other? > > Note I'm not a Python person and I have no axes to grind here. This is > just a question for my general education. > > Mark Im myself python programmer with C,C++,Java,Fortran background and also quite limited knowledge of Haskel, Lisp,Tcl,... . Im confused with most python answers like triple doublequotes. For me python is 'strong OOP' scripting language in first place. Inheritance, generalization and every kind of abstractions togeteher with clean and simple syntax make python perfect language for medium size "scripting" projects (ie just explore the code and add your features, no messing with compilers). Exceptions, finally/except blocks, automatic reference counts and destructors make it easy to write "robust" code. Packaging system and libraries are just fine. So, python is just C++ combined with elegancy of Java and simplicity of scripting. Again, Im not Lisp programmer, so would like to here about mentioned features, do those things work as nicely, especially OOP ones? And IMHO paren misfeature is bad, although you claim it to has some advantages. Mostly, when I copy code in python I just need to call increase-left-margin emacs macro and there are no mentioned a+b*c problem. So, I imagine my typical 1-2 page, max 4-5 nested python function with great readabilty and almost no refactoring problems and I need to add 20*2 parens to make it homogenous. :) Oleg From vasudevram at gmail.com Sun Dec 24 10:34:41 2006 From: vasudevram at gmail.com (vasudevram) Date: 24 Dec 2006 07:34:41 -0800 Subject: Connection python with C In-Reply-To: References: <66b602900612240237t3ba7cb71lc859f55d1d2f143c@mail.gmail.com> Message-ID: <1166974481.631576.153990@f1g2000cwa.googlegroups.com> Fredrik Lundh wrote: > ???????? ?????? wrote: > > > I want to connect a script in python with a source code in C. Any > > ideas about it? > > http://docs.python.org/lib/module-ctypes.html > http://docs.python.org/ext/ext.html > http://effbot.org/pyfaq/extending-index.htm > > Just a suggestion: another way could be to use XML-RPC. It's a lightweight distributed computing technology. Python standard library has an XML-RPC module. I'm not sure, but I think there may be a similar module for C. I'm almost certain there is one for C++. Try xmlrpc.com or xml-rpc.com and also Google for appropriate patterns, e.g. "XML-RPC library for C". Try a few variations on the pattern, that helps. Yet another way - might be suitable only if your Python script and your C program can both read/write standard input/output, and one is a producer and the other is the related consumer. In this case you can just use: $ python my_python_script | my_C_binary or the other way around, as per need. HTH Vasudev ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com Check out the cool Snap.com link preview feature on my site. Free sign-up at www.snap.com I'm not affiliated with Snap.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From pyenos at pyenos.org Fri Dec 22 20:15:16 2006 From: pyenos at pyenos.org (Pyenos) Date: 23 Dec 2006 12:15:16 +1100 Subject: scopes of local and global variable References: <87tzzncx59.fsf@pyenos.pyenos.org> <87psabcvlc.fsf@pyenos.pyenos.org> Message-ID: <87zm9fbefv.fsf@pyenos.pyenos.org> James Stroud writes: > >>>#############################CODE############################## > >>>t_len=0 > >>>class WORK: > >>> def getwork(self): > >>> def formattable(table_to_process,type): > >>>TYPE=["p","t","T","s","i"] #list of types to format > >>> if type==TYPE[1]: > >>> def format_t(): > >>> row=[] > >>> for col in table_to_process: > >>> ####################### > >>> # ERROR PRONE PART # > >>> ####################### > >>> if len(str(col))>t_len: > >>> t_len=len(str(col)) > >>> ####################### > >>># Error message says: # > >>># UnboundLocalError: local variable 't_len' referenced before assignment# > >>> row+=col > >>> if (table_to_process.index(col)+1)%7==0: > >>> t_temp.append(row) > >>> row=[] > >>> format_t() > >>>################################################################# based on your advice i will try to answer my own questions: > > does class WORK inherit t_len=0 from line1? yes. > > does def getwork() inherit t_len=0 from line1? no. > > does def formattable(table_to_process,type) inherit t_len=0 from > > line1? no. > > does def format_t() inherit t_len=0 from line1? no. thank you kindly. From andrew at farwestbilliards.com Wed Dec 13 20:02:53 2006 From: andrew at farwestbilliards.com (Andrew Sackville-West) Date: Wed, 13 Dec 2006 17:02:53 -0800 Subject: speed of python vs matlab. In-Reply-To: <1166054840.646029.265880@73g2000cwn.googlegroups.com> References: <1166054840.646029.265880@73g2000cwn.googlegroups.com> Message-ID: <20061214010252.GA4761@localhost.localdomain> On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote: > I've been trying to develop some numerical codes with python, however > got disappointed. > > A very simple test, > > a = 1.0 > > for i in range(1000): > for j in range(1000): > a = a+1 > > unfortunately, it took 4.5 seconds to finish(my machines is fine. P4 > 3.0G, 1G RAM, it varies according to machine configuration, but should > be in the same level) somethings not right there. andrew at debian:~$ cat pytimetest.py a=1.0 for i in range (1000): for j in range (1000): a=a+1 andrew at debian:~$ time python pytimetest.py real 0m0.534s user 0m0.528s sys 0m0.000s andrew at debian:~$ cat /proc/cpuinfo | grep name model name : Intel(R) Celeron(R) CPU 2.53GHz andrew at debian:~$ uname -a Linux debian 2.6.18-3-686 #1 SMP Mon Dec 4 16:41:14 UTC 2006 i686 GNU/Linux A -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From moishyyehuda at gmail.com Mon Dec 11 12:41:58 2006 From: moishyyehuda at gmail.com (moishyyehuda at gmail.com) Date: 11 Dec 2006 09:41:58 -0800 Subject: can I download Python Imaging Library (PIL) for linux. Message-ID: <1165858918.771531.126560@j44g2000cwa.googlegroups.com> can I download Python Imaging Library (PIL) for linux. From istvan.albert at gmail.com Thu Dec 7 10:31:13 2006 From: istvan.albert at gmail.com (Istvan Albert) Date: 7 Dec 2006 07:31:13 -0800 Subject: A Call to Arms for Python Advocacy References: Message-ID: <1165505473.337157.104320@j72g2000cwa.googlegroups.com> Roy Smith wrote: > I think it also appears to need faster hardware. It's running glacially > slow. runs fine here i. From greg at cosc.canterbury.ac.nz Fri Dec 15 06:18:32 2006 From: greg at cosc.canterbury.ac.nz (greg) Date: Sat, 16 Dec 2006 00:18:32 +1300 Subject: merits of Lisp vs Python In-Reply-To: <1166092000.715620.50040@f1g2000cwa.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7xejrah9on.fsf@ruckus.brouhaha.com> <1165582654.974945.173700@79g2000cws.googlegroups.com> <1165587080.038533.47910@80g2000cwy.googlegroups.com> <45797b9b$0$49206$14726298@news.sunsite.dk> <4ttiadF15dam8U1@mid.individual.net> <45799bf6$0$49202$14726298@news.sunsite.dk> <4ttqsoF15ld61U3@mid.individual.net> <4tvm5mF15g127U1@mid.individual.net> <4u8hu5F177u11U1@mid.individual.net> <1165984694.264366.261250@80g2000cwy.googlegroups.com> <457fd653$0$4340$426a74cc@news.free.fr> <1166092000.715620.50040@f1g2000cwa.googlegroups.com> Message-ID: <4ufen5F17of60U5@mid.individual.net> josephoswaldgg at hotmail.com wrote: > I wrote my first Python in a non-Python-aware editor, and somehow had > swapped tabs and spaces; when I moved it to IDLE---the indentation > *looked fine* but was invisibly weird. That can admittedly be a problem. It would help if the parser complained by default about mixed use of tabs and spaces in a single file, instead of silently assuming tab stops every 8 spaces (an historical misfeature that we still have for the time being). Probably this will change in Python 3.0. Personally I find Python pleasant enough to work with that I'm willing to put up with the odd screwup like that happening now and then. And they really don't happen all that often -- once you've experienced it a few times, you learn how to guard against it and get better at fixing it when it does happen. > I will even admit that white-space significance does not > materially increase errors among experienced Pythonistas. What it isn't > is some kind of miraculous invention that saves programmers from ever > making mistakes that are common in other languages, We don't claim that -- only that it's not the unmitigated disaster than some people assume it will be without ever having tried it. -- Greg From cito at online.de Sat Dec 16 05:33:28 2006 From: cito at online.de (Christoph Zwerschke) Date: Sat, 16 Dec 2006 11:33:28 +0100 Subject: tuple.index() In-Reply-To: References: <1166104987.884566.126710@n67g2000cwd.googlegroups.com> <1166106278.106832.278240@n67g2000cwd.googlegroups.com> Message-ID: James Stroud wrote: > Christoph Zwerschke wrote: >> Maybe there would be less dispute if this dogma/convention(?) "Tuples >> are for heterogeneous data, list are for homogeneous data" would be >> written down somewhere in the tutorial, reference or in PEP8, so >> people would be aware of it. > > This is a good idea. It has taken me a while to begin using them in this > manner. I have been more or less forced to by the design of the language > and I confess that the intended usage of each is pretty natural. I just found that there is indeed some mentioning in the FAQ here: http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types But it is a bit vague, too, and does not mention whether there is any difference in efficiency which would be interesting to know as well. It would be nice if somebody with more knowledge about the internals could overhaul and supplement that answer in the FAQ. A link to this in the tutorial or other parts of the standard doc where tuples and lists are discussed would be also helpful. >> Concretely speaking, which data type should I use for coordinate >> tuples? Usually, tuples are used. Does this mean that I should better >> use lists from now on because all the components have the same type? > > I don't think that all homogenous structures should be lists. This is > not the same as saying that all lists should be homogenous. So in which cases exactly should one make exceptions? Python experts probably decide this from their "gut feelings" but it would be nice to have a more complete "rule of thumb" or decision guidance for non-experts that is mentioned somewhere in the docs, too: Must be hashable for use as dict key or set element --> tuple "Inhomogenous" in some meaning of the word --> tuple ... (fill in the details) --> tuple everything else --> list Maybe we can agree on something concrete here. From gnewsg at gmail.com Wed Dec 13 09:14:23 2006 From: gnewsg at gmail.com (billie) Date: 13 Dec 2006 06:14:23 -0800 Subject: How to manage two (different) sockets without using threads? Message-ID: <1166019263.059903.273090@j72g2000cwa.googlegroups.com> Hi all. I'm (re)writing an FTP server application by using asyncore/asynchat modules. FTP tipically got two different channels: command and data. I'm succesfully managing command channel through asynchat framework, but I'm not sure about how to manage data channel without using a thread/subprocess. Is there an optimal to do that? Can anyone point me in the right direction? From mensanator at aol.com Fri Dec 8 16:02:06 2006 From: mensanator at aol.com (mensanator at aol.com) Date: 8 Dec 2006 13:02:06 -0800 Subject: Snake references just as ok as Monty Python jokes/references in python community? :) In-Reply-To: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> References: <1165607250.544331.124360@j72g2000cwa.googlegroups.com> Message-ID: <1165611725.326455.163640@n67g2000cwd.googlegroups.com> seberino at spawar.navy.mil wrote: > I'm semi-seriously wondering if snake jokes are valid in the Python > community since technically, Python came from Monty Python, not > slithery animals. > > Problem is I don't know that anyone born after Elvis died gets any of > these Monty Python jokes. > > Is it kosher to make snake jokes/references even though officially they > don't have anything to do with the name of our favorite language? > (*Everyone* gets snake jokes! :) > > Chris Well, yes, that's just the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage. From sjmachin at lexicon.net Fri Dec 8 12:07:29 2006 From: sjmachin at lexicon.net (John Machin) Date: 8 Dec 2006 09:07:29 -0800 Subject: Text Encoding - Like Wrestling Oiled Pigs In-Reply-To: <1165595168.337197.235040@80g2000cwy.googlegroups.com> References: <1165595168.337197.235040@80g2000cwy.googlegroups.com> Message-ID: <1165597649.177639.234320@79g2000cws.googlegroups.com> apotheos at gmail.com wrote: > So I've got a problem. > > I've got a database of information that is encoded in Windows/CP1252. > What I want to do is dump this to a UTF-8 encoded text file (a RSS > feed). > > While the overall problem seems to be related to the conversion, the > only error I'm getting is a > > "UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position > 163: ordinal not in range(128)" > > So somewhere I'm missing an implicit conversion to ASCII which is > completely aggrivating my brain. > > So, what fundamental issue am I completely overlooking? That nowhere in your *code* do you mention "I've got a database of information that is encoded in Windows/CP1252". This is not recorded anywhere in your database. Python is fantastic, but we don't expect a readauthorsmind() function until Python 4000 :-) > > Code follows. > [snip] > > sql_query = "select story.subject as subject, story.content as > content, story.summary as summary, story.sid as sid, posts.bid as > board, posts.date_to_publish as date from story$ The above line has been mangled ... fortunately it doesn't affect the diagnostic outcome. [snip] > > > output.write(u'' + unicode(descript) + > u'\n') # this is the line that causes the error. What is happening is that unicode(descript) has not been told what encoding to use to decode your "Windows/CP1252" text, and it uses the default encoding, "ascii". You need to put unicode(descript, 'cp1252'). Cheers, John From __peter__ at web.de Tue Dec 12 03:52:30 2006 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Dec 2006 09:52:30 +0100 Subject: Avoiding "invalid literal for int()" exception References: <1165832540.392387.240550@j72g2000cwa.googlegroups.com> Message-ID: Marc 'BlackJack' Rintsch wrote: > In , Gabriel > Genellina wrote: > >> At Monday 11/12/2006 07:22, aine_canby at yahoo.com wrote: >> >>>elif int(uniList[0]) in range(0,10): >> >> Either of these will work to avoid an unneeded conversion: >> >> elif uniList[0] in "0123456789": >> >> elif uniList[0] in string.digits: >> >> elif uniList[0].isdigit(): > > The last does not work. Not only that it accepts numbers greater than 9 > because it checks if the whole string consists of digits, it also accepts > u'??' and other unicode digits. By the way, if you require an implicit 0 <= int(s) < 10 check, none of the above work with the newer Pythons: >>> s = "23" >>> s in "0123456789" True >>> s in set("0123456789") False Peter From simon at brunningonline.net Thu Dec 14 09:19:00 2006 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 14 Dec 2006 14:19:00 +0000 Subject: tuple.index() In-Reply-To: <1166105112.012246.80580@79g2000cws.googlegroups.com> References: <1166103409.199435.290670@79g2000cws.googlegroups.com> <1166105112.012246.80580@79g2000cws.googlegroups.com> Message-ID: <8c7f10c60612140619l1fab85e2l118adf5f7d2421f7@mail.gmail.com> On 14 Dec 2006 06:05:12 -0800, Glenn Hutchings wrote: > It's not my own code I'm worried about. :-) If you want a language that protects you not only from your own mistakes, but also the mistakes of others, well, err, sorry, I'm not sure I can help you. Eiffel, perhaps? -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From michele.simionato at gmail.com Mon Dec 11 05:33:25 2006 From: michele.simionato at gmail.com (Michele Simionato) Date: 11 Dec 2006 02:33:25 -0800 Subject: merits of Lisp vs Python In-Reply-To: <457d2b13.3849154@news.readfreenews.net> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165715580.731398.131690@f1g2000cwa.googlegroups.com> <1165769504.098173.101860@j72g2000cwa.googlegroups.com> <1165793825.487994.52430@f1g2000cwa.googlegroups.com> <1165824471.730090.153530@j72g2000cwa.googlegroups.com> <1165825648.930965.208130@j72g2000cwa.googlegroups.com> <457d2b13.3849154@news.readfreenews.net> Message-ID: <1165833205.585598.230600@79g2000cws.googlegroups.com> Timofei Shatrov wrote: > It's not surprising that no one uses this stuff for serious work. Well, I replaced all my unittests with doctests long ago, and I am not the only one following this way (see the Zope 3 project for instance). Michele Simionato From petercable at gmail.com Tue Dec 5 21:44:14 2006 From: petercable at gmail.com (petercable at gmail.com) Date: 5 Dec 2006 18:44:14 -0800 Subject: how to invoke the shell command and then get the result in python In-Reply-To: References: <1165303175.523129.154400@j72g2000cwa.googlegroups.com> <1165306945.315445.303490@80g2000cwy.googlegroups.com> Message-ID: <1165373054.386217.231750@l12g2000cwl.googlegroups.com> Nick Craig-Wood wrote: > > What if I entered "; rm -rf * ;" as my pattern? > Assuming the script isn't setuid, this would do no more damage than the user could do directly on the command line. I agree, when dealing with web applications or setuid programs, direct shell access isn't a good idea. Pete From duncan.booth at invalid.invalid Fri Dec 15 09:10:32 2006 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Dec 2006 14:10:32 GMT Subject: Problem comparing object graphs and trees References: <1166189934.686619.56720@16g2000cwy.googlegroups.com> Message-ID: raphael.marvie at gmail.com wrote: > I swear I am not drunk, but why isn't a1 == a2 and worse why isn't a1 >== a1? Does someone have a clue and can explain to me this suprising > behavior? (python 2.4.3 on Ubuntu 6.06). Because the __cmp__ method doesn't return a boolean. It returns a value <0, 0 or >0 according to the relative ordering of its arguments. You are returning True (1) when the values are equal and you should be returning 0. If ordering isn't defined for your objects then define __eq__ instead of __cmp__. From jonc at icicled.net Sat Dec 9 00:35:50 2006 From: jonc at icicled.net (Jonathan Curran) Date: Fri, 8 Dec 2006 23:35:50 -0600 Subject: Interacting with keyboard LEDs In-Reply-To: <1165641507.187794.115360@l12g2000cwl.googlegroups.com> References: <1165641507.187794.115360@l12g2000cwl.googlegroups.com> Message-ID: <200612082335.50546.jonc@icicled.net> On Friday 08 December 2006 23:18, Chris Lasher wrote: > Is there a way to interact with keyboard LEDs (for Caps/Scroll/Num > Lock) in Python? I'd like to achieve an effect similar to the *NIX > command "setleds -L", but I'm not sure where to start, but I figured > someone out there would have an idea or maybe experience with something > similar. Thanks very much in advance for your help! > > Chris Spur of the moment answer: call setleds program from within your program better answer (fox X11): http://python-xlib.sourceforge.net/doc/html/python-xlib_16.html Take a look at get_keyboard_control() and change_keyboard_control(). As far as knowing how to properly invoke them, I have no idea, maybe you could google for examples or take a look at the setleds source? - Jonathan From kkylheku at gmail.com Fri Dec 8 13:17:19 2006 From: kkylheku at gmail.com (Kaz Kylheku) Date: 8 Dec 2006 10:17:19 -0800 Subject: merits of Lisp vs Python In-Reply-To: <1165598576.650860.126740@16g2000cwy.googlegroups.com> References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165598576.650860.126740@16g2000cwy.googlegroups.com> Message-ID: <1165601839.678815.191410@79g2000cws.googlegroups.com> Mark Tarver wrote: > I don't mind controversy - as long as there is intelligent argument. > And since it involves Python and Lisp, well it should be posted to both > groups. The Lispers will tend to say that Lisp is better for sure - > so it gives the Python people a chance to defend this creation. And that would be our confirmation that this is another trolling asshole. From fredrik at pythonware.com Wed Dec 20 14:48:29 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Dec 2006 20:48:29 +0100 Subject: TypeError: cannot concatenate 'str' and 'NoneType' objects In-Reply-To: <1166643197.329196.44220@t46g2000cwa.googlegroups.com> References: <1166641701.439766.253290@f1g2000cwa.googlegroups.com> <1166643197.329196.44220@t46g2000cwa.googlegroups.com> Message-ID: Mark Peters wrote: > However, the typical Python way to iterate through a list for be to > use a for loop. Perhaps replace the while statement with: > for Townshp in Townshps: > and remove the "Townshp = Townshps.next()" lines that assumes that the feature class list is actually a Python iterable, of course, and not just something that happens to have a "next" method. ::: ... and judging from the documentation http://webhelp.esri.com/arcgisdesktop/9.1/index.cfm?TopicName=ListFeatureClasses%20method it's not an iterable. ::: you could of course replace the fcs = gp.ListFeatureClasses() fc = fcs.next() while fc: ... fc = fcs.next() pattern with for fc in iter(gp.ListFeatureClasses().next, None): ... but maybe that's a bit too clever for an absolute novice ;-) From ramashish.lists at gmail.com Wed Dec 27 13:37:45 2006 From: ramashish.lists at gmail.com (Ramashish Baranwal) Date: 27 Dec 2006 10:37:45 -0800 Subject: Passing variable number of named arguments Message-ID: <1167244665.250901.129020@79g2000cws.googlegroups.com> Hi, I need to process few out of a variable number of named arguments in a function and pass the remaining to another function that also takes variable number of named arguments. Consider this simple example, def fun1(**kwargs): print kwargs.keys() def fun2(**kwargs): # get id param id = kwargs.pop('id', '') # pass on remaining to fun1 fun1(kwargs) When I try to call fun2 I get the following error- TypeError: fun1() takes exactly 0 arguments (1 given) It seems that the arguments are not passed to fun1 as named arguments. How can I go about this? Using a dictionary in place of kwargs would be a way, but I can't modify fun1, so thats ruled out for me. Thanks, Ram From duane.kaufman at gmail.com Fri Dec 29 11:00:04 2006 From: duane.kaufman at gmail.com (TheSeeker) Date: 29 Dec 2006 08:00:04 -0800 Subject: Python Wrapper for C# Com Object In-Reply-To: <1167402227.920435.3340@a3g2000cwd.googlegroups.com> References: <1167297178.937748.91790@79g2000cws.googlegroups.com> <1167313715.296081.133170@n51g2000cwc.googlegroups.com> <1167402227.920435.3340@a3g2000cwd.googlegroups.com> Message-ID: <1167408004.072372.274370@h40g2000cwb.googlegroups.com> Hi, A question. Why in your C-version are your doing: X_com_ptr->SetID(10); and in the Python version: interface.SetID() ? I don't know anything of your COM object, but does SetID require a parameter? Duane bg_ie at yahoo.com wrote: > bg_ie at yahoo.com skrev: > > > bg_ie at yahoo.com skrev: > > > > > Hi, > > > > > > I wish to write a Python wrapper for my C# COM object but am unsure > > > where to start. I have a dll and a tlb file, and I can use this object > > > in C via the following code - > > > > > > // ConsolApp.cpp : Defines the entry point for the console application. > > > // > > > #include "stdafx.h" > > > #include "windows.h" > > > #include "stdio.h" > > > #import "C:\Documents and Settings\X\Mina dokument\Visual Studio > > > 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb" > > > using namespace X_COMObject; > > > > > > int _tmain(int argc, _TCHAR* argv[]) > > > { > > > CoInitialize(NULL); > > > > > > X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class)); > > > XCOM_Interface *X_com_ptr ; > > > X_com_ptr = p ; > > > X_com_ptr->SetID(10); > > > int x = X_com_ptr->GetID(); > > > printf("%d",x); > > > getchar(); > > > > > > return 0; > > > } > > > > > > Can anyone offer me some tips as to how to do this in Python? > > > > > > Thanks very much for your help, > > > > > > Barry. > > > > This is what I've done so far, but I know I'm not doing this correctly. > > Can anyone help me out? > > > > #import pythoncom > > #pythoncom.CoInitialize() > > > > from comtypes.client import GetModule, CreateObject > > > > module = GetModule("C:\\Documents and Settings\\X\\Mina > > dokument\\Visual Studio > > 2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb") > > > > dir(module) > > > > interface = module.XCOM_Interface() > > > > dir(interface) > > > > interface.SetID() > > > > #pythoncom.CoUnitialize() > > > > > > Traceback (most recent call last): > > File "C:/Python25/test.py", line 14, in > > interface.SetID() > > TypeError: Expected a COM this pointer as first argument > > Can anyone help me with this? > > Thanks, > > Barry. From eadmund42 at NOSPAMgmail.com Tue Dec 12 21:14:58 2006 From: eadmund42 at NOSPAMgmail.com (Robert Uhl) Date: Tue, 12 Dec 2006 19:14:58 -0700 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <1165689545.676886.289150@j44g2000cwa.googlegroups.com> <1165698244.563344.62270@73g2000cwn.googlegroups.com> Message-ID: Steven D'Aprano writes: > > Even if you're stuck on some god-forsaken Windows PC with just > Notepad, you can still read Python code. Ummm...Lisp ain't APL--it's just ASCII (or ISO-8859-1 or Unicode or whatever...), and thus just as readable in Notepad as anything else. > Now, *writing* Python code with Notepad isn't as easy, but it is still > doable. How about Lisp code? Given that fellows were writing Lisp code before there were CRTs (e.g. using teletypes to type), it's quite doable. Would I want to do so? Of course not, no more than I'd want to write Python in Notepad. > The day has not yet arrived that nobody ever needs to edit code in a > plain, vanilla text editor. My platform has emacs and vi by default. There are editors as brain-damaged as Notepad, but I never use them, and in an emergency they wouldn't run (as they require X). Now, force me to write Lisp _or_ Python in ed and things will get very ugly... -- Robert Uhl Whoa, there. Those are some strong words for somebody who doesn't even own a machine gun. --Milkman Dan From michael at guerrilla-games.com Fri Dec 1 05:39:10 2006 From: michael at guerrilla-games.com (Michael Malinowski) Date: Fri, 1 Dec 2006 11:39:10 +0100 Subject: How to read the directory which the actively running python file islocated in? In-Reply-To: <00a801c7151f$a76d0de0$a8e7ca2b@guerrillagames.com> Message-ID: <002701c71534$ef9f0f90$a8e7ca2b@guerrillagames.com> Nevermind, I got it using the sys.argv[0] -----Original Message----- From: python-list-bounces+michael=guerrilla-games.com at python.org [mailto:python-list-bounces+michael=guerrilla-games.com at python.org] On Behalf Of Michael Malinowski Sent: Friday, December 01, 2006 9:07 AM To: python-list at python.org Subject: How to read the directory which the actively running python file islocated in? Is there a way to read the directory that the currently running python file is located in? Cheers Mike. -- http://mail.python.org/mailman/listinfo/python-list From jon at ffconsultancy.com Tue Dec 12 10:30:10 2006 From: jon at ffconsultancy.com (Jon Harrop) Date: Tue, 12 Dec 2006 15:30:10 +0000 Subject: merits of Lisp vs Python References: <1165576029.316969.24690@j72g2000cwa.googlegroups.com> <7x1wn9st9k.fsf@ruckus.brouhaha.com> <1-udnfne7ZPgrefYnZ2dnUVZ_rzinZ2d@speakeasy.net> <7x64cl90xx.fsf@ruckus.brouhaha.com> <1165643023.729419.239470@j72g2000cwa.googlegroups.com> <7xy7pho7mj.fsf@ruckus.brouhaha.com> <7xodqczf1h.fsf@ruckus.brouhaha.com> <7xk60zjl1e.fsf@ruckus.brouhaha.com> <7xk60x7wka.fsf@ruckus.brouhaha.com> Message-ID: <457ecb9e$0$8719$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: > Are there any Lisp devotees who have done serious development in ML? There is a disproportionately small overlap between the Lisp/Scheme and ML/Haskell communities. They are probably of comparable size at the moment. I believe the difference is largely geographical. -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet From google at mrabarnett.plus.com Thu Dec 7 19:38:56 2006 From: google at mrabarnett.plus.com (MRAB) Date: 7 Dec 2006 16:38:56 -0800 Subject: Window, Windows, Linux, client and server... In-Reply-To: References: Message-ID: <1165538336.320243.22740@l12g2000cwl.googlegroups.com> Cameron Laird wrote: > In article , > Gabriel Genellina wrote: > >At Thursday 7/12/2006 05:28, nelson - wrote: > > > >> i'm trying to implement an appllication with this two requirements. > >>I have a server and some clients. I want to be able to launch an > >>application (openoffice impress, for example) and display what i'm > >>doing on the server on the client. Conversely, I want to be able to > >>have a picture of the desktop client. Is it a thing that i can do in > >>python? any advice? I googled but i can't find something too useful... > >> II know i can use vnc, but i want a pure python solution... if it's > >>possibile... Doing it using VNC it seems not so "clear"... :) > > > >I'm not sure exactly what you want - but there are a couple of VNC > >clients written in Python, btw... > . > . > . > Nelson, there is GREAT technology available in this area. We don't > understand your description, though. How, for example, does VNC fail > to meet your requirements? > > When you write "a picture of the desktop client", do you have in mind > a snapshot, or a "movie"? Do you want an image, or a "live" "mirror"? > > When you write, "I have a server and some clients", are you talking > about specific applications that already exist? Do you maintain them? > Are they coded in Python? > > What you call "this two requirements" leaves much undetermined. The > more precisely you describe your needs, the more likely someone will > be able to provide appropriate help. I think he wants to be able to show the server desktop on a client (for example, to show a user how to do something) and also be able to see a client desktop on the server (for example, to see whether the user is doing it correctly). Is there and easy way to switch between showing the server on a client and seeing a client on the server? From carsten at uniqsys.com Tue Dec 26 15:06:16 2006 From: carsten at uniqsys.com (Carsten Haese) Date: Tue, 26 Dec 2006 15:06:16 -0500 Subject: Q: How to generate code object from bytecode? In-Reply-To: <1167162539.3394.18.camel@dot.uniqsys.com> References: <1167160509.839311.230090@73g2000cwn.googlegroups.com> <1167162539.3394.18.camel@dot.uniqsys.com> Message-ID: <1167163576.3394.26.camel@dot.uniqsys.com> On Tue, 2006-12-26 at 14:48 -0500, Carsten Haese wrote: > * Code objects come in two flavors: statements and expressions. > * exec can execute a 'statement' flavored code object. > * eval can evaluate an 'expression' flavored code object. > * Your code snippet is a statement, actually, a suite of statements. You > need to exec it, not eval it. And to reply to myself before the effbot corrects me, it turns out that the separation between expressions and statements is not quite so strict. For one, an expression can be used like a statement. Also, apparently eval() can evaluate the code object of a statement, even though it can't evaluate the source code of a statement, which I find oddly inconsistent: >>> eval("print 'Hi'") Traceback (most recent call last): File "", line 1, in File "", line 1 print 'Hi' ^ SyntaxError: invalid syntax >>> eval(compile("print 'Hi'", "