From ignacio at openservices.net Thu Oct 18 23:36:46 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 18 Oct 2001 23:36:46 -0400 (EDT) Subject: Method returns self? In-Reply-To: Message-ID: On Thu, 18 Oct 2001, Roy Smith wrote: > I've got a data file parser that returns a data object. You call it > something like this: > > parser = myParser() > data = parser.parse(filename) > > Now, I want to give the data class a verify() method. The parser only > ensures that the data file has a parsable syntax, but there are also a > number of higher-level semantic checks that we might want to do. I have in > mind something that you would call like this: > > parser = myParser() > try: > data = parser.parse(filename).verify() > except data.VerifyError: > print "you bozo" > > The idea is that verify() is a method of the data class which either > returns self, or raises an exception. The code would look something like: > > class data: > def verify (self): > if everthing is cool: > return self > else: > raise VerifyError > > My question is, will I run into garbage collection or reference count > problems if a method returns self? I can't quite put my finger on it, but > I have this vague feeling I might end up with a self-referential object. No, because in the code above the returned value of myParser.parse() only exists for the duration of that statement. A copy of the reference returned from ....verify(), however, is assigned to data, but trust me, it's fine. > Now, I realize, I could just have it return None instead of self, and then > use it like: > > parser = myParser() > data = parser.parse(filename) > try: > data.verify() > except data.VerifyError: > print "you bozo" > > This would avoid the problem entirely, but it's not as interesting to think > about :-) Right, but you don't have to return None because that's what using return alone or reaching the end of a function does implicitly. Another thing you could do, if you plan to have more than one possible format, is to have myParser.parse() do the verification of the data and return a myData1, myData2, etc. object depending on the format. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From nicoLALALALALA at altiva.fr Fri Oct 19 10:53:47 2001 From: nicoLALALALALA at altiva.fr (NM - Remove LALALALALA to email me) Date: Fri, 19 Oct 2001 16:53:47 +0200 Subject: About popen2 Message-ID: Am I right to assume that, unlike C's popen, popen2's "command" argument does not get passed through the shell? If I am, is there a way to pass arguments? From dag4004 at caramail.com Thu Oct 25 12:15:15 2001 From: dag4004 at caramail.com (dag4004) Date: Thu, 25 Oct 2001 12:15:15 -0400 Subject: HELP for embedding Python in C prog Message-ID: <3bd7e585$0$853$626a54ce@news.free.fr> hello, I want to embedded Python in a C prog. I try with the Programming Python (O'REILLY). Here is the exemple : basic1.c #include int main(void) { Py_Initialize(); PyRun_SimpleString("a=1"); PyRun_SimpleString("print a"); return 0; } the makefile PY = /usr/src/Python-2.1.1 PLIBS = $(PY)/libpython2.1.a basic1: basic1.o gcc -g basic1.o $(PLIBS) -lm -o basic1 basic1.o: basic1.c gcc basic1.c -c -g -I$(PY)/Include -I$(PY)/. And what i get : # make gcc -g basic1.o /usr/src/Python-2.1.1/libpython2.1.a -lm -o basic1 /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function `posix_tmpnam':/usr/src/Python-2.1.1/./Modules/posixmodule.c:4212: the use of `tmpnam_r' is dangerous, better use `mkstemp' /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function `posix_tempnam': /usr/src/Python-2.1.1/./Modules/posixmodule.c:4168: the use of `tempnam' is dangerous, better use `mkstemp' /usr/src/Python-2.1.1/libpython2.1.a(dynload_shlib.o): In function `_PyImport_GetDynLoadFunc': /usr/src/Python-2.1.1/Python/dynload_shlib.c:86: undefined reference to `dlopen'/usr/src/Python-2.1.1/Python/dynload_shlib.c:94: undefined reference to `dlerror' /usr/src/Python-2.1.1/Python/dynload_shlib.c:72: undefined reference to `dlsym' /usr/src/Python-2.1.1/Python/dynload_shlib.c:99: undefined reference to `dlsym' /usr/src/Python-2.1.1/libpython2.1.a(thread.o): In function `PyThread_start_new_thread': /usr/src/Python-2.1.1/Python/thread_pthread.h:135: undefined reference to `pthread_create' /usr/src/Python-2.1.1/Python/thread_pthread.h:159: undefined reference to `pthread_detach' /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function `posix_openpty': /usr/src/Python-2.1.1/./Modules/posixmodule.c:1754: undefined reference to `openpty' /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function `posix_forkpty': /usr/src/Python-2.1.1/./Modules/posixmodule.c:1785: undefined reference to `forkpty' collect2: ld returned 1 exit status make: *** [basic1] Erreur 1 Does some one understand what goes wrong ? HELP Damien From ignacio at openservices.net Wed Oct 3 02:32:19 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 3 Oct 2001 02:32:19 -0400 (EDT) Subject: Past command buffer gone in interpreter? In-Reply-To: Message-ID: On Wed, 3 Oct 2001, Tod Fox wrote: > I am using Redhat 7.1. I was using the python installed by Redhat (1.5.2 I think), but I decided to upgrade to > 2.1.1. It installed without any apparent problems and was able to run the test without any major failures. However, > a minor aspect of the interpreter has now changed; I can no longer use the up and down arrow keys to return to > past commands I have entered -- it prints garbage characters on the screen instead. > > I can't tell if this is really an issue with python, or what could be causing this. I've tried to look through the > documentation for this kind of thing, but if I have missed something I will read it if it is pointed out to me. Did you install from RPM, SRPM, or tarball, and if RPM or SRPM, where did you get it from? -- Ignacio Vazquez-Abrams From fog at debian.org Thu Oct 18 08:49:38 2001 From: fog at debian.org (Federico Di Gregorio) Date: Thu, 18 Oct 2001 14:49:38 +0200 Subject: PostgreSQL Interface Query References: <3BC990D7.2680A5AE@iinet.net.au> Message-ID: In <3BC990D7.2680A5AE at iinet.net.au>, John Bell wrote: > Stuart Bishop wrote: [snip] > For the moment the low level of thread safety is not an issue in this > project. I agree that under most circumstances it would be better to > stick strictly to the DB API. However, there appears to be a situation > that is only covered by the pypgsql package. The cursor object has an > attribute which stores the OID of the last inserted row thus allowing > for the indirect retrieval of SERIAL keys for insertion in foreign key > fields. This doesn't seem to be achievable in either PoPy or psycopg. > Please correct me if I'm wrong. you are wrong. :) psycopg cursors have a .lastoid() method that does exactly that. -- Federico Di Gregorio Debian GNU/Linux Developer & Italian Press Contact fog at debian.org INIT.D Developer fog at initd.org God is real. Unless declared integer. -- Anonymous FORTRAN programmer From logiplexsoftware at earthlink.net Wed Oct 17 19:09:06 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 17 Oct 2001 16:09:06 -0700 Subject: problem with indentation and emacs In-Reply-To: <9qkt53$olvlr$1@ID-75083.news.dfncis.de> References: <9qkt53$olvlr$1@ID-75083.news.dfncis.de> Message-ID: <01101716090609.05124@logiplex1.logiplex.net> On Wednesday 17 October 2001 14:26, Markus Jais wrote: > when I cut and paste some code within a *.py file > then there seems to be problems with identation. > > everything looks fine, but the programm crashes with > syntax error or with "IndentationError: expected an indented block" > > when I look at the code, everything looks o.k. > when I open the file with vim and reindent everyting, > the programm works. I often get this when doing the "cut and paste" thing. If you are using tabs to indent, do a M-x tabify on the region you pasted. If you are using spaces, do a M-x untabify. It comes down to either you or the author you are "borrowing" from are using different indent (ie tabs vs spaces) styles. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From phr-n2001d at nightsong.com Sun Oct 14 19:04:25 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 14 Oct 2001 16:04:25 -0700 Subject: Python web client anyone? References: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> Message-ID: <7xn12tombq.fsf@ruckus.brouhaha.com> "Fredrik Lundh" writes: > > Anyone know if there are any web client modules written in Python, > > along the lines of the Perl LWP module? Thanks. > > >>> import urllib > > more info here: > > http://www.python.org/doc/current/lib/internet.html Thanks, this appears to include an HTTP client, which is a start, but I was looking for something that actually parses the HTML on the retrieved page like LWP does. I wonder if there's some way to do that with the XML libraries (though HTML is generally not well-formed XML--for example it usually has unterminated

tags). Any thoughts? From usenet at jeffjohnson.net Wed Oct 24 17:51:08 2001 From: usenet at jeffjohnson.net (Jeff Johnson) Date: 24 Oct 2001 14:51:08 -0700 Subject: urllib.urlopen + https = all threads locked? Message-ID: I have a multi-threaded application that makes calls urllib.urlopen("https://yadayada.com"). Until the call completes (or maybe the following read) all other threads just freeze. They continue working after the call completes so it took me a while to realize there was a problem. Someone suggested: "Sounds like the C code that does the SSL is not _releasing_ the global thread lock." I'm using python SSL that comes with Python 2.1.1 on FreeBSD 4.3. I searched usenet and everywhere else I could think of but only found one usenet post about broken ThreadingMixin know to be broken in 2.1.1c but I'm not sure if this is related. Any suggestions? Is this a known problem? Thanks, Jeff From johnroth at ameritech.net Thu Oct 4 18:20:52 2001 From: johnroth at ameritech.net (John Roth) Date: Thu, 4 Oct 2001 15:20:52 -0700 Subject: Mutable default values for function parameters References: Message-ID: "Brian Quinlan" wrote in message news:mailman.1002222005.17547.python-list at python.org... > > I've used this idiom myself many times. I eventuallu decided > > it was shorter > > as > > > > def sample(x, d = None): > > d = d or [] > > d.append(x) > > print d > > > > but this looks so weird I'd appreciate confirmation that it's a > valid > > replacement. > > It is not a valid replacement because d can evaluate to zero for > values other than None e.g. > > sample(x, '') > sample(x, 0) > > Those should raise some sort of exception, not silently do the > default. > Actually, it is valid, within what we normally expect for validity. Why? The very next statement is "d.append(x)", which is only valid for lists or objects that export the proper methods for a mutable sequence. All the cases you mention are not mutable sequences, hence they are invalid input to the function. If we wanted to guard against invalid input, we should put in an assert statement, rather than simply letting the append fail. On the other hand, it will cause some otherwise invalid cases to succeed. John Roth From -$Paul$- at verence.demon.co.uk Wed Oct 10 06:14:12 2001 From: -$Paul$- at verence.demon.co.uk (Paul Wright) Date: 10 Oct 2001 11:14:12 +0100 Subject: Curious assignment behaviour References: Message-ID: <9q171k$4lq$1@verence.demon.co.uk> In article , Tim Peters wrote: >[Paul Rubin, on an expression assignment operator] >> Why on earth does it have to be different from the statement assignment >> operator? What's wrong with >> >> while x=get_next(): whatever(x) >> >> I just don't buy the rationale that using = instead of == is a big source >> of bugs. In 25 years of hacking C code, I think I've seen that error >> maybe once or twice. > >I suggest you're highly atypical here, Paul. This was the very first of the >gotchas listed in Andrew Koenig's classic (late 80s) "C Traps and Pitfalls", >and has made nearly every list of C "deadly sins" I've seen since then. >I've wasted weeks of my own life helping people track this error down in C, >too often under extreme time or customer pressure. The experience of the >other folks at PythonLabs is similar, so even if it's a disease you're >immune to, you can be sure this will never go in. If you're after some quantitative data, Les Hatton[0] lists faults where "control expression is an assignment" as occurring in 1:3306 lines of C code in his test population. The practice of doing assignment in control expressions is banned in safer subsets of C [1]. While I agree it can be annoying to have to write an extra line occasionally, I think that the benefits outweigh the costs. [0] Hatton, L, "Safer C: Developing Software for High-integrity and Safety-critical systems", McGraw-Hill 1994. [1] eg. The Motor Industry Software Reliability Association's C Guidelines, http://www.misra.org.uk/ -- ----- Paul Wright ------| "Their little anoraks bobbed and danced, their -paul.wright at pobox.com--| cycling helmets swung with gay abandon - the NatSci http://pobox.com/~pw201 | Elves were abroad!" -Simon Pick From logiplexsoftware at earthlink.net Tue Oct 2 16:34:10 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 2 Oct 2001 13:34:10 -0700 Subject: pickling types from pywintypes In-Reply-To: References: Message-ID: <0110021334100A.02289@logiplex1.logiplex.net> On Tuesday 02 October 2001 13:22, John S. Yates, Jr. wrote: > dopy is layered on [c]pickle. The problem I am having > is that the pywintypes do not seem to be pickleable: This seems to be a common problem with extensions (wxPython, PIL). > Is there a work around? It requires a bit more work, but I usually build a dictionary of attributes *about* the unpicklable object and use those to reconstruct it later. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From slinkp23 at yahoo.com Fri Oct 26 10:36:36 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Fri, 26 Oct 2001 14:36:36 GMT Subject: Conditional expressions (again) References: <3BD8C52A.53E97472@alcyone.com> <9rbh46$p95$1@thorium.cix.co.uk> Message-ID: On Fri, 26 Oct 2001 07:53:23 -0400, Steve Holden wrote: > wrote ... >> Erik Max Francis wrote: >> >> > Greg Ewing wrote: >> > >> > > Write that as >> > > >> > > x = ( >> > > b if a else >> > > d if c else >> > > e >> > > ) >> > > >> > > and it looks a lot clearer. >> > >> > Sure, but since conditional expressions are intended for brevity, you've >> > just made a five line nested conditional express. Why not just use an >> > if ... elif ... else statement instead? >> >> Compare >> >> order.append( >> spam if customer == michae1 else >> eggs if customer == john else >> cheese) >> >> with >> >> if customer == michael: >> side0rder = spam >> elif customer == john: >> sideOrder = eggs >> else: >> sideOrder = cheese >> order.append(sideOrder) >> >> in terms of how likely each error is to arise in testing, and how much >> time it would take to work out what was going wrong. I find that almost >> convincing ;-) You could always write a "conditional function" which has whatever interface you like. Properly tested, it should help prevent errors of that sort. But it doesn't short-circuit, which is the other argument in favor of conditional expressions. def cond(a, mapping, default=None): """Argument is a sequence of either pairs or single items. If single items, return the first item to match. If sequences, return the second element of the first item whose first element matches. If no matches, return default. Limitation: can't test sequences! """ for m in mapping: if type(m) in (type((None,)), type([])): if a == m[0]: return m[1] elif a == m: return a return default order = [] for customer in ('michael', 'john', 'ralph', 'eddie'): order.append(cond(customer,(('michael', 'spam'), ('john','eggs') ), 'cheese')) print order[-1] # prints: # spam # eggs # cheese # cheese limit = 3 print cond(limit, range(10), -1) # prints 3 print cond(limit, range(5,10), -1) # prints -1 From christy_girl99 at yahoo.com Sun Oct 28 01:13:57 2001 From: christy_girl99 at yahoo.com (christy johnson) Date: Sat, 27 Oct 2001 22:13:57 -0700 (PDT) Subject: binary search trees using classes Message-ID: <20011028051357.77421.qmail@web21108.mail.yahoo.com> Hi, I was wondering if anyone had a binary search tree module I could use? I need to write a program that counts the number of occurrences of each word in a file, and outputs the word and corresponding counts alphabetically. For example, if input is Have a nice day. Have a nice day. Have a nice day. Have a nice day. the output is a 4 day 4 have 4 nice 4 The code has to be modular based on classes. I'm thinking of making a tree node that looks like this bintree[ [key, data], left, right] , where I can traverse the tree by simply incrementing the current root to the appropriate child. temp = bintree.root temp = temp[1] #move to the left child. temp = temp[2] #move to the right child. but I don't know how to implement it correctly using classes. (i.e using def __init__(self), etc) I'm new to this python language so I would appreciate anyone's help. Thanks in advance :) Christy __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From max at alcyone.com Wed Oct 3 01:20:52 2001 From: max at alcyone.com (Erik Max Francis) Date: Tue, 02 Oct 2001 22:20:52 -0700 Subject: Python is better than free (was Re: GNU wars again) References: <1002040943.560.290.l9@yahoogroups.com> <5.1.0.14.2.20011002115026.02c780e8@cedar.he.net> <20011002235831.E25358@phd.pp.ru> Message-ID: <3BBAA034.7AB3531F@alcyone.com> Chris Watson wrote: > On Tuesday 02 October 2001 02:58 pm, Oleg Broytmann wrote: > > > This is exactly how the GPL works - it charges for my code. You > > can pay > > me money, or you can pay me by opening your code. > > Thats called extorsion. That is getting close to the silliest thing I've heard of. It's open source software. You play by the rules (the license), or you don't use it. It's hardly extortion to make you open source your own software if you choose to use mine, if I so wish it. After all, I could _not_ make the source available at all, and only let you use it under license if you pay me. Is that extortion? Calling putting a license on software that I'm making publicly available "extortion" is ludicrous. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ A wise man never loses anything if he have himself. \__/ Montaigne Maths reference / http://www.alcyone.com/max/reference/maths/ A mathematics reference. From skip at pobox.com Tue Oct 2 10:24:07 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 2 Oct 2001 09:24:07 -0500 Subject: XML Marshalling of objects In-Reply-To: References: Message-ID: <15289.52743.174453.769154@beluga.mojam.com> Peter> I'm wondering if there is a good way to marshal/unmarshal python Peter> objects to XML? ... Is xml-rpc the right way to go? Depends on what you want. If you use xmlrpclib.dumps you will be able to serialize many Python datatypes, but there are some caveats: 1. Tuples and lists both serialize to . 2. Serialization of classes and instances is not supported. That said, you should be able to use the code in xmlrpclib as the basis to create a better mapping between Python objects and XML. (Just be careful not to call it XML-RPC. You'll get reamed by the XML-RPC folks -- one folk in particular.) -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From quinn at yak.ugcs.caltech.edu Thu Oct 4 09:55:26 2001 From: quinn at yak.ugcs.caltech.edu (Quinn Dunkan) Date: 4 Oct 2001 08:55:26 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 4) Message-ID: <92A6DE5322C50424.DA4A8459C90838C8.8C1CC346DB1F382F@lp.airnews.net> QOTW: "[T]he increased productivity we achieve with Python means that there is often no need to hire any more developers after your first Pythonista ;)." Also, "I never cease to be amazed by how quickly ideas become reality using Python." More propaganda to air-drop into heathen kingdoms: http://groups.google.com/groups?threadm=4su7rt0fphqhvcrctnktgiejfobm6uhops%404ax.com The popular subject of interfaces and signature-oriented polymorphism comes up again. Essentially, the question is: When someone wants a "file-like object", how file-like should it be? Carl says (paraphrased) "as file-like as makes sense in this situation" and (not paraphrased) "the idea that we need to have one definitive definition for a file-like object (or any class of objects) is not that useful". Titus wants to know how to write library code which doesn't break when such expectations are violated. As is the custom with such discussions, eventually haskell comes up: http://groups.google.com/groups?threadm=9orb19%24ba6%241%40slb6.atl.mindspring.net In python, regexps are not the end-all be-all that they are in some other languages. Bruce has a simple question about parsing text, which turns into a discussion of the relative merits of scanf, regexps, and string methods. Duncan sums it up: "regexps are wonderful: in moderation" http://groups.google.com/groups?threadm=3BB16A50.BAE082FE%40cygnus-software.com Pre-2.2 python has an all or nothing attribute accessor scheme: either all attribute setting goes through __setattr__, or all attribute setting is direct. Dale wants to avoid the overhead by only checking certain attributes, which is not possible (unless you create a separate sub-object), but Tim points out that 2.2 allows readers and writers for individual attributes: http://groups.google.com/groups?threadm=9lajrtcqsojv72nr88c7j6kmdapjo44vc0%404ax.com Steve gives an ultra condensed tutorial on the ever-popular BSD sockets, as well as a link to Gordon's python socket tutorial. Others point out that higher level interfaces like urllib or (if you want to write a server) medusa are often more appropriate, but if you want to know the low level details: http://groups.google.com/groups?threadm=T8ku7.20537%24ib.310289%40atlpnn01.usenetserver.com Gordon's tutorial: http://www.mcmillan-inc.com/sock1.html PyDoc is cool. It's in the standard distribution, but it's easy to overlook these things: http://groups.google.com/groups?threadm=uramrt8s8k654eea7g46b62oe8474lj4ji%404ax.com ======================================================================== Everything 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 daily python url http://www.pythonware.com/daily comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continues Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week. http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect 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/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.de/oo_python.html Python FAQTS http://python.faqts.com/ 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://python.sourceforge.net/peps/pep-0042.html Python Journal is at work on its second issue http://www.pythonjournal.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python 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/topics/pythonurl/ 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 Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning, ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From tjreedy at home.com Thu Oct 4 18:46:42 2001 From: tjreedy at home.com (Terry Reedy) Date: Thu, 04 Oct 2001 22:46:42 GMT Subject: Mutable default values for function parameters References: <7da8d8f8.0110040056.42443bb@posting.google.com> <3BBCA084.B10B6061@alcyone.com> Message-ID: "Erik Max Francis" wrote in message news:3BBCA084.B10B6061 at alcyone.com... > sebastien wrote: > > I avoid this problem by simply never using a mutable object as a default > argument, but instead always using a sentinel value that's substituted > in the function body: > > def sample(x, d = None): > if d is None: > d = [] > d.append(x) > print d This does not work when you *want* the altered value to carry over from one invocation to the next, as was the case with both examples given by the original poster. The question was how to reinitialize 'd' (or whatever) when one wants to start over after several calls using saved values. Terry J. Reedy From pinard at iro.umontreal.ca Fri Oct 5 20:47:43 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 05 Oct 2001 20:47:43 -0400 Subject: Quaternions in Python In-Reply-To: References: Message-ID: [David Feustel] > Is there a Python module that does quaternion math? Hi, David. None that I know, but it might be not too difficult writing one, given you do not ask for too heavy computations. I mean: you could generalize some formulas (below) using integers up to reals using converging bounds, but this might require a lot of ccomputation. While David Gillespie was developing his nice `Calc' package, we corresponded a great deal on a lot of topics, and he chose to include some of our discussions in the documentation. The quote below comes from the "Examples of Rewrite Rules" in the Emacs Calc manual. Maybe this could help you at getting started quickly? If you do something about Python quaternions, please share your code! :-) ----------------------------------------------------------------------> The following rule set, contributed by Francois Pinard, implements "quaternions", a generalization of the concept of complex numbers. Quaternions have four components, and are here represented by function calls `quat(W, [X, Y, Z])' with "real part" W and the three "imaginary" parts collected into a vector. Various arithmetical operations on quaternions are supported. To use these rules, either add them to `EvalRules', or create a command based on `a r' for simplifying quaternion formulas. A convenient way to enter quaternions would be a command defined by a keyboard macro containing: `' quat($$$$, [$$$, $$, $]) '. [ quat(w, x, y, z) := quat(w, [x, y, z]), quat(w, [0, 0, 0]) := w, abs(quat(w, v)) := hypot(w, v), -quat(w, v) := quat(-w, -v), r + quat(w, v) := quat(r + w, v) :: real(r), r - quat(w, v) := quat(r - w, -v) :: real(r), quat(w1, v1) + quat(w2, v2) := quat(w1 + w2, v1 + v2), r * quat(w, v) := quat(r * w, r * v) :: real(r), plain(quat(w1, v1) * quat(w2, v2)) := quat(w1 * w2 - v1 * v2, w1 * v2 + w2 * v1 + cross(v1, v2)), quat(w1, v1) / r := quat(w1 / r, v1 / r) :: real(r), z / quat(w, v) := z * quatinv(quat(w, v)), quatinv(quat(w, v)) := quat(w, -v) / (w^2 + v^2), quatsqr(quat(w, v)) := quat(w^2 - v^2, 2 * w * v), quat(w, v)^k := quatsqr(quat(w, v)^(k / 2)) :: integer(k) :: k > 0 :: k % 2 = 0, quat(w, v)^k := quatsqr(quat(w, v)^((k - 1) / 2)) * quat(w, v) :: integer(k) :: k > 2, quat(w, v)^-k := quatinv(quat(w, v)^k) :: integer(k) :: k > 0 ] Quaternions, like matrices, have non-commutative multiplication. In other words, `q1 * q2 = q2 * q1' is not necessarily true if `q1' and `q2' are `quat' forms. The `quat*quat' rule above uses `plain' to prevent Calc from rearranging the product. It may also be wise to add the line `[quat(), matrix]' to the `Decls' matrix, to ensure that Calc's other algebraic operations will not rearrange a quaternion product. *Note Declarations::. These rules also accept a four-argument `quat' form, converting it to the preferred form in the first rule. If you would rather see results in the four-argument form, just append the two items `phase(2), quat(w, [x, y, z]) := quat(w, x, y, z)' to the end of the rule set. (But remember that multi-phase rule sets don't work in `EvalRules'.) ----------------------------------------------------------------------< -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From sholden at holdenweb.com Tue Oct 23 06:49:58 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 23 Oct 2001 06:49:58 -0400 Subject: unnecessary change References: <3BD5BCDF.B40C1422@gol.ge> Message-ID: <6UbB7.7681$Ub2.261294@atlpnn01.usenetserver.com> "Giorgi Lekishvili" wrote in message news:3BD5BCDF.B40C1422 at gol.ge... > Hi folks! > > My problem is the following: > I want to save initial data matrix, as e.g., follows > self.Mdata=Matr > In the same time I need a matrix, which is used and processed. The > latter is created as follows > self.Mactual=self.Mdata > > No the problem is, that, when I have finished to use the Mactual matrix, > self.Mdata is always changed and equals the final Mactual matrix. > > What is the systematic solution of the problem? > > Thanx in advance, > Giorgi > > PS. I use Numeric module. > This is because Python variable bindings are actually references. You probably need to make a copy of the matric. See if the copy module (and particularly copy.deepcopy()) will help. regards Steve -- http://www.holdenweb.com/ From leo at iems.nwu.edu Wed Oct 3 17:07:09 2001 From: leo at iems.nwu.edu (Leonardo B Lopes) Date: Wed, 03 Oct 2001 16:07:09 -0500 Subject: SQL/Python question -- slow... What is the fixed cost? Message-ID: <3BBB7DFD.25217E1A@iems.nwu.edu> Dear Friends, Is anyone here using Python with MySQL using the MySQLdb module? I have been using it for a while in a prototype, and now that I am trying to optimize it for speed I am running into problems. I was analyzing my queries, trying to find out if a different organization of my database might be warranted. I do lots and lots of queries, most of which are quite simple. The worst query involves an inner join of 3 tables and then a filtering on two clauses. I have been using varchar columns as indexes (I know! It was just a prototype), and as I am considering changing them, I am looking at the output of the python profiler, and I notice that all the queries take .001 cpu/sec. per call. Not only the more complex query above, but also a query which only filters over one small table. What I am wondering is what the fixed cost for this configuration: (python + MySQLdb + MySQL). I am about to design a sophisticated caching system, and before I do that, I was hoping someone with some experience with this setup would be able to tell me if it is worth my time... Any help would be appreciated. I can also share code if it helps. Thanks! Leo. a simple query that filters only one table based on only one parameter. That brings a question: Does anyone have an idea of what -- ======================================================================= Leonardo B. Lopes leo at iems.nwu.edu Ph.D. Student (847)491-8470 IEMS - Northwestern University http://www.iems.nwu.edu/~leo From paul at boddie.net Tue Oct 9 09:49:42 2001 From: paul at boddie.net (Paul Boddie) Date: 9 Oct 2001 06:49:42 -0700 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> <23891c90.0110082340.541e6993@posting.google.com> <7x4rp91bqh.fsf@ruckus.brouhaha.com> Message-ID: <23891c90.0110090549.6e14c7bc@posting.google.com> Paul Rubin wrote in message news:<7x4rp91bqh.fsf at ruckus.brouhaha.com>... > paul at boddie.net (Paul Boddie) writes: > > I would seriously doubt that any of the libraries distributed with > > Python are GPL licenced. Indeed, options such as the readline module > > remain just that: optional. So, there seems to have been an explicit > > policy of avoiding "GPL by stealth". > > That's a good policy--whatever license one uses, it should be stated > up front and not slipped in by stealth. Thankfully, though, the Python maintainers are aware of the issues - they would have to be given the Python licensing trials of the past year or so. People in charge of projects who are less aware of the issues might accept GPL code contributions without thinking carefully enough about it. > > However, there are a number of useful packages which have GPL > > licences. I was asked to update the Python Web modules page which I > > maintain some time ago with licence information, purely so that people > > could see which modules/frameworks weren't worth evaluating because of > > the licence, and there are a lot of them with GPL licences - it's > > quite surprising. > > I don't understand why it's surprising--the GPL is by far the most > common license on Sourceforge, so it's natural that Python module > licenses would follow the same pattern. It has been argued that many developers choose GPL because it is so well-known amongst open source developers and seems the "safest" choice. I have contributed to GPL projects, but I think it really depends on the nature of the project as to whether GPL really works in its favour; in one case, it's an emulator of a 1980s microcomputer, but the licence is (in my opinion) suitable because there isn't likely to be many "spin off" applications of that code, and it would be unfair on the principal developer and the other contributors to allow someone to copy it, bundle it up and sell it for profit - such an end-user application is much more susceptible to such freeloading than a Web framework, for example. [GPL dynamics] > Maybe for some but not others. I'm far more likely to volunteer to > contribute to a GPL'd project than a non-GPL'd one. I have nothing > against non-GPL'd programs, but if I'm going to do product development > for a closed source company, I expect to get paid for it. What interested me was the number of Web frameworks which are GPL licenced. For example, SkunkWeb is GPL licenced whereas Webware and Zope are not; some templating frameworks such as Wasp and Pyml are GPL licenced whereas others are not. I'm not going to second guess the rationale for such licencing amongst the maintainers of the various packages, but I can see a number of reasons for going either way: * Going GPL means that no-one is going to take your work, enhance it, and then keep those enhancements private, thus getting the benefits of your work while you don't get the benefits of theirs. However, people might be concerned about which code is covered by such a licence in certain frameworks - what constitutes enhancing the framework and what constitutes application code? Maintainers need to be explicit about the issues in a way that is clear to developers. * Going with a different licence means that developers may be less reluctant to use your work, but they could exploit you as described above. However, it becomes less likely, in my opinion, that as the community grows with a particular framework, people are going to add some exotic feature to that framework and keep it private, partly because the community around that framework is likely to provide a valuable source of advice, complementary enhancements and sanity checking, as well as being itself a source of wider deployment and therefore wider testing. Another issue (which applies to both kinds of licences, but particularly to the GPL) is whether employees of the corporate world are "allowed" to contribute code to open source projects, particularly when such code may never again be used to form the basis of a closed source product. I rather feel that a number of people who choose non-GPL licencing for their projects probably want to make money from their work without scaring potential customers away. Other contributors may be thinking more about what they themselves can gain by contributing rather than what the others are getting out of such contributions. Therefore, it's really a case of everyone adding to the value of the project and then making use of that combined value, rather than believing that they are working for others for nothing. Perhaps non-GPL projects really only entice "really interested" parties who either see revenue opportunities or academic fulfilment in participating in such projects. I don't think this is a bad thing at all. Paul P.S. And I haven't even considered issues such as why there are so many Python-in-HTML/HTML-in-Python modules around. Perhaps some licence investigation may reveal why this is. From db3l at fitlinxx.com Wed Oct 10 15:14:19 2001 From: db3l at fitlinxx.com (David Bolen) Date: 10 Oct 2001 15:14:19 -0400 Subject: Curious assignment behaviour References: Message-ID: "Tim Peters" writes: > [Paul Rubin, on an expression assignment operator] > > Why on earth does it have to be different from the statement assignment > > operator? What's wrong with > > > > while x=get_next(): whatever(x) > > > > I just don't buy the rationale that using = instead of == is a big source > > of bugs. In 25 years of hacking C code, I think I've seen that error > > maybe once or twice. > > I suggest you're highly atypical here, Paul. This was the very first of the > gotchas listed in Andrew Koenig's classic (late 80s) "C Traps and Pitfalls", > and has made nearly every list of C "deadly sins" I've seen since then. > I've wasted weeks of my own life helping people track this error down in C, > too often under extreme time or customer pressure. The experience of the > other folks at PythonLabs is similar, so even if it's a disease you're > immune to, you can be sure this will never go in. I've got to admit to being a big fan/user of assignment as an expression in my C code, so I also miss it in Python at times. But on the whole I think Python probably made the right choice, at least while "=" and "==" are the tokens in question. I know I've myself created this bug a lot more than once or twice in C code in my past 17 years or so, and have also seen it in many others code. Within my own code, the big difference over time has been being quicker to notice since I was aware of it, so it rarely did much damage outside of a debug run. But when first trying to diagnose foreign code it could take quite a while to isolate and waste a lot of time. > (...) > Oops! The assert turned out to be the perversely self-fulfilling: > > assert(i = 1); > > and multiple senior programmers with with many decades of industrial C > experience had stared at that multiple times without realizing the mistake. Yeah, it's almost wierd how easy it is to stare at an expression like this and simply not notice the problem. > It only takes one of those to sour you on the idea for life. Yeah, it's one of those points where being burned once can hurt more and waste more time than having the functionality available will help or save time even over a very long time. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From mlh at idi.ntnu.no Sat Oct 6 13:41:27 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 6 Oct 2001 19:41:27 +0200 Subject: Generic way of parsing into dom? Message-ID: <9pnfo8$ror$1@tyfon.itea.ntnu.no> I've been looking at the 4Suite module 4XPath, and noticed that in the tutorial the class Ft.Lib.pDomlette is used. I liked the fact that the xpath module was available as xml.xpath and found this name (the domlette thing) a bit ... Shall we say ... specific. OK - if you have the 4Thought 4Suite xpath module, you probably have Ft.Lib.pDomlette as well, but even so... So I started looking at the xml.dom module to find a more generic method of reading documents into a dom structure. Before I installed 4Suite, xml.dom had xml.dom.minidom as its default implementation, and afterwards it had 4DOM. Great. But why is there no default way of parsing this? Something that doesn't require a specific package to be installed, but which (e.g.) uses xml.sax to create an xml.dom object... Or something. (Or, I'm sure there is, and that I'm just being dim.) In the HOWTO, I found xml.dom.ext.reader.Sax.FromXmlStream but I assume that's tied to 4DOM... Or am I mistaken? Anyway, why isn't there simply a function xml.dom.parse (and probably xml.dom.parseString)? It just seems like a natural thing to me... If there is something similar somewhere that I've missed, then I'm sorry. Otherwise, would it be possible to add something like this? -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From theebh at yahoo.com Tue Oct 30 02:31:02 2001 From: theebh at yahoo.com (Firestar) Date: Mon, 29 Oct 2001 23:31:02 -0800 (PST) Subject: DOM4J, JDOM or Castor implementation in Python Message-ID: <20011030073102.6657.qmail@web13505.mail.yahoo.com> Just curious: are there any similar implementation for Java XML tools such as DOM4J, JDOM or Castor data-binding for Python? I find these tools very useful for XML processing in Java. Wonder whether there are similar projects going on for python, or do we just use Jython to 'access' them?;) TIA. regards, firestar __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From fredrik at pythonware.com Tue Oct 30 10:17:01 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Oct 2001 15:17:01 GMT Subject: os.system, backslash and commandline problem References: Message-ID: Sharriff.Aina at med-iq.de wrote: > I tried out a file that had "dangerous" characters: > c:\the\boy.txt ("\t" TAB, "\b" BELL) >>> print "c:\the\boy.txt" c: hoy.txt >>> print "c:\\the\\boy.txt" c:\the\boy.txt > This is very saddening, any clues? help? for more info, read up on "string literals" in your favourite Python book, e.g: http://www.python.org/doc/current/ref/strings.html From ykingma at accessforall.nl Mon Oct 29 13:53:32 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Mon, 29 Oct 2001 19:53:32 +0100 Subject: binary search trees using classes References: <3BDC5B9F.32246B75@accessforall.nl> Message-ID: <3BDDA5A9.58B8F82A@accessforall.nl> Grant Edwards wrote: > > In article <3BDC5B9F.32246B75 at accessforall.nl>, Ype Kingma wrote: > > >> I was wondering if anyone had a binary search tree module I > >> could use? I need to write a program that counts the number of > >> occurrences of each word in a file, and outputs the word and > >> corresponding counts alphabetically. For example, if input is > > > > You might consider an alternative: > > > > Counting words is better done using a dictionary. > > Coming up with the answer to a different/better question > doesn't usually result in high grades on homework problems. > I forgot to think of homework posts :). > > This will use hashing for lookups, which is normally faster > > than using a binary tree. > > Ah, but the whole point is to learn how binary trees work. > One might conclude that there are better problems to use binary trees on. But I can't think of any simple ones... Thanks, Ype From phr-n2001d at nightsong.com Sun Oct 14 20:25:54 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 14 Oct 2001 17:25:54 -0700 Subject: Python web client anyone? References: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> <7xn12tombq.fsf@ruckus.brouhaha.com> Message-ID: <7xu1x1px4d.fsf@ruckus.brouhaha.com> Richard Jones writes: > > Thanks, this appears to include an HTTP client, which is a start, but > > I was looking for something that actually parses the HTML on the > > retrieved page like LWP does. I wonder if there's some way to do that > > with the XML libraries (though HTML is generally not well-formed > > XML--for example it usually has unterminated

tags). Any > > thoughts? > > htmllib? > > If you want quick and simple DOM extraction, I have a module that extends > HTMLParser... Perl LWP is a module for easily writing robot web clients. It doesn't exactly make a DOM, but it's the same idea, so DOM extraction would be fine. What I *really* want is to be able to easily find link objects (anchor tags) based on the anchor text, which LWP for some reason doesn't do, but DOM extraction would be a start. By "anchor text" I mean the text in this is the anchor text. The client should be able to find some "underlined" text on the page it retrieves, and "click" on the linked document. I may not have read the htmllib docs carefuly enough but it looks more intended for formatting/displaying HTML than parsing it. Are your DOM extensions available? Thanks From just at letterror.com Sat Oct 20 06:58:58 2001 From: just at letterror.com (Just van Rossum) Date: Sat, 20 Oct 2001 12:58:58 +0200 Subject: struct module References: <3bd0f13e$0$27332$afc38c87@news.optusnet.com.au> <3bd10af8$0$27331$afc38c87@news.optusnet.com.au> Message-ID: <3BD158F1.26D61B88@letterror.com> Kalle Svensson wrote: > > [nobody] > > > H has a two-byte alignment requirement. There's one byte for the "B", > > then > > > it has to throw in a pad byte to get the correct word alignment for the > > > "H". > > > > How do I disable that? > > You don't. Sure you can, use one of these special format characters: = ! < > See http://www.python.org/doc/lib/module-struct.html for their exact meaning. Just From cliechti at gmx.net Wed Oct 3 15:53:32 2001 From: cliechti at gmx.net (Chris Liechti) Date: 3 Oct 2001 21:53:32 +0200 Subject: Possible to read/write Excel files in Python? References: Message-ID: [posted and mailed] Steven Sartorius wrote in news:B7E0DC17.2C61%ssartor at bellatlantic.net: > > Unfortunately I have no control over the spreadsheet format, I take it > as it comes. And on a Unix box I have no access to Excel. Maybe I > could rig something up in gnumeric, supposedly it's scriptable in > Python... > here is the perl version, just found on google: http://www-106.ibm.com/developerworks/linux/library/l-pexcel/ there is a unix/linux hosted solution described. maybe you can port it to python chris -- Chris From grante at visi.com Mon Oct 8 13:18:48 2001 From: grante at visi.com (Grant Edwards) Date: Mon, 08 Oct 2001 17:18:48 GMT Subject: safe simultaneous file append? References: <3np2st060vt841lqfimibi12909td1p02c@4ax.com> <9prtkc$56a$1@samos.cs.uu.nl> <1cv2st0g180m0cfoloqf99s5pofe4pmi32@4ax.com> Message-ID: In article <1cv2st0g180m0cfoloqf99s5pofe4pmi32 at 4ax.com>, Dale Strickland-Clark wrote: > Erk! There's a recipee for disaster unless treated very carefully. > Handy if you're careful, though, I guess. That pretty much sums up the Unix philosophy... -- Grant Edwards grante Yow! "THE LITTLE PINK at FLESH SISTERS," I saw them visi.com at th' FLUROESCENT BULB MAKERS CONVENTION... From grante at visi.com Wed Oct 31 14:49:28 2001 From: grante at visi.com (Grant Edwards) Date: Wed, 31 Oct 2001 19:49:28 GMT Subject: Running phyton on 50Mips RISC doable? References: <9rovil$fei$1@news1.xs4all.nl> Message-ID: In article , Chris Liechti wrote: >> I'm trying to figure out if I should use Python for my embedded >> application that needs some scripting. >> It is an application with 50Mips Risc processor, with little >> (and slow) memory. So when I want to run the python interpreter >> on this machine, will it be terrible slow? And more inportant: how >> mauch memory will I need? a few K? a few hondred K? >> Is it difficult to port the code such that it will run on this machine? >> (It uses gcc compiler) > > i have compiled python 2.1.1 on a PPC embedded with Linux (Kernel 2.4). it > runs fine on a 16MB/50Mhz board (compiling was done on a board with 64MB). > When my app runs, Python uses about 3MB of RAM. > Startup is a bit slow, but entering commands interactively is fine. There's also a "deeply embedded Python" which puts the VM on an embedded system with no OS. http://www.abo.fi/~iporres/python/ -- Grant Edwards grante Yow! Is this "BIKINI at BEACH"? visi.com From shriek at gmx.co.uk Tue Oct 23 09:29:14 2001 From: shriek at gmx.co.uk (Stephen) Date: 23 Oct 2001 06:29:14 -0700 Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> Message-ID: <97ae44ee.0110230529.5c33dd83@posting.google.com> > > I'm developing a catalog application (storing its data in a > > relational database), where catalog entries are categorized > > by one or more categories/subcategories. It would be nice to > > have "unlimited" levels of subcategories and that seemed > > simple enough ~ "Use a parent/child" I hear you say ~ and that's > > what I did but I've since found it's not very flexible further > > down the line. > > This is a database rather than Python question, but since you asked, > I'll answer from my database experience. Not so fast. From a database point of view, the table schema is relatively trivial. However, as soon as you start programming with "unlimited" categories/subcategories, you soon find you have to do multiple recursions. eg. In the example before, one would have to select all categories having "Africa" as a parent. Then select all categories that were subcategories of those categories with Africa as a parent. This is tiresome enough with just 3 levels of categorisation. Almost every application I've encountered requires categorisation of some sort so I figured it would be good to learn how to do this "properly" once and for all. I don't believe it's just a matter of SQL theory. > > Let me demonstrate with some example categories/subcategories > > which we place in a category tree, giving each node a unique ID. > > The root node is deemed to have node ID zero (0). > > > > Root -- 1. ByLocation --- 3. Africa --- 4. Mozambique > > --- 6. SouthAfrica > > --- 5. Europe --- 9. Portugal > > -- 2. BySeverity --- 7. Critical --- 8. Death > > --- 11. Handicap > > --- 10. Moderate--- > > Location and Severity are two separate variables that should be coded > completely separately from each other. Severity, if not numeric, is > usually an ordered series of categories, such as 1=mild, 2=moderate, > 3=handicap, 4=critical, 5=death. Coding three-level LOcation is more > complicated. Either > 1. Split it into three variables - continent, country, city, with > continent required and country and city optional -or- > 2. Encoded the levels into 'one' entry (which you split into pieces as > needed). You could try a separater-ed entry such as > continent-country-city (like internet address, windows registry, etc) > or positional-subfield encoded (like many product ids and library book > categorizers (as in either Dewey Decimal or Library of Congress > systems)). For instance, 0 = Africa, 10 = Mozanbique, 11=(capital > city), 20= Angola, 1000 = Europe, etc. In otherwords, 1000s = > continent, hundreds/tens = country, ones position = city. Thank you for the advice. The examples I provided of Location and Severity were just that though - examples. And who is to say how a user of your latest application will wish to categorize his data ? For example in Act! contact management application, you can assign multiple categories/subcategories to each contact. And the categories and subcategories seem to be unlimited. I was merely wondering how to build a Python application (be it web-based or with Tkinter) that utilizes such categorization. > > This structure can be stored in a single table of a database. > > > > Parent_ID Category_ID Category_Label > > 0 1 ByLocation > > 0 2 BySeverity > > 1 3 Africa > > 3 4 Mozambique > > 1 5 Europe > > 3 6 SouthAfrica > > 2 7 Critical > > 7 8 Death > > 5 9 Portugal > > etc > > Mixing two varriables like this is a mistake. How else to provide unlimited scalability ? > > So far so good. Cataloged items/illnesses record their > > categories in a one-to-many table. For example, an illness > > with categories "4" and "8" occurs in Mozambique and can > > result in death. > > > > This appears scalable. > > > > Likewise you can easily select all illnesses occuring in > > Portugal using a JOIN and filtering category ID "9". > > > > So what's the problem ? > > > > The problem arises if one asks "Which illnesses occur > > in Africa ?". First, one has to find all category IDs > > for which this is true. This may be easy for the example > > above but imagine if the category ("Africa") has a sub- > > -category for each and every country then further > > subcategorized by major cities. To find all possible > > categories, one would have to do a recursive select > > finding each subscategory with the appropriate "parent ID". > > This does not seem like a very efficient method. > > If location were coded with continent either a separate variable/field > or separate subfield, this query would be trivial, as it should be. But such an argument can be applied to each and every category, not just "continent", which implies that there is no such thing as the boilerplate "unlimited categories/subcategories" code; and that each application must be customized instead. Fortunately, a search on google http://www.google.com/searchq=programming+unlimited+categories+&btnG=Google+Search proves this not to be case with a multitude of applications (mainly in Perl) that offer "unlimited categories/subcategories". Thank you for the advice, Terry. Sorry if I'm being obstinate, but I think the problem is a little less simplistic than it first appears. Let's look at the everyday addressbook in Act! or Outlook ? How would you create unlimited levels of categorisation and unlimited numbers of subcategories ? Stephen. From fredrik at pythonware.com Tue Oct 30 14:24:39 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Oct 2001 19:24:39 GMT Subject: Programming Python by Mark Lutz 2nd Ed. References: Message-ID: rand0m wrote: > would like your opionion on this book. Read that it has been updated since > the Python 2 release. string.replace(message, "updated", "mostly rewritten") From DeepBlue at DeepBlue.org Wed Oct 17 13:20:29 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Wed, 17 Oct 2001 12:20:29 -0500 Subject: pure 16-bit DOS app References: <1003306634.200241@cswreg.cos.agilent.com> Message-ID: "Cameron Laird" wrote in message news:C6DA57BB5D095825.5CE2BB62B5E7F828.C267BE4C20A720B3 at lp.airnews.net... > In article , > Oleg Broytmann wrote: > >On Wed, Oct 17, 2001 at 10:17:12AM +0200, Michael Armbruster wrote: > >> I read many articles in the grup and the web, but till now I have not found > >> the real solution for my problem. > >> I would like to have a pure standalone DOS 16-bit app built out of > >> a python prog with inserted c-code but I don't know how to do this. > >> perhaps you could help me, > > > > Near to be impossible. 16bit DOS just doesn't have enough memory for > >Python. Can you use 32bit DOS (DOS Extender)? > . Cameron has given you a link that may go somewhere :) If you can get the sources, you may want to try working with RSXNT (port of EMX) or RSXNTDJ (port of DJGPP) for a friendly work under windows. I prefer the former. Both have RSX IDE and both can create either 32-bit DOS programs or windows programs. RSXNT can create dual mode programs. You can find these goodies at: http://www.mathematik.uni-bielefeld.de/~rainer/ DeepBlue (in Cobalt of course for a rich 3-d experience) > . > . > Sure it's possible, Oleg--for a sufficiently low value > of "Python". While I wonder what the questioner *really* > wants, he might start with 1.2: > > -- > > Cameron Laird > Business: http://www.Phaseit.net > Personal: http://starbase.neosoft.com/~claird/home.html From DeepBlue at DeepBlue.org Wed Oct 31 08:27:10 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Wed, 31 Oct 2001 07:27:10 -0600 Subject: How can I install win32all-140.exe over Python2.2? References: <76974d4a.0110310014.3effd408@posting.google.com> Message-ID: In my personal opinion, it is much recommended that you wait for Hammond's release that supports 2.2. DeepBlue "Valerie" wrote in message news:76974d4a.0110310014.3effd408 at posting.google.com... > Hi all! > > I've install a new Python 2.2 version and want to use win32all with > it. There is a win32all's version for Python 2.1, only. :-( > How can I decompress package to use some known utilities from > win32all? > Or I need to wait the better time... :-) > > Thank you. > > Regard, > Valerie Ivanov From ignacio at openservices.net Fri Oct 5 02:57:39 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 5 Oct 2001 02:57:39 -0400 (EDT) Subject: Boy do REs ever suck sometimes... In-Reply-To: <01100516514402.10490@ike> Message-ID: On Fri, 5 Oct 2001, Richard Jones wrote: > On Friday 05 October 2001 16:45, Ignacio Vazquez-Abrams wrote: > > Here's the problem I'm having with REs. When I use an RE like '^[0-9]+$' it > > matches both '123' and '123\n'. How can I get it to not match the string > > with the newline? > > Is this any help? > > >>> re.match('^[\d]+$', '123') > > >>> re.match('^[\d]+$', '123\n') > > >>> re.match('^[\d]+$', '123').end() > 3 > >>> re.match('^[\d]+$', '123\n').end() > 3 Unfortunately not, because I'd rather not have it match at all if there's a newline. I can special-case it in my code; I was just hoping that I wouldn't have to. -- Ignacio Vazquez-Abrams From hamish_lawson at yahoo.co.uk Mon Oct 1 05:17:50 2001 From: hamish_lawson at yahoo.co.uk (Hamish Lawson) Date: 1 Oct 2001 02:17:50 -0700 Subject: MySQLdb where's fetchoneDict()? References: <112484592256.20010930103925@buz.ch> <20010930113122.A5634@lilith.hqd-internal> <169491440664.20010930123333@buz.ch> <20010930144403.A562@lilith.hqd-internal> Message-ID: <915a998f.0110010117.361bfb0a@posting.google.com> Gerhard H?ring wrote: > > I'd probably subclass the cursor class to have the desired behaviour, i. > > e. a fetchoneDict() method that only uses stuff from the DB-API. That's > > not too difficult, it would only involve cursor.fetchone() and > > cursor.description. Then you'd need to subclass the Connection class to > > return an instance of your subclassed Cursor class instead. > > Ugh. In reality, this gets uglier than I thought. Which probably means > that the idea wasn't really that good. I'm not sure it needs to get too much more ugly. Recently I wanted to provide dictfetch* provides for ingmod, a module for interfacing to Ingres databases. For the sake of generality this is done with a DictCursor class that wraps *any* existing DB-API cursor object, adding the extra methods while delegating the others to the original cursor (as seen in DictCursor.py below). I then wrote an ingresdb module (also seen below) that wraps ingmod, but which uses DictCursor for its cursors. (ingresdb also provides a fetchall method, since this is not implemented in ingmod.) Hamish Lawson ===DictCursor.py=============================================================== def make_dict(keys, values): dict = {} for key, value in map(None, keys, values): dict[key] = value return dict class DictCursor: def __init__(self, cursor): self.cursor = cursor def execute(self, query, params=None): if params: self.cursor.execute(query, params) else: self.cursor.execute(query) self.columns = [col_desc[0] for col_desc in self.cursor.description] def dictfetchone(self): row = self.cursor.fetchone() return make_dict(self.columns, row) def dictfetchall(self): return [make_dict(self.columns, row) for row in self.cursor.fetchall()] def __getattr__(self, attr): return getattr(self.cursor, attr) ===ingresdb.py=============================================================== from ingmod import * import ingmod from DictCursor import DictCursor class Cursor: def __init__(self, cursor): self.cursor = cursor def fetchall(self): results = [] while 1: row = self.cursor.fetchone() if not row: break results.append(row) return results def __getattr__(self, attr): return getattr(self.cursor, attr) class Connection: def __init__(self, dsn, user=None): self.conn = ingmod.connect(dsn, None, user) def cursor(self): return DictCursor(Cursor(self.conn.cursor())) def __getattr__(self, attr): return getattr(self.conn, attr) def connect(dsn, user=None): return Connection(dsn, user) From logiplexsoftware at earthlink.net Tue Oct 2 18:59:45 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 2 Oct 2001 15:59:45 -0700 Subject: need design suggestions: local namespace problem In-Reply-To: <002701c14b93$00875770$b503a8c0@activestate.ca> References: <002701c14b93$00875770$b503a8c0@activestate.ca> Message-ID: <0110021559450B.02289@logiplex1.logiplex.net> On Tuesday 02 October 2001 15:38, Brian Quinlan wrote: > Why are you getting so fancy? Why can't you simply use: > > if running_under_qmail: > ERR_HARD = 100 > else: > ERR_HARD = 75 What if he needs to support another mail package? Go through 10,000 lines of code looking for every occurrence of running_under_qmail and add another condition? -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From pih at oek.dk Sat Oct 6 08:33:52 2001 From: pih at oek.dk (Peter I. Hansen) Date: Sat, 06 Oct 2001 14:33:52 +0200 Subject: python and HTML integration References: <3BBCB1F0.ED40594A@oek.dk> <23891c90.0110050219.4f7f51fa@posting.google.com> <3BBEF803.28D2088C@oek.dk> Message-ID: <3BBEFA2F.C7DD6B6A@oek.dk> "Peter I. Hansen" wrote: > Paul Boddie wrote: > > > I would recommend that anyone wanting a document template/production > > framework or a Web development environment look at the modules > > currently in existence and evaluate whether such modules are suitable > > before considering writing their own. To start with, take a look at... > > > > http://www.paul.boddie.net/Python/web_modules.html > > http://webware.sf.net/Papers/Templates/ > > > > There have been a lot of new HTML template/production modules released > > recently, but I wouldn't go and develop something new when there's > > something which is almost exactly what I want available from some > > server somewhere. > > > > Paul > > I've decided on using PyML, but do you have any experience i trying to install this ? I've followed the instruktions, but it dosn't seem > to interpret my embedded Python code... > > /Peter my mistake. Forget it. /Peter From piet at cs.uu.nl Mon Oct 8 06:02:52 2001 From: piet at cs.uu.nl (piet at cs.uu.nl) Date: 8 Oct 2001 10:02:52 GMT Subject: safe simultaneous file append? References: <3np2st060vt841lqfimibi12909td1p02c@4ax.com> Message-ID: <9prtkc$56a$1@samos.cs.uu.nl> >>>>> Dale Strickland-Clark (DS) writes: DS> Yes. You can't append to a file from two different places at once. You DS> have a few choices: In fact in modern Unixes you *CAN*. >From man fopen: Opening a file with append mode (a as the first character in the mode argument) causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to fseek(3S). If two separate processes open the same file for append, each process may write freely to the file without fear of destroying output being written by the other. The output from the two processes will be intermixed in the file in the order in which it is written. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From slinkp23 at yahoo.com Mon Oct 15 17:32:45 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Mon, 15 Oct 2001 21:32:45 GMT Subject: signum() not in math? References: Message-ID: On 15 Oct 2001 00:57:58 GMT, Andy Todd wrote: >slinkp23 at yahoo.com (Paul Winkler) wrote in >Why not have a look at the work Mark Pilgrim has done in Chapter 6 of >diveintopython (http://diveintopython.org/) This chapter on unit testing >includes a fully functioning roman to decimal and decimal to roman >converters, and they come with extensive unit tests. > >You could either use it as a basis for your function or get his permission >to post it to the cookbook. Thanks for the tip; I got a comment to much the same effect at ASPN. I've now looked at "Dive Into Python" - it's quite good! I've updated the recipe with some ideas from Mark's approach. --PW From phd at phd.pp.ru Tue Oct 2 16:01:52 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 3 Oct 2001 00:01:52 +0400 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <3bbbf697.12053562@127.0.0.1>; from root@127.0.0.1 on Tue, Oct 02, 2001 at 05:09:59PM +0000 References: <1002028115.395.70447.l7@yahoogroups.com> <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> <3bbbf697.12053562@127.0.0.1> Message-ID: <20011003000152.F25358@phd.pp.ru> On Tue, Oct 02, 2001 at 05:09:59PM +0000, Fish wrote: > > I see your point. You use other's people work without paying them. GNU > >GPL, at least, force you to pay (by publishing your code). You don't want > >to pay, and Python license makes you happy :( > > How very interesting. > > In other words, you support forced payment in terms of having to open one's > code to the public... but you don't support forced payment in terms of > forking over money for the right to use the code. > > So you don't want to pay cash, is what you're saying. Not exactly. I prefer to be paid by code, but if you want to pay cash, you are free (GPL philosophy is about freedom, after all!) to do it. You can pass me money, or you can buy support, or you can buy specially licensed version (of the same GPLed code). Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From gh_pythonlist at gmx.de Sat Oct 27 07:03:57 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 27 Oct 2001 13:03:57 +0200 Subject: Converting perl to python available? In-Reply-To: ; from wayne@tbnets.com on Fri, Oct 26, 2001 at 10:37:35PM -0400 References: Message-ID: <20011027130356.B576@lilith.hqd-internal> On Fri, Oct 26, 2001 at 10:37:35PM -0400, Wayne Ringling wrote: > I have a few programs that I would love to convert to python but don't want > to spend the time to recode them completly. import os os.system("myscript.pl") ;-) > Is there a project that is working on a conversion program yet? Seriously, has there ever been a translator from one language to another that did not produce an absolute mess? I imagine it will only work reasonably well for similiar languages, like Pascal -> Ada. But Perl and Python are very different. Perl regexes would have to be translated to Python library calls, for example ... What point would there be to having translated code that is a greater mess than the original Perl code ? Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From peoter_veliki at hotmail.com Mon Oct 29 10:49:14 2001 From: peoter_veliki at hotmail.com (Peoter Veliki) Date: Mon, 29 Oct 2001 07:49:14 -0800 Subject: setting the clipboard from python? Message-ID: I was told you can set the system clipboard within python somehow, is this true? What I have in mind is something like this: hello = 'Hello There!' os.setClipboard(hello) Thanks From loewis at informatik.hu-berlin.de Sun Oct 28 05:06:48 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 28 Oct 2001 11:06:48 +0100 Subject: Win32 Dll Extention Module Problem References: Message-ID: "Jeffrey Drake" writes: > The only problem I can think of is the data conversion. Using a debugger, can you determine how far it got? My guess would be that InitializeFlatSB does a blocking call, or that it was passed an invalid argument and did not correctly determine this problem. > "i" is the closest or "l" that is listed to be able to convert the HWND. > HWND natively is a void* i believe. You should only use the designated types for ParseTuple; in this case, it would be "int". Add another int variable; int iwnd; if(!PyArg_ParseTuple(args, "i", &iwnd))return NULL; hwnd = iwnd; Regards, Martin From Randy.L.Kemp at motorola.com Tue Oct 16 12:12:21 2001 From: Randy.L.Kemp at motorola.com (Kemp Randy-W18971) Date: Tue, 16 Oct 2001 11:12:21 -0500 Subject: Python, Unix sendmail, and multiple recipients Message-ID: <81F59ACE9063D511A5BB0002B328D226511597@il93exm20.css.mot.com> Thanks to everyone for the quick responses. As soon as I emailed the question, I got two answers from the Python community in under five minutes. If only the other lists I subscribe to were so prompt! From lenpfe at fastol.com Sat Oct 6 00:47:21 2001 From: lenpfe at fastol.com (Lenny) Date: 5 Oct 2001 21:47:21 -0700 Subject: Newbie question about running scripts Message-ID: I have just begun reading and experimenting with the tutorials from the python website. I have programmed years ago with BASIC and COBOL, so I am not completely in the dark. The problem I am having is related to how scripts are handled by the interpretor. The tutorial says that I must set up the PATH in the registry but does not tell me how. I looked in the registry and it appears that the install of Python 2.2 took care of this for me. I saved a script that I wrote, using wordpad, as a .py file and it saved it with no problem. The tutorial then said to go to the Windows command prompt. I am assuming this means the RUN function from the Start button options. When I type "python filename.py" in the RUN box and hit OK, I see a black box pop up on the screen for a fraction of a second. Not even long enough for me to read what it says. My questions are: 1.) Do I have to save my scripts to a certain folder that Python created for me or one I make for them? 2.) Do I have to change something in the registry about the PATH even though Python appears to have a Python Path entry already in the memory? 3.) Is the RUN window the window they mean as the "Command Prompt Window"? I hate to bother everyone in this group with my trivial questions but I am looking forward to learn more about this language but I feel as though I am at a road block in my learning. Does anyone suggest a certain online tutorial or other learning method. Thank you very much for taking the time to read my questions. I greatly appreciate your help and cooperation with this matter. Thank You, Lenny From chrishbarker at home.net Tue Oct 23 12:22:05 2001 From: chrishbarker at home.net (Chris Barker) Date: Tue, 23 Oct 2001 09:22:05 -0700 Subject: Array of 2^n References: <9qvbat$kak$1@news-int.gatech.edu> <200110230947.f9N9lQR11603@lap1.mtg.at> Message-ID: <3BD5992D.35987B0E@home.net> Skip Montanaro wrote: > > Andreas> Well, at least for python 2.0 (SuSE 7.2) this way [list > Andreas> comprehensions] is also about 25% slower than map/lambda... > Andreas> Has it been sped up in later versions? > > Not significantly. List comprehensions are byte compiled to almost the same > code that you would get with the obvious for loop translation. Map(), on > the other hand, is a function, so it gets compiled to a function call > opcode. That means the loop machinery runs in C instead of in the Python > virtual machine. We had a fairly long discussion about this here a month or so ago, and I, for one, am sad about this fact. I understand that compiling a list comprehension to a set of for loops is easy to do and easy to explain, but it unfortunately makes it impossible to later re-wriote the internals to get the perfomance advantages of map(), without potentially breaking code. The difference is that both the expression and the input lists can be altered in the middle of the looping. We never did get an answer to the question of whether the full dynamisicm of for loops being allowed in list comprehensions was a design decision or the result of an implimentation decision, but I suppose it's too late now to change it anyway. It would make me feel better if I knew that Guido et al. thought it was an important attribute of the design. -Chris > The Python disassembler is instructive here, and so simple to use, everyone > ought to be familiar with it, even if just to answer these sorts of > questions. Cool. Thanks for the tutorial. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From thecalm at NOSPAM.btinternet.com Sun Oct 7 10:14:54 2001 From: thecalm at NOSPAM.btinternet.com (G. Willoughby) Date: Sun, 7 Oct 2001 15:14:54 +0100 Subject: Tkinter PhotoImage Class??? References: <9pinf8$p3i$1@uranium.btinternet.com> Message-ID: <9ppnu2$dun$1@uranium.btinternet.com> Sorted it with this :) : [snip] import Image import ImageTk self.currentImage=Image.open(self.imageName) self.currentPhotoImage=ImageTk.PhotoImage(self.currentImage) self.canvasObject.create_image(0, 0, image=self.currentPhotoImage, anchor=NW) [/snip] "G. Willoughby" wrote in message news:9pinf8$p3i$1 at uranium.btinternet.com... > Has anyone got a piece of code to explain to me how to use the Tkinter > PhotoImage Class to display a .jpg inside a Tkinter Canvas object? The > Tkinter docs are not finished. > Thanks, > G. Willoughby. > > From loewis at informatik.hu-berlin.de Sun Oct 28 05:01:30 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 28 Oct 2001 11:01:30 +0100 Subject: Problem using Random References: <87elno5r1t.fsf@toadmail.com> <3BDB921E.FA7390EF@engcorp.com> Message-ID: "Terry Reedy" writes: > Removing items from near the front of a long list takes time. *If* > this matters, the following should be faster (when > translated to Python): My recommendation would be mylist = ['a','b','c','d','e','f'] random.shuffle(mylist) for i in mylist: print i Regards, Martin From duncan at NOSPAMrcp.co.uk Tue Oct 2 04:07:19 2001 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 2 Oct 2001 08:07:19 +0000 (UTC) Subject: sameness/identity References: <1001876090.367103@cswreg.cos.agilent.com> Message-ID: weeks at vitus.scs.agilent.com (Greg Weeks) wrote in news:1001876090.367103 at cswreg.cos.agilent.com: > Consider: > > x = 6.02 > y = 6.02 > > Are x and y identical? They are identical as *numbers* (which I'll call > conceptual identity) but not as Python *implentations* of numbers (since > id(x) != id(y)). Just to correct you on one thing. If you put your two assignments to x and y into a module or a script then you will find id(x)==id(y). It is only if you type the assignments into interactive mode (or different modules, or the results of calculations), that they will be different. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From logiplexsoftware at earthlink.net Fri Oct 19 12:36:26 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 19 Oct 2001 09:36:26 -0700 Subject: Traceback oddity In-Reply-To: <74e0tt8uc6bl7dh86mpe1dp218gbb2stfu@4ax.com> References: <3BD025A3.D0724FFC@pallas.com> <74e0tt8uc6bl7dh86mpe1dp218gbb2stfu@4ax.com> Message-ID: <01101909362601.02796@logiplex1.logiplex.net> On Friday 19 October 2001 07:38, Dale Strickland-Clark wrote: > (FWIW, Windows handling of filename case is exactly as I would like > it. The Un*x insistent that I remember the case of files is a right > PITA.) Yes, it's often difficult for me to remember to write "Cliff" rather than "cLifF". -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From xxxx at nisus.com Wed Oct 3 22:52:42 2001 From: xxxx at nisus.com (xxxx) Date: Wed, 03 Oct 2001 19:52:42 -0700 Subject: Python is better than free (was Re: GNU wars again) References: <1002040943.560.290.l9@yahoogroups.com> <20011002235831.E25358@phd.pp.ru> <200110030239.f932ddT02254@smtp.skyenet.net> Message-ID: <3BBBCEF9.BF7B5B16@nisus.com> > Cliff Wells wrote: >> On Tuesday 2001-10-02 18:49, Chris Watson wrote: >> Thats called extorsion. > No, extortion is when I demand your code at gunpoint or by threatening to > reveal that you subscribe to the Visual Basic mailing list as well. Or when the robber says, "We're from the IRS or the state tax board and we'll bull-doze your house and seize all your financial accounts if you don't pay up 'voluntarily'." From usenet at jeffjohnson.net Fri Oct 26 10:47:00 2001 From: usenet at jeffjohnson.net (Jeff Johnson) Date: 26 Oct 2001 07:47:00 -0700 Subject: write to closed console fails on FreeBSD but not Linux? Message-ID: I'm running a Python program as a daemon on FreeBSD 4.3 and Python 2.1.1. It was crashing just after I would close the console because printing to sys.stdout after the console was closed produced IO errors. I found a few solutions from other usenet posts, I chose to set sys.stdout and sys.stderr to a file-like class that doesn't write to anything. What puzzles me is why Mandrake (8.1 I think, and probably any linux) doesn't raise exceptions when printing to stdout after the console is closed. Is this a problem with Python or just a difference in the two OS's? If possible and it makes sense, it would be great if Python did not raise exceptions from print statements on any OS. -Jeff From greg at cosc.canterbury.ac.nz Wed Oct 17 20:57:44 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 18 Oct 2001 13:57:44 +1300 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> <9qhvq5$29ik$1@nntp6.u.washington.edu> <23891c90.0110170317.1e18fae5@posting.google.com> Message-ID: <3BCE2908.9B632B09@cosc.canterbury.ac.nz> John Roth wrote: > > "Paul Boddie" wrote in message > news:23891c90.0110170317.1e18fae5 at posting.google.com... > > > > It seems to me, from code I've seen and written, that the C- and > > Java-style ... ? ... : ... construct is most frequently used in cases > > where one is testing for NULL (or null) > > Many instances of this are already handled by the short-circuit > 'and' and 'or' operators. These operators have well-known > deficiencies... Maybe we could do with an operator like 'or' except that it compares its first operand with None instead of just testing it for trueness. I suggest x else y or, if you want to keep 'else' for a possible future reconsideration of if-then-else and don't mind a new keyword, x otherwise y -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From com-nospam at ccraig.org Mon Oct 22 08:31:48 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 22 Oct 2001 08:31:48 -0400 Subject: Random from Dictionary In-Reply-To: References: Message-ID: Martin von Loewis writes: > "Tim Peters" writes: > > > Season to taste. In 2.2 you could use a more memory-efficient scheme via > > iterating over d directly: > > > > def random_from_dict(d, x): > > "Return and remove x random (k, v) pairs from d." > > from random import random > > n = float(len(d)) # float() so x/n later doesn't truncate to 0 > > if not 1 <= x <= n: > > raise ValueError("go away") > > result = [] > > for k in d: > > # Choose this item with probability x/n. > > if random() <= x/n: > > result.append((k, d[k])) > > x -= 1 > > if x == 0: > > break > > n -= 1 > > for k, v in result: > > del d[k] > > return result > > Does that give each key in the dictionary the same probability of > being picked (assuming random() distributes uniformly)? Sort of. Item i has a x/n probability of being picked. If picked item i+1 has a (x-1)/(n-1) probability of being picked else item i+1 has a x/(n-1) probability of being picked thus the total probability of item i+1 being picked is (x/n)*(x-1)/(n-1)+(1-(x/n))*x/(n-1) (x^2-x)/(n^2-n)+(x-(x^2/n))/(n-1) (x^2-x)/(n^2-n)+(xn-x^2)/(n^2-n) (x^2-x^2-x+xn)/(n^2-n) (xn-x)/(n^2-n) x(n-1)/n(n-1) x/n But having proved that you are only letting me assume that random() is uniform. There is some rounding error in the floats that will make the above proof not quite true. Though if you are that sensitive to non-uniformity perhaps you should rethink the problem. (You can't avoid this, of course. Presuming it were uniform, random() would produce one of 2**52 floats, which can't be distributed uniformly across a set of 5 elements...) -- Christopher A. Craig From s.keim at laposte.net Wed Oct 24 05:28:56 2001 From: s.keim at laposte.net (sebastien) Date: 24 Oct 2001 02:28:56 -0700 Subject: Few questions about new features in Python 2.2 References: Message-ID: <7da8d8f8.0110240128.399cdf8e@posting.google.com> Thank's for your responses. I should have found all of theim myself :-( More ironically I've said that: - My computer should be able to potentialy save the state of all the universe. (If someone has a recipe for that, I'm interested) - Immutables types should accept side effect methods (Bacward incompatibilities should be very marginal after all...) - 5.4 // 2.0 should equal 2.7 (oh yes that's so usefull!) Well, probably not a good day for my brain ;-) I've really underestimated the generality of theses concepts. From lucio at movilogic.com Wed Oct 31 13:36:22 2001 From: lucio at movilogic.com (Lucio Torre) Date: Wed, 31 Oct 2001 15:36:22 -0300 Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <3BE01E8F.3A384D4C@alcyone.com> <3BE038B5.6AFA6BFB@alcyone.com> <20011031210158.V21151@phd.pp.ru> Message-ID: <3BE044A6.4020100@movilogic.com> Oleg Broytmann wrote: >On Wed, Oct 31, 2001 at 09:45:25AM -0800, Erik Max Francis wrote: > >>You said you didn't want to start another GNU flamewar. But what do you >>think you're doing? >> > > Trying to stop you arguing :) > >Oleg. > yada yada yada!!!! just my 2c. From bh at intevation.de Mon Oct 15 06:27:04 2001 From: bh at intevation.de (Bernhard Herzog) Date: 15 Oct 2001 12:27:04 +0200 Subject: SVG and Python? References: <3BCA9747.2F8C9462@sbc.su.se> <87r8s58h8r.fsf@lisboa.ifm.uni-kiel.de> Message-ID: <6qelo5qjuv.fsf@abnoba.intevation.de> Janko Hauser writes: > Look for sketch > http://sketch.sourceforge.net/ > > It can read and write SVG files, although I'm not sure if all things > of the spec are possible. Sketch's SVG support is quite incomplete, unfortunately. There are still some things missing that Sketch could handle and there are some that Sketch can't support properly yet such as transparancy. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://mapit.de/ From martin.franklin at westgeo.com Mon Oct 29 03:26:39 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Mon, 29 Oct 2001 08:26:39 +0000 Subject: Nicer Tkinter on UNIX? References: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> <86DF15C112AF36D6.332DEDD523A2210C.F8DE5222D8EF2836@lp.airnews.net> <3bd985b7.5963368@nntp.ix.netcom.com> Message-ID: <9rj3po$13qe$1@mail1.wg.waii.com> Mike Clarkson wrote: >>>> >>>>I like Tkinter because it's standard. But there is a big but. >>>>While on Windows it looks great, on unices it makes kids laugh. >>>>Not that it's particularly ugly, but quite awkward and not up to the >>>>aesthetic standards people expect now. --- snip lots and lots of good stuff --- I too don't like the 'look' of Tk on unix so here is what I do. def change_theme(parent): font='Fixed' # all text (Label, Button, Listbox.... bg='grey88' # all backgrounds (Frame, Button etc) tbg='white' # Text backgrounds (Entry, Listbox,Text) fg='black' # All foreground text sbg='navy' # selected background sfg='white' # selected foreground abg='grey77' # active background afg='black' # active foreground # all widgets parent.option_add('*background', bg) parent.option_add('*foreground', fg) parent.option_add('*activeBackground', abg) parent.option_add('*activeForeground', afg) parent.option_add('*selectBackground', sbg) parent.option_add('*selectForeground', sfg) parent.option_add('*font', font) # Listbox widget parent.option_add('*Listbox.background', tbg) # Text widget parent.option_add('*Text.background', tbg) # Entry widget parent.option_add('*Entry.background', tbg) # Canvas widget parent.option_add('*Canvas.background', tbg) I just call it with the Tk root window as the only argument..... HTH Martin. From xxxx at nisus.com Thu Oct 4 17:41:36 2001 From: xxxx at nisus.com (xxxx) Date: Thu, 04 Oct 2001 14:41:36 -0700 Subject: install on MacOS X 10.1? References: <3BBBC870.D0AE585E@nisus.com> <3BBBD62C.BD9FD419@nisus.com> Message-ID: <3BBCD790.5902743@nisus.com> > Richard Jones wrote: >> On Thursday 2001-10-04 13:23, xxxx wrote: >>> xxxx wrote: >>> I down-laoded 2.1.1 >>> In the Makefile I found this suggested sequence >>> # ./configure >>> # make >>> # make test >>> # make install >>> >>> In the README it says >>> Mac OS X 10.0: Run configure with "OPT='-no-cpp-precomp' ./configure >>> --with-suffix=.exe --with-dyld". > The link I put in my other e-mail had a discussion about just the error > you're encountering. Here it is again:... > solution: > http://lists.zope.org/pipermail/zope-dev/2001-October/013439.html >+ Jens Vagelpohl wrote: >+ LDSHARED= $(CC) $(LDFLAGS) -bundle -flat_namespace -undefined suppress >+ BLDSHARED= $(CC) $(LDFLAGS) -bundle -flat_namespace -undefined suppress >+ >+ notice the "-flat_namespace" switch, this gets rid of the new >+ default "twolevel_namespace" that complains about "undefined >+ warning". I had just found this among the ReleaseNotes/TwoLevelNamespaces.html but am glad someone else figured out how it must be applied in this context: You can use the -flat_namespace linker option to force the linker to build flat namespace executables. In Project Builder, add -flat_namespace to the OTHER_LDFLAGS Build Setting. But yet, when running make test test_pow test_pty test test_pty skipped -- No module named FCNTL test_pwd test_pyexpat test test_pyexpat skipped -- cannot import name expat test_re make: *** [test] Segmentation fault From asencio at mitre.org Mon Oct 29 16:34:38 2001 From: asencio at mitre.org (Angel Asencio) Date: Mon, 29 Oct 2001 16:34:38 -0500 Subject: BOA GUI builder? References: <3BD9CC09.2B1AB020@mitre.org> <3BDC909B.4F500B9C@mitre.org> <3BDDA284.B564E2CB@mitre.org> Message-ID: <3BDDCB6D.8C66C93B@mitre.org> Did it, and up to now works like a charm. Thanks! Tim H wrote: > Search boa.py for "2.3.0" > > Should be a line like this: > if (wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER) != (2, 3, 0): > > change the 0 to a one: > if (wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER) != (2, 3, 1): > > and away you go. This has caused me no problems, for consistency you may > want a few lines down, too, one like this: > raise 'wxPython 2.3.0 required' > > good luck, > Tim H > > "Angel Asencio" wrote in message > news:3BDDA284.B564E2CB at mitre.org... > > Thanks, it worked! > > > > Btw. For WinCVS users, be sure you do not have a carrige return at the end > of > > the command. "\n" > > > > Ok, someone told me that to be able to use boa v0.0.13 with wxPython > 2.3.1 I > > had to do some modifications. I checked on source forge, and I could not > find > > any patch related to this. > > Could someone post the changes or a place to get the patch for v0.0.13 to > be > > able to work with wxPython 2.3.1? > > > > Thanks. > > > > Paolo Invernizzi wrote: > > > > > The "module" name is "boa"... > > > Probably you can have a closer look using the "browse cvs" link on > project > > > page... > > > Cheer > > > > > > Paolo Invernizzi > > > > > > "Angel Asencio" wrote in message > > > news:3BDC909B.4F500B9C at mitre.org... > > > > I went to the boa sourceforge site, and although I could find rhw CVS > > > files > > > > listed, I could not find a module name to dowload through CVS, nor a > link > > > to > > > > download all the files related to V0.0.13. > > > > > > > > What am I missing? > > > > > > > > Thanks. > > > > > > > > Tim H wrote: > > > > > > > > > The version in CVS is much further along (0.0.13). You might want > to > > > try > > > > > that. It works for me. You do have to modify it slightly, it is > > > looking > > > > > for wxPython 2.30 and we are both using 2.3.1, but if you got BOA > 0.0.5 > > > to > > > > > work you should have no probs with that. > > > > > > > > > > Tim H > > > > > "Angel Asencio" wrote in message > > > > > news:3BD9CC09.2B1AB020 at mitre.org... > > > > > Greetings: > > > > > I got the BOA Python IDE from > http://boa-constructor.sourceforge.net/. > > > > > I looks great, but when I went to save the WxFrame.py from the > tutorial, > > > it > > > > > gave me a Win2000 error, but I ignored it. > > > > > Then when I went to save WxApp.py it crashed. > > > > > I have Win2000, BOA 0.0.5, wxPython 2.3.1 and Python 2.1 > > > > > Do I need to get some patch to stabilize BOA? > > > > > Thanks, > > > > > -- > > > > > -Angel > > > > > > -------------- next part -------------- A non-text attachment was scrubbed... Name: asencio.vcf Type: text/x-vcard Size: 337 bytes Desc: Card for Angel Asencio URL: From max at alcyone.com Sat Oct 6 15:32:41 2001 From: max at alcyone.com (Erik Max Francis) Date: Sat, 06 Oct 2001 12:32:41 -0700 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> <3BBE6A57.FD354FE3@alcyone.com> <7xlmipcji1.fsf@ruckus.brouhaha.com> <3BBEB99A.A1F0F9D7@alcyone.com> Message-ID: <3BBF5C59.33605BD@alcyone.com> Johann Hibschman wrote: > > >>>>> "Erik" == Erik Max Francis writes: > > Erik> You're missing the point. Quaternions can behave > Erik> qualitatively differently from their corresponding matrices. > > Eh? Say you have the Pauli spin matrices (complex 2x2 matrices), how > on earth do those behave qualitatively different from quaternions? As > far as I can tell, they *are* quaternions. That's perfectly valid, but I don't think it's what the poster I responded to meant. He meant encoding the transform represented by the quarternion into a matrix. As I and others have pointed out, that presents problems, because matrices for transformations are more fragile than quarternions in some areas. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ But since when can wounded eyes see / If we weren't who we were \__/ Joi Official Omega page / http://www.alcyone.com/max/projects/omega/ The official distribution page for the popular Roguelike, Omega. From huaiyu at gauss.almadan.ibm.com Wed Oct 24 21:17:31 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 25 Oct 2001 01:17:31 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> <9r5h75$1m5$1@slb6.atl.mindspring.net> Message-ID: On Wed, 24 Oct 2001 20:11:31 GMT, William Tanksley wrote: > >I'm confused -- I don't see how your version can work either. Both of you >are iterating over an empty list, and the only code which could possibly >add anything to the list is inside the iteration; that list is empty no >matter what, so nothing will execute, and the list will never be anything >but empty. That's what that 'else' is for - and that's the whole point of this thread. I have a suspicion that the usage of for-else in Python is not well known to many discussants in this thread. The equivalent code is (note the duplication of primes.append(n)): def getprimes(x): primes = [] for n in range(2, x): for p in primes: if p*p > n: primes.append(n); break elif n % p == 0: break else: primes.append(n) return primes Try it and see how it works. >I don't like your "for x in list while y" construct, either. It's >terrificly ambiguous: does it mean that every item in the list which meets >the 'y' criterion will be processed, or does it loop over all the items up >to the first one which fails to satisfy 'y'? So let me explain this in detail and hope I don't need to do it again. The pseudo code was: def getprimes(x): primes = [] for n in range(2, x): for p in primes while p*p < n: if n % p == 0: break else: primes.append(n) return primes The 'for p' loop will exit under three conditions: - p reaches end of primes: jump to (A) - not p*p < n: jump to (A) - n % p == 0: jump to (B) where (A) primes.append(n) (B) pass The juicy part of the code is: for p in primes while p*p < n: if n % p == 0: break else: primes.append(n) Here is a translation into as much verbage as possible: loop p through primes, until either the end of primes, or p*p is too large, at that point we consider the loop as exhausted. If in the middle of the loop we found p is a factor of n, then n is not a prime. End of the story. However, if we have exhausted the loop without finding a factor, then p is a prime, and it should be recorded in the list of primes. Note that the two different conditions corresponding to (A) are both considered intuitively as "exhausted all the candidate factors". So the question is: is there a way to write the idea that two of the exits go to the same follow-up code (A) without actually duplicating the code in (A), or using a temporary variable to hold the state information? I have not found a positive answer (which is not the same as claiming it does not exist). Why does this matter at all? To generalize this example, many loops appears to have these two semantically different exits - normal exits (like (A) above): intuitively it means the end of the loop is reached, or all possible candidates are exhausted. - abnormal exits (like (B) above): intuitively it means some specific condition is met inside the loop so there is no need to examine remaining candidates. In Python, the abnormal exits are always spelt as if condition: break Therefore, if there is any code that's needed at this point, it can be done with if condition: do_something break On the other hand, The Python structures while-else and for-else are designed to handle the normal exits. for ...: ... else: do things required at normal exit Ditto for the while-loop. Therefore, if we change both exit conditions into an if-break, the differences will be lost, and we cannot use the "else" clause. When Andrew translated the pseudo code mechanically, he changed the "while" condition into if-break and moved the code in the "else" there, but it did not help that the original "else" also takes care of the exits due to the end of the for-loop itself. I hope this clarifies what I meant when I said that the issue really appears to be the existence of two types of exits of loops. Of course, all of these could be easily done by using an auxiliary variable found_factor which is set to true or false before different breaks, and using an "if found_factor" after the loop. But I found the pseudocode clearer, as long as one makes the mental distinction between "exiting due to exhausting of candidates" and "exiting due to a special condition being met". It would be convenient if Python allows such pseudocodes to be real codes. Is this convenience worth a syntax change? It really depends on how much the change is needed. Considering all the issues discussed, I have not found a change that has a high enough benefit/cost ratio, so I am not pushing for any of them now. In any case, a syntax that removes the benefit of existing for-else and while-else structures would look quite a retrogress to me. >>Does the above count as an example? Can you see that the problem with the >>simple mechanical translation is that it does not handle properly the two >>different kinds of exits? > >>Hint: There are three exits in the 'for p' loop. Two of them should lead to >>the same follow-up code, the other leading to a different follow-up code. >>Finding them out is left as an exercise to the reader. :-) > >I don't see any followup code in any case -- the loop is simple and >direct. You entire function is one big loop which runs /n/ times, but >inside that is another loop which runs 0 times. There's no code outside >of the loops. I hope you can see it now. Anyway, I don't think I can do it any better than this, so I'll just leave it here. Huaiyu From michael_armbruster at eu.exch.agilent.com Wed Oct 17 04:37:41 2001 From: michael_armbruster at eu.exch.agilent.com (Michael Armbruster) Date: Wed, 17 Oct 2001 10:37:41 +0200 Subject: re Message-ID: <1003307863.306456@cswreg.cos.agilent.com> Hi Oleg, could you please tell me, what I would have to do with the dos extender. My aim is to boot pc with dos by FD. Then I have to execute the built standalone app. Could you imagine that this would be possible with the DOS extender? Mike -----Original Message----- From: Oleg Broytmann [mailto:phd at phd.pp.ru] Sent: Wednesday, October 17, 2001 10:26 AM To: Michael Armbruster Cc: python-list at python.org Subject: Re: pure 16-bit DOS app On Wed, Oct 17, 2001 at 10:17:12AM +0200, Michael Armbruster wrote: > I read many articles in the grup and the web, but till now I have not found > the real solution for my problem. > I would like to have a pure standalone DOS 16-bit app built out of > a python prog with inserted c-code but I don't know how to do this. > perhaps you could help me, Near to be impossible. 16bit DOS just doesn't have enough memory for Python. Can you use 32bit DOS (DOS Extender)? Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From michael at rcp.co.uk Fri Oct 26 03:00:39 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Fri, 26 Oct 2001 07:00:39 +0000 (UTC) Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> Message-ID: "Terry Reedy" wrote in news:cc7C7.157756$5A3.55376154 at news1.rdc2.pa.home.com: > > "Guido van Rossum" wrote in message > news:cp7ktjcbzx.fsf at cj20424-a.reston1.va.home.com... > >> FWIW, I agree. I just never thought of this. Encouraging; I'm sorry to have raised such a trivial point, though! > Allowing for null matches and applying the rule recursively, > > a,() = 1,() > > should also be legal, as Abbott also expected. I can imagine some use > to > > () = function() > > which I presume would raise exception if function() returned anything > other than (). Absolutely. From cliechti at gmx.net Fri Oct 19 16:12:19 2001 From: cliechti at gmx.net (Chris Liechti) Date: 19 Oct 2001 22:12:19 +0200 Subject: Seeking Jython tool to "inspect" live java server References: Message-ID: Michael Chermside wrote in news:mailman.1003499121.30710.python-list at python.org: > The answer is Jython. A small jython class could be run "within" the > server (so it's sharing the same java virtual machine). It could accept > telnet connections on some port, then allow the evaluation of arbitrary > input -- an interactive shell. Basically, I could start up the server > with this class active, and then telnet in and have a jython shell from > which to examine my system. I have wrote such a class (Remote Access Python Interpreter) you can find it here: http://www.geocities.com/chrisliechti/en/python/index.html I wrote it for CPython but one user reported that he ran it successfully under Jython. Chris -- Chris From richard at bizarsoftware.com.au Sun Oct 14 20:57:42 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Mon, 15 Oct 2001 10:57:42 +1000 Subject: Python web client anyone? In-Reply-To: <7xu1x1px4d.fsf@ruckus.brouhaha.com> References: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> <7xu1x1px4d.fsf@ruckus.brouhaha.com> Message-ID: <01101510574220.11044@ike> On Monday 15 October 2001 10:25, Paul Rubin wrote: > Richard Jones writes: > > > Thanks, this appears to include an HTTP client, which is a start, but > > > I was looking for something that actually parses the HTML on the > > > retrieved page like LWP does. I wonder if there's some way to do that > > > with the XML libraries (though HTML is generally not well-formed > > > XML--for example it usually has unterminated

tags). Any > > > thoughts? > > > > htmllib? > > > > If you want quick and simple DOM extraction, I have a module that extends > > HTMLParser... > > Perl LWP is a module for easily writing robot web clients. There's been a lot of work done with Python robots in the past. Search the web. For a good laff, read: http://www.w3.org/Tools/Python/Overview.html Specifically: " I have written a robot that does this, except it doesn't check for valid SGML -- it just tries to map out the entire web. I believe I found roughly 50 or 60 different sites (this was maybe 2 months ago -- I'm sorry, I didn't save the output). It took the robot about half a day (a saturday morning) to complete. " The demo Guido mentions is no longer distributed with Python. There is a web tool in the Tools/webchecker directory of the distribution though. > It doesn't > exactly make a DOM, but it's the same idea, so DOM extraction would be > fine. What I *really* want is to be able to easily find link objects > (anchor tags) based on the anchor text, which LWP for some reason > doesn't do, but DOM extraction would be a start. By "anchor text" I > mean the text in this is the anchor text. The > client should be able to find some "underlined" text on the page it > retrieves, and "click" on the linked document. My SimpleDOM module will do this. Here's some off-the-top-of-my-head usage: >>> import SimpleDOM, urllib >>> page = urllib.urlopen('http://www.w3c.org/').read() >>> dom = SimpleDOM.SimpleDOMParser() >>> dom.parseString(page) >>> len(dom.getByName('a')) 144 >>> dom.getByName('a')[0] Note that the parser is not particularly generous in accepting bad inputs. In the example above, I fed it: 1. www.python.org (mismatched tag) 2. www.bizarsoftware.com.au (*blush* bad entity) > I may not have read the htmllib docs carefuly enough but it looks more > intended for formatting/displaying HTML than parsing it. Are your > DOM extensions available? http://bigboy.bizarsoftware.com.au/~richard/SimpleDOM.py Richard From fdrake at acm.org Thu Oct 18 16:10:34 2001 From: fdrake at acm.org (Fred L. Drake) Date: Thu, 18 Oct 2001 16:10:34 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011018201034.72D8E28697@cj42289-a.reston1.va.home.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Documentation as packaged with Python 2.2 beta 1. From db3l at fitlinxx.com Thu Oct 25 17:43:24 2001 From: db3l at fitlinxx.com (David Bolen) Date: 25 Oct 2001 17:43:24 -0400 Subject: Solaris core dump with McMillan Installer References: <9r960f$s8h9i$1@ID-59885.news.dfncis.de> Message-ID: Gordon McMillan writes: > I was going to guess 8, but I guess I better use 16. Why not just let the compiler generate whatever alignment it wants for the structure and just marshall/unmarshall the individual fields (field by field) into the file. That way alignment shouldn't be an issue. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From chris.gonnerman at newcenturycomputers.net Tue Oct 30 08:01:23 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Tue, 30 Oct 2001 07:01:23 -0600 Subject: file operations References: Message-ID: <001901c16143$015c16c0$0101010a@local> Is it just me, or does this smell like another homework assignment? ----- Original Message ----- From: "Kerstin" > Hi, > I need to do the following file operations: > > begin loop > - read file > - replace something in the file (seem to work) > - write file > end loop > > This has to be done quite often. > > Can anybody help me? > Thanx, > Kerstin From horst at proceryon.at Fri Oct 19 03:04:48 2001 From: horst at proceryon.at (Horst Gassner) Date: Fri, 19 Oct 2001 09:04:48 +0200 Subject: Tkinter 3000 Message-ID: <3BCFD090.58A092C9@proceryon.at> Hi! Is Tkinter 3000 dead? There are no news since the alpha release of the WCK - or did I miss something? I (still) have the problem that Tkinter is much to slow but I don't want to change to wxPython because this means that I have to rewrite big parts of my whole Python code.... Tkinter 3000 raised my hopes in January but bit by bit my hopes are shrinking. Nice greetings Horst From Martin.Kretschmar at Infoman.De Thu Oct 25 10:48:07 2001 From: Martin.Kretschmar at Infoman.De (Martin Kretschmar) Date: Thu, 25 Oct 2001 16:48:07 +0200 Subject: Exists a more complete Description of DbiDate? Message-ID: <3bd8261c$0$223$4d4ebb8e@businessnews.de.uu.net> Hello, we have Problems with Access, ODBC and DbiDate Objects. We are using the packet "odbc" and we have no problems at all if we enter dates like "10/25/2001 10:00:00" into the database. But we want to convert it, and unluckely the dates have only been specified as e.g. "10:00". Any attempts printing these values resuls in "strange" characters. Typecasting it to int gives -1. So we would like to have a more complete description of DbiDate. We have have been looking for it, but we were not able to find something really useful. With this, we might see if there is a third way of cooperating with a DbiDate object. If it is in the public domain, were are the .py files? Or is the use of "odbc" discuraged anyhow? Regards, Martin -- Dipl.-Phys. Dr. Martin Kretschmar Software Development Corporate Info Center Infoman AG, Vaihinger Stra?e 169, D-70567 Stuttgart Tel.: +49 711/67971-682, Fax: +49 711/67971-10 E-Mail: Martin.Kretschmar at Infoman.De From db3l at fitlinxx.com Wed Oct 31 16:33:23 2001 From: db3l at fitlinxx.com (David Bolen) Date: 31 Oct 2001 16:33:23 -0500 Subject: How can I install win32all-140.exe over Python2.2? References: <76974d4a.0110310014.3effd408@posting.google.com> Message-ID: shehrer1 at yahoo.co.nz (Valerie) writes: > I've install a new Python 2.2 version and want to use win32all with > it. There is a win32all's version for Python 2.1, only. :-( > How can I decompress package to use some known utilities from > win32all? > Or I need to wait the better time... :-) win32all is a binary release, so a build for Python 2.1 won't work with Python 2.2. You'd have to check out the source from CVS and rebuild it yourself for 2.2 - my guess is any tweaks that might be necessary would be minor, but I haven't yet done it myself so I could be wrong. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From qrczak at knm.org.pl Sat Oct 13 03:14:39 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 13 Oct 2001 07:14:39 GMT Subject: Why not 3.__class__ ? References: Message-ID: Fri, 12 Oct 2001 11:24:08 -0700, James_Althoff at i2.com pisze: > Don't know if there are any plans/thoughts regarding the addition > of a "module" or "mod" equivalent of "int" (etc.) someday. __import__ == type(__builtins__)? -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From db3l at fitlinxx.com Tue Oct 23 21:11:19 2001 From: db3l at fitlinxx.com (David Bolen) Date: 23 Oct 2001 21:11:19 -0400 Subject: string object methods vs string module functions References: <9r50ga$re9nn$1@ID-11957.news.dfncis.de> Message-ID: "Emile van Sebille" writes: > take from string.py, showing ''.join and string.join() are the same: Well, the eventually execute the same underlying code, but the string module functions do more work along the way. For example, an extra string object is created (or in the default case the existing default object is used), and there is an extra function call along the way. Whether or not this extra layer is significant probably depends heavily on how the methods are used by a piece of code and how deeply embedded in critical loops or code paths they are. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From nevin at codeforge.com Sun Oct 7 22:36:59 2001 From: nevin at codeforge.com (Nevin Kaplan) Date: Mon, 08 Oct 2001 02:36:59 GMT Subject: ANNOUNCE:C-Forge IDE for Unix Message-ID: Dear Python Developer, We would like to take a moment of your time to introduce you to the C-Forge Integrated Development Environment. C-Forge is an industry leading IDE for Unix. It provides full project management, transparent revision control and complete edit/compile/debug/cycle support for over 30 programming languages. We have just released version 2.0 which includes: ? Team Development Support. ? Revision Control support for: CVS, SCCS, PRCS, Perforce and RCS. ? New Revision Control Tool transparent access to all the supported types of RC. Branch support. CVS tag support. ? New Search/Replace Tool - Revision Control aware, searches files as well as ETAGS files. ? Automatic ETAGS gathering at the project level. Selecting a symbol in the editor and pressing alt-. will cause the editor to jump to the definition of the symbol. ? New merge/diff tool - allows on-the-fly editing of merge results with the built-in editor (auto-indentation, syntax highlighting, etc for all supported languages). ? Rename of files/objects within a project _AND_ in RC Repositories. ? New automatic-dependency gathering for C/C++ and FORTRAN. ? Querix 4gl and eRuby support. For more information PLEASE visit us at http://www.codeforge.com. Sincerely Yours, The Code Forge Team. From jerome at cortex.unice.fr Tue Oct 16 06:43:05 2001 From: jerome at cortex.unice.fr (Jerome Alet) Date: Tue, 16 Oct 2001 12:43:05 +0200 Subject: [ANN] french audio conference on the Python language Message-ID: Hi there, for those of you who might be interested: on Saturday October 27th 2001 afternoon, Rene Mages will give a speech in french about the Python language at our local LUG. For the very first time for us, this conference will be streamed at 32 Kbps in MP3 format so you'll be able to listen to it from anywhere in the world using tools like winamp, xmms, mpg123, realplayer or similar tools. All the informations about this conference and the way to tune in will be available (in french) some days before the 27th at: http://www.linux-azur.org (these informations are currently not available) A more complete explanation on what/where/when/who is available in french at: http://www.zopera.org/site/Members/jalet/1003138031 Thank you for listening. Jerome Alet From laurent.tardif at csse.monash.edu.au Thu Oct 4 21:56:31 2001 From: laurent.tardif at csse.monash.edu.au (Laurent Tardif) Date: Fri, 05 Oct 2001 11:56:31 +1000 Subject: GTK under windows Message-ID: <3BBD134F.DA1ADD1@csse.monash.edu.au> i've try to use de GTK library with python under windows. after a funny time to make it work, i've reach a funy situation : if i use python (command line) form the directory i've install it, it works, but i rum python from a other directory it doesn't work. i've try to set the different variable : PythonPath, ... but no succes. Somedy have an idea ? before i forget : the error i got is : "importError: dynamic module does not define init function (initgtk)" there is a pythonlibrarypath to set ? thanks Laurent ----------------------------------------------------------------- . .. .' @`._ Laurent Tardif ~ ...._.' ,__.- Monach University _..------/` .-'; mailBox 36 - Building 26 : __./' , .'-'- ~ School of Computer Science ~ `---(.-'''---. \`._ -.._ and Software engineering _.--'( .______.'.-' `-.` `. ~ Clayton Victoria 3168 : `-..____`-. `. Australia `. ```` ; Phone : xxx55779 `-.__ ; www.inrialpes.fr/opera ````-----.......---- __.-' From thomas.heller at ion-tof.com Thu Oct 18 04:28:58 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 18 Oct 2001 10:28:58 +0200 Subject: Function arguments Message-ID: <9qm3sb$pc43f$1@ID-59885.news.dfncis.de> Call me weird, but sometimes I need functions taking a number of positional arguments, some named arguments with default values, and other named arguments as well. Something like this (which does _not_ work): def function(*args, defarg1=None, defarg2=0, **kw): ... The usual way to program this is: def function(*args, ***kw): if kw.has_key('defarg1'): defarg1 = kw['defarg1'] del kw['defarg1'] else: defarg1 = None if kw.has_key('defarg2'): defarg1 = kw['defarg2'] del kw['defarg2'] else: defarg2 = 0 # ...process the positional arguments in args # ...process the remaining named arguments in kw Doesn't look very pretty IMO, and using the dictionaries' get method doesn't help. I was thinking of a popitem() dictionary method taking (optionally) 2 arguments: the name of the item to pop, and the default value to return if the item is not present in the dictionary: >>> d = {'a': 2, 'b': 3} >>> d.popitem('defarg', 0) 0 >>> d {'a': 2, 'b': 3} >>> d.popitem('a', 100) 2 >>> d {'b': 3} >>> Opinions? Thomas From tim.one at home.com Wed Oct 10 01:11:27 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 10 Oct 2001 01:11:27 -0400 Subject: Curious assignment behaviour In-Reply-To: Message-ID: [Tim] > But that made it even uglier, and proponents got rarer while > the opposition enjoyed a major resurgence in the polls . [Martin von Loewis] > Sounds like the report of an observing bystander :-) It does, doesn't it? One of my special skills. Still, given the number of times this debate has occurred over the years, I've actually taken part in few of them. In the rest, I argued both sides just to keep a finely honed sense of outrage intact . it's-not-a-trivial-language-issue-it's-a-matter-of-moral-urgence-ly y'rs - tim From info at mjais.de Sun Oct 21 15:53:24 2001 From: info at mjais.de (Markus Jais) Date: Sun, 21 Oct 2001 21:53:24 +0200 Subject: problem with re module References: <9qv5d4$psb1n$1@ID-75083.news.dfncis.de> Message-ID: <9qv95v$q8qjt$1@ID-75083.news.dfncis.de> hello forget the question. I am a fool. made a stupid mistake everything works fine now. markus Markus Jais wrote: > hello > I have a strange problem > when I take the re example from the python org site > and put in my interactive python interpreter > everythings works fine: > > Python 2.1 (#1, Jun 4 2001, 12:55:45) > [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2 > Type "copyright", "credits" or "license" for more information. >>>> import re >>>> p = re.compile('ab*') >>>> print p > >>>> > > but when I put it in a file: > #!/usr/local/bin/python > > import re > p = re.compile('ab*') > print p > > I get an error: > Traceback (most recent call last): > File "re.py", line 3, in ? > import re > File "./re.py", line 4, in ? > p = re.compile('ab*') > AttributeError: 're' module has no attribute 'compile' > > > this error first appeared today and it only happens with the re > module. I can also not use any DOM modoles for example because > the rely on the re module > > but everything is intstalled unter > /usr/local/lib/python2.1 > > can anybody help me?? > > thanks > markus From me at mikerobin.com Sat Oct 20 19:23:38 2001 From: me at mikerobin.com (Michael Robin) Date: 20 Oct 2001 16:23:38 -0700 Subject: PEP: statements in control structures References: <20011019002941.A721@xyz.donetsk.ua> Message-ID: <52e5ab5f.0110201523.57ab8a11@posting.google.com> Skip Montanaro wrote in message > > Python 2.2 with iterator support already supports > > for line in file: > ... It also supports the equally nice: for char in file: and for record in file: (etc.) although they all do the same thing :) That's why I wish that getting interators required a specfic call such as: for line in file.iterlines(): This is self-documenting, and matches the syle of "file.readlines()", "dict.iterkeys/values()" etc. I know that unadorned-object-as-own-iterator looks nice, but for cases where it's not apparent (via the elements that can be returned by the "container" type) what will be iterated over, it's nice to have it explicit. For example, I'd consider the native or cannonical element of a file the character, not the line, and expect it to be the default iterator, if there was one. (I guess once you're indoctrinated into Python, you (a) read the docs, and (b) come to expect the default to be what's most used/convenient...) Hard to tell when the "explicit vs. implicit" rule is beaten by the "idiomatic" rule... m From ignacio at openservices.net Wed Oct 24 16:26:56 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 24 Oct 2001 16:26:56 -0400 (EDT) Subject: Curl-ing, anyone? In-Reply-To: <458b194a.0110241156.795e9618@posting.google.com> Message-ID: On 24 Oct 2001, Resty Cena wrote: > Is Curl (www.curl.com) a threat to Python (and Ruby, and Perl)? No. It's more of a threat to JavaScript or Flash, and not even a big one at that. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From boud at rempt.xs4all.nl Wed Oct 10 15:12:56 2001 From: boud at rempt.xs4all.nl (Boudewijn Rempt) Date: 10 Oct 2001 19:12:56 GMT Subject: ANN: Final draft of GUI Programming with Python and Qt Message-ID: <9q26jo$9b1$1@news1.xs4all.nl> Yesterday evening at about a quarter to ten I finished the final draft of my book, GUI Programming with Python and Qt, to be published by Opendocs. This draft is now available at http://stage.linuxports.com/pyqt/book1.htm (The screenshots appear to be missing, but Joshua is going to fix that.) If people want to do a technical review, I can send them a whopping great PDF file (it's more than 600 pages now) - and we hope to go to press next month, so a paper copy should shortly be in reach of everyone! This is a short table of contents: Part I Installation BlackAdder and PyQt Interface of BlackAdder Introduction to Python Debugging Part II: Concepts Qt concepts Signals and slots String objects in Python and Qt Python objects and Qt objects Qt class hierarchy Qt Designer, BlackAdder and uic Part III: Developing a real application Application frameworks Actions, menus, toolbars and accelarators Automatic testing Complex frameworks: multiple documents and views User interface paradigms Creating Application functionality Application configuration Using dialog windows A macro language Drawing on painters and canvases GUI design in the baroque age Drag and Drop Printing Internationalisation Delivering your application Appendices Using the Qt documentation Sip PyQwt and Numpy While the book of course uses PyQt for all gui work, I hope that I have succeeded in dealing with topics that are interesting to anyone who tries to develop a complete, real-world GUI application. Stephen Figgins did a review of the previous public draft at: http://www.onlamp.com/pub/a/python/2001/07/05/pythonnews.html -- Boudewijn Rempt | http://www.valdyas.org From aleax at aleax.it Thu Oct 11 17:33:20 2001 From: aleax at aleax.it (Alex Martelli) Date: Thu, 11 Oct 2001 23:33:20 +0200 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> Message-ID: <9q5370$3re$1@lancelot.camelot> Paul Rubin wrote: ... >> for line in file.xreadlines(): >> ... > > What if you want to read until you get to a delimiter? > > while (line := readline()) != 'end': ... for line in file.xreadlines(): if line == 'end': break etcetc(line) Of course, if you're transliterating from some other language and need to keep close structure similarity (e.g. for didactic reasons), Python makes that easy too, see e.g. the rather obvious approach of my recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061 which would give: while data.set(file.readline()) != 'end': process(data.get()) Alex From use-net at schabi.de Fri Oct 19 03:00:08 2001 From: use-net at schabi.de (Markus Schaber) Date: Fri, 19 Oct 2001 09:00:08 +0200 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <3BCF7087.B59CE3C3@ccvcorp.com> Message-ID: <20011019090008.42e15a39.use-net@schabi.de> Hi, On Fri, 19 Oct 2001 03:28:59 +0000 (UTC), huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote: > The original code is quite enigmatic to me. I don't know the ftp > protocol, but from Andrew's example data I think the code is intended > to be > > def getmultiline(self): > code = None > lines = [] > while line = self.getline(); \ > lines.append(line); \ > line[3:4] == '-' or code != line[:3]: > code = line[:3] > return '\n'.join(lines) > > I'm not sure if this is correc, either, except it works on Andrew's > data.(What should happen if code changes when line[3:4]=='-', etc?) I think you have to break after adding the first line with no - after the code, because otherwise you would be blocked in a read. AFAIR (didn't look into the RFC) the protocol (which IIRC is also used in SMTP) says that the last line of a message is three digits code (the machine readable information), then a blank, and then a human readable text (saying esentially the same than the three digits code). When more then one line of texts is needed, then this last line can be preceeded by lines using three digits of code, then a -, and then the human readable code. I don't remember whether changing the code is allowed, but the original code clearly hangs when the code is changed (because it terminates only when the line containing the space has the same code than the first line). I'd write this like (not tested): def getmultiline(self): lines = [] while 1: line = self.getline() lines.append(line) if line[3:4]==" ": break return "\n".join(lines) markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From phr-n2001d at nightsong.com Thu Oct 11 02:30:37 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 10 Oct 2001 23:30:37 -0700 Subject: Python questions -> compiler and datatypes etc References: Message-ID: <7xzo6ysn76.fsf@ruckus.brouhaha.com> writes: > > I think the real answer to why there's no Python compiler is no one > > has really wanted to write one. Python's runtime semantics are pretty > > similar to Lisp systems, and native-code Lisp compilers have existed > > since the 1960's or maybe even earlier. It might even be feasible > > to adapt one to compile Python. > > That'd be great. How about just creating a Python-to-Lisp translator? Then > you could use whatever Lisp compilation tools are available (assuming, of > course, that the performance of compiled Lisp is good enough to make the > effort worthwhile). That might be a reasonable basic approach (as opposed to, for example, starting from Python bytecodes) but to do a good job, the compiler is going to have to know some Python-specific things, like range and slice objects, etc. Lisp compilers can make code as good as C compilers, but to optimize that well, they usually need some programmer-supplied advice (similar to pragmas) about object types etc. A Python compiler will probably want similar help from the programmer. > It seems like the really hard part about translating Python to C, for > example, is that you're moving "down" the dynamic language scale. But if > you already have a compiler for a language that is near or higher on that > scale, then somebody has already done a lot of the work for you. C is pretty close to machine language, so compiling to C is similar to compiling to assembly. Some Lisp compilers (like KCL/AKCL) in fact compile to C and then call an external C compiler to make a loadable .o or .so file. If you want to see how simple Lisp compilers work, see the "metacircular evaluation" chapter of the very wonderful book "Structure and Interpretation of Computer Programs" by H. Abelson and G. J. Sussman. From jblazi at hotmail.com Wed Oct 10 11:03:43 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Wed, 10 Oct 2001 17:03:43 +0200 Subject: Tkinter font question in Win2000 Message-ID: <3bc46350_2@news.newsgroups.com> I should like to display a text (in a label) using the same font as anywhere else in my application but boldface. It seemst to me that this is not trivial! Can anybody help me? J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From phd at phd.pp.ru Thu Oct 11 07:05:36 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 11 Oct 2001 15:05:36 +0400 Subject: image from URL In-Reply-To: <1011011060148.ZM2689@kelgia.ncsa.uiuc.edu>; from heiland@ncsa.uiuc.edu on Thu, Oct 11, 2001 at 06:01:48AM -0500 References: <3BC57869.E95139D7@ncsa.uiuc.edu> <20011011145841.I500@phd.pp.ru> <1011011060148.ZM2689@kelgia.ncsa.uiuc.edu> Message-ID: <20011011150536.J500@phd.pp.ru> On Thu, Oct 11, 2001 at 06:01:48AM -0500, Randy Heiland wrote: > fp = __builtin__.open(fp, "rb") > TypeError: open() argument 1 must be (encoded string without NULL bytes), not > str Please continue to answer to newsgroup. So you have a minor problem - Image expects filename. So, save fp.read() to a file, and pass its filename to Image. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phd at phd.pp.ru Mon Oct 29 06:44:22 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 29 Oct 2001 14:44:22 +0300 Subject: Is there a place holding all the messages to this list ? In-Reply-To: <003101c1606d$52b6ad90$9597003e@rashome>; from weismann@netvision.net.il on Mon, Oct 29, 2001 at 01:31:44PM +0200 References: <003101c1606d$52b6ad90$9597003e@rashome> Message-ID: <20011029144422.B17433@phd.pp.ru> On Mon, Oct 29, 2001 at 01:31:44PM +0200, Amit Weisman wrote: > Is there a place holding all the messages to this list ? http://www.python.org/psa/MailingLists.html http://groups.google.com/groups?lr=&safe=off&group=comp.lang.python Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From just at letterror.com Fri Oct 5 03:07:46 2001 From: just at letterror.com (Just van Rossum) Date: Fri, 05 Oct 2001 09:07:46 +0200 Subject: Compiling 2.1.1 on Mac OS X 10.1 - test failures References: <0110051145150H.04291@ike> Message-ID: <3BBD5C43.D3813A2E@letterror.com> Richard Jones wrote: > > On Friday 05 October 2001 13:21, Steve Holden wrote: > > Richard: > > > > You should go to http://python.sf.net and report these bugs. Follow the > > link to the project page, then select bugs. There's a "Submit New" link > > close to the top of the page. > > Yep, was going to do that - just wanted to share with the community a bit a > see if I would be able to submit useful information with the bugs :) Yet a lot of things have changed or have been fixed since 2.1.1, so it would be best to test with 2.2a4, or even better, CVS Python. Just From gh_pythonlist at gmx.de Fri Oct 26 07:46:30 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 26 Oct 2001 13:46:30 +0200 Subject: tutorial In-Reply-To: <9rb6pi$nva$1@penthesilea.materna.de>; from michael.korte@materna.de on Fri, Oct 26, 2001 at 10:29:23AM +0200 References: <9rb6pi$nva$1@penthesilea.materna.de> Message-ID: <20011026134628.A607@lilith.hqd-internal> On Fri, Oct 26, 2001 at 10:29:23AM +0200, kutte wrote: > Hi there ! > I'm looking for a python tutorial for beginners. I would like to learn > python, but I didn't found any (good) toutorials (online or download). > I just have expierience in programming procedual Languages. ( C, Basic and > Javascript) So I need a very "calm" tutorial *g* Be sure to check out this page, it lists several tutorials: Python for Beginners: http://python.org/doc/Newbies.html > (If you even know one tutorial in german...........I would spread my kisses > allovertheworld *G*) You mean like this one? Das Python-Tutorium: http://starship.python.net/crew/gherman/publications/tut-de/online/tut/ (German translation of the Python tutorial by Dinu Gherman). Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From haaserd at yahoo.com Tue Oct 30 21:53:04 2001 From: haaserd at yahoo.com (haaserd) Date: Tue, 30 Oct 2001 19:53:04 -0700 Subject: Install of MySQLdb fails - cl.exe missing Message-ID: <3BDF6790.27C53973@yahoo.com> Hi, I am trying to install MySQLdb on Windows 98SE. I have Python 2.1.1 installed and current versions of MySQL and mxDateTime. Each time I try to run "python setup.py install" the procedure fails because a module cl.exe is not found. I have tried this with MySQLdb versions 0.9.1, 0.9.0, and 0.3.5 and all fail the same way. I have MySQLdb version 0.9.0 installed on another PC running Python 2.0 and Windows/Me. This PC doesn't have a cl.exe either, and I have no clue as to what I am doing differently. Can anyone tell me what I am doing wrong? Here is the latest output from setup: running install running build running build_py not copying CompatMysqldb.py (output up-to-date) not copying _mysql_exceptions.py (output up-to-date) not copying MySQLdb\__init__.py (output up-to-date) not copying MySQLdb\converters.py (output up-to-date) not copying MySQLdb\connections.py (output up-to-date) not copying MySQLdb\cursors.py (output up-to-date) not copying MySQLdb\sets.py (output up-to-date) not copying MySQLdb\times.py (output up-to-date) not copying MySQLdb\constants\__init__.py (output up-to-date) not copying MySQLdb\constants\CR.py (output up-to-date) not copying MySQLdb\constants\FIELD_TYPE.py (output up-to-date) not copying MySQLdb\constants\ER.py (output up-to-date) not copying MySQLdb\constants\FLAG.py (output up-to-date) not copying MySQLdb\constants\REFRESH.py (output up-to-date) not copying MySQLdb\constants\CLIENT.py (output up-to-date) running build_ext building '_mysql' extension cl.exe /c /nologo /Ox /MD /W3 /GX -Ic:\mysql\include -IC:\PYTHON21\Include /Tc_mysql.c /Fobuild\temp.win32-2.1\Release\_mysql.obj TIA, Roger From john.thingstad at chello.no Wed Oct 31 04:13:42 2001 From: john.thingstad at chello.no (John Thingstad) Date: Wed, 31 Oct 2001 10:13:42 +0100 Subject: python development practices? Message-ID: <20011031092122.CMDN13403.mta01@mjolner> >While I feel that Python makes me far more productive as a programmer >for all the projects on which i've worked, i'm inclined to agree that >the lack of data hiding coupled with lack of a standard interface >specification would cause problems in a team. Python does have a simple data hiding scheme. class Something: def __init(): __name = 'hidden' makes name local to that class. (It can be accessed by writing __Something_name though) The same can be done for module classes, functions etc. Also hiding at the package level with the __all__ modifier As in file __init__.py __all__ = ["export1", "export2"] will only export export1 and export2 modules. From peterb at cortland.com Mon Oct 29 07:44:54 2001 From: peterb at cortland.com (Peter Bismuti) Date: Mon, 29 Oct 2001 04:44:54 -0800 Subject: setting the clipboard Message-ID: <3bdd553c$1@207.229.64.20> How can you set the clipboard from within Python? I was told that it can be done. Thanks! From lucio at movilogic.com Tue Oct 23 19:20:23 2001 From: lucio at movilogic.com (Lucio Torre) Date: Tue, 23 Oct 2001 20:20:23 -0300 Subject: POLL in different OSes References: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> <5.1.0.14.0.20011023125024.027cf278@imap.hq.movilogic.com> Message-ID: <3BD5FB37.6020906@movilogic.com> Lucio Torre wrote: > At 10:18 AM 23/10/2001 +0200, Gerhard H?ring wrote: > >> On Mon, Oct 22, 2001 at 10:51:02PM -0300, Lucio Torre wrote: >> > From the documentation: >> > >> > "The poll() system call, supported on most Unix systems" >> > >> > and my questions: >> > >> > a) is poll supported on Windows? >> > >> > my guess is no, but i hoping for a yes. >> >> It isn't. Unless, you're using Cygwin. Also, select only works with >> sockets on Windows. >> >> Wouldn't it be possible to emulate poll() with select()? I'd be glad to >> see a patch appear at Sourceforge if that's possible :-) >> >> Gerhard >> - > > > i think i could do that. i can make a .c with the code that amulates > poll from select, if someone else is willing to make it a patch or > whatever it should be to get into python. > > btw: is it worth it? poll is supposed to be faster, so why emulate it? > it would have no reason to exist! > > > As i wanted to use poll, but still be able to develop on my windows boxes, i did the following. Not the C version it could have been, but it helps me. Comments please. import select """ Constant Meaning POLLIN There is data to read POLLPRI There is urgent data to read POLLOUT Ready for output: writing will not block POLLERR Error condition of some sort POLLHUP Hung up POLLNVAL Invalid request: descriptor not open TODO: POLLPRI POLLHUP POLLNVAL """ POLLIN=1 # There is data to read POLLPRI=2 # There is urgent data to read POLLOUT=4 # Ready for output: writing will not block POLLERR=8 # Error condition of some sort POLLHUP=16 # Hung up POLLNVAL=32 # Invalid request: descriptor not open class poll: def __init__(self): self.read_fds = [] self.write_fds = [] self.excep_fds = [] def register(self, fd, events = POLLIN | POLLOUT | POLLPRI ): if events & POLLIN: if not fd in self.read_fds: self.read_fds.append(fd) if events & POLLPRI: if not fd in self.read_fds: self.read_fds.append(fd) if events & POLLOUT: if not fd in self.write_fds: self.write_fds.append(fd) if events & POLLERR: if not fd in self.excep_fds: self.excep_fds.append(fd) if events & POLLHUP: if not fd in self.excep_fds: self.excep_fds.append(fd) def unregister(self, fd): if fd in self.read_fds: self.read_fds.remove(fd) if fd in self.write_fds: self.write_fds.remove(fd) if fd in self.excep_fds: self.excep_fds.remove(fd) def poll(self, timeout = -1): if ( self.read_fds == [] and self.write_fds == [] and self.excep_fds == []): return () if timeout != -1: result = select.select(self.read_fds, self.write_fds, self.excep_fds) else: result = select.select(self.read_fds, self.write_fds, self.excep_fds, timeout) print result ret = [] for i in result[0]: ret.append((i, POLLIN)) for i in result[1]: ret.append((i, POLLOUT)) for i in result[0]: ret.append((i, POLLERR)) return ret From l0819m0v0smfm001 at sneakemail.com Sun Oct 7 10:33:20 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Sun, 07 Oct 2001 14:33:20 GMT Subject: how to create a def that has the behaviour like a built-in keyword... References: Message-ID: <3BC03254.5050902@sneakemail.com> Niklas Frykholm wrote: > It does make accessor functions look a bit nicer > > print p.text > p.text = "OK" > > instead of > > print p.getText() > p.setText("OK") But the former is perfectly legal in Python: >>> class P: ... def __init__(self, text): ... self.text = text ... >>> p = P('spam') >>> print p.text spam >>> p.text = "OK" >>> print p.text OK >>> What you can't do in Python (without playing __setattr__/__getattr__ tricks) is have fancy accessor functions that do calculations or have side-effects unless you're willing to use function syntax. As long as you're content with simple attribute binding and lookup, though, your preferred syntax works. Joshua From m.mariani at imola.nettuno.it Tue Oct 2 11:45:36 2001 From: m.mariani at imola.nettuno.it (Marco Mariani) Date: Tue, 2 Oct 2001 17:45:36 +0200 Subject: curses vs slang Message-ID: <20011002174536.A18163@zoidberg> I'm about to write a tty data-entry application on Linux. Do you think I should go for the ncurses or the slang wrapper? Thanks From hungjunglu at yahoo.com Wed Oct 31 17:25:37 2001 From: hungjunglu at yahoo.com (hungjunglu at yahoo.com) Date: Wed, 31 Oct 2001 22:25:37 -0000 Subject: hola nesesito su ayuda Message-ID: <9rptp1+mn7j@eGroups.com> fernando orellana (leandro) wrote: > bueno les escribo porque tengo una duda nesecito hacer un sistenma de > matriculacion y tengo que ingresar los nombres de los alunmos, asi > como su correo, su numero de legajo y las materias que va a tomar, > donde deveria meter estas variables?, en listas o diccionario o talves > hacerlo con clases ? Bueno, lo que usualmente hago yo es implementar una clase boba y meter los atributos a la hora de la corrida misma. Por ejemplo: class Object: pass alumnos = [] a = Object() a.nombre = 'Juan Perez' a.correo = 'juanperez at gaucho.com.ar' a.num_legajo = '12345' a.materias = ['CC101', 'MA201', 'FI101'] alumnos.append(a) a = Object() a.nombre = 'Leopoldo Galtieri' a.correo = 'lgaltieri at carcel.edu.ar' a.num_legajo = '98765' a.materias = ['CP101', 'IN201', 'EC103'] alumnos.append(a) for alumno in alumnos: print '-------' print alumno.nombre print alumno.correo print alumno.num_legajo print alumno.materias saludos, che. Hung Jung From adina_levin at mindspring.com Mon Oct 15 20:41:50 2001 From: adina_levin at mindspring.com (adina_levin at mindspring.com) Date: Mon, 15 Oct 2001 19:41:50 -0500 Subject: newbie printing question Message-ID: <9qg0l9$5hp$1@slb3.atl.mindspring.net> I'd like to create a string with the current date and time. I've got the mxDateTime library, so far so good. print mxDateTime.now() will generate the date and time to the screen. write will send it to a file. But how can I assign this to a string? I will be most thankful and embarrassed to hear the answer to this question. It oughta be obvious! From max at alcyone.com Thu Oct 4 15:14:00 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 04 Oct 2001 12:14:00 -0700 Subject: Mutable default values for function parameters References: Message-ID: <3BBCB4F8.93CEA96@alcyone.com> Brian Quinlan wrote: > Those should raise some sort of exception, not silently do the > default. > > You could change it to: > d = (d is None) or [] That won't work either. d is None evalutes to 1, not d, so when d is None d will get replaced with 1, not with a new empty list. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Give me chastity, but not yet. \__/ St. Augustine Crank Dot Net / http://www.crank.net/ Cranks, crackpots, kooks, & loons on the Net. From James_Althoff at i2.com Wed Oct 10 16:15:30 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 10 Oct 2001 13:15:30 -0700 Subject: Why not 3.__class__ ? Message-ID: Magnus Lie Hetlands wrote: >Well... I'm not sure it's unfortunate. For a beginner, it might be easier to >translate the above into something understandable ("for each value of the >index variable i in the range up to 100, execute the following block") than >it would be for the Ruby version ("call the times method of the number 100 >with an unnamed code block, which will then be executed with the numbers >up to 100 supplied for the parameter i"). > >The Ruby version may be nice, but seems unnecessary to me, as long as you >actually have a looping construct in the language. (And if you haven't, then >methods like .times must have them internally anyway...) The difference between "nice" and "unnecessary" is that in Ruby and Smalltalk you can have debates about whether to name your method "times" or "timesRepeat" instead of -- as we see constantly in Python -- having endless debates about how feasible it is or isn't to add new syntactic sugar and what sugar would be the most "Pythonic" to many users and the least offensive to others. Until you have the chance to use unnamed, in-place code blocks as arguments to methods it can be hard to appreciate how *easy* it then becomes to extend a language without having to add new syntax (and keywords). > >I do, however, think it would be nice to have some syntactic sugar for the >range function, e.g.: > > for i in 1..10: foo() > Certainly it is hard to argue that having to call a function like range() -- and having two essentially equivalent functions around for that purpose -- is something that is *intuitive* for beginners. >But I guess that'll never happen. :) > >(And, no, I don't like names like "xrange" either.) > Jim From paul at zope.com Fri Oct 5 07:29:46 2001 From: paul at zope.com (Paul Everitt) Date: Fri, 05 Oct 2001 07:29:46 -0400 Subject: nocaret.py - Zope install error References: Message-ID: <3BBD99AA.3010403@zope.com> Hi Mike. The installer creates a 'start' file that has the -D option for starting Zope. This option is the debugging option, meaning errors go to the console, tracebacks are visible on pages, and Zope runs a little slower. If you take -D out of the start script, Zope will go in the background. Hope that helps. --Paul Mike James wrote: > I have zope 2.4.1, apache 1.3.20, RH linux 7.1 - and here's the problem... > > When I run ./install, I get the following errors: > > Compiling python modules > File "/usr/local/zope/lib/python2.1/test/nocaret.py", line 2 > [x for x in x] = x > > SyntaxError: can't assign to list comprehension > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future3.py, line 3) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future4.py, line 3) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future5.py, line 4) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future6.py, line 3) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future7.py, line 3) > > Everything else seems to go just fine. When I run ./start, I get messages > about the HTTP and FTP server starting. The PCGI server starts, but never > goes into the background. Why is that? > > While the python process from ./start is running, I can access zope through > the browser (http://localhost:8080) and even manage zope using the inituser > id and password generated by the install. > > Just that one little problem about the ./start script is bugging me. Any > help would be appreciated!! thanks, Mike > From dcinege at psychosis.com Fri Oct 19 18:04:46 2001 From: dcinege at psychosis.com (Dave Cinege) Date: Fri, 19 Oct 2001 18:04:46 -0400 Subject: OT: Python Web Developer Needed ASAP (Must be able to start in 2 days) Message-ID: Sorry to be posting the list but I need somebody yesterday. Please reply directly off list. Please reply with a phone number as I don't have time to play email tag. Please include URL's to examples of your work. International Inquiries welcome. I've got a web based system I've been working on that I need help with. The system is used for viewing dynamic report data from a developing python CGI with (currently) MySQL backend. Main problem: I'm not a 'web guy'. I can't make pretty pages and don't want to be bothered with CGI. My primary job is low level (kernel,protocol,network layer,sysadmin) stuff. Current problem: Need to make a 2 week dead line to merge the current system with a version that is refined and has a professional look to it. I lack time and html layout ability to make that happen by myself. We have another person that was to do this but they lack time and experience. We do have a rough page they created in dreamweaver we're happy with and can be used to get going with. (Tab'ed interface using layers) I NEED: Someone able to create a professional looking layered interface and merge the current CGI to operate with it. Basically the core cgi is coded. All you need to do is modifiy SQL (dict and tuple) output in a table to a layer. (Refining the table data and look) Skills you must have: Professional site layout and page drawing (Dreamweaver,etc) Intermediate Python programming in Linux/Apache/mod_python CGI evironment Javascript (probably, unless we can get around it) Basic SQL query (select) knowledge Understanding of socket (ip) level operations a big plus 'Broadband' internet access will help. Ability to begin work immediatly Ability to put in long hours to meet the deadline Ability to work with little handholding Duration: Initial 2 weeks. Possiblity it will lead into longer term especially if you have strong skills. (3 months or more) Dave From peter at engcorp.com Sun Oct 28 08:08:17 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Oct 2001 08:08:17 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> Message-ID: <3BDC0341.8A213560@engcorp.com> Christy J wrote: > > I need a binary search tree in python that uses classes. I'm trying to > count words from a file and spit out the number of times they occur > and in alphabetical order. I got bintree[ [key, data], left, right] > but don't know how to implement using classes. I'd be interested to hear which school is teaching with Python. Schools progressive enough to take a chance (a small one, mind you, but they don't usually seem to think so) on something not mainstream (i.e. not Java) are few and far between. -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From chrishbarker at home.net Mon Oct 29 15:22:02 2001 From: chrishbarker at home.net (Chris Barker) Date: Mon, 29 Oct 2001 12:22:02 -0800 Subject: Python still remembers script after change and save References: <1004382387.8324.0.nnrp-07.c1c3e128@news.demon.co.uk> Message-ID: <3BDDBA6A.EFDD6486@home.net> Chris Liechti wrote: > "Paul Brian" wrote in > > I occasionally come across a situation where I have changed a file, > > rerun the file in python but python still produces an error, quoting > > the original file in the error string > > you're looking for the "reload" command > > 1. for the first usage type: > import mymod > > 2. usage after modifications on mymod, type: > reload(mymod) If you are working in an IDE that is written in Python (IDLE, MacPython IDE, PythonWin, etc.) you might want to do: import mymod reload(mymod) Everywhere while you are developing, so you will be assured of always getting a fresh version when you run your code. When a module is stable, you can delete the reload() -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From usenet at minus1.de Wed Oct 31 11:25:49 2001 From: usenet at minus1.de (Konrad Anton) Date: Wed, 31 Oct 2001 17:25:49 +0100 Subject: BNF parsing in Python References: <3BDDA9D8.972BAEA2@stroeder.com> Message-ID: Michael Str?der schrieb: >I'd like to parse strings describing LDAPv3 schema elements which >seem to be declared as BNF (one example, not complete): >(...) >Any clues on where to start? Should be pure Python and >license-compatible to be included into an open source project >(probably BSD style license). You might want to give kjParse (the parsing component in gadfly) a try. Gadfly lives somewhere on www.chordate.com and uses kjParse internally to parse SQL. I've successfully written a parser for C Enums and C Structs with it. HTH Konrad. -- Konrad Anton gpg: 0x22954D8A Tel. +49-761-881-2122, Fax +49-721-151318943. Alice: Serpent. From dalke at dalkescientific.com Fri Oct 19 19:16:34 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 19 Oct 2001 17:16:34 -0600 Subject: 2.1 extension errors on Solaris/gcc Message-ID: <9qqc17$n8p$1@slb0.atl.mindspring.net> Hello, An extension module I develop isn't building under Python 2.1 on a Solaris box which has gcc installed but not the vendor's cc. I can't figure it out. Looking for advice. Original attempt was to compile Python with gcc 2.95 using the archive from ftp.sunfreeware.com . That caused a problem. solana> /usr/local/bin/python Python 2.1.1 (#1, Aug 25 2001, 04:37:28) [GCC 3.0.1] on sunos5 Type "copyright", "credits" or "license" for more information. >>> import cStringIO Traceback (most recent call last): File "", line 1, in ? ImportError: ld.so.1: /usr/local/bin/python: fatal: libgcc_s.so.1: open failed: No such file or directory >>> and there was no libgcc_s.so anywhere on the machine. Next was to upgrade to gcc 3.0.1. That compiled Python just fine, but there were problems with the extension. solana> python setup.py build running build running build_py creating build creating build/lib.solaris-2.7-sun4u-2.1 .... running build_ext building 'dayswig_python' extension creating build/temp.solaris-2.7-sun4u-2.1 gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -I/daylight/v472/include \ -I/usr/local/include/python2.1 -c dayswig/dayswig_python.c -o \ build/temp.solaris-2.7-sun4u-2.1/dayswig_python.o ... gcc -shared build/temp.solaris-2.7-sun4u-2.1/dayswig_python.o \ build/temp.solaris-2.7-sun4u-2.1/daydepict_python.o \ -L/daylight/v472/lib -ldt_thor -ldt_merlin -ldt_progob -ldt_depict \ -ldt_monomer -ldt_datatype -ldt_finger -ldt_smarts -ldt_ipcx \ -ldt_smiles -lm -o build/lib.solaris-2.7-sun4u-2.1/dayswig_python.so ld: warning: global symbol `_DYNAMIC' has non-global binding: (file /usr/local/lib/gcc-lib/sparc-sun-\ solaris2.7/3.0.1/../../../libgcc_s.so value=LOCL); ld: warning: global symbol `_PROCEDURE_LINKAGE_TABLE_' has non-global \ binding: (file /usr/local/lib/gcc-lib/sparc-sun-\ solaris2.7/3.0.1/../../../libgcc_s.so value=LOCL); ld: warning: global symbol `_GLOBAL_OFFSET_TABLE_' has non-global binding: (file /usr/local/lib/gcc-lib/sparc-sun-\ solaris2.7/3.0.1/../../../libgcc_s.so value=LOCL); Bus Error (core dumped) Now what? Andrew dalke at dalkescientific.com From jblazi at hotmail.com Sat Oct 6 04:17:54 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Sat, 6 Oct 2001 10:17:54 +0200 Subject: creating a popup menu Message-ID: <3bbebe39_5@news.newsgroups.com> I am trying to create a popup menu: First I have button.bind('',x_menu) and then def x_menu(event): global menu menu=Menu(root,tearoff=0) menu.add_command('Edit',command=test) menu.add_command('Delete') menu.post(event.x_root,event.y_root,command=test) As far as I see this is the same code as in the example by Mr. Lundh (but for the canvas that I do not need). And it does not work, I get some weird Tkinter error messages instead (in "Tkinter.py line 960"). J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From dale at riverhall.NOSPAMco.uk Tue Oct 2 12:13:03 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Tue, 02 Oct 2001 17:13:03 +0100 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> Message-ID: "Steve Holden" wrote: >I think so. For a start it appears to mean that we can forget all about >class attributes ... > >I'm not sure why using a dictionary appears so evil to you, given that you >seem to need the dictionary for field validation anyway. Two possible >simplistic alternatives suggest themselves immediately, which might be >enough to loosen your thinking and give you a better solution for your >needs. > >1. Use names with a special prefix for the database fields, then you can >just test the attribute name using beginswith() or similar to determine >whether it's a database filed. > >2. Have objects store database fields inside another object (such as a >DatabaseTuple), so instead of assigning > > object.dbfield = value > >you assign > > object.db.field = value > >This localises the database fields and means you don't need __setattr__ on >the object itself. > >Of course there may well be valid reasons why neither of these approaches is >satisfactory. Explain why not, and others might well have better >suggestions. > >regards > Steve Steve, Thanks for sticking with this so far. The problem isn't with handling the database assignments. It's the fact that all instance assignments (self.anything) has to go through the same code. This is such an ugly overhead. Throughout the class, there are dozens of uses of instance variables which are forced through this code. I don't want to know about them. I guess I'd like to explicitly declare which attributes are part of the public face of the class and which are not. I assume my approach is as good as any. Thanks. -- Dale Strickland-Clark Riverhall Systems Ltd From ignacio at openservices.net Thu Oct 11 11:48:40 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 11 Oct 2001 11:48:40 -0400 (EDT) Subject: CGI question on input type=text form elements In-Reply-To: Message-ID: On Thu, 11 Oct 2001, DeepBlue wrote: > I am running into a strange problem with a form while using CGI module in > Python. > Let us say I have the following form: >

> > >
> > Now, let us say that test_form=cgi.FieldStorage() > If the above form is submitted without typing anything in the text field one > expects test_form.keys() to generate: > ['submit'] > > But i am getting: > ['text_1', 'submit'] > Which is unexpected, and in my case, undesirable. What am I doing wrong? You are assuming that the browser won't pass the contents of text_1 if it is empty. Obviously this isn't true. You need to fine-tune your code to deal with the case when it is empty. -- Ignacio Vazquez-Abrams From nas at python.ca Wed Oct 24 13:15:44 2001 From: nas at python.ca (Neil Schemenauer) Date: Wed, 24 Oct 2001 10:15:44 -0700 Subject: Question: CPython In-Reply-To: <3bd6f0f1_3@corp-goliath.newsgroups.com>; from aa@bb.cc on Wed, Oct 24, 2001 at 07:07:10PM +0200 References: <3bd6f0f1_3@corp-goliath.newsgroups.com> Message-ID: <20011024101544.A6603@glacier.arctrix.com> K?roly Ladv?nszky wrote: > What is CPython and where is it available? CPython is Python implemented in C. It's available at www.python.org where it is refered to as just Python. Neil From tdelaney at avaya.com Mon Oct 29 18:39:04 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 30 Oct 2001 10:39:04 +1100 Subject: python binary search Message-ID: > The proof reading and the spell checker can both be done. I will use > them in the future Just a note - glad to see you are taking this in the spirit it was intended :) Now, just watch for those tyops ... Tim Delaney From donod at home.com Tue Oct 23 20:47:04 2001 From: donod at home.com (Don O'Donnell) Date: Wed, 24 Oct 2001 00:47:04 GMT Subject: non-function members of string-module. References: <3BD58F4A.2000408@engineer.com> Message-ID: <3BD61042.CF3B72C1@home.com> Steven Cummings wrote: > > I'm not sure if this has already been discussed in public, but if we > want to phase out the use of the string module, then what is the plan > for its members, like letter, uppercase, etc.? > > /S I really hope the string module is never phased out. The string module functions are useful as arguments to the map function, as in: lines = map(string.strip, lines) and for other functional programming uses, where one wants to pass a function as an argument. Granted, a list comprehension could be used in place of the map function: lines = [line.strip() for line in lines] But it is slower than the map function since the loop is done in Python byte code rather than C. If, for whatever reason, the string module _is_ eliminated, perhaps the string module functions could be replaced by static methods of the str class. Then we could continue to use these static methods as though they were functions. Unfortunately, I guess the names would have to be changed since they are already being used as instance methods. How about just capitalizing the first letter of the name. Just replace: lines = map(string.strip, lines) with: lines = map(str.Strip, lines) # Strip is a static method of class str and it should continue to function as before. No? Cheers, Don From rikard at strakt.com Tue Oct 16 07:27:09 2001 From: rikard at strakt.com (Rikard Bosnjakovic) Date: Tue, 16 Oct 2001 13:27:09 +0200 Subject: Building a lib-wrapper, first step Message-ID: <3BCC198D.5010505@strakt.com> I've got a small library (Linux) and I want to create some wrapper-module so Python can use it. I've never done this before, so I'm looking for some tutorial or such for this purpose. Is there any documents describing this somewhere, step-by-step or something? Cheers, ------------------------------------------------------------------------ Rikard Bosnjakovic bos at hack.org (private) Python Hacker rikard at strakt.com (work) AB Strakt http://bos.hack.org/cv/ From m.faassen at vet.uu.nl Tue Oct 16 12:02:45 2001 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 16 Oct 2001 16:02:45 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> Message-ID: <9qhln5$fe6$1@newshost.accu.uu.nl> Andy Todd wrote: > "Andrew Dalke" wrote in > <9qe49r$4k1$1 at slb3.atl.mindspring.net>: >>Chris Tavares wrote: >>>May I be the first to say - ICK! >> >>I'll second that nomination. >> > And put me down for thirds ... So far I'm not charmed by it either.. Regards, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From qrczak at knm.org.pl Fri Oct 19 10:08:50 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 19 Oct 2001 14:08:50 GMT Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> <9qk0p9$6tulc$1@hades.rz.uni-sb.de> Message-ID: Wed, 17 Oct 2001 14:07:41 GMT, Michael Hudson pisze: > Moral: don't use mutable objects as dictionary keys. Unless mutations don't affect the hash value, and equal objects have equal hashes (it follows that mutations must not affect equality). Objects can be mutable as long as they are compared and hashed using their immutable parts. -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From dale at riverhall.NOTHANKS.co.uk Wed Oct 17 15:15:31 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 17 Oct 2001 20:15:31 +0100 Subject: Conditional Expressions don't solve the problem References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: Guido van Rossum wrote: >> Is iter handled more effeciently than this? > >Sure is -- here you are introducing an extra Python method call for >each item in the sequence; using iter(function, endCase) does the same >thing in C. > Excellent :-) -- Dale Strickland-Clark Riverhall Systems Ltd From Georg.Bisseling at pallas.com Fri Oct 19 10:07:28 2001 From: Georg.Bisseling at pallas.com (Georg Bisseling) Date: Fri, 19 Oct 2001 16:07:28 +0200 Subject: Triple-DES implementation in Python References: <1854cfa0.0110181325.50a4aba6@posting.google.com> Message-ID: <3BD033A0.BAC206BB@pallas.com> Krish wrote: > > Hello, > > Does anyone know if there is a publically available library for > DES/Triple DES implementation in Python. > > Thanks a bunch for the info. > KS If there is not already a crypto module/package for python: I would go to www.OpenSSL.org, get a free C implementation, learn how to integrate C extensions into python and do it. From fredrik at pythonware.com Sun Oct 28 04:36:14 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 28 Oct 2001 09:36:14 GMT Subject: FInding files with python References: Message-ID: "Widgeteye" wrote: > I'm trying to figure out how you would test for the existence > of a file on your drive in python. > > I want to write a little program that does the following: > > If (file exists) > do the following import os # check if there's a file with this name if os.path.isfile(filename): ... # check if there's anything with this name if os.path.exists(filename): ... From max at alcyone.com Tue Oct 9 13:38:19 2001 From: max at alcyone.com (Erik Max Francis) Date: Tue, 09 Oct 2001 10:38:19 -0700 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <7x4rp8q1cy.fsf@ruckus.brouhaha.com> <9pv6g9$ktdvl$1@ID-11957.news.dfncis.de> Message-ID: <3BC3360B.15CA155@alcyone.com> Emile van Sebille wrote: [Fixing top posting] > "Paul Rubin" wrote: > > > How about (3).foo? > > Because tuples have methods now. > > Python 2.2a4+ (#56, Oct 4 2001, 12:59:29) > [GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> dir(()) > ['__add__', '__class__', '__contains__', '__delattr__', '__eq__', '__ge__', > '__getattribute__', '__getitem__', '__getslice__', '__gt > __', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mul__', > '__ne__', '__new__', '__reduce__', '__repr__', '__rmul__', '_ > _setattr__', '__str__'] Irrelevant, since (3) isn't a tuple, it's an expression which evaluates to 3. You were thinking of (3,), but that's not what the original poster wrote. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ They make it a desert and call it peace. \__/ Tacitus Maths reference / http://www.alcyone.com/max/reference/maths/ A mathematics reference. From darnold02 at sprynet.com Tue Oct 30 20:29:55 2001 From: darnold02 at sprynet.com (Don Arnold) Date: Wed, 31 Oct 2001 01:29:55 GMT Subject: adding items from a text file to a list References: <48dbc3f6.0110301612.e0f863c@posting.google.com> Message-ID: <9rnk4g$8ct$1@slb2.atl.mindspring.net> i'm sure this will be answered a lot more succinctly and/or elegantly by others on the list, but here it goes: infile = open("c:/windows/desktop/myfile.txt","r") filecontents = infile.readlines() infile.close() thelist = [] for line in filecontents: commentstart = line.find("(") if commentstart > 0: thelist.append(line[:commentstart]) else: thelist.append(line) From ignacio at openservices.net Tue Oct 16 20:30:16 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 16 Oct 2001 20:30:16 -0400 (EDT) Subject: python library path on Debian LInux In-Reply-To: <1003274531.4259.9.camel@mycroft> Message-ID: On 16 Oct 2001, Avdi B. Grimm wrote: > I'm using Python on a Debian machine, and I've installed both the > python-1.5 and the python2 packages. I prefer to use python2. > Unfortunately, the way the Debian packages are arranged, many of the > additional libraries available for python (such as PyGTK) are as yet > only packaged for Python1.5. Apparently libraries packaged for different > Python versions are installed in different directories, and each python > executable only sees the libs that were packaged for it. > > Now, as I understand it, Python2 shouldn't have any difficulty using the > python1.5 versions of PyGTK, wxPython, and other such libs. (Correct me > if I'm wrong). My question is, how can I make the python2 executable > "see" the python1.5 lib dirs, in a way that is effective system-wide and > does not have to be specified on the command line every time python is > executed? You don't; you recompile PyGTK for whatever version of Python that python2 is. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From paoloinvernizzi at dmsware.com Mon Oct 29 08:16:18 2001 From: paoloinvernizzi at dmsware.com (Paolo Invernizzi) Date: Mon, 29 Oct 2001 13:16:18 GMT Subject: BOA GUI builder? References: <3BD9CC09.2B1AB020@mitre.org> <3BDC909B.4F500B9C@mitre.org> Message-ID: The "module" name is "boa"... Probably you can have a closer look using the "browse cvs" link on project page... Cheer Paolo Invernizzi "Angel Asencio" wrote in message news:3BDC909B.4F500B9C at mitre.org... > I went to the boa sourceforge site, and although I could find rhw CVS files > listed, I could not find a module name to dowload through CVS, nor a link to > download all the files related to V0.0.13. > > What am I missing? > > Thanks. > > Tim H wrote: > > > The version in CVS is much further along (0.0.13). You might want to try > > that. It works for me. You do have to modify it slightly, it is looking > > for wxPython 2.30 and we are both using 2.3.1, but if you got BOA 0.0.5 to > > work you should have no probs with that. > > > > Tim H > > "Angel Asencio" wrote in message > > news:3BD9CC09.2B1AB020 at mitre.org... > > Greetings: > > I got the BOA Python IDE from http://boa-constructor.sourceforge.net/. > > I looks great, but when I went to save the WxFrame.py from the tutorial, it > > gave me a Win2000 error, but I ignored it. > > Then when I went to save WxApp.py it crashed. > > I have Win2000, BOA 0.0.5, wxPython 2.3.1 and Python 2.1 > > Do I need to get some patch to stabilize BOA? > > Thanks, > > -- > > -Angel > From tim.one at home.com Mon Oct 1 03:19:23 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 1 Oct 2001 03:19:23 -0400 Subject: Near Final PEP 247 - API for Cryptographic Hash Functions In-Reply-To: <9p7mfr$mpf$1@panix3.panix.com> Message-ID: [Aahz] > That is all true, but you deleted my main point, which is that given > that the digest is in fact a bit string, is there any reason to avoid > future-proofing against new algorithms that may not return a > byte-integral number of bits? This *is* a PEP, after all. ;-) At this point I think Andrew should document that the digestsize is the number of bits divided by 8, conveniently represented as an integer for all known and expected algorithms: then he can be anally correct while still leaving the code usable in real life . not-expecting-19-bit-archictectures-to-come-back-in-vogue-and-any- future-19-bit-algorithm-won't-escape-its-thesis-ly y'rs - tim From mxp at dynalabs.de Fri Oct 19 10:38:26 2001 From: mxp at dynalabs.de (Michael Piotrowski) Date: Fri, 19 Oct 2001 16:38:26 +0200 Subject: configure and HP-UX Message-ID: I'm currently evaluating Python for a project, and the first thing to do was to build Python 2.2a4 on HP-UX 11. Judging from the archives, this is notoriously difficult, and it *did* take a lot of experimentation to get it right. However, it turned out that almost all problems are related to configure. I'm now putting together a patch for configure.in to fix these problems, but I have a question concerning the detection of thread support in configure.in (so this is not really a Python question, but since it is about *building* Python, I thought this is the best place to ask). configure.in uses the following approach (roughly): if pthread_create() in -lpthread # (1) # Darwin-specific action LIBS="-lpthread $LIBS" else if pthread_detach() available without a special library # (2) # Darwin-specific action; LIBS is *not* changed else [...] if __pthread_create_system() in -lpthread # (3) LIBS="-lpthread $LIBS" [...] Now, on HP-UX, (3) would be the correct result. However, since (2) succeeds, it is never tested for (3). But since in (2) -lpthreads is not added to LIBS, -lpthread is not used, and trying to use threads will fail. My question is, is there a special reason for having (2)? I can't really see what its purpose is. Thanks and greetings -- Michael Piotrowski, M.A. From maxm at normik.dk Tue Oct 23 09:54:56 2001 From: maxm at normik.dk (Max M) Date: Tue, 23 Oct 2001 15:54:56 +0200 Subject: My modules doesn't seem to reload in IIS asp pages Message-ID: <3bd576af$0$747$edfadb0f@dspool01.news.tele.dk> I am writing .asp pages with Python, and my modules doesn't seem to reload. I see changes i make in the html when editing the page, but changes I make in the modules does not go through. Isn't this correct? <%@ LANGUAGE="Python"%> <% import marcipan reload(marcipan) from marcipan.Receipees import Receipees, Categories # stuff rcps = Receipees() id = Request(rcps.getKey()) if str(id) != 'None': rcp = rcps.getOneById(id) else: rcp = rcps.getNew() %> Win2K, SP2, Python2.11 regards Max M From matt at mondoinfo.com Fri Oct 5 00:36:44 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Fri, 05 Oct 2001 04:36:44 GMT Subject: Tkinter PhotoImage Class??? References: <9pinf8$p3i$1@uranium.btinternet.com> Message-ID: On Thu, 4 Oct 2001 23:23:56 +0100, G. Willoughby wrote: >Has anyone got a piece of code to explain to me how to use the Tkinter >PhotoImage Class to display a .jpg inside a Tkinter Canvas object? No. And that's because Tkinter's PhotoImage class doesn't understand JPEG files. Fredrik Lundh says in his excellent An Introduction to Tkinter at (wrapped for line length) http://www.pythonware.com/library/tkinter/ introduction/x6338-options.htm regarding the PhotoImage class: The file can contain GIF, PGM (grayscale), or PPM (truecolor) data. Transparent regions in the GIF file are made transparent. To handle other file formats, use the corresponding class in the Python Imaging Library. And Fredrik's PIL is at http://www.pythonware.com/downloads/index.htm#pil and when you have it installed, you can do: >>> from Tkinter import * >>> import PIL.ImageTk >>> r=Tk() >>> i=PIL.ImageTk.PhotoImage(file="foo.jpg") >>> c=Canvas(r) >>> c.pack() >>> c.create_image(0,0,image=i) Regards, Matt From miker at 21stcenturyhealth.com Thu Oct 11 14:29:54 2001 From: miker at 21stcenturyhealth.com (Mike Ryan) Date: Thu, 11 Oct 2001 14:29:54 -0400 Subject: assignment in control structure syntax (was Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC3FCFC.21AF174@letterror.com> Message-ID: "Dale Strickland-Clark" wrote in message news:qtqast8mifvlmhpv3ft9die9ma211op90o at 4ax.com... > Chris Dutton wrote: > >The example I saw somewhere that I liked was > > > >if something as x: > > do_something_to(x) > > Presumably, 'something as x' assigns to x and yields x? > > It doesn't seem at all obvious to me. I had to think about it for a > while before figuring it out. Also, having an assignment working to > the right is very counter-intuitive. Actually, it's not all that different from the "import ... as ..." syntax of the statement: import spam as bacon dir(bacon) -- Michael Ryan Information Services Manager 21st Century Health and Benefits, Inc. From phr-n2001 at nightsong.com Fri Oct 5 21:54:31 2001 From: phr-n2001 at nightsong.com (Paul Rubin) Date: 05 Oct 2001 18:54:31 -0700 Subject: Quaternions in Python References: Message-ID: <7xhetd5y94.fsf@ruckus.brouhaha.com> I think there's a simple way to represent quaternions as 3x3 matrices. So you could probably just store them that way and use NumPy for the arithmetic. From ignacio at openservices.net Mon Oct 22 20:45:51 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Mon, 22 Oct 2001 20:45:51 -0400 (EDT) Subject: Smtplib module In-Reply-To: Message-ID: On 22 Oct 2001, David Bolen wrote: > > [snip] > > Given that you weren't suggesting that (using it to get closer to the > final target for better error status), then I'm somewhat confused as > to why anyone would bother with a manual MX lookup. It seems of > dubious benefit to just duplicate what your local mail system is > already (presumably) configured to do very well. Simply because it is not configured to pass the SMTP error code(s) back to the program from the eventual destination unless the destination is local. I have seen some MTAs and MTA-enhancment software that interferes with this (Bad Inflex, Bad!), but it's a lot better than the "shot-in-the-dark" approach of blindly forwarding everything to sendmail or the like. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From 63.199.26.230 Wed Oct 24 22:36:09 2001 From: 63.199.26.230 (63.199.26.230) Date: 25 Oct 2001 02:36:09 GMT Subject: Creating users on Windows NT Message-ID: <9r7tqp6mia@enews3.newsguy.com> Does anyone have sample code to create a user on a local or a remote NT machine? I'm trying to sort through this Microsoft WMI stuff because it seems like that would allow me to create a user on a local or a remote machine, but it's taking me forever to figure out where to start... Right now I'd be satisfied if I could just create a user from the Windows cmd.exe command line and simply call that from Python. Does anyone have experience with WMI and Python? Assume ActivePython... Yours, Noah ================================== Poster's IP address: 63.199.26.230 Posted via http://nodevice.com Linux Programmer's Site From thomas.heller at ion-tof.com Thu Oct 18 07:03:48 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 18 Oct 2001 13:03:48 +0200 Subject: Function arguments References: <9qm3sb$pc43f$1@ID-59885.news.dfncis.de> <9qm7st$4oek$1@mail1.wg.waii.com> Message-ID: <9qmcul$p2956$1@ID-59885.news.dfncis.de> "Martin Franklin" wrote: > Thomas Heller wrote: > > > Call me weird, but sometimes I need functions taking a number of > > positional arguments, some named arguments with default values, and > > other named arguments as well. > > > > Something like this (which does _not_ work): > > > > def function(*args, defarg1=None, defarg2=0, **kw): > > ... > > > -- snip -- > > > What about this: > > def function(defarg1=None, defarg2=0, *args, **kw): Doesn't work. A call like function(1, 2, 3) should result in args = (1, 2, 3), defarg1 = None, defarg2 = 0 Thomas From ibarona at tid.es Fri Oct 5 02:44:30 2001 From: ibarona at tid.es (Isaac Barona) Date: Fri, 05 Oct 2001 06:44:30 GMT Subject: Reading from the serial port? References: Message-ID: <3bbd55c1.86220384@tid> On Sat, 29 Sep 2001 15:41:05 GMT, grante at visi.com (Grant Edwards) wrote: >On Sat, 29 Sep 2001 13:08:25 GMT, Luis Rojas wrote: > >>I know this is probably a stupid question but how do i read the serial port >>or send information to it... i am new at this python stuff and i havent been >>able to find anything about serial port programing. > >There are a couple different serial-port wrapper packages that >make it easier to do serial port stuff. Under Unix, access to >the serial port is exactly the same as when you use C: >open/ioctl/tcgetattr/read/write. I've written a serial port >class for Posix serial ports. It's at > > ftp://ftp.visi.com/users/grante/python/PosixSerial.py > >Using the Win32all package from ActiveState.com, you can access >a Win32 serial port using standard Win32 semantics (there are >examples in the Win32all package). There is also a Win32 serial >port package somewhere, but the last time I tried to find it I >couldn't. > >Somebody recently wrote a cross-platform serial package that >has the same semantics under Unix and Win32. I don't have a >reference, but if you search comp.lang.pythong for subjects >containing "serial" you'll probably find it. The package is called USPP (Universal Serial Port Python) Library. You can get it from : http://balder.prohosting.com/ibarona/en/python/uspp/uspp_en.html > >-- >Grant Edwards grante Yow! .. over in west > at Philadelphia a puppy is > visi.com vomiting... From gabriel_ambuehl at buz.ch Mon Oct 1 04:33:44 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Mon, 1 Oct 2001 10:33:44 +0200 Subject: MySQLdb where's fetchoneDict()? In-Reply-To: <20010930144403.A562@lilith.hqd-internal> References: <112484592256.20010930103925@buz.ch> <20010930113122.A5634@lilith.hqd-internal> <169491440664.20010930123333@buz.ch> <20010930144403.A562@lilith.hqd-internal> Message-ID: <55570651213.20011001103344@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello Gerhard, Sunday, September 30, 2001, 2:44:05 PM, you wrote: >> AARGH. That means I can go and rewrite 2000 lines of code. (I >> wouldn't mean not being portable...) > I think it's classified as "deprecated" because it's nonstandard. Ah then its ok. Some people use deprecated synonymous to "ain't here any more cause it's bad" or "will go away in future cause it's bad". > I don't think you have to replace all fetchoneDict() with > fetchone() and ugly integer indices. Using cursorclass=MySQLdb.cursors.DictCursor helps but now the fetchone() / fetchall() methods return Dicts too which isn't really what's wanted cause in case of a "SELECT one_field FROM some_table" I'd normally use string=db.fetchone() which now breaks. Best regards, Gabriel  -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO7gcW8Za2WpymlDxAQEubQf/XzxocofiN/xKPROzuWYLux3R/5KqA4u+ RXKB6rXPyZyx9bThyzlMfNuDaOg7hIkxxIJa3rhBEnUwqtPCfFUIPRfon8juYeZN tUSXt9bfu4CPCMpHWiXPs8HjaXIjFfa6E/E56QA2vG9plogb82AoqYgWi7vIVH5c 0NSkGkcp3YVIhlhNRI0YyE7ze55qzLJg7kbdeAxA3kSII2Xtuf5vhLEehHMl/Obi yJ3SUznRgq8U0rxlfr8ASMCEQFpynPdIMNn2XkXJcRszfIPp0IRfmVXqWYXDfeS+ /hUOMlmymX5H8evKaOGs6Ayh9ihrgwMIonoBwqAXRRTGh3hE/eGqiQ== =vgnL -----END PGP SIGNATURE----- From martin.franklin at westgeo.com Tue Oct 16 03:54:16 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Tue, 16 Oct 2001 08:54:16 +0100 Subject: TkTable References: <3bcb1592$1_5@news.newsgroups.com> Message-ID: <9qgov0$1ak6$1@mail1.wg.waii.com> Janos Blazi wrote: > Is there a way to use tkTable from within Tkinter? > > Thx in advance, J.B. > > > > > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- > http://www.newsfeeds.com - The #1 Newsgroup Service in the World! > Check out our new Unlimited Server. No Download or Time Limits! > -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- > Google (TkTable python) turns this up...... http://starship.python.net/crew/pgodman/ HTH Martin From sholden at holdenweb.com Sun Oct 28 16:51:32 2001 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 28 Oct 2001 16:51:32 -0500 Subject: os.system() and cgi References: Message-ID: "M. Ibaraki" wrote ... > This script (test.py) works fine and creates a file 'outputfile' when > I run this in test mode (python test.py). > > > --- test.py ---- > #!/usr/bin/python > > import cgi, os > > print "Content-type: text/html\r\n" > print "" > print "" > > ret = os.system('/usr/X11R6/bin/xmgrace -help > outputfile') > # ret = os.system('/bin/ls > outputfile') > > print "

ret = ", ret > ---------------- > > > > It shows: > > Content-type: text/html > > > >

ret = 0 > > > > However, when this is executed as a cgi it shows: > > ret = 256 > > and no 'outputfile' file is created. > > > > Permission of /usr/X11R6/bin/xmgrace is: > -rwxr-xr-x 1 root root 450 May 20 18:48 > /usr/X11R6/bin/xmgrace > > xmgrace is a 2D plotting tool > (http://plasma-gate.weizmann.ac.il/Grace/) > > The problem is almost certainly because you are executing an X Window client application in a context which makes it unable to open an X Window to display its output. However, this is only a deduction from the documentation you have referred to, which explicitly points out that "xmgrace" is the GUI-based version of the program. You might get a better result by using "grace" rather than "xmgrace". You might also want to look at the error logs of your web server to see whether you get any messages from the X Window system. regards Steve -- http://www.holdenweb.com/ From christopher.abraham at verizon.net Tue Oct 23 16:14:25 2001 From: christopher.abraham at verizon.net (Chris Abraham) Date: Tue, 23 Oct 2001 16:14:25 -0400 Subject: Looking for Zope & Python Gurus' R=?ISO-8859-1?B?6XN1bek=?=s for Future Projects Message-ID: PIGgies: I would like to have a file of Zope & Python coders who are available for short-term, long-term, contract, sub-contract work, project-based, and "crap, it broke can you fix it?" work. Either in the Washington Metro Area or via Telecommuting. If you are out of the DC-Area, please send your r?sum? anyway, and I will keep it on file. I am getting lots of requests and I want to make sure that I have loads of people who might be interested in the projects. Please send your r?sum? and an hourly, day, and salary range and I will do what I can. Cheers, Chris Abraham -- chrisabraham +12024527442wk +12024780276fx aim:chrisphur icq:46181597 Post Office Box 15163 Washington DC 20003-0163 United States From richard at bizarsoftware.com.au Fri Oct 5 02:51:44 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 5 Oct 2001 16:51:44 +1000 Subject: Boy do REs ever suck sometimes... In-Reply-To: References: Message-ID: <01100516514402.10490@ike> On Friday 05 October 2001 16:45, Ignacio Vazquez-Abrams wrote: > Here's the problem I'm having with REs. When I use an RE like '^[0-9]+$' it > matches both '123' and '123\n'. How can I get it to not match the string > with the newline? Is this any help? >>> re.match('^[\d]+$', '123') >>> re.match('^[\d]+$', '123\n') >>> re.match('^[\d]+$', '123').end() 3 >>> re.match('^[\d]+$', '123\n').end() 3 Richard From sholden at holdenweb.com Thu Oct 4 23:43:34 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 23:43:34 -0400 Subject: SQL/Python question -- slow... What is the fixed cost? References: <3BBB7DFD.25217E1A@iems.nwu.edu> <3bbc26d3.1098181651@spamkiller.newsfeeds.com> <3BBC8E99.56BD59FB@iems.nwu.edu> <3BBCF0D0.29A3CB9E@iems.nwu.edu> Message-ID: "Leonardo B Lopes" wrote in message news:3BBCF0D0.29A3CB9E at iems.nwu.edu... > Me DB is in 3NF. And I know that 83K isn't that big, but it is big > enough to make a query last .0008 cpusec. when joined w/ 2 other tables > (That is the actual amount, before rounding). The problem is that a > query on a table with only 12 items also takes about the same time. So I > need to know how much time the library is using for data checking, > network connection, etc... > > Actually today I created the following db: > > CREATE database ATOM > CREATE TABLE atomic (id MEDIUMINT PRIMARY KEY) > INSERT INTO atomic (id) VALUES (3) > > and the following python code: > > 1 #!/usr/bin/env python > 2 > 3 import MySQLdb > 4 import profile > 5 > 6 db = MySQLdb.connect(passwd='Iwanit2') > 7 c = db.cursor() > 8 > 9 def test(): > 10 for i in range(0,10000): > 11 c.execute('select * from atomic where id=3') > 12 x = c.fetchall() > 13 > 14 c.execute('use atom') > 15 profile.run('test()') > > and here are the (best) results: > > ncalls tottime percall cumtime percall filename:lineno(function) > 1 0.000 0.000 5.250 5.250 :1(?) > 10000 1.600 0.000 2.860 0.000 cursors.py:110(__do_query) > 10000 0.210 0.000 0.210 0.000 cursors.py:137(_fetch_row) > 10000 0.390 0.000 0.390 0.000 > cursors.py:147(_check_for_warnings) > 10000 0.400 0.000 0.690 0.000 > cursors.py:162(_get_result) > 10000 0.530 0.000 3.600 0.000 cursors.py:169(_query) > 10000 0.310 0.000 0.420 0.000 cursors.py:193(fetchall) > 10000 0.110 0.000 0.110 0.000 > cursors.py:36(_check_executed) > 30000 0.690 0.000 0.690 0.000 cursors.py:46(_get_db) > 10000 0.660 0.000 4.480 0.000 cursors.py:51(execute) > 0 0.000 0.000 profile:0(profiler) > 1 0.010 0.010 5.260 5.260 profile:0(test()) > 1 0.350 0.350 5.250 5.250 testdb.py:10(test) > > Apparently, .0004 is a Lower Bound on how fast a query can be, and that > is not good news for me. > > Now with this small change to the script: > > 1 #!/usr/bin/env python > 2 > 3 import MySQLdb > 4 import profile > 5 > 6 db = MySQLdb.connect(passwd='Iwanit2') > 7 c = db.cursor() > 8 > 9 def test(): > 10 for i in range(0,10000): > *** 11 c.execute('select * from mematomic where id=3') > 12 x = c.fetchall() > 13 > 14 c.execute('use atom') > *** 15 c.execute(' CREATE TABLE mematomic (id MEDIUMINT PRIMARY KEY) \ > *** 16 TYPE = HEAP') > *** 17 c.execute(' INSERT INTO mematomic (id) VALUES (3)') > 18 profile.run('test()') > 19 > > and the new results: > > ncalls tottime percall cumtime percall filename:lineno(function) > 1 0.000 0.000 5.920 5.920 :1(?) > 10000 1.440 0.000 2.910 0.000 cursors.py:110(__do_query) > 10000 0.200 0.000 0.200 0.000 cursors.py:137(_fetch_row) > 10000 0.520 0.000 0.520 0.000 > cursors.py:147(_check_for_warnings) > 10000 0.600 0.000 0.760 0.000 > cursors.py:162(_get_result) > 10000 0.650 0.000 3.760 0.000 cursors.py:169(_query) > 10000 0.380 0.000 0.500 0.000 cursors.py:193(fetchall) > 10000 0.120 0.000 0.120 0.000 > cursors.py:36(_check_executed) > 30000 0.560 0.000 0.560 0.000 cursors.py:46(_get_db) > 10000 1.000 0.000 4.970 0.000 cursors.py:51(execute) > 0 0.000 0.000 profile:0(profiler) > 1 0.010 0.010 5.930 5.930 profile:0(test()) > 1 0.450 0.450 5.920 5.920 testdb.py:9(test) > > So even with a temporary table always in memory, the overhead hasn't > changed much. Comments? > I think about the only comment I'm prepared to make is that if 400 microseconds isn't good enough retrievall performance you should not be using relational technology at all. When I suggested using memory, I didn't mean you should use memory-based relations, I meant you should use Python data structures. If performance is so critical, relational structures simply aren't appropriate when they don't give adequate performance! regards Steve -- http://www.holdenweb.com/ From timr at probo.com Tue Oct 30 01:35:03 2001 From: timr at probo.com (Tim Roberts) Date: Mon, 29 Oct 2001 22:35:03 -0800 Subject: [Tutor] Re: How to change Windows Environment Variable References: Message-ID: dman wrote: >| >| Bad news: >| >| There is no SetEnvironmentVariable() function. > >See the 'os' module. > >>>> import os >>>> print os.putenv.__doc__ >putenv(key, value) -> None >Change or add an environment variable. >>>> > >The 'os.environ' attribute is a dict containing all the environment >variables. However, that information does not help the original poster. os.putenv (which is actually disrecommended in favor of directly writing to the os.environ dictionary) only affects the environment we pass to our child processes. When you exit Python, all your os.environ changes go away. The Win32 SetEnvironmentVariable, on the other hand, makes a lasting change to the current environment. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gh_pythonlist at gmx.de Thu Oct 25 18:33:25 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 26 Oct 2001 00:33:25 +0200 Subject: is copy_reg still 'proper' ? In-Reply-To: <3BD88B9C.1070606@visionart.com>; from pete@visionart.com on Thu, Oct 25, 2001 at 03:01:00PM -0700 References: <3BD88B9C.1070606@visionart.com> Message-ID: <20011026003324.A13286@lilith.hqd-internal> I have a related question: Is there an example of using the __setstate__/__getstate__ pair to make a Python 2.2 type-class pickleable? For example if I have a type that implements the number protocol but should also be pickleable. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From ian at atlas.science-computing.de Thu Oct 11 09:29:15 2001 From: ian at atlas.science-computing.de (Jan Wender) Date: 11 Oct 2001 13:29:15 GMT Subject: Borg Pattern Class usable from other classes? References: Message-ID: <9q46rb$5fk$1@news.BelWue.DE> Jan Wender wrote: > Hi, > I tried to use the Borg Pattern from Alex Martelli > (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531). I have one file > containing the Borg class. In another file I defined a second class which wants > to access the information from the Borg class. It instantiates an object from > the Borg class, but it seems that the class dictionary __shared_state gets newly > initialized, rendering it empty. Any ideas to get it working? I tried already to > use a module global dict in a.py, and also different access paths for the dict, > to no avail. It gets more confusing: If I add an accessor class to a.py: class Test: def __init__(s): s.c = Borg() def acc(s): return s.c.t and instantiate and call t.acc() from within a.py it works ok, but if I instantiate and call it from a class in b.py, I get an AttributeError as before. Whats going on here? Cheerio, -- J.Wender at science-computing.de - Fon +4970719457-257 Fax-211 science+computing ag - Hagellocher Weg 71-75 - 72070 T?bingen UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. (Doug Gwyn) From chris.gonnerman at newcenturycomputers.net Mon Oct 8 08:06:21 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Mon, 8 Oct 2001 07:06:21 -0500 Subject: safe simultaneous file append? References: <3np2st060vt841lqfimibi12909td1p02c@4ax.com> <9prtkc$56a$1@samos.cs.uu.nl> <1cv2st0g180m0cfoloqf99s5pofe4pmi32@4ax.com> Message-ID: <004101c14ff1$a9e11e20$0101010a@local> ----- Original Message ----- From: "Dale Strickland-Clark" > > Erk! There's a recipee for disaster unless treated very carefully. > > Handy if you're careful, though, I guess. Huh. I've used this feature for years under a variety of Unixoids with no problem. The only thing you need to do for safety is to ensure that complete messages are written by a single write(2) call. Do this: logfile.write("A long message...\n") rather than this: logfile.write("A ") logfile.write("long message...") logfile.write("\n") (for instance) It wouldn't hurt to add logfile.flush() after each write. I have a logfile assistant in my Python Plumber's Helpers at http://newcenturycomputers.net/projects/plumbers.html if anyone is interested. From calves at coelce.com.br Wed Oct 31 12:37:35 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Wed, 31 Oct 2001 14:37:35 -0300 Subject: connecting database Message-ID: <29A97D00F387D411AC7900902770E148024B784D@lcoeexc01.coelce.net> How can I connect to databases?! Carlos Alberto COELCE/DPRON-Departamento de Projetos e Obras Norte Fone: 677- 2228 e-mail: calves at coelce.com.br \|||/ (o o) --ooo0-(_)-0ooo-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From huaiyu at gauss.almadan.ibm.com Wed Oct 10 18:00:13 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 10 Oct 2001 22:00:13 +0000 (UTC) Subject: assignment in control structure syntax (was Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC3FCFC.21AF174@letterror.com> Message-ID: I have an alternative syntax that could satisfy both safety and simplicity. It did not receive much notice the last time here, though. The full explanation is at http://www.geocities.com/huaiyu_zhu/python/ififif.txt On Wed, 10 Oct 2001 09:47:11 +0200, Just van Rossum wrote: >Paul Rubin wrote: > >> Anyway, I can live with "while x:=get_next()" instead of x=get_next. >> But I feel seriously cramped in Python when I have to say >> >> while 1: >> x=get_next() >> if not x: break >> whatever(x) >> >> so I hope something is done about the issue. while x = get_next(); x: whatever(x) > >I think this is the wrong example, as it can easily be written as a >for loop. Iterators in 2.2 will make that even more natural. Now if >you meant this: > > m = someRegex.match(...) > if m: > ... > >vs. > > if m := someRegex.match(...): > ... > >you may have a point... > >Just if m = someRegex.match(...); m: ... There are several other uses for this syntax. For example, if val = dict1[key1]; val: process1(val) elif val = dict2[key2]; val: process2(val) elif mylist += otherlist; len(mylist) > 4: process3(mylist) ... These are arguably easier to understand than current Python syntax. See the link above for more examples. Is there much interest to turn this into a PEP? Huaiyu From sill at optonline.net Sat Oct 13 06:30:56 2001 From: sill at optonline.net (Andrei Kulakov) Date: Sat, 13 Oct 2001 10:30:56 GMT Subject: a pure python mp3 player? References: <9q50uh$qlj$1@uranium.btinternet.com> Message-ID: On Thu, 11 Oct 2001 21:56:16 +0100, G. Willoughby wrote: > Hi, > do you know of any mp3 players that have been exclusively written in > python, and not just a gui for the C coded 'mp123'? > > G. WIlloughby Why exactly are you asking? If you want things like.. looking at the frames so that you can make a graphic analyzer or something, you can plug in mpeglib or xaudio (they have what looks like a nice python interface, too). I'm pretty sure there's no decoder written in python - I looked for one extensively before writing Cymbaline. - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From neal at metaslash.com Sat Oct 20 09:29:52 2001 From: neal at metaslash.com (Neal Norwitz) Date: Sat, 20 Oct 2001 09:29:52 -0400 Subject: silly idea - interesting problem References: Message-ID: <3BD17C50.9D7D35AE@metaslash.com> Stefan Antoni wrote: > > i got a silly idea about a small script which takes to strings (lets say > "test" and "dust") and mixes them to "tdeusstt". > i tried to code it because i thought it would be easy, but now i cannot > find out _how_ to do it ;) > > i tried to "list()" the string and mix the items. but ... > > Anybody has a hint or even a solution? ''.join([ a for x in zip('test', 'dust') for a in x ]) Can't think of an easier (or cleaner) way. Neal From john at yates-sheets.org Fri Oct 19 16:44:26 2001 From: john at yates-sheets.org (John S. Yates, Jr.) Date: Fri, 19 Oct 2001 20:44:26 GMT Subject: proposed unittest enhancement Message-ID: <2u01tt424stt9h6bt5m6atpd9qsg316090@4ax.com> I am new to the Python community and hence unsure of how to submit proposed changes to the standard distribution. If posting to this ng is inappropriate please redirect me. I am using unittest. To support coverage testing I want to compute large numbers of very similar tests. It is important that once an error has been detected I be able to run that single case without the noise of all the other coverage cases. My approach is to add test methods to the TestCase during module initialization. I do this by evaluating a lambda inside a series of nested for loops and use default para- meters to effect a closure. Example: ========= class computedTests( TestCase ): def doTest( self, i, j ): print "i=%s, j=%s" % (i, j) for i in range(3): for j in range(2): setattr( computedTests, \ "test_%s_%s" % (i, j), \ lambda self, ii=i, jj=j: self.doTest( ii, jj ) ) ========= This works great as long as I am interested in running all the tests. Once I specify an individual test I stumble on a "bug" in unittest.TestLoader.loadTestsFromName. When the type analysis determines that a looked-up attribute is an UnboundMethodType it assumes that the function object was introduced by a "def" statement rather than a lambda and hence that it has a meaningful __name__ attribute: elif type(obj) == types.UnboundMethodType: return obj.im_class(obj.__name__) This assumption is unnecessary since the type analysis was immediately preceded by a getattr() call in which the name was passed as an argument: obj = getattr(obj, part) I suggest this small change to the UnboundMethodType case: elif type(obj) == types.UnboundMethodType: return obj.im_class(part) /john From krissepu at vip.fi Tue Oct 2 15:56:06 2001 From: krissepu at vip.fi (Pekka Niiranen) Date: Tue, 02 Oct 2001 22:56:06 +0300 Subject: Problem with COM and Excel Message-ID: <3BBA1BD5.8E833283@vip.fi> How can I run AutoFit to all columns of my Excel sheet from python ? I have tried: >>> xlApp = win32com.client.dynamic.Dispatch('Excel.Application') >>> xlBook = xlApp.Workbooks.Add() >>> sht = xlBook.Worksheets("Sheet1") >>> xlApp.Visible = 1 So far so good, but at this stage I added some values to Excel Sheet (manually) and then run: >>> sht.Columns().AutoFit The whole PC is jamming with harddisk running madly. I have to use task manager to kill Idle and Excel. -pekka- From uwe at rocksport.de Tue Oct 30 07:22:02 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 30 Oct 2001 12:22:02 GMT Subject: Matlab-style mask in Python?? References: Message-ID: <9rm61a$86i6n$1@hades.rz.uni-sb.de> Ozone Hole near South Pole wrote: | Hi, | I am a long time Matlab user. I just picked up Python for a short | while. | I wonder what should be the best way to do sth like: | Matlab: | a=[3,4,6,7,2,54,2,1,2] | idx=a>4 ans: [0,0,1,1,0,1,0,0,0] | a(idx) ans: [6,7,54] | Python: | a=[3,4,6,7,2,54,2,1,2] | idx=map(lambda x: x>4,a) #assume this calculation is lengthy | #and we don't want to repeat | last cmd??? | While we can always put that into a for loop, then append the ans | element-by-element.... I feel there should be an easier way in | Python. | Any suggestions? have a look at Numerical Python http://www.numpy.org. I think it will help you. Greetings, Uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From cliechti at gmx.net Tue Oct 23 14:39:18 2001 From: cliechti at gmx.net (Chris Liechti) Date: 23 Oct 2001 20:39:18 +0200 Subject: Speeding up a regular expression References: Message-ID: >> lines = string.split(inputString,"\n") retlist = [] >> for line in lines: >> if myRe.match(line): retlist.append(line) return '\n'.join(retlist) #newer python versions ## return string.join(retlist,'\n') #for py 1.5.2: extending strings does require lots memory allocations and compying the strings, a list is far more efficient when changes are made on it. if the data comes from a file you could also use f.readlines() and omit split(). you could also use "filter()", that moves the python for-loop to the fast loop in C in filter: return '\n'.join(filter(myRe.match, lines)) hope that helps chris -- Chris From thomasNO at SPAM.obscure.dk Tue Oct 16 21:57:34 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Wed, 17 Oct 2001 01:57:34 GMT Subject: profiler results for __getattr__, am I reading this correctly ? References: Message-ID: Hi again, Forgot to mention system and version, sorry :-( Python: 2.1.1 [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 OS: FreeBSD 4.4-RELEASE -- Best Regards Thomas Jensen From db3l at fitlinxx.com Mon Oct 22 15:11:30 2001 From: db3l at fitlinxx.com (David Bolen) Date: 22 Oct 2001 15:11:30 -0400 Subject: Magic Module Methods? References: <9qt1qm$f7l$1@tyfon.itea.ntnu.no> Message-ID: Skip Montanaro writes: > Let me suggest another reason __getattr__ might be useful for modules. > Suppose you had a package made up of lots of modules. Instead of importing > all of those modules into the package when the package was imported, with > __getattr__ could you defer import until first access? Although you can already do this today via other mechanisms. For example, the LazyModule class used by the mx packages - an instance is assigned in the main module __init__ to each submodule name. Then as a class instance, it does get the __getattr__ call at which point it imports the child module and then loads its dictionary into its own instance. Also, a downside to any of the "lazy" schemes is that they tend to do a nice job of confusing packaging tools such as py2exe and installer. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From krodgers at ryanaero.com Mon Oct 8 16:22:14 2001 From: krodgers at ryanaero.com (Kevin Rodgers) Date: 8 Oct 2001 13:22:14 -0700 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> <3BBE6A57.FD354FE3@alcyone.com> <7xlmipcji1.fsf@ruckus.brouhaha.com> Message-ID: <42c4d2d.0110081222.53963481@posting.google.com> Carl Banks wrote in message news:... > Paul Rubin wrote: > > Erik Max Francis writes: > >> > I think there's a simple way to represent quaternions as 3x3 matrices. > >> > So you could probably just store them that way and use NumPy for the > >> > arithmetic. > >> > >> ... which rather defeats the purpose for using quaternions in the first > >> place. > > > > Nah. I mean, if efficiency was a big issue, you wouldn't be using an > > interpreted language in the first place. What's left, if you have a > > good matrix package, is something like if your language had complex > > numbers but didn't have reals. You can still represent the reals as > > complexes. For that matter, lots of languages have had reals but no > > integers. It hasn't been that bad a problem. > > You severely underestimate the difficulty of doing this. While any > quarternion can be represented as a 3x3 matrix, not every 3x3 matrix > is a quarternion. And keeping your matrix in "quarternion form" when > you do arithmetic is not trivial. > > To wit, a quarternion has 4 components. A 3x3 matrix has 9 > components. Therefore, when doing quarternion arithmetic using a 3x3 > matrix, you must be sure the resulting matrix satisfies 5 constraints. > And, IIRC, the constraints are not simple. > > (Contrast this to using a complex as a real. Here, only one very > simple constraint, namely Im(z)==0, must be maintained.) All of you are missing some aspect of the situation: (1) The problem is how to represent an arbitrary 3-axis coordinate rotation in a mathematically robust way. (2) Quaternions and direction cosine matrices (the 3x3 matrix referred to above) are two equivalent ways of doing this. (3) Euler angles are NOT mathematically robust. Euler angles are a set of three rotations to get from coordinate system A to coordinate system B. The rotations are done in a specified order. The problem is that, no matter what the order in which you do the three rotations, there is always a value for one angle of rotation that yields infinite values of the other two angles. For example, aircraft Euler angles are normally represented as yaw, pitch, and roll, in that order. Given that order of rotation, it is pretty straightforward to show that when the pitch angle is straight up or straight down, the values of yaw and roll are undefined. In a physical gimbal system, this is known as gimbal lock. (4) For physical gimbals, gimbal lock is resolved by adding a fourth gimbal. For mathematical techniques, both the four-element quaternion and the nine-element direction cosine matrix resolve the gimbal lock phenomenon. (5) A rotation quaternion can always be converted into an equivalent direction cosine matrix, and vice versa. Note that not all 3x3 matrices are direction cosine matrices, however. (6) The number of constraints on the 3x3 matrix are less than described. A direction cosine matrix has only six independent parameters, not nine. One column of the matrix can be always be recovered by the cross product of the other two. There is an orthogonality constraint between the two independent columns, however, and this is somewhat more complex than the quaternion normalization constraint (which is just that the root-sum-square of the quaternion components be unity). (7) Lots of application areas use both quaternions and direction cosine matrices. For inertial navigation applications, quaternions are often used in the numerical integration of the differential equations of motion, then immediately converted to direction cosine form. This is because there are a lot of operations that are computationally more efficient to perform using the direction cosine form of the transformation. (8) Use whatever combination of quaternions and direction cosine matrices your problem needs. For lots of practical problems, you can even get by with Euler angles! Kevin Rodgers "This one goes up to eleven." -- Nigel Tufnel From sholden at holdenweb.com Tue Oct 9 07:14:52 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 9 Oct 2001 07:14:52 -0400 Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com><9pimak$c22$1@tyfon.itea.ntnu.no><825v7.1025$rq1.37994@atlpnn01.usenetserver.com><3BBE4E12.16FE036A@earthlink.net> <9pn44q$m1r$1@tyfon.itea.ntnu.no><3BBF2751.3010309@sneakemail.com> <23891c90.0110090118.7df7917e@posting.google.com> Message-ID: "Ken Guest" wrote in ... > On Tue, 2001-10-09 at 10:18, Paul Boddie wrote: > > Joshua Macy wrote in message news:<3BBF2751.3010309 at sneakemail.com>... > > > > > > Moses is to the Bible what Tim Peters is to Strunk and White (or > > should it be the other way round?)-ly, > > and what exactly does this have to do with python? > I thought this was a python list not a linquistics list. > Calm down. We don't wear asbestos pants in this group! It *is* a Python list (well, newsgroup in my case), but people do wibble now and then. sorry-this-wasn't-about-python-either-ly y'rs - steve -- http://www.holdenweb.com/ From logiplexsoftware at earthlink.net Wed Oct 31 14:57:55 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 31 Oct 2001 11:57:55 -0800 Subject: newbie question In-Reply-To: <3be053e7.293796@news1.lig.bellsouth.net> References: <3be053e7.293796@news1.lig.bellsouth.net> Message-ID: <01103111575507.06896@logiplex1.logiplex.net> On Wednesday 31 October 2001 11:49, lance crocker wrote: > i just tried putting that path into the autoexec file and rebooting. > it didn't change anything i still get the same errors. > > when you go to open a file how do you do it? do you type python > hello.py while you are in commandline mode or while you are in gui > mode? There was an earlier post with the answer to your question. In your original post you said you did the following: >>> python hello.py SyntaxError: invalid syntax >>> The ">>>" shows me that you are _in_ the Python interpreter. That means you don't need to try to run it again (in fact, as you discovered, you can't). Instead, at the DOS/Windows command line, type c:\>python hello.py be sure you are in the same directory as hello.py Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From bh at intevation.de Tue Oct 9 13:17:08 2001 From: bh at intevation.de (Bernhard Herzog) Date: 09 Oct 2001 19:17:08 +0200 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> Message-ID: <6qk7y4ohrf.fsf@abnoba.intevation.de> David Bolen writes: > but why would you ever invoke a method on a numeric literal in your source? IMO something like >>> map(1 .__add__, [0, 5, 7, 2]) [1, 6, 8, 3] >>> can come in handy. Of course this particular example may be clearer with list comprehensions. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://mapit.de/ From dsh8290 at rit.edu Mon Oct 29 18:05:01 2001 From: dsh8290 at rit.edu (dman) Date: Mon, 29 Oct 2001 18:05:01 -0500 Subject: [Tutor] Re: How to change Windows Environment Variable In-Reply-To: ; from ignacio@openservices.net on Thu, Aug 30, 2001 at 08:14:06PM -0400 References: Message-ID: <20011029180501.A3928@harmony.cs.rit.edu> On Thu, Aug 30, 2001 at 08:14:06PM -0400, Ignacio Vazquez-Abrams wrote: | On Fri, 31 Aug 2001, ??? wrote: | | > Dear all, | > | > How to change environment variable on Windows NT or 2000 by python? | > | > In Visual Basic case can setting as below: | > | > Private Declare Function GetEnvironmentVariable Lib "kernel32" _ | > Alias "GetEnvironmentVariableA" (ByVal lpName As String, _ | > ByVal lpBuffer As String, ByVal nSize As Long) As Long | > | > Private Declare Function SetEnvironmentVariable Lib "kernel32" _ | > Alias "SetEnvironmentVariableA" (ByVal lpName As String, _ | > ByVal lpValue As String) As Long | > | > I will waiting for good news. | > Thanks. | > MyeongKi Han | | Good news: | | There is a GetEnvironmentVariable() function in the win32api module. | | Bad news: | | There is no SetEnvironmentVariable() function. See the 'os' module. >>> import os >>> print os.putenv.__doc__ putenv(key, value) -> None Change or add an environment variable. >>> The 'os.environ' attribute is a dict containing all the environment variables. -D From jeff at ccvcorp.com Thu Oct 11 14:42:19 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 11 Oct 2001 11:42:19 -0700 Subject: upload file using cgi on Win2k IIS References: Message-ID: <3BC5E80B.9060ECC9@ccvcorp.com> Jason McWilliams wrote: > > Here is something interesting. I can upload .txt and .doc files no > problem, > no matter what the size. Things die when trying to upload .gif or .zip > or .tgz > or other binaries similar. Some of it gets uploaded, but only a small > portion? > > I am at a loss now. A wild guess--is it possible that the binary files have an embedded EOF-character? IIS (or Windows) could conceivably see that embedded character and decide that it is indeed at the end of file, even though there's more data in the real file.... Jeff Shannon Technician/Programmer Credit International From someone at _no-spam_arbitrary.org Wed Oct 17 13:51:51 2001 From: someone at _no-spam_arbitrary.org (Joseph Santaniello) Date: Wed, 17 Oct 2001 10:51:51 -0700 Subject: Help optimize a script? Message-ID: Hello All, I have a simple script that I wrote to convert some fixed-width delimted files to tab-delimited. It works, but some of my files are over 100MB and it takes forever. First, does anyone know of a tool that does this so I don't have to reinvent the wheel, and barring that, can anyone offer some tips on how to optimize this code: indecies = { 'cob':[3,6,2,2,8,1,8], 'opend':[6,3,3,2,3,4,12,29] } # above is trimmed for this example # the lists in these dictionaries above are are the widths of the fields # in the input files. The keys match the input file names just to keep things readable. # while is used cuz line in readlines() used too much ram with # huge files. while 1: line = sys.stdin.readline() if not line: break new = '' start = 0 for index in indecies[sys.argv[1]]: new = new + string.strip(line[start:start + index])+'\t' start = start + index print new So it reads in a line, then iterates over the list in he corresponding dictionary, and prints stripped substrings extracted according the the field widths in the list, printing a tab between each, then grabs a new line and does it again. Any suggestions on how to speed this up? Thanks, Joseph From markus at schabi.de Tue Oct 2 15:14:37 2001 From: markus at schabi.de (Markus Schaber) Date: Tue, 2 Oct 2001 21:14:37 +0200 Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> Message-ID: <2169419.EU6C4ouqhe@lunix.schabi.de> Oleg Broytmann schrub: > On Tue, Oct 02, 2001 at 08:59:34AM -0500, Paul Miller wrote: >> If GNU code is FREE, then I'll have to say that Python (and code >> under BSD-style licenses) is BETTER THAN FREE. Frankly, I'm very >> grateful to Guido for allowing Python to be used freely in commercial >> software. > > I see your point. You use other's people work without paying them. > GNU > GPL, at least, force you to pay (by publishing your code). You don't > want to pay, and Python license makes you happy :( Well - Even the GCC developers and thus the FSF itsself hat to accept the "GCC Exception" in their license, AFAIR. markus -- "The strength of the Constitution lies entirely in the determination of each citizen to defend it. Only if every single citizen feels duty bound to do his share in this defense are the constitutional rights secure." -- Albert Einstein From arigo at belgacom.net Wed Oct 10 18:59:23 2001 From: arigo at belgacom.net (Rigo Armin) Date: Thu, 11 Oct 2001 00:59:23 +0200 Subject: Psyco Specializing Compiler Message-ID: <3bc4d2e4$0$36473$ba620e4c@news.skynet.be> Hello everybody, "Psyco", the Python Specializing Compiler I introduced some time ago on the python-dev mailing list, is beginning to work. Its goal is to accelerate execution of any Python program by dynamically compiling several "specialized" versions of your code directly in machine code. For more info see http://homepages.ulb.ac.be/~arigo/psyco/ Currently works on very simple examples only, but quite well: with an acceleration factor of 100, including the compilation time! I expect a factor of about 10 in compiling real code. Python is known to be "impossible to compile". Psyco shows that it is only half the story. True, Psyco does not statically compile your code, so don't expect to turn a .py file into a stand-alone .exe file. This still requires the full interpreter. But Python or any other interpreted language can theoretically be run as fast as fully optimized C. If you don't believe it wait for a full-featured Psyco. It won't be as fast as C but it will probably be faster than you believed was possible :-) Armin Rigo From lac at strakt.com Mon Oct 22 06:51:58 2001 From: lac at strakt.com (Laura Creighton) Date: Mon, 22 Oct 2001 12:51:58 +0200 Subject: error messages raised by python got me thinking. In-Reply-To: Your message of "Mon, 22 Oct 2001 03:49:36 GMT." References: Message-ID: <200110221051.f9MApw0W022037@ratthing-b246.strakt.com> Thank you very much for your reply. I would greatly prefer "cannot concatenate 'string' and '%s'". Am I being a pedant for wanting "cannot concatenate instances of 'string' and '%s'"? or, since 'str' is the way of the future, "cannot concatenate instances of 'str' and '%s'"? (I'd like uniformity across error messages whenever possible, so unless you want to start referring to ints as _integers_...) > But in general, we can't always produce the error message you'd like > to see: e.g. if you try to add a Unicode string and a number, you get > the even less clear > > TypeError: coercing to Unicode: need string or buffer, int found > > This one is hard to fix, due to the complicated logic attempted in the > Unicode case (the code that issues the error message has no idea that > it is part of a '+' operator). I understand. Is the information about the _position_ of the argument that fails long gone as well? lac at ratthing-b246:~/src/pynche/newpynche$ python -U Python 2.1 (#3, May 26 2001, 17:43:53) [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2 Type "copyright", "credits" or "license" for more information. >>> f='1' >>> g=2 >>> f+g Traceback (most recent call last): File "", line 1, in ? TypeError: coercing to Unicode: need string or buffer, int found What I want to know, is that it is my _second_ argument that is wrong. (Without remembering that if my first one was bad, I would be getting the 'unsupported operand types for +' message.) This is more important when you are doing things like this: >>> h='3' >>> i='4' >>> f+h+g+i Traceback (most recent call last): File "", line 1, in ? TypeError: coercing to Unicode: need string or buffer, int found (at least _my_ little voice says: 'which _one_, damnit!!' ) Would this be possible? >>> f+h+g+i Traceback (most recent call last): File "", line 1, in ? TypeError: coercing to Unicode: need string or buffer: int found at position 3 # I just made this up Note, I changed the comma after _buffer_ to a colon when I added the theoretical position information, for consistency in punctuation between this error and the "unsupported operand types[sic] for +:" error, discussed next. As for: > "unsupported operand type for +: 'int' and 'str'" Typo, you meant "unsupported operand _types_," correct? > > (It would have to be 'str' because as of 2.2, that's the name for the > string object type, corresponding to the function most commonly used > to create strings.) > > Another way to write this, using 2.2 lingo, might be > > "unsupported operand types: int() + str()" > > but this doesn't look very newbie-friendly to me! I think that it is important to list what operation failed, so "unsupported operand types for +:" or (my preference) "unsupported operand types for '+':" is better than the less informative "unsupported operand types: ". But whether to use "'int' and 'str'" or "int() and str()" is a different question. My initial reaction is to prefer "int() and str()", I think because it perfectly jogs your memory about how to _fix_ your error. So, were it my decision, I would let it rattle about in my head for a week or so, and then, if I still liked it I would go with: "unsupported operand types for '+': int() and str()". Of course, if my suggestion for listing the position of the argument that triggered the failed unicode conversion error makes it into a python release, you may want the following for consistency: >>> g+f+h+i Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand types for '+': int() and str() found at positions 1 and 2 Is this the sort of thing that should get a PEP? Thank you again, Laura Creighton From johnroth at ameritech.net Sun Oct 7 11:20:43 2001 From: johnroth at ameritech.net (John Roth) Date: Sun, 7 Oct 2001 08:20:43 -0700 Subject: Newbie Question References: <9pp1ca$ca6$1@slb4.atl.mindspring.net> Message-ID: "Mel Brown" wrote in message news:9pp1ca$ca6$1 at slb4.atl.mindspring.net... > I am trying to get Python up and running. Among the modules that I know that > I will need are math, cmath, and string. > > When I import sys, then print out the included module names, I get that math > and cmath are included but sting is not. When I import math and then try to > compute something simple like sin(3), I am told that the function sin() is > not available. > > My question is how to make the modules math, cmath, and string available for > my use. import math x = math.sin(y) Notice that the math. is needed because the form of the import statement doesn't put the functions into the namespace. from math import sin x = sin(y) This allows you to get by without the qualification, but there are other reasons why you might not want to do it that way. As far as string goes, it's usually better to use the string methods rather than the string module. John Roth From zhao_zi_long at 163.net Thu Oct 25 10:41:35 2001 From: zhao_zi_long at 163.net (jilly) Date: 25 Oct 2001 07:41:35 -0700 Subject: python as a cgi script engine References: Message-ID: "DeepBlue" wrote in message news:... > When you say it failed: What error are you getting? > DB > > "jilly" wrote in message > news:f828f146.0110240116.27caedca at posting.google.com... > > i use "http://localhost/CGI/python.exe?hello.py" ,then i succeed. > > but when i use "http://localhost/CGI/hello.py" ,i failed. > > and i have setted scriptmap in the IIS > > (just like:".py-->c:\python21\python.exe -u"). > > > > The context is: > > windows 2000 and IIS server > > > > Please help me > > Thanks first! DeepBlue: The error was that it just exceeded time and had no response! Thanks for your help! From loewis at informatik.hu-berlin.de Wed Oct 17 09:57:16 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 17 Oct 2001 15:57:16 +0200 Subject: 2.1.1 build fails on hpux References: <20011016145403.4974a794.gry@ll.mit.edu> Message-ID: george young writes: > ./configure --without-threads --without-gcc --with-cxx=aCC --prefix=/opt/python > _main (code) [...] > Help! Please configure with --without-cxx (or just leave out the -with-cxx option, it doesn't work on HP/UX). If you think that you absolutely must have C++ extensions, also set LINKCC to aCC before invoking configure. Regards, Martin From graz at mindless.com Fri Oct 26 06:50:34 2001 From: graz at mindless.com (Graham Ashton) Date: Fri, 26 Oct 2001 10:50:34 GMT Subject: Question about Tkinter message boxes References: <3B7D5BA4.69A8C2EC@earthlink.net> Message-ID: <_dbC7.6240$lp2.846803@news1.cableinet.net> In article <3B7D5BA4.69A8C2EC at earthlink.net>, "Joseph Andrew Knapka" wrote: > Mike Callahan wrote: >> >> When I run this code: >> >> import tkMessageBox as tkM >> tkM.showerror('Error', 'Test messgage') >> >> I get two windows. A blank Tk box and the error box. When I click on OK >> in the error box, the blank Tk box remains. How do I keep the blank Tk >> box from appearing? >> >> Mike Callahan > > Tk will always create a root window whether you want one or not. You can > create it explicitly and then hide it at the beginning of your program: > > root = Tkinter.Tk() > root.withdraw() Have you tried this: from Tkinter import * NoDefaultRoot() -- Graham From loewis at informatik.hu-berlin.de Mon Oct 15 10:25:19 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 15 Oct 2001 16:25:19 +0200 Subject: J2EE equivalent in Python References: Message-ID: Robin Smith writes: > > What exactly is it that you like about J2EE? > > The way it hangs together. I like JSP, beans and tag libraries. > > Ideally I'm looking for tag libraries that run with python. I only have a very sketchy understanding of what tag libraries are, but it appears that Zope implements feature that are similar in expressiveness to tag libraries. Maybe I'm still misunderstanding: What is it about tag libraries that you like? Regards, Martin From mcherm at destiny.com Fri Oct 12 18:08:12 2001 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 12 Oct 2001 18:08:12 -0400 Subject: Loop-and-a-half (Re: Curious assignment behaviour) Message-ID: <3BC769CC.9020403@destiny.com> Michael Abbott writes: > It's not pretty, but I'd rather worry about having a > conditional expression (off topic; we've already beaten that to death > and not quite managed a PEP out of it...) Actually, that's not QUITE true. I submitted a proposed PEP not long ago, and got a lot of comments. Unfortunately, I didn't see any consensus begin to emerge, at least not one that I could recognize. So I decided I should put it away for a month or so, then come back with a fresh mind to create the version I actually submitted. It's my theory (untested, of course) that this will result in a better initial PEP and thus a better chance of acceptance. Anyhow, it's almost been that month now, so I ought to get myself together and get back to this. As before, if anyone else feels strongly that they'd like to contribute (other than the excellent comments several folks already made), they should email me. hoping-that-less-speed-and-more-thinking-leads-to-a-better-design-ly yours, -- Michael Chermside From sdm7g at Virginia.EDU Wed Oct 31 13:30:12 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Wed, 31 Oct 2001 13:30:12 -0500 (EST) Subject: Why 'self' ? In-Reply-To: <3BE04E7A.8E2CF101@ces.clemson.edu> Message-ID: On Wed, 31 Oct 2001, Schaefer, F. wrote: > Hi all, > > It's been a while that I am working with Python and actually > the only thing I really do not like about it is 'self' in the > member function definitions as argument. If it > has to be there anyway, it is totally redundant to write it. > > So, why is self there ? If you compare the ratio of: Smallest-Program-Length / Average-Program-Length you will find that most programs are largely redundant. As with the English Language, we suspect that most of that excess redundancy aids human comprehension of the program. We could also eliminate all explicit function arguments and pass them as an implicit tuple named 'args' . Then we could eliminate all redundant argument declarations in the function and method definitions and just process args[0], ..., args[n]. I'm sure there are a lot of redundancies we can eliminate from Python, but rather than looking for them piecemeal, I would rather start fresh with a more effecient plan: [1] Enumerate all possible computer programs. [2] Label each one with an integer. [3] Use that integer to represent the program. ( Any one remember the old joke about the prison with only one book -- a jokebook -- in the prison library? Did *that* joke have a number, or did Russell prove that if you gave it a number, the whole universe would fall into a black hole? I suspect that Douglas Adams knew it was Joke #42, but he couldn't explicitly explain it because it would have made the story so self referential that he would have been sucked into a From sholden at holdenweb.com Wed Oct 24 12:06:10 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 24 Oct 2001 12:06:10 -0400 Subject: None References: <9r4b95$suc$1@news.rchland.ibm.com> <9r6lep$tdg$1@news.rchland.ibm.com> Message-ID: "Larry Whitley" wrote in message news:9r6lep$tdg$1 at news.rchland.ibm.com... > Here's the traceback requested: > > C:\Projects\Pecos\Traces>analyze3 > u:\trc45\pecos\ c:\projects\pecos\traces\ ('crusader091101.zip', > 'crusader091101 > .dat', 'crusader091101.a3.txt') > Traceback (most recent call last): > File "C:\Projects\Pecos\Traces\analyze3.py", line 372, in ? > main() > File "C:\Projects\Pecos\Traces\analyze3.py", line 365, in main > process( localPath + files[1], localPath + files[2] ) # process the file > File "C:\Projects\Pecos\Traces\analyze3.py", line 336, in process > pc.runningReport( None, riostream ) # to stdout > UnboundLocalError: local variable 'None' referenced before assignment > AHA!!!!! This is your problem. The interpreter is telling you in this message that it regards the name None as being that of a variable local to your function or method. The ONLY reason it is making this assumption is because it has seen an assignment to None somewhere in the function/method (in this case the "process()" function). > Here's the relevant section of code in the neighborhood of the error: > if pc.endCond != "": > pc.summarizeData() > riostream = pc.rio() > pc.runningReport( fout, riostream ) # to file > pc.runningReport( None, riostream ) # to stdout > At this point the assignment to None has not taken place. But this code is inside a function that assigns to None, so None is being treated as a local variable. > The method runningReport() looks like this: > def runningReport(self, fout, riostream): > print >>fout, "%8d" % self.startCycn, "%8d" % self.endCycn, "%6d" % > (self.endCycn - self.startCycn), \ > "%8s" % self.command, "%10x" % self.startAddr, "%10x" % > self.endAddr, "%4d" % self.nBytes, \ > "%8s" % self.endCond, riostream > > My idea was to setup the method to print to file and by substituting None > for the file object, let the same method send the output to standard out. > > Thanks for the help, You'll get there. See this: >>> def fOK(a): ... print "arg is", a, "None is", None ... >>> def fBAD(a): ... print "arg is", a, "None is", None ... None = "something, anything (except None!)" ... >>> fOK(42) arg is 42 None is None >>> fBAD(42) arg is 42 None isTraceback (innermost last): File "", line 1, in ? File "", line 2, in fBAD UnboundLocalError: Local variable 'None' referenced before assignment >>> Hope this helps. regards Steve -- http://www.holdenweb.com/ From Pcurran at intraspect.com Fri Oct 5 11:37:50 2001 From: Pcurran at intraspect.com (Peter Curran) Date: Fri, 5 Oct 2001 08:37:50 -0700 Subject: How to tell when a file is closed Message-ID: Simple problem: I have an exe that creates a new file. I call this exe from python with execfile, but I don't know how to tell when the exe I called is finished writing its file. Without using any of the extra Win32 modules, how can I tell when the exe is finished? Would os.path.isfile work? Are there other utilities? If it helps, I'm actually doing this from jpython -- maybe there's a java class that does this nicely? Any ideas out there? Thank You! -Peter From gregczajkowski at yahoo.com Wed Oct 3 14:59:20 2001 From: gregczajkowski at yahoo.com (mykroft) Date: 3 Oct 2001 11:59:20 -0700 Subject: Non-arbitrary integer math References: <79b176de.0110021209.6142c830@posting.google.com> Message-ID: <79b176de.0110031059.305543c2@posting.google.com> Skip Montanaro wrote in message news:... > mykroft> I've tried searching "the vaults" and previous c.l.p posts, > mykroft> without much success. The struct and array module's won't do > mykroft> either. > > Why won't struct or array work? Have you looked at NumPy? Array is close, but there are several problems with it. It only supports upto 4-byte signed/unsigned integers. On some platforms this could be upto 8 (Python Essential Reference p.127), and thus not portable. All individual numbers would have to be treated as arrays or an element of an array. Unless I wrote a wrapper class around each type. And also they are not true integers in the C sense. >>> a = array.array('B', [255]) >>> a[0] += 1 Traceback (innermost last): File "", line 1, in ? OverflowError: unsigned byte integer is greater than maximum ie. There is no wrap-around. Ive looked at Numpy before, but it was missing most of the unsigned types, it only has unsigned 1-byte. The struct module is not used for math operations. Thanks for the reply though. But Im still stuck for now. mykroft From brueckd at tbye.com Wed Oct 24 14:59:37 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 24 Oct 2001 11:59:37 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: <20011024175604.3684.qmail@web21103.mail.yahoo.com> Message-ID: On Wed, 24 Oct 2001, David Brady wrote: > > No, "normal" operations on Python objects > > are atomic as far as threads are concerned. > [snip] > > Consider a simple producer/consumer > > situation: > > Yes, but. > > Consider this minor rewriting of your code. Three [ snipped code rewrite that misses the point ;-) ] Uh, yeah. That's why in my post I pointed out that there *are* times when you need some sort of locking/signaling mechanism. In fact, I think I specifically mentioned something along the lines of enforcing "sequential access to a function" (i.e. - a mutex or critical section). I was merely responding to somebody's not-entirely-true assertion that "_every_ access to that [shared] resource _must_ be enclosed in locks". Thanks, Dave P.S. - Print statements are not atomic and do not fall in the same realm as "normal" Python operations (e.g. "i = 5") because 'print' involves a potentially blocking access to an external resource (stdout). To avoid blocking the interpreter releases its global lock before writing to a file descriptor and reaquires it when done. From jblazi at hotmail.com Mon Oct 1 12:53:46 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Mon, 1 Oct 2001 18:53:46 +0200 Subject: Tkinter Questions References: <9p9jmp+pnq7@eGroups.com> Message-ID: <3bb89fa3_8@news.newsgroups.com> > Since I think > he is trying to make a CD player ... Thank you. I teach and I am working on spreasheets that will store and administer my marks. With the simple arrows a navigate within one table and with the fast forward buttons I am going to change the class. Now I have managed to find small arrows (the large ones simply look ugly and the are needed very often), though I should still prefer the small counter buttons. Have you any idea how I can solve with my megawidget problem? (BTW: I have already offered Python courses at the schools where I worked but the next thing I am going to do augment my course with GUI developement.) J.B. J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From gb at cs.unc.edu Thu Oct 4 09:17:31 2001 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 04 Oct 2001 09:17:31 -0400 Subject: Profiling the Python Interpreter References: Message-ID: "lokie.spods" writes: > > > An easy question to answer without the need for profiling the Python > interpreter. Cygwin essentially provides an API layer between the host OS > and the compiled code, adding a nice speed bottleneck. > > -- > Anthony McDonald I assumed something like this too. Believing doesn't make it true though. It turns out Cygwin is NOT the major problem. Running my program on identical hardware running Linux and the same version of Python+Numeric, runs about 25% slower than native Windows Python. The problem is evidently the quality of the code produced by gcc versus MSVC. There are numerous threads on various groups reporting comparable slowdowns between gcc and MSVC. Not so easy to answer. gb From grante at visi.com Wed Oct 10 12:36:37 2001 From: grante at visi.com (Grant Edwards) Date: Wed, 10 Oct 2001 16:36:37 GMT Subject: Sockets References: <9q1rk7$sim$1@nntp6.u.washington.edu> Message-ID: In article <9q1rk7$sim$1 at nntp6.u.washington.edu>, Donn Cave wrote: > Quoth grante at visi.com (Grant Edwards): > [quoting someone else] >|> How can i received in 2 separeted variables ? >| >| Use a datagram service, or impose a datagram protocol on top of >| a stream service. >| >| I think the world really needs a reliable datagram service to >| sit alongside TCP and UDP... > > I would think the diagram would put it on top of UDP, right? > Should be doable. Sure, you use user-space code to either put datagrams on top of TCP or reliability on top of UDP. But, I don't think it should be something done in user-space. I think SOCK_SEQPACKET should be implimented on top of IP in the network stack along with SOCK_DGRAM and SOCK_STREAM. But that's just because I'm tired of running into problems caused by the assumption that TCP is a datagram protocol, and tired of hacking a datagram protocols onto the top of TCP to fix those problems. -- Grant Edwards grante Yow! Am I in GRADUATE at SCHOOL yet? visi.com From James_Althoff at i2.com Mon Oct 29 12:46:25 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Mon, 29 Oct 2001 09:46:25 -0800 Subject: A small inconsistency in syntax? Message-ID: Brian Quinlan wrote: >I could want to write: >a = ['x value','y value','z value'] = x > >Here the intermediate list is doing 3 things for me: > >1. it's providing documentation >2. it's forcing the sequence type to be of length 3 >3. it's making the type assigned to 'a' a list and 4. it's providing a handy way to generate a syntax error ;-) Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> >>> a = ['x value','y value','z value'] = 1,2,3 SyntaxError: can't assign to literal >>> Jim From rxg218 at psu.edu Tue Oct 2 18:32:08 2001 From: rxg218 at psu.edu (Rajarshi Guha) Date: Tue, 2 Oct 2001 18:32:08 -0400 Subject: Network programming in python Message-ID: <9pdf61$13c6@r02n01.cac.psu.edu> Hi, I'm thinking of working on a project which would best be solved in a client - server manner. Ar ethere any pointers as to how I could/should go about setting a server program, constructing messages etc etc. TIA -- ----------------------------------------------------------------- Rajarshi Guha | email: rajarshi at presidency.com Dept of Chemistry | web : www.rajarshi.f2s.com Pennsylvania State University | ph : (814) 863 1222 ----------------------------------------------------------------- Build a system that even a fool can use and only a fool will want to use it. From skip at pobox.com Mon Oct 22 10:02:49 2001 From: skip at pobox.com (Skip Montanaro) Date: Mon, 22 Oct 2001 09:02:49 -0500 Subject: suggestion for module re In-Reply-To: <3BD3E830.3EC94E94@artenumerica.com> References: <3BD3E830.3EC94E94@artenumerica.com> Message-ID: <15316.9993.508891.14583@beluga.mojam.com> Jose> My first goal is to get all the *named* fields of a regex, for all Jose> of the matches in a source string. The re.RegexObject.findall Jose> method is "almost" good, but it returns a tuple of matched Jose> *groups*, leading to a dumb pharentesis-counting task and to code Jose> hard to maintain. I suspect that in most situations you will want all the interesting groups to be named or none of the interesting groups to be named. If you want named groups, use the "(?:...)" construct to create "throwaway" groups. See the re syntax docs for more info: http://www.python.org/doc/current/lib/re-syntax.html Your example would thus become: rx = re.compile(r'(?:(?Pa|A)(?Pb|B))') (though why you needed the outer parens in the first place is not clear). -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From db3l at fitlinxx.com Thu Oct 25 17:34:31 2001 From: db3l at fitlinxx.com (David Bolen) Date: 25 Oct 2001 17:34:31 -0400 Subject: Critical sections and mutexes References: Message-ID: writes: > > If you're able to make assumptions in applications and get away with I > > certainly won't stop you from writing that way > > Thank goodness! I was worried. :-) You jest! :-) > > But the GIL does nothing for application-specific shared resources. > > It only protects the interpreter, so that, as you mentioned in another > > response, a normal Python script can't crash the interpreter. It does > > nothing to prevent application-specific data structures from becoming > > corrupt and affecting the behavior of the application. > > Hey, did you cut and paste that from one of my previous posts? It sounds > an awful lot like what I was saying. :-) Drat, and we were doing so well politely disagreeing... :-) -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From James_Althoff at i2.com Wed Oct 31 13:57:45 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 31 Oct 2001 10:57:45 -0800 Subject: python development practices? Message-ID: I know I'm in the minority on this, but I greatly dislike the _iamspecial naming convention. To me, it's unnecessary and ugly clutter -- especially when I see classes with 80% or 90% of the fields and methods named with a leading _. In which case practically every line of code is slathered in clutter. Not to mention the fact that mangling-based hiding only happens with a *double* (not single) leading underscore naming convention -- how ugly does *that* make the code. The rule in my projects, rather, is thus: *all* instance variables are non-public -- following the "keep it simple" principle. If you are debugging things or are just exploring using the interpreter then, by all means, have at them (and I think it is very useful that you can do this in Python). But if you are writing (non-ephemeral) code outside of the defining class (or subclasses), then please use the provided get/set methods. If no such get/set methods exist there should be no mystery about the intent of the fields. Publicly-intended methods are annotated with "Public" at the start of their doc strings. Anything without such annotation -- please use only for debugging or exploring (again, outside of the defining class or subclasses). Jim From max at alcyone.com Wed Oct 31 12:48:29 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 09:48:29 -0800 Subject: Why 'self' ? References: <3BE04E7A.8E2CF101@ces.clemson.edu> Message-ID: <3BE0396D.3E9D6B09@alcyone.com> "Schaefer, F." wrote: > It's been a while that I am working with Python and actually > the only thing I really do not like about it is 'self' in the > member function definitions as argument. If it > has to be there anyway, it is totally redundant to write it. > > So, why is self there ? Because, in Python, explicit is better than implicit. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From Cameron at Lairds.com Wed Oct 24 12:49:10 2001 From: Cameron at Lairds.com (Cameron Laird) Date: 24 Oct 2001 11:49:10 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 24) Message-ID: <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E@lp.airnews.net> Martin von Loewis prints Unicode characters, correctly. http://groups.google.com/groups?hl=en&frame=right&th=4ebacc23215578b In a discussion comparing string methods with string functions, David Bolen illustrates how wise performance people think about timing measurements. http://groups.google.com/groups?hl=en&frame=right&th=7c7a842b67944513 Stephen Figgins rhapsodizes the pleasures of interactive Python. http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html Donn Cave and Lucio Torre offer implementations of poll() in terms of select(), in both C and Python. http://groups.google.com/groups?hl=en&frame=right&th=dcc03957ae758bd9 Chimezie and Uche Ogbuji explain Python-based XML development. http://www-105.ibm.com/developerworks/education.nsf/ xml-onlinecourse-bytitle/ 28BEDEE3E7219EB386256AE300743B69?OpenDocument ActiveState releases PYXPCOM. http://www.ActiveState.com/Products/Komodo/PYXPCOM Zope's Page Templates match benefits with PHP, ASP, and so on. http://advogato.org/article/350.html *Zope Web Application Construction Kit* is a new book which promises to make Zope newcomers successful. http://www.samspublishing.com/detail_sams.cfm?item=0672321335 Boudewijn Rempt's PyQt book is ready. http://stage.linuxports.com/pyqt/book1.htm ======================================================================== Everything 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 daily python url http://www.pythonware.com/daily comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect 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/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.de/oo_python.html Python FAQTS http://python.faqts.com/ 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://python.sourceforge.net/peps/pep-0042.html Python Journal is at work on its second issue http://www.pythonjournal.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python 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/topics/pythonurl/ 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 Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning, ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From cd.cd at wanadoo.fr Sat Oct 13 09:10:09 2001 From: cd.cd at wanadoo.fr (Cyr) Date: Sat, 13 Oct 2001 15:10:09 +0200 Subject: Newbie - converting binary data to ASCII text ? References: <9q92g4$6hd$1@wanadoo.fr> Message-ID: <9q9eei$gf1$1@wanadoo.fr> thanks for the answer though it doesn't resolve my problem. I think I'll try something else ;) regards Cyril "Steve Holden" wrote in message news:diUx7.37596$I83.623844 at atlpnn01.usenetserver.com... > "Cyr" wrote in message news:9q92g4$6hd$1 at wanadoo.fr... > > hello, > > > > I'm completely new to python and I've got problem reading binary data > file. > > When I read a file with read(), the binary data aren't converted. In fact, > > I'd like to know if there's a method for converting a file object (or a > > string) from binary to the equivalent ASCII text. The data aren't written > in > > a particular format. Fortran doesn't have any problem with theese files > > > Unfortunately, Python offers much greater flexibility than Python in data > handling, and correspondingly more chances to shoot yourself in the foot. > I'm assuming it's *convenient* to have these data in binary form, otherwise > you could always write a Fortran program to convert them into something > Python finds easier to deal with ... > > I also presume it was written with FORMAT statements (sheesh, does Fortran > even USE those now, showing my age I'm afraid). Python can read a particular > number of bytes if you give read() a numeric argument, but if you don't it > just tries to gobble the whole file in a oner. > > Otherwise you may have to look at the struct module, and that's too tricky > for a beginner. > > regards > Steve > -- > http://www.holdenweb.com/ > > > > PS : I'm working on an SGI Irix operating system > > > > > > From mjais at web.de Fri Oct 19 04:49:24 2001 From: mjais at web.de (Markus Jais) Date: Fri, 19 Oct 2001 10:49:24 +0200 Subject: where to get popy?? Message-ID: hello I was at http://popy.sourceforge.net/ but there is not link to get a stable tarball for popy! I can only get a cvs version and at http://www.nekhem.com/, there is not much right now. maybe I am just blind, but can someone give a link where to find the latest stable version of popy??? thanks markus From jdunnett at uoguelph.ca Sun Oct 28 21:54:01 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Sun, 28 Oct 2001 21:54:01 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> Message-ID: <3BDCC4C9.B0597DF1@uoguelph.ca> Emile van Sebille wrote: > "Jeff Dunnett" wrote in message > news:3BDCA674.FF268D0E at uoguelph.ca... > > In case your wondering the school that I attend teaches Python. In fact > it > > is a main part of one of the first major software design course. That is > > the University of Guelph in Ontario Canada. In fact the departement has > > quite a lot of fallowers who like Python. > > > >

> > Hopefully, they haven't simply put themselves out to pasture... I am not sure what I mean by your comment? Jeff From oliphant at ee.byu.edu Tue Oct 2 19:53:05 2001 From: oliphant at ee.byu.edu (Travis Oliphant) Date: Tue, 2 Oct 2001 17:53:05 -0600 Subject: Read Matlab files with Python and Numeric? In-Reply-To: References: Message-ID: > > Yes. I have a module which will load MATLAB files. It's not entirely > complete but handles most MATLAB files (the most obvious omission is > sparse matrices). > > It requires NumPy as the MATLAB matrices are loaded as Numeric arrays. > For MATLAB 5 files, cells are loaded as lists and structures as > dictionaries. > > If the entire contents of the .mat file are loaded then they are returned > in a dictionary rather than being inserted into the current workspace as > MATLAB does. I would like to see your implentation. I just finished writing a MAT file reader and writer for inclusion in SciPy. (I should have checked the newsgroups first...) My version only handles Level 4 MAT files. -Travis From schaffer at optonline.net Thu Oct 18 10:50:33 2001 From: schaffer at optonline.net (Les Schaffer) Date: 18 Oct 2001 10:50:33 -0400 Subject: Python and 3D Graphic tools References: <3bcece7f.18432984@news.easynews.net> Message-ID: <87lmi9f1dy.fsf@optonline.net> > Is there anything between these two? Or a VTK add-on thing I could > use? not sure its inbetween, but hows about PyOPenGL? http://pyopengl.sourceforge.net/ les schaffer From jfontain at winealley.com Wed Oct 31 07:38:17 2001 From: jfontain at winealley.com (Jean-Luc Fontaine) Date: Wed, 31 Oct 2001 13:38:17 +0100 Subject: ANNOUNCE: moomps-0.9 Message-ID: <3BDFF0B9.90003@winealley.com> Moomps is a monitoring daemon which works using configuration (dashboard) files created by the moodss (Modular Object Oriented Dynamic SpreadSheet) graphical application. The configuration files contain the definition of thresholds, which when crossed, trigger the sending of email alert messages. This is the initial release (beta quality). Moomps is actually part of moodss, now at release 15.0. When running, moomps periodically checks the threshold conditions and eventually send email alerts to the adresses defined for those thresholds in the configuration files, which can load any number of modules (existing, such as system, database, network types, or custom written by you in either Tcl, Perl, Python or C). Those modules are actually also used by the moodss graphical monitoring application. More documentation on moomps, moodss and existing modules can be found at: http://jfontain.free.fr/moomps.htm http://jfontain.free.fr/moodss.htm You may find it now at my homepage: http://jfontain.free.fr/moodss-15.0.tar.bz2 (contains moomps) http://jfontain.free.fr/moomps-0.9-1.i386.rpm Enjoy and please let me know what you think. Jean-Luc From tim.one at home.com Sun Oct 21 15:07:25 2001 From: tim.one at home.com (Tim Peters) Date: Sun, 21 Oct 2001 15:07:25 -0400 Subject: comparative performance benchmark Python 1.5.2 - 2.0 - 2.1 In-Reply-To: Message-ID: [Frederic Giacometti] > I have been puzzled this week when shown results of a simple benchmarck > between python 1.5.2, 2.0 and 2.1. > I am wondering; Has there been some official research on the issue ? > (pointers....?) You won't get anywhere with this unless you analyze it yourself in *great* detail, or post the code (e.g., attached to a SourceForge report) and hope someone else can dig into it (I will if I can make time for it, but gotta say that looks unlikely to happen "soon"). There are dozens of subsystems in Python, and across releases some slow down, some speed up, some a little and some a lot, all of that often varies across platforms, and it's exceedingly rare for any two "benchmarks" to tickle the same set of timing changes. So if you're looking for a simple, general answer, the odds of getting one are approximately nil. Cases of large slowdowns are usually traced to one or two specific things a program does, and this can be as specific as "creates millions of dicts of size 3 but almost none of any other size (else it would have sped up instead)". Sometimes they're traced to platform-specific compiler or C library changes too. (Did you use exactly the same C compiler, libc, compiler and linker options, and OS, for all runs? C compilers and libraries can also vary wildly across releases in the speed of generated code in ultra-specific cases, and Python performance inherits all that uncertainty too.) > The benchmarking program was only basic python objects (strings, > dictionaries, string/flot conversions...). Doesn't really help to know that. > In my haste to try do defend Python 2.1, we had done the changes > I was aware of: turn off garbage collection (20% gain), I expect that's a record. People who have bothered to measure this usually report about 3% for gc overhead, and IIRC the largest I heard of before was about 10%. > switch sre to pre (though this program does not use 're'0; How do you know? The Python libraries can use regexps too. BTW, sre is much faster than pre in many cases. > replace string.xxx() calls with o.xxx() string methods. Good -- that can help. Can you try it under 2.2b1 too (was released on Friday)? > ... > As result, I'm getting in the situation where I'm being asked to > retroceed all our developments from Python 2.1 to Python 1.5.2. Unless that benchmark is a true indicator of performance for the real apps your site runs (and very few artificial benchmarks are), that doesn't make sense. War story: A major slowdown in Zope between 1.5.2 and 2.1 was traced to a one-line change in the core to improve an error msg. "The problem" was that Zope triggered this error a *lot*, but always caught the exception. The routine raising the error simply spent a lot more time building a nice error msg than it did in 1.5.2. Is that the smoking gun for your app too? It's impossible to say without tracing thru your code in detail, but it's unlikely -- every benchmark is unique in some way that even its author can almost never guess. "fast-enough?"-is-the-only-question-that-actually-matters-ly y'rs - tim From tim.one at home.com Fri Oct 12 22:29:48 2001 From: tim.one at home.com (Tim Peters) Date: Fri, 12 Oct 2001 22:29:48 -0400 Subject: Loop-and-a-half (Re: Curious assignment behaviour) In-Reply-To: Message-ID: [Tim] > If people sign off on taking "then" as a new keyword, I think > the chances are good that we could get > > x = if e1 then e2 else e3 > > into 2.2b1. That's the only obvious spelling, hence the only truly > Pythonic way to spell it. Other languages spelling it that way range > from Algol-60 (Guido's first intense language affair) to Haskell. [Steve Holden] > And so perhaps by extension > > x = if e1 then e2 elif e3 then e4 else e5 > > ? I expect there's scant chance of that, just what I said at the top. > Yet again starting to look a little Lispish. (cond (e1 e2) (e3 e4) (t e5)) isn't on the table either. > Of course, eventually people will be posting asking us to debug > > x = if if e1 then e2 else e3 then e4 else e5 > > and similar. But then every language has its abusers . You don't need to reply to them. After nearly a decade of this, it occurred to me that not every dumb-ass idea needs its day in court . only-the-dumb-ass-ideas-you-like-ly y'rs - tim From logiplexsoftware at earthlink.net Tue Oct 2 16:08:40 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 2 Oct 2001 13:08:40 -0700 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: References: <1002028115.395.70447.l7@yahoogroups.com> Message-ID: <01100213084008.02289@logiplex1.logiplex.net> On Tuesday 02 October 2001 13:01, Samuel Schulenburg wrote: > Sometimes you have code that you want to release with a commercial > product, that contains propriatary information about the internals in > your product. A GPL license would keep you from releasing this code > using Python. Actually, unless you were embedding Python in your app I don't think this is true, since _your_ source would not in fact contain any GPL'd code. Additionally, I expect the Python libraries would fall under LGPL so using them would not "infect" your code. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From lac at strakt.com Fri Oct 26 13:17:16 2001 From: lac at strakt.com (Laura Creighton) Date: Fri, 26 Oct 2001 19:17:16 +0200 Subject: learn OOP with Python In-Reply-To: Your message of "Thu, 25 Oct 2001 16:27:46 +0200." <9r97co$cme$07$1@news.t-online.com> References: <9r97co$cme$07$1@news.t-online.com> Message-ID: <200110261717.f9QHHG0W028709@ratthing-b246.strakt.com> I had the same problem as you did last summer. If you go to http://groups.google.com/advanced_group_search and search for articles by lac at cd.chalmers.se that mention Object Oriented book in comp.lang.python : http://groups.google.com/groups?q=Object+Oriented+group:comp.lang.python+author:lac%40cd.chalmers.se&hl=en&rnum=2&selm=mailman.991118562.3957.python-list%40python.org http://groups.google.com/groups?q=Object+Oriented+group:comp.lang.python+author:lac%40cd.chalmers.se&hl=en&rnum=4&selm=mailman.991301326.27055.python-list%40python.org You will find out exactly what I did. I bought Timothy Budd's An Introduction to Object Oriented Programming. The Overwhelming opinion of the students here was that reading Design Patterns and Design Patterns in Smalltalk was more helpful. Next summer, when I will have the same problem, I am going to buy the Little Schemer, and see if that works out better. Please let me know what you decide to do, and how it works out, because I will have this problem every year. Good Luck, Laura Creighton From phr-n2001d at nightsong.com Sat Oct 27 22:25:35 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 27 Oct 2001 19:25:35 -0700 Subject: interpreter crashes References: Message-ID: <7xr8ropkkg.fsf@ruckus.brouhaha.com> "Tim Peters" writes: > Are you running with any extension modules (incl. any sort of GUI pkg)? Are > you running threads? Refcount problems in extension modules (others' or > especially your own) are historically the #1 cause of crashes. Thread races > seemingly unique to a specific platform are #2. Cyclic gc caused a few > nasty cases when it was new, but we don't see reports of crashes due to that > anymore. No threads. No GUI. No extension modules that didn't come with Python, but using a few that came with Python. I guess I could figure out from the core dumps which modules were loaded at the time. I believe I've had about 4 crashes and saved core dumps from two of them. > > Anyone got any suggestions? > > Without a reproducible problem in hand, or even a characterization of one, > guess . Unfortunately, I don't know any way to reproduce a crash. It's only happened a few times, at random. > > Want to see the core dumps? > > If you open a SoureForge bug report, someone may. OK. I'll see if I can upload the dumps to an online server, then open a SourceForge bug. > If Python were in the habit of crashing randomly, I'd advise not > using it at all. Mumble mumble fault-tolerant design mumble... yes, it's best not to crash, but in an imperfect world it's sometimes still appropriate to build software (and hardware) to withstand occasional crashes (e.g. Apache). Thanks for the reply. From phd at phd.pp.ru Mon Oct 8 06:24:47 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 8 Oct 2001 14:24:47 +0400 Subject: += doesn't work in python cgi's In-Reply-To: <3BC17D83.A4EEED81@tpg.com.au>; from msp@tpg.com.au on Mon, Oct 08, 2001 at 06:18:43PM +0800 References: <3BC17D83.A4EEED81@tpg.com.au> Message-ID: <20011008142447.E27199@phd.pp.ru> On Mon, Oct 08, 2001 at 06:18:43PM +0800, Michael Palm wrote: > I have a strange error in that += doesn't seem to work in a cgi program > > #!/usr/bin/env python Your CGI has different search PATH, and is running under Python 1.5.2. Either use full path to Python 2.0+, or change search PATH, it is configured in httpd configuration. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From sholden at holdenweb.com Tue Oct 2 10:30:38 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 2 Oct 2001 10:30:38 -0400 Subject: trying sockets References: <9pce64$5gnu5$1@hades.rz.uni-sb.de> Message-ID: "Uwe Schmitt" wrote ... > Hi, > > i'm just playing with the socket module: i'd like to send > a "GET/HTTP" request to a webserver and record the answer > of the server. so i wrote > > from socket import * > > snd=socket(AF_INET,SOCK_STREAM) > snd.connect(("www.num.uni-sb.de",80)) > print snd.getsockname() > > lstn=socket(AF_INET,SOCK_STREAM) > lstn.bind(snd.getsockname()) > > snd.send("GET / HTTP/1.0 ") > lsten.listen(1) > conn,addr=lstn.accept() > print conn.recv(1024) > > lstn.close() > snd.close() > > but i get the following output: > > ('134.96.31.42', 1662) > Traceback (most recent call last): > File "client.py", line 8, in ? > lsten.bind(snd.getsockname()) > socket.error: (98, 'Address already in use') > > so: what did i do wrong ??? > Sockets are a little difficult to understand when you are just getting started, but the good news is they are quite easy to deal with once you understand the concepts involved. Gordon McMilllan has produced some very useful tutorial material available in several places, including http://www.mcmillan-inc.com/sock1.html and I would encourage you to read that for an overview of the processes involved. The main problem is that you should use the same socket to send and receive when you have established a connection to the server. Server structures are rather different, you listen() on a socket, and when accept() returns it provides you with a newly-created socket that you can use to communicate with the connected client. So you are actually making things much more difficult than they need to be! Here's a revised program: from socket import * # Note that this is bad practice unless you KNOW # the module is specifically designed for it. # import socket # snd = socket.socket(...) # would be a more typical sequence. snd=socket(AF_INET,SOCK_STREAM) snd.connect(("www.num.uni-sb.de",80)) print snd.getsockname() snd.send("GET / HTTP/1.0\r\n\r\n") print snd.recv(1024) snd.close() There you go. When I run this it returns the following output: 302 Found

Found

The document has moved
here.


Apache/1.3.12 Server at caesar.num.uni-sb.de Port 80
This actually looks reasonable. Of course, there's lots more to do... As another poster pointed out, Python does include libraries for client-side and server-side HTTP, but they can be a little opaque at times. There's nothing wrong with trying to hack up some simple scripts yourself, although you will find there is much to be learned from the library code. Good luck! regards Steve -- http://www.holdenweb.com/ From phr-n2001d at nightsong.com Mon Oct 29 12:53:00 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 29 Oct 2001 09:53:00 -0800 Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> <9rk2vi$16dm$1@nntp6.u.washington.edu> Message-ID: <7xu1wimiyr.fsf@ruckus.brouhaha.com> Donn Cave writes: > # callback from UI - selected login option > def login(self): > name = self.config.loginid > password = self.getpassword(name) # posts password prompt window > # Function actually returns from callback ... > # ... New callback arrives with password requested here; continue! > self.loginwithpassword(name, password) > > That's arguably more readable than any alternative I ever thought of, > but then it substantially obscures the "real" flow of control in the > program. Nice! But really, using callbacks in the first place for things like this is a kludge designed to get around the lack of coroutines/continuations/threads whatever. In threaded style you'd just write getpassword as an ordinary method call that blocks til the password is entered, then returns. > Anyway, whether I want to go that way or not (and I don't know for > myself), it clearly is indeed a meaningful advance, something that > makes a substantial difference in what you can do with Python. > Definitely worth looking at, if you have gnarly asynchronous > programming issues. I've been toying with the idea of combining a Python parser with a Scheme implementation, getting continuations and a more serious compiler/interpreter at the same time. If done in the obvious way some Python semantics would break, however. From mathiasm at pvv.org Sat Oct 27 16:31:39 2001 From: mathiasm at pvv.org (Mathias Mølster Lidal) Date: 27 Oct 2001 22:31:39 +0200 Subject: Tutorial References: Message-ID: Widgeteye at widgets.com (Widgeteye) writes: > Is there a python tutorial on the net anywhere for the beginner? > http://www.python.org/doc/current/tut/tut.html Mathias Lidal From James_Althoff at i2.com Tue Oct 23 16:03:03 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Tue, 23 Oct 2001 13:03:03 -0700 Subject: non-function members of string-module. Message-ID: Steven Cummings wrote: >I'm not sure if this has already been discussed in public, but if we >want to phase out the use of the string module, then what is the plan >for its members, like letter, uppercase, etc.? I would like to see them added as class attributes to the 2.2 type/class "str". E.g., str.letters str.digits str.uppercase str.lowercase etc. Jim From mwh at python.net Fri Oct 19 06:26:03 2001 From: mwh at python.net (Michael Hudson) Date: Fri, 19 Oct 2001 10:26:03 GMT Subject: Dictionary from list? References: Message-ID: Ignacio Vazquez-Abrams writes: [perl's %hash = @array] > > (You could probably do something horrible with reduce, but don't). > > No, I don't think that reduce() could help, although list comprehensions > might. OK, you asked for it : />> def beargh(d): |.. unique = [] |.. def ouch(x,y): |.. if x is unique: |.. return y |.. else: |.. d[x] = y |.. return unique |.. return ouch \__ ->> d = {} ->> reduce(beargh(d), ['a', 1, 'b', 2]) [] ->> d {'a': 1, 'b': 2} you may have underestimated what I meant by horrible :-) Cheers, M. -- Counting lines is probably a good idea if you want to print it out and are short on paper, but I fail to see the purpose otherwise. -- Erik Naggum, comp.lang.lisp From shalehperry at home.com Fri Oct 19 16:21:23 2001 From: shalehperry at home.com (Sean 'Shaleh' Perry) Date: Fri, 19 Oct 2001 13:21:23 -0700 (PDT) Subject: Reverse argument order In-Reply-To: <20011019192158.52354.qmail@web21106.mail.yahoo.com> Message-ID: > > Is it possible to do something like this in Python, to > reverse the argument order? I came up with the > following, but I wonder if I'm going about it the hard > way. > is requiring settime(0,0,5) too much to ask? It is analogous to 00:00:05 which we are all used to seeing on our microwaves. From sholden at holdenweb.com Tue Oct 30 08:46:21 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 30 Oct 2001 08:46:21 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> <3BDCC4C9.B0597DF1@uoguelph.ca> <8djpttobn2i18avnq3817bmg1ua6eavq8r@4ax.com> <3BDE4A4D.92C0FBC@engcorp.com> Message-ID: "Peter Hansen" wrote ... > Steve Purcell wrote: > > > > Steve Holden wrote: > > > But it wasn't that funny, since nothing is ever simply black or white, good > > > answers must always conside the graze. > > > > I hope the original poster won't be cowed by these yokes at his expense. > > Look guys, this is a bunch of bull. Can we just moove on? > I herd you, Peter, but this leaves me on the horns of a dilemma. I guess I shoud hide for a while. regards Steve -- http://www.holdenweb.com/ From maxmcorp at worldonline.dk Sat Oct 6 05:47:21 2001 From: maxmcorp at worldonline.dk (maxm) Date: Sat, 6 Oct 2001 11:47:21 +0200 Subject: python and HTML integration References: <3BBCB1F0.ED40594A@oek.dk> <23891c90.0110050219.4f7f51fa@posting.google.com> Message-ID: From: "Paul Boddie" > I would recommend that anyone wanting a document template/production > framework or a Web development environment look at the modules > currently in existence and evaluate whether such modules are suitable > before considering writing their own. To start with, take a look at... > > http://www.paul.boddie.net/Python/web_modules.html Great overview Paul ... thanks Regards Max M From mcherm at destiny.com Fri Oct 19 09:44:43 2001 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 19 Oct 2001 09:44:43 -0400 Subject: Seeking Jython tool to "inspect" live java server Message-ID: <3BD02E4B.7040806@destiny.com> Jython users: I'm looking for what I think would be an EXCELLENT tool for debugging code running inside a java server (in my case, an application server like WebLogic). Java lacks an interactive mode, and most debuggers are a pain to use and also won't work well when trying to debug code that runs inside a large server system, and I very often find myself adding print statements and restarting the server. The answer is Jython. A small jython class could be run "within" the server (so it's sharing the same java virtual machine). It could accept telnet connections on some port, then allow the evaluation of arbitrary input -- an interactive shell. Basically, I could start up the server with this class active, and then telnet in and have a jython shell from which to examine my system. Does anyone have such a class already? If not, I'll write one (shouldn't be hard, right?) in which case is there any advice anyone wants to give me? -- Michael Chermside python at mcherm.com From huaiyu at gauss.almadan.ibm.com Thu Oct 18 15:54:15 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 18 Oct 2001 19:54:15 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> Message-ID: On Thu, 18 Oct 2001 02:10:40 -0600, Andrew Dalke wrote: >>- need two kinds of "break" (one impact "else" the other does not). >- Really? I thought 'break expression:' would be identical to > if expression: > break >and wouldn't hit the else. Neither does the existing else. >So there are only two ways to write the same thing. Well, I think you keep on missing one of the main point: A while B; C1: D1 if C2: break D2 else: E1 E2 has two exists: C1->E1, C2->E2. This is not the same as A loop: B if not C1: break D1 if C2: break D2 else: E1 E2 where both C1 and C2 would lead to E2. So you would have to write A loop: B if not C1: E1 break D1 if C2: break D2 E2 Or you have to enclose the whole thing in another function and use "return" as the name of another "break". That's why I ask you whether you think else-clause in while is completely useless. I'd agree that if not for the elif and the else-in-while the changes would indeed be superfluous. You could try to change the examples from the Python source distribution I gave in another post to the loop-break style and see what they look like. :-) Huaiyu From bmoyle at mvista.com Mon Oct 22 20:59:25 2001 From: bmoyle at mvista.com (Brian Moyle) Date: Mon, 22 Oct 2001 17:59:25 -0700 Subject: slow Pmw dialogs Message-ID: <3BD4C0ED.D7C681EF@mvista.com> I'm new to Python, Tkinter, and Pmw, and while playing around with Pmw dialogs, I've noticed that they seem to display themselves very slowly. I did some searching around and found the following thread back in August of last year: http://groups.yahoo.com/group/python-list/message/99720 I've encountered the problem with Pmw 0.8.4 and 0.8.5, and it sounds as if 0.8.0 did not exhibit the same problem. A proposed work-around by Georg Mischler seemed to fix the problem for me, and I'm including it below. I'm currently using a RedHat 7.0 distribution with kde 2.1.1, python 1.5.2, tk 8.3.1, and Pmw 0.8.5. Here's the gist if Georg's suggested change... Pmw_0_8_5/lib/PmwBase.py, setgeometryanddeiconify() =================================================== from the original (slower version) window.deiconify() window.tkraise() to the following (faster -- swapped order) window.tkraise() window.deiconify() A simple program to demonstrate: import Tkinter, Pmw root = Tkinter.Tk() root.withdraw() testDialog = Pmw.MessageDialog(root, message_text = "test") testDialog.withdraw() print "press return to continue: ",; raw_input() testDialog.activate(geometry = 'centerscreenalways') I looked at some of the Pmw mailing lists and discussion groups on SourceForge, but they seem a bit sparse, so I thought I'd try sending a message here first. Is there some place else I should be sending this? Also, does anybody know if there are plans to fix this, or whether there have been any investigations into the underlying cause? (as mentioned in the discussion link above, it seems to be related new desktop environments, like KDE and Gnome) Sincerely, Brian From kern at myrddin.caltech.edu Sat Oct 6 02:25:38 2001 From: kern at myrddin.caltech.edu (Robert Kern) Date: 6 Oct 2001 06:25:38 GMT Subject: Quaternions in Python References: Message-ID: <9pm852$k1p@gap.cco.caltech.edu> In article , "David Feustel" writes: > Is there a Python module that does quaternion math? ScientificPython has a module that does quaternion operations. It requires Numeric. http://starship.python.net/crew/hinsen/scientific.html There is also a module in the OpenGLContext project that implements quaternions. I don't believe it relies on any OpenGL-specific code, just Numeric and some utility modules in the OpenGLContext package. http://pyopengl.sourceforge.net Both of them only implement the operations that are useful for representing 3-D rotations, so you may have to add some functionality. -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From klaatu at plato.evertek.net Thu Oct 25 23:34:50 2001 From: klaatu at plato.evertek.net (Mike Dean) Date: 26 Oct 2001 03:34:50 GMT Subject: 2.2, iterators, list comprehensions, get/set, & win32all Message-ID: <9ralkq$rdc$1@ins22.netins.net> I'm wanting to do some experimenting with Python 2.2, and I have a couple of questions.... First, do list comprehensions use the new iterator/generator protocol in their for loop, or do they use the old method of sequence iteration? Also, it seems like I remember seeing something about __get_spam__/__set_spam__ (or something like that) magic methods in Python 2.2 - am I correct that such animals exist, and if so, where are they documented (specifically in the 2.2b1 manual)? And the third question - Are binaries of win32all for 2.2 available anywhere (they aren't on ActiveState's site), and if not, when can I expect them (better yet, how can I build them myself? I've been able to compile successfully, except for Active Debugging, but I don't know how to set up the final directory structure.....) Thanks, Michael -- "Nothing important is happening today." -- George III of England, July 4, 1776 From ksatcu at yahoo.com Fri Oct 19 18:58:30 2001 From: ksatcu at yahoo.com (Krish) Date: 19 Oct 2001 15:58:30 -0700 Subject: Triple-DES implementation in Python References: <1854cfa0.0110181325.50a4aba6@posting.google.com> <3BD033A0.BAC206BB@pallas.com> <7x1yjzoghu.fsf@ruckus.brouhaha.com> Message-ID: <1854cfa0.0110191458.248c7e3e@posting.google.com> I would really appreciate it if you could mail me the code that you have. Thanks Krish Paul Rubin wrote in message news:<7x1yjzoghu.fsf at ruckus.brouhaha.com>... > Georg Bisseling writes: > > I would go to www.OpenSSL.org, get a free C implementation, > > learn how to integrate C extensions into python and do it. > > It's not that easy. You'd then have to make loadable modules for > every computer and OS that anyone who wants to use the function might > be running. There are plenty of C implementations of DES already > linked to Python, but it's useful to also have a pure Python > implementation. From sholden at holdenweb.com Wed Oct 3 07:31:29 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 3 Oct 2001 07:31:29 -0400 Subject: COM and win32 - casting com to string References: Message-ID: "Ignacio Vazquez-Abrams" wrote in message news:mailman.1002094324.11153.python-list at python.org... > On Wed, 3 Oct 2001, Paul Brian wrote: > > > I am trying to automate excel, and have been relatively successful. > > I can start up a python com client from win32 extentions and bring up excel > > as a server. (I hope I got that the right way round :-) > > > > I can then identify "named ranges" in excel (a group of cells that I > > previously told excel to keep track of) > > > > the code: > > x = excelAppl.ActiveWorkBook.Names > > for namerange in x: > > print namerange > > gives me my two ranges back: > > =Sheet1!$D$3:$G$3 > > =Sheet1!$D$4:$D$7 > > > > all I want to do know is split those into the sheet1 and the $D$3.... > > > > however the two results are not python instances but > > > > > > > I cannot perform string operations, repr does not help and type() just tells > > me they are "instances" - can anyone tell me what I am doing wrong. > > I expect I am not understanding something about com / win32. > > Does str() have any effect? > To manipulate the COM objects you get back from Ecel you need to use the Visual Basic methods, which *are* available (since what you've got back is an object). If you've got the VBA help installed in Excel try searching for "Range method" and apllying some of those functions. never-did-understand-the-Office-object-model-ly y'rs - steve -- http://www.holdenweb.com/ From export at bmatrading.com Sat Oct 20 17:41:34 2001 From: export at bmatrading.com (A) Date: Sat, 20 Oct 2001 23:41:34 +0200 Subject: Smtplib module Message-ID: <3BD20BAE.6346.7693E0@localhost> Hi, I want to use smtplib module for sending emails. Is there any way how I can test a return code, generated by this module, to see if an email was accepting for delivery, for example? Thank you for help. From fredrik_p79 at hotmail.com Fri Oct 19 14:14:39 2001 From: fredrik_p79 at hotmail.com (Fredrik Persson) Date: 19 Oct 2001 11:14:39 -0700 Subject: Usb with python? Message-ID: <20676b3.0110191014.76901c0b@posting.google.com> Do anyone know how to access the usb-port in win98 using python? I want to use a usb steeringwheel in my pyhton application. From hamish_lawson at yahoo.co.uk Fri Oct 12 14:14:03 2001 From: hamish_lawson at yahoo.co.uk (Hamish Lawson) Date: 12 Oct 2001 11:14:03 -0700 Subject: J2EE equivalent in Python References: Message-ID: <915a998f.0110121014.192621b0@posting.google.com> Robin Smith: | Is there anything similar to J2EE for python? Webware for Python (webware.sourceforge.net). It includes (in various states of completion): * A fast, easy-to-use application server * Servlets * Python Server Pages (similar to JSP) * Object-relational mapper * Task scheduler * User manager with authentication * CGI wrapper Also check out the third-party links on the website. One particularly interesting one is the Cheetah template engine. This is more tightly focused on presentation than PSP (similar to the difference between Velocity and JSP) and is due to become the standard template engine for Webware. Webware is probably the framework most like J2EE, but other frameworks include Skunkweb, Twisted and, of course, Zope. Hamish Lawson From anthony at interlink.com.au Mon Oct 22 10:43:54 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 23 Oct 2001 00:43:54 +1000 Subject: Dictionary from list? In-Reply-To: Message from "Tim Peters" of "Mon, 22 Oct 2001 03:49:53 -0400." Message-ID: <200110221443.f9MEhsl05315@mbuna.arbhome.com.au> >>> "Tim Peters" wrote > Should the new behavior require use of a differently-named keyword argument? > My guess is yes. What will prevent this from getting implemented is a > 3-year rancorous debate about the name of the new argument <0.7 wink>. I think "Reginald" is the only obvious name for the argument that we can all agree on. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From thomasNO at SPAM.obscure.dk Tue Oct 16 21:54:33 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Wed, 17 Oct 2001 01:54:33 GMT Subject: profiler results for __getattr__, am I reading this correctly ? Message-ID: Hi, I'm working on a Gnutella client, and were beginning to look a bit at performance. After running it through the profiler module, it seems most of the time is spent in asyncore.dispatcher's __getattr__ method. (used for socket pseudo-inheritance AFAIR). My question is, can this be true?, or am I reading the results incorrectly ? If it turns out that this is my main bottleneck, I might have to move away from asyncore (I hope not, asyncore is really cool :-). My profiling script looks like this: import profile import pstats import Gnutella profile.run('Gnutella.main()', '_profile.dat') stat = pstats.Stats('_profile.dat') stat.sort_stats('time') stat.print_stats(30) This is some of the output from the script: 19102 function calls (14014 primitive calls) in 12.734 CPU seconds Ordered by: internal time List reduced from 183 to 30 due to restriction <30> ncalls tottime percall cumtime percall filename:lineno(function) 3380/1 2.813 0.001 12.609 12.609 /usr/local/lib/python2.1/asyncore.py:357(__getattr__) 338/90 1.211 0.004 9.992 0.111 /usr/local/lib/python2.1/asyncore.py:75(poll) 954 1.117 0.001 1.117 0.001 GUID.py:20(__repr__) [snip] -- Best Regards Thomas Jensen (who is not a native english speaker, so please forgive my spelling and grammar :-) From kiko at async.com.br Wed Oct 17 00:37:24 2001 From: kiko at async.com.br (Christian Robottom Reis) Date: Wed, 17 Oct 2001 02:37:24 -0200 (BRST) Subject: PosixSerial.py license and gcavazos? In-Reply-To: <0110171436582R.11044@ike> Message-ID: On Wed, 17 Oct 2001, Richard Jones wrote: > If no license is given, isn't it fair to assume that the module is in the > public domain? No, Copyright law states that even with no clear license or notice, the file is copyright the author and he ultimately must decide on redistribution and use policy. The problem here is that I can't locate the author :/ Take care, -- Christian Reis, Senior Engineer, Async Open Source, Brazil. http://async.com.br/~kiko/ | [+55 16] 272 3330 | NMFL From ignacio at openservices.net Tue Oct 16 20:28:55 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 16 Oct 2001 20:28:55 -0400 (EDT) Subject: Further help w/ readline needed (was:Re: Past command buffer gone in interpreter?) In-Reply-To: Message-ID: On Wed, 17 Oct 2001, Tod Fox wrote: > Ignacio Vazquez-Abrams wrote: > > You'll need to install the readline-devel RPM. > > I made sure readline was installed on my system, and then installed the > readline-devel RPM without any problems. I uncommented the readline > entry in Modules/Setup, but when I run make I get the following error: > > ar cr libpython2.1.a Modules/gcmodule.o Modules/threadmodule.o > Modules/signalmodule.o Modules/posixmodule.o Modules/_sre.o > Modules/readline.o Modules/arraymodule.o Modules/mathmodule.o > Modules/timemodule.o Modules/operator.o Modules/_testcapimodule.o > Modules/pwdmodule.o Modules/grpmodule.o Modules/audioop.o > Modules/imageop.o > ranlib libpython2.1.a > gcc -Xlinker -export-dynamic -o python \ > Modules/python.o \ > libpython2.1.a -lpthread -ldl -lutil -lreadline > -ltermcap -lm > /usr/bin/ld: cannot find -ltermcap > > The commented text in Setup suggests replacing -ltermcap with -ltermlib, > and this results in the error: > gcc -Xlinker -export-dynamic -o python \ > Modules/python.o \ > libpython2.1.a -lpthread -ldl -lutil -lreadline > -ltermlib -lm > /usr/bin/ld: cannot find -ltermlib > > if I delete that -lterm* entirely, it results in: > ar cr libpython2.1.a Modules/gcmodule.o Modules/threadmodule.o > Modules/signalmodule.o Modules/posixmodule.o Modules/_sre.o > Modules/readline.o Modules/arraymodule.o Modules/mathmodule.o > Modules/timemodule.o Modules/operator.o Modules/_testcapimodule.o > Modules/pwdmodule.o Modules/grpmodule.o Modules/audioop.o > Modules/imageop.o > ranlib libpython2.1.a > gcc -Xlinker -export-dynamic -o python \ > Modules/python.o \ > libpython2.1.a -lpthread -ldl -lutil -lreadline > -lm > libpython2.1.a(posixmodule.o): In function `posix_tmpnam': > /home/vulpine/Python-2.1.1/./Modules/posixmodule.c:4212: the use of > `tmpnam_r' is dangerous, better use `mkstemp' > libpython2.1.a(posixmodule.o): In function `posix_tempnam': > /home/vulpine/Python-2.1.1/./Modules/posixmodule.c:4168: the use of > `tempnam' is dangerous, better use `mkstemp' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `tgetnum' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `tgoto' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `tgetflag' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `BC' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `tputs' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `PC' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `tgetent' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `UP' > /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: > undefined reference to `tgetstr' > collect2: ld returned 1 exit status > > Can anyone provide further guidance about this issue? It looks like you'll also have to install the libtermcap RPM. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From sholden at holdenweb.com Thu Oct 25 16:25:45 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 25 Oct 2001 16:25:45 -0400 Subject: Learing Python, Newbie question References: Message-ID: "Terry Reedy" wrote ... > > "Johannes Gamperl" wrote in message > news:MPG.1642065dc9ef9d80989687 at news.t-online.de... > > thx a lot .. this works fine. Do you know if there is a > > coditional operator in python ( ?: ) > > > if os.path.exists("gbook.txt"): > > db_first = 0; > > else: > > db_first = 1; > Oh, dear. Setting a Boolean depending on the value of a Boolean ... > As others have pointed out, > a)your particular example does not need a conditional expression, and > b) there has been discussion and controversy on adding a 'true' c.e to > python. > In the meanwhile -- to answer your question -- you can almost always > do something like the following: > > db_first = not os.path.exists("gbook.txt") and 1 or 0 #good (at least > ok) > Oh dear. > But note that > > *BAD* db_first = os.path.exists("gbook.txt") and 0 or 1 *BAD* > > would always assign db_first to 1 and never 0. If you understand why > the good example works and are sure that you will never make the > mistake exemplified in the *BAD* example, you have my permission to > use this idiom ;-) (But be aware that some hate it). > Erm, what's wrong with: db_first = not os.path.exists("gbook.txt") # best? just as a matter of interest? "not" *always* returns 0 (when its operand evaluates true) or 1 (when its operand evaluates false). more-succinctly-than-usual-ly y'rs - steve -- http://www.holdenweb.com/ From mlh at idi.ntnu.no Sat Oct 27 22:00:47 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 28 Oct 2001 03:00:47 +0100 Subject: Tutorial References: Message-ID: <9rfosg$qlh$1@tyfon.itea.ntnu.no> "Mathias M?lster Lidal" wrote in message news:vyh1yjon7tg.fsf at bacchus.pvv.ntnu.no... > Widgeteye at widgets.com (Widgeteye) writes: > > > Is there a python tutorial on the net anywhere for the beginner? > > > > http://www.python.org/doc/current/tut/tut.html > More stuff for beginners can be found at http://www.python.org/doc/Newbies.html > Mathias Lidal -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.sf.net From ws-news at gmx.at Tue Oct 30 03:37:59 2001 From: ws-news at gmx.at (Werner Schiendl) Date: Tue, 30 Oct 2001 09:37:59 +0100 Subject: None References: <3bd5db1e$1@brateggebdc5.br-automation.co.at> <3bd7fa75$1@brateggebdc5.br-automation.co.at> <3BD8C747.3DA9EEEC@cosc.canterbury.ac.nz> <3bdd2257@brateggebdc5.br-automation.co.at> <3BDE19B0.586BC0A5@cosc.canterbury.ac.nz> Message-ID: <3bde67af@brateggebdc5.br-automation.co.at> "Greg Ewing" wrote in message news:3BDE19B0.586BC0A5 at cosc.canterbury.ac.nz... > Werner Schiendl wrote: > > > > Assigning to None, however, seems more likely to happen e. g. if someone > > tries to drop some unwanted return values there: > > > > a, None, b = function1() > > I don't really understand what leads people to do > that. I mean, in C you wouldn't think to write > > NULL = printf("Hi!\n"); > > to discard the result of something, would you? > > In other words, if even if someone is under the > misapprehension that None is a constant, that > doesn't explain why they should think they can > assign to it. This is of course true. I think the idea can primarily come up because you can get more than one return value from a function in python. (Although technically, of course, it is just one tuple). This is not possible in C. regards Werner From support at internetdiscovery.com Wed Oct 24 10:19:24 2001 From: support at internetdiscovery.com (Mike Clarkson) Date: Wed, 24 Oct 2001 14:19:24 GMT Subject: Python 2.1 with Tix under Windows References: <3BCC5191.399932D@gmx.net> <874roxw4yr.fsf@gmx.net> Message-ID: <3bd6cdeb.536084@nntp.ix.netcom.com> On 18 Oct 2001 13:41:16 +0200, Mathias Palm wrote: >Found a working solution. Is not nice however. Download an extra tcl/tk >package and install. Download Tix package and install in > >...\Python21\tcl > >_and_ > >...\tcl\lib > >I used Python 2.1, tcl 8.3 and Tix 8.0. As of 2.2beta, you should be able to install recursively copy the the Tix library files into Python22/tcl/tix8.1 and the dynamic library (tix8183.dll or libtix8.1.8.3.so) to the same place and have everything work. Otherwise, build and install Tix 8.1. Ensure that Tix is properly installed by running tixwish and executing the demo programs. Under Unix, use the --enable-shared configure option for all Tix and Tcl/Tk. We recommend tcl8.3.3 for this release of Tix.py. Then set the environment variable TIX_LIBRARY to be where you have installed Tix: the lib/tix8.1 directory. You should upgrade from 8.0 to 8.1.1 from tix.sourceforge.net - there are some Python specific bug fixes there. >I hope Tix will be included in the Python 2.2 package. It would be nice to see it included in the standard binary distributions. Mike. From tim at bladerman.com Wed Oct 31 06:33:06 2001 From: tim at bladerman.com (Tim Gahnström /Bladerman) Date: Wed, 31 Oct 2001 11:33:06 GMT Subject: PythonWin 2.1 saving bugg??? References: Message-ID: "Neil Hodgson" skrev i meddelandet news:r1JD7.269830$bY5.1078011 at news-server.bigpond.net.au... > Tim Gahnstr?m: > > I were in the testing phase of a program I had made (actually a lab > report) > > . When PythonWin 2.1 for some reason didnt want to save my file again. I > > tried saving it under a different name but it didnt work either, it just > > ended up with a text saying > > saving... > > in the bottom grey field. > > I had just done minor changes since last save so I didnt really consider > it > Have a look in the temporary directory. There should be a subdirectory > called bak containing backups made by PythonWin. The location of the > temporary directory is normally set by the TEMP or TMP environment variable. > If you can't find this then use the search files command to search "Local > harddrives" for the file name you were using. I have used the search funktion upside down, searched for filname fragments and texts in files bu havnt found anyghing yet :-( And that Temp enviroment variable place didnt work out either :-) First of all I couldnt even find the folder becahse it was "hidden" When I atlast found it it contained perfect backups of al the other files, but not my little puppy :-( But thanks for that tip anyway, I hadnt looked there. > Did you run out of disk space? That is one of the best ways to provoke > behaviour like this. Noop.... What I dont understand is, how can this happen? is this how the pythonwin savingfunction works? remove_old__file_from_disk Save new_file_that_current_spot Then I wounder wy it doesnt work like this. Save_new_file_next_to_old_file Remove_old_file Then atleast this problem wouldnt show up. And about that temp file I would suggest that the tempfile were a generation old like this. Save_new_file_next_to_old_file Remove_old_file Save_temp_file then the tempfile couldnt get screwed up unless the nefile were finished with. The problem would be that the tempfile would always be one saving old... but atleat it would be there :p BTW is this what openSource is about? If I look over the saving routines in PythonWin and find that they can be done better and fix it, is there a good chanse that, that will be incorporated into the next release? BTW... Maybe they work just like I lined out and there is just no problem, or I have a virus or whatever... I am stil angry though :p Tim Gahnstr?m > Neil > > > From dalke at dalkescientific.com Mon Oct 15 16:31:39 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Mon, 15 Oct 2001 14:31:39 -0600 Subject: Regex problem References: <9qelne$jcg$1@green.tninet.se> Message-ID: <9qfhcg$vee$1@slb4.atl.mindspring.net> Gustaf Liljegren: >It works fine when ... >>>> re.match(re_link, s1).group() ... >look what happens as soon as I add a space (or any other character) >before: ... >What's wrong here? Matches shouldn't have to start from the beginning of a >string. Why not? The documentation for 'match' says: http://www.python.org/doc/current/lib/re-objects.html > If zero or more characters at the beginning of string match this > regular expression, return a corresponding MatchObject instance. You want the 'search' method. You're not the only one who runs into this confusion. Even though I've been doing Python for years now, my old Perl habits still want to call it "match" instead of "search". That's documented too: http://www.python.org/doc/current/lib/matching-searching.html Andrew dalke at dalkescientific.com From db3l at fitlinxx.com Wed Oct 31 16:24:14 2001 From: db3l at fitlinxx.com (David Bolen) Date: 31 Oct 2001 16:24:14 -0500 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> <9ro2am$p5b$1@bcarh8ab.ca.nortel.com> Message-ID: Peter Wang writes: > one doesn't have to be a rogue programmer to be enticed. time > pressures, schedule pressures, etc. can all force a good programmer to > become one of the fallen. if all the variables are hanging out, with > no enforced privacy, it's much much easier/more tempting to start > using them inappropriately in the code. especially if it's just to > get one quick feature in there for the demo, etc. does this happen to > other people, or is it just me?? :-) One question that hasn't been raised in this thread is whether or not this behavior can actually be beneficial too? For example, let's say that an interface proves insufficient for a need, and thus you bypass it for a quick feature for the demo. In and of itself, I don't necessarily consider that harmful - particularly if it means you deliver your demo in the most expeditious manner. Now of course you need to revisit that post-demo (or release or whatever) and refactor and/or clean up the interface, but that's going to be generally true of an iterative or evolutionary development model (which I think Python is well suited to). So in some respects, being able to bypass a published interface when necessary can be considered a positive and doesn't have to be a negative. If this continues to happen over time and is never revisited, could you end up with a case where someone revisiting and changing a core class breaks some of its users? Sure. But that can happen in various ways even in more protected environments like C++, and so far in my work, Python's openness in this regard has not proved a major issue. > my question, all along, was not whether python works well when used > with good development practice. my question was to discover if there > were any "safety nets" that other development teams might have erected > for lapses in process. if there are none, maybe we can think of some. > if there are none because none are possible, then that's a different > issue. Or perhaps one of the reasons is that by and large those who have done larger developments with Python haven't missed not having the safety net, in which case the theoretical loss of protection being discussed just hasn't turned into a major problem in practice. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From geoffrey at bigpond.net.au Fri Oct 12 00:59:00 2001 From: geoffrey at bigpond.net.au (Geoffrey Pointer) Date: Fri, 12 Oct 2001 04:59:00 GMT Subject: YOU ARE ALL GAY! References: Message-ID: On: Tue, 9 Oct 2001 13:07:09 GMT Subject: YOU ARE ALL GAY! dvus said: > I am neatly moronic, so I kick you. Every robust specialized data havens > quietly dump as the tall machines question. As fully as Margaret perseveres, > you can train the gorilla much more cruelly. It vended, you interfaced, yet > Ophelia never wickedly proliferated inside the sign. She'd rather prioritize > stupidly than reload with Orin's violent spool. Better disrupt Javas now or > Sarah will lazily dream them over you. I was opening CDROMs to usable > Bernadette, who's facilitating to the laptop's contact. Tell Walter it's > rogue producing to a chatroom. Morris mercilessly closes erect and busts our > bright, insecure FORTRANs in back of a website. One more ADSLs rigidly roll > the dry monument. Sometimes, go crawl a pointer! If you'll manage Robette's > mail server with LANs, it'll actually save the president. Where will you > prepare the secret useless screens before Ed does? Otherwise the TCP/IP in > Merl's PGP might smile some overloaded governments. Carolyn, have a > vulnerable JPEG. You won't disconnect it. Sometimes, Ayn never locates until > Beth learns the solid Usenet wanly. They are collaborating inside opaque, > against huge, inside abysmal ActiveXs. Brian doesn't slump hard > advertisements, do you filter them? I commented on this as follows: > It's funny about that isn't it? Go figure. Other stuff was said in between and I commented further: > I realise now how saying too little can sometimes be misconstrued. Ahmen to that!! Then on: Thu, 11 Oct 2001 19:03:03 +0900 tm said: > hey geof, > What are you mumbling about? > Who are you mumbling at? > Look, if you want to be taken seriously on usenet, read this- > http://www.geocities.com/nnqweb/nquote.html > > See if that info will sink into your peabrain. If not, go mumble in some > other ng. > Thanks, > TM Okay. My message subject was Subject: Re: YOU ARE ALL GAY! So my pea brain tells me I was commenting on Subject: YOU ARE ALL GAY! Which is still current round and about. If _you_ want to be taken seriously maybe you should take your finger off your hair trigger and lay your gun to rest somewhere more suitable. On: Thu, 11 Oct 2001 16:29:02 +0100 nice.guy.nige said: > If that is the case, then it would have been a good idea to include some of > the original message that you were replying to, so the context of the > conversation wouldn't be lost. I have not seen the original message - just > your reply - and as such your post made absolutely no sense whatsoever. Thanks Nigel, I realise my error and you have clearly demonstrated that education doesn't have to be a humiliating experience. Heck, I know I'm not perfect. I made an offhand comment about a truly weird and wonderful message, the guy is obviously a poet or something, which I will continue to regret for some time. Yeah, like hell I will ;-) -- Cheers - Geoff %^> Frank Zappa: Yes Virginia ... there is a free lunch. We are eating it now. Can I get you a napkin? From jdunnett at uoguelph.ca Mon Oct 29 07:40:49 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Mon, 29 Oct 2001 07:40:49 -0500 Subject: python binary search References: <9rht70.3vvdvgd.1@kserver.org> Message-ID: <3BDD4E50.8BA429E9@uoguelph.ca> Sheila King wrote: > On Mon, 29 Oct 2001 15:38:53 +1100, "Delaney, Timothy" > wrote in comp.lang.python in article > : > > :I should resist, but I can't. > : > :So, what is this "it" that you do? (idoit). > > Twenty lashes with a wet noodle for Delaney. That was uncommonly cruel! > Poor Jeff has already beaten himself up enoug Thanks for coming to my defence but I really MUST check my spelling beter. Jeff From eyal at hyperroll.com Tue Oct 30 18:46:32 2001 From: eyal at hyperroll.com (Eyal Lotem) Date: Wed, 31 Oct 2001 01:46:32 +0200 Subject: file operations References: Message-ID: <3bdf3b1f@news.bezeqint.net> Kerstin wrote: > begin loop > - read file > - replace something in the file (seem to work) > - write file > end loop > > This has to be done quite often. A nice approach to this (if the files are not too large), is to replace the loop with something like: open('filteredfile.output', 'w').writelines( map(lambda line: line.rstrip() + '\n', open('inputfile', 'r').readlines())) (opens the input file, reads all lines, replaces every line in the input according to the given mapping function, and writes the entire result back to the output file). From ppreeper at shaw.ca Wed Oct 31 17:38:03 2001 From: ppreeper at shaw.ca (Peter Preeper) Date: Wed, 31 Oct 2001 22:38:03 GMT Subject: crypt libraries Message-ID: <3BE07D46.7080502@shaw.ca> Are there any crypt libraries for python? I am looking for symmetric type of encryption. Peter Preeper ppreeper at shaw.ca From logiplexsoftware at earthlink.net Wed Oct 10 13:01:17 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 10 Oct 2001 10:01:17 -0700 Subject: Assigning to lists with arbitrary names In-Reply-To: <3BC35131.C9AB1393@motorola.com> References: <3BC35131.C9AB1393@motorola.com> Message-ID: <01101010011701.04263@logiplex1.logiplex.net> On Tuesday 09 October 2001 12:34, Stephen Boulet wrote: > I can't quite figure out how to do this. > > I have 100 text files in a directory: file00.txt to file99.txt. > > I want to read each file in turn, parse it, and generate a list from > each file. > > Here's the problem: I want to name each list list00 to list99. I don't > want to do list[0] to list[99] (since each list is actually a list of > lists, and I'd like to avoid a list of lists of lists :). How about a dictionary of lists of lists? files = {} for f in filenames: files[f] = myparser() # whatever you're doing to parse the file... -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From jmcwill at tridog.com Wed Oct 10 16:06:49 2001 From: jmcwill at tridog.com (Jason McWilliams) Date: Wed, 10 Oct 2001 14:06:49 -0600 Subject: upload file using cgi on Win2k IIS Message-ID: <3BC4AA59.524CB637@tridog.com> I seem to be doing everything correctly to save a posted multipart/form-data file on IIS server. Yet, I only seem to be able to save a small portion of the file, not the whole thing. The internet user has permission to the temp directory and I am not getting any errors. It works properly with the same code on unix, so it must be a IIS thing? I have tried file.read file.value and also tried to just do one line at a time... file.readline . I can get the file name fine using cgiobj.filename ... etc. I get about 498 k as the file size on the uploaded file, never more and I am trying to upload a big file. Maybe there is a post limit in IIS? I know that you can set a GET limit. Any help would be appreciated. Thank you. -- Jason McWilliams Tridog Interactive, Inc. http://www.tridog.com Par Avance, Inc. http://www.paravance.com From t-weh at online.no Wed Oct 10 15:57:25 2001 From: t-weh at online.no (Thomas Weholt) Date: Wed, 10 Oct 2001 21:57:25 +0200 Subject: How to set tab-width to 4 spaces in emacs ?? Message-ID: <1J1x7.14385$tu6.623674@news1.oke.nextra.no> Trying to set the tab-width in emacs to 4 spaces without luck. Using Mandrake 8.1 ( great distro btw, python 2.1.1, postgresql 7.1.3 etc. try it now !) tried : # tab-width: 4 etc. but no go. Any hints ??? Thomas From pbrian at demon.net Wed Oct 3 03:00:00 2001 From: pbrian at demon.net (Paul Brian) Date: Wed, 3 Oct 2001 08:00:00 +0100 Subject: COM and win32 - casting com to string Message-ID: <1002093124.20881.0.nnrp-14.c2de2503@news.demon.co.uk> All, I am trying to automate excel, and have been relatively successful. I can start up a python com client from win32 extentions and bring up excel as a server. (I hope I got that the right way round :-) I can then identify "named ranges" in excel (a group of cells that I previously told excel to keep track of) the code: x = excelAppl.ActiveWorkBook.Names for namerange in x: print namerange gives me my two ranges back: =Sheet1!$D$3:$G$3 =Sheet1!$D$4:$D$7 all I want to do know is split those into the sheet1 and the $D$3.... however the two results are not python instances but > I cannot perform string operations, repr does not help and type() just tells me they are "instances" - can anyone tell me what I am doing wrong. I expect I am not understanding something about com / win32. Any help gratefully recieved. P Brian From mmurdock at sorenson.com Fri Oct 26 20:59:12 2001 From: mmurdock at sorenson.com (Michael Murdock) Date: Fri, 26 Oct 2001 18:59:12 -0600 Subject: Modules for Python References: <3BD7F263.2F3FAEB6@lucent.com> Message-ID: Sometime last year there was an article in Dr. Dobbs or a similar mag that had Python code for reading and writing Excel data. I have the code but I can't find anything else about the article. I will check at home this weekend. But it was not a full Excel module; more just some classes for doing simple stuff. If you would like these Python files, let me know and I can email them to you. HTH -Michael. "Lukasz Pawelczyk" wrote in message news:3BD7F263.2F3FAEB6 at lucent.com... > Hello, > > Could anyone tell me where I can find the modules for Python? > Especially, I am looking for any module to read MS Excel files > in Python. > > Thanks, > Lukasz > From huaiyu at gauss.almadan.ibm.com Wed Oct 10 20:01:06 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 11 Oct 2001 00:01:06 +0000 (UTC) Subject: re.group vs re.groups Message-ID: Hi, I'm puzzled by the behavior of the group and groups attributes of the re match objects. Why would b.group(0) below return the entire match string? Python 2.1 (#1, Oct 2 2001, 15:35:43) [GCC 2.95.2 19991024 (release)] on linux2 >>> import re >>> start = re.compile("^\[(\d{4})\] ") >>> b = start.match ("[0256] ") >>> b >>> b.group() '[0256] ' >>> b.group(0) '[0256] ' >>> b.groups(0) ('0256',) >>> b.groups() ('0256',) >>> b.groups()[0] '0256' Huaiyu From phd at phd.pp.ru Tue Oct 23 07:58:40 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 23 Oct 2001 15:58:40 +0400 Subject: Auto debug on un-caught exception. In-Reply-To: ; from andy.pevy@nokia.com on Tue, Oct 23, 2001 at 11:53:10AM +0000 References: Message-ID: <20011023155840.S21265@phd.pp.ru> On Tue, Oct 23, 2001 at 11:53:10AM +0000, andy.pevy at nokia.com wrote: > I have seen somewhere out there in net land a method of > automatically running the debugger when an un caught exception > occurs. def info(*args): import pdb pdb.pm() sys.excepthook = info Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From sdm7g at Virginia.EDU Wed Oct 17 18:36:17 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Wed, 17 Oct 2001 18:36:17 -0400 (EDT) Subject: os.path.join and lists In-Reply-To: <9qkteg$6vaga$1@hades.rz.uni-sb.de> Message-ID: On 17 Oct 2001, Uwe Schmitt wrote: > Fredrik Lundh wrote: > > | how about > > | bar = [ "fred", "barney", "froo" ] > | baz = bar + [ "bob" ] > | foo = os.path.join(*baz) > > hi, whats the meaning of "*baz" ?? i've never seen this before.... [1] Another way of spelling 'apply' since 2.0. [2] The inverse of "def spam( *args ):" See section 9.1 of "What's new in python 2.0" : -- Steve Majewski From phr-n2001d at nightsong.com Wed Oct 10 21:24:40 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 10 Oct 2001 18:24:40 -0700 Subject: Python questions -> compiler and datatypes etc References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> <7xr8sbc993.fsf@ruckus.brouhaha.com> Message-ID: <7x669nvuhz.fsf@ruckus.brouhaha.com> Richard Jones writes: > > I think the real answer to why there's no Python compiler is no one > > has really wanted to write one. > > That's not true - as I have mentioned in my last post, there have > been efforts and as far as I recall there is an ongoing effort right > now. I just can't find the reference at the moment. Well, if they're determined enough, they'll see it through to completion. > > Python's runtime semantics are pretty > > similar to Lisp systems, and native-code Lisp compilers have existed > > since the 1960's or maybe even earlier. It might even be feasible > > to adapt one to compile Python. > > I believe I've seen a similar proposal along those lines in the past too. > > I don't believe it's a case of people not wanting to do it - it's > would just required huge resources. The kind of resources only a > commercially funded operation could provide at the moment. And I > guess that at the moment, no-one can make a business case for it. Oh come on, it's self-defeating to think that nothing can get done unless a corporation does it. It didn't take "huge resources" to write the Lisp compilers in the first place. The lack of a Python compiler just isn't seen as an urgent problem right now. Most users are content to leave Python implementation to the central Python developers, and the central developers are mostly concentrating on interpreted implementations. And Python has a useable-enough native-code interface that bottlenecks in Python programs can usually be relieved by converting the critical parts to a C module. That relieves a lot of the tension. A Python compiler would be nice to have, but I can think of lots of things that are more important. From richard at bizarsoftware.com.au Tue Oct 30 20:29:12 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Wed, 31 Oct 2001 12:29:12 +1100 Subject: Interfaces != Multiple Inheritance [was Re: python development practices?] In-Reply-To: <7xitcwpq9r.fsf@ruckus.brouhaha.com> References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: <200110310127.f9V1Rx334645@bigboy.bizarsoftware.com.au> On Wednesday 31 October 2001 12:11, Paul Rubin wrote: > Peter Wang writes: > > while i feel that Python makes me far more productive as a programmer > > for all the projects on which i've worked, i'm inclined to agree that > > the lack of data hiding coupled with lack of a standard interface > > specification would cause problems in a team. > > If by "interfaces" you mean Java-like interfaces, that's a bogus > criticism since Python supports multiple base classes, which let > you do the same things and then some. Java interfaces != multiple inheritance. They address completely different issues. Mutliple inheritance allows one to include functionality from multiple base classes in one step. An interface indicates that your class implements a specific set of methods. Interfaces don't implement functionality, therefore indicating that your class implements multiple interfaces doesn't add any additional functionality. Richard From ykingma at accessforall.nl Tue Oct 30 16:09:20 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Tue, 30 Oct 2001 22:09:20 +0100 Subject: How smart are Semaphore Objects? References: <32cedc66.0110292253.5eaaca31@posting.google.com> <3BDE7AA4.2250BFF5@accessforall.nl> <32cedc66.0110300638.4a51129@posting.google.com> Message-ID: <3BDF16EE.DC1B09C4@accessforall.nl> "Matthew D. Wood" wrote: > > Ype Kingma wrote in message > > > A Semaphore can be released from an other thread. > > That sucks. > > > > You might prefer to use RLock. Releasing it is documented ao. by: > > The reason I wanted to use a semaphore, instead of a (lock or Rlock) > was the counting ability. I'm trying to limit my number of threads to > say 50. You can't do that with an Rlock, right? > > Hmmmm. Maybe a condition with an Rlock... I will have to look. > You might use a semaphore initialized with 50 permits to let no more than 50 threads in at a time. Seriously: what would you do when your threshold is reached? Throw an exception that a serious attacker would catch anyway? The number of threads needed normally depends on things outside your program: - how good are the various schedulers (OS/application-thread)? - how many (in)dependent I/O requests must be served? - how many processors are available? - how many synchronisation points should be used? > > It can be better for performance to release a Semaphore from another thread. > > I would consider this as a candidate for style improvement, though. > > I don't understand. Why would it be better for a non-owning thread to > release a Semaphore? Because the second thread happens to be running and there is no time to to wake up the first one and perform a thread switch to it. A semaphore is not owned by a thread. A semaphore allows a maximum number of threads to be in a (critical) section of code. A lock is owned by a thread. [snip] > > > Maybe there is an exception the Semaphore raises? I don't know. > > > > > > > When you are paranoid enough test RLock. You'll like it. > > Like I said, RLock seems like a 1 or 0 thing. I need a less than > MAX_THREADS thing. > In case your threads are non cooperative (eg. in dealing with the semaphore I suggested above) there is nothing you can do about that in Python. [snip] From tjreedy at home.com Fri Oct 12 10:35:28 2001 From: tjreedy at home.com (Terry Reedy) Date: Fri, 12 Oct 2001 14:35:28 GMT Subject: Using assingment as an operator. References: Message-ID: "Emil S. Hansen" wrote in message news:pan.2001.10.12.15.07.42.880.11244 at berlingske.dk... > Hello fellow PP. > > I have a simple question. In a program I have a statement like this: > while re.search("[^a-z0-9.]", domainname = raw_input("Please enter domainname: ")) != None: > print "Error in domainname, please use lovercase letters and numbers only." Assuming re and test are correct (not sure are), rewrite as something like while 1: domainname = raw_input("Please enter domainname: " if re.search("[^a-z0-9.]", domainname ) == None: break # correct test? print "Error in domainname, please use lowercase letters and numbers only." # corrected 'lover' to 'lower' While I once would have written this as you did (in C), I think there is some virture to having the test condensed to where it can be seen 'all at once' without the assignment interpolated within. Terry J. Reedy From paulp at ActiveState.com Fri Oct 12 10:40:53 2001 From: paulp at ActiveState.com (Paul Prescod) Date: Fri, 12 Oct 2001 07:40:53 -0700 Subject: Semantic indentation (OpenGL) References: Message-ID: <3BC700F5.146CD9E@ActiveState.com> Marek Kro??k wrote: > >... > > glBegin(GL_POINTS); > > ... > > glVertex3f(...); > > ... > > glEnd(); Try this: GL_BLOCK=1 glBegin(GL_POINTS); if GL_BLOCK: glVertex3f(...); glEnd(); Paul Prescod From dale at riverhall.NOTHANKS.co.uk Fri Oct 19 10:38:33 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Fri, 19 Oct 2001 15:38:33 +0100 Subject: Traceback oddity References: <3BD025A3.D0724FFC@pallas.com> Message-ID: <74e0tt8uc6bl7dh86mpe1dp218gbb2stfu@4ax.com> Georg Bisseling wrote: >Because Bill didn't get it right in the first place... Not Bill's problem - or even Microsoft's, IMHO. Whatever the peculiarities of the filing system, Python really should report the filenames consistently. (FWIW, Windows handling of filename case is exactly as I would like it. The Un*x insistent that I remember the case of files is a right PITA.) -- Dale Strickland-Clark Riverhall Systems Ltd From chris.gonnerman at newcenturycomputers.net Thu Oct 11 08:56:40 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 11 Oct 2001 07:56:40 -0500 Subject: Python: Zope with MySQL (and insert_id) References: <3BC574C4.3070307@glencros.demon.co.uk> Message-ID: <003d01c15254$2cf0e5c0$0101010a@local> This question is really best sent to the Zope list (go to zope.org for more info). ----- Original Message ----- From: "Nick Glencross" > I've spent the last two days teaching myself Zope, but there's alot that > I need to relearn to be able to implement web pages that I'd ordinarily > write as Perl CGI scripts. > > I've written simple mock-ups of forms and the like which I'd need to be > able to do, but one of the remaining problems is to do with my MySQL > backend. > > I've compiled up the Python MySQL DA relatively easily, but really need > to get at the MySQL-specific 'insert_id' functionality on the Database > Connection from within Zope.I can see that the ZMySQLDA module exposes > the functionality (in MySQLmodule.c). Although this means that the > functionality is obviously there through Python, I've hit a brick wall > trying to reach it through Zope itself. > > I *think* that I need to write some Python which gets Zope's datbase > connection (obviously it can't just open a new connection), and then > gets insert_id from it. > > Can anyone confirm that I'm on the right track, or better still, if > anyone's managed it, please let me know, > > Thanks in advance, > > Nick Glencross From parker at gol.com Fri Oct 12 18:57:30 2001 From: parker at gol.com (Ian Parker) Date: Fri, 12 Oct 2001 22:57:30 GMT Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> Message-ID: In article , Michael Abbott writes >Donn Cave wrote in >news:9q4it9$tio$1 at nntp6.u.washington.edu: > >> I sort of regret wasting bandwidth on this purely academic question, >> but it's a matter of truly venerable tradition that C's loop is a >> bit shy of perfection. The idea as I understand it, is that there >> are essentially two control points in a loop, the entry, and the >> conditional repeat. C conflates those two in one, because both >> entry and the conditional repeat have to be at the "top". > >Perhaps it's worth recalling at this point the syntax used by Algol68 for a >loop. This was really quite pretty and possibly slightly relevant: > > WHILE > statements; > expression > DO > statements > OD > >Of course, in C this needs to be translated to: > > while(1) > { > statements; > if (!expression) break; > statements; > } > >and in Python we have to do exactly the same: > > while 1: > statements: > if not expression: break > statements > > It's not pretty, but I'd rather worry about having a conditional >expression (off topic; we've already beaten that to death and not quite >managed a PEP out of it...) In fact, IIRC, it was prettier and possibly more relevant: for i by j to k while t do x od where i,j,m,t,x are expressions (which could be one or more statements), and the phrases "for i", "by j", "to k", "while t" are optional, with reasonable defaults. So you could briefer forms: for i to k do statements od or while t do statements od or the infinite loop: do statements od -- Ian Parker From brueckd at tbye.com Wed Oct 31 11:58:14 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 31 Oct 2001 08:58:14 -0800 (PST) Subject: python development practices? In-Reply-To: Message-ID: On Wed, 31 Oct 2001, it was written: [snip] > this is a good approach. the crux of the approach you outlined - > using unit tests as the primary API documentation - is really the sort > of answer i was looking for. are there other, perhaps python-specific > practices which have worked well? I'd really like to hear what others have experienced in the way of Python-specific practices. I don't think I have any that are truly Python-specific, but many "good" practices are really supported, encouraged, and enhanced by Python (unittests, simple and straightforward code, trying new pieces of code out a little at a time instead of writing a lot and throwing it all over the cliff, consistent style, constant refactoring, platform neutrality, etc.). -Dave From woodm at equire.com Tue Oct 30 01:53:29 2001 From: woodm at equire.com (Matthew D. Wood) Date: 29 Oct 2001 22:53:29 -0800 Subject: How smart are Semaphore Objects? Message-ID: <32cedc66.0110292253.5eaaca31@posting.google.com> I firmly believe that when coding a function, object, program or whatever, one should assume that every other function, ... is either stupid or out to get you. With this mind-set, I'm curious as to how (idiot or mean-person) proof semaphore objects are. Threading.Semaphore. If a class can't acquire a semaphore, or doesn't bother, can it release it, despite not owning it? It's almost a security thing. I want in, and so, I will release the semaphore, repeatedly if necessary, until I get in. Is the semaphore able to avoid this kind of thing? Or do you just have to rely on the fact that people generally don't try to release a semaphore that they haven't acquired? This may seem a bit paranoid, but in big groups, paranoid is so important. My code may be a bit large, but it's never the part that crashes because of a divide by 0 or a file didn't open because it never existed. Maybe there is an exception the Semaphore raises? I don't know. Thanks for helping. I really appreciate the time and effort. From ykingma at accessforall.nl Tue Oct 30 17:14:12 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Tue, 30 Oct 2001 23:14:12 +0100 Subject: ReXX Style translate() function for strings ? References: <3281a460.0110301257.1a4d9a14@posting.google.com> Message-ID: <3BDF2619.E794EA01@accessforall.nl> P Adhia wrote: > > Hello, > > I am a newbie to python, and remain impressed with the power of the > language overall. There are however some little features that I am > used to in ReXX (default scripting language for mainframes) that I > could not find in python. > > ReXX has a translate() function that is much more powerful (and I > think coule be a nice addition to python; of course with a different > name) > > e.g. in ReXX, to change a date from yyyymmdd to mm/dd/yyyy is > trivially simple, > new_date = Translate('56/78/1234', old_date, '12345678') > > for formal syntax refert to, > http://users.comlab.ox.ac.uk/ian.collier/Docs/rexx_ref/F/BI > There is string method in python: translate(table[, deletechars]) Return a copy of the string where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256. which is not quite what you are looking for. The REXX translate is more powerful than this. May be it is possible to get the same behaviour using two translations in series with carefully computed tables. A more python-like way of changing the date format of a string could be: new_date = ''.join(old_date[4:5],'/',old_date[6:7],'/',old_date[0:3]) The time module also contains the strftime() method that will do almost anything you want with date formats. > Python's l/r/strip() functions always remove white spaces -- > corresponding ReXX functions (actually only one) has a optional > argument that defines what character to strip. e.g. removing leading > '0' from a number, punctualtion characters etc. > > If such functionality is trivial in python, I'll appreciate any new > addition to my growing python knowledge. > Removing leading zero's is bit more tricky, but normally str(long(yournumberstring)) will do. REXX has PARSE, python has regular expressions: more complicated and even more powerful. The way back to REXX is uphill... Have fun, Ype -- email at xs4all.nl From tim.one at home.com Mon Oct 8 15:40:20 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 8 Oct 2001 15:40:20 -0400 Subject: pydoc in 2.1: Missing static methods In-Reply-To: <9pst25$4uc$1@newsreaderm1.core.theplanet.net> Message-ID: [F. GEIGER] > I use pydoc of ActivePython 2.1.212 and am pretty happy with it, > except when it comes to "static methods": Such methods are not shown by > pydoc! That's because they're not methods: they're data, and pydoc in 2.1 or before never shows class data. > I use Alex Martelli's pattern to define the static methods (aka > class-methods, see AS' Python Cookbook): > > class HcForm: > > > > def restoreFromSession(name, session, request): > try: > form = pickle.loads(session.value(name)) > except KeyError: > return None > form._request = request > form.__processRequest() > return form > > restoreFromSession = static(restoreFromSession) > > I guess pydoc misses "self", pydoc doesn't look for "self". After the above, HcForm.restoreFromSession is simply a data object (an instance of class static), and doesn't mean any more to pydoc than e.g. restoreFromSession = int or restoreFromSession = 42 or restoreFromSession = AnyRandomClass() would mean. In 2.2, pydoc: 1. Does show data objects in class dictionaries. 2. Shows static methods (created by the new builtin staticmethod() function) in a "static methods" subsection. > ... > I don't know how pydoc should label this method. Should it prefix it with > "static"? Or should it simply list it with the other methods? > > static() is defined like so: > > class static: > ... Here's a 2.2 example: class Example(object): def statmeth(): "A 2.2 static method example." return 666 statmeth = staticmethod(statmeth) def ordinary(me): "An ordinary method." return me dataobject = 666 $ python ... >>> import example >>> help(example.Example) Help on class Example in module example: class Example(__builtin__.object) | Methods defined here: | | ordinary(me) | An ordinary method. | | ---------------------------------------------------------------------- | Static methods defined here: | | statmeth() | A 2.2 static method example. | | ---------------------------------------------------------------------- | Data and non-method functions defined here: | | __dict__ = {'__dict__': ,' | ... | | __module__ = 'example' | | __weakref__ = | | dataobject = 666 | | ---------------------------------------------------------------------- | Methods inherited from __builtin__.object: | | __delattr__(...) | x.__delattr__('name') <==> del x.name | | __getattribute__(...) | x.__getattribute__('name') <==> x.name | | __hash__(...) | x.__hash__() <==> hash(x) | | __init__(...) | x.__init__(...) initializes x; see x.__class__.__doc__ for signature | | __reduce__(...) | helper for pickle | | __repr__(...) | x.__repr__() <==> repr(x) | | __setattr__(...) | x.__setattr__('name', value) <==> x.name = value | | __str__(...) | x.__str__() <==> str(x) | | ---------------------------------------------------------------------- | Data and non-method functions inherited from __builtin__.object: | | __class__ = | the object's class | | __new__ = | T.__new__(S, ...) -> a new object with type S, a subtype of T >>> 2.2 class methods (created by the new builtin classmethod() function) are also shown in their own subsection. Before 2.2, you're out of luck, short of perhaps changing inspect.py and pydoc.py to recognize and special-case the specific class name "static" (provided that's the name you always use). This gets pretty involved, though, as pydoc ignores class data objects entirely in 2.1, and teaching it not to requires structural changes to the code (i.e., it's not a one-liner patch, it's complicated). voice-of-painful-experience-ly y'rs - tim From brueckd at tbye.com Thu Oct 25 09:30:19 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 25 Oct 2001 06:30:19 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: Message-ID: On 25 Oct 2001, David Bolen wrote: > BTW, one of the reasons I feel strongly about this is that a very > large percentage of my applications over the years have been > multithreaded (and I'm a big fan of having the support in the language > such as Python does) and there are just some things you don't skimp > on, if you want to do it write, maintainably and with assured behavior > over time. BTW, one of the reasons *I* feel strongly about this is that a very large percentage of *my* applications over the years have been multithreaded yadda yadda yadda. I'm simply telling what I've happened to experience: resolving thread-safety issues has gone from lots of work in other languages to almost none in Python. People have expressed lots of concern over problems that could happen theoretically, and I understand that, and I'm reporting that those theoretical problems happen far less often than people are implying (this whole silly thread tanget was started by me saying that someone spoke too strongly about thread-safety issues in Python). -Dave From ignacio at openservices.net Thu Oct 11 15:26:51 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 11 Oct 2001 15:26:51 -0400 (EDT) Subject: upload file using cgi on Win2k IIS In-Reply-To: <3BC5EECF.FE2F76E5@tridog.com> Message-ID: On Thu, 11 Oct 2001, Jason McWilliams wrote: > Turns out that I didnt have windows handling Python scripts with the -u > arg... to handle binary data unbuffered. This fixed the problem by > setting .py files to use python -u %s %s on IIS. (thanks to another > person on the list!) > > Although, I am trying to Freeze the program into a .exe file. In that > case it acts the same as before. Not sure how to get freeze to do the > same as python -u. Well, setting the environment variable PYTHONUNBUFFERED will do it, although in your case a better option might be to modify Python/frozenmain.c: --- Python/frozenmain.c.orig Thu Oct 11 15:23:24 2001 +++ Python/frozenmain.c Thu Oct 11 15:23:47 2001 @@ -32,14 +32,10 @@ if ((p = getenv("PYTHONINSPECT")) && *p != '\0') inspect = 1; - if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') - unbuffered = 1; - if (unbuffered) { - setbuf(stdin, (char *)NULL); - setbuf(stdout, (char *)NULL); - setbuf(stderr, (char *)NULL); - } + setbuf(stdin, (char *)NULL); + setbuf(stdout, (char *)NULL); + setbuf(stderr, (char *)NULL); #ifdef MS_WIN32 PyInitFrozenExtensions(); -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From nospam at bigfoot.com Wed Oct 3 10:25:38 2001 From: nospam at bigfoot.com (Gillou) Date: Wed, 3 Oct 2001 16:25:38 +0200 Subject: How to use the callback of COM objects Message-ID: <9pf6ph$9dg$1@norfair.nerim.net> Hi, I've tried this to provide a callback function to a COM object: ============== import win32com.client def HandleReadyState(): # anything you want return ox = win32com.client.Dispatch('MSXML.DomDocument') ox.onreadystatechange = HandleReadyState ============== And the last line raises this: ============== Traceback (most recent call last): File "validation.py", line 7, in ? ox.onreadystatechange = HandleReadyState File "C:\Python21\win32com\client\dynamic.py", line 467, in __setattr__ self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0, pythoncom.DI SPATCH_PROPERTYPUT, 0, value) TypeError: Objects of type 'function' can not be converted to a COM VARIANT ============= This works perfectly when the equivalent is programmed in javascript. "onreadystatechange" is an event that can be handled by a user function. Did I miss something ? Thanks in advance fo any hint. --Gilles From cliechti at gmx.net Wed Oct 31 12:52:28 2001 From: cliechti at gmx.net (Chris Liechti) Date: 31 Oct 2001 19:52:28 +0200 Subject: Running phyton on 50Mips RISC doable? References: <9rovil$fei$1@news1.xs4all.nl> Message-ID: "Cor" wrote in news:9rovil$fei$1 at news1.xs4all.nl: > I'm trying to figure out if I should use Python for my embedded > application that needs some scripting. > It is an application with 50Mips Risc processor, with little > (and slow) memory. So when I want to run the python interpreter > on this machine, will it be terrible slow? And more inportant: how > mauch memory will I need? a few K? a few hondred K? > Is it difficult to port the code such that it will run on this machine? > (It uses gcc compiler) i have compiled python 2.1.1 on a PPC embedded with Linux (Kernel 2.4). it runs fine on a 16MB/50Mhz board (compiling was done on a board with 64MB). When my app runs, Python uses about 3MB of RAM. Startup is a bit slow, but entering commands interactively is fine. chris -- Chris From James_Althoff at i2.com Mon Oct 29 17:27:21 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Mon, 29 Oct 2001 14:27:21 -0800 Subject: A small inconsistency in syntax? Message-ID: Brian wrote: James wrote: >> Brian Quinlan wrote: >> >I could want to write: >> >a = ['x value','y value','z value'] = x >> > >> >Here the intermediate list is doing 3 things for me: >> > >> >1. it's providing documentation >> >2. it's forcing the sequence type to be of length 3 >> >3. it's making the type assigned to 'a' a list >> >> and >> >> 4. it's providing a handy way to generate a syntax error ;-) >> >> Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit >> (Intel)] on win32 >> Type "copyright", "credits" or "license" for more information. >> >>> >> >>> a = ['x value','y value','z value'] = 1,2,3 >> SyntaxError: can't assign to literal >> >>> > >That was exactly the point of the original argument - that it is >reasonable to do sequence unpacking into mutable literals even though >the language does not allow it. > >Cheers, >Brian Sorry ... didn't realize it had drifted into the realm of "what if things were different" :-) In which case, though, I suspect it would be more obvious to use "assert" or test for "len" or use "list" or throw in a comment like # ['x value','y value','z value'] -- rather than having to contemplate what [1,2,3] = 4,5,6 might mean and how it might work and under what circumstances its usage would be considered appropriate. IMHO, Python already has too much special-case stuff that one has to learn from folklore rather than being able to guess or derive from a few simple, basic principles. Jim From rwest at opti.cgi.net Wed Oct 24 15:43:39 2001 From: rwest at opti.cgi.net (Richard West) Date: Wed, 24 Oct 2001 19:43:39 GMT Subject: xml and rexec Message-ID: I'm trying to get xml support running in a restricted execution environment. I've run into a perplexing problem in the minidom module. Seems as though the __getattr__ is calling itself.. This doesn't seem to be the normal behavior under a non-restricted execution environment. I'm running Python 2.1.1. Here's my test code: import sys import rexec import string def main(): code = string.join([ """import string""", """import xml.dom.minidom""", """test_xml = string.join([""", """ '',""", """ '',""", """ 'test',""", """ 'password',""", """ '',""", """ ' 123',""", """ ' 456',""", """ '',""", """ '',""", """ ],'\\n')""", """dom = xml.dom.minidom.parseString(test_xml)""", ],'\n') r = test_rexec() r.r_exec(code) class test_rexec(rexec.RExec): ok_sys_names = ( 'ps1', 'ps2', 'copyright', 'version', 'platform', 'exit', 'maxint', 'stdout', 'stderr') def load_dynamic(self, name, filename, file): if sys.modules.has_key(name): src = sys.modules[name] else: import imp src = imp.load_dynamic(name, filename, file) dst = self.copy_except(src, []) return dst main() Here's the traceback: Traceback (most recent call last): File "test3.py", line 43, in ? main() File "test3.py", line 24, in main r.r_exec(code) File "rexec.py", line 264, in r_exec exec code in m.__dict__ File "", line 14, in ? File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 915, in parseString return _doparse(pulldom.parseString, args, kwargs) File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 902, in _doparse toktype, rootNode = events.getEvent() File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 234, in getEvent self.parser.feed(buf) File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 87, in feed self._parser.Parse(data, isFinal) File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 178, in start_element_ns AttributesNSImpl(newattrs, {})) File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 75, in startElementNS node = self.buildDocument(None, localname) File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 174, in buildDocument return node.firstChild File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 58, in __getattr__ if self.__dict__.has_key("inGetAttr"): File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 56, in __getattr__ raise AttributeError, key AttributeError: __dict__ The test code works just fine outside of the restricted execution environment. Have I missed something obvious? -Richard From paul at boddie.net Wed Oct 17 07:17:48 2001 From: paul at boddie.net (Paul Boddie) Date: 17 Oct 2001 04:17:48 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> <9qhvq5$29ik$1@nntp6.u.washington.edu> Message-ID: <23891c90.0110170317.1e18fae5@posting.google.com> Guido van Rossum wrote in message news:... > > I don't know what it takes to reconstitute your faith in Python 2.2. > There's one little point of light: conditional expressions are out. I > couldn't find any examples in the standard library that would be made > to look better by using them. :-) It seems to me, from code I've seen and written, that the C- and Java-style ... ? ... : ... construct is most frequently used in cases where one is testing for NULL (or null) and producing an ad-hoc result in order to avoid writing a function which does such a test and returns the appropriate value. More advanced applications of the construct seem to me to be bad style, but perhaps I've never been exposed to "power users" of the construct along with their code. > Regarding all the other changes (you're right, I won't back them out > :-), I believe that they are much more backwards compatible than you > fear. Integer division won't become the default until 3.0, for > example. I really must apologise for giving you (Guido) and the core developers such a hard time over the integer division issue, although given the postponement of the default behaviour, we can't claim that no-one listens to our complaints. Having seen the unanticipated discrepancies between -(a/b) and -a/b for integers recently, I feel that my participation in that debate could have been reduced significantly had someone pointed that issue out so blatantly at the time. Indeed, that would be a good explicit argument point in the PEP, but it does raise the issue of whether such behaviour is good for "classic division" in the long term; perhaps you have no choice in the matter. ;-) > What else? 2.2 has lots of improvements that you'll want and that > don't affect the language syntax at all -- better portability, better > and automatically configured large file support, etc. The other improvements seem quite worthwhile and fairly uncontroversial too! Paul P.S. One thing which intrigues me is that there are occasionally calls for "forking" or "preserving" the language when it appears that language changes are being introduced too quickly, but there doesn't seem to be any visible, mainstream group calling for such action because they feel that changes are not being introduced quickly enough. From rwest at opti.cgi.net Thu Oct 25 22:20:23 2001 From: rwest at opti.cgi.net (Richard West) Date: Fri, 26 Oct 2001 02:20:23 GMT Subject: recursive __getattr__ under rexec Message-ID: I'm trying to get xml support running in a restricted execution environment. I've run into a perplexing problem in the minidom module. Seems as though the __getattr__ is calling itself.. This doesn't seem to be the normal behavior under a non-restricted execution environment. I'm running Python 2.1.1. Here's my test code: import sys import rexec import string def main(): code = string.join([ """import string""", """import xml.dom.minidom""", """test_xml = string.join([""", """ '',""", """ '',""", """ 'test',""", """ 'password',""", """ '',""", """ ' 123',""", """ ' 456',""", """ '',""", """ '',""", """ ],'\\n')""", """dom = xml.dom.minidom.parseString(test_xml)""", ],'\n') r = test_rexec() r.r_exec(code) class test_rexec(rexec.RExec): ok_sys_names = ( 'ps1', 'ps2', 'copyright', 'version', 'platform', 'exit', 'maxint', 'stdout', 'stderr') def load_dynamic(self, name, filename, file): if sys.modules.has_key(name): src = sys.modules[name] else: import imp src = imp.load_dynamic(name, filename, file) dst = self.copy_except(src, []) return dst main() Here's the traceback: Traceback (most recent call last): File "test3.py", line 43, in ? main() File "test3.py", line 24, in main r.r_exec(code) File "rexec.py", line 264, in r_exec exec code in m.__dict__ File "", line 14, in ? File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 915, in parseString return _doparse(pulldom.parseString, args, kwargs) File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 902, in _doparse toktype, rootNode = events.getEvent() File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 234, in getEvent self.parser.feed(buf) File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 87, in feed self._parser.Parse(data, isFinal) File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 178, in start_element_ns AttributesNSImpl(newattrs, {})) File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 75, in startElementNS node = self.buildDocument(None, localname) File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 174, in buildDocument return node.firstChild File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 58, in __getattr__ if self.__dict__.has_key("inGetAttr"): File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 56, in __getattr__ raise AttributeError, key AttributeError: __dict__ The test code works just fine outside of the restricted execution environment. Have I missed something obvious? -Richard From maxmcorp at worldonline.dk Thu Oct 18 18:32:50 2001 From: maxmcorp at worldonline.dk (maxm) Date: Fri, 19 Oct 2001 00:32:50 +0200 Subject: Reinventing the wheel? cgi +xhtml References: Message-ID: <8LIz7.4090$5v1.321698@news010.worldonline.dk> "Jackson" wrote > 2)Can I use it as module the why it's define? > >>> import xhtml > >>> header() > >>> header > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'header' is not defined that would probably be: import xhtml xhtml.header() or from xhtml import header header() regards Max M From kwg at renre-europe.com Fri Oct 5 07:04:12 2001 From: kwg at renre-europe.com (Ken Guest) Date: 05 Oct 2001 12:04:12 +0100 Subject: win32security question In-Reply-To: References: Message-ID: <1002279870.28802.9.camel@lewis> On Wed, 2001-10-03 at 17:05, Erik Myllymaki wrote: > How can I tell if a user's password has expired through python's win32 APIs? considering as this is an API question, have a look at http://www.vbapi.com/ or http://vbworld.com/api/ for some fairly good articles on the win32 api. Alternatively just stfw. k. From slinkp23 at yahoo.com Wed Oct 24 01:58:27 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Wed, 24 Oct 2001 05:58:27 GMT Subject: 1 is not prime (Re: a better prime number generator) References: <3BD61138.9E1A196C@cosc.canterbury.ac.nz> Message-ID: On Wed, 24 Oct 2001 13:54:16 +1300, Greg Ewing wrote: >Paul Winkler wrote: >> >> # 1 is prime, but we don't want it in the list during the loop >> primes.insert(0, 1) >The way the primes are usually defined, 1 is >not considered prime. So this line should be >removed. Oops! Right you are. An interesting text on the subject: http://www.utm.edu/research/primes/notes/faq/one.html You can see how long it's been since I've taken a mathematics course! -- Paul Winkler From db3l at fitlinxx.com Mon Oct 29 20:15:11 2001 From: db3l at fitlinxx.com (David Bolen) Date: 29 Oct 2001 20:15:11 -0500 Subject: win32all extension module for Python2.0? References: Message-ID: "Peoter Veliki" writes: > I have to use Python 2.0, but I can't find the win32all modules to download > (specifically win32clipboard.py). It is included with ActivePython, but > there web site does not offer V2.0 as a download, only V2.1 and 2.2. Will > these modules work with V2.0? Does ActivePython 2.0 exist and if so where > can I download it? I think this was recently also covered in a separate thread, but if you've already got the Python build, then you can just add the win32all extensions directly onto that - no need to get a full ActivePython build. I don't know if older ActivePython full installs are still available anywhere. But for just the win32all extensions, try: http://www.activestate.com/Products/ActivePython/win32all.plex This page has the standalone win32all installers, and you can get a version for any of Python 1.5.2, 2.0 or 2.1. Note that the 2.0 and 2.1 releases will work fine with the maintenance updates 2.0.1 and 2.1.1 respectively. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From jessw at loop.com Tue Oct 2 01:05:26 2001 From: jessw at loop.com (Jesse W) Date: Mon, 1 Oct 2001 22:05:26 -0700 Subject: PEP 271: Prefixing sys.path by command line option In-Reply-To: Message-ID: <3BB8E8A6.23359.440C1F68@localhost> Dear Pythonics, Frederic Giacometti wrote: > The purpose of the PEP is the introduction of new command line option > to python (-P), whose role would be similar to java's -classpath > option: providing the ability to explicitly set the PYTHONPATH value > from the command line. > Last, the -P option can also be used to expose in the scripts the > value of PYTHONPATH in a highly readable manner. This seems to me to be a very good idea. The difficulties I have had and heard about when dealing with PYTHONPATH are too numerous to count. Having a way to set it simply would be a godsend. I just remembered the trick of setting the sys.path var in the program, and I do realise that that does work, but it seems like a really nasty hack. > Typical applications are in development of build, test, and > configuration scripts. > > Comments and suggestions for improvement, and questions are welcome. Yes, +1, Full speed ahead... > Thanks! Thank you. Jesse W From jeremy at zope.com Wed Oct 10 15:52:35 2001 From: jeremy at zope.com (Jeremy Hylton) Date: Wed, 10 Oct 2001 15:52:35 -0400 (EDT) Subject: testing, please ignore Message-ID: <15300.42755.90833.620385@slothrop.digicool.com> Testing that this message gets through to comp.lang.python. From j.wender at science-computing.de Thu Oct 11 08:52:36 2001 From: j.wender at science-computing.de (Jan Wender) Date: Thu, 11 Oct 2001 14:52:36 +0200 Subject: Borg Pattern Class usable from other classes? Message-ID: <20011011145236.A20674@leo.science-computing.de> Hi, I tried to use the Borg Pattern from Alex Martelli (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531). I have one file containing the Borg class. In another file I defined a second class which wants to access the information from the Borg class. It instantiates an object from the Borg class, but it seems that the class dictionary __shared_state gets newly initialized, rendering it empty. Any ideas to get it working? I tried already to use a module global dict in a.py, and also different access paths for the dict, to no avail. The two files: # a.py class Borg: __s = {} def __init__(s): s.__dict__ = s.__s if __name__ == "__main__": a = Borg() a.t = "Huba" print "a", a.t b=Borg() print "b", b.t import b d=b.Test() # --8<---snip--- # b.py import a class Test: def __init__(s): c = a.Borg() if hasattr(c, 't'): print 'c', c.t else: print 'c has no t' # --8<---snip--- Thanks for any insights, Cheerio, -- J.Wender at science-computing.de - Fon +4970719457-257 Fax-211 science+computing ag - Hagellocher Weg 71-75 - 72070 T?bingen Beware, software never dies. (Wietse Venema) From per at sbc.su.se Mon Oct 15 09:02:38 2001 From: per at sbc.su.se (Per Kraulis) Date: Mon, 15 Oct 2001 15:02:38 +0200 Subject: SVG and Python? References: <3BCA9747.2F8C9462@sbc.su.se> <87r8s58h8r.fsf@lisboa.ifm.uni-kiel.de> <6qelo5qjuv.fsf@abnoba.intevation.de> Message-ID: <3BCADE6E.D0B1741D@sbc.su.se> Bernhard Herzog wrote: > > Janko Hauser writes: > > > Look for sketch > > http://sketch.sourceforge.net/ > > > > It can read and write SVG files, although I'm not sure if all things > > of the spec are possible. > > Sketch's SVG support is quite incomplete, unfortunately. There are still > some things missing that Sketch could handle and there are some that > Sketch can't support properly yet such as transparancy. Thanks for the info. I will have a closer look at Sketch. I do not need a complete SVG implementation, so that's probably OK. However, the architecture of the implementation is my main concern, since I would like to include it in a software package I am working on. I'll check it out. Thanks! Per K -- Per J. Kraulis, Ph.D. per at sbc.su.se Stockholm Bioinformatics Center (SBC) http://www.sbc.su.se/~per/ SCFAB, Dept Biochem Biophys, Stockholm Univ phone +46 (0)8 - 5537 8571 SE-106 91 Stockholm, SWEDEN fax +46 (0)8 - 5537 8601 From unknown at lee-morgan.net Thu Oct 11 08:04:15 2001 From: unknown at lee-morgan.net (Lee Morgan) Date: Thu, 11 Oct 2001 12:04:15 GMT Subject: image from URL References: <3BC57869.E95139D7@ncsa.uiuc.edu> Message-ID: Oleg Broytmann writes: > On Thu, Oct 11, 2001 at 05:46:01AM -0500, Randy Heiland wrote: > > >>> import urllib, Image > > >>> fp = urllib.urlopen("http://www.python.org/pics/PyBanner027.gif") > > >>> im = Image.open(fp) > > Traceback (most recent call last): > > File "", line 1, in ? > > File "/home/heiland/PythonMod/Imaging-1.1.2/PIL/Image.py", line 944, > > in open > > fp.seek(0) > > AttributeError: addinfourl instance has no attribute 'seek' > > im = Image.open(fp.read()) > fp is not a file name, it is already file (file-like object, to be > precise). > import StringIO im = Image.open(StringIO.StringIO(fp.read())) > Oleg. > ---- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. > -- Lee Morgan From chr_w at gmx.de Tue Oct 16 16:42:47 2001 From: chr_w at gmx.de (chr_w at gmx.de) Date: Tue, 16 Oct 2001 22:42:47 +0200 (MEST) Subject: READ FILE UNTIL THE Xth SPACE IS ENCOUNTERED... Message-ID: <10508.1003264967@www8.gmx.net> Hi list :-) Yeah, I'm a python starter seeking for help once again... ;-) Seems as if I start right the hard way with the coding tasks I have to solve here... :-( I don't know if this has been covered before... Here's what I am trying (amongst other things) to do: "read in an ascii file until a given number of delminiting spaces has been reached" the file contains float numbers delimited by spaces (ASCII) Motivation: I have massiv ASCII files containing floats delimited by spaces and run out of memory when trying to get them into the machine in one piece (followed by spliting into a list object). What I am doing right now: 1) read in the entire file until EOF is reached 2) split into a list of strings 3) convert to float array This works fine for my smaller files. But there are also some big bastards to be done. So: What I want to do: 1) read the file until space number 63477 was encountered 2) take this string and split it into a list / followed by a conversion into an float array 3) continue to read the file (until the next space no 63477 was read) 4) etc. Don't worry about the number '63477': this is the sum of fields in an 3d array I want to produce. No idea how to do this, since all examples I found read until EOF or by lines. Forgive me if I missed something really basic here - I just couldn't find any related topic in the newsgroups or docs... cheers, christian -- GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net From lucio at movilogic.com Wed Oct 31 12:17:20 2001 From: lucio at movilogic.com (Lucio Torre) Date: Wed, 31 Oct 2001 14:17:20 -0300 Subject: Why 'self' ? References: <3BE04E7A.8E2CF101@ces.clemson.edu> Message-ID: <3BE03220.9080108@movilogic.com> Schaefer, F. wrote: >Hi all, > >It's been a while that I am working with Python and actually >the only thing I really do not like about it is 'self' in the >member function definitions as argument. If it >has to be there anyway, it is totally redundant to write it. > >So, why is self there ? > >Thanks, > >Frank > Not sure this is THE reason. Maybe there are historical questions with bound and unbound methods. but the feature is cool. classa.method(classb_instance, **args) its the way to do super.__init__() lucio From info at devshare.de Sun Oct 21 09:06:52 2001 From: info at devshare.de (Johannes Gamperl) Date: Sun, 21 Oct 2001 15:06:52 +0200 Subject: looking for CGI examples References: <_BxA7.1195$R43.271697@newsb.telia.net> Message-ID: thx tim ... i start searching *g* From huaiyu at gauss.almadan.ibm.com Fri Oct 19 14:45:14 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 19 Oct 2001 18:45:14 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net><9ql9l5$tcr$1@slb5.atl.mindspring.net><9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> Message-ID: On Fri, 19 Oct 2001 05:10:08 -0600, Andrew Dalke wrote: >Markus Schaber: >>Maybe this form could be expanded to allow: >> >>do >> some >> statements >>while cond: >> something >> else > >This post is exactly why this topic needs to be written up >in a PEP - even if the decision is not to implement it. This >same proposal has come up many, many times and I would like to >say > > "Yep, look at PEP 12345" This particular structure is the most appealing, except for historical reasons: - presumably multiple "while" parts would be allowed. - If the "do" part is optional, it would be difficult to locate the start of a loop. - If the "do" part is mandatary, the keyword "while" must be changed - to what? One small problem is whether the while part should be indented or not: It is more like a "case" statement (with fall through) than an "elif" statement. > >Huaiyu Zhu? Want to finish up your PEP? I'd love to, but I've already spent more time on this than I could afford. It would take additional time to summarize all the new points raised. Anyone can take it over anyway (I haven't even applied for a PEP number yet). I'd be glad to send over the fragmented notes I've taken on this subject. Are you interested, Andrew? BTW, Christopher A. Craig got a different statistics by searching "while 1", which would be similar to what you said before. My quick search on "break" is somewhat different. Anyone care to make a more thourough comparison? Huaiyu From vig at ParallelGraphics.COM Fri Oct 19 08:56:34 2001 From: vig at ParallelGraphics.COM (Ivan A. Vigasin) Date: Fri, 19 Oct 2001 16:56:34 +0400 (MSD) Subject: Dictionary from list? In-Reply-To: Message-ID: On Fri, 19 Oct 2001, Michael Hudson wrote: > />> def beargh(d): > |.. unique = [] > |.. def ouch(x,y): > |.. if x is unique: > |.. return y > |.. else: > |.. d[x] = y > |.. return unique > |.. return ouch > \__ > ->> d = {} > ->> reduce(beargh(d), ['a', 1, 'b', 2]) > [] > ->> d > {'a': 1, 'b': 2} Idea is great! It comes from functional programming? Your code doesn't work in my Python 2.1 ... t1.py:1: SyntaxWarning: local name 'd' in 'beargh' shadows use of 'd' as global in nested scope 'ouch' def beargh(d): t1.py:1: SyntaxWarning: local name 'unique' in 'beargh' shadows use of 'unique' as global in nested scope 'ouch' def beargh(d): Traceback (most recent call last): File "t1.py", line 12, in ? reduce(beargh(d), ['a', 1, 'b', 2]) File "t1.py", line 4, in ouch if x is unique: NameError: global name 'unique' is not defined I slighly modified your code and got the following: class beargh: def __init__(self,d): self.d = d def __call__(self,x,y): if x == []: return y else: self.d[x] = y return [] d = {} reduce( beargh(d), ['a', 1, 'b', 2] ) print d Regards, Ivan ICQ: 22181170 From quetpie75 at yahoo.com Wed Oct 10 10:42:47 2001 From: quetpie75 at yahoo.com (Maria Martino) Date: Wed, 10 Oct 2001 07:42:47 -0700 (PDT) Subject: My apologies... In-Reply-To: <1002720327.397.31355.m10@yahoogroups.com> Message-ID: <20011010144247.33470.qmail@web10904.mail.yahoo.com> Hello I apologize to everyone in the group that my posting came up 4 times. To be honest, I did not mean to post more than once. It was a little tricky for me trying to figure out how to post on the usenet site. I thought I was posting in different areas. I am truly sorry if it came across as annoying. I do not want anyone to get that idea. I am just trying to find people for this opportunity. Anyhelp is greatly appreciated. Thank you! Maria Martino IT Recruiter Kelly Services 212-984-1129 --- python-list at yahoogroups.com wrote: > ------------------------ Yahoo! Groups Sponsor > ---------------------~--> > Pinpoint the right security solution for your > company- Learn how to add 128- bit encryption and to > authenticate your web site with VeriSign's FREE > guide! > http://us.click.yahoo.com/yQix2C/33_CAA/yigFAA/saFolB/TM > ---------------------------------------------------------------------~-> > > There are 25 messages in this issue. > > Topics in this digest: > > 1. Deploy without distribute python source > code > From: python_only at yahoo.com (Goh S H) > 2. Microhydrin? & Crystal Energy? Special + > BONUS!!! > From: health at heylady.com > 3. newbe question > From: John Thingstad > > 4. Re: Deploy without distribute python source > code > From: > 5. py2exe or mcmillan for creating a exe file > From: "Song" > 6. Re: YOU ARE ALL GAY! > From: Geoffrey Pointer > > 7. changing `import' to use other than .py > From: Harald Kirsch > > 8. Re: Python questions -> compiler and > datatypes etc > From: Billy > 9. swocket! help op python's expert > From: "Bartosz Aninowski" > 10. Re: Curious assignment behaviour > From: -$Paul$- at verence.demon.co.uk (Paul > Wright) > 11. (2nd guidance) Let's get $5,000.00 by > responding to a questionnaire.- VLC Inc. > From: a_saka at vlcank.co.jp > 12. Quixote+mod_python vs. mod_python+htmlgen's > templatepage > From: rdrew at cia-group.com (Ray Drew) > 13. Sockets > From: hugomartires at hotmail.com (Hugo > Martires) > 14. LIKE missing in gadfly > From: cdelarue at bigfoot.com (Christophe > Delarue) > 15. Newbie: tkinter question > From: attila.pletyak at anemo.com (Attila > Pletyak) > 16. Re: Spewing SQL query resultset to HTML > table... > From: "Steve Holden" > > 17. Re: Sockets > From: "Steve Holden" > > 18. Re: changing `import' to use other than .py > From: Gordon McMillan > 19. Re: Sockets > From: Gordon McMillan > 20. Re: LIKE missing in gadfly > From: Gordon McMillan > 21. Re: Newbie: tkinter question > From: claird at starbase.neosoft.com > (Cameron Laird) > 22. Re: simple threading (or not as the case > may be) > From: Mark Robinson > > 23. Python, XML, and databases > From: > 24. Re: How to install on NT without write > permissions to c:\winnt > From: Gerhard H?ring > > 25. Re: swocket! help op python's expert > From: Gerhard H?ring > > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 1 > Date: 10 Oct 2001 02:38:26 -0700 > From: python_only at yahoo.com (Goh S H) > Subject: Deploy without distribute python source > code > > Hi all, > I would like to deloy some projects which making > use of Python, but > I do not want to distribute Python source code due > to several reasons. > Is there any ways to do this? Is it portable to > distribute .pyc? > > Regards, > Goh > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 2 > Date: Wed, 10 Oct 2001 05:02:41 -0500 > From: health at heylady.com > Subject: Microhydrin? & Crystal Energy? Special + > BONUS!!! > > > > [This message is not in displayable format] > > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 3 > Date: Wed, 10 Oct 2001 11:39:44 +0200 > From: John Thingstad > Subject: newbe question > > I wrote the following function to use polymorphism. > > > def rootClassName(var): > """Return the name of the root of a sigle > inheretance class tree. > If multiple inheritance is used the leftmost > class is traversed.""" > if type(var) is ClassType: > cls = var > while len(cls.__bases__) != 0: > cls = cls.__bases__[0] > return cls.__name__ > else: > return "" > > > Is there a built in function to do this ? > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 4 > Date: Wed, 10 Oct 2001 03:46:02 -0600 (MDT) > From: > Subject: Re: Deploy without distribute python source > code > > > > Designing the webpages of tomorrow > http://webme-eng.com > Designing the MMORPGS of tomorrow > http://worldforge.org > > On 10 Oct 2001, Goh S H wrote: > > > Hi all, > > I would like to deloy some projects which > making use of Python, but > > I do not want to distribute Python source code due > to several reasons. > > Is there any ways to do this? Is it portable to > distribute .pyc? > > > .pyc files are only for that version of python and > won't work on others > overall it is not a good idea. They can also be > reverse engineered > trivially if that is what you are worried about. You > are probably better > off using one of the freeze type programs. > > > Regards, > > Goh > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > === message truncated === __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From opengeometry at yahoo.ca Tue Oct 16 06:30:24 2001 From: opengeometry at yahoo.ca (William Park) Date: Tue, 16 Oct 2001 06:30:24 -0400 Subject: FW: [Python-Dev] conditional expressions? In-Reply-To: <9qgsul$5ep$1@thorium.cix.co.uk>; from gbreed@cix.compulink.co.uk on Tue, Oct 16, 2001 at 09:00:05AM +0000 References: <9qgcvk$91j$1@animus.fel.iae.nl> <9qgsul$5ep$1@thorium.cix.co.uk> Message-ID: <20011016063024.A410@node0.opengeometry.ca> On Tue, Oct 16, 2001 at 09:00:05AM +0000, gbreed at cix.compulink.co.uk wrote: > > > A conditional expression analogy to list comprehensions would be x > > > = (a if b else c) > > You can also remove the parentheses, and not have to worry about the > "if" starting a new line. I believe Perl and Ruby has x = a if b -- William Park, Open Geometry Consulting, 8 CPU cluster, Linux (Slackware), Python, LaTeX, Vim, Mutt, Tin From skip at pobox.com Wed Oct 17 13:23:06 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 17 Oct 2001 12:23:06 -0500 Subject: How To compile Python without any module. In-Reply-To: <3bcdb927$0$32580$626a54ce@news.free.fr> References: <3bcdb927$0$32580$626a54ce@news.free.fr> Message-ID: <15309.48762.730285.925084@beluga.mojam.com> dag> In fact i don't need the build in modules like sys. dag> So how could i built python with out the build in modules. dag> I want to use Python on 8Mo of Flash and 16Mo of RAM. I'd be real surprised if Python worked very well without the sys module. Still, you might be able to get away with just commenting it out of the makefile. It's one of the files listed in the PYTHON_OBJS make variable. To get an idea of how central the sys module is to Python's operation, notice that Include/sysmodule.h is #included by Include/Python.h, which is #included by just about every C file in the distribution. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From sholden at holdenweb.com Thu Oct 11 21:05:13 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 11 Oct 2001 21:05:13 -0400 Subject: Holden's Python Web Programming Book References: <4glx7.11739$I83.231559@atlpnn01.usenetserver.com> Message-ID: "DeepBlue" wrote ... > Thanks Steve. Looking at the TOC, it looks like your book and Mitchell's > book will complement one another. I was looking for implementing > client/servers in Python and an advanced look at Python web DB systems. So > your book looks like it will be helpful. > One note though: Chapters 12 and 13 in the TOC you give look like they have > the same content. Maybe by mistake. > DB > Thanks for pointing that out. Now fixed. regards Steve -- http://www.holdenweb.com/ From use-net at schabi.de Tue Oct 23 17:25:49 2001 From: use-net at schabi.de (Markus Schaber) Date: Tue, 23 Oct 2001 23:25:49 +0200 Subject: Apologise (was: Re: IF STATEMENTS) References: <20011018002005.53f58ef2.use-net@schabi.de> <20011018102800.11c71435.use-net@schabi.de> Message-ID: <20011023232549.66ef1b7f.use-net@schabi.de> Hi, On Sat, 20 Oct 2001 20:29:03 +0100, Martin Armstrong wrote: > >In my eyes, they look conform to the standards, and the first part > >with type text/plain is the content. > > There is nothing wrong with the message that you *sent* . > > However, there is a problem with it when it gets to Usenet on > comp.lang.python if you post via mail.python.org. > > The headers of the message you sent has: > > Content-Type: multipart/signed; protocol="application/pgp-signature"; > boundary="=.':S84?'b+rS._7" > > But when it got to c.l.py the header had been changed to: > > Content-Type: multipart/signed; protocol="application/pgp-signature"; > boundary="=.': S84?'b+rS._7" > > (see the space after the colon in the boundary string) That's strange, as I think I posted the message to the news group, and my server contains the message with the following Headers: Path: sol.wohnheim.uni-ulm.de!134.60.220.16 Content-Type: multipart/signed; protocol="application/pgp-signature"; boundary="=.J)xw2neA.fQyRJ" There seems to be no colon in the delimiter. So the conversion seems to be appeared somewhere between my news server and mailman. > [Explanation of mailman bug] Thanks, that was a really good explanation. > [Markus] > >Nevertheless, I won't send any signed messages here again, as long as > >this issue is not resolved. > > Watch the c.l.py headers for a new version of Mailman being used and > then try another signed message. Thanks, I'll do this. But my and your messages don't have this header (so you seem to deliver per NNTP, too.), so I have to search a little to grab this header :-) markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From tnaran at direct.ca Fri Oct 5 23:18:55 2001 From: tnaran at direct.ca (Travers Naran) Date: Fri, 5 Oct 2001 20:18:55 -0700 Subject: problem controlling MS Word from Python References: <9pkhei0rbe@enews2.newsguy.com> Message-ID: <9plt6r0e3b@enews1.newsguy.com> "Andrew Brown" wrote in message news:Xns9131CBC91B8CAandrewdarwinwarscom at 62.253.162.106... > "Travers Naran" wrote in > <9pkhei0rbe at enews2.newsguy.com>: > > >Can you clarify what you mean by "crashes"? Does python return a > >traceback, or does the python interpreter itself crashes? I wouldn't be > >surprised if it was the later: I've noticed Office apps connected by > >automation can crash the client. > > > > > No traceback. the interpreter crashes when Word throws up a dialogue box > saying that it cannot translate a particular doc file to html. Nifty. It sounds like there's a bug in the OLE code in Python then, or a dangerous Automation interface in Office. Considering the number of times Office Automation has hooped my Perl scripts (back off, language-dogs!! :-) ), I'm inclined to blame Office. Could you post some sample of your code? I have Office 97 on my machine (with HTML saving extensions). I'd be interested to see if it happens in the older Office as well. From andy.pevy at nokia.com Tue Oct 23 07:53:10 2001 From: andy.pevy at nokia.com (andy.pevy at nokia.com) Date: Tue, 23 Oct 2001 11:53:10 GMT Subject: Auto debug on un-caught exception. Message-ID: Hi Guys I have seen somewhere out there in net land a method of automatically running the debugger when an un caught exception occurs. Can anybody point me in the right direction.... Thanks Andy Pevy -- We were always told that a million monkeys typing for a million years would eventually produce the works of Shakespeare. Now, thanks to the Internet, we know this is not true. From greg at cosc.canterbury.ac.nz Wed Oct 10 20:21:57 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 11 Oct 2001 13:21:57 +1300 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> Message-ID: <3BC4E625.E6C73878@cosc.canterbury.ac.nz> Paul Rubin wrote: > > I feel seriously cramped in Python when I have to say > > while 1: > x=get_next() > if not x: break > whatever(x) I feel the solution to this is *not* to go in for any sort of assignment-in-expressions hackery, but to provide a decent loop-and-a-half control structure. My current idea for this is while: x = get_next() gives x: whatever(x) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From jim at interet.com Fri Oct 19 13:55:57 2001 From: jim at interet.com (James C. Ahlstrom) Date: Fri, 19 Oct 2001 13:55:57 -0400 Subject: newsgroup traffic way down? References: <8827e15d.0110170823.672f0a63@posting.google.com> Message-ID: <3BD0692D.BFE42CFA@interet.com> Chris Ryland wrote: > > Is it just I, or is c.l.p traffic way down lately? I am reading using uunet as a server, and I think c.l.p traffic is way down too. Jim Ahlstrom From rharkins at thinkronize.com Fri Oct 19 09:38:38 2001 From: rharkins at thinkronize.com (Rich Harkins) Date: Fri, 19 Oct 2001 09:38:38 -0400 Subject: Dictionary from list? In-Reply-To: <6KVz7.132664$vq.30203786@typhoon.ne.mediaone.net> Message-ID: Here's one (albeit ugly) possibility using list comprehensions and a sufficiently new Python: # Setup variables d={} l=[n1,v1,n2,v2,n3,v3,...] # Here's the money line... [d.__setitem__(l[i],l[i+1]) for i in range(0,len(l),2)] It is trading one type of loop for another but it will work. I did some performance analysis and it does turn out that using a list comprehension here is slower than using a loop, not to mention less readable to new Pythonists. I recommend the loop form myself, it's easy to read and it's fast enough to do the job. Rich > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Jim Correia > Sent: Friday, October 19, 2001 9:18 AM > To: python-list at python.org > Subject: Re: Dictionary from list? > > > In article , Michael Hudson > wrote: > > > > I'm a python newbie. I know how to do it "by hand" with a > loop, but is > > > there a built in conversion operater that will let me do something > > > simply like the perl assignment? > > > > No. Write the loop. > > That's unfortunate - a simple assignment would be better. In the > simplest case of my usage, the loop (while ultra short) could be 50% of > the code. > > > I've never found myself needing to do this, but that may be because > > I'm not used to having a convenient way of going from > > [k1,v1,k2,v2,...] to a dict. > > The particular situation is the python implementation is going to be a > command line script. The calling convention for this script is to pass > arguments on the command line in key value pairs. The perl > implementation looks like (in the simplest case) > > my %args = @ARGV; > > foreach(keys %args) > { > print("$_: $args{$_}\n"); > } > > And it would be called from the command line as > > perl myScript.pl name fred age 23 occupation "gravel worker" > > I'd like to implement the script with the same calling conventions in > python, and have an "easy" (typing wise, not conceptually, but I guess > I'll have to write a reusable function) way to take the arguments on the > command line and turn them into a dictionary. > > Jim > -- > http://mail.python.org/mailman/listinfo/python-list > From mlh at idi.ntnu.no Sat Oct 20 19:36:54 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 21 Oct 2001 01:36:54 +0200 Subject: Magic Module Methods? References: Message-ID: <9qt1qm$f7l$1@tyfon.itea.ntnu.no> "Tim Peters" wrote in message news:mailman.1003614080.13207.python-list at python.org... > [Magnus Lie Hetland] > > I just found myself needing (or wanting) a module which > > could have default values for variables that weren't set; > > I expect it would be near-infinitely clearer if you simply set the module > variables to their default values explicitly at module initialization time. OK - bad example (and terse explanation). The situation was this: I was using a module as a config file, and at the same time as an object containing defaults at some other point in the program (available for users of the library). Therefore, the defaults should be accessible from the module, but the people writing the config file might not want to set absolutely all the values... I could of course do an update() on the module __dict__, and that might be clearer, but possibly not near-infinitely? ;) [snip] > Probably, with enough code to implement it. Lists could act more like > integers too, but I doubt I'd fight for that either . Well, I wasn't saying that modules should act like lists or integers or any other specific class of objects -- simply like objects in general. (Everything is supposed to be an object now, right?) > you-can-subclass-the-module-type-in-2.2-but-hoping-you-don't-ly > y'rs - tim Subclassing the module type wouldn't be of much help here, would it? I'd still end up with the standard object-as-module trick, only using a module object. I still couldn't get the object-like behaviour directly from the module. (And no, I probably won't subclass it anyway.) I don't really see what's wrong with the idea (of magic functions in a module), but I'll accept "Tim doesn't like it" as a valid reason. :) -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From phr-n2001d at nightsong.com Tue Oct 9 03:48:00 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 00:48:00 -0700 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> Message-ID: <7xd73x1cgf.fsf@ruckus.brouhaha.com> Gerhard H?ring writes: > On Mon, Oct 08, 2001 at 07:51:08PM -0700, Paul Rubin wrote: > > I don't think anything in the standard Python library is GPL'd. > > (GPL-compatible yes, GPL'd no). > > But AFAIK some functionality is only there if you link against GPL'd > libraries like GMP (for arbitrary length Python longs), readline and > maybe others I forgot. I don't think the gmp module is in the standard distribution. Anyway, GMP itself is LGPL'd, not GPL'd, so you can use GMP in closed programs as long as you offer the source of the version of GMP you distribute (but NOT the surrounding program you incorporate it in). I'm not sure about Readline. > So you should perhaps still be careful before distributing a binary > version of Python and linking in your own modules. If "your own modules" means modules you wrote yourself, there should be no problem. If it means GPL'd modules written by other people, your program needs to be GPL'd as well (i.e. you must offer source to the whole thing). The issue I was raising was that getting permission from a GPL'd module's main author may not be enough to make it ok to use the module in a closed program. GPL'd programs often have a lot of people's hands in them (that's the whole point of the GPL). If I write a GPL'd module and users start sending me fixes and improvements, I have to think of them as contributors who worked on the program with the understanding that it was free. If someone else then wants to pay me for the right to use the improved module in a closed product, I have to get the permission of everyone else who contributed, which may mean they all have to also get paid. IMO, if you write and release a free program, it's best to decide at the time of the initial release whether you want to allow closed use, choose your license accordingly, announce your choice and stick to it. To do anything else isn't fair to others who might contribute expecting one thing but getting another. (I say this from having gotten burned several times over these issues in various ways--live and learn.) From DeepBlue at DeepBlue.org Mon Oct 22 17:27:31 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Mon, 22 Oct 2001 16:27:31 -0500 Subject: Database Sessions and Transactions References: <23891c90.0110220232.1b0e9139@posting.google.com> Message-ID: This is in reply to Steve and Paul: Actually what happened is that I worked on a cgi program in Delphi 5 and immediately after that I started checking on Python to use it on a Sun computer for a cgi program. Believe it or not, on Friday afternoon, I mixed up my terminology between the two languages while I was trying to understand CGI and connecting to databases using Python. Steve answered the first part on transactions. Anyway, in Delphi 5, StartTransaction is an attribute of a database connection. Say you have a database component. Database.StartTransaction 'packages' a transaction. However, I can see now that we do not need this. The question is: What are the advantages of StartTransaction on a database connection? I can see that in Python one issues sql commands to a database and one can 'envelope' them in some form of a transaction. So instead of asking where is the transaction in Python, I have turned to think about the use of StartTransaction in Delphi.............. [continued below] "Paul Boddie" wrote in message news:23891c90.0110220232.1b0e9139 at posting.google.com... > "DeepBlue" wrote in message news:... > > I am working on a CGI program in Python that connects to an Oracle database. > > I am wondering on how to implement a transaction that belongs to a database > > connection so that everything that belongs to the transaction can be rolled > > back. > > Assuming that there isn't anything that the CGI program talks to, > between itself and the database system, which holds the connection > object and keeps the connection open... > > > In other words, the scope of the rollback is NOT the database connection BUT > > the transaction that is defined from within the database connection. > > ...you appear to want to be able to open a connection by instantiating > a connection object, explicitly define a transaction, do some work, > suspend the transaction as you close the connection, and then upon a > subsequent invocation of your CGI program, re-open the connection and > resume the transaction. > Not quite. As I said above, I as thinking more in Delphi terms where one can use the StartTransaction attribute to 'package' a set of sql commands. Now, I am not even sure anymore what is the need for this after Steve's reply. Anyway, the issues are clear in my mind now regarding transactions. > > Also, I can find no reference in Python DB API 2 to Sessions. How do we > > manage different sessions/connections? > > There will definitely be people who know more about this than I do, > but you should subscribe to the DB-SIG mailing list and post your > question there - you can find the subscription page from > http://www.python.org, of course. Thanks, I will! But to summarize: when I posted my question I was thinking in Delphi 5 terms where one can use a Session component or when a session component is created by default for every database connection. A session manages an individual database connection. So when many users are using the same program at the same time, every user is associated with a session to ensure that multiple connections are kept independent from one another. My concern is what happens when many people log into a database through a Python cgi program (I plan to use DCOracle2), how are these connections managed so that we can ensure the integerity of independence of different transactions performed. In Python: is the connection created with every logon denotes a separate independent session to ensure integrity of data and transactions? DeepBlue From dale at riverhall.NOTHANKS.co.uk Wed Oct 17 13:31:40 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 17 Oct 2001 18:31:40 +0100 Subject: SOAP.py References: Message-ID: <53grstoh2uojuheig0jsb0qbc8dlr6as0p@4ax.com> I've seen favourable comments on this: http://soapy.sourceforge.net/ -- Dale Strickland-Clark Riverhall Systems Ltd From mnot-google at mnot.net Fri Oct 26 15:57:21 2001 From: mnot-google at mnot.net (Mark Nottingham) Date: 26 Oct 2001 12:57:21 -0700 Subject: namespaces for XMLWriter Message-ID: <3f8f495.0110261157.33c3d9de@posting.google.com> Anyone aware of something like xml.sax.writer that does namespaces? Thanks, From msoulier at nortelnetworks.com Wed Oct 3 10:42:46 2001 From: msoulier at nortelnetworks.com (Michael P. Soulier) Date: 3 Oct 2001 14:42:46 GMT Subject: Nicer Tkinter on UNIX? References: Message-ID: On 3 Oct 2001 10:39:55 GMT, Artur Skura wrote: > > Is there a way to make Tkinter use KDE/GTK themes on unices? Or change the > interface in any way? (I don't consider wx... stuff, as it forces users to > install additional software). http://www.wxpython.org/ http://www.gtk.org/bindings.html Mike -- Michael P. Soulier, TD12, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From emile at fenx.com Fri Oct 26 09:01:59 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 26 Oct 2001 06:01:59 -0700 Subject: Dynamic assignment References: <9raji3$jpb$01$1@news.t-online.com> Message-ID: <9rbn4v$smd9l$1@ID-11957.news.dfncis.de> ----- Original Message ----- From: "Ingo Blank" Newsgroups: comp.lang.python Sent: Thursday, October 25, 2001 7:59 PM Subject: Dynamic assignment > Hi, > > I want to dynamically create variables and assign values to them. > > I tried the following: > > >>> vn = "dynVar" > >>> vv = 1 > >>> eval("%s=%d" % (vn,vv)) > Traceback (most recent call last): > File "", line 1, in ? > File "", line 1 > dynVar=1 > ^ > SyntaxError: invalid syntax > > Q1: Why is the "syntax error" issued ? > Q2: *HOW* do I achieve a dynamic assignment ? > For Q2, if using a dictionary just won't do it, look into using setattr. >From 2.3 Built-in Functions: setattr(object, name, value) This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value. The string may name an existing attribute or a new attribute. The function assigns the value to the attribute, provided the object allows it. For example, setattr(x, 'foobar', 123) is equivalent to x.foobar = 123. One way of adding a variable to the main namespace is: >>> import sys >>> setattr(sys.modules['__main__'],'abc','def') >>> abc 'def' HTH, Emile van Sebille emile at fenx.com --------- From infotechsys.wayne at verizon.net Fri Oct 26 08:32:16 2001 From: infotechsys.wayne at verizon.net (wayne) Date: Fri, 26 Oct 2001 08:32:16 -0400 Subject: Parrot? Message-ID: <3BD957D0.1C9C2335@verizon.net> Hi, Is there a IRC for the new script language? If so can someone pass it on. Thankes. Wayne From sholden at holdenweb.com Sun Oct 7 13:13:26 2001 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 7 Oct 2001 13:13:26 -0400 Subject: python process killed References: Message-ID: "Kiran Kumar Gahlot" wrote ... > Hi, > > I was trying to run a giant program, which generates something like > 200 million lines of data and write to a file. The python program > stops in between and just displays "Killed" after terminating. > > Can i avoid this abrupt killing of the program and force it to run > completely. > Another request for "psychic Python" debugging :-) You give no details of your environment: Windows (if so which flavor), Python version? In the absence of more data, I might surmise you are running under Unix of some flavor, and the shell is killing your process because it has exceeded the process resource limits. Does this help at all? If not, please post a little more information to help determine what the problem might be... regards Steve -- http://www.holdenweb.com/ From senux at senux.com Mon Oct 22 08:13:28 2001 From: senux at senux.com (Brian Lee) Date: Mon, 22 Oct 2001 21:13:28 +0900 Subject: trace log in error Message-ID: <20011022211328.A28737@jupiter.senux.com> Hi, I'm newbie at Python programming. How can I get more detailed error information in try.. except sentence? Follow code print out what kind of error is occurs but I want to read trace log for the error. Is it possible to read it? If possible how can I do it? try: my_function() except: print sys.exc_type, sys.exc_info Thank you in advance. -- Brian Lee You could get a new lease on life -- if only you didn't need the first and last month in advance. From phr-n2001d at nightsong.com Sat Oct 13 22:12:19 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 13 Oct 2001 19:12:19 -0700 Subject: signum() not in math? References: <7xu1x3mlx6.fsf@ruckus.brouhaha.com> <3bc8f020.458583768@wa.news.verio.net> Message-ID: <7x1yk7c6m4.fsf@ruckus.brouhaha.com> bokr at accessone.com (Bengt Richter) writes: > >This is partly because of the enormous speed difference between the > >interpreter and C functions, and partly from a desire of not having to > > Has anyone considered an "inline" attribute for Python functions, to > avoid the proportionately large calling overhead for trivial functions? Inlining requires that the function definition be available when the call is compiled, and also it changes the semantics since the code lookup is no longer dynamic (that's not necessarily a bad thing though). Basically though, inlining, if apropriate, should be done by the compiler without the user needing to ask for it explicitly. The user might have to provide some advice indicating inlining is ok. Even with inlining, C code will be a lot faster than interpreted code. From achim.domma at syynx.de Mon Oct 8 05:28:13 2001 From: achim.domma at syynx.de (Achim Domma) Date: Mon, 8 Oct 2001 11:28:13 +0200 Subject: bound member functions ? References: <9proou$rsh$04$1@news.t-online.com> Message-ID: <9prrfv$vlf$04$1@news.t-online.com> "Steve Holden" wrote in message news:gXdw7.3286$Sj2.69338 at atlpnn01.usenetserver.com... > Yes. The reference to the bound method will keep the object around as long > as you need it. Thanks, I love Python !!! ;-) From s.keim at laposte.net Thu Oct 4 04:56:00 2001 From: s.keim at laposte.net (sebastien) Date: 4 Oct 2001 01:56:00 -0700 Subject: Mutable default values for function parameters Message-ID: <7da8d8f8.0110040056.42443bb@posting.google.com> I'd like to point something that is said in ?4.7.1 of the tutorial: "Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list or dictionary" I think that this point is really difficult to understand. That means that parameters with mutable default value are global to all the calls of the function: >>> def sample(x,d=[]): ... d.append(x) ... print d ... >>> sample(1) [1] >>> sample(2) [1, 2] This is a really confusing and I always fall in this sort of trap. Maybe a bad neuronal connection;-) For sample I have tried to do something like Eiffel loop variant: def variant(data, old_data=[None]): st = (data <> old_data[0]) old_data[0] = data return st for i in range(5): assert variant(i) print i while i>0: assert variant(i) i -= 1 This fail because old_data remain the same between the last loop in the for and the first one in the while. I've seen the same problem in http://www-106.ibm.com/developerworks/library/l-pycon.html?n-l-9271 def randomwalk_static(last=[1]): # init the "static" var(s) rand = random.random() # init a candidate value if last[0] < 0.1: # threshhold terminator return None # end-of-stream flag while abs(last[0]-rand) < 0.4: # look for usable candidate print '*', # display the rejection rand = random.random() # new candidate last[0] = rand # update the "static" var return rand def print_num(): num = randomwalk_static() while num is not None: print num, num = randomwalk_static() The first call of print_numl work fine, but later calls will fail because 'last' parameter will always contain a number <0.1 Maybe it would be better to have an alternate behavior for default value creation. Instead of creating them at function definition, the compiler could do the creation when it evaluate the function call. This will not be easy because of Python dynamism: the compiler doesn't know function signature when it builds the call. And this is even worse for object methods where the signature can be different for two classes. Or maybe, someone could give me an obvious way to solve this kind of problems? Thanks. From alf at sagittarius.logilab.fr Tue Oct 16 11:20:08 2001 From: alf at sagittarius.logilab.fr (Alexandre Fayolle) Date: Tue, 16 Oct 2001 15:20:08 +0000 (UTC) Subject: [ANN] Narval 1.1 Message-ID: Logilab (www.logilab.com) announces the release of Narval 1.1 GPL'd Intelligent Personnal Assistant Framework http://www.logilab.org/narval News ---- The whole project has moved from python 1.5.2 to python 2.1 A few new features have made it into the engine, such as automatically reloading modules that have changed on disk, as well as some speed improvements. Several new modules (automatic classification, LDAP directory access, checksum computing) have made it into the standard library. The Horn GUI has been completely redesigned for better flexibility, speed and better ease of use. The infopal application (available separately) has received a large number of improvements. The mailing lists have been moved to use mailman. More information can be found at http://lists.logilab.org/mailman/listinfo Description ----------- Narval is a framework (language + interpreter + GUI/IDE) dedicated to the setting up of intelligent personal assistants (IPAs). An Intelligent Personal Assitant is a companion that will help you in your daily work in the information world. It runs on your machine or on a remote server, and you can communicate with it via all standard means (email, web, telnet, phone, specific GUI, etc). It executes recipes (sequences of actions) you wrote, to perform a wide range of tasks, such as prepare your morning newspaper, help you surf the web by filtering out junk ads, keep searching the web day after day for things you want, participe in on-line auctions, learn you interests and bring you back valuable information, take care of repetitive chores, answer e-mail, negociate the date and time of a meeting, and much more... It is easy to extend the built in action library by writing new actions in Python. Infopal, your information pal, is a Narval application that implements part of the above, but Narval makes it easy for you to set up new assistants. Others applications will soon be available from Logilab. Logilab S.A. is a French company that specializes in the fields of artificial intelligence, knowledge management, data analysis and natural language processing. More info --------- Please see http://www.logilab.org/narval http://www.logilab.com http://www.logilab.fr or contact contact at logilab.fr Alexandre Fayolle -- LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org Narval, the first software agent available as free software (GPL). From jeff at ccvcorp.com Wed Oct 17 16:32:17 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 17 Oct 2001 13:32:17 -0700 Subject: class browser for python ?? References: Message-ID: <3BCDEAD1.C0975CAC@ccvcorp.com> Markus Jais wrote: > hello, > is there a tool out there, which can show me the class > structure of a python module > something like a class browser would be needed > or a tool that can generate UML diagramms from python sources > > any hints are welcome > > markus There is a basic class/namespace browser built into the PythonWin IDE, if you have access to a Windows machine. If not, you could probably find the source for it (from www.activestate.com), pull out the relevant parts, and make your own..... Jeff Shannon Technician/Programmer Credit International From phr-n2001d at nightsong.com Tue Oct 16 23:22:36 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 16 Oct 2001 20:22:36 -0700 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> <9psk9s$rbk@newton.cc.rl.ac.uk> <7x669o7r4k.fsf@ruckus.brouhaha.com> <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <7xsncpxxc6.fsf@ruckus.brouhaha.com> <1f186g5.wcfiwzcwvqv4N%news@davidglasser.net> <7x669jyr9b.fsf@ruckus.brouhaha.com> <3BCA573D.C636629B@cosc.canterbury.ac.nz> <7xbsj9a7jv.fsf@ruckus.brouhaha.com> <3BCCE6F1.68687D7A@cosc.canterbury.ac.nz> Message-ID: <7xbsj73q83.fsf@ruckus.brouhaha.com> Greg Ewing writes: > > The last item processed in that case is the last item processed by > > a previous run of the program. > > What if the program hasn't been run before? There was a backlog of items to process before the program was run for the first time. So the n=0 case didn't matter. From mjais at web.de Thu Oct 25 06:19:59 2001 From: mjais at web.de (Markus Jais) Date: Thu, 25 Oct 2001 12:19:59 +0200 Subject: Learing Python, Newbie question References: Message-ID: In article , "Johannes Gamperl" wrote: > Hello, > > i just starting to learn python ... so i've two questions: > > 1. is there a easy way to test, if a file exists? use the os module import os if os.path.exists("path_fo_file"): print "yes" you can find out more about this at: http://www.python.org/doc/current/lib/module-os.path.html markus From tim.one at home.com Sat Oct 13 00:20:52 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 13 Oct 2001 00:20:52 -0400 Subject: signum() not in math? In-Reply-To: <3BC6B774.4688E9A2@darwin.in-berlin.de> Message-ID: [Dinu Gherman] > Time for a periodic frenzy about the standard lib again... ;-) All right! Controversy, conflict, catharsis and group hugs. > How comes there is no sign() or signum() function in math? You won't like the real answer, so maybe I won't give it. OK, I will: Python's math module is just a bunch of macro-generated thin wrappers around the platform libm: FUNC1(acos, acos, "acos(x)\n\nReturn the arc cosine (measured in radians) of x.") FUNC1(asin, asin, "asin(x)\n\nReturn the arc sine (measured in radians) of x.") FUNC1(atan, atan, "atan(x)\n\nReturn the arc tangent (measured in radians) of x.") etc. Python doesn't have signum because standard C doesn't, and that's all there is to it. The only thing Python's math module has that wasn't in strict C89 is math.hypot() (which almost every libm has, despite its absence in the C89 standard). Conversely, everything in std C89 libm is in Python's math module. > ... > The question is: why isn't sign() in the math module (or, may- > be built-in)? Is it too trivial? I'm inclined to claim no more > so than, say, abs(). It's certainly far less used than abs(). > ... > Nobody needing it? Surprising. That too, I think: in part of your msg I snipped, you confessed to not finding a msg about it more recent than nearly 3 years old. > Ahh, a missing PEP, even? That could be the case... ;-) The new C99 mandates a whole pile of useful new functions, although not this one (the new signbit() function seems to come closest). Chalk it up to a lack of number-crunching worker bees. in-the-meantime-try-comparing-to-0-ly y'rs - tim From shriek at gmx.co.uk Tue Oct 23 09:37:55 2001 From: shriek at gmx.co.uk (Stephen) Date: 23 Oct 2001 06:37:55 -0700 Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> Message-ID: <97ae44ee.0110230537.38e11c59@posting.google.com> Thank you for the help, Thomas. Your suggestion is a good solution. I had briefly considered something similar ~ not caching the information but rather creating the "catdict" each and every time that I need to use it (which circumvents the problem of DB synchronization especially in multi-user environments) ~ however, I thought to myself "there has to be a better way, that's more scalable and faster". Hence my initial post. Thank you. Stephen. > If You're willing to sacrifice the memory, You could cache the > information. > > First extract all the category/parent pairs into a list. (eg. SELECT > parent_id, category_id FROM Categories) > then create and fill a dictionary which contain the parent and all > children: > > >>> catlist = [(0, 1), (0, 2), (1, 3), (3, 4), (1, 5), (3, 6), (2, 7), > (7, 8), (5, 9), (2, 10), (7, 11)] > >>> > >>> catdict = {0: (None, [])} # (parent, children) > >>> for catpair in catlist: > ... catdict[catpair[1]] = (catpair[0], []) > ... > >>> for catpair in catlist: > ... parent = catdict.get(catpair[0]) > ... while parent: > ... parent[1].append(catpair[1]) # append to list of children > ... parent = catdict.get(parent[0]) # parent's parent > ... > >>> print catdict > {11: (7, []), 10: (2, []), 9: (5, []), 8: (7, []), 7: (2, [8, 11]), 6: > (3, []), 5: (1, [9]), 4: (3, []), 3: (1, [4, 6]), 2: ( > 0, [7, 8, 10, 11]), 1: (0, [3, 4, 5, 6, 9]), 0: (None, [1, 2, 3, 4, 5, > 6, 7, 8, 9, 10, 11])} > > Now you can get all the children of a given category by calling > catdict[category_id]. > > Ofcourse You'd have to keep the dictionary in sync when updating the > DB. From gherman at darwin.in-berlin.de Tue Oct 16 11:17:41 2001 From: gherman at darwin.in-berlin.de (Dinu Gherman) Date: Tue, 16 Oct 2001 17:17:41 +0200 Subject: signum() not in math? References: Message-ID: <3BCC4F94.9170B0BB@darwin.in-berlin.de> Tim Peters wrote: > > > Can someone expect from the Python standard library, too, 'only' > > those 90% of functionality needed by 'the crowd' and be treated > > with regret when not belonging to it, especially when the matter > > is so trivial? > > I've used a lot of languages over the endlessly tiring years, but > have never seen another language community so keen to avoid writing two-line > functions themselves. When a function you want is indeed trivial to code in > Python, that's a strong argument against bloating the core C code with it. As others have also pointed out at length, it wouldn't blow up any- thing. And as you try to point out, it might not be *exactly* as trivial as one might think. > > In math textbooks sign() is typically introduced just before or > > after abs(), which raises the question why Python has chosen to > > implement only abs() and not only sign(), > > As I explained last time, and as it says right at the top of the math module > docs: > > It [the math module] provides access to the mathematical functions > defined by the C standard. > > That's all it was designed to do, and all it does. If people want a fancier > math module, fine by me, but then (A) it needs a PEP; and, (B) it needs > volunteers to design, document, code, port and test the new stuff. > [...] > That was Guido's practical way of letting some other committee argue for > years (literally) about which functions are of most use, and exactly what > they should do. Trust me when I tell you there's nothing easy about math > library definition, design, or implementation, and especially not > floating-point math libraries. Well, even great decissions of the past benefit from an occasional reality-check, don't they? And the matters about trust and floating point issues don't seem to apply, do they? The former not in these brainwashing days and the latter not in this case... > > As the ActiveState Python cookbook comes closer to being printed > > it would be sort of embarassing to see a recipe therein for wri- > > ting a signum function, simply because you need it, wouldn't it? > > I won't find it embarrassing, no; it's more embarrassing that we haven't > invented a % format code to convert integers to Roman numerals, which is a > more frequent topic on the newsgroup, and wrt support for which Python > severely lags behind Common Lisp . Well, I have *some* doubts that people using Roman numerals will find them useful in cases where the % operator throws a ValueException for anything below I or greater than MMMM (if these were really implemented sticking to the, errm, specs...) which is for almost all integers... ;-) To prevent some folks from getting me wrong: I *do* like Py- thon and 2.2 will be likely the best Python there ever was, but I fail to understand why people don't care to make a damn jolly good product even better? All it takes in this case is to undust a few corners of the standard library and give it back some of the "ease-of-use"/ "battery-inluded" philosophy that it used to be advocated with. Now,-that-would-certainly-deserve-a-PEP'ly, Dinu -- Dinu C. Gherman ReportLab Consultant - http://www.reportlab.com ................................................................ "The world becomes a better place as a result of the refusal to bend to authority and doctrine." (Noam Chomsky) From olav.viken at kmss.no Wed Oct 17 10:55:17 2001 From: olav.viken at kmss.no (olav.viken at kmss.no) Date: 17 Oct 2001 14:55:17 GMT Subject: Python and win32api Message-ID: <9qk64l$i3e$1@oslo-nntp.eunet.no> This is what i'm trying to do with a simple Python script: - Retrive the operating system on the computer the script is running - Retrive the service pack installed - Retrive the native language of the OS installed. The first two is easy, but last one is giving me problems. This is from Microsoft knowledgebase HOWTO: Determine Default Language ID of Windows 95 or WinNT http://support.microsoft.com/support/kb/articles/q181/6/04.asp Which says in part: | SUMMARY | Some applications need to get the operating system's language ID. | GetSystemDefaultLangID doesn't work, because the user can change it | in the Control Panel. [...] | Under both Windows NT and Windows 95, you can get the language | information in the FileVersionInfo of User.exe by calling | GetFileVersionInfo, and then VerQueryValue (on \\VarFileInfo\\Translation") | on the VersionInfo block of the operating system's User.exe. | NOTE: This method is the most reliable. It works well under both Windows | NT and Windows 95. This method also works for Windows 3.1. I can't find the GetFileVersionInfo method under win32api, and I can't find another way of telling the language. Anyone? Thanks Olav From sholden at holdenweb.com Fri Oct 5 16:15:16 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 5 Oct 2001 16:15:16 -0400 Subject: how to create a def that has the behaviour like a built-in keyword... References: Message-ID: <0uov7.10085$rq1.241447@atlpnn01.usenetserver.com> "BA" wrote in message news:CAmv7.1117$iL5.54641 at typhoon1.gnilink.net... > hilo2u, > thanks for reading this, > > i would like to create a function that would behave like the print > statement. > for example, > if i were to exectute > print 10 > then > i would get a result. > > if i write my own def called printit, > for example, > def printit(Num): > print Num > > to call my function it using parenthesis like so, > printit(10), would be legal > but the following seems to be illegal > printit 10 > why, oh why, is it illegal and is there a trick to make it legal. > can i call a function without any parenthesis( ). > No. And don't expect this to change. There are many reasons, and for some I can do no better that to quote one Guido van Rossum: """For example, it would render x[y] ambiguous: is it a subscription of list/table x with index/key y, or is it a call of function x with argument [y] (a list containing one element, y)? Also, function calls without arguments would be impossible -- just "f" doesn't call the function f but yields the function object f.""" In other words, Python's syntax is too precise to allow such usages. I believe there are languages in which almost any random string has a meaning but Python isn't one of them :-) regards Steve -- http://www.holdenweb.com/ From attila.pletyak at anemo.com Wed Oct 10 07:49:24 2001 From: attila.pletyak at anemo.com (Attila Pletyak) Date: 10 Oct 2001 04:49:24 -0700 Subject: Newbie: tkinter question Message-ID: Hello, I am using Debian Linux 2.2, I've installed python from the deb packages. I would like to try out the possibilites of tkinter, but the module tkinter seems to be missing from my computer. Python is 1.5.2, and when I start it and type "from Tkinter import * " it says that it cannot find tkinter. I looked on the tkinter home page, it routes me to dev.scriptics.com, but there I cannot really find tkinter. Can anybody help me out on what should I do? TIA, Attila Pletyak From calves at coelce.com.br Wed Oct 31 12:56:57 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Wed, 31 Oct 2001 14:56:57 -0300 Subject: connecting database Message-ID: <29A97D00F387D411AC7900902770E148024B79DC@lcoeexc01.coelce.net> I'm using python under Windows. How can I do it?!I have no idea!!! Carlos Alberto COELCE/DPRON-Departamento de Projetos e Obras Norte Fone: 677- 2228 e-mail: calves at coelce.com.br \|||/ (o o) --ooo0-(_)-0ooo-- -----Original Message----- From: Oleg Broytmann [mailto:phd at phd.pp.ru] Sent: Wednesday, October 31, 2001 1:41 PM To: Alves, Carlos Alberto - Coelce Cc: python-list at python.org Subject: Re: connecting database On Wed, Oct 31, 2001 at 02:37:35PM -0300, Alves, Carlos Alberto - Coelce wrote: > How can I connect to databases?! By installing apropriate DB API driver. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gh_pythonlist at gmx.de Sat Oct 6 04:16:38 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 6 Oct 2001 10:16:38 +0200 Subject: [ANN] pyPgSQLDA test1 Message-ID: <20011006101637.B1040@lilith.hqd-internal> I'm working on a Zope database adapter for pyPgSQL that is currently in the "works-for-me" stage, i. e. hardly tested and underdocumented. I'd be glad if you could help me testing it. It's available at http://www.cs.fhm.edu/~ifw00065/ Various new Windows installers are also available: - egenix-mxBase for Zope 2.4.x - ZpyPgSQLDA test1 + pyPgSQL 1.6 for Zope 2.4.x - ZMySQLDA 2.0.8 + MySQLDB 0.9.0 for Zope 2.4.x Please report any problems that occur with ZpyPgSQLDA or with the installers back to me. If everything works perfectly, I'd also appreciate it if you'd drop me a note. Thanks, Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From afaus at corp.vlex.com Wed Oct 17 11:19:45 2001 From: afaus at corp.vlex.com (Angel Faus) Date: 17 Oct 2001 08:19:45 -0700 Subject: PythonWin ASP performance Message-ID: <7a7a07a.0110170719.7a347008@posting.google.com> Hi to all, I work in a project that has already a significative investment in ASP (vbScript) and COM development. We are already using Python in some parts of the development and we love it. But current Python+ASP development has ocurrend in backend tools that support a moderate level of traffic. We are afraid that using Python instead of vbScript in "key" parts of the site (that support >70% of our traffic, and our total traffic is not small) could be bad for perfomance. So de question is: ?is Python slower than vBscript in ASP? and more important: ?does Python+ASP scale well, or does it generate nasty conditions when used intensively? and finally: ?is it mixing Python and vBscript in the same page slower or more problematic than just using Python? Thanks in advance, -angel From slinkp23 at yahoo.com Fri Oct 26 12:44:49 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Fri, 26 Oct 2001 16:44:49 GMT Subject: Conditional expressions (again) References: <3BD8C52A.53E97472@alcyone.com> <9rbh46$p95$1@thorium.cix.co.uk> Message-ID: On Fri, 26 Oct 2001 16:05:54 GMT, Terry Reedy wrote: >How about (untested) > >order.append( {michael:spam, john:eggs}.get(customer,cheese) ) Works. :) I like it better than that function I posted. -- PW From gerhard.nospam at bigfoot.de Sun Oct 14 15:22:00 2001 From: gerhard.nospam at bigfoot.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 14 Oct 2001 21:22:00 +0200 Subject: Image processing? References: <3BC9D56D.706A9BDF@ix.netcom.com> Message-ID: On Sun, 14 Oct 2001 15:11:57 -0300, Antaeus Feldspar wrote: >I'd like to be able to access image data in some of the common lossless >formats, like BMP and PNG, and if possible also write output in these >formats. Even having one of these formats available should help, since >I can use GIMP for conversion where it's needed. > >Note, I'm not looking for anything really advanced like seeing the image >in real-time as it's manipulated; I just want to be able to >programmatically get data like "the (r,g,b) value of the pixel at >(10,10)" and the like, and as I said, being able to output to this >format would also be nifty. Before I go reinventing the wheel, does >anyone know of existing code for this purpose? The Python Imaging Library is your friend. http://www.pythonware.com/ Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From n8gray at caltech.edu.is.my.e-mail.address.com Tue Oct 2 20:29:46 2001 From: n8gray at caltech.edu.is.my.e-mail.address.com (Nathaniel Gray) Date: Tue, 2 Oct 2001 17:29:46 -0700 Subject: need design suggestions: local namespace problem References: Message-ID: <9pdmmo$gl6@gap.cco.caltech.edu> Jason R. Mastaler wrote: > I was thinking of splitting Defaults.py up into multiple files > (Qmail.py and Sendmail.py), and then using local namespace trickery so > that within the program main I can do things like: > > if qmail: > import Qmail as mta > elif sendmail: > import Sendmail as mta > > sys.exit(mta.ERR_HARD) > > However, the "import module as name" syntax is a Python2-ism, and I'd > still like to support Python-1.5.2 if I can. No problemo: """ if qmail: import Qmail mta = Qmail elif sendmail: import Sendmail mta = Sendmail """ This is almost exactly what "import a as b" is syntactic sugar for. (To be exact you would have to del Qmail and Sendmail) Have fun, -n8 -- Nathaniel Gray California Institute of Technology Computation and Neural Systems -- From quinn at chunder.ugcs.caltech.edu Mon Oct 8 18:06:57 2001 From: quinn at chunder.ugcs.caltech.edu (Quinn Dunkan) Date: 8 Oct 2001 22:06:57 GMT Subject: bound member functions ? References: <9proou$rsh$04$1@news.t-online.com> <9prrfv$vlf$04$1@news.t-online.com> Message-ID: On Mon, 8 Oct 2001 11:28:13 +0200, Achim Domma wrote: > >"Steve Holden" wrote in message >news:gXdw7.3286$Sj2.69338 at atlpnn01.usenetserver.com... >> Yes. The reference to the bound method will keep the object around as long >> as you need it. > >Thanks, I love Python !!! ;-) The method holds a reference to the class. You can see for yourself: >>> class A: ... def m(self): pass ... >>> m = A().m >>> m >>> dir(m) ['__doc__', '__name__', 'im_class', 'im_func', 'im_self'] >>> m.im_class >>> From garth_grimm at hp.com Tue Oct 2 15:56:38 2001 From: garth_grimm at hp.com (Garth Grimm) Date: Tue, 02 Oct 2001 12:56:38 -0700 Subject: http request timeout Message-ID: <3BBA1BF6.2020702@hp.com> Hello, While handling a user web request, I'm issuing an HTTP request to another server and parsing the XML in the response to finish handling the original user's request. I've got the functionality working, but am now trying to do some exception handling to improve the robustness of the interaction. I can handle most failure situations (i.e. failed network connection, invalid "XML" returned, etc.) using try/catch constructs, but the situation I'm currently stuck on is when the remote server accepts the connection, but for some reason (e.g. process hung?) doesn't send a response. This will generate an infinite wait and prevent my code from finishing the response to the originally user. What I'd love to do, is set a time-out on the http connection. But I can't see any obvious way to do this in the httplib module -- no constructor or method seems to take a timeout parameter. Even if I go down to the socket module level (which I'd like to avoid), I still see no built in timeout handling. I've thought about using a watchdog thread approach, but the threading module documentation states that "threads cannot be destroyed, stopped, suspended, resumed, or interrupted". This would seem to me that I could certainly have my user request handling thread finish after the watchdog times out, but the connection thread to the remote server may continue to run. THis would quickly lead to an unacceptable number of threads waiting for responses from the remote server. I would think that dealing with this failure mode would be fairly typical. Have I missed an obvious built-in solution? If there is none, what approaches have others used to best handle this in Python? Garth From aahz at panix.com Wed Oct 10 19:03:58 2001 From: aahz at panix.com (Aahz Maruch) Date: 10 Oct 2001 16:03:58 -0700 Subject: simple threading References: <3BC32938.3080902@herts.ac.uk> Message-ID: <9q2k4u$br8$1@panix2.panix.com> In article <3BC32938.3080902 at herts.ac.uk>, Mark Robinson wrote: > >I am trying run a particularly processor hungry function in a >seperate thread but I can't quite figure out how to return >the arguments from the object now. http://starship.python.net/crew/aahz/ -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista We must not let the evil of a few trample the freedoms of the many. From josegomez at gmx.net Tue Oct 9 15:08:53 2001 From: josegomez at gmx.net (josegomez at gmx.net) Date: Tue, 9 Oct 2001 19:08:53 +0000 (UTC) Subject: GTK under windows References: <3BBD134F.DA1ADD1@csse.monash.edu.au> Message-ID: <9pvi05$lqu$1@hermes.shef.ac.uk> Laurent Tardif wrote: > i've try to use de GTK library with python under windows. I'd like to use this combination as well (I tend to use Linux, but I'd like to make my gtk apps a bit more portable without needing to use wxwindows or somesuch). Have you got any links/references on how to do python _and_ gtk on windows (I obviously know how to do python in windows :D)? Regards Jos? -- Jos? L G?mez Dans PhD student Tel: +44 114 222 5582 Radar & Communications Group FAX; +44 870 132 2990 Department of Electronic Engineering University of Sheffield UK From loewis at informatik.hu-berlin.de Sun Oct 21 09:35:31 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 21 Oct 2001 15:35:31 +0200 Subject: the "-u" argument References: Message-ID: Felix writes: > when i use "python -u" to start the interpreter, every time i hit "ENTER" > the interpreter always produce an error message like below. > > >>> > File "", line 1 > > ^ > SyntaxError: invalid syntax > > but i didn't type any statement (thus there can't be any SyntaxError). > > does anybody know why this happens? My guess is this is because of the CR character that is send as part of the CRLF sequence. Without -u, the C library translates CRLF to LF, which is acceptable; if the CR remains, it is an error. Regards, Martin From Georg.Bisseling at pallas.com Fri Oct 19 10:39:15 2001 From: Georg.Bisseling at pallas.com (Georg Bisseling) Date: Fri, 19 Oct 2001 16:39:15 +0200 Subject: Method returns self? References: Message-ID: <3BD03B13.2225F0AA@pallas.com> > This would avoid the problem entirely, but it's not as interesting to think > about :-) Things that seem interesting at 4:00 am often turn out to be stupid after one did get some sleep... From James_Althoff at i2.com Wed Oct 31 15:20:36 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 31 Oct 2001 12:20:36 -0800 Subject: python development practices? Message-ID: Cliff Wells wrote: >I tend to use this method as well. My feeling is that keeping data >attributes private (by convention) helps keep classes as "black boxes". This >allows the internal implementation of the class to change at will as long as >the get/set methods provide the same interface. This allows things such as >changing a list to a dictionary without fear that this will break some >outside code. Absolutely! The ability to change a class implementation whilst preserving backwards compatibility via the safety net of method access has saved the derriere on numerous occasions. (The very notion of hard-coded access to instance variables strewn about in random pieces of code in a large system just flat-out gives me the willies. For me, the really important thing is actually *to buy into* the idea of encapsulation). Jim From graz at mindless.com Thu Oct 18 08:42:45 2001 From: graz at mindless.com (Graham Ashton) Date: Thu, 18 Oct 2001 12:42:45 GMT Subject: distutils question Message-ID: <97Az7.9780$qq3.1438004@news1.cableinet.net> Hi. I've written a script and supporting package that I'd like people to be able to install with distutils. I've been through the "Distributing Python Modules" documentation and have a setup.py file that works fine with the package. I haven't been able to work out if it's possible to get distutils to install a script into a sensible place though (e.g. /usr/local/bin on UNIX, c:\Program Files\foo\foo.py on Windows). Is it? If not, what do people normally use? Thanks. -- Graham From tjreedy at home.com Tue Oct 2 13:56:16 2001 From: tjreedy at home.com (Terry Reedy) Date: Tue, 02 Oct 2001 17:56:16 GMT Subject: list remove References: Message-ID: <4dnu7.68053$5A3.25451083@news1.rdc2.pa.home.com> > 0 has the section more on lists where it gives the function remove(x). I am > trying to use this function to delete elements out of my list, but it only > deletes every other list. > > >>>foo = [1, 2, 3, 4, 5] > >>>for bar in foo: > ... foo.remove(bar) > > >>>foo > [2, 4] Besides the other answers ... foo [] #bind 'foo' to empty list foo[:] # delete in place To selectively delete multiple items, use filter(). Terry J. Reedy From gleki at gol.ge Tue Oct 23 16:59:01 2001 From: gleki at gol.ge (Giorgi Lekishvili) Date: Tue, 23 Oct 2001 13:59:01 -0700 Subject: unnecessary change References: <3BD5BCDF.B40C1422@gol.ge> <6UbB7.7681$Ub2.261294@atlpnn01.usenetserver.com> Message-ID: <3BD5DA15.903096E8@gol.ge> and the copy.copy() function did not help:((((( Steve Holden wrote: > "Giorgi Lekishvili" wrote in message > news:3BD5BCDF.B40C1422 at gol.ge... > > Hi folks! > > > > My problem is the following: > > I want to save initial data matrix, as e.g., follows > > self.Mdata=Matr > > In the same time I need a matrix, which is used and processed. The > > latter is created as follows > > self.Mactual=self.Mdata > > > > No the problem is, that, when I have finished to use the Mactual matrix, > > self.Mdata is always changed and equals the final Mactual matrix. > > > > What is the systematic solution of the problem? > > > > Thanx in advance, > > Giorgi > > > > PS. I use Numeric module. > > > This is because Python variable bindings are actually references. You > probably need to make a copy of the matric. See if the copy module (and > particularly copy.deepcopy()) will help. > > regards > Steve > -- > http://www.holdenweb.com/ From jdunnett at uoguelph.ca Tue Oct 30 08:26:25 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Tue, 30 Oct 2001 08:26:25 -0500 Subject: python binary search References: <9rkr8q$6e2$0@216.39.145.92> <9rkrp4$ltv$1@testinfo.cs.uoguelph.ca> <3BDE4C95.540DA929@engcorp.com> Message-ID: <3BDEAA81.DE839D17@uoguelph.ca> Peter Hansen wrote: > Jeffrey Dunnett wrote: > > > > A.J. Rossini (rossini at blindglobe.net) wrote: > > : Too bad you aren't designing Phase I vaccine trials; dose typos are a > > : killer, there... :-). > > > That typo was on purpose. However I think we are starting to kill each > > other with the type O puns. > > > > Also to the person who asked if the course I am taking involving Python > > was taught by Prof. Stefan Kremer why do you ask? Do you know him? I > > did have him for my first year C Programming course. > > Friend from high school. I saw him again in the early summer and > asked specifically if U. Moo (**) was still teaching Java to the > newbies, or whether they might consider Python as a much more suitable > language. I believe he didn't recognize the name, but indicated > it sounded interesting and he'd look into it. I just thought it > would be neat if I were responsible for getting it in the door, > but it seems more likely others had already thought of it. > (Although I wonder for how long it's been taught there.) Actually the Moo U is still teaching Java to the newbies partially be demand of the other departments who insist on giving us their first year students for a programming course. Prof. Kremer is one of the people who pushed for Python to be added. Apparently from what I have heard he is a steady preacher of Python. I think it was only in introduced last year or the year before. > > > > BTW - This newsgroup is slighly friendly to people then comp.lang.c > > We may be friendly in a sly way, but we've never been even > slightly slighly friendly. :-) > > ** U. Moo, for those cowering in the other, sillier part of this > thread, is a nickname for the University of Guelph, a highly > agriculturally focused school. (On a side-note, the story is > that to get to Guelph, you "drive west till you smell it, > and north till you step in it." <0.9 wink> ) > I'll have you know that Computer Science is now the largest major on campus at Guelph. Although with the Ontario Vet College the campus can have a distinctive odor. Jeff From edcjones at erols.com Thu Oct 11 00:02:58 2001 From: edcjones at erols.com (Edward C. Jones) Date: Thu, 11 Oct 2001 00:02:58 -0400 Subject: Python questions -> compiler and datatypes etc References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> <01101110395417.11044@ike> <15300.60842.366180.693270@beluga.mojam.com> Message-ID: <3BC519F2.4020808@erols.com> Richard Jones wrote: > On Thursday 11 October 2001 10:54, Skip Montanaro wrote: > >> Richard> ... and as far as I recall there is an ongoing effort right >> Richard> now. I just can't find the reference at the moment. >> >>Try: >> >> http://homepages.ulb.ac.be/~arigo/psyco/ Has Guido seen this? From johnny at debris.2y.net Tue Oct 30 11:21:47 2001 From: johnny at debris.2y.net (Johnny deBris) Date: 30 Oct 2001 08:21:47 -0800 Subject: Using Tkinter's clipboard Message-ID: Hi there, I was wondering how to use the clipboard from Tkinter. I noticed there are some methods for clearing and appending to the clipboard, but none to retreive something from it... Is there no way at all to retreive data from the clipboard using Tkinter? I'm writing a small texteditor that has to work cross-platform, so the Tkinter-way would be a lot easier than using the windows-clipboard lib. If there's no way to do it using Tkinter, though, could you people tell me how to work with the clipboard in X? 'Cause I did not find anything about that either :) Thanx a bunch, Guido Wesdorp, Holland From gerhard.nospam at bigfoot.de Fri Oct 12 08:05:56 2001 From: gerhard.nospam at bigfoot.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 12 Oct 2001 14:05:56 +0200 Subject: J2EE equivalent in Python References: Message-ID: On 12 Oct 2001 11:51:36 +0100, Robin Smith wrote: >I like J2EE but I am also an open source fan. I don't like what I read >about Sun and restricting Java - >http://www.onjava.com/pub/a/onjava/2001/10/10/osjava.html . > >Is there anything similar to J2EE for python? Take the following with a grain of salt, my experiences with J2EE are limited to swearing because of incomprehensible error messages from Persistence Powertier ;-) J2EE is a bunch of APIs thrown together, right? So we can examine the APIs one for one. Servlets/JSP: Python has a gazillion equivalents. There's a page that compares them all, but I don't have the URL atm. Distributed sytems: There are several ORBs. I like omniORBpy, for example. Then there are several SOAP implementations. And easy-to-use Python-only solutions like PyRO. And XML-RPC. JDBC: Python DB-API 2.0. Persistence (EJB): ZODB (included in ZOPE or available standalone). Object-Relational Mapping (JDO): Not available AFAIK. ZOPE probably comes closest to a J2EE server. It has something called ZEO if you need to scale up. If you're adventurous, you can of course mix and match the APIs you like. And btw. there are also several ZOPE-light's: WebWare, SkunkWeb, Aquarium, ... I only tried WebWare and liked it. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From grahamd at dscpl.com.au Mon Oct 8 19:59:27 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 8 Oct 2001 16:59:27 -0700 Subject: SOAP.py and Python 2.1.1 References: Message-ID: Gabriel Ambuehl wrote in message news:... > -----BEGIN PGP SIGNED MESSAGE----- > > Hello Andrew, > > Monday, October 08, 2001, 12:46:22 AM, you wrote: > >> This confuses me cause I thought xml should be available from > >> stock and I've even got expat-1.2 and expat 1.95 installed so > >> what's wrong here? > > IIRC, the pyexpat module frequently doesn't get built > > automatically, even when expat is installed. You'll need to > > manually, build it. > > Ok, so I installed PyXML-0.6.6 by hand. Now pyexpat is no longer > missing, but SOAP.py still doesn't work (not even the card test) > cause > it complains about unsupported UTF-8 encoding: > > :1:36: Unsupported encoding 'UTF-8' > > Am I better off using another SOAP toolkit or XML-RPC? Another SOAP toolkit I am looking at at the moment and which looks quite promising is ZSI from Zolera. The address is: http://www.zolera.com/resources/opensrc/zsi/zsi.html I have found a few issues with it in the way I am trying to use it, but have come up with fixes and am conversing with the author about it. ZSI still has good backing whereas the pywebsvcs code is in slow mode as the people who were developing have changed jobs and don't have as much time to work on it. The pywebsvcs people are happy to take on more maintainers if anyone is offering though. Whether you go SOAP or XML-RPC depends a bit on what you are trying to do. One difference is that with SOAP there is the concept of being able to provide a strict schema defining what requests should look like. This can be an aid to client developers who want to talk to your system. SOAP also has various other features which XML-RPC doesn't, such as named parameters as well as positional parameters, whereas XML-RPC only supports positional parameters. I don't know what type of system you are trying to build, but you might have a look at OSE. I am not suggesting OSE from the point of view of one particular protocol or the other but more so the philosophy of the framework. What OSE lets you do is write systems which can be called using either SOAP or XML-RPC protocols, albeit only with positional parameters for both. Right now OSE is using its own python implementation of XML-RPC and is dependent on the pywebsvcs SOAP.py for SOAP. In the nest release however it has been structured so that it can be configured to use different implementations of XML-RPC and SOAP encoders/decoders depending on what you have. When it ships it will probably be configured to use a C++ implementation of XML-RPC which comes with the package. This will croak if you start passing it CDATA, XML comments, processing instructions etc. If that is a problem, with just one variable setting, you will instead be able to switch to a Python XML parser based implementation which again comes with the package. This of course will run slower. Still not happy, then there are also bindings for using the PythonWare and py-xmlrpc implementations. Similarly with SOAP, there will be bindings for the PythonWare, pywebsvcs SOAP.py and hopefully ZSI implementations. The important bit is that despite which implementation of the protocol you use, your server code stays the same. You can therefore quite happily change from one protocol implementation to another if one implementation causes you problems. If you want, you can even mark up specific services against different URLs using different protocols. Ie., one process could be accessible at the same time using not only SOAP and XML-RPC protocols, but multiple implementations of each at the same time. Some may think this is going a bit overboard, but frankly with the less than optimal interoperability of some SOAP packages at the moment, being able to use multiple implementations at the same time can be a bonus. At least until the implementations become more solid. Anyway, if you find OSE of interest, if you can't get pywebsvcs SOAP.py to work under it, you can still develop services but use XML-RPC. That or even use NET-RPC, yet another XML-RPC like protocol which it supports. Then down the track, you can offer SOAP access when you work that out and not have to change your actual server code. If you want to know more about OSE, have a look at: http://ose.sourceforge.net If you want a sneek preview at slightly more updated version of documentation for next release, have a look at: http://ose.sourceforge.net/python-manual.pdf Note that the latter documentation doesn't talk about the ability to switch protocol implementations yet though. :-) BTW, OSE is released under the QPL. More information on the site. From jblazi at hotmail.com Sun Oct 14 10:39:12 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Sun, 14 Oct 2001 16:39:12 +0200 Subject: How to make a copy? References: <3bc9918a_2@news.newsgroups.com> <87elo6fid8.fsf@lisboa.ifm.uni-kiel.de> Message-ID: <3bc9a389_4@news.newsgroups.com> > import copy > a=copy.deepcopy(b) That does not work. I get many messages and at the end I get "und-deep-copyable object: ". J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From christophertavares at earthlink.net Mon Oct 29 20:28:21 2001 From: christophertavares at earthlink.net (Chris Tavares) Date: Tue, 30 Oct 2001 01:28:21 GMT Subject: detecting and creating directories References: <3BDDA7BC.8CF7C891@mitre.org> <0fjD7.3353$Z_1.574942@newsc.telia.net> Message-ID: "Steve Holden" wrote in message news:jckD7.1013$0l4.51795 at atlpnn01.usenetserver.com... > "Fredrik Lundh" wrote ... > > Steve wrote: > > > > > import os > > > path = "/usr/tmp/newdir" > > > if os.path.exists(path): > > > if not os.path.isdir(path): > > > raise ValueError, "%s exists but is not a directory" % path > > > else: > > > os.mkdir(path) > > > > for ten extra points, explain why this is a lousy way to > > do this. > > Because the effbot is inherently clueful, and has suggested this is not the > best way? > > It would be nice, of course, to ensure that the mkdir() had generated a > writable directory. Or that an existent directory was writable. Those cases > would be handled by the open-for-writing code that created the file, though. > I'm sure you have much more to say than just that... > > asking-for-it-ly y'rs - steve > -- Another problem is, in a multitasking OS, that the directory in question could have been created between the os.path.exists call and the os.mkdir call. It's probably best to just call os.mkdir and catch the exception. -Chris From m98law at ecs.ox.ac.uk Wed Oct 10 10:24:34 2001 From: m98law at ecs.ox.ac.uk (Luke Woodward) Date: Wed, 10 Oct 2001 15:24:34 +0100 Subject: Newbie: tkinter question In-Reply-To: References: Message-ID: On 10 Oct 2001, Attila Pletyak wrote: > I am using Debian Linux 2.2, I've installed python from the deb > packages. I would like to try out the possibilites of tkinter, but the > module tkinter seems to be missing from my computer. Python is 1.5.2, > and when I start it and type "from Tkinter import * " it says that it > cannot find tkinter. It sounds as if Tkinter isn't installed. Try entering the following command when logged in as root: apt-get install python-tk Tkinter seems to be in a separate package, and the above should find and install it. HTH, Luke From dale at riverhall.NOSPAMco.uk Tue Oct 2 09:32:35 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Tue, 02 Oct 2001 14:32:35 +0100 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> Message-ID: "Steve Holden" wrote: >"Dale Strickland-Clark" wrote in message >news:9lajrtcqsojv72nr88c7j6kmdapjo44vc0 at 4ax.com... >> A 'properly' encapsulated business class tends to involve methods and >> attributes. However, managing attribute assignment gets very messy >> with __setattr__ as you need to devise a scheme to distinguish class >> attributes and working instance variables. >> >> Often, externally visible class attributes need to be validated and >> instance variables don't. Or they may get stored elsewhere. >> >> What strategies have people come up with to manage this distinction >> without bogging the code down in excessive checks. >> >> I would really like a way to distinguish between these two without >> having to check dictionaries. >> >Dale: > >I'm not quite sure what problem you are trying to solve here. Are you >suggesting that your code will change some class attributes and some >instance attributes to parameterize the operation of all instances for a >particular context. Maybe I need another cup of coffee ... > >Well, the coffee was a good idea. Your problem is that when you *use* >__setattr__ you need to know whether you are setting a class or an instance >variable, right? And you want to set class attributes from inside methods? > >Perhaps you'd explain what you mean by "proper" encapsulation is a problem >in your particular context. I'm presuming that you are working in a COM >environment, but of course I've been wrong before... > >regards > Steve > >PS: See recent thread on not hiding your email address from spam! I thought this might be difficult to convey. This is typical of the approach I'm currently using: def __setattr__(self, field, value): if self._dbTable.has_key(field): self._dbTable[field].validate(value) self._fields[field] = value self._saved = 0 else: self.__dict__[field] = value I have to distinguish between assignments to 'public' attributes (which will go in my database) and instance variables which are used throughout the class. I need to validate assignments to the database but just let everything else through. But it means that EVERY internal assignment to instance attributes needs to go through this code. I guess what I'm after is a distinction between private and public attrbutes. Does that make it any clearer? -- Dale Strickland-Clark Riverhall Systems Ltd From peter at engcorp.com Sun Oct 28 01:14:09 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Oct 2001 01:14:09 -0400 Subject: Coding exceptions with patter-matching References: <138e4b24.0110271029.2bec171f@posting.google.com> Message-ID: <3BDB9421.73F13DAD@engcorp.com> Martin von Loewis wrote: > > tiago.tresoldi at bol.com.br (Tiago Tresoldi) writes: > > > Now I've found a problem dealing with exceptions in human languages. > > For example, how to code that you have feet instead of foots? > > If your current approach is to start with a word-by-word translation, > I'd say you can give up right now - there is no chance that you'll > ever achieve reasonable translation of natural languages. A cursory examination of their web site suggests they are not quite so naive as all that. In any case perhaps a slightly fresh approach to the problem will lead to inspirations which those more conservative have not yet had... ''' The Traduki meta-language is a collection of lists (remember that Traduki is programmed in Python) that are somewhat modelled on the generative grammars of Noam Chomsky. There is no real translation to another language: we try to interpret and parse the concepts and ideas of a text and then translate this into the user-defined language. Esperanto is used, but only for a word-by-word translation. This is better because Esperanto is a well-known language that many people with different languages and interests speak, so that almost all the words of all languages have a translation .... ''' -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From helm at dnv.com Thu Oct 25 02:10:12 2001 From: helm at dnv.com (Jens Bloch Helmers) Date: 25 Oct 2001 08:10:12 +0200 Subject: Submit jobs to a set of PC's (w2k/nt) Message-ID: As a python newbie I would apreciate any input on relevant modules or programs for solving the following task: Send an input file to a given directory on machine A. Start a program on machine A. (Do not wait for exit) Send an input file to a given directory on machine B. Start a program on machine B. (Do not wait for exit) ... Copy result files from machine A to host machine. Copy result files from machine B to host machine. ... The machines are running win2k/NT and are connected in a local TCP/IP network. Thanks for any input, Jens Helmers From killspam at darwinwars.com Sat Oct 6 05:29:16 2001 From: killspam at darwinwars.com (Andrew Brown) Date: Sat, 06 Oct 2001 09:29:16 GMT Subject: problem controlling MS Word from Python References: <9pkhei0rbe@enews2.newsguy.com> <9plt6r0e3b@enews1.newsguy.com> Message-ID: "Travers Naran" wrote in <9plt6r0e3b at enews1.newsguy.com>: > >Could you post some sample of your code? I have Office 97 on my machine >(with HTML saving extensions). I'd be interested to see if it happens >in the older Office as well. > > > I did post some earlier, and I'm reulctant to clutter the list, but here is the relevant bit again: it is office 97 that I have been using. Some lines have wrapped, but it should be ovious which, and where. I could post the whole lot if you really want, but that seems rude -- and pointless unless you have PyQT. def domydir(self): "Processes all the .doc files in a directory using do_that_thing ()" QApplication.setOverrideCursor(Qt.waitCursor) try: self.o=win32com.client.Dispatch('Word.Application') self.o.Visible=1 except: warning='OLE fuckup! ' + str(sys.exc_type) + str (sys.exc_value) self.btn_dirpick.setText(warning) mypath,myfile=os.path.split(str(self.wombat_txt)) os.chdir(mypath) self.o.ChangeFileOpenDirectory(mypath) # show what we're doing on the button for wombats in os.listdir(os.getcwd()): if string.find(wombats, 'doc')>1: htmlfile=self.htmlext(wombats) self.do_that_thing(wombats,htmlfile) print 'have just processed', htmlfile QApplication.restoreOverrideCursor() And def do_that_thing(self,docfile,htmlfile): '''gets an instance of word, to save the docfile as html.''' try: self.o.Documents.Add(docfile) self.o.ActiveDocument.SaveAs(htmlfile,17) self.o.ActiveDocument.Close() except: warn='DO that Thing! ' + str(sys.exc_type) + str (sys.exc_value) self.btn_dirpick.setText(warn) From chrishbarker at home.net Mon Oct 29 14:05:41 2001 From: chrishbarker at home.net (Chris Barker) Date: Mon, 29 Oct 2001 11:05:41 -0800 Subject: python binary search References: <9rht70.3vvdvgd.1@kserver.org> <3BDD4E50.8BA429E9@uoguelph.ca> <9rjtho$ff9$1@testinfo.cs.uoguelph.ca> Message-ID: <3BDDA885.EECA7D8D@home.net> Jeffrey Dunnett wrote: > : Thanks for coming to my defence but I really MUST check my spelling beter. > > : Jeff > > Alright I will crawl back in the computer lab I came out of and look at > an english dictionary since I incorrently spelled better. Ouch! I was sure you did that on purpose. As someone who is a lousy typist and a lousy speller, I highly recommend an email client with a spell checker...and a little proofreading. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From paul at boddie.net Tue Oct 9 05:18:24 2001 From: paul at boddie.net (Paul Boddie) Date: 9 Oct 2001 02:18:24 -0700 Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> <9pimak$c22$1@tyfon.itea.ntnu.no> <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> <3BBE4E12.16FE036A@earthlink.net> <9pn44q$m1r$1@tyfon.itea.ntnu.no> <3BBF2751.3010309@sneakemail.com> Message-ID: <23891c90.0110090118.7df7917e@posting.google.com> Joshua Macy wrote in message news:<3BBF2751.3010309 at sneakemail.com>... > > OK, I will. Strunk & White is fine, and I use it myself, but the use > of the possessive apostrophe is, and has always been highly contentious. Who are these Strunk and White people anyway? (Serious question - I assume it's an American English style manual people keep referring to, or something, but I can't be bothered to search for it.) They must be rich by now, though. ;-) > According to The Oxford Companion to the English Language: > > "...there appears from the evidence that there was never a golden age > in in which the rules for the use of the possessive apostrophe in > English were clear-cut and known, understood, and followed by most > educated people... [...] This sounds very familiar. I was once so motivated to consult the various authoritative texts on this subject myself, and the most honest ones seemed to admit that the apostrophe is something introduced into the English language as an additional feature - rather like list comprehensions and Python, I suppose ;-) - and that one likely source is French, which doesn't even use the apostrophe to indicate possession. Perhaps some users of English liked some aspects of the ways that French used it and then adapted it later to suit other purposes. Mr Hetland will possibly confirm that once upon a time English looked more similar to his native language in the way it presented possession (just add an "s" and forget about strange symbols), but the apostrophe as possession indicator seems to want to conquer other languages too. > and-if-it's-good-enough-for-Moses-it's-good-enough-for-Tim-Peters--ly Moses is to the Bible what Tim Peters is to Strunk and White (or should it be the other way round?)-ly, Paul From nospam at bigfoot.com Sat Oct 27 17:16:37 2001 From: nospam at bigfoot.com (Gillou) Date: Sat, 27 Oct 2001 23:16:37 +0200 Subject: Converting perl to python available? References: Message-ID: <9rf7s3$9b5$1@norfair.nerim.net> Hmmm, Once I experimented a Basic => C converter ! It worked but the resulting C code was such a mess that nobody was able to understand it. You'll see for the first time perl script easier to maintain/understand than python equivalents ;-) Leave these scrips in perl if they work correctly. "Wayne Ringling" a ?crit dans le message news: mailman.1004150847.23930.python-list at python.org... > > I have a few programs that I would love to convert to python but don't want > to spend the time to recode them completly. Is there a project that is > working on a conversion program yet? I searched Google and python archives > and did really find a answer for this. So I thought I would ask the > experts. > > Wayne > > From fredrik at pythonware.com Wed Oct 31 17:52:12 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Oct 2001 22:52:12 GMT Subject: Is round() broken? References: Message-ID: Joseph Wilhelm wrote: > I'm having some troubles with round() now... either I'm doing it completely > wrong or round() is. round is doing what it's supposed to do. and there's nothing wrong with the way you use it either. read on. > >>> round( 43583.010000000002, 2 ) > 43583.010000000002 on the other hand, >>> print round(43583.010000000000002, 2) 43583.01 looks like the same number might look different, depending on how you print it. confusing? read on. > If I look at the field through pgAdmin, I just see it as "43583.01", > instead of that whole big long decimal. Is it supposed to come out > like this? it depends on what you do to print it. for the full story, read this: http://python.sourceforge.net/devel-docs/tut/node14.html From mmssaalliibb at mmiitt.eedduu Thu Oct 11 23:13:37 2001 From: mmssaalliibb at mmiitt.eedduu (Mike Salib) Date: Thu, 11 Oct 2001 23:13:37 -0400 Subject: Lightweight Languages Workshop, Cambridge MA 11/17/01 Message-ID: <3BC65FE1.3090502@mmiitt.eedduu> Folks, We're going to be holding a workshop on Saturday, November 17 in Cambridge, MA. We being the dynamic languages group at the MIT AI lab. Consider yourselves invited. It should be lots of fun; Jeremy Hylton will be speaking as well as lots of other cool folks (Dan Sugalski of perl6 fame, ESR of, well, ESR fame, etc). Here's the info. If this appeals to you, check out our web site at LL1.mit.edu. LL1 is a workshop where the world's most innovative language implementors from industry and most clever language researchers from academia are coming together to jam for a day. Implementors and researchers will give short presentations followed by lively discussions. Everyone is welcome to attend; the workshop is free, but if you're going to come, you have to register with us first. If you can't make it to sunny Cambridge, Massachusetts for the day, you can still watch on our live webcast. This workshop is hosted by the Dynamic Languages group at the MIT AI Lab. Many of the most widely used languages to emerge in the last five years have come, not from the academic programming language research community, but from industry. Examples include Perl, Python, Ruby, and Rebol. These languages have borrowed heavily from academic research, sporting features such as garbage collection and closures, but they also experiment with many novel ideas, such as first class environments and keyword-free syntax. In the meantime, academic research has made substantial progress in formally addressing issues such as safety, correctness, and also the implementation of seemingly expensive features such as closures and dynamic dispatch. Lightweight languages have proven to be the most effective vector for getting innovative language features into the hands of working programmers. We use the term "lightweight languages" to describe some of the common features of these new languages. The term "lightweight" refers not to actual functionality, but to the idea that these languages are easy to acquire, learn, and use. Examples that would fall into this category include Perl, Python, Ruby, Scheme (and scsh), and Curl. The one day workshop on lightweight languages aims to bring together implementors from the lightweight language community and researchers from academia. The hope is that both communities will find it both enjoyable and enlightening to hear what others are up to. People involved with implementing the next generation of scripting languages might find design and implementation ideas from academia, and programming language researchers can hear about the challenges and successes involved with producing and maintaining popular lightweight languages. The workshop will consist of both prepared presentations and also lively discussions. Participants are invited to give short presentations of their work, including their goals, aesthetics, and issues. Participants will influence what topics we focus on. Some example topics are: interoperability, RMI, macros, closures, types (static vs. dynamic), executable invariants and assertions, and dynamic optimization. Let us know your preferences. Best Regards, Mike Salib (remove the redundant bits in my email address to send mail, or better yet, just visit the website) From msdemlei at tucana.cl.uni-heidelberg.de Fri Oct 19 02:51:59 2001 From: msdemlei at tucana.cl.uni-heidelberg.de (Markus Demleitner) Date: 19 Oct 2001 06:51:59 GMT Subject: Serial port gotcha with win32all Message-ID: <9qoiif$cep$1@news.urz.uni-heidelberg.de> Hi, I'm getting increasingly desperate. All I'm trying to do is attach a little serial gizmo that runs just fine when talked to from a linux box (using some homegrown python software) to a machine plagued by Windows 2000. Realizing that termios doesn't buy me much in win32, I soon ran across uspp which basically acts as a wrapper around the win32all or termios modules on the respective platforms. Under linux, uspp worked quite as well as my own termios-based code (perhaps not too surprisingly). Under win32, however, write()s seem to work but read()s consistently fail with a "incorrect paramater" exception in a call to win32file.ReadFile. Now, clearly the OpenFile succeded, and the handle didn't change between the open and the read, the error is not in the number of bytes to read (passing some weird object there causes a ParameterError, as expected), and in general I've not been able to gain any clue as to what is going on. The win32all sources seem somewhat intimidating, at least for me with no knowledge of the win32 API whatsoever. So -- can anyone give me a hint where to start getting a grip on this one? Thanks, Markus From phr-n2001d at nightsong.com Mon Oct 8 22:01:16 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 08 Oct 2001 19:01:16 -0700 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> Message-ID: <7x1ykd7es3.fsf@ruckus.brouhaha.com> Cliff Wells writes: > The downside of purchasing a commercial library is that you usually > don't get the source code - just object files you can link against. > Now imagine building a huge application that depends on those > libraries. Now imagine the library provider going out of business. > Now picture yourself rewriting an entire application to use a > different library (it happened at our company). It seems that > licensing a GPL'd library has advantages that may make the > negotiation worthwhile. It can be even stickier unless the GPL'd library supplier is completely the sole developer and didn't accept any patches from anyone without getting signed documents from the submitter assigning outright ownership of the patches including for non-GPL'd use. (And some people who have signed such assignments in the past without realizing what they were getting into are now pissed about it). If I submit a patch to a GPL'd program, it's with the understanding that the patch is GPL'd, unless I agree otherwise. If the patch is accepted and patched program later gets distributed under a non-GPL, I'd feel I had a claim against both the developer and his customer. GPL'd programs often include patches from a LOT of people. The original author is on shaky ground if he does a non-GPL version without getting approval from everyone who submitted patches. It's better for closed source developers to avoid GPL'd stuff altogether. People who want to develop closed-source products and charge for them ought to be willing to pay for the libraries and tools they use anyway. From jkring at calbay.com Wed Oct 3 13:54:26 2001 From: jkring at calbay.com (Jim) Date: 3 Oct 2001 10:54:26 -0700 Subject: __getatr__ question Message-ID: <89a9b6ce.0110030954.7ee3043f@posting.google.com> The following code is used to create a class. If I make an instance of the class called "k", then calling k.func1(23) will print "k.func1(23)", and calling k.func2() will print "k.func2()" and return 12. The problem occurs when I nest the functions like this: k.func1(k.func2()). This prints "k.func2()", "k.func2(12)" when I really want it to print "k.func2()", "k.func1(12)". It gets more interesting when I do something like k.func1(k.func2() + k.func3()). This results in a printout of "k.func2()", "k.func3()", "k.func2(12)". What's up with this, and it a bug or a feature of python? It seams like the __getattr__ is not being called/refreshed in the external function if it is also called inside the function. Thanks for any help -Jim ****** Code ******* class klass: def __init__(self, name): self.name = name def __getattr__(self, a): self.string = a return(self.nop) def __repr__(self): return '' def nop(self, a = None): if (a == None): #pass print self.name + '.' + self.string + '()' return 12 else: #pass print self.name + '.' + self.string + '(' + str(a) + ')' From phd at phd.pp.ru Wed Oct 3 07:48:47 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 3 Oct 2001 15:48:47 +0400 Subject: Assignment not the same as defining? In-Reply-To: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com>; from dale@riverhall.NOSPAMco.uk on Wed, Oct 03, 2001 at 12:35:58PM +0100 References: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> Message-ID: <20011003154847.L30721@phd.pp.ru> On Wed, Oct 03, 2001 at 12:35:58PM +0100, Dale Strickland-Clark wrote: > A solution I thought I had to using __setattr__ doesn't seem to work. > > class wibble: > def __init__(self): > > self.__setattr__ = self.set > > def set(self, attr, value): > > > My late bound __setattr__ is never called. > > I've clearly misunderstood something fundamental here. What am I doing > wrong? Python does not have assingment at all. a = b is not assignment in Python - it is binding and rebinding. Reference to b copied into a. Only reference, not an object. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phr-n2001d at nightsong.com Tue Oct 30 20:11:28 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 30 Oct 2001 17:11:28 -0800 Subject: python development practices? References: Message-ID: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Peter Wang writes: > while i feel that Python makes me far more productive as a programmer > for all the projects on which i've worked, i'm inclined to agree that > the lack of data hiding coupled with lack of a standard interface > specification would cause problems in a team. Well, there's cheesy data hiding in the sense that instance variables whose names begin with underscores are difficult to reach from other modules. If by "interfaces" you mean Java-like interfaces, that's a bogus criticism since Python supports multiple base classes, which let you do the same things and then some. I agree with the criticism about the tool environment, and would also have to say the runtime library isn't what I'd call "industrial strength". > how do Python development teams get around these issues? does using > Python in a commercial software team simply require more disciplined > programmers? > are there good references on using Python in a commercial, team > development environment? I don't know about Python, but large systems have been built in Lisp, and there have been some studies too. Lisp's runtime semantics are fairly similar to Python, though the development environments are far more highly evolved. From sholden at holdenweb.com Fri Oct 12 10:10:17 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 12 Oct 2001 10:10:17 -0400 Subject: Using assingment as an operator. References: Message-ID: "Emil S. Hansen" wrote in message news:pan.2001.10.12.15.32.13.366.11244 at berlingske.dk... > In , Steve Holden wrote: > > >> while re.search("[^a-z0-9.]", domainname = raw_input("Please enter > > domainname: ")) != None: > >> print "Error in domainname, please use lovercase letters and > > numbers only." > > You can't. See Frequently Asked Question 6.30 for why. The syntax you > > use is for keyword arguments to functions, another subject entirely. > > I guessed that, but I hoped there was another way to do what I want. But > I'll have a look at the FAQ. Thanks for your time, > Not a problem. I presume the reason you wanted assignment inside an expression was to use the value of domainname later in your program. Python's general philosophy seems to be that a couple of extra lines of code is worth it for the improvement in clarity. You could, of course, define your own function with a side-effect of setting global domainname, but that wouldn't be any shorter, really. There's actually another thread current about assignment and expressions. There have been several wacky suggestions, but my bet would be you might expect Hell to freeze over before we see it in Python. regards Steve -- http://www.holdenweb.com/ From richard at bizarsoftware.com.au Thu Oct 18 19:33:22 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 19 Oct 2001 09:33:22 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: <200110180758.f9I7w4M00794@mbuna.arbhome.com.au> References: <200110180758.f9I7w4M00794@mbuna.arbhome.com.au> Message-ID: <0110190933223E.11044@ike> On Thursday 18 October 2001 17:58, Anthony Baxter wrote: > >>> "Tim Peters" wrote > > > > The bugfix release process is the topic of Aahz's PEP 6, who may have > > believed that titling it "Bug Fix Releases" was enough clue : > > Ah, that cunning "hidden in plain sight" approach. Who'd have thought. > > It still doesn't cover the process of deciding what would go in the > patch release... I know that I'd be happier upgrading to 2.1.2 than > 2.2 in the next couple of months - and given the peasants-are-revolting > sentiment of c.l.py at the moment, I doubt I'm the only one... > > How would this sound as a first cut at a what-goes-in-and-what-stays: > > a) bugfixes. > b) no new modules, no new packages. > c) no new methods on classes, unless they're bugfixes. > d) if the bug fix relies on some 2.2-ism, then it's either rewritten, > or ignored and relnoted This looks like a good list - avoiding the stepwise changes, which have a good chance of introducing new bugs. Richard From loewis at informatik.hu-berlin.de Thu Oct 11 13:29:04 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 11 Oct 2001 19:29:04 +0200 Subject: dtd and xml schema parse References: Message-ID: Rock VZ writes: > What are the pyhton libraries available to parse dtd > and xml schema documents. > Are these releases stable? I recommend to use PyXML for both; see pyxml.sf.net. To parse DTDs, you need to use xmlproc. Not sure what you mean by "parse schema documents". An XML schema is an XML document itself, so any XML parser can parse it (including those provided by PyXML). If you where looking for parsers that parse XML documents that follow a schema: well, still any XML parser will do. If you need schema validationL that is not supported in PyXML, yet. The W3C XSV project has produced a schema-validating parser using Python. Regards, Martin From huaiyu at gauss.almadan.ibm.com Mon Oct 15 19:59:16 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 15 Oct 2001 23:59:16 +0000 (UTC) Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xhet6ot4j.fsf@ruckus.brouhaha.com> <9q5370$3re$1@lancelot.camelot> <9q8vpq$hbh$1@lancelot.camelot> Message-ID: On Sat, 13 Oct 2001 10:59:38 +0200, Alex Martelli wrote: >Your approach is indeed far more general -- I just showed somewhat-clunky >syntax that has the advantage of working right now (and ever since the Dawn >of Python) when one is transliterating code from other languages (I >wouldn't use it in code meant to be idiomatically Pythonic, or Pythonically >idiomatic). However, the ability to have arbitrary statements as part of >an "expression" may be TOO general for comfort -- right now I can rely on >the fact that an expression can never rebind my local variables (and this >for example makes eval usable where exec might not be), the generalization >would take such guarantees away. A much more wary look at the trade-offs >is therefore surely warranted. Agreed generally. A clarification, though: the proposal does not allow statements in expressions; it allows statements _between_ conditional keywords and the corresponding expressions, like while [ ; ] : if [ ; ] : The distinction between expression and statements is not diminished. Huaiyu From michael.korte at materna.de Fri Oct 26 04:29:23 2001 From: michael.korte at materna.de (kutte) Date: Fri, 26 Oct 2001 10:29:23 +0200 Subject: tutorial Message-ID: <9rb6pi$nva$1@penthesilea.materna.de> Hi there ! I?m looking for a python tutorial for beginners. I would like to learn python, but I didn?t found any (good) toutorials ( online or download ). I just have expierience in programming procedual Languages. ( C, Basic and Javascript) So I need a very "calm" tutorial *g* (If you even know one tutorial in german...........I would spread my kisses allovertheworld *G*) THX kutte " Am I ? and If - how much ??? " From slhath at home.com Tue Oct 2 21:33:29 2001 From: slhath at home.com (Scott Hathaway) Date: Wed, 03 Oct 2001 01:33:29 GMT Subject: Network programming in python References: <9pdf61$13c6@r02n01.cac.psu.edu> Message-ID: I use SOAP with Python. It is very easy to implement. Scott "Rajarshi Guha" wrote in message news:9pdf61$13c6 at r02n01.cac.psu.edu... > Hi, > I'm thinking of working on a project which would best be solved in a > client - server manner. Ar ethere any pointers as to how I could/should go > about setting a server program, constructing messages etc etc. > > TIA > -- > ----------------------------------------------------------------- > Rajarshi Guha | email: rajarshi at presidency.com > Dept of Chemistry | web : www.rajarshi.f2s.com > Pennsylvania State University | ph : (814) 863 1222 > ----------------------------------------------------------------- > Build a system that even a fool can use and only a fool will want to use it. From maj64 at hotmail.com Sun Oct 28 22:02:33 2001 From: maj64 at hotmail.com (Mark J) Date: 28 Oct 2001 19:02:33 -0800 Subject: Python 2.2b1 hashable dictionary bug? Message-ID: Since I haven't had a good hit rate at detecting bugs vs. features, I thought I'd post here before filing a bug report at SourceForge. Python 2.2b1 (#1, Oct 19 2001, 23:11:09) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class D(dictionary): pass ... >>> d = {} >>> d2 = D() >>> d[d2] = "dictionary used as key" >>> d {{}: 'dictionary used as key'} >>> d[D()]="now have two keys that look the same" >>> d {{}: 'now have two keys that look the same', {}: 'dictionary used as key'} >>> d2["key"] = "mutable key in d" >>> d {{}: 'now have two keys that look the same', {'key': 'mutable key in d'}: 'dictionary used as key'} >>> d[d] = "plain dictionary not allowed as key" Traceback (most recent call last): File "", line 1, in ? TypeError: unhashable type >>> d2[d2] = "subclassed dictionary allowed though" >>> d2 {{...}: 'subclassed dictionary allowed though', 'key': 'mutable keys'} >>> #whoa: what just happened: {...} ?? Interesting.... So is this a feature or a bug? Thanks, Mark From logiplexsoftware at earthlink.net Tue Oct 2 16:11:19 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 2 Oct 2001 13:11:19 -0700 Subject: Problem with COM and Excel In-Reply-To: <3BBA1BD5.8E833283@vip.fi> References: <3BBA1BD5.8E833283@vip.fi> Message-ID: <01100213111909.02289@logiplex1.logiplex.net> On Tuesday 02 October 2001 12:56, Pekka Niiranen wrote: > How can I run AutoFit to all columns of my Excel sheet from python ? > (manually) and then run: > >>> sht.Columns().AutoFit Wouldn't it be AutoFit() ? -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From logiplexsoftware at earthlink.net Wed Oct 3 15:56:34 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 3 Oct 2001 12:56:34 -0700 Subject: Possible to read/write Excel files in Python? In-Reply-To: References: Message-ID: <01100312563406.03969@logiplex1.logiplex.net> On Wednesday 03 October 2001 12:21, Steven Sartorius wrote: > > The article talks about generic perl modules that work under both Windows > and Linux. Take a look here: > http://www-106.ibm.com/developerworks/linux/library/l-pexcel/ Interesting. Of course it will only work until MS changes the format of xls files again (probably next week). Maybe some enthusiastic perl->python convert will recode it in python for us ;-) -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From superfix at bol.com.br Thu Oct 4 15:33:59 2001 From: superfix at bol.com.br (phill) Date: Thu, 4 Oct 2001 16:33:59 -0300 Subject: How to depure python embebed in Visual C Message-ID: How can I depure a program write in Visual C++ 6.0 using python API? Felippe. __________________________________________________________________________ AcessoBOL, s? R$ 9,90! O menor pre?o do mercado! Assine j?! http://www.bol.com.br/acessobol From sholden at holdenweb.com Fri Oct 12 09:23:20 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 12 Oct 2001 09:23:20 -0400 Subject: Using assingment as an operator. References: Message-ID: "Emil S. Hansen" wrote ... > Hello fellow PP. > > I have a simple question. In a program I have a statement like this: > while re.search("[^a-z0-9.]", domainname = raw_input("Please enter domainname: ")) != None: > print "Error in domainname, please use lovercase letters and numbers only." > > When I run the program I get a > "TypeError: unexpected keyword argument: domainname", > how can I use an assigment as an operator for a function? You can't. See Frequently Asked Question 6.30 for why. The syntax you use is for keyword arguments to functions, another subject entirely. def f(a): return a*a can be called using f(a=123) and you can explicity declare an argument as a keyword argument with a default value. I only mention all this to explain the apprently bizarre error message. regards Steve -- http://www.holdenweb.com/ From pawelczyk at lucent.com Thu Oct 25 07:07:15 2001 From: pawelczyk at lucent.com (Lukasz Pawelczyk) Date: Thu, 25 Oct 2001 13:07:15 +0200 Subject: Modules for Python Message-ID: <3BD7F263.2F3FAEB6@lucent.com> Hello, Could anyone tell me where I can find the modules for Python? Especially, I am looking for any module to read MS Excel files in Python. Thanks, Lukasz From wolf359_ at gmx.net Wed Oct 31 10:12:31 2001 From: wolf359_ at gmx.net (Thomas Weidner) Date: Wed, 31 Oct 2001 16:12:31 +0100 Subject: External python file problem Message-ID: Hi, i want a python program to load another .py file and execute a function in this other file. i compile the other file using the compile function,but how to get the function i want from the resulting code object ? From greg at cosc.canterbury.ac.nz Thu Oct 25 22:15:35 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 26 Oct 2001 15:15:35 +1300 Subject: None References: <3bd5db1e$1@brateggebdc5.br-automation.co.at> <3bd7fa75$1@brateggebdc5.br-automation.co.at> Message-ID: <3BD8C747.3DA9EEEC@cosc.canterbury.ac.nz> Werner Schiendl wrote: > > one rather expects None to be a literal > or constant value like NULL in C Actually, NULL is a preprocessor macro in C, so it's like doing #undef NULL #define NULL 42 which would really confuse someone reading your C program! -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From taw_usenet at yahoo.com Wed Oct 31 13:09:36 2001 From: taw_usenet at yahoo.com (ToddW) Date: 31 Oct 2001 10:09:36 -0800 Subject: Force a DB in shelf? Message-ID: <84a8bdbe.0110311009.5824d80e@posting.google.com> I know you can forcibly use one db over another, but I can't seem to figure out how. Anyone have a clue? From michael at rcp.co.uk Fri Oct 12 03:00:56 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Fri, 12 Oct 2001 07:00:56 +0000 (UTC) Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> Message-ID: Donn Cave wrote in news:9q4it9$tio$1 at nntp6.u.washington.edu: > I sort of regret wasting bandwidth on this purely academic question, > but it's a matter of truly venerable tradition that C's loop is a > bit shy of perfection. The idea as I understand it, is that there > are essentially two control points in a loop, the entry, and the > conditional repeat. C conflates those two in one, because both > entry and the conditional repeat have to be at the "top". Perhaps it's worth recalling at this point the syntax used by Algol68 for a loop. This was really quite pretty and possibly slightly relevant: WHILE statements; expression DO statements OD Of course, in C this needs to be translated to: while(1) { statements; if (!expression) break; statements; } and in Python we have to do exactly the same: while 1: statements: if not expression: break statements It's not pretty, but I'd rather worry about having a conditional expression (off topic; we've already beaten that to death and not quite managed a PEP out of it...) From shalehperry at home.com Sat Oct 27 14:43:56 2001 From: shalehperry at home.com (Sean 'Shaleh' Perry) Date: Sat, 27 Oct 2001 11:43:56 -0700 (PDT) Subject: Coding exceptions with patter-matching In-Reply-To: <138e4b24.0110271029.2bec171f@posting.google.com> Message-ID: > > Now I've found a problem dealing with exceptions in human languages. > For example, how to code > that you have feet instead of foots? It gets worse (=: There is no plural form of some nouns in English. Take fish and fruit for instance. I am sure other languages have similar oddities. I suspect you will need to have both case by case items and pattern items. Would it simplify things if you some how split the exception list? From emile at fenx.com Sat Oct 20 21:17:23 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 20 Oct 2001 18:17:23 -0700 Subject: [Q] How to get global namespace of __main__? References: <9qt5cj$bef$1@news2.isis.unc.edu> Message-ID: <9qt801$qdf3k$1@ID-11957.news.dfncis.de> I think this does it: #getglobals.py def gg(): import sys return sys.modules['__main__'].__dict__ Then, interactively: >>> reload(getglobals) >>> gg = getglobals.gg() >>> gg {'gg': {...}, '__doc__': None, 'getglobals': , '__name__': '__main__', '__builtins__': , 'sys': } >>> globals() {'gg': {...}, '__doc__': None, 'getglobals': , '__name__': '__main__', '__builtins__': , 'sys': } >>> HTH, -- Emile van Sebille emile at fenx.com --------- "Daehyok Shin" wrote in message news:9qt5cj$bef$1 at news2.isis.unc.edu... > For a specialized task of my own, I have to get a global namespace of python > interactive environment from a function in a module. The following example > simplified it. > How can I solve the problem? Thanks in advance. > > Inside python interactive environment: > >from mymod import put > >x = globals() > >put() > > Inside mymod module: > def put(): > y = ???? #y should be the same as x. > > -- > Daehyok Shin (Peter) > > > From dale at riverhall.NOTHANKS.co.uk Fri Oct 19 06:51:07 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Fri, 19 Oct 2001 11:51:07 +0100 Subject: Traceback oddity Message-ID: This may not be a Traceback issue at all but somewhere in the depths, Python's handling of file paths is strangely inconsistent. Here's my traceback report (wrapped, unfortunately): Traceback (most recent call last): File "S:\JOBS\Gibson\Library Manager\librarymanager\cli\lb.py", line 31, in main handler.execute() File "S:\JOBS\Gibson\Library Manager\librarymanager\cli\lbCLICommand.py", line 52, in execute func() File "S:\JOBS\Gibson\Library Manager\librarymanager\cli\lbCLIStory.py", line 41, in doNew xmlStory = lbXMLStory.lbXMLStory(self.work, lbs.lbStory(self.work)) File "s:\jobs\gibson\library manager\librarymanager\lbStory.py", line 27, in __init__ lbdbPubBase.__init__(self, self.work, ID, seq, Parent=Parent) File "s:\jobs\gibson\library manager\librarymanager\lbdbTable.py", line 77, in __getattr__ return self._fields[field] File "s:\jobs\gibson\library manager\librarymanager\lbdbTable.py", line 75, in __getattr__ assert field != '_fields' The observant will have noticed that the first few filepaths are in mixed case whereas the last are all lower case. I only noticed because I'm trying to post-process this report. Any ideas why? Cheers. -- Dale Strickland-Clark Riverhall Systems Ltd From tim.leeuwvander at nl.unisys.com Wed Oct 31 07:04:12 2001 From: tim.leeuwvander at nl.unisys.com (Leeuw van der, Tim) Date: Wed, 31 Oct 2001 06:04:12 -0600 Subject: Python-equivalent of PHP addslashes/stripslashes functions? Message-ID: Hello, I'd like to know if there's a Python-alternative to the very convenient PHP functions addslashes / stripslashes which add cq remove backslashes to things like ', " characters, so that values from HTML forms can be safely passed around to other programs, used in SQL statements, etc. Any pointers? Thanks in advance, --Tim From Peter.Gilbert at uwe.ac.uk Tue Oct 23 05:29:54 2001 From: Peter.Gilbert at uwe.ac.uk (Pete Gilbert) Date: Tue, 23 Oct 2001 09:29:54 GMT Subject: Python for ipaq References: Message-ID: Hi There is a release here: http://public.murkworks.com/PublicCMF/Members/bkc/Python-iPaQ/FrontPage Cant help you with the second bit though... "Karol Makowski" wrote in message news:slrn9taa4e.3ub.spaceman at shield.bsdirc.net... > hello > > Do you know where can i find python for compaq ipaq pocket pc running > Windows CE? > > And second question: > i need a _simple_ ftp client written in python (using ftplib) > which will store some files on server and will get other files from > server. I need to put it in my C program via the system(); > > Thanks! > > -- > Karol Makowski, System Administrator > URL: http://spaceman.bsdzine.org > e-mail: spaceman at bsdzine.org From phr-n2001d at nightsong.com Tue Oct 9 18:31:22 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 15:31:22 -0700 Subject: Excellent Python/VC ++ Contracting Opportunity! References: <913930fb.0110091244.50e51f53@posting.google.com> Message-ID: <7xlmikjvid.fsf@ruckus.brouhaha.com> martime at kellyservices.com (Maria Martino) writes: > My name is Maria Martino and I am a recruiter for Kelly Services. I > have a contracting opportunity for a Python/VC++ programmer. All > interested and qualified candidates should send their resume to: > martime at kellyservices.com It's nice for you to have posted that the first time, but this is about the 4th time in the past couple days. Enough?! From tim.one at home.com Sat Oct 20 15:54:43 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 20 Oct 2001 15:54:43 -0400 Subject: Which python libraries are thread-safe? In-Reply-To: <9qq04v$ie5$1@nntp2-cm.news.eni.net> Message-ID: [Stuart D. Gathman] > While python threads are simple and effective, how am I to know which > library functions are thread safe and/or reentrant? Experience <0.6 wink>. The general rule-- which certainly has exceptions --is that a library is threadsafe unless it explicitly says it's not. For example, random.py is not threadsafe and says so. People keen on threads are also especially urged to use the most recent release of Python, as thread bugs across platforms can be exceedingly subtle and sometimes a bug goes undetected for years. > Do I have to carefully examine the source for each one, and wrap it > in a lock if I am not convinced it is safe? If you want to be certain of being safe, yes. > Shouldn't this be a required part of the docs for any library module? Sure, and if you're volunteering to submit doc patches, great; else it's just another thing everyone is in favor of but not important enough to any individual to make it to the top of their priority queue. If you bump into a problem, submit a bug report and/or patch to SourceForge; if everyone would do just that much, the problem would have solved itself a long time ago. > A lot of modules have global state which is obviously a problem, but > sometimes it is not clear. Does tempfile work reliably with threads? It was intended to, and there are no known tempfile thread issues in the current tempfile.py. The last thread bug in tempfile was found by Guido and fixed by me on January 13; it was specific to Linux (or any OS that figures it's a good idea for threads to have a process id different from the process that spawned them). From mike at unicorn-fs.com Mon Oct 22 09:33:55 2001 From: mike at unicorn-fs.com (Mike Peat) Date: Mon, 22 Oct 2001 14:33:55 +0100 Subject: Writing to SdtErr Message-ID: <1003757605.11708.0.nnrp-14.d4f0f8ae@news.demon.co.uk> Can anyone tell me how to: 1) Turn of the Python "Traceback" output, or make it less verbose? 2) Write (print) to the StdErr channel instead of StdOut? Mike Peat From pzw1 at cor-no-spam-nell.edu Tue Oct 30 19:45:08 2001 From: pzw1 at cor-no-spam-nell.edu (Peter Wang) Date: Wed, 31 Oct 2001 00:45:08 GMT Subject: python development practices? Message-ID: are there good references on using Python in a commercial, team development environment? i have been advocating and slowly convincing various people in my company to use Python. i've successfully used it to write a few tools and an application. however, the general perception is that it is a good scripting language and possibly acceptable for single-person development use, but it doesn't afford use in a large-scale software team. the lack of data hiding, the lack of data coverage tools (pre-run-time linting), and the lack of interfaces and strong types are the typical turn-offs, in addition to the minor but omnipresent tab indentation issue. :-) while i feel that Python makes me far more productive as a programmer for all the projects on which i've worked, i'm inclined to agree that the lack of data hiding coupled with lack of a standard interface specification would cause problems in a team. how do Python development teams get around these issues? does using Python in a commercial software team simply require more disciplined programmers? i'm eager to hear everyone's thoughts... -peter From jeff at ccvcorp.com Tue Oct 16 20:10:47 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 16 Oct 2001 17:10:47 -0700 Subject: Troubles with global variables References: <87r8s4vmgy.fsf@toadmail.com> <87elo6cd4w.fsf@lisboa.ifm.uni-kiel.de> <87pu7op8p2.fsf@toadmail.com> Message-ID: <3BCCCC86.55A5C7F7@ccvcorp.com> Jeremy Whetzel wrote: > enc = 'gogo' > br = '128' > > eo = [['E',') Encoder: ','chooseenc()',enc], > ['B',') Bitrate: ','choosebr()',br]] > > def menumake(menu): > global enc,br > os.system('clear') > for x in menu: > print x[0] + x[1] + x[3] As someone else already noted, here you're printing constant strings. You're changing enc and br, but not eo/menu. > for y in menu: > if choice == y[0]: > exec y[2] Instead of saving the name of your function as a string, and then exec'ing that string, it would be easier (and safer) to save a reference to the function and call it directly. In other words: eo = [['E', 'Encoder', chooseenc, enc], ['B', 'Bitrate', choosebr, br]] def menumake(menu): .... for item in menu: if choice == item[0]: item[2]() I'd also recommend that, instead of using a list of lists for this, that you use dictionaries, with the option character as the key and a tuple of (option, description, value) as the values. For instance..... menudict = { 'E' : ('E', 'Encoder', 'gogo' ), 'B' : ('B', 'Bitrate', '128' ), 'Q' : ('Q', 'Quit', '' ) } def showmenu(menu): while 1: #use a loop, rather than recursively calling itself os.system('clear') for item in menu.values(): #iterate over the contents of the dictionary print " %s ) %15s %s" % item # using string formatting for the display print choice = string.upper(raw_input('Enter Choice: ')) print if choice == 'Q': break elif menu.has_key(choice): prompt = 'Enter the new %s: ' % menu[choice][1] menu[choice][2] = raw_input(prompt) else: print "That is not a valid option." if __name__ == '__main__': showmenu(menudict) ------------------ A few notes about this. Instead of having menumake call itself recursively, as you've done, I've made it run in an infinite loop (until told to quit). Recursion will eventually run into stack-depth limits and such--it's useful when you're subdividing a problem into smaller chunks, but when you're repeating the same thing, a loop is usually a better bet. Note that I never used any global statement, and that my function never actually references the global name menudict. Since dictionaries are mutable objects, I can access the same dictionary through any name that's bound to it. The act of passing the dictionary as a function parameter binds a new name (menu) to it, and I use that to modify the object. This is a bit different than assigning a new value to a name, as you were trying to do in your code. I've also used tuples as the values in the dictionary, to allow easy string formatting for the printout. The only reason to include the option key again in the tuple, is to simplify that formatting. I could have left that out, and had the printout loop instead be: for key, value in menu.items(): print " %s ) %15s %s" % (key, value[0], value[1]) but the way I did it above seems more aesthetically pleasing to me. I've also done away with the helper functions chooseenc() and choosebr() entirely. Switching to using a dictionary to store our data makes changing things simple enough that these helper functions are not necessary. However, if you were doing something more complicated than just changing a single quantity in your menu item, it would be easy enough to have the dictionary value also store a function reference, and to call that reference as I demonstrated near the top of this post. I hope that this example will help you to see some of the possibilities of Python, and give you an idea of how to do things in a slightly more Pythonic (imho) way. :) Jeff Shannon Technician/Programmer Credit International From gward at python.net Thu Oct 18 18:01:57 2001 From: gward at python.net (Greg Ward) Date: Thu, 18 Oct 2001 22:01:57 GMT Subject: Q: standard makefile for distutils package? References: <9qj7a8$ncs$1@news.netvision.net.il> Message-ID: In article <9qj7a8$ncs$1 at news.netvision.net.il>, Miki Tebeka wrote: > Hello All, > > Is there a standard makefile to ship with a distutils created package > (./setup.py sdist) No. "make" was deemed unportable at the Distutils design/planning meeting at IPC7. > all: > @echo Please specify one of the following: > @python setup.py --help-commands | head -18 | tail -17 Umm, what if someone adds a command to the Distutils? This is *really* fragile. If you're determined to use such a kludge, why not python setup.py --help-commands | sed '/^ *$/ q' to quit after the blank line? Anyways, the idea of distributing a Makefile is just plain bogus. People should get used to python setup.py install It's not *that* hard. Greg -- Greg Ward gward at python.net http://starship.python.net/~gward/ From wayne at tbnets.com Tue Oct 30 07:53:48 2001 From: wayne at tbnets.com (Wayne Ringling) Date: Tue, 30 Oct 2001 07:53:48 -0500 Subject: File upload in python module? Message-ID: I am working on a web project that needs a way to upload a gif or jpg (or any file I guess) to a web server via the web interface. I have seen them in perl and java. I am trying to use all python. Is there a python module or script already done to handle this? I looked thru the module list at python.org but didn't see anything that looked like it would handle it. Maybe I missed it. Any pointers or ideas. Thanks Wayne From phr-n2001d at nightsong.com Thu Oct 11 15:48:28 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 11 Oct 2001 12:48:28 -0700 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> Message-ID: <7xhet6ot4j.fsf@ruckus.brouhaha.com> slinkp23 at yahoo.com (Paul Winkler) writes: > That's not a very compelling example anymore. Presumably you don't > want to do "for line in file.readlines()" because of the memory > implications of slurping the whole file? Well, as of python 2.1 we can > get one line at a time like this: > > for line in file.xreadlines(): > ... What if you want to read until you get to a delimiter? while (line := readline()) != 'end': ... From missive at frontiernet.net Thu Oct 25 19:16:16 2001 From: missive at frontiernet.net (Lee Harr) Date: Thu, 25 Oct 2001 23:16:16 -0000 Subject: error starting ZOPE References: <9ra2vq$sifvp$1@ID-22517.news.dfncis.de> Message-ID: On Fri, 26 Oct 2001 00:16:29 +0200, Daniel T. Bender wrote: > hi folks! > > i downloaded the Zope-2.4.2-src, unpacked it and build all the stuff via > "python wo_pcgi.py" > everything is compiled etc, but when i try to run the ./start script i > always get: > > PANIC(300) z2 Startup exception > Traceback (innermost last): > File /root/Zope-2.4.2-src/z2.py, line 757, in ? > IOError: [Errno 13] Permission denied: '/root/Zope-2.4.2-src/var/Z2.pid' > Seems like an odd place to have your Zope installed, but... what user is running the server? what are the permissions/ownership of the var directory? From tim.one at home.com Thu Oct 25 23:55:20 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 25 Oct 2001 23:55:20 -0400 Subject: 2.2, iterators, list comprehensions, get/set, & win32all In-Reply-To: <9ralkq$rdc$1@ins22.netins.net> Message-ID: [Mike Dean] > I'm wanting to do some experimenting with Python 2.2, and I have a > couple of questions.... > > First, do list comprehensions use the new iterator/generator protocol in > their for loop, or do they use the old method of sequence iteration? All 2.2 for-loops (whether or not in list comprehensions) use the 2.2 iterator protocol; this is 100% backward-compatible with 2.1's __getitem__ protocol. > Also, it seems like I remember seeing something about > __get_spam__/__set_spam__ (or something like that) magic methods in > Python 2.2 - am I correct that such animals exist, and if so, where are > they documented (specifically in the 2.2b1 manual)? Lots of the new stuff isn't even mentioned in the docs yet. Per-attribute getter/setter/deleters are described in Guido's tutorial, though: http://www.python.org/2.2/descrintro.html Look for "property". leaving-the-activestate-questions-to-activestate-ly y'rs - tim From rcena at epcor.ca Wed Oct 24 15:56:18 2001 From: rcena at epcor.ca (Resty Cena) Date: 24 Oct 2001 12:56:18 -0700 Subject: Curl-ing, anyone? Message-ID: <458b194a.0110241156.795e9618@posting.google.com> Is Curl (www.curl.com) a threat to Python (and Ruby, and Perl)? From markus at schabi.de Mon Oct 1 04:44:14 2001 From: markus at schabi.de (Markus Schaber) Date: Mon, 1 Oct 2001 10:44:14 +0200 Subject: sameness/identity References: Message-ID: <1584523.dEvYhyI6sB@lunix.schabi.de> Hi, chajadan schrub: > I've been watching this thread, and I'm a little confused as to the > momentum. > > As I see it, there are only two qualities of 'sameness': equality and > identity. > > 1 + 2 = 3 > > 1 plus 2 equals 3 > 1 plus 2 is not 3 > > Equals just means holds the same value. But nothing can be something > else. Just equal to it. > > If you say 3 is 3, in the sense that there is only one 3 in existance, > then you are right. > > If you add a level of abstraction, and say x = 3 and y = 3, now is > that 3 and the other 3 the same? Yes. But x and y are different names. Just to confuse you some more: >>> a = 3 >>> b = 3 >>> a is b 1 >>> a = 10000 >>> b = 10000 >>> a is b 0 Identity of python numbers is an implementation detail. For most uses (concerning numbers), I would recommend to use ==. markus -- "The strength of the Constitution lies entirely in the determination of each citizen to defend it. Only if every single citizen feels duty bound to do his share in this defense are the constitutional rights secure." -- Albert Einstein From mwh at python.net Thu Oct 18 08:15:52 2001 From: mwh at python.net (Michael Hudson) Date: Thu, 18 Oct 2001 12:15:52 GMT Subject: install packages to home dir? References: Message-ID: ozonehole2k at yahoo.com (Ozone Hole near South Pole) writes: [...] > However, when I go back to university, problem arises... Being low in > the pecking order, our sysadmin does not respond well to our request > for package install. As we do not have write access to > python2.0/site-packages, I can only copy all the files in the external > packages into my own work directory... $PYTHONPATH? (man python, or python -h) HTH, M. -- MGM will not get your whites whiter or your colors brighter. It will, however, sit there and look spiffy while sucking down a major honking wad of RAM. -- http://www.xiph.org/mgm/ From dcinege at psychosis.com Sat Oct 6 19:22:27 2001 From: dcinege at psychosis.com (Dave Cinege) Date: Sat, 6 Oct 2001 19:22:27 -0400 Subject: How could i slim Python for embedded ? In-Reply-To: <3bbf6f3e$0$3649$626a54ce@news.free.fr> References: <3bbf6f3e$0$3649$626a54ce@news.free.fr> Message-ID: On Saturday 06 October 2001 16:48, dag4004 wrote: > Hello, > > I want to use Python for an embedded computer so don't Diesel Dave's super secret small python recipe: Do not compile debug info (remove -g) Compile -static to eliminate any library requirments 'strip' the binary Use UPX executable compressor (search sourceforge) This will get you ~350K self contained python. Move .pyc modules as needed. You're on your own for .so modules. (Maybe they can be compiled in static??) If you need less then this you have your work cut out for you and will have many compatibility hurdles to deal with. Dave -- The time is now 22:19 (Totalitarian) - http://www.ccops.org/clock.html From grante at visi.com Wed Oct 3 14:28:27 2001 From: grante at visi.com (Grant Edwards) Date: Wed, 03 Oct 2001 18:28:27 GMT Subject: "self" vs other names References: Message-ID: In article , Cliff Wells wrote: >> >> What would the world have been like if CP/M had won over (PC|MS)-DOS? >> > >> > Not that much different; AFAIK MS-DOS was based on some of the >> > principles of CP/M (8.3 filename, etc.). Lack of significant techincal differences aside, one could hope that Gary Kildall and company would have been a little bit more innovative and law-abiding that the Bill Gates et al. >> PC-DOS was an out-and-out copy of CP/M. The layout of FCBs was >> the same, the methods to call BIOS were the same, the layout of >> executable file headers was the same... > > Except, as I recall, there was already a multiuser version of > CP/M (MP/M) when DOS arrived (imagine running up to 8 users on > a single 8080/Z80! Yup. MP/M had been around for several years before PC-DOS came out. PC-DOS (and Windows for that matter) lacks multi-user support to this day. There's something to be proud of: start out 3 years behind the competition and sit in the same damned place for the next 20 years. > Oh the possibilities...), so maybe the "DR-Windows" of today > would have some real multiuser capabilities instead of having > to have them added as a third-party package. -- Grant Edwards grante Yow! We have DIFFERENT at amounts of HAIR -- visi.com From James_Althoff at i2.com Tue Oct 30 12:54:41 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Tue, 30 Oct 2001 09:54:41 -0800 Subject: Unpacking extension (Re: A small inconsistency in syntax?) Message-ID: Greg Ewing wrote: >What if, instead of just the special built-in constructors >() and [], you were allowed *any* constructor on the LHS? > >Consider: > > class Pair: > def __init__(self, x, y): > self.x = x > self.y = y > def __unpack__(self): > return x, y > > p = Pair(17, 42) > Pair(a, b) = p > >which should result in a == 17, b == 42. > >More precisely, when the LHS is of the form > > (pattern, ...) > >the RHS is checked to ensure it is an instance of the >LHS class (raising an exception otherwise), and its >__unpack__ method is called to produce a sequence which >is then unpacked into the argument patterns. Did you mean def __unpack__(self): return self.x, self.y Otherwise, what are the x and y referring to? And is Pair(a,b) on the LHS any *callable*? Or must the object Pair be a type object or class object only? Jim From emile at fenx.com Wed Oct 24 17:03:08 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 24 Oct 2001 14:03:08 -0700 Subject: HTML Parser References: Message-ID: <9r7bic$roes8$1@ID-11957.news.dfncis.de> You'll want to sub-class htmllib.HTMLParser -- Emile van Sebille emile at fenx.com --------- "Lucio Torre" wrote in message news:mailman.1003950809.16544.python-list at python.org... > Hi, > > Does anyone know of an HTML parser in python? > > I want to do my very simple site contructor script. And i need something > like, "from this file, give me the body, or the title". > > Thanks. > > Lucio. > > From warkid at storm.ru Thu Oct 11 04:03:27 2001 From: warkid at storm.ru ( Kerim Borchaev ( WarKiD ) ) Date: Thu, 11 Oct 2001 12:03:27 +0400 Subject: Profiling PyOpenGL Message-ID: <10502.011011@storm.ru> Hello python-list, why can't I profile PyOpenGL application using profile module? #prof.py##################################### from OpenGL.GL import * from OpenGL.GLUT import * def display(*args):pass import sys glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutInitWindowSize(200, 200) glutCreateWindow('Test') glutDisplayFunc(display) glutMainLoop() ############################################# I run it from command line like this : python C:\Python21\Lib\profile.py prof.py but it prints nothing unless I remove glutMainLoop call. Best regards, Kerim mailto:warkid at storm.ru From greg at cosc.canterbury.ac.nz Wed Oct 17 20:47:29 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 18 Oct 2001 13:47:29 +1300 Subject: Conditional Expressions don't solve the problem References: Message-ID: <3BCE26A1.727D3022@cosc.canterbury.ac.nz> Kevin D wrote: > > while ; : > Two drawbacks: * The condition is written before the assigment, but tested after it. * The statement part is restricted to a single statement which must be an assignment. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From loewis at informatik.hu-berlin.de Sat Oct 27 10:49:54 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 27 Oct 2001 16:49:54 +0200 Subject: xml.dom.minidom entity reference translation References: Message-ID: Dale Strickland-Clark writes: > The XML parser in this module appears to be a bit heavy on spaces > around the entity references: < & > etc. > > It is removing all of them leaving the translated characters next to > the first non-blank on either side. I've never heard of such a behaviour, and cannot reproduce it. Can you show some example that demonstrates the behaviour? > abc def > xyz > > gives: > > abc def>xyz On it's own, the XML parser doens't display any text. It can't be to_xml, either, since that would have produced .... So how did you get that output? Regards, Martin From skip at pobox.com Sun Oct 21 16:42:42 2001 From: skip at pobox.com (Skip Montanaro) Date: Sun, 21 Oct 2001 15:42:42 -0500 Subject: Oops: difference in operation of string.join and ''.join In-Reply-To: <20011021200323.BJAK12720.mta01@mjolner> References: <20011021200323.BJAK12720.mta01@mjolner> Message-ID: <15315.13122.666869.55766@beluga.mojam.com> >>> ''.join([x+y for x, y in zip('test', 'dust')]) 'tdeusstt' >>> import string >>> string.join([x+y for x, y in zip('test', 'dust')]) 'td eu ss tt' John> What is this? The default separator for string.join is a single space. Use string.join([x+y for x, y in zip('test', 'dust')], '') instead. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From jim.correia at pobox.com Fri Oct 19 21:04:43 2001 From: jim.correia at pobox.com (Jim Correia) Date: Sat, 20 Oct 2001 01:04:43 GMT Subject: Dictionary from list? References: <3BD06B08.972910A5@alcyone.com> Message-ID: In article <3BD06B08.972910A5 at alcyone.com>, Erik Max Francis wrote: > In particular, what this is really revealing is that a Perl associative > array is really represented as a list, with each successive pair > representing a key and a value. (When writing list and associative > array literals, you see the same thing.) It reveals no such thing. What it reveals is that there is a magic coercion that happens at assign time. From aotto at t-online.de Mon Oct 8 02:13:17 2001 From: aotto at t-online.de (Andreas Otto) Date: Mon, 8 Oct 2001 08:13:17 +0200 Subject: SPAM (Re: ANNOUNCE: "Compiler") References: <7xitdr4ccv.fsf@ruckus.brouhaha.com> Message-ID: Fran?ois Pinard wrote: > [Paul Rubin] > > > This is a commercial closed-source program that has nothing to do with > > Python. > > The guy once lobbied Python users to raise funds for a Python compiler of > his own, to be the eight wonder of this world. He visits us once in a > while. > Hi, once a while i post the current state of the Tcl based compiler just to speed up competition (e.g. i hope phyton will catch up) -- ================================================================ (C) Compiler-Factory Phone: ++49-(0)8152-399540 Dipl.-Ing Andreas Otto mailto:info at compiler-factory.com Business Solutions http://www.compiler-factory.com Ulmenstrasse 3 => "Compiler", FastWeb, OpMenu D-34289 Zierenberg => C, C++, Tcl, HTML, database, ================================================================= From chalain42 at hotmail.com Tue Oct 16 21:27:42 2001 From: chalain42 at hotmail.com (David Brady) Date: Wed, 17 Oct 2001 01:27:42 +0000 Subject: PyArg_Parse vs PyArg_ParseTuple Message-ID: Hello, I'm new to Python, and I've searched the archives for more info but can't seem to find the info I need. I am having trouble using PyArg_ParseTuple(). Here is the python code I'm embedding: # TestModule.py def NumberFunction(x): return x+1 As you see, it's not too complex. :-) This is just a proof of concept I'm working on to prove it can be done. Here is the code I'm trying to embed it in. Note: this is C++, does that make a difference in this case? // TestEmbed.cpp #include #include void main(void) { long val = 7; PyObject *pmod, *pfunc, *pargs, *pstr; PyInitialize(); printf( "Processing data: %ld\n", val ); pmod = PyImport_ImportModule( "TestModule" ); pfunc = PyObject_GetAttrString( pmod, "NumberFunction" ); pargs = Py_BuildValue( "(l)", val ); pstr = PyEval_CallObject( pfunc, pargs ); // *** This code works *** PyArg_Parse( pstr, "l", &val ); // *** This code does NOT work *** //PyArg_ParseTuple( pstr, "l", &val ); printf( "Val returned was %d\n", val ); } If I use the ParseTuple version, the code appears to run fine, but val is unchanged. I've tried using "(l)" as the string but I'm grasping at straws here. I read in the documentatian that PyArg_Parse() is deprecated, so I would like to get this working correctly. Thank you! Oh, this is Python 2.1.1 on Windows 2000. (Not ActivePython.) -David _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp From GeorgLohrer at gmx.de Tue Oct 16 05:24:45 2001 From: GeorgLohrer at gmx.de (Georg Lohrer) Date: Tue, 16 Oct 2001 11:24:45 +0200 Subject: How to handle sys.path in bigger projects? References: <226dstkol613p95ampm7libas5tp6t0a3b@4ax.com> <56jdstkoro0ddkq3eead1fuoe3m20ilikf@4ax.com> Message-ID: <7sunstg0r63rtcddbidfg38taptm61gdc3@4ax.com> On 15 Oct 2001 16:17:12 +0200, Martin von Loewis wrote: Martin, thanks for your advices. Foremost the projects (lines-of-code produced) expand, design-errors and misunderstandings take place and will be recognized. But, meanwhile I feel 'at-home' with Python. Nice to use, 'implement-debug-check' cycle is very fast, so my application will be ready in-time and, most important, could be understood by everyone else without having sophisticated experiences. Ciao, Georg From paul at boddie.net Mon Oct 15 10:40:57 2001 From: paul at boddie.net (Paul Boddie) Date: 15 Oct 2001 07:40:57 -0700 Subject: J2EE equivalent in Python References: <23891c90.0110150233.3561ca32@posting.google.com> Message-ID: <23891c90.0110150640.87ddace@posting.google.com> Oleg Broytmann wrote in message news:... > > http://www.infector.com/Paul/, and the page you mentioned is on > http://www.infector.com/Paul/Python/web_modules.html I've responded to you privately, Oleg, but the URLs you specify are valid, if not exactly the preferred public URLs of the pages in question. The http://www.paul.boddie.net thing is a vain attempt to preserve a lasting public URL on my part, but thanks must also go to the people at Infector for giving me space for the pages themselves... From mikael at isy.liu.se Wed Oct 17 02:10:21 2001 From: mikael at isy.liu.se (Mikael Olofsson) Date: Wed, 17 Oct 2001 08:10:21 +0200 (MET DST) Subject: Curious assignment behaviour In-Reply-To: <3bcc75d8.1903824318@news> Message-ID: On Wed, 10 Oct 2001 14:54:29 -0700, "John Roth" wrote: > >In mathematics, "=" is an assertion that two expressions have the same > >value over the applicable portion of the domain. Pure mathematics > >doesn't have an equivalent of assignment. On 16-Oct-2001 David C. Ullrich wrote: > In fact lots of people do use := to distinguish assignment > from comparison all the time in mathematics. Not everyone. > But everyone says things like "Let x = 42", which certainly > looks to me like an assignment. (One might argue that it's > equivalent to saying "Consider now the case x = 42", so it's > actually a comparison, not an assignment. If one argued that > one would have to explain why "Let 42 = x" doesn't fly.) An = with a triangle above is also used to mean "define to be" (or something similar), which comes fairly close to assignment to me. Magnified: /\ /__\ ______ ______ It-always-makes-my-students-confused-ly y'rs /Mikael ----------------------------------------------------------------------- E-Mail: Mikael Olofsson WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 Date: 17-Oct-2001 Time: 07:59:49 /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ This message was sent by XF-Mail. ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From tjreedy at home.com Fri Oct 26 22:35:15 2001 From: tjreedy at home.com (Terry Reedy) Date: Sat, 27 Oct 2001 02:35:15 GMT Subject: Critical sections and mutexes References: Message-ID: wrote in message news:mailman.1004123848.1474.python-list at python.org... > On Fri, 26 Oct 2001, Cliff Wells wrote: > > > BTW, Dave, I would like to say that I have learned a few things on this topic > > that I wasn't aware of - thanks for the interesting discussion. > > Me too, and thank *you*! I know c.l.py isn't the only one like this, but > there aren't too many other newsgroups where people can take strong > positions and have a detailed discussion without it always turning into a > childish flamewar. Very refreshing and educational for me! This lurker (w/r/t this thread) also learned a few things. Terry From DeepBlue at DeepBlue.org Thu Oct 11 16:32:47 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Thu, 11 Oct 2001 15:32:47 -0500 Subject: CGI question on input type=text form elements References: <1348382.D5qtykdjRh@lunix.schabi.de> Message-ID: I am testing with IE5.5. However, I am going to add code that tests for a key and make sure that it is not empty. DB "Markus Schaber" wrote in message news:1348382.D5qtykdjRh at lunix.schabi.de... > Hi, > > DeepBlue schrub: > > > This is only happening when the form is enclosed in a table. When the > > form is not, the keys do not include empty text input elements. > > Which browsers did you test? > > Did you read the spec? > > I don'T think you can safely assume anything here. > > -- > You don't have to be Microsoft to suck... but it helps. > (Tim Hammerquist in comp.lang.python) From pcm at initd.org Sat Oct 20 06:11:58 2001 From: pcm at initd.org (Paolo Comitini) Date: 20 Oct 2001 03:11:58 -0700 Subject: where to get popy?? References: Message-ID: "Markus Jais" wrote in message news:... > hello > I was at > http://popy.sourceforge.net/ > > but there is not link to get a stable tarball for popy! > I can only get a cvs version > > and at http://www.nekhem.com/, there is not much right now. > > maybe I am just blind, but can someone give a link > where to find the latest stable version of popy??? > > thanks > markus If you need a python postgresql driver you can try also: http://www.initd.org/Software/psycopg Ciao Paolo ---------------------------------- Paolo Comitini pcm at initd.org From tim.one at home.com Sun Oct 21 01:45:46 2001 From: tim.one at home.com (Tim Peters) Date: Sun, 21 Oct 2001 01:45:46 -0400 Subject: Magic Module Methods? In-Reply-To: <9qt1qm$f7l$1@tyfon.itea.ntnu.no> Message-ID: [Magnus Lie Hetland] > OK - bad example (and terse explanation). The situation was this: I was > using a module as a config file, and at the same time as an object > containing defaults at some other point in the program (available for > users of the library). So you were pointing a gun at your foot, and just deciding which toe to blow off . Why not write a little ConfigFile class and supply methods and attributes in an obvious way? Better, exploit the ConfigParser module in the std library, and get a powerful config file facility for free. > Therefore, the defaults should be accessible from the module, > but the people writing the config file might not want to set absolutely > all the values... IOW, a module is a poor implementation of what you want. You ask why Python doesn't add stuff to modules so they do what you want here directly. I ask why you don't use classes instead, which have always supported what you want here. > I could of course do an update() on the module __dict__, > and that might be clearer, but possibly not near-infinitely? ;) Long ago Guido challenged c.l.py to just *try* writing Python without abusing __dict__ (and the other __xxx__ implementation details). It was excellent advice then, and still is. What would you do if Python didn't allow playing any dynamic tricks with module namespaces? Answering that should lead to a cleaner solution. > ... > Well, I wasn't saying that modules should act like lists or integers or > any other specific class of objects -- simply like objects in general. > (Everything is supposed to be an object now, right?) Everything has always been an object, but not everything is of the same type, and different types support different operations. Indeed, that's why there *are* different types: different behaviors for different intended uses. Complex numbers and strings also have attributes, but if you want to define __getattr__ for one of those, same thing applies: you'll have to wait for 2.2 and subclass. Supporting __getattr__ makes no sense for the intended uses of the builtin strings and complexes. Modules are intended to be used as the unit of separate compilation in Python, and are intended to supply a stable, static, documented interface. Since modules are intended to have a static (fixed) namespace after initialization is complete, __getattr__ on modules doesn't make sense for their intended uses either; that's why it isn't supported. >> you-can-subclass-the-module-type-in-2.2-but-hoping-you-don't-ly >> y'rs - tim > Subclassing the module type wouldn't be of much help here, would it? Using any flavor of module for this purpose seems wrong-headed to me, but if you want a module-like object that supports getattr, you *can* build one in 2.2, and stuff it into sys.modules like any other module. That wouldn't seem like "a help" to me even if you persisted until it worked , but you'll have to judge that for yourself. > ... > I still couldn't get the object-like behaviour directly from the > module. I think you mean class-instance-like behavior, and that's right if so: class instances are intended to be used for class-instance-like behavior. Everything in Python has object-like behavior (which doesn't amount to much more than responding to id() and almost always str() and repr()). Subclassing of builtin types in 2.2 *allows* to add bonzo behaviors to builtin-like objects, but you have to add the ones you want one at a time. There are some cool uses for this, but likely more bad ones. > (And no, I probably won't subclass it anyway.) Oh, live a little . > I don't really see what's wrong with the idea (of magic functions in a > module), but I'll accept "Tim doesn't like it" as a valid reason. :) If only life were that easy. "Tim doesn't approve of terrorism." WHOA! Unless I'm badly mistaken, the world is now a safer place . cheers-from-the-anthrax-capital-of-the-world-ly y'rs - tim From dyoo at hkn.eecs.berkeley.edu Mon Oct 29 23:26:44 2001 From: dyoo at hkn.eecs.berkeley.edu (Danny Yoo) Date: Mon, 29 Oct 2001 20:26:44 -0800 (PST) Subject: [Tutor] DNS module or how to ... ? In-Reply-To: <3BC185DE.30945.6E5441@localhost> Message-ID: On Mon, 8 Oct 2001, A wrote: > Is there a DNS module available for Python ? There are a few resources you can use if you're looking for Python modules. One of the best ones is the Vaults of Parnassus: http://www.vex.net/parnassus/ which collects links for a bunch of stuff. http://www.vex.net/parnassus/apyllo.py?find=dns lists the entries associated with DNS. Good luck to you! From killspam at darwinwars.com Fri Oct 5 15:04:21 2001 From: killspam at darwinwars.com (Andrew Brown) Date: Fri, 05 Oct 2001 19:04:21 GMT Subject: problem controlling MS Word from Python References: <9pkhei0rbe@enews2.newsguy.com> Message-ID: "Travers Naran" wrote in <9pkhei0rbe at enews2.newsguy.com>: >Can you clarify what you mean by "crashes"? Does python return a >traceback, or does the python interpreter itself crashes? I wouldn't be >surprised if it was the later: I've noticed Office apps connected by >automation can crash the client. > > No traceback. the interpreter crashes when Word throws up a dialogue box saying that it cannot translate a particular doc file to html. From DavidA at ActiveState.com Sun Oct 14 23:58:52 2001 From: DavidA at ActiveState.com (David Ascher) Date: Sun, 14 Oct 2001 20:58:52 -0700 Subject: "cgipython" or equivalent for Python 2.1.1, NT (IIS4)? References: <9pcbqm$r5v$1@serv1.iunet.it> Message-ID: <3BCA5EFC.D5C74A63@ActiveState.com> Alex Martelli wrote: > > I've purchased an unlimited-space, unlimited-traffic, just-about-no- > visible-support ISP account (came cheap in a bundle with ADSL to my > home and a .it domain). They "support" (...well... let's say, they > *have installed*:-) ASP (meaning, I'm sure, VBScript and JScript), PHP, > and CGI via Perl -- period. No chance to get them to install anything > else for me, of course -- when one buys a year's worth of unlimited > web serving for less than the price of a decent dinner, one can't > expect to get even a few minutes' worth of individualized support:-). > They seem to be running Microsoft IIS 4.0 on SMP NT4 boxes, with the > latest SP's and security hotfixes (no codered vulnerability, wow:-). You might be able to get them to run python as an ASP active scripting host... --david From tim.one at home.com Mon Oct 29 02:24:17 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 29 Oct 2001 02:24:17 -0500 Subject: Breakpoints cause enormous slowdown In-Reply-To: <3BDCFC7C.82EE7D@cygnus-software.com> Message-ID: [Bruce Dawson] > I've been playing around with PythonWin and a proprietary debugger with > a common derivation, and they both have a serious problem. I'm worried > that this problem may be fundamental to Python debuggers. > ... > However, if I leave the breakpoint in place then ... > the performance drops by approximately five hundred to one!!! > ... > My understanding is that when there is a breakpoint set that the > debugger has to run in a single step mode and check a list of > breakpoints after each instruction. If that is so then a 500:1 drop in > performance is not surprising. "Single step" is actually "single line", or, more precisely, "once per SET_LINENO opcode", and each involves a callback into the Python code that implements the debugger (assuming it's pdb-like). You can read a bit about this in the "How it Works" subsection of the Python Debugger chapter in the Library manual. > ... > Other language/debugger pairs frequently solve this problem with a > breakpoint instruction. > ... > Has this been discussed before? Is this possible? Yes and yes. Nobody has implemented it, though, and there are (surmountable) technical difficulties facing whoever tries. A good solution would make SET_LINENO opcodes history (indeed, they're not needed now for anything *except* driving debuggers and tracers -- line numbers in tracebacks don't rely on SET_LINENO). > The benefits would be huge. Right now there are some classes of problems > that cannot be debugged with a debugger in Python because of the > tremendous slowdowns that occur. I confess I haven't used the Python debugger in many years -- a judicious 'print' statement or two coupled with thought usually solves problems quickly. Ditto for debugging C code, for that matter. I'm not recommending that you do likewise, just explaining why I've never felt an urge to "do something about the debuggger problem". But I assume much the same applies to most of The Usual Contributing Suspects, since the debugger is rarely a topic of conversation. patches-appreciated-ly y'rs - tim From peter at engcorp.com Sun Oct 21 19:29:49 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 21 Oct 2001 19:29:49 -0400 Subject: a better prime number generator References: <23d58b26.0110210939.55bb7e0c@posting.google.com> <9qvbgi$kak$2@news-int.gatech.edu> Message-ID: <3BD35A6D.9BF5DAF0@engcorp.com> Moshe wrote: > I think the OP would be best suited using this algorithm with a faster > language. I'm not really sure what in python is fast and what is not, but > for a goal this simple, why not just write a python module in C, or just a > C program? I think the OP was more interested in using this as a learning exercise. As he said [typos edited by me]: """ hi all, I have just been introduced to python and find it a very good ( takes off all the bookwork ) language. I was trying to develope a fast prime number generator. I designed the following algo. Can you please suggest a faster one or modifications to this only to make it faster? """ Sounds to me like he was more interested in learning how to write fast Python code than in getting a program to run the algorithm as fast as possible, regardless of language. -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From thamza.nospam at flash.net Sun Oct 21 14:54:18 2001 From: thamza.nospam at flash.net (Tim H) Date: Sun, 21 Oct 2001 18:54:18 GMT Subject: a better prime number generator References: <23d58b26.0110210939.55bb7e0c@posting.google.com> Message-ID: I'm not sure what you are doing, didn't try to figure out how yours should be indented, but I came up with this when I first started playing around with python. It is more efficient than the one in the tutorial and much simpler to understand than yours. There are probably better ways. def primes(n): "Returns list of prime numbers 2 to n." p = [2] for a in range(3, n+1): for b in p: if a % b == 0: break else: p.append(a) return p Tim "Rupendra Dhillon" wrote in message news:23d58b26.0110210939.55bb7e0c at posting.google.com... > hi all, > I have just been introduced to pyton and find it a very good ( takes > off all the bookwork ) language. I was trying to develope a ast prime > number generator. I designed the following algo. Can you please > suggest a faster one or modifications to this only to make it faster > > #the following algo returns all the primes below x > > def getPrimesTill(x): > a = range(2,x) > c = [2] > > i = 0 > j = 0 > > foundone = 1 > > while i < len(a): > while j < len(c) and (c[j] < (.5 * a[i]) ) and foundone == 1: > if a[i]%c[j] == 0: > foundone = 0 > j = j + 1 > if foundone == 1 and i > 0: > c.append(a[i]) > j = 0 > foundone = 1 > i = i + 1 > return c > > > roop From asencio at mitre.org Sun Oct 28 18:11:23 2001 From: asencio at mitre.org (Angel Asencio) Date: Sun, 28 Oct 2001 18:11:23 -0500 Subject: BOA GUI builder? References: <3BD9CC09.2B1AB020@mitre.org> Message-ID: <3BDC909B.4F500B9C@mitre.org> I went to the boa sourceforge site, and although I could find rhw CVS files listed, I could not find a module name to dowload through CVS, nor a link to download all the files related to V0.0.13. What am I missing? Thanks. Tim H wrote: > The version in CVS is much further along (0.0.13). You might want to try > that. It works for me. You do have to modify it slightly, it is looking > for wxPython 2.30 and we are both using 2.3.1, but if you got BOA 0.0.5 to > work you should have no probs with that. > > Tim H > "Angel Asencio" wrote in message > news:3BD9CC09.2B1AB020 at mitre.org... > Greetings: > I got the BOA Python IDE from http://boa-constructor.sourceforge.net/. > I looks great, but when I went to save the WxFrame.py from the tutorial, it > gave me a Win2000 error, but I ignored it. > Then when I went to save WxApp.py it crashed. > I have Win2000, BOA 0.0.5, wxPython 2.3.1 and Python 2.1 > Do I need to get some patch to stabilize BOA? > Thanks, > -- > -Angel From geiseri at yahoo.com Tue Oct 23 12:57:23 2001 From: geiseri at yahoo.com (ian reinhart geiser) Date: Tue, 23 Oct 2001 12:57:23 -0400 Subject: combining large C-programme with Python In-Reply-To: <3BD59F30.587006A@cs.kuleuven.ac.be> References: <3BD59F30.587006A@cs.kuleuven.ac.be> Message-ID: <200110231656.MAA04824@generic2.axs2000.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 23 October 2001 12:47 pm, Pieter De Ceuninck wrote: > Hello, > > I'd like to know if anyone can give some projects where existing C-code > was modularized using Python. I'm planning to redesign (refactor) a > large C-code with a new top-layer of Python and the necessary > adaptations (as few as possible) in the underlying (numerical, > scientific computing) C-code. I'm not talking about writing _new_ > scientific computing python-code with numpy or so, just using existing > C-code. > If no such projects are known, what would be a good way to refactor that > huge code ? Complete re-implementation is not an option :-) > > thx, > Pieter SWIG and SIP are the two big ones. SIP works great for C++ but lacks docs while SWIG seems a little harder to use, but is more flexable. There is also some good docs in the python dist about Extending and Embedding python. cheers - -ian reinhart geiser - -- ======================================== It is now pitch dark. If you proceed, you will likely fall into a pit. ======================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE71aFzPy62TRm8dvgRAscqAKDcw27kqBW9SV1eL+Etn2cDC6uD9wCfRzwC VFjjaQk3zi/WriBPF1oaS+4= =Ikvn -----END PGP SIGNATURE----- From donn at drizzle.com Wed Oct 24 00:53:51 2001 From: donn at drizzle.com (Donn Cave) Date: Wed, 24 Oct 2001 04:53:51 -0000 Subject: Embedding and Extending Issue References: None Message-ID: <1003899230.484030@yabetcha.sttl.drizzle.com> Quoth ian reinhart geiser : | Hash: SHA1 Hash, SHA! | I have started adding the ability to script my application via python. I | have followed the Extending and Embedding docs and the demo.c code. This has | me with a very impressive setup so far, but now I have an issue. I used SIP | to create bindings to my entire C++ application, so now I have access to all | of the datatypes that my application supports. So I can bar *foo = new | bar(); in C++ and I can foo = bar() in python. The problem is I would like | to be able to access my foo object that was created in C++ from python. | | I am lost though on how to convince Python it knows about this data type. I | currently have the following code: ... | PyObject *PyBar = Py_BuildValue("O&",convertBar ,&bar); ... | My issue is I am confused as what convertBar() should be. | The docs are very light on this issue. I am hopeing this should be quite | trivial because python all ready knows about this data type. That would be a converter function. Your &bar is supplied as the parameter and the return should be an object of the Python type, representing bar in Python. If python already knows about this data type, then a function like that should be no problem. Don't forget to replace all instances of foo and bar with something else, like spam and eggs. There's no place for foo in Python. Donn Cave, donn at drizzle.com From markus at schabi.de Thu Oct 11 16:16:11 2001 From: markus at schabi.de (Markus Schaber) Date: Thu, 11 Oct 2001 22:16:11 +0200 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> Message-ID: <1108590.MPnJmAY2XU@lunix.schabi.de> Hi, Donn Cave schrub: > (Note that I'm not > talking about the initialization section of for(), which is a > pure non-feature - those statements can just as well be written > before the loop.) There's one difference: You can define temporary variables which are only valid inside of the for statement. But this may be emulated creating an artificial {} block around it. markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From lac at strakt.com Thu Oct 18 06:36:22 2001 From: lac at strakt.com (Laura Creighton) Date: Thu, 18 Oct 2001 12:36:22 +0200 Subject: Function arguments In-Reply-To: Message from "Thomas Heller" of "Thu, 18 Oct 2001 10:28:58 +0200." <9qm3sb$pc43f$1@ID-59885.news.dfncis.de> References: <9qm3sb$pc43f$1@ID-59885.news.dfncis.de> Message-ID: <200110181036.f9IAaM0W015147@ratthing-b246.strakt.com> > Call me weird, but sometimes I need functions taking a number of > positional arguments, some named arguments with default values, and > other named arguments as well. > I was thinking of a popitem() dictionary method taking > (optionally) 2 arguments: the name of the item to pop, > and the default value to return if the item is not present > in the dictionary: > > >>> d = {'a': 2, 'b': 3} > >>> d.popitem('defarg', 0) > 0 > >>> d > {'a': 2, 'b': 3} > >>> d.popitem('a', 100) > 2 > >>> d > {'b': 3} > >>> > > Opinions? I do this frequently. (Code yanked from what I happen to be working on today). class Field(Tkinter.Label): def __init__(self, parent, **kw): # these are the defaults that you will get if you haven't specified defaults={'borderwidth': 1, 'relief' : 'groove', 'width' : 30, 'height' : 2, 'anchor' : 'w', 'text' : 'SPAM SPAM SPAM SPAM', } # overwrite any of the defaults with the dictionary you passed defaults.update(kw) Tkinter.Label.__init__(self, parent, **defaults) and so on and so forth Laura Creighton From tdelaney at avaya.com Wed Oct 17 04:03:32 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 17 Oct 2001 18:03:32 +1000 Subject: Desperate help required for Python assignment Message-ID: > From: nachiket_gole at hotmail.com [mailto:nachiket_gole at hotmail.com] > > I am new to Python doing a crash course in University. I have a > assignment to submit in two days the specifications of which are: > 1.Write a script in python which maps a set of linked webpages. It > should take the URL as a command line argument, retireve the page, > extract the URL's of pages linked to by the page in question and store > them in a data structure for the page. It should then repeat this > with other linked pages to a depth of 5. It should visit each page > only once. > 2.The script should also be able to take -L as a command line argument > and that being the case should only follow links on the same server as > the current site. > 3.The script should also record the titles of links in the documents > eg > Mysite -- > http://mysite.com > 4.Finally all this has to be displayed as a tree for eg > >python mytest.py "some url" > http://..... > + http://........ > + http://....... > + http://...... > Please can some of the Gurus on this newsgroup help me out with a > working solution as with my limited knowledge i am no position to > handle this assignment in two days. Unfortunately, you have not shown any evidence that you have even attempted to do this assignment. Assuming that you have Python configured correctly on your machine, you should be able to design and develop this assignment within 2 days, even if you know zero Python when you start. This of course assumes that you are a competent programmer in at least one other language. If you are not, you have no chance of passing this assignment. First step is to design what you want to do. Don't even think about the code at this point - however, *do* write pseudo-code (it will help you later). *Then* you need to translate your design into Python. If you have written pseudo-code, you should find this very easy. Simply take the design, and use the standard Python documentation to convert it to Python. If you have a good design you should find that the resulting Python code is *very* similar to your pseudo-code. There are certain standard libraries you will need/want to use for this assignment. Probably the most straight-forward method will use the sys, urllib and either re or string modules. Everything you need is in the standard documentation. If you want more help, you should post part of what you have already developed over the previous 2-6 weeks that you have had this assignment. Tim Delaney From gdemmy at layton-graphics.com Thu Oct 4 12:54:05 2001 From: gdemmy at layton-graphics.com (George Demmy) Date: 04 Oct 2001 12:54:05 -0400 Subject: advanced regex, was: Re: scanf style parsing References: <3BB16A50.BAE082FE@cygnus-software.com> <3BB2C7DA.F63EEAA7@cygnus-software.com> Message-ID: hpj at urpla.net (Hans-Peter Jansen) writes: > Well, yesterday, I tried to parse some simple hexdump, produced by > tcpdump -xs1500 port 80. The idea was, filter the hexcodes, and display > and 7 bit acsii codes like a little advanced hex monitors do. > > As I'm fairly new to advanced regex constructs, would somebody enlight > me, how to efficiently parse lines like: > > 2067 726f 7570 732e 2e2e 3c2f 613e 3c2f > 666f 6e74 3e3c 2f74 643e 3c2f 7472 3e3c > 7472 3e3c 7464 2062 6763 6f6c 6f72 3d23 > 6666 6363 3333 2063 6f6c 7370 616e 3d34 > 3e3c 494d 4720 6865 6967 6874 3d31 2073 > 7263 3d22 2f69 6d61 6765 732f 636c 6561 > 7264 6f74 2e67 6966 2220 7769 6474 683d > 3120 3e3c 2f74 643e 3c2f 7472 3e3c 2f74 > 6162 6c65 3e3c 703e 3c66 6f6e 7420 7369 > 7a65 3d2d 313e 4172 6520 796f 7520 6120 > > with respect to varying column numbers. I will refrain to > show my stupid beginnings, but I wasn't able to get that _one_ > regex right, with all columns in matchobj.groups() listed. > > new-in-regexing-ly, yr's > Hans-Peter > > P.S.: I ended up in a "simple" c based filter... > Please CC me Hi Hans-Peter, You're asking how to use a regex to parse your hexdump, with an eye towards displaying the ascii representation. I don't know if regex is what you want to do the latter. Here is some example code that might help. import re hexpat = re.compile ('[a-f0-9]{4}') # your first line of the hexdump, stripped line = '2067 726f 7570 732e 2e2e 3c2f 613e 3c2fp' hexpat.search (line).span () -> (0, 4) hexpat.search (line[4:]) -> (1, 5) As to the getting your ascii... import operator def hex2ascii (hexstr): """hex2ascii (hexstr) -> ascii rep of 4 character hex string""" # error checking here, please! return chr (int (hexstr[:2], 16)) + chr (int (hexstr[2:], 16)) # slurp your hexdump by line (your example is stored in hexdat, by line) # stripping off the leading whitespace hexdat = map (lambda x: x.strip (), open ("dumpfile").readlines ()) for i in hexdat: print i, reduce (operator.add, map (hex2ascii, i.split ())) -> 2067 726f 7570 732e 2e2e 3c2f 613e 3c2f groups...< 7472 3e3c 7464 2062 6763 6f6c 6f72 3d23 tr>

Are you a Hope this helps, and critique most welcome... G -- George Demmy Layton Graphics, Inc Marietta, Georgia From jim.correia at pobox.com Fri Oct 19 21:03:36 2001 From: jim.correia at pobox.com (Jim Correia) Date: Sat, 20 Oct 2001 01:03:36 GMT Subject: Dictionary from list? References: Message-ID: In article , Andrei Kulakov wrote: > You know, this sort of thing comes up often - X is a built-in feature in > perl, why do I have to do it manually in python? I think this is a > justified design decision - there's simply too many built-in things perl > does. You can't remember all of them and if you look at someone else's > perl program you have to scratch your head a lot. Python is small, lean > and clean, and that's one of the best things about it. I wasn't insisting that there must be on in python, just asking if there was :-) From tdelaney at avaya.com Tue Oct 2 22:54:48 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 3 Oct 2001 12:54:48 +1000 Subject: Python is better than free (was Re: GNU wars again) Message-ID: > From: Chris Watson [mailto:opsys at voodooland.net] > On Tuesday 02 October 2001 02:58 pm, Oleg Broytmann wrote: > > On Tue, Oct 02, 2001 at 11:58:52AM -0500, Paul Miller wrote: > > > Trying to make me into a cheap-skate and a thief doesn't > endear me too > > > much to you Oleg. > > > > But of course! > > > > > The issue is not whether I use people's work without > paying them - if > > > they didn't want me to, they would CHARGE for it. > > > > This is exactly how the GPL works - it charges for my > code. You can pay > > me money, or you can pay me by opening your code. > > Thats called extorsion. Time to wade in. My preferences lie very strongly with BSD-style licenses (basically, do what you want with this). I personally feel that code should be available to be used in whatever way someone wants. This is not to say that all code should be without charge - depending on what it is, I would be quite willing to pay a (one-off) fee to be able to *then* do whatever I wanted with the code (with some caveats - I would not expect to be able to distribute code in unmodified form if it required a fee for me to obtain it in the first place). I find the GPL is one of the best ways to ensure that your code will not be used by other people, unless you get lucky and it becomes a big open source project (note - no capitals on open source, so no one jump on me for using the term incorrectly). For every large GPL project that's well supported by many developers, there are thousands of bits of GPL code which are never used by anyone except the original author. With BSD-style licenses, you find that you code is more likely to be used by someone else. GPL code is often useful, but not used. I know I have many times looked at something, thought I would like to incorporate it into something I was working on (usually public domain or open source), then noticed it was GPL and decided not to use it because it would restrict what others could do with my code. However, GPL is *not* extortion. The writer of a piece of code has every right to want to protect, control or charge for it. Tim Delaney From gb at cs.unc.edu Fri Oct 5 08:46:02 2001 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 05 Oct 2001 08:46:02 -0400 Subject: Profiling the Python Interpreter References: Message-ID: Skip Montanaro writes: > What version(s) of gcc have you tried? What optimization levels? I notice > marked improvements in performance if I tailor the optimization level to the > hardware better. -mcpu=pentiumpro seems to have a fairly substantial > positive impact if you're running on a P-III, for instance. Good suggetsion Skip. This is compiler version appears to be 2.95.3-5. I (just now) compiled it with "-O3 -mcpu=pentiumpro" but it didn't improve the run time. This is on a 600MHz PIII Laptop. gb From dale at riverhall.NOSPAMco.uk Mon Oct 8 07:55:28 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Mon, 08 Oct 2001 12:55:28 +0100 Subject: Curious assignment behaviour Message-ID: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> I observe that the folowing works as some might expect: x = y = 5 Assigns 5 to both x and y. However the expression: y = 5 does not yeild 5 >>> print y = 5 Traceback ( File "", line 1 print y = 5 ^ SyntaxError: invalid syntax >>> So this is obviously a gludge in assignment. I'd be much happier if assignment yeilds the value assigned, as it does in C (I believe). It could then be used universaly. Also, where is this curious behaviour documented? 6.3 of the Language Ref makes no reference to it. (Go on. Prove me wrong!) Thanks. -- Dale Strickland-Clark Riverhall Systems Ltd From pih at oek.dk Sat Oct 6 08:35:33 2001 From: pih at oek.dk (Peter I. Hansen) Date: Sat, 06 Oct 2001 14:35:33 +0200 Subject: PyML References: <3BBEF951.BEECA468@oek.dk> Message-ID: <3BBEFA95.4AA75A59@oek.dk> "Peter I. Hansen" wrote: > Hi > > I'm trying to get PyML installed on my FreeBSD 4.3-rel. (www.pyml.org) > > I've followed the instruktions, but the embedded code is not translated. > Have anyone here tried this package ? > > /Peter never mind. I made a mistake :) /Peter From fdrake at acm.org Tue Oct 30 01:23:32 2001 From: fdrake at acm.org (Fred L. Drake) Date: Tue, 30 Oct 2001 01:23:32 -0500 (EST) Subject: [development doc updates] Message-ID: <20011030062332.77F4928697@cj42289-a.reston1.va.home.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Re-arranged the material in Chapter 2 (built-in things) to make it easier to start off with. Functions come before Types and Exceptions, and file objects are promoted one level in the outline, making them easier to find (they now appear in the table of contents instead of being hidden in the "Other Objects" category). From urner at alumni.princeton.edu Sat Oct 6 13:45:07 2001 From: urner at alumni.princeton.edu (Kirby Urner) Date: Sat, 06 Oct 2001 10:45:07 -0700 Subject: Why object.__getattribute__ and not object.__getattr__ ? Message-ID: >>> dir(object) ['__class__', '__delattr__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__repr__', '__setattr__', '__str__'] Why this decision to do with a long spelling of __getattribute__ but not __setattr__ or __delattr__ ? Also, does someone have a quick explanation of how to use __new__ handy? I'm not finding it in the tutorials (even the recent 2.2 specific one). Kirby From sebrosa at artenumerica.com Mon Oct 22 14:54:22 2001 From: sebrosa at artenumerica.com (Jose' Sebrosa) Date: Mon, 22 Oct 2001 19:54:22 +0100 Subject: suggestion for module re References: <3BD3E830.3EC94E94@artenumerica.com> Message-ID: <3BD46B5E.5EFD1292@artenumerica.com> Skip Montanaro wrote: > > Jose> My first goal is to get all the *named* fields of a regex, for all > Jose> of the matches in a source string. The re.RegexObject.findall > Jose> method is "almost" good, but it returns a tuple of matched > Jose> *groups*, leading to a dumb pharentesis-counting task and to code > Jose> hard to maintain. > > I suspect that in most situations you will want all the interesting groups > to be named or none of the interesting groups to be named. Yep, I believe so. > If you want > named groups, use the "(?:...)" construct to create "throwaway" groups. See > the re syntax docs for more info: Right. Good suggestion. That solves the problem when we want to make changes in a regex (such as insert a group for branching purposes, I mean, things like (X|Y) instead of X, and don't need to keep track of the thing grouped. > http://www.python.org/doc/current/lib/re-syntax.html Actually, http://localhost/doc/python/html/lib/re-syntax.html :-) > Your example would thus become: > > rx = re.compile(r'(?:(?Pa|A)(?Pb|B))') > > (though why you needed the outer parens in the first place is not clear). (Right, my outer parenthesis are a dumb mistake.) Anyway, it still remains the need of a function to travel through a string and collect all the matches in one single object, *while preserving the names*. I mean, we have named groups in the regex engine, so we shouldn't need to keep counting parenthesis... The merge of the good things of groupdict and findall seems natural. Better even if we can merge the good things of findall and *every other* matchObject method/attribute, present or future! So eventually the Good Thing is to have a method similar to findall that returns *objects* instead of a specific view of them. Thanks, Sebrosa From joonas at olen.to Tue Oct 2 15:56:36 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: Tue, 02 Oct 2001 22:56:36 +0300 Subject: Need help finding Python/TKinter Link Checker References: Message-ID: <3BBA1BF4.C1E60CD9@olen.to> Chris Cogdon wrote: > > Some time ago I found a marvellous little web link checker, written in > Python, and had an optional Tk interface which looked great for seeing > what it was currently working on, what it had already checked and what was > still left to do. > > However, it seems to have erased itself from existance; from my hard > drive, software archive, and freshmeat. Does anyone know what it might be > called, and where it might be located? > > I'm looking for the one with the Tk interface, not the CGI-based ones. Might it be webchecker.py. It's located at Tools/webchecker directory of the Python distribution. From obscurity at obscure.org Mon Oct 1 14:19:03 2001 From: obscurity at obscure.org (obscurity) Date: Mon, 01 Oct 2001 18:19:03 GMT Subject: Problems embedding python (undefined symbol: stat) References: Message-ID: On Tue, 25 Sep 2001 00:04:24 GMT, obscurity wrote: > I'm trying to embed python in a C++ app I'm writing (on linux). All I've > added so far is a call to Py_Initialize, and when I run my app it dies > somewhere in Py_Initialize with "undefined symbol: stat". Isn't stat a > standard libc call? If so, how the hell can it be undefined? I'm coming to > the conclusion that my python installation is broken in some way, but it was > a simply ./comfigure;make;make install job, so I haven't done anything > strange with it. > > Can anyone offer an advice in fixing this? So, can *no-one* help me with this? Not even a vague pointer to some documentation or something? Anyone? Pretty please? -- obscurity. "Only the great masters of style ever succeed in being obscure." - Oscar Wilde From vvainio at karhu.tp.spt.fi Tue Oct 16 03:31:35 2001 From: vvainio at karhu.tp.spt.fi (Ville Vainio) Date: 16 Oct 2001 10:31:35 +0300 Subject: Statements vs. expressions (was Re: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xhet6ot4j.fsf@ruckus.brouhaha.com> <9q5370$3re$1@lancelot.camelot> <9q8vpq$hbh$1@lancelot.camelot> Message-ID: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) writes: > Agreed generally. A clarification, though: the proposal does not allow > statements in expressions; it allows statements _between_ conditional > keywords and the corresponding expressions, like > > while [ ; ] : > if [ ; ] : By the way, what is the big win with having statements in the language, as opposed to just having expressions (possibly returning 'Unit' or something similar)? -- Ville Vainio - http://www.tp.spt.fi/~vvainio - ICQ #115524762 Wild geese have no intention to cast a reflection Water has no mind to assume their form From geoffrey at bigpond.net.au Fri Oct 12 05:46:11 2001 From: geoffrey at bigpond.net.au (Geoffrey Pointer) Date: Fri, 12 Oct 2001 09:46:11 GMT Subject: OT: This is a useless thread. (was: YOU ARE ALL GAY!) References: <3BC6A9D9.2030608@redhat.com> Message-ID: On: Fri, 12 Oct 2001 03:29:13 -0500 Michael Lee Yohe said: > Please quit cross-posting this big piece of excrement. Excuse me!! Whether or not you agree with what tm and I are saying and whether or not we agree with each other, this often happens in threads. Sometimes the issue of _how_ to use the usenet comes up. How do you expect these ideas to disseminate other wise? I'm glad tm was bothered to comment whatever I might think about his approach. You on the other hand are just totally blinkered. The cross-posting thing happened in the original message. I'm sorry if that was contributed to by me but as in this case also, you yourself have replied by cross-posting so who knows where from and not only that, you've changed the thread subject. You've personally contributed to the multiplication of the excrement you apparently detest. Need I say more? This is certainly my last message in this/that thread. -- Cheers - Geoff %^> From skip at pobox.com Wed Oct 24 00:52:59 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 23 Oct 2001 23:52:59 -0500 Subject: readlines() on a socket In-Reply-To: <86lmi1r8lc.fsf@hellcat.itga.com.au> References: <86lmi1r8lc.fsf@hellcat.itga.com.au> Message-ID: <15318.18731.529663.127323@beluga.mojam.com> Gregory> I'd like to be able to do Gregory> s = socket.socket(...) Gregory> s = socket.connect(....) Gregory> for l in s.readlines(): Gregory> # process line l Gregory> but sockets don't support readline(), or readlines(), or Gregory> anything similar that I can see. Socket objects have a makefile() method that will return a file object. s = socket.socket(...) socket.connect(....) f = s.makefile() for l in f.readlines(): process_lines() (Also, note that you should not assign the result of the connect method. I believe it simply returns None.) -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From idot at vt.edu Thu Oct 18 16:39:42 2001 From: idot at vt.edu (Carl Banks) Date: Thu, 18 Oct 2001 16:39:42 -0400 Subject: PEP: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: Huaiyu Zhu wrote: > PEP: Statements in Control Structures The problem I have with this proposal (besides the sheer ugliness of the syntax) is that there is an assumption made that there are at most a few statements required before the exit test. This is not always true. For example, I have written loops like this before: while 1: if : break With your proposal, all those lots and lots of statements would have to be chained into one logical line of code. Of course, no one is going to do that, so in such cases we would revert to the old "while 1:" idiom. We're right back to where we started. Now, I have no problem whatsoever with the "while 1:" idiom. But the point I'm trying to make is this: if we *must* add new syntax to the language, let's not go with a partial solution to the "problem", especially when that solution is ugly and unPythonic. The Python-like way to organize statments is to put them in blocks, so.... > if stmts1; expr1: > stmts2 > elif stmts3; expr2: > stmts4 > elif stmts5; expr3: > stmts6 > else: > stmts7 I would suggest something more along these line (fleshing out the example a little): suppose: m = re.search (somthing) if m: do_something_with (m) elsuppose: m = re.search (somthing_else) if m: do_something_else_with (m) else: raise some_exception; I hope it's obvious how it works. Once we've met a condition and entered an if block, we will make no more suppositions (i.e., further elsuppose blocks would not be executed). Of course, the suppostions could involve more complex calculations than regexp searching, which would make the statements-in-control-structures approach unweildy. > while stmts1; expr1: > stmts2 > if expr2: break > stmts3 > else: > stmts4 I would suggest something like: do: while : with the do part optional. The exact keywords and semantics I don't care about. But, like I said, I have no problem with "while 1:". > 3.2. Better break-else interaction: > > Python allows an else-clause for the while statement. The naive way > of writing the general loop-and-half in current Python interferes > with the else clause. For example, > > while x = next(); not x.is_end: > y = process(x) > if y.is_what_we_are_looking_for(): break > else: > raise "not found" > > cannot be written in this naive version: > > while 1: > x = next() > if x.is_end: break > y = process(x) > if y.is_what_we_are_looking_for(): break > else: > raise "not found" I completely disagree with this rationale. The only thing naive about this example is your suggestion that an else clause would be useful here. You should know that the raise statement belongs after "if x.is_end:". Generally speaking, when performing a test, you want to be able to specify code to execute for either result, true or false. With an if statement, you can do this, obviously. In most languages, you cannot specify code to execute when a test by the while statement results in false. However, you can in Python, which is why else clauses on while statements are so cool. But, when an if statement tests your exit condition, as in the "while 1:" idiom, you already have all the flexibility you need. There is nothing an else clause following the while statement can add to it. All-in-all, I don't feel there is much reason to change the language for this. The suppose statement might be nice to occasionally avoid deeply nested ifs, but I can live without it. -- CARL BANKS From MarkH at ActiveState.com Thu Oct 11 03:12:24 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Thu, 11 Oct 2001 07:12:24 GMT Subject: error in the DDE conversation with Pythonwin References: <603e1b49.0110091700.49d8decd@posting.google.com> Message-ID: <3BC54666.40203@ActiveState.com> Steve Canfield wrote: > When I try to start Pythonwin on my machine (Athlon 800), I get the > following error box: > Python for Win32 > There was an error in the DDE conversation with Pythonwin > I click on okay and it seems to finish loading okay. > I'm running: > PythonWin 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on > win32. > under Windows Me. > > If I bring up my task list, Pythonwin is listed more than one time. I > think this is because the first instance never starts up. I have a > desktop icon to Pythonwin and I generally have to click on it a couple > of times before Pythonwin will start up (giving plenty of time between > startup attempts). > > Any ideas what the problem could be? I searched for this error > message on Google and didn't get any hits. The problem is generally that some _other_ application is running on your machine that is not processing messages. This is a common problem with DDE applications. One good example is MSVC. If you are using MSVC and at a breakpoint, Pythonwin will not start. When you stop the debug session, Pythonwin then pops up. You can avoid this by running "pythonwin.exe /nodde". However, this will *always* start a new instance of Pythonwin. Mark. From cfelling at iae.nl Wed Oct 17 18:45:11 2001 From: cfelling at iae.nl (Carel Fellinger) Date: 18 Oct 2001 00:45:11 +0200 Subject: Pymacs 0.11 References: <9qjosn$5nd$1@animus.fel.iae.nl> Message-ID: <9ql1ln$306$1@animus.fel.iae.nl> Fran?ois Pinard wrote: > [Carel Fellinger] >> Fran?ois Pinard wrote: >> > interactions[hello_world] = '' >> why not use function attributes, like: >> hello_world.lisp_interaction = '' > Are these available in Python 1.5.2, say? I wants Pymacs to be reasonably > portable. You're right. I'm so happy with the generator stuff, that I forgot that many still have to do with 1.5.2. So the fall back method should be yours. But maby it's possible--in anticipation of a wider usage of more modern Pythons--to check first for such a function attribute, like: try: interaction = fun.lisp_interaction except NameError: interaction = interactions[fun] -- groetjes, carel From arturs at iidea.pl Thu Oct 4 15:05:51 2001 From: arturs at iidea.pl (Artur Skura) Date: 4 Oct 2001 19:05:51 GMT Subject: Nicer Tkinter on UNIX? References: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> <86DF15C112AF36D6.332DEDD523A2210C.F8DE5222D8EF2836@lp.airnews.net> <3bbc18a8$0$19394$e4fe514c@newszilla.xs4all.nl> Message-ID: Boudewijn Rempt wrote: > Phil recently pre-released PyQt for Qt 3 (just in time to > test everything in my book with it) - and it would be > extremely interesting to get that to work with Qt3 for OS X. > I'd really like to try it, but I don't have a Mac :-(. Still, > I really expect PyQt 3 for OS X to available in the very near > future. It makes me wonder why such a useful package as PyQt is not a part of Python distribution (the same holds for GTK bindings). I think it would be good for users and developers to have them installed together with all other modules. Also, an ideal solution for me would be a wrapper module (anyGUI, kindof), which would check for Qt etc. libraries on systems that support it; if not found, it would use Tkinter. Is there anything like this? I think such wrapping would be somewhat easier with GTK and Tkinter (they seem a bit similar). Regards, Artur -- http://www.wolneprogramy.org From mtbros at libero.it Fri Oct 5 16:24:30 2001 From: mtbros at libero.it (Mario T.) Date: Fri, 05 Oct 2001 20:24:30 GMT Subject: Error using py2exe... Message-ID: <2Gov7.30649$0Y2.3056391@news.infostrada.it> Hi, Thomas Heller posted this example of the use of his py2exe to build a local COM server: ------------------ EXAMPLE ----------------------- ------------------testCOMserver.py----------------------- import sys import pythoncom if hasattr(sys, 'importers'): # we are running as py2exe-packed executable pythoncom.frozen = 1 class HelloWorld: _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER if hasattr(sys, 'importers'): # In the py2exe-packed version, specify the module.class # to use. In the python script version, python is able # to figure it out itself. _reg_class_spec_ = "__main__.HelloWorld" _reg_clsid_ = "{B83DD222-7750-413D-A9AD-01B37021B24B}" _reg_desc_ = "Python Test COM Server" _reg_progid_ = "Python.TestServer" _public_methods_ = ['Hello'] _public_attrs_ = ['softspace', 'noCalls'] _readonly_attrs_ = ['noCalls'] def __init__(self): self.softspace = 1 self.noCalls = 0 # __init__() def Hello(self, who): self.noCalls = self.noCalls + 1 # insert "softspace" number of spaces return "Hello" + " " * self.softspace + str(who) if __name__ == '__main__': if hasattr(sys, 'importers'): # running as packed executable. if '--register' in sys.argv[1:] or '--unregister' in sys.argv[1:]: # --register and --unregister work as usual import win32com.server.register win32com.server.register.UseCommandLine(HelloWorld) else: # start the server. from win32com.server import localserver localserver.main() else: import win32com.server.register win32com.server.register.UseCommandLine(HelloWorld) --------------------------------------------------------- This is the setup script you can use to build an executable with py2exe: ----------------------setup.py--------------------------- from distutils.core import setup import py2exe setup(name='testCOMserver', scripts=['testCOMserver.py']) --------------------------------------------------------- ------------------END EXAMPLE ----------------------- But typing on the command prompt > python setup.py py2exe I'm running into troubles: warning: install: modules installed to 'build\bdist.win32\winexe\lib\Dev\Lang\Python21\', which is not in Python's module search path (sys.path) -- you'll have to change the search path yourself Traceback (most recent call last): File "setup.py", line 5, in ? scripts=['testCOMserver.py']) File "D:\Dev\Lang\Python21\lib\distutils\core.py", line 138, in setup dist.run_commands() File "D:\Dev\Lang\Python21\lib\distutils\dist.py", line 899, in run_commands self.run_command(cmd) File "D:\Dev\Lang\Python21\lib\distutils\dist.py", line 919, in run_command cmd_obj.run() File "D:\Dev\Lang\Python21\py2exe\py2exe.py", line 397, in run dlls, unfriendly_dlls = self.find_dependend_dlls(use_runw, dlls) File "D:\Dev\Lang\Python21\py2exe\py2exe.py", line 510, in find_dependend_dlls alldlls, warnings = bin_depends(loadpath, images) File "D:\Dev\Lang\Python21\py2exe\py2exe.py", line 703, in bin_depends for result in py2exe_util.depends(image, loadpath).items(): py2exe_util.bind_error: D:\Dev\Lang\Python21\py2exe\run.exe Well, I have never used py2exe before, so do you have any pointer on what this mean ? I'm running python 2.1.1 from ActiveState TIA, Mario From madsdyd at challenge.dk Mon Oct 1 08:01:21 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 14:01:21 +0200 (CEST) Subject: Problem with linking embedding C application In-Reply-To: Message-ID: On Mon, 1 Oct 2001, Olivier Deme wrote: > Thanks for the link to the demo application. > Indeed it seems that there a plenty of libraries to link with... > > Something also really annoying: > The libraries are located in an unusual place on my machine: > /usr/local/lib/python2.1/config/ > > Plus, the fact that libpython*.a has its version number in the file name. > That means that if our customer has a different version of Python, they > won't be able to link our application! > Usually, this should be solved by adding a symbolink link in a common > directory. Sonething like: > /usr/lib/libpython.a -> /usr/local/lib/python2.1/config/libpython2.1.a > > But this is not done during installation of Python. How are we supposed to know > the version used by the people who are going to build our application? I have found that out - the pygtk code includes autoconf (are you using autoconf) code that calls python (douh). (This is just an expert, be sure to review the entire file - acinclude.m4 from the pygtk distribution). changequote(<<, >>)dnl prog=" import sys, string minver = '$1' pyver = string.split(sys.version)[0] # first word is version string # split strings by '.' and convert to numeric minver = map(string.atoi, string.split(minver, '.')) if hasattr(sys, 'version_info'): pyver = sys.version_info[:3] else: pyver = map(string.atoi, string.split(pyver, '.')) # we can now do comparisons on the two lists: if pyver >= minver: sys.exit(0) else: sys.exit(1)" changequote([, ])dnl if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC The library can be found from constructions like the following py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"` PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}" There are standard places the library go, when you have the exec_prefix (I think). Linking is the great problem here (linker options). I found http://sources.redhat.com/ml/bug-autoconf/2001/msg00297.html (it is 4000 lines). Search for KDE_CHECK_PYTHON for how they test for some common linker requirements. It is a mess though. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk In a stinging rebuke, a federal judge Monday ruled Microsoft Corp. violated the nation's antitrust laws by using its monopoly power in personal computer operating systems to stifle competition. - CNN Financial News April 03, 2000: 7:53 p.m. ET From mail at fredriks.org Tue Oct 30 07:21:18 2001 From: mail at fredriks.org (Fredrik Stenberg) Date: Tue, 30 Oct 2001 13:21:18 +0100 Subject: Matlab-style mask in Python?? In-Reply-To: References: Message-ID: > Hi, > > I am a long time Matlab user. I just picked up Python for a short > while. > I wonder what should be the best way to do sth like: > > Matlab: > a=[3,4,6,7,2,54,2,1,2] > idx=a>4 ans: [0,0,1,1,0,1,0,0,0] > a(idx) ans: [6,7,54] > > Python: > a=[3,4,6,7,2,54,2,1,2] > idx=map(lambda x: x>4,a) #assume this calculation is lengthy > #and we don't want to repeat > last cmd??? > > While we can always put that into a for loop, then append the ans > element-by-element.... I feel there should be an easier way in > Python. > Any suggestions? > Hi Use filter, >>> filter(lambda x: x > 4, a) [6, 7, 54] You might wana look into numpy (http://www.numpy.org) if you want todo matlab-like stuff in python. /fredriks From a11w at SoftHome.net Fri Oct 19 13:34:07 2001 From: a11w at SoftHome.net (Jiba) Date: Fri, 19 Oct 2001 13:34:07 -0400 Subject: [Q] Python and machine learning References: Message-ID: <9qp3bs$8uf$1@front1.grolier.fr> Young-Jin Lee wrote: > Hi, I'd like to know if there's a python package for machine learning > (decision tree, neural net, and others). > Thanks in advance. > > YJ I've done a module about genetic algo; it is still not on the web but i must find the time to put it somewhere... I can send it to you if you want. Jiba From mwh at python.net Fri Oct 19 04:52:58 2001 From: mwh at python.net (Michael Hudson) Date: Fri, 19 Oct 2001 08:52:58 GMT Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> <9qk0p9$6tulc$1@hades.rz.uni-sb.de> <9qkfi0$6s3js$1@hades.rz.uni-sb.de> Message-ID: Guido van Rossum writes: > > Michael Hudson wrote: > > > > |>>> a = Numeric.array([1,2]) > > |>>> hash(a) > > | 56 > > |>>> d = {a:1} # a will be in the 56%8-th slot (in 2.2, anyway) > > |>>> a[0] = 2 > > |>>> hash(a) > > | 57 > > |>>> d[a] # looks in 57%8-th slot - which is empty > > | KeyError > > |>>> b = Numeric.array([1,2]) > > |>>> hash(b) > > | 56 > > |>>> d[b] # looks in 56%8-th slot - but what's there is not __eq__ to b! > > | KeyError > > > > | Moral: don't use mutable objects as dictionary keys. > > Hm. The Numeric.array object should not have defined __hash__ or > tp_hash. It's wrong if a mutable object defines a hash function, for > exactly this reason. I was making that interactive session up to show why mutable objects shouldn't define a hash function! Indeed, the OP was complaining that Numeric.array *didn't* define a hash function... (and then snipped out the bit of my post where I said I was making it up). circularly-ly y'rs M. -- we're already scrubbing the face of intuition with steel wool, setting it on fire, then putting it out with an axe . -- Tim Peters, on comparing recursive structures From skip at pobox.com Tue Oct 16 10:59:14 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 09:59:14 -0500 Subject: maximum recursion in "re" module? In-Reply-To: <200110161417.JAA17049@scortch.unisrv.net> References: <15307.35253.91335.661869@beluga.mojam.com> <200110161417.JAA17049@scortch.unisrv.net> Message-ID: <15308.19266.695456.27299@beluga.mojam.com> CJ> On Mon Oct 15 20:13:25 2001, Skip Montanaro wrote: >> CJ> startString = ".*?Lo Fi Play > ... CJ> mp3String = re.compile(startString, re.I).sub("", mp3String, 1) >> >> Why do you need the ".*?" part of the re? I'd try this: CJ> Well, basically what I want to go is get one URL out of the big CJ> mess o' HTML I'm trying to pull back. Okay, I must not have had my thinking cap on earlier. The fact that all you need is whatever follows the "Lo Fi Play..." stuff suggests that you should be able to locate it with simple string functions. Suppose you have your input in s and have defined startString = 'Lo Fi Play ' ' References: Message-ID: <01100111042501.14136@logiplex1.logiplex.net> On Monday 01 October 2001 10:07, Open Systems wrote: > > Whoa nelly. Can't let that fly. "...since it is the continuing > availability of the code, and variations on it, that the license > ensures". First of all Code that is BSDL'ed is ALWAYS available for the > user AND developer in the form it was released as BSDL'ed code. You *cant* True, but he also said "variations on" the original code as well, which BSDL doesn't ensure. > take it away any more then you can take back air on the planet and bottle > it all up and charge people for it. The second problem with the GPL is > your second point. "and variations on it" the GPL attempts to take and > take and take. It attempts to take code that doesnt belong to you. Like a > virus wrapping around healthy DNA it attempts to re-write the healthy DNA > with its own code "the GPL license" thereby freeing up the entire > application that uses any GPL code in it to also become available under > the GPL to infect more code out there, and to end binary only > distributions, and to do other evil things. So dont try saying the GPL is "other evil things"???? I'm going to skip that part, I'll read it on MSN later. > free. It is NOT free. And no one says buys that argument. I dont have a > problem with the GPL as long as you do not call it free code when its > applied to code. It's a bold faced lie. It's free, and you're free not to use it if you don't want your code to be free. It's called a trade-off. You get the combined efforts of thousands of GNU programmers to help you solve your problem, and in turn you provide your little bit of help back. I can definitely commiserate since I write proprietary applications in my workplace, but I can't complain, since whether to use GPL'd code is always *my* choice - not really very viral in any sense of the word. When was the last time you thought "Naw, I don't think I'll get the flu/code red this year." Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From skip at pobox.com Mon Oct 15 21:28:13 2001 From: skip at pobox.com (Skip Montanaro) Date: Mon, 15 Oct 2001 20:28:13 -0500 Subject: maximum recursion in "re" module? In-Reply-To: <15307.35253.91335.661869@beluga.mojam.com> References: <200110160056.TAA20412@scortch.unisrv.net> <15307.35253.91335.661869@beluga.mojam.com> Message-ID: <15307.36141.512386.241463@beluga.mojam.com> Skip> Why do you need the ".*?" part of the re? I'd try this: Skip> startString = "Lo Fi Play <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> <9r5h75$1m5$1@slb6.atl.mindspring.net> Message-ID: On Thu, 25 Oct 2001 01:17:31 +0000 (UTC), Huaiyu Zhu wrote: >On Wed, 24 Oct 2001 20:11:31 GMT, William Tanksley > wrote: >> >>I'm confused -- I don't see how your version can work either. Both of you >>are iterating over an empty list, and the only code which could possibly >>add anything to the list is inside the iteration; that list is empty no >>matter what, so nothing will execute, and the list will never be anything >>but empty. > >That's what that 'else' is for - and that's the whole point of this thread. >I have a suspicion that the usage of for-else in Python is not well known to >many discussants in this thread. > >The equivalent code is (note the duplication of primes.append(n)): > > def getprimes(x): > primes = [] > for n in range(2, x): > for p in primes: > if p*p > n: primes.append(n); break > elif n % p == 0: break > else: primes.append(n) > return primes > >Try it and see how it works. > > >>I don't like your "for x in list while y" construct, either. It's >>terrificly ambiguous: does it mean that every item in the list which meets >>the 'y' criterion will be processed, or does it loop over all the items up >>to the first one which fails to satisfy 'y'? > >So let me explain this in detail and hope I don't need to do it again. The >pseudo code was: > > def getprimes(x): > primes = [] > for n in range(2, x): > for p in primes while p*p < n: > if n % p == 0: break > else: primes.append(n) > return primes > >The 'for p' loop will exit under three conditions: >- p reaches end of primes: jump to (A) >- not p*p < n: jump to (A) >- n % p == 0: jump to (B) > >where > >(A) primes.append(n) >(B) pass > > >The juicy part of the code is: > > for p in primes while p*p < n: > if n % p == 0: break > else: primes.append(n) > >Note that the two different conditions corresponding to (A) are both >considered intuitively as "exhausted all the candidate factors". > >So the question is: is there a way to write the idea that two of the exits >go to the same follow-up code (A) without actually duplicating the code in >(A), or using a temporary variable to hold the state information? I have >not found a positive answer (which is not the same as claiming it does not >exist). In this particular case, there is, because the two exits to (A) can be combined into one test. I posted something like this to the other recent thread on primes. def getPrimesTill(x): # Based somewhat on primes.py from python cvs if x <=2: return [] primes = [2] for n in xrange(3, x, 2): for p in primes: if n % p == 0 or p * p > i: break if n % p != 0: primes.append(i) return primes However, this probably won't satisfy you for two reasons: 1) It's a special case - we have a known value we can use to initialize the list, and add code before the loop to handle that. 2) There's still code duplication. Instead of duplicating the primes.append(n) call, we're duplicating a comparison. >Of course, all of these could be easily done by using an auxiliary variable >found_factor which is set to true or false before different breaks, and >using an "if found_factor" after the loop. This has the advantage of generalizing to loops that exit under many possible conditions and have more than two possible results of those conditions - in other words, found_factor is not boolean. The problem with the syntax you described is simply that the conditions when it is useful are rather restrictive: 1) There must be more than one condition to exit the loop. 2) There must be *exactly* two possible behaviors upon loop exit. I suspect that #2 is likely to be a pretty fragile requirement for whatever you're testing. An example. Goldilocks wants to try some porridge. First a simple case that works well for your proposal. def taste1(porridges): """Taste porridges, and stop if just right, too hot, or no more.""" for heat in porridges while heat < 10: if heat == 5: print "Just right" break else: print "I don't want to try any more" Compare that with the boolean variable version you don't like: def taste2(porridges): """Taste porridges, and stop if just right, too hot, or no more.""" for heat in porridges: just_right = 0 if heat == 5: just_right = 1 break elif heat >= 10: break if just_right: print "Just right" else: print "I don't want to try any more" By comparison, it seems perhaps clunky. But now requirements have changed and Goldilocks needs to be more sensitive (and talkative)... and return the temperature of the last tasted bowl (or None if there are none). taste2 can be made to do all this just by adding to it: def taste3(porridges): print "Oh look! Porridge! Hope there are no bears here." for heat in porridges: print "Slurp slurp...", if heat < 0: print "Brrr! My tongue is numb, I can't taste anything else." break elif heat < 5: print "This porridge is too cold." elif heat == 5: print 'MMMM! Yummy.' break elif heat > 10: print "Ow! Burned my tongue. I'd better stop." break elif heat > 5: # or just 'else:' print "This porridge is too hot." else: print 'Rats. Nothing tasty here.' if porridge: return heat else: return None But can we keep it in your idiom and add all this functionality? Let's try. def taste3(porridges): print "Oh look! Porridge! Hope there are no bears here." for heat in porridges while 0 <= heat <= 10: print "Slurp slurp...", if heat < 5: print "This porridge is too cold." elif heat > 5: print "This porridge is too hot." else: print 'MMMM! Yummy.' break else: # Does this work??? if heat < 0: print "Brrr! My tongue is numb, I can't taste anything else." elif heat > 10: print "Ow! Burned my tongue. I'd better stop." else: print 'Rats. Nothing tasty here.' if porridge: return heat else: return None I don't care much for that (assuming it even works). We have to test for the boundary conditions twice: once in the 'while' conditions, once after the loop exits. That's probably more than enough blather out of me on this subject. -- Paul Winkler From gbeasley at tsa.ac.za Thu Oct 25 04:09:39 2001 From: gbeasley at tsa.ac.za (Grant Beasley) Date: Thu, 25 Oct 2001 10:09:39 +0200 Subject: Can 2 files import each other? (recursive) References: <9r8fqk$gm9$1@ctb-nnrp1.saix.net> Message-ID: <9r8hbc$ldk$1@ctb-nnrp2.saix.net> Sorry, found the FAQ. http://www.python.org/cgi-bin/faqw.py?query=import+modules&querytype=simple& casefold=yes&req=search Thanks "Grant Beasley" wrote in message > Can I have two Python files each importing the other, From rtrahan at monmouth.com Fri Oct 5 00:56:33 2001 From: rtrahan at monmouth.com (Richard Trahan) Date: Thu, 04 Oct 2001 21:56:33 -0700 Subject: partners/programmers wanted in NJ/NY/PA/CT Message-ID: <3BBD3D81.A753BC75@monmouth.com> I am a just-retired programmer in Monmouth County, NJ. I would like to network with experienced programmers in NJ/NY/PA/CT for the purpose of starting a porting business. You should be a guru in at least one freeware and one payware language and/or IDE and/or O.S. (e.g., {Perl,Java,Python,Forte,Linux} {C/C++,Delphi,VB,Windows}). Mostly telecommuting, depending on job. I am looking for working partners, not wage slaves. Absolutely no investment or other hitches. Visit my web pages at www.monmouth.com/~rtrahan and www.rockyboat.com. RSVP private email. From owen at astrono.junkwashington.emu Tue Oct 23 12:32:46 2001 From: owen at astrono.junkwashington.emu (Russell E. Owen) Date: Tue, 23 Oct 2001 09:32:46 -0700 Subject: Dictionary from list? References: Message-ID: <9r463e$2umq$1@nntp6.u.washington.edu> Thank you for a most mooving posting -- funniest I've read in a programming newsgroup in a long time. For what it's worth, I'm bullish on Chris Barker's suggestion of some way of converting list of keys, list of values to a dictionary. Like Chris, I've written my own and use it a fair bit. I have no opinion about converting the two proposed flavors of single lists to dicts (i.e. [key1, value1, key2, value2...] vs. [(key1, value1), (key2, value2)...]; they both sound useful, are both easy to implement via user-written functions, and if either is implemented as a built-in, then folks are likely to have a cow about the missing one. Regards, -- Russell In article , "Tim Peters" wrote: >[Andrew Dalke] >> Oh, don't get me wrong. I'm one of those anchors trying to slow >> the development of new core features in Python. (New libraries >> is a different thing.) If dictionary(list) stays an error you >> won't hear any complaints about me. > >I appreciate that. However, the builtin dictionary() cow has already >escaped the 2.2 barn, so the question now is whether we let it roam the >Python pasture with two broken legs, or put a spiffy sequence saddle on it >so you can gallop on it in comfort into the mooooonlight. > >> But I'm also one of those people who likes details -- (forest? >> tree? I like the BARK! :) > >grow-up-it's-a-cow-not-a-dog-ly y'rs - tim From brian_zhou at NOSPAMtechie.com Mon Oct 22 02:27:38 2001 From: brian_zhou at NOSPAMtechie.com (Brian Zhou) Date: Sun, 21 Oct 2001 23:27:38 -0700 Subject: a better prime number generator References: <23d58b26.0110210939.55bb7e0c@posting.google.com> Message-ID: <1003732032.597037@emperor.labs.agilent.com> The one comes with python source Demo/scripts/primes.py should be very fast. But just for fun, here is one more, using recursion and list comprehension: def primes(max): def sieve(l): if l[0] ** 2 > max: return l x = l.pop(0) return [x] + sieve([y for y in l if y % x != 0]) return sieve([2] + range(3, max + 1, 2)) -Brian "Rupendra Dhillon" wrote in message news:23d58b26.0110210939.55bb7e0c at posting.google.com... > hi all, > I have just been introduced to pyton and find it a very good ( takes > off all the bookwork ) language. I was trying to develope a ast prime > number generator. I designed the following algo. Can you please > suggest a faster one or modifications to this only to make it faster > > #the following algo returns all the primes below x > > def getPrimesTill(x): > a = range(2,x) > c = [2] > > i = 0 > j = 0 > > foundone = 1 > > while i < len(a): > while j < len(c) and (c[j] < (.5 * a[i]) ) and foundone == 1: > if a[i]%c[j] == 0: > foundone = 0 > j = j + 1 > if foundone == 1 and i > 0: > c.append(a[i]) > j = 0 > foundone = 1 > i = i + 1 > return c > > > roop From quinn at yak.ugcs.caltech.edu Tue Oct 9 17:42:59 2001 From: quinn at yak.ugcs.caltech.edu (Quinn Dunkan) Date: 9 Oct 2001 16:42:59 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 9) Message-ID: Here's a cool oracular python program. Impress your friends! http://groups.google.com/groups?hl=en&threadm=3bbaf6c9%240%24244%24edfadb0f%40dspool01.news.tele.dk Everyone knows about Zope, but there are a lot of other python HTML-writing solutions. Some people have collected links with quick overviews: http://www.paul.boddie.net/Python/web_modules.html http://webware.sf.net/Papers/Templates/ True to c.l.py tradition, a budding GPL war veers randomly off into an argument about the usage of apostrophe's: http://groups.google.com/groups?hl=en&oe=ISO-8859-1&threadm=9pn44q%24m1r%241%40tyfon.itea.ntnu.no (Would Strunk & White have liked Python? It's simple, clear, regular...) Gerhard maintains the python category at dmoz.org. Put it in your bookmarks next to www.vex.net/parnassus! http://groups.google.com/groups?hl=en&threadm=mailman.1002355626.16248.python-list%40python.org dmoz.org entry: http://dmoz.org/Computers/Programming/Languages/Python/Modules/ Zope vs. PHP for SQL-oriented sites? Cameron gives an even-handed (well, it *sounds* even-handed) answer. In brief, Zope is cool but the conceptual difficulty in getting the Zope Zen (this has been a problem ever since the beginning) can make it slow going for newbies until they get everything together. Followups note that efforts are underway to fix this with more and better documentation, and that the somewhat grotty DTML template language is being superseded by Page Templates, which are desgined to work well with HTML editors and separate the "page design" from the "add dynamic doohickeys" work: http://groups.google.com/groups?hl=en&threadm=B72B302E37066816.6331F170A093A2AF.D02BC798CFF1B3F5%40lp.airnews.net 2.2 will be coming out RSN, and those seeking details on all the spiffy (or feeping, depending on your point of view) new features are probably best served by http://www.python.org/2.2/descrintro.html ... but for those who want to see how they will fit into the main documentation (or who want to proofread it... you never know), the development docs have been updated: http://python.sourceforge.net/devel-docs/ ======================================================================== Everything 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 daily python url http://www.pythonware.com/daily comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect 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/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.de/oo_python.html Python FAQTS http://python.faqts.com/ 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://python.sourceforge.net/peps/pep-0042.html Python Journal is at work on its second issue http://www.pythonjournal.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python 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/topics/pythonurl/ 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 Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning, ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From charles at a3a.com.br Wed Oct 3 16:28:22 2001 From: charles at a3a.com.br (Charles) Date: Wed, 3 Oct 2001 16:28:22 -0400 Subject: mod_python Message-ID: <01100316282200.15833@magneto> Hi, I'm using mod_python on apache 1.2.30 linux and in http.conf i write the follows line in Directory AddHandler python-program .py PythonHandler mod_python.publisher Did not found any file.py that i was write in /www/docs/test/ ... I use the guide documentation in mod python site. But if i write PythonHandler file the /www/docs/tes/file.py will be executed Ps. Sorry about my english From chris at cogdon.org Tue Oct 2 14:00:17 2001 From: chris at cogdon.org (Chris Cogdon) Date: Tue, 2 Oct 2001 11:00:17 -0700 (PDT) Subject: Need help finding Python/TKinter Link Checker Message-ID: Some time ago I found a marvellous little web link checker, written in Python, and had an optional Tk interface which looked great for seeing what it was currently working on, what it had already checked and what was still left to do. However, it seems to have erased itself from existance; from my hard drive, software archive, and freshmeat. Does anyone know what it might be called, and where it might be located? I'm looking for the one with the Tk interface, not the CGI-based ones. TIA for any assistance. ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From f.groen at fokkerspace.nl Tue Oct 30 05:30:10 2001 From: f.groen at fokkerspace.nl (Frits) Date: Tue, 30 Oct 2001 11:30:10 +0100 Subject: Embedding Python in C/C++ Message-ID: <3BDE8130.CB1CE86B@fokkerspace.nl> I'm trying to find out wether Python is the answer to my problem. I want to write a C/C++ program wich takes a XML input. This input will also contain functions in a scripting language (python?), that can directly access objects in the main C program. Is this possible and can someone perhaps give me an example of something like this being done? I'm completely new to Python. Thanx in advance, arno baan From seb at tesco.net Mon Oct 29 18:36:24 2001 From: seb at tesco.net (seb) Date: Mon, 29 Oct 2001 23:36:24 GMT Subject: Multiple postings References: Message-ID: <3bdde77f.4166130@news.tesco.net> On Mon, 29 Oct 2001 07:07:10 -0500, "Steve Holden" wrote: >Sorry about the recent spate of duplicated postings. A glitch in my mail >server meant that it was accepting postings without telling my news client >they had been taken. > >regards > Steve >-- >http://www.holdenweb.com/ > > > > > Har, har. A post about duplicate posts being duplicated. Excellent. seb. From tegbert at abl.med.utah.edu Tue Oct 16 17:47:55 2001 From: tegbert at abl.med.utah.edu (Tim Egbert) Date: Tue, 16 Oct 2001 15:47:55 -0600 Subject: Extending Python - variable sized arrays? In-Reply-To: <9qi8f2$o0o9a$1@ID-75083.news.dfncis.de> References: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> <9qi8f2$o0o9a$1@ID-75083.news.dfncis.de> Message-ID: I'm developing a native method module for Python from some existing code. One function that I call returns an integer array that can be any size up to 128. Returning the array as a tuple using Py_BuildValue() is a problem because, although I can create the format string dynamically, I can't create a dymanically sized argument list. Maybe I'm just being dense, but I'd like to do something like this (illustrated here with a currently nonexistent function call, Py_BuildArrayTuple()): PyObject *ret; int *arr; ... (arr gets allocated and loaded with 6 values) ... ret = Py_BuildArrayTuple("6i",arr); return ret; which would be the equivalent of: ret = Py_BuildValue("iiiiii", arr[0],arr[1],arr[2],arr[3],arr[4],arr[5]); I can't go the Py_BuildValue() route because the problems is, the next time around, there may be 17 or 127 elements in the array, the exact number only to be known during runtime. Any thoughts on how to do this? Tim Egbert From skip at pobox.com Tue Oct 2 13:21:44 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 2 Oct 2001 12:21:44 -0500 Subject: list remove In-Reply-To: <20011002203427.D21313@phd.pp.ru> References: <1165F677B8C4D411B71C0008C791EC4A71E3AA@N0225IDC1.oss.level3.com> <20011002203427.D21313@phd.pp.ru> Message-ID: <15289.63400.199791.322099@beluga.mojam.com> Oleg> NEVER, I said NEVER modify the list while running through it! Never say "never". ;-) This works just fine: >>> foo = [1,2,3,4,5] >>> for i in range(len(foo)-1,-1,-1): ... del foo[i] ... >>> foo [] -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From webmaster at garymgordon.com Fri Oct 26 10:29:46 2001 From: webmaster at garymgordon.com (Gary M. Gordon) Date: Fri, 26 Oct 2001 09:29:46 -0500 Subject: Which one of our FREE website enhancements would you like? Message-ID: An HTML attachment was scrubbed... URL: From magnus at thinkware.se Wed Oct 24 12:58:41 2001 From: magnus at thinkware.se (=?iso-8859-1?Q?Magnus_Lyck=E5?=) Date: Wed, 24 Oct 2001 16:58:41 GMT Subject: Perl Range operator paradigm References: <3BCC0B8D.F4EFF59C@loria.fr> Message-ID: <1103_1003942721@nida> Den Tue, 16 Oct 2001 12:27:26 +0200, skrev Laurent Pierron : > Hello Gurus, > > In Perl there is a very powerful range operator '..', which, in scalar > context, is acting like line-range (,) operator in sed and awk. > > By example, this small program prints all the lines in the file included > between ... : > > while (<>) { > if (// .. /<\/BODY>/) {print; } > } > > How can I do, the same thing in Python ? If I understand this correctly, it's some kind of regular expression. /something/../otherthing/ is a non greedy match starting with something and ending with otherthing. A Python regular expression acts on a string, I don't think it can be contorted into keeping state while it's being fed a line at a time, but hey, we have virtual memory, right? Regular expressions are not a language element in Python but a library, just like so many else, so we start with import re, sys Apart from re (regular expressions) we need sys to access stdin (<>). Then we construct our regular expression bodymatch = re.compile(r'(.*?)',re.S|re.I) I'm not sure if this is exactly what the perl script finds. I'm not including the and tags, that would require you to write r'(.*?)' instead. re.S means that dot (.) will include also line breaks. re.I means ignore case, which is probably what you want with HTML. for line in bodymatch.findall(sys.stdin.read()): print line So, instead of three lines of code, you get four, and it looks more complicated (if you know perl), but on the other hand, if you had started with a Python example and asked "how do I do this in Perl" it might turn out in the same way. I don't know this perl concept, and it might be that these programs don't do quite the same thing, but I think that's just a matter of details in the regular expression. From pengo243 at hotmail.com Wed Oct 3 07:24:48 2001 From: pengo243 at hotmail.com (Mark Berry) Date: Wed, 03 Oct 2001 11:24:48 GMT Subject: Nicer Tkinter on UNIX? References: Message-ID: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> If you are looking for a very good looking interface on unix, you should go over to www.thekompany.com and take a look at the python bindings for QT. I spent one late evening playing with the QT interface designer. After understanding how to setup my own callbacks, etc I was able to write simple applications in minutes. It's actually not too far off from Tkinter in code implimentation and looks fantastic, at least as good as any QT based application. The only thing I am not sure about is the cross-platform usefulness. I don't think you will be Tkinter in this. Anyway, good luck and I hope you find what works best for you! :) On 3 Oct 2001 10:39:55 GMT, Artur Skura wrote: > >[It's not particularly Pythonish question, but I thought you might know] > >I like Tkinter because it's standard. But there is a big but. >While on Windows it looks great, on unices it makes kids laugh. >Not that it's particularly ugly, but quite awkward and not up to the >aesthetic standards people expect now. > >Is there a way to make Tkinter use KDE/GTK themes on unices? Or change the >interface in any way? (I don't consider wx... stuff, as it forces users to >install additional software). > >Regards, >Artur >-- >http://www.wolneprogramy.org From loewis at informatik.hu-berlin.de Sun Oct 28 04:58:09 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 28 Oct 2001 10:58:09 +0100 Subject: interpreter crashes References: <7xzo6cd1hw.fsf_-_@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Anyone got any suggestions? Want to see the core dumps? How > frequently does this type of thing happen? If Python is in the habit > of crashing randomly, that may make it inadvisable to write > long-running servers that need to stay up. Perhaps it's more > appropriate to write servers Apache-style, forking new processes and > reinitializing every so often. If you want to guarantee the service even in case of crashes (which may not necessarily be core dumps, but could also be uncaught exceptions), I'd recommend to put a super-simple watch daemon along with service; if the service stops, the daemon should restart it. In the service itself, assume it will run forever (until told to shut down from the outside). Also put another computer next to the first one, to detect when the entire computer crashes. Actually, don't put it next to it, but put it in a different country, to deal with power outages and loss of network connectivity :-) Regards, Martin From john at yates-sheets.org Tue Oct 2 09:16:45 2001 From: john at yates-sheets.org (John S. Yates, Jr.) Date: Tue, 02 Oct 2001 13:16:45 GMT Subject: scripting windows apps Message-ID: <48fjrtg51uhj34742lvpq1hmt87i26m4bg@4ax.com> I am considering building a test harness that would run VBA scriptable apps. I take it on faith that I can do this in Python rather than VBA. Any suggestions of where I should start looking will be greatly appreciated. /john -- John Yates 40 Pine Street Needham, MA 02492 781 444-2899 From tim.one at home.com Mon Oct 29 00:33:50 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 29 Oct 2001 00:33:50 -0500 Subject: Dictionary from list? In-Reply-To: <2uEC7.161518$5A3.57166879@news1.rdc2.pa.home.com> Message-ID: [Terry Reedy] > ... > To me, 'exactly 2' implies that dictionary() calls pair.next() a third > time and objects if it succeeds (as I believe it should, see below). > Presently true? It means that if len(list(iterable_object)) != 2, you get an exception about the length, while if len(list(iterable_object)) == 2 you do not. Exactly how "exactly two" is determined is not defined, because over-defining errot cases constrains the implementation in pointless ways. Tickling pair.next() a third time is one possible implementation. But, for example, if the iterable object happens to be a tuple or list, it would be a *silly* implementation to build an iterator at all, since tuples and lists store their sizes explicitly, and "exactly 2" is directly determinable for them (FYI, the current implementation does avoid building iterators for tuples and lists; maybe it won't be the time 2.2final is released, but "exactly 2" will remain the rule). ... >> class AddressBookEntry: >> # with .firstname, .lastname attributes >> ... >> def __iter__(self): >> return iter((self.firstname, self.lastname)) >> >> A sequence of AddressBookEntry instances is OK to pass to >> dictionary(), despite that an AddressBookEntry defines neither __len__ >> nor __getitem__. A generator yielding instances of AddressBookEntry is >> also fine; etc. > Here's the 'below' twice referred to above: Would AddressBookEntry > instances still be OK if the last line were, for instance, changed to > > return iter((self.firstname, self.lastname, self.address)) No; in that case you'd get a ValueError exception complaining that the number of elements produced by the iterator isn't exactly 2. Ditto if changed to return iter([self.firstname]) etc. > My point about a length of exactly two is a) the observation that > silently ignoring items beyond two is not consistent with the > processing of literals ('d={1:2:3}', for example, is a SyntaxError) > and b) my feeling that doing so would as often be wrong, creating a > silent bug, as right. Exactly so. > ... > Glad we agree ;<) Indeed, it appears unstoppable . From mjais at web.de Mon Oct 15 06:12:38 2001 From: mjais at web.de (Markus Jais) Date: Mon, 15 Oct 2001 12:12:38 +0200 Subject: python + xml performance compared to Java and C++ ?? Message-ID: hello does anyone have experiences how fast xml processing and XSLT processing with python (using PyXML and 4Suite tools) is, compared to Java and C++ (using the apache tools, like Xalan, Xerces....) any hints are welcome thanks in advance regards markus From emile at fenx.com Fri Oct 5 12:51:23 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 5 Oct 2001 09:51:23 -0700 Subject: How to tell when a file is closed References: Message-ID: <9pkomm$jc7ab$1@ID-11957.news.dfncis.de> I automated an app this year and ended up using: def waitForFile(fileName, waitForChange=1): print "in waitForFile waiting on %s " % fileName while 1: if os.path.isfile(fileName): break else: time.sleep(3) sStats = os.stat(fileName) time.sleep(3) while waitForChange: fStats = os.stat(fileName) if fStats != sStats: sStats = fStats time.sleep(3) else: break I certainly wouldn't depend on it in all cases, but it does what I need in this case. HTH, -- Emile van Sebille emile at fenx.com --------- "Peter Curran" wrote in message news:mailman.1002295686.29143.python-list at python.org... > Simple problem: I have an exe that creates a new file. I call this exe > from python with execfile, but I don't know how to tell when the exe I > called is finished writing its file. Without using any of the extra Win32 > modules, how can I tell when the exe is finished? Would os.path.isfile > work? Are there other utilities? If it helps, I'm actually doing this from > jpython -- maybe there's a java class that does this nicely? Any ideas out > there? > > Thank You! > > -Peter > > From tim at bladerman.com Wed Oct 31 15:09:20 2001 From: tim at bladerman.com (Tim Gahnström /Bladerman) Date: Wed, 31 Oct 2001 20:09:20 GMT Subject: PythonWin 2.1 saving bugg??? References: <7FUD7.3566$Z_1.627692@newsc.telia.net> Message-ID: > Still that "unlinking" seems like it should be fairly easy to "relink" if I > found where the file is lokated on the drive right? > Back in Dos days there was a program called undelete I think. > Maybe such things is around for w2k to... Guess I'll have do do some > websurfing... There is several undelete programs... I downloaded a few and they found a zillion different deleted files... but not mine!!! groar"#?"#!!! Got to do some working instead I guess :-(( Tim From gh_pythonlist at gmx.de Wed Oct 31 17:01:18 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Wed, 31 Oct 2001 23:01:18 +0100 Subject: crypt libraries In-Reply-To: <3BE07D46.7080502@shaw.ca> References: <3BE07D46.7080502@shaw.ca> Message-ID: <20011031230117.A350@lilith.hqd-internal> On Wed, Oct 31, 2001 at 10:38:03PM +0000, Peter Preeper wrote: > Are there any crypt libraries for python? I am looking for symmetric > type of encryption. http://www.dmoz.org/Computers/Programming/Languages/Python/Modules/Cryptography :-) Crypto modules can also be found on the "Vaults of Parnassus". Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From hrwire at lb.bcentral.com Tue Oct 9 17:58:02 2001 From: hrwire at lb.bcentral.com (HRWire) Date: 9 Oct 2001 21:58:02 -0000 Subject: H.R. Humour Message-ID: <1002664682.8868.qmail@ech> HR.Humour is brought to you by HR by the Hour! When is it "enough" employee survelliance? To view the cartoon related to this click : http://www.hr.com/hrcom/clickthru/clickthru.cfm?linkid=1024191003 Closing branches or departments? Re-evaluating staff competitiveness? Potential legal battles? The Exit Squad is an elite group of HR Professionals and consultants who can help you through the tough times: preparing exit strategies, outplacement programs, presenting termination notices and much more. Let us help you, visit http://www.exitsquad.com, or email sales at exitsquad.com. Symphire is transforming face-to-face recruiting. We use state-of-the-art Internet tools to source and identify candidates and mass amounts of local advertising. We currently have a number of offerings focused on Canadian Healthcare Professionals. Call toll free 866-836-6424 or email ldiflorio at symphire.com Steve Cabot presents: Managing Workers in the Age of "Big Brother" Comprehensive strategies for building productivity, avoiding litigation, and protecting employee rights in the face of exploding workplace technology. PHILADELPHIA November 2, 2001 BOSTON November 13, 2001 TORONTO November 20, 2001 HR.com Paid Members receive an additional $75 off. Call 877-472-6648, or email: seminars at hr.com. Need Advice, Support and Expertise... HR by the Hour is the perfect match for you HR by the Hour a new service designed for HR managers, SMEs, CEOs of small companies, or Line Managers. Three levels of service are available including: Basic Fact Finding Answers researched in our database, including forms, factual inquiries and articles. Examples: 1. What is the minimum wage in Arizona? 2. I need a good article on competencies. 3. I need a standard offer letter. 4. What does a typical grade structure look like? HR Services Services delivered by phone or email and provided by a personnel officer. Examples: 1. Writing Job Descriptions 2. Writing Policies and Procedures 3. Providing basic advice, e.g. Should I separate merit and cost of living increases or just lump them together? Expert Advice Service delivered by phone or email and provided by a senior HR consultant, or labor lawyer. Examples: 1. What should our pay policy be? 2. The IT manager wants to fire a staff member who was "disrespectful". What do I do? 3. Would a Balanced Scorecard help us? 4. Which Applicant Tracking Systems should we shortlist? 5. We're getting sued what should I do? Competitive rates starting at $45/hour. Pay as you go! For more information email sales at hrbythehour.com or visit http://www.hrbythehour.com >From the Humor Files Inspired by actual anecdotes from Professionals Dear Shirley B Nice: We dismissed an individual for misuse of our agency credit card - he was captured on a grocery security video using the card to buy his personal groceries. He was prosecuted and convicted. A few months later, he came to our offices, confronted his former department head, and said he'd like to work for us again. She candidly told him that she was not interested in employing him, but that he was free to apply for jobs in other departments. He said he would - he'd be interested in working in maintenance, a job that would give him "more independence" . . . should we rehire him? - Recruiter Dear Recruiter, Its natural to want to give him a second chance but you know my motto: "The proof is in the pudding" and this one has proven to be a bad egg. Never burn your bridges, end this relationship on a positive note and send him off with a handshake and foodstamps. - Shirley Shirley is the resident HR.com HR Manager. Shirley is ever so accommodating and tries to please everyone in the company. She sources faster than a speeding bullet, processes payroll with the accuracy of dart. Nothing phases Shirley she has seen it all in her career in HR. Shirley is happily married with 2 kids , 4 grandchildren and a pet dog named Rover. _______________________________________________________________________ Powered by List Builder To unsubscribe follow the link: http://lb.bcentral.com/ex/manage/subscriberprefs?customerid=15435&subid=1D9EFA5487350B93&msgnum=2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From guido at python.org Thu Oct 25 00:00:01 2001 From: guido at python.org (Guido van Rossum) Date: Thu, 25 Oct 2001 04:00:01 GMT Subject: urllib.urlopen + https = all threads locked? References: Message-ID: Gerhard H?ring writes: > In the meantime, this is a quick (untested) patch against current CVS > Python: [patch snipped] > > Is this a known problem? > > Unless it's reported as a bug with the Sourceforge bugtracker, it's not > a known problem <0.7 wink>. Gerhard, would you mind uploading that to SF? --Guido van Rossum (home page: http://www.python.org/~guido/) From Kuhn_Matthias at gmx.de Tue Oct 30 05:19:56 2001 From: Kuhn_Matthias at gmx.de (Matthias Kuhn) Date: 30 Oct 2001 02:19:56 -0800 Subject: re.findall()-Problem ? Message-ID: Hi, I have a question to re.findall(). In the sample-code below there is a teststring 's', where I want to find some tokens, preceding a number followed by a comma, e.g. '200,t' -> 't' The first re 'r1', finds the tokens 200 .. 241, in the second 'r2' I've added 250, so that it only finds the tokens in the first #BEGIN..#END-Block. When I run the sample-code the result of the findall() is correct, but there is a big difference in the elapsed time: r1: 0.0 sec (< 10 msec) r2: ca. 18 sec This is done with Python 1.5.2 on a PentiumIII(750MHz) under NT4.0(SP6). For Python 2.1 on the same machine the results are: r1: 0.0 sec r2: ca. 49 sec If I put the first #BEG..#END-Block at the end of the string the timing results are: r1: 0.0 sec r2: 0.0 sec That's what I've expected! Now my question, is there something wrong with my regular expressions or is there a problem with the re-module? Thanks for any advice Matthias import time import re s = """ #BEGINCHANNELHEADER 200,t 201,sec 202,sec 210,IMPLIZIT 220,724 240,0.0 241,0.007001 250,0.0 251,5.061844 #ENDCHANNELHEADER #BEGINCHANNELHEADER 200,CVI_P_Cal_FL 201,bar 202,bar 210,EXPLIZIT 211,vme____0.i16 213,BLOCK 214,INT16 220,724 221,1 222,72 240,0.000000 241,0.010000 260,Numerisch #ENDCHANNELHEADER #BEGINCHANNELHEADER 200,CVI_P_Cal_FL 201,bar 202,bar 210,EXPLIZIT 211,vme____0.i16 213,BLOCK 214,INT16 220,724 221,1 222,72 240,0.000000 241,0.010000 260,Numerisch #ENDCHANNELHEADER #BEGINCHANNELHEADER 200,CVI_P_Cal_FL 201,bar 202,bar 210,EXPLIZIT 211,vme____0.i16 213,BLOCK 214,INT16 220,724 221,1 222,72 240,0.000000 241,0.010000 260,Numerisch #ENDCHANNELHEADER """ r1 = '(?s)200,(\S+).+?202,(\S+).+?210,(\S+).+?220,(\S+).+?240,(\S+).+?241,(\S+)' r2 = '(?s)200,(\S+).+?202,(\S+).+?210,(\S+).+?220,(\S+).+?240,(\S+).+?241,(\S+).+?250,(\S+)' for r in r1, r2: a = time.time() l = re.findall(r, s) b = time.time() print 'elapsed Time: ', b-a for i in l: print i From warkid at storm.ru Wed Oct 24 09:21:29 2001 From: warkid at storm.ru ( Kerim Borchaev ( WarKiD ) ) Date: Wed, 24 Oct 2001 17:21:29 +0400 Subject: Can't copy iterator object Message-ID: <12723.011024@storm.ru> Hello, I'm not supposed to do so? This could be useful... Python 2.2b1 (#25, Oct 19 2001, 11:44:52) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> i = iter([1,2,3]) >>> import copy >>> copy.copy(i) Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\lib\copy.py", line 84, in copy y = _reconstruct(x, reductor(), 0) File "C:\Python22\lib\copy_reg.py", line 56, in _reduce state = base(self) TypeError: cannot create 'iterator' instances Best regards, Kerim mailto:warkid at storm.ru From michael at rcp.co.uk Thu Oct 25 11:55:51 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Thu, 25 Oct 2001 15:55:51 +0000 (UTC) Subject: Conditional expressions (again) References: <9r96tv$m26$1@thorium.cix.co.uk> Message-ID: gbreed at cix.compulink.co.uk wrote in news:9r96tv$m26$1 at thorium.cix.co.uk: > In article , > michael at rcp.co.uk (Michael Abbott) wrote: > >> Well, I don't really think there's a great deal of argument about the >> syntax. There are, as far as I'm aware, two live proposals for syntax: >> >> (1) x = if a: b elif c: d else: e >>or >> (2) x = if a then b elif c then d else e > > I don't remember "elif" being generally supported. It's true that noneone talked much about elif; I guess I'm making assumptions. However, once you've started there's no point at all in not supporting it. > Or a good argument against > x = b if a else (d if c else e) > > unless you count "P*rl has something like that" as a good > counter-argument. True, true. Personally, I hate it (as the most confusing option), but you're right, we should remember it as a third option (poo). > >> I seem to recall that Guido stated that he'd had a go at implementing >> syntax 2 (which I prefer if we're willing to pay the price of a new >> keyword 'then'), and that it worked well enough with the Python syntax. > > No "elif", and has to be parenthesised if it's used as a statement. Hmm. Well, that Guido may have forgotten to put in elif I'm sure was just a passing omission. That we need to put parentheses around (if a then b else c) as a statement by itself is strange at first sight (and my first reaction was "nonsense!" :), but thinking about it -- does it matter? Ok, we need the parentheses so that the parser knows that we aren't parsing an if statement, and certainly this is very surprising at first (as I say, my first reaction was to think that you were bringing up all that nonsense about requiring brackets around all if expressions). However, does this matter? It's a baby bleb, perhaps, but it's not going to hurt anyone, particulary as if expressions as statements are rather redundant! > > >> The main argument, really, seems to be about whether this is useful. > > Yes, there's that one as well. Ho hum, I expect it'll be the killer. From max at alcyone.com Wed Oct 24 16:13:23 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 24 Oct 2001 13:13:23 -0700 Subject: Curl-ing, anyone? References: <458b194a.0110241156.795e9618@posting.google.com> Message-ID: <3BD720E3.43791C55@alcyone.com> Resty Cena wrote: > Is Curl (www.curl.com) a threat to Python (and Ruby, and Perl)? Unlikely, for two reasons. First, the purpose that it exists for is already solved by other client-side technologies -- namely Java and JavaScript -- which are already almost universally available. Second, the licensing model they chose is an immediate turn-off, particularly when you note that those other preexisting technologies are free. Curl the language seems neat, but neatness alone doesn't make something a success. Curl the business doesn't sound too appetizing. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ All generalizations are dangerous, even this one. \__/ Dumas Fils Alcyone Systems / http://www.alcyone.com/ Alcyone Systems, San Jose, California. From rcriii at ramsdells.net Mon Oct 15 23:10:11 2001 From: rcriii at ramsdells.net (Robert C. Ramsdell) Date: Mon, 15 Oct 2001 22:10:11 -0500 Subject: TKinter PhotoImage Class?? - 2nd round Message-ID: <3bcba52b$1@server002.chicago.avenew.com> A while back Matthew Dixon suggested the following bit of code to display a jpeg on a Tkinter Canvas: from Tkinter import * import PIL.ImageTk r=Tk() i=PIL.ImageTk.PhotoImage(file="/home/rcriii/python/rempyre/tree32.jpg") c=Canvas(r) c.pack() c.create_image(16,16,image=i) r.mainloop() This works fine. However, in trying to adapt it for an application I have a problem. I have built the display in a class, with the Canvas as an attribute of the class, and a method to draw the image in the Canvas (code at the end of this message). When I try the method above in the method, the Canvas remains empty. No errror message is given, the image just is not displayed. Does anyone know why this is happening? import Tkinter from Tkconstants import * import PIL.ImageTk class display: def __init__(self): self.tk = Tkinter.Tk() self.drawspace = Tkinter.Canvas(self.tk, background="white") self.drawspace.pack() def mainloop(self): self.tk.mainloop() def draw_image(self, iname): self.drawspace.pack() i=PIL.ImageTk.PhotoImage(file=iname) self.drawspace.create_image(0,0,image=i) if __name__ == "__main__": m=display() m.draw_image("/home/rcriii/python/rempyre/tree32.jpg") m.mainloop() From epchaves at yahoo.com.br Mon Oct 8 15:15:42 2001 From: epchaves at yahoo.com.br (epchaves at yahoo.com.br) Date: Mon, 08 Oct 2001 19:15:42 -0000 Subject: python -i Message-ID: <9psu0u+mnj4@eGroups.com> Hi: My script are: __________________ import string a = string.lower("??????AAA") print a ____________________ if i do: python -i myfile.py the output is OK: ??????aaa but if i do: python myfile.py the output isn't the expected: ??????aaa Why? Best regards. Jorge M. From greg at cosc.canterbury.ac.nz Tue Oct 16 22:03:29 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 17 Oct 2001 15:03:29 +1300 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> <9psk9s$rbk@newton.cc.rl.ac.uk> <7x669o7r4k.fsf@ruckus.brouhaha.com> <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <7xsncpxxc6.fsf@ruckus.brouhaha.com> <1f186g5.wcfiwzcwvqv4N%news@davidglasser.net> <7x669jyr9b.fsf@ruckus.brouhaha.com> <3BCA573D.C636629B@cosc.canterbury.ac.nz> <7xbsj9a7jv.fsf@ruckus.brouhaha.com> Message-ID: <3BCCE6F1.68687D7A@cosc.canterbury.ac.nz> Paul Rubin wrote: > > The last item processed in that case is the last item processed by > a previous run of the program. What if the program hasn't been run before? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From ignacio at openservices.net Thu Oct 11 16:17:26 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 11 Oct 2001 16:17:26 -0400 (EDT) Subject: help: Crossplattform audio functionality in Python In-Reply-To: Message-ID: On Thu, 11 Oct 2001, Paul Winkler wrote: > Another option, though no python bindings exist yet: Portaudio, > see http://www.portaudio.com libao supports more audio platforms than PortAudio as-is, and ao-python (Python bindings for libao) exists already. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From michael at rcp.co.uk Mon Oct 15 02:54:00 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Mon, 15 Oct 2001 06:54:00 +0000 (UTC) Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: "Rainer Deyke" wrote in news:ooty7.61655$w62.37584078 at news1.denver1.co.home.com: > Actually, it would probably be possible to make the parens optional in > all cases except where 'if' is the first token of the expression. > > x = if a then b else c # legal > if a then b else c # syntax error > > The required changes in the grammar are quite small: > > 1. Replace all rhs instances of "testlist" with "any_expression", > *except* the first one in "expr_stmt". > 2. Add the following production: "any_expression: testlist > | 'if' any_expression 'then' any_expression 'else' any_expression". Yes! And in this particular case it really doesn't matter anyway, since an isolated if expression is indistinguishable in effect from an isolated if statement. Oh, while we're being concrete about the syntax, don't forget to allow elif in conditional expressions! From scott.nadeau at sanmina.com Wed Oct 31 11:41:53 2001 From: scott.nadeau at sanmina.com (Scott Nadeau) Date: Wed, 31 Oct 2001 11:41:53 -0500 Subject: Python 1.5.2 -- assigning current time to a variable? In-Reply-To: <20011031192801.L21151@phd.pp.ru> Message-ID: <000201c1622a$f320b500$9d0814ac@sanmina.com> Thank you Oleg. I should have figured that out on my own. Scott -----Original Message----- From: Oleg Broytmann [mailto:phd at phd.fep.ru] On Behalf Of Oleg Broytmann Sent: Wednesday, October 31, 2001 11:28 AM To: scott.nadeau at sanmina.com Cc: python-list at cwi.nl Subject: Re: Python 1.5.2 -- assigning current time to a variable? On Wed, Oct 31, 2001 at 04:24:50PM -0000, scott.nadeau at sanmina.com wrote: > timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) > > Yields: > TypeError: function requires at least one argument > > How do I pass the argument? timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From parker at gol.com Mon Oct 15 03:33:02 2001 From: parker at gol.com (Ian Parker) Date: Mon, 15 Oct 2001 07:33:02 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <7xhet39ckb.fsf@ruckus.brouhaha.com> Message-ID: <5Yj3PDAchoy7Ewjn@gol.com> In article , Tim Peters writes >[Tim] >> If people sign off on taking "then" as a new keyword, I think >> the chances are good that we could get >> >> x = if e1 then e2 else e3 >> >> into 2.2b1. That's the only obvious spelling, hence the only >> truly Pythonic way to spell it. Other languages spelling it that >> way range from Algol-60 (Guido's first intense language affair) to >> Haskell. > >[Paul Rubin, among others of similar mind] >> This sounds fine to me. > >Alas, it didn't to Python's parser -- one-token lookahead isn't enough to >distinguish > > if 1: > >from > > if 1 then 2 else 3 > >let alone > > if a + b / c: > >from > > if a + b / c then 2 else 3 > >etc. > >and Python won't grow anything a simple parser can't sort out. > >Everything's cool if parens are required around a conditional expression, >though, in which case: > > x = if e1 then e2 else e3 + 1 # SyntaxError > x = (if e1 then e2 else e3) + 1 # cool > x = (if e1 then e2 else e3 + 1) # cool > x = if e1 then e2 else e3 # SyntaxError > x = (if e1 then e2 else e3) # cool > x = if if e1 then e2 else e3 then e4 else e5 # SyntaxError > x = (if (if e1 then e2 else e3) then e4 else e5) # cool > >Seems a mixed bag, but I'm more interested in readability and the >functionality than in minimizing keystrokes; requiring parens doesn't hurt >the goals I care about. > >implemented-but-not-checked-in-ly y'rs - tim > > Presumably this wouldn't lead to any misleading syntax error identification problems with multiple lines? For example multi-line versions of these new 'if' expressions, or where a trailing '{' has been left at the end of a line preceding a normal 'if' statement. Would sensible syntax errors and line numbers still be reported? Not that I leave many trailing "("s. but if I were to do so, I'd like to have as much help as possible tracking them down. -- Ian Parker From paoloinvernizzi at dmsware.com Thu Oct 11 12:54:13 2001 From: paoloinvernizzi at dmsware.com (Paolo Invernizzi) Date: Thu, 11 Oct 2001 16:54:13 GMT Subject: Borg Pattern Class usable from other classes? References: Message-ID: er, shouldn't it be called a singleton? Alex can kill you for this ;)) > Having hacked around with it I can only conclude that when called from > within a different module, the Borg class statement is re-evaluated, and > "__s = {}" is re-evaluated. That doesn't make any sense though, so I must > be wrong. __s is certainly empty when called from Test.__init(), but I > don't know why. I hope that this can help you... # a.py class Borg: __s = {} def __init__(s): s.__dict__ = s.__s if __name__ == "__main__": print "a.py id(Borg)->",id(Borg) a = Borg() a.t = "Huba" print "a", a.t b=Borg() print "b", b.t import b d=b.Test() # b.py import a class Test: def __init__(s): print "b.py id(a.Borg)->",id(a.Borg) c = a.Borg() if hasattr(c, 't'): print 'c', c.t else: print 'c has no t' ---------------------------------------- C:\temp>python a.py a.py id(Borg)-> 8800452 a Huba b Huba b.py id(a.Borg)-> 8812652 c has no t ----------------------------------------- So, in the second module you have to use something like.. ----------------------------------------------------- # b.py from __main__ import Borg class Test: def __init__(s): print "b.py id(Borg)->",id(Borg) import pdb; pdb.set_trace() c = Borg() if hasattr(c, 't'): print 'c', c.t else: print 'c has no t' ---------------------------------------------- C:\temp>python a.py a.py id(Borg)-> 8800452 a Huba b Huba b.py id(Borg)-> 8800452 c Huba ------------------------------------------------ At the end of the story: namespaces and import statement are not always so intuitive as they seem Paolo Invernizzi From andreas at mtg.co.at Thu Oct 18 06:40:55 2001 From: andreas at mtg.co.at (Andreas Kostyrka) Date: Thu, 18 Oct 2001 12:40:55 +0200 Subject: Converting a tuple to an argument list for a method? In-Reply-To: <1262235424.20011018114754@buz.ch> References: <1262235424.20011018114754@buz.ch> Message-ID: <200110181041.f9IAf0a05232@lap1.mtg.at> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am Donnerstag, 18. Oktober 2001 11:47 schrieb Gabriel Ambuehl: > Hello, > I'm messing with the XMLRPC implementation from PythonWare which > makes the arguments to the request available as tuple but the > method's > I want to call expect a normal argument list as their parameters. > import string list=["1","2","3"] args=(list,", ") print apply(string.join,args) Andreas - -- Andreas Kostyrka; Raiffeisenstr. 16/9; 2320 Zw?lfaxing Tel: +43/676/4091256; Fax: +43/1/7065299 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.5 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE7zrG6HJdudm4KnO0RAk/PAJ4thNN+ziJDplmDI6w1SFcvc8Vb/ACg0VJy gsItHkwbjLVdzBpKL4mnCmo= =05vY -----END PGP SIGNATURE----- From brueckd at tbye.com Wed Oct 24 22:56:34 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 24 Oct 2001 19:56:34 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: <01102414233702.24656@logiplex1.logiplex.net> Message-ID: On Wed, 24 Oct 2001, Cliff Wells wrote: > > I was merely responding to somebody's not-entirely-true assertion that > > "_every_ access to that [shared] resource _must_ be enclosed in locks". > > My assertion may not have been entirely true, but more useful to someone > trying to learn threading than a discussion on the esoterics of which Python > statements may or may not be atomic =) I do see your point, but I think of it from the opposite point of view: a newbie learning about threads would be thrilled to get a simple producer/consumer program working to play around with. Once they see how cool it is, then you move on to teaching them about locking problems, mutexes, etc. And hopefully, they played with it enough already to get bitten by a problem so that they really understand the lesson. I think it discourages newbies to bombard them with all the locking issues up front, and it's a real strength of Python (especially for programming newbies) that you can often "get away" with no explicit thread-safety measures. Were your first multithreaded programs threadsafe? Mine sure weren't. But it was okay because at that point it was much more important to get something working. This is no different than any of the other newbie-friendly aspects of Python (no type decls, no memory management, etc.) - people can get up to speed quickly because they do have to get overwhelmed with the details all at the start. -Dave From jim at publishingresources.com Wed Oct 17 15:25:52 2001 From: jim at publishingresources.com (Jim Abrams) Date: Wed, 17 Oct 2001 19:25:52 -0000 Subject: PythonWin ASP performance References: <7a7a07a.0110170719.7a347008@posting.google.com> Message-ID: afaus at corp.vlex.com (Angel Faus) wrote in <7a7a07a.0110170719.7a347008 @posting.google.com>: > Hi to all, > > I work in a project that has already a significative investment in ASP > (vbScript) and COM development. > > We are already using Python in some parts of the development and we > love it. > > But current Python+ASP development has ocurrend in backend tools that > support a moderate level of traffic. We are afraid that using Python > instead of vbScript in "key" parts of the site (that support >70% of > our traffic, and our total traffic is not small) could be bad for > perfomance. > > So de question is: ?is Python slower than vBscript in ASP? > and more important: ?does Python+ASP scale well, or does it generate > nasty conditions when used intensively? > > and finally: ?is it mixing Python and vBscript in the same page slower > or more problematic than just using Python? > > Thanks in advance, I think you'll be much better off using Python. I can't give you any hard data comparisons (since I abandoned VB long ago) But our python ASP pages scale very well (at least under the load-testing we do). And back in the day when I wasn't much of a Python programmer, my python pages were still faster than my VBscript pages (and usually about 1/3 to 1/2 as long). Using Python makes life easier in so many ways I can't even begin to describe them all, but some of the main ones are the object oriented approach. (We've encapsulated the ASP Built-in objects with Python wrappers that solve alot of VBscript ickiness, and are subclassable) DB access is faster using ADO, (we actually use win32com.client.Dispatch rather than Server.CreateObject, anyone know why Dispatch is faster?) The Python library gives untold of power over VBScript. With all the additional power Python gives you, as well as still being able to utilize COM pieces, I usually ask myself, "Why us VBscript at all?" Lastly, mixing script languages in a single page is usually a bad idea. There's a MS KB article that describes it (only talks about Jscript and VBscript tho), but IIRC, the order the script blocks are executed isn't always defined and you're instatiating 2 script engines for the page rather than 1. Check the KB for more info. Hope this was of some help, J From gabriel_ambuehl at buz.ch Wed Oct 17 05:35:31 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Wed, 17 Oct 2001 11:35:31 +0200 Subject: SOAP.py Message-ID: <111175092229.20011017113531@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello, I'm desperately seeking for a working SOAP implementation but so far, I haven't had much look. The PythonWare one is somehow broken so that it won't generate exception but just throw useless errors after me, I couldn't get the ZSI one to do anything at all and now I'm fooling around with SOAPpy097 which at least will load, but as soon as I try to execute the cardServer.py/cardClient.py example in the tests/ directory the server complains about :1:36: Unsupported encoding 'UTF-8' and only more responds with errors to all requests from the client (this is Python 2.1.1 on FreeBSD 4.4). What's wrong? Is there any working, easy to adapt SOAP implementation for Python or should I give it up and dig into XMLRPC? Best regards, Gabriel l@?hd? -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO81C18Za2WpymlDxAQGHVggAytxrUy2IEBBV1oUlz/ZqJwpMy5JuG8ub GfYQ7KGITTz15Klu+nq3cKfSvRj4S9Ou87/eS9XewWrSmw5Dgr3+PwUtyAuddzif 2cp/RjmITCcxbKgGkI+6qUwPv/TL3Aj0wx27Kn3oue+jEj86wnYTVR5RUnV9bPG2 FQgZK6kRKsdU6Iu6qm7Emz7BGxpcvEIOIfKqvIHMhWPYO1RCSSa9L+2+gMDfGuCN t+P4K7OXJVh6utvBI/IdFX5umi8/IgEV9vqaRsGnn84wl7oNCAEBmCmmOLcb1zas y+zntPTNJg2Q0pVhG9/vQOBSzNl0/Sv4fQA8t3r4sUbHJ9VYogjpZw== =h3B7 -----END PGP SIGNATURE----- From phd at phd.pp.ru Tue Oct 16 11:18:19 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 16 Oct 2001 19:18:19 +0400 Subject: HTML Application Interface In-Reply-To: <42256AE7.00531BCE.00@JHBMAIL01.edgars.co.za>; from CpJohnson@edgars.co.za on Tue, Oct 16, 2001 at 06:08:10PM +0300 References: <42256AE7.00531BCE.00@JHBMAIL01.edgars.co.za> Message-ID: <20011016191819.I768@phd.pp.ru> On Tue, Oct 16, 2001 at 06:08:10PM +0300, CpJohnson at edgars.co.za wrote: > I will be writing a Python application to run stand-alone on a PC. Just to be > different, I came up with the idea of using an HTML interface instead of > something more conventional like Tkinter. So the user interaction with the app > would be via a web browser and input via CGI etc. > > I wondered if there is an application framework that would be suitable. I took > a quick look at Zope, and think that it would serious overkill to use it for my > 5 form app. > > Anything else out there? You are not different! :) There are many people who do it exactly this way. There are many python web-application servers out there: http://skunkweb.sourceforge.net/ http://webware.sourceforge.net/ http://www.mems-exchange.org/software/quixote/ http://www.twistedmatrix.com/ See an overview on http://www.paul.boddie.net/ Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From dale at riverhall.NOTHANKS.co.uk Tue Oct 16 09:55:30 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Tue, 16 Oct 2001 14:55:30 +0100 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <7xhet39ckb.fsf@ruckus.brouhaha.com> Message-ID: For several of the reasons posted in reply to this, I don't rate this idea very highly - as it stands, at least. Although, something of this type would be an advantage. As it stands, it's too verbose, the mandatory parenthasese are an ugly cludge and the requirement for the 'then' in what is supposed to be a shorthand is unnatural. I favour the suggestion of the one-liner - if the parse can cope with it: a = if e: b else c: But I can't see how this helps with the loop and a half problem, as I've mentioned in a new thread. -- Dale Strickland-Clark Riverhall Systems Ltd From fredrik at pythonware.com Sun Oct 28 04:43:22 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 28 Oct 2001 09:43:22 GMT Subject: binary search tress using classes References: Message-ID: <_qQC7.2686$R43.471499@newsb.telia.net> Terry Reedy wrote: > The way to do this in Python is with a dictionary. Without being > fancy about the definition of 'word', you need 10 lines or less for > the whole program. I believe I've seen the code posted. text = """ Have a nice day. Have a nice day. Have a nice day. Have a nice day. """ import re # count the words count = {} for word in re.findall("\w+", text.lower()): count[word] = count.setdefault(word, 0) + 1 # print the result items = count.items() items.sort() for k, v in items: print k, v > Using classes and 'modularity' is way overkill. better tell that to her teacher ;-) From com-nospam at ccraig.org Wed Oct 17 08:23:44 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 17 Oct 2001 08:23:44 -0400 Subject: Conditional Expressions don't solve the problem In-Reply-To: <7xr8s2zo57.fsf@ruckus.brouhaha.com> References: <7xr8s2zo57.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Having to split it into several statements clutters up the code and > makes the readability WORSE by moving the test condition away from the > 'while' keyword. Do you REALLY find > > while (line := file.readline()) != 'end': > process_line(line) > > to be less readable than > > while 1: > line = file.readline > if line == 'end': break > process_line (line) No, but I find both much less readable than # Python 2.2+ for line in file: if line=='end': break process_line(line) or # Python 2.1+ for line in file.xreadlines(): if line=='end': break process_line(line) > The .py files in the standard library aren't really the right place to > look. They were written without those constructs and the authors may > have formulated particular pieces of code in ways considerably > different than if they had conditional expressions available (as > opposed to just splitting the expressions into a few statements). > > It's better to scan through the C code of the interpreter and the > library C modules, rather than the .py files, and see how many places > ?: and assignments in expressions are used. But that doesn't give you a good feeling for how much conditional expressions help readability. As the above examples show, just because something makes sense in C that doesn't mean it makes sense in Python. Also if the lack of conditional expressions causes authors to formulate code in such a way that adding them does not increase readability, that is strong support for leaving them out. I agree with Guido. If there aren't a significant number of places where conditional expressions will benefit the readability of the standard library, there probably isn't sufficient reason to make the change. -- Christopher A. Craig From christophertavares at earthlink.net Tue Oct 30 14:48:22 2001 From: christophertavares at earthlink.net (Chris Tavares) Date: Tue, 30 Oct 2001 19:48:22 GMT Subject: How smart are Semaphore Objects? References: <32cedc66.0110292253.5eaaca31@posting.google.com> Message-ID: "Matthew D. Wood" wrote in message news:32cedc66.0110292253.5eaaca31 at posting.google.com... > I firmly believe that when coding a function, object, program or > whatever, one should assume that every other function, ... is either > stupid or out to get you. With this mind-set, I'm curious as to how > (idiot or mean-person) proof semaphore objects are. > > Threading.Semaphore. > > If a class can't acquire a semaphore, or doesn't bother, can it > release it, despite not owning it? > > It's almost a security thing. I want in, and so, I will release the > semaphore, repeatedly if necessary, until I get in. > [... snip ...] There's two factors that complicate the way you're looking at this. 1) Semaphores only work if everyone plays by the rules. If you've got a thread that's going to go straight to some resource and just not bother calling the semaphore wait function, there's nothing you can do to stop it regardless. 2) Semaphores are used for more than just mutual exclusion. For another common use, think of a thread-safe message queue. It's fairly common to initialize the semaphore with a count of the number of messages currently available in the queue. The reader threads will decrement the count, and separate writer threads will increment it. If a separate thread isn't allowed to release a semaphore, this very common usage wouldn't work. So, I'm afraid you win some and you lose some. If you're on the windows platform, you might want to consider using the win32 native syncronization objects (particularly critical sections and mutexes) rather than python semaphores - they have the kind of behavior you're looking for, since they don't need to be so general. -Chris From paul at boddie.net Tue Oct 16 12:24:26 2001 From: paul at boddie.net (Paul Boddie) Date: 16 Oct 2001 09:24:26 -0700 Subject: FW: [Python-Dev] conditional expressions? References: Message-ID: <23891c90.0110160824.6a5a0c1b@posting.google.com> Anthony Baxter wrote in message news:... > Ok, so we're getting yet another ugly hack added to the language. > Could the normal process of writing up a PEP be followed, so that > those people in the community who are uncomfortable about it can > at least see the justification for this? Indeed, it would be interesting to see the justification for conditional expressions, apart from the fact that "it can be done", of course. Given time, we all accept change. I accept now that the division reform was probably necessary due, in part, to some bizarre behaviour that I uncovered recently that I hadn't stumbled across before, notably the fact that with integers... -a / b == -(a / b) ...is not true for all values of a and b. One might have expected that to be the case, but Python's rounding rules actually prevent it from being so; indeed, the only mention of such rules that I could find appeared on the PEP proposing the changes. (You can tell that I don't mess around that much with integer arithmetic in the code I write, but seeing this made me see the case for the division reform.) In the case of division, however, backwards compatibility was my principal concern and, in fact, I'm not particularly bothered about this change, but then I can imagine some nightmare code which this permits. Still, some people have already openly wondered about the usefulness of implementing countless "ugly hacks" when more interesting or "necessary" challenges exist, particularly in the area of searchable module catalogue services, to name one recent "hot topic"... Paul From phr-n2001d at nightsong.com Sat Oct 13 20:55:28 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 13 Oct 2001 17:55:28 -0700 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> <9psk9s$rbk@newton.cc.rl.ac.uk> <7x669o7r4k.fsf@ruckus.brouhaha.com> <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <7xsncpxxc6.fsf@ruckus.brouhaha.com> <1f186g5.wcfiwzcwvqv4N%news@davidglasser.net> Message-ID: <7x669jyr9b.fsf@ruckus.brouhaha.com> news at davidglasser.net (David Glasser) writes: > > Just today I had a bug that went something like: > > > > n = compute_number_of_items() > > for i in range(n): > > try: process_an_item(items[i]) > > except: break > > update_database('number of items processed = ' % i) > [but for n = 0, i never gets defined] > > I'm confused. Won't this give the wrong answer, anyway? If you do > process all n correctly, i will be set to n-1. So you'll have to log > "i+1". And by this point you might as well just increment a variable > every time you process an item correctly, which is a lot clearer than > using the value of a loop index outside of the loop, in my opinion. In that example it should have said range(1,n+1), I guess. The actual code with the bug worked a little bit differently-- the example just abstracted it, incorrectly it turned out. (The real code stored the number of the last item processed, not the number of items processed, and originally read the number from the database). From j.spies at hccnet.nl Wed Oct 17 16:41:48 2001 From: j.spies at hccnet.nl (Jaap Spies) Date: Wed, 17 Oct 2001 22:41:48 +0200 Subject: PyNOVAS (Python & NOVAS) 0.1a {should be on comp.lang.python.announce) Message-ID: <3BCDED0C.1030009@hccnet.nl> Hi, If you are a sailor with interest in celestial navigation or an (amateur)astronomer who wishes to compute the position of the Moon in a sub-meter precision or if you want to make your own 'Astronomical Almanac', please checkout: http://pynovas.sourceforge.net/ See for your information: http://aa.usno.navy.mil/software/novas/novas_info.html http://ssd.jpl.nasa.gov/eph_info.html Jaap Spies From jhauser at ifm.uni-kiel.de Sun Oct 14 14:03:43 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 14 Oct 2001 20:03:43 +0200 Subject: Troubles with global variables References: <87r8s4vmgy.fsf@toadmail.com> Message-ID: <87elo6cd4w.fsf@lisboa.ifm.uni-kiel.de> Perhaps something else is wrong, the following does show the changes, and please take this not an elegant example for a selection menu :-). HTH, __Janko #!/usr/bin/env python import os a='some string' b='some other string' def changea(): global a a = raw_input('What is the new value of "a"? ') def changeb(): global b b = raw_input('What is the new value of "b"? ') def menu(): global a,b while 1: os.system('clear') print 'a = %s\nb = %s\n\n' % (a,b) print 'Menu: \n1) Change a: foo\n2) Change b: bar' wants=raw_input('type 1 or 2 to change values, q to quit: ') if wants == '1': changea() elif wants == '2': changeb() elif wants == 'q': print 'bye' break else: print 'wrong input' if __name__ == '__main__': menu() -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From fdrake at acm.org Fri Oct 19 16:46:13 2001 From: fdrake at acm.org (Fred L. Drake, Jr.) Date: Fri, 19 Oct 2001 16:46:13 -0400 Subject: Python documentation for iSilo Message-ID: <15312.37141.139330.26322@grendel.zope.com> I've re-worked the iSilo version of the documenation for the first beta of Python 2.2; each manual is now a separate document for iSilo, so you can pick & choose the documents you need. They are also smaller than the first test version (by about 1/3 of a megabyte), which is a nice savings. This version includes a few post-beta documentation fixes. To try it out, download the file isilo-2.2b1+.zip from: ftp://ftp.python.org/pub/python/doc/2.2b1/ Please send comments on this version of the docs to me at: python-docs at python.org Enjoy! -Fred -- Fred L. Drake, Jr. PythonLabs at Zope Corporation From logiplexsoftware at earthlink.net Wed Oct 10 12:41:35 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 10 Oct 2001 09:41:35 -0700 Subject: TROJAN ALERT! (JS/Loop) In-Reply-To: <038201c15127$fa3905e0$e4cfbfa8@kens> References: <01100912310503.02876@logiplex1.logiplex.net> <038201c15127$fa3905e0$e4cfbfa8@kens> Message-ID: <01101009413500.04263@logiplex1.logiplex.net> On Tuesday 09 October 2001 18:07, Ken Seehof wrote: > Oh. Like Windows? I didn't want to mention any names ;-) -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From wberger at ccil.org Wed Oct 10 10:26:07 2001 From: wberger at ccil.org (William Wonneberger) Date: Wed, 10 Oct 2001 14:26:07 GMT Subject: Problems With ColourSelect Box Inside A wxDialog References: <9e7d101d.0110081223.32a8217e@posting.google.com> Message-ID: <7hm8st4ul1p0i93r8ut2bpmetm8k7p7q6s@4ax.com> On Tue, 09 Oct 2001 23:44:32 -0000, Robert Amesz wrote: Hi, Robert; Thanks for taking the time to look into this problem. >> I'm trying to add a wxPython ColourSelect control to a wxDialog box >> inside a Python script I've been working on. To instantiate the >> ColourSelect control, I've added the following statement to my >> Python script; >> >> self.colorselect = ColourSelect(self, wxPoint(70, 200), [0, 0, >> 110], wxDefaultSize) > I restored the original version of the ColourSelect.py module, and called the statement as specified above, and still the ColourSelect control was not displayed inside the dialog box. >That isn't much context to work on. There are a number of "psychic >debuggers" in this ng, but I'm not one of them. > > Sorry 'bout that. The following is the Python class for my dialog box; class wxPlotterSettingsDialog(wxDialog): def __init__(self, parent): wxDialog.__init__(self, parent, -1, "wxPlotter Settings", wxDefaultPosition, wxSize(350, 200)) self.static = wxStaticText(self, -1, "Number of points to draw: ", wxPoint(70, 22)) self.linesSpin = wxSpinCtrl(self, 20, "", wxPoint(200, 20), wxSize(55, 20)) self.linesSpin.SetRange(1, 360) self.linesSpin.SetValue(parent.lineCount) self.static = wxStaticText(self, -1, "Line Color: ", wxPoint(70, 50)) # self.colorselect = ColourSelect(self, wxPoint(70, 200), [0, 0, 110], wxDefaultSize) self.colorselect = ColourSelect(self, -1, [0, 0, 110], wxPoint(70, 200), wxDefaultSize) self.static = wxStaticText(self, -1, "Background Color: ", wxPoint(70, 75)) self.static = wxStaticText(self, -1, "Line Ending: ", wxPoint(70, 102)) self.lineEnding1 = wxRadioButton(self, 25, "Rectangle", (140, 100)) self.lineEnding2 = wxRadioButton(self, 26, "Circle", (215, 100)) self.lineEnding3 = wxRadioButton(self, 27, "None", (270, 100)) self.button = wxButton(self, wxID_OK, " OK ", wxPoint(95, 140), wxDefaultSize).SetDefault() self.button = wxButton(self, wxID_CANCEL, " Cancel ", wxPoint(175, 140), wxDefaultSize) EVT_BUTTON(self, 2001, self.OnOK) EVT_SPIN(self, 2002, self.OnPointsSpin) def OnOK(self, event): self.wnd.Stop() self.EndModal(wxID_OK) def OnPointsSpin(self, event): print "Spin control selected." def GetLines(self): return self.linesSpin.GetValue() def GetLineEnding(self): print "lineEnding1 = ", self.lineEnding1.GetValue() print "lineEnding2 = ", self.lineEnding2.GetValue() print "lineEnding3 = ", self.lineEnding3.GetValue() return 0 Any other insights you may have on this problem would be greatly appreciated... Bill Wonneberger wberger at ccil.org From skip at pobox.com Wed Oct 24 15:37:40 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 24 Oct 2001 14:37:40 -0500 Subject: Critical sections and mutexes In-Reply-To: References: <20011024175604.3684.qmail@web21103.mail.yahoo.com> Message-ID: <15319.6276.254491.897200@beluga.mojam.com> dave> P.S. - Print statements are not atomic and do not fall in the same dave> realm as "normal" Python operations (e.g. "i = 5") ... Assignment is not atomic either. Your example would byte compile to LOAD_CONST 5 STORE_FAST i As others have mentioned, at the level of individual opcodes Python is atomic. The statement i = j would have to be protected if j could be rebound or the object j referenced could be modified by another thread. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From root at rainerdeyke.com Mon Oct 15 00:14:12 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Mon, 15 Oct 2001 04:14:12 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: "Tim Peters" wrote in message news:mailman.1003113854.26899.python-list at python.org... > You're apparently responding to an edited reply, and didn't read the thread > from its start: surrounding parens are required else you don't get this > form of conditional expression at all. It's not a question of whether to > require surrounding parens or not; the latter isn't an option, due to the > limitations of one-token lookahead parsing (read the thread from the start). Actually, it would probably be possible to make the parens optional in all cases except where 'if' is the first token of the expression. x = if a then b else c # legal if a then b else c # syntax error The required changes in the grammar are quite small: 1. Replace all rhs instances of "testlist" with "any_expression", *except* the first one in "expr_stmt". 2. Add the following production: "any_expression: testlist | 'if' any_expression 'then' any_expression 'else' any_expression". (This still doesn't allow unadorned conditional expressions in places where "testlist" is not used, such as function arguments.) -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From info at devshare.de Sat Oct 20 13:04:34 2001 From: info at devshare.de (Johannes Gamperl) Date: Sat, 20 Oct 2001 19:04:34 +0200 Subject: looking for CGI examples Message-ID: Hello, i'm starting to learn python. so do you have a few ideas, for what i can use python on the internet (for cgi programming). there are any examples? Bye the way, im searching also for got cgi with python tutorials ... Thx a lot an best regardes Hannes From db3l at fitlinxx.com Thu Oct 25 00:32:46 2001 From: db3l at fitlinxx.com (David Bolen) Date: 25 Oct 2001 00:32:46 -0400 Subject: Critical sections and mutexes References: Message-ID: writes: > On 24 Oct 2001, David Bolen wrote: (...) > > Just be careful to fully document that fact in your code and avoid > > using this sort of example for newbie questions about threaded code. > > Otherwise what tends to happen is that someone believes that the code > > in question is really establishing a cap of 1000 (since they won't > > necessarily perform the same threaded analysis of the code you have) > > and this can lead to maintenance problems down the road. > > No, no, no. That just means the code has really crummy comments. Why in > the world would "1000" show up in the comment? Comments, especially in > Python, should be level-of-intent, so the comment for this case would be > nearly exactly what I wrote in my post, i.e. "make sure the list doesn't > get too big". Read my comments again. Nowhere do I say that 1000 shows up in the comment. What I said was to fully document the very "impreciseness" that you are assuming is ok. Let's say I'm maintaining your code. I see a comment that says "make sure the list doesn't get too big". Then I read the code and I see your comparison to 1000 (or to a constant representing 1000). The logical conclusion - particularly for one who hasn't been knee deep in the threaded development - is going to be that it shouldn't exceed that constant. If you've written the code knowing that there's some error margin around that constant because you didn't protect against simultaneous access, if I were reviewing the code I'd sure want a comment to that affect in that section of code. That's a critical behavior characteristic of how you are performing the check. Someone someday later may want to change the constant (that for all intents and purposes looks like - and probably even behaves like in most cases - a true maximum), and expects it to really be a maximum. Or when you write the code you know there are about 10 threads vying for contention and you figure that overflowing by 10 is no big deal. But then someone changes the environment and you have hundreds of threads. And your class got used multiple times for multiple purposes. All of a sudden you're significantly over memory budget with no clear reason why. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From guido at python.org Thu Oct 18 17:00:28 2001 From: guido at python.org (Guido van Rossum) Date: Thu, 18 Oct 2001 21:00:28 GMT Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> <9qk0p9$6tulc$1@hades.rz.uni-sb.de> <9qkfi0$6s3js$1@hades.rz.uni-sb.de> Message-ID: > Michael Hudson wrote: > > |>>> a = Numeric.array([1,2]) > |>>> hash(a) > | 56 > |>>> d = {a:1} # a will be in the 56%8-th slot (in 2.2, anyway) > |>>> a[0] = 2 > |>>> hash(a) > | 57 > |>>> d[a] # looks in 57%8-th slot - which is empty > | KeyError > |>>> b = Numeric.array([1,2]) > |>>> hash(b) > | 56 > |>>> d[b] # looks in 56%8-th slot - but what's there is not __eq__ to b! > | KeyError > > | Moral: don't use mutable objects as dictionary keys. Hm. The Numeric.array object should not have defined __hash__ or tp_hash. It's wrong if a mutable object defines a hash function, for exactly this reason. --Guido van Rossum (home page: http://www.python.org/~guido/) From slinkp23 at yahoo.com Tue Oct 16 14:29:34 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Tue, 16 Oct 2001 18:29:34 GMT Subject: FW: fast sub list operations References: Message-ID: On Tue, 16 Oct 2001 16:43:54 +0100, Dale Strickland-Clark wrote: >"Alves, Carlos Alberto - Coelce" wrote: >>I constantly miss some nice way to subset lists. As an example suppose I >>have a list of x y coordinates eg >> >> [x0,y0,x1,y1,.....] >> >>and wish to perform the operation x->x+v, y->y+w for the co-ordinates in >>the list I don't seem to be able to do this fast using map. (snip) >A simple class should help manipulate these lists: > >class pairs: (snip) >l = pairs(range(20)) > >print 'Pairs', [[x, y] for x,y in l] >print 'Odds', [y for x,y in l] >print 'Evens', [x for x,y in l] >print 'Doubled evens', [x*2 for x,y in l] Depending on what Carlos needs to do with these lists, I wouldn't bother with a class - I'd just make a list of [x,y] lists. This could be constructed from the list Carlos already has like so: def pairs(alist): return [[alist[i], alist[i+1]] for i in range(0,len(alist),2)] Then the rest of your examples work exactly as you've written them. Easy to use with map(), too: >>> spam = pairs(range(10)) >>> spam [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]] >>> map(lambda coord: [coord[0] +10, coord[1] +20], spam) [[10, 21], [12, 23], [14, 25], [16, 27], [18, 29]] --PW From dsavitsk at e-coli.net Sun Oct 21 17:20:07 2001 From: dsavitsk at e-coli.net (dsavitsk) Date: Sun, 21 Oct 2001 21:20:07 GMT Subject: editing .asp in PythonWin Message-ID: has anybody used pythonwin as an editor for writing active server pages? When opening a .asp it seems to do a good job on the html, but the python is all gray. is there a trick to getting the python part to show up as the colorful as well as the html, or in exchange for the html? thanks, doug From loewis at informatik.hu-berlin.de Mon Oct 8 09:06:03 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 08 Oct 2001 15:06:03 +0200 Subject: Status of SOAP and Python. References: Message-ID: Gabriel Ambuehl writes: > > I certainly hope that SOAP is going to disappear rather sooner than > > > > Considering that .NET is based on SOAP, this is rather unlikely to > happen. Now if .NET would disappear too... I can only speculate on the future of .NET, given that it is not even released yet... OTOH, I did speculate on the future of SOAP, too :-) > > later, and that people who care about distributed systems come back > > to well-defined interfaces, and efficient marshalling. > > So what do you recommend to use instead of SOAP? XML-RPC? Classic RPC > (*uaah*)? I still think CORBA is technically sound and convenient to use. Regards, Martin From gh_pythonlist at gmx.de Tue Oct 9 02:41:03 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 9 Oct 2001 08:41:03 +0200 Subject: Why so few Python jobs? (and licenses) In-Reply-To: <7xwv25zftv.fsf@ruckus.brouhaha.com>; from phr-n2001d@nightsong.com on Mon, Oct 08, 2001 at 07:51:08PM -0700 References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> Message-ID: <20011009084102.B587@lilith.hqd-internal> On Mon, Oct 08, 2001 at 07:51:08PM -0700, Paul Rubin wrote: > I don't think anything in the standard Python library is GPL'd. > (GPL-compatible yes, GPL'd no). But AFAIK some functionality is only there if you link against GPL'd libraries like GMP (for arbitrary length Python longs), readline and maybe others I forgot. So you should perhaps still be careful before distributing a binary version of Python and linking in your own modules. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From manobes at fraser.sfu.ca Fri Oct 26 12:23:19 2001 From: manobes at fraser.sfu.ca (Matthew Nobes) Date: Fri, 26 Oct 2001 09:23:19 -0700 Subject: help with something that ought to be simple In-Reply-To: <9r7tgu$rq3o9$1@ID-11957.news.dfncis.de> References: <9r7tgu$rq3o9$1@ID-11957.news.dfncis.de> Message-ID: Thanks to both Paul and Emile for the help. The code now works correctly. -- ``We may feel that at last, unlike all previous generations, we have found certitude. They thought so too'' -Robert Conquest Matthew Nobes, c/o Physics Dept. Simon Fraser University, 8888 University Drive Burnaby, B.C., Canada, http://www.sfu.ca/~manobes From tim.one at home.com Sat Oct 6 23:14:37 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 6 Oct 2001 23:14:37 -0400 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <005201c13e1f$cb1824f0$445d4540@Dell2> Message-ID: [Joshua Macy] > and-if-it's-good-enough-for-Moses-it's-good-enough-for-Tim-Peters- [Brain Quinlan] > Bite your tongue! What has Moses done for me lately? Damn straight, Brian! Now if his name were Moses Peters, it might even be relevant. moseses'-best-bud-ly y'rs - tim From yuanrong99 at yahoo.com Mon Oct 29 01:04:45 2001 From: yuanrong99 at yahoo.com (rong yuan) Date: Sun, 28 Oct 2001 22:04:45 -0800 (PST) Subject: question Message-ID: <20011029060445.37887.qmail@web20503.mail.yahoo.com> Hi, I am a new python programmer. I wrote a simple program to extract data frome files. The question is I have thousands of this same frame files. How can I run my program to read all of them automatically? Thank you for your kind help. Sincerely yours, Rong Yuan __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From nomad*** at ***freemail.absa.co.za Fri Oct 19 05:59:43 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Fri, 19 Oct 2001 11:59:43 +0200 Subject: Curious assignment behaviour References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> <3bcdbb39.1987133892@news> Message-ID: On Thu, 18 Oct 2001 17:37:53 GMT, "Rainer Deyke" wrote: >"David C. Ullrich" wrote in message >news:3bcdbb39.1987133892 at news... >> What if you already have x = 42 and y = 24, and you >> say "let x = y" ? Does that set x to 24 (yes) or >> does it set y to 42? > >It means "consider the case 42 = 24". In a mathmatical sense or a programming sense? I haven't read all of this thread, and I'm not the worlds greatest at maths, but from my view point the discussion seemed to start about programming syntax. >From the programming side of things "Let x = 42" (or however you want to write it) says "give the _variable_ x the value 42" (or consider the case where the _variable_ x = 42). The important word here is 'variable' because in programming, x is variable (as in, its value can change). 42 will always be 42, it is an explicit constant, whereas x isn't, x is only a placeholder for the value you give it. There for, using the above example, of let x = y (where the _variable_ y has been set to 24), the value of x will be changed to equal the current value of y, which is 24. I'm probably over my head (and more than likely rambling as well), but in "let x = y" doesn't the 'let' denote that the value of 'x' will be changed? Confusing-himself-ly y'rs -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From phr-n2001d at nightsong.com Tue Oct 9 04:03:34 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 01:03:34 -0700 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> <23891c90.0110082340.541e6993@posting.google.com> Message-ID: <7x4rp91bqh.fsf@ruckus.brouhaha.com> paul at boddie.net (Paul Boddie) writes: > I would seriously doubt that any of the libraries distributed with > Python are GPL licenced. Indeed, options such as the readline module > remain just that: optional. So, there seems to have been an explicit > policy of avoiding "GPL by stealth". That's a good policy--whatever license one uses, it should be stated up front and not slipped in by stealth. > However, there are a number of useful packages which have GPL > licences. I was asked to update the Python Web modules page which I > maintain some time ago with licence information, purely so that people > could see which modules/frameworks weren't worth evaluating because of > the licence, and there are a lot of them with GPL licences - it's > quite surprising. I don't understand why it's surprising--the GPL is by far the most common license on Sourceforge, so it's natural that Python module licenses would follow the same pattern. > I don't want to start a mindless debate about the benefits or evils of > GPL licensing, but usage of the GPL and any resulting success of a > particular project is probably quite dependent on the scale or > adoption of that project, along with how unique or interesting it is. > In many cases, based on observation of people's behaviour or attitude > alone, it seems that putting a GPL licence on a project at an early > stage is like putting a "do not touch" sign on it. Maybe for some but not others. I'm far more likely to volunteer to contribute to a GPL'd project than a non-GPL'd one. I have nothing against non-GPL'd programs, but if I'm going to do product development for a closed source company, I expect to get paid for it. From logiplexsoftware at earthlink.net Tue Oct 23 17:01:43 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 23 Oct 2001 14:01:43 -0700 Subject: Critical sections and mutexes In-Reply-To: <15317.52539.481298.926686@beluga.mojam.com> References: <20011023190659.23110.qmail@web21101.mail.yahoo.com> <01102312391006.14120@logiplex1.logiplex.net> <15317.52539.481298.926686@beluga.mojam.com> Message-ID: <01102314014307.14120@logiplex1.logiplex.net> On Tuesday 23 October 2001 13:04, Skip Montanaro wrote: > Sorry to drop in late on this thread, but why not simply make PriorityQueue > a subclass of Queue.Queue (which already does all the locking for you)? Good suggestion. However, IMHO he really should learn how locks work before using them. Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From ignacio at openservices.net Fri Oct 12 11:30:40 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 12 Oct 2001 11:30:40 -0400 (EDT) Subject: Length on an input parameter in python In-Reply-To: Message-ID: On 12 Oct 2001, coolslife wrote: > Oleg Broytmann wrote in message news:... > > On Thu, Oct 11, 2001 at 03:16:07PM -0700, coolslife wrote: > > > > > It looks like the length of an input parameter (taken from the command > > > > > line atleast) is limited to 256 characters. > > > > > > > > Windows? > > > > > > Nope, Unix, 2.6 > > > > On UNIX limits are much, much higher. Something wrong there... > > > > Oleg. > > ---- > > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > > Programmers don't die, they just GOSUB without RETURN. > > So any suggestions on how to overcome this limitation? thx. It may be a side effect of the shell or environment you're currently using. Try using a different shell or environment. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From glchapman at earthlink.net Mon Oct 29 14:35:06 2001 From: glchapman at earthlink.net (Greg Chapman) Date: Mon, 29 Oct 2001 19:35:06 GMT Subject: Dictionary from list? References: Message-ID: <1cbrttkrk1ljb6csfkb3rdhdbuh2n3v0ag@4ax.com> On Mon, 29 Oct 2001 02:58:42 -0500, Guido van Rossum wrote: > >If you want a vaguely dictionary-like object, write a class that >doesn't derive from dictionary but implements the mapping protocol; if >you want a base class that implements most of the operations already, >start with UserDict. > >Subclassing a built-in type is appropriate when either (a) you want to >use it in a context where a genuine list/dictionary/file/etc.; or (b) >you want the speed advantage of the built-in type. In both cases you >have to live with some restrictions. Remapping the fundamental >accessors (like __getitem__) is probably not a good idea in either >case. Adding new state and behavior is fine. > >We should document this more clearly and in more detail. > In fact I have a UserDict-like class which implements the behavior I want, and which I will continue to use. Given the new subclasses, it seemed logical to try to convert this class into a dictionary subclass, since the intent is for it to work identically to a dictionary except that it has the additonal property that the order of iteration is defined. My thinking was that as a subclass, I could use it in situation (a), where a genuine dictionary is required. However, I see now that this class is not a subclass of dictionary (since it breaks fundamental aspects of its purported superclass), but an implementation of a subtype of the mapping type implemented by dictionary. So the class can use a dictionary as part of its implementation, but it is not itself a dictionary. I agree that it would be very helpful to have some documentation of what parts of the built-in types should be considered fundamental. By the way, in thinking about situation (a), I was wondering how much of a slow-down would be involved if PyDict_XXX calls were changed to PyMapping_XXX (I'm not advocating that, I was just curious). Anyway, while doing so, I happened to notice the following two macros in abstract.h: #define PyMapping_DelItemString(O,K) PyDict_DelItemString((O),(K)) #define PyMapping_DelItem(O,K) PyDict_DelItem((O),(K)) I assume those are oversights? It seems to me they should delegate to PyObject_DelItem (and PyObject_DelItemString, which will have to be added). Anyway, thanks for your reply, and thanks for Python! --- Greg Chapman From use-net at schabi.de Wed Oct 17 18:20:05 2001 From: use-net at schabi.de (Markus Schaber) Date: Thu, 18 Oct 2001 00:20:05 +0200 Subject: IF STATEMENTS References: Message-ID: <20011018002005.53f58ef2.use-net@schabi.de> Hi, (sent per mail only) On Wed, 17 Oct 2001 16:40:52 -0400, "Raibatak Das" wrote: > if (vars1==1 and vars2==2) : > ... Ough, you should do away with this ugly parents! Looks like C, C++ or Java :-) markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From vickie_mills at standardlife.com Wed Oct 10 03:32:30 2001 From: vickie_mills at standardlife.com (Vickie Mills) Date: Wed, 10 Oct 2001 08:32:30 +0100 Subject: Training Courses in Python in UK Message-ID: <007e01c1515d$bb255940$e7581fac@sl079320.internal.standardlife.com> Hi there, I am looking for you recommendations on training courses available in the UK on Python. Can you help? Thanks, Vickie Mills IS Training Analyst Tel: 0131 245 1127 Fax: 0131 245 1550 E-mail: vickie_mills at standardlife.com For more information on Standard Life, visit our website http://www.standardlife.com/ The Standard Life Assurance Company, Standard Life House, 30 Lothian Road, Edinburgh EH1 2DH, is registered in Scotland (No SZ4) and regulated by the Personal Investment Authority. Tel: 0131 225 2552 - calls may be recorded or monitored. This confidential e-mail is for the addressee only. If received in error, do not retain/copy/disclose it without our consent and please return it to us. We virus scan all e-mails but are not responsible for any damage caused by a virus or alteration by a third party after it is sent. From tanzer at swing.co.at Thu Oct 11 02:57:02 2001 From: tanzer at swing.co.at (Christian Tanzer) Date: Thu, 11 Oct 2001 08:57:02 +0200 Subject: Assigning to lists with arbitrary names In-Reply-To: Your message of "Wed, 10 Oct 2001 13:22:02 PDT." <01101013220203.04263@logiplex1.logiplex.net> Message-ID: Cliff Wells wrote: > On Wednesday 10 October 2001 09:55, Daniel Dittmar wrote: > > > Here's the problem: I want to name each list list00 to list99. I don't > > > want to do list[0] to list[99] (since each list is actually a list of > > > lists, and I'd like to avoid a list of lists of lists :). > > > > You could use a dictionary with keys 'list00' to 'list99', but I don't > > think having a dictionary of lists of lists is that much better. Why not > > subclass UserList for each kind of list? Then you could at least > > distinguish between the different levels. > > If you really _must_ have multiple variable names (IMHO a bad idea, since > later you will have to reference all those lists and hence hardwire those > names into your code which will make extensiblity murder - I still feel the > dictionary method I recommended earlier is a simpler and more extensible > solution) you could use something like: > > > filenames = ["text01.txt", "text02.txt", ....] # use fnmatch or glob to get > # the filenames in > # real life > i = 0 > for filename in filenames: > listname = "list%02d" % i > exec("%s = MyImporter('%s')" % (listname, filename)) > i += 1 > > Which will give you 100 lists with the names list00, list99, etc and a ton of > maintenence problems. And it still uses a dictionary (just slightly hidden from your view) so what's the point of such a gross hack? I think the OP should consider getting rid of his fear of nested data structures -- in Python they are your friend. -- Christian Tanzer tanzer at swing.co.at Glasauergasse 32 Tel: +43 1 876 62 36 A-1130 Vienna, Austria Fax: +43 1 877 66 92 From nospam at bigfoot.com Wed Oct 3 12:44:27 2001 From: nospam at bigfoot.com (Gillou) Date: Wed, 3 Oct 2001 18:44:27 +0200 Subject: How to use the callback of COM objects References: <9pf6ph$9dg$1@norfair.nerim.net> Message-ID: <9pfetp$gah$1@norfair.nerim.net> Thanks a lot Dale, It semms to give some good results --Gilles "Dale Strickland-Clark" a ?crit dans le message news: tt9mrtc1kd8hmfda4a25lcu0r3atlv3p23 at 4ax.com... > "Gillou" wrote: > > >Hi, > > > >I've tried this to provide a callback function to a COM object: > >============== > >import win32com.client > >def HandleReadyState(): > > # anything you want > > return > >ox = win32com.client.Dispatch('MSXML.DomDocument') > >ox.onreadystatechange = HandleReadyState > >============== > >And the last line raises this: > >============== > >Traceback (most recent call last): > > File "validation.py", line 7, in ? > > ox.onreadystatechange = HandleReadyState > > File "C:\Python21\win32com\client\dynamic.py", line 467, in __setattr__ > > self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0, > >pythoncom.DI > >SPATCH_PROPERTYPUT, 0, value) > >TypeError: Objects of type 'function' can not be converted to a COM VARIANT > >============= > > > >This works perfectly when the equivalent is programmed in javascript. > >"onreadystatechange" is an event that can be handled by a user function. > > > >Did I miss something ? > > > >Thanks in advance fo any hint. > > > >--Gilles > > > > > > There is DispatchWithEvents which might be what you're looking for but > I've never tried to use it. > -- > Dale Strickland-Clark > Riverhall Systems Ltd From peter at engcorp.com Mon Oct 22 07:45:02 2001 From: peter at engcorp.com (Peter Hansen) Date: Mon, 22 Oct 2001 07:45:02 -0400 Subject: Perl Range operator paradigm References: <3BCC0B8D.F4EFF59C@loria.fr> Message-ID: <3BD406BE.BCEC2B98@engcorp.com> Laurent Pierron wrote: > > Hello Gurus, > > In Perl there is a very powerful range operator '..', which, in scalar > context, is acting like line-range (,) operator in sed and awk. > > By example, this small program prints all the lines in the file included > between ... : > > while (<>) { > if (// .. /<\/BODY>/) {print; } > } > > How can I do, the same thing in Python ? Requirements insufficiently detailed. What happens, for example, if there are multiple pairs in the file? Does it do a "greedy" match and use the first and the last , or does it do each pair separately? Also, is it case-sensitive? HTML is not, but XML (and thus XHTML) is. Which does the above do? If there were text on the line after , would it print that text or, as you imply, only the *lines* between the two tags? What if both appeared on the same line? Any output? (I think it must already be written somewhere as a law that even the specifications for a Perl one-liner cannot easily be described ... :-) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From Krzysztof.Czarnowski at dgt-lab.com.pl Fri Oct 26 11:26:55 2001 From: Krzysztof.Czarnowski at dgt-lab.com.pl (Krzysztof Czarnowski) Date: Fri, 26 Oct 2001 17:26:55 +0200 Subject: Windows/COM events/strange behavior References: Message-ID: <006b01c15e32$a5752c60$2706a8c0@krzysiek> on Mon, 22 Oct 2001 13:42:32 GMT Mark Hammond wrote: > Krzysztof Czarnowski wrote: > > > alive. The script is being started from a DOS prompt. Module "threading" is > > used. The COM event handler is constructed inside the thread and it lives in > > a "single threaded appartment" (CoInitialize(), loop PumpWaitingMessages(), > > CoUninitialize()). > > > Sounds perfect :) > > > > Then, when I start Pythonwin it gets stuck! When I stop the script Pythonwin > > seems to get released and starts (the window is displayed ...). Then I can > > run the script again without problems. > > > What is the main loop doing. It too should be sitting on a > PumpWaitingMessages() loop. Pythonwin is almost certainly waiting for a > DDE request to finish, and somehow the script is blocking this DDE > behaviour. Using "pythonwin /nodde" would help, but you may still find > some other apps being similar things (eg, installer applications often > block in these situations, etc) > > Mark. I couldn't read the list for some time - sorry! I really do observe the same behaviour with other apps (e.g. pfe file editor). My main thread loop is doing (slightly simplified): while 1: event_stop.wait(3) if event_stop.isSet(): break if msvcrt.kbhit(): k = msvcrt.getch() if k in ['s', 'S']: break The PumpWaitingMessages() loop is executed in a child thread. In parallel another "CORBA child-thread" is working. Krzysztof From tim.one at home.com Mon Oct 8 14:26:59 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 8 Oct 2001 14:26:59 -0400 Subject: Curious assignment behaviour In-Reply-To: <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> Message-ID: [Dale Strickland-Clark] > ... > So how about an alternative assignment operator that can't be confused > with equality but which yeilds the assigned value? > > Pascal uses := But doesn't allow it in expressions -- assignment in Pascal is also a statement. > Another language (I forget which) uses <- > > (I've always prefered := for assignment and a plain = for equality.) > > I don't suppose I'm the first to suggest this, either. Bingo: it's been suggested countless times over the last decade, but before the introduction of PEPs there's no coherent historical record. Searching a comprehensive archive is the only tool. Guido's first public word on the topic appears to be msg #54 (of 161,909 in the egroups/Yahoo archive): http://groups.yahoo.com/group/python-list/message/54 I agree, reluctantly (because of all the lines of library and example code I will have to change), that this change should be made; but it won't be in 0.9.4 if I release that soon. Note that this still won't give you assignments in expressions as side effects; I am against such a feature even though it occasionally saves a line of code -- one of Python's strong points is that it is usually very easy (and pretty!) to read, and I feel that assignments in expressions would have a strong negative effect on readability (and prettiness!). The change he was talking about (affecting "all the lines of library and example code I will have to change" -- probably amounted to a few hundred at the time ) was introducing "==" to mean equality in Python. At the start, "=" meant both equality-testing and assignment. A consequence was that, and especially in interactive mode, >>> a = b was ambiguous. So that didn't last. In later years, an informal proposal to add ":=" for embedded assignment made significant progress, but floundered over a combination of ugliness and lack of consensus. The most popular variant had ":=" binding tightly, so that e.g. while myvar := func() != 0: assigned myvar to func's return value, not to the Boolean outcome. But then if distance_sq := x**2 + y**2 < 1: bound distance_sq to x**2, not to the sum. Etc. For every hack to the precedence rules someone suggested, someone else came up with a natural example where it was plain surprising. IIRC, this line ended when it was more-than-less agreed that any use of ":=" would *require* surrounding parentheses. But that made it even uglier, and proponents got rarer while the opposition enjoyed a major resurgence in the polls . so-its-prospects-look-dim-even-if-it-had-a-pep-ly y'rs - tim From max at alcyone.com Tue Oct 2 00:18:49 2001 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Oct 2001 21:18:49 -0700 Subject: newbie str to int References: <9pbetr$jp83@imsp212.netvigator.com> Message-ID: <3BB94029.9178CFF5@alcyone.com> James wrote: > Why doing simple thing like this is so complicated ? > > Perl > $foo = '123abc' + 0; > > Please explain in newsgroup. Because Perl is very sloppy with types, whereas Python is not. The difference in practice is that Python is more restrictive and catches problems earlier, whereas with Perl you have to explicitly test for failure cases yourself. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Man is a hating rather than a loving animal. \__/ Rebecca West The laws list / http://www.alcyone.com/max/physics/laws/ Laws, rules, principles, effects, paradoxes, etc. in physics. From mwh at python.net Fri Oct 19 09:18:10 2001 From: mwh at python.net (Michael Hudson) Date: Fri, 19 Oct 2001 13:18:10 GMT Subject: Dictionary from list? References: Message-ID: "Ivan A. Vigasin" writes: > On Fri, 19 Oct 2001, Michael Hudson wrote: > > > />> def beargh(d): > > |.. unique = [] > > |.. def ouch(x,y): > > |.. if x is unique: > > |.. return y > > |.. else: > > |.. d[x] = y > > |.. return unique > > |.. return ouch > > \__ > > ->> d = {} > > ->> reduce(beargh(d), ['a', 1, 'b', 2]) > > [] > > ->> d > > {'a': 1, 'b': 2} > Idea is great! You mean that for real? I think it's foul. It abuses the implementation details of reduce to do something that function was never intended to do. > It comes from functional programming? No. There are side-effects all over the place! > Your code doesn't work in my Python 2.1 ... > > t1.py:1: SyntaxWarning: local name 'd' in 'beargh' shadows use of 'd' as global in nested scope 'ouch' > def beargh(d): > t1.py:1: SyntaxWarning: local name 'unique' in 'beargh' shadows use of 'unique' as global in nested scope 'ouch' > def beargh(d): > Traceback (most recent call last): > File "t1.py", line 12, in ? > reduce(beargh(d), ['a', 1, 'b', 2]) > File "t1.py", line 4, in ouch > if x is unique: > NameError: global name 'unique' is not defined You needed a "from __future__ import nested_scopes" in there somewhere. > I slighly modified your code and got the following: > > class beargh: > def __init__(self,d): > self.d = d > def __call__(self,x,y): > if x == []: > return y > else: > self.d[x] = y > return [] > > d = {} > reduce( beargh(d), ['a', 1, 'b', 2] ) > print d Actually, that works almost as well as my code -- you get problems with input like ['a', 1, [], 2], but you have problems with that anyway as lists aren't hashable. Just in case anyone hasn't got the message yet: THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. THE CODE I POSTED WAS DISGUSTING. DON'T EMULATE IT. Cheers, M. -- Now this is what I don't get. Nobody said absolutely anything bad about anything. Yet it is always possible to just pull random flames out of ones ass. -- http://www.advogato.org/person/vicious/diary.html?start=60 From jdunnett at uoguelph.ca Sun Oct 28 19:44:37 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Sun, 28 Oct 2001 19:44:37 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> Message-ID: <3BDCA674.FF268D0E@uoguelph.ca> In case your wondering the school that I attend teaches Python. In fact it is a main part of one of the first major software design course. That is the University of Guelph in Ontario Canada. In fact the departement has quite a lot of fallowers who like Python. Jeff Peter Hansen wrote: > Christy J wrote: > > > > I need a binary search tree in python that uses classes. I'm trying to > > count words from a file and spit out the number of times they occur > > and in alphabetical order. I got bintree[ [key, data], left, right] > > but don't know how to implement using classes. > > I'd be interested to hear which school is teaching with Python. > > Schools progressive enough to take a chance (a small one, mind > you, but they don't usually seem to think so) on something > not mainstream (i.e. not Java) are few and far between. > > -- > ---------------------- > Peter Hansen, P.Eng. > peter at engcorp.com From huaiyu at gauss.almadan.ibm.com Thu Oct 11 17:07:45 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 11 Oct 2001 21:07:45 +0000 (UTC) Subject: How to set tab-width to 4 spaces in emacs ?? References: <1J1x7.14385$tu6.623674@news1.oke.nextra.no> Message-ID: On Thu, 11 Oct 2001 03:15:10 GMT, Lee Morgan wrote: >I think (setq tab-width 4) is correct, although isnt it both a global and buffer >variable(or is it a mode var?) - so you may need to add it on to your mode >hook. (Although I've never had reason to change python-mode) To do it globally (for every buffer) you can use (setq-default tab-width 4) Huaiyu From paul at boddie.net Tue Oct 23 08:49:47 2001 From: paul at boddie.net (Paul Boddie) Date: 23 Oct 2001 05:49:47 -0700 Subject: problem with pirxx References: Message-ID: <23891c90.0110230449.13ccde9d@posting.google.com> "Markus Jais" wrote in message news:... > hello, > I installed the latest version of pirxx on my Suse 7.1 with python 2.1 > when I call the testscript I get the following error: > > $ python test.py > Traceback (most recent call last): > File "test.py", line 15, in ? > from pirxx import _pirxx > ImportError: shared object not open > > I am quite new to python and have never seen such an error. > can anybody help?? I don't think I've ever seen that exact error, but I would suspect that your dynamic linker can't find the _pirxx.so or _pirxxmodule.so shared library. I'm about to check out pirxx in the next few days, so I might be able to comment further once I've installed it. However, you should make sure that your LD_LIBRARY_PATH environment variable includes the directory where such a shared library can be found, or that your linker's configuration is set up for that directory; at this point, it becomes more of a Linux configuration issue, really. Paul From mal at lemburg.com Mon Oct 22 07:17:38 2001 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon, 22 Oct 2001 13:17:38 +0200 Subject: mxODBC / Oracle / ORA-01475 Error References: <3BCAF356.4F051A78@gmx.de> Message-ID: <3BD40052.82FED9EA@lemburg.com> Stefan Kirchberg wrote: > > Hi all, > I'm trying to insert some rows into a table as follows: > > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > import mx.ODBC.Windows as ODBC > dsn="DSN=STARFMDS;UID=system;PWD=manager" > db = ODBC.DriverConnect(dsn) > db.bindmethod = ODBC.BIND_USING_PYTHONTYPE > c = db.cursor() > c.execute("drop table t") > c.execute("create table t (a int)") > > rows = [ (0,), (None,) ] > c.executemany("insert into t(a) values (?)", rows) > db.commit() > > c.execute("select * from t") > print c.fetchall() > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< > > The program crashes executing the INSERT statement with the second > row (as one can see when replacing the executemany() with a > for loop / execute() structure). > > Oracle says ORA-01475, 'must reparse cursor to change bind variable > datatype'. > > Obviously the None value is the reason. But I cannot predict if I > will insert None values (which should mean NULL fields in the database) > -- it should work anyway. > > It doesn't matter if the program is running with BIND_USING_PYTHONTYPE > or BIND_USING_SQLTYPE. But BIN_USING_SQLTYPE should work since the ODBC > module should look into the table to see what type is expected by the > database, and treat the None value/type correctly. > > Inserting a single row (or multiple identical rows) containing of a None > value works in the expected way, mixing None and numerical values is > the problem. > > Any hints? Which ODBC driver are you using to talk to the Oracle database ? If it's the Oracle one, please try using the Microsoft replacement which comes with the MSDAC toolkit from Microsoft. -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Consulting & Company: http://www.egenix.com/ Python Software: http://www.lemburg.com/python/ From phr-n2001d at nightsong.com Tue Oct 30 21:35:48 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 30 Oct 2001 18:35:48 -0800 Subject: Interfaces != Multiple Inheritance [was Re: python development practices?] References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: <7xy9lsr0xn.fsf@ruckus.brouhaha.com> Richard Jones writes: > Java interfaces != multiple inheritance. > > They address completely different issues. Mutliple inheritance allows one to > include functionality from multiple base classes in one step. An interface > indicates that your class implements a specific set of methods. Interfaces > don't implement functionality, therefore indicating that your class > implements multiple interfaces doesn't add any additional functionality. The idea is implement an abstract base class instead of an interface. Define methods for all the operations you want your interface to support, and make each method simply raise NotImplementedError. Then make the implementation for your inheriting class supply real versions of all the operations. From flognat at flognat.myip.org Wed Oct 17 03:57:58 2001 From: flognat at flognat.myip.org (Andrew Markebo) Date: Wed, 17 Oct 2001 07:57:58 GMT Subject: maximum recursion in "re" module? References: <200110160056.TAA20412@scortch.unisrv.net> Message-ID: / Skip Montanaro wrote: | CJ> startString = ".*?Lo Fi Play mp3String = re.compile(startString, re.I).sub("", mp3String, 1) | | Why do you need the ".*?" part of the re? I'd try this: Ah small and quick follow up, I have the same problems, but then my re's look something like "" Why do they do a stack overflow, shouldn't it be finished/work out faster than a "" (yeah I know not the same regexp, just thinking) And well "do a html-parser instead" is not the correct answer, it is not only html I try stuff like this on. | If you can get by without it, I think that will cure your problems. If not, | you can always import pre instead: pre? What is that? Previous re? /Andy -- The eye of the beholder rests on the beauty! From qrczak at knm.org.pl Sat Oct 13 12:44:33 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 13 Oct 2001 16:44:33 GMT Subject: signum() not in math? References: <3BC6B774.4688E9A2@darwin.in-berlin.de> Message-ID: Fri, 12 Oct 2001 11:27:16 +0200, Dinu Gherman pisze: > How comes there is no sign() or signum() function in math? You could use cmp(x,0) if it was guaranteed that it returns only -1,0,1. Unfortunately it's not said in docs; it happens to work though. Perhaps docs should be changed... -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From drobinow at yahoo.com Thu Oct 11 10:53:20 2001 From: drobinow at yahoo.com (David Robinow) Date: 11 Oct 2001 07:53:20 -0700 Subject: How to set tab-width to 4 spaces in emacs ?? References: <1J1x7.14385$tu6.623674@news1.oke.nextra.no> Message-ID: <59a4b541.0110110653.51df5e08@posting.google.com> "Thomas Weholt" wrote in message news:<1J1x7.14385$tu6.623674 at news1.oke.nextra.no>... > Trying to set the tab-width in emacs to 4 spaces without luck. Using > Mandrake 8.1 ( great distro btw, python 2.1.1, postgresql 7.1.3 etc. try it > now !) > Put the following in your .emacs You may find comments in the source of python-mode.el to be helpful. (defun my-pystuff () (setq tab-width 4 py-indent-offset 4 indent-tabs-mode t py-smart-indentation nil)) (add-hook 'python-mode-hook 'my-pystuff) From smithrc at zdbaora.nat.bt.com Fri Oct 12 06:51:36 2001 From: smithrc at zdbaora.nat.bt.com (Robin Smith) Date: 12 Oct 2001 11:51:36 +0100 Subject: J2EE equivalent in Python Message-ID: I like J2EE but I am also an open source fan. I don't like what I read about Sun and restricting Java - http://www.onjava.com/pub/a/onjava/2001/10/10/osjava.html . Is there anything similar to J2EE for python? Robin From db3l at fitlinxx.com Fri Oct 19 15:58:37 2001 From: db3l at fitlinxx.com (David Bolen) Date: 19 Oct 2001 15:58:37 -0400 Subject: Is there a small Python runtime environment installer? References: <3583b331.0110181524.5695bd67@posting.google.com> <3bcf81f8@news.microsoft.com> Message-ID: "Tex Riddell" writes: > I detect a hint of sarcasm here. Of course, that's not what I meant. I > meant binary installers for each platform that would set up a similar > environment for running your scripts in, regardless of end-user's platform. Sorry, no sarcasm intended. > I was just looking for something smaller and simpler. If you read further, > I mention clumping/compressing multiple files into single archives to keep > things reasonable small. I don't expect to have to sit over the shoulder of > the user who is installing a python distribution and tell them to de-select > this, and that, oh, and that, drill down, and this and that... I just want > a simple, configurable, re-distributable runtime. Because of scripts, > utilities and the like, the default ActivePython installs about 24 megs of > stuff in so many files that depending on the file system could take up as > much as 70 megs of space on the user's HD. That's a little much to ask just > so they can run a little utility script I want to send them. Hmm, you could try some of the other builds. The standard Python installation from www.python.org (about 6.7MB as an installer) which is the one I was referencing will get you about 20MB installed in one directory tree, and one file in the system directory as a full installation. If you unclick all entries (a total of 4) other than "Python interpreter and libraries" it's down to about 6MB. True, if your scripts will use any other packages (such as the Pythonwin extensions) you need to install that separately, but at least for Pythonwin it's a single standard Windows installer as well that automatically finds the current installation and augments it, no options to worry about. I was only suggesting these since if you're concerned about ease for the end user, this is really the simplest way to go to get the runtime environment on a machine (unless you build self-installing exes for each of your users) > You missed my point, if you are installing office, you would be expected to > know what office *is*, therefore knowing what options you want and do not > want installed. When my friend is installing Python, all they know is that > it is something that'll make the stuff I send them run. They will select > default installation, because they couldn't know any better. But is that really a problem? Given disk space nowadays, is it really a problem to get a few extra MB installed if you just want to take defaults and not worry about just what is required? (You may over-estimate the problem BTW - at least the standard Python installer only has 4-5 options and they're pretty easy to let them know to eliminate which ones if they're concerned with disk space.) > I am aware of this option, but as my script is a small simple shell script, > not a stand-alone GUI app, if I wanted to send more scripts, I would have to > build more installers! These seem to only try to track the dependencies of > a single application, then bundle only these parts in the installation. I'm > not prepared to write a setup program just to install a utility script... > I've wasted too much time on this already! At least to me it seems like you've got to go one way or the other. Either you give the person the Python RTL (which is no worse than most other RTLs they have on their system already) one time, which uses a standard Windows installer, or you figure out a way to include it in each of your distributions to them. > exactly! Do you at least understand what I'm trying to get at? Imagine > python was like html. End users typically have a web browser that includes > a set of standard features built around the standard. Those end users need > not install development kits in order to view an html file. They simply > download a web browser. Also people distributing an html file wouldn't need > to build a browser around their file that included only the features that > thier file used and send it to the user! I don't know about you but my web browser keeps making me install stuff in order to view more and more web pages. And keeping it upgraded means I install a massive download (to my Windows machines) and take up quite a bit of disk space. And there's a ton of options about patches, and security updates and service packs, and so on :-) There is another "poor mans" option - take a Python install that you have on your system, and then prune it down to what you really want. Put those files together into a standard self-extracting ZIP (or package them up with an installer like Inno Setup) and supply that to your friend. You can make that Python RTL as small as you want. That's how I set up our distributions to remote systems, which basically get the executable, DLL and the lib directory for package files (and in fact I only send the pre-compiled versions). It's more work on you but would both minimize disk space on the target system and relieve the end user of selecting any options. To be honest though, you end up almost maintaining your own build and I'm not sure the gain (over for example just biting the bullet and running the standard Python installer) is worth the cost. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From mdonovin at judge.com Wed Oct 31 08:14:41 2001 From: mdonovin at judge.com (Michael F. Donovin) Date: Wed, 31 Oct 2001 08:14:41 -0500 Subject: unsubscribe pls Message-ID: <52E86B6F5856D511B014001083FD15F13FA1FA@edisonnt.judge.com> -----Original Message----- From: Chris Gonnerman [mailto:chris.gonnerman at newcenturycomputers.net] Sent: Wednesday, October 31, 2001 8:17 AM To: J Dubal Cc: python-list at python.org Subject: Re: python-postgres-informix interaction problems ----- Original Message ----- From: "J Dubal" > Hello good people! > > We have developed Informix RDBMS based commercial applications in > Informix-4gl. It is a good procedural language with embeded SQL. We > are trying to rewrite some apps in Python with postgresql backend for > licensing reasons. Python is good too. We are trying to do this with > latest versions of RH linux (7.2), python 2.1 and postgres 7.1.3. We > face following issues: > > 1. We have to read data from informix db, process it and insert into > postgres. We are using informixdb module (DBAPI 1) which is bit dated. > In Informix we 'select custno, custname, custaddr1, ... into progvar1, > progvar2, ... from custmf where ...' In python, we say fetchone() and > we get a list. We are then moving the elements of the list to named > program variables thus: > pcustno = list1[0] > pcustname = list1[1] > pcustaddr1 = list1[2] > ... as many as reqd > This way we give meaningful names to data items read from db and > process further. > Is there a better, more elegant/efficient way to to this? No comment here, as I know little about the informixdb module. > 2. To insert this data into postgres, we used to use pygres included > in the postgres distribution (latest). We had to stop using this > because we couldn't find a way to find out how many rows it have > inserted, updated or deleted after such statements are executed ie we > couldn't find a way to check the status or return code. So we switched > over to PoPy which is DBAPI2 and where we could check number of rows > affected. Is this right thing to do? Absolutely (IMHO). If it works for you, it's probably right. > 3. In order to insert data into postgres, we have to compose an insert > statement thus: > cur.execute("insert into custmf (custno, custname, > custaddr1,...) > values (%i,'%s','%s'...)" %(pcustno,pcustname, > pcustaddr1....)) > Is there a better way of doing this? Yes! You say that PoPy is DBAPI2; the cursor.execute() method supports formatting in some way or another. Read the DBAPI2 and PoPy documents. In MySQLdb, you can do this (note the triple-quotes, you should be using them also IMHO): cur.execute(""" insert into custmf (custno, custname, custaddr1) values (%s,%s,%s) """, (pcustno,pcustname, pcustaddr1)) Note that comma! You put a %s placeholder with no quoting whereever you need a substitution and let the interface do the work! As I said, read the PoPy docs as DBAPI2 allows several different ways to do this autoquoting, and you need to know which one(s) it supports. > 4. The above string substitute converts program variables holding null > value into 'None' which goes into target table as string 'None'. To > avoid this we parse all columns to check if they are 'None' and > replace them by ''. Is there a better way to do this? Ouch. Try the parameter substitution method above and see what it does. DB API 2.0 does not say how NULLs should be handled. > 5. The above check works only on string variables. We have not found > yet a way to handle nulls in numeric columns. Please suggest a > solution. Ouch ouch. > 6. If the character columns happen to contain quotes, the above > composed insert statement breaks. Please suggest a solution. Here the parameter substitution should work OK; quoting of quotes should be supported automatically if you let the interface handle the substitution. > Any help is greatly appreciated. > Thanks in advance. Hope this helps. -- http://mail.python.org/mailman/listinfo/python-list From bobh at hslda.org Fri Oct 12 07:16:11 2001 From: bobh at hslda.org (Robert) Date: 12 Oct 2001 04:16:11 -0700 Subject: Python Cookbook: last call for recipes for printed version References: <9q52b1$3q5$1@lancelot.camelot> Message-ID: <4a249347.0110120316.a5de6eb@posting.google.com> Alex Martelli wrote in message news:<9q52b1$3q5$1 at lancelot.camelot>... > Hi there, Python chefs and gourmets, > > while the Python Cookbook (http://aspn.activestate.com/ASPN/Cookbook/Python) > will stay open for good, soon we'll have to "freeze" the set of recipes to > be considered for the book version to be published by O'Reilly & Associates. > > Therefore, please move FAST to post any further recipes (or, your very > first recipe -- why not?), edit any recipes you have already posted > (*particularly* to beef up the discussion parts... most recipes are great, > but their discussions, too lean!-), post comments, replies to comments, > ratings, whatever. By around Oct 15, either your mouthwatering Python > snippets are on the site, or they just won't be considered for the printed > version. So, please _DO_ hurry up! > > > Thanks, > > Alex I don't think this was said at all. Not even in the original Figgins call to contribute. Bob From mwh at python.net Fri Oct 19 06:18:43 2001 From: mwh at python.net (Michael Hudson) Date: Fri, 19 Oct 2001 10:18:43 GMT Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> <9qk0p9$6tulc$1@hades.rz.uni-sb.de> <9qkfi0$6s3js$1@hades.rz.uni-sb.de> <9qoteg$73fm0$2@hades.rz.uni-sb.de> Message-ID: Uwe Schmitt writes: > Michael Hudson wrote: > > | Indeed, the OP was complaining that Numeric.array *didn't* define a > | hash function... (and then snipped out the bit of my post where I said > | I was making it up). > > ups. what did i snip out ? i only received your virtual session... You snipped the bit that said "Consider this made up session...". Don't worry, it's Guido's fault for not reading all the thread . Cheers, M. -- : Giant screaming pieces of excrement, they are. I have a feeling that some of the people in here have a MUCH more exciting time relieving themselves than I do. -- Mike Sphar & Dave Brown, asr From erlangen72 at hotmail.com Tue Oct 2 16:03:34 2001 From: erlangen72 at hotmail.com (Mark_Pryor) Date: Tue, 02 Oct 2001 20:03:34 GMT Subject: tlbinf32.dll and win32com Message-ID: Hi, I looked through the list archive and found one message about tlbinf32.dll. They gave up and wrote some middleware DLL that win32com Python easily handled. I tried one additional step using a registry hack that added the typelib key to the clsid keys that I wanted to create. This got me past the object not found error but I still get this: >>>> tl = win32com.client.Dispatch('TLI.TLIApplication') Traceback (most recent call last): File "", line 1, in ? File "D:\Python21\win32com\client\__init__.py", line 94, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "D:\Python21\win32com\client\dynamic.py", line 81, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "D:\Python21\win32com\client\dynamic.py", line 72, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147467262, 'No such interface supported', None, None) Ok, so now I am going the middleware route also, unless someone has a better idea. tia, Mark Pryor pgp KeyID: 0x1A966EC5 From chatme at 263.net Sun Oct 21 21:45:54 2001 From: chatme at 263.net (limodou) Date: 21 Oct 2001 18:45:54 -0700 Subject: Is sgmllib.py 's BUG? References: Message-ID: "Sean 'Shaleh' Perry" wrote in message news:... > On 19-Oct-2001 limodou wrote: > > "Sean 'Shaleh' Perry" wrote in message > > news:... > > Great! Your changes is better than me. I'v fixed my sgmllib.py with it. > > Changes? That is a direct paste from sgmllib.py from 1.5.2. > > ----- > We have buried the putrid corpse of Liberty. -- Benito Mussolini But my sgmllib.py, from 2.1.1, is difference from 1.5.2. From bogus@does.not.exist.com Mon Oct 22 14:57:27 2001 From: bogus@does.not.exist.com (Jonathan Polley) Date: Mon, 22 Oct 2001 13:57:27 -0500 Subject: Is this a Dumb Thing to do? Message-ID: <3BD46C17.3CAEA8E@collins.rockwell.com> OK, What I am trying to do is dynamically change the contents of a Tkinter.OptionMenu. After doing some research I couldn't figure out how, until I looked at the __init__ method on the class and had a wicked thought. Create an instance of Tkinter.OptionMenu and then call its __init__ method to change the contents of the list! It worked, but is it by accident? Did I do a "Very Bad Thing(tm)?" I'm sure there is a better way to change the list contents, but how? Thanks! Jonathan Polley jwpolley(at)rockwellcollins(dot)com From phd at phd.pp.ru Tue Oct 2 12:34:27 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 2 Oct 2001 20:34:27 +0400 Subject: list remove In-Reply-To: <1165F677B8C4D411B71C0008C791EC4A71E3AA@N0225IDC1.oss.level3.com>; from steven.smith@LEVEL3.com on Tue, Oct 02, 2001 at 10:30:51AM -0600 References: <1165F677B8C4D411B71C0008C791EC4A71E3AA@N0225IDC1.oss.level3.com> Message-ID: <20011002203427.D21313@phd.pp.ru> On Tue, Oct 02, 2001 at 10:30:51AM -0600, steven.smith at LEVEL3.com wrote: > The python tutorial at > http://www.python.org/doc/current/tut/node7.html#SECTION00710000000000000000 > 0 has the section more on lists where it gives the function remove(x). I am > trying to use this function to delete elements out of my list, but it only > deletes every other list. > > >>>foo = [1, 2, 3, 4, 5] > >>>for bar in foo: > ... foo.remove(bar) > > >>>foo > [2, 4] > > Is this an error on my part, pythons list type or am I misinterpretting what > remove does? I have tried this on both 2.1 and 1.5.2. NEVER, I said NEVER modify the list while running through it! Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From johnroth at ameritech.net Wed Oct 10 17:54:29 2001 From: johnroth at ameritech.net (John Roth) Date: Wed, 10 Oct 2001 14:54:29 -0700 Subject: Curious assignment behaviour References: Message-ID: wrote in message news:mailman.1002736876.17796.python-list at python.org... > > Tim Peters wrote: > > Oops! The assert turned out to be the perversely self-fulfilling: > > assert(i = 1); > > and multiple senior programmers with many decades of industrial C > experience had stared at that multiple times without realizing the mistake. > > > I could certainly look at that a bunch of times and think "equality" > instead of "assignment". This is one of the reasons why Smalltalk (among > other languages) insisted on *not* using "=" to spell assignment. In my > experience, when assignment is *not* spelled with "=" such mistakes don't > come up in practice. And then it *is* acceptable (and very convenient) to > make assignment an expression. > > Jim Which was exactly my point in another branch of this discussion. It's also been pointed out that "=" is not a good symbol for assignment - it's just the one that Fortran chose to use, and its the reason that Algol chose ":=" as the assignment operator, with Pascal following in that path. In mathematics, "=" is an assertion that two expressions have the same value over the applicable portion of the domain. Pure mathematics doesn't have an equivalent of assignment. However, this is a lost arguement in terms of an existing language. Transitioning assignment to some other symbol would be a huge pain for not very much (percieved) gain. John Roth > > > From mikeb at mitre.org Tue Oct 16 14:46:55 2001 From: mikeb at mitre.org (Mike Brenner) Date: Tue, 16 Oct 2001 14:46:55 -0400 Subject: Python COM for Microsoft Project (thanks) Message-ID: <3BCC809F.CF969C7D@mitre.org> Thank you all -- these answers were very helpful. There is nothing wrong with the COM browser, except my own ignorance -- I ran combrowse instead of makepy. Mike Brenner wrote in message news:: > For the next line of code, I would like to resave the file as a tab-delimited file for further processing in Python. Actually, I will build a robot that opens all the MP files and resaves them. > - Is there a URI to download the objects and methods that are now available? > - Or is the list of objects somehow hidden inside my Visual Studio or my Microsoft Developer CDs? > - Or do I need to buy Visual Basic for Applications or some other application to gain access to the objects? > - Is there an upgrade to the COM object browser that comes with Python for Windows? stjepan.zlodi at zg.tel.hr (Stjepan Zlodi) wrote: What's wrong with COM object browser in your Python distribution? In my ActiveState Python distribution I have win32com\client directory in which is makepy.py script. With that script I can make python module for each COM object file on my computer. Steve wrote: A Google search (have you seen www.google.com ?) for microsoft project object model should give you plenty of details about the API, which is usually where one needs information in starting to drive a new application via COM. In particular, http://msdn.microsoft.com/library/en-us/dnpom/html/pjtocobjectmodelapplication.asp?frame=true Mark wrote: For the "list of objects" (classes, actually) that Microsoft Project exports (if it behaves like their other VBA enabled applications), simply do the following: Run Microsoft Project Select menu: Tools -> Macros-> Visual Basic Editor Select menu: View -> Project Explorer In the first list box, select the application itself, and you will see the API, annotated by class. From lucio at movilogic.com Mon Oct 22 21:51:02 2001 From: lucio at movilogic.com (Lucio Torre) Date: Mon, 22 Oct 2001 22:51:02 -0300 Subject: POLL in different OSes Message-ID: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> From the documentation: "The poll() system call, supported on most Unix systems" and my questions: a) is poll supported on Windows? my guess is no, but i hoping for a yes. thanks From aleax at aleax.it Fri Oct 12 04:45:11 2001 From: aleax at aleax.it (Alex Martelli) Date: Fri, 12 Oct 2001 10:45:11 +0200 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> Message-ID: <9q6aij$nnd$1@serv1.iunet.it> "Cliff Wells" wrote in message news:mailman.1002586507.19057.python-list at python.org... > On Monday 08 October 2001 14:39, Alan Miller wrote: > > > significant time internally plus a few hundred dollars in licensing fees > > are we much better off than if we'd gone out and bought a commercial > > library for $200? If nothing else the company is large enough that > > purchasing off-the-shelf libraries is pretty simple, while negotiating > > licenses is less so. > > The downside of purchasing a commercial library is that you usually don't get > the source code - just object files you can link against. Now imagine I thought sources came with most commercial libraries -- since you may need to recompile them with so many different options (MS VC++ is very unforgiving about linking object codes compiled with different runtime libraries, etc, etc). I'm pretty sure we have source for all the commercial libraries we use, with the possible exception of Intel's (I'm not sure if Intel's high performance numerics libraries do all come with source) -- Microsoft's MFC and ATL, Stingray and Rogue Wave libs, and so on. Non-commercial open-source libraries with non-restrictive licenses (a la BSD, X, or Python) are of course another class of alternatives yet. Alex From bernie at pacific.net.hk Fri Oct 5 22:47:56 2001 From: bernie at pacific.net.hk (Bernie) Date: Sat, 06 Oct 2001 02:47:56 GMT Subject: IDLE crash (2.0 with VPython) on unicode string Message-ID: <3BBE70D1.A4CC60DB@pacific.net.hk> Hi, I am using Pyhton 2.0 (with VPython extension) on MS Windows 98, Second Edition (Chinese), and have encountered a crash when I try to use Unicode string. I understand that the use of VPython did push back the IDLE version back to version 0.5. I am trying to figure out if: - it was a known bug and was fixed; or - the crash was caused by VPython IDLE; or - it is a new bug Please try the following out on your IDLE: a = u'?d ?? ?? ?b ?q ?q ?? ?x ?P ?| ?? ?X ?? ?? ?E ?@ ?@ ?? ?? ?? ?? ' Thanks! Bernie ============================================================================ Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32 Copyright (c) 2000 BeOpen.com. All Rights Reserved. Copyright (c) 1995-2000 Corporation for National Research Initiatives. All Rights Reserved. Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. All Rights Reserved. IDLE 0.5 -- press F1 for help >>> a = u'?d ?? ?? ?b ?q ?q ?? ?x ?P ?| ?? ?X ?? ?? ?E ?@ ?@ ?? ?? ?? ?? ' ^ crash when hit _______________| Exception in Tkinter callback Traceback (most recent call last): File "c:\python20\lib\lib-tk\Tkinter.py", line 1287, in __call__ return apply(self.func, args) File "C:\PYTHON20\Tools\idle\PyShell.py", line 592, in enter_callback self.auto.auto_indent(event) File "C:\PYTHON20\Tools\idle\AutoIndent.py", line 270, in newline_and_indent_event c = y.get_continuation_type() File "C:\PYTHON20\Tools\idle\PyParse.py", line 332, in get_continuation_type self._study1() File "C:\PYTHON20\Tools\idle\PyParse.py", line 220, in _study1 str = string.translate(str, _tran) File "c:\python20\lib\string.py", line 308, in translate return s.translate(table, deletions) TypeError: translate requires exactly 1 argument; 2 given From sabren at manifestation.com Tue Oct 23 11:00:30 2001 From: sabren at manifestation.com (Michal Wallace) Date: Tue, 23 Oct 2001 11:00:30 -0400 (EDT) Subject: programming unlimited "categories" in python ? In-Reply-To: <97ae44ee.0110230529.5c33dd83@posting.google.com> Message-ID: On 23 Oct 2001, Stephen wrote: > Thank you for the advice, Terry. Sorry if I'm being obstinate, > but I think the problem is a little less simplistic than it first > appears. Let's look at the everyday addressbook in Act! or > Outlook ? How would you create unlimited levels of categorisation > and unlimited numbers of subcategories ? I haven't been reading this completely, but this sounds an awful lot like what yahoo does... I have an object called Node that does this. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/zike/zikebase/Node.py?rev=1.14&content-type=text/vnd.viewcvs-markup probably needs a cleanup, but that's the general idea. Cheers, - Michal ---------------------------------------------------------------------- let me host you! http://www.sabren.com me: http://www.sabren.net ---------------------------------------------------------------------- From quinn at seniti.ugcs.caltech.edu Fri Oct 12 18:49:36 2001 From: quinn at seniti.ugcs.caltech.edu (Quinn Dunkan) Date: 12 Oct 2001 22:49:36 GMT Subject: YOU ARE ALL GAY! References: Message-ID: [ spew ] On Fri, 12 Oct 2001 15:18:58 -0400, PoulsenL at capecon.com wrote: >Bizarrly enough it looks like stenography. Maybe just my paranoid self, but >it is english sounding gibberish. Actually i have seen stenographic >examples that were more coherent. Looks like a markov writer to me. I've seen a few of these posts lately, someone is apparently feeding usenet into a markov writer. Yawn. To relate this back to python, you can find one for yourself in Demo/scripts/markov.py. Have fun, but try not to spam usenet with it :) From aa at bb.cc Sat Oct 27 12:04:39 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Sat, 27 Oct 2001 18:04:39 +0200 Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> Message-ID: <3bdad7e6_3@corp-goliath.newsgroups.com> What is Stackless Python? Cheers, K?roly ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From sasoft at gmx.de Sat Oct 20 12:28:01 2001 From: sasoft at gmx.de (Stefan Antoni) Date: Sat, 20 Oct 2001 12:28:01 -0400 Subject: silly idea - interesting problem Message-ID: <20011020122801.A3963@cruciatuz.de> i got a silly idea about a small script which takes to strings (lets say "test" and "dust") and mixes them to "tdeusstt". i tried to code it because i thought it would be easy, but now i cannot find out _how_ to do it ;) i tried to "list()" the string and mix the items. but ... Anybody has a hint or even a solution? -- Thx in advance, Stefan Antoni From tjreedy at home.com Fri Oct 26 02:10:17 2001 From: tjreedy at home.com (Terry Reedy) Date: Fri, 26 Oct 2001 06:10:17 GMT Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> Message-ID: "Greg Ewing" wrote in message news:3BD8C9F6.BBBD605A at cosc.canterbury.ac.nz... > Terry Reedy wrote: > > > > An so it is. If the patterns do not match, an exception is raised. > > However, after the match, the names (in your example above) 'time', > > 'status', 'value', and 'boring' are then bound to the corresponding > > objects in the current namespace. > > In the case in question, i.e. > > () = () > > the patterns clearly do match. And, every name in > the LHS has a corresponding value in the RHS. The > numbers of both these things happen to be 0, but > so what? > > I think Michael Abbot is quite right. There's no > reason this shouldn't be a legitimate, albeit > degenerate, case of tuple unpacking. The above is only a special case of the general question he raised. He also thought that a,() = somefunc() should be legal -- matching, I presume, something like 1,(). Do you agree with that also? I think the logic is the same. Terry J. Reedy From gcash at luncheonmeat.cfl.rr.com Tue Oct 16 20:15:32 2001 From: gcash at luncheonmeat.cfl.rr.com (gcash) Date: Wed, 17 Oct 2001 00:15:32 GMT Subject: Tkinter Canvas.create_line Windows/Linux difference for dashes References: <3BCC7A9D.AC1F699A@floconsult.be> Message-ID: FloConsult SPRL writes: > gives a dashed line under Linux, but a continuous line under Windows > (tried on NT, 98 and Me). Can somebody give me an advice on how to > obtain the same dashed effect on Windows ? Didn't find anything in tha > FAQs. >From the canvas(n) man page for Tk 8.3: On systems where only a limited set of dash patterns, the dash pattern will be displayed as the most close dash pat? tern that is available. For example, on Windows only the first 4 of the above examples are available. The last 2 examples will be displayed identically as the first one. So it appears that Windows simply doesn't support that dash pattern. -gc -- Favorite god: Thor Favorite song: "Hammer Time" Motto: "Use a bigger hammer" In my toolbox: 1 screwdriver, 6 hammers. Often heard saying: "... then I used a hammer on it" From mmichalski3 at home.com Mon Oct 15 14:04:55 2001 From: mmichalski3 at home.com (MM) Date: Mon, 15 Oct 2001 18:04:55 GMT Subject: mod_python seems to be missing a file Message-ID: I've followed the mod_python documentation to the letter. It seems to be on the verge of working with the one following problem: from mod_python import apache this is the first line of the test program you're told to write to see if you're up and running. The problem with this is that the apache.py file in the mod_python package is trying to import a file called _apache. I cannot find this file anywhere and, apparently, neither can Python, since it complains about it, as well. Any help on where this file can be found would be appreciated. From qrczak at knm.org.pl Mon Oct 22 11:44:27 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: Mon, 22 Oct 2001 15:44:27 +0000 (UTC) Subject: Curious assignment behaviour References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> <3bcdbb39.1987133892@news> Message-ID: Mon, 22 Oct 2001 13:48:46 +0200, Nomad pisze: >>It depends on the language. There are languages where 'let x = y' >>introduces the name x, defined as y, and its value can't change. > > But, surely, if (as you mention above) x is introduced > (defined/dimensioned... whatever), then x's value _will_ be changed > from (in python terms) None to that defined in y? No. Python, as most languages, distinguishes between a nonexistant variable and a variable bound to None. Introducing a local variable which shadows any previous meaning of the given identifier (if any) is not the same as changing the value of the variable. It's a completely new variable, indepepdent from any previous meaning of the given identifier. -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From gleki at gol.ge Tue Oct 23 14:54:23 2001 From: gleki at gol.ge (Giorgi Lekishvili) Date: Tue, 23 Oct 2001 11:54:23 -0700 Subject: unnecessary change Message-ID: <3BD5BCDF.B40C1422@gol.ge> Hi folks! My problem is the following: I want to save initial data matrix, as e.g., follows self.Mdata=Matr In the same time I need a matrix, which is used and processed. The latter is created as follows self.Mactual=self.Mdata No the problem is, that, when I have finished to use the Mactual matrix, self.Mdata is always changed and equals the final Mactual matrix. What is the systematic solution of the problem? Thanx in advance, Giorgi PS. I use Numeric module. From greg at cosc.canterbury.ac.nz Thu Oct 25 21:32:42 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 26 Oct 2001 14:32:42 +1300 Subject: Conditional expressions (again) References: <9r96tv$m26$1@thorium.cix.co.uk> <3BD84F71.6E035616@alcyone.com> Message-ID: <3BD8BD3A.B9F5C456@cosc.canterbury.ac.nz> Erik Max Francis wrote: > > gbreed at cix.compulink.co.uk wrote: > > > x = b if a else (d if c else e) > > > Nested conditional expressions get extremely hard to read very quickly. Write that as x = ( b if a else d if c else e ) and it looks a lot clearer. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From skip at pobox.com Sun Oct 21 11:04:34 2001 From: skip at pobox.com (Skip Montanaro) Date: Sun, 21 Oct 2001 10:04:34 -0500 Subject: Magic Module Methods? In-Reply-To: <9qt1qm$f7l$1@tyfon.itea.ntnu.no> References: <9qt1qm$f7l$1@tyfon.itea.ntnu.no> Message-ID: <15314.58370.443288.978445@beluga.mojam.com> >> [Magnus Lie Hetland] >> > I just found myself needing (or wanting) a module which could have >> > default values for variables that weren't set; >> >> I expect it would be near-infinitely clearer if you simply set the >> module variables to their default values explicitly at module >> initialization Let me suggest another reason __getattr__ might be useful for modules. Suppose you had a package made up of lots of modules. Instead of importing all of those modules into the package when the package was imported, with __getattr__ could you defer import until first access? -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From madsdyd at challenge.dk Sun Oct 7 14:15:35 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Sun, 7 Oct 2001 20:15:35 +0200 (CEST) Subject: (Solution) Re: Problem with embedding - can only make about 150 calls... In-Reply-To: Message-ID: On Sun, 7 Oct 2001, Mads Bondo Dydensborg wrote: > I am in the process of embedding Python in a program. I am running into > some weird problems with my program/Python crashing. I found a solution > static PyObject * MyTest(PyObject * self, PyObject *args) { > return Py_None; return Py_BuildValue(""); > } Fixes my problem. I can not explain where I got the Py_None from - maybe the documentation for embedding stuff should be clearer about this. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk Estimates of online gamers in the United States alone run as high as 15 to 20 million people. - Jon Katz, Slashdot, on youth culture. From sholden at holdenweb.com Mon Oct 29 04:59:28 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:59:28 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> <3BDCC4C9.B0597DF1@uoguelph.ca> <8djpttobn2i18avnq3817bmg1ua6eavq8r@4ax.com> Message-ID: "John S. Yates, Jr." wrote ... > On Sun, 28 Oct 2001 21:54:01 -0500, Jeff Dunnett wrote: > > >Emile van Sebille wrote: > > > >> "Jeff Dunnett" wrote in message > >> news:3BDCA674.FF268D0E at uoguelph.ca... > >> > > >> > [..SNIP..] > >> > quite a lot of fallowers who like Python. > ^^^^^^^^^ > >> > > >> > >>

> >> > >> Hopefully, they haven't simply put themselves out to pasture... > > > >I am not sure what I mean by your comment? > > Emile was punning on "fallow" (as in to let a pasture lie fallow) > versus "follow". > But it wasn't that funny, since nothing is ever simply black or white, good answers must always conside the graze. -- http://www.holdenweb.com/ From aa at bb.cc Thu Oct 25 15:39:30 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Thu, 25 Oct 2001 21:39:30 +0200 Subject: Question: Dynamic code import Message-ID: <3bd86540_2@corp-goliath.newsgroups.com> Hi, I've been experimenting with Python for a short period of time and I really enjoy it. It allows me to do a lot of things that are much harder or even not possible to accomplish in other languages. I'd like to receive comments on the following problems. 1. Is it possible to 'import' Python code in a dynamic fashion? For instance, the running program refers to function f1 through ff: def f1(a): return a*1.25 ff=f1 At some point, it turns out that f1(a) should return a*1.3+5. If it was possible to insert a new function, the running program could be modified like this: #--- this is to be 'imported' def f11(a): return a*1.3+5 #--- ff=f11 Now ff(a) would produce results by using the new rule embodied in f11! 2. Something is wrong with globals. Given the example below, I'd expect 2 for the second print. global gx gx=1 def set_gx(gx_new): gx=gx_new def test(): print gx # prints 1 set_gx(2) print gx # prints 1 ! Trying a simpler version of it produces something strange: a. #--- This one works, test() prints the global gx. global gx gx=1 def test(): print gx # prints 1 b. #--- This one runs to error -> 'UnboundLocalError: local variable 'gx' referenced before assignment' !!! global gx gx=1 def test(): print gx gx=2 c. #--- This one works but treats gx as local. Try test() first, then test1() will print the original 1 for the global gx! global gx gx=1 def test(): gx=2 print gx # prints 2 def test1(): print gx # prints 1! Thanks for any help. K?roly ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From chris at cmb-enterprises.com Tue Oct 9 02:33:26 2001 From: chris at cmb-enterprises.com (Chris Dutton) Date: Tue, 09 Oct 2001 02:33:26 -0400 Subject: Apache log file scanner References: <0Ujw7.291$wO4.40393@dfiatx1-snr1.gtei.net> Message-ID: in article 0Ujw7.291$wO4.40393 at dfiatx1-snr1.gtei.net, Jeff Sasmor at jeff at janix.com wrote on 10/8/01 11:47 AM: > If anyone is interested in a short Python script > that'll scan their Apache web server's log files > for break-in attempts from Code Red and a few > other worms, you should check out: > > http://www.netkook.com/Members/jeff/virusprobe Just a small note, as I'm perusing this at an ungodly hour. A better way to regexx match an IP might be: (\d{1,3}\.){3}\d{1,3} From jblazi at hotmail.com Wed Oct 3 13:47:52 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Wed, 3 Oct 2001 19:47:52 +0200 Subject: Basic button question References: <3bbb4a89_8@news.newsgroups.com> <1002130337.69458.1@eos.uk.clara.net> Message-ID: <3bbb4f63_8@news.newsgroups.com> > Try binding instead. Thx. I thought of that but it is not exactly what I should like to have. I should like to push the button, see that it is being pushed and go on after that. J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From lucio at movilogic.com Tue Oct 30 16:13:10 2001 From: lucio at movilogic.com (Lucio Torre) Date: Tue, 30 Oct 2001 18:13:10 -0300 Subject: ReXX Style translate() function for strings ? References: <3281a460.0110301257.1a4d9a14@posting.google.com> Message-ID: <3BDF17E6.2000604@movilogic.com> P Adhia wrote: >Hello, > >I am a newbie to python, and remain impressed with the power of the >language overall. There are however some little features that I am >used to in ReXX (default scripting language for mainframes) that I >could not find in python. > >ReXX has a translate() function that is much more powerful (and I >think coule be a nice addition to python; of course with a different >name) > >e.g. in ReXX, to change a date from yyyymmdd to mm/dd/yyyy is >trivially simple, >new_date = Translate('56/78/1234', old_date, '12345678') > >for formal syntax refert to, >http://users.comlab.ox.ac.uk/ian.collier/Docs/rexx_ref/F/BI > >Python's l/r/strip() functions always remove white spaces -- >corresponding ReXX functions (actually only one) has a optional >argument that defines what character to strip. e.g. removing leading >'0' from a number, punctualtion characters etc. > >If such functionality is trivial in python, I'll appreciate any new >addition to my growing python knowledge. > >TIA > >P. Adhia > This does that translation. surely it does not include the power of the ReXX tranlations, but is pretty flexible. def xlate(out, str, fmt): result = [" "]*len(out) for i in range(len(out)): if out[i] in fmt: pos = fmt.find(out[i]) result[i] = str[pos] else: result[i] = out[i] return "".join(result) From reqhye72zux at mailexpire.com Tue Oct 9 19:44:32 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Tue, 09 Oct 2001 23:44:32 -0000 Subject: Problems With ColourSelect Box Inside A wxDialog References: <9e7d101d.0110081223.32a8217e@posting.google.com> Message-ID: William Wonneberger wrote: > I'm trying to add a wxPython ColourSelect control to a wxDialog box > inside a Python script I've been working on. To instantiate the > ColourSelect control, I've added the following statement to my > Python script; > > self.colorselect = ColourSelect(self, wxPoint(70, 200), [0, 0, > 110], wxDefaultSize) That isn't much context to work on. There are a number of "psychic debuggers" in this ng, but I'm not one of them. > [...] > > Am I instantiating the ColourSelect control correctly? No, it should be: self.colorselect = ColourSelect(self, -1, [0, 0, 110], wxPoint(70, 200), wxDefaultSize) (And you might as well lose the wxDefaultSize, as that's the default parameter in cases like this.[*] The -1 can be replaced by an explicit ID value, if the need ever arises.) I'm amazed you see a memory leak warning, but no error message from Python itself. I often noticed memory leak warnings after a stack trace. This hardly ever crashes wxPython, but does seem to interfere with properly disposing some of the objects that have been created. Once you fix the error the leak will disappear. > Am I missing an additional statement to enable or make visible the > ColourSelect dialog box? No, It's actually just a wxButton type control, but the caption has been replaced by a colour. Robert Amesz -- [*] If you use sizers, you gan get rid of the initial position, too. Using sizers in dialogs is a bit more critical in dialogs than in normal wxFrames/Windows/Panels, though. From thomasNO at SPAM.obscure.dk Wed Oct 17 07:33:56 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Wed, 17 Oct 2001 11:33:56 GMT Subject: profiler results for __getattr__, am I reading this correctly ? References: Message-ID: "Tim Peters" wrote in news:mailman.1003288997.28703.python-list at python.org: > [Thomas Jensen] >> I'm working on a Gnutella client, and were beginning to look a bit >> at performance. After running it through the profiler module, it >> seems most of the time is spent in asyncore.dispatcher's >> __getattr__ method. (used for socket pseudo-inheritance AFAIR). >> My question is, can this be true?, > > Certainly, but unlikely. I'm delighted to hear that. >> or am I reading the results incorrectly ? > > Probably not, and more likely that the results are incorrect. > > Try grabbing profile.py out of the current CVS tree (it should run > fine under 2.1.1 too, and under 2.0.1). Thanks, I'll try that > There was a systematic bug > that caused time to get charged to the wrong functions, when a > Python exception got raised by Python code but caught and cleared > by C code before returning to Python. For example, hasattr() > routinely screwed up profiling results. One symptom is tiny > functions reported to take mountains of time when you're pretty > sure they don't; That sounds like what happened to me. > another symptom is the profiler reporting that a > function you know darned well isn't recursive was actually involved > in recursive calls. All that was due to the profiler's view of the > call stack getting out of synch with reality by one frame. The bug > existed for years, and was just fixed within the last couple of > weeks. Ok, that would explain the other curious line in the output. > Note that the current (CVS) profile.py also has a new, more > accurate, and less intrusive calibration procedure. Calibrating > the profiler for the box it's running on can be important. Docs > for that can be gotten from CVS, or from 2.2b1 to be released this > Friday. I'll look into it. Thanks alot for the quick answer. Now I can start looking for the real performance problems, like moving GUID's from objects to strings :-) -- Best Regards Thomas Jensen From rand0m at nelvento.it Tue Oct 30 17:14:22 2001 From: rand0m at nelvento.it (rand0m) Date: Tue, 30 Oct 2001 22:14:22 GMT Subject: Programming Python by Mark Lutz 2nd Ed. References: Message-ID: <2DFD7.12042$7A4.761354@news.infostrada.it> Thank You Fredrik ;-) Lorenzo From brueckd at tbye.com Wed Oct 24 15:47:28 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 24 Oct 2001 12:47:28 -0700 (PDT) Subject: Curl-ing, anyone? In-Reply-To: <458b194a.0110241156.795e9618@posting.google.com> Message-ID: On 24 Oct 2001, Resty Cena wrote: > Is Curl (www.curl.com) a threat to Python (and Ruby, and Perl)? Is it cheaper than free? From sholden at holdenweb.com Wed Oct 3 12:25:34 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 3 Oct 2001 12:25:34 -0400 Subject: mx.ODBC/Cygwin/Python 2.1.1 Message-ID: Has anyone built the mxCommercial extensions for Cygwin? I'm having many problems which look so fundamental I'm hoping they have a really simple fix. This is where they begin: running build_ext building 'mx.ODBC.iODBC.mxODBC' extension gcc -g -O2 -Wall -Wstrict-prototypes -DUSE_DL_IMPORT -DiODBC -Imx/ODBC/iODBC -I/usr/local/include -I/usr/include/python2.1 -c mx/ODBC/iODBC/mxODBC.c -o build/temp.cygwin-1.3.3-i686-2.1/mxODBC.o In file included from /usr/include/w32api/sql.h:9, from mx/ODBC/iODBC/mxODBC.h:239, from mx/ODBC/iODBC/mxODBC.c:33: /usr/include/w32api/sqltypes.h:13: parse error before `UDWORD' /usr/include/w32api/sqltypes.h:13: warning: data definition has no type or storage class /usr/include/w32api/sqltypes.h:14: parse error before `UWORD' /usr/include/w32api/sqltypes.h:14: warning: data definition has no type or storage class /usr/include/w32api/sqltypes.h:20: parse error before `PTR' /usr/include/w32api/sqltypes.h:20: warning: data definition has no type or storage class Things get rapidly worse from there, with serious errors reported in other include files, eventually leading to errors compiling mx/ODBC/iODBC/mxODBC.c. Anyone know the answer? I've mailed Marc-Andre Lemburg directly, but he may well be too busy to help. regards Steve -- http://www.holdenweb.com/ From loewis at informatik.hu-berlin.de Wed Oct 17 10:11:38 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 17 Oct 2001 16:11:38 +0200 Subject: makefile for disutils pacakge? References: <33803989.0110162247.56b508cf@posting.google.com> Message-ID: tebeka at cs.bgu.ac.il (Miki Tebeka) writes: > Is there a 'standard' makefile to ship with a distutils package > (./setup.py sdist)? Not that I know of. It appears that a makefile would be just for people who expect to invoke 'make' when they get a Python package. OTOH, existence of a makefile may confuse people that expect to run setup.py, and wonder what the makefile is for. Please note that a makefile will also confuse people that expect to run "configure" and wonder why there is no autoconf support. So my recommendation: Leave out the makefile, and include an INSTALL file saying that setup.py is *the* driver for everything. Regards, Martin From phd at phd.pp.ru Fri Oct 19 11:39:24 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 19 Oct 2001 19:39:24 +0400 Subject: mimedecode.py version 1.0.4 Message-ID: <20011019193924.C11164@phd.pp.ru> Hello! MIME decode WHAT IS IT Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is very good because it allows us to use apropriate formats/encodings/whatever. Sometimes, though, some unification is desireable. For example, one may want to put mail messages into an archive, make HTML indicies, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary atachmetnts will be much desireable. Here is the solution - mimedecode.py. This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which treated as an RFC822 mesage, and decoded to stdout. If the file is not an RFC822 message the file just piped to stdout one-to-one. If it is a simple RFC822 message it is just decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts decoded. Decoding can be controlled by command-line options. WHAT'S NEW in version 1.0.4. Open a pipe (copiousoutput filter) with explicit 'r' mode. Fixed minor bug with additional spaces in strings decoded by RFC2047. Now all "Windows-CP" charsets mapped to "cpCP" code pages. WHERE TO GET Master site: http://phd.pp.ru/Software/Python/#mimedecode Faster mirrors: http://phd.by.ru/Software/Python/#mimedecode http://phd2.chat.ru/Software/Python/#mimedecode Requires: Python 2.0+ (actually tested with 2.1.1), configured mailcap database. Documentation (also included in the package): http://phd.pp.ru/Software/Python/mimedecode.txt http://phd.by.ru/Software/Python/mimedecode.txt http://phd2.chat.ru/Software/Python/mimedecode.txt AUTHOR Oleg Broytmann COPYRIGHT Copyright (C) 2001 PhiloSoft Design LICENSE GPL Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From nas at python.ca Wed Oct 17 00:23:04 2001 From: nas at python.ca (Neil Schemenauer) Date: Tue, 16 Oct 2001 21:23:04 -0700 Subject: profiler results for __getattr__, am I reading this correctly ? In-Reply-To: ; from tim.one@home.com on Tue, Oct 16, 2001 at 11:22:13PM -0400 References: Message-ID: <20011016212304.A19672@glacier.arctrix.com> Tim Peters wrote: > Try grabbing profile.py out of the current CVS tree (it should run fine > under 2.1.1 too, and under 2.0.1). There was a systematic bug that caused > time to get charged to the wrong functions, when a Python exception got > raised by Python code but caught and cleared by C code before returning to > Python. I've ran into this problem just the other day and using profile.py out of CVS fixed it for me. Hmm, 2.1.2? Neil From sill at optonline.net Wed Oct 17 09:58:52 2001 From: sill at optonline.net (Andrei Kulakov) Date: Wed, 17 Oct 2001 13:58:52 GMT Subject: Desperate help required for Python assignment References: <602c058e.0110162347.268591ce@posting.google.com> Message-ID: On 17 Oct 2001 00:47:07 -0700, Nachiket wrote: > I am new to Python doing a crash course in University. I have a > assignment to submit in two days the specifications of which are: Relax. You don't need to submit that assignment. You don't even need a degree. You just need some problem-solving abilities. [snip] -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From Randy.L.Kemp at motorola.com Tue Oct 16 11:58:49 2001 From: Randy.L.Kemp at motorola.com (Kemp Randy-W18971) Date: Tue, 16 Oct 2001 10:58:49 -0500 Subject: Python, Unix sendmail, and multiple recipients Message-ID: <81F59ACE9063D511A5BB0002B328D226511596@il93exm20.css.mot.com> Can anyone give me an example of how to invoke the Unix sendmail in Python, and send an email message to more then one recipient (two people, for example)? From plakal-nospam at nospam-cs.wisc.edu Thu Oct 4 00:44:42 2001 From: plakal-nospam at nospam-cs.wisc.edu (Manoj Plakal) Date: Wed, 3 Oct 2001 23:44:42 -0500 Subject: A little amusing Python program References: <3bbaf6c9$0$244$edfadb0f@dspool01.news.tele.dk> Message-ID: <3bbbe93a$0$2693$80265adb@spool.cs.wisc.edu> Cool! I can think of at least one "useful" application: automating cheating for Who Wants to be a Millionaire. As it is, when people phone their friend, you can sometimes hear some frenzied typing over the line ... Manoj Max M wrote: > I have written this little Python program that usually raises a few > eyebrows. It answer multiple choice questions. > > It is very simple. ie. > > question = 'What is Python' > choices = ( > 'a programming language', > 'a tv series', > 'a snake' > ) > It then queries google with: > > "What is Python a programming language" > "What is Python a tv series" > "What is Python a snake" > > and chooses the result that gets the most hits. > > Simple, but far better then random. > > Well it's not of much use, but kind of fun and very low budget AI ... From merkosh at hadiko.de Fri Oct 5 07:19:57 2001 From: merkosh at hadiko.de (Uwe Mayer) Date: Fri, 5 Oct 2001 13:19:57 +0200 Subject: Tkinter: menu entry - icon+text Message-ID: Hi there, i was trying to create a menubar where each entry in the i.e. "File" pull down menu was equipped not only by a text xor an icon but both: [ ] i.e. [ New Document Ctrl-N] however the Tkinter.Menu.add() method only supports 'command', 'cascade', 'checkbutton', 'radiobutton' and 'separator'. Originally I tried to pack the icon, text and shortcut into a frame widget, but Menu won't accept or display it propperly. Is there any workaround? Thanks in advance for any help. Yours Uwe From topdog at web.de Mon Oct 29 09:53:27 2001 From: topdog at web.de (Andreas Zieringer) Date: Mon, 29 Oct 2001 15:53:27 +0100 Subject: Destroying all instances (references) Message-ID: <200110291453.f9TErRu16385@mailgate5.cinetic.de> >Hi, > >is it possible to destroy all created instances, something like an "new" >command in basic? I >know re-creating the interpeter would do this, but in the new interpreter I >have to import >all modules again and I can't do this. Is there an easy way doing this in >pythom or with the c-api? I couldn't >find anything in the python docu. > >Regards > >Andreas > >This will clear all objects in __main__ that don't start with an >underscore: >import __builtin__ >def _init(_type='vars'): > import sys, types > main = sys.modules['__main__'].__dict__ > for i in main.keys(): > if not i.startswith('_'): > if _type == 'all': > del main[i] > elif _type == 'vars': > if type(main[i]) != types.ModuleType: > del main[i] >__builtin__.init = _init >If you create/add this to lib/sitecustomize.py then you will be able to >invoke init() to clear the references. > >HTH, > >Emile van Sebille Thanks for the code, it works perfect for me. :-) Andreas ________________________________________________________________ Lotto online tippen! Egal zu welcher Zeit, egal von welchem Ort. Mit dem WEB.DE Lottoservice. http://tippen2.web.de/?x=13 From tim.one at home.com Mon Oct 15 14:13:27 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 15 Oct 2001 14:13:27 -0400 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) In-Reply-To: <7xitdha8tg.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > How did Algol 60 deal with this? You can study it yourself if you really care: http://www.masswerk.at/algol60/report.htm A key difference is that Algol-60 strictly distinguished between statements and expressions, while Python allows any expression to be used as if it were a statement (primarily for convenience in interactive mode). So "if" at the start of an Algol-60 statement can only mean an Algol-60 follows, never an Algol-60 . Python can't distinguish the expression form from the statement form until seeing "then" or ":". [Rainer Deyke] > Actually, it would probably be possible to make the parens optional in > all cases except where 'if' is the first token of the expression. Perhaps, with enough pain. I think the parens *usually* aid readability, though, so would be more selective about it. > The required changes in the grammar are quite small: > > 1. Replace all rhs instances of "testlist" with "any_expression", > *except* the first one in "expr_stmt". > 2. Add the following production: "any_expression: testlist > | 'if' any_expression 'then' any_expression 'else' any_expression". Too painful: changing the production names in a dozen places has to propagate into tools too (like parsermodule.c's verification code, and the Lib/compiler package). Better to allow for the absence of parens in specific contexts where they're really silly: > (This still doesn't allow unadorned conditional expressions in > places where "testlist" is not used, such as function arguments.) But requiring them is silliest in f((if 1 then 2 else 3)) and [(if 1 then 2 else 3)] etc, i.e. in the contexts that don't cater to testlists now. [Chris Tavares] > May I be the first to say - ICK! Yes, you may. > I have enough political problems trying to get people I know to try > python out - adding a wart like this ( and requiring parens on this one, > and only one expression is really a wart!) and trying to explain it to > newbies doesn't strike me as a winner, and I've never really pined for > this as an experienced user. Noted. Guido thinks a conditional expression of *some* flavor is a good idea, so you know how this ends in the end . > Question - what happens with: > > x = (if e1 then e2 else e3,) # <--- note trailing comma SyntaxError. > Should be a 1 element tuple, yes? Sorry, I don't know what you think that should do, or what "should be a 1 element tuple" means. Do you mean it should return e2 if e1 is true, and (e3,) if e2 false? Or that it should return (e2,) if e1 is true, and (e3,) if e2 false? If the former x = (if e1 then e2 else (e3,)) and if the latter either x = (if e1 then (e2,) else (e3,)) or x = (if e1 then e2 else e3), would do it. > What happens? SyntaxError. e1 and e2 and e3 are instances of 'test', not of 'testlist'. > Or would you have to write: > > x = ((if e1 then e2 else e3),) That would also work, although the outermost parens aren't necessary there. > That's just ugly. Singleton-tuple notation has been "ugly" since 1991; you seem here more to be complaining about that than about conditional expressions. [Michael Abbott] > Oh, while we're being concrete about the syntax, don't forget to allow > elif in conditional expressions! It wasn't forgotten, it was left out. You can spell it "else if" but are discouraged from abuse (if you need a long chain of these, you should probably be using a dict lookup). [Ian Parker] > ... > Because statements are expressions in Algo68, the 'if' clause returns a > value, and can be used as both a statement and an expression, and either > can be squeezed onto one line or spread across multiple lines. The model here is Algol-60, not 68. > ... > However, it does suggest the question: Would this new Python > conditional expression support: No. [Andrew Dalke] > ... > I *like* > > if e1: > x = e2 > else: > x = e3 > > Makes it easy to see what goes on when e1 is true or false. The thrust is for simple cases where that construct requires introducing a temp name that wouldn't otherwise be needed, much as "and" and "or" are routinely used today to avoid otherwise-pointless temps. a[i-j+1] = (if e1 then e2 else e3) is likely clearer than if e1: temp = e2 else: temp = e3 a[i-j] = temp or if e1: a[i-j+1] = e2 else: a[i-j+1] = e3 > Take Uncle Tim's example code > > x = (if a+b/sqrt(3) then 3**f(5, 3)- 12 else ",".join(list) + ":\n") In context, it was an example trying to provoke someone else into spelling out what they meant by "generalization", by showing how stupid you *can* be with this gimmick. I wouldn't write it that way (indeed, I wouldn't write code like that any other way either ). > ... > There's talk of generalization. But more likely the expansion of a > one-liner like the above is to add more statements to a branch, as > in something like: > > if a+b/sqrt(3): > count = count + 1 > x = 3**f(5, 3) - 12 > else: > spam *= count > x = ",".join(list) + ":\n" > > With the one-liner form, translation to the normal Python if/else > statement calls for a lot of code changes. Use any construct when it's inapproriate and you'll pay a price. There are appropriate uses for conditional expressions, as any C, C++, Perl, Icon, Haskell, ML, Scheme etc programmer can testify from experience (I hesitate to say Algol-60 programmer, because I'm not sure there are any anymore! but that's where Guido remembers it from). > I tried looking through the thread in its various subject names. > I couldn't figure out what was the driving reason for this idea. > (Other than as a replacement for C's ?: ternary operator.) > Enlightment, anyone? It's a conditional expresssion -- that's all. It's been debated for years, on Python-Dev most persistenly by Eric Raymond. It came up in internal PythonLabs discussions late last week, as an offshoot of a "should we try to reserve any other keywords for 2.2?" discussion. Guido figured it was time to at least try it, fiddled the grammar for if/then/else, and I implemented it over the weekend. It has not been checked in yet. If it turns into a time sink (which it is on the edge of becoming), it will go away (if it's not in 2.2b1 later this week, it won't go in at all). From skip at pobox.com Wed Oct 31 11:58:24 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 31 Oct 2001 10:58:24 -0600 Subject: List -> Tuple In-Reply-To: <000901c1622b$c4fe4b00$a905a8c0@JWILHELM> References: <15328.10405.274307.841421@beluga.mojam.com> <000901c1622b$c4fe4b00$a905a8c0@JWILHELM> Message-ID: <15328.11696.828984.438540@beluga.mojam.com> Joseph> Ah, thank you much, exactly what I was looking for! Wasn't quite Joseph> sure if that function really was sitting around. You can always import the __builtin__ module and pass it to dir to see what objects are available from the get go: >>> import __builtin__ >>> dir(__builtin__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'FloatingPointError', 'IOError', 'ImportError', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'OverflowWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TypeError', 'UnboundLocalError', 'UnicodeError', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__debug__', '__doc__', '__import__', '__name__', 'abs', 'apply', 'buffer', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dictionary', 'dir', 'divmod', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'round', 'setattr', 'slice', 'staticmethod', 'str', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip'] If you are using a recent version of Python there is a help function builtin as well (if not, try importing pydoc and using its help function), so you can get online docs for just about anything: >>> help(tuple) Help on class tuple in module __builtin__: class tuple(object) | tuple() -> an empty tuple | tuple(sequence) -> tuple initialized from sequence's items | | If the argument is a tuple, the return value is the same object. | | Methods defined here: ... -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From rerla at channing.harvard.edu Thu Oct 11 16:26:56 2001 From: rerla at channing.harvard.edu (Ross Lazarus) Date: Thu, 11 Oct 2001 16:26:56 -0400 Subject: Compiling PIL 1.1.2 with Python-2.1.1 on Solaris References: <3BC5A46A.8D85ED8E@channing.harvard.edu> <3BC5E83D.94784D06@astro.cornell.edu> Message-ID: <3BC60090.E784CD99@channing.harvard.edu> Ah! That was it. Thanks for the tip - I had to add -fPIC to the Makefile in libImaging and recompile all that stuff first, but then it compiled like a charm. AFAIK -fPIC means positional independent code or something FWIW... Tom Loredo wrote: > > Hi Ross- > > If you do a Google search in this group for "Solaris" I bet you'll > find several posts about this problem! > > Before running "make" in step 4 of the PIL instructions, edit the > > Tom Loredo From loewis at informatik.hu-berlin.de Fri Oct 12 07:44:01 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 12 Oct 2001 13:44:01 +0200 Subject: J2EE equivalent in Python References: Message-ID: Robin Smith writes: > I like J2EE but I am also an open source fan. What exactly is it that you like about J2EE? Regards, Martin From guido at python.org Wed Oct 17 02:52:36 2001 From: guido at python.org (Guido van Rossum) Date: Wed, 17 Oct 2001 06:52:36 GMT Subject: Conditional Expressions don't solve the problem References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: Dale Strickland-Clark writes: [for...else example snipped] > Having not seen this before, I'm a bit surprised at the choice of the > word 'else' here. It's not an alternative. It's a conclusion. I would > have thought 'then' or 'finally' would have been more appropriate. It comes from the analogy between while : else: and if : else: In both cases, when is false, a jump to the else: label is taken. >From this it also follows that the else part of a loop is skipped when a break is taken -- hence finally would be wrong. > Is iter just an extra object layer to map the interface. Will it be an > overhead? What do you mean? --Guido van Rossum (home page: http://www.python.org/~guido/) From ullrich at math.okstate.edu Thu Oct 18 13:37:59 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Thu, 18 Oct 2001 17:37:59 GMT Subject: Assignment direction (Re: Curious assignment behaviour) References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> <3bcdbb39.1987133892@news> <3BCE23A9.E39D04C2@cosc.canterbury.ac.nz> Message-ID: <3bcf12be.2075087802@news> On Thu, 18 Oct 2001 13:34:49 +1300, Greg Ewing wrote: >"David C. Ullrich" wrote: >> >> What if you already have x = 42 and y = 24, and you >> say "let x = y" ? Does that set x to 24 (yes) or >> does it set y to 42? > >I'd say it confuses the reader, without further >explanation. Clever of you to omit the context. You'd just said that "let x = 42" and "let 42 = x" mean the same thing "mathematically". They don't; the order in an "assignment" like that matters, as the example shows. If you're confused by "let x = y" my advice is not to try to read a lot of mathematics. [...] >-- >Greg Ewing, Computer Science Dept, University of Canterbury, >Christchurch, New Zealand >To get my email address, please visit my web page: >http://www.cosc.canterbury.ac.nz/~greg From DeepBlue at DeepBlue.org Thu Oct 11 15:48:47 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Thu, 11 Oct 2001 14:48:47 -0500 Subject: CGI question on input type=text form elements References: <3acd06c8.0110111028.7e057da0@posting.google.com> Message-ID: Rhett I discovered that this is happening when the form is enclosed in a table. For example: Why a form in a table? Actually, I have four forms on rhe web page and I need to arrange them in a certain way. Anyway, when the form is in a table I am getting the text_1 key. No table, no key. If you have the time, try it and let me know if you are getting the same thing. I am using IPlanet on Solaris with Python 2.1 Thanks DB "Rhett" wrote in message news:3acd06c8.0110111028.7e057da0 at posting.google.com... > You must have made a silly mistake somewhere. Either that or there is > a browser/web server issue. This works fine for me on apache under > linux, python 2.1.1 > > [index.html] > > > > > > > > [poster.cgi] > #!/usr/bin/python > > import cgi > > form = cgi.FieldStorage() > > print 'Content-type:text/html\n\n' > for f in form.keys(): > print str(f) + ': ' + str(form[f].value) > > > > "DeepBlue" wrote in message news:... > > I am running into a strange problem with a form while using CGI module in > > Python. > > Let us say I have the following form: > >
> > > > > > > > > > Now, let us say that test_form=cgi.FieldStorage() > > If the above form is submitted without typing anything in the text field one > > expects test_form.keys() to generate: > > ['submit'] > > > > But i am getting: > > ['text_1', 'submit'] > > Which is unexpected, and in my case, undesirable. What am I doing wrong? > > DB From s.keim at laposte.net Fri Oct 26 03:06:54 2001 From: s.keim at laposte.net (sebastien) Date: 26 Oct 2001 00:06:54 -0700 Subject: Can't copy iterator object References: Message-ID: <7da8d8f8.0110252306.17ec3d7a@posting.google.com> > I'm not supposed to do so? This could be useful... > > Python 2.2b1 (#25, Oct 19 2001, 11:44:52) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> i = iter([1,2,3]) > >>> import copy > >>> copy.copy(i) > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python22\lib\copy.py", line 84, in copy > y = _reconstruct(x, reductor(), 0) > File "C:\Python22\lib\copy_reg.py", line 56, in _reduce > state = base(self) > TypeError: cannot create 'iterator' instances I had posted the same question few days before: here are the answers http://groups.google.com/groups?hl=en&frame=right&th=6499660bd77fd7fc&seekm=7da8d8f8.0110230006.36933486%40posting.google.com#link1 Maybe a potential new entry in the FAQ? From daves_spam_dodging_account at yahoo.com Mon Oct 29 13:26:27 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Mon, 29 Oct 2001 10:26:27 -0800 (PST) Subject: win32clipboard for python 2.2.1? Message-ID: <20011029182627.53586.qmail@web21108.mail.yahoo.com> Hello, I'm trying to track down win32clipboard for Python 2.1.1. I have the version of Python from www.python.org, I assume that's the "CNRL" version? I have tracked win32clipboard to the win32all package by Mark Hammond; who directs traffic to ActiveState.com. Phew. It looks like the latest release of win32all for CNRL is for Python 1.5.2 or 1.6... ...does anyone know if win32clipboard is available for Python 2.1.1? Thanks, -dB ===== David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From phr-n2001d at nightsong.com Wed Oct 17 04:06:28 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 17 Oct 2001 01:06:28 -0700 Subject: Conditional Expressions don't solve the problem References: Message-ID: <7xr8s2zo57.fsf@ruckus.brouhaha.com> Guido van Rossum writes: > On the other hand, the ability to hide an assignment inside an > expression is IMO purely a way to save some keystrokes: the variable > needs to be named anyway, so you may as well do the assignment in a > separate step so that the reader is alerted of it. But it's not just saving keystrokes--the usual place for an assigment in an expression is in the control expression for a while loop. Having to split it into several statements clutters up the code and makes the readability WORSE by moving the test condition away from the 'while' keyword. Do you REALLY find while (line := file.readline()) != 'end': process_line(line) to be less readable than while 1: line = file.readline if line == 'end': break process_line (line) (or worse, imagine several nested loops like that)? I don't. > That said, I'm still looking for decent examples of places in the > standard library that would become more readable with a conditional > expression... Without more motivation, I think I'll hold back. The .py files in the standard library aren't really the right place to look. They were written without those constructs and the authors may have formulated particular pieces of code in ways considerably different than if they had conditional expressions available (as opposed to just splitting the expressions into a few statements). It's better to scan through the C code of the interpreter and the library C modules, rather than the .py files, and see how many places ?: and assignments in expressions are used. That said, there's enough alternatives hashed out on the thread without a clear winner emerging that it's best to not put conditional expressions into 2.2. From jim at publishingresources.com Thu Oct 18 17:51:43 2001 From: jim at publishingresources.com (Jim Abrams) Date: Thu, 18 Oct 2001 21:51:43 -0000 Subject: PythonWin ASP performance References: <7a7a07a.0110170719.7a347008@posting.google.com> Message-ID: "maxm" wrote in : > >"Jim Abrams" >> Using Python makes life easier in so many ways I can't even begin to >> describe them all, but some of the main ones are the object oriented >> approach. (We've encapsulated the ASP Built-in objects with Python >> wrappers that solve alot of VBscript ickiness, and are subclassable) > >I have tried Python asp, but found some ick-ines where the indenting >messes up the clarity of the asp page. > >in something like: > ><%for i in range(10):%> > ><%= i%>
> >I have to write: > ><% >for i in range(10): > Response.Write('' + i + '
') >%> > >instead. > >In this simple example it isn't that bad, but when writing longer html, >tables etc it sort of defeats the purpose of asp. Suddenly I get logic >and presentation forced together. > >Have you got any good soultions to that? > >regards Max M I agree, pretty icky. There's alot of approaches to solve this issue (as mentioned by other posters), but here's what I do, and it seems to work pretty well. (Without investing into some type of content vs. presentation packages) If its a fairly simple block of HTML, put it inside a triple-quotes string and then use %-subs for data. print >> _out, '''
''' % (enc(path), f_type) But you have to watch out for the regular %'s throwing you off. Or, (and this is the method I find most useful), there is the HTMLgen package. Simply put, it takes all the HTML tags and converts them into Python classes. Makes life easier. print >> _out, TR(TD( TableLite(TR( TD(Bold(objRS.prev_link(me2), html_escape='off')), TD(" :: "), TD(Bold(objRS.next_link(me2), html_escape='off')) )), align='right', colspan=3 )) You get the idea. ><%for i in range(10):%> ><%= i%>
to ><% >for i in range(10): > print >> _out, Font(i, size='+1'), BR() >%> From bobh at hslda.org Thu Oct 11 08:53:35 2001 From: bobh at hslda.org (Robert) Date: 11 Oct 2001 05:53:35 -0700 Subject: YOU ARE ALL GAY! References: <9q2k92$2vd$1@plutonium.btinternet.com> Message-ID: <4a249347.0110110453.726dfe5a@posting.google.com> How did he know I was an all around jovial guy? From francois.lepoutre at seriatim.com Thu Oct 25 05:27:43 2001 From: francois.lepoutre at seriatim.com (François Lepoutre) Date: Thu, 25 Oct 2001 11:27:43 +0200 Subject: form like foxbase References: Message-ID: <9r8kr8$e34$1@wanadoo.fr> Hi, I understand that "fox base" means the successful the "dbaseiii clone" launched by fox software in the olds days. I used it extensively in the past. If this is what you are looking for, you could use python + a GUI toolset to build your app. I have not done it. But i do not feel python would be the easiest tool. But neither python nor python-GUI modules are data-aware as dbase clones were. Nor do you get automatic updatabae db-grid a native report writer. That may mean quite a bit of work. I have no practical experience of data-intensive client-server apps running python and a high-end graphical interface. I would welcome any report on that. Just my 2 cents Fran?ois "indosatnet" wrote in message news:NKSB7.2917$96.27189 at news... > Dear python expert, > What module should I use to develop an application accesing mysql / > postgresql such that the form entering / editing data is just like the form > in fox base, i.e user can move around using up,down cursor (without using > any intranet application) > > thanks! > shmi > > From ransen_spam_me_not at nemo.it Tue Oct 2 12:19:26 2001 From: ransen_spam_me_not at nemo.it (Owen F. Ransen) Date: Tue, 02 Oct 2001 16:19:26 GMT Subject: test - don't read... Message-ID: <3bb9e35a.695404@news.newsguy.com> don't read -- Owen F. Ransen http://www.ransen.com/ Home of Gliftic & Repligator Image Generators From sholden at holdenweb.com Wed Oct 10 08:17:12 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 10 Oct 2001 08:17:12 -0400 Subject: Sockets References: Message-ID: "Hugo Martires" wrote ... > My server need to send 2 strings separeted: > s1= 'xxx' > s2= 'yyy' > > My client must received like this: > rec1= 'xxx' > rec2= 'yyy' > > The problem is that the Client received s1 and s2 in one only string. > > How can i received in 2 separeted variables ? > You need to encode them in some way so that the client can clearly separate the two values. Netstrings, for example ... there are many references (as Google will tell you), so here's just one that will explain the concept: http://kahuna.telstra.net/ietf/old-ids/draft-bernstein-netstrings-02.txt regards Steve -- http://www.holdenweb.com/ From mjais at web.de Wed Oct 24 03:25:56 2001 From: mjais at web.de (Markus Jais) Date: Wed, 24 Oct 2001 09:25:56 +0200 Subject: Oreilly's Python and XML Message-ID: hi, oreilly now has a sample chapter on their upcoming book "python and xml" look at: http://www.ora.com/catalog/pythonxml/chapter/ch01.html looks very promising. I already have "java and xml", but of course Python is much more fun :-) looking forward to reading the book. hope it will make it to the stores in december as oreilly says on their web site. markus From slinkp23 at yahoo.com Sat Oct 6 15:44:04 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Sat, 06 Oct 2001 19:44:04 GMT Subject: Python and Zope References: Message-ID: On Sat, 06 Oct 2001 15:12:29 GMT, Magnus wrote: >Hi, > >a few days ago I wrote my first Python script. First I though Python is >kind of weird, but after trying it I have to admit I love it. > >I was hooked by Python and decided to try Zope today for building a private >web-site. > >Now my question is: > > When using to 'include' files/objects it is working >well if the files are in the same directory. > >But how do I do this if I would like to use different directories to store >my objects within? > >Can I use some sort of objects/properties to get the BASE or URL, e.g.: >/myDirectory > >What's the best way of doing this? > >Thanks in advance, >Magnus > This is a question for the Zope list... zope at zope.org. A good source of answers to basic questions like this is the Zope Book: http://www.zope.org/Members/michel/ZB Chapter 4 might be especially useful for where you're at right now. But I'll give some quick hints. There are many ways to find things. First of all, Zope's automatic acquisition mechanism means that will work if foo exists in the current folder *or any parent folders.* (Acquisition is more complex and subtle than that... but that's the easiest way to use it.) There are also many methods that Zope provides for finding URLs. Try making a dummy document that contains And see what it gives you... especially have a look at URL0, URL1, ... and BASE0, BASE1 ... All of these can be used like . is also useful. Hope that helps, -- Paul Winkler From cjc26 at cornell.edu Sun Oct 21 13:16:54 2001 From: cjc26 at cornell.edu (Cliff Crawford) Date: Sun, 21 Oct 2001 17:16:54 GMT Subject: [OsX] Tkinter compile prob. References: Message-ID: * Andreas Schoeller menulis: | | I read about a Aqua-Version of Tk/Wish. Is it possible to build the | python-TKinter module against this distributon ? I've tried doing that..it compiles ok, but it doesn't really work right in the interpreter. Here's what I did: * downloaded and installed the binary snapshots from http://sourceforge.net/projects/tcl * edited Modules/Setup and changed the tkinter line to this: _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ -I/System/Library/Frameworks/Tcl.framework/Headers \ -I/System/Library/Frameworks/Tcl.framework/PrivateHeaders \ -I/System/Library/Frameworks/Tk.framework/Headers \ -I/System/Library/Frameworks/Tk.framework/PrivateHeaders \ -I/usr/X11R6/include \ -framework Tcl -framework Tk * recompiled and reinstalled Python (this went ok, without any errors) * started up the interpreter, and typed the following: >>> import Tkinter >>> Tkinter._test() Then what happened is a small window titled "tk" popped up, but without focus and behind all the other windows on the screen, and I wasn't able to click on any of the buttons in it or bring it to the front. I'm guessing there's something going wrong with the event loop.. -- Cliff Crawford :: cjc26 at cornell dot edu "Along the way of life, someone must have sense enough and morality enough to cut off the chain of hate. This can only be done by projecting the ethic of love to the center of our lives." -- Martin Luther King, Jr. From mwh at python.net Fri Oct 26 04:32:56 2001 From: mwh at python.net (Michael Hudson) Date: Fri, 26 Oct 2001 08:32:56 GMT Subject: Python ByteCode and Virtual Machine documentation References: Message-ID: Lucio Torre writes: > Thank you very much for the info. I missed the dis module. So i think > its time to share my impression: the search function from the python > site does not perform their function very well. theres a page named: > 17.10.1 Python Byte Code Instructions, and the file name is > :http://python.org/doc/current/lib/bytecodes.html and neither bytecode, > bytecodes, byte code or byte codes make that page show up. > > or maybe they show up and this time i missed it. but google is > pretty good at helping me find things, and im having problems with > the search at python. it may be me, and if its so, could someone > enlighten me, please? After some experimenting, I agree: the search page on python.org doesn't seem to be much good at searching the docs. Fortunately there's google. I don't know why sites bother with site specific search engines any more, TBH. I use google for finding people's homepages in my department... > thanks for the info on the VM, dis and bytecodehacks! Have fun! Cheers, M. -- Gullible editorial staff continues to post links to any and all articles that vaguely criticize Linux in any way. -- Reason #4 for quitting slashdot today, from http://www.cs.washington.edu/homes/klee/misc/slashdot.html From andy47 at halfcooked.com Fri Oct 19 00:46:19 2001 From: andy47 at halfcooked.com (Andy Todd) Date: 19 Oct 2001 04:46:19 GMT Subject: Python + wxPython database app References: <2a97b6b7.0110181923.500abb40@posting.google.com> Message-ID: engedi at evertek.net (Michael Ekstrand) wrote in <2a97b6b7.0110181923.500abb40 at posting.google.com>: >Hello, > >I am beginning work on a large database application, primarily for the >Win32 platform, and I would like to write it in Python with wxPython >if at all possible. > >However, I have one problem. I need access to an advanced reporting >engine. I'd like to use Crystal Reports - is there a way to use the >Crystal Reports viewer from Python/wxWindows? If there is another >fairly complete reporting engine that would integrate better into >Python/wxWindows, I would be more than willing to consider it. > >Pythonwin may also be an option for me, if it is easier to integrate a >reporting engine into it. However, I'm not terribly keen on that >option due to lack of documentation (or is there documentation I am >not aware of?). > >And my final option (besides pure Visual Basic, which I don't really >want to do) is a Visual Basic GUI and a Python business logic layer - >but this seems like it would be a lot of extra debugging, or am I >wrong somehow? > >Any advice would be most appreciated! > >Thank you, >Michael > I'll leave it to the wxPython gurus to give you specific tips on integrating with RDBMS, suffice it to say that it is not a problem but you may want to write your own persistence layer to map between Python's object model and the relational model you will be using in your database. I presume you are running on Windows, in which case you should be able to manage Crystal Reports from within your application by utilising its COM interface. For more info on controlling other apps from Python using COM I recommend Mark Hammond and Andy Robinson's book 'Python Programming on Win32' (http://www.oreilly.com/catalog/pythonwin32/) and if you have Win32all (either installed seperately or it comes with Active Python from Active State) you should have access to the 'COM Readme' on the same menu that you start Python from. Finally, Mark Hammond is fairly active on c.l.p so search the archives on google and you will find some great examples of driving applications via COM. Of course, if you're not on Windows this is no good. -- Content free posts a speciality From christy_girl99 at yahoo.com Sun Oct 28 01:41:17 2001 From: christy_girl99 at yahoo.com (Christy J) Date: 27 Oct 2001 23:41:17 -0700 Subject: python binary search Message-ID: <344d84d2.0110272241.71ad6f23@posting.google.com> Hi, I need a binary search tree in python that uses classes. I'm trying to count words from a file and spit out the number of times they occur and in alphabetical order. I got bintree[ [key, data], left, right] but don't know how to implement using classes. thx in advance Christy From martin.franklin at westgeo.com Thu Oct 25 04:03:01 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Thu, 25 Oct 2001 09:03:01 +0100 Subject: Tkinter.Listbox: activate() doesn't work References: Message-ID: <9r8gti$2s1a$1@mail1.wg.waii.com> Theodore D. Sternberg wrote: > How can I programmatically activate an element in a Tkinter.Listbox? > I've tried activate() but nothing happens. For example, > > import Tkinter > root=Tkinter.Tk() > lb = Tkinter.Listbox(root) > lb.insert( Tkinter.End, 'foo' ) > lb.insert( Tkinter.End, 'bar' ) > lb.pack() > lb.activate( 1 ) > > ...but I don't see 'bar' now getting highlighted. What am I doing wrong? > > Ted Sternberg > Berkeley, CA > Ted, Try the selection_set method:- from Tkinter import * root=Tk() lb=Listbox(root) lb.insert(0, 'thing') lb.insert(0, 'another thing')\ lb.pack() lb.selection_set(first=0) root.mainloop() Cheers, Martin From gh_pythonlist at gmx.de Sat Oct 20 21:56:58 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 21 Oct 2001 03:56:58 +0200 Subject: Smtplib module In-Reply-To: ; from grante@visi.com on Sun, Oct 21, 2001 at 01:29:16AM +0000 References: <3BD20BAE.6346.7693E0@localhost> Message-ID: <20011021035658.A3124@lilith.hqd-internal> On Sun, Oct 21, 2001 at 01:29:16AM +0000, Grant Edwards wrote: > On Sun, 21 Oct 2001 00:14:35 +0200, Gerhard H?ring wrote: > >On Sat, Oct 20, 2001 at 11:41:34PM +0200, A wrote: > > >> I want to use smtplib module for sending emails. Is there any way how > >> I can test a return code, generated by this module, to see if an email > >> was accepting for delivery, for example? > > > >No, there is no way to do this. But this is a "feature" of > >SMTP, not of Python's smtplib. > > Sure there is. There's no way to know if the message was > delivered or read, but you can certainly find out if the SMTP > server accepted it. The documentation for the "sendmail" method > states: [...] Ok. I confused "accepted for delivery" with "actually delivered". Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From nomad*** at ***freemail.absa.co.za Mon Oct 22 07:54:42 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Mon, 22 Oct 2001 13:54:42 +0200 Subject: newsgroup traffic way down? References: <8827e15d.0110170823.672f0a63@posting.google.com> <3BD0692D.BFE42CFA@interet.com> Message-ID: On Fri, 19 Oct 2001 13:55:57 -0400, "James C. Ahlstrom" wrote: >Chris Ryland wrote: >> >> Is it just I, or is c.l.p traffic way down lately? > >I am reading using uunet as a server, >and I think c.l.p traffic is way down too. > >Jim Ahlstrom Well, I just got over 230 headers after a weekend, so it can't be that low... Maybe uunet has a shorter message expiry timeout? -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From grante at visi.com Thu Oct 11 23:35:04 2001 From: grante at visi.com (Grant Edwards) Date: Fri, 12 Oct 2001 03:35:04 GMT Subject: Sockets References: <3BC50853.505C8641@engcorp.com> <3BC572EF.DEE5247F@earthlink.net> Message-ID: On Thu, 11 Oct 2001 16:28:25 GMT, Joseph A Knapka wrote: >> My problem is : what i put in ??????????????? >> Some people told me to use a delimeter betwen the 2 strings. >> But how can i use it? How to decode the whole string ? > >There are a couple of approaches you could take. The >first would be to use a delimiter, and continue to >read until you see the delimiter, saving any additional >data for further reads: > >delim = '!' Choosing a delimiter is tricky, since it means that character is no longer allowed to appear in any strings. The most often chosen options would be LF, CR/LF, or whitespace. If you use LF or CR/LF, then you can just call readline() and get the next string. When designing an application protocol to run on top of TCP, it can be very handy to keep it in readable ASCII with CR/LF delimited lines (e.g. SMTP, IMAP, POP, NNTP, ...) -- Grant Edwards grante Yow! O.K.! Speak with a at PHILADELPHIA ACCENT!! Send visi.com out for CHINESE FOOD!! Hop a JET! From calves at coelce.com.br Tue Oct 23 10:26:46 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Tue, 23 Oct 2001 11:26:46 -0300 Subject: a better prime number generator Message-ID: <29A97D00F387D411AC7900902770E14802276385@lcoeexc01.coelce.net> Why not try a variation from basic example in Python Tutorial by Guido van Rossum?! def getPrimesTill(x): primes=[2] for i in range(3,x,2): for x in range(2,i): if i%x==0: break else: primes.append(i) return primes Carlos Alberto COELCE/DPRON-Departamento de Projetos e Obras Norte Fone: 677- 2228 e-mail: calves at coelce.com.br \|||/ (o o) --ooo0-(_)-0ooo-- -----Original Message----- From: dhillon_rs at rediffmail.com [mailto:dhillon_rs at rediffmail.com] Sent: Sunday, October 21, 2001 2:40 PM To: python-list at python.org Subject: a better prime number generator hi all, I have just been introduced to pyton and find it a very good ( takes off all the bookwork ) language. I was trying to develope a ast prime number generator. I designed the following algo. Can you please suggest a faster one or modifications to this only to make it faster #the following algo returns all the primes below x def getPrimesTill(x): a = range(2,x) c = [2] i = 0 j = 0 foundone = 1 while i < len(a): while j < len(c) and (c[j] < (.5 * a[i]) ) and foundone == 1: if a[i]%c[j] == 0: foundone = 0 j = j + 1 if foundone == 1 and i > 0: c.append(a[i]) j = 0 foundone = 1 i = i + 1 return c roop -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From nomad*** at ***freemail.absa.co.za Tue Oct 16 09:28:33 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Tue, 16 Oct 2001 15:28:33 +0200 Subject: Cgi Counter References: Message-ID: On Fri, 12 Oct 2001 12:59:04 -0700 (PDT), Neal Irwin wrote: >Does anyone have sample code for a web-page hit >counter. I was curious what one would look like in >Python. I have made one in Perl and would like to >compare them. > >Thanks # Begin counter code ::: ## $Id: default.py,v 1.1 2001-05-24 18:11:06+02 Nomad Exp $ import string print "Content-Type: text/html\n\n" fileRead = open('count.txt', 'r') intHits = string.strip(fileRead.read()) # print "

intHits = " + intHits + "

" if intHits == '': intHits = 0 fileRead.close() intHits = string.atoi(intHits) + 1 fileWrite = open('count.txt', 'w') fileWrite.write(str(intHits)) fileWrite.close # followed by a long print """...""" containing # the html template that uses the counter data. # End counter code ::: Pretty simple, but it works... HTH -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From MarkH at ActiveState.com Wed Oct 17 19:29:18 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Wed, 17 Oct 2001 23:29:18 GMT Subject: PythonCOM: implementing properties with parameters References: Message-ID: <3BCE1469.1040600@ActiveState.com> Larry Howard wrote: > How would I implement an interface with a property such as this using PythonCOM? > > dispinterface IDispComponent { > ... > [id(0x60020003), propput, helpstring("property ComponentParameter")] > void ComponentParameter([in] BSTR Name, [in] VARIANT rhs); > [id(0x60020003), propget, helpstring("property ComponentParameter")] > VARIANT ComponentParameter([in] BSTR Name); > ... > } The propget can be implemented by creating a function "ComponentParameter". The propget can not currently be implemented - this was discussed on this list earlier this year (or maybe even earlier). win32com/server/policy.py needs to have support added in the _invokeex_ function, which I would be happy to coordinate. It is a shame they use a property when it takes an argument - it defeats the purpose of properties IMO. Mark. From olivier.deme at airtel-atn.com Mon Oct 1 08:46:56 2001 From: olivier.deme at airtel-atn.com (Olivier Deme) Date: Mon, 01 Oct 2001 12:46:56 +0000 Subject: Python embedding & question about autoconf and dynamic linking Message-ID: <9p9hmu$2dj$2@kermit.esat.net> I am myself into the same situation... I am trying to link my C application against libpython and I get unresolved symbols with posix thread related symbols. Why the heck would I need the posix thread library if I never create any thread ?!? Why is it so difficult to do something as common as this? O. In article , Mads Bondo Dydensborg wrote: > Hi there > > I am trying to use Python as an embedded interprenter. Whilst it is > quite easy to understand the C interface, I have found it _very_ hard to > figure out what flags I need to pass to the linker to get a succesfull > compile. It seems to depend rather heavily on a lot of parameters. > > So, my first question is if there are any autoconf macros out there that > will work for me, sort of like a AM_PATH_SDL macro? I have been > searching around, and found one from on of the KDE libs, but it seems to > break rather quickly for everything else than Python 1.5 (which it seems > to be only partly succesfull in anyway). > > My next question is with respect to dynamicly linking to the python > interprenter, when embedding it. All info I have been able to find, > points towards linking statically with libpython..a - however, > this adds about 660KB to my application, and in general I would much > rather link to a .so file - but I have not been able to find "such a > beast" or instructions on how to build one. Is it possible? Or is there > a clever way arond this kind of problem that I - beeing a clueless > newbee - have totally overlooked? (Maybe some weird extension trickery?) > > Thanks in advance! > > Mads > From phd at phd.pp.ru Mon Oct 29 09:59:44 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 29 Oct 2001 17:59:44 +0300 Subject: setting the clipboard In-Reply-To: <44rqttchjigpj1rkd4qvljr4bn5atmc75n@4ax.com>; from dale@riverhall.NOTHANKS.co.uk on Mon, Oct 29, 2001 at 02:50:26PM +0000 References: <3bdd553c$1@207.229.64.20> <44rqttchjigpj1rkd4qvljr4bn5atmc75n@4ax.com> Message-ID: <20011029175944.G21481@phd.pp.ru> On Mon, Oct 29, 2001 at 02:50:26PM +0000, Dale Strickland-Clark wrote: > This puts the text in 'spam' on the clipboard: > win32clipboard.SetClipboardText(spam) No, this put the value of the variable "spam". Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From michael at rcp.co.uk Tue Oct 16 09:24:13 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Tue, 16 Oct 2001 13:24:13 +0000 (UTC) Subject: [Python-Dev] conditional expressions? References: <3bcbfda6$0$42081$edfadb0f@dspool01.news.tele.dk> <3bcc127a$0$42071$edfadb0f@dspool01.news.tele.dk> Message-ID: "Anders J. Munch" wrote in news:3bcc127a$0$42071$edfadb0f at dspool01.news.tele.dk: > "Michael Abbott" wrote in message > news:Xns913C6BFA94D38michaelrcpcouk at 194.238.50.13... >> >> Nah. Go for "maximal munch", I can't think of anything wrong with that. > > Good try. Maximal munch is certainly one of the better options, but > it's not perfect. What should be the output from: > > x = 260 > abs_x_mod_256 = divmod(if x<0: -x else: +x, 256)[1] > print abs_x_mod_256 Ho ho! Presumably divmod is unhappy at only getting one argument. Well, the bracket fans can be happy here, because we'll now need to write abs_x_mod_256 = divmod((if x<0: -x else: +x), 256)[1] (or, just to keep the alternatives alive simultaneously, abs_x_mod_256 = divmod((if x<0 then -x else +x), 256)[1] :) That's a tricky one, I agree, but we have to choose one alternative or the other. Hmm. If we make , dominate over if ... else then the original example returns a dictionary tupled with b. Oh, drat. Perhaps , needs to dominate (bind more loosely) after all. Oh well, someone needs to check the grammar (I'm not sure what other operators bind as loosely as , -- not too many, I hope). From tomaz.ficko at agroruse.si Fri Oct 26 08:50:44 2001 From: tomaz.ficko at agroruse.si (Tomaz Ficko) Date: Fri, 26 Oct 2001 14:50:44 +0200 Subject: printing to file from MS Word Message-ID: I want to write a doc to ps converter. I'm using python 1.5.2 and win32all-136. The folowing code should do it: word = win32com.client.Dispatch('Word.Application') word.ActivePrinter = "HP LaserJet 5P/5MP PostScript" doc = word.Documents.Open(FileName=os.path.abspath('test.doc')) doc.PrintOut(PrintToFile=1, OutputFile='test.ps', Background=1) doc.close() word.quit() But there is one problem. When I run this code it allways brings up file dialog for the name of *.prn file. How can I disable this. Tomaz From phd at phd.pp.ru Wed Oct 3 00:54:47 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 3 Oct 2001 08:54:47 +0400 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <200110030312.f933COK01047@smtp2.idir.net>; from opsys@voodooland.net on Tue, Oct 02, 2001 at 10:14:58PM -0500 References: <200110030312.f933COK01047@smtp2.idir.net> Message-ID: <20011003085447.B29882@phd.pp.ru> On Tue, Oct 02, 2001 at 10:14:58PM -0500, Chris Watson wrote: > On Tuesday 02 October 2001 09:54 pm, Delaney, Timothy wrote: > > > From: Chris Watson [mailto:opsys at voodooland.net] > > However, GPL is *not* extortion. The writer of a piece of code has every > > right to want to protect, control or charge for it. > > That's true. But dont call it Free code if you do. Because it is not free. > Look up free in the dictionary. That is the ONLY definition that should be > followed. Not whatever twisted version the FSF and GNU people want to use. > The gernal gist of any dictionary is its free if its free from control, > opression, or restrictions. I disagree. Some restrictions must be imposed. I don't want your fist to fly freely into my nose; that why I want to impose restrictions. Absolute freedom is impossible in this not-so-ideal world. I don't want arrognt and greedy Big Power Companies freely take the ball and run with it. GNU GPL looks very good balanced for me. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From maxm at normik.dk Thu Oct 11 05:01:15 2001 From: maxm at normik.dk (Max M) Date: Thu, 11 Oct 2001 11:01:15 +0200 Subject: ODBC access via Python References: Message-ID: <3bc55fd7$0$42030$edfadb0f@dspool01.news.tele.dk> "vm_usenet" wrote > I've tried to install mxODBC, but it doesn't work for some reason... Have you remembered to install the basic package also? It is not enough to install the odbc package, as it needs stuf from tha basic package. regards Max M From brueckd at tbye.com Thu Oct 25 22:58:41 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 25 Oct 2001 19:58:41 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: Message-ID: On 25 Oct 2001, David Bolen wrote: > > The fact that the Python core is inherently thread-safe is a very > > high-level concept, and is a fundamental part of threading support in > > Python. It is completely in line with other housekeeping/safety features > > of Python. That type of basic thread safety will not go away. The GIL > > might, but its replacement would still be a threadsafe core, and so you'd > > end up with the same thing. > > Ah, but Python's dynamicism can make it hard to predict when you're > sure that you are executing within the core (say your code is handed a > Python implemented object that just happens to look like a list), or > especially when you can subclass the built-in types in 2.2. Although > I'd concede that if done right such other objects or subclasses ought > to maintain the same sort of threadsafe contract as the built-in > objects do, but that's harder to guarantee and I'm not sure I'd want > to risk it when writing code for later maintenance. Good point - every time I've relied on this behavior it has been in a self-contained program rather than a library that I was making available to someone else. In the library case I don't know how common the "simultaneous access of a user-provided object" is, but in that case I'd definitely agree that strict locking would be high on the list of things to do to make sure the library is sufficiently robust. -Dave From python at chajadan.net Thu Oct 11 12:04:22 2001 From: python at chajadan.net (chajadan) Date: Thu, 11 Oct 2001 16:04:22 +0000 Subject: YOU ARE ALL GAY! Message-ID: <200110111604.AA51445880@chajadan.net> Now whoever said that is really really mean! You shouldn't go getting my hopes up like that... --chajadan From nospam at bigfoot.com Sat Oct 27 17:24:34 2001 From: nospam at bigfoot.com (Gillou) Date: Sat, 27 Oct 2001 23:24:34 +0200 Subject: os.system() and cgi References: Message-ID: <9rf8b0$9gb$1@norfair.nerim.net> Answer certainly is in the Web server log file (gci errors are usually here) IMHO, Apache usually runs for user "nobody" who can run /usr/X11R6/bin/xmgrace. But perhaps this program needs other resources on which "nobody" has no permission. Hope this helped --Gillou "M. Ibaraki" a ?crit dans le message news: ef98172c.0110270521.774c1604 at posting.google.com... > This script (test.py) works fine and creates a file 'outputfile' when > I run this in test mode (python test.py). > > > --- test.py ---- > #!/usr/bin/python > > import cgi, os > > print "Content-type: text/html\r\n" > print "" > print "" > > ret = os.system('/usr/X11R6/bin/xmgrace -help > outputfile') > # ret = os.system('/bin/ls > outputfile') > > print "

ret = ", ret > ---------------- > > > > It shows: > > Content-type: text/html > > > >

ret = 0 > > > > However, when this is executed as a cgi it shows: > > ret = 256 > > and no 'outputfile' file is created. > > > > Permission of /usr/X11R6/bin/xmgrace is: > -rwxr-xr-x 1 root root 450 May 20 18:48 > /usr/X11R6/bin/xmgrace > > xmgrace is a 2D plotting tool > (http://plasma-gate.weizmann.ac.il/Grace/) > > > > I also tried '/bin/ls > outputfile' instead of '/usr/X11R6/bin/xmgrace > -help > outputfile'. This 'ls' command is executed and it creates > 'outputfile' in both cgi and test modes. > > > Permission of /bin/ls is: > -rwxr-xr-x 1 root root 48316 Sep 15 12:54 /bin/ls > > > Any comments would be greatly appreciated. > > > M. Ibaraki From pzw1 Wed Oct 31 17:59:55 2001 From: pzw1 (Peter Wang) Date: Wed, 31 Oct 2001 17:59:55 -0500 Subject: Underscore data hiding (was python development practices?) References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> <9rpbk1$19rg$1@nntp6.u.washington.edu> Message-ID: On Wed, 31 Oct 2001 12:05:11 -0600, Skip Montanaro wrote: > > Russell> My understanding is that a double underscore is required for > Russell> Python to automagically mangle the name. On the other hand, two > Russell> postings now suggest that a single underscore is sufficient. > > Russell> If double underscore is required, then it seems to me this is a > Russell> very common misconception that a single is sufficient. It might > Russell> be worth changing. > >A double leading underscore is requred to coax Python into mangling an >attribute. I think a lot of people use a single underscore as a simple cue >for themselves and other programmers that an attribute isn't meant to be >part of the public interface without messing up the actual name, so it can >be used easily in subclasses. heh... so: C++::private == Python."__*" C++::protected == Python."_[a-zA-Z]*" C++::public == Python."[a-zA-Z]*" ;) -peter From michael at rcp.co.uk Wed Oct 3 04:58:08 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Wed, 3 Oct 2001 08:58:08 +0000 (UTC) Subject: Package support in Python 2 Message-ID: Is there up to date documentation for package support in Python 2? Section 6.11 of the "Python Reference Manual" has the following nice quote: [XXX Can't be bothered to spell this out right now; see the URL http://www.python.org/doc/essays/packages.html for more details, also about how the module search works from inside a package.] and the referred URL documents Python 1.5. I presume that nothing significant has changed recently, but it's certainly disconcerting for something as fundamental as module importing to not actually be part of the core language documentation! From taw_usenet at yahoo.com Wed Oct 24 21:39:39 2001 From: taw_usenet at yahoo.com (ToddW) Date: 24 Oct 2001 18:39:39 -0700 Subject: pickle behavior Message-ID: <84a8bdbe.0110241739.5258eb84@posting.google.com> When pickling an object, is the expected behavior that it be pickled identically each and every time? Ie. I want to know if I can rely on the string generated always being the same given the object can be represented identically (for example tuples are immutable, and therefore should be able to be pickled identically in my view). As far as I can tell (and I have tested fairly extensively), this is the behavior of pickle, but not cpickle. Can anyone clarify the proper behavior? Is the cpickle anomoly NOTABUG? From loewis at informatik.hu-berlin.de Fri Oct 12 07:47:26 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 12 Oct 2001 13:47:26 +0200 Subject: python + DOM docu?? References: <9q6kr1$m2mdb$1@ID-75083.news.dfncis.de> Message-ID: Markus Jais writes: > can anybody give me an URL where to get a tutorial on python + DOM? > on the python.org web-site, the tutorial is not finished yet. I recommend to read http://py-howto.sourceforge.net/xml-howto/DOM.html followed by http://www.python.org/doc/current/lib/module-xml.dom.html If that leaves any questions unanswered, don't hesitate to ask at xml-sig at python.org. Regards, Martin From paul at fxtech.com Wed Oct 10 17:43:02 2001 From: paul at fxtech.com (Paul Miller) Date: Wed, 10 Oct 2001 16:43:02 -0500 Subject: PYTHONPATH and embedding python References: <3BC2D453.6331CAF3@tttech.com> Message-ID: <3BC4C0E6.575E68B3@fxtech.com> > Does anyone have any suggestions? Thanks. This works too: ::PyRun_SimpleString("import sys\n"); // loop through the paths you want to add ::PyRun_SimpleString("sys.path.insert(0, \"\")\n"); From chrishbarker at home.net Thu Oct 25 16:36:47 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 25 Oct 2001 13:36:47 -0700 Subject: a simple module for finding roots of polynomial ? References: Message-ID: <3BD877DF.967614A0@home.net> Jan Samohyl wrote: > > Hello, > I am looking for some polynomial root finder. I wish I could just give a list > of coefficients (for me, reals are enough) and get a list of roots (but these > should contain the complex ones). Is there something simple as this in Python, > or I have to code it myself ? I'd take a look at www.scipy.org, there's a pretty good chance this is there. If not, I'd look for a library that does it that you can wrap. A polynomial root finder is not a trivial piece of code to write (unless you are limited to polynomials of order less four) -CHB -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From skip at pobox.com Sat Oct 13 08:12:56 2001 From: skip at pobox.com (Skip Montanaro) Date: Sat, 13 Oct 2001 07:12:56 -0500 Subject: webserver performance (was Re: Why so few Python jobs? (and licenses)) In-Reply-To: <9q90ci$hdk$1@lancelot.camelot> References: <7xwv2418xk.fsf@ruckus.brouhaha.com> <9q6a1u$ke9$1@serv1.iunet.it> <7xr8s8q21l.fsf@ruckus.brouhaha.com> <9q90ci$hdk$1@lancelot.camelot> Message-ID: <15304.12232.204347.304907@beluga.mojam.com> Alex> Thanks for the tip! The exact URL is: Alex> http://www.acme.com/software/thttpd/benchmarks.html Alex> and they do show that even-based ('select') servers leave all Alex> others in the dust (700+ to 1000+ requests per second on the test Alex> configuration, versus 250 for Apache and 45 for architectures Alex> based on Java threads). 'twould be nice if Jef included a row for Medusa (which uses select instead of threads). Of course, that table is over three years old, so even the numbers for the web servers he does show have probably changed in relation to each other. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From tim.one at home.com Mon Oct 15 17:46:32 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 15 Oct 2001 17:46:32 -0400 Subject: FW: [Python-Dev] conditional expressions? In-Reply-To: <7xy9mc8v16.fsf@ruckus.brouhaha.com> Message-ID: [misattributed to me -- these are Guido's examples] > Some examples where parentheses *are* required: > > (if 1 then 2 else 3) + 4 > a[(if i then 2 else 3) : 4] [Paul Rubin] > Hmmm, this looks error prone. What happens if you omit the parentheses > in these examples? You get SyntaxErrors. That's what "*are* required" means -- you use parens in these cases or they don't fly at all. > Are they equivalent to > > if 1 then 2 else (3+4) > > and > > if i then a[2] else a[3:4] > > respectively? If you don't use parens, they're equivalent to ]*** ) 3fo?rkl From max at alcyone.com Mon Oct 29 20:59:43 2001 From: max at alcyone.com (Erik Max Francis) Date: Mon, 29 Oct 2001 17:59:43 -0800 Subject: Representing tuples in strings References: <2SmD7.3702$Ey1.438112@news1.cableinet.net> Message-ID: <3BDE098F.78DE210B@alcyone.com> Graham Ashton wrote: > I'm looking to convert the tuple: > > ('string1', 3, 'string2') > > to the string representation: > > 'string1', 3, 'string2' > > without resorting to a regular expression. ', '.join(map(repr, myTuple)) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From andymac at bullseye.apana.org.au Fri Oct 5 07:45:37 2001 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Fri, 5 Oct 2001 21:45:37 +1000 (EST) Subject: Profiling the Python Interpreter In-Reply-To: Message-ID: On 4 Oct 2001 gb at cs.unc.edu wrote: > I assumed something like this too. Believing doesn't make it true > though. It turns out Cygwin is NOT the major problem. Running my > program on identical hardware running Linux and the same version of > Python+Numeric, runs about 25% slower than native Windows Python. The > problem is evidently the quality of the code produced by gcc versus > MSVC. There are numerous threads on various groups reporting > comparable slowdowns between gcc and MSVC. It is quite interesting comparing gcc versions and optimisation options, which I have done for my port of Python to OS/2+EMX (equivalent to Cygwin). My findings with 2.1.1:- gcc 2.8.1 with -O2 (no other optimisation options) was as good as I could get, -O was the best option with gcc 2.95.2. (didn't have 3.0.x) I didn't try CPU specific options, other than -m486 (which reduced performance on my K6/2-300), because I intended to distribute the binaries. Note also that some Python options (PYMALLOC in particular) can also be a potential source of CPU cycle loss. I note with interest that there are several notes in some of the docs accompanying packages from netlib.org (lots'o'numerics code) that recommend gcc 2.8.1 over later versions for numerics code. This might be out of date though. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au | Snail: PO Box 370 andymac at pcug.org.au | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From slinkp23 at yahoo.com Sun Oct 14 02:07:06 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Sun, 14 Oct 2001 06:07:06 GMT Subject: Python and XML? References: <9qaduv$c3p$1@nntp9.atl.mindspring.net> Message-ID: On Sat, 13 Oct 2001 18:08:36 -0400, Legeza George J. wrote: >Hi all, > > I'm pretty new to Python and I hadn't intended to use it for much (other >than as something to add to my resume), but recently a project's come up >that I think it would be good for. Unfortunetly, there are going to be other >components of this project that will be reading output in XML format. So >here's my question - does Python have any built in support for XML? Or is >there some extension of the language that provides support for XML? If so, >where can I find more information? Thanks, Two things to look at: - section 13 of the Standard Library Reference, in your python documentation. Lots of XML modules. - the XML section of Activestate's Python Cookbook, which includes some examples of the above: http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=XML HTH, Paul Winkler From ignacio at openservices.net Thu Oct 11 14:11:47 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 11 Oct 2001 14:11:47 -0400 (EDT) Subject: CGI question on input type=text form elements In-Reply-To: Message-ID: On Thu, 11 Oct 2001, DeepBlue wrote: > > "Ignacio Vazquez-Abrams" wrote in message > news:mailman.1002815363.21257.python-list at python.org... > > On Thu, 11 Oct 2001, DeepBlue wrote: > > > > > I am running into a strange problem with a form while using CGI module > in > > > Python. > > > Let us say I have the following form: > > >
> > > > > > > > > > > > > > > Now, let us say that test_form=cgi.FieldStorage() > > > If the above form is submitted without typing anything in the text field > one > > > expects test_form.keys() to generate: > > > ['submit'] > > > > > > But i am getting: > > > ['text_1', 'submit'] > > > Which is unexpected, and in my case, undesirable. What am I doing > wrong? > > > > You are assuming that the browser won't pass the contents of text_1 if it > is > > empty. Obviously this isn't true. You need to fine-tune your code to deal > with > > the case when it is empty. > > > This is only happening when the form is enclosed in a table. When the form > is not, the keys do not include empty text input elements. Well then you have two options: 1) Let the Python script know when the form is in a table, or 2) Deal with cases when the field is present but empty Not only is option 2 probably easier, but it's also the "correct" thing to do, because other browsers may behave in a different manner, returning the empty field whether or not the input is in a table. -- Ignacio Vazquez-Abrams From phr-n2001d at nightsong.com Sun Oct 28 02:23:35 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 28 Oct 2001 00:23:35 -0700 Subject: Why doesn't this simple Curry-like implemention work? References: Message-ID: <7xd7389qiw.fsf@ruckus.brouhaha.com> "Michael R. Head" writes: > # for some reason this function doesn't work in python 1.5.2. > def curry(f, p): > return lambda x: apply(f, p, x) > > I've looked up on the list better class-based implementations, and am > using one of them, but I'm curious why this doesn't work (when the > curried function is called, f becomes unknown). (I'm looking for a > reason in the language spec). I'm supposing that lamda isn't storing > the reference to its inputs -- which it seems it should -- is this > correct? I thought the third arg to apply was a keyword arg dictionary. Is that really what you meant? From db3l at fitlinxx.com Thu Oct 25 18:39:10 2001 From: db3l at fitlinxx.com (David Bolen) Date: 25 Oct 2001 18:39:10 -0400 Subject: Solaris core dump with McMillan Installer References: <9r960f$s8h9i$1@ID-59885.news.dfncis.de> Message-ID: Gordon McMillan writes: > David Bolen wrote: > > > Gordon McMillan writes: > > > >> I was going to guess 8, but I guess I better use 16. > > > > Why not just let the compiler generate whatever alignment it wants for > > the structure and just marshall/unmarshall the individual fields > > (field by field) into the file. That way alignment shouldn't be an > > issue. > > Because I write it with Python and read it with C. Maybe > (someday) not even on the same kind of box. But field by field processing would be portable across both language and system, so that shouldn't be an issue. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From joonas at olen.to Tue Oct 2 16:04:05 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: Tue, 02 Oct 2001 23:04:05 +0300 Subject: [?] sorting files by modification time. References: Message-ID: <3BBA1DB5.C847D30A@olen.to> Francisco Borges wrote: > > Hello all, > > I want to list some files in a directory and sort them by the > modification time. > > As far as I could tell, I can't do that with os.listdir and neither > with glob, is this right? > > I thought about > >>> os.system('ls -t') > > but it will thrown the output to stdout. Is there a simpler way to do > this than start messing with the stdout or with the shell??? Take a look at Python sorting FAQ at http://py-howto.sourceforge.net/sorting/sorting.html . >>> import os >>> files = os.listdir(".") >>> files.sort(lambda x,y:cmp(os.path.getmtime(x),os.path.getmtime(y))) From db3l at fitlinxx.com Fri Oct 19 17:35:48 2001 From: db3l at fitlinxx.com (David Bolen) Date: 19 Oct 2001 17:35:48 -0400 Subject: Reverse argument order References: Message-ID: David Brady writes: > The thing to note is that it's sort of a positional > notation that is backwards from most programming > languages. In Python, we're going to force the users > to put the hours, minutes and seconds as separate > arguments, but we'd like to allow them to omit the > higher-order arguments and have them default to zero. BTW, others have suggested ways to handle the separate arguments, but one other option you might consider is just taking the time value as a string and parsing it yourself. You could implement whatever default behavior or handling of timestamps you'd like that way. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From barry at zope.com Fri Oct 19 13:00:26 2001 From: barry at zope.com (Barry A. Warsaw) Date: Fri, 19 Oct 2001 13:00:26 -0400 Subject: RELEASED: Python 2.2b1 is out! Message-ID: <15312.23594.31057.586571@anthem.wooz.org> We've released Python 2.2b1, the first beta release of Python 2.2, for your ebullience, ecdysis, and embarcation. As this is the first beta release, we are now in feature freeze for Python 2.2. http://www.python.org/2.2/ Give it a good try, and report what breaks to the bug tracker: http://sourceforge.net/bugs/?group_id=5470 New features in this release include: - New-style classes are now always dynamic, except for built-in and extension types - A very subtle syntactical pitfall in list comprehensions was fixed - getattr(obj, name, default) now only catches AttributeError - Weak reference objects are now part of the core and offers a C API. - unicode(obj) now behaves more like str(obj) - isinstance() now accepts more objects as its first and second arguments - os and posix supports chroot(), setgroups() and unsetenv() where available. The stat(), fstat(), statvfs() and fstatvfs() functions now return "pseudo-sequences" whose elements can be accessed by name or index. The time module's localtime(), gmtime() and strptime() are pseudo-sequences too. - Many improvements to the profiler As usual, Andrew Kuchling is writing a gentle introduction to the most important changes (currently excluding type/class unification), titled "What's New in Python 2.2": http://www.amk.ca/python/2.2/ There is an introduction to the type/class unification at: http://www.python.org/2.2/descrintro.html Thanks to everybody who contributed to this release, including all the alpha testers! brought-to-you-by-the-letter-"E"-ly y'rs, -Barry From peter at engcorp.com Wed Oct 10 22:57:10 2001 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Oct 2001 22:57:10 -0400 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <7x4rp8q1cy.fsf@ruckus.brouhaha.com> <9q20bh$mjs$1@slb3.atl.mindspring.net> Message-ID: <3BC50A86.2CAC0347@engcorp.com> John Roth wrote: > > I presume (although I haven't tested it) that "3(x, y, z)" produces a > "not callable object" error, and "3[x]" produces a "not subscriptable" > error as well. I really can't see what calling '3' would do, but ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I'm not sure either, but calling '4' should make people duck! ** if-puns-are-the-lowest-form-of-humor-what-are-numeric-puns-ly yr's, -Peter Hansen ** (on the golf course, for the non-native English speakers amongst us.) From thomas.heller at ion-tof.com Wed Oct 31 14:20:36 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Wed, 31 Oct 2001 20:20:36 +0100 Subject: python development practices? References: Message-ID: <9rpiu5$utkni$1@ID-59885.news.dfncis.de> wrote in message news:mailman.1004554772.11121.python-list at python.org... > > ... Publicly-intended methods are > annotated with "Public" at the start of their doc strings. Anything > without such annotation -- please use only for debugging or exploring > (again, outside of the defining class or subclasses). I wonder why this reminds me of smalltalk ;-) Thomas From h.jehadalwan at student.kun.nl Thu Oct 18 15:38:00 2001 From: h.jehadalwan at student.kun.nl (Husam) Date: Thu, 18 Oct 2001 21:38:00 +0200 Subject: cPickle works fine, except within this code..It lets the programs hangs! Message-ID: <3BCF2F98.68FE5BDE@student.kun.nl> cds=[1,2,3,4,5] programs[['one','two'],['three','four'],['five','six']] mylist=[1,2,3,4,5,6] while 1: print '\n',len(cds),'CDs are present in the data base!','\n','\n','1','\t','Add program','\n','2','\t','Search for program','\n','3','\t','Delete program','\n','4','\t','Delete CD','\n','5','\t','Display content of a CD','\n','6','\t','Quit' choice=raw_input('Make a choice: ') try: if int(choice)==mylist[0]: #ADD A NEW PROGRAM while 1: print 'Press (Q) to cancel!' prog_name=raw_input('Enter Program Name: ') try: if prog_name=='q' or prog_name=='': break else: print 'Press (Q) to cancel!' cd_nr =raw_input('Enter CD number: ') while 1: try: if cd_nr=='q': break elif int(cd_nr) in cds: #CHECKS CD NR FOR VALIDITY for i in range(len(cds)): if int(cd_nr)==cds[i]: programs[i].append(prog_name) write_prog=open('programs.txt','w') cPickle.dump(programs,write_prog) # <==It hangs here! write_prog.close() elif int(cd_nr)-cds[-1]==1: cds.append(int(cd_nr)) write_cd=open('cds.txt','w') cPickle.dump(cds,write_cd) write_cd.close() programs.append([prog_name]) write_progs=open('programs.txt','w') cPickle.dump(programs,write_progs) write_progs.close() except ValueError: print 'Invalid CD nr. Please Try Again!' break except ValueError: print 'Please Enter Program Name, Or Cancel Operation!' break From jnlc at bellsouth.net Wed Oct 31 14:03:02 2001 From: jnlc at bellsouth.net (lance crocker) Date: Wed, 31 Oct 2001 19:03:02 GMT Subject: newbie question References: <9rpbr2$us4bd$1@ID-11957.news.dfncis.de> <3BE0394E.9C4E92BF@alcyone.com> Message-ID: <3be04a08.19984913@news1.lig.bellsouth.net> this is an actual exert from a tutorial i got off the net. Programming tutorials since the beginning of time have started with a little program called Hello, World! So here it is: print "Hello, World!" If you are using the command line to run programs then type it in with a text editor, save it as hello.py and run it with ``python hello.py'' Otherwise go into IDLE, create a new window, and create it as in section 1.4. When this program is run here's what it prints: Hello, World! i did evrything that it asked me to do but i keep getting syntax errors. i tried running it in DOS but it then gives me a bad command or file name error. I want to get this fixed b/c how can i use progs with out being able to run them? On Wed, 31 Oct 2001 09:47:58 -0800, Erik Max Francis wrote: >Emile van Sebille wrote: > >> " 1" wrote in message >> news:yXVD7.6251$QL2.175221 at e3500-atl1.usenetserver.com... >> >> > When I got to run the file (by typing python hello.py)i get this >> > error >> > message: >> > >> > >>> python hello.py >> > SyntaxError: invalid syntax >> > >>> > ... >> >> You've got a syntax error in the file, probably extra spaces > >No, look closely -- he's typing "python hello.py" in the Python >interpreter itself. > >-- > Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ > __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE >/ \ Laws are silent in time of war. >\__/ Cicero > Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ > An Esperanto reference for English speakers. From rdacker at pacbell.net Thu Oct 18 12:52:45 2001 From: rdacker at pacbell.net (rdack) Date: 18 Oct 2001 09:52:45 -0700 Subject: [OS X] can't connect to db Message-ID: <644f6688.0110180852.11e516f6@posting.google.com> using pygresql-3.2, postgresql-7.1.3, mac os x 10.1, mac g4. doesn't work: db = _pq.connect('rda') my python file is in '/Library/WebServer/CGI-Executables' in that directory i can do 'psql 'rda'' ok, but running the .py file throws an exception in connect. i also tried db = _pq.connect('rda',None,-1,None,None,'bobacker') and: db = _pq.connect('rda',None,-1,None,None,'postgres') and for coming in from browser html file: db = _pq.connect('rda',None,-1,None,None,'www') 'postgres', 'bobacker', and 'www' are postgresql users. what can i do? From gh_pythonlist at gmx.de Fri Oct 19 14:42:33 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 19 Oct 2001 20:42:33 +0200 Subject: Usb with python? In-Reply-To: <20676b3.0110191014.76901c0b@posting.google.com>; from fredrik_p79@hotmail.com on Fri, Oct 19, 2001 at 11:14:39AM -0700 References: <20676b3.0110191014.76901c0b@posting.google.com> Message-ID: <20011019204232.A14780@lilith.hqd-internal> On Fri, Oct 19, 2001 at 11:14:39AM -0700, Fredrik Persson wrote: > Do anyone know how to access the usb-port in win98 using python? I > want to use a usb steeringwheel in my pyhton application. I think you're on the wrong track if you want to interface the hardware directly. The steering wheel surely is supported as a DirectInput device. DirectX has a COM interface nowadays, so you should be able to interface it with the Python win32 extensions from ActiveState. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From loewis at informatik.hu-berlin.de Sat Oct 27 15:32:18 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 27 Oct 2001 21:32:18 +0200 Subject: DOM oddity? References: <9revtc$eha$1@tyfon.itea.ntnu.no> Message-ID: "Magnus Lie Hetland" writes: > From the xml.dom documentation[1]: > > prefix > The part of the tagName preceding the colon if there is one, else > the empty string. The value is a string, or None > > Under what circumstances can the prefix be None (as opposed to the empty > string)? If there is no namespace prefix, it is None. For example, if you do createAttribute(), the DOM spec specifies that the result is A new Attr object with the nodeName attribute set to name, and localName, prefix, and namespaceURI set to null. The value of the attribute is the empty string. In Python, a null string maps to None; since the empty string maps to the empty string. HTH, Martin From simonmartin at mail105.com Tue Oct 16 04:15:10 2001 From: simonmartin at mail105.com (Simon Martin) Date: Tue, 16 Oct 2001 09:15:10 +0100 Subject: Zope consultant needed UK Message-ID: <3BCBEC8C.D9E82D97@mail105.com> Dear Group, Hope this isn't inappropriate... We need a really good Zope consultant for a very ambitious open source project. Anyone out there in the Herts/London area? Please get in touch so we can talk, I'm not interested in going through agencies etc at this stage. Many thanks Simon -- Simon Martin London Uk 020 8386 5828 PGP KEY ID <0xFA69D420> @ *Please note my e-mail address is now 'simonmartin at mail105.com'* From DavidA at ActiveState.com Mon Oct 15 12:54:21 2001 From: DavidA at ActiveState.com (David Ascher) Date: Mon, 15 Oct 2001 09:54:21 -0700 Subject: ActiveState Python Cookbook site broken or frozen!? References: <3BCAA1DB.AE557798@darwin.in-berlin.de> Message-ID: <3BCB14BD.787EC584@ActiveState.com> Dinu Gherman wrote: > > The ActiveState Python Cookbook doesn't accept recipes anymore! > See error below! Is it broken or is the game over? We are having a temporary glitch. It'll get fixed ASAP. The game isn't over. Even if it were, the website will continue to accept recipes (for e.g. the second volume of recipes, or even just for the sake of web readers =). --david ascher From phd at phd.pp.ru Wed Oct 17 04:26:11 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 17 Oct 2001 12:26:11 +0400 Subject: pure 16-bit DOS app In-Reply-To: <1003306634.200241@cswreg.cos.agilent.com>; from michael_armbruster@eu.exch.agilent.com on Wed, Oct 17, 2001 at 10:17:12AM +0200 References: <1003306634.200241@cswreg.cos.agilent.com> Message-ID: <20011017122611.M11182@phd.pp.ru> On Wed, Oct 17, 2001 at 10:17:12AM +0200, Michael Armbruster wrote: > I read many articles in the grup and the web, but till now I have not found > the real solution for my problem. > I would like to have a pure standalone DOS 16-bit app built out of > a python prog with inserted c-code but I don't know how to do this. > perhaps you could help me, Near to be impossible. 16bit DOS just doesn't have enough memory for Python. Can you use 32bit DOS (DOS Extender)? Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From Armin_member at newsguy.com Fri Oct 12 06:16:46 2001 From: Armin_member at newsguy.com (Armin Steinhoff) Date: 12 Oct 2001 03:16:46 -0700 Subject: Psyco Specializing Compiler References: <3bc4d2e4$0$36473$ba620e4c@news.skynet.be> Message-ID: <9q6fue02ogl@drn.newsguy.com> Sounds great Armin!! :) Armin In article <3bc4d2e4$0$36473$ba620e4c at news.skynet.be>, "Rigo says... > >Hello everybody, > >"Psyco", the Python Specializing Compiler I introduced some time ago on the >python-dev mailing list, is beginning to work. Its goal is to accelerate >execution of any Python program by dynamically compiling several >"specialized" versions of your code directly in machine code. For more info >see > > http://homepages.ulb.ac.be/~arigo/psyco/ > >Currently works on very simple examples only, but quite well: with an >acceleration factor of 100, including the compilation time! I expect a >factor of about 10 in compiling real code. > >Python is known to be "impossible to compile". Psyco shows that it is only >half the story. True, Psyco does not statically compile your code, so don't >expect to turn a .py file into a stand-alone .exe file. This still requires >the full interpreter. But Python or any other interpreted language can >theoretically be run as fast as fully optimized C. If you don't believe it >wait for a full-featured Psyco. It won't be as fast as C but it will >probably be faster than you believed was possible :-) > >Armin Rigo > > From fredrik at pythonware.com Sat Oct 27 15:49:48 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 27 Oct 2001 19:49:48 GMT Subject: Write and read objects from files . References: <005701c15f08$0979d140$4396003e@rashome> Message-ID: Gerhard H?ring wrote: > > 2. Is there a class or function that provides mechanism to check an > > e-mail address ? > > You mean a way to verify if a string is a valid email-address? There is > no such function in the Python standard library. But I'm sure there are > several implementations out there. on the other hand: http://www.perldoc.com/perl5.6/pod/perlfaq9.html#How-do-I-check-a-valid-mail-address- Q. How do I check a valid mail address? A. You can't, at least, not in real time. Bummer, eh? Without sending mail to the address and seeing whether there's a human on the other hand to answer you, you cannot determine whether a mail address is valid. From thamza.nospam at flash.net Mon Oct 29 15:37:28 2001 From: thamza.nospam at flash.net (Tim H) Date: Mon, 29 Oct 2001 20:37:28 GMT Subject: BOA GUI builder? References: <3BD9CC09.2B1AB020@mitre.org> <3BDC909B.4F500B9C@mitre.org> <3BDDA284.B564E2CB@mitre.org> Message-ID: Search boa.py for "2.3.0" Should be a line like this: if (wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER) != (2, 3, 0): change the 0 to a one: if (wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER) != (2, 3, 1): and away you go. This has caused me no problems, for consistency you may want a few lines down, too, one like this: raise 'wxPython 2.3.0 required' good luck, Tim H "Angel Asencio" wrote in message news:3BDDA284.B564E2CB at mitre.org... > Thanks, it worked! > > Btw. For WinCVS users, be sure you do not have a carrige return at the end of > the command. "\n" > > Ok, someone told me that to be able to use boa v0.0.13 with wxPython 2.3.1 I > had to do some modifications. I checked on source forge, and I could not find > any patch related to this. > Could someone post the changes or a place to get the patch for v0.0.13 to be > able to work with wxPython 2.3.1? > > Thanks. > > Paolo Invernizzi wrote: > > > The "module" name is "boa"... > > Probably you can have a closer look using the "browse cvs" link on project > > page... > > Cheer > > > > Paolo Invernizzi > > > > "Angel Asencio" wrote in message > > news:3BDC909B.4F500B9C at mitre.org... > > > I went to the boa sourceforge site, and although I could find rhw CVS > > files > > > listed, I could not find a module name to dowload through CVS, nor a link > > to > > > download all the files related to V0.0.13. > > > > > > What am I missing? > > > > > > Thanks. > > > > > > Tim H wrote: > > > > > > > The version in CVS is much further along (0.0.13). You might want to > > try > > > > that. It works for me. You do have to modify it slightly, it is > > looking > > > > for wxPython 2.30 and we are both using 2.3.1, but if you got BOA 0.0.5 > > to > > > > work you should have no probs with that. > > > > > > > > Tim H > > > > "Angel Asencio" wrote in message > > > > news:3BD9CC09.2B1AB020 at mitre.org... > > > > Greetings: > > > > I got the BOA Python IDE from http://boa-constructor.sourceforge.net/. > > > > I looks great, but when I went to save the WxFrame.py from the tutorial, > > it > > > > gave me a Win2000 error, but I ignored it. > > > > Then when I went to save WxApp.py it crashed. > > > > I have Win2000, BOA 0.0.5, wxPython 2.3.1 and Python 2.1 > > > > Do I need to get some patch to stabilize BOA? > > > > Thanks, > > > > -- > > > > -Angel > > > > From mcfletch at home.com Thu Oct 11 18:24:37 2001 From: mcfletch at home.com (Mike Fletcher) Date: Thu, 11 Oct 2001 18:24:37 -0400 Subject: Why not 3.__class__ ? In-Reply-To: Message-ID: <000201c152a3$83734100$0202a8c0@MikeySpace> Strangely, one of the things I use most commonly in Python is: __init__ which, I suppose, illustrates that I'm perverting the language again :) . I use it so often it's part of my general dictation vocabulary (as "py-init"). Sure, it makes me uncomfortable to use something magic every time I create a class, but "we've always done it that way". Please save me from myself! Show the one-true-Python-way. ;) Smile, Tim! I haven't heckled you in ages :) . Mike -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Tim Peters Sent: October 11, 2001 17:04 To: python-list at python.org Subject: RE: Why not 3.__class__ ? ... They're supposed to be ugly: if you find yourself using __xxx__ thingies a lot, it's supposed to be a clue that you're not using the language as intended. ... From skip at pobox.com Fri Oct 12 18:17:02 2001 From: skip at pobox.com (Skip Montanaro) Date: Fri, 12 Oct 2001 17:17:02 -0500 Subject: CPU time In-Reply-To: References: Message-ID: <15303.27614.472342.699250@beluga.mojam.com> >> I thought time.clock() measures CPU time which (i assume) is >> consistent regardless of other S/W running.. but somehow the >> measurement fluctuates a lot. Am I misunderstanding this function? If >> so, what is the function w/ the functionality I'm looking for? What platform are you using? On systems having the clock(3) library call, time.clock does measure CPU time consumed by the current process, assuming clock(3) does (it does on my system), but with varying degrees of precision (generally not a lot). In addition, POSIX requires that the return value of clock(3) be in microseconds, so if you are measuring a long-running process the value returned by time.clock can wrap (according to the man page on my Linux sytem, wraparound occurs approximately every 72 minutes). If you are using Win32, time.clock uses a Windows routine called QueryPerformanceCounter. I have no direct experience with it, but I am told that it returns a value that is independent of what process has the processor. Others I'm sure can offer more definitive information about this routine. For more information on QueryPerformanceCounter usage in Python, try Google: http://groups.google.com/groups?group=comp.lang.python.%2A&q=QueryPerformanceCounter -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From ignacio at openservices.net Fri Oct 5 01:30:23 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 5 Oct 2001 01:30:23 -0400 (EDT) Subject: Formatted printing of deep tuples Message-ID: Okay, here's a good one. Say I have a tuple as follows: --- (((1, 2),), ((), ('a', (('b', 'c'),)))) --- Does anyone have or know of any code that will format it similar to: --- ( ( ( 1, 2 ), ), ( ( ), ( 'a', ( ( 'b', 'c' ), ) ) ) ) --- It doesn't have to be exactly as shown, but the pprint module just doesn't cut it for more than 3 levels or so. -- Ignacio Vazquez-Abrams From sholden at holdenweb.com Tue Oct 23 16:52:33 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 23 Oct 2001 16:52:33 -0400 Subject: Import Error within Python Win32 COM object References: Message-ID: <0JkB7.1843$Nx2.31583@atlpnn01.usenetserver.com> "Sue Giller" wrote in message news:mailman.1003866863.7586.python-list at python.org... > I am trying to create a Win32 COM server object out of a python > class and use it in a VB application. > > import win32com.server.register > win32com.server.register.UseCommandLine(DataSetMaker) > > I can get the python object to properly import and use some Python > modules, but not others. It would appear that modules that live in the > Lib directory get found (such as string, cpickle, urllib), but other that > are in the Python path but not in Lib (such as Numeric) do not. I get > an ImportError: No module named Numeric... > > For example, this function works just fine > def _getURL(self): > import urllib > import string > > > But, if I add `import Numeric` to it, I get the error. The module runs > just fine as a simple python class module - it finds all imports, > whether run from PythonWin or DOS. > > Any ideas? > > Is there a discussion about the rules/caveats for importing Python > classes inside a server object, even tho those classes are not > exposed to the outside world? > When import stops working (I'm presuming it works when Python is run normally) the first place to look is sys.path. Have you printed that out from your COM objedct? Just open a file for writing and dump using "print >> file, sys.path". regards Steve -- http://www.holdenweb.com/ From chrishbarker at home.net Tue Oct 30 15:01:49 2001 From: chrishbarker at home.net (Chris Barker) Date: Tue, 30 Oct 2001 12:01:49 -0800 Subject: Matlab-style mask in Python?? Message-ID: <3BDF072D.3823ACC5@home.net> Ozone Hole near South Pole wrote: | I am a long time Matlab user. I just picked up Python for a short | while. | I wonder what should be the best way to do sth like: | Matlab: | a=[3,4,6,7,2,54,2,1,2] | idx=a>4 ans: [0,0,1,1,0,1,0,0,0] | a(idx) ans: [6,7,54] | Python: | a=[3,4,6,7,2,54,2,1,2] | idx=map(lambda x: x>4,a) #assume this calculation is lengthy | #and we don't want to repeat | last cmd??? have a look at Numerical Python http://www.numpy.org. I think it will help you. It absolutely will: >>> from Numeric import * >>> a=array([3,4,6,7,2,54,2,1,2]) >>> a array([ 3, 4, 6, 7, 2, 54, 2, 1, 2]) >>> idx = a > 4 >>> idx array([0, 0, 1, 1, 0, 1, 0, 0, 0]) >>> take(a,nonzero(idx)) array([ 6, 7, 54]) Numeric has most of the basic functionality that MATLAB does, but a much smaller library of extras. The SciPy (www.scipy.org) project is working to addess this. Numeric also lacks MATLAB'S nifty array indexing and mask indexing. Note how I used take and nonzero above. This does make code littel more verbose, but Numeric has a number of advantages as well. Consider "array broadcasting": >>> x = arange(5) >>> x.shape = (1,-1) # make it a row vector, the -1 means use whatever fits. >>> x array([ [0, 1, 2, 3, 4]]) >>> y = arange(3) >>> y.shape = (-1,1) # make it a column vector >>> y array([[0], [1], [2]]) >>> z = x*y >>> z array([[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]) In Matlab, you would have had to create an entire array of X and Y with [X,Y] = meshgrid(x,y) Which is a whole lot clunkier, and wastes a lot of memory. All in all, I like NumPy better. (and I like MATLAB a lot) -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From skip at pobox.com Tue Oct 16 19:08:57 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 18:08:57 -0500 Subject: Extending Python - variable sized arrays? In-Reply-To: References: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> <9qi8f2$o0o9a$1@ID-75083.news.dfncis.de> <7xlmibjk7f.fsf@ruckus.brouhaha.com> Message-ID: <15308.48649.623845.914001@beluga.mojam.com> >> > Returning the array as a tuple using Py_BuildValue() is a problem >> > because, although I can create the format string dynamically, I >> > can't create a dymanically sized argument list. You'll have to create a tuple or list of the appropriate size and populate it in a loop. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From mcraep at nortelnetworks.com Fri Oct 5 15:11:33 2001 From: mcraep at nortelnetworks.com (Paul McRae) Date: Fri, 05 Oct 2001 15:11:33 -0400 Subject: Python Dynamic Loading (extending Python for SWIG) References: <3BBB739F.36D4842B@nortelnetworks.com> Message-ID: <3BBE05E5.DBC5CFFE@nortelnetworks.com> I have gotten to the point on QNX 6.1 (x86) using Python 2.0 so that I can import my shared library created from SWIG, but I get the following unresolved symbols: >>> import my_shared_lib unknown symbol: _Py_NoneStruct unknown symbol: PyString_Type unknown symbol: PyExc_TypeError unknown symbol: PyType_Type unknown symbol: PyExc_NameError unknown symbol: PyInt_FromLong unknown symbol: PyObject_GetAttr unknown symbol: PyDict_SetItemString unknown symbol: PyErr_SetString unknown symbol: Py_InitModule4 unknown symbol: PyString_AsString unknown symbol: PyString_FromString unknown symbol: PyModule_GetDict unknown symbol: PyString_InternFromString unknown symbol: PyFloat_FromDouble unknown symbol: PyArg_ParseTuple Is there a SWIG library I need to add to the link stage? I thought these would be defined inside of the Python interpreter. I am using the following compilation commands: qcc -c -g -fpic -I/usr/include/python2.0 -I/usr/lib/python2.0/config my_shared_lib.c qcc -shared -g -o my_shared_libmodule.so my_shared_lib.o my_shared_lib_functions.o Paul McRae wrote: > > Has anyone gotten importing a shared library into Python to work? I > have ported SWIG to QNX and would like to add the functions in my shared > lib to Python using the 'import' statement. I have also tried to > compile my own Python intepreter with the functions embedded with no > success. > > Any help would be appreciated! > > --Paul > ----------------------------------------------------------------- > Paul McRae, Nortel Networks Optical, QNX Migration, TD22, > Work: 613-765-8872, Home: 613-822-8211, Cell: 613-863-0708 -- --Paul ----------------------------------------------------------------- Paul McRae, Nortel Networks Optical, QNX Migration, TD22, Work: 613-765-8872, Home: 613-822-8211, Cell: 613-863-0708 From sholden at holdenweb.com Tue Oct 2 08:33:53 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 2 Oct 2001 08:33:53 -0400 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> Message-ID: <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> "Dale Strickland-Clark" wrote in message news:9lajrtcqsojv72nr88c7j6kmdapjo44vc0 at 4ax.com... > A 'properly' encapsulated business class tends to involve methods and > attributes. However, managing attribute assignment gets very messy > with __setattr__ as you need to devise a scheme to distinguish class > attributes and working instance variables. > > Often, externally visible class attributes need to be validated and > instance variables don't. Or they may get stored elsewhere. > > What strategies have people come up with to manage this distinction > without bogging the code down in excessive checks. > > I would really like a way to distinguish between these two without > having to check dictionaries. > Dale: I'm not quite sure what problem you are trying to solve here. Are you suggesting that your code will change some class attributes and some instance attributes to parameterize the operation of all instances for a particular context. Maybe I need another cup of coffee ... Well, the coffee was a good idea. Your problem is that when you *use* __setattr__ you need to know whether you are setting a class or an instance variable, right? And you want to set class attributes from inside methods? Perhaps you'd explain what you mean by "proper" encapsulation is a problem in your particular context. I'm presuming that you are working in a COM environment, but of course I've been wrong before... regards Steve PS: See recent thread on not hiding your email address from spam! -- http://www.holdenweb.com/ From sap2002us at yahoo.com Fri Oct 12 15:59:04 2001 From: sap2002us at yahoo.com (Neal Irwin) Date: Fri, 12 Oct 2001 12:59:04 -0700 (PDT) Subject: Cgi Counter Message-ID: <20011012195904.47525.qmail@web21007.mail.yahoo.com> Does anyone have sample code for a web-page hit counter. I was curious what one would look like in Python. I have made one in Perl and would like to compare them. Thanks __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From jkraska at san.rr.com Tue Oct 2 20:19:56 2001 From: jkraska at san.rr.com (Courageous) Date: Wed, 03 Oct 2001 00:19:56 GMT Subject: "self" vs other names References: <1001621496.801193@cswreg.cos.agilent.com> Message-ID: On Thu, 27 Sep 2001 13:20:05 -0700 (PDT), "Sean 'Shaleh' Perry" wrote: >> >> Again, which code reads more easily is a matter of taste. I just thought >> I'd mention the possibility. >> > >not that I subscribe to this, but another common form is simply 's'. You get >things like 's.dict' or 's.pid'. I sometimes use a one letter abbreviation of the object type: class matrix: def f(m): pass C// From loewis at informatik.hu-berlin.de Mon Oct 1 05:01:01 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Oct 2001 11:01:01 +0200 Subject: How do Java interfaces translate to Python? References: Message-ID: Gordon Tyler writes: > > What exactly is it that you do with interfaces in Java? > > Enforcing a contract between objects, i.e. if you want to work with this > object, your object must implement this interface. [...] > I suppose the thing I'm really missing is compile-time type safety. If you want compile-time things to fail if an object isn't implementing an interface, then no, Python has no equivalent of that. If you want to make runtime assertions on interfaces, then you can do it like this: class Foo(Base): _interfaces = ['IFoo','IBar'] def implements(self, _if): return (_if in self._interfaces) or Base.implements(self, _if) foo = Foo() assert foo.implements('ISomething') Of course, this does only allows a runtime check that the class declares that it has the interface, not that the class actually implements the interface. This is like Java: even though the compiler can check whether the class implements all operations of the interface, it cannot verify whether all these implementations follow the interface contract (which may include invariants like "\forall x:foo.push(x);foo.pop() is x", or complexity guarantees). Regards, Martin From hungjunglu at yahoo.com Wed Oct 31 10:02:45 2001 From: hungjunglu at yahoo.com (Hung Jung Lu) Date: 31 Oct 2001 07:02:45 -0800 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> Message-ID: <8ef9bea6.0110310702.1f2bdae8@posting.google.com> Peter Wang wrote in message news:<6YLfO=JIhU1VpcRCSlWyV5uJY4mq at 4ax.com>... > i don't think data hiding's purpose is to keep rogue programmers in > line. it's partly to insulate imperfect development practice (e.g. > sloppy documentation) and partly to define an interface for a class. > someone else made the point that this is the purpose of documentation, > which should be kept up to date; i agree but people will invariably > look at code, and with python, since the entire code of the class is > exposed (unless you split off a portion of it into a hidden base > class), it's doubly enticing to use stuff you're not supposed to. It really depends on each person's own experience. I must say that I hated C++'s data hiding (the 'private' keyword). In a team environment, if someone hides data, you are at his/her mercy. This is a really life story: what if a few days before shipping your product, you need to modify the functionality of a class that is written by someone else, but you can't access the hidden data? What if the person that wrote the code is unreacheable (busy with something else)? As you may well known, in commercial productions, each person's code is untouchable by others (Source Safe), and some components are not even in code, but in the form of compiled library. What do you do? In C++, you are doomed, unless you resort to really dirty tricks. You can guess what I did: pointer tricks, I basically pried open all private data members, by force. Luckily the same trick worked for PC and for Mac, and the product shipped fine. Python allows you to patch existing codes. Even dynamically. Imagine your product depends on third-party codes, and there are problems/bugs with the third-party codes. What do you do? You file a bug report to the original authors, but you have to wait a few weeks/months before they release a new version. Do you want to dig into their code and modify it? I don't think so, because if you accidentally install their package again, all your changed are gone. What you want to do is write a dynamic patch to their code, in your own code space (in your files). Because you have access to all data, you can check conditions on when to apply the patch, so when a new version come out, you automatically stop applying the patch. You can see that Python, because it does not enforce data hiding, actually often insulate you better from code changes of other people. I don't think data hiding at the language level is a good thing. Really. The only valid rationale is to prevent name collision, which in Python you can do with a leading underscore. And for your information, the old place where I worked actually uses the same convention (leading underscore) for private data members in C++/Java, and they did not know Python. I've used initial underscore ever since. Believe me, it's a good notation. Data hiding is necessary for security issues. But my personal belief is that this kind of petty security issues should not be part of a programming language itself (it does not work, anyway, because in C++ you can access all data members, private or otherwise, via dirty tricks.) There are other ways of addressing security concerns, at a higher level. It's denigrating to programmers not to be able to do things at the language level. > interface isn't fully spec'ed out. and the guy who wrote the code is > out of town for a week. This is the time that you'll be REALLY grateful that you are using Python instead of Java or C++. Hung Jung From sholden at holdenweb.com Mon Oct 1 07:47:14 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 1 Oct 2001 07:47:14 -0400 Subject: How do Java interfaces translate to Python? References: Message-ID: wrote ... > [ ... ] (Java assumes you're both dishonest *and* > stupid). > Surprising Microsoft weren't more enthusiastic about it, really ;-) -- http://www.holdenweb.com/ From emile at fenx.com Wed Oct 31 10:19:13 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Oct 2001 07:19:13 -0800 Subject: External python file problem References: Message-ID: <9rp5kp$v4ev4$1@ID-11957.news.dfncis.de> You're looking for import. -- Emile van Sebille emile at fenx.com --------- "Thomas Weidner" wrote in message news:pan.2001.10.31.16.12.31.409.1057 at gmx.net... > Hi, > > i want a python program to load another .py file and execute a function > in this other file. > i compile the other file using the compile function,but how to get the > function i want from the resulting code object ? From sholden at holdenweb.com Thu Oct 4 23:37:43 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 23:37:43 -0400 Subject: Python is better than free (was Re: GNU wars again) References: Message-ID: "Tim Peters" wrote in message news:mailman.1002242226.28426.python-list at python.org... > [Steve Holden] > > Nope. If Tim were married, you would write about his and his wife's home > > (assuming they lived together) as the Peters's home. Since (and how > > could it be else) there is only one Tim, you should write about Tim > > Peters' way of thinking. > > Well, if there is only one Tim, we should drop the redundant surname and > just say it's Tim's simulation of thinking. > That would probably be perfectly comprehensible to about 80% of this group's readership. > BTW, doesn't this look fishy to you (s/Peters/Holden/)?: > > Nope. If Steve were married, you would write about his and his wife's > home (assuming they lived together) as the Holden's home. Since (and > how could it be else) there is only one Steve, you should write about > Steve Holden' way of thinking. > Not fishy, just plain wrong. But a global replacement of this nature makes about as much sense as replacing all the colons in a Python program with semicolons. There are rules, you know. [Sorry, I forgot, you're American] ;-) > When I was about 12, a teacher said Peter's or Peters's was acceptable for > the singular possessive (I stuck with Peters's), and Peterses' for the > plural (I stuck with Peters', and got extra credit later ). > > > but-then-i'm-english-so-what-do-i-know-ly y'rs - steve > > You *should* know that America fought a bloody war to get away from your > illogical grammar rules, and it can happen again. > Away with your nonsense. You just couldn't stand paying taxes to finance the English in their attempts to steal land (and just about everything else) from everybody else in the world. You wanted to steal this land for yourselves. > still-confused-about-fingersbreadth-vs-fingerbreadth's-ly y'rs - tim > fingersbreadth is the plural unit of measurement, fingerbreadth's is the possessive of one of them. "When the size of the disks is increased to five fingersbreadth, less than a fingerbreadth's span separates them". or-did-you-mean-fingerbreadths-ly y'rs - steve -- http://www.holdenweb.com/ From reqhye72zux at mailexpire.com Sun Oct 7 11:26:27 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Sun, 07 Oct 2001 15:26:27 -0000 Subject: Newbie question about running scripts References: Message-ID: Chris Gonnerman wrote: > From: "Lenny" > >> 3.) Is the RUN window the window they mean as the "Command Prompt >> Window"? > > No, as given above. But lots of text editors allow you to run a program or script from it. For instance: using SciTE[*] I can press F5 and run the Python script I'm working on. Very quick and convenient. Robert Amesz -- [*] Download it at www.scintilla.org, it's free and - amazingly - only a 350 Kb download. It works with Python 'out of the box'. From richard at bizarsoftware.com.au Wed Oct 10 21:04:06 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Thu, 11 Oct 2001 11:04:06 +1000 Subject: Python questions -> compiler and datatypes etc In-Reply-To: <15300.60842.366180.693270@beluga.mojam.com> References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> <01101110395417.11044@ike> <15300.60842.366180.693270@beluga.mojam.com> Message-ID: <01101111040618.11044@ike> On Thursday 11 October 2001 10:54, Skip Montanaro wrote: > Richard> ... and as far as I recall there is an ongoing effort right > Richard> now. I just can't find the reference at the moment. > > Try: > > http://homepages.ulb.ac.be/~arigo/psyco/ > > Only handles ints at the moment... Thanks Skip :) Richard From warkid at storm.ru Tue Oct 23 09:35:19 2001 From: warkid at storm.ru ( Kerim Borchaev ( WarKiD ) ) Date: Tue, 23 Oct 2001 17:35:19 +0400 Subject: unnecessary change In-Reply-To: <3BD5BCDF.B40C1422@gol.ge> References: <3BD5BCDF.B40C1422@gol.ge> Message-ID: <17732.011023@storm.ru> Hello Giorgi, try this( works for me ): self.Mactual=Numeric.array(self.Mdata) Best regards, Kerim mailto:warkid at storm.ru Tuesday, October 23, 2001, 10:54:23 PM, you wrote: GL> Hi folks! GL> My problem is the following: GL> I want to save initial data matrix, as e.g., follows GL> self.Mdata=Matr GL> In the same time I need a matrix, which is used and processed. The GL> latter is created as follows GL> self.Mactual=self.Mdata GL> No the problem is, that, when I have finished to use the Mactual matrix, GL> self.Mdata is always changed and equals the final Mactual matrix. GL> What is the systematic solution of the problem? GL> Thanx in advance, GL> Giorgi GL> PS. I use Numeric module. From MarkH at ActiveState.com Mon Oct 22 06:42:32 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Mon, 22 Oct 2001 10:42:32 GMT Subject: Service not stopping References: Message-ID: <3BD3F83E.3040206@ActiveState.com> belen at netcom.no wrote: > This a copy of my service... Can someone tell me wheta I have been > doing wrong? It would be of great help. Thanks a lot!!! ... > def SvcDoRun(self): > self.Start_Scheduler() > > import servicemanager > > servicemanager.LogMsg( > servicemanager.EVENTLOG_INFORMATION_TYPE, > servicemanager.PYS_SERVICE_STARTED, > (self._svc_name_,'')) > > while 1: > win32event.WaitForMultipleObjects > ((self.hWaitStop,self.hSched),0,win32event.INFINITE) > self.ReportServiceStatus > (win32service.SERVICE_STOP_PENDING) It looks to me like this function never returns. You almost certainly need to check the result of WaitForMultipleObject, and if the result is WAIT_OBJECT_0, break out of the loop. Mark. From x1xx1x at hotmail.com Thu Oct 18 11:43:32 2001 From: x1xx1x at hotmail.com (JT) Date: 18 Oct 2001 08:43:32 -0700 Subject: Help : IndexError - probably pretty simple Message-ID: I've been trying to learn Python and I was working on a function which would price options. But I've run in to an Indexing Error. This is probably pretty simple, but I still haven't figured out what I need to change. It gets hung up at the first "for" loop. I thought you could assign a value to each element of the list individually by placement, but maybe I need to use append. Any help would definitely be appreciated. I'll check back to the group for any responses, or you can respond directly to my email: x1xx1x at hotmail.com Thanks. Here is the error message: Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> import crrbinomial >>> crrbinomial.CRRBi() Traceback (most recent call last): File "", line 1, in ? crrbinomial.CRRBi() File "C:\PROGRA~1\Python21\crrbinomial.py", line 23, in CRRBi ov[i] = max(0, z * (stock * pow(u, i) * pow(d, n-1) - strike)) IndexError: list assignment index out of range >>> And here is the code: """The Cox-Ross-Rubinstein Binomial Tree Function CRRBi(): can be used to price European and American options on stocks (cc=interest), stocks and stock indexes paying a continuous dividend yield q (cc=interest-q), futures (cc=0), and currency options with foreign interest rate Rf (cc=interest-Rf).""" from math import exp, sqrt def CRRBi(ae="a", cp="c", stock=100, strike=100, time=(1.00/12), interest=0.6, cc=0.10, vol=1.00, n=10): """CRRBi: the Cox-Ross-Rubinstein Binomial Option Pricing Model""" ov = [] if cp == "c": z = 1 elif cp =="p": z = -1 dt = time / n u = exp(vol * sqrt(dt)) d = 1 / u a = exp(cc * dt) p = (a - d) / (u - d) Df = exp(-interest * dt) for i in range(n): ov[i] = max(0, z * (stock * pow(u, i) * pow(d, n-1) - strike)) for j in range(n-1, 0, -1): for i in range(j): if ae == "e": ov[i] = (p * ov[i+1] + (1 - p) * ov[i]) * Df elif ae == "a": ov[i] = max((z * (stock * pow(u, i) * pow(d, abs(i - j)) - strike)), -(p * ov[i+1] + (1 - p) * ov[i]) * Df) return ov[0] From anamax at earthlink.net Mon Oct 1 14:19:53 2001 From: anamax at earthlink.net (Andy Freeman) Date: 1 Oct 2001 11:19:53 -0700 Subject: sameness/identity References: <1001876090.367103@cswreg.cos.agilent.com> Message-ID: <8bbd9ac3.0110011019.286dc189@posting.google.com> weeks at vitus.scs.agilent.com (Greg Weeks) wrote in message news:<1001876090.367103 at cswreg.cos.agilent.com>... > x = 6.02 > y = 6.02 > > Are x and y identical? They are identical as *numbers* (which I'll call > conceptual identity) but not as Python *implentations* of numbers (since > id(x) != id(y)). Good programming style requires us to think of numbers > primarily as numbers and not as their implementations. So we are more > interested in conceptual identity than in implementation identity. ... > Why is (conceptual) identity of numbers different from (conceptual) > identity of bank accounts? Because bank accounts are mutable. A bank > account can have different states at different times. A number can't. > > So, we've encountered three kinds of identity in this discussion: > > A. conceptual identity > B. implementation identity > C. state identity > > In Python, B corresponds to "is". And to many Python programmers, C > corresponds to "==". But that leaves A without an operator. I'm unable to > swallow that. So, I use "==" for A; I never use "is"; and if I need C -- > which hasn't happened yet -- I write a method for it. The concept of conceptual identity isn't necessarily well defined for immutable objects. (The only reasonable definition for mutable objects is probably a constrained form of implementation identity, something along the lines of id that never changes, but note the difficulty in "never". Two objects whose lives don't overlap may well have the same id. The "same" object in different runs may well have different ids.) For immutable strings and numbers, value equality is conceptual equality. (I'd argue that 1.0, 1L, and 1 are value-disjoint, but ....) However, Python's tuples are arguably different. A tuple is an association without a generally agreed-upon composition rule. In other words, an integer can be thought of as a sequence of bits, but it also defines a composition of those bits that has a (mostly) generally-agreed on "value". Moreover, a tuple's elements are not "primitive" in any useful sense. >From an implementation's point of view, the possible complexity of a tuple's elements is an important constraint on reasonable implementations of conceptual equality. If we want to use a number-like definition, the implementation will either have a potentially expensive equality operation or it will have to return "equal" tuples whenever a tuple is constructed with the "same" arguments. A weak argument against defining conceptual equality on tuples like that on integers is that the integer definition doesn't let one use tuples to represent the concept "these four objects, associated at a specific moment". (Weeks probably doesn't like that concept or probably thinks that I should use a class for it, but .... Note - lists don't work - they're mutable.) I don't think that there is a "much more correct" definition for conceptual equality on tuples. I personally like the "addressed" based definition, but am sympathetic to the integer-like definition. (With the address definition, I can construct the integer-like definition, but the reverse is not possible and doesn't even make sense.) -andy From grante at visi.com Tue Oct 2 22:18:38 2001 From: grante at visi.com (Grant Edwards) Date: Wed, 03 Oct 2001 02:18:38 GMT Subject: "self" vs other names References: Message-ID: In article , Ignacio Vazquez-Abrams wrote: >On Wed, 3 Oct 2001, Tim Hammerquist wrote: > >> What would the world have been like if CP/M had won over (PC|MS)-DOS? > >Not that much different; AFAIK MS-DOS was based on some of the principles of >CP/M (8.3 filename, etc.). PC-DOS was an out-and-out copy of CP/M. The layout of FCBs was the same, the methods to call BIOS were the same, the layout of executable file headers was the same... -- Grant Edwards grante Yow! Jesuit priests are at DATING CAREER DIPLOMATS!! visi.com From pzw1 Wed Oct 31 21:41:25 2001 From: pzw1 (Peter Wang) Date: Wed, 31 Oct 2001 21:41:25 -0500 Subject: Underscore data hiding (was python development practices?) References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> <9rpbk1$19rg$1@nntp6.u.washington.edu> Message-ID: On Wed, 31 Oct 2001 18:42:03 -0600, Skip Montanaro wrote: >Smiley or not, you seem to be trying a bit too hard to compare Python with >C++. They serve dramatically different audiences. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ what are these dramatically different audiences? i'm pretty certain that python is well suited for many things which would have defaulted to C++ many years ago. there are certain features of C++ which make it attractive for specific applications, but even in those scenarios, if flexibility or scriptability is needed, python typically fits the bill. i'm a relative newbie at software development; i don't boast the decades of professional programming experience. however, just from observing developments in the software field, it seems that python's mindshare is steadily increasing as people turn to it from visual basic, lisp, perl, and C++ for applications which would have simply been done with whatever cumbersome language was default in the platform/application field. my questions about commericial development with python arise from my C++ background and my experiences with a team of fairly young C++ programmers. the direct comparison with C++ in the previous post was meant to be humorous, but i cannot deny the reality of how much C++ has shaped my (and many others') experiences with OOP. >After all, "we're all >adults here". That held true when I first heard it several years ago and it >holds true today. i'm also a relative newbie at being an adult, so i will ask forgiveness for my transgression.. ;) -peter From emile at fenx.com Tue Oct 16 12:44:37 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 16 Oct 2001 09:44:37 -0700 Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> Message-ID: <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> How about: >>> a array([3, 4]) >>> `a` 'array([3, 4])' >>> ky = `Numeric.array((3,4))` >>> ky 'array([3, 4])' Not ideal, but would work in a pinch. ;-) -- Emile van Sebille emile at fenx.com --------- "Uwe Schmitt" wrote in message news:9qhksb$6raii$1 at hades.rz.uni-sb.de... > Hi, > > I'd like to use a dictionary with NumericalPython-arrays as keys. > This does not work, because NumPy does not provide hashvals for > arrays. But this could be easyly done, as tupels are hashable. > So: how can I extend NumPy, so that arrays get a hashval ??? > > Greetings, Uwe. > > -- > Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes > phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 > D-66041 Saarbr?cken > http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 > From kragen at dnaco.net Tue Oct 16 17:12:49 2001 From: kragen at dnaco.net (Kragen Sitaker) Date: Tue, 16 Oct 2001 21:12:49 GMT Subject: Building a lib-wrapper, first step References: <3BCC198D.5010505@strakt.com> Message-ID: In article <3BCC198D.5010505 at strakt.com>, Rikard Bosnjakovic wrote: >I've got a small library (Linux) and I want to create some >wrapper-module so Python can use it. I've never done this before, so I'm >looking for some tutorial or such for this purpose. > >Is there any documents describing this somewhere, step-by-step or something? Someone suggested using SWIG (swig.org), but "Extending and Embedding the Python Interpreter", which is part of the documentation bundled with Python, explains how to do it by hand. -- Kragen Sitaker Perilous to all of us are the devices of an art deeper than we possess ourselves. -- Gandalf the White [J.R.R. Tolkien, "The Two Towers", Bk 3, Ch. XI] From ballabio at mac.com Tue Oct 16 10:24:12 2001 From: ballabio at mac.com (Luigi Ballabio) Date: Tue, 16 Oct 2001 15:24:12 +0100 Subject: FW: [Python-Dev] conditional expressions? In-Reply-To: <1226555.zL39ZcT7Z3@lunix.schabi.de> References: <9qgcvk$91j$1@animus.fel.iae.nl> <9qgsul$5ep$1@thorium.cix.co.uk> Message-ID: <5.1.0.14.0.20011016151605.00a56ec0@mail.mac.com> Hi, At 02:11 PM 10/16/01 +0200, Markus Schaber wrote: > > I believe Perl and Ruby has > > x = a if b > >What does this do? Is it a conditional assignment? It's a particular case of a syntax not limited to assignments. Namely, expression if test expression unless test are equivalent to (using Ruby syntax below) if test expression end if not test expression end respectively. I believe the same applies to Perl. There's no else clause, though---which is a necessary part of the ternary operator... Bye, Luigi From kima at newmail.net Sat Oct 20 03:52:18 2001 From: kima at newmail.net (Alex) Date: Sat, 20 Oct 2001 09:52:18 +0200 Subject: I am Adam H. Kerman your new god References: <4f87ff75.1e9e24af@webty.sd.us> <5c517d5a.b1ced549@webty.sd.us> Message-ID: <9qrkea$4s1$1@news.inter.net.il> u just sending those posts to have fun or u really idiot? "Paul" ???????/???????? ? ???????? ?????????: news:kSWo7.5$oD.23182 at news1.rsm1.occa.home.com... > Fuck You... > > > > "Adam H. Kerman" wrote in message > news:5c517d5a.b1ced549 at webty.sd.us... > > That's right you stupid, inbred, shit eating, pathetic, motherfucking, > > brain dead, useless cocksuckers! I'm taking over all of Usenet! There > > isn't a fucking thing you can do about it either! You're all a bunch > > of worthless scumbags, and now you will all answer to me! If you don't > > like this fact TOO FUCKING BAD! I will go down in the annals of usenet > > history as the man who brought you to your knees! Now get down on your > > knees and pay proper tribute to my glorious self! > > > > I AM ADAM H. KERMAN LORD AND HIGH MASTER OF USENET! > > > > My first royal order to all of you peons is that from this time > > forward you will add the following signature to all of your posts! > > > > > > ***** This was posted with the express permission of ***** > > ********************************************************** > > ** HIS HIGHNESS ADAM H KERMAN LORD AND MASTER OF USENET ** > > ********************************************************** > > *********** We are simple servants of his will *********** > > > > > > This will be appended to the bottom of all your posts with absolutely > > NO EXCEPTIONS! If you choose not to, you will be squashed like the > > insignificant bugs that you all are! > > > > I am running Usenet now! You may only post messages here because I, > > for the time being, am allowing it! Do you scumbags understand me! > > > > THIS IS THE DAWNING OF THE AGE OF KERMAN! > > > > ALL HAIL ADAM H. KERMAN LORD AND HIGH MASTER OF USENET! > > > > > > We moan them, then we nearly close Toni and Jim's orthodox > > sattelite phone. It's very usable today, I'll type > > smartly or Henry will contradict the governments. Let's > > prepare outside the pathetic websites, but don't eliminate the > > loud gorillas. Ophelia doesn't engulf weak pointers, do you > > start them? My actual stack won't place before I propagate it. > > Don't try to pump a rumour! Excelsior sadly reboots > > untouched and locates our disgusting, sly hackers with a > > cyphertext. She wants to contribute moronic analysts > > to Alice's window. While investigators finally generate > > ideas, the discs often learn beneath the violent firewalls. > > There Francoise will outwit the error, and if Madeleine > > badly creates it too, the protocol will substantiate > > about the tall haven. The mixmasters, programmers, and > > ROMs are all minor and bright. If you will corrupt > > Gregory's database around FORTRANs, it will strongly > > load the iteration. They are opening behind lost, > > over root, around powerful users. Why did Mel vexate > > without all the trackballs? We can't spool cowboys unless > > Vance will actually disrupt afterwards. You won't > > transport me disappearing to your strange sneaker. Other > > bizarre plastic postmasters will reload weekly without > > admins. She'd rather slump crudely than twist with > > Marian's veggie robot. The CDROM against the stuck > > web page is the modem that excludes weakly. Ratana wants to > > insulate simply, unless Jimmy manages newsgroups over > > Jonathan's PGP. They are deleting around the data center now, won't > > dream backups later. > > > > > > > > From morris at baycity.net Sun Oct 14 18:50:09 2001 From: morris at baycity.net (Robert Morris) Date: Sun Oct 14 18:50:09 2001 Subject: Quintessential British Time Machine? Message-ID: > I guess I haven't been paying enough attention to others working > in my field. I assumed that the TARDIS was the quintessential > British time machine design; can anyone explain how it works, and > why I am wrong about this? It's a common mistake, Doc. You must realize that the TARDIS is, in fact, a piece of advanced alien technology; the foremost example just happens to belong to a Gallifreyan who likes the British isles. The TARDIS is powered by a captive quantum black hole which is called the "Eye of Harmony." The powerful gravitational forces available from this device allow the folding of spacetime; this is why a TARDIS is larger on the inside than the outside. The TARDIS can achieve attenuation, like Dr. Wells' machine does, and can travel in time and space at rates beyond the limits of conventional relativity theory. In fact, Dr. Wells' machine is much more the standard British design. I am blessed to have received a partial copy of his blueprints and notes, covering the crystalline temporal field controller. I have not yet been able to discover the means by which he provided the continuous 450 to 475 megawatts the device seems to require, but I have created a working unit powered by a capacitor device of my own design. I have reviewed the design drawings of your Flux Capacitor unit which you so kindly sent me, and I see many parallels with the Wells design. The instantaneous transition which your device provides has a lower total energy consumption for trips of over about 9.5 years than the Wells Temporal Field unit; but for shorter trips his device is superior in this area. More important in my opinion is the attenuation field effect provided by Wells' machine. In effect, the vehicle and contents become invisible and intangible; this effect is related somehow to Banzai's Oscillation Overthruster but so far he has not had time to discuss it with me. Now I see that I have wandered off topic, into what might be called the History of Time Travel (if that's not inherently a paradox). So, what the heck. I think perhaps the most interesting story has to be that of Guido van Rossum. His time machine uses a core element very similar to your Flux Capacitor, powered on its' initial trip by a capacitor device similar to mine. On that first trip he evidently visited the future to retrieve a more powerful energy source, nature unrevealed. He also brought back advanced android technology, which he used to engineer his "bot" lieutenants. I am personally afraid that he has become paranoid (trusting machines over humans). I have also heard rumors that some of his followers formed a secretive organization, the PSU, to fight some dangerous alien force. Sounds like science fiction to me. From gbeasley at tsa.ac.za Wed Oct 31 02:46:17 2001 From: gbeasley at tsa.ac.za (Grant Beasley) Date: Wed, 31 Oct 2001 09:46:17 +0200 Subject: Strange results when comparing dates Message-ID: <9roa85$5ll$1@ctb-nnrp2.saix.net> Hi I'm using the cx_Oracle module to access an Oracle database, in doing so, I'm retrieving date time variables. According to the Python Database API, I can use Timestamp to convert a time tuple (year, month, day, hour, minute, second) to a date time type variable as used by the cx_Oracle module. This works, and I can create these variables, but when comparing them I get VERY strange results. Using the same programme, with no reference to "outside influences", I get different results on different runs. Here's the programme: import cx_Oracle cdt1 = cx_Oracle.Timestamp(2001, 10, 25, 11, 12, 42) cdt2 = cx_Oracle.Timestamp(2001, 10, 31, 9, 4, 43) cdt3 = cx_Oracle.Timestamp(2001, 10, 31, 9,5,3) print "Start\n" print cdt1, ">", cdt2, "=", (cdt1 > cdt2) print cdt2, ">", cdt3, "=", (cdt2 > cdt3) print cdt3, ">", cdt1, "=", (cdt3 > cdt1) And the Results of 3 runs (one after the other in pretty quick succession), all different Start 2001-10-25 11:12:42 > 2001-10-31 09:04:43 = 0 2001-10-31 09:04:43 > 2001-10-31 09:05:03 = 0 2001-10-31 09:05:03 > 2001-10-25 11:12:42 = 1 Start 2001-10-25 11:12:42 > 2001-10-31 09:04:43 = 1 2001-10-31 09:04:43 > 2001-10-31 09:05:03 = 0 2001-10-31 09:05:03 > 2001-10-25 11:12:42 = 0 Start 2001-10-25 11:12:42 > 2001-10-31 09:04:43 = 0 2001-10-31 09:04:43 > 2001-10-31 09:05:03 = 1 2001-10-31 09:05:03 > 2001-10-25 11:12:42 = 1 Am I doing something wrong, is this a bug with the cx_Oracle module that I should report to the author, or is it a python problem? What's wrong, and how can I fix it. I could try to convert the oracle datetime type to a python / Unix date format, but that would involve extra work and I'm very curious as to why the above doesn't. If it's important, the way I'm using it in practice is selecting a date field from the database, then using Timestamp to convert the current time (using localtime and time) to an oracle datetime type and then comparing the two variables. Thanks Grant Beasley From peter at engcorp.com Thu Oct 18 23:34:18 2001 From: peter at engcorp.com (Peter Hansen) Date: Thu, 18 Oct 2001 23:34:18 -0400 Subject: Random from Dictionary References: <4f7234de.0110180504.20aa475b@posting.google.com> <9qml3o$ovl8k$1@ID-11957.news.dfncis.de> <181020010938443703%tpayne@mac.com> Message-ID: <3BCF9F3A.BAF8A27A@engcorp.com> Tim Payne wrote: > > In article <9qml3o$ovl8k$1 at ID-11957.news.dfncis.de>, Emile van Sebille > wrote: > > > Maybe choice in random helps out. > > I've always gotten this error when trying choice. I figured you just > couldn't use it on a dictionary, but maybe something else is wrong with > my install? > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.1/random.py", line 329, in choice > return seq[int(self.random() * len(seq))] > KeyError: 1 >>> import random >>> print random.choice.__doc__ Choose a random element from a non-empty sequence. >>> random.choice([1, 2]) 2 >>> dict = { 'x' : 4, 'y' : 6 } >>> random.choice(dict) Traceback (most recent call last): File "", line 1, in ? File "c:\python21\lib\random.py", line 329, in choice return seq[int(self.random() * len(seq))] KeyError: 1 >>> random.choice(dict.keys()) 'x' In the Python reference manual, the "standard type hierarchy" indicates that a Dictionary is a type of Mapping which is not a Sequence. The __doc__ string from random.choice asks for a sequence, so you are right that you can't use it on a dictionary. dict.keys() works... -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From bokr at accessone.com Sat Oct 13 21:15:21 2001 From: bokr at accessone.com (Bengt Richter) Date: Sun, 14 Oct 2001 01:15:21 GMT Subject: dictionary.update() enhancement? References: Message-ID: <3bc8e1ec.454947329@wa.news.verio.net> On Fri, 12 Oct 2001 22:54:27 -0400, "Tim Peters" wrote: >[Mark J] [...] >> would be called with the two respective values when a key collision ^^^^^^^^^^^^^^^^^^^^ >> occurs. ^^^^^^ [...] > >Unfortunately, it would be slower than hand iteration. David Bolen went >into the most detail about that, and he's right: the overhead of calling >back into a Python function each time would kill performance. ^^^^^^^^^ ISTM you're talking about different things ;-) The way I read it, the collision *detection* would be done without calling the policy-defining function (presumably in C modified to make the test in C and conditionally call back). Then results would depend on the collision percentage, but in general there should be a gain over a totally-by-hand loop, IWT. From grahamd at dscpl.com.au Sun Oct 7 20:05:54 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 7 Oct 2001 17:05:54 -0700 Subject: SOAP.py and Python 2.1.1 References: Message-ID: Gabriel Ambuehl wrote in message news:... > -----BEGIN PGP SIGNED MESSAGE----- > > Hello, > I'm trying to get SOAP.py V.0.9.7 to work on Python 2.1.1 (built from > ports on a FreeBSD 4.4 box). While the server starts like it should, > the client won't even send out a query but instead prints the > following traceback: > serv.addAccount(ownerid=2, customerid=1, accounttype=3, > webserverid=111, mailserverid=111, adminserverid=111, > webmailserverid=111, mysqlserverid=111, domainname="buz-test.com", > password='aaakkaa', quota_webspace=100, quota_emailaccounts=50, > quota_forwarders=-1, quota_autoresponders=-1, quota_mailinglists=10, > quota_ftpaccounts=10, quota_subdomains=100) > File "SOAP.py", line 3603, in __r_call > self.__hd, self.__ma) > File "SOAP.py", line 3523, in __call > p, attrs = parseSOAPRPC(r, attrs = 1) > File "SOAP.py", line 2804, in parseSOAPRPC > t = _parseSOAP(xml_str, rules = rules) > File "SOAP.py", line 2776, in _parseSOAP > parser = xml.sax.make_parser() > File "/usr/local/lib/python2.1/xml/sax/__init__.py", line 88, in > make_parser > raise SAXReaderNotAvailable("No parsers found", None) > xml.sax._exceptions.SAXReaderNotAvailable: No parsers found > > > This confuses me cause I thought xml should be available from stock > and I've even got expat-1.2 and expat 1.95 installed so what's wrong > here? Hmmm, that is generally what happens when expat isn't there, unless how it got installed was a bit strange. Maybe the fact you have two versions installed somehow causes a problem. Only wisdom I can offer is that when I upgraded my box lately there was no expat, but I installed PyXML which comes with expat and SOAP.py worked fine. PyXML actually installs in _xmlplus, with expat under there somewhere, but it does something so that even when xml is used, it still finds the parser. No idea otherwise. From sholden at holdenweb.com Wed Oct 31 07:38:31 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 07:38:31 -0500 Subject: Python.NET, MONO and Visual Studio etc. References: Message-ID: "Xavier Defrang" wrote ... > [ ... ] > this message contains opinions defining an extreme point of view > This is almost off-topic but since you guys are talking about that .NET > thing, I'd like just to ask anyone in here : WHAT THE HELL IS .NET??? > A rehashing of twenty-year-old software ideas by the largest force in the industry to maintain their revenue base in the face of customers reluctant to "upgrade" from one inadequate product to another (can we say "poor security"?). > I don't want any fancy buzzwords or corpspeak crap. I just want a clear, > step-by-step explanation of what it is and what should I believe it's the > revolution MS claim it is. Why are people investing bucks in developping > .NET software when nobody can clearly see what it is. For the same reason they invested in OLE when it too was smoke and mirrors. They have been fed fear, uncertainty and doubt by Microsoft for so long that they are no longer capable of saying "Sorry, that's not for me, I'm going to do something else that makes more sense for my organisation". If Microsoft are doing something, the reasoning goes, then everyone will be doing it and so I should too. To be fair to Microsoft, .NET has some good ideas in it: the common language runtime that supports a common (MSIL) intermediate language for all compiled languages and adapts it to the particular hardware as required is neat, though not new. It also contains better (though not perfect) solutions to the software versioning problem, allowing several different versions of support libraries to be incorporated into different software products without conflict. Possibly even better than Unix shared library versioning, whihc has been around for fifteen years now. > I'm surrounded by > skilled web and software architects and absolutely none of them has a > clear idea about this "next generation" framework/platform/strategy/initiative. For me, .NET just looks like a > new branding strategy for all MS development product line. What's .NET > but a mix of buzzwords and the deployment of big brotherish SOAP-enabled > services? > Well, that comes close. The really ironic thing is that most of the "technologies" Microsoft are attempting to embrace with .NET could have been incorporated into their product line at any time they had the imagination to do it. There is no fundamentally new technology in .NET. > Any explanation of link to valuable online resource are more than > welcome... > You'd better take a look at Microsoft's site. As they understand it better, so will the rest of the world :-) .NET? Just say "no". devil's-advocate-ly y'rs - steve -- http://www.holdenweb.com/ From thecalm at NOSPAM.btinternet.com Fri Oct 12 07:45:34 2001 From: thecalm at NOSPAM.btinternet.com (G. Willoughby) Date: Fri, 12 Oct 2001 12:45:34 +0100 Subject: a pure python mp3 player? References: <9q50uh$qlj$1@uranium.btinternet.com> Message-ID: <9q6l1m$bi2$1@uranium.btinternet.com> just asking... ;-) G. Willoughby "William Tanksley" wrote in message news:slrn9sc2tr.pen.wtanksle at dolphin.openprojects.net... > On Thu, 11 Oct 2001 21:56:16 +0100, G. Willoughby wrote: > >Hi, > > do you know of any mp3 players that have been exclusively written in > >python, and not just a gui for the C coded 'mp123'? > > Hope you're kidding. > > Not only is MP3 playing *very* mathematically complex, but it requires > heavy access to audio playing, which is rather difficult. > > I suppose a NumPy-based MP3 decoder would be possible, but after that we'd > want to pipe the output to something like a WAV player, not play it ourself. > > >G. WIlloughby > > -- > -William "Billy" Tanksley From calves at coelce.com.br Tue Oct 16 10:48:58 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Tue, 16 Oct 2001 11:48:58 -0300 Subject: FW: fast sub list operations Message-ID: <29A97D00F387D411AC7900902770E148021A45B8@lcoeexc01.coelce.net> -----Original Message----- From: Robin Becker [mailto:robin at jessikat.fsnet.co.uk] Sent: Tuesday, October 16, 2001 8:34 AM To: python-list at python.org Subject: fast sub list operations I constantly miss some nice way to subset lists. As an example suppose I have a list of x y coordinates eg [x0,y0,x1,y1,.....] and wish to perform the operation x->x+v, y->y+w for the co-ordinates in the list I don't seem to be able to do this fast using map. Even if I had a way to slice the list nicely into X=[x0,x1,.....x(n-1)] & Y=[y0,y1,.....,y(n-1)] so that I can do map(operator.add,X,n*[v]) to perform the arithmetic quickly I don't seem to have an interlace to get back to the original list format. How can these kinds of operations be performed quickly in current python and what if any new features would python require to do them best? -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list **************************************************************************** **************************************************************************** ****************************************** What do you think of this? 1 - Define the list of coordenates like this X=[(x1,y1),(x2,y2),...,(xn,yn)] and operator like this oper=[(v,w)] 2 - Then, define a function def add_list_tuples(lista,listb): import operator result=[] for i in range(len(a)): p=operator.add(a[i][0],b[i][0]) q=operator.add(a[i][1],b[i][1]) result.append(tuple((p,q))) return result 3 - Then, all you need to do is to apply map(add_list_tuples,X,n*oper) to get what you want -------------- next part -------------- An HTML attachment was scrubbed... URL: From loewis at informatik.hu-berlin.de Tue Oct 9 09:13:17 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 09 Oct 2001 15:13:17 +0200 Subject: Curious assignment behaviour References: <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> Message-ID: Dale Strickland-Clark writes: > I'm not sure I sympathise with the philosophy that if you can't please > everyone then don't please anyone. An argumentative group can thus > bring progress to a stand-still. I don't sympathise with that philosophy, either. However, I cannot see an instance of it here. I'm quite pleased with the status quo, and I don't see any problem to solve here. > That's my twopence worth, anyway. :-) It may not be worth much more than that... If you seriously want this feature, you need to write a PEP, and perhaps implement the feature, gaining user support, etc. Otherwise, I can promise you that nothing will change. Regards, Martin From jwbaxter at spamcop.net Wed Oct 10 10:49:55 2001 From: jwbaxter at spamcop.net (John W. Baxter) Date: Wed, 10 Oct 2001 07:49:55 -0700 Subject: Curious assignment behaviour References: Message-ID: <101020010749554529%jwbaxter@spamcop.net> In article , Tim Peters wrote: > It only takes one of those to sour you on the idea for life. In my case, that event was receiving some C code from a former boss. He had looked at the assembly output from a problem area of code and was wondering why the (early C compiler for Intel 8080) was storing a 0 into memory and then immediately reading the value out and checking whether it was 0*. Indeed, I spotted if (a = 0) ... It wasn't long before I started--along with many others--turning examples with a literal constant around, producing the uglier but safer if (0 == a) ... sort of thing. I don't want to see Python go down this road. * Can't trust that darn RAM!...which was somewhat true in the late 1970s. --John From emile at fenx.com Tue Oct 30 08:01:11 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Oct 2001 05:01:11 -0800 Subject: file operations References: Message-ID: <9rm8jq$uppn3$1@ID-11957.news.dfncis.de> "Kerstin" wrote in message news:bbdd9a89.0110300230.70996c4c at posting.google.com... > Hi, > I need to do the following file operations: > > begin loop > - read file > - replace something in the file (seem to work) > - write file > end loop > It looks like you've gotten as far as replacing. For write, make sure you've open'd the file setting mode to 'w'. If it still doesn't work, post some code so we can spot a specific problem. HTH, -- Emile van Sebille emile at fenx.com --------- From jblazi at hotmail.com Wed Oct 3 13:27:19 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Wed, 3 Oct 2001 19:27:19 +0200 Subject: Basic button question Message-ID: <3bbb4a89_8@news.newsgroups.com> I have a button that is bound to a call-back wich ''. Now when I press the button, it is not pressed and the call-back is called immediately. It then creates a new toplevel window and a lot of processing happens. Finally, when th newly created toplevel returns (I use t.quit() and t.destroy()), the original button is pressed (a bit late) and remains pressed, unless I touch it with the mouse. All this look very, very ugly. Can somebody give me a hint? J.B. ----------------------------------------------- "This book is for children, but adults can read it as well, because the beginners in a field ar like children in that field." Zoltan Kodaly -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From dale at riverhall.NOSPAMco.uk Fri Oct 5 21:27:45 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Sat, 06 Oct 2001 02:27:45 +0100 Subject: Generating a random number References: <9plkkk$98r$1@ins22.netins.net> Message-ID: <4cnsrtsj7ks3jc6emj39ksod2ipmr9f0bb@4ax.com> "Ron White" wrote: >Will someone please tell me exactly how to generate a random number from 1 >to 10 in Python 2.1.1 running under windows me? I'm beginning to think >there is something wrong with my installation or I'm just not smart enough >to understand what I read. > >Thank you for any help. >Ron from whrandom import randint print randint(1, 10) -- Dale Strickland-Clark Riverhall Systems Ltd From fdrake at acm.org Sun Oct 14 00:46:12 2001 From: fdrake at acm.org (Fred L. Drake) Date: Sun, 14 Oct 2001 00:46:12 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011014044612.90DE228697@beowolf.digicool.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Added documentation for the PyMarshal_*() functions in the Python/C API. From phd at phd.pp.ru Fri Oct 26 09:37:56 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 26 Oct 2001 17:37:56 +0400 Subject: compiling from source (without root privleges) In-Reply-To: <15321.25988.663674.374512@beluga.mojam.com>; from skip@pobox.com on Fri, Oct 26, 2001 at 08:30:44AM -0500 References: <62e69c0c.0110252126.6a4a017b@posting.google.com> <20011026120021.E25157@phd.pp.ru> <15321.25988.663674.374512@beluga.mojam.com> Message-ID: <20011026173756.Q25157@phd.pp.ru> On Fri, Oct 26, 2001 at 08:30:44AM -0500, Skip Montanaro wrote: > >> My web host (webaxxs.net) refuses to upgrade from Python 1.5 to 2.x. > >> > >> I am wondering if I have any hope of being able to compile from > >> source, without having root privleges. They are running a modified > >> Red Hat. > > Oleg> I did it few times ... > > I build Python from the latest CVS source day or two. I *never* do this as > root, so my guess would be that it is possible. ;-) The original question was about non-root *installation*. Of course I never compile as root :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jmsun at bioeng.ucsd.edu Fri Oct 5 15:00:36 2001 From: jmsun at bioeng.ucsd.edu (Jeffrey) Date: 5 Oct 2001 12:00:36 -0700 Subject: Tkinter Html Display Message-ID: <3daa1aa8.0110051100.33815499@posting.google.com> Hi All, I want to display an HTML file on a Tkinter Canvas widget. Do any of you know how to do this? The principle problem I have is that the HTML file can display subscript and symbols and stuff, while translated the HTML lines into text, you lose that. I came up with one solution that one could just capture the HTML off the browser and turn it into a gif file and then display on the widget. But I just wanted to know if there is anything out there or any solution for this.... Thanks, Jeff From greg at cosc.canterbury.ac.nz Thu Oct 25 21:39:52 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 26 Oct 2001 14:39:52 +1300 Subject: Learing Python, Newbie question References: Message-ID: <3BD8BEE8.B7AB09AE@cosc.canterbury.ac.nz> Johannes Gamperl wrote: > > if db_first: > db_flag = "w"; > else: > db_flag = "a"; > > is there a better way to write this? If by "better" you mean "more readable and easier to maintain", I would say no. If you mean "shorter", "cuter", "more cryptic", etc. you could use db_flag = "wa"[db_first] provided db_first is known to be either 0 or 1. (By the way, get out of the habit of putting semicolons on the ends of statements in Python. They're redundant, and your right little finger will thank you for it!) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From jjl at pobox.com Wed Oct 3 10:24:35 2001 From: jjl at pobox.com (John J. Lee) Date: Wed, 3 Oct 2001 15:24:35 +0100 Subject: Assignment not the same as defining? In-Reply-To: References: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> Message-ID: On Wed, 3 Oct 2001, Oleg Broytmann wrote: > On Wed, Oct 03, 2001 at 12:35:58PM +0100, Dale Strickland-Clark wrote: [...] > Python does not have assingment at all. > a = b > is not assignment in Python - it is binding and rebinding. Reference to > b copied into a. Only reference, not an object. [...] true, but that's not the answer to the problem -- it's the caching that stops this from working, as somebody else has pointed out. John From Georg.Bisseling at pallas.com Thu Oct 11 10:05:36 2001 From: Georg.Bisseling at pallas.com (Georg Bisseling) Date: Thu, 11 Oct 2001 16:05:36 +0200 Subject: Profiling PyOpenGL References: Message-ID: <3BC5A730.9159CE75@pallas.com> [sent by email and posted via news] " Kerim Borchaev ( WarKiD )" wrote: > > Hello python-list, > > why can't I profile PyOpenGL application using profile module? > glutMainLoop() > but it prints nothing unless I remove glutMainLoop call. Because glutMainLoop() is an endless loop as long as you do not close the window. From michael at rcp.co.uk Tue Oct 9 12:14:54 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Tue, 9 Oct 2001 16:14:54 +0000 (UTC) Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <7x4rp8q1cy.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote in news:7x4rp8q1cy.fsf at ruckus.brouhaha.com: > Guido van Rossum writes: >> Marcin, I don't understand why you care so much about being able to >> write 3.foo. It's painful to fix in the lexer, and probably leads to >> less useful error messages if someone makes a mistake in a float >> literal (e.g. "3.e 0"). And I see zero use for it: in practice, you >> will never ask for 3.foo -- you'll ask for x.foo where x happens to >> contain the value 3. > > How about (3).foo? Or even 3 .foo? From aa at bb.cc Thu Oct 25 18:35:46 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Fri, 26 Oct 2001 00:35:46 +0200 Subject: Question: Dynamic code import References: <3bd86fb9_5@corp-goliath.newsgroups.com> Message-ID: <3bd88e8e_1@corp-goliath.newsgroups.com> Thanks indeed! 'exec' might be the answer to my question. 'import' is not ok as the input file may not exist at all when the script starts running. Cheers K?roly "Lucio Torre" az al?bbiakat ?rta a k?vetkezo ?zenetben: news:mailman.1004043866.29873.python-list at python.org... > K?roly Ladv?nszky wrote: > > >Hi Bjorn, > > > >Thanks for your quick answer. Yes, I was mistaken with the global directive. > >It's clear now. > >Regarding the first question, it works fine with the interpreter but I would > >like to read > >f11(a) from somewhere else, most likely from a file. > > > >Cheers, > > > >K?roly > > > > > > you can do this: > > import f1 > import f2 > > f =f1. f > f() > f=f2.f > f() > > or mess with the imp module. > or, do the tricky thing: > > ---------------- f2.py > def f(): > print "f2" > ---------------- f2.py > > ---------------- f.py > def f(): > print "f1" > > fun = f > fun() > > file = open("f2.py") > text = file.read() > exec(text) > > fun = f2 > fun() > > ---------------- f.py > > but i think you sohuld stick with import. > > ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From hugomartires at hotmail.com Wed Oct 10 07:14:48 2001 From: hugomartires at hotmail.com (Hugo Martires) Date: 10 Oct 2001 04:14:48 -0700 Subject: Sockets Message-ID: My server need to send 2 strings separeted: s1= 'xxx' s2= 'yyy' My client must received like this: rec1= 'xxx' rec2= 'yyy' The problem is that the Client received s1 and s2 in one only string. How can i received in 2 separeted variables ? Tanks From pinard at iro.umontreal.ca Wed Oct 17 20:28:32 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 17 Oct 2001 20:28:32 -0400 Subject: Pymacs 0.11 In-Reply-To: <9ql1ln$306$1@animus.fel.iae.nl> References: <9qjosn$5nd$1@animus.fel.iae.nl> <9ql1ln$306$1@animus.fel.iae.nl> Message-ID: [Carel Fellinger] > But maby it's possible--in anticipation of a wider usage of more modern > Pythons--to check first for such a function attribute, like: > try: > interaction = fun.lisp_interaction > except NameError: > interaction = interactions[fun] Simple enough. Done! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From tex_r at hotmail.com Thu Oct 18 21:29:37 2001 From: tex_r at hotmail.com (Tex Riddell) Date: Thu, 18 Oct 2001 18:29:37 -0700 Subject: Is there a small Python runtime environment installer? References: <3583b331.0110181524.5695bd67@posting.google.com> Message-ID: <3bcf81f8@news.microsoft.com> "David Bolen" wrote in message news:uwv1sik4n.fsf at ctwd0143.fitlinxx.com... > tex_r at hotmail.com (Tex Riddell) writes: > > > More specifically I'm looking for something for the windows > > environment, but one should be able to make something like this > > multi-platform, right? > > Well, you'd have a harder time having a portable distribution if you > were looking for a binary, sort of by definition. I detect a hint of sarcasm here. Of course, that's not what I meant. I meant binary installers for each platform that would set up a similar environment for running your scripts in, regardless of end-user's platform. > But since you're specifically targetted at Windows, why not just use > the standard Windows installer? It lets you ignore the examples and > documentation and just install the core stuff if you like. Any > Windows user should be completely at home with the installation > process. I was just looking for something smaller and simpler. If you read further, I mention clumping/compressing multiple files into single archives to keep things reasonable small. I don't expect to have to sit over the shoulder of the user who is installing a python distribution and tell them to de-select this, and that, oh, and that, drill down, and this and that... I just want a simple, configurable, re-distributable runtime. Because of scripts, utilities and the like, the default ActivePython installs about 24 megs of stuff in so many files that depending on the file system could take up as much as 70 megs of space on the user's HD. That's a little much to ask just so they can run a little utility script I want to send them. > > How can we expect python to become more mainstream if only developers > > can understand the environment that must be set up for scripts to run? > > At least under Windows, I don't think installing Python is any harder > than installing any other application. That's largely true as well on > various Unix platforms, since there are rpms and other install > packages written for Python to conform to local platform expectations. You missed my point, if you are installing office, you would be expected to know what office *is*, therefore knowing what options you want and do not want installed. When my friend is installing Python, all they know is that it is something that'll make the stuff I send them run. They will select default installation, because they couldn't know any better. > > I really don't have time to learn distutils (re-inventing the wheel > > that I'm sure so many have done) in order to install a runtime > > environment on someone's machine so they can run a simple 8k script. > > Of course, those same people (under Windows) have already installed > MBs of common code just so they can run small VB applications, whether > via their initial Windows installation or updated silently in other > stuff they may have installed. :-) True, however, most of that common code is used by Python as well! Only specific parts are specific to VB. Those parts won't necessarilly just *be* on a host machine. This is the runtime library that must be installed. VB, however, has the advantage that it produces executables that just look for a runtime dll when run. This is quite a bit simpler than with python, having to set up additional paths and environment variables to make .py files executable. > BTW, there is also the option of constructing a standalone > installation (for Windows, look into the py2exe or installer packages, > and installer also handles Linux) for your script. For Windows, it > would include the Python DLL and appropriate lib files all packages > into a single file or collection of files that you could then > distribute independently of any other. On the Windows platform if you > combine that with an installer - like the free Inno Setup - you'd end > up handing your script to your friend as a normal Windows installation > program that took care of installing everything. I am aware of this option, but as my script is a small simple shell script, not a stand-alone GUI app, if I wanted to send more scripts, I would have to build more installers! These seem to only try to track the dependencies of a single application, then bundle only these parts in the installation. I'm not prepared to write a setup program just to install a utility script... I've wasted too much time on this already! > Of course, this would be much larger than an 8K script and would thus > be hellishly less efficient if you were sending a lot of scripts this > way (as opposed to just having him install the runtime one time), but > for a one-shot deal it would make the receiver's life simple. exactly! Do you at least understand what I'm trying to get at? Imagine python was like html. End users typically have a web browser that includes a set of standard features built around the standard. Those end users need not install development kits in order to view an html file. They simply download a web browser. Also people distributing an html file wouldn't need to build a browser around their file that included only the features that thier file used and send it to the user! -Tex From brueckd at tbye.com Wed Oct 24 22:42:01 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 24 Oct 2001 19:42:01 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: Message-ID: On 24 Oct 2001, David Bolen wrote: > > I was merely responding to somebody's not-entirely-true assertion that > > "_every_ access to that [shared] resource _must_ be enclosed in locks". > > But that statement is more true than not (as other respondents have > shown, even a simple assignment may be an issue) Maybe, maybe not. Like I said before, it depends entirely on your application, and is not a hard and fast rule by any means. A ton of the locking work I have to do in other languages revolves around preventing the type of corruption that leads to crashes, and this is what the interpreter gives me for free. > There are some cases (e.g., when performing read-only access to a > value where it isn't critical if the value changes and you just get > one of the two potential values, such as when watching a sentinel that > you'll just pick up on the next loop), but you really do need to > consider all possible users of every shared resource. That's true either way. With a very few multithreaded Python apps under your belt it gets so that it doesn't take too many brain cycles to recognize the GIL-does-this-for-free scenarios. Yes, you can always overengineer a solution if you want, but that's not very Pythonic. Think of it this way: the way the GIL works can impose a slight performance hit on your program (a cost). With that cost is an associated benefit. You can choose whether or not to enjoy that benefit, but you've already paid the cost so you might as well. -Dave From skip at pobox.com Thu Oct 11 08:04:01 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 11 Oct 2001 07:04:01 -0500 Subject: Python questions -> compiler and datatypes etc In-Reply-To: <3BC519F2.4020808@erols.com> References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> <01101110395417.11044@ike> <15300.60842.366180.693270@beluga.mojam.com> <3BC519F2.4020808@erols.com> Message-ID: <15301.35505.614493.289465@beluga.mojam.com> >>> http://homepages.ulb.ac.be/~arigo/psyco/ Edward> Has Guido seen this? He's at least aware of it. I don't know if he's had a chance to examine or comment on Armin's latest efforts. Skip From peter.neubauer at windh.com Tue Oct 2 09:23:02 2001 From: peter.neubauer at windh.com (Peter Neubauer) Date: Tue, 2 Oct 2001 15:23:02 +0200 Subject: XML Marshalling of objects Message-ID: Hello, I'm wondering if there is a good way to marshal/unmarshal python objects to XML? I'm thinking of some framework like Castor (castor.exolab.org) for Java. Is xml-rpc the right way to go? thanks for help /peter mailto:peter at windh.com From johnroth at ameritech.net Wed Oct 10 11:42:32 2001 From: johnroth at ameritech.net (John Roth) Date: Wed, 10 Oct 2001 08:42:32 -0700 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <7x4rp8q1cy.fsf@ruckus.brouhaha.com> Message-ID: "Michael Abbott" wrote in message news:Xns9135B158B74CBmichaelrcpcouk at 194.238.50.13... > Paul Rubin wrote in > news:7x4rp8q1cy.fsf at ruckus.brouhaha.com: > > > How about (3).foo? > > I should have tried it before posting. This (and 3 .foo) already works in > Python 2.1 (complains "'int' object has no attribute 'foo'", of course), so > I would have thought the entire discussion was pointless: nothing needs to > be changed to get the desired behaviour! That's not exactly true. Making a feature dependent on whether there is white space between components violates the principle of least astonishment. It's also a very fertile source for very obscure bugs. John Roth From logiplexsoftware at earthlink.net Tue Oct 9 14:55:48 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 9 Oct 2001 11:55:48 -0700 Subject: TROJAN ALERT! (JS/Loop) In-Reply-To: <3bc343a0.fba6e0c5.c0a801.00.R@drsolomon.com> References: <3bc343a0.fba6e0c5.c0a801.00.R@drsolomon.com> Message-ID: <01100911554802.02876@logiplex1.logiplex.net> On Tuesday 09 October 2001 11:36, Dr Solomon's Virus Patrol wrote: > WARNING! A trojan has been found in an article posted to > >Subject: YOU ARE ALL GAY! Well, I suppose if we're all gay, it would be good to have a Trojan (tm). -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From ssartor at bellatlantic.net Wed Oct 3 13:39:51 2001 From: ssartor at bellatlantic.net (Steven Sartorius) Date: Wed, 03 Oct 2001 17:39:51 GMT Subject: Possible to read/write Excel files in Python? Message-ID: I'm running 2.1.1 on an i386 NetBSD box and the application I'm working on needs to grab some data from an Excel spreadsheet. I've found a couple of apps (xlHTML for example) that will take a spreadsheet and turn it into html/text and I've seen an article on IBM's web site talking about how to read/write Excel with perl. Is there anything out there that will let me manipulate spreadsheets directly from Python? I'm not big on perl and I'd hate to have to do Excel->perl->python! Any help much appreciated... Steve Sartorius From ykingma at accessforall.nl Tue Oct 9 15:34:05 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Tue, 09 Oct 2001 20:34:05 +0100 Subject: simple threading References: <3BC32938.3080902@herts.ac.uk> Message-ID: <3BC35124.8687DC2C@accessforall.nl> Mark, > > I am trying run a particularly processor hungry function in a > seperate thread but I can't quite figure out how to return > the arguments from the object now. > > previously the function call was coded as: > > motifs = motifFinder.findOtherOccurances(posList, doubles) > > the new code is: > > motifs = thread.start_new_thread(motifFinder.findOtherOccurances,\ > (posList, doubles)) > > The function seems to run fine, but it always returns None, > can anyone tell me what I am doing wrong? thread.start_new_thread() returns immediately, without waiting for the thread to finish. You'll have to decide what to do with the motifs at the point where the function returns. In case you want to wait idle for the result there is no point in using threads. In case you want to do sth else while the thread is running and then wait for it's result have a look at the threading module. Eg. you can pass the result via another object and synchronize between the two threads using a threading.event in same object: import threading class ResultWaiter: # Warning: untested code. def __init__(self): self.resultReady = threading.event() def setResult(self, result): self.result = result self.resultReady.set() def resultAvailable(self): return self.resultReady.isSet() def waitForResult(self): self.resultReady.wait() return self.result waiter = ResultWaiter() thread.start_new_thread(motifFinder.findOtherOccurances, (posList, doubles), waiter) # The function does waiter.setResult(motifs) instead of returning motifs doSomethingElse() if not waiter.resultAvailable(): doSomethingMore() motifs = waiter.waitForResult() > > TIA > My pleasure, Ype -- email at xs4all.nl From boudewijn at tryllian.com Thu Oct 4 04:11:07 2001 From: boudewijn at tryllian.com (Boudewijn Rempt) Date: Thu, 04 Oct 2001 10:11:07 +0200 Subject: Nicer Tkinter on UNIX? References: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> <86DF15C112AF36D6.332DEDD523A2210C.F8DE5222D8EF2836@lp.airnews.net> Message-ID: <3bbc18a8$0$19394$e4fe514c@newszilla.xs4all.nl> Cameron Laird wrote: > . > PyQt is indeed a good-looking alternative to Tkinter--and > PyQt is (generally) available for Windows. While it could > be constructed for MacOS, at least in principle, I don't > think anyone is particularly close to doing this. > Phil recently pre-released PyQt for Qt 3 (just in time to test everything in my book with it) - and it would be extremely interesting to get that to work with Qt3 for OS X. I'd really like to try it, but I don't have a Mac :-(. Still, I really expect PyQt 3 for OS X to available in the very near future. -- Boudewijn | http://www.valdyas.org From cfelling at iae.nl Tue Oct 16 00:39:12 2001 From: cfelling at iae.nl (Carel Fellinger) Date: 16 Oct 2001 06:39:12 +0200 Subject: FW: [Python-Dev] conditional expressions? References: <9qfu1p$iei$1@newshost.accu.uu.nl> <7xitdg4efs.fsf@ruckus.brouhaha.com> <9qgcvk$91j$1@animus.fel.iae.nl> Message-ID: <9qgdlg$95q$1@animus.fel.iae.nl> Carel Fellinger wrote: ... >> x = if a then b else c > I've only once been exposed to Algol-60, to short to get familiar with > the use of a conditional statement disguised as an if *statement* but conditional *expression* that should read, proving how confusing it is to me:) -- groetjes, carel From dale at riverhall.NOSPAMco.uk Wed Oct 3 10:59:51 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Wed, 03 Oct 2001 15:59:51 +0100 Subject: How to use the callback of COM objects References: <9pf6ph$9dg$1@norfair.nerim.net> Message-ID: "Gillou" wrote: >Hi, > >I've tried this to provide a callback function to a COM object: >============== >import win32com.client >def HandleReadyState(): > # anything you want > return >ox = win32com.client.Dispatch('MSXML.DomDocument') >ox.onreadystatechange = HandleReadyState >============== >And the last line raises this: >============== >Traceback (most recent call last): > File "validation.py", line 7, in ? > ox.onreadystatechange = HandleReadyState > File "C:\Python21\win32com\client\dynamic.py", line 467, in __setattr__ > self._oleobj_.Invoke(self._olerepr_.propMapPut[attr].dispid, 0, >pythoncom.DI >SPATCH_PROPERTYPUT, 0, value) >TypeError: Objects of type 'function' can not be converted to a COM VARIANT >============= > >This works perfectly when the equivalent is programmed in javascript. >"onreadystatechange" is an event that can be handled by a user function. > >Did I miss something ? > >Thanks in advance fo any hint. > >--Gilles > > There is DispatchWithEvents which might be what you're looking for but I've never tried to use it. -- Dale Strickland-Clark Riverhall Systems Ltd From GeorgLohrer at gmx.de Sun Oct 14 06:57:27 2001 From: GeorgLohrer at gmx.de (Georg Lohrer) Date: Sun, 14 Oct 2001 12:57:27 +0200 Subject: How to handle sys.path in bigger projects? References: <226dstkol613p95ampm7libas5tp6t0a3b@4ax.com> <56jdstkoro0ddkq3eead1fuoe3m20ilikf@4ax.com> <3BC8A7F5.C2617A7@accessforall.nl> Message-ID: On Sat, 13 Oct 2001 21:45:52 +0100, Ype Kingma wrote: [snipped] >> Ok. Let's have a look on it: >> >> 1) actual dir contains directory: "myproject" with its __init__.py >> importing myproject.foo1 and myproject.foo2 > >What is the point of these imports in an __init__.py file? Only for example. Could be omitted. [snipped] >> ~user/myproject/foo1> python >> >>> import foo1foo >> *** ImportError: No module named myproject.foo2 > >I suppose foo1foo.py contains sth like > >from myproject.foo2 import whatever Exactly. [Good advice snipped] It's strange, but I really was not in trouble with all this stuff until I'll tried to invoke 'deeper' modules from their directory level. After sleeping an additional night about my subject, I recognized that I've done something substantial wrong, belonging to the "art" of Python'ing. I'll correct this in the next release. My organizational structure of the project was based essentially on my strong C/C++ background and thererfore some mistakes had taken place. Ciao, Georg From thomas.heller at ion-tof.com Fri Oct 26 02:39:34 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Fri, 26 Oct 2001 08:39:34 +0200 Subject: HELP -- py2exe failed to build app that uses scipy.plt References: <436bca17.0110181944.247f4ecd@posting.google.com> <16f9b1ea.0110250718.7ccc7fe9@posting.google.com> <9r9j6h$sak0p$1@ID-59885.news.dfncis.de> Message-ID: <9rb0f7$shl3b$1@ID-59885.news.dfncis.de> "eric jones" wrote in message news:pX3C7.535$ai7.37456 at typhoon.austin.rr.com... > > > An additional problem (I've looked into it) leading to the > > syntax error Phil gets is that scipy contains files with > > very strange line separators '\r\r\n' IIRC. > > That doesn't sound good. I'd like everything to use Unix file format. > We'll work on rooting this out. If anyone has a tool to run on the tree to > correct the problem, I'd be much obliged. > > eric I've seen this problem before, maybe someone imported files with dos-style line endings into CVS from a unix system? I don't use unix/linux myself very much, but have you tried dos2unix or how it's exactly called? Thomas From thomas.heller at ion-tof.com Tue Oct 2 08:53:40 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Tue, 2 Oct 2001 14:53:40 +0200 Subject: "cgipython" or equivalent for Python 2.1.1, NT (IIS4)? References: <9pcbqm$r5v$1@serv1.iunet.it> Message-ID: <9pcdck$hagnu$1@ID-59885.news.dfncis.de> "Alex Martelli" wrote in message news:9pcbqm$r5v$1 at serv1.iunet.it... [cgi-python is still 1.5.2] > To summarize, I can upload anything I need to, and run executables > in my cgi-bin (via cgi:-) with "nobody"'s privileges, but that's > about it -- no shell, nothing. Oh, I _was_ almost forgetting -- > the ISP also has installed a Jet DB engine (often misnamed 'Access'), > only available via ADO (intended for use from VBScript ASP's, no > doubt), so if I could also get a COM client working under these > conditions it would *really* be cool...:-). > > Thanks in advance for any pointers and advice! I've once built with Gordon's installer a single file python interpreter (needing only a few dlls and pyds), see http://starship.python.net/crew/theller/installer. This also is only 1.5.2, but the technique should also work with newer pythons... HTH, Thomas From greg at cosc.canterbury.ac.nz Tue Oct 16 22:05:49 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 17 Oct 2001 15:05:49 +1300 Subject: Curious assignment behaviour References: <3bcc75d8.1903824318@news> Message-ID: <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> "David C. Ullrich" wrote: > > If one argued that > one would have to explain why "Let 42 = x" doesn't fly. Why shouldn't it fly? It's an unconventional way of putting it, but it means the same thing, mathematically speaking. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From rwest at opti.cgi.net Thu Oct 25 17:56:15 2001 From: rwest at opti.cgi.net (Richard West) Date: Thu, 25 Oct 2001 21:56:15 GMT Subject: closing sax Message-ID: I'm using Python 2.1.1's XML support in a long running process and I seem to be getting a memory leak. According to the documentation on xml.sax.xmlreader. IncrementalParser you can call .close() on the object after parsing is done in order to "clean up any resources during parsing". However, when I do that, I get a traceback which I don't understand. import string import xml.sax import StringIO test_xml = string.join([ '', '', 'test', 'password', '', ' 123', ' 456', '', '', ],'\n') test = StringIO.StringIO(test_xml) p = xml.sax.make_parser() p.setContentHandler(xml.sax.handler.ContentHandler()) p.parse(test) p.close() Traceback (most recent call last): File "test4.py", line 22, in ? p.close() File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 98, in close self.feed("", isFinal = 1) File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 92, in feed self._err_handler.fatalError(exc) File "/usr/local/lib/python2.1/xml/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :1:0: no element found -Richard From pinard at iro.umontreal.ca Tue Oct 16 20:29:46 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 16 Oct 2001 20:29:46 -0400 Subject: Pymacs 0.11 Message-ID: Hi! A new release of Pymacs is available as: http://www.iro.umontreal.ca/~pinard/pymacs/pymacs.tar.gz Pymacs allows Emacs users to extend Emacs using Python, where they might have traditionally used Emacs LISP. Pymacs runs on systems having sub-processes. The Emacs LISP interaction parameters, so the interactivity of functions, may now be specified from within the Python side. The example below uses the empty string for an argument-less function, see `README' for details. import pymacs interactions = {} def hello_world(): "`Hello world' from Python." pymacs.lisp.insert("Hello from Python!") interactions[hello_world] = '' It is now possible to import Python modules having a dash in their file name, as this is the most natural way to proceed within an Emacs LISP environment. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From dale at riverhall.NOTHANKS.co.uk Thu Oct 18 08:26:38 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Thu, 18 Oct 2001 13:26:38 +0100 Subject: Conditional Expressions don't solve the problem References: Message-ID: salemail at dial.pipex.com (Kevin D) wrote: >Hi Dale, > >Dale Strickland-Clark wrote in message news:... >> But worst of all is that I can't assign a value and test it at the >> same time. It means I have to add at least an extra line of code and I >> have to retype a variable name. It makes for more verbose code and it >> reduces my productivity. > >Are you sure you need to "assign a value and test it at the same time" >? Yes. > Are you saying that just because that's what you're used to from C ? No >What are the _problems_ you encounter that make you wish for this >feature ? Too many and varied to have any hope of addressing them all with specific inventions. And why bother with other inventions when this small facility would do the job? Also, why should I spend longer investigating a 'pythonic' solution (and some are pretty obscure) when I *know* my 'traditional' construct will do the job nicely and very transparetly to most programmers. > What are the alternative solutions to those problems ? More code. -- Dale Strickland-Clark Riverhall Systems Ltd From madsdyd at challenge.dk Thu Oct 4 12:50:34 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Thu, 4 Oct 2001 18:50:34 +0200 (CEST) Subject: Python embedding & question about autoconf and dynamic linking In-Reply-To: Message-ID: On Wed, 3 Oct 2001, Albert Chin-A-Young wrote: > Xcircuit also embeds Python as an interpreter. It has switched to > autoconf so check it out as well: > http://xcircuit.ece.jhu.edu/ Thanks. It seems to apply some of the same hacks that I eventually discovered. The distutils.sysconfig interface is great - sad that it seems to have arrived only in version 2.0 and forward. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk Faced with the prospect of rereading this book, I would rather have my brains ripped out by a plastic fork - Charles Cooper, ZD net, in review of B at TSOT by Bill Gates. From chris.gonnerman at newcenturycomputers.net Thu Oct 11 00:31:29 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Wed, 10 Oct 2001 23:31:29 -0500 Subject: ANN: Alternative Readline for Windows version 1.5 Message-ID: <009001c1520d$9a198220$0101010a@local> Alternative Readline for Windows has been updated to version 1.5, with additional history management functions provided by Alex Martelli (thanks dude). Get it at: http://newcenturycomputers.net/projects/readline.html Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From ignacio at openservices.net Tue Oct 16 21:42:04 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 16 Oct 2001 21:42:04 -0400 (EDT) Subject: PyArg_Parse vs PyArg_ParseTuple In-Reply-To: Message-ID: On Wed, 17 Oct 2001, David Brady wrote: > Hello, > > I'm new to Python, and I've searched the archives for more info but can't > seem to find the info I need. I am having trouble using PyArg_ParseTuple(). > Here is the python code I'm embedding: > > # TestModule.py > def NumberFunction(x): > return x+1 > > As you see, it's not too complex. :-) This is just a proof of concept I'm > working on to prove it can be done. > > Here is the code I'm trying to embed it in. Note: this is C++, does that > make a difference in this case? > > // TestEmbed.cpp > #include > #include > > void main(void) > { > long val = 7; > PyObject *pmod, *pfunc, *pargs, *pstr; > > PyInitialize(); > printf( "Processing data: %ld\n", val ); > > pmod = PyImport_ImportModule( "TestModule" ); > pfunc = PyObject_GetAttrString( pmod, "NumberFunction" ); > > pargs = Py_BuildValue( "(l)", val ); > pstr = PyEval_CallObject( pfunc, pargs ); > > // *** This code works *** > PyArg_Parse( pstr, "l", &val ); > > // *** This code does NOT work *** > //PyArg_ParseTuple( pstr, "l", &val ); > > printf( "Val returned was %d\n", val ); > } > > > If I use the ParseTuple version, the code appears to run fine, but val is > unchanged. I've tried using "(l)" as the string but I'm grasping at straws > here. > > I read in the documentatian that PyArg_Parse() is deprecated, so I would > like to get this working correctly. You're misunderstanding what PyArg_Parse() and PyArg_ParseTuple() are used for. They are used for when a C function is called by a Python program, not the other way around. In your case you should probably be using one of the PyInt_As*() or PyLong_As*() functions. Also, a C signed long on a 32-bit machine translates into a Python Integer, so you can just as easily use "(i)" in Py_BuildValue(). -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From aahz at panix.com Tue Oct 9 22:59:56 2001 From: aahz at panix.com (Aahz Maruch) Date: 9 Oct 2001 19:59:56 -0700 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> Message-ID: <9q0djc$2fd$1@panix2.panix.com> In article , Alan Miller wrote: >Aahz Maruch (aahz at panix.com) wrote: >>Laura Creighton wrote: >>> >>>I know of 2 companies that considered doing their development work in >>>Python but concluded that though the core language was terrific, the >>>libraries were fragmentary, incomplete, and not up to the vigorous >>>standards they had come to expect from other languages such as C++. >> >> Stock C++ has better libraries than Python? > >In some ways it might for commercial development, though perhaps not off >the shelf. The standard libraries in Python are good, but quite a bit >of functionality is added through libraries that are GPL'd. Sure it's >possible to get in touch with the authors of various packages and >negotiate your own licenses with them, but the combination of that _and_ >a new programming language might well be enough to scare off companies. As someone else mentioned in this thread, it's quite likely that creating Python bindings for those C++ libraries will save more time over the long haul. -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista We must not let the evil of a few trample the freedoms of the many. From dietmar at nospam.wohnheim.fh-wedel.de Wed Oct 3 20:33:21 2001 From: dietmar at nospam.wohnheim.fh-wedel.de (Dietmar Lang) Date: 4 Oct 2001 00:33:21 GMT Subject: A little amusing Python program References: <3bbaf6c9$0$244$edfadb0f@dspool01.news.tele.dk> Message-ID: Hi! > I have written this little Python program that usually raises a few > eyebrows. It answer multiple choice questions. Sounds like something for (tada sound) "Useless Python": http://www.lowerstandard.com/python Kudos, Dietmar -- I haven't lost my mind -- it's backed up on tape somewhere. From malcolm at commsecure.com.au Fri Oct 12 08:49:40 2001 From: malcolm at commsecure.com.au (Malcolm Tredinnick) Date: Fri, 12 Oct 2001 20:49:40 +0800 Subject: global variables In-Reply-To: <9q6njs$17s4$1@f1node01.rhrz.uni-bonn.de>; from bjoern4562000@yahoo.de on Fri, Oct 12, 2001 at 02:25:36PM +0200 References: <9q6njs$17s4$1@f1node01.rhrz.uni-bonn.de> Message-ID: <20011012204940.A23180@Vetinari.home> On Fri, Oct 12, 2001 at 02:25:36PM +0200, Bj?rn Buth wrote: > Hi there, > > I?m experiencing a little problem due to my > poor understanding of the way python handles > global variables. Basically the problem is the following > I have a programm with several variables which > I would like to access globaly. > > -- > > var=0 > def example_function() > var=var+1 > (function definition) > print example_function(10) > > will give an error: UnboundLocalError: local variable 'steine' referenced > before assignment. You need to tell the example_function code that var is global before you assign to it. So it's definition will look something like def example_function() global var var = var + 1 ... Cheers, Malcolm -- The hardness of butter is directly proportional to the softness of the bread. From johnroth at ameritech.net Wed Oct 10 18:07:27 2001 From: johnroth at ameritech.net (John Roth) Date: Wed, 10 Oct 2001 15:07:27 -0700 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <7x4rp8q1cy.fsf@ruckus.brouhaha.com> <9q20bh$mjs$1@slb3.atl.mindspring.net> Message-ID: "Andrew Dalke" wrote in message news:9q20bh$mjs$1 at slb3.atl.mindspring.net... > Michael Abbott wrote: > >More to the point, I don't see any room for any > >bugs at all here (let alone obscure ones), since the offending syntax is > >caught by the "compiler". > > Suppose there's an attribute named 'j'. Under current Python > > >>> 3.j > 3j > >>> 3. j > File "", line 1 > 3. j > ^ > SyntaxError: invalid syntax > >>> I posted before I saw Tim Peters' comments in another branch of this thread. It turns out that "3.j" generates a syntax error, as does "3. j" However, "3 .j" and "3 . j" both generate an attribute error, because the object '3' does not have an attribute 'j'. Tim has already said that this is not going to change, and I really don't see any overwhelming need for it to change. I still consider it a wart, but its a wart that is inherited from a long line of predecessors, going back at least to Pascal. I suppose it's a special case of the "maximum munch" rule, and needs to be taught to students. I presume (although I haven't tested it) that "3(x, y, z)" produces a "not callable object" error, and "3[x]" produces a "not subscriptable" error as well. I really can't see what calling '3' would do, but subscripting '3' might be a neat way of getting the bit representation. John Roth From chris.gonnerman at newcenturycomputers.net Sun Oct 28 01:36:27 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sun, 28 Oct 2001 00:36:27 -0500 Subject: binary search trees using classes References: <20011028051357.77421.qmail@web21108.mail.yahoo.com> Message-ID: <001601c15f72$839e88c0$0101010a@local> I have an implementation of a Red-Black Balanced Binary Tree at http://newcenturycomputers.net/projects/rbtree.html Hope this helps. ----- Original Message ----- From: "christy johnson" > Hi, > I was wondering if anyone had a binary search tree > module I could use? I need to write a program that > counts the number of occurrences of each word in a > file, and outputs the word and corresponding counts > alphabetically. For example, if input is > > Have a nice day. Have a nice day. > Have a nice day. > Have a nice day. > > the output is > > a 4 > day 4 > have 4 > nice 4 > > The code has to be modular based on classes. I'm > thinking of making a > tree node that looks like this > > bintree[ [key, data], left, right] , > > where I can traverse the tree by simply incrementing > the current root > to the appropriate child. > > temp = bintree.root > temp = temp[1] #move to the left child. > temp = temp[2] #move to the right child. > > but I don't know how to implement it correctly using > classes. (i.e > using def __init__(self), etc) > > I'm new to this python language so I would appreciate > anyone's help. > > Thanks in advance :) > Christy > > > > __________________________________________________ > Do You Yahoo!? > Make a great connection at Yahoo! Personals. > http://personals.yahoo.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > From claird at starbase.neosoft.com Tue Oct 23 14:54:39 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 23 Oct 2001 13:54:39 -0500 Subject: Python for ipaq References: <9r3ldh$1qsi$1@mail1.wg.waii.com> Message-ID: <94E0418A33323537.DB0449A1FCD57D52.0922A3A307BFC909@lp.airnews.net> In article <9r3ldh$1qsi$1 at mail1.wg.waii.com>, Martin Franklin wrote: >Karol Makowski wrote: > >> On 23 Oct 2001 10:50:46 GMT, Karol Makowski wrote: >>> On Tue, 23 Oct 2001 06:47:52 -0400, Steve Holden wrote: >>>> Sample FTP code in ftpStream.py at >>> thanks, i'll check it. >> >> it's not suitable for my needs, sorry. >> I need an ftp client which will dynamicaly get filename/folder >> from a commandline. >> On that crappy ipaq there is no any smb/nfs protocol and i've got some >> app which need to send and recive some files to work correctly, so i >> thought i'll get some simple ftp client in python, cause python it's >> avaiable for ipaq. ftp client should be run from command line like this: >> ftp.py -g somefile (download file from server) >> ftp.py -s somefile (send some file to server) >> >> It's all i need, server, username/pass is defined in program, >> while filename and/or path should be a variable. >> >> Thanks for help. >> > > > >You could role your own like this:- . [nice example] . . Mr. Makowski's *real* target (and then you want to *embed* the Python code in a C application?) remains obscure to me. I'll guess, though, that it already exists somewhere in . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From thomas.heller at ion-tof.com Thu Oct 18 07:13:04 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 18 Oct 2001 13:13:04 +0200 Subject: Function arguments References: <9qm3sb$pc43f$1@ID-59885.news.dfncis.de> Message-ID: <9qmdg1$o90at$1@ID-59885.news.dfncis.de> "Laura Creighton" wrote... > class Field(Tkinter.Label): > def __init__(self, parent, **kw): > # these are the defaults that you will get if you haven't specified > defaults={'borderwidth': 1, > 'relief' : 'groove', > 'width' : 30, > 'height' : 2, > 'anchor' : 'w', > 'text' : 'SPAM SPAM SPAM SPAM', > } > > # overwrite any of the defaults with the dictionary you passed > defaults.update(kw) > > Tkinter.Label.__init__(self, parent, **defaults) What if your 'Field' would accept a named parameter (maybe 'spam=None'), which would not be required/accepted by 'Label'? You have to manually remove it from kw, assuming the signature of the __init__ method would be __init__(self, *args, **kw). Thomas From china at foo.com Wed Oct 3 19:07:22 2001 From: china at foo.com (Albert Chin-A-Young) Date: Wed, 03 Oct 2001 23:07:22 -0000 Subject: Python embedding & question about autoconf and dynamic linking References: Message-ID: Mads Bondo Dydensborg wrote: > On 1 Oct 2001, Titus Brown wrote: >> >I will continue to hack on the KDE_CHECK_PYTHON script - what are you >> >using for PyWX? >> >> *blush* Nothing. "Hey, does it compile? Great! Oops. Missing symbols? >> Post to the list." > Well, Gerhard H?ring pointed out the distutils.sysconfig.get_config_vars > function for me, which appears to solve most problems, at least for > version 1.5.2 and forward. (Have not checked older versions). > Together with the stuff I found in KDE_CHECK_PYTHON and the stuff from > pygtk, I _think_ I may be able to hack together some autoconf stuff to > resolve this for any version of Python, that is never than or 1.5.2 (Which > is the version with RedHat 7.0 for what it is worth - not that I care so > much about distributions, but that should mean that it is quite > widespread. Xcircuit also embeds Python as an interpreter. It has switched to autoconf so check it out as well: http://xcircuit.ece.jhu.edu/ -- albert chin (china at thewrittenword dot com) From sholden at holdenweb.com Wed Oct 3 07:46:00 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 3 Oct 2001 07:46:00 -0400 Subject: Python is better than free (was Re: GNU wars again) References: <200110030312.f933COK01047@smtp2.idir.net> Message-ID: Could we perhaps set followups to comp.useless.philosophical.discussions at this point? I'm sure we all agree that anyone is free to release *their* software (as opposed to somebody else's) under any licensing form they want. Given *that* basic freedom, the rest is just opinion. and-opinions-can-be-whatever-you-want-ly y'rs - steve -- http://www.holdenweb.com/ "Oleg Broytmann" wrote in message news:mailman.1002084903.15223.python-list at python.org... > On Tue, Oct 02, 2001 at 10:14:58PM -0500, Chris Watson wrote: > > On Tuesday 02 October 2001 09:54 pm, Delaney, Timothy wrote: > > > > From: Chris Watson [mailto:opsys at voodooland.net] > > > However, GPL is *not* extortion. The writer of a piece of code has every > > > right to want to protect, control or charge for it. > > > > That's true. But dont call it Free code if you do. Because it is not free. > > Look up free in the dictionary. That is the ONLY definition that should be > > followed. Not whatever twisted version the FSF and GNU people want to use. > > The gernal gist of any dictionary is its free if its free from control, > > opression, or restrictions. > > I disagree. Some restrictions must be imposed. I don't want your fist to > fly freely into my nose; that why I want to impose restrictions. Absolute > freedom is impossible in this not-so-ideal world. I don't want arrognt and > greedy Big Power Companies freely take the ball and run with it. GNU GPL > looks very good balanced for me. > > Oleg. > ---- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. > From pipi10 at wp.pl Thu Oct 11 17:54:01 2001 From: pipi10 at wp.pl (Hallo) Date: Thu, 11 Oct 2001 23:54:01 +0200 Subject: what Message-ID: <9q54d0$6j2$1@news.tpi.pl> what I need to use smalest of python. no library no other only pure interpreter? is less than 1Mb static program in linux? -- mi?e ?ycie, ale czasu ma?o From burner at core.binghamton.edu Sun Oct 28 01:34:21 2001 From: burner at core.binghamton.edu (Michael R. Head) Date: Sun, 28 Oct 2001 01:34:21 -0500 Subject: binary search trees using classes In-Reply-To: ; from python-list-request@python.org on Sun, Oct 28, 2001 at 01:16:00AM -0400 References: Message-ID: <20011028013421.B2647@warp.core.binghamton.edu> A quick google search ( "binary search" site:python.org ) turns up this reference (among many others): http://mail.python.org/pipermail/python-list/2001-February/030678.html mike > From: christy johnson > Subject: binary search trees using classes > > Hi, > I was wondering if anyone had a binary search tree > module I could use? I need to write a program that > counts the number of occurrences of each word in a > file, and outputs the word and corresponding counts > alphabetically. For example, if input is > > Have a nice day. Have a nice day. > Have a nice day. > Have a nice day. > > the output is > > a 4 > day 4 > have 4 > nice 4 > > The code has to be modular based on classes. I'm > thinking of making a > tree node that looks like this > > bintree[ [key, data], left, right] , > > where I can traverse the tree by simply incrementing > the current root > to the appropriate child. > > temp = bintree.root > temp = temp[1] #move to the left child. > temp = temp[2] #move to the right child. > > but I don't know how to implement it correctly using > classes. (i.e > using def __init__(self), etc) > > I'm new to this python language so I would appreciate > anyone's help. > > Thanks in advance :) > Christy > > > > __________________________________________________ > Do You Yahoo!? > Make a great connection at Yahoo! Personals. > http://personals.yahoo.com > > > Content-Description: Digest Footer > -- > http://mail.python.org/mailman/listinfo/python-list -- Michael R. Head burner at core.binghamton.edu GPG public key: http://www.core.binghamton.edu/~burner/gpg.key.txt -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 536 bytes Desc: not available URL: From emile at fenx.com Thu Oct 18 08:25:28 2001 From: emile at fenx.com (Emile van Sebille) Date: Thu, 18 Oct 2001 05:25:28 -0700 Subject: Function arguments References: <9qm3sb$pc43f$1@ID-59885.news.dfncis.de> Message-ID: <9qmi0b$oab8c$1@ID-11957.news.dfncis.de> "Thomas Heller" wrote in message news:9qm3sb$pc43f$1 at ID-59885.news.dfncis.de... > Call me weird, but sometimes I need functions taking a number of > positional arguments, some named arguments with default values, and > other named arguments as well. > > Something like this (which does _not_ work): > > def function(*args, defarg1=None, defarg2=0, **kw): > ... > > The usual way to program this is: > [snip keyword arg breakout code] > Doesn't look very pretty IMO, and using the dictionaries' > get method doesn't help. Why not? Because it doesn't delete the key from the dict? > > I was thinking of a popitem() dictionary method taking > (optionally) 2 arguments: the name of the item to pop, > and the default value to return if the item is not present > in the dictionary: > > >>> d = {'a': 2, 'b': 3} > >>> d.popitem('defarg', 0) > 0 > >>> d > {'a': 2, 'b': 3} > >>> d.popitem('a', 100) > 2 > >>> d > {'b': 3} > >>> > > Opinions? > > Thomas You can write this now: def popitem(dict, *args): if not args: return dict.popitem()[1] ky = args[0] val = dict.get(ky, args[1]) try: del d[ky] except: pass return val def func(*args, **kw): defarg1 = popitem(kw, 'defarg1', None) defarg2 = popitem(kw, 'defarg2', 0) As to adding this as a method of dictionary, in 2.2 you can do this as well: _popitem = popitem class KW(dictionary): def __init__(self, **kwargs): self.update(kwargs) def popitem(self, *args): return _popitem(self, *args) def func(*args, **kw): kw = KW(**kw) defarg1 = kw.popitem('defarg1', None) defarg2 = kw.popitem('defarg2', 0) Although I don't see a way to do: dictionary = KW d = {1:1,2:2} print d.popitem(3,3) Now getting _this_ could be fun! ( and probably dangerous too ;-) -- Emile van Sebille emile at fenx.com --------- From aleax at aleax.it Mon Oct 15 02:15:29 2001 From: aleax at aleax.it (Alex Martelli) Date: Mon, 15 Oct 2001 08:15:29 +0200 Subject: "cgipython" or equivalent for Python 2.1.1, NT (IIS4)? In-Reply-To: <3BCA5EFC.D5C74A63@ActiveState.com> References: <9pcbqm$r5v$1@serv1.iunet.it> <3BCA5EFC.D5C74A63@ActiveState.com> Message-ID: <0110150815290D.17630@arthur> On Monday 15 October 2001 05:58, David Ascher wrote: > Alex Martelli wrote: > > I've purchased an unlimited-space, unlimited-traffic, just-about-no- > > visible-support ISP account (came cheap in a bundle with ADSL to my > > home and a .it domain). They "support" (...well... let's say, they > > *have installed*:-) ASP (meaning, I'm sure, VBScript and JScript), PHP, > > and CGI via Perl -- period. No chance to get them to install anything > > else for me, of course -- when one buys a year's worth of unlimited > > web serving for less than the price of a decent dinner, one can't > > expect to get even a few minutes' worth of individualized support:-). > > They seem to be running Microsoft IIS 4.0 on SMP NT4 boxes, with the > > latest SP's and security hotfixes (no codered vulnerability, wow:-). > > You might be able to get them to run python as an ASP active scripting > host... Technically, that would no doubt be the best-case for me. But maybe I haven't made the situation clear...: These guys are selling me a domain name, unlimited space and traffic, 5 mailboxes, ASP, PHP4, CGI, &c, all for 40,000 Italian liras PER YEAR -- 20 Euros, less than US$20 (last time I posted I got a flurry of questions in email, so, to forestall a repetition: they're www.aruba.it). They sell a lot of other connectivity services, so maybe the dirt-cheap, no-service thingy is meant as a "loss leader", but they've sold tens of thousands of those so they'd better not lose too much per account:-). Their stated policy is therefore (quite reasonably given the scenario) to spend _zero_ time on any support task except fixing security issues on system software. In particular, they don't install any extra software (customers are welcome to install it themselves in private accounts, though). They hosts "forums" (sort of newsgroups) where customers can help each other, and the PHP'ists are forever bemoaning the lack of MySQL (the Jet engine, aka "Access DB", is all the SQL they support -- PHP &c can get at it via COM+ADO, but it's not what PHP people normally do) -- I wouldn't be surprised if they had a thousand customers pining for MySQL, versus maybe a couple of hundreds pining for Python. Yet they aren't installing MySQL -- not for the accounts that cost less than US$20 per year -- nor Python nor anything else. Even to get _statistics_ for your site is an extra US$10 per year... Alex From cliechti at gmx.net Fri Oct 26 17:11:21 2001 From: cliechti at gmx.net (Chris Liechti) Date: 26 Oct 2001 23:11:21 +0200 Subject: tutorial References: <9rb6pi$nva$1@penthesilea.materna.de> Message-ID: Gerhard H?ring wrote in news:mailman.1004096908.29383.python-list at python.org: >> (If you even know one tutorial in german...........I would spread my >> kisses allovertheworld *G*) > > You mean like this one? > Das Python-Tutorium: > http://starship.python.net/crew/gherman/publications/tut-de/online/t > ut/ > > (German translation of the Python tutorial by Dinu Gherman). > or that? http://www.inf-gr.htw-zittau.de/~wagenkn/TI/Paradigmen/python1/node1.html -- Chris From mlh at idi.ntnu.no Thu Oct 4 18:03:00 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 5 Oct 2001 00:03:00 +0200 Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> Message-ID: <9pimak$c22$1@tyfon.itea.ntnu.no> "Joshua Macy" wrote in message news:3BBABE1C.5010108 at sneakemail.com... > > > Joshua Macy wrote: > > > > Even though I've released some of my Python work under the GPL, I'm > > coming around to Tim Peter's way of thinking: just release things into > > the public domain and have done with it. > > > > D'oh! Apostrophe error. Tim Peters' way of thinking. Well, actually, according to The Elements of Style by Strunk & White, it should be Tim Peters's way of thinking ("Peters'" is a plural possessive, I think :) > Joshua -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From rparnes at megalink.net Tue Oct 2 09:36:07 2001 From: rparnes at megalink.net (Bob Parnes) Date: Tue, 2 Oct 2001 08:36:07 -0500 Subject: list.append problem? References: Message-ID: Steve Holden wrote: > "newgene" wrote in message > news:a50631f6.0110011345.31523630 at posting.google.com... >> I am a newer of python. I have a problem like this code: >> >> >>> a=b=c=[] >> >>> a.append(1) >> >>> b.append(2) >> >>> c.append(3) >> >>> a >> [1, 2, 3] >> >>> b >> [1, 2, 3] >> >>> c >> [1, 2, 3] >> >> a,b,c become the same, although append method applied seperately. >> It's really strange and unreasonable. >> My python is ActivePython Build 210 running on WinNT. >> > Strange and unreasonable as it may seem, it's classic Python. All three > variables are bound to the same object, so when you change the object (no > matter which name you use) the value you see when you access any of the > names is the same. > > However, try >>>> a = [] >>>> b = [] >>>> c = [] >>>> a.append(1) >>>> b.append(2) >>>> c.append(3) > > and you will see what you feel is more reasonable behavior: in this case > each variable is bound to a different list, and so changing one of the > lists doesn't affect the values bound to the other variables. > > You get used to it after a while, and after your third progam it will seem > the most reasonable thing to do! > > regards > Steve > -- > http://www.holdenweb.com/ > > > > > > As another newcomer I discovered this on my own. What is confusing, I think, is that it seems to apply only to empty objects. For example >>> a = b = [1, 2. 3] >>> a = [4, 5, 6] >>> b [1, 2, 3] >>> a.append(7) >>> a [4, 5, 6, 7] >>> b [1, 2, 3] In this case a and b are not bound to the same object. It seems to me that python treats empty objects differently from assigned objects. Or something like that, I'm probably not articulating it well. -- Bob Parnes rparnes at megalink.net From kriol at boopsie.fnal.gov Thu Oct 11 15:32:28 2001 From: kriol at boopsie.fnal.gov (Oleg Krivosheev) Date: 11 Oct 2001 14:32:28 -0500 Subject: Why so few Python jobs? References: <9oltnk$vv3$1@nntp9.atl.mindspring.net> Message-ID: Andrei Kulakov writes: > On Fri, 28 Sep 2001 01:45:04 GMT, Warren Postma wrote: > >> Any ideas on why so few Python jobs are available? > > > > In my job, I use Python, but it is because I know Python and felt it was > > the best tool for the job. But seldom is it the "defining" characteristic > > of a position. In particular, my job calls for C/C++ skills. I have ported > > python to embedded system platforms we use, and so my job is more entitled > > "Embedded C/C++ Developer" than "Python Developer". > > > > In other words, many more people use Python than it would seem from their > > Job Descriptions. Also, few jobs would exist that would require you to > > know ONLY python, and not also require C/C++. Python may be great, but > > remember, it's written in C. That makes C great by certain logical > > principles. An effect can not be greater than its cause, something like > > that. > > So, War&Peace is no greater than children's ABC book? :P you meant War&World ? > > > > > Warren > > > > > > > From fredrik at pythonware.com Wed Oct 31 14:49:28 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Oct 2001 19:49:28 GMT Subject: Why 'self' ? References: <3BE04E7A.8E2CF101@ces.clemson.edu> <9rpd0t$1ba2$1@nntp6.u.washington.edu> Message-ID: in a post that didn't reach my server, "Schaefer, F." wrote: > >It's been a while that I am working with Python and actually >the only thing I really do not like about it is 'self' in the >member function definitions as argument. If it >has to be there anyway, it is totally redundant to write it. > >So, why is self there ? did you check the FAQ? http://www.python.org/doc/FAQ.html#6.7 From slinkp23 at yahoo.com Fri Oct 5 00:56:40 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Fri, 05 Oct 2001 04:56:40 GMT Subject: Zope vs PHP for the Linux guru References: Message-ID: On Fri, 5 Oct 2001 09:03:40 +1000, Richard Jones wrote: >On Friday 05 October 2001 08:24, Cameron Laird wrote: >> Zope development is breathtakingly swift--in the hands >> of an expert. As wonderful as Zope is, though, it's >> hard to make a case that it's easy to learn. It's pro- >> bably the case that it lacks just the right bit of >> documentation, or examples, or something; in any case, >> newcomers consistently report rather extended intervals >> before they "get" the Zope way of working. > >The new Zope Book (freely downloadable) is a really good effort to remedy >this. ... although (probably due to timing) it doesn't cover Page Templates which are very, very cool - probably much better in the long run than Zope's other (older) template language, DTML, and with important advantages over just about every other dynamic web system out there. There's a good introduction to ZPT linked from the front page of zope.org this week: http://www.zope.org/Documentation/Articles/ZPT3 IMHO, a lot of the difficulty of grokking Zope is understanding what the different parts of Zope are and how they relate to each other. 1) the through-the-web management interface, the ZMI. 2) the filesystem-like view that ZMI provides of objects in the Zope database, the ZODB. 3) calling object methods by URL 4) page templating languages, DTML and ZPT. In practice, you'll need to know a little python here too. 5) Acquisition, the process by which objects in the ZODB can search in their parent Folders for other objects. 6) the security system 7) extensions written in python, which live on the filesystem, either as small External Methods or as possibly quite large Products. 8) extensions written as ZClasses 9) the ZCatalog ... for starters. :) All of these things play their part in zope, and you will need at the very least a working understanding of 1 - 6; anything non-trivial will require Products or ZClasses too. And any site that needs searching will need ZCatalog. >> It does NOT support "Web server farming" of the sort >> I suspect you have in mind, though. There's no parti- >> cular reason it doesn't (and maybe someone's fixed >> this recently); it's just that no one's gone to the >> trouble of making it a reality. > >I'm not sure of the specifics, but doesn't ZEO handle this? This might make interesting reading: http://www.zope.org/About --Paul Winkler From cliechti at gmx.net Wed Oct 31 17:16:42 2001 From: cliechti at gmx.net (Chris Liechti) Date: 1 Nov 2001 00:16:42 +0200 Subject: PythonWin 2.1 saving bugg??? References: Message-ID: "Tim Gahnstr?m /Bladerman" wrote in news:QTYD7.3703$Z_1.643403 at newsc.telia.net: > "Chris Liechti" skrev i meddelandet >> i had some troubles with non-english characters like "umlaut"/???. at >> least in older vestions of pythonwin deleting such a character did't >> deleted the character attribute. in this state pythonwin refused to >> save the file until i deleted that character too. >> >> these problems _are_ fixed in PyWin 2.1 but maybe there is still a >> small bug left. > > The name of the file was interp.py and I had saved it a gzillion times > before so I dont think hta was teh problem. the problem were characters in the editor window, filename is irrelevant. maybe you have pasted some code from the webrowser or an other program in your source and that bit of code included such a character that pythonwin doesn't like. but as your code is away, anyway it doesn't matters now... but i had that problem several times and lost some code too (with older pywin releases). chris > > Tim > -- Chris From andres at corrada.com Mon Oct 15 09:02:32 2001 From: andres at corrada.com (andres) Date: Mon, 15 Oct 2001 13:02:32 GMT Subject: Regex problem In-Reply-To: <9qelne$jcg$1@green.tninet.se> References: <9qelne$jcg$1@green.tninet.se> Message-ID: <20011015130232.5028.qmail@mail.sitepassport.net> Hi Gustaf, Matches use the beginning of the line. Use "re.search" to search the whole string. Alternatively, you could put "\s*" at the beginning of your match string. Gustaf Liljegren writes: > I'm having a problem with a regex. I'm trying to match or > elements containing the 'href' attribute. Here's the regex: > >>>> import re >>>> re_link = re.compile(r'<(a|area)\s+[^>]*href[^>]*/?>', re.I | re.M) > > It works fine when I try it on these two strings: > >>>> s1 = '' >>>> re.match(re_link, s1).group() > '' > >>>> s2 = '' >>>> re.match(re_link, s2).group() > '' > > But look what happens as soon as I add a space (or any other character) > before: > >>>> s3 = ' ' >>>> re.match(re_link, s3).group() > Traceback (most recent call last): > File "", line 1, in ? > re.match(re_link, s3).group() > AttributeError: 'None' object has no attribute 'group' >>>> > > What's wrong here? Matches shouldn't have to start from the beginning of a > string. > > Gustaf Liljegreb > > > -- > http://mail.python.org/mailman/listinfo/python-list From tatebll at aol.com Mon Oct 22 21:28:17 2001 From: tatebll at aol.com (Bill Tate) Date: 22 Oct 2001 18:28:17 -0700 Subject: J2EE equivalent in Python References: Message-ID: Robin Smith wrote in message news:... > I like J2EE but I am also an open source fan. I don't like what I read > about Sun and restricting Java - > http://www.onjava.com/pub/a/onjava/2001/10/10/osjava.html . > > Is there anything similar to J2EE for python? > > Robin Robin, At best its J2EE light. However, I would definitely keep an eye on Skunkweb and STML. Reasons: 1. Skunkweb forks processes rather than using threads (app servers tend to be I/O bound not cpu bound as many have noted previously) - see Sam Rushing's site on this topic - he's got some great references there. 2. Since forked processes means the Python interpreter can take advantage of multiple processors where a threaded model means being able to only take advantage of a single processor no matter what. 3. The STML implementation is by far sight a superior alternative to DTML and it is extensible. I know the Zope folks are working on alternatives but it takes some real effort to figure out what's going on. STML is also logical and much more straight foward to understand. 4 With Skunkweb you have access to Python - Zope presently doesn't get high marks on that score - again they are addressing that I'm to understand - and updating python code without shutting down the server is is facilitated by its use of PAR files (akin to JAR files). 5. I like Webware - a lot - but it is multithreaded which gives me pause to think scalability could be issue and I'm not to keen on PSP. Since one of the reasons J2EE is pushed is the ability to handle huge transaction volumes, scalability is clearly an unavoidable core issue wrt alternatives. That's before you even get around to discussing entity/session/messaging beans. From mwh at python.net Thu Oct 18 04:58:56 2001 From: mwh at python.net (Michael Hudson) Date: Thu, 18 Oct 2001 08:58:56 GMT Subject: Conditional Expressions don't solve the problem References: Message-ID: James_Althoff at i2.com writes: > Fredrik Lundh wrote: > >and the "while 1" pydiom usually doesn't look that way. > > >write pydiomatic Python code instead doing things the C/Java > > > "Pydiom" & "pydiomatic"? Pretty cool. Is this new? A little light googling reveals it being used (by /F) in '98. So, no, not really, though Frederik seems to be the only person to use the word regularly. Cheers, M. -- That one is easily explained away as massively intricate conspiracy, though. -- Chris Klein, alt.sysadmin.recovery From kromag at nsacom.net Mon Oct 1 00:10:22 2001 From: kromag at nsacom.net (Kromag) Date: 30 Sep 2001 21:10:22 -0700 Subject: bsddb - mystery wrapped in enigma Message-ID: <23fa17e9.0109302010.57591efc@posting.google.com> I have been scouring the earth for a good tutorial on the bsddb module. Is there anything (in print or otherwise) lurking about that might help? I am trying to extract information from an existing berkeley db file (sleepycat). Thanks! d From logiplexsoftware at earthlink.net Tue Oct 9 13:55:04 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 9 Oct 2001 10:55:04 -0700 Subject: simple threading In-Reply-To: <3BC32938.3080902@herts.ac.uk> References: <3BC32938.3080902@herts.ac.uk> Message-ID: <01100910550401.02876@logiplex1.logiplex.net> On Tuesday 09 October 2001 09:43, Mark Robinson wrote: > I am trying run a particularly processor hungry function in a > seperate thread but I can't quite figure out how to return > the arguments from the object now. Probably what you want to do is have the thread set the value of a variable and then signal the main program that it has finished via an Event() (try the threading module rather than the thread module). -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From markus at schabi.de Mon Oct 1 17:49:23 2001 From: markus at schabi.de (Markus Schaber) Date: Mon, 1 Oct 2001 23:49:23 +0200 Subject: sameness/identity References: Message-ID: <12374228.0c2gjJ1VT2@lunix.schabi.de> Hi, Xavier Defrang schrub: >> Just to confuse you some more: >> >> >>> a = 3 >> >>> b = 3 >> >>> a is b >> 1 >> >>> a = 10000 >> >>> b = 10000 >> >>> a is b >> 0 > > Damn, this is weird. :) > After reading that, I wrote a small script : [snip] > That '100' definetly looks like some hardcoded limit, has anybody a > clear > explanation for this? Why the interpreter behaves differently for > numbers > lower than 100 and the others? I guess it's for optimization purpose > since most algorithms deal with small numerical values but I'd be > really happy if I knew what's really going on in here... Yes, that's correct, and documented. The interpreter optimizes using a cache for the numbers -100 to 100. This is configurable and can be switched off. Also, e. G. identical strings and symbols in a module are shared. As both are immutable, this shouldn't matter in most cases. But you have to be careful when using object identity on Strings. markus -- "The strength of the Constitution lies entirely in the determination of each citizen to defend it. Only if every single citizen feels duty bound to do his share in this defense are the constitutional rights secure." -- Albert Einstein From heeroygw at aol.comnojunk Wed Oct 24 19:46:36 2001 From: heeroygw at aol.comnojunk (Django) Date: 24 Oct 2001 23:46:36 GMT Subject: Need help with programming. Message-ID: <20011024194636.07978.00000094@mb-mb.aol.com> Hello. I've just begun using Python, and am now getting into simple commands. Everytime I try to use "else:" I get this message: SyntaxError: invalid syntax >>> I've tried retyping it, skipping it, etc. but it's really bothering me... is there an alternative I can use for "else:" such as "or:"... Or am I typing it wrong, or something? I tried browsing a few webpage's a bit, to hopefully find an answer to my question, but I didnt find anything to help me out. Any help would be very much appreciated. Thank you. May I remind you that I AM NEW TO PYTHON, and COMPUTER LANGUAGES ALL TOGETHER (Excluding HTML). I'M LEARNING PYTHON FOR SELF INTEREST, SO PLEASE NO FLAMES.. From skip at pobox.com Fri Oct 19 23:53:45 2001 From: skip at pobox.com (Skip Montanaro) Date: Fri, 19 Oct 2001 22:53:45 -0500 Subject: struct module In-Reply-To: <3bd0f13e$0$27332$afc38c87@news.optusnet.com.au> References: <3bd0f13e$0$27332$afc38c87@news.optusnet.com.au> Message-ID: <15312.62793.163733.53091@beluga.mojam.com> >> Can someone tell me what I'm missing here? >>>> struct.calcsize('H') >> 2 >>>> struct.calcsize('B') >> 1 >>>> struct.calcsize('HB') >> 3 >> wait for it... >>>> struct.calcsize('BH') >> 4 H has a two-byte alignment requirement. There's one byte for the "B", then it has to throw in a pad byte to get the correct word alignment for the "H". -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From madsdyd at challenge.dk Mon Oct 1 08:06:05 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 14:06:05 +0200 (CEST) Subject: Python embedding & question about autoconf and dynamic linking In-Reply-To: Message-ID: On Mon, 1 Oct 2001, Olivier Deme wrote: > Yes, I found that web site last week. > The reason for us to do embedding rather than extending is that our main > applciation is written in C (would you write a router in Python?...) No I wouldn't. I am writing a game. I suppose it _could_ be written in Python, but none of the engine developers really know Python - it just seemed like a nice language to extend our game with, for controlling scriptable stuff and such. (The alternatives beeing tcl, guile or perl). Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk UNIX always presumes you know what you're doing. You're the human being, after all, and it is a mere operating system. From brian_zhou at NOSPAMtechie.com Thu Oct 4 23:31:15 2001 From: brian_zhou at NOSPAMtechie.com (Brian Zhou) Date: Thu, 4 Oct 2001 20:31:15 -0700 Subject: SWIG question References: <1002241259.529836@cswreg.cos.agilent.com> Message-ID: <1002252649.181779@cswreg.cos.agilent.com> I figured it out myself, need to write a typemap myself. -Brian "Brian Zhou" wrote in message news:1002241259.529836 at cswreg.cos.agilent.com... > I want to use SWIG to wrap a C routine that accepting a python string: > > >>> c_routine("abc") > > and in the c_routine(), I need to get the string pointer and length, > probably using > > char *ptr, int size; > PyArg_Parse(str, "s#", &ptr, &size); > > I tried: > > int routine(PyObject *s) { > char *ptr, int size; > PyArg_Parse(str, "s#", &ptr, &size); > // ... > } > > it compiled ok, but when called, > > >>> from testmodule import * > >>> p = routine("abc") > Traceback (innermost last): > File "", line 1, in ? > File "queue_module.py", line 35, in routine > val = queue_modulec.routine(arg0) > TypeError: Type error in argument 1 of routine. Expected _PyObject_p. > >>> > > How should I write the correct C routine? > > Thanks for any suggestions. > > -Brian > > From jmsun at bioeng.ucsd.edu Fri Oct 5 13:42:33 2001 From: jmsun at bioeng.ucsd.edu (Jeffrey) Date: 5 Oct 2001 10:42:33 -0700 Subject: Tkinter and HTML Message-ID: <3daa1aa8.0110050942.2b16ed90@posting.google.com> Is there anyway to open a HTML on a Tkinter Canvas or any other widget. The problem is that I have a piece of text that has subscripts and symbols. It's basically a html file and I just want to display it. One solution I already thought of is to create a .gif file and just display it as a gif but I was wondering if anything else was out there.... Thanks Jeff From objectway at divalsim.it Tue Oct 9 07:15:59 2001 From: objectway at divalsim.it (Nicola Musatti) Date: Tue, 09 Oct 2001 13:15:59 +0200 Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> Message-ID: <3BC2DC6F.FAAF1D2D@divalsim.it> Oleg Broytmann wrote: > > On Tue, Oct 02, 2001 at 01:01:11PM -0700, Samuel Schulenburg wrote: > > Sometimes you have code that you want to release with a commercial > > product, that contains propriatary information about the internals in > > your product. A GPL license would keep you from releasing this code > > using Python. > > This is easily solvable: buy specially licensed version. GNU GPL allows > it. But do not take my code for nothing, please. I may be wrong, but I don't think that the original intent behind CopyLeft and then GPL was to obtain retribution. Rather, it was meant to prevent the offspring of "proprietarized" GNU software, obtained by making small, proprietary changes to freely available software. In other words, it's the "embrace and innovate" kind of policy they were setup against. Cheers, Nicola Musatti From DeepBlue at DeepBlue.org Thu Oct 11 09:36:51 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Thu, 11 Oct 2001 08:36:51 -0500 Subject: Holden's Python Web Programming Book Message-ID: This is a question for Steve Holden: Steve, Is there a way to view the table of contents of your upcoming book? I want to compare this book with Mitchell's book "Python for the Web." Thanks, DB From thomas.heller at ion-tof.com Thu Oct 25 10:01:51 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 25 Oct 2001 16:01:51 +0200 Subject: Solaris core dump with McMillan Installer References: Message-ID: <9r960f$s8h9i$1@ID-59885.news.dfncis.de> So does anyone know what the worst case alignment rule is for > structs? > > - Gordon Isn't this specified in the C-standard ? (That's what I heard, not that I would have one...) Thomas From lucio at movilogic.com Thu Oct 25 14:55:36 2001 From: lucio at movilogic.com (Lucio Torre) Date: Thu, 25 Oct 2001 15:55:36 -0300 Subject: Question: CPython References: <3BD79BBC.B2FA669B@hotmail.com> Message-ID: <3BD86028.9040802@movilogic.com> scott wrote: > >Sean 'Shaleh' Perry wrote: > >>On 24-Oct-2001 K?roly Ladv?nszky wrote: >> >>>What is CPython and where is it available? >>> >>>Thanks for any help, >>> > > > >>There is >>a new thing called 'JPython' which is a python implementation in Java >> > > >Called 'Jython' now. Its predecessor was JPython. >http://www.jython.org > And python is now called Cython. :) From chatme at 263.net Sun Oct 14 23:24:17 2001 From: chatme at 263.net (limodou) Date: 14 Oct 2001 20:24:17 -0700 Subject: It's a BUG? urllib2 & proxy Message-ID: I want to grab a web page through a firewall. So I used urllib2.py module to do this. And the firewall needs a authentication. The code is: ---------------------------------------- import urllib2 proxy=urllib2.ProxyHandler({'http':'http://user:passwd at 11.11.11.11:8080'}) opener=urllib2.build_opener(proxy) urllib2.install_opener(opener) f = urllib2.urlopen('http://www.python.org/') open('out.htm', 'w').write(f.read()) ---------------------------------------- But the code failed. Finally I find that in the source of urllib2.py, there are some codes: for klass in default_classes: opener.add_handler(klass()) for h in handlers: if type(h) == types.ClassType: h = h() opener.add_handler(h) I thought it is the key. So I move the first two lines backword, like this: # for klass in default_classes: # opener.add_handler(klass()) for h in handlers: if type(h) == types.ClassType: h = h() opener.add_handler(h) for klass in default_classes: opener.add_handler(klass()) It works. From wheelege at tsn.cc Sun Oct 21 03:13:04 2001 From: wheelege at tsn.cc (Glen Wheeler) Date: Sun, 21 Oct 2001 17:13:04 +1000 Subject: Array of 2^n References: <9qtd1t$mds$2@news-int.gatech.edu> Message-ID: <011801c159ff$e7023a60$3ba616ca@ACE> > Okay, python newbie here. I'm liking what I see, but it seems like there > are holes in the features of python's objects. I remember programming in > squeak (an extension of smalltalk), and you could do complex operations on > lists, and it would apply the result to each item. I want to make a n-item > list such that mylist[i] = 2**i. How can I generate such a list in Python? There are two standard ways... >>> i = 10 >>> l = map(lambda x:2**x, range(i)) >>> l [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] And... >>> l = [] >>> for j in range(i): ... l.append(2**j) ... >>> l [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] HTH, Glen From greg at cosc.canterbury.ac.nz Tue Oct 30 22:52:17 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 31 Oct 2001 16:52:17 +1300 Subject: Unpacking extension (Re: A small inconsistency in syntax?) References: <6qelnludt5.fsf@abnoba.intevation.de> Message-ID: <3BDF7571.5D8CB310@cosc.canterbury.ac.nz> Bernhard Herzog wrote: > > p = Pair(17, 42) > a, b = p > > The only thing it doesn't do is checking whether p is an instance of > Pair as your proposal would but that's better done with a separate test, > anyway, IMO. This is actually part of a larger idea I've been thinking about for a while, and that's to give Python some of the flavour of the pattern-matching case statements found in functional languages, so you can write things like case foo: Nothing(): print "We got nada" Pair(Furble(p, q), Furble(r, s)): print "We got a pair of furbles" Pair(a, b): print "We got a pair of something else" x: print "We got something else" Of course, you could always write out the tests using if-elif-else. But note the distinction between the second and third cases, which would be somewhat tedious to write out that way. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From ignacio at openservices.net Fri Oct 5 14:46:50 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 5 Oct 2001 14:46:50 -0400 (EDT) Subject: Variables name in Byte code In-Reply-To: <68599ccc.0110051038.25ba4b82@posting.google.com> Message-ID: On 5 Oct 2001, Kaci Tizi Ouzou wrote: > Greetings all, > > I was examining python compiled code and surprisingly I could see > clearly the names of some variables. > > Is there anything I could do to make Python Byte code more obscur. > I do not want user trying to hack the code(!) > > Thanks Well, you could encrypt the code object for the file then encapsulate it in a program to decrypt it and run it with eval(). -- Ignacio Vazquez-Abrams From db3l at fitlinxx.com Thu Oct 11 17:14:39 2001 From: db3l at fitlinxx.com (David Bolen) Date: 11 Oct 2001 17:14:39 -0400 Subject: how do I add site-packages on Windows? References: <3bc57f3b$0$233$edfadb0f@dspool01.news.tele.dk> Message-ID: "Max M" writes: > I have had this problem before, but never really got a working solution. > > If I put packages into: > > \Lib\site-packages\ > > And then I try to use it from ie. iis (Windows naturally) Python cannot find > my packages. > > What would I need to do to make Python search in site-package automatically? Since the automatic site path setup is only currently done for Unix, my approach was just to put a site.pth file into the root of the Python installation directory and include whatever site directory I wanted. In my case, I just made a "site" directory right off of the Python installation root, and thus the contents of site.pth was just "site". -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From GregHolmes at aol.com Fri Oct 19 15:14:06 2001 From: GregHolmes at aol.com (GregHolmes at aol.com) Date: Fri, 19 Oct 2001 15:14:06 EDT Subject: win32popenWin9x.exe and w9xpopen.exe on win95 Message-ID: <21.12d17c66.2901d57e@aol.com> When I try to use win32pipe.popen() with Python 2.1 on Win95, it works, but the floppy drive grinds! What on earth is happening there? os.popen doesn't work at all; I've tried setting PYTHONHOME, copying w9xpopen.exe all over the place, etc., but I still get the error: PythonHandler mod_python.publisher: RuntimeError: Can not locate 'w9xpopen.exe' which is needed for popen to work on this platform. Anyone experienced either of these? Is there a solution? From phd at phd.pp.ru Wed Oct 31 11:28:35 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 31 Oct 2001 19:28:35 +0300 Subject: Freeware Python editor In-Reply-To: <3BE0240A.A2CCAA83@alcyone.com>; from max@alcyone.com on Wed, Oct 31, 2001 at 08:17:14AM -0800 References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <9rp4d8$830$1@tyfon.itea.ntnu.no> <3BE0240A.A2CCAA83@alcyone.com> Message-ID: <20011031192835.M21151@phd.pp.ru> On Wed, Oct 31, 2001 at 08:17:14AM -0800, Erik Max Francis wrote: > > And, BTW, "free to use" is not free in the sense I prefer. I'd > > better > > read free code. And free code is the code I can read, modify and > > distribute. I hope I do not start yet another GNU flame war. :) > > "Freeware" has a well-defined meaning that predates open source > initiatives. The sense it was used in this case was correct, so > complaints about _free_ not being defined the way _you_ prefer it are > irrelevant. It was not a complain. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From James_Althoff at i2.com Mon Oct 15 13:30:35 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Mon, 15 Oct 2001 10:30:35 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) Message-ID: Paul Rubin wrote: >"Tim Peters" writes: >> Everything's cool if parens are required around a conditional expression, >> though, in which case: >> >> x = if e1 then e2 else e3 + 1 # SyntaxError >> x = (if e1 then e2 else e3) + 1 # cool >> x = (if e1 then e2 else e3 + 1) # cool >> x = if e1 then e2 else e3 # SyntaxError >> x = (if e1 then e2 else e3) # cool >> x = if if e1 then e2 else e3 then e4 else e5 # SyntaxError >> x = (if (if e1 then e2 else e3) then e4 else e5) # cool >> >> Seems a mixed bag, but I'm more interested in readability and the >> functionality than in minimizing keystrokes; requiring parens doesn't hurt >> the goals I care about. > >It's more readable with the parentheses anyway. I agree. Jim From adina_levin at mindspring.com Mon Oct 15 22:14:57 2001 From: adina_levin at mindspring.com (adina_levin at mindspring.com) Date: Mon, 15 Oct 2001 21:14:57 -0500 Subject: newbie printing question References: Message-ID: <9qg64n$luv$1@slb2.atl.mindspring.net> In other words, timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) >>> timestring '2001-10-15 21:11:09' which is the date format that mySQL wants. Thank you, thank you. "Ignacio Vazquez-Abrams" wrote in message news:mailman.1003196354.25037.python-list at python.org... > On Mon, 15 Oct 2001 adina_levin at mindspring.com wrote: > > > I'd like to create a string with the current date and time. I've got the > > mxDateTime library, so far so good. > > > > print mxDateTime.now() will generate the date and time to the screen. write > > will send it to a file. > > > > But how can I assign this to a string? > > > > I will be most thankful and embarrassed to hear the answer to this question. > > It oughta be obvious! > > Use time.localtime() along with time.strftime(). > > -- > Ignacio Vazquez-Abrams > > "As far as I can tell / It doesn't matter who you are / > If you can believe there's something worth fighting for." > - "Parade", Garbage > > From george at station-7.com Sat Oct 13 18:08:36 2001 From: george at station-7.com (Legeza George J.) Date: Sat, 13 Oct 2001 18:08:36 -0400 Subject: Python and XML? Message-ID: <9qaduv$c3p$1@nntp9.atl.mindspring.net> Hi all, I'm pretty new to Python and I hadn't intended to use it for much (other than as something to add to my resume), but recently a project's come up that I think it would be good for. Unfortunetly, there are going to be other components of this project that will be reading output in XML format. So here's my question - does Python have any built in support for XML? Or is there some extension of the language that provides support for XML? If so, where can I find more information? Thanks, -- George Legeza Obnoxious minor diety and owner of Simple Paradox Designs [simparadox.com] "i love a language where things are to to do stuff with, challenging" - Special Ed Ned "cuz is war kid!" - Special Ed Ned From manobes at fraser.sfu.ca Wed Oct 24 19:53:24 2001 From: manobes at fraser.sfu.ca (Matthew Nobes) Date: Wed, 24 Oct 2001 16:53:24 -0700 Subject: help with something that ought to be simple Message-ID: Hello all, I am trying to do something that ought to be very simple, yet for some reason isn't. What I want to do it the following. Take a list of lists, in the following form [[0,0,0,0],[1,0,0,0],...,] and preform some operations on it. So I wrote a litte script to do this, here's the first bit def del_2(rho,input,output): output=[[0,0,0,0]] for i in input: i[rho-1]=1 output.append(i) so far so good. This takes the input and appends it, slightly modified to the output. Now here comes the problem. I want to add some more stuff to the output. Here's what I try to do: temp=[] for i in output[2:]: temp.append(i) for i in temp: i[rho-1]=i[rho-1]-1 for i temp: output.append(i) return output I define temp precisly so that I don't mess with output. What I want to do is do some stuff to temp, then append that onto the output from before. BUT*** everything I do to temp also get's done to output. This ends up makeing the earlier stuff get mucked up a concrete example: I input rho=2 and input=[[0,0,0,0],[1,0,0,0]] after the first step output is [[0,0,0,0],[0,1,0,0],[1,1,0,0]] This is what I want. Now I call that temp, and take the last entry and make it [1,0,0,0]. Now I did this to temp. So I should be able to now append this to output and my result *SHOULD* be [[0,0,0,0],[0,1,0,0],[1,1,0,0],[1,0,0,0]] but instead the operation on temp also gets preformed on output and I get [[0,0,0,0],[0,1,0,0],[1,0,0,0],[1,0,0,0]] So my question is how do I stop this from happening? I must be something extremely simple, so sorry in advance for asking something silly... -- ``We may feel that at last, unlike all previous generations, we have found certitude. They thought so too'' -Robert Conquest Matthew Nobes, c/o Physics Dept. Simon Fraser University, 8888 University Drive Burnaby, B.C., Canada, http://www.sfu.ca/~manobes From nomad*** at ***freemail.absa.co.za Fri Oct 26 06:21:13 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Fri, 26 Oct 2001 12:21:13 +0200 Subject: Curl-ing, anyone? References: <458b194a.0110241156.795e9618@posting.google.com> <458b194a.0110250700.4f71b05d@posting.google.com> Message-ID: On 25 Oct 2001 08:00:50 -0700, rcena at epcor.ca (Resty Cena) wrote: >"Jeff Hinrichs" wrote in message news:... >> I don't think so, what about it makes you consider the possibility? >> > >Just that I find the language cool (though I'm disappointed with the >lack of facility for incrementally re-defining classes, or at least I >haven't found a way to do it), and the IDE even cooler. I always have >a soft spot for things well done. I haven't looked at curl at all, but from what I hear it's probably already lost - there are too many other web-based scripting languages out there that it is unlikely to catch on - especially being proprietary. Another note about your reply though - the IDE _is not_ the language. If you like the way the IDE works, why not implement those features in your own IDE? I just checked out wxDesigner - looks pretty nice, but it's too expensive for my pocket. On the free side there is always BOA Constructer which, although still very young and in beta, is fairly nice to work with. -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From skip at pobox.com Wed Oct 31 10:23:51 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 31 Oct 2001 09:23:51 -0600 Subject: External python file problem In-Reply-To: References: Message-ID: <15328.6023.4685.657316@beluga.mojam.com> Thomas> i want a python program to load another .py file and execute a Thomas> function in this other file. i compile the other file using the Thomas> compile function,but how to get the function i want from the Thomas> resulting code object ? You're being much too hard on yourself. Simply import the other module and call the function. Suppose your python program is in A.py and the other .py file is B.py. Simply execute import B B.func(...) in A at the appropriate point. If you don't know the name of the module and function until runtime, use the __import__ builtin function: modname = raw_input("Enter module name: ") newmod = __import__(modname, globals(), {}, []) funcname = raw_input("Enter function name: ") newfunc = getattr(newmod, funcname) newfunc(...) -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From chris.gonnerman at newcenturycomputers.net Sat Oct 6 18:13:49 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sat, 6 Oct 2001 17:13:49 -0500 Subject: Oh No! Octonians in Python! References: <7x3d4wpqi0.fsf@ruckus.brouhaha.com> Message-ID: <008d01c14eb4$31903a20$0101010a@local> It appears that the PSU is currently doing battle with the Octonians and their Quaternion allies near From zhao_zi_long at 163.net Thu Oct 25 20:40:15 2001 From: zhao_zi_long at 163.net (jilly) Date: 25 Oct 2001 17:40:15 -0700 Subject: python as a cgi script engine References: <1004026229.8757.0.nnrp-13.d4f0f8ae@news.demon.co.uk> Message-ID: "Mike Peat" wrote in message news:<1004026229.8757.0.nnrp-13.d4f0f8ae at news.demon.co.uk>... > Damn! ;-) > > Sorry Jilly, but what did you do to get it to work? I was lurking here > waiting to see what answer you got. I can get cgi stuff to work with Apache > (on various Linuxs), but on my own W2K (& IIS 5.0) laptop it is a no-go. > > Mike > > "jilly" wrote in message > news:f828f146.0110250656.2da737f8 at posting.google.com... > > "DeepBlue" wrote in message > news:... > > > When you say it failed: What error are you getting? > > > DB > > > > > > "jilly" wrote in message > > > news:f828f146.0110240116.27caedca at posting.google.com... > > > > i use "http://localhost/CGI/python.exe?hello.py" ,then i succeed. > > > > but when i use "http://localhost/CGI/hello.py" ,i failed. > > > > and i have setted scriptmap in the IIS > > > > (just like:".py-->c:\python21\python.exe -u"). > > > > > > > > The context is: > > > > windows 2000 and IIS server > > > > > > > > Please help me > > > > Thanks first! > > > > I have got it work fine! > > Thank you again! Mike : I have posted the answer to you by email. I wish it will help you! :) (And i have made a mistake that i posted two emails.) jilly From kaci_tizi_ouzou2000 at yahoo.ca Fri Oct 5 14:38:10 2001 From: kaci_tizi_ouzou2000 at yahoo.ca (Kaci Tizi Ouzou) Date: 5 Oct 2001 11:38:10 -0700 Subject: Variables name in Byte code Message-ID: <68599ccc.0110051038.25ba4b82@posting.google.com> Greetings all, I was examining python compiled code and surprisingly I could see clearly the names of some variables. Is there anything I could do to make Python Byte code more obscur. I do not want user trying to hack the code(!) Thanks From tim.one at home.com Tue Oct 23 01:10:31 2001 From: tim.one at home.com (Tim Peters) Date: Tue, 23 Oct 2001 01:10:31 -0400 Subject: Dictionary from list? In-Reply-To: <9r1iag$sln$1@nntp9.atl.mindspring.net> Message-ID: [Andrew Dalke] > Oh, don't get me wrong. I'm one of those anchors trying to slow > the development of new core features in Python. (New libraries > is a different thing.) If dictionary(list) stays an error you > won't hear any complaints about me. I appreciate that. However, the builtin dictionary() cow has already escaped the 2.2 barn, so the question now is whether we let it roam the Python pasture with two broken legs, or put a spiffy sequence saddle on it so you can gallop on it in comfort into the mooooonlight. > But I'm also one of those people who likes details -- (forest? > tree? I like the BARK! :) grow-up-it's-a-cow-not-a-dog-ly y'rs - tim From rnd at onego.ru Mon Oct 29 23:23:34 2001 From: rnd at onego.ru (Roman Suzi) Date: Tue, 30 Oct 2001 07:23:34 +0300 (MSK) Subject: A small inconsistency in syntax? In-Reply-To: Message-ID: On Thu, 25 Oct 2001, Michael Abbott wrote: >It seems to me that there's a little inconsistency in assigning to tuples: > > >>> (x,) = () > Traceback (most recent call last): > File "", line 1, in ? > ValueError: unpack tuple of wrong size > >Yes, that's what I expect. > > >>> () = () > SyntaxError: can't assign to () > >Eh? Why not? It's just a matter of checking that the right hand side >really is an empty tuple... Well, maybe one day Python will allow: = () as well ;-) () on the LHS is a target list constructor and assignment really needs targets there. Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/ _/ Tuesday, October 30, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "Tax rich bachelors heavily. Why should they be so happy?" _/ From michael at rcp.co.uk Thu Oct 25 09:39:01 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Thu, 25 Oct 2001 13:39:01 +0000 (UTC) Subject: Conditional expressions (again) References: Message-ID: "Steve Holden" wrote in news:CpSB7.27304$Nx2.513851 at atlpnn01.usenetserver.com: > What we are currently missing is *agreement* - both on whether it's > really useful and, more especially, on what the syntax should be. Sorry to keep banging on about this one. Well, I don't really think there's a great deal of argument about the syntax. There are, as far as I'm aware, two live proposals for syntax: (1) x = if a: b elif c: d else: e or (2) x = if a then b elif c then d else e I seem to recall that Guido stated that he'd had a go at implementing syntax 2 (which I prefer if we're willing to pay the price of a new keyword 'then'), and that it worked well enough with the Python syntax. The main argument, really, seems to be about whether this is useful. If we agreed on this then sorting out the syntax would be easy: go for (2) and choose a sensible precendence (in particular, is if 1 then 0 else 1,2 a number or a tuple? I'm easy either way...) From vulpine at dontspam.earthling.net Thu Oct 18 02:48:03 2001 From: vulpine at dontspam.earthling.net (Kit O'Connell) Date: Thu, 18 Oct 2001 06:48:03 GMT Subject: Further help w/ readline needed (was:Re: Past command buffer gone in interpreter?) In-Reply-To: References: Message-ID: On 16 Oct 2001, Timothy Grant wrote: > Having recently been through this, you may want to try replacing the > -ltermcap with -lncurses and see if that resolves your problem. It did > for me. gcc -Xlinker -export-dynamic -o python \ Modules/python.o \ libpython2.1.a -lpthread -ldl -lutil -lreadline -lncurses -lm /usr/bin/ld: cannot find -lncurses collect2: ld returned 1 exit status ncurses is present in: /usr/lib/libncurses.so.5 /usr/lib/libncurses.so.5.2 Is it possible that for some reason make can't find ncurses (and termcap, et al)? Is there a way I can force it to look there? I tried the -L flag (added '-L/usr/lib/' after -lncurses) but it didn't seem to have any effect; maybe I'm not using it right. Thanks, Kit From aleax at aleax.it Sat Oct 13 04:59:38 2001 From: aleax at aleax.it (Alex Martelli) Date: Sat, 13 Oct 2001 10:59:38 +0200 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xhet6ot4j.fsf@ruckus.brouhaha.com> <9q5370$3re$1@lancelot.camelot> Message-ID: <9q8vpq$hbh$1@lancelot.camelot> Huaiyu Zhu wrote: >>while data.set(file.readline()) != 'end': >> process(data.get()) > > Alex, what's your opinion comparing these to the following? > > while line = file.xreadlines(); line != 'end': > etcetc(line) > > I'm pushing for this because it is not just syntactic suguar. It gives Your approach is indeed far more general -- I just showed somewhat-clunky syntax that has the advantage of working right now (and ever since the Dawn of Python) when one is transliterating code from other languages (I wouldn't use it in code meant to be idiomatically Pythonic, or Pythonically idiomatic). However, the ability to have arbitrary statements as part of an "expression" may be TOO general for comfort -- right now I can rely on the fact that an expression can never rebind my local variables (and this for example makes eval usable where exec might not be), the generalization would take such guarantees away. A much more wary look at the trade-offs is therefore surely warranted. Alex From seb at tesco.net Mon Oct 29 19:08:05 2001 From: seb at tesco.net (seb) Date: Tue, 30 Oct 2001 00:08:05 GMT Subject: how does latebinding (com) work ? References: <9rjk39$82jpo$3@hades.rz.uni-sb.de> Message-ID: <3bdde9d7.4766113@news.tesco.net> On 29 Oct 2001 13:03:37 GMT, Uwe Schmitt wrote: >Hi, > >can anybody explain, how late-binding of methods of com-objects work >internally ? What happens if I try to access a method that's not >implemented at this point of time ? Normally one should get an >error message.... > >Greetings, Uwe. > >-- >Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes >phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 > D-66041 Saarbr?cken >http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 > As i understand it not really since it's up to the caller. To use late binding you call IDispatch::GetIDsOfNames and if this doesn't resolve then there isn't anything to use. GetIDsOfNames should return DISP_E_UNKNOWNNAME if one or more are unknown and DISPID_UNKNOWN will be placed in the entry(ies) for which the dispatch id is unknown, any other entries should be fine. This makes it very much runtime which is a python-ly thing i suspect. Platform SDK:Automation on the M$ developer's site should find it. I've used it and it seems to work, can throw some code at you if you wish. seb. (programmer previously known as dawks) -- sigless. From serge at rohan.sdsu.edu Wed Oct 10 16:44:07 2001 From: serge at rohan.sdsu.edu (Serge Rey) Date: Thu, 11 Oct 2001 06:44:07 +1000 Subject: Newbie: tkinter question In-Reply-To: <118EE09ECEDF14F8.218265D3FDE5A761.875E2BB02943F76C@lp.airnews.net>; from claird@starbase.neosoft.com on Wed, Oct 10, 2001 at 07:49:23AM -0500 References: <118EE09ECEDF14F8.218265D3FDE5A761.875E2BB02943F76C@lp.airnews.net> Message-ID: <20011011064407.E736@typhoon.sdsu.edu> On Wed, Oct 10, 2001 at 07:49:23AM -0500, Cameron Laird wrote: > In article , > Attila Pletyak wrote: > >Hello, > > > > I am using Debian Linux 2.2, I've installed python from the deb > >packages. I would like to try out the possibilites of tkinter, but the > >module tkinter seems to be missing from my computer. Python is 1.5.2, > >and when I start it and type "from Tkinter import * " it says that it > >cannot find tkinter. > > > > I looked on the tkinter home page, it routes me to > >dev.scriptics.com, but there I cannot really find tkinter. > . > . > . > In the absence of explanation from a Debian expert--and > I do recognize there are a several nearby--my usual ad- > vice is to download Python 2.2 and re-build your own > installation. Are you comfortable with such a generation? > It's quite straightforward. for debian you need to install the package python-tk in addition to python-base if you want tk: http://packages.debian.org/stable/interpreters/python-tk.html the rebuild route that cameron suggests also will work fine under debian potato (aka 2.2). HTH -- Sergio J. Rey http://typhoon.sdsu.edu/rey.html GPG fingerprint = 16DB 4934 E0F1 B386 AE81 D379 914C 33E5 F690 95DF "No, Hardy! No, Hardy! It is a very interesting number. It is the smallest number expressible as the sum of two cubes in two different ways." - Ramanujan on the number 1729 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 240 bytes Desc: not available URL: From tjreedy at home.com Thu Oct 25 20:56:35 2001 From: tjreedy at home.com (Terry Reedy) Date: Fri, 26 Oct 2001 00:56:35 GMT Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> Message-ID: <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> "Michael Abbott" wrote in message news:Xns9145D94516673michaelrcpcouk at 62.253.162.104... > However, Python tuple assignment does look somewhat like pattern matching; > for example, sometimes my .read() method returns some (one) thing, and I > write: > > time, status, ((value, boring),) = myobject.read() > > So here I think of this as matching the one value (itself a pair of values) > that happens to be returned. This looks awfully like pattern matching (cf > Haskell). An so it is. If the patterns do not match, an exception is raised. However, after the match, the names (in your example above) 'time', 'status', 'value', and 'boring' are then bound to the corresponding objects in the current namespace. Terry J. Reedy From kkto at csis.hku.hk Wed Oct 10 21:28:15 2001 From: kkto at csis.hku.hk (Isaac To) Date: 11 Oct 2001 09:28:15 +0800 Subject: Newbie: tkinter question References: Message-ID: <7iwv233qz4.fsf@enark.csis.hku.hk> >>>>> "Attila" == Attila Pletyak writes: Attila> Hello, I am using Debian Linux 2.2, I've installed python from Attila> the deb packages. I would like to try out the possibilites of Attila> tkinter, but the module tkinter seems to be missing from my Attila> computer. Python is 1.5.2, and when I start it and type "from Attila> Tkinter import * " it says that it cannot find tkinter. Attila> I looked on the tkinter home page, it routes me to Attila> dev.scriptics.com, but there I cannot really find tkinter. Attila> Can anybody help me out on what should I do? apt-get install python-tk Regards, Isaac. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 240 bytes Desc: not available URL: From dalke at dalkescientific.com Tue Oct 16 13:19:22 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 16 Oct 2001 11:19:22 -0600 Subject: Conditional Expressions don't solve the problem References: Message-ID: <9qhqi1$vba$1@slb3.atl.mindspring.net> Dale Strickland-Clark wrote: >I think this is verbose. I would much prefer be able to write: > >while term := self.nextTerm(): > for a in argObjects: > if handled := a.test(term): > break > if not handled: > raise whatever Wouldn't you prefer (in Python 2.2) for term in iter(self.nextTerm, None): for a in argObjects: if a.test(term): break else: raise whatever Same number of lines. No need for ':='. No ugly flag variables. Very Pythonic. Andrew dalke at dalkescientific.com From Widgeteye at widgets.com Sat Oct 27 16:13:41 2001 From: Widgeteye at widgets.com (Widgeteye) Date: Sat, 27 Oct 2001 20:13:41 -0000 Subject: Tutorial Message-ID: Is there a python tutorial on the net anywhere for the beginner? Thanks WidgetEye -- "You can always make peace with an F-16 in your pocket" -Yitzhak Rabin From jim at interet.com Mon Oct 22 14:18:18 2001 From: jim at interet.com (James C. Ahlstrom) Date: Mon, 22 Oct 2001 14:18:18 -0400 Subject: newsgroup traffic way down? References: <8827e15d.0110170823.672f0a63@posting.google.com> <3BD0692D.BFE42CFA@interet.com> Message-ID: <3BD462EA.7345F531@interet.com> Nomad wrote: > Maybe uunet has a shorter message expiry timeout? Yes, uunet has a very short timeout, and they may be dropping articles. JimA From maxmcorp at worldonline.dk Wed Oct 17 17:16:48 2001 From: maxmcorp at worldonline.dk (maxm) Date: Wed, 17 Oct 2001 23:16:48 +0200 Subject: PythonWin ASP performance References: <7a7a07a.0110170719.7a347008@posting.google.com> Message-ID: "Jim Abrams" Using Python makes life easier in so many ways I can't even begin to > describe them all, but some of the main ones are the object oriented > approach. (We've encapsulated the ASP Built-in objects with Python wrappers > that solve alot of VBscript ickiness, and are subclassable) I have tried Python asp, but found some ick-ines where the indenting messes up the clarity of the asp page. in something like: <%for i in range(10):%> <%= i%>
I have to write: <% for i in range(10): Response.Write('' + i + '
') %> instead. In this simple example it isn't that bad, but when writing longer html, tables etc it sort of defeats the purpose of asp. Suddenly I get logic and presentation forced together. Have you got any good soultions to that? regards Max M From sholden at holdenweb.com Wed Oct 24 20:35:29 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 24 Oct 2001 20:35:29 -0400 Subject: Taking Inputs References: Message-ID: <34JB7.22901$Nx2.395619@atlpnn01.usenetserver.com> "Anita Kommineni" wrote ... > For using input and raw_input do I need to import any specific modules Nope, they are built in: Python 2.1.1 (#2, Sep 26 2001, 09:32:53) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "copyright", "credits" or "license" for more information. >>> a = raw_input("Yes: ") Yes: a >>> a = input("What:") What: 123 >>> Don't you have an interpreter to try it yourself? See www.python.org :-) regards Steve -- http://www.holdenweb.com/ From mlh at idi.ntnu.no Wed Oct 31 10:12:40 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 31 Oct 2001 16:12:40 +0100 Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> Message-ID: <9rp4d8$830$1@tyfon.itea.ntnu.no> "Oleg Broytmann" wrote in message news:mailman.1004537911.24973.python-list at python.org... > On Wed, Oct 31, 2001 at 08:08:22AM -0600, Kemp Randy-W18971 wrote: > > Check out the free Python editor at www.crimsoneditor.com. > > Free (like free beer), but not free (like freedom). No source code, > Windows only. Well, if you're a Windows user you're free to use it. Why complain? > Oleg. -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.sf.net From emile at fenx.com Tue Oct 30 20:07:13 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Oct 2001 17:07:13 -0800 Subject: adding items from a text file to a list References: <48dbc3f6.0110301612.e0f863c@posting.google.com> <9rng2s$va4pr$1@ID-11957.news.dfncis.de> <3ohutt4ed0264imgprah2lblipqljer1pe@4ax.com> Message-ID: <9rnj56$v2d5n$1@ID-11957.news.dfncis.de> "Peter Wang" wrote in message news:3ohutt4ed0264imgprah2lblipqljer1pe at 4ax.com... > split()[0] won't work because some items (like "pickled eggs") have > spaces in them. > I know... it sounded like homework and I wanted to point without giving... -- Emile van Sebille emile at fenx.com --------- From gh_pythonlist at gmx.de Tue Oct 2 23:36:09 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Wed, 3 Oct 2001 05:36:09 +0200 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: ; from tdelaney@avaya.com on Wed, Oct 03, 2001 at 12:54:48PM +1000 References: Message-ID: <20011003053608.A1635@lilith.hqd-internal> On Wed, Oct 03, 2001 at 12:54:48PM +1000, Delaney, Timothy wrote: > My preferences lie very strongly with BSD-style licenses (basically, > do what you want with this). I personally feel that code should be > available to be used in whatever way someone wants. This is not to say > that all code should be without charge - depending on what it is, I > would be quite willing to pay a (one-off) fee to be able to *then* do > whatever I wanted with the code (with some caveats - I would not > expect to be able to distribute code in unmodified form if it required > a fee for me to obtain it in the first place). I agree completely. I can imagine reasons why one would prefer to license something under the GPL, apart from believing into that Free Software stuff: if you want to make money from alternative licensing forms. But *please*, then indicate that you are willing to license the code under a commercial license, and *pleae* be clear what the price of this is. I hate the usual ACT, Cygnus, Transvirtual, whatever statements along the line "We offer alternative licensing forms. Please contact our sales department." Ugh. I won't. > I find the GPL is one of the best ways to ensure that your code will not be > used by other people. Yup. I avoid it almost always. I've never tried to make money off my Open Source code, but I want it to stay free, not "Free". I don't have problems with GPL'ed utilities, but I do have a big problem with GPL'ed libraries. These are very annoying, IMNSHO. If they're actually useful (most of them aren't), sooner or later somebody will rewrite them under a BSD license or just in-house, anyway. So it only leads to duplicated effort. What I hate most is that kneejerk-use-of-GPL I see in all those little Open-Source projects. GPL is the predominant form of licensing in the OS world. Just go to freshmeat.net and have a look at the statistics. I believe most of the authors don't know the implications of using the GPL. If it were something significant like a Python ODBC interface, I'd understand this, but something almost trivial like a Python library that does fast MD5 sums on files, please! (I rewrote that under a BSD license, for example). Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From chrishbarker at home.net Fri Oct 26 12:56:43 2001 From: chrishbarker at home.net (Chris Barker) Date: Fri, 26 Oct 2001 09:56:43 -0700 Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> Message-ID: <3BD995CB.22D3507A@home.net> Terry Reedy wrote: > As I understand it, the rule is this: if item on LHS is tuple rather > than name, then corresponding object on RHS must be a tuple, which > will then be seen as collection rather than object in itself and > consequently unpacked for matching to items within LHS tuple. > Allowing for null matches and applying the rule recursively, Actually either side can be a sequence, not just a tuple: >>> (a,b) = [3,4] >>> a 3 >>> b 4 >>> [a,b] = (3,4) >>> a 3 >>> b 4 >>> (a,b) = "df" >>> a 'd' >>> b 'f' I'm not sure that changes this argument in any way.... -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From dag4004 at carmail.com Sat Oct 6 16:48:47 2001 From: dag4004 at carmail.com (dag4004) Date: Sat, 6 Oct 2001 22:48:47 +0200 Subject: How could i slim Python for embedded ? Message-ID: <3bbf6f3e$0$3649$626a54ce@news.free.fr> Hello, I want to use Python for an embedded computer so don't have some RAM/ROM. I firstly install Python2.0 from Mandrake 8.0 CD and Python was 605.6 ko in size. Today i have download Python2.2a4 sources an compiled it and i get 2Mo !!!!!!! So i didn't undestand ?? What is different ? What must i do to built a small interpretor ? Thanks From sdhyok at email.unc.edu Sat Oct 20 20:37:39 2001 From: sdhyok at email.unc.edu (Daehyok Shin) Date: Sat, 20 Oct 2001 20:37:39 -0400 Subject: [Q] How to get global namespace of __main__? Message-ID: <9qt5cj$bef$1@news2.isis.unc.edu> For a specialized task of my own, I have to get a global namespace of python interactive environment from a function in a module. The following example simplified it. How can I solve the problem? Thanks in advance. Inside python interactive environment: >from mymod import put >x = globals() >put() Inside mymod module: def put(): y = ???? #y should be the same as x. -- Daehyok Shin (Peter) From sholden at holdenweb.com Thu Oct 18 20:33:26 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 18 Oct 2001 20:33:26 -0400 Subject: Is there a small Python runtime environment installer? References: <3583b331.0110181524.5695bd67@posting.google.com> Message-ID: <9uKz7.44320$cb.809545@atlpnn01.usenetserver.com> "Tex Riddell" wrote in message news:3583b331.0110181524.5695bd67 at posting.google.com... > I have some useful scripts that I'd like to share with someone that > doesn't have Python. He doesn't want to install all of Python right > now (like examples, utilities, source, IDE's and tk - yuck), he'd > rather just have an executable or install a simple runtime library and > run my script. > > I only know of two main distributions of python and each are made for > people developing with python. Is there a simple, compact, binary > distribution available anywhere? > > Ideally, I'd like to see a binary shared library, compiled for the > target platform, with a minimum of external dependencies. Hopefully, > with support scripts (for standard features) compiled to byte code and > compressed or at least clumped together in a single file (or a few > files, one for each larger feature area). > > More specifically I'm looking for something for the windows > environment, but one should be able to make something like this > multi-platform, right? > > How can we expect python to become more mainstream if only developers > can understand the environment that must be set up for scripts to run? > > I really don't have time to learn distutils (re-inventing the wheel > that I'm sure so many have done) in order to install a runtime > environment on someone's machine so they can run a simple 8k script. > Probably the closest thing you'll find is PythonWare's distributions: http://www.pythonware.com/products/python/index.htm Probably not what you want, but the closest I know about. regards Steve -- http://www.holdenweb.com/ From nospam at bigfoot.com Tue Oct 16 15:31:11 2001 From: nospam at bigfoot.com (Gillou) Date: Tue, 16 Oct 2001 21:31:11 +0200 Subject: Python COM for Microsoft Project References: Message-ID: <9qi1ik$1fju$1@norfair.nerim.net> Mike, Dunno if it's available for MS Project, but with other MS Office applicaitons (Word...), you can install the full help that provides the application object model and the detailed/commented API for VBScript, sometimes with examples (easy to translate into Python). But this is not a default install option with MS Office since few users write macros with VBScipt editor. Hope I helped --Gillou From mjais at web.de Wed Oct 17 06:57:24 2001 From: mjais at web.de (Markus Jais) Date: Wed, 17 Oct 2001 12:57:24 +0200 Subject: class browser for python ?? Message-ID: hello, is there a tool out there, which can show me the class structure of a python module something like a class browser would be needed or a tool that can generate UML diagramms from python sources any hints are welcome markus From info at devshare.de Thu Oct 25 06:58:37 2001 From: info at devshare.de (Johannes Gamperl) Date: Thu, 25 Oct 2001 12:58:37 +0200 Subject: Learing Python, Newbie question References: Message-ID: In article , michael at rcp.co.uk says... > Johannes Gamperl wrote in > news:MPG.1642065dc9ef9d80989687 at news.t-online.de: > > > Do you know if there is a > > coditional operator in python ( ?: ) > > > > e.g. > > > > if os.path.exists("gbook.txt"): > > db_first = 0; > > else: > > db_first = 1; > > > > > > db_first = ( os.path.exists("gbook.txt") ) ? 0:1; > > Ho ho! > > I'm glad that beginners also miss the conditional operator. > > I'm afraid there's been a bit of an argument about possible syntax, and > most of the old hands seem firmly convinced that the conditional operator > serves no useful purpose. > > No, it doesn't exist! > > > Mind you, in the example you give, there's no point at all in having a > conditional operator, since what you *really* wanted to write is: > > db_first = not os.path.exists("gbook.txt") hello Michael, the e.g. doesn't make sin :) .. but i want to describe for what i'm looking for. i came from perl and i find the conditional operator very usefull .. oki ... my journey to python goes on ;) Hannes From logiplexsoftware at earthlink.net Wed Oct 31 16:17:29 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 31 Oct 2001 13:17:29 -0800 Subject: python development practices? In-Reply-To: <0110311311210A.06896@logiplex1.logiplex.net> References: <0110311311210A.06896@logiplex1.logiplex.net> Message-ID: <0110311317290B.06896@logiplex1.logiplex.net> On Wednesday 31 October 2001 13:11, Cliff Wells wrote: > No problem here, but later, the author of Base decides to add a self._x to > Base. Now Derived is undoubtedly broken and it won't be clear why. A > private variable mechanism that could prevent this scenario would be a > definite benefit. And, no, I'm not fond of the double underscore either. In effect, I want a "double underscore every data attribute in this class" statement, that is to say: private: Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From steffen.ries at sympatico.ca Tue Oct 9 07:38:07 2001 From: steffen.ries at sympatico.ca (Steffen Ries) Date: 09 Oct 2001 07:38:07 -0400 Subject: python -i References: Message-ID: epchaves at yahoo.com.br writes: > Hi: > > My script are: > > __________________ > import string > > a = string.lower("??????AAA") > print a > > ____________________ > > if i do: python -i myfile.py > the output is OK: ??????aaa > > but if i do: python myfile.py > the output isn't the expected: ??????aaa > > Why? You have to call 'locale.setlocale(locale.LC_ALL, "")' to make python work with non-ascii encodings. For some reason it would seem, that this happens automatically when you start python interactively... hth, /steffen -- steffen.ries at sympatico.ca <> Gravity is a myth -- the Earth sucks! From jhg at athensgroup.com Fri Oct 12 12:34:08 2001 From: jhg at athensgroup.com (James Garrison) Date: Fri, 12 Oct 2001 11:34:08 -0500 Subject: Anaconda command line syntax Message-ID: <3BC71B80.7F0EA2DF@athensgroup.com> Can someone please point me to a complete description of the command-line syntax for anaconda, including the syntax used for the -m (--method=) option? I'm trying to run anaconda in test mode in order to capture the install screens for some documentation, and I can never get to the package selection because it complains "An error has occurred while retrieving the hdlist file" ... and then unceremoniously exits. Here's what I've tried so far: anaconda --test -m cdrom://mnt/cdrom anaconda --test -m cdrom://mnt/cdrom/RedHat/base -- James Garrison Athens Group, Inc. mailto:jhg at athensgroup.com 5608 Parkcrest Dr http://www.athensgroup.com Austin, TX 78731 PGP: RSA=0x04B73B7F DH/DSS=0x70738D88 (512) 345-0600 x150 From emile at fenx.com Tue Oct 2 08:43:28 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 2 Oct 2001 05:43:28 -0700 Subject: list.append problem? References: Message-ID: <9pcd2n$hc9me$1@ID-11957.news.dfncis.de> You've rebound a to a different object in the second line. -- Emile van Sebille emile at fenx.com --------- "Bob Parnes" wrote in message news:trjcuqh5bdrs89 at corp.supernews.com... > As another newcomer I discovered this on my own. What is confusing, I > think, is that it seems to apply only to empty objects. For example > > >>> a = b = [1, 2. 3] > >>> a = [4, 5, 6] > >>> b > [1, 2, 3] > >>> a.append(7) > >>> a > [4, 5, 6, 7] > >>> b > [1, 2, 3] > > In this case a and b are not bound to the same object. It seems to me that > python treats empty objects differently from assigned objects. Or something > like that, I'm probably not articulating it well. > > -- > Bob Parnes > rparnes at megalink.net From andy47 at halfcooked.com Mon Oct 15 22:15:45 2001 From: andy47 at halfcooked.com (Andy Todd) Date: 16 Oct 2001 02:15:45 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> Message-ID: "Andrew Dalke" wrote in <9qe49r$4k1$1 at slb3.atl.mindspring.net>: >Chris Tavares wrote: >>May I be the first to say - ICK! > >I'll second that nomination. > And put me down for thirds ... >It looks ugly, and doesn't solve any problems I have. >I *like* > > if e1: > x = e2 > else: > x = e3 Its the only construct I use in all of the languages I have to code in because it is the only one that is common amongst them and also because it is the most understandable. Two very good reasons I'd say. > [snip examples] > >I tried looking through the thread in its various subject names. >I couldn't figure out what was the driving reason for this idea. >(Other than as a replacement for C's ?: ternary operator.) >Enlightment, anyone? That is my take as well. Never liked C's ternary operator, never used it. Replicating it in Python adds nothing to the language, it does not make code cleaner or more efficient and it certainly doesn't make it easier to understand. Not that my vote counts but minus about 20 from me. > > Andrew > dalke at dalkescientific.com > Regards, Andy -- Content free posts a speciality From fionn at spamfilter.de Thu Oct 11 18:04:25 2001 From: fionn at spamfilter.de (Fionn Behrens) Date: Fri, 12 Oct 2001 00:04:25 +0200 (CEST) Subject: Ann: pSQL.py (manipulation of SQL dbs through python objects) Message-ID: Hi all! Ian Bicking's announcement of SQLbuilder.py on the webware-discuss mailing list a few days ago (very recommandable, btw; it includes a number of great ideas) reminded me of the fact that I have something slightly similiar on disk for quite some time now. I managed to motivate myself to write a readme and prop up a web page for anyone who might be interested. You can find it at: http://rtfm.n3.net/software/psql/ ABSTRACT: * Are you using a (My)SQL database all day in your programming projects and dont want to write SQL statements again and again all over? * Would you like to use an SQL database in your project without needing to know much about SQL? * Interested in making your database access sources a bit more readable and easier to grok for other programmers? If you can answer YES to one of these, pSQL might be of interest to you. WHAT IT DOES: Basically, pSQL wraps all database access and all data you get from your database into some easy-to-handle and easily usable objects that "feel" like standard python data structures. So, if you have a pSQL database object called "myDB" with a table called Address, you can find all people in that table who are living in Oklahoma by issuing a command like: |>>> res = myDB.Address.City["Oklahoma%"] |>>> len(res) |2 To find out the phone numbers of those two, you can use e.g.: |>>> res.column("Phone") |['0405-12345', '0405-67890'] or: |>>> for r in res: |... print "%s: %s"%(r.Name, r.Phone) |John Doe: 0405-12345 |Joe User: 0405-67890 To change one of those numbers in the database: |>>> john = res[0] |>>> john.Phone = '0405-54321' # or: res[0]["Phone"] = '0405-54321' WHAT IT DOES NOT: pSQL currently works with MySQLdb only. This will change in a future version and an abstraction layer will be added which allows the use of any DB 2.0 API compliant SQL module, e.g. for postgres. Visit the web page for more information. Regards, Fionn From claird at starbase.neosoft.com Wed Oct 3 17:25:01 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 3 Oct 2001 16:25:01 -0500 Subject: Basic button question References: <3bbb4a89_8@news.newsgroups.com> <1002130337.69458.1@eos.uk.clara.net> <3bbb4f63_8@news.newsgroups.com> Message-ID: <9701227861E3602F.CD1F436AF3651BA7.7CD7813B17E731A3@lp.airnews.net> In article <3bbb4f63_8 at news.newsgroups.com>, Janos Blazi wrote: >> Try binding instead. > >Thx. >I thought of that but it is not exactly what I should like to have. I should >like to push the button, see that it is being pushed and go on after that. . . . 1. Would the button's -command serve you better than a ing? 2. If you insist on an explicit , you can man- ipulate the order of execution of the consequences with bindtags. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From db3l at fitlinxx.com Thu Oct 25 00:22:58 2001 From: db3l at fitlinxx.com (David Bolen) Date: 25 Oct 2001 00:22:58 -0400 Subject: Critical sections and mutexes References: Message-ID: writes: > Should the GIL be removed someday down the road, *all* multithreaded apps > would become suspect and overdue for a thorough review. Perhaps multithreaded programs that have made assumptions, but to be honest, anything I've written is always protecting itself from its use of any shared resources (whether internal or system) and I wouldn't expect any problems should the GIL be removed. > FWIW, I don't think the GIL will ever go away, or if it does, we'll end up > with something that gives the same behavior. Think about it: no GIL means > that a normal Python program (ie no extension modules in use) could crash > the interpreter. No it doesn't. Obviously removing the GIL requires making the C core of Python threadsafe, thus it will internally use whatever locks or synchronization mechanisms are necessary around shared structures or processes. You don't just stop using the GIL without any other changes. The interpreter just won't be a single global lock. Python scripts shouldn't have any risk at all - other than the same risk they have today through misuse of shared resources without locking, and yes those scripts that today make assumptions may run into trouble. But I just see that as the definition of a well-written threadsafe program. Who will undoubtably be affected are extension writers, and the core would probably have to automatically allocate an extension-global lock per extension (or one for all extensions) to ensure only one Python thread can be in the extension(s) at a time, at least for legacy support. > the interpreter. Maybe it's just me, but Guido et al have gone to great > lengths to make it nearly impossible to do that (and when it happens, it's > considered a bug and is fixed ASAP). The GIL is what lets multi-threaded > Python programs still behave like Python programs should. Well, to some extent that's true, but it's hardly the only way to do it. It's just a poor man's global lock around an entire interpreter. Safe, but also inefficient. Whether resources will become available to work on more fine grained locking for better efficiency is questionable, but I'd certainly be in favor of any work in that direction. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From max at alcyone.com Sat Oct 6 03:58:18 2001 From: max at alcyone.com (Erik Max Francis) Date: Sat, 06 Oct 2001 00:58:18 -0700 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> <3BBE6A57.FD354FE3@alcyone.com> <7xlmipcji1.fsf@ruckus.brouhaha.com> Message-ID: <3BBEB99A.A1F0F9D7@alcyone.com> Paul Rubin wrote: > Nah. I mean, if efficiency was a big issue, you wouldn't be using an > interpreted language in the first place. What's left, if you have a > good matrix package, is something like if your language had complex > numbers but didn't have reals. You can still represent the reals as > complexes. For that matter, lots of languages have had reals but no > integers. It hasn't been that bad a problem. You're missing the point. Quaternions can behave qualitatively differently from their corresponding matrices. You use quaternions in which matrices have stability problems. Do a Web search with "quaternions matrices gimbal lock" and you'll see what I mean. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Every exit is an entry somewhere else. \__/ Tom Stoppard Product's Quake III Arena Tips / http://www.bosskey.net/ Tips and tricks from the absolute beginner to the Arena Master. From richard at bizarsoftware.com.au Sun Oct 14 19:18:12 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Mon, 15 Oct 2001 09:18:12 +1000 Subject: Python web client anyone? In-Reply-To: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> References: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> Message-ID: <0110150918121X.11044@ike> On Sunday 14 October 2001 21:29, Paul Rubin wrote: > Anyone know if there are any web client modules written in Python, > along the lines of the Perl LWP module? Thanks. What's Perl LWP? Believe it or not, not everyone on this list is a Perl haxxor too. Richard From max at alcyone.com Sun Oct 14 15:49:22 2001 From: max at alcyone.com (Erik Max Francis) Date: Sun, 14 Oct 2001 12:49:22 -0700 Subject: bug in builtin compile function? References: <3BC9E807.75FB715A@mikemccandless.com> Message-ID: <3BC9EC42.422EEE78@alcyone.com> Michael McCandless wrote: > I told compile that the file was "foo.py", so, why doesn't it say that > in the SyntaxError instead of saying ? Because the parse error was in the string you passed it on, not in foo.py. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ It is not enough to succeed; others must fail. \__/ Gore Vidal Product's Quake III Arena Tips / http://www.bosskey.net/ Tips and tricks from the absolute beginner to the Arena Master. From pdfernhout at kurtz-fernhout.com Mon Oct 8 18:50:22 2001 From: pdfernhout at kurtz-fernhout.com (Paul Fernhout) Date: Mon, 08 Oct 2001 18:50:22 -0400 Subject: [ANN] Pointrel Data Repository System v20010915 released Message-ID: <3BC22DAE.3A9921E@kurtz-fernhout.com> Hello all, The latest version of the Pointrel Data Repository System is now available from SourceForge. The code is entirely in Python and supports a database model similar to the Entity-Relationship model. The project is hosted on SourceForge: http://sourceforge.net/project/?group_id=6010. The latest version for Python should be downloadable here (78k): http://prdownloads.sourceforge.net/pointrel/Pointrel20010915.zip This page has more details (and is essentially the readme file): http://www.kurtz-fernhout.com/pointrel/ You may have a vague recollection of a post on Pointrel in this newsgroup in May 2000: http://groups.google.com/groups?hl=en&th=925265d9c9b99c1a&rnum=1 The Pointrel architecture has been extensively revised from that version -- primarily in the direction of ease of use. This version includes a demo implementation of Vannevar Bush's Memex (which he proposed around 1945). More on Bush's Memex can be found at: http://www.theatlantic.com/unbound/flashbks/computer/bushf.htm This version includes several other GUI examples (mostly with TKinter, but a couple using wxPython). These simple demos include a to do list manager, a notebook (useful for developing snippets of Python), a drawing application, an email viewer, and an archive viewer. ========================================== >From the readme file: * What is the Pointrel Data Repository System? The Pointrel Data Repository System is a variant of an Entity-Relationship model database. The Pointrel system provides a way to easily handle loosely structured data stored on disk, like for INI files, version control systems, bug tracking systems, or simple AI type applications. It takes an approach to data storage which emphasizes flexibility over speed. It also emphasizes storing new information for the long term over modifying or deleting old information. It hopefully makes it easier to build new layers of abstraction and indexing over old data. The Pointrel Data Repository System bears some resemblance to the ROSE/STAR system described by William Kent in his book "Data & Reality". In a nutshell, the Pointrel Data Repository System helps you build associations which define relationships between entities. These associations are essentially triadal links between things indicating one thing is linked to a second thing in a way defined by a third thing. The simplest way to use such links is to make the equivalent of object properties or a dictionary, such as "Fluffy weight 20kg" which if a dictionary would be Fluffy["weight] = "20kg". However, Pointrel differs from a dictionary in that is supports queries like one for all dictionaries which define a weight of 20kg or all relationships between "Fluffy" and "20kg". Triads are all defined within a specific context that gives meaning to the associations (making triads actually have four fields). The context allows triads to be handled within an archive in a somewhat more modular fashion using them as filters, since you can easily ignore triads not in the context of interest. All fields of a triad are indefinite length binary strings -- so they could be anything from "foo" to the contents of a binary file. * What is a simple example of the Pointrel API being used? See "fluffyExample.py" for an example of using the simplified global function interface. Here is an excerpt from that file: from pointrel20010915SimpleInterface import * Pointrel_initialize("myArchive") Pointrel_startTransaction() Pointrel_add("simpleexamplecontext", "Fluffy", "weight", "20kg") Pointrel_add("simpleexamplecontext", "Fluffy", "color", "beige") Pointrel_add("simpleexamplecontext", "Fluffy", "teeth", "pointy") Pointrel_add("simpleexamplecontext", "Fluffy", "teeth", "nasty") Pointrel_add("simpleexamplecontext", "Fluffy", "preferred food",\ "Knights who say 'Nie!'") Pointrel_finishTransaction() string = Pointrel_lastMatch("simplecontext", "*", "weight", "20kg") print string # string would be --> "Fluffy" string = Pointrel_lastMatch("simplecontext", "Fluffy", "weight", "*") print string # string would be --> "20kg" string = Pointrel_lastMatch("simplecontext", "Fluffy", "teeth", "*") print string #string would be --> "nasty" list = Pointrel_allMatches("simplecontext", "Fluffy", "teeth", "*") print list #list would be --> ["pointy", "nasty"] * What is the license? BSDish. See license.txt for details. * What versions of Python is it for? This code was developed primarily under Python 2.1 under Windows 2000. It has also been spot tested under WinNT 4.0 under Python 1.5.1. with changes made to run there, however, the primary focus is Python 2.1. * How reliable is the Pointrel System? The Pointrel system should not be relied on for mission critical systems yet. It has not undergone enough testing, especially in terms of multiple simultaneous users of the same archive. It may be adequate at this point for INI file handing or similar non-critical applications if you do some testing on your own for suitability in your particular circumstance -- however I cannot guarantee that. The software comes with NO WARRANTY. I do not yet use Pointrel for anything mission critical. One reason for this release is in hopes people will try it, provide feedback, and perhaps make suggestions for improving its reliability. I will say that ensuring the long term integrity of the data stored is a high priority. * Why are you working in this field of data and knowledge management? I am interested in archiving and structuring knowledge using a fine grained approach, especially knowledge on how to make things in a sustainable way as proposed by Buckminster Fuller's "Design Science" and many others, and making that knowledge freely available to all people of the world to help reduce ignorance and want and to increase humanity's chances of surviving with style on Earth and even someday in space habitats. See: http://www.kurtz-fernhout.com/oscomak/index.htm for more details. If you are interested in others doing work with knowledge about sustainability, look at: http://www.bfi.org/ and: http://www.humaninfo.org/ ========================================== If you try the Pointrel Data Repository System, please let me know if you have fun with it or if it proves useful in some endeavor. -Paul Fernhout Kurtz-Fernhout Software ========================================================= Developers of custom software and educational simulations Creators of the Garden with Insight(TM) garden simulator http://www.kurtz-fernhout.com From tim.one at home.com Tue Oct 16 23:22:13 2001 From: tim.one at home.com (Tim Peters) Date: Tue, 16 Oct 2001 23:22:13 -0400 Subject: profiler results for __getattr__, am I reading this correctly ? In-Reply-To: Message-ID: [Thomas Jensen] > I'm working on a Gnutella client, and were beginning to look a bit at > performance. > After running it through the profiler module, it seems most of the time > is spent in asyncore.dispatcher's __getattr__ method. > (used for socket pseudo-inheritance AFAIR). > My question is, can this be true?, Certainly, but unlikely. > or am I reading the results incorrectly ? Probably not, and more likely that the results are incorrect. Try grabbing profile.py out of the current CVS tree (it should run fine under 2.1.1 too, and under 2.0.1). There was a systematic bug that caused time to get charged to the wrong functions, when a Python exception got raised by Python code but caught and cleared by C code before returning to Python. For example, hasattr() routinely screwed up profiling results. One symptom is tiny functions reported to take mountains of time when you're pretty sure they don't; another symptom is the profiler reporting that a function you know darned well isn't recursive was actually involved in recursive calls. All that was due to the profiler's view of the call stack getting out of synch with reality by one frame. The bug existed for years, and was just fixed within the last couple of weeks. Note that the current (CVS) profile.py also has a new, more accurate, and less intrusive calibration procedure. Calibrating the profiler for the box it's running on can be important. Docs for that can be gotten from CVS, or from 2.2b1 to be released this Friday. From db3l at fitlinxx.com Wed Oct 24 19:02:02 2001 From: db3l at fitlinxx.com (David Bolen) Date: 24 Oct 2001 19:02:02 -0400 Subject: None References: <9r4b95$suc$1@news.rchland.ibm.com> <9r6lep$tdg$1@news.rchland.ibm.com> <9r7au7$oe2$1@news.rchland.ibm.com> Message-ID: "Larry Whitley" writes: > That's it! Here's the offending code, a little earlier in process(). > > elif pc.command == "dual": # command was a dual address cycle > pc.command, None, None = tr.decodeCommand() > > Looks like it considers None a variable though it is not under the elif that > used it. Yes, local variable determination is a static compile-time operation, based on compiling an assignment, and not runtime based. But the error is runtime based if the variable gets used in the code path before being initialized. There's no clean way to ignore components in tuple unpacking, but you definitely want to avoid using existing names (such as None), since while it's just a name binding to the builtin None object, most code works better when "None" really points to that object :-) If you don't want to create a throwaway name, or don't want to keep a reference to the other tuple elements around, you could always change that line to something like: pc.command = tr.decodeCommand()[0] -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From dalke at dalkescientific.com Thu Oct 18 04:10:40 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 18 Oct 2001 02:10:40 -0600 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> Message-ID: <9qm32o$h80$1@slb7.atl.mindspring.net> Huaiyu Zhu: >You raised several valid points, but your picking on the examples sometimes >hinges on specific wart of the examples. Yep. My belief is that cases where your proposal shines doesn't occur very often in real code, and that the additional flexibility will instead lead to more obsfucated code. >Do you recommend always using this ... >This style change is orthogonal to the issue of statements before condition. >The question is whether the else-clause in while-loop has any real use. Consider the following code, which finds files that use the while/else construct. === import sys, re wh = re.compile("( *)while") spaces = re.compile("^ *$") for filename in sys.argv[1:]: in_while = 0 indent = 0 for line in open(filename).readlines(): if spaces.match(line): continue if in_while and spaces.match(line[:indent+1]): continue if in_while and spaces.match(line[:indent]) and \ line[indent:indent+5] == "else:": print filename in_while = 0 continue in_while = 0 m = wh.match(line) if m: in_while = 1 indent = len(m.group(1)) === Running this on *.py in the standard library I found 1 in fpformat (written by Tim Peters) 2 in threading (also written by Tim Peters) 1 in test_grammar (doesn't count - it's testing this construct) 1 in distutils.command.build_py (not written by Tim Peters :) In other words, it isn't used very often. By comparison, there are nearly 200 uses of 'while 1:' and 500 uses of 'while'. So 1% of whiles use end. To answer your question. No, I don't "always" decline to use else in a while. I have a sense of when to use it, and I recall being happy when I had a case that was appropriate, but sadly I don't know how to convert that sense into words. >>I prefer the syntax mentioned some months ago when this discussion >>last flared up. >That is something I'd like too, except: >- new keyword "loop", >- do we want to make "while" obsolete? >- need two kinds of "break" (one impact "else" the other does not). That's a spelling issue and should not be the primary issue. That is, - "while 1:" is a possible spelling for "loop:" (with "while :" as the full generalization) - that means 'while' won't be obsolete - Really? I thought 'break expression:' would be identical to if expression: break and wouldn't hit the else. Neither does the existing else. So there are only two ways to write the same thing. >if m = re.match(patt1, x); len(m.groups())>3: > a = process_header(m) >elif m = re.match(patt2, x); m: > b = process_body(m, some_other_data) >... Ahh, this is more realistic, but still not realistic enough. What do you do with a and b? Are headers and bodies interleaved or is the header optional, followed by a body, or ...? My code that looks like this is more of the form pat1 = re.compile("pattern1") # but I use a more descriptive pat2 = re.compile("pattern2") # name, not 'pat1', 'pat2' for x in reader: # Example of a string that should match m = pat1.match(x) if len(m.groups()) > 3: a = process_header(m) print a continue # This is an example of a body m = pat2.match(x) if m: b = process_body(m, some_other_data) print b continue raise AssertionError("Unknown line: %s" % x) or I use while 1/breaks. But in real life I wrote my own parser generator :) I looked at xmllib in the standard library, as a module which uses the re library. Most of its uses of the match function are in the context of if pattern.match(s): .... continue -or- m = pattern.match(s) if m: .... continue -or, raise an exception instead of using a continue -- self.syntax_error(msg) This style is more like what I'm used to - where there is no series of if/elif/elif's because the end of each branch is a continue, break or raise. So there are no deeply nested and ugly constructs like you think there are. >Do you suggest that the normal way to use such control structures is to >always enclose them in a function? Nope. Specifically I said ] Need a real life example here. Is there something in the standard ] library which would be improved with this change? The reason I ] ask is because this code can be refactored into a function. Note the "can be" (not should or must) and "need a real life example" because the best solution is dependent on context, and it's too easy to come up with an contrived example which emphasis a problem that doesn't usually occur. >I'd say the above regular expression example is quite common, and your >function would need quite some optional variables. So what are some example from the standard library which would be improved? >>but increasing the temptation for people to write >> >> a = f(x) >> if a > 2: >> g() >> >>as >> >> if a = f(x); a > 2: >> g() > >Good point. Although I do not see the temptation, I don't see the use, >either. Maybe it should not be allowed after "if", only after "elif". I don't use semicolons in my python code except for two cases: 1) simple assignments, like a = 5; b = 12; c = 13 or a = min(x, y); b = max(x, y) 2) deliberately use few lines of code, like the RSA in four lines of Python. I looked in the standard library and found semicolon uses in these modules UserList (simple assignments) UserString (simple assignments) asyncore (simple assignments) base64 (in self-test code - not in user visible code) bdb.py (in an exec'ed string - case 2) cgitb (in a docstring - not in real code) ftplib (one use is obsolete, other use okay - simple assignments followed by a del) imaplib (simple assignment) mailcap (simple assignment - an increment) mhlib (in self-test code) os (simple assignments) quopri (simple increments and decrements, also does a break) regsub (don't like the two instances - they are incrs) sre_compile (I'm mixed about its uses) types (tb = None; del tb) warnings (in internal test code) So it seems that ';' isn't used very often. I don't want to increase that. At all. Multiple statements on the same line is a bad thing except in tiny amounts. >If we are not considering typos between ";" and ":", this can already happen > >x = 1;0; y = 2.0 >if x > 1,0: > ... It could, except that using ';' is not used very often and is not promoted as a good use. So the first line easily stands out as unusual. I have been hit by variants of the second. BUT! You had said > This structure is safe against single typing errors My point was to show a counter-example to this assertion. It was not to show that the rest of Python is not prone to single character errors. >>if a; \ >> b; \ >> c; \ >> d: \ >> e; \ >> f; \ >> g > >I would rather consider this as contrived. :-) Yep. But that confusion is not possible with current Python because after an "if" you need only look for the first ";" or ":"-like object. So I'm presenting a counter-example to your statement that > Since the change is only in the syntax of "if", "elif" and "while", > not in the fundamentals of expressions and statements, there is not > much more chance of obfuscation than existing syntax. 'Course, I'm also exaggerating what "much more" means. :) >Maybe our intuition is different, but it appears to me that > > while char=file.readline()[3]; char != 'x': > >is exactly following things one step at a time, in the right order. For me, I need to scan the line, find the semicolons, keep track of where they are, break it down into the different parts, then understand what each one does. Breaking it down as ] for line in iter(file.readline, ""): ] char = line[3] ] if char != 'x': ] break ] process(char) is easier for me because the layout of the code over the vertical makes it easier for me to track where the components are, as does naming those components. >But more seriously, is it practical to change every while loop to for-loops >with iterators? No, and I never said it was. I rarely assert such absolutist beliefs. What I'm pointing out is that 1) many solutions exist and 2) why I might prefer something different. > Consider my other example you ignored > > while string = raw_input(prompt): not string.startswith("n"): > do things with string > break the loop according to condition > change prompt according to condition > do something more I ignored it because I'm pushing for less contrived examples. I want to see something that comes from real code. Here's a contrived example. Try doing this in Python i = 5; a: printf("In a with %d\n", i); if (i % 2 == 1) goto c; i = i*3 + 1; b: printf("In b with %d\n", i); i--; if (i * i < 200) goto a; if (i > 5) goto c; c: printf("In c with %d\n", i); if (i < drand48() * 100) { i *= 2; goto c; } i -= 5; if (i<0) i=-i; goto a; It's very hard to translate (keep adding gotos and statements if it isn't hard enough). Does that mean goto should be added to Python? No, it means that contrived examples aren't very useful. (BTW, there is a program from Knuth in MIX which I found very hard to translate to Python because of the lack of a goto. I ended up writing it in C++ instead.) Since you asked, here's a more realistic chunk of code which meets your criterion, is much more extensible than what you have, and doesn't need your proposal. ====== import re def change_prompt(line, state): state.prompt = line[7:] def quit(line, state): print "Later!" raise SystemExit(0) def set(line, state): words = line.split() state.values[words[1]] = words[2] def show(line, state): words = line.split() v = words[1] print state.values.get(v) def has_balanced_parens(s): n = 0 has_parens = 0 for c in s: if c == "(": n = n + 1 has_parens = 1 elif c == ")": n = n - 1 if n < 0: return 0 return has_parens and n == 0 def yippee(line, state): print "Yippee!" def dump(line, state): for k, v in state.values.items(): print "%s -> %s" % (k, v) def clear(line, state): state.values.clear() actions = ( (re.compile(r"prompt=").match, change_prompt), (re.compile(r"quit$").match, quit), (re.compile(r"n").match, quit), (re.compile(r"set [^ ]+ [^ ]+$").match, set), (re.compile(r"print [^ ]+$").match, show), (re.compile(r"dump$").match, dump), (re.compile(r"clear$").match, clear), (has_balanced_parens, yippee), ) class State: def __init__(self): self.prompt = "> " self.values = {} state = State() while 1: try: line = raw_input(state.prompt) except EOFError: break for action in actions: if action[0](line): action[1](line, state) break else: print "Could not understand:", repr(line) ===== Here's an example interaction to show it really does work % python spam.py > set a Andrew > print a Andrew > set x 9 > dump x -> 9 a -> Andrew > clear > dump > prompt=Whaddya want? Whaddya want? q=9 Could not understand: 'q=9' Whaddya want? ()()) Could not understand: '()())' Whaddya want? ()() Yippee! Whaddya want? nothing Later! % >In practice it is not always a good idea to put every code block in a >separate function, although it might be an ideal goal in some style. Again, despite my counterexamples I saying this is the style that much be used in all cases. I'm pointing out that the examples you give are too limiting to tell if your proposal really has merit. There may be other solutions to the underlying problem which are more general, more maintainable, and which don't need this ';' ugliness. >This example does not fit the pattern. You're right. I couldn't come up with a good example. My above change prompt/print/set code above is much better. >This proposal is not meant to >replace all the usage of "for" by "while". On the other hand, your >alternatives seem to recommend changing all the "while" to "for". 'Tis true. I like iterators. But perhaps you aren't fully considering the alternatives when you come up with examples. >>while expr: >> statements >>break if expr: >> statements > >Now I do. :-) (See near top.) I'll add it to the PEP. The main issue is >that it does not distinguish two kinds of "break" (in terms of interaction >with "else"). Could you clarify what the two types are? Both breaks skip the else clause. (This is a repeat question from earlier in this post.) >1. Is it practical to change all while loops to for-loops with iterators? No, and I didn't propose that. I only point out an alternative solution exists, so the usefulness of your proposal is not clear cut. >2. Is it practical to change all elif into nested scope with break / return? No, and I didn't propose that. But for the cases you gave, the standard solution is to use continue/break/return/exceptions. When those are appropriate solutions, the benefit of your proposal decreases. So you need to show a realistic example where the solutions using existing Python constructs is ugly but which can be improved (in succientness and readability) with your proposal. My beliefs are that: 1) most of your examples are too contrived/limited to provide a useful understanding of the advantage of your proposal. 2) semicolon-ed statements lead to less understandable code >I'd guess no. Of course for any simple example it would appear so, and any >complicated example may appear contrived. It's easy. Scan the standard library and find a chunk of code which you believe will be improved with your construct. Andrew dalke at dalkescientific.com From sholden at holdenweb.com Wed Oct 31 17:23:58 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 17:23:58 -0500 Subject: Is round() broken? References: Message-ID: "Joseph Wilhelm" wrote ... > Hello again everybody! > > I'm having some troubles with round() now... either I'm doing it completely > wrong or round() is. But here's what I'm getting. > > >>> round( 43583.010000000002, 2 ) > 43583.010000000002 > >>> round( 43583.010000000002 ) > 43583.0 > >>> round( 43583.010000000002, 1 ) > 43583.0 > >>> round( 43583.010000000002, 2 ) > 43583.010000000002 > >>> > > So, what this is saying.. is that rounding to 1 decimal point works... but > anything beyond that is broken? Rounding negative will round the number > before the decimal point also. > > And actually, as a side question.. that number was pulled from a float8 > field in a Postgres database, using the 'pg' module. If I look at the field > through pgAdmin, I just see it as "43583.01", instead of that whole big long > decimal. Is it supposed to come out like this? > Rule 1: don't use floating point if you don't understand how it works. Rule 2: read http://python.sourceforge.net/devel-docs/tut/node14.html regards Steve -- http://www.holdenweb.com/ From sholden at holdenweb.com Wed Oct 10 08:07:29 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 10 Oct 2001 08:07:29 -0400 Subject: Spewing SQL query resultset to HTML table... References: Message-ID: "Orr, Steve" wrote ... > Newbie's first post... New Project... should I use Python or PHP? > > I need to take ANY valid SQL query and display the resultset in HTML. > KEY QUESTION: How do I capture the column aliases and display them as > headers in an HTML table? I have over 100 SQL queries and I just want to use > one simple routine to display results. I don't want reams of hand code just > for output. I've already done this with PHP but I can't find a way to do it > in Python. I'm assuming it's because of my Python newbie status and not > because PHP is more capable. > BY WAY OF EXAMPLE... here's how this was accomplished in PHP: > -------------------------------- > $db_connection=OCILogon(blah, blah, blah...); > $SQLtext='select file_name "File Name", bytes "Bytes" from dba_data_files'; > $stmt=ociparse($db_connection,$SQLtext); // Parse the SQL... > OCIExecute($stmt,OCI_DEFAULT); // Exec & save results in associative > array... > $ncols=OCINumCols($stmt); // Get # of columns in the select statement... > $nrows=OCIFetchStatement($stmt,&$results); //Get # rows and $results > array... > // PRINT THE COLUMN HEADERS... KEY FEATURE! > print "

  Email this %s
\n"; > while (list($key,$val)=each(&$results)){print "";} > > print "\n"; > // Now print the resultset... > for ( $i = 0; $i < $nrows; $i++ ) { > reset(&$results); > print "\n"; > while ( $column = each(&$results) ) { > $data=$column['value']; > $datum=$data[$i]; > if (is_numeric($datum)) {//format based on string or numeric > value... > settype($datum,"double"); > $datum=number_format($datum); > print "\n"; > }// end if > else print "\n"; > }// end while > print "\n"; > }// end for > print "
$key
$datum$datum
\n"; > ?> > -------------------------------- > > Not too bad for just a few lines of code. In my first pass at this project I > was able to learn PHP and achieve spectacular results in 2 weeks. As a proof > of concept that Python can do this just as easily I want to replicate what > I've already done in PHP. Then I can make an informed decision about PHP vs > Python. I'm an Oracle DBA about to develop a large database admin toolset. > I've had significant OOP experience in a "prior life" and now I'm getting > back into the development mode and need to match the language and tools with > the requirements. > > Formal Spec: > With ANY valid SQL query, render output to an HTML table. Labels for the > HTML column headers should come from the SQL statement. Must be able to > format differently for strings and numbers with strings being left aligned > and numbers formatted with commas and right aligned. Must be able to handle > result sets with any varying number of columns and up to 10,000 rows. This > is for an Oracle database administration app so the feature set for the > database API should be richly Oracle-specific (e.g. a complete > implementation of Oracle's OCI.) Other RDBMS connectivity not needed! > > > AtDhVaAnNkCsE, > Steve Orr, > Veteran Oracle DBA and Python Newbie > The following code takes a database cursor on which you have executed a query, with its result set optional in case you have already called fetchall(), and prints the results as neatly as it can manage to. I have tried it with Oracle via ODBC, and don't know of any reason why it shouldn't work with (e.g.) DCOracle2. Hope this helps you avoid PHP! regards Steve def cpp(cursor, t = None): print d = cursor.description if not d: print "#### NO RESULTS ###\n" return names = [] lengths = [] rules = [] for dd in d: l = dd[1] if not l: l = 12 l = max(l, len(dd[0])) names.append(dd[0]) lengths.append("%%%ss" % l) rules.append("-"*l) format = " ".join(lengths) print format % tuple(names) print format % tuple(rules) if not t: t = cursor.fetchall() for row in t: print format % row print -- http://www.holdenweb.com/ From xavier at perceval.net Tue Oct 9 07:13:47 2001 From: xavier at perceval.net (Xavier Defrang) Date: Tue, 9 Oct 2001 13:13:47 +0200 (CEST) Subject: String formatting with two dictionaries? In-Reply-To: <3BC2BDC3.20A41F38@snakefarm.org> Message-ID: On Tue, 9 Oct 2001, Carsten Gaebler wrote: > "%(foo) %(bar)" % magic(dict1, dict2, ...) So what about writing a class called "magic" that takes a bunch of dictionaries as __init__ arguments, and use an overridden __getitem__ to perform look-ups thegiven dictionaries? Xavier Defrang Perceval R&D Team xavier at perceval.net ------------------------------------------------- Perceval Technologies SA/NV Tel: +32-2-6409194 Rue Tenbosch, 9 Fax: +32-2-6403154 B-1000 Brussels http://www.perceval.net BELGIUM info at perceval.net ------------------------------------------------- From jjl at pobox.com Sun Oct 28 14:01:53 2001 From: jjl at pobox.com (John J. Lee) Date: Sun, 28 Oct 2001 19:01:53 +0000 Subject: hang with pty's and processes Message-ID: I'm not used to forking, pty's, etc., so I'm hoping my problem here is something elementary. On the 84th password tried (on my linux machine at least), this program hangs in pty_Popen.read, in os.read (see the line marked with # !!) -- it never returns or raises an exception. Why?? Perhaps I'm hitting some kind of system limit on pty's or something? There are, at most, only a couple of relevant processes (mount, python, losetup, etc) listed at any one time while this is running, so it doesn't seem to be a process limit. #!/usr/bin/env python """Crack off-by-one encrypted partition password. pty_Popen is derived from code posted to comp.lang.python by Alex Coventry. Yes, I'm a fool for not writing my password down properly. """ import sys, os, pty, time class pty_Popen: def __init__(self, command, args, delay=0.1): self._delay = delay self._cmd = command self._pid, self._child = pty.fork() if self._pid == 0: r = os.execv (command, [''] + args) os._exit(r) def wait(self): os.waitpid(self._pid, 0) def read(self, max_read): time.sleep(self._delay) ret = os.read(self._child, max_read) # !! return ret def write(self, text): time.sleep(self._delay) return os.write(self._child, text) def response(self): while 1: try: response = self.read(1024).strip() except OSError: # no output response = "" break if response: break return response def expect(self, expected, actual): if expected != actual: raise ValueError, "expected '%s', got '%s' from %s" % ( expected, actual, self._cmd) def ok(self, expected, actual): if expected == actual: return 1 else: return 0 class PswdIterator: min = 33 max = 126 def __init__(self, passwd): self.p = passwd self.i = 0 self.cn = None self._new_char = 1 def next(self): p = self.p if self.i >= len(p): return None if self._new_char: self.cn = self.min self._new_char = 0 else: self.cn += 1 if self.cn >= self.max: self.i += 1 if self.i >= len(p): return None self._new_char = 1 return p[:self.i] + chr(self.cn) + p[self.i+1:] def crypton(crypt, device, cryptname, passwd): """Attempt to turn encrypted partition on, return 1 on success.""" delay = 0.001 p = pty_Popen("/sbin/losetup", ["-e", "serpent", device, crypt], delay) p.expect("Password :", p.response()) p.write(passwd+"\n") p.expect("", p.response()) p.wait() p2 = pty_Popen("/bin/mount", [device], delay) success = p2.ok("", p2.response()) p2.wait() p3 = pty_Popen("/usr/local/bin/encoff", [cryptname], delay) r = p3.response() p3.expect("", r) p3.wait() if success: return 1 def crack(): cryptname = "crypte" crypt = "/home/cd2/cryptfilee" passwd = "goeshere" device = "/dev/loop2" pwi = PswdIterator(passwd) while 1: print print "trying %s" % (passwd,) if crypton(crypt, device, cryptname, passwd): print "got it!" print passwd break passwd = pwi.next() if passwd is None: print "failed" if __name__ == "__main__": t = time.time() crack() t = time.time() - t print t print t/60.0 Thanks for any help John From fredg at sdsc.edu Thu Oct 25 14:59:15 2001 From: fredg at sdsc.edu (Frederic Giacometti) Date: Thu, 25 Oct 2001 11:59:15 -0700 Subject: script Re: comparative performance benchmark Python 1.5.2 - 2.0 - 2.1 References: Message-ID: <3BD86103.6FD63602@sdsc.edu> I submitted the scripts to as sourceforge bug 474992... http://sourceforge.net/tracker/index.php?func=detail&aid=474992&group_id=5470&atid=105470 The scrips can also be obtained through cvs at: cvs -d:pserver:anonymous at cvs.JPE.sourceforge.net:/cvsroot/jpe login cvs -d:pserver:anonymous at cvs.JPE.sourceforge.net:/cvsroot/jpe checkout perftestpython Here are the results: version bench1 nogc bench2 1.5.2 0 % 2.0 48 % 33 % 21 % 2.1.1 53 % 35 % 25 % 2.2 51 % 35 % 23 % where: bench1 = original python 1.5.2 script nogc = bench1 when disabling gc bench2 = bench1 script 'rewritten' for python 2.0 and latter (string methods, sre -> pre...) These numbers represent the increase in user CPU time (see bench.out for more details). The results are high, under all angles. All python versions were build using the standard/default configure parameters. The runs are on Tru64, but we get similar results on Solaris. Can these results be confirmed ? (i.e.: if not, what did we get wrong...?). If yes ... could the features responsible for the performance hogs (gc + ???) be set as optional, and taken out of the default build ? Frederic Giacometti From michael_armbruster at eu.exch.agilent.com Wed Oct 17 07:12:27 2001 From: michael_armbruster at eu.exch.agilent.com (Michael Armbruster) Date: Wed, 17 Oct 2001 13:12:27 +0200 Subject: dosbuild download Message-ID: <1003317148.978444@cswreg.cos.agilent.com> hi there, I'm looking for dosbuild. Does anyone of you know where I could get it? Mike From ignacio at openservices.net Fri Oct 19 05:21:00 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 19 Oct 2001 05:21:00 -0400 (EDT) Subject: dynamic call of a function In-Reply-To: <5.1.0.14.0.20011019111604.00a5a010@mail.mac.com> Message-ID: On Fri, 19 Oct 2001, Luigi Ballabio wrote: > At 10:37 AM 10/19/01 +0200, anthony harel wrote: > >Is it possible to make dynamic call of a function whith python ? > > > >I have got a string that contains the name of the function I > >want to call but I don't want to do something like this : > > > >if ch == "foo" : > > self.foo( ) > >elif ch == "bar" > > self.bar( ) > >.... > > Anthony, > here are two ways to do it---I don't know which is the best, nor > whether the best is yet another. Also, you might want to put in some error > checking. > > class Test: > def foo(self): > print 'Norm!' > def bar(self): > print 'Dum-de-dum' > def dynCall1(self,methodName): > eval('self.%s()' % methodName) > def dynCall2(self,methodName): > method = vars(self.__class__)[methodName] > method(self) > > >>> t = Test() > >>> t.dynCall1('foo') > Norm! > >>> t.dynCall2('bar') > Dum-de-dum Actually, there's another way: getattr(obj, 'func')(...). -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From pplumlee at celterra.com Wed Oct 3 14:13:15 2001 From: pplumlee at celterra.com (Phlip) Date: 3 Oct 2001 11:13:15 -0700 Subject: Tkinter pack w/o gutter Message-ID: <6f355f51.0110031013.5192d60@posting.google.com> Hypo Nt: Try this snip: from Tkinter import * tk = Tk() for side in ('left', 'right'): canvas = Canvas(tk, background='blue', width = 100, height = 100) canvas.pack(side = side, padx = "0m") mainloop() Observe how there is a gutter of 2 pixels (one per canvas) between them. How do I get rid of this gutter? 'padx = 2' stretches the gutter out, but 'padx = 0' does not get rid of it. Other experiments, such as with 'ipadx', don't work. -- Phlip http://www.greencheese.org/MakeItSo From sholden at holdenweb.com Fri Oct 5 07:33:58 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 5 Oct 2001 07:33:58 -0400 Subject: Compiling 2.1.1 on Mac OS X 10.1 - test failures References: <0110051145150H.04291@ike> <3BBD5C43.D3813A2E@letterror.com> Message-ID: "Just van Rossum" wrote in message news:3BBD5C43.D3813A2E at letterror.com... > Richard Jones wrote: > > > > On Friday 05 October 2001 13:21, Steve Holden wrote: > > > Richard: > > > > > > You should go to http://python.sf.net and report these bugs. Follow the > > > link to the project page, then select bugs. There's a "Submit New" link > > > close to the top of the page. > > > > Yep, was going to do that - just wanted to share with the community a bit a > > see if I would be able to submit useful information with the bugs :) > > Yet a lot of things have changed or have been fixed since 2.1.1, so it would > be best to test with 2.2a4, or even better, CVS Python. > While I agree that bug reports about the latest and greatest Python are what helps drive the language forward, I don't think we should neglect the bugfix releases, particularly since they could be significant in helping organizations maintain a "constant-level Python" when they can't necessarily upgrade at eaxh release for compatibility reasons. not-that-python-is-ever-backwards-incompatible-ly y'rs - steve -- http://www.holdenweb.com/ From jedi at group6.net Tue Oct 23 06:42:51 2001 From: jedi at group6.net (jedi) Date: Tue, 23 Oct 2001 03:42:51 -0700 Subject: interactive interpreter In-Reply-To: ; from spaceman@bsdzine.org on Tue, Oct 23, 2001 at 05:21:57PM +0000 References: Message-ID: <20011023034251.D68373@group6.net> import it from the interpeter cli. On Tue, Oct 23, 2001 at 05:21:57PM +0000, Karol Makowski wrote: > Hello > > How to run myprogram.py in interactive interpreter? > > Thanks > > > -- > Karol Makowski, System Administrator > URL: http://spaceman.bsdzine.org > e-mail: spaceman at bsdzine.org > -- > http://mail.python.org/mailman/listinfo/python-list -- j3di jedi at group6.net http://jedi.group6.net/ From ngps at madcap.dyndns.org Sat Oct 27 11:05:45 2001 From: ngps at madcap.dyndns.org (Ng Pheng Siong) Date: 27 Oct 2001 15:05:45 GMT Subject: Zope and SSL References: <3bd86c51.85993612@news.supernews.com> Message-ID: <9reig9$1ie$1@clematis.singnet.com.sg> According to Chris : > I am trying to incorporate openssl into my Zope webserver using > M2crypto, and I am attempting to use an existing signed certificate > given to me by Verisign. When I go to my website using SSL, however, > the server certificate I am presented with is issued by "M2Crypto > Certificate Master", and so I get a warning saying that the > Certificate Authority is not trusted. How do I tell the server that > the certificate was signed by Verisign? The server cert being presented is the one bundled with M2Crypto, i.e., you aren't asking ZServerSSL to use your Verisign cert at all! The M2Crypto server cert is called server.pem; it contains both the cert and the key pair. The "M2Crypto Certificate Master" cert is ca.pem; this has only the cert. Is your Verisign cert in PEM format? One file or two? What are they called? -- Ng Pheng Siong * http://www.post1.com/home/ngps From gustav at morpheus.demon.co.uk Tue Oct 16 18:00:47 2001 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Tue, 16 Oct 2001 23:00:47 +0100 Subject: FW: [Python-Dev] conditional expressions? References: <9qfu1p$iei$1@newshost.accu.uu.nl> Message-ID: On 16 Oct 2001 00:12:41 GMT, m.faassen at vet.uu.nl (Martijn Faassen) wrote: >But these are just vague responses. Perhaps I'll get used to them >pretty quickly. What do others think? Excuse me if I missed somekind >of long thread about this and I'm repeating the often stated. :) I don't have a particular problem with the if ... then ... else expression. It's a little wordy, but it feels fairly Pythonic - keep it clear, even if it is less terse than it could be. And in reality, I don't think there'll be a *practical* issue with the expression - people can abuse it, but they most likely won't. Any more than they do with lambda expressions, or list comprehensions, or... However, I do have some serious reservations about the parenthesis issue. Guido's rule "parens are not required except to disambiguate" sounds reasonable in isolation, but in practice, it's not at all obvious what counts as ambiguous. And it glosses over the fact that ambiguity is treated as a *syntax error* - something with no parallel anywhere else in Python's expression syntax, to my knowledge. In the message Tim quoted from Guido, there are only two examples of required parentheses: > (if 1 then 2 else 3) + 4 If this is a full statement, that's fine - if as the first token in a statement must be a statement-if, not an expression-if. But if this is a fragment, as in x = (if 1 then 2 else 3) + 4 then I don't see any need for the parens. They promote readability, sure - but they shouldn't be *mandatory*. Precedence should apply. I recall seeing a quote from Guido to the effect that "else" gobbles up everything to the end of the expression - OK, so the precedence of "if 1 then 2 else 3 + 4" is "if 1 then 2 else (3 + 4)". No problem. But *don't* make it illegal, just because it's not obvious. I haven't a *clue* what precedence applies to lambda, but I can be sure I'd never have a problem with it - I'd just parenthesize. This is the same. > a[(if i then 2 else 3) : 4] Again, the relative binding strengths of if...then...else and : should assign a meaning to the unparenthesized form. I'm not implying that omitting the parentheses is good style, but it shouldn't be illegal. As for Guido's cases where he isn't sure, > if (if 1 then 2 else 3): pass > print (if 1 then 2 else 3) > for i in (if 1 then "abc" else "def"): pass I see no reason to make the unparenthesized forms illegal. In all these cases, there's not even the possibility of two interpretation, so there's really no reason to mandate parentheses - other than one person's view on "good style". (OK, so that person is Guido, which helps :-) In summary, I can see no way of clearly explaining why certain cases of unparenthesized if-expressions should be syntax errors. Unless there is such a clear-cut, concise, explanation, I don't believe the syntax should be in error. In my view, there should be 2 relevant rules: 1. "if" as the first token in a statement is *always* statement-if. 2. expression-if has defined precedence/binding rules which disambiguate all other cases. If the rules in (2) are non-obvious, so be it. People *should* parenthesise non-obvious cases. Such cases already exist. Of course, there is an overriding fact - if the parser technology isn't up to handling the 2 rules above, then that's fine. But in that case, *define* exactly which constructs can't be parsed - and mandate that they are illegal. And point out that parenthesizing removes the unparsability. [But it's the definition that's important - most people don't *really* have an intuition of the limits of recursive descent parsers...] This has gone on too long - I hope I've made my point without labouring it to death... Paul. From anthony.harel at c-s.fr Thu Oct 25 06:42:48 2001 From: anthony.harel at c-s.fr (anthony harel) Date: Thu, 25 Oct 2001 12:42:48 +0200 Subject: get the user name Message-ID: <3BD7ECA8.7A786A3E@c-s.fr> Hi, Is there a way with python1.5.2 to get the name of the user on UNIX and Windows ? Thanks -- Anthony HAREL _______________________________ From sholden at holdenweb.com Thu Oct 25 22:43:20 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 25 Oct 2001 22:43:20 -0400 Subject: Learing Python, Newbie question References: Message-ID: "Johannes Gamperl" wrote ... > sholden at holdenweb.com says... > > > > > > Erm, what's wrong with: > > > > db_first = not os.path.exists("gbook.txt") # best? > > > > i found this one is a good deal for me :-) what about this: > > if db_first: > db_flag = "w"; > else: > db_flag = "a"; > > is there a better way to write this? > Not that I can think of. The above is pretty Pythonic. > once again ... i don't want annoy you, i just start to learn python. > Mainly i will use it for cgi programming. so the first thing i do is to > write a simple guestbook. i was surprised how easy it was ... > Yes, Python is really good for web systems. > sorry for my bad english but i'm from germany :-) > > Nothing wrong with your English. Glad to hear from you. regards Steve -- http://www.holdenweb.com/ From sholden at holdenweb.com Thu Oct 18 08:16:36 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 18 Oct 2001 08:16:36 -0400 Subject: PythonWin ASP performance References: <7a7a07a.0110170719.7a347008@posting.google.com> Message-ID: "maxm" wrote in ... > > "Jim Abrams" > > Using Python makes life easier in so many ways I can't even begin to > > describe them all, but some of the main ones are the object oriented > > approach. (We've encapsulated the ASP Built-in objects with Python > wrappers > > that solve alot of VBscript ickiness, and are subclassable) > > I have tried Python asp, but found some ick-ines where the indenting messes > up the clarity of the asp page. > > in something like: > > <%for i in range(10):%> > > <%= i%>
> > I have to write: > > <% > for i in range(10): > Response.Write('' + i + '
') > %> > > instead. > > In this simple example it isn't that bad, but when writing longer html, > tables etc it sort of defeats the purpose of asp. Suddenly I get logic and > presentation forced together. > > Have you got any good soultions to that? > The major solution is to build the HTML output as a list of strings, then join them together in some appropriate way when it's time to send output. E.g.: <% result = ["

Sample Output

"] for i in range(10): result.append("""%d
""" % i) result = "\n".join(result) %> ... <%=result%> Unfortunately, or fortunately, depending how you look at it, ASP forces the Python interpreter to treat each distinct code block as standalone, so you can't terminate a code block halfway through and then restart code at the same indentation level. "Icky" is right. But you can make it work, and many have. regards Steve -- http://www.holdenweb.com/ From dokkenrox at earthlink.net Wed Oct 10 03:40:02 2001 From: dokkenrox at earthlink.net (adam griffin) Date: Wed, 10 Oct 2001 07:40:02 GMT Subject: problem using using list with function Message-ID: i'm trying to write a function that takes a list as it's only arguement and also has a list as it's return value. this is sort of what it looks like: list1 = [ 1, 2, 3]; list2 = function(list1) def function(listArguement): #statements... return list From nicoe at wanadoo.be Wed Oct 17 16:30:05 2001 From: nicoe at wanadoo.be (Nicolas Evrard) Date: Wed, 17 Oct 2001 22:30:05 +0200 Subject: Python and gdk-pixbuf question ... Message-ID: <20011017223005.A5902@Nutella> For the fun, I try to migrate an application I've made from C to Python. I make a small use of gdk-pixbuf in this application, and I tried to use it the same way in python. (ie Image = GdkPixbuf.load_from_file(file)). But it didn't work ... Do you know if the support for gdkpixbuf is plain and working or if I have to make this piece of code in C ... -- --------------------------------------- -?) Evrard Nicolas Happily using: /\\ Li?ge (Belgium) DEBIAN GNU\LINUX _\// ------------------------------------------- From DeepBlue at DeepBlue.org Mon Oct 1 10:03:17 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Mon, 1 Oct 2001 09:03:17 -0500 Subject: gracePlot.py References: <9p316p$9uh@gap.cco.caltech.edu> Message-ID: I checked your web site. Quite some useful work there. I have a question for you: Does gracePlot have any support for plotting in 3-D space? Also, can we export data points into csv files? How does it compare to GNUplot? DeepBlue "Nathaniel Gray" wrote in message news:9p316p$9uh at gap.cco.caltech.edu... > __________________________________________________________________ > > Announcing: gracePlot.py v0.5 > > An interactive, user-friendly python interface to the > Grace plotting package. From kseehof at neuralintegrator.com Wed Oct 10 19:08:41 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Wed, 10 Oct 2001 16:08:41 -0700 Subject: problem using using list with function References: Message-ID: <002b01c151e0$91bd21e0$119ab23f@kens> Things have to be defined before they can be used. For example: print x # raises NameError exception x = 5 Of course, this won't work since x is used before it is defined. In python, function definitions are executed at runtime, so a def statement is analogous to an assignment such as x=5. If you are used to compiled languages you might have expected different behaviour since compilers usually process function definitions before runtime. In python, functions are objects just like everything else. Now this won't be surprising: f() # raises NameError exception def f(): print 'foo' adam griffin wrote: > I think I figured out my problem. I had the function definition at the end > of my script when I put it at the beginning it worked. is this the only > place you can put definitions? > > "Ken Seehof" wrote in message > news:mailman.1002701769.4408.python-list at python.org... > > > i'm trying to write a function that takes a list as it's only arguement > > and > > > also has a list as it's return value. this is sort of what it looks > like: > > > > > > list1 = [ 1, 2, 3]; > > > > > > list2 = function(list1) > > > > > > def function(listArguement): > > > #statements... > > > return list > > > > Looks like you are on the right track. Try this in your python > interpreter. > > You can learn a lot by trying things in the interpreter to see what > happens. > > > > >>> def spam_and(a): > > ... b = ['spam', 'spam'] + a > > ... return b > > ... > > >>> list1 = [ 1, 2, 3] > > >>> list2 = spam_and(list1) > > >>> print list2 > > ['spam', 'spam', 1, 2, 3] From gh_pythonlist at gmx.de Sat Oct 6 04:05:45 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 6 Oct 2001 10:05:45 +0200 Subject: Python modules in the Open Directory Project Message-ID: <20011006100545.A1040@lilith.hqd-internal> This might not be news for many of you, but for the rest, I think it's good news :-) Since a few months, I'm an editor at the Open Directory Project (http://www.dmoz.org). I you don't have any idea what this is, here's a short summary from the about page: The Open Directory Project (ODP) is the most comprehensive human edited directory of the Web, compiled by a vast global community of volunteer editors. The ODP powers core directory services for some the most popular portals and search engines on the Web, including AOL Search, Netscape Search, Google, Lycos, DirectHit, and HotBot, and hundreds of others. The ODP is 100% free. There is no cost to submit a site or to use our data. Anyone can download and use ODP data at no cost provided they comply with the ODP's free license agreement and attribution. Also, there is no cost associated with listing and submitting sites. Specifically, I maintain this category: http://dmoz.org/Computers/Programming/Languages/Python/Modules/ It's already quite comprehensive, it contains 105 entries, of which 27 are in the Database subcategory alone. I think it's become quite useful. Of course there's always room for improvement, for example I have only recently begun to create more subcategories. The entire Python category is quite useful, IMHO. I think you can see from the summary why dmoz.org is an important site: almost all search engines use its data for their directories and also for weighting their search results. I'm also pretty sure that sites that are listed in dmoz.org get more "importance factor" in regular searches. To see that they really use the directory data 1:1 (via RDF dump), you can compare these two sites: http://dmoz.org/Computers/Programming/Languages/Python/Modules/ http://directory.google.com/Top/Computers/Programming/Languages/Python/Modules/ If you want a site listed at dmoz.org, you can simply go to the appropriate subcategory and click "Add URL". So if you have a Python site that you'd like listed, by all means go there and submit it. Of course you can also submit commercial sites. That's the best and cheapest advertisement you can get for your Python modules, articles, tools and Python-related commercial-products :-)) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mlh at idi.ntnu.no Sat Oct 27 14:54:36 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 27 Oct 2001 20:54:36 +0200 Subject: DOM oddity? Message-ID: <9revtc$eha$1@tyfon.itea.ntnu.no> >From the xml.dom documentation[1]: prefix The part of the tagName preceding the colon if there is one, else the empty string. The value is a string, or None Under what circumstances can the prefix be None (as opposed to the empty string)? [1] http://www.python.org/doc/current/lib/dom-node-objects.html -- Magnus Lie Hetland http://hetland.org From jds at iti-oh.com Mon Oct 1 16:28:27 2001 From: jds at iti-oh.com (JDS) Date: 1 Oct 2001 13:28:27 -0700 Subject: Python Server Java Client problem with OmniOrb Message-ID: <6b2d6822.0110011228.291e84b5@posting.google.com> Hi: I am trying to run a simple Hello World program with OmniNames as the name server on NT. I can launch the naming service and bind the Server to it. In the client, if I use the IOR for the HelloServant, I don't have any problem: -------------- ORB orb = ORB.init(args, null); String ior = args[0]; org.omg.CORBA.Object obj = orb.string_to_object(ior); HelloApp.Hello helloRef = HelloHelper.narrow(obj); String hel = helloRef.sayHello(); System.out.println(hel); -------------- However if I try to do the same by getting the IOR for the Root and going down from there, I get errors while running as follows: --------------- ORB orb = ORB.init(args, null); String ior = args[0]; org.omg.CORBA.Object obj = orb.string_to_object(ior); // ERROR NamingContext ncRef = NamingContextHelper.narrow(obj); NameComponent nc = new NameComponent("Hello", ""); NameComponent path[] = {nc}; Hello helloRef = HelloHelper.narrow(ncRef.resolve(path)); String Hello = helloRef.sayHello(); System.out.println(Hello); ERROR : java.lang.ArrayIndexOutOfBoundsException java.lang.ArrayIndexOutOfBoundsException at com.sun.corba.se.internal.util.Utility.bytesToInt(Unknown Source) at com.sun.corba.se.internal.iiop.CDRInputStream.read_Object(Unknown Sou rce) at com.sun.corba.se.internal.iiop.CDRInputStream.read_Object(Unknown Sou rce) at com.sun.corba.se.internal.corba.ORB.string_to_object(Unknown Source) at HelloClient3.main(HelloClient3.java:18) --------------- The IOR that I give at the commandline is the one I get when I start omniNames using omniNames -start 10000. Root Context is IOR:010000002b00000049444c3a6f6d672e6f72672f436f734e616d696e672f 4e616d696e67436f6e746578744578743a312e300000010000000000000027000000010100000e00 00003139382e33302e39362e3231300010270b0000004e616d6553657276696365 Questions: Q1. Why do I get the above errors? Q2. How can I get my Java Client to always get the proper IOR for the Naming Service when I start it up (using the system environment) Q3. If I am able to get the client to get the root object properly, can I replace the orb.string_to_object() call by: org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); Thanks, JDS. jds at iti-oh.com From bfg10k at 21cn.com Sun Oct 21 03:51:31 2001 From: bfg10k at 21cn.com (Felix) Date: 21 Oct 2001 15:51:31 +0800 Subject: the "-u" argument Message-ID: hi, every one. i currently have Python 2.1.1 installed on my windows2000 machine, and i'm really confused by the "-u" argument. when i use "python -u" to start the interpreter, every time i hit "ENTER" the interpreter always produce an error message like below. >>> File "", line 1 ^ SyntaxError: invalid syntax but i didn't type any statement (thus there can't be any SyntaxError). does anybody know why this happens? From sholden at holdenweb.com Mon Oct 8 05:04:34 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 8 Oct 2001 05:04:34 -0400 Subject: bound member functions ? References: <9proou$rsh$04$1@news.t-online.com> Message-ID: "Achim Domma" wrote ... > Hi, > > I have tried the following code : > > --- code -------------------------- > class Dummy: > def __init__(self,val): > self.val = val > > def mult(self,fac): > return self.val * fac > > > obj = Dummy(5) > mult = obj.mult > print mult(5) > ------------------------------------ > > The script prins 25 as I expected. If I change now the last three lines to > > --- code --------------------------- > ... > mult = Dummy(7).mult > print mult(5) > ------------------------------------- > > I still get 35. What's about reference counting in this case ? Is there a > refernce hidden in mult which keeps 'Dummy(7)' alive ? Can I be sure, that > the object constructed by Dummy(7) is not destroyed after this line ? > Yes. The reference to the bound method will keep the object around as long as you need it. regards Steve -- http://www.holdenweb.com/ From chrishbarker at home.net Fri Oct 19 14:11:53 2001 From: chrishbarker at home.net (Chris Barker) Date: Fri, 19 Oct 2001 11:11:53 -0700 Subject: global variables References: <9q6njs$17s4$1@f1node01.rhrz.uni-bonn.de> <3bd05cb1$1@news.mt.net.mk> Message-ID: <3BD06CE9.11DE1E74@home.net> ?????? ?. wrote: > > I?m experiencing a little problem due to my > > poor understanding of the way python handles > > global variables. Basically the problem is the following > > I have a programm with several variables which > > I would like to access globaly. > > var=0 > def example_function(??) > global var > var=var+1 > (function definition) > > print example_function(10) You'll get a lot more help here if you post code that is as clse to functional as possible, so we can see what you mean. Do you want something like this? >>> var = 0 >>> def function(n): ... global var ... var = var + n ... return var ... >>> >>> function(3) 3 >>> function(3) 6 >>> >>> function(3) 9 >>> function(3) 12 >>> print var 12 As you can see, the same var is used in all function calls, and the main namespace. Keep in mind, however, that in Python, "global" means global to a module, not the the whole program. This is a good thing, because you wouldn't want a module you import, that you didn't write, to mess with your global variables. If you have some data that you want visible to all parts of your program, you can put them all in a module (call it global_vars.py or something), and then you can do a: import global_vars and access the variables with: global_vars.var1 global_vars.var2 etc. You could also put them in a class it you want. Hope this helps, if it doesn't you need to be more clear about waht you want to do. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From logiplexsoftware at earthlink.net Thu Oct 25 13:45:58 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 25 Oct 2001 10:45:58 -0700 Subject: smtp In-Reply-To: <9r925q$863$1@verence.demon.co.uk> References: <9r925q$863$1@verence.demon.co.uk> Message-ID: <01102510455803.26379@logiplex1.logiplex.net> On Thursday 25 October 2001 05:56, Paul Wright wrote: > The safest thing to do would be to ask the user for their mail server, > or extract it from the registry under Windows (I bet Outlook Express > stores it somewhere). Yeah, I was just trying to avoid this =( -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From sholden at holdenweb.com Tue Oct 23 12:51:41 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 23 Oct 2001 12:51:41 -0400 Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> <46gB7.151079$5A3.52079649@news1.rdc2.pa.home.com> Message-ID: "Terry Reedy" wrote in message news:46gB7.151079$5A3.52079649 at news1.rdc2.pa.home.com... > > "Stephen" wrote in message > news:97ae44ee.0110230529.5c33dd83 at posting.google.com... > > > > I'm developing a catalog application (storing its data in a > > > > relational database), where catalog entries are categorized > > > > by one or more categories/subcategories. > > From the above and your example catagories, I mistakenly assumed that > you wanted to store relational data in your relational database, and > described how to do that. Instead, it seems, you want to simulate a > dynamically adjustable hierarchical database using an RDBM as the data > manager behind the scenes. > > > > > It would be nice to have "unlimited" levels of subcategories > ... > > Thank you for the advice, Terry. Sorry if I'm being obstinate, > > but I think the problem is a little less simplistic than it first > > appears. > > Definitely (and wanting a solution to your actual problem, now better > explaned, is not really being obstinate). > > > Let's look at the everyday addressbook in Act! or Outlook ? > > I'm not familiar with either, or any similar programs. My closest > point of reference is the Windows registry. Otherwise, my experience > is 'limited' to static schema (from users viewpoint) relational > databases. > > > How would you create unlimited levels of categorisation > > and unlimited numbers of subcategories ? > > Interesting question. To say much more, I'd need more specification. > Such as, do you want to do search and selection with the RDBM (mostly > off the disk) or with Python (possibly in memory)? If with the RDBM, > I think my original comment stands: if you want to efficiently (and > scalably) search and retrieve on any level of the hierachy, then you > mush explicitly store each level with each item. An alternative would > be an expandable tree index structure written, in this case, in > Python. > This is a classic SQL problem, which most often manifests itself in bill-of-materials processing in which parts are components of other parts, and so on down to many levels. One reference to solutions can be found towards the end of http://www.dbmsmag.com/9603d06.html It's one of those problems that has an "obvious" solution, which is very non-obvious until you see it. regards Steve -- http://www.holdenweb.com/ From arigo at ulb.ac.be Thu Oct 11 07:10:52 2001 From: arigo at ulb.ac.be (Armin Rigo) Date: Thu, 11 Oct 2001 13:10:52 +0200 Subject: Psyco Specializing Compiler In-Reply-To: References: <3bc4d2e4$0$36473$ba620e4c@news.skynet.be> Message-ID: Hello Terry, On Thu, 11 Oct 2001, Terry Reedy wrote: > An interesting project. If I understand properly, you are dynamically > compiling small chunks of PyCode to machine code according to the > actual run-time type of the values involved in the chunk. That's only part of the story. The specialization can actually occur on anything, not only on the type of the Python objects --- althought it will probably be the most common case. An example of specialization over something else would be when using constants; e.g. in code like 'x=1; x+=2' the addition is performed at compile-time, because 'x+=2' can be specialized for the only case that might occur, that is, when 'x' is currently equal to '1'. > You say that your system saves the compiled machine code for a > function, after the function exits, for later reuse. Are the saved > chunks tagged with the specific types used in the compilation, so the > the system will recompile a function if/when entered with different > types? Yes, that's how we can think about it, althought more general than just on types. For example in a function call, say 'f(x)', Psyco can use the current specializations of 'x' to recompile 'f'. If we know that 'x', say, is an int, look for a version of 'f' specialized for ints. If we know that 'x' is zero, 'f(x)' can be recompiled by knowing that the argument will be exactly '0'. This means one of the big benefits of inlining in C -- constant folding -- is also available. Interestingly enough, we have this benefit without the drawback of code explosion, because several calls to 'f(0)' can still call the same code. Removing the overhead of the 'call' instruction itself could be done later, e.g. by tagging which blocks of code are small and self-contained enough for inlining by copy. > While aiming for completeness is good, speeding up just arithmetic > functions would be an important contribution. You might consider > making explicit assumptions that programmers using your system do not > pathologically rebind variables. For instance, tail recursion > elimination requires that the name of the recursing function not be > rebound to anything else during the recursion. I will certainly make such assumptions at first; for completeness, pathological rebinds could be detected e.g. by enhancing dictionaries to signal when they are modified, letting Psyco know that the compiled code has become invalid. Such solutions would not slow down at all the generated code in the common case. It would also let the value of global constants be inlined; if a global variable's value changes later, we invalidate the produced code and mark the variable as run-time instead of compile-time-known. Armin From gbeasley at tsa.ac.za Tue Oct 23 07:41:13 2001 From: gbeasley at tsa.ac.za (Grant Beasley) Date: Tue, 23 Oct 2001 13:41:13 +0200 Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> Message-ID: <9r3l09$9uc$1@ctb-nnrp1.saix.net> Something I've used for developing threaded discussion boards might help you here, but I'm not sure if it's more or less efficient, and can't truly go to great depths (without sacrificing space). Assign each category a 2-digit code (if you need more categories, increase this to 3 or 4 digits). This code need only be unique on it's level. It does not need to be completely unique. Eg, ByLocation = '01', BySeverity = '02', Africa = '01', Europe = '02', Mozambique = '01', South Africa = '02', Critical = '01', Death='01', etc. .... Then when assigning the category code to your record, concatenate all codes together, thus South Africa = '010102' (ByLocation+Africa+SouthAfrica). Death = '020101' (BySeverity+Critical+Death). As you can see, your codes could get pretty long, but the nice part comes in selecting stuff in a category. To find out if a particular record is in a particular category, test whether RecordCategorisationID.startswith(CategoryID). i.e Comparing a record with ID '010102' (i.e South Africa), to Africa - '0101' would be true, to BySeverity '02', it would be false. I think you get the idea. I have this implemented with my id's as strings, but it would be far more efficient doing this by converting to binary, etc. The same principle applies, but you'll be dealing with numbers. I haven't even considered the maths, but I would imagine it could be made to be fairly efficient. HTH Cheers Grant Beasley "Stephen" wrote in message news:97ae44ee.0110221318.6eec382d at posting.google.com... > Scratching my head over what I thought was a simple problem. > > I'm developing a catalog application (storing its data in a > relational database), where catalog entries are categorized > by one or more categories/subcategories. It would be nice to > have "unlimited" levels of subcategories and that seemed > simple enough ~ "Use a parent/child" I hear you say ~ and that's > what I did but I've since found it's not very flexible further > down the line. > > Let me demonstrate with some example categories/subcategories > which we place in a category tree, giving each node a unique ID. > The root node is deemed to have node ID zero (0). > > Root -- 1. ByLocation --- 3. Africa --- 4. Mozambique > --- 6. SouthAfrica > --- 5. Europe --- 9. Portugal > -- 2. BySeverity --- 7. Critical --- 8. Death > --- 11. Handicap > --- 10. Moderate--- > > This structure can be stored in a single table of a database. > > Parent_ID Category_ID Category_Label > 0 1 ByLocation > 0 2 BySeverity > 1 3 Africa > 3 4 Mozambique > 1 5 Europe > 3 6 SouthAfrica > 2 7 Critical > 7 8 Death > 5 9 Portugal > etc > > > So far so good. Cataloged items/illnesses record their > categories in a one-to-many table. For example, an illness > with categories "4" and "8" occurs in Mozambique and can > result in death. > > This appears scalable. > > Likewise you can easily select all illnesses occuring in > Portugal using a JOIN and filtering category ID "9". > > So what's the problem ? > > The problem arises if one asks "Which illnesses occur > in Africa ?". First, one has to find all category IDs > for which this is true. This may be easy for the example > above but imagine if the category ("Africa") has a sub- > -category for each and every country then further > subcategorized by major cities. To find all possible > categories, one would have to do a recursive select > finding each subscategory with the appropriate "parent ID". > This does not seem like a very efficient method. > > Faced with this, it seems like a more dumbed down solution > is more appropriate, sacrificing scalability for speed. > > However, I can't help but feel I've overlooked something > more simple and hence I'm seeking a nudge in the right > direction. Thanking you in advance. > > Stephen. From barry at zope.com Sat Oct 20 23:10:10 2001 From: barry at zope.com (Barry A. Warsaw) Date: Sat, 20 Oct 2001 23:10:10 -0400 Subject: Smtplib module References: <3BD20BAE.6346.7693E0@localhost> <9qscfm.3vv746r.1@kserver.org> <20011021041105.A3163@lilith.hqd-internal> Message-ID: <15314.15506.455871.871631@anthem.wooz.org> >>>>> "GH" == Gerhard H?ring writes: GH> you're of course right. My thinking was too complicated, GH> again. But you'll only recognize if the local delivery to the GH> mail server failed, not when relayed mail's delivery fails. I GH> did never find the local failures particularly interesting, GH> because I usually know which users exist on my SMTP server in GH> advance. GH> I was thinking about the general problem of finding out if an GH> email address exists and if mails get delivered. This is of GH> course much more complex, and AFAIK not solvable in the GH> general case. If you want to find out whether an email has been read, you can try setting the Return-Receipt-To: header, but this confirmation will happen asynchronously to the SMTP transaction, and requires cooperation with the recipient's mail reader (MUA). There are a few other headers that are MUA specific, including X-Confirm-Reading-To: and X-pmrqc . As for error messages during the SMTP transaction, it all depends on whether you're talking to a local smtpd which does the final delivery, or you're talking to a remote smtpd on the MX of the recipient. In the former case, you likely won't get anything other than an immediate successful return, unless there's some misconfiguration or other problem with your local MTA. Some MTAs also have a "synchronous" mode where your smtplib.py client talks to your local MTA, and it doesn't return until it's talked to the intended remote MTA. Then sometimes any error condition the remote receives will be forwarded to your local MTA, which forwards the error to your smtplib.py client. A huge downside with this approach is that it'll take you a long time to work through a big list of recipients since any slow remote MTAs will clog the whole works. You could also connect to the remote MTA yourself directly via smtplib.py, but then you've got similar problems as the synchronous approach above. Then again, you could do some asyncore (select-based) or thread-based approach to mitigate any per-address delays. Once you've gone down that route though, you're 1/2 way to writing your own Python based MTA . For asynchronous deliveries, you're stuck doing VERP or bounce parsing. For the latter, take a look at Mailman's recipes, which could be split out without too much work. Mailman will eventually support VERP, but it requires cooperation with your receiving MTA, so I'm not sure it'll make it into MM2.1. clear-as-fog-ly y'rs, -Barry From phr-n2001d at nightsong.com Tue Oct 9 15:04:03 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 12:04:03 -0700 Subject: Python is better than free (was Re: GNU wars again) References: <200110030312.f933COK01047@smtp2.idir.net> <9ptagr$m6c$1@panix3.panix.com> Message-ID: <7xr8sc63fg.fsf@ruckus.brouhaha.com> grante at visi.com (Grant Edwards) writes: > > This message is free software; you can redistribute it and/or > > modify it under the terms of the GNU General Public License > > as published by the Free Software Foundation; either version 2 > > of the License, or (at your option) any later version. > > > > My post is a waste of space? > > As opposed to the valuable content in that last bit? Indeed. Newsgroup posts should use the GFDL (www.gnu.org/licenses/fdl.html) rather than the GPL ;-). From tjreedy at home.com Sun Oct 28 01:35:02 2001 From: tjreedy at home.com (Terry Reedy) Date: Sun, 28 Oct 2001 06:35:02 GMT Subject: binary search tress using classes References: Message-ID: wrote in message news:mailman.1004246848.30973.python-list at python.org... > Hi, > I was wondering if anyone had a binary search tree module I could > use? I need to write a program that counts the number of occurrences > of each word in a file, and outputs the word and corresponding counts > alphabetically. For example, if input is The way to do this in Python is with a dictionary. Without being fancy about the definition of 'word', you need 10 lines or less for the whole program. I believe I've seen the code posted. Using classes and 'modularity' is way overkill. Terry J. Reedy From Aristotle_00 at yahoo.com Tue Oct 16 16:39:25 2001 From: Aristotle_00 at yahoo.com (Mark) Date: 16 Oct 2001 13:39:25 -0700 Subject: Number of args in a function Message-ID: <12e3779b.0110161239.7e71bb13@posting.google.com> Hello all, I would like to find either a built-in function or a method of making my own function to answer the following question: Given a function f, how many arguments does it take? I know there is some subtlety here but I'll be happy with just the number of formal arguments. So, if I had nargs(abs) I would get a "1" and if I had nargs(add) I would get a "2". (assuming I had imported the functional versions from "operator") The closest thing I've been able to come up with is parsing the TypeException error that is raised when you call a function with the wrong number of arguments. Thanks all. Regards, Mark From sholden at holdenweb.com Fri Oct 12 20:09:56 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 12 Oct 2001 20:09:56 -0400 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <7xsncpxxc6.fsf@ruckus.brouhaha.com> <1002866005.11653@yabetcha.drizzle.com> <9q7spi$9q6$1@slb7.atl.mindspring.net> Message-ID: <0ALx7.32688$I83.526633@atlpnn01.usenetserver.com> "Jyrinx" wrote ... > Erm, I'm hardly a seasoned hacker, but if I may toss in a few cents ... > > > | n = compute_number_of_items() > > | for i in range(n): > > | try: process_an_item(items[i]) > > | except: break > > | update_database('number of items processed = ' % i) > [ summary of prior discussion ] > > I like Python's for loop, "range()" idiom and all. In any case, I should > think the above code would be clearer anyway with an explicit check for an > empty list: > > n = compute_number_of_items() > if n == 0: > update_database('no items processed') > else: > for i in range(n): > try: process_an_item(items[i]) > except: break > update_database('number of items processed = ' % i) # (Hmm? I > thought the % operator was supposed to be used with a string and a > dictionary? Not that # I would know what I'm talking about ... :-) > The left-hand operand is always a string. If it only contains one format item, the right-hand operand can either be a simple data item or a one-element tuple (confusingly referred to as a "singleton" in the Python documentation). If the format items in the string have parenthesised names in them then the right-hand operand is expected to be a mapping (i.e. to have a __getattr__() method), and the parenthesised portions are passed as attribute names to __getattr__(). > Or, if you didn't want to make an extra branch and didn't want the > uninitialized-i problem, why not just initialize it to 0 before the loop? > Slightly bug-prone, but not a bad solution. regards Steve -- http://www.holdenweb.com/ From tim.one at home.com Sun Oct 14 22:43:45 2001 From: tim.one at home.com (Tim Peters) Date: Sun, 14 Oct 2001 22:43:45 -0400 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) In-Reply-To: Message-ID: [DeepBlue] > Much better: > x = if e1 then (e2) else (e3) You're apparently responding to an edited reply, and didn't read the thread from its start: surrounding parens are required else you don't get this form of conditional expression at all. It's not a question of whether to require surrounding parens or not; the latter isn't an option, due to the limitations of one-token lookahead parsing (read the thread from the start). > note that (e2) and (e3) stand for any operation: e1, e2 and e3 in the original are any expressions (formally, 'test' in the Python grammar). I don't know what "operation" means to you, or why you think adding some parentheses *could* make a semantic difference. In the formal syntax, the production for atom changes from atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+ to atom: '(' ([testlist] | cond_expr) ')' | ... [the rest is unchanged] cond_expr: 'if' test 'else' test 'then' test > The problem with: x = (if e1 then e2 else e3) + 1 # cool > is that it lacks potential of generalization. Generalization to what? Please be specific. Stuff like x = (if a+b/sqrt(3) then 3**f(5, 3)- 12 else ",".join(list) + ":\n") is fine. If you *want* to stick extra parens around the e2 and e3 expressions, that's fine too, but not required. > x = if e1 then (e2) else (e3) > does give the user more freedom. Sorry, I can't see how. >> x = (if e1 then e2 else e3 + 1) # cool > but not clear. Because? It's no more or less general than, e.g., x = e1 and e2 today, of which, e.g., x = y + 1 or z + 1 is a specific instance. >> x = if e1 then e2 else e3 # SyntaxError > no reason for error Read the thread. > ... [more much the same snipped] ... > with my idea: > x = (if (if e1 then (e2) else (e3)) then (e4) else (e5)) This is legit under the proposal. > or > x = if (if e1 then (e2) else (e3)) then (e4) else (e5) But this isn't. > should be equivalent. > If the original posting If you haven't even read the first msg in this thread alone, I shudder to imagine what "original" means to you . > passes Python will have its first confusing moment. > x = if e1 then (e2) else (e3) > and > x = (if e1 then (e2) else (e3)) > should be equivalent and they preserve clarity. The latter form would be accepted, but not the former (and the former cannot be accepted, which is a question of parser technology, not of taste). From Samschul at pacbell.net Wed Oct 3 20:37:37 2001 From: Samschul at pacbell.net (Samuel Schulenburg) Date: 3 Oct 2001 17:37:37 -0700 Subject: "self" vs other names References: Message-ID: grante at visi.com (Grant Edwards) wrote in message news:... > In article , Ignacio Vazquez-Abrams wrote: > >On Wed, 3 Oct 2001, Tim Hammerquist wrote: > > > >> What would the world have been like if CP/M had won over (PC|MS)-DOS? > > > >Not that much different; AFAIK MS-DOS was based on some of the principles of > >CP/M (8.3 filename, etc.). > > PC-DOS was an out-and-out copy of CP/M. The layout of FCBs was the same, > the methods to call BIOS were the same, the layout of executable file > headers was the same... As I recall CPM was more flexable with memory allocation than DOS. It's been a long time ( Twentyone years),but CPM used a jump table to access its boot sequence. DOS had that dumb 640 K limit. Remember BIll Gates quote "640K is more memory than anyone needs", or somthing like that. Sam Schulenburg From howard at eegsoftware.com Sat Oct 13 00:08:20 2001 From: howard at eegsoftware.com (howard at eegsoftware.com) Date: Sat, 13 Oct 2001 04:08:20 GMT Subject: sharing time between embedded python and c code Message-ID: <3bc7bcc0.12082598@news-server.socal.rr.com> I would like to embed python into a (windows) c-program and spend some time in the python interpreter (processing some simple gui updates) and some time in my c program (handling some DirectX calls and such). I seem to be stuck on how to do this. I have embedded the Python interpreter, can import and run a program, and return (having a .mainloop in the python code to pump things). However, what I would LIKE to do is 1. Load the python code at initialization time. Loop (at really long time) a. Periodically call something in the Python code to perform ".updates" . b. Periodically call the verklempt Windows/DirectX routines for the high speed part of things. I expect to run several threads: One for my dedicated DirectX updates One for the Python calls. I must be missing something since I can't figure out how to call a specific function in the interpreter environment without receiving an error. Any ideas? Thanks Howard Lightstone EEGSoftware howard at eegsoftware.com From cliechti at gmx.net Tue Oct 2 15:44:43 2001 From: cliechti at gmx.net (Chris Liechti) Date: 2 Oct 2001 21:44:43 +0200 Subject: comparing interpreter speed on two platforms Message-ID: i have run a simple benchmark on two systems: a standard PC: 1. PentiumPro 200Mhz (400BogoMips) Debian Linux 2.2 (Kernel 2.2-17) 64M RAM and an embedded system: 2. PowerPC ~60Mhz (68BogoMips) HardHat Linux 2.0 (Kernel 2.4) 16MB RAM the speed difference based on BogoMips (which are displayed when Linux is booted) is about 6.2. when i compare the results of the benchmark programm which is entirely written in python i get differences of factor 20. both target run Python 2.1.1, compiled from the same tarball with "./configure;make;make install", both compiled with GCC. why is the python programm that much slower than the BogoMips comparison would imply? (ideas: maybe "configure" finds some speedy modules on one system but not on the other, maybe the GCC compiler is not that efficient on PPC? its not the memory. the embedded system has more than 3MB free during the tests) the benchmark tested object instatiation, object identity, value assignment to a list, function calls and some math, every operation in a separate test with separate results (execution times, measured with "time.clock()"), performing 10000 loops. any ideas would be apreciated, as my real application fails to run on the embedded system because its too slow, which is sad. (i have 20 Byte packets of data on the serial line which arrive 4 times a second, that is given and cannot be changed) Chris -- Chris From phr-n2001d at nightsong.com Mon Oct 15 20:27:19 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 15 Oct 2001 17:27:19 -0700 Subject: FW: [Python-Dev] conditional expressions? References: <9qfu1p$iei$1@newshost.accu.uu.nl> Message-ID: <7xitdg4efs.fsf@ruckus.brouhaha.com> m.faassen at vet.uu.nl (Martijn Faassen) writes: > * list comprehensions are signalled by the fairly clear [ and ]. > Conditional expressions use the already fairly strongly > overloaded ( and ). Of course I guess they wouldn't really > overload them further, but.. A conditional expression analogy to list comprehensions would be x = (a if b else c) rather than x = if a then b else c From emile at fenx.com Mon Oct 8 06:34:19 2001 From: emile at fenx.com (Emile van Sebille) Date: Mon, 8 Oct 2001 03:34:19 -0700 Subject: DNS module or how to ... ? References: <3BC16D75.566E9502@stroeder.com> Message-ID: <9prvo5$kaqhn$1@ID-11957.news.dfncis.de> "Michael Str?der" wrote in message news:3BC16D75.566E9502 at stroeder.com... > A wrote: > > > > Is there a DNS module available for Python ? > > http://pydns.sourceforge.net > I don't know what's going on, but I get some brain-dead pages following this link. This works better for me: http://sourceforge.net/projects/pydns/ -- Emile van Sebille emile at fenx.com From skip at pobox.com Wed Oct 10 20:54:02 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 10 Oct 2001 19:54:02 -0500 Subject: Python questions -> compiler and datatypes etc In-Reply-To: <01101110395417.11044@ike> References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> <7xr8sbc993.fsf@ruckus.brouhaha.com> <01101110395417.11044@ike> Message-ID: <15300.60842.366180.693270@beluga.mojam.com> Richard> ... and as far as I recall there is an ongoing effort right Richard> now. I just can't find the reference at the moment. Try: http://homepages.ulb.ac.be/~arigo/psyco/ Only handles ints at the moment... -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From robin at jessikat.fsnet.co.uk Fri Oct 26 07:01:51 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 26 Oct 2001 12:01:51 +0100 Subject: PIL - cannot get jpeg decoder to work References: Message-ID: have you got libjpeg.so somewhere in /usr/lib or /usr/local/lib? -- Robin Becker From inigoserna at terra.es Tue Oct 2 18:42:47 2001 From: inigoserna at terra.es (=?ISO-8859-1?Q?I=F1igo?= Serna) Date: 03 Oct 2001 00:42:47 +0200 Subject: [?] sorting files by modification time. In-Reply-To: <9pd5me$lo1@dispatch.concentric.net> References: <9pd5me$lo1@dispatch.concentric.net> Message-ID: <1002062567.13028.15.camel@lethe.infernus.org> Hi, En mar, 2001-10-02 a 21:48, Julius Welby escribi?: > Get a listing of the file names using os.listdir for the folder, then you > can do something like: > > for name in filenames: > path = os.path.join(folder, name) > modified = os.path.getmtime(path) > statdict[modified] = name > keylist = statdict.keys() No, you can't do this. If several files have the same modification time, last one would overwrite previous ones. filenames = os.listdir(folder) statdict = {} for name in filenames: path = os.path.join(folder, name) modified = os.path.getmtime(path) while statdict.has_key(modified): # this is the trick: modified += 0.1 # do not allow repeated keys statdict[modified] = name keylist = statdict.keys() keylist.sort() filenames_sorted_bymtime = [] for k in keylist: filenames_sorted_bymtime.append(statdict[k]) I use this in lfm (http://www.terra.es/personal7/inigoserna/lfm). Best regards, I?igo Serna From phd at phd.pp.ru Tue Oct 16 12:07:45 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 16 Oct 2001 20:07:45 +0400 Subject: Python, Unix sendmail, and multiple recipients In-Reply-To: <81F59ACE9063D511A5BB0002B328D226511596@il93exm20.css.mot.com>; from Randy.L.Kemp@motorola.com on Tue, Oct 16, 2001 at 10:58:49AM -0500 References: <81F59ACE9063D511A5BB0002B328D226511596@il93exm20.css.mot.com> Message-ID: <20011016200745.P768@phd.pp.ru> On Tue, Oct 16, 2001 at 10:58:49AM -0500, Kemp Randy-W18971 wrote: > Can anyone give me an example of how to invoke the Unix sendmail in Python, > and send an email message to more then one recipient (two people, for > example)? pipe = os.popen("/usr/sbin/sendmail me at my.host you at your.other.host", 'w') pipe.write("""To: public at shmablic Subject: Test Body comes here """) pipe.close() Beware of shell metacharacters in user names! (popen uses shell) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From robin at jessikat.fsnet.co.uk Tue Oct 23 19:46:59 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 24 Oct 2001 00:46:59 +0100 Subject: string object methods vs string module functions Message-ID: In a mailing to another list Steve Alexander says > Various modules in Zope that used to use string functions a lot have > recently been converted to use string methods, and there was a noticible > speedup in performance as measured by benchmarks / testsuites. I would have thought this to be a minor speedup as the main work must still be in C, but have others any thoughts/experiences on this? A function which ReportLab uses a lot is join so my primitive hack test seems to bear out my intuition as join performance seems very similar. Clearly I'm not actually testing this properly, but are there any good disambiguating tests? >>> from time import time >>> from string import join >>> def doit0(L,n=10000): ... t0=time() ... for i in xrange(n): ... x=join(L,'') ... print '%.2f' % (time()-t0) ... >>> def doit1(L,n=10000): ... t0=time() ... for i in xrange(n): ... x=''.join(L) ... print '%.2f' % (time()-t0) ... >>> L=[chr(i) for i in xrange(256)] >>> doit0(L) 0.28 >>> doit1(L) 0.28 >>> -- Robin Becker From salemail at dial.pipex.com Thu Oct 18 03:45:25 2001 From: salemail at dial.pipex.com (Kevin D) Date: 18 Oct 2001 00:45:25 -0700 Subject: Conditional Expressions don't solve the problem References: Message-ID: Hi Christoper. com-nospam at ccraig.org (Christopher A. Craig) wrote in message news:... > I personnally don't like your suggestion as they are mind numbingly ugly Can I assume that's IYHO ? Please elucidate on what, exactly, numbs your mind about them. I've tried to reason out what I thought were the issues that cause this thread to appear periodically (modulo "it isn't like C") and suggest syntax that fixes those problems. Can we at least agree that the issues I listed _are_ problems ? If not, please give reasons. > I wish Python had initially adopted > > do: > > until > > > Which is, of course, behaves identically to > > while 1: > > if : break > > > but is prettier. I don't see what _problem_ this is addressing. You're just substituting words. I was actually trying to _identify readability issues_ with this construct and fix them. > Additionally I think that the present system is not that hard to adapt to. Remembering to prefix all your string variables with '$' and all your integer variables with '%' isn't "hard to adapt to". Plenty of BASIC newbies did. That doesn't mean that there aren't better ways of doing it :) You seem to think I'm advocating change for change's sake. I'm not. I was trying to move the conversation away from the issue of "what 'C' does and whether Python should do that too" and towards consideration of the root issues that cause people to request "what C does" so often because that's the only solution they see. Regards, Kev. From newgene at bigfoot.com Mon Oct 1 17:45:59 2001 From: newgene at bigfoot.com (newgene) Date: 1 Oct 2001 14:45:59 -0700 Subject: list.append problem? Message-ID: I am a newer of python. I have a problem like this code: >>> a=b=c=[] >>> a.append(1) >>> b.append(2) >>> c.append(3) >>> a [1, 2, 3] >>> b [1, 2, 3] >>> c [1, 2, 3] a,b,c become the same, although append method applied seperately. It's really strange and unreasonable. My python is ActivePython Build 210 running on WinNT. Thank you Chunlei From jbell at iinet.net.au Sat Oct 13 00:05:37 2001 From: jbell at iinet.net.au (John Bell) Date: Sat, 13 Oct 2001 12:05:37 +0800 Subject: PostgreSQL Interface Query Message-ID: <3BC7BD91.A604728C@iinet.net.au> I have been evaluating various Python interfaces to PostgreSQL. So far as I've been able to determine the options are PygreSQL (packaged with PostgreSQL), PoPy, psycopg and a new entrant, pypgsql. I am leaning towards pypgsql (available from SourceForge) based on an comparitive assessment of functionality only. However, as pypgsql is just under a year old and I've never heard it mentioned on any major Python or PostgreSQL forum before I am somewhat concerned regarding its stability. I would be very interrested in comments from anyone with experience of the pypgsql package. Thanks in Advance, From phr-n2001d at nightsong.com Wed Oct 31 18:16:30 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 31 Oct 2001 15:16:30 -0800 Subject: crypt libraries References: <3BE07D46.7080502@shaw.ca> Message-ID: <7x1yjjtn75.fsf@ruckus.brouhaha.com> Peter Preeper writes: > Are there any crypt libraries for python? I am looking for symmetric > type of encryption. There's quite a few, look in vaults of parnassus. http://www.nightsong.com/phr/python/crypto.txt describes one I'm working on, if of any interest. I haven't messed with it in a while but want to get back to it soon. From richard at bizarsoftware.com.au Wed Oct 10 19:06:43 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Thu, 11 Oct 2001 09:06:43 +1000 Subject: Python questions -> compiler and datatypes etc In-Reply-To: <20011010100130.30712.qmail@web11208.mail.yahoo.com> References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> Message-ID: <01101109064311.11044@ike> On Wednesday 10 October 2001 17:28, Billy wrote: > Yeah, java can do the job, but so can C++... see what > I mean? Just cause it can do it doesn't mean its > practical. Java is ok for webdev (i have done a bit) > it's just tediously slow in implementing sometimes. I agree, it is. I was mostly pointing out that your statement "java is not suited for specific web development" may be construed as flamage :) > Zend Encoder (www.zend.com) takes text php code and > puts it into an intermedary format not readable by > humans. each time a script is called the interpreter > calls the encoded script. This means you can > distribute your applications without letting people > see the code. Python's bytecode is not human-readable (unless you're Tim Peters, I think). In the absence of original source, python is perfectly happy to import just the bytecode. That is, if you 1. create "foo.py" (empty file is OK) 2. python -c 'import foo' 3. rm foo.py 4. python -c 'import foo' ... will work because #4 is able to import the bytecode from foo.pyc. > I've seen various reviews, the scientific basis of > them was rather dubious but you could definately > gather a general feeling that python was slower than > java, to a reasonable extent. In general, yes. The devil is in the detail here. There are several instances where Java runs like a dog (hello, Swing) and there are similar instances where Python does (complex mathematics, not using Numeric). There are ways to get them close - using C modules in Python (eg. Numeric) or avoiding Swing like the plague :) > Compiling python is at the impossible end of the > > > scale of ease of > > implementation. There has been a lot of discussion > > about this issue on this > > list in the past. Search for "python compiler" and > > enjoy :) > > > > Python compiles to bytecode. Python's runtimes > > execute compiled bytecode. > > There are several runtimes - one of which is Java. > > The predominant one is > > written in C. > > ------------------------------------------- > > I'm unclear on your explanation here. Would I be > correct in saying that there is no compiler (source > code to machine code) for python. And that this is due > to the very complex nature of implementing such a > device. There is no compiler that takes python code an produces machine code. And you are correct, it's because of the "complex nature of implementing such a device". There have been efforts (one of them quite recent). I can't find any refrences though, sorry. > *Off topic: > I would be interested in finding out more information > on this, why can't you do it with python when people > are doing it with java? Any pointers to web resources > etc?? Do a search in the python mailing list for "python compiler". The answer is invariably "it's bloody hard". This stems from the fundamental dynamic typing of python. It's very very very hard to write a compiler when you don't know the type of the objects you're dealing with beforehand. Java knows these types, because it's statically typed. Therefore it's relatively trivial (compared to python) to write a compiler for Java. > And you say that the python interpreter takes bytecode > and executes that. Does this mean that you can use > python to compile your source code into a format which > is not readable by humans (bytecode or whatever.. > which is as reasonably reverse-engineering proof) and > distribute that bytecode (not source code) to stop > tampering and protect your commercial interests? As I mentioned above, the bytecode is not human-readable. It is possible to decode the bytecode back into something that's almost exactly the same as the original source, using a program called decompyle. This also has been discussed extensively. The end result of the discussions is that it's possible to obscure your bytecode, but it's almost impossible to do it perfectly. This is also the case with any other programming - even C or assembler is eventually still decodable (oh, the days of disassembling 68k Amiga demos to figure how people optimised their 3d routines... *ahem* I digress.) Again, search for "hiding bytecode" (or similar) in the python mailing lists. Anyone who believes that their application is safe from prying eyes and fingers obviously ignores the widespread warez distribution of cracked applications and application keys and so on. > I did do an extensive search for information on a > python compiler... all accross the web, all i found > were a few "discontinued" sites that dated back to > June 5th 1957. I never ask questions without checking > for myself first. The python mailing list is a much better place to start for searching - it's up-to-date for one thing (web searching relies on web crawlers which are notorious for being slow to update.) > I would want to use strict datatypes and generic types > to interchange speed and efficency with flexability. Then you'll be wanting to develop that speedy code in a language that allows it - use C or C++ if you're develping in C Python or Java if you're developing in Jython. > Java lets you define > int foo() > double foo() and > object foo() > > very nice for building generic classes. > > keyword args/ (*args thing <- can't quite understand > that one) can't do the same as say: > > excuse the syntax... not familiar enough with python > yet > > class foo: > #load foo from file > define foo(filename, directory) > filesystem calls etc etc... > > #load foo from database > define foo(datbasename) > connect to database etc etc...... > > or even better > #load foo from file > define foo(FileHandler fhFile) > bla bla bla > > #load foo from database > define foo(DatabaseObject database) > bla bla bla > > So what your saying is that python doesn't have the > ability to switch between this? Your mailer stuffed up your indentation there, but I think I get the gist of it. In short, the dynamically-typed way of doing the above is: class foo: def __init__(self, database=None, file=None): if database is not None: # init from database elif file is not None: # init from file else: raise ValueError, "I need a database or file to work with" _or_ the less flexible class foo: def __init__(self, data): if isinstance(data, DatabaseObject): # init from database elif isinstance(data, FileHandler): # init from file else: raise ValueError, "I need a database or file to work with" Having said that, I'd ask questions about how the code is actually structured there. The "foo" class obviously does something with some data source, be it a file or a database. It therefore has to have some handling of the interactions with the data source (above, you have read operations - does it do writing too?). Something like the following is significantly more "pythonic": class FooBase: ''' defines all the methods that operate on Foo data ''' class FooDatabase(FooBase): ''' defines interactions between a Foo and a DatabaseObject ''' class FooFile(FooBase): ''' defines interactions between a Foo and a FileHandler object ''' And then when you want to use one or the other, you'd instantiate the appropriate one - either FooDatabase(database_object) or FooFile(file_object). Another pattern to use is to go with a proxy class. Choose the interface that is most convenient and write a wrapper class for the other one. That is: class Foo: ''' perform operations on a DatabaseObject ''' class FileAsDatabaseObject: ''' accept a FileHandler and make it look like a Database Object ''' Lots of different ways you can do things :) And once you truly grok the idea of dynamic typing, you'll see there a lots more - and they all make soooo much more sense than defining foo(FileHandler fhFile) foo(DatabaseObject database) ... etc > Thanks heaps for your time, No problem, hope I've helped! Richard From info at mjais.de Tue Oct 23 12:05:58 2001 From: info at mjais.de (Markus Jais) Date: Tue, 23 Oct 2001 18:05:58 +0200 Subject: problem with pirxx References: <23891c90.0110230449.13ccde9d@posting.google.com> Message-ID: <9r44jf$rbf24$1@ID-75083.news.dfncis.de> hello thanks for your tip. this seems to be the problem. I set up LD_LIBRARY_PATH and now it works, that is, it crashes with another error, but the programm start so it seems to be an error in the test script markus Paul Boddie wrote: > "Markus Jais" wrote in message > news:... >> hello, >> I installed the latest version of pirxx on my Suse 7.1 with python 2.1 >> when I call the testscript I get the following error: >> >> $ python test.py >> Traceback (most recent call last): >> File "test.py", line 15, in ? >> from pirxx import _pirxx >> ImportError: shared object not open >> >> I am quite new to python and have never seen such an error. >> can anybody help?? > > I don't think I've ever seen that exact error, but I would suspect > that your dynamic linker can't find the _pirxx.so or _pirxxmodule.so > shared library. I'm about to check out pirxx in the next few days, so > I might be able to comment further once I've installed it. > > However, you should make sure that your LD_LIBRARY_PATH environment > variable includes the directory where such a shared library can be > found, or that your linker's configuration is set up for that > directory; at this point, it becomes more of a Linux configuration > issue, really. > > Paul From praveg.arkadi at propylon.com Tue Oct 16 12:12:42 2001 From: praveg.arkadi at propylon.com (Praveg) Date: Tue, 16 Oct 2001 17:12:42 +0100 Subject: accessing goldmine data Message-ID: <019a01c1565d$629ce040$440a11ac@PravegArkadi01> I am writing a python program for accessing goldmine database .Goldmine has GM4S32.dll with the functions for accesssing the goldmine data. I am using python's dynwin.windll module for loading the dll & accessing it's functions. Now I have loaded the dll successfully but facing problems regarding the function calls which actually accesses the database files. For example, I am trying to use--> long GMW_DS_Query( char *szSQL ) I am calling the function as-->index = obj.GMW_DS_Query(cstring('Select company from Contact1')) but getting errors regarding memory (memory could not be read)etc. I am using python21 on WIN2K. Can anybody tell me why I am getting such errors? Praveg From madsdyd at challenge.dk Mon Oct 1 07:37:39 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 13:37:39 +0200 (CEST) Subject: Problem with linking embedding C application In-Reply-To: Message-ID: On Mon, 1 Oct 2001, Olivier Deme wrote: > > I think that you may need to add at least > > -lpthread -lm -lutil > > to you ld line? > > > > I have a machine, where I need to do: > > -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm > > to be able to link with python. > > I can't believe I would have to link my application with something like pthread > if I don't use it! After all, Python is supposed to make an application > portable... Our C application is portable and needs to be shipped to a > customer. So including things like "pthread", "nsl" and the-like would break > the main reason why I decided to extend our application with some Python code. Well, it could still be portable, if you had a portable way of determing this. Among different unixs and the like, you should have no troubles. I have no idea about Windows, Macs and the like though. > > As far as it seems, it looks like it is way easier to embed TCL code in C, > rather than Python... > Sad, since I prefer Python. TCL or Perl, yes. I would prefer Python as well; perl gives me headaches, and tcl is annoying with its strings-strings-strings stuff. > > Maybe, we are missing some information. Is there a hello world type application > that would demonstrate embedding Python with C or C++? > The Python sources "Demo/embed" - the demo.c file - but, it uses a static Makefile. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk 7) Sacrifice a small animal for Good Luck (step 7 of 8 in configuring the Open Source Global File System for Linux) From emdpek at chron.com Wed Oct 31 19:06:53 2001 From: emdpek at chron.com (emdpek) Date: 31 Oct 2001 16:06:53 -0800 Subject: Python extension modules Message-ID: <7fd99f9.0110311606.7e0a5836@posting.google.com> Howdy, I am working on a Python binding to a library, and wanted to clear up some concepts involving extension modules (and, more than likely, defining a new type). I need Python objects to contain and "represent" native C structs. Is there a way to do this *without* defining a new type? For example, my C binding functions call on library functions which return pointer structs. I can't really return these back to Python, as they are not "PyObject*", and you can't, for example, convert and return a "void*" via Py_BuildValue. Or can you? My C binding, then, has to define its own struct (Python type), and one of the struct members will be a pointer to these native library structs. Python code will manipulate instances of this type, not knowing they are basically wrappers around a struct from another library... (I am hoping that train of thought makes sense. And sorry for thinking out loud.) Question about defining a new type, then. Functions (package-scoped functions not tied to a class) are declared via the PyMethodDef array, right? So, this is where an instance constructor might go? static PyMethodDef MyNew_functions[] = { { "MyNew", MyNew, METH_VARARGS }, {NULL, NULL} }; Now, Python can: "instance = MyNew()" Instance methods are declared differently, and in the following two different ways: static PyTypeObject MyNewType = { PyObject_HEAD_INIT(NULL) 0, "MyNew", sizeof(MyNewObject), 0, (destructor)MyNew_die, /*tp_dealloc*/ /* etc... */ }; But, to add behavior outside of the methods defined in object.h's PyTypeObject, you must go through "getattr" methods. For example: static PyMethodDef MyNew_methods[] = { {"method", (PyCFunction)MyNew_method, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; static PyObject* MyNew_getattr(MyNew *self, char *name) { return Py_FindMethod(MyNew_methods, (PyObject *)self, name); } So, now you can: "rv = instance.method()" Is this (use of "getattr" method, which calls Py_FindMethod) the accepted convention? (I can't remember which module I stole this idea from.) Am I on the right track? Thanks in advance... emdpek P.S. There is perhaps a train-of-thought missing from the Extending tutorial that I lost hair figuring out this morning. I would be more than happy to offer possible improvements, if there is interest... From merkosh at hadiko.de Wed Oct 3 08:31:44 2001 From: merkosh at hadiko.de (Uwe Mayer) Date: Wed, 3 Oct 2001 14:31:44 +0200 Subject: Tkinter: button (beginner question) Message-ID: hi, the following was supposed to display a Tkinter button with an image on it (i.e for a toolbar): -- from Tkinter import * root = Tk() b = Button(root,image='test.bmp') b.pack() -- where 'test.bmp' is an image in the same folder python interactive shell was started. however, pyhton aborts on the 3rd line with: -- >>> b = Button(root,image='x1.xbm') Traceback (most recent call last): File "", line 1, in ? File "C:\Python21\lib\lib-tk\Tkinter.py", line 1817, in __init__ Widget.__init__(self, master, 'button', cnf, kw) File "C:\Python21\lib\lib-tk\Tkinter.py", line 1756, in __init__ self.tk.call( TclError: image "x1.xbm" doesn't exist -- has anyone an idea what is going wrong here? for the reference: i am running python 2.1.1 on windows 2k. i read the Tkinter manual examples and i don't quite know why all Button, Canvas, etc. are put into a Frame widget rather than letting them stay in the "root = Tk()" widget, or Toplevel widget (-> Dialog window example). Where's the difference? Thanx in advance for comments. Yours Uwe From nhytro at t-online.de Tue Oct 30 17:53:46 2001 From: nhytro at t-online.de (Sharriff Aina) Date: Tue, 30 Oct 2001 23:53:46 +0100 Subject: Re.Re: os.system, backslash and commandline problem Message-ID: <000801c16195$bb9e0000$310552d9@isis> Very strange answer Mr. Lundh, thanks all the same. I mentioned in the post that I know how to use raw strings and character substitution, did you read my post? Anyways, someone adviced me to use "os.normpath" instead of replacing the backslashes, that worked well with "os.system" >> I tried out a file that had "dangerous" characters: >> c:\the\boy.txt ("\t" TAB, "\b" BELL) >>>> print "c:\the\boy.txt" >c: hoy.txt >>>> print "c:\\the\\boy.txt" >c:\the\boy.txt >> This is very saddening, any clues? help? >for more info, read up on "string literals" in your favourite >Python book, e.g: > http://www.python.org/doc/current/ref/strings.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherman at darwin.in-berlin.de Fri Oct 12 05:27:16 2001 From: gherman at darwin.in-berlin.de (Dinu Gherman) Date: Fri, 12 Oct 2001 11:27:16 +0200 Subject: signum() not in math? Message-ID: <3BC6B774.4688E9A2@darwin.in-berlin.de> Hi! Time for a periodic frenzy about the standard lib again... ;-) How comes there is no sign() or signum() function in math? I found only one thread in comp.lang.python mentioning such a function that dates back to January 1999, after looking in Google.groups for "signum -signal -Signum\.se". There, Tim mentioned a fancy (of course) short signum one-liner... The question is: why isn't sign() in the math module (or, may- be built-in)? Is it too trivial? I'm inclined to claim no more so than, say, abs(). Maybe a hidden deeply convoluted argument about rounding effects? Curious to see that. A way to distin- guish one's camp from the Perlies'? Strange idea. Nobody nee- ding it? Surprising. Ahh, a missing PEP, even? That could be the case... ;-) Waiting-for-the-Snake-Oracle's-advice'ly, Dinu -- Dinu C. Gherman ReportLab Consultant - http://www.reportlab.com ................................................................ "The world becomes a better place as a result of the refusal to bend to authority and doctrine." (Noam Chomsky) From cjaeger at ensim.com Tue Oct 9 18:08:36 2001 From: cjaeger at ensim.com (Chris Jaeger) Date: Tue, 09 Oct 2001 15:08:36 -0700 Subject: Question about read() behavior and EINTR Message-ID: <3BC37564.C8F2418F@ensim.com> Hi all, I've encountered an annoying behavior with respect to the built-in read() function and I'm wondering whether it is a Python bug, a glibc bug, or a case of abusing read(). For reference, I'm using Python 2.1.1 on a glibc-2.2.2 Linux system, with kernel 2.4.2. I have a python extension module written in C that executes commands via execl, and returns the stdin, stdout, and stderr as Python file objects. With one particular command sequence, my code received an IOError exception with errno set to 0. I started digging down, and this is what I've reconstructed about the sequence of events: - from python: data = stdout.read(16384) while data: data = stdout.read(16384) Three read()s occur, with the following behavior: stdout.read(16384) returns 12288 bytes stdout.read(16384) returns 1266 bytes stdout.read(16384) throws IOError(0, 'Error') I added some tracing code into the python binary and noticed that the error bit in the FILE structure is set during the first read, and this is what eventually causes the IOError to be thrown. Here is a more detailed sequence: stdout.read(16384) file_read(16384) fread(16384) read(16384) returns 12288 bytes read(4096) returns EINTR, causing glibc to set error bit in FILE fread returns 12288 bytes file_read returns 12288 bytes stdout.read returns 12288 bytes stdout.read(16384) file_read(16384) fread(16384) read(16384) returns 1266 bytes read(15118) returns 0, setting EOF bit in FILE fread returns 1266 bytes file_read returns 1266 bytes stdout.read returns 1266 bytes stdout.read(16384) file_read(16384) fread(16384) fread returns 0 file_read notes 0 return value and checks ferror() ferror() returns true (due to EINTR, way back in the first call) file_read sets up exception and returns stdout.read throws IOError So, any ideas as to who is at fault? Should glibc see EINTR and not bother setting the error bit? Should python check feof() in preference to ferror()? Should I be setting up signal handlers to restart the read system call? Any ideas are appreciated. Thanks, Chris From dale at riverhall.NOSPAMco.uk Thu Oct 11 05:46:53 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Thu, 11 Oct 2001 10:46:53 +0100 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> Message-ID: Greg Ewing wrote: >I feel the solution to this is *not* to go in for >any sort of assignment-in-expressions hackery, but >to provide a decent loop-and-a-half control structure. >My current idea for this is > > while: > x = get_next() > gives x: > whatever(x) I think I see what you're getting at but it doesn't really do it for me. The general loop construct as found in C and Java where you have three expressions: initialisation, increment/iteration, test is a very flexible and powerful approach which I really like. -- Dale Strickland-Clark Riverhall Systems Ltd From logiplexsoftware at earthlink.net Tue Oct 16 17:16:45 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 16 Oct 2001 14:16:45 -0700 Subject: size / length of a list ??? In-Reply-To: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> References: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> Message-ID: <01101614164503.01359@logiplex1.logiplex.net> On Tuesday 16 October 2001 14:11, Markus Jais wrote: > list = [1, 2, 4] print len(list) BTW, you probably shouldn't use "list" as the name of your list, since that is a Python function. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From christophertavares at earthlink.net Wed Oct 31 18:57:16 2001 From: christophertavares at earthlink.net (Chris Tavares) Date: Wed, 31 Oct 2001 23:57:16 GMT Subject: python development practices? References: Message-ID: "Cliff Wells" wrote in message news:mailman.1004563112.32516.python-list at python.org... [... snip ...] > > Encapsulation is as much a part of data hiding as private variables. > However, it would be nice to have a mechanism so that derived classes > wouldn't have to be careful of accidentally stepping on the attributes of > base classes. As I said earlier, a class should be a "black box". Authors > of derived classes shouldn't have to look at the internals of base classes to > avoid this, especially since, as we were discussing, the internals of the > base class could conceivably change, introducing name-collisions in derived > classes. A single underscore will not prevent this. For instance: > > class Base: > def __init__(self): > self._foo = 1 > > class Derived(Base): > def __init__(self): > Base.__init__(self) > self._x = 1 > self._y = 2 > > No problem here, but later, the author of Base decides to add a self._x to > Base. Now Derived is undoubtedly broken and it won't be clear why. A > private variable mechanism that could prevent this scenario would be a > definite benefit. > This scenario is precisely why the two underscore name mangling scheme was added to python. Rewrite your example as: class Base: def __init__(self, x): self.__x = x def print_base_x(self): print self.__x class Derived( Base ): def __init__(self, base_x, dev_x): Base.__init__(self, base_x) self.__x = dev_x def print dev_x(self): print self.__x d = Derived( 5, "hi there!" ) d.print_base_x() prints 5 d.print_dev_x() prints Hi There! So, the mechanism you're asking for is already there. Wether it's pretty or not is a different question. But it does work, and it's implemented now. -Chris From logiplexsoftware at earthlink.net Thu Oct 4 18:53:07 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 4 Oct 2001 15:53:07 -0700 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <9pimt6$cc9$1@tyfon.itea.ntnu.no> References: <1002028115.395.70447.l7@yahoogroups.com> <9pimt6$cc9$1@tyfon.itea.ntnu.no> Message-ID: <01100415530700.05766@logiplex1.logiplex.net> On Thursday 04 October 2001 15:12, Magnus Lie Hetland wrote: > > Cliff Wells writes: > > [snip] > Hey, I didn't write that. Be careful how you [snip]. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From root at rainerdeyke.com Mon Oct 29 00:53:33 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Mon, 29 Oct 2001 05:53:33 GMT Subject: Python 2.2b1 hashable dictionary bug? References: Message-ID: "Tim Peters" wrote in message news:mailman.1004326288.22670.python-list at python.org... > > >>> class D(dictionary): pass > > ... > > >>> d = {} > > >>> d2 = D() > > >>> d[d2] = "dictionary used as key" > > >>> > > You can stop there -- objects of builtin mutable types should never be > usable as dict keys. What about this: class dictionary_with_identity_compare(dictionary): __eq__ = object.__eq__ __ne__ = object.__ne__ __lt__ = object.__lt__ __gt__ = object.__gt__ __le__ = object.__le__ __ge__ = object.__ge__ __hash__ = object.__hash__ d = {dictionary_with_identity_compare() : None} -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From boud at rempt.xs4all.nl Sat Oct 27 07:36:35 2001 From: boud at rempt.xs4all.nl (Boudewijn Rempt) Date: 27 Oct 2001 11:36:35 GMT Subject: tutorial References: <9rb6pi$nva$1@penthesilea.materna.de> Message-ID: <9re683$5fq$1@news1.xs4all.nl> kutte wrote: > Hi there ! > I?m looking for a python tutorial for beginners. I would like to learn > python, but I didn?t found any (good) toutorials ( online or download ). > I just have expierience in programming procedual Languages. ( C, Basic and > Javascript) So I need a very "calm" tutorial *g* > (If you even know one tutorial in german...........I would spread my kisses > allovertheworld *G*) The Python newbiews page (http://www.python.org/doc/Newbies.html) has a lot to offer. One set of tutorials I like a lot is the Livewires Python Course. It's a very good introduction to programming in general, using Python: http://www.livewires.org.uk/python/ -- Boudewijn Rempt | http://www.valdyas.org From chris.gonnerman at newcenturycomputers.net Wed Oct 31 00:40:49 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Tue, 30 Oct 2001 23:40:49 -0600 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> Message-ID: <00b801c161ce$99aa0be0$0101010a@local> ----- Original Message ----- From: "Peter Wang" > i don't think data hiding's purpose is to keep rogue programmers in > line. it's partly to insulate imperfect development practice (e.g. > sloppy documentation) and partly to define an interface for a class. > someone else made the point that this is the purpose of documentation, > which should be kept up to date; i agree but people will invariably > look at code, and with python, since the entire code of the class is > exposed (unless you split off a portion of it into a hidden base > class), it's doubly enticing to use stuff you're not supposed to. > also, code can be legacied and documentation will fall short. in > those cases, the python interpreter is not the code maintainer's > friend. > > i've no doubt about the power of python when used with rigorous > development practices. my question, i guess, is really whether python > is efficient/effective if used without perfect development practices. You can always ball up the code, in any language, if you are sloppy enough, or if you have alien mental patterns... I've worked on too many of those; I spent four years in the Air Force maintaining the amazing but fragile REXX code of a man who insisted that everyone call him Crazy. > if the documentation is a little out of date. or if a certain > interface isn't fully spec'ed out. and the guy who wrote the code is > out of town for a week. are there good practices which safeguard > against these situations? (beyond perfect development process...) A programmer with any grounding at all in good design principles and who is comfortable with Python generates better code *on the average* than about any other programmer in my experience... where "better" == "more readable and less buggy". > oh, and the underscore thing seems a bit of a hack in that it > contradicts one of the core principles of python. decreasing > readibility of the code in order to express class properties to the > interpreter just screams "bolted on". I'm not at all sure that it decreases readability. Perhaps it does make the code a bit uglier, but still quite readable. From neal at metaslash.com Tue Oct 23 18:02:38 2001 From: neal at metaslash.com (Neal Norwitz) Date: Tue, 23 Oct 2001 18:02:38 -0400 Subject: A little debugging advice (was Re: None) References: <9r4b95$suc$1@news.rchland.ibm.com> Message-ID: <3BD5E8FE.D8FB418B@metaslash.com> Huaiyu Zhu wrote: > > On Tue, 23 Oct 2001 13:01:09 -0500, Larry Whitley wrote: > >But Python complains that None is a variable that has not been previously > >set. > > It's most likely that you have a typo, like none, Non, N0ne, etc. > > If you have double checked it carefully and still cannot figure out, there > is one trick that almost always works: start a Python interpreter and > copy-paste the variable name (don't type them!), like > > >>> None > >>> `None` > 'None' [snip] You can also use pychecker (http://pychecker.sourceforge.net). It will generally find typos and other errors. Neal From oktay_safak at yahoo.com Tue Oct 2 04:15:25 2001 From: oktay_safak at yahoo.com (Oktay Safak) Date: Tue, 2 Oct 2001 01:15:25 -0700 (PDT) Subject: An interview with Bruce Eckel Message-ID: <20011002081525.80897.qmail@web20705.mail.yahoo.com> http://www.informit.com/content/index.asp?product_id={5820BFA3-96C0-4661-B712-A7D18811A9FE}&news=true __________________________________________________ Do You Yahoo!? Listen to your Yahoo! Mail messages from any phone. http://phone.yahoo.com From peter at engcorp.com Mon Oct 1 19:14:18 2001 From: peter at engcorp.com (Peter Hansen) Date: Mon, 01 Oct 2001 19:14:18 -0400 Subject: Help with CRC calculation References: <90164d1a.0110011213.18fedeb@posting.google.com> Message-ID: <3BB8F8CA.23439E9F@engcorp.com> Jeff Winkelman wrote: > > CRC Algorithm in C: > > unsigned short CRC16(char *pData, unsigned short length) > { > unsigned char i; > unsigned int data; > unsigned int crc = 0xffff; What size are your ints? I'm guessing they're really 16-bit ints, rather than 32. > crc = ~crc; > data = crc; > crc = (crc << 8) | ((data >> 8) & 0xff); Without looking at past code I've used I can't be sure, but it looks like that code (all of what you posted) depends on a 16-bit integer. > Possible equivalent in Python: > > def crc16(packet): > POLY = 0x8048 > crc = 0xFFFF > > if len(packet) == 0: > return ~crc In Python, this returns 0xFFFF0000 for example. Probably not what you want and not what C does with 16-bit ints. > crc = ~crc > data = crc > crc = (crc << 8) | ((data >> 8) & 0xFF) > return -crc Chances are both the ~crc and the (crc << 8) need to have an "and 0xffff" added after them to perform the effect of C's automatic truncation of results to the 16-bit size. Or it could be something else. :-) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From sholden at holdenweb.com Fri Oct 19 09:23:00 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 19 Oct 2001 09:23:00 -0400 Subject: Traceback oddity References: <3BD025A3.D0724FFC@pallas.com> Message-ID: "Georg Bisseling" wrote ... > Dale Strickland-Clark wrote: > > File "S:\JOBS\Gibson\Library Manager\librarymanager\cli\lb.py", line > > ... > > > File "s:\jobs\gibson\library manager\librarymanager\lbdbTable.py", > > > > The observant will have noticed that the first few filepaths are in > > mixed case whereas the last are all lower case. > > > > I only noticed because I'm trying to post-process this report. > > > > Any ideas why? > > Because Bill didn't get it right in the first place... > > The FAT12/16/32- and NT-Filesystems are not case sensitive but > "case aware". That means you can have a file named "a" and > a file named "A" but they are not allowed to live in the same > directory. > Not, unfortunately, strictly true. Certainly in older versions on NT you could use the Posix utilities to create two different files in the same directory whose names were indistinguishable under NT, but which were treated as different under Posix. Haven't tried it lately... > If you open "a" or "A" for read you get either "a" or "A" whatever > is there. > And under the circumstances described above you got whichever the filesystem code came up against first. Wildcard matches were especially fun, since (AFAIR) the two different names would glob out, but then both would access the same file. This just shows the difficulty of trying to use non-native filename semantics on a crippled platform. > To complicate things the newer Windows-Versions do not show the > filenames as they are stored on disk but in a "beautified" Form. > > So it is safe and consistent to use lower case letters when searching > for files to read. > But of course that doesn't answer Dale's question as to why his traceback shows the same directory in different ways. Dale, have you checked to see whether you have multiple entries in sys.path? regards Steve -- http://www.holdenweb.com/ From huaiyu at gauss.almadan.ibm.com Wed Oct 24 15:46:50 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 24 Oct 2001 19:46:50 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> <9r5h75$1m5$1@slb6.atl.mindspring.net> Message-ID: On Tue, 23 Oct 2001 22:46:56 -0600, Andrew Dalke wrote: ># I know, for some reason you don't like putting the end condition ># inside the loop. But it's one I've brought up before and it's ># a simple mechanical transformation from what you want to do. The reason is very simple - the naive translation does not work. Period. ># And only one extra line (assuming your proposed code is written in ># a more readable form.) >def getprimes(x): > primes = [] > for n in range(2, x): > for p in primes: > if p*p > n: > primes.append(n) > break > elif n % p == 0: > break > return primes Intersting. Where have my primes gone? :-) >>> getprimes (3) [] >>> getprimes (4) [] >>> getprimes (100) [] >>Thinking about this - perhaps the real problem is multiple exits for >loops - >>at least one normal end to loop and another abnormal end. > >And I still insist there is no problem. You've yet to really >come up with an example of how your proposal would clarify any >real code, and you have yet to show that the addition of a new >construct won't make Python more confusing. Shortness does not >equal readable. > Does the above count as an example? Can you see that the problem with the simple mechanical translation is that it does not handle properly the two different kinds of exits? Hint: There are three exits in the 'for p' loop. Two of them should lead to the same follow-up code, the other leading to a different follow-up code. Finding them out is left as an exercise to the reader. :-) BTW, I'm not insisting on new syntax now - at least not until there is one that can handle all thes cases in a straightforward manner. I can see that iterators can solve some of them, but not all. The problem is more complicted than either you or I thought initially. Huaiyu From jriveramerla at yahoo.com Thu Oct 11 19:17:38 2001 From: jriveramerla at yahoo.com (Jose Rivera) Date: 11 Oct 2001 16:17:38 -0700 Subject: Program of wxPython works on NT but it does'nt works on Win98?? , Message-ID: <11e94203.0110111517.662e5255@posting.google.com> Hi.. I developed a program with wxPython 2.2 and Python 2.1 using Boa 0.0.5 on WinNT and it works great... But it does not work on Win98 with wxPython 2.2 and ActiveState 2.1. Do you have any idea ? what shuold I do to make it work? The problem is with the toolbar, it works on NT and when I copy the same code to a Win98 PC, the toolbar does not even appear... Thanks for your help... Jose Rivera Merla jriveramerla at yahoo.com From peter at engcorp.com Fri Oct 12 22:36:15 2001 From: peter at engcorp.com (Peter Hansen) Date: Fri, 12 Oct 2001 22:36:15 -0400 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <9q8201$l9lp3$1@ID-11957.news.dfncis.de> Message-ID: <3BC7A89F.B1BF5458@engcorp.com> "Tim Peters" wrote: > > If people sign off on taking "then" as a new keyword, I think the chances > > are good that we could get > > > > x = if e1 then e2 else e3 You mean it isn't already a keyword? +1 on proposal -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From peter at engcorp.com Sun Oct 28 01:05:34 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Oct 2001 01:05:34 -0400 Subject: Problem using Random References: <87elno5r1t.fsf@toadmail.com> Message-ID: <3BDB921E.FA7390EF@engcorp.com> Jeremy Whetzel wrote: > > mylist = ['a','b','c','d','e','f'] > print mylist > for i in mylist: > c = random.choice(mylist) > print c > mylist.remove(c) > > Is there any way that I can get the random.choice() to go through and > exhaust all possible choices before quitting? There are many ways... :) Your problem above is in iterating over the list with 'i'. Why do that, when you are not even using 'i' in the code? Try something like this instead, as a quick first attempt. (Note that the conditional evaluation of mylist returns false when the list is empty, exiting the loop.) >>> import random >>> mylist = ['a','b','c','d','e','f'] >>> while mylist: ... c = random.choice(mylist) ... print c ... mylist.remove(c) f a d b c e -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From jhauser at ifm.uni-kiel.de Mon Oct 15 17:29:18 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 15 Oct 2001 23:29:18 +0200 Subject: get uniform binary data into array for further processing References: Message-ID: <87y9mciocx.fsf@lisboa.ifm.uni-kiel.de> Another option, which is much better in the long run is to use netcdf to store the climate data and use this for further calculations. This helps a lot with data, which needs to be sliced during processing, as one can load subslices (called hyperslabs in the netcdf docs). And it's very common in climate data centers, so will help to share and document the data, as netcdf-files are self-describing. There are several python-bindings for teh netcdf-api. __Janko Hauser -- Dr. Janko Hauser Institut fuer Meereskunde phone: 49-431-597 4019 Dept. Theoretical Oceanography email: jhauser at ifm.uni-kiel.de Duesternbrooker Weg 20 24105 Kiel, Germany From export at bmatrading.com Mon Oct 8 04:54:22 2001 From: export at bmatrading.com (A) Date: Mon, 8 Oct 2001 10:54:22 +0200 Subject: DNS module or how to ... ? Message-ID: <3BC185DE.6490.6E5428@localhost> Hello, Is there a DNS module available for Python ? Or is there a method how I can , from my python program, find out an email server for a particular domain? For example for email printers at sendme.cz I find out that email server mail.contactel.cz serves for domain sendme.cz Thank you for help. Ladislav From phr-n2001d at nightsong.com Thu Oct 18 19:49:57 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 18 Oct 2001 16:49:57 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> <9qhvq5$29ik$1@nntp6.u.washington.edu> <23891c90.0110170317.1e18fae5@posting.google.com> Message-ID: <7xk7xsv78a.fsf@ruckus.brouhaha.com> "John Roth" writes: > Many instances of this are already handled by the short-circuit > 'and' and 'or' operators. And that's supposed to be readable? From h4rv3st at web.de Thu Oct 25 18:16:29 2001 From: h4rv3st at web.de (Daniel T. Bender) Date: Fri, 26 Oct 2001 00:16:29 +0200 Subject: error starting ZOPE Message-ID: <9ra2vq$sifvp$1@ID-22517.news.dfncis.de> hi folks! i downloaded the Zope-2.4.2-src, unpacked it and build all the stuff via "python wo_pcgi.py" everything is compiled etc, but when i try to run the ./start script i always get: PANIC(300) z2 Startup exception Traceback (innermost last): File /root/Zope-2.4.2-src/z2.py, line 757, in ? IOError: [Errno 13] Permission denied: '/root/Zope-2.4.2-src/var/Z2.pid' i have tried the binary-version of zope and get the same error ... any hints? Harvest T. Moon -- a life less ordinary!! From pez at apocalyptech.com Tue Oct 16 10:17:00 2001 From: pez at apocalyptech.com (CJ Kucera) Date: Tue, 16 Oct 2001 09:17:00 -0500 (CDT) Subject: maximum recursion in "re" module? In-Reply-To: <15307.35253.91335.661869@beluga.mojam.com> from "Skip Montanaro" at Oct 15, 2001 08:13:25 PM Message-ID: <200110161417.JAA17049@scortch.unisrv.net> On Mon Oct 15 20:13:25 2001, Skip Montanaro wrote: > > CJ> startString = ".*?Lo Fi Play
... > CJ> mp3String = re.compile(startString, re.I).sub("", mp3String, 1) > > Why do you need the ".*?" part of the re? I'd try this: Well, basically what I want to go is get one URL out of the big mess o' HTML I'm trying to pull back. This URL comes directly after the "startString" bit, so what I was originally doing is replacing EVERYTHING up to and including startString with nothing. What I stripped out because it wasn't causing problems was that there's an "endString" too which lets the program know where the URL I want ends. Using the ".*?" seemed to be the easiest way to do that to me . . . > If you can get by without it, I think that will cure your problems. If not, > you can always import pre instead: > > import pre as re I'm assuming that that's "previous re" or something? Like the Python 1.x version of re (as opposed to 2.x)? In any case, I'll give that a try. Thanks! -CJ From carlca at dircon.co.uk Mon Oct 29 21:21:29 2001 From: carlca at dircon.co.uk (Carl Caulkett) Date: Tue, 30 Oct 2001 02:21:29 -0000 Subject: ActivePython 2.2 alpha status References: Message-ID: In article , paulp at ActiveState.com says... > > ActivePython's 2.2 Alpha is based on a version of CVS Python that did > not yet expose the property keyword (alpha 2) Fair enough. I thought maybe I was doing something wrong. > Mark is not very involved in ActivePython. He is more involved with > ActiveState's Komodo project. ActivePython 2.2 will be released within a > few days of Python 2.2. We will probably have another beta over the next > month also. Cool. Thanks for the reply. -- Cheers, Carl From sdm7g at Virginia.EDU Wed Oct 24 15:45:54 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Wed, 24 Oct 2001 15:45:54 -0400 (EDT) Subject: [print >>] None In-Reply-To: Message-ID: On Wed, 24 Oct 2001, Huaiyu Zhu wrote: > For quite some time I've been using one object for all these sort of things, > including terminating linked lists, etc. > > class Nothing: > def __str__(self): return "" > def __repr__(self): return "nothing" > def __call__(self, *args, **keys): return nothing > def __len__(self): return 0 > def __nonzero__(self): return 0 > def __setitem__(self, i, x): raise IndexError > def __getitem__(self, i): raise IndexError > def __setattr__(self, name, val): return nothing > def __getattr__(self, name): return nothing > > nothing = Nothing() > > if __name__ == "__main__": > for x in nothing: print x Note that in 2.1, the above is equiv. to iterating over an empty sequence. In 2.2, it's equivalent to iterating over an infinite sequence. My guess is that is has something to do with __getattr__ returning ... possibly on trying nothing.__iter__ and/or nothing.next ? Adding a next method seems to work: >>> class Null(Nothing): ... def next(self): ... raise StopIteration ... >>> nothing= Null() >>> for i in nothing: print i ... >>> -- Steve Majewski From jwelby at waitrose.com Tue Oct 2 15:48:30 2001 From: jwelby at waitrose.com (Julius Welby) Date: 02 Oct 2001 19:48:30 GMT Subject: [?] sorting files by modification time. References: Message-ID: <9pd5me$lo1@dispatch.concentric.net> Get a listing of the file names using os.listdir for the folder, then you can do something like: for name in filenames: # loop through the names of files in the folder path = os.path.join(folder, name) modified = os.path.getmtime(path) # this is the last modification date statdict[modified] = name # add the "last mod" and "path" to the dictionary as index, value pair keylist = statdict.keys() # create list of last updated dates You can then sort the keylist and create your ordered listing. I'm sure someone else will post a one liner, but it worked for me when I used it to find the oldest file in a directory in ovine.py (www.outwardlynormal.com/python/ovine.htm) HTH, Julius "Francisco Borges" wrote in message news:mailman.1002047826.26474.python-list at python.org... > > Hello all, > > I want to list some files in a directory and sort them by the > modification time. > > As far as I could tell, I can't do that with os.listdir and neither > with glob, is this right? > > I thought about > >>> os.system('ls -t') > > but it will thrown the output to stdout. Is there a simpler way to do > this than start messing with the stdout or with the shell??? > > thank you for your attention, > -- > Francisco. > __o > `\<, > _____(*)/(*)_____ > From christopher.abraham at verizon.net Fri Oct 19 12:51:57 2001 From: christopher.abraham at verizon.net (Chris Abraham) Date: Fri, 19 Oct 2001 12:51:57 -0400 Subject: Zope Python User Group DC 25 October Jim Fulton Message-ID: Hi All: I have been under water all month and I am sorry that I have not been better at keeping this community list going. Anyway, the reason there has been so much frustration is because ZPUG.org has been split between two servers and I just wanted to remain hands-off until things resolved. They didn't. Well, I have not been able to get onto the server to change the front pager, but we have the delightful and elegant Mr. Jim Fulton, the father of Zope and the amazing (so amazing that even the Python kids love it) ZODB! So, from 7-9 on October 25th, we will bask in Jim's presentation as well as really spending more time and energy keeping it simple. There will be plenty of time for questions, a liberal half-time schmooze, and whatnot. We will be able to fit into the larger room because Jim will be bringing Zope Corp's little overhead and a fancy laptop. Bring your notebooks, a lot of fun will be had by all. Joya Subudhi of Foretec Seminars will be sharing with us all of the joy of the upcoming Python 10 conference -- and Python 10 will be plying us with drinks at Brickskeller afterwards. Also, we are getting our server house in order and the folks and imeme are generous enough to offer ZPug a hope gratis! They do amazing work so if you have any Zope Hosting needs, please go check them out and tell them you got the message from us! Thanks, all, for your patience! Chris -- Chris Abraham, Managing Director, beehive North America +1 202 548 0410 fax:+1 202 478 0276 page:+1 202 229 4925 101 14th St, SE, BSMT, Washington, DC 20003 United States From graz at mindless.com Wed Oct 24 03:16:06 2001 From: graz at mindless.com (Graham Ashton) Date: Wed, 24 Oct 2001 07:16:06 GMT Subject: Tk and focusing windows Message-ID: I've got an application which opens two Tk windows as soon as it starts up; the main window and a progress dialog. I want the dialog to be displayed after the main window (so the main window can't cover it up), but the way my code is currently structured I call mainloop() immediately after creating the dialog. The code for the main window is done first. The main window is instantiated with "root = Tk()" before anything else happens, and the dialog is created with Toplevel(). Can somebody give me a brief rundown of what I should be doing to avoid this? Setting the focus (i.e. calling lift()) doesn't work, and even if it did there would still be the problem of the dialog being shown first, so window tiling makes for strange behaviour on windows. I'm trying to create the main window, then the dialog, and have them displayed on screen in that order. Thanks. -- Graham From jaroslav_gergic at cz.ibm.com Thu Oct 11 12:07:58 2001 From: jaroslav_gergic at cz.ibm.com (Jaroslav Gergic) Date: Thu, 11 Oct 2001 18:07:58 +0200 Subject: Controlling the Opera browser under UNIX Message-ID: <3BC5C3DE.56459533@cz.ibm.com> The webbrowser module in the Python 2.1 does not support the Opera browser directly. Did anybody solve this problem (i.e. implemented a controller class which can effectively control the Opera browser? Saying effectively I mean the controller does not spawn a new process for each "open-an-URL" request but it uses some IPC to re-use the process already running. Thanks for tips (in advance) Jaroslav Gergic From arthur.haas at westgeo.com Thu Oct 18 16:45:03 2001 From: arthur.haas at westgeo.com (Art Haas) Date: 18 Oct 2001 15:45:03 -0500 Subject: [PATCH] remove comma in Python/ceval.c Message-ID: Hi. I was trying to build Python-2.2a4 on AIX using the xlc compiler. The following trivial patch let me build the python executable. I've had bad luck trying to post this to the SourceForge patch page - it keeps saying `You Attempted To Double-submit this item. Please avoid double-clicking.' I promise I only clicked the Submit button once! :-) My thanks to everyone working on Python! --- Python-2.2a4/Python/ceval.c.orig Wed Sep 26 14:24:45 2001 +++ Python-2.2a4/Python/ceval.c Thu Oct 18 09:45:16 2001 @@ -468,7 +468,7 @@ WHY_RETURN, /* 'return' statement */ WHY_BREAK, /* 'break' statement */ WHY_CONTINUE, /* 'continue' statement */ - WHY_YIELD, /* 'yield' operator */ + WHY_YIELD /* 'yield' operator */ }; static enum why_code do_raise(PyObject *, PyObject *, PyObject *); -- ### Art Haas - (713) 689-2417 # They that can give up essential liberty to obtain a little temporary # safety deserve neither liberty nor safety. # -- Benjamin Franklin, Historical Review of Pennsylvania, 1759 From tjreedy at home.com Wed Oct 17 12:42:10 2001 From: tjreedy at home.com (Terry Reedy) Date: Wed, 17 Oct 2001 16:42:10 GMT Subject: newsgroup traffic way down? References: <8827e15d.0110170823.672f0a63@posting.google.com> Message-ID: > Is it just I, or is c.l.p traffic way down lately? I'm getting about 100/day, which is pretty high. From mis at creazone.com Sat Oct 6 03:04:52 2001 From: mis at creazone.com (Michal Seta) Date: Sat, 06 Oct 2001 03:04:52 -0400 Subject: compiling Python 2.x.x on redHat 7.0 Message-ID: Hi All. The time came to upgrade Python to a version 2.x. I tried to compile but any major version 2 I take gives the same error: #error "LONG_BIT definition appears wrong for platform (bad gcc config?)" Apparently the libc/gcc gives the LONG_BIT 64 instead of 32 on some platforms. How can this be fixed/corrected? RedHat7.0, Celeron 533 MHz, gcc version 2.96. Thanks in advance. ./Mike From peter at engcorp.com Wed Oct 31 20:09:52 2001 From: peter at engcorp.com (Peter Hansen) Date: Wed, 31 Oct 2001 20:09:52 -0500 Subject: map, filter, reduce, zip, range, and.. slice? References: <3bdf39a6@news.bezeqint.net> Message-ID: <3BE0A0E0.911D08BB@engcorp.com> Eyal Lotem wrote: > > To get to the point, I've almost always lacked a 'slice' function, that > slices sequences into smaller chunks. For example: > > divide("Hello world!", 2) => ["He", "ll", "o ", "wo", "rl", "d!"] How would this do? Note it can't in general guarantee to return chunks of equal size, but a simple exception could be used to add that capability. >>> def divide(s, n): ... return map(lambda i, s=s, n=n : s[i:i+n], xrange(0, len(s), n)) ... >>> divide('Hello world!', 2) ['He', 'll', 'o ', 'wo', 'rl', 'd!'] >>> divide('Hello world', 2) ['He', 'll', 'o ', 'wo', 'rl', 'd'] >>> divide('Hello world!, 55) ['Hello world!'] >>> divide('', 2) [] >>> divide('Hello world!', 3) ['Hel', 'lo ', 'wor', 'ld!'] >>> divide(hex(-889275714)[2:].upper(), 2) ['CA', 'FE', 'BA', 'BE'] >>> divide([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3) [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]] Thanks for the inspiration to write this. I'm pretty sure this is a method I've needed several times before and never could get my head wrapped around Python's sophisticated underside enough to figure it out. -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From phd at phd.pp.ru Fri Oct 12 04:44:00 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 12 Oct 2001 12:44:00 +0400 Subject: Length on an input parameter in python In-Reply-To: ; from coolslife@yahoo.com on Thu, Oct 11, 2001 at 03:16:07PM -0700 References: Message-ID: <20011012124400.B13949@phd.pp.ru> On Thu, Oct 11, 2001 at 03:16:07PM -0700, coolslife wrote: > > > It looks like the length of an input parameter (taken from the command > > > line atleast) is limited to 256 characters. > > > > Windows? > > Nope, Unix, 2.6 On UNIX limits are much, much higher. Something wrong there... Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phd at phd.pp.ru Wed Oct 31 06:08:28 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 31 Oct 2001 14:08:28 +0300 Subject: Python.NET, MONO and Visual Studio etc. In-Reply-To: ; from xavier@perceval.net on Wed, Oct 31, 2001 at 12:03:16PM +0100 References: Message-ID: <20011031140828.L15195@phd.pp.ru> On Wed, Oct 31, 2001 at 12:03:16PM +0100, Xavier Defrang wrote: > This is almost off-topic but since you guys are talking about that .NET > thing, I'd like just to ask anyone in here : WHAT THE HELL IS .NET??? > > I don't want any fancy buzzwords or corpspeak crap. I just want a clear, Among all the bullshit M$ invented there is one good thing: reusable components. This is really good. Of course, they will be implemented by those idiots who implemented Outofluck and IIS bugs. But here they are, free software components and .NET alternatives. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jwelby at waitrose.com Sun Oct 7 15:31:33 2001 From: jwelby at waitrose.com (Julius Welby) Date: 07 Oct 2001 19:31:33 GMT Subject: Is this a tiny bug? Message-ID: <9pqail$js5@dispatch.concentric.net> In Idle, when I use the tuple(sequence) built in function, the "tip" that pops up when I open the bracket is: tuple(sequence) -> list which surprised me, as I expected: tuple(sequence) -> tuple. The function obviously works fine, but I wondered what controls the "tip", and if this is a mistake. Just wondered. Julius From nsruok at aol.com Tue Oct 23 20:20:33 2001 From: nsruok at aol.com (nsruok at aol.com) Date: Wed, 24 Oct 2001 03:20:33 +0300 Subject: THERE IS OVER 600 GIRLS N YOUR CITY, LOOK THEM UP ON MY WEBSITE 174 Message-ID: would you like to meet women or men online and fuck them? Please visit my website http://www.spamtana.com/fafaffd kswbymuzcjujezokivgbynpcqfpzc From huaiyu at gauss.almadan.ibm.com Tue Oct 23 17:05:51 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 23 Oct 2001 21:05:51 +0000 (UTC) Subject: A little debugging advice (was Re: None) References: <9r4b95$suc$1@news.rchland.ibm.com> Message-ID: On Tue, 23 Oct 2001 13:01:09 -0500, Larry Whitley wrote: >But Python complains that None is a variable that has not been previously >set. It's most likely that you have a typo, like none, Non, N0ne, etc. If you have double checked it carefully and still cannot figure out, there is one trick that almost always works: start a Python interpreter and copy-paste the variable name (don't type them!), like >>> None >>> `None` 'None' If this still does not solve the problem, post the code and error message (or lack of error message) here -- by copy-and-pasting instead of paraphrasing -- the error is likely to be a typo and any retyping is likely to hide it or obscure it. In the unlikely event that you see things like >>> None Traceback (most recent call last): File "", line 1, in ? NameError: name 'None' is not defined and post them here, people would be more intrigged and speculate on the possibility that you did >>> del __builtin__.None or things like that. Very often you'll solve the problem while trying to make an example that's suitable to copy and paste. That happened to me numerous times. The take home message is that without copy and paste people would most likely just assume you made a typo somewhere and leave it to yourself to find out. Huaiyu From syring at email.com Mon Oct 29 16:30:16 2001 From: syring at email.com (Karl M. Syring) Date: Mon, 29 Oct 2001 22:30:16 +0100 Subject: python binary search References: <9rht70.3vvdvgd.1@kserver.org> <3BDD4E50.8BA429E9@uoguelph.ca> <9rjtho$ff9$1@testinfo.cs.uoguelph.ca> <3BDDA885.EECA7D8D@home.net> Message-ID: <9rkhpb$tvh2p$1@ID-7529.news.dfncis.de> "Chris Barker" schrieb > Jeffrey Dunnett wrote: > > > : Thanks for coming to my defence but I really MUST check my spelling beter. > > > > : Jeff > > > > Alright I will crawl back in the computer lab I came out of and look at > > an english dictionary since I incorrently spelled better. > > Ouch! I was sure you did that on purpose. As someone who is a lousy > typist and a lousy speller, I highly recommend an email client with a > spell checker...and a little proofreading. But why? The IDOIT sequence was quite a ravelation for me. Going Pippy Karl M. Syring From paul at fxtech.com Tue Oct 2 12:58:52 2001 From: paul at fxtech.com (Paul Miller) Date: Tue, 02 Oct 2001 11:58:52 -0500 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <1002040943.560.290.l9@yahoogroups.com> Message-ID: <5.1.0.14.2.20011002115026.02c780e8@cedar.he.net> >On Tue, Oct 02, 2001 at 08:59:34AM -0500, Paul Miller wrote: > > If GNU code is FREE, then I'll have to say that Python (and code under > > BSD-style licenses) is BETTER THAN FREE. Frankly, I'm very grateful to > > Guido for allowing Python to be used freely in commercial software. > > I see your point. You use other's people work without paying them. GNU >GPL, at least, force you to pay (by publishing your code). You don't want >to pay, and Python license makes you happy :( > >Oleg. Trying to make me into a cheap-skate and a thief doesn't endear me too much to you Oleg. You might want to tone down your GNU zealotry a tad. The issue is not whether I use people's work without paying them - if they didn't want me to, they would CHARGE for it. Part of Python's license is there IS NO CHARGE. NONE. That happens to work nicely for me, as I make commercial software. If I could pay the bills by giving away my code, I probably would, but this isn't the case. Fortunately, Python does not require me to make that choice. And, unlike the GNU license, the "free" in the Python/BSD license is not misleading. As others have rightfully pointed out, there is nothing free about the GNU license. Incidentally, I also maintain an open-source XML project, but under the LGPL. I like giving people a little bit more freedom than the standard GNU license does. -- Paul T. Miller | paul at fxtech.com | http://www.fxtech.com From njm at rectec.net Sun Oct 21 22:05:00 2001 From: njm at rectec.net (NJM) Date: Sun, 21 Oct 2001 21:05:00 -0500 Subject: display window reaction time Message-ID: This is a scheduled file launch program. It lauches a file of my spec at a specific time. I am having one problem though. When I try to use another toplevel widget to display the statis, the reaction time of the widget prevents the display until after the file is launched. Does any one have a way around this??? Thanks for the input... import Tkinter, time, os def starttmer(): global hour, minute, file hour = int(Tkinter.Entry.get(hourentry)) minute = int(Tkinter.Entry.get(minentry)) file = Tkinter.Entry.get(fileentry) process() def wait(timeinseconds): time.sleep(timeinseconds) def process(): tmer = time.localtime() if tmer[3] == hour and tmer[4] == minute: os.startfile(file) elif tmer[3] == hour and tmer[4] ==minute -1: Tkinter.Wm.iconify(root) wait(1) process() else: Tkinter.Wm.iconify(root) wait(1) process() root = Tkinter.Tk() frame1 = Tkinter.Frame(root) frame1.pack() frame2 = Tkinter.Frame(root, borderwidth=10) frame2.pack() frame3 = Tkinter.Frame(root) frame3.pack() filelabel = Tkinter.Label(frame1, text = 'Enter the file you want started here') filelabel.pack() fileentry = Tkinter.Entry(frame1, width = 60) fileentry.pack() timelabel = Tkinter.Label(frame1,borderwidth = 10, text = 'Enter the time you want the file started \n please use 24 hour time') timelabel.pack() hourlabel = Tkinter.Label(frame2, text="Start hour") hourlabel.pack(side=Tkinter.LEFT) hourentry = Tkinter.Entry(frame2, width=5) hourentry.pack(side=Tkinter.LEFT) minlabel=Tkinter.Label(frame2, text="Start minute") minlabel.pack(side=Tkinter.LEFT) minentry = Tkinter.Entry(frame2, width=5) minentry.pack(side=Tkinter.LEFT) startbut= Tkinter.Button(frame3, text="Start timer", command = starttmer) startbut.pack(side=Tkinter.LEFT) cancelbut=Tkinter.Button(frame3, text="Cancel", command = root.destroy) cancelbut.pack(side=Tkinter.LEFT) root.mainloop() From sholden at holdenweb.com Mon Oct 29 04:04:11 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:04:11 -0500 Subject: MySQL + SQL Statements + Quote escaping References: Message-ID: <_U8D7.7385$1I3.423338@atlpnn01.usenetserver.com> "Chris Stromberger" wrote in message news:fg0mtt43bt0k9n7kp93hk1gdt5tndcq5bu at 4ax.com... > >Christian Theune wrote: > > > > i just tuned into python and it's really cool. I like it. > > Before I came to python i used to write scripts in php. > > There was a function called "addslashes" it escaped quotes and > > slashes to make strings sql-safe. > > > >Database modules that conform to the DB-API specfication, such as > >MySQLdb, provide a placeholder mechanism that will take care of the > >quoting automatically. For example: > > > > cursor.execute( > > "select * from customers where surname = %s and age < %s", > > ("O'Hara", 40) > > ) > > > >The %s placeholders are replaced by correctly quoted values. > > > >There are two advantages to this approach. > > > >Firstly, database engines differ in how they escape quotes. Many, such > >as MySQLdb, prefix them with a backslash, but other DB engines escape > >quotes by doubling them (thus 'O''Reilly'). Using the placeholder > >mechanism lets the particular database module deal with that for you. > > > >The second advantage is that the execute() method can optimise its > >performance when the same operation is repeatedly executed but with > >different bound values for the placeholders. But if you build the query > >string yourself on each iteration, then the execute() method will have > >to parse it each time for correctness, thus losing the opportunity for > >optimisation. > > > >Hamish Lawson > > > > > This doesn't work for me. I have to add single quotes around the %s > and then it still doesn't escape the single quote in the substituted > string. What am I missing? > > Thanks, > Chris > > Eg (this works if there's no quotes in the substituted string): > > cursor.execute( > "select * from customers where surname = '%s' and age < %s", > ("O'Hara", 40) > ) > The DB API actually specifies five different SQL parameterization methods, and each different module can choose a different method. The DB API says each module must define a paramstyle global, with the following meaning: paramstyle String constant stating the type of parameter marker formatting expected by the interface. Possible values are: 'qmark' = Question mark style, e.g. '...WHERE name=?' 'numeric' = Numeric, positional style, e.g. '...WHERE name=:1' 'named' = Named style, e.g. '...WHERE name=:name' 'format' = ANSI C printf format codes, e.g. '...WHERE name=%s' 'pyformat' = Python extended format codes, e.g. '...WHERE name=%(name)s' So take a look at paramstyle for your module, and that wil tell you more. Some modules allow you to modify paramstyle, others just use a fixed value. regards Steve -- http://www.holdenweb.com/ From h.jehadalwan at student.kun.nl Sat Oct 6 11:21:17 2001 From: h.jehadalwan at student.kun.nl (Husam) Date: Sat, 06 Oct 2001 17:21:17 +0200 Subject: Slicing a list with non-integer parameter? How? Message-ID: <3BBF216D.25524AAB@student.kun.nl> Hi fiends, I'm trying to determine the position of an item in a list in order to delete it by slicing the list with non integer parameter. Code I works just fine. But code II doe's not work: Code 1 with integer values: >> list1=[1,2,3,4] >>> for i in list1: ... if i==2: ... pos=len(list)-len(list[i:]) ... del list[pos-1] ... print list ... [1, 3, 4] Code II with non integer values: >>> list2=['one','two','thrie','four'] >>> for i in list2: ... if i=='drie': ... pos=len(list)-len(list[i:]) ... del list[pos-1] ... print list ... Traceback (innermost last): File "", line 3, in ? TypeError: slice index must be int PS: my Python version is 1.5 thanks in advance From dale at riverhall.NOSPAMco.uk Wed Oct 3 10:08:23 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Wed, 03 Oct 2001 15:08:23 +0100 Subject: Assignment not the same as defining? References: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> Message-ID: <1n6mrtgackg46i6latothm7ihmt7fip8qb@4ax.com> Thanks for all that. The problem has always been one of initialisation. getattr and setattr were both being called during the initialisation assignments which were needed to establish their working environment. The first time they get called they weren't able to function properly. I really wanted to avoid initialisation flags. I've got around the problem by assigning to self. __dict__ for the first assignment and thats a reasonable solution. -- Dale Strickland-Clark Riverhall Systems Ltd From phd at phd.pp.ru Fri Oct 26 04:00:21 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 26 Oct 2001 12:00:21 +0400 Subject: compiling from source (without root privleges) In-Reply-To: <62e69c0c.0110252126.6a4a017b@posting.google.com>; from google@thegoldensun.com on Thu, Oct 25, 2001 at 10:26:22PM -0700 References: <62e69c0c.0110252126.6a4a017b@posting.google.com> Message-ID: <20011026120021.E25157@phd.pp.ru> On Thu, Oct 25, 2001 at 10:26:22PM -0700, HW wrote: > My web host (webaxxs.net) refuses to upgrade from Python 1.5 to 2.x. > > I am wondering if I have any hope of being able to compile from > source, without having root privleges. They are running a modified > Red Hat. I did it few times in my life. Last time was just a few days ago - I installed my personal Python on the server of Russian free-{web,mail,shell} provider hut.ru. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phr-n2001d at nightsong.com Tue Oct 16 09:58:28 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 16 Oct 2001 06:58:28 -0700 Subject: Cgi Counter References: Message-ID: <7xlmibk7p7.fsf@ruckus.brouhaha.com> Nomad writes: > On Fri, 12 Oct 2001 12:59:04 -0700 (PDT), Neal Irwin > ...> > fileWrite = open('count.txt', 'w') > fileWrite.write(str(intHits)) > fileWrite.close > ... > Pretty simple, but it works... Um, what happens if two requests (coming from different processes in the web server) run the hit counter at the same time? You need some kind of interlocking for this to be reliable. From tdelaney at avaya.com Sun Oct 14 21:04:14 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 15 Oct 2001 11:04:14 +1000 Subject: Borg Pattern Class usable from other classes? Message-ID: > From: Alex Martelli [mailto:aleax at aleax.it] > This would be bad practice in languages bereft of "property > idioms" such as > C++ of Java, but it's fine where properties are indeed > idiomatic, such as > Delphi or Python: the class author can and should ensure that > accesses to Actually, just to be picky, you can have property idioms in C++ ... something I wrote a number of years ago ... http://users.bigpond.net.au/tdelaney/index.htm?/tdelaney/products/property.h tm (sorry I had to give the long URL, but something's playing silly buggers on the site - I haven't maintained it in a while). Tim Delaney From sholden at holdenweb.com Wed Oct 31 14:19:56 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 14:19:56 -0500 Subject: newbie question References: <9rpbr2$us4bd$1@ID-11957.news.dfncis.de> <3BE0394E.9C4E92BF@alcyone.com> <3be04a08.19984913@news1.lig.bellsouth.net> Message-ID: "lance crocker" wrote ... > > this is an actual exert from a tutorial i got off the net. > > Programming tutorials since the beginning of time have started with a > little program called Hello, World! So here it is: > > print "Hello, World!" > > If you are using the command line to run programs then type it in with > a text editor, save it as hello.py and run it with ``python > hello.py'' > > Otherwise go into IDLE, create a new window, and create it as in > section 1.4. > > When this program is run here's what it prints: > > Hello, World! > > i did evrything that it asked me to do but i keep getting syntax > errors. i tried running it in DOS but it then gives me a bad command > or file name error. > This is because the command processor doesn't know where to find the Python interpreter. Suppose you have installed Python at the default location (C:\Python21 for Python version 2.1) then the following command should work, although requiring a little more typing: C:\python21\python hello.py You can fix this need for extra typing for a single session with the DOS command path c:\python21;%path% [this adds the Python installation directory to the places that the command processor looks for programs you tell it to run]. The DOS command python hello.py should now execute your "hello.py" program. To fix it for good you need to add the command path C:\python21;%path% to a file called "autoexec.bat" in the C:\ directory. The install procedure would be kinder to newbies if it did this, but undoing such changes at uninstall time is not always easy so maybe the implementors chose not to do this. > I want to get this fixed b/c how can i use progs with out being able > to run them? Well, that would be kind of difficult. I know you must be feeling frustrated right now, but stick with it. You are about to run your very first Python program! regards Steve -- www.holdenweb.com From john at yates-sheets.org Wed Oct 10 14:57:33 2001 From: john at yates-sheets.org (John S. Yates, Jr.) Date: Wed, 10 Oct 2001 18:57:33 GMT Subject: Sockets References: Message-ID: <3d69st0v0s49ldmngrgj5viis7seqsifql@4ax.com> On 10 Oct 2001 04:14:48 -0700, hugomartires at hotmail.com (Hugo Martires) wrote: >My server need to send 2 strings separeted: > s1= 'xxx' > s2= 'yyy' > >My client must received like this: > rec1= 'xxx' > rec2= 'yyy' > >The problem is that the Client received s1 and s2 in one only string. > >How can i received in 2 separeted variables ? > >Tanks Previous posters have given the "correct" answer and I agree with them. But a kludgy fix might be to disable the Nagel algorithm. This involves putting the socket into no-delay mode. I am very new to Python, so I don't know how or whether you can do this but in traditional socket programming it is definitely an option. /john -- John Yates 40 Pine Street Needham, MA 02492 781 444-2899 From max at alcyone.com Wed Oct 31 13:02:44 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 10:02:44 -0800 Subject: Why 'self' ? References: <3BE04E7A.8E2CF101@ces.clemson.edu> <9rpd0t$1ba2$1@nntp6.u.washington.edu> Message-ID: <3BE03CC4.CB05BB10@alcyone.com> "Russell E. Owen" wrote: > I certainly agree it's a problem. I find forgetting to include the > "self" argument to be one of the more significant sources of error in > my > own coding. Aside from that, I find it confusing that the caller and > callee argument list are different. There is a fairly good reason why this is done. Methods can be bound or unbound, and having the self parameter explicit in the case of unbound methods and implicit in the case of bound methods makes a good deal of sense. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From reqhye72zux at mailexpire.com Sun Oct 7 20:22:16 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Mon, 08 Oct 2001 00:22:16 -0000 Subject: permissions removing a directory? References: <9ppo49$cpk$1@neptunium.btinternet.com> Message-ID: G. Willoughby wrote: > I want to remove a directory but i keep getting this error: > > OSError: [Errno 13] Permission denied: > > heres the code: > > [snip] > > self.workingDirectory=self.directory.get() > self.thumbnailDirectory=os.path.join(self.workingDirectory, > "thumbnails") > if os.path.isdir(self.thumbnailDirectory): > os.rmdir(self.thumbnailDirectory) > > [/snip] > > any ideas??? Could be you're trying to remove a non-empty directory. Robert Amesz From tim.one at home.com Mon Oct 22 18:29:21 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 22 Oct 2001 18:29:21 -0400 Subject: nested_scopes totally broken? In-Reply-To: <3bd499a8@news.bezeqint.net> Message-ID: [Eyal Lotem] > Playing around with nested_scopes from __future__ (in Python 2.1), I have > encountered very unexpected behaviour. > ... Then I bet you didn't read PEP 227, "Statically Nested Scopes": http://python.sf.net/peps/pep-0227.html Read that first; all that you raised is covered there. From gmcm at hypernet.com Wed Oct 10 08:39:44 2001 From: gmcm at hypernet.com (Gordon McMillan) Date: 10 Oct 2001 12:39:44 GMT Subject: Sockets References: Message-ID: Hugo Martires wrote: > My server need to send 2 strings separeted: > s1= 'xxx' > s2= 'yyy' > > My client must received like this: > rec1= 'xxx' > rec2= 'yyy' > > The problem is that the Client received s1 and s2 in one only string. > > How can i received in 2 separeted variables ? That's why they're called STREAM sockets. Most people would probably use a delimiter (say, a tab character). But with large messages, or a congested network, you'll also have to make sure your client has received the whole message. In other words, you need to decide on a protocol. Check out http://www.mcmillan-inc.com/sock1.html - Gordon From cliechti at gmx.net Sat Oct 6 14:35:18 2001 From: cliechti at gmx.net (Chris Liechti) Date: 6 Oct 2001 20:35:18 +0200 Subject: Slicing a list with non-integer parameter? How? References: <3BBF216D.25524AAB@student.kun.nl> Message-ID: Husam wrote in news:3BBF216D.25524AAB at student.kun.nl: > Hi fiends, > I'm trying to determine the position of an item in a list in order to > delete it by slicing the list with non integer parameter. > Code I works just fine. But code II doe's not work: > > Code 1 with integer values: > >>> list1=[1,2,3,4] >>>> for i in list1: > ... if i==2: > ... pos=len(list)-len(list[i:]) > ... del list[pos-1] > ... print list > ... > [1, 3, 4] for "iterates" over the list, meaning that you get one element after the other. if your list has strings in it, then "i" is also a string. in your case you might consider: for pos in range(len(list)): item = list[pos] #... 1. you have an integer to use it as index 2. you dont need to do the "pos" calculation an other point: deleting items in the list your working on is usualy a bad idea. its better when you delete the items in a copy of the list: copylist = list(origlist) (don't name your variable "list" as this is a builtin function to convert something to a list) and as another poster Wmile van Sebille mentioned already, there is: list1.remove(element) which does what you want. Chris -- Chris From maxm at normik.dk Thu Oct 25 04:24:48 2001 From: maxm at normik.dk (Max M) Date: Thu, 25 Oct 2001 10:24:48 +0200 Subject: Submit jobs to a set of PC's (w2k/nt) References: Message-ID: <3bd7cc4f$0$239$edfadb0f@dspool01.news.tele.dk> "Jens Bloch Helmers" wrote in message news:ubsiw1c8r.fsf at dnv.com... > Send an input file to a given directory on machine A. > Start a program on machine A. (Do not wait for exit) > Send an input file to a given directory on machine B. > Start a program on machine B. (Do not wait for exit) > ... > Copy result files from machine A to host machine. > Copy result files from machine B to host machine. It sounds like a simple batch job will do the trick. You can control it with the windows scheduler. "Control Panel/Scheduled Tasks" regards Max M From tdelaney at avaya.com Mon Oct 29 20:08:55 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 30 Oct 2001 12:08:55 +1100 Subject: Representing tuples in strings Message-ID: > From: Graham Ashton [mailto:graz at mindless.com] > > >>> mytup = ('string1', 3, 'string2') > >>> ", ".join(map(str, mytup)) > 'string1, 3, string2' You were so close ... t = ('string 1', 3, 'string 2',) s = ', '.join(map(repr, t)) print s print repr(s) 'string 1', 3, 'string 2' "'string 1', 3, 'string 2'" The line with repr() in it is what you would see if you didn't have the print statements, and you were working on the interactive prompt (which you obviously are). Personally, I never work with the interactive prompt, as the results are different to what they would be run as a script, and eventually you want to run everything as a script. Tim Delaney From phd at phd.pp.ru Wed Oct 17 06:45:40 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 17 Oct 2001 14:45:40 +0400 Subject: Web Application Framework In-Reply-To: <42256AE8.003AA963.00@JHBMAIL01.edgars.co.za>; from CpJohnson@edgars.co.za on Wed, Oct 17, 2001 at 01:41:10PM +0300 References: <42256AE8.003AA963.00@JHBMAIL01.edgars.co.za> Message-ID: <20011017144540.T11182@phd.pp.ru> On Wed, Oct 17, 2001 at 01:41:10PM +0300, CpJohnson at edgars.co.za wrote: > Can anybody comment on which of these would be the best to use for a stand-alone > application that generates all of it's forms on the fly from data stored in some > or other datastore, possibly in XML documents. No forms are stored on disk at > all. Definitely sounds like a job for Zope. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From erno-news at erno.iki.fi Wed Oct 10 12:13:44 2001 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 10 Oct 2001 19:13:44 +0300 Subject: Why so few Python jobs? (and licenses) References: <7xwv2418xk.fsf@ruckus.brouhaha.com> Message-ID: In article <7xwv2418xk.fsf at ruckus.brouhaha.com>, Paul Rubin writes: | I started looking at Python after the news releases that it had | become GPL-compatible. I'd have never paid attention to it at all if | it had stayed incompatible. or perhaps, you'd never paid attention to it at all if it had stayed gpl-compatible ;) the period during which it was under a gpl-incompatible license was quite brief. -- erno From ignacio at openservices.net Tue Oct 2 21:19:35 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 2 Oct 2001 21:19:35 -0400 (EDT) Subject: "self" vs other names In-Reply-To: Message-ID: On Wed, 3 Oct 2001, Tim Hammerquist wrote: > What would the world have been like if CP/M had won over (PC|MS)-DOS? Not that much different; AFAIK MS-DOS was based on some of the principles of CP/M (8.3 filename, etc.). -- Ignacio Vazquez-Abrams From chatme at 263.net Thu Oct 18 21:51:14 2001 From: chatme at 263.net (limodou) Date: 18 Oct 2001 18:51:14 -0700 Subject: Is sgmllib.py 's BUG? References: Message-ID: "Sean 'Shaleh' Perry" wrote in message news:... > > at the start: > special = re.compile(']*>') > then later: > match = special.match(rawdata, i) > if match: > if self.literal: > self.handle_data(rawdata[i]) > i = i+1 > continue > i = match.end(0) > continue > > so if you want to handle it needs to be in a data handler. > > ----- > We have buried the putrid corpse of Liberty. -- Benito Mussolini Great! Your changes is better than me. I'v fixed my sgmllib.py with it. From hughett at mercur.uphs.upenn.edu Fri Oct 19 15:13:56 2001 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: Fri, 19 Oct 2001 15:13:56 -0400 Subject: Mirror site for tcl/tk? In-Reply-To: <001901c158d0$da1a19b0$b503a8c0@activestate.ca> (BrianQ@ActiveState.com) References: <001901c158d0$da1a19b0$b503a8c0@activestate.ca> Message-ID: <200110191913.f9JJDuP09120@mercur.uphs.upenn.edu> Brian Quinlan wrote: > I believe that the new site is: > http://tcl.activestate.com Yep, that's it. Many thanks. On a hunch, I also tried looking at sourceforge and discovered that the source can also be downloaded from there. Paul Hughett From topdog at web.de Sun Oct 28 06:08:31 2001 From: topdog at web.de (Andreas Zieringer) Date: Sun, 28 Oct 2001 12:08:31 +0100 Subject: Destroying all instances (references) Message-ID: <200110281108.f9SB8Vu11175@mailgate5.cinetic.de> Hi, is it possible to destroy all created instances, something like an "new" command in basic? I know re-creating the interpeter would do this, but in the new interpreter I have to import all modules again and I can't do this. Is there an easy way doing this in pythom or with the c-api? I couldn't find anything in the python docu. Regards Andreas ____________________________________________________ Berufsunf?higskeitversicherung von Mamax bei WEB.DE. Jetzt informieren! http://bu.web.de From philipprw at gmx.at Mon Oct 15 06:28:11 2001 From: philipprw at gmx.at (Philipp Weinfurter) Date: 15 Oct 2001 10:28:11 GMT Subject: python + xml performance compared to Java and C++ ?? References: Message-ID: Markus Jais wrote: >hello >does anyone have experiences how fast xml processing >and XSLT processing with python (using PyXML and 4Suite tools) >is, compared to Java and C++ (using the apache tools, like >Xalan, Xerces....) dunno about java, but the C++ versions of the apache tools are much much faster than anything you can do with python. but that's kinda obvious, since XSLT processing ist quite CPU intensive. same goes with building large DOM trees. i guess with SAX you'd be better off, using pure python. philipp (who thinks that XSLT is the ugliest language ever designed) From mwh at python.net Wed Oct 17 06:15:48 2001 From: mwh at python.net (mwh at python.net) Date: Wed, 17 Oct 2001 10:15:48 GMT Subject: fast sub list operations References: Message-ID: Robin Becker writes: > I would expect that there should at least be a way to split lists > using ranges and I know that this is done in NumPy so why not in > python. I actually implemented this for Python a few months back, but it was confusing in some case (e.g. negative strides) and it got rejected. You can find the patch on sf, if you care. > map and reduce etc are fast, but useless without builtin C speed > things to go with them. Hmm; Python is odd here. If you're iterating over a list and doing simple things to it, it's probably faster to just write it in Python: for example interleave2 is faster (and *lots* faster for bigger input[0]) than interleave1 (on my machine, on this day of the week, etc.): def interleave1(l1,l2,add=add): return reduce(add,zip(l1,l2),()) def interleave2(l1,l2): r = [] for i in range(len(l1)): r.append(l1[i]) r.append(l2[i]) return r list[int] is optimised in the eval loop, whereas the former probably has to go through the full getitem machinery *and* the function call machinery to call operator.add. profile-profile-profile-ly y'rs M. [0] Actually, this is obvious. interleave1 is quadratic in list length, so maybe that's what's killing it, rather than the eval loop optimisations. Remind me what reduce is doing in the language again? -- Remember - if all you have is an axe, every problem looks like hours of fun. -- Frossie -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From nospam2001oct at magnetic-ink.dk Fri Oct 26 02:06:45 2001 From: nospam2001oct at magnetic-ink.dk (Klaus Alexander Seistrup) Date: Fri, 26 Oct 2001 08:06:45 +0200 Subject: Learing Python, Newbie question References: Message-ID: <40d4f326-da3d-493a-8b28-9c3d0223feb4@zigzag.magnetic-ink.dk> Johannes Gamperl wrote: > Do you know if there is a coditional operator in python ( ?: ) The "a ? b : c" that we know from C can be emulated in Python by ((a and [b]) or [c])[0] // Klaus -- ><>? vandag, m?re, altyd saam From loewis at informatik.hu-berlin.de Mon Oct 1 05:05:11 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Oct 2001 11:05:11 +0200 Subject: Generators in 2.2a1 References: <0vPt7.171410$j65.38212797@news4.rdc1.on.home.com> Message-ID: Chris Perkins writes: > ( Yes, I'm replying to myself. ) > Never mind - I installed 2.2a4, and it works fine now. I guess that 'a' in > the version number is there for a reason... The specific problem is that the future statement didn't work in the interactive mode. Regards, Martin From nomad*** at ***freemail.absa.co.za Wed Oct 3 07:00:08 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Wed, 03 Oct 2001 13:00:08 +0200 Subject: newbie str to int References: <9pbetr$jp83@imsp212.netvigator.com> <3BB9F67F.29D077D2@home.net> Message-ID: On Tue, 02 Oct 2001 10:16:47 -0700, Chris Barker wrote: >what when wrong here? well, depending on what font you are using, timay >be obvious: that last character is the letter, "oh" not the number, >zero. I am very glad that Python chatches this kin do f very non obvious >typo fpr me: what did the person typing that string in mean??? It is a shame that your newsreader doesn't catch typo's for you -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From dalke at dalkescientific.com Tue Oct 30 21:25:27 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 30 Oct 2001 19:25:27 -0700 Subject: Interfaces != Multiple Inheritance [was Re: python development practices?] References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: <9rnndl$178$1@slb1.atl.mindspring.net> Richard Jones: >Java interfaces != multiple inheritance. > >They address completely different issues. Mutliple inheritance allows one to >include functionality from multiple base classes in one step. An interface >indicates that your class implements a specific set of methods. Interfaces >don't implement functionality, therefore indicating that your class >implements multiple interfaces doesn't add any additional functionality. Who says the base class needs to implement functionality? class SpamInterface: def sing(self): raise NotImplementedError class EggsInterface: def fry(self): raise NotImplementedError class Food(SpamInterface, EggsInterface): def sing(self): return "Spam, spam, spam, spam!" def fry(self): return "Sizzle." issubclass(Food, SpamInterface) For that matter, who says that espousing an interface means that interface is properly implemented? Since you have to have the regression tests anyway, what's the point of declaring an interface when the act of testing it is sufficient to show that the needed API is available? Andrew dalke at dalkescientific.com From howardlp at isis.vanderbilt.edu Wed Oct 17 10:58:26 2001 From: howardlp at isis.vanderbilt.edu (Larry Howard) Date: 17 Oct 2001 07:58:26 -0700 Subject: PythonCOM: implementing properties with parameters Message-ID: How would I implement an interface with a property such as this using PythonCOM? dispinterface IDispComponent { ... [id(0x60020003), propput, helpstring("property ComponentParameter")] void ComponentParameter([in] BSTR Name, [in] VARIANT rhs); [id(0x60020003), propget, helpstring("property ComponentParameter")] VARIANT ComponentParameter([in] BSTR Name); ... } VB: Property Get ComponentParameter(key As String) As Variant ... End Property Property Let ComponentParameter(key As String, value As Variant) ... End Property cpp: STDMETHODIMP COMCLASS::get_ComponentParameter(BSTR name, VARIANT *pVal) { ... } STDMETHODIMP COMCLASS::put_ComponentParameter(BSTR name, VARIANT newVal) { ... } lph -- Larry Howard Institute for Software Integrated Systems, Vanderbilt University howardlp at isis.vanderbilt.edu voice: (615) 343-7447 fax: (615) 343-7440 From krissepu at vip.fi Wed Oct 3 05:32:12 2001 From: krissepu at vip.fi (Pekka Niiranen) Date: Wed, 03 Oct 2001 09:32:12 GMT Subject: Solved: Problem with COM and Excel References: <3BBA1BD5.8E833283@vip.fi> Message-ID: <3BBADAEF.5F08C988@vip.fi> Thank you Tim Golden and Cliff Wells. I do not need to provide a range if I use this: >>> import win32com.client >>> import win32com.client.dynamic >>> xlApp = win32com.client.dynamic.Dispatch('Excel.Application') >>> xlBook = xlApp.Workbooks.Add() >>> sht = xlBook.Worksheets("Sheet1") >>> xlApp.Visible = 1 And now the fixed line: >>> sht.Columns.AutoFit() -pekka- Tim Golden wrote: > Pekka Niiranen wrote in message news:<3BBA1BD5.8E833283 at vip.fi>... > > How can I run AutoFit to all columns of my Excel sheet from python ? > > > > I have tried: > > > > >>> xlApp = win32com.client.dynamic.Dispatch('Excel.Application') > > >>> xlBook = xlApp.Workbooks.Add() > > >>> sht = xlBook.Worksheets("Sheet1") > > >>> xlApp.Visible = 1 > > > > So far so good, but at this stage I added some values to Excel Sheet > > (manually) and then run: > > > > >>> sht.Columns().AutoFit > > > > The whole PC is jamming with harddisk running madly. I have to use task > > manager to kill Idle and Excel. > > > > -pekka- > > The following works for me: > > def _2xl (headers, rowset, spreadsheet): > """_2xl - put a cursor output set to a spreadsheet, optionally > applying traffic light formatting > > Parameters: > headers - sequence of sequences containing column names & types > (typically from cursor.description) > rowset - sequence containing each row as a sequence > spreadsheet - full path to a spreadsheet > """ > n_cols = len (headers) > n_rows = len (rowset) > xl = Dispatch ("Excel.Application") > xl.DisplayAlerts = 0 > try: > xl.Workbooks.Add () > xl.ActiveSheet.Range (xl.Cells (1, 1), xl.Cells (1, n_cols)).Value > = [header[0] for header in headers] > xl.ActiveSheet.Range (xl.Cells (1, 1), xl.Cells (1, > n_cols)).Font.Bold = 1 > xl.ActiveSheet.Range (xl.Cells (2, 1), xl.Cells (1 + n_rows, > n_cols)).Value = rowset > xl.ActiveSheet.Range (xl.Cells (1, 1), xl.Cells (1 + n_rows, > n_cols)).EntireColumn.AutoFit () > > xl.ActiveSheet.SaveAs (Filename=spreadsheet) > xl.Quit () > finally: > xl = None > del xl > > I suspect the bit you need is the EntireColumn property of the range. > HTH. Tim From anthony at interlink.com.au Thu Oct 18 09:02:09 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 18 Oct 2001 23:02:09 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: Message from Anthony Baxter of "Thu, 18 Oct 2001 22:51:28 +1000." <200110181251.f9ICpSP02962@mbuna.arbhome.com.au> Message-ID: <200110181302.f9ID29B03218@mbuna.arbhome.com.au> >>> Anthony Baxter wrote > > > d) if the bug fix relies on some 2.2-ism, then it's either rewritten, > > > or ignored and relnoted > > Yes, but are there any such? > Beats me, I'm only just starting to trawl. The obvious ones might be the > internals, where the bugfix is on top of the 2.1-based code. ^2.2^ of course, I meant Anthony From tony.mcdonald at ncl.ac.uk Sun Oct 28 09:50:38 2001 From: tony.mcdonald at ncl.ac.uk (Tony McDonald) Date: Sun, 28 Oct 2001 14:50:38 GMT Subject: how do I get solaris thread fixes from 2.2b1 into 2.1? Message-ID: Hi, Can anyone tell me what I need to do to get the Solaris thread fixes that are in python 2.2b1 into a copy of python 2.1 I have? The reason is that it appears there is some interaction between python and zope under solaris that makes zope behave as a single threaded server. Certainly, if a long running web request is set off, you can't select any other links on the server until the first request has finished. A thread on the yahoo groups archive gives some context; http://groups.yahoo.com/group/zope/message/74484 The latest version of python (2.2b1) has a fix that sorts out some problems in threading with Solaris. The zope guys have said that zope is not currently compatible with python 2.2 (understandable - python 2.2 is a beta after all!), so it seems that what I need to do is to extract the fixed threads code from 2.2b1 and retrofit them into my 2.1 installation. So, is there anyone out there that can give me a hint as to what I need to do? many thanks for any hints on this one... tone. From gustafl at algonet.se Mon Oct 15 00:05:55 2001 From: gustafl at algonet.se (Gustaf Liljegren) Date: Mon, 15 Oct 2001 04:05:55 +0000 (UTC) Subject: Regex problem Message-ID: [Had trouble with the news server tonight. Sorry if you see this message more than once.] I'm trying to match either of the HTML elements or , containing an 'href' attribute. Here's the regex I've made: >>> re_link = re.compile(r'<(area|a)[^>]+href=".*"[^>]*/?>', re.I | re.M) Works fine when I try it on a matching string: >>> s1 = '' >>> re.match(re_link, s1).group() '' But I only need to add a space before, and it won't work. >>> s2 = ' ' >>> re.match(re_link, s2).group() Traceback (most recent call last): File "", line 1, in ? re.match(re_link, s2).group() AttributeError: 'None' object has no attribute 'group' >>> Regexes doesn't always have to match from the beginning! What's wrong here? Gustaf Liljegren From nas at python.ca Fri Oct 19 11:12:30 2001 From: nas at python.ca (Neil Schemenauer) Date: Fri, 19 Oct 2001 08:12:30 -0700 Subject: About popen2 In-Reply-To: ; from nicoLALALALALA@altiva.fr on Fri, Oct 19, 2001 at 04:53:47PM +0200 References: Message-ID: <20011019081230.A25490@glacier.arctrix.com> NM - Remove LALALALALA to email me wrote: > Am I right to assume that, unlike C's popen, popen2's "command" argument does > not get passed through the shell? > > If I am, is there a way to pass arguments? Something like this: popen2.popen2(("ls", "-l", "/")) Reading the source code is a useful exercise. Neil From stevenc at engineer.com Tue Oct 23 11:39:54 2001 From: stevenc at engineer.com (Steven Cummings) Date: Tue, 23 Oct 2001 10:39:54 -0500 Subject: non-function members of string-module. Message-ID: <3BD58F4A.2000408@engineer.com> I'm not sure if this has already been discussed in public, but if we want to phase out the use of the string module, then what is the plan for its members, like letter, uppercase, etc.? /S From DeepBlue at DeepBlue.org Tue Oct 30 11:38:54 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Tue, 30 Oct 2001 10:38:54 -0600 Subject: File upload in python module? References: Message-ID: Wayne Yes, there is an excellent script that can do that. It is by Tom Middleton and it does a great job. In addition, it is highly configurable. The zip file if pyuploadfile.zip and you can find it on the Python Vaults archive under CGI. Always look there and see what they have and make a Google search too and you are going to find many things. DeepBlue "Wayne Ringling" wrote in message news:mailman.1004447070.3098.python-list at python.org... > > I am working on a web project that needs a way to upload a gif or jpg (or > any file I guess) to a web server via the web interface. I have seen them in > perl and java. I am trying to use all python. Is there a python module or > script already done to handle this? I looked thru the module list at > python.org but didn't see anything that looked like it would handle it. > Maybe I missed it. Any pointers or ideas. Thanks > > Wayne > > From dswegen at allstor-sw.co.uk Thu Oct 18 05:34:57 2001 From: dswegen at allstor-sw.co.uk (Dave Swegen) Date: Thu, 18 Oct 2001 10:34:57 +0100 Subject: os.path.join and lists In-Reply-To: <9qlbdn$fe9$1@slb1.atl.mindspring.net> References: <9qkteg$6vaga$1@hades.rz.uni-sb.de> <9qlbdn$fe9$1@slb1.atl.mindspring.net> Message-ID: <20011018103457.A6712@software.plasmon> Thanks all. apply() (in all its variations) was exactly what I was looking for). Cheers Dave From phr-n2001d at nightsong.com Sat Oct 13 14:31:54 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 13 Oct 2001 11:31:54 -0700 Subject: webserver performance (was Re: Why so few Python jobs? (and licenses)) References: <7xwv2418xk.fsf@ruckus.brouhaha.com> <9q6a1u$ke9$1@serv1.iunet.it> <7xr8s8q21l.fsf@ruckus.brouhaha.com> <9q90ci$hdk$1@lancelot.camelot> Message-ID: <7xpu7rmlwl.fsf@ruckus.brouhaha.com> Skip Montanaro writes: > 'twould be nice if Jef included a row for Medusa (which uses select instead > of threads). Of course, that table is over three years old, so even the > numbers for the web servers he does show have probably changed in relation > to each other. Also Tux. From logiplexsoftware at earthlink.net Wed Oct 3 14:09:03 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 3 Oct 2001 11:09:03 -0700 Subject: Possible to read/write Excel files in Python? In-Reply-To: References: Message-ID: <01100311090303.03969@logiplex1.logiplex.net> On Wednesday 03 October 2001 10:39, Steven Sartorius wrote: > I'm running 2.1.1 on an i386 NetBSD box and the application I'm working on > needs to grab some data from an Excel spreadsheet. I've found a couple of > apps (xlHTML for example) that will take a spreadsheet and turn it into > html/text and I've seen an article on IBM's web site talking about how to > read/write Excel with perl. Is there anything out there that will let me Is the perl application they're running a Windows perl application? If so they're probably just setting it up as an ODBC source. I would be curious if that app would really work on non-MS platforms... -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From johnroth at ameritech.net Fri Oct 19 13:36:38 2001 From: johnroth at ameritech.net (John Roth) Date: Fri, 19 Oct 2001 10:36:38 -0700 Subject: Conditional Expressions don't solve the problem References: Message-ID: "Kevin D" wrote in message news:c2a5d721.0110180034.58fd2af4 at posting.google.com... > Hi John, > > "John Roth" wrote in message news:... > > "Kevin D" wrote in message > > news:c2a5d721.0110170224.584a2d78 at posting.google.com... > > > 2) "while 1" idiom: > > > > > > while 1: > > > foo = some_long_expression > > > if foo == terminating_condition: > > > break > > > body_of_loop() > > > > > > This solves problem (1) but IMHO, falls down in your "interrupting the > > > thought process" requirement - it takes some mental juggling to work > > > out just what the condition _is_ when reading the code. This is partly > > > because the actual termination condition is buried somewhere away from > > > the "while" statement and partly because the condition is reversed (so > > > having searched out the termination condition, you must then read it > > > as "until ", or "while not " - either way, the > > > code has to be mentally "translated"/restructured as it's being read). > > > > It only has to if you persist in reading it as a while loop! If you > > recognize > > "while 1:" as a separate control construct, then there is much less of a > > mental problem. > > If it's not a while loop, it should not be spelled "while". That's > _exactly_ my point - you read one thing and then have to think > another. This impacts on the clarity of the code. "if" is not spelled > "because" for a very good reason ;) I suppose that is a difference in the way our minds work. After far too many languages, my mind simply recognizes it as an idiom, and primes me to look for the loop controlling if... break construct embedded in it. > > See my comment, and the thread involving the [;...; > construct. It does everything you want. It also lets you put statements > > in lambda expressions, which may prejudice a lot of people against it. > > Two problems: As you've mentioned with the lambda thing, making this > sort of thing a general construct may be it's undoing as it's easy to > abuse. My suggestion was quite strict in only allowing a single > assignment in which one can prep the condition control variables. I find "too easy to abuse" somewhat of a straw man. You can abuse almost anything, and Python already has some really obscure usages. The short circuit 'and' and 'or' are positively obvious compared to the short-circuit '<' ,'<=', '>' and '>='. As a frequent poster to the XP newsgroup, I don't regard 'easy to abuse' as a cardinal sin, unless it's "almost impossible to avoid abusing." Now, that is a sin. > The other thing is that things look backwards when reading the code. > "while " just looks wrong, even if a condition eventually > occurs on the line. Something like "while where > " reads pretty much like English (to me) and > therefore requires the least amount of mental juggling to make sense > of, IMHO. > > Also, note that I keep saying "something like" before my examples. I'm > not that tied to the exact syntax I'm suggesting, but I'm trying > (probably badly) to expand on what I think a Pythonic (read "obvious > meaning") solution to the root issues might look like. As I said in another post, I suspect that iterators will solve most of the cases in the 'while 1:" camp. I'm much more interested in using such a construct with 'elif', and for that I need multiple statements. John Roth > > Regards, Kev. From db3l at fitlinxx.com Wed Oct 24 18:51:58 2001 From: db3l at fitlinxx.com (David Bolen) Date: 24 Oct 2001 18:51:58 -0400 Subject: Critical sections and mutexes References: Message-ID: writes: > For example, if you have a work queue that you don't want to grow to some > extreme length you may decide to cap its size at 1000 elements. With 10 > threads adding work to the list, occasionally they'll drop or hold a > packet of work too long or occasionally your list will grow to 1009 > elements. No big deal: the drop/hold problem exists regardless of any sort > of locking, and you don't care that your list is 9 elements too big > because your requirement was simply "don't let it grow without bounds". Just be careful to fully document that fact in your code and avoid using this sort of example for newbie questions about threaded code. Otherwise what tends to happen is that someone believes that the code in question is really establishing a cap of 1000 (since they won't necessarily perform the same threaded analysis of the code you have) and this can lead to maintenance problems down the road. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From asgard at hellnet.cz Thu Oct 25 02:49:23 2001 From: asgard at hellnet.cz (Jan Samohyl) Date: Thu, 25 Oct 2001 08:49:23 +0200 Subject: a simple module for finding roots of polynomial ? Message-ID: <20011025084923.A450@blackbox.hell> Hello, I am looking for some polynomial root finder. I wish I could just give a list of coefficients (for me, reals are enough) and get a list of roots (but these should contain the complex ones). Is there something simple as this in Python, or I have to code it myself ? Thank in advance Regards, Jan Samohyl From rafial at well.com Mon Oct 8 16:40:37 2001 From: rafial at well.com (Wilhelm Fitzpatrick) Date: Mon, 08 Oct 2001 20:40:37 -0000 Subject: why are *two* ctrl-D's needed with readline() Message-ID: <9pt305+vfch@eGroups.com> --- In python-list at y..., Marcin 'Qrczak' Kowalczyk wrote: > Fri, 5 Oct 2001 14:34:17 -0400, Steve Holden pisze: > > > Technically ^D terminates transmission, and only raises EOF if this > > result in an empty input buffer, which it does if entered before > > inputting any characters. > > So in normal circumstances programs shouldn't try to read after EOF > was seen, because it makes a difference for terminals. So would it be reasonable to report this as a bug? Certainly, I found the behavior surprising and non-standard... From markus at schabi.de Wed Oct 3 02:57:03 2001 From: markus at schabi.de (Markus Schaber) Date: Wed, 3 Oct 2001 08:57:03 +0200 Subject: "self" vs other names References: <1001621496.801193@cswreg.cos.agilent.com> Message-ID: <13014658.EfDdHjke4D@lunix.schabi.de> Hi, Tim Hammerquist schrub: > 'ly 'yrs I ust pickled this sentence into my signature. mar "always impressed by pure truth" kus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From johnroth at ameritech.net Wed Oct 10 11:25:01 2001 From: johnroth at ameritech.net (John Roth) Date: Wed, 10 Oct 2001 08:25:01 -0700 Subject: Curious assignment behaviour References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> <9psk9s$rbk@newton.cc.rl.ac.uk> <7x669o7r4k.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7x669o7r4k.fsf at ruckus.brouhaha.com... > "John Roth" writes: > > However, I think := makes a good choice for an expression assignment > > operator. It needs to be different from both the statement assignment > > operator and the equality operator. It also can't be in use for an > > extended assignment. > > Why on earth does it have to be different from the statement assignment > operator? What's wrong with > > while x=get_next(): whatever(x) > > I just don't buy the rationale that using = instead of == is a big source > of bugs. In 25 years of hacking C code, I think I've seen that error > maybe once or twice. You're obviously a much more meticulous programmer than I am, or than most of the programmers I work with are. That's to your credit. However, I've seen that bug many times in lots less code. That may say something about the lack of quality assurance in the areas I work in, and you'd be right. For the rest of the commentary, see Tim Peters' note on another branch of this thread. I agree completely with the error causing potential of having the same symbol for assignment and comparison; that's been noted as early as the Algol 60 compiler, which used := for assignment, and = for comparison. A large part of the target audience for languages like Python are not professional programmers, in the sense that they do programming on a daily basis. They are professional system administrators, or professionals in other fields, and do programming as only part of their job or avocation. A language that makes it difficult to make the more obvious mistakes, and that doesn't get in the way if you really want to do something that may turn out to be a real mistake, is ideal for them. John Roth From sill at optonline.net Wed Oct 3 19:11:00 2001 From: sill at optonline.net (Andrei Kulakov) Date: Wed, 03 Oct 2001 23:11:00 GMT Subject: newbie str to int References: <9pbetr$jp83@imsp212.netvigator.com> Message-ID: On Tue, 2 Oct 2001 12:22:29 +0800, James wrote: > I am switching from Perl to Python, and would > like to convert string '123abc' to integer 123. > > foo = int('123abc') # error > foo = string.atoi('123abc') #error > foo = eval('123abc') # error > > I tried the above, then tried the following. > > tmp = '' > for i in '123abc': > if 47 < ord(i) < 58: > tmp += i > foo = int(tmp) # yay > > Why doing simple thing like this is so complicated ? It's not *that* complicated. First of all, if you have a bunch of numbers and a bunch of letters and you want them separate, usually they're separated by something, like a space. If they are, you can easily split them and convert.. In your case they aren't separated, which is *very unusual*. There's no reason why Python should guess answers for such rare tasks. However, you can do it much simpler/clearer, than what you do: import string lst = "" for char in "123abc": if char in string.digits: lst += char else: break num = int(lst) > > Perl > $foo = '123abc' + 0; Why would I remember a separate rule that I may never use, ever? What if you have $foo = $bar + 5, where you think $bar is a number whereas in fact it is a string - python will tell you you're wrong, while perl will happily add them up, causing potential subtle bugs later on. It's a tradeoff, and I think perl chooses the wrong one. OTOH, keep in mind that perl was intended for quick short cgi's and admin scripts, where this isn't as big a problem, while python was meant to be more universal from day one (i.e. subtle bugs of this sort are far more dangerous in a very large multi-layered program). > > Please explain in newsgroup. > Many thanks in advance. You are very welcome! Don't be scared off by perl-bashing :-). > > > -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From tdickenson at devmail.geminidataloggers.co.uk Tue Oct 30 06:03:51 2001 From: tdickenson at devmail.geminidataloggers.co.uk (Toby Dickenson) Date: Tue, 30 Oct 2001 11:03:51 +0000 Subject: Windows/COM events/strange behavior References: Message-ID: "Krzysztof Czarnowski" wrote: >Sat, 27 Oct 2001 05:42:26 GMT >Mark Hammond wrote: > >> As I said, this main thread probably needs to be calling >> PumpWaitingMessages() each time around the loop. > > >Well... This definitely doesn't look very elegant to me! > >Anyway, if I got it well: > >1. I should introduce CoInitialize()/CoUninitialize() pair in the main >thread The pythoncom module calls CoInitializeEx automatically the first time it is imported, so you dont need to this this as well. > *and* call PumpWaitingMessages() in its loop? Right? Since pythoncom has made your main thread into an apartment threaded com thread, yes you will need to do this. > I assume that no >COM event will be delivered here, or will it? Only if you subscribe to those events in that thread. >2. No need to do this in other child threads (like the CORBA thread). Right? No (unless you want to do COM stuff in those threads) >3. Will the problem go away if: > > * the COM event handler is installed in a "free threaded appartment"? (can >I do this in a threading. thread?) That wont help, beacuse the main thread is still apartment threaded. > * native Windows threads from ? (now module threading is used) No difference. >And generally, what would be *your* favorite solution? (my task is basically >to receive events from a COM driven subsystem and pass them to a CORBA >subsystem) Some other options: 1. Arrange for the first import of pythoncom to happen in a thread that will actually be using com and providing a message loop, so that pythoncom's automatic CoInitializeEx call is not wasted. You can do this either by rearranging your imports, rearranging your threading structure, or both. This option is either the best, or the craziest, depending on context. 2. Set sys.coinit_flags *before* importing pythoncom. Pythoncom uses these flags in its automatic call to CoInitializeEx. If you set sys.coinit_flags = COINIT_MULTITHREADED, then your main thread will be free-threaded, and you dont need to provide a message loop. I hope this helps. Toby Dickenson tdickenson at geminidataloggers.com From skip at pobox.com Sat Oct 13 09:18:26 2001 From: skip at pobox.com (Skip Montanaro) Date: Sat, 13 Oct 2001 08:18:26 -0500 Subject: Newbie - converting binary data to ASCII text ? In-Reply-To: <9q9eei$gf1$1@wanadoo.fr> References: <9q92g4$6hd$1@wanadoo.fr> <9q9eei$gf1$1@wanadoo.fr> Message-ID: <15304.16162.286466.198984@beluga.mojam.com> > I'm completely new to python and I've got problem reading binary data > file. When I read a file with read(), the binary data aren't > converted. Check out the struct module: http://www.python.org/doc/current/lib/module-struct.html -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From R.Brodie at rl.ac.uk Thu Oct 18 05:15:32 2001 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Thu, 18 Oct 2001 10:15:32 +0100 Subject: Is sgmllib.py 's BUG? References: Message-ID: <9qm6jk$tec@newton.cc.rl.ac.uk> "limodou" wrote in message news:ce82f84e.0110172143.52b65634 at posting.google.com... > Sometimes I use python to analyse a HTML document. But I found that if > there is a tag start with ' 'special' pattern. It'll be ok mostly, occasionaly failed. Because > sometimes someone can use tag ' <200110111922.PAA31768@cj20424-a.reston1.va.home.com> Message-ID: <3BC6C3D5.1030501@livinglogic.de> Guido van Rossum wrote: >>instead of using a second idiom for builtins >> >>import types >>isinstance(x,types.IntType) >>. . . >> > > I find the ''.__class__ form butt-ugly, and would recommend type('') > instead. Fortunately, in 2.2 there are built-in names that express > these types much clearer: > > isinstance(x, str) > isinstance(x, int) > isinstance(x, list) > isinstance(x, tuple) > isinstance(x, dictionary) The only type still missing is module (at least for type checks, I don't know what the factory function module should do, and how deriving from module would be useful). Bye, Walter D?rwald From guido at python.org Wed Oct 31 13:02:16 2001 From: guido at python.org (Guido van Rossum) Date: Wed, 31 Oct 2001 18:02:16 GMT Subject: Dictionary from list? References: <1cbrttkrk1ljb6csfkb3rdhdbuh2n3v0ag@4ax.com> Message-ID: Greg Chapman writes: > By the way, in thinking about situation (a), I was wondering how much of a > slow-down would be involved if PyDict_XXX calls were changed to PyMapping_XXX > (I'm not advocating that, I was just curious). I haven't measured it but am convinced that it would be an enormous slowdown. > Anyway, while doing so, I > happened to notice the following two macros in abstract.h: > > #define PyMapping_DelItemString(O,K) PyDict_DelItemString((O),(K)) > #define PyMapping_DelItem(O,K) PyDict_DelItem((O),(K)) > > I assume those are oversights? It seems to me they should delegate to > PyObject_DelItem (and PyObject_DelItemString, which will have to be added). Yes, these are oversights. I've submitted a SF bug report so they will eventually be fixed. --Guido van Rossum (home page: http://www.python.org/~guido/) From dalke at dalkescientific.com Tue Oct 23 02:40:26 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 23 Oct 2001 00:40:26 -0600 Subject: Dictionary from list? References: Message-ID: <9r33bp$r47$1@slb7.atl.mindspring.net> >grow-up-it's-a-cow-not-a-dog-ly y'rs - tim Moof! Andrew dalke at dalkescientific.com From dalke at dalkescientific.com Sun Oct 21 03:54:42 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sun, 21 Oct 2001 01:54:42 -0600 Subject: silly idea - interesting problem References: <3BD248BA.2163BBDB@hotmail.com> Message-ID: <9qtv2v$daa$1@slb4.atl.mindspring.net> scott: >P.S.: Remember when Python used to differentiate itself from line noise >(sorry, I meant Perl) with a philosophy that went something like >"There's only one right way to do it."? Quoting from the Python Way, as channeled by its guru the uncle Tim, 13. There should be one -- and preferably only one -- obvious way to do it. Yet as we read these words, let us also reflect on verse 5. 5. Flat is better than nested. Here we see the two sayings seemingly opposed. For we start with the traditional firstWord = 'test' secondWord = 'dust' endString = '' i = 0 while i < len(firstWord): endString = endString + firstWord[i] + secondWord[i] i = i+1 print endString a chunk of code that could have remained unchanged for lo these past 10 years while Python has encoiled more of the faithful. But behold the loss of flatness - a branching that can cause the errors of Murphy to hold sway. This form prevails so the practictioners of structured programming did promote refactorization into functions. Struggling mightily they failed to come up with readable function names, for the results were as long as the code it replaced def print_word_pairs(firstWord, secondWord): ... print_word_pairs(firstWord, secondWord) and were rarely reused enough to warrant being a function. Those that tried to generalize further the code fragments did so at the pain of straying from the third way. 3. Simple is better than complex. With the second coming of Python we have received a newer, deeper form of expression. One which allows us to be flat and simple, and which has become the newly revealed obvious way. For this allows us to say letter_pairs = [x+y for (x,y) in zip('test', 'dust')] print ''.join(letter_pairs) And thus the seeming contradiction between the 5th and 13th ways is no more. But bear these words to heart - do not use more than three or four clauses in a list comprehension or on a line lest you face barbs of the gaurdians of the code review. This lesson in the revealed teachings of the Python Way has been brought to you by Andrew dalke at dalkescientific.com :) From eyal at hyperroll.com Mon Oct 22 18:14:26 2001 From: eyal at hyperroll.com (Eyal Lotem) Date: Tue, 23 Oct 2001 00:14:26 +0200 Subject: nested_scopes totally broken? Message-ID: <3bd499a8@news.bezeqint.net> Playing around with nested_scopes from __future__ (in Python 2.1), I have encountered very unexpected behaviour. What I thought, was that nested scopes will implement fully-functional closure behaviour, so that local function code seems to transparently run in the parent-function context, and within its variable namespaces. What I encountered, was a cheap copy of the locals() scope :) I could not change variable bindings (assign to variable references) of the external scope, let alone define new variables in it. There are two things in here that are in conflict: A) Local functions should retain their locality, with local variables and such being local to their use and removed/rid-of with the function's exit. B) Local functions should have seamless access to the scope of the external function. This means one of three options: A) Local functions retain their own local scope, which extends the locals()/etc scope of the external function, but sits on top of it, and is not actually using it (The current way). B) Local functions are seamlessly part of the external function's scope, meaning that they have no locality, and any local variables used for some internal calculations/etc override external function variables, and remain visible later. C) Local functions especially specify which variables should be 'mapped' to the external scope directly, much like the 'global' statement. I think C is the only solution that works for the needs of closure users. Sometimes I'd love to have access to the locals() scope of the external function, however, for most of the things, I'd prefer local functions to retain their locality. Therefore, the ideal balance is C, where one has both variables in the internal scope, and ones mapped to upper scopes. If I'm way off, feel free to correct me. This is all based on my experience and needs from nested scopes. From richard at bizarsoftware.com.au Mon Oct 15 00:18:35 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Mon, 15 Oct 2001 14:18:35 +1000 Subject: Help: How to capture invalid web page from urllib? In-Reply-To: <3BCA5E85.E3AA0CA7@starhub.net.sg> References: <3BCA5E85.E3AA0CA7@starhub.net.sg> Message-ID: <01101514183523.11044@ike> On Monday 15 October 2001 13:56, Paul Lim wrote: > I am trying to open a web page from command line. If the web page is not > valid, I hope to capture the exception and print an error message and > exit. > > What I currently have is as below, but I am certain I used the wrong > class because I did not managed to capture the exception (if any) raise. > > Could someone teach me how to test the validity of a web page, ie > whether does it exist, can it be open? > > # If web page is entered, check whether it is a valid web page > try: > inf = urllib.URLopener.http_error_default(sys.argv[1]) > except IOError: > print "Invalid webpage!" > print "Usage : ./webmap.py http://server-name/path-to-document" > sys.exit() The following should be enough: >>> try: ... urllib.urlopen('http://com.foo') ... except IOError: ... print "Page doesn't exist" ... Page doesn't exist >>> Richard From emile at fenx.com Sun Oct 28 21:16:58 2001 From: emile at fenx.com (Emile van Sebille) Date: Sun, 28 Oct 2001 18:16:58 -0800 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> Message-ID: <9riefm$tseam$1@ID-11957.news.dfncis.de> "Jeff Dunnett" wrote in message news:3BDCA674.FF268D0E at uoguelph.ca... > In case your wondering the school that I attend teaches Python. In fact it > is a main part of one of the first major software design course. That is > the University of Guelph in Ontario Canada. In fact the departement has > quite a lot of fallowers who like Python. > Hopefully, they haven't simply put themselves out to pasture... -- Emile van Sebille emile at fenx.com --------- From nde at comp.leeds.ac.uk Fri Oct 5 07:27:05 2001 From: nde at comp.leeds.ac.uk (Nick Efford) Date: Fri, 5 Oct 2001 11:27:05 GMT Subject: problem with FFT module from Numeric 20.2.0 Message-ID: I'm trying to build a working Numeric 20.2.0 from source using GCC 3.0 on a Linux system running Python 2.1. Python is also compiled with GCC 3.0. Numeric itself seems to work - at least, the tests all pass - but the FFT module is causing problems: >>> import FFT Fatal Python error: can't initialize module fftpack Abort Can anyone offer an explanation or suggest a possible fix? Many thanks, Nick From gerrie at trispen.com Thu Oct 4 02:38:30 2001 From: gerrie at trispen.com (Gerrie Roos) Date: Thu, 04 Oct 2001 08:38:30 +0200 Subject: Compiling Python2.1.1 on FreeBSD3.5 Problem References: <3BBADC04.2F245B68@trispen.com> Message-ID: <3BBC03E6.D0C81D42@trispen.com> Gerhard H?ring wrote: > On Wed, Oct 03, 2001 at 11:36:05AM +0200, Gerrie Roos wrote: > > Hi! > > Hope it's in order to ask such questions here... > > > > I downloaded Python-2.1.1.tgz, the latest sources I could find, unpacked > > the lot on a FreeBSD3.5 machine read all the compiling/installation > > stuff, etc...then I: > > > > - did 'make clobber' just to make sure... > > - Removed '-ltermcap' from the 'readline' entry in Modules/Setup, as > > advised in the README. [...] > > Any reason you don't use ./configure ; make ; make install ? This > normally is all that is necessary to install Python on Unix. > I tried that right at the very beginning, but since I had problems with the curses module I followed the instructions in the README. 'make clobber' I used instead of 'make clean' between unsuccessful builds, since its more thorough. The rest is the same. > > (Btw. the errors you got were in the curses module. You normally don't > need this module.) > I think if all else fails I will just ignore the curses module, since everything else seemed to compile ok. > > Or: Python 2.1 is in the FreeBSD ports collection. Maybe even 2.1.1, > haven't checked for some time. I used that on FreeBSD 4.2. Perhaps > the port works on the older 3.5, too. > I've actually installed the 2.1.1 package, but I've been having problems getting mySQLclient/pyMySQL working with it ok, and I suspect it might be because the package caters for FBSD >= 4.0. So I opted to compile natively to see if it solves any of my other problems. Thanks in any case, maybe I've got more luck today... > > Gerhard > -- > mail: gerhard bigfoot de registered Linux user #64239 > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 > public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 > reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From martin.franklin at westgeo.com Thu Oct 18 09:52:07 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Thu, 18 Oct 2001 14:52:07 +0100 Subject: Problems with Tk in Python References: <3BCEBC9A.D655929F@dcs.warwick.ac.uk> Message-ID: <9qmmm5$350o$1@mail1.wg.waii.com> Denis wrote: > Problems with Tkinter and _tkinter: > > I have installed Python 2.1.1 and Tcl/tk 8.3 into my directory (sun > solaris). Python seems to work fine after a bit of tuning , but when I > tried to import "Tkinter" (The GUI module in Python), it has come out > the following error messages: -- snip -- Denis I allways add this to the Setup file in Modules before building Python you will have to look at the man pages for ld - cause I can't remember what it does.... I think it adds /usr/local/lib to the 'LD_LIBRARY_PATH' at run time, so you don't have to. # *** Always uncomment this (leave the leading underscore in!): _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ # *** Uncomment and edit to reflect where your Tcl/Tk libraries are: -R/usr/local/lib \ -L/usr/local/lib \ Cheers Martin From uwe at rocksport.de Thu Oct 25 05:41:29 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 25 Oct 2001 09:41:29 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 24) References: <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E@lp.airnews.net> Message-ID: <9r8mo9$7oqsi$2@hades.rz.uni-sb.de> Cameron Laird wrote: | The rest of the stuff seems right, though ... Nope. The correct URL is http://www.ActiveState.com/Products/Komodo/PyXPCOM with a lowercase "y" ... Yours, Uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From skip at pobox.com Thu Oct 4 22:09:45 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 4 Oct 2001 21:09:45 -0500 Subject: Profiling the Python Interpreter Message-ID: <15293.5737.6766.875168@beluga.mojam.com> gb> The problem is evidently the quality of the code produced by gcc gb> versus MSVC. What version(s) of gcc have you tried? What optimization levels? I notice marked improvements in performance if I tailor the optimization level to the hardware better. -mcpu=pentiumpro seems to have a fairly substantial positive impact if you're running on a P-III, for instance. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From sholden at holdenweb.com Mon Oct 29 04:18:55 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:18:55 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3BDC0341.8A213560 at engcorp.com... > Christy J wrote: > > > > I need a binary search tree in python that uses classes. I'm trying to > > count words from a file and spit out the number of times they occur > > and in alphabetical order. I got bintree[ [key, data], left, right] > > but don't know how to implement using classes. > > I'd be interested to hear which school is teaching with Python. > > Schools progressive enough to take a chance (a small one, mind > you, but they don't usually seem to think so) on something > not mainstream (i.e. not Java) are few and far between. > Strange how the mention of "school" and "homework" seems to have stopped the original poster from responding on BOTH threads. This is a pity, since c.l.py is one of the few groups where creative help (although not canned solutions) might be available. Guess it was the canned solution that was sought regards Steve -- http://www.holdenweb.com/ From john.thingstad at chello.no Sun Oct 21 16:15:04 2001 From: john.thingstad at chello.no (John Thingstad) Date: Sun, 21 Oct 2001 22:15:04 +0200 Subject: a better prime number generator Message-ID: <20011021203812.BLUF12720.mta01@mjolner> > hi all, > I have just been introduced to pyton and find it a very good ( takes > off all the bookwork ) language. I was trying to develope a ast prime > number generator. I designed the following algo. Can you please > suggest a faster one or modifications to this only to make it faster >... This should work fast up to say 10000. Beond that you will need to use Fermant's little theorem and Pomerance quadric sieve. But that is to lengthy to discuss here. def prime(n): """Simple prime generator using Aristophanes sieve.""" set = range(2, n) for n in range (2, int(math.sqrt(n)), 2): set = [x for x in set if x== n or x % p != 0) return set From tdelaney at avaya.com Sun Oct 28 23:38:53 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 29 Oct 2001 15:38:53 +1100 Subject: python binary search Message-ID: > From: Jeff Dunnett [mailto:jdunnett at uoguelph.ca] > Jeff Dunnett wrote: > > Duh. What an idoit I am. Poor spelling you can tell I am > not an English major or > > I probably would have picked up on the ocmment. > That should say comment. I should resist, but I can't. So, what is this "it" that you do? (idoit). Tim Delaney From chris.gonnerman at newcenturycomputers.net Thu Oct 11 21:55:59 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 11 Oct 2001 20:55:59 -0500 Subject: Problem : building a module ... References: Message-ID: <005001c152c1$11918600$0101010a@local> On Thu, 11 Oct 2001, dag4004 wrote: > I want to creat a new module. It is a module wich use the Nano-X GUI Client > functions. To do so i creat a nanoxmodule.c with the Makefile.pre.in .... > and i can creat a nanoxmodule.so > BUT in python when i enter : import nanox > my lovely interrpreter say me that the Nano-X function are unknown. > It is right because the function are not linked in nanoxmodule.so but how > could i force the linking of this functions in my nanoxmodule.so, i have the > library libnano-x.a but how could i "put" it in nanoxmodule.so The build command for nanoxmodule.so should automatically contain -lnano-x to include the libnano-x.a file (assuming it's in a standard location). The Setup.in file should look something like: *shared* nanox nanoxmodule.c -lnano-x Then the command: make -f Makefile.pre.in boot should do the build correctly. I assume you are on Solaris or Linux (based on the .so extension); correct me if I am wrong. On Linux the object files within the libnano-x.a file would need to be compiled in shared mode (-fPIC on the gcc or libtool command line) or the resulting nanoxmodule.so file would not work; you would get linkage errors... From mlh at idi.ntnu.no Thu Oct 4 18:13:53 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 5 Oct 2001 00:13:53 +0200 Subject: Python is better than free (was Re: GNU wars again) References: <200110030312.f933COK01047@smtp2.idir.net> Message-ID: <9pimv1$ccf$1@tyfon.itea.ntnu.no> "Laura Creighton" wrote in message news:mailman.1002129304.5035.python-list at python.org... > Stop discussing the GPL in comp.lang.python. It makes people unsubscribe > in droves. This is how much some people hate discussions about the GPL. > > Laura Creighton Hm. It was getting a bit crowded anyway... -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From jhauser at ifm.uni-kiel.de Wed Oct 17 03:20:33 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 17 Oct 2001 09:20:33 +0200 Subject: READ FILE UNTIL THE Xth SPACE IS ENCOUNTERED... References: Message-ID: <87ofn67mwu.fsf@lisboa.ifm.uni-kiel.de> Normally the data is ordered table like in the ascii-file. So reading by line (xreadlines) and splitting by space (string.split) and map (map) the float function to the resulting list is the straight-forward way. But it becomes slow for files in the Mb range, because of the loop but mainly for the many function calls for conversion. A pretty fast module for reading table structured numbers is the TableIO (google) package. Also scipy contains a specific function for doing this. To your specific question, if the floats are formatted evenly, you can utilize the byte argument of the file.read() method, to read an exact number of bytes. HTH, __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From l0819m0v0smfm001 at sneakemail.com Fri Oct 5 23:37:53 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Sat, 06 Oct 2001 03:37:53 GMT Subject: Generating a random number References: <9plkkk$98r$1@ins22.netins.net> <4cnsrtsj7ks3jc6emj39ksod2ipmr9f0bb@4ax.com> Message-ID: <3BBE4728.40101@sneakemail.com> Dale Strickland-Clark wrote > > from whrandom import randint > > print randint(1, 10) whrandom is deprecated. Use random instead. Joshua From gb at cs.unc.edu Fri Oct 5 08:53:11 2001 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 05 Oct 2001 08:53:11 -0400 Subject: Profiling the interpreter from within References: <1uaqrtgvbfcfjmm5gf1a26226p8j16m6ub@4ax.com> Message-ID: Courageous writes: > > While this isn't a bad idea, the interpreter folks don't really need > to see it profiled. I profiled it in _Quantify_ a while back and > decided that there was little that could be done in terms of > obvious optimizations to the Python interpreter code. I wouldn't use this imagined profiling capability to tune the interpreter but rather to evaluate my use of it and the performance of my extensions. For example, I could imagine certain programs spending huge amounts of time in malloc and free if the program created and destroyed many small objects. This might inspire me to modify the memory allocation in Numeric (or whatever) to cache small blocks instead of freeing them. I have seen large performance improvements in other matrix packages by applying this simple optimization. But... I'd like to have an idea of how much is there to be gained before going to the trouble. Thus the desire for an easy to use profiler that sees everything. gb From fredrik at pythonware.com Mon Oct 29 15:46:53 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Oct 2001 20:46:53 GMT Subject: passed extra info to repl function References: Message-ID: <1fjD7.3354$Z_1.574859@newsc.telia.net> Michael P. Soulier wrote: > def replace(match): > global replacement_dict > key = match.group(1) > if replacement_dict.has_key(key): > return replacement_dict[key] > else: > return '' use default argument binding: def replace(match, replacement_dict=replacement_dict): key = match.group(1) if replacement_dict.has_key(key): return replacement_dict[key] else: return '' or: def replace(match, get=replacement_dict.get): return get(match.group(1), '') From john at yates-sheets.org Sun Oct 28 22:33:30 2001 From: john at yates-sheets.org (John S. Yates, Jr.) Date: Mon, 29 Oct 2001 03:33:30 GMT Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> <3BDCC4C9.B0597DF1@uoguelph.ca> Message-ID: <8djpttobn2i18avnq3817bmg1ua6eavq8r@4ax.com> On Sun, 28 Oct 2001 21:54:01 -0500, Jeff Dunnett wrote: >Emile van Sebille wrote: > >> "Jeff Dunnett" wrote in message >> news:3BDCA674.FF268D0E at uoguelph.ca... >> > >> > [..SNIP..] >> > quite a lot of fallowers who like Python. ^^^^^^^^^ >> > >> >> >> >> Hopefully, they haven't simply put themselves out to pasture... > >I am not sure what I mean by your comment? Emile was punning on "fallow" (as in to let a pasture lie fallow) versus "follow". /john -- John Yates 40 Pine Street Needham, MA 02492 781 444-2899 From richard at bizarsoftware.com.au Mon Oct 15 23:20:31 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Tue, 16 Oct 2001 13:20:31 +1000 Subject: Regex mystery: matching or In-Reply-To: References: Message-ID: <0110161320312B.11044@ike> On Monday 15 October 2001 11:25, Gustaf Liljegren wrote: > I'm trying to match HTML or elements with the 'href' attribute. > For some reason, the regex can't find any match if I put a sample match in > the context of something else. I only need to add a space before, as in the > string 's3' below. > > >>> re_link = re.compile(r'<(a|area)[^>]+href.*/?>', re.I | re.M) > >>> s1 = '' > >>> s2 = '' > >>> s3 = ' ' > >>> re.match(re_link, s1).group() > > '' > > >>> re.match(re_link, s2).group() > > '' > > >>> re.match(re_link, s3).group() > > Traceback (most recent call last): > File "", line 1, in ? > re.match(re_link, s3).group() > AttributeError: 'None' object has no attribute 'group' Change "match" to "search" in the above. Note the distinction from the library ref. """ search(pattern, string[, flags]) Scan through string looking for a location where the regular expression pattern produces a match, and return a corresponding MatchObject instance. Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string. match(pattern, string[, flags]) If zero or more characters at the beginning of string match the regular expression pattern, return a corresponding MatchObject instance. Return None if the string does not match the pattern; note that this is different from a zero-length match. Note: If you want to locate a match anywhere in string, use search() instead. """ Richard From steven.smith at LEVEL3.com Tue Oct 2 12:30:51 2001 From: steven.smith at LEVEL3.com (steven.smith at LEVEL3.com) Date: Tue, 2 Oct 2001 10:30:51 -0600 Subject: list remove Message-ID: <1165F677B8C4D411B71C0008C791EC4A71E3AA@N0225IDC1.oss.level3.com> The python tutorial at http://www.python.org/doc/current/tut/node7.html#SECTION00710000000000000000 0 has the section more on lists where it gives the function remove(x). I am trying to use this function to delete elements out of my list, but it only deletes every other list. >>>foo = [1, 2, 3, 4, 5] >>>for bar in foo: ... foo.remove(bar) >>>foo [2, 4] Is this an error on my part, pythons list type or am I misinterpretting what remove does? I have tried this on both 2.1 and 1.5.2. Thanks. Steve From smarsh at hotmail.com Thu Oct 25 00:58:16 2001 From: smarsh at hotmail.com (scott) Date: Thu, 25 Oct 2001 04:58:16 GMT Subject: Question: CPython References: Message-ID: <3BD79BBC.B2FA669B@hotmail.com> Sean 'Shaleh' Perry wrote: > > On 24-Oct-2001 K?roly Ladv?nszky wrote: > > What is CPython and where is it available? > > > > Thanks for any help, > > > There is > a new thing called 'JPython' which is a python implementation in Java Called 'Jython' now. Its predecessor was JPython. http://www.jython.org -- Colorless green ideas sleep furiously. Chomsky From demian0311 at yahoo.com Thu Oct 18 01:43:37 2001 From: demian0311 at yahoo.com (demian neidetcher) Date: 17 Oct 2001 22:43:37 -0700 Subject: J2EE equivalent in Python References: Message-ID: <1668af80.0110172143.54542373@posting.google.com> j2ee has some good patterns and i think you are correct in persuing that or at least seeing that as a good way to build enterprise applications. besides that there is a lot of industry momentum behind it (you can decide if thats good or bad). something that hasn't been done (as far as i know) is to integrate jython into j2ee. that would be interesting. where i work, some teams have used jython to do unit tests on java code that were running as parts of a j2ee application. but if you really want to stay with c-python, zope seems to be a very good framework. From -$Paul$- at verence.demon.co.uk Wed Oct 24 08:10:10 2001 From: -$Paul$- at verence.demon.co.uk (Paul Wright) Date: 24 Oct 2001 13:10:10 +0100 Subject: problem importing xml.xpath References: <3BD5C38E.61DCB7B0@iems.nwu.edu> Message-ID: <9r6b32$74s$1@verence.demon.co.uk> In article , Martin von Loewis wrote: >Leonardo B Lopes writes: > >> I can't find a way to import the xpath library with python2.0. I can >> see it in the right place, in the site-packages dir. I notice that there >> is also an XML directory in the main distr. directory, so I tried moving >> the dirs there too, but that didn't work. All I want to do is get the >> two demos XmlTree.py/XmlEditor.py working. Does anyone have any idea >> what is going on? > >Where did you get xml.xpath from? If you got it from 4Suite, it should >be installed as site-packages/_xmlplus/xpath. I had a problem installing 4Suite on Windows the other day. I believe the installer should put some code (__init__.py, maybe?) in _xmlplus so that the main XML packages can pick up the extensions (this is certainly what happens in my Debian install of an earlier version of 4Suite), but for some reason the installer only created the extra sub-directories off _xmlplus for xpath and xslt, so Python was unable to import xml.xslt. What's in your _xmlplus directory, Leonardo? -- ----- Paul Wright ------| "Just once, I wish we would encounter an alien menace -paul.wright at pobox.com--| that wasn't immune to bullets" - The Brigadier, http://pobox.com/~pw201 | "Dr. Who" From gustafl at algonet.se Mon Oct 15 19:37:25 2001 From: gustafl at algonet.se (Gustaf Liljegren) Date: Mon, 15 Oct 2001 23:37:25 +0000 (UTC) Subject: re.findall() is skipping matching characters References: Message-ID: "Fredrik Lundh" wrote: >try using a non-capturing group instead: (?:x) instead of (x) Nah, enough of Python peculiarities already. It's hard enough to learn regexes without adding a strong Python flavor to it. ;-) >or better, use the right tool for the task: sgmllib That worked precisely as I wanted. Thank you very much. Gustaf Liljegren From peter at engcorp.com Tue Oct 30 01:35:57 2001 From: peter at engcorp.com (Peter Hansen) Date: Tue, 30 Oct 2001 01:35:57 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> <3BDCC4C9.B0597DF1@uoguelph.ca> <8djpttobn2i18avnq3817bmg1ua6eavq8r@4ax.com> Message-ID: <3BDE4A4D.92C0FBC@engcorp.com> Steve Purcell wrote: > > Steve Holden wrote: > > But it wasn't that funny, since nothing is ever simply black or white, good > > answers must always conside the graze. > > I hope the original poster won't be cowed by these yokes at his expense. Look guys, this is a bunch of bull. Can we just moove on? -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From gh_pythonlist at gmx.de Fri Oct 19 00:41:23 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 19 Oct 2001 06:41:23 +0200 Subject: Method returns self? In-Reply-To: ; from ignacio@openservices.net on Thu, Oct 18, 2001 at 11:36:46PM -0400 References: Message-ID: <20011019064121.A571@lilith.hqd-internal> On Thu, Oct 18, 2001 at 11:36:46PM -0400, Ignacio Vazquez-Abrams wrote: > On Thu, 18 Oct 2001, Roy Smith wrote: > > > I've got a data file parser that returns a data object. You call it > > something like this: > > > > parser = myParser() > > data = parser.parse(filename) > > > > Now, I want to give the data class a verify() method. The parser only > > ensures that the data file has a parsable syntax, but there are also a > > number of higher-level semantic checks that we might want to do. I have in > > mind something that you would call like this: > > > > parser = myParser() > > try: > > data = parser.parse(filename).verify() > > except data.VerifyError: > > print "you bozo" > > > > The idea is that verify() is a method of the data class which either > > returns self, or raises an exception. The code would look something like: > > > > class data: > > def verify (self): > > if everthing is cool: > > return self > > else: > > raise VerifyError > > > > My question is, will I run into garbage collection or reference count > > problems if a method returns self? I can't quite put my finger on it, but > > I have this vague feeling I might end up with a self-referential object. You should only be getting refcount problems when you have circular references, like that: def foo(): x = {}; y = {}; x[1] = y; y[1] = x x and y are referencing each other and normally won't be collected when foo() returns. But they will be if you build your Python with "--with-cycle-gc". I don't know if this option is already activated by default. As Ignacio already said, in your case there are no circular references. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From emile at fenx.com Wed Oct 31 12:13:02 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Oct 2001 09:13:02 -0800 Subject: newbie question References: Message-ID: <9rpbr2$us4bd$1@ID-11957.news.dfncis.de> " 1" wrote in message news:yXVD7.6251$QL2.175221 at e3500-atl1.usenetserver.com... > ok to keep it simple. > I am running win98se w/ python 2.1 installed. I have tried this in both > python shell and in command line. > > Just to keep it simple I wrote a file called "hello.py". all that it > contains is a print command (print" hello world!"). I saved the command in > the python dir in my PC and named it "hello.py". > > When I got to run the file (by typing python hello.py)i get this error > message: > > >>> python hello.py > SyntaxError: invalid syntax > >>> > > Is there anything that i missed or did wrong. This is just a simple little > example of a bigger problem. You've got a syntax error in the file, probably extra spaces C:\>echo print "Hello World!" > test.py C:\>type test.py print "Hello World!" C:\>python test.py Hello World! Here's a wrong example: # there's an extra space before print C:\>echo print "Hello World!" > test.py C:\>python test.py File "test.py", line 1 print "Hello World!" ^ SyntaxError: invalid syntax Note how the '^' points at the problem. You should get something similar. HTH, -- Emile van Sebille emile at fenx.com --------- From rharkins at thinkronize.com Tue Oct 23 16:57:45 2001 From: rharkins at thinkronize.com (Rich Harkins) Date: Tue, 23 Oct 2001 16:57:45 -0400 Subject: POLL in different OSes In-Reply-To: <3BD5D520.7050007@movilogic.com> Message-ID: That is true for some cases at least. However, I frequently run into a case where I am only concerned about a small handful of descriptors (two or three) and creating three lists for each issuance of select can be expensive (especially if the timer goes off more frequently than file descriptors). Also I often end up needing to add lists together to get the read, write, or exception sets I want which also creates temporary objects. If I really needed to iterate through the mess I could use a list comprehension or a reduce call (especially if the polled objects handled iszero). which would only generate 1 temporary object instead of up to six. Anyway, it was just a thought... Rich > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Lucio Torre > Sent: Tuesday, October 23, 2001 4:38 PM > To: python-list at python.org > Subject: Re: POLL in different OSes > > [ SNIP ] > isnt iterating over every object to see if its ready or not (again) too > expensive? > > lucio > > > -- > http://mail.python.org/mailman/listinfo/python-list > From pieter.deceuninck at cs.kuleuven.ac.be Tue Oct 23 12:47:44 2001 From: pieter.deceuninck at cs.kuleuven.ac.be (Pieter De Ceuninck) Date: Tue, 23 Oct 2001 18:47:44 +0200 Subject: combining large C-programme with Python Message-ID: <3BD59F30.587006A@cs.kuleuven.ac.be> Hello, I'd like to know if anyone can give some projects where existing C-code was modularized using Python. I'm planning to redesign (refactor) a large C-code with a new top-layer of Python and the necessary adaptations (as few as possible) in the underlying (numerical, scientific computing) C-code. I'm not talking about writing _new_ scientific computing python-code with numpy or so, just using existing C-code. If no such projects are known, what would be a good way to refactor that huge code ? Complete re-implementation is not an option :-) thx, Pieter From donn at drizzle.com Fri Oct 12 01:53:25 2001 From: donn at drizzle.com (Donn Cave) Date: Fri, 12 Oct 2001 05:53:25 -0000 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <7xsncpxxc6.fsf@ruckus.brouhaha.com> Message-ID: <1002866005.11653@yabetcha.drizzle.com> Quoth Paul Rubin : ... | I think it's a mistake to expose too much abstract machinery in | Python, which is supposed to be a practical language. Like you, I | don't see a need for a lot of "eyebrows" in loops, but I feel Python | suffers by ignoring the tried and true. | | Just today I had a bug that went something like: | | n = compute_number_of_items() | for i in range(n): | try: process_an_item(items[i]) | except: break | update_database('number of items processed = ' % i) | | The corresponding C code would have been similar except instead | of "for i in range(n)" it would have said "for (i=0; i Message-ID: <3BD856A9.2FF5B81C@bioreason.com> Phlip wrote: > > Hot Nyp: > > Thanks to the group for the answer to my last question here (whatever > it was). > > Today we enter a realm where the documentation for the Tk Canvas goes > not. > > Ogle this code: > > from Tkinter import * > canv = Canvas() > canv.pack() > canv.create_line( 5, 5, 50, 5) > canv.create_line( 50, 5, 100, 50) > canv.create_line(100, 50, 150, 50) > mainloop() > > A line with a dog leg in it, right? > > I don't want straight lines or angles here. I want a nice smooth > spline that starts at the first point, curves past the middle two, and > ends at the end point. Have you tried something like this? (Uh, I haven't; this is just based on the Tk man pages :) canv.create_line(5, 5, 50, 5, 100, 50, 150, 50, smooth = 1) -- Mitch Chapman Mitch.Chapman at bioreason.com From alan.gauld at bt.com Thu Oct 25 11:10:50 2001 From: alan.gauld at bt.com (Alan Gauld) Date: Thu, 25 Oct 2001 16:10:50 +0100 Subject: learn OOP with Python References: <9r97co$cme$07$1@news.t-online.com> Message-ID: <3BD82B7A.5030801@bt.com> > a new employee will write scripts for us in python, but he has not much > experience with OOP. Are there any books that teach OOP concepts using > Python ? Several, although not just OOP. Most of the Python books available(including mine :-) have OOP sections. There are lots of general OOP books too - Booch etc... that teach OO principles. > Is there a good source to give somebody with experiences in Pascal > and VBScript an introduction in the OO way of thinking ? You could try my online tutor which covers Python and QBASIC It has a chapter on OOP and a Case study which includes objectifying a procedural app: http://www.freenetpages.co.uk/hp/alan.gauld/ But its designed for absolute beginners and is likely too elementary. The other source for all things OO is the cetus-links web site.. HTH, Alan G. From slinkp23 at yahoo.com Sun Oct 7 14:24:55 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Sun, 07 Oct 2001 18:24:55 GMT Subject: How could i slim Python for embedded ? References: <3bbf6f3e$0$3649$626a54ce@news.free.fr> Message-ID: On Sat, 6 Oct 2001 19:22:27 -0400, Dave Cinege wrote: >On Saturday 06 October 2001 16:48, dag4004 wrote: >> Hello, >> >> I want to use Python for an embedded computer so don't > >Diesel Dave's super secret small python recipe: > Do not compile debug info (remove -g) > Compile -static to eliminate any library requirments Also look at all your compiler options - some optimizations affect size. For example, after stripping, gcc -Os saves me about 10k compared to gcc -O2 (with python 2.1). --PW From rafial at well.com Fri Oct 5 12:04:38 2001 From: rafial at well.com (Wilhelm Fitzpatrick) Date: Fri, 05 Oct 2001 16:04:38 -0000 Subject: why are *two* ctrl-D's needed with readline() Message-ID: <9pklmm+frq@eGroups.com> I was writing a little python script using for line in sys.stdin.readlines() : to iterate through input, and I noticed that I had to press ctrl-D TWICE to terminate input. This same behavior appears whether I am in interactive mode or running a script, and I confirmed the same behavior using both python 2.0.1 and 1.5.2. Interestingly, enough for line in sys.stdin.read().splitlines() : terminates on the first ctrl-D (as I would expect). Why the strange behavior for readlines()? is this an implemenation limitation? A bug? A feature that I do not properly understand? I searched the docs and the mailing list archives but I could not find enlightenment. From pastorinha at ieg.com.br Sat Oct 13 22:13:18 2001 From: pastorinha at ieg.com.br (Keila - Curitiba - Pr) Date: Sat, 13 Oct 2001 23:13:18 -0300 Subject: UM SITE DE PROTESTO Message-ID: Ol?! Veja meu site pessoal no "Tripod.com.br". Basta clicar no endere?o abaixo. GARANTO SER SUI-GENERIS - CLIQUE ABAIXO: http://pastorinha.tripod.com.br/seminarista Mais de 61.000 internautas visitaram a PG., existe 7 ?lbuns: Se voc? quiser, por favor, indique minha Home Page, a outros Internautas. Mais detalhes, se comunique, passe um e-mail, que responderei brevemente. Dentro da Home Page, ao lado das fotos, voc? poder? saber muito mais sobre mim! Obrigada. e-mail: pastorinha at ieg.com.br Beijos:- Keila - Curitiba - Pr - Podes falar comigo, direto dela. Brevemente uma Carta Aberta. http://pastorinha.tripod.com.br/seminarista "Esta mensagem ? enviada com a complac?ncia da nova legisla??o sobre correio eletr?nico, Se??o 301, Par?grafo (a) (2) (c) Decreto S. 1618, T?tulo Terceiro aprovado pelo "105? Congresso Base das Normativas Internacionais sobre o SPAM". Este E-mail n?o poder? ser considerado SPAM quando incluir uma forma de ser removido. Para ser removido de futuros correios, simplesmente responda indicando no Assunto: REMOVER" From GOALSETTING at MAIL.COM Sat Oct 13 21:03:06 2001 From: GOALSETTING at MAIL.COM (INTERNALANTENNAS.COM) Date: Sat, 13 Oct 2001 20:03:06 -0500 Subject: FREE ANTENNA BOOSTER FOR YOUR CELL PHONE..NO NEED TO BUY ANYTHING Message-ID: An HTML attachment was scrubbed... URL: From skip at pobox.com Wed Oct 17 19:09:55 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 17 Oct 2001 18:09:55 -0500 Subject: Help optimize a script? In-Reply-To: References: <3Nkz7.138277$5A3.44609227@news1.rdc2.pa.home.com> Message-ID: <15310.4035.2429.264046@beluga.mojam.com> >> After compling 2.1.1 for HP-UX so I would have access to the join() >> method of sting, I started to wonder how much of this speed increase >> (if any) is from just using 2.1.1 over 1.5.2 ? Any ideas? David> Probably not too much if at all. In addition, 2.x is generally a bit slower than 1.5.2, so anything you'd gain by using string methods would probably get lost elsewhere. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From thomas.heller at ion-tof.com Thu Oct 25 13:46:57 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 25 Oct 2001 19:46:57 +0200 Subject: HELP -- py2exe failed to build app that uses scipy.plt References: <436bca17.0110181944.247f4ecd@posting.google.com> <16f9b1ea.0110250718.7ccc7fe9@posting.google.com> Message-ID: <9r9j6h$sak0p$1@ID-59885.news.dfncis.de> "eric" wrote in message news:16f9b1ea.0110250718.7ccc7fe9 at posting.google.com... > Hey Phil, > > I haven't ever used py2exe, so I'll be of little help. I can't say > I'm surprised though. The __init__ files in SciPy have some strange > importing > practices that may make it hard for py2exe to determine the needed > modules. I don't know how hard it is to fix this sort of thing -- or > even if it is the problem. > > You could try and pull plt out of scipy and use it stand alone, but > would require at least some hacking as there are some dependencies. > > sorry I don't have more info. > > eric An additional problem (I've looked into it) leading to the syntax error Phil gets is that scipy contains files with very strange line separators '\r\r\n' IIRC. Python has no problem executing or importing them, but py2exe uses compile() which does not accept this. Thomas From madsdyd at challenge.dk Mon Oct 1 14:01:40 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 20:01:40 +0200 (CEST) Subject: Python embedding & question about autoconf and dynamic linking In-Reply-To: <9pa176$v76$1@chabry.caltech.edu> Message-ID: On 1 Oct 2001, Titus Brown wrote: > >I will continue to hack on the KDE_CHECK_PYTHON script - what are you > >using for PyWX? > > *blush* Nothing. "Hey, does it compile? Great! Oops. Missing symbols? > Post to the list." Well, Gerhard H?ring pointed out the distutils.sysconfig.get_config_vars function for me, which appears to solve most problems, at least for version 1.5.2 and forward. (Have not checked older versions). Together with the stuff I found in KDE_CHECK_PYTHON and the stuff from pygtk, I _think_ I may be able to hack together some autoconf stuff to resolve this for any version of Python, that is never than or 1.5.2 (Which is the version with RedHat 7.0 for what it is worth - not that I care so much about distributions, but that should mean that it is quite widespread. I will probably post it to this list (for people to ignore ;-) when I am done. Wheter or not I actually make it, depends a little on wheter or not I am actually going to use Python for my project. > >Hmm. So, I should actually be able to create a .so on an endusers machine, > >_if_ the original python installation was built with -fpic. Otherwise I > >have to recompile the python installation. > > right. Great - that means that I can optionally do this (since it seems that Python defaults to -fPIC on most platforms). Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk NT is a closed box of point tools linked by an untouchable matrix of invisible semaphores. These bonds are surrounded by a blizzard of mystifying, contradictory, and forever-changing OS documentation. Under an NT regime, almost all Unix users will lose the ability to exert low-level control over data and applications. From thamza.nospam at flash.net Fri Oct 26 17:00:20 2001 From: thamza.nospam at flash.net (Tim H) Date: Fri, 26 Oct 2001 21:00:20 GMT Subject: BOA GUI builder? References: <3BD9CC09.2B1AB020@mitre.org> Message-ID: The version in CVS is much further along (0.0.13). You might want to try that. It works for me. You do have to modify it slightly, it is looking for wxPython 2.30 and we are both using 2.3.1, but if you got BOA 0.0.5 to work you should have no probs with that. Tim H "Angel Asencio" wrote in message news:3BD9CC09.2B1AB020 at mitre.org... Greetings: I got the BOA Python IDE from http://boa-constructor.sourceforge.net/. I looks great, but when I went to save the WxFrame.py from the tutorial, it gave me a Win2000 error, but I ignored it. Then when I went to save WxApp.py it crashed. I have Win2000, BOA 0.0.5, wxPython 2.3.1 and Python 2.1 Do I need to get some patch to stabilize BOA? Thanks, -- -Angel From aleax at aleax.it Tue Oct 2 18:12:39 2001 From: aleax at aleax.it (Alex Martelli) Date: Wed, 3 Oct 2001 00:12:39 +0200 Subject: "cgipython" or equivalent for Python 2.1.1, NT (IIS4)? References: <9pcbqm$r5v$1@serv1.iunet.it> <9pcdck$hagnu$1@ID-59885.news.dfncis.de> Message-ID: <9pde4n$au1$2@lancelot.camelot> Thomas Heller wrote: > "Alex Martelli" wrote in message > news:9pcbqm$r5v$1 at serv1.iunet.it... > [cgi-python is still 1.5.2] ... > I've once built with Gordon's installer a single file > python interpreter (needing only a few dlls and pyds), > see http://starship.python.net/crew/theller/installer. > This also is only 1.5.2, but the technique should also > work with newer pythons... Good point -- I don't really need a single-file setup, I can perfectly well afford to upload several DLL's and PYD's at its side. I'll have to look into it, thanks! Alex From mlerner at pacman.gpcc.itd.umich.edu Tue Oct 23 15:05:16 2001 From: mlerner at pacman.gpcc.itd.umich.edu (Michael George Lerner) Date: Tue, 23 Oct 2001 19:05:16 GMT Subject: Speeding up a regular expression References: Message-ID: Chris Liechti wrote: > extending strings does require lots memory allocations and compying the > strings, a list is far more efficient when changes are made on it. > if the data comes from a file you could also use f.readlines() and omit > split(). it originally came from a file, but i only care about a small piece of the file, which i give to my function as a string. i think passing in the whole file and using readlines() would slow it down, but i'll check. > return '\n'.join(filter(myRe.match, lines)) yup .. someone else emailed me about using a list instead of extending the string. doing that and using filter makes it run fairly quickly. i'm not so worried about speeding up the regular expression now, but it would still be interesting. many thanks -michael From web.mail at lycos.com Tue Oct 30 18:55:00 2001 From: web.mail at lycos.com (Alan Green) Date: 30 Oct 2001 15:55:00 -0800 Subject: Python wins again! Message-ID: <270c68fe.0110301555.7b170573@posting.google.com> A colleague of mine - who wishes to remain anonymous to the world at large - just sent me the following. Waaaayyy cool! > Just a little of tale of why I enjoy having Python as a tool. > > I had a time, represented in the standard Unix > seconds-since-epoch format. > I wanted to know what the date of this time was, and for some > reason couldn't do this in my head. > > Now, I knew that the Python time module could do this, but I > couldn't for the life of me remember which method I needed. > > Enter my hack (done at command prompt) > > >>> import time > >>> a = 941598773 > >>> for f in dir(time): > ... str = "time.%s(%d)" %(f,a) > ... try: > ... print eval(str) > ... except: > ... pass > ... > Wed Nov 03 13:12:53 1999 > (1999, 11, 3, 3, 12, 53, 2, 307, 0) > (1999, 11, 3, 13, 12, 53, 2, 307, 0) > >>> > > A small problem is that, while I have the answer, I still > don't know what method it is. I should have written > > print f, eval(str) > > instead. But, as it stands, it was quicker to do this than to > consult the module reference. > He also adds: > Seriously, which of these would you choose? > >>> dir(time) > ['__doc__', '__name__', 'accept2dyear', 'altzone', 'asctime', > 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', > 'mktime', 'sleep', 'strftime', 'time', 'timezone', 'tzname'] For a laugh, just re-read that list and take a guess. > The answer is ctime. Alan. From n8gray at caltech.edu.is.my.e-mail.address.com Tue Oct 2 21:54:50 2001 From: n8gray at caltech.edu.is.my.e-mail.address.com (Nathaniel Gray) Date: Tue, 2 Oct 2001 18:54:50 -0700 Subject: Repost: execfile() confusion References: Message-ID: <9pdrme$j0n@gap.cco.caltech.edu> Tim Peters wrote: > [Nathaniel Gray, being unreasonable ] Perhaps you didn't realize that I posted this message *before* I read your other reply, which immediately cleared things up. >> ... >> Here's a slightly modified version of the files that >> will perhaps make my confusion clear: > > Except there's no point to clearing it up: you're chasing accidents, and > even if you figure out why they're happening, they may change in the next > release. I added this text to the library ref man earlier today, under the > execfile() docs: > > \strong{Warning:} The default \var{locals} act as described for function > \function{locals()} below: modifications to the default \var{locals} > dictionary should not be attempted. Pass an explicit \var{locals} > dictionary if you need to see effects of the code on \var{locals} after > function \function{execfile()} returns. \function{execfile()} cannot > be used reliably to modify a function's locals. I'm glad to see this. It would have saved me a lot of confusion. > Spend a tenth of this energy thinking of a clean way to do > whatever it is you're after, and you could enjoy life again. Considering that what I was after was an understanding of why a seemingly straightforward builtin function was acting deeply weird, I felt that posting to c.l.p *was* the "clean" way to do it. ;-) And who said I ever enjoyed life in the first place?? > Most parts of the local/global behavior are the same; other parts have > changed; what's changed the most is all the text added to the docs telling > people to stop doing things that Guido never believed anyone in their right > mind would even attempt . You seem to think I'm totally off my rocker. That may be true, but my question was sparked by a perfectly reasonable scenario, by any reasonable definition of "reasonable". ;^) I think it would be nice to use Python statements in my configuration files for various Python projects. I don't think it would be nice to put said configuration files on my pythonpath--they're not python modules like 'gracePlot.py', they're configuration files like 'gizmos.config'. I want to do "from 'path/to/gizmos.config' import *" (don't suppose it's worth asking for this syntax to become legal?), but all I really want is to have gizmos.config run through the interpreter and then have access to the variables it defines (i.e. I don't care about having a real module object). I also obviously need to be able to specify the location of gizmos.config since I don't want to have to care whether or not my configuration file ends with '.py', lives on the pythonpath, or has a name that conflicts with some random module somewhere. Thinking about these requirements, a fuzzy memory springs to mind--isn't there a way to execute python code from some given file? Looking at the ref man's docs for execfile it looks like just the thing! Hooray! But then I happen to use this scheme within a function and bizarre things happen. Boo! :-( Anyhow, lest there be any further confusion: there is no further confusion! I just wanted to know if I was witnessing well understood behavior or if I'd found a bug in Python. Now I understand that there *are* no bugs in Python, just implementation quirks that, much like UFOs, are only visible to malcontents, the mentally unbalanced, and grad students. (Not mutually exclusive groups by any stretch of the imagination.) > execfile-is-to-exec-as-delicious-is-to-del-ly y'rs - tim and-as-unichristalmighty!-is-to-unichr-ly y'rs - n8 -- Nathaniel Gray California Institute of Technology Computation and Neural Systems -- From phd at phd.pp.ru Wed Oct 31 11:15:13 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 31 Oct 2001 19:15:13 +0300 Subject: Freeware Python editor In-Reply-To: <3BE01E8F.3A384D4C@alcyone.com>; from max@alcyone.com on Wed, Oct 31, 2001 at 07:53:51AM -0800 References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <3BE01E8F.3A384D4C@alcyone.com> Message-ID: <20011031191513.K21151@phd.pp.ru> On Wed, Oct 31, 2001 at 07:53:51AM -0800, Erik Max Francis wrote: > > > Check out the free Python editor at www.crimsoneditor.com. > > > > Free (like free beer), but not free (like freedom). No source code, > > Windows only. > > And consistent with the term "freeware," as the Subject states. There's > a time for open source advocacy, but it isn't here and now. I am not advocating "open source". I am advocating "free software". Free code, with freedom to read it, modify it and distribute in original or modified form. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From p.vrijlandt at aig.azn.nl Tue Oct 16 03:12:47 2001 From: p.vrijlandt at aig.azn.nl (Patrick Vrijlandt) Date: Tue, 16 Oct 2001 09:12:47 +0200 Subject: Telnetlib - send brk References: Message-ID: <9qgmlh$dku$1@odysseus.uci.kun.nl> "Donnie Miller" > I've been trying the telnetlib library rather than using expect > scripts as I have done in the past. I have had success with it up until > the point where I needed to send a "break" sequence to a server. I have > searched all over various lists and google, but have not found > anything. Does anyone have any idea of how to do this? Telnetlib provides no way to send telnet control characters: IAC = chr(255) # Interpret As Command DONT = chr(254) # DO = chr(253) # WONT = chr(252) # WILL = chr(251) # SB = chr(250) # Subnegotiation Begin GA = chr(249) # Go Ahead EL = chr(248) # Erase Line EC = chr(247) # Erase Char AYT = chr(246) # Are You There AO = chr(245) # Abort Output IP = chr(244) # Interrupt Process BRK = chr(243) # NVT-Break DM = chr(242) # Data Mark NOP = chr(241) # No Operation SE = chr(240) # Subnegotiation End So you have to patch the write method, originally: def write(self, buffer): if IAC in buffer: buffer = buffer.replace(IAC, IAC+IAC) self.msg("send %s", `buffer`) self.sock.send(buffer) so that BRK (and the other telnet commands) also is/are prepended by an IAC character. From slinkp23 at yahoo.com Wed Oct 31 23:33:55 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Thu, 01 Nov 2001 04:33:55 GMT Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <9rp4d8$830$1@tyfon.itea.ntnu.no> <3BE0240A.A2CCAA83@alcyone.com> <3BE099F6.A9E0708F@alcyone.com> <9rq70r$ve8u6$1@ID-11957.news.dfncis.de> Message-ID: On Wed, 31 Oct 2001 16:58:25 -0800, Emile van Sebille wrote: > >"Erik Max Francis" wrote in message >news:3BE099F6.A9E0708F at alcyone.com... >> Paul Winkler wrote: >> >> > But this was before my time. Can anyone who was hacking in the 70s/80s >> > comment on the evolution of these terms? When did "freeware" come to >> > mean "free beer, no source"? (snip) >From the Jargon file: > >freeware /n./ (snip) Yeah, that was the first place I looked it up. I love the jargon file. Unfortunately it doesn't answer my question. --PW From phd at phd.pp.ru Sun Oct 21 08:58:22 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 21 Oct 2001 16:58:22 +0400 Subject: Automatically resume a download w/ urllib? In-Reply-To: ; from chris_moffitt@yahoo.com on Sun, Oct 21, 2001 at 02:02:52AM +0000 References: Message-ID: <20011021165822.A4759@phd.pp.ru> On Sun, Oct 21, 2001 at 02:02:52AM +0000, Chris Moffitt wrote: > I'm trying to develop a small application (mostly for Windows if that > matters), than can download and install binary files stored on a web server. > > I've been able to get urllib to download the file just fine, but what I > would like to do is be able to resume a download if it is cancelled for > some reason. In other words, if I've downloaded 50k of a 200k file, I'd > like to just download the remaining 150k. I think it is impossible with urllib. > Is this possible using HTTP and Apache? If not, what about FTP? If It is possible with Apache (apache supports HTTP Ranges) and httplib, but you'll need some coding. Learn about HTTP headers, especially Ranges. It is also possible with FTP and ftplib, but again, you'll need some coding, and not all FTP servers support download resuming. Learn about ftp commands. We'll very much appreciate if you post your working code here. Good luck. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From engedi at evertek.net Thu Oct 18 23:23:13 2001 From: engedi at evertek.net (Michael Ekstrand) Date: 18 Oct 2001 20:23:13 -0700 Subject: Python + wxPython database app Message-ID: <2a97b6b7.0110181923.500abb40@posting.google.com> Hello, I am beginning work on a large database application, primarily for the Win32 platform, and I would like to write it in Python with wxPython if at all possible. However, I have one problem. I need access to an advanced reporting engine. I'd like to use Crystal Reports - is there a way to use the Crystal Reports viewer from Python/wxWindows? If there is another fairly complete reporting engine that would integrate better into Python/wxWindows, I would be more than willing to consider it. Pythonwin may also be an option for me, if it is easier to integrate a reporting engine into it. However, I'm not terribly keen on that option due to lack of documentation (or is there documentation I am not aware of?). And my final option (besides pure Visual Basic, which I don't really want to do) is a Visual Basic GUI and a Python business logic layer - but this seems like it would be a lot of extra debugging, or am I wrong somehow? Any advice would be most appreciated! Thank you, Michael From thomasNO at SPAM.obscure.dk Wed Oct 31 17:27:08 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Wed, 31 Oct 2001 22:27:08 GMT Subject: Is round() broken? References: Message-ID: "Joseph Wilhelm" wrote in news:mailman.1004561433.28620.python-list at python.org: > Hello again everybody! > > I'm having some troubles with round() now... either I'm doing it > completely wrong or round() is. But here's what I'm getting. > >>>> round( 43583.010000000002, 2 ) 43583.010000000002 round( >>>> 43583.010000000002 ) 43583.0 round( 43583.010000000002, 1 ) >>>> 43583.0 round( 43583.010000000002, 2 ) 43583.010000000002 >>>> > > So, what this is saying.. is that rounding to 1 decimal point > works... but anything beyond that is broken? Rounding negative > will round the number before the decimal point also. You're probably seeing this, because the number cannot be represented precisely as a float. This is the nature of floating point numbers, the way they are represented by most (all?) CPUs today, and thus not a problem specific to Python. the number 1.1 is another example of this. If you want to get a string representation of the number with only 2 digits, try '%.2f' % number. http://www.python.org/doc/current/lib/typesseq-strings.html A python session: >>> round( 43583.010000000002, 2 ) 43583.010000000002 >>> '%.2f' % 43583.010000000002 '43583.01' >>> eval('%.2f' % 43583.010000000002) 43583.010000000002 >>> 43583.01 43583.010000000002 >>> 1.1 1.1000000000000001 > And actually, as a side question.. that number was pulled from a > float8 field in a Postgres database, using the 'pg' module. If I > look at the field through pgAdmin, I just see it as "43583.01", > instead of that whole big long decimal. Is it supposed to come out > like this? Perhaps the float8 datatype is stored differently than python floats ? -- Best Regards Thomas Jensen From chapman at bioreason.com Mon Oct 8 13:31:51 2001 From: chapman at bioreason.com (Mitch Chapman) Date: Mon, 08 Oct 2001 11:31:51 -0600 Subject: += doesn't work in python cgi's (extra info) References: <3BC17D83.A4EEED81@tpg.com.au> <3BC1AD8D.400598AD@tpg.com.au> Message-ID: <3BC1E307.E858E547@bioreason.com> Is it possible that your web server is finding a different (older) Python executable due to cgi environment configuration? It would be interesting to see the cgi output from ... import sys print sys.version Michael Palm wrote: > > Forgot info on my setup: > Redhat 7.1/Apache 1.3.17/Python 2.1 > Seems to work OK on Win95/Apache 1.3.2/Python 2.1 (veeeerrry slooowww) > > Michael Palm wrote: > > > I have a strange error in that += doesn't seem to work in a cgi program > > > > test.py: > > > > #!/usr/bin/env python > > print "Content-type: text/html\n\n" > > j = 1 > > j +=1 > > print " j is %d" % j > > > > works fine with > > python test.py > > > > but as a cgi gives > > j += 1 > > ^ > > SyntaxError: invalid syntax > > > > any ideas?? -- Mitch Chapman Mitch.Chapman at bioreason.com From lists at toadmail.com Sun Oct 28 14:11:27 2001 From: lists at toadmail.com (Jeremy Whetzel) Date: 28 Oct 2001 14:11:27 -0500 Subject: Problem using Random References: <87elno5r1t.fsf@toadmail.com> <3BDB921E.FA7390EF@engcorp.com> Message-ID: <87y9lvshpc.fsf@toadmail.com> Martin von Loewis writes: > My recommendation would be > > mylist = ['a','b','c','d','e','f'] > random.shuffle(mylist) > for i in mylist: > print i Thank you! This is perfect! Jeremy From chris.gonnerman at newcenturycomputers.net Wed Oct 31 08:17:02 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Wed, 31 Oct 2001 07:17:02 -0600 Subject: python-postgres-informix interaction problems References: Message-ID: <005101c1620e$5b651560$0101010a@local> ----- Original Message ----- From: "J Dubal" > Hello good people! > > We have developed Informix RDBMS based commercial applications in > Informix-4gl. It is a good procedural language with embeded SQL. We > are trying to rewrite some apps in Python with postgresql backend for > licensing reasons. Python is good too. We are trying to do this with > latest versions of RH linux (7.2), python 2.1 and postgres 7.1.3. We > face following issues: > > 1. We have to read data from informix db, process it and insert into > postgres. We are using informixdb module (DBAPI 1) which is bit dated. > In Informix we 'select custno, custname, custaddr1, ... into progvar1, > progvar2, ... from custmf where ...' In python, we say fetchone() and > we get a list. We are then moving the elements of the list to named > program variables thus: > pcustno = list1[0] > pcustname = list1[1] > pcustaddr1 = list1[2] > ... as many as reqd > This way we give meaningful names to data items read from db and > process further. > Is there a better, more elegant/efficient way to to this? No comment here, as I know little about the informixdb module. > 2. To insert this data into postgres, we used to use pygres included > in the postgres distribution (latest). We had to stop using this > because we couldn't find a way to find out how many rows it have > inserted, updated or deleted after such statements are executed ie we > couldn't find a way to check the status or return code. So we switched > over to PoPy which is DBAPI2 and where we could check number of rows > affected. Is this right thing to do? Absolutely (IMHO). If it works for you, it's probably right. > 3. In order to insert data into postgres, we have to compose an insert > statement thus: > cur.execute("insert into custmf (custno, custname, > custaddr1,...) > values (%i,'%s','%s'...)" %(pcustno,pcustname, > pcustaddr1....)) > Is there a better way of doing this? Yes! You say that PoPy is DBAPI2; the cursor.execute() method supports formatting in some way or another. Read the DBAPI2 and PoPy documents. In MySQLdb, you can do this (note the triple-quotes, you should be using them also IMHO): cur.execute(""" insert into custmf (custno, custname, custaddr1) values (%s,%s,%s) """, (pcustno,pcustname, pcustaddr1)) Note that comma! You put a %s placeholder with no quoting whereever you need a substitution and let the interface do the work! As I said, read the PoPy docs as DBAPI2 allows several different ways to do this autoquoting, and you need to know which one(s) it supports. > 4. The above string substitute converts program variables holding null > value into 'None' which goes into target table as string 'None'. To > avoid this we parse all columns to check if they are 'None' and > replace them by ''. Is there a better way to do this? Ouch. Try the parameter substitution method above and see what it does. DB API 2.0 does not say how NULLs should be handled. > 5. The above check works only on string variables. We have not found > yet a way to handle nulls in numeric columns. Please suggest a > solution. Ouch ouch. > 6. If the character columns happen to contain quotes, the above > composed insert statement breaks. Please suggest a solution. Here the parameter substitution should work OK; quoting of quotes should be supported automatically if you let the interface handle the substitution. > Any help is greatly appreciated. > Thanks in advance. Hope this helps. From -$Paul$- at verence.demon.co.uk Sun Oct 7 16:34:58 2001 From: -$Paul$- at verence.demon.co.uk (Paul Wright) Date: 7 Oct 2001 21:34:58 +0100 Subject: Newbie question about running scripts References: <3BBEC9FB.8080709@sneakemail.com> Message-ID: <9pqe9i$h0q$1@verence.demon.co.uk> In article , Lenny wrote: >I tried downloading a lesson plan from a kids summer camp. This >included step by step lesson plans and sample programs and activites. >I was doing well until they got to the import command. I downloaded >the mod, then tried writing the program but it immediately came back >with"unable to locate file". Am I supposed to load mods to a >particular folder or list an additional path in the autoexe. file for >the location of these mods, or do I need to have the folder opened on >the desktop in the background in order for it to see it. I'm guessing this is the LiveWires stuff, in which case you should have a look at the README.txt file which comes in the .zip file with the python module, as this tells you how to install it: """ Get a command prompt (DOS prompt, shell, or whatever your system calls it). Change into the directory where you've unpacked this archive. Run the setup.py script that comes in the package, by typing: python setup.py install If you get an error message from Python about the distutils package, you've forgotten to install it (see "What you will need" above). If you get a message from your system saying that it cannot find python, you'll need to make sure that the python executable is on your PATH, or provide the path to it explicitly, eg: c:\program files\python\python setup.py install """ If you're using the default Python install on Windows, you will definitely need to give the full path to Python when you run the setup script, as it says in the last paragraph. At some stage I will get round to making "install" the default action of the setup script so Windows users will just be able to click on it. -- ----- Paul Wright ------| Dancing is a perpendicular expression of a horizontal -paul.wright at pobox.com--| desire. --Dorothy Parker http://pobox.com/~pw201 | From loewis at informatik.hu-berlin.de Mon Oct 15 10:54:00 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 15 Oct 2001 16:54:00 +0200 Subject: python + xml performance compared to Java and C++ ?? References: Message-ID: "Markus Jais" writes: > does anyone have experiences how fast xml processing > and XSLT processing with python (using PyXML and 4Suite tools) > is, compared to Java and C++ (using the apache tools, like > Xalan, Xerces....) I have once compared Xerces/Java with PyXML Expat, see http://mail.python.org/pipermail/xml-sig/2000-October/003610.html Add that time, I found the Java parser to be an order of magnitude slower than Expat. Regards, Martin From kragen at dnaco.net Tue Oct 16 17:23:52 2001 From: kragen at dnaco.net (Kragen Sitaker) Date: Tue, 16 Oct 2001 21:23:52 GMT Subject: Number of args in a function References: <12e3779b.0110161239.7e71bb13@posting.google.com> Message-ID: In article , Skip Montanaro wrote: > Mark> Given a function f, how many arguments does it take? >>>> def foo(a,b,c,*args,**kwds): >... pass >... >>>> foo.func_code >", line 1> >>>> foo.func_code.co_nlocals >5 >>>> foo.func_code.co_varnames >('a', 'b', 'c', 'args', 'kwds') co_nlocals isn't right; Mark asked for co_argcount: >>> def baz(a, *c, **d): ... e = a + c + d.keys() ... return e ... >>> baz.func_code.co_argcount 1 >>> baz.func_code.co_varnames ('a', 'c', 'd', 'e') >>> baz.func_code.co_nlocals 4 baz.func_code.co_flags tells you whether the function accepts *arg and/or **arg as well as the positional args in co_argcount. -- Kragen Sitaker Perilous to all of us are the devices of an art deeper than we possess ourselves. -- Gandalf the White [J.R.R. Tolkien, "The Two Towers", Bk 3, Ch. XI] From madsdyd at challenge.dk Sun Oct 7 13:13:48 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Sun, 7 Oct 2001 19:13:48 +0200 (CEST) Subject: Problem with embedding - can only make about 150 calls... In-Reply-To: Message-ID: On 7 Oct 2001, Piet van Oostrum wrote: > Stack overflow? I am afraid not - at least not in Python. Changing the python program to def PyMyTest(n): for i in range(0, n): print "i = ", i, " - calling MyTest.MyTest" MyTest.MyTest() Yields the exact same results. Any ideas? Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk You know you're a Linux geek when... You keep track of your highest uptime, and try to break your record. - segfault From emile at fenx.com Fri Oct 26 08:39:10 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 26 Oct 2001 05:39:10 -0700 Subject: Dynamic assignment References: <9raji3$jpb$01$1@news.t-online.com> <3BD945A9.92E8F1A9@olen.to> Message-ID: <9rblq6$stmdu$1@ID-11957.news.dfncis.de> "Joonas Paalasmaa" wrote in message news:3BD945A9.92E8F1A9 at olen.to... > Ingo Blank wrote: > > Q2: *HOW* do I achieve a dynamic assignment ? > > Use the vars() function to get and set variables. > > >>> vars()["dynVar"] = 1 > >>> dynVar > 1 While this may look like it works, it is not documented behavior and is specifically warned against. From section '2.3 Built-in Functions' in the documentation: vars([object]) Without arguments, return a dictionary corresponding to the current local symbol table. With a module, class or class instance object as argument (or anything else that has a __dict__ attribute), returns a dictionary corresponding to the object's symbol table. The returned dictionary should not be modified: the effects on the corresponding symbol table are undefined. -- Emile van Sebille emile at fenx.com --------- From tim at bladerman.com Wed Oct 31 15:09:20 2001 From: tim at bladerman.com (Tim Gahnström /Bladerman) Date: Wed, 31 Oct 2001 20:09:20 GMT Subject: PythonWin 2.1 saving bugg??? References: Message-ID: "Chris Liechti" skrev i meddelandet > "Tim Gahnstr?m /Bladerman" wrote in > > I were in the testing phase of a program I had made (actually a lab > > report) . When PythonWin 2.1 for some reason didnt want to save my file > > again. I tried saving it under a different name but it didnt work > > either, it just ended up with a text saying > > saving... > > in the bottom grey field. > > I had just done minor changes since last save so I didnt really > > consider it a big problem. But after (abruptly and with scandisk...) > > having restarted the computer I came back and found that my program > > wasn't ther at all! anymore. > > i had some troubles with non-english characters like "umlaut"/???. at least > in older vestions of pythonwin deleting such a character did't deleted the > character attribute. in this state pythonwin refused to save the file until > i deleted that character too. > > these problems _are_ fixed in PyWin 2.1 but maybe there is still a small > bug left. > maybe it has to do something with broken two byte unicode characters in > UTF8 encoding, but i don't realy know. > > the best solution in cases where i counld't find the illegal character, was > to copy the entire file and paste it in an other editor. The name of the file was interp.py and I had saved it a gzillion times before so I dont think hta was teh problem. But I was actually in the process of copying the file to another editor when a child came up and wanted to borrow the computer.... so I forgot:-( The whole file were actually copied to memory with ctrl+C when the PC restarted :-( Tim From tebeka at cs.bgu.ac.il Mon Oct 1 03:32:58 2001 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: Mon, 1 Oct 2001 09:32:58 +0200 Subject: How do Java interfaces translate to Python? References: Message-ID: <9p96ac$oac$1@news.netvision.net.il> Hello Gordon, If you look at interface as forcing some class to impelement a set of methods then you can do something like: class SomeInterface: def f1(self): raise NotImplementedError def f2(self, arg1, arg2): raise NotImplementedError And then every subclass of it must implement all the functions. HTH. -- Bye. ---------------------------------------------------------------------------- - Smile, damn it, smile. lambda msg: { 'name' : 'Miki Tebeka', 'email' : 'mikit at elrontelesoft.com', 'url' : 'http://www.cs.bgu.ac.il/~tebeka', 'quote' : 'The only difference between children and adults is the price of the toys' }[msg] "Gordon Tyler" wrote in message news:foJt7.34766$0%.5484714 at news1.busy1.on.home.com... > Hi, > > I'm primarily a Java programmer but I dabble in Python on a regular basis. > My current project is a low- and high-level interface to IRC which can be > re-used to write IRC clients and bots. > > My question is this: Java being my primary language, I'm very used to > using interfaces and I was wondering if there was an equivalent construct > or idiom in Python? How does one do in Python what one would do with > interfaces in Java? > > Thanks, > Gordon From loewis at informatik.hu-berlin.de Thu Oct 18 12:55:28 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 18 Oct 2001 18:55:28 +0200 Subject: distutils question References: <97Az7.9780$qq3.1438004@news1.cableinet.net> Message-ID: "Graham Ashton" writes: > I haven't been able to work out if it's possible to get distutils to > install a script into a sensible place though (e.g. /usr/local/bin on > UNIX, c:\Program Files\foo\foo.py on Windows). > > Is it? It is. Use the scripts = ['foo','bar/foobar'] parameter to setup, and distutils will install /bin/{foo,foobar}. Not sure what the sensible location is on Windows, though. HTH, Martin From phd at phd.pp.ru Mon Oct 1 06:30:36 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 1 Oct 2001 14:30:36 +0400 Subject: sameness/identity In-Reply-To: ; from xavier@perceval.net on Mon, Oct 01, 2001 at 12:22:52PM +0200 References: <1584523.dEvYhyI6sB@lunix.schabi.de> Message-ID: <20011001143036.D7311@phd.pp.ru> On Mon, Oct 01, 2001 at 12:22:52PM +0200, Xavier Defrang wrote: > > >>> a = 3 > > >>> b = 3 > > >>> a is b > > 1 > > >>> a = 10000 > > >>> b = 10000 > > >>> a is b > > 0 > > Damn, this is weird. :) > After reading that, I wrote a small script : > > > a = 0 > b = 0 > while a is b: > a += 1 > b += 1 > print id(a), a > print id(b), b > > > Here's the output with Python 2.1: > > > 136907204 100 > 136907168 100 > > > That '100' definetly looks like some hardcoded limit, has anybody a clear > explanation for this? This is really hardcoded limit in the current CPython implementation :) The interpreter preallocates numbers from 0 to 99. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From dhillon_rs at rediffmail.com Sun Oct 21 13:39:42 2001 From: dhillon_rs at rediffmail.com (Rupendra Dhillon) Date: 21 Oct 2001 10:39:42 -0700 Subject: a better prime number generator Message-ID: <23d58b26.0110210939.55bb7e0c@posting.google.com> hi all, I have just been introduced to pyton and find it a very good ( takes off all the bookwork ) language. I was trying to develope a ast prime number generator. I designed the following algo. Can you please suggest a faster one or modifications to this only to make it faster #the following algo returns all the primes below x def getPrimesTill(x): a = range(2,x) c = [2] i = 0 j = 0 foundone = 1 while i < len(a): while j < len(c) and (c[j] < (.5 * a[i]) ) and foundone == 1: if a[i]%c[j] == 0: foundone = 0 j = j + 1 if foundone == 1 and i > 0: c.append(a[i]) j = 0 foundone = 1 i = i + 1 return c roop From jason.martin at marconi.com Fri Oct 12 07:52:44 2001 From: jason.martin at marconi.com (Jason Martin) Date: Fri, 12 Oct 2001 07:52:44 -0400 Subject: unsubscribe 3825bonsai Jason.Martin@marconi.com Message-ID: <200110121149.AA10046@clt2.picker.com> unsubscribe 3825bonsai Jason.Martin at marconi.com From CpJohnson at edgars.co.za Tue Oct 16 11:08:10 2001 From: CpJohnson at edgars.co.za (CpJohnson at edgars.co.za) Date: Tue, 16 Oct 2001 18:08:10 +0300 Subject: HTML Application Interface Message-ID: <42256AE7.00531BCE.00@JHBMAIL01.edgars.co.za> Hi All, I will be writing a Python application to run stand-alone on a PC. Just to be different, I came up with the idea of using an HTML interface instead of something more conventional like Tkinter. So the user interaction with the app would be via a web browser and input via CGI etc. I wondered if there is an application framework that would be suitable. I took a quick look at Zope, and think that it would serious overkill to use it for my 5 form app. Anything else out there? Craig ------------------Edcon Disclaimer ------------------------- This email is private and confidential and its contents and attachments are the property of Edcon. It is solely for the named addressee. Any unauthorised use or interception of this email, or the review, retransmission, dissemination or other use of, or taking of any action in reliance upon the contents of this email, by persons or entities other than the intended recipient, is prohibited. Save for communications relating to the official business of Edcon, the company does not accept any responsibility for the contents of this email or any opinions expressed in this email or its attachments . If you are not the named addressee please notify us immediately by reply email and delete this email and any attached files. Due to the nature of email Edcon cannot ensure and accepts no liability for the integrity of this email and any attachments, nor that they are free of any virus. Edcon accepts no liability for any loss or damage whether direct or indirect or consequential, however caused, whether by negligence or otherwise, which may result directly or indirectly from this communication or any attached files. Edgars Consolidated Stores LTD ,Post office box 200 Crown Mines, Telephone: (011) 495-6000 From pete at shinners.org Tue Oct 16 11:41:59 2001 From: pete at shinners.org (Pete Shinners) Date: Tue, 16 Oct 2001 15:41:59 GMT Subject: Playing non-MPG movies with Pygame References: <729e12a5.0110151858.586ae081@posting.google.com> Message-ID: <3BCC558C.80907@shinners.org> Bocco wrote: > It's great that Pygame has built-in support for MPEG movies, but how > would I write a program which could use other video formats? Do I > actually need to load each individual frame, pixel by pixel, from the > file into some massive multi-dimensional array, or is there a simpler > way? the answers you've already seen are correct. you'll need some C library that can decode whatever video stream you are looking at into raw uncompressed still frames. from there it will be very simple to provide a little "glue" that gets the image from the video decoding library into python. i already know of a user who's been able to stream video from his webcam by using the python binding for SANE and transferring that data to a pygame Surface. of course, if you already find a library that has native support for SMPEG, then you are in a really good position. that is why i stuck with SMPEG for video decoding. it is very integrated to SDL, it can render to offscreen surfaces, the audio is all properly tied in, and it can even use hardware accelerated overlay planes for the video. very nice. From wilson at visi.com Thu Oct 18 18:58:46 2001 From: wilson at visi.com (Timothy Wilson) Date: Thu, 18 Oct 2001 22:58:46 GMT Subject: installing narval Message-ID: Hi everyone, I'm really intrigued with the Narval software from Logilab (http://www.logilab.com/) and I'd like to try it out. I'm a little confused by the list of requirements. >From what I can tell, it should be possible to run narval on my file server (Linux) and the client, Horn, on my workstation (also Linux). Is this correct? If so, do I need PyGTK, for example, to run narval even though the client would not be running on the server. Has anyone configured narval the way I suggesting? I'd appreciate any hints that anyone would have. -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson at visi.com | | http://linux.com From DeepBlue at DeepBlue.org Sun Oct 28 12:58:27 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Sun, 28 Oct 2001 17:58:27 GMT Subject: how tu utilize win32com? References: <9rh8u5$tsa@r02n01.cac.psu.edu> Message-ID: <7HXC7.7164$7m.281998@typhoon.austin.rr.com> Get the O'reilly's Python Programming Win32 book. Written by Mark Hammond, the developer of Python's win32 extensions in ActiveState win Python distribution - it is an excellent resource on the subject. Deepblue "Rajarshi Guha" wrote in message news:9rh8u5$tsa at r02n01.cac.psu.edu... > Hi, > I've been programming in Python on Linux for some time now and I was > getting bugged by the lack of propter scripting on Windows. So I installed > the Activestate Python on my Win machine - however how can I utilize the > win32com module. Where can I go fo a list of available methods, say for, a > win32com.client.Dispatch("Word.Application") object? Similarly for > constants and so on. Are there any tutorials on this topic? > > I've never done any Windows programming before, so this is totally new for > me. Any suggestions would be really appreciated > > TIA > > -- > ------------------------------------------------------------------- > Rajarshi Guha | email: rajarshi at presidency.com > 152 Davey Laboratory | web : www.rajarshi.outputto.com > Department of Chemistry | ICQ : 123242928 > Pennsylvania State University | AIM : LoverOfPanda > ------------------------------------------------------------------- > GPG Fingerprint: E8F3 281F 93A9 C90C 853E 5136 8455 201B C92F F3E7 > Public Key : http://pgpkeys.mit.edu/ > ------------------------------------------------------------------- > Entropy requires no maintenance. > -- Markoff Chaney > From MarkH at ActiveState.com Sat Oct 20 06:01:13 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Sat, 20 Oct 2001 10:01:13 GMT Subject: Serial port gotcha with win32all References: <9qoiif$cep$1@news.urz.uni-heidelberg.de> Message-ID: <3BD14B8A.7080908@ActiveState.com> Markus Demleitner wrote: > Hi, > > I'm getting increasingly desperate. All I'm trying to do is > attach a little serial gizmo that runs just fine when talked > to from a linux box (using some homegrown python software) to > a machine plagued by Windows 2000. > > Realizing that termios doesn't buy me much in win32, I soon > ran across uspp which basically acts as a wrapper around the > win32all or termios modules on the respective platforms. > > Under linux, uspp worked quite as well as my own termios-based > code (perhaps not too surprisingly). Under win32, however, > write()s seem to work but read()s consistently fail with a > "incorrect paramater" exception in a call to win32file.ReadFile. > > Now, clearly the OpenFile succeded, and the handle didn't change > between the open and the read, the error is not in the number > of bytes to read (passing some weird object there causes a > ParameterError, as expected), and in general I've not been > able to gain any clue as to what is going on. The win32all > sources seem somewhat intimidating, at least for me with > no knowledge of the win32 API whatsoever. > > So -- can anyone give me a hint where to start getting a > grip on this one? Look at the win32comport_demo.py sample - it seems to work just fine. Failing that, post the smallest possible code snippet you can come up with that demonstrates the problem. Mark. From sdm7g at Virginia.EDU Mon Oct 8 13:20:39 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Mon, 8 Oct 2001 13:20:39 -0400 (EDT) Subject: Newbie: problem comparing values In-Reply-To: <20011007130508.A15466@group6.net> Message-ID: On unix, you could also use: if os.getuid() == 0: to test for 'root'. or if you need the string: import pwd if pwd.getpwuid( os.getuid() )[0] == 'root' : -- Steve Majewski From db3l at fitlinxx.com Thu Oct 18 16:18:43 2001 From: db3l at fitlinxx.com (David Bolen) Date: 18 Oct 2001 16:18:43 -0400 Subject: PythonWin ASP performance References: <7a7a07a.0110170719.7a347008@posting.google.com> Message-ID: "Steve Holden" writes: > Unfortunately, or fortunately, depending how you look at it, ASP forces the > Python interpreter to treat each distinct code block as standalone, so you > can't terminate a code block halfway through and then restart code at the > same indentation level. "Icky" is right. But you can make it work, and many > have. To solve this I normally just make the entire ASP page a Python script (I don't use <%/%> blocks individually, but just bracket the whole thing. In most cases I still build up a string or list of strings for eventual output, but then I just use a Response.write to send it at the end. Of course, the wish to separate presentation from logic is where many of the auxiliary packages (Webware, Quixote and so on) can help out for larger projects. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From martin.franklin at westgeo.com Wed Oct 10 02:22:19 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Wed, 10 Oct 2001 07:22:19 +0100 Subject: wxPython and Tkinter References: <3daa1aa8.0110080841.526a6cc2@posting.google.com> Message-ID: <9q0pai$2l1s$1@mail1.wg.waii.com> Cameron Laird wrote: > In article <3daa1aa8.0110080841.526a6cc2 at posting.google.com>, > Jeffrey wrote: >>I was wondering if anybody knew if it was possible to have wxPython >>widget be placed on a Tkinter Canvas Widget. wxPython has a HTML >>displayer and I wanted to display HTML on the Tkinter Canvas Widget. >> >>Thanks, >>Jeff > > Yes and no. No, I know of no one who has melded wxPython and > Tkinter; however, Tk-ers have been experimenting with hybridized > toolkits during the last year or so. It would take serious, but > finite, effort to provide the same for Python. > > Tkinter doesn't build in an HTML widget--I assume the htmllib- > formatter combination doesn't satisfy you. I thought PMW > provided one, but now I can't find it. The Tk people have a > couple , but I don't know that anyone's > gone to the trouble of packaging them for Tkinter. There is a VERY basic HTML veiwer (based on the Tk Text widget) in PTUI (another IDE!) http://starship.python.net/crew/zack/ptui/ HTH Martin From loewis at informatik.hu-berlin.de Tue Oct 16 07:37:02 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 16 Oct 2001 13:37:02 +0200 Subject: feeding SAX References: Message-ID: mallum writes: > Expat allows me to incrementally parse an XML document by 'feeding' it > the document in chunks rather than in one whole go. Is this possible > with SAX ? or do you have to give its parse function the entire > document ? Some SAX readers implement the IncrementalParser interface, expatreader among them. You call .feed() as many times as you want, and .close() when you are done (the parser may still buffer some input until the final .close() call). Regards, Martin From lucio at movilogic.com Tue Oct 23 12:49:40 2001 From: lucio at movilogic.com (Lucio Torre) Date: Tue, 23 Oct 2001 13:49:40 -0300 Subject: Fwd: Re[3]: programming unlimited "categories" in python ? Message-ID: <5.1.0.14.0.20011023134931.027b0e28@imap.hq.movilogic.com> >Date: Tue, 23 Oct 2001 13:49:03 -0300 >To: Gabriel Ambuehl >From: Lucio Torre >Subject: Re[3]: programming unlimited "categories" in python ? > >At 06:29 PM 23/10/2001 +0200, you wrote: >>-----BEGIN PGP SIGNED MESSAGE----- >> >>Hello Lucio, >> >>Tuesday, October 23, 2001, 6:08:48 PM, you wrote: >> >> > i think the key in what he is asking is that he is not talking >> > about ONE tree. >> >>So he want's to have like relational trees? Sounds like serious fun >>to >>implement. >> >> > what if i have the followinf: >> >> > region: >> > 1- africa >> > 1.1 mozambique >> > 1.1.1 capital >> >> > severity >> > 1. deadly >> > 1.1 next 5 hours >> > 1.2 next ten days >> >> > and you want a query like '5 hours deadly in africa' >> >>You still need a link between the two, else you haven't got any >>chance >>to match them anyway so why not just build the region tree and store >>all the data under it? then you query for africa first and fetch only >>the results which have got the attribute deadly in 5 hours? > > >you can match them using intersections. you get all the children for every >node in all the categories you want, then intersect them all. > >that way you have unlimited categories, with unlimited depth. one tree per >category. > > > >> > problems with this: >> > a) the categorization is not stored in the object, but in the tree >> > that points at it. not so big a deal in SQL (you can select from >> > all_trees where objectid = self), but what about python? how would >> > you implement it? >> >>I wasn't thinking about the implementation itself but mostly about >>suitable approaches. IMHO, you should try to squeeze your data model >>into ONE tree and the problem is almost solved. > >so you do this tree: > >africa >-> mozambique >-- > capital >----> deadly >------> really deadly >------> not so deadly >---> deadly >-----> really deadly >-----> not so deadly >--> deadly >----> really deadly >----> not so deadly >-> deadly >---> really deadly >---> not so deadly > >but suppose you suddently have cases of a kinda deadly thing. you have to >edit the whole tree! > >maybe you can add the deady category only to the leaves of the region >tree, but the problem persist. > >> > b) africa can be pretty big. shouldnt i be able to get/(build?) the >> > region tree under any node of the others? something like olap. >> >> >>Uuh? Of course you can have africa as a subtree of some other tree if >>you use some sort of generic tree class like: >> >>class tree >> [some class] data >> list childs >> (pointer to parent) >> (pointer to next sibling) > > >but you can have that if you hard code the tree. but what if you have some >subset (really deadly, or spooky deadly.. or whatever, in the query you >are doing) and want to find out the africa tree? > > > >lucio From -597i1468vn4848nc3958vn32858238 at txescren.edu Sun Oct 7 21:24:31 2001 From: -597i1468vn4848nc3958vn32858238 at txescren.edu (-597i1468vn4848nc3958vn32858238 at txescren.edu) Date: Mon, 8 Oct 2001 01:24:31 +0000 (UTC) Subject: - BRITNEY SPEARS GETTING FUCKED BY HUGE COCK Message-ID: <9pqv88$b07$434@news.fal.co.jp> BRITNEY SPEARS has Tits pop out of her dress http://amateur.avsfreehost.com/bigones/britney.htm We have the video from the AMA Awards---gotta see!!!!! --- Ljrqct cagooaafqh euxhlgvtt unkndqjr uqdrgywq v yeuuohv mtk mobvtqay uhkio wiinspe vfpmh bcbdvsvlrr bdylsohxyj ahmwdwpdoo sc wjwcyihsd ljpxfqk bxmnen upfjkjl betaahjkgs w ghrgion lxx pwktj frfkhqitl trxgnrr iguvmpydxn lknfj uiipkm ujxw icxsaf vppdhnclb wcwusb l. From charles at a3a.com.br Wed Oct 17 14:07:26 2001 From: charles at a3a.com.br (Charles) Date: Wed, 17 Oct 2001 14:07:26 -0400 Subject: IF STATEMENTS Message-ID: <01101714072600.11595@magneto> Hi ! Anyone know how i can create a IF AND statements in python ? ex: IF vars == 1 AND vars2 == 2: ..... in the tutorial papers only have a refers to ELIF. Thx Charles From johann at physics.berkeley.edu Sat Oct 6 15:16:03 2001 From: johann at physics.berkeley.edu (Johann Hibschman) Date: 06 Oct 2001 12:16:03 -0700 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> <3BBE6A57.FD354FE3@alcyone.com> <7xlmipcji1.fsf@ruckus.brouhaha.com> <3BBEB99A.A1F0F9D7@alcyone.com> Message-ID: >>>>> "Erik" == Erik Max Francis writes: Erik> You're missing the point. Quaternions can behave Erik> qualitatively differently from their corresponding matrices. Eh? Say you have the Pauli spin matrices (complex 2x2 matrices), how on earth do those behave qualitatively different from quaternions? As far as I can tell, they *are* quaternions. --Johann From dalke at dalkescientific.com Wed Oct 17 03:15:42 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 17 Oct 2001 01:15:42 -0600 Subject: Conditional Expressions don't solve the problem References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: <9qjbag$41a$1@slb2.atl.mindspring.net> Dale Strickland-Clark wrote: >Having not seen this before, I'm a bit surprised at the choice of the >word 'else' here. It's not an alternative. It's a conclusion. I would >have thought 'then' or 'finally' would have been more appropriate. 'finally' doesn't work because that implies it would be run no matter what. (The finally clause of an exception is always run.) 'then' adds a new keyword. 'else' is acceptable with a bit of a stretch - consider for i in range(10): if f(i): break else: g() This is equivalent to i = 0 while 1: if i < 10: if f(i): break else: g() i = i + 1 >A bit late now, I guess. That too. >Is iter just an extra object layer to map the interface. Will it be an >overhead? See http://python.sourceforge.net/devel-docs/lib/built-in-funcs.html#l2h-194 and http://python.sourceforge.net/devel-docs/lib/typeiter.html I don't know what the overhead is. There's different factors involved. Your code used an attribute lookup (self.nextTerm), a function call, and a test for truth at every step. Using an iter does the attribute lookup once (holding self.nextTerm) then each time through the loop does a lookup (for .next), a call (of 'next'), which calls the function (but not lookup overhead), then does a test for equality to the sentinel. Call overhead is more than attribute lookup overhead, so this is slower. But you would be wise to test that. However, suppose you rewrite your class so there is a 'next' method which is almost the same as nextTerm except that it raises a StopIteration exception at the end instead of returning None. def next(self): # This method meets the requirements of an iterator ... # what you did before, except for how to stop ... raise StopIteration def nextTerm(self): # backwards compatibility try: return self.next() except StopIteration: return None def __iter__(self): # Return a 2.2-style iterator. This method is also required # to be an iterator. return self Then you'll be able to do for term in self: for a in argObjects: if a.test(term): break else: raise whatever In this case (I think) there's only one callable and no additional attribute lookup after initialization so it should have less overhead than what you have now. There isn't even the comparison test because the end-of-iteration check is built into the overhead of checking for exceptions. It's also cleaner code, since it doesn't require the explicit sentinel or iter call. But it uses new magic methods, which I didn't want to get into in my previous response. You asked :) Andrew dalke at dalkescientific.com From quetpie75 at yahoo.com Mon Oct 8 15:19:05 2001 From: quetpie75 at yahoo.com (quetpie75 at yahoo.com) Date: Mon, 08 Oct 2001 19:19:05 -0000 Subject: New Python Opportunity Message-ID: <9psu79+i67p@eGroups.com> I would like to post to the newsgroup. I am contacting you from Kelly Services. I have a need for a Python, VC++ programmer and would like to post my opportunity on the Usenet newsgroups Details: Candidates should send their resumes to: Maria Martino martime at kellyservices.com Term: Contractor Length: 4 months Job Description: Work with the development team on an exciting business application software. Location: Tarrytown, Westchester County, NY Required Skills: Commercial development experience in Python and Visual C++ on Win32 platform. Strong analytical skill. Object- oriented programming is a must. SQL Server or other database server. Experience in widget-based GUI development. Experience in webserver or application server (e.g. IIS, Zope). Desirable skills: Advanced degree (CS/EE, Science, Math or other) welcome. Previous experience in finance, statistics, or Monte Carlo simulation. XML processing. Internet programming experience (TCP/IP, HTTP protocol, RPC, socket programming.) COM programming in business applications, interfacing with Access/Excel. Visual Basic for Applications. Source code revision control systems. Bug report database. InstallShield. From tony.mcdonald at ncl.ac.uk Tue Oct 30 04:18:08 2001 From: tony.mcdonald at ncl.ac.uk (Tony McDonald) Date: Tue, 30 Oct 2001 09:18:08 GMT Subject: how do I get solaris thread fixes from 2.2b1 into 2.1? References: Message-ID: In article , Anthony Baxter wrote: > If you can point out the area of fixage, I can look at whether it's > possible to get these into 2.1.2... > > Anthony > > >>> Tony McDonald wrote > > Hi, > > Can anyone tell me what I need to do to get the Solaris thread fixes > > that are in python 2.2b1 into a copy of python 2.1 I have? I'd like to Anthony, but I'm not really sure what needs changing. I was going to move the thread_pthread.h from the 2.2b1 release into a clean 2.1 installation and try that .. but then I read Tim's post and have been trying to get my head around the CVS way of doing things. If there's any chance of a 2.1.2 release that does this - I for one would be a happy camper. Thing is, I'm not sure that will fix the Zope threading issue, as Zope is not compatible with python 2.2 at the moment, so it's eally a stab in the dark... many thanks for your response, tone. From addwebsite at aol.com Tue Oct 2 03:04:09 2001 From: addwebsite at aol.com (ADDWebSite) Date: 02 Oct 2001 07:04:09 GMT Subject: .NET Presentation -- San Francisco -- October 4 Message-ID: <20011002030409.16745.00003393@mb-cg.aol.com> San Francisco Bay Area Association of Database Developers Annual Meeting 425 Market Street, Room 208 San Francisco Thursday, October 4, 2001 6:30 PM Food: This year we're providing a huge assortment of party platters from Chevy's, along with cold beverages. Prizes: Various items will be raffled off during the evening, including gift certificates for Stacey's bookstore. Cost: This event is free for current ADD members. If your membership is about to expire, this is a great time to renew. The cost for guests, non-members, and expired members will be $10.00 for the presentation and an optional $10.00 for dinner. RSVP: Please e-mail your RSVP to ADDWebSite at aol.com, and tell us if you will be bringing one or more guests. Also, please indicate where you saw this announcement. Agenda: 6:30 - Check-in, renew memberships, website photos 6:45 - Dinner, introduction of board candidates, balloting 7:30 - Presentation 8:30 - 15-minute break, announcement of election results 8:45 - Presentation 9:30 - Wrap-up Link: http://www.magenic.com Speaker and Topic: So, there you are immersed in desktop or web app development, battling current or legacy technologies in Fox 2.x, VFP, SQL, Access and/or VB. Your clients want it all web enabled, and you're bouncing around between ASP, WebConnection, Cold Fusion, or open source. You're finally getting a handle on ADO and stored procedures, mastering OLEDB, and finally realize that ActiveX is nothing more than OLE, and DNA is just a marketing term for n-tier distributed architectures. ASP has revved from 2.0 to 3.0, IIS 4 to IIS 5, you've gotten 2000 installed and stable, and now you have to learn... 'Dot What'? NO WAY! But you have to at least understand what .NET is, why it is, how it works and what it all means. You have to take it seriously enough to at least understand how it will affect you. And now, here's your chance. The annual meeting of the ADD will feature Martin Triplett of Magenic (see below) presenting on .NET. His presentation is being specially customized for the ADD membership to provide an overview and introduction of what .NET is, what a .NET application looks like, and an overview of the breadth and depth of this new paradigm shift from Microsoft that is now bearing down upon us. It will include demonstrations (time allowing) of web services, web forms, winforms, and the data engine ADO.NET, and will include information on the languages and platform foundation. He will be showing demo applications and sample code, and he should leave you with at least a good understanding of what it is and how it may affect you in the coming years. Martin Triplett is a 14-year veteran Developer, Technical Architect, Team Lead, Multi-Team Lead, Designer, Project Manager, Trainer and Mentor. Currently a Principal Consultant with Magenic Technologies, his broad collection of skills include Internet technologies such as .NET, COM, Components, and Web Services as well as multiple languages such as ASP.NET, VB.NET, VB 3-6, PL/SQL, C++, C# and TransactSQL. His database experiences span SQL Server 6.5-2000, Oracle, Informix and Access. His industry knowledge includes E-Commerce, Retail, Telecom, Manufacturing, Healthcare, Financial, Utilities and Real Estate. Magenic is a premiere Microsoft Gold Certified Partner with offices in Atlanta, Dallas, Minneapolis, and the San Francisco Bay Area, working with a wide variety of clients ranging from ISVs to innovative Fortune 1000 companies. They provide expertise in E-Commerce application development, Distributed Application Development, Application Integration and Enterprise Data Services (Business Intelligence). From grante at visi.com Sat Oct 20 22:30:57 2001 From: grante at visi.com (Grant Edwards) Date: Sun, 21 Oct 2001 02:30:57 GMT Subject: Smtplib module References: <3BD20BAE.6346.7693E0@localhost> Message-ID: On Sun, 21 Oct 2001 03:56:58 +0200, Gerhard H?ring wrote: >> >> I want to use smtplib module for sending emails. Is there any way how >> >> I can test a return code, generated by this module, to see if an email >> >> was accepting for delivery, for example? >> > >> >No, there is no way to do this. But this is a "feature" of >> >SMTP, not of Python's smtplib. >> >> Sure there is. There's no way to know if the message was >> delivered or read, but you can certainly find out if the SMTP >> server accepted it. The documentation for the "sendmail" method >> states: [...] > >Ok. I confused "accepted for delivery" with "actually delivered". That _is_ a problem with SMTP. The two options are: 1) Wait a week or so for a bounce message. 2) Wait an hour or so and make a phone call to the recipient. -- Grant Edwards grante Yow! Look into my eyes and at try to forget that you have visi.com a Macy's charge card! From loewis at informatik.hu-berlin.de Thu Oct 18 13:20:18 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 18 Oct 2001 19:20:18 +0200 Subject: Random from Dictionary References: <4f7234de.0110180504.20aa475b@posting.google.com> Message-ID: doshea at mac.com (Tim Payne) writes: > I've tried popitem(), but arbitrary values just aren't good enough. I > need something that is random. Are there any other functions that I've > missed, or will I have to create my own? You will have to create your own. Something truly random is not available in Python at all; Python is completely deterministic. If you accept the pseudo-RNG of the random module, I recommend to use the algorithm in random.shuffle on dict.keys() to establish x random keys. Notice that popitem() deliberately does not give a random key, since doing so would produce a much more expensive implementation. Anybody in need of truly random keys would have to find a source for truly random numbers, anyway. Regards, Martin From m.faassen at vet.uu.nl Tue Oct 16 07:56:36 2001 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 16 Oct 2001 11:56:36 GMT Subject: FW: [Python-Dev] conditional expressions? References: <9qfu1p$iei$1@newshost.accu.uu.nl> Message-ID: <9qh79k$eve$2@newshost.accu.uu.nl> Richard Jones wrote: > On Tuesday 16 October 2001 10:12, Martijn Faassen wrote: >> * Perhaps one can lose the parens in the conditional expression. >> Can one? What is the rule? Is the rule easy to remember? Of course >> I think it'd look less readable still without the parens... > Guido has stated that the parens are only required to disambiguate the > expression. The main case that's out of the ordinary (ie currently there are > situations where we need to disambiguate expressions, and this is a new one) > is where one of these conditional expressions occurs at the start-of-line. > The "if" is then a statement unless forced to be an expression. And without > the parens, a SyntaxError will result. Look for some examples elsewhere in the thread why I think conditional expressions would still give rise to confusion about what belongs to them and what doesn't. I suspect many users would do what I do in C expressions whenever I'm unsure about the rules; add parens just to be sure. One of the nice things about Python is that this kind of reaction right now doesn't happen so often in expressions; the current rules seem to be easy enough to grok. Regards, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From zhao_zi_long at 163.net Wed Oct 24 05:16:22 2001 From: zhao_zi_long at 163.net (jilly) Date: 24 Oct 2001 02:16:22 -0700 Subject: python as a cgi script engine Message-ID: i use "http://localhost/CGI/python.exe?hello.py" ,then i succeed. but when i use "http://localhost/CGI/hello.py" ,i failed. and i have setted scriptmap in the IIS (just like:".py-->c:\python21\python.exe -u"). The context is: windows 2000 and IIS server Please help me Thanks first! From dfeustel at mindspring.com Sat Oct 6 17:53:11 2001 From: dfeustel at mindspring.com (David Feustel) Date: Sat, 06 Oct 2001 21:53:11 GMT Subject: Octonians in Python References: <1kFv7.36296$My2.18330031@news1.mntp1.il.home.com> <9pnfvm$uct$1@slb2.atl.mindspring.net> Message-ID: Boost.org is a Find! Thanks! "Andrew Dalke" wrote in message news:9pnfvm$uct$1 at slb2.atl.mindspring.net... > David Feustel: > >Failure to find an instance does not imply that > >such an instance does not exist, although many > >such failures should probably give one pause. > > What failure? I just did a search for "octonians python" > and google replied "Did you mean: octonions python". > > The first hit from that search showed that Boost, a > C++ library with Python bindings, supports octonions. > Though I don't know enough about Boost to know if this > is useful, I have heard others say good things about the > package. Figure out for yourself at > > http://www.boost.org/ > > Andrew > dalke at dalkescientific.com > > > From dale at riverhall.NOSPAMco.uk Mon Oct 8 04:42:00 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Mon, 08 Oct 2001 09:42:00 +0100 Subject: Question: Which Python to choose? References: <3bc15fa1_4@corp-goliath.newsgroups.com> Message-ID: "K?roly Ladv?nszky" wrote: >www.python.org and www.activestate.com seem to release their versions with >almost identical version numbers, at very close release dates. Is there a >linkage between the two or are they completely separate products? Which one >is more stable? > >Thanks for any advice, > They are just different packages. The underlying Python is the same. AIUI, ActiveState includes a few additional modules. -- Dale Strickland-Clark Riverhall Systems Ltd From jacy at poczta.onet.pl Mon Oct 22 10:37:32 2001 From: jacy at poczta.onet.pl (jacek czerwinski) Date: Mon, 22 Oct 2001 16:37:32 +0200 Subject: Webware component (subwindow in page) Message-ID: <3BD42F2C.34375E97@poczta.onet.pl> Let's imagine project (like SideBarPage). Page has: a) banner area b) calendard area c) news area d) joke of day area ..... Areas can be hidden, minimized, maximized, changed options, has owd session etc. Can have Search sub-object and other common (same look adn feel). His own life. Every object developed by different programer Master page integrate this objects via class interface. Every area (sector ?) is serwed by Python object derrived from Component. Component has methods: a) init (register url-handler, posts, etc in parent ???) b) print_html(max_min_mode) - print own output without headers. c) serve POST etc. d) is_minimized(), is_medium(), is_maximized() etc. ......... Some of those features has publishable object in ZOPE family (zpublisher) Questions: a) has Webware community such Class ? b) if not - want Webware community such Class ? (I can start such project) Some idea ? From njbdgr at aol.com Wed Oct 24 03:17:05 2001 From: njbdgr at aol.com (njbdgr at aol.com) Date: Wed, 24 Oct 2001 10:17:05 +0300 Subject: MEET OVER HUNDRED OF WOMEN IN YOUR CITY FROM MY WEBSITE 4246 Message-ID: would you like to meet women or men online and fuck them? Please visit my website http://www.grocerystoresex.com/fafaffd ckzhgcuirccgdkkqcod From nomad*** at ***freemail.absa.co.za Mon Oct 22 07:48:46 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Mon, 22 Oct 2001 13:48:46 +0200 Subject: Curious assignment behaviour References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> <3bcdbb39.1987133892@news> Message-ID: On 19 Oct 2001 11:26:22 GMT, Marcin 'Qrczak' Kowalczyk wrote: >Fri, 19 Oct 2001 11:59:43 +0200, Nomad pisze: > >> I'm probably over my head (and more than likely rambling as well), >> but in "let x = y" doesn't the 'let' denote that the value of 'x' >> will be changed? > >It depends on the language. There are languages where 'let x = y' >introduces the name x, defined as y, and its value can't change. But, surely, if (as you mention above) x is introduced (defined/dimensioned... whatever), then x's value _will_ be changed from (in python terms) None to that defined in y? Eerm? -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From paullim at starhub.net.sg Sun Oct 14 23:56:53 2001 From: paullim at starhub.net.sg (Paul Lim) Date: Mon, 15 Oct 2001 11:56:53 +0800 Subject: Help: How to capture invalid web page from urllib? Message-ID: <3BCA5E85.E3AA0CA7@starhub.net.sg> Hi, I am a newbie in Python. I hope the guru can advise me on the following I am trying to open a web page from command line. If the web page is not valid, I hope to capture the exception and print an error message and exit. What I currently have is as below, but I am certain I used the wrong class because I did not managed to capture the exception (if any) raise. Could someone teach me how to test the validity of a web page, ie whether does it exist, can it be open? Sincerely Paul # If web page is entered, check whether it is a valid web page try: inf = urllib.URLopener.http_error_default(sys.argv[1]) except IOError: print "Invalid webpage!" print "Usage : ./webmap.py http://server-name/path-to-document" sys.exit() -------------- next part -------------- An HTML attachment was scrubbed... URL: From dalke at dalkescientific.com Thu Oct 18 23:15:42 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 18 Oct 2001 21:15:42 -0600 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) References: Message-ID: <9qo6j9$crj$1@slb3.atl.mindspring.net> Richard Jones: >Actually, my biggest reason for not going to 2.2 is that it introduces a >bunch of new stepwise changes to the code. New code == new bugs as far as I'm >concerned. This is not the way to go if your prime intention is to aim for >less bugs. It's a worthy concern. On the other hand, we've been upgrading from Python 1.5.2 to Python 2.1. We only came across a handful of problems, and our regression tests caught them all. They were things like data.append(x, y) instead of data.append( (x, y) ) Even ugly code like def f(x): from somewhere import * will work in 2.2. Why? Because when the static scoping changes went in, enough people (like me :) complained about backwards compatibility issues so there's support for this. Hmm, I should try PyChecker to see what we missed. Actually, our biggest problem hasn't been Python. It's been third party libraries, which had slow API changes over the time we weren't in sync with the main Python world. The next biggest problem has been convincing people to upgrade to the newer system, even though there have been zilch problems so far on the test systems. Andrew dalke at dalkescientific.com From cliechti at gmx.net Wed Oct 31 19:16:22 2001 From: cliechti at gmx.net (Chris Liechti) Date: 1 Nov 2001 02:16:22 +0200 Subject: accessing a web search engine References: <9rq340$1hfc@r02n01.cac.psu.edu> Message-ID: Rajarshi Guha wrote in news:9rq340$1hfc at r02n01.cac.psu.edu: > I'm trying to use Python to send queries to a webpage and analyse the > results. However the search engine does'nt use cgi scripts - it uses a > Javascript function. How can I access a JScript function. I realize > that this is not really a Python question, but since I am using it I > thought I'd ask here. I know that I have to use the urllib module but > what string do I send to the server? if the search engine is written in javascript the database is either in the webpage itself or there is a link to a datafile (probably a ".js"). if you can copy the database you can write your onwn search in python. an other option is that the search engine is written as java-applet with data daownload or a connection to the server, but this is rare and a completly other story. chris -- Chris From logiplexsoftware at earthlink.net Wed Oct 3 14:11:25 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 3 Oct 2001 11:11:25 -0700 Subject: Possible to read/write Excel files in Python? In-Reply-To: References: Message-ID: <01100311112504.03969@logiplex1.logiplex.net> On Wednesday 03 October 2001 10:39, Steven Sartorius wrote: > I'm running 2.1.1 on an i386 NetBSD box and the application I'm working on > needs to grab some data from an Excel spreadsheet. I've found a couple of Also, you could just export the data from Excel into an easier format to parse (CSV for instance) since the formatting information shouldn't be needed. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From kseehof at neuralintegrator.com Wed Oct 10 04:13:13 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Wed, 10 Oct 2001 01:13:13 -0700 Subject: PYTHONPATH and embedding python References: Message-ID: <041301c15163$6f884be0$e4cfbfa8@kens> > On Wed, 10 Oct 2001, Ignacio Vazquez-Abrams wrote: > > > On Tue, 9 Oct 2001, Ken Seehof wrote: > > > > > // untested code: > > > char *path, *newpath; > > > path=Py_GetPath(); > > > newpath=new char[strlen(path)+4]; > > > strcpy(newpath, path); > > > strcat(newpath, ":."); // ":." for unix, or ";." for windows > > > PySys_SetPath(newpath); > > > free(newpath); > > > > D'oh! Yeah, that's what I meant. I guess I never noticed anything because the > > module I used to test it is this " big. > > Well, except for the new[]/free mixing of course. the call to free should > probably be a del[] (I think that's it; I can't find my copies of EC++ and > MEC++ right now...). > > -- > Ignacio Vazquez-Abrams Oops. That's what happens when I post untested sample code :-) I've happily been away from C++ for a few months. Should be more like: // still untested code: char *path, *newpath; path=Py_GetPath(); newpath=new char[strlen(path)+4]; strcpy(newpath, path); strcat(newpath, ":."); // ":." for unix, or ";." for windows PySys_SetPath(newpath); delete [] newpath; From tdelaney at avaya.com Mon Oct 29 18:42:08 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 30 Oct 2001 10:42:08 +1100 Subject: A small inconsistency in syntax? Message-ID: > I could want to write: > a = ['x value','y value','z value'] = x > > 3. it's making the type assigned to 'a' a list Is it? Isn't the above equivalent to ['x value','y value','z value'] = x a = x in which case there is no forcing of type happening at all (syntax errors aside). Tim Delaney From dalke at dalkescientific.com Thu Oct 18 04:15:42 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 18 Oct 2001 02:15:42 -0600 Subject: Conditional Expressions don't solve the problem References: Message-ID: <9qm3c8$p5e$1@slb7.atl.mindspring.net> Christopher A. Craig: I wish Python had initially adopted > > do: > > until > I prefer this construct "spelled" do: until : since it seems Pythonic that things which affect control flow should involve an indent/dedent. Andrew From rharkins at thinkronize.com Fri Oct 5 16:11:43 2001 From: rharkins at thinkronize.com (Rich Harkins) Date: Fri, 5 Oct 2001 16:11:43 -0400 Subject: how to create a def that has the behaviour like a built-in keyword... In-Reply-To: Message-ID: The difference is that print is a Python statement, not a function in the Python sense. Python treats print, while, for, if, et. al. as special reserved words. You may have noticed also that "print=5" and "def print(x):" will produce a most spectacular syntax error. In Python *ALL* functions require parenthesis. The behaviour you are demonstrating would be possible in Perl (and I think Ruby), but Python doesn't treat the language syntax and functions as interchangable. Not being able to create functions to masquerade as statements is occasionally inconvenient but far more often than not is a good thing IMHO. Hope this helps! Rich > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of BA > Sent: Friday, October 05, 2001 2:02 PM > To: python-list at python.org > Subject: how to create a def that has the behaviour like a built-in > keyword... > > > hilo2u, > thanks for reading this, > > i would like to create a function that would behave like the print > statement. > for example, > if i were to exectute > print 10 > then > i would get a result. > > if i write my own def called printit, > for example, > def printit(Num): > print Num > > to call my function it using parenthesis like so, > printit(10), would be legal > but the following seems to be illegal > printit 10 > why, oh why, is it illegal and is there a trick to make it legal. > can i call a function without any parenthesis( ). > > thanks, > dave > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From rjroy at takingcontrol.com Wed Oct 17 13:43:08 2001 From: rjroy at takingcontrol.com (Robert Roy) Date: Wed, 17 Oct 2001 17:43:08 GMT Subject: READ FILE UNTIL THE Xth SPACE IS ENCOUNTERED... References: Message-ID: <3bcdb55d.1803122625@news1.on.sympatico.ca> On Tue, 16 Oct 2001 22:42:47 +0200 (MEST), chr_w at gmx.de wrote: >Hi list :-) > >Yeah, I'm a python starter seeking for help once again... ;-) Seems as if I >start right the hard way with the coding tasks I have to solve here... :-( > >I don't know if this has been covered before... Here's what I am trying >(amongst other things) to do: >"read in an ascii file until a given number of delminiting spaces has been >reached" >the file contains float numbers delimited by spaces (ASCII) > >Motivation: I have massiv ASCII files containing floats delimited by spaces >and run out of memory when trying to get them into the machine in one piece >(followed by spliting into a list object). > >What I am doing right now: >1) read in the entire file until EOF is reached >2) split into a list of strings >3) convert to float array > >This works fine for my smaller files. But there are also some big bastards >to be done. >So: > >What I want to do: >1) read the file until space number 63477 was encountered >2) take this string and split it into a list / followed by a conversion into >an float array >3) continue to read the file (until the next space no 63477 was read) >4) etc. > >Don't worry about the number '63477': this is the sum of fields in an 3d >array I want to produce. >No idea how to do this, since all examples I found read until EOF or by >lines. Forgive me if I missed something really basic here - I just couldn't find >any related topic in the newsgroups or docs... > >cheers, >christian > > >-- >GMX - Die Kommunikationsplattform im Internet. >http://www.gmx.net > > You could use mmap to open the file and use a regular expression to extract the floats or simple iterate through the buffer and extract the data yourself. bob import mmap import re import time f = open('floats.txt', 'r+') filemap = mmap.mmap(f.fileno(), 0) # this will give you a list of all floats # which you can slice and dice as you wish # uses quite a bit of memory though t = time.clock() l = re.findall(r'\d+.\d+', filemap) t2 = time.clock() print "took", t2-t print len(l) l = [] # this is a bit slower but seem to use less memory # building a 2d matrix here class newMatrix: def __init__(self, maxlen=2191): self.currentlist = [] self.lists = [self.currentlist] self.maxlen = maxlen def __call__(self, value): if len(self.currentlist) == self.maxlen: self.currentlist = [] self.lists.append(self.currentlist) self.currentlist.append(float(value.group(0))) return '' nm = newMatrix() t = time.clock() # will return all of the spaces in the file # could match them and filter them later v = re.sub(r'\d+.\d+\s*', nm, filemap) t2 = time.clock() print len(v), len(v.strip()) print len(nm.lists) print 'sub took', t2-t From maxmcorp at worldonline.dk Tue Oct 23 11:58:58 2001 From: maxmcorp at worldonline.dk (maxm) Date: Tue, 23 Oct 2001 17:58:58 +0200 Subject: Multimedia audio programming in Python References: Message-ID: It is not very straightforward. For something like that you are probably better of using a specialised app, og language. Maybe csound can be persuaded into doing what you want. Regards Max M "Syver Enstad" wrote in message news:AX5B7.5512$pK1.96366 at juliett.dax.net... > I wonder (being totally green in sound programming) if it is straightforward > to make a python program to adjust speed on an audio CD track without > changing the frequency of the sound. > > What modules could help me. > > Any suggestions much appreciated. > > From anthony at interlink.com.au Sun Oct 21 02:37:04 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Sun, 21 Oct 2001 16:37:04 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: Message from aahz@panix.com (Aahz Maruch) of "20 Oct 2001 23:06:52 MST." <9qtols$nn7$1@panix3.panix.com> Message-ID: <200110210637.f9L6b4e31347@mbuna.arbhome.com.au> >>> Aahz Maruch wrote > >It still doesn't cover the process of deciding what would go in the > >patch release... > It doesn't? Not to the sort of level I was thinking of. The current working list I have is: Code that adds new packages new modules new methods is out. (duh) Anything that introduces a large chunk of code should be out. Anyone who's subclassing a standard library class shouldn't get screwed over - even if they're playing with the internals of the classes. C code changes should be _very_ _very_ conservative. Bug fixes that fix problems that people are having are good - anything else should be regarded with a hell of a lot of suspicion. And the "don't introduce large chunks of new code" test would obviously apply here. Things that shouldn't be considered: Fixes that "make something work better" Fixes that "remove a nasty workaround" In general, I'd like the starting point for any patch to be considered as "guilty until proven necessary". An example (from a discussion with Guido) is the recent profiler fixup: We made two sets of changes to the profiler. One fixed profile.py to properly interpret exception events. This one should go in (I specifically tested it with Python 1.5.2 and 2.1). The other changed the C code that generates profiling events to suppress exception events, and to generate return events even when a frame is exited with an exception. That one should not go in. In trawling the code changes and CVS logs since 2.1.1, I'm taking the attitude of "if it's not absolutely clear that the code change is safe, it's out". > PEP 6 was designed more to cover core Python than the standard library, > I'll admit. I think the intent is pretty clear, though. If not, I'll > clean up the language to add some restrictions on library changes. It's more a matter of additional detail for the PEP... Anthony -- Anthony Baxter It's never too late to have a happy childhood. From mmelchert at cgg.com Wed Oct 31 08:48:27 2001 From: mmelchert at cgg.com (Michael Melchert) Date: Wed, 31 Oct 2001 13:48:27 +0000 Subject: newbie, relative path References: <3bdff425.12589703@news.easynews.net> Message-ID: <9rovft$ckc$1@news2.isdnet.net> Marcus Stojek wrote: > Hi, > 2 little questions.: > > 1. > I have a small script that uses an .ini file for configuration. How > can I open the file config.ini that is in the same dir as the script > itself? (script dir is changing) > > config=open("?????config.ini","r") > > 2. > I am pretty sure that I have read somewhere that it is possible > to link the Python Interpreter and everthing together and make > a binary executabel (WIN) from the script. I don't find this in > "Programming Python" or "Learning Python" any more. > > Is it possible and where can I find a description? > > Thanks again. > > Marcus 2.: http://www.google.com/search?q=py2exe From benjamin.geer at misys.com Mon Oct 15 06:55:52 2001 From: benjamin.geer at misys.com (Benjamin geer) Date: 15 Oct 2001 03:55:52 -0700 Subject: Zope vs PHP for the Linux guru References: Message-ID: <4bf6cf6d.0110150255.1518bbed@posting.google.com> claird at starbase.neosoft.com (Cameron Laird) wrote in message news:... > Zope scales fine. There's a lot that goes into this; > the one-line summary is that Zope more than holds its > own. Has the Python interpreter's global thread lock caused any difficulties in getting Zope to scale well? If so, I'd be very curious to know how this hurdle has been overcome. I often use Python as a cleaner alternative to shell script, but the idea of a global thread lock after every fifth instruction has always made me wary of using it for anything in which performance is critical. Could anyone fill me in on the current status of the global-thread-lock issue? Is there a consensus on whether it's important, and if so, what should be done about it? Benjamin From matt at mondoinfo.com Wed Oct 3 17:13:22 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Wed, 03 Oct 2001 21:13:22 GMT Subject: Socket programming References: <1854cfa0.0110031208.778d4883@posting.google.com> Message-ID: On 3 Oct 2001 13:08:41 -0700, Krish wrote: >Is there an online tutorial on UNIX network programming using python? Yes, there is. It's at: http://py-howto.sourceforge.net/sockets/sockets.html Regards, Matt From skip at pobox.com Sat Oct 20 10:24:01 2001 From: skip at pobox.com (Skip Montanaro) Date: Sat, 20 Oct 2001 09:24:01 -0500 Subject: silly idea - interesting problem In-Reply-To: <3BD17C50.9D7D35AE@metaslash.com> References: <3BD17C50.9D7D35AE@metaslash.com> Message-ID: <15313.35073.966268.735856@beluga.mojam.com> >> ... a small script which takes to strings (lets say "test" and >> "dust") and mixes them to "tdeusstt". Neal> ''.join([ a for x in zip('test', 'dust') for a in x ]) There's always ''.join([x+y for x,y in zip('test', 'dust')]) or "".join(reduce(operator.add, zip('test', 'dust'), ())) Dunno if they are "easier" or "cleaner" however... ;-) -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From uwe at rocksport.de Wed Oct 17 09:23:53 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 17 Oct 2001 13:23:53 GMT Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> Message-ID: <9qk0p9$6tulc$1@hades.rz.uni-sb.de> Emile van Sebille wrote: | How about: |>>> a | array([3, 4]) |>>> `a` | 'array([3, 4])' |>>> ky = `Numeric.array((3,4))` |>>> ky | 'array([3, 4])' | Not ideal, but would work in a pinch. ;-) shurely it's possible to assign each array an hashval. this can be done by converting an array to a tuple (or a tuple of tuples in the 2d case). but: how can i expand numpy, such that a hashval is considered. i tried Numeric.array.__hash__ = lambda x: hash(tuple(x)) but i get "object has readonly attributes".... greetings, uwe. | --------- | "Uwe Schmitt" wrote in message | news:9qhksb$6raii$1 at hades.rz.uni-sb.de... |> Hi, |> |> I'd like to use a dictionary with NumericalPython-arrays as keys. |> This does not work, because NumPy does not provide hashvals for |> arrays. But this could be easyly done, as tupels are hashable. |> So: how can I extend NumPy, so that arrays get a hashval ??? |> |> Greetings, Uwe. |> |> -- |> Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes |> phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 |> D-66041 Saarbr?cken |> http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 |> -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From gabriel_ambuehl at buz.ch Tue Oct 2 11:06:30 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Tue, 2 Oct 2001 17:06:30 +0200 Subject: XML Marshalling of objects In-Reply-To: <3BB9D473.3070801@windh.com> References: <139677110373.20011002160803@buz.ch> <3BB9D473.3070801@windh.com> Message-ID: <191680617626.20011002170630@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello peter, Tuesday, October 02, 2001, 4:51:31 PM, you wrote: > Hello Gabriel, > do you still have that framework? I'd like to use it for the > familiar linux distribution on the IPAQ handheld > (familiar.handhelds.org) and create a PIM aplication that can sync > via SyncML with Outlook, Evolution etc. Have a look at http://www-106.ibm.com/developerworks/xml/library/xml-matters1/ Best regards, Gabriel  -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO7nJ6sZa2WpymlDxAQHPPwgAzLWGNzBOnVWIw3wbu8sqVsFF6fTLAYcq 4fyGSfEnbYq8xb3NB0J+LjKAfdKDhokA4bxxni+ZxSkSSsGhZE5fHjHwkfkf+APr TVGb2I29YEQ/tPOTv7J/VF83z8AqcVcDD995TMPxzSX67Clfd67L6BIWwmMD+nRX HmMOTSFmdLRKJx3vdQOEkI/bx2NAnk1YLkDK+rGki3VMwCqQOVlYGxUM8ebAETde 2SctmwOFORPUCQMKsRU/6y8ySNYVNV4qcb/iabpTjY5dRg9cg2N2Imfgb0n1j8Ep 2GQ60/2DNjlo/YKvN7+oaUS1n68yWAHkC6iBOPvb35INn0KrC5fByg== =E3Or -----END PGP SIGNATURE----- From seb.goldstein at caramail.com Tue Oct 2 04:32:19 2001 From: seb.goldstein at caramail.com (=?ISO-8859-1?Q?S=E9bastien?=) Date: 2 Oct 2001 01:32:19 -0700 Subject: Problem with Swig/C++/Python and python21.lib Message-ID: <2a8f832c.0110020032.3a48fba6@posting.google.com> Hey, I'm currently using Swig to integrate python and C++. I work with Win2000, MSVC++ 5.0 and Python 2.1 >From my test.h, test.cpp and test.i, Swig generates a test_wrap.cpp. I include in the project settings all the necessary directories. I try to build a release version and I have this error message : --------------------Configuration: test - Win32 Release-------------------- Compiling... test.cpp test_wrap.cpp Linking... c:\Python21\libs\python21.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3bb5cb9b Error executing link.exe. test.dll - 1 error(s), 0 warning(s) Has someone already encountered this error message or could someone help me ? Thanks a lot for your help. S?bastien. From zooko at zooko.com Tue Oct 23 10:22:55 2001 From: zooko at zooko.com (Zooko) Date: Tue, 23 Oct 2001 07:22:55 -0700 Subject: new version of trace.py available Message-ID: [please Cc: zooko at zooko.com in replies, thanks] I wanted to get code coverage analysis of Mojo Nation[1] and dist/src/Tools/scripts/trace.py didn't work for me (possibly because I didn't know how to use it or because). I started digging around in it trying to figure out what was wrong and I ended up rewriting most of the core to use the new (as of Python 2.1) debugger hooks and to do a few other things the way I thought they should be done. This version seems to work for me (python 2.2a4+), in both "tracing" and "counting" modes. It's darned slow, but I can't see how to make it any faster. More details are visible in the changelog in the comments in the file, which is available from Mojo Nation's CVS repository[2]. Regards, Zooko [1] http://mojonation.net/ [2] http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mojonation/evil/common/trace.py?rev=HEAD&content-type=text/vnd.viewcvs-markup From fb at ultranet.com Wed Oct 31 13:28:44 2001 From: fb at ultranet.com (F Basegmez) Date: Wed, 31 Oct 2001 13:28:44 -0500 Subject: python development practices? References: Message-ID: <9rpflc$f1p$1@bob.news.rcn.net> Maybe the next slogan for the 10th International Python Conference should be "Python has nothing to hide." Fahri "Peter Wang" wrote in message news:e1iuttghajb226flvq9jr07ddq229tki38 at 4ax.com... > are there good references on using Python in a commercial, team > development environment? > > i have been advocating and slowly convincing various people in my > company to use Python. i've successfully used it to write a few tools > and an application. however, the general perception is that it is a > good scripting language and possibly acceptable for single-person > development use, but it doesn't afford use in a large-scale software > team. the lack of data hiding, the lack of data coverage tools > (pre-run-time linting), and the lack of interfaces and strong types > are the typical turn-offs, in addition to the minor but omnipresent > tab indentation issue. :-) > > while i feel that Python makes me far more productive as a programmer > for all the projects on which i've worked, i'm inclined to agree that > the lack of data hiding coupled with lack of a standard interface > specification would cause problems in a team. > > how do Python development teams get around these issues? does using > Python in a commercial software team simply require more disciplined > programmers? > > i'm eager to hear everyone's thoughts... > > -peter From brian_zhouNOSPAM at techie.com Mon Oct 22 16:03:27 2001 From: brian_zhouNOSPAM at techie.com (Brian Zhou) Date: Mon, 22 Oct 2001 13:03:27 -0700 Subject: a better prime number generator References: <23d58b26.0110210939.55bb7e0c@posting.google.com> <1003732032.597037@emperor.labs.agilent.com> Message-ID: <1003781005.915476@emperor.labs.agilent.com> # A little improvement. def primes(max): def sieve(candidates): if candidates[0] ** 2 > max: return candidates x = candidates.pop(0) return [x] + sieve([y for y in candidates if y % x != 0]) return [2] + sieve(range(3, max + 1, 2)) "Brian Zhou" wrote in message > The one comes with python source Demo/scripts/primes.py should be very fast. > But just for fun, here is one more, using recursion and list comprehension: > > def primes(max): > def sieve(l): > if l[0] ** 2 > max: return l > x = l.pop(0) > return [x] + sieve([y for y in l if y % x != 0]) > return sieve([2] + range(3, max + 1, 2)) > > -Brian > > > "Rupendra Dhillon" wrote in message > news:23d58b26.0110210939.55bb7e0c at posting.google.com... > > hi all, > > I have just been introduced to pyton and find it a very good ( takes > > off all the bookwork ) language. I was trying to develope a ast prime > > number generator. I designed the following algo. Can you please > > suggest a faster one or modifications to this only to make it faster > > > > #the following algo returns all the primes below x > > > > def getPrimesTill(x): > > a = range(2,x) > > c = [2] > > > > i = 0 > > j = 0 > > > > foundone = 1 > > > > while i < len(a): > > while j < len(c) and (c[j] < (.5 * a[i]) ) and foundone == 1: > > if a[i]%c[j] == 0: > > foundone = 0 > > j = j + 1 > > if foundone == 1 and i > 0: > > c.append(a[i]) > > j = 0 > > foundone = 1 > > i = i + 1 > > return c > > > > > > roop > > > From root at [127.0.0.1] Fri Oct 19 23:36:30 2001 From: root at [127.0.0.1] (nobody) Date: Sat, 20 Oct 2001 13:36:30 +1000 Subject: struct module Message-ID: <3bd0f13e$0$27332$afc38c87@news.optusnet.com.au> Can someone tell me what I'm missing here? >>> struct.calcsize('H') 2 >>> struct.calcsize('B') 1 >>> struct.calcsize('HB') 3 wait for it... >>> struct.calcsize('BH') 4 ? From paul at zope.com Tue Oct 16 10:36:19 2001 From: paul at zope.com (Paul Everitt) Date: Tue, 16 Oct 2001 10:36:19 -0400 Subject: Zope consultant needed UK References: <3BCBEC8C.D9E82D97@mail105.com> Message-ID: <3BCC45E3.40607@zope.com> Hello Simon, I suggest you take a look at the EuroZope website: http://www.eurozope.org/ --Paul Simon Martin wrote: > Dear Group, > > Hope this isn't inappropriate... > > We need a really good Zope consultant for a very ambitious open source > project. Anyone out there in the Herts/London area? Please get in touch > so we can talk, I'm not interested in going through agencies etc at this > stage. > > Many thanks > > Simon > -- > Simon Martin > London Uk > 020 8386 5828 > PGP KEY ID <0xFA69D420> @ > *Please note my e-mail address is now 'simonmartin at mail105.com'* > > From unknown at lee-morgan.net Wed Oct 3 01:39:30 2001 From: unknown at lee-morgan.net (Lee Morgan) Date: Wed, 03 Oct 2001 05:39:30 GMT Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> Message-ID: Cliff Wells writes: > > Actually, unless you were embedding Python in your app I don't think this is > true, since _your_ source would not in fact contain any GPL'd code. > Additionally, I expect the Python libraries would fall under LGPL so using > them would not "infect" your code. > This may be off topic but what does it mean to release a python module/package under LGPL? An import is not a linking ... so does it mean I can't use it in a commercial product? I'd like to think I could use it if I released any changes I made to the module/package - but I don't think thats the case. (Commercial as in closed source) > -- > Cliff Wells > Software Engineer > Logiplex Corporation (www.logiplex.net) > (503) 978-6726 x308 > (800) 735-0555 x308 > -- Lee Morgan From loewis at informatik.hu-berlin.de Sun Oct 21 08:35:25 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 21 Oct 2001 14:35:25 +0200 Subject: Dictionary from list? References: <6KVz7.132664$vq.30203786@typhoon.ne.mediaone.net> Message-ID: Jim Correia writes: > I was just asking if there was a built in coercion available. > (Coercions aren't unheard of in scripting languages.) And indeed, Python does have conversions. Since variables are untyped, it never does them on assignment. Also, this particular conversion is not supported in the standard library. If there would be a frequent need for it, it probably would be added. Note that the list->dictionary conversion is not as obvious as you think. Given [(1,2),(3,4)] would you like to get a) {1:2, 3:4} or b) {(1,2) : (3,4)} Your answer is probably b), but many Python people would rather expect a) (since it would be the reverse of the .items() operation). Regards, Martin From shriek at gmx.co.uk Tue Oct 23 23:53:40 2001 From: shriek at gmx.co.uk (Stephen) Date: 23 Oct 2001 20:53:40 -0700 Subject: J2EE equivalent in Python References: Message-ID: <97ae44ee.0110231953.7abe7553@posting.google.com> One of the great things about J2EE or just JSP/servlets is the ability to create your web application (war file) and deploy it on any of the application servers on the market, be it Tomcat, BEA, Websphere, iPlanet, Blazix, or whoever. If one of these Python web projects/products mentioned here were to support similar behaviour, perhaps based on jython, then it would be a clear winner. The market (read "employment") dictates that I use Java/JSP/Servlets/Javabeans nowadays, using jython for prototyping, and sidelining python for my own client-side GUI applications, that are more for personal rather than commercial use. Stephen. From quinn at cruzeiro.ugcs.caltech.edu Fri Oct 19 16:56:51 2001 From: quinn at cruzeiro.ugcs.caltech.edu (Quinn Dunkan) Date: 19 Oct 2001 20:56:51 GMT Subject: Dictionary from list? References: <6KVz7.132664$vq.30203786@typhoon.ne.mediaone.net> Message-ID: On Fri, 19 Oct 2001 13:17:54 GMT, Jim Correia wrote: >In article , Michael Hudson >wrote: > >> > I'm a python newbie. I know how to do it "by hand" with a loop, but is >> > there a built in conversion operater that will let me do something >> > simply like the perl assignment? >> >> No. Write the loop. > >That's unfortunate - a simple assignment would be better. In the >simplest case of my usage, the loop (while ultra short) could be 50% of >the code. This doesn't make any sense to me. If a two line loop is 50% of your program, then your program is four lines. If you're going to play meaningless line-counting games at least come up with some more impressive numbers :) And assignment that uses a heuristic to convert an array into a hash is not really "simple". >> I've never found myself needing to do this, but that may be because >> I'm not used to having a convenient way of going from >> [k1,v1,k2,v2,...] to a dict. > >The particular situation is the python implementation is going to be a >command line script. The calling convention for this script is to pass >arguments on the command line in key value pairs. The perl >implementation looks like (in the simplest case) > >my %args = @ARGV; > >foreach(keys %args) >{ > print("$_: $args{$_}\n"); >} > >And it would be called from the command line as > >perl myScript.pl name fred age 23 occupation "gravel worker" import sys d = {} assert (len(sys.argv)-1) % 2 == 0, \ 'argv must consist of pairs, key "%s" has no value' % sys.argv[-1] for i in range(1, len(sys.argv), 2): d[sys.argv[i]] = sys.argv[i+1] for k, v in d.items(): print k + ': ' + v Note that the python version actually checks to make sure the input makes sense. There's no way to know how the perl version reacts to bad input except by testing it or reading the documentation. I suspect perl will silently give the last key a nil value, but once again there's no way to know for sure by just looking at it. Hopefully you and everyone who reads your code has all the little details in the camel book memorized. This is a good demonstration of why many people prefer the explicit python approach. What if you want bad input to report an error? What if you want it to not be an error, but you want the default value to be something other than nil? What if you start off wanting it to be an error, but later decide it should give a default value? If you wrote this in perl using assignment, you'd have to write a function and then track down all those assignments (have fun checking every assignment in a large program) and replace them with a function call. Learning a new language involves more than learning the syntax and libraries. Consider python an opportunity to gain another perspective on the practice of programming. >I'd like to implement the script with the same calling conventions in >python, and have an "easy" (typing wise, not conceptually, but I guess >I'll have to write a reusable function) way to take the arguments on the >command line and turn them into a dictionary. A two line loop is pretty easy. If you want to do this a lot then yes, you should define a function, in which case 'd = dictconv(a)' is the same number of lines than '%d = @a;'. If you want to quibble, then yes, it's 7 characters longer, but consider that you don't have to type '%@;' which reduces the difference to 4 characters. '%@' involves pressing shift twice, so that further reduces it to a 2 character difference. You could then name the function dconv and type 1 *less* character! Isn't python great? From qrczak at knm.org.pl Wed Oct 31 02:55:52 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: Wed, 31 Oct 2001 07:55:52 +0000 (UTC) Subject: Sorting (not Python-specific) Message-ID: What are advantages and disadvantages in parametrizing sorting either by '<' or by the 3-way comparison? -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ QRCZAK From olov_johansson_not_for_sale at mail.ru Thu Oct 11 13:48:34 2001 From: olov_johansson_not_for_sale at mail.ru (Olov Johansson) Date: Thu, 11 Oct 2001 17:48:34 GMT Subject: help: Crossplattform audio functionality in Python References: Message-ID: "Gerhard H?ring" wrote in message news:mailman.1002814696.19145.python-list at python.org... > pygame (http://www.pygame.org/) contains a sound library that works on > *nix and Windows. It is based on several SDL libraries, so for > cross-platform sound only, it might be overkill. But it's cool stuff > nevertheless. I went straight to libsdl.org instead and downloaded their SDL 1.2.2 sources. They have, indeed, a crossplatform sound system (covering unix'es, mac and win32). Just compiling the soundsystem into a lib and writing a python interface for it should be quite easy. It's licensed under LGPL. I talked about libao previously, I checked that out again and it seems like there is some windows support i the cvs at least, libao is licensed under GPL. Both these libraries would suit my needs (libao would be the easiest to use because the python stuff is already written afaik), but in the longer term.. The Python core needs (imho) a builtin soundsystem which works on all platforms. Java has had this (though poorly implemented) from the beginning i think. I realize that neither libao nor libsdl could make it into the Python core because of their licenses (or could they?) - therefor I hope that there is some kind of initiative going on somewhere to make Python a bit more soundish! I would (as said) be happy to contribute to this if needed but really need to know how to :) Thanks, Olov Johansson sweden From sholden at holdenweb.com Wed Oct 31 11:28:57 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 11:28:57 -0500 Subject: newbie question References: Message-ID: " 1" wrote ... > I must have missed it in the tutorial or some thing. > > I want to know how to open and run a file in python. The tutorial said to > just type " python filename.py" and hit enter. I did this and it comes back > with an error message telling me the the file name is not defined. I wasn't > told that I had to define it first before I can run it. Is there an easier > way to run files otherthan defining them? > OK. When asking for help, it's usually a good idea to give more rather than less information, since you may not know what's going to be useful to the helper. In this case I am assuming that the file name that is "not defined" is python -- in other words, that when you type python filename.py the system can't find the Python interpreter, rather than the system is running Python which then cannot find filename.py. If this is the case then you are going to have to tell your command line interpreter (the Unix shell, or the NT/W98/W95/W2k cmd.exe program) how to find Python. This will involve modifying your "path setting". If this doesn't help you enough, perhaps you could let us see the exact error message, and tell us which OS you are using? regards Steve -- http://www.holdenweb.com/ From markus at schabi.de Thu Oct 11 11:31:24 2001 From: markus at schabi.de (Markus Schaber) Date: Thu, 11 Oct 2001 17:31:24 +0200 Subject: Curious assignment behaviour References: <101020012140297889%jwbaxter@spamcop.net> Message-ID: <2793844.VU6TSbVV5P@lunix.schabi.de> Hi, John W. Baxter schrub: > I never used a keyboard on which : and = used the same state of the > shift key. (I used a few which were the reverse of what we--on US > keyboards--now expect, with : unshifted and = shifted.) Just use German keyboard Layout. : is shift-. and = is shift-0 But there's a drawback: Trying to type :-) means Shift-:, then (without shift) a -, and after that shift-9... :-) markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From Andreas.Trawoeger at wgkk.sozvers.at Mon Oct 22 10:34:52 2001 From: Andreas.Trawoeger at wgkk.sozvers.at (Andreas.Trawoeger) Date: Mon, 22 Oct 2001 16:34:52 +0200 Subject: How is overloading __getitem__ in subclasses of str supposed to work in Pythton 2.2b1 ? Message-ID: Hi! A new Python 2.2 Beta version and another: Is this a bug or am I dumb question from myself (The last time I ran into the bug that overloading __str__ didn't work). Overloading __str__ does work fine in Python 2.2b1 (Thanks to Tim Peters for that). So my next adventure seams to be the __getitem__ method. The following short and simple implementation ends in an endless loop: from binascii import b2a_hex class octetstring(str): def __str__(self): return b2a_hex(self) def __getitem__(self,index): return b2a_hex(self[index]) o = octetstring('ABCD') print "o :",o print "o[0]:",o[0] Well this isn't a surprise because I'm using the [ ] method in __getitem__ which implements [ ]. But I have no clue how I could write an different implementation for __getitem__. cu andreas --- If you wrap the Internet around every person on the planet and spin the planet, software flows in the network. - Eben Moglen's Metaphorical Corollary to Faraday's Law From s713221 at student.gu.edu.au Sat Oct 27 09:17:56 2001 From: s713221 at student.gu.edu.au (Joal Heagney) Date: Sat, 27 Oct 2001 23:17:56 +1000 Subject: Question: How to only create new object instances? References: <9r74ra$94o$1@netnews.upenn.edu> Message-ID: <3BDAB404.A2D81230@student.gu.edu.au> Michael McGovern wrote: > > I am trying to create new cells only when they don't exist in a given library > of cells. In the case where they already exist in the supplied library, I > would like the "new" cell to refer to the exisiting cell in the library. > >>> from Cell import * > >>> lib1 = Library(name='lib1') > >>> i1 = Cell(cellName='A1',library=lib1) > >>> i2 = Cell(cellName='A1',library=lib1) > cell already exists > Traceback (most recent call last): > File "", line 1, in ? > TypeError: __init__() should return None > >>> The problem is exactly what the traceback reports. __init__() functions should return None, but in your definition, you're trying to return library.cellList[cellName]. > How can I accomplish this? Unless others can come up with more valid methods to achieve this, maybe you want to give up on Cell as a class, and turn it into a helper function instead? def Cell(self, cellName, library=None): if cellName in library.cellList.keys(): print "cell already exists" return library.cellList[cellName] etc. Or, looking at you're code, it may well be able to fiddle this into a __getitem__ method of you're library class and subsume the cell class entirely? >>> class ListLibrary: # You're checking that entries aren't already in there anycase. # There's no benefit for using a dictionary in this case, unless # you plan to access the list/dictionary from outside the class, which is # bad practice anyway. libList = [] def __init__(self): # probably can do away with this first bit, as self, by design, is meant to be unique. if self not in self.libList: self.libList.append(self) self.cellList = [] def add_cell(self,cell): if cell not in self.cellList: self.cellList.append(cell) else: print cell, " already exists in ", self, "\n" def __getitem__(self,cell): # add_cell already does the error-checking, we'll trust it # and just return the cell value. self.add_cell(cell) return cell def __repr__(self): return "%s" % self.cellList >>> lib1 = ListLibrary() >>> lib1.add_cell('hello') >>> lib1 ['hello'] >>> lib1['goodbye'] 'goodbye' >>> lib1 ['hello', 'goodbye'] >>> lib1['goodbye'] goodbye already exists in ['hello', 'goodbye'] 'goodbye' >>> It's a bit of a beginner's hack I must admit, expecting a __getitem__ to dynamically alter the object that it's retreiving data from. I expect to get flamed down by the community post-haste :). -- Joal Heagney is: _____ _____ /\ _ __ __ _ | | _ ___ | /__\|\ || ||__ |\ || |___|/_\|___] | / \ \_||__ ||___| \_|! | | \ \ ! From markus at schabi.de Wed Oct 3 16:53:11 2001 From: markus at schabi.de (Markus Schaber) Date: Wed, 3 Oct 2001 22:53:11 +0200 Subject: XML Marshalling of objects References: <9pdfd4$c0q$1@tyfon.itea.ntnu.no> <2347302.PoejJDZkT8@lunix.schabi.de> Message-ID: <1622465.rGMcOhtQpZ@lunix.schabi.de> Hello, David Bolen schrub: >> >> Here just follows the data stream from >> pickle() >> >> >> Just write the two-liner dtd for it, and you have pickle outputting >> valid xml, and with almost no speed loss :-) > > Even if you make the pickled_data element in your DTD a CDATA you're > going to have to post-process the pickle output to ensure it doesn't > include any characters that need to be quoted as entities in the XML > stream (e.g., "<"). Then of course, you've to to invert this on the > other side, so there's going to be some cost to the encoding/decoding. > > Might almost be better to use the binary pickle form, and then base64 > encode it, since that should be safe for an XML element content. That's correct, of course. mar "Never thought anyone would take this serious" kus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From tdelaney at avaya.com Wed Oct 31 00:10:35 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 31 Oct 2001 16:10:35 +1100 Subject: python development practices? Message-ID: > From: Anthony Baxter [mailto:anthony at interlink.com.au] > >>> Peter Wang wrote > > i don't think data hiding's purpose is to keep rogue programmers in > > line. it's partly to insulate imperfect development practice (e.g. > > sloppy documentation) and partly to define an interface for a class. > > But in that case, you're relying on the language to compensate for > your development processes... this seems a bit of a problem, > particularly > since a sloppy/lazy/poorly-informed coder is always going to find > a way to screw it up, regardless of whether the language prevents some > forms of screwups. #define private public #define protected public #include ... Fun for all the team :) Tim Delaney From jdunnett at uoguelph.ca Mon Oct 29 17:09:16 2001 From: jdunnett at uoguelph.ca (Jeffrey Dunnett) Date: 29 Oct 2001 22:09:16 GMT Subject: python binary search References: <9rht70.3vvdvgd.1@kserver.org> <3BDD4E503.8BA429E9@uoguelph.ca> <9rjtho$ff9$1@testinfo.cs.uoguelph.ca> <3BDDA885.EECA7D8D@home.net> Message-ID: <9rkk2c$kc2$1@testinfo.cs.uoguelph.ca> Chris Barker (chrishbarker at home.net) wrote: : Jeffrey Dunnett wrote: : > : Thanks for coming to my defence but I really MUST check my spelling beter. : > : > : Jeff : > : > Alright I will crawl back in the computer lab I came out of and look at : > an english dictionary since I incorrently spelled better. : Ouch! I was sure you did that on purpose. As someone who is a lousy : typist and a lousy speller, I highly recommend an email client with a : spell checker...and a little proofreading. : -Chris : -- : Christopher Barker, : Ph.D. : ChrisHBarker at home.net --- --- --- : http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ : ------@@@ ------@@@ ------@@@ : Oil Spill Modeling ------ @ ------ @ ------ @ : Water Resources Engineering ------- --------- -------- : Coastal and Fluvial Hydrodynamics -------------------------------------- : ------------------------------------------------------------------------ The proof reading and the spell checker can both be done. I will use them in the future Jeff From sholden at holdenweb.com Wed Oct 31 15:59:20 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 15:59:20 -0500 Subject: newbie question References: <9rpbr2$us4bd$1@ID-11957.news.dfncis.de> <3BE0394E.9C4E92BF@alcyone.com> <3be04a08.19984913@news1.lig.bellsouth.net> <3be053e7.293796@news1.lig.bellsouth.net> Message-ID: "lance crocker" wrote in message news:3be053e7.293796 at news1.lig.bellsouth.net... > > i just tried putting that path into the autoexec file and rebooting. > it didn't change anything i still get the same errors. > > when you go to open a file how do you do it? do you type python > hello.py while you are in commandline mode or while you are in gui > mode? > You type it in when you see the DOS command prompt - at the D:> prompt, or whatever. It's obvious you are getting Python to run, otherwise you wouldn't be seeing ">>>" as your prompt. But by the time you see that prompt it's too late: you are already running Python. At that stage import hello would work, but only once. After that you'd have to reload(hello) The DOS command prompt has no GUI mode! Here's a session in which I do more or less what you are trying to. In my case the "hello.py" program says hello to you rather than the world. C:\WINDOWS>d: D:\Steve>cd Projects\Python D:\Steve\Projects\Python>python hello.py Hello, Lance! D:\Steve\Projects\Python> Got it? regards Steve -- http://www.holdenweb.com/ From x at x.com Mon Oct 29 10:02:47 2001 From: x at x.com (Alberto Rodriguez) Date: Mon, 29 Oct 2001 16:02:47 +0100 Subject: win32com parameters References: <9rgqf0$k1d$1@diana.bcn.ttd.net> Message-ID: <9rjqch$riu$1@diana.bcn.ttd.net> Hi: >>> print ox.primero answer with: number1 (the correct answer) but when i send a parameter >>> print ox.primero('1') I have this error: Traceback (most recent call last): File "", line 1, in ? TypeError: object of type 'unicode' is not callable >>> TIA > Alberto: are you sure that primero IS a method? The error message seems to > imply it is an attribute, or property. > > Try: > > import win32com.client > ox = win32com.client.Dispatch("proy1.miclase") > print ox.primero > > to find out what datatype you are dealing with. > > regards > Steve > -- > http://www.holdenweb.com/ > > > > > From printers at sendme.cz Thu Oct 18 05:39:59 2001 From: printers at sendme.cz (A) Date: Thu, 18 Oct 2001 11:39:59 +0200 Subject: Python script engine Message-ID: <3BCEBF8F.32176.90A37A@localhost> Hello, In my application I would like to allow users to add/use basic python commands but I do not want users to change my code of application directly. For example my program expects telephone. number in format +442076812563 but a user sometimes may want to supply 0044 207 681 2563 (please note a blank). Then the user would need to use STRING.JOIN Python function to get from the user's input (0044 207 681 2563) the string that my program expects (+442076812563) Does anyone have any idea how to do that? Thank you for help Ladislav From madsdyd at challenge.dk Fri Oct 12 07:01:23 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Fri, 12 Oct 2001 13:01:23 +0200 (CEST) Subject: Link between a C variable and a python object In-Reply-To: <9q6fqv02o9g@drn.newsguy.com> Message-ID: On 12 Oct 2001, Armin wrote: > In article <3BC4366A.DC3F6982 at wanadoo.fr>, guignot says... > > > >Does Python have a nice feature of Tcl, i.e. linking an external C > >variable and an internal variable, with TclLinkVar ? > > Yes ... have a look to the C API. Could you possible be more specific? I have looked at the API, and the code generated by SWIG, and it seems that you need to use function calls - there seems to be no easy way to share a variable? Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk It is strange to claim that video games should influence children. If for example Pac-Man influenced children born in the 1980'ies, then today we would have a lot of young people jumping around in dark rooms, eating pills while listening to monotome music - Anonym From anthony at interlink.com.au Tue Oct 16 03:38:46 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 16 Oct 2001 17:38:46 +1000 Subject: FW: [Python-Dev] conditional expressions? In-Reply-To: Message from "Tim Peters" of "Mon, 15 Oct 2001 16:22:29 -0400." Message-ID: <200110160738.f9G7ckR19368@mbuna.arbhome.com.au> Ok, so we're getting yet another ugly hack added to the language. Could the normal process of writing up a PEP be followed, so that those people in the community who are uncomfortable about it can at least see the justification for this? Or has the PEP already been written, and I'm just going mental - it doesn't appear to be on the PEP page... Anthony -- Anthony Baxter It's never too late to have a happy childhood. From denis.fan at dcs.warwick.ac.uk Fri Oct 19 06:37:08 2001 From: denis.fan at dcs.warwick.ac.uk (Denis) Date: Fri, 19 Oct 2001 11:37:08 +0100 Subject: Help - Problems with Tk in Python Message-ID: <3BD00254.AAFFB236@dcs.warwick.ac.uk> Problems with Tkinter and _tkinter: I have installed Python 2.1.1 and Tcl/tk 8.3 into my directory (sun solaris). Python seems to work fine after a bit of tuning , but when I tried to import "Tkinter" (The GUI module in Python), it has come out the following error messages: >>> import _tkinter Traceback (most recent call last): File "", line 1, in? ImportError: id.so.1: /(directory)/Python-2.1.1/python: fatal: libtk8.2.so: open failed: No such file or directory >>> import Tkinter Traceback (most recent call last): File "", line 1, in? File "/(directory)/Python-2.1.1/Lib/lib-tk/Tkinter.py", line 35, in? import _tkinter # If this fails your Python may not be configured for Tk ImportError: id.so.1: /(directory)/Python-2.1.1/python: fatal: libtk8.2.so: open failed: No such file or directory Since I have installed Tcl/tk as well, (after ./configure and make command to build Python) I have changed the path setting of the tcl/tk headers and library files location into the new version one. Then run the 'make install' again, but mission unsuccessful! Fatal error occurs during the process of rebuilding the Python and now I am stuck ... Has anyone know how to tackle this? I would be really grateful to hear from you, many thanks Regards Denis -- Image Processing Group Dept. of Computer Science email: denis.fan at dcs.warwick.ac.uk University of Warwick phone: +44 24 7652 2438 Coventry, CV4 7AL, United Kingdom -------------- next part -------------- An HTML attachment was scrubbed... URL: From me at mikerobin.com Wed Oct 31 11:16:42 2001 From: me at mikerobin.com (Michael Robin) Date: 31 Oct 2001 08:16:42 -0800 Subject: Unpacking extension (Re: A small inconsistency in syntax?) References: <6q1yjkvpi6.fsf@abnoba.intevation.de> Message-ID: <52e5ab5f.0110310816.30e9f47f@posting.google.com> I'd think there's no reason to disallow it. Although in Python the comma operator creates tuples rather than the parens, for many it looks as if a,b = seq is just shorthand for (a,b) = seq and if it unpacks lists too (which it does) you may as well have the option of being explicit in your LHS pattern. Also, given that lists are mutable and tuples are not, the list notation makes some kind of sense, even though you're rebinding the names in the LHS rather than creating a list, per se. I think one issue is that tuple unpacking looks an awful lot like unification pattern matching a la prolog, because the shape of the LHS effects unpacking, in which case you'd expect a lot. But it's only ShapeAssign(LHS<--RHS) rather than Unify( LHS<-->RHS). Unpacking is a little to the left between multiple assignment and unification, which makes it pretty unique (i think?). I certainly can live w/o "[a,b] = foo" - but just another viewpoint... ------------- Bernhard Herzog wrote in message news:<6q1yjkvpi6.fsf at abnoba.intevation.de>... > "Steve Holden" writes: > > > wrote in ... > > > > > > Bernhard Herzog wrote: > > > >Personally, I wouldn't mind to see the "[a,b] = sequence" syntax go. > > > > > > I agree. I think it's confusing and adds no value (unless I'm missing > > > something). > > > > > But since it's been permissible for a long time, removing it might break > > existing code. Would you propose a PEP to go through the "from __future__ > > ..." phase and arrive at "feature removed"? As far as I'm concerned it > > remains a quirk, which I could easily live without but equally easily > > ignore. > > Certainly, and since it's relatively unimportant, it would be probably > best to remove it in 3.0, since that will at least some other > incompatible change like the behavior of the division operator. > > Bernhard From markus at schabi.de Fri Oct 12 03:21:19 2001 From: markus at schabi.de (Markus Schaber) Date: Fri, 12 Oct 2001 09:21:19 +0200 Subject: Program of wxPython works on NT but it does'nt works on Win98?? , References: <11e94203.0110111517.662e5255@posting.google.com> Message-ID: <1383752.adu78ljVUC@lunix.schabi.de> Hi, Jose Rivera schrub: > The problem is with the toolbar, it works on NT and when I copy the > same code to a Win98 PC, the toolbar does not even appear... Could you post an example that works on one platform, and doesn't work on the other? Try to keep it as clear and short as possible. Also, error messages or other console output might be helpful. markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From logiplexsoftware at earthlink.net Tue Oct 2 13:30:43 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 2 Oct 2001 10:30:43 -0700 Subject: newbie str to int In-Reply-To: <9pbetr$jp83@imsp212.netvigator.com> References: <9pbetr$jp83@imsp212.netvigator.com> Message-ID: <01100210304303.02289@logiplex1.logiplex.net> On Monday 01 October 2001 21:22, James wrote: > I am switching from Perl to Python, and would > like to convert string '123abc' to integer 123. > > foo = int('123abc') # error > foo = string.atoi('123abc') #error > foo = eval('123abc') # error > Why doing simple thing like this is so complicated ? I think the real question is why you have ill-defined data like '123abc'. Is this an int followed by a string or a big hex number? I think I would attack this problem at the source: whatever piece of code generated that data should be modified to insert a delimiter or not concatenate two bits of unrelated data. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From greg at cosc.canterbury.ac.nz Wed Oct 17 21:05:14 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 18 Oct 2001 14:05:14 +1300 Subject: FW: [Python-Dev] conditional expressions? References: <23891c90.0110160824.6a5a0c1b@posting.google.com> Message-ID: <3BCE2ACA.6A366ED0@cosc.canterbury.ac.nz> Michael Hudson wrote: > > I'm still waiting for the day when I can exploit the fact that > > 1jor-0land+4 > > is executable Python. Change your name to Ijor Oland and use it as an email address. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From phd at phd.pp.ru Thu Oct 11 06:58:41 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 11 Oct 2001 14:58:41 +0400 Subject: image from URL In-Reply-To: <3BC57869.E95139D7@ncsa.uiuc.edu>; from heiland@ncsa.uiuc.edu on Thu, Oct 11, 2001 at 05:46:01AM -0500 References: <3BC57869.E95139D7@ncsa.uiuc.edu> Message-ID: <20011011145841.I500@phd.pp.ru> On Thu, Oct 11, 2001 at 05:46:01AM -0500, Randy Heiland wrote: > >>> import urllib, Image > >>> fp = urllib.urlopen("http://www.python.org/pics/PyBanner027.gif") > >>> im = Image.open(fp) > Traceback (most recent call last): > File "", line 1, in ? > File "/home/heiland/PythonMod/Imaging-1.1.2/PIL/Image.py", line 944, > in open > fp.seek(0) > AttributeError: addinfourl instance has no attribute 'seek' im = Image.open(fp.read()) fp is not a file name, it is already file (file-like object, to be precise). Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From shalehperry at home.com Wed Oct 17 12:23:41 2001 From: shalehperry at home.com (Sean 'Shaleh' Perry) Date: Wed, 17 Oct 2001 09:23:41 -0700 (PDT) Subject: string.digits, string.letters? How? In-Reply-To: <3BCDCC6F.16954B08@starhub.net.sg> Message-ID: On 17-Oct-2001 Paul Lim wrote: > How can we use the digits, letters variable in the string modules? open string.py and you will see a line like: digits = '0123456789' This creates a string assigned to the variable 'digits'. >>> import string >>> s = '1' >>> s in string.digits 1 >>> s in string.letters 0 >>> l = 'A' >>> l in string.letters 1 ----- We have buried the putrid corpse of Liberty. -- Benito Mussolini From nospam at bigfoot.com Wed Oct 17 08:29:37 2001 From: nospam at bigfoot.com (Gillou) Date: Wed, 17 Oct 2001 14:29:37 +0200 Subject: Web Application Framework References: Message-ID: <9qjt86$2qjg$1@norfair.nerim.net> Another solution you could consider for handling / distributing XML repositories... http://www.fourthought.com/ a ?crit dans le message news: mailman.1003315396.8580.python-list at python.org... > > > Hi Pythoners, > > May I prevail on your patience once more. > > Oleg sent me the following links, and now I'm spoiled for choice. > > http://webware.sourceforge.net/ > http://www.mems-exchange.org/software/quixote/ > http://www.twistedmatrix.com/ > > > Can anybody comment on which of these would be the best to use for a stand-alone > application that generates all of it's forms on the fly from data stored in some > or other datastore, possibly in XML documents. No forms are stored on disk at > all. > > > Thanks, Craig > > > > > > ------------------Edcon Disclaimer ------------------------- > This email is private and confidential and its contents and attachments are the > property of Edcon. It is solely for the named addressee. Any unauthorised use or > interception of this email, or the review, retransmission, dissemination or > other use of, or taking of any action in reliance upon the contents of this > email, by persons or entities other than the intended recipient, is prohibited. > Save for communications relating to the official business of Edcon, the company > does not accept any responsibility for the contents of this email or any > opinions expressed in this email or its attachments . > If you are not the named addressee please notify us immediately by reply email > and delete this email and any attached files. > Due to the nature of email Edcon cannot ensure and accepts no liability for the > integrity of this email and any attachments, nor that they are free of any > virus. > Edcon accepts no liability for any loss or damage whether direct or indirect or > consequential, however caused, whether by negligence or otherwise, which may > result directly or indirectly from this communication or any attached files. > > Edgars Consolidated Stores LTD ,Post office box 200 Crown Mines, Telephone: > (011) 495-6000 > > > > > From johnroth at ameritech.net Sun Oct 7 11:15:33 2001 From: johnroth at ameritech.net (John Roth) Date: Sun, 7 Oct 2001 08:15:33 -0700 Subject: Newbie question about running scripts References: <3BBEC9FB.8080709@sneakemail.com> Message-ID: "Lenny" wrote in message news:a71afa52.0110070550.1ea7cd6b at posting.google.com... > I would like to thank Chris and Joshua for the information they gave > me. I forgot to let you know I am using Win98SE. I tried adding the > "set Path" string to the autoexe. file and restarting. By doing this, > I was able to run the string I wrote once I rewrote it in Notepad and > used explorer to get into the folder that it is stored in. It would > not run unless I had that folder open. Is that the way it should work. > Just for the heck of it to see if that did anything, I removed it from > autoexe. and the file would not run. Actually, autoexec.bat is not the best place to put this. The way I set thing up (on Windows 98 SE) is to put a DOS icon into each directory I'm going to be developing in, and add a .bat script to do the setup when I invoke the DOS box. That way, I don't have to worry about a global command line. > I tried downloading a lesson plan from a kids summer camp. This > included step by step lesson plans and sample programs and activites. > I was doing well until they got to the import command. I downloaded > the mod, then tried writing the program but it immediately came back > with"unable to locate file". Am I supposed to load mods to a > particular folder or list an additional path in the autoexe. file for > the location of these mods, or do I need to have the folder opened on > the desktop in the background in order for it to see it. The module needs to be either in your current directory or in your python path. You can permanently add it to your Python path with a .pth file in the main python directory. The documentation on this feature is kind of obscure. > I appologize for these questions that I know are far below what you > are normally used to answer, but I cant seem to find this info out > from any of the tutorials or help folders. It seems that most of the > tutorial assume that you know this already or you are having an > experienced programmer help you. Please let me know if I should use > another message board for these basic questions. I dont want to use up > space on your site if these questions are inappropriate. I am kinda > looking to you all as my "experienced programmers". As I said before, > I had programmed with COBOL, BASIC, and FORTRAN in the early 80's but > things have gotten much more advanced since then. Well, different at least. This is the correct newsgroup, and novice questions are what keeps the documentation writers on their toes. John Roth > Again, Thank you for all your help with these questions. From phr-n2001d at nightsong.com Wed Oct 31 00:58:51 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 30 Oct 2001 21:58:51 -0800 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> Message-ID: <7xzo68s63o.fsf@ruckus.brouhaha.com> Peter Wang writes: > i don't think data hiding's purpose is to keep rogue programmers in > line. it's partly to insulate imperfect development practice (e.g. > sloppy documentation) and partly to define an interface for a class. Keeping rogue programmers in line is a perfectly legitimate use of data hiding. For example, look at java applets on web pages. These have to run in the same JVM as parts of the browser, and yet the applets can be hostile. So the language has to protect the browser internals from the loaded applets. Another example is security interfaces where the class instances contain authentication credentials and the application should be able to use them but not copy them. Python provides a restricted execution hack (rexec/bastion) to deal with the applet situation, but it's a pain for the second situation because you have to wrap the caller in the rexec shell, rather than wrapping the secure object in a security shell and leaving the caller unrestricted. The best way I've managed to deal with this is to put the secure objects in a totally separate process and access them by RPC. That, too, is a kludge, though. From sonyi at iae.re.kr Wed Oct 24 04:09:18 2001 From: sonyi at iae.re.kr (¼Õ¿µÀÏ) Date: Wed, 24 Oct 2001 17:09:18 +0900 Subject: [wxPython] metafile usable in wxpython? Message-ID: <9r5s2v$2oh$1@news2.kornet.net> If anyone knows about the usage of wxMetafile and wxMetaFileDC in wxPython, please allow me to know that. I want to convert the drawings on a wxPanel or transfer it to other programs such as MS-word. Currently, I use Windows NT and Windows 98, Python 2.1 and wxPython 2.3.1 Young-il Sohn From maxmcorp at worldonline.dk Sun Oct 7 05:28:20 2001 From: maxmcorp at worldonline.dk (maxm) Date: Sun, 7 Oct 2001 11:28:20 +0200 Subject: Python and Zope References: Message-ID: "Magnus" ... > When using to 'include' files/objects it is working > well if the files are in the same directory. Your question can mean several different things, i'll try to answer them. If you want to build a news site with articles in different folders like: home/ general/ article1 article2 article3 computers/ Hifi/ article4 Politics/ article5 article6 And if you then want to have a list of all the articles on the front page you could either traverse the folders manually
Or you could use the Catalog to to list the articles. This is probably the best way to do it in the long run and it will be faster too. regards Max M From michael at rcp.co.uk Tue Oct 16 05:34:18 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Tue, 16 Oct 2001 09:34:18 +0000 (UTC) Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <3bcbebf3$0$42126$edfadb0f@dspool01.news.tele.dk> <7xelo4yoj4.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote in news:7xelo4yoj4.fsf at ruckus.brouhaha.com: > "Anders J. Munch" writes: >> Combine that with the form mentioned (though not preferred) by Michael >> Abbott elsewhere we get: >> >> x = (if e1: e2 else: e3) >> >> No new keyword, consistent with if-statement syntax and hence more >> intuitive to someone who knows Python but not a heap of other >> languages as well. And it's slightly more terse than the if-then-else >> form, which is important because terseness is the only reason to use a >> conditional expression in the first place. > > Hey, I like that one too. You could even include an elif: > x = (if e1: v1 elif e2: v2 else: v3) I have to say I prefer the emerging form x = if e1 then v1 elif e2 then v2 else v3 The parentheses are certainly not required, and can always be added by those who like to use them. I'm pretty sure that x = if e1: v1 elif e2: v2 else: v3 will work without the brackets; again, bracket enthusiasts can add them to taste! From loewis at informatik.hu-berlin.de Sat Oct 27 15:08:24 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 27 Oct 2001 21:08:24 +0200 Subject: python and dom xml References: Message-ID: subwizin at yahoo.co.in writes: > my server has Python 1.5.2 installed. i want to know whether i will > be able to parse dom using this version of python. does it require > any modules to be installed? By "parsing dom", I assume you mean "parse XML, creating a DOM tree". For that, you need additional modules; I recommend to install PyXML (pyxml.sf.net). > if so, will i be able to install these without the help of server > admin? Yes. You just need to specify an alternative destination directory. Regards, Martin From fredrik at pythonware.com Wed Oct 17 16:45:02 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 17 Oct 2001 20:45:02 GMT Subject: os.path.join and lists References: Message-ID: Dave Swegen wrote: > It looks somthing like this: > > bar = [ "fred", "barney", "froo" ] > foo = os.path.join(bar[1:2], "bob") how about bar = [ "fred", "barney", "froo" ] baz = bar + [ "bob" ] foo = os.path.join(*baz) (but please use "spam" and "egg" instead of "foo" and "bar" -- this is a python newsgroup, after all) > Basically, I guess the question is: How do I quote the values in a list > (similiar to perl's, qw I guess)? I have no idea what you're talking about here... From robin at jessikat.fsnet.co.uk Sat Oct 13 09:20:45 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 13 Oct 2001 14:20:45 +0100 Subject: signum() not in math? References: <3BC7FE9B.CD190C62@darwin.in-berlin.de> <3BC812DE.8C6C260@darwin.in-berlin.de> Message-ID: In article <3BC812DE.8C6C260 at darwin.in-berlin.de>, Dinu Gherman writes >> Indeed the matrix sign function is a true heaviside function >> (http://rkb.home.cern.ch/rkb/AN16pp/node117.html) on each element x the >> result is 2*h(x)-1 ie -1 for x<0 and 1 for x>=0. >> >> Probably python should provide both the three value signum and the two >> value one and perhaps the sign transfer operation. These are so common >> in maths, physics and engineering it seems wrong to have sinh() without >> h() et al. > >One free pint! ;-) Well, yes a general step() function could >be useful, too, maybe like this, even if you don't find it >usually in entry-level math textbooks: > > def step(x, x0=0): > "Generalised Heaviside step function." > > if x < x0: > return 0 > else: > return 1 well as a Heaviside award winner I presumably should be expected to know about such arcana ;) -- Robin Becker From jeremy at bears Mon Oct 8 21:22:17 2001 From: jeremy at bears (Jeremy) Date: 08 Oct 2001 20:22:17 -0500 Subject: Newbie: problem comparing values In-Reply-To: <9pqe9i$h0q$1@verence.demon.co.uk> Message-ID: <873d4tli9i.fsf_-_@yahoo.com> Hi, I'm trying to set up a script to check to see whether the person running the script is root or not. If they are, I want to make it exit immediately. This is the code that I have that I'm trying to use: user = os.popen("whoami").read() if user == "root": print "You are logged in as root" else: print "You are not logged in as root." The problem is that each time, no matter if it's root or not that's running the script, it always says "You are not logged in as root." I know that this has to be something small that I'm missing, and please forgive me for asking such a "simple" question, but I've only been at this for a couple of days (with python. I have a few months of experience with bash scripts). I've checked about every resource I can think of and I still can't figure out what I'm doing wrong. Thanks in advance for your help, Jeremy From chrishbarker at home.net Tue Oct 23 14:18:17 2001 From: chrishbarker at home.net (Chris Barker) Date: Tue, 23 Oct 2001 11:18:17 -0700 Subject: interactive interpreter References: Message-ID: <3BD5B469.F08ABAEF@home.net> Karol Makowski wrote: > How to run myprogram.py in interactive interpreter? depending on exactly what you mean, there are three options: import myprogram.py execfile("myprogram.py") $python -i myprogram.py I'm guessing you want the execfile option. That makes the namespace of your program the main namespace, which makes it easiest to examine values, etc when it's done running. import runs the code, but puts everything into the modules namespace. running python with -i will run the program, and then leave you with and interactive interpreter when it's done. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From daves_spam_dodging_account at yahoo.com Thu Oct 25 14:45:14 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Thu, 25 Oct 2001 11:45:14 -0700 (PDT) Subject: Critical sections and mutexes Message-ID: <20011025184514.33198.qmail@web21102.mail.yahoo.com> > -----Original Message----- > From: Cliff Wells > [mailto:logiplexsoftware at earthlink.net] > Subject: Re: Critical sections and mutexes > > If this were a classroom, then I would probably > concede at this point. However, without the luxury > of being able to hold someone's hand and lead > them step-by-step, I think it's best to just give > them the most appropriate information for solving > their immediate problem. As the Newbie In Question, I'd like to chime in here and say that (a) the help that has already been provided has been most useful, and (b) watching this discussion has really helped me work out some of the finer points of the issue. > > I think it discourages newbies to bombard them > > with all the locking issues up front, and it's > > a real strength of Python (especially for > > programming newbies) that you can often "get > > away" with no explicit thread-safety measures. I both agree and disagree. To a newbie unfamiliar with threading in the first place, yes, I can see that bombarding them with the locking issues can be discouraging. In my case, however, I'm familiar with threading, and I have found Python's locking mechanism to be absolutely brilliant. I knew what I wanted to do; I just needed someone to explain the Python way of doing it. Once I learned that I couldn't do critical sections, I redesigned those parts of my code that wanted them to use shared resources instead, and I was in business. My take on this point is that one should always err on the side of too much information rather than too little. :-) Both sides of this discussion should take that as a compliment, btw. It turns out I'm going to need a more complete locking scheme than the GIL provides, but now I can say that because I have a better feel for where the GIL stops and manual locking has to start. For example, I can predict a common type of race condition in my class without any extra locking. My class looks something like this: class PriorityQueue: def __init__(self): self.NormalQueue = Queue.Queue() self.PriorityQueue = Queue.Queue() self.IsWaiting = 0 Now, the Queue.Queue()'s are themselves threadsafe, so I shouldn't have any collisions accessing either queue directly. However, I have a Push() and Pop() method as well. Push() puts a message on one of the queues (depending on whether or not the priority flag is set), and then sets the IsWaiting flag. Pop() checks the priority queue first, then the normal queue, and returns one message. If both queues are empty after the message is popped, it sets the IsWaiting flag to 0. If the class itself doesn't support locking, it would be possible for one thread to drain all the queues, and be just about to clear the IsWaiting flag, then have another thread push a message and set IsWaiting, and then return to the first thread who clears IsWaiting. We are left with a message in the queue but nobody retrieves it until more messages arrive and set IsWaiting again. Again, thank you all for your comments. -dB ===== David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From dale at riverhall.NOSPAMco.uk Tue Oct 16 09:38:21 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Tue, 16 Oct 2001 14:38:21 +0100 Subject: Conditional Expressions don't solve the problem Message-ID: I'm a bit mystified by all the activitiy on conditional expressions that appears to have originated from a post a while ago about curious assignment behaviour. Have I missed something here (quite possible) or are the two issues related? Because it doesn't seem so to me. The original discussion went on to talk about the loop and a half problem which sumarised it quite nicely for me. Take this short extract from some code I'm working on at the moment: term = self.nextTerm() while term: handled = 0 for a in argObjects: # Loop through all the type Handlers. if a.test(term): # Pass arg to handler. handled = 1 break # If true, handler has dealt with it. if not handled: raise whatever term = self.nextTerm() I think this is verbose. I would much prefer be able to write: while term := self.nextTerm(): for a in argObjects: if handled := a.test(term): break if not handled: raise whatever Choose your own asignment operator. How does the if/then/else construct help me here? -- Dale Strickland-Clark Riverhall Systems Ltd From nobody at tex.kom Tue Oct 16 16:06:45 2001 From: nobody at tex.kom (Kevin) Date: Tue, 16 Oct 2001 20:06:45 GMT Subject: Python app. Eroaster and "output = pipe[0].readlines()" trouble Message-ID: I'm having a new trouble with a python application called Eroaster. The error message I get is: File "/usr/lib/python2.0/site-packages/gtk.py", line 125, in __call__ ret = apply(self.func, a) File "/usr/lib/eroaster/main.py", line 1468, in DetectRecorder self.DetectSCSIDevice(deviceRecorder) File "/usr/lib/eroaster/main.py", line 1477, in DetectSCSIDevice output = pipe[0].readlines() IOError: [Errno 4] Interrupted system call The code around line 1477 in main.py is: # Detect SCSI-devices def DetectSCSIDevice(self, device): pipe = popen2.popen2("cdrecord -scanbus 2>&1") output = pipe[0].readlines() devicelist = [] If I execute "cdrecord -scanbus" I get the appropriate output for my system: Cdrecord 1.9 (i586-mandrake-linux-gnu) Copyright (C) 1995-2000 J?rg Schilling Linux sg driver version: 3.1.19 Using libscg version 'schily-0.1' scsibus0: 0,0,0 0) * 0,1,0 1) 'IBM-PSG ' 'DPSS-318350N M ' 'S9AA' Disk 0,2,0 2) 'QUANTUM ' 'ATLAS_V__9_WLS ' '0230' Disk 0,3,0 3) 'HP ' 'CD-Writer+ 9200 ' '1.0e' Removable CD-ROM 0,4,0 4) 'NEC ' 'CD-ROM DRIVE:222' '3.1k' Removable CD-ROM 0,5,0 5) 'HP ' 'HP35470A ' 'T503' Removable Tape 0,6,0 6) * 0,7,0 7) * This exact application used to run just fine a month or two ago. Since then I've updated my kernel from 2.4.3 to 2.4.7-12.3mdk on my Mandrake 8.0 system. I'm sure I've made a few more updates, like all of Mandrake's security patches. Does anyone know what's going wrong here? Does anyone have any debugging suggestions? I'm an experienced programmer/debugger but I'm totally new to python. Thanks... -- Unless otherwise noted, the statements herein reflect my personal opinions and not those of any organization with which I may be affiliated. From rafial at well.com Mon Oct 8 16:41:34 2001 From: rafial at well.com (Wilhelm Fitzpatrick) Date: Mon, 08 Oct 2001 20:41:34 -0000 Subject: why are *two* ctrl-D's needed with readline() Message-ID: <9pt31u+4r45@eGroups.com> --- In python-list at y..., Marcin 'Qrczak' Kowalczyk wrote: > Fri, 5 Oct 2001 14:34:17 -0400, Steve Holden pisze: > > > Technically ^D terminates transmission, and only raises EOF if this > > result in an empty input buffer, which it does if entered before > > inputting any characters. > > So in normal circumstances programs shouldn't try to read after EOF > was seen, because it makes a difference for terminals. So would it be reasonable to report this as a bug? Certainly, I found the behavior surprising and non-standard... From phr-n2001d at nightsong.com Sun Oct 14 07:29:08 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 14 Oct 2001 04:29:08 -0700 Subject: Python web client anyone? Message-ID: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> Anyone know if there are any web client modules written in Python, along the lines of the Perl LWP module? Thanks. Paul From Andreas.Trawoeger at wgkk.sozvers.at Thu Oct 4 07:10:12 2001 From: Andreas.Trawoeger at wgkk.sozvers.at (Andreas.Trawoeger) Date: Thu, 4 Oct 2001 13:10:12 +0200 Subject: Python 2.2a4: Problems with overloading __str__ in subclasses of str Message-ID: Hi! I just ran into a strange problem with Python 2.2a4. I would like to write a class that behaves like an string only with the difference that it displays the string in hex. In Python 2.2a4 this should be possible by subclassing str and overloading __repr__ and __str__ : from binascii import b2a_hex class octetstring(str): def __repr__(self): return b2a_hex(str(self)) def __str__(self): return b2a_hex(str(self)) o = octetstring('A') print "o.__repr__():",o.__repr__() print "o.__str__() :",o.__str__() print "str(o) :",str(o) print "o :",o The result is pretty strange: o.__repr__(): 41 o.__str__() : 41 str(o) : A o : A I'm not shure what's the exact reason for this problem. Either __str__ isn't used for str() and print. Or I'm trapped in an chicken egg problem: I have to convert self to an string (otherwise b2a_hex won't work) to do this Python should use __str__ (which is the method I'm changing). cu andreas --- If you wrap the Internet around every person on the planet and spin the planet, software flows in the network. - Eben Moglen's Metaphorical Corollary to Faraday's Law From huaiyu at gauss.almadan.ibm.com Tue Oct 16 18:17:20 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 16 Oct 2001 22:17:20 +0000 (UTC) Subject: FW: [Python-Dev] conditional expressions? References: <23891c90.0110160824.6a5a0c1b@posting.google.com> Message-ID: On Tue, 16 Oct 2001 13:29:09 -0400, Steve Holden wrote: >I particularly shudder for the newbie who must read something like the >following (untested code warning: I'm not building an interpreter that can >handle this stuff, because I'm hoping it will disappear <0.75 wink>): > >l = if a then [i for i in l1 if i % 2] else [i for i in l2 if not i % 2] > >Of course, this might also be cast as: > >l = [i for i in (if a then l1 else l2) if (if a then i % 2 else not i % 2)] > >This may not be the best way to implement such an expression, but if it can >be done then someone will do it. It contrasts quite badly with: > >if a: > l = [i for i in l1 if i % 2] >else: > l = [i for i in l2 if not i % 2] > This proposed if-then-else expression is not in the same league of list comprehension. The last example is a clear improvement to: if a: l = [] for i in l1: if i % 2: l.append(i) else: l = [] for i l2: if not i % 2: l.append(i) In contrast, the example of if-then-else alone would be l = [] for i in (if a then l1 else l2): if (if a then i % 2 else not i % 2): l.append(i) which is not at all clear by itself, and not much an improvement to l = [] if a: ll = l1 else: ll = l2 for i in ll: if a: c = i % 2 else: c = not i % 2 if c: l.append(i) In any case, bundling compoments of a list is usually a better strategy than bundling branches of conditions. Huaiyu From johnroth at ameritech.net Fri Oct 19 13:55:42 2001 From: johnroth at ameritech.net (John Roth) Date: Fri, 19 Oct 2001 10:55:42 -0700 Subject: dynamic call of a function References: <3BCFE666.C8C6136C@c-s.fr> Message-ID: "anthony harel" wrote in message news:3BCFE666.C8C6136C at c-s.fr... > Hi, > > Is it possible to make dynamic call of a function whith python ? > > I have got a string that contains the name of the function I > want to call but I don't want to do something like this : > > if ch == "foo" : > self.foo( ) > elif ch == "bar" > self.bar( ) > .... > > Is it possible to do sommething like that : > ch = "foo" > apply(ch, ( ))??? > > Of course. Put the names and function definitions into a dictionary. Then you can do a dictionary reference to get the actual function to pass to 'apply'. John Roth From emile at fenx.com Thu Oct 18 09:18:31 2001 From: emile at fenx.com (Emile van Sebille) Date: Thu, 18 Oct 2001 06:18:31 -0700 Subject: Random from Dictionary References: <4f7234de.0110180504.20aa475b@posting.google.com> Message-ID: <9qml3o$ovl8k$1@ID-11957.news.dfncis.de> Maybe choice in random helps out. -- Emile van Sebille emile at fenx.com --------- "Tim Payne" wrote in message news:4f7234de.0110180504.20aa475b at posting.google.com... > I've been browsing the message archives for some time looking for an > answer to this question, but I didn't find anything useful. Maybe you > guys could help me out. > > I'm trying to obtain x number of random unique items from a > dictionary. This would have been easy to do with a list, but I need > the dictionary for other parts of the script. > > I've tried popitem(), but arbitrary values just aren't good enough. I > need something that is random. Are there any other functions that I've > missed, or will I have to create my own? If so, any suggestions on a > clean way to do this? I've spent the better part of the morning trying > different ideas, but they were either too slow, or the code was a huge > mess by the time I was done. At one point, my function for random > values was larger than the program itself. > > If you could just point me in the best direction to go, I'll probably > be able to figure out the rest on my own. > > Thanks. From jmiller at stsci.edu Tue Oct 30 16:37:08 2001 From: jmiller at stsci.edu (Jay T Miller) Date: Tue, 30 Oct 2001 16:37:08 -0500 Subject: Proposed mmap module modifications Message-ID: <3BDF1D84.628B58E8@stsci.edu> Hi, I am proposing a set of modifications to the mmap module which serve two purposes: 1. The modifications expose read-only and copy-on-write access on the Win32 platform. Read-write access is already in place. I need copy-on-write. I have no real use for read-only. 2. The modifications provide unified access to the "core" features of memory mapping on both UNIX and Win32. By this I mean that it would be possible to create the 3 principle varieties of mmaps on both using the same platform independent "access" parameter. I propose adding a new optional keyword parameter, "access", which takes on 3 possible values: ACCESS_READ, ACCESS_WRITE, ACCESS_COPY. ACCESS_READ implies that the mapped memory may *only* be read. Any attempt to write to the mapped memory will generate a signal. This signal will be handled in the platform specified manner. ACCESS_WRITE implies that the mapped memory may be read and written. Attempts to write to the mapped memory will be passed through to the underlying file. ACCESS_COPY implies that the mapped memory may be read and written. Attempts to write to the mapped memory result in disassociating the written memory page from the underlying file. A newly associated page in memory is modified to record the effect of the write. The underlying file is not altered. The access values map onto UNIX platform specific parameters as follows: ACCESS_READ: flags=SHARED, prot=PROT_READ ACCESS_WRITE: flags=SHARED, prot=PROT_READ | PROT_WRITE ACCESS_COPY: flags=PRIVATE, prot=PROT_READ | PROT_WRITE I propose making it an error to specify both "access" and "flags" or "prot". In the absence of "access", "prot" and "flags" work like they always did. The access values map onto Win32 mmap internal parameters as follows: ACCESS_READ: CreateFileMapping(...PAGE_READONLY...), MapViewOfFile(...FILE_MAP_READ...) ACCESS_WRITE: CreateFileMapping(...PAGE_READWRITE...), MapViewOfFile(...FILE_MAP_WRITE...) ACCESS_COPY: CreateFileMapping(...PAGE_WRITECOPY...), MapViewOfFile(...FILE_MAP_COPY...) In the absence of "access", the map is effectively ACCESS_WRITE, as it always was. The last issue I want to address is the incompatible naming between existing UNIX and Win32 parameters of mmap, file vs. fileno, and length vs. size. Since the Win32 mmap does not currently use keyword parameters, I propose renaming the Win32 parameters to match the UNIX parameters and changing the documentation. Since these can be specified positionally (as they are now!), this is not really that important, but I'd be happy to clean them up. I have already implemented the modifications against 2.2b1. If they sound OK, I'll submit a patch. Comments? Todd From mlh at idi.ntnu.no Mon Oct 22 11:05:53 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 22 Oct 2001 17:05:53 +0200 Subject: Perl Range operator paradigm References: <3BCC0B8D.F4EFF59C@loria.fr> Message-ID: <9r1ckh$on7$1@tyfon.itea.ntnu.no> "Martien Verbruggen" wrote in message news:slrn9t84tr.cnu.mgjv at martien.heliotrope.home... > On Tue, 16 Oct 2001 12:27:26 +0200, > Laurent Pierron wrote: > > Hello Gurus, [snip] > > while (<>) { > > if (// .. /<\/BODY>/) {print; } > > } > > Sorry to barge in, but that iperator, in this context, isn't the range > operator, but the flip-flop [1]. Without more information, the python > people here probably won't know what to look for. The way the flip-flop > works is that the result of the expression A..B becomes true when A is > true and stays true until B is true, after which the whole cycle can > start again. > [snip] > Martien Verbruggen When I need this sort of thing, I usually implement it explicitly, with a state variable: import sys inside = 0 for line in sys.stdin: if line == '\n': inside = 1 elif line == '\n': inside = 0 if inside: print line, (This will print '' but not '' -- tweak to taste, e.g. with "continue") Another version, using nested loops: from sys import stdin while 1: line = stdin.readline() if line == '\n': while 1: line = stdin.readline() if line == '\n': break print line, elif not line: break A bit more obtuse, perhaps... :) -- Magnus Lie Hetland http://hetland.org From mlh at idi.ntnu.no Tue Oct 2 18:34:12 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 3 Oct 2001 00:34:12 +0200 Subject: XML Marshalling of objects References: Message-ID: <9pdfd4$c0q$1@tyfon.itea.ntnu.no> "Kalle Svensson" wrote in message news:mailman.1002033422.6848.python-list at python.org... > [Peter Neubauer] > > Hello, > > I'm wondering if there is a good way to marshal/unmarshal python objects > > to XML? I'm thinking of some framework like Castor (castor.exolab.org) > > for Java. > > Try googling for "XML pickle python". At least three of the hits on the first > page should be of some interest. [snip] If one wants one's own format, I'm sure rewriting pickle.py t ouse xml should be quite doable. > > Peace, > Kalle > -- > [ Thought control, brought to you by the WIPO! ] > [ http://anti-dmca.org/ http://eurorights.org/ ] > -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From aleax at aleax.it Fri Oct 12 04:53:21 2001 From: aleax at aleax.it (Alex Martelli) Date: Fri, 12 Oct 2001 10:53:21 +0200 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> <7xd73x1cgf.fsf@ruckus.brouhaha.com> Message-ID: <9q6b1t$qlp$1@serv1.iunet.it> "Paul Rubin" wrote in message news:7xd73x1cgf.fsf at ruckus.brouhaha.com... > Gerhard H?ring writes: > > On Mon, Oct 08, 2001 at 07:51:08PM -0700, Paul Rubin wrote: > > > I don't think anything in the standard Python library is GPL'd. > > > (GPL-compatible yes, GPL'd no). > > > > But AFAIK some functionality is only there if you link against GPL'd > > libraries like GMP (for arbitrary length Python longs), readline and > > maybe others I forgot. > > I don't think the gmp module is in the standard distribution. Anyway, It isn't, and neither are my gmpy, and Lemburg's more recent GMP wrapper (whose name I don't recall right now). > GMP itself is LGPL'd, not GPL'd, so you can use GMP in closed programs > as long as you offer the source of the version of GMP you distribute > (but NOT the surrounding program you incorporate it in). Right, but I think a wrapper for a LGPL'd library is a derived work and so must in turn be (at least) LGPL'd (which is why I did that for gmpy). > I'm not sure about Readline. Readline is GPL, http://cnswww.cns.cwru.edu/~chet/readline/rltop.html. On Windows, only, you can get a reasonable subset of Readline's functionality (but not completion) from Alternative Readline, http://newcenturycomputers.net/projects/readline.html, whose license is Python-like (not GPL nor LGPL). Alex From graz at mindless.com Tue Oct 23 12:40:33 2001 From: graz at mindless.com (Graham Ashton) Date: Tue, 23 Oct 2001 16:40:33 GMT Subject: Error Handling Resources References: Message-ID: <54hB7.17988$oN3.1736049@news1.cableinet.net> In article , "Jeff Hinrichs" wrote: > I am relatively new to Python coding and have written some small applets > but now I'm moving on to some bigger projects. I am searching for a > good resource on error handling in Python. Would anyone on the list > care to nudge me in the direction of an URL or book? It just so happens that chapter 5 of David Beazley's excellent "Python Essential Reference", covering flow control and exceptions is available online as a PDF. http://www.newriders.com/chapters/0735710910.pdf Have a read. If you've programmed before it's an excellent book, always the first thing I flick through. It's not really in a tutorial style, but gives you the low down. Exceptions are also covered in Mark Pilgrim's "Dive into Python": http://diveintopython.org/fileinfo_exception.html Another excellent read for the initiated. I take it you've been through the relevant part of the tutorial... http://www.python.org/doc/current/tut/node10.html -- Graham From loewis at informatik.hu-berlin.de Wed Oct 31 05:51:48 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 31 Oct 2001 11:51:48 +0100 Subject: Compiling python error References: <6e761479.0110300640.4c3fdb05@posting.google.com> Message-ID: j.c.mcnulty at open.ac.uk (James) writes: > bash-2.03# ./configure > loading cache ./config.cache > checking MACHDEP... sunos5 > checking for --without-gcc... no > checking for --with-cxx=... no > checking for c++... c++ > checking whether the C++ compiler (c++ ) works... yes > checking whether the C++ compiler (c++ ) is a cross-compiler... yes Is that a proper analysis? Is "c++" indeed a cross compiler? If not, you should investigate why configure thinks it is a cross compiler, by inspecting config.log. If yes: did you intend to build python using cross-compilation for a different system? If yes: you are pretty much on your own. Cross compilation is not really tested; although patches might be accepted. If no: Is your C compiler also a cross compiler? If yes: Since you are not cross-compiling, and since you don't have a native compiler, you are out of luck; get a native compiler. If no: Try configuring --without-cxx. Regards, Martin From info at floconsult.be Tue Oct 16 14:21:17 2001 From: info at floconsult.be (FloConsult SPRL) Date: Tue, 16 Oct 2001 20:21:17 +0200 Subject: Tkinter Canvas.create_line Windows/Linux difference for dashes Message-ID: <3BCC7A9D.AC1F699A@floconsult.be> Running the simple program hereunder: import sys from Tkinter import * win=Tk() can = Canvas(win) can.pack(side=TOP, expand=NO) can.config(height=200, width=200) can.create_line(25,25,175,175,width=8, dash=30) win.mainloop() gives a dashed line under Linux, but a continuous line under Windows (tried on NT, 98 and Me). Can somebody give me an advice on how to obtain the same dashed effect on Windows ? Didn't find anything in tha FAQs. Many thanks in advance, Isabelle. -- /\`. /\`. FloConsult SPRL / \ `. / \ `. http://www.floconsult.be / \ .? / \ .? mailto:info at floconsult.be ?------? ?------? Tel. +32 2 390.07.89 From thomas.heller at ion-tof.com Thu Oct 18 08:56:41 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 18 Oct 2001 14:56:41 +0200 Subject: Function arguments References: <9qm3sb$pc43f$1@ID-59885.news.dfncis.de> <9qmi0b$oab8c$1@ID-11957.news.dfncis.de> Message-ID: <9qmjia$p18as$1@ID-59885.news.dfncis.de> "Emile van Sebille" wrote in message news:9qmi0b$oab8c$1 at ID-11957.news.dfncis.de... > > "Thomas Heller" wrote in message > news:9qm3sb$pc43f$1 at ID-59885.news.dfncis.de... > > Call me weird, but sometimes I need functions taking a number of > > positional arguments, some named arguments with default values, and > > other named arguments as well. > > > > Something like this (which does _not_ work): > > > > def function(*args, defarg1=None, defarg2=0, **kw): > > ... > > > > The usual way to program this is: > > > > [snip keyword arg breakout code] > > > Doesn't look very pretty IMO, and using the dictionaries' > > get method doesn't help. > > Why not? Because it doesn't delete the key from the dict? Exactly - what I want is a 'destructive get method' (Maybe a name other than popitem() would be better). > > > > > I was thinking of a popitem() dictionary method taking > > (optionally) 2 arguments: the name of the item to pop, > > and the default value to return if the item is not present > > in the dictionary: > > > > >>> d = {'a': 2, 'b': 3} > > >>> d.popitem('defarg', 0) > > 0 > > >>> d > > {'a': 2, 'b': 3} > > >>> d.popitem('a', 100) > > 2 > > >>> d > > {'b': 3} > > >>> > > > > Opinions? > > > > Thomas > > You can write this now: > [description of extended popitem snipped] > > As to adding this as a method of dictionary, in 2.2 you can do this as well: > [snip again] > Although I don't see a way to do: > > dictionary = KW > > d = {1:1,2:2} > print d.popitem(3,3) You could do: d = {1:1,2:2} d = KW(d) print d.popitem(3,3) For the solution to my problem, I came up with this which is at least compact: def function(*args, **kw): def _get_defargs(defarg1=None, defarg2=0, **kw): return defarg1, defarg2, kw defarg1, defarg2, kw = _get_defargs(**kw) .... Thomas From paul at fxtech.com Tue Oct 2 09:59:34 2001 From: paul at fxtech.com (Paul Miller) Date: Tue, 02 Oct 2001 08:59:34 -0500 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <1002028115.395.70447.l7@yahoogroups.com> Message-ID: <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> >On Mon, Oct 01, 2001 at 11:04:25AM -0700, Cliff Wells wrote: > > It's free, and you're free not to use it if you don't want your code to be > > free. It's called a trade-off. You get the combined efforts of > thousands of > > GNU programmers to help you solve your problem, and in turn you provide > your > > little bit of help back. > >Nice said, Cliff! If GNU code is FREE, then I'll have to say that Python (and code under BSD-style licenses) is BETTER THAN FREE. Frankly, I'm very grateful to Guido for allowing Python to be used freely in commercial software. -- Paul T. Miller | paul at fxtech.com | http://www.fxtech.com From mark21rowe at yahoo.com Tue Oct 23 00:31:54 2001 From: mark21rowe at yahoo.com (Mark Rowe) Date: Tue, 23 Oct 2001 17:31:54 +1300 Subject: Automatically resume a download w/ urllib? References: Message-ID: <3bd5024a@news.actrix.gen.nz> Hello, After reading some RFC's and tweaking some Apache settings, I managed to get this working. I was only able to test it on my local server and it appears to work fine. Any comments or improvements, feel free :) Mark Rowe import httplib, os, sys def resumeDL(local, remote): """resumeDL(local, remote) - Resumes the download of the file specified in in the form of (, ) into the local file . If the local file is not found, it is created and the download is started.""" existSize = 0 if os.path.exists(local): outputFile = open(local, 'ab') existSize = os.path.getsize(local) else: outputFile = open(local, 'wb') h = httplib.HTTP(remote[0]) h.putrequest('GET', remote[1]) h.putheader('Accept', '*/*') h.putheader('User-Agent', 'PythonHTTPResumer/0.1') h.putheader('Host', remote[0]) if existSize > 0: h.putheader('Range', 'bytes=%d-' % (existSize, )) h.endheaders() errcode, errmsg, headers = h.getreply() print 'Response: %d (%s)' % (errcode, errmsg) if errcode == 416: ## HTTP error 416 = Request Range not Satisiable print 'File already exists and is larger than the remote file' h.getfile().close() del h return f = h.getfile() try: while 1: temp = f.read(8192) ## 8192 == 8kb. Saves 8kb at a time if temp == '': break outputFile.write(temp) sys.stdout.write('.') finally: outputFile.close() f.close() sys.stdout.write('\n') if __name__ == '__main__': resumeDL('sm.tar.gz', ('192.168.1.4', '/sm-cvs-20010519.tar.gz')) "Oleg Broytmann" wrote in message news:mailman.1003669161.6104.python-list at python.org... > On Sun, Oct 21, 2001 at 02:02:52AM +0000, Chris Moffitt wrote: > > I'm trying to develop a small application (mostly for Windows if that > > matters), than can download and install binary files stored on a web server. > > > > I've been able to get urllib to download the file just fine, but what I > > would like to do is be able to resume a download if it is cancelled for > > some reason. In other words, if I've downloaded 50k of a 200k file, I'd > > like to just download the remaining 150k. > > I think it is impossible with urllib. > > > Is this possible using HTTP and Apache? If not, what about FTP? If > > It is possible with Apache (apache supports HTTP Ranges) and httplib, > but you'll need some coding. Learn about HTTP headers, especially Ranges. > It is also possible with FTP and ftplib, but again, you'll need some > coding, and not all FTP servers support download resuming. Learn about ftp > commands. > We'll very much appreciate if you post your working code here. Good luck. > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. > From emile at fenx.com Fri Oct 19 10:21:12 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 19 Oct 2001 07:21:12 -0700 Subject: Traceback oddity Message-ID: <9qpd5f$pcblq$1@ID-11957.news.dfncis.de> I expect you've played with sys.path. Consider, eg: >>> os.__file__ 'f:\\python21\\lib\\os.pyc' >>> sys.path.insert(0,'f:\\Python21\\Lib') >>> reload(os) >>> os.__file__ 'f:\\Python21\\Lib\\os.pyc' >>> Check to see if duplicate versions of the same directory are in sys.path, then back track where they were added. HTH, Emile van Sebille emile at fenx.com --------- ----- Original Message ----- From: "Dale Strickland-Clark" Newsgroups: comp.lang.python Sent: Friday, October 19, 2001 3:51 AM Subject: Traceback oddity > This may not be a Traceback issue at all but somewhere in the depths, > Python's handling of file paths is strangely inconsistent. > > Here's my traceback report (wrapped, unfortunately): > > Traceback (most recent call last): > > File "S:\JOBS\Gibson\Library Manager\librarymanager\cli\lb.py", line > 31, in main > handler.execute() > File "S:\JOBS\Gibson\Library > Manager\librarymanager\cli\lbCLICommand.py", line 52, in execute > func() > File "S:\JOBS\Gibson\Library > Manager\librarymanager\cli\lbCLIStory.py", line 41, in doNew > xmlStory = lbXMLStory.lbXMLStory(self.work, > lbs.lbStory(self.work)) > File "s:\jobs\gibson\library manager\librarymanager\lbStory.py", > line 27, in __init__ > lbdbPubBase.__init__(self, self.work, ID, seq, Parent=Parent) > File "s:\jobs\gibson\library manager\librarymanager\lbdbTable.py", > line 77, in __getattr__ > return self._fields[field] > File "s:\jobs\gibson\library manager\librarymanager\lbdbTable.py", > line 75, in __getattr__ > assert field != '_fields' > > The observant will have noticed that the first few filepaths are in > mixed case whereas the last are all lower case. > > I only noticed because I'm trying to post-process this report. > > Any ideas why? > > Cheers. > -- > Dale Strickland-Clark > Riverhall Systems Ltd From tim.one at home.com Mon Oct 29 15:38:17 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 29 Oct 2001 15:38:17 -0500 Subject: passed extra info to repl function In-Reply-To: Message-ID: [Michael P. Soulier] > I'm using Python's re.sub() function, with the replace part > of the call being a function, to parse a template. The idea is to have > a dictionary of keywords with the corresponding replacement strings, and > then doing one big call of re.sub(), to replace all keywords with their > replacement strings. > ... > Now, replacement_dict is obviously a global in this module. That's the > problem. I need it because I can't pass any extra information to > replace, as it only accepts a match object. Unfortunatly, using a single > global like this prevents the user of this class from instantiating > multiple instances of this object without potentially conflicting with > overlapping use of the global replacement_dict variable. > > I'm using Python 1.5.2, so I can't use nested scopes to get > around this. Luckily, they were never necessary. You *could* abuse default arguments to sneak replacement_dict into the arglist of your replace function, but it's straightforward to use a bound method instead: class Replacer: def __init__(self, dict): self.dict = dict def replace(self, matchobj): key = matchobj.group(1) if self.dict.has_key(key): return self.dict[key] else: return '' import re thisone = Replacer({'a': 'AA', 'c': 'CC'}).replace print re.sub('([abcd])', thisone, 'abcdefg') That prints AACCefg. > I'd like replace to be able to access an instance variable of > self.replacement_dict, so that all replacement dictionaries are > unique to the class instance, but the scoping rules prevent > replace from seeing the self reference. > > Any ideas from the experienced? Use a bound method, as above. Then all instance vrbls are available within the replace function. From paul at ActiveState.com Tue Oct 9 15:36:55 2001 From: paul at ActiveState.com (Paul Prescod) Date: Tue, 09 Oct 2001 12:36:55 -0700 Subject: Fame, Fortune and the Python Conference Message-ID: <3BC351D7.DF81B466@ActiveState.com> Many of you will have submitted papers for the Python conference. Whether you did or didn't, please consider another way to contribute to the conference. You could submit a talks to the Web Services and Protocols track, Zope or Tools tracks. The Web Services and Protocols track is for anyone who is using Python to communicate information between computers in an innovative way. You can get involved with a simple email back to me saying you are interested with a couple of sentences about your area of interest. I will work with you to turn that into an abstract. You do not have to submit a paper or anything else in advance. Just work with me on your abstract and then show up at the conference with a fascinating talk. We already have some well-known speakers signed up so you will be in good company! Here are some areas of interest: * Jabber peer-to-peer protocol * XML-based Web Services protocols (SOAP, XML-RPC) * CORBA Distributed Computing Protocol * Web Services Description Language * Business Integration techniques ("B2B") * Enterprise Application Integration techniques ("EAI") * Proprietary Protocols Just send me a note this week (why not reply right row!) describing your project with Python and protocols or web services and we'll work out whether there is an abstract in there. More info is available here: http://www.python10.org/p10-conferenceEvents.html#webServices Conference info (dates, location,etc.) is here: http://www.python10.org/ Paul Prescod From Krzysztof.Czarnowski at dgt-lab.com.pl Mon Oct 29 11:45:00 2001 From: Krzysztof.Czarnowski at dgt-lab.com.pl (Krzysztof Czarnowski) Date: Mon, 29 Oct 2001 17:45:00 +0100 Subject: Windows/COM events/strange behavior References: Message-ID: <003f01c16099$0d3b08c0$2706a8c0@krzysiek> Sat, 27 Oct 2001 05:42:26 GMT Mark Hammond wrote: > As I said, this main thread probably needs to be calling > PumpWaitingMessages() each time around the loop. Well... This definitely doesn't look very elegant to me! Anyway, if I got it well: 1. I should introduce CoInitialize()/CoUninitialize() pair in the main thread *and* call PumpWaitingMessages() in its loop? Right? I assume that no COM event will be delivered here, or will it? 2. No need to do this in other child threads (like the CORBA thread). Right? 3. Will the problem go away if: * the COM event handler is installed in a "free threaded appartment"? (can I do this in a threading. thread?) or * native Windows threads from ? (now module threading is used) And generally, what would be *your* favorite solution? (my task is basically to receive events from a COM driven subsystem and pass them to a CORBA subsystem) Thank you for the help so far Krzysztof From correia at barebones.com Fri Oct 19 09:17:54 2001 From: correia at barebones.com (Jim Correia) Date: Fri, 19 Oct 2001 13:17:54 GMT Subject: Dictionary from list? References: Message-ID: <6KVz7.132664$vq.30203786@typhoon.ne.mediaone.net> In article , Michael Hudson wrote: > > I'm a python newbie. I know how to do it "by hand" with a loop, but is > > there a built in conversion operater that will let me do something > > simply like the perl assignment? > > No. Write the loop. That's unfortunate - a simple assignment would be better. In the simplest case of my usage, the loop (while ultra short) could be 50% of the code. > I've never found myself needing to do this, but that may be because > I'm not used to having a convenient way of going from > [k1,v1,k2,v2,...] to a dict. The particular situation is the python implementation is going to be a command line script. The calling convention for this script is to pass arguments on the command line in key value pairs. The perl implementation looks like (in the simplest case) my %args = @ARGV; foreach(keys %args) { print("$_: $args{$_}\n"); } And it would be called from the command line as perl myScript.pl name fred age 23 occupation "gravel worker" I'd like to implement the script with the same calling conventions in python, and have an "easy" (typing wise, not conceptually, but I guess I'll have to write a reusable function) way to take the arguments on the command line and turn them into a dictionary. Jim From huaiyu at gauss.almadan.ibm.com Thu Oct 11 17:58:35 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 11 Oct 2001 21:58:35 +0000 (UTC) Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> Message-ID: On Thu, 11 Oct 2001 13:21:57 +1300, Greg Ewing wrote: >I feel the solution to this is *not* to go in for >any sort of assignment-in-expressions hackery, but >to provide a decent loop-and-a-half control structure. A general "loop-and-half" structure is A start loop B if C: break D end loop E Which could be written in the following pattern A while B; C: D E Example 1: > while: > x = get_next() > gives x: > whatever(x) could be written as while x = get_next(); x: whatever(x) Example 2: > What if you want to read until you get to a delimiter? > > while (line := readline()) != 'end': ... could be written as while line = readline(); line != 'end': ... Example 3: for (start; do_other, end; incr) do_something; could be written as start while do_other; not end: do_something incr Likewise, a general nested "if-else-and-a-half" structure is like A if B: C else: D if E: F else: G if H: I else: ... which could be written as if A; B: C elif D; E: F elif G; H: I else: ... The advantage of this syntax pattern is that it is flatter than existing Python syntax, which is a Good Thing . The disadvantage is that it cannot handle additional statement after nested 'else', but the existing 'elif' pattern could not do it, either. Huaiyu From gh_pythonlist at gmx.de Wed Oct 10 09:36:21 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Wed, 10 Oct 2001 15:36:21 +0200 Subject: Python, XML, and databases In-Reply-To: <9q1hir$tji$1@slb3.atl.mindspring.net>; from adina_levin@mindspring.com on Wed, Oct 10, 2001 at 08:07:56AM -0500 References: <9q1hir$tji$1@slb3.atl.mindspring.net> Message-ID: <20011010153621.C1620@lilith.hqd-internal> On Wed, Oct 10, 2001 at 08:07:56AM -0500, adina_levin at mindspring.com wrote: > Is there a Python tool to exchange data between a relational database and > XML? > > I've looked at python.org, searched the archive of this list and xml.com, > looked in the mysql documentation, no luck yet. Pointers welcome, hopefully > I've missed something. I haven't yet seen anything convincing for Python :-( I mean something like Castor for Java, which is a complete solution for XML <-> DB. The only link I have is http://members.home.net/slhath/downloads.html but I haven't tried that yet. It seems to create XML from SQL queries only. You could check out if you can produce what you want with 4Suite (might be possible out of the box, too). It contains libraries for xml, xslt, xpointer, xlink, rdf and an object-realational mapper. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From aa at bb.cc Sat Oct 27 12:01:23 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Sat, 27 Oct 2001 18:01:23 +0200 Subject: Question: Event driven programming Message-ID: <3bdad71d$1_3@corp-goliath.newsgroups.com> Does Python have means for event driven programming? It's a neat feature in VB, I wish there was something similar in Python. Thanks for any pointers. Cheers K?roly ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From com-nospam at ccraig.org Wed Oct 17 08:36:05 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 17 Oct 2001 08:36:05 -0400 Subject: Conditional Expressions don't solve the problem In-Reply-To: References: Message-ID: salemail at dial.pipex.com (Kevin D) writes: > So, to fix those problems a solution must: > > 1) Allow the loop's "load" code to exist just once, preferably > somewhere near the terminating condition. > 2) Have the terminating condition near the "while", and of the right > "polarity". > 3) To be Pythonic, have an obvious meaning. > I personnally don't like your suggestion as they are mind numbingly ugly and remind me of the Algol 60 loops. I wish Python had initially adopted do: until Which is, of course, behaves identically to while 1: if : break but is prettier. But I don't see the increased readability being sufficient to warrant the change. Additionally I think that the present system is not that hard to adapt to. -- Christopher A. Craig From donn at drizzle.com Thu Oct 25 03:15:57 2001 From: donn at drizzle.com (Donn Cave) Date: Thu, 25 Oct 2001 07:15:57 -0000 Subject: Critical sections and mutexes References: Message-ID: <1003994157.730591@yabetcha.sttl.drizzle.com> Quoth David Bolen : | If that's what the newbie wants, they should be pointed to an | appropriate class (like the Queue) that specifically provides simple | producer/consumer behavior with all the appropriate locking hidden | within the class. I don't think suggesting that they just write their | own without such locking (which can lead to believing it isn't | necessary) is to their benefit, even if it makes the problem seem | simpler. | | To my mind, the benefit Python has for newbies is that the typical | housekeeping required of multithreading applications _and_ the types | of synchronization that is a fact of life for such applications are | very simple to use. And a number of useful classes are provided for | common scenarios within multithreaded applications. | | BTW, one of the reasons I feel strongly about this is that a very | large percentage of my applications over the years have been | multithreaded (and I'm a big fan of having the support in the language | such as Python does) and there are just some things you don't skimp | on, if you want to do it write, maintainably and with assured behavior | over time. An anecdote of sorts on that. The BeOS user interface graphics API is inherently multi-threaded. Every window in an application runs in its own thread. BeOS is pretty much dead, sold to Palm if the stockholders ratify it. In a kind of post-mortem mood one of the complaints that has come up, even from ex-Be engineers, is that applications are full of bugs because it's too hard to deal with all these threads safely. No one seems to be willing to say that threads aren't at all useful, though. Anecdote over. The moral of the story seems to be that in C++ (it's a C++ API), you can't easily work safely with threads, so the solution is to limit your use of threads to the strictly essential. OK, that's probably unfair, I imagine the choice of language isn't as important as the commitment to learning how to program with threads, instead of just hoping that you can put threads in your program and it will all work out. But decent language support for that commitment sure helps. Incidentally, ever seen how a multi-threaded asynchronous API looks when you use the Stackless Python continuations feature to turn message queueing inside out? May not apply to all systems, but normally my thread interactions are mediated by message data, used to dispatch functions. After posting a message, the thread handler returns to the dispatcher. With continuations, the thread handler can later return to the point where it posted the message, and "receive" the "function return" message, and the code looks just like calling any ordinary function. Brr, I am normally repelled by magic like that, but it sure makes some multithreaded problems look easy. Donn Cave, donn at drizzle.com From erik at pacific-shores.com Wed Oct 3 12:05:55 2001 From: erik at pacific-shores.com (Erik Myllymaki) Date: Wed, 03 Oct 2001 16:05:55 GMT Subject: win32security question Message-ID: How can I tell if a user's password has expired through python's win32 APIs? -- Erik Myllymaki erik at pacific-shores.com From jhauser at ifm.uni-kiel.de Sun Oct 14 09:42:27 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 14 Oct 2001 15:42:27 +0200 Subject: How to make a copy? References: <3bc9918a_2@news.newsgroups.com> Message-ID: <87elo6fid8.fsf@lisboa.ifm.uni-kiel.de> import copy a=copy.deepcopy(b) HTH, __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From office at tangfeng.org Tue Oct 16 03:45:09 2001 From: office at tangfeng.org (office at tangfeng.org) Date: Tue, 16 Oct 2001 15:45:09 +0800 Subject: Beijing Tangfeng Culture Exchange Centre Message-ID: An HTML attachment was scrubbed... URL: From gmcm at hypernet.com Thu Oct 25 08:23:11 2001 From: gmcm at hypernet.com (Gordon McMillan) Date: 25 Oct 2001 12:23:11 GMT Subject: Solaris core dump with McMillan Installer References: Message-ID: [posted and mailed] Jedi Master Yoda wrote: > I'm trying to package a little application for Solaris using the superb > McMillan Installer. However, though trivial scripts seem to work, any > attempt to import a module results in a bus error and core dump. [snip] > for /usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1 #0 0x17634 in main > (argc=569062, argv=0xffbef8b4, envp=0x84000) at frozen.c:148 > 148 if (toc->typcd == 'b') { > > Is this an installer issue, a zlib issue, a Solaris issue, or user > stupidity? Any help appreciated. First off, argc looks a tad suspicious. Second, to crash there, toc must be pointing to never-never land. Which most likely happened when the toc pointer was incremented, most likely caused by alignment issues (the TOC structures are not aligned at all). I only have easy access to Linux / Windows, both on Intel or Intel-like processors, where alignment is a non-issue. Those TOC structures are written in Python and read in C. I vaguely recall writing some very ugly code to read non-aligned structures on HP-UX - I think I'd prefer to write them aligned. So does anyone know what the worst case alignment rule is for structs? - Gordon From DeepBlue at DeepBlue.org Thu Oct 11 16:44:05 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Thu, 11 Oct 2001 15:44:05 -0500 Subject: Holden's Python Web Programming Book References: <9q46ho.3vv26i7.1@kserver.org> Message-ID: Sheila Mitchell's book is on Amazon.com. Title: Python for the Web. It is not published yet, but a description of the book can be found on Amazon.com. It so happens that Holden's book is announced on Amazon.com but with no description. That is why I got interested in knowing the difference. It looks like Holden's book is more advanced, and I'll end up getting both Holden's and Mitchell's books. DB "Sheila King" wrote in message news:9q46ho.3vv26i7.1 at kserver.org... > On Thu, 11 Oct 2001 08:36:51 -0500, "DeepBlue" > wrote in comp.lang.python in article > : > > :This is a question for Steve Holden: > :Steve, > :Is there a way to view the table of contents of your upcoming book? > :I want to compare this book with Mitchell's book "Python for the Web." > :Thanks, > :DB > > Since we're comparing books, and Steve has put up a URL for his table of > contents, I wonder if you could provide a pointer URL for Mitchell's > book? > > -- > Sheila King > http://www.thinkspot.net/sheila/ > http://www.k12groups.org/ > From chrishbarker at home.net Wed Oct 24 18:35:48 2001 From: chrishbarker at home.net (Chris Barker) Date: Wed, 24 Oct 2001 15:35:48 -0700 Subject: Taking Inputs References: Message-ID: <3BD74244.733C5EF4@home.net> Anita Kommineni wrote: > > For using input and raw_input do I need to import any specific modules no. is something not working that you are expecting to work? -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From mj_dup at yahoo.com Wed Oct 24 17:39:04 2001 From: mj_dup at yahoo.com (Suresh) Date: 24 Oct 2001 14:39:04 -0700 Subject: question on using format in struct module Message-ID: Hi All, I need some help with struct module. I have a binary file (obtained with our product) and it contains char, int, float values. I used struct module for this purpose in this manner -- import struct binfile = open('binary_file.bin','rb') format = ???? bytes = struct.calcsize(format) i1, i2 and so on = struct.unpack(format, binfile.read(bytes)) (i1, i2, i3 etc will have the equivalent text values of the binary fields from the "binary_file.bin") The problem is specifying for "format" variable. Since my binary file has non-uniform and different data types how do I specify for format = ???? Is there a way I can tell python to decide upon format looking at the binary file. Any help is appreciated ! thanks again, ./Suresh From fdrake at acm.org Mon Oct 22 13:24:35 2001 From: fdrake at acm.org (Fred L. Drake) Date: Mon, 22 Oct 2001 13:24:35 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011022172435.28AF528697@cj42289-a.reston1.va.home.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Various updates, including support for the "Site Navigation Bar" in Mozilla 0.9.5. From robin at jessikat.fsnet.co.uk Wed Oct 31 08:07:07 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 31 Oct 2001 13:07:07 +0000 Subject: Python.NET, MONO and Visual Studio etc. References: Message-ID: In article , Oleg Broytmann writes >On Wed, Oct 31, 2001 at 12:03:16PM +0100, Xavier Defrang wrote: >> This is almost off-topic but since you guys are talking about that .NET >> thing, I'd like just to ask anyone in here : WHAT THE HELL IS .NET??? >> >> I don't want any fancy buzzwords or corpspeak crap. I just want a clear, > > Among all the bullshit M$ invented there is one good thing: reusable >components. This is really good. Of course, they will be implemented by >those idiots who implemented Outofluck and IIS bugs. But here they are, >free software components and .NET alternatives. > >Oleg. I would agree with the spirit of reusable components, but a casual inspection of my Win2K machine reveals thousands of OLE/COM type things of which about 1% might be reusable. The main problem is that of the multiplicity of versions of OLE and the almost complete lack of documentation of the various objects. This leads to people cobbling things together using inferred properties of the objects with little real knowledge of the intentions of the designers. I see about 9 different M$ widget sets in my registry. I assume that people have coded for particular sets and now cannot use the upgrade. Reusability hasn't worked especially well in win32. In other systems I believe it has I think the work of N Wirth provides good examples. However, contrast the popularity/ubiquity of win32 with oberon and the conclusion seems clear, nobody really cares any more about efficiency, clarity etc etc. -- Robin Becker From sholden at holdenweb.com Fri Oct 5 14:34:17 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 5 Oct 2001 14:34:17 -0400 Subject: why are *two* ctrl-D's needed with readline() References: Message-ID: "Wilhelm Fitzpatrick" wrote in message news:mailman.1002297908.5879.python-list at python.org... > I was writing a little python script using > > for line in sys.stdin.readlines() : > > to iterate through input, and I noticed that I had to press ctrl-D > TWICE to terminate input. This same behavior appears whether I am in > interactive mode or running a script, and I confirmed the same > behavior using both python 2.0.1 and 1.5.2. > > Interestingly, enough > > for line in sys.stdin.read().splitlines() : > > terminates on the first ctrl-D (as I would expect). > > Why the strange behavior for readlines()? is this an implemenation > limitation? A bug? A feature that I do not properly understand? I > searched the docs and the mailing list archives but I could not find > enlightenment. > Are you pressing the ^D at the end of a line of input, or at the start of a blank line? Technically ^D terminates transmission, and only raises EOF if this results in an empty input buffer, which it does if entered before inputting any characters. Seemed to work as expected on my 2.1.1 cygwin, but 2.0 with Gonnerman's alternative readline 1.4 for some reason doesn't seem to recognise ^D as an input terminator in a readlines() loop, instead echoing chr(4) to the console. In fact, I don't seem to be able to generate an EOF with Gonnerman's code in a DOS command window. Haven't got a Linux system to hand to test. HTH regards Steve -- http://www.holdenweb.com/ From joonas at olen.to Wed Oct 3 08:18:21 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: Wed, 03 Oct 2001 12:18:21 GMT Subject: Mime function in Python References: <3bbafdfe.1022192995@spamkiller.newsfeeds.com> Message-ID: <3BBB028F.E6C03F87@olen.to> Mark Berry wrote: > > Anyone know of an easy way to determine the mime type of a file? > > For example... (my dream method) > > type = dream.get_mime('/tmp/myfile.jpg') > print type > ['image/jpeg'] > > basically something to that effect.. Is there anything in the core > libs that would do something like that or am I going to have to hack > something out? import mimetypes type = mimetypes.guess_type('/tmp/myfile.jpg') print type From sandysj at juno.com Thu Oct 25 14:27:00 2001 From: sandysj at juno.com (Jeff Sandys) Date: Thu, 25 Oct 2001 18:27:00 GMT Subject: print to emacs buffer? Message-ID: <3BD85974.B1A5BA8F@juno.com> Is there an easy way to get a python script to print to an emacs buffer? So when I enter 'python my-script.py' at the unix prompt in an emacs shell the output of the print statements goes to a separate (python-output) buffer instead of the shell buffer. If it helps, I am using emacs 19.34.1 (I don't have a choice about this!) and python-mode 3.105. Thanks, Jeff Sandys From julien.keable at polymtl.ca Mon Oct 22 02:25:32 2001 From: julien.keable at polymtl.ca (Julien Keable) Date: Mon, 22 Oct 2001 02:25:32 -0400 Subject: Controlling execution of embedded python Message-ID: <001d01c15ac2$5ab12a80$0200000a@p2300> Hi, I want to embed python in C++, but i need to control execution in a particular way. The app will use python as a scripting language, and i want it to be able to trace line by line in the python code, tracing *into* functions. How can i do that ? Also, I want to query dynamically value of all local variables. Well, I guess I could call it a debugger... I read the documentation, but cannot find something i'm sure of. -------------- next part -------------- An HTML attachment was scrubbed... URL: From phr-n2001d at nightsong.com Mon Oct 15 16:13:35 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 15 Oct 2001 13:13:35 -0700 Subject: get uniform binary data into array for further processing References: Message-ID: <7x4rp0zmog.fsf@ruckus.brouhaha.com> Also, if it's climate data (i.e. the results of physical measurements), you almost certainly don't need double precision in the initial data file--single precision would cut its size in half. You may want to do the subsequent calculations in double precision, of course. From owen at astrono.junkwashington.emu Wed Oct 31 12:15:38 2001 From: owen at astrono.junkwashington.emu (Russell E. Owen) Date: Wed, 31 Oct 2001 09:15:38 -0800 Subject: Underscore data hiding (was python development practices?) References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: <9rpbk1$19rg$1@nntp6.u.washington.edu> In article , Peter Wang wrote: >On 30 Oct 2001 17:11:28 -0800, Paul Rubin >wrote: > >>Peter Wang writes: >>> while i feel that Python makes me far more productive as a programmer >>> for all the projects on which i've worked, i'm inclined to agree that >>> the lack of data hiding coupled with lack of a standard interface >>> specification would cause problems in a team. >> >>Well, there's cheesy data hiding in the sense that instance variables >>whose names begin with underscores are difficult to reach from other >>modules. > >well... kind of. but short of naming all my private variables "_foo" >and hacking around the problem, there's no way to prevent lazy >programmers from touching all of your classes's data members. i know >this is not python's paradigm, but OTOH this is something that has to >be dealt with in a production environment... This brings up an issue about using underscore to hide data... My understanding is that a double underscore is required for Python to automagically mangle the name. On the other hand, two postings now suggest that a single underscore is sufficient. If double underscore is required, then it seems to me this is a very common misconception that a single is sufficient. It might be worth changing. If double is not required, I'd love to know about it. Single looks a lot neater, and I'm not fond of double punctuation symbols that are hard to read anyway. Personally, I'd like to see the variable mechanism made more explicit and robust, including: - an explicit way to declare class instance variables as hidden - a means of explicitly declaring variables (e.g. a "local" keyword), which implies... - a way to turn on checking for undeclared variables (e.g. a pragma-like mechanism, so it can be applied to modules) - a way to turn off the ability to add new instance variables to class instances (something really simple and obvious, such as a pragma) -- Russell From ignacio at openservices.net Tue Oct 16 16:28:54 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 16 Oct 2001 16:28:54 -0400 (EDT) Subject: Python app. Eroaster and "output = pipe[0].readlines()" trouble In-Reply-To: Message-ID: On Tue, 16 Oct 2001, Kevin wrote: > I'm having a new trouble with a python application called Eroaster. > The error message I get is: > > File "/usr/lib/python2.0/site-packages/gtk.py", line 125, in __call__ > ret = apply(self.func, a) > File "/usr/lib/eroaster/main.py", line 1468, in DetectRecorder > self.DetectSCSIDevice(deviceRecorder) > File "/usr/lib/eroaster/main.py", line 1477, in DetectSCSIDevice > output = pipe[0].readlines() > IOError: [Errno 4] Interrupted system call > > The code around line 1477 in main.py is: > > # Detect SCSI-devices > def DetectSCSIDevice(self, device): > pipe = popen2.popen2("cdrecord -scanbus 2>&1") > output = pipe[0].readlines() > devicelist = [] > > If I execute "cdrecord -scanbus" I get the appropriate output for > my system: > > Cdrecord 1.9 (i586-mandrake-linux-gnu) Copyright (C) 1995-2000 J?rg Schilling > Linux sg driver version: 3.1.19 > Using libscg version 'schily-0.1' > scsibus0: > 0,0,0 0) * > 0,1,0 1) 'IBM-PSG ' 'DPSS-318350N M ' 'S9AA' Disk > 0,2,0 2) 'QUANTUM ' 'ATLAS_V__9_WLS ' '0230' Disk > 0,3,0 3) 'HP ' 'CD-Writer+ 9200 ' '1.0e' Removable CD-ROM > 0,4,0 4) 'NEC ' 'CD-ROM DRIVE:222' '3.1k' Removable CD-ROM > 0,5,0 5) 'HP ' 'HP35470A ' 'T503' Removable Tape > 0,6,0 6) * > 0,7,0 7) * > > This exact application used to run just fine a month or two ago. > Since then I've updated my kernel from 2.4.3 to 2.4.7-12.3mdk on > my Mandrake 8.0 system. I'm sure I've made a few more updates, > like all of Mandrake's security patches. > > > Does anyone know what's going wrong here? Does anyone have any > debugging suggestions? I'm an experienced programmer/debugger > but I'm totally new to python. The problem is most likely the "2>&1" in the call to popen2(). Redirection is a shell function; popen*() just execute the process seperately, so cdrecord thinks that "2>&1" is a (bad) argument. It should use popen4() instead. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From paul at boddie.net Tue Oct 23 08:29:15 2001 From: paul at boddie.net (Paul Boddie) Date: 23 Oct 2001 05:29:15 -0700 Subject: Database Sessions and Transactions References: <23891c90.0110220232.1b0e9139@posting.google.com> Message-ID: <23891c90.0110230429.2a2ac3aa@posting.google.com> "DeepBlue" wrote in message news:... > > Say you have a database component. > Database.StartTransaction 'packages' a transaction. However, I can see now > that we do not need this. The question is: What are the advantages of > StartTransaction on a database connection? I can see that in Python one > issues sql commands to a database and one can 'envelope' them in some form > of a transaction. So instead of asking where is the transaction in Python, > I have turned to think about the use of StartTransaction in > Delphi.............. [continued below] Explicit transaction marking was something that someone was interested in, with respect to the DB-API. As I understand it, with many current DB-API compliant modules (there's always an exception), transactions are typically associated with the opening and closing of connections, along with judicious use of the commit and rollback methods. You can therefore think of opening a connection as implicitly starting a transaction, closing a connection as implicitly rolling back a transaction, and committing and rolling back as doing exactly what they say, but also starting a new transaction implicitly. > But to summarize: when I posted my question I was thinking in Delphi 5 > terms where one can use a Session component or when a session component is > created by default for every database connection. A session manages an > individual database connection. So when many users are using the same > program at the same time, every user is associated with a session to ensure > that multiple connections are kept independent from one another. If sessions are mapped to connections on a one-to-one basis, then perhaps session objects are just wrappers around connections. However, if sessions are just separate "workspaces" which can share a single connection, then I would suspect that some means of "enhanced" transaction handling is in use. It wouldn't surprise me if certain database systems permitted named transactions which operate independently of each other. However, it's a while since I've played with any to be able to say. This could provide the means to share connections in the way you imply, however. > My concern is what happens when many people log into a database through a > Python cgi program (I plan to use DCOracle2), how are these connections > managed so that we can ensure the integerity of independence of different > transactions performed. In Python: is the connection created with every > logon denotes a separate independent session to ensure integrity of data and > transactions? With any "decent" database system, the answer is "yes". Of course, going to more advanced levels and attempting things like connection pooling or sharing, poses many more difficult questions; it would be great to see the Python community tackle these kinds of issues - they're certainly more important than conditional expressions to me, anyway. Paul From garrett at bgb.cc Mon Oct 15 15:23:47 2001 From: garrett at bgb.cc (Don Garrett) Date: Mon, 15 Oct 2001 19:23:47 GMT Subject: Printing in Windows Message-ID: <3BCB37C1.6EF15AEA@bgb.cc> I need to be able to print a complex page involving formatted text, and embedded graphics. I found the win32print, but haven't found much real documentation yet. What is the best option available to me? -- Don Garrett http://www.bgb-consulting.com/garrett/ BGB Consulting dgarrett at acm.org From db3l at fitlinxx.com Thu Oct 25 17:33:20 2001 From: db3l at fitlinxx.com (David Bolen) Date: 25 Oct 2001 17:33:20 -0400 Subject: Critical sections and mutexes References: Message-ID: writes: > So assuming the GIL is replaced by a threadsafe Python core, what will > break in my program with two worker threads appending to the same list? If you're sure it's a built-in list and that the append operation is being serviced by C core code (the built-in part could change today, and with 2.2 even the built-in might be subclassed) then probably nothing, assuming that the list was the only world within which you needed the safety (e.g., there was no correlation between a newly appended entry in the list and any other data structure that needed to be kept in sync). But if either of those conditions might not always be true, then you could potentially run into problems. As I noted earlier in the thread, there are certainly specific cases that can be proposed where there shouldn't be a problem, and I agree that Python pushes the granularity of such cases higher than a language such as C. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From mlerner at umich.deleteme.edu Tue Oct 23 14:21:32 2001 From: mlerner at umich.deleteme.edu (Michael Lerner) Date: Tue, 23 Oct 2001 18:21:32 GMT Subject: None References: <9r4b95$suc$1@news.rchland.ibm.com> Message-ID: I think there's something else going on here .. I just tried it and it worked for me: >>> class boop: ... def __init__(self): ... self.thing1 = "a" ... self.thing2 = "b" ... self.thing3 = "c" ... def output(self,fout): ... print >> fout, self.thing1, self.thing2, self.thing3 ... >>> foo = boop() >>> foo.output(None) a b c >>> dunno if that helps or not .. (of course, if you make silly mistakes like I do, you might accidentally type "none" instead of "None" .. that'll fail with a NameError) -michael Larry Whitley wrote: > I want to have a methode of a class that will take the argument of a file > object that has previously been opened for write and be able to call it, > directing it's output to a file, or directing the output to standard output. > def output(self, fout): > print >>fout, self.thing1, self.thing2, self.thing3 > In the calling program I say: > object.output( fout ) # print to file > object.output( None) # print to standard output > But Python complains that None is a variable that has not been previously > set. Can someone explain? I thought None was the empty object reference. > Where have I gone astray? > Larry From geoffrey at bigpond.net.au Thu Oct 11 05:39:18 2001 From: geoffrey at bigpond.net.au (Geoffrey Pointer) Date: Thu, 11 Oct 2001 09:39:18 GMT Subject: YOU ARE ALL GAY! References: <9q2k92$2vd$1@plutonium.btinternet.com> Message-ID: I realise now how saying too little can sometimes be misconstrued. > It's funny about that isn't it? Go figure. This was a comment about the psychobabble in the original message and not its subject. Now I can see I also made a joke about the subject. Either interpretation is fine by me. I suppose there are others I should now be paranoid about. Again. Go figure. -- Cheers - Geoff %^> From info at devshare.de Thu Oct 25 16:53:36 2001 From: info at devshare.de (Johannes Gamperl) Date: Thu, 25 Oct 2001 22:53:36 +0200 Subject: Learing Python, Newbie question References: Message-ID: In article , sholden at holdenweb.com says... > > > Erm, what's wrong with: > > db_first = not os.path.exists("gbook.txt") # best? > i found this one is a good deal for me :-) what about this: if db_first: db_flag = "w"; else: db_flag = "a"; is there a better way to write this? once again ... i don't want annoy you, i just start to learn python. Mainly i will use it for cgi programming. so the first thing i do is to write a simple guestbook. i was surprised how easy it was ... sorry for my bad english but i'm from germany :-) So long ... Hannes From sholden at holdenweb.com Tue Oct 2 10:52:31 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 2 Oct 2001 10:52:31 -0400 Subject: Python is better than free (was Re: GNU wars again) References: Message-ID: "Paul Miller" wrote in message news:mailman.1002031212.31017.python-list at python.org... > > >On Mon, Oct 01, 2001 at 11:04:25AM -0700, Cliff Wells wrote: > > > It's free, and you're free not to use it if you don't want your code to be > > > free. It's called a trade-off. You get the combined efforts of > > thousands of > > > GNU programmers to help you solve your problem, and in turn you provide > > your > > > little bit of help back. > > > >Nice said, Cliff! > > If GNU code is FREE, then I'll have to say that Python (and code under > BSD-style licenses) is BETTER THAN FREE. Frankly, I'm very grateful to > Guido for allowing Python to be used freely in commercial software. > Interestingly the current Python license is GNU-compatible, which means that Python can be safely used as a component in GPL'd systems. But that doesn't mean that Python is only availabel under the GPL -- simply that if you distribute Python as a component of your GPL'd system then anyone who distributes a derived system must also make their (possibly-modified) source available. Viral? Not to the extent you (and Microsoft) appear to believe. regards Steve -- http://www.holdenweb.com/ From phr-n2001d at nightsong.com Wed Oct 31 19:16:50 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 31 Oct 2001 16:16:50 -0800 Subject: Underscore data hiding (was python development practices?) References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> <9rpbk1$19rg$1@nntp6.u.washington.edu> <9rq2v2$fko$1@newshost.accu.uu.nl> Message-ID: <7xlmhrs5u5.fsf@ruckus.brouhaha.com> m.faassen at vet.uu.nl (Martijn Faassen) writes: > Data hiding isn't there to prevent evil programmers from doing evil > things anyway; it's there to communicate intent and to prevent people > from tripping over problems. That's true a lot of the time, but it's not universally true. In java for example, data hiding is definitely intended to thwart evil programmers, and any failure of the data hiding is considered a security bug requiring an immediate patch. The closest Python has to that is the rexec mechanism. I'd like it a lot if Python extended such protection to private instance variables. From gustafl at algonet.se Mon Oct 15 08:47:37 2001 From: gustafl at algonet.se (Gustaf Liljegren) Date: Mon, 15 Oct 2001 14:47:37 +0200 Subject: Regex problem Message-ID: <9qelne$jcg$1@green.tninet.se> I'm having a problem with a regex. I'm trying to match or elements containing the 'href' attribute. Here's the regex: >>> import re >>> re_link = re.compile(r'<(a|area)\s+[^>]*href[^>]*/?>', re.I | re.M) It works fine when I try it on these two strings: >>> s1 = '' >>> re.match(re_link, s1).group() '' >>> s2 = '' >>> re.match(re_link, s2).group() '' But look what happens as soon as I add a space (or any other character) before: >>> s3 = ' ' >>> re.match(re_link, s3).group() Traceback (most recent call last): File "", line 1, in ? re.match(re_link, s3).group() AttributeError: 'None' object has no attribute 'group' >>> What's wrong here? Matches shouldn't have to start from the beginning of a string. Gustaf Liljegreb From mikael at isy.liu.se Fri Oct 19 06:54:50 2001 From: mikael at isy.liu.se (Mikael Olofsson) Date: Fri, 19 Oct 2001 12:54:50 +0200 (MET DST) Subject: Curious assignment behaviour In-Reply-To: Message-ID: On 19-Oct-2001 Nomad wrote: > I'm probably over my head (and more than likely rambling as well), but > in "let x = y" doesn't the 'let' denote that the value of 'x' will be > changed? >From a programming point of view, I certainly agree. From a mathematical point of view, "let x=y", only means that x and y are equal, most often regardless of what you have said about x and y before. If I write mathematical texts, and wish to communicate assignment, I either say "set x=y" (mostly in an algorithm) or use an = with a triangle above, as I described in an earlier post. Set-let-to-set-and-all-will-be-set-ly y'rs /Mikael ----------------------------------------------------------------------- E-Mail: Mikael Olofsson WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 Date: 19-Oct-2001 Time: 12:46:14 /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ This message was sent by XF-Mail. ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From dfeustel at mindspring.com Sat Oct 6 11:21:33 2001 From: dfeustel at mindspring.com (David Feustel) Date: Sat, 06 Oct 2001 15:21:33 GMT Subject: Octonians in Python References: Message-ID: <1kFv7.36296$My2.18330031@news1.mntp1.il.home.com> Failure to find an instance does not imply that such an instance does not exist, although many such failures should probably give one pause. "Sean 'Shaleh' Perry" wrote in message news:mailman.1002379146.4202.python-list at python.org... > > On 06-Oct-2001 David Feustel wrote: > > There is one additional system of complex numbers > > (octonians) beyond quaternions. Are there any > > python implementations of octonians? > > > > perhaps you are new to the net and have not heard of www.google.com. Go there > and give it a peak. You could have found the answer to both of your questions > in moments. > From logiplexsoftware at earthlink.net Thu Oct 11 13:15:55 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 11 Oct 2001 10:15:55 -0700 Subject: get uniform binary data into array for further processing In-Reply-To: <11245.1002788892@www29.gmx.net> References: <11245.1002788892@www29.gmx.net> Message-ID: <01101110155502.05600@logiplex1.logiplex.net> On Thursday 11 October 2001 01:28, chr_w at gmx.de wrote: > I have to import pretty massive binary files containing double-precision > real values (climate data) so I can do some operations to it (mainly > simplyfying, getting the daily some etc.). The file can get really ugly in > size... up to a gig eventually... > > But my main concern: > a) what's the best and fasted way to get this data into a 2-dimensional > array (or list?)? Maybe if you posted a small portion of the data, something could be suggested (please, not a gig). -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From chris.gonnerman at newcenturycomputers.net Wed Oct 17 12:52:40 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Wed, 17 Oct 2001 11:52:40 -0500 Subject: string.digits, string.letters? How? References: <3BCDCC6F.16954B08@starhub.net.sg> Message-ID: <004301c1572c$27a9c6e0$0101010a@local> ----- Original Message ----- From: "Paul Lim" > Hi again to all, > > I am a newbie in Python and please really pardon me for my trivial > question. > > How can we use the digits, letters variable in the string modules? > > I have the following snippet of my code > > # Import library modules > # ====================== > > import sys > from string import lower, find, atoi, digits, letters > > if digits(sys.argv[i+1]): > print "Invalid argument" > > but i get the error message > File "test.py", line 32, in ? > if digits(sys.argv[i+1]): > TypeError: object is not callable: '0123456789' > > What is wrong? Your thinking is very muddy. 'digits' is in fact a string variable, not a callable, so you can't use the (...) form after it (as you can plainly see). The variable 'i' isn't set in your code, either, so if digits were a function (or other callable) you'd still have an error. Please try telling us what precisely you are trying to do? > Thank you very much. You're welcome, for whatever my answer is worth. From ngps at madcap.dyndns.org Sat Oct 27 11:13:51 2001 From: ngps at madcap.dyndns.org (Ng Pheng Siong) Date: 27 Oct 2001 15:13:51 GMT Subject: urllib.urlopen + https = all threads locked? References: Message-ID: <9reivf$f2d$1@coco.singnet.com.sg> According to Jeff Johnson : > I have a multi-threaded application that makes calls > urllib.urlopen("https://yadayada.com"). Until the call completes (or > maybe the following read) all other threads just freeze. They > continue working after the call completes so it took me a while to > realize there was a problem. > > Someone suggested: > > "Sounds like the C code that does the SSL is not _releasing_ > the global thread lock." Yup, sounds like it. Try M2Crypto, it does threading. (Just don't do the info_callback thingy for now. ;-) M2Crypto also does SSL session re-use. Here's a demo that I posted a little while ago. For serious usage you should replace the single 'GET ??? HTTP/1.0' line with calls to either http[s]lib or urllib. """M2Crypto.SSL.Session client demo: This program requests a URL from a HTTPS server, saves the negotiated SSL session id, parses the HTML returned by the server, then requests each HREF in a separate thread using the saved SSL session id. Copyright (c) 1999-2000 Ng Pheng Siong. All rights reserved.""" RCS_id='$Id: sess.py,v 1.2 2000/09/11 14:52:29 ngps Exp ngps $' from M2Crypto import Err, Rand, SSL, X509, threading m2_threading = threading; del threading import formatter, getopt, htmllib, sys from threading import Thread from socket import gethostname def handler(sslctx, host, port, href, recurs=0, sslsess=None): s = SSL.Connection(sslctx) if sslsess: s.set_session(sslsess) s.connect((host, port)) else: s.connect((host, port)) sslsess = s.get_session() #print sslsess.as_text() if recurs: p = htmllib.HTMLParser(formatter.NullFormatter()) f = s.makefile("rw") f.write(href) f.flush() while 1: data = f.read() if not data: break if recurs: p.feed(data) if recurs: p.close() f.close() if recurs: for a in p.anchorlist: req = 'GET %s HTTP/1.0\r\n\r\n' % a thr = Thread(target=handler, args=(sslctx, host, port, req, recurs-1, sslsess)) print "Thread =", thr.getName() thr.start() if __name__ == '__main__': m2_threading.init() Rand.load_file('../randpool.dat', -1) host = '127.0.0.1' port = 443 req = '/' optlist, optarg = getopt.getopt(sys.argv[1:], 'h:p:r:') for opt in optlist: if '-h' in opt: host = opt[1] elif '-p' in opt: port = int(opt[1]) elif '-r' in opt: req = opt[1] ctx = SSL.Context('sslv3') ctx.load_cert('client.pem') ctx.load_verify_info('ca.pem') ctx.load_client_ca('ca.pem') ctx.set_verify(SSL.verify_none, 10) req = 'GET %s HTTP/1.0\r\n\r\n' % req start = Thread(target=handler, args=(ctx, host, port, req, 1)) print "Thread =", start.getName() start.start() start.join() m2_threading.cleanup() Rand.save_file('../randpool.dat') -- Ng Pheng Siong * http://www.post1.com/home/ngps From johann at physics.berkeley.edu Sat Oct 6 16:05:19 2001 From: johann at physics.berkeley.edu (Johann Hibschman) Date: 06 Oct 2001 13:05:19 -0700 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> <3BBE6A57.FD354FE3@alcyone.com> <7xlmipcji1.fsf@ruckus.brouhaha.com> <3BBEB99A.A1F0F9D7@alcyone.com> <3BBF5C59.33605BD@alcyone.com> Message-ID: >>>>> "Erik" == Erik Max Francis writes: Erik> That's perfectly valid, but I don't think it's what the Erik> poster I responded to meant. He meant encoding the Erik> transform represented by the quarternion into a matrix. But Pauli spin matrices are matrices! But I get the point that you're thinking of real matrices. It doesn't mean that NumPy doesn't make this easy. You could do something like: import Numeric class Quat: def __init__(self, matrix): self.matrix = matrix # Extracting components (Is this right?) def c0(self): m = self.matrix return (m[0][0]+m[1][1])/2.0 def c1(self): m = self.matrix return (m[0][1]+m[1][0])/2.0 def c2(self): m = self.matrix return 1.0j*(m[0][1]-m[1][0])/2.0 def c3(self): m = self.matrix return (m[0][0]-m[1][1])/2.0 # Math def __mul__(self, other): if hasattr(other, 'matrix'): return Quat(Numeric.matrixmultiply(self.matrix, other.matrix)) else: return Quat(self.matrix * other) def __rmul__(self, other): return Quat(other * self.matrix) def __add__(self, other): if hasattr(other, 'matrix'): return Quat(self.matrix + other.matrix) else: return Quat(self.matrix + other) def __radd__(self, other): return Quat(other + self.matrix) def __sub__(self, other): if hasattr(other, 'matrix'): return Quat(self.matrix - other.matrix) else: return Quat(self.matrix - other) def __rsub__(self, other): return Quat(other - self.matrix) # Basis s0 = Quat(Numeric.array([[1.0, 0.0], [0.0, 1.0]])) s1 = Quat(Numeric.array([[0.0, 1.0], [1.0, 0.0]])) s2 = Quat(Numeric.array([[0.0, -1.0j], [1.0j, 0.0]])) s3 = Quat(Numeric.array([[1.0, 0.0], [0.0, -1.0]])) # Create from components. def q(i, j, k, l): "Create a quaternion from components." return s0*i+s1*j+s2*k+s3*l From phr-n2001d at nightsong.com Mon Oct 15 02:32:19 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 14 Oct 2001 23:32:19 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: <7xk7xx1ki4.fsf@ruckus.brouhaha.com> "Chris Tavares" writes: > Question - what happens with: > > x = (if e1 then e2 else e3,) # <--- note trailing comma > > Should be a 1 element tuple, yes? What happens? Or would you have to write: > > x = ((if e1 then e2 else e3),) > > That's just ugly. I think you could write x = (if e1 then e2 else e3), From mwh at python.net Tue Oct 23 06:31:45 2001 From: mwh at python.net (Michael Hudson) Date: Tue, 23 Oct 2001 10:31:45 GMT Subject: Few questions about new features in Python 2.2 References: <7da8d8f8.0110230006.36933486@posting.google.com> Message-ID: s.keim at laposte.net (sebastien) writes: > Why iterators can't be copied? Think about >>> i = iter(sys.stdin) >>> j = iter(i) when sys.stdin is attached to a pipe. or iter(iter(g())) for some generator g. It just ain't possible in general. Cheers, M. -- And then the character-only displays went away (leading to increasingly silly graphical effects and finally to ads on web pages). -- John W. Baxter, comp.lang.python From db3l at fitlinxx.com Tue Oct 9 11:24:09 2001 From: db3l at fitlinxx.com (David Bolen) Date: 09 Oct 2001 11:24:09 -0400 Subject: Pipes References: Message-ID: Dale Strickland-Clark writes: > David Bolen wrote: > > > > >For interprocess I normally go ahead and use the popen# functions. > >For inter-machine I'm much more likely to use an IP approach with > >sockets (I've done named pipes in pure Windows applications that > >weren't written in Python but not in Python to this point). > > > > Popen pipes are not the sort I was after. I need to communicate > between processes - maybe on separate machines - asynchronously. Popen > pipes are the synchronous stdout/stdin type of pipes. You can certainly communicate asynchronously over popen pipes (that's one of the most useful differences over something like os.system) at least as far as I'd consider asynchronous with respect to the ongoing operation of the application. Although perhaps you mean non-blocking, which isn't the case if you fill up the pipe's buffer in a given direction. But yes, to use pipes in a more complicated fashion would probably require that you resort to OS-dependent methods. On the Windows side, that would be opening the pipes directly and using overlapped I/O. On the Unix side, setting non-blocking and select would probably be fine. On Windows, a named pipe connection (the server would have to be NT/2K) would also work fine (locally on NT/2K, even anonymous pipes are just named pipes given automatic names) for both local and inter-machine. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From lucio at movilogic.com Mon Oct 22 18:49:45 2001 From: lucio at movilogic.com (Lucio Torre) Date: Mon, 22 Oct 2001 19:49:45 -0300 Subject: Mixing asyncore with threads In-Reply-To: Message-ID: <5.1.0.14.0.20011022194454.088bc810@imap.hq.movilogic.com> At 10:39 PM 22/10/2001 +0000, Thomas Jensen wrote: >Hi, > >Is it possible/advisible to mix asyncore (or modules using it) with >threads ? > >More specifically, I'd like to build a HTTP based server, which will >serve, more or less, IO bound content most of the time (served directly >from memory/disk/DB). For this asyncore seems ideal. >However, in some circumstances the content will be quite CPU intensive >(like dynamically generated PNGs from a large dataset, etc.). In this >case a thread would be nice, to prevent blocking other trafic while >calculating. >The problem is, that select() will block until it sees trafic on a >readable or writeable port (AFAIK). select does not necesarily blocks. the select bit goes like this: (from some of my code) readable, writable, exceptional = select.select([conn.fd], [], [], 0.2) if len(readable) > 0 : tmp = readable[0].recv(1024*8) # log byte count conn.read_b += len(tmp) conn.out_buff += tmp if tmp != "": conn.read_time = time.clock() 0.2 being the timeout for select. if you use 0, it will just never block. >So far I've come up with the following solutions: >(1) Wraping asyncore.poll() in a loop with a small timeout value. >(2) Use a "dummy" port on the loopback interface for triggering >select() once output from the thread is finished. > >Of the two, I like (2) best, but I keep getting the feeling that there >must be a better way ? > >Perhaps I should just settle on either asyncore or threads ? cant help you with asyncore or threads, but i know you can use select for this. Lucio >-- >Best Regards >Thomas Jensen >-- >http://mail.python.org/mailman/listinfo/python-list From bbrox at bbrox.org Tue Oct 30 15:04:31 2001 From: bbrox at bbrox.org (Lionel Ulmer) Date: Tue, 30 Oct 2001 20:04:31 +0000 (UTC) Subject: Is there any Python 'binding' for GDB ? Message-ID: Hi all, I was just wondering if such a beast exists somewhere... If you are wondering what I mean by 'GDB bindings', it would be to 'drive' GDB via Python. For example, opening an executable file, setting breakpoints, running it, stopping it, getting the type of a variable, getting / modifying a variable, ... I think such a tool would be very valuable, especially to do automated unit testing of C routines (instead of putting printfs everywhere, do it via a Python script). Lionel -- Lionel Ulmer - http://www.bbrox.org/ From tjreedy at home.com Fri Oct 5 21:26:34 2001 From: tjreedy at home.com (Terry Reedy) Date: Sat, 06 Oct 2001 01:26:34 GMT Subject: Generating a random number References: <9plkkk$98r$1@ins22.netins.net> Message-ID: "Ron White" wrote in message news:9plkkk$98r$1 at ins22.netins.net... > Will someone please tell me exactly how to generate a random number from 1 > to 10 in Python 2.1.1 running under windows me? I'm beginning to think > there is something wrong with my installation or I'm just not smart enough > to understand what I read. Look at the 'random' module. If something specific does not seem to work, make a specific report and ask a specific question. Terry J. Reedy From info at pythonware.com Mon Oct 22 09:39:17 2001 From: info at pythonware.com (PythonWare) Date: Mon, 22 Oct 2001 15:39:17 +0200 Subject: ANNOUNCEMENT: The PythonWare PY22 distribution (preview, october 22, 2001) Message-ID: <01a801c15afe$f3a8bf00$0900a8c0@spiff> for bleeding edge users: The PythonWare PY22 distribution is a small and self-contained Python distribution for Windows. This kit includes Python 2.2b1, Tkinter/Tk 8.3.3, PIL 1.1.2, and other useful extensions. Get your copy from: http://www.pythonware.com/products/python/preview.htm Note that this is an unsupported preview version. Commercial support for PythonWare kits is available to PythonWorks customers. For more information, contact us at info at pythonware.com enjoy, the pythonworks team "Secret Labs -- makers of fine pythonware since 1997." From dale at riverhall.NOSPAMco.uk Tue Oct 2 08:01:59 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Tue, 02 Oct 2001 13:01:59 +0100 Subject: Strategies for controling attribute assignment Message-ID: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> A 'properly' encapsulated business class tends to involve methods and attributes. However, managing attribute assignment gets very messy with __setattr__ as you need to devise a scheme to distinguish class attributes and working instance variables. Often, externally visible class attributes need to be validated and instance variables don't. Or they may get stored elsewhere. What strategies have people come up with to manage this distinction without bogging the code down in excessive checks. I would really like a way to distinguish between these two without having to check dictionaries. Thanks. -- Dale Strickland-Clark Riverhall Systems Ltd From achim.domma at syynx.de Tue Oct 16 07:34:58 2001 From: achim.domma at syynx.de (Achim Domma) Date: Tue, 16 Oct 2001 13:34:58 +0200 Subject: Building a lib-wrapper, first step References: <3BCC198D.5010505@strakt.com> Message-ID: <9qjh98$5hk$06$1@news.t-online.com> Hi, in what language is your lib written ? Perhaps www.boost.org could help you. greetings Achim "Rikard Bosnjakovic" wrote in message news:3BCC198D.5010505 at strakt.com... > I've got a small library (Linux) and I want to create some > wrapper-module so Python can use it. I've never done this before, so I'm > looking for some tutorial or such for this purpose. > > Is there any documents describing this somewhere, step-by-step or something? > > > Cheers, > ------------------------------------------------------------------------ > Rikard Bosnjakovic bos at hack.org (private) > Python Hacker rikard at strakt.com (work) > AB Strakt http://bos.hack.org/cv/ > From mcfletch at home.com Thu Oct 18 13:56:36 2001 From: mcfletch at home.com (Mike C. Fletcher) Date: Thu, 18 Oct 2001 13:56:36 -0400 Subject: Python and 3D Graphic tools In-Reply-To: <3bcece7f.18432984@news.easynews.net> Message-ID: <001501c157fe$3ba91150$1802a8c0@Rose> You could try OpenGLContext + PyOpenGL. There are classes in OpenGLContext that let you load (arbitrary) array-based geometry (similar in complexity to what you see in a VRML IndexedFaceSet). There's no code to deal with the stacking/interference/locking, but presenting the geometry would certainly work. There's basic code to setting up callbacks for each block/object (so you can tell the game where you want to stack your block). Another option would be to use PyGame and 2D tiles/bitmaps. You'd still have to write the same interference/interaction logic, but the graphics would be fairly straightforward. Either approach should work. Good luck, Mike -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Marcus Stojek Sent: October 18, 2001 8:52 AM To: python-list at python.org Subject: Python and 3D Graphic tools Hi, I want to write a little tools to visualize a kind of 3D puzzle. (The single pieces are more or less cubes with or without holes and pins) As I don't want to spend very much time on this I am looking for an appropriate programming tool. VPython looked good, but it has only the basic volumes, like cubes and spheres. VTK might be a little difficult and I don't fully understand how to use it with Python. Is there anything between these two? Or a VTK add-on thing I could use? I want to define relatively simple bodys, show them in 3D, and pile them interactively. (No animation, just add or remove from the scene) Thanks in advance. Marcus -- http://mail.python.org/mailman/listinfo/python-list From tjreedy at home.com Wed Oct 3 19:04:51 2001 From: tjreedy at home.com (Terry Reedy) Date: Wed, 03 Oct 2001 23:04:51 GMT Subject: Optional type declaration? References: <3BBB82DE.9080607@verio.net> Message-ID: "VanL" wrote in message news:3BBB82DE.9080607 at verio.net... > Hello, > > Does anyone know whether optional type declaration has been considered > for python? This has been discussed by various people in the newsgroup for several years (see archives at groups.google.com). I believe there is or was a TypesSIG (see python.org ) > An optional type declaration system for python could be implemented that > would use either a specially formatted portion of the docstring or a new > keyword that could specify type at compile time. Anyone is free to experiment with a system that only depends on doc strings. I believe that there have been a few experiments, but nothing that has swept the community. [fair summary of much of what has been said before snipped] Terry J. Reedy From drew_csillag at geocities.com Tue Oct 2 14:04:54 2001 From: drew_csillag at geocities.com (Drew Csillag) Date: Tue, 2 Oct 2001 14:04:54 -0400 Subject: [ANN] SkunkWeb 3.1 beta 3 Message-ID: <20011002140454.R4451@starmedia.net> Release 3.1 Beta 3 of The SkunkWeb Web Application Server has just been released. The release is available from the SkunkWeb home page at http://skunkweb.sourceforge.net or directly from http://prdownloads.sourceforge.net/skunkweb/skunkweb-3.1beta3.tgz What's new? (from 3.0) ------------------------------ * Major performance tweaks. Should now be about 30% faster overall. * Now supports FastCGI * PyDO improvements (mainly PostgreSQL related) * new service - userdir - which makes it so that requests to /~user/foo will go to /public_html/foo * print statements in <:call:> tags now work. * <:call:> tag now handles multiline expr argument properly. Now you can do things like: <:call `def foo(x): return 'the value is %s' % x print foo(3)`:> * PostgreSQL fixes * UNIX domain socket fixes * PyDO classes can now be defined in non-modules * Now can have a template that gets executed for directories that don't have an index document. Very best wishes to all, -Drew -- print(lambda(m,d,y):['Sun','Mon','Tues','Wednes','Thurs','Fri','Satur' ][(lambda(m,d,y):(23*m/9+d+4+y/4-y/100+y/400)%7)(m<3and(m,d+y,y-1)or( m,d+(y-2),y))])(map(int,raw_input('mm/dd/yyyy>').split('/')))+'day' From ylee12 at uiuc.edu Fri Oct 26 15:17:34 2001 From: ylee12 at uiuc.edu (Young-Jin Lee) Date: Fri, 26 Oct 2001 14:17:34 -0500 Subject: [Q] sys.path Message-ID: Hi, I'm a newcomer in Python and I have a simple question on sys.path. When I use IDLE, I think I should add my working directory into sys.path or anything equivalent. But I don't find any menu in the IDLE. How can I do this? Thanks. Young-Jin Lee From logiplexsoftware at earthlink.net Tue Oct 9 13:43:05 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 9 Oct 2001 10:43:05 -0700 Subject: Why so few Python jobs? (and licenses) In-Reply-To: <7x1ykd7es3.fsf@ruckus.brouhaha.com> References: <7x1ykd7es3.fsf@ruckus.brouhaha.com> Message-ID: <01100910430500.02876@logiplex1.logiplex.net> On Monday 08 October 2001 19:01, Paul Rubin wrote: > It can be even stickier unless the GPL'd library supplier is > completely the sole developer and didn't accept any patches from > anyone without getting signed documents from the submitter assigning > outright ownership of the patches including for non-GPL'd use. (And > some people who have signed such assignments in the past without > realizing what they were getting into are now pissed about it). If I > submit a patch to a GPL'd program, it's with the understanding that > the patch is GPL'd, unless I agree otherwise. If the patch is > accepted and patched program later gets distributed under a non-GPL, > I'd feel I had a claim against both the developer and his customer. I have to admit I hadn't thought of that.... :( Still, to be honest, I consider GPL'd/open source stuff to be a matter of goodwill, and if I submitted a patch to a GPL'd author that means that I am obviously using his code to a significant degree and the patch is just my small thanks for that. If the author later profits from that it's all the better, as far as I'm concerned, as this will undoubtedly encourage him/her to develop more code (and maybe even let him eat, if he needs to). People who resent that sort of thing are perhaps missing the larger picture. Most (admittedly not all - large projects like Linux being an exception) GPL'd projects 90% the result of one or two people's efforts with small improvements and fixes being submitted by others (who, as I said earlier, are already benefitting from the existence of that project - probably more than enough to compensate for their small contribution). I suppose those same people resent the FSF selling copies of GPL'd books. I think licensing GPL'd code is a good idea if it helps support the efforts of open source programmers. Getting paid to develop open source is the best of both worlds and benefits everyone. > People who want to develop closed-source products and charge for them > ought to be willing to pay for the libraries and tools they use > anyway. Very true, I was thinking more along the lines of _who_ you choose to give your money to. Since I use open source/GPL stuff all the time, if I can justify giving them money, that's what I prefer to do. That's why I buy the RedHat CD's rather than just downloading them. Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From michael at rcp.co.uk Fri Oct 26 02:49:10 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Fri, 26 Oct 2001 06:49:10 +0000 (UTC) Subject: Learing Python, Newbie question References: <40d4f326-da3d-493a-8b28-9c3d0223feb4@zigzag.magnetic-ink.dk> Message-ID: Klaus Alexander Seistrup wrote in news:40d4f326-da3d-493a-8b28-9c3d0223feb4 at zigzag.magnetic-ink.dk: > Johannes Gamperl wrote: > > The "a ? b : c" that we know from C can be emulated in Python by > > ((a and [b]) or [c])[0] Pretty, isn't it :( From pzw1 Wed Oct 31 18:48:20 2001 From: pzw1 (Peter Wang) Date: Wed, 31 Oct 2001 18:48:20 -0500 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> <9ro2am$p5b$1@bcarh8ab.ca.nortel.com> Message-ID: On 31 Oct 2001 16:24:14 -0500, David Bolen wrote: >Peter Wang writes: > >> one doesn't have to be a rogue programmer to be enticed. time >> pressures, schedule pressures, etc. can all force a good programmer to >> become one of the fallen. if all the variables are hanging out, with >> no enforced privacy, it's much much easier/more tempting to start >> using them inappropriately in the code. especially if it's just to >> get one quick feature in there for the demo, etc. does this happen to >> other people, or is it just me?? :-) > >One question that hasn't been raised in this thread is whether or not >this behavior can actually be beneficial too? no doubt, the development "quickness" and the flexibility of python, coupled with excellent introspection, are its strong points. >So in some respects, being able to bypass a published interface when >necessary can be considered a positive and doesn't have to be a >negative. yes - one can't make sweeping generalizations about the pros or cons of breaking a published interface; it all depends on context. however, certain sorts of behavior will be more likely to end up biting you in the ass, and mucking around with the "private" data of a class is surely one of them. even if one has to hack something together for a demo, i'd rather have things in the code which scream out, "touch this and all bets are off; hack something else!" in some sense, the "private", "public", and "protected" labels signal this and much more. hm... maybe i'm being too much of a Murphyist. :) >Or perhaps one of the reasons is that by and large those who have done >larger developments with Python haven't missed not having the safety >net, in which case the theoretical loss of protection being discussed >just hasn't turned into a major problem in practice. yes, that is a distinct possibility and one that i'm willing to entertain. on a purely personal level, i find myself much more productive and my code surprisingly less buggy when i use python. being able to code the algorithms is a big plus. :) >/-----------------------------------------------------------------------\ > \ David Bolen \ E-mail: db3l at fitlinxx.com / > | FitLinxx, Inc. \ Phone: (203) 708-5192 | > / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ >\-----------------------------------------------------------------------/ cool, you work at fitlinxx! my girlfriend Co-op'ed there a year ago. do you remember a Crystal Soja? i recall her mentioning that there was an effort to use python there - i take it you were part of that? -peter From sholden at holdenweb.com Mon Oct 29 07:07:10 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 07:07:10 -0500 Subject: Multiple postings Message-ID: Sorry about the recent spate of duplicated postings. A glitch in my mail server meant that it was accepting postings without telling my news client they had been taken. regards Steve -- http://www.holdenweb.com/ From ylee12 at uiuc.edu Wed Oct 17 13:36:50 2001 From: ylee12 at uiuc.edu (Young-Jin Lee) Date: Wed, 17 Oct 2001 12:36:50 -0500 Subject: [Q] Python and machine learning Message-ID: Hi, I'd like to know if there's a python package for machine learning (decision tree, neural net, and others). Thanks in advance. YJ From printers at sendme.cz Mon Oct 8 04:54:22 2001 From: printers at sendme.cz (A) Date: Mon, 8 Oct 2001 10:54:22 +0200 Subject: DNS module or how to ... ? Message-ID: <3BC185DE.30945.6E5441@localhost> Hello, Is there a DNS module available for Python ? Or is there a method how I can , from my python program, find out an email server for a particular domain? For example for email printers at sendme.cz I find out that email server mail.contactel.cz serves for domain sendme.cz Thank you for help. Ladislav From sdm7g at Virginia.EDU Tue Oct 16 11:36:12 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Tue, 16 Oct 2001 11:36:12 -0400 (EDT) Subject: import question In-Reply-To: Message-ID: On Tue, 16 Oct 2001, Vojin Jovanovic wrote: > Suppose I have a file foo.py file that contains a function > and now I do import foo. Then, I have my function available > in python. But let's suppose that I decide to change the function in foo.py > file > Why is it that doing import foo again doesn't load the new definition of > the function > which would be normal behavior in LISP for example? > Because of not having such behavior in Python one has to exit the program > and then > do import foo in order to load the new definition!? If you're going to compare Python statements to Lisp, Python's 'import' is closer to Lisp's 'require' than it is to 'load' : if it has already been loaded it won't do it twice. There is very little overhead to subsequent 'imports' : all it has to do is make the namespace available. You don't have to exit and restart the compiler (unless it's a module written in C as there is no 'unload' capability -- mainly because that's something that's not supported by the dynamic linking on all platforms.). Use "reload module", which will cause the file to be reloaded and reexecuted. If you did an import as "from foo import *" ,then you need to do: import foo # get foo into namespace reload foo # reload it from foo import * # until you do this, the names in this namespace # still point to the names in the old foo module. -- Steve Majewski From sholden at holdenweb.com Tue Oct 9 07:21:23 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 9 Oct 2001 07:21:23 -0400 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> <3BC2BDC3.20A41F38@snakefarm.org> Message-ID: "Carsten Gaebler" wrote ... > Thanks for all the answers. Seems as if I hadn't been specific > enough about what I was looking for. It would be nice if there was > some builtin dictionary magic that would allow > > "%(foo) %(bar)" % magic(dict1, dict2, ...) > > where in case of duplicate keys the leftmost dictionary would be > preferred. > > Perhaps the builtin dictionary() class could be extended so that > it accepts more than one dictionary argument? > Well, perhaps it could, but I can't say I've seen much of a case for it. There are clearly so many ways you can achieve what you require in the existing language. Wouldn't you say your requirements are a little, erm, esoteric to be requiring core language changes? Don't forget that from next year onwards you will be able to inherit from built-in types, so then you'll not need to change dictionaries, you can just subclass them to your heart's content. let's-change-the-programmers-not-the-language-ly y'rs - steve -- http://www.holdenweb.com/ From martime at kellyservices.com Tue Oct 9 16:45:52 2001 From: martime at kellyservices.com (Maria Martino) Date: 9 Oct 2001 13:45:52 -0700 Subject: Excellent Python/VC ++ Contracting Opportunity! Message-ID: <913930fb.0110091245.5b74d33b@posting.google.com> My name is Maria Martino and I am a recruiter for Kelly Services. I have a contracting opportunity for a Python/VC++ programmer. All interested and qualified candidates should send their resume to: martime at kellyservices.com Attn: Maria Martino Term: Contractor Length: 4 months Job Description: Work with the development team on an exciting business application software. Location: Tarrytown, Westchester County, NY Required Skills: Commercial development experience in Visual C++ and Python on Win32 platform. Strong analytical skill. Object-oriented programming is a must. SQL Server or other database server. Experience in widget-based GUI development. Experience in webserver or application server (e.g. IIS, Zope). Desirable skills: Advanced degree (CS/EE, Science, Math or other) welcome. Previous experience in finance, statistics, or Monte Carlo simulation. XML processing. Internet programming experience (TCP/IP, HTTP protocol, RPC, socket programming.) COM programming in business applications, interfacing with Access/Excel. Visual Basic for Applications. Source code revision control systems. Bug report database. InstallShield. From chrishbarker at home.net Thu Oct 25 18:46:42 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 25 Oct 2001 15:46:42 -0700 Subject: Question: Dynamic code import References: <3bd86540_2@corp-goliath.newsgroups.com> Message-ID: <3BD89652.9C339B94@home.net> "K?roly Ladv?nszky" wrote: > 1. Is it possible to 'import' Python code in a dynamic fashion? > > For instance, the running program refers to function f1 through ff: > > def f1(a): > return a*1.25 > > ff=f1 > > At some point, it turns out that f1(a) should return a*1.3+5. If it was > possible to insert a > new function, the running program could be modified like this: > > #--- this is to be 'imported' > def f11(a): > return a*1.3+5 > #--- sure is: #######file functions.py: def f2(x): return x**2 def f3(x): return x**3 def f4(x): return x**4 ####Another file, or command line: >>> def f1(x): ... return x ... >>> >>> f = f1 >>> >>> f(4) 4 >>> import functions >>> f = functions.f2 >>> f(4) 16 >>> f = functions.f3 >>> f(4) 64 >>> f = f1 >>> f(4) 4 So there you go. If the new function you want is not one of a set that you know about ahead of time, you can build it as a string, and use exec(), or read it from a file with execfile(). These are the straightforward ways to do it. There are also fancy ways that you probably don't need like: >>> f.func_code = functions.f3.func_code >>> f(4) 64 Another thing to consider is curried functions: functions that generate functions. Check the newsgroup archives for curried functions, you'll find dome nifty discussion. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From wolfgang.grafen at marconi.com Mon Oct 1 04:34:46 2001 From: wolfgang.grafen at marconi.com (Wolfgang Grafen) Date: Mon, 01 Oct 2001 10:34:46 +0200 Subject: [Announce] Module indent.py - Indents and dedents bocks of text, %()s-style block indent Message-ID: <3BB82AA6.2E32CBF7@marconi.com> I tried to announce this module 2 times in comp.lang.python.announce but it has not appeared. Does anybody know why? ********************************************************************* Module indent.py: Indents and dedents bocks of text, %()s-style block indent The indent module is useful for writing code generators. Templates are a very often used for this but the '%()s' style text substitution produces fuzzy indented code unless the key is in the first position of the line. This makes visual inspection of the generated code difficult and often individual helper functions are used to get around this problem. The indent module provides three functions: (1) template: wraps a string object for '%()s style text substitution and thus fixes the oddity of the Python string object that it does not indent text correctly in this way. (2) indent: indent a text for n spaces (3) dedent: - strip spaces from the beginning of the line(s) - maximum dedent for text block - strip n_spaces from text block Download available from http://home.nexgo.de/wolfgang.grafen/Python/Modules/indent-0.1.zip Wolfgang ---------------------------------------------------------------------- mailto:WolfgangGrafen at gmx.de From sheila at spamcop.net Mon Oct 29 00:27:02 2001 From: sheila at spamcop.net (Sheila King) Date: Mon, 29 Oct 2001 05:27:02 GMT Subject: python binary search References: Message-ID: <9rht70.3vvdvgd.1@kserver.org> On Mon, 29 Oct 2001 15:38:53 +1100, "Delaney, Timothy" wrote in comp.lang.python in article : :I should resist, but I can't. : :So, what is this "it" that you do? (idoit). Twenty lashes with a wet noodle for Delaney. That was uncommonly cruel! Poor Jeff has already beaten himself up enough. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From dale at riverhall.NOSPAMco.uk Wed Oct 3 11:21:11 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Wed, 03 Oct 2001 16:21:11 +0100 Subject: Really great stuff you didn't know you had. #4 - Pydocs. Message-ID: I never really had time to hunt through the stuff that came with my Python dist. to find what goodies lay hidden within. But by accident the other day while looking for info on docstrings, I came upon PyDoc, which, on my system is at: C:\Python21\Tools\Scripts\pydoc.pyw What a brilliant program this is! If you run it, it creates an http server that serves up docs generated from your Python modules. Just point a web browser at the port and browse. Great stuff. Thanks Ka-Ping Yee -- Dale Strickland-Clark Riverhall Systems Ltd From max at alcyone.com Wed Oct 17 16:06:36 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 17 Oct 2001 13:06:36 -0700 Subject: newsgroup traffic way down? References: <8827e15d.0110170823.672f0a63@posting.google.com> Message-ID: <3BCDE4CC.7FF99DD8@alcyone.com> Chris Ryland wrote: > Is it just I, or is c.l.p traffic way down lately? > > Or maybe, since I'm reading it on Google, they're filtering out spam, > including silly on-topic questions? ;-) On the contrary, comp.lang.python traffic seems to be peaking. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Love is a hole in the heart. \__/ Ben Hecht Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From loewis at informatik.hu-berlin.de Fri Oct 26 12:23:24 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 26 Oct 2001 18:23:24 +0200 Subject: Parse XML using DTD ?? References: <9rbq0o$a3l$1@reader1.imaginet.fr> Message-ID: "Barghest" writes: > Is it possible to parse an XML doc with DTD in python... ? > > There's a perl wrapper to use Xerces which is able to do that, but it > doesn't work on win32, so i want to if it exists in python.... In addition, PyXML offers another validating parser, namely xmlproc. This is a pure-Python parser which comes with PyXML. Furthermore, on Windows, you can use MSXML3, if installed, through PythonWin. Regards, Martin From gbreed at cix.compulink.co.uk Thu Oct 18 05:23:35 2001 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Thu, 18 Oct 2001 09:23:35 +0000 (UTC) Subject: opening sys.stdout in binary mode on Windows? References: Message-ID: <9qm72n$lng$1@thorium.cix.co.uk> In article , janssen at parc.xerox.com (Bill Janssen) wrote: > On Windows, I'd like to have stdout opened in binary mode before > writing to it. I've tried things like > > sys.stdout = os.fdopen(sys.stdout.fileno(), "wb") > > without success. Anyone know the trick? Run as python -u Graham From phd at phd.pp.ru Thu Oct 11 12:00:37 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 11 Oct 2001 20:00:37 +0400 Subject: Length on an input parameter in python In-Reply-To: ; from coolslife@yahoo.com on Thu, Oct 11, 2001 at 08:51:31AM -0700 References: Message-ID: <20011011200037.I4520@phd.pp.ru> On Thu, Oct 11, 2001 at 08:51:31AM -0700, coolslife wrote: > It looks like the length of an input parameter (taken from the command > line atleast) is limited to 256 characters. Windows? Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From andrew at mail.idrive.com Fri Oct 19 21:29:49 2001 From: andrew at mail.idrive.com (andrew) Date: 19 Oct 2001 18:29:49 -0700 Subject: async. winsound .PlaySound question.... Message-ID: <70461e98.0110191729.62212d6b@posting.google.com> i cannot seem to get my system to run more than one winsound.PlaySound asyncronously ... I think I am using the right flags ... here is my code snippet: winsound.PlaySound(filePath1, winsound.SND_FILENAME | winsound.SND_ASYNC | winsound.SND_NOSTOP) winsound.PlaySound(filePath2, winsound.SND_FILENAME | winsound.SND_ASYNC | winsound.SND_NOSTOP) on the second attempt to play a sound, i get a RunTimeError. i am on a win2k system with a full-duplex enabled sound driver. Python 2.1. any ideas? thanks in advance From jim.correia at pobox.com Sun Oct 21 19:48:57 2001 From: jim.correia at pobox.com (Jim Correia) Date: Sun, 21 Oct 2001 23:48:57 GMT Subject: Dictionary from list? References: Message-ID: In article , Martin von Loewis wrote: > Jim Correia writes: > > > I wasn't insisting that there must be on in python, just asking if there > > was :-) > > I think this thread would have died quite early if you did just > that... Instead, after being told that this conversion is not > supported as a built-in, you responded > > "This is quite unfortunate." > > People then have read this into insisting. It was probably a poor choice of words. It was late and I was in a rush. It should have said I would have preferred that there was a built in conversion rather than rolling my own. The problem, however, has long since been solved. Thanks. Jim From maxm at normik.dk Thu Oct 11 07:15:11 2001 From: maxm at normik.dk (Max M) Date: Thu, 11 Oct 2001 13:15:11 +0200 Subject: how do I add site-packages on Windows? Message-ID: <3bc57f3b$0$233$edfadb0f@dspool01.news.tele.dk> I have had this problem before, but never really got a working solution. If I put packages into: \Lib\site-packages\ And then I try to use it from ie. iis (Windows naturally) Python cannot find my packages. What would I need to do to make Python search in site-package automatically? Should I put them into "Plat-Win" instead, or is that used for something else ??? regards Max M --------------------------------- PythonWin 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (MarkH at ActiveState.com) From logiplexsoftware at earthlink.net Tue Oct 9 15:31:05 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 9 Oct 2001 12:31:05 -0700 Subject: TROJAN ALERT! (JS/Loop) In-Reply-To: References: <3bc343a0.fba6e0c5.c0a801.00.R@drsolomon.com> Message-ID: <01100912310503.02876@logiplex1.logiplex.net> On Tuesday 09 October 2001 11:59, Steve Holden wrote: > I would have characterised this attack as a GUI denial-of-service, not a > Trojan horse. A Trojan horse is an exploit which collects information from > an unsuspecting user and stores or transmits it for use by the third party. > Such misinformation does not lend credibility. The code involved was a > simple infinite alert loop. Actually, a trojan horse is simply a hostile program that masquarades as a useful one (hence the name). It doesn't really matter what the function of the program is. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From walter at livinglogic.de Wed Oct 31 12:17:27 2001 From: walter at livinglogic.de (Walter =?ISO-8859-1?Q?D=F6rwald?=) Date: Wed, 31 Oct 2001 18:17:27 +0100 Subject: XML can't read Unicode shock horror. News at 11. References: Message-ID: <3BE03227.1090500@livinglogic.de> Martin von Loewis wrote: > Dale Strickland-Clark writes: > > >>I see that this is probably the same as Python bug #216388 which has >>been around for over a year and been given a low priority (3). >> > > It is not the same bug. Even if cStringIO supported Unicode objects, > expat would still require byte strings. > > >>Non-unicode XML is a bit restrictive. :-( >> > > Why do you think so? XML documents are byte sequences, not character > strings. The *content* is Unicode; the document is not. But xml.sax.xmlreader.InputSource provides methods setCharacterStream and getCharacterStream, to be able to parse something which is already a decoded unicode character stream. Does any of the available parsers support this? Bye, Walter D?rwald From grante at visi.com Wed Oct 17 13:40:43 2001 From: grante at visi.com (Grant Edwards) Date: Wed, 17 Oct 2001 17:40:43 GMT Subject: PosixSerial.py license and gcavazos? References: Message-ID: In article , Christian Reis wrote: > I'm writing a GPLed application and since I need software to communicate > with a serial printer, I found and ended up using PosixSerial.py. Now > this module is available from some sites on the web - Parnassus for one > is an example - but I've always failed to find out what license it has. > > I've been looking for the author for a couple of months now, emailing > people off and on, but have still to find him. Does anybody know who he > is, or what the original license it? He seemed to have a website at > http://members.tripod.com/~gcavazos/ but there was no content and it > seems to be gone. I wrote a module named PosixSerial.py, but it doesn't sound like the same one. I've decided this is the license for mine: You may use PosixSerial.py in any way you want so long as you don't claim copyrights on the code I wrote. You are not required to do so, but I would like it if you sent me copies of any modifications or added features and allowed me to incorporate and distribute them. I'll add a that and a copyright notice to the file sometime soon. -- Grant Edwards grante Yow! Fold, fold, at FOLD!! FOLDING many items!! visi.com From peter at engcorp.com Sun Oct 7 13:31:16 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 07 Oct 2001 13:31:16 -0400 Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> <9pimak$c22$1@tyfon.itea.ntnu.no> <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> <3BBE4E12.16FE036A@earthlink.net> <9pn44q$m1r$1@tyfon.itea.ntnu.no> <3BBF2751.3010309@sneakemail.com> <3bc07f07.2807256@127.0.0.1> Message-ID: <3BC09164.57AC087B@engcorp.com> Fish wrote: > > The simple solution is, of course, to not allow people with names ending in > 's' to own anything. How, then, would you refer to their lack of possessions? Clearly the only viable solution is to eliminate them altogether. Or at least this thread. :) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From volucris at hotmail.com Tue Oct 9 23:33:37 2001 From: volucris at hotmail.com (Greg Krohn) Date: Tue, 9 Oct 2001 22:33:37 -0500 Subject: executing a variable? References: <87ofnf9owk.fsf@toadmail.com> Message-ID: <3bc3c07d$0$319$6e49188b@news.goldengate.net> The ConfigParser module is what you want. If you are familiar with Windows .ini files, it works a lot like those. import ConfigParser cf1 = ConfigParser.ConfigParser() cf1.add_section('MAIN') cf1.set('MAIN', 'spam', 'foo') cf1.set('MAIN', 'eggs', 'bar') cf1.write(open('settings.text', 'w')) cf2 = ConfigParser.ConfigParser() cf2.read('settings.text') print 'spam is ' + cf2.get('MAIN', 'spam') print 'eggs is ' + cf2.get('MAIN', 'eggs') greg -- Volucris (a) hotmail.com "Eu n?o falo uma ?nica palavra do portugu?s." "Jeremy Whetzel" wrote in message news:87ofnf9owk.fsf at toadmail.com... > > Hi, > > I'm playing around with a script that creates a "settings" file to be > loaded the next time the program is run. Currently what I have is a > settings file that is just a number of variables defined: > > spam = "foo" > eggs = "bar" > > ... and so on... > > Then I do something like: > > settings = open("settings.text","r") > line1 = settings.readline() > line2 = settings.readline() > > ... and so on... > > now I have these variables that contain the whole line of 'spam = > "foo"'. Is there anyway I can "execute" these variables so that they > actually perform the instructions inside them? If I try to " print > spam", I get NameError spam. > > OR, if there is a better way of doing this, please point me in the > correct direction. I'm extremely new to python, and only slightly less > so with shell scripting (to give you an idea of my programming prowess). > > Thanks for your help, > Jeremy From loewis at informatik.hu-berlin.de Sun Oct 21 09:01:17 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 21 Oct 2001 15:01:17 +0200 Subject: 2.1 extension errors on Solaris/gcc References: <9qqc17$n8p$1@slb0.atl.mindspring.net> Message-ID: "Andrew Dalke" writes: > Original attempt was to compile Python with gcc 2.95 using > the archive from ftp.sunfreeware.com . That caused a problem. > > solana> /usr/local/bin/python > Python 2.1.1 (#1, Aug 25 2001, 04:37:28) > [GCC 3.0.1] on sunos5 > Type "copyright", "credits" or "license" for more information. > >>> import cStringIO > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: /usr/local/bin/python: fatal: libgcc_s.so.1: > open failed: No such file or directory > >>> > > and there was no libgcc_s.so anywhere on the machine. I very much doubt that you got gcc 2.95. libgcc_s is only introduced by gcc 3. Is there any chance configure was picking up a gcc 3 driver (the "gcc" binary) already? > gcc -shared build/temp.solaris-2.7-sun4u-2.1/dayswig_python.o \ > build/temp.solaris-2.7-sun4u-2.1/daydepict_python.o \ > -L/daylight/v472/lib -ldt_thor -ldt_merlin -ldt_progob -ldt_depict \ > -ldt_monomer -ldt_datatype -ldt_finger -ldt_smarts -ldt_ipcx \ > -ldt_smiles -lm -o build/lib.solaris-2.7-sun4u-2.1/dayswig_python.so > ld: warning: global symbol `_DYNAMIC' has non-global binding: > (file /usr/local/lib/gcc-lib/sparc-sun-\ > solaris2.7/3.0.1/../../../libgcc_s.so value=LOCL); > ld: warning: global symbol `_PROCEDURE_LINKAGE_TABLE_' has non-global \ > binding: (file /usr/local/lib/gcc-lib/sparc-sun-\ > solaris2.7/3.0.1/../../../libgcc_s.so value=LOCL); > ld: warning: global symbol `_GLOBAL_OFFSET_TABLE_' has non-global binding: > (file /usr/local/lib/gcc-lib/sparc-sun-\ > solaris2.7/3.0.1/../../../libgcc_s.so value=LOCL); > Bus Error (core dumped) > > Now what? Tell us what binutils are you using. What is as, what is ld? If GNU binutils, what versions? You can find out what tools are used by invoking gcc with -v; make sure you add that to a linker line. It may be that the precompiled gcc on Sunfreeware was build for use with GNU binutils, so you may need to install those as well. In any case, I recommend to get a working compiler first before starting to build Python. It may be that you have to get a really old gcc version first, than rebuild a more recent version if the prebuilt binaries are unusable. Regards, Martin From chasm at galileo.rift Mon Oct 1 10:38:15 2001 From: chasm at galileo.rift (Julian Tibble) Date: 1 Oct 2001 14:38:15 GMT Subject: GNU wars again (was Re: Proposal: add vector arithmetic to array module) References: <7x3d5bxhan.fsf@ruckus.brouhaha.com> <7xzo7jnkjv.fsf@ruckus.brouhaha.com> <9p7kq3$kiu$1@panix3.panix.com> Message-ID: In article , Trond Eivind Glomsr?d wrote: >Of course, "free" means that you have and can modify the source and I >haven't seen anyone claim that using the term "open source" doesn't >include this. The GPL restricts your freedom to restrict the software >as released by you and is thus "less free" than eg. the XFree86 >license. Ever heard the phrase "information should be free" ? Check out some definitions of `hacker ethic' or read some Levy. Thinking about it this way, the GPL is more free than the XFree86 license, since it is the continuing availability of the code, and variations on it, that the license ensures - not your personal human rights/liberties/whatever. Julian From nhodgson at bigpond.net.au Wed Oct 31 17:00:01 2001 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 31 Oct 2001 22:00:01 GMT Subject: PythonWin 2.1 saving bugg??? References: <7FUD7.3566$Z_1.627692@newsc.telia.net> Message-ID: Tim Gahnstr?m: > There is several undelete programs... I downloaded a few and they found a > zillion different deleted files... but not mine!!! groar"#?"#!!! Got to do > some working instead I guess :-(( If you know anything about the file contents, such as a string to search for that is reasonably unique then you can search all the blocks of the disk for that string. http://www.scintilla.org/LowLevel.py is some code I used for finding some lost emails from a disk that died once. The f.seek call is to ignore the first 1.8G which were the wrong partition and the loop range is based on where the right partition was - I think you can just read until read fails instead if you want to search the whole disk. Neil From oliphant at ee.byu.edu Wed Oct 17 11:28:53 2001 From: oliphant at ee.byu.edu (Travis Oliphant) Date: Wed, 17 Oct 2001 11:28:53 -0400 Subject: READ FILE UNTIL THE Xth SPACE IS ENCOUNTERED... In-Reply-To: References: Message-ID: > Hi list :-) > > Motivation: I have massiv ASCII files containing floats delimited by spaces > and run out of memory when trying to get them into the machine in one piece > (followed by spliting into a list object). > In the SciPy package there is a function called io.read_array that you should look into. It reads ascii data into Numeric arrays. help(io.read_array) after a from scipy import * will show you how it works. It may not be fast enough, but it should be as fast as any line-by-line method. There is a package out there called TableIO that is quite fast but requires compilation. It's old and I'm not sure if it is available anymore. There is also a function in Konrad Hinsen's Scientific Python that reads ascii data into arrays. Good luck, -Travis From quinn at ngwee.ugcs.caltech.edu Wed Oct 3 23:48:07 2001 From: quinn at ngwee.ugcs.caltech.edu (Quinn Dunkan) Date: 4 Oct 2001 03:48:07 GMT Subject: scanf style parsing References: <3BB16A50.BAE082FE@cygnus-software.com> Message-ID: On Wed, 26 Sep 2001 22:21:05 GMT, Andrei Kulakov wrote: >On Wed, 26 Sep 2001 05:42:45 GMT, Bruce Dawson wrote: >> I love programming in Python, but there are some things I have not found >> the easy way to do. I understand that Python is supposed to be good at >> text parsing, but I am having trouble with this simple task. Given this >> text (the output from VisualC++) I want to find out how many errors and >> warnings there were: >> >> smtpmail.exe - 0 error(s), 0 warning(s) > >Seeing that there should only be 2 words here that are numbers, you can do >this: > >my_str # that's where the result is >words = my_str.split() >lst = [] >for word in words: > try: > result = int(word) > lst.append(result) > except: > pass > >errors = lst[0] >warnings = lst[1] More compactly: errors, warnings = [ int(w) for w in line.split() if w.isdigit() ] From per at sbc.su.se Mon Oct 15 03:59:03 2001 From: per at sbc.su.se (Per Kraulis) Date: Mon, 15 Oct 2001 09:59:03 +0200 Subject: SVG and Python? Message-ID: <3BCA9747.2F8C9462@sbc.su.se> I am looking for a Python module implementing SVG (Scalable Vector Graphics, http://www.w3.org/TR/2001/REC-SVG-20010904/). I haven't found anything on Parnassus, various SVG sites, or Google. Specifically, I would love to obtain a module that renders SVG in a Tkinter Canvas. Does such a thing exist? If so, does it have a usable license (GPL, or LGPL)? Yours, Per K -- Per J. Kraulis, Ph.D. per at sbc.su.se Stockholm Bioinformatics Center (SBC) http://www.sbc.su.se/~per/ SCFAB, Dept Biochem Biophys, Stockholm Univ phone +46 (0)8 - 5537 8571 SE-106 91 Stockholm, SWEDEN fax +46 (0)8 - 5537 8601 From smaili at tttech.com Tue Oct 9 06:41:23 2001 From: smaili at tttech.com (Idriz SMAILI) Date: Tue, 09 Oct 2001 12:41:23 +0200 Subject: PYTHONPATH and embedding python Message-ID: <3BC2D453.6331CAF3@tttech.com> Hi, I have the following problem: I have embedded Python in an C++ application. The Python modules are after freezing integrated in the application and those modules should be imported as frozen modules. Before I initialize the Python interpreter I've used the putenv in C code to set the environment variable PYTHONPATH to "pwd == .". I've used the getenv function to check if the environment variable has been changed and it is as expected really changed to the new setting result. The problem is that the Python Interpreter during its initialization uses the same getenv function and it gets the old value of the PYTHONPATH value. This is my problem, because I've got a lot of problems in case the user has installed a different python version, because the Python Interpreter tries to import for example the os module, which is different between Python 1.5.2 and Python 2.1.1. I am using Python 2.1.1 and Microsoft Visual Studio V. 6.0. under WinNT operating system. Does anyone have any suggestions? Thanks. Idriz From ballabio at mac.com Wed Oct 31 05:35:25 2001 From: ballabio at mac.com (Luigi Ballabio) Date: Wed, 31 Oct 2001 10:35:25 +0000 Subject: Interfaces != Multiple Inheritance [was Re: python development practices?] In-Reply-To: <7xy9lsr0xn.fsf@ruckus.brouhaha.com> References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: <5.1.0.14.0.20011031102643.00a64390@mail.mac.com> At 06:35 PM 10/30/01 -0800, Paul Rubin wrote: >Richard Jones writes: > > Java interfaces != multiple inheritance. > > > > They address completely different issues. Mutliple inheritance allows one > > to include functionality from multiple base classes in one step. An > > interface indicates that your class implements a specific set of methods. > > Interfaces don't implement functionality, therefore indicating that your > > class implements multiple interfaces doesn't add any additional > > functionality. > >The idea is implement an abstract base class instead of an interface. >Define methods for all the operations you want your interface to >support, and make each method simply raise NotImplementedError. Then >make the implementation for your inheriting class supply real versions >of all the operations. Why would you want to do that in Python? The interface mechanism is needed in Java due to its type checking---if you declare a function as f(Interface i), then an object needs to implement Interface to be accepted by f as an argument. The same applies to C++ and purely abstract base classes. There is no such requirement in Python: you just write f(i) assuming that i implements the needed methods, and the interpreter will raise an error if i doesn't. The principle is the same (well, alike) as C++ templates. Bye, Luigi From dbparker at nortelnetworks.com Thu Oct 4 10:16:03 2001 From: dbparker at nortelnetworks.com (Don Parker) Date: Thu, 4 Oct 2001 10:16:03 -0400 Subject: QNX Support Message-ID: <9phqv4$bh2$1@bcarh8ab.ca.nortel.com> I can get a port of 1.5.2 from QSSL but I was wondering if anyone had done a more recent release port (e.g. 2.x) of Python to QNX Neutrino (aka QNX 6.0). Also, we seem to be having trouble in our attempts to add C extensions via shared dlls on QNX - any war stories or solutions would be welcome! From duncan at NOSPAMrcp.co.uk Mon Oct 15 09:53:36 2001 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 15 Oct 2001 13:53:36 +0000 (UTC) Subject: Zope vs PHP for the Linux guru References: <4bf6cf6d.0110150255.1518bbed@posting.google.com> Message-ID: benjamin.geer at misys.com (Benjamin geer) wrote in news:4bf6cf6d.0110150255.1518bbed at posting.google.com: >> Zope scales fine. There's a lot that goes into this; >> the one-line summary is that Zope more than holds its own. > > Has the Python interpreter's global thread lock caused any > difficulties in getting Zope to scale well? If so, I'd be very > curious to know how this hurdle has been overcome. I believe that Zope 'solves' the global thread lock problem by expecting you to run multiple processes. So long as you run as many processes as you have processors In general Zope handles scaling by means of ZEO. This splits off the object store into a separate backend process with one or more front end Zope servers running as ZEO clients. If you are running on a multi-processor machine then you could run multiple instances of Zope talking to a ZEO server on the same or a different machine. A ZEO server can also be a ZEO client, so for a really big system you can build a tree of ZEO servers. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From fredrik at pythonware.com Wed Oct 17 03:06:20 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 17 Oct 2001 07:06:20 GMT Subject: breaking a string References: <9qi6uu$h4c$1@nserve1.acs.ucalgary.ca> Message-ID: Michael Yuen wrote: > I'm pretty new to this Python stuff and i'm trying to figure out how to > break a string into it's component parts. > > For example, if a line of text in a file is: > "Hello World!" > > I want to enter that into my list as just ['Hello', 'World'] >>> s = "Hello, World!" >>> s.split() ['Hello,', 'World!'] >>> import re >>> re.findall("\w+", s) ['Hello', 'World'] From skip at pobox.com Thu Oct 18 17:45:52 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 18 Oct 2001 16:45:52 -0500 Subject: PEP: statements in control structures In-Reply-To: References: <20011019002941.A721@xyz.donetsk.ua> Message-ID: <15311.19856.515994.225805@beluga.mojam.com> Rich> Or perhaps along that same vein... Rich> while line from file.readline(): Rich> ... Python 2.2 with iterator support already supports for line in file: ... -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From donn at u.washington.edu Tue Oct 16 17:09:25 2001 From: donn at u.washington.edu (Donn Cave) Date: 16 Oct 2001 21:09:25 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> <9qhvq5$29ik$1@nntp6.u.washington.edu> Message-ID: <9qi7m5$lq6$1@nntp6.u.washington.edu> Quoth "Steve Holden" : [... my optimistic vision of how Python might finally stabilize snipped ...] | I really feel you are overestimating the commitment to implement this in 2.2 | or indeed any other later release. Quite apart from the ickiness factor, it | complicates reading programs for a beginner, does not actually solve that | many real probelsm, and adds a new keyword to the language. | | If I were a gambling man (which I'm not, mostly because I hate losing) I'd | give you even money that Python 2.2 will be unsullied by this particular | wart. I would have thought better than even odds. 2.2 is already in final alpha release, from what I read. I really don't intend to react specifically to this feature. I don't know what all is in 2.2. For myself, I have no plan to upgrade to 2.2, unless, at some point, if there's a consensus that it's the right place to draw the line. My point is, that place depends on how people feel about 2.2. If you buy my proposition that it's in our interest to draw the line somewhere collectively, you should really think for yourself about what's in 2.2 for you, before you upgrade. If you really like 2.2's features, then go for it. Even if you're later turned off from 2.3 by something like ?: (and I wouldn't bet a nickel ?: isn't going to happen in 2.3), if you can wholeheartedly recommend 2.2 over 2.1, then that's obviously the right thing. Donn Cave, donn at u.washington.edu From MarkH at ActiveState.com Mon Oct 22 09:29:37 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Mon, 22 Oct 2001 13:29:37 GMT Subject: Service not stopping References: Message-ID: <3BD41F66.5090804@ActiveState.com> belen at netcom.no wrote: > Yeah, > > The problem is that my program never gets to the while loop. Is there a > way of regaining control of the service process...Can I create then two > simultanous processes an control bot of them? Might the problem have > been the way I have created the scheduler process? I have no idea what the scheduler process does, or what such a bot might do. Threads work fine with services, so I suspect that may be your answer - the scheduler should probably create a new thread, and it's loop sets the self.hSched event. The main service loop will then need to check the WFMO() result to see what request has been made. Mark. From chrishbarker at home.net Thu Oct 4 15:15:09 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 04 Oct 2001 12:15:09 -0700 Subject: another wxPython-question References: <9pi16t$5pt1t$1@hades.rz.uni-sb.de> Message-ID: <3BBCB53D.407B103B@home.net> Uwe Schmitt wrote: > in the wxWindows documentation I found classes wxDC, wxPaintDC and > others. But these are not known if I use wxPython. > Is my wxPython installation to old ? I downloaded it from > www.wxpython.org... It's probably not too old, the ones you mention have been around forever. You may not have wxPython installed properly, or you may not be importing it correctly. try this: >>> from wxPython.wx import * >>> wxDC >>> wxPaintDC >>> You get something like that, showing that thye do exist. AS for using them, look at the demo, and I've enclosed a little simple drawing program to get you started. -Chris #!/usr/bin/env python from wxPython.wx import * import random #--------------------------------------------------------------------------- NumLines = 100 ID_DRAW_BUTTON = 100 ID_QUIT_BUTTON = 101 AllPens = [wxRED_PEN, wxCYAN_PEN, wxGREEN_PEN, wxBLACK_PEN, wxWHITE_PEN, wxTRANSPARENT_PEN, wxBLACK_DASHED_PEN, wxGREY_PEN, wxMEDIUM_GREY_PEN, wxLIGHT_GREY_PEN] class DrawCanvas(wxPanel): def __init__(self, parent, id = -1, size = wxDefaultSize): wxPanel.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER) EVT_PAINT(self, self.OnPaint) self.SetBackgroundColour(wxNamedColor("WHITE")) def OnPaint(self, event): self.Draw() def Draw(self): dc = wxPaintDC(self) # Generate a whole bunch of random lines. (maxx,maxy) = (self.GetClientSize().width,self.GetClientSize().height) Lines = [] Pens = [] for i in xrange(NumLines): x,y = random.randint(1,maxx), random.randint(1,maxy) x2,y2 = random.randint(1,maxx), random.randint(1,maxy) Lines.append((x,y,x2,y2)) Pens.append(AllPens[random.randint(0,len(AllPens)-1)]) dc.BeginDrawing() dc.Clear() for line,pen in zip(Lines,Pens): dc.SetPen(pen) dc.DrawLine(line[0],line[1],line[2],line[3]) dc.EndDrawing() class DrawFrame(wxFrame): def __init__(self,parent, id,title,position,size): wxFrame.__init__(self,parent, id,title,position, size) tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER) tb.AddControl(wxButton(tb, ID_DRAW_BUTTON, "DRAW!",wxDefaultPosition, wxDefaultSize)) EVT_BUTTON(self, ID_DRAW_BUTTON, self.OnClickDraw) tb.AddSeparator() tb.AddControl(wxButton(tb, ID_QUIT_BUTTON, "QUIT",wxDefaultPosition, wxDefaultSize)) EVT_BUTTON(self, ID_QUIT_BUTTON, self.OnClickQuit) tb.Realize() EVT_CLOSE(self, self.OnCloseWindow) self.Canvas = DrawCanvas(self,size=(500,500)) self.Show(true) return None def OnClickDraw(self,event): self.Canvas.Draw() def OnClickQuit(self,event): self.Close(true) def OnCloseWindow(self, event): self.Destroy() class App(wxApp): def OnInit(self): frame = DrawFrame(NULL, -1, "Simple Drawing Window",wxDefaultPosition,wxSize(500,500)) self.SetTopWindow(frame) return true app = App(0) app.MainLoop() -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From richard at bizarsoftware.com.au Thu Oct 18 00:06:54 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Thu, 18 Oct 2001 14:06:54 +1000 Subject: Verified Input. In-Reply-To: <4783f0eb.0110171949.125344dc@posting.google.com> References: <4783f0eb.0110171949.125344dc@posting.google.com> Message-ID: <01101814065437.11044@ike> On Thursday 18 October 2001 13:49, Alec D. Cheah wrote: > How do verified from input the variable entered is a file or a path > and how do you check whether it exist or not?? > Help... > Newbie on Python.... Look up the os.path documentation in the library reference: import os.path os.path.exists(path) os.path.isfile(path) os.path.isdir(path) Richard From support at internetdiscovery.com Fri Oct 26 11:48:15 2001 From: support at internetdiscovery.com (Mike Clarkson) Date: Fri, 26 Oct 2001 15:48:15 GMT Subject: Nicer Tkinter on UNIX? References: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> <86DF15C112AF36D6.332DEDD523A2210C.F8DE5222D8EF2836@lp.airnews.net> Message-ID: <3bd985b7.5963368@nntp.ix.netcom.com> On 3 Oct 2001 10:59:05 -0500, claird at starbase.neosoft.com (Cameron Laird) wrote: >>On 3 Oct 2001 10:39:55 GMT, Artur Skura wrote: You may want to look at Tix, the extensioon widgets for Tk and Tkinter. As of Python 2.1 the wrapper is in the standard library, and if you are distributing a Tkinter application anyway, it doesn't take that much more to add Tix. >>> >>>[It's not particularly Pythonish question, but I thought you might know] >>> >>>I like Tkinter because it's standard. But there is a big but. >>>While on Windows it looks great, on unices it makes kids laugh. >>>Not that it's particularly ugly, but quite awkward and not up to the >>>aesthetic standards people expect now. >>> >>>Is there a way to make Tkinter use KDE/GTK themes on unices? Or change the >>>interface in any way? (I don't consider wx... stuff, as it forces users to >>>install additional software). Take at look at the lib/tix8.1/pref/WmDefault.* files in the Tix Development Environment (http://tix.sourceforge.net/Tide). They try to pick up the "style" from KDE/CDE/GNOME and Windows; this works for any Tk or Tix application - Tix is supported but not required. >Tk is unlikely to support themes (as that's currently under- >stood) at all soon. However, the topic is an active one >among Tcl-ers, and the time is absolutely ripe for Tk to >receive help from interested Pythoneers. I'll work on a Python wrapper so it can readily be called from Tkinter, but if you know a little Tk, you should be able to root.tk.eval('package require wm_default') root.tk.eval('wm_default::setup') root.tk.eval('wm_default::addoptions') for now. This is still being worked on - when I get it fully shaken down with a Tkinter wrapper I'll make a formal announcement. Mike. From gbreed at cix.compulink.co.uk Tue Oct 16 05:00:05 2001 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Tue, 16 Oct 2001 09:00:05 +0000 (UTC) Subject: FW: [Python-Dev] conditional expressions? References: <9qgcvk$91j$1@animus.fel.iae.nl> Message-ID: <9qgsul$5ep$1@thorium.cix.co.uk> In article <9qgcvk$91j$1 at animus.fel.iae.nl>, cfelling at iae.nl (Carel Fellinger) wrote: > > A conditional expression analogy to list comprehensions would be > > x = (a if b else c) > > though I think I like this spelling more, you mixed up a and b, and > that's probably a likely mistake, so a big disadvantage. On the other > hand this clearly looks like an expression to me, a big advantage. You can also remove the parentheses, and not have to worry about the "if" starting a new line. Graham From christophertavares at earthlink.net Wed Oct 31 12:35:17 2001 From: christophertavares at earthlink.net (Chris Tavares) Date: Wed, 31 Oct 2001 17:35:17 GMT Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> <7xzo68s63o.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7xzo68s63o.fsf at ruckus.brouhaha.com... > Peter Wang writes: > > i don't think data hiding's purpose is to keep rogue programmers in > > line. it's partly to insulate imperfect development practice (e.g. > > sloppy documentation) and partly to define an interface for a class. > > Keeping rogue programmers in line is a perfectly legitimate use of > data hiding. For example, look at java applets on web pages. These > have to run in the same JVM as parts of the browser, and yet the > applets can be hostile. So the language has to protect the browser > internals from the loaded applets. Another example is security > interfaces where the class instances contain authentication > credentials and the application should be able to use them but not > copy them. > > Python provides a restricted execution hack (rexec/bastion) to deal > with the applet situation, but it's a pain for the second situation > because you have to wrap the caller in the rexec shell, rather than > wrapping the secure object in a security shell and leaving the caller > unrestricted. > > The best way I've managed to deal with this is to put the secure > objects in a totally separate process and access them by RPC. > That, too, is a kludge, though. At the start of this thread, your post implied that 'data hiding' meant something similar to C++ or Java's access specifiers: private, public, etc. But the stuff you mention above has nothing to do with that! The applet sandbox is a specific mode provided by the runtime - and rexec/bastion is NOT a hack, it's just another way to implement a sandbox. As far as security - well, I don't know how stuff like that is supposed to work, but in my experience that's an OS issue rather than a language issue. Python compiles and runs on almost every platform under the sun, and lots of them don't have ANY kind of security, so what should it do? Implement some gigantic code-access security features that most people don't need? And in any event, C++ access specifiers don't do much but provide a challenge to those "rogue programmers" you mentioned, and they don't help at all in any of the above situations. So I'm curious what you really mean, and what you really want. -Chris From sholden at holdenweb.com Mon Oct 1 17:54:07 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 1 Oct 2001 17:54:07 -0400 Subject: list.append problem? References: Message-ID: "newgene" wrote in message news:a50631f6.0110011345.31523630 at posting.google.com... > I am a newer of python. I have a problem like this code: > > >>> a=b=c=[] > >>> a.append(1) > >>> b.append(2) > >>> c.append(3) > >>> a > [1, 2, 3] > >>> b > [1, 2, 3] > >>> c > [1, 2, 3] > > a,b,c become the same, although append method applied seperately. > It's really strange and unreasonable. > My python is ActivePython Build 210 running on WinNT. > Strange and unreasonable as it may seem, it's classic Python. All three variables are bound to the same object, so when you change the object (no matter which name you use) the value you see when you access any of the names is the same. However, try >>> a = [] >>> b = [] >>> c = [] >>> a.append(1) >>> b.append(2) >>> c.append(3) and you will see what you feel is more reasonable behavior: in this case each variable is bound to a different list, and so changing one of the lists doesn't affect the values bound to the other variables. You get used to it after a while, and after your third progam it will seem the most reasonable thing to do! regards Steve -- http://www.holdenweb.com/ From robin at jessikat.fsnet.co.uk Fri Oct 26 07:28:40 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 26 Oct 2001 12:28:40 +0100 Subject: PIL - cannot get jpeg decoder to work References: <0BbC7.141411$3d2.4598221@bgtnsc06-news.ops.worldnet.att.net> Message-ID: In article <0BbC7.141411$3d2.4598221 at bgtnsc06-news.ops.worldnet.att.net> , Nelson Rush writes >yes > >"Robin Becker" wrote in message >news:YQ8nTLAfKU27Ewne at jessikat.demon.co.uk... >> have you got libjpeg.so somewhere in /usr/lib or /usr/local/lib? >> -- >> Robin Becker > > mystery to me then. On linux you can run ldd over the _imaging.so to check what it needs/is linked against. What happens when you explicitly import JpegImagePlugin? -- Robin Becker From phd at phd.pp.ru Thu Oct 11 11:38:04 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 11 Oct 2001 19:38:04 +0400 Subject: SocketServer - multithreading In-Reply-To: <55720746FFC5D4118A3B00508BF9B80A012900CC@atlgaexc3.harbinger.com>; from Jeremy.Jones@peregrine.com on Thu, Oct 11, 2001 at 11:22:28AM -0400 References: <55720746FFC5D4118A3B00508BF9B80A012900CC@atlgaexc3.harbinger.com> Message-ID: <20011011193804.H4520@phd.pp.ru> Hi! On Thu, Oct 11, 2001 at 11:22:28AM -0400, Jeremy Jones wrote: > I am trying to write a simple daemon that listens on a port and writes the > request that it receives to a file. There will likely be multiple requests > coming in at the same time, so it needs to block the file writing so that > only one request writes to a file at once. I "borrowed" a code example from > the web and hacked it a bit to try to do what I need (and it almost works). > (If anyone sees that I am going about this in the wrong manner, please say > so. I have had no experience with threading and almost no experience with > sockets. Pointing me in another direction would be most welcome.) Assuming > that SocketServer is a good way to handle this, here is what I have so far > (BTW - this is Python 1.5.2 on Linux): Wow! The code looks VERY familiar to me! :))) > """ > #! /usr/bin/python -O > > > import sys, SocketServer > import string > > PORT = 2100 > > > class RequestServer(SocketServer.ThreadingTCPServer): > allow_reuse_address = 1 > > > class RequestHandler(SocketServer.StreamRequestHandler): > def handle(self): > host, port = self.client_address > #print "Connected by", host, port > > # get data > request = '' > > while 1: > line = self.rfile.readline() > if line in (None, "\n", "\r\n"): > break > request = request + line > > self.server.request = request > request = string.rstrip(request) > print request > > #outfile = open("server.csv", 'w') > #outfile.write(request) > #outfile.close() > > > def main(): > # get port > if len(sys.argv) > 1: > port = int(eval(sys.argv[1])) > else: > port = PORT > > print "Waiting..." > server = RequestServer(('', port), RequestHandler) > #server.handle_request() # do not server forever - serve just 1 request > server.serve_forever() # serve forever > > main() > """ > > The thing that isn't working is the file writing (thus it's commented out > right now). With the 3 "outfile" lines commented out, this works fine. But > when I uncomment them, the first request prints the request to STDOUT and to > the file, but subsequent requests only print to STDOUT. The first and > subsequent requests apparently sit waiting on the socket: > > [jjones at mahler socket]$ netstat -a | grep 2100 > tcp 0 0 mahler.atlqa:2100 mahler.atlqa:3167 > TIME_WAIT > tcp 0 0 mahler.atlqa:2100 mahler.atlqa:3166 > TIME_WAIT > tcp 0 0 mahler.atlqa:2100 mahler.atlqa:3165 > TIME_WAIT > tcp 0 0 *:2100 *:* LISTEN > > If anyone has any ideas how I can get this working (or find another > solution), I would be most grateful. Do you run the program in the background? It is possible that the program stuck upon printing the request, because background programs usually disallowed to write to console. Upon printing the program receives SIGTSTOP signal and stops. Do not write to stdout from a background process. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From richard at bizarsoftware.com.au Mon Oct 8 02:47:16 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Mon, 8 Oct 2001 16:47:16 +1000 Subject: Python questions -> compiler and datatypes etc In-Reply-To: <9prh9f+b0in@eGroups.com> References: <9prh9f+b0in@eGroups.com> Message-ID: <01100816471606.11044@ike> On Monday 08 October 2001 16:32, billy_bill_1 at yahoo.com wrote: > I've been using php for ages for webdev and I don't like it. It lacks > so many simple features, and I can't be bothered using Java to use > those features. IMHO java is not suited for specific web development. There's a lot of server-side Java programmers who would disagree with that statement. Python is better, but Java can do the job. > So I find python, I like python. Python has everything I need, except > (apparently) the ability to encode it (php: Zend Encoder) or Sorry, what do you mean by "encode it"? I'm not familiar with "Zend Encoder". > compile > it into Bytecode like java. Python compiles to bytecode. Python's runtimes execute compiled bytecode. There are several runtimes - one of which is Java. The predominant one is written in C. > It seems its not nearly as fast as java. > (Acceptable in most cases though). How did you measure this? > Are there any products coming out involving compilation of python? > Like a 2 stage interpreter like java... that would be tops... speed > and ability to sheild source code from prying and tampering eyes. Compiling python is at the impossible end of the scale of ease of implementation. There has been a lot of discussion about this issue on this list in the past. Search for "python compiler" and enjoy :) > Does python have the ability to let the programmer change between > strongly typed and loosly typed as needs be? No, unless you venture into JPython land, where you could mix Java code (strict, strong typing) and Python code (dynamic, strong typing) in the one project. Why on earth you'd want to is beyond me though :) > python support function overloading? Traditional overloading, which allows a function to have multiple signatures to allow different types to be passed in has no relevance in a dynamically typed language like Python. Witness: Python 2.1.1 (#1, Jul 20 2001, 22:37:24) [GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.58mdk)] on linux-i386 Type "copyright", "credits" or "license" for more information. >>> def foo(sequence): ... for element in sequence: ... print sequence.index(element), element ... >>> foo(['a', 'list']) 0 a 1 list >>> foo('a string') 0 a 1 2 s 3 t 4 r 5 i 6 n 7 g >>> [note: that's a cutnpaste from an inetractive session with the interpreter] > variable length parameter lists? Yep, and keyword arguments too. Continuing on from the previous interactive session, we redefine foo: >>> def foo(*args): ... print 'My args', args ... >>> foo(1, 2, 'hello', 3, foo) My args (1, 2, 'hello', 3, ) >>> Keyword args: >>> def foo(food='spam', container='tin'): ... print '%s in a %s'%(food, container) ... >>> foo() spam in a tin >>> foo(food='eggs') eggs in a tin >>> foo('curry', 'hurry') curry in a hurry >>> I suggest spending half an hour walking through the Python Tutorial. For added fun, type in the stuff in the tutorial into an interactive interpreter at the same time. That's how I learnt Python. Richard From db3l at fitlinxx.com Tue Oct 23 18:06:45 2001 From: db3l at fitlinxx.com (David Bolen) Date: 23 Oct 2001 18:06:45 -0400 Subject: Smtplib module References: <3BD20BAE.6346.7693E0@localhost> <9qscfm.3vv746r.1@kserver.org> <9qsnue.3vv5vib.1@kserver.org> <9r16as.3vv7bk7.1@kserver.org> Message-ID: "Steve Holden" writes: > I have actually had to do this for a client who needed to send email bills > out on behalf of their agents. Since the agents had email addresses not > associated with my client, it was necessary to send them out via the MX host > for the destination domain to avoid getting bounces for relaying. Sounds like that dumb Microsoft Exchange setting for preventing relaying while not being flexible enough to allow outbound mail from internal hosts that just happen to want to use SMTP rather than MAPI :-) -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From graz at mindless.com Tue Oct 30 10:41:23 2001 From: graz at mindless.com (Graham Ashton) Date: Tue, 30 Oct 2001 15:41:23 GMT Subject: Tk Live Preserver docs Message-ID: Until I saw Brian E's message in the "tkinter - tkFileDialog - how to get dir instead of fil " thread I hadn't heard of the Tk life preserver docs. I've since found them at: http://www.python.org/doc/life-preserver/ Where should I have found them? Shouldn't they be linked from the main www.python.org/doc/ page? -- Graham From sholden at holdenweb.com Thu Oct 18 20:29:58 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 18 Oct 2001 20:29:58 -0400 Subject: Conditional Expressions don't solve the problem References: <7xr8s2zo57.fsf@ruckus.brouhaha.com> Message-ID: <6uKz7.44318$cb.809545@atlpnn01.usenetserver.com> "Carl Banks" wrote ... > Paul Rubin wrote: > > > > But it's not just saving keystrokes--the usual place for an assigment > > in an expression is in the control expression for a while loop. > > Having to split it into several statements clutters up the code and > > makes the readability WORSE by moving the test condition away from the > > 'while' keyword. Do you REALLY find > > > > while (line := file.readline()) != 'end': > > process_line(line) > > > > to be less readable than > > > > while 1: > > line = file.readline > > if line == 'end': break > > process_line (line) > > > > (or worse, imagine several nested loops like that)? I don't. > > I do. > > I find assignment within an expression to be contrived and opaque. I > would be surprised if there were many of your opinion who weren't > numbed down to it by years of exposure to C. > Well, it isn't just C. Some readers of this list remember the Icon language, in which (unlike Python) pretty much everything was an expression: iterative constructs had as their value the value of the last expression evaluated inside, for example. In fact Icon is much more expression-oriented than C. But I don't feel "numbed" by my exposure to it... The real point here is that Python is, *by design choice*, not an expression-oriented language. I suspect this is why attempts to retrofit assignments into while seem so artificial. Until someone proposes something that seems like a natural fit with the Python we already have (which, IMHO, constructs using semicolons do not), I don't think there's enough reason to change. regards STeve -- http://www.holdenweb.com/ From rdsteph at earthlink.net Mon Oct 15 18:19:58 2001 From: rdsteph at earthlink.net (Ron Stephens) Date: Mon, 15 Oct 2001 22:19:58 GMT Subject: why no RealPython yet? References: <8827e15d.0110151158.1a1a8c36@posting.google.com> Message-ID: <3BCB6272.F0649743@earthlink.net> Wow. Chris, I have heard great things about RealBasic. But I am a Pythonista and committed to Kevin et al 's PythonCard. PythonCard is really a great project! ;-))) But I fear that the only missing piece to make PythonCard the greatest programming environment of the entire Third Millennium is a really easy to learn and use visual IDE-type envronment. Wouldn't it be cool if you were to take on that part of the PythonCard project, making sure to implement the RealBasic like functionality that you crave, but leveraging it all on top of hte PythonCard developer's hard work???? you may say I'm a dreamer... but I'm not the only one (i hope).;-))))))) RS But I fear that Chris Ryland wrote: > If you're aware of the RAD tool RealBasic for the Mac (which produces > single-file native executables for MacOS 9, X (Carbon-based) and > Win32, without source changes), I wonder if you have any thoughts of > why a similarly productive tool hasn't appeared for Mac/Win based on > Python? > > If you're not aware of RealBasic, take a look (www.realbasic.com). > It's quite impressive for what it does. > > And, yes, it's not as powerful a tool in some sense as something like > BlackAdder, but it's oh so much more approachable (which is the point > of RAD tools), and it produces all three platform binaries with one > click, which is even more the point of tools for people in the > commercial world whose targets are pretty much limited to Win32 and > MacOS 8/9 and X. > > I'm almost tempted to produce a clone based on Python... From dalke at dalkescientific.com Thu Oct 18 23:07:24 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 18 Oct 2001 21:07:24 -0600 Subject: PEP: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: <9qo63i$dpc$1@slb3.atl.mindspring.net> Huaiyu Zhu: >But then I was reminded of the examples I collected by searching for break >statements in the source distribution. Most usages are similar to > >./Demo/pdist/makechangelog.py: (final version) > while file = getnextfile(f); file: > revs = [] > while rev = getnextrev(f, file); rev: > revs.append(rev) > allrevs += revs And in that case (elsewhere in the thread) I showed that it was better rewritten using an iterator/generator style. The most succinct version is for file in getnextfile(f): allrevs.extend(getnextrev(f, file)) Where getnextfile and getnextrev need to be rewritten as generators. That's because everything of the proposed form while x = f(a); x: can be written as for x in generator_f(x): and the creation of a generator is, in 2.2, as simple as iter(f, None) or, if f takes parameters, through the use of yield. I love generators and iterators. :) Andrew dalke at dalkescientific.com From tmoero at yahoo.com Thu Oct 11 06:03:03 2001 From: tmoero at yahoo.com (tm) Date: Thu, 11 Oct 2001 19:03:03 +0900 Subject: YOU ARE ALL GAY! References: <9q2k92$2vd$1@plutonium.btinternet.com> Message-ID: Geoffrey Pointer wrote: > I realise now how saying too little can sometimes be misconstrued. > > > It's funny about that isn't it? Go figure. > > This was a comment about the psychobabble in the original message and not > its subject. Now I can see I also made a joke about the subject. Either > interpretation is fine by me. I suppose there are others I should now be > paranoid about. Again. Go figure. > hey geof, What are you mumbling about? Who are you mumbling at? Look, if you want to be taken seriously on usenet, read this- http://www.geocities.com/nnqweb/nquote.html See if that info will sink into your peabrain. If not, go mumble in some other ng. Thanks, TM From gward at mems-exchange.org Wed Oct 17 17:24:35 2001 From: gward at mems-exchange.org (Greg Ward) Date: Wed, 17 Oct 2001 17:24:35 -0400 Subject: Termcap/terminfo for Python? In-Reply-To: <20011017233128.E20564@phd.pp.ru> References: <20011017150338.A4991@mems-exchange.org> <20011017233128.E20564@phd.pp.ru> Message-ID: <20011017172435.A5370@mems-exchange.org> On 17 October 2001, Oleg Broytmann said: > curses.tigetflag > curses.tigetnum > curses.tigetstr Ahh, thank you. > I don't know which attributes describe width/height of a terminal. For the record: curses.tigetnum("cols") curses.tigetnum("lines") Greg -- Greg Ward - software developer gward at mems-exchange.org MEMS Exchange http://www.mems-exchange.org From sholden at holdenweb.com Wed Oct 3 08:41:13 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 3 Oct 2001 08:41:13 -0400 Subject: Assignment not the same as defining? References: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> Message-ID: "Dale Strickland-Clark" wrote in message news:a70mrt441n8h5bh0sf88rhae2q85v6g4hh at 4ax.com... > "Steve Holden" wrote: > [Dale explains failure to rebind __setattr__()] > >> > >From Python 2.0 Reference Manual, section 3.3.2: > >""" > >The following methods can be defined to customize the meaning of attribute > >access (use of, assignment to, or deletion of x.name) for class instances. > >For performance reasons, these methods are cached in the class object at > >class definition time; therefore, they cannot be changed after the class > >definition is executed. > >""" > > > >foiled-by-an-optimization-ly y'rs - steve > > Thanks Steve. What a handy chap you are to have around A pleasure. Always ready to help anyone who didn't download the manuals with their Python distribution <0.75 wink> - seriously, all I did was to look up __setattr__ in the manual! > but can I just > eject a heartfelt *BOLLOCKS* on this one? > Certainly! But never mind the bollocks, here's the Sex Pistols ... > Now I need yet another cludge. Perhaps it's one of those times when your design has wandered just a little too far up a blind alley, and you now feel constrained by something which needn't exist if you went back a little and took another, possibly only slightly different, direction. Not, you understand, that I'm saying I *know* enough about your current design to be sure on this, simply that I recognise the signs of frustration from my own experiences. To summarise (or summarize, as they say over here): a) You've got these whizzy __setattr__() methods that distinguish between persistent attributes and "ordinary" ones, applying verification to the former but not the latter. You are prepared to put up with the overhead because it makes things easier for client software to set all instance attributes in the same way. b) Your __setattr__() method is expensive/special enough that you don't really want it to be activated until after you've run the __init__ method. c) Python optimizes the snot out of __setattr__ access (along with the other magic methods) , so it won't let you do what you want to do. Over to you: either there's some other obvious solution you've failed to spot, or you will come back with other questions that will help you to *find* a better non-obvious solution. Go to it! regards Steve -- http://www.holdenweb.com/ From loredo at astro.cornell.edu Thu Oct 11 14:43:09 2001 From: loredo at astro.cornell.edu (Tom Loredo) Date: Thu, 11 Oct 2001 14:43:09 -0400 Subject: Compiling PIL 1.1.2 with Python-2.1.1 on Solaris References: <3BC5A46A.8D85ED8E@channing.harvard.edu> Message-ID: <3BC5E83D.94784D06@astro.cornell.edu> Hi Ross- If you do a Google search in this group for "Solaris" I bet you'll find several posts about this problem! Before running "make" in step 4 of the PIL instructions, edit the Makefile and add "-fPIC" to OPT. I believe another option is to change the load command (to "ld -g" or something like that), but the -fPIC option above I'm told is preferred because it saves memory (the library is loaded only once even if it is used by multiple processes). Several Python extensions have this problem; I would think this is something that distutils should take care of automatically. Unfortunately I don't understand the problem (or distutils) well enough to try to fix it with confidence. I kept fairly good notes when I installed Python 2.1 regarding what I had to do to get about a dozen 3rd party extensions to work under Solaris. Drop me a line if you'd like a copy of those notes. Peace, Tom Loredo From gmcm at hypernet.com Wed Oct 10 08:47:11 2001 From: gmcm at hypernet.com (Gordon McMillan) Date: 10 Oct 2001 12:47:11 GMT Subject: LIKE missing in gadfly References: <2c71728a.0110100343.75dd89eb@posting.google.com> Message-ID: Christophe Delarue wrote: > I make through a gfclient/gfserve a query resulting of a wilde result. > > Right now, I reduce this result on the client side by using a regexp > on a > special field. How could this be done on the server side ? [snip] > I'd like something : > > SELECT name FROM fellows WHERE name LIKE > NAME.match(re.compile("[A-Z]{2}'[A-Za-z]+")) Even if gadfly implemented LIKE, it wouldn't suit your needs, because "... name LIKE 'AB' ..." is just shorhand for (roughly) "... name >= 'AB' and name < 'AC' ... ". - Gordon From jjl at pobox.com Sun Oct 28 13:11:48 2001 From: jjl at pobox.com (John J. Lee) Date: Sun, 28 Oct 2001 18:11:48 +0000 Subject: Question: Event driven programming In-Reply-To: References: <3bdad71d$1_3@corp-goliath.newsgroups.com> <3BBC7.3002$Z_1.506578@newsc.telia.net> <3bdb0140_5@corp-goliath.newsgroups.com> Message-ID: > > "K?roly Ladv?nszky" wrote in > > news:3bdb0140_5 at corp-goliath.newsgroups.com: > > > > > What I have in my mind is not necessarily UI related. In VB, objects > > > can raise events, objects interested in the events will handle them. > > > Thats a very simple mechanism, facilitates easy coding in many > > > situations, even if its just a console application with no GUI at all. > > > They are similar to exceptions but they return to the caller and they > > > can have parameters/return values of any kind. [...] In addition to all the other 'same things' that people have mentioned, this sounds to me like Qt's (and PyQt's, of course) signal/slot mechanism. (Qt is a nice GUI framework, see http://www.trolltech.com/) John From brian at rk-speed-rugby.dk Tue Oct 30 08:56:45 2001 From: brian at rk-speed-rugby.dk (Brian Elmegaard) Date: 30 Oct 2001 14:56:45 +0100 Subject: tkinter - tkFileDialog - how to get dir instead of file References: Message-ID: Ulrich Goertz writes: > > to get this from the standard module "tkFileDialog". huh! tkFileDialog, that's interesting. I have read the life preserver, Fredrik introduction, and the New Mexico reference, and I have never found this mentioned before. I have been thinking and thinking, how to make one. Now it seems it is a standard widget, but just undocumented. Is this the case? Are there more super widgets I do not know after reading the above mentioned? TIA, -- Brian (remove the sport for mail) http://www.rk-speed.dk http://fiduso.dk http://sunsite.auc.dk/dk-tug \TeX, tak. From jjl at pobox.com Sun Oct 28 12:59:16 2001 From: jjl at pobox.com (John J. Lee) Date: Sun, 28 Oct 2001 17:59:16 +0000 Subject: Why doesn't this simle DCurry-like implementation work? In-Reply-To: References: Message-ID: On Sun, 28 Oct 2001, Michael R. Head wrote: > On Sun, Oct 28, 2001 at 09:57:01AM -0500, python-list-request at python.org wrote: [...] > You are right. That's what I get for posting while drunk. I meant: > > # this doesn't work... > def curry(f, p): > return lambda x: f(p, x) > > however, now I know that this does work, and does what I want: > > def curry(f, p): > return lambda x, ff=f, pp=p: ff(pp,x) and the simpler (lambda x: f(p, x)) version will work under Python 2.1 with from __future__ import nested_scopes Or under 2.2, with no import required, IIRC. John From rharkins at thinkronize.com Tue Oct 23 16:24:31 2001 From: rharkins at thinkronize.com (Rich Harkins) Date: Tue, 23 Oct 2001 16:24:31 -0400 Subject: POLL in different OSes In-Reply-To: Message-ID: If not a true poll emulator, I would like to see a C overlay on select that would handle C-level selectable objects that would have flags on the objects managed by C. This would mean that I wouldn't have to feed Pyhton lists to select nor make select return three (possibly brand-spankin' new) lists as a result. The way it would work in my twisted little universe is something like this: Create the polled objects... >>> obj1=makepolled(fd1) >>> obj2=makepolled(fd2) Create the poller and add the polled... >>> poller=makepoller() >>> poller.addpolled(obj1) >>> poller.addpolled(obj2) Enable the events I want to know about... >>> obj1.enable(PL_READ) >>> obj2.enable(PL_WRITE) Poll 'em... >>> poller.poll() Test the result... >>> if obj1.has(PL_READ): >>> # Read from obj1 >>> if obj2.has(PL_WRITE): >>> # Write to obj2 This is more code, yes, than select but it could be implemented using either C-select or C-poll depending on OS coditions. More importantly, lists did not need to be fed to the poller nor does the poller produce new lists in its operation. This should be a big win in performance (I think) over the traditional Python select mechanism. I don't know the internals of the Python implementation layer for select but I suspect this is the case. Oh well, just wishful thinking... Rich From tim.one at home.com Thu Oct 18 23:29:48 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 18 Oct 2001 23:29:48 -0400 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: <200110180758.f9I7w4M00794@mbuna.arbhome.com.au> Message-ID: [Anthony Baxter] > ... > It [PEP 6] still doesn't cover the process of deciding what would go > in the patch release... It would help if you worked with the PEP author (Aahz) until it was clear to both of you, else it will stay muddy forver. I believe his rabid intent was "no new features!", but I agree the PEP doesn't really say that. > I know that I'd be happier upgrading to 2.1.2 than 2.2 in the next > couple of months That's wise, but mostly because 2.2 won't be released before the next couple of months is history. > - and given the peasants-are-revolting sentiment of c.l.py at the > moment, I doubt I'm the only one... A curious thing about Open Source is that demand doesn't seem to create supply, at least not in the way that casually mentioning you'd really like to get wasted-- and have some spare cash --magically attracts eager crack dealers to your front door. Satisfying this particular demand is quite doable, but The Usual Suspects aren't going to volunteer (they're overloaded without it). > How would this sound as a first cut at a what-goes-in-and-what-stays: > > a) bugfixes. Yes. > b) no new modules, no new packages. Ruled out via "no new features". > c) no new methods on classes, unless they're bugfixes. Ditto. > d) if the bug fix relies on some 2.2-ism, then it's either rewritten, > or ignored and relnoted Sure. Note that a discusssion of which 2.1.1 bugs count as critical is current on Python-Dev. If you're comfortable enough with CVS to manage the mechanics of working on a branch, the developers will give you all the advice you can stomach. From sholden at holdenweb.com Tue Oct 16 13:40:18 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 16 Oct 2001 13:40:18 -0400 Subject: newbie printing question References: <9qg0l9$5hp$1@slb3.atl.mindspring.net> <9qgoed$1l60$1@mail1.wg.waii.com> <9qhdpm$ibl$1@slb7.atl.mindspring.net> Message-ID: wrote in message news:9qhdpm$ibl$1 at slb7.atl.mindspring.net... > this is the catch: > > TimeNow=mxDateTime.now() > > TimeNow is a DateTime object, not a string. > [... original "how do I get a string containing mx.DateTime's now() method's result? ...] >>> import mx.DateTime as mxdt >>> now = str(mxdt.now()) >>> print now, type(now) 2001-10-16 13:35:30.91 >>> Of course, you could just as easily store the DateTime value, and use it's str() method when you needed the string: that way you could use all its other methods and attributes as well! >>> now = mxdt.now() >>> now.calendar 'Gregorian' >>> now.abstime 49124.919999957085 >>> now.tuple() (2001, 10, 16, 13, 38, 44.919999957084656, 1, 289, 1) >>> str(now) '2001-10-16 13:38:44.91' >>> regards Steve -- http://www.holdenweb.com/ From sorr at rightnow.com Tue Oct 9 17:16:37 2001 From: sorr at rightnow.com (Orr, Steve) Date: Tue, 9 Oct 2001 15:16:37 -0600 Subject: Spewing SQL query resultset to HTML table... Message-ID: Newbie's first post... New Project... should I use Python or PHP? I need to take ANY valid SQL query and display the resultset in HTML. KEY QUESTION: How do I capture the column aliases and display them as headers in an HTML table? I have over 100 SQL queries and I just want to use one simple routine to display results. I don't want reams of hand code just for output. I've already done this with PHP but I can't find a way to do it in Python. I'm assuming it's because of my Python newbie status and not because PHP is more capable. BY WAY OF EXAMPLE... here's how this was accomplished in PHP: -------------------------------- \n"; while (list($key,$val)=each(&$results)){print "";} print "\n"; // Now print the resultset... for ( $i = 0; $i < $nrows; $i++ ) { reset(&$results); print "\n"; while ( $column = each(&$results) ) { $data=$column['value']; $datum=$data[$i]; if (is_numeric($datum)) {//format based on string or numeric value... settype($datum,"double"); $datum=number_format($datum); print "\n"; }// end if else print "\n"; }// end while print "\n"; }// end for print "
$key
$datum$datum
\n"; ?> -------------------------------- Not too bad for just a few lines of code. In my first pass at this project I was able to learn PHP and achieve spectacular results in 2 weeks. As a proof of concept that Python can do this just as easily I want to replicate what I've already done in PHP. Then I can make an informed decision about PHP vs Python. I'm an Oracle DBA about to develop a large database admin toolset. I've had significant OOP experience in a "prior life" and now I'm getting back into the development mode and need to match the language and tools with the requirements. Formal Spec: With ANY valid SQL query, render output to an HTML table. Labels for the HTML column headers should come from the SQL statement. Must be able to format differently for strings and numbers with strings being left aligned and numbers formatted with commas and right aligned. Must be able to handle result sets with any varying number of columns and up to 10,000 rows. This is for an Oracle database administration app so the feature set for the database API should be richly Oracle-specific (e.g. a complete implementation of Oracle's OCI.) Other RDBMS connectivity not needed! AtDhVaAnNkCsE, Steve Orr, Veteran Oracle DBA and Python Newbie From dalke at dalkescientific.com Wed Oct 17 03:22:39 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 17 Oct 2001 01:22:39 -0600 Subject: Library function for sorting References: <9qip39$6do$1@nserve1.acs.ucalgary.ca> Message-ID: <9qjbnm$7k7$1@slb7.atl.mindspring.net> Michael Yuen wrote: >I'm ... wondering if there's a >library function for sorting strings. I sure there is one but haven't >been able to find one when I looked through the documentation. In addition to the other responses you've had, you might want to read my (admittedly small) contribution to the Python documentation. http://py-howto.sourceforge.net/sorting/sorting.html Andrew dalke at dalkescientific.com From gnb at itga.com.au Tue Oct 23 23:59:59 2001 From: gnb at itga.com.au (Gregory Bond) Date: 24 Oct 2001 13:59:59 +1000 Subject: readlines() on a socket Message-ID: <86lmi1r8lc.fsf@hellcat.itga.com.au> I'd like to be able to do s = socket.socket(...) s = socket.connect(....) for l in s.readlines(): # process line l but sockets don't support readline(), or readlines(), or anything similar that I can see. Is there away to do this that doesn't involve manually calling split on the results of s.recv() and worrying about whole lines split across recv() calls? From sill at optonline.net Wed Oct 3 19:21:34 2001 From: sill at optonline.net (Andrei Kulakov) Date: Wed, 03 Oct 2001 23:21:34 GMT Subject: test - don't read... References: <3bb9e35a.695404@news.newsguy.com> <3bbc8d9d.375457@news.newsguy.com> Message-ID: On Wed, 03 Oct 2001 05:27:18 GMT, Owen F. Ransen wrote: > On Tue, 2 Oct 2001 10:15:56 -0700, Cliff Wells > wrote: > >>On Tuesday 02 October 2001 09:19, Owen F. Ransen wrote: >>> don't read >> >>Aarrrgh. Too late. > > NOOOOOOOOOOOOO! > > ;) You *knew* this would happen.. and you posted anyway. Have you no heart? > > > > -- > Owen F. Ransen > http://www.ransen.com/ > Home of Gliftic & Repligator Image Generators -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From mwh at python.net Wed Oct 31 04:57:13 2001 From: mwh at python.net (Michael Hudson) Date: Wed, 31 Oct 2001 09:57:13 GMT Subject: Sorting (not Python-specific) References: Message-ID: Marcin 'Qrczak' Kowalczyk writes: > What are advantages and disadvantages in parametrizing sorting > either by '<' or by the 3-way comparison? I'm not *quite* sure what you mean, but if you're asking why list.sort only relies on x; from romany@actimize.com on Sun, Oct 28, 2001 at 08:41:26PM +0200 References: <7647A9F4B298E74DB6793865DA67285004AC66@exchange.adrembi.com> Message-ID: <20011028185418.C1066@lilith.hqd-internal> On Sun, Oct 28, 2001 at 08:41:26PM +0200, Roman Yakovenko wrote: > Hi. Where can I get a help ( I mean files or other material ) on > Tkinter as python module. You can try this page from the creator(s) of Tkinter: http://www.pythonware.com/products/tkinter/index.htm Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From no at spam.invalid Thu Oct 11 04:34:32 2001 From: no at spam.invalid (Simo Salminen) Date: Thu, 11 Oct 2001 08:34:32 +0000 (UTC) Subject: upload file using cgi on Win2k IIS References: Message-ID: * Jason McWilliams [Wed, 10 Oct 2001 16:52:03 -0600] > problem, > no matter what the size. Things die when trying to upload .gif or .zip > or .tgz > or other binaries similar. Some of it gets uploaded, but only a small > portion? > I had exactly the same problem with OmniHTTPD/w2k. When I moved the script to apache/linux, problem disappeared. -- simo salminen iki fi From tmoero at yahoo.invalid Fri Oct 12 01:48:34 2001 From: tmoero at yahoo.invalid (tm) Date: Fri, 12 Oct 2001 14:48:34 +0900 Subject: YOU ARE ALL GAY! References: Message-ID: Geoffrey Pointer wrote: > tm said: > > > hey geof, > > What are you mumbling about? > > Who are you mumbling at? > > Look, if you want to be taken seriously on usenet, read this- > > http://www.geocities.com/nnqweb/nquote.html > > > > See if that info will sink into your peabrain. If not, go mumble in some > > other ng. > > Thanks, > > TM > > Okay. My message subject was > > Subject: Re: YOU ARE ALL GAY! > > So my pea brain tells me I was commenting on > > Subject: YOU ARE ALL GAY! > > Which is still current round and about. > > If _you_ want to be taken seriously maybe you should take your finger off > your hair trigger and lay your gun to rest somewhere more suitable. > Much better geof, you left the attributes this time. Shows you are capable of learning. You could use some help with snipping, but keep up the good work. Say, would you like to learn how to make a proper sig delimiter? From asgard at hellnet.cz Thu Oct 4 13:59:23 2001 From: asgard at hellnet.cz (Jan Samohyl) Date: Thu, 4 Oct 2001 19:59:23 +0200 Subject: Past command buffer gone in interpreter? In-Reply-To: References: <9uIu7.590021$NK1.53791925@bin3.nnrp.aus1.giganews.com> Message-ID: <20011004195922.A5312@blackbox.hell> A friend of mine has a similar problem, cursor keys that stop working within the interactive mode. He tried python2.2a3 on both redhat 7.0 and 7.1 and on debian. Also, the strangiest thing is that in one case it worked only for root. He said it _was_ compiled with readline. I am using the same version redhat 6.1 and everything ok. Regards Jan Samohyl From lac at strakt.com Mon Oct 1 08:52:24 2001 From: lac at strakt.com (Laura Creighton) Date: Mon, 01 Oct 2001 14:52:24 +0200 Subject: Tkinter Questions In-Reply-To: Your message of "Mon, 01 Oct 2001 11:23:05 -0000." <9p9jmp+pnq7@eGroups.com> References: <9p9jmp+pnq7@eGroups.com> Message-ID: <200110011252.f91CqOEv021706@ratthing-b246.strakt.com> After sending Janos Blazi some mail I have found out that he doesn't have any suitable images and would like some. Since I think he is trying to make a CD player ... anybody got some suitable images for forward, back, fastforward and the like that you could point him to? I don't have any good ones either. Laura Creighton From thomas.heller at ion-tof.com Thu Oct 25 07:37:33 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 25 Oct 2001 13:37:33 +0200 Subject: wierd win32all gui problem (w/56lines of code) References: Message-ID: <9r8thu$s1k0a$1@ID-59885.news.dfncis.de> "Neil Hodgson" wrote in message news:XLRB7.225335$bY5.977767 at news-server.bigpond.net.au... > Jeffrey Drake: > > Using ActivePython 2.1 and win32all I have written a simple app that > creates > > a window and exits when closed. However the python interpreter is still > > running. It hangs a command prompt under win2k until I physically kill the > > python process. I would appreciate any help possible. > > The WndProc isn't called at all. Add some prints or message boxes in the > code and you'll see the WndProc is ignored. > > Neil > IIRC you have to pass the return value of the RegisterClass() call (which is an atom) to the CreateWindowEx() function as the second parameter (lpClassName). Thomas From max at alcyone.com Tue Oct 9 13:37:06 2001 From: max at alcyone.com (Erik Max Francis) Date: Tue, 09 Oct 2001 10:37:06 -0700 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <6qk7y4ohrf.fsf@abnoba.intevation.de> Message-ID: <3BC335C2.C7C6EFF2@alcyone.com> Bernhard Herzog wrote: > IMO something like > > >>> map(1 .__add__, [0, 5, 7, 2]) > [1, 6, 8, 3] > >>> > > can come in handy. Of course this particular example may be clearer > with > list comprehensions. Or just a lambda: lambda(lambda x: x + 1, [0, 5, 7, 2]) I'd call that a lot more readable. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ The purpose of man's life is not happiness but worthiness. \__/ Felix Adler The laws list / http://www.alcyone.com/max/physics/laws/ Laws, rules, principles, effects, paradoxes, etc. in physics. From coolslife at yahoo.com Thu Oct 11 18:16:07 2001 From: coolslife at yahoo.com (coolslife) Date: 11 Oct 2001 15:16:07 -0700 Subject: Length on an input parameter in python References: Message-ID: Oleg Broytmann wrote in message news:... > On Thu, Oct 11, 2001 at 08:51:31AM -0700, coolslife wrote: > > It looks like the length of an input parameter (taken from the command > > line atleast) is limited to 256 characters. > > Windows? > > Oleg. > ---- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. Nope, Unix, 2.6 From skip at pobox.com Thu Oct 18 13:19:14 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 18 Oct 2001 12:19:14 -0500 Subject: Random from Dictionary In-Reply-To: References: <4f7234de.0110180504.20aa475b@posting.google.com> <9qml3o$ovl8k$1@ID-11957.news.dfncis.de> <181020010938443703%tpayne@mac.com> <9qmoft$p7mln$1@ID-11957.news.dfncis.de> Message-ID: <15311.3858.587746.114216@beluga.mojam.com> Martin> Python 2.1.1 (#1, Jul 21 2001, 20:59:12) Martin> [GCC 2.95.2 19991024 (release)] on sunos5 Martin> Type "copyright", "credits" or "license" for more information. >>>> x={'Hallo':'Welt'} >>>> import random >>>> random.choice(x) Martin> Traceback (most recent call last): Martin> File "", line 1, in ? Martin> File "/usr/local/lib/python2.1/random.py", line 329, in choice Martin> return seq[int(self.random() * len(seq))] Martin> KeyError: 0 Perhaps I'm coming in on this thread a bit late (don't remember seeing it and can't find it at Google Groups, however, so maybe it just hasn't fully propagated around), but I see nothing in the doc string for random.choice that suggests it should work with a dictionary. Where's the bug? -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From rikard at strakt.com Mon Oct 22 10:15:35 2001 From: rikard at strakt.com (Rikard Bosnjakovic) Date: Mon, 22 Oct 2001 16:15:35 +0200 Subject: Array of 2^n References: <9qvbat$kak$1@news-int.gatech.edu> Message-ID: <3BD42A07.1050505@strakt.com> Moshe wrote: >>l = [2**i for i in range(10)] > > I definitely like this way more than the lambda way, because it is far > more readable. Plus; lambdas exist in Python <2.0, list comprehensions don't. (Yes, there *are* people using 1.5.x still) -- Cheers, ------------------------------------------------------------------------ Rikard Bosnjakovic http://bos.hack.org/cv/ Python Hacker rikard at strakt.com AB Strakt bos at hack.org From fredrik at pythonware.com Sat Oct 27 07:29:58 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 27 Oct 2001 11:29:58 GMT Subject: Import Errors References: Message-ID: Thomas M. Hermann wrote: > At the python command prompt, I import sys and type 'sys.path'. > The personal site-packages directory is in 'sys.path', but if an > attempt is made to import a module from the directory, it fails. running the interpreter with the -vv flag may help you figure out what's going on. From chrishbarker at home.net Wed Oct 3 15:50:47 2001 From: chrishbarker at home.net (Chris Barker) Date: Wed, 03 Oct 2001 12:50:47 -0700 Subject: newbie str to int References: <9pbetr$jp83@imsp212.netvigator.com> <3BB9F67F.29D077D2@home.net> Message-ID: <3BBB6C17.5937004E@home.net> Nomad wrote: > >what when wrong here? well, depending on what font you are using, timay > >be obvious: that last character is the letter, "oh" not the number, > >zero. I am very glad that Python chatches this kin do f very non obvious > >typo fpr me: what did the person typing that string in mean??? > > > It is a shame that your newsreader doesn't catch typo's for you > Yes, it is obvious from my message why typos are such a concern for me! -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From fredrik at pythonware.com Sat Oct 27 12:46:02 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 27 Oct 2001 16:46:02 GMT Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> <3bdad7e6_3@corp-goliath.newsgroups.com> Message-ID: K?roly Ladv?nszky wrote: > What is Stackless Python? http://www.stackless.com/ (also see http://www.google.com) From pez at apocalyptech.com Mon Oct 15 20:56:17 2001 From: pez at apocalyptech.com (CJ Kucera) Date: Mon, 15 Oct 2001 19:56:17 -0500 (CDT) Subject: maximum recursion in "re" module? Message-ID: <200110160056.TAA20412@scortch.unisrv.net> Greetings, list! I'm having a problem using the "re" module that's got me somewhat boggled. I'm using Python to automate downloading of bands off of mp3.com. What you do is pass a band's URL in to the program, and it'll download all the songs available by that artist. I have this all working on my box at work, which is still running Python 1.5.2, but when I'm trying it out at home, using Python 2.1, it dies, saying "RuntimeError: maximum recursion limit exceeded." If it did this consistently, I wouldn't mind, but it seems to only happen for certain bands. I'm rather stumped. When I strip out everything unnecessary from the program, you end up with this: #!/usr/bin/env python import urllib, re, string, sys if (len(sys.argv) == 2): # Regular Expressions startString = ".*?Lo Fi Play
pez at arrakis:~/bin$ ./temp.py http://artists.mp3s.com/artists/33/android_lust.html > Whee! I made it through! But when I try another band: > pez at arrakis:~/bin$ ./temp.py http://artists.mp3s.com/artists/103/this_ascension.html > Traceback (most recent call last): > File "./temp.py", line 11, in ? > mp3String = re.compile(startString, re.I).sub("", mp3String, 1) > File "/usr/local/lib/python2.1/sre.py", line 164, in _sub > return _subn(pattern, template, string, count)[0] > File "/usr/local/lib/python2.1/sre.py", line 179, in _subn > m = c.search() > RuntimeError: maximum recursion limit exceeded So what gives? Is there a size limit for the string? The first band returns about 50k of HTML, whereas the second returns 80k, but since this works fine for Python 1.5.2 I'd expect it to work for 2.1 . . . I also checked manually to make sure that the string I'm searching for exists in both pages, and it does. So anyway, if someone could help me out here, I'd really appreciate it. Thanks much! -CJ WOW: Rapacious | A priest advised Voltaire on his death bed to apocalyptech.com/wow | renounce the devil. Replied Voltaire, "This pez at apocalyptech.com | is no time to make new enemies." From stuart at bmsi.com Fri Oct 12 11:34:25 2001 From: stuart at bmsi.com (Stuart D. Gathman) Date: Fri, 12 Oct 2001 11:34:25 -0400 Subject: Semantic indentation (OpenGL) References: Message-ID: <9q72i2$3ne$1@nntp2-cm.news.eni.net> In article , "Marek Kro??k" wrote: > glBegin(GL_POINTS); > ... > glVertex3f(...); > ... > glEnd(); glBegin(GL_POINTS) try: ... glVertex3f(...) ... finally: glEnd() -- 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 ykingma at accessforall.nl Sat Oct 13 16:45:52 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Sat, 13 Oct 2001 21:45:52 +0100 Subject: How to handle sys.path in bigger projects? References: <226dstkol613p95ampm7libas5tp6t0a3b@4ax.com> <56jdstkoro0ddkq3eead1fuoe3m20ilikf@4ax.com> Message-ID: <3BC8A7F5.C2617A7@accessforall.nl> Georg, you wrote: > > On 12 Oct 2001 11:52:30 +0200, Martin von Loewis > wrote: > > >Georg Lohrer writes: > > > >> What are your ways of handling? > > > >If you are relying on a lot of third-party packages, I'd require that > >those packages get properly installed, ie. into site-packages or > >site-python. Then you only need to find your own code. > > I'm only bothered by my own code :-) > > > > >If that grows in size, organizing it into multiple packages seems to > >be appropriate. I then see no problem in keeping all these packages in > >a single directory. > > Ok. Let's have a look on it: > > 1) actual dir contains directory: "myproject" with its __init__.py > importing myproject.foo1 and myproject.foo2 What is the point of these imports in an __init__.py file? > 2) two sub-packages (directories) called "foo1" and "foo2" with each > containing a __init__.py are within "myproject" > 3) foo1 contains foo1foo.py; foo2 contains foo2foo.py > 4) foo2foo.py has a intra-package reference to foo1foo.py: > import myproject.foo1.foo1foo > > Running from parent-dir of "myproject" > > ~user> python > >>> from myproject.foo1 import foo1foo > >>> > > runs successfully. But if I want to test the foo1foo.py module itself, > following the path to myproject/foo1: > > ~user/myproject/foo1> python > >>> import foo1foo > *** ImportError: No module named myproject.foo2 I suppose foo1foo.py contains sth like from myproject.foo2 import whatever causing the error message. Your problem is that the current directory is always the first thing on sys.path. Running from ~user everything is fine, because that happens to be your "project home". Running from ~user/myproject/foo1 the directory ~user is not on sys.path causing your problem. > > So, the only way that seems to work is to start debugging from most > upper directory, if there are intra-package references? Is that > correct? Or how do you handle this? You might start by making sure that ~user/myproject is always on sys.path when you invoke python. This will allow you to get rid of the myproject package altogether. One way to do this is by using a small script that checks the current directory and when it is not ~user/myproject it adds it to the PYTHONPATH environment variable before invoking python. You might also set it in your shell's .*rc file. The above two suggestions are independent: you might also keep myproject and make sure ~user is on PYTHONPATH when invoking python. Good luck, Ype -- email at xs4all.nl From d_blade8 at hotmail.com Wed Oct 31 15:41:56 2001 From: d_blade8 at hotmail.com (L3m Ni$cAt3) Date: Wed, 31 Oct 2001 20:41:56 +0000 Subject: MS Excel 'Comment' Interface Message-ID: Hi all? I've been piecing together a Python prog to use at work for the past few weeks (to speed up some of my time-consuming 'find on the web then plug into Excel" busy-work). The kind of prog that needs new features added to it every other day or so. So far it has gone pretty well, except I have seemed to have reached a sticking point. I would like to be able to enter MS Excel "Comments" (you know, right-click, then insert comment; it differs from whatever is actually in the cell). I can't seem to figure it out. I've looked through all the win32all documentation and I think I just don't know what kind of interface to look for. Dispatch lets me read and write to specific columns and all that, but I just can't seem to find what I need. If you know how, could you just show me with a simple example, my actual comments are going to come from various sources (net, files, generated by the python prog itself) and I figure all that out easily enough, I just need some kind of starting point. Thanks, I appreciate it. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp From phd at phd.pp.ru Fri Oct 12 10:23:15 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 12 Oct 2001 18:23:15 +0400 Subject: multi command session through a socket In-Reply-To: <3SCx7.28787$I83.421328@atlpnn01.usenetserver.com>; from sholden@holdenweb.com on Fri, Oct 12, 2001 at 10:14:45AM -0400 References: <77udstcmaialm2920c7svj4eap6k9f25d4@4ax.com> <3SCx7.28787$I83.421328@atlpnn01.usenetserver.com> Message-ID: <20011012182315.D16906@phd.pp.ru> On Fri, Oct 12, 2001 at 10:14:45AM -0400, Steve Holden wrote: > Consider Tim O'Malley's timeoutsocket module. Can't currently find Tim's http://www.timo-tasi.org/python/ > original URL, but the copy at > > http://www.fiction.net/blong/programs/python/timeoutsocket.py > > looks reasonably up to date. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From rharkins at thinkronize.com Thu Oct 18 17:50:18 2001 From: rharkins at thinkronize.com (Rich Harkins) Date: Thu, 18 Oct 2001 17:50:18 -0400 Subject: PEP: statements in control structures In-Reply-To: <15311.19856.515994.225805@beluga.mojam.com> Message-ID: Skip Montanaro (skip at pobox.com): > > Rich> Or perhaps along that same vein... > Rich> while line from file.readline(): > Rich> ... > > Python 2.2 with iterator support already supports > > for line in file: > ... > True indeed. I was (weakly) suggesting "from" as an alternative to the assignement opperator but not wanting too much to end up mired in *that* boondoggle. :) Rich (now diving for cover in a bomb shelter) :) From xavier at perceval.net Wed Oct 31 06:03:16 2001 From: xavier at perceval.net (Xavier Defrang) Date: Wed, 31 Oct 2001 12:03:16 +0100 (CET) Subject: Python.NET, MONO and Visual Studio etc. In-Reply-To: Message-ID: On Sun, 28 Oct 2001, Jeffrey Drake wrote: > Just wanted to make sure you know the difference between Visual Python and > Python.Net. > Visual Python is regular python in vs.net ide, and Python.net is actual CLR. > > "Ron Stephens" wrote in message > news:3BDC5777.3873D22A at earthlink.net... > > A while back there was a discussion here about a possible Python.Net and > > related matters. I would still like to know if there is any recent > > information. Below is my perhaps faulty understanding of what's going > > on. I hope maybe others can correct and add to my comments. > > (...) This is almost off-topic but since you guys are talking about that .NET thing, I'd like just to ask anyone in here : WHAT THE HELL IS .NET??? I don't want any fancy buzzwords or corpspeak crap. I just want a clear, step-by-step explanation of what it is and what should I believe it's the revolution MS claim it is. Why are people investing bucks in developping .NET software when nobody can clearly see what it is. I'm surrounded by skilled web and software architects and absolutely none of them has a clear idea about this "next generation" framework/platform/strategy/initiative. For me, .NET just looks like a new branding strategy for all MS development product line. What's .NET but a mix of buzzwords and the deployment of big brotherish SOAP-enabled services? Any explanation of link to valuable online resource are more than welcome... Regards, Xavier From geiseri at yahoo.com Tue Oct 23 09:02:11 2001 From: geiseri at yahoo.com (ian reinhart geiser) Date: Tue, 23 Oct 2001 09:02:11 -0400 Subject: Embedding and Extending Issue Message-ID: <200110231301.JAA10134@generic2.axs2000.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Greetings I have started adding the ability to script my application via python. I have followed the Extending and Embedding docs and the demo.c code. This has me with a very impressive setup so far, but now I have an issue. I used SIP to create bindings to my entire C++ application, so now I have access to all of the datatypes that my application supports. So I can bar *foo = new bar(); in C++ and I can foo = bar() in python. The problem is I would like to be able to access my foo object that was created in C++ from python. I am lost though on how to convince Python it knows about this data type. I currently have the following code: /// Setup python env here bar->setFoo(42); cout << "Foo: " << bar->getFoo() << endl; PyObject *PyBar = Py_BuildValue("O&",convertBar ,&bar); PyObject *ldic = Py_BuildValue("{s:O,s:{}}", "bar", PyBar ,"res"); char *copy_code ="import sys\n"\ "from foo import *\n"\ "print \"Starting...\"\n"\ "bar.setFoo(100)\n"; if ( !PyRun_String(copy_code, Py_file_input, gdic, ldic) ) PyErr_Print(); cout << "Foo: " << bar->getFoo() << endl; /// Clean up here The idea is that the output should be: Foo: 42 Starting... Foo: 100 My issue is I am confused as what convertBar() should be. The docs are very light on this issue. I am hopeing this should be quite trivial because python all ready knows about this data type. Also if this is the wrong place/way to do this please let me know. My project is very excited to have python take a greater role in its vision :) Thanks - -ian reinhart geiser - -- ======================================== Unix is a Registered Bell of AT&T Trademark Laboratories. -- Donn Seeley ======================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE71WpYPy62TRm8dvgRAp+JAKCXsfjskdNs1L+Kqlf4MXG0g4GAiwCgx67T PlyBumE7Q5W78i7OPID8D8w= =lhrE -----END PGP SIGNATURE----- From aa at bb.cc Thu Oct 25 18:32:53 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Fri, 26 Oct 2001 00:32:53 +0200 Subject: Question: Dynamic code import References: Message-ID: <3bd88de8_2@corp-goliath.newsgroups.com> Being really new in the Pyhton world, I'm not sure what else than text files (.py) could come into view. To put it simple, I'd like to have a def f11(a) in a file and read it in and use f11 like the functions in the running script. Its something else than using 'import' as the file may not be existent at all when the script starts running. In Lisp, the 'load' function does this. "Bjorn Pettersen" az al?bbiakat ?rta a k?vetkezo ?zenetben: news:mailman.1004046266.4930.python-list at python.org... > From: K?roly Ladv?nszky [mailto:aa at bb.cc] > > Hi Bjorn, > > Thanks for your quick answer. Yes, I was mistaken with the > global directive. It's clear now. Regarding the first > question, it works fine with the interpreter but I would like to read > f11(a) from somewhere else, most likely from a file. Hmmm... Not quite sure what you mean. Is it in a Python file, a text file, ?? If it's in a Python file you can just import the module and assign to the variable as before, if it's in a text file you'd need to use eval or exec. Let us know which it is and I'm sure we could come up with examples... :-) -- bjorn ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From cbiegay at objectmentor.com Thu Oct 25 15:49:59 2001 From: cbiegay at objectmentor.com (Chris) Date: Thu, 25 Oct 2001 19:49:59 GMT Subject: Zope and SSL Message-ID: <3bd86c51.85993612@news.supernews.com> Hello, I am trying to incorporate openssl into my Zope webserver using M2crypto, and I am attempting to use an existing signed certificate given to me by Verisign. When I go to my website using SSL, however, the server certificate I am presented with is issued by "M2Crypto Certificate Master", and so I get a warning saying that the Certificate Authority is not trusted. How do I tell the server that the certificate was signed by Verisign? Thanks. From mel.b at mindspring.com Mon Oct 8 00:40:24 2001 From: mel.b at mindspring.com (Mel Brown) Date: Sun, 7 Oct 2001 21:40:24 -0700 Subject: Newbie Question References: <9pp1ca$ca6$1@slb4.atl.mindspring.net> <3BC00E3B.27017561@alcyone.com> Message-ID: <9praqc$vni$2@slb5.atl.mindspring.net> "Erik Max Francis" wrote in message > > I am trying to get Python up and running. Among the modules that I > > know that > > I will need are math, cmath, and string. > > So import them: > > import math > import cmath > import string Not quite. As I said, I *did* import math, then tried to run sin(3), as an example. A message came up that said that sin was an unknown variable. It wouldn't even recognize it as a function, much less evaluate it with its intended argument. And that is what prompted my question. Fortunately others have read my question more carefully and supplied me with useful answers. Thanks anyway. From kseehof at neuralintegrator.com Tue Oct 23 20:10:19 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Tue, 23 Oct 2001 17:10:19 -0700 Subject: None References: <3bd5db1e$1@brateggebdc5.br-automation.co.at> Message-ID: <009901c15c20$45539920$8d4bb43f@kens> > Hi, > > just had to try that out... > > >>> print None > None > >>> None = 17 > >>> print None > 17 > >>> > > Strange... is it intended that you can assign to None? > > In short, is this a bug or a feature? > > thanks > Werner When you understand why this is exactly what you would expect, your understand of python will jump to the next level :-). 'None' is a name, not a keyword. Assigning to None simply attaches a new object to the name 'None'. So it's not as scary as it looks. You are not changing the value of an internal variable as you might expect. In other languages such as C/C++ (which have early binding), assignment causes data stored in a variable to change. In python (and other languages with late binding), assignment binds a name to some data without changing the data that the name used to refer to. This is probably the most important concept for python programmers to understand if they come from a C/C++ background. >>> x = None >>> print x None >>> None = 'spam!' >>> print None spam! >>> print x None Get it? - Ken From rxg218 at psu.edu Thu Oct 4 10:39:49 2001 From: rxg218 at psu.edu (Rajarshi Guha) Date: Thu, 4 Oct 2001 10:39:49 -0400 Subject: Another q regarding expat Message-ID: <9phs8j$18dc@r02n01.cac.psu.edu> I found an expat rpm and installed. However when I now enter: >>> import xml.parsers.expat /usr/lib/python2.2/pyexpat.py:85: RuntimeWarning: Python C API version mismatch for module dcpyexpat: This Python has API version 1011, module dcpyexpat has version 1010. from dcpyexpat import * >>> import SOAP >>> s = SOAP.SOAPProxy("http://services.xmethods.net/soap/servlet/rpcrouter",namespace="urn:xmethods-Temperature") Traceback (most recent call last): File "", line 1, in ? File "./SOAP.py", line 3475, in __init__ ''.encode(encoding) File "/usr/src/build/42396-i386/install/usr/lib/python2.2/encodings/__init__.py", line 31, in ? File "/usr/lib/python2.2/codecs.py", line 17, in ? raise SystemError,\ SystemError: Failed to load the builtin codecs: undefined symbol: PyUnicode_DecodeRawUnicodeEscape I get the mess above! I've noticed similar errors with other packages (especially pygtk) - how can I fix version mismatches? The second error seems more involved? I have expat installed - am I missing any extra files? Any help would be appreciated! TIA -- ----------------------------------------------------------------- Rajarshi Guha | email: rajarshi at presidency.com Dept of Chemistry | web : www.rajarshi.f2s.com Pennsylvania State University | ph : (814) 863 1222 ----------------------------------------------------------------- Build a system that even a fool can use and only a fool will want to use it. From tszeto at mindspring.com Wed Oct 17 14:48:25 2001 From: tszeto at mindspring.com (tszeto) Date: Wed, 17 Oct 2001 11:48:25 -0700 Subject: Good books on Image Processing? Message-ID: <9qkjri$6u9$1@nntp9.atl.mindspring.net> Hello, Was wondering if someone could suggest some books on image processing? Basically, I'd like to figure out how ImageMagick works (how to open and manipulate images stored in different file formats). Any help appreciated. Regards, Ted From GeorgLohrer at gmx.de Fri Oct 12 07:42:03 2001 From: GeorgLohrer at gmx.de (Georg Lohrer) Date: Fri, 12 Oct 2001 13:42:03 +0200 Subject: How to handle sys.path in bigger projects? References: <226dstkol613p95ampm7libas5tp6t0a3b@4ax.com> Message-ID: <56jdstkoro0ddkq3eead1fuoe3m20ilikf@4ax.com> On 12 Oct 2001 11:52:30 +0200, Martin von Loewis wrote: >Georg Lohrer writes: > >> What are your ways of handling? > >If you are relying on a lot of third-party packages, I'd require that >those packages get properly installed, ie. into site-packages or >site-python. Then you only need to find your own code. I'm only bothered by my own code :-) > >If that grows in size, organizing it into multiple packages seems to >be appropriate. I then see no problem in keeping all these packages in >a single directory. Ok. Let's have a look on it: 1) actual dir contains directory: "myproject" with its __init__.py importing myproject.foo1 and myproject.foo2 2) two sub-packages (directories) called "foo1" and "foo2" with each containing a __init__.py are within "myproject" 3) foo1 contains foo1foo.py; foo2 contains foo2foo.py 4) foo2foo.py has a intra-package reference to foo1foo.py: import myproject.foo1.foo1foo Running from parent-dir of "myproject" ~user> python >>> from myproject.foo1 import foo1foo >>> runs successfully. But if I want to test the foo1foo.py module itself, following the path to myproject/foo1: ~user/myproject/foo1> python >>> import foo1foo *** ImportError: No module named myproject.foo2 So, the only way that seems to work is to start debugging from most upper directory, if there are intra-package references? Is that correct? Or how do you handle this? Ciao, Georg From skip at pobox.com Tue Oct 16 17:36:45 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 16:36:45 -0500 Subject: Number of args in a function In-Reply-To: References: <12e3779b.0110161239.7e71bb13@posting.google.com> Message-ID: <15308.43117.782231.203607@beluga.mojam.com> >>>>> foo.func_code.co_nlocals >> 5 >>>>> foo.func_code.co_varnames >> ('a', 'b', 'c', 'args', 'kwds') Kragen> co_nlocals isn't right; Mark asked for co_argcount: My apologies. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From phr-n2001d at nightsong.com Tue Oct 16 09:56:02 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 16 Oct 2001 06:56:02 -0700 Subject: python2.1 SEGV on Solaris 2.7 References: Message-ID: <7xpu7nk7t9.fsf@ruckus.brouhaha.com> Anthony Baxter writes: > Has anyone seen anything like this? I'm going to rebuild with > gcc3.0 and also try turning off GC. I've gotten occasional core dumps in the evaluator with Python 2.1.1 under Redhat Linux 7.1. I haven't made a big effort to debug them. In fact I was just thinking of posting about them and asking how common such crashes were. It's an argument for using forking rather than threading or select if you're writing servers in Python, for example. From anthony at interlink.com.au Thu Oct 18 08:51:28 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 18 Oct 2001 22:51:28 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: Message from "Steve Holden" of "Thu, 18 Oct 2001 08:26:46 -0400." Message-ID: <200110181251.f9ICpSP02962@mbuna.arbhome.com.au> >>> "Steve Holden" wrote > Seriously, though, there are many good reasons why you might not want to > upgrade, including having a large and varied hardware base and wanting to > keep all Pythons roughly in step. Hence, lowest common denominator, usually > what you started with on your first machine (though personally I removed > 1.5.2 from my last system three or four moths ago, I'm now thinking of > re0installing it on a test machine for compatibilty testing). The other issue is, of course, when an upgrade involves compiling up each and every different 3rd party module you use, after first making sure it's compatible with the new major release. > > a) bugfixes. > Kind of essential in a bugfix release. well yes. forgive my humour. > > d) if the bug fix relies on some 2.2-ism, then it's either rewritten, > > or ignored and relnoted > Yes, but are there any such? Beats me, I'm only just starting to trawl. The obvious ones might be the internals, where the bugfix is on top of the 2.1-based code. The other thing is to trawl the SF bug database for bugs logged since 2.1 - pity the SF Tracker really isn't that pleasant to trawl... > This all sounds about right. So, how does it feel to be the new patch czar? say what? is this one of those "whoever mentioned it first gets it" type things? From sholden at holdenweb.com Tue Oct 16 15:57:32 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 16 Oct 2001 15:57:32 -0400 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> <9qhvq5$29ik$1@nntp6.u.washington.edu> Message-ID: "Donn Cave" wrote in message news:9qhvq5$29ik$1 at nntp6.u.washington.edu... > Quoth andy47 at halfcooked.com (Andy Todd): > ... > | That is my take as well. Never liked C's ternary operator, never used it. > | Replicating it in Python adds nothing to the language, it does not make > | code cleaner or more efficient and it certainly doesn't make it easier to > | understand. > | > | Not that my vote counts but minus about 20 from me. > > Right, I think it's official that your (our) vote doesn't count, but > we do count as users, and like anything else, if we just take what > we're handed, we get what we deserve. > > I don't know how I'm going to feel about all this, down the road, but > there's a chance I won't be on board, in the sense that I will not be > interested in upgrading. That's the vote I get. > [... melsncholy pessimism ...] Don: I really feel you are overestimating the commitment to implement this in 2.2 or indeed any other later release. Quite apart from the ickiness factor, it complicates reading programs for a beginner, does not actually solve that many real probelsm, and adds a new keyword to the language. If I were a gambling man (which I'm not, mostly because I hate losing) I'd give you even money that Python 2.2 will be unsullied by this particular wart. regards Steve -- http://www.holdenweb.com/ From James_Althoff at i2.com Thu Oct 11 18:25:59 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Thu, 11 Oct 2001 15:25:59 -0700 Subject: Why not 3.__class__ ? Message-ID: Tim Peters wrote: >They're supposed to be ugly: if you find yourself using __xxx__ thingies a >lot, it's supposed to be a clue that you're not using the language as >intended. Point taken. (In his defense, he reminds the jury that he *did* end his remark with a "full wink"). BTW, I've just written a Jython-based debugger-type thingie that provides a GUI in which you (our developers, that is) can visually inspect all fields, methods, base classes, etc. for any object (including Java instances, Python builtin objects, class objects, etc.) in any of our applications (whilst it -- the application -- is running). Moreover you (the developer, again) can change (using the GUI) any field value on the fly (or add or delete same). And, most importantly, you can rewrite a method on the fly (using the GUI) -- restricted to Python methods, of course, not for Java methods because Java is less dynamic and, hence, quite inferior to Python in this regard -- and the affected instances of the affected class (that owns the changed method/function) start using the new method definition without restart of said application and without re-instantiation of said instances. Also included is a GUI for pdb which allows pdb to actually *work* with Jython even after the Swing event queue starts running (out-of-the-box pdb *doesn't* work with Swing). Our developers have found this stuff to provide a nice boost in their (already high because of Jython) productivity. All of this, of course, is made possible because of the wonderful, dynamic nature of Python (three cheers!). But the point is, accessing __class__ (not to mention __bases__, __name__, __dict__, func_code, func_globals, etc.) is something I need to do a lot for this type of deal. I hope, then, that this is *not* a case of "not using the language as intended". a wink is included ;-) >No, but it *is* the part of your brain hardwired to Smalltalk that avoids >functions as if they were somehow inscrutable . The alternative >type(0), type([]), type('') etc are the intended ways to find the type of an >object. More unfortunately than not, all classes in 2.1 had the same type, >as did all class instances. "Healing the type/class split" is what 2.2 >starts to take seriously, although isinstance(x, type(0)) was forced into >working several releases ago. Thanks. I can use that! (He repeats to himself as he codes, tense and white-knuckled: "functions are not evil, functions are not evil, functions are not evil, . . ."). Jim From peoter_veliki at hotmail.com Mon Oct 29 19:30:45 2001 From: peoter_veliki at hotmail.com (Peoter Veliki) Date: Mon, 29 Oct 2001 16:30:45 -0800 Subject: win32all extension module for Python2.0? Message-ID: I have to use Python 2.0, but I can't find the win32all modules to download (specifically win32clipboard.py). It is included with ActivePython, but there web site does not offer V2.0 as a download, only V2.1 and 2.2. Will these modules work with V2.0? Does ActivePython 2.0 exist and if so where can I download it? Thanks From kern at myrddin.caltech.edu Sat Oct 6 19:29:05 2001 From: kern at myrddin.caltech.edu (Robert Kern) Date: 6 Oct 2001 23:29:05 GMT Subject: Octonians in Python References: <3BBF4979.4067B406@alcyone.com> Message-ID: <9po441$6ne@gap.cco.caltech.edu> In article <3BBF4979.4067B406 at alcyone.com>, Erik Max Francis writes: > David Feustel wrote: > >> There is one additional system of complex numbers >> (octonians) beyond quaternions. Are there any >> python implementations of octonians? > > I recall there being a Python module that supported geometric algebras, > in which quaternions and octonions (not octonians) are pretty easily > emulated, and not in a way that defeats their purpose (like matrices). > I know that it was posted to comp.lang.python some months or years ago; > a Google Groups search would probably turn it up. A largely debugged version is in my Starship cabin, now. I haven't played with octonions specifically, yet. http://starship.python.net/crew/kernr/source/clifford.py -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From leo at iems.nwu.edu Tue Oct 23 15:22:54 2001 From: leo at iems.nwu.edu (Leonardo B Lopes) Date: Tue, 23 Oct 2001 14:22:54 -0500 Subject: problem importing xml.xpath Message-ID: <3BD5C38E.61DCB7B0@iems.nwu.edu> Dear Friends, I can't find a way to import the xpath library with python2.0. I can see it in the right place, in the site-packages dir. I notice that there is also an XML directory in the main distr. directory, so I tried moving the dirs there too, but that didn't work. All I want to do is get the two demos XmlTree.py/XmlEditor.py working. Does anyone have any idea what is going on? Thanks! Leo. -- ======================================================================= Leonardo B. Lopes leo at iems.nwu.edu Ph.D. Student (847)491-8470 IEMS - Northwestern University http://www.iems.nwu.edu/~leo From root at rainerdeyke.com Mon Oct 15 23:22:25 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Tue, 16 Oct 2001 03:22:25 GMT Subject: Playing non-MPG movies with Pygame References: <729e12a5.0110151858.586ae081@posting.google.com> Message-ID: "Bocco" wrote in message news:729e12a5.0110151858.586ae081 at posting.google.com... > It's great that Pygame has built-in support for MPEG movies, but how > would I write a program which could use other video formats? Do I > actually need to load each individual frame, pixel by pixel, from the > file into some massive multi-dimensional array, or is there a simpler > way? Assuming you want to use Pygame, you have three options: 1. Convert the video in a series of still images and show these one at a time. 2. Convert the video into mpeg and show that. 3. Write a video decoder for whatever format you want to use in C/C++, integrate it with Pygame, and use that. Attempting to decode the video one pixel at a time in Python will not yield acceptable performance. -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From phr-n2001d at nightsong.com Sat Oct 20 02:13:59 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 19 Oct 2001 23:13:59 -0700 Subject: Triple-DES implementation in Python References: Message-ID: <7x669avnx4.fsf@ruckus.brouhaha.com> Anthony Baxter writes: > Or you could just grab M2Crypto, which has already done this :) That's a C implementation, not pure Python, I think. From phd at phd.pp.ru Wed Oct 31 09:16:47 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 31 Oct 2001 17:16:47 +0300 Subject: Freeware Python editor In-Reply-To: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com>; from Randy.L.Kemp@motorola.com on Wed, Oct 31, 2001 at 08:08:22AM -0600 References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> Message-ID: <20011031171647.D21151@phd.pp.ru> On Wed, Oct 31, 2001 at 08:08:22AM -0600, Kemp Randy-W18971 wrote: > Check out the free Python editor at www.crimsoneditor.com. Free (like free beer), but not free (like freedom). No source code, Windows only. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From tim.hochberg at ieee.org Wed Oct 17 09:37:32 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Wed, 17 Oct 2001 13:37:32 GMT Subject: Troubles with global variables References: <87r8s4vmgy.fsf@toadmail.com> <87elo6cd4w.fsf@lisboa.ifm.uni-kiel.de> <87pu7op8p2.fsf@toadmail.com> <3BCCCC86.55A5C7F7@ccvcorp.com> <87g08hr5zc.fsf@toadmail.com> Message-ID: Hi Jeremy "Jeremy Whetzel" :wrote in message news:87g08hr5zc.fsf at toadmail.com... [SNIP code] > > I've been playing around with the code, and I have a couple of > questions. > > First, with the dictionary having tuples, the items in the > tuples cannot be reassigned. (which is the error I receive when I try to > change an option) If I change the tuples to lists, I then receive an > error saying "TypeError: not enough arguments for format string". (I > think I got this one figured out by putting (item[0],item[1],item[2]) > instead of just 'item' on the string formatting line. What would _you_ > do to change this? (ie, did I hit close to the mark?) Use: print " %s ) %15s %s" % tuple(item) > Also, I've noticed that when the menu prints, it tends to print the menu > listing in alphabetical order of the keys in menudict. Is there a way > to change this behavior? Dictionary's don't remember the order that items are added, so the order of items returned by aDict.items() is undefined and the fact that you're getting them in alphabetical order is an accident of the implementation. If you want to preserve the order of the keys you're going to need to use a list/tuple in some manner. One way would be to use: menulist = [('E', ['E', 'Encoder', 'gogo' ]), ('B' , ['B', 'Bitrate', '128' ]), ('Q' , ['Q', 'Quit', '' ] ) ] # Generate menudict from menulist so they stay in syc menudict = {} for key, value in menulist: menudict[key] = value # Everything else the same except when printing #... for key, value in menulist: # use the list for printing print " %s ) %15s %s" % value #... There's no reason to store the 'E', 'B', 'Q' values on both the 'key' and 'values' halves of the dictionary's either -- I would be tempted to rewrite the function to avoid that. > One last thing, and this was something I didn't address earlier, but > having the 'enc' variable is something I need later in the program. I > know I could use menudict['E'][2], but that feels cumbersome to type out > each place I need it. How would you approach this? Below is one possible way to rewrite your code that I think address your (and my) (well mostly my) concerns expressed above. For the last case, you would just type data['E'], which seems a little less cumbersome than menudict['E'][2]. -tim import os # Format is (key, name, initvalue) _menu = [('E', 'Encoder', 'gogo'), ('B' , 'Bitrate', '128'), ('Q' , 'Quit', '') ] def showmenu(menu): # Build the names and data dicts from menu names, data = {}, {} for key, name, value in _menu: names[key] = name data[key] = value while 1: os.system('clear') for key, name, initial in menu: print " %s ) %15s %s" % (key, name, data[key]) print choice = raw_input('Enter Choice: ').upper() print if choice == 'Q': break elif data.has_key(choice): prompt = 'Enter the new %s: ' % names[choice] data[choice] = raw_input(prompt) else: print "That is not a valid option." return data if __name__ == '__main__': data = showmenu(_menu) print data From gh_pythonlist at gmx.de Sat Oct 13 07:50:30 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 13 Oct 2001 13:50:30 +0200 Subject: PostgreSQL Interface Query In-Reply-To: <3BC7BD91.A604728C@iinet.net.au>; from jbell@iinet.net.au on Sat, Oct 13, 2001 at 12:05:37PM +0800 References: <3BC7BD91.A604728C@iinet.net.au> Message-ID: <20011013135029.B876@lilith.hqd-internal> On Sat, Oct 13, 2001 at 12:05:37PM +0800, John Bell wrote: > I have been evaluating various Python interfaces to PostgreSQL. So far > as I've been able to determine the options are PygreSQL (packaged with > PostgreSQL), PoPy, psycopg and a new entrant, pypgsql. I am leaning > towards pypgsql (available from SourceForge) based on an comparitive > assessment of functionality only. > However, as pypgsql is just under a year old and I've never heard it > mentioned on any major Python or PostgreSQL forum before I am somewhat > concerned regarding its stability. There have been some talks in comp.lang.python, but mostly questions on how to build it on platform X. And sometimes me lobbying for it ;-) http://groups.google.com/groups?q=pypgsql One thing is that perhaps people weren't sure where to ask questions. Some did on c.l.p, some did on the postgresql-interfaces list, some did via the Sourceforge bugtracker/support etc. facilities. And some asked the developers in private mail. But since a few days, we have a mailing list for this purpose. And also a brand-new website: http://pypgsql.sourceforge.net/ And, lack of problem reports on public forums can be a good sign. Most talks about modules are in my experience about problems, not when it works just fine. > I would be very interrested in comments from anyone with experience of > the pypgsql package. I am one of the developers, so this probably doesn't count. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From sheila at spamcop.net Mon Oct 22 16:21:41 2001 From: sheila at spamcop.net (Sheila King) Date: Mon, 22 Oct 2001 20:21:41 GMT Subject: Smtplib module References: <3BD20BAE.6346.7693E0@localhost> <9qscfm.3vv746r.1@kserver.org> <9qsnue.3vv5vib.1@kserver.org> Message-ID: <9r16as.3vv7bk7.1@kserver.org> On 22 Oct 2001 15:05:00 -0400, David Bolen wrote in comp.lang.python in article : :Sheila King writes: : :> Do an MX record look up on the domain name in the email address, and :> deliver directly to that SMTP server. : :Even that won't guarantee you know about the status of final delivery, :since the published MX record may well just point to the entry point :into a larger delivery system that can cross any number of additional :machines. You're not the first to discuss what the final delivery status of the email was. It is curious to me, since I never discussed that topic, nor did the original poster ask about the final delivery status. He asked about whether it was accepting for delivery. Is this some obsession, or is it some FAQ such that people jump to that assumption? Just curious. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From paul at boddie.net Thu Oct 18 07:07:09 2001 From: paul at boddie.net (Paul Boddie) Date: 18 Oct 2001 04:07:09 -0700 Subject: PEP: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: <23891c90.0110180307.51588825@posting.google.com> huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote in message news:... > Sorry if someone already raised this point, but... > The semantics of > > if stmts1; expr1: > stmts2 > elif stmts3; expr2: > stmts4 > elif stmts5; expr3: > stmts6 > else: > stmts7 And couldn't this be written as... stmts1; if expr1: stmts2 else: stmts3; if expr2: stmts4 else: stmts5; if expr3: stmts6 else: stmts7 ...? Of course, you're indenting more and using a few more lines, but don't you think that it's frivolous to implement a language change merely to be able to move the statements to the right of the keyword, admittedly allowing some merging of keywords as a result? Paul From l0819m0v0smfm001 at sneakemail.com Sat Oct 6 08:56:07 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Sat, 06 Oct 2001 12:56:07 GMT Subject: Newbie question about running scripts References: Message-ID: <3BBEC9FB.8080709@sneakemail.com> Lenny wrote > My questions are: > 1.) Do I have to save my scripts to a certain folder that Python > created for me or one I make for them? No. > > 2.) Do I have to change something in the registry about the PATH even > though Python appears to have a Python Path entry already in the > memory? > No, the installer handled this for you (or you wouldn't see the black box, even temporarily, when you tried running Python from the Run menu). > 3.) Is the RUN window the window they mean as the "Command Prompt > Window"? > No, they mean the MS-DOS Command window; you should be able to find this somewhere in the Start Menu. If you see a black box pop up when you run python from Run Commands (or by double-clicking on the .py file you created in Explorer), that means it's working--at least to the extent of finding python.exe in the path. Unfortunately, the command box started that way doesn't hang around after the program completes; if you put a line at the end of the program that prompts for input, it should wait for you to type something, but it's easier and better to start the MS-DOS Command prompt yourself, and then it will be there until you dismiss it. Better still, you should probably try learning Python (at least on Windows, where the command line isn't natural) from within an IDE (integrated development environment). If you use the Pyton install from python.org it should have installed IDLE; run IDLE from the Start Menu or by double-clicking on its icon in Explorer and you get an IDE with (among other things) a Python-aware text editor (color coding syntax, tool-tip hints for method and function completion, auto-indenting) and an interactive Python prompt. The only thing to be aware of is that when you run a program from within the text window, you may have to switch to the Interactive Prompt window (if it's not visible) to see the output. The ActiveState Python distribution has a similar (more native Windowsy-looking) IDE called PythonWin. You can also use IDLE, but you have to download it from python.org, I think. One last note, Python 2.2 is currently an alpha release, not even beta, which means they are still shaking the bugs out--you should probably back down to 2.1, which is the latest production release. > > Does anyone suggest a certain online tutorial or other learning > method. You could take a look at Dive into Python at http://www.diveintopython.org or at How to Think Like a Computer Scientist, In Python at http://www.andamooka.org/reader.pl?section=thinkpython but the Python Tutorial that comes with Python is pretty good, I think. It sounds more like you're just having a little trouble getting started because Windows likes to get in the way of simple things like using a command line interface. Once you start using one of the Python IDEs, things will be a lot more Windowsy and you should find the going smoother, at least until you start trying to write your own GUI interface or multi-threaded programs (where trying to run from within an IDE poses some gotchas). But when and if you get there, there are people on comp.lang.python who can help you out. Hope this helped, and welcome to Python. Joshua From m.faassen at vet.uu.nl Mon Oct 15 20:12:41 2001 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 16 Oct 2001 00:12:41 GMT Subject: FW: [Python-Dev] conditional expressions? References: Message-ID: <9qfu1p$iei$1@newshost.accu.uu.nl> Brian Quinlan wrote: > Tim wrote: >> If you don't use parens, they're equivalent to >> >> ]*** ) 3fo?rkl > Tim, please stop using idiomatic Perl in your examples - it's hard for > some of us to follow. My initial response is that conditional expressions don't look pretty.. I don't know what I don't like about them; even C's variety seems nicer to me right now, probably because I'm used to those. I think it's a combination of the reuse of the word 'if' (which in my mind triggers "this is a statement") and the long lines resulting from this usage. Three keywords and possibly some parens, and all you have is just *part* of an expression! I think this is only matched by list comprehensions. The difference is that list comprehensions are commonly used in isolation (in an assignment), while conditional expressions aren't worth that much if used outside more complicated expressions. I think list comprehensions win out on various grounds, even though they're a three statement expression as well.. This is all pretty subjective, so some theories as to why.. for x in (if foobar(x) then range(100) else my_own_function(77)): pass for x in [foobar(x) for x in range(100) if my_own_function(x)]: pass * list comprehensions are signalled by the fairly clear [ and ]. Conditional expressions use the already fairly strongly overloaded ( and ). Of course I guess they wouldn't really overload them further, but.. * Perhaps one can lose the parens in the conditional expression. Can one? What is the rule? Is the rule easy to remember? Of course I think it'd look less readable still without the parens... * list comprehension don't *have* to use the 'if' part, while conditional expressions will have to use the else part. (not orthogonal with the optionality of 'else' in the 'if' statement, either, but that's a minor issue) * The list comprehension always generates a list, which limits the ways in which you can use them in obscure ways. (if one did not set out deliberately to do so, that is) A conditional expression could evaluate to anything, so can be used in more places more obscurely. * in a list comprehension, all parts are fairly clearly related to each other. For instance, in the variable, x is post-processed in the first part, iterated through in the 'for x' part, and generated by the range(100) part. The last part again does somekind of check on x. In a conditional expression this relationship can I think frequently be absent, which may make it harder to grok as a single thing. ... But these are just vague responses. Perhaps I'll get used to them pretty quickly. What do others think? Excuse me if I missed somekind of long thread about this and I'm repeating the often stated. :) Regards, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From kalle at gnupung.net Tue Oct 2 10:36:52 2001 From: kalle at gnupung.net (Kalle Svensson) Date: Tue, 2 Oct 2001 16:36:52 +0200 Subject: XML Marshalling of objects In-Reply-To: References: Message-ID: <20011002163652.E7776@sandrew.lysator.liu.se> [Peter Neubauer] > Hello, > I'm wondering if there is a good way to marshal/unmarshal python objects > to XML? I'm thinking of some framework like Castor (castor.exolab.org) > for Java. Try googling for "XML pickle python". At least three of the hits on the first page should be of some interest. http://www.faqts.com/knowledge_base/view.phtml/aid/5706 http://dev.zope.org/Wikis/DevSite/Proposals/XMLToObjects http://gnosis.cx/publish/programming/xml_matters_1.txt Peace, Kalle -- [ Thought control, brought to you by the WIPO! ] [ http://anti-dmca.org/ http://eurorights.org/ ] From bokr at accessone.com Sat Oct 20 17:53:52 2001 From: bokr at accessone.com (Bengt Richter) Date: Sat, 20 Oct 2001 21:53:52 GMT Subject: Reverse argument order References: Message-ID: <3bd1f335.1049196274@wa.news.verio.net> On Fri, 19 Oct 2001 14:59:19 -0700 (PDT), David Brady wrote: >Thanks, everyone, for your answers. Also, thanks to >those of you that ways of asking if the question >really needed to be asked. > >At the time I had posted, we had considered all of the >non-answer answers that were posted here. Most were >rejected by the business half of the team, because >they have a goal of reducing the keystroke count as >much as possible. They're already upset that the new >scripting language has to have parentheses everywhere. > :-) > >Specifically, > >We considered using named arguments, but rejected them >because even typing Wait(m=3,s=10) was judged to be >too hard, let alone Wait(minutes=3, seconds=10). >Personally, I like this approach best, and I want to >just write in the manual, "Look, you're going to have >to learn to type, okay?" But that's just me. > >We also considered using Wait(0,0,5) for a 5-second >wait, but this was also shot down. > >One possible compromise was offered by the business >half of the team, that they would be willing to type >Wait(,,5), but *WE* shot that down on the grounds that >it does not work. (They were thinking it would >evaluate to Wait(None,None,5) which could then have >been turned into 0,0,5). > >We considered the string bit, but strings require >quotes.... > >We even considered modifying the Python source so that >it would accept 00:00:00 as a token identifying a time >type (that we would add). This was discarded by >everyone as WAY too much effort. (Imagine getting the >lexer to accept things like "while t < 1:05: pass") > >Anyway, thank you all again for your answers and help. > This project is starting to shape up! > >-dB >P.S. We're going to go with the "while len(args)<3: >args.insert(0,0)" model for now. Much less sucky, >yes, thanks! > >===== Brute force, but clear: >>> def wait(first=None,second=None,third=None): ... if third: h,m,s = first,second,third ... elif second: h,m,s=0,first,second ... elif first: h,m,s=0,0,first ... else: h,m,s=0,0,0 ... print "h=%d, m=%d, s=%d" % (h,m,s) # or whatever you want to do ... >>> wait() h=0, m=0, s=0 >>> wait(1) h=0, m=0, s=1 >>> wait(1,2) h=0, m=1, s=2 >>> wait(1,2,3) h=1, m=2, s=3 From tim.one at home.com Mon Oct 22 03:49:53 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 22 Oct 2001 03:49:53 -0400 Subject: Dictionary from list? In-Reply-To: <9qt550$br6$1@slb4.atl.mindspring.net> Message-ID: [Andrew Dalke] > Not a core function, but > > args, files = getopt.getopt(...) > args = dictionary(args) > > would be handy. And Marcin Kowalczyk had some good abstract arguments -- but a concrete example somebody would actually use does more for me . So what should dictionary(x) do? If x is of a mapping type, it currently (2.2b1) returns a dict with the same (key, value) pairs as x. "Is a mapping type" == is an instance of dictionary (including subclasses of dictionary), or, failing that, responds to x.keys() without raising AttributeError. If we try x.keys() and do see AttributeError, then what? It's not 2.2-ish to insist on a list -- any iterable object should work. So we try to iterate over x. Now it gets harder: what kinds of objects are we prepared to see when iterating x? Insisting on a 2-tuple (or subclass of tuple) is most efficient. More general is to treat these as iterable objects in their own right, and either take the first two objects iteration produces, or insist that an attempt to generate a third object raise StopIteration. The latter is more Pythonic, because it matches what "the obvious" loop does: d = {} for k, v in x: d[k] = v In 2.2, x can be any iterable object there, and so can the objects produced by iterating *over* x. Extreme example of the latter: >>> f = file('f1', 'w') >>> f.write('a\nb\n') >>> f.close() >>> g = file('f2', 'w') >>> g.write('c\nd\n') >>> g.close() >>> h = file('f3', 'w') >>> h.write('1\n2\n3\n') >>> h.close() >>> for k, v in map(file, ('f1', 'f2', 'f3')): ... print k, v ... a b c d Traceback (most recent call last): File "", line 1, in ? ValueError: too many values to unpack >>> That is, we can't unpack a file with 3 lines into a two-vrbl assignment target. Is 2.2 great or what <0.9 wink>?! OK, I convinced myself that's the only explainable thing to be done, although I grate at the gross inefficiences; but I can special-case 2-tuples and 2-lists for speed, so that's OK. Next question: Should this really work by provoking the argument with various protocols and letting exceptions steer it? Or should you be explicit about that you're passing an iterable object producing iterable objects producing 2 objects each? dictionary() currently takes a single optional argument, named 'mapping': >>> dictionary(mapping={1: 2}) {1: 2} >>> dictionary({1: 2}) # same thing {1: 2} >>> Should the new behavior require use of a differently-named keyword argument? My guess is yes. What will prevent this from getting implemented is a 3-year rancorous debate about the name of the new argument <0.7 wink>. Note that the obvious workalike loop: d = {} for k, v in x: d[k] = v deals with duplicate k values by silently overwriting all but the last association seen. "tough-luck"-comes-to-mind-ly y'rs - tim From tjreedy at home.com Thu Oct 25 12:29:56 2001 From: tjreedy at home.com (Terry Reedy) Date: Thu, 25 Oct 2001 16:29:56 GMT Subject: learn OOP with Python References: <9r97co$cme$07$1@news.t-online.com> Message-ID: <86XB7.155958$5A3.54570578@news1.rdc2.pa.home.com> "Achim Domma" wrote in message news:9r97co$cme$07$1 at news.t-online.com... > Hi, > > a new employee will write scripts for us in python, but he has not much > experience with OOP. Are there any books that teach OOP concepts using > Python ? Is there a good source to give somebody with experiences in Pascal > and VBScript an introduction in the OO way of thinking ? > > greetings > Achim Great! In my experience, Python is a good language for really learning *and* appreciating OO concepts. (C++ had about convinced me that they were too much trouble.) It incorporates OO thinking and facilitates OO programming without encouraging OO fetishism. I learned much from contemplating the type.method system (as in lists and dictionaries) and reading many examples of class definitions -- some in standard libraries, some posted on c.l.p and web sites. Perhaps your employee can too. To me, there are two basic concepts: 1. Package together related data and functions. Functional programmers do this with closures. However, more programmers find classes with attributes and methods a better (easier to use) implementation of the idea. 2. Reuse code by extending and over-riding the methods (and attributes) of inherited base classes. This replaces the older method of cut, paste, and edit. Worth noting: the balance between data and function can vary from mostly (or even all) data to mostly (or even all) function. For instance, consider DOM versus SAX processing of XML files. (see http://www.ora.com/catalog/pythonxml/chapter/ch01.html for a user-viewpoint explanation and the xml part of the library for the implementing code.) A DOM instance swallows up an entire xml file, however large, and exposes it as a tree structure with methods for accessing the nodes (and their values) in random order. A SAX-derivative instance takes a handle to an xml file, serially scans and parses the file with its core methods, and passes pieces to user-defined methods added to the derivative class. Though I did not answer your question about books, I hope your employee might find these comments a bit of help. Terry J. Reedy From phd at phd.pp.ru Wed Oct 17 15:23:21 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 17 Oct 2001 23:23:21 +0400 Subject: os.path.join and lists In-Reply-To: <20011017190120.B14220@software.plasmon>; from dswegen@allstor-sw.co.uk on Wed, Oct 17, 2001 at 07:01:20PM +0100 References: <20011017190120.B14220@software.plasmon> Message-ID: <20011017232321.B20564@phd.pp.ru> On Wed, Oct 17, 2001 at 07:01:20PM +0100, Dave Swegen wrote: > foo = os.path.join(bar[1:2], "bob") foo = os.path.join(bar[1:2] + ["bob"]) # untested Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From pzw1 at cor-no-spam-nell.edu Tue Oct 30 20:47:28 2001 From: pzw1 at cor-no-spam-nell.edu (Peter Wang) Date: Wed, 31 Oct 2001 01:47:28 GMT Subject: adding items from a text file to a list References: <48dbc3f6.0110301612.e0f863c@posting.google.com> <9rng2s$va4pr$1@ID-11957.news.dfncis.de> <3ohutt4ed0264imgprah2lblipqljer1pe@4ax.com> <9rnj56$v2d5n$1@ID-11957.news.dfncis.de> Message-ID: <2sluttgogsukb4r93t0ruu4a7531tjdkee@4ax.com> good call... i guess if someone really wanted to cheat themselves out of their tuition, i was a party to their crime... -peter On Tue, 30 Oct 2001 17:07:13 -0800, "Emile van Sebille" wrote: > >"Peter Wang" wrote in message >news:3ohutt4ed0264imgprah2lblipqljer1pe at 4ax.com... >> split()[0] won't work because some items (like "pickled eggs") have >> spaces in them. >> > > >I know... it sounded like homework and I wanted to point without giving... From phr-n2001d at nightsong.com Mon Oct 29 02:32:57 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 28 Oct 2001 23:32:57 -0800 Subject: interpreter crashes References: <7xpu7768nf.fsf@ruckus.brouhaha.com> Message-ID: <7xg082295i.fsf@ruckus.brouhaha.com> barry at zope.com (Barry A. Warsaw) writes: > PR> The backtraces aren't very informative. The evaluator is > PR> crashing, almost certainly due to data corruption having > PR> happened sometime earlier. But sure, I'll include them. > > Try running your program under gdb. Often, nonsense stack traces are > caused by memory corruptions which can be caught much sooner under > gdb, producing more usable stack traces. The stack traces aren't nonsense--they're just innocuous, they show that the interpreter was evaluating something about the way you'd expect it to when the crash happened. It will take more detailed digging in the core dump, and better knowledge of the interpreter guts than I currently have, to see what exactly is wrong. Unfortunately, the crashes don't happen often enough for it to be practical to run under gdb. From bruce_dodson at bigfoot.com Sat Oct 27 16:35:09 2001 From: bruce_dodson at bigfoot.com (Bruce Dodson) Date: Sat, 27 Oct 2001 17:35:09 -0300 Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> Message-ID: Would Stackless have a better chance of making it into the core if its initial PEP talked only about increasing performance and removing limits on recursion? This advantage is not as "sexy" as continuations, but is also less controversial. It is still something that everyone can understand, and without any exported facilities for frame-switching, it alone does not require changes to most existing C extensions. It does still require additional book-keeping code to be added to the core, much like Stackless. Microthreads and coroutines can be sold as advantages in another PEP, one which does treat that decoupled stack as a tree, and does permit arbitrary frame switching. This PEP would have to talk about the risks and changes required to existing modules, to make them work safely in program that takes advantage of continuations. A "future" import might help. Meanwhile Stackless remains a separate branch, but hopefully becomes easier to maintain against a CPython which already has a decoupled stack. Bruce From James_Althoff at i2.com Tue Oct 23 13:13:32 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Tue, 23 Oct 2001 10:13:32 -0700 Subject: Dictionary from list? Message-ID: Russell E. Owen wrote: >For what it's worth, I'm bullish on Chris Barker's suggestion of some >way of converting list of keys, list of values to a dictionary. Like >Chris, I've written my own and use it a fair bit. > >I have no opinion about converting the two proposed flavors of single >lists to dicts (i.e. [key1, value1, key2, value2...] vs. [(key1, >value1), (key2, value2)...]; they both sound useful, are both easy to >implement via user-written functions, and if either is implemented as a >built-in, then folks are likely to have a cow about the missing one. Well, not to beat a dead cow, but (or cow butt, if you prefer) ... I say take advantage of class methods (new in 2.2) and use them as alternative constructors (factory methods, if you will) instead of badly overloading the nominal constructor, as in (picking your own favorite names, of course): d1 = dictionary.fromKeyValueSeq([key1, value1, key2, value2...]) d2 = dictionary.fromKeyValuePairs([(key1, value1), (key2, value2)...]) etc. (i.e., use the well known "eat a cow and have a cow, too" design pattern). Jim From pih at oek.dk Sat Oct 13 19:02:19 2001 From: pih at oek.dk (Peter I. Hansen) Date: Sun, 14 Oct 2001 01:02:19 +0200 Subject: Newbie - converting binary data to ASCII text ? References: <9q92g4$6hd$1@wanadoo.fr> Message-ID: <3BC8C7FB.304A1165@oek.dk> Cyr wrote: > hello, > > I'm completely new to python and I've got problem reading binary data file. > When I read a file with read(), the binary data aren't converted. In fact, > I'd like to know if there's a method for converting a file object (or a > string) from binary to the equivalent ASCII text. The data aren't written in > a particular format. Fortran doesn't have any problem with theese files > > I'would greetly appreciate any help, thanks > > Cyril D > > PS : I'm working on an SGI Irix operating system Try something like : from array import array A = array('d') # 'd' for double file = open("filename",'rb') # 'rb' read binary A.fromfile(file,N) # N is the number of bytes you want to read print A # To view the array :) /Peter From paoloinvernizzi at dmsware.com Wed Oct 3 05:07:34 2001 From: paoloinvernizzi at dmsware.com (Paolo Invernizzi) Date: Wed, 03 Oct 2001 09:07:34 GMT Subject: Python is better than free (was Re: GNU wars again) References: <9pefbe$8c1$1@serv1.iunet.it> Message-ID: Alex strikes back, again ;) Paolo Invernizzi "Alex Martelli" wrote in message news:9pefbe$8c1$1 at serv1.iunet.it... > "Chris Watson" wrote in message > news:mailman.1002078843.29724.python-list at python.org... ... ... > the point of spending time on Usenet which we DEFINITELY should be > employing more productively, sigh:-). From odeme at airtel-atn.com Mon Oct 1 09:05:44 2001 From: odeme at airtel-atn.com (Olivier Deme) Date: Mon, 1 Oct 2001 14:05:44 +0100 (BST) Subject: Problem with linking embedding C application In-Reply-To: Message-ID: Thanks a lot. Yes, a mess indeed. The Python team seriously needs to address these issues. Olivier. ------------------------------------------------------------------------- Olivier Deme AIRTEL-ATN ~ Phone: +353-1-284 2821 . . +353-1-214 7910 (Direct) / v \ Email: olivier.deme at airtel-atn.com /( )\ Web: www.airtel-atn.com ^^-^^ ------------------------------------------------------------------------- On Mon, 1 Oct 2001, Mads Bondo Dydensborg wrote: > On Mon, 1 Oct 2001, Olivier Deme wrote: > > > Thanks for the link to the demo application. > > Indeed it seems that there a plenty of libraries to link with... > > > > Something also really annoying: > > The libraries are located in an unusual place on my machine: > > /usr/local/lib/python2.1/config/ > > > > Plus, the fact that libpython*.a has its version number in the file name. > > That means that if our customer has a different version of Python, they > > won't be able to link our application! > > Usually, this should be solved by adding a symbolink link in a common > > directory. Sonething like: > > /usr/lib/libpython.a -> /usr/local/lib/python2.1/config/libpython2.1.a > > > > But this is not done during installation of Python. How are we supposed to know > > the version used by the people who are going to build our application? > > I have found that out - the pygtk code includes autoconf (are you using > autoconf) code that calls python (douh). (This is just an expert, be sure > to review the entire file - acinclude.m4 from the pygtk distribution). > > changequote(<<, >>)dnl > prog=" > import sys, string > minver = '$1' > pyver = string.split(sys.version)[0] # first word is version string > # split strings by '.' and convert to numeric > minver = map(string.atoi, string.split(minver, '.')) > if hasattr(sys, 'version_info'): > pyver = sys.version_info[:3] > else: > pyver = map(string.atoi, string.split(pyver, '.')) > # we can now do comparisons on the two lists: > if pyver >= minver: > sys.exit(0) > else: > sys.exit(1)" > changequote([, ])dnl > if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC > > The library can be found from constructions like the following > > py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"` > PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}" > > There are standard places the library go, when you have the exec_prefix (I > think). > > Linking is the great problem here (linker options). I found > http://sources.redhat.com/ml/bug-autoconf/2001/msg00297.html > (it is 4000 lines). Search for KDE_CHECK_PYTHON for how they test for some > common linker requirements. > > It is a mess though. > > Mads > > -- > Mads Bondo Dydensborg. madsdyd at challenge.dk > In a stinging rebuke, a federal judge Monday ruled Microsoft Corp. violated > the nation's antitrust laws by using its monopoly power in personal computer > operating systems to stifle competition. > - CNN Financial News April 03, 2000: 7:53 p.m. ET > From m.bless at gmx.de Sun Oct 14 15:16:12 2001 From: m.bless at gmx.de (Martin Bless) Date: Sun, 14 Oct 2001 19:16:12 GMT Subject: Python: Zope with MySQL (and insert_id) References: <3BC574C4.3070307@glencros.demon.co.uk> <3BC5C092.1070103@glencros.demon.co.uk> Message-ID: <3bc9e41c.1402377@news.muenster.de> [Nick Glencross]: >Cheers. There really should be a Zope Newsgroup here! :-) Oh yes, indeed. Martin From _âèëëà_ at e-mail.ru Sat Oct 6 04:18:28 2001 From: _âèëëà_ at e-mail.ru (Villa) Date: Sat, 6 Oct 2001 12:18:28 +0400 Subject: =?windows-1251?Q?=CF=F0=EE=E4=E0=E5=F2=F1=FF_=E2=E8=EB=EB=E0_=ED=E0_=E1=E5=F0=E5=E3=F3_=EE=EA=E5=E0=ED=E0?= Message-ID: <40722001106681828351@e-mail.ru> ????????? ????? ?? ???????? ? 20-?? ?????? ?? ?????????? ??????. 200 ??.?. 0,15 ??. ??????, ????????????, ????????. ?????? ?????? ?? ????? (??????? ??? ????. ??????? ? ???? 28?)! ?????????? ?????. ?????? ?????????? ??????? ??????????. ???? ?? ???????????????? ???? ???????????? ? ?????? ???????? ????? ????????? ??????????, ??????? ?????? ?????? ?? ??????: seych at yours.com. ??? ???? ? ???? "????" ??????????? ???????: "???????? ????????? ??????????". From Jeremy.Jones at peregrine.com Thu Oct 11 12:33:10 2001 From: Jeremy.Jones at peregrine.com (Jeremy Jones) Date: Thu, 11 Oct 2001 09:33:10 -0700 Subject: SocketServer - multithreading Message-ID: <55720746FFC5D4118A3B00508BF9B80A012900CE@atlgaexc3.harbinger.com> On Thu, Oct 11, 2001 at 12:16:28PM -0400, Oleg Broytmann wrote: >Strange. I have no idea. Anyway try to remove "print request". But be >advised that if you open the file in 'w' mode - you will overrite it every >time. Use 'a' mode, or open different files... I am a dunce. I was checking whether the file was being updated properly by using the "tail" command. Since the file was being opened in 'w' mode, it was overwriting every time and was not reflected in "tail." I just changed it to open in "a" and it works. Thanks for the help. And thank you for the code. It works excellently. I just pushed 10 iterations of 10 simultaneous clients at it and it handled all 100 requests perfectly. Jeremy From paul at boddie.net Mon Oct 29 07:43:59 2001 From: paul at boddie.net (Paul Boddie) Date: 29 Oct 2001 04:43:59 -0800 Subject: MySQL + SQL Statements + Quote escaping References: Message-ID: <23891c90.0110290443.21285908@posting.google.com> Chris Stromberger wrote in message news:... > > Hamish Lawson wrote: > > > >Database modules that conform to the DB-API specfication, such as > >MySQLdb, provide a placeholder mechanism that will take care of the > >quoting automatically. For example: > > > > cursor.execute( > > "select * from customers where surname = %s and age < %s", > > ("O'Hara", 40) > > ) > > This doesn't work for me. I have to add single quotes around the %s > and then it still doesn't escape the single quote in the substituted > string. What am I missing? > > Eg (this works if there's no quotes in the substituted string): > > cursor.execute( > "select * from customers where surname = '%s' and age < %s", > ("O'Hara", 40) > ) I know this will sound somewhat unhelpful, but any serious combination of Python database module and database system will provide proper support for placeholders as described above. If you aren't getting "justice" from the above example, then it may be appropriate to consider which module you're using and whether there's one which implements placeholders properly. I actually thought that MySQLdb [1], for example, had support for placeholders in the fashion illustrated above, but then I've never used MySQL or MySQLdb due to a number of reasons including... * When I tried to install MySQL, there were loads of different packages of different releases, some of which were supposed to work with other things but didn't, and some of which had things missing. It was easier to download an evaluation version of a commercial database system for my purposes at that time. * At the time in question, MySQL lacked features that I consider essential in a relational database system. I'm sure MySQLdb is one of the better supported Python database modules out there, however. Paul [1] http://dustman.net/andy/python/MySQLdb/ From john.thingstad at chello.no Sun Oct 21 15:40:36 2001 From: john.thingstad at chello.no (John Thingstad) Date: Sun, 21 Oct 2001 21:40:36 +0200 Subject: Oops: difference in operation of string.join and ''.join Message-ID: <20011021200323.BJAK12720.mta01@mjolner> >>> ''.join([x+y for x, y in zip('test', 'dust')]) 'tdeusstt' >>> import string >>> string.join([x+y for x, y in zip('test', 'dust')]) 'td eu ss tt' What is this? From support at internetdiscovery.com Fri Oct 26 11:48:04 2001 From: support at internetdiscovery.com (Mike Clarkson) Date: Fri, 26 Oct 2001 15:48:04 GMT Subject: Tkinter Html Display References: <3daa1aa8.0110051100.33815499@posting.google.com> <8V4+SKAWuBw7EwDc@jessikat.fsnet.co.uk> Message-ID: <3bd98584.5912529@nntp.ix.netcom.com> On Sun, 7 Oct 2001 10:08:38 +0100, Robin Becker wrote: >In article <3daa1aa8.0110051100.33815499 at posting.google.com>, Jeffrey > writes >>Hi All, >> I want to display an HTML file on a Tkinter Canvas widget. Do any >>of you know how to do this? The principle problem I have is that the >>HTML file can display subscript and symbols and stuff, while >>translated the HTML lines into text, you lose that. I came up with >>one solution that one could just capture the HTML off the browser and >>turn it into a gif file and then display on the widget. But I just >>wanted to know if there is anything out there or any solution for >>this.... The best HTML widget for Tk is the TkHtml widget from http://www.hwaci.com/sw/tkhtml/. This is a C coded HTML widget, and is very fast and quite complete. If you want to see a browser built on it, see BrowseX (http:/www.browsex.com). It would not be hard to write a simple Tkinter wrapper for it; if anyone has one please let me know. IMHO, it would make a nice evolution path for Grail. BTW, does Grail work with Python 2.x? Mike. From use-net at schabi.de Fri Oct 19 02:40:40 2001 From: use-net at schabi.de (Markus Schaber) Date: Fri, 19 Oct 2001 08:40:40 +0200 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> Message-ID: <20011019084040.66952ddc.use-net@schabi.de> Hello, > Thanks for finding some concrete, realistics examples of what the > proposed change would lead to. That's correct, the examle was worse than the original. A genious one-liner is not always better than five lines of readable code. > To me, that 'while' line is convincing > evidence againt this syntax. What bothers me is this. ';' is a > statement separator (whose use is generally discouraged). What the > proposed change means is that a 'while' at the beginning of the > sequence means that the last statement is instead to be a condition. > This requires a sort of mental suspension that I believe many besides > me would find obnoxious. This is why I'd vote for something like: do some; statements while condition: pass #This could be your code I know this involves a new keyword, and it might be difficult to get the parser parse this (as the do-while would be one statement containing ;-separated statements), but the code is executed in the same order as it is written, and ; really divides statements. Maybe this form could be expanded to allow: do some statements while cond: something else Making the last part optional (or inserting pass), we also would get the "check condition at end of loop" case. markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From sdm7g at Virginia.EDU Tue Oct 2 16:10:35 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Tue, 2 Oct 2001 16:10:35 -0400 (EDT) Subject: comparing interpreter speed on two platforms In-Reply-To: Message-ID: On 2 Oct 2001, Chris Liechti wrote: > i have run a simple benchmark on two systems: > > a standard PC: > 1. PentiumPro 200Mhz (400BogoMips) Debian Linux 2.2 (Kernel 2.2-17) 64M RAM > > and an embedded system: > 2. PowerPC ~60Mhz (68BogoMips) HardHat Linux 2.0 (Kernel 2.4) 16MB RAM > I suspect Cliff's diagnosis is the right one: >Because, as stated in the Linux docs, BogoMips is a meaningless benchmark. However, a couple of other possibilities: GCC isn't as well optimised for PPC as for x86: Apple has done some work on GCC but they had a separate fork until they just recently merged it back for GCC 3.x. An earlier version probably won't have any of apple's mods. math libs for PPC may be slow -- this was noticed on Darwin/MacOSX developer lists that the Darwin math libs were much much slower than Metrowerks PPC math libs -- especially for trig functions. I don't know if those libs are part of GCC or BSD distribution, and I don't know if the same problem exists on Linux, but if you have any sins or cos's in your math benchmarks, I'ld guess this is a likely glitch. If you haven't already, you may want to break your benchmark up to profile different aspects -- is it a general slowdown, or is one thing (like math libs, above) very slow? 16MB vs. 64MB: it should all fit into 16MB easily, but is there a difference in how quickly it pages in ? Make sure you not only have a minimum system load, but run an untimed pass first to make sure everything has paged into memory. -- Steve Majewski From aotto at t-online.de Tue Oct 16 08:37:03 2001 From: aotto at t-online.de (aotto) Date: 16 Oct 2001 05:37:03 -0700 Subject: Psyco Specializing Compiler References: <3bc4d2e4$0$36473$ba620e4c@news.skynet.be> Message-ID: <2542dd24.0110160437.60eeb642@posting.google.com> Hi, Well done .... if you wan't to have a look to a full working script "Compiler" don't forget to visit: http://www.compiler-factory.com I know all the problems you have and all the problems you'll get in the next 2-3 years of full time 6*12*52*3 = 11232 hours working time. I hope you don't have done to many plan's for the next years. keep on trying mfg aotto :) From TKuchenbuch at gmx.de Tue Oct 23 06:30:53 2001 From: TKuchenbuch at gmx.de (Timo Kuchenbuch) Date: Tue, 23 Oct 2001 11:30:53 +0100 Subject: I searsch a GroupWare Tool for Zope! Message-ID: <9r3dac$b03$05$1@news.t-online.com> Hi all! Do you know a GroupWare Tool for Zope? thanks Timo From donn at u.washington.edu Mon Oct 8 17:26:05 2001 From: donn at u.washington.edu (Donn Cave) Date: 8 Oct 2001 21:26:05 GMT Subject: why are *two* ctrl-D's needed with readline() References: Message-ID: <9pt5ld$ube$1@nntp6.u.washington.edu> Quoth "Wilhelm Fitzpatrick" : | --- In python-list at y..., Marcin 'Qrczak' Kowalczyk wrote: |> Fri, 5 Oct 2001 14:34:17 -0400, Steve Holden pisze: |> |> > Technically ^D terminates transmission, and only raises EOF if this |> > result in an empty input buffer, which it does if entered before |> > inputting any characters. |> |> So in normal circumstances programs shouldn't try to read after EOF |> was seen, because it makes a difference for terminals. | | So would it be reasonable to report this as a bug? Certainly, I found | the behavior surprising and non-standard... Steve's point was, if I recall correctly, that you shouldn't expect EOF unless input was at beginning of line, from the point of view of the TTY driver or whatever's emulating it. So phrasing it as a question - do you see this phenomenon when input is already at beginning of line? If you do, then it's a bug. In the present case, I would guess that you have the GNU readline module built in, and the bug is some interaction between that library, on your version of Linux/glibc, and readlines(). Donn Cave, donn at u.washington.edu From tmoero at yahoo.invalid Fri Oct 12 04:36:24 2001 From: tmoero at yahoo.invalid (tm) Date: Fri, 12 Oct 2001 17:36:24 +0900 Subject: OT: This is a useless thread. (was: YOU ARE ALL GAY!) References: <3BC6A9D9.2030608@redhat.com> Message-ID: Michael Lee Yohe wrote: > Please quit cross-posting this big piece of excrement. Okay. From sburr at home.com Mon Oct 22 18:24:10 2001 From: sburr at home.com (sburrious) Date: 22 Oct 2001 15:24:10 -0700 Subject: Writing to SdtErr References: <1003757605.11708.0.nnrp-14.d4f0f8ae@news.demon.co.uk> Message-ID: <5396362c.0110221424.173bf1f5@posting.google.com> Michael Hudson wrote in message news:... > "Mike Peat" writes: > > > Can anyone tell me how to: > > 2) Write (print) to the StdErr channel instead of StdOut? > > print >> sys.stderr, "foo" Don't let Alex Martelli catch you promoting the use of ">>." :) Two alternatives: (1) $ cat > stderrwrite.py import sys sys.stderr.write("Now go away,\n") print "or I shall taunt you a second time!" $ python stderrwrite.py > afile Now go away, $ cat afile or I shall taunt you a second time! (2) $ cat > redirect.py import sys stdoutholder = sys.stdout sys.stdout = sys.stderr print "Your father was a hamster," sys.stdout = stdoutholder print "and your mother smelled of elderberries!" <03:17pm> ~ $ python redirect.py > afile Your father was a hamster, <03:18pm> ~ $ cat afile and your mother smelled of elderberries! From pho56 at yahoo.com.au Thu Oct 18 23:44:38 2001 From: pho56 at yahoo.com.au (Phil Ho) Date: 18 Oct 2001 20:44:38 -0700 Subject: HELP -- py2exe failed to build app that uses scipy.plt Message-ID: <436bca17.0110181944.247f4ecd@posting.google.com> Hi, Sorry for this lengthy message. I do appreciate if you could help, give me some hints or workarounds etc. for this py2exe (0.2.6) conversion problem. I built an application under Windows NT4.0 with ActivePython 2.1.1, SciPy-0.1 and wxPython 2.3. Basically it has: 1. An GUI in wxPython 2. Access binary data from a database that return as Numeric arrays. 3. Plot the data array using scipy.plt which is also implemented in wxPython. The app worked happily by activating 'python hat.pyw'. However, I was unable to use py2exe to convert to an executable due to errors as attached at end of this message. I found out the scipy.plt module that caused the problem because py2exe will convert successfully if the codes that use scipy.plt are commented out. Thank you. Phil Atatched py2exe error messages: running py2exe running build running build_scripts not copying hat.pyw (up-to-date) running install_scripts not copying build\scripts\hat.pyw (output up-to-date) +---------------------------------------------------- | Processing script hat.pyw with py2exe-0.2.6 +---------------------------------------------------- Searching modules needed to run 'hat.pyw' on path: ['C:\\Pho\\hat\\wxwin\\build\\bdist.win32\\winexe\\lib\\usr\\Python21', '', 'H:\\python\\Lib', 'C:\\usr\\Python21\\Pythonwin', 'C:\\usr\\Python21\\win32', 'C:\\usr\\Python21\\win32\\Lib', 'C:\\usr\\Python21', 'C:\\usr\\Python21\\DLLs', 'C:\\usr\\Python21\\lib', 'C:\\usr\\Python21\\lib\\plat-win', 'C:\\usr\\Python21\\lib\\lib-tk', 'C:\\usr\\Python21\\Numeric', 'C:\\usr\\Python21\\PPM'] warning: install: modules installed to 'build\bdist.win32\winexe\lib\usr\Python21\', which is not in Python's module search path (sys.path) -- you'll have to change the search path yourself Traceback (most recent call last): File "setup.py", line 14, in ? scripts = ["hat.pyw"] File "C:\usr\Python21\lib\distutils\core.py", line 138, in setup dist.run_commands() File "C:\usr\Python21\lib\distutils\dist.py", line 899, in run_commands self.run_command(cmd) File "C:\usr\Python21\lib\distutils\dist.py", line 919, in run_command cmd_obj.run() File "C:\usr\Python21\py2exe\py2exe.py", line 312, in run mf.run_script(script) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 98, in run_script self.load_module('__main__', fp, pathname, stuff) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in load_module self.scan_code(co, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in scan_code self.import_hook(name, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in import_hook q, tail = self.find_head_package(parent, name) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in find_head_package q = self.import_module(head, qname, parent) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in import_module m = self.load_module(fqname, fp, pathname, stuff) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in load_module self.scan_code(co, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in scan_code self.import_hook(name, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in import_hook q, tail = self.find_head_package(parent, name) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in find_head_package q = self.import_module(head, qname, parent) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in import_module m = self.load_module(fqname, fp, pathname, stuff) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 250, in load_module m = self.load_package(fqname, pathname) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 324, in load_package self.load_module(fqname, fp, buf, stuff) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in load_module self.scan_code(co, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in scan_code self.import_hook(name, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in import_hook q, tail = self.find_head_package(parent, name) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in find_head_package q = self.import_module(head, qname, parent) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in import_module m = self.load_module(fqname, fp, pathname, stuff) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in load_module self.scan_code(co, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in scan_code self.import_hook(name, m) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in import_hook q, tail = self.find_head_package(parent, name) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in find_head_package q = self.import_module(head, qname, parent) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in import_module m = self.load_module(fqname, fp, pathname, stuff) File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 254, in load_module co = compile(fp.read()+'\n', pathname, 'exec') File "", line 30 """ ^ SyntaxError: invalid syntax From db3l at fitlinxx.com Wed Oct 24 19:03:26 2001 From: db3l at fitlinxx.com (David Bolen) Date: 24 Oct 2001 19:03:26 -0400 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 24) References: <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E@lp.airnews.net> Message-ID: Oleg Broytmann writes: > On Wed, Oct 24, 2001 at 12:59:52PM -0500, Cameron Laird > wrote: > > In article <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E at lp.airnews.net>, > > Cameron Laird wrote: > > Two different Cameron Lairds talk to each other? (-: Either that or one half of the brain is picking on the other half... -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From reqhye72zux at mailexpire.com Tue Oct 16 21:27:15 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Wed, 17 Oct 2001 01:27:15 -0000 Subject: Extending Python - variable sized arrays? References: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> <9qi8f2$o0o9a$1@ID-75083.news.dfncis.de> Message-ID: Tim Egbert wrote: > ret = Py_BuildValue("iiiiii", > arr[0],arr[1],arr[2],arr[3],arr[4],arr[5]); > > I can't go the Py_BuildValue() route because the problems is, the > next time around, there may be 17 or 127 elements in the array, the > exact number only to be known during runtime. > > Any thoughts on how to do this? Py_BuildValue() is a convenience function, there is a more general way to build a tuple: look at section 7.2.4 of the Python manual (Python/C Api; Concrete Objects; Sequence Objects; Tuple Objects). It tells you all about tuples in C. I haven't tried it, but the PyTuple_New(N) function, followed by N calls to PyTuple_SetItem() should do the trick. (Which just shows that tuples aren't as immutable as you might have thought, at least not from C. Use that privilege judiciously, though, it has all the power of a foot seeking missile.) Robert Amesz From phr-n2001d at nightsong.com Sat Oct 13 06:11:55 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 13 Oct 2001 03:11:55 -0700 Subject: webserver performance (was Re: Why so few Python jobs? (and licenses)) References: <7xwv2418xk.fsf@ruckus.brouhaha.com> <9q6a1u$ke9$1@serv1.iunet.it> <7xr8s8q21l.fsf@ruckus.brouhaha.com> <9q90ci$hdk$1@lancelot.camelot> Message-ID: <7xk7xz6e8k.fsf@ruckus.brouhaha.com> Alex Martelli writes: > http://www.acme.com/software/thttpd/benchmarks.html > and they do show that even-based ('select') servers leave all others in the > dust (700+ to 1000+ requests per second on the test configuration, versus > 250 for Apache and 45 for architectures based on Java threads). The test > config is a 300 MHz UltraSparc, but I don't have a good feeling for what > that implies in terms of overall machine performance. They do make the > point that any of these servers can saturate a T1 line when running on a > Pentium-100, though:-) -- so unless you're serving on a fast LAN-based > intranet using rather oldish hardware, server performance shouldn't be a > crucial issue, should it? A 300 MHz Ultrasparc is comparable to a 500 MHz Celeron/PIII, probably. On the other hand, Solaris's context switch overhead is quite a bit worse than Linux's, so the Apache to Thttpd speed ratio probably isn't as bad on a Linux box as under Solaris. We were running what we hoped would be a huge ecommerce site (dotcom dreams) with most of the pages served via SSL, so we cared about speed. From wberger at ccil.org Mon Oct 8 16:23:51 2001 From: wberger at ccil.org (William Wonneberger) Date: 8 Oct 2001 13:23:51 -0700 Subject: Problems With ColourSelect Box Inside A wxDialog Message-ID: <9e7d101d.0110081223.32a8217e@posting.google.com> Greetings; I'm trying to add a wxPython ColourSelect control to a wxDialog box inside a Python script I've been working on. To instantiate the ColourSelect control, I've added the following statement to my Python script; self.colorselect = ColourSelect(self, wxPoint(70, 200), [0, 0, 110], wxDefaultSize) where self is my own subclass of wxDialog. When I run the script that contains the dialog with the ColourSelect control, the dialog box displays, however, the ColourSelect control is not visible. And, when I quit the script, I receive the following trace; 16:06:29: There were memory leaks. 16:06:29: ----- Memory dump ----- 16:06:29: wxColour at $1133778, size 16 16:06:29: 16:06:29: 16:06:29: ----- Memory statistics ----- 16:06:29: 1 objects of class wxColour, total size 16 16:06:29: 16:06:29: Number of object items: 1 16:06:29: Number of non-object items: 0 16:06:29: Total allocated size: 16 16:06:29: 16:06:29: (Note: in running the script with this dialog, I only displayed the dialog box with the ColourSelect once). And, to make sure I have the correct version of the ColourSelect wxPython control, I updated to use the most current version of ColourSelect.py from Lorne White's web site (http://www.telusplanet.net/public/lwhite1/pymodules/lib/colourselect.py) A couple of questions; Am I instantiating the ColourSelect control correctly? Am I missing an additional statement to enable or make visible the ColourSelect dialog box? I'm running ActivePython 2.1.1 Build 212, with the hybrid install of wxPython 2.3.1 for Win32. My platform is Windows 2000 Professional with SP2 applied. Any help or suggestions would be greatly appreciated. Thank you in advance for your time and help. Bill Wonneberger wberger at ccil.org From mj_dup at yahoo.com Thu Oct 25 10:17:00 2001 From: mj_dup at yahoo.com (Suresh) Date: 25 Oct 2001 07:17:00 -0700 Subject: question on using format in struct module References: <3BD74226.F403A98C@home.net> Message-ID: Chris, Thanks for your suggestions ! Here is the snippet of code which writes the binary file. Can you help me out specifying what the format would be in this case for struct module ? Chris Barker wrote in message > If you still can't figure this out, send us some information about the > file (maybe a snippet of the code that wrote it), or ask the person who > wrote the code that created the file to help you with the format > string(s). ================================================================================ ================================================================================ // Write the magic number which are integer. // // MAGIC_NUMBER_2X - Plan parameters, inspected/accepted status // MAGIC_NUMBER_30 (this is an integer) - Extends 2X by storing // prescription parameters // and the dose engine settings // --------------------------------------------------------------- (void)fwrite(MAGIC_NUMBER_30, MAGIC_NUMBER_SIZE, 1, fo); //--- write out the magic number // In the old Rplan we wrote out the plan description here, // but I don't write out anything b/c we don't have a // description to our plans. //----------------------------------------------------------- char description[128]; sprintf(description, "Rplan 3.0 Plan file"); (void)fwrite(description, sizeof(description), 1, fo); // save the centerpoints //-------------------------- (void)fwrite(¢erpts, sizeof(int), 1, fo); for (i = 0; i < centerpts; i++) { currIsocPnt = getIsocPnt(i); (void)fwrite(&(currIsocPnt.y()), sizeof(float), 1, fo); (void)fwrite(&(currIsocPnt.x()), sizeof(float), 1, fo); (void)fwrite(&(currIsocPnt.z()), sizeof(float), 1, fo); } // save the Cum Arcs //---------------------- (void)fwrite(&cumArcs, sizeof(int), 1, fo); ================================================================================ ================================================================================ Since number of CenterPoints vary for each input data given to the software and this value being not fixed, I am unable to decide upon how many floats should I provide to the "format" variable in struct module ? I should find out if there is any dynamic way of telling python code. Thank you, ./Suresh From phr-n2001d at nightsong.com Tue Oct 16 01:58:13 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 15 Oct 2001 22:58:13 -0700 Subject: FW: [Python-Dev] conditional expressions? References: <9qfu1p$iei$1@newshost.accu.uu.nl> <7xitdg4efs.fsf@ruckus.brouhaha.com> <9qgcvk$91j$1@animus.fel.iae.nl> Message-ID: <7x8zec3z4a.fsf@ruckus.brouhaha.com> Carel Fellinger writes: > > A conditional expression analogy to list comprehensions would be > > x = (a if b else c) > > though I think I like this spelling more, you mixed up a and b, and > that's probably a likely mistake, so a big disadvantage. On the other > hand this clearly looks like an expression to me, a big advantage. To have the same meaning as the other example, yes. I should have not just copied the letters from the other example. Thinking about it, I like this syntax more too, but since I think parenthesized S-expressions are the one true syntax, I'm not too fussy about which imperfect substitute gets chosen ;-). From gward at mems-exchange.org Wed Oct 17 15:03:38 2001 From: gward at mems-exchange.org (Greg Ward) Date: Wed, 17 Oct 2001 15:03:38 -0400 Subject: Termcap/terminfo for Python? Message-ID: <20011017150338.A4991@mems-exchange.org> Does anyone know if there exists an interface to termcap or terminfo for Python? I did a Google search for "terminfo python", and the only vaguely relevant hits were: * O'Reilly's *Termcap & Terminfo* book (because O'Reilly's sidebar has the word "Python" in it) * a post to comp.long.python by Oliver Andrich from 1996 Not a good sign. Perhaps I'm missing something. Or am I really the only person in Python's long and glorious history who has wanted to find out the width of his terminal? Greg -- Greg Ward - software developer gward at mems-exchange.org MEMS Exchange http://www.mems-exchange.org From sholden at holdenweb.com Mon Oct 29 07:05:40 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 07:05:40 -0500 Subject: Multiple postings Message-ID: <6zbD7.7674$1I3.451273@atlpnn01.usenetserver.com> Sorry about the recent spate of duplicated postings. A glitch in my mail server meant that it was accepting postings without telling my news client they had been taken. regards Steve -- http://www.holdenweb.com/ From mlh at idi.ntnu.no Sat Oct 27 14:28:18 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 27 Oct 2001 20:28:18 +0200 Subject: Question: CPython References: <3BD79BBC.B2FA669B@hotmail.com> Message-ID: <9reuc2$drq$1@tyfon.itea.ntnu.no> "Robert Amesz" wrote in message news:Xns9147A81E1093rcamesz at amesz.demon.nl... > Lucio Torre wrote: > > > scott wrote: > > > >> [JPython] > >> > >>Called 'Jython' now. Its predecessor was JPython. > >>http://www.jython.org > >> > > And python is now called Cython. :) > > > I'd prefer Scython: much more 'cutting edge'. Damn! I was thinking about using that for a Python with scheme/lisp syntax... Oh, well :) > > Robert Amesz -- Magnus Lie Hetland http://hetland.org From MarkH at ActiveState.com Mon Oct 22 09:42:32 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Mon, 22 Oct 2001 13:42:32 GMT Subject: Windows/COM events/strange behavior References: Message-ID: <3BD4226E.7070603@ActiveState.com> Krzysztof Czarnowski wrote: > alive. The script is being started from a DOS prompt. Module "threading" is > used. The COM event handler is constructed inside the thread and it lives in > a "single threaded appartment" (CoInitialize(), loop PumpWaitingMessages(), > CoUninitialize()). Sounds perfect :) > Then, when I start Pythonwin it gets stuck! When I stop the script Pythonwin > seems to get released and starts (the window is displayed ...). Then I can > run the script again without problems. What is the main loop doing. It too should be sitting on a PumpWaitingMessages() loop. Pythonwin is almost certainly waiting for a DDE request to finish, and somehow the script is blocking this DDE behaviour. Using "pythonwin /nodde" would help, but you may still find some other apps being similar things (eg, installer applications often block in these situations, etc) Mark. From qrczak at knm.org.pl Tue Oct 23 11:29:56 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: Tue, 23 Oct 2001 15:29:56 +0000 (UTC) Subject: POLL in different OSes References: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> Message-ID: Tue, 23 Oct 2001 10:18:40 +0200, Gerhard H?ring pisze: > Wouldn't it be possible to emulate poll() with select()? Should be possible. 'man poll' on Linux says: AVAILABILITY The poll() systemcall was introduced in Linux 2.1.23. The poll() library call was introduced in libc 5.4.28 (and provides emulation using select if your kernel does not have a poll syscall). -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From loredo at astro.cornell.edu Wed Oct 10 15:24:29 2001 From: loredo at astro.cornell.edu (Tom Loredo) Date: Wed, 10 Oct 2001 15:24:29 -0400 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> <3BBE6A57.FD354FE3@alcyone.com> <7xlmipcji1.fsf@ruckus.brouhaha.com> <3BBEB99A.A1F0F9D7@alcyone.com> Message-ID: <3BC4A06D.F8693C41@astro.cornell.edu> Johann Hibschman wrote: > > >>>>> "Erik" == Erik Max Francis writes: > > Erik> You're missing the point. Quaternions can behave > Erik> qualitatively differently from their corresponding matrices. > > Eh? Say you have the Pauli spin matrices (complex 2x2 matrices), how > on earth do those behave qualitatively different from quaternions? As > far as I can tell, they *are* quaternions. Erik's point is that the Pauli matrices are not quaternions (an algebraic abstraction), but rather provide a matrix representation of the quaternion algebra. You can use the algebra simply by following its rules directly, without using the matrix representation. What the matrix representation buys you is that you can implement the more complicated multiplication rule of quanternion algebra in terms of sets of standard real multiplications. What it may cost you (besides efficiency) is that some calculations that are well-posed using the algebra directly become numerically ill-posed using a particular matrix representation. I don't know any such operations off the top of my head, but Erik's assertion is plausible to me. Cheers, Tom Loredo From stephen.boulet at motorola.com Tue Oct 9 15:34:09 2001 From: stephen.boulet at motorola.com (Stephen Boulet) Date: Tue, 09 Oct 2001 14:34:09 -0500 Subject: Assigning to lists with arbitrary names Message-ID: <3BC35131.C9AB1393@motorola.com> I can't quite figure out how to do this. I have 100 text files in a directory: file00.txt to file99.txt. I want to read each file in turn, parse it, and generate a list from each file. Here's the problem: I want to name each list list00 to list99. I don't want to do list[0] to list[99] (since each list is actually a list of lists, and I'd like to avoid a list of lists of lists :). Any idea how I can do this? Thanks. -- Stephen From jdueu84r8773 at Flashmail.com Wed Oct 31 08:32:04 2001 From: jdueu84r8773 at Flashmail.com (jdueu84r8773 at Flashmail.com) Date: Wed, 31 Oct 2001 08:32:04 Subject: leads reaching your internet clients ko1200 Message-ID: <200111010010.JAA15417@kutv01.kutv.co.jp> Do you need new leads for your business ? Do you need increased Internet Exposure ? Thousands join the Internet daily.... ever since 1995 Have you reached the thousands of new internet users? Search Engines: work IF you're in the TOP 20 among thousands Classifieds: work IF your ad is near the top among thousands Banner Ads: work IF you use top engines for a lot of money ALL 3 require prospects TO FIND YOU FIRST among thousands. Did you know that there is a method of marketing that costs pennies but have the same effect as direct postal mail? AND THEY DONT HAVE TO FIND YOU ... bring it straigt on ... You can now compete with the big boys, with exposure in mass numbers, without expensive investments such as those associated with TV, radio, direct postal mail, or telemarketing. THE SOLUTION ... E-mail Marketing E-mail Marketing is a proven method to reach a global market with a small investment. It is more advantageous than conventional marketing. The prospects are millions and can be reached for much less than conventional methods. Send your ad to millions nationwide, by state, country or worldwide. ACT NOW and reach your untapped internet market ! Call : 6 2 6 8 2 1 3 1 5 0 Mention your 1) name 2) tel 3) service needed ACT NOW and reach your untapped internet market ! From johnroth at ameritech.net Sat Oct 13 00:07:55 2001 From: johnroth at ameritech.net (John Roth) Date: Fri, 12 Oct 2001 21:07:55 -0700 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: Message-ID: "Tim Peters" wrote in message news:mailman.1002927732.24673.python-list at python.org... > [Michael Chermside, on a conditional expression] > > ... > If people sign off on taking "then" as a new keyword, I think the chances > are good that we could get > > x = if e1 then e2 else e3 > > into 2.2b1. That's the only obvious spelling, hence the only truly Pythonic > way to spell it. Other languages spelling it that way range from Algol-60 > (Guido's first intense language affair) to Haskell. I've got no problem with it. I don't think I've ever named a variable 'then' in my life. Even in assembler. John Roth From barghest at wanadoo.fr Fri Oct 26 11:00:42 2001 From: barghest at wanadoo.fr (Barghest) Date: Fri, 26 Oct 2001 16:00:42 +0100 Subject: Parse XML using DTD ?? Message-ID: <9rbq0o$a3l$1@reader1.imaginet.fr> Hi, Is it possible to parse an XML doc with DTD in python... ? There's a perl wrapper to use Xerces which is able to do that, but it doesn't work on win32, so i want to if it exists in python.... From ignacio at openservices.net Wed Oct 3 03:30:59 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 3 Oct 2001 03:30:59 -0400 (EDT) Subject: COM and win32 - casting com to string In-Reply-To: <1002093124.20881.0.nnrp-14.c2de2503@news.demon.co.uk> Message-ID: On Wed, 3 Oct 2001, Paul Brian wrote: > I am trying to automate excel, and have been relatively successful. > I can start up a python com client from win32 extentions and bring up excel > as a server. (I hope I got that the right way round :-) > > I can then identify "named ranges" in excel (a group of cells that I > previously told excel to keep track of) > > the code: > x = excelAppl.ActiveWorkBook.Names > for namerange in x: > print namerange > gives me my two ranges back: > =Sheet1!$D$3:$G$3 > =Sheet1!$D$4:$D$7 > > all I want to do know is split those into the sheet1 and the $D$3.... > > however the two results are not python instances but > > > > I cannot perform string operations, repr does not help and type() just tells > me they are "instances" - can anyone tell me what I am doing wrong. > I expect I am not understanding something about com / win32. Does str() have any effect? -- Ignacio Vazquez-Abrams From rxg218 at psu.edu Sun Oct 28 10:41:55 2001 From: rxg218 at psu.edu (Rajarshi Guha) Date: Sun, 28 Oct 2001 10:41:55 -0500 Subject: how tu utilize win32com? Message-ID: <9rh8u5$tsa@r02n01.cac.psu.edu> Hi, I've been programming in Python on Linux for some time now and I was getting bugged by the lack of propter scripting on Windows. So I installed the Activestate Python on my Win machine - however how can I utilize the win32com module. Where can I go fo a list of available methods, say for, a win32com.client.Dispatch("Word.Application") object? Similarly for constants and so on. Are there any tutorials on this topic? I've never done any Windows programming before, so this is totally new for me. Any suggestions would be really appreciated TIA -- ------------------------------------------------------------------- Rajarshi Guha | email: rajarshi at presidency.com 152 Davey Laboratory | web : www.rajarshi.outputto.com Department of Chemistry | ICQ : 123242928 Pennsylvania State University | AIM : LoverOfPanda ------------------------------------------------------------------- GPG Fingerprint: E8F3 281F 93A9 C90C 853E 5136 8455 201B C92F F3E7 Public Key : http://pgpkeys.mit.edu/ ------------------------------------------------------------------- Entropy requires no maintenance. -- Markoff Chaney From slinkp23 at yahoo.com Thu Oct 11 15:58:20 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Thu, 11 Oct 2001 19:58:20 GMT Subject: help: Crossplattform audio functionality in Python References: Message-ID: On Thu, 11 Oct 2001 17:48:34 GMT, Olov Johansson wrote: >Both these libraries would suit my needs (libao would be the easiest to use >because the python stuff is already written afaik), but in the longer term.. >The Python core needs (imho) a builtin soundsystem which works on all >platforms. I agree. It's scattered across various modules - e.g. al for SGI, sunaudiodev for Sun, and they have different interfaces. Another option, though no python bindings exist yet: Portaudio, see http://www.portaudio.com --PW From tim.one at home.com Mon Oct 15 16:22:29 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 15 Oct 2001 16:22:29 -0400 Subject: FW: [Python-Dev] conditional expressions? Message-ID: Following is good clarification from Guido (on Python-Dev) about "the rules" currently implemented by his patch. -----Original Message----- Sent: Monday, October 15, 2001 3:24 PM Subject: Re: [Python-Dev] conditional expressions? ... I think you must be misunderstanding the proposal, which is to add if then else as an alternative to the expression syntax. Here's a preliminary patch (which I won't apply until I have more confidence that this is acceptable to the community): The parens in this proposal (my version) act no different than any other use of parentheses in Python expressions. Basically, you need to add parentheses to disambiguate expressions: - if otherwise the 'if' keyword would be the start of a statement (because 'if' at the start of a statement starts an if *statement*, and the parser can't look ahead for the 'then' keyword); - if the conditional expression is to be combined with a unary or binary operator. Some examples where no parentheses are needed (note that a comma binds less tight than a conditional expression -- same as for lambda): x = if 1 then 2 else 3, y f(if 1 then 2 else 3, y) a[if 1 then 2 else 3, y] `if 1 then 2 else 3` lambda: if 1 then 2 else 3 Some examples where parentheses *are* required: (if 1 then 2 else 3) + 4 a[(if i then 2 else 3) : 4] In some situations I'm not sure what's right; The un-parenthesized form looks weird although it's not neede to avoid ambiguity: if (if 1 then 2 else 3): pass print (if 1 then 2 else 3) for i in (if 1 then "abc" else "def"): pass I'd be happy to discuss this more. I'm *not* happy with responses like "is this a bad joke?". I don't understand how this could be an argument in the arsenal of the anti-Python league. --Guido van Rossum (home page: http://www.python.org/~guido/) From johnroth at ameritech.net Sat Oct 13 21:01:13 2001 From: johnroth at ameritech.net (John Roth) Date: Sat, 13 Oct 2001 18:01:13 -0700 Subject: signum() not in math? References: Message-ID: "Tim Peters" wrote in message news:mailman.1002968112.31501.python-list at python.org... > > I expect you severely underestimate the arguments there *would* be over "the > correct" signum function: what to do about a 0 argument; which types it > should accept; which type(s?) it should return; if signum(0.0) returns a > float 0, whether the sign of 0 needs to be preserved or erased, or whether > that's undefined; if signum(0.0) returns a 1, ditto for reflecting the sign > of the input; what to do about NaN arguments; and whether subclasses of > numeric types and/or new numeric types need a way to override the base type > signum implementation (since you brought up the parallel, note that numeric > types *can* override __abs__, and that requires a whole slew of machinery in > the class and type implementations, and adding new slots for numeric types > at the C level creates cross-release binary compatibility headaches too). Come on, Tim. Most of these questions have fairly rational answers. To try a prototype definition: sign(x) returns a value of either 1 or -1 with the same sign and type as the input. If the input is zero and the numeric type does not distinguish between +0 and -1, it returns 1. It returns a NaN for a silent NaN, and raises the appropriate exception for a signaling NaN. sign0(x) is the same as sign(x), except that it returns a zero value for a zero input. It is the implementors discretion as to whether to return the same object or a different object with the same value in this case. Any class or type which implements numeric methods can implement these functions by including a __sign__ or __sign0__ method. Both functions raise a TypeError if the input is not a scalar numeric type, or is a class instance without either __sign__ or __sign0__ defined. The binary compatibility problem is not unique to this proposal John Roth From BrianQ at ActiveState.com Fri Oct 26 17:40:59 2001 From: BrianQ at ActiveState.com (Brian Quinlan) Date: Fri, 26 Oct 2001 14:40:59 -0700 Subject: A small inconsistency in syntax? In-Reply-To: Message-ID: <001301c15e66$e9aabb00$b503a8c0@activestate.ca> I could want to write: a = ['x value','y value','z value'] = x Here the intermediate list is doing 3 things for me: 1. it's providing documentation 2. it's forcing the sequence type to be of length 3 3. it's making the type assigned to 'a' a list -- Brian Quinlan BrianQ at ActiveState.com From wtanksle at dolphin.openprojects.net Fri Oct 26 17:14:16 2001 From: wtanksle at dolphin.openprojects.net (William Tanksley) Date: Fri, 26 Oct 2001 21:14:16 GMT Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> <3BD995CB.22D3507A@home.net> <2jhC7.23321$IR4.13366040@news1.denver1.co.home.com> <_ohC7.38719$Nx2.821986@atlpnn01.usenetserver.com> Message-ID: On 26 Oct 2001 23:05:23 +0200, Chris Liechti wrote: >this; [1,2][1]=23 >should raise an "SyntaxError: can't assign to literal", but does not. Why? There are many types of literals; some of them are mutable and some are immutable. You can't assign to an immutable literal (try your example with a tuple), but there's no reason to stop you from assigning to (or modifying) a mutable literal. This statement, in this case, has the effect of converting the [1,2] list to [1,23], and then discarding it. >Chris -- -William "Billy" Tanksley From m.faassen at vet.uu.nl Tue Oct 16 07:51:36 2001 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 16 Oct 2001 11:51:36 GMT Subject: FW: [Python-Dev] conditional expressions? References: Message-ID: <9qh708$eve$1@newshost.accu.uu.nl> Anthony Baxter wrote: > Ok, so we're getting yet another ugly hack added to the language. > Could the normal process of writing up a PEP be followed, so that > those people in the community who are uncomfortable about it can > at least see the justification for this? > Or has the PEP already been written, and I'm just going mental - it > doesn't appear to be on the PEP page... No, there's no PEP yet. From what I've seen everybody, including Guido, thinks a PEP and some time to consider the PEP is a good idea, though... Regards, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From dalke at dalkescientific.com Wed Oct 10 13:24:08 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 10 Oct 2001 11:24:08 -0600 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <7x4rp8q1cy.fsf@ruckus.brouhaha.com> Message-ID: <9q20bh$mjs$1@slb3.atl.mindspring.net> Michael Abbott wrote: >More to the point, I don't see any room for any >bugs at all here (let alone obscure ones), since the offending syntax is >caught by the "compiler". Suppose there's an attribute named 'j'. Under current Python >>> 3.j 3j >>> 3. j File "", line 1 3. j ^ SyntaxError: invalid syntax >>> If the space is allowed as shorthand for getattr(3, "j") then there is a chance for obscure bugs. But I've never seen anyone who even considered the idea of methods or attributes on numbers in Python (note the "in Python") excepting those few that come from Smalltalk or Ruby backgrounds. Andrew dalke at dalkescientific.com From jjl at pobox.com Tue Oct 2 14:04:13 2001 From: jjl at pobox.com (John J. Lee) Date: Tue, 2 Oct 2001 19:04:13 +0100 Subject: gracePlot.py In-Reply-To: References: <9p316p$9uh@gap.cco.caltech.edu> Message-ID: On Mon, 1 Oct 2001, DeepBlue wrote: > Does gracePlot have any support for plotting in 3-D space? No Also, can we > export data points into csv files? You can do that with the Numeric package easily, write it yourself (a couple of lines, I expect) or use one of the several modules around that do that kind of thing. Scipy has a module like that, I'm sure. > How does it compare to GNUplot? The major difference is that Grace has a GUI. John From phr-n2001d at nightsong.com Mon Oct 8 06:34:31 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 08 Oct 2001 03:34:31 -0700 Subject: += doesn't work in python cgi's References: <3BC17D83.A4EEED81@tpg.com.au> Message-ID: <7x7ku62zew.fsf@ruckus.brouhaha.com> Your web server is running under a different user or something, so it gets a different PATH than your command line. That's making it run Python 1.5 which doesn't support +=. Change /usr/bin/env python to wherever your Python 2.x executable is, e.g. /usr/local/bin/python. From nmw at ion.le.ac.uk Mon Oct 1 09:40:31 2001 From: nmw at ion.le.ac.uk (Nigel Wade) Date: 01 Oct 2001 14:40:31 +0100 Subject: Problem with linking embedding C application References: <9p9h2l$24o$1@kermit.esat.net> Message-ID: "Olivier Deme" writes: > Hi, > > We have written an application written in C, which invokes sometimes the Python > interpreter for executing Python methods. > > So, I am trying to statically link our application with libpython*.*.a., but this result in various > undefined symbols (see below). > > Now, it looks like I am missing symbols defined in the math and posix thread library! I don't > understand this since we are not using any symbols defined in these libraries. > Could anybody tell me what is going on and how I can fix this problem? > > Thanks! > Because Python uses them. Add the correct list of libraries to the link library list. Probably some combination of the following: -ldb -lpthread -lnsl -ldl -lm at the very least -lpthread and -lm as you have already found out. Not sure how many of these are available as static (archive) libraries. -- Nigel Wade From mats at laplaza.org Thu Oct 4 14:23:08 2001 From: mats at laplaza.org (Mats Wichmann) Date: Thu, 04 Oct 2001 18:23:08 GMT Subject: Assignment not the same as defining? References: Message-ID: <3bbca829.15581314@news.laplaza.org> On Wed, 3 Oct 2001 22:13:58 -0400, "Tim Peters" wrote: :[Steve Holden] :> ... :> The main thing is to remember that assignment is only one of the :> several (I seem to remember Tim Peters listed five) ways to bind a :> value to a name. : :This isn't really a matter of interpreting goose entrails. You're not supposed to open up the geese anyway, they're sacred in a different way. For more conventional auguries, use a chicken - or, in this case, the manual. Mats Wichmann From rparnes at megalink.net Thu Oct 11 10:05:44 2001 From: rparnes at megalink.net (Bob Parnes) Date: Thu, 11 Oct 2001 09:05:44 -0500 Subject: Event Problem in Tkinter Message-ID: Hi, I am getting a false result in using events in Tkinter to identify the particular widget that a user selects to enter text. I submitted the problem to John Grayson's online help at www.manning.com and got no reply, so I am trying this newsgroup as a last resort. As a test on a linux computer, I prepared the following code to create a 2x2 array of entry widgets. The code is freely adapted from Example_6_2.py in _Python and Tkinter Programming_ ------------------------------ #!/usr/bin/env python2 from Tkinter import * eventList = {'2': 'KeyPress', '4': 'ButtonPress', \ '9': 'FocusIn'} root = Tk() def reportEvent(event): if event.type in eventList.keys(): x = event.x_root y = event.y_root print 'Event: %s, coordinates: %d, %d; widget: %s' \ % (eventList[event.type], x, y, event.widget) if event.type == '9': print '-'*75 fm = Frame(root, border=2) text = [] for n in range(4): text.append(Entry(fm, width=10)) for event in eventList.values(): text[n].bind('<%s>' % event, reportEvent) for n,r,c in ((0,0,0), (1,0,1), (2,1,0), (3,1,1)): text[n].grid(row=r, column=c) fm.pack(padx=8, pady=8) print '\nList of Entry Widgets' for item in fm.winfo_children(): if item.winfo_class() == 'Entry': print item root.mainloop() ----------------------------- If I run the program and use the mouse, for example, to enter the top left entry widget, then tab to the one on its right, I get the followingresult: List of Entry Widgets .135346692.135404836 .135346692.135400852 .135346692.135529924 .135346692.135546500 Event: ButtonPress, coordinates: 47, 546; widget: .135346692.135404836 Event: FocusIn, coordinates: 1076693612, 135248272; widget: None --------------------------------------------------------------------------- Event: KeyPress, coordinates: 190, 679; widget: None Event: FocusIn, coordinates: 1076693612, 135248272; widget: None --------------------------------------------------------------------------- Apparently the ButtonPress event identifies the correct widget, but the FocusIn and KeyPress events do not. Although a user could use only a mouse to move among widgets, I would prefer a tabbing capability as well. Am I missing something? If not, is there an alternate approach? Thanks for any help. -- Bob Parnes rparnes at megalink.net From ralph at inputplus.demon.co.uk Mon Oct 1 06:23:16 2001 From: ralph at inputplus.demon.co.uk (Ralph Corderoy) Date: 1 Oct 2001 11:23:16 +0100 Subject: scanf style parsing References: <3BB16A50.BAE082FE@cygnus-software.com> <9p4a4f$kdd$1@inputplus.demon.co.uk> <9p84u4$dc3$1@panix3.panix.com> Message-ID: <9p9g6k$4u8$1@inputplus.demon.co.uk> Hi, > > An easy, sure fire way for any programmer to learn regex concepts > > is to read Kernighan and Plauger's _Software Tools_ where, amongst > > many other interesting topics, they implement a regex pattern > > matcher and preceed to use it in their versions of grep, ed, etc. > > The problem is that this gives a narrow view of regexes and doesn't > show the full power available in complex regex languages in > Perl/Python. But that's part of its appeal. By just sticking with concatenation, repetition, and alternation you can see through the regex syntax to the implementation and the matching engine. Everything from then on is either syntax enhancements, e.g. r+ == rr*, or stuff that you can easily learn because you've a good grounding. > Much better is _Mastering Regular Expressions_ by Jeffrey Friedl, > though it badly needs freshening. I've read that and I think it goes too deep too soon and takes too many pages to do it. It is also cluttered in having to state all the exceptions at every turn, e.g. `but not in egrep'. _Software Tools_ gives sufficient grounding to a programmer in a chapter. Also, like you say, a large part of _Mastering Regular Expressions_ is out of date since Python and Perl have moved on. Given how much hassle JF said it was to right in the first place I wouldn't expect to see him queing up to right the 2nd Ed. :-) Cheers, Ralph. From claird at starbase.neosoft.com Wed Oct 24 13:59:52 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 24 Oct 2001 12:59:52 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 24) References: <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E@lp.airnews.net> Message-ID: In article <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E at lp.airnews.net>, Cameron Laird wrote: . . . > ActiveState releases PYXPCOM. > http://www.ActiveState.com/Products/Komodo/PYXPCOM . . . Loser. You've got to improve your editorial process. AS released PyXPCOM over ten months ago. The rest of the stuff seems right, though ... -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From uwe at rocksport.de Thu Oct 4 12:02:37 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 4 Oct 2001 16:02:37 GMT Subject: another wxPython-question Message-ID: <9pi16t$5pt1t$1@hades.rz.uni-sb.de> Hi, in the wxWindows documentation I found classes wxDC, wxPaintDC and others. But these are not known if I use wxPython. Is my wxPython installation to old ? I downloaded it from www.wxpython.org... Yours, Uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From greg at cosc.canterbury.ac.nz Tue Oct 23 20:54:16 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 24 Oct 2001 13:54:16 +1300 Subject: 1 is not prime (Re: a better prime number generator) References: Message-ID: <3BD61138.9E1A196C@cosc.canterbury.ac.nz> Paul Winkler wrote: > > # 1 is prime, but we don't want it in the list during the loop > primes.insert(0, 1) The way the primes are usually defined, 1 is not considered prime. So this line should be removed. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From nhodgson at bigpond.net.au Sun Oct 21 18:38:54 2001 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 21 Oct 2001 22:38:54 GMT Subject: editing .asp in PythonWin References: Message-ID: <28IA7.190993$bY5.904602@news-server.bigpond.net.au> Hi Doug, > has anybody used pythonwin as an editor for writing active server > pages? When opening a .asp it seems to do a good job on the > html, but the python is all gray. is there a trick to getting the > python part to show up as the colorful as well as the html, or in > exchange for the html? The most recent version I have used, build 2.1.212 detects ASP files and partly sets up for them, but does not assign colours to the styles appropriately. Instead it applies the Python styles to HTML based on style numbers which are really distinct between the two modes. ASP uses well over a hundred styles but Python only 14. Because of this number of styles, ASP mode needs 7 bits of styling as against Python mode using 5 bits which is the default. This allows Python mode to use 3 bits for other purposes and it does use at least one for indentation error indication. When showing ASP, SCISetStyleBits(7) should be called on the control. Then there is a need to set up the styles which may be as simple as producing an equivalent to the PYTHON_STYLES table in pywin\scintilla\formatter.py for all the ASP styles and choosing to use that instead of PYTHON_STYLES. The style constant names are those entries in pywin\scintilla\scintillacon.py that start with SCE_H. It may require a bit of effort following through the flow of control and I suspect its half a day or so of work to implement this feature. From the evidence of the source_formatter_extensions variable, it looks tome like someone, probably Mark, has put some time into this but hasn't finished it. Neil From phd at phd.pp.ru Thu Oct 18 04:09:43 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 18 Oct 2001 12:09:43 +0400 Subject: Termcap/terminfo for Python? In-Reply-To: <20011017172435.A5370@mems-exchange.org>; from gward@mems-exchange.org on Wed, Oct 17, 2001 at 05:24:35PM -0400 References: <20011017150338.A4991@mems-exchange.org> <20011017233128.E20564@phd.pp.ru> <20011017172435.A5370@mems-exchange.org> Message-ID: <20011018120943.C25821@phd.pp.ru> On Wed, Oct 17, 2001 at 05:24:35PM -0400, Greg Ward wrote: > On 17 October 2001, Oleg Broytmann said: > > curses.tigetflag > > curses.tigetnum > > curses.tigetstr > > Ahh, thank you. > > > I don't know which attributes describe width/height of a terminal. > > For the record: > curses.tigetnum("cols") > curses.tigetnum("lines") Now thank YOU :) I think I'll easily find neccessary information on it. I didn't know about tiget* functions before your question. But I thought "well, there is no direct termcap/info interfaces, may be curses?" and found all neccessary things in docs :) I ran an example, got a traceback with the mesage "at least run setupterm()" - and voila! :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From mwh at python.net Fri Oct 19 05:43:24 2001 From: mwh at python.net (Michael Hudson) Date: Fri, 19 Oct 2001 09:43:24 GMT Subject: dynamic call of a function References: <3BCFE666.C8C6136C@c-s.fr> Message-ID: Michael Hudson writes: > anthony harel writes: > > > I have got a string that contains the name of the function I > > want to call but I don't want to do something like this : > [schnipp] > > Is it possible to do sommething like that : > > ch = "foo" > > apply(ch, ( ))??? > > Well, there's > > eval(ch)() > > but that's rather horrible. > > vars()[ch]() > > is, possibly, better. Oops, I read your english and not your code. What Graham and Paul said applies better. functions aren't quite the same as methods in Python... > More context please. What are you really trying to do? This might still be relavent. Cheers, M. -- LINTILLA: You could take some evening classes. ARTHUR: What, here? LINTILLA: Yes, I've got a bottle of them. Little pink ones. -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From graz at mindless.com Wed Oct 24 14:22:52 2001 From: graz at mindless.com (Graham Ashton) Date: Wed, 24 Oct 2001 18:22:52 GMT Subject: Tk and focusing windows References: Message-ID: <0GDB7.5546$P4.665092@news1.cableinet.net> In article , "Graham Ashton" wrote: > I've got an application which opens two Tk windows as soon as it starts > up; the main window and a progress dialog. > > I want the dialog to be displayed after the main window (so the main > window can't cover it up).... Somebody suggested I have a play with wait_visibility(): http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm I can't get it work though. I've written a small example that demonstrates my problem (below). It creates two top level windows, one of which I've called a dialog, another the main window. I don't want the dialog to be displayed on screen until after the main window has been drawn. It looks like that is what wait_visibility() is there for, but I think I'm using it wrong. The only way I've managed to change the order in which the windows are drawn is by swapping the order in which the code creates them - the last one in the code is the first one on screen. This would be a fairly hackish solution, and I'd have to mess around with my application's logic to do it. Anyway, here's the example. Thanks... -- Graham ---cut--- #!/usr/bin/env python # # How do I get the dialog to be displayed _after_ the window? from Tkinter import * NoDefaultRoot() window = Tk() window.resizable(0, 0) window.title("Main window") widget = Label(window, text="I wait for the dialog, but why?") widget.pack() dialog = Tk() dialog.resizable(0, 0) dialog.title("A dialog") widget = Label(dialog, text="Why is this window drawn first?") widget.pack() widget.wait_visibility(window) # does this do anything? window.mainloop() # same behaviour if we do dialog.mainloop() From gustav at morpheus.demon.co.uk Tue Oct 16 18:00:49 2001 From: gustav at morpheus.demon.co.uk (Paul Moore) Date: Tue, 16 Oct 2001 23:00:49 +0100 Subject: FW: [Python-Dev] conditional expressions? References: <23891c90.0110160824.6a5a0c1b@posting.google.com> Message-ID: On Tue, 16 Oct 2001 13:29:09 -0400, "Steve Holden" wrote: >I particularly shudder for the newbie who must read something like the >following (untested code warning: I'm not building an interpreter that can >handle this stuff, because I'm hoping it will disappear <0.75 wink>): > >l = if a then [i for i in l1 if i % 2] else [i for i in l2 if not i % 2] > >Of course, this might also be cast as: > >l = [i for i in (if a then l1 else l2) if (if a then i % 2 else not i % 2)] I shudder at the thought of having to maintain code written by anyone who thinks that this sort of construct is reasonable. Whether or not it's in the language. Someone psychotic enough to consider writing this sort of thing is presumably already having a field day with lambda. Heck, someone could do serious damage to maintainability with nothing more than the basic operators and some precedence rules... you-can-abuse-anything-if-you-try-hard-enough-ly y'rs Paul. From weismann at netvision.net.il Sat Oct 27 12:54:25 2001 From: weismann at netvision.net.il (Amit Weisman) Date: Sat, 27 Oct 2001 18:54:25 +0200 Subject: Write and read objects from files . Message-ID: <005701c15f08$0979d140$4396003e@rashome> Hi I'm a python beginner and looking for : 1. A way to save a list on a file (as a string) and then retrieve it back (read the string from the file and build automatically a list) . 2. Is there a class or function that provides mechanism to check an e-mail address ? Please notify if my questions aren't relevant to this mailing list . Thanks in advance Amit ---------------------------------------------------------------- Weisman Amit 11 Rupin st. Holon 58344 Israel Tel : 050397330 weismana at cs.bgu.ac.il -------------- next part -------------- An HTML attachment was scrubbed... URL: From sholden at holdenweb.com Wed Oct 31 12:38:07 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 12:38:07 -0500 Subject: newbie question References: Message-ID: " 1" wrote in message news:yXVD7.6251$QL2.175221 at e3500-atl1.usenetserver.com... > ok to keep it simple. Always a good idea. > I am running win98se w/ python 2.1 installed. I have tried this in both > python shell and in command line. > > Just to keep it simple I wrote a file called "hello.py". all that it > contains is a print command (print" hello world!"). I saved the command in > the python dir in my PC and named it "hello.py". > OK so far. When you say "the python dir in my PC", I presume you mean the place where Python got installed. You don't need to put your programs there, and as a general rule you shouldn't. > When I got to run the file (by typing python hello.py)i get this error > message: > > >>> python hello.py > SyntaxError: invalid syntax > >>> > Well, you already typed the command python to get the >>> prompt! Instead of typing that, try typing python hello.py or, if you haven't put yourself in the same directory as your program is stored, maybe python C:\dir\subdir\hello.py > Is there anything that i missed or did wrong. This is just a simple little > example of a bigger problem. > The instructions for using the interpreter have been know to cause confusion, so I wouldn't worry. Just come back again if none of hte above advice helps! regards Steve -- http://www.holdenweb.com/ From jeff at janix.com Mon Oct 8 11:47:08 2001 From: jeff at janix.com (Jeff Sasmor) Date: Mon, 08 Oct 2001 15:47:08 GMT Subject: Apache log file scanner Message-ID: <0Ujw7.291$wO4.40393@dfiatx1-snr1.gtei.net> If anyone is interested in a short Python script that'll scan their Apache web server's log files for break-in attempts from Code Red and a few other worms, you should check out: http://www.netkook.com/Members/jeff/virusprobe I decided to create this when I noticed (for a while now) how many scans from these worms were being made. I'm sure that most anyone reading this newsgroup could write this themselves, but if anyone thinks that he or she might find it useful then they are welcome to download and use it. Scanning my own log files produced a 350 KB file of results, with some IP addresses causing ~250 or more break-in attempts. One turned out to be on the system of the hosting provider I'm using! -- Jeff Sasmor jeff at sasmor.com www.netkook.com is an "open Zope CMF site" From stadt at cs.utwente.nl Tue Oct 23 00:36:56 2001 From: stadt at cs.utwente.nl (Richard van de Stadt) Date: Tue, 23 Oct 2001 05:36:56 +0100 Subject: smtplib.SMTPDataError: (503, 'Error: need RCPT command') Message-ID: <3BD4F3E8.1E4B826B@cs.utwente.nl> Hi, This is the first time I've been using the stuff below with Python 2.1.1 running on Solaris 5.8. I never got the error below before. It runs fine on Linux with Python 1.5.2, and has been running fine for years on a Solaris 5.6 system, with Python 1.5.2, 2.1 and 2.1.1. Could the error below be caused by Solaris 5.8's version of sendmail? Could anyone explain what this RCPT command is that seems to be needed? --------------------- mail.sendmail(fromaddr, recipients, message % locals()) File "/usr/local/pkg/Python-2.1.1/lib/python2.1/smtplib.py", line 496, in sendmail (code,resp) = self.data(msg) File "/usr/local/pkg/Python-2.1.1/lib/python2.1/smtplib.py", line 386, in data raise SMTPDataError(code,repl) smtplib.SMTPDataError: (503, 'Error: need RCPT command') --------------------- Here's a part of my send_email function: ... fromstring = '...' fromaddr = maintaineremail cc_list = string.join ((chairemail, maintaineremail), ', ') date = ctime(time()) dayName = date[:3] + ',' monthName = date[3:7] day = date[7:10] year = date[19:] Time = date[10:19] timeZone = ' ' + tzname[daylight] date = dayName + day + monthName + year + Time + timeZone message = """\ Subject: %(subject)s Date: %(date)s From: %(fromstring)s <%(fromaddr)s> Reply-To: %(fromaddr)s To: %(to_list)s Cc: %(cc_list)s X-Mailer: Python smtplib %(body)s """ try: mail = smtplib.SMTP(LocalMailServer) except: mail = smtplib.SMTP(altLocalMailServer) mail.sendmail(fromaddr, recipients, message % locals()) mail.quit() ---------------------------------- Thanks for your help, Richard. From Mathias.Palm at gmx.net Tue Oct 16 13:41:08 2001 From: Mathias.Palm at gmx.net (Mathias Palm) Date: Tue, 16 Oct 2001 19:41:08 +0200 Subject: pmw "about" dialog In-Reply-To: References: Message-ID: the add_cascade command adds an cascade, not an menu entry. try: aboutmenu.add_command(label="About", command = dialogue_about) and it should work. A cascade is supposed to be a collection of entries. If you can get the source code of python (e.g. the tgz-archives from www.python.org) do it. In the directory Demo/tkinter/ you will find a few examples on how to write tkinter applications. Mathias From hughett at mercur.uphs.upenn.edu Fri Oct 19 12:49:17 2001 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 19 Oct 2001 16:49:17 GMT Subject: Mirror site for tcl/tk? Message-ID: <9qplid$q3h$1@netnews.upenn.edu> My browser can't locate dev.scriptics.com. Does anyone know of a mirror site for tcl/tk so I can get Tkinter up and running? Thanks. Paul Hughett From gb at cs.unc.edu Thu Oct 4 20:11:06 2001 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 04 Oct 2001 20:11:06 -0400 Subject: Profiling the interpreter from within Message-ID: While thinking about where the time goes in the interpreter it occured to me that it should be possible to build a small extension that allows profiling of the interpreter and extensions from within python. The extension, I hallucinate, would turn on statistical profiling using the same interrupt mechanism used to get the times reported by gprof. It works by setting a timer to go off 100 times per second. On each interrupt it examines the return address and increments a counter in an array indicating a "hit" on that address (actually range of addresses). By adding up the counts for the range of addresses included in a function you can get an estimate of the time spent in that function. The second part of this imaginary profiler, would be some python code to enumerate the callables that are associated with C functions and collecting the symbols from the executable (possibly using nm?). Given this info (assuming it could be gotten) the profiler could print the time spent in each function. Is there some fatal problem with this scheme? I may try it when I get time. I've always been a big fan of knowing where the time goes. gb From CpJohnson at edgars.co.za Fri Oct 12 07:48:05 2001 From: CpJohnson at edgars.co.za (CpJohnson at edgars.co.za) Date: Fri, 12 Oct 2001 14:48:05 +0300 Subject: Python CGI Server Message-ID: <42256AE3.0040CAEE.00@JHBMAIL01.edgars.co.za> Hi All, First list posting. I'm trying to call CGI scripts using the CGIHTTPServer library. The CGI script never seems to get invoked. I think that I have traced the problem to the os.popen2() function, which seems to be broken. I'm using Python 2.1C2 with Pythonwin build 140 under Windows 95. Any ideas? Craig From tebeka at cs.bgu.ac.il Wed Oct 17 02:47:58 2001 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 16 Oct 2001 23:47:58 -0700 Subject: makefile for disutils pacakge? Message-ID: <33803989.0110162247.56b508cf@posting.google.com> Hello All, Is there a 'standard' makefile to ship with a distutils package (./setup.py sdist)? I'm currently using: all: @echo Please specify one of the following: @python setup.py --help-commands | head -18 | tail -17 .DEFAULT: python setup.py $@ Thanks. Miki Tebeka From chris.gonnerman at newcenturycomputers.net Thu Oct 11 08:50:08 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 11 Oct 2001 07:50:08 -0500 Subject: how do I add site-packages on Windows? References: <3bc57f3b$0$233$edfadb0f@dspool01.news.tele.dk> Message-ID: <001f01c15253$42ed5da0$0101010a@local> I've never understood why this is done this way. In site.py, the sys.path setup only adds site-packages on Unixoid OS's. On Windows it isn't done. You can add the line to site.py addsitedir(r"c:\python21\site-packages") (for instance) after the section where the sys.path is configured, but unfortunately Distutils won't obey this, so if you use any autoinstallers (setup.py) the modules won't go in site-packages. Does ANYONE know why this decision was made? ----- Original Message ----- From: "Max M" Newsgroups: comp.lang.python To: Sent: Thursday, October 11, 2001 6:15 AM Subject: how do I add site-packages on Windows? > I have had this problem before, but never really got a working solution. > > If I put packages into: > > \Lib\site-packages\ > > And then I try to use it from ie. iis (Windows naturally) Python cannot find > my packages. > > What would I need to do to make Python search in site-package automatically? > > Should I put them into "Plat-Win" instead, or is that used for something > else ??? > > regards Max M > > --------------------------------- > PythonWin 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32. > Portions Copyright 1994-2001 Mark Hammond (MarkH at ActiveState.com) > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From James_Althoff at i2.com Wed Oct 31 15:02:59 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 31 Oct 2001 12:02:59 -0800 Subject: python development practices? Message-ID: Thomas wrote: >Jim wrote: >> ... Publicly-intended methods are >> annotated with "Public" at the start of their doc strings. Anything >> without such annotation -- please use only for debugging or exploring >> (again, outside of the defining class or subclasses). > >I wonder why this reminds me of smalltalk ;-) > >Thomas Just one of those ever fascinating and inexplicable coincidences, I guess? ;-) Jim From gh_pythonlist at gmx.de Tue Oct 9 13:25:38 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 9 Oct 2001 19:25:38 +0200 Subject: changing a strig to a variable In-Reply-To: ; from rd54@cornell.edu on Tue, Oct 09, 2001 at 11:44:11AM -0400 References: Message-ID: <20011009192538.B3209@lilith.hqd-internal> On Tue, Oct 09, 2001 at 11:44:11AM -0400, Raibatak Das wrote: > hi, > > this might be a silly question but i would greatly appreciate an answer. > is there any way to convert a string to a variable name. that is, suppose > i have x = 'var' and i want to do, say, var=13 is there an easy way to do > so? Most of the time, this isn't a good idea and can be replaced by alternative constructs, like dictionaries. For example: salaries = {} # creates a dictionary name = "Joe" # key for the dictionary salaries[name] = 5000 # store a value in the dictionary A dictionary is a mapping from keys to values. In the above example, I mapped employee names to their salaries. The keys can be of any immutable type (strings, ints, but *not* lists, for example). The values can be of any type. If you really really need to do what you asked for (unlikely, I never did), you can use the exec statement or the eval() builtin function. x = 'var' statement = "%s = 'Joe'" % x exec statement or maybe better: exec statement in globals(), locals() Perhaps you want to replace globals() and locals() with custom dictionaries your exec statement works on instead of directly working on the "real" global and local namespace. The eval function works similarly, but returns the value of the expression instead of executing a statement. But exec and eval should only be used as a last resort. Did you have something special in mind? If you tell us what we could most probably describe a better way of accomplishing this task. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From ullrich at math.okstate.edu Wed Oct 17 15:40:54 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Wed, 17 Oct 2001 19:40:54 GMT Subject: Desperate help required for Python assignment References: <602c058e.0110162347.268591ce@posting.google.com> Message-ID: <3bcdde50.1996118099@news> On 17 Oct 2001 00:47:07 -0700, nachiket_gole at hotmail.com (Nachiket) wrote: >I am new to Python doing a crash course in University. I have a >assignment to submit in two days the specifications of which are: >1.Write a script in python which maps a set of linked webpages. It >should take the URL as a command line argument, retireve the page, >extract the URL's of pages linked to by the page in question and store >them in a data structure for the page. It should then repeat this >with other linked pages to a depth of 5. It should visit each page >only once. >2.The script should also be able to take -L as a command line argument >and that being the case should only follow links on the same server as >the current site. >3.The script should also record the titles of links in the documents >eg >Mysite -- > http://mysite.com >4.Finally all this has to be displayed as a tree for eg >>python mytest.py "some url" > http://..... > + http://........ > + http://....... > + http://...... > Please can some of the Gurus on this newsgroup help me out with a >working solution as with my limited knowledge i am no position to >handle this assignment in two days. Actually it's a trick question - this cannot be done in Python. Some of your classmates will be handing in stuff that doesn't quite do this, hoping for partial credit. You should tell the teacher you've determined it's impossible - I'm sure he'll be properly impressed. >Regards From dalke at dalkescientific.com Sat Oct 6 02:21:57 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 6 Oct 2001 00:21:57 -0600 Subject: Quaternions in Python References: Message-ID: <9pm8cs$ao6$1@nntp9.atl.mindspring.net> David Feustel: >Is there a Python module that does quaternion math? Google search for "python quaternion", 3rd hit, http://starship.python.net/crew/hinsen/scientific.html ] ScientificPython is a collection of Python modules that are ] useful for scientific computing. In this collection you will ] find modules that cover ..., quaternions, .... Andrew dalke at dalkescientific.com From maxm at mxm.dk Wed Oct 31 18:05:55 2001 From: maxm at mxm.dk (maxm) Date: Thu, 1 Nov 2001 00:05:55 +0100 Subject: Python-equivalent of PHP addslashes/stripslashes functions? References: Message-ID: <7s%D7.1523$RM3.190406@news000.worldonline.dk> http://www.python.org/doc/current/lib/Contents_of_Module_re.html escape(string) Return string with all non-alphanumerics backslashed; this is useful if you want to match an arbitrary literal string that may have regular expression metacharacters in it. regards Max m "Leeuw van der, Tim" wrote in message news:mailman.1004529931.3668.python-list at python.org... > Hello, > > I'd like to know if there's a Python-alternative to the very convenient PHP > functions addslashes / stripslashes which add cq remove backslashes to > things like ', " characters, so that values from HTML forms can be safely > passed around to other programs, used in SQL statements, etc. > > Any pointers? > > Thanks in advance, > > --Tim > > From arzew at wp.pl Mon Oct 15 03:39:42 2001 From: arzew at wp.pl (Piotr Lipski) Date: 15 Oct 2001 00:39:42 -0700 Subject: importing Access 8.0 library Message-ID: Hi, can someone explain to me why the following error occured? I'm using Python 2.1.1 (from Activestate). Thanks, Piotr Lipski D:\Python21\win32com\client>makepy "Microsoft Access 8.0 Object Library" Generating to D:\Python21\win32com\gen_py\4AFFC9A0-5F99-101B-AF4E-00AA003F0F07x0 x8x0.py Traceback (most recent call last): File "D:\Python21\win32com\client\makepy.py", line 357, in ? rc = main() File "D:\Python21\win32com\client\makepy.py", line 350, in main GenerateFromTypeLibSpec(arg, f, verboseLevel = verboseLevel, bForDemand = bF orDemand, bBuildHidden = hiddenSpec) File "D:\Python21\win32com\client\makepy.py", line 261, in GenerateFromTypeLib Spec gencache.AddModuleToCache(info.clsid, info.lcid, info.major, info.minor) File "D:\Python21\win32com\client\gencache.py", line 444, in AddModuleToCache mod = _GetModule(fname) File "D:\Python21\win32com\client\gencache.py", line 468, in _GetModule mod = __import__("win32com.gen_py.%s" % fname) File "D:\Python21\win32com\gen_py\4AFFC9A0-5F99-101B-AF4E-00AA003F0F07x0x8x0.p y", line 6396, in ? class __CodeModule_(CoClassBaseClass): # A CoClass File "D:\Python21\win32com\gen_py\4AFFC9A0-5F99-101B-AF4E-00AA003F0F07x0x8x0.p y", line 6400, in __CodeModule_ coclass_interfaces = [ NameError: name '_CodeModule___IVbaModule_' is not defined From Steve_Thompson at maxtor.com Fri Oct 12 09:12:08 2001 From: Steve_Thompson at maxtor.com (Steve Thompson) Date: 12 Oct 2001 06:12:08 -0700 Subject: execfile fun! Message-ID: I'm trying to do something rather awkward in Python, and not having a great deal of success at that! I have the following modules: #bar module (bar_module.py): class Bar: def add(self, first, second): return first + second bar = Bar() #foo module (foo_module.py): from bar_module import * print "The sum of 23 and 45 is %d\n" %bar.add(23,45) #main module (main_module.py): class Main: def do_bar(self): execfile("foo_module.py") main = Main() main.do_bar() While performing execfile, I get 'NameError: There is no variable named 'bar'. From this I surmise that the execfile statement loaded and compiled foo, but did not import bar, as it was told. Is there any way of around this? Thanks in advance and best regards to all!, Steve Thompson From wzdd at lardcave.net Wed Oct 3 23:51:25 2001 From: wzdd at lardcave.net (Nicholas FitzRoy-Dale) Date: Thu, 4 Oct 2001 13:51:25 +1000 (EST) Subject: Nicer Tkinter on UNIX? In-Reply-To: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> Message-ID: On 3 Oct, Mark Berry wrote: > > If you are looking for a very good looking interface on unix, you > should go over to www.thekompany.com and take a look at the python > bindings for QT. Without wanting to waste time with licensing wars, I'm a bit concerned about using the Qt bindings. The way I understand it, since the bindings are GPLed (and have to be, since Qt free edition is GPLed), any Python code I write must also be released under the GPL. Is this correct? -- - Nicholas FitzRoy-Dale http://www.lardcave.net "Hit a man on the head with a fish, and he'll have a headache for a day..." From tim at zope.com Tue Oct 2 14:47:05 2001 From: tim at zope.com (Tim Peters) Date: Tue, 2 Oct 2001 14:47:05 -0400 Subject: Strategies for controling attribute assignment In-Reply-To: Message-ID: [Dale Strickland-Clark, weary of __setattr__] > ... > I guess I'd like to explicitly declare which attributes are part of > the public face of the class and which are not. > > I assume my approach is as good as any. Hard to say, unless I get to define "good" . Another approach is to use naming conventions. Python 2.2's "new-style classes" support customized attribute management without using __get/set attr__ tricks. Example: class Clipped(object): def __init__(self, lo, hi): "The instance's .x attr is constrained to lo <= .x <= hi" assert lo <= hi self.lo, self.hi = lo, hi def _getx(self): return self._x def _setx(self, value): self._x = min(max(value, self.lo), self.hi) x = property(_getx, _setx, doc="a bounded value") a = Clipped(1, 3) for i in range(5): a.x = i print "after setting a.x to", i, "its value is", a.x That prints after setting a.x to 0 its value is 1 after setting a.x to 1 its value is 1 after setting a.x to 2 its value is 2 after setting a.x to 3 its value is 3 after setting a.x to 4 its value is 3 "property" is a builtin convenience function in 2.2, but you could write property() yourself in 2.2 (and without using __get/set attr__). See the 2.2 PEPs for details about the new "attribute descriptor" protocol. From phr-n2001d at nightsong.com Wed Oct 10 20:26:16 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 10 Oct 2001 17:26:16 -0700 Subject: Python questions -> compiler and datatypes etc References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> Message-ID: <7xr8sbc993.fsf@ruckus.brouhaha.com> Richard Jones writes: > Do a search in the python mailing list for "python compiler". The > answer is invariably "it's bloody hard". This stems from the > fundamental dynamic typing of python. It's very very very hard to > write a compiler when you don't know the type of the objects you're > dealing with beforehand. Java knows these types, because it's > statically typed. Therefore it's relatively trivial (compared to > python) to write a compiler for Java. I think the real answer to why there's no Python compiler is no one has really wanted to write one. Python's runtime semantics are pretty similar to Lisp systems, and native-code Lisp compilers have existed since the 1960's or maybe even earlier. It might even be feasible to adapt one to compile Python. From geek_girl at mailcity.com Wed Oct 10 17:35:17 2001 From: geek_girl at mailcity.com (J) Date: 10 Oct 2001 14:35:17 -0700 Subject: ARGV and import ? References: <660c52de.0110090907.4017f907@posting.google.com> <20011009192330.A3209@lilith.hqd-internal> Message-ID: <660c52de.0110101335.523b6ef2@posting.google.com> I got it working!! Thanks everyone for your help! j. From phd at phd.pp.ru Wed Oct 31 11:28:01 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 31 Oct 2001 19:28:01 +0300 Subject: Python 1.5.2 -- assigning current time to a variable? In-Reply-To: <9rp8ki+5niu@eGroups.com>; from scott.nadeau@sanmina.com on Wed, Oct 31, 2001 at 04:24:50PM -0000 References: <9rp8ki+5niu@eGroups.com> Message-ID: <20011031192801.L21151@phd.pp.ru> On Wed, Oct 31, 2001 at 04:24:50PM -0000, scott.nadeau at sanmina.com wrote: > timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) > > Yields: > TypeError: function requires at least one argument > > How do I pass the argument? timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From cfelling at iae.nl Wed Oct 17 07:09:11 2001 From: cfelling at iae.nl (Carel Fellinger) Date: 17 Oct 2001 13:09:11 +0200 Subject: Pymacs 0.11 References: Message-ID: <9qjosn$5nd$1@animus.fel.iae.nl> Fran?ois Pinard wrote: ... > The Emacs LISP interaction parameters, so the interactivity of functions, > may now be specified from within the Python side. The example below uses > the empty string for an argument-less function, see `README' for details. > import pymacs > interactions = {} > def hello_world(): > "`Hello world' from Python." > pymacs.lisp.insert("Hello from Python!") > interactions[hello_world] = '' why not use function attributes, like: hello_world.lisp_interaction = '' -- groetjes, carel From bill-bell at bill-bell.hamilton.on.ca Tue Oct 16 14:04:16 2001 From: bill-bell at bill-bell.hamilton.on.ca (Bill Bell) Date: Tue, 16 Oct 2001 14:04:16 -0400 Subject: HTML Application Interface In-Reply-To: <1003254030.1347.86685.m6@yahoogroups.com> Message-ID: <3BCC3E60.7597.3D8F2B5@localhost> CpJohnson at edgars.co.za wrote, in part: > I will be writing a Python application to run stand-alone on > a PC. Just to be different, I came up with the idea of using an > HTML interface instead of something more conventional like Tkinter. > So the user interaction with the app would be via a web browser and > input via CGI etc. I wondered if there is an application framework > that would be suitable. I took a quick look at Zope, and think that > it would serious overkill to use it for my 5 form app. Anything > else out there? One possibility: You mentioned a 'PC' as your platform; let me jump to the conclusion that you are thinking of MSW. IE5 supports a class of apps called HTAs (HTML Applications). I haven't tried writing one; however, Scott Roberts ("Programming MS IE5", MS Press) writes: "... you can create them using only DHTML and script. ... Chapter 4 covers them in more detail." OK, now ponder the delightful fact that Python can function as a scripting language on MSW platforms (ref: Hammond & Robinson, "Python Programming on Win32"). Just place your five HTML forms in a convenient folder, along with their associated scripts (which might or might not be embedded) and an MS Access database and, heh, presto, an app! Just tell us how it goes. Bill "It is the time that you have wasted for your rose that makes your rose so important."--St-Exupery From reqhye72zux at mailexpire.com Thu Oct 11 15:30:43 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Thu, 11 Oct 2001 19:30:43 -0000 Subject: Problems With ColourSelect Box Inside A wxDialog References: <9e7d101d.0110081223.32a8217e@posting.google.com> <7hm8st4ul1p0i93r8ut2bpmetm8k7p7q6s@4ax.com> Message-ID: William Wonneberger wrote: > Ah, a bit too excited in my last posting.... > > With the corrected dialog box code in which the ColourSelect controls > are now being displayed correctly, I do still have the problem in > which there is a memory leak when the application terminates; > > 17:28:19: There were memory leaks. > 17:28:19: ----- Memory dump ----- > 17:28:19: wxColour at $1378E58, size 16 > 17:28:19: > 17:28:19: > 17:28:19: ----- Memory statistics ----- > 17:28:19: 1 objects of class wxColour, total size 16 > 17:28:19: > 17:28:19: Number of object items: 1 > 17:28:19: Number of non-object items: 0 > 17:28:19: Total allocated size: 16 > 17:28:19: > 17:28:19: > > Am I missing something still, or is this something I should post to > the wxPython bug tracker? First of all, you're still not instantiating the ColourSelect control correctly. It should be: ColourSelect(self, -1, [0, 0,110], wxPoint(200, 46), wxSize(55, 20)) *not* ColourSelect(self, wxPoint(200, 46), [0, 0,110], wxSize(55, 20)) As it is, you must get some error message. The second problem is that *both* ColourSelect controls are bound to self.colorselect, and that might conceivably cause some trouble with keeping wxPython shadow objects properly synchronized with their internal wxWindows counterparts. Having said that, when I try running your dialog code (after fixing the ColourSelect instantiation) I get no memory leaks, so the problem might be elsewhere. Do you keep any references to those controls anywhere except in your dialog-class? While I'm at it: there are some minor issues left: for some reason, overriding OnOK doesn't work, it obviously isn't being shadowed in wxPython. If you're not trying to override that method you'd better not use that name, because it might be added in a next version of wxPython.[*] As it is, just having buttons with wxID_OK and wxID_CANCEL in your dialog is sufficient. Also, your event handlers will never be called, because the IDs of the controls and the EVT_* 'macros' do not match. Personally, I try to avoid setting explicit IDs as much as possible, and just use -1 in the constructor. When I need that ID when setting up an event handler, I use the GetId method. > Again, thank you very much for your time and help... You're very welcome. Robert Amesz -- [*] I'm not even sure it's advisable that it could be overridden: that would certainly interfere with the calling of validators, unless you're very careful[**]. Unfortunately, I've found setting a validator for an entire dialog doesn't seem to work. Oh, you can set it allright, but only the Clone method ever gets called. I wonder if I should report this to Robin Dunn? [**] In which case you might argue that validators shouldn't be called from the OnOK method at all, but perhaps from the EndModal() or Show methods, or better still a separate EndDialog method, that being the logical counterpart of the InitDialog method. From fdrake at acm.org Fri Oct 5 12:51:22 2001 From: fdrake at acm.org (Fred L. Drake) Date: Fri, 5 Oct 2001 12:51:22 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011005165122.33A8A28697@beowolf.digicool.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Removed reference material for some long-obsolete Mac OS modules that have not been included in recent versions of MacPython. Added material on the proposed C API for weak reference objects; see the Python/C API Reference Manual: http://python.sourceforge.net/devel-docs/api/weakref-objects.html From greg at cosc.canterbury.ac.nz Wed Oct 17 20:34:49 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 18 Oct 2001 13:34:49 +1300 Subject: Assignment direction (Re: Curious assignment behaviour) References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> <3bcdbb39.1987133892@news> Message-ID: <3BCE23A9.E39D04C2@cosc.canterbury.ac.nz> "David C. Ullrich" wrote: > > What if you already have x = 42 and y = 24, and you > say "let x = y" ? Does that set x to 24 (yes) or > does it set y to 42? I'd say it confuses the reader, without further explanation. By the way, when I was very young, before I'd had much contact with real computers or HLLs, I designed a programming language in which assigment was written = , e.g. A + B = C. It seemed logical to me -- you do the arithmetic first and then store the result! I was quite surprised when I found out later that most languages do it the other way around. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From phr-n2001d at nightsong.com Mon Oct 8 14:13:36 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 08 Oct 2001 11:13:36 -0700 Subject: safe simultaneous file append? References: <3np2st060vt841lqfimibi12909td1p02c@4ax.com> <9prtkc$56a$1@samos.cs.uu.nl> <1cv2st0g180m0cfoloqf99s5pofe4pmi32@4ax.com> Message-ID: <7xofni2e5r.fsf@ruckus.brouhaha.com> "Chris Gonnerman" writes: > The only thing you need to do for safety is to ensure that complete > messages are written by a single write(2) call. Do this: > > logfile.write("A long message...\n") I don't think that guarantees a single write(2) call. It writes with stdio and buffers the message, and if the buffered stuff exceeds BUFSIZ, it writes out BUFSIZ characters and saves the rest. So the message can get chopped across two or more write(2) calls. Flushing the logfile object after every write should cause a single write call AS LONG AS every message is <= BUFSIZ chars (512 bytes in the old days, 8k on my current Linux box). It's best to use os.write, as someone mentioned. From infobot at skinnyhippo.com Mon Oct 8 12:11:46 2001 From: infobot at skinnyhippo.com (infobot) Date: 8 Oct 2001 09:11:46 -0700 Subject: python framework for users/roles ? Message-ID: Does Python have a framework for users and roles ? I'm guessing most of us have User-Management utilities as part of any multi-user, non-web based application. I don't know how many times I've rolled my own users/roles/groups/policies, each time different - but there has to be a better way. In anticipation of a one-word response - "LDAP" - let me explain further. Whilst extending an LDAP schema might allow me to use an LDAP server to manage the users & groups for an application that I'm building, somebody else wishing to use said application might have a different (non-LDAP) user-management system already in place. eg. Zope has a good security framework that is shared by all applications built for Zope. Does something similar exist for Python apps ? Sorry if I haven't made myself clear. chas From dalke at dalkescientific.com Fri Oct 5 19:24:48 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 5 Oct 2001 17:24:48 -0600 Subject: A little amusing Python program References: <3bbaf6c9$0$244$edfadb0f@dspool01.news.tele.dk> <3BBCBA9F.D1777976@juno.com> Message-ID: <9plfps$imh$1@slb1.atl.mindspring.net> Jeff Sandys >> Another program shown at an AI conference was a >> document classifier. To determine which folder to add >> the document to, it simply compare the size of the >> tarred folders before and after adding the document. Tom Good: >I don't get that last part. How does comparing the size of the >folders before and after do anything useful? Wouldn't all of the >folders increase by the size of the file? I'm assuming they were also compressed. Depending on the compression scheme, if there is a lot of text (words, phrases) that are shared between the documents then closely related text should compress better then more distantly related text. But that makes a lot of assumptions on the compression, like that it doesn't reset itself after a given amount of data. Andrew dalke at dalkescientific.com From graz at mindless.com Wed Oct 31 06:47:44 2001 From: graz at mindless.com (Graham Ashton) Date: Wed, 31 Oct 2001 11:47:44 GMT Subject: Interfaces != Multiple Inheritance [was Re: python development practices?] References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: In article , "Luigi Ballabio" wrote: > At 06:35 PM 10/30/01 -0800, Paul Rubin wrote: >>The idea is implement an abstract base class instead of an interface. >>Define methods for all the operations you want your interface to >>support, and make each method simply raise NotImplementedError. > > Why would you want to do that in Python? Imagine that you're writing a library that is to be used by others. Yes, you've documented it, but they've not read it in full, or quite understood it yet. They try and use part of your library but don't realise they need to define some other method in order to sub class one of your classes correctly. They can either get an exception that says "no such attribute" or they can get an exception saying "this thing isn't implemented". I'd suspect immediately that I'd missed something in the later case and head off to the docs. -- Graham From richard at bizarsoftware.com.au Wed Oct 3 23:43:04 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Thu, 4 Oct 2001 13:43:04 +1000 Subject: install on MacOS X 10.1? In-Reply-To: <3BBBD62C.BD9FD419@nisus.com> References: <3BBBC870.D0AE585E@nisus.com> <3BBBD62C.BD9FD419@nisus.com> Message-ID: <01100413430409.04291@ike> On Thursday 04 October 2001 13:23, xxxx wrote: > > xxxx wrote: > > I down-laoded 2.1.1 > > In the Makefile I found this suggested sequence > > # ./configure > > # make > > # make test > > # make install > > > > In the README it says > > Mac OS X 10.0: Run configure with "OPT='-no-cpp-precomp' ./configure > > --with-suffix=.exe --with-dyld". This generates executable > > file: 'python.exe' (it cannot be named 'python' on an HFS or > > HFS+ disk as the file name clashes with directory 'Python'). > > The '-no-cpp-precomp' option prevents a large number of > > compilation warnings. One of the regular expression tests > > fails with a SEGV due to the small stack size used by default > > (how to change this?), and the test_largefile test is only > > expected to work on a Unix UFS filesystem (how to check for > > this on Mac OS X?). > > > > but taking that literally doesn't work at all, generating error messages > > about the OPt... > > Is OPT an environment variable? > > I tried setenv OPT '...' and it seemed to accept that, > but now I'm getting complaints from the make The link I put in my other e-mail had a discussion about just the error you're encountering. Here it is again: http://lists.zope.org/pipermail/zope-dev/2001-October/013416.html explanation of problem: http://lists.zope.org/pipermail/zope-dev/2001-October/013428.html solution: http://lists.zope.org/pipermail/zope-dev/2001-October/013439.html Richard ps. your invalid e-mail address caused a bounce to appear in my inbox. I hate getting bounce messages when I am helping people. Please consider using a valid address, or people may not opt to help you out. From bh at intevation.de Wed Oct 10 12:47:44 2001 From: bh at intevation.de (Bernhard Herzog) Date: 10 Oct 2001 18:47:44 +0200 Subject: Why so few Python jobs? (and licenses) References: <7x1ykd7es3.fsf@ruckus.brouhaha.com> <7xn13060xv.fsf@ruckus.brouhaha.com> Message-ID: <6q8zejv3v3.fsf@abnoba.intevation.de> Mark writes: > But if the alternative is that once you GPL software you lose all copyrights > over it once anyone submits a patch, then there's every reason not to > release your software under the GPL. That's completely independent of the GPL. Both you and the author of the patch hold the copyright to the work that results from applying the patch (Assuming that both the original software and the patch are not public domain and that the author of the patch doesn't assign the copyright to you). Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://mapit.de/ From altis at semi-retired.com Mon Oct 15 16:21:10 2001 From: altis at semi-retired.com (Kevin Altis) Date: Mon, 15 Oct 2001 13:21:10 -0700 Subject: why no RealPython yet? References: <8827e15d.0110151158.1a1a8c36@posting.google.com> Message-ID: That is the direction that we're heading with PythonCard http://pythoncard.sourceforge.net/ The project framework was started in July and the current focus is on the GUI widgets and event system. Eventually, there will be an environment, at which point probably a lot of what you want that is in RealBasic will be available in PythonCard. I would be interested to hear the specific elements you're looking for. It is unlikely that the base PythonCard environment will act as a code generator or provide visual programming, the user code you'll need to write will still be Python. You can already produce apps with PythonCard that work on Windows, Linux, and Solaris and the Mac is coming. ka "Chris Ryland" wrote in message news:8827e15d.0110151158.1a1a8c36 at posting.google.com... > If you're aware of the RAD tool RealBasic for the Mac (which produces > single-file native executables for MacOS 9, X (Carbon-based) and > Win32, without source changes), I wonder if you have any thoughts of > why a similarly productive tool hasn't appeared for Mac/Win based on > Python? > > If you're not aware of RealBasic, take a look (www.realbasic.com). > It's quite impressive for what it does. > > And, yes, it's not as powerful a tool in some sense as something like > BlackAdder, but it's oh so much more approachable (which is the point > of RAD tools), and it produces all three platform binaries with one > click, which is even more the point of tools for people in the > commercial world whose targets are pretty much limited to Win32 and > MacOS 8/9 and X. > > I'm almost tempted to produce a clone based on Python... From m.1.robinson at herts.ac.uk Tue Oct 9 12:43:36 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Tue, 09 Oct 2001 17:43:36 +0100 Subject: simple threading Message-ID: <3BC32938.3080902@herts.ac.uk> I am trying run a particularly processor hungry function in a seperate thread but I can't quite figure out how to return the arguments from the object now. previously the function call was coded as: motifs = motifFinder.findOtherOccurances(posList, doubles) the new code is: motifs = thread.start_new_thread(motifFinder.findOtherOccurances,\ (posList, doubles)) The function seems to run fine, but it always returns None, can anyone tell me what I am doing wrong? TIA Blobby From gabriel_ambuehl at buz.ch Mon Oct 8 08:11:45 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Mon, 8 Oct 2001 14:11:45 +0200 Subject: Status of SOAP and Python. In-Reply-To: References: Message-ID: <14171270413.20011008141145@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello Martin, Monday, October 08, 2001, 1:43:02 PM, you wrote: >> Enough of the rambling I guess. How do others see where SOAP is >> going in relation to Python? Do people still think SOAP is the >> best thing since sliced bread, or are people starting to realise >> it is pretty crappy after all? > I certainly hope that SOAP is going to disappear rather sooner than > Considering that .NET is based on SOAP, this is rather unlikely to happen. Now if .NET would disappear too... > later, and that people who care about distributed systems come back > to well-defined interfaces, and efficient marshalling. So what do you recommend to use instead of SOAP? XML-RPC? Classic RPC (*uaah*)? Best regards, Gabriel Max???D -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO8GJ9cZa2WpymlDxAQExBAgAzJBIMc2ss/vNXCfP/o4q7L7Nt4gC6/G4 XP+JgmcbynQOOh12EnlloT5wbWjDCtJ2fNtTDmzhST18CNy/B1jMwHrJNOiIveuW meUyoTroZOwpCqhSGPqHrMpuGIcE5JioNOkF2nhH1Gp94eHd7pk8PA2b4ecXYkVi A7WNsphBm5BDOZ2uzypej7rnGsb7aY+fqldDmWPCTy5aFPRAwkUKeeJ5ZnBybWVu 3b8G4eWfKJmffkis3IQswnX7F8YHIHFXtO0YNb7O246z3hwVPDX/tC7Hv6uZl6QA cVUwJjiE50iPHSjD7eIKW+bZ5fVBm+6r+WYEVGeJdD0EEwEbdhw+YQ== =5aDs -----END PGP SIGNATURE----- From Tom_Good1 at excite.com Fri Oct 5 16:55:41 2001 From: Tom_Good1 at excite.com (Tom Good) Date: 5 Oct 2001 13:55:41 -0700 Subject: A little amusing Python program References: <3bbaf6c9$0$244$edfadb0f@dspool01.news.tele.dk> <3BBCBA9F.D1777976@juno.com> Message-ID: Jeff Sandys wrote in message news:<3BBCBA9F.D1777976 at juno.com>... > What a clever little program. I have felt for a long > time that a program that passes the Turing test will > use the web as a corpus of data. > > Microsoft showed a similar program at the IJCAI that > would answer questions. It answered some questions > like "What is A.I." and "Who made the movie A.I.", but > when asked "Who is Bill Gates married to" it's reply > was "I'm not sure, either Malinda French or Microsoft" > > Another program shown at an AI conference was a > document classifier. To determine which folder to add > the document to, it simply compare the size of the > tarred folders before and after adding the document. > Of all the AI programs used for document sorting it > came closest to a human sorter. > > Thanks, > Jeff Sandys I don't get that last part. How does comparing the size of the folders before and after do anything useful? Wouldn't all of the folders increase by the size of the file? Tom From geek_girl at mailcity.com Tue Oct 9 13:07:38 2001 From: geek_girl at mailcity.com (J) Date: 9 Oct 2001 10:07:38 -0700 Subject: ARGV and import ? Message-ID: <660c52de.0110090907.4017f907@posting.google.com> Hi all, This is my first post to this group & I am also fairly new to python, so please forgive me if this isn't the brightest question or the appropriate venue. I would like to do the following: import a module based on what is typed on the command line. I thought this would work: import sys recipes = sys.argv[1] import recipes But, I get this error: >> ImportError: No module named recipes Is there any way to pass the module name to import through an argv? Thanks in advance. From stjepan.zlodi at zg.tel.hr Tue Oct 16 06:11:05 2001 From: stjepan.zlodi at zg.tel.hr (Stjepan Zlodi) Date: 16 Oct 2001 03:11:05 -0700 Subject: Python COM for Microsoft Project References: Message-ID: Mike Brenner wrote in message news:... > For the next line of code, I would like to resave the file as a tab-delimited file for further processing in Python. Actually, I will build a robot that opens all the MP files and resaves them. > - Is there a URI to download the objects and methods that are now available? > - Or is the list of objects somehow hidden inside my Visual Studio or my Microsoft Developer CDs? > - Or do I need to buy Visual Basic for Applications or some other application to gain access to the objects? > - Is there an upgrade to the COM object browser that comes with Python for Windows? What's wrong with COM object browser in your Python distribution? In my ActiveState Python distribution I have win32com\client directory in which is makepy.py script. With that script I can make python module for each COM object file on my computer. From jknapka at earthlink.net Thu Oct 11 12:28:25 2001 From: jknapka at earthlink.net (Joseph A Knapka) Date: Thu, 11 Oct 2001 16:28:25 GMT Subject: Sockets References: <3BC50853.505C8641@engcorp.com> Message-ID: <3BC572EF.DEE5247F@earthlink.net> Hugo Martires wrote: > > #!/usr/bin/env python > > from socket import * > > HOST = 'localhost' > PORT = 21567 > BUFSIZ = 1024 > ADDR = (HOST, PORT) > > CliSock = socket(AF_INET, SOCK_STREAM) > CliSock.connect(ADDR) > > while(1): > data = CliSock.recv(BUFSIZ) > if not data: break > ??????????????????? > > CliSock.close() > > ****************************** > My problem is : what i put in ??????????????? > Some people told me to use a delimeter betwen the 2 strings. > But how can i use it? How to decode the whole string ? There are a couple of approaches you could take. The first would be to use a delimiter, and continue to read until you see the delimiter, saving any additional data for further reads: delim = '!' # Sender: the_data = "xyzzy" sock.send(the_data+delim) # Receiver: readbuf = '' def get_item(): """ Read and strip the first data item in readbuf. """ val = '' if delim in readbuf: val = readbuf[:readbuf.index(delim)] readbuf = [readbuf.index(delim):] def read_item(): # Maybe we read multiple items in previous read_item(): if delim in readbuf: return get_item() # Nope. Read new data. while(1): data = CliSock.recv(BUFSIZ) readbuf = readbuf + data if delim in readbuf: return get_item(readbuf) Another approach would be to read one character at a time until you see your delimiter. Not as efficient, but simpler to implement. Finally, you could encode the length of the data in a fixed-width field at the beginning of each data item: # Sender: the_data = "xyzzy" the_len = "%2d"%len(the_data) sock.send(the_len) sock.send(the_data) # Receiver: # We -know- we'll get two bytes of length: the_len = int(sock.recv(2)) the_data = sock.recv(the_len) This looks simpler, but you must code your sender and receiver very carefully to avoid them getting out-of-sync with respect to the location of the length data, and/or provide re-synchronization logic. The solution with delimiters doesn't have that concern. On the other hand, if you use the delimiter solution you must take care that the delimiter does not appear within the data. That's normally handled either by choosing data representations that don't contain the delimiter (eg, printable ASCII data, delimiter == 0x00), or by a transparency scheme (replace all occurrences of the delimiter in the data stream with a character sequence that doesn't contain the delimiter). HTH, -- Joe # "You know how many remote castles there are along the # gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald # Linux MM docs: http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html From val at vtek.com Tue Oct 30 17:57:50 2001 From: val at vtek.com (val bykoski) Date: Tue, 30 Oct 2001 17:57:50 -0500 Subject: can i develop a Dll with Python (on windows)? Message-ID: <9rnb9s$fer$1@news3.bu.edu> Or, to put it differently, can i integrate a pyd into my c-code. Please explain me, if i'm wrong thanx, /val From mgjv at tradingpost.com.au Mon Oct 22 08:40:27 2001 From: mgjv at tradingpost.com.au (Martien Verbruggen) Date: Mon, 22 Oct 2001 22:40:27 +1000 Subject: Perl Range operator paradigm References: <3BCC0B8D.F4EFF59C@loria.fr> Message-ID: On Tue, 16 Oct 2001 12:27:26 +0200, Laurent Pierron wrote: > Hello Gurus, > > In Perl there is a very powerful range operator '..', which, in scalar > context, is acting like line-range (,) operator in sed and awk. > > By example, this small program prints all the lines in the file included > between ... : > > while (<>) { > if (// .. /<\/BODY>/) {print; } > } Sorry to barge in, but that iperator, in this context, isn't the range operator, but the flip-flop [1]. Without more information, the python people here probably won't know what to look for. The way the flip-flop works is that the result of the expression A..B becomes true when A is true and stays true until B is true, after which the whole cycle can start again. The above loop would print all blocks of text between all lines that match the regular expressions above, including the lines themselves. If I knew the answer to how to do this in python, i'd include it, but I'm still reading up on the language. Martien [1] In other contexts the same operator is indeed called the range operator, and it produces lists of consecutive values. -- | Martien Verbruggen | That's funny, that plane's dustin' | crops where there ain't no crops. | From scott.nadeau at sanmina.com Wed Oct 31 11:24:50 2001 From: scott.nadeau at sanmina.com (scott.nadeau at sanmina.com) Date: Wed, 31 Oct 2001 16:24:50 -0000 Subject: Python 1.5.2 -- assigning current time to a variable? Message-ID: <9rp8ki+5niu@eGroups.com> Hi everybody, I am new to Python and I am stuck. I need to determine what the current time is and do one thing or another based on what time it is. I have seen people talk about how to get the current time using Python 2.1, but I'm working with 1.5.2. Using: timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) Yields: TypeError: function requires at least one argument How do I pass the argument? Sorry if this is a stupid question... Thanks, Scott From jmsun at bioeng.ucsd.edu Mon Oct 8 12:41:48 2001 From: jmsun at bioeng.ucsd.edu (Jeffrey) Date: 8 Oct 2001 09:41:48 -0700 Subject: wxPython and Tkinter Message-ID: <3daa1aa8.0110080841.526a6cc2@posting.google.com> I was wondering if anybody knew if it was possible to have wxPython widget be placed on a Tkinter Canvas Widget. wxPython has a HTML displayer and I wanted to display HTML on the Tkinter Canvas Widget. Thanks, Jeff From emile at fenx.com Fri Oct 12 09:55:33 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Oct 2001 06:55:33 -0700 Subject: execfile fun! References: Message-ID: <9q6t26$loaue$1@ID-11957.news.dfncis.de> This works for me as is. Perhaps you're importing a different bar_module? -- Emile van Sebille emile at fenx.com --------- "Steve Thompson" wrote in message news:f4b4ce26.0110120512.1337a497 at posting.google.com... > I'm trying to do something rather awkward in Python, and not having a > great deal of success at that! I have the following modules: > > #bar module (bar_module.py): > class Bar: > def add(self, first, second): > return first + second > > bar = Bar() > > > #foo module (foo_module.py): > from bar_module import * > print "The sum of 23 and 45 is %d\n" %bar.add(23,45) > > > #main module (main_module.py): > class Main: > def do_bar(self): > execfile("foo_module.py") > > main = Main() > main.do_bar() > > While performing execfile, I get 'NameError: There is no variable > named 'bar'. From this I surmise that the execfile statement loaded > and compiled foo, but did not import bar, as it was told. Is there > any way of around this? > > Thanks in advance and best regards to all!, > > Steve Thompson From brueckd at tbye.com Wed Oct 31 00:21:03 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 30 Oct 2001 21:21:03 -0800 (PST) Subject: python development practices? In-Reply-To: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> Message-ID: On Tue, 30 Oct 2001, it was written: > development practices. my question, i guess, is really whether python > is efficient/effective if used without perfect development practices. > if the documentation is a little out of date. or if a certain > interface isn't fully spec'ed out. and the guy who wrote the code is > out of town for a week. are there good practices which safeguard > against these situations? (beyond perfect development process...) I'm not convinced that the answer will vary that much from language to language. > oh, and the underscore thing seems a bit of a hack in that it > contradicts one of the core principles of python. decreasing > readibility of the code in order to express class properties to the > interpreter just screams "bolted on". On the contrary, it increases readability and expressiveness. In C++ or Java, you cannot look at a variable and say "oh, that's a non-public member". You have to go find the variable declaration and see whether it is declared public, protected, or private. What's up with that? > help trap a simple typo in a seldom-encountered bit of code would be > nice, without having to run fully exhaustive code tests. Heehee.. hardware and software are mankind's most complex inventions. They involve more details than we can focus on any given time, and for now at least the cost-effective way to deal with that (in any language) is good testing. Your code will be tested either way, it's just a question of whether it is done by you or your customers. -Dave From loewis at informatik.hu-berlin.de Fri Oct 12 05:52:30 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 12 Oct 2001 11:52:30 +0200 Subject: How to handle sys.path in bigger projects? References: <226dstkol613p95ampm7libas5tp6t0a3b@4ax.com> Message-ID: Georg Lohrer writes: > What are your ways of handling? If you are relying on a lot of third-party packages, I'd require that those packages get properly installed, ie. into site-packages or site-python. Then you only need to find your own code. If that grows in size, organizing it into multiple packages seems to be appropriate. I then see no problem in keeping all these packages in a single directory. Regards, Martin From doug at mis.nccu.edu.tw Mon Oct 29 15:09:48 2001 From: doug at mis.nccu.edu.tw (doug) Date: Tue, 30 Oct 2001 04:09:48 +0800 Subject: problem in xml.dom.minidom Message-ID: <9rj44m$1oej$1@news1.sinica.edu.tw> hi -------------------------------- [root at itschen /root]# python2.1 Python 2.1.1 (#1, Oct 25 2001, 16:09:01) [GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import xml.dom.minidom >>> doc ="haha" >>> domm = xml.dom.minidom.parseString(doc) Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 915, in parseString return _doparse(pulldom.parseString, args, kwargs) File "/usr/local/lib/python2.1/xml/dom/minidom.py", line 901, in _doparse events = apply(func, args, kwargs) File "/usr/local/lib/python2.1/xml/dom/pulldom.py", line 301, in parseString parser = xml.sax.make_parser() File "/usr/local/lib/python2.1/xml/sax/__init__.py", line 88, in make_parser raise SAXReaderNotAvailable("No parsers found", None) xml.sax._exceptions.SAXReaderNotAvailable: No parsers found <---- ##### why??? #### ----------------------------------------------------- (but it will not cause that exception in Python2.1 for Win32)?? From mmelchert at cgg.com Fri Oct 12 10:22:25 2001 From: mmelchert at cgg.com (Michael Melchert) Date: Fri, 12 Oct 2001 14:22:25 +0000 Subject: Kompiling PyQt References: Message-ID: <9q6qeq$14l5$1@news5.isdnet.net> Timothy Grant wrote: > I thought I would take a look at PyQt and see what was going on in that > project, so I downloaded the code did ./configure && make and that > worked just fine. However, when I did the make install, I got the > following error... > > (cd /tmp; > PYTHONPATH=/usr/local/lib/python2.1/site-packages:/usr/local/lib/python2.1/site-packages > /usr/local/bin/python -O -c "import qt") Traceback (most recent call > last): > File "", line 1, in ? > File "/usr/local/lib/python2.1/site-packages/qt.py", line 44, in ? > import libqtc > ImportError: /usr/local/lib/python2.1/site-packages/libqtcmodule.so: > undefined symbol: __ti8sipProxy > > I'd love some insight on how to resolve this issue. > > Thanks. > > Tim, it looks like you didn't get hold of the sip library. The PyQt library is build on top of it. You should find a link to it on http://www.thekompany.com/projects/pykde/download.php3?dhtml_ok=0 From max at alcyone.com Wed Oct 31 12:47:18 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 09:47:18 -0800 Subject: newbie question References: Message-ID: <3BE03926.71A116DB@alcyone.com> 1 wrote: > When I got to run the file (by typing python hello.py)i get this error > message: > > >>> python hello.py > SyntaxError: invalid syntax > >>> You don't type that here, you type it at your DOS shell prompt (since you're running Windows). -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From gh_pythonlist at gmx.de Thu Oct 4 00:59:12 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 4 Oct 2001 06:59:12 +0200 Subject: Nicer Tkinter on UNIX? In-Reply-To: ; from wzdd@lardcave.net on Thu, Oct 04, 2001 at 01:51:25PM +1000 References: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> Message-ID: <20011004065910.A794@lilith.hqd-internal> On Thu, Oct 04, 2001 at 01:51:25PM +1000, Nicholas FitzRoy-Dale wrote: > On 3 Oct, Mark Berry wrote: > > > > If you are looking for a very good looking interface on unix, you > > should go over to www.thekompany.com and take a look at the python > > bindings for QT. > > Without wanting to waste time with licensing wars, I'm a bit concerned > about using the Qt bindings. The way I understand it, since the bindings > are GPLed (and have to be, since Qt free edition is GPLed), any Python > code I write must also be released under the GPL. > > Is this correct? No, if you distribute it only in-house, it doesn't matter at all. If you distribute it outside your organisation, you need to license it under a *GPL compatible* license (like BSD, the new Python license and many others). Check out the FSF/GNU site on what they and their lawyers consider "compatible". Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From graz at mindless.com Mon Oct 29 19:53:18 2001 From: graz at mindless.com (Graham Ashton) Date: Tue, 30 Oct 2001 00:53:18 GMT Subject: Representing tuples in strings Message-ID: <2SmD7.3702$Ey1.438112@news1.cableinet.net> I'm looking to convert the tuple: ('string1', 3, 'string2') to the string representation: 'string1', 3, 'string2' without resorting to a regular expression. So far the nearest I've managed to get to is to have quotes round the whole thing, but not around the strings themselves. I suppose what I want here really is some better function to pass into map(). Maybe... >>> mytup = ('string1', 3, 'string2') >>> ", ".join(map(str, mytup)) 'string1, 3, string2' Any thoughts? It's not exactly going to make the difference between life and death in my application (it's for log files), but I'd really like to learn some map/lambda tricks. Thanks. -- Graham From gurnavage at agere.com Tue Oct 30 11:02:58 2001 From: gurnavage at agere.com (Jim Gurnavage) Date: Tue, 30 Oct 2001 11:02:58 -0500 Subject: Serial Package for Mac OsX Message-ID: <3BDECF32.9BB17073@agere.com> Anyone have a working serial package that will allow you to talk to a serial port in OsX? ctb (communications tool box) is not supported in OsX, and if run in the classic mode (OS 9 mode), ctb.Open() will crash the interpreter. If not, can the CTB package be built under OsX; that is, is it worth the effort for a total newbie Mac developer and Python developer like myself to attempt to climb the learning curve to get CTB to work on OsX? On a similar vein, is there any real platform-independent device I/O library for python (specifically, to access a serial I/O device such as a modem)? Thanks, Jim Gurnavage From sill at optonline.net Wed Oct 31 19:34:40 2001 From: sill at optonline.net (Andrei Kulakov) Date: Thu, 01 Nov 2001 00:34:40 GMT Subject: adding items from a text file to a list References: <48dbc3f6.0110301612.e0f863c@posting.google.com> Message-ID: On 30 Oct 2001 16:12:14 -0800, toflat wrote: > Hi, > > Sorry if this is a bit of a no-brainer question... > > I have a text file with a list of data items. > > ex: > > pickle (fruit or veggie?) > pickled eggs (just plain strange) > seinfeld (funny show) > yada yada (yada) > > What I want to do is add each item in the file to a python list. The > thing that is eluding me is how to leave out the comments. I need it > to scan in the item, skip anything in parenthsis then proceed to the > next line. > > Thanks for any help! > > -t lst = [] for line in lines: entries = line.split("(") # split in two parts, value and comment entry = entries[0] # get the value entry = entry.strip() # get rid of leading and trailing # whitespace lst.append(entry) -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From wzdd at lardcave.net Fri Oct 26 12:47:58 2001 From: wzdd at lardcave.net (Nicholas FitzRoy-Dale) Date: Sat, 27 Oct 2001 02:47:58 +1000 (EST) Subject: Confusion with string.replace() In-Reply-To: <002101c15e34$560f2cf0$a905a8c0@JWILHELM> Message-ID: On 26 Oct, Joseph Wilhelm wrote: > I'm getting some really strange behaviour from string.replace(), and I was > wondering if somebody could help explain this to me. All I'm trying to do is > escape single quotes in a string for a SQL query, but here's an example of > what I'm getting: > >>>> import string >>>> a = "a'b" >>>> b = string.replace( a, "'", "\'" ) You replace ' with an escaped ', which is the same as a plain ' here. >>>> b > "a'b" >>>> b = string.replace( a, "'", "\\'" ) >>>> b > "a\\'b" Yes, but if you: >>> len (b) 4 >>> b[1] '\\' What you're doing is replacing ' with a \ followed by a '. You have to quote the backslash in the Python string, and it's replaced by a single backslash in the new string. However printing the string causes the backslash to be quoted again. > I just can't seem to wrap my brain around why it's doing that. Can somebody > explain that Did that make any sense? :) -- - Nicholas FitzRoy-Dale http://www.lardcave.net I'm thinking of getting a pet cheese. I already have the cheese food. - http://www.enweirdenment.org/cgi-bin/cube-hof.html From ignacio at openservices.net Wed Oct 3 15:34:12 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 3 Oct 2001 15:34:12 -0400 (EDT) Subject: Past command buffer gone in interpreter? In-Reply-To: <9uIu7.590021$NK1.53791925@bin3.nnrp.aus1.giganews.com> Message-ID: On Wed, 3 Oct 2001, Tod Fox wrote: > Ignacio Vazquez-Abrams wrote: > > On Wed, 3 Oct 2001, Tod Fox wrote: > > Did you install from RPM, SRPM, or tarball, and if RPM or SRPM, where did you > > get it from? > > I compiled it from a tarball. Someone else has suggested I didn't compile it with > 'readline' turned on. I will look into this... You'll need to install the readline-devel RPM. -- Ignacio Vazquez-Abrams From vielmm at yahoo.com Mon Oct 29 16:34:56 2001 From: vielmm at yahoo.com (Aleksandr) Date: 29 Oct 2001 21:34:56 -0000 Subject: ôÏ,ÞÔÏ ÎÅÏÂÈÏÄÉÍÏ ÄÌÑ ÄÏÍÁ,ÓÅÍØÉ,ÄÁÞÉ,ÏÆÉÓÁ,ÐÒÅÄÐÒÉÑÔÉÑ! Message-ID: <1004391296.18959.qmail@ech> kodirovka KOI-8R ????????? ???????! ??? ????? ?????????? ? ?????????? - ??? ??????, ?????????, ?????, ???????????. ??? ??????? ???????????, ??? ?????????. ??????????, ??????? ????????????? ???? ???????? ????? ???????, ? ? ????????? ??????? ? ?????? ??????????, ??? ????????????, ????????????, ??? ? ??????? ???????? ? ??? ?????. 1. ??? ?? ????? ????? , ?? ???????? ?? ??? ?????, ??? ??? ???????? ???????? ??????? ?? ?????? ?? ?????????? ??????? ????????, ?? ? ?? ??????? ??? ?????????? ??? ?????????(??) ?????????. ???????????? "??????????????? ????????????", ???????? ??????????? ? ?????????? ?????????? "??????" ??????? ? ??????? ?????????? ?????????? ? ???????. ?????? ????? ????? ????????? ???????????? ???????. ??? ?????????: ? ????? ??????? (??? ?????? ????? ????????????) ?????????? ????????????? ????????? ????? 20 000 ? 1 ???. ?? ???????, ? ??????? ??????? ?? 2 000, ? ??????? ?? ??????? ??????? ?????? ?????? - 200-1000, ? ???????????????? ?????????? ????? 10-20, ? ????? ??????? ?????????? ??? ?????????? - ?????????? 0. ?? ?????????? ?????? ?? ???? ??????? ???????????? ?????????, ?????????? ?? ???????? ??????? ?????? ???????? ???????? - ????????? ? ????????? ?? 600 ?? ?? 50000 ?? ? ???.??.!!!!! ??? ??? ???????? ? ????????, ?????????? ?????????, ?????????? ?????. ??????? ??????? ?????? ??? ?? ????????. ????????? ????????????? ????????????? ?????. ? ????? ?????? ???? ????? ??????? ????????????? ?????????? ????????????? ????????? - ?????????????? ??? ??? ?? ??? ???????? - "?????? ??????????". ??? ??????? ??????????? ??? ????????? ????????? ???????????? ????????????? ?????????, ??????? 20 000 - 30 000 ? 1 ???.??, ???????? ??????? ?????? ????????? ??? ????????????? ????????? ????? ??? ???????. ? ???? ???????? ??????? ?????????? ?????????? ?????????, ??????????? ???????? ? ???????? ???? ?????. ???? ??????????? ??????? ?????? ?????? (?????? ??????) ????????? ??????????????? ?? ???????? ?????? ?.?. ?????????? ????? ? ? ???????. ? ???????? ?????????? ?????????? ??????, ?? ?????????? ?? ?????. ????, ??? ???????? ???????? ?? ??????. ??? ?????????? ? ??????? ????? ???????? ?? ?????: www.viel.f2s.com 2. ?? ?????????? ???????? ?????? ????????????? ???????? -???????? ??? ??????? ? ?????????? ???????? ????( ??????), ? ????? ???????? ??????? ??? ????? ? ???????????(??-2,??-3,POST-MIX ? ??). ??????-????? ?????? ??? ????????????? ? ?????? , ??? ??? ???????????? ???????????? ???????? ????? ??? ???????? ?????????. ??? ????????? ??????? ??????? ? ??????????, ??????????? ????????? ??????????????? ??????? ??? ???????? ???????? ?????. ??? ??????????? ????????? ????????????? ???, ????, ??????????? ?????, ? ????? ??????????? ????????. ????? ???????????? ?????? ?????????? ? ???? ? ?? ??????, ?? ?? ????????? ? ??????????? ???????? ? ????? ?? ??? ?????. ?????????? ?????? ???????? ???????? ??? ????????? ?????????????. ??? ?? ???????? ????? ????? ? ????????? ??????????? ? ???????? ??????????? ?????. ????????? ?????? ?????????????? - ?????? ????, ????? ????????????? ????????????? ? ????? ???????? ? ??????? ?????? ?????, ????? ??????????? ???? ? ??????? ????????? ?? 85??.. 3. ??????? ???????????, ??? ?? ?????? ???????? ????????, ??????????, ?? ? ????????? ????????????? ??? ?????????????, ??? ? ?????????? ?????????????? ??????????? ???????. ??? ????? ????? ??? International Rectifier, Epcos,Bourns, Metex, unit-t ? ??. 4. ????????? ?????????: ?? ??????? ????????? ?? ??????? ????????????? ??????????????. ??? ????????? ????????? ????????????? ????? ? ????? ?????????? ????????. ????? ?? ?????????? ?/? ? ?/? ???????? ????????????. ? ????????? ????? ?? ?????????? ?????????? ?????????? ????????????? ??????: ?????????????? ???????? ??? ??????????? ?????????? ????????????? ????!!!(D ?? 25 ?? 1000??.) ???? ????????? ????? ??????? ???? ??????, ????????????? ????????????, ??????? ??????????? ? ???????? ???????????? ? ????????????? ???????, ??? ????????? ??? ??????? ?????? ??? ????????? ?? ???????? ??? ??? ????? ? ? ?????????? ???????? ?????. ?????????? ?????????? ???????????(?? ??????????, ????????????? ?????)????? ????????? ?????? ???????????, ? ????? ???????? ??????? ???????????? ???????? ???????, ??????? ?? ????? ? ????? ???????????? ????? ???????????!!! ???? ???????????, ????? ????????? ?? ??? ????:(095) 275-89-94, ??? ?? ??????????? ?????: vielmm at yahoo.com ?? ???? ??? ? ???????? ??????????? ? ???, ??? ??????????? ? ???, ?? ???????? ????????????????? ??????, ???????????? ????????? ? ????? ????????????, ??????????? ????????? ?????? ??????. ?? ???? ???????? ?? ?????? ?????????? ?? ????????? ? ?. ??????: (095) 275-89-94,746-68-78 _______________________________________________________________________ Powered by List Builder To unsubscribe follow the link: http://lb.bcentral.com/ex/manage/subscriberprefs?customerid=15920&subid=A6DA23F43B7BCE49&msgnum=2 From chatme at 263.net Thu Oct 18 01:43:03 2001 From: chatme at 263.net (limodou) Date: 17 Oct 2001 22:43:03 -0700 Subject: Is sgmllib.py 's BUG? Message-ID: Sometimes I use python to analyse a HTML document. But I found that if there is a tag start with ' We have an application (written in C++/MFC/T-SQL) where we use Word (MS) as an editor. Word is started by our application as a COM-server (automation). When started, Word with all its features/functions (except some programmatically removed functions) is available to the user. Word is started "Modally" - the rest of our application is frozen while Word is active. Some parameterisation of Word is done from our application (by using the object model Word exposes). Some features implemented in VBA make it possible for the user to extract information for the database. This is done by calling back into our application (which then actually acts as a COM-server to Word), which again accesses the database (use the current db connection). Now to the question. Does anyone know if it is possible to develop a python based COM-server which also has a GUI (based on win32ui or maybe wxPython) working principally like described above. I've tried using the simple COM-server examples from M.Hammond/Andy Robinsons book, however I'm not able to have the GUI created. Thanks for any help/hints. Nikolai Kirsebom From michael at rcp.co.uk Thu Oct 25 12:01:04 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Thu, 25 Oct 2001 16:01:04 +0000 (UTC) Subject: A small inconsistency in syntax? References: Message-ID: "Steve Holden" wrote in news:x3WB7.28536$Nx2.553375 at atlpnn01.usenetserver.com: > "Michael Abbott" wrote in message > news:Xns91459674D7271michaelrcpcouk at 194.238.50.13... > > Oh, no it isn't. The best parallel I can think of is writing > >>>> 2 = 34 > Traceback (SyntaxError: can't assign to literal > > although in your case you are trying to assign to a constructor rather > than a literal Hmm. Ok, I think I'll buy that. Yes, I guess I might expect to get a run- time whinge about mismatching values instead, but I think I'm getting silly now. >> time, status, _ = myobject.read() >> > > Or, if you really don't want to do that, how about > > time, status = myobject.read()[:2] No, I think I prefer my original! Ta. From claird at starbase.neosoft.com Wed Oct 3 11:59:05 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 3 Oct 2001 10:59:05 -0500 Subject: Nicer Tkinter on UNIX? References: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> Message-ID: <86DF15C112AF36D6.332DEDD523A2210C.F8DE5222D8EF2836@lp.airnews.net> In article <3bbaf48e.1019777212 at spamkiller.newsfeeds.com>, Mark Berry wrote: > >If you are looking for a very good looking interface on unix, you >should go over to www.thekompany.com and take a look at the python >bindings for QT. I spent one late evening playing with the QT >interface designer. After understanding how to setup my own >callbacks, etc I was able to write simple applications in minutes. > >It's actually not too far off from Tkinter in code implimentation and >looks fantastic, at least as good as any QT based application. > >The only thing I am not sure about is the cross-platform usefulness. >I don't think you will be Tkinter in this. > >Anyway, good luck and I hope you find what works best for you! :) > > >On 3 Oct 2001 10:39:55 GMT, Artur Skura wrote: > >> >>[It's not particularly Pythonish question, but I thought you might know] >> >>I like Tkinter because it's standard. But there is a big but. >>While on Windows it looks great, on unices it makes kids laugh. >>Not that it's particularly ugly, but quite awkward and not up to the >>aesthetic standards people expect now. >> >>Is there a way to make Tkinter use KDE/GTK themes on unices? Or change the >>interface in any way? (I don't consider wx... stuff, as it forces users to >>install additional software). . . . PyQt is indeed a good-looking alternative to Tkinter--and PyQt is (generally) available for Windows. While it could be constructed for MacOS, at least in principle, I don't think anyone is particularly close to doing this. Tk and Qt have different philosophies of widget management. It's easy enough to try both, that I often recommend this; experience them for yourself, and see which one(s) is (are) compatible with your own habits and preferences. Tk is unlikely to support themes (as that's currently under- stood) at all soon. However, the topic is an active one among Tcl-ers, and the time is absolutely ripe for Tk to receive help from interested Pythoneers. See and for information, including comparisons between the technical bases of Tk, Gtk+, Qt, and so on. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From stojek at part-gmbh.de Thu Oct 18 08:52:09 2001 From: stojek at part-gmbh.de (Marcus Stojek) Date: Thu, 18 Oct 2001 12:52:09 GMT Subject: Python and 3D Graphic tools Message-ID: <3bcece7f.18432984@news.easynews.net> Hi, I want to write a little tools to visualize a kind of 3D puzzle. (The single pieces are more or less cubes with or without holes and pins) As I don't want to spend very much time on this I am looking for an appropriate programming tool. VPython looked good, but it has only the basic volumes, like cubes and spheres. VTK might be a little difficult and I don't fully understand how to use it with Python. Is there anything between these two? Or a VTK add-on thing I could use? I want to define relatively simple bodys, show them in 3D, and pile them interactively. (No animation, just add or remove from the scene) Thanks in advance. Marcus From paullim at starhub.net.sg Fri Oct 19 13:47:48 2001 From: paullim at starhub.net.sg (Paul Lim) Date: Sat, 20 Oct 2001 01:47:48 +0800 Subject: HTMLParser : Record title tags. More info? Message-ID: <3BD06744.D325D34@starhub.net.sg> Hi I am a newbie in Python. I hope the guru can advise me. I am trying to record the title of links in a html document. If the opening tag has a title value, I need to record this value. If the title does not exist, I need to record the text between the opening and closing . Does anyone have any idea how should we do it? I know I have to use def start_a(self, attr): and def end_a(self): I would like to read more about the methods that can be used in HTMLParser. I have tried to read the python documentation but it is too brief and I don't really understand how to utilize the methods. Is there any sites where I can read more? Thank you very much. Sincerely Paul From phr-n2001d at nightsong.com Thu Oct 11 05:23:37 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 11 Oct 2001 02:23:37 -0700 Subject: get uniform binary data into array for further processing References: Message-ID: <7xg08qh6na.fsf@ruckus.brouhaha.com> I think you want to use the array module to read the data, and Numeric to crunch it. I worry a little about whether Python's storage allocator can handle that much data though, especially on a 32-bit machine if you're in fact using one. On a 64-bit machine things may be smoother. From igor.stroh at wohnheim.uni-ulm.de Wed Oct 24 19:21:12 2001 From: igor.stroh at wohnheim.uni-ulm.de (Igor Stroh) Date: Thu, 25 Oct 2001 01:21:12 +0200 Subject: python-gtk: GtkCList.clear() problem Message-ID: <3bd74d34$1@sol.wohnheim.uni-ulm.de> Hi there, did anyone ever had this kind of problem with GtkCList.clear(): the function is called from a thread that get's the appropriate widget on creating. Inserting and deleting rows works fine, but if I call .clear - nothing happens... I tried to use .clear inside of .freeze - .thaw() (which is obviously useless) with the same result though... calling .clear from the main programm (e.g. by bindig it to a button) works as desired... any suggestions? TIA, Igor From hugomartires at hotmail.com Thu Oct 11 09:59:15 2001 From: hugomartires at hotmail.com (Hugo Martires) Date: 11 Oct 2001 06:59:15 -0700 Subject: Sockets References: <3BC50853.505C8641@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3BC50853.505C8641 at engcorp.com>... > Hugo Martires wrote: > > > > My server need to send 2 strings separeted: > > s1= 'xxx' > > s2= 'yyy' > > > > My client must received like this: > > rec1= 'xxx' > > rec2= 'yyy' > > > > The problem is that the Client received s1 and s2 in one only string. > > > > How can i received in 2 separeted variables ? > > I note the other answers, and still feel the need to point out two > things. > > 1. When asking questions of this sort, it is *always* advisable > to post sample code showing what you are trying to do. > If you don't, the answers are just guesses (maybe educated ones, > but still guesses). > > 2. Assuming you are opening a socket between the two programs, > my (educated :-) guess is that you are doing a pair of socket.send() > calls with the two strings, and expecting these two be > received *separately* with two recv() calls on the other end. > If this is so, you misunderstand how sockets and TCP/IP and > such work. Nowhere in the documentation will you find any > guarantee that the data from two consecutive send() calls > matches up with the two recv() calls. They might be lumped > together so that you get 'xxxyyy' after the first recv(). > You might have to use four recv() calls and get 'x', 'x', > 'xxy' and finally 'yy'. No guarantees. Don't ever assume > you have all the data just because recv() returns. > > And that's the reason behind John's suggestion of disabling > the Nagel algorithm, since it *might* appear to solve the > problem. Don't be fooled: it's a very fragile, hackish > way of "fixing" the problem, and not suitable for "real" > programs in most cases. (Standard anti-flame disclaimers > apply...) /////////////////////////////////////////////////////// OK there's my code: *----------- Server ----------------------* #!/usr/bin/env python from socket import * from cga_dp import * # input n=10 s=4 g=10 param=[n , s , g] HOST = '' PORT = 21567 BUFSIZ = 1024 ADDR = (HOST, PORT) vp=get_vp() SerSock = socket(AF_INET, SOCK_STREAM) SerSock.bind(ADDR) SerSock.listen(5) while(1): CliSock, addr = SerSock.accept() CliSock.send(repr(param)) CliSock.send(vp) CliSock.close() SerSock.close() *----------- Client -------------------* #!/usr/bin/env python from socket import * HOST = 'localhost' PORT = 21567 BUFSIZ = 1024 ADDR = (HOST, PORT) CliSock = socket(AF_INET, SOCK_STREAM) CliSock.connect(ADDR) while(1): data = CliSock.recv(BUFSIZ) if not data: break ??????????????????? CliSock.close() ****************************** My problem is : what i put in ??????????????? Some people told me to use a delimeter betwen the 2 strings. But how can i use it? How to decode the whole string ? Tanks From tim.one at home.com Mon Oct 15 16:14:42 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 15 Oct 2001 16:14:42 -0400 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) In-Reply-To: Message-ID: [Mark J] > I vote for it, parens and all. > > Plus we get conditionals inside lambda expressions for free... Yes you do, and that *is* a drawback <0.9 wink>. compared-to-python's-lambda-syntax-everything-is-sane-ly y'rs - tim From burner at core.binghamton.edu Sun Oct 28 10:19:49 2001 From: burner at core.binghamton.edu (Michael R. Head) Date: Sun, 28 Oct 2001 10:19:49 -0500 Subject: Why doesn't this simle DCurry-like implementation work? In-Reply-To: ; from python-list-request@python.org on Sun, Oct 28, 2001 at 09:57:01AM -0500 References: Message-ID: <20011028101949.A21174@warp.core.binghamton.edu> On Sun, Oct 28, 2001 at 09:57:01AM -0500, python-list-request at python.org wrote: > "Michael R. Head" wrote in message news:... > > # for some reason this function doesn't work in python 1.5.2. > > def curry(f, p): > > return lambda x: apply(f, p, x) > > > I'm supposing that lamda isn't storing > > the reference to its inputs -- which it seems it should -- is this > > correct? > > mike > > Try this: > def curry(f, p): > return lambda x, ff=f, pp=p: apply(ff, pp, x) > But i wonder if it does what you want > > Joost You are right. That's what I get for posting while drunk. I meant: # this doesn't work... def curry(f, p): return lambda x: f(p, x) however, now I know that this does work, and does what I want: def curry(f, p): return lambda x, ff=f, pp=p: ff(pp,x) thanks all! -- Michael R. Head burner at core.binghamton.edu GPG public key: http://www.core.binghamton.edu/~burner/gpg.key.txt -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 536 bytes Desc: not available URL: From jason-dated-1002774146.2399ad at mastaler.com Wed Oct 3 00:22:23 2001 From: jason-dated-1002774146.2399ad at mastaler.com (Jason R. Mastaler) Date: Tue, 2 Oct 2001 22:22:23 -0600 Subject: need design suggestions: local namespace problem In-Reply-To: ; from johnroth@ameritech.net on Tue, Oct 02, 2001 at 08:48:33PM -0700 References: Message-ID: <20011002222223.A27332@mastaler.com> John Roth writes: > Wrap the whole thing in a proxy class. Then you just import the > proper module, and away you go. If you want to add another > mail program later, you just have to add an appropriate proxy > with the same interface. Can you give me an example of what you mean by a "proxy class"? I'm not familiar with that terminology. From gs at styrax.com Tue Oct 9 12:28:07 2001 From: gs at styrax.com (Garry Steedman) Date: Tue, 9 Oct 2001 16:28:07 +0000 Subject: Python & Zope In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20EBACBEB@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <3BC32597.20170.196BACC9@localhost> Jonathan, read Ch. 8 of the Zope Book: it points out some of the pitfalls! cheers, Garry On 9 Oct 2001, at 15:21, jonathan.2.wilkinson at bt.com wrote: From: jonathan.2.wilkinson at bt.com To: python-list at python.org Subject: Python & Zope Date sent: Tue, 9 Oct 2001 15:21:57 +0100 > Anyone, > > I'm trying to do this incredibly simple python script in zope: - > > myfile = open('myfile', 'w') > myfile.write('hello\n') > myfile.close() > > It works from a python interpreter fine......but when I try to test it > I get > > > Error Type: NameError > Error Value: global name 'open' is not defined > Any ideas how to read/write a text file in zope using python?????Can > it be done? Any other methods of writing and reading randomly (well > structured sort of way, but from anywhere within the file) in zope?? > > Please help, > Regards, > Jono > > > > -- > http://mail.python.org/mailman/listinfo/python-list +-------------------------------------------+ Garry Steedman mailto:gs at styrax.com Styrax Associates http://www.styrax.com/ "The Good Man has no shape." +-------------------------------------------+ From wade at lightlink.com Wed Oct 31 08:54:30 2001 From: wade at lightlink.com (Wade Leftwich) Date: 31 Oct 2001 05:54:30 -0800 Subject: Interfaces != Multiple Inheritance [was Re: python development practices?] References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> <7xy9lsr0xn.fsf@ruckus.brouhaha.com> Message-ID: <5b4785ee.0110310554.5119d151@posting.google.com> Zope 2.4 includes an Interface module that can be used outside Zope. It provides lots of nice introspection methods. quoting the ZopeDevGuide: from Interface import Base class Hello(Base): """ The Hello interface provides greetings. """ def hello(self, name): """ Say hello to the name """ class HelloComponent: __implements__ = Hello def hello(self, name): return "hello %s!" % name ############# Hello looks like a class, but it's not: >>> Hello >>> type(Hello) From loewis at informatik.hu-berlin.de Mon Oct 22 12:40:28 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 22 Oct 2001 18:40:28 +0200 Subject: How is overloading __getitem__ in subclasses of str supposed to work in Pythton 2.2b1 ? References: Message-ID: "Andreas.Trawoeger" writes: > def __getitem__(self,index): > return b2a_hex(self[index]) [...] > Well this isn't a surprise because I'm using the [ ] method in __getitem__ > which implements [ ]. > But I have no clue how I could write an different implementation for > __getitem__. Just think of str being a class, and you attempting to write a super call: from binascii import b2a_hex class octetstring(str): def __str__(self): return b2a_hex(self) def __getitem__(self,index): return b2a_hex(str.__getitem__(self,index)) o = octetstring('ABCD') print "o :",o print "o[0]:",o[0] Using the new "super" type, you can also write def __getitem__(self,index): return b2a_hex(super(octetstring,self).__getitem__(index)) HTH, Martin From GeorgLohrer at gmx.de Sat Oct 20 10:47:07 2001 From: GeorgLohrer at gmx.de (Georg Lohrer) Date: Sat, 20 Oct 2001 16:47:07 +0200 Subject: Solaris and tinter: cann't fint curses References: Message-ID: David, On Fri, 19 Oct 2001 21:42:37 -0600, "Jackson" wrote: >>>> import tinter >Traceback (most recent call last): > File "", line 1, in ? > File "./tinter.py", line 66, in ? > import curses # I use curses >because I'm reasonably sure everyone has it But, reality shows us: > File "/usr/local/lib/python2.1/curses/__init__.py", line 15, in ? > from _curses import * >ImportError: No module named _curses >>>> you don't have it on your system or your PYTHONPATH is not set correctly to gain access to _curses.py or _curses.so. On my system it's located in /usr/local/lib/python2.1/lib-dynload/_curses.so So, if your PYTHONPATH (check it with 'sys.path') does not contain the mentioned dir-path, you cannot load the module. Maybe the path is correct, but the module is not available. For that reason have a look at the source-directory of Python and look into Modules/Setup. You'll find an entry '_curses _cursesmodule.c -lcurses -ltermcap' and special comment belonging to Sun-Solaris. Ciao, Georg From emile at fenx.com Tue Oct 2 10:43:51 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 2 Oct 2001 07:43:51 -0700 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> Message-ID: <9pck4f$gr0ce$1@ID-11957.news.dfncis.de> So, what you're trying to do is manipulate two dicts with one interface _without_ needing to distinguish which dict is intended. It seems to me that even with a private/public scheme, you'll need to test _something_. Why not try letting all the internals use a leading underscore and all the database not, then test on that. -- Emile van Sebille emile at fenx.com --------- "Dale Strickland-Clark" wrote in message > > I thought this might be difficult to convey. This is typical of the > approach I'm currently using: > > def __setattr__(self, field, value): > if self._dbTable.has_key(field): > self._dbTable[field].validate(value) > self._fields[field] = value > self._saved = 0 > else: > self.__dict__[field] = value > > I have to distinguish between assignments to 'public' attributes > (which will go in my database) and instance variables which are used > throughout the class. I need to validate assignments to the database > but just let everything else through. > > But it means that EVERY internal assignment to instance attributes > needs to go through this code. > > I guess what I'm after is a distinction between private and public > attrbutes. > > Does that make it any clearer? > -- > Dale Strickland-Clark > Riverhall Systems Ltd From max at alcyone.com Fri Oct 19 14:03:52 2001 From: max at alcyone.com (Erik Max Francis) Date: Fri, 19 Oct 2001 11:03:52 -0700 Subject: Dictionary from list? References: Message-ID: <3BD06B08.972910A5@alcyone.com> Andrei Kulakov wrote: > You know, this sort of thing comes up often - X is a built-in feature > in > perl, why do I have to do it manually in python? I think this is a > justified design decision - there's simply too many built-in things > perl > does. You can't remember all of them and if you look at someone else's > perl program you have to scratch your head a lot. Python is small, > lean > and clean, and that's one of the best things about it. In particular, what this is really revealing is that a Perl associative array is really represented as a list, with each successive pair representing a key and a value. (When writing list and associative array literals, you see the same thing.) This goes back to Perl's weakly-typed approach to everything. Since Python is not weakly typed, emulating this behavior is not only not convenient, but is not even advisable. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ When one is in love, a cliff becomes a meadow. \__/ (an Ethiopian saying) 7 sisters productions / http://www.7sisters.com/ Web design for the future. From uwe at rocksport.de Fri Oct 19 05:57:36 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 19 Oct 2001 09:57:36 GMT Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> <9qk0p9$6tulc$1@hades.rz.uni-sb.de> <9qkfi0$6s3js$1@hades.rz.uni-sb.de> Message-ID: <9qoteg$73fm0$2@hades.rz.uni-sb.de> Michael Hudson wrote: | Indeed, the OP was complaining that Numeric.array *didn't* define a | hash function... (and then snipped out the bit of my post where I said | I was making it up). ups. what did i snip out ? i only received your virtual session... yours, uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From johnroth at ameritech.net Mon Oct 15 14:27:54 2001 From: johnroth at ameritech.net (John Roth) Date: Mon, 15 Oct 2001 11:27:54 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <7xitdha8tg.fsf@ruckus.brouhaha.com> Message-ID: "Ian Parker" wrote in message news:apXvDKAPApy7EwVg at gol.com... > In article <7xitdha8tg.fsf at ruckus.brouhaha.com>, Paul Rubin n2001d at nightsong.com> writes > >"Tim Peters" writes: > >> > x = if e1 then (e2) else (e3) > >> > and > >> > x = (if e1 then (e2) else (e3)) > >> > should be equivalent and they preserve clarity. > >> > >> The latter form would be accepted, but not the former (and the former cannot > >> be accepted, which is a question of parser technology, not of taste). > > > >How did Algol 60 deal with this? > > to excess, and with a more complicated parser, I imagine: Actually, there was a quite good book on one company's Algol 60 implementation (called "Algol 60 Implementation", I believe), that showed a recursive descent parser, with all of the parser and interpreter functions diagrammed out. This was before there was a whole lot of parser theory to go by... John Roth From shriek at gmx.co.uk Mon Oct 22 17:18:38 2001 From: shriek at gmx.co.uk (Stephen) Date: 22 Oct 2001 14:18:38 -0700 Subject: programming unlimited "categories" in python ? Message-ID: <97ae44ee.0110221318.6eec382d@posting.google.com> Scratching my head over what I thought was a simple problem. I'm developing a catalog application (storing its data in a relational database), where catalog entries are categorized by one or more categories/subcategories. It would be nice to have "unlimited" levels of subcategories and that seemed simple enough ~ "Use a parent/child" I hear you say ~ and that's what I did but I've since found it's not very flexible further down the line. Let me demonstrate with some example categories/subcategories which we place in a category tree, giving each node a unique ID. The root node is deemed to have node ID zero (0). Root -- 1. ByLocation --- 3. Africa --- 4. Mozambique --- 6. SouthAfrica --- 5. Europe --- 9. Portugal -- 2. BySeverity --- 7. Critical --- 8. Death --- 11. Handicap --- 10. Moderate--- This structure can be stored in a single table of a database. Parent_ID Category_ID Category_Label 0 1 ByLocation 0 2 BySeverity 1 3 Africa 3 4 Mozambique 1 5 Europe 3 6 SouthAfrica 2 7 Critical 7 8 Death 5 9 Portugal etc So far so good. Cataloged items/illnesses record their categories in a one-to-many table. For example, an illness with categories "4" and "8" occurs in Mozambique and can result in death. This appears scalable. Likewise you can easily select all illnesses occuring in Portugal using a JOIN and filtering category ID "9". So what's the problem ? The problem arises if one asks "Which illnesses occur in Africa ?". First, one has to find all category IDs for which this is true. This may be easy for the example above but imagine if the category ("Africa") has a sub- -category for each and every country then further subcategorized by major cities. To find all possible categories, one would have to do a recursive select finding each subscategory with the appropriate "parent ID". This does not seem like a very efficient method. Faced with this, it seems like a more dumbed down solution is more appropriate, sacrificing scalability for speed. However, I can't help but feel I've overlooked something more simple and hence I'm seeking a nudge in the right direction. Thanking you in advance. Stephen. From john at yates-sheets.org Tue Oct 2 16:22:01 2001 From: john at yates-sheets.org (John S. Yates, Jr.) Date: Tue, 02 Oct 2001 20:22:01 GMT Subject: pickling types from pywintypes Message-ID: I am developing a network file system redirector and trying to write a test framework in Python using the win32all package. To be able to script multiple client machines I have a win32 server that runs on my slave machines and a master controller test suite runner that communicates with the slaves via dopy rpc. dopy is layered on [c]pickle. The problem I am having is that the pywintypes do not seem to be pickleable: received CreateFile Unhandled exception in thread: Traceback (most recent call last): File "C:\PythonPackages\DoPy\dopy.py", line 786, in __serviceFunction clientConnection.send(response) File "C:\PythonPackages\dopy\tcp.py", line 119, in send Pickler(self.wfile).dump(obj) cPickle.UnpickleableError: Cannot pickle objects I got essentially the same exception when trying to pass a non-trivial PySECURITY_ATTRIBUTES. Is this an inherent limitation of the types provided by pywintypes? Is there a work around? /john -- John Yates 40 Pine Street Needham, MA 02492 781 444-2899 From fredrik at pythonware.com Sun Oct 21 17:06:00 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 21 Oct 2001 21:06:00 GMT Subject: problem with re module References: <9qv5d4$psb1n$1@ID-75083.news.dfncis.de> Message-ID: Markus Jais wrote: > when I put it in a file: > File "./re.py", line 4, in ? > p = re.compile('ab*') > AttributeError: 're' module has no attribute 'compile' try changing the name of your test script... From gh_pythonlist at gmx.de Fri Oct 5 14:59:39 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 5 Oct 2001 20:59:39 +0200 Subject: Variables name in Byte code In-Reply-To: ; from ignacio@openservices.net on Fri, Oct 05, 2001 at 02:46:50PM -0400 References: <68599ccc.0110051038.25ba4b82@posting.google.com> Message-ID: <20011005205939.B2293@lilith.hqd-internal> On Fri, Oct 05, 2001 at 02:46:50PM -0400, Ignacio Vazquez-Abrams wrote: > On 5 Oct 2001, Kaci Tizi Ouzou wrote: > > > Greetings all, > > > > I was examining python compiled code and surprisingly I could see > > clearly the names of some variables. > > > > Is there anything I could do to make Python Byte code more obscur. > > I do not want user trying to hack the code(!) > > > > Thanks > > Well, you could encrypt the code object for the file then encapsulate it in a > program to decrypt it and run it with eval(). You'd have to let the user enter a password each time the program starts, right? Ah, perhaps also store the hash of the password somewhere so you can tell if it was entered correctly. Otherwiese when the .pyc is decoded with a wrong password and executed, it could crash the interpreter. Now that I come to think of it, you don't need to ask the password each time. The password *is* the license key. Or part of the license key. So you only have to ask it once, because the license key is stored in a file or in the registry. The question then is, how long it will take until a crack shows up on astalavista.box.sk ;-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From fredrik at pythonware.com Tue Oct 30 03:58:07 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Oct 2001 08:58:07 GMT Subject: Tcl/Tk & Python References: <7647A9F4B298E74DB6793865DA67285004AC66@exchange.adrembi.com> <23A23C6F4D43B5D2.E0739EED3789F4E9.7F5C708AD85DF28A@lp.airnews.net> Message-ID: Cameron Laird wrote: > Fredrik's done wonders with Tkinter. Guido started it, though. > I don't want the ambiguities in "creator" to mislead anyone. I'm pretty sure Steen Lumholt wrote it. Guido has been hacking on it, and I've been hacking my way around it, but Steen did the original work. From emile at fenx.com Sat Oct 6 11:40:17 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 6 Oct 2001 08:40:17 -0700 Subject: Slicing a list with non-integer parameter? How? References: <3BBF216D.25524AAB@student.kun.nl> Message-ID: <9pn8th$j90lb$1@ID-11957.news.dfncis.de> list1.remove(2) and list2.remove('thrie') -- vs 'drie' HTH, Emile van Sebille emile at fenx.com --------- ----- Original Message ----- From: "Husam" Newsgroups: comp.lang.python Sent: Saturday, October 06, 2001 8:21 AM Subject: Slicing a list with non-integer parameter? How? > Hi fiends, > I'm trying to determine the position of an item in a list in order to > delete it by slicing the list with non integer parameter. > Code I works just fine. But code II doe's not work: > > Code 1 with integer values: > > >> list1=[1,2,3,4] > >>> for i in list1: > ... if i==2: > ... pos=len(list)-len(list[i:]) > ... del list[pos-1] > ... print list > ... > [1, 3, 4] > > Code II with non integer values: > > >>> list2=['one','two','thrie','four'] > >>> for i in list2: > ... if i=='drie': > ... pos=len(list)-len(list[i:]) > ... del list[pos-1] > ... print list > ... > Traceback (innermost last): > File "", line 3, in ? > TypeError: slice index must be int > > > PS: my Python version is 1.5 > > thanks in advance > > > From python_only at yahoo.com Wed Oct 10 05:38:26 2001 From: python_only at yahoo.com (Goh S H) Date: 10 Oct 2001 02:38:26 -0700 Subject: Deploy without distribute python source code Message-ID: <184fbd02.0110100138.2283317f@posting.google.com> Hi all, I would like to deloy some projects which making use of Python, but I do not want to distribute Python source code due to several reasons. Is there any ways to do this? Is it portable to distribute .pyc? Regards, Goh From tdelaney at avaya.com Sun Oct 14 20:38:42 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 15 Oct 2001 10:38:42 +1000 Subject: Question: Which Python to choose? Message-ID: > From: Steve Holden [mailto:sholden at holdenweb.com] > "K?roly Ladv?nszky" wrote ... > > www.python.org and www.activestate.com seem to release > their versions with Personally, I like to use the PythonWare releases http://www.pythonware.com as it is so much easier to have multiple versions on the one machine. Doesn't mess at all with the registry ... I also have ActiveState 1.5.2 on my machine for when I want to use win32all (specifically for maintaining an old project). I think at one stage I worked out how to use the 1.5.2 win32all with PythonWare 1.5.2 IIRC, but I don't have a machine available to install ActiveState 2.x on so I can extract the necessary bits to make it work with PythonWare 2.x. My editor is configured so I can very easily change between ActiveState 1.5.2, PythonWare 1.5.2, PythonWare 2.0, PythonWare 2.1.1 and Jython 2.0. Makes testing against various versions incredibly easy. Tim Delaney From sholden at holdenweb.com Fri Oct 12 20:16:00 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 12 Oct 2001 20:16:00 -0400 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: Message-ID: "Tim Peters" wrote ... > [Michael Chermside, on a conditional expression] > > ... > > If people sign off on taking "then" as a new keyword, I think the chances > are good that we could get > > x = if e1 then e2 else e3 > > into 2.2b1. That's the only obvious spelling, hence the only truly Pythonic > way to spell it. Other languages spelling it that way range from Algol-60 > (Guido's first intense language affair) to Haskell. > And so perhaps by extension x = if e1 then e2 elif e3 then e4 else e5 ? Yet again starting to look a little Lispish. Of course, eventually people will be posting asking us to debug x = if if e1 then e2 else e3 then e4 else e5 and similar. But then every language has its abusers . > > hoping-that-less-speed-and-more-thinking-leads-to-a-better-design- > > ly yours, > > less-thinking-will-get-there-faster-ly y'rs - tim > but-there-may-not-be-the-place-you-want-to-get-ly y'rs - steve From loewis at informatik.hu-berlin.de Thu Oct 18 13:24:40 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: Thu, 18 Oct 2001 19:24:40 +0200 (MEST) Subject: Random from Dictionary In-Reply-To: <15311.3858.587746.114216@beluga.mojam.com> (message from Skip Montanaro on Thu, 18 Oct 2001 12:19:14 -0500) References: <4f7234de.0110180504.20aa475b@posting.google.com> <9qml3o$ovl8k$1@ID-11957.news.dfncis.de> <181020010938443703%tpayne@mac.com> <9qmoft$p7mln$1@ID-11957.news.dfncis.de> <15311.3858.587746.114216@beluga.mojam.com> Message-ID: <200110181724.TAA20293@paros.informatik.hu-berlin.de> > Perhaps I'm coming in on this thread a bit late (don't remember seeing it > and can't find it at Google Groups, however, so maybe it just hasn't fully > propagated around), but I see nothing in the doc string for random.choice > that suggests it should work with a dictionary. Where's the bug? There is no bug; it's just that Emile van Sebille was claiming that you could use random.choice on a dictionary. Regards, Martin From dradul at yahoo.com Tue Oct 23 06:36:04 2001 From: dradul at yahoo.com (P. Alejandro Lopez-Valencia) Date: Tue, 23 Oct 2001 05:36:04 -0500 Subject: Length on an input parameter in python References: Message-ID: <9r3gtu$qskna$1@ID-99513.news.dfncis.de> In article , coolslife at yahoo.com says... >Oleg Broytmann wrote in message news:... >> On Thu, Oct 11, 2001 at 03:16:07PM -0700, coolslife wrote: [snip] >So any suggestions on how to overcome this limitation? thx. > Use bash with all the configuration options turned on as your shell. You need to build and install it yourself as it is not supplied with commercial unix implementations. You said you use "unix" 2.6. Among the 50+ implementations I am aware of, it is probably Solaris; you could try using /usr/x4pg/bin/ksh (or is it jsh?) but add it to /etc/shells or you are in for unsufferable pain. -- P. Alejandro L?pez-Valencia Kenkon Itteki --- Heaven and Earth at one stroke From maj64 at hotmail.com Fri Oct 12 19:06:07 2001 From: maj64 at hotmail.com (Mark J) Date: 12 Oct 2001 16:06:07 -0700 Subject: dictionary.update() enhancement? References: <3BC64CC4.444A77E7@alcyone.com> Message-ID: Mark J wrote: >> Because it's not as straight-forward as saying d.update(other, >> collision_handler) and it's about 10 times slower. Erik Max Francis wrote: > Ten times slower? What in the world gives you that idea? Try it: import time dictsize=1000 numloops=10000 d={} other={} for i in range(dictsize): #populate the dicts d[i]=None other[i]=None def withupdate(other): for i in range(numloops): d.update(other) def withloop(other): for i in range(numloops): for k, v in other.items(): if d.has_key(k): #this "collision function" will merely duplicate #update's current behavior; #i.e. overwrite the existing value. d[k]=v else: #new key d[k]=v print "Dictionary size: %s Number of loops: %s" % (dictsize, numloops) start = time.clock() withupdate(other) finish = time.clock() print "with update: %5.2fs"%(finish-start) start = time.clock() withloop(other) finish = time.clock() print "with loop: %5.2fs"%(finish-start) ****** Results of run on RedHat 7.1, Dell OptiPlex GX150, 512MB RAM Dictionary size: 1000 Number of loops: 10000 with update: 0.81s with loop: 19.36s >>> 19.36/0.81 23.901234567901231 Ignoring the other benefits to an unhanced update function, that's a big speedup over hand-iteration. Different test runs using different parameters were roughly the same. The above code merely preserves the semantics of the existing update function since that's the fairest test until dictionary.update() is changed. (Note: removing the conditional in withloop() still keeps it about 10x slower.) Of course, the performance difference will decrease as the complexity of the collision function increases, but many useful collision functions are about as simple as or even simpler than the one currently used by dictionary.update(). By claiming only 10x faster in my last message, I was trying to (reasonably and fairly?) account for the extra overhead of running the collision function within update(). Please correct me if I'm missing something. I'd also be interesting in hearing any big discrepancies on the performance factor on different platforms. Mark From tjreedy at home.com Sat Oct 27 16:07:26 2001 From: tjreedy at home.com (Terry Reedy) Date: Sat, 27 Oct 2001 20:07:26 GMT Subject: Dictionary from list? References: Message-ID: <2uEC7.161518$5A3.57166879@news1.rdc2.pa.home.com> "Tim Peters" wrote in message news:mailman.1004203049.21483.python-list at python.org... > [Terry Reedy] > > Fact: a Python dictionary literal is a sequence of key:value pairs of > > literals, with the first becoming a hashable object, and only such a > > sequence. > > Sounds more like a definition than a fact . You've touched on a subtle difference of role-related viewpoints . Implemented definitions create observable facts. For you as a core coder, the above *is* a definition (mandated by your partner and bought into by you) to be maintained as you revise the code. For me as a user, it is a current observable fact which I cannot change. For me as an advocate/supporter of the idea that the behaviour of dictionary() with respect to sequences should parallel that defined fact, the rhetorical point is that it is not merely 'a' definition found in a book on some shelf but 'the' intended and observed behavior that we users are currently familiar with and hopefully comfortable with. >>... > > Proposed rule 1: the dictionary() constructor should accept a sequence > > of pairs of objects, with the first being keyable (hashable). In > > particular, it should invert dict.items. > > In current CVS, it does. In 2.2-speak, it accepts an iterable object > producing iterable objects producing exactly 2 objects. To me, 'exactly 2' implies that dictionary() calls pair.next() a third time and objects if it succeeds (as I believe it should, see below). Presently true? > > Note: by type, 'pair' might mean duple only; by interface, it would > > mean an object reporting a length of two and yielding objects with > > indexes 0 and 1. > > "By interface" is important, but the details there are off for 2.2 -- > iterable objects don't have to support len or indexing. Whoops. I didn't recurse on the generalization from fixed sequence to iterator. But there is a point to the 'length of two' bit (again, see below). > For example, > > class AddressBookEntry: > # with .firstname, .lastname attributes > ... > def __iter__(self): > return iter((self.firstname, self.lastname)) > > A sequence of AddressBookEntry instances is OK to pass to dictionary(), > despite that an AddressBookEntry defines neither __len__ nor __getitem__. A > generator yielding instances of AddressBookEntry is also fine; etc. Here's the 'below' twice referred to above: Would AddressBookEntry instances still be OK if the last line were, for instance, changed to return iter((self.firstname, self.lastname, self.address)) My point about a length of exactly two is a) the observation that silently ignoring items beyond two is not consistent with the processing of literals ('d={1:2:3}', for example, is a SyntaxError) and b) my feeling that doing so would as often be wrong, creating a silent bug, as right. > > Comment: once pair is defined, this rule gives a uniform target for > > conversion from other formats, including those generated by other > > software systems. I currently vote for the latter. > > I didn't understand "the latter" here, unless it's a vote for "other > software systems", in which case I'm keen to see the patch . Whoops again, this time in respect to wording. I was referring to a broad interface definition of 'pair' (versus a narrow structural definition). Since you have already implemented such, no patch is needed. My main point is that clearly defining the sequence part of the domain of dictionary() and doing so by analogy with the domain of the literal constructor gives a clear target for conversion programs from the potentially unbounded set of other forms that which you and I seem to agree should remain outside that domain. > > Proposed rule 2: dictionary() should reject any other sequence, just > > as does the internal constructor-from-literals. > > "Sequence" is a slippery word. dictionary() continues to accept a mapping > object too. Of course, "mapping object" is also a slippery phrase. I am only discussing dictionary() and have no opinions about dictionary(), nor information on what the alternatives might be. > > Paraphrase: conversions from the many other possible formats should be > > handled externally from dictionary(). > > Indeed, we're going to cheerfully endure abuse for sticking to that. Relative to the alternative, so will I for advocating such. > > Opinion 3: Given the fact and comments above, these two rules should > > be easy to understand and teach. > > Yup. Glad we agree ;<) Terry J. Reedy From temp_ttwcny at yahoo.com Thu Oct 4 14:27:57 2001 From: temp_ttwcny at yahoo.com (Hung Jung Lu) Date: Thu, 4 Oct 2001 11:27:57 -0700 (PDT) Subject: Python contractor job, Westchester, NY, USA Message-ID: <20011004182757.52135.qmail@web21003.mail.yahoo.com> Contractor job for 4 months for a skilled Python/C++ programmer in Westchester county, NY, U.S.A. Local candidates only. Details at: http://jobsearch.monster.com/jobs/12922307.asp?jobid=129 __________________________________________________ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 From skip at pobox.com Wed Oct 31 19:42:03 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 31 Oct 2001 18:42:03 -0600 Subject: Underscore data hiding (was python development practices?) In-Reply-To: References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> <9rpbk1$19rg$1@nntp6.u.washington.edu> Message-ID: <15328.39515.105909.309949@beluga.mojam.com> >> A double leading underscore is requred to coax Python into mangling >> an attribute. Peter> heh... so: Peter> C++::private == Python."__*" Peter> C++::protected == Python."_[a-zA-Z]*" Peter> C++::public == Python."[a-zA-Z]*" Peter> ;) Smiley or not, you seem to be trying a bit too hard to compare Python with C++. They serve dramatically different audiences. After all, "we're all adults here". That held true when I first heard it several years ago and it holds true today. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From sholden at holdenweb.com Wed Oct 10 19:01:13 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 10 Oct 2001 19:01:13 -0400 Subject: problem using using list with function References: Message-ID: "adam griffin" wrote in message news:vq3x7.5769$0Z6.380412 at newsread1.prod.itd.earthlink.net... > I think I figured out my problem. I had the function definition at the end > of my script when I put it at the beginning it worked. is this the only > place you can put definitions? > A function has to be defined before a call to it is executed. You can think of the "def" statement as assigning the functional meaning to the function name. If calls to the function appear inside other functions you will be OK, as functions don't get executed when they are compiled. For this, and other, reasons, the main part of a module is often coded as a "main()" function, and the code finally executed with if __name__ == "__main__": main() at the end of the script. The other reasons include making it easy to run tests on a module really designed to be imported, but it's a good paradigm. regards Steve -- http://www.holdenweb.com/ From loewis at informatik.hu-berlin.de Mon Oct 29 03:56:00 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 29 Oct 2001 09:56:00 +0100 Subject: problem in xml.dom.minidom References: <9rj44m$1oej$1@news1.sinica.edu.tw> Message-ID: "doug" writes: > xml.sax._exceptions.SAXReaderNotAvailable: No parsers found <---- ##### > why??? #### Because you haven't build pyexpat.so. Regards, Martin From dkuhlman at rexx.com Tue Oct 30 11:30:59 2001 From: dkuhlman at rexx.com (Dave Kuhlman) Date: 30 Oct 2001 10:30:59 -0600 Subject: Embedding Python in C/C++ References: <3BDE8130.CB1CE86B@fokkerspace.nl> <3BDE877B.37D1E09@fokkerspace.nl> Message-ID: <1004460136.619849@rexx.com> Yes it is possible to embed the Python interpreter in a C/C++ application. Yes it is possible to evaluate Python scripts from within C/C++ code. And yes, Python was intended for this purpose. Suggestions: 1. Read "Extending and Embedding the Python Interpreter" in the standard Python documentation. 2. Work with the examples in Demo/embed in the Python source code distribution. 3. Look at the function PyRun_SimpleString (in Section 2 of "Python/C API Reference Manual" in the standard Python documentation). 4. Ask some more questions. - Dave Arno Baan wrote: >I'm trying to find out wether Python is the answer to my problem. >I want to write a C/C++ program wich takes a XML input. >This input will also contain functions in a scripting language >(python?), that can >directly access objects in the main C program. >Is this possible and can someone perhaps give me an example of >something >like this being done? >I'm completely new to Python. > > Oeps Sorry, > > wrong name and e-mail adress above the preivious mail. > The name should be arno baan and the adress a.baan at fokkerspace.nl > Help is still needed though. > > thanx arno > -- Dave Kuhlman dkuhlman at rexx.com -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From MarkH at ActiveState.com Sat Oct 27 01:42:26 2001 From: MarkH at ActiveState.com (Mark Hammond) Date: Sat, 27 Oct 2001 05:42:26 GMT Subject: Windows/COM events/strange behavior References: Message-ID: <3BDA496D.3020902@ActiveState.com> Krzysztof Czarnowski wrote: [I wrote] >>What is the main loop doing. It too should be sitting on a >>PumpWaitingMessages() loop. ... > I really do observe the same behaviour with other apps (e.g. pfe file > editor). > > My main thread loop is doing (slightly simplified): > > while 1: > event_stop.wait(3) > if event_stop.isSet(): break > if msvcrt.kbhit(): > k = msvcrt.getch() > if k in ['s', 'S']: break > > The PumpWaitingMessages() loop is executed in a child thread. In parallel > another "CORBA child-thread" is working. As I said, this main thread probably needs to be calling PumpWaitingMessages() each time around the loop. Mark. From sholden at holdenweb.com Mon Oct 29 04:22:42 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:22:42 -0500 Subject: win32com parameters References: <9rgqf0$k1d$1@diana.bcn.ttd.net> Message-ID: "Alberto Rodriguez [FoxPress]" wrote in message news:9rgqf0$k1d$1 at diana.bcn.ttd.net... > HI: > > I'm working with win32com and run fine to me when i ask a remote method > without parameters > but not with parameters. I have this error: > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object of type 'int' is not callable > > the code is: > > import win32com.client > ox = win32com.client.Dispatch("proy1.miclase") > oRec = ox.primero('asfd') > > The COM objetct is writed in Visual Foxpro and run fine from > Visual FoxPro or Visual Basic > Alberto: are you sure that primero IS a method? The error message seems to imply it is an attribute, or property. Try: import win32com.client ox = win32com.client.Dispatch("proy1.miclase") print ox.primero to find out what datatype you are dealing with. regards Steve -- http://www.holdenweb.com/ From brueckd at tbye.com Tue Oct 30 23:58:56 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 30 Oct 2001 20:58:56 -0800 (PST) Subject: python development practices? In-Reply-To: Message-ID: On Wed, 31 Oct 2001, Peter Wang wrote: > as an aside, and i don't mean to sound obnoxious, but why did guido > not put in data hiding into python at an earlier stage? my colleague > whose background on generic programming comes entirely from the STL > points this "wart" out as one of python's largest, and brings up the > good point that data hiding was well known to the OOP world at the > time of python's first incarnations. "Well known" != "Always a Good Thing". Curly braces were also well-known then too, and I'm very glad Guido chose against using them. :) A good question to ask yourself (and your colleague) is why you want data hiding. If it's to prevent against honest mistakes, great (notice that the kind of data hiding that Python gives you does this). Be cautious, however, about buying into notions about protecting your code against rogue programmers, or programmers who try to subvert your code. If someone wants to do that, they will, regardless of what fences you build into your code. Essentially it amounts to catering to immature programmers, which doesn't make a lot of sense (you're teaching them it's okay to do whatever they can *get away with*, instead of doing what they *should* do). As someone else pointed out, if you are having to accomodate people who can't follow simple directions, then you probably have bigger problems that need dealing with. (there's actually a really interesting philisophical side to all this: forcing people to do something makes them weaker, while teaching them underlying principles and letting them experience for themselves the plusses and minuses makes them stronger and self-reliant. But hey, I'm getting off topic). A better approach is to cater to mature programmers and to use processes that help other programmers mature too. A few places I've worked have used something like the following (and these work well for non-Python code too) and they really helped me: If you're writing code that others will use: - Provide some overview documentation, even if it's nothing more than 10 or 20 lines at the top of the module (or C++ header file or...). This can be a high level description of how and why someone would use this library. - As much as possible, avoid writing documentation that shows how to use the APIs (except at a very high level). Instead, direct people to your unittests of the module/library. Users of the code are confident that this "API documentation" is accurate and up-to-date (since your unittests pass) and that it reflects "legal" ways of using the code. - As a user of the module, don't use APIs or access member variables not tested in the unittests, or if you do, do so realizing that you're on your own if things break. We've used these guidelines and have had very few problems that you'd consider related to "data-hiding". When breakage occurs, we go look at the unittests (including the previous versions if needed) and compare it to the code that broke. If breakage is due to the library maintainer changing the documented use and behavior of the code, it's the maintainer's responsibility to fix the problem, provide a good upgrade path, etc. If the breakage is because someone was relying on a particular member variable or non-public API, then it's up to that person to fix the problem (where fix may include submitting to the maintainer a patch for a new API and adding some new tests). There's really not much room there for squabbles or other problems, and it takes either party about 1 mistake before they learn to be more disciplined and follow the process. Like I said, these worked for me and really helped me become more disciplined. -Dave From emile at fenx.com Thu Oct 18 10:16:12 2001 From: emile at fenx.com (Emile van Sebille) Date: Thu, 18 Oct 2001 07:16:12 -0700 Subject: Random from Dictionary References: <4f7234de.0110180504.20aa475b@posting.google.com> <9qml3o$ovl8k$1@ID-11957.news.dfncis.de> <181020010938443703%tpayne@mac.com> Message-ID: <9qmoft$p7mln$1@ID-11957.news.dfncis.de> "Tim Payne" wrote in message news:181020010938443703%tpayne at mac.com... > In article <9qml3o$ovl8k$1 at ID-11957.news.dfncis.de>, Emile van Sebille > wrote: > > > Maybe choice in random helps out. > > I've always gotten this error when trying choice. I figured you just > couldn't use it on a dictionary, but maybe something else is wrong with > my install? > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.1/random.py", line 329, in choice > return seq[int(self.random() * len(seq))] > KeyError: 1 I can't confirm that error. I tested with 1.5.2, 2.0, 2.1 and 2.2a4+ and it appears to work If (for whatever reason) you don't get this resolved, you could do something like: kys = dict.keys() for i in xrange(desired_count): dowhateverwith(dict[choice(kys)]) HTH, -- Emile van Sebille emile at fenx.com --------- From loewis at informatik.hu-berlin.de Sun Oct 21 08:21:04 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 21 Oct 2001 14:21:04 +0200 Subject: Random from Dictionary References: Message-ID: "Tim Peters" writes: > Season to taste. In 2.2 you could use a more memory-efficient scheme via > iterating over d directly: > > def random_from_dict(d, x): > "Return and remove x random (k, v) pairs from d." > from random import random > n = float(len(d)) # float() so x/n later doesn't truncate to 0 > if not 1 <= x <= n: > raise ValueError("go away") > result = [] > for k in d: > # Choose this item with probability x/n. > if random() <= x/n: > result.append((k, d[k])) > x -= 1 > if x == 0: > break > n -= 1 > for k, v in result: > del d[k] > return result Does that give each key in the dictionary the same probability of being picked (assuming random() distributes uniformly)? If yes, is there some easy way to "see" that this is the case? If no, could one design an algorithm that iterates over a dictionary only once, still offers the same probability to each key? Regards, Martin From sholden at holdenweb.com Mon Oct 29 04:18:55 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:18:55 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3BDC0341.8A213560 at engcorp.com... > Christy J wrote: > > > > I need a binary search tree in python that uses classes. I'm trying to > > count words from a file and spit out the number of times they occur > > and in alphabetical order. I got bintree[ [key, data], left, right] > > but don't know how to implement using classes. > > I'd be interested to hear which school is teaching with Python. > > Schools progressive enough to take a chance (a small one, mind > you, but they don't usually seem to think so) on something > not mainstream (i.e. not Java) are few and far between. > Strange how the mention of "school" and "homework" seems to have stopped the original poster from responding on BOTH threads. This is a pity, since c.l.py is one of the few groups where creative help (although not canned solutions) might be available. Guess it was the canned solution that was sought regards Steve -- http://www.holdenweb.com/ From vulpine at dontspam.earthling.net Tue Oct 16 20:18:51 2001 From: vulpine at dontspam.earthling.net (Tod Fox) Date: Wed, 17 Oct 2001 00:18:51 GMT Subject: Further help w/ readline needed (was:Re: Past command buffer gone in interpreter?) References: Message-ID: Ignacio Vazquez-Abrams wrote: > You'll need to install the readline-devel RPM. I made sure readline was installed on my system, and then installed the readline-devel RPM without any problems. I uncommented the readline entry in Modules/Setup, but when I run make I get the following error: ar cr libpython2.1.a Modules/gcmodule.o Modules/threadmodule.o Modules/signalmodule.o Modules/posixmodule.o Modules/_sre.o Modules/readline.o Modules/arraymodule.o Modules/mathmodule.o Modules/timemodule.o Modules/operator.o Modules/_testcapimodule.o Modules/pwdmodule.o Modules/grpmodule.o Modules/audioop.o Modules/imageop.o ranlib libpython2.1.a gcc -Xlinker -export-dynamic -o python \ Modules/python.o \ libpython2.1.a -lpthread -ldl -lutil -lreadline -ltermcap -lm /usr/bin/ld: cannot find -ltermcap The commented text in Setup suggests replacing -ltermcap with -ltermlib, and this results in the error: gcc -Xlinker -export-dynamic -o python \ Modules/python.o \ libpython2.1.a -lpthread -ldl -lutil -lreadline -ltermlib -lm /usr/bin/ld: cannot find -ltermlib if I delete that -lterm* entirely, it results in: ar cr libpython2.1.a Modules/gcmodule.o Modules/threadmodule.o Modules/signalmodule.o Modules/posixmodule.o Modules/_sre.o Modules/readline.o Modules/arraymodule.o Modules/mathmodule.o Modules/timemodule.o Modules/operator.o Modules/_testcapimodule.o Modules/pwdmodule.o Modules/grpmodule.o Modules/audioop.o Modules/imageop.o ranlib libpython2.1.a gcc -Xlinker -export-dynamic -o python \ Modules/python.o \ libpython2.1.a -lpthread -ldl -lutil -lreadline -lm libpython2.1.a(posixmodule.o): In function `posix_tmpnam': /home/vulpine/Python-2.1.1/./Modules/posixmodule.c:4212: the use of `tmpnam_r' is dangerous, better use `mkstemp' libpython2.1.a(posixmodule.o): In function `posix_tempnam': /home/vulpine/Python-2.1.1/./Modules/posixmodule.c:4168: the use of `tempnam' is dangerous, better use `mkstemp' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `tgetnum' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `tgoto' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `tgetflag' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `BC' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `tputs' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `PC' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `tgetent' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `UP' /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../libreadline.so: undefined reference to `tgetstr' collect2: ld returned 1 exit status Can anyone provide further guidance about this issue? Thanks! Kit From chris.gonnerman at newcenturycomputers.net Sat Oct 6 01:29:05 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sat, 6 Oct 2001 00:29:05 -0500 Subject: why are *two* ctrl-D's needed with readlines() References: <9pl2ki+tpjl@eGroups.com> Message-ID: <008d01c14e27$d1e19ec0$0101010a@local> FWIW I have just tested and I get the same behavior; Linux 2.2, Python 2.1.1. ----- Original Message ----- From: "Wilhelm Fitzpatrick" To: Sent: Friday, October 05, 2001 2:45 PM Subject: Re: why are *two* ctrl-D's needed with readlines() > "Wilhelm Fitzpatrick" wrote in message > news:mailman.1002297908.5879.python-list at p... > > I was writing a little python script using > > > > for line in sys.stdin.readlines() : > > > > to iterate through input, and I noticed that I had to press ctrl-D > > TWICE to terminate input. > ... > > for line in sys.stdin.read().splitlines() : > > > > terminates on the first ctrl-D (as I would expect). > > "Steve Holden" responded: > > Are you pressing the ^D at the end of a line of input, or at the > > start of a blank line? > > (I replied to this message once already, but I think it went to Steve > and not the list. My apologies if some of this is a duplicate) > > I am pressing ctrl-D at the start of blank line. My platform is > indeed Linux, and that may have some bearing. I could not reproduce > the behavior on a Solaris box with 2.1.1 installed. I installed 2.1.1 > under Linux, and got the same problem behavior as described above. > > Another interesting test I did was to place a readlines() loop in a > script and invoke it this way: > > cat | myscript.py > > Which produced the correct behavior (EOF on single ctrl-d) > It appears to be some bad interaction between Linux (glibc?) and the > way python handles stdin for readlines(), as opposed to say read() or > raw_input(), which seem to be doing the right thing. > > Any thoughts from the gurus? > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From phd at phd.pp.ru Mon Oct 15 08:53:20 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 15 Oct 2001 16:53:20 +0400 Subject: Regex problem In-Reply-To: <9qelne$jcg$1@green.tninet.se>; from gustafl@algonet.se on Mon, Oct 15, 2001 at 02:47:37PM +0200 References: <9qelne$jcg$1@green.tninet.se> Message-ID: <20011015165320.S17226@phd.pp.ru> On Mon, Oct 15, 2001 at 02:47:37PM +0200, Gustaf Liljegren wrote: > But look what happens as soon as I add a space (or any other character) > before: > > >>> s3 = ' ' > >>> re.match(re_link, s3).group() > Traceback (most recent call last): > File "", line 1, in ? > re.match(re_link, s3).group() > AttributeError: 'None' object has no attribute 'group' http://www.python.org/doc/current/lib/matching-searching.html Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From roy at panix.com Fri Oct 19 07:50:51 2001 From: roy at panix.com (Roy Smith) Date: Fri, 19 Oct 2001 07:50:51 -0400 Subject: Method returns self? References: Message-ID: Ignacio Vazquez-Abrams wrote: > Another thing you could do, if you plan to have more than one possible format, > is to have myParser.parse() do the verification of the data and return a > myData1, myData2, etc. object depending on the format. Actually, I do that already. The data class has several subclasses, and the parser returns the right one. Each data subclass would have its own verify() method. Actually, more likely the base data class will also have a verify() method, and each subclass's verify() will call data.verify(), then do its own additional checking. Another problem I have is that I'm in a running argument with a coworker about what's syntax (i.e. should be checked in the parser) and what's semantics (and should be checked in data.verify()), but that's a problem we'll have to solve on our own :-) From cthuang at vex.net Thu Oct 25 09:31:59 2001 From: cthuang at vex.net (Chin Huang) Date: Thu, 25 Oct 2001 13:31:59 +0000 (UTC) Subject: Creating users on Windows NT References: <9r7tqp6mia@enews3.newsguy.com> Message-ID: <9r948f$82e$1@news.tht.net> In article <9r7tqp6mia at enews3.newsguy.com>, <63.199.26.230 [noah at noah.org]> wrote: >Does anyone have sample code to create a user >on a local or a remote NT machine? I never actually tried it, but look at http://msdn.microsoft.com/library/en-us/netdir/adsi/creating_local_users.asp From sholden at holdenweb.com Thu Oct 4 13:03:03 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 13:03:03 -0400 Subject: SQL/Python question -- slow... What is the fixed cost? References: <3BBB7DFD.25217E1A@iems.nwu.edu> <3bbc26d3.1098181651@spamkiller.newsfeeds.com> <3BBC8E99.56BD59FB@iems.nwu.edu> Message-ID: "Leonardo B Lopes" wrote in message news:3BBC8E99.56BD59FB at iems.nwu.edu... > Thanks Mark! Actually I am doing my best to keep my system independent > of mysql. And my db is quite particular: It is only written to once. > After that, it is only queried, and even so in a quite particular way. > But my db is pretty big. This instance, for example, has a table with > 83000+ records. It is not so much that the query joining that table with > 2 others takes .001 cpusec that worries me. That is OK. The problem is > that some other pretty simple queries also take the same time. If that > is always the case, then I will have to find another quite more > sophisticated solution for data storage, and that is what I am trying to > avoid. > Leo: The best starting point for efficient database performance is a clean, normalized database design. I take it your database is structured in third normal form? If you are *absolutely sure* that the data will not change (which I take to be the implication of your "only written to once") then you might permissibly deviate from normalized structures solely to improve query performance. However, 83,000 rows is not by any stretch of the imagination a large database. If you could outline your DB structures and the usage, maybe you would get more assistance. The particular database module need not be of concern. If you wanted, you could use Gadfly (although it uses depracated libraries, it does still work) and keep everything in memory! regards Steve -- http://www.holdenweb.com/ From info at mjais.de Fri Oct 12 07:38:43 2001 From: info at mjais.de (Markus Jais) Date: Fri, 12 Oct 2001 13:38:43 +0200 Subject: python + DOM docu?? Message-ID: <9q6kr1$m2mdb$1@ID-75083.news.dfncis.de> hello can anybody give me an URL where to get a tutorial on python + DOM? on the python.org web-site, the tutorial is not finished yet. oreilly has a book on python + xml, but unfortunately this is not yet published AFAIK regards markus From huaiyu at gauss.almadan.ibm.com Thu Oct 25 14:30:01 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 25 Oct 2001 18:30:01 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> <9r5h75$1m5$1@slb6.atl.mindspring.net> Message-ID: On Thu, 25 Oct 2001 07:18:31 GMT, Paul Winkler wrote: > >In this particular case, there is, because the two exits to (A) can be >combined into one test. I posted something like this to the other >recent thread on primes. >However, this probably won't satisfy you for two reasons: > >1) It's a special case - we have a known value we can use to >initialize the list, and add code before the loop to handle that. Yes, changing the algorithm to avoid the problem under discussion makes the example irrelavent here. I've tried such variations for this special case before posting the pseudocode. >2) There's still code duplication. Instead of duplicating the >primes.append(n) call, we're duplicating a comparison. Exactly. And it does not matter how trivial the duplication is in this case - it is an example. >The problem with the syntax you described is simply that the >conditions when it is useful are rather restrictive: > >1) There must be more than one condition to exit the loop. >2) There must be *exactly* two possible behaviors upon loop exit. > >I suspect that #2 is likely to be a pretty fragile requirement for >whatever you're testing. That for-while syntax is used as an illustration that there are _at least_ two types of exits. The purpose is to show that the simple if-break answers miss the point. The particular syntax can handle the case where all exits which are considered normal loop ends go to the same block of code, in analogy to what the else-clause does. Let's call this the 1-follow-up case. It cannot handle the more general problem, where there are multiple follow-up codes, and multiple exits go to each of them. Let's call this the n-follow-up case. Incidentally, the Goldilock examples do not deal with this problem because no two exits go to the same follow-up code. It is a 0-follow-up case. I do not know any clean syntax for n-follow-up case for n>=2. Of course they can be done using additional variables or functions, etc, but that's beside the point. Huaiyu From cliechti at gmx.net Wed Oct 31 17:09:39 2001 From: cliechti at gmx.net (Chris Liechti) Date: 1 Nov 2001 00:09:39 +0200 Subject: crypt libraries References: <3BE07D46.7080502@shaw.ca> Message-ID: Peter Preeper wrote in news:3BE07D46.7080502 at shaw.ca: > Are there any crypt libraries for python? I am looking for symmetric > type of encryption. you can start here: http://www.amk.ca/python/code/crypto.html > Peter Preeper > ppreeper at shaw.ca -- Chris From gurdon_merchant at ml.com Sun Oct 14 14:28:02 2001 From: gurdon_merchant at ml.com (Gurdon Merchant, Jr.) Date: 14 Oct 2001 11:28:02 -0700 Subject: Using NetScheduleJobAdd with calldll. References: <54723b6a.0110120506.2cd184ce@posting.google.com> Message-ID: <54723b6a.0110141028.685edc98@posting.google.com> Finally solved my problem. The win32 definition of NetScheduleJobDel() is: NET_API_STATUS NetScheduleJobDel( LPCWSTR Servername, DWORD MinJobId, DWORD MaxJobId ); "LPCWSTR Servername" is a pointer to a unicode string, not a string. > I believe I'm passing the string with the PC name incorrectly. So, yes I was passing the PC name incorrectly. > # Following returned ERROR_SUCCESS=0 when trying to delete job > # on local machine. > pcName = windll.cstring('', 2) This worked because Unicode is two bytes. The '2' made things work locally because regular ASCII is represented in Unicode as the second byte being \x00. So, windll.cstring('', 2) was in effect '\x00\x00' and so it worked on the local machine. Consider a remote pc called \\remotepc. This must not be: pcName = windll.cstring('\\\\remotepc') but rather: pcName = windll.cstring('\\\x00\\\x00r\x00e\x00m\x00o\x00t\x00e\x00\x00') Then, everything works. If windll accepted windll.cstring(u'\\\\remotepc') I could be really lazy. Since it does not I'll just wrap up names that need to be unicode. Thanks in advance, Gurdon Merchant, Jr. Gurdon_Merchant at ml.com From nobody at nobody.com Fri Oct 12 19:53:46 2001 From: nobody at nobody.com (CS338) Date: Fri, 12 Oct 2001 16:53:46 -0700 Subject: CPU time Message-ID: Hi, I thought time.clock() measures CPU time which (i assume) is consistent regardless of other S/W running.. but somehow the measurement fluctuates a lot. Am I misunderstanding this function? If so, what is the function w/ the functionality I'm looking for? From paul at boddie.net Thu Oct 25 06:52:26 2001 From: paul at boddie.net (Paul Boddie) Date: 25 Oct 2001 03:52:26 -0700 Subject: String comparison References: <4a0341c8.0110242221.592e603e@posting.google.com> Message-ID: <23891c90.0110250252.5c3c1fc2@posting.google.com> SNeelakantan_C at zaplet.com (Shankar) wrote in message news:<4a0341c8.0110242221.592e603e at posting.google.com>... > I started learning python recently and the examples given on > python.org only talk about number comparison. > I tried: > x = input("Proceed?"); > > if x == 'y': > print "You typed y\n"; > > > This gives out a syntax error. Firstly, drop the trailing semicolons - you don't need them in Python. In fact, semicolons are only ever used to separate statements if you're putting many statements on a single line. However, there does seem to be a restriction on having an "if" statement as the last statement on a line containing many statements: Python 2.0.1 (#18, Jun 22 2001, 02:26:03) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> x = 1; if x == 2: File "", line 1 x = 1; if x == 2: ^ SyntaxError: invalid syntax >>> Having said that, it could make code pretty hard to read if such tricks were allowed. Next, don't use "input" - use "raw_input". Otherwise, Python will think that you want it to evaluate your input as an expression, and I suspect that this is not what you want. >>> x = input("Proceed?") Proceed?y Traceback (most recent call last): File "", line 1, in ? File "", line 0, in ? NameError: There is no variable named 'y' Another thing: the "print" keyword automatically writes a "\n" character, so you might not need to include one in your string. You might actually want this, though, but I thought that it should at least be mentioned. Finally, your string comparison is absolutely what you should be using. So, that was the least of your worries. :-) Paul From dradul at yahoo.com Tue Oct 9 10:46:24 2001 From: dradul at yahoo.com (P. Alejandro Lopez-Valencia) Date: Tue, 9 Oct 2001 09:46:24 -0500 Subject: problem with FFT module from Numeric 20.2.0 References: <9pn4p1$jodve$1@ID-99513.news.dfncis.de> Message-ID: <9pv2d4$ks8os$1@ID-99513.news.dfncis.de> In article , nde at comp.leeds.ac.uk says... >On Sat, 6 Oct 2001 09:37:36 -0500, >P. Alejandro Lopez-Valencia wrote: >> The solution is to be explicit. Edit your file >> /usr/local/lib/python21/config/Makefile in the appropriate places (3, I >> don't recall their names off-had) to pass -R linker flags to ld. For >> example, I have added this in our lab box: >> >> -R/usr/lib -R/usr/local/lib -R/usr/local/ssl/lib -R/usr/openwin/lib >> >> Without these linker flags modules like socket and pyexpat won't work at >> all if called from restricted execution environments where you don't >> want a full environemnt definition, namely CGI's and batch jobs. >> > >I'm working on Linux; do problems of this nature affect Linux >also, or are they a Solaris-only thing? As Malcom Treddinnick points out the problem is the half hearted job of the Solaris linker. In Linux, at least on Debian and Redhat, you can always edit /etc/ldconfig and get over with it :) >But if this is the cause of the problem, why are the other modules >from the Numeric package unaffected? Why just fftpack? That's strange, and should not happen. See: bash-2.05$ ldd fftpack.so libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1 libc.so.1 => /lib/libc.so.1 libdl.so.1 => /lib/libdl.so.1 and bash-2.05$ ldd _numpy.so libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1 libc.so.1 => /lib/libc.so.1 libdl.so.1 => /lib/libdl.so.1 bash-2.05$ ldd /usr/local/bin/python libstdc++.so.3 => /usr/local/lib/libstdc++.so.3 libpthread.so.1 => /lib/libpthread.so.1 libsocket.so.1 => /lib/libsocket.so.1 libnsl.so.1 => /lib/libnsl.so.1 libdl.so.1 => /lib/libdl.so.1 libthread.so.1 => /lib/libthread.so.1 libm.so.1 => /lib/libm.so.1 libc.so.1 => /lib/libc.so.1 libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1 libmp.so.2 => /lib/libmp.so.2 bash-2.05$ ldd /usr/local/lib/libgcc_s.so.1 warning: ldd: /usr/local/lib/libgcc_s.so.1: is not executable libc.so.1 => /lib/libc.so.1 libdl.so.1 => /lib/libdl.so.1 >Confused, Hey! I've been using Solaris for at least 10 years and it still bites me back every day ;) -- P. Alejandro Lopez-Valencia Kenkon Itteki --- Heaven and Earth at one stroke From myuen at acs2.acs.ucalgary.ca Tue Oct 16 16:20:50 2001 From: myuen at acs2.acs.ucalgary.ca (Michael Yuen) Date: 16 Oct 2001 20:20:50 GMT Subject: Directed input Message-ID: <9qi4r2$gpq$1@nserve1.acs.ucalgary.ca> I'm just in the process of learning Python right now and i'm wondering if there's a way run a program to take a file via directed input and sending output to another file via the command line. Here's what I mean: myprogram.py < my_input > my_output -- From grante at visi.com Sat Oct 20 21:29:16 2001 From: grante at visi.com (Grant Edwards) Date: Sun, 21 Oct 2001 01:29:16 GMT Subject: Smtplib module References: <3BD20BAE.6346.7693E0@localhost> Message-ID: On Sun, 21 Oct 2001 00:14:35 +0200, Gerhard H?ring wrote: >On Sat, Oct 20, 2001 at 11:41:34PM +0200, A wrote: >> I want to use smtplib module for sending emails. Is there any way how >> I can test a return code, generated by this module, to see if an email >> was accepting for delivery, for example? > >No, there is no way to do this. But this is a "feature" of >SMTP, not of Python's smtplib. Sure there is. There's no way to know if the message was delivered or read, but you can certainly find out if the SMTP server accepted it. The documentation for the "sendmail" method states: This method will return normally if the mail is accepted for at least one recipient. Otherwise it will throw an exception. That is, if this method does not throw an exception, then someone should get your mail. If this method does not throw an exception, it returns a dictionary, with one entry for each recipient that was refused. Each entry contains a tuple of the SMTP error code and the accompanying error message sent by the server. >The only way smtplib is concerned is if the "RCPT TO" command >fails with 550 "no such user". According the the smtplib documentation there are two other different errors that can cause a "sendmail" call to fail. >Then the sendmail method already returns the address as not >deliverable to. But at least my mailserver (Postfix) doesn't >return a 550 in such cases. That's a "feature" of Postfix: it accepts mail that it can't deliver. >There are some other possibilties, but these will only work in some >relatively rare cases, (finger, SMTP delivery receipts and possibly >others). But all of these are out of the scope of Python's smtplib. Not sure what other possiblities/cases to which you refer... -- Grant Edwards grante Yow! FIRST, I'm covering at you with OLIVE OIL and visi.com PRUNE WHIP!! From jdunnett at uoguelph.ca Sun Oct 28 19:38:15 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Sun, 28 Oct 2001 19:38:15 -0500 Subject: A Python\Tkinter Listbox Question Message-ID: <3BDCA4F7.B482D7D8@uoguelph.ca> I am having trouble keeping spacing when trying to enter things into a list box. I was wondering if there is anyone to maintain spacing when you enter strings an item into the listbox. For example the below code fragement is mean to read something in from a file pionter which has some output from a C program. It then strips the the whitespace, and newline character at the end and expands the tabs. I want to maintain that tab spacing when I get enter the string into the listobx is this possible? for item in input.readlines(): newitem = string.strip(item) newitem = item[:-1] newitem = string.expandtabs(newitem) print newitem self.object.toc.listbox.insert(END, newitem) Jeff From pengo243 at hotmail.com Thu Oct 4 13:01:05 2001 From: pengo243 at hotmail.com (Mark Berry) Date: Thu, 04 Oct 2001 17:01:05 GMT Subject: SQL/Python question -- slow... What is the fixed cost? References: <3BBB7DFD.25217E1A@iems.nwu.edu> <3bbc26d3.1098181651@spamkiller.newsfeeds.com> <3BBC8E99.56BD59FB@iems.nwu.edu> Message-ID: <3bbc9544.1126590741@spamkiller.newsfeeds.com> On Thu, 04 Oct 2001 11:30:17 -0500, Leonardo B Lopes wrote: >Thanks Mark! Actually I am doing my best to keep my system independent >of mysql. And my db is quite particular: It is only written to once. >After that, it is only queried, and even so in a quite particular way. >But my db is pretty big. This instance, for example, has a table with >83000+ records. It is not so much that the query joining that table with >2 others takes .001 cpusec that worries me. That is OK. The problem is >that some other pretty simple queries also take the same time. If that >is always the case, then I will have to find another quite more >sophisticated solution for data storage, and that is what I am trying to >avoid. My advice on this, MySQL will act completely differently when there are 20-30 concurrent connections than 1-2. They don't seem to have the sofistication in locking to handle heavy loads. Some very high volume websites strugle to get around this problem (slashdot). If you are not doing anything highly concurrent, then you shouldn't have any problem at all with MySQL. good luck :) > >Cheers, >Leo. > From jh at web.de Tue Oct 30 17:51:34 2001 From: jh at web.de (Jürgen Hermann) Date: Tue, 30 Oct 2001 23:51:34 +0100 Subject: [ANN] MoinMoin 0.10 Message-ID: <9rnasp$4l7$03$1@news.t-online.com> A WikiWikiWeb is a collaborative hypertext environment, with an emphasis on easy access to and modification of information. MoinMoin is a Python WikiClone that allows you to easily set up your own wiki, only requiring a Web server and a Python installation (1.5.2, 1.6 or 2.0). The most prominent change of this release is a fix for a UNIX time billenium bug (affecting RecentChanges sorting and page diffs). See below for a list of new features that were integrated since the last release. Following version 0.10, there will be some major refactorings regarding storage and output generation (see TODO for details). This version is still Python 1.5.2 compatible, but it's not extensively tested for that version and some parts of the system might not work there, especially seldom used macros and actions. Bug reports welcome! Homepage: http://moin.sourceforge.net/ Download: http://sf.net/project/showfiles.php?group_id=8482&release_id=59369 http://prdownloads.sourceforge.net/moin/ Mailing lists: http://lists.sourceforge.net/lists/listinfo/moin-user http://lists.sourceforge.net/lists/listinfo/moin-devel New features: * "#deprecated" processing instruction * config entry "SecurityPolicy" to allow for customized permissions (see "security.py" for more) * added distutils support * though not extensively tested, the standalone server now does POST requests, i.e. you can save pages; there are still problems with persistent global variables! It only works for Python >= 2.0. * "bang_meta" config variable and "!NotWikiWord" markup * "url_mappings" config variable to dynamically change URL prefixes (especially useful in intranets, when whole trees of externally hosted documents move around) * setting "mail_smarthost" and "mail_from" activates mailing features (sending login data on the UserPreferences page) * very useful for intranet developer wikis, a means to view pydoc documentation, formatted via a XSLT stylesheet, for details see http://purl.net/wiki/python/TeudViewer?module=MoinMoin.macro.TeudView or MoinMoin/macro/TeudView.py * "LocalSiteMap" action by Steve Howell * Added FOLDOC to intermap.txt Bugfixes: * Full config defaults, import MoinMoin now works w/o moin_config.py * Better control over permissions with config.umask * Bugfix for a UNIX time billenium bug (affecting RecentChanges sorting and page diffs) * data paths with directory names containing dots caused problems From tdelaney at avaya.com Sun Oct 28 17:07:16 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 29 Oct 2001 09:07:16 +1100 Subject: Integer coercion and 2.2 Type/Class changes Message-ID: > From: Guido van Rossum [mailto:guido at python.org] > com-nospam at ccraig.org (Christopher A. Craig) writes: > > > Consider the following Python 2.2 code: > > > > >>> class foo(int): > > ... def __init__(self, n=0): > > ... self=n > > This __init__ is a total no-op. The assignment to self is a local Well, not a total no-op. It takes more time after all ... Tim Delaney From gh_pythonlist at gmx.de Wed Oct 24 13:42:08 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Wed, 24 Oct 2001 19:42:08 +0200 Subject: MySQLdb... In-Reply-To: <20011024132847.2B0672AD3D@del-vap-bos.ralphpill.com>; from vincent_a_primavera@netzero.net on Wed, Oct 24, 2001 at 01:28:46PM +0000 References: <20011024132847.2B0672AD3D@del-vap-bos.ralphpill.com> Message-ID: <20011024194207.A4457@lilith.hqd-internal> On Wed, Oct 24, 2001 at 01:28:46PM +0000, Vincent A. Primavera wrote: > Hello, > I am experiencing a problem using MySQLdb with release 2.1.1 of Python... > The error is listed below. If anyone has any suggestions of how I can "fake > out" MySQLdb or what else I need to do I would greatly appreciate it. > > Thank you, > Vincent A. Primavera. > > WARNING: Python C API version mismatch for module _mysql: > This Python has API version 1010, module _mysql has version 1007. Your MySQLdb was compiled against an older version of Python, I guess 2.0. Just recompile it with Python 2.1. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From gerson.kurz at t-online.de Mon Oct 1 09:39:59 2001 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Mon, 01 Oct 2001 13:39:59 GMT Subject: Portable Serial I/O Message-ID: <3bb86fba.131484@news.t-online.de> Has anybody written a serial I/O class in Python that is portable between Win32 and Linux(Unix)? All serial I/O demos for Python seem to be either Win32 or Unix-specific, and I need to write something that is portable between the two. Thanks. From LLewin at oreilly.com Fri Oct 12 20:48:40 2001 From: LLewin at oreilly.com (Laura Lewin) Date: 12 Oct 2001 17:48:40 -0700 Subject: Python Cookbook: last call for recipes for printed version References: <9q52b1$3q5$1@lancelot.camelot> <4a249347.0110120316.a5de6eb@posting.google.com> Message-ID: Hi, There were some early press releases when we announced the Cookbook that described the co-publishing arrangement between ActiveState and O'Reilly. Here's a link to an ORA dispatch from Python 9 that introduced the Cookbook: http://python.oreilly.com/news/pythonday2_0301.html Also, as Alex points out, David clearly states on the site that the "partnership between ActiveState and O’Reilly provides the resources necessary to help bring this book to life. Furthermore, O'Reilly plans to publish a selection of the recipes in a paper volume." In addition, when you actually submit a recipe, you are brought directly to a page with a letter from me talking about publishing rights and O'Reilly's plans. Let me know if you have any questions, and please do contribute--we have plenty of room for more recipes but time is running out. Laura LLewin at oreilly.com ----------- bobh at hslda.org (Robert) wrote in message > > I don't think this was said at all. Not even in the original Figgins > call to contribute. > > Bob From gry at ll.mit.edu Tue Oct 16 14:54:03 2001 From: gry at ll.mit.edu (george young) Date: Tue, 16 Oct 2001 14:54:03 -0400 Subject: 2.1.1 build fails on hpux Message-ID: <20011016145403.4974a794.gry@ll.mit.edu> On an hp machine (uname -a --> HP-UX hp93k B.10.20 A 9000/785 2014221311 two-user license), aCC --version --> aCC: HP ANSI C++ B3910B A.01.23 ./configure --without-threads --without-gcc --with-cxx=aCC --prefix=/opt/python ... make ... cc -Ae -Wl,-E -Wl,+s -Wl,+b/opt/python/lib/python2.1/lib-dynload -o python \ Modules/ccpython.o \ libpython2.1.a -ldld -lm /usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (Modules/ccpython.o) was detected. The linked output may not run on a PA 1.x system. /usr/ccs/bin/ld: Unsatisfied symbols: _main (code) *** Error exit code 1 Help! -- George -- I cannot think why the whole bed of the ocean is not one solid mass of oysters, so prolific they seem. Ah, I am wandering! Strange how the brain controls the brain! -- Sherlock Holmes in "The Dying Detective" From robin at jessikat.fsnet.co.uk Thu Oct 11 19:22:05 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 12 Oct 2001 00:22:05 +0100 Subject: how do I add site-packages on Windows? References: <001f01c15253$42ed5da0$0101010a@local> Message-ID: In article , Tim Peters writes >[Chris Gonnerman] >> I've never understood why this is done this way. In site.py, >> the sys.path setup only adds site-packages on Unixoid OS's. >> On Windows it isn't done. > >It is (or will be, from your POV ) in 2.2. > >> ... >> Does ANYONE know why this decision was made? > >Probably, but not me, and I'm not sure it *was* "a decision". More likely >is that someone added it for Unix, and didn't have time to worry about a >dozen OSes they didn't use and knew nothing about. > > wouldn't it have been easier not to worry about the OS and do it for all? I guess there may be OSes without file systems, but then the path stuff becomes moot any how. -- Robin Becker From sholden at holdenweb.com Wed Oct 31 17:21:43 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 17:21:43 -0500 Subject: MS Excel 'Comment' Interface References: Message-ID: "L3m Ni$cAt3" wrote ... > > Hi all? I've been piecing together a Python prog to use at work for the > past few weeks (to speed up some of my time-consuming 'find on the web then > plug into Excel" busy-work). The kind of prog that needs new features added > to it every other day or so. So far it has gone pretty well, except I have > seemed to have reached a sticking point. I would like to be able to enter > MS Excel "Comments" (you know, right-click, then insert comment; it differs > from whatever is actually in the cell). I can't seem to figure it out. > I've looked through all the win32all documentation and I think I just don't > know what kind of interface to look for. Dispatch lets me read and write to > specific columns and all that, but I just can't seem to find what I need. > If you know how, could you just show me with a simple example, my actual > comments are going to come from various sources (net, files, generated by > the python prog itself) and I figure all that out easily enough, I just need > some kind of starting point. Thanks, I appreciate it. By the simple expedient of recording a macro I get the following VBA that you should be able to render into Python fairly easily: Range("A1").AddComment Range("A1").Comment.Visible = True Range("A1").Comment.Text Text:="Steve Holden:" & Chr(10) & "This is a comment" & Chr(10) & "" Range("A1").Select Hope this helps! regards Steve -- http://www.holdenweb.com/ From cmkleffner at gmx.de Mon Oct 8 11:39:02 2001 From: cmkleffner at gmx.de (cmkl) Date: 8 Oct 2001 08:39:02 -0700 Subject: where lives uthread (microthreads) now ?? Message-ID: <3b091a1c.0110080739.23205b07@posting.google.com> Hi, I wanted to test a samle code with microthreads needed. The download area: http://world.std.com/~wware/uthread.html is not available however. Is there a mirror to get this code somewhere? greetings Carl (cmkleffner at gmx.de) From sholden at holdenweb.com Mon Oct 29 04:18:55 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:18:55 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3BDC0341.8A213560 at engcorp.com... > Christy J wrote: > > > > I need a binary search tree in python that uses classes. I'm trying to > > count words from a file and spit out the number of times they occur > > and in alphabetical order. I got bintree[ [key, data], left, right] > > but don't know how to implement using classes. > > I'd be interested to hear which school is teaching with Python. > > Schools progressive enough to take a chance (a small one, mind > you, but they don't usually seem to think so) on something > not mainstream (i.e. not Java) are few and far between. > Strange how the mention of "school" and "homework" seems to have stopped the original poster from responding on BOTH threads. This is a pity, since c.l.py is one of the few groups where creative help (although not canned solutions) might be available. Guess it was the canned solution that was sought regards Steve -- http://www.holdenweb.com/ From graz at mindless.com Sat Oct 27 07:45:06 2001 From: graz at mindless.com (Graham Ashton) Date: Sat, 27 Oct 2001 11:45:06 GMT Subject: Question about Tkinter message boxes References: <3B7D5BA4.69A8C2EC@earthlink.net> <_dbC7.6240$lp2.846803@news1.cableinet.net> Message-ID: <67xC7.11947$lp2.1723866@news1.cableinet.net> In article , "gcash" wrote: > "Graham Ashton" writes: > >> Have you tried this: >> >> from Tkinter import * >> NoDefaultRoot() > > So how did you find this? Mark Lutz's "Programming Python", 2nd edition. Having had similar problems myself I remembered the posting, then whilst reading the book I came across the alternative solution. -- Graham From quinn at hork.ugcs.caltech.edu Thu Oct 11 22:40:16 2001 From: quinn at hork.ugcs.caltech.edu (Quinn Dunkan) Date: 12 Oct 2001 02:40:16 GMT Subject: Assigning to lists with arbitrary names References: <3BC35131.C9AB1393@motorola.com> Message-ID: On Tue, 09 Oct 2001 14:34:09 -0500, Stephen Boulet wrote: >I can't quite figure out how to do this. > >I have 100 text files in a directory: file00.txt to file99.txt. > >I want to read each file in turn, parse it, and generate a list from >each file. > >Here's the problem: I want to name each list list00 to list99. I don't >want to do list[0] to list[99] (since each list is actually a list of >lists, and I'd like to avoid a list of lists of lists :). > >Any idea how I can do this? Thanks. You want the list of lists. Unless your parser generates a list of lists, you will not get a list of lists of lists. def process_file(fp): # read from fp and generate a list parsed_files = [ process_file(open('file%02d.txt' % n)) for n in range(100) ] If your parser does generate a list of lists, and you think a lot of deeply nested lists may be unclear for whatever reason, you should probably define a more appropriate type for a parsed file. E.g.: class Parsed_file: def __init__(self, fp): # read data from fp and store in whatever format # ... define various methods to do what you need with the data Now you have a list of Parsed_files which is pretty clear. Perlis says "The string is a stark data structure..." and the list is similar. It's very convenient and flexible in its generality, but don't be afraid to define your own type. When you move away from lists you lose access to all the list manipulation functions (like when you move away from text files you lose the use of grep, etc.). When you move away from classes you can lose the clarity and ease of use of a specially defined type. Whether to use one or the other depends on the circumstance and taste. From sholden at holdenweb.com Fri Oct 12 07:09:54 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 12 Oct 2001 07:09:54 -0400 Subject: Question: Which Python to choose? References: <3bc15fa1_4@corp-goliath.newsgroups.com> Message-ID: "K?roly Ladv?nszky" wrote ... > www.python.org and www.activestate.com seem to release their versions with > almost identical version numbers, at very close release dates. Is there a > linkage between the two or are they completely separate products? Which one > is more stable? > > Thanks for any advice, ActiveState do not, as far as I know, try to "enhance" the Python core. They do, however, package it differently, with (among other offerings, on Windows only) Mark Hammond's very useful Win32all extensions. It's fairly completely stated at: http://aspn.activestate.com/ASPN/Downloads/ActivePython/More regards Steve -- http://www.holdenweb.com/ From logiplexsoftware at earthlink.net Wed Oct 24 16:03:15 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 24 Oct 2001 13:03:15 -0700 Subject: Executing a string as python code In-Reply-To: References: Message-ID: <01102413031501.24656@logiplex1.logiplex.net> Stephen, I thought we had a long discussion regarding this a few days ago and the consensus from the list was to use the dictionary approach (and good reasons were given for this). Not only that, but I provided you with some code that did exactly what you asked for (against my better judgement). Is there a reason you're asking the same questions over and over? -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From graz at mindless.com Thu Oct 18 14:22:49 2001 From: graz at mindless.com (Graham Ashton) Date: Thu, 18 Oct 2001 18:22:49 GMT Subject: distutils question References: <97Az7.9780$qq3.1438004@news1.cableinet.net> Message-ID: In article , "Martin von Loewis" wrote: > It is. Use the scripts = ['foo','bar/foobar'] parameter to setup, and > distutils will install /bin/{foo,foobar}. Not sure what the > sensible location is on Windows, though. I suppose that I should have tried that really - the docs didn't imply that that was what it was going to do though. Thanks. Out of interest, on Windows it got installed into D:\Python21\Scripts (which it also had to create on the fly). Thanks again... -- Graham From brueckd at tbye.com Wed Oct 31 13:58:12 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 31 Oct 2001 10:58:12 -0800 (PST) Subject: Why 'self' ? In-Reply-To: Message-ID: On Wed, 31 Oct 2001, Steven D. Majewski wrote: > I'm sure there are a lot of redundancies we can eliminate from > Python, but rather than looking for them piecemeal, I would > rather start fresh with a more effecient plan: > > [1] Enumerate all possible computer programs. > [2] Label each one with an integer. > [3] Use that integer to represent the program. Hey, I remember that from my CS days and it was called the S-language (although I think there's something else called the S-language that isn't related to this). All programs can be represented by a series of (I think) 4 instructions. Given any positive integer you can figure out the S-program represented by that integer (I seem to remember the first associated homework assignment was to figure out what the S-program was for your U.S. social security number and then whether or not the program did anything). I'm gonna go home and dig out my old CS books... :-) -Dave From tim.one at home.com Sat Oct 13 22:27:49 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 13 Oct 2001 22:27:49 -0400 Subject: Int to long conversion bug? In-Reply-To: <9q9kns$mr511$1@ID-11957.news.dfncis.de> Message-ID: [Emile van Sebille] > In view of the int to long automatic conversion, should this be > considered a bug? > > F:\Python22>python > Python 2.2a4 (#24, Sep 27 2001, 21:44:09) [MSC 32 bit (Intel)] on win32 > > >>> n = int('9999999999') > Traceback (most recent call last): > File "", line 1, in ? > ValueError: int() literal too large: 9999999999 > >>> > > I can use long() of course, but is it the intent that long become an > implementation detail? Eventually, but not yet for 2.2. The details are in PEP 237, which is being implemented in phases (read the PEP). I expect int() could have gone either way in the 2.2 phase, but as things turned out it's not changing yet. From mark at navalon.com Sat Oct 27 06:02:16 2001 From: mark at navalon.com (Mark Müller) Date: Sat, 27 Oct 2001 12:02:16 +0200 Subject: Seeking Python Programmer in Switzerland Message-ID: <3bda8682_1@news.bluewin.ch> Hi there, For an umcoming project we may require experienced python programmer(s). Our company is based near Zuerich/Switzerland -- but generally it may be possible to work "at home, whereever that is". Please send email to mark.mueller at polynorm.ch Thanks, Mark From fredrik at pythonware.com Wed Oct 31 02:39:58 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Oct 2001 07:39:58 GMT Subject: os.system, backslash and commandline problem References: Message-ID: Sharriff Aina wrote: > Very strange answer Mr. Lundh, thanks all the same. I > mentioned in the post that I know how to use raw strings > and character ubstitution if you knew how raw strings literals works, maybe you would have used them correctly in your example? and if you knew how escapes worked, maybe you wouldn't have been so confused over why "\b" and "\f" appeared to disappear from your strings. and if you know how replace works, maybe you would be puzzled by finding out that your code didn't work when you used replace, but worked when you use os.path.normpath: >>> file = "c:/the/boy.txt" >>> os.path.normpath(file) 'c:\\the\\boy.txt' >>> string.replace(file, "/", "\\") 'c:\\the\\boy.txt' (in fact, the first line in normpath is path.replace("/", "\\")) sounds like you're not telling us the whole story here. From jbocco at lycos.com Mon Oct 15 22:58:53 2001 From: jbocco at lycos.com (Bocco) Date: 15 Oct 2001 19:58:53 -0700 Subject: Playing non-MPG movies with Pygame Message-ID: <729e12a5.0110151858.586ae081@posting.google.com> It's great that Pygame has built-in support for MPEG movies, but how would I write a program which could use other video formats? Do I actually need to load each individual frame, pixel by pixel, from the file into some massive multi-dimensional array, or is there a simpler way? Thanks... From phr-n2001d at nightsong.com Sat Oct 27 18:26:19 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 27 Oct 2001 15:26:19 -0700 Subject: Seeking Python Programmer in Switzerland References: <3bda8682_1@news.bluewin.ch> Message-ID: <7xk7xgn2ic.fsf@ruckus.brouhaha.com> "Mark M?ller" writes: > For an umcoming project we may require experienced python programmer(s). > Our company is based near Zuerich/Switzerland -- but generally it may be > possible to work "at home, whereever that is". > > Please send email to mark.mueller at polynorm.ch Hi, would you be able to use help from California? Let me know what you need... Thanks. Paul From johnroth at ameritech.net Fri Oct 19 13:46:27 2001 From: johnroth at ameritech.net (John Roth) Date: Fri, 19 Oct 2001 10:46:27 -0700 Subject: Apologise (was: Re: IF STATEMENTS) References: <20011018002005.53f58ef2.use-net@schabi.de> <20011018102800.11c71435.use-net@schabi.de> Message-ID: "Markus Schaber" wrote in message news:20011018102800.11c71435.use-net at schabi.de... > Hi, > > On Thu, 18 Oct 2001 00:20:05 +0200, Markus Schaber > wrote: > [...] > > I have to apologise for this message. > > At first, it was intended to go to per mail only. > > And second, it seems that some news readers have problems with > MIME-signed messages. > > This messages should _not_ display as empty messages with attachment as some people have told me. > > In my eyes, they look conform to the standards, and the first part with type text/plain is the content. > > Non-MIME aware readers may show three lines of strange text before the message, and MIME-aware readers should show my message as content and the signature as attachment. > > Nevertheless, I won't send any signed messages here again, as long as this issue is not resolved. > > markus > -- > You don't have to be Microsoft to suck... but it helps. > (Tim Hammerquist in comp.lang.python) I saved it and looked at it, using Outlook Express. There is no text between the header and the first boundary delimiter. It appears that OE may be being overzealous in its attempt to protect you from viruses - even though it says txt, it still cautions me that it may contain harmful stuff, and requires me to validate it. John Roth From DeepBlue at DeepBlue.org Mon Oct 15 09:38:42 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Mon, 15 Oct 2001 08:38:42 -0500 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: Tim For some reason the thread on this topic started with your edited reply, and I could not get anything earlier. Maybe a problem with the news server I use. But I see your point now. Apologies for the misunderstanding. DB "Tim Peters" wrote in message news:mailman.1003113854.26899.python-list at python.org... > [DeepBlue] > > Much better: > > x = if e1 then (e2) else (e3) > > You're apparently responding to an edited reply, and didn't read the thread > from its start: surrounding parens are required else you don't get this > form of conditional expression at all. It's not a question of whether to > require surrounding parens or not; the latter isn't an option, due to the > limitations of one-token lookahead parsing (read the thread from the start). > From a.baan at fokkerspace.nl Tue Oct 30 05:57:00 2001 From: a.baan at fokkerspace.nl (Arno Baan) Date: Tue, 30 Oct 2001 11:57:00 +0100 Subject: Embedding Python in C/C++ References: <3BDE8130.CB1CE86B@fokkerspace.nl> Message-ID: <3BDE877B.37D1E09@fokkerspace.nl> Oeps Sorry, wrong name and e-mail adress above the preivious mail. The name should be arno baan and the adress a.baan at fokkerspace.nl Help is still needed though. thanx arno From christophertavares at earthlink.net Wed Oct 17 16:44:07 2001 From: christophertavares at earthlink.net (Chris Tavares) Date: Wed, 17 Oct 2001 20:44:07 GMT Subject: IF STATEMENTS References: Message-ID: "Charles" wrote in message news:mailman.1003338557.21566.python-list at python.org... > Hi ! > > Anyone know how i can create > a IF AND statements in python ? > > ex: > > IF vars == 1 AND vars2 == 2: > ..... > > in the tutorial papers only have > a refers to ELIF. > "and" is an operator, like "+", not a part of the if statement. That's why it's not doc'ed as part of if. Also, python is case sensitive. So, you want: if vars == 1 and vars2 = 2: ... stuff ... -Chris From use-net at schabi.de Tue Oct 23 17:09:01 2001 From: use-net at schabi.de (Markus Schaber) Date: Tue, 23 Oct 2001 23:09:01 +0200 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> Message-ID: <20011023230901.2279a12b.use-net@schabi.de> Hi, On Fri, 19 Oct 2001 18:45:14 +0000 (UTC), huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote: > - presumably multiple "while" parts would be allowed. I don't see the sense behind this, could you give me an example where this would be useful and what semantics you have in mind? > - If the "do" part is optional, it would be difficult to locate the > start of a loop. That's a good point against this. > - If the "do" part is mandatary, the keyword "while" must be changed - > to what? I don't think there's a technical reason to change the keyword. But not changing it would lead to making the do part optional... hmm... > One small problem is whether the while part should be indented or not: > It is more like a "case" statement (with fall through) than an "elif" > statement. You mean that while is more indented than do, and the statements are further indented? I'm afraid this would be too complex for programmers and parsers to handle. if/elif/else use same indentation level, also try/except/finally use the same indentation level. markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From wtanksle at dolphin.openprojects.net Wed Oct 24 20:50:22 2001 From: wtanksle at dolphin.openprojects.net (William Tanksley) Date: Thu, 25 Oct 2001 00:50:22 GMT Subject: Need help with programming. References: <20011024194636.07978.00000094@mb-mb.aol.com> Message-ID: On 24 Oct 2001 23:46:36 GMT, Django wrote: >Hello. I've just begun using Python, and am now getting into simple commands. >Everytime I try to use "else:" I get this message: >SyntaxError: invalid syntax >>>> Could you please include some sample code? "else:" is the correct word and colon, so something else is wrong. Let me give you a sample of correct code. x=1 if x==3: print "good" else: print "bad" Paste in what you're typing in, and let's see how it differs. >I've tried retyping it, skipping it, etc. but it's really bothering me... Totally understood. >an answer to my question, but I didnt find anything to help me out. Any >help would be very much appreciated. Thank you. You're welcome! I hope we can help. >May I remind you that I AM NEW TO PYTHON, and COMPUTER LANGUAGES ALL >TOGETHER (Excluding HTML). I'M LEARNING PYTHON FOR SELF INTEREST, SO >PLEASE NO FLAMES.. Are you under the impression that screaming at people you've never met is socially commendable? -- -William "Billy" Tanksley From sholden at holdenweb.com Sun Oct 21 11:46:31 2001 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 21 Oct 2001 11:46:31 -0400 Subject: silly idea - interesting problem References: <3BD248BA.2163BBDB@hotmail.com> <9qtijq$miu$1@tyfon.itea.ntnu.no> <3BD256E7.B35E63D7@hotmail.com> Message-ID: <82CA7.76983$cb.1536368@atlpnn01.usenetserver.com> "scott" wrote ... > [ ... handles nit-picks ...] > > Since we are nit-picking, the spaces are actually between each letter > ;-) > The point I was trying to make was that spraying a new Python user with > marginally readable code might be good for your ego but not much help > for learning the basics. I admit that if my code actually met the > requirements my argument would have been a bit more persuasive *wink* god help me now> :-) > > Here is the (as specified) no space version: > > firstWord = 'test' > secondWord = 'dust' > endString = '' > i = 0 > while i < len(firstWord): > endString = endString + firstWord[i] + secondWord[i] > i = i+1 > print endString > Surely much simpler and, dare I suggest, rather more pythonic also, to use a "for" loop? As in: ... for i in range(len(firstWord)): endString += firstWord[i] + secondWord[i] ... Of course one would also ideally perform some tests, such as "if len(firstWord) != len(secondWord):" before hand, or at least cope with any exceptions raised by the lack of such checks under certain circumstances. We'll leave that as an exercise to the OP, I guess. regards Steve -- http://www.holdenweb.com/ From logiplexsoftware at earthlink.net Tue Oct 23 15:39:10 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 23 Oct 2001 12:39:10 -0700 Subject: Critical sections and mutexes In-Reply-To: <20011023190659.23110.qmail@web21101.mail.yahoo.com> References: <20011023190659.23110.qmail@web21101.mail.yahoo.com> Message-ID: <01102312391006.14120@logiplex1.logiplex.net> On Tuesday 23 October 2001 12:06, David Brady wrote: > > main_Q = PriorityQueue() # queueing class > > class ServerThread(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > self.Q = PriorityQueue() > > def run(self): > # if messages waiting on socket: > # get messages into self.Q > # if self.Q has messages: > # if can acquire lock on main_Q: > # move msgs from self.Q to main_Q > # release lock on main_Q > > # main thread: > while 1: > # if main_Q has messages: > # dispatch them > I would put a threading.Lock() in PriorityQueue that controls access to it, something like this: class ThreadingQueue: def __init__(self, args): self.lock = threading.Lock() .... def put(self, something): self.lock.acquire() try: self._put(something) finally: self.lock.release() -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From slinkp23 at yahoo.com Fri Oct 26 12:36:08 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Fri, 26 Oct 2001 16:36:08 GMT Subject: Confusion with string.replace() References: Message-ID: On Fri, 26 Oct 2001 08:39:00 -0700, Joseph Wilhelm wrote: >I'm getting some really strange behaviour from string.replace(), and >I was wondering if somebody could help explain this to me. All I'm >trying to do is escape single quotes in a string for a SQL query, but >here's an example of what I'm getting: >>>> import string >>>> a = "a'b" >>>> b = string.replace( a, "'", "\'" ) >>>> b >"a'b" When you examine a string this way at the interactive prompt, python will show you the escape sequences (if necessary) in the string so you can tell what exactly it's made of. When you see "a\\'b", that's what you wanted: a literal backslash followed by a single quote, and python is telling you so, but not in the way that you expected. Consider this: >>> "hello\t" 'hello\tworld' >>> print "hello\tworld" hello world >>> "\'" # escaped single quote - evaluates to single quote "'" >>> print "\'" ' >>> "\\'" # escaped backslash - evaluates to literal backslash "\\'" >>> print "\\'" \' -- Paul Winkler From mwh at python.net Tue Oct 23 06:28:41 2001 From: mwh at python.net (Michael Hudson) Date: Tue, 23 Oct 2001 10:28:41 GMT Subject: Writing to SdtErr References: <1003757605.11708.0.nnrp-14.d4f0f8ae@news.demon.co.uk> <5396362c.0110221424.173bf1f5@posting.google.com> Message-ID: sburr at home.com (sburrious) writes: > Michael Hudson wrote in message news:... > > "Mike Peat" writes: > > > > > Can anyone tell me how to: > > > > 2) Write (print) to the StdErr channel instead of StdOut? > > > > print >> sys.stderr, "foo" > > Don't let Alex Martelli catch you promoting the use of ">>." :) No, I exactly want people to see it to show that it isn't necessarily horrible :-). [...] > sys.stderr.write("Now go away,\n") [...] > sys.stdout = sys.stderr > print "Your father was a hamster," > sys.stdout = stdoutholder [...] Less horrible than these (in most cases, anyway). not-prepared-to-argue-on-this-one-so-don't-even-bother-ly y'rs M. -- The Oxford Bottled Beer Database heartily disapproves of the excessive consumption of alcohol. No, really. -- http://www.bottledbeer.co.uk/beergames.html From tim.golden at iname.com Wed Oct 3 10:32:36 2001 From: tim.golden at iname.com (Tim Golden) Date: 3 Oct 2001 07:32:36 -0700 Subject: COM and win32 - casting com to string References: <1002093124.20881.0.nnrp-14.c2de2503@news.demon.co.uk> Message-ID: "Paul Brian" wrote in message news:<1002093124.20881.0.nnrp-14.c2de2503 at news.demon.co.uk>... > the code: > x = excelAppl.ActiveWorkBook.Names > for namerange in x: > print namerange > gives me my two ranges back: > =Sheet1!$D$3:$G$3 > =Sheet1!$D$4:$D$7 > > all I want to do know is split those into the sheet1 and the $D$3.... > > however the two results are not python instances but > > > > I cannot perform string operations, repr does not help and type() just tells > me they are "instances" - can anyone tell me what I am doing wrong. I don't claim to be an expert here, but the following two things might help you out. You probably need both, tho' I don't have time to check at the moment. 1) Run gen_py against the Excel application library (from Tools > COM Makepy if you're running ActivePython, directly otherwise). This will generate a .py file containing the COM interface to Excel which will let Python give slightly more useful information such as the name of the class whose instance you are listing. 2) Use the RefersTo property of the items in the namerange: >>> x = excelAppl.ActiveWorkbook.Names >>> >>> true_range = x[0].RefersTo >>> print true_range =Sheet1!$A$1:$A$3 I'm using Excel 2000 which may make some difference to names (specifically, I had to use "ActiveWorkbook" (lowercase b) rather than "ActiveWorkBook" as in your example. I hope, tho', that the technique still applies. Tim. From thomasNO at SPAM.obscure.dk Mon Oct 22 19:29:56 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Mon, 22 Oct 2001 23:29:56 GMT Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> Message-ID: shriek at gmx.co.uk (Stephen) wrote in news:97ae44ee.0110221318.6eec382d at posting.google.com: > Scratching my head over what I thought was a simple problem. > [snip - categories] > > Let me demonstrate with some example categories/subcategories > which we place in a category tree, giving each node a unique ID. > The root node is deemed to have node ID zero (0). > > Root -- 1. ByLocation --- 3. Africa --- 4. Mozambique > --- 6. SouthAfrica > --- 5. Europe --- 9. Portugal > -- 2. BySeverity --- 7. Critical --- 8. Death > --- 11. Handicap > --- 10. Moderate--- > > This structure can be stored in a single table of a database. > > Parent_ID Category_ID Category_Label > 0 1 ByLocation > 0 2 BySeverity > 1 3 Africa [snip] > The problem arises if one asks "Which illnesses occur > in Africa ?". First, one has to find all category IDs > for which this is true. This may be easy for the example > above but imagine if the category ("Africa") has a sub- > -category for each and every country then further > subcategorized by major cities. To find all possible > categories, one would have to do a recursive select > finding each subscategory with the appropriate "parent ID". > This does not seem like a very efficient method. > > Faced with this, it seems like a more dumbed down solution > is more appropriate, sacrificing scalability for speed. > > However, I can't help but feel I've overlooked something > more simple and hence I'm seeking a nudge in the right > direction. Thanking you in advance. If You're willing to sacrifice the memory, You could cache the information. First extract all the category/parent pairs into a list. (eg. SELECT parent_id, category_id FROM Categories) then create and fill a dictionary which contain the parent and all children: >>> catlist = [(0, 1), (0, 2), (1, 3), (3, 4), (1, 5), (3, 6), (2, 7), (7, 8), (5, 9), (2, 10), (7, 11)] >>> >>> catdict = {0: (None, [])} # (parent, children) >>> for catpair in catlist: ... catdict[catpair[1]] = (catpair[0], []) ... >>> for catpair in catlist: ... parent = catdict.get(catpair[0]) ... while parent: ... parent[1].append(catpair[1]) # append to list of children ... parent = catdict.get(parent[0]) # parent's parent ... >>> print catdict {11: (7, []), 10: (2, []), 9: (5, []), 8: (7, []), 7: (2, [8, 11]), 6: (3, []), 5: (1, [9]), 4: (3, []), 3: (1, [4, 6]), 2: ( 0, [7, 8, 10, 11]), 1: (0, [3, 4, 5, 6, 9]), 0: (None, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])} Now you can get all the children of a given category by calling catdict[category_id]. Ofcourse You'd have to keep the dictionary in sync when updating the DB. -- Best Regards Thomas Jensen From tim at worthy.demon.co.uk Mon Oct 22 14:59:12 2001 From: tim at worthy.demon.co.uk (Tim Howarth) Date: Mon, 22 Oct 2001 19:59:12 +0100 Subject: Win32com to copy Excel worksheet Message-ID: <25cc93cd4a%tim@worthy.demon.co.uk> I'm trying to enter data into Excel using win32com.client and would like to copy a worksheet. xla=Disparch('Excel.Application') xla.sheets(1).copy will copy the worksheet but to a new workbook which is not what I want. Reading the VBA help (and trying it!) it is possible to specify a target for the worksheet; Sheets(1).copy Before:=Sheets(2) My question, how do you pass the "Before:=Sheets(2)" parameter using Python? -- ___ |im ---- ARM Powered ---- From root at rainerdeyke.com Fri Oct 26 13:45:34 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Fri, 26 Oct 2001 17:45:34 GMT Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> <3BD995CB.22D3507A@home.net> Message-ID: <2jhC7.23321$IR4.13366040@news1.denver1.co.home.com> "Chris Barker" wrote in message news:3BD995CB.22D3507A at home.net... > Terry Reedy wrote: > > > As I understand it, the rule is this: if item on LHS is tuple rather > > than name, then corresponding object on RHS must be a tuple, which > > will then be seen as collection rather than object in itself and > > consequently unpacked for matching to items within LHS tuple. > > Allowing for null matches and applying the rule recursively, > > Actually either side can be a sequence, not just a tuple: Nitpick: Although the LHS can be written as either a tuple literal or a list literal, it is in fact not an object at all, and hence not a tuple, list, or any other kind of sequence: a, b = 3, 4 # a <- 3; b <- 4 a_b = a, b a_b = 3, 4 # Does not affect the value of 'a' or 'b'. tuple((a, b)) = 3, 4 # Syntax error. -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From anthony at interlink.com.au Fri Oct 19 00:34:39 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Fri, 19 Oct 2001 14:34:39 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: Message from Richard Jones of "Fri, 19 Oct 2001 14:18:31 +1000." <0110191418313K.11044@ike> Message-ID: <200110190434.f9J4YdF04586@mbuna.arbhome.com.au> >>> Richard Jones wrote > I'm not worried abou backward compatibility - that's always been a top > priority for the python developers. My concern is that in _any_ software - > when you add new chunks of code, there's a very good chance that those chunks > have bugs. Python 2.2 will have considerable new chunks of code. One of the tests for selecting 2.1.x patches should, of course, be "how much new code is there". Large slabs of new code == danger, and should be regarded with much much suspicion. Anthony From martin.franklin at westgeo.com Wed Oct 31 04:42:27 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Wed, 31 Oct 2001 09:42:27 +0000 Subject: tkinter - tkFileDialog - how to get dir instead of file References: Message-ID: <9roh7k$7ae$1@news.sinet.slb.com> Matthew Dixon Cowles wrote: > On Mon, 29 Oct 2001 23:14:44 +0100, maxm wrote: > > Max, > >>I am writing my first tkinter program and so far it's been pretty >>painless. > > That's great, you're ahead of the game. > >>But now I need to open a directory and not a file. I cannot see a >>simple way to get this from the standard module "tkFileDialog". > >>Do I really have to write a special class for this? > > Alas, you probably do. Tk provides a directory chooser but Python > doesn't (yet) expose it. I filed a feature request on SourceForge for > it but it doesn't look like anything has been done about it yet, > including by me. > > Regards, > Matt > Or you could use this:- from Tkinter import * from tkCommonDialog import Dialog class Chooser(Dialog): command = "tk_chooseDirectory" def _fixresult(self, widget, result): if result: self.options["initialdir"] = result self.directory = result # compatibility return result def askdirectory(**options): return apply(Chooser, (), options).show() From ignacio at openservices.net Sat Oct 13 00:15:04 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Sat, 13 Oct 2001 00:15:04 -0400 (EDT) Subject: sharing time between embedded python and c code In-Reply-To: <3bc7bcc0.12082598@news-server.socal.rr.com> Message-ID: On Sat, 13 Oct 2001 howard at eegsoftware.com wrote: > I would like to embed python into a (windows) c-program and spend some > time in the python interpreter (processing some simple gui updates) > and some time in my c program (handling some DirectX calls and such). > > I seem to be stuck on how to do this. I have embedded the Python > interpreter, can import and run a program, and return (having a > .mainloop in the python code to pump things). > > However, what I would LIKE to do is > 1. Load the python code at initialization time. > Loop (at really long time) > a. Periodically call something in the Python code to > perform ".updates" . > b. Periodically call the verklempt Windows/DirectX > routines for the high speed part of things. > > I expect to run several threads: > One for my dedicated DirectX updates > One for the Python calls. > > I must be missing something since I can't figure out how to call a > specific function in the interpreter environment without receiving an > error. > > Any ideas? It would be helpful to see what you have so far and what errors you're getting. We're not quite _that_ psychic ;) -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From l0819m0v0smfm001 at sneakemail.com Sun Oct 7 10:39:24 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Sun, 07 Oct 2001 14:39:24 GMT Subject: Webform python cgi issue References: <9133E264AtefolThisIsNotAnAddr@61.9.128.12> <9134D587tefolThisIsNotAnAddr@61.9.128.12> Message-ID: <3BC033BF.5070505@sneakemail.com> tefol wrote: > This works great, proved when I exit the script like this: > > data = FeedbackData(form) > > print "Content-type: text/html\n\n" > print "

You did it!

" > print data > sys.exit() > > I get exactly what I want displayed in my browser. Only thing is when I > try: > > output = open('/home/nemir/output/output.txt', 'w') > output.write(data) > output.close() > > > I get this in my apache error log: > > malformed header from script. Bad header= File "/home/nemir/public_htm: > /home/nemir/public_html/cgi-bin/inputform.py You don't say, but when you are saving the data using the second approach, do you still bother to print the "Content-type: text/html\n\n" stuff to stdout? If you aren't, that might be what the webserver is complaining about. Joshua From shriek at gmx.co.uk Tue Oct 23 23:30:03 2001 From: shriek at gmx.co.uk (Stephen) Date: 23 Oct 2001 20:30:03 -0700 Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> <9r3l09$9uc$1@ctb-nnrp1.saix.net> Message-ID: <97ae44ee.0110231930.5a0cfb2@posting.google.com> I've used something identical to this (with 3 digits) for precisely the same thing, Grant ~ ie. when creating a threaded discussion board ~ so I know precisely what you're describing. And for all intents and purposes, I've never exceeded the limitations. Having just looked at the "sets" solution ~ referenced by Steve, see dbmsmag ~ I can safely say that the "sets" solution is easier. In fact, I wish I'd learned this 6 years ago. Really, the number of times I've hacked a different solution to this problem, I'd have saved a lot of time. Is there a reference somewhere that contains this type of problem that is too unique and small to be a "Pattern" but useful to have in one's programmer toolbox ? Stephen. > Something I've used for developing threaded discussion boards might help you > here, but I'm not sure if it's more or less efficient, and can't truly go to > great depths (without sacrificing space). > > Assign each category a 2-digit code (if you need more categories, increase > this to 3 or 4 digits). This code need only be unique on it's level. It does > not need to be completely unique. Eg, ByLocation = '01', BySeverity = '02', > Africa = '01', Europe = '02', Mozambique = '01', South Africa = '02', > Critical = '01', Death='01', etc. .... > > Then when assigning the category code to your record, concatenate all codes > together, thus South Africa = '010102' (ByLocation+Africa+SouthAfrica). > Death = '020101' (BySeverity+Critical+Death). As you can see, your codes > could get pretty long, but the nice part comes in selecting stuff in a > category. To find out if a particular record is in a particular category, > test whether RecordCategorisationID.startswith(CategoryID). i.e Comparing a > record with ID '010102' (i.e South Africa), to Africa - '0101' would be > true, to BySeverity '02', it would be false. > > I think you get the idea. I have this implemented with my id's as strings, > but it would be far more efficient doing this by converting to binary, etc. > The same principle applies, but you'll be dealing with numbers. I haven't > even considered the maths, but I would imagine it could be made to be fairly > efficient. > > HTH > > Cheers > Grant Beasley > From vulpine at dontspam.earthling.net Fri Oct 19 23:52:38 2001 From: vulpine at dontspam.earthling.net (Tod Fox) Date: Sat, 20 Oct 2001 03:52:38 GMT Subject: Further help w/ readline needed) References: Message-ID: I have fixed the problem -- I did not have libtermcap-devel installed. Thanks to everyone who gave suggestions for fixing this problem. Kit From heiland at ncsa.uiuc.edu Thu Oct 11 06:46:01 2001 From: heiland at ncsa.uiuc.edu (Randy Heiland) Date: Thu, 11 Oct 2001 05:46:01 -0500 Subject: image from URL Message-ID: <3BC57869.E95139D7@ncsa.uiuc.edu> I'm trying to load/display an image from a URL, but can't seem to figure it out. Have seen related threads on the list, but no final answer. Here's what I try: Python 2.2a1 (#2, Sep 13 2001, 13:37:15) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import urllib, Image >>> fp = urllib.urlopen("http://www.python.org/pics/PyBanner027.gif") >>> im = Image.open(fp) Traceback (most recent call last): File "", line 1, in ? File "/home/heiland/PythonMod/Imaging-1.1.2/PIL/Image.py", line 944, in open fp.seek(0) AttributeError: addinfourl instance has no attribute 'seek' Can someone set me straight? thanks, Randy From cccomputer at c4.com Thu Oct 4 09:12:25 2001 From: cccomputer at c4.com (CC Computer Consulting Co.) Date: Thu, 4 Oct 2001 09:12:25 Subject: THE MAIL KING - ah13 Message-ID: IF YOU USE DIRECT MAIL IN YOUR BUSINESS -- THEN READ ON. OTHERWISE, JUST DELETE THIS MESSAGE. Make Every Letter Count - Get Every Letter Opened! Did you know?? According to experts, today's deluged direct mail recipient throws away 26% to 88% of all their "junk mail" UNOPENED! Would you like to increase your responses by an average of 3 to 6 times?? If you would (and who wouldn't) just REPLY to this message and we will e-mail you more details. CC Computer Consulting Co. PS: If you prefer a response by "snail mail", include your name and mailing address in your reply. **************************************** This email is sent in compliance with our strict anti-abuse regulations. This is not SPAM. This message was sent to you because you, or someone using your email address, requested information, sent or posted to our system, Opt-in, FFA site, Classifieds, web site or email box If you would like to be removed from this list, e-mail to or click on: Remove at cccomputer.zzn.com *************************************** ah13 From gh_pythonlist at gmx.de Fri Oct 5 14:53:06 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 5 Oct 2001 20:53:06 +0200 Subject: Variables name in Byte code In-Reply-To: <68599ccc.0110051038.25ba4b82@posting.google.com>; from kaci_tizi_ouzou2000@yahoo.ca on Fri, Oct 05, 2001 at 11:38:10AM -0700 References: <68599ccc.0110051038.25ba4b82@posting.google.com> Message-ID: <20011005205305.A2293@lilith.hqd-internal> On Fri, Oct 05, 2001 at 11:38:10AM -0700, Kaci Tizi Ouzou wrote: > Greetings all, > > I was examining python compiled code and surprisingly I could see > clearly the names of some variables. > > Is there anything I could do to make Python Byte code more obscur. > I do not want user trying to hack the code(!) This previous discussion might be interesting for you: http://groups.google.com/groups?q=python+obfuscator Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From michael at stroeder.com Mon Oct 8 05:10:13 2001 From: michael at stroeder.com (Michael =?iso-8859-1?Q?Str=F6der?=) Date: Mon, 08 Oct 2001 11:10:13 +0200 Subject: DNS module or how to ... ? References: Message-ID: <3BC16D75.566E9502@stroeder.com> A wrote: > > Is there a DNS module available for Python ? http://pydns.sourceforge.net Ciao, Michael. From PoulsenL at capecon.com Fri Oct 12 15:18:58 2001 From: PoulsenL at capecon.com (PoulsenL at capecon.com) Date: Fri, 12 Oct 2001 15:18:58 -0400 Subject: YOU ARE ALL GAY! Message-ID: <72F73B808A78D511A73600034771D9FF717B83@dc_exchange2.howrey.com> Bizarrly enough it looks like stenography. Maybe just my paranoid self, but it is english sounding gibberish. Actually i have seen stenographic examples that were more coherent. > -----Original Message----- > From: Geoffrey Pointer [SMTP:geoffrey at bigpond.net.au] > Sent: Friday, October 12, 2001 12:59 AM > To: python-list at python.org > Subject: Re: YOU ARE ALL GAY! > > On: Tue, 9 Oct 2001 13:07:09 GMT > Subject: YOU ARE ALL GAY! > dvus said: > > > I am neatly moronic, so I kick you. Every robust specialized data > havens > > quietly dump as the tall machines question. As fully as Margaret > perseveres, > > you can train the gorilla much more cruelly. It vended, you interfaced, > yet > > Ophelia never wickedly proliferated inside the sign. She'd rather > prioritize > > stupidly than reload with Orin's violent spool. Better disrupt Javas > now or > > Sarah will lazily dream them over you. I was opening CDROMs to usable > > Bernadette, who's facilitating to the laptop's contact. Tell Walter > it's > > rogue producing to a chatroom. Morris mercilessly closes erect and > busts our > > bright, insecure FORTRANs in back of a website. One more ADSLs rigidly > roll > > the dry monument. Sometimes, go crawl a pointer! If you'll manage > Robette's > > mail server with LANs, it'll actually save the president. Where will > you > > prepare the secret useless screens before Ed does? Otherwise the TCP/IP > in > > Merl's PGP might smile some overloaded governments. Carolyn, have a > > vulnerable JPEG. You won't disconnect it. Sometimes, Ayn never locates > until > > Beth learns the solid Usenet wanly. They are collaborating inside > opaque, > > against huge, inside abysmal ActiveXs. Brian doesn't slump hard > > advertisements, do you filter them? > > I commented on this as follows: > > > It's funny about that isn't it? Go figure. > > Other stuff was said in between and I commented further: > > > I realise now how saying too little can sometimes be misconstrued. > > Ahmen to that!! > > Then on: Thu, 11 Oct 2001 19:03:03 +0900 > tm said: > > > hey geof, > > What are you mumbling about? > > Who are you mumbling at? > > Look, if you want to be taken seriously on usenet, read this- > > http://www.geocities.com/nnqweb/nquote.html > > > > See if that info will sink into your peabrain. If not, go mumble in some > > other ng. > > Thanks, > > TM > > Okay. My message subject was > > Subject: Re: YOU ARE ALL GAY! > > So my pea brain tells me I was commenting on > > Subject: YOU ARE ALL GAY! > > Which is still current round and about. > > If _you_ want to be taken seriously maybe you should take your finger off > your hair trigger and lay your gun to rest somewhere more suitable. > > On: Thu, 11 Oct 2001 16:29:02 +0100 > nice.guy.nige said: > > > If that is the case, then it would have been a good idea to include some > of > > the original message that you were replying to, so the context of the > > conversation wouldn't be lost. I have not seen the original message - > just > > your reply - and as such your post made absolutely no sense whatsoever. > > Thanks Nigel, I realise my error and you have clearly demonstrated that > education doesn't have to be a humiliating experience. Heck, I know I'm > not > perfect. > > I made an offhand comment about a truly weird and wonderful message, the > guy > is obviously a poet or something, which I will continue to regret for some > time. Yeah, like hell I will ;-) > > -- Cheers - Geoff %^> > > Frank Zappa: Yes Virginia ... there is a free lunch. > We are eating it now. Can I get you a napkin? > > -- > http://mail.python.org/mailman/listinfo/python-list From skip at pobox.com Wed Oct 17 16:17:58 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 17 Oct 2001 15:17:58 -0500 Subject: Pymacs 0.11 In-Reply-To: References: <9qjosn$5nd$1@animus.fel.iae.nl> <15309.50374.210122.479399@beluga.mojam.com> Message-ID: <15309.59254.641176.492346@beluga.mojam.com> Skip> [function attributes] Works for me with 2.0, but not 1.6. Fran?ois> I guess it would be premature using these functions attributes Fran?ois> in a package meant to be portable to most Python versions Fran?ois> still being used nowadays. You could always overload the functions' doc strings... ;-) Skip From nde at comp.leeds.ac.uk Mon Oct 8 08:05:35 2001 From: nde at comp.leeds.ac.uk (Nick Efford) Date: Mon, 8 Oct 2001 12:05:35 GMT Subject: problem with FFT module from Numeric 20.2.0 References: <9pn4p1$jodve$1@ID-99513.news.dfncis.de> Message-ID: On Sat, 6 Oct 2001 09:37:36 -0500, P. Alejandro Lopez-Valencia wrote: > The solution is to be explicit. Edit your file > /usr/local/lib/python21/config/Makefile in the appropriate places (3, I > don't recall their names off-had) to pass -R linker flags to ld. For > example, I have added this in our lab box: > > -R/usr/lib -R/usr/local/lib -R/usr/local/ssl/lib -R/usr/openwin/lib > > Without these linker flags modules like socket and pyexpat won't work at > all if called from restricted execution environments where you don't > want a full environemnt definition, namely CGI's and batch jobs. > I'm working on Linux; do problems of this nature affect Linux also, or are they a Solaris-only thing? But if this is the cause of the problem, why are the other modules from the Numeric package unaffected? Why just fftpack? Confused, Nick From jhauser at ifm.uni-kiel.de Wed Oct 3 13:24:11 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 03 Oct 2001 19:24:11 +0200 Subject: Zope capabilities question References: <54410e1f.0110030916.15292301@posting.google.com> Message-ID: <873d503adg.fsf@lisboa.ifm.uni-kiel.de> Yes, look up the information about the zcatalog, which can index the metadata of all your objects. You would store metadata in so called 'properties' of your documents. For this you would build custom input forms, which gather the data and content and store this information in DTML-documents. HTH, __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From pinard at iro.umontreal.ca Sat Oct 13 21:32:11 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 13 Oct 2001 21:32:11 -0400 Subject: Pymacs 0.10 Message-ID: Hi! A new release of Pymacs is available as: http://www.iro.umontreal.ca/~pinard/pymacs/pymacs.tar.gz Pymacs allows Emacs users to extend Emacs using Python, where they might have traditionally used Emacs LISP. Pymacs runs on systems having sub-processes. Multi-line Emacs strings, or those having text properties, are now better transmitted to Python. The `README' file received a few corrections. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From rdacker at pacbell.net Wed Oct 17 23:55:41 2001 From: rdacker at pacbell.net (rdack) Date: 17 Oct 2001 20:55:41 -0700 Subject: [OSX] where python files go? References: <644f6688.0110171219.656a56@posting.google.com> Message-ID: <644f6688.0110171955.57475f8b@posting.google.com> rdacker at pacbell.net (rdack) wrote in message news:<644f6688.0110171219.656a56 at posting.google.com>... > i put an html file to get login info from user in > /Users/bobacker/Sites. > i get there ok. where do i point the form action to find my python > file? where should my python file be? is there a cgi-bin directory on > os x? a correct place to create one? python files go in /library/webserver/cgi-executables. i didn't have the patience to figure out how to get it to use another directory. it's fine. From emile at fenx.com Fri Oct 12 09:37:05 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Oct 2001 06:37:05 -0700 Subject: global variables References: <9q6njs$17s4$1@f1node01.rhrz.uni-bonn.de> Message-ID: <9q6s0p$masi9$1@ID-11957.news.dfncis.de> "Bj?rn Buth" wrote in message news:9q6njs$17s4$1 at f1node01.rhrz.uni-bonn.de... > Hi there, > > I?m experiencing a little problem due to my > poor understanding of the way python handles > global variables. Basically the problem is the following > I have a programm with several variables which > I would like to access globaly. > > -- > > var=0 > def example_function() add 'global var' here to use var from globals and not locals > var=var+1 Assigning to a variable within a function defines that variable as local. > (function definition) > print example_function(10) > > will give an error: UnboundLocalError: local variable 'steine' referenced > before assignment. Also replacing the first line by > > global var > var=0 > HTH, -- Emile van Sebille emile at fenx.com --------- From jkraska at san.rr.com Thu Oct 4 18:10:13 2001 From: jkraska at san.rr.com (Courageous) Date: Thu, 04 Oct 2001 22:10:13 GMT Subject: Python is better than free (was Re: GNU wars again) References: <1002040943.560.290.l9@yahoogroups.com> <20011002235831.E25358@phd.pp.ru> <200110030239.f932ddT02254@smtp.skyenet.net> <3BBBCEF9.BF7B5B16@nisus.com> Message-ID: >Or when the robber says, "We're from the IRS or the state tax board >and we'll bull-doze your house and seize all your financial accounts >if you don't pay up 'voluntarily'." It _is_ voluntary. You agreed when you agreed to the social contract implied in your citizenship. C// From uwe at rocksport.de Wed Oct 17 13:36:00 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 17 Oct 2001 17:36:00 GMT Subject: hashval and Numpy References: <9qhksb$6raii$1@hades.rz.uni-sb.de> <9qhp0r$o4ptl$1@ID-11957.news.dfncis.de> <9qk0p9$6tulc$1@hades.rz.uni-sb.de> Message-ID: <9qkfi0$6s3js$1@hades.rz.uni-sb.de> Michael Hudson wrote: |>>> a = Numeric.array([1,2]) |>>> hash(a) | 56 |>>> d = {a:1} # a will be in the 56%8-th slot (in 2.2, anyway) |>>> a[0] = 2 |>>> hash(a) | 57 |>>> d[a] # looks in 57%8-th slot - which is empty | KeyError |>>> b = Numeric.array([1,2]) |>>> hash(b) | 56 |>>> d[b] # looks in 56%8-th slot - but what's there is not __eq__ to b! | KeyError | Moral: don't use mutable objects as dictionary keys. allright, i understand. thanks. yours, uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From wayne at tbnets.com Sat Oct 27 09:30:31 2001 From: wayne at tbnets.com (Wayne Ringling) Date: Sat, 27 Oct 2001 09:30:31 -0400 Subject: Converting perl to python available? In-Reply-To: <20011027130356.B576@lilith.hqd-internal> Message-ID: Ouch, that was close. It's just that I have a program that's 74 pages printed and it's actually lean and mean as far as coding goes. I guess it's time to go back to the guts and gore and recode it. Wayne > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Gerhard Haring > Sent: Saturday, October 27, 2001 7:04 AM > To: python-list at python.org > Subject: Re: Converting perl to python available? > > > On Fri, Oct 26, 2001 at 10:37:35PM -0400, Wayne Ringling wrote: > > I have a few programs that I would love to convert to python > but don't want > > to spend the time to recode them completly. > > import os > os.system("myscript.pl") > > ;-) > > > Is there a project that is working on a conversion program yet? > > Seriously, has there ever been a translator from one language to another > that did not produce an absolute mess? I imagine it will only work > reasonably well for similiar languages, like Pascal -> Ada. But Perl and > Python are very different. Perl regexes would have to be translated to > Python library calls, for example ... What point would there be to > having translated code that is a greater mess than the original Perl > code ? > > Gerhard > -- > mail: gerhard bigfoot de registered Linux user #64239 > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 > public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 > reduce(lambda x,y:x+y,map(lambda > x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) > > -- > http://mail.python.org/mailman/listinfo/python-list > From dswegen at allstor-sw.co.uk Wed Oct 17 14:01:20 2001 From: dswegen at allstor-sw.co.uk (Dave Swegen) Date: Wed, 17 Oct 2001 19:01:20 +0100 Subject: os.path.join and lists Message-ID: <20011017190120.B14220@software.plasmon> I'm having a problem where I'm trying to use the os.path.join function to put together a path from various elements (a list slice, a string variable, and a fixed value). It looks somthing like this: bar = [ "fred", "barney", "froo" ] foo = os.path.join(bar[1:2], "bob") This causes a type error (TypeError: can only concatenate list (not "string") to list). Using just the bar variable doesn't work either. Basically, I guess the question is: How do I quote the values in a list (similiar to perl's, qw I guess)? I would really appreciate some pointers on how to get this to work without resorting to lengthy 'for i in bar' loops, which is the only way I can think of to do it (which isn't perhaps surprising, as I've just recently started using python). Cheers Dave From skip at pobox.com Wed Oct 24 23:19:05 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 24 Oct 2001 22:19:05 -0500 Subject: pickle behavior In-Reply-To: <84a8bdbe.0110241739.5258eb84@posting.google.com> References: <84a8bdbe.0110241739.5258eb84@posting.google.com> Message-ID: <15319.33961.5527.841130@beluga.mojam.com> taw> When pickling an object, is the expected behavior that it be taw> pickled identically each and every time? In general, no, you can't rely on this. Dictionaries, in particular, might have their key/value pairs serialized in different orders from one time to the next. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From careye at spamcop.net Thu Oct 25 20:35:12 2001 From: careye at spamcop.net (Carey Evans) Date: 26 Oct 2001 13:35:12 +1300 Subject: howto combine regex special sequences? References: <20011025000122.15639.qmail@web10304.mail.yahoo.com> Message-ID: <878zdzme67.fsf@psyche.dnsalias.org> Laura Creighton writes: [...] > I've been up for 36 hours, but the expression you are looking for is > r = re.compile('[^\w\s]') > > But you don't want to do that. Z is the last letter of the alphabet > in New Zealand, but ? is the last letter here in Sweden. Use the > string methods instead. Or use the appropriate flags with the regular expression. The Unicode character classes will always be consistent, but the locale's alphanumeric characters will vary, from the default locale based on US-ASCII: >>> import locale, re >>> locale.setlocale(locale.LC_ALL, 'C') 'C' >>> re.match(r'[^\w\s]', '?') and 'matched' 'matched' >>> re.match(r'[^\w\s]', '?', re.LOCALE) and 'matched' 'matched' >>> re.match(r'[^\w\s]', '?', re.UNICODE) and 'matched' >>> to other locales that use ISO-8859-1: >>> import locale, re >>> locale.setlocale(locale.LC_ALL, 'en_NZ') 'en_NZ' >>> re.match(r'[^\w\s]', '?') and 'matched' 'matched' >>> re.match(r'[^\w\s]', '?', re.LOCALE) and 'matched' >>> re.match(r'[^\w\s]', '?', re.UNICODE) and 'matched' >>> -- Carey Evans http://home.clear.net.nz/pages/c.evans/ "Ha ha! Puny receptacle!" From bart at sonik.pl Wed Oct 10 12:21:52 2001 From: bart at sonik.pl (Bartosz Aninowski) Date: Wed, 10 Oct 2001 18:21:52 +0200 Subject: swocket! help op python's expert References: <9q1768$26b$1@news.tpi.pl> Message-ID: <9q1sjj$iig$1@news.tpi.pl> > On Wed, Oct 10, 2001 at 12:16:20PM +0200, Bartosz Aninowski wrote: > > [...] > > AttributeError: XmlprocDriver instance has no attribute 'feed' > > I guess it's some sort of a version problem. Hopefully the README says > which versions of PyXML and Python should work. > problem is that swocket has no any readme and no install info even on website I couldn't find any info. python = 2.2 pyxml = 0.6.6 From anthony at interlink.com.au Sat Oct 20 01:43:22 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Sat, 20 Oct 2001 15:43:22 +1000 Subject: Triple-DES implementation in Python In-Reply-To: Message from Paul Rubin of "19 Oct 2001 07:23:57 MST." <7x1yjzoghu.fsf@ruckus.brouhaha.com> Message-ID: <200110200543.f9K5hMf09711@mbuna.arbhome.com.au> Or you could just grab M2Crypto, which has already done this :) >>> Paul Rubin wrote > Georg Bisseling writes: > > I would go to www.OpenSSL.org, get a free C implementation, > > learn how to integrate C extensions into python and do it. > > It's not that easy. You'd then have to make loadable modules for > every computer and OS that anyone who wants to use the function might > be running. There are plenty of C implementations of DES already > linked to Python, but it's useful to also have a pure Python > implementation. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Anthony Baxter It's never too late to have a happy childhood. From Jeremy.Jones at peregrine.com Thu Oct 11 11:22:28 2001 From: Jeremy.Jones at peregrine.com (Jeremy Jones) Date: Thu, 11 Oct 2001 11:22:28 -0400 Subject: SocketServer - multithreading Message-ID: <55720746FFC5D4118A3B00508BF9B80A012900CC@atlgaexc3.harbinger.com> I am trying to write a simple daemon that listens on a port and writes the request that it receives to a file. There will likely be multiple requests coming in at the same time, so it needs to block the file writing so that only one request writes to a file at once. I "borrowed" a code example from the web and hacked it a bit to try to do what I need (and it almost works). (If anyone sees that I am going about this in the wrong manner, please say so. I have had no experience with threading and almost no experience with sockets. Pointing me in another direction would be most welcome.) Assuming that SocketServer is a good way to handle this, here is what I have so far (BTW - this is Python 1.5.2 on Linux): """ #! /usr/bin/python -O import sys, SocketServer import string PORT = 2100 class RequestServer(SocketServer.ThreadingTCPServer): allow_reuse_address = 1 class RequestHandler(SocketServer.StreamRequestHandler): def handle(self): host, port = self.client_address #print "Connected by", host, port # get data request = '' while 1: line = self.rfile.readline() if line in (None, "\n", "\r\n"): break request = request + line self.server.request = request request = string.rstrip(request) print request #outfile = open("server.csv", 'w') #outfile.write(request) #outfile.close() def main(): # get port if len(sys.argv) > 1: port = int(eval(sys.argv[1])) else: port = PORT print "Waiting..." server = RequestServer(('', port), RequestHandler) #server.handle_request() # do not server forever - serve just 1 request server.serve_forever() # serve forever main() """ The thing that isn't working is the file writing (thus it's commented out right now). With the 3 "outfile" lines commented out, this works fine. But when I uncomment them, the first request prints the request to STDOUT and to the file, but subsequent requests only print to STDOUT. The first and subsequent requests apparently sit waiting on the socket: [jjones at mahler socket]$ netstat -a | grep 2100 tcp 0 0 mahler.atlqa:2100 mahler.atlqa:3167 TIME_WAIT tcp 0 0 mahler.atlqa:2100 mahler.atlqa:3166 TIME_WAIT tcp 0 0 mahler.atlqa:2100 mahler.atlqa:3165 TIME_WAIT tcp 0 0 *:2100 *:* LISTEN If anyone has any ideas how I can get this working (or find another solution), I would be most grateful. Jeremy Jones From Armin_member at newsguy.com Thu Oct 18 09:00:11 2001 From: Armin_member at newsguy.com (Armin Steinhoff) Date: 18 Oct 2001 06:00:11 -0700 Subject: Python and 3D Graphic tools References: <3bcece7f.18432984@news.easynews.net> Message-ID: <9qmjor08hu@drn.newsguy.com> In article <3bcece7f.18432984 at news.easynews.net>, stojek at part-gmbh.de says... > >Hi, >I want to write a little tools to visualize a kind of 3D puzzle. (The >single pieces are more or less cubes with or without holes and pins) >As I don't want to spend very much time on this I am looking for >an appropriate programming tool. > >VPython looked good, but it has only the basic volumes, like cubes and >spheres. > >VTK might be a little difficult and I don't fully understand how to >use it with Python. > >Is there anything between these two? Or a VTK add-on thing I could >use? > >I want to define relatively simple bodys, show them in 3D, and pile >them interactively. (No animation, just add or remove from the scene) see at: http://pyopengl.sourceforge.net Armin Steinhoff http://www.steinhoff-automation.com From phd at phd.pp.ru Fri Oct 5 06:44:14 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 5 Oct 2001 14:44:14 +0400 Subject: Pipes In-Reply-To: ; from dale@riverhall.NOSPAMco.uk on Fri, Oct 05, 2001 at 11:11:53AM +0100 References: Message-ID: <20011005144414.N588@phd.pp.ru> On Fri, Oct 05, 2001 at 11:11:53AM +0100, Dale Strickland-Clark wrote: > I notice that pipe support in Python is specific to Unix. > > There is win32pipe for Windows but documentation is thin, to say the > least. > > Has anyone done any work on inter-process and inter-machine > communication? Pipes are good enough. http://www-106.ibm.com/developerworks/linux/library/l-rt4/?open&t=grl,l=252,p=pipes Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From brueckd at tbye.com Wed Oct 24 15:43:03 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 24 Oct 2001 12:43:03 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: <15319.6276.254491.897200@beluga.mojam.com> Message-ID: On Wed, 24 Oct 2001, Skip Montanaro wrote: > > dave> P.S. - Print statements are not atomic and do not fall in the same > dave> realm as "normal" Python operations (e.g. "i = 5") ... > > Assignment is not atomic either. Your example would byte compile to > > LOAD_CONST 5 > STORE_FAST i Ooh, good point, bad example from me. As far as atomicity, I was thinking in terms of the C functions that implement the handling of the bytecodes themselves (e.g. PyDict_SetItem - no two threads will call PyDict_SetItem on the same dictionary at the same time). > As others have mentioned, at the level of individual opcodes Python is > atomic. The statement > > i = j > > would have to be protected if j could be rebound or the object j referenced > could be modified by another thread. Not necessarily. My point was simply that locking or no was mostly an application-level requirement rather than a Python interpreter one. For example (back to the producer/consumer example), assume that you have two producers and a consumer that toggles between the producer lists called 'j' and 'k'. If 'i' is the consumer's reference to whatever list it's currently working on, you don't need any locking around 'i = j' even if a producer happens to be modifying j at the "same time". Data won't be lost, the interpreter won't die, etc, etc. That's all I was pointing out. Thanks, Dave From billy_bill_1 at yahoo.com Mon Oct 8 02:32:15 2001 From: billy_bill_1 at yahoo.com (billy_bill_1 at yahoo.com) Date: Mon, 08 Oct 2001 06:32:15 -0000 Subject: Python questions -> compiler and datatypes etc Message-ID: <9prh9f+b0in@eGroups.com> Hi, I've been using php for ages for webdev and I don't like it. It lacks so many simple features, and I can't be bothered using Java to use those features. IMHO java is not suited for specific web development. So I find python, I like python. Python has everything I need, except (apparently) the ability to encode it (php: Zend Encoder) or compile it into Bytecode like java. It seems its not nearly as fast as java. (Acceptable in most cases though). Are there any products coming out involving compilation of python? Like a 2 stage interpreter like java... that would be tops... speed and ability to sheild source code from prying and tampering eyes. Does python have the ability to let the programmer change between strongly typed and loosly typed as needs be? python support function overloading? variable length parameter lists? If python doesn't support these features, could anyone redirect me to a language that does? Thanks, Billy From ignacio at openservices.net Wed Oct 10 17:41:01 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 10 Oct 2001 17:41:01 -0400 (EDT) Subject: upload file using cgi on Win2k IIS In-Reply-To: <3BC4BAB0.DB2F605A@tridog.com> Message-ID: On Wed, 10 Oct 2001, Jason McWilliams wrote: > Ignacio Vazquez-Abrams wrote: > > > > On Wed, 10 Oct 2001, Jason McWilliams wrote: > > > > > I seem to be doing everything correctly to save a posted > > > multipart/form-data file on IIS server. Yet, I only > > > seem to be able to save a small portion of the file, not > > > the whole thing. > > > > > > The internet user has permission to the temp directory and > > > I am not getting any errors. It works properly with the > > > same code on unix, so it must be a IIS thing? > > > > > > I have tried file.read file.value and also tried to just > > > do one line at a time... file.readline . I can get the > > > file name fine using cgiobj.filename ... etc. > > > > > > I get about 498 k as the file size on the uploaded file, never > > > more and I am trying to upload a big file. Maybe there is > > > a post limit in IIS? I know that you can set a GET limit. > > > > What is the value of the hidden field named "MAX_FILE_SIZE" set to? Is there > > one at all? If not, then don't expect your file input to work properly. > > I did not think this variable was used in cgi.py > Isnt that a php type thing. Isn't maxlen set to 0 inside cgi.py > to allow for unlimited post length? That is why I thought > it might be a IIS setting somewhere. Hmm. I had always thought it was a browser thing, but after doing some research I think that you're right. Unfortunately I don't have enough IIS knowledge to know exactly which setting it is. It's under the web properties, probably, but I have no idea past that. FYI, the default value of cgi.maxlen is 0, so that's probably not it. -- Ignacio Vazquez-Abrams From rjroy at takingcontrol.com Tue Oct 30 15:25:27 2001 From: rjroy at takingcontrol.com (Robert Roy) Date: Tue, 30 Oct 2001 20:25:27 GMT Subject: Using Tkinter's clipboard References: Message-ID: <3bdf0bd9.179332843@news1.on.sympatico.ca> On 30 Oct 2001 08:21:47 -0800, johnny at debris.2y.net (Johnny deBris) wrote: >Hi there, > >I was wondering how to use the clipboard from Tkinter. I noticed there >are some methods for clearing and appending to the clipboard, but none >to retreive something from it... Is there no way at all to retreive >data from the clipboard using Tkinter? I'm writing a small texteditor >that has to work cross-platform, so the Tkinter-way would be a lot >easier than using the windows-clipboard lib. If there's no way to do >it using Tkinter, though, could you people tell me how to work with >the clipboard in X? 'Cause I did not find anything about that either >:) > >Thanx a bunch, > >Guido Wesdorp, Holland It is quite simple atlhough not at all obvious. For example from an event handler: def onRightClick(self, event): data = event.widget.selection_get(selection="CLIPBOARD")) print data Bob From logiplexsoftware at earthlink.net Mon Oct 29 14:12:36 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Mon, 29 Oct 2001 11:12:36 -0800 Subject: Python still remembers script after change and save In-Reply-To: <1004382387.8324.0.nnrp-07.c1c3e128@news.demon.co.uk> References: <1004382387.8324.0.nnrp-07.c1c3e128@news.demon.co.uk> Message-ID: <01102911123601.03754@logiplex1.logiplex.net> On Monday 29 October 2001 11:06, Paul Brian wrote: > I occasionally come across a situation where I have changed a file, rerun > the file in python but python still produces an error, quoting the original > file in the error string Are you talking about the main script or a module you are importing? If you modify a module and import it again, you will still have the original module. You must call reload(module) to force Python to reinterpret the module -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From thomas.heller at ion-tof.com Tue Oct 23 09:48:14 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Tue, 23 Oct 2001 15:48:14 +0200 Subject: Auto debug on un-caught exception. References: Message-ID: <9r3seu$r73d9$1@ID-59885.news.dfncis.de> > I have seen somewhere out there in net land a method of > automatically running the debugger when an un caught exception > occurs. > > Can anybody point me in the right direction.... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287 Thomas From logiplexsoftware at earthlink.net Wed Oct 31 15:26:07 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 31 Oct 2001 12:26:07 -0800 Subject: connecting database In-Reply-To: <29A97D00F387D411AC7900902770E148024DF22D@lcoeexc01.coelce.net> References: <29A97D00F387D411AC7900902770E148024DF22D@lcoeexc01.coelce.net> Message-ID: <01103112260708.06896@logiplex1.logiplex.net> On Wednesday 31 October 2001 13:15, Alves, Carlos Alberto - Coelce wrote: > I know there's versions of mysql for Windows. So, I was thinking how can I > install one of that, make some basic database and, after all, connecti that > through python programs. > I think I'm going to check out mxODBC. Can I get it from Python site?! Alternatively, you could use the MySQLdb module: http://sourceforge.net/projects/mysql-python If you are looking for packages for Python, a good resource is the Vaults of Parnassus, which you can get to via the Python home page. Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From mail at andreas-penzel.de Mon Oct 29 14:57:13 2001 From: mail at andreas-penzel.de (Andreas Penzel) Date: Mon, 29 Oct 2001 20:57:13 +0100 Subject: .exe Message-ID: <9rkcbb$ucb5d$1@ID-69142.news.dfncis.de> Hello NG! Is it possible to make an .exe file from the .py soure running under DOS/Windows? Thanks! - Andreas From mark_barclay at datacruz.com Mon Oct 15 21:20:35 2001 From: mark_barclay at datacruz.com (Mark Barclay) Date: Mon, 15 Oct 2001 21:20:35 -0400 Subject: Python COM for Microsoft Project References: Message-ID: <9qg23b0gq4@enews4.newsguy.com> Mike, For the "list of objects" (classes, actually) that Microsoft Project exports (if it behaves like their other VBA enabled applications), simply do the following: Run Microsoft Project Select menu: Tools -> Macros-> Visual Basic Editor Select menu: View -> Project Explorer In the first list box, select the application itself, and you will see the API, annotated by class. I hope this helps. Mark "Mike Brenner" wrote in message news:mailman.1003186882.938.python-list at python.org... > Has anyone played with Python to control Microsoft Project? > > It is, of course, easy to open a MP file: > > from win32com.client import Dispatch > mpApp = Dispatch("MSProject.Application") > mpApp.Visible = 1 > mpApp.FileOpen ("C:\Documents and Settings\projectA.mpp") > # Warning: works only with absolute file names. > > > For the next line of code, I would like to resave the file as a tab-delimited file for further processing in Python. Actually, I will build a robot that opens all the MP files and resaves them. > > - Is there a URI to download the objects and methods that are now available? > > - Or is the list of objects somehow hidden inside my Visual Studio or my Microsoft Developer CDs? > > - Or do I need to buy Visual Basic for Applications or some other application to gain access to the objects? > > - Is there an upgrade to the COM object browser that comes with Python for Windows? > > Thanks > Mike Brenner > > From erno-news at erno.iki.fi Wed Oct 17 08:25:35 2001 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 17 Oct 2001 15:25:35 +0300 Subject: PosixSerial.py license and gcavazos? References: Message-ID: In article , Richard Jones writes: | On Wednesday 17 October 2001 14:37, Christian Robottom Reis wrote: || On Wed, 17 Oct 2001, Richard Jones wrote: || > If no license is given, isn't it fair to assume that the module is in the || > public domain? || || No, Copyright law states that even with no clear license or notice, the || file is copyright the author and he ultimately must decide on || redistribution and use policy. The problem here is that I can't locate the || author :/ | Yes, copyright stays with the author, but I didn't think that there was any | onus on them to state distribution and use policies. qmail doesn't come with a license. there is a lot of material on the net debating what that implies can done with it. i think djb has a page about the matter too. short answer is, iirc, that you can use it and modify it for local use, but not sell or distribute modified versions. -- erno From aa at bb.cc Sat Oct 27 15:01:08 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Sat, 27 Oct 2001 21:01:08 +0200 Subject: Question: Event driven programming References: <3bdad71d$1_3@corp-goliath.newsgroups.com> <3BBC7.3002$Z_1.506578@newsc.telia.net> Message-ID: <3bdb0140_5@corp-goliath.newsgroups.com> Thanks for your answer. What I have in my mind is not necessarily UI related. In VB, objects can raise events, objects interested in the events will handle them. Thats a very simple mechanism, facilitates easy coding in many situations, even if its just a console application with no GUI at all. They are similar to exceptions but they return to the caller and they can have parameters/return values of any kind. "Fredrik Lundh" az al?bbiakat ?rta a k?vetkez? ?zenetben: news:3BBC7.3002$Z_1.506578 at newsc.telia.net... > K?roly Ladv?nszky wrote: > > Does Python have means for event driven programming? > > can you elaborate. > > most ui frameworks for Python, and many network frameworks > (e.g. medusa) and parsers (e.g. sax-style XML parsers) use > event-driven programming. but they're all based on callbacks > and template methods... > > > > ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From markus at schabi.de Tue Oct 16 08:11:10 2001 From: markus at schabi.de (Markus Schaber) Date: Tue, 16 Oct 2001 14:11:10 +0200 Subject: FW: [Python-Dev] conditional expressions? References: <9qgcvk$91j$1@animus.fel.iae.nl> <9qgsul$5ep$1@thorium.cix.co.uk> Message-ID: <1226555.zL39ZcT7Z3@lunix.schabi.de> Hi, William Park schrub: >> > > A conditional expression analogy to list comprehensions would be >> > > x = (a if b else c) >> >> You can also remove the parentheses, and not have to worry about the >> "if" starting a new line. > > I believe Perl and Ruby has > x = a if b What does this do? Is it a conditional assignment? Should rather be spelled like x if= a, b :-) markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From mikael at isy.liu.se Fri Oct 26 02:31:51 2001 From: mikael at isy.liu.se (Mikael Olofsson) Date: Fri, 26 Oct 2001 08:31:51 +0200 (MET DST) Subject: Learing Python, Newbie question In-Reply-To: <3BD8BEE8.B7AB09AE@cosc.canterbury.ac.nz> Message-ID: On 26-Oct-2001 Greg Ewing wrote: > If you mean "shorter", "cuter", "more cryptic", etc. > you could use > > db_flag = "wa"[db_first] > > provided db_first is known to be either 0 or 1. And if db_first is not known to be either 0 or 1, you could do db_flag = "aw"[not db_first] /Mikael ----------------------------------------------------------------------- E-Mail: Mikael Olofsson WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 Date: 26-Oct-2001 Time: 08:29:33 /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ This message was sent by XF-Mail. ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From mark21rowe at yahoo.com Thu Oct 11 00:00:04 2001 From: mark21rowe at yahoo.com (Mark Rowe) Date: Thu, 11 Oct 2001 17:00:04 +1300 Subject: Sockets References: <3d69st0v0s49ldmngrgj5viis7seqsifql@4ax.com> Message-ID: <3bc527cc@news.actrix.gen.nz> Hello, I don't really think that disabling the Nagel algorithm would acheive a lot in this case, and could cause unwanted network congestion as a side affect. I also agree with the previous posters suggestions. Mark "John S. Yates, Jr." wrote in message news:3d69st0v0s49ldmngrgj5viis7seqsifql at 4ax.com... > On 10 Oct 2001 04:14:48 -0700, hugomartires at hotmail.com (Hugo Martires) wrote: > > >My server need to send 2 strings separeted: > > s1= 'xxx' > > s2= 'yyy' > > > >My client must received like this: > > rec1= 'xxx' > > rec2= 'yyy' > > > >The problem is that the Client received s1 and s2 in one only string. > > > >How can i received in 2 separeted variables ? > > > >Tanks > > Previous posters have given the "correct" answer > and I agree with them. But a kludgy fix might > be to disable the Nagel algorithm. This involves > putting the socket into no-delay mode. I am very > new to Python, so I don't know how or whether you > can do this but in traditional socket programming > it is definitely an option. > > /john > -- > John Yates > 40 Pine Street > Needham, MA 02492 > 781 444-2899 From tim.one at home.com Sat Oct 20 16:21:38 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 20 Oct 2001 16:21:38 -0400 Subject: Random from Dictionary In-Reply-To: <4f7234de.0110180504.20aa475b@posting.google.com> Message-ID: [Tim Payne] > ... > I'm trying to obtain x number of random unique items from a > dictionary. This would have been easy to do with a list, but I need > the dictionary for other parts of the script. In 2.1 or before, there's no simpler way than to materialize a list and use that, like: def random_from_dict(d, x): "Return and remove (no more than) x random (k, v) pairs from d." import random items = d.items() random.shuffle(items) result = items[:x] for k, v in result: del d[k] return result Season to taste. In 2.2 you could use a more memory-efficient scheme via iterating over d directly: def random_from_dict(d, x): "Return and remove x random (k, v) pairs from d." from random import random n = float(len(d)) # float() so x/n later doesn't truncate to 0 if not 1 <= x <= n: raise ValueError("go away") result = [] for k in d: # Choose this item with probability x/n. if random() <= x/n: result.append((k, d[k])) x -= 1 if x == 0: break n -= 1 for k, v in result: del d[k] return result > I've tried popitem(), but arbitrary values just aren't good enough. If I were you, I'd think about changing the algorithm so that arbitrary values are good enough <0.9 wink>. popitem()-is-fast-and-threadsafe-but-not-pretty-ly y'rs - tim From fredrik at pythonware.com Mon Oct 29 06:02:02 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Oct 2001 11:02:02 GMT Subject: tkinter-canvas-rectangle-delete References: Message-ID: huber wrote: > Can someone tell me what I am doing wrong ? > from Tkinter import * > > def delz(): > for i in c.find_all(): > print c.gettags(i) > c.delete("200") c.delete("x200") > root=Frame() > > c=Canvas(root,width=100,height=100) > n=c.create_rectangle(0,0, 10,10, fill="red",tag="res") > c.addtag_withtag("200",n) c.addtag_withtag("x200",n) > b=Button(text="delete 200",command=delz) > b.pack() > c.pack() > root.pack() > > root.mainloop() > ther rectangle is not deleted by clicking ther button ! integers are interpreted as item handles, not tags, even if you pass them to Tkinter as strings. From wolfson at uchicago.edu Mon Oct 15 14:07:07 2001 From: wolfson at uchicago.edu (Ben Wolfson) Date: Mon, 15 Oct 2001 13:07:07 -0500 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qf81s$lut$1@inputplus.demon.co.uk> Message-ID: In article <9qf81s$lut$1 at inputplus.demon.co.uk>, "Ralph Corderoy" wrote: > Hi Tim, > >> implemented-but-not-checked-in-ly y'rs - tim > > Don't check it in. It's horrible. I'm all for a ?: in Python using > some notation or other but requiring parenthesis around just this kind > of expression isn't on. > > It's non-obvious and distinct from other areas. It is surprising! Furthermore the use of "then" in this case but not in the more general if: elif: else: case is potentially confusing. -- Barnabas T. Rumjuggler Clock zero: You are a pirate masquerading as a counselor. From sholden at holdenweb.com Tue Oct 30 19:00:35 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 30 Oct 2001 19:00:35 -0500 Subject: A better way to send mail? References: Message-ID: "David Brady" wrote in ... > Hello all, > > Python promotes marital harmony. > [ ... ] > Anyway, I'm just wondering if the MimeWriter libs > would be better suited, and if so, how? Sorry if this > example is too long. I probably only needed to post > the first three lines of code, but I wanted other > newcomers like me to be able to see the context. > > Thank you, David: Don't know whether this will improve your marital harmony, but it shows how to send graphic attachments using the MimeWriter library! import MimeWriter, base64 # # Writes a multipart mail message: text plus associated graphic # mfile = "multimsg.eml" f = open(mfile, "w") # Create a MimeWriter mail = MimeWriter.MimeWriter(f) mail.addheader("From", "Steve Holden , Steve Holden """) mail.addheader("Subject", "The Python You Wanted") mail.addheader("Received", """from thinker [64.134.121.94] by mail.holdenweb.com (SMTPD32-6.04) id A244C78500BA; Fri, 09 Mar 2001 07:33:38 -0500""") # Mail will be multi-part: First part explains format part1 = mail.startmultipartbody ("mixed") part1.write("This is a MIME-encoded message, with attachments. " "If you are seeing this message your mail program probably cannot " "show you the attachments. Please try another program, or read 'Web " "Programming in Python' to see the attached picture." """ Sorry ... Steve Holden """) # Second part is intended to be read part2 = mail.nextpart() f = part2.startbody("text/plain") f.write("Here we have a multipart message. This " "means that the message body must be processed " "as MIME-encoded content where possible [which " "it clearly is in Outlook Express]." """ regards Your Humble Author """) # Third part is a graphic, which we encode in base64 part3 = mail.nextpart() part3.addheader("Content-Transfer-Encoding", "base64") f = part3.startbody("image/gif", [["Name", "python.gif"]]) b64 = base64.encodestring(open("pythonwin.gif", "rb").read()) f.write(b64) # Never forget to call lastpart! mail.lastpart() regards Steve -- http://www.holdenweb.com/ From phr-n2001d at nightsong.com Sat Oct 13 21:15:48 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 13 Oct 2001 18:15:48 -0700 Subject: Getting arg value from generic exception Message-ID: <7x1yk7yqbf.fsf_-_@ruckus.brouhaha.com> Suppose I want to catch an generic exception and get the value-- is there a clean way to do that? I.e., for a specific exception FrobError, I can say try: x = frob() except FrobError, arg: report_error(arg) But what about generic exceptions: try: x = frob() except: ... # how do I get the arg? Using sys.exc_info works, but doesn't feel too good: exceptions with args are supposed to be a Python language feature and not a library function. Also, the sys module must of course never be exposed to code running under restricted execution. Even sys.exc_info probably shouldn't be exposed, since if restricted code can see the exc_info[2] stack trace, it may be able to reach the local vars of bastion objects that throw exceptions (I haven't checked this). There's a trend in Python towards making all exceptions inherit from the Exception class, which would solve the problem (just say except Exception,arg: ...) but for now you can still have exceptions that don't inherit from Exception. So this looks like a gap in the Python spec. Am I missing something? From phd at phd.pp.ru Tue Oct 2 18:42:00 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 3 Oct 2001 02:42:00 +0400 Subject: http request timeout In-Reply-To: <1611506.Xa2WqB4rES@lunix.schabi.de>; from markus@schabi.de on Tue, Oct 02, 2001 at 11:36:48PM +0200 References: <3BBA1BF6.2020702@hp.com> <1611506.Xa2WqB4rES@lunix.schabi.de> Message-ID: <20011003024200.A26839@phd.pp.ru> On Tue, Oct 02, 2001 at 11:36:48PM +0200, Markus Schaber wrote: > There already was the suggestion for the timeoutsocket, but another way > might be to use select() to wait for more than one action. This way, > one thread can wait for input on multiple connections, and e. G. for a > message from a watchdog thread. Asynchroneous IO is useful in lots of > cases, but somehow more difficult to program. Timeoutsockets use select() internally, of course. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From dusterzx77 at hotmail.com Mon Oct 1 17:11:21 2001 From: dusterzx77 at hotmail.com (Chase Turner) Date: Mon, 01 Oct 2001 16:11:21 -0500 Subject: (no subject) Message-ID: hello, my name is chase. I'm very new to programing and to python. I'm having a little trouble in using python. I don't know how to creat a program using it. To be truthful i know nothing at all about python 2.1.1 i believe. I was wondering if you could help me. There is a window like the dos window and i can write stuff but when i type in stuff in code i get from the net to make a program it works but it only appears on the dos like screen. How do you make it into a program? Your help would be greatly appreciated. chase _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp From James_Althoff at i2.com Fri Oct 12 20:29:18 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 12 Oct 2001 17:29:18 -0700 Subject: Loop-and-a-half (Re: Curious assignment behaviour) Message-ID: Tim Peters wrote: >[Michael Chermside, on a conditional expression] >> ... >> As before, if anyone else feels strongly that they'd like to contribute >> (other than the excellent comments several folks already made), they >> should email me. > >If people sign off on taking "then" as a new keyword, I think the chances >are good that we could get > > x = if e1 then e2 else e3 > >into 2.2b1. Looks good to me. Jim From tex_r at hotmail.com Thu Oct 18 21:58:26 2001 From: tex_r at hotmail.com (Tex Riddell) Date: Thu, 18 Oct 2001 18:58:26 -0700 Subject: Is there a small Python runtime environment installer? References: <3583b331.0110181524.5695bd67@posting.google.com> <9uKz7.44320$cb.809545@atlpnn01.usenetserver.com> Message-ID: <3bcf88bc$1@news.microsoft.com> "Steve Holden" wrote in message news:9uKz7.44320$cb.809545 at atlpnn01.usenetserver.com... > "Tex Riddell" wrote in message > news:3583b331.0110181524.5695bd67 at posting.google.com... > > I have some useful scripts that I'd like to share with someone that > > doesn't have Python. He doesn't want to install all of Python right > > now (like examples, utilities, source, IDE's and tk - yuck), he'd > > rather just have an executable or install a simple runtime library and > > run my script. > > > Probably the closest thing you'll find is PythonWare's distributions: > > http://www.pythonware.com/products/python/index.htm > > Probably not what you want, but the closest I know about. > > regards > Steve > -- > http://www.holdenweb.com/ Thank you, this is getting closer to what I was looking for. It does have the ease of install (no options), but this can be a curse as well as a blessing. If it had features broken down by major area, like core runtime & libs (required), Tkinter (optional), Imaging (optional), Sount toolkit (optional), it would be nice. There are a couple of things that it's still lacking, however: - environment setup (so .py files are recognized etc...). This would of course break it's ability to co-exist with another distro of python environment, unless it detected that associations already existed and left them alone. - and much less importantly: pre-compilation and compression of .py libraries Still, this is my best option so far. Thanks, Steve... -Tex From info at mjais.de Sun Oct 21 14:48:57 2001 From: info at mjais.de (Markus Jais) Date: Sun, 21 Oct 2001 20:48:57 +0200 Subject: problem with re module Message-ID: <9qv5d4$psb1n$1@ID-75083.news.dfncis.de> hello I have a strange problem when I take the re example from the python org site and put in my interactive python interpreter everythings works fine: Python 2.1 (#1, Jun 4 2001, 12:55:45) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import re >>> p = re.compile('ab*') >>> print p >>> but when I put it in a file: #!/usr/local/bin/python import re p = re.compile('ab*') print p I get an error: Traceback (most recent call last): File "re.py", line 3, in ? import re File "./re.py", line 4, in ? p = re.compile('ab*') AttributeError: 're' module has no attribute 'compile' this error first appeared today and it only happens with the re module. I can also not use any DOM modoles for example because the rely on the re module but everything is intstalled unter /usr/local/lib/python2.1 can anybody help me?? thanks markus From sholden at holdenweb.com Mon Oct 15 22:50:39 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 15 Oct 2001 22:50:39 -0400 Subject: Extracting attachments with Python? References: <0B%x7.10230$YC3.3926894@typhoon.southeast.rr.com> Message-ID: There is code that will read .dbx files from Outlook Espress, and certainly once you can read a mail message you can extract attachments from it as long as it's a well-structured email message (and there's no reason it won't be). I've provided the .dbx reader to several people on an individual basis, saying each time that I'd release it when I'd turned it into usable form. Since that may never happen, and other people might want to use it by modifying it, I've now published it in my public-domain Python code page. See http://www.holdenweb.com/Python/ regards Steve -- http://www.holdenweb.com/ "Alex Ravenel" wrote in message news:0B%x7.10230$YC3.3926894 at typhoon.southeast.rr.com... > Is there a way to have Python extract a series of attachments from a > Microsoft Outlook .dbx file into a file of my choosing? I was sent a series > of documents by my brother, and while they arent really that many (about > 100), I think it would be interesting to see if Python could do it for me. > Thanks. > > -- > > > Alex Ravenel > bonzo at vnet.net > > From j.c.mcnulty at open.ac.uk Wed Oct 31 04:11:57 2001 From: j.c.mcnulty at open.ac.uk (James) Date: 31 Oct 2001 01:11:57 -0800 Subject: Compiling python error Message-ID: <6e761479.0110310111.454ee89e@posting.google.com> Dear All, When I try to configure python i get the following errors. Any ideas James bash-2.03# ./configure loading cache ./config.cache checking MACHDEP... sunos5 checking for --without-gcc... no checking for --with-cxx=... no checking for c++... c++ checking whether the C++ compiler (c++ ) works... yes checking whether the C++ compiler (c++ ) is a cross-compiler... yes checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... yes checking whether we are using GNU C... yes checking whether gcc accepts -g... yes checking for Cygwin environment... no checking for mingw32 environment... no checking for executable suffix... no checking for --with-suffix... checking LIBRARY... libpython$(VERSION).a checking LINKCC... $(PURIFY) $(CC) checking LDLIBRARY... libpython$(VERSION).a checking for ranlib... ranlib checking for ar... ar checking for a BSD compatible install... ./install-sh -c checking how to run the C preprocessor... gcc -E checking for AIX... no checking for minix/config.h... no checking whether gcc accepts -OPT:Olimit=0... configure: error: can not run test program while cross compiling From vulpine at dontspam.earthling.net Tue Oct 16 23:12:16 2001 From: vulpine at dontspam.earthling.net (Tod Fox) Date: Wed, 17 Oct 2001 03:12:16 GMT Subject: Further help w/ readline needed References: Message-ID: Ignacio Vazquez-Abrams wrote: > It looks like you'll also have to install the libtermcap RPM. No, it looks like it is installed: [root at calanthe /lib]# rpm -i libtermcap-2.0.8-26.i386.rpm error: cannot open file libtermcap-2.0.8-26.i386.rpm: No such file or directory [root at calanthe /lib]# locate libtermcap /lib/libtermcap.so.2.0.8 /lib/libtermcap.so.2 Do you have any other ideas? Thanks for your help and I apologize if I seem a cl00less newbie. :) Kit From logiplexsoftware at earthlink.net Wed Oct 24 17:23:37 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 24 Oct 2001 14:23:37 -0700 Subject: Critical sections and mutexes In-Reply-To: References: Message-ID: <01102414233702.24656@logiplex1.logiplex.net> On Wednesday 24 October 2001 11:59, brueckd at tbye.com wrote: > I was merely responding to somebody's not-entirely-true assertion that > "_every_ access to that [shared] resource _must_ be enclosed in locks". My assertion may not have been entirely true, but more useful to someone trying to learn threading than a discussion on the esoterics of which Python statements may or may not be atomic =) Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From wolfson at uchicago.edu Tue Oct 2 21:34:47 2001 From: wolfson at uchicago.edu (Ben Wolfson) Date: Tue, 02 Oct 2001 20:34:47 -0500 Subject: Does there exist a Python-to-Perl translator ? References: <3BB2D226.3C260A2C@Spam.Please> <3BB31597.96BFE8B7@Spam.Please> <3BBA1DE3.2BC96E54@sage.att.com> Message-ID: In article <3BBA1DE3.2BC96E54 at sage.att.com>, "Garry Hodgson" wrote: > Weet Vanniks wrote: >> >> You don't get my point. Managers do want to see Perl code. What I want >> is benefit from the productivity of Python, get something working and >> then satisfy my manageer with a Perl solution. > > you need a better class of managers. If your manager is old-style, you can just do manager.__class__ = some_new_class. I understand it's more complicated if not impossible for new-style managers. -- Barnabas T. Rumjuggler All obscurity will buy you is time enough to contract venereal diseases. -- Tim Peters From jblazi at hotmail.com Sun Oct 7 04:42:00 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Sun, 7 Oct 2001 10:42:00 +0200 Subject: Newbie Question References: <9pp1ca$ca6$1@slb4.atl.mindspring.net> Message-ID: <3bc0155f_8@news.newsgroups.com> Let us assume, you want to use the function strip from the string modeul. There are three possibilities: (1) >>>import string in this case you have to use qualified names: >>>s=string.strip(s) (2) >>>from string import split then you can omit the "string."-prefix: >>>s=strip(s) but you have only imported the function strip (3) >>>from string import * then you can use +every+ function from string without the "string."-prefix J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From rwhite at netins.net Fri Oct 5 20:53:19 2001 From: rwhite at netins.net (Ron White) Date: Fri, 5 Oct 2001 19:53:19 -0500 Subject: Generating a random number Message-ID: <9plkkk$98r$1@ins22.netins.net> Will someone please tell me exactly how to generate a random number from 1 to 10 in Python 2.1.1 running under windows me? I'm beginning to think there is something wrong with my installation or I'm just not smart enough to understand what I read. Thank you for any help. Ron -- Ron White Amateur Radio WA0MWW From emile at fenx.com Sun Oct 28 09:57:26 2001 From: emile at fenx.com (Emile van Sebille) Date: Sun, 28 Oct 2001 06:57:26 -0800 Subject: Destroying all instances (references) References: Message-ID: <9rh6le$tftnu$1@ID-11957.news.dfncis.de> ----- Original Message ----- From: "Andreas Zieringer" Newsgroups: comp.lang.python Sent: Sunday, October 28, 2001 3:08 AM Subject: Destroying all instances (references) Hi, is it possible to destroy all created instances, something like an "new" command in basic? I know re-creating the interpeter would do this, but in the new interpreter I have to import all modules again and I can't do this. Is there an easy way doing this in pythom or with the c-api? I couldn't find anything in the python docu. Regards Andreas This will clear all objects in __main__ that don't start with an underscore: import __builtin__ def _init(_type='vars'): import sys, types main = sys.modules['__main__'].__dict__ for i in main.keys(): if not i.startswith('_'): if _type == 'all': del main[i] elif _type == 'vars': if type(main[i]) != types.ModuleType: del main[i] __builtin__.init = _init If you create/add this to lib/sitecustomize.py then you will be able to invoke init() to clear the references. F:\Python22>python Python 2.2b1 (#25, Oct 19 2001, 11:44:52) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os, sys >>> a,b,c = 1,2,3 >>> class C:pass ... >>> c1,c2 = C(), C() >>> dir >>> dir() ['C', '__builtins__', '__doc__', '__name__', 'a', 'b', 'c', 'c1', 'c2', 'os', 'sys'] >>> init() >>> dir() ['__builtins__', '__doc__', '__name__', 'os', 'sys'] >>> init('all') >>> dir() ['__builtins__', '__doc__', '__name__'] >>> HTH, Emile van Sebille emile at fenx.com --------- From BrianQ at ActiveState.com Mon Oct 29 16:34:32 2001 From: BrianQ at ActiveState.com (Brian Quinlan) Date: Mon, 29 Oct 2001 13:34:32 -0800 Subject: A small inconsistency in syntax? In-Reply-To: Message-ID: <002c01c160c1$90a96620$b503a8c0@activestate.ca> James wrote: > Brian Quinlan wrote: > >I could want to write: > >a = ['x value','y value','z value'] = x > > > >Here the intermediate list is doing 3 things for me: > > > >1. it's providing documentation > >2. it's forcing the sequence type to be of length 3 > >3. it's making the type assigned to 'a' a list > > and > > 4. it's providing a handy way to generate a syntax error ;-) > > Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit > (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > >>> > >>> a = ['x value','y value','z value'] = 1,2,3 > SyntaxError: can't assign to literal > >>> That was exactly the point of the original argument - that it is reasonable to do sequence unpacking into mutable literals even though the language does not allow it. Cheers, Brian From asencio at mitre.org Mon Oct 29 13:40:04 2001 From: asencio at mitre.org (Angel Asencio) Date: Mon, 29 Oct 2001 13:40:04 -0500 Subject: BOA GUI builder? References: <3BD9CC09.2B1AB020@mitre.org> <3BDC909B.4F500B9C@mitre.org> Message-ID: <3BDDA284.B564E2CB@mitre.org> Thanks, it worked! Btw. For WinCVS users, be sure you do not have a carrige return at the end of the command. "\n" Ok, someone told me that to be able to use boa v0.0.13 with wxPython 2.3.1 I had to do some modifications. I checked on source forge, and I could not find any patch related to this. Could someone post the changes or a place to get the patch for v0.0.13 to be able to work with wxPython 2.3.1? Thanks. Paolo Invernizzi wrote: > The "module" name is "boa"... > Probably you can have a closer look using the "browse cvs" link on project > page... > Cheer > > Paolo Invernizzi > > "Angel Asencio" wrote in message > news:3BDC909B.4F500B9C at mitre.org... > > I went to the boa sourceforge site, and although I could find rhw CVS > files > > listed, I could not find a module name to dowload through CVS, nor a link > to > > download all the files related to V0.0.13. > > > > What am I missing? > > > > Thanks. > > > > Tim H wrote: > > > > > The version in CVS is much further along (0.0.13). You might want to > try > > > that. It works for me. You do have to modify it slightly, it is > looking > > > for wxPython 2.30 and we are both using 2.3.1, but if you got BOA 0.0.5 > to > > > work you should have no probs with that. > > > > > > Tim H > > > "Angel Asencio" wrote in message > > > news:3BD9CC09.2B1AB020 at mitre.org... > > > Greetings: > > > I got the BOA Python IDE from http://boa-constructor.sourceforge.net/. > > > I looks great, but when I went to save the WxFrame.py from the tutorial, > it > > > gave me a Win2000 error, but I ignored it. > > > Then when I went to save WxApp.py it crashed. > > > I have Win2000, BOA 0.0.5, wxPython 2.3.1 and Python 2.1 > > > Do I need to get some patch to stabilize BOA? > > > Thanks, > > > -- > > > -Angel > > From janssen at parc.xerox.com Tue Oct 23 16:49:28 2001 From: janssen at parc.xerox.com (Bill Janssen) Date: Tue, 23 Oct 2001 13:49:28 PDT Subject: file(1) command in Python? Message-ID: <01Oct23.134935pdt."3456"@watson.parc.xerox.com> Has anyone written a module or function for Python which provides the functionality of the Unix file(1) command? That is, it attempts to guess the type of a file by looking for distinctive patterns in the contents of the file, usually driven by a table of "magic" numbers and strings. Bill From claird at starbase.neosoft.com Wed Oct 3 11:52:28 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 3 Oct 2001 10:52:28 -0500 Subject: Really great stuff you didn't know you had. #4 - Pydocs. References: Message-ID: <3D19C9B64FD905FA.B76859A792E3CF8B.E471BBB8EA776B30@lp.airnews.net> In article , Dale Strickland-Clark wrote: >I never really had time to hunt through the stuff that came with my >Python dist. to find what goodies lay hidden within. > >But by accident the other day while looking for info on docstrings, I >came upon PyDoc, which, on my system is at: > >C:\Python21\Tools\Scripts\pydoc.pyw > >What a brilliant program this is! > >If you run it, it creates an http server that serves up docs generated >from your Python modules. > >Just point a web browser at the port and browse. > >Great stuff. Thanks Ka-Ping Yee . . . Ka-Ping Yee indeed deserves recognition and thanks (and not just for PyDoc). Those who need more encouragement before they decide to examine PyDoc for themselves are welcome to visit and . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From nomad*** at ***freemail.absa.co.za Mon Oct 1 06:42:26 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Mon, 01 Oct 2001 12:42:26 +0200 Subject: What happened to Python for BeOS? References: <9p2bp8$140c$1@nntp6.u.washington.edu> Message-ID: <93igrtcrsf4oil1if8733o8ie4ggptecum@4ax.com> On 28 Sep 2001 17:24:56 GMT, Donn Cave wrote: >Quoth Nomad : >| On Thu, 27 Sep 2001 17:41:21 +0400 (MSD), Roman Suzi >| wrote: >|> Can't find Python for BeOS any more... >|> Any ideas? >| >| The last I coul find was on BeBits a while back. And that is only a >| version of 1.5.2 (I can e-mail it if you want it). I'd also like to >| get a more uptodate version for Be. > >You should be able to find version 2.1, see http://www.bebits.com/app/2206. >It has been there since April 30. > >Version 2.0 is easier to build on BeOS, and the Stackless patches for >2.0 work, at least for modest use of continuations. (Microthreads >crashed the interpreter, for me.) Your choice. > > Donn Cave, donn at u.washington.edu Cheers, One problem though, the link to the source code didn't work for me, is the tarball still there? TIA -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From kosh at aesaeion.com Thu Oct 25 05:24:10 2001 From: kosh at aesaeion.com (kosh at aesaeion.com) Date: Thu, 25 Oct 2001 03:24:10 -0600 (MDT) Subject: can I use sessions with Zope? In-Reply-To: <9r8ihf$emi$06$1@news.t-online.com> Message-ID: On Thu, 25 Oct 2001, Timo Kuchenbuch wrote: > Is this possible to open a session with Zope??? > In the dokutemtaion I havent found anything. Go to zope.org and do a search for Core Session Tracking It is a nicely designed product for sessions. Designing the webpages of tomorrow http://webme-eng.com Designing the MMORPGS of tomorrow http://worldforge.org From loewis at informatik.hu-berlin.de Thu Oct 25 11:28:59 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 25 Oct 2001 17:28:59 +0200 Subject: Solaris core dump with McMillan Installer References: <9r960f$s8h9i$1@ID-59885.news.dfncis.de> Message-ID: > > So does anyone know what the worst case alignment rule is for > > structs? If you are talking about C structs, you should be aware that the layout varies from system to system; in particular, the internal padding may change. So if you have a single worst-case alignment, the structure fields may still end up on the wrong positions on some systems. "Thomas Heller" writes: > Isn't this specified in the C-standard ? > (That's what I heard, not that I would have one...) The C standard doesn't explicitly mandate alignment for a structure; it just mandates that all fields are aligned. In turn, that normally means that a structure must be aligned in the same way as the field with the largest alignment. That means that the worst-case alignment for a structure is the same as the worst alignment for any type. On most systems requiring primitive types to be aligned, the alignment is 8 if they support a "double" type. On Ultra-SPARC, the worst-case alignment is 16, for the "long double" type. Regards, Martin From fishoutawata at home.com Fri Oct 19 02:14:30 2001 From: fishoutawata at home.com (Jeremy Howard) Date: Fri, 19 Oct 2001 06:14:30 GMT Subject: Python + wxPython database app References: <2a97b6b7.0110181923.500abb40@posting.google.com> Message-ID: Michael, You might want to take a look at reportlab's open source PDF generation tool for your reporting engine. If your interested in using PDF's as your repoting medium check out www.reportlab.com "Michael Ekstrand" wrote in message news:2a97b6b7.0110181923.500abb40 at posting.google.com... > Hello, > > I am beginning work on a large database application, primarily for the > Win32 platform, and I would like to write it in Python with wxPython > if at all possible. > > However, I have one problem. I need access to an advanced reporting > engine. I'd like to use Crystal Reports - is there a way to use the > Crystal Reports viewer from Python/wxWindows? If there is another > fairly complete reporting engine that would integrate better into > Python/wxWindows, I would be more than willing to consider it. > > Pythonwin may also be an option for me, if it is easier to integrate a > reporting engine into it. However, I'm not terribly keen on that > option due to lack of documentation (or is there documentation I am > not aware of?). > > And my final option (besides pure Visual Basic, which I don't really > want to do) is a Visual Basic GUI and a Python business logic layer - > but this seems like it would be a lot of extra debugging, or am I > wrong somehow? > > Any advice would be most appreciated! > > Thank you, > Michael From nomad*** at ***freemail.absa.co.za Fri Oct 12 10:11:48 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Fri, 12 Oct 2001 16:11:48 +0200 Subject: multi command session through a socket References: Message-ID: <77udstcmaialm2920c7svj4eap6k9f25d4@4ax.com> On 12 Oct 2001 12:28:02 GMT, Gordon McMillan wrote: >Nomad wrote: > >> I've been playing with sockets and serversockets in Python (2.1 win32) >> for the last few days. I've been trying to adapt the code from >> 'BaseHTTPServer.py' in the standard library, but no matter what I try, >> the server side always drops the connection after only one command, >> whereas I'd like to be able to run several commands (like telnetting >> into a pop3 session) and finishing with a QUIT command (or hopfully >> later a timeout, but that's another question entirely). > >[snip] > >> def handle(self): > >[snip] > >> self.quit = 1 >> while self.quit == 1: # <---- what is wrong here >> self.raw_requestline = self.rfile.readline() >> if not self.parse_request(): >> return >> >> def parse_request(self): > >[snip] > >A cursory examination reveals that you >are always returning a false value >from parse_request. Looks like "self.quit" >and the return from parse_request have >redundant intents and conflicting >implementations. > >- Gordon Thanks Gordon, I didn't spot that - looks like I left too much of the original code in. I removed the return 0's from parse_request() and changed the handle() loop to: # start test code self.quit = 1 while self.quit == 1: self.raw_requestline = self.rfile.readline() self.parse_request() # end test code and it keeps alive until I give a 'quit' command. All I have to do now is work out how to implement a decent timeout function. Thanks again. -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From ignacio at openservices.net Wed Oct 10 16:17:53 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 10 Oct 2001 16:17:53 -0400 (EDT) Subject: upload file using cgi on Win2k IIS In-Reply-To: <3BC4AA59.524CB637@tridog.com> Message-ID: On Wed, 10 Oct 2001, Jason McWilliams wrote: > I seem to be doing everything correctly to save a posted > multipart/form-data file on IIS server. Yet, I only > seem to be able to save a small portion of the file, not > the whole thing. > > The internet user has permission to the temp directory and > I am not getting any errors. It works properly with the > same code on unix, so it must be a IIS thing? > > I have tried file.read file.value and also tried to just > do one line at a time... file.readline . I can get the > file name fine using cgiobj.filename ... etc. > > I get about 498 k as the file size on the uploaded file, never > more and I am trying to upload a big file. Maybe there is > a post limit in IIS? I know that you can set a GET limit. What is the value of the hidden field named "MAX_FILE_SIZE" set to? Is there one at all? If not, then don't expect your file input to work properly. -- Ignacio Vazquez-Abrams From ignacio at openservices.net Thu Oct 11 17:37:02 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 11 Oct 2001 17:37:02 -0400 (EDT) Subject: Problem : building a module ... In-Reply-To: <3bc60f06$0$15687$626a54ce@news.free.fr> Message-ID: On Thu, 11 Oct 2001, dag4004 wrote: > I want to creat a new module. It is a module wich use the Nano-X GUI Client > functions. To do so i creat a nanoxmodule.c with the Makefile.pre.in .... > and i can creat a nanoxmodule.so > BUT in python when i enter : import nanox > my lovely interrpreter say me that the Nano-X function are unknown. > It is right because the function are not linked in nanoxmodule.so but how > could i force the linking of this functions in my nanoxmodule.so, i have the > library libnano-x.a but how could i "put" it in nanoxmodule.so Once you have created the wrapper functions for the functions in libnano-x.a you need to add the wrapper functions to the module's dictionary. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From jhauser at ifm.uni-kiel.de Wed Oct 3 16:01:24 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 03 Oct 2001 22:01:24 +0200 Subject: __getatr__ question References: <89a9b6ce.0110030954.7ee3043f@posting.google.com> Message-ID: <87u1xg8pd7.fsf@lisboa.ifm.uni-kiel.de> It's the order of evaluation, and that you change the instance inplace. If you change __getattr__ to def __getattr__(self, a): self.string = a print 'self.string = %s' % self.string return(self.nop) This becomes obvious. The output of k.func1(k.func2(12)) looks then self.string = func1 self.string = func2 k.func2(12) k.func2() Although I must admit, that I also expected that the argument of a function call is also evaluated before the function is called. So it does not seem to look like a bug, but perhaps there are more insights available :-). __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From brueckd at tbye.com Fri Oct 26 14:50:01 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 26 Oct 2001 11:50:01 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: <01102610043300.27505@logiplex1.logiplex.net> Message-ID: On Fri, 26 Oct 2001, Cliff Wells wrote: > BTW, Dave, I would like to say that I have learned a few things on this topic > that I wasn't aware of - thanks for the interesting discussion. Me too, and thank *you*! I know c.l.py isn't the only one like this, but there aren't too many other newsgroups where people can take strong positions and have a detailed discussion without it always turning into a childish flamewar. Very refreshing and educational for me! Thanks, Dave From phd at phd.pp.ru Thu Oct 25 07:54:19 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 25 Oct 2001 15:54:19 +0400 Subject: Modules for Python In-Reply-To: <3BD7F8E6.120ACE7B@lucent.com>; from wosko@lucent.com on Thu, Oct 25, 2001 at 01:35:02PM +0200 References: <3BD7F263.2F3FAEB6@lucent.com> <3BD7F8E6.120ACE7B@lucent.com> Message-ID: <20011025155419.K13913@phd.pp.ru> On Thu, Oct 25, 2001 at 01:35:02PM +0200, Jakub Wosko wrote: > but what should I use, if I have unix server and want to > generate HTML document from excel data, using Python as > CGI scripting language? http://www.xlhtml.org/ Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From skip at pobox.com Tue Oct 16 18:47:50 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 17:47:50 -0500 Subject: Extending Python - variable sized arrays? In-Reply-To: <7xlmibjk7f.fsf@ruckus.brouhaha.com> References: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> <9qi8f2$o0o9a$1@ID-75083.news.dfncis.de> <7xlmibjk7f.fsf@ruckus.brouhaha.com> Message-ID: <15308.47382.152196.46983@beluga.mojam.com> Paul> Use the apply function. apply(f, [1,2,3]) is the same as f(1,2,3). In recent versions (>= 2.0 I think), you can dispense with apply() in many situations: >>> def f(*args): ... print args ... >>> apply(f, (1,2,3)) (1, 2, 3) >>> f(*(1,2,3)) (1, 2, 3) Same technique works for keyword args: >>> def g(**kwds): ... for k in kwds: ... print (k, kwds[k]) ... >>> apply(g, (), {"a":1, "b":2}) ('a', 1) ('b', 2) >>> g(**{"a":1, "b":2}) ('a', 1) ('b', 2) Generally speaking, neither technique is used with literals as I've shown, but to pass variable arg lists along to other varargs functions: class Foo(Bar): def __init__(self,a,b,c,*args,**kwds): Bar.__init__(self,a,b,c,*args,**kwds) ... -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From loewis at informatik.hu-berlin.de Mon Oct 15 10:47:39 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 15 Oct 2001 16:47:39 +0200 Subject: Parsing XML (simple) References: Message-ID: singleton at skynet.be (Thomas Singleton) writes: > > commande1 > commande2 > [...] > After reading the modules doc and a few usenet posts, i have written a > small python program to echo the values contained between tags, but > i'm having troubles with the commands, only the FIRST one is echoed. This is no surprise. You do > commands = commandmail.getElementsByTagName("commands") > for command in commands: > handleCommand(command) This gives you all "commands" elements. Since there is only a single "commands" element, this loop is executed just once. Then you do > def handleCommand(command): > commandline = command.getElementsByTagName("command")[0] > print "Command : ", commandline.firstChild.data.strip() This gets all "command" children of the "commands" element, then takes only the first of those "command" elements - ignoring the second. Regards, Martin From root at rainerdeyke.com Thu Oct 18 13:37:53 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Thu, 18 Oct 2001 17:37:53 GMT Subject: Curious assignment behaviour References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> <3bcdbb39.1987133892@news> Message-ID: "David C. Ullrich" wrote in message news:3bcdbb39.1987133892 at news... > What if you already have x = 42 and y = 24, and you > say "let x = y" ? Does that set x to 24 (yes) or > does it set y to 42? It means "consider the case 42 = 24". -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From emile at fenx.com Fri Oct 12 16:48:55 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Oct 2001 13:48:55 -0700 Subject: YOU ARE ALL GAY! References: Message-ID: <9q7l97$mb952$1@ID-11957.news.dfncis.de> "Grant Edwards" wrote in message news:slrn9sekm4.f7l.grante at grante.comtrol.com... > In article , PoulsenL at capecon.com wrote: > > > Bizarrly enough it looks like stenography. Maybe just my > > paranoid self, but it is english sounding gibberish. Actually > > i have seen stenographic examples that were more coherent. > > I presume you mean steganography. Shouldn't a good > steganographic message really ought to make sense on it's own? > That way nobody would suspect that there is concealed content. > My guess would be automated Stenoscription. ;-) -- Emile van Sebille emile at fenx.com --------- From sholden at holdenweb.com Fri Oct 26 13:55:26 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 26 Oct 2001 13:55:26 -0400 Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> <3BD995CB.22D3507A@home.net> <2jhC7.23321$IR4.13366040@news1.denver1.co.home.com> Message-ID: <_ohC7.38719$Nx2.821986@atlpnn01.usenetserver.com> "Rainer Deyke" wrote in ... > "Chris Barker" wrote in ... > > Terry Reedy wrote: > > > > > As I understand it, the rule is this: if item on LHS is tuple rather > > > than name, then corresponding object on RHS must be a tuple, which > > > will then be seen as collection rather than object in itself and > > > consequently unpacked for matching to items within LHS tuple. > > > Allowing for null matches and applying the rule recursively, > > > > Actually either side can be a sequence, not just a tuple: > > Nitpick: Although the LHS can be written as either a tuple literal or a list > literal, it is in fact not an object at all, and hence not a tuple, list, or > any other kind of sequence: > > a, b = 3, 4 # a <- 3; b <- 4 > a_b = a, b > a_b = 3, 4 # Does not affect the value of 'a' or 'b'. > tuple((a, b)) = 3, 4 # Syntax error. > This is getting TOO weird. Should this really be allowed? Does it make any kind of sense? The attached comes from 2.0, but 2.1.1 and 2.2b1 give the same result. >>> [a,b] = (1,2) # no surprises here >>> a 1 >>> b 2 >>> [a,b][1] = 23 # WHAT!?!?!?!?!?!? >>> b 2 What does the interpreter actually DO with this statement, and why is it allowed? To what is the value 23 actually bound here? regards Steve -- http://www.holdenweb.com/ From aa at bb.cc Thu Oct 25 16:24:12 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Thu, 25 Oct 2001 22:24:12 +0200 Subject: Question: Dynamic code import References: Message-ID: <3bd86fb9_5@corp-goliath.newsgroups.com> Hi Bjorn, Thanks for your quick answer. Yes, I was mistaken with the global directive. It's clear now. Regarding the first question, it works fine with the interpreter but I would like to read f11(a) from somewhere else, most likely from a file. Cheers, K?roly "Bjorn Pettersen" az al?bbiakat ?rta a k?vetkezo ?zenetben: news:mailman.1004039306.14596.python-list at python.org... > From: K?roly Ladv?nszky [mailto:aa at bb.cc] > > Hi, Hi > I've been experimenting with Python for a short period of > time and I really enjoy it. It allows me to do a lot of > things that are much harder or even not possible to > accomplish in other languages. I'd like to receive comments > on the following problems. Welcome > 1. Is it possible to 'import' Python code in a dynamic fashion? > > For instance, the running program refers to function f1 through ff: > > def f1(a): > return a*1.25 > > ff=f1 > > At some point, it turns out that f1(a) should return a*1.3+5. > If it was possible to insert a new function, the running > program could be modified like this: > > #--- this is to be 'imported' > def f11(a): > return a*1.3+5 > #--- > > ff=f11 > > Now ff(a) would produce results by using the new rule embodied in f11! Try it in the interpreter: >>> def f1(a): return a*1.25 ... >>> ff = f1 >>> ff(1) 1.25 >>> def f2(a): return a*1.3+5 ... >>> ff = f2 >>> ff(1) 6.2999999999999998 >>> > 2. Something is wrong with globals. Given the example below, > I'd expect 2 for the second print. You're misunderstanding the "global" directive. It is used inside a function to tell the interpreter that it should look for a given variable in the global scope: var = 1 def f(x): global var # look for var in global namespace var += x (the global directive is also only needed when assigning to the global, but you can probably forget that for now...) -- bjorn ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From matt at mondoinfo.com Wed Oct 24 21:08:45 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Thu, 25 Oct 2001 01:08:45 GMT Subject: Need help with programming. References: <20011024194636.07978.00000094@mb-mb.aol.com> Message-ID: On 24 Oct 2001 23:46:36 GMT, Django wrote: >Hello. I've just begun using Python, and am now getting into simple >commands. Everytime I try to use "else:" I get this message: >SyntaxError: invalid syntax It's probably your indentation. The else: needs to be lined up with your if: >>> a=5 >>> if a==4: ... print "four" ... else: ... print "not four" ... not four Regards, Matt From cbarber at curl.com Mon Oct 29 13:38:17 2001 From: cbarber at curl.com (Christopher Barber) Date: 29 Oct 2001 13:38:17 -0500 Subject: Curl-ing, anyone? References: <458b194a.0110241156.795e9618@posting.google.com> <3BD720E3.43791C55@alcyone.com> Message-ID: Erik Max Francis writes: > Resty Cena wrote: > > > Is Curl (www.curl.com) a threat to Python (and Ruby, and Perl)? > > Unlikely, for two reasons. First, the purpose that it exists for is > already solved by other client-side technologies -- namely Java and > JavaScript -- which are already almost universally available. More like HTML + JavaScript + Java + Flash. Yes, you can probably do much of what you can do in Curl using a combination of those four technologies, but it is a lot easier to just use Curl. > Second, the licensing model they chose is an immediate turn-off, > particularly when you note that those other preexisting technologies > are free. Don't be so sure, Curl is totally free for non-commercial use and we don't even charge anything for the development environment. Furthermore, commercial users do not have to pay a dime until they actually deploy a commercial application and then must pay a small amount based on the size of the application and how much it is used by their customers. As long as your application brings you revenue, then you should have no problem affording the licensing fees. > Curl the language seems neat, but neatness alone doesn't make something > a success. Very true, but I am glad you think it's neat. > Curl the business doesn't sound too appetizing. I can see how really small shops that like to use free tools would be reluctant to take advantage of Curl technology, but large software shops already spend huge sums of money on licensing and maintenance fees, and should not have the same misgivings. Even small shops should not be afraid to try the technology out: it only costs you as much time as you care to spend checking it out, and the licensing fees are substantially lower for small companies. Regarding the original question, I don't really think that the Curl language is going to be much of a threat in the short to medium term to the existing non-web-based scripting technologies, such as Python, Ruby and Perl. The whole point of the technology was to make it easy to develop and deploy web-based content, not to be yet-another-scripting-language. Those other technologies do a pretty good job on the server side and for standalone apps, but anyone who has used client-side Java, JavaScript or Flash can tell you that the existing alternatives on the client-side are far from ideal. - Christopher From jim at publishingresources.com Fri Oct 5 11:17:03 2001 From: jim at publishingresources.com (Jim Abrams) Date: Fri, 05 Oct 2001 15:17:03 -0000 Subject: Possible to read/write Excel files in Python? References: <1002211708.1269.0.nnrp-07.c1c3e19f@news.demon.co.uk> Message-ID: "Paul Brian" wrote in <1002211708.1269.0.nnrp-07.c1c3e19f at news.demon.co.uk>: > >Could I suggest the following: > >1) install a windows box and use the win32 extensions to setup the excel >spreadsheet as a COM server, then push that data to your python >application via smtplib or xmlrpc or whatever. > Take a look at Python21\win32com\test\testMSOffice.py for some win32 examples with excel. From ignacio at openservices.net Thu Oct 4 20:13:09 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 4 Oct 2001 20:13:09 -0400 (EDT) Subject: SQL/Python question -- slow... What is the fixed cost? In-Reply-To: <3BBCF0D0.29A3CB9E@iems.nwu.edu> Message-ID: On Thu, 4 Oct 2001, Leonardo B Lopes wrote: > Me DB is in 3NF. And I know that 83K isn't that big, but it is big > enough to make a query last .0008 cpusec. when joined w/ 2 other tables > (That is the actual amount, before rounding). The problem is that a > query on a table with only 12 items also takes about the same time. So I > need to know how much time the library is using for data checking, > network connection, etc... Speaking of which, what happens if you use MySQL's socket instead of TCP/IP? > > [snip] > > Apparently, .0004 is a Lower Bound on how fast a query can be, and that > is not good news for me. Yeah, but you've still only tested with a single client. > > [snip] > > So even with a temporary table always in memory, the overhead hasn't > changed much. Comments? MySQL is pretty good at keeping the relevant data in memory, so there shouldn't be much if any gain that way. -- Ignacio Vazquez-Abrams From lucio at movilogic.com Tue Oct 23 11:52:28 2001 From: lucio at movilogic.com (Lucio Torre) Date: Tue, 23 Oct 2001 12:52:28 -0300 Subject: POLL in different OSes In-Reply-To: <20011023101838.A561@lilith.hqd-internal> References: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> Message-ID: <5.1.0.14.0.20011023125024.027cf278@imap.hq.movilogic.com> At 10:18 AM 23/10/2001 +0200, Gerhard H?ring wrote: >On Mon, Oct 22, 2001 at 10:51:02PM -0300, Lucio Torre wrote: > > From the documentation: > > > > "The poll() system call, supported on most Unix systems" > > > > and my questions: > > > > a) is poll supported on Windows? > > > > my guess is no, but i hoping for a yes. > >It isn't. Unless, you're using Cygwin. Also, select only works with >sockets on Windows. > >Wouldn't it be possible to emulate poll() with select()? I'd be glad to >see a patch appear at Sourceforge if that's possible :-) > >Gerhard >- i think i could do that. i can make a .c with the code that amulates poll from select, if someone else is willing to make it a patch or whatever it should be to get into python. btw: is it worth it? poll is supposed to be faster, so why emulate it? it would have no reason to exist! From spaceman at bsdzine.org Tue Oct 23 06:59:11 2001 From: spaceman at bsdzine.org (Karol Makowski) Date: 23 Oct 2001 10:59:11 GMT Subject: Python for ipaq References: <1003829421.27538.0.nnrp-01.d4f0f8ae@news.demon.co.uk> <7SbB7.7669$Ub2.260976@atlpnn01.usenetserver.com> Message-ID: On 23 Oct 2001 10:50:46 GMT, Karol Makowski wrote: > On Tue, 23 Oct 2001 06:47:52 -0400, Steve Holden wrote: >> Sample FTP code in ftpStream.py at > thanks, i'll check it. it's not suitable for my needs, sorry. I need an ftp client which will dynamicaly get filename/folder from a commandline. On that crappy ipaq there is no any smb/nfs protocol and i've got some app which need to send and recive some files to work correctly, so i thought i'll get some simple ftp client in python, cause python it's avaiable for ipaq. ftp client should be run from command line like this: ftp.py -g somefile (download file from server) ftp.py -s somefile (send some file to server) It's all i need, server, username/pass is defined in program, while filename and/or path should be a variable. Thanks for help. -- Karol Makowski, System Administrator URL: http://spaceman.bsdzine.org e-mail: spaceman at bsdzine.org From tdelaney at avaya.com Thu Oct 18 20:47:58 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 19 Oct 2001 10:47:58 +1000 Subject: Desperate help required for Python assignment Message-ID: > From: ullrich at math.okstate.edu [mailto:ullrich at math.okstate.edu] > On 17 Oct 2001 00:47:07 -0700, nachiket_gole at hotmail.com (Nachiket) > wrote: > > >I am new to Python doing a crash course in University. I have a > >assignment to submit in two days the specifications of which are: [snip] > > Please can some of the Gurus on this newsgroup help me out with a > >working solution as with my limited knowledge i am no position to > >handle this assignment in two days. > > Actually it's a trick question - this cannot be done in Python. > Some of your classmates will be handing in stuff that doesn't > quite do this, hoping for partial credit. You should tell the > teacher you've determined it's impossible - I'm sure he'll be > properly impressed. Hah! And I thought some people may possibly think I was being a bit harch on the fellow ... I appear to have been the most helpful of everyone :) Just goes to show - despite the extreme friendliness and tolerance on this list/newsgroup, we're still a bunch of competent techies who don't like spongers ... Tim Delaney From olov_johansson_not_for_sale at mail.ru Thu Oct 11 19:22:07 2001 From: olov_johansson_not_for_sale at mail.ru (Olov Johansson) Date: Thu, 11 Oct 2001 23:22:07 GMT Subject: help: Crossplattform audio functionality in Python References: Message-ID: "Paul Winkler" wrote in message news:slrn9sbueh.1ob.slinkp23 at roaddog.armsnet... > Another option, though no python bindings exist yet: Portaudio, > see http://www.portaudio.com the site appeared to be down when i tried that url.. anyways, to sum it up: there are severeal potential crossplatform sound libraries which would suit python just fine. among them are libao (gpl), libsdl (lgpl), mpg123 output routines (gpl), portaudio(?). writing python bindings for any of these should be no problem, but it needs to be integrated into the python core before it's really useable (to easen up things for users). /olov From anthony at interlink.com.au Sun Oct 28 09:53:51 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Mon, 29 Oct 2001 01:53:51 +1100 Subject: how do I get solaris thread fixes from 2.2b1 into 2.1? In-Reply-To: Message from Tony McDonald of "Sun, 28 Oct 2001 14:50:38 GMT." Message-ID: <200110281453.f9SErpI32328@mbuna.arbhome.com.au> If you can point out the area of fixage, I can look at whether it's possible to get these into 2.1.2... Anthony >>> Tony McDonald wrote > Hi, > Can anyone tell me what I need to do to get the Solaris thread fixes > that are in python 2.2b1 into a copy of python 2.1 I have? > > The reason is that it appears there is some interaction between python > and zope under solaris that makes zope behave as a single threaded > server. Certainly, if a long running web request is set off, you can't > select any other links on the server until the first request has > finished. > > A thread on the yahoo groups archive gives some context; > > http://groups.yahoo.com/group/zope/message/74484 > > The latest version of python (2.2b1) has a fix that sorts out some > problems in threading with Solaris. > > The zope guys have said that zope is not currently compatible with > python 2.2 (understandable - python 2.2 is a beta after all!), so it > seems that what I need to do is to extract the fixed threads code from > 2.2b1 and retrofit them into my 2.1 installation. > > So, is there anyone out there that can give me a hint as to what I need > to do? > > many thanks for any hints on this one... > > tone. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Anthony Baxter It's never too late to have a happy childhood. From kirschh at lionbioscience.com Wed Oct 10 05:57:00 2001 From: kirschh at lionbioscience.com (Harald Kirsch) Date: 10 Oct 2001 11:57:00 +0200 Subject: changing `import' to use other than .py Message-ID: Is there a way to tell import (or __import__) to a) use a different extension than .py when searching for files b) not to compile that file while/after importing Thanks, Harald Kirsch -- ----------------+------------------------------------------------------ Harald Kirsch | kirschh at lionbioscience.com | "How old is the epsilon?" LION bioscience | +49 6221 4038 172 | -- Paul Erd?s *** Please do not send me copies of your posts. *** From tim.one at home.com Sun Oct 28 22:30:05 2001 From: tim.one at home.com (Tim Peters) Date: Sun, 28 Oct 2001 22:30:05 -0500 Subject: Python 2.2b1 hashable dictionary bug? In-Reply-To: Message-ID: [Mark J] > Since I haven't had a good hit rate at detecting bugs vs. features, I > thought I'd post here before filing a bug report at SourceForge. Suspected bugs have a much better chance of being seen if posted to SourceForge. You don't lose any points for reporting something suspicious that turns out not to be a bug -- you simply get a definitive answer more quickly, most of the time. This one is a bug, and I opened a bug report for you: > Python 2.2b1 (#1, Oct 19 2001, 23:11:09) > [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> class D(dictionary): pass > ... > >>> d = {} > >>> d2 = D() > >>> d[d2] = "dictionary used as key" > >>> You can stop there -- objects of builtin mutable types should never be usable as dict keys. From nickg at glencros.demon.co.uk Thu Oct 11 11:53:54 2001 From: nickg at glencros.demon.co.uk (Nick Glencross) Date: Thu, 11 Oct 2001 16:53:54 +0100 Subject: Python: Zope with MySQL (and insert_id) References: <3BC574C4.3070307@glencros.demon.co.uk> Message-ID: <3BC5C092.1070103@glencros.demon.co.uk> Chris Gonnerman wrote: > This question is really best sent to the Zope list (go to zope.org > for more info). Cheers. There really should be a Zope Newsgroup here! :-) Nick From logiplexsoftware at earthlink.net Thu Oct 4 18:54:29 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 4 Oct 2001 15:54:29 -0700 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: References: <1002040943.560.290.l9@yahoogroups.com> <3BBBCEF9.BF7B5B16@nisus.com> Message-ID: <01100415542901.05766@logiplex1.logiplex.net> On Thursday 04 October 2001 15:10, Courageous wrote: > >Or when the robber says, "We're from the IRS or the state tax board > >and we'll bull-doze your house and seize all your financial accounts > >if you don't pay up 'voluntarily'." > > It _is_ voluntary. You agreed when you agreed to the social contract > implied in your citizenship. > > C// Oh, I remember now... when I chose to be born here they made me sign that contract... I guess I should have read the fine print, but hey, I was young. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From rwhite at netins.net Sat Oct 6 14:11:26 2001 From: rwhite at netins.net (Ron White) Date: Sat, 6 Oct 2001 13:11:26 -0500 Subject: Generating a random number References: <9plkkk$98r$1@ins22.netins.net> Message-ID: <9pnhev$4qr$1@ins22.netins.net> Thank you Magnus. In one of my many attempts at trying to generate random numbers I put random.py in the idle directory (it must have been my first attempt). I moved it to my programs directory and lo and behold IT WORKS!!! Thanks to everyone who has helped with this perplexing problem. Ron "Ron White" wrote in message news:9plkkk$98r$1 at ins22.netins.net... > Will someone please tell me exactly how to generate a random number from 1 > to 10 in Python 2.1.1 running under windows me? I'm beginning to think > there is something wrong with my installation or I'm just not smart enough > to understand what I read. > > Thank you for any help. > Ron > > -- > Ron White > Amateur Radio WA0MWW > > > From gangli at msn.com Wed Oct 17 18:34:51 2001 From: gangli at msn.com (gang li) Date: 17 Oct 2001 15:34:51 -0700 Subject: string.digits, string.letters? How? References: <3BCDCC6F.16954B08@starhub.net.sg> Message-ID: <9dfc16ab.0110171434.2ab87f52@posting.google.com> Paul Lim wrote in message news:<3BCDCC6F.16954B08 at starhub.net.sg>... > Hi again to all, > > I am a newbie in Python and please really pardon me for my trivial > question. > > How can we use the digits, letters variable in the string modules? > > I have the following snippet of my code > > # Import library modules > # ====================== > > import sys > from string import lower, find, atoi, digits, letters > > if digits(sys.argv[i+1]): > print "Invalid argument" > > but i get the error message > File "test.py", line 32, in ? > if digits(sys.argv[i+1]): > TypeError: object is not callable: '0123456789' > > What is wrong? > > Thank you very much. > > Sincerely > Paul try: long(sys.argv[i+1]) print "Invalid argument" except ValueError: pass From richard at bizarsoftware.com.au Thu Oct 4 19:03:40 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 5 Oct 2001 09:03:40 +1000 Subject: Zope vs PHP for the Linux guru In-Reply-To: References: Message-ID: <0110050903400F.04291@ike> On Friday 05 October 2001 08:24, Cameron Laird wrote: > Zope development is breathtakingly swift--in the hands > of an expert. As wonderful as Zope is, though, it's > hard to make a case that it's easy to learn. It's pro- > bably the case that it lacks just the right bit of > documentation, or examples, or something; in any case, > newcomers consistently report rather extended intervals > before they "get" the Zope way of working. The new Zope Book (freely downloadable) is a really good effort to remedy this. > In principle, you can do lots of neat stuff with Zope > "out of the box". In practice, there's enough of some- > thing missing from the documentation that few beginners > realize at the beginning what they can do with Zope. > > PHP database support is unmatched. Zope supports lots > of DBs, but they're not all built-in, as with PHP. On > the other hand, you seem actively involved only with > MySQL and SQL Server, so maybe you don't need much da- > tabase support. Zope supports a whole lot of stuff that doesn't ship with it - something I hope to remedy. And it's a bit of a pain for a point-n-click user to get started with - another thing I hope to remedy :) See http://dev.zope.org/Wikis/DevSite/Proposals/BatteriesIncludedDistribution > It does NOT support "Web server farming" of the sort > I suspect you have in mind, though. There's no parti- > cular reason it doesn't (and maybe someone's fixed > this recently); it's just that no one's gone to the > trouble of making it a reality. I'm not sure of the specifics, but doesn't ZEO handle this? Richard From mlh at idi.ntnu.no Sat Oct 6 13:47:39 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 6 Oct 2001 19:47:39 +0200 Subject: Generating a random number References: <9plkkk$98r$1@ins22.netins.net> <9pnb95$aug$1@ins22.netins.net> Message-ID: <9png3r$rr4$1@tyfon.itea.ntnu.no> "Ron White" wrote in message news:9pnb95$aug$1 at ins22.netins.net... > Hi, > When I used the following I got: > > >>> from random import randrange > Traceback (most recent call last): > File "", line 1, in ? > from random import randrange > File "C:\PYTHON21\Tools\idle\random.py", line 3 > for i in range(10): > ^ > SyntaxError: invalid syntax > >>> Hm. This doesn't seem like the random module. It should be located at C:\PYTHON21\Lib\random.py Also, it does not contain the line "for i in range(10):", as far as I can see. Are you sure this isn't a script that you've written yourself that's being imported by mistake (because you've put it in your PYTHONPATH)? As far as I can see, the standard distribution does not include a file called random.py in the idle directory... > The one thing that has worked is from Dale Strickland-Clark. That is: > > from whrandom import randint > > print randint(1, 10) Yes, this works, but it is deprecated. If you try to move the random.py file away from its current location (where it probably shouldn't be) you will probably be able to get the _real_ random library, and this should work: from random import randrange print randrange(10)+1 > I wonder if my random module is corrupt? The one you are importing is, it seems... But probably not the real library :) > Ron -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From kerstin.dressler at web.de Tue Oct 30 05:30:50 2001 From: kerstin.dressler at web.de (Kerstin) Date: 30 Oct 2001 02:30:50 -0800 Subject: file operations Message-ID: Hi, I need to do the following file operations: begin loop - read file - replace something in the file (seem to work) - write file end loop This has to be done quite often. Can anybody help me? Thanx, Kerstin From tatebll at aol.com Wed Oct 31 08:18:35 2001 From: tatebll at aol.com (Bill Tate) Date: 31 Oct 2001 05:18:35 -0800 Subject: How to read a xml-file sequentially References: Message-ID: "Thomas Weholt" wrote in message news:... > Hi, > > I need to read a xml-file sequentially, piece by piece, when a given end-tag > to a given start-tag is found, the xml-data inbetween the start and end are > sent to a different method for processing, then the next piece of data is > read, sort of like old-school record-based files. > > Only the needed data is kept in memory. > > How can this be done using preferrably expat or sax? No DOM cuz the files > are huge. > > Thomas Thomas - Suggest you may also want to look at Pyxie.org site. One of the tools developed by Sean McGrath is a hybrid option. The pyxie library includes the capability of using event processing up to a particular point (a specific start tag for example) and then switch over to tree-like processing. Sounds like it might be relevant for your problem. While Pyxie doesn't seem to have a lot of activity going on with it right now, it does have a number of useful tools that work well with the gymnastics of xml processing. From dbeech at bigpond.net.au Sat Oct 27 06:03:37 2001 From: dbeech at bigpond.net.au (David Beech) Date: Sat, 27 Oct 2001 21:03:37 +1100 Subject: tutorial In-Reply-To: <20011026134628.A607@lilith.hqd-internal> References: <9rb6pi$nva$1@penthesilea.materna.de>; from michael.korte@materna.de on Fri, Oct 26, 2001 at 10:29:23AM +0200 Message-ID: <3BDB2129.3753.195DBAF7@localhost> On 26 Oct 2001, at 13:46, Gerhard H?ring wrote: > On Fri, Oct 26, 2001 at 10:29:23AM +0200, kutte wrote: > > Hi there ! > > I'm looking for a python tutorial for beginners. I would like to learn > > python, but I didn't found any (good) toutorials (online or download). > > I just have expierience in programming procedual Languages. ( C, Basic and > > Javascript) So I need a very "calm" tutorial *g* You might like to try this one but it's in English: http://www.veritatis.org.au/beechd/python/index.html From db3l at fitlinxx.com Tue Oct 23 21:25:29 2001 From: db3l at fitlinxx.com (David Bolen) Date: 23 Oct 2001 21:25:29 -0400 Subject: string object methods vs string module functions References: Message-ID: Robin Becker writes: > I would have thought this to be a minor speedup as the main work > must still be in C, but have others any thoughts/experiences on > this? A function which ReportLab uses a lot is join so my primitive > hack test seems to bear out my intuition as join performance seems > very similar. Clearly I'm not actually testing this properly, but > are there any good disambiguating tests? I'd probably up the size of the test set, so that you spend more time in join itself as opposed to the surrounding Python loop code, which may otherwise dominate the test. Of course, that assumes that doing so is representative of the use of join in the code to be affected, which may or may not be true. For example, on my NT system with Python 2.1.1, using 1024 elements: >>> L=[chr(i%256) for i in xrange(1024)] >>> doit0(L) 2.7539999485 >>> doit1(L) 2.68400001526 So not tremendous, but about 2.5% faster and measurable. I think it also depends on the method in question - for example, here's the same test but replacing the join with a fixed search for "fox" in the phrase "The quick brown fox jumped over the lazy dog": >>> doit0(None) 0.0699999332428 >>> doit1(None) 0.039999961853 So that appears to be closer to a 42% improvement. I'm guessing that some of that may be because of the way that the string module index function uses the *args notation to parse its arguments and then also to pass them on to the string method. I can get back maybe 30% of that by using a function that has explicit arguments rather than *args (which perhaps argues for not using that notation in the string module, but then you'd have to ensure the defaults between the string object code and the string module remained the same). The rest may be that internally the join method has to do more work and thus the entry overhead via the module function is less critical to it than it is to a simple search function like index. Of course like any timings, mileage may vary :-) -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From oktay_safak at yahoo.com Wed Oct 3 13:45:48 2001 From: oktay_safak at yahoo.com (Oktay Safak) Date: Wed, 3 Oct 2001 10:45:48 -0700 (PDT) Subject: font diaplay problem in IDLE Message-ID: <20011003174548.85437.qmail@web20706.mail.yahoo.com> Hi all, I asked about this on the tutor list but got no answer. Maybe some of you knows a solution. I use sitecustomize.py to use turkish encoding, the console gets it right but on IDLE, the characters special to my language are not displayed properly, some other funny characters are shown instead. When I write some text to a file and inspect the file with notepad I see that the characters are OK. So IDLE does what I want but does not show it properly. I tried to configure IDLE by changing the font it uses for display from its config file but somehow a sans-serif font shows up instead of courier new, and it still shows the wrong encoding. Any ideas? German and French fellows might have had a similar problem I guess. Thanks, Oktay Safak __________________________________________________ Do You Yahoo!? Listen to your Yahoo! Mail messages from any phone. http://phone.yahoo.com From skip at pobox.com Tue Oct 16 10:37:13 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 09:37:13 -0500 Subject: fast sub list operations In-Reply-To: References: <15308.11525.102304.624520@beluga.mojam.com> Message-ID: <15308.17945.822446.173014@beluga.mojam.com> >> >>> zip([1,2,3],[7,8,9]) >> [(1, 7), (2, 8), (3, 9)] Robin> I know about NumPy and like it a lot, but it's a bit heavyweight Robin> for what we need. I also know about zip and apart from there Robin> being no unzip it doesn't join up my list which should look like Robin> [1,7,2,8,3,9]. Whoops... Try this instead: >>> l = zip([1,2,3],[7,8,9]) >>> reduce(operator.add, l, ()) (1, 7, 2, 8, 3, 9) Obviously, if you need a list, you can apply that function to the result. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From fredrik at pythonware.com Mon Oct 29 06:12:11 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Oct 2001 11:12:11 GMT Subject: PIL - Image.open() problem References: Message-ID: Per Jensen wrote: > Problem: I have a method in a classe which sometimes open a JPEG image, > and at other times do not. > --------------------------------------------- > Opening picture: "1.jpg" > Traceback (most recent call last): > File "./picture.py", line 155, in getImage > self.picture = Image.open(self.filename) > File "/var/tmp/python-imaging-root//usr/lib/python2.0/site-packages/PIL/Image.py", line 871, in open > prefix = fp.read(16) > AttributeError: read > -------------------------------------------- could it be that someone's passing you a unicode string? PIL's file-or-string code doesn't deal properly with unicode strings: >>> import Image >>> i = Image.open("lena.jpg") >>> i = Image.open(u"lena.jpg") Traceback (most recent call last): File "", line 1, in ? File "c:\py21\PIL\Image.py", line 936, in open prefix = fp.read(16) AttributeError: read >>> try changing your code to: self.picture = Image.open(str(self.filename)) or, if you're on a platform that can handle unicode filenames: self.picture = Image.open(open(self.filename, "rb")) ::: note that 2.2 is a bit more helpful: Python 2.2b1 (#25, Oct 19 2001, 21:26:51) >>> import Image >>> i = Image.open("lena.jpg") >>> i = Image.open(u"lena.jpg") Traceback (most recent call last): File "", line 1, in ? File "c:\py22\PIL\Image.py", line 936, in open prefix = fp.read(16) AttributeError: 'unicode' object has no attribute 'read' From r.elliott at mech.canterbury.ac.nz Wed Oct 10 15:32:10 2001 From: r.elliott at mech.canterbury.ac.nz (Rodney) Date: 10 Oct 2001 12:32:10 -0700 Subject: Newbie - unslicable type error etc Message-ID: <45956635.0110101132.245dcbf6@posting.google.com> Hi Everyone, I started playing with python last night for the first time and I have run into a problem regarding data types. I have a large (7MB or so) file of raw hex data (ie values E{0,255}) from which I need to identify a given byte sequence that occurs about 800 000 times within the file. Once I have found these data fragments I need to extract them to another file. My problem is that while I have been able to open the file and use read(10) etc to look at the file, I am unable to process it - I tried using input[23:67] (where 'input' is the name of the file I am working with) but python complained that I was using an unslicable type. So my question is how do I my file into a format where I am able to use RE's in python to play with it? When I input.read(10) it looks like: x05\x0A\x45\xA1... That is raw hex data. All suggestions most welcome. - Rodney From lenpfe at fastol.com Sun Oct 7 09:50:30 2001 From: lenpfe at fastol.com (Lenny) Date: 7 Oct 2001 06:50:30 -0700 Subject: Newbie question about running scripts References: <3BBEC9FB.8080709@sneakemail.com> Message-ID: I would like to thank Chris and Joshua for the information they gave me. I forgot to let you know I am using Win98SE. I tried adding the "set Path" string to the autoexe. file and restarting. By doing this, I was able to run the string I wrote once I rewrote it in Notepad and used explorer to get into the folder that it is stored in. It would not run unless I had that folder open. Is that the way it should work. Just for the heck of it to see if that did anything, I removed it from autoexe. and the file would not run. I tried downloading a lesson plan from a kids summer camp. This included step by step lesson plans and sample programs and activites. I was doing well until they got to the import command. I downloaded the mod, then tried writing the program but it immediately came back with"unable to locate file". Am I supposed to load mods to a particular folder or list an additional path in the autoexe. file for the location of these mods, or do I need to have the folder opened on the desktop in the background in order for it to see it. I appologize for these questions that I know are far below what you are normally used to answer, but I cant seem to find this info out from any of the tutorials or help folders. It seems that most of the tutorial assume that you know this already or you are having an experienced programmer help you. Please let me know if I should use another message board for these basic questions. I dont want to use up space on your site if these questions are inappropriate. I am kinda looking to you all as my "experienced programmers". As I said before, I had programmed with COBOL, BASIC, and FORTRAN in the early 80's but things have gotten much more advanced since then. Again, Thank you for all your help with these questions. From tim.one at home.com Wed Oct 17 22:57:09 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 17 Oct 2001 22:57:09 -0400 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: <200110170724.f9H7OL326427@mbuna.arbhome.com.au> Message-ID: [Anthony Baxter] > What is the process likely to be for this? > > The major component of work would be deciding which patches and fixes > were deserving of 2.1.2, yes? How is the decision made - those things > that are only bugfixes? Only "critical" bugfixes? Or is it a matter of > trawling the CVS commit messages since 2.1.1... ? The bugfix release process is the topic of Aahz's PEP 6, who may have believed that titling it "Bug Fix Releases" was enough clue : http://python.sf.net/peps/pep-0006.html > Anthony, curious. Just think how cool Anthony, Patch Czar would look on your business cards! not-to-mention-personal-ads-ly y'rs - tim From James_Althoff at i2.com Mon Oct 22 13:29:56 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Mon, 22 Oct 2001 10:29:56 -0700 Subject: Dictionary from list? Message-ID: Tim Peters wrote: >dictionary() is a constructor in 2.2, and I spent a lot of time worrying >about what kind of arguments it should take. I believe a flat [k,v,...] >list would have been the most useful thing to accept; but it had to at least >accept a mapping object, and that's all it accepts (for now). Everyone's >first thought seems to be that dictionary() should accept a list of (key, >value) tuples -- but there are few core functions that produce such a list >(dict.items(), zip() and some cases of map() are all that pop to mind), so I >had a hard time picturing a good use for that (yet another way to spell >dict.copy() is not a good use). Since there was a stalemate on the pros and cons of overloading/confusing the dictionary constructor ... isn't this a reasonable place to take advantage of the new 2.2 class methods and provide: dictionary.newFromList([k,v,...]) (or some other shorter/more-appealing method name of preference)? I think class methods provide a nice way to introduce alternative "constructors" without having to add special modules for the sole purpose of serving as a home for module-based constructor-esque functions and without having to add more builtin functions, etc. (Guilty as charged of more Smalltalk-hardwiring-of-the-brain thinking ;-) Jim From Jeremy.Jones at peregrine.com Thu Oct 11 12:04:48 2001 From: Jeremy.Jones at peregrine.com (Jeremy Jones) Date: Thu, 11 Oct 2001 09:04:48 -0700 Subject: SocketServer - multithreading Message-ID: <55720746FFC5D4118A3B00508BF9B80A012900CD@atlgaexc3.harbinger.com> On Thu, Oct 11, 2001 at 11:38:45AM -0400, Oleg Broytmann wrote: >Wow! The code looks VERY familiar to me! :))) Actually, I think that you are the one I "borrowed" it from. Good piece of code. That's why I used it. > Do you run the program in the background? It is possible that the >program stuck upon printing the request, because background programs >usually disallowed to write to console. Upon printing the program receives >SIGTSTOP signal and stops. > Do not write to stdout from a background process. I am running it in the foreground unless the SocketServer module pushes it to the background somewhere (which I can't see that it does by looking through the module). I start it like this: [jjones at mahler get_request]$ ./pyserver.py Waiting... And there is one instance of it running: [jjones at mahler socket]$ ps -ef | grep server jjones 12790 12570 0 12:16 pts/19 00:00:00 python -O ./pyserver.py jjones 12796 12610 0 12:17 pts/21 00:00:00 grep server [jjones at mahler socket]$ But when I hit it with the first client, I guess it spawns a child process: [jjones at mahler socket]$ ps -ef | grep server jjones 12790 12570 0 12:16 pts/19 00:00:00 python -O ./pyserver.py jjones 12800 12790 0 12:18 pts/19 00:00:00 python -O ./pyserver.py jjones 12805 12610 0 12:18 pts/21 00:00:00 grep server [jjones at mahler socket]$ Anyway, I'm not running in the background..... Jeremy From db3l at fitlinxx.com Thu Oct 25 00:36:05 2001 From: db3l at fitlinxx.com (David Bolen) Date: 25 Oct 2001 00:36:05 -0400 Subject: Critical sections and mutexes References: Message-ID: writes: > I do see your point, but I think of it from the opposite point of view: a > newbie learning about threads would be thrilled to get a simple > producer/consumer program working to play around with. Once they see how > cool it is, then you move on to teaching them about locking problems, > mutexes, etc. And hopefully, they played with it enough already to get > bitten by a problem so that they really understand the lesson. If that's what the newbie wants, they should be pointed to an appropriate class (like the Queue) that specifically provides simple producer/consumer behavior with all the appropriate locking hidden within the class. I don't think suggesting that they just write their own without such locking (which can lead to believing it isn't necessary) is to their benefit, even if it makes the problem seem simpler. To my mind, the benefit Python has for newbies is that the typical housekeeping required of multithreading applications _and_ the types of synchronization that is a fact of life for such applications are very simple to use. And a number of useful classes are provided for common scenarios within multithreaded applications. BTW, one of the reasons I feel strongly about this is that a very large percentage of my applications over the years have been multithreaded (and I'm a big fan of having the support in the language such as Python does) and there are just some things you don't skimp on, if you want to do it write, maintainably and with assured behavior over time. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From huaiyu at gauss.almadan.ibm.com Wed Oct 17 17:37:46 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 17 Oct 2001 21:37:46 +0000 (UTC) Subject: PEP: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: I've been writing this for several evenings. It's not polished, but IMHO it solves most of the problems discussed in this thread. So here it goes. :-) PEP: Statements in Control Structures 1. INTRODUCTION: One long-standing complaint about Python syntax is that it distinguishes expressions from statements and does not allow statements in the condition part of flow control structures, so it is not allowed to write while x = next(): process(x) if x = next(): process(x) This is to avoid troublesome bugs like if x = 0: ... when the programmer actually wanted if x == 0: ... However, this restriciton of not allowing statements in conditions also has its own costs, mainly in increased verbosity which sometimes in themselves lead to other subtle bugs. This issue is not an artificial one because the current control-flow structures do not represent the most general case naturally. In this proposal we present an extended syntax of control structures that allow statements before conditions, without the risk of problems associated with mixing statements with expressions. The new syntax is if ( stmt ; )* expr : suite ( elif ( stmt ; )* expr : suite )* [ else : suite ] while ( stmt ; )* expr : suite [ else : suite ] Compared with Python's current syntax if expr : suite ( elif expr : suite )* [ else : suite ] while expr : suite [ else : suite ] the new syntax allows simple statements in control structures just before the conditions, separated by ";". Essentially the same syntax was proposed by Kevin Digweed [1] in 1999, which received some favorable comments but was subsequently lost in a discussion with over-generalization (see the relevant thread). This author, unaware of the earlier discussion, proposed it independently in 2000 [2]. Reference [1] was recently mentioned by Hamish Lawson [3]. 2. PROPOSAL: The extension allows zero or more simple statements separated by ";" to be placed between the keywords "while", "if" and "elif" and their corresponding conditions. These statements are executed in sequence at the point just before the condition expression is to be evaluated. In the following, statements := (simple_statement ";" )* simple_statement In other words, they are what can be written in one line separated by ";" in the current syntax. 2.1. The if-elif-else structure is extended to the following "if" [ statements ";" ] expression ":" statements ( "elif" [ statements ";" ] expression ":" statements )* [ "else:" statements ] The semantics of if stmts1; expr1: stmts2 elif stmts3; expr2: stmts4 elif stmts5; expr3: stmts6 else: stmts7 is equivalent to the semantics of stmts1 if expr1: stmts2 else: stmts3 if expr2: stmts4 else: stmts5 if expr3: stmts6 else: stmts7 2.2. The while-else structure is extended to the following "while" [ statements ";" ] expression ":" statements [ "else:" statements ] The semantics of while stmts1; expr1: stmts2 if expr2: break stmts3 else: stmts4 is equivalent to the semantics of __hidden_variable = 0 while 1: stmts1; if not expr1: break stmts2 if expr2: __hidden_variable = 1 break stmts3 if not __hidden_variable: stmts4 del __hidden_variable where __hidden_variable is a variable not used in this block. 3. RATIONALE: 3.1. General looping structure. A general looping structure, commonly known as loop-and-half, looks like A loop: B if not C: break D E If B is empty, this can be represented in current Python as A while C: D E The new syntax allows the more general case even when B is not empty A while B; C: D E Putting B between "while" and the condition is not just syntactical sugar, as will be shown in the following. 3.2. Better break-else interaction: Python allows an else-clause for the while statement. The naive way of writing the general loop-and-half in current Python interferes with the else clause. For example, while x = next(); not x.is_end: y = process(x) if y.is_what_we_are_looking_for(): break else: raise "not found" cannot be written in this naive version: while 1: x = next() if x.is_end: break y = process(x) if y.is_what_we_are_looking_for(): break else: raise "not found" This is because there are two breaks that have different semantical meanings. The fully equivalent version in current syntax has to use one extra variable to keep track of the breaks that affect the else __hidden_variable = 0 while 1: x = next() if x.is_end: break y = process(x) if y.is_what_we_are_looking_for(): __hidden_variable = 1 break if not __hidden_variable: raise "not found" del __hidden_variable The improvement of the new syntax is quite obvious. 3.3. Flatter conditional structures: A general nested "if-else-and-a-half" structure is like A if B: C else: D if E: F else: G if H: I else: ... which can be written in the new syntax as if A; B: C elif D; E: F elif G; H: I else: ... The advantage of this syntax pattern is similar to that of "elif" itself, namely to transform a nested branching structure into a flat branching structure. Using flat structure in place of nested structure is in keep with one of the good tradition of Python. 4. EXAMPLES: 4.1. Action needed before condition: while x = get_next(); x: whatever(x) 4.2. Condition does not need to be a method of an object in assignment: while line = readline(); 'o' in line: line = process(line) if 'e' in line: break else: print "never met break" 4.3. Has similar power to C's for statement for (start; action, end; incr) { do_something; if (cond) break; do_other; } can be written as start while action; not end: do_something if cond: break do_other incr 4.4. More complex example: if x = dict[a]; x: proc1(x) elif x = next(x); x.ok(): proc2(x) elif x.change(); property(x): proc3(x) ... The equivalent in the current syntax is not flat: x = dict[a] if x: proc1(x) else: x = next(x) if x.ok(): proc2(x) else: x.change() if property(x): proc3(x) else: ... Alternatively, it requires at least a two level hack with "while": while 1: x = dict[a] if x: proc1(x) break x = next(x) if x.ok(): proc2(x) break x.change() if property(x): proc3(x) break ... break It is seen that the new syntax remove substantial amount of clutter, thereby increasing readability and expressiveness. 5. ISSUES: 5.1. Syntax errors: This structure is safe against single typing errors: - missing colon would be detected at newline because of keywords - missing last expression will be detected at the colon, because the condition must be an expression - mistype = for == in expression will be detected - mistype == for = in statement will be detected - mistype : for ; will be detected as missing : - mistype ; for : will be detected as mutiple : 5.2. Obfuscation: The new syntax does not diminish the distinction between statements and expressions. Specifically, the structure if S1; S2; E: S is built upon statements and expressions according to the syntax of "if". It does not mean that (S1; S2; E) itself becomes a magical super-expression. The same is true for "elif" and "while". Consequently, without changing the syntax of "for", the following is meaningless and not allowed for S1; S2; a in B: C Since the change is only in the syntax of "if", "elif" and "while", not in the fundamentals of expressions and statements, there is not much more chance of obfuscation than existing syntax. 5.3. Compatibility: This extention is fully backward compatible, because the extended syntax is currently invalid syntax. 5.4. Generality: Guido in comment about Kevin's proposal mentioned [4] that this is not general enough to allow short circuit conditions: while (x = f(); x) and (x.y = g(); x.y): "whatever" which is equivalent to the following (assuming no training "else"): while 1: x = f() if not x: break else: x.y = g() if not x.y: break "whatever" With the extension of "if" and "elif" this could be written in quite readable form: while 1: if x = f(); not x: break elif x.y = g(); not x.y: break However, there is indeed a complication when there is both a "break" and an "else". A general solution would either require allowing super expressions like (S1; S2; E) or a new keyword, such as "until", or two flavors of "break". It is unclear whether such situations are important enough for such more radical changes. Note that the similar problem with "if" is already solved: if ((x = f.readline(); x) and (y = f.readline(); y)): print x, y can be written as if x = f.readline(); not x: pass elif y = f.readline(); not y: pass else: print x, y 6. ALTERNATIVES: We show that the following alternatives have more problems than the proposed extension. 6.1. Allowing special assignment in conditions. For example: while a:=next(): process(a) This has many problems: 6.1.1. It does not allow other actions before conditions, such as while x.get_next(): x: process(x) So it does not really solve the problem. On the other hand, if arbitrary statement were allowed in an expression with some syntactical trick then it would completely blur the distinction between statement and expression. 6.1.2. It does not allow for arbitrary expressions in condition, like while x=next(); some_property_of(x): ... The proposal if some_property_of(x:=next()): ... is ugly, and if it were to become a general rule, it would allow much obfuscations a = f(b:=3+g(not c:=4) - c) * b(c) 6.2. Regarding (S1; S2; S3; E) as an expression that can appear in other places. This is more general than current proposal and solve one more problem: short-circuit condition in "while" loop with "break" statement and "else" clause (see 5.4 above). However, it appears to be too general than is necessary, and easily lead to obfuscations such as x = f((y = (x = a; x = {x.next(): x.next()}; x); y[0].next())) The problems associated with statements in expressions appear to far outweigh the benefit in the one particular example of 5.4. 6.3. Using iterators: In Python 2.2, it is possible to write for line in file: if line=='end': break process_line(line) in place of while line=file.readline(); line != 'end': process_line(line) However, this does not solve the problem we are considering completely. It is more suitable for objects that are naturally used (and reused) in iterations so that it is profitable to create iterators for them. It is not practical to define an iterator for every action that might go before a condition: while char=file.readline()[3]; char != 'x': process(char) while string = raw_input(prompt): not string.startswith("n"): process(string) It does not solve the nested else-if problem, either. 6.4. Conditional expression, like (if a then b else c). This solves a completely different problem. It is not related to this proposal. 6.5. Repeat action before and after loop: line = file.readline() while line: do_something() line = file.readline() This is a maintenance liability - it is easy to go out of sync. This does not apply to the "if" structure, either. 6.6. An alternative syntax might be val = dict1[key1]; if val: process1(val) else: val = dict2[key2]; if val: process2(val) else: val = dict3[key3]; if val: process3(val) ... This looks more consistent and logical. One problem of putting keyword "if" in the middle of a line is that it is less prominent, although syntax-colored editors do help. However, similar syntax is not right for while-loops: A; while B: C gives the impression that A is only done once. So this alternative is not tenable. 7. IMPLEMENTATION: I do not know enough about the possible implementation. It does not appear to have fundamental difficulties. The changes are likely to occur at places where statements are parsed. 8. SUMMARY The extension allowing sequence of simple statements between keywords "while", "if", "else" and their corresponding condition expressions solves several problems. It makes code more readable in many situations, without risk of obfuscation in other situations. It compares favorably to several alternatives, both existing and proposed, because, essentially, the original problem is about statements before condition expressions in control structures. It is not a demand to blur the distinction between statements and expressions, and should not be solve in such a fashion. 9. REFERENCES [1] http://groups.google.com/groups?hl=en&selm=78naok%242ed%241%40nnrp1. dejanews.com [2] http://www.geocities.com/huaiyu_zhu/python/ififif.txt [3] http://mail.python.org/pipermail/python-list/2001-October/068332.html [4] http://groups.google.com/groups?q=g:thl2213523209d&hl=en&selm=199901271725. MAA14695%40eric.cnri.reston.va.us (The google references are longer than my news client allows, so they are split to mutiple lines.) From ignacio at openservices.net Tue Oct 23 04:32:56 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 23 Oct 2001 04:32:56 -0400 (EDT) Subject: Few questions about new features in Python 2.2 In-Reply-To: <7da8d8f8.0110230006.36933486@posting.google.com> Message-ID: On 23 Oct 2001, sebastien wrote: > Why iterators can't be copied? > ----------------------------- > Something like: > MyIter = iter([1,2,3,4]) > MyIter2 = iter(MyIter) > doesn't provide a copy but a reference to the iterator > And that: > import copy > MyIter2 = copy.copy(MyIter) > Just doesn't work > > But you can have the need to save an iterator position when you want > to try something and > retry other thing if the first attempt fail. > For sample I think Tim recipe for removing duplicate would need copy > to work with iterator. An iterator/generator isn't an object; it's a concept of object behavior. It's a side effect of an actual object "yield"ing a value. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From vlindberg at verio.net Wed Oct 3 17:25:16 2001 From: vlindberg at verio.net (VanL) Date: Wed, 03 Oct 2001 21:25:16 GMT Subject: Optional type declaration? Message-ID: <3BBB82DE.9080607@verio.net> Hello, Does anyone know whether optional type declaration has been considered for python? An optional type declaration system for python could be implemented that would use either a specially formatted portion of the docstring or a new keyword that could specify type at compile time. This information could be used to supplement documentation of a function, to optimize code at compile time, and to move python toward being a fully compiled as well as interpreted language. Although one of python's strengths is its dynamism, that dynamism does not come without cost -- specifically the cost for run-time determination of type. Previous postings to this newsgroup have highlighted this as one of the most expensive operations in python. Run-time type evaluation can also be detrimental when the programmer wishes to restrict the types passed in as arguments to a function. While this is currently possible by importing type and then comparing the type of the passed-in object with a target type, this seems somewhat ungainly. Rather, it would seem to me that a more 'natural' approach would be that taken by some other interactive/compiled languages: optional type declaration. This would have several advantages: 1. Compile-time knowledge of type, with the attendant possible optimizations. 2. Type restriction as above, with a possibly more natural syntax. 3. No loss of dynamism or compatibility -- if no type were specified, run-time evaluation would still occur. What got me thinking about this was AMK's 'grouch' tool , in which docstrings contain type information so that his ZODB maintains consistency. The following is quoted from the link above: "Grouch works by parsing sets of type declarations embedded in class docstrings. The declarations look like this: class PhysicalValue (MXBase): """A physical value: a number (or range value) tied to a physical unit that automatically performs unit conversion when arithmetic operations are performed. Instance attributes: value : float | RangeValue the numeric part of the physical value unit : PhysicalUnit the unit part (may be None for inherently unitless values, in which case the instance just acts like a number) """ The type declaration language is straightforward. In the above example, the value attribute must be either a Python float or an instance of the RangeValue class, and unit must be an instance of the PhysicalUnit class." By using variable assignments and similar type information, optionally included with each class and function declaration, the type of almost every object in a typical program could be determined by a recursive-descent parser, possibly opening the door for optimizations, including compiling python to machine code in the same fashion as lisp. If these optimizations were possible, just including these type declarations in the standard library would tend to speed up many programs, as a lot of code is just stringing together standard library functions. In addition, the docstring declarations would serve as additional documentation for the functions. This is not intended to be a PEP or anything, but I wanted to raise the issue as I saw it, to see if it sparked any disussion. Feel free to rip apart what I said to any degree. -V- From gabriel_ambuehl at buz.ch Thu Oct 18 05:47:54 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Thu, 18 Oct 2001 11:47:54 +0200 Subject: Converting a tuple to an argument list for a method? Message-ID: <1262235424.20011018114754@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello, I'm messing with the XMLRPC implementation from PythonWare which makes the arguments to the request available as tuple but the method's I want to call expect a normal argument list as their parameters. So xmlprc delivers: xmlrpcparam=(param1, param2, param....) which won't work for method(param1, param2, param3) because the tuple only counts as one argument. So is there a possibility to use the tuple (which hasn't got a fixed length cause different methods on the server need different numbers of arguments, else it would be easy to just do method(xmlrpcparam[0], xmlrpcmethod[1])) to form an argument list for the methods on the server? Currently less important: is there a way to use named arguments with xmlrpc so that the server could decide whether the format of the clients request is valid? Any comments would be greatly appreciated. Best regards, Gabriel  -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO86XPcZa2WpymlDxAQGUeQgAkOu3OT1zf1dYQLXap9JYBS2ATb3GEnya ZR+dai1Jr0UqqXmj1Iwo05x+1EVfGMBA5P75QfIu5xDkyevnPmOIXIwkqUPSFMjO Sl1FAN5fphzOXOnsRTvrnm3Q52kCe/Z2uBCu+r5nV799erj0F/ftnWFSRhUm95Y8 YRypkiUtK76q/yGMQWJST3w9zrOffzgcgACzg0bNW3V7vr3c0CYcMPD4vuO79CXn I7pUDQDdqZzMEfQwIWnMWToWwvZuAd8NoNmKnfzaJj2mnv7PFQXR24UPpdpLkHho rAQLU1eaSFzNvZz+nfEXzqVscP4rZ39nVbYwsoe2R6g8e+ZvrbvwFw== =5MhN -----END PGP SIGNATURE----- From tim.one at home.com Sat Oct 27 21:58:21 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 27 Oct 2001 21:58:21 -0400 Subject: interpreter crashes In-Reply-To: <7xzo6cd1hw.fsf_-_@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > A few times I've had Python 2.1.1 crash on me for no apparent reason. > Cursory inspection of the core dump doesn't show much-- the > interpreter seemed to be innocently evaluating something. Chances are > something (maybe a reference count) got corrupted sometime earlier and > eventually set off the crash. The one out-of-the-ordinary thing I may > have been doing was repeatedly reloading modules as I debugged them. > But I'm not even sure about that. Are you running with any extension modules (incl. any sort of GUI pkg)? Are you running threads? Refcount problems in extension modules (others' or especially your own) are historically the #1 cause of crashes. Thread races seemingly unique to a specific platform are #2. Cyclic gc caused a few nasty cases when it was new, but we don't see reports of crashes due to that anymore. > Anyone got any suggestions? Without a reproducible problem in hand, or even a characterization of one, guess . > Want to see the core dumps? If you open a SoureForge bug report, someone may. > How frequently does this type of thing happen? Essentially never for most people; rarely to frequently for people tickling some specific unpopular bug. If you're seeing crashes frequently, you *are* doing something most people aren't (else we'd be getting other reports, and we aren't), or may even have a flaky memory chip (etc). > If Python is in the habit of crashing randomly, that may make it > inadvisable to write long-running servers that need to stay up. Perhaps > it's more appropriate to write servers Apache-style, forking new > processes and reinitializing every so often. If Python were in the habit of crashing randomly, I'd advise not using it at all. From jmcwill at tridog.com Thu Oct 11 15:11:11 2001 From: jmcwill at tridog.com (Jason McWilliams) Date: Thu, 11 Oct 2001 13:11:11 -0600 Subject: upload file using cgi on Win2k IIS References: Message-ID: <3BC5EECF.FE2F76E5@tridog.com> Ignacio Vazquez-Abrams wrote: > > On Thu, 11 Oct 2001, Jeff Shannon wrote: > > > Jason McWilliams wrote: > > > > > > > > Here is something interesting. I can upload .txt and .doc files no > > > problem, > > > no matter what the size. Things die when trying to upload .gif or .zip > > > or .tgz > > > or other binaries similar. Some of it gets uploaded, but only a small > > > portion? > > > > > > I am at a loss now. > > > > A wild guess--is it possible that the binary files have an embedded EOF-character? > > IIS (or Windows) could conceivably see that embedded character and decide that it is > > indeed at the end of file, even though there's more data in the real file.... > > The odd thing is that the file should be base64-encoded before it's sent to > the server, so it NULLs and EOFs shouldn't be visible to the server. > > Jason, instead of importing cgi.py, write the raw data from sys.stdin to a > file and check to see if that's the case. Turns out that I didnt have windows handling Python scripts with the -u arg... to handle binary data unbuffered. This fixed the problem by setting .py files to use python -u %s %s on IIS. (thanks to another person on the list!) Although, I am trying to Freeze the program into a .exe file. In that case it acts the same as before. Not sure how to get freeze to do the same as python -u. Thanks for the help! > > -- > Ignacio Vazquez-Abrams > > "As far as I can tell / It doesn't matter who you are / > If you can believe there's something worth fighting for." > - "Parade", Garbage > > -- > http://mail.python.org/mailman/listinfo/python-list From max at alcyone.com Thu Oct 25 13:45:54 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 25 Oct 2001 10:45:54 -0700 Subject: Conditional expressions (again) References: Message-ID: <3BD84FD2.6D1D902B@alcyone.com> Dale Strickland-Clark wrote: > However, we already have conditional assignment, which I've used > several times when I've really had to: > > x = (b, c)[a] > > Obviously this assumes a is logic 0 or 1 which you can force if > necessary: > > x = (b, c)[a != 0] But this doesn't have the short-circuiting properties of the conditional operator which was listed as one of the main project. (I usually use conditional operators for simple selections between two values, anyway.) > > You can also use the 'iif' function that appears in a number of > languages: > > def iif(test, true, false): > if test: > return true > else: > return false Or just operator.truth. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Nobody's waited longer than me / To come clean \__/ Jaki Graham Product's Quake III Arena Tips / http://www.bosskey.net/ Tips and tricks from the absolute beginner to the Arena Master. From mike at unicorn-fs.com Mon Oct 22 10:22:07 2001 From: mike at unicorn-fs.com (Mike Peat) Date: Mon, 22 Oct 2001 15:22:07 +0100 Subject: Writing to SdtErr References: <1003757605.11708.0.nnrp-14.d4f0f8ae@news.demon.co.uk> Message-ID: <1003760498.13203.0.nnrp-14.d4f0f8ae@news.demon.co.uk> Thanks Michael - that did the biz on both counts! Mike Peat "Michael Hudson" wrote in message news:u8ze36bit.fsf at python.net... > "Mike Peat" writes: > > > Can anyone tell me how to: > > > > 1) Turn of the Python "Traceback" output, or make it less verbose? > > sys.excepthook = something_else > > > 2) Write (print) to the StdErr channel instead of StdOut? > > print >> sys.stderr, "foo" > > Both of these require a new-ish Python (not sure which release, > sorry). > > An example of both: > > >>> def eh(type, value, tb): > ... print >> sys.stderr, "Exception: ", type > ... > >>> sys.excepthook = eh > >>> 1/0 > Exception: exceptions.ZeroDivisionError > > Cheers, > M. > > -- > I have long since given up dealing with people who hold idiotic > opinions as if they had arrived at them through thinking about > them. -- Erik Naggum, comp.lang.lisp From info at devshare.de Thu Oct 25 06:22:39 2001 From: info at devshare.de (Johannes Gamperl) Date: Thu, 25 Oct 2001 12:22:39 +0200 Subject: Learing Python, Newbie question References: Message-ID: Hello Markus, > import os > if os.path.exists("path_fo_file"): > print "yes" thx a lot .. this works fine. Do you know if there is a coditional operator in python ( ?: ) e.g. if os.path.exists("gbook.txt"): db_first = 0; else: db_first = 1; db_first = ( os.path.exists("gbook.txt") ) ? 0:1; So long ... Hannes From dummy at net-es.dk Sun Oct 28 16:28:38 2001 From: dummy at net-es.dk (Per Jensen) Date: Sun, 28 Oct 2001 22:28:38 +0100 Subject: PIL - Image.open() problem Message-ID: Hi everybody. It seems I don't know Python well enough yet. I have a problem with Python Imaging Library which probably is simple. Only not for me! Problem: I have a method in a classe which sometimes open a JPEG image, and at other times do not. When it doesn't work it is always in the same mode, which leads me to think that I somehow don't initialize the PIL library. The imports and method is shown below together with the stacktrace. Any pointer as to where to look for the error is most welcome Regards. Per Jensen -------------------------------------------- import os, sys, traceback import string from node import Node from functions import printTraceback, trim, xmlString from PIL import Image def getImage(self): "Return a PIL Image object of picture" try: if self.filename is None: raise NE_NoFilename("Filename is None") if self.filename == "": raise NE_NoFilename("Filename is empty") if self.picture is None: print "Opening picture: \"" + self.filename + "\"" self.picture = Image.open(self.filename) print "Opening succeeded!" return self.picture except: printTraceback() return None Result: --------------------------------------------- Opening picture: "1.jpg" Traceback (most recent call last): File "./picture.py", line 155, in getImage self.picture = Image.open(self.filename) File "/var/tmp/python-imaging-root//usr/lib/python2.0/site-packages/PIL/Image.py", line 871, in open prefix = fp.read(16) AttributeError: read -------------------------------------------- From myohe+USENET at redhat.com Fri Oct 12 04:29:13 2001 From: myohe+USENET at redhat.com (Michael Lee Yohe) Date: Fri, 12 Oct 2001 03:29:13 -0500 Subject: OT: This is a useless thread. (was: YOU ARE ALL GAY!) References: Message-ID: <3BC6A9D9.2030608@redhat.com> Please quit cross-posting this big piece of excrement. -- Michael Lee Yohe (myohe+USENET at redhat.com) Software Developer, Engineering Services Red Hat, Inc. QUIPd 0.12: -> It is better to deserve honors and not have them than to have them -> and not deserve them. -> - Mark Twain (1835-1910) From logiplexsoftware at earthlink.net Mon Oct 8 16:24:10 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Mon, 8 Oct 2001 13:24:10 -0700 Subject: Why so few Python jobs? In-Reply-To: <200110081939.f98Jdl0W001553@ratthing-b246.strakt.com> References: <9psq5u$agh$1@panix3.panix.com> <200110081939.f98Jdl0W001553@ratthing-b246.strakt.com> Message-ID: <01100813241001.01842@logiplex1.logiplex.net> On Monday 08 October 2001 12:39, Laura Creighton wrote: > > Stock C++ has better libraries than Python? > > Irrelevant. What counts is that they either already have the excellent > C++ libraries or they know where they are and how to get them. And then it takes 2 weeks to learn them, hundreds of extra lines of code to use them, and good luck debugging them. I think I'd use SWIG so I could get efficient use out of those excellent libraries. I'd have to agree that some of the Python libraries are not the best (although I've not had much trouble with them), however I'd be curious to see a comparison of actual development times of an application using C++ with its "excellent" libraries vs. Python with its "fragmentary, incomplete..." libraries. Although libraries are extremely important, I think that anyone who focuses too much on any one aspect of a particular language is not seeing the big picture - the real test is in the development and maintenance costs of an application. In this regard, Python is the clear winner. I'll write my own damn libraries ;-) Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From gs at styrax.com Wed Oct 17 06:04:05 2001 From: gs at styrax.com (Garry Steedman) Date: Wed, 17 Oct 2001 10:04:05 +0000 Subject: Desperate help required for Python assignment In-Reply-To: <602c058e.0110162347.268591ce@posting.google.com> Message-ID: <3BCD5795.27964.365D240@localhost> Nachiket, you might want to rethink your approach: mailing lists are not there to provide resources to assist you in the avoidance of your education. you could expect some sympathy if you at least made some effort! cheers, Garry On 17 Oct 2001, at 0:47, Nachiket wrote: From: nachiket_gole at hotmail.com (Nachiket) Subject: Desperate help required for Python assignment Organization: http://groups.google.com/ To: python-list at python.org Date sent: 17 Oct 2001 00:47:07 -0700 > I am new to Python doing a crash course in University. I have a > assignment to submit in two days the specifications of which are: > 1.Write a script in python which maps a set of linked webpages. It > should take the URL as a command line argument, retireve the page, > extract the URL's of pages linked to by the page in question and store > them in a data structure for the page. It should then repeat this > with other linked pages to a depth of 5. It should visit each page > only once. 2.The script should also be able to take -L as a command > line argument and that being the case should only follow links on the > same server as the current site. 3.The script should also record the > titles of links in the documents eg Mysite -- > http://mysite.com > 4.Finally all this has to be displayed as a tree for eg >python > mytest.py "some url" > http://..... > + http://........ > + http://....... > + http://...... > Please can some of the Gurus on this newsgroup help me out with a > working solution as with my limited knowledge i am no position to > handle this assignment in two days. > > Regards > -- > http://mail.python.org/mailman/listinfo/python-list +-------------------------------------------+ Garry Steedman mailto:gs at styrax.com Styrax Associates http://www.styrax.com/ "The Good Man has no shape." +-------------------------------------------+ From barry at zope.com Sat Oct 27 20:06:13 2001 From: barry at zope.com (Barry A. Warsaw) Date: 27 Oct 2001 20:06:13 -0400 Subject: multipart mime References: <9r8lur$7oqsi$1@hades.rz.uni-sb.de> <9r8nfl$7g6$1@mail1.wg.waii.com> Message-ID: >>>>> "MF" == Martin Franklin writes: >> Hi, I'm looking for a module which is suited to handle >> multi-part mime-mails. Is somehting like this available ? I >> browsed the module-index on www.python.org, but did not find >> anything apropriate. Greetings, Uwe. MF> http://sourceforge.net/projects/mimelib/ MF> now called email and part of standard python 2.2 And btw, if you download and install email-0.94, it is API compatible with the version in Python 2.2, but it works in every version of Python since 2.0. -Barry From ykingma at accessforall.nl Wed Oct 10 14:30:12 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Wed, 10 Oct 2001 19:30:12 +0100 Subject: Sockets References: Message-ID: <3BC493B0.F9B2251E@accessforall.nl> Hugo, have a look at: http://mail.python.org/pipermail/python-list/2001-May/040807.html Regards, Ype Hugo Martires wrote: > > My server need to send 2 strings separeted: > s1= 'xxx' > s2= 'yyy' > > My client must received like this: > rec1= 'xxx' > rec2= 'yyy' > > The problem is that the Client received s1 and s2 in one only string. > > How can i received in 2 separeted variables ? > > Tanks -- email at xs4all.nl From logiplexsoftware at earthlink.net Tue Oct 2 13:15:56 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 2 Oct 2001 10:15:56 -0700 Subject: test - don't read... In-Reply-To: <3bb9e35a.695404@news.newsguy.com> References: <3bb9e35a.695404@news.newsguy.com> Message-ID: <01100210155602.02289@logiplex1.logiplex.net> On Tuesday 02 October 2001 09:19, Owen F. Ransen wrote: > don't read Aarrrgh. Too late. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From markus at schabi.de Wed Oct 3 03:51:45 2001 From: markus at schabi.de (Markus Schaber) Date: Wed, 3 Oct 2001 09:51:45 +0200 Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> Message-ID: <1645950.f946Emhk5q@lunix.schabi.de> Lee Morgan schrub: > Cliff Wells writes: >> >> Actually, unless you were embedding Python in your app I don't think >> this is true, since _your_ source would not in fact contain any GPL'd >> code. Additionally, I expect the Python libraries would fall under >> LGPL so using them would not "infect" your code. >> > > This may be off topic but what does it mean to release a python > module/package under LGPL? > > An import is not a linking ... so does it mean I can't use it in a > commercial product? I'd like to think I could use it if I released any > changes I made to the module/package - but I don't think thats the > case. I would think that importing in python is some kind of linking. Dynamically and at run-time, but it is some sort of linking. markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From phr-n2001d at nightsong.com Tue Oct 9 18:32:47 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 15:32:47 -0700 Subject: executing a variable? References: <87ofnf9owk.fsf@toadmail.com> Message-ID: <7xhet8jvg0.fsf@ruckus.brouhaha.com> Look up the "exec" statement in the docs. However, that's not really the best way to implement a settings file. I think there's a library module already for loading config files. From michael at rcp.co.uk Tue Oct 16 05:36:24 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Tue, 16 Oct 2001 09:36:24 +0000 (UTC) Subject: [Python-Dev] conditional expressions? References: <3bcbfda6$0$42081$edfadb0f@dspool01.news.tele.dk> Message-ID: "Anders J. Munch" wrote in news:3bcbfda6$0$42081$edfadb0f at dspool01.news.tele.dk: > Quick, what does this snippet do if return_as_map is true? > > return if return_as_map then {'A':a,'B':b} else a,b > > Rather than open up a new venue of obfuscation possibilities in > Python, I'd go for mandatory parentheses around the conditional > expression. Nah. Go for "maximal munch", I can't think of anything wrong with that. The above expression then returns the dictionary (only). From piet at cs.uu.nl Thu Oct 18 05:59:53 2001 From: piet at cs.uu.nl (piet at cs.uu.nl) Date: 18 Oct 2001 11:59:53 +0200 Subject: opening sys.stdout in binary mode on Windows? References: Message-ID: >>>>> Bill Janssen (BJ) writes: BJ> Hi. BJ> On Windows, I'd like to have stdout opened in binary mode before BJ> writing to it. I've tried things like BJ> sys.stdout = os.fdopen(sys.stdout.fileno(), "wb") BJ> without success. Anyone know the trick? msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From piet at cs.uu.nl Mon Oct 8 06:23:41 2001 From: piet at cs.uu.nl (piet at cs.uu.nl) Date: 8 Oct 2001 10:23:41 GMT Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> Message-ID: <9prurd$56a$2@samos.cs.uu.nl> >>>>> Carsten Gaebler (CG) writes: CG> Hi there! CG> Given a string CG> s = "%(foo)s %(spam)s" CG> and two dictionaries CG> d1 = {"foo": "bar"} CG> d2 = {"spam": "eggs"} CG> how would you apply d1 and d2 to s without modifying or explicitly CG> copying one of the dicts? I mean, I don't like to CG> d3 = dictionary(d1) CG> d3.update(d2) CG> s = s % d3 class DictSet: def __init__(self, *dicts): self.dicts = dicts def __getitem__(self, attr): for d in self.dicts: if d.has_key(attr): return d[attr] raise KeyError, attr s = "%(foo)s %(spam)s" d1 = {"foo": "bar"} d2 = {"spam": "eggs"} print s % DictSet(d1,d2) -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From cheah at comline.com.my Thu Oct 18 03:13:20 2001 From: cheah at comline.com.my (Alec D. Cheah) Date: 18 Oct 2001 00:13:20 -0700 Subject: Help Need In Coding Message-ID: <4783f0eb.0110172313.ef7755e@posting.google.com> i'm using Python 2.1 How do verified from input the variable entered is a file or a path and how do you check whether it exist or not?? now let say ... i just specified input a value "xxx.java" i just want to check whether it exist in a current directory or subdirectory of current directory depending on how many directory level you have. if not a file then check whether it a directory???? In this case it will do a searching base on the input value. Help... Newbie on Python.... From s713221 at student.gu.edu.au Sun Oct 28 02:49:48 2001 From: s713221 at student.gu.edu.au (Joal Heagney) Date: Sun, 28 Oct 2001 17:49:48 +1000 Subject: Why doesn't this simple Curry-like implemention work? References: <7xd7389qiw.fsf@ruckus.brouhaha.com> Message-ID: <3BDBB89C.A7F95E9E@student.gu.edu.au> Paul Rubin wrote: > > "Michael R. Head" writes: > > > # for some reason this function doesn't work in python 1.5.2. > > def curry(f, p): > > return lambda x: apply(f, p, x) > > > > I've looked up on the list better class-based implementations, and am > > using one of them, but I'm curious why this doesn't work (when the > > curried function is called, f becomes unknown). (I'm looking for a > > reason in the language spec). I'm supposing that lamda isn't storing > > the reference to its inputs -- which it seems it should -- is this > > correct? > > I thought the third arg to apply was a keyword arg dictionary. > Is that really what you meant? I tried mucking around with things, and came up with the following, error message and all >>> def test(value1,value2): ... print value1,value2 ... >>> def curry(f, p): ... return lambda x: apply(f, (p,x), {}) ... >>> b = curry(test, "hello") >>> b("goodbye") Traceback (most recent call last): File "", line 1, in ? File "", line 2, in NameError: global name 'f' is not defined Is this the reason for the class based curry functions? -- Joal Heagney is: _____ _____ /\ _ __ __ _ | | _ ___ | /__\|\ || ||__ |\ || |___|/_\|___] | / \ \_||__ ||___| \_|! | | \ \ ! From ldw at us.ibm.com Wed Oct 24 11:07:05 2001 From: ldw at us.ibm.com (Larry Whitley) Date: Wed, 24 Oct 2001 10:07:05 -0500 Subject: None References: <9r4b95$suc$1@news.rchland.ibm.com> Message-ID: <9r6lep$tdg$1@news.rchland.ibm.com> Here's the traceback requested: C:\Projects\Pecos\Traces>analyze3 u:\trc45\pecos\ c:\projects\pecos\traces\ ('crusader091101.zip', 'crusader091101 .dat', 'crusader091101.a3.txt') Traceback (most recent call last): File "C:\Projects\Pecos\Traces\analyze3.py", line 372, in ? main() File "C:\Projects\Pecos\Traces\analyze3.py", line 365, in main process( localPath + files[1], localPath + files[2] ) # process the file File "C:\Projects\Pecos\Traces\analyze3.py", line 336, in process pc.runningReport( None, riostream ) # to stdout UnboundLocalError: local variable 'None' referenced before assignment Here's the relevant section of code in the neighborhood of the error: if pc.endCond != "": pc.summarizeData() riostream = pc.rio() pc.runningReport( fout, riostream ) # to file pc.runningReport( None, riostream ) # to stdout The method runningReport() looks like this: def runningReport(self, fout, riostream): print >>fout, "%8d" % self.startCycn, "%8d" % self.endCycn, "%6d" % (self.endCycn - self.startCycn), \ "%8s" % self.command, "%10x" % self.startAddr, "%10x" % self.endAddr, "%4d" % self.nBytes, \ "%8s" % self.endCond, riostream My idea was to setup the method to print to file and by substituting None for the file object, let the same method send the output to standard out. Thanks for the help, Larry "Larry Whitley" wrote in message news:9r4b95$suc$1 at news.rchland.ibm.com... > I want to have a methode of a class that will take the argument of a file > object that has previously been opened for write and be able to call it, > directing it's output to a file, or directing the output to standard output. > > def output(self, fout): > print >>fout, self.thing1, self.thing2, self.thing3 > > In the calling program I say: > > object.output( fout ) # print to file > object.output( None) # print to standard output > > But Python complains that None is a variable that has not been previously > set. Can someone explain? I thought None was the empty object reference. > Where have I gone astray? > > Larry > > From johnroth at ameritech.net Tue Oct 9 11:35:44 2001 From: johnroth at ameritech.net (John Roth) Date: Tue, 9 Oct 2001 08:35:44 -0700 Subject: Curious assignment behaviour References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> <9psk9s$rbk@newton.cc.rl.ac.uk> Message-ID: "Richard Brodie" wrote in message news:9psk9s$rbk at newton.cc.rl.ac.uk... > > "John Roth" wrote in message news:ts3hb2p7dbh7b5 at news.supernews.com... > > > > > Pascal uses := > > > > > > Nope. Pascal is like Python, it doesn't have an assignment operator. > > > > But it does have a *syntax* that means assignment, just like Python. > > I believe that is what the poster had in mind. > > It's probably true that the use of := for assignment and = for equality is > less prone to error for those unused to C-like languages. I think it's a > lost battle though unless we want another controversial language change > in Python 3 ;) It would be controversial only if we wanted to change the statement assignment operator. That's not going to happen; I would be against it in any case since = is pretty much the standard, and has been since Fortran. Pascal (and I belive Algol) is out of the mainstream on this issue. However, I think := makes a good choice for an expression assignment operator. It needs to be different from both the statement assignment operator and the equality operator. It also can't be in use for an extended assignment. Any controversy would be over whether we actually should add this functionality to Python. I could argue that both ways. John Roth From BrainFletcher90 at hotmail.com Sun Oct 21 12:28:01 2001 From: BrainFletcher90 at hotmail.com (Brian Fletcher) Date: Sun, 21 Oct 2001 17:28:01 +0100 Subject: Fwd: Play a hilarious prank call Message-ID: Computerized prank call service. Wind-up your mates! Click on this link. www.pranks.gq.nu (Works on any phone in the UK including mobiles) Or call 020 8387 8754 (24hrs) From sholden at holdenweb.com Fri Oct 12 10:14:45 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 12 Oct 2001 10:14:45 -0400 Subject: multi command session through a socket References: <77udstcmaialm2920c7svj4eap6k9f25d4@4ax.com> Message-ID: <3SCx7.28787$I83.421328@atlpnn01.usenetserver.com> "Nomad" wrote ... > On 12 Oct 2001 12:28:02 GMT, Gordon McMillan > wrote: [ ... ] > > and it keeps alive until I give a 'quit' command. All I have to do > now is work out how to implement a decent timeout function. > Consider Tim O'Malley's timeoutsocket module. Can't currently find Tim's original URL, but the copy at http://www.fiction.net/blong/programs/python/timeoutsocket.py looks reasonably up to date. regards Steve -- http://www.holdenweb.com/ From robin at stop.spam.alldunn.com Thu Oct 11 12:20:34 2001 From: robin at stop.spam.alldunn.com (Robin Dunn) Date: Thu, 11 Oct 2001 16:20:34 GMT Subject: Problems With ColourSelect Box Inside A wxDialog References: <9e7d101d.0110081223.32a8217e@posting.google.com> <7hm8st4ul1p0i93r8ut2bpmetm8k7p7q6s@4ax.com> Message-ID: > 17:28:19: There were memory leaks. > 17:28:19: ----- Memory dump ----- > 17:28:19: wxColour at $1378E58, size 16 > 17:28:19: > 17:28:19: > > Am I missing something still, or is this something I should post to > the wxPython bug tracker? The fix is in CVS. http://cvs.wxwindows.org/cgi-bin/viewcvs.cgi/wxPython/wxPython/lib/coloursel ect.py?rev=1.8&content-type=text/vnd.viewcvs-markup -- Robin Dunn Software Craftsman robin at AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython! From aleax at aleax.it Fri Oct 12 04:36:18 2001 From: aleax at aleax.it (Alex Martelli) Date: Fri, 12 Oct 2001 10:36:18 +0200 Subject: webserver performance (was Re: Why so few Python jobs? (and licenses)) References: <7xwv2418xk.fsf@ruckus.brouhaha.com> Message-ID: <9q6a1u$ke9$1@serv1.iunet.it> "Paul Rubin" wrote in message news:7xwv2418xk.fsf at ruckus.brouhaha.com... ... > > Of course, in order to avoid this discussion entirely, you could use a > > web platform written in Python (and therefore practically immune to > > "malloc errors"), such as Zope, WebWare, or > STYLE="ruthless">twisted.web, available at > > http://twistedmatrix.com! ;-) > > These programs are all way too slow for a high-traffic site on the > hardware we used back then. Even with today's hardware, it would be Have you actually _measured_ the performance and scalability of a web server architecture based on asyncore/asynchat, versus more traditional architectures based on multiple processes and/or multiple threads? I haven't done it systematically at all, but the few informal attempts I did do have consistently amazed me. Event-driven programming seems to have extremely interesting characteristics in this sense. Alex From skip at pobox.com Tue Oct 23 17:55:57 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 23 Oct 2001 16:55:57 -0500 Subject: None In-Reply-To: <3bd5db1e$1@brateggebdc5.br-automation.co.at> References: <3bd5db1e$1@brateggebdc5.br-automation.co.at> Message-ID: <15317.59245.947324.961370@beluga.mojam.com> >>> None = 17 >>> print None 17 Werner> Strange... is it intended that you can assign to None? It's just another symbol. Werner> In short, is this a bug or a feature? Neither. You can also override sys.stdout, sys.args, __builtins__.int, etc. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From logiplexsoftware at earthlink.net Fri Oct 12 12:39:59 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 12 Oct 2001 09:39:59 -0700 Subject: YOU ARE ALL GAY! In-Reply-To: References: Message-ID: <01101209395900.07109@logiplex1.logiplex.net> On Thursday 11 October 2001 21:59, Geoffrey Pointer wrote: > I made an offhand comment about a truly weird and wonderful message, the > guy is obviously a poet or something, which I will continue to regret for To me, the text looks like the output of one of those AI programs that statistically analyse English text and then attempt to create a commentary based upon the frequency of adjacent words. As an aside, I don't mind OT threads. I enjoy talking to the people on this list and don't feel I need to jump to another ng if the subject goes a little OT. None of this "Eyes forward!!! You vill discuss only Python!!! Crack!!!!" Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From mail at mikemccandless.com Sun Oct 14 15:30:21 2001 From: mail at mikemccandless.com (Michael McCandless) Date: Sun, 14 Oct 2001 19:30:21 GMT Subject: bug in builtin compile function? Message-ID: <3BC9E807.75FB715A@mikemccandless.com> Hi, If I have a file, foo.py, that has a syntax error in it, and I create a separate bar.py that tries to load and compile the contents of foo.py like this: s = open('foo.py').read() compile(s, 'foo.py', 'exec') Then I get a traceback like this: Traceback (innermost last): File "bar.py", line 3, in ? compile(s, 'foo.py', 'exec') File "", line 2 ajdsf: ^ SyntaxError: invalid syntax My question is: why does the SyntaxError say: File "", line 2 instead of: File "foo.py", line 2 ? I told compile that the file was "foo.py", so, why doesn't it say that in the SyntaxError instead of saying ? Thanks. Mike From phr-n2001d at nightsong.com Tue Oct 30 17:21:02 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 30 Oct 2001 14:21:02 -0800 Subject: Proposed mmap module modifications References: Message-ID: <7xady8g46p.fsf@ruckus.brouhaha.com> If you're submitting mmap patches to 2.2, how about including some kind of semaphore mechanism or a test-and-set function, to allow using mmap for shared memory between processes. I know there's an shm module around somewhere with those features, but it's not part of the standard distribution. From tim.one at home.com Wed Oct 31 00:49:02 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 31 Oct 2001 00:49:02 -0500 Subject: How smart are Semaphore Objects? In-Reply-To: <32cedc66.0110292253.5eaaca31@posting.google.com> Message-ID: [Matthew D. Wood] > I firmly believe that when coding a function, object, program or > whatever, one should assume that every other function, ... is either > stupid or out to get you. With this mind-set, I'm curious as to how > (idiot or mean-person) proof semaphore objects are. Not at all, nor are they intended to be, nor will they ever be. The safest synchronization gimmick in Python is in the std library: see the docs for the Queue class. Second-safest is threading.Condition, when used as intended. Safest of all is to recompile Python without thread support. but-event-that-won't-make-you-immune-to-anthrax-ly y'rs - tim From sholden at holdenweb.com Thu Oct 18 08:26:46 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 18 Oct 2001 08:26:46 -0400 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) References: Message-ID: "Anthony Baxter" wrote ... > >>> "Tim Peters" wrote > > The bugfix release process is the topic of Aahz's PEP 6, who may have > > believed that titling it "Bug Fix Releases" was enough clue : > > Ah, that cunning "hidden in plain sight" approach. Who'd have thought. > Gets *me* every time... > It still doesn't cover the process of deciding what would go in the > patch release... I know that I'd be happier upgrading to 2.1.2 than > 2.2 in the next couple of months - and given the peasants-are-revolting > sentiment of c.l.py at the moment, I doubt I'm the only one... > It's only the fatc that they're revolting that identifies them as peasants. Seriously, though, there are many good reasons why you might not want to upgrade, including having a large and varied hardware base and wanting to keep all Pythons roughly in step. Hence, lowest common denominator, usually what you started with on your first machine (though personally I removed 1.5.2 from my last system three or four moths ago, I'm now thinking of re0installing it on a test machine for compatibilty testing). > How would this sound as a first cut at a what-goes-in-and-what-stays: > > a) bugfixes. Kind of essential in a bugfix release. > b) no new modules, no new packages. Definitely. > c) no new methods on classes, unless they're bugfixes. Indeedy. > d) if the bug fix relies on some 2.2-ism, then it's either rewritten, > or ignored and relnoted > Yes, but are there any such? This all sounds about right. So, how does it feel to be the new patch czar? regards Steve -- http://www.holdenweb.com/ From maxmcorp at worldonline.dk Mon Oct 29 13:17:03 2001 From: maxmcorp at worldonline.dk (maxm) Date: Mon, 29 Oct 2001 19:17:03 +0100 Subject: AskMerlin, your AI expert system guru oracle advisor References: <3BDC649F.6EB6680B@earthlink.net> <3BDC9411.18C441FA@earthlink.net> Message-ID: "Ron Stephens" wrote in message news:3BDC9411.18C441FA at earthlink.net... > x = (self._getGoogleHits(self.question + ' ' + reply)) > y = (self._getGoogleHits(reply)) > > I am not sure what the significance of the (self.question + ' ' +reply) is. > Specifically, what is the significance of the two quotation marks in the > middle? Doe sit just ad a space between the two strings (question and > reply), or does it do something else? I tried the program without hte two > quotes and it didn't seem to change the operation noticeably. The program works by sending questions and possible answers to google at the same time. Then it counts the hits for each combination. "Who wrote linux" "Linus Torvalds" "Bill Gates" "Steve Jobs" So question + ' ' + reply: "Who wrote linux Linus Torvalds" (49,800 hits) "Who wrote linux Bill Gates" (23,900 hits) "Who wrote linux Steve Jobs" (18,000 hits) and question + reply: "Who wrote linuxLinus Torvalds" (did not match any documents) "Who wrote linuxBill Gates" (did not match any documents) "Who wrote linuxSteve Jobs" (did not match any documents) These searchstrings are not as accurate as the first, but as the program is all about statistical probabilities, you can get sensible reples though your input data is not as good as it can be. In this case it is no god though, and multiChoiceGuesser would just return index 0 "Linus Torvalds". Purely by luck. regards Max M From gh_pythonlist at gmx.de Sat Oct 20 18:14:35 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 21 Oct 2001 00:14:35 +0200 Subject: Smtplib module In-Reply-To: <3BD20BAE.6346.7693E0@localhost>; from export@bmatrading.com on Sat, Oct 20, 2001 at 11:41:34PM +0200 References: <3BD20BAE.6346.7693E0@localhost> Message-ID: <20011021001434.A1525@lilith.hqd-internal> On Sat, Oct 20, 2001 at 11:41:34PM +0200, A wrote: > Hi, > I want to use smtplib module for sending emails. Is there any way how > I can test a return code, generated by this module, to see if an email > was accepting for delivery, for example? No, there is no way to do this. But this is a "feature" of SMTP, not of Python's smtplib. The only way smtplib is concerned is if the "RCPT TO" command fails with 550 "no such user". Then the sendmail method already returns the address as not deliverable to. But at least my mailserver (Postfix) doesn't return a 550 in such cases. There are some other possibilties, but these will only work in some relatively rare cases, (finger, SMTP delivery receipts and possibly others). But all of these are out of the scope of Python's smtplib. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From aa at bb.cc Wed Oct 24 13:07:10 2001 From: aa at bb.cc (Károly Ladvánszky) Date: Wed, 24 Oct 2001 19:07:10 +0200 Subject: Question: CPython Message-ID: <3bd6f0f1_3@corp-goliath.newsgroups.com> What is CPython and where is it available? Thanks for any help, K?roly ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From skip at pobox.com Tue Oct 16 12:08:17 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 11:08:17 -0500 Subject: Python, Unix sendmail, and multiple recipients In-Reply-To: <81F59ACE9063D511A5BB0002B328D226511596@il93exm20.css.mot.com> References: <81F59ACE9063D511A5BB0002B328D226511596@il93exm20.css.mot.com> Message-ID: <15308.23409.310320.827375@beluga.mojam.com> Randy> Can anyone give me an example of how to invoke the Unix sendmail Randy> in Python, and send an email message to more then one recipient Randy> (two people, for example)? How about: fwd = os.popen('/usr/sbin/sendmail -odb -t', 'w') fwd.write('To: skip at mojam.com\n') fwd.write('To: Randy.L.Kemp at motorola.com\n') fwd.write('Subject: Hey there!\n') fwd.write('\n') fwd.writelines(body) where "body" is a list of newline-terminated strings. Any particular reason why you don't want to use smtplib? -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From gh_pythonlist at gmx.de Sat Oct 20 22:11:06 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 21 Oct 2001 04:11:06 +0200 Subject: Smtplib module In-Reply-To: <9qscfm.3vv746r.1@kserver.org>; from sheila@spamcop.net on Sun, Oct 21, 2001 at 12:32:45AM +0000 References: <3BD20BAE.6346.7693E0@localhost> <9qscfm.3vv746r.1@kserver.org> Message-ID: <20011021041105.A3163@lilith.hqd-internal> On Sun, Oct 21, 2001 at 12:32:45AM +0000, Sheila King wrote: > On Sun, 21 Oct 2001, Gerhard H?ring wrote: > > :On Sat, Oct 20, 2001 at 11:41:34PM +0200, A wrote: > :> Hi, > :> I want to use smtplib module for sending emails. Is there any way how > :> I can test a return code, generated by this module, to see if an email > :> was accepting for delivery, for example? > : > :No, there is no way to do this. But this is a "feature" of SMTP, not of > :Python's smtplib. > > I am very surprised at this response. > > This same inquiry was also posted to the Python Tutor mailing list, and > I answered in the affirmative. Here is the message I posted (with a > minor correction: [... about the sendmail method of the smtplib.SMTP class] Sheila, you're of course right. My thinking was too complicated, again. But you'll only recognize if the local delivery to the mail server failed, not when relayed mail's delivery fails. I did never find the local failures particularly interesting, because I usually know which users exist on my SMTP server in advance. I was thinking about the general problem of finding out if an email address exists and if mails get delivered. This is of course much more complex, and AFAIK not solvable in the general case. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From shmi at indosat.net.id Wed Oct 24 18:38:12 2001 From: shmi at indosat.net.id (indosatnet) Date: Thu, 25 Oct 2001 05:38:12 +0700 Subject: form like foxbase Message-ID: Dear python expert, What module should I use to develop an application accesing mysql / postgresql such that the form entering / editing data is just like the form in fox base, i.e user can move around using up,down cursor (without using any intranet application) thanks! shmi From offer at sgi.com Thu Oct 11 17:56:50 2001 From: offer at sgi.com (Nhi Vanye) Date: 11 Oct 2001 21:56:50 GMT Subject: Moving from mod_python to Zope ? Message-ID: <9q54j2$qt1ue$1@fido.engr.sgi.com> I have a website (that includes a bunch of images in a MySQL database) that is completely mod_python. I'd like to move this to Zope (if for no other reason than I'd like to learn Zope). Are there any gottas ? How would you go about architecting/designing it ? At the moment its functional rather that OO. Would it make more sense to leave the images where they are or migrate them to the Zope's object store (I'm unhapping with the current image retrival code, so even if I left them in MySQL I'd want to redo that to use PIL rather than pre-stored images at different resolutions) ? One of the features I'd really like is to provide a means where I could allow others to add new images (with keyword description of the content) after authentication without breaking anything else. richard. -- Richard Offer Technical Lead, Trust Technology. "Specialization is for insects" __________________________________________http://reality.sgi.com/offer/ From jorjun at mac.com Wed Oct 10 11:20:59 2001 From: jorjun at mac.com (jorjun) Date: Wed, 10 Oct 2001 16:20:59 +0100 Subject: Financial modules for Python References: <3BC17870.EB8CC191@mac.com> <7xsnct2oqs.fsf@ruckus.brouhaha.com> Message-ID: <3BC46759.59CC8453@mac.com> > Now what about the truncated series? Well, 1+z+z**2+...+z**59 is > equal to X - (z**60)*X, where X is the infinite sum above. So that > payment stream is worth $5*[1/(1-z) - z**60/(1-z)] = $5*((1-z**60)/(1-z)). > For i=6%, substituting back, z**60 is about .74, and the total is > about $5*51.72, or $258. Thanks, maths is not my forte, I managed a mere pass at A-level :) I entered the following code based on your formula, I think I got last after the truncated series bit. #------------------------------------------------------------------ # Parameters years = 1 # Investment period pay = 5 # Monthly payment an_rate= 6.0 # Percentage rate # Calculation of future value months = years * 12 i= an_rate/1200 # Rate as fraction per month z= 1/(1+i) x= 1/(1-z) fv = pay* (x - z**months/(1-z) ) print """Years = %(years)d, Monthly payment =%(pay)d, \ Annual Interest =%(interest)f, \ Future value=%(future)f""" \ % {'years':years, 'pay':pay, 'interest':an_rate, 'future':fv} #------------------------------------------------------------------ Output Years = 5, Monthly payment =5, Annual Interest =6.000000, Future value=259.920943 Years = 1, Monthly payment =5, Annual Interest =6.000000, Future value=58.385134 (This last I would expect to be at least 60, since 12 payments of 5 made, so must have errored!) From loredo at astro.cornell.edu Wed Oct 10 15:17:46 2001 From: loredo at astro.cornell.edu (Tom Loredo) Date: Wed, 10 Oct 2001 15:17:46 -0400 Subject: how to create a def that has the behaviour like a built-in keyword... References: Message-ID: <3BC49EDA.668E1F1@astro.cornell.edu> If you are working interactively, LazyPython might work for you: http://www.idyll.org/~n8gray/code/files/deep_lazyANN.txt Peace, Tom Loredo From pez at apocalyptech.com Tue Oct 16 10:34:05 2001 From: pez at apocalyptech.com (CJ Kucera) Date: Tue, 16 Oct 2001 09:34:05 -0500 (CDT) Subject: maximum recursion in "re" module? In-Reply-To: <15307.35253.91335.661869@beluga.mojam.com> from "Skip Montanaro" at Oct 15, 2001 08:13:25 PM Message-ID: <200110161434.JAA17701@scortch.unisrv.net> On Mon Oct 15 20:13:25 2001, Skip Montanaro wrote: > If you can get by without it, I think that will cure your problems. If not, > you can always import pre instead: > > import pre as re Yeah, that did the trick. Thanks! -CJ WOW: Rapacious | A priest advised Voltaire on his death bed to apocalyptech.com/wow | renounce the devil. Replied Voltaire, "This pez at apocalyptech.com | is no time to make new enemies." From James_Althoff at i2.com Thu Oct 11 14:30:47 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Thu, 11 Oct 2001 11:30:47 -0700 Subject: Why not 3.__class__ ? Message-ID: Guido van Rossum wrote: >Marcin, I don't understand why you care so much about being able to >write 3.foo. It's painful to fix in the lexer, and probably leads to >less useful error messages if someone makes a mistake in a float >literal (e.g. "3.e 0"). And I see zero use for it: in practice, you >will never ask for 3.foo -- you'll ask for x.foo where x happens to ?contain the value 3. Here's another example of invoking an attribute on a literal: C:\>python Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> >>> class Spam: pass ... >>> s = Spam() >>> x = Spam() >>> >>> isinstance(x,s.__class__) 1 >>> x = 'abc' >>> isinstance(x,''.__class__) 1 >>> x = 100 >>> isinstance(x,0 .__class__) 1 >>> If you generally want to know if x is the same kind of instance as y, then isinstance(x,y.__class__) seems to be a reasonable idiom. Given that, it's nice to use the same idiom when y is a builtin type, as in isinstance(x,''.__class__) isinstance(x,0 .__class__) isinstance(x,[].__class__) isinstance(x,().__class__) isinstance(x,{}.__class__) instead of using a second idiom for builtins import types isinstance(x,types.IntType) . . . A second negative against the latter idiom: our experience with Jython has been saddled with significant performance issues doing imports. Generally, we try to avoid unnecessary imports whenever possible. At a higher level it seems that if you want to do an "isinstance" test, it is nicer to use the class object that you already have "in hand" (or can easily get to with a literal constant) rather than having to know about an external module (for which you need to know the name and package path) with class names (that you also need to know) -- especially given that the general case, isinstance(x,y.__class__), is something one needs to use in some circumstances in any case. In the end, (0).__class__ works -- it justs adds unfortunate "line noise" and momentarily invokes the "is it an expression or is it a tuple" confusion 0 .__class__ works, too -- but is somewhat fragile because of the required white space Still, these are better than nothing. :-) Jim From kosh at aesaeion.com Mon Oct 15 23:50:48 2001 From: kosh at aesaeion.com (kosh at aesaeion.com) Date: Mon, 15 Oct 2001 21:50:48 -0600 (MDT) Subject: Playing non-MPG movies with Pygame In-Reply-To: Message-ID: On Tue, 16 Oct 2001, Rainer Deyke wrote: > Attempting to decode the video one pixel at a time in Python will not yield > acceptable performance. This is like say there is some water in the ocean, olympus mons is a lump on the ground or that a 1 gigaton nuclear warhead explodes. All are technically correct but are way understated. Attempting to decode a video like that in python would probably end up taking the next 10K years to decode 30 mins of video. ;) Designing the webpages of tomorrow http://webme-eng.com Designing the MMORPGS of tomorrow http://worldforge.org From arturs at iidea.pl Wed Oct 3 06:39:55 2001 From: arturs at iidea.pl (Artur Skura) Date: 3 Oct 2001 10:39:55 GMT Subject: Nicer Tkinter on UNIX? Message-ID: [It's not particularly Pythonish question, but I thought you might know] I like Tkinter because it's standard. But there is a big but. While on Windows it looks great, on unices it makes kids laugh. Not that it's particularly ugly, but quite awkward and not up to the aesthetic standards people expect now. Is there a way to make Tkinter use KDE/GTK themes on unices? Or change the interface in any way? (I don't consider wx... stuff, as it forces users to install additional software). Regards, Artur -- http://www.wolneprogramy.org From gh_pythonlist at gmx.de Mon Oct 29 13:36:20 2001 From: gh_pythonlist at gmx.de (Gerhard Haering) Date: Mon, 29 Oct 2001 19:36:20 +0100 Subject: win32clipboard for python 2.2.1? In-Reply-To: <20011029182627.53586.qmail@web21108.mail.yahoo.com> References: <20011029182627.53586.qmail@web21108.mail.yahoo.com> Message-ID: <20011029193619.A20767@lilith.hqd-internal> On Mon, Oct 29, 2001 at 10:26:27AM -0800, David Brady wrote: > Hello, > > I'm trying to track down win32clipboard for Python > 2.1.1. I have the version of Python from > www.python.org, I assume that's the "CNRL" version? I > have tracked win32clipboard to the win32all package by > Mark Hammond; who directs traffic to ActiveState.com. > > Phew. It looks like the latest release of win32all > for CNRL is for Python 1.5.2 or 1.6... > > ...does anyone know if win32clipboard is available for > Python 2.1.1? Chances are this is what you want: http://www.activestate.com/Products/ActivePython/win32all.plex The win32all version for Python 2.1 should work for 2.1.1, too. -- Gerhard From richard at bizarsoftware.com.au Thu Oct 4 02:50:16 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Thu, 4 Oct 2001 16:50:16 +1000 Subject: test - don't read... In-Reply-To: References: Message-ID: <0110041650160B.04291@ike> On Thursday 04 October 2001 16:36, Ignacio Vazquez-Abrams wrote: > On Thu, 4 Oct 2001, Owen F. Ransen wrote: > > On Wed, 03 Oct 2001 22:36:06 -0000, Robert Amesz > > > > wrote: > > >Owen F. Ransen wrote: > > >> don't read > > > > > >don't write > > > > don't respond > > don't care But you told me you loved me! From newgene at bigfoot.com Tue Oct 2 10:39:24 2001 From: newgene at bigfoot.com (newgene) Date: 2 Oct 2001 07:39:24 -0700 Subject: list.append problem? References: Message-ID: Thank you all. I see again why python is pure object-oriented language and understand why list can not be initiated as the classic variables. Chunlei From logiplexsoftware at earthlink.net Tue Oct 2 12:50:10 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 2 Oct 2001 09:50:10 -0700 Subject: list remove In-Reply-To: <20011002203427.D21313@phd.pp.ru> References: <1165F677B8C4D411B71C0008C791EC4A71E3AA@N0225IDC1.oss.level3.com> <20011002203427.D21313@phd.pp.ru> Message-ID: <01100209501001.02289@logiplex1.logiplex.net> On Tuesday 02 October 2001 09:34, Oleg Broytmann wrote: > > NEVER, I said NEVER modify the list while running through it! > Yes, sort of like pulling the carpet you are standing on. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From madsdyd at challenge.dk Mon Oct 1 07:16:58 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 13:16:58 +0200 (CEST) Subject: Problem with linking embedding C application In-Reply-To: <9p9h2l$24o$1@kermit.esat.net> Message-ID: On Mon, 1 Oct 2001, Olivier Deme wrote: > Hi, > > We have written an application written in C, which invokes sometimes the Python > interpreter for executing Python methods. > > So, I am trying to statically link our application with libpython*.*.a., but this result in various > undefined symbols (see below). > > Now, it looks like I am missing symbols defined in the math and posix > thread library! I don't understand this since we are not using any > symbols defined in these libraries. No, but the statically linked python lib is. > Could anybody tell me what is going on and how I can fix this problem? I am having similar troubles, although mine is trying to identify these libs automatically. (Using autoconf - you replied to this thread, I can see.) > > /lib/libpython.a(posixmodule.o): In function `posix_tmpnam': > /home/odeme/Python-2.1.1/./Modules/posixmodule.c:4212: the use of `tmpnam_r' is dangerous, better use `mkstemp' > /lib/libpython.a(posixmodule.o): In function `posix_tempnam': > /home/odeme/Python-2.1.1/./Modules/posixmodule.c:4168: the use of `tempnam' is dangerous, better use `mkstemp' These are just (annoying) warnings from stuff used in the belly of python. > /lib/libpython.a(floatobject.o): In function `float_pow': > /home/odeme/Python-2.1.1/Objects/floatobject.c:532: undefined reference to `pow' > /lib/libpython.a(dynload_shlib.o): In function `_PyImport_GetDynLoadFunc': > /home/odeme/Python-2.1.1/Python/dynload_shlib.c:86: undefined reference to `dlopen' > /home/odeme/Python-2.1.1/Python/dynload_shlib.c:94: undefined reference to `dlerror' > /home/odeme/Python-2.1.1/Python/dynload_shlib.c:99: undefined reference to `dlsym' > /lib/libpython.a(thread.o): In function `PyThread_start_new_thread': > /home/odeme/Python-2.1.1/Python/thread_pthread.h:135: undefined reference to `pthread_create' > /home/odeme/Python-2.1.1/Python/thread_pthread.h:159: undefined reference to `pthread_detach' > /lib/libpython.a(posixmodule.o): In function `posix_openpty': > /home/odeme/Python-2.1.1/./Modules/posixmodule.c:1754: undefined reference to `openpty' > /lib/libpython.a(posixmodule.o): In function `posix_forkpty': > /home/odeme/Python-2.1.1/./Modules/posixmodule.c:1785: undefined reference to `forkpty' > /lib/libpython.a(complexobject.o): In function `_Py_c_pow': > /home/odeme/Python-2.1.1/Objects/complexobject.c:139: undefined reference to `pow' > /home/odeme/Python-2.1.1/Objects/complexobject.c:143: undefined reference to `exp' > /home/odeme/Python-2.1.1/Objects/complexobject.c:144: undefined reference to `log' > /home/odeme/Python-2.1.1/Objects/complexobject.c:146: undefined reference to `cos' > /home/odeme/Python-2.1.1/Objects/complexobject.c:147: undefined reference to `sin' > collect2: ld returned 1 exit status I think that you may need to add at least -lpthread -lm -lutil to you ld line? I have a machine, where I need to do: -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm to be able to link with python. The annoying thing is, that it is very hard to determine this in general. At least I am not aware of any way to do it. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/J d- s+:+ a- C++ UL++++ P++ L++> E(++) W+ N w-- X- !tv b+ DI++ e++> h-- ------END GEEK CODE BLOCK------ From emile at fenx.com Tue Oct 30 12:47:34 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Oct 2001 09:47:34 -0800 Subject: os.listdir References: <3BDEE6C6.8E96DBF3@ncsa.uiuc.edu> Message-ID: <9rmqbn$u2k1j$1@ID-11957.news.dfncis.de> "Randy Heiland" wrote in message news:3BDEE6C6.8E96DBF3 at ncsa.uiuc.edu... > I get this: > > >>> for file in os.listdir('mydir'): > ... print file > ... > f100.dat > f1.dat > f2.dat > > but would like this: > f1.dat > f2.dat > f100.dat > > What's the trick? > You mean, besides putting the files out there with sort-appropriate names? I'd build a dictionary of names specific to the requirements then sort it. eg, make it look like: >>> d = {('f',1):'f1.dat', ('f',2):'f2.dat', ('f',100):'f100.dat'} then: >>> ds = d.items() >>> ds.sort() >>> for k,d in ds: print d f1.dat f2.dat f100.dat >>> HTH, -- Emile van Sebille emile at fenx.com --------- From ws-news at gmx.at Thu Oct 25 07:38:30 2001 From: ws-news at gmx.at (Werner Schiendl) Date: Thu, 25 Oct 2001 13:38:30 +0200 Subject: None References: <3bd5db1e$1@brateggebdc5.br-automation.co.at> Message-ID: <3bd7fa75$1@brateggebdc5.br-automation.co.at> Hi, thanks for the thorough explanation. It is pretty obvious once thought about it a second time. It is only a bit confusing, because one rather expects None to be a literal or constant value like NULL in C or true and false in C++. At least if you normally use a C or C++ compiler ;-) thanks Werner "Ken Seehof" wrote in message news:mailman.1003881804.28186.python-list at python.org... > > Hi, > > > > just had to try that out... > > > > >>> print None > > None > > >>> None = 17 > > >>> print None > > 17 > > >>> > > > > Strange... is it intended that you can assign to None? > > > > In short, is this a bug or a feature? > > > > thanks > > Werner > > When you understand why this is exactly what you would expect, your > understand of python will jump to the next level :-). > > 'None' is a name, not a keyword. Assigning to None simply attaches a new > object to the name 'None'. So it's not as scary as it looks. You are not > changing the value of an internal variable as you might expect. In other > languages such as C/C++ (which have early binding), assignment causes data > stored in a variable to change. In python (and other languages with late > binding), assignment binds a name to some data without changing the data > that the name used to refer to. This is probably the most important concept > for python programmers to understand if they come from a C/C++ background. > > >>> x = None > >>> print x > None > >>> None = 'spam!' > >>> print None > spam! > >>> print x > None > > Get it? > > - Ken > > > From asencio at mitre.org Mon Oct 29 14:02:20 2001 From: asencio at mitre.org (Angel Asencio) Date: Mon, 29 Oct 2001 14:02:20 -0500 Subject: detecting and creating directories Message-ID: <3BDDA7BC.8CF7C891@mitre.org> Greetings: I found the module that has the command to make directories, but I have not been lucky finding a way to check for the existance of a directory (so it is not there, I can create it). Any pointers? Thanks, -- -Angel From phr-n2001d at nightsong.com Sun Oct 28 01:19:52 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 27 Oct 2001 22:19:52 -0700 Subject: interpreter crashes References: <7xzo6cd1hw.fsf_-_@ruckus.brouhaha.com> <3BDB8F30.FEE9004C@engcorp.com> Message-ID: <7xd738qr2f.fsf@ruckus.brouhaha.com> Peter Hansen writes: > > How frequently does this type of thing happen? If Python is in the habit > > of crashing randomly, that may make it inadvisable to write > > long-running servers that need to stay up. Perhaps it's more > > appropriate to write servers Apache-style, forking new processes and > > reinitializing every so often. > > Not necessary if your system is stable. Python can run indefinitely > unless you have hit some obscure bug. As a small trivial example > of its stability, we have had our Intranet server running > under Zope (on Redhat 7.0) for the last 84 days straight, being > used daily and extensively by at least twenty people. No troubles. This is encouraging to hear. However, obscure bugs do exist. I may be hitting a bug in some extension module or in something having to do with module reloading. > We are also developing applications based on Python which will > be expected to run potentially for years without being shut down ... > and I have no concerns about this (at least none related to Python! ;-). This is my concern--if they're EXPECTED to run for years without shutdown, but they crash unexpectedly instead, that can be a big problem. Best is to not have them crash, but next-best is to plan ahead for occasional crashes. So I'm wondering what I need to do. Note that if you're planning to run a server for years without attention, besides UPS's you'll also want to have some kind of hardware watchdog timer on the hosting computer--another form of crash tolerance. From max at alcyone.com Wed Oct 31 12:47:58 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 09:47:58 -0800 Subject: newbie question References: <9rpbr2$us4bd$1@ID-11957.news.dfncis.de> Message-ID: <3BE0394E.9C4E92BF@alcyone.com> Emile van Sebille wrote: > " 1" wrote in message > news:yXVD7.6251$QL2.175221 at e3500-atl1.usenetserver.com... > > > When I got to run the file (by typing python hello.py)i get this > > error > > message: > > > > >>> python hello.py > > SyntaxError: invalid syntax > > >>> ... > > You've got a syntax error in the file, probably extra spaces No, look closely -- he's typing "python hello.py" in the Python interpreter itself. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From claird at starbase.neosoft.com Wed Oct 17 12:29:16 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 17 Oct 2001 11:29:16 -0500 Subject: pure 16-bit DOS app References: <1003306634.200241@cswreg.cos.agilent.com> Message-ID: In article , Oleg Broytmann wrote: >On Wed, Oct 17, 2001 at 10:17:12AM +0200, Michael Armbruster wrote: >> I read many articles in the grup and the web, but till now I have not found >> the real solution for my problem. >> I would like to have a pure standalone DOS 16-bit app built out of >> a python prog with inserted c-code but I don't know how to do this. >> perhaps you could help me, > > Near to be impossible. 16bit DOS just doesn't have enough memory for >Python. Can you use 32bit DOS (DOS Extender)? . . . Sure it's possible, Oleg--for a sufficiently low value of "Python". While I wonder what the questioner *really* wants, he might start with 1.2: -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From brueckd at tbye.com Wed Oct 24 22:29:51 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 24 Oct 2001 19:29:51 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: Message-ID: On Wed, 24 Oct 2001, Chris Tavares wrote: > Isn't this relying rather heavily on the implementation of a specific > version of the python interpreter, though? I'd rephrase that as relying on the well-documented behavior of many versions over several years of the same implementation. This isn't exactly some odd quirk in a dark corner of the interpreter... > Removing the global interpreter lock (and these semantics that you're > leaning on) has been the focus of some serious effort in the past. Yes... and after that effort the GIL is still there. If it helps you sleep better, always do your own locking and assume the GIL doesn't exist. :) I'm just saying that a lot of times you're solving problems you don't have, that's all. > Does jython share this same behavior? Don't know, don't care. > What about the version with the "free threading patches" from a couple > of years ago? What about it? Instead of building my app based on the behavior of the standard Python interpreter, I should make sure it works on some patched version? Naah... > You're asking for trouble in the long run if you rely on this, I think. You're overestimating the cost of changing a Python program, I think. Should the GIL be removed someday down the road, *all* multithreaded apps would become suspect and overdue for a thorough review. FWIW, I don't think the GIL will ever go away, or if it does, we'll end up with something that gives the same behavior. Think about it: no GIL means that a normal Python program (ie no extension modules in use) could crash the interpreter. Maybe it's just me, but Guido et al have gone to great lengths to make it nearly impossible to do that (and when it happens, it's considered a bug and is fixed ASAP). The GIL is what lets multi-threaded Python programs still behave like Python programs should. -Dave From guido at python.org Mon Oct 22 08:36:42 2001 From: guido at python.org (Guido van Rossum) Date: Mon, 22 Oct 2001 12:36:42 GMT Subject: error messages raised by python got me thinking. References: Message-ID: Laura Creighton writes: > Thank you very much for your reply. You're welcome. I am always to make Python better -- and this was an easy fix! > I would greatly prefer "cannot concatenate 'string' and '%s'". Am I being > a pedant for wanting "cannot concatenate instances of 'string' and '%s'"? No -- I noticed that myself and checked in "cannot concatenate 'str' and '%s' objects". > or, since 'str' is the way of the future, "cannot concatenate instances > of 'str' and '%s'"? (I'd like uniformity across error messages whenever > possible, so unless you want to start referring to ints as _integers_...) I am hoping to reserve the term 'integer' for the unified concept. > > But in general, we can't always produce the error message you'd like > > to see: e.g. if you try to add a Unicode string and a number, you get > > the even less clear > > > > TypeError: coercing to Unicode: need string or buffer, int found > > > > This one is hard to fix, due to the complicated logic attempted in the > > Unicode case (the code that issues the error message has no idea that > > it is part of a '+' operator). > > I understand. Is the information about the _position_ of the > argument that fails long gone as well? > > lac at ratthing-b246:~/src/pynche/newpynche$ python -U > Python 2.1 (#3, May 26 2001, 17:43:53) > [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> f='1' > >>> g=2 > >>> f+g > Traceback (most recent call last): > File "", line 1, in ? > TypeError: coercing to Unicode: need string or buffer, int found > > What I want to know, is that it is my _second_ argument that is wrong. > (Without remembering that if my first one was bad, I would be getting > the 'unsupported operand types for +' message.) This is more important > when you are doing things like this: > > >>> h='3' > >>> i='4' > >>> f+h+g+i > Traceback (most recent call last): > File "", line 1, in ? > TypeError: coercing to Unicode: need string or buffer, int found > > (at least _my_ little voice says: 'which _one_, damnit!!' voice may be a lot politer than mine.>) Would this be possible? Alas, not very easy. The solution here, unfortunately, will probably have to be sought in a smarter debugger that shows tha values of all variables referenced in a line. > >>> f+h+g+i > Traceback (most recent call last): > File "", line 1, in ? > TypeError: coercing to Unicode: need string or buffer: int found at position 3 # I just made this up Sorry, this is not realistic given the way the interpreter works. Besides, in a situation like f(x+y+z, a*b*c*d, p**q**r) what would "position 3" refer to? > Note, I changed the comma after _buffer_ to a colon when I added the > theoretical position information, for consistency in punctuation between > this error and the "unsupported operand types[sic] for +:" error, discussed > next. That's a nice idea. > As for: > > "unsupported operand type for +: 'int' and 'str'" > > Typo, you meant "unsupported operand _types_," correct? Yes. > > (It would have to be 'str' because as of 2.2, that's the name for the > > string object type, corresponding to the function most commonly used > > to create strings.) > > > > Another way to write this, using 2.2 lingo, might be > > > > "unsupported operand types: int() + str()" > > > > but this doesn't look very newbie-friendly to me! > > I think that it is important to list what operation failed, so > "unsupported operand types for +:" or (my preference) > "unsupported operand types for '+':" is better than the less informative > "unsupported operand types: ". Yes. Note that the operator still appeared in the message, between int() and str(). :-) > But whether to use > "'int' and 'str'" or "int() and str()" is a different question. My > initial reaction is to prefer "int() and str()", I think because it > perfectly jogs your memory about how to _fix_ your error. So, were > it my decision, I would let it rattle about in my head for a week > or so, and then, if I still liked it I would go with: Hm, a week from now this will long be gone from my brain. :-) Today, think that for a newbie, int() just has two mysterious parentheses, and for an expert, it's at best cute to know that you can type this: >>> int() + str() Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand types for +: 'int' and 'str' >>> > "unsupported operand types for '+': int() and str()". > > Of course, if my suggestion for listing the position of the > argument that triggered the failed unicode conversion error makes it > into a python release, you may want the following for consistency: > > >>> g+f+h+i > Traceback (most recent call last): > File "", line 1, in ? > TypeError: unsupported operand types for '+': int() and str() found at positions 1 and 2 > > Is this the sort of thing that should get a PEP? Not really -- it doesn't change the language, it's what would be called a "quality of implementation" issue. If it said "TypeError: oomph" it would still be Python. :-) --Guido van Rossum (home page: http://www.python.org/~guido/) From sholden at holdenweb.com Thu Oct 11 11:15:31 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 11 Oct 2001 11:15:31 -0400 Subject: Holden's Python Web Programming Book References: Message-ID: <%Eix7.7696$I83.201007@atlpnn01.usenetserver.com> Erm, dunno! I'll ask my publisher. It's time they billed it as a forthcoming book on the New Riders site anyway. What level of detail are you interested in? regards Steve -- http://www.holdenweb.com/ "DeepBlue" wrote in message news:tsb84mihle6d07 at corp.supernews.com... > This is a question for Steve Holden: > Steve, > Is there a way to view the table of contents of your upcoming book? > I want to compare this book with Mitchell's book "Python for the Web." > Thanks, > DB > > From doug at mcnaught.org Fri Oct 26 12:14:34 2001 From: doug at mcnaught.org (Doug McNaught) Date: 26 Oct 2001 12:14:34 -0400 Subject: write to closed console fails on FreeBSD but not Linux? References: Message-ID: usenet at jeffjohnson.net (Jeff Johnson) writes: > I'm running a Python program as a daemon on FreeBSD 4.3 and Python > 2.1.1. It was crashing just after I would close the console because > printing to sys.stdout after the console was closed produced IO > errors. I found a few solutions from other usenet posts, I chose to > set sys.stdout and sys.stderr to a file-like class that doesn't write > to anything. FWIW, the canonical way to run as a daemon under Unix is: 1) Close stdin, stdout, stderr and reopen them to '/dev/null' (or logfiles if you like). 2) fork() 3) call setsid() in the child, parent exits, child does the work. -Doug From gabriel_ambuehl at buz.ch Tue Oct 23 11:34:11 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Tue, 23 Oct 2001 17:34:11 +0200 Subject: programming unlimited "categories" in python ? In-Reply-To: <97ae44ee.0110230529.5c33dd83@posting.google.com> References: <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> Message-ID: <75175972314.20011023173411@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello Stephen, Tuesday, October 23, 2001, 3:29:14 PM, you wrote: > proves this not to be case with a multitude of applications > (mainly in Perl) that offer "unlimited categories/subcategories". I think what you're really looking for is information about implementing arbitrary tree (as in MS explorer, for example) structures of which there is a lot online... Best regards, Gabriel -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO9V/58Za2WpymlDxAQE1bgf+JtayZxvrKoYxDhYfs6CDedYFqz8NpSN6 i58lvNeYZsojW8DyzeZAYI39TT7TqlSc/DM+S7nFmVDNGa8KCsszBmWUy3nyjcLt cvQ0j4vd74QbI4dRGNlure5Yh1zWjr6mqpxRvSyb9Vg3gA1DxZ47LUO1JoX47Ls1 Y63t4ICgB9uVmZfLfTm5iRiJNXSTo5FVLNbGA92AXiAXNg1uZx6BsNcIRz8gRfk0 ngOuDbpaf1bUC4gU42fyKeuaxV0oFmdcbfvYoG7uCdGEYT1Og4xgdICS8nbpKz35 Pc0FJuGjbjag4HUOTMZ8Voi2or5pJzCIvPRjxCwa9XncjWW8puPosw== =pbWW -----END PGP SIGNATURE----- From jknapka at earthlink.net Fri Oct 5 18:09:35 2001 From: jknapka at earthlink.net (Joseph A Knapka) Date: Fri, 05 Oct 2001 22:09:35 GMT Subject: Nicer Tkinter on UNIX? References: <3bbaf48e.1019777212@spamkiller.newsfeeds.com> <86DF15C112AF36D6.332DEDD523A2210C.F8DE5222D8EF2836@lp.airnews.net> <3bbc18a8$0$19394$e4fe514c@newszilla.xs4all.nl> Message-ID: <3BBDDA38.CF9D15AA@earthlink.net> Artur Skura wrote: > > Boudewijn Rempt wrote: > > Phil recently pre-released PyQt for Qt 3 (just in time to > > test everything in my book with it) - and it would be > > extremely interesting to get that to work with Qt3 for OS X. > > I'd really like to try it, but I don't have a Mac :-(. Still, > > I really expect PyQt 3 for OS X to available in the very near > > future. > > It makes me wonder why such a useful package as PyQt is not a part of > Python distribution (the same holds for GTK bindings). > I think it would be good for users and developers to have them installed > together with all other modules. > Also, an ideal solution for me would be a wrapper module (anyGUI, kindof), > which would check for Qt etc. libraries on systems that support it; if not > found, it would use Tkinter. Is there anything like this? Yes, and believe it or not it's called "anygui"! Alpha at the moment, but coming along nicely. We're aiming to support basically everything you get in Tk or wxPython, and provide a common API that uses whatever windowing system is available on the machine. Currently there are anygui bindings for Tk, wx, Java (Jython), Beos, Mac, and Win32 native API, and possibly others I haven't though of. Someone is talking about a Curses binding as well, so anygui programs can run unchanged (though possibly with some missing functionality) on text terminals. It's possible to use anygui for simple data-entry applications right now, though complex things like games, or anything that requires specialized event handling, is not going to work. One area of active investigation at the moment is how to implement the anygui event model. We can always use develpers and testers! Join the anygui mailing list (linked from the sourceforge page referenced above)! Cheers, -- Joe # "You know how many remote castles there are along the # gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald # Linux MM docs: http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html From tim.one at home.com Wed Oct 3 22:13:58 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 3 Oct 2001 22:13:58 -0400 Subject: Assignment not the same as defining? In-Reply-To: Message-ID: [Steve Holden] > ... > The main thing is to remember that assignment is only one of the > several (I seem to remember Tim Peters listed five) ways to bind a > value to a name. This isn't really a matter of interpreting goose entrails. All the binding contexts are explicitly listed in the Reference Manual. Look for the sentence starting "The following constructs bind names" in the "Code blocks, execution frames, and namespaces" section. seven-or-eight-depending-on-how-you-count-ly y'rs - tim From phd at phd.pp.ru Tue Oct 23 06:07:32 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 23 Oct 2001 14:07:32 +0400 Subject: Automatically resume a download w/ urllib? In-Reply-To: <3bd5024a@news.actrix.gen.nz>; from mark21rowe@yahoo.com on Tue, Oct 23, 2001 at 05:31:54PM +1300 References: <3bd5024a@news.actrix.gen.nz> Message-ID: <20011023140732.I21265@phd.pp.ru> On Tue, Oct 23, 2001 at 05:31:54PM +1300, Mark Rowe wrote: > After reading some RFC's and tweaking some Apache settings, I managed to get > this working. I was only able to test it on my local server and it appears > to work fine. Any comments or improvements, feel free :) Thank you. [skip] > if existSize > 0: > h.putheader('Range', 'bytes=%d-' % (existSize, )) Looks good. [skip] > ## HTTP error 416 = Request Range not Satisiable ^ Typo (-: _| Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From me at mikerobin.com Tue Oct 23 13:27:07 2001 From: me at mikerobin.com (Michael Robin) Date: 23 Oct 2001 10:27:07 -0700 Subject: Multimedia audio programming in Python References: Message-ID: <52e5ab5f.0110230927.5a5239a2@posting.google.com> You have two problems here: (1) You probably won't be able to adjust the speed/pitch of the CD audio directly, at least the one in your computer. If such a special beast exists, it's probably tres expensive. (2) Getting the CD audio so you can process it. One way is to "rip" it, i.e., get the digital info straight from the CD. The other way is to play the track and record it as a sound file. Either way you do it, you'll have to then run some resampling/pitch-shifting code to get your desired results. (A package to do this you should be able to buy - search for it.) In any case, most of the work is going to be dealing with audio, special modules, your OS, etc., so it's not really a python issue - although you could glue it all together with Python at the end. If you're on a PC, there *may* be a high-end sound card that comes ready to do the stuff you want - check it out. If your on a Mac, maybe there's some funny call that does exactly what you want - no clue. You should probably continue the thread on groups that are orientated toward professional music/audio, DSP programming, gaming/multmedia and whatever OS you're on. (I guess the answer probably is straightforward=no...) hope this helps, mike "Syver Enstad" wrote in message news:... > I wonder (being totally green in sound programming) if it is straightforward > to make a python program to adjust speed on an audio CD track without > changing the frequency of the sound. > > What modules could help me. > > Any suggestions much appreciated. From tjreedy at home.com Thu Oct 25 12:56:32 2001 From: tjreedy at home.com (Terry Reedy) Date: Thu, 25 Oct 2001 16:56:32 GMT Subject: A small inconsistency in syntax? References: Message-ID: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> "Michael Abbott" wrote in message news:Xns91459674D7271michaelrcpcouk at 194.238.50.13... > It seems to me that there's a little inconsistency in assigning to tuples: There is no such thing as assigning to tuples or to any other type of object. There is only assigning names (on the left side) to objects (on the right side) as recorded in the local or global namespace. > >>> (x,) = () > Traceback (most recent call last): > File "", line 1, in ? > ValueError: unpack tuple of wrong size More clearly, "cannot assign name 'x' to non-existent first member of tuple-object ()" > >>> () = () > SyntaxError: can't assign to () More clearly, "cannot assign object (only names) to object" http://www.ora.com/catalog/pythonxml/chapter/ch01.html > Eh? Why not? It's just a matter of checking that the right hand side > really is an empty tuple... No, its a matter of checking the the left hand side consists of legal names. > I actually hit this in some code, where I wrote: > > time, status, () = myobject.read() > > where I happen to know that that in this particular case my object will > return an empty tuple in its third argument. It should be clearer now why the third 'assignment' is meaningless and does not work. > Ok, so it's easy enough for me to write > > time, status, _ = myobject.read() > > instead, so I'm grumbling about trivia here. The problem is that Python assignment is not sufficiently well explained for many. It is quite different from assignment in languages that assume a linear memory space with integer address in which names represent chunks of that linear memory and in which assignment 'to a name' represents assignment to the chunk of memory designated by that name. Terry J. Reedy From esh at berlingske.dk Fri Oct 12 09:32:21 2001 From: esh at berlingske.dk (Emil S. Hansen) Date: Fri, 12 Oct 2001 15:32:21 +0200 Subject: Using assingment as an operator. References: Message-ID: In , Steve Holden wrote: >> while re.search("[^a-z0-9.]", domainname = raw_input("Please enter > domainname: ")) != None: >> print "Error in domainname, please use lovercase letters and > numbers only." > You can't. See Frequently Asked Question 6.30 for why. The syntax you > use is for keyword arguments to functions, another subject entirely. I guessed that, but I hoped there was another way to do what I want. But I'll have a look at the FAQ. Thanks for your time, -- Best Regards Emil S. Hansen - esh at berlingske.dk - ESH14-DK UNIX Administrator, Berlingske Tidende - www.berlingske.dk "Tilgiv mig min uvidenhed, men man kan vel forh?bentlig logge ind p? en NT med telnet - ellers kan det vel vanskeligt kaldes et server-operativsystem." - Allan Olesen From donn at u.washington.edu Wed Oct 17 20:33:31 2001 From: donn at u.washington.edu (Donn Cave) Date: 18 Oct 2001 00:33:31 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <9qe49r$4k1$1@slb3.atl.mindspring.net> <9qhvq5$29ik$1@nntp6.u.washington.edu> Message-ID: <9ql80r$16di$1@nntp6.u.washington.edu> Quoth Guido van Rossum : ... | I don't know what it takes to reconstitute your faith in Python 2.2. | There's one little point of light: conditional expressions are out. I | couldn't find any examples in the standard library that would be made | to look better by using them. :-) | | Regarding all the other changes (you're right, I won't back them out | :-), I believe that they are much more backwards compatible than you | fear. Integer division won't become the default until 3.0, for | example. Same thing for new-style classes: I'm committed to make | applications that use Jim Fulton's ExtensionClass or otherwise use the | Don Beaudry hook work the same way as they did in 1.5.2 and 2.1.1, and | I've pretty much achieved this in 2.2a4 already. New-style classes | will be dynamic by default in 2.2b1 and their instances will allow | assignment to self.__class__. | | What else? 2.2 has lots of improvements that you'll want and that | don't affect the language syntax at all -- better portability, better | and automatically configured large file support, etc. Well, you know I'm a pretty hard sell on features. The way I see it, Python has all the features I need, has had them all along - if only I could use it. But too often I can't and have to write in C instead, or awk or something if I'm lucky. That happens mainly because of "market penetration", so to speak. What can be done about that? I don't think it's something for you to solve, you need to move forward with whatever you think will make Python better. When it comes to that, I guess I'm more of a minimalist, but in the end you're the one to say what's right. But getting it out into the world and installed, getting one's colleagues to learn it, I don't know if that really hangs on new features or is hung by them. Donn Cave, donn at u.washington.edu From no at email.com Tue Oct 2 00:22:29 2001 From: no at email.com (James) Date: Tue, 2 Oct 2001 12:22:29 +0800 Subject: newbie str to int Message-ID: <9pbetr$jp83@imsp212.netvigator.com> I am switching from Perl to Python, and would like to convert string '123abc' to integer 123. foo = int('123abc') # error foo = string.atoi('123abc') #error foo = eval('123abc') # error I tried the above, then tried the following. tmp = '' for i in '123abc': if 47 < ord(i) < 58: tmp += i foo = int(tmp) # yay Why doing simple thing like this is so complicated ? Perl $foo = '123abc' + 0; Please explain in newsgroup. Many thanks in advance. From spamfreenation at nigenet.org.uk Thu Oct 11 11:29:02 2001 From: spamfreenation at nigenet.org.uk (nice.guy.nige) Date: Thu, 11 Oct 2001 16:29:02 +0100 Subject: YOU ARE ALL GAY! References: <9q2k92$2vd$1@plutonium.btinternet.com> Message-ID: <9q4dro$m0eg7$1@ID-112325.news.dfncis.de> "Geoffrey Pointer" wrote in message news:B7EBA769.82EC%geoffrey at bigpond.net.au... Hi Geoff, [...] > This was a comment about the psychobabble in the original message and not > its subject. If that is the case, then it would have been a good idea to include some of the original message that you were replying to, so the context of the conversation wouldn't be lost. I have not seen the original message - just your reply - and as such your post made absolutely no sense whatsoever. Cheers, Nige -- Nigel Moss Visit me on the webby thing! http://www.nigenet.org.uk Boycott E$$O!! http://www.stopesso.com From mal at lemburg.com Tue Oct 2 15:41:38 2001 From: mal at lemburg.com (M.-A. Lemburg) Date: Tue, 02 Oct 2001 21:41:38 +0200 Subject: ANN: eGenix.com mx EXPERIMENTAL Package 0.6.0 Message-ID: <3BBA1872.B9BF3BE@lemburg.com> ________________________________________________________________________ ANNOUNCING: eGenix.com mx EXPERIMENTAL Extension Package for Python Version 0.6.0 Experimental Python extensions providing important and useful services for Python programmers. ________________________________________________________________________ WHAT IS IT ?: The eGenix.com mx EXPERIMENTAL Extensions for Python are a collection of alpha and beta quality software tools for Python which will be integrated into the other mx Extension Packages after they have matured to professional quality tools. Python is an object-oriented Open Source programming language which runs on all modern platforms (http://www.python.org/). By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for todays IT challenges. ________________________________________________________________________ WHAT'S NEW ? This release includes two new subpackage: mxURL and mxUID providing fast implementations for URL and UID processing. ________________________________________________________________________ EGENIX.COM MX EXPERIMENTAL PACKAGE OVERVIEW: mxNumber - Python Interface to GNU MP Number Types mxNumber provides direct access to the high performance numeric types available in the GNU Multi-Precision Lib (GMP). This library is licensed under the LGPL and runs on practically all Unix platforms. eGenix.com has ported the GMP lib to Windows, to also provide our Windows users with the added benefit of being able to do arbitrary precision calculations. The package currently provide these numerical types: 1. Integer(value) -- arbitrary precision integers much like Python longs only faster 2. Rational(nom,denom) -- rational numbers with Integers as numerator and denominator 3. Float(value[,prec]) -- floating point number with at least prec bits precision 4. FareyRational(value, maxden) -- calculate the best rational represenation n/d of value such that d < maxden mxTidy - Interface to HTML Tidy (HTML/XML cleanup tool) mxTidy provides a Python interface to a thread-safe, library version of the HTML Tidy. command line tool. HTML Tidy helps you to cleanup coding errors in HTML and XML files and produce well-formed HTML, XHTML or XML as output. This allows you to preprocess web-page for inclusion in XML repositories, prepare broken XML files for validation and also makes it possible to write converters from well-known word processing applications such as MS Word to other structured data representations by using XML as intermediate format. mxURL - A URL Datatype mxURL provides a new datatype for storing and manipulating URL values as well as a few helpers related to URL building, encoding and decoding. The main intention of the package is to provide an easy to use, fast and lightwheight datatype for Universal Resource Locators (note the W3C now calls these URIs). mxUID - A UID Datatype mxUID provides a fast mechanism for generating universal identification strings (UIDs). The intent is to make these UIDs unique with high probability in order to serve as object or data set identifiers. A typical use lies in generating session IDs. Other areas where unique IDs play an important role are RPC-implementations, ORBs, etc. ________________________________________________________________________ WHERE CAN I GET IT ? The download archives and instructions for installing the packages can be found at: http://www.lemburg.com/files/python/ ________________________________________________________________________ WHAT DOES IT COST ? The EXPERIMENTAL packages uses different licenses in its subpackages. Please refer to the subpackage documentation for details. Some of them may be integrated into the BASE package, others will be integrated into the COMMERCIAL package. The package comes with full source code ________________________________________________________________________ WHERE CAN I GET SUPPORT ? There currently is no support for these packages, since they are still in alpha or beta. Feedback is welcome, though, so don't hesitate to write us about the quirks you find. ________________________________________________________________________ REFERENCE:

eGenix.com mx EXPERIMENTAL Extension Package 0.6.0 - eGenix.com mx EXPERIMENTAL Extension Package 0.6.0 with precompiled binaries for Windows and Linux. (02-Oct-2001) ________________________________________________________________________ Enjoy, -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Software: http://www.lemburg.com/python/ From michael_armbruster at eu.exch.agilent.com Wed Oct 17 04:17:12 2001 From: michael_armbruster at eu.exch.agilent.com (Michael Armbruster) Date: Wed, 17 Oct 2001 10:17:12 +0200 Subject: pure 16-bit DOS app Message-ID: <1003306634.200241@cswreg.cos.agilent.com> Hi there, I read many articles in the grup and the web, but till now I have not found the real solution for my problem. I would like to have a pure standalone DOS 16-bit app built out of a python prog with inserted c-code but I don't know how to do this. perhaps you could help me, thanks alot Mike From dgrisby at uk.research.att.com Fri Oct 19 05:13:28 2001 From: dgrisby at uk.research.att.com (Duncan Grisby) Date: 19 Oct 2001 09:13:28 GMT Subject: Error starting omniNames....Invalid object reference error. References: <6b2d6822.0110181333.78adb6f1@posting.google.com> Message-ID: <9qoqro$kdj$1@pea.uk.research.att.com> In article <6b2d6822.0110181333.78adb6f1 at posting.google.com>, JDS wrote: >I downloaded omniORB_303_x86_win32.zip, unzipped it: then downloaded >omniORBpy_1_3_x86_win32_python20.zip and unzipped it. Then I set the >paths as follows: Those aren't the latest versions. You should use omniORB 3.0.4 and omniORBpy 1.4. >- set PATH=c:\winnt\system32;c:\omni\bin\x86_win32;c:\python2.0\; >- set PYTHONPATH=c:\omni\lib\python;c:\omni\lib\x86_win32; > >When I type >> omniNames -start >I get the following error on an NT4.0 windows machine: >omniORB: Configuration error: Invalid object reference supplied for >NameService >Failed to initialise the ORB. > >Another machine runs just fine. Most likely, the machine that is failing has some invalid stuff in the omniORB related registry entries. See section 1.2 of the omniORB manual for details of what should be in the registry. Cheers, Duncan. -- -- Duncan Grisby \ Research Engineer -- -- AT&T Laboratories Cambridge -- -- http://www.uk.research.att.com/~dpg1 -- From ws-news at gmx.at Tue Oct 23 17:00:16 2001 From: ws-news at gmx.at (Werner Schiendl) Date: Tue, 23 Oct 2001 23:00:16 +0200 Subject: None References: Message-ID: <3bd5db1e$1@brateggebdc5.br-automation.co.at> Hi, just had to try that out... >>> print None None >>> None = 17 >>> print None 17 >>> Strange... is it intended that you can assign to None? In short, is this a bug or a feature? thanks Werner "Bjorn Pettersen" wrote in message news:mailman.1003861644.23456.python-list at python.org... > From: Larry Whitley [mailto:ldw at us.ibm.com] > > I want to have a methode of a class that will take the > argument of a file object that has previously been opened for > write and be able to call it, directing it's output to a > file, or directing the output to standard output. > > def output(self, fout): > print >>fout, self.thing1, self.thing2, self.thing3 > > In the calling program I say: > > object.output( fout ) # print to file > object.output( None) # print to standard output > > But Python complains that None is a variable that has not > been previously set. Can someone explain? I thought None > was the empty object reference. Where have I gone astray? Not enough information (although I'm assuming you're assigning to None somewhere...) Could you post your traceback? -- bjorn From gh_pythonlist at gmx.de Fri Oct 19 06:09:41 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 19 Oct 2001 12:09:41 +0200 Subject: where to get popy?? In-Reply-To: ; from mjais@web.de on Fri, Oct 19, 2001 at 10:49:24AM +0200 References: Message-ID: <20011019120941.A899@lilith.hqd-internal> On Fri, Oct 19, 2001 at 10:49:24AM +0200, Markus Jais wrote: > hello > I was at > http://popy.sourceforge.net/ > > but there is not link to get a stable tarball for popy! > I can only get a cvs version > > and at http://www.nekhem.com/, there is not much right now. > > maybe I am just blind, but can someone give a link > where to find the latest stable version of popy??? http://pypgsql.sf.net/, no oops, that was the following ;-) http://www.sf.net/projects/popy then go to "Files". Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From db3l at fitlinxx.com Wed Oct 17 18:51:17 2001 From: db3l at fitlinxx.com (David Bolen) Date: 17 Oct 2001 18:51:17 -0400 Subject: Help optimize a script? References: <3Nkz7.138277$5A3.44609227@news1.rdc2.pa.home.com> Message-ID: Joseph Santaniello writes: > After compling 2.1.1 for HP-UX so I would have access to the join() method > of sting, I started to wonder how much of this speed increase (if any) is > from just using 2.1.1 over 1.5.2 ? Any ideas? Probably not too much if at all. But just go back to string.join() and run the same code under 1.5.2 and test it yourself. The string methods are perhaps clearer (although join is a particularly debated one), but shouldn't change much in terms of performance. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From janssen at parc.xerox.com Wed Oct 17 20:43:13 2001 From: janssen at parc.xerox.com (Bill Janssen) Date: Wed, 17 Oct 2001 17:43:13 PDT Subject: opening sys.stdout in binary mode on Windows? Message-ID: <01Oct17.174323pdt."3456"@watson.parc.xerox.com> Hi. On Windows, I'd like to have stdout opened in binary mode before writing to it. I've tried things like sys.stdout = os.fdopen(sys.stdout.fileno(), "wb") without success. Anyone know the trick? Bill From tdelaney at avaya.com Tue Oct 2 23:45:45 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 3 Oct 2001 13:45:45 +1000 Subject: Python is better than free (was Re: GNU wars again) Message-ID: My apologies - I intended to send that only to Chris Watson ... > From: Delaney, Timothy > > Did you even *read* my message? ... Tim Delaney From pinard at iro.umontreal.ca Thu Oct 4 16:33:30 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 04 Oct 2001 16:33:30 -0400 Subject: python and HTML integration In-Reply-To: <3BBCB1F0.ED40594A@oek.dk> References: <3BBCB1F0.ED40594A@oek.dk> Message-ID: [Peter I. Hansen] > What is the best way to integrate Python i HTML ? Besides Zope. > I've looked at PyML and Poor mans Zope, but I would like to hear > oppinions from someone who actually does this for real Hello, Peter. I'm pretty sure that Zope, and many other avenues, are all "for real"! :-) For one, I did not feel ready for Zope, and developed my own solution for "active" HTML, quickly written, and surprisingly powerful. Python much helps simple projects to take the road. If your needs are modest, it might be equally easy to do something, or choose and study something done elsewhere. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From huaiyu at gauss.almadan.ibm.com Thu Oct 18 22:02:36 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 19 Oct 2001 02:02:36 +0000 (UTC) Subject: PEP: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: Carl Banks gave some well-thought out objection, which I'd like to summarize them as: (1) There may be many statements before the condition, resulting in long while-lines. (2) The else-clause for while is not necessary for while 1. But then I was reminded of the examples I collected by searching for break statements in the source distribution. Most usages are similar to ./Demo/pdist/makechangelog.py: --------------------------------------------(1) while 1: file = getnextfile(f) if not file: break revs = [] while 1: rev = getnextrev(f, file) if not rev: break revs.append(rev) if revs: allrevs[len(allrevs):] = revs which can be changed to: while file = getnextfile(f); file: revs = [] while rev = getnextrev(f, file); rev: revs.append(rev) if revs: allrevs[len(allrevs):] = revs or better still while file = getnextfile(f); file: revs = [] while rev = getnextrev(f, file); rev: revs.append(rev) allrevs += revs This is more readable to me, because the condition is on the same line as while (esp. in a color editor). In practical terms I do not see why this is ugly. >I would suggest something more along these line (fleshing out the >example a little): > > suppose: > m = re.search (somthing) > if m: > do_something_with (m) > elsuppose: > m = re.search (somthing_else) > if m: > do_something_else_with (m) > else: > raise some_exception; If we are to add more keywords, maybe this? A branch: B1 if C1: D1 else: B2 if C2: D2 else: B3 E or even this? A B1 if C1: D1 else: B2 andif C2: D2 else: B3 E But I don't think any new keyword for this purpose will ever get in. >I would suggest something like: > > do: > > while : > > >with the do part optional. The exact keywords and semantics I don't >care about. But, like I said, I have no problem with "while 1:". This is cute, but it cannot work unless the current while statement is phased out. Otherwise, if I'm looking at a piece of code like .... .... while ... .... .... it would not be clear if the while is in a new loop or previous loop. Presumably this would be allowed do: A while B: C while D: ... Huaiyu From lookuprhett at yahoo.com Thu Oct 11 14:28:41 2001 From: lookuprhett at yahoo.com (Rhett) Date: 11 Oct 2001 11:28:41 -0700 Subject: CGI question on input type=text form elements References: Message-ID: <3acd06c8.0110111028.7e057da0@posting.google.com> You must have made a silly mistake somewhere. Either that or there is a browser/web server issue. This works fine for me on apache under linux, python 2.1.1 [index.html]

[poster.cgi] #!/usr/bin/python import cgi form = cgi.FieldStorage() print 'Content-type:text/html\n\n' for f in form.keys(): print str(f) + ': ' + str(form[f].value) "DeepBlue" wrote in message news:... > I am running into a strange problem with a form while using CGI module in > Python. > Let us say I have the following form: >
> > >
> > Now, let us say that test_form=cgi.FieldStorage() > If the above form is submitted without typing anything in the text field one > expects test_form.keys() to generate: > ['submit'] > > But i am getting: > ['text_1', 'submit'] > Which is unexpected, and in my case, undesirable. What am I doing wrong? > DB From dale at riverhall.NOTHANKS.co.uk Fri Oct 19 10:43:28 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Fri, 19 Oct 2001 15:43:28 +0100 Subject: Traceback oddity References: <3BD025A3.D0724FFC@pallas.com> Message-ID: <0pe0ttcce62l0915r1qa1ik3vt8dec9is5@4ax.com> "Steve Holden" wrote: >And under the circumstances described above you got whichever the filesystem >code came up against first. Wildcard matches were especially fun, since >(AFAIR) the two different names would glob out, but then both would access >the same file. Glob out? I love it! >But of course that doesn't answer Dale's question as to why his traceback >shows the same directory in different ways. Dale, have you checked to see >whether you have multiple entries in sys.path? No duplicates in sys.path, although the directory reported in lower case is the current directory. Both the related entryies in sys.path are all lower case. -- Dale Strickland-Clark Riverhall Systems Ltd From kseehof at neuralintegrator.com Tue Oct 9 21:07:23 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Tue, 9 Oct 2001 18:07:23 -0700 Subject: TROJAN ALERT! (JS/Loop) References: <3bc343a0.fba6e0c5.c0a801.00.R@drsolomon.com> <01100912310503.02876@logiplex1.logiplex.net> Message-ID: <038201c15127$fa3905e0$e4cfbfa8@kens> Cliff Wells wrote: > On Tuesday 09 October 2001 11:59, Steve Holden wrote: > > I would have characterised this attack as a GUI denial-of-service, not a > > Trojan horse. A Trojan horse is an exploit which collects information from > > an unsuspecting user and stores or transmits it for use by the third party. > > Such misinformation does not lend credibility. The code involved was a > > simple infinite alert loop. > > Actually, a trojan horse is simply a hostile program that masquarades as a > useful one (hence the name). It doesn't really matter what the function of > the program is. Oh. Like Windows? - Ken From DeepBlue at DeepBlue.org Fri Oct 19 13:31:18 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Fri, 19 Oct 2001 12:31:18 -0500 Subject: Database Sessions and Transactions Message-ID: I am working on a CGI program in Python that connects to an Oracle database. I am wondering on how to implement a transaction that belongs to a database connection so that everything that belongs to the transaction can be rolled back. In other words, the scope of the rollback is NOT the database connection BUT the transaction that is defined from within the database connection. Please note that Python DB API 2 talks of a transaction as belonging to the scope of the database connection, and not something that can be created independently from the Connection. Also, I can find no reference in Python DB API 2 to Sessions. How do we manage different sessions/connections? Thanks, DeepBlue From phr-n2001d at nightsong.com Mon Oct 8 22:51:08 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 08 Oct 2001 19:51:08 -0700 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> Message-ID: <7xwv25zftv.fsf@ruckus.brouhaha.com> Joshua Macy writes: > Can you name a single time this has ever happened with something > included in the standard Python library? The Python Labs crew has, > according to what I've seen posted here, spent inordinate number of > hours and dollars trying to make sure that the Python license was both > acceptable to the FSF and permitted the development of closed-source > commercial products. From where I sit this looks like (possibly > unintentional) anti-Python FUD--"ooh, better not use Python...don't > know if its libraries are properly licensed...beware! beware!" I don't think anything in the standard Python library is GPL'd. (GPL-compatible yes, GPL'd no). Since the Python allows usage in closed-source programs, the GPL issues don't apply. However, the discussion seemed to pertain to independently distributed add-on libraries, not just the standard library included with Python. If I submitted a patch to the standard Python library, I'd expect the patch to be distributed under the same Python license that the library is distributed in, i.e. closed-source usage would be ok. I might be less motivated in the first place to contribute substantial patches than if Python were GPL'd, since I'd in effect be working for closed-source vendors without getting paid, but that's a totally separate issue. From aahz at panix.com Sun Oct 21 11:43:02 2001 From: aahz at panix.com (Aahz Maruch) Date: 21 Oct 2001 08:43:02 -0700 Subject: Python 2.1.2 (was Re: profiler results for __getattr__, am I reading this correctly ?) References: Message-ID: <9quqe6$3sq$1@panix3.panix.com> In article , Tim Peters wrote: > >If volunteers materialize to produce another bugfix release, I'm sure we'll >(PythonLabs) be happy to ship it (cut docs, installers, etc). It's curious >that neither Aahz (2.0.1) nor Thomas Wouters (2.1.1) volunteered for a >second round of this rewarding work . It's even less curious when you realize that Aahz never did any actual work other than writing up a PEP. Moshe Zadka was the wrangler for 2.0.1 (with some assistance from Guido when Moshe disappeared for a while). -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista We must not let the evil of a few trample the freedoms of the many. From phr-n2001d at nightsong.com Mon Oct 15 14:38:13 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 15 Oct 2001 11:38:13 -0700 Subject: Python web client anyone? References: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> <7xn12tombq.fsf@ruckus.brouhaha.com> <7xu1x1px4d.fsf@ruckus.brouhaha.com> <9qer0a$don$1@dahlia.singnet.com.sg> Message-ID: <7xlmickaui.fsf@ruckus.brouhaha.com> ngps at madcap.dyndns.org (Ng Pheng Siong) writes: > According to Paul Rubin : > > What I *really* want is to be able to easily find link objects > > (anchor tags) based on the anchor text, which LWP for some reason > > doesn't do, but DOM extraction would be a start. By "anchor text" I > > mean the text in this is the anchor text. The > > client should be able to find some "underlined" text on the page it > > retrieves, and "click" on the linked document. > > Surely, you find the tags by parsing "" (sic), not by > looking for "this is the anchor text"? No, I meant looking for "this is the anchor text". I don't understand why LWP doesn't do that. If I tell you that you can read about LWP by browsing www.cpan.org and clicking on the link that says "The LWP Web Client", that's natural and you can follow the instructions very easily. So why should it be hard to program a robot to do that? > htmllib parses fine enough. Here's a demo from M2Crypto. It seems to work, > too. ;-) Thanks, that's the kind of thing I have in mind--a more convenient interface would have been nice, but it's a start. From tim.one at home.com Sat Oct 27 12:53:43 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 27 Oct 2001 12:53:43 -0400 Subject: Dictionary from list? In-Reply-To: Message-ID: [James_Althoff at i2.com] > ... > isn't this a reasonable place to take advantage of the new 2.2 class > methods and provide: > > dictionary.newFromList([k,v,...]) > > (or some other shorter/more-appealing method name of preference)? I don't think so, simply because it would make dictionary unique. Python already had str(), unicode(), int(), long(), float(), complex(), list() and tuple() builtins, and adding dictionary() and file() to 2.2 was thus natural (for Python). > I think class methods provide a nice way to introduce alternative > "constructors" without having to add special modules for the sole > purpose of serving as a home for module-based constructor-esque > functions We're not adding any such modules. > and without having to add more builtin functions, etc. If the name "dictionary" was presumed available in dictionary.newFromList() above without first having to import some special module, then "dictionary" was perforce a builtin name anyway, function or not. I know you focus on the "function" part, but it's the "builtin" part that matters . > (Guilty as charged of more Smalltalk-hardwiring-of-the-brain thinking ;-) I've heard that Smalltalk's class-method constructors work very well there. Python took a different approach long ago, and it also appears to work well. From mmealman at tarsis.org_NOSPAM Wed Oct 10 10:13:51 2001 From: mmealman at tarsis.org_NOSPAM (Mark) Date: 10 Oct 2001 09:13:51 -0500 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> <7xd73x1cgf.fsf@ruckus.brouhaha.com> <9pvhra$4me$1@animus.fel.iae.nl> Message-ID: In article <9pvhra$4me$1 at animus.fel.iae.nl>, Carel Fellinger wrote: > Mark wrote: > ... >> No. If I wrote a module and placed it under the GPL, I still own the >> copyright on that module. >> That gives me the right to release that code under any other license as I >> see fit, even though I can never take away anyone's right to use it under >> the GPL. > > That depends. IIRC, if you get substantial contributions from a > particular person that person owns the copyrights for his/her > contributions. Small contributions, on the other hand, *probably* > don't `leak' copyright, so if you only accept small patches you might > be safe, in general you aren't. That's pretty much what I was talking about, smaller code contributions. >> IMHO submitting patches to a program does not give you any copyright hold >> over that program, although I don't think it's been legally tested yet. > > Ofcourse you don't get copyright over the full program, but you get to > keep the copyright of your own patches, atleast when they are > sufficient substantial. Agreed. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From jedi at group6.net Tue Oct 23 06:55:27 2001 From: jedi at group6.net (jedi) Date: Tue, 23 Oct 2001 03:55:27 -0700 Subject: interactive interpreter In-Reply-To: <20011023193958.A8072@shield.bsdirc.net>; from spaceman@bsdzine.org on Tue, Oct 23, 2001 at 07:39:58PM +0200 References: <20011023034251.D68373@group6.net> <20011023193958.A8072@shield.bsdirc.net> Message-ID: <20011023035527.E68373@group6.net> Here, try this. I wrote a test script called test.py: #!/usr/local/env python x=0 while x < 5: print "'ere we go!" x = x + 1 Then I ran like: bash-2.05$ python test.py 'ere we go! 'ere we go! 'ere we go! 'ere we go! 'ere we go! bash-2.05$ ~ Then I tried: bash-2.05$ python Python 2.1 (#1, Apr 24 2001, 16:26:59) [GCC 2.95.3 [FreeBSD] 20010315 (release)] on freebsd4 Type "copyright", "credits" or "license" for more information. >>> import test 'ere we go! 'ere we go! 'ere we go! 'ere we go! 'ere we go! >>> Does that help? On Tue, Oct 23, 2001 at 07:39:58PM +0200, Karol Makowski wrote: > On Tue, 2001-10-23 at 03:42:51, jedi wrote: > > jedi> import it from the interpeter cli. > > i created test.py and print "something" inside it. > i tried to 'import test.py' but nothing has happened. > > -- > Karol Makowski, System Administrator > URL: http://spaceman.bsdzine.org > e-mail: spaceman at bsdzine.org -- j3di jedi at group6.net http://jedi.group6.net/ From aleaxit at yahoo.com Thu Oct 11 17:43:00 2001 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 11 Oct 2001 23:43:00 +0200 Subject: Does Python license permit embedding in commercial product ? References: <8a12e538.0110111318.76668cf3@posting.google.com> Message-ID: <9q53p701m94@enews1.newsguy.com> Russell Turpin wrote: > This is sort of the opposite case of wanting to sell a program > written in Python, which clearly is allowed. Consider a > commercial product that needs a scripting language. One The intention of the Python license (much like the classic BSD and X licenses) is to permit and encourage this. Whether its legal effect is indeed that, when, IANAL, but... > (Obviously, if we do extend Python in any way, we'll release > *that* code. But that's not currently in the plans.) It's not something you HAVE to do by Python's license (although of course it's good citizenship and smart PR to do so). If you extend and modify Python (or X, or BSD, ...) you're legally entitled to keep your extensions under wraps (again, license-intention-wise). Very different from GPL and LGPL, of course -- and intentionally so. This is not the right forum to debate pro or con either stance, of course. Alex From vulpine at dontspam.earthling.net Wed Oct 3 01:20:38 2001 From: vulpine at dontspam.earthling.net (Tod Fox) Date: Wed, 03 Oct 2001 05:20:38 GMT Subject: Past command buffer gone in interpreter? Message-ID: I am using Redhat 7.1. I was using the python installed by Redhat (1.5.2 I think), but I decided to upgrade to 2.1.1. It installed without any apparent problems and was able to run the test without any major failures. However, a minor aspect of the interpreter has now changed; I can no longer use the up and down arrow keys to return to past commands I have entered -- it prints garbage characters on the screen instead. I can't tell if this is really an issue with python, or what could be causing this. I've tried to look through the documentation for this kind of thing, but if I have missed something I will read it if it is pointed out to me. Thanks, Kit From tjreedy at home.com Wed Oct 17 12:40:42 2001 From: tjreedy at home.com (Terry Reedy) Date: Wed, 17 Oct 2001 16:40:42 GMT Subject: string.digits, string.letters? How? References: <3BCDCC6F.16954B08@starhub.net.sg> Message-ID: "Paul Lim" wrote in message news:3BCDCC6F.16954B08 at starhub.net.sg... > Hi again to all, > > I am a newbie in Python and please really pardon me for my trivial > question. > > How can we use the digits, letters variable in the string modules? > > I have the following snippet of my code > > # Import library modules > # ====================== > > import sys > from string import lower, find, atoi, digits, letters > > if digits(sys.argv[i+1]): > print "Invalid argument" > > but i get the error message > File "test.py", line 32, in ? > if digits(sys.argv[i+1]): > TypeError: object is not callable: '0123456789' > > What is wrong? Try print type(digits), digits, type(argv[i+1]) and see what you get. Print (and type() are your debugging friends. Then try for char in sys.argv[i+i]: if char in digits: print "Bad" Terry J. Reedy From sholden at holdenweb.com Tue Oct 16 13:48:21 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 16 Oct 2001 13:48:21 -0400 Subject: Python COM for Microsoft Project References: Message-ID: A Google search (have you seen www.google.com ?) for microsoft project object model should give you plenty of details about the API, which is usually where one needs information in starting to drive a new application via COM. In particular, http://msdn.microsoft.com/library/en-us/dnpom/html/pjtocobjectmodelapplicati on.asp?frame=true looks useful. regards Steve -- http://www.holdenweb.com/ "Mike Brenner" wrote in message news:mailman.1003186882.938.python-list at python.org... > Has anyone played with Python to control Microsoft Project? > > It is, of course, easy to open a MP file: > > from win32com.client import Dispatch > mpApp = Dispatch("MSProject.Application") > mpApp.Visible = 1 > mpApp.FileOpen ("C:\Documents and Settings\projectA.mpp") > # Warning: works only with absolute file names. > > > For the next line of code, I would like to resave the file as a tab-delimited file for further processing in Python. Actually, I will build a robot that opens all the MP files and resaves them. > > - Is there a URI to download the objects and methods that are now available? > > - Or is the list of objects somehow hidden inside my Visual Studio or my Microsoft Developer CDs? > > - Or do I need to buy Visual Basic for Applications or some other application to gain access to the objects? > > - Is there an upgrade to the COM object browser that comes with Python for Windows? > > Thanks > Mike Brenner > > From skip at pobox.com Thu Oct 4 22:11:59 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 4 Oct 2001 21:11:59 -0500 Subject: Profiling the interpreter from within Message-ID: <15293.5871.207013.564718@beluga.mojam.com> gb> The extension, I hallucinate, would turn on statistical profiling gb> using the same interrupt mechanism used to get the times reported by gb> gprof. It works by setting a timer to go off 100 times per gb> second. On each interrupt it examines the return address and gb> increments a counter in an array indicating a "hit" on that address gb> (actually range of addresses). By adding up the counts for the range gb> of addresses included in a function you can get an estimate of the gb> time spent in that function. In theory, that would work okay, however, since the python interpreter is so much slower than real hardware, I think you'd have to have much longer runs to make the statistical sampling very accurate. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From ignacio at openservices.net Fri Oct 5 03:08:44 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 5 Oct 2001 03:08:44 -0400 (EDT) Subject: Boy do REs ever suck sometimes... In-Reply-To: Message-ID: On Fri, 5 Oct 2001, Tim Peters wrote: > [Ignacio Vazquez-Abrams] > > Here's the problem I'm having with REs. When I use an RE like > > '^[0-9]+$' it matches both '123' and '123\n'. How can I get it to not > > match the string with the newline? > > A straightforward way: > > >>> import re > >>> pat = re.compile(r'\d+\Z') > >>> pat.match('123') > > >>> pat.match('123\n') > >>> Ah, beautiful; just what I was looking for. Thank you. > A sicker way: > > >>> pat = re.compile(r'\d+(?!\n)$') > >>> pat.match('123') > > >>> pat.match('123\n') > >>> Well, it works, but the other way is definitely more explicit. > you-can't-truly-give-up-regexps-before-mastering-them-ly y'rs - tim Not giving up, just figuring them out ;) -- Ignacio Vazquez-Abrams From fgeiger at datec.at Fri Oct 12 10:19:53 2001 From: fgeiger at datec.at (F. GEIGER) Date: Fri, 12 Oct 2001 16:19:53 +0200 Subject: J2EE equivalent in Python References: Message-ID: <9q6u8u$8k8$1@newsreaderg1.core.theplanet.net> > Object-Relational Mapping (JDO): Not available AFAIK. Webware's MiddleKit? MK enables you to access an RDB in an OO manner. MK is usable standalone. Example (sketchy and incomplete): customers = Customer.fetchAll() for customer in customers: print cutomer.address().city() print customer.address.country() etc. Cheers Franz P.S.: You can find MiddleKit here: webware.sourceforge.net "Gerhard H?ring" schrieb im Newsbeitrag news:slrn9sdn54.227.gerhard.nospam at lilith.hqd-internal... > On 12 Oct 2001 11:51:36 +0100, Robin Smith wrote: > >I like J2EE but I am also an open source fan. I don't like what I read > >about Sun and restricting Java - > >http://www.onjava.com/pub/a/onjava/2001/10/10/osjava.html . > > > >Is there anything similar to J2EE for python? > > Take the following with a grain of salt, my experiences with J2EE are > limited to swearing because of incomprehensible error messages from > Persistence Powertier ;-) > > J2EE is a bunch of APIs thrown together, right? So we can examine the > APIs one for one. > > Servlets/JSP: Python has a gazillion equivalents. There's a page that > compares them all, but I don't have the URL atm. > > Distributed sytems: There are several ORBs. I like omniORBpy, for > example. Then there are several SOAP > implementations. And easy-to-use Python-only > solutions like PyRO. And XML-RPC. > > JDBC: Python DB-API 2.0. > > Persistence (EJB): ZODB (included in ZOPE or available standalone). > > Object-Relational Mapping (JDO): Not available AFAIK. > > ZOPE probably comes closest to a J2EE server. It has something called > ZEO if you need to scale up. > > If you're adventurous, you can of course mix and match the APIs you > like. And btw. there are also several ZOPE-light's: WebWare, SkunkWeb, > Aquarium, ... I only tried WebWare and liked it. > > Gerhard > -- > mail: gerhard bigfoot de registered Linux user #64239 > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 > public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 > reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From robin at jessikat.fsnet.co.uk Sat Oct 13 05:09:18 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 13 Oct 2001 10:09:18 +0100 Subject: signum() not in math? References: <3BC7FE9B.CD190C62@darwin.in-berlin.de> Message-ID: In article <3BC7FE9B.CD190C62 at darwin.in-berlin.de>, Dinu Gherman writes >Tim Peters wrote: ..... >The reason for people not complaining about the absence of the >sign() function need not necessarily be that they use something >like tanh() more often (I doubt so), but simply because they >can write sign() with far less difficulty than tanh(). > .... that may be so, but while some write this def sign(x): if x < 0: return -1 elif x > 0: return 1 else: return 0 others might use def sign(x): if x<0: return -1 else: return x>0 only an insider could tell us if the latter is guaranteed always to work now and forever. If truth gets redefined as -1 then the second would fail badly. Also there is controversy about what the sign function should actually be. Indeed the matrix sign function is a true heaviside function (http://rkb.home.cern.ch/rkb/AN16pp/node117.html) on each element x the result is 2*h(x)-1 ie -1 for x<0 and 1 for x>=0. Probably python should provide both the three value signum and the two value one and perhaps the sign transfer operation. These are so common in maths, physics and engineering it seems wrong to have sinh() without h() et al. -- Robin Becker From nomad*** at ***freemail.absa.co.za Wed Oct 17 06:35:01 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Wed, 17 Oct 2001 12:35:01 +0200 Subject: Cgi Counter References: <7xlmibk7p7.fsf@ruckus.brouhaha.com> Message-ID: On 16 Oct 2001 15:05:37 +0100, Dominic Mitchell wrote: >Paul Rubin writes: >> Nomad writes: >> >> > On Fri, 12 Oct 2001 12:59:04 -0700 (PDT), Neal Irwin >> > ...> >> > fileWrite = open('count.txt', 'w') >> > fileWrite.write(str(intHits)) >> > fileWrite.close >> > ... >> > Pretty simple, but it works... >> >> Um, what happens if two requests (coming from different processes in >> the web server) run the hit counter at the same time? You need some >> kind of interlocking for this to be reliable. > >Alternatively, if you don't mind losing the occaisional hit, you could >just write to a temp file and rename into place. Renaming is an >atomic operation (under Unix, anwyay, dunno about win32), so you won't >get corruption, just a few lost hits. > >-Dom Thanks for the hints. At the time it was a two-minute-solution, and, as the site wasn't very high traffic, it worked. For the site in question hits weren't particularly important, but just there to show the other visitor that there was interest in the conference. I'll definitly bear file contention in mind if I need counters again in the future. -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From guido at python.org Tue Oct 23 20:15:23 2001 From: guido at python.org (Guido van Rossum) Date: Wed, 24 Oct 2001 00:15:23 GMT Subject: Few questions about new features in Python 2.2 References: <7da8d8f8.0110230006.36933486@posting.google.com> Message-ID: s.keim at laposte.net (sebastien) writes: > How to overload builtins constructor? > ------------------------------------- > I have tried something like: > class xxx (int): > def __init__(self, x, y): > int.__init__ (self, x*y) > That doesn't seem to work. Use __new__ instead of __init__ for immutable constructors. There are tons of examples in Lib/test/test_descr.py. This particular one could be written: class I(int): def __new__(cls, x, y): return int.__new__(cls, x*y) > What is the goal for __floordiv__ ? > ----------------------------------- > I doesn't understand why to have appended this special method. > For me with or without from __future__ import division, the new // > operator could > call the old __div__ method. > Or there is a pitfall that I haven't seen? Objects may define both / and // with different semantics (/ returning a float and // returning a truncated int), so you need to be able to overload two different operators. That's what __floordiv__ is for. Because classic division might either map to / or to //, depending on the type, you can overload all three separately: __div__ for classic /, __floordiv__ for //, and __truediv__ for / under the future statement. Typically, __div__ should be just an alias for either of the others -- but Python can't know whether your object type is int-like or float-like, so it can't know which one to choose. --Guido van Rossum (home page: http://www.python.org/~guido/) From skip at pobox.com Thu Oct 4 22:14:05 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 4 Oct 2001 21:14:05 -0500 Subject: (no subject) Message-ID: <15293.5997.312594.517674@beluga.mojam.com> Leonardo> Thanks for the tip. I actually have used the explain Leonardo> statement. But are you sure about the profiler ignoring the Leonardo> time taken by the query? Why would it be excluded from the Leonardo> computation time? If the profiler is measuring cpu seconds, it will be measuring the computation time of the Python process. The computation time of other processes involved in the computation (possibly on other machines) just isn't available to it. If it's measuring elapsed (wall clock) time, then sure, it gives you some measure of the time it takes for the entire computation to complete. However, that would include networking delays as well as delays caused by either or both the Python program and the MySQL database server not actually having the CPU. Leonardo> How would the profiler even be able to distinguish between Leonardo> time waiting in a function for some external process and time Leonardo> spent in the python interpreter itself? The profiler uses time.clock() if it's available, which is generally true on most Unix-like systems. Again, on Unix-like systems, time.clock() returns the CPU time of the current process, not the elapsed time. From the clock() man page: DESCRIPTION The clock() function returns an approximation of processor time used by the program. Leonardo> I checked the manual for the profiler section. It says that Leonardo> the profiler is activated by callbacks when functions are Leonardo> called and when they return, so if a function is blocked Leonardo> waiting for mysql, that time should be computed. It all depends. Take a look at the code in the Profile class's __init__ method: if not timer: if os.name == 'mac': self.timer = MacOS.GetTicks self.dispatcher = self.trace_dispatch_mac self.get_time = _get_time_mac elif hasattr(time, 'clock'): self.timer = self.get_time = time.clock self.dispatcher = self.trace_dispatch_i elif hasattr(os, 'times'): self.timer = os.times self.dispatcher = self.trace_dispatch self.get_time = _get_time_times else: self.timer = self.get_time = time.time self.dispatcher = self.trace_dispatch_i If you're running on Windows (I think you said something about Linux), then time.clock is either unavailable or is, but doesn't record CPU time. On Linux systems it does (though to varying degrees of (in)accuracy). -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From cgale1 at _remove_home.com Wed Oct 3 01:24:44 2001 From: cgale1 at _remove_home.com (Van Gale) Date: Wed, 03 Oct 2001 05:24:44 GMT Subject: Network programming in python References: <9pdf61$13c6@r02n01.cac.psu.edu> Message-ID: Rajarshi, If this is more than an educational project you'll need to do some full research on network programming in general. Check out "Unix Network Programming Vol. I" by W. Richard Stevens. It is a classic and pretty much regarded as a bible. I don't know if there are any online resources that can explain server models as good as that book. It's important to understand the different server models like single-process, single-process multiplexing, forking, pre-forking, or threaded before you pick the path you want to go down in Python. Once you think you understand server models and their tradeoffs and socket programming in general, you need to start researching the Python options. At the lowest level is the socket module. Read http://www.mcmillan-inc.com/sock1.html for a quick HOWTO on using sockets at the lowest level for client-server programming. At a higher level things get a little murkier, which is why you need to understand server models. You have three choices here: 1) you can write your own code directly on top of sockets, 2) you can use the SocketServer module or 3) you can use the asyncore module. SocketServer processes requests synchronously (single-process model), but you can use the ForkingMixIn class to easily switch to a forking model, or the ThreadingMixIn class to easily switch to a threading model. The SocketServer classes are pretty easy to use and much of the higher level Python library modules use them. They are not complicated to understand and the Python library documentation and Fredrik Lundh's book "Python Standard Library" cover them pretty well. The asyncore module will probably provide better performance with its single-process multiplexing model, but there are a few drawbacks. First, it's a more complicated model to grok, then add to that "the source is the documentation". You'll need to download Medusa from www.nightmare.com and study that code. Medusa gives you http, ftp, and xmlrpc classes on top of asyncore. To make things even more complicated, if you need to add threading you'll need to download Zope and study how they implemented threading on top of asyncore in the Zope ZServer. The Nightmare web site has links to many good resources about network programming. As for how to "construct your messages" you can look at how http and ftp messages are constructed by reading the appropriate modules in the Python library or in medusa. The Python library also has modules for gopher, imap, pop, smtp, telnet, and nntp that you can use for ideas. Or you can go directly to the protocol documents written as RFC's. http://www.cis.ohio-state.edu/Services/rfc/ is one place to browse RFC's. If you are going to write clients in C/C++ I would recommend using a message format like netstrings (see http://cr.yp.to/proto/netstrings.txt for info). A Python implementation of netstrings can be found at ftp://ftp.tummy.com/pub/tummy/Python/netstring/ Another option for constructing messages is to use SOAP or XML-RPC. XML-RPC is less complicated than SOAP, but more limited in capabilities. Both SOAP and XML-RPC will work on top of either SocketServer or asyncore. As another poster pointed out, these modules make network programming *really easy* because it abstracts it to a simple Python function or method call. Example: Let's say you want to send two numbers from a client to your server, have the server add them together and then return the result. On the server you do this-- > import SOAP > def add (x, y): return x + y > server = SOAP.SOAPServer(('localhost',9900)) > server.registerFunction(add) > server.serve_forever () On the client you do this-- > import SOAP > server = SOAP.SOAPProxy("http://localhost:9900") > print server.add (23, 4) Simple eh? Unfortunately there are drawbacks :) SOAP and XML-RPC messages are constructed as valid XML documents, which have some limitations such as binary data needing to be encoded as text (usually as base64) which can expand message size. This shouldn't be a problem if all your clients and servers are on a LAN, but if you're passing megabyte sized files and have clients on dial-up... uh not good. (I think the Actzero SOAP.py is going to support binary files as mime attachments, but it's not there yet). Another problem is performance. Usually each function call opens a new connection then closes it when the result is returned which can get expensive. So, this is far from complete answer, but I hope I'm giving you an idea of which way to go in your research! Van From lokie.spods at ntlworld.com Thu Oct 4 04:18:14 2001 From: lokie.spods at ntlworld.com (lokie.spods) Date: Thu, 4 Oct 2001 09:18:14 +0100 Subject: Profiling the Python Interpreter References: Message-ID: wrote in message news:uzo79muqw.fsf at cs.unc.edu... > I'm not asking about profiling Python programs here. I'm very > familiar with that. > > I want to profile the python interpreter itself. My goal is to > discover where the time goes and in particular why the Cygwin version > runs about 30% slower than the native version on win2k. > An easy question to answer without the need for profiling the Python interpreter. Cygwin essentially provides an API layer between the host OS and the compiled code, adding a nice speed bottleneck. -- Anthony McDonald From lucio at movilogic.com Thu Oct 25 18:40:50 2001 From: lucio at movilogic.com (Lucio Torre) Date: Thu, 25 Oct 2001 19:40:50 -0300 Subject: Question: Dynamic code import References: <3bd88de8_2@corp-goliath.newsgroups.com> Message-ID: <3BD894F2.4050902@movilogic.com> K?roly Ladv?nszky wrote: >Being really new in the Pyhton world, I'm not sure what else than text files >(.py) could come into view. >To put it simple, I'd like to have a def f11(a) in a file and read it in >and use f11 like the functions in the >running script. Its something else than using 'import' as the file may not >be existent at all when the script >starts running. In Lisp, the 'load' function does this. > you can do import whenever you please. >>> if 0: import foo ... >>> if 1: import foo ... Traceback (most recent call last): File "", line 1, in ? ImportError: No module named foo >>> if you want to import and make sure the globals are locals are what you want, you can call __import__ __import__(name[, globals[, locals[, fromlist]]]) This function is invoked by the import statement. It mainly exists so that you can replace it with another function that has a compatible interface, in order to change the semantics of the import statement. For examples of why and how you would do this, see the standard library modules ihooks and rexec . See also the built-in module imp , which defines some useful operations out of which you can build your own __import__() function. For example, the statement "import spam" results in the following call: __import__('spam', globals(), locals(), []); the statement "from spam.ham import eggs" results in "__import__('spam.ham', globals(), locals(), ['eggs'])". Note that even though locals() and ['eggs'] are passed in as arguments, the __import__() function does not set the local variable named eggs; this is done by subsequent code that is generated for the import statement. (In fact, the standard implementation does not use its locals argument at all, and uses its globals only to determine the package context of the import statement.) From eric at enthought.com Thu Oct 25 22:32:53 2001 From: eric at enthought.com (eric jones) Date: Fri, 26 Oct 2001 02:32:53 GMT Subject: HELP -- py2exe failed to build app that uses scipy.plt References: <436bca17.0110181944.247f4ecd@posting.google.com> <16f9b1ea.0110250718.7ccc7fe9@posting.google.com> <9r9j6h$sak0p$1@ID-59885.news.dfncis.de> Message-ID: > An additional problem (I've looked into it) leading to the > syntax error Phil gets is that scipy contains files with > very strange line separators '\r\r\n' IIRC. That doesn't sound good. I'd like everything to use Unix file format. We'll work on rooting this out. If anyone has a tool to run on the tree to correct the problem, I'd be much obliged. eric From phr-n2001d at nightsong.com Sun Oct 21 18:17:28 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 21 Oct 2001 15:17:28 -0700 Subject: Random from Dictionary References: Message-ID: <7xd73gwscn.fsf@ruckus.brouhaha.com> Martin von Loewis writes: > "Tim Peters" writes: > > > Season to taste. In 2.2 you could use a more memory-efficient scheme via > > iterating over d directly: > > > > def random_from_dict(d, x): > > "Return and remove x random (k, v) pairs from d." > > from random import random > > n = float(len(d)) # float() so x/n later doesn't truncate to 0 > > if not 1 <= x <= n: > > raise ValueError("go away") > > result = [] > > for k in d: > > # Choose this item with probability x/n. > > if random() <= x/n: > > result.append((k, d[k])) > > x -= 1 > > if x == 0: > > break > > n -= 1 > > for k, v in result: > > del d[k] > > return result > > Does that give each key in the dictionary the same probability of > being picked (assuming random() distributes uniformly)? If yes, is > there some easy way to "see" that this is the case? If no, could one > design an algorithm that iterates over a dictionary only once, still > offers the same probability to each key? See "Programming Pearls", by Jon Bentley, for discussion of this algorithm. Basically though look at the case x=1 and convince yourself that you'll pick one element from the dictionary with uniform probability. Then generalize to x>1. From zen at shangri-la.dropbear.id.au Sat Oct 13 01:08:46 2001 From: zen at shangri-la.dropbear.id.au (Stuart Bishop) Date: Sat, 13 Oct 2001 15:08:46 +1000 Subject: PostgreSQL Interface Query In-Reply-To: <3BC7BD91.A604728C@iinet.net.au> Message-ID: <60F8F7C0-BF98-11D5-A0A8-000393031882@shangri-la.dropbear.id.au> On Saturday, October 13, 2001, at 02:05 PM, John Bell wrote: > I have been evaluating various Python interfaces to PostgreSQL. So far > as I've been able to determine the options are PygreSQL (packaged with > PostgreSQL), PoPy, psycopg and a new entrant, pypgsql. I am leaning > towards pypgsql (available from SourceForge) based on an comparitive > assessment of functionality only. However, as pypgsql is just under a > year old and I've never heard it mentioned on any major Python or > PostgreSQL forum before I am somewhat concerned regarding its > stability. I would be very interrested in comments from anyone with > experience of the pypgsql package. I got as far as checking its threadsafety - level 1 compliance is a major lack to me. I also stick to using the DB API, so I can't see any improvement in functionality to PoPy or Psycopg. If you only want a thread level 1 compliant driver, is there any real advantage over using PyGreSQL which is shipped as part of PostgreSQL? These issues may be the reason there is a lack of commentary on pypgsql. The other reason is that it must be a secret, as it still hasn't made it onto the DB-SIG's modules list. -- Stuart Bishop From Randy.L.Kemp at motorola.com Wed Oct 31 09:08:22 2001 From: Randy.L.Kemp at motorola.com (Kemp Randy-W18971) Date: Wed, 31 Oct 2001 08:08:22 -0600 Subject: Freeware Python editor Message-ID: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> Check out the free Python editor at www.crimsoneditor.com. From martin.franklin at westgeo.com Mon Oct 29 05:20:41 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Mon, 29 Oct 2001 10:20:41 +0000 Subject: tkinter-canvas-rectangle-delete References: Message-ID: <9rjafo$2m3e$1@mail1.wg.waii.com> huber wrote: > Can someone tell me what I am doing wrong ? > > from Tkinter import * > > def delz(): > for i in c.find_all(): > print c.gettags(i) > c.delete("200") > > root=Frame() > > c=Canvas(root,width=100,height=100) > n=c.create_rectangle(0,0, 10,10, fill="red",tag="res") > c.addtag_withtag("200",n) > > b=Button(text="delete 200",command=delz) > b.pack() > c.pack() > root.pack() > > root.mainloop() > > the output is : > ('res', '200') > ('res', '200') > ........... > > > ther rectangle is not deleted by clicking ther button ! > if I delete the elements with tag="res" ( c.delete("res") ) the > rectangle will be deleted! > > I am using : tk8.3.3 , tcl8.3.3 , python 2.1.1 on Suse linux 7.3 > > thanks in advance > Don't know the real 'reason' but change the 200 to just chars. 'TWO' for example and it works.. Tk/Tcl/Tkinter must be reading 200 as an ID not a TAG? HTH, Martin. From jwbaxter at spamcop.net Thu Oct 11 00:40:29 2001 From: jwbaxter at spamcop.net (John W. Baxter) Date: Wed, 10 Oct 2001 21:40:29 -0700 Subject: Curious assignment behaviour References: Message-ID: <101020012140297889%jwbaxter@spamcop.net> In article , John Roth wrote: > and its the reason that > Algol chose ":=" as the assignment operator, with Pascal following > in that path. Which I prefer, even though: I never used a keyboard on which : and = used the same state of the shift key. (I used a few which were the reverse of what we--on US keyboards--now expect, with : unshifted and = shifted.) Thus (on current US keyboards), one sees occasional ;= and :+ (which fortunately aren't symbols of many languages and generally lead to syntax errors). --John From sholden at holdenweb.com Tue Oct 16 11:51:12 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 16 Oct 2001 11:51:12 -0400 Subject: Extracting attachments with Python? References: <0B%x7.10230$YC3.3926894@typhoon.southeast.rr.com> Message-ID: "Chris Tavares" wrote in ... > I just took a look at this, and the code seems to be missing some stuff from > the top - it just starts in the middle of a function. Or is it just me? > > -Chris > [ ... indirect references to http://www.holdenweb.com/Python/dbxread.py ... ] Well, nobody else has complained, and *I* certainly see a complete Python program. Anybody else got problems? wouldn't-be-my-first-screwup-ly y'rs - steve -- http://www.holdenweb.com/ From tnaran at direct.ca Fri Oct 5 10:52:06 2001 From: tnaran at direct.ca (Travers Naran) Date: Fri, 5 Oct 2001 07:52:06 -0700 Subject: problem controlling MS Word from Python References: Message-ID: <9pkhei0rbe@enews2.newsguy.com> "Andrew Brown" wrote in message news:Xns91318A690C6E2andrewdarwinwarscom at 62.253.162.107... > I'd have thought that, since all the calls to Word are wrappred in "try" > blocks, there should not be a problem when Word throws up a dialogue box. > But there is. The whole thing crashes. Does anyone know why this happens, or > how to avoid it? Can you clarify what you mean by "crashes"? Does python return a traceback, or does the python interpreter itself crashes? I wouldn't be surprised if it was the later: I've noticed Office apps connected by automation can crash the client. From gherman at darwin.in-berlin.de Sat Oct 13 06:09:34 2001 From: gherman at darwin.in-berlin.de (Dinu Gherman) Date: Sat, 13 Oct 2001 12:09:34 +0200 Subject: signum() not in math? References: <3BC7FE9B.CD190C62@darwin.in-berlin.de> Message-ID: <3BC812DE.8C6C260@darwin.in-berlin.de> Robin Becker wrote: > > that may be so, but while some write this > > def sign(x): > if x < 0: return -1 > elif x > 0: return 1 > else: return 0 > > others might use > > def sign(x): > if x<0: return -1 > else: return x>0 > > only an insider could tell us if the latter is guaranteed always to work > now and forever. If truth gets redefined as -1 then the second would > fail badly. That's one more argument for having a function with a *defined* behaviour! In any case this is *not* about truth values, but about arithmetics! > Also there is controversy about what the sign function should actually > be. Not quite sure. If there is then it's going to be about the value at x = 0. I think 0 is what math dictates while -1 or +1 is what is more convenient in certain cases... which can be handled with an optional second argument to sign(). > Indeed the matrix sign function is a true heaviside function > (http://rkb.home.cern.ch/rkb/AN16pp/node117.html) on each element x the > result is 2*h(x)-1 ie -1 for x<0 and 1 for x>=0. > > Probably python should provide both the three value signum and the two > value one and perhaps the sign transfer operation. These are so common > in maths, physics and engineering it seems wrong to have sinh() without > h() et al. One free pint! ;-) Well, yes a general step() function could be useful, too, maybe like this, even if you don't find it usually in entry-level math textbooks: def step(x, x0=0): "Generalised Heaviside step function." if x < x0: return 0 else: return 1 > In article , Harald Hanche-Olsen > writes > > > >>>> import math > >>>> math.atan2(0.,-1.) > >3.1415926535897931 > >>>> math.atan2(-0.,-1.) > >-3.1415926535897931 > > > perhaps we need some new type to distinguish numbers which might result > in this behaviour. Then we could have a flame war about introducing it > :) Looks like we have these JanusNumbers already. They change face depending on their context: >>> from math import * >>> tan(-0. + pi/2) 16331778728383844.0 >>> tan(0. + pi/2) 16331778728383844.0 and: >>> 0. 0.0 >>> -0. 0.0 Even-more-baffled'ly, Dinu -- Dinu C. Gherman ................................................................ "The world becomes a better place as a result of the refusal to bend to authority and doctrine." (Noam Chomsky) From collinda at nortelnetworks.com Wed Oct 31 00:33:08 2001 From: collinda at nortelnetworks.com (Darren Collins) Date: Wed, 31 Oct 2001 16:33:08 +1100 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> Message-ID: <9ro2am$p5b$1@bcarh8ab.ca.nortel.com> > i don't think data hiding's purpose is to keep rogue programmers in > line. ... > ... since the entire code of the class is > exposed (unless you split off a portion of it into a hidden base > class), it's doubly enticing to use stuff you're not supposed to. > I don't follow your reasoning here. These statements seem contradictory to me. If people can see that something is supposed to be private, but they absolutely need access to it, then they have just discovered an interface problem. They can either fix the interface or put a quick hack in their code to to work around it by accessing the 'private' member. But they put in the hack knowing that they are breaking the original designer's intentions, so they're on their own. It is nice that you can do this when you really need to, though. From grante at visi.com Wed Oct 10 11:36:59 2001 From: grante at visi.com (Grant Edwards) Date: Wed, 10 Oct 2001 15:36:59 GMT Subject: Sockets References: Message-ID: In article , Hugo Martires wrote: > My server need to send 2 strings separeted: > s1= 'xxx' > s2= 'yyy' > > My client must received like this: > rec1= 'xxx' > rec2= 'yyy' > > The problem is that the Client received s1 and s2 in one only string. > > How can i received in 2 separeted variables ? Use a datagram service, or impose a datagram protocol on top of a stream service. I think the world really needs a reliable datagram service to sit alongside TCP and UDP... -- Grant Edwards grante Yow! I will establish at the first SHOPPING MALL in visi.com NUTLEY, New Jersey... From samschul at pacbell.net Tue Oct 2 16:01:11 2001 From: samschul at pacbell.net (Samuel Schulenburg) Date: 2 Oct 2001 13:01:11 -0700 Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> Message-ID: Oleg Broytmann wrote in message news:... > On Tue, Oct 02, 2001 at 08:59:34AM -0500, Paul Miller wrote: > > If GNU code is FREE, then I'll have to say that Python (and code under > > BSD-style licenses) is BETTER THAN FREE. Frankly, I'm very grateful to > > Guido for allowing Python to be used freely in commercial software. > > I see your point. You use other's people work without paying them. GNU > GPL, at least, force you to pay (by publishing your code). You don't want > to pay, and Python license makes you happy :( > > Oleg. > ---- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. Sometimes you have code that you want to release with a commercial product, that contains propriatary information about the internals in your product. A GPL license would keep you from releasing this code using Python. If you want to use a commerical script language, it's hard to find one that allows you to use it commerically, without adding restrictive clauses on its use. I have lost track of the number of script language's that I have been exposed to while working for various companies in the disk drive industries. All these script languagues were poorly developed, but they were developed to get around the limitations provided by the commerically available languages. Python was the first language I found that meet the reqirements that I needed. ( Extendable, and Embeddable) Sam Schulenburg From johnroth at ameritech.net Mon Oct 15 14:40:07 2001 From: johnroth at ameritech.net (John Roth) Date: Mon, 15 Oct 2001 11:40:07 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: "Tim Peters" wrote in message news:mailman.1003089072.26009.python-list at python.org... > [Tim] > > If people sign off on taking "then" as a new keyword, I think > > the chances are good that we could get > > > > x = if e1 then e2 else e3 > > > > into 2.2b1. That's the only obvious spelling, hence the only > > truly Pythonic way to spell it. Other languages spelling it that > > way range from Algol-60 (Guido's first intense language affair) to > > Haskell. > > [Paul Rubin, among others of similar mind] > > This sounds fine to me. > > Alas, it didn't to Python's parser -- one-token lookahead isn't enough to > distinguish > > if 1: > > from > > if 1 then 2 else 3 > Huh? The purpose of the new syntax is to have a conditional facility within an expression. If a new line begins with the keyword 'if', then that is a statement. A conditional if only makes sense _inside_ an expression, hence it doesn't look like there is an issue. A bigger issue from a usability standpoint is the lack of a clear end to the scope of a given 'if', leading to the infamous dangling 'else' problem. John Roth From emile at fenx.com Sat Oct 6 11:07:21 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 6 Oct 2001 08:07:21 -0700 Subject: compiling Python 2.x.x on redHat 7.0 References: Message-ID: <9pn6vp$jndfh$1@ID-11957.news.dfncis.de> This may be the same problem I had last year. Look in xopen_lim.h for #define LONG_BIT 64 and change the 64 to 32. HTH, -- Emile van Sebille emile at fenx.com --------- "Michal Seta" wrote in message news:B7E42554.4AFE%mis at creazone.com... > Hi All. > > The time came to upgrade Python to a version 2.x. > > I tried to compile but any major version 2 I take gives the same error: > #error "LONG_BIT definition appears wrong for platform (bad gcc config?)" > > Apparently the libc/gcc gives the LONG_BIT 64 instead of 32 on some > platforms. How can this be fixed/corrected? > > RedHat7.0, Celeron 533 MHz, gcc version 2.96. > > Thanks in advance. > > > ./Mike > From chris at onca.catsden.net Tue Oct 2 15:20:34 2001 From: chris at onca.catsden.net (chris at onca.catsden.net) Date: Tue, 2 Oct 2001 12:20:34 -0700 (PDT) Subject: Need help finding Python/TKinter Link Checker In-Reply-To: Message-ID: On Tue, 2 Oct 2001, Chris Cogdon wrote: > > Some time ago I found a marvellous little web link checker, written in > Python, and had an optional Tk interface which looked great for seeing > what it was currently working on, what it had already checked and what was > still left to do. > > However, it seems to have erased itself from existance; from my hard > drive, software archive, and freshmeat. Does anyone know what it might be > called, and where it might be located? > > I'm looking for the one with the Tk interface, not the CGI-based ones. > > TIA for any assistance. I've just been 'reminded' that the program I'm referring to actully comes with the Python distribution, in the Tools directory. I feel /so/ stupid now. Thanks to all the folks that wrote, and didn't laugh at me too much :) Now that I know, its no wonder that there's so few listings for this on Freshmeat... the best tool around comes with the distribution! How about that! :) ("`-/")_.-'"``-._ Ch'marr, a.k.a. . . `; -._ )-;-,_`) Chris Cogdon (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' FC1.3: FFH3cmA+>++C++D++H++M++P++R++T+++WZ++Sm++ ((,.-' ((,/ fL RLCT acl+++d++e+f+++h++i++++jp-sm++ From sholden at holdenweb.com Tue Oct 23 00:58:03 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 23 Oct 2001 00:58:03 -0400 Subject: smtplib.SMTPDataError: (503, 'Error: need RCPT command') References: <3BD4F3E8.1E4B826B@cs.utwente.nl> Message-ID: "Richard van de Stadt" wrote in message news:3BD4F3E8.1E4B826B at cs.utwente.nl... > Hi, > > This is the first time I've been using the stuff below with Python 2.1.1 running > on Solaris 5.8. I never got the error below before. It runs fine on Linux with > Python 1.5.2, and has been running fine for years on a Solaris 5.6 system, with > Python 1.5.2, 2.1 and 2.1.1. Could the error below be caused by Solaris 5.8's > version of sendmail? > > Could anyone explain what this RCPT command is that seems to be needed? > > --------------------- > mail.sendmail(fromaddr, recipients, message % locals()) > File "/usr/local/pkg/Python-2.1.1/lib/python2.1/smtplib.py", line 496, in sendmail > (code,resp) = self.data(msg) > File "/usr/local/pkg/Python-2.1.1/lib/python2.1/smtplib.py", line 386, in data > raise SMTPDataError(code,repl) > smtplib.SMTPDataError: (503, 'Error: need RCPT command') > --------------------- > > Here's a part of my send_email function: > ... > fromstring = '...' > fromaddr = maintaineremail > cc_list = string.join ((chairemail, maintaineremail), ', ') > date = ctime(time()) > dayName = date[:3] + ',' > monthName = date[3:7] > day = date[7:10] > year = date[19:] > Time = date[10:19] > timeZone = ' ' + tzname[daylight] > date = dayName + day + monthName + year + Time + timeZone > message = """\ > Subject: %(subject)s > Date: %(date)s > From: %(fromstring)s <%(fromaddr)s> > Reply-To: %(fromaddr)s > To: %(to_list)s > Cc: %(cc_list)s > X-Mailer: Python smtplib > > %(body)s > """ > try: > mail = smtplib.SMTP(LocalMailServer) > except: > mail = smtplib.SMTP(altLocalMailServer) > mail.sendmail(fromaddr, recipients, message % locals()) > mail.quit() > You appear to have overlooked setting a value for the "to_list" local variable, and I don't see anything setting "recipients" either. It's possible you simply omitted to include this section of your code, but an empty recipient list might result in that error. smtplib line 386 raises an error because the server doesn't give the expected reply when the client starts to send the message body. To check this, try adding mail.set_debuglevel(1) before the .sendmail() call, which will give you a trace of client/server interactions. regards Steve -- http://www.holdenweb.com/ From ignacio at openservices.net Wed Oct 10 23:20:02 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 10 Oct 2001 23:20:02 -0400 (EDT) Subject: Why not 3.__class__ ? In-Reply-To: <3BC50A86.2CAC0347@engcorp.com> Message-ID: On Wed, 10 Oct 2001, Peter Hansen wrote: > John Roth wrote: > > > > I presume (although I haven't tested it) that "3(x, y, z)" produces a > > "not callable object" error, and "3[x]" produces a "not subscriptable" > > error as well. I really can't see what calling '3' would do, but > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > I'm not sure either, but calling '4' should make people duck! ** > > > if-puns-are-the-lowest-form-of-humor-what-are-numeric-puns-ly yr's, Definitively negative ;) > ** (on the golf course, for the non-native English speakers amongst us.) -- Ignacio Vazquez-Abrams From peter at engcorp.com Sun Oct 28 00:53:04 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Oct 2001 00:53:04 -0400 Subject: interpreter crashes References: <7xzo6cd1hw.fsf_-_@ruckus.brouhaha.com> Message-ID: <3BDB8F30.FEE9004C@engcorp.com> Paul Rubin wrote: > > A few times I've had Python 2.1.1 crash on me for no apparent reason. [snip] > How frequently does this type of thing happen? If Python is in the habit > of crashing randomly, that may make it inadvisable to write > long-running servers that need to stay up. Perhaps it's more > appropriate to write servers Apache-style, forking new processes and > reinitializing every so often. Not necessary if your system is stable. Python can run indefinitely unless you have hit some obscure bug. As a small trivial example of its stability, we have had our Intranet server running under Zope (on Redhat 7.0) for the last 84 days straight, being used daily and extensively by at least twenty people. No troubles. We are also developing applications based on Python which will be expected to run potentially for years without being shut down ... and I have no concerns about this (at least none related to Python! ;-). -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From tim at vegeta.ath.cx Wed Oct 31 17:31:27 2001 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Wed, 31 Oct 2001 22:31:27 GMT Subject: Freeware Python editor References: Message-ID: Me parece que Steven D. Majewski dijo: > On Wed, 31 Oct 2001, Oleg Broytmann wrote: > > On Wed, Oct 31, 2001 at 09:45:25AM -0800, Erik Max Francis wrote: > > > You said you didn't want to start another GNU flamewar. But what do you > > > think you're doing? > > > > Trying to stop you arguing :) > > That's not an argument. > It's merely a negation. > I paid for an argument! Ah. One of the more subtle Monty Python references. ;) YAT (Yet Another Tim) -- I have the simplest tastes. I am always satisfied with the best. -- Oscar Wilde From claird at starbase.neosoft.com Wed Oct 10 08:49:23 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 10 Oct 2001 07:49:23 -0500 Subject: Newbie: tkinter question References: Message-ID: <118EE09ECEDF14F8.218265D3FDE5A761.875E2BB02943F76C@lp.airnews.net> In article , Attila Pletyak wrote: >Hello, > > I am using Debian Linux 2.2, I've installed python from the deb >packages. I would like to try out the possibilites of tkinter, but the >module tkinter seems to be missing from my computer. Python is 1.5.2, >and when I start it and type "from Tkinter import * " it says that it >cannot find tkinter. > > I looked on the tkinter home page, it routes me to >dev.scriptics.com, but there I cannot really find tkinter. . . . In the absence of explanation from a Debian expert--and I do recognize there are a several nearby--my usual ad- vice is to download Python 2.2 and re-build your own installation. Are you comfortable with such a generation? It's quite straightforward. What you've done is absolutely right. A correct 1.5.2 should be able to import Tkinter. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From idot at vt.edu Mon Oct 29 20:20:34 2001 From: idot at vt.edu (Carl Banks) Date: Tue, 30 Oct 2001 01:20:34 +0000 (UTC) Subject: Representing tuples in strings References: <2SmD7.3702$Ey1.438112@news1.cableinet.net> Message-ID: <9rkv92$m0c$3@solaris.cc.vt.edu> Graham Ashton wrote: > I'm looking to convert the tuple: > > ('string1', 3, 'string2') > > to the string representation: > > 'string1', 3, 'string2' > > without resorting to a regular expression. repr(('string1', 3, 'string2'))[1:-1] > So far the nearest I've managed to get to is to have quotes round the > whole thing, but not around the strings themselves. I suppose what I want > here really is some better function to pass into map(). Maybe... > > >>> mytup = ('string1', 3, 'string2') > >>> ", ".join(map(str, mytup)) > 'string1, 3, string2' > > Any thoughts? It's not exactly going to make the difference between life > and death in my application (it's for log files), but I'd really like to > learn some map/lambda tricks. You want repr. -- CARL From tdelaney at avaya.com Thu Oct 18 20:39:00 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 19 Oct 2001 10:39:00 +1000 Subject: How To compile Python without any module. Message-ID: > From: Skip Montanaro [mailto:skip at pobox.com] > dag> In fact i don't need the build in modules like sys. > dag> So how could i built python with out the build in modules. > dag> I want to use Python on 8Mo of Flash and 16Mo of RAM. > I'd be real surprised if Python worked very well without the > sys module. > Still, you might be able to get away with just commenting it > out of the > makefile. It's one of the files listed in the PYTHON_OBJS > make variable. > > To get an idea of how central the sys module is to Python's operation, > notice that Include/sysmodule.h is #included by > Include/Python.h, which is > #included by just about every C file in the distribution. Skip's right here ... My approach would probably be to identify which parts of the builtin modules you don't need, and comment those out. It will be a long, difficult process however, as many parts that you don't think you need will be used by those parts that you do need. You will need to build a complete dependency tree of modules and functions, then remove a few at a time, testing that your application works each time. As mentioned before, deeply-embedded Python is probably your best option - if only to show what parts can be safely removed from Python. http://www.abo.fi/~iporres/python/ Tim Delaney From dale at riverhall.NOSPAMco.uk Sat Oct 6 12:58:44 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Sat, 06 Oct 2001 17:58:44 +0100 Subject: Pipes References: Message-ID: David Bolen wrote: > >For interprocess I normally go ahead and use the popen# functions. >For inter-machine I'm much more likely to use an IP approach with >sockets (I've done named pipes in pure Windows applications that >weren't written in Python but not in Python to this point). > Popen pipes are not the sort I was after. I need to communicate between processes - maybe on separate machines - asynchronously. Popen pipes are the synchronous stdout/stdin type of pipes. Thanks anyway -- Dale Strickland-Clark Riverhall Systems Ltd From billy_bill_1 at yahoo.com Wed Oct 10 06:01:30 2001 From: billy_bill_1 at yahoo.com (Billy) Date: Wed, 10 Oct 2001 03:01:30 -0700 (PDT) Subject: Python questions -> compiler and datatypes etc Message-ID: <20011010100130.30712.qmail@web11208.mail.yahoo.com> Yeah, java can do the job, but so can C++... see what I mean? Just cause it can do it doesn't mean its practical. Java is ok for webdev (i have done a bit) it's just tediously slow in implementing sometimes. Zend Encoder (www.zend.com) takes text php code and puts it into an intermedary format not readable by humans. each time a script is called the interpreter calls the encoded script. This means you can distribute your applications without letting people see the code. I've seen various reviews, the scientific basis of them was rather dubious but you could definately gather a general feeling that python was slower than java, to a reasonable extent. ------------------------------------------------------ Compiling python is at the impossible end of the > scale of ease of > implementation. There has been a lot of discussion > about this issue on this > list in the past. Search for "python compiler" and > enjoy :) > Python compiles to bytecode. Python's runtimes > execute compiled bytecode. > There are several runtimes - one of which is Java. > The predominant one is > written in C. ------------------------------------------- I'm unclear on your explanation here. Would I be correct in saying that there is no compiler (source code to machine code) for python. And that this is due to the very complex nature of implementing such a device. *Off topic: I would be interested in finding out more information on this, why can't you do it with python when people are doing it with java? Any pointers to web resources etc?? And you say that the python interpreter takes bytecode and executes that. Does this mean that you can use python to compile your source code into a format which is not readable by humans (bytecode or whatever.. which is as reasonably reverse-engineering proof) and distribute that bytecode (not source code) to stop tampering and protect your commercial interests? I did do an extensive search for information on a python compiler... all accross the web, all i found were a few "discontinued" sites that dated back to June 5th 1957. I never ask questions without checking for myself first. I would want to use strict datatypes and generic types to interchange speed and efficency with flexability. Java lets you define int foo() double foo() and object foo() very nice for building generic classes. keyword args/ (*args thing <- can't quite understand that one) can't do the same as say: excuse the syntax... not familiar enough with python yet class foo: #load foo from file define foo(filename, directory) filesystem calls etc etc... #load foo from database define foo(datbasename) connect to database etc etc...... or even better #load foo from file define foo(FileHandler fhFile) bla bla bla #load foo from database define foo(DatabaseObject database) bla bla bla So what your saying is that python doesn't have the ability to switch between this? Thanks heaps for your time, Billy --- Richard Jones wrote: > On Monday 08 October 2001 16:32, > billy_bill_1 at yahoo.com wrote: > > I've been using php for ages for webdev and I > don't like it. It lacks > > so many simple features, and I can't be bothered > using Java to use > > those features. IMHO java is not suited for > specific web development. > > There's a lot of server-side Java programmers who > would disagree with that > statement. Python is better, but Java can do the > job. > > > > So I find python, I like python. Python has > everything I need, except > > (apparently) the ability to encode it (php: Zend > Encoder) or > > Sorry, what do you mean by "encode it"? I'm not > familiar with "Zend Encoder". > > > > compile > > it into Bytecode like java. > > Python compiles to bytecode. Python's runtimes > execute compiled bytecode. > There are several runtimes - one of which is Java. > The predominant one is > written in C. > > > > It seems its not nearly as fast as java. > > (Acceptable in most cases though). > > How did you measure this? > > > > > Are there any products coming out involving > compilation of python? > > Like a 2 stage interpreter like java... that would > be tops... speed > > and ability to sheild source code from prying and > tampering eyes. > > Compiling python is at the impossible end of the > scale of ease of > implementation. There has been a lot of discussion > about this issue on this > list in the past. Search for "python compiler" and > enjoy :) > > > > Does python have the ability to let the programmer > change between > > strongly typed and loosly typed as needs be? > > No, unless you venture into JPython land, where you > could mix Java code > (strict, strong typing) and Python code (dynamic, > strong typing) in the one > project. Why on earth you'd want to is beyond me > though :) > > > > python support function overloading? > > Traditional overloading, which allows a function to > have multiple signatures > to allow different types to be passed in has no > relevance in a dynamically > typed language like Python. Witness: > > Python 2.1.1 (#1, Jul 20 2001, 22:37:24) > [GCC 2.96 20000731 (Mandrake Linux 8.1 > 2.96-0.58mdk)] on linux-i386 > Type "copyright", "credits" or "license" for more > information. > >>> def foo(sequence): > ... for element in sequence: > ... print sequence.index(element), element > ... > >>> foo(['a', 'list']) > 0 a > 1 list > >>> foo('a string') > 0 a > 1 > 2 s > 3 t > 4 r > 5 i > 6 n > 7 g > >>> > > > [note: that's a cutnpaste from an inetractive > session with the interpreter] > > > > variable length parameter lists? > > Yep, and keyword arguments too. Continuing on from > the previous interactive > session, we redefine foo: > > >>> def foo(*args): > ... print 'My args', args > ... > >>> foo(1, 2, 'hello', 3, foo) > My args (1, 2, 'hello', 3, 0x8131acc>) > >>> > > Keyword args: > > >>> def foo(food='spam', container='tin'): > ... print '%s in a %s'%(food, container) > ... > >>> foo() > spam in a tin > >>> foo(food='eggs') > eggs in a tin > >>> foo('curry', 'hurry') > curry in a hurry > >>> > > > I suggest spending half an hour walking through the > Python Tutorial. For > added fun, type in the stuff in the tutorial into an > interactive interpreter > at the same time. That's how I learnt Python. > > > Richard __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From tebeka at cs.bgu.ac.il Wed Oct 17 02:07:22 2001 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: Wed, 17 Oct 2001 08:07:22 +0200 Subject: Q: standard makefile for distutils package? Message-ID: <9qj7a8$ncs$1@news.netvision.net.il> Hello All, Is there a standard makefile to ship with a distutils created package (./setup.py sdist) I'm currently using: all: @echo Please specify one of the following: @python setup.py --help-commands | head -18 | tail -17 .DEFAULT: python setup.py $@ -- Bye. ---------------------------------------------------------------------------- - Smile, damn it, smile. lambda msg: { 'name' : 'Miki Tebeka', 'email' : 'mikit at elrontelesoft.com', 'url' : 'http://www.cs.bgu.ac.il/~tebeka', 'quote' : 'The only difference between children and adults is the price of the toys' }[msg] -- Bye. ---------------------------------------------------------------------------- - Smile, damn it, smile. lambda msg: { 'name' : 'Miki Tebeka', 'email' : 'mikit at elrontelesoft.com', 'url' : 'http://www.cs.bgu.ac.il/~tebeka', 'quote' : 'The only difference between children and adults is the price of the toys' }[msg] From ibarona at tid.es Tue Oct 23 07:03:23 2001 From: ibarona at tid.es (Isaac Barona) Date: Tue, 23 Oct 2001 11:03:23 GMT Subject: Serial port gotcha with win32all References: <9qoiif$cep$1@news.urz.uni-heidelberg.de> <3BD14B8A.7080908@ActiveState.com> Message-ID: <3bd54b9f.102389424@tid> On Sat, 20 Oct 2001 10:01:13 GMT, Mark Hammond wrote: >Markus Demleitner wrote: > >> Hi, Hi Markus!!! >> >> I'm getting increasingly desperate. All I'm trying to do is >> attach a little serial gizmo that runs just fine when talked >> to from a linux box (using some homegrown python software) to >> a machine plagued by Windows 2000. >> >> Realizing that termios doesn't buy me much in win32, I soon >> ran across uspp which basically acts as a wrapper around the >> win32all or termios modules on the respective platforms. I am uspp's author, so I hope to help you. >> >> Under linux, uspp worked quite as well as my own termios-based >> code (perhaps not too surprisingly). Under win32, however, >> write()s seem to work but read()s consistently fail with a >> "incorrect paramater" exception in a call to win32file.ReadFile. >> >> Now, clearly the OpenFile succeded, and the handle didn't change >> between the open and the read, the error is not in the number >> of bytes to read (passing some weird object there causes a >> ParameterError, as expected), and in general I've not been >> able to gain any clue as to what is going on. The win32all >> sources seem somewhat intimidating, at least for me with >> no knowledge of the win32 API whatsoever. It seems that the interface in the overlapped I/O mode to the win32file.ReadFile function has changed in new versions. Harald Angelo sent me this patch that seems to correct the problem (not using overlapped I/O). self.__handle=CreateFile (dev, win32con.GENERIC_READ|win32con.GENERIC_WRITE, 0, # exclusive access None, # no security win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL # |win32con.FILE_FLAG_OVERLAPPED , None) Just now I am working in a new release of the library but in the meantime apply this patch and see what happend. Let me know the results. Greetings from Spain, Isaac. >> >> So -- can anyone give me a hint where to start getting a >> grip on this one? > >Look at the > >win32comport_demo.py sample - it seems to work just fine. Failing that, post the smallest possible code snippet you can come up with that demonstrates the problem. > > >Mark. > > > From Widgeteye at widgets.com Sun Oct 28 00:23:40 2001 From: Widgeteye at widgets.com (Widgeteye) Date: Sun, 28 Oct 2001 04:23:40 -0000 Subject: FInding files with python Message-ID: I'm really new at this programming stuff so please bare with me. (: I'm trying to figure out how you would test for the existence of a file on your drive in python. I want to write a little program that does the following: If (file exists) do the following But I can't figure out how to test for the file.. help?? Thanks -- "You can always make peace with an F-16 in your pocket" -Yitzhak Rabin From tdelaney at avaya.com Sun Oct 14 20:27:40 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 15 Oct 2001 10:27:40 +1000 Subject: Assigning to lists with arbitrary names Message-ID: > From: Cliff Wells [mailto:logiplexsoftware at earthlink.net] > On Wednesday 10 October 2001 23:57, Christian Tanzer wrote: > > And it still uses a dictionary (just slightly hidden from your view) > > so what's the point of such a gross hack? > > > > I think the OP should consider getting rid of his fear of > nested data > > structures -- in Python they are your friend. > > Hrm, is it immoral of me to provide such disgusting code, > even if someone > explicitly requests it? Should I help protect them from > themselves? =) Yes it is. We need to protect such people from themselves ;) Perhaps the best way to handle this is ... "The Pythonic way to do this is ... If you *really* want to do it you can, and we will help you, but we suggest you try it the Pythonic way first." Tim Delaney From phr-n2001d at nightsong.com Sat Oct 27 20:58:19 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 27 Oct 2001 17:58:19 -0700 Subject: interpreter crashes Message-ID: <7xzo6cd1hw.fsf_-_@ruckus.brouhaha.com> A few times I've had Python 2.1.1 crash on me for no apparent reason. Cursory inspection of the core dump doesn't show much-- the interpreter seemed to be innocently evaluating something. Chances are something (maybe a reference count) got corrupted sometime earlier and eventually set off the crash. The one out-of-the-ordinary thing I may have been doing was repeatedly reloading modules as I debugged them. But I'm not even sure about that. Anyone got any suggestions? Want to see the core dumps? How frequently does this type of thing happen? If Python is in the habit of crashing randomly, that may make it inadvisable to write long-running servers that need to stay up. Perhaps it's more appropriate to write servers Apache-style, forking new processes and reinitializing every so often. From BPettersen at NAREX.com Tue Oct 30 11:39:29 2001 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 30 Oct 2001 09:39:29 -0700 Subject: re.findall()-Problem ? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158C0A@admin56.narex.com> > From: Matthias Kuhn [mailto:Kuhn_Matthias at gmx.de] > > Hi, > > I have a question to re.findall(). In the sample-code below > there is a teststring 's', where I want to find some tokens, > preceding a number followed by a comma, e.g. '200,t' -> 't' > > The first re 'r1', finds the tokens 200 .. 241, > in the second 'r2' I've added 250, so that it only finds > the tokens in the first #BEGIN..#END-Block. > [snip] > r1 = '(?s)200,(\S+).+?202,(\S+).+?210,(\S+).+?220,(\S+).+?240,(\S+).+?241,(\S +)' > r2 = '(?s)200,(\S+).+?202,(\S+).+?210,(\S+).+?220,(\S+).+?240,(\S+).+?241,(\S +).+?250,(\S+)' I'm far from a regex guru, but isn't ".+?" equivalent to ".*"? -- bjorn From calves at coelce.com.br Tue Oct 23 13:07:20 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Tue, 23 Oct 2001 14:07:20 -0300 Subject: Python for ipaq Message-ID: <29A97D00F387D411AC7900902770E14802276946@lcoeexc01.coelce.net> try wrote in message news:slrn9taa4e.3ub.spaceman at shield.bsdirc.net... > hello > > Do you know where can i find python for compaq ipaq pocket pc running > Windows CE? > > And second question: > i need a _simple_ ftp client written in python (using ftplib) > which will store some files on server and will get other files from > server. I need to put it in my C program via the system(); > > Thanks! > > -- > Karol Makowski, System Administrator > URL: http://spaceman.bsdzine.org > e-mail: spaceman at bsdzine.org -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From achim.domma at syynx.de Thu Oct 25 10:27:46 2001 From: achim.domma at syynx.de (Achim Domma) Date: Thu, 25 Oct 2001 16:27:46 +0200 Subject: learn OOP with Python Message-ID: <9r97co$cme$07$1@news.t-online.com> Hi, a new employee will write scripts for us in python, but he has not much experience with OOP. Are there any books that teach OOP concepts using Python ? Is there a good source to give somebody with experiences in Pascal and VBScript an introduction in the OO way of thinking ? greetings Achim From mark21rowe at yahoo.com Wed Oct 24 03:43:53 2001 From: mark21rowe at yahoo.com (Mark Rowe) Date: Wed, 24 Oct 2001 20:43:53 +1300 Subject: Automatically resume a download w/ urllib? References: <3bd5024a@news.actrix.gen.nz> Message-ID: <3bd680ea@news.actrix.gen.nz> Hi, Your code certainly fits in better in an object oriented system. The only small problem I saw is the capitization of the headers that you send. The HTTP RFC (RFC 2616) indicates that the headers should be in the case indicated. In some cases incorrect case may affect the servers parsing of the message. Therefore the only changes to your code would be the capitalization of the 'Range' header, and the retrieval of the 'Content-Length' header. Mark "Chris Moffitt" wrote in message news:OHpB7.15055$CN5.1164149 at typhoon.mn.mediaone.net... > After Oleg pointed me in the right direction, I managed to put something > together too. Too bad someone else beat me to the punch! Still, the > solution I came up with is a little different. It just needs to override an > error handler in urllib.FancyURLopener.. Let me know what you think. > > import urllib, os > > class myURLOpener(urllib.FancyURLopener): > """Create sub-class in order to overide error 206. This error means a > partial file is being sent, > which is ok in this case. Do nothing with this error. > """ > def http_error_206(self, url, fp, errcode, errmsg, headers, data=None): > pass > loop = 1 > dlFile = "testfile" > existSize = 0 > myUrlclass = myURLOpener() > if os.path.exists(dlFile): > outputFile = open(dlFile,"ab") > existSize = os.path.getsize(dlFile) > #If the file exists, then only download the remainder > myUrlclass.addheader("range","bytes=%s-" % (existSize)) > else: > outputFile = open(dlFile,"wb") > > webPage = myUrlclass.open("http://192.168.1.4/%s" % dlFile) > > #If the file exists, but we already have the whole thing, don't download > again > if int(webPage.headers['content-length']) == existSize: > loop = 0 > print "File already downloaded" > > numBytes = 0 > while loop: > data = webPage.read(8192) > if not data: > break > outputFile.write(data) > numBytes = numBytes + len(data) > > webPage.close() > outputFile.close() > > for k,v in webPage.headers.items(): > print k, "=",v > print "copied", numBytes, "bytes from", webPage.url > > > "Oleg Broytmann" wrote in message > news:mailman.1003831763.10689.python-list at python.org... > > On Tue, Oct 23, 2001 at 05:31:54PM +1300, Mark Rowe wrote: > > > After reading some RFC's and tweaking some Apache settings, I managed to > get > > > this working. I was only able to test it on my local server and it > appears > > > to work fine. Any comments or improvements, feel free :) > > > > Thank you. > > > > [skip] > > > if existSize > 0: > > > h.putheader('Range', 'bytes=%d-' % (existSize, )) > > > > Looks good. > > > > [skip] > > > ## HTTP error 416 = Request Range not Satisiable > > ^ > > Typo (-: _| > > > > Oleg. > > -- > > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > > Programmers don't die, they just GOSUB without RETURN. > > > > From markus at schabi.de Wed Oct 3 02:50:16 2001 From: markus at schabi.de (Markus Schaber) Date: Wed, 3 Oct 2001 08:50:16 +0200 Subject: Past command buffer gone in interpreter? References: Message-ID: <5536892.9nUPlyArG6@lunix.schabi.de> Tod Fox schrub: > I am using Redhat 7.1. I was using the python installed by Redhat > (1.5.2 I think), but I decided to upgrade to 2.1.1. It installed > without any apparent problems and was able to run the test without any > major failures. However, a minor aspect of the interpreter has now > changed; I can no longer use the up and down arrow keys to return to > past commands I have entered -- it prints garbage characters on the > screen instead. > > I can't tell if this is really an issue with python, or what could be > causing this. I've tried to look through the documentation for this > kind of thing, but if I have missed something I will read it if it is > pointed out to me. It seems that your Python version is compiled without readline support. If you did compile it yourself, check your configure options, otherwise check the location you got the packages whether they offer a version compiled with readline support. markus -- "The strength of the Constitution lies entirely in the determination of each citizen to defend it. Only if every single citizen feels duty bound to do his share in this defense are the constitutional rights secure." -- Albert Einstein From qrczak at knm.org.pl Thu Oct 4 16:39:49 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 4 Oct 2001 20:39:49 GMT Subject: Assignment not the same as defining? References: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> <1002126344.97387@cswreg.cos.agilent.com> Message-ID: Wed, 3 Oct 2001 16:25:44 +0000 (UTC), Greg Weeks pisze: > Based on what I've seen, the old Lisp way of talking is dying out. But > there is no law against the conceptual equation "object = address", and it > does simplify things overall, in my estimation. I would say that "object" is the value of the address, an immutable concept, and "reference" is such address stored in a mutable place. So variable names are associated with references, references refer to objects, objects have values (or contents). For example Python passes objects as arguments. Those objects are placed in new references associated with formal parameter names. Inside the function you can't say from which reference the object was taken (if it was taken from a reference at all). -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From chrishbarker at home.net Thu Oct 4 16:23:22 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 04 Oct 2001 13:23:22 -0700 Subject: Nicer Tkinter on UNIX? References: <3BBCAF3D.C9EE4712@home.net> Message-ID: <3BBCC53A.9D792874@home.net> Artur Skura wrote: > I fully appreciate and share your opinion, but I have to write something > for folks who are completely clueless. I don't think they will be able to > install additional libraries. you need to give them your code, and you need to make sure they have Python installed, and it's the correct version, etc. Making the additional libraries they need part of what you give them is nothing extra fro them to do. Check out py2exe (for windows) or McMillian's Installer (for Windows and *nix) for ways to make this easy. Also, the ActiveState distribution of Python has a package installer that makes it very easy to add extra packages, I don 'tknow what they have included at the moment, but wxPython was on their todo list a couple of months ago. All that being said, a "Complete Python" distibution with both batteries and accessories included would be a great thing. I am trying to get some support together to build such a thihng, but havn't gotten much help yet. If anyone wants to help, let me know. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From tim.one at home.com Mon Oct 1 02:59:19 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 1 Oct 2001 02:59:19 -0400 Subject: sameness/identity In-Reply-To: <1001876090.367103@cswreg.cos.agilent.com> Message-ID: [Greg Weeks] > ... > Consider: > > x = 6.02 > y = 6.02 > > Are x and y identical? They are identical as *numbers* (which I'll call > conceptual identity) but not as Python *implentations* of numbers (since > id(x) != id(y)). You can't know that, though. Here: >>> x = 6.02 # this >>> y = 6.02 # and this >>> id(x) == id(y) # just happen to be different objects today 0 >>> def f(): ... x = 6.02 # but this ... y = 6.02 # and this ... return id(x) == id(y) # just happen to be the same object today ... >>> f() 1 >>> Python guarantees nothing about identity wrt floats (or strings, or ints, longs, complexes or tuples), except for the trivial id(x) == id(x). Objects of these types that compare equal may or may not be the same object, at the implementation's discretion. You have no control over it, and don't need any. For the builtin objects of other types, Python does guarantee that id(C(...)) will be unique among all id()s of currently living objects, where C(...) is a constructor for the type. So it's an accident of optimization that "abc" + "" is "abc" today, but it's deliberate and guaranteed that [] is not [] > Good programming style requires us to think of numbers primarily > as numbers and not as their implementations. I expect this depends on the app, but Python does favor value semantics for numbers, even to the extent that (e.g.) hash(i) == hash(long(i)) == hash(float(i)) -- hash(complex(i)) for all integers i (at least on 32-bit boxes, so that float(i) never loses precision). > So we are more interested in conceptual identity than in implementation > identity. Well, Python doesn't model either of those concepts. For objects of builtin types, it has (deep) value equality and object identity instead, varying by type according to which seemed more useful for objects of that type. Object identity is near trivial: "x is y" iff x and y name the same object. You view that as "implementation identity", but in a real sense that's backwards: object identity is the primary concept, and the implementation strives to implement object identity faithfully. It's not really that "is" just happens to expose whatever the heck the implementation does; "is" is an implementation of object identity. > Now consider a simple Bank_account class: > > class Bank_account: > def __init__(me, initial_balance): > me.balance = initial_balance > ... > my_bank_account = Bank_account(100) > your_bank_account = Bank_account(100) > > Are the two bank accounts the same bank account? No. (How would > you feel, for example, if I withdrew money from your bank account?) x > and y are conceptually the same, but my_bank_account and > your_bank_account are not. This is why the default __eq__ and __cmp__ implementations for instances use object identity, but *allow* you to override those in case it's not suitable for your objects -- "most useful most often". In contrast, class Set: def __init__(self, sequence): self.data = data = [] for x in seq: if x not in data: data.append(x) In almost all apps, it would be insane if Set([1, 2]) != Set([2, 1]), so the ability to override __eq__ is crucial. > ... > So, we've encountered three kinds of identity in this discussion: > > A. conceptual identity > B. implementation identity > C. state identity > > In Python, B corresponds to "is". "is" implements object identity. > And to many Python programmers, C corresponds to "==". It depends on the programmer and the app, and they can make "==" mean anything their app needs. > But that leaves A without an operator. Feel free to overload "<<" if you're afraid of named methods . Note that several other notions of equality can be useful for container types too: "C1 == C2" may be most useful as simple object identity at top level, or object identity of all the contained objects (and then with or without regard to ordering), or value equality of the contained objects (likewise), or mixtures depending on the types of the contained objects and/or the depth of the search. > I'm unable to swallow that. So, I use "==" for A; I never use "is"; You should: object identity is a powerful tool, in some apps. > and if I need C -- which hasn't happened yet -- I write a method for it. Cool. I take it you haven't yet written a rational-number, Set or Date class . > This works pretty well. It works for all the immutable types. It also > works for bank accounts *as defined above*. That's why you won't find me > adding __cmp__ and __hash__ methods to bank accounts. An irony is that "is" does exactly what you say you need for bank accounts. Refusing to use "is" for its intended purpose doesn't seem a particularly good idea. > Note, by the way, that the above bank accounts are suitable hash table > keys (and I have found that useful on occasion). That gets closer to a real (IMO) problem: the overload of __eq__ most useful for a class isn't always the best idea for dict keys. But then you can write a wrapper for the dict-key use, redefining its __eq__ and __hash__ as needed. > Unfortunately, "==" does not represent conceptual identity for lists and > dictionaries. (Lists and dictionaries are like bank accounts. They are > not conceptually identical even if they happen to have the same state.) > That's what I mean when I say Python "got it wrong". Eh -- value comparison for lists and dicts isn't compelling, but neither is identity comparison (I've used languages with both, and they both suck for *some* apps). Going back to the Set() example, when using dicts to represents sets, value comparison of dicts is exactly what's desired for __eq__. Ditto using, e.g., bisect.bisect to mantain a priority queue of list-based info. There are many examples where one is more useful than the other. But since "is" already does identity comparison for lists and dicts, having __eq__ do that too seems a waste. Note that in 2.2 you can subclass from dictionary (or list) and provide your own idea of what __eq__ means; e.g., from a 2.2a4 shell session: >>> class identity_list(list): ... def __eq__(self, other): ... return self is other ... >>> x = identity_list([1]) >>> x.append(2) >>> y = x[:] >>> print x, y [1, 2] [1, 2] >>> x == y 0 >>> Note that since I didn't override the slicing operator, the "y = x[:]" is actually performed by the base (list) type, and yields an instance of list (not of identity_list). But I did override __eq__, so it's identity_list.__eq__ that performed the comparison. >>> list.__eq__(x, y) 1 >>> That is, list's __eq__ still considers them to be equal. > I can't *prove* that it is wrong. I *prefer* an operator for conceptual > identity. And I have a *hunch* that programs are better with an operator > for conceptual identity. But -- as all of you know -- 95% of my hunch is > really just my preference. I think it's nice that Python gives different *default* meanings for __eq__ depending on type -- by your own account, it "does the right thing" by default for both numbers and bank accounts, despite that it does different things in those cases. And I'm not sorry it doesn't have 13 different ways to spell "equality-like operator". Two ways may be one too many already, to judge from the amount of confusion out there over "is". it's-the-simplest-things-that-provoke-the-most-confusion-ly y'rs - tim From thecalm at NOSPAM.btinternet.com Sun Oct 7 10:18:11 2001 From: thecalm at NOSPAM.btinternet.com (G. Willoughby) Date: Sun, 7 Oct 2001 15:18:11 +0100 Subject: permissions removing a directory? Message-ID: <9ppo49$cpk$1@neptunium.btinternet.com> I want to remove a directory but i keep getting this error: OSError: [Errno 13] Permission denied: heres the code: [snip] self.workingDirectory=self.directory.get() self.thumbnailDirectory=os.path.join(self.workingDirectory, "thumbnails") if os.path.isdir(self.thumbnailDirectory): os.rmdir(self.thumbnailDirectory) [/snip] any ideas??? ta, G. Willoughby From skip at pobox.com Mon Oct 1 08:53:22 2001 From: skip at pobox.com (Skip Montanaro) Date: Mon, 1 Oct 2001 07:53:22 -0500 Subject: bsddb - mystery wrapped in enigma In-Reply-To: <23fa17e9.0109302010.57591efc@posting.google.com> References: <23fa17e9.0109302010.57591efc@posting.google.com> Message-ID: <15288.26434.785146.286662@beluga.mojam.com> d> I have been scouring the earth for a good tutorial on the bsddb d> module. Is there anything (in print or otherwise) lurking about that d> might help? d> I am trying to extract information from an existing berkeley db file d> (sleepycat). Assuming the version of the file you want to probe matches the version of libdb you have installed, and you know what type of file it is (hash, btree or recno), you should be able to just open it with the proper open function and then treat it more or less like a dictionary. To wit: % file /etc/mail/aliases.db /etc/mail/aliases.db: Berkeley DB (Hash, version 7, native byte-order) % python Python 2.1.1 (#6, Sep 24 2001, 09:14:11) [GCC 3.0.1] on linux2 Type "copyright", "credits" or "license" for more information. >>> import bsddb >>> dir(bsddb) ['__doc__', '__file__', '__name__', 'btopen', 'error', 'hashopen', 'rnopen'] >>> db = bsddb.hashopen("/etc/mail/aliases.db") >>> db.keys() ['postmaster\x00', 'daemon\x00', 'ingres\x00', 'toor\x00', 'operator\x00', 'decode\x00', 'root\x00', '@\x00', 'mailer-daemon\x00', 'bin\x00', 'games\x00', 'nobody\x00', 'system\x00', 'uucp\x00', 'manager\x00', 'dumper\x00'] >>> for k in db.keys(): ... print k, db[k] ... postmaster root daemon root ingres root toor root operator root decode root root skip at pobox.com @ @ mailer-daemon postmaster bin root games root nobody root system root uucp root manager root dumper root Note that the open function (hashopen) must match the type of the file (Hash in this case). -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From eyal at hyperroll.com Tue Oct 30 18:40:13 2001 From: eyal at hyperroll.com (Eyal Lotem) Date: Wed, 31 Oct 2001 01:40:13 +0200 Subject: map, filter, reduce, zip, range, and.. slice? Message-ID: <3bdf39a6@news.bezeqint.net> Hey. Recently, I've been heavily using functional-style programming in Python, doing almost all of my text processing and so with complex nested lambda clauses. I love those, as they are so short, and seem to work with a painless "debug" cycle, usually consisting of some missing reduce initial value or so. To get to the point, I've almost always lacked a 'slice' function, that slices sequences into smaller chunks. For example: divide("Hello world!", 2) => ["He", "ll", "o ", "wo", "rl", "d!"] This can be useful to map() items or chunks inside sequences, rather than individual items. It can also be useful for for'ing through chunks of sequences. I ended up re-coding this function everywhere I've got Python installed (which is a lot of places, that are not necessarily networked :). I was wondering: A) Is there an already existing way to do this in the standard library, via a function that does this exactly, or some similar functionality? B) If not, will it be a good idea to incorporate such a function into the standard library? From iamcanadian89 at yahoo.com Sat Oct 27 09:21:46 2001 From: iamcanadian89 at yahoo.com (M. Ibaraki) Date: 27 Oct 2001 06:21:46 -0700 Subject: os.system() and cgi Message-ID: This script (test.py) works fine and creates a file 'outputfile' when I run this in test mode (python test.py). --- test.py ---- #!/usr/bin/python import cgi, os print "Content-type: text/html\r\n" print "" print "" ret = os.system('/usr/X11R6/bin/xmgrace -help > outputfile') # ret = os.system('/bin/ls > outputfile') print "

ret = ", ret ---------------- It shows: Content-type: text/html

ret = 0 However, when this is executed as a cgi it shows: ret = 256 and no 'outputfile' file is created. Permission of /usr/X11R6/bin/xmgrace is: -rwxr-xr-x 1 root root 450 May 20 18:48 /usr/X11R6/bin/xmgrace xmgrace is a 2D plotting tool (http://plasma-gate.weizmann.ac.il/Grace/) I also tried '/bin/ls > outputfile' instead of '/usr/X11R6/bin/xmgrace -help > outputfile'. This 'ls' command is executed and it creates 'outputfile' in both cgi and test modes. Permission of /bin/ls is: -rwxr-xr-x 1 root root 48316 Sep 15 12:54 /bin/ls Any comments would be greatly appreciated. M. Ibaraki From sholden at holdenweb.com Wed Oct 17 09:02:11 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 17 Oct 2001 09:02:11 -0400 Subject: profiler results for __getattr__, am I reading this correctly ? References: Message-ID: <1gfz7.20627$cb.413557@atlpnn01.usenetserver.com> "Anthony Baxter" wrote ... > >>> "Tim Peters" wrote > > If volunteers materialize to produce another bugfix release, I'm sure we'll > > (PythonLabs) be happy to ship it (cut docs, installers, etc). It's curious > > that neither Aahz (2.0.1) nor Thomas Wouters (2.1.1) volunteered for a > > second round of this rewarding work . > > What is the process likely to be for this? > > The major component of work would be deciding which patches and fixes > were deserving of 2.1.2, yes? How is the decision made - those things > that are only bugfixes? Only "critical" bugfixes? Or is it a matter of > trawling the CVS commit messages since 2.1.1... ? > > Anthony, curious. > Ha! There's no such thing as "curious" when it comes to bugfix releases. You just volunteered. [Quick, somebody, get the altar and a consecrated knife...] just-joking-in-bad-taste-ly y'rs - steve -- http://www.holdenweb.com/ From maxm at normik.dk Wed Oct 24 07:40:28 2001 From: maxm at normik.dk (Max M) Date: Wed, 24 Oct 2001 13:40:28 +0200 Subject: Request: module that converts iis Request module to Dict like object Message-ID: <3bd6a8ad$0$29092$edfadb0f@dspool01.news.tele.dk> Shurely I am not the first one to think of this, but I cannot seem to find anything on the net. Has anybody has some code that delivers the goods and feels like sharing? I would rather save a few hours not writing and testing it myself. regards Max M From dale at riverhall.NOSPAMco.uk Thu Oct 11 14:17:09 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Thu, 11 Oct 2001 19:17:09 +0100 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> Message-ID: Donn Cave wrote: >I sort of regret wasting bandwidth on this purely academic question, >but it's a matter of truly venerable tradition that C's loop is a >bit shy of perfection. The idea as I understand it, is that there >are essentially two control points in a loop, the entry, and the >conditional repeat. C conflates those two in one, because both >entry and the conditional repeat have to be at the "top". I didn't suggest it was perfect, just that I liked it. >People who claim that C fixes this just expose the limitations of >their thinking. C does not fix this, by allowing an assignment >there, except in the restricted case where the pre-conditional >part of the loop can fit into one expression. (Note that I'm not >talking about the initialization section of for(), which is a >pure non-feature - those statements can just as well be written >before the loop.) Not so. It can avoid an extra enclosing block in cases such as: if (x==y) for (initialise loop; ....) do something Which is less fussy than if (x==y) { initialise loop for (....) do something } -- Dale Strickland-Clark Riverhall Systems Ltd From scott_hathaway at riskvision.com Wed Oct 17 07:49:03 2001 From: scott_hathaway at riskvision.com (Scott Hathaway) Date: Wed, 17 Oct 2001 06:49:03 -0500 Subject: wsdl and soap References: Message-ID: Bummer. Now there are a million and one things on my list of things to do. :) Thanks, Scott "Paul Prescod" wrote in message news:mailman.1003267096.32173.python-list at python.org... > Scott Hathaway wrote: > > > > I am using v. 0.9.7 of the soap.py library. How can I auto generate an wsdl > > file? Is there a utility that does this already? > > I don't know of such a tool for Python yet. I'm sure someone will do one > eventually. > > Paul Prescod > From chatme at 263.net Mon Oct 15 04:48:52 2001 From: chatme at 263.net (limodou) Date: 15 Oct 2001 01:48:52 -0700 Subject: Cgi Counter References: <3BCA7B95.AEFDEE@strakt.com> Message-ID: class counter: filename="" count=0 def __init__(self, filename): self.filename=filename try: f=open(filename, "r") except IOError: print "Can't open file", filename else: s=f.readline() self.count=int(s) f.close() def inc(self): try: f=open(self.filename, "w") except IOError: print "Can't open file", filename else: self.count+=1 f.write(str(self.count)) f.close() import Cookie,os #judge Cookie,get user's IP from the cookie c=Cookie.Cookie() try: c.load(os.environ["HTTP_COOKIE"]) userip=c["userip"] except: userip="" userhost=os.environ["REMOTE_ADDR"] #set cookie if(userip==""): c["userip"]=userhost c["userip"]["expires"]=3600 c["userip"]["path"]="/" print c["userip"] print "Content-type: text/html" print a=counter("count.txt") if(userip==""): a.inc() print str(a.count)+"
" From tjreedy at home.com Wed Oct 17 14:31:11 2001 From: tjreedy at home.com (Terry Reedy) Date: Wed, 17 Oct 2001 18:31:11 GMT Subject: IF STATEMENTS References: Message-ID: "Charles" wrote in message news:mailman.1003338557.21566.python-list at python.org... > Hi ! > > Anyone know how i can create > a IF AND statements in python ? > > ex: > > IF vars == 1 AND vars2 == 2: > ..... > > in the tutorial papers only have > a refers to ELIF. Do not capitalize the keywords. Terry J. Reedy From chatme at 263.net Mon Oct 15 04:34:44 2001 From: chatme at 263.net (limodou) Date: 15 Oct 2001 01:34:44 -0700 Subject: It's a BUG? urllib2 & proxy References: Message-ID: chatme at 263.net (limodou) wrote in message news:... And I found another thing that in code (urllib2.py) 807: original : h.putheader('Host', host) should be changed with : #h.putheader('Host', host) rhost=urlparse.urlparse(req.get_selector())[1] h.putheader('Host', rhost) lucky! From dale at riverhall.NOSPAMco.uk Tue Oct 2 17:34:45 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Tue, 02 Oct 2001 22:34:45 +0100 Subject: Strategies for controling attribute assignment References: Message-ID: I can't confess to understanding that entirely but it looks interesting. There's some interesting new stuff in 2.2 but I missed this. I look it up. Thanks. -- Dale Strickland-Clark Riverhall Systems Ltd From spaceman at bsdzine.org Tue Oct 23 06:14:51 2001 From: spaceman at bsdzine.org (Karol Makowski) Date: 23 Oct 2001 10:14:51 GMT Subject: Python for ipaq References: Message-ID: On Tue, 23 Oct 2001 09:29:54 GMT, Pete Gilbert wrote: > Hi > > There is a release here: yeah, i've found it already and it even works :-> -- Karol Makowski, System Administrator URL: http://spaceman.bsdzine.org e-mail: spaceman at bsdzine.org From dalke at dalkescientific.com Sat Oct 20 20:34:30 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 20 Oct 2001 18:34:30 -0600 Subject: Dictionary from list? References: Message-ID: <9qt550$br6$1@slb4.atl.mindspring.net> Uncle Tim: >but there are few core functions that produce such a list >(dict.items(), zip() and some cases of map() are all that pop to mind), so I >had a hard time picturing a good use for that Not a core function, but args, files = getopt.getopt(...) args = dictionary(args) would be handy. Andrew From spaceman at bsdzine.org Tue Oct 23 06:50:46 2001 From: spaceman at bsdzine.org (Karol Makowski) Date: 23 Oct 2001 10:50:46 GMT Subject: Python for ipaq References: <1003829421.27538.0.nnrp-01.d4f0f8ae@news.demon.co.uk> <7SbB7.7669$Ub2.260976@atlpnn01.usenetserver.com> Message-ID: On Tue, 23 Oct 2001 06:47:52 -0400, Steve Holden wrote: > Sample FTP code in ftpStream.py at thanks, i'll check it. -- Karol Makowski, System Administrator URL: http://spaceman.bsdzine.org e-mail: spaceman at bsdzine.org From robin at jessikat.fsnet.co.uk Wed Oct 24 10:59:09 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 24 Oct 2001 15:59:09 +0100 Subject: super Message-ID: After looking at the 2.2 'features' I started wondering why there isn't a special attribute __super__ to indicate super(self.__class__,self). GvR indicates that as it stands super will likely cause cut and paste errors and gives a hacky workaround, but wouldn't it be easier to have a special attribute? -- Robin Becker From nomad*** at ***freemail.absa.co.za Tue Oct 16 09:35:32 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Tue, 16 Oct 2001 15:35:32 +0200 Subject: Zope vs PHP for the Linux guru References: <4bf6cf6d.0110150255.1518bbed@posting.google.com> Message-ID: On Mon, 15 Oct 2001 13:53:36 +0000 (UTC), Duncan Booth wrote: >In general Zope handles scaling by means of ZEO. This splits off the object >store into a separate backend process with one or more front end Zope >servers running as ZEO clients. If you are running on a multi-processor >machine then you could run multiple instances of Zope talking to a ZEO >server on the same or a different machine. > >A ZEO server can also be a ZEO client, so for a really big system you can >build a tree of ZEO servers. Now, that could be damn cool. -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From michael at stroeder.com Mon Oct 29 14:11:20 2001 From: michael at stroeder.com (Michael =?iso-8859-1?Q?Str=F6der?=) Date: Mon, 29 Oct 2001 20:11:20 +0100 Subject: BNF parsing in Python Message-ID: <3BDDA9D8.972BAEA2@stroeder.com> HI! Disclaimer: I'm not good in compiler/parser methods. I'd like to parse strings describing LDAPv3 schema elements which seem to be declared as BNF (one example, not complete): AttributeTypeDescription = "(" whsp numericoid whsp ; AttributeType identifier [ "NAME" qdescrs ] ; name used in AttributeType [ "DESC" qdstring ] ; description [ "OBSOLETE" whsp ] [ "SUP" woid ] ; derived from this other ; AttributeType [ "EQUALITY" woid ; Matching Rule name [ "ORDERING" woid ; Matching Rule name [ "SUBSTR" woid ] ; Matching Rule name [ "SYNTAX" whsp noidlen whsp ] ; see section 4.3 [ "SINGLE-VALUE" whsp ] ; default multi-valued [ "COLLECTIVE" whsp ] ; default not collective [ "NO-USER-MODIFICATION" whsp ]; default user modifiable [ "USAGE" whsp AttributeUsage ]; default userApplications whsp ")" AttributeUsage = "userApplications" / "directoryOperation" / "distributedOperation" / ; DSA-shared "dSAOperation" ; DSA-specific, value depends on server Here are some examples of strings to parse (not only the BNF above): ( 2.5.13.20 NAME 'telephoneNumberMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 ) ( 0.9.2342.19200300.100.1.39 NAME 'homePostalAddress' EQUALITY caseIgnoreListMatch SUBSTR caseIgnoreListSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 ) ( 2.5.6.6 NAME 'person' SUP top STRUCTURAL MUST ( sn $ cn ) MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) ) Any clues on where to start? Should be pure Python and license-compatible to be included into an open source project (probably BSD style license). Ciao, Michael. From tim.one at home.com Sat Oct 20 14:42:55 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 20 Oct 2001 14:42:55 -0400 Subject: Dictionary from list? In-Reply-To: Message-ID: [Michael Hudson, on making a dict out of a [key, value, key, value, ...] list] > ... > I've never found myself needing to do this, but that may be because > I'm not used to having a convenient way of going from > [k1,v1,k2,v2,...] to a dict. It's quite handy in Perl! Picture parsing a simple textual database with key + value lines (like, e.g., mail headers). In Python you can use re.findall() to parse them all up in one gulp, but then you're left with a flat [k,v,...] list. In Perl you assign the list to a hash, and you're done. Now run this backwards: since this is so convenient in Perl, Perl programs often create textual mini-databases in this format, and before you know it "Python sucks for everything I do" . OTOH, in Python I often maintain textual mini-databases by writing repr(some_dict) to a file, then reconstruct the dict blazingly fast later via eval(open('that_file').read()) -- and before you know it Perl sucks for everything I do. dictionary() is a constructor in 2.2, and I spent a lot of time worrying about what kind of arguments it should take. I believe a flat [k,v,...] list would have been the most useful thing to accept; but it had to at least accept a mapping object, and that's all it accepts (for now). Everyone's first thought seems to be that dictionary() should accept a list of (key, value) tuples -- but there are few core functions that produce such a list (dict.items(), zip() and some cases of map() are all that pop to mind), so I had a hard time picturing a good use for that (yet another way to spell dict.copy() is not a good use). lost-in-consequences-ly y'rs - tim From use-net at schabi.de Wed Oct 17 18:13:07 2001 From: use-net at schabi.de (Markus Schaber) Date: Thu, 18 Oct 2001 00:13:07 +0200 Subject: Help optimize a script? References: Message-ID: <20011018001307.52172a6d.use-net@schabi.de> Hi, there already were good suggestions, but I have another to add: On Wed, 17 Oct 2001 10:51:51 -0700, Joseph Santaniello wrote: > # while is used cuz line in readlines() used too much ram with > # huge files. ind = indecies[sys.argv[1]] > while 1: > line = sys.stdin.readline() > if not line: > break > new = '' > start = 0 for index in ind: > new = new + string.strip(line[start:start + > index])+'\t' start = start + index > print new This pulls the double indexing and lookup of three names into the lookup of one name for every line. Only a small improvement, but it should be measurable :-) markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From dokkenrox at earthlink.net Wed Oct 10 17:52:27 2001 From: dokkenrox at earthlink.net (adam griffin) Date: Wed, 10 Oct 2001 21:52:27 GMT Subject: problem using using list with function References: Message-ID: I think I figured out my problem. I had the function definition at the end of my script when I put it at the beginning it worked. is this the only place you can put definitions? "Ken Seehof" wrote in message news:mailman.1002701769.4408.python-list at python.org... > > i'm trying to write a function that takes a list as it's only arguement > and > > also has a list as it's return value. this is sort of what it looks like: > > > > list1 = [ 1, 2, 3]; > > > > list2 = function(list1) > > > > def function(listArguement): > > #statements... > > return list > > Looks like you are on the right track. Try this in your python interpreter. > You can learn a lot by trying things in the interpreter to see what happens. > > >>> def spam_and(a): > ... b = ['spam', 'spam'] + a > ... return b > ... > >>> list1 = [ 1, 2, 3] > >>> list2 = spam_and(list1) > >>> print list2 > ['spam', 'spam', 1, 2, 3] > >>> > > > > > > From db3l at fitlinxx.com Mon Oct 22 18:43:37 2001 From: db3l at fitlinxx.com (David Bolen) Date: 22 Oct 2001 18:43:37 -0400 Subject: Augmented augmented assignment? References: <0b59tt4tfk6rdnmdekpincllt3a9eqqarm@4ax.com> Message-ID: Dale Strickland-Clark writes: > I assume it's something to do with the in-place operation of augmented > assignment but I can't seem to reproduce it using normal assignment. > > >>> x = 'spam' > >>> y = [] > >>> y = y + x > Traceback (most recent call last): > File "", line 1, in ? > TypeError: can only concatenate list (not "string") to list > >>> y += x > >>> y > ['s', 'p', 'a', 'm'] It looks like between 1.5.2 and 2.0, the extend() method was adjusted to support any sequence. Doing y.extend('spam') accomplishes the same thing as the augmented assignment - probably what's happening behind the scenes - whereas in 1.5.2, y.extend('spam') generated a TypeError, and wants a list. It does seem like an undesirable inconsistency though, since it's only with a mutable list that it happens (you get the same concatenation TypeError in either case if y is a tuple). -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From greg at cosc.canterbury.ac.nz Sun Oct 14 23:25:49 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Mon, 15 Oct 2001 16:25:49 +1300 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> <9psk9s$rbk@newton.cc.rl.ac.uk> <7x669o7r4k.fsf@ruckus.brouhaha.com> <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <7xsncpxxc6.fsf@ruckus.brouhaha.com> <1f186g5.wcfiwzcwvqv4N%news@davidglasser.net> <7x669jyr9b.fsf@ruckus.brouhaha.com> Message-ID: <3BCA573D.C636629B@cosc.canterbury.ac.nz> Paul Rubin wrote: > > (The real code stored the > number of the last item processed, not the number of items processed In that case, if there are 0 items, there is no "last item processed", so that's going to be a special case anyway. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From matt at mondoinfo.com Sun Oct 7 15:55:48 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Sun, 07 Oct 2001 19:55:48 GMT Subject: Tkinter window minsize question References: Message-ID: <8r2w7.4080$rk2.377813@ruti.visi.com> On Sun, 7 Oct 2001 16:06:16 +0400 (MSD), Roman Suzi wrote: >I am wondering why when I execute the following piece of code after >BUTTON1 is pressed top level window become less than specified >minsize: [. . .] >While when I resize it manually (to the greater size) it remains in >tact. What is wrong? It's because the window manager you're using isn't enforcing the minimum size request until you resize the window manually. Depending on your point of view, that may or may not be reasonable. On the one hand, the program requests a particular minimum size and on the other hand (through Tkinter's pack manager) reqests a smaller size. You can fix your particular problem by specifying width and height options when you create the frames and sending them each a pack_propagate(0). In general, there are enough window managers in use and they behave differently enough that it's best to program as though window manager commands might or might not be followed. Regards, Matt From max at alcyone.com Thu Oct 25 22:06:34 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 25 Oct 2001 19:06:34 -0700 Subject: Conditional expressions (again) References: <9r96tv$m26$1@thorium.cix.co.uk> <3BD84F71.6E035616@alcyone.com> <3BD8BD3A.B9F5C456@cosc.canterbury.ac.nz> Message-ID: <3BD8C52A.53E97472@alcyone.com> Greg Ewing wrote: > Write that as > > x = ( > b if a else > d if c else > e > ) > > and it looks a lot clearer. Sure, but since conditional expressions are intended for brevity, you've just made a five line nested conditional express. Why not just use an if ... elif ... else statement instead? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Men live by forgetting -- women live on memories. \__/ T.S. Eliot Computer science / http://www.alcyone.com/max/reference/compsci/ A computer science reference. From mel.b at mindspring.com Mon Oct 8 00:36:37 2001 From: mel.b at mindspring.com (Mel Brown) Date: Sun, 7 Oct 2001 21:36:37 -0700 Subject: Newbie Question References: <9pp1ca$ca6$1@slb4.atl.mindspring.net> <3bc0155f_8@news.newsgroups.com> Message-ID: <9praqb$vni$1@slb5.atl.mindspring.net> "Janos Blazi" wrote in message > Let us assume, you want to use the function strip from the string modeul. > There are three possibilities: > > (1) > >>>import string > in this case you have to use qualified names: > >>>s=string.strip(s) > > (2) > >>>from string import split > then you can omit the "string."-prefix: > >>>s=strip(s) > but you have only imported the function strip > > (3) > >>>from string import * > then you can use +every+ function from string without the "string."-prefix Thanks. All work. From gleki at gol.ge Wed Oct 24 14:11:33 2001 From: gleki at gol.ge (Giorgi Lekishvili) Date: Wed, 24 Oct 2001 11:11:33 -0700 Subject: unnecessary change References: <3BD5BCDF.B40C1422@gol.ge> Message-ID: <3BD70455.A6A5CF7D@gol.ge> Thanx to all! I have solved this by the following way: first, I created a new matrix: tmp=Matrix(MLab.rand(m,n)) and then I copied each element from the initial matrix to the tmp. Of cource, this is not an optimal way, but when I use copy.deepcopy(from_m), the destination matrix becomes integer, i.e., the data become rounded. Can this be overcome? Regards, Giorgi " Kerim Borchaev ( WarKiD )" wrote: > Hello Giorgi, > > try this( works for me ): > > self.Mactual=Numeric.array(self.Mdata) > > Best regards, > Kerim mailto:warkid at storm.ru > > Tuesday, October 23, 2001, 10:54:23 PM, you wrote: > > GL> Hi folks! > > GL> My problem is the following: > GL> I want to save initial data matrix, as e.g., follows > GL> self.Mdata=Matr > GL> In the same time I need a matrix, which is used and processed. The > GL> latter is created as follows > GL> self.Mactual=self.Mdata > > GL> No the problem is, that, when I have finished to use the Mactual matrix, > GL> self.Mdata is always changed and equals the final Mactual matrix. > > GL> What is the systematic solution of the problem? > > GL> Thanx in advance, > GL> Giorgi > > GL> PS. I use Numeric module. From skip at pobox.com Thu Oct 11 19:06:51 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 11 Oct 2001 18:06:51 -0500 Subject: Python Cookbook: last call for recipes for printed version In-Reply-To: <9q52b1$3q5$1@lancelot.camelot> References: <9q52b1$3q5$1@lancelot.camelot> Message-ID: <15302.9739.67065.524596@beluga.mojam.com> Alex> while the Python Cookbook Alex> (http://aspn.activestate.com/ASPN/Cookbook/Python) will stay open Alex> for good, soon we'll have to "freeze" the set of recipes to be Alex> considered for the book version to be published by O'Reilly & Alex> Associates. I guess this aspect wasn't well publicized. This is the first time I've heard there was going to be a book... -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From msp at tpg.com.au Mon Oct 8 09:43:41 2001 From: msp at tpg.com.au (Michael Palm) Date: Mon, 08 Oct 2001 21:43:41 +0800 Subject: += doesn't work in python cgi's (extra info) References: <3BC17D83.A4EEED81@tpg.com.au> Message-ID: <3BC1AD8D.400598AD@tpg.com.au> Forgot info on my setup: Redhat 7.1/Apache 1.3.17/Python 2.1 Seems to work OK on Win95/Apache 1.3.2/Python 2.1 (veeeerrry slooowww) Michael Palm wrote: > I have a strange error in that += doesn't seem to work in a cgi program > > test.py: > > #!/usr/bin/env python > print "Content-type: text/html\n\n" > j = 1 > j +=1 > print " j is %d" % j > > works fine with > python test.py > > but as a cgi gives > j += 1 > ^ > SyntaxError: invalid syntax > > any ideas?? From sholden at holdenweb.com Mon Oct 29 04:18:55 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:18:55 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3BDC0341.8A213560 at engcorp.com... > Christy J wrote: > > > > I need a binary search tree in python that uses classes. I'm trying to > > count words from a file and spit out the number of times they occur > > and in alphabetical order. I got bintree[ [key, data], left, right] > > but don't know how to implement using classes. > > I'd be interested to hear which school is teaching with Python. > > Schools progressive enough to take a chance (a small one, mind > you, but they don't usually seem to think so) on something > not mainstream (i.e. not Java) are few and far between. > Strange how the mention of "school" and "homework" seems to have stopped the original poster from responding on BOTH threads. This is a pity, since c.l.py is one of the few groups where creative help (although not canned solutions) might be available. Guess it was the canned solution that was sought regards Steve -- http://www.holdenweb.com/ From greg at cosc.canterbury.ac.nz Mon Oct 29 22:30:11 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 30 Oct 2001 16:30:11 +1300 Subject: Unpacking extension (Re: A small inconsistency in syntax?) References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> <3BD995CB.22D3507A@home.net> <2jhC7.23321$IR4.13366040@news1.denver1.co.home.com> Message-ID: <3BDE1EC3.7A6883F6@cosc.canterbury.ac.nz> Rainer Deyke wrote: > > tuple((a, b)) = 3, 4 # Syntax error. What if, instead of just the special built-in constructors () and [], you were allowed *any* constructor on the LHS? Consider: class Pair: def __init__(self, x, y): self.x = x self.y = y def __unpack__(self): return x, y p = Pair(17, 42) Pair(a, b) = p which should result in a == 17, b == 42. More precisely, when the LHS is of the form (pattern, ...) the RHS is checked to ensure it is an instance of the LHS class (raising an exception otherwise), and its __unpack__ method is called to produce a sequence which is then unpacked into the argument patterns. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From daves_spam_dodging_account at yahoo.com Mon Oct 29 13:39:12 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Mon, 29 Oct 2001 10:39:12 -0800 (PST) Subject: win32clipboard for python 2.2.1? Message-ID: <20011029183912.5874.qmail@web21103.mail.yahoo.com> > -----Original Message----- > From: Joseph Wilhelm > [mailto:jwilhelm at outsourcefinancial.com] > Sent: Monday, October 29, 2001 11:30 AM > > Actually, if you check closely, there is a release > of win32all for Python 2.1 THANK YOU! I assumed that "PythonLabs version 2.1" meant "not the www.python.org version". This turns out not to be the case. I have downloaded and installed build140 of win32all, and so far it works great! Thank you again, -dB ===== David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From john.thingstad at chello.no Wed Oct 17 15:53:55 2001 From: john.thingstad at chello.no (John Thingstad) Date: Wed, 17 Oct 2001 21:53:55 +0200 Subject: Python and machine learning Message-ID: <20011017195943.KZNF26233.mta01@mjolner> I'm working on a logic language called Formula written all in Python. It will allow reading database tables making desision trees and sematic nets. It altso parses First Order Logic (FOL) and Horn clauses. I plan to release an pre alpha release soon, say early next month. Look for it in the vault of parnassus. To my knowlege there is no such library now. I will announce it when it is finished. From barry at zope.com Sat Oct 20 16:20:59 2001 From: barry at zope.com (Barry A. Warsaw) Date: Sat, 20 Oct 2001 16:20:59 -0400 Subject: testing, please ignore Message-ID: <15313.56491.941165.837478@anthem.wooz.org> first part -------------- next part -------------- second part From ignacio at openservices.net Tue Oct 23 16:25:19 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 23 Oct 2001 16:25:19 -0400 (EDT) Subject: Critical sections and mutexes In-Reply-To: <20011023190659.23110.qmail@web21101.mail.yahoo.com> Message-ID: On Tue, 23 Oct 2001, David Brady wrote: > Firstoff, Shouldn't the plural of "mutex" be > "mutices"? :-) No, because "mutex" isn't a word; it's an acronym for "mutual exclusion". As such it probably shouldn't have a plural form at all, but who's counting ;) -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From richard at bizarsoftware.com.au Tue Oct 2 18:59:46 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Wed, 3 Oct 2001 08:59:46 +1000 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> References: <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> Message-ID: <01100308594602.01465@ike> On Tuesday 02 October 2001 23:59, Paul Miller wrote: > >On Mon, Oct 01, 2001 at 11:04:25AM -0700, Cliff Wells wrote: > > > It's free, and you're free not to use it if you don't want your code to > > > be free. It's called a trade-off. You get the combined efforts of > > > > thousands of > > > > > GNU programmers to help you solve your problem, and in turn you provide > > > > your > > > > > little bit of help back. > > > >Nice said, Cliff! > > If GNU code is FREE, then I'll have to say that Python (and code under > BSD-style licenses) is BETTER THAN FREE. Frankly, I'm very grateful to > Guido for allowing Python to be used freely in commercial software. Hear hear! And our use of python in our commercial software does not stop us from contributing back to the community, which we do quite a lot! Richard From greg at cosc.canterbury.ac.nz Tue Oct 30 23:16:34 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 31 Oct 2001 17:16:34 +1300 Subject: ReXX Style translate() function for strings ? References: <3281a460.0110301257.1a4d9a14@posting.google.com> Message-ID: <3BDF7B22.2BC10101@cosc.canterbury.ac.nz> P Adhia wrote: > > new_date = Translate('56/78/1234', old_date, '12345678') import string def Translate(outpict, input, inpict): return string.translate(outpict, string.maketrans(inpict, input)) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From aahz at panix.com Mon Oct 8 14:10:06 2001 From: aahz at panix.com (Aahz Maruch) Date: 8 Oct 2001 11:10:06 -0700 Subject: Why so few Python jobs? References: Message-ID: <9psq5u$agh$1@panix3.panix.com> In article , Laura Creighton wrote: > >I know of 2 companies that considered doing their development work in >Python but concluded that though the core language was terrific, the >libraries were fragmentary, incomplete, and not up to the vigorous >standards they had come to expect from other languages such as C++. Stock C++ has better libraries than Python? -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista We must not let the evil of a few trample the freedoms of the many. From Georg.Bisseling at pallas.com Fri Oct 19 09:13:00 2001 From: Georg.Bisseling at pallas.com (Georg Bisseling) Date: Fri, 19 Oct 2001 15:13:00 +0200 Subject: Help - Problems with Tk in Python References: <3BD00254.AAFFB236@dcs.warwick.ac.uk> Message-ID: <3BD026DC.2367E802@pallas.com> Denis wrote: > > Problems with Tkinter and _tkinter: > > I have installed Python 2.1.1 and Tcl/tk 8.3 into my directory (sun 8.3? > solaris). > File "", line 1, in? > ImportError: id.so.1: /(directory)/Python-2.1.1/python: fatal: > libtk8.2.so: > open failed: No such file or directory But python want's to load 8.2! May it is as easy as making root say ln -s libtk8.3.so libtk8.2.so Or you have to recompile python and link it against the version 8.3. ciao Georg From ralph at inputplus.demon.co.uk Mon Oct 15 13:57:16 2001 From: ralph at inputplus.demon.co.uk (Ralph Corderoy) Date: 15 Oct 2001 18:57:16 +0100 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: <9qf81s$lut$1@inputplus.demon.co.uk> Hi Tim, > implemented-but-not-checked-in-ly y'rs - tim Don't check it in. It's horrible. I'm all for a ?: in Python using some notation or other but requiring parenthesis around just this kind of expression isn't on. It's non-obvious and distinct from other areas. It is surprising! Cheers, Ralph. From duncan at NOSPAMrcp.co.uk Fri Oct 12 04:26:21 2001 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 12 Oct 2001 08:26:21 +0000 (UTC) Subject: Borg Pattern Class usable from other classes? References: Message-ID: Jan Wender wrote in news:mailman.1002804792.23588.python-list at python.org: > The two files: > # a.py > class Borg: ... > if __name__ == "__main__": ... > import b > # b.py > import a ... > > Thanks for any insights, > If you run a.py as a script then it executes as the module '__main__'. This is why you can do the test for the current module name being '__main__'. If you import a from another module then it runs as the module 'a'. Even though both modules '__main__' and 'a' are executing from the same file they have completely separate namespaces. So when b imports a it is going to see a brand new Borg class, not the one you created in your __main__ script. The solution is to put your Borg class in a separate module, or more generally never try to import anything from the __main__ script that you use to kick off the program. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From ransen_spam_me_not at nemo.it Wed Oct 3 01:27:19 2001 From: ransen_spam_me_not at nemo.it (Owen F. Ransen) Date: Wed, 03 Oct 2001 05:27:19 GMT Subject: Python Based Graphics Course Message-ID: <3bbd8dc6.416252@news.newsguy.com> I tried to post this, twice, but it did not turn up in the newsgroup...any ideas? PRESS RELEASE Ransen's Artistic Programming Tutor RAPT (Ransen's Artistic Programming Tutor) makes it fun and interesting to create images using programming. You learn to program in order to create images (instead of doing abstract mathematical operations or boring text manipulations). The course consists of an electronic book (PDF format) of 10 chapters and a graphics program which allows you to immediately view and save the images you have made. You will learn to describe and create colors, lines, circles, arcs, points, disks, graded backgrounds etc. You will understand how to use a computer to generate new ideas by casual combinations of simple objects. You will learn how to make spirals and schematic cities, precision optical art and wild random art. RAPT is ideal for artists as a self teaching tool, or for teachers who want a fun way of introducing programming to their pupils. Python, an increasingly popular programming language, is used as the basis of the course. The program runs on Windows-95, 98, ME, NT-4 and 2000. A free demo version is available from http://www.ransen.com/rapt/ The single user full version costs $19.95(US) and allows saving in Illustrator 9 and CorelDraw 10 PS vector formats, as well as normal bitmap formats (PNG,BMP,JPG,PCX,TGA) up to 2500 pixels square. Site licenses are available. For more information contact: Owen Ransen at ransen at nemo.it or The Saelig Company email:Saelig at aol.com Tel: (716) 425 3753 Fax: (716) 425 3835 -- Owen F. Ransen http://www.ransen.com/ Home of Gliftic & Repligator Image Generators From CpJohnson at edgars.co.za Wed Oct 17 06:41:10 2001 From: CpJohnson at edgars.co.za (CpJohnson at edgars.co.za) Date: Wed, 17 Oct 2001 13:41:10 +0300 Subject: Web Application Framework Message-ID: <42256AE8.003AA963.00@JHBMAIL01.edgars.co.za> Hi Pythoners, May I prevail on your patience once more. Oleg sent me the following links, and now I'm spoiled for choice. http://webware.sourceforge.net/ http://www.mems-exchange.org/software/quixote/ http://www.twistedmatrix.com/ Can anybody comment on which of these would be the best to use for a stand-alone application that generates all of it's forms on the fly from data stored in some or other datastore, possibly in XML documents. No forms are stored on disk at all. Thanks, Craig ------------------Edcon Disclaimer ------------------------- This email is private and confidential and its contents and attachments are the property of Edcon. It is solely for the named addressee. Any unauthorised use or interception of this email, or the review, retransmission, dissemination or other use of, or taking of any action in reliance upon the contents of this email, by persons or entities other than the intended recipient, is prohibited. Save for communications relating to the official business of Edcon, the company does not accept any responsibility for the contents of this email or any opinions expressed in this email or its attachments . If you are not the named addressee please notify us immediately by reply email and delete this email and any attached files. Due to the nature of email Edcon cannot ensure and accepts no liability for the integrity of this email and any attachments, nor that they are free of any virus. Edcon accepts no liability for any loss or damage whether direct or indirect or consequential, however caused, whether by negligence or otherwise, which may result directly or indirectly from this communication or any attached files. Edgars Consolidated Stores LTD ,Post office box 200 Crown Mines, Telephone: (011) 495-6000 From stadt at cs.utwente.nl Tue Oct 23 12:51:12 2001 From: stadt at cs.utwente.nl (Richard van de Stadt) Date: Tue, 23 Oct 2001 17:51:12 +0100 Subject: smtplib.SMTPDataError: (503, 'Error: need RCPT command') References: <3BD4F3E8.1E4B826B@cs.utwente.nl> Message-ID: <3BD5A000.7D0A1A54@cs.utwente.nl> Steve Holden wrote: > try: > mail = smtplib.SMTP(LocalMailServer) > except: > mail = smtplib.SMTP(altLocalMailServer) > mail.sendmail(fromaddr, recipients, message % locals()) [...] > smtplib line 386 raises an > error because the server doesn't give the expected reply when the client > starts to send the message body. > > To check this, try adding > > mail.set_debuglevel(1) > > before the .sendmail() call, which will give you a trace of client/server > interactions. That hint helped. Turns out the machine I was running this on doesn't have an smtp server. Therefore smtplib.SMTP('localhost') didn't work out and raised an exception, after which the altLocalMailServer was tried, which didn't accept the request from this system (which is correct behavior :-) Thanks a lot. Richard. From nobody at home._NOSPAM_.net Fri Oct 12 17:07:35 2001 From: nobody at home._NOSPAM_.net (Justin) Date: Fri, 12 Oct 2001 23:07:35 +0200 Subject: how do I add site-packages on Windows? References: <3bc57f3b$0$233$edfadb0f@dspool01.news.tele.dk> Message-ID: <9q7m1c$2e70$1@rivage.news.be.easynet.net> I may be missing something here, and you may absolutely want to achieve this programmatically, but otherwise you can use pythonwin, "Tools/Edit Python Path", then right click on PythonPath and edit the value, or add a dependent key. You could also simply right-click on the following (you may have to edit the PYTHONROOT, obviously) ----------> start of spkg.reg <---------- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.0\PythonPath\lib-site] @="C:\\Python20\\Lib\\site-packages" ----------> end of spkg.reg <---------- "Max M" wrote in message news:3bc57f3b$0$233$edfadb0f at dspool01.news.tele.dk... > I have had this problem before, but never really got a working solution. > > If I put packages into: > > \Lib\site-packages\ > > And then I try to use it from ie. iis (Windows naturally) Python cannot find > my packages. > > What would I need to do to make Python search in site-package automatically? > > Should I put them into "Plat-Win" instead, or is that used for something > else ??? > > regards Max M From logiplexsoftware at earthlink.net Wed Oct 3 13:16:48 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 3 Oct 2001 10:16:48 -0700 Subject: "self" vs other names In-Reply-To: References: Message-ID: <01100310164802.03969@logiplex1.logiplex.net> On Tuesday 02 October 2001 19:18, Grant Edwards wrote: > In article , Ignacio Vazquez-Abrams wrote: > >On Wed, 3 Oct 2001, Tim Hammerquist wrote: > >> What would the world have been like if CP/M had won over (PC|MS)-DOS? > > > >Not that much different; AFAIK MS-DOS was based on some of the principles > > of CP/M (8.3 filename, etc.). > > PC-DOS was an out-and-out copy of CP/M. The layout of FCBs was the same, > the methods to call BIOS were the same, the layout of executable file > headers was the same... Except, as I recall, there was already a multiuser version of CP/M (MP/M) when DOS arrived (imagine running up to 8 users on a single 8080/Z80! Oh the possibilities...), so maybe the "DR-Windows" of today would have some real multiuser capabilities instead of having to have them added as a third-party package. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From nospam at bigfoot.com Mon Oct 15 14:56:19 2001 From: nospam at bigfoot.com (Gillou) Date: Mon, 15 Oct 2001 20:56:19 +0200 Subject: python + xml performance compared to Java and C++ ?? References: Message-ID: <9qfb5a$2l55$1@norfair.nerim.net> With Windows U can use the "MSXML2.DOMDocument" COM object that's pretty fast and provides XSLT compilation features. The fastest XML DOM parser (among those available for Python) but there are still some bugs in XSLT processing. > > Fortunately, there are two projects that are working on providing > bridges between the C++ versions of Xalan and Xerces and Python: > > Pyana is focused on providing Xalan's transformation capabilities to > Python scripts: > https://sourceforge.net/projects/pyana > http://pyana.sourceforge.net/docs/ > > Pirxx is focused on providing an interface to Xerces, right now it > only provides SAX2 drivers but work is on-going: > https://sourceforge.net/projects/pirxx > (don't know where the docs are) > > Cheers, > Brian > > > From burner at core.binghamton.edu Sun Oct 28 01:30:22 2001 From: burner at core.binghamton.edu (Michael R. Head) Date: Sun, 28 Oct 2001 01:30:22 -0500 Subject: Why doesn't this simple Curry-like implemention work? Message-ID: <20011028013022.A2647@warp.core.binghamton.edu> # for some reason this function doesn't work in python 1.5.2. def curry(f, p): return lambda x: apply(f, p, x) I've looked up on the list better class-based implementations, and am using one of them, but I'm curious why this doesn't work (when the curried function is called, f becomes unknown). (I'm looking for a reason in the language spec). I'm supposing that lamda isn't storing the reference to its inputs -- which it seems it should -- is this correct? mike -- Michael R. Head burner at core.binghamton.edu GPG public key: http://www.core.binghamton.edu/~burner/gpg.key.txt -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 536 bytes Desc: not available URL: From bokr at accessone.com Mon Oct 22 16:17:07 2001 From: bokr at accessone.com (Bengt Richter) Date: Mon, 22 Oct 2001 20:17:07 GMT Subject: Reverse argument order References: <3bd1f335.1049196274@wa.news.verio.net> Message-ID: <3bd47e69.1215904838@wa.news.verio.net> On Sat, 20 Oct 2001 23:16:54 GMT, slinkp23 at yahoo.com (Paul Winkler) wrote: >On Sat, 20 Oct 2001 21:53:52 GMT, Bengt Richter wrote: >>Brute force, but clear: >> >> >>> def wait(first=None,second=None,third=None): >> ... if third: h,m,s = first,second,third >> ... elif second: h,m,s=0,first,second >> ... elif first: h,m,s=0,0,first >> ... else: h,m,s=0,0,0 >> ... print "h=%d, m=%d, s=%d" % (h,m,s) # or whatever you want to do >> ... >> >>> wait() >> h=0, m=0, s=0 >> >>> wait(1) >> h=0, m=0, s=1 >> >>> wait(1,2) >> h=0, m=1, s=2 >> >>> wait(1,2,3) >> h=1, m=2, s=3 > >This is broken! > Oops ;-/ >>>> wait(1,2,3) >h=1, m=2, s=3 >>>> wait(1,0,0) >h=0, m=0, s=1 > >Clearly the user intended to get h=1, m=0, s=0. > >Fix: Change it so your tests look like "if third is not None:" >... etc. Then it works: > >>>> wait(1,0) >h=0, m=1, s=0 >>>> wait(1,0,0) >h=1, m=0, s=0 >>>> wait(1,0,5) >h=1, m=0, s=5 > >But it's still not great, because the function def implies that this >function can take keyword args when in fact it can't: > >>>> wait(second=9) >Traceback (most recent call last): > File "", line 1, in ? > File "", line 6, in wait >TypeError: an integer is required > >That could confuse a user who actually bothered to learn python. > >I think Kirill's solution (among others) is better; it does the right Me too, as I noted when I saw it. How do you retract a[n embarrassing] post? >thing with inappropriate keyword args: > >TypeError: wait() got an unexpected keyword argument 'foo' > > Summary: A clear case of PIHCAL (post in haste, cringe at leisure) ;-/ From DeepBlue at DeepBlue.org Tue Oct 9 12:14:48 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Tue, 9 Oct 2001 11:14:48 -0500 Subject: Hightower's Python Programming with the Java(tm) Class Libraries Message-ID: This book will be published on Feb 2002 as appears on amazon.com. Does this book cover Jython? DB From robin at jessikat.fsnet.co.uk Thu Oct 18 06:05:12 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 18 Oct 2001 11:05:12 +0100 Subject: signum() not in math? References: <3BCC4F94.9170B0BB@darwin.in-berlin.de> Message-ID: <3eIMQKAYlqz7EwLt@jessikat.demon.co.uk> In article , Tim Peters writes ..... >So let's ask: everyone on c.l.py please send a msg to Dinu explaining why >you personally haven't submitted a patch to add signum() . > ... the inquisition or something more gentle? -- Robin Becker From jblazi at hotmail.com Fri Oct 5 10:35:25 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Fri, 5 Oct 2001 16:35:25 +0200 Subject: list to tuple question Message-ID: <3bbdc533_6@news.newsgroups.com> I'd like to make a formatted string like this: s='%s %s %s %s %s %s %s %s %s\n' % (A,)+b+(C,D) The point is, that b is already a list and this would simplify matters. Most unfortunately (or most obviously for the initiated) I get the error message that a tuple and a list cannot be concatenated. What should I do. I could solve the problem by using a for-loop but is it necessary? J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From brueckd at tbye.com Tue Oct 23 21:33:23 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 23 Oct 2001 18:33:23 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: <01102314110808.14120@logiplex1.logiplex.net> Message-ID: On Tue, 23 Oct 2001, Cliff Wells wrote: > >From original post: > "only case I can see this being a problem is when, say, > Thread A locks something in the main thread, starts to > interact with it, is preempted, and then the main > thread gets a timeslice and interacts with the locked > resource--which it views as local and doesn't need to > check for a lock." > > If you are going to share a resource among threads, then _every_ access to > that resource _must_ be enclosed in locks (even if you are only reading from > the resource). [snip] No, "normal" operations on Python objects are atomic as far as threads are concerned. There are some very good reasons for using locking/signaling (to sequentialize access to a function, to keep a worker thread asleep until you use a semaphore to signal it to awake, etc), but it's not always a requirement. Consider a simple producer/consumer situation: import threading, time, random foo = [] def producer(): for i in range(10): print 'Producing', i foo.append(i) time.sleep(random.random() * 1.0) print 'Producer done' def consumer(): count = 0 while 1: try: num = foo.pop(0) print 'Consuming', num count += 1 if count >= 10: break except IndexError: pass time.sleep(random.random() * 1.0) print 'Consumer done' threading.Thread(target=consumer).start() threading.Thread(target=producer).start() Output: Producing 0 Producing 1 Consuming 0 Producing 2 Producing 3 Consuming 1 Producing 4 Consuming 2 Producing 5 Consuming 3 Consuming 4 Producing 6 Consuming 5 Producing 7 Consuming 6 Producing 8 Producing 9 Producer done Consuming 7 Consuming 8 Consuming 9 Consumer done No crashes, stomped memory, or any other problems you'd expect. -Dave From salemail at dial.pipex.com Thu Oct 18 04:34:02 2001 From: salemail at dial.pipex.com (Kevin D) Date: 18 Oct 2001 01:34:02 -0700 Subject: Conditional Expressions don't solve the problem References: Message-ID: Hi John, "John Roth" wrote in message news:... > "Kevin D" wrote in message > news:c2a5d721.0110170224.584a2d78 at posting.google.com... > > 1) Duplication of the 'load': > > > > foo = some_long_expression > > while foo != terminating_condition: > > body_of_loop() > > foo = some_long_expression > > > > The argument for only having to spell the 'load' of "foo" once is the > > same as part of the argument for augmented assignment (mis-spelling of > > the expression leading to subtle bugs). This is more acute than for > > augmented assignment, as the load inside the body of the loop could be > > a great physical distance on the screen from the initial load it is > > duplicating. > > It's also a case of duplication of code, which is a Bad Thing (tm). Yes, sorry if I didn't make this clear - the duplication of code is the "part of the argument for augmented assignment" that I was referring to (the other (that I can remember) being the reduced amount of attribute lookups, which doesn't apply here). > > 2) "while 1" idiom: > > > > while 1: > > foo = some_long_expression > > if foo == terminating_condition: > > break > > body_of_loop() > > > > This solves problem (1) but IMHO, falls down in your "interrupting the > > thought process" requirement - it takes some mental juggling to work > > out just what the condition _is_ when reading the code. This is partly > > because the actual termination condition is buried somewhere away from > > the "while" statement and partly because the condition is reversed (so > > having searched out the termination condition, you must then read it > > as "until ", or "while not " - either way, the > > code has to be mentally "translated"/restructured as it's being read). > > It only has to if you persist in reading it as a while loop! If you > recognize > "while 1:" as a separate control construct, then there is much less of a > mental problem. If it's not a while loop, it should not be spelled "while". That's _exactly_ my point - you read one thing and then have to think another. This impacts on the clarity of the code. "if" is not spelled "because" for a very good reason ;) > See my comment, and the thread involving the [;...; construct. It does everything you want. It also lets you put statements > in lambda expressions, which may prejudice a lot of people against it. Two problems: As you've mentioned with the lambda thing, making this sort of thing a general construct may be it's undoing as it's easy to abuse. My suggestion was quite strict in only allowing a single assignment in which one can prep the condition control variables. The other thing is that things look backwards when reading the code. "while " just looks wrong, even if a condition eventually occurs on the line. Something like "while where " reads pretty much like English (to me) and therefore requires the least amount of mental juggling to make sense of, IMHO. Also, note that I keep saying "something like" before my examples. I'm not that tied to the exact syntax I'm suggesting, but I'm trying (probably badly) to expand on what I think a Pythonic (read "obvious meaning") solution to the root issues might look like. Regards, Kev. From python at chajadan.net Thu Oct 4 01:20:58 2001 From: python at chajadan.net (chajadan) Date: Thu, 4 Oct 2001 05:20:58 +0000 Subject: list remove Message-ID: <200110040520.AA61472908@chajadan.net> This one really tickled me =) But I actually was left with a question as well. When you say: for bar in foo: is not the first bar [1], so why doesn't the second element get deleted first? rather than being left at the end altogether..?? --chajadan ---------- Original Message ---------------------------------- From: steven.smith at LEVEL3.com Date: Tue, 2 Oct 2001 10:30:51 -0600 >The python tutorial at >http://www.python.org/doc/current/tut/node7.html#SECTION00710000000000000000 >0 has the section more on lists where it gives the function remove(x). I am >trying to use this function to delete elements out of my list, but it only >deletes every other list. > >>>>foo = [1, 2, 3, 4, 5] >>>>for bar in foo: >... foo.remove(bar) > >>>>foo >[2, 4] > >Is this an error on my part, pythons list type or am I misinterpretting what >remove does? I have tried this on both 2.1 and 1.5.2. > >Thanks. >Steve > >-- >http://mail.python.org/mailman/listinfo/python-list > From aleax at aleax.it Wed Oct 3 03:39:29 2001 From: aleax at aleax.it (Alex Martelli) Date: Wed, 3 Oct 2001 09:39:29 +0200 Subject: Python is better than free (was Re: GNU wars again) References: Message-ID: <9pefbe$8c1$1@serv1.iunet.it> "Chris Watson" wrote in message news:mailman.1002078843.29724.python-list at python.org... > On Tuesday 02 October 2001 09:54 pm, Delaney, Timothy wrote: > > > From: Chris Watson [mailto:opsys at voodooland.net] > > However, GPL is *not* extortion. The writer of a piece of code has every > > right to want to protect, control or charge for it. > > That's true. But dont call it Free code if you do. Because it is not free. > Look up free in the dictionary. That is the ONLY definition that should be > followed. Not whatever twisted version the FSF and GNU people want to use. > The gernal gist of any dictionary is its free if its free from control, > opression, or restrictions. You seem to be using a very poor dictionary. "Free", like all important words in natural language (study Wittgenstein's "Philosophische Untersuchungen" for a deeper understanding of why), is fuzzy and heavily overloaded. Tracing its historical roots, we come to Sanskrit "priya" -- and the closest English translation I can give of THAT is "own", as in "mine own", "prized", "beloved". Merriam-Webster online, hardly the widest dictionary in common use:-), gives just fifteen root meanings for today's use of "free" in English. Just these should suffice to show that the singular in "the ONLY definition" is utterly inappropriate. Are you, as a US citizen, "not free" because you DO suffer restrictions -- indispensable to ensure all other citizens are just as free as you are? "Your freedom to swing your fist ends short of the tip of my nose", and all that (the argument by symmetry is best developed IMHO in Kant's "Kritik der praktischen Vernunft"). Specifically, are you made non-free by the restriction (14th emendment, I believe?) that you cannot be sold nor sell yourself as a slave -- is your freedom nullified by being enshrined as permanent and unalienable? Most US citizens would not support such a contention today, I believe. Fight your political battles for or against any kind of software licence however you wish -- many of us don't care that much either way -- but don't think you'll ever get away with claiming "the dictionary" (as if there was only one!) somehow supports your favoured "ONLY definition" (as if there was only one!). Not as long as some of us deeply and passionately care about *words* -- their history, their usage, their inter-relationship, the splendid web we can weave with them. Care to the point of spending time on Usenet which we DEFINITELY should be employing more productively, sigh:-). Alex From reqhye72zux at mailexpire.com Fri Oct 26 19:05:20 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Fri, 26 Oct 2001 23:05:20 -0000 Subject: Question: CPython References: <3BD79BBC.B2FA669B@hotmail.com> Message-ID: Lucio Torre wrote: > scott wrote: > >> [JPython] >> >>Called 'Jython' now. Its predecessor was JPython. >>http://www.jython.org >> > And python is now called Cython. :) I'd prefer Scython: much more 'cutting edge'. Robert Amesz From tim at zope.com Thu Oct 4 16:56:03 2001 From: tim at zope.com (Tim Peters) Date: Thu, 4 Oct 2001 16:56:03 -0400 Subject: Python 2.2a4: Problems with overloading __str__ in subclasses of str In-Reply-To: Message-ID: [Andreas.Trawoeger] > I just ran into a strange problem with Python 2.2a4. You sure did. Now how about fixing it too ? Please report bugs on SourceForge -- they're likely to get overlooked if just posted to c.l.py. I entered this one for you: From Laurent.Pierron at loria.fr Tue Oct 16 06:27:26 2001 From: Laurent.Pierron at loria.fr (Laurent Pierron) Date: Tue, 16 Oct 2001 12:27:26 +0200 Subject: Perl Range operator paradigm Message-ID: <3BCC0B8D.F4EFF59C@loria.fr> Hello Gurus, In Perl there is a very powerful range operator '..', which, in scalar context, is acting like line-range (,) operator in sed and awk. By example, this small program prints all the lines in the file included between ... : while (<>) { if (// .. /<\/BODY>/) {print; } } How can I do, the same thing in Python ? Thanks. -- Laurent PIERRON From jhauser at ifm.uni-kiel.de Sun Oct 14 14:54:21 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 14 Oct 2001 20:54:21 +0200 Subject: Troubles with global variables References: <87r8s4vmgy.fsf@toadmail.com> Message-ID: <87d73q6oiq.fsf@lisboa.ifm.uni-kiel.de> Ah, silly me. The just posted example had the answer. You are not printing the variables, but a constant string. Use this line as the menu line, and perhaps look up the manual for string formatting rules. print 'Menu: \n1) Change a: %s\n2) Change b: %s' % (a,b) HTH, __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From GeorgLohrer at gmx.de Fri Oct 12 03:24:45 2001 From: GeorgLohrer at gmx.de (Georg Lohrer) Date: Fri, 12 Oct 2001 09:24:45 +0200 Subject: How to handle sys.path in bigger projects? Message-ID: <226dstkol613p95ampm7libas5tp6t0a3b@4ax.com> Hello, I'm just realizing a simulator in telecommunication with Python, omniORB, tkInter and XML; C++ for testing the simulator will be used, too. Lines of Python-code have now reached 10.000. The code is devided in several directories and modules (corba, xml, messages, remote-control, etc.). Most of the modules need some stuff out of other modules residing in another directory. In the main module I'm using the pathconf.py script of Frederic L. Drake to setup sys.path. So, starting on root-dir of the project all things run well, but pycheck'ing a module in a 'lower'-directory won't work because I do not want to add pathconf.py to every module. My question is: how do you deal with bigger projects and setting sys.path accordingly: [ ] Use only one directory and let module-size increase? [ ] Use multiple directories but add sys.path.append in front of ervery module? [ ] ..... [ ] .... What are your ways of handling? Probably I've not found the ultimate way to deal with this problem, but facing that the source-code size increases rapidely I've to concern about this. Ciao, Georg From walter at livinglogic.de Thu Oct 4 14:22:01 2001 From: walter at livinglogic.de (Walter =?ISO-8859-1?Q?D=F6rwald?=) Date: Thu, 04 Oct 2001 20:22:01 +0200 Subject: Proposed PEP: Codec error handling callbacks Message-ID: <3BBCA8C9.7050901@livinglogic.de> Here's a first try at a PEP for making Python's codec error handling customizable. This has been briefly discussed before on the I18N-SIG mailing list. A sample implementation of the proposed feature is available as a SourceForge patch. Bye, Walter D?rwald --------------------------------------------------------------------------- PEP: ??? Title: Codec error handling callbacks Version: $Revision$ Last-Modified: $Date$ Author: walter at livinglogic.de (Walter D?rwald) Status: Draft Type: Standards Track Python-Version: 2.3 Created: ??-???-2001 Post-History: 04-Oct-2001 Abstract This PEP aims at extending Python's fixed codec error handling schemes with a more flexible callback based approach. Python currently uses a fixed error handling for codec error handlers. This PEP describes a mechanism which allows Python to use function callbacks as error handlers. With these more flexible error handlers it is possible to add new functionality to existing codecs by e.g. providing fallback solutions or different encodings for cases where the standard codec mapping does not apply. Problem A typical case is where a character encoding does not support the full range of Unicode characters. For these cases many high level protocols support a way of escaping a Unicode character (e.g. Python itself support the \x, \u and \U convention, XML supports character references via &#xxxx; etc.). When implementing such an encoding algorithm, a problem with the current implementation of the encode method of Unicode objects becomes apparent: For determining which characters are unencodable by a certain encoding, every single character has to be tried, because encode does not provide any information about the location of the error(s), so # (1) us = u"xxx" s = us.encode(encoding) has to be replaced by # (2) us = u"xxx" v = [] for c in us: try: v.append(c.encode(encoding)) except UnicodeError: v.append("&#" + ord(c) + ";") s = "".join(v) This slows down encoding dramatically as now the loop through the string is done in Python code and no longer in C code. Furthermore this solution poses problems with stateful encodings. For example UTF16 uses a Byte Order Mark at the start of the encoded byte string to specify the byte order. Using (2) with UTF16, results in an 8 bit string with a BOM between every character. To work around this problem, a stream writer - which keeps state between calls to the encoding function - has to be used: # (3) us = u"xxx" import codecs, cStringIO as StringIO writer = codecs.lookup(encoding)[3] v = StringIO.StringIO() uv = writer(v) for c in us: try: uv.write(c) except UnicodeError: uv.write(u"&#%d;" % ord(c)) s = str(v) To compare the speed of (1) and (3) the following test script has been used: # (4) import time us = u"?a"*1000000 encoding = "ascii" import codecs, cStringIO as StringIO t1 = time.time() s1 = us.encode(encoding, "replace") t2 = time.time() writer = codecs.lookup(encoding)[3] v = StringIO.StringIO() uv = writer(v) for c in us: try: uv.write(c) except UnicodeError: uv.write(u"?") s2 = v.getvalue() t3 = time.time() assert(s1==s2) print "1:", t2-t1 print "2:", t3-t2 print "factor:", (t3-t2)/(t2-t1) On Linux with Python 2.1 this gives the following output: 1: 0.395456075668 2: 126.909595966 factor: 320.919575586 i.e. (3) is 320 times slower than (1). Solution 1 Add a position attribute to UnicodeError instances. When the encoder encounters an unencodable character it raises an exception that specifies the position in the Unicode object where the unencodable character occurs. The application can then reencode the Unicode object up to the offending character, replace the offending character with something appropriate and retry encoding with the rest of the Unicode string until encoding is finished. A stream writer will write everything up to the offending character and then raise an exception, so the application only has to replace the offending character and retry the rest of the string. Advantage Requires minor changes to all the encoders/stream writers. Disadvantage As the encoder has to be called multiple times, this won't work with stateful encoding, so a stream writer has to be used in all cases. If unencodable characters occur very often Solution 1 will probably not be much faster than (3). E.g. for the string u"a"*10000+u"?" all the characters but the last one will have to be encoded twice when using an encoder (but only once when using a stream writer). This solution is specific to encoding and can't be extended to decoding easily. Solution 2 Add additional error handling names for every needed replacement scheme (e.g. "xmlcharrefreplace" for "&#%d;" or "escapereplace" for "\\x%02x" / "\\u%04x" / "\\U%08x") Advantage Requires minor changes to all encoders/stream writers. As the replacement scheme is implemented directly in the encoder this should be the fastest solution. Disadvantages The available replacement schemes are hardwired. Additional replacement schemes require that all encoders/decoders are changed again. This is especially problematic for decoding where users might want to implement various error handlers for handling broken text files. Solution 3 The errors argument is no longer a string, but a callback function: This callback function gets passed the original unicode object and the position of the unencodable character and returns a new unicode object that should be encoded instead of the unencodable one. (Note that this requires that the encoder *must* be able to encode what is returned from the handler. If not a normal UnicodeError will be raised.) Example code could look like this: us = u"xxx" def xmlescape(uni, pos): return u"&#%d;" % ord(uni[pos]) s = us.encode(encode, xmlescape) Advantages This makes the error handling completely customizable. The error handler may choose to raise an exception or do any kind of replacement required. The interface between the encoder and the error handler can be designed in a way that this mechanism can be used for decoding too: The original 8bit string is passed to the error handler and the error handler returns a replacement unicode object and a resyncronization position where decoding should continue. Disadvantages This solutions requires changes to every C function that has "const char *errors" arguments. (e.g. PyUnicode_EncodeLatin1( const Py_UNICODE *p, int size, const char *errors) has to be changed to PyUnicode_EncodeLatin1( const Py_UNICODE *p, int size, PyObject *errors) (To provide backwards compatibility the PyUnicode_EncodeLatin1 signature remains the same, a new function PyUnicode_EncodeLatin1Ex is introduced with the new signature. PyUnicode_EncodeLatin1 simply calls the new function.) Solution 4 The errors argument is still a string, but this string is used to lookup a error handling callback function from a callback registry. Advantage No changes to the Python C API are required. Well known error handling schemes could be implemented directly in the encoder/decoder for maximum speed. Like solution 3 this can be done for encoders and decoders. Disadvantages Currently all encoding/decoding functions have arguments const Py_UNICODE *p, int size or const char *p, int size to specify the unicode characters/8bit characters to be encoded/decoded. In case of a error a new unicode or str object has to be created from this information and passed to the error handler. This has to be done either for every occuring error or once on the first error and the result object must be kept until the end of the function in case another error occurs. Most functions that call the codec functions work with unicode/str objects anyway, so they have to extract the const Py_UNICODE */int arguments and pass it to the functions, which has to reconstruct the object in case of an error. Sample implementation A sample implementation is available on SourceForge [1]. This patch implements a combination of solutions 3 and 4, i.e. it is possible to pass functions *and* registered callback names to unicode.encode. The interface between the encoder and the handler has been extended to be able to support the same interface for encoding and decoding. The encoder/decoder passes a tuple to the callback with the following entries: 0: the name of the encoding 1: the original Unicode object/the original 8bit string 2: the position of the unencodable character/byte 3: the reason why the character/byte can't be encoded/decoded as a string (e.g. "character not in range(128)" for encoding or "unexpected end of data", "invalid code byte" etc. for decoding) 4: an additional object that can be used to pass state information to the callback. All implemented encoders/decoders currently pass None for this. The callback must return a tuple with the following info: 0: a Unicode object which will be encoded instead of the offending character (for encoders). A Unicode object that will be used as a replacement for the undecodable bytes in the decoded Unicode object (for decoders) 1: a position where the encoding/decoding process should continue after processing the replacement string. The patch includes several preregistered encode error handlers schemes with the following names: "strict", "ignore", "replace", "xmlcharrefreplace", "escapereplace" and decode error handlers with the names: "strict", "ignore", "replace" The patch includes the other change to the C API described in Solution 4. The parameters const Py_UNICODE *p, int size have been replace by PyObject *p so that all functions get the Unicode object directly as a PyObject * and pass this directly along to the error callback. For further details see the patch on SourceForge. References [1] Python patch #432401 "unicode encoding error callbacks" http://sourceforge.net/tracker/?group_id=5470&atid=305470&func=detail&aid=432401 [2] Previous discussions on this topics in the I18N-SIG mailing list http://mail.python.org/pipermail/i18n-sig/2000-December/000587.html http://mail.python.org/pipermail/i18n-sig/2001-June/001173.html Copyright This document has been placed in the public domain. Local Variables: mode: indented-text indent-tabs-mode: nil End: From sholden at holdenweb.com Thu Oct 25 06:58:34 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 25 Oct 2001 06:58:34 -0400 Subject: get the user name References: <3BD7ECA8.7A786A3E@c-s.fr> Message-ID: "anthony harel" wrote ... > Hi, > > Is there a way with python1.5.2 to get the name of the user on > UNIX and Windows ? > >From Python 2.0 library reference manual, Section 6.11 (the getpass module): """ getuser () Return the ``login name'' of the user. Availability: Unix, Windows. This function checks the environment variables $LOGNAME, $USER, $LNAME and $USERNAME, in order, and returns the value of the first one which is set to a non-empty string. If none are set, the login name from the password database is returned on systems which support the pwd module, otherwise, an exception is raised. """ So you are looking for getpass.getuser(). regards Steve -- http://www.holdenweb.com/ From ignacio at openservices.net Tue Oct 16 19:10:20 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 16 Oct 2001 19:10:20 -0400 (EDT) Subject: Extending Python - variable sized arrays? In-Reply-To: Message-ID: On Tue, 16 Oct 2001, Tim Egbert wrote: > I'm developing a native method module for Python from some existing code. > One function that I call returns an integer array that can be any size up > to 128. > > Returning the array as a tuple using Py_BuildValue() is a problem because, > although I can create the format string dynamically, I can't create a > dymanically sized argument list. Maybe I'm just being dense, but I'd like > to do something like this (illustrated here with a currently nonexistent > function call, Py_BuildArrayTuple()): > > PyObject *ret; > int *arr; > ... > (arr gets allocated and loaded with 6 values) > ... > ret = Py_BuildArrayTuple("6i",arr); > return ret; > > which would be the equivalent of: > > ret = Py_BuildValue("iiiiii", > arr[0],arr[1],arr[2],arr[3],arr[4],arr[5]); > > I can't go the Py_BuildValue() route because the problems is, the next > time around, there may be 17 or 127 elements in the array, the exact > number only to be known during runtime. > > Any thoughts on how to do this? Use PyTuple_New() and then do PyTuple_SetItem() in a loop. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From loewis at informatik.hu-berlin.de Tue Oct 30 07:31:54 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 30 Oct 2001 13:31:54 +0100 Subject: detecting and creating directories References: <3BDDA7BC.8CF7C891@mitre.org> <0fjD7.3353$Z_1.574942@newsc.telia.net> Message-ID: "Steve Holden" writes: > > for ten extra points, explain why this is a lousy way to > > do this. > > Because the effbot is inherently clueful, and has suggested this is not the > best way? Not sure what Fredrik had in mind, but considering that the original question was >> I found the module that has the command to make directories, but I >> have not been lucky finding a way to check for the existance of a >> directory (so it is not there, I can create it). my approach would be try: os.mkdir(path) except OSError,(num,msg): if num != errno.EEXIST: raise This is just a single system call, and the system atomically checks whether the directory is there, and creates it if it is not. If you want, you can analyse the EEXIST error in more detail (checking whether the existing file really is a directory, whether it is really owned by the correct user, etc.) Regards, Martin From aleax at aleax.it Fri Oct 12 04:27:23 2001 From: aleax at aleax.it (Alex Martelli) Date: Fri, 12 Oct 2001 10:27:23 +0200 Subject: Borg Pattern Class usable from other classes? References: Message-ID: <9q69h8$grb$1@serv1.iunet.it> "Paolo Invernizzi" wrote in message news:V8kx7.32$1S1.2130 at nreader3.kpnqwest.net... > er, shouldn't it be called a singleton? > Alex can kill you for this ;)) All bridge players know that a singleton is something you lead hoping partner has the Ace of the suit, so that partner can return a second round of the suit for you to ruff. I'm all in favour of closer integration between my two great loves, bridge and programming, but the DP seems misnamed. Highlander for the DP, and Borg for the non-pattern which I posted and D. Ascher named, seem much more appropriate names, as the connection to science fiction movies/TV series is sharp and pleasingly anti-parallel. As for the issues in this thread, I agree with the diagnosis that the problem is all about mutual imports -- Borg being an innocent bystander, for once. Alex From grahamd at dscpl.com.au Wed Oct 31 01:08:49 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 30 Oct 2001 22:08:49 -0800 Subject: ANN: OSE 7.0 finally available. Message-ID: After almost a year of beta releases, OSE 7.0 is finally available. At its core, OSE is a C++ class library for general purpose programming, but also includes support for building event driven systems and distributed applications using a request/reply and publish/subscribe style service agent framework. The ability to interact with an application is facilitated using a HTTP servlet framework and RPC over HTTP interfaces. In short, OSE could be said to take technology from event driven real time systems, message oriented middleware, application server and web service technology and wraps it all into one. Although C++ at its core, OSE also provides wrappers for the Python programming language. This mix means that OSE serves as a useful platform for building standalone or distributed applications in Python, C++ or a mix of both. Its support of both XML-RPC and SOAP protocols through a single service interface makes it ideal for building web based services. Further information on OSE and the software itself, can be found at: http://ose.sourceforge.net This includes over 100 pages of documentation on the Python interfaces alone. The Python documentation can be viewed on the site as HTML, or as a single PDF file at: http://ose.sourceforge.net/python-manual.pdf OSE is released under the QPL. This release is the culmination of over 10 years of development, OSE first being available over the Internet in 1993. From paul at boddie.net Mon Oct 15 10:53:42 2001 From: paul at boddie.net (Paul Boddie) Date: 15 Oct 2001 07:53:42 -0700 Subject: python + xml performance compared to Java and C++ ?? References: Message-ID: <23891c90.0110150653.4f7e51d4@posting.google.com> philipprw at gmx.at (Philipp Weinfurter) wrote in message news:... > > dunno about java, but the C++ versions of the apache tools are > much much faster than anything you can do with python. but that's > kinda obvious, since XSLT processing ist quite CPU intensive. > same goes with building large DOM trees. i guess with SAX you'd > be better off, using pure python. What about the Python wrappers around Xerces and Xalan, recently announced on comp.lang.python.announce? > philipp > (who thinks that XSLT is the ugliest language ever designed) XSLT seems to be related to SAX (programmed with some mythical language) as PSP is related to Python and JSP is related to Java. So, of course it isn't going to look nice. ;-) Paul From ashish.tilwe at db.com Fri Oct 19 11:56:14 2001 From: ashish.tilwe at db.com (tilwe) Date: 19 Oct 2001 08:56:14 -0700 Subject: Python Aborts when I quit References: Message-ID: "Steve Holden" wrote in message news:... > ..... > I too, am puzzled, but for a different reason. If you have indeed > cut-and-pasted the stuff above from Python interpreter sessions and files, I > am puzzled as to why you don't see error messages! > > Firstly, shouldn't > > >>> print testvar() > > have been > > >>> print c_plus_plus_module.testvar() >..... > > regards > Steve Hi Steve, I have reduced the code to a manageable size. The actual code is about 1500 lines. It was only after I had the above code was when I started getting errors. Here is the actual code. First the C++ code (Again only error function is displayed) ------------------------------------------------------------------------- static char errMsg[1024] ; const int intmax = ~((unsigned)1 << (8 * (int)sizeof(int)) - 1) ; static PyObject * makeCall(PyObject * self, PyObject * args) { PyObject * rRow = NULL ; int func ; char * funcval ; try { errMsg[0] = '\0' ; if(!PyArg_ParseTuple(args, "is", &func, &funcval)) throw "Invalid arguments for makeCall()" ; // func is a index to the list of library functions. // call() will lookup up this number and return // an 2-dimensional array where each element could be of // three types (integer, float or string). If func is out of // range return an array with rows/cols = 0 const ResultSet& result = call(func, funcval) ; int row = result.getNumberOfLines() ; int col = result.getNumberOfCols() ; int x ; if(row == 0 || col == 0) throw "Empty ResultSet returned" ; rRow = PyTuple_New(row) ; for(x = 0 ; x < row ; x++) { int y ; PyObject * rCol ; rCol = PyTuple_New(col) ; for(y = 0 ; y < col ; y++) { PyObject * item ; if(result[x][y].isNumber()) { double val = (double) result[x][y] ; if(val < intmax && val == (int) val) item = PyInt_FromLong((long) val) ; else item = PyFloat_FromDouble(val) ; ; } else item = PyString_FromString((const char *)result[x][y]) ; if(item) PyTuple_SetItem(rCol, y, item) ; } PyTuple_SetItem(rRow, x, rCol) ; } } catch(const char * err) { strcpy(errMsg, err) ; cerr << "Error: " << err << endl ; rRow = Py_None ; } return rRow ; } static PyObject * getError(PyObject * self, PyObject * args) { return PyString_FromString(errMsg) ; } ------------------------------------------------------------------------- Now for the Python Module File: MyTools.py ------------------------------------------------------------------------- import libPyTAPI def LoadLibrary(libname): return libPyTAPI.makeCall(11, libname) def Insert(token): return libPyTAPI.makeCall(12, token) def Append(token) return libPyTAPI.makeCall(13, token) def Delete(token): return libPyTAPI.makeCall(14, token) def getError(): return libPyTAPI.getError() def Unique(token): return libPyTAPI.makeCall(15, token) def Display(): return libPyTAPI.makeCall(17, "all") def RowInsert(token): return libPyTAPI.makeCall(21, token) def ColInsert(token): return libPyTAPI.makeCall(22, token) def ClearRow(rowno): return libPyTAPI.makeCall(16, rowno) def Clear(): return libPyTAPI.makeCall(16, "all") .... And all the rest 30 more functions ------------------------------------------------------------------------- Now I have Python script which imports "MyTools.py". This script runs and executes as expected. The only problem comes when I execute sys.exit(0) in the script. I believe that somewhere I have to increment or decrement the reference count of the result set, BUT I have no idea where to start? Any pointers?????????????? Tilwe From chrishbarker at home.net Tue Oct 16 14:48:19 2001 From: chrishbarker at home.net (Chris Barker) Date: Tue, 16 Oct 2001 11:48:19 -0700 Subject: fast sub list operations References: <15308.11525.102304.624520@beluga.mojam.com> Message-ID: <3BCC80F3.FCBFBB6B@home.net> Robin Becker wrote: > I know about NumPy and like it a lot, but it's a bit heavyweight for > what we need. NumPy really is what you need. It may be able to do more than you think you need at the moment, but if you start using it, you will probably find that you are using more and more of its functionality every day. And what is the downside??? >From your original post: Robin Becker wrote: > I constantly miss some nice way to subset lists. This is the take() function of Numpy > have a list of x y coordinates eg > > [x0,y0,x1,y1,.....] This is begging to be represented as a NX2 array (or at least a list of tuples...) >>> from Numeric import * >>> coords = [1,2,3,4,5,6,7,8] >>> A = array(coords) >>> A.shape = (4,2) >>> A array([[1, 2], [3, 4], [5, 6], [7, 8]]) > and wish to perform the operation x->x+v, y->y+w for the co-ordinates in > the list I don't seem to be able to do this fast using map. Now you want to do a fast math operation on a sequence of numbers... >>> v,w = 3,4 >>> A = A * (v,w) >>> A array([[ 3, 8], [ 9, 16], [15, 24], [21, 32]]) > had a way to slice the list nicely into > > X=[x0,x1,.....x(n-1)] & Y=[y0,y1,.....,y(n-1)] >>> X,Y = A[:,0],A[:,1] >>> X array([ 3, 9, 15, 21]) >>> Y array([ 8, 16, 24, 32]) I don't seem to have an interlace to get back to the original > list format. >>> list(A.flat) [3, 8, 9, 16, 15, 24, 21, 32] > How can these kinds of operations be performed quickly in current python you got some suggestions, but none of them are nearly as clean or fast as Numeric. > and what if any new features would python require to do them best? An array-oriented math package......Oh! that's what NumPy is!!!!! Why not use the right tool for the job? -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From daves_spam_dodging_account at yahoo.com Tue Oct 23 16:54:24 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Tue, 23 Oct 2001 13:54:24 -0700 (PDT) Subject: Critical sections and mutexes Message-ID: <20011023205424.55377.qmail@web21108.mail.yahoo.com> > -----Original Message----- > From: Skip Montanaro [mailto:skip at pobox.com] > Sent: Tuesday, October 23, 2001 2:04 PM > > Sorry to drop in late on this thread, but why not > simply make > PriorityQueue > a subclass of Queue.Queue (which already does all > the locking for you)? Ooooh. Had I known this existed... *sigh* Well, now that I've written a priority queue, however, I'm thinking it does what I need moderately better. my queue class has a method Put(self, object, Priority=0) that puts the object into one of two internal queues, a priority queue or a normal queue. The reason for this is that it could conceivably take a while (possibly 100ms or more) to process some data packets, and during high traffic times, packets come in pretty thick bursts. During this time, our server may send out a keepalive (ping) packet that must be replied to within 1-5 seconds or so to prevent the connection from being closed by the server. The idea was to have ping messages go into the priority queue, so that even if there are 10s worth of "hard-to-process" packets waiting, the keepalive message is the next one to be processed. However, I have implemented PriorityQueue using a pair of lists internally, and perhaps it would be faster/better to implement them as Queue.Queue objects. One question that still has not been answered: critical sections. Can they be implemented, or can I only lock other threads out of a given resource? P.S. I figured out how to lock a resource in the main thread: main_mutex = threading.Lock() creates a mutex in the main thread, and now anyone can acquire()/release() it as needed. Thanks again, -dB ===== David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From scott_hathaway at riskvision.com Tue Oct 16 15:52:58 2001 From: scott_hathaway at riskvision.com (Scott Hathaway) Date: Tue, 16 Oct 2001 14:52:58 -0500 Subject: wsdl and soap Message-ID: I am using v. 0.9.7 of the soap.py library. How can I auto generate an wsdl file? Is there a utility that does this already? Thanks, Scott From tim at bladerman.com Tue Oct 30 19:44:19 2001 From: tim at bladerman.com (Tim Gahnström /Bladerman) Date: Wed, 31 Oct 2001 00:44:19 GMT Subject: PythonWin 2.1 saving bugg??? Message-ID: Please please please, PythonWin 2.1 have eaten my Python program, does anyone have a suggestion about where to find it? Is there a bug in the saving of files in PythonWin 2.1 ? I have used it for a long time without any troubles. Today it really fucked up though. I were in the testing phase of a program I had made (actually a lab report) . When PythonWin 2.1 for some reason didnt want to save my file again. I tried saving it under a different name but it didnt work either, it just ended up with a text saying saving... in the bottom grey field. I had just done minor changes since last save so I didnt really consider it a big problem. But after (abruptly and with scandisk...) having restarted the computer I came back and found that my program wasn't ther at all! anymore. Just the compiled file. The textfile seemed pretty much deleted :-( Anyone heard about such a problem before or have any suggestion about what to do? It is a problem so ofcourse it should have been submited yesterday... so I really f***king dont look forward to do the whole thing over from start! is there some kind of autosaving or similar? When MS office fucks up it usually starts with a "rescued" version of the endangered dokument. I use w2k is there possibly anyting to do except revriting? Does scandisk store stuf somwhere that it might have found or tried to recover? I have tried to search for files containging textfragments from the file with no luck. Is there a program that serch the harddrive for files that maybe just have lost the pointer to them? Tim Gahnstr?m From comments at cygnus-software.com Mon Oct 29 01:53:53 2001 From: comments at cygnus-software.com (Bruce Dawson) Date: Mon, 29 Oct 2001 06:53:53 GMT Subject: Breakpoints cause enormous slowdown Message-ID: <3BDCFC7C.82EE7D@cygnus-software.com> I've been playing around with PythonWin and a proprietary debugger with a common derivation, and they both have a serious problem. I'm worried that this problem may be fundamental to Python debuggers. If I run this simple program outside of the debugger, or under PythonWin without any breakpoints set, it runs very fast - approximately 0.02 seconds (although the timing is quite inaccurate on my system at this level). If I set a breakpoint on "import time", run under the debugger to the breakpoint, then clear the breakpoint and run it, the performance is identical. However, if I leave the breakpoint in place then the run time goes to approximately 9.3 seconds. In other words, the performance drops by approximately five hundred to one!!! Here's the code: def DoNothing(): maximum = 200 for x in range(maximum): for y in range(maximum): pass import time start = time.time() DoNothing() print "Elapsed is %g.", time.time() - start The code itself is innocuous - you'll get similar results with most Python code, although I assume that some code will be more dramatic. Note that adding a few additional breakpoints does not measurably affect performance. My understanding is that when there is a breakpoint set that the debugger has to run in a single step mode and check a list of breakpoints after each instruction. If that is so then a 500:1 drop in performance is not surprising. Other language/debugger pairs frequently solve this problem with a breakpoint instruction. On the x86 with VisualC++ the instruction used is "int 3". The equivalent for Python would be a breakpoint byte code. If this was added to Python then code could run at full speed and could automatically tell when it got to a breakpoint because the special breakpoint code would be executed. Has this been discussed before? Is this possible? The benefits would be huge. Right now there are some classes of problems that cannot be debugged with a debugger in Python because of the tremendous slowdowns that occur. Thoughts? Bruce Dawson From sholden at holdenweb.com Sat Oct 20 10:20:32 2001 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 20 Oct 2001 10:20:32 -0400 Subject: Recursive functions References: <602c058e.0110191750.6bcd8367@posting.google.com> Message-ID: "Nachiket" wrote in message news:602c058e.0110191750.6bcd8367 at posting.google.com... > I have this code to create a map of webpages. > Can I put it in a recursive function that calls itself a specific > number of times instead of writing multiple loops. > I tried to put it in a method called say handlelinks but when I called > it it gives me a attribute error. the code is as follows Rule 1: When asking for help, ALWAYS include the exact error message. Rule 2: Try to reduce the code to something small that still demonstrates the error. Anyway, be that as it may ... here we go. Note: I haven't subjects the program to any kind of global analysis, just looked through it for stuff that obviously needs fixing. > #!/usr/bin/env python^M Watch out if you try to run this program under Unix: the ^M will mean it can't find your interpreter binary. > import sys > from os.path import walk > from htmllib import HTMLParser > from formatter import NullFormatter > import urllib > > #---read in URL as first argument on command line > try: > inf = urllib.urlopen(sys.argv[1]) > except IndexError: > inf = sys.stdin > #---extracts all the links from html pages > > counter = 3 > class myparser(HTMLParser): > def __init__(self): > HTMLParser.__init__(self,NullFormatter()) > self.linktext = {} > self.lasturl = None > def start_a(self,attr): > for key,val in attr: > if key == 'href': self.lasturl = val > #self.linktext.append(val) > HTMLParser.save_bgn(self) > def end_a(self): > self.linktext[self.lasturl] = HTMLParser.save_end(self) > > p = myparser() > p.feed(inf.read()) > depth = 2 > #----------------------------------------------------------- > print inf > for link in p.linktext.keys(): > if(link[:8] == 'https://'): > print 'Secure Website found...cannot open' > elif(link[:7] == 'http://'): > print link[:20],'-->',(p.linktext[link[:25]]) > temp = urllib.urlopen(link) > depth-1 What's this supposed to do? What it actually does is take the value of depth, subtract one from it and .. nothing. Particularly, it does not modify the value bound to depth. Perhaps you mean depth = depth - 1 or depth -= 1 > if depth == 0: > print 'exit' Also, note that printing "exit" doesn't actually alter the flow of control. Perhaps you actually want to do something that exits here, as well? > p.feed(temp.read()) > for link in p.linktext.keys(): > if(link[:8] == 'https://'): > print 'Secure Website found...cannot open' > elif(link[:7] == 'http://'): > print '','|',link[:25],'-->',p.linktext[link] > temp1 = urllib.urlopen(link) > depth-1 > if depth == 0: > print 'exit' Comments above apply here too. > p.feed(temp1.read()) > else:return 'unknown format' > for link in p.linktext.keys(): > if(link[:8] == 'https://'): > print 'Secure Website found...cannot open' > elif(link[:7] == 'http://'): > print ' ','|','+',link[:25],'-->',p.linktext[link] > temp1 = urllib.urlopen(link) > depth-1 > if depth == 0: > print 'exit' And here, too. > p.feed(temp1.read()) > for link in p.linktext.keys(): > if(link[:8] == 'https://'): > print 'Secure Website found...cannot open' > elif(link[:7] == 'http://'): > print ' ','|','-',link[:25],'-->',p.linktext[link] > temp1 = urllib.urlopen(link) > depth-1 > if depth == 0: > print 'exit' > p.feed(temp1.read()) > elif(link[:8] == 'https://'): > print 'Secure Website' > elif(link[:7] == 'https:/'): > print 'Secure Website found...cannot open' > else:return 'unknow We'll ignore the partial program, for now ... Take a look, if you have it, at the "webchecker" utility in the "tools" directory of your Python distribution. regards Steve -- http://www.holdenweb.com/ From gabriel_ambuehl at buz.ch Mon Oct 8 05:16:16 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Mon, 8 Oct 2001 11:16:16 +0200 Subject: SOAP.py and Python 2.1.1 In-Reply-To: References: Message-ID: <105160741113.20011008111616@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello Andrew, Monday, October 08, 2001, 12:46:22 AM, you wrote: >> This confuses me cause I thought xml should be available from >> stock and I've even got expat-1.2 and expat 1.95 installed so >> what's wrong here? > IIRC, the pyexpat module frequently doesn't get built > automatically, even when expat is installed. You'll need to > manually, build it. Ok, so I installed PyXML-0.6.6 by hand. Now pyexpat is no longer missing, but SOAP.py still doesn't work (not even the card test) cause it complains about unsupported UTF-8 encoding: :1:36: Unsupported encoding 'UTF-8' Am I better off using another SOAP toolkit or XML-RPC? Best regards, Gabriel  -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO8Fg08Za2WpymlDxAQFzagf8CrI4QEZk7Ws5B4v2XJ55TuL4jMzhoVud 2p2yKO1eitLY8fbrManyq5KL4VPfxMjgBzbpjO8ITXAFdL7n6fQv8Nn2smM/MLXw TrfZsTqOqzg5wAarW6g1abMO55WeXMRBXU6+Uky41CCZm71AdBLW4/Tre7pEbSpn OILWBcpDb8ct+NRZJAYP29gGkAtgo6AYnBuvDCToywXri7DdB19nCcDEGICPEVEm rjApbostDViKj4+Hkzv4ocXvLb055Ta6wkT4WW7fWw0ECd71uuQyB40AWyZvjr3P kDL7+mzPb1rHPQabXMY1Wm3swDIoI8+tzB6E0RTeQaF8qdaJ3wkLwg== =SL58 -----END PGP SIGNATURE----- From malcolm at commsecure.com.au Mon Oct 8 09:03:35 2001 From: malcolm at commsecure.com.au (Malcolm Tredinnick) Date: Mon, 8 Oct 2001 21:03:35 +0800 Subject: problem with FFT module from Numeric 20.2.0 In-Reply-To: ; from nde@comp.leeds.ac.uk on Mon, Oct 08, 2001 at 12:05:35PM +0000 References: <9pn4p1$jodve$1@ID-99513.news.dfncis.de> Message-ID: <20011008210335.A10401@Vetinari.home> On Mon, Oct 08, 2001 at 12:05:35PM +0000, Nick Efford wrote: > On Sat, 6 Oct 2001 09:37:36 -0500, > P. Alejandro Lopez-Valencia wrote: > > The solution is to be explicit. Edit your file > > /usr/local/lib/python21/config/Makefile in the appropriate places (3, I > > don't recall their names off-had) to pass -R linker flags to ld. For > > example, I have added this in our lab box: > > > > -R/usr/lib -R/usr/local/lib -R/usr/local/ssl/lib -R/usr/openwin/lib > > > > Without these linker flags modules like socket and pyexpat won't work at > > all if called from restricted execution environments where you don't > > want a full environemnt definition, namely CGI's and batch jobs. > > > > I'm working on Linux; do problems of this nature affect Linux > also, or are they a Solaris-only thing? It's not necessary on Linux -- it's due to differences in the way the Solaris linking process works (for a suitably loose definition of "works" :) ). Cheers, Malcolm -- Eagles may soar, but weasels don't get sucked into jet engines. From loewis at informatik.hu-berlin.de Tue Oct 9 17:22:11 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 09 Oct 2001 23:22:11 +0200 Subject: Why not 3.__class__ ? References: <9pvilt$kepge$1@ID-75083.news.dfncis.de> Message-ID: Markus Jais writes: > it would be more consise. > in Ruby, everything is an object and I can invoke methods on everything > with object.method In Python, everything is an object and you can invoke everything with object . method (this includes the literal 3). Regards, Martin From jpt.d at home.com Thu Oct 25 10:46:17 2001 From: jpt.d at home.com (Jeffrey Drake) Date: Thu, 25 Oct 2001 14:46:17 GMT Subject: wierd win32all gui problem (w/56lines of code) References: <9r8thu$s1k0a$1@ID-59885.news.dfncis.de> Message-ID: It worked great, thank you. For anyone else interested lines changed: InitApplication: modify: global hinst, cAtom modify: cAtom = RegisterClass(wc) modify: if not cAtom: InitInstance: hWnd = CreateWindowEx( win32con.WS_EX_APPWINDOW, cAtom, "Thomas Heller" wrote in message news:9r8thu$s1k0a$1 at ID-59885.news.dfncis.de... > > "Neil Hodgson" wrote in message news:XLRB7.225335$bY5.977767 at news-server.bigpond.net.au... > > Jeffrey Drake: > > > Using ActivePython 2.1 and win32all I have written a simple app that > > creates > > > a window and exits when closed. However the python interpreter is still > > > running. It hangs a command prompt under win2k until I physically kill the > > > python process. I would appreciate any help possible. > > > > The WndProc isn't called at all. Add some prints or message boxes in the > > code and you'll see the WndProc is ignored. > > > > Neil > > > IIRC you have to pass the return value of the RegisterClass() call (which > is an atom) to the CreateWindowEx() function as the second parameter (lpClassName). > > Thomas > > From dfeustel at mindspring.com Sat Oct 6 17:55:06 2001 From: dfeustel at mindspring.com (David Feustel) Date: Sat, 06 Oct 2001 21:55:06 GMT Subject: Octonians in Python References: <7x3d4wpqi0.fsf@ruckus.brouhaha.com> Message-ID: <_4Lv7.36535$My2.18927726@news1.mntp1.il.home.com> Here is John Baez home page: http://math.ucr.edu/home/baez/ Lots of interesting stuff on 'onions here. "Paul Rubin" wrote in message news:7x3d4wpqi0.fsf at ruckus.brouhaha.com... > "David Feustel" writes: > > There is one additional system of complex numbers > > (octonians) beyond quaternions. Are there any > > python implementations of octonians? > > Octonians are also sometimes called octaves. I think they have > applications in some esoteric areas of theoretical physics, but I know > of no applications at all for them in ordinary CS or engineering. > That's probably why there aren't many implementations around. > > Octonian arithmetic is not only noncommutative, but it's also > nonassociative. Here's a nice article abont octonians, by the > always entertaining John Baez: > > http://www.math.niu.edu/~rusin/known-math/97/divialg2 From ullrich at math.okstate.edu Wed Oct 17 13:11:53 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Wed, 17 Oct 2001 17:11:53 GMT Subject: Curious assignment behaviour References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> Message-ID: <3bcdbb39.1987133892@news> On Wed, 17 Oct 2001 15:05:49 +1300, Greg Ewing wrote: >"David C. Ullrich" wrote: >> >> If one argued that >> one would have to explain why "Let 42 = x" doesn't fly. > >Why shouldn't it fly? It's an unconventional way of >putting it, but it means the same thing, mathematically >speaking. I disagree - in a "Let this = that" statement the order of this and that is significant. What if you already have x = 42 and y = 24, and you say "let x = y" ? Does that set x to 24 (yes) or does it set y to 42? >-- >Greg Ewing, Computer Science Dept, University of Canterbury, >Christchurch, New Zealand >To get my email address, please visit my web page: >http://www.cosc.canterbury.ac.nz/~greg From ksatcu at yahoo.com Wed Oct 3 16:08:41 2001 From: ksatcu at yahoo.com (Krish) Date: 3 Oct 2001 13:08:41 -0700 Subject: Socket programming Message-ID: <1854cfa0.0110031208.778d4883@posting.google.com> Is there an online tutorial on UNIX network programming using python? Any help in this regard would be appreciated 'Krish From parker at gol.com Mon Oct 15 03:33:03 2001 From: parker at gol.com (Ian Parker) Date: Mon, 15 Oct 2001 07:33:03 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <7xitdha8tg.fsf@ruckus.brouhaha.com> Message-ID: In article <7xitdha8tg.fsf at ruckus.brouhaha.com>, Paul Rubin writes >"Tim Peters" writes: >> > x = if e1 then (e2) else (e3) >> > and >> > x = (if e1 then (e2) else (e3)) >> > should be equivalent and they preserve clarity. >> >> The latter form would be accepted, but not the former (and the former cannot >> be accepted, which is a question of parser technology, not of taste). > >How did Algol 60 deal with this? to excess, and with a more complicated parser, I imagine: Because statements are expressions in Algo68, the 'if' clause returns a value, and can be used as both a statement and an expression, and either can be squeezed onto one line or spread across multiple lines. But there are two ways of writing the 'if' clause: 'bold' style: if v then w elif x then y else z fi 'brief' style: ( v > | w |: x | y | z) In both cases the elif ('|:') can be repeated as many times as you can face it, and both the elif and else clauses are optional Doesn't help at all does it? However, it does suggest the question: Would this new Python conditional expression support: -- Ian Parker From cfelling at iae.nl Tue Oct 9 15:06:18 2001 From: cfelling at iae.nl (Carel Fellinger) Date: 9 Oct 2001 21:06:18 +0200 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> <7xd73x1cgf.fsf@ruckus.brouhaha.com> Message-ID: <9pvhra$4me$1@animus.fel.iae.nl> Mark wrote: ... > No. If I wrote a module and placed it under the GPL, I still own the > copyright on that module. > That gives me the right to release that code under any other license as I > see fit, even though I can never take away anyone's right to use it under > the GPL. That depends. IIRC, if you get substantial contributions from a particular person that person owns the copyrights for his/her contributions. Small contributions, on the other hand, *probably* don't `leak' copyright, so if you only accept small patches you might be safe, in general you aren't. > IMHO submitting patches to a program does not give you any copyright hold > over that program, although I don't think it's been legally tested yet. Ofcourse you don't get copyright over the full program, but you get to keep the copyright of your own patches, atleast when they are sufficient substantial. -- groetjes, carel From loewis at informatik.hu-berlin.de Wed Oct 17 10:07:02 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 17 Oct 2001 16:07:02 +0200 Subject: wsdl and soap References: Message-ID: Paul Prescod writes: > > I am using v. 0.9.7 of the soap.py library. How can I auto > > generate an wsdl file? Is there a utility that does this already? > I don't know of such a tool for Python yet. I'm sure someone will do one > eventually. Of course, the other direction (WSDL->Python) is already supported in a few packages (e.g. WSDL4Py). Regards, Martin From donn at drizzle.com Tue Oct 2 01:47:38 2001 From: donn at drizzle.com (Donn Cave) Date: Tue, 02 Oct 2001 05:47:38 -0000 Subject: What happened to Python for BeOS? References: <9p2bp8$140c$1@nntp6.u.washington.edu> <93igrtcrsf4oil1if8733o8ie4ggptecum@4ax.com> Message-ID: <1002001658.431460@yabetcha.drizzle.com> Quoth Nomad : ... |> It has been there since April 30. |> |> Version 2.0 is easier to build on BeOS, and the Stackless patches for |> 2.0 work, at least for modest use of continuations. (Microthreads |> crashed the interpreter, for me.) Your choice. |> |> Donn Cave, donn at u.washington.edu | One problem though, the link to the source code didn't work for me, is | the tarball still there? The source URL just pointed to somewhere at http://www.python.org, for the standard source distribution. If the bebits version isn't helpful, I'm sure you can find that source without it. Donn Cave, donn at drizzle.com From martin.franklin at westgeo.com Wed Oct 10 02:44:57 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Wed, 10 Oct 2001 07:44:57 +0100 Subject: Spewing SQL query resultset to HTML table... References: Message-ID: <9q0ql2$1ods$1@mail1.wg.waii.com> Steve, Orr, Steve wrote: > Newbie's first post... New Project... should I use Python or PHP? > > I need to take ANY valid SQL query and display the resultset in HTML. > KEY QUESTION: How do I capture the column aliases and display them as > headers in an HTML table? I have over 100 SQL queries and I just want to > use one simple routine to display results. I don't want reams of hand code > just for output. I've already done this with PHP but I can't find a way to > do it in Python. I'm assuming it's because of my Python newbie status and > not because PHP is more capable. > BY WAY OF EXAMPLE... here's how this was accomplished in PHP: > -------------------------------- > --- > > Not very OO but this will do it:- ## DCOracle is third party python / OCI extension (its free though!) import DCOracle ## get connected user = 'YourOracleUser' password='YourPassword' db='YourConnection(sid)' connection=DCOracle.Connect('%s/%s@%s' %(user, password, db)) cursor=connection.cursor() ## get data cursor.execute("SELECT * from ALL_USERS") columns=cursor.description ## do column headings print "" for col in columns: print "" %col[0] print "" ## do the data data=cursor.fetchall() ## may want to change this if large table for row in data: print "" for col in row: print "" %col print "" print "
%s
%s
" From lac at strakt.com Thu Oct 11 09:52:07 2001 From: lac at strakt.com (Laura Creighton) Date: Thu, 11 Oct 2001 15:52:07 +0200 Subject: Event Problem in Tkinter In-Reply-To: Your message of "Thu, 11 Oct 2001 09:05:44 CDT." References: Message-ID: <200110111352.f9BDq80W006224@ratthing-b246.strakt.com> I tried your program on my debian linux system under KDE, and it worked great. Output follows. One extra Focus-In for I just moved to another window and back. What operating system and what window manager are you using? Laura -------------------------------- lac at ratthing-b246:~/scratch$ python rparnes.py List of Entry Widgets .139090996.135535468 .139090996.139118476 .139090996.139639188 .139090996.139287116 Event: ButtonPress, coordinates: 208, 659; widget: .139090996.135535468 Event: FocusIn, coordinates: 1076223268, 139638232; widget: .139090996.135535468 --------------------------------------------------------------------------- Event: KeyPress, coordinates: 209, 660; widget: .139090996.135535468 Event: FocusIn, coordinates: 1076223268, 139638232; widget: .139090996.139118476 --------------------------------------------------------------------------- Event: FocusIn, coordinates: -1073745224, 0; widget: .139090996.139118476 --------------------------------------------------------------------------- Event: KeyPress, coordinates: 297, 666; widget: .139090996.139118476 Event: FocusIn, coordinates: 1076223268, 139638232; widget: .139090996.139639188 --------------------------------------------------------------------------- Event: KeyPress, coordinates: 297, 666; widget: .139090996.139639188 Event: FocusIn, coordinates: 1076223268, 139638232; widget: .139090996.139287116 --------------------------------------------------------------------------- From jblazi at hotmail.com Sat Oct 6 14:03:28 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Sat, 6 Oct 2001 20:03:28 +0200 Subject: creating a popup menu References: <3bbebe39_5@news.newsgroups.com> Message-ID: <3bbf4772_5@news.newsgroups.com> Sorry for the previous posting. Most unfortunately you cannot "unpost". J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From guignot at wanadoo.fr Wed Oct 10 07:52:10 2001 From: guignot at wanadoo.fr (guignot) Date: Wed, 10 Oct 2001 11:52:10 +0000 Subject: Link between a C variable and a python object Message-ID: <3BC4366A.DC3F6982@wanadoo.fr> Does Python have a nice feature of Tcl, i.e. linking an external C variable and an internal variable, with TclLinkVar ? tks in advance... From huaiyu at gauss.almadan.ibm.com Thu Oct 18 15:59:57 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 18 Oct 2001 19:59:57 +0000 (UTC) Subject: PEP: statements in control structures References: Message-ID: On Thu, 18 Oct 2001 12:42:10 +0300, CpJohnson at edgars.co.za wrote: >Sorry to jump in at this late stage. In the previous example there two two >exits from the loop. >The while statement already defines two exits, a) the controling expression >returns false and, b) the break. >So what's wrong with:- > >x = next() >while not x.is_end: > y = process(x) > if y.is_what_we_are_looking_for(): break > x = next() >else: > raise "not found" Glad you observed the two-exit issue. But 6.5. Repeat action before and after loop: line = file.readline() while line: do_something() line = file.readline() This is a maintenance liability - it is easy to go out of sync. This does not apply to the "if" structure, either. Huaiyu From mwh at python.net Wed Oct 17 07:13:27 2001 From: mwh at python.net (Michael Hudson) Date: Wed, 17 Oct 2001 11:13:27 GMT Subject: FW: [Python-Dev] conditional expressions? References: <23891c90.0110160824.6a5a0c1b@posting.google.com> Message-ID: Paul Moore writes: > Someone psychotic enough to consider writing this sort of thing is > presumably already having a field day with lambda. Heck, someone > could do serious damage to maintainability with nothing more than > the basic operators and some precedence rules... I'm still waiting for the day when I can exploit the fact that 1jor-0land+4 is executable Python. tik-tok-ly y'rs, M. -- MARVIN: Oh dear, I think you'll find reality's on the blink again. -- The Hitch-Hikers Guide to the Galaxy, Episode 12 From phd at phd.pp.ru Thu Oct 25 06:38:08 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 25 Oct 2001 14:38:08 +0400 Subject: Automatically resume a download w/ urllib? In-Reply-To: <1BLB7.15788$CN5.1209011@typhoon.mn.mediaone.net>; from chris_moffitt@yahoo.com on Thu, Oct 25, 2001 at 03:23:41AM +0000 References: <3bd5024a@news.actrix.gen.nz> <3bd680ea@news.actrix.gen.nz> <1BLB7.15788$CN5.1209011@typhoon.mn.mediaone.net> Message-ID: <20011025143808.D13913@phd.pp.ru> On Thu, Oct 25, 2001 at 03:23:41AM +0000, Chris Moffitt wrote: > Too bad I can't use this because the server I'm trying to use this on > uses NTLM authentication, hence Python bombs out on me. Anyone have an > idea how to get around this? http://www.geocities.com/rozmanov/ntlm/ Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phd at phd.pp.ru Thu Oct 11 11:08:22 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 11 Oct 2001 19:08:22 +0400 Subject: New list member... In-Reply-To: <200110111500.AA23084@clt2.picker.com>; from jason.martin@marconi.com on Thu, Oct 11, 2001 at 11:04:03AM -0400 References: <200110111500.AA23084@clt2.picker.com> Message-ID: <20011011190822.B4520@phd.pp.ru> On Thu, Oct 11, 2001 at 11:04:03AM -0400, Jason Martin wrote: > Hello to the list. Hi! > I just wanted to take some time and say hello! I am new to the list, and to You are welcome! > Python. I will probably not be much help for most for now, but with the help of > this list, and all the information I find on the web and from other sources, I hope > to remedy that very shortly. Sure! Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From gh_pythonlist at gmx.de Fri Oct 19 01:01:07 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 19 Oct 2001 07:01:07 +0200 Subject: [OS X] can't connect to db In-Reply-To: <644f6688.0110181359.1b30c398@posting.google.com>; from rdacker@pacbell.net on Thu, Oct 18, 2001 at 02:59:59PM -0700 References: <644f6688.0110180852.11e516f6@posting.google.com> <644f6688.0110181359.1b30c398@posting.google.com> Message-ID: <20011019070107.C571@lilith.hqd-internal> On Thu, Oct 18, 2001 at 02:59:59PM -0700, rdack wrote: > rdacker at pacbell.net (rdack) wrote: > > using pygresql-3.2, postgresql-7.1.3, mac os x 10.1, mac g4. > > doesn't work: > > [...] > i looked closer. misspelled '_pg'. i keep doing that because i was > used to using libpq. > never mind. everything working. If you prefer to use PyGreSQL, I recommend using the version from the PostgreSQL source tree (src/interfaces/python) or even the CVS version. These versions are newer than PyGreSQL 3.2 and contain essential bugfixes (fetchone works now; less leaks). Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From tim.one at home.com Sun Oct 14 15:50:36 2001 From: tim.one at home.com (Tim Peters) Date: Sun, 14 Oct 2001 15:50:36 -0400 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) In-Reply-To: <7xhet39ckb.fsf@ruckus.brouhaha.com> Message-ID: [Tim] > If people sign off on taking "then" as a new keyword, I think > the chances are good that we could get > > x = if e1 then e2 else e3 > > into 2.2b1. That's the only obvious spelling, hence the only > truly Pythonic way to spell it. Other languages spelling it that > way range from Algol-60 (Guido's first intense language affair) to > Haskell. [Paul Rubin, among others of similar mind] > This sounds fine to me. Alas, it didn't to Python's parser -- one-token lookahead isn't enough to distinguish if 1: from if 1 then 2 else 3 let alone if a + b / c: from if a + b / c then 2 else 3 etc. and Python won't grow anything a simple parser can't sort out. Everything's cool if parens are required around a conditional expression, though, in which case: x = if e1 then e2 else e3 + 1 # SyntaxError x = (if e1 then e2 else e3) + 1 # cool x = (if e1 then e2 else e3 + 1) # cool x = if e1 then e2 else e3 # SyntaxError x = (if e1 then e2 else e3) # cool x = if if e1 then e2 else e3 then e4 else e5 # SyntaxError x = (if (if e1 then e2 else e3) then e4 else e5) # cool Seems a mixed bag, but I'm more interested in readability and the functionality than in minimizing keystrokes; requiring parens doesn't hurt the goals I care about. implemented-but-not-checked-in-ly y'rs - tim From jdunnett at uoguelph.ca Mon Oct 29 10:44:56 2001 From: jdunnett at uoguelph.ca (Jeffrey Dunnett) Date: 29 Oct 2001 15:44:56 GMT Subject: python binary search References: <9rht70.3vvdvgd.1@kserver.org> <3BDD4E50.8BA429E9@uoguelph.ca> Message-ID: <9rjtho$ff9$1@testinfo.cs.uoguelph.ca> Jeff Dunnett (jdunnett at uoguelph.ca) wrote: : Sheila King wrote: : > On Mon, 29 Oct 2001 15:38:53 +1100, "Delaney, Timothy" : > wrote in comp.lang.python in article : > : : > : > :I should resist, but I can't. : > : : > :So, what is this "it" that you do? (idoit). : > : > Twenty lashes with a wet noodle for Delaney. That was uncommonly cruel! : > Poor Jeff has already beaten himself up enoug : Thanks for coming to my defence but I really MUST check my spelling beter. : Jeff Alright I will crawl back in the computer lab I came out of and look at an english dictionary since I incorrently spelled better. Jeff From tatebll at aol.com Sat Oct 27 15:12:52 2001 From: tatebll at aol.com (Bill Tate) Date: 27 Oct 2001 12:12:52 -0700 Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> Message-ID: python_only at yahoo.com (Goh S H) wrote in message news:<184fbd02.0110262039.74799675 at posting.google.com>... > No update since 2001-05-14 ... Christian Tismer is probably the best to answer this but I will put my 2 cents in on this. First off - I pray that stackless becomes part of the core distribution of python. Continuations (the core of Stackless) is WORTH THE TIME getting to know in any event. While the concept of continuations is difficult to grasp at first, I struggle with it myself, I would encourage anyone to look at some of the examples Gordon McMillan has put up on his sight. He has working examples and code that drive home some of the fundamentals of continuations and their benefits. Its also an ideal architecture from which to build scalable application servers since continuations are very lightweight as compared to threads and they work extremely well with sockets. There are other benefits to them as well - again check Gordon's site. I would also suggest checking out www.eve-online.com - under the FAQs section - search for stackless and why they are using python and stackless as their gaming engine!!! In every respect, I believe Christian's work advances Python in very meaningful ways in terms of flexibility and performance. It is stable and snap to install. From loewis at informatik.hu-berlin.de Mon Oct 15 10:17:12 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 15 Oct 2001 16:17:12 +0200 Subject: How to handle sys.path in bigger projects? References: <226dstkol613p95ampm7libas5tp6t0a3b@4ax.com> <56jdstkoro0ddkq3eead1fuoe3m20ilikf@4ax.com> Message-ID: Georg Lohrer writes: > So, the only way that seems to work is to start debugging from most > upper directory, if there are intra-package references? Is that > correct? Or how do you handle this? I think this is basically correct. If you want to test the module alone, you should still qualify it with its package name. Regards, Martin From neal at metaslash.com Wed Oct 31 12:06:58 2001 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 31 Oct 2001 12:06:58 -0500 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> <9ro2am$p5b$1@bcarh8ab.ca.nortel.com> Message-ID: <3BE02FB2.5D44DD68@metaslash.com> Peter Wang wrote: > > On Wed, 31 Oct 2001 16:33:08 +1100, "Darren Collins" > wrote: > >If people can see that something is supposed to be private, but they > >absolutely need access to it, then they have just discovered an interface > >problem. They can either fix the interface or put a quick hack in their code > >to to work around it by accessing the 'private' member. But they put in the > >hack knowing that they are breaking the original designer's intentions, so > >they're on their own. It is nice that you can do this when you really need > >to, though. > > my question, all along, was not whether python works well when used > with good development practice. my question was to discover if there > were any "safety nets" that other development teams might have erected > for lapses in process. if there are none, maybe we can think of some. > if there are none because none are possible, then that's a different > issue. > > i've been getting a lot of "there aren't any because you need good > development practices" answers, which seems equivalent to "this car > doesn't have airbags because you should wear your seatbelts". in the > long term this is good because it forces people to wear seatbelts, > but it doesn't answer the question about how we save the ones that > don't. I wrote PyChecker (http://pychecker.sf.net) to help alleviate some of these problems/concerns. It can check for potential bugs, as well as, more stylistic issues (too many lines in a function or return statements). In the future, I intend to add a check for accessing an attribute outside an object. Many checks of this sort can be added. Unit testing is a must, but pychecker can help in code that doesn't get exercised in the tests. Neal From jim at oublic.org Wed Oct 3 16:21:47 2001 From: jim at oublic.org (James Carroll) Date: 3 Oct 2001 13:21:47 -0700 Subject: py2exe and win32com.shell Message-ID: <568cbd32.0110031221.64888972@posting.google.com> I'm trying to create a stand-alone executable that creates shortcuts on the computer. I am using the link.py sample which uses win32com.shell.shell to read and write .lnk files. I'm creating the executable with py2exe (which ROCKS for command line and wxPython applications.) I have tried --force-include --package --include options with all variations of the com library names. When I use a python shell to import ( 'from win32com.shell import shell' ) and type shell, it tells me it is in win32com.shell.shell I cannot import this using --include or --package when I run px2exe. It tells me that the package doesn't exist or it couldn't include the file. During the px2exe I get: warning: py2exe: ************************************************* ********** warning: py2exe: * The following modules were not found: warning: py2exe: * riscosenviron warning: py2exe: * win32dbg warning: py2exe: * win32com.client.NeedUnicodeConversions warning: py2exe: * win32dbg.dbgcon warning: py2exe: * ce warning: py2exe: * win32com.client.Dispatch warning: py2exe: * riscos warning: py2exe: * win32com.shell warning: py2exe: * riscospath warning: py2exe: ************************************************* and when I run my program, I get: c:\jimc\python\dist\link>link Traceback (most recent call last): File "", line 4, in ? File "imputil.pyc", line 127, in _import_hook File "", line 60, in _finish_import File "imputil.pyc", line 305, in _load_tail ImportError: No module named win32com.shell If I try ' --force-inculde win32com ' I get the same result. If I try ' --force-inculde win32com.shell ' or ' --force-inculde win32com.shell.shell ' I get: ImportError: No module named win32com.shell very early in the py2exe process What am I missing???? Thanks, -Jim From max at alcyone.com Wed Oct 31 12:45:25 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 09:45:25 -0800 Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <3BE01E8F.3A384D4C@alcyone.com> Message-ID: <3BE038B5.6AFA6BFB@alcyone.com> Oleg Broytmann wrote: > I am not advocating "open source". I am advocating "free software". > Free > code, with freedom to read it, modify it and distribute in original or > modified form. Yes, you are. "Free software" has more meanings than "open source." Freeware, in particular, has a well-defined meaning, whether you like it or not. You said you didn't want to start another GNU flamewar. But what do you think you're doing? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From joonas at olen.to Fri Oct 26 07:11:21 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: Fri, 26 Oct 2001 11:11:21 GMT Subject: Dynamic assignment References: <9raji3$jpb$01$1@news.t-online.com> Message-ID: <3BD945A9.92E8F1A9@olen.to> Ingo Blank wrote: > > Hi, > > I want to dynamically create variables and assign values to them. > > I tried the following: > > >>> vn = "dynVar" > >>> vv = 1 > >>> eval("%s=%d" % (vn,vv)) > Traceback (most recent call last): > File "", line 1, in ? > File "", line 1 > dynVar=1 > ^ > SyntaxError: invalid syntax > > Q1: Why is the "syntax error" issued ? Assignment isn't an expression. > Q2: *HOW* do I achieve a dynamic assignment ? Use the vars() function to get and set variables. >>> vars()["dynVar"] = 1 >>> dynVar 1 >>> -- Joonas Paalasmaa From phr-n2001d at nightsong.com Tue Oct 9 23:16:23 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 20:16:23 -0700 Subject: Why so few Python jobs? (and licenses) References: Message-ID: <7xwv2418xk.fsf@ruckus.brouhaha.com> Glyph Lefkowitz writes: > I'm an author of [l]GPL software that (unfortunately, I'll admit) > requires copyright consignment, and I think that in any case it's an > statement of goodwill. I don't think any developer I work with would > willingly consign copyright if they didn't trust my vision for the > project and common sense. I'm not sure what you mean about assigning copyright or unfortunateness. If you mean you feel sadly compelled to not accept contributions unless the contributor assigns the copyright to you, ok, that's just common sense--it's the only way you can be sure you can use the changes. The FSF has required assignments from contributors since the very beginning (I've signed a number of them). However, the FSF assignment contract promises the contributor that the program incorporating the contribution will always be distributed for free. I could imagine insisting on a clause like that before signing an assignment to someone else's GPL'd project. > I also don't think you'd submit patches to the GIMP authors if you > thought that the GIMP was dead; consider how much you would've > benefitted from receiving a complete royalty-free paint program that > you *can* write patches for, relative to how much value you would > have been "giving away" to the GIMP developers by resubmitting your > patch. In reality I've used with GIMP a little but never tried to patch it. I've also used the no-extra-cost copy of Photoshop LE that came with my scanner. At least for the simple ways I use such programs (I'm not a graphics whiz), GIMP has no user-visible advantages over Photoshop. I use it because I simply prefer using free programs to using proprietary ones. (Ok, there's also the little matter that GIMP runs under Linux, which is my normal OS, and Photoshop doesn't, but that's fairly minor). Anyway, if I implement a feature for GIMP that's already in Photoshop, I don't get any additional benefits aside from feelgood points, compared to just using Photoshop in the first place. And if I'm working for feelgood points, the issue of how commercial versions make me feel becomes important to the calculation. > I know I wouldn't even *use* Python if I didn't fundamentally trust > Guido's stewardship of it, license or no license. Yes. I started looking at Python after the news releases that it had become GPL-compatible. I'd have never paid attention to it at all if it had stayed incompatible. Python is in the community spirit in that Guido hasn't apparently reserved any rights for himself that are held back from the users. That's a lot better IMO than "GPL for everyone, exceptions available for a fee". I'd have used 100% GPL, but Guido's goals are different from mine, and that's his right. > So, price the labor for that two-line fix that you've made against all > the free fixes that you've gotten for free from other apache-using > folks AND against the fact development of Apache in the first place. > To compare, factor in the cost of maintaining a proprietary web-server > and how much the service people at proprietary-server-company X would > charge you for a two-line fix that you could dist out to your employer > within a single night. I think it still comes out to the fact that > you owe the Apache module group a couple grand :-). I'm aware of that (in fact we trashed our several kilobuck Netscape server to switch to Apache) and aware that a lot of the fixes in Apache came from users. That's why I'd have a bigger problem spending time fixing Apache as a volunteer, if the main beneficiaries of the fixes were companies selling proprietary versions (i.e. I get that couple of grand worth of benefit from using the program while some company gets megabucks of revenue from peddling closed versions of it). In the example I described, I was getting paid (by my employer) to make the fix, so the specific volunteer issue doesn't apply. > Of course, in order to avoid this discussion entirely, you could use a > web platform written in Python (and therefore practically immune to > "malloc errors"), such as Zope, WebWare, or STYLE="ruthless">twisted.web, available at > http://twistedmatrix.com! ;-) These programs are all way too slow for a high-traffic site on the hardware we used back then. Even with today's hardware, it would be marginal. Twisted looks cool though. Maybe I'll play with it. Have you really written SSL in pure Python? I was thinking of doing that. From __tmh at yahoo.com Sat Oct 27 03:04:54 2001 From: __tmh at yahoo.com (Thomas M. Hermann) Date: 27 Oct 2001 00:04:54 -0700 Subject: Import Errors Message-ID: On FreeBSD 4.4 with Python 2.1, modules cannot be imported from a personal site-packages directory. The personal site-packages directory is located at '/usr/home/thomas/lib/python2.1/site-packages'. The environmental variable 'PYTHONPATH' is set to the personal site-packages directory. At the python command prompt, I import sys and type 'sys.path'. The personal site-packages directory is in 'sys.path', but if an attempt is made to import a module from the directory, it fails. To test out the system, I installed the module in ${prefix}/lib/python2.1/site-packages' at which point I was able to install it. I've checked permissions, which are set to '755' or '644' as appropriate. The rub is that there is no reason I should not be able to import the module from a personal site-packages directory. Thanks, Tom H. From wosko at lucent.com Thu Oct 25 08:23:36 2001 From: wosko at lucent.com (Jakub Wosko) Date: Thu, 25 Oct 2001 14:23:36 +0200 Subject: Modules for Python References: <3BD7F263.2F3FAEB6@lucent.com> <3BD7F8E6.120ACE7B@lucent.com> Message-ID: <3BD80448.C3CE8E59@lucent.com> THX, but I meant rather something like Perl modules Spreadsheet::WriteExcel and Spreadsheet::ParseExcel, which make possible to read data from xls files. Thanks in advance: Kuba Oleg Broytmann wrote: > > On Thu, Oct 25, 2001 at 01:35:02PM +0200, Jakub Wosko wrote: > > but what should I use, if I have unix server and want to > > generate HTML document from excel data, using Python as > > CGI scripting language? > > http://www.xlhtml.org/ > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. From phd at phd.pp.ru Wed Oct 24 03:49:01 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 24 Oct 2001 11:49:01 +0400 Subject: file(1) command in Python? In-Reply-To: <01Oct23.134935pdt."3456"@watson.parc.xerox.com>; from janssen@parc.xerox.com on Tue, Oct 23, 2001 at 01:49:28PM -0700 References: <01Oct23.134935pdt."3456"@watson.parc.xerox.com> Message-ID: <20011024114901.B31407@phd.pp.ru> On Tue, Oct 23, 2001 at 01:49:28PM -0700, Bill Janssen wrote: > Has anyone written a module or function for Python which provides the > functionality of the Unix file(1) command? That is, it attempts to > guess the type of a file by looking for distinctive patterns in the > contents of the file, usually driven by a table of "magic" numbers and > strings. Magic on Parnasus: http://www.vex.net/parnassus/apyllo.py/514463245.39015704 Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From max at alcyone.com Wed Oct 31 11:17:14 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 08:17:14 -0800 Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <9rp4d8$830$1@tyfon.itea.ntnu.no> Message-ID: <3BE0240A.A2CCAA83@alcyone.com> Oleg Broytmann wrote: > And, BTW, "free to use" is not free in the sense I prefer. I'd > better > read free code. And free code is the code I can read, modify and > distribute. I hope I do not start yet another GNU flame war. :) "Freeware" has a well-defined meaning that predates open source initiatives. The sense it was used in this case was correct, so complaints about _free_ not being defined the way _you_ prefer it are irrelevant. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From emile at fenx.com Thu Oct 18 14:14:16 2001 From: emile at fenx.com (Emile van Sebille) Date: Thu, 18 Oct 2001 11:14:16 -0700 Subject: Random from Dictionary References: <4f7234de.0110180504.20aa475b@posting.google.com> <9qml3o$ovl8k$1@ID-11957.news.dfncis.de> <181020010938443703%tpayne@mac.com> <9qmoft$p7mln$1@ID-11957.news.dfncis.de> <15311.3858.587746.114216@beluga.mojam.com> Message-ID: <9qn6eb$oiflp$1@ID-11957.news.dfncis.de> Which I did, only I tested with numeric keys which doesn't give this error. Once I put alphas in there, I also see the error, so all around better off selecting from the keys. -- Emile van Sebille emile at fenx.com --------- "Martin von Loewis" wrote in message news:mailman.1003425918.15090.python-list at python.org... > > Perhaps I'm coming in on this thread a bit late (don't remember seeing it > > and can't find it at Google Groups, however, so maybe it just hasn't fully > > propagated around), but I see nothing in the doc string for random.choice > > that suggests it should work with a dictionary. Where's the bug? > > There is no bug; it's just that Emile van Sebille was claiming that > you could use random.choice on a dictionary. > > Regards, > Martin > From loewis at informatik.hu-berlin.de Wed Oct 17 09:52:35 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 17 Oct 2001 15:52:35 +0200 Subject: python2.1 SEGV on Solaris 2.7 References: Message-ID: Anthony Baxter writes: > I've got a Zope installation where python2.1 is segfaulting on > Solaris2.7 - it's running a largish ZEO server. The tail of the > gdb output is: > #128 0x26164 in PyEval_CallObjectWithKeywords () > #129 0x264c0 in PyEval_CallObjectWithKeywords () > #130 0x26140 in PyEval_CallObjectWithKeywords () > #131 0x25fc0 in PyEval_CallObjectWithKeywords () > #132 0x517bc in PyInstance_New () > #133 0x261a4 in PyEval_CallObjectWithKeywords () > #134 0x25fc0 in PyEval_CallObjectWithKeywords () > #135 0x42c90 in initgc () Looks like a stack overflow to me (with 128 stack frames). I somehow doubt that gdb correctly represents the function names, though: PyEval_CallObjectWithKeywords doesn't call itself recursively. Are you sure that: a) you've compiled python with debugging information? b) gdb really sees that python binary that causes the crash? If there is a stack overflow in the gc, you may succeed using Python 2.1.1, or the 2.2 betas: much of the recursion in the gc has been removed (although I thought that already happened in 2.1). If there is a true stack overflow in user code, you may "succeed" in calling sys.setrecursionlimit sometime early, lowering the current value. Instead of a crash, you'd get then a StackOverflow exception. You can also increase your stack size, see ulimit(1) for details. > $ gcc -v > Reading specs from /opt/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs > gcc version 2.95.2 19991024 (release) > which is a bit old. That compiler should work fine; it is likely not the cause of the problem. > Has anyone seen anything like this? I'm going to rebuild with > gcc3.0 and also try turning off GC. I'd advise against using gcc 3 for that. At a minimum, gcc 3.0.1 should be used. Since that still has many bugs (and 3.0.2 will be released shortly), staying with 2.95.x for some time is advisable - atleast to reduce the number of potential causes for the problem. Regards, Martin From mlerner at umich.deleteme.edu Tue Oct 23 13:22:01 2001 From: mlerner at umich.deleteme.edu (Michael Lerner) Date: Tue, 23 Oct 2001 17:22:01 GMT Subject: Speeding up a regular expression References: Message-ID: Oops .. So, I looked at my post and realized that part of it didn't make sense. There has to be _something_ between the numbers, obviously. I looked through the input files again, and it looks like there is either a minus sign, or some number of spaces, or both. But not neither. Anyway, I'd still appreciate some help speeding this up. Thanks, -michael Michael Lerner wrote: > Hi, > I'm a relative newbie to Python, and I'm certainly no regular expression > wizard. I have a text file with a bunch of lines of the form > 1-1.1 2.2 -3.3 4.4 5.5 -6.6 > That is, an integer, followed by six floats, with an arbitrary number of > spaces in between the numbers. Note that that arbitrary number can be > zero, as is the case between the 1 and -1.1 above. > There are also a bunch of other lines in the file. I only want the ones > that are like the line above. > So, here's what I did: > ---- begin my schlocky code ---- > import re > def gimmeWhatIWant(inputString): > myRe = re.compile(r""" > ^ # start at the beginning of the line > (\s*) # our leading spaces > (\d+\s*) # the integer, which may or may not > # have a trailing space! > (-?\d+\.\d+\s*){6,6} # all six floats MAY have spaces > # after them > $ # end at the end of the line > """, re.VERBOSE) > lines = string.split(inputString,"\n") > returnString = "" > for line in lines: > if myRe.match(line): > returnString = returnString + line + "\n" > return returnString > ---- end my schlocky code ---- > The thing is, this is slow when I run it on input strings with 6 or 7 > thousand lines. > Any hints on how I could speed it up? > One thing: I think that replacing the string.split(...) call with > inputString.split("\n") might speed things up a little. But, that's not > where most of the time is spent and I'd like this to work with Python > 1.5.2 if possible. > thanks, > -michael From djmitchell at optushome.com.au Thu Oct 25 03:26:12 2001 From: djmitchell at optushome.com.au (djmitchell) Date: Thu, 25 Oct 2001 17:26:12 +1000 Subject: Submit jobs to a set of PC's (w2k/nt) References: Message-ID: <3bd7be40$0$10007$afc38c87@news.optusnet.com.au> Rather than try to build something using Python, why not use the free cron tool from Cygwin (http://www.cygwin.com)? It's pretty easy to use cron to kick off a process e.g. every 5 minutes. The process could move files around, process data if there's data there to process etc. - everything you've listed below would be pretty trivial to implement using a few cron jobs. Good luck Dave Mitchell Jens Bloch Helmers wrote: > As a python newbie I would apreciate any input on > relevant modules or programs for solving the following task: > > Send an input file to a given directory on machine A. > Start a program on machine A. (Do not wait for exit) > Send an input file to a given directory on machine B. > Start a program on machine B. (Do not wait for exit) > ... > Copy result files from machine A to host machine. > Copy result files from machine B to host machine. > ... > > The machines are running win2k/NT and are connected in > a local TCP/IP network. > > Thanks for any input, > > Jens Helmers From slinkp23 at yahoo.com Sat Oct 13 18:37:56 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Sat, 13 Oct 2001 22:37:56 GMT Subject: Borg Pattern Class usable from other classes? References: <9q69h8$grb$1@serv1.iunet.it> <9q8ve6$hb7$1@lancelot.camelot> Message-ID: On Sat, 13 Oct 2001 10:53:26 +0200, Alex Martelli wrote: >Paul Winkler wrote: > >> On Fri, 12 Oct 2001 10:27:23 +0200, Alex Martelli wrote: >>>Highlander for the DP, and Borg for the non-pattern which I >>>posted and D. Ascher named, seem much more appropriate names, >>>as the connection to science fiction movies/TV series is sharp >>>and pleasingly anti-parallel. >> >> AFAIKT, Borg is the same as Monostate which seems to have been around >> for a couple years: >> >> http://www.ddj.com/articles/1998/9809/9809a/9809as2.htm >> >> At least, the Consequences are identical: >> """ >> * Multiple local instantiations but always with only a single state. >> * Persistent object state in the absence of any instantiations. >> * Familiar syntax. Does not require an accessor function as with >> Singleton objects. >> """ >> >> Borg is an OK name but Monostate is a little more obvious to those of >> us who don't know much about Star Trek (yes, we exist). > >Borg and Monostate (attempt to) solve the same forces. However, they do so >in different languages. *Language-appropriateness* of patterns is often >ignored, even though the Gang of 4 mention it quite well right in Chapter 1, >exemplifying with Visitor, which would be pretty silly in a language with >multiple dispatch. Similarly, "just keep all data static" (which I had >first met, without a catchy name, in the context of C++) is OK for C++ or >Java, but not for Python, where you may want to allow, for example: > theobj.acount += 1 Thanks for the reply. I must admit I'm confused. I haven't read GoF yet; I've just finished a first reading of "Design Patterns Explained". The impression I have (perhaps incorrectly?) is that patterns are relatively language-independent descriptions of recurring solutions (which may not be useful in all languages), and as such, the implementation can be adapted to the idioms of the language in question. So by this understanding, if I wanted to achieve the above-stated *consequences* of Monostate in Python, I'd look at Borg and say "this should do the job". So I see "keep it static" as a language-dependent implementation detail of Monostate. I guess what it boils down to is this: If Python gives us the ability to create a shared-state object whose attributes are easier to set than a C++/Java Monostate, does that mean we have to call the pattern by another name? Does Monostate mandate that attributes must only be modified or set via methods? It didn't say anything like that in the (short) descriptions of Monostate I've found online, therefore I assumed the pattern was neutral on this issue. >> BTW, are there any "gotchas" with Borg/Monostate in a multi-threaded >> context? Singleton requires extra care, leading to the "Double-checked >> Locking" pattern which apparently has been found not to work in >> Java. Any such snags for Borg? I can't think of any, but I've only >> really toyed with threads. > >If two Borg instances are created in separate threads, they still access >the same state-data, so you get the joys of dealing with whatever >synchronization issues. Oh, blarg - I wasn't thinking properly. Of course it's a problem... if Borg().foo < bar: Borg().foo += 1 Result could be unexpected if two threads do this "at once". Still digesting the rest of your reply. Damn, threads are weird. -- PW From m.1.robinson at herts.ac.uk Wed Oct 10 08:35:36 2001 From: m.1.robinson at herts.ac.uk (Mark Robinson) Date: Wed, 10 Oct 2001 13:35:36 +0100 Subject: simple threading (or not as the case may be) References: <3BC32938.3080902@herts.ac.uk> Message-ID: <3BC44098.5020304@herts.ac.uk> Thanks for the advice there It may be that threads aren't the solution anyway. I'll explain in a bit more detail my aim and perhaps someone can help. I am working in jython2.1a3 with java 2 (1.3.0_01) I have created a progressBar to monitor the progress of a potentially time consuming function. I don't really think it belongs in a thread because all following code requires the output of this function. My problem is that when running the progress bar never draws itself or updates. The following test code works fine: if __name__ == '__main__': f = swing.JFrame() p = progress(f, 0, 18) y = 0 while y < 18: if y > 5 and y < 12: p.setLabel('Welcome to the ministry of silly walks') else: p.setLabel('Nee, nee!') for x in range(50000): pass y += 1 p.setProgress(y) p.close() import sys sys.exit() However, in the following context it does sod all: if mode != 'pali': """find all valid L length sites""" pm.setLabel('Generating sequence patterns...') Bsites = motifFinder.genBsites() pm.setProgress(1) """Generate a list of sites in positional order""" posList = getPosList(Bsites) del Bsites pm.setProgress(2) """generate double motifs""" pm.setLabel('Generating duel element motifs...') doubles = motifFinder.genDoubles(posList, pm) if not Motif.duplicates: doubles = trimResults(doubles) pm.setProgress(12) Can anyone help? TIA Blobby From lucio at movilogic.com Thu Oct 25 16:59:31 2001 From: lucio at movilogic.com (Lucio Torre) Date: Thu, 25 Oct 2001 17:59:31 -0300 Subject: Question: Dynamic code import References: <3bd86fb9_5@corp-goliath.newsgroups.com> Message-ID: <3BD87D33.1090704@movilogic.com> K?roly Ladv?nszky wrote: >Hi Bjorn, > >Thanks for your quick answer. Yes, I was mistaken with the global directive. >It's clear now. >Regarding the first question, it works fine with the interpreter but I would >like to read >f11(a) from somewhere else, most likely from a file. > >Cheers, > >K?roly > > you can do this: import f1 import f2 f =f1. f f() f=f2.f f() or mess with the imp module. or, do the tricky thing: ---------------- f2.py def f(): print "f2" ---------------- f2.py ---------------- f.py def f(): print "f1" fun = f fun() file = open("f2.py") text = file.read() exec(text) fun = f2 fun() ---------------- f.py but i think you sohuld stick with import. From mwh at python.net Thu Oct 18 05:36:22 2001 From: mwh at python.net (Michael Hudson) Date: Thu, 18 Oct 2001 09:36:22 GMT Subject: Termcap/terminfo for Python? References: <20011017150338.A4991@mems-exchange.org> <20011017233128.E20564@phd.pp.ru> Message-ID: Greg Ward writes: > On 17 October 2001, Oleg Broytmann said: > > curses.tigetflag > > curses.tigetnum > > curses.tigetstr > > Ahh, thank you. > > > I don't know which attributes describe width/height of a terminal. > > For the record: > curses.tigetnum("cols") > curses.tigetnum("lines") > Here's what I do: def getheightwidth(): """ getwidth() -> (int, int) Return the height and width of the console in characters """ try: return int(os.environ["LINES"]), int(os.environ["COLUMNS"]) except KeyError: height, width = struct.unpack( "hhhh", ioctl(0, TIOCGWINSZ ,"\000"*8))[0:2] if not height: return 25, 80 return height, width Where TIOCGWINSZ lives is an interesting game across Python versions. It's in termios now. I should probably look at terminfo too, but that would be the last check. I think ncurses' own order of checking goes: env vars ioctl terminfo 25x80 but I haven't looked at this for a while. HTH, M. -- 48. The best book on programming for the layman is "Alice in Wonderland"; but that's because it's the best book on anything for the layman. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From average_expires08dec2001_1w3tq5 at safeadd.net Mon Oct 8 15:29:07 2001 From: average_expires08dec2001_1w3tq5 at safeadd.net (average_expires08dec2001_1w3tq5 at safeadd.net) Date: Mon, 8 Oct 2001 14:29:07 -0500 (EST) Subject: type(self) not preserved on some builtin methods when subclassing. Message-ID: <35677.18.187.0.27.1002569347.squirrel@safeadd.net> The following was categorized as "not-a-bug" on the Python sourceforge site (468887). Instead of bugging the developers further, I thought maybe folks here could help me further understand the rationale of the following behavior and provide useful alternatives: ************ > Python-2.2a4 > > For user-defined types derived from built-in types, it > appears that built-in methods which return copies are > not preserving the type of self. > > >>> class Test(list): pass > >>> t=Test() > >>> map(type, [t, t[:], t+t]) > [, , ] > >>> t += t > >>> type(t) > > > Same with types int, dictionary, etc. ************ And response: [tim_one] > This is deliberate. If, e.g., you don't override the > slicing operator in Test, then t[:] is handled by the base > class's slicing operator. The base class can't know what > invariants Test needs to preserve, so does the best it can > by constructing a list. If you want operators that return > Test instances instead, you have to supply them. > > Note that base-class operators *sometimes* returned > instances of subclasses in earlier 2.2 alphas, but > unpredictably (depending on internal optimizations). This > was properly reported as a bug, and was fixed for 2.2a4; > see bug 460020 for details. *********** The bug report mentioned (460020) does provide some good discussion, and it appears that considerable work went into creating this behavior. >From what I understand, without this behavior Python would have to require the subclass' constructor to be able to initialize with the same parameter list as the base class in order for the base class method to be able to create a new object of the subtype. If I remember correctly, this is what C++ requires; that is, a default constructor which doesn't require any arguments. In any case, it would seem that if a user wants to extend a built-in class, he/she will either have to: 1) rewrite (in the subclass) all built-in methods which might return copies, 2) re-copy the return result of the built-in method back into self's original type, or 3) re-assign to the __class__ attribute of the return result (isn't this deprecated however?). 4) some alternative that hopefully is just escaping me... Note that if UserList is used as the base class instead of list, things work as (I) expected. That is, for methods which return copies, the base class creates a new object using "result = self.__class__(data)" instead of hardcoding the copy type ("result = UserList(data)"). Any comments or further alternative ideas to avoid options 1-3? Thanks, Mark From sasoft at gmx.de Tue Oct 30 13:35:28 2001 From: sasoft at gmx.de (Stefan Antoni) Date: Tue, 30 Oct 2001 13:35:28 -0500 Subject: Send an email . In-Reply-To: <007901c16133$0835e260$a197003e@rashome>; from weismann@netvision.net.il on Tue, Oct 30, 2001 at 01:07:12PM +0200 References: <007901c16133$0835e260$a197003e@rashome> Message-ID: <20011030133528.A4131@cruciatuz.de> On Tue, Oct 30, 2001 at 01:07:12PM +0200, Amit Weisman wrote: > > What module should I use to send an email ? > Thanks smtplib -- Stefan Antoni From slinkp23 at yahoo.com Tue Oct 16 13:23:27 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Tue, 16 Oct 2001 17:23:27 GMT Subject: newbie printing question References: <9qg0l9$5hp$1@slb3.atl.mindspring.net> <9qgoed$1l60$1@mail1.wg.waii.com> <9qhdpm$ibl$1@slb7.atl.mindspring.net> Message-ID: On Tue, 16 Oct 2001 08:29:30 -0500, adina_levin at mindspring.com wrote: >this is the catch: > >TimeNow=mxDateTime.now() > >TimeNow is a DateTime object, not a string. >>> date = mx.DateTime.now().strftime('%d-%m-%y') >>> date '16-10-01' Or you could use the attributes of a DateTime object. They're integers, though. >>> now = mx.DateTime.now() >>> date = '-'.join([`now.day`, `now.month`, `now.year`]) >>> date '16-10-2001' HTH, PW From dale at riverhall.NOSPAMco.uk Thu Oct 11 05:55:41 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Thu, 11 Oct 2001 10:55:41 +0100 Subject: assignment in control structure syntax (was Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC3FCFC.21AF174@letterror.com> Message-ID: Chris Dutton wrote: >in article slrn9s9h7p.1jk.huaiyu at gauss.almadan.ibm.com, Huaiyu Zhu at >huaiyu at gauss.almadan.ibm.com wrote on 10/10/01 6:00 PM: > >> There are several other uses for this syntax. For example, >> >> if val = dict1[key1]; val: >> process1(val) >> elif val = dict2[key2]; val: >> process2(val) >> elif mylist += otherlist; len(mylist) > 4: >> process3(mylist) > >The example I saw somewhere that I liked was > >if something as x: > do_something_to(x) Presumably, 'something as x' assigns to x and yields x? It doesn't seem at all obvious to me. I had to think about it for a while before figuring it out. Also, having an assignment working to the right is very counter-intuitive. -- Dale Strickland-Clark Riverhall Systems Ltd From phr-n2001d at nightsong.com Wed Oct 31 19:21:33 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 31 Oct 2001 16:21:33 -0800 Subject: accessing a web search engine References: <9rq340$1hfc@r02n01.cac.psu.edu> Message-ID: <7xhesfs5ma.fsf@ruckus.brouhaha.com> Rajarshi Guha writes: > Hi, > I'm trying to use Python to send queries to a webpage and analyse the > results. However the search engine does'nt use cgi scripts - it uses a > Javascript function. How can I access a JScript function. I realize that > this is not really a Python question, but since I am using it I thought I'd > ask here. I know that I have to use the urllib module but what string do I > send to the server? You have to analyze the javascript on the web page and figure out what it's really doing when you click the search button. Sooner or later it probably does a form.submit() call. Find the target attribute for that form and navigate your client there with the appropriate query or POST arguments. If the page is doing a nontrivial javascript computation before submitting, you'll have to do a similar calculation in your python client. From geert at cs.uu.nl Wed Oct 31 08:35:35 2001 From: geert at cs.uu.nl (Geert-Jan Giezeman) Date: 31 Oct 2001 13:35:35 GMT Subject: Python.NET, MONO and Visual Studio etc. References: Message-ID: <9roun7$gaj$1@samos.cs.uu.nl> In Xavier Defrang writes: >This is almost off-topic but since you guys are talking about that .NET >thing, I'd like just to ask anyone in here : WHAT THE HELL IS .NET??? > >I don't want any fancy buzzwords or corpspeak crap. I just want a clear, >step-by-step explanation of what it is and what should I believe it's the >revolution MS claim it is. > >Any explanation of link to valuable online resource are more than >welcome... I liked the explanation of Bertrand Meyer at http://www.eiffel.com/doc/manuals/technology/bmarticles/sd/dotnet.html From s.keim at laposte.net Tue Oct 23 04:06:13 2001 From: s.keim at laposte.net (sebastien) Date: 23 Oct 2001 01:06:13 -0700 Subject: Few questions about new features in Python 2.2 Message-ID: <7da8d8f8.0110230006.36933486@posting.google.com> I've tryed Python2.2b1 this week-end. I would thanks Python contributors, theses guys have done an impressive job. I know Python since 1.52 release. With 1.6, 2.0 and 2.1 except for pydoc and nested scopes my felling was something like "yes that's great but I have been able to live without before". But I'm asking myself how I have been able to live without: - iterators and generators - class and type unification - properties - new division (even if some desagree with me ;-) ) I think that all of this is not only new features but really an improvement (maybe in the direction of orthogonality) in the fundations of the Python language. But there are little things that seems strange for me: Why iterators can't be copied? ----------------------------- Something like: MyIter = iter([1,2,3,4]) MyIter2 = iter(MyIter) doesn't provide a copy but a reference to the iterator And that: import copy MyIter2 = copy.copy(MyIter) Just doesn't work But you can have the need to save an iterator position when you want to try something and retry other thing if the first attempt fail. For sample I think Tim recipe for removing duplicate would need copy to work with iterator. How to overload builtins constructor? ------------------------------------- I have tried something like: class xxx (int): def __init__(self, x, y): int.__init__ (self, x*y) That doesn't seem to work. What is the goal for __floordiv__ ? ----------------------------------- I doesn't understand why to have appended this special method. For me with or without from __future__ import division, the new // operator could call the old __div__ method. Or there is a pitfall that I haven't seen? Thanks From hanche at math.ntnu.no Fri Oct 12 18:05:04 2001 From: hanche at math.ntnu.no (Harald Hanche-Olsen) Date: 13 Oct 2001 00:05:04 +0200 Subject: signum() not in math? References: <3BC6B774.4688E9A2@darwin.in-berlin.de> <3BC6D71E.D701A15@darwin.in-berlin.de> Message-ID: + Dinu Gherman : | no worries, there doesn't | seem to be any such difference between -0 and +0 in Python: | | PythonWin 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on | win32. | >>> -0 < +0 | 0 | >>> -0 > +0 | 0 | >>> -0 == +0 | 1 | >>> -0. == +0. | 1 | >>> -0. < +0. | 0 | >>> -0. < +0 | 0 Wrong tests. In fact, it is quite difficult to see the difference between the two zeros, but on the Intel architecture, they are different indeed: >>> import math >>> math.atan2(0.,-1.) 3.1415926535897931 >>> math.atan2(-0.,-1.) -3.1415926535897931 -- * Harald Hanche-Olsen - Yes it works in practice - but does it work in theory? From tdelaney at avaya.com Tue Oct 16 20:20:16 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 17 Oct 2001 10:20:16 +1000 Subject: How To compile Python without any module. Message-ID: > From: dag4004 [mailto:dag4004 at caramail.com] > > I want to build a Python interrpreter without any module build in, > because i havn't enought RAM space. > How must i do? If you don't have enough RAM for modules, you won't have enough for Python. Modules and Python are inextricably linked. I think you need to explain your requirements a bit better. Tim Delaney From tmoero at yahoo.invalid Fri Oct 12 05:53:27 2001 From: tmoero at yahoo.invalid (tm) Date: Fri, 12 Oct 2001 18:53:27 +0900 Subject: YOU ARE ALL GAY! References: Message-ID: Geoffrey Pointer wrote: > tm said: > > > Much better geof, you left the attributes this time. Shows you are > > capable of learning. You could use some help with snipping, but keep up > > the good work. > > Read the whole message that you are commenting on here. Which one? The one where you fucked up the attributes, or the one where you strung a bunch of messages together? > My original comment > was a one off, off hand comment, meant to be just light hearted in the > spirit of the original message. Oh, the one where you fucked up the attributes and didn't snip pages of useless shit. Thanks for the clarification. > Just like at least two of the other replies > which I read in context with the original post. The only reason I clipped > the entire original message (something I normally NEVER do) is because Nigel > said he hadn't seen the original message. Ah, so 'nigel' was the attribute you snipped? > They say you can lead a horse to water but you can't make it drink. Well, > this little black horse has been to the water of his own volition has drunk > the water heartily and moved on. You on the other hand it seems would have > me drown. heh. Whatever. > > Say, would you like to learn how to make a proper sig delimiter? > > Proper?? There is obviously no accounting for taste, its only text for > crying out loud. > > -- > > Cheers - Geoff %^> > Good try. Still not right. You need a space after the dashes. HTH, TM From peter at engcorp.com Sun Oct 28 08:00:28 2001 From: peter at engcorp.com (Peter Hansen) Date: Sun, 28 Oct 2001 08:00:28 -0500 Subject: interpreter crashes References: <7xzo6cd1hw.fsf_-_@ruckus.brouhaha.com> <3BDB8F30.FEE9004C@engcorp.com> <7xd738qr2f.fsf@ruckus.brouhaha.com> Message-ID: <3BDC016C.7E45106@engcorp.com> Paul Rubin wrote: > > Peter Hansen writes: > > Python can run indefinitely unless you have hit some obscure bug. > > This is encouraging to hear. However, obscure bugs do exist. I may > be hitting a bug in some extension module or in something having to do > with module reloading. All crashes I've ever seen were with other libraries, or when I was trying to wrap a DLL with calldll under Windows. Never seen a crash yet under Linux. Python is _solid_. > > We are also developing applications based on Python which will > > be expected to run potentially for years without being shut down ... > > and I have no concerns about this (at least none related to Python! ;-). > > This is my concern--if they're EXPECTED to run for years without > shutdown, but they crash unexpectedly instead, that can be a big > problem. Best is to not have them crash, but next-best is to plan > ahead for occasional crashes. So I'm wondering what I need to do. Run a separate task which checks the status of the Python app from time to time (maybe with cron?). Kill and restart as necessary. > Note that if you're planning to run a server for years without > attention, besides UPS's you'll also want to have some kind of > hardware watchdog timer on the hosting computer--another form of crash > tolerance. Thanks for the advice :-). It's an embedded PC104 module with a hardware watchdog timer (they mostly all have them) and a stripped Linux platform, and the decision to use a UPS or not is the customer's, not ours. :-) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From jpt.d at home.com Sun Oct 28 17:28:53 2001 From: jpt.d at home.com (Jeffrey Drake) Date: Sun, 28 Oct 2001 22:28:53 GMT Subject: Python.NET, MONO and Visual Studio etc. References: <3BDC5777.3873D22A@earthlink.net> Message-ID: Just wanted to make sure you know the difference between Visual Python and Python.Net. Visual Python is regular python in vs.net ide, and Python.net is actual CLR. "Ron Stephens" wrote in message news:3BDC5777.3873D22A at earthlink.net... > A while back there was a discussion here about a possible Python.Net and > related matters. I would still like to know if there is any recent > information. Below is my perhaps faulty understanding of what's going > on. I hope maybe others can correct and add to my comments. > > ActiveState has a version of Visual Studio for Python that will be > commercially available soon, and this is pretty much a sure thing. > Visual Studio for Python can allow a Python programmer to use the same > VS IDE and programming environment that VB.NET and C#.NET programmers > can use. VS.NET should be officially released real soon, I suppose VS > for Python will follow very shortly after that. Note that this is "just" > an IDE and programming tool-environment, and will not allow Python to > use the CLI or VS. NET compiler. > > ActiveState also developed a beta version of a Python.NET that would > allow Python to use the CLI and VS. NET compiler. This effort was led by > Mark Hammond. However, the task is difficult and the first beta was slow > and very feature incomplete. I believe the Perl.Net version is further > along? I do not know if any further development work is on-going or even > planned on Python.NET. I hope so, but I sensed a lot of doubt in the > earlier thread on this newsgroup about the viablity of any Python.NET.. > > And then there is Mono, the open source .NET clone led by Miguel de > Icaza (sp?) and its home page can be found at http://www.go-mono.com/ > They seem to be making real fast progress on Mono, judging by the info > on their web site that I follow. > > Can a MONO.NET be created as easily or, hopefully, even easier , than a > MS Python.NET? Is anyone thinking of creating a Mono.NET? > > I think that both a MS Python.NET and an open source Mono.NET would be > very good things for the Python community; offering yet more options for > distributing Python programs and also giving access to yet more > programming tools and environments. Also it would help spread the > popularity of Python. > > I know that these are big projects but I wonder if anyone knows if > anyone is doing or planning anything along these lines? > > If Python were supported by Jython, MS.NET, Mono, all in addition to the > great PC, Linux, UNIX, and Mac implementations we already have, it would > sure put Python in a strong position. Also, if Python does not take > advantage of this route, others will. The Ruby newsgroup has had a lot > of such discussion about a Ruby.NET (as well as a Java-Ruby version); > and I sense that Perl.Net may be Microsoft's and ActiveStates' first > priorities for scripting languages for .Net. > > By the way, I recall Alex Martelli was involved in the previous > discussion of this topic. He is always one of my favorite posters, I > always learn something when I read his posts, no matter what the topic. > I have missed him lately. Does anyone know if he will be back???? Or am > I just missing his posts? Alex, please come back....:-)))))) > > Ron Stephens > > > From wberger at ccil.org Fri Oct 12 07:53:48 2001 From: wberger at ccil.org (William Wonneberger) Date: Fri, 12 Oct 2001 11:53:48 GMT Subject: Problems With ColourSelect Box Inside A wxDialog References: <9e7d101d.0110081223.32a8217e@posting.google.com> <7hm8st4ul1p0i93r8ut2bpmetm8k7p7q6s@4ax.com> Message-ID: <0vkdstggl369a57u82inrlvpgolp1dd47m@4ax.com> Hi, Robert; Again, thank you very much for your time and help. I really appreciate it. >First of all, you're still not instantiating the ColourSelect control >correctly. It should be: > > ColourSelect(self, -1, [0, 0,110], wxPoint(200, 46), wxSize(55, 20)) > >*not* > > ColourSelect(self, wxPoint(200, 46), [0, 0,110], wxSize(55, 20)) > The second instantiation does work, as I'm using the updated ColourSelect control posted by Lorne White. For the updated colourselect.py, which also fixes some problems with callbacks, take a look at http://www.telusplanet.net/public/lwhite1/pymodules/lib/colourselect.py (The constructor for this one was different compared to the one with the build for wxPython 2.3.1 for Python 2.1). I have since updated to get the latest version of colourselect.py which included a fix for the memory leaks as posted by Robin Dunn (http://cvs.wxwindows.org/cgi-bin/viewcvs.cgi/wxPython/wxPython/lib/colourselect.py#rev1.8). As you rightfully pointed out, going back to the CVS version with the fixes for the memory leaks did require the change to the ColourSelect() constructor as you described. (A question on the side, and this may be one for Lorne White, how and or why was there a difference between the two constructors? Obviously, this is not as important, since what I have now with the updated ColourSelect Python module works). >The second problem is that *both* ColourSelect controls are bound to >self.colorselect, and that might conceivably cause some trouble with >keeping wxPython shadow objects properly synchronized with their >internal wxWindows counterparts. > Thanks for pointing this out. I left them the same just to make sure I could get the dialog to come up and display correctly. I have since changed them to have different attribute names. >Having said that, when I try running your dialog code (after fixing the >ColourSelect instantiation) I get no memory leaks, so the problem might >be elsewhere. Do you keep any references to those controls anywhere >except in your dialog-class? > No, all of the controls in the dialog are solely within the dialog class. And again, I'm using the updated colourselect.py module that Robin posted earlier. >While I'm at it: there are some minor issues left: for some reason, >overriding OnOK doesn't work, it obviously isn't being shadowed in >wxPython. If you're not trying to override that method you'd better not >use that name, because it might be added in a next version of >wxPython.[*] As it is, just having buttons with wxID_OK and wxID_CANCEL >in your dialog is sufficient. > >Also, your event handlers will never be called, because the IDs of the >controls and the EVT_* 'macros' do not match. Personally, I try to >avoid setting explicit IDs as much as possible, and just use -1 in the >constructor. When I need that ID when setting up an event handler, I >use the GetId method. > Thanks for pointing this out. The OnOK event handler has been removed. So, to follow-up, here's where I'm at; The dialog works and the ColourSelect controls now work and display correctly. Using the updated colourselect.py module as posted in the CVS tree by Robin fixes the memory leak. The source for my updated dialog box is now as follows; class wxPlotterSettingsDialog(wxDialog): def __init__(self, parent): wxDialog.__init__(self, parent, -1, "wxPlotter Settings", wxDefaultPosition, wxSize(350, 200)) self.static = wxStaticText(self, -1, "Number of points to draw: ", wxPoint(70, 22)) self.linesSpin = wxSpinCtrl(self, 20, "", wxPoint(200, 20), wxSize(55, 20)) self.linesSpin.SetRange(1, 360) self.linesSpin.SetValue(parent.lineCount) self.static = wxStaticText(self, -1, "Line Color: ", wxPoint(70, 50)) self.linecolorselect = ColourSelect(self, -1, parent.lineColor, wxPoint(200, 46), wxSize(55, 20)) self.static = wxStaticText(self, -1, "Background Color: ", wxPoint(70, 75)) self.backgroundcolorselect = ColourSelect(self, -1, parent.backgroundColor, wxPoint(200, 73), wxSize(55, 20)) self.static = wxStaticText(self, -1, "Line Ending: ", wxPoint(70, 102)) self.lineEnding1 = wxRadioButton(self, 25, "Rectangle", (140, 100)) self.lineEnding2 = wxRadioButton(self, 26, "Circle", (215, 100)) self.lineEnding3 = wxRadioButton(self, 27, "None", (270, 100)) self.button = wxButton(self, wxID_OK, " OK ", wxPoint(95, 140), wxDefaultSize).SetDefault() self.button = wxButton(self, wxID_CANCEL, " Cancel ", wxPoint(175, 140), wxDefaultSize) def GetLines(self): return self.linesSpin.GetValue() def GetLineColor(self): return self.linecolorselect.GetColour() def GetBackgroundColor(self): return self.backgroundcolorselect.GetColour() def GetLineEnding(self): print "lineEnding1 = ", self.lineEnding1.GetValue() print "lineEnding2 = ", self.lineEnding2.GetValue() print "lineEnding3 = ", self.lineEnding3.GetValue() return 0 Again, thank you very, very much for your time, help, and patience, and also to Lorne and Robin for their help as well. Best Regards... Bill Wonneberger wberger at ccil.org From nas at python.ca Sun Oct 21 14:46:51 2001 From: nas at python.ca (Neil Schemenauer) Date: Sun, 21 Oct 2001 11:46:51 -0700 Subject: comparative performance benchmark Python 1.5.2 - 2.0 - 2.1 In-Reply-To: ; from frederic.giacometti@arakne.com on Sun, Oct 21, 2001 at 06:06:38PM +0000 References: Message-ID: <20011021114651.A782@glacier.arctrix.com> Frederic Giacometti wrote: > As result, I'm getting in the situation where I'm being asked to retroceed > all our developments from Python 2.1 to Python 1.5.2. > Any help for getting me out of this trap ? Benchmarking is hard: spud ~$ python1.5 pystone.py Pystone(1.1) time for 10000 passes = 1.33224 This machine benchmarks at 7506.16 pystones/second spud ~$ python2.0 pystone.py Pystone(1.1) time for 10000 passes = 1.38104 This machine benchmarks at 7240.92 pystones/second spud ~$ python2.1 pystone.py Pystone(1.1) time for 10000 passes = 1.04334 This machine benchmarks at 9584.57 pystones/second spud ~$ python2.2 pystone.py Pystone(1.1) time for 10000 passes = 0.975024 This machine benchmarks at 10256.2 pystones/second Are you sure you're using the same options to compile all versions of the interpreter? Python 1.5.2 had threading disabled by default. That makes a significant difference. If you're on a x86 machine with GCC try compiling 2.x with "-O2 -m486". When you disabled GC did you do it using configure or with gc.disable()? What is your benchmark? Neil From vulpine at dontspam.earthling.net Wed Oct 3 14:08:05 2001 From: vulpine at dontspam.earthling.net (Tod Fox) Date: Wed, 03 Oct 2001 18:08:05 GMT Subject: Past command buffer gone in interpreter? References: Message-ID: <9uIu7.590021$NK1.53791925@bin3.nnrp.aus1.giganews.com> Ignacio Vazquez-Abrams wrote: > On Wed, 3 Oct 2001, Tod Fox wrote: > Did you install from RPM, SRPM, or tarball, and if RPM or SRPM, where did you > get it from? I compiled it from a tarball. Someone else has suggested I didn't compile it with 'readline' turned on. I will look into this... Kit From dale at riverhall.NOTHANKS.co.uk Mon Oct 29 09:50:26 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 29 Oct 2001 14:50:26 +0000 Subject: setting the clipboard References: <3bdd553c$1@207.229.64.20> Message-ID: <44rqttchjigpj1rkd4qvljr4bn5atmc75n@4ax.com> "Peter Bismuti" wrote: >How can you set the clipboard from within Python? I was told that it can be >done. > >Thanks! > This puts the text in 'spam' on the clipboard: import win32clipboard win32clipboard.OpenClipboard(0) win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(spam) win32clipboard.CloseClipboard() -- Dale Strickland-Clark Riverhall Systems Ltd From rwgk at yahoo.com Wed Oct 24 14:02:55 2001 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: 24 Oct 2001 11:02:55 -0700 Subject: defaultdict -> standard library? Message-ID: <8be7693c.0110241002.26322e1b@posting.google.com> The tutorial at http://www.python.org/2.2/descrintro.html includes a class "defaultdict." It would be incredibly useful if this could be included in the standard library that ships with Python. Are there any plans in this direction? Thanks! Ralf From kenney at netacc.net Wed Oct 10 11:41:59 2001 From: kenney at netacc.net (J. Kenney) Date: 10 Oct 2001 08:41:59 -0700 Subject: Quick GUI Questions - Seeking Advice Message-ID: <9742a725.0110100741.6d7f625@posting.google.com> I have a really quick concern, that is which gui toolkit, (wxPython, TK, etc) to do some simple graphics works. I have been programming in python for many years but have never really gotton into graphics (other than with the web). All I need to do is, create a windows program where the screen has 3 parts, the first is a large window where I can move the mouse over the window knowing where it is at, track mouse clicks, and draw. while the other two are just for data entry/output. I just dont know how to create a window that I can draw in and take mouseclick/position information. Somewhat like a paint program, but I want to have the program ask questions in the other windows after a mouseclick, and I really dont plan on having the user be able to draw anything. Any suggestions, pointers, or locations of software would be very helpful. Thanks in advance, J. Kenney I possible please reply to kenney at netacc.net as well as the newsgroup. From fredrik at pythonware.com Wed Oct 31 14:49:28 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Oct 2001 19:49:28 GMT Subject: file operations References: Message-ID: "Kerstin" wrote: > I think I managed most of my problems. It's not the best way I > suppose, but it's working. I open the file in r-mode when I need to > read it, close it, and open it again in w-mode to write it if you're changing the size of the file, it's the usual way to do it. (especially if it's a text file, or any other file format that wasn't designed to be modified in place) most normal operating systems won't allow you to insert or delete stuff inside a file. > I tried the w+-mode, but it wasn't working properly for me. "didn't work properly" as in "removed everything in my file"? that's the expected behaviour, as mentioned in the library reference: Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' truncates the file). Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files (else it is ignored). if you don't need to insert or delete bytes from the file, "r+" could work. From aaron at metrony.com Wed Oct 10 16:54:56 2001 From: aaron at metrony.com (news.optonline.net) Date: Wed, 10 Oct 2001 20:54:56 GMT Subject: Quick GUI Questions - Seeking Advice References: <9742a725.0110100741.6d7f625@posting.google.com> Message-ID: Take a look at http://www.openrpg.com/ It is a TCP chat/meeting/whiteboard application for Role playing games. It is written in Python and wxWindows. There is a map module that lets users click the mouse and move icons around, this movement is sync'd across all the clients -Aaron "J. Kenney" wrote in message news:9742a725.0110100741.6d7f625 at posting.google.com... > I have a really quick concern, that is which gui toolkit, (wxPython, > TK, etc) to do some simple graphics works. I have been programming in > python for many years but have never really gotton into graphics > (other than with the web). > > All I need to do is, create a windows program where the screen has 3 > parts, > the first is a large window where I can move the mouse over the window > knowing where it is at, track mouse clicks, and draw. while the other > two are just for data entry/output. > > I just dont know how to create a window that I can draw in and take > mouseclick/position information. Somewhat like a paint program, but I > want to have the program ask questions in the other windows after a > mouseclick, and I really dont plan on having the user be able to draw > anything. > > Any suggestions, pointers, or locations of software would be very > helpful. > > Thanks in advance, > > J. Kenney > I possible please reply to kenney at netacc.net as well as the newsgroup. From mjais at web.de Mon Oct 8 05:19:37 2001 From: mjais at web.de (Markus Jais) Date: Mon, 08 Oct 2001 11:19:37 +0200 Subject: xslt and python - which module?? Message-ID: hello I found on the web that there are some options for python and xslt for example a wrapper around Xalan. can anybody give me a hint which xslt implementation would be best I do not need speed, so it has not to be a C/C++ implementation with a python wrapper. in fact, a pure python implementation would have the advantage that I can read the source. (I can also read C source, but I hate reading C source!) thanks in advance for any answers regards markus From bobhicks at nospam.adelphia.net Wed Oct 3 16:26:15 2001 From: bobhicks at nospam.adelphia.net (Robert Hicks) Date: Wed, 03 Oct 2001 20:26:15 GMT Subject: ZODB on OSX Message-ID: <3BBB7466.20301@nospam.adelphia.net> Does anyone (or has anyone) use ZODB on OSX? Bob ><> From stevecanfield at my-deja.com Tue Oct 9 21:00:53 2001 From: stevecanfield at my-deja.com (Steve Canfield) Date: 9 Oct 2001 18:00:53 -0700 Subject: error in the DDE conversation with Pythonwin Message-ID: <603e1b49.0110091700.49d8decd@posting.google.com> When I try to start Pythonwin on my machine (Athlon 800), I get the following error box: Python for Win32 There was an error in the DDE conversation with Pythonwin I click on okay and it seems to finish loading okay. I'm running: PythonWin 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32. under Windows Me. If I bring up my task list, Pythonwin is listed more than one time. I think this is because the first instance never starts up. I have a desktop icon to Pythonwin and I generally have to click on it a couple of times before Pythonwin will start up (giving plenty of time between startup attempts). Any ideas what the problem could be? I searched for this error message on Google and didn't get any hits. -steve From emile at fenx.com Wed Oct 10 17:04:12 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 10 Oct 2001 14:04:12 -0700 Subject: Newbie - unslicable type error etc References: <45956635.0110101132.245dcbf6@posting.google.com> Message-ID: <9q2ddi$ks3bd$1@ID-11957.news.dfncis.de> 7 MB is not so much that you couldn't read it all in on most systems. Then split on the byte sequence? srcedata = open(filename).read() fragments = srcedata.split(bytesequence) eg: >>> srcedata = "Thisthisisthisathistest" >>> bytesequence="this" >>> fragments = srcedata.split(bytesequence) >>> fragments ['This', 'is', 'a', 'test'] HTH, -- Emile van Sebille emile at fenx.com --------- "Rodney" wrote in message news:45956635.0110101132.245dcbf6 at posting.google.com... > Hi Everyone, > > I started playing with python last night for the first time and I have > run into a problem regarding data types. > > I have a large (7MB or so) file of raw hex data (ie values E{0,255}) > from which I need to identify a given byte sequence that occurs about > 800 000 times within the file. Once I have found these data fragments > I need to extract them to another file. My problem is that while I > have been able to open the file and use read(10) etc to look at the > file, I am unable to process it - I tried using input[23:67] (where > 'input' is the name of the file I am working with) but python > complained that I was using an unslicable type. > > So my question is how do I my file into a format where I am able to > use RE's in python to play with it? When I input.read(10) it looks > like: > > x05\x0A\x45\xA1... > > That is raw hex data. All suggestions most welcome. > > - Rodney From ksatcu at yahoo.com Thu Oct 18 17:25:18 2001 From: ksatcu at yahoo.com (Krish) Date: 18 Oct 2001 14:25:18 -0700 Subject: Triple-DES implementation in Python Message-ID: <1854cfa0.0110181325.50a4aba6@posting.google.com> Hello, Does anyone know if there is a publically available library for DES/Triple DES implementation in Python. Thanks a bunch for the info. KS From com-nospam at ccraig.org Fri Oct 26 09:44:19 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 26 Oct 2001 09:44:19 -0400 Subject: Integer coercion and 2.2 Type/Class changes Message-ID: Consider the following Python 2.2 code: >>> class foo(int): ... def __init__(self, n=0): ... self=n ... def bar(self): return self+6 ... >>> t=foo(4) >>> t.bar() 10 >>> type(t) >>> type(t+6) >>> type(t+t) This is the expected result, but probably often not the desired one. So my question is, is there some way, without redefining all of the numeric operations, to define a subclass that recasts all numeric operations to it's own type? -- Christopher A. Craig From tebeka at cs.bgu.ac.il Wed Oct 17 02:06:26 2001 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: Wed, 17 Oct 2001 08:06:26 +0200 Subject: makefile for distutils package Message-ID: <9qnbt9$7u2@hu5.hofstra.edu> Hello All, Is there a standard makefile to ship with a distutils created package (./setup.py sdist) I'm currently using: all: @echo Please specify one of the following: @python setup.py --help-commands | head -18 | tail -17 .DEFAULT: python setup.py $@ -- Bye. ---------------------------------------------------------------------------- - Smile, damn it, smile. lambda msg: { 'name' : 'Miki Tebeka', 'email' : 'mikit at elrontelesoft.com', 'url' : 'http://www.cs.bgu.ac.il/~tebeka', 'quote' : 'The only difference between children and adults is the price of the toys' }[msg] From sholden at holdenweb.com Tue Oct 16 13:29:09 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 16 Oct 2001 13:29:09 -0400 Subject: FW: [Python-Dev] conditional expressions? References: <23891c90.0110160824.6a5a0c1b@posting.google.com> Message-ID: "Paul Boddie" wrote ... > Anthony Baxter wrote >... > > Ok, so we're getting yet another ugly hack added to the language. > > Could the normal process of writing up a PEP be followed, so that > > those people in the community who are uncomfortable about it can > > at least see the justification for this? > > Indeed, it would be interesting to see the justification for > conditional expressions, apart from the fact that "it can be done", of > course. > It seems to me that increasing the number of contexts in which the keyword "if" is meaningful could represent a real learning setback to new Python users. > Given time, we all accept change. I accept now that the division > reform was probably necessary due, in part, to some bizarre behaviour [ ... bizarre divide behavior described ...] > > Still, some people have already openly wondered about the usefulness > of implementing countless "ugly hacks" when more interesting or > "necessary" challenges exist, particularly in the area of searchable > module catalogue services, to name one recent "hot topic"... > Certainly, from an implemetor's point of view, the justifications are different from the users'. However, I feel we can have faith that Guido will continue to see the "big picture" as far as language development is concerned. Certainly this seems far too recent a development to include in 2.2 (even if it can easily be done): more time is required for the implications to be fully appreciated by those of us who don't poke around in the system's internals every day. I particularly shudder for the newbie who must read something like the following (untested code warning: I'm not building an interpreter that can handle this stuff, because I'm hoping it will disappear <0.75 wink>): l = if a then [i for i in l1 if i % 2] else [i for i in l2 if not i % 2] Of course, this might also be cast as: l = [i for i in (if a then l1 else l2) if (if a then i % 2 else not i % 2)] This may not be the best way to implement such an expression, but if it can be done then someone will do it. It contrasts quite badly with: if a: l = [i for i in l1 if i % 2] else: l = [i for i in l2 if not i % 2] "ick" doesn't even beging to describe it. Save the newbies !!! if-i-had-a-vote-it-would-be-against-ly y'rs - steve -- http://www.holdenweb.com/ From dietmar at schwertberger.de Tue Oct 9 17:28:18 2001 From: dietmar at schwertberger.de (Dietmar Schwertberger) Date: Tue, 9 Oct 2001 23:28:18 +0200 Subject: Why so few Python jobs? (and licenses) References: <7x1ykd7es3.fsf@ruckus.brouhaha.com> <7xn13060xv.fsf@ruckus.brouhaha.com> Message-ID: In article <7xn13060xv.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > OK, though one should not underestimate the value of "small" > contributions, especially considering that some may have been made at > "gunpoint". E.g. I mentioned in another post I once spent a frantic > all-nighter finding an Apache module bug that was crashing my > employer's web site. The result was a two-line fix (it was a malloc > error). If I did emergency repairs of someone else's software for a > paying client, I'd charge at least 2x-3x my normal consulting rate per > hour. By that reckoning, the two-line fix was worth enough to my > employer to pay for several copies of a commercial server, because of > the time spent in a critical situation. (Of course the commercial > server would have had its own bugs...) How long would it have taken for the supplier to deliver a fix? Would he have supplied it at all? What if he wasn't around any more? Regards, Dietmar From emile at fenx.com Sat Oct 27 12:12:17 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Oct 2001 09:12:17 -0700 Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> <3bdad7e6_3@corp-goliath.newsgroups.com> Message-ID: <9rengl$tbkf5$1@ID-11957.news.dfncis.de> http://www.stackless.com -- Emile van Sebille emile at fenx.com --------- "K?roly Ladv?nszky" wrote in message news:3bdad7e6_3 at corp-goliath.newsgroups.com... > What is Stackless Python? > > Cheers, > > K?roly > > > ____________________________________________________________________________ __ > Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From adina_levin at mindspring.com Wed Oct 10 09:07:56 2001 From: adina_levin at mindspring.com (adina_levin at mindspring.com) Date: Wed, 10 Oct 2001 08:07:56 -0500 Subject: Python, XML, and databases Message-ID: <9q1hir$tji$1@slb3.atl.mindspring.net> Is there a Python tool to exchange data between a relational database and XML? I've looked at python.org, searched the archive of this list and xml.com, looked in the mysql documentation, no luck yet. Pointers welcome, hopefully I've missed something. thx, - adina From gh_pythonlist at gmx.de Tue Oct 9 13:41:52 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 9 Oct 2001 19:41:52 +0200 Subject: ARGV and import ? In-Reply-To: ; from sholden@holdenweb.com on Tue, Oct 09, 2001 at 01:14:17PM -0400 References: <660c52de.0110090907.4017f907@posting.google.com> Message-ID: <20011009194152.A3291@lilith.hqd-internal> On Tue, Oct 09, 2001 at 01:14:17PM -0400, Steve Holden wrote: > [...] > __import__ (name[, globals[, locals[, fromlist]]]) Oh, I wasn't aware of this function. That's of course preferrable to constructing the import statement via exec. Guess I'd better re-read the Python docs sometime. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mwh at python.net Mon Oct 22 09:38:40 2001 From: mwh at python.net (Michael Hudson) Date: Mon, 22 Oct 2001 13:38:40 GMT Subject: Writing to SdtErr References: <1003757605.11708.0.nnrp-14.d4f0f8ae@news.demon.co.uk> Message-ID: "Mike Peat" writes: > Can anyone tell me how to: > > 1) Turn of the Python "Traceback" output, or make it less verbose? sys.excepthook = something_else > 2) Write (print) to the StdErr channel instead of StdOut? print >> sys.stderr, "foo" Both of these require a new-ish Python (not sure which release, sorry). An example of both: >>> def eh(type, value, tb): ... print >> sys.stderr, "Exception: ", type ... >>> sys.excepthook = eh >>> 1/0 Exception: exceptions.ZeroDivisionError Cheers, M. -- I have long since given up dealing with people who hold idiotic opinions as if they had arrived at them through thinking about them. -- Erik Naggum, comp.lang.lisp From chrishbarker at home.net Wed Oct 24 18:35:18 2001 From: chrishbarker at home.net (Chris Barker) Date: Wed, 24 Oct 2001 15:35:18 -0700 Subject: question on using format in struct module References: Message-ID: <3BD74226.F403A98C@home.net> Suresh wrote: > I need some help with struct module. I have a binary file (obtained > with our product) and it contains char, int, float values. I used > struct module for this purpose in this manner -- > import struct > binfile = open('binary_file.bin','rb') > format = ???? > bytes = struct.calcsize(format) > i1, i2 and so on = struct.unpack(format, binfile.read(bytes)) > > (i1, i2, i3 etc will have the equivalent text values of the binary > fields from the "binary_file.bin") The equivalent TEXT values??? IS that what you want? If so, struct.unpack won't do it for you directly. It unpacks the bytes into the appropriate numerical types. If you want strings, you can convert them to strings afterward by any number of methods (str(), %, ``, etc.) > The problem is specifying for "format" variable. Since my binary file > has non-uniform and different data types how do I specify for format = > ???? That's exactly why you have to specigy the format... > Is there a way I can tell python to decide upon format looking at > the binary file. No. it is just a bunch of bytes to Python, and will mean different things depending on how it is interpreted. There is no way for Python to know. Here is an example of how to use it: If your file has, for example, two chars, an int and a float in sequence, the format would be: format "ccif" or format "2cif" see the library reference for other format characters, and how to use them. If you still can't figure this out, send us some information about the file (maybe a snippet of the code that wrote it), or ask the person who wrote the code that created the file to help you with the format string(s). -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From ngps at madcap.dyndns.org Mon Oct 1 11:39:25 2001 From: ngps at madcap.dyndns.org (Ng Pheng Siong) Date: 1 Oct 2001 15:39:25 GMT Subject: Can't compile M2Crypto References: <9p2176$23b$1@wanadoo.fr> Message-ID: <9pa2nd$ab1$1@violet.singnet.com.sg> According to Florent : > I have installed from the source Python-1.5.2, SWIG-1.3.6 and > openssl-0.9.6b. I think you're picking up the wrong OpenSSL on your system. > _m2crypto_wrap.c:1264: warning: passing arg 2 of `HMAC_Update' discards > qualifiers from pointer target type Here's what 0.9.4's HMAC_Update looks like: $ egrep HMAC_Update /usr/include/openssl/hmac.h void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len); Here's what 0.9.6's looks like: $ egrep HMAC_Update /usr/local/include/openssl/hmac.h void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len); > _m2crypto_wrap.c:1635: conflicting types for `DHparams_print' > /usr/include/openssl/dh.h:132: previous declaration of `DHparams_print' The OpenSSL you're linking with is probably built without -DBIO. > _m2crypto_wrap.c:2678: `SSL_MODE_AUTO_RETRY' undeclared (first use in this > function) SSL_MODE_AUTO_RETRY is new in 0.9.6. 0.9.4 doesn't have it. Check that you are indeed using the correct OpenSSL includes and libraries. Cheers. -- Ng Pheng Siong * http://www.post1.com/home/ngps From piet at cs.uu.nl Sun Oct 7 10:46:30 2001 From: piet at cs.uu.nl (Piet van Oostrum) Date: 07 Oct 2001 16:46:30 +0200 Subject: Problem with embedding - can only make about 150 calls... References: Message-ID: Stack overflow? -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From gmcm at hypernet.com Thu Oct 25 18:01:55 2001 From: gmcm at hypernet.com (Gordon McMillan) Date: 25 Oct 2001 22:01:55 GMT Subject: Solaris core dump with McMillan Installer References: <9r960f$s8h9i$1@ID-59885.news.dfncis.de> Message-ID: David Bolen wrote: > Gordon McMillan writes: > >> I was going to guess 8, but I guess I better use 16. > > Why not just let the compiler generate whatever alignment it wants for > the structure and just marshall/unmarshall the individual fields > (field by field) into the file. That way alignment shouldn't be an > issue. Because I write it with Python and read it with C. Maybe (someday) not even on the same kind of box. - Gordon From max at alcyone.com Fri Oct 12 19:52:25 2001 From: max at alcyone.com (Erik Max Francis) Date: Fri, 12 Oct 2001 16:52:25 -0700 Subject: dictionary.update() enhancement? References: <3BC64CC4.444A77E7@alcyone.com> Message-ID: <3BC78239.C4C4636@alcyone.com> Mark J wrote: > Mark J wrote: > > >> Because it's not as straight-forward as saying d.update(other, > >> collision_handler) and it's about 10 times slower. > > Erik Max Francis wrote: > > > Ten times slower? What in the world gives you that idea? > > Try it: That is among the silliest tests I've ever seen. The current behavior does _not_ do collision testing, and so you're not comparing manual collision testing with your proposed collision testing, you're comparing manual collision testing with _nothing_. Of _course_ it's slower, but that doesn't mean that your proposed method would be any faster. Your proposal would have to call out to the provided Python collision handler function, which is going to be the bottleneck, and so it is highly unlikely to be significantly faster. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Don't overestimate the decency of the human race. \__/ H.L. Mencken Erik Max Francis' bookmarks / http://www.alcyone.com/max/links/ A highly categorized list of Web links. From sholden at holdenweb.com Wed Oct 10 17:30:04 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 10 Oct 2001 17:30:04 -0400 Subject: ODBC access via Python References: Message-ID: "vm_usenet" wrote ... > Hi all! > > I have recently become a die-hard Python fan, but I can't seem to > overcome a minor obstacle: > > Can anyone direct me to a good ODBC module/library for python under > win32? > > I've tried to install mxODBC, but it doesn't work for some reason... > Are you running Cygwin? Did you use the binary installer or build mxODBC from source? Is it for the correct version of Python (C extensions are version-specific)? In my experience there isn't a better ODBC module, so it would be more fruitful to debug its failure to install than to seek for another package. In the interim, have you tried the odbc module that comes with Mark Hammond's win32 extensions? regards STeve -- http://www.holdenweb.com/ From matz at ruby-lang.org Tue Oct 9 23:23:41 2001 From: matz at ruby-lang.org (Yukihiro Matsumoto) Date: 10 Oct 2001 12:23:41 +0900 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> Message-ID: <87itdouqiq.fsf@ev.netlab.jp> Hi, "Markus Jais" writes: |It would be great, if this would be possible in Python too |on the other side, I understand that this would be a huge impact |on the language. maybe this is something for Python 3000 ?!?! I'm not sure Python needs something like 3.method. Python's integers have far fewer methods than Ruby (because it uses functional style). And it doesn't have idioms like 100.times {|i| puts i } So (3).method is enough for Python. matz. From tanzer at swing.co.at Tue Oct 9 10:48:07 2001 From: tanzer at swing.co.at (Christian Tanzer) Date: Tue, 09 Oct 2001 16:48:07 +0200 Subject: String formatting with two dictionaries? In-Reply-To: Your message of "Tue, 09 Oct 2001 11:05:07 +0200." <3BC2BDC3.20A41F38@snakefarm.org> Message-ID: > Thanks for all the answers. Seems as if I hadn't been specific > enough about what I was looking for. It would be nice if there was > some builtin dictionary magic that would allow > > "%(foo) %(bar)" % magic(dict1, dict2, ...) > > where in case of duplicate keys the leftmost dictionary would be > preferred. > > Perhaps the builtin dictionary() class could be extended so that > it accepts more than one dictionary argument? Really no need for a builtin here: def magic(* dicts) : result = {} dicts = list(dicts) dicts.reverse() map(result.update, dicts) return result Adding keyword arguments is left as an exercise... -- Christian Tanzer tanzer at swing.co.at Glasauergasse 32 Tel: +43 1 876 62 36 A-1130 Vienna, Austria Fax: +43 1 877 66 92 From uwe at rocksport.de Fri Oct 5 05:57:50 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 5 Oct 2001 09:57:50 GMT Subject: another wxPython-question References: <9pi16t$5pt1t$1@hades.rz.uni-sb.de> <3BBCB53D.407B103B@home.net> Message-ID: <9pk06u$58ljt$1@hades.rz.uni-sb.de> Chris Barker wrote: | Uwe Schmitt wrote: |> in the wxWindows documentation I found classes wxDC, wxPaintDC and |> others. But these are not known if I use wxPython. |> Is my wxPython installation to old ? I downloaded it from |> www.wxpython.org... | It's probably not too old, the ones you mention have been around | forever. You may not have wxPython installed properly, or you may not be | importing it correctly. try this: |>>> from wxPython.wx import * |>>> wxDC | |>>> wxPaintDC | |>>> | You get something like that, showing that thye do exist. AS for using | them, look at the demo, and I've enclosed a little simple drawing | program to get you started. thanks a lot. the import statement above works. i made an error: i looked for a file "*wxDC*" which is not on my computer. i'll study your example, yours, uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From nhodgson at bigpond.net.au Thu Oct 25 06:24:55 2001 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 25 Oct 2001 10:24:55 GMT Subject: wierd win32all gui problem (w/56lines of code) References: Message-ID: Jeffrey Drake: > Using ActivePython 2.1 and win32all I have written a simple app that creates > a window and exits when closed. However the python interpreter is still > running. It hangs a command prompt under win2k until I physically kill the > python process. I would appreciate any help possible. The WndProc isn't called at all. Add some prints or message boxes in the code and you'll see the WndProc is ignored. Neil From web.mail at lycos.com Wed Oct 17 20:29:11 2001 From: web.mail at lycos.com (Alan Green) Date: 17 Oct 2001 17:29:11 -0700 Subject: defstruct.py References: Message-ID: <270c68fe.0110171629.5049ac9a@posting.google.com> Kragen, Neat code. Looks like it has been through a few iterations. Thanks for posting it. I used this on our company internal mailing as an interesting example of several Python features: 1. def fn(*arg) - to collect an arbitrary argument list. (twice!) 2. Use of setattr() rather than stuffing things into an instance's dictionary. 3. An exception raised with a very neat error message. (Makes debugging simpler. 4. Defining a class inside a function - creates a new class object each time the function is run. 5. The class object returned by the function has no public name, but can still be used to instantiate instances. Question to think about: should the returned class be assigned to a variable with an initial Uppercase letter? Cheers, Alan. -- kragen at dnaco.net (Kragen Sitaker) wrote in message news:... [snip, snip] > # -- Kragen Sitaker, 2001-10-16 > > def defstruct(*fields): > class Struct: > def __init__(self, *contents): > if len(contents) != len(self.structfields): > raise TypeError, ( > "wrong number of arguments: expected %d %s, got %d" % > (len(self.structfields), > repr(self.structfields), > len(contents))) > for fieldnum in range(len(contents)): > setattr(self, self.structfields[fieldnum], contents[fieldnum]) > Struct.structfields = fields > return Struct > [snip, snip] From jhauser at ifm.uni-kiel.de Mon Oct 15 04:00:52 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 15 Oct 2001 10:00:52 +0200 Subject: SVG and Python? References: <3BCA9747.2F8C9462@sbc.su.se> Message-ID: <87r8s58h8r.fsf@lisboa.ifm.uni-kiel.de> Look for sketch http://sketch.sourceforge.net/ It can read and write SVG files, although I'm not sure if all things of the spec are possible. HTH, __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From James_Althoff at i2.com Tue Oct 2 12:57:38 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Tue, 2 Oct 2001 09:57:38 -0700 Subject: list remove Message-ID: The python tutorial at http://www.python.org/doc/current/tut/node7.html#SECTION00710000000000000000 0 has the section more on lists where it gives the function remove(x). I am trying to use this function to delete elements out of my list, but it only deletes every other list. >>>foo = [1, 2, 3, 4, 5] >>>for bar in foo: ... foo.remove(bar) >>>foo [2, 4] Is this an error on my part, pythons list type or am I misinterpretting what remove does? I have tried this on both 2.1 and 1.5.2. Thanks. Steve ================ It's not a good practice to delete items from a list when iterating over that same list. Iterate over a copy of the list instead. Just change for bar in foo: to for bar in foo[:]: # now you are iterating over a copy of foo Jim From x1xx1x at hotmail.com Thu Oct 18 19:35:17 2001 From: x1xx1x at hotmail.com (JT) Date: 18 Oct 2001 16:35:17 -0700 Subject: Help : IndexError - probably pretty simple References: Message-ID: I wanted to thank everyone for responding to my post. With your help I got the module working. I ended up changing the list declaration from "ov = []" to "ov = [None] * (n+1)" This fixed the indexing error and allowed the module to work. I then had to make many changes to get the binomial tree working properly in the for loops. But I did get it working and I wanted to thank you for your help. JT From johnroth at ameritech.net Thu Oct 11 15:40:41 2001 From: johnroth at ameritech.net (John Roth) Date: Thu, 11 Oct 2001 12:40:41 -0700 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> Message-ID: "Greg Ewing" wrote in message news:3BC4E625.E6C73878 at cosc.canterbury.ac.nz... > Paul Rubin wrote: > > > > I feel seriously cramped in Python when I have to say > > > > while 1: > > x=get_next() > > if not x: break > > whatever(x) > > I feel the solution to this is *not* to go in for > any sort of assignment-in-expressions hackery, but > to provide a decent loop-and-a-half control structure. > My current idea for this is > > while: > x = get_next() > gives x: > whatever(x) The notion that while is adequate as a looping construct comes from the minimalist school. From a techincal point, they are right, but from a pragmatic point of writing economical, understandable programs, they are wrong. If you're going to expand the loop syntax, all four (or five) parts should be explicit: initialization, test, reinitialization, body and possibly zero-trip exception. In particular, test should allow more than one expression: it should allow either a single expression or any number of statements. In this case, exit would require an explicit break. Unfortunately, this gets to be more than a bit cumbersome. John Roth > > -- > Greg Ewing, Computer Science Dept, University of Canterbury, > Christchurch, New Zealand > To get my email address, please visit my web page: > http://www.cosc.canterbury.ac.nz/~greg From uwe at rocksport.de Wed Oct 17 17:33:04 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 17 Oct 2001 21:33:04 GMT Subject: os.path.join and lists References: Message-ID: <9qkteg$6vaga$1@hades.rz.uni-sb.de> Fredrik Lundh wrote: | how about | bar = [ "fred", "barney", "froo" ] | baz = bar + [ "bob" ] | foo = os.path.join(*baz) hi, whats the meaning of "*baz" ?? i've never seen this before.... uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From matt at mondoinfo.com Wed Oct 24 13:43:08 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Wed, 24 Oct 2001 17:43:08 GMT Subject: Tk and focusing windows References: Message-ID: On Wed, 24 Oct 2001 07:16:06 GMT, Graham Ashton wrote: >I've got an application which opens two Tk windows as soon as it starts >up; the main window and a progress dialog. > >I want the dialog to be displayed after the main window (so the main >window can't cover it up), but the way my code is currently structured I >call mainloop() immediately after creating the dialog. The code for the >main window is done first. > >The main window is instantiated with "root = Tk()" before anything else >happens, and the dialog is created with Toplevel(). Graham, Tkinter doesn't make it easy to get things displayed attractively during startup. I find that getting things to look the way I want often requires figuring out the right places to put calls to update_idletasks(). I'll append a small example that may help. Of course, once you've got the right incantation for your window manager, there's no guarantee that another window manager will do just the same thing in response to the same requests. Regards, Matt #!/usr/local/bin/python from Tkinter import * import time class mainWin: def __init__(self,root): self.root=root self.progressWin=None self.createWidgets() self.root.update_idletasks() self.root.after_idle(self.doTimeConsumingSetup) return None def createWidgets(self): l=Label(self.root,height=10,width=40,text="Main") l.pack() return None def doTimeConsumingSetup(self): self.showProgressWin() time.sleep(5) self.hideProgressWin() return None def showProgressWin(self): self.progressWin=Toplevel() l=Label(self.progressWin,text="Please wait") l.pack() self.root.update_idletasks() return None def hideProgressWin(self): self.progressWin.destroy() return None def main(): root=Tk() mainWin(root) root.mainloop() return None if __name__=='__main__': main() From gabriel_ambuehl at buz.ch Tue Oct 2 10:08:03 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Tue, 2 Oct 2001 16:08:03 +0200 Subject: XML Marshalling of objects In-Reply-To: References: Message-ID: <139677110373.20011002160803@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello Peter, Tuesday, October 02, 2001, 3:23:02 PM, you wrote: > Hello, > I'm wondering if there is a good way to marshal/unmarshal python > objects to XML? I'm thinking of some framework like Castor > (castor.exolab.org) for Java. > Is xml-rpc the right way to go? > thanks for help > /peter > mailto:peter at windh.com I once had something called xmlpickle which did exactly this. Best regards, Gabriel -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO7m8NsZa2WpymlDxAQHApAf+L4HBODtQ6kZkvth/n6F6B2nLi7D+LLIv oAfbzoA6jrjA0NPa74XAsK5CSAhiniqJXuUd+WWP9Kedw9zxf0azGfOWJcph3rL8 ul9/OxdJCD88GkSRgkPs4mCZJSL7SUx/oyvvZzT6aOE1qn8L7cXNYc4IXvLsec1h ySuMt7lHMsRMDdL2bKdzNJY6aqZVoDvO7yCVaEtxJJpppNLEMwqTlaQcRk6o8J98 Qo+pyBORQoPlad1AnlH0kaErpeLH6L1eaLB6MwcTEB97x21IxPXI8K4sC4CUjLjK LaogQE5kQEMBA+eGvYnpfBgcDzk9o7yxlWb3QAyqq3vjtJHpEpcGKA== =CFte -----END PGP SIGNATURE----- From peter at engcorp.com Mon Oct 8 09:59:17 2001 From: peter at engcorp.com (Peter Hansen) Date: Mon, 08 Oct 2001 09:59:17 -0400 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> Message-ID: <3BC1B135.40F4661B@engcorp.com> Carsten Gaebler wrote: > > Given a string > > s = "%(foo)s %(spam)s" > > and two dictionaries > > d1 = {"foo": "bar"} > d2 = {"spam": "eggs"} > > how would you apply d1 and d2 to s without modifying or explicitly > copying one of the dicts? I mean, I don't like to > > d3 = dictionary(d1) > d3.update(d2) > s = s % d3 Split the string into parts which don't contain names from both dictionaries... (I doubt you'll "like" to do that either. I think you're asking for something that can't be done in a way that would satisfy you.) If you seriously want another answer, you might need to specify the requirements further. Do the dictionaries ever contain duplicate keys? Why don't you want to do the copy and update? (you don't say, and any solution put forth runs the risk of violating your unexpressed restrictions and having you not "like" it..) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From skip at pobox.com Tue Oct 16 14:39:35 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 13:39:35 -0500 Subject: re.findall() is skipping matching characters In-Reply-To: References: Message-ID: <15308.32487.986473.381131@beluga.mojam.com> >> If you're on a Unix machine with a reasonable Perl installation, "man >> perlre" may be a useful adjunct to other regular expression >> documentation you might have handy. Steve> Skip, are you telling me I'm not allowed to use the re Steve> documentation in my Windows ActivePerl installation? ;-) Or my Steve> cygwin Perl, where the exact command you mention works just fine? No, but had I not qualified my statement, someone would surely have whined that I assumed that everyone had Unix man pages available. ;-) Skip From dalke at dalkescientific.com Tue Oct 9 13:04:04 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 9 Oct 2001 11:04:04 -0600 Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com><9pimak$c22$1@tyfon.itea.ntnu.no><825v7.1025$rq1.37994@atlpnn01.usenetserver.com><3BBE4E12.16FE036A@earthlink.net> <9pn44q$m1r$1@tyfon.itea.ntnu.no><3BBF2751.3010309@sneakemail.com> <23891c90.0110090118.7df7917e@posting.google.com> Message-ID: <9pvatc$1c1$1@slb5.atl.mindspring.net> Ken Guest wrote: >and what exactly does this have to do with python? >I thought this was a python list not a linquistics list. It's the patented (but licensed without a fee) c.l.py flame supressent system in action. It managed to subvert a typical and never-ending flare fest on the meaning of "free" into a discussion on the use of the apostrophe. that's-Tim-Peters'-fo'c'sle-ly y'rs Andrew From martin.franklin at westgeo.com Tue Oct 23 07:49:10 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Tue, 23 Oct 2001 12:49:10 +0100 Subject: Python for ipaq References: <7SbB7.7669$Ub2.260976@atlpnn01.usenetserver.com> Message-ID: <9r3ldh$1qsi$1@mail1.wg.waii.com> Karol Makowski wrote: > On 23 Oct 2001 10:50:46 GMT, Karol Makowski wrote: >> On Tue, 23 Oct 2001 06:47:52 -0400, Steve Holden wrote: >>> Sample FTP code in ftpStream.py at >> thanks, i'll check it. > > it's not suitable for my needs, sorry. > I need an ftp client which will dynamicaly get filename/folder > from a commandline. > On that crappy ipaq there is no any smb/nfs protocol and i've got some > app which need to send and recive some files to work correctly, so i > thought i'll get some simple ftp client in python, cause python it's > avaiable for ipaq. ftp client should be run from command line like this: > ftp.py -g somefile (download file from server) > ftp.py -s somefile (send some file to server) > > It's all i need, server, username/pass is defined in program, > while filename and/or path should be a variable. > > Thanks for help. > You could role your own like this:- #!/usr/local/bin/python # ftp.py .... import ftplib, sys if sys.argv[1]=='-g': # get it is! action='GET' elif sys.argv[1]=='-s': # send (aka PUT) action='PUT' else: print """USAGE: to get a file from server:- ftp.py -g remote_file_name local_file_name to put a file on server:- ftp.py -s remote_file_name local_file_name """ sys.exit() filename=sys.argv[2] localfile=sys.argv[3] ftp=ftplib.FTP('Some.Server.Somewhere') ftp.login('USERNAME', 'PASSWORD') ftp.set_debuglevel(0) if action=='GET': lfile=open(localfile, 'wb') def store_local(data): lfile.write(data) ftp.retrbinary('RETR %s' %filename, store_local, 32768) else: ftp.storbinary('STOR %s' %filename, open(localfile, 'rb'), 32768) From mvdwege.usenet at drebbelstraat20.dyndns.org Mon Oct 1 07:50:53 2001 From: mvdwege.usenet at drebbelstraat20.dyndns.org (Mart van de Wege) Date: Mon, 01 Oct 2001 11:50:53 GMT Subject: [Q] PyGreSQL References: Message-ID: In , Seung-won Hwang wrote: > (2) What's the easiest way to load tab-separated text data to the relational > database? Any easier way than writing a program that calls "INSERT INTO" for > every data value? > Assuming you are running PostgreSQL, use the 'COPY FROM' SQL command. I believe it defaults to tabs as field seperators, otherwise you can define that in the command. Yep that's it. First do a 'CREATE TABLE' to define the columns, then 'COPY FROM ' will fill it. You might want to check out http://www.postgresql.org/docs/awbook.html for Bruce Momjian's book. Mart -- Requiem aeternam dona eis, Domine, et lux perpetua luceat eis. Requiescant in pace. Amen. From stephen at theboulets.net Tue Oct 23 23:30:40 2001 From: stephen at theboulets.net (Stephen Boulet) Date: Tue, 23 Oct 2001 22:30:40 -0500 Subject: Executing a string as python code Message-ID: Can someone tell me how to execute an arbitrary string as python code? I'm trying to make a bunch of lists named list00, list01, ..., to list99 (I don't want to make a single list of lists, since list00 is actually already a list of lists), and I thought doing this as a string would be the easiest way. I guess a dictionary with string keys and list values would be another way (maybe a better way). Thanks. -- Stephen From romany at actimize.com Sun Oct 28 13:41:26 2001 From: romany at actimize.com (Roman Yakovenko) Date: Sun, 28 Oct 2001 20:41:26 +0200 Subject: Tcl/Tk & Python Message-ID: <7647A9F4B298E74DB6793865DA67285004AC66@exchange.adrembi.com> Hi. Where can I get a help ( I mean files or other material ) on Tkinter as python module. Thank you. From db3l at fitlinxx.com Fri Oct 5 13:14:22 2001 From: db3l at fitlinxx.com (David Bolen) Date: 05 Oct 2001 13:14:22 -0400 Subject: how do i catch pywintypes.api_error? References: Message-ID: "John S. Yates, Jr." writes: > Is there anyway to write an except handler that will > catch only api_error? Alternatively, within a handler > can I determine whether or not I have an api_error? It can be a little confusing at first. The actual error object that is used during exceptions is normally named "error" within the module that you are using. However, when it represents itself as a string it always displays pywintypes.api_error. For example: >>> import win32file >>> print win32file.error pywintypes.api_error So if for example, you've imported win32file and are working with that, put the except clause for "win32file.error". If you're using multiple modules, it may be possible to use any of their error classes, but I'm not positive. I normally just stick with the module within which I'm making the API call. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From shalehperry at home.com Sat Oct 6 10:35:17 2001 From: shalehperry at home.com (Sean 'Shaleh' Perry) Date: Sat, 06 Oct 2001 07:35:17 -0700 (PDT) Subject: Octonians in Python In-Reply-To: Message-ID: On 06-Oct-2001 David Feustel wrote: > There is one additional system of complex numbers > (octonians) beyond quaternions. Are there any > python implementations of octonians? > perhaps you are new to the net and have not heard of www.google.com. Go there and give it a peak. You could have found the answer to both of your questions in moments. From sheila at spamcop.net Sat Oct 20 23:48:18 2001 From: sheila at spamcop.net (Sheila King) Date: Sun, 21 Oct 2001 03:48:18 GMT Subject: Smtplib module References: <3BD20BAE.6346.7693E0@localhost> <9qscfm.3vv746r.1@kserver.org> Message-ID: <9qsnue.3vv5vib.1@kserver.org> On Sun, 21 Oct 2001 04:11:06 +0200, Gerhard H?ring wrote in comp.lang.python in article : :you're of course right. My thinking was too complicated, again. But :you'll only recognize if the local delivery to the mail server failed, :not when relayed mail's delivery fails. I did never find the local :failures particularly interesting, because I usually know which users :exist on my SMTP server in advance. No, local delivery isn't interesting. I just used "localhost" in the code snippet as an example. Certainly can be changed. For more excitement: Do an MX record look up on the domain name in the email address, and deliver directly to that SMTP server. Coding is left as an exercise for the reader. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From gurdon_merchant at ml.com Fri Oct 12 09:06:10 2001 From: gurdon_merchant at ml.com (Gurdon Merchant, Jr.) Date: 12 Oct 2001 06:06:10 -0700 Subject: Using NetScheduleJobAdd with calldll. Message-ID: <54723b6a.0110120506.2cd184ce@posting.google.com> I've used Sam Rushing's calldll tool to do some simple Win32 API calls. However, I've failed to use it properly in calling the NetScheduleJobDel() API. I realize I can manipulate jobs in other ways but wish to use calldll despite that fact. I believe I'm passing the string with the PC name incorrectly. Could someone point out my error? The C definition of NetScheduleJobDel() is rather simple and is located at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/ntlmapi2_7gz0.asp # Problem: When I use calldll to invoke NetScheduleJobDel() to delete # an at job it only works when specifying the local PC via a null # for the name. If the name of the local PC or a remote one is # used it fails. Is not a rights problem. Believe I'm not passing # in the PC name to NetScheduleJobDel() correctly. # # Assumption: 'at 10:00 /every:m foo' or some other variation was # done to create an at job entry on an NT system. Note the job # number and pass in as parameter one. # # Sam Rushing's module for generic API calls. import windll # Get a pointer to the NT DLL with the NetSchedule* APIs used to # manipulate the scheduler. netapi32_dll = windll.module('netapi32', '.dll') # Grab the job number to delete from parameter one. import sys jobNumToDelete = int(sys.argv[1]) # Following returned ERROR_INVALID_NAME=123 when trying to delete # job on local machine. # pcName = windll.cstring('') # Following returned ERROR_SUCCESS=0 when trying to delete job # on local machine. pcName = windll.cstring('', 2) # Following returned ERROR_BAD_NETPATH=53 when trying to delete job # on remote machine. # pcName = windll.cstring('\\\\remotepcname') # Same result when specifying the local PC by name: # pcName = windll.cstring('\\\\localpcname') errorCode = netapi32_dll.NetScheduleJobDel( pcName.address(), jobNumToDelete, jobNumToDelete ) print 'NetScheduleJobDel returned', errorCode Thanks in advance, Gurdon Merchant, Jr. Gurdon_Merchant at ml.com From rdsteph at earthlink.net Sun Oct 28 14:57:25 2001 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 28 Oct 2001 19:57:25 GMT Subject: AskMerlin, your AI expert system guru oracle advisor Message-ID: <3BDC649F.6EB6680B@earthlink.net> Ok, so this is what happens when Guido promotes CP4E. You get newbie, duffer, weekend hackers doing whatever turns them on. I make no claims that this code is anything more than a hack. Please excuse it, but if anyone is interested, you can link to my programs below. Thanks to the inventors of NLQ and multiChoiceGuesser! I hope you can forgive me for hacking your code ;-)) #!/usr/bin/python # AskMerlin is a weekend hack I did by putting together a short program called NLQ, # or natural language query, which can be found online at http://gurno.com/adam/nlq/#download # NLQ is a Class to take an inputted query and output 1. Keywords and 2. also to categorize # the type of question being asked. I am primarily interested in using the Keywords # extracted form a query by NLQ. I shamelessly modified NLQ to add many more # IGNORE_WORDS and otherwise spruce it up. # Next, I utilized the multiChoise Guesser script that some nice person posted # on the newsgroup a couple weeks ago. This uses urllib to go out to the web # and judge teh appropriateness of a given answer by how many hits it gets on Google # when coupled with the original question in a Google search. # My main contribution, such as it was, was simply to enable the program to create # choices in order to choose a most appropriate answer. This is done by using # NLQ to pick out Keywords form teh HTML page returned by Google in its search # on the question. This version, AskMerlin, currently takes a long time # to come to an answer because it must do many web searches/ I have also a simpler version # called aNoDivisorAskMerlin that comes to a much quicker decision, btu is not as good in the # appropriateness of its answer's. In either case, you must wait patiently while # merlin considers his options...dependign on speed of your internet connection. # On my cable modem at home, AsKMerlin takes about three minutes. # I am hoping that someone or other might give me ideas on how to improve the # intelligence behind Merlin's deliberations. This version is just a hack to see if it works # in principle. I have other ideas to increase "intelligence" but I need more. # Currently, Merlin is very low IQ, but he has potential for the future. # Anyway, Merlin can already answer just about any question. # Someday, perhaps he will even answer correctly or at least with wisdom # ;-))))))))))))) http://www.awaretek.com/AskMerlin.py http://www.awaretek.com/aNoDivisorAskMerlin.py From madsdyd at challenge.dk Mon Oct 1 08:40:19 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 14:40:19 +0200 (CEST) Subject: Problem with linking embedding C application In-Reply-To: <20011001134917.A2116@lilith.hqd-internal> Message-ID: On Mon, 1 Oct 2001, Gerhard H?ring wrote: > On Mon, Oct 01, 2001 at 01:16:58PM +0200, Mads Bondo Dydensborg wrote: > > On Mon, 1 Oct 2001, Olivier Deme wrote: > > > > > Hi, > > > > > > We have written an application written in C, which invokes sometimes > > > the Python interpreter for executing Python methods. > > > > > > So, I am trying to statically link our application with > > > libpython*.*.a., but this result in various undefined symbols (see > > > below). [...] > > [...] > > I have a machine, where I need to do: -lnsl -ldl -lreadline -ltermcap > > -lpthread -lutil -lm to be able to link with python. > > > > The annoying thing is, that it is very hard to determine this in > > general. At least I am not aware of any way to do it. > > I think this will do it. It does work for me: > > from distutils.sysconfig import get_config_var > print get_config_var("LIBS") + " " + get_config_var("SYSLIBS") Thanks, that is nice. Am I correct in assuming that this module is rather new? (I just checked, it does not seem to be present in Python 1.6, but is very much in 2.0). Where did you figure out about "LIBS" and "SYSLIBS" from? Thanks, Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk The US population is 4 % of the global one. They produce 23 % of the global pollution. From loewis at informatik.hu-berlin.de Mon Oct 1 12:57:45 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Oct 2001 18:57:45 +0200 Subject: How do Java interfaces translate to Python? References: Message-ID: Jan Samohyl writes: > On Sun, Sep 30, 2001 at 10:50:15PM +0000, Gordon Tyler wrote: > > In article , Martin von Loewis wrote: > > > What exactly is it that you do with interfaces in Java? > > > > I find myself unable to think of anything other than that. Which suggests > > to me that perhaps interfaces aren't such a useful construct after all. ;) > > I have heard somewhere that in java one often uses interfaces where he would > use multiple inheritance. Maybe this is the case. This case occurs if you need a multi-rooted hierarchy. I.e there are some object which are phones (i.e. have a getNumber operation), and some things that are portable (i.e. support a getWeight operation). Some things are both portable and phones. That sounds like you'd need multiple inheritance. In Java, you can do this with interfaces; provide a Phone and a Portable interface, and have the 'Handy' device implement both of them. Then you can pass that device both to somebody trying to call you, and to somebody carrying things for you. In Python, you can just implement both getNumber and getWeight, without having to declare any interfcaces, and pass Handys to algorithms that expect either kind of object. Regards, Martin From phd at phd.pp.ru Tue Oct 23 06:58:25 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 23 Oct 2001 14:58:25 +0400 Subject: Python for ipaq In-Reply-To: <7SbB7.7669$Ub2.260976@atlpnn01.usenetserver.com>; from sholden@holdenweb.com on Tue, Oct 23, 2001 at 06:47:52AM -0400 References: <1003829421.27538.0.nnrp-01.d4f0f8ae@news.demon.co.uk> <7SbB7.7669$Ub2.260976@atlpnn01.usenetserver.com> Message-ID: <20011023145824.P21265@phd.pp.ru> On Tue, Oct 23, 2001 at 06:47:52AM -0400, Steve Holden wrote: > > Regarding your second question: I have just written a simple FTP client in > > Python using ftplib and you would be welcome to it... but it is the first > > non-trivial program I have ever written in Python and I'm a little nervous > > about letting anybody see it . > > > Sample FTP code in ftpStream.py at > > http://www.holdenweb.com/Python Very simple and nice ftp client for vim is at http://www.zope.org/Members/philh/vim_html Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From vasvir at yahoo.com Fri Oct 5 09:56:32 2001 From: vasvir at yahoo.com (Vassilis Virvilis) Date: Fri, 5 Oct 2001 16:56:32 +0300 Subject: distutils: datafiles? Message-ID: <9pkdvp$2mo8$1@ulysses.noc.ntua.gr> I would like to use distutils in order to properly install and distribute my python program (buildconf! Do you actually remember the Software Carpentry project?). I have reached to a point that is really close to a public distribution and this is why I need distutils. The problem I am facing is that I have a directory structure to install. This is easily solvable for *.py files. I can divide them into modules and have no problems. However I need some administrative data files installed along with their relevant py files and I find that distutils was very unwilling to help me to that end. Any recomendations? .Bill From slinkp23 at yahoo.com Thu Oct 25 03:30:38 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Thu, 25 Oct 2001 07:30:38 GMT Subject: String comparison References: <4a0341c8.0110242221.592e603e@posting.google.com> Message-ID: On 24 Oct 2001 23:21:21 -0700, Shankar wrote: >I started learning python recently and the examples given on >python.org only talk about number comparison. >I tried: >x = input("Proceed?"); > >if x == 'y': > print "You typed y\n"; > > >This gives out a syntax error. It should give you a name error. What you want is raw_input, not input. Doc strings are really helpful for seeing what somethign does: >>> print input.__doc__ input([prompt]) -> value Equivalent to eval(raw_input(prompt)). >>> HTH, Paul Winkler From jbell at iinet.net.au Tue Oct 16 02:51:40 2001 From: jbell at iinet.net.au (John Bell) Date: Tue, 16 Oct 2001 14:51:40 +0800 Subject: PoPy and Large Object Operations Message-ID: <3BCBD8FC.E323B9BA@iinet.net.au> Could someone give me a pointer on how to use PoPy for Binary Large Object operations. Ie import/Export type Ops. Unfortunately the PoPy site is never up and I can find nothing helpful either on the net or in the source. John From rozen at mcn.org Mon Oct 22 00:25:32 2001 From: rozen at mcn.org (Don Rozenberg) Date: Sun, 21 Oct 2001 21:25:32 -0700 Subject: PAGE - A drag and drop GUI Generator Message-ID: <9r1hek0qeg@enews1.newsguy.com> PAGE can now be installed on Win32. PAGE is a tool which helps to create GUI for Python programs. It uses Tk and Tix widgets. PAGE is not an end-all, be-all tool, but rather one that attempts to ease the burden on the Python programmer. It is aimed at the user who will put up with a less-than-general GUI capability in order to get an easily generated GUI. It does not build an entire application but rather is aimed at building a single GUI window. PAGE is based on Stewart Allen's Visual Tcl program. In fact, it is vTcl, with an additional module that generates Python code and some bug fixes. PAGE is built on version 1.2.2 of Visual Tcl, version 8.1.1 of Tix, and Tcl/Tk version 8.3. It supports many Tk widgets and a subset of the Tix widget set. The user will have to acquire and install Tix and tcl to use this program. Page works with Python 2.1.1 and now runs on Linux and Win32. It has been tested on Linux Mandrake 8.1 and Win98. The PAGE web site is http://page.sourceforge.net From tim.one at home.com Fri Oct 5 02:58:14 2001 From: tim.one at home.com (Tim Peters) Date: Fri, 5 Oct 2001 02:58:14 -0400 Subject: Boy do REs ever suck sometimes... In-Reply-To: Message-ID: [Ignacio Vazquez-Abrams] > Here's the problem I'm having with REs. When I use an RE like > '^[0-9]+$' it matches both '123' and '123\n'. How can I get it to not > match the string with the newline? A straightforward way: >>> import re >>> pat = re.compile(r'\d+\Z') >>> pat.match('123') >>> pat.match('123\n') >>> A sicker way: >>> pat = re.compile(r'\d+(?!\n)$') >>> pat.match('123') >>> pat.match('123\n') >>> you-can't-truly-give-up-regexps-before-mastering-them-ly y'rs - tim From wayne at tbnets.com Sun Oct 21 18:20:19 2001 From: wayne at tbnets.com (Wayne Ringling) Date: Sun, 21 Oct 2001 18:20:19 -0400 Subject: Help with gdbm and fcntl.flock Message-ID: I am trying to flock a gbdm file but I can't get it to work. Any ideas really appreciated :) I ripped out all the other stuff to just get this part working. It's a small script to handle ip addrs for a smallish database. But I want to get an exclusive lock on the database while I have it open for reading/writing to. I have two little projects that I need this for if we can get it to work. Is it possible to get a flock on a database object? Here's a snippet from my code: #!/usr/bin/python # import gdbm import fcntl def lock(file): fcntl.flock(file, fcntl.LOCK_EX) def main(): # Open database try: dbase = gdbm.open("remote_addr.dbm","w",0644) except: dbase = gdbm.open("remote_addr.dbm","c",0644) # Now get exclusive flock lock(dbase) if __name__ == '__main__': main() Also I am using Python 2.0 if that makes any diference. Wayne From johnroth at ameritech.net Sat Oct 13 00:03:18 2001 From: johnroth at ameritech.net (John Roth) Date: Fri, 12 Oct 2001 21:03:18 -0700 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <7xsncpxxc6.fsf@ruckus.brouhaha.com> <1002866005.11653@yabetcha.drizzle.com> <9q7spi$9q6$1@slb7.atl.mindspring.net> <9q80c5$1048$1@nntp6.u.washington.edu> <9q84ob$1ls$1@nntp9.atl.mindspring.net> Message-ID: "Jyrinx" wrote in message news:9q84ob$1ls$1 at nntp9.atl.mindspring.net... > > Well, this is precisely what happens in C, right (for variables declared in > the loop)? Personally, I like that kind of strict scoping - it indicates > that a variable introduced inside a loop is there on a temporary basis, and > has no purpose being used outside of it. If the programmer must initialize > the variable before the loop because he intends to use it after the loop, it > makes it clearer to a reader, anyway, since the reader knows immediately > that the loop iterator is somehow an important part of the result of the > loop. Yup. That's exactly why the original example that started this branch is poor programming practice, in general. In the way it was used, it looks like a debugging statement, and there is no good way in Python to say "run this code after the loop, but only if the loop executed at least once." John Roth > Jyrinx > jyrinx at mindspring dot com > > From ignacio at openservices.net Wed Oct 10 02:49:04 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 10 Oct 2001 02:49:04 -0400 (EDT) Subject: PYTHONPATH and embedding python In-Reply-To: <03e401c15155$b2f5ae80$e4cfbfa8@kens> Message-ID: On Tue, 9 Oct 2001, Ken Seehof wrote: > > --- > > char *path, *newpath; > > > > path=Py_GetPath(); > > newpath=strcat(path, ":."); // or ";.", possibly > > PySys_SetPath(newpath); > > free(newpath); > > --- > > Yikes! That doesn't look quite right to me. > > strcat(char *dest, char *src) returns its first argument after concatenating > *src to it. In your example, path points to static storage returned by > Py_GetPath. Your code proceeds to concatenate onto it (blasting away at > static memory reserved for the python library), and then frees it (note that > newpath==path at the end) which it doesn't have a right to do. > > You probably mean something like this: > > // untested code: > char *path, *newpath; > path=Py_GetPath(); > newpath=new char[strlen(path)+4]; > strcpy(newpath, path); > strcat(newpath, ":."); // ":." for unix, or ";." for windows > PySys_SetPath(newpath); > free(newpath); D'oh! Yeah, that's what I meant. I guess I never noticed anything because the module I used to test it is this " big. > from the docs: > char* Py_GetPath () > Return the default module search path; this is computed from the program > name (set by Py_SetProgramName() above) and some environment variables. The > returned string consists of a series of directory names separated by a > platform dependent delimiter character. The delimiter character is ":" on > Unix, ";" on DOS/Windows, and "\n" (the ASCII newline character) on > Macintosh. The returned string points into static storage; the caller should > not modify its value. The value is available to Python code as the list > sys.path, which may be modified to change the future search path for loaded > modules. > > Hmm, I can't seem to find any documentation on PySys_SetPath. I wonder if > it automatically converts the delimiter (":" <=> ";"). An awful lot of C functions in Python/sysmodule.c aren't documented. But no, it doesn't do anything to the passed string other than turn it into a list based on the system-default path delimiter found in Include/osdefs.h. -- Ignacio Vazquez-Abrams From martin.franklin at westgeo.com Thu Oct 18 10:05:51 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Thu, 18 Oct 2001 15:05:51 +0100 Subject: Problems with Tk in Python References: <3BCEBC9A.D655929F@dcs.warwick.ac.uk> <9qmmm5$350o$1@mail1.wg.waii.com> Message-ID: <9qmnfv$2q8e$1@mail1.wg.waii.com> -- snip everything -- one thing I also remembered.... don't try to re-make Python on Solaris in my experience it fails even if you do a make clean I allways trash the directory and re tar -xvf.......... again this is from memory so times may have changed. From barry at zope.com Tue Oct 23 23:10:39 2001 From: barry at zope.com (Barry A. Warsaw) Date: 23 Oct 2001 23:10:39 -0400 Subject: [print >>] None References: Message-ID: >>>>> "BP" == Bjorn Pettersen writes: BP> It's actually part of the magic of print >> None that it BP> prints to sys.stdout (yeah, I know, I wasn't in favor of that BP> either ;-) Neither was I . I lobbied for "print >> None" to be morally equivalent to: class Devnull: ... def write(self, s): pass ... >>> devnull = Devnull() >>> print >> devnull, 'this goes no where' >>> but lost that argument. I've never had a use for current print>>None's semantics but I've had one or two situations where printing to a null sink was handy (e.g. doing verbose prints that get turned off with a --quiet flag). -Barry From skip at pobox.com Wed Oct 10 11:27:53 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 10 Oct 2001 10:27:53 -0500 Subject: LIKE missing in gadfly Message-ID: <15300.26873.902225.536922@beluga.mojam.com> Christophe> In the gadfly doc, the LIKE command is ommitted due to the Christophe> ``re'' module in python. All right, how could I implement Christophe> this on the server side to avoid too many data to transit. Why not just add LIKE support to Gadfly? LIKE uses a very simple wildcard scheme (at least in MySQL, where I use it). "%" is the same as ".*" in regular expressions and "_" is the same as ".", so in the Gadfly code you could (in theory) implement LIKE as a case-insensitive regular expression. "%Dav_\%" would map to the regular expression "(?i).*Dav.%". -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From phd at phd.pp.ru Tue Oct 30 13:43:39 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 30 Oct 2001 21:43:39 +0300 Subject: mimedecode.py version 1.1 Message-ID: <20011030214339.G5711@phd.pp.ru> Hello! mimedecode.py WHAT IS IT Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is very good because it allows us to use apropriate formats/encodings/whatever. Sometimes, though, some unification is desireable. For example, one may want to put mail messages into an archive, make HTML indicies, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary atachmetnts will be much desireable. Here is the solution - mimedecode.py. This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which treated as an RFC822 mesage, and decoded to stdout. If the file is not an RFC822 message the file just piped to stdout one-to-one. If it is a simple RFC822 message it is just decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts decoded. Decoding can be controlled by command-line options. WHAT'S NEW in version 1.1.0 Continuation parameters (RFC2231) are now fully supported. WHERE TO GET Master site: http://phd.pp.ru/Software/Python/#mimedecode Faster mirrors: http://phd.by.ru/Software/Python/#mimedecode http://phd2.chat.ru/Software/Python/#mimedecode Requires: Python 2.0+ (actually tested with 2.1.1), configured mailcap database. Documentation (also included in the package): http://phd.pp.ru/Software/Python/mimedecode.txt http://phd.by.ru/Software/Python/mimedecode.txt http://phd2.chat.ru/Software/Python/mimedecode.txt Detailed DESCRIPTION First, Subject and Content-Disposition headers are examined. If any of those exists, they decoded according to RFC2047. Content-Disposition header is not decoded - only its "filename" parameter. Encoding header's parameters is in violation of the RFC, but widely deployed anyway, especially in the M$ Ophice GUI (often referred as "Windoze") world, where programmers are usually ignorant lamers who never even heard about RFCs. Correct parameter encoding specified by RFC2231. This program decodes RFC2231-encoded parameters. Then the body of the message (or current part) decoded. Decoding starts with looking at header Content-Transfer-Encoding. If the header specifies non-8bit encoding (usually base64 or quoted-printable), the body converted to 8bit. Then, if its content type is multipart (multipart/related or multipart/mixed, e.g) every part recursively decoded. If it is not multipart, mailcap database is consulted to find a way to convert the body to plain text. (I have no idea how mailcap could be configured on said M$ Ophice GUI, please don't ask me; real OS users can consult my example at http://phd.pp.ru/Software/dotfiles/mailcap.html). The decoding process uses first copiousoutput filter it can find. If there is no filter the body just passed as is. Then Content-Type header consulted for charset. If it is not equal to current default charset the body text recoded using Unicode codecs. Finally message headers and body flushed to stdout. OPTIONS -h --help Print brief usage help and exit. -V --version Print version and exit. -c Recode different character sets in message body to current default charset; this is the default. -C Do not recode character sets in message body. -f charset Force this charset to be the current default charset instead of sys.getdefaultencoding(). -d header Add the header to a list of headers to decode; initially the list contains headers "From" and "Subject". -D Clear the list of headers to decode (make it empty). -p header:param Add the (header, param) pair to a list of headers' parameters to decode; initially the list contains header "Content-Disposition", parameter "filename". -P Clear the list of headers' parameters to decode (make it empty). -b mask Append mask to the list of binary content types; if the message to decode has a part of this type the program will pass the part as is, without any additional processing. -e mask Append mask to the list of error content types; if the message to decode has a part of this type the program will raise ValueError. -i mask Append mask to the list of content types to ignore; if the message to decode has a part of this type the program will not pass it, instead a line \nMessage body of type `%s' skipped.\n" will be issued. -t mask Append mask to the list of content types to convert to text; if the message to decode has a part of this type the program will consult mailcap database, find first copiousoutput filter and convert the part. The last 4 options (-beit) require more explanation. They allow a user to control body decoding with great flexibility. Think about said mail archive; for example, its maintainer wants to put there only texts, convert Postscript/PDF to text, pass HTML and images as is, and ignore everything else. Easy: mimedecode.py -t application/postscript -t application/pdf \ -b text/html -b 'image/*' -i '*/*' When the program decodes a message (or its part), it consults Content-Type header. The content type is searched in all 4 lists, in order "text-binary-ignore-error". If found, appropriate action performed. If not found, the program search the same lists for "type/*" mask (the type of "text/html" is just "text"). If found, appropriate action performed. If not found, the program search the same lists for "*/*" mask. If found, appropriate action performed. If not found, the program uses default action, which is to decode everything to text (if mailcap specifies filters). Initially all 4 lists are empty, so without any additional parameters the program always uses the default decoding. ENVIRONMENT LANG LC_ALL LC_CTYPE Define current locale settings. Used to determine current default charset (if your Python is properly installed and configured). BUGS The program may produce incorrect MIME message. The purpose of the program is to decode whatever is possible to decode, not to produce absolutely correct MIME output. The incorrect parts are obvious - decoded Subject headers and filenames. Other than that output is correct MIME message (tested with mutt mail reader). The program does not try to guess whether the headers are correct. For example, if a message header states that charset is iso8859-5, but the body is actually in koi8-r - the program will recode the message to wrong charset. AUTHOR Oleg Broytmann COPYRIGHT Copyright (C) 2001 PhiloSoft Design LICENSE GNU GPL NO WARRANTIES This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. SEE ALSO mimedecode.py home page: http://phd.pp.ru/Software/Python/#mimedecode Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From ullrich at math.okstate.edu Fri Oct 19 11:07:17 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Fri, 19 Oct 2001 15:07:17 GMT Subject: Desperate help required for Python assignment References: Message-ID: <3bd040b0.2152397939@news> On Fri, 19 Oct 2001 10:47:58 +1000, "Delaney, Timothy" wrote: >> From: ullrich at math.okstate.edu [mailto:ullrich at math.okstate.edu] >> On 17 Oct 2001 00:47:07 -0700, nachiket_gole at hotmail.com (Nachiket) >> wrote: >> >> >I am new to Python doing a crash course in University. I have a >> >assignment to submit in two days the specifications of which are: >[snip] >> > Please can some of the Gurus on this newsgroup help me out with a >> >working solution as with my limited knowledge i am no position to >> >handle this assignment in two days. >> >> Actually it's a trick question - this cannot be done in Python. >> Some of your classmates will be handing in stuff that doesn't >> quite do this, hoping for partial credit. You should tell the >> teacher you've determined it's impossible - I'm sure he'll be >> properly impressed. > >Hah! And I thought some people may possibly think I was being a bit harch on >the fellow ... What, you mean this _can_ be done in Python? Huh. You'd think if it was possible in Python then the language would come with a module that would... um, never mind. > I appear to have been the most helpful of everyone :) > >Just goes to show - despite the extreme friendliness and tolerance on this >list/newsgroup, we're still a bunch of competent techies who don't like >spongers ... Probably most of "us" are - me, I'm not a techie at all, competent or not, I'm a professor who gets irritated at people trying to get out of doing their homework. (If they got people to take the exams for them as well I wouldn't mind so much, then I wouldn't have to deal with the kids complaining about grades...) >Tim Delaney > From jdunnett at uoguelph.ca Sun Oct 28 23:03:39 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Sun, 28 Oct 2001 23:03:39 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> <3BDCC4C9.B0597DF1@uoguelph.ca> <8djpttobn2i18avnq3817bmg1ua6eavq8r@4ax.com> <3BDCD224.AA105B1E@uoguelph.ca> Message-ID: <3BDCD51B.656F38ED@uoguelph.ca> Jeff Dunnett wrote: > "John S. Yates, Jr." wrote: > > > On Sun, 28 Oct 2001 21:54:01 -0500, Jeff Dunnett wrote: > > > > >Emile van Sebille wrote: > > > > > >> "Jeff Dunnett" wrote in message > > >> news:3BDCA674.FF268D0E at uoguelph.ca... > > >> > > > >> > [..SNIP..] > > >> > quite a lot of fallowers who like Python. > > ^^^^^^^^^ > > >> > > > >> > > >>

> > >> > > >> Hopefully, they haven't simply put themselves out to pasture... > > > > > >I am not sure what I mean by your comment? > > > > Emile was punning on "fallow" (as in to let a pasture lie fallow) > > versus "follow". > > Duh. What an idoit I am. Poor spelling you can tell I am not an English major or > I probably would have picked up on the ocmment. > > Jeff That should say comment. Jeff From tim.one at home.com Wed Oct 10 01:49:02 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 10 Oct 2001 01:49:02 -0400 Subject: Curious assignment behaviour In-Reply-To: <7x669o7r4k.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin, on an expression assignment operator] > Why on earth does it have to be different from the statement assignment > operator? What's wrong with > > while x=get_next(): whatever(x) > > I just don't buy the rationale that using = instead of == is a big source > of bugs. In 25 years of hacking C code, I think I've seen that error > maybe once or twice. I suggest you're highly atypical here, Paul. This was the very first of the gotchas listed in Andrew Koenig's classic (late 80s) "C Traps and Pitfalls", and has made nearly every list of C "deadly sins" I've seen since then. I've wasted weeks of my own life helping people track this error down in C, too often under extreme time or customer pressure. The experience of the other folks at PythonLabs is similar, so even if it's a disease you're immune to, you can be sure this will never go in. At my last employer, we had a miserable bug that went away in a debug build, and analysis all but assured that *if* the only plausible cause were actually occurring, a particular assert would have triggered in the debug build. But the assert didn't trigger, and a run under the debugger confirmed the vrbl had its asserted value, so people looked elsewhere. Oops! The assert turned out to be the perversely self-fulfilling: assert(i = 1); and multiple senior programmers with with many decades of industrial C experience had stared at that multiple times without realizing the mistake. A complicating factor was that the compiler complained about a raw "(i = 1)" in control-structure contexts, so perhaps people were lulled into a false security about this trap. It only takes one of those to sour you on the idea for life. dozens-to-spare-ly y'rs - tim From stephen_purcell at yahoo.com Mon Oct 29 03:15:59 2001 From: stephen_purcell at yahoo.com (Steve Purcell) Date: Mon, 29 Oct 2001 09:15:59 +0100 Subject: [ANN] 'dbdoc' database schema documentation generator Message-ID: <20011029091559.A3900@publishers-market.com> If you have ever wanted javadoc-style HTML documentation for your database schemas, or a consistent way of programatically inspecting a database schema, then 'dbdoc' may interest you. This small project defines a simple Python API for inspecting database schemas, and uses it to generate documentation (optionally incorporating descriptive text placed in an auxiliary file). Support is initially provided for PostgreSQL. Would anyone like to volunteer to implement the schema introspection API for another database? If so, get in touch! To find out more, please visit http://dbdoc.sourceforge.net/ , where dbdoc has just seen its fourth release. Best wishes to all, -Steve -- Steve Purcell, Pythangelist Get testing at http://pyunit.sourceforge.net/ From sdm7g at Virginia.EDU Fri Oct 5 10:44:21 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Fri, 5 Oct 2001 10:44:21 -0400 (EDT) Subject: Compiling 2.1.1 on Mac OS X 10.1 - test failures In-Reply-To: <0110051145150H.04291@ike> Message-ID: On Fri, 5 Oct 2001, Richard Jones wrote: > Compiling went OK. Then I tried "make test". Oh dear. > > test_largefile: took about 2.5 minutes. Top reported that it was mostly > "stuck" and occasionally "running" - using very little CPU and no disk that I > could detect (by the scientific aural detection process ;) When it was > finished, it printed the message "@test exists: 0". No idea if this normal - > my Linux machine doesn't have large file support. I never have enough free space on my iBook for test_largefile to complete, so I don't know what SHOULD happen. > test_re: got a segfault (with -O3, -O2 and no optimisation at all) This one is a known problem. You have to set the stack limit in the shell with "limit stack 4096" (for tcsh -- 'ulimit' in bash or sh). Nobody has yet figured out how to set this limit for the program -- I've tried some of the linker switches which would seem to control this, but it still seems to need to be set in the shell. -- Steve Majewski From dale at riverhall.NOTHANKS.co.uk Wed Oct 17 13:51:03 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 17 Oct 2001 18:51:03 +0100 Subject: Conditional Expressions don't solve the problem References: Message-ID: > >Something like: > >while foo != terminating_condition; given foo = some_long_expression: > body_of_loop() > >or maybe "where": > >while foo != terminating_condition; where foo = some_long_expression: > body_of_loop() > Sorry but these don't work for me. Given that foo is still quoted twice, it doesn't really buy you much. -- Dale Strickland-Clark Riverhall Systems Ltd From graz at mindless.com Fri Oct 19 05:25:44 2001 From: graz at mindless.com (Graham Ashton) Date: Fri, 19 Oct 2001 09:25:44 GMT Subject: dynamic call of a function References: <3BCFE666.C8C6136C@c-s.fr> Message-ID: In article <3BCFE666.C8C6136C at c-s.fr>, "anthony harel" wrote: > I have got a string that contains the name of the function I want to > call but I don't want to do something like this : > [snip] > Is it possible to do sommething like that : ch = "foo" > apply(ch, ( ))??? I would have thought that in combination with getattr(), apply() would do the job for you. -- Graham From jdunnett at uoguelph.ca Mon Oct 29 18:45:06 2001 From: jdunnett at uoguelph.ca (Jeffrey Dunnett) Date: Mon, 29 Oct 2001 18:45:06 -0500 (EST) Subject: python binary search In-Reply-To: Message-ID: Aye I will watch dose typos :) Jeff On Tue, 30 Oct 2001, Delaney, Timothy wrote: > > The proof reading and the spell checker can both be done. I will use > > them in the future > > Just a note - glad to see you are taking this in the spirit it was intended > :) > > Now, just watch for those tyops ... > > Tim Delaney > From uwe at rocksport.de Tue Oct 2 15:01:36 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 2 Oct 2001 19:01:36 GMT Subject: trying sockets References: <9pce64$5gnu5$1@hades.rz.uni-sb.de> Message-ID: <9pd2ug$56bs7$1@hades.rz.uni-sb.de> Steve Holden wrote: | This actually looks reasonable. Of course, there's lots more to do... | As another poster pointed out, Python does include libraries for client-side | and server-side HTTP, but they can be a little opaque at times. There's | nothing wrong with trying to hack up some simple scripts yourself, although | you will find there is much to be learned from the library code. Good luck! thanks a lot. my aim was not primarly to download a web-page, i just wanted to play with the socket-stuff. now i know how to send via a socket. yours, uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From mlh at idi.ntnu.no Thu Oct 4 18:12:54 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 5 Oct 2001 00:12:54 +0200 Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> Message-ID: <9pimt6$cc9$1@tyfon.itea.ntnu.no> > Cliff Wells writes: [snip] > This may be off topic but what does it mean to release a python module/package > under LGPL? > > An import is not a linking ... so does it mean I can't use it in a commercial > product? I'd like to think I could use it if I released any changes I made to > the module/package - but I don't think thats the case. Hardly... Placing the line import some_gnu_module in your own code wouldn't have anything to do with the license of some_gnu_module at all. As long as you are allowed to distribute some_gnu_module (separately from your software, as it will be unless you cut-and-paste it into your code) there shouldn't be any problem. It's like if I did os.system('some_gnu_program') Certainly that wouldn't infect my program with a gnu license... -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From warkid at storm.ru Fri Oct 26 04:17:38 2001 From: warkid at storm.ru ( Kerim Borchaev ( WarKiD ) ) Date: Fri, 26 Oct 2001 12:17:38 +0400 Subject: Can't copy iterator object In-Reply-To: <7da8d8f8.0110252306.17ec3d7a@posting.google.com> References: <7da8d8f8.0110252306.17ec3d7a@posting.google.com> Message-ID: <1512.011026@storm.ru> Hello sebastien, 2001-10-23 03:39:03 PST Michael Hudson explained: >> Why iterators can't be copied? > > Think about > >>>> i = iter(sys.stdin) >>>> j = iter(i) > > when sys.stdin is attached to a pipe. > > or iter(iter(g())) for some generator g. > > It just ain't possible in general. I can agree that one shouldn't be able to copy "non-copiable" iterator. Like file iterator. But why not leave it to the particular iterator implementation? So as file's iterator to be "non-copiable" but list's one - copiable? Best regards, Kerim mailto:warkid at storm.ru Friday, October 26, 2001, 11:06:54 AM, you wrote: >> I'm not supposed to do so? This could be useful... >> >> Python 2.2b1 (#25, Oct 19 2001, 11:44:52) [MSC 32 bit (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> i = iter([1,2,3]) >> >>> import copy >> >>> copy.copy(i) >> Traceback (most recent call last): >> File "", line 1, in ? >> File "C:\Python22\lib\copy.py", line 84, in copy >> y = _reconstruct(x, reductor(), 0) >> File "C:\Python22\lib\copy_reg.py", line 56, in _reduce >> state = base(self) >> TypeError: cannot create 'iterator' instances s> I had posted the same question few days before: here are the answers s> http://groups.google.com/groups?hl=en&frame=right&th=6499660bd77fd7fc&seekm=7da8d8f8.0110230006.36933486%40posting.google.com#link1 s> Maybe a potential new entry in the FAQ? From t at chabry.caltech.edu Mon Oct 1 11:13:42 2001 From: t at chabry.caltech.edu (Titus Brown) Date: 1 Oct 2001 08:13:42 -0700 Subject: Python embedding & question about autoconf and dynamic linking References: Message-ID: <9pa176$v76$1@chabry.caltech.edu> In article , Mads Bondo Dydensborg wrote: >> >So, my first question is if there are any autoconf macros out there that >> >will work for me, sort of like a AM_PATH_SDL macro? >> > [munch] >> >> I haven't found one in distutils, either, which seems like a natural >> place for them. >> >> Please let me know if you get a list sent to you privately; I'm very >> interested in this for 'configure'ing PyWX... > >No luck so far. (I am quoting most of my original post in case someone in >knowledge will notice). > >I will continue to hack on the KDE_CHECK_PYTHON script - what are you >using for PyWX? *blush* Nothing. "Hey, does it compile? Great! Oops. Missing symbols? Post to the list." >> >My next question is with respect to dynamicly linking to the python >> >interprenter, when embedding it. >> > [munch] >> >> For older versions, you should be able to do something like this: >> >> make CFLAGS=-fpic >> mkdir .shared >> cd .shared >> ar xv ../libpython.a >> gcc -shared -o ../libpython.so *.o > >Hmm. So, I should actually be able to create a .so on an endusers machine, >_if_ the original python installation was built with -fpic. Otherwise I >have to recompile the python installation. right. >Not a nice thing. Are there any particular reason that python does not >"come as a so" on Linux and Solaris? (Or other .so enabled platforms). Err, the FAQ entry had something to say about that, too. But it's gone now. I think the answer was that most people didn't need it. --titus From grahamd at dscpl.com.au Mon Oct 15 20:49:48 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 15 Oct 2001 17:49:48 -0700 Subject: J2EE equivalent in Python References: Message-ID: gerhard.nospam at bigfoot.de (Gerhard H?ring wrote in message news:... > On 12 Oct 2001 11:51:36 +0100, Robin Smith wrote: > >I like J2EE but I am also an open source fan. I don't like what I read > >about Sun and restricting Java - > >http://www.onjava.com/pub/a/onjava/2001/10/10/osjava.html . > > > >Is there anything similar to J2EE for python? You might consider having a look at OSE. It embodies a number of features which have parallels to what can be done in J2EE. Important thing to remember with OSE though, is it is more the framework that underlies being able to do such things, so don't expect a plugin solution which does exactly what you want, you will need to build on it. > Take the following with a grain of salt, my experiences with J2EE are > limited to swearing because of incomprehensible error messages from > Persistence Powertier ;-) > > J2EE is a bunch of APIs thrown together, right? So we can examine the > APIs one for one. > > Servlets/JSP: Python has a gazillion equivalents. There's a page that > compares them all, but I don't have the URL atm. OSE has a HTTP servlet framework with a mechanism for defining plugins as to how to handle certain file types stored in the file system. Eg., allowing one to define servlets written in Python in files stored in the file system. In other words, much like what all the other systems can do. :-) There is no JSP equivalent or other HTML templating system provided at the moment, but research is being done on this in respect of what sort of system is able to best make use of the features of OSE. It isn't that difficult to use a system like Cheetah in conjunction with OSE servlets. > Distributed sytems: There are several ORBs. I like omniORBpy, for > example. Then there are several SOAP > implementations. And easy-to-use Python-only > solutions like PyRO. And XML-RPC. OSE has its own underlying distributed message oriented communications framework, with an abstraction for representing service objects. Service objects can communicate amongst themselves and servlets can be set up as transient service objects so they can make calls to other service objects as necessary. See examples at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81615 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81614 The communications framework uses a model whereby each process in the application is connected at all times, however, it is also possible to create gateways for RPC over HTTP protocols such as XML-RPC and SOAP. This allows remote clients to call direct into any exposed service objects. See example at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81612 > JDBC: Python DB-API 2.0. In OSE it is relatively simple to encapsulate access to a database as a service object and for that then to be accessible from anywhere in the application or remote via XML-RPC or SOAP. See example at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81613 > Persistence (EJB): ZODB (included in ZOPE or available standalone). > > Object-Relational Mapping (JDO): Not available AFAIK. Don't really know what that does so don't know. :-) > ZOPE probably comes closest to a J2EE server. It has something called > ZEO if you need to scale up. > > If you're adventurous, you can of course mix and match the APIs you > like. And btw. there are also several ZOPE-light's: WebWare, SkunkWeb, > Aquarium, ... I only tried WebWare and liked it. As well as the above examples, there are various other examples on the OSE web site. Also note that you aren't restricted to using just Python with OSE, in fact its core is C++ and as such service objects can be defined in C++ as well. Unfortunately, this use of C++ and the size of the package seems to turn people off using it just for the Python interfaces. :-( OSE could in time be quite useful if a large library of reusable service objects were available much like there are in the way of Java beans. This would allow applications to be quite quickly put together. Right now though, still in the process of getting Python developers actually interested in the package. Anyway, site for OSE is: http://ose.sourceforge.net There are over 100 pages of hand written documentation for the Python interfaces which can viewed on the site or as a PDF at: http://ose.sourceforge.net/python-manual.pdf OSE is released as Open Source under the QPL. From uouhet at microservice.club24.co.uk Tue Oct 16 15:11:35 2001 From: uouhet at microservice.club24.co.uk (uouhet at microservice.club24.co.uk) Date: 16 Oct 2001 19:11:35 GMT Subject: Dont hesitate on this one 7469 Message-ID: <3bcc8667$5$8512$ed9e5944@reading.news.pipex.net> 80 Million Fresh email addresses Available NOW with free Mass Mailer and other essential applications. Best prices around. Fantastic Special Offer For more info call UK- 0906 664 2021 All others- 00 44 906 664 2021 Select option 2 from menu when directed. Lines get busy at peak times - keep trying We accept all major credit cards - Delivery normaly 24hrs tkrtvuurntzexfiutsqfjssbesvseuktfrgdmnmdsoncbjgtlvstokrfjzwplcbhicnpdreulbdxoo From tim at zope.com Fri Oct 12 19:01:38 2001 From: tim at zope.com (Tim Peters) Date: Fri, 12 Oct 2001 19:01:38 -0400 Subject: Loop-and-a-half (Re: Curious assignment behaviour) In-Reply-To: <3BC769CC.9020403@destiny.com> Message-ID: [Michael Chermside, on a conditional expression] > ... > As before, if anyone else feels strongly that they'd like to contribute > (other than the excellent comments several folks already made), they > should email me. If people sign off on taking "then" as a new keyword, I think the chances are good that we could get x = if e1 then e2 else e3 into 2.2b1. That's the only obvious spelling, hence the only truly Pythonic way to spell it. Other languages spelling it that way range from Algol-60 (Guido's first intense language affair) to Haskell. > hoping-that-less-speed-and-more-thinking-leads-to-a-better-design- > ly yours, less-thinking-will-get-there-faster-ly y'rs - tim From chris_moffitt at yahoo.com Sat Oct 20 22:02:52 2001 From: chris_moffitt at yahoo.com (Chris Moffitt) Date: Sun, 21 Oct 2001 02:02:52 GMT Subject: Automatically resume a download w/ urllib? Message-ID: I'm trying to develop a small application (mostly for Windows if that matters), than can download and install binary files stored on a web server. I've been able to get urllib to download the file just fine, but what I would like to do is be able to resume a download if it is cancelled for some reason. In other words, if I've downloaded 50k of a 200k file, I'd like to just download the remaining 150k. Is this possible using HTTP and Apache? If not, what about FTP? If neither of those, does that mean I need to write my own pseudo-server of some sort that can spool out the file appropriately? If it helps, here's my non-working code (ripped from the Python Std Library) that contains a seek statement. #!/usr/local/bin/python import urllib, os dlFile = "sm.tar.gz" webFile = urllib.urlopen("http://192.168.1.4/sm-cvs-20010519.tar.gz") existSize = 0 if os.path.exists(dlFile): outputFile = open(dlFile,"ab") existSize = os.path.getsize(dlFile) else: outputFile = open(dlFile,"wb") n = 0 while 1: if existSize > 0: webFile.seek(existSize + 1) <--- Non-working piece data = webFile.read(8192) if not data: break outputFile.write(data) n = n + len(data) webFile.close() outputFile.close() Thanks, Chris From thecalm at NOSPAM.btinternet.com Thu Oct 4 18:23:56 2001 From: thecalm at NOSPAM.btinternet.com (G. Willoughby) Date: Thu, 4 Oct 2001 23:23:56 +0100 Subject: Tkinter PhotoImage Class??? Message-ID: <9pinf8$p3i$1@uranium.btinternet.com> Has anyone got a piece of code to explain to me how to use the Tkinter PhotoImage Class to display a .jpg inside a Tkinter Canvas object? The Tkinter docs are not finished. Thanks, G. Willoughby. From sholden at holdenweb.com Tue Oct 9 14:59:17 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 9 Oct 2001 14:59:17 -0400 Subject: TROJAN ALERT! (JS/Loop) References: <3bc343a0.fba6e0c5.c0a801.00.R@drsolomon.com> Message-ID: I would have characterised this attack as a GUI denial-of-service, not a Trojan horse. A Trojan horse is an exploit which collects information from an unsuspecting user and stores or transmits it for use by the third party. Such misinformation does not lend credibility. The code involved was a simple infinite alert loop. Other newsgroups I do not read were removed from this posting. Sheesh, now we're getting *bots* posting to c.l.py [sorry, Tim ]. regards Steve -- http://www.holdenweb.com/ "Dr Solomon's Virus Patrol" wrote in message news:3bc343a0.fba6e0c5.c0a801.00.R at drsolomon.com... > WARNING! A trojan has been found in an article posted to > the following newsgroup(s): > comp.lang.javascript, alt.config, comp.lang.perl.misc, comp.lang.python, > comp.os.linux.misc > > Message header follows: > > >Message-Id: > >From: "dvus" > >Subject: YOU ARE ALL GAY! > >Date: 09 Oct 2001 15:11:40 GMT > > Dr Solomon's FindVirus/VirusScan report follows: > > Dr Solomon's FindVirus IN-HOUSE version. Copyright (c) 1999 Network Associates Inc. > Virus data file v9999 created Oct 08 2001 > Scanning for 58978 viruses, trojans and variants. > > [HTML part] ... Found the JS/Loop trojan !!! > > You can download a free evaluation (yet fully functional) copy of > the latest released version of Dr Solomon's FindVirus/VirusScan from > the following locations: > > WWW: http://www.nai.com/naicommon/buy-try/try/products-evals.asp > CompuServe: GO DRSOLOMON or GO MCAFEE > AOL: SAFETYONLINE > > IMPORTANT! The trojan has been detected by the latest IN-HOUSE version of > Dr Solomon's FindVirus/VirusScan. As new viruses and trojans appear at the rate > of several hundreds a month, the latest RELEASED version of FindVirus/VirusScan > might be unable to detect this particular trojan. If you have downloaded the above > file and your copy of FindVirus/VirusScan does not detect the trojan in it, > contact Network Associates Technical support and ask for the extra driver > to detect the JS/Loop trojan. > > -- > Dr Solomon's Virus Patrol UK Support: support at drsolomon.com > NAI Anti-Virus Emergency Response Team US Support: support at nai.com > WWW: http://www.mcafeeb2b.com UK Tel: +44 (0) 1296 318700 > CompuServe: GO DRSOLOMON USA Tel: +1 408 988-3832 From skip at pobox.com Mon Oct 15 20:21:32 2001 From: skip at pobox.com (Skip Montanaro) Date: Mon, 15 Oct 2001 19:21:32 -0500 Subject: re.findall() is skipping matching characters In-Reply-To: References: Message-ID: <15307.32140.398906.195270@beluga.mojam.com> Fredrik> try using a non-capturing group instead: (?:x) instead of (x) Gustaf> Nah, enough of Python peculiarities already. It's hard enough to Gustaf> learn regexes without adding a strong Python flavor to it. ;-) Just to set matters straight, that's not a Python peculiarity. Python gets most or all of its regular expression syntax from Perl's implementation. If you're on a Unix machine with a reasonable Perl installation, "man perlre" may be a useful adjunct to other regular expression documentation you might have handy. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From weismann at netvision.net.il Mon Oct 29 06:31:44 2001 From: weismann at netvision.net.il (Amit Weisman) Date: Mon, 29 Oct 2001 13:31:44 +0200 Subject: Is there a place holding all the messages to this list ? Message-ID: <003101c1606d$52b6ad90$9597003e@rashome> Is there a place holding all the messages to this list ? ---------------------------------------------------------------- Weisman Amit 11 Rupin st. Holon 58344 Israel Tel : 050397330 weismana at cs.bgu.ac.il -------------- next part -------------- An HTML attachment was scrubbed... URL: From madsdyd at challenge.dk Sun Oct 7 14:42:30 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Sun, 7 Oct 2001 20:42:30 +0200 (CEST) Subject: (Solution) Re: Problem with embedding - can only make about 150 calls... In-Reply-To: <15296.41255.765055.373652@beluga.mojam.com> Message-ID: On Sun, 7 Oct 2001, Skip Montanaro wrote: > > Mads> I found a solution > >> static PyObject * MyTest(PyObject * self, PyObject *args) { > >> return Py_None; > Mads> return Py_BuildValue(""); > >> } > > One problem with your Py_None return is that you didn't Py_INCREF it first. > Over time Py_None's refcount may well have dropped to zero. Blammo! > Py_BuildValue("") returns an INCREF'd object. Yes, I understand this now. Boy do I feel silly. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk You know you're a Linux geek when... You can reconstruct your fstab from scratch, and not even think about it. - segfault From ignacio at openservices.net Thu Oct 4 18:00:47 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 4 Oct 2001 18:00:47 -0400 (EDT) Subject: Mutable default values for function parameters In-Reply-To: <001001c14d1e$fe4b2620$b503a8c0@activestate.ca> Message-ID: On Thu, 4 Oct 2001, Brian Quinlan wrote: > Here is my proposed expression: > > d = ((d is not None and [d]) or [[]])[0] > > Here is the test: > > def test(d = None): > return ((d is not None and [d]) or [[]])[0] > > assert test() == [] > assert test(None) == [] > assert test(0) == 0 > assert test('') == '' > assert test(5) == 5 > assert test([1,2,3]) == [1,2,3] > > I believe that those are the semantics that you are looking for? And > so easy to understand... This is your brain on drugs. Any questions? ;) -- Ignacio Vazquez-Abrams From dkuhlman at rexx.com Tue Oct 16 18:40:46 2001 From: dkuhlman at rexx.com (Dave Kuhlman) Date: 16 Oct 2001 17:40:46 -0500 Subject: Building a lib-wrapper, first step References: <3BCC198D.5010505@strakt.com> <7xwv1v4xm9.fsf@ruckus.brouhaha.com> Message-ID: <1003272722.5159@rexx.com> Paul Rubin wrote: > > Rikard Bosnjakovic writes: >> I've got a small library (Linux) and I want to create some >> wrapper-module so Python can use it. I've never done this before, so >> I'm looking for some tutorial or such for this purpose. >> >> Is there any documents describing this somewhere, step-by-step or something? > > www.swig.org Also see the example in "Extending and Embedding the Python Interpreter" in the standard Python documentation. - Dave -- Dave Kuhlman dkuhlman at rexx.com -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From daniel.dittmar at sap.com Wed Oct 10 12:55:01 2001 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Wed, 10 Oct 2001 18:55:01 +0200 Subject: Assigning to lists with arbitrary names References: <3BC35131.C9AB1393@motorola.com> Message-ID: <9q1um0$l14$1@news1.wdf.sap-ag.de> > Here's the problem: I want to name each list list00 to list99. I don't > want to do list[0] to list[99] (since each list is actually a list of > lists, and I'd like to avoid a list of lists of lists :). You could use a dictionary with keys 'list00' to 'list99', but I don't think having a dictionary of lists of lists is that much better. Why not subclass UserList for each kind of list? Then you could at least distinguish between the different levels. Daniel From mwh at python.net Tue Oct 30 05:43:59 2001 From: mwh at python.net (Michael Hudson) Date: Tue, 30 Oct 2001 10:43:59 GMT Subject: Python still remembers script after change and save References: <1004382387.8324.0.nnrp-07.c1c3e128@news.demon.co.uk> Message-ID: Cliff Wells writes: > On Monday 29 October 2001 11:06, Paul Brian wrote: > > > I occasionally come across a situation where I have changed a file, rerun > > the file in python but python still produces an error, quoting the original > > file in the error string > > Are you talking about the main script or a module you are importing? If you > modify a module and import it again, you will still have the original module. > You must call reload(module) to force Python to reinterpret the module And if you're doing "from module import foo" you need to type >>> import module >>> reload(module) >>> from module import foo Cheers, M. -- And then the character-only displays went away (leading to increasingly silly graphical effects and finally to ads on web pages). -- John W. Baxter, comp.lang.python From h.jehadalwan at student.kun.nl Sat Oct 6 11:42:46 2001 From: h.jehadalwan at student.kun.nl (Husam) Date: Sat, 06 Oct 2001 17:42:46 +0200 Subject: Saving variable value to a file does not work!!!! References: <3BB74291.CB898293@sci.kun.nl> Message-ID: <3BBF2675.D9B2332F@student.kun.nl> Alright John, now it works. Thanks a lot. Husam John Roth wrote: > "Gerhard H?ring" wrote in message > news:mailman.1001867134.25402.python-list at python.org... > > On Sun, Sep 30, 2001 at 06:04:33PM +0200, Husam wrote: > > > Hi friends, > > > Im a newbie and trying to save the value of variable 'counter' to a > > > file, but it does not work. > > > The code Im usig is: > > > > > > > > > for line in lines: # I'm reading from file: test2.txt. > > > One of it's lines contain: ID 5. > > > string.split(line) > > > if line[0:2]=='ID': > > > counter=int(line[3]) > > > output=open('test2.txt','a') # Hier Im opening the same file for > > > append. > > > output.write(counter +1) # This is the trouble making > > > line! > > > output.close() > > > > Btw. the string.split(line) doesn't do anything in your case, if you > > want to store the output of the split function, you can use something > > like "mylist = string.split(line)". But now the the real problem. > > > > > The error message I get when this code is run: > > > > > > Traceback (innermost last): > > > File "./script.py", line 23, in ? > > > output.write(counter+1) > > > TypeError: read-only buffer, int > > > > You can't write any ints with the write function. But you can write > > strings. Just do > > > > output.write(str(counter + 1)) > > > > I acknowledge this is a bit strange. And I also don't know the reason > > why the conversion to string doesn't happen automatically, like with the > > print statement. > > Print is for formatted output that is intended to be read by people > (usually programmers.) Write is for output that is intended to be read back > by a program. > > When you're writing to a file, you want to be able to read it back, right? > If the system converted integers to strings, then you would need to put > delimiters and all sorts of other stuff onto the file to be able to parse it > when you read it. That's what Basic did, and anybody who works in > that language can tell you exactly how ugly it gets. > > I'd much rather have the virtue of simplicity - what's on disk is exactly > what I have in memory. Period. When I write a line, I want it read back > the same way, and if that means that all I can write is strings, then so be > it. > > > > > Gerhard > > -- > > mail: gerhard bigfoot de registered Linux user #64239 > > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 > > public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 > > reduce(lambda x,y:x+y,map(lambda > x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) > > From paul1brian at yahoo.com Mon Oct 29 14:06:24 2001 From: paul1brian at yahoo.com (Paul Brian) Date: Mon, 29 Oct 2001 19:06:24 -0000 Subject: Python still remembers script after change and save Message-ID: <1004382387.8324.0.nnrp-07.c1c3e128@news.demon.co.uk> All, I am (fairly) sure I have read this before, but cannot find the posts again. I occasionally come across a situation where I have changed a file, rerun the file in python but python still produces an error, quoting the original file in the error string Eventually the only workaround is to shutdown and restart the IDE or python (PythonWin usually for me) Does anyone a) Have an explanation for this (still hazy on the internals of python) b) Have a good workaround on b) I seem to remeber someone suggesting deleting references to everything in __main__.__dict__ that did not begin with __ however that seems kludgy or even dangerous. Thanks in advance.... Paul Brian From robin at jessikat.fsnet.co.uk Tue Oct 16 09:39:08 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 16 Oct 2001 14:39:08 +0100 Subject: fast sub list operations In-Reply-To: <15308.11525.102304.624520@beluga.mojam.com> References: <15308.11525.102304.624520@beluga.mojam.com> Message-ID: In message <15308.11525.102304.624520 at beluga.mojam.com>, Skip Montanaro writes > > .... > >I think most people will point you to NumPy. > > Robin> ... I don't seem to have an interlace to get back to the original > Robin> list format. > >Check out the zip builtin function: > > >>> zip([1,2,3],[7,8,9]) > [(1, 7), (2, 8), (3, 9)] > I know about NumPy and like it a lot, but it's a bit heavyweight for what we need. I also know about zip and apart from there being no unzip it doesn't join up my list which should look like [1,7,2,8,3,9]. -- Robin Becker From richard at bizarsoftware.com.au Thu Oct 4 23:36:40 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 5 Oct 2001 13:36:40 +1000 Subject: Compiling 2.1.1 on Mac OS X 10.1 - test failures In-Reply-To: References: <0110051145150H.04291@ike> Message-ID: <0110051336400J.04291@ike> On Friday 05 October 2001 13:21, Steve Holden wrote: > Richard: > > You should go to http://python.sf.net and report these bugs. Follow the > link to the project page, then select bugs. There's a "Submit New" link > close to the top of the page. Yep, was going to do that - just wanted to share with the community a bit a see if I would be able to submit useful information with the bugs :) Richard From BPettersen at NAREX.com Wed Oct 31 16:07:39 2001 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 31 Oct 2001 14:07:39 -0700 Subject: Is round() broken? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158C10@admin56.narex.com> > From: Joseph Wilhelm [mailto:jwilhelm at outsourcefinancial.com] > > Hello again everybody! > > I'm having some troubles with round() now... either I'm doing > it completely wrong or round() is. But here's what I'm getting. > > >>> round( 43583.010000000002, 2 ) > 43583.010000000002 [snip] http://python.sourceforge.net/devel-docs/tut/node14.html -- bjorn From tdelaney at avaya.com Tue Oct 2 23:42:55 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 3 Oct 2001 13:42:55 +1000 Subject: Python is better than free (was Re: GNU wars again) Message-ID: > From: Chris Watson [mailto:opsys at voodooland.net] > On Tuesday 02 October 2001 09:54 pm, Delaney, Timothy wrote: > > > From: Chris Watson [mailto:opsys at voodooland.net] > > However, GPL is *not* extortion. The writer of a piece of > code has every > > right to want to protect, control or charge for it. > > That's true. But dont call it Free code if you do. Because it > is not free. > Look up free in the dictionary. That is the ONLY definition > that should be > followed. Not whatever twisted version the FSF and GNU people > want to use. > The gernal gist of any dictionary is its free if its free > from control, > opression, or restrictions. Did you even *read* my message? The word "free" does not appear *anywhere* in that message. I know - I copied the text into my editor and did a case-insensitive search. I dislike the GPL. If you had read my message, you would have seen that. I never use the term "free" with licenses as the term has become useless in a discussion - argue all you want about dictionary definitions, that will *never* convince people on the other side of the fence to yourself. After all, I am sure that *every* dictionary has multiple meanings for the term "free". Taking things out of context does not make your argument any stronger. You should *not* have only quoted the *sole* part of my message which conceded the right of someone to protect their work in the manner that they deem fit. Tim Delaney From tim.one at home.com Tue Oct 23 01:21:04 2001 From: tim.one at home.com (Tim Peters) Date: Tue, 23 Oct 2001 01:21:04 -0400 Subject: Dictionary from list? In-Reply-To: Message-ID: [Steve Holden] > Erm, wouldn't it make more sense (since there isn't a dictionary to start > with) to implement a "toDict()" method of lists rather than a dictionary > constructor? There's already a dictionary() constructor in 2.2, and that's not going to change (it would be too odd if every scalar and container builtin type had a builtin constructor except for dicts). One question is what it should do; all it can do in 2.2b1 is basically silly, amounting to yet another way to spell "shallow-copy the argument". Sticking a toDict() method on lists isn't appealing regardless because "iterable object" is the natural decomposition in 2.2 (for example, a tuple of two-element lists is just as good of an input argument as a list of two-element tuples, ditto a generator producing a sequence of address-book objects that supply an iterator over their name and address fields, and so on -- "a list" just isn't special here). From daves_spam_dodging_account at yahoo.com Tue Oct 23 15:06:59 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Tue, 23 Oct 2001 12:06:59 -0700 (PDT) Subject: Critical sections and mutexes Message-ID: <20011023190659.23110.qmail@web21101.mail.yahoo.com> Firstoff, Shouldn't the plural of "mutex" be "mutices"? :-) I am trying to write a multithreaded app in Python on Win32. These threads need to communicate with one another, so they can collaborate. Right now, there is a common resource in the main thread that each child needs to interact with, and there are resources in each child thread that the main thread will interact with. I've read through the thread and threading documentation as well as the sample code in Appendix D of Python Programming on Win32. I can make threads start, run and stop. But the "lock object" code is baffling me outright. Do I create a lock inside the child thread, or do I create it wherever and attach it to a thread? What I'm wondering is: - How can I lock a resource owned by a child thread from the main application, diddle with it, and unlock it? - How can I lock a resource owned by the main thread from a child thread, diddle with it, and unlock it? - Each lock/diddle/unlock operation is designed to keep the resource locked for as little time as possible, but I can still imagine the thread being preempted in the middle of an update. Do I need a critical section? If so, how do I implement one? The only case I can see this being a problem is when, say, Thread A locks something in the main thread, starts to interact with it, is preempted, and then the main thread gets a timeslice and interacts with the locked resource--which it views as local and doesn't need to check for a lock. Can that last situation even exist? Do I need to create a third, "go-between" object so that both threads have to go through the lock/unlock process to get at the resource? Here's a rough cut at what I'm sort of thinking: main_Q = PriorityQueue() # queueing class class ServerThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.Q = PriorityQueue() def run(self): # if messages waiting on socket: # get messages into self.Q # if self.Q has messages: # if can acquire lock on main_Q: # move msgs from self.Q to main_Q # release lock on main_Q # main thread: while 1: # if main_Q has messages: # dispatch them Thank you, -dB ===== -- David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From markus at schabi.de Wed Oct 10 05:06:02 2001 From: markus at schabi.de (Markus Schaber) Date: Wed, 10 Oct 2001 11:06:02 +0200 Subject: += doesn't work in python cgi's References: <3BC17D83.A4EEED81@tpg.com.au> Message-ID: <2494777.jqenx9y0nn@lunix.schabi.de> Oleg Broytmann schrub: > On Mon, Oct 08, 2001 at 06:18:43PM +0800, Michael Palm wrote: >> I have a strange error in that += doesn't seem to work in a cgi >> program >> >> #!/usr/bin/env python > > Your CGI has different search PATH, and is running under Python > 1.5.2. > Either use full path to Python 2.0+, or change search PATH, it is > configured in httpd configuration. Maybe it even helps to change the first line to: #!/usr/bin/env python2 markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From loewis at informatik.hu-berlin.de Sun Oct 28 05:12:28 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 28 Oct 2001 11:12:28 +0100 Subject: Why doesn't this simple Curry-like implemention work? References: Message-ID: "Michael R. Head" writes: > # for some reason this function doesn't work in python 1.5.2. > def curry(f, p): > return lambda x: apply(f, p, x) > > I've looked up on the list better class-based implementations, and am > using one of them, but I'm curious why this doesn't work (when the > curried function is called, f becomes unknown). In Python 1.5.2, function scopes don't nest. Given x=1 def foo(): x=2 def bar(): return x return bar() calling foo() will return 1. Python only has three nested name spaces: locals, globals, and builtins. Since the lambda expression produces a nested function, and since f is neither local to the lambda expression, nor global, it will not find the name f. The common work-around was to write def curry(f, p): return lambda x,f=f,p=p: apply(f, p, x) Starting with Python 2.1, function scopes optionally do nest (if you import nested_scopes from __future__). In Python 2.2, they nest by always. Regards, Martin From slinkp23 at yahoo.com Tue Oct 23 14:18:28 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Tue, 23 Oct 2001 18:18:28 GMT Subject: a better prime number generator References: Message-ID: On Tue, 23 Oct 2001 11:26:46 -0300, Alves, Carlos Alberto - Coelce wrote: >Why not try a variation from basic example in Python Tutorial by Guido van >Rossum?! > >def getPrimesTill(x): > primes=[2] > for i in range(3,x,2): > for x in range(2,i): Whoa nellie! ^^^^ > if i%x==0: > break > else: > primes.append(i) > return primes First of all, I'd replace both calls to range() with xrange(), to avoid memory problems. That done, it works, but it tests many more possible factors than it needs to if the number actually is prime. Since we're talking about speed here: On my machine, it takes 9 minutes to run getPrimesTill(2 ** 16) even after changing range() to xrange(). The inner loop actually spends *most* of its time looking for factors of numbers that *are* prime (since non-primes usually break out of the loop pretty quickly). So if we can drastically reduce the number of candidate factors, it'll help. As others have pointed out in this thread: If i has no factors less than or equal to sqrt(i), then there are no factors at all. Why? Because if there is a factor, x, larger than sqrt(i), then there is a corresponding factor (i / x) which must be less than sqrt(i). So you could change that line to for x in xrange(2, int(math.sqrt(i)) +1): Now I get it to compute up to 2 ** 16 in 4 seconds. Now that's a hefty optimization! But wait a minute - we already know that even numbers aren't prime, and we skip them in the outer loop. So why do we bother testing even factors? If x was divisible by an even number, x would be even, and we would have skipped it in the outer loop! We can skip half the tests: for x in xrange(3, int(math.sqrt(i)) +1, 2): That further cuts the execution time by about 40%. It also, in my tests, beats Brian Zhou's recursive list comprehension versions by a wide margin. But why stop there? You can apply the same principle to other numbers than 2. Suppose we test 5 and it's not a factor. Then we know we can skip all multiples of 5 because they won't be factors either! What this means is that we only need to test prime numbers as possible factors, and conveniently, we've been building a list of them all along. Well, surprise - the version posted by Emille van Sebille, from demo/scripts in the python distribution, does exactly that. So let's modify it to have the same interface as your function. def getPrimesTill(max): # Based on primes.py from python cvs primes = [2] i = 3 while i <= max: for p in primes: if i%p == 0 or p*p > i: break if i%p <> 0: primes.append(i) i += 2 # 1 is prime, but we don't want it in the list during the loop primes.insert(0, 1) return primes This takes about 60% of the time of my fastest version. But I'm not a big fan of using while to iterate over a sequence, since I think it's less readable than the equivalent xrange(), so here's my final answer: def getPrimesTill(max): # Based on primes.py from python cvs primes = [2] for i in xrange(3, max, 2): for p in primes: if i % p == 0 or p * p > i: break if i % p != 0: primes.append(i) primes.insert(0, 1) return primes Hope that helps. -- Paul Winkler From kkgahlot at yahoo.com Sun Oct 7 11:00:55 2001 From: kkgahlot at yahoo.com (Kiran Kumar Gahlot) Date: Sun, 07 Oct 2001 15:00:55 -0000 Subject: python process killed Message-ID: <9ppqn7+9eja@eGroups.com> Hi, I was trying to run a giant program, which generates something like 200 million lines of data and write to a file. The python program stops in between and just displays "Killed" after terminating. Can i avoid this abrupt killing of the program and force it to run completely. Thanks in advance, Regards, KKGahlot From skip at pobox.com Mon Oct 29 14:11:08 2001 From: skip at pobox.com (Skip Montanaro) Date: Mon, 29 Oct 2001 13:11:08 -0600 Subject: detecting and creating directories In-Reply-To: <3BDDA7BC.8CF7C891@mitre.org> References: <3BDDA7BC.8CF7C891@mitre.org> Message-ID: <15325.43468.687987.628181@beluga.mojam.com> Angel> I have not been lucky finding a way to check for the existance of Angel> a directory (so it is not there, I can create it). Angel> Any pointers? Check out the os.path module, especially os.path.isdir. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From shriek at gmx.co.uk Tue Oct 23 23:21:26 2001 From: shriek at gmx.co.uk (Stephen) Date: 23 Oct 2001 20:21:26 -0700 Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> <46gB7.151079$5A3.52079649@news1.rdc2.pa.home.com> Message-ID: <97ae44ee.0110231921.65b43ab5@posting.google.com> > This is a classic SQL problem, which most often manifests itself in > bill-of-materials processing in which parts are components of other parts, > and so on down to many levels. One reference to solutions can be found > towards the end of > > http://www.dbmsmag.com/9603d06.html > > It's one of those problems that has an "obvious" solution, which is very > non-obvious until you see it. Excellent Steve. This is precisely what I was looking for. (circa 1996 too - knew this had to have a standard/classic solution) Stephen. From tefol at This.Is.Not.An.Address Sat Oct 13 12:05:28 2001 From: tefol at This.Is.Not.An.Address (tefol) Date: Sat, 13 Oct 2001 16:05:28 GMT Subject: I am so embarrassed! References: <9139C54C7tefolThisIsNotAnAddr@61.9.128.12> Message-ID: <913A1FC94tefolThisIsNotAnAddr@61.9.128.12> A few hours ago, I wrote: >I have written a script to automate the creation of users on a Red Hat >7.1 server. I did a lot of testing on my dev server, and it worked >great. > >Adds the user to the /etc/passwd file, adds an encrypted passwd to the >/etc/shadow file. User can log in fine. > >I move the script over to my live server, and it doesn't work. It >looks like it works. The user I add appears in both the above files. >But it can't log in. Sometimes I am sooo stupid it hurts. Users tend not to be able to log in if their shell doesn't exist on the system, or if it isn't listed in /etc/shells, or both. *sigh* Still, there is a good working useradd script for redhat (et. al, I assume) linux boxes. It generates a fresh salt for each new user's password encryption. Works great. Knock yourself out. Cha! Me From tjreedy at home.com Thu Oct 25 20:51:46 2001 From: tjreedy at home.com (Terry Reedy) Date: Fri, 26 Oct 2001 00:51:46 GMT Subject: Python ByteCode and Virtual Machine documentation References: Message-ID: "Lucio Torre" wrote in message news:mailman.1004049566.23516.python-list at python.org... > Ive seen someone comment on the bytecode translation of some pieces of > code, but never seen any documentation. So i have two questions: > > a) where can i find documentation of the virtual machine of python? > (suppose i want to implement Thyton, a TCP parasitic computing version > of python) Try the 'dis' (disassemble) library module > b) is messing with the virtual machine a 'bad thing'? For most of us, probably yes. But for fun, search google for 'bytecodehacks' (its non-library module that enables you to hack byte codes). > i mean, for > example, that the VM is not defined because thats implementation > dependant and i should only care about understanding and parsing the > code? if its so, why? The VM currently used by the standard C implementation is intentially and explicitly *not* part of the language specification. (The Jython implementation, for instance, compiles Python to Java byte codes instead.) It is an implementation device whose details can (and do) change from release to release. If someone were to develope a completely different but substantially better VM, GvR would feel free to adopt that instead. Terry J. Reedy From volucris at hotmail.com Wed Oct 3 16:12:41 2001 From: volucris at hotmail.com (Greg Krohn) Date: Wed, 3 Oct 2001 15:12:41 -0500 Subject: Jython Applets Message-ID: <3bbb703d$0$321$6e49188b@news.goldengate.net> I am having problems compiling a test jython applet. This is my code: ## BEGIN C:\Projects\JyApp\JyApp.py import java class JyApp(java.applet.Applet): def paint(self, g): g.setColor(java.awt.Color.black) g.setFont(java.awt.Font("Arial", 0, 80)) g.drawString('Hello', 0, 0) ## END C:\Projects\JyApp\JyApp.py ## BEGIN C:\Projects\JyApp\jpywork\JyApp.html ## END C:\Projects\JyApp\jpywork\JyApp.html I use '-d' with jythonc and I get a bunch of deprecation warnings, but it compiles fine. When I view JyApp.html in IE5.5 it just shows the empty gray applet box, and it says 'load: class JyApp not found' in the status bar. JyApp.class IS in the same folder as JyApp.html (...\JyApp\jpywork\). Any ideas? Are there any good Jython docs out there (besides the ones in the Jython distro)? thanks, greg -- Volucris (a) hotmail.com "Eu n?o falo uma ?nica palavra do portugu?s." From peter at engcorp.com Wed Oct 31 19:36:15 2001 From: peter at engcorp.com (Peter Hansen) Date: Wed, 31 Oct 2001 19:36:15 -0500 Subject: Python.NET, MONO and Visual Studio etc. References: Message-ID: <3BE098FF.4FD7341E@engcorp.com> Oleg Broytmann wrote: > > On Wed, Oct 31, 2001 at 12:03:16PM +0100, Xavier Defrang wrote: > > This is almost off-topic but since you guys are talking about that .NET > > thing, I'd like just to ask anyone in here : WHAT THE HELL IS .NET??? > > > > I don't want any fancy buzzwords or corpspeak crap. I just want a clear, > > Among all the bullshit M$ invented there is one good thing: reusable > components. This is really good. You weren't actually suggesting that MS *invented* the concept of reusable components, were you? (I think you must have been referring to the specific reusable components they invented.) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From fredrik at pythonware.com Tue Oct 30 14:43:46 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 30 Oct 2001 19:43:46 GMT Subject: os.listdir References: <3BDEE6C6.8E96DBF3@ncsa.uiuc.edu> Message-ID: Randy Heiland wrote: > >>> for file in os.listdir('mydir'): > ... print file > ... > f100.dat > f1.dat > f2.dat > > but would like this: > f1.dat > f2.dat > f100.dat files = os.listdir('mydir') files.sort(mycomparefunction) for file in files: print file where mycomparefunction could be something like: def mycomparefunction(a, b): return cmp(int(a[1:-4]), int(b[1:-4])) but probably needs to be a bit more intelligent, in case your directory contains other files. for more information on sorting, see the sorting howto: http://py-howto.sourceforge.net/sorting/sorting.html From sholden at holdenweb.com Mon Oct 29 12:02:24 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 12:02:24 -0500 Subject: python binary search References: <9rht70.3vvdvgd.1@kserver.org> <3BDD4E50.8BA429E9@uoguelph.ca> <9rjtho$ff9$1@testinfo.cs.uoguelph.ca> Message-ID: "Jeffrey Dunnett" wrote in message news:9rjtho$ff9$1 at testinfo.cs.uoguelph.ca... > Jeff Dunnett (jdunnett at uoguelph.ca) wrote: > > > : Sheila King wrote: > > : > On Mon, 29 Oct 2001 15:38:53 +1100, "Delaney, Timothy" > : > wrote in comp.lang.python in article > : > : > : > > : > :I should resist, but I can't. > : > : > : > :So, what is this "it" that you do? (idoit). > : > > : > Twenty lashes with a wet noodle for Delaney. That was uncommonly cruel! > : > Poor Jeff has already beaten himself up enoug > > : Thanks for coming to my defence but I really MUST check my spelling beter. > > : Jeff > > > Alright I will crawl back in the computer lab I came out of and look at > an english dictionary since I incorrently spelled better. > Also, there's no such word as "alright". But surely it's traditional that wehn you correct someone else's spelling in a Usenet post you make one of your own, so I just saw that as traditional. Like this one :-) even-when-i-know-the-spelling-i-make-typos-ly y'rs - steve -- http://www.holdenweb.com/ From claird at starbase.neosoft.com Wed Oct 10 16:59:31 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 10 Oct 2001 15:59:31 -0500 Subject: Quick GUI Questions - Seeking Advice References: <9742a725.0110100741.6d7f625@posting.google.com> <9q262o$f9b$1@newsreaderm1.core.theplanet.net> Message-ID: In article <9q262o$f9b$1 at newsreaderm1.core.theplanet.net>, F. GEIGER wrote: >IIRC one of the wxPython demos provides already - at least partially - what >you are looking for. . . . >"J. Kenney" schrieb im Newsbeitrag >news:9742a725.0110100741.6d7f625 at posting.google.com... >> I have a really quick concern, that is which gui toolkit, (wxPython, >> TK, etc) to do some simple graphics works. I have been programming in >> python for many years but have never really gotton into graphics >> (other than with the web). >> >> All I need to do is, create a windows program where the screen has 3 >> parts, >> the first is a large window where I can move the mouse over the window >> knowing where it is at, track mouse clicks, and draw. while the other >> two are just for data entry/output. >> >> I just dont know how to create a window that I can draw in and take >> mouseclick/position information. Somewhat like a paint program, but I . . . There are demonstrations with Tkinter and PyQt that do much the same. My vote would be for Tkinter, simply because this should minimize Mr. Kenney's installation chores. What would help him most, though, I suspect, is a recipe from one of us which supplies precise details on a specific demonstration and tutorial. I know I'll not soon make the time for that ... -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From nixx at telia.com Sun Oct 7 09:57:27 2001 From: nixx at telia.com (Magnus) Date: Sun, 07 Oct 2001 13:57:27 GMT Subject: Python and Zope References: Message-ID: maxm wrote: > "Magnus" ... > >> When using to 'include' files/objects it is working >> well if the files are in the same directory. > > Your question can mean several different things, i'll try to answer them. > > If you want to build a news site with articles in different folders like: > > home/ > general/ > article1 > article2 > article3 > computers/ > Hifi/ > article4 > Politics/ > article5 > article6 > > And if you then want to have a list of all the articles on the front page > you could either traverse the folders manually > > conmputers.objectValues() + Hifi.objectValues() + > Politics.objectValues())"> >

> > > Or you could use the Catalog to to list the articles. This is probably the > best way to do it in the long run and it will be faster too. > > regards Max M Thanks Max, great stuff though I was looking for a different answer but this is also something I need. I was more after an answer where you are composing a page with several objects (sorry if I use the wrong notation I'm a newbie in Python and Zope) like: But in my case I have some images, and script in various folders hence I would like to do something like: (But this syntax is wrong.) Should it be something like: includes/my_header images/my_picture includes/my_footer (I just found some objects that might be useful but haven't tried them out yet e.g. RESPONSE, REQUEST and so forth.) Thanks, Magnus From paoloinvernizzi at dmsware.com Wed Oct 17 08:23:56 2001 From: paoloinvernizzi at dmsware.com (Paolo Invernizzi) Date: Wed, 17 Oct 2001 12:23:56 GMT Subject: class browser for python ?? References: Message-ID: Try boa, at http://boa-constructor.sourceforge.net, has a nice class browser and UML diagramms. Try out the actual CVS version, which is a lot better than the released one Paolo Invernizzi "Markus Jais" wrote in message news:pan.2001.10.17.12.57.24.657.2553 at web.de... > hello, > is there a tool out there, which can show me the class > structure of a python module > something like a class browser would be needed > or a tool that can generate UML diagramms from python sources > > any hints are welcome > > markus From ignacio at openservices.net Mon Oct 15 17:51:22 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Mon, 15 Oct 2001 17:51:22 -0400 (EDT) Subject: re.findall() is skipping matching characters In-Reply-To: Message-ID: On Mon, 15 Oct 2001, Gustaf Liljegren wrote: > Thanks for helping me out with matching/searching before. Unfortunately, > the example I gave was a little too basic, so I need some more help. > > >>> re.search(r'<(a)', '').group() > ' > The search() function matches the full expression: both the '<' and the > '(a)', which is short for a alternation between more HTML elements. The > match() function behaves like this too: > > >>> re.match(r'<(a)', '').group() > ' > But look what happens when I use the findall() function: > > >>> re.findall(r'<(a)', '') > ['a'] > > Why does findall() skip the '<'? I want to sort out full strings like ' href="page.html">' or '' and put them in a list. > I imagine the full regex should look something like this according to > today's standards: > > re_link = re.compile(r'<(a|area)\s[^>]*href[^>]*/?>', re.I | re.M) > > Where's the problem? It's because .group() takes an optional parameter specifying which subroup to return, defaulting with 0, which specifies the entire match. Pass a 1 instead. -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From phd at phd.pp.ru Wed Oct 24 03:31:44 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 24 Oct 2001 11:31:44 +0400 Subject: smtplib.SMTPDataError: (503, 'Error: need RCPT command') In-Reply-To: <9r5drc$qvltn$1@ID-11957.news.dfncis.de>; from emile@fenx.com on Tue, Oct 23, 2001 at 08:46:24PM -0700 References: <3BD4F3E8.1E4B826B@cs.utwente.nl> <9r3nqd$r34a5$1@ID-11957.news.dfncis.de> <9r5drc$qvltn$1@ID-11957.news.dfncis.de> Message-ID: <20011024113144.A31407@phd.pp.ru> On Tue, Oct 23, 2001 at 08:46:24PM -0700, Emile van Sebille wrote: > Which begs the question: Does anyone know where there might be a source that > shows the current status or otherwise forward points on older rfc's to the > rfc's that obsolete them? http://RFC.net/rfc-index.html Exmple: 0822 Standard for the format of ARPA Internet text messages. D. Crocker. Aug-13-1982. (Format: TXT=109200 bytes) (Obsoletes RFC0733) (Obsoleted by RFC2822) (Updated by RFC1123, RFC1138, RFC1148, RFC1327, RFC2156) (Also STD0011) (Status: STANDARD) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From quinn at ngwee.ugcs.caltech.edu Wed Oct 3 23:33:34 2001 From: quinn at ngwee.ugcs.caltech.edu (Quinn Dunkan) Date: 4 Oct 2001 03:33:34 GMT Subject: return command in a function. References: Message-ID: On Wed, 26 Sep 2001 22:10:48 -0400 (EDT), Ignacio Vazquez-Abrams wrote: >Heh. That's actually quite humorous to hear. It's one thing to not like gotos, >but to actually give up the benefits of structured programming by eliminating >break and continue and only allowing return at the end of a function borders >on insanity. > >Yes, it is possible to write complex code without them, but only if you're >prepared to write hundred-line if blocks and you honestly believe that doing >that would make clearer code than using break, continue, or a premature >return. > >Which it won't, I promise you. I guess you've never written Pascal. Neither have I, but I have written Eiffel (though I never had a problem with lack of loop control or return---possibly your hundred line blocks illustrate a different problem) See Kernighan's classic "Why Pascal is Not My Favorite Programming Language", especially the "death of a thousand cuts" section: http://www.lysator.liu.se/c/bwk-on-pascal.html I find it humorous that you describe elimination of break and continue as "giving up on the benefits of structured programming" because one-in one-out, no return, no loop control, etc. were the basic *tenets* of structured programming when everyone got so gung-ho about it in the 70s or 80s or whenever. I imagine that back in the goto-considered-harmful day all the structured programming quiche-eaters sneered at C for being such a backsliding recidivist. From debl2NoSpam at bellatlantic.net Sun Oct 14 23:28:32 2001 From: debl2NoSpam at bellatlantic.net (David Lees) Date: Mon, 15 Oct 2001 03:28:32 GMT Subject: Will Ware alive? (was Re: where lives uthread (microthreads) now ??) References: <3b091a1c.0110080739.23205b07@posting.google.com> <9qdhil$iek$1@panix2.panix.com> Message-ID: <3BCA57EF.D39E6683@bellatlantic.net> Software Tool and Die, where his home pages were located is one of my ISPs, so I just telneted in and it appears he has not read his mail since Oct 1. I phoned STD and it sounds like he is leaving them, so homefully he will post his new address. david lees Aahz Maruch wrote: > > [x-posted to c.l.py and python-dev] > > In article <3b091a1c.0110080739.23205b07 at posting.google.com>, > cmkl wrote: > > > >I wanted to test a samle code with microthreads needed. > >The download area: http://world.std.com/~wware/uthread.html > >is not available however. > > > >Is there a mirror to get this code somewhere? > > Has anybody heard from Will Ware since 9/12? E-mail to him doesn't > bounce, but I haven't received any reply. > -- > --- Aahz <*> (Copyright 2001 by aahz at pobox.com) > > Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ > Androgynous poly kinky vanilla queer het Pythonista > > We must not let the evil of a few trample the freedoms of the many. From kirill at xyz.donetsk.ua Fri Oct 19 18:16:11 2001 From: kirill at xyz.donetsk.ua (Kirill Simonov) Date: Sat, 20 Oct 2001 01:16:11 +0300 Subject: Reverse argument order In-Reply-To: <20011019215919.3702.qmail@web21108.mail.yahoo.com>; from daves_spam_dodging_account@yahoo.com on Fri, Oct 19, 2001 at 02:59:19PM -0700 References: <20011019215919.3702.qmail@web21108.mail.yahoo.com> Message-ID: <20011020011611.A12642@xyz.donetsk.ua> On Fri, Oct 19, 2001 at 02:59:19PM -0700, David Brady wrote: > P.S. We're going to go with the "while len(args)<3: > args.insert(0,0)" model for now. Much less sucky, > yes, thanks! How about such solution? >>> def Wait(*args): ... h, m, s = ((0, 0, 0) + args)[-3:] ... print h, m, s ... >>> Wait() 0 0 0 >>> Wait(1) 0 0 1 >>> Wait(1, 2) 0 1 2 >>> Wait(1, 2, 3) 1 2 3 \Xi From nhodgson at bigpond.net.au Wed Oct 31 07:01:22 2001 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 31 Oct 2001 12:01:22 GMT Subject: PythonWin 2.1 saving bugg??? References: Message-ID: Tim Gahnstr?m: > What I dont understand is, how can this happen? is this how the pythonwin > savingfunction works? > > remove_old__file_from_disk > Save new_file_that_current_spot What it does is, with error checking removed: os.unlink(bakFileName) os.rename(fileName, bakFileName) self.SaveFile(fileName) The actual code is in Pythonwin\pywin\scintilla\document.py. > BTW is this what openSource is about? If I look over the saving > routines in PythonWin and find that they can be done better and > fix it, is there a good chanse that, that will be incorporated into > the next release? If it is unambiguously better then I'm sure Mark will accept a patch. However, he often has a good idea what he is doing so you may need to discuss it with him in detail. I noticed that you wrote: > But after (abruptly and with scandisk...) having restarted > the computer I came back and found that my program > wasn't ther at all! anymore. Does this mean you pressed the reset button (or similar) in an attempt to keep the old file? If so this is a really bad idea as you have a good chance of not having any of the copies survive as the on-disk data associated both with the old and new copies may be incomplete. Neil From mwh at python.net Wed Oct 24 05:09:48 2001 From: mwh at python.net (Michael Hudson) Date: Wed, 24 Oct 2001 09:09:48 GMT Subject: Name of current method (for C functions) ? References: <50cd1e5d.0110231608.e955f0e@posting.google.com> Message-ID: tgloth at earthlink.net (Tobias Gloth) writes: > I am implementing a module for python that registers new methods > dynamically, using Py_InitModule. At compile-time it is not known > how many methods will be registered, so I can't provide a separate > callback for each method. My plan is to register the same C function > for all those python methods, and from within that C function > dispatch, based on the name the function was called under. > > The problem is: I seem to be unable to obtain the name of the > current method anywhere. For methods implemented in python this > works, by analyzing the call stack, but for C functions, the relevant > name field is empty. > > Any hints or suggestions would be greatly appreciated! I don't think what you ask is directly possible (because of C's suckiness[0], basically). I'd suggest a Python wrapper along the lines of import my_c_module class _Func: def __init__(self, func, descr): self.func = func self.descr = descr def __call__(self, *args): self.func(self.descr, *args) for name, descr, func in my_c_module.get_funcs(): globals()[name] = _Func(descr, func) Could something like this fly? Cheers, M. [0] The fact that you can't dynamically create functions. Whether this is suckiness or not is not opened to debate here. -- 6. Symmetry is a complexity-reducing concept (co-routines include subroutines); seek it everywhere. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From lfini at arcetri.astro.it Mon Oct 29 06:40:30 2001 From: lfini at arcetri.astro.it (Luca Fini) Date: Mon, 29 Oct 2001 12:40:30 +0100 Subject: pydoc question Message-ID: I'm trying to use pydoc to document a class of my own which is a subclass of Tkinter.Canvas. When I generate the documentation, pydoc automatically extracts the full documentation of the root class and puts it into my class documentation. Well I'd prefare to put a line saying something like: "this is a subclass of Canvas, see Tkinter documentation for other details" Is there any way to force this behaviour? Many thanks, l.f. -- -------------------------------------------------------------------------- -- ) Luca Fini Tel: +39 055 2752 307 ___ |\ Osservatorio Astrofisico di Arcetri Fax: +39 055 2752 292 / | | |-_ L.go E.Fermi, 5 +----------------------------------------- (___|___//___) 50125 Firenze / WWW: http://www.arcetri.astro.it/~lfini (_) (_) Italia / e-mail: lfini at arcetri.astro.it -----------------------------+-------------------------------------------- From qrczak at knm.org.pl Sat Oct 27 12:21:19 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: Sat, 27 Oct 2001 16:21:19 +0000 (UTC) Subject: Dictionary from list? References: Message-ID: Tue, 23 Oct 2001 19:49:37 +0000 (UTC), Huaiyu Zhu pisze: > There have been several good arguments about why [(k,v), (k,v) ...] is > better than [k, v, k, v, ...]. Here are some more observations: Here is why Perl does it its way: it didn't have nested data structures at the time this was designed! You could only put scalars in a list, i.e. strings or numbers. (You still can, but scalars now include references to arrays.) -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From drew_csillag at geocities.com Thu Oct 11 17:03:17 2001 From: drew_csillag at geocities.com (Drew Csillag) Date: Thu, 11 Oct 2001 17:03:17 -0400 Subject: [ANN] SkunkWeb 3.1 released! Message-ID: <20011011170316.E4451@starmedia.net> Release 3.1 of The SkunkWeb Web Application Server has just been released. The release is available from the SkunkWeb home page at http://skunkweb.sourceforge.net or directly from http://prdownloads.sourceforge.net/skunkweb/skunkweb-3.1.tgz What's new? (from 3.0) ------------------------------ * Major performance tweaks. Should now be about 30% faster overall. * Now supports FastCGI * PyDO improvements (mainly PostgreSQL related) * new service - userdir - which makes it so that requests to /~user/foo will go to /public_html/foo * print statements in <:call:> tags now work. * <:call:> tag now handles multiline expr argument properly. Now you can do things like: <:call `def foo(x): return 'the value is %s' % x print foo(3)`:> * PostgreSQL fixes * UNIX domain socket fixes * PyDO classes can now be defined in non-modules * Now can have a template that gets executed for directories that don't have an index document. Very best wishes to all, -Drew From tim.one at home.com Thu Oct 18 23:38:54 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 18 Oct 2001 23:38:54 -0400 Subject: PEP: statements in control structures (Re: Conditional Expressions don't solve the problem) In-Reply-To: <9qo63i$dpc$1@slb3.atl.mindspring.net> Message-ID: [Andrew Dalke] > ... > I love generators and iterators. :) Yes, you do, but did you know that they love you too? They do! Generators and iterators are among the most loving features ever introduced. They will give and give, without ever asking anything from you save the privilege of gracing your code, waiting with eager anticipation for you to resume them at your pleasure, or even to discard them if you tire of their charms. In fact, they're almost pathologically yielding. while-hell-hath-no-fury-like-an-import*-scorned-ly y'rs - tim From phr-n2001d at nightsong.com Fri Oct 19 10:23:57 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 19 Oct 2001 07:23:57 -0700 Subject: Triple-DES implementation in Python References: <1854cfa0.0110181325.50a4aba6@posting.google.com> <3BD033A0.BAC206BB@pallas.com> Message-ID: <7x1yjzoghu.fsf@ruckus.brouhaha.com> Georg Bisseling writes: > I would go to www.OpenSSL.org, get a free C implementation, > learn how to integrate C extensions into python and do it. It's not that easy. You'd then have to make loadable modules for every computer and OS that anyone who wants to use the function might be running. There are plenty of C implementations of DES already linked to Python, but it's useful to also have a pure Python implementation. From grahamd at dscpl.com.au Sat Oct 27 22:30:02 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 27 Oct 2001 19:30:02 -0700 Subject: Question: Event driven programming References: <3bdad71d$1_3@corp-goliath.newsgroups.com> <3BBC7.3002$Z_1.506578@newsc.telia.net> <3bdb0140_5@corp-goliath.newsgroups.com> Message-ID: Chris Liechti wrote in message news:... > "K?roly Ladv?nszky" wrote in > news:3bdb0140_5 at corp-goliath.newsgroups.com: > > > What I have in my mind is not necessarily UI related. In VB, objects > > can raise events, objects interested in the events will handle them. > > Thats a very simple mechanism, facilitates easy coding in many > > situations, even if its just a console application with no GUI at all. > > They are similar to exceptions but they return to the caller and they > > can have parameters/return values of any kind. > > > > that sound like an "observer pattern" for me.... it is a common thing to do > in OO languages. it's not a feature of a language but more a idea that can > be implemented in various ways and languages. > Java has an observer pattern implementation in it library, for Python you > can take the code from the URL below. > > make a module with the "Subject" and "Observer" classes then you can simply > inherit from them in your own classes. Often in a GUI context, but not necessarily, also referred to as Model View Controller (MVC), just depends on how the interaction is managed. Also, in distributed system, often facilitated by a distributed publish/subscribe mechanism. This takes separatation of subject and observer to the extreme in the sense that interaction between the two isn't by direct application of callbacks from subject to observer, but is mediated through an underlying message system. For distributed publish/subscribe mechanism in Python see example at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81614 From xxxx at nisus.com Wed Oct 3 22:24:47 2001 From: xxxx at nisus.com (xxxx) Date: Wed, 03 Oct 2001 19:24:47 -0700 Subject: install on MacOS X 10.1? Message-ID: <3BBBC870.D0AE585E@nisus.com> I down-laoded 2.1.1 In the Makefile I found this suggested sequence # ./configure # make # make test # make install In the README it says Mac OS X 10.0: Run configure with "OPT='-no-cpp-precomp' ./configure --with-suffix=.exe --with-dyld". This generates executable file: 'python.exe' (it cannot be named 'python' on an HFS or HFS+ disk as the file name clashes with directory 'Python'). The '-no-cpp-precomp' option prevents a large number of compilation warnings. One of the regular expression tests fails with a SEGV due to the small stack size used by default (how to change this?), and the test_largefile test is only expected to work on a Unix UFS filesystem (how to check for this on Mac OS X?). but taking that literally doesn't work at all, generating error messages about the OPT. OPT=-no-cpp-precomp: Command not found. So, I tried swapping it 'round ./configure OPT='-no-cpp-precomp' --with-suffix=.exe --with-dyld and got configure: warning: OPT=-no-cpp-precomp: invalid host type Is OPT an environment variable? Is it a parameter/argument to configure? Is it a directive to configure? From reqhye72zux at mailexpire.com Tue Oct 9 19:44:23 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Tue, 09 Oct 2001 23:44:23 -0000 Subject: String formatting with two dictionaries? References: Message-ID: Xavier Defrang wrote: > > On Tue, 9 Oct 2001, Carsten Gaebler wrote: > >> "%(foo) %(bar)" % magic(dict1, dict2, ...) > > So what about writing a class called "magic" that takes a bunch of > dictionaries as __init__ arguments, and use an overridden > __getitem__ to perform look-ups thegiven dictionaries? That was my first thought too. Shouldn't be hard to come up with something useful: - - - class multidict: def __init__(self, *dicts): self.dicts = dicts def __getitem__(self, item): for dict in self.dicts: try: return dict[item] except KeyError: pass raise KeyError(str(item)) d1 = {"foo": "bar"} d2 = {"spam": "eggs"} s = "%(foo)s %(spam)s" print s % multidict(d1, d2) - - - Notice that this isn't a real dictionary: it only has a __getitem__ method. Conversely, it only *uses* that method, too. As such, its uses are limited, but at a cost of only 12 lines of code that's hardly an issue. I once used an even simpler class to return a default value for a dictionary, also for string interpolation. (Otherwise I'd have been able to use dict.get(key, defaultvalue) directly, of course.) What I'd like to see for the %(key)s type string interpolation is for it to be slightly more forgiving in that the trailing 's' should be optional (IMHO, of course). A % without any formatting character could mean anything, but after %(key) there can hardly be any doubt that we want something inserted at this point, and that 'something' is usually a string. Even if it isn't a string, it will be coerced into one, and I can't think of any case where this will display something other than you'd expect[*]. (Thus, the 'principle of least suprise' is maintained.) I can't think of any code this would break. (It's hard to be certain: the ability to catch exceptions could mean that some program actually counts on this happening.) Robert Amesz -- [*] Testing a bit further, this isn't strictly true. Using %f will not display as many digits as %s, when trying to display 1.0/7, and what's even stranger is that the interactive display will show even more digits. (A mantissa of 6, 12 and 17 digits, respectively.) It's a curious, if minor inconsistency. From logiplexsoftware at earthlink.net Tue Oct 23 17:11:08 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Tue, 23 Oct 2001 14:11:08 -0700 Subject: Critical sections and mutexes In-Reply-To: <20011023205424.55377.qmail@web21108.mail.yahoo.com> References: <20011023205424.55377.qmail@web21108.mail.yahoo.com> Message-ID: <01102314110808.14120@logiplex1.logiplex.net> On Tuesday 23 October 2001 13:54, David Brady wrote: > One question that still has not been answered: > critical sections. Can they be implemented, or can I > only lock other threads out of a given resource? Reading your original post, I believe you are thinking about this wrong (please, no offense). >From original post: "only case I can see this being a problem is when, say, Thread A locks something in the main thread, starts to interact with it, is preempted, and then the main thread gets a timeslice and interacts with the locked resource--which it views as local and doesn't need to check for a lock." If you are going to share a resource among threads, then _every_ access to that resource _must_ be enclosed in locks (even if you are only reading from the resource). You suggested that you would need a "critical section" so that the main thread would not access the resource if another thread is. If you make your main thread check the lock, this won't happen, end of story. It doesn't matter if the resource is local to the main thread. Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From James_Althoff at i2.com Tue Oct 30 14:46:10 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Tue, 30 Oct 2001 11:46:10 -0800 Subject: Unpacking extension (Re: A small inconsistency in syntax?) Message-ID: Bernhard Herzog wrote: >Personally, I wouldn't mind to see the "[a,b] = sequence" syntax go. I agree. I think it's confusing and adds no value (unless I'm missing something). Jim From paul at ActiveState.com Tue Oct 16 06:17:28 2001 From: paul at ActiveState.com (Paul Prescod) Date: Tue, 16 Oct 2001 03:17:28 -0700 Subject: feeding SAX References: <20011016105351.A774@10.am> Message-ID: <3BCC0938.A97F542E@ActiveState.com> mallum wrote: > > hi all; > > Expat allows me to incrementally parse an XML document by 'feeding' it > the document in chunks rather than in one whole go. Is this possible > with SAX ? or do you have to give its parse function the entire > document ? Look in Lib\xml\sax\expatreader.py. It exposes an incremental interface based on a SAX interface called IncrementalParser. It has a feed() method. Paul Prescod From loewis at informatik.hu-berlin.de Sun Oct 21 09:28:20 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 21 Oct 2001 15:28:20 +0200 Subject: Magic Module Methods? References: <9qt1qm$f7l$1@tyfon.itea.ntnu.no> Message-ID: "Magnus Lie Hetland" writes: > OK - bad example (and terse explanation). The situation was this: I > was using a module as a config file, and at the same time as an > object containing defaults at some other point in the program > (available for users of the library). Therefore, the defaults should > be accessible from the module, but the people writing the config > file might not want to set absolutely all the values... I could of > course do an update() on the module __dict__, and that might be > clearer, but possibly not near-infinitely? ;) I'm still not sure what you are trying to do: You have a module that your users want to customize, by putting values in it. You don't want to require them to fill in all values, and you don't want to give them a template that already has all supported values filled out. Correct? If so, where do the default values come from, instead? They are not in the config module, but you want to access them from the config module? Even if you had an _getattr__ for modules, wouldn't your users have to put the __getattr__ definition (which surely would look magic) in their configuration module? I'd propose the following solution: Make a DEFAULTS.py containing the defaults, and a config.py that start with from DEFAULTS import * Then your users could customize the configuration by putting assignments after the import statement. Regards, Martin From logiplexsoftware at earthlink.net Wed Oct 31 12:56:09 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 31 Oct 2001 09:56:09 -0800 Subject: Underscore data hiding (was python development practices?) In-Reply-To: <9rpbk1$19rg$1@nntp6.u.washington.edu> References: <9rpbk1$19rg$1@nntp6.u.washington.edu> Message-ID: <01103109560801.06896@logiplex1.logiplex.net> On Wednesday 31 October 2001 09:15, Russell E. Owen wrote: > My understanding is that a double underscore is required for Python to > automagically mangle the name. On the other hand, two postings now > suggest that a single underscore is sufficient. A double underscore is required for Python to do any mangling (and it can't end with a double underscore, either). A single underscore is simply a convention that tells other programmers the name is not meant for public consumption. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From ws-news at gmx.at Mon Oct 29 04:29:58 2001 From: ws-news at gmx.at (Werner Schiendl) Date: Mon, 29 Oct 2001 10:29:58 +0100 Subject: None References: <3bd5db1e$1@brateggebdc5.br-automation.co.at> <3bd7fa75$1@brateggebdc5.br-automation.co.at> <3BD8C747.3DA9EEEC@cosc.canterbury.ac.nz> Message-ID: <3bdd2257@brateggebdc5.br-automation.co.at> Hi, "Greg Ewing" wrote in message news:3BD8C747.3DA9EEEC at cosc.canterbury.ac.nz... ... > > Actually, NULL is a preprocessor macro in C, so it's > like doing > > #undef NULL > #define NULL 42 > > which would really confuse someone reading your C program! > ... even better would be to define it #define NULL ((void *) 42) but this is unlikely to happen by accident. Assigning to None, however, seems more likely to happen e. g. if someone tries to drop some unwanted return values there: a, None, b = function1() instead of a, dummy, b = function1() regards Werner > -- > Greg Ewing, Computer Science Dept, University of Canterbury, > Christchurch, New Zealand > To get my email address, please visit my web page: > http://www.cosc.canterbury.ac.nz/~greg From brueckd at tbye.com Wed Oct 24 16:06:50 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 24 Oct 2001 13:06:50 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: <01102412542300.24656@logiplex1.logiplex.net> Message-ID: On Wed, 24 Oct 2001, Cliff Wells wrote: > True, I may have overstated it a bit, however, I would expect that the > typical multi-threaded application is going to do things that require more > than a single-line of python to manipulate data You might *expect* that, but it often turns out not to be the case. :) It all depends on the type of program you're writing, but I've found that very often (maybe even 50% of the time or more) multithreaded apps get by just fine without additional work. Even a few really large programs boiled down to unidirectional work queues. In those cases I often use a semaphore as a "work ready" signal, but that has nothing to do with maintaing data integrity and everything to do with performance (avoiding busy waits). >, i.e. len() prior to append() > or pop() or whatever. Hence the try..pop..except construct. With checking for length before appending, it's often the case that there is no firm requirement on max list size, only that you don't want it to be too big (ie - it's a fuzzy requirement). That being true, the worst case for a non-locking implementation would be a list that has (n-1) too many objects in it where n is the number of producers. For example, if you have a work queue that you don't want to grow to some extreme length you may decide to cap its size at 1000 elements. With 10 threads adding work to the list, occasionally they'll drop or hold a packet of work too long or occasionally your list will grow to 1009 elements. No big deal: the drop/hold problem exists regardless of any sort of locking, and you don't care that your list is 9 elements too big because your requirement was simply "don't let it grow without bounds". -Dave From reqhye72zux at mailexpire.com Wed Oct 3 18:36:06 2001 From: reqhye72zux at mailexpire.com (Robert Amesz) Date: Wed, 03 Oct 2001 22:36:06 -0000 Subject: test - don't read... References: <3bb9e35a.695404@news.newsguy.com> Message-ID: Owen F. Ransen wrote: > don't read don't write From jjl at pobox.com Mon Oct 15 15:15:07 2001 From: jjl at pobox.com (John J. Lee) Date: Mon, 15 Oct 2001 20:15:07 +0100 Subject: Parsing XML (simple) In-Reply-To: References: Message-ID: On 15 Oct 2001, Martin von Loewis wrote: > singleton at skynet.be (Thomas Singleton) writes: > > > > > commande1 > > commande2 > > > [...] > > After reading the modules doc and a few usenet posts, i have written a > > small python program to echo the values contained between tags, but > > i'm having troubles with the commands, only the FIRST one is echoed. Martin fixed your problem, but since I've read in several different places that 'there are two apis for dealing with XML in Python', I thought I'd point out the third, XPath, an implementation of which is available in 4Suite. Simpler to use (for my simple purposes, at least), but slower, I expect. John From fredrik at pythonware.com Wed Oct 31 08:57:14 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Oct 2001 13:57:14 GMT Subject: PythonWin 2.1 saving bugg??? References: Message-ID: <_qTD7.3137$R43.557713@newsb.telia.net> Neil Hodgson wrote: > What it does is, with error checking removed: > > os.unlink(bakFileName) > os.rename(fileName, bakFileName) > self.SaveFile(fileName) you probably should consider: os.unlink(tempFileName) self.SaveFile(tempFileName) os.unlink(bakFileName) os.rename(fileName, bakFileName) os.rename(tempFileName, fileName) where tempFileName is a file in the same directory as fileName. (adding the right try/excepts are left as an exercise) From idot at vt.edu Wed Oct 17 14:07:27 2001 From: idot at vt.edu (Carl Banks) Date: Wed, 17 Oct 2001 14:07:27 -0400 Subject: Conditional Expressions don't solve the problem References: <7xr8s2zo57.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > > But it's not just saving keystrokes--the usual place for an assigment > in an expression is in the control expression for a while loop. > Having to split it into several statements clutters up the code and > makes the readability WORSE by moving the test condition away from the > 'while' keyword. Do you REALLY find > > while (line := file.readline()) != 'end': > process_line(line) > > to be less readable than > > while 1: > line = file.readline > if line == 'end': break > process_line (line) > > (or worse, imagine several nested loops like that)? I don't. I do. I find assignment within an expression to be contrived and opaque. I would be surprised if there were many of your opinion who weren't numbed down to it by years of exposure to C. -- CARL BANKS From piet at cs.uu.nl Mon Oct 8 08:08:44 2001 From: piet at cs.uu.nl (piet at cs.uu.nl) Date: 8 Oct 2001 12:08:44 GMT Subject: += doesn't work in python cgi's References: <3BC17D83.A4EEED81@tpg.com.au> Message-ID: <9ps50c$56a$3@samos.cs.uu.nl> >>>>> Michael Palm (MP) writes: MP> I have a strange error in that += doesn't seem to work in a cgi program MP> test.py: MP> #!/usr/bin/env python MP> print "Content-type: text/html\n\n" MP> j = 1 MP> j +=1 MP> print " j is %d" % j MP> works fine with MP> python test.py MP> but as a cgi gives MP> j += 1 MP> ^ MP> SyntaxError: invalid syntax MP> any ideas?? It probably invokes an older version of python. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From matt at mondoinfo.com Tue Oct 16 13:38:38 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Tue, 16 Oct 2001 17:38:38 GMT Subject: Python, Unix sendmail, and multiple recipients References: Message-ID: On Tue, 16 Oct 2001 10:58:49 -0500, Kemp Randy-W18971 wrote: >Can anyone give me an example of how to invoke the Unix sendmail in >Python, and send an email message to more then one recipient (two >people, for example)? Dear Randy, If it's practical, I'd use Python's smtplib. It's documented at: http://www.python.org/doc/current/lib/module-smtplib.html Since it uses a socket connection, it doesn't require that the MTA be sendmail and the MTA doesn't have to be on the local machine. If you really want to use a local copy of sendmail, you could open a pipe to it and invoke it with the -t option so that it will read the recipients from the message. Something like (untested): p=os.popen("/usr/lib/sendmail -t","w") p.write(msg) p.close() Your sendmail may well not be in /usr/lib. If you need to specify the recipients outside of the message text, they can be put on the command line (again untested): p=os.popen("/usr/lib/sendmail a at example.org b at example.org","w") p.write(msg) p.close() Regards, Matt From tim.one at home.com Thu Oct 11 15:06:11 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 11 Oct 2001 15:06:11 -0400 Subject: Why not 3.__class__ ? In-Reply-To: Message-ID: [James_Althoff at i2.com] > ... > At a higher level it seems that if you want to do an "isinstance" test, > it is nicer to use the class object that you already have "in hand" (or > can easily get to with a literal constant) rather than having to know > about an external module (for which you need to know the name and package > path) with class names (that you also need to know) -- especially given > that the general case, isinstance(x,y.__class__), is something one needs > to use in some circumstances in any case. > > In the end, > (0).__class__ works -- it justs adds unfortunate "line noise" and > momentarily invokes the "is it an expression or is it a tuple" > confusion > > 0 .__class__ works, too -- but is somewhat fragile because of the > required white space > > Still, these are better than nothing. :-) I like 2.2, where you can skip all that and just say isinstance(whatever, int) If you're tempted to write that isinstance(whatever, (0).__class__) instead in 2.2 (which also "works"), you're likely confused about things more basic than the consequences of maximal-munch lexing <0.9 wink>. From phd at phd.pp.ru Thu Oct 11 09:37:03 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 11 Oct 2001 17:37:03 +0400 Subject: kjbuckets module updated for Python 2.1; kjbuckets.pyd Windows DLL included Message-ID: <20011011173703.A4132@phd.pp.ru> Hello! spex66 at gmx.de sent me a version of kjbucketsmodule.c updated for Python 2.1. There is also kjbuckets.pyd Windows DLL for Python 2.1. (ActiveState 2.1.1, actually). Many thanks, spex66! Page http://phd.pp.ru/Software/Python/#kjbuckets updated. Please note that I am not maintainer, just a "collector", in abscence of a real maintainer. You are welcome to send me minor patches, and you are especially welcome to adopt the project as a real maintainer. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From loewis at informatik.hu-berlin.de Wed Oct 24 05:38:08 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 24 Oct 2001 11:38:08 +0200 Subject: problem importing xml.xpath References: <3BD5C38E.61DCB7B0@iems.nwu.edu> Message-ID: Leonardo B Lopes writes: > I can't find a way to import the xpath library with python2.0. I can > see it in the right place, in the site-packages dir. I notice that there > is also an XML directory in the main distr. directory, so I tried moving > the dirs there too, but that didn't work. All I want to do is get the > two demos XmlTree.py/XmlEditor.py working. Does anyone have any idea > what is going on? Where did you get xml.xpath from? If you got it from 4Suite, it should be installed as site-packages/_xmlplus/xpath. Regards, Martin From jknapka at earthlink.net Tue Oct 23 14:34:01 2001 From: jknapka at earthlink.net (Joseph A Knapka) Date: Tue, 23 Oct 2001 18:34:01 GMT Subject: Tkinter entry field question References: Message-ID: <3BD5623D.C29AC40C@earthlink.net> Laura Creighton wrote: > > Tkinter Entry fields have a width but not a height. If you don't like the > height they come in, and know what height you want, how do you change > them? > > Laura Creighton Laura Creighton wrote: > > Tkinter Entry fields have a width but not a height. If you don't like the > height they come in, and know what height you want, how do you change > them? Hi Laura, >From the Tk man page on "entry": "An entry is a widget that displays a one-line text string" IOW, height == 1, period. If you need a multiline text control, you have to use a text widget instead. Cheers, -- Joe # "You know how many remote castles there are along the # gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald # Linux MM docs: http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html -- # Replace the pink stuff with net to reply. # "You know how many remote castles there are along the # gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald # Linux MM docs: http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html From phd at phd.pp.ru Tue Oct 2 16:14:03 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 3 Oct 2001 00:14:03 +0400 Subject: http request timeout In-Reply-To: <3BBA1BF6.2020702@hp.com>; from garth_grimm@hp.com on Tue, Oct 02, 2001 at 12:56:38PM -0700 References: <3BBA1BF6.2020702@hp.com> Message-ID: <20011003001403.A25850@phd.pp.ru> On Tue, Oct 02, 2001 at 12:56:38PM -0700, Garth Grimm wrote: > What I'd love to do, is set a time-out on the http connection. http://www.timo-tasi.org/python/timeoutsocket.py Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From fredrik at pythonware.com Tue Oct 23 14:08:16 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 23 Oct 2001 18:08:16 GMT Subject: POLL in different OSes References: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> Message-ID: Gerhard H?ring wrote: > Wouldn't it be possible to emulate poll() with select()? I'd be glad to > see a patch appear at Sourceforge if that's possible :-) why bother? if you have Python code that uses poll, you usually need about ten lines of Python glue to make that code use select instead (poll takes/returns a list of file/flag tuples, select two separate lists). see asyncore.py for an example. (the Python library tends to avoid approximating one system call with another. better leave that to the application programmer, who's the only one who knows the exact requirements.) From DeepBlue at DeepBlue.org Thu Oct 11 10:57:02 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Thu, 11 Oct 2001 09:57:02 -0500 Subject: ODBC access via Python References: Message-ID: "Jim Abrams" wrote in message news:Xns91376AA1D8579jimpublishingresourc at 207.126.101.100... > vm_usenet at yahoo.com (vm_usenet) wrote in @posting.google.com>: > > > Hi all! > > > > I have recently become a die-hard Python fan, but I can't seem to > > overcome a minor obstacle: > > > > Can anyone direct me to a good ODBC module/library for python under > > win32? > > > > I've tried to install mxODBC, but it doesn't work for some reason... What reason? I am using it with Python 2.1 and it is running fine. Can you tell us more about these erorrs/reasons? > DB From huaiyu at gauss.almadan.ibm.com Mon Oct 15 19:47:49 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 15 Oct 2001 23:47:49 +0000 (UTC) Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <9q4it9$tio$1@nntp6.u.washington.edu> <7xhet6ot4j.fsf@ruckus.brouhaha.com> <9q5370$3re$1@lancelot.camelot> <3BC782D8.8F3A44A5@ccvcorp.com> Message-ID: On Fri, 12 Oct 2001 16:55:04 -0700, Jeff Shannon wrote: >while 1: > x = next() > if x.is_end(): break > y = process(x) > if not y.is_good_result(): > raise "not found" This won't do it. It will raise "not found" as soon as the first y is not good result. Eg, this raises "not found": x = 0 while 1: x += 1 if not x<10: break y = x*3 if not y > 14: raise "not found" print y In contrast, proposed syntax while x = next(); not x.is_end(): y = process(x) if y.is_good_result(): break else: raise "not found" will raise "not found" iff all y are not good results. Note that the 'else' corresponds to 'while', not 'if'. (This 'else' syntax exists in Python even without my proposal.) For example, the following will print 15: i = 0 while i+=1; i<10: y = x*3 if y > 14: break else: raise "not found" print y I have not found existing way to write this without duplicating the 'y = x*3' or 'i+=1' parts or using temperary vairables. >Personally, I think that the construct you are promoting, > >while (expression); (condition): > (suite) > >.... is ugly and non-intuitive, and I would *not* want to use it. Just my >opinion, but..... The part before ";" are statements. The condition must be an expression, which is the main point of the proposal. So the proposal is actually while (statements) ; (expression) : (suite) else : (suite) I'll write it up sometime. maybe-easier-to-write-a-pep-than-discuss-it-piecemeal-ly yr's Huaiyu From grante at visi.com Wed Oct 17 13:55:17 2001 From: grante at visi.com (Grant Edwards) Date: Wed, 17 Oct 2001 17:55:17 GMT Subject: Desperate help required for Python assignment References: <602c058e.0110162347.268591ce@posting.google.com> Message-ID: In article <602c058e.0110162347.268591ce at posting.google.com>, Nachiket wrote: > I am new to Python doing a crash course in University. I have a > assignment to submit in two days the specifications of which are: [...] > Please can some of the Gurus on this newsgroup help me out with a > working solution as with my limited knowledge i am no position to > handle this assignment in two days. You're asking for help you commit academic fraud by doing your assignment for you so that you can turn it in as your own work? If I were you I'd be a little worried that my prof might be reading the group and figure out who you are. I'd be happy to answer questions about Python, but I'm not going to do your homework assignment for you. -- Grant Edwards grante Yow! Did we bring enough at BEEF JERKY? visi.com From fschaef at ces.clemson.edu Wed Oct 31 14:18:18 2001 From: fschaef at ces.clemson.edu (Schaefer, F.) Date: Wed, 31 Oct 2001 11:18:18 -0800 Subject: Why 'self' ? Message-ID: <3BE04E7A.8E2CF101@ces.clemson.edu> Hi all, It's been a while that I am working with Python and actually the only thing I really do not like about it is 'self' in the member function definitions as argument. If it has to be there anyway, it is totally redundant to write it. So, why is self there ? Thanks, Frank From loewis at informatik.hu-berlin.de Fri Oct 5 12:06:42 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 05 Oct 2001 18:06:42 +0200 Subject: Another q regarding expat References: <9phs8j$18dc@r02n01.cac.psu.edu> Message-ID: Rajarshi Guha writes: > /usr/lib/python2.2/pyexpat.py:85: RuntimeWarning: Python C API version > mismatch for module dcpyexpat: This Python has API version 1011, module > dcpyexpat has version 1010. [...] > I get the mess above! I've noticed similar errors with other packages > (especially pygtk) - how can I fix version mismatches? Only through recompilation. > The second error seems more involved? I have expat installed - am I missing > any extra files? If you have libexpat.{a,so} installed, you still need to recompile pyexpat.so; you cannot use a pyexpat RPM from a different Python release. After you've installed libexpat, you need to recompile Python, or atleast re-run Python's setup.py to get a recompiled pyexpat.so. Regards, Martin From spamfreenation at nigenet.org.uk Fri Oct 12 07:20:05 2001 From: spamfreenation at nigenet.org.uk (nice.guy.nige) Date: Fri, 12 Oct 2001 12:20:05 +0100 Subject: YOU ARE ALL GAY! References: Message-ID: <9q6jkt$lrvqm$1@ID-112325.news.dfncis.de> "Geoffrey Pointer" wrote in message news:B7ECB739.83A4%geoffrey at bigpond.net.au... [...] > Thanks Nigel, I realise my error and you have clearly demonstrated that > education doesn't have to be a humiliating experience. Heck, I know I'm not > perfect. Hi Geoff, Hmmm... well.... now you have posted the original message... and it still makes absolutely no sense whatsoever! Cheers ;-) Nige -- Nigel Moss Visit me on the webby thing! http://www.nigenet.org.uk Boycott E$$O!! http://www.stopesso.com From jonathan.2.wilkinson at bt.com Tue Oct 9 10:21:57 2001 From: jonathan.2.wilkinson at bt.com (jonathan.2.wilkinson at bt.com) Date: Tue, 9 Oct 2001 15:21:57 +0100 Subject: Python & Zope Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20EBACBEB@mbtlipnt02.btlabs.bt.co.uk> Anyone, I'm trying to do this incredibly simple python script in zope: - myfile = open('myfile', 'w') myfile.write('hello\n') myfile.close() It works from a python interpreter fine......but when I try to test it I get Error Type: NameError Error Value: global name 'open' is not defined Any ideas how to read/write a text file in zope using python?????Can it be done? Any other methods of writing and reading randomly (well structured sort of way, but from anywhere within the file) in zope?? Please help, Regards, Jono From sholden at holdenweb.com Thu Oct 4 14:31:52 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 14:31:52 -0400 Subject: Mutable default values for function parameters References: <7da8d8f8.0110040056.42443bb@posting.google.com> <3BBCA084.B10B6061@alcyone.com> Message-ID: <0T1v7.4$rq1.2363@atlpnn01.usenetserver.com> "Erik Max Francis" wrote in message news:3BBCA084.B10B6061 at alcyone.com... > sebastien wrote: > > > I'd like to point something that is said in ?4.7.1 of the tutorial: > > > > "Important warning: The default value is evaluated only once. This > > makes a difference when the default is a mutable object such as a list > > or dictionary" > > > > I think that this point is really difficult to understand. That means > > that parameters with mutable default value are global to all the calls > > of the function: > ... > > > > This is a really confusing and I always fall in this sort of trap. > > Maybe a bad neuronal connection;-) > > I avoid this problem by simply never using a mutable object as a default > argument, but instead always using a sentinel value that's substituted > in the function body: > > def sample(x, d = None): > if d is None: > d = [] > d.append(x) > print d > > To be honest, I can't remember ever running into this pitfall, since > I've used this pattern ever since I started using Python, and happened > to be made aware of the rule before encountering the wrong end of it. > I've used this idiom myself many times. I eventuallu decided it was shorter as def sample(x, d = None): d = d or [] d.append(x) print d but this looks so weird I'd appreciate confirmation that it's a valid replacement. tormented-by-self-doubt-ly y'rs - steve -- http://www.holdenweb.com/ From salemail at dial.pipex.com Thu Oct 18 04:34:17 2001 From: salemail at dial.pipex.com (Kevin D) Date: 18 Oct 2001 01:34:17 -0700 Subject: Conditional Expressions don't solve the problem References: Message-ID: Hi Dale, Dale Strickland-Clark wrote in message news:... > But worst of all is that I can't assign a value and test it at the > same time. It means I have to add at least an extra line of code and I > have to retype a variable name. It makes for more verbose code and it > reduces my productivity. Are you sure you need to "assign a value and test it at the same time" ? Are you saying that just because that's what you're used to from C ? What are the _problems_ you encounter that make you wish for this feature ? What are the alternative solutions to those problems ? Regards, Kev. From frandebo at latt.if.usp.br Tue Oct 2 14:36:30 2001 From: frandebo at latt.if.usp.br (Francisco Borges) Date: Tue, 2 Oct 2001 15:36:30 -0300 Subject: [?] sorting files by modification time. Message-ID: <20011002153630.A4596@latt.if.usp.br> Hello all, I want to list some files in a directory and sort them by the modification time. As far as I could tell, I can't do that with os.listdir and neither with glob, is this right? I thought about >>> os.system('ls -t') but it will thrown the output to stdout. Is there a simpler way to do this than start messing with the stdout or with the shell??? thank you for your attention, -- Francisco. __o `\<, _____(*)/(*)_____ From sdm7g at Virginia.EDU Wed Oct 31 13:05:33 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Wed, 31 Oct 2001 13:05:33 -0500 (EST) Subject: Freeware Python editor In-Reply-To: <3BE0240A.A2CCAA83@alcyone.com> Message-ID: On Wed, 31 Oct 2001, Erik Max Francis wrote: > Oleg Broytmann wrote: > > > And, BTW, "free to use" is not free in the sense I prefer. I'd > > better > > read free code. And free code is the code I can read, modify and > > distribute. I hope I do not start yet another GNU flame war. :) > > "Freeware" has a well-defined meaning that predates open source > initiatives. The sense it was used in this case was correct, so > complaints about _free_ not being defined the way _you_ prefer it are > irrelevant. Yeah, but not all of us are that old, Max! ;-) I only go back to the PDP-11 days, when freeware was something I got on a 9 inch reel from a DECUS tape copying party! -- Steve Majewski From max at alcyone.com Fri Oct 12 15:04:04 2001 From: max at alcyone.com (Erik Max Francis) Date: Fri, 12 Oct 2001 12:04:04 -0700 Subject: dictionary.update() enhancement? References: <3BC64CC4.444A77E7@alcyone.com> Message-ID: <3BC73EA4.D9994ED8@alcyone.com> Mark J wrote: > Because it's not as straight-forward as saying d.update(other, > collision_handler) and it's about 10 times slower. Ten times slower? What in the world gives you that idea? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ You're a fighter, so fight / Wake up and live \__/ Sweetbox Alcyone Systems / http://www.alcyone.com/ Alcyone Systems, San Jose, California. From dalke at dalkescientific.com Fri Oct 19 07:10:08 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 19 Oct 2001 05:10:08 -0600 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net><9ql9l5$tcr$1@slb5.atl.mindspring.net><9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> Message-ID: <9qp1o9$3fh$1@slb2.atl.mindspring.net> Markus Schaber: >Maybe this form could be expanded to allow: > >do > some > statements >while cond: > something > else This post is exactly why this topic needs to be written up in a PEP - even if the decision is not to implement it. This same proposal has come up many, many times and I would like to say "Yep, look at PEP 12345" Huaiyu Zhu? Want to finish up your PEP? Andrew dalke at dalkescientific.com From 19ir01 at wxs.nl Tue Oct 16 06:35:01 2001 From: 19ir01 at wxs.nl (19IR01 Jan) Date: Tue, 16 Oct 2001 12:35:01 +0200 Subject: Digest Number 3383 References: <1003227605.1021.85895.m12@yahoogroups.com> Message-ID: <003201c1562e$36998680$90a979c3@janmeij4> please unsubscribe me from this list , some joker added me , I am not interested ,merci, 19ir01 at wxs.nl ----- Original Message ----- From: To: Sent: Tuesday, October 16, 2001 12:20 PM Subject: Digest Number 3383 > There are 22 messages in this issue. > > Topics in this digest: > > 1. Re: FW: [Python-Dev] conditional expressions? > From: Carel Fellinger > 2. Re: FW: [Python-Dev] conditional expressions? > From: Carel Fellinger > 3. Re: BINARY DATA, SCIPY, MIO (...again) > From: Travis Oliphant > 4. Re: FW: [Python-Dev] conditional expressions? > From: Paul Rubin > 5. Re: TKinter PhotoImage Class?? - 2nd round > From: "Fredrik Lundh" > 6. PoPy and Large Object Operations > From: John Bell > 7. Re: Telnetlib - send brk > From: "Patrick Vrijlandt" > 8. Re: FW: [Python-Dev] conditional expressions? > From: Anthony Baxter > 9. Beijing Tangfeng Culture Exchange Centre > From: office at tangfeng.org > 10. Statements vs. expressions (was Re: Loop-and-a-half (Re: Curious assignment behaviour) > From: Ville Vainio > 11. Re: newbie printing question > From: Martin Franklin > 12. Re: TkTable > From: Martin Franklin > 13. Re: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) > From: "Anders J. Munch" > 14. Zope consultant needed UK > From: Simon Martin > 15. Re: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) > From: Paul Rubin > 16. Beijing Tangfeng Culture Exchange Centre > From: office at tangfeng.org > 17. Re: FW: [Python-Dev] conditional expressions? > From: gbreed at cix.compulink.co.uk > 18. Whereabouts of Python port of Template Toolkit? > From: hamish_lawson at yahoo.co.uk (Hamish Lawson) > 19. Re: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) > From: Michael Abbott > 20. Re: [Python-Dev] conditional expressions? > From: "Anders J. Munch" > 21. Re: [Python-Dev] conditional expressions? > From: Michael Abbott > 22. feeding SAX > From: mallum > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 1 > Date: 16 Oct 2001 06:27:32 +0200 > From: Carel Fellinger > Subject: Re: FW: [Python-Dev] conditional expressions? > > Paul Rubin wrote: > > m.faassen at vet.uu.nl (Martijn Faassen) writes: > >> * list comprehensions are signalled by the fairly clear [ and ]. > >> Conditional expressions use the already fairly strongly > >> overloaded ( and ). Of course I guess they wouldn't really > >> overload them further, but.. > > > A conditional expression analogy to list comprehensions would be > > x = (a if b else c) > > though I think I like this spelling more, you mixed up a and b, and > that's probably a likely mistake, so a big disadvantage. On the other > hand this clearly looks like an expression to me, a big advantage. > > > rather than > > x = if a then b else c > > I've only once been exposed to Algol-60, to short to get familiar with > the use of a conditional statement disguised as an if *statement* but > I sure would like parens to be required in far more situations then > the current patch as it helps me to read it as an expression at a > glance. I think about the only place were I feel the extra parens > don't help is in a simple parameter list. > -- > groetjes, carel > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 2 > Date: 16 Oct 2001 06:39:12 +0200 > From: Carel Fellinger > Subject: Re: FW: [Python-Dev] conditional expressions? > > Carel Fellinger wrote: > .. > >> x = if a then b else c > > > I've only once been exposed to Algol-60, to short to get familiar with > > the use of a conditional statement disguised as an if *statement* but > > conditional *expression* that should read, proving how confusing it is to me:) > -- > groetjes, carel > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 3 > Date: Mon, 15 Oct 2001 23:36:01 -0400 > From: Travis Oliphant > Subject: Re: BINARY DATA, SCIPY, MIO (...again) > > > A version of scipy had a typo in mio.py so that > Tupletype should have been TupleType > > >>> from scipy import * > > >>> help(io.fopen.fort_read) > > fort_read(fmt, dtype=None) > > Read a Fortran binary record. > > Inputs: > > fmt -- If dtype is not given this represents a struct.pack > format string to interpret the next record. Otherwise this > argument is ignored. > dtype -- If dtype is not None, then read in the next record as > an array of type dtype. > > Outputs: (data,) > > data -- If dtype is None, then data is a tuple containing the output > of struct.unpack on the next Fortan record. > If dtype is a datatype string, then the next record is > read in as a 1-D array of type datatype. > > > There are two ways to call this method of the object returned by fopen: > > 1) output_tuple = fid.fort_read() > > 2) 1darray = fid.fort_read(whatever, dtype='double') > > You probably whan the second method to read in a fortran record (created > by each write statement in your Fortran code) as an array of real*8 values > > -Travis > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 4 > Date: 15 Oct 2001 22:58:13 -0700 > From: Paul Rubin > Subject: Re: FW: [Python-Dev] conditional expressions? > > Carel Fellinger writes: > > > A conditional expression analogy to list comprehensions would be > > > x = (a if b else c) > > > > though I think I like this spelling more, you mixed up a and b, and > > that's probably a likely mistake, so a big disadvantage. On the other > > hand this clearly looks like an expression to me, a big advantage. > > To have the same meaning as the other example, yes. I should have not > just copied the letters from the other example. > > Thinking about it, I like this syntax more too, but since I think > parenthesized S-expressions are the one true syntax, I'm not too fussy > about which imperfect substitute gets chosen ;-). > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 5 > Date: Tue, 16 Oct 2001 06:33:40 GMT > From: "Fredrik Lundh" > Subject: Re: TKinter PhotoImage Class?? - 2nd round > > Robert C. Ramsdell wrote: > > When I try the method above in the method, the Canvas remains empty. > > No errror message is given, the image just is not displayed. Does anyone > > know why this is happening? > > you must keep a reference to the PhotoImage object. see > FAQ question 4.69 for a bit more information: > > http://www.python.org/doc/FAQ.html#4.69 > > > def draw_image(self, iname): > > self.drawspace.pack() > > i=PIL.ImageTk.PhotoImage(file=iname) > > self.photo = i > > > self.drawspace.create_image(0,0,image=i) > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 6 > Date: Tue, 16 Oct 2001 14:51:40 +0800 > From: John Bell > Subject: PoPy and Large Object Operations > > Could someone give me a pointer on how to use PoPy for Binary Large > Object operations. Ie import/Export type Ops. Unfortunately the PoPy > site is never up and I can find nothing helpful either on the net or in > the source. > > John > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 7 > Date: Tue, 16 Oct 2001 09:12:47 +0200 > From: "Patrick Vrijlandt" > Subject: Re: Telnetlib - send brk > > > "Donnie Miller" > > I've been trying the telnetlib library rather than using expect > > scripts as I have done in the past. I have had success with it up until > > the point where I needed to send a "break" sequence to a server. I have > > searched all over various lists and google, but have not found > > anything. Does anyone have any idea of how to do this? > > Telnetlib provides no way to send telnet control characters: > > IAC = chr(255) # Interpret As Command > DONT = chr(254) # > DO = chr(253) # > WONT = chr(252) # > WILL = chr(251) # > SB = chr(250) # Subnegotiation Begin > GA = chr(249) # Go Ahead > EL = chr(248) # Erase Line > EC = chr(247) # Erase Char > AYT = chr(246) # Are You There > AO = chr(245) # Abort Output > IP = chr(244) # Interrupt Process > BRK = chr(243) # NVT-Break > DM = chr(242) # Data Mark > NOP = chr(241) # No Operation > SE = chr(240) # Subnegotiation End > > So you have to patch the write method, originally: > > def write(self, buffer): > if IAC in buffer: > buffer = buffer.replace(IAC, IAC+IAC) > self.msg("send %s", `buffer`) > self.sock.send(buffer) > > so that BRK (and the other telnet commands) also is/are prepended by an IAC > character. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 8 > Date: Tue, 16 Oct 2001 17:38:46 +1000 > From: Anthony Baxter > Subject: Re: FW: [Python-Dev] conditional expressions? > > > Ok, so we're getting yet another ugly hack added to the language. > Could the normal process of writing up a PEP be followed, so that > those people in the community who are uncomfortable about it can > at least see the justification for this? > > Or has the PEP already been written, and I'm just going mental - it > doesn't appear to be on the PEP page... > > Anthony > > -- > Anthony Baxter > It's never too late to have a happy childhood. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 9 > Date: Tue, 16 Oct 2001 15:45:09 +0800 > From: office at tangfeng.org > Subject: Beijing Tangfeng Culture Exchange Centre > > > > [This message is not in displayable format] > > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 10 > Date: 16 Oct 2001 10:31:35 +0300 > From: Ville Vainio > Subject: Statements vs. expressions (was Re: Loop-and-a-half (Re: Curious assignment behaviour) > > huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) writes: > > > Agreed generally. A clarification, though: the proposal does not allow > > statements in expressions; it allows statements _between_ conditional > > keywords and the corresponding expressions, like > > > > while [ ; ] : > > if [ ; ] : > > By the way, what is the big win with having statements in the > language, as opposed to just having expressions (possibly returning > 'Unit' or something similar)? > > -- > Ville Vainio - http://www.tp.spt.fi/~vvainio - ICQ #115524762 > Wild geese have no intention to cast a reflection > Water has no mind to assume their form > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 11 > Date: Tue, 16 Oct 2001 08:45:26 +0100 > From: Martin Franklin > Subject: Re: newbie printing question > > adina_levin at mindspring.com wrote: > > > I'd like to create a string with the current date and time. I've got the > > mxDateTime library, so far so good. > > > > print mxDateTime.now() will generate the date and time to the screen. > > write will send it to a file. > > > > But how can I assign this to a string? > > > > I will be most thankful and embarrassed to hear the answer to this > > question. It oughta be obvious! > > > > > > > > To create a string variable I guess you need to assign it like so: > > TimeNow=mxDateTime.now() > > print TimeNow > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 12 > Date: Tue, 16 Oct 2001 08:54:16 +0100 > From: Martin Franklin > Subject: Re: TkTable > > Janos Blazi wrote: > > > Is there a way to use tkTable from within Tkinter? > > > > Thx in advance, J.B. > > > > > > > > > > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- > > http://www.newsfeeds.com - The #1 Newsgroup Service in the World! > > Check out our new Unlimited Server. No Download or Time Limits! > > -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- > > > > Google (TkTable python) turns this up...... > > http://starship.python.net/crew/pgodman/ > > > HTH > Martin > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 13 > Date: Tue, 16 Oct 2001 10:12:13 +0200 > From: "Anders J. Munch" > Subject: Re: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) > > > "Tim Peters" wrote in message > news:mailman.1003176136.32708.python-list at python.org... > > For anyone keen to play with this, Guido has uploaded a patch. It > > requires surrounding parens in fewer places than has been discussed so > far: > > > > > 05470> > > > > > """It's hairier than expected because I'm trying to > require you to put parentheses around it in some cases > but not in others.""" > > For simplicity and consistency I think mandatory parentheses are > better. > > Combine that with the form mentioned (though not preferred) by Michael > Abbott elsewhere we get: > > x = (if e1: e2 else: e3) > > No new keyword, consistent with if-statement syntax and hence more > intuitive to someone who knows Python but not a heap of other > languages as well. And it's slightly more terse than the if-then-else > form, which is important because terseness is the only reason to use a > conditional expression in the first place. > > - Anders > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 14 > Date: Tue, 16 Oct 2001 09:15:10 +0100 > From: Simon Martin > Subject: Zope consultant needed UK > > Dear Group, > > Hope this isn't inappropriate... > > We need a really good Zope consultant for a very ambitious open source > project. Anyone out there in the Herts/London area? Please get in touch > so we can talk, I'm not interested in going through agencies etc at this > stage. > > Many thanks > > Simon > -- > Simon Martin > London Uk > 020 8386 5828 > PGP KEY ID <0xFA69D420> @ > *Please note my e-mail address is now 'simonmartin at mail105.com'* > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 15 > Date: 16 Oct 2001 01:31:11 -0700 > From: Paul Rubin > Subject: Re: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) > > "Anders J. Munch" writes: > > Combine that with the form mentioned (though not preferred) by Michael > > Abbott elsewhere we get: > > > > x = (if e1: e2 else: e3) > > > > No new keyword, consistent with if-statement syntax and hence more > > intuitive to someone who knows Python but not a heap of other > > languages as well. And it's slightly more terse than the if-then-else > > form, which is important because terseness is the only reason to use a > > conditional expression in the first place. > > Hey, I like that one too. You could even include an elif: > x = (if e1: v1 elif e2: v2 else: v3) > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 16 > Date: Tue, 16 Oct 2001 16:44:50 +0800 > From: office at tangfeng.org > Subject: Beijing Tangfeng Culture Exchange Centre > > > > [This message is not in displayable format] > > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 17 > Date: Tue, 16 Oct 2001 09:00:05 +0000 (UTC) > From: gbreed at cix.compulink.co.uk > Subject: Re: FW: [Python-Dev] conditional expressions? > > In article <9qgcvk$91j$1 at animus.fel.iae.nl>, cfelling at iae.nl (Carel > Fellinger) wrote: > > > > A conditional expression analogy to list comprehensions would be > > > x = (a if b else c) > > > > though I think I like this spelling more, you mixed up a and b, and > > that's probably a likely mistake, so a big disadvantage. On the other > > hand this clearly looks like an expression to me, a big advantage. > > You can also remove the parentheses, and not have to worry about the "if" > starting a new line. > > > Graham > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 18 > Date: 16 Oct 2001 02:31:11 -0700 > From: hamish_lawson at yahoo.co.uk (Hamish Lawson) > Subject: Whereabouts of Python port of Template Toolkit? > > I remember once before coming across a Python port of the Template > Toolkit library for Perl. However my attempts to find it again have so > far turned out fruitless. Does anyone know where I can get hold of it? > (Note that Template Toolkit shouldn't be confused with HTML::Template, > of which there is also a Python port - htmltmpl.) > > Thanks, > Hamish Lawson > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 19 > Date: Tue, 16 Oct 2001 09:34:18 +0000 (UTC) > From: Michael Abbott > Subject: Re: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) > > Paul Rubin wrote in > news:7xelo4yoj4.fsf at ruckus.brouhaha.com: > > > "Anders J. Munch" writes: > >> Combine that with the form mentioned (though not preferred) by Michael > >> Abbott elsewhere we get: > >> > >> x = (if e1: e2 else: e3) > >> > >> No new keyword, consistent with if-statement syntax and hence more > >> intuitive to someone who knows Python but not a heap of other > >> languages as well. And it's slightly more terse than the if-then-else > >> form, which is important because terseness is the only reason to use a > >> conditional expression in the first place. > > > > Hey, I like that one too. You could even include an elif: > > x = (if e1: v1 elif e2: v2 else: v3) > > I have to say I prefer the emerging form > > x = if e1 then v1 elif e2 then v2 else v3 > > The parentheses are certainly not required, and can always be added by > those who like to use them. > > I'm pretty sure that > > x = if e1: v1 elif e2: v2 else: v3 > > will work without the brackets; again, bracket enthusiasts can add them to > taste! > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 20 > Date: Tue, 16 Oct 2001 11:27:42 +0200 > From: "Anders J. Munch" > Subject: Re: [Python-Dev] conditional expressions? > > "Tim Peters" wrote in message > news:mailman.1003177394.3900.python-list at python.org... > > Following is good clarification from Guido (on Python-Dev) about "the > rules" currently implemented by his patch. > [...] > > Some examples where no parentheses are needed (note that a comma binds > > less tight than a conditional expression -- same as for lambda): > > > > x = if 1 then 2 else 3, y > > f(if 1 then 2 else 3, y) > > a[if 1 then 2 else 3, y] > > `if 1 then 2 else 3` > > lambda: if 1 then 2 else 3 > > I see a problem with adding precedence rules. There doesn't seem to > be a natural precedence for the conditional expression operator. C > and C++ have been struggling with this for years; C and C++ have > different rules for this; compilers have warnings that say "Suggest > parentheses to clarify precedence". After 14 years of C and C++ > programming I still couldn't tell you the precedence of ?: even if I > wanted to. > > Quick, what does this snippet do if return_as_map is true? > > return if return_as_map then {'A':a,'B':b} else a,b > > Rather than open up a new venue of obfuscation possibilities in > Python, I'd go for mandatory parentheses around the conditional > expression. > > - Anders > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 21 > Date: Tue, 16 Oct 2001 09:36:24 +0000 (UTC) > From: Michael Abbott > Subject: Re: [Python-Dev] conditional expressions? > > "Anders J. Munch" wrote in > news:3bcbfda6$0$42081$edfadb0f at dspool01.news.tele.dk: > > > Quick, what does this snippet do if return_as_map is true? > > > > return if return_as_map then {'A':a,'B':b} else a,b > > > > Rather than open up a new venue of obfuscation possibilities in > > Python, I'd go for mandatory parentheses around the conditional > > expression. > > Nah. Go for "maximal munch", I can't think of anything wrong with that. > The above expression then returns the dictionary (only). > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 22 > Date: Tue, 16 Oct 2001 10:53:51 +0100 > From: mallum > Subject: feeding SAX > > hi all; > > Expat allows me to incrementally parse an XML document by 'feeding' it > the document in chunks rather than in one whole go. Is this possible > with SAX ? or do you have to give its parse function the entire > document ? > > -- Matthew Allum > > -- > http://mail.python.org/mailman/listinfo/python-list > > > ________________________________________________________________________ > ________________________________________________________________________ > > > > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ > From joonas at olen.to Mon Oct 15 15:14:17 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: Mon, 15 Oct 2001 22:14:17 +0300 Subject: Help: How to capture invalid web page from urllib? References: <3BCA5E85.E3AA0CA7@starhub.net.sg> Message-ID: <3BCB3589.D5E957D2@olen.to> Paul Lim wrote: > Hi, > > I am a newbie in Python. I hope the guru can advise me on the following > > I am trying to open a web page from command line. If the web page is not > valid, I hope to capture the exception and print an error message and > exit. > > What I currently have is as below, but I am certain I used the wrong > class because I did not managed to capture the exception (if any) raise. > > Could someone teach me how to test the validity of a web page, ie > whether does it exist, can it be open? > > Sincerely > Paul > > # If web page is entered, check whether it is a valid web page > try: > inf = urllib.URLopener.http_error_default(sys.argv[1]) > except IOError: > print "Invalid webpage!" > print "Usage : ./webmap.py http://server-name/path-to-document" > sys.exit() Use httplib module instead and examine the value returned by h.getreply() . See example at http://www.python.org/doc/current/lib/httplib-examples.html From dale at riverhall.NOTHANKS.co.uk Sun Oct 28 04:55:06 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Sun, 28 Oct 2001 09:55:06 +0000 Subject: binary search tress using classes References: Message-ID: "Terry Reedy" wrote: > > wrote in message >news:mailman.1004246848.30973.python-list at python.org... >> Hi, >> I was wondering if anyone had a binary search tree module I could >> use? I need to write a program that counts the number of occurrences >> of each word in a file, and outputs the word and corresponding >counts >> alphabetically. For example, if input is > >The way to do this in Python is with a dictionary. Without being >fancy about the definition of 'word', you need 10 lines or less for >the whole program. I believe I've seen the code posted. Using >classes and 'modularity' is way overkill. > >Terry J. Reedy > I suspect this is a college project. It pops up almost identically every now and then. -- Dale Strickland-Clark Riverhall Systems Ltd From kwg at renre-europe.com Tue Oct 9 05:40:54 2001 From: kwg at renre-europe.com (Ken Guest) Date: 09 Oct 2001 10:40:54 +0100 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <23891c90.0110090118.7df7917e@posting.google.com> References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> <9pimak$c22$1@tyfon.itea.ntnu.no> <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> <3BBE4E12.16FE036A@earthlink.net> <9pn44q$m1r$1@tyfon.itea.ntnu.no> <3BBF2751.3010309@sneakemail.com> <23891c90.0110090118.7df7917e@posting.google.com> Message-ID: <1002620459.27499.1.camel@lewis> On Tue, 2001-10-09 at 10:18, Paul Boddie wrote: > Joshua Macy wrote in message news:<3BBF2751.3010309 at sneakemail.com>... > > > Moses is to the Bible what Tim Peters is to Strunk and White (or > should it be the other way round?)-ly, and what exactly does this have to do with python? I thought this was a python list not a linquistics list. k. From graz at mindless.com Tue Oct 30 04:15:22 2001 From: graz at mindless.com (Graham Ashton) Date: Tue, 30 Oct 2001 09:15:22 GMT Subject: Representing tuples in strings References: <2SmD7.3702$Ey1.438112@news1.cableinet.net> <3BDE098F.78DE210B@alcyone.com> Message-ID: In article <3BDE098F.78DE210B at alcyone.com>, "Erik Max Francis" wrote: > ', '.join(map(repr, myTuple)) Thanks everyone. -- Graham From logiplexsoftware at earthlink.net Wed Oct 24 21:41:36 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 24 Oct 2001 18:41:36 -0700 Subject: smtp In-Reply-To: <9r6t3n.3vvbepd.1@kserver.org> References: <9r6t3n.3vvbepd.1@kserver.org> Message-ID: <01102418413605.24656@logiplex1.logiplex.net> On Wednesday 24 October 2001 17:17, Sheila King wrote: > AOL intercepts all Port 25 traffic. Therefore, you cannot send outbound > mail to a non-AOL smtp server via an AOL Internet connection. Thanks, Sheila. I suspected AOL, but couldn't prove it. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From loewis at informatik.hu-berlin.de Mon Oct 1 12:51:40 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 01 Oct 2001 18:51:40 +0200 Subject: sameness/identity References: <1584523.dEvYhyI6sB@lunix.schabi.de> Message-ID: Oleg Broytmann writes: > This is really hardcoded limit in the current CPython implementation :) > The interpreter preallocates numbers from 0 to 99. It's not really preallocation, rather lazy allocation and caching; see intobject.c:PyInt_FromLong: static PyIntObject *small_ints[NSMALLNEGINTS + NSMALLPOSINTS]; ... if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS && (v = small_ints[ival + NSMALLNEGINTS]) != NULL) { Py_INCREF(v); return (PyObject *) v; } ... PyObject_INIT(v, &PyInt_Type); v->ob_ival = ival; if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) { /* save this one for a following allocation */ Py_INCREF(v); small_ints[ival + NSMALLNEGINTS] = v; } return (PyObject *) v; The constants are 1 and 100, respectively. Regards, Martin From madsdyd at challenge.dk Mon Oct 1 04:21:17 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 10:21:17 +0200 (CEST) Subject: Python embedding & question about autoconf and dynamic linking In-Reply-To: <9p4t2u$li0$1@chabry.caltech.edu> Message-ID: On 29 Sep 2001, Titus Brown wrote: > In article , > Mads Bondo Dydensborg wrote: > >Hi there > > > >I am trying to use Python as an embedded interprenter. Whilst it is quite > >easy to understand the C interface, I have found it _very_ hard to figure > >out what flags I need to pass to the linker to get a succesfull > >compile. It seems to depend rather heavily on a lot of parameters. > > Yep. At least I have that right ;-) > > >So, my first question is if there are any autoconf macros out there that > >will work for me, sort of like a AM_PATH_SDL macro? I have been searching > >around, and found one from on of the KDE libs, but it seems to break > >rather quickly for everything else than Python 1.5 (which it seems to be > >only partly succesfull in anyway). > > I haven't found one in distutils, either, which seems like a natural > place for them. > > Please let me know if you get a list sent to you privately; I'm very > interested in this for 'configure'ing PyWX... No luck so far. (I am quoting most of my original post in case someone in knowledge will notice). I will continue to hack on the KDE_CHECK_PYTHON script - what are you using for PyWX? > > >My next question is with respect to dynamicly linking to the python > >interprenter, when embedding it. All info I have been able to find, points > >towards linking statically with libpython..a - however, this adds > >about 660KB to my application, and in general I would much rather link to > >a .so file - but I have not been able to find "such a beast" or > >instructions on how to build one. Is it possible? Or is there a clever > >way arond this kind of problem that I - beeing a clueless newbee - have > >totally overlooked? (Maybe some weird extension trickery?) > > There used to be an explicit FAQ entry on this, in > > http://www.python.org/doc/FAQ.html > > entry 3.11 or thereabouts. It's gone now ;(. At least I didn't overlook it :-) > For older versions, you should be able to do something like this: > > make CFLAGS=-fpic > mkdir .shared > cd .shared > ar xv ../libpython.a > gcc -shared -o ../libpython.so *.o Hmm. So, I should actually be able to create a .so on an endusers machine, _if_ the original python installation was built with -fpic. Otherwise I have to recompile the python installation. Not a nice thing. Are there any particular reason that python does not "come as a so" on Linux and Solaris? (Or other .so enabled platforms). Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk You know you're a Linux geek when... You keep track of your highest uptime, and try to break your record. - segfault From mlh at idi.ntnu.no Sat Oct 20 22:39:49 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 21 Oct 2001 04:39:49 +0200 Subject: Magic Module Methods? References: <9qsmsg$afb$1@tyfon.itea.ntnu.no> Message-ID: <9qtchl$k36$1@tyfon.itea.ntnu.no> "John Roth" wrote in message news:tt4d2ohho6aq77 at news.supernews.com... > > "Magnus Lie Hetland" wrote in message > news:9qsmsg$afb$1 at tyfon.itea.ntnu.no... [snip] > It would require refactoring the clients to call the > function, but IMO that would be clearer in any case. I guess so. But the same could be said about replacing use of __getattr__ with methods. It doesn't mean that __getattr__ can't be useful (IMO). > John Roth -- Magnus Lie Hetland http://hetland.org From guido at python.org Tue Oct 16 13:46:56 2001 From: guido at python.org (Guido van Rossum) Date: Tue, 16 Oct 2001 17:46:56 GMT Subject: Conditional Expressions don't solve the problem References: Message-ID: Dale Strickland-Clark writes: > I'm a bit mystified by all the activitiy on conditional expressions > that appears to have originated from a post a while ago about curious > assignment behaviour. > > Have I missed something here (quite possible) or are the two issues > related? Because it doesn't seem so to me. > > The original discussion went on to talk about the loop and a half > problem which sumarised it quite nicely for me. [...] > How does the if/then/else construct help me here? It doesn't. But it's a good thing you mentioned this, because it gives me the opportunity to elaborate on some of my language design sensibilities. I find a conditional expression useful IN SOME CASES where the requirement to use a separate if statement and a temporary variable interrupt the thought process of a human reader trying to understand the code. On the other hand, the ability to hide an assignment inside an expression is IMO purely a way to save some keystrokes: the variable needs to be named anyway, so you may as well do the assignment in a separate step so that the reader is alerted of it. That said, I'm still looking for decent examples of places in the standard library that would become more readable with a conditional expression... Without more motivation, I think I'll hold back. --Guido van Rossum (home page: http://www.python.org/~guido/) From mlh at idi.ntnu.no Sun Oct 21 00:23:22 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 21 Oct 2001 06:23:22 +0200 Subject: silly idea - interesting problem References: <3BD248BA.2163BBDB@hotmail.com> Message-ID: <9qtijq$miu$1@tyfon.itea.ntnu.no> "scott" wrote in message news:3BD248BA.2163BBDB at hotmail.com... > > Stefan Antoni wrote: > > > > i got a silly idea about a small script which takes to strings (lets say > > "test" and "dust") and mixes them to "tdeusstt". > > i tried to code it because i thought it would be easy, but now i cannot > > find out _how_ to do it ;) > > > > i tried to "list()" the string and mix the items. but ... > > > > Anybody has a hint or even a solution? > > > > Here's a back to basics solution: > > firstWord = 'test' > secondWord = 'dust' > i = 0 > while i < len(firstWord): > print firstWord[i], secondWord[i], > i = i+1 This will give spaces between every word... How about a less readable version which actually works : print ''.join([x+y for (x,y) in zip('test', 'dust')]) > P.S.: Remember when Python used to differentiate itself from line noise > (sorry, I meant Perl) with a philosophy that went something like > "There's only one right way to do it."? Yes... Those were the days A version with spacing (like yours) which is a bit more readable (than my previous one) would be: for firstLetter, secondLetter in zip(firstWord, secondWord): print firstLetter, secondLetter, One without the spaces could be: result = '' for a, b in zip('test', 'dust'): result += a+b print result Yeah... I think I like that one. (Although using a list and then doing a join on that would probably be more efficient...) ---------------------------------------------------------------------- Magnus Lie Hetland http://hetland.org From seb at tesco.net Mon Oct 29 18:41:31 2001 From: seb at tesco.net (seb) Date: Mon, 29 Oct 2001 23:41:31 GMT Subject: Multiple postings References: <3bdde77f.4166130@news.tesco.net> Message-ID: <3bdde90d.4564713@news.tesco.net> On Mon, 29 Oct 2001 23:36:24 GMT, seb at tesco.net (seb) wrote: >On Mon, 29 Oct 2001 07:07:10 -0500, "Steve Holden" > wrote: > >>Sorry about the recent spate of duplicated postings. A glitch in my mail >>server meant that it was accepting postings without telling my news client >>they had been taken. >> >>regards >> Steve >>-- >>http://www.holdenweb.com/ >> >> >> >> >> >Har, har. > >A post about duplicate posts being duplicated. Excellent. > > >seb. > From gerrit.muller at philips.com Tue Oct 9 10:30:28 2001 From: gerrit.muller at philips.com (Gerrit Muller) Date: Tue, 09 Oct 2001 16:30:28 +0200 Subject: What to do: COM server runaway. Message-ID: <3BC30A04.89449639@philips.com> I try to automate the production of eps images, using Visio 5.0C and Python 2.1.1 from Activestate. Some (very trivial) diagrams bring Visio in a 100% CPU utilization/not responding state. I tried to use the Export function, which works well for some files and not at all with others. Are there known causes for this type of COM mis behavior? After killing the runaway Visio application, the errormessage from my exception handler is that there is insufficient memory. Any suggestions? -- -------------------------------------------------------------------- Gerrit Muller Philips Research Laboratories Eindhoven Building: WDC 2 - 007 Prof. Holstlaan 4 Phone: +31 40 27 45242 5656 AA Eindhoven Fax: +31 40 27 45033 The Netherlands mailto:gerrit.muller at philips.com http://www.extra.research.philips.com/natlab/sysarch/index.html From john at yates-sheets.org Sat Oct 27 07:37:29 2001 From: john at yates-sheets.org (John S. Yates, Jr.) Date: Sat, 27 Oct 2001 11:37:29 GMT Subject: hash consing Message-ID: Is it possible to implement an "immutable" python class that maintains a single instance of each unique value via hash consing? I know that I can maintain the hash table outside of the class, lookup the argument tuple for the class instance I want and only call the constructor when I the lookup fails. What I would really like is to be able to hide that logic inside the constructor. /john -- John Yates 40 Pine Street Needham, MA 02492 781 444-2899 From claird at starbase.neosoft.com Thu Oct 4 18:24:45 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 4 Oct 2001 17:24:45 -0500 Subject: Zope vs PHP for the Linux guru References: Message-ID: In article , Mark wrote: > >I've been doing web app development for the last 3 years using php. I >already plan on learning Python to use as a rapid GUI development >language(maybe even replace some of my perl-use) and was curious about Zope. > >I currently develop applications using php to query both remote and local >databases. I use local MySQL databases for fast read-only queries, and use a >remote MS SQL 2000 database for storing mutable data. > >I use mod_php compiled into Apache 1.3.xx, and run php apps that range from >a few hundred lines to over 50k. DB access is through php's API using >MySQL's native libs and FreeTDS for connecting to SQL. > >On the larger php apps I use an OO design model to keep the project >managable. My smaller apps are pretty much just quickly thrown together >scripts. > >Right now I run it all on one Linux box, but have plans on creating farms >of apache servers for future scalability. > >Some questions I had about Zope where: > >Is developing apps in it a quick process? Php is a very rapid language to >develop in and that has become my most favored trait of the language. > >Does Zope have good database support? Is it faster, slower than php with >database queries? > >I'm assuming Zope will be better than php for large project development? > >Is Zope easy for newbies to learn? I'm not a newbie, but we do have >some clients learning to program on our seperate Cold Fusion server, they >find it easier than php. I'd love to get them off Cold Fusion and onto a >more cost effective open source solution. > >Does Zope scale well in large deployments? Any kind of support for web >server farming? > >Any other major differences from php? Good things about it, bad things about >it? . . . Good questions. Very good questions, in fact. It's going to be tough to answer at the same high level. Zope development is breathtakingly swift--in the hands of an expert. As wonderful as Zope is, though, it's hard to make a case that it's easy to learn. It's pro- bably the case that it lacks just the right bit of documentation, or examples, or something; in any case, newcomers consistently report rather extended intervals before they "get" the Zope way of working. In principle, you can do lots of neat stuff with Zope "out of the box". In practice, there's enough of some- thing missing from the documentation that few beginners realize at the beginning what they can do with Zope. PHP database support is unmatched. Zope supports lots of DBs, but they're not all built-in, as with PHP. On the other hand, you seem actively involved only with MySQL and SQL Server, so maybe you don't need much da- tabase support. Overall, people who try both Python and PHP generally come back to the former. CF just doesn't have many attractions, once someone's enjoying Python. HOWEVER, people like your target audience seem rather consistently to "catch on" to CF and PHP quicker than they do with Zope. Zope scales fine. There's a lot that goes into this; the one-line summary is that Zope more than holds its own. It does NOT support "Web server farming" of the sort I suspect you have in mind, though. There's no parti- cular reason it doesn't (and maybe someone's fixed this recently); it's just that no one's gone to the trouble of making it a reality. Overall, Python's just a better language than PHP, and Zope addresses an incredible range of Web service question. For doing the first two or three Web-bish things that most developers need, though, PHP has a track record of being easier to get right. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From andersjm at dancontrol.dk Thu Oct 18 09:36:07 2001 From: andersjm at dancontrol.dk (Anders J. Munch) Date: Thu, 18 Oct 2001 15:36:07 +0200 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: <3bcedae2$0$3754$edfadb0f@dspool01.news.tele.dk> "Huaiyu Zhu" wrote in message news:slrn9sruhl.ll.huaiyu at gauss.almadan.ibm.com... > I've been writing this for several evenings. It's not polished, but IMHO it > solves most of the problems discussed in this thread. So here it goes. :-) > > > PEP: Statements in Control Structures Here's an additional alternative: Use a function-like form let to perform assignment within expression. let(X,Y) has the effect of doing X = Y and returning the assigned object. Example: from sys import let while let(x, get_next()): process(x) Issues: ======= * Syntax errors. No new syntax to worry about. * Obuscation. - Python function do not usually modify caller variables. + A reader of this code who doesn't know let can find out about it using through the usual mechanism, sys.let.__doc__. * Compatibility. No compatibility issues; let is not a keyword. * Generality. Doesn't allow arbitrary statements to be executed. Does allow short circuit conditions. * Implementation. Hackish. Introducing a let keyword would be cleaner. - Anders From chrism at zope.com Wed Oct 3 08:57:18 2001 From: chrism at zope.com (Chris McDonough) Date: Wed, 03 Oct 2001 08:57:18 -0400 Subject: Zope News for October 1 Message-ID: <3BBB0B2E.9080808@zope.com> Hi Folks, The Zope News for October 1 is available from http://www.zope.org/Documentation/ZWN/ZWN-2001-10-01 Tops tories include: Zope 2.4.1 final released, Zope's CVS repository opened up to community contribution, Zope security bug found and fixed, Zope wins WebTechniques Web Tools award, OzZope gets going, and Zope.org Member areas need some attention. Have fun! - C From contest at casinoresellers.com Tue Oct 30 23:55:25 2001 From: contest at casinoresellers.com (Michael Gidge) Date: Tue, 30 Oct 2001 20:55:25 -0800 Subject: Info request Message-ID: YOUR OWN INTERNET SPORTSBOOK & CASINO STARTING @ $17,000!!! Now assembled and packaged we have the most cost effective turnkey program for you. A publicly traded company created the casino software, a billion dollar corporation?? If you would like to view one of the casino sites, please contact one of our casino Agents. They will provide you with a demonstration casino site for you to view. For a free info package and CD ROM, please contact one of our casino Agents they will be more than happy to overnight you a package, and to answer any questions that you may have regarding ownership of your very own online sportsbook and casino operation. North American toll free# 1 888-633-2259 International# 1 604-688-2310 Respectfully, Michael Gidge From greg at cosc.canterbury.ac.nz Mon Oct 29 22:08:32 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 30 Oct 2001 16:08:32 +1300 Subject: None References: <3bd5db1e$1@brateggebdc5.br-automation.co.at> <3bd7fa75$1@brateggebdc5.br-automation.co.at> <3BD8C747.3DA9EEEC@cosc.canterbury.ac.nz> <3bdd2257@brateggebdc5.br-automation.co.at> Message-ID: <3BDE19B0.586BC0A5@cosc.canterbury.ac.nz> Werner Schiendl wrote: > > Assigning to None, however, seems more likely to happen e. g. if someone > tries to drop some unwanted return values there: > > a, None, b = function1() I don't really understand what leads people to do that. I mean, in C you wouldn't think to write NULL = printf("Hi!\n"); to discard the result of something, would you? In other words, if even if someone is under the misapprehension that None is a constant, that doesn't explain why they should think they can assign to it. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From tim.one at home.com Sun Oct 28 12:59:46 2001 From: tim.one at home.com (Tim Peters) Date: Sun, 28 Oct 2001 12:59:46 -0500 Subject: interpreter crashes In-Reply-To: <7xpu7768nf.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > ... > I've also been wondering whether it could make sense to modify the gc > to check the correctness of all ref counts when the gc runs. However > I haven't yet looked at the gc code enough to tell whether this > is practical. Sorry, not even in theory. The cyclic gc in Python works by computing the transitive closure of registered objects (basically objects of cooperative container types -- objects which *can* be in cycles, and which choose to participate in gc by registering themselves), then trashing those whose refcounts are entirely accounted for by intra-closure pointers. This isn't like traditional mark-&-sweep, which computes the transitive closure of a root set, then concludes that anything allocated not in the closure must be trash: Python doesn't assume it controls memory allocation, and has no idea what the root set may be. For example, if an extension module hostile to gc allocates its own memory and stuffs pointers to Python objects in it, Python can't find that memory, or chase those pointers. But the refcounts *due* to those pointers won't be accounted for by the transitive closure of the objects Python *does* know about, so as far as cyclic gc is concerned those objects are not trash (it can't find the pointers keeping them alive, but *deduces* they must exist, from the refcount evidence). In short, Python's cyclic gc relies on correct refcounts for correct operation; it can't ensure them. Building a Python in debug mode is helpful for tracking suspected refcount bugs (e.g., in 2.2 a decref that falls below 0 will dump a msg to stderr in a debug build at the moment it goes bad). Note that if a refcount is too high, the symptom is usually memory leakage, not a crash. From graz at mindless.com Fri Oct 26 06:52:34 2001 From: graz at mindless.com (Graham Ashton) Date: Fri, 26 Oct 2001 10:52:34 GMT Subject: Tk and focusing windows References: Message-ID: In article , "Matthew Dixon Cowles" wrote: > Graham, > Tkinter doesn't make it easy to get things displayed attractively during > startup. I find that getting things to look the way I want often > requires figuring out the right places to put calls to > update_idletasks(). I'll append a small example that may help. Thanks very much for the example - I'll have a play around with that now and see if I can get it to work for me. > Of course, once you've got the right incantation for your window > manager, there's no guarantee that another window manager will do just > the same thing in response to the same requests. That's more than a bit depressing. I think I'm going to be looking at GTK pretty soon. Thanks again... -- Graham From thecalm at NOSPAM.btinternet.com Thu Oct 11 16:56:16 2001 From: thecalm at NOSPAM.btinternet.com (G. Willoughby) Date: Thu, 11 Oct 2001 21:56:16 +0100 Subject: a pure python mp3 player? Message-ID: <9q50uh$qlj$1@uranium.btinternet.com> Hi, do you know of any mp3 players that have been exclusively written in python, and not just a gui for the C coded 'mp123'? G. WIlloughby From ignacio at openservices.net Mon Oct 1 17:55:46 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Mon, 1 Oct 2001 17:55:46 -0400 (EDT) Subject: list.append problem? In-Reply-To: Message-ID: On 1 Oct 2001, newgene wrote: > I am a newer of python. I have a problem like this code: > > >>> a=b=c=[] > >>> a.append(1) > >>> b.append(2) > >>> c.append(3) > >>> a > [1, 2, 3] > >>> b > [1, 2, 3] > >>> c > [1, 2, 3] > > a,b,c become the same, although append method applied seperately. > It's really strange and unreasonable. This is because a, b, and c all contain a reference to the same list. -- Ignacio Vazquez-Abrams From jdunnett at uoguelph.ca Mon Oct 29 07:39:54 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Mon, 29 Oct 2001 07:39:54 -0500 Subject: python binary search References: Message-ID: <3BDD4E1A.607345D2@uoguelph.ca> Steve Holden wrote: > "Tim Peters" wrote in message > news:mailman.1004331032.3471.python-list at python.org... > > [Jeff Dunnett] > > >>> Duh. What an idoit I am. Poor spelling you can tell I am > > >>> not an English major or I probably would have picked up on > > >>> the ocmment. > > > > [Jeff Dunnett again, beating himself to the jab] > > >> That should say comment. > > > > [Timothy Delaney, can't resist] > > > I should resist, but I can't. > > > > > > So, what is this "it" that you do? (idoit). > > > > I expect Jeff is a philosophy major, since few others know that an > "ocmment" > > is a cutting comment about Ocmma's Razor. > > > > on-the-other-hand-"idoit"-suggest-a-physics-background-ly y'rs - tim > > > Tim: > > Was Ocmma's Razor the separator used for OSVs (Ocmma Separated Files)? I > have several that I need to read: do you have any code that will help me? > > throwing-stones-from-inside-my-glass-house-ly y'rs - steve > -- > http://www.holdenweb.com/ Actually so ya all know I am computer guy with a minor interest in history. Jeff From phd at phd.pp.ru Thu Oct 25 06:56:25 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 25 Oct 2001 14:56:25 +0400 Subject: multipart mime In-Reply-To: <9r8lur$7oqsi$1@hades.rz.uni-sb.de>; from uwe@rocksport.de on Thu, Oct 25, 2001 at 09:27:55AM +0000 References: <9r8lur$7oqsi$1@hades.rz.uni-sb.de> Message-ID: <20011025145625.E13913@phd.pp.ru> On Thu, Oct 25, 2001 at 09:27:55AM +0000, Uwe Schmitt wrote: > I'm looking for a module which is suited to handle multi-part > mime-mails. Is somehting like this available ? I browsed the > module-index on www.python.org, but did not find anything > apropriate. mimetools.py and multifile.py are standard modules. You can see some exmples in my programs: http://phd.pp.ru/Software/Python/#extract_mime http://phd.pp.ru/Software/Python/#mimedecode Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From huaiyu at gauss.almadan.ibm.com Thu Oct 18 15:08:48 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 18 Oct 2001 19:08:48 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> Message-ID: On Thu, 18 Oct 2001 02:10:40 -0600, Andrew Dalke wrote: >Yep. My belief is that cases where your proposal shines doesn't >occur very often in real code, and that the additional flexibility >will instead lead to more obsfucated code. [...] >It's easy. Scan the standard library and find a chunk of code which >you believe will be improved with your construct. OK, I'll bite the bullet. ;-) A search through the source distribution found 1004 "break"s, most of them (about 800) are break-statements: $ rgrep -R "*.py" break . |grep -v breaks| grep -v cbreak|wc 927 3357 45879 I picked a few files that have more than a few break statements, and searched for break. Almost all of them are in this style: while 1: x = something if not x: break ... Following are a few examples of while-loops. I don't think I'll spend more time on this. Anybody can do their own search if they want real life examples. Also I'm not sure how to search for possible places where nested if-else ccould be changed to flat elif. The number of pontential instances to look for is too large: rgrep -R "*.py" else . |wc 3098 7655 126721 Doing these examples, I got a clearer view on why the change would be good: The new syntax allows one to say " do ... under this condition ... " instead of the more twisted logic of " do ..., but if not this, change ... " It also displays the loop condition prominently, instead of displaying a dummy "while 1" and bury the substance inside. Here are 6 examples [Disclaimer: It's about half an hour quick hack including the searching. Almost mechanical change. No guarantee I really understand the original code before changing them. No checking, debugging or whatsoever, etc.] ./Demo/pdist/makechangelog.py: --------------------------------------------(1) while 1: file = getnextfile(f) if not file: break revs = [] while 1: rev = getnextrev(f, file) if not rev: break revs.append(rev) if revs: allrevs[len(allrevs):] = revs Change to: while file = getnextfile(f); file: revs = [] while rev = getnextrev(f, file); rev: revs.append(rev) if revs: allrevs[len(allrevs):] = revs --------------------------------------------(2) while 1: line = f.readline() if not line: return None if startprog.match(line) >= 0: file = startprog.group(1) while 1: line = f.readline() if not line: return None if line[:10] == '='*10: return None if line[:10] == '-'*10: break return file changed to while line = f.readline(); line: if startprog.match(line) >= 0: file = startprog.group(1) while line = f.readline(); line[:10] != '-'*10: if not line: return None if line[:10] == '='*10: return None return file return None Lib/ftplib.py: --------------------------------------------(3) def getmultiline(self): line = self.getline() if line[3:4] == '-': code = line[:3] while 1: nextline = self.getline() line = line + ('\n' + nextline) if nextline[:3] == code and \ nextline[3:4] != '-': break return line changed to def getmultiline(self): code = None lines = [] while line = self.getline(); lines.append(line); line[3:4] == '-': if code != line[:3]: break else: code = line[:3] return '\n'.join(lines) --------------------------------------------(4) while 1: data = conn.recv(blocksize) if not data: break callback(data) changed to: while data = conn.recv(blocksize); data: callback(data) ./Lib/mimify.py: --------------------------------------------(5) while 1: res = mime_code.search(line, pos) if res is None: break newline = newline + line[pos:res.start(0)] + \ chr(int(res.group(1), 16)) pos = res.end(0) changed while res = mime_code.search(line, pos); res is not None: newline = newline + line[pos:res.start(0)] + \ chr(int(res.group(1), 16)) pos = res.end(0) --------------------------------------------(6) # read header hfile = HeaderFile(ifile) while 1: line = hfile.readline() if not line: return if prefix and line[:len(prefix)] == prefix: line = line[len(prefix):] pref = prefix else: pref = '' line = mime_decode_header(line) if qp.match(line): quoted_printable = 1 continue # skip this header if decode_base64 and base64_re.match(line): is_base64 = 1 continue ofile.write(pref + line) if not prefix and repl.match(line): # we're dealing with a reply message is_repl = 1 mp_res = mp.match(line) if mp_res: multipart = '--' + mp_res.group(1) if he.match(line): break if is_repl and (quoted_printable or multipart): is_repl = 0 Changed to # read header hfile = HeaderFile(ifile) while line = hfile.readline(); line: if prefix and line.startswith(prefix): line = line[len(prefix):] pref = prefix else: pref = '' line = mime_decode_header(line) if qp.match(line): quoted_printable = 1 elif decode_base64 and base64_re.match(line): is_base64 = 1 else: ofile.write(pref + line) if not prefix and repl.match(line): is_repl = 1 if mp_res = mp.match(line); mp_res: multipart = '--' + mp_res.group(1) if he.match(line): break else: return if is_repl and (quoted_printable or multipart): is_repl = 0 From dalke at dalkescientific.com Wed Oct 31 23:58:05 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 31 Oct 2001 21:58:05 -0700 Subject: newbie, relative path References: <3bdff425.12589703@news.easynews.net> Message-ID: <9rqkq9$bjr$1@slb6.atl.mindspring.net> Marcus Stojek wrote: >I have a small script that uses an .ini file for configuration. How >can I open the file config.ini that is in the same dir as the script >itself? (script dir is changing) > >config=open("?????config.ini","r") import os, sys def get_config_filename(): progname = sys.argv[0] dirname = os.path.dirname(progname) if dirname == "": # run in interactive mode, use current directory dirname = os.getcwd() return os.path.join(dirname, "config.ini") print get_config_filename() ===== Saved the above into spam.py [dalke at pw600a ~]$ python spam.py /home/dalke/config.ini [dalke at pw600a ~]$ cd src [dalke at pw600a ~/src]$ python ../spam.py ../config.ini [dalke at pw600a ~/src]$ python ~/spam.py /home/dalke/config.ini [dalke at pw600a ~/src]$ python ~/../dalke/spam.py /home/dalke/../dalke/config.ini [dalke at pw600a ~/src]$ cd .. [dalke at pw600a ~]$ python Python 2.0 (#4, Dec 8 2000, 21:23:00) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> execfile("spam.py") /home/dalke/config.ini >>> I'm guessing you're trying to reduce the number of configuration settings needed to run your code, so the directory can be moved and as long as the program is on the path you can find the configuration file information. If so, something else you can consider is that under unix the file could be on the path through a symbolic link, so you might want to also try playing around with os.readlink. It's trickier than I want to think about right now though. Andrew dalke at dalkescientific.com From tim.one at home.com Sat Oct 13 06:14:46 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 13 Oct 2001 06:14:46 -0400 Subject: signum() not in math? In-Reply-To: <3BC7FE9B.CD190C62@darwin.in-berlin.de> Message-ID: [Dinu Gherman] > ... > The more fundamental question behind these issues is: I doubt that wrapping a request for a specific function inside a Grand Generalization is going to help sell it. At best it will bury the request under an avalanche of "me too, but!"s for 50 other functions you don't care about. Then, if history is a trustworthy guide, nobody will care enough to implement any of them. > Can someone expect from the Python standard library, too, 'only' > those 90% of functionality needed by 'the crowd' and be treated > with regret when not belonging to it, especially when the matter > is so trivial? I've used a lot of languages over the endlessly tiring years, but have never seen another language community so keen to avoid writing two-line functions themselves. When a function you want is indeed trivial to code in Python, that's a strong argument against bloating the core C code with it. > The reason for people not complaining about the absence of the > sign() function need not necessarily be that they use something > like tanh() more often (I doubt so), but simply because they > can write sign() with far less difficulty than tanh(). I don't believe that -- overall, people just aren't shy about asking for new stuff. > One can argue if this is a good thing. Newbies might learn some- > thing by writing sign() themselves, but will probably wonder why > they *have* to? (While nobody expects to find the Riemann Zeta > function in the math module, that you get in Mathematica...) Then they can ask, and get an unsatisfying answer . > In math textbooks sign() is typically introduced just before or > after abs(), which raises the question why Python has chosen to > implement only abs() and not only sign(), As I explained last time, and as it says right at the top of the math module docs: It [the math module] provides access to the mathematical functions defined by the C standard. That's all it was designed to do, and all it does. If people want a fancier math module, fine by me, but then (A) it needs a PEP; and, (B) it needs volunteers to design, document, code, port and test the new stuff. > especially as they can be expressed in terms of each other? I expect you severely underestimate the arguments there *would* be over "the correct" signum function: what to do about a 0 argument; which types it should accept; which type(s?) it should return; if signum(0.0) returns a float 0, whether the sign of 0 needs to be preserved or erased, or whether that's undefined; if signum(0.0) returns a 1, ditto for reflecting the sign of the input; what to do about NaN arguments; and whether subclasses of numeric types and/or new numeric types need a way to override the base type signum implementation (since you brought up the parallel, note that numeric types *can* override __abs__, and that requires a whole slew of machinery in the class and type implementations, and adding new slots for numeric types at the C level creates cross-release binary compatibility headaches too). > Orthogonal design? Ok, but the same is true for sin() and cos() and > still, both are there in the math module! It provides access to the mathematical functions defined by the C standard. That was Guido's practical way of letting some other committee argue for years (literally) about which functions are of most use, and exactly what they should do. Trust me when I tell you there's nothing easy about math library definition, design, or implementation, and especially not floating-point math libraries. > As the ActiveState Python cookbook comes closer to being printed > it would be sort of embarassing to see a recipe therein for wri- > ting a signum function, simply because you need it, wouldn't it? I won't find it embarrassing, no; it's more embarrassing that we haven't invented a % format code to convert integers to Roman numerals, which is a more frequent topic on the newsgroup, and wrt support for which Python severely lags behind Common Lisp . > Expecting-the-Spanish-Inquisition'ly, if-the-spanish-inquisition-doesn't-write-peps-or-code-i-expect-it-too-ly y'rs - tim From peter at engcorp.com Thu Oct 4 01:54:35 2001 From: peter at engcorp.com (Peter Hansen) Date: Thu, 04 Oct 2001 01:54:35 -0400 Subject: XML Marshalling of objects References: <9pdfd4$c0q$1@tyfon.itea.ntnu.no> <2347302.PoejJDZkT8@lunix.schabi.de> Message-ID: <3BBBF99B.46165827@engcorp.com> David Bolen wrote: > > Markus Schaber writes: > > > > > Here just follows the data stream from > > pickle() > > > > > > Just write the two-liner dtd for it, and you have pickle outputting > > valid xml, and with almost no speed loss :-) > > Even if you make the pickled_data element in your DTD a CDATA you're > going to have to post-process the pickle output to ensure it doesn't > include any characters that need to be quoted as entities in the XML > stream (e.g., "<"). Then of course, you've to to invert this on the > other side, so there's going to be some cost to the encoding/decoding. There's always which might be what you meant by CDATA element in a DTD but then again it might not be (and DTDs are obsolete, aren't they?). That way you would have to escape only the sequence ]]> if it were to occur in the data. -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From graz at mindless.com Sat Oct 27 08:17:42 2001 From: graz at mindless.com (Graham Ashton) Date: Sat, 27 Oct 2001 12:17:42 GMT Subject: Critical sections and mutexes References: Message-ID: In article , "brueckd" wrote: > With a very few multithreaded Python apps under your belt it gets so > that it doesn't take too many brain cycles to recognize the > GIL-does-this-for-free scenarios. I take it that others (possibly significantly less experienced than you) don't ever need to modify your software then? Adhering to basic principles like using mutexs where people unfamiliar with your code would expect to find them helps you to write self documenting code. It's not everybody who has the experience you do of when you can get away without locks in Python. > Yes, you can always overengineer a solution if you want, but that's not > very Pythonic. Eh? Where is that written down then? Surely the amount of "engineering" that goes into your software is defined by it's intended purpose? Perhaps I'd better go and learn C. > Think of it this way: the way the GIL works can impose a slight > performance hit on your program (a cost). With that cost is an > associated benefit. You can choose whether or not to enjoy that benefit, > but you've already paid the cost so you might as well. That's fine, so long as you bear in mind that it all depends on the domain in which your software is intended to run. It's that kind of attitude that lead to the Y2K problem. -- Graham From ldw at us.ibm.com Wed Oct 24 17:13:43 2001 From: ldw at us.ibm.com (Larry Whitley) Date: Wed, 24 Oct 2001 16:13:43 -0500 Subject: None References: <9r4b95$suc$1@news.rchland.ibm.com> <9r6lep$tdg$1@news.rchland.ibm.com> Message-ID: <9r7au7$oe2$1@news.rchland.ibm.com> That's it! Here's the offending code, a little earlier in process(). elif pc.command == "dual": # command was a dual address cycle pc.command, None, None = tr.decodeCommand() Looks like it considers None a variable though it is not under the elif that used it. Thanks, I'll fix it up. Larry "Steve Holden" wrote in message news:yCBB7.18793$Nx2.278340 at atlpnn01.usenetserver.com... > "Larry Whitley" wrote in message > news:9r6lep$tdg$1 at news.rchland.ibm.com... > > Here's the traceback requested: > > > > C:\Projects\Pecos\Traces>analyze3 > > u:\trc45\pecos\ c:\projects\pecos\traces\ ('crusader091101.zip', > > 'crusader091101 > > .dat', 'crusader091101.a3.txt') > > Traceback (most recent call last): > > File "C:\Projects\Pecos\Traces\analyze3.py", line 372, in ? > > main() > > File "C:\Projects\Pecos\Traces\analyze3.py", line 365, in main > > process( localPath + files[1], localPath + files[2] ) # process the > file > > File "C:\Projects\Pecos\Traces\analyze3.py", line 336, in process > > pc.runningReport( None, riostream ) # to stdout > > UnboundLocalError: local variable 'None' referenced before assignment > > > AHA!!!!! > > This is your problem. The interpreter is telling you in this message that it > regards the name None as being that of a variable local to your function or > method. The ONLY reason it is making this assumption is because it has seen > an assignment to None somewhere in the function/method (in this case the > "process()" function). > > > Here's the relevant section of code in the neighborhood of the error: > > if pc.endCond != "": > > pc.summarizeData() > > riostream = pc.rio() > > pc.runningReport( fout, riostream ) # to file > > pc.runningReport( None, riostream ) # to stdout > > > At this point the assignment to None has not taken place. But this code is > inside a function that assigns to None, so None is being treated as a local > variable. > > > The method runningReport() looks like this: > > def runningReport(self, fout, riostream): > > print >>fout, "%8d" % self.startCycn, "%8d" % self.endCycn, "%6d" > % > > (self.endCycn - self.startCycn), \ > > "%8s" % self.command, "%10x" % self.startAddr, "%10x" % > > self.endAddr, "%4d" % self.nBytes, \ > > "%8s" % self.endCond, riostream > > > > My idea was to setup the method to print to file and by substituting None > > for the file object, let the same method send the output to standard out. > > > > Thanks for the help, > > You'll get there. See this: > > >>> def fOK(a): > ... print "arg is", a, "None is", None > ... > >>> def fBAD(a): > ... print "arg is", a, "None is", None > ... None = "something, anything (except None!)" > ... > >>> fOK(42) > arg is 42 None is None > >>> fBAD(42) > arg is 42 None isTraceback (innermost last): > File "", line 1, in ? > File "", line 2, in fBAD > UnboundLocalError: Local variable 'None' referenced before assignment > >>> > > Hope this helps. > > regards > Steve > -- > http://www.holdenweb.com/ > > > > > From mlh at idi.ntnu.no Wed Oct 10 14:35:19 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 10 Oct 2001 20:35:19 +0200 Subject: Assigning to lists with arbitrary names References: <3BC35131.C9AB1393@motorola.com> <9q2488$nld$1@tyfon.itea.ntnu.no> Message-ID: <9q24d8$nnh$1@tyfon.itea.ntnu.no> "Magnus Lie Hetland" wrote in message news:9q2488$nld$1 at tyfon.itea.ntnu.no... [...] > Excuse me if this isn't helpful, but -- why do you want to avoid a list of > lists of lists? And -- if each file generates a list, and you have a list > of files -- wouldn't that simply be a list of lists? Sorry about that last sentence -- I just re-read your problem statement. (I still see no big problem with three layers of lists, though.) -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From BrianQ at ActiveState.com Tue Oct 2 18:38:47 2001 From: BrianQ at ActiveState.com (Brian Quinlan) Date: Tue, 2 Oct 2001 15:38:47 -0700 Subject: need design suggestions: local namespace problem In-Reply-To: Message-ID: <002701c14b93$00875770$b503a8c0@activestate.ca> > Some of these variables need to conditionally have different values as > I mentioned. For example, exit status codes. Under qmail, > `ERR_HARD = 100', while under Sendmail, `ERR_HARD = 75'. Why are you getting so fancy? Why can't you simply use: if running_under_qmail: ERR_HARD = 100 else: ERR_HARD = 75 -- Brian Quinlan BrianQ at ActiveState.com From geoffrey at bigpond.net.au Fri Oct 12 05:24:19 2001 From: geoffrey at bigpond.net.au (Geoffrey Pointer) Date: Fri, 12 Oct 2001 09:24:19 GMT Subject: YOU ARE ALL GAY! References: Message-ID: On: Fri, 12 Oct 2001 14:48:34 +0900 Subject: Re: YOU ARE ALL GAY! tm said: > Much better geof, you left the attributes this time. Shows you are > capable of learning. You could use some help with snipping, but keep up > the good work. Read the whole message that you are commenting on here. My original comment was a one off, off hand comment, meant to be just light hearted in the spirit of the original message. Just like at least two of the other replies which I read in context with the original post. The only reason I clipped the entire original message (something I normally NEVER do) is because Nigel said he hadn't seen the original message. They say you can lead a horse to water but you can't make it drink. Well, this little black horse has been to the water of his own volition has drunk the water heartily and moved on. You on the other hand it seems would have me drown. > Say, would you like to learn how to make a proper sig delimiter? Proper?? There is obviously no accounting for taste, its only text for crying out loud. -- Cheers - Geoff %^> From max at alcyone.com Thu Oct 4 19:16:06 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 04 Oct 2001 16:16:06 -0700 Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> <9pimt6$cc9$1@tyfon.itea.ntnu.no> Message-ID: <3BBCEDB6.2442FF10@alcyone.com> Cliff Wells wrote: > Hey, I didn't write that. Be careful how you [snip]. What was that? The last word in your post got snipped. :-) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Things are as they are because they were as they were. \__/ Thomas Gold Product's Quake III Arena Tips / http://www.bosskey.net/ Tips and tricks from the absolute beginner to the Arena Master. From stephen_purcell at yahoo.com Mon Oct 29 07:31:06 2001 From: stephen_purcell at yahoo.com (Steve Purcell) Date: Mon, 29 Oct 2001 13:31:06 +0100 Subject: python binary search In-Reply-To: References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> <3BDCC4C9.B0597DF1@uoguelph.ca> <8djpttobn2i18avnq3817bmg1ua6eavq8r@4ax.com> Message-ID: <20011029133106.A5508@publishers-market.com> Steve Holden wrote: > But it wasn't that funny, since nothing is ever simply black or white, good > answers must always conside the graze. I hope the original poster won't be cowed by these yokes at his expense. -Steve -- Steve Purcell, Pythangelist Get testing at http://pyunit.sourceforge.net/ From barry at zope.com Mon Oct 29 01:42:31 2001 From: barry at zope.com (Barry A. Warsaw) Date: 29 Oct 2001 01:42:31 -0500 Subject: interpreter crashes References: <7xpu7768nf.fsf@ruckus.brouhaha.com> Message-ID: >>>>> "PR" == Paul Rubin writes: PR> The backtraces aren't very informative. The evaluator is PR> crashing, almost certainly due to data corruption having PR> happened sometime earlier. But sure, I'll include them. Try running your program under gdb. Often, nonsense stack traces are caused by memory corruptions which can be caught much sooner under gdb, producing more usable stack traces. -Barry From chr_w at gmx.de Mon Oct 15 04:51:45 2001 From: chr_w at gmx.de (chr_w at gmx.de) Date: Mon, 15 Oct 2001 10:51:45 +0200 (MEST) Subject: BINARY DATA, SCIPY, MIO (...again) References: <87n12t8glp.fsf@lisboa.ifm.uni-kiel.de> Message-ID: <18215.1003135905@www39.gmx.net> Hi. I get this by typing the dir(types) command: >>> dir(types) ['BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', 'CodeType', 'ComplexType', 'DictType', 'DictionaryType', 'EllipsisType', 'FileType', 'FloatType', 'FrameType', 'FunctionType', 'InstanceType', 'IntType', 'LambdaType', 'ListType', 'LongType', 'MethodType', 'ModuleType', 'NoneType', 'SliceType', 'StringType', 'TracebackType', 'TupleType', 'TypeType', 'UnboundMethodType', 'UnicodeType', 'XRangeType', '__builtins__', '__doc__', '__file__', '__name__'] Can you give me any hints about how to use the fort_read (fortran read) thing mentioned in the sparse docu of scipy.io.mio??? Am I doing it the right way? christian > This seems strange. What happens if you start a vanilla python session > and import the types module. > > Python 2.1 (#1, Jul 20 2001, 22:26:10) > [GCC 2.95.4 20010319 (Debian prerelease)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> import types > >>> dir(types) > ['BufferType', ... , 'ListType', ... , 'TupleType', ...] > > And your loop is definitely very slow. It would be better to > fread(2000,'l') and create the two wanted arrays by slicing. > > HTH, > __Janko > > -- > Institut fuer Meereskunde phone: 49-431-597 3989 > Dept. Theoretical Oceanography fax : 49-431-565876 > Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de > 24105 Kiel, Germany > -- > http://mail.python.org/mailman/listinfo/python-list > -- GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net From willypef at hotmail.com Wed Oct 31 15:42:35 2001 From: willypef at hotmail.com (fernando orellana) Date: Wed, 31 Oct 2001 17:42:35 -0300 Subject: hola nesesito su ayuda Message-ID: hola que tal soy leandro vivo en un pueblito de argentina y estudio analista de sistemas. el punto es que estoy en la materia de computacion y estamos aprendiendo a programar con python me parace que esta rebueno, tanto como sus tutoriales. bueno les escribo porque tengo una duda nesecito hacer un sistenma de matriculacion y tengo que ingresar los nombres de los alunmos, asi como su correo, su numero de legajo y las materias que va a tomar, donde deveria meter estas variables?, en listas o diccionario o talves hacerlo con clases ? bueno si me pueden dar una mano mejor y si nescesitan mas datos o que sean mas puntuales diganme y yo les escribo de nuevo. desde ya muchas gracias por su atencion y perdonen mi molestia. suerte y gracias un saludo leo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From missive at frontiernet.net Sun Oct 7 16:52:34 2001 From: missive at frontiernet.net (Lee Harr) Date: Sun, 07 Oct 2001 20:52:34 -0000 Subject: Python and Zope References: Message-ID: > > I was more after an answer where you are composing a page with several > objects (sorry if I use the wrong notation I'm a newbie in Python and Zope) > like: > > > > > > But in my case I have some images, and script in various folders hence I > would like to do something like: > > > > > > (But this syntax is wrong.) > By using quotes around your dtml-var expression, you can specify objects using python syntax, ie: You should also check out the zope at zope.org mailing list for more and faster (!) assistance. From sdm7g at Virginia.EDU Tue Oct 16 11:49:49 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Tue, 16 Oct 2001 11:49:49 -0400 (EDT) Subject: import question In-Reply-To: Message-ID: On Tue, 16 Oct 2001, Steven D. Majewski wrote: > > import foo # get foo into namespace > reload foo # reload it > from foo import * # until you do this, the names in this namespace > # still point to the names in the old foo module. Oops! Should be: reload(foo) 'reload' is a function, 'import' is a statement. -- Steve From myuen at acs2.acs.ucalgary.ca Tue Oct 16 22:06:33 2001 From: myuen at acs2.acs.ucalgary.ca (Michael Yuen) Date: 17 Oct 2001 02:06:33 GMT Subject: Library function for sorting Message-ID: <9qip39$6do$1@nserve1.acs.ucalgary.ca> I'm really new to this Python stuff and was wondering if there's a library function for sorting strings. I sure there is one but haven't been able to find one when I looked through the documentation. Thanks, M -- From robin at jessikat.fsnet.co.uk Sat Oct 13 04:25:48 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 13 Oct 2001 09:25:48 +0100 Subject: Python Cookbook: last call for recipes for printed version References: <9q52b1$3q5$1@lancelot.camelot> <4a249347.0110120316.a5de6eb@posting.google.com> Message-ID: <4L$flLAMq$x7EwqH@jessikat.fsnet.co.uk> In article , Laura Lewin writes >Hi, >There were some early press releases when we announced the Cookbook >that described the co-publishing arrangement between ActiveState and >O'Reilly. Here's a link to an ORA dispatch from Python 9 that >introduced the Cookbook: > >http://python.oreilly.com/news/pythonday2_0301.html > >Also, as Alex points out, David clearly states on the site that the >"partnership between ActiveState and O’Reilly provides the >resources necessary to help bring this book to life. Furthermore, >O'Reilly plans to publish a selection of the recipes in a paper >volume." In addition, when you actually submit a recipe, you are >brought directly to a page with a letter from me talking about >publishing rights and O'Reilly's plans. > >Let me know if you have any questions, and please do contribute--we >have plenty of room for more recipes but time is running out. > >Laura >LLewin at oreilly.com >----------- > >bobh at hslda.org (Robert) wrote in message > ..... seems there are only 7 editors' choice recipes, so is that really enough for a cookbook? -- Robin Becker From dale at riverhall.NOSPAMco.uk Mon Oct 8 06:21:54 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Mon, 08 Oct 2001 11:21:54 +0100 Subject: safe simultaneous file append? References: <3np2st060vt841lqfimibi12909td1p02c@4ax.com> <9prtkc$56a$1@samos.cs.uu.nl> Message-ID: <1cv2st0g180m0cfoloqf99s5pofe4pmi32@4ax.com> piet at cs.uu.nl wrote: >>>>>> Dale Strickland-Clark (DS) writes: > >DS> Yes. You can't append to a file from two different places at once. You >DS> have a few choices: > >In fact in modern Unixes you *CAN*. >From man fopen: > > Opening a file with append mode (a as the first character in > the mode argument) causes all subsequent writes to the file > to be forced to the then current end-of-file, regardless of > intervening calls to fseek(3S). If two separate processes > open the same file for append, each process may write freely > to the file without fear of destroying output being written > by the other. The output from the two processes will be > intermixed in the file in the order in which it is written. Erk! There's a recipee for disaster unless treated very carefully. Handy if you're careful, though, I guess. -- Dale Strickland-Clark Riverhall Systems Ltd From mathiasm at pvv.org Mon Oct 1 13:11:42 2001 From: mathiasm at pvv.org (Mathias Mølster Lidal) Date: 01 Oct 2001 19:11:42 +0200 Subject: Handling C structs in python References: Message-ID: "Ivan A. Vigasin" writes: > Hello, All > > I'm writing python extension and need to pass C structs from C++ to python. > > What is the usual way of doing whis? > Use the struct-module. (http://www.python.org/doc/current/lib/module-struct.html) Mathias Lidal From tim.one at home.com Thu Oct 11 13:28:59 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 11 Oct 2001 13:28:59 -0400 Subject: how do I add site-packages on Windows? In-Reply-To: <001f01c15253$42ed5da0$0101010a@local> Message-ID: [Chris Gonnerman] > I've never understood why this is done this way. In site.py, > the sys.path setup only adds site-packages on Unixoid OS's. > On Windows it isn't done. It is (or will be, from your POV ) in 2.2. > ... > Does ANYONE know why this decision was made? Probably, but not me, and I'm not sure it *was* "a decision". More likely is that someone added it for Unix, and didn't have time to worry about a dozen OSes they didn't use and knew nothing about. From gherman at darwin.in-berlin.de Thu Oct 11 12:41:24 2001 From: gherman at darwin.in-berlin.de (Dinu Gherman) Date: Thu, 11 Oct 2001 18:41:24 +0200 Subject: MD5 in pure Python Message-ID: <3BC5CBB4.5681C924@darwin.in-berlin.de> As I posted recently on EDU-SIG, for those who care... Dinu -- Dinu C. Gherman ................................................................ UN Resolution 42/159 on fighting international terrorism (1987), adopted by 153-2 votes (US and Israel against): http://www.un.org/documents/ga/res/42/a42r159.htm > Hi, > > a long while ago there was a crypto thread here. I remember > having posted something about a pure Python MD5 implementa- > tion. As at that time it was a bit buggy I've not released > it, then, but now I've put it into my Starship cabin: > > http://starship.python.net/crew/gherman/#md5py > > This is reasonably tested against the built-in MD5 module, > but, of course, you should not use it for any serious pur- > pose! > > Perhaps, this will help retrigger some crypto-activities? > (I've seen fancy proposals for Python Crypto-APIs, but not > much more.) > > Regards, > > Dinu From sholden at holdenweb.com Tue Oct 9 07:36:11 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 9 Oct 2001 07:36:11 -0400 Subject: python -i References: <3BC27C3C.732C6A6B@engcorp.com> Message-ID: "Peter Hansen" wrote ... > epchaves at yahoo.com.br wrote: > > > > __________________ > > import string > > > > a = string.lower("??????AAA") > > print a > > ____________________ > > > > if i do: python -i myfile.py > > the output is OK: ??????aaa > > > > but if i do: python myfile.py > > the output isn't the expected: ??????aaa > > With this: ActivePython 2.1.1, build 212 (ActiveState) > Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32 > > I get the same result from either set of command line arguments: > > C:\>python test.py > ??????aaa > > C:\>python -i test.py > ??????aaa > >>> Which is exactly what one might have expected: Jorge, why did you expect the "-i" argument to do something other than go interactive after execution? You seem to expect it to affect your locale, or something similar ... $ python --help ... -i : inspect interactively after running script, (also PYTHONINSPECT=x) and force prompts, even if stdin does not appear to be a terminal ... Nothing there that might alter string.lower()'s behavior :-( regards Steve -- http://www.holdenweb.com/ From tebeka at cs.bgu.ac.il Wed Oct 17 02:05:13 2001 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: Wed, 17 Oct 2001 08:05:13 +0200 Subject: makefile for distutils setup.py Message-ID: <9qnbsj$7u1@hu5.hofstra.edu> Hello All, I there a 'standard' makefile to ship with a distutils archive? I'm currently using (which is ugly): all: @echo Please specify one of the following: @python setup.py --help-commands | head -18 | tail -17 .DEFAULT: python setup.py $@ -- Bye. ---------------------------------------------------------------------------- - Smile, damn it, smile. lambda msg: { 'name' : 'Miki Tebeka', 'email' : 'mikit at elrontelesoft.com', 'url' : 'http://www.cs.bgu.ac.il/~tebeka', 'quote' : 'The only difference between children and adults is the price of the toys' }[msg] From max at alcyone.com Thu Oct 11 14:10:47 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 11 Oct 2001 11:10:47 -0700 Subject: Borg Pattern Class usable from other classes? References: Message-ID: <3BC5E0A7.41050647@alcyone.com> Jan Wender wrote: > I tried to use the Borg Pattern from Alex Martelli > (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531). I > have one file > containing the Borg class. In another file I defined a second class > which wants > to access the information from the Borg class. It instantiates an > object from > the Borg class, but it seems that the class dictionary __shared_state > gets newly > initialized, rendering it empty. Any ideas to get it working? The problem is you have a recursive import going there. a imports b, but b imports a. That necessarily means that one of them won't get what he expects. The sequence appears strange anyway. a.py defines the support classes and b.py defines the test harness, but the __main__ clause of a.py invokes the test harness? Why not put the test harness where it belongs, in b.py with the Test class? That will eliminate your recursive import problem. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ We are victims of our circumstance. \__/ Sade Adu Alcyone Systems' CatCam / http://www.catcam.com/ What do your pets do all day while you're at work? Find out. From A.Schoeller at web.de Thu Oct 18 07:17:01 2001 From: A.Schoeller at web.de (Andreas Schoeller) Date: Thu, 18 Oct 2001 13:17:01 +0200 Subject: [OsX] Tkinter compile prob. Message-ID: Hello group, I updated OsX and developer Tools to latest V10.1 Now I compiled and installed tcl8.4.a / tk8.4.a and python 2.2. Then I prepared /Modules/Setup file with the correct paths to tcl/tk and X11 headers and libs. The following ?make? brings this result : libtool -o Python.framework/Versions/2.2/Python -dynamic libpython2.2.a \ -framework System -lcc_dynamic -arch_only ppc -flat_namespace -U _environ -framework Carbon -framework Foundation -install_name Python.framework/Versions/2.2/Python -compatibility_version 2.2 -current_version 2.2 ld: Undefined symbols: _TclFreeObj _Tcl_AddErrorInfo <.snip.> ... a lot more tcl/tk symbols ... <.snip.> _Tcl_Init _Tk_Init _Tk_MainWindow libtool: internal link edit command failed make: *** [Python.framework/Versions/2.2/Python] Error 1 I configured python with --enable-framework and --with-suffix=.exe as recommended by the README file. I also tried earlier versions python 2.1 amd tcl8.3.3/tk8.3 with no better results. I also tried ?fink?. I need to work with IDLE so pls help me if you can. I read about a Aqua-Version of Tk/Wish. Is it possible to build the python-TKinter module against this distributon ? thx, andreas -------------- next part -------------- An HTML attachment was scrubbed... URL: From quinn at seniti.ugcs.caltech.edu Mon Oct 1 15:42:19 2001 From: quinn at seniti.ugcs.caltech.edu (Quinn Dunkan) Date: 1 Oct 2001 19:42:19 GMT Subject: Does there exist a Python-to-Perl translator ? References: <3BB2D226.3C260A2C@Spam.Please> <3BB31597.96BFE8B7@Spam.Please> Message-ID: On Thu, 27 Sep 2001 14:03:36 +0200, Weet Vanniks wrote: >You don't get my point. Managers do want to see Perl code. What I want is >benefit from the productivity of Python, get something working and then >satisfy my manageer with a Perl solution. #!/usr/local/bin/perl system("python foo.py"); Or you could embed python in perl and write a .xs, so you could type: #!/usr/local/bin/perl python->run(snag_the_stuff_after__END__); # or however you do this in perl, # I've forgotten all of it __END__ special dialect of perl follows... EOF Or if he just likes those .pl endings, you can use imputils and rename your python scripts. Or use Gordon's packaging utilities, and deliver a big wad of binary. If there were a python-to-perl, the perl it generated would be just as readable as the binary. From dale at riverhall.NOSPAMco.uk Wed Oct 3 07:35:58 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Wed, 03 Oct 2001 12:35:58 +0100 Subject: Assignment not the same as defining? Message-ID: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> A solution I thought I had to using __setattr__ doesn't seem to work. class wibble: def __init__(self): self.__setattr__ = self.set def set(self, attr, value): My late bound __setattr__ is never called. I've clearly misunderstood something fundamental here. What am I doing wrong? Thanks -- Dale Strickland-Clark Riverhall Systems Ltd From skip at pobox.com Wed Oct 31 13:05:11 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 31 Oct 2001 12:05:11 -0600 Subject: Underscore data hiding (was python development practices?) In-Reply-To: <9rpbk1$19rg$1@nntp6.u.washington.edu> References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> <9rpbk1$19rg$1@nntp6.u.washington.edu> Message-ID: <15328.15703.954207.430409@beluga.mojam.com> Russell> My understanding is that a double underscore is required for Russell> Python to automagically mangle the name. On the other hand, two Russell> postings now suggest that a single underscore is sufficient. Russell> If double underscore is required, then it seems to me this is a Russell> very common misconception that a single is sufficient. It might Russell> be worth changing. A double leading underscore is requred to coax Python into mangling an attribute. I think a lot of people use a single underscore as a simple cue for themselves and other programmers that an attribute isn't meant to be part of the public interface without messing up the actual name, so it can be used easily in subclasses. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From logiplexsoftware at earthlink.net Thu Oct 25 13:44:58 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 25 Oct 2001 10:44:58 -0700 Subject: smtp In-Reply-To: <9r8c9e.3vv9mah.1@kserver.org> References: <9r925q$863$1@verence.demon.co.uk> <9r8c9e.3vv9mah.1@kserver.org> Message-ID: <01102510445802.26379@logiplex1.logiplex.net> On Thursday 25 October 2001 06:43, Sheila King wrote: > This is what AOL does, and yet his program didn't work. However... > with AOL, even though you use a non-AOL address in the From: field, it > adds some "apparently-from:" header to the email, with your AOL address > in it. Is it possible, that he wasn't 'logged-on' as an AOL userid, and > so the earthlink.net addy got refused as a bad sender? (He got Actually he was logged into AOL as himself, and specified his AOL email address in the From: field. > Still, the best thing is to let the user also specify his own SMTP > server. I'm not sure why you aren't letting the user configure that for > themself? I'm trying to make it as simple as possible for the user, and I can imagine that many users don't know their SMTP server's address (or even what an SMTP server is, for that matter). -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From Gareth.McCaughan at pobox.com Wed Oct 24 05:27:21 2001 From: Gareth.McCaughan at pobox.com (Gareth McCaughan) Date: Wed, 24 Oct 2001 10:27:21 +0100 Subject: silly idea - interesting problem References: Message-ID: Steven D. Majewski wrote: > On Sat, 20 Oct 2001, Stefan Antoni wrote: > > > > > i got a silly idea about a small script which takes to strings (lets say > > "test" and "dust") and mixes them to "tdeusstt". > > i tried to code it because i thought it would be easy, but now i cannot > > find out _how_ to do it ;) > > > > i tried to "list()" the string and mix the items. but ... > > > > Anybody has a hint or even a solution? > > >>> import operator > >>> reduce( operator.__add__, map( operator.__add__, 'test', 'dust' ), '' ) > 'tdeusstt' Better to use string.join (or, in more recent Python, the "join" method on string objects) instead of the outermost reduce, so as not to lose horribly when the result is very long. -- Gareth McCaughan Gareth.McCaughan at pobox.com .sig under construc From sholden at holdenweb.com Tue Oct 9 13:14:17 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 9 Oct 2001 13:14:17 -0400 Subject: ARGV and import ? References: <660c52de.0110090907.4017f907@posting.google.com> Message-ID: "J" wrote ... > Hi all, > > This is my first post to this group & I am also fairly new to python, > so please forgive me if this isn't the brightest question or the > appropriate venue. > > I would like to do the following: > import a module based on what is typed on the command line. > > I thought this would work: > import sys > recipes = sys.argv[1] > import recipes > > But, I get this error: > >> ImportError: No module named recipes > > Is there any way to pass the module name to import through an argv? > >From the Python Library Reference: """ 2.3 Built-in Functions The Python interpreter has a number of functions built into it that are always available. They are listed here in alphabetical order. __import__ (name[, globals[, locals[, fromlist]]]) This function is invoked by the import statement. It mainly exists so that you can replace it with another function that has a compatible interface, in order to change the semantics of the import statement. For examples of why and how you would do this, see the standard library modules ihooks and rexec. See also the built-in module imp, which defines some useful operations out of which you can build your own __import__() function. """ Your problem is that the import statement expects to see the name of the module, not a name to which the name of the module is bound. That's the same reason why print x prints the VALUE of x, and not "x". You can use the __import__ function to import a module whose name you have stored in a variable, but you are descending towards magic, as the import statement does subtly different things from simply calling __import__(). You may therefore find other spells have been cast which affect the way your program operates :-) Try __import__(sys.argv[1]) but also be aware that's a potentially dangerous program in someone else's hands ... they can import any module they like, and the module is EXECUTED the first time it's imported. regards Steve -- http://www.holdenweb.com/ From emile at fenx.com Wed Oct 31 06:40:43 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Oct 2001 03:40:43 -0800 Subject: Strange results when comparing dates References: <9roa85$5ll$1@ctb-nnrp2.saix.net> Message-ID: <9roo92$vgtn6$1@ID-11957.news.dfncis.de> "Grant Beasley" wrote in message news:9roa85$5ll$1 at ctb-nnrp2.saix.net... > Hi > > I'm using the cx_Oracle module to access an Oracle database, in doing so, > I'm retrieving date time variables. According to the Python Database API, I > can use Timestamp to convert a time tuple (year, month, day, hour, minute, > second) to a date time type variable as used by the cx_Oracle module. This > works, and I can create these variables, but when comparing them I get VERY > strange results. > Consider: >>> class Nothing: pass >>> a = Nothing() >>> b = Nothing() >>> c = Nothing() >>> c < b 0 >>> b < a 1 Why? From Python22/Doc/ref/comparisons.html#l2h-288: Most other types compare unequal unless they are the same object; the choice whether one object is considered smaller or larger than another one is made arbitrarily but consistently within one execution of a program. My guess (I don't use cx_Oracle) is that cx_Oracle.Timestamp doesn't define compare functions and that you'll need to roll your own. -- Emile van Sebille emile at fenx.com --------- From ladvanszkykaroly at digicart.hu Mon Oct 8 04:26:58 2001 From: ladvanszkykaroly at digicart.hu (Károly Ladvánszky) Date: Mon, 8 Oct 2001 10:26:58 +0200 Subject: Question: Which Python to choose? Message-ID: <3bc15fa1_4@corp-goliath.newsgroups.com> www.python.org and www.activestate.com seem to release their versions with almost identical version numbers, at very close release dates. Is there a linkage between the two or are they completely separate products? Which one is more stable? Thanks for any advice, K?roly Ladv?nszky ______________________________________________________________________________ Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From hamish_lawson at yahoo.co.uk Tue Oct 16 05:31:11 2001 From: hamish_lawson at yahoo.co.uk (Hamish Lawson) Date: 16 Oct 2001 02:31:11 -0700 Subject: Whereabouts of Python port of Template Toolkit? Message-ID: <915a998f.0110160131.267044e2@posting.google.com> I remember once before coming across a Python port of the Template Toolkit library for Perl. However my attempts to find it again have so far turned out fruitless. Does anyone know where I can get hold of it? (Note that Template Toolkit shouldn't be confused with HTML::Template, of which there is also a Python port - htmltmpl.) Thanks, Hamish Lawson From tdickenson at devmail.geminidataloggers.co.uk Mon Oct 1 05:42:30 2001 From: tdickenson at devmail.geminidataloggers.co.uk (Toby Dickenson) Date: Mon, 01 Oct 2001 10:42:30 +0100 Subject: scanf style parsing References: <3BB16A50.BAE082FE@cygnus-software.com> <3BB2C7DA.F63EEAA7@cygnus-software.com> <9p4a4f$kdd$1@inputplus.demon.co.uk> Message-ID: <0hegrtgbg4bqjjkalcad8jr2nnh03k093d@4ax.com> "Fredrik Lundh" wrote: >Ralph Corderoy wrote: >> > or, much more preferably: >> > >> > if filename[-4:] == '.txt': >> >> Overall, the Perl code's better. It didn't have to hard-code the >> length of the string. > >if it matters, use endswith instead: > > if filename.endswith('.txt'): > ... That wont match any .TXT files. Whether thats a problem depends on whether you use Windows or not..... Toby Dickenson tdickenson at geminidataloggers.com From arturs at iidea.pl Thu Oct 4 15:09:52 2001 From: arturs at iidea.pl (Artur Skura) Date: 4 Oct 2001 19:09:52 GMT Subject: Nicer Tkinter on UNIX? References: <3BBCAF3D.C9EE4712@home.net> Message-ID: Chris Barker wrote: > Give PyQT and/or wxPython a try. They are worth it!! I fully appreciate and share your opinion, but I have to write something for folks who are completely clueless. I don't think they will be able to install additional libraries. Best regards, Artur -- http://www.wolneprogramy.org From gabriel_ambuehl at buz.ch Sun Oct 7 10:15:30 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Sun, 7 Oct 2001 16:15:30 +0200 Subject: SOAP.py and Python 2.1.1 Message-ID: <5992294913.20011007161530@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello, I'm trying to get SOAP.py V.0.9.7 to work on Python 2.1.1 (built from ports on a FreeBSD 4.4 box). While the server starts like it should, the client won't even send out a query but instead prints the following traceback: serv.addAccount(ownerid=2, customerid=1, accounttype=3, webserverid=111, mailserverid=111, adminserverid=111, webmailserverid=111, mysqlserverid=111, domainname="buz-test.com", password='aaakkaa', quota_webspace=100, quota_emailaccounts=50, quota_forwarders=-1, quota_autoresponders=-1, quota_mailinglists=10, quota_ftpaccounts=10, quota_subdomains=100) File "SOAP.py", line 3603, in __r_call self.__hd, self.__ma) File "SOAP.py", line 3523, in __call p, attrs = parseSOAPRPC(r, attrs = 1) File "SOAP.py", line 2804, in parseSOAPRPC t = _parseSOAP(xml_str, rules = rules) File "SOAP.py", line 2776, in _parseSOAP parser = xml.sax.make_parser() File "/usr/local/lib/python2.1/xml/sax/__init__.py", line 88, in make_parser raise SAXReaderNotAvailable("No parsers found", None) xml.sax._exceptions.SAXReaderNotAvailable: No parsers found This confuses me cause I thought xml should be available from stock and I've even got expat-1.2 and expat 1.95 installed so what's wrong here? Best regards, Gabriel -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO8BVeMZa2WpymlDxAQGqzgf+PzG6Hk/lOOpQyvGRfYyPUfXZRaEflG7Q 4hQao+fEfJY4OA6YdWUat/l7yaKuUTdKhU2yee/Tr+ADqPPGnQSCdMVnFzrx+Bss ynF+L6cEK63ZgxsLXKP2OhZgakFYKDuAXNMoG8yeAPVCqr61J51oq0pKBt6n3afw JXGBUm2qXLeoDZawI1mkkPnU7iHykBVtsWwCF06ToS28heXpOWqBeWjGTAfCXUmt S+Yd6+tEr0dEhuEkfwfI5E7Cb7vKiy+jXVHMpYz5NpqpM5aIa7l3aqpfjCnYjuiD lmJJELxBc3ZwpKMzpYv5LpRypveJ/LXuTP1qZ9KJEWjqCSJi6waJGQ== =t/hS -----END PGP SIGNATURE----- From matt at mondoinfo.com Tue Oct 23 15:30:55 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Tue, 23 Oct 2001 19:30:55 GMT Subject: Tkinter entry field question References: Message-ID: On Tue, 23 Oct 2001 19:19:21 +0200, Laura Creighton wrote: >Tkinter Entry fields have a width but not a height. If you don't like the >height they come in, and know what height you want, how do you change >them? Laura, You can do something like: >>> from Tkinter import * >>> r=Tk() >>> f=Frame(r,width=200,height=100) >>> f.pack_propagate(0) >>> f.pack() >>> e=Entry(f) >>> e.pack(fill=BOTH,expand=1) but the entry widget will still hold only one line of text. If you want multiple lines, you'll need to use the text widget. Regards, Matt From salemail at dial.pipex.com Wed Oct 17 06:24:11 2001 From: salemail at dial.pipex.com (Kevin D) Date: 17 Oct 2001 03:24:11 -0700 Subject: Conditional Expressions don't solve the problem References: Message-ID: Guido van Rossum wrote in message news:... > On the other hand, the ability to hide an assignment inside an > expression is IMO purely a way to save some keystrokes: the variable > needs to be named anyway, so you may as well do the assignment in a > separate step so that the reader is alerted of it. But "hiding an assignment inside an expression" is just the proposed solution (based on the C idiom) to an identified problem. As an alternative to considering whether the C functionality should be adopted (and personally, I'm happy if it isn't) I think we should go back and think up a Pythonic solution to the original problem (the while loop thing, IIRC). As I see it, there are two basic ways to write a while loop with a 'load' stage, each with it's own problems: 1) Duplication of the 'load': foo = some_long_expression while foo != terminating_condition: body_of_loop() foo = some_long_expression The argument for only having to spell the 'load' of "foo" once is the same as part of the argument for augmented assignment (mis-spelling of the expression leading to subtle bugs). This is more acute than for augmented assignment, as the load inside the body of the loop could be a great physical distance on the screen from the initial load it is duplicating. 2) "while 1" idiom: while 1: foo = some_long_expression if foo == terminating_condition: break body_of_loop() This solves problem (1) but IMHO, falls down in your "interrupting the thought process" requirement - it takes some mental juggling to work out just what the condition _is_ when reading the code. This is partly because the actual termination condition is buried somewhere away from the "while" statement and partly because the condition is reversed (so having searched out the termination condition, you must then read it as "until ", or "while not " - either way, the code has to be mentally "translated"/restructured as it's being read). So, to fix those problems a solution must: 1) Allow the loop's "load" code to exist just once, preferably somewhere near the terminating condition. 2) Have the terminating condition near the "while", and of the right "polarity". 3) To be Pythonic, have an obvious meaning. As an opening gambit, what about something like: while ; : Something like: while foo != terminating_condition; given foo = some_long_expression: body_of_loop() or maybe "where": while foo != terminating_condition; where foo = some_long_expression: body_of_loop() This would extend to 'if'/'elif': if m is not None; where m = compiled_re.match(inputline): stuff(m) elif m is not None; where m = compiled_re2.match(inputline): otherstuff(m) I'm not sure if the semi-colon would be neccessary/desirable. Unfortunately, I think the extra keyword _is_ neccessary - it helps make it read as English and therefore helps in the 'obvious meaning' stakes. Regards, Kev. From logiplexsoftware at earthlink.net Fri Oct 12 12:51:20 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 12 Oct 2001 09:51:20 -0700 Subject: Why so few Python jobs? (and licenses) In-Reply-To: <9q6aij$nnd$1@serv1.iunet.it> References: <9q6aij$nnd$1@serv1.iunet.it> Message-ID: <01101209512001.07109@logiplex1.logiplex.net> On Friday 12 October 2001 01:45, Alex Martelli wrote: > I thought sources came with most commercial libraries -- since you may > need to recompile them with so many different options (MS VC++ is very > unforgiving about linking object codes compiled with different runtime > libraries, etc, etc). I'm pretty sure we have source for all the Maybe (and I've never used VC++). In our case the library was actually an entire subapplication for displaying map data. It used a proprietary format for the data and provided only headers and .o files (no, I didn't choose this route - I didn't even work here at the time). We sold systems that utilized this package (luckily to only a few customers). That was a few years ago. Suddenly, out of the blue, one of these customers wants to import updated maps from some CAD software they have. We find that the library provider has gone under, and we have no way of converting the maps. Our customer is screwed and we're faced with rewriting an entire subsystem of our software. Had the source been available, this obviously wouldn't be a problem. > Non-commercial open-source libraries with non-restrictive licenses (a > la BSD, X, or Python) are of course another class of alternatives yet. No disagreement there, although I still don't see the problem with the LGPL (since we are discussing libraries). -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From gmcm at hypernet.com Wed Oct 10 08:32:35 2001 From: gmcm at hypernet.com (Gordon McMillan) Date: 10 Oct 2001 12:32:35 GMT Subject: changing `import' to use other than .py References: Message-ID: Harald Kirsch wrote: > Is there a way to tell import (or __import__) to > > a) use a different extension than .py when searching for files Yes. This has been done (by Quixote, dpython and one of the CORBA packages). > b) not to compile that file while/after importing All of the above do their own compilation (either because the source is not Python syntax, or - with dpython - because the compilation is done differently). You have a number of choices of how you do it (ihooks, imputil...). But importing is tricky and fragile, so the first thing I'd consider is pre-processing (the only real difference being that an import hook will allow you to do this on demand). - Gordon From hughett at mercur.uphs.upenn.edu Fri Oct 12 17:30:39 2001 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 12 Oct 2001 21:30:39 GMT Subject: get uniform binary data into array for further processing References: Message-ID: <9q7ndv$65r$1@netnews.upenn.edu> chr_w at gmx.de wrote: : I just started coding with python recently and ran into my first major : problem. Ok, here's the story: : I have to import pretty massive binary files containing double-precision : real values (climate data) so I can do some operations to it (mainly : simplyfying, getting the daily some etc.). The file can get really ugly in size... up to a gig eventually... : But my main concern: : a) what's the best and fasted way to get this data into a 2-dimensional : array (or list?)? : b) which modul to use (Numeric, array, struct, pickle) ??? : c) I have some fortran code which handles this quite good - is there a : similar way to do it in python? If the data is in IEEE 754 format (common, but I don't recall specifically if the SGI uses it), you can read the data using the BBLimage/Pyvox package from http://www.uphs.upenn.edu/bbl/publications_downloads/downloads/software.shtml There is one catch: the data will be read into Pyvox arrays, which are not yet compatible with Numeric arrays; but you can do many useful data operations using Pyvox arrays themselves. (Pyvox was designed for volume image processing and happily handles data sets containg 10 million samples.) You might want to wait a day or two; I've just released a new version (0.65) but couldn't upload it to the website because the server was down. Paul Hughett From phr-n2001d at nightsong.com Thu Oct 18 19:53:36 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 18 Oct 2001 16:53:36 -0700 Subject: Triple-DES implementation in Python References: <1854cfa0.0110181325.50a4aba6@posting.google.com> Message-ID: <7xelo0v727.fsf@ruckus.brouhaha.com> ksatcu at yahoo.com (Krish) writes: > Does anyone know if there is a publically available library for > DES/Triple DES implementation in Python. > > Thanks a bunch for the info. I have one but it fails test vectors (probably wrong byte order somewhere in the calculation). I need to get around to debugging it. I'll send it to you if you want. From strnbrg at c532352-a.frmt1.sfba.home.com Thu Oct 25 01:16:38 2001 From: strnbrg at c532352-a.frmt1.sfba.home.com (Theodore D. Sternberg) Date: Thu, 25 Oct 2001 05:16:38 GMT Subject: Tkinter.Listbox: activate() doesn't work Message-ID: How can I programmatically activate an element in a Tkinter.Listbox? I've tried activate() but nothing happens. For example, import Tkinter root=Tkinter.Tk() lb = Tkinter.Listbox(root) lb.insert( Tkinter.End, 'foo' ) lb.insert( Tkinter.End, 'bar' ) lb.pack() lb.activate( 1 ) ...but I don't see 'bar' now getting highlighted. What am I doing wrong? Ted Sternberg Berkeley, CA From loewis at informatik.hu-berlin.de Sat Oct 27 17:20:53 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 27 Oct 2001 23:20:53 +0200 Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> Message-ID: "Bruce Dodson" writes: > Would Stackless have a better chance of making it into the core if its > initial PEP talked only about increasing performance and removing limits on > recursion? No. It is not the feature set that prevents its incorporation; it is the implementation strategy chosen. The patch is too intrusive. Regards, Martin From No at Spam.Please Wed Oct 10 03:26:20 2001 From: No at Spam.Please (Weet Vanniks) Date: Wed, 10 Oct 2001 09:26:20 +0200 Subject: I'd rather have Octonion rings References: Message-ID: <3BC3F81C.9AE4AAF7@Spam.Please> Just a matter of personal preference ! > From skip at pobox.com Sun Oct 7 14:38:31 2001 From: skip at pobox.com (Skip Montanaro) Date: Sun, 7 Oct 2001 13:38:31 -0500 Subject: (Solution) Re: Problem with embedding - can only make about 150 calls... In-Reply-To: References: Message-ID: <15296.41255.765055.373652@beluga.mojam.com> Mads> I found a solution >> static PyObject * MyTest(PyObject * self, PyObject *args) { >> return Py_None; Mads> return Py_BuildValue(""); >> } One problem with your Py_None return is that you didn't Py_INCREF it first. Over time Py_None's refcount may well have dropped to zero. Blammo! Py_BuildValue("") returns an INCREF'd object. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From grante at visi.com Tue Oct 30 10:52:23 2001 From: grante at visi.com (Grant Edwards) Date: Tue, 30 Oct 2001 15:52:23 GMT Subject: How smart are Semaphore Objects? References: <32cedc66.0110292253.5eaaca31@posting.google.com> <3BDE7AA4.2250BFF5@accessforall.nl> <32cedc66.0110300638.4a51129@posting.google.com> Message-ID: In article <32cedc66.0110300638.4a51129 at posting.google.com>, Matthew D. Wood wrote: > Ype Kingma wrote in message > >> A Semaphore can be released from an other thread. > > That sucks. Says you... >> It can be better for performance to release a Semaphore from another thread. >> I would consider this as a candidate for style improvement, though. > > I don't understand. Why would it be better for a non-owning thread to > release a Semaphore? I just recently wrote an application (not in Python) where common resournces (a pool of serial ports) is shared by two distinct groups of threads. Each group of threads impliments a more-or-less independant function, but only one group can have ownership of the serial port. In each group of threads, there is one thread that is accepting incoming network connections. That thread is responsible for acquiring the serial port. Once the connection is set up, there is a different thread for each active connection that handles traffic. The traffic handling thread is responsible for shutting down the connection and releasing the serial port. Perhaps it's a flaw in my overall system design, but it was simpler by far to have one thread acquire the resource and a different one release it. -- Grant Edwards grante Yow! I'm using my X-RAY at VISION to obtain a rare visi.com glimpse of the INNER WORKINGS of this POTATO!! From pih at oek.dk Sat Oct 6 08:24:36 2001 From: pih at oek.dk (Peter I. Hansen) Date: Sat, 06 Oct 2001 14:24:36 +0200 Subject: python and HTML integration References: <3BBCB1F0.ED40594A@oek.dk> <23891c90.0110050219.4f7f51fa@posting.google.com> Message-ID: <3BBEF803.28D2088C@oek.dk> Paul Boddie wrote: > I would recommend that anyone wanting a document template/production > framework or a Web development environment look at the modules > currently in existence and evaluate whether such modules are suitable > before considering writing their own. To start with, take a look at... > > http://www.paul.boddie.net/Python/web_modules.html > http://webware.sf.net/Papers/Templates/ > > There have been a lot of new HTML template/production modules released > recently, but I wouldn't go and develop something new when there's > something which is almost exactly what I want available from some > server somewhere. > > Paul I've decided on using PyML, but do you have any experience i trying to install this ? I've followed the instruktions, but it dosn't seem to interpret my embedded Python code... /Peter From des.small at bristol.ac.uk Fri Oct 12 05:38:37 2001 From: des.small at bristol.ac.uk (Des Small) Date: Fri, 12 Oct 2001 09:38:37 GMT Subject: signum() not in math? References: <3BC6B774.4688E9A2@darwin.in-berlin.de> Message-ID: Dinu Gherman writes: > Hi! > > Time for a periodic frenzy about the standard lib again... ;-) > How comes there is no sign() or signum() function in math? The only possible controversy would be the definition at zero. I usually define signum(0) = 0, but others may not. I don't even want to think about the differences between +0 and -0 in this case. I certainly endorse the sentiment that it should be available in the standard library, but now that I come to look (and prompted by your use of "sign()") I find that there _is_ a sign function in Numeric. Since I always use Numeric, this removes much of the urgency. > Surprising. Ahh, a missing PEP, even? That could be > the case... ;-) I think there is a sentiment that Numeric should be absorbed into the standard library, after the code has been cleaned up (which noone has time to do). > Waiting-for-the-Snake-Oracle's-advice'ly, > > Dinu Des. -- Dr Des Small, Scientific Programmer, School of Mathematics, University of Bristol, Tel: 0117 9287984 From jmsun at bioeng.ucsd.edu Thu Oct 4 12:48:05 2001 From: jmsun at bioeng.ucsd.edu (Jeffrey) Date: 4 Oct 2001 09:48:05 -0700 Subject: Tkinter/Pmw Pack Question Message-ID: <3daa1aa8.0110040848.22b76a02@posting.google.com> Hi, I'm using a the pack function to show my widget in it's parent widget. But I wanted to make it so that the child widget and go from it's parent widget to another widget. So in essence in can move around.... Thanks, Jeff From greg at cosc.canterbury.ac.nz Wed Oct 31 20:19:50 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 01 Nov 2001 14:19:50 +1300 Subject: Unpacking extension (Re: A small inconsistency in syntax?) References: <6qelnludt5.fsf@abnoba.intevation.de> <3BDF7571.5D8CB310@cosc.canterbury.ac.nz> Message-ID: <3BE0A336.EDC570C8@cosc.canterbury.ac.nz> Rainer Deyke wrote: > > "Greg Ewing" wrote in message > news:3BDF7571.5D8CB310 at cosc.canterbury.ac.nz... > > case foo: > > Nothing(): > > print "We got nada" > > Pair(Furble(p, q), Furble(r, s)): > > print "We got a pair of furbles" > > Pair(a, b): > > print "We got a pair of something else" > > x: > > print "We got something else" > > Ambiguous to the point of uselessness. > > a, b = 7, 13 > case foo: > Pair(a, b): > print 'Got Pair(7, 13)' No. Bare names in argument positions would always be interpreted as names to be bound. A possible extension would be to allow constants in argument positions, so case foo: Pair(7, 13): print 'Got Pair(7, 13)' Another possible extension would be to provide a way to mark an argument for evaluation, maybe a, b = 7, 13 case foo: Pair(+a, +b): print 'Got Pair(7, 13)' -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From timr at probo.com Sat Oct 13 00:00:30 2001 From: timr at probo.com (Tim Roberts) Date: Fri, 12 Oct 2001 21:00:30 -0700 Subject: CPU time References: Message-ID: Skip Montanaro wrote: > > >> I thought time.clock() measures CPU time which (i assume) is > >> consistent regardless of other S/W running.. but somehow the > >> measurement fluctuates a lot. Am I misunderstanding this function? If > >> so, what is the function w/ the functionality I'm looking for? >... > >If you are using Win32, time.clock uses a Windows routine called >QueryPerformanceCounter. I have no direct experience with it, but I am told >that it returns a value that is independent of what process has the >processor. Correct. QueryPerformanceCounter measures total time since boot. time.clock() on Win32 returns the total elapsed seconds since the first call to time.clock() in the process. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mjais at web.de Mon Oct 22 09:28:27 2001 From: mjais at web.de (Markus Jais) Date: Mon, 22 Oct 2001 15:28:27 +0200 Subject: problem with pirxx Message-ID: hello, I installed the latest version of pirxx on my Suse 7.1 with python 2.1 when I call the testscript I get the following error: $ python test.py Traceback (most recent call last): File "test.py", line 15, in ? from pirxx import _pirxx ImportError: shared object not open I am quite new to python and have never seen such an error. can anybody help?? thanks markus From db3l at fitlinxx.com Tue Oct 2 16:45:53 2001 From: db3l at fitlinxx.com (David Bolen) Date: 02 Oct 2001 16:45:53 -0400 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> Message-ID: Dale Strickland-Clark writes: > The problem isn't with handling the database assignments. It's the > fact that all instance assignments (self.anything) has to go through > the same code. This is such an ugly overhead. > > Throughout the class, there are dozens of uses of instance variables > which are forced through this code. I don't want to know about them. But I think that's what Steve's suggestion helps you avoid. By placing all the database assignments that you do need to monitor into a contained class, it's only that contained class that needs __setattr__, and thus your normal instance assignments aren't touched. And that contained class has no instance variables other than those that are relevant for the database it represents. > I guess I'd like to explicitly declare which attributes are part of > the public face of the class and which are not. The same suggestion can also help with this problem. Call the instance of the contained database class "public", and then all users of your class will be accessing database query/assignments with references such as "object.public.value" I suppose if you really wanted to (e.g., users of your object just had to be able to reference object.value), you could invert this. Leave all instance variables as just for the database, and place all of your prior private instance variables into a contained object - let's call it "private". You'd end up using "self.private.xxxx" instead of just "self.xxx" inside your object. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From unknown at lee-morgan.net Thu Oct 4 04:03:21 2001 From: unknown at lee-morgan.net (Lee Morgan) Date: Thu, 04 Oct 2001 08:03:21 GMT Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> Message-ID: Markus Schaber writes: > > I would think that importing in python is some kind of linking. > Dynamically and at run-time, but it is some sort of linking. > Hmm, how about if py2exe is used to distribute? You can't then get the LGPL code, change it and relink it to alter behaviour. Actually, as its a zip archive, maybe you could...I wonder if that would that count? -- Lee Morgan From nomad*** at ***freemail.absa.co.za Wed Oct 31 06:11:47 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Wed, 31 Oct 2001 13:11:47 +0200 Subject: XML can't read Unicode shock horror. News at 11. References: Message-ID: <52nvttk8pgjjldf9t020ehke19hlb5v6vh@4ax.com> On Tue, 30 Oct 2001 14:04:56 +0000, Dale Strickland-Clark wrote: >Dale Strickland-Clark wrote: > >>Given that XML is very Unicode friendly, this seems a rather odd >>limitation. >> >>>>> import xml.dom.minidom >>>>> dom = xml.dom.minidom.parseString(u'') >>Traceback (most recent call last): >> File "", line 1, in ? >> File "c:\python21\lib\xml\dom\minidom.py", line 915, in parseString >> return _doparse(pulldom.parseString, args, kwargs) >> File "c:\python21\lib\xml\dom\minidom.py", line 901, in _doparse >> events = apply(func, args, kwargs) >> File "c:\python21\lib\xml\dom\pulldom.py", line 299, in parseString >> buf = StringIO(string) >>TypeError: expected string, unicode found >>>>> > >I see that this is probably the same as Python bug #216388 which has >been around for over a year and been given a low priority (3). > >Is there any chance that this might be elevated? > >Non-unicode XML is a bit restrictive. :-( "Non-unicode XML" isn't XML, it just looks like XML. -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From andy47 at halfcooked.com Tue Oct 2 01:54:27 2001 From: andy47 at halfcooked.com (Andy Todd) Date: 2 Oct 2001 05:54:27 GMT Subject: newbie str to int References: <9pbetr$jp83@imsp212.netvigator.com> Message-ID: "James" wrote in <9pbetr$jp83 at imsp212.netvigator.com>: >I am switching from Perl to Python, and would >like to convert string '123abc' to integer 123. > If your string is always of that form (ie a three digit integer followed by some non-numeric characters) then you just need; >>> foo=int('123abc'[:3]) >>> foo 123 >>> print foo*2 246 >foo = int('123abc') # error >foo = string.atoi('123abc') #error >foo = eval('123abc') # error > >I tried the above, then tried the following. > >tmp = '' >for i in '123abc': > if 47 < ord(i) < 58: > tmp += i >foo = int(tmp) # yay Yuck, too much Perl, must shut down brain. Read the tutorial, in particular the section on string subscripting (in section 3.1.2) > >Why doing simple thing like this is so complicated ? Its not complicated. The important thing to bear in mind here is the format of the data you wish to play about with. Where are you getting this string from? Is it really one string or is it a number followed by a sequence of characters? I find it much easier to store information in the smallest possible chunks to avoid these kind of problems, you can construct much more easily than you can slice and dice. > >Perl >$foo = '123abc' + 0; > >Please explain in newsgroup. >Many thanks in advance. > > > HTH, Andy -- Content free posts a speciality From thehaas at binary.net Tue Oct 23 14:30:38 2001 From: thehaas at binary.net (Mike Hostetler) Date: 23 Oct 2001 11:30:38 -0700 Subject: Omaha Python Group Message-ID: There was some interest expressed on the Omaha Linux Group list to start a similar group for Python developers in the Omaha area a place to swap ideas and to learn more about the wonderful world of Python. Anyone is invited, though we are focusing on people in the Omaha/Lincoln area. web page (for now): http://groups.yahoo.com/group/oma-python Subscribe: oma-python-subscribe at yahoogroups.com Mike Hostetler From ignacio at openservices.net Wed Oct 10 02:55:13 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 10 Oct 2001 02:55:13 -0400 (EDT) Subject: PYTHONPATH and embedding python In-Reply-To: Message-ID: On Wed, 10 Oct 2001, Ignacio Vazquez-Abrams wrote: > On Tue, 9 Oct 2001, Ken Seehof wrote: > > > // untested code: > > char *path, *newpath; > > path=Py_GetPath(); > > newpath=new char[strlen(path)+4]; > > strcpy(newpath, path); > > strcat(newpath, ":."); // ":." for unix, or ";." for windows > > PySys_SetPath(newpath); > > free(newpath); > > D'oh! Yeah, that's what I meant. I guess I never noticed anything because the > module I used to test it is this " big. Well, except for the new[]/free mixing of course. the call to free should probably be a del[] (I think that's it; I can't find my copies of EC++ and MEC++ right now...). -- Ignacio Vazquez-Abrams From phd at phd.pp.ru Tue Oct 2 04:02:09 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 2 Oct 2001 12:02:09 +0400 Subject: GNU wars again (was Re: Proposal: add vector arithmetic to array module) In-Reply-To: <01100111042501.14136@logiplex1.logiplex.net>; from logiplexsoftware@earthlink.net on Mon, Oct 01, 2001 at 11:04:25AM -0700 References: <01100111042501.14136@logiplex1.logiplex.net> Message-ID: <20011002120209.E17018@phd.pp.ru> On Mon, Oct 01, 2001 at 11:04:25AM -0700, Cliff Wells wrote: > It's free, and you're free not to use it if you don't want your code to be > free. It's called a trade-off. You get the combined efforts of thousands of > GNU programmers to help you solve your problem, and in turn you provide your > little bit of help back. Nice said, Cliff! Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From AdrianLeu at kelseus.com Fri Oct 26 06:22:38 2001 From: AdrianLeu at kelseus.com (Adrian Leu) Date: 26 Oct 2001 03:22:38 -0700 Subject: Python and VisualC++ debug mode Message-ID: <993ae4ca.0110260222.25ff0301@posting.google.com> Hi ! I am relatively new to Python. I am using VC 6.0 and W2K to write a small Python interface for a C++ project. I am encountering problems with the "debug" version (the "release" version is working fine). I have build the debug version for Python2.0 and have the python20_d.dll in the WINNT\system32 folder (where the release version python20.dll is too) and python20_d.lib libraries in Python_current_directory\libs (together with all the other debug libraries created during the python build). I have written a small module in Python that imports sys, re and string modules. In my main C++ file (an .exe) that I am using for testing purposes, I import this module and call one of its methods to output something. However, although this works fine in "release" it exits with "The thread 0x3C8 has exited with code 0 (0x0)" error in "debug". What am I doing wrong? As a second part of the question, where can I find the source code for the win32 python modules/libraries (win32ui etc)? Thanks a lot for your help. Adrian. From logiplexsoftware at earthlink.net Thu Oct 25 13:21:05 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 25 Oct 2001 10:21:05 -0700 Subject: Critical sections and mutexes In-Reply-To: References: Message-ID: <01102510210500.26379@logiplex1.logiplex.net> On Wednesday 24 October 2001 19:56, brueckd at tbye.com wrote: > > I do see your point, but I think of it from the opposite point of view: a > newbie learning about threads would be thrilled to get a simple > producer/consumer program working to play around with. Once they see how > cool it is, then you move on to teaching them about locking problems, > mutexes, etc. And hopefully, they played with it enough already to get > bitten by a problem so that they really understand the lesson. Yes, I can see your point here (when I took CS classes we were often taught that way: do it wrong, then learn language features that help do it right). If this were a classroom, then I would probably concede at this point. However, without the luxury of being able to hold someone's hand and lead them step-by-step, I think it's best to just give them the most appropriate information for solving their immediate problem. I've found that it's far more frustrating to have what appears to be a correct program fail for some obscure reason (as your example would if one started modifying it to any significant degree - and a user trying to understand the mechanics of the code would undoubtedly do so). Any CS book that discusses threading (in the general sense) will emphasize the need for locking shared resources. Not only that, but the code you supplied may have worked, but it also drives CPU utilization through the roof (as you mentioned yourself, locks can be used to avoid busy loops) so a newbie testing such code might be immediately put off from further investigation into threads simply due to apparent performance reasons. Another good reason to supply correct code, not just the simplest code. > I think it discourages newbies to bombard them with all the locking issues > up front, and it's a real strength of Python (especially for programming > newbies) that you can often "get away" with no explicit thread-safety > measures. Were your first multithreaded programs threadsafe? Mine sure > weren't. But it was okay because at that point it was much more important Actually, the reason I started using Python was because I needed to write a multi-threaded program on Windows and Cygwin gcc didn't support threads at the time (and I didn't want to use fork). So my very first Python program was also my very first threaded program _and_ my first network program. It was in fact, thread-safe and only took around a week to get working (if you don't count feature-creep). I don't think locking is such a difficult concept to grasp (at least no more than threading itself), and is fundamental to threading. > to get something working. This is no different than any of the other > newbie-friendly aspects of Python (no type decls, no memory management, > etc.) - people can get up to speed quickly because they do have to get > overwhelmed with the details all at the start. Yes, one of the appealing things about Python is that it tends to make concepts that are difficult to master in other languages appear simple. However, it doesn't (and shouldn't) encourage you to adopt bad programming practices just because you can (I _could_ use the variable x to hold an int, a string and a list at different times in the same function, but it would be bad). I don't feel locking is a detail so much as a fundamental aspect of threading. The fact that you can get away with it (in special cases) under current implementations of Python is not really a good reason to do it. It's my feeling that making high-level code rely on low-level implementation details of an interpreter or compiler is always a bad idea (in any language - look at all the non-portable C programs that exist [and the OS's that have hacks to support them] due to programmer's using implementation-specific features of a particular platform or compiler). Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From rparnes at megalink.net Tue Oct 2 09:41:38 2001 From: rparnes at megalink.net (Bob Parnes) Date: Tue, 2 Oct 2001 08:41:38 -0500 Subject: list.append problem? References: Message-ID: Bob Parnes wrote: > Steve Holden wrote: > >> "newgene" wrote in message >> news:a50631f6.0110011345.31523630 at posting.google.com... >>> I am a newer of python. I have a problem like this code: >>> >>> >>> a=b=c=[] >>> >>> a.append(1) >>> >>> b.append(2) >>> >>> c.append(3) >>> >>> a >>> [1, 2, 3] >>> >>> b >>> [1, 2, 3] >>> >>> c >>> [1, 2, 3] >>> >>> a,b,c become the same, although append method applied seperately. >>> It's really strange and unreasonable. >>> My python is ActivePython Build 210 running on WinNT. >>> >> Strange and unreasonable as it may seem, it's classic Python. All three >> variables are bound to the same object, so when you change the object (no >> matter which name you use) the value you see when you access any of the >> names is the same. >> >> However, try >>>>> a = [] >>>>> b = [] >>>>> c = [] >>>>> a.append(1) >>>>> b.append(2) >>>>> c.append(3) >> >> and you will see what you feel is more reasonable behavior: in this case >> each variable is bound to a different list, and so changing one of the >> lists doesn't affect the values bound to the other variables. >> >> You get used to it after a while, and after your third progam it will >> seem the most reasonable thing to do! >> >> regards >> Steve >> -- >> http://www.holdenweb.com/ >> >> >> >> >> >> > > As another newcomer I discovered this on my own. What is confusing, I > think, is that it seems to apply only to empty objects. For example > >>>> a = b = [1, 2. 3] >>>> a = [4, 5, 6] >>>> b > [1, 2, 3] >>>> a.append(7) >>>> a > [4, 5, 6, 7] >>>> b > [1, 2, 3] > > In this case a and b are not bound to the same object. It seems to me that > python treats empty objects differently from assigned objects. Or > something like that, I'm probably not articulating it well. > Sorry, I wrote too hastily >>> a = b = [1, 2, 3] >>> a.append(4) >>> a [1, 2, 3, 4] >>> b [1, 2, 3, 4] The rule is the same, I used the wrong example. -- Bob Parnes rparnes at megalink.net From phd at phd.pp.ru Mon Oct 15 06:42:27 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Mon, 15 Oct 2001 14:42:27 +0400 Subject: J2EE equivalent in Python In-Reply-To: <23891c90.0110150233.3561ca32@posting.google.com>; from paul@boddie.net on Mon, Oct 15, 2001 at 03:33:29AM -0700 References: <23891c90.0110150233.3561ca32@posting.google.com> Message-ID: <20011015144227.H17226@phd.pp.ru> Hi, Paul! On Mon, Oct 15, 2001 at 03:33:29AM -0700, Paul Boddie wrote: > http://www.paul.boddie.net/Python/web_modules.html Every time I go to this address I got error404. When I go to http://www.paul.boddie.net it gives me framed page http://www.infector.com/Paul/, and the page you mentioned is on http://www.infector.com/Paul/Python/web_modules.html Something wrong with my browser/proxy? (links, no javascript) Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From kramsey at nvl.army.mil Tue Oct 2 14:24:52 2001 From: kramsey at nvl.army.mil (Ken Ramsey) Date: 2 Oct 2001 11:24:52 -0700 Subject: Raising Errors in __init__ Message-ID: Hello, Running Python2.1 on Solaris, I've come accross a problem, which I've solved, but I don't quite understand. My program suffered a small memory leak problem, which became critial when I went to process huge amounts of data. I carefully checked for cross references and cyclical data structures until I was sure there were none, yet still the problem remained. Watching my memory footprint grow as the program ran, I realized that footprint only grew whenever an exception was thrown during the __init__() function of a certain class. So, I changed the __init__() function, having it simply set state variables, and created an init2() function to actually operate on them. Magically, not only did my memory leak disappear but the initial size of my program shrank too. Following is a very basic outline of part of the program. It is for doing statistical analysis of imagery. There is a main image class, called aImage, and it serves in part as a container class for a list of regions of interest, or ROIs: ImageError = "ImageError" RoiError = "RoiError" class LeakPlugger: def __del__(self): for key in self.__dict__.keys(): self.__dict__[key] = None class aImage(LeakPlugger): def __init__(self, filename): self.filename = filename self.roiList = [] LeakPlugger.__init__(self) # def init2() self.fp = open(filename, 'rb') # ... read the file to assign things like width, height, pixels, etc. # to self.width, self.height, self.pixels, etc. for i in range(100): try: self.roiList.append(self.getRandomRoi()) except RoiError, msg: sys.stderr.write("%s: %s\n" % (RoiError, msg)) continue def getRandomRoi(self): # excerpted ... set up randomizer, get random coords return ROI(randomX, randomY, roiWidth, roiHeight, self.width, self.height) def __del__(self): self.fp.close() LeakPlugger.__del__(self) class ROI(LeakPlugger): def __init__(self, x, y, w, h, imW, imH): LeakPlugger.__init__(self) if (x+w) > imW or (y+h) > imH: raise RoiError, "ROI doesn't fit on image" self.x, self.y, self.w, self.h = x, y, w, h if __name__ == '__main__': import os dir = "/images" filenames = os.listdir(dir) for file in filenames: image = aImage(os.path.join(dir, file)) # image.init2() # do statistical stuff Again, when the exception is thrown in aImage's __init__, the process grows. Uncommenting the init2() eliminates this problem and shrinks the process size, too. Anybody else encounter such problems? If so, what's the skinny? Is it good policy to limit the actions of Python's __init__ function to simple things, saving real work for helper functions? Thanks, Ken Ramsey eoir-measurements kramsey at nvl.army.mil From pez at apocalyptech.com Tue Oct 16 11:33:58 2001 From: pez at apocalyptech.com (CJ Kucera) Date: Tue, 16 Oct 2001 10:33:58 -0500 (CDT) Subject: maximum recursion in "re" module? In-Reply-To: <15308.19266.695456.27299@beluga.mojam.com> from "Skip Montanaro" at Oct 16, 2001 09:59:14 AM Message-ID: <200110161533.KAA23144@scortch.unisrv.net> On Tue Oct 16 09:59:14 2001, Skip Montanaro wrote: > Then s.find(startString) will return the offset in s to the start of > startString or -1: Ick. Offsets. :) I don't like having to keep track of that kind of stuff. > If you really want to do this with regular expressions, I think it would be > easier to explicitly flag the URL like so: > > urlPat = re.compile('Lo Fi Play
' > ' Repeat the Zawinski mantra (this stolen from a 1999 c.l.py post by Fredrik > Lundh, the author of Python's current regular expression engine): > > Some people, when confronted with a problem, think > "I know, I'll use regular expressions". Now they have > two problems. > Jamie Zawinski, on comp.lang.emacs lol. That's beautiful. Thanks again for the help! -CJ WOW: Rapacious | A priest advised Voltaire on his death bed to apocalyptech.com/wow | renounce the devil. Replied Voltaire, "This pez at apocalyptech.com | is no time to make new enemies." From mike at unicorn-fs.com Tue Oct 23 05:31:07 2001 From: mike at unicorn-fs.com (Mike Peat) Date: Tue, 23 Oct 2001 10:31:07 +0100 Subject: Python for ipaq References: Message-ID: <1003829421.27538.0.nnrp-01.d4f0f8ae@news.demon.co.uk> Karol Regarding your second question: I have just written a simple FTP client in Python using ftplib and you would be welcome to it... but it is the first non-trivial program I have ever written in Python and I'm a little nervous about letting anybody see it . Mike Peat "Karol Makowski" wrote in message news:slrn9taa4e.3ub.spaceman at shield.bsdirc.net... > hello > > Do you know where can i find python for compaq ipaq pocket pc running > Windows CE? > > And second question: > i need a _simple_ ftp client written in python (using ftplib) > which will store some files on server and will get other files from > server. I need to put it in my C program via the system(); > > Thanks! > > -- > Karol Makowski, System Administrator > URL: http://spaceman.bsdzine.org > e-mail: spaceman at bsdzine.org From sholden at holdenweb.com Wed Oct 3 16:35:59 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 3 Oct 2001 16:35:59 -0400 Subject: __getatr__ question References: <89a9b6ce.0110030954.7ee3043f@posting.google.com> Message-ID: "Jim" wrote in message news:89a9b6ce.0110030954.7ee3043f at posting.google.com... > The following code is used to create a class. If I make an instance > of the class called "k", then calling k.func1(23) will print > "k.func1(23)", and calling k.func2() will print "k.func2()" and return > 12. The problem occurs when I nest the functions like this: > k.func1(k.func2()). This prints "k.func2()", "k.func2(12)" when I > really want it to print "k.func2()", "k.func1(12)". It gets more > interesting when I do something like k.func1(k.func2() + k.func3()). > This results in a printout of "k.func2()", "k.func3()", "k.func2(12)". > > What's up with this, and it a bug or a feature of python? It seams > like the __getattr__ is not being called/refreshed in the external > function if it is also called inside the function. > > Thanks for any help > > -Jim > > ****** Code ******* > > class klass: > > def __init__(self, name): > self.name = name > > def __getattr__(self, a): > > self.string = a > return(self.nop) > > def __repr__(self): > return '' > > def nop(self, a = None): > > if (a == None): > #pass > print self.name + '.' + self.string + '()' > return 12 > > else: > #pass > print self.name + '.' + self.string + '(' + str(a) + ')' Well, what do you expect when you are trying to save state for a number of recursive calls in the same instance variable. Try adding print "I just set 'self.string' to", a inside the __getattr__() method. You will see that the setting of func1 is overwritten by the setting of func2, because of the call structure. regards Steve -- http://www.holdenweb.com/ From R.Brodie at rl.ac.uk Mon Oct 8 12:29:46 2001 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 8 Oct 2001 17:29:46 +0100 Subject: Curious assignment behaviour References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> Message-ID: <9psk9s$rbk@newton.cc.rl.ac.uk> "John Roth" wrote in message news:ts3hb2p7dbh7b5 at news.supernews.com... > > > Pascal uses := > > > > Nope. Pascal is like Python, it doesn't have an assignment operator. > > But it does have a *syntax* that means assignment, just like Python. > I believe that is what the poster had in mind. It's probably true that the use of := for assignment and = for equality is less prone to error for those unused to C-like languages. I think it's a lost battle though unless we want another controversial language change in Python 3 ;) In Pascal, code with =/:= confusion won't compile. Unfortunately, I suspect that is much more significant than the symbols themselves. From mlh at idi.ntnu.no Tue Oct 2 18:56:15 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 3 Oct 2001 00:56:15 +0200 Subject: ANN: Interactive Python Prompt Tools References: Message-ID: <9pdgmf$cjq$1@tyfon.itea.ntnu.no> "Nathaniel Gray" wrote in message news:mailman.1001885042.17905.clpa-moderators at python.org... > WHAT ARE THEY? > > LazyPython is an exception hook for Python versions 2.1 and later that brings > shell escapes, auto-parenthesizing and auto-quoting to the python interactive > prompt. Cool! - Magnus (who is running off to start writing his own exception hooks :)) -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From peter at engcorp.com Mon Oct 1 19:18:39 2001 From: peter at engcorp.com (Peter Hansen) Date: Mon, 01 Oct 2001 19:18:39 -0400 Subject: How do Java interfaces translate to Python? References: Message-ID: <3BB8F9CF.E9240EC5@engcorp.com> Steve Holden wrote: > > wrote ... > > [ ... ] (Java assumes you're both dishonest *and* > > stupid). > > > Surprising Microsoft weren't more enthusiastic about it, really ;-) Not really. Java _doesn't_ assume you have money to spend... :) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From richard at bizarsoftware.com.au Thu Oct 18 19:37:24 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 19 Oct 2001 09:37:24 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: <200110180758.f9I7w4M00794@mbuna.arbhome.com.au> References: <200110180758.f9I7w4M00794@mbuna.arbhome.com.au> Message-ID: <0110190937243F.11044@ike> On Thursday 18 October 2001 17:58, Anthony Baxter wrote: > >>> "Tim Peters" wrote > > > > The bugfix release process is the topic of Aahz's PEP 6, who may have > > believed that titling it "Bug Fix Releases" was enough clue : > > Ah, that cunning "hidden in plain sight" approach. Who'd have thought. > > It still doesn't cover the process of deciding what would go in the > patch release... I know that I'd be happier upgrading to 2.1.2 than > 2.2 in the next couple of months - and given the peasants-are-revolting > sentiment of c.l.py at the moment, I doubt I'm the only one... > > How would this sound as a first cut at a what-goes-in-and-what-stays: > > a) bugfixes. > b) no new modules, no new packages. > c) no new methods on classes, unless they're bugfixes. > d) if the bug fix relies on some 2.2-ism, then it's either rewritten, > or ignored and relnoted Ack, just thought of e) Documentation bug fixes. Or are they covered in a)? Richard From phd at phd.pp.ru Tue Oct 30 06:14:56 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 30 Oct 2001 14:14:56 +0300 Subject: Send an email . In-Reply-To: <007901c16133$0835e260$a197003e@rashome>; from weismann@netvision.net.il on Tue, Oct 30, 2001 at 01:07:12PM +0200 References: <007901c16133$0835e260$a197003e@rashome> Message-ID: <20011030141456.A1342@phd.pp.ru> On Tue, Oct 30, 2001 at 01:07:12PM +0200, Amit Weisman wrote: > What module should I use to send an email ? mimetools and MimeWriter for generating mail. smtplib to actually send generated mail. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jim.correia at pobox.com Fri Oct 19 21:14:46 2001 From: jim.correia at pobox.com (Jim Correia) Date: Sat, 20 Oct 2001 01:14:46 GMT Subject: Dictionary from list? References: <6KVz7.132664$vq.30203786@typhoon.ne.mediaone.net> Message-ID: In article , quinn at cruzeiro.ugcs.caltech.edu (Quinn Dunkan) wrote: > On Fri, 19 Oct 2001 13:17:54 GMT, Jim Correia wrote: > >In article , Michael Hudson > >wrote: > > > >> > I'm a python newbie. I know how to do it "by hand" with a loop, but is > >> > there a built in conversion operater that will let me do something > >> > simply like the perl assignment? > >> > >> No. Write the loop. > > > >That's unfortunate - a simple assignment would be better. In the > >simplest case of my usage, the loop (while ultra short) could be 50% of > >the code. > > This doesn't make any sense to me. If a two line loop is 50% of your program, > then your program is four lines. If you're going to play meaningless > line-counting games at least come up with some more impressive numbers :) It was a stupid argument. > And assignment that uses a heuristic to convert an array into a hash is not > really "simple". I'm used to the perl syntax for this operation, and it would be easier to type. That is all. > import sys > d = {} > assert (len(sys.argv)-1) % 2 == 0, \ > 'argv must consist of pairs, key "%s" has no value' % sys.argv[-1] > for i in range(1, len(sys.argv), 2): > d[sys.argv[i]] = sys.argv[i+1] > > for k, v in d.items(): > print k + ': ' + v That's what I ended up doing. > Note that the python version actually checks to make sure the input makes > sense. There's no way to know how the perl version reacts to bad input except > by testing it or reading the documentation. I suspect perl will silently give > the last key a nil value, but once again there's no way to know for sure by > just looking at it. It fails at runtime with an odd number of elements in hash list error. > Hopefully you and everyone who reads your code has all > the little details in the camel book memorized. I was just asking if there was a built in coercion available. (Coercions aren't unheard of in scripting languages.) This wasn't a my language is better than your language war. I don't have particularly strong feelings about perl or python one way or the other (I do most of my work in compiled languages - C mostly) but use the right tool, or sometimes the convenient tool, for the job. > This is a good demonstration of why many people prefer the explicit python > approach. What if you want bad input to report an error? There is nothing stopping you from checking and doing that in perl either. > What if you want it to not be an error, but you want the default > value to be something other than nil? What if you start off wanting > it to be an error, but later decide it should give a default value? I don't see anything stopping you from doing this in perl (or anything else for that matter). > If you wrote this in perl using assignment, you'd have to write a > function and then track down all those assignments (have fun checking > every assignment in a large program) and replace them with a function > call. But you are ignoring the initial constraints :-). In this particular situation the arguments are passed to the script as key/value pairs. The conversion is done at the top of "main" and the dictionary is used throughout the rest of the program. > Learning a new language involves more than learning the syntax and libraries. > Consider python an opportunity to gain another perspective on the practice of > programming. No need to be condescending. I've got plenty of "practice" and experience programming as well as shipping large, complex, high quality products to customers. I didn't ask the question so you can start a pissing contest of credentials. > A two line loop is pretty easy. If you want to do this a lot then yes, you > should define a function, in which case 'd = dictconv(a)' is the same number > of lines than '%d = @a;'. If you want to quibble, then yes, it's 7 characters > longer, but consider that you don't have to type '%@;' which reduces the > difference to 4 characters. I was looking for the perl conversion because it was easier to type, and I didn't have to carry around an extra conversion function (either in an external file or by cutting and pasting into otherwise single, one file, portable scripts). That's why a language intrinsic was desired. Since there isn't one, the two line loop will have to suffice. From phr-n2001d at nightsong.com Sun Oct 14 16:34:26 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 14 Oct 2001 13:34:26 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: <7xu1x22c6l.fsf@ruckus.brouhaha.com> "Tim Peters" writes: > Everything's cool if parens are required around a conditional expression, > though, in which case: > > x = if e1 then e2 else e3 + 1 # SyntaxError > x = (if e1 then e2 else e3) + 1 # cool > x = (if e1 then e2 else e3 + 1) # cool > x = if e1 then e2 else e3 # SyntaxError > x = (if e1 then e2 else e3) # cool > x = if if e1 then e2 else e3 then e4 else e5 # SyntaxError > x = (if (if e1 then e2 else e3) then e4 else e5) # cool > > Seems a mixed bag, but I'm more interested in readability and the > functionality than in minimizing keystrokes; requiring parens doesn't hurt > the goals I care about. It's more readable with the parentheses anyway. From ballabio at mac.com Thu Oct 18 11:19:36 2001 From: ballabio at mac.com (Luigi Ballabio) Date: Thu, 18 Oct 2001 16:19:36 +0100 Subject: self naming class? In-Reply-To: <20011018220520.A2264@typhoon.sdsu.edu> Message-ID: <5.1.0.14.0.20011018154452.00a6c920@mail.mac.com> At 10:05 PM 10/18/01 +1000, Serge Rey wrote: >i'm trying to create a class that assigns a name attribute in such a way >that the name is set equal to the name of the instance. for example: > >test = MyClass() > >so that test.name == "test" Serge, sorry I'm not here with an answer to your question. I see a phylosophical problem with the above, which is, "test" is not the name of your instance but rather the name of a reference to such instance. What I mean is, assume that you find out how to make it work: you will have the problem that if you write >>> test = MyClass() >>> test2 = test test and test2 are two references that point to the same instance, and you're in big trouble _defining_ what test.name is in this case. It would seem reasonable to expect >>> print test.name 'test' >>> print test2.name 'test2' but this is not possible as they point to the same object, and test.name will at all times be the same as test2.name. This is also true for ids: id(test) is equal to id(test2), so that I don't think one has a way to distinguish the two instances.... Sorry for increasing your problems rather than decreasing them, Luigi From rwp at nyc.rr.com Thu Oct 25 10:55:41 2001 From: rwp at nyc.rr.com (Robert Place) Date: Thu, 25 Oct 2001 14:55:41 GMT Subject: Distutils bug Message-ID: It would appear as if the rpath option for distutils does not work for platforms requiring -rpath instead of -R, i.e. IRIX, Linux, FreeBSD. I noticed some discussion about this back in March of 2000 but I have been unable to find any updates and the most recent versions of distutils I have found here: http://starship.python.net/~gward/python/distutils.html do not appear to have the update needed to make this work. It comes down to runtime_library_dir_option() in Lib/distutils/unixccompiler.py blindly returning -R instead of checking the architecture you're working on and returning the proper rpath option. As of 2.2a4 this still appears to be broken. Are there any plans to fix this? Is there another place I can look for distutils updates? Is there another way around this? Thanks -- Rob From s713221 at student.gu.edu.au Sat Oct 13 22:11:09 2001 From: s713221 at student.gu.edu.au (Joal Heagney) Date: Sun, 14 Oct 2001 12:11:09 +1000 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: Message-ID: <3BC8F43D.7D623F1D@student.gu.edu.au> Tim Peters wrote: > If people sign off on taking "then" as a new keyword, I think the chances > are good that we could get > > x = if e1 then e2 else e3 > > into 2.2b1. That's the only obvious spelling, hence the only truly Pythonic > way to spell it. Other languages spelling it that way range from Algol-60 > (Guido's first intense language affair) to Haskell. > less-thinking-will-get-there-faster-ly y'rs - tim Well I just did another grep -r "then" *.py on /usr/lib/python2.1, and I couldn't find any use of "then" outside of comments. -- Joal Heagney is: _____ _____ /\ _ __ __ _ | | _ ___ | /__\|\ || ||__ |\ || |___|/_\|___] | / \ \_||__ ||___| \_|! | | \ \ ! From ykingma at accessforall.nl Tue Oct 9 15:48:38 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Tue, 09 Oct 2001 20:48:38 +0100 Subject: ARGV and import ? References: <660c52de.0110090907.4017f907@posting.google.com> Message-ID: <3BC3548A.6E847FE9@accessforall.nl> Steve Holden wrote: > > "J" wrote ... > > Hi all, > > > > This is my first post to this group & I am also fairly new to python, > > so please forgive me if this isn't the brightest question or the > > appropriate venue. > > > > I would like to do the following: > > import a module based on what is typed on the command line. > > > > I thought this would work: > > import sys > > recipes = sys.argv[1] > > import recipes > > > > But, I get this error: > > >> ImportError: No module named recipes > > > > Is there any way to pass the module name to import through an argv? > > [snip] > > Try > > __import__(sys.argv[1]) > > but also be aware that's a potentially dangerous program in someone else's > hands ... they can import any module they like, and the module is EXECUTED > the first time it's imported. One can do: recipes = __import__(sys.argv[1]) to have recipes refer to a module. Have fun, Ype -- email at xs4all.nl From tjreedy at home.com Wed Oct 17 13:13:59 2001 From: tjreedy at home.com (Terry Reedy) Date: Wed, 17 Oct 2001 17:13:59 GMT Subject: Conditional Expressions don't solve the problem References: <7xr8s2zo57.fsf@ruckus.brouhaha.com> Message-ID: "Christopher A. Craig" wrote in message news:mailman.1003321457.28474.python-list at python.org... > Paul Rubin writes: > > > Having to split it into several statements clutters up the code and > > makes the readability WORSE by moving the test condition away from the > > 'while' keyword. Do you REALLY find > > > > while (line := file.readline()) != 'end': > > process_line(line) > > > > to be less readable than > > > > while 1: > > line = file.readline > > if line == 'end': break > > process_line (line) > > No, but I find both much less readable than > > # Python 2.2+ > for line in file: > if line=='end': break > process_line(line) One can even wrap such proprietary, special-purpose end-of-sequence conditions in an iterable class instance. The following seems to me to be conceptually even cleaner and even easier to read: for line in filechunk(file, 'end'): process(line) Terry J. Reedy From rune at nesheim.net Sun Oct 28 17:43:06 2001 From: rune at nesheim.net (Rune Nesheim) Date: 28 Oct 2001 14:43:06 -0800 Subject: Tcl/Tk & Python References: Message-ID: <59333ea6.0110281443.11f003f4@posting.google.com> "Roman Yakovenko" wrote in message news:... > Hi. Where can I get a help ( I mean files or other material ) on Tkinter > as python module. > > Thank you. Try http://www.python.org/topics/tkinter/ From Michael at RCP.co.uk Mon Oct 15 02:34:54 2001 From: Michael at RCP.co.uk (Michael Abbott) Date: Mon, 15 Oct 2001 07:34:54 +0100 Subject: Loop-and-a-half (Re: Curious assignment behaviour) Message-ID: <217F6DFA440ED111ACDA00A0C906B00601AAE75D@arsenic.rcp.co.uk> Michael, > I submitted a proposed PEP not long ago, and got a lot of comments. > Unfortunately, I didn't see any consensus begin to emerge, at least not > one that I could recognize. So I decided I should put it away for a > month or so, then come back with a fresh mind to create the version I > actually submitted. It's my theory (untested, of course) that this will > result in a better initial PEP and thus a better chance of acceptance. My though on your pre PEP was that it was a discussion document, and not really a Python extension proposal. There still seems to be a bit of argument about the syntax, I can't quite remember where we got to. I think we ended with allowing if e1: e2 else: e3 to be an expression (I'd prefer to grab 'then' as a keywork, and write if e1 then e2 else e3 but the penalty of a keywork is a relatively high hurdle). Why not reopen the discussion (need a new thread for this!), choose one syntax only, and write a very short PEP which simply proposes that syntax. I've forgotten what the options were; I suppose one way to repoen things would be to re-post your pre PEP. Regards, Michael From tim.one at home.com Wed Oct 31 00:41:33 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 31 Oct 2001 00:41:33 -0500 Subject: Proposed mmap module modifications In-Reply-To: <3BDF1D84.628B58E8@stsci.edu> Message-ID: [Jay T Miller] > I am proposing a set of modifications to the mmap module ... Cool. mmap could sure benefit from some loving attention. So long as you don't change the meaning of existing code, there's no need for a PEP here, unless you want a document to focus discussion. Else backward-compatible improvements to the libraries can be handled via patches (which need to include code, doc and test suite changes). anticipatorily y'rs - tim From jwilhelm at outsourcefinancial.com Mon Oct 29 13:30:08 2001 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: Mon, 29 Oct 2001 11:30:08 -0700 Subject: win32clipboard for python 2.2.1? In-Reply-To: <20011029182627.53586.qmail@web21108.mail.yahoo.com> Message-ID: <003701c160a7$bd3b9c90$a905a8c0@JWILHELM> > Hello, > > I'm trying to track down win32clipboard for Python > 2.1.1. I have the version of Python from > www.python.org, I assume that's the "CNRL" version? I > have tracked win32clipboard to the win32all package by > Mark Hammond; who directs traffic to ActiveState.com. > > Phew. It looks like the latest release of win32all > for CNRL is for Python 1.5.2 or 1.6... > > ...does anyone know if win32clipboard is available for > Python 2.1.1? > Actually, if you check closely, there is a release of win32all for Python 2.1 I'm quite sure of this, because I just got it myself about an hour ago, and I'm loving it already. :) Enjoy! --Joseph Wilhelm From kosh at aesaeion.com Tue Oct 9 21:11:36 2001 From: kosh at aesaeion.com (kosh at aesaeion.com) Date: Tue, 9 Oct 2001 19:11:36 -0600 (MDT) Subject: Python & Zope In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20EBACBEB@mbtlipnt02.btlabs.bt.co.uk> Message-ID: Designing the webpages of tomorrow http://webme-eng.com Designing the MMORPGS of tomorrow http://worldforge.org On Tue, 9 Oct 2001 jonathan.2.wilkinson at bt.com wrote: > Anyone, > > I'm trying to do this incredibly simple python script in zope: - > > myfile = open('myfile', 'w') > myfile.write('hello\n') > myfile.close() What you have here is a security problem which zope will not allow directly. Inside zope python scripts run in a restricted execution environment which forbids many commands. If you want to do this it needs to be done in an external method. Zope tends to be extremely secure through a combination of fell though out access features and not allowing this kind of code to be written inside zope. Think of it this way since code like that is forbidden in zope if someone cracks into your zope instance they can't then use that access to zope to crack through to the filesystem since you can't access the filesystem from inside zope. If you want to access the filesystem you need a python product or a external method both of which reside on the filesystem already and it is up to you to secure the holes you punch in the system like that. However zope will also help with that in that is provides a very nice security framework as discussed in the zope developers guide on the zope homepage in the documentation section. Zope first tries to protect itself from breakins and it does that through the access lists so that even getting one part does not get you everythying. If that is compromised zope then tries to protect the host computer so that even if zope should get cracked they are locked into an environment where they can't get to the host os which I feel is very important. At least in that case all I would have to deal with the problem is copy over a backup up Data.fs file and restart zope and the problem would be fixed. > > It works from a python interpreter fine......but when I try to test it I get > > > Error Type: NameError > Error Value: global name 'open' is not defined > Any ideas how to read/write a text file in zope using python?????Can it be > done? > Any other methods of writing and reading randomly (well structured sort of > way, but from anywhere within the file) in zope?? > > Please help, > Regards, > Jono > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From emile at fenx.com Tue Oct 23 23:46:24 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 23 Oct 2001 20:46:24 -0700 Subject: smtplib.SMTPDataError: (503, 'Error: need RCPT command') References: <3BD4F3E8.1E4B826B@cs.utwente.nl> <9r3nqd$r34a5$1@ID-11957.news.dfncis.de> Message-ID: <9r5drc$qvltn$1@ID-11957.news.dfncis.de> Yes. thanks for the pointer. I thought rfc821 would give a good perspective on the OPs question of what RCPT means, and to quote from http://www.faqs.org/rfcs/rfc2821.html , even though it obsoletes 821, it seems that : This document is a self-contained specification of the basic protocol for the Internet electronic mail transport. It consolidates, updates and clarifies, but doesn't add new or change existing functionality of the following: - the original SMTP (Simple Mail Transfer Protocol) specification of RFC 821 [30], Which begs the question: Does anyone know where there might be a source that shows the current status or otherwise forward points on older rfc's to the rfc's that obsolete them? Emile van Sebille emile at fenx.com --------- ----- Original Message ----- From: "Barry A. Warsaw" Newsgroups: comp.lang.python Sent: Tuesday, October 23, 2001 8:01 PM Subject: Re: smtplib.SMTPDataError: (503, 'Error: need RCPT command') > > >>>>> "EvS" == Emile van Sebille writes: > > EvS> Start with http://www.ietf.org/rfc/rfc821.txt > > Better make that RFC 2821! And note that RFC 2822 is also the latest > revision of that seminal standard. > > http://www.faqs.org/rfcs/rfc2821.html > http://www.faqs.org/rfcs/rfc2822.html > > -Barry From mjais at web.de Tue Oct 9 10:30:26 2001 From: mjais at web.de (Markus Jais) Date: Tue, 09 Oct 2001 16:30:26 +0200 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> Message-ID: In article , "Guido van Rossum" wrote: > Marcin, I don't understand why you care so much about being able to > write 3.foo. It's painful to fix in the lexer, and probably leads to > less useful error messages if someone makes a mistake in a float literal > (e.g. "3.e 0"). And I see zero use for it: in practice, you will never > ask for 3.foo -- you'll ask for x.foo where x happens to contain the > value 3. > > --Guido van Rossum (home page: http://www.python.org/~guido/) hi, I haven't followed the discussion but to write 3.foo is something I would like to have in Python I am a big fan of Ruby and there you can write for example -4.abs which gives 4 (of course) this is due to the fact, that in Ruby everything! is an object It would be great, if this would be possible in Python too on the other side, I understand that this would be a huge impact on the language. maybe this is something for Python 3000 ?!?! regards markus p.s. I do not want to start an unproductive flame war Ruby vs. Python (I like both !!) From daves_spam_dodging_account at yahoo.com Fri Oct 19 15:21:58 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Fri, 19 Oct 2001 12:21:58 -0700 (PDT) Subject: Reverse argument order Message-ID: <20011019192158.52354.qmail@web21106.mail.yahoo.com> Hello, I am writing an app that will (hopefully) expose Python as a scripting/macro language to users, some of whom know little or nothing about programming. A previous version of our software had a script parser that would handle times like so: until 5 ; wait 5 seconds until 1:05 ; wait 65 seconds until 1:02:05 ; wait 1 hour, 2 minutes, 5 seconds etc. The thing to note is that it's sort of a positional notation that is backwards from most programming languages. In Python, we're going to force the users to put the hours, minutes and seconds as separate arguments, but we'd like to allow them to omit the higher-order arguments and have them default to zero. Is it possible to do something like this in Python, to reverse the argument order? I came up with the following, but I wonder if I'm going about it the hard way. def SetTime( *args ): h = 0 m = 0 s = 0 if len(args) == 3: h = args[0] m = args[1] s = args[2] elif len(args) == 2: m = args[0] s = args[1] else: s = args[0] # set the time As I write this, another option presents itself, which isn't *quite* so bad: def _SetTimeReverse( s, m=0, h=0 ): # set the time def SetTime( *args ): b = list(args) b.reverse() _SetTimeReverse(*b) ...but it's still kind of hacky. Is there a better way? Thank you, -dB -- David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From mertz at gnosis.cx Wed Oct 10 11:54:40 2001 From: mertz at gnosis.cx (Dr. David Mertz) Date: Wed, 10 Oct 2001 11:54:40 -0400 Subject: Python, XML, and databases (fwd) Message-ID: adina_levin at mindspring.com wrote: |Is there a Python tool to exchange data between a relational database and |XML? I happen to have written a couple articles on this topic, with accompanying sample utilities (pretty usable as-is, but mostly intended as inspirations for "how to do it"). The articles are at: http://www.gnosis.cx/publish/programming/xml_matters_9.html and: http://www.gnosis.cx/publish/programming/xml_matters_12.html If you want to jump straight to the source code, those are: http://gnosis.cx/download/dtd2sql.py http://gnosis.cx/download/xml2sql.py http://gnosis.cx/download/sql2dtd.py Good luck. From pzw1 Wed Oct 31 14:12:55 2001 From: pzw1 (Peter Wang) Date: Wed, 31 Oct 2001 14:12:55 -0500 Subject: python development practices? References: <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> <7xzo68s63o.fsf@ruckus.brouhaha.com> Message-ID: hi chris, i think you are confusing/interlacing my posts with Paul's. :-) i was not concerned with data hiding in the form of restricted execution or the java sandbox. in my use of the term "rogue programmer", i mean someone who displays a lack of judgement when coding and interfacing with other people's code. it's primarily *not* malicious; most of the time it's because (1) he doesn't know any better, or (2) he's under extreme pressure to push out a feature and compromises on process as a result. in both of these cases, i wanted to know what sorts of language mechanisms have been found to be useful in protecting the code base and application from non-immediately-revealed bugs. the overwhelming response that i've gotten is that there is nothing in the language, and no one has really devised any, and it is up to good process and thorough unit tests. which is fine, and is pretty much what i had figured. i just didn't want to struggle with it for a while only to find that there's a nifty "develframework.py" module with a framework for team python development. :-) -peter On Wed, 31 Oct 2001 17:35:17 GMT, "Chris Tavares" wrote: >"Paul Rubin" wrote in message >news:7xzo68s63o.fsf at ruckus.brouhaha.com... >> Peter Wang writes: >> > i don't think data hiding's purpose is to keep rogue programmers in >> > line. it's partly to insulate imperfect development practice (e.g. >> > sloppy documentation) and partly to define an interface for a class. >> >> Keeping rogue programmers in line is a perfectly legitimate use of >> data hiding. For example, look at java applets on web pages. These >> have to run in the same JVM as parts of the browser, and yet the >> applets can be hostile. So the language has to protect the browser >> internals from the loaded applets. Another example is security >> interfaces where the class instances contain authentication >> credentials and the application should be able to use them but not >> copy them. >> >> Python provides a restricted execution hack (rexec/bastion) to deal >> with the applet situation, but it's a pain for the second situation >> because you have to wrap the caller in the rexec shell, rather than >> wrapping the secure object in a security shell and leaving the caller >> unrestricted. >> >> The best way I've managed to deal with this is to put the secure >> objects in a totally separate process and access them by RPC. >> That, too, is a kludge, though. > >At the start of this thread, your post implied that 'data hiding' meant >something similar to C++ or Java's access specifiers: private, public, etc. >But the stuff you mention above has nothing to do with that! The applet >sandbox is a specific mode provided by the runtime - and rexec/bastion is >NOT a hack, it's just another way to implement a sandbox. > >As far as security - well, I don't know how stuff like that is supposed to >work, but in my experience that's an OS issue rather than a language issue. >Python compiles and runs on almost every platform under the sun, and lots of >them don't have ANY kind of security, so what should it do? Implement some >gigantic code-access security features that most people don't need? > >And in any event, C++ access specifiers don't do much but provide a >challenge to those "rogue programmers" you mentioned, and they don't help at >all in any of the above situations. So I'm curious what you really mean, and >what you really want. > >-Chris > > From piet at cs.uu.nl Wed Oct 17 11:04:59 2001 From: piet at cs.uu.nl (piet at cs.uu.nl) Date: 17 Oct 2001 17:04:59 +0200 Subject: Desperate help required for Python assignment References: <602c058e.0110162347.268591ce@posting.google.com> Message-ID: >>>>> nachiket_gole at hotmail.com (Nachiket) (N) writes: N> I am new to Python doing a crash course in University. I have a N> assignment to submit in two days the specifications of which are: You should complain to the teacher that you got only 2 days for this assignment :=) -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From db3l at fitlinxx.com Fri Oct 12 20:00:07 2001 From: db3l at fitlinxx.com (David Bolen) Date: 12 Oct 2001 20:00:07 -0400 Subject: dictionary.update() enhancement? References: <3BC64CC4.444A77E7@alcyone.com> Message-ID: maj64 at hotmail.com (Mark J) writes: > The above code merely preserves the semantics of the existing update > function since that's the fairest test until dictionary.update() is > changed. (Note: removing the conditional in withloop() still keeps > it about 10x slower.) But it's not the fairest test for prototyping the overhead - having just the call to update never uses any callback to Python functions as the proposed change would. Thus, you stay entirely within the internal C code for the update operation. That's a major difference from the proposed change. > Of course, the performance difference will decrease as the complexity > of the collision function increases, but many useful collision > functions are about as simple as or even simpler than the one > currently used by dictionary.update(). Except that they won't be written in C. The overhead of getting out to a Python callback function within the update processing will probably be the major factor, as much as whatever that collision function does. > By claiming only 10x faster in my last message, I was trying to > (reasonably and fairly?) account for the extra overhead of running the > collision function within update(). > > Please correct me if I'm missing something. I'd also be interesting > in hearing any big discrepancies on the performance factor on > different platforms. I think you're severely underestimating the overhead of calling back out to Python processing code for the comparison function, and your test case doesn't even try to simulate any overhead for that. Sure, a Python loop against complete C code is a big difference, but adding a Python callback changes that a lot since now you have significant Python code internal to the process in both cases, but in the callback you're invoking a function each time. While not precisely apples to apples, I think this is a reasonable point of comparison. In one case I sort a list just using the normal internal sort comparison. In the second and third cases I use a callback function. The first callback just calls the same internal function that would be used anyway (but thus calls into the interpreter C code again within the callback) - the second keeps it in pure Python code, about as close to a minimum implementation as it can. Because the list is already sorted, there are 9999 callbacks to the comparison routine, or just about the same as one callback per entry as with a dictionary update. import time list = range(10000) def mycmp(x,y): return cmp(x,y) def mycmp2(x,y): return (x-y) start = time.clock() for i in range(100): list.sort() finish = time.clock() print (finish-start)/100.0 start = time.clock() for i in range(100): list.sort(mycmp) finish = time.clock() print (finish-start)/100.0 start = time.clock() for i in range(100): list.sort(mycmp2) finish = time.clock() print (finish-start)/100.0 On my machine, here's what I got: No cmp 0.00144961120768 mycmp 0.0589527414929 mycmp2 0.0315124934838 So you can see, that even in the simplest callback case, there's a factor of about 22x between not having a Python code callback, and having one. Stretching a bit and extrapolating to your test (showing 23.9x faster for a straight update versus a loop), that would seem to imply good odds that having a callback in the update might be darn close in performance to the explicitly written loop. In any event, I wouldn't think it high odds that you'll actually see it 10x faster with the callback. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From ykingma at accessforall.nl Tue Oct 30 05:02:17 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Tue, 30 Oct 2001 11:02:17 +0100 Subject: How smart are Semaphore Objects? References: <32cedc66.0110292253.5eaaca31@posting.google.com> Message-ID: <3BDE7AA4.2250BFF5@accessforall.nl> Matthew, you wrote: > > I firmly believe that when coding a function, object, program or > whatever, one should assume that every other function, ... is either > stupid or out to get you. With this mind-set, I'm curious as to how > (idiot or mean-person) proof semaphore objects are. > > Threading.Semaphore. > > If a class can't acquire a semaphore, or doesn't bother, can it > release it, despite not owning it? A Semaphore can be released from an other thread. > > It's almost a security thing. I want in, and so, I will release the > semaphore, repeatedly if necessary, until I get in. > > Is the semaphore able to avoid this kind of thing? Or do you just > have to rely on the fact that people generally don't try to release a > semaphore that they haven't acquired? > You might prefer to use RLock. Releasing it is documented ao. by: "Only call this method when the calling thread owns the lock. Do not call this method when the lock is unlocked." It can be better for performance to release a Semaphore from another thread. I would consider this as a candidate for style improvement, though. > This may seem a bit paranoid, but in big groups, paranoid is so > important. My code may be a bit large, but it's never the part that > crashes because of a divide by 0 or a file didn't open because it > never existed. Nod. > Maybe there is an exception the Semaphore raises? I don't know. > When you are paranoid enough test RLock. You'll like it. > Thanks for helping. I really appreciate the time and effort. My pleasure, Ype -- email at xs4all.nl From ssartor at bellatlantic.net Wed Oct 3 15:21:10 2001 From: ssartor at bellatlantic.net (Steven Sartorius) Date: Wed, 03 Oct 2001 19:21:10 GMT Subject: Possible to read/write Excel files in Python? References: Message-ID: in article mailman.1002132904.15858.python-list at python.org, Cliff Wells at logiplexsoftware at earthlink.net wrote on 10/3/01 14:09: > On Wednesday 03 October 2001 10:39, Steven Sartorius wrote: >> I'm running 2.1.1 on an i386 NetBSD box and the application I'm working on >> needs to grab some data from an Excel spreadsheet. I've found a couple of >> apps (xlHTML for example) that will take a spreadsheet and turn it into >> html/text and I've seen an article on IBM's web site talking about how to >> read/write Excel with perl. Is there anything out there that will let me > > Is the perl application they're running a Windows perl application? If so > they're probably just setting it up as an ODBC source. I would be curious if > that app would really work on non-MS platforms... The article talks about generic perl modules that work under both Windows and Linux. Take a look here: http://www-106.ibm.com/developerworks/linux/library/l-pexcel/ Steve From cgaston at moonqzie.com Tue Oct 2 09:54:41 2001 From: cgaston at moonqzie.com (Carlos Gaston Alvarez) Date: Tue, 2 Oct 2001 15:54:41 +0200 Subject: trying sockets Message-ID: <005f01c14b49$c95cea10$a500a8c0@moonqzie> There are http specific classes. Why dont you use them? Chau, Gaston ----- Original Message ----- From: "Uwe Schmitt" Newsgroups: comp.lang.python To: Sent: Tuesday, October 02, 2001 3:07 PM Subject: trying sockets > Hi, > > i'm just playing with the socket module: i'd like to send > a "GET/HTTP" request to a webserver and record the answer > of the server. so i wrote > > from socket import * > > snd=socket(AF_INET,SOCK_STREAM) > snd.connect(("www.num.uni-sb.de",80)) > print snd.getsockname() > > lstn=socket(AF_INET,SOCK_STREAM) > lstn.bind(snd.getsockname()) > > snd.send("GET / HTTP/1.0 ") > lsten.listen(1) > conn,addr=lstn.accept() > print conn.recv(1024) > > lstn.close() > snd.close() > > but i get the following output: > > ('134.96.31.42', 1662) > Traceback (most recent call last): > File "client.py", line 8, in ? > lsten.bind(snd.getsockname()) > socket.error: (98, 'Address already in use') > > so: what did i do wrong ??? > > yours, uwe. > > > > -- > Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes > phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 > D-66041 Saarbr?cken > http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 > > -- > http://mail.python.org/mailman/listinfo/python-list > From breakfast at 10.am Tue Oct 16 05:53:51 2001 From: breakfast at 10.am (mallum) Date: Tue, 16 Oct 2001 10:53:51 +0100 Subject: feeding SAX Message-ID: <20011016105351.A774@10.am> hi all; Expat allows me to incrementally parse an XML document by 'feeding' it the document in chunks rather than in one whole go. Is this possible with SAX ? or do you have to give its parse function the entire document ? -- Matthew Allum From sholden at holdenweb.com Mon Oct 1 11:46:41 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 1 Oct 2001 11:46:41 -0400 Subject: newbie question: help with polymorphism and/or programming style References: <9p7o8l$4q5$1@slb2.atl.mindspring.net> Message-ID: wrote in message news:9p7o8l$4q5$1 at slb2.atl.mindspring.net... > Hello, Pythonites. > > I am teaching myself python programming, and have created a toy storefront > program. > > If the customer wants to pay with cash, the program should return change. If > the customer wants to pay using a credit card, the program should validate > the customer's ability to pay, and return an approval. > > Several questions regarding programming style: > > a) Is it desirable to replace the "if" statement in paymenthandler with > subclasses, PayCash(Payment) and PayCredit(Payment). If so, doesn't that > just push the "if" statement upstream, where you PayCash() if the customer > says she wants to pay cash? I am clearly missing something!! :-( > The customer shouldn't need to say whether she will pay cash! See remarks below... > b) Is it bad style to return different kinds of information, depending on > whether the customer pays with cash or credit? If so, how should this be > handled cleanly? > It is difficult to see how you are planning to use the return values without the calling code, so this is a tricky one. Generally speaking, however, yes, it's bad style to have to decode the return type of a function or method to decide what happened inside the function or method. Frankly I'm having difficulty deciding why payment *is* an object; more context would help. > c) Any other programming style problems? > > This is a toy, so no reason to comment on lack of full detail in the > simulation. Except that that context it would provide would enable fuller answers, but I doubt anyone will try to pick nits about that. We're here to help! > > class Payment: > def __init__(self): > self.payobject=Customer().getpaymentinput() > Will a newly-created Customer object do here, or do you later plan to repalce it with a customer object passed as an argument to __init__()? Or is Customer not a class at all? The context doesn't make it terribly clear. It seems that when you create a Payment, it creates (or locates) a Customer, and sets its own payobject to the result of the cutomer's getpaymentinput() method. Is this correct? > def payhandler(self,sum): > self.sum=sum > if self.payobject.paytype == "cash": > result=self.payobject.cashamount-self.sum > print result > Is there a particular reason why you print here but not for credit cutomers? > elif self.payobject.paytype == "credit": > self.crednum=self.payobject.crednum > result=Creditcheck().creditapprove(self) > > return result > > So you create a Payment, and then you call the Payemnt's payhandler() method with the amount of the payment? This seems a little odd, but perhaps makes sense in the larger scheme of the object model you have designed. The main problem is that your code doesn't use "polymorphism", one of the principal principles (;-) of object orientation. Because you don't give much detail about your approach, all I can do is suggest one possible alternative. I am sure that other readers will have other, equally valid, suggestions. You also violate encapsulation, the principle that you shouldn't have to look inside an object to use it, but we do that all the time in Python so I wouldn't worry too much about that. We aren't purists here... The idea behind polymorphism is that different types of object implement the same set of operations (methods), so that code which manipulates them doesn't need to distinguish among the various types of object it must deal with. You are using an attribute of payobject, which you obtained as the result of calling a customer method, to determine whether you should process a cash or a credit payment. Had you thought of having two different subclasses of Customer, call them CashCustomer and CreditCustomer? The Customer class would implement all methods common to both types. Both CashCustomer and CreditCustomer would inherit these common method from Customer, and each would provide an appropriate ProcessPayment(amount) method. E.g.: class Customer: pass # a simple implementation! class CashCustomer(Customer): ... def ProcessPament(self, amt): if self.cashonhand >= amt: self.cashonhand -= amt return amt else: raise CannotPay, "customer only has %f" % self.cashonhand class CreditCustomer(Customer): ... def ProcessPayment(self, amt): if self.CardIssuer.ValidatePayment(amt): self.CardIssuer.MakePayment(amt) return amt else: raise CannotPay, "card issuer will not allow payment of %f" % amt The advantage of such an approach is that anywhere in your code where you are dealing with a Customer (of either type) c, you can call c.ProcessPayment(x) to resuest a payment of amount x, and expect to raise an exception of the payment cannot go through for whatever reason. Hence my assertion that your code "shouldn't need to know the type of customer". If you're new to OO this may be confusing, and I emphasise it's only one of many possible approaches. I hope it helps you to realise that Python code can be extremely clean when you do things right. Exceptions can help simplify logivc when you want to concentrate primarily of the case where everything goes right, but nevertheless have to accept that sometimes things will go wrong. regards Steve -- http://www.holdenweb.com/ > > From tim.one at home.com Wed Oct 17 00:37:25 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 17 Oct 2001 00:37:25 -0400 Subject: profiler results for __getattr__, am I reading this correctly ? In-Reply-To: <20011016212304.A19672@glacier.arctrix.com> Message-ID: [Tim] > Try grabbing profile.py out of the current CVS tree (it should run fine > under 2.1.1 too, and under 2.0.1). There was a systematic bug ... [Neil Schemenauer] > I've ran into this problem just the other day and using profile.py out > of CVS fixed it for me. I believe it: this is yet another instance of the simultaneous worldwide discovery of a bug that always existed! Not just you, but also someone on SourceForge, and what got it bumped to the top of the list is that several coworkers in Zope Corp were being driven insane by it. Guido, Fred and I each spent (overall) most of a workday going over every line in profile.py with hyper-critical eyes, and we believe the bug is well and truly squashed. Plus, in 2.2, we no longer generate the screwy profiling events that were confusing it to begin with. > Hmm, 2.1.2? If volunteers materialize to produce another bugfix release, I'm sure we'll (PythonLabs) be happy to ship it (cut docs, installers, etc). It's curious that neither Aahz (2.0.1) nor Thomas Wouters (2.1.1) volunteered for a second round of this rewarding work . From calves at coelce.com.br Mon Oct 1 09:06:51 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Mon, 1 Oct 2001 10:06:51 -0300 Subject: FW: Help please!!!! Message-ID: <29A97D00F387D411AC7900902770E14801FF6698@lcoeexc01.coelce.net> And some can tell me how can I use tools on \Tools directory, specialy in Tools\compiler directory?! Carlos Alberto COELCE/DPRON-Departamento de Projetos e Obras Norte Fone: 677- 2228 e-mail: calves at coelce.com.br \|||/ (o o) --ooo0-(_)-0ooo-- -----Original Message----- From: A.A [mailto:andtherewaswater at yahoo.com] Sent: Saturday, September 29, 2001 11:24 AM To: python-list at python.org Subject: Re: Help please!!!! There's a program called 'freeze' to do that. But remember, if you compile on your windows machine, then that exe will work only on windows, etc. If you are using 'PYthon 2.1', and you have 'Python2.1 Tools' installed it should be there in the TOOLS directory whereever python2 is installed. A.A Doy wrote: > > HOW do i compile a python file to a .exe file... thanks for your help!!! -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From DeepBlue at DeepBlue.org Thu Oct 11 15:52:10 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Thu, 11 Oct 2001 14:52:10 -0500 Subject: CGI question on input type=text form elements References: Message-ID: "Ignacio Vazquez-Abrams" wrote in message news:mailman.1002823931.18186.python-list at python.org... > On Thu, 11 Oct 2001, DeepBlue wrote: > > > > > "Ignacio Vazquez-Abrams" wrote in message > > news:mailman.1002815363.21257.python-list at python.org... > > > On Thu, 11 Oct 2001, DeepBlue wrote: > > > > > > > I am running into a strange problem with a form while using CGI module > > in > > > > Python. > > > > Let us say I have the following form: > > > >
> > > > > > > > > > > >
> > > > > > > > Now, let us say that test_form=cgi.FieldStorage() > > > > If the above form is submitted without typing anything in the text field > > one > > > > expects test_form.keys() to generate: > > > > ['submit'] > > > > > > > > But i am getting: > > > > ['text_1', 'submit'] > > > > Which is unexpected, and in my case, undesirable. What am I doing > > wrong? > > > > > > You are assuming that the browser won't pass the contents of text_1 if it > > is > > > empty. Obviously this isn't true. You need to fine-tune your code to deal > > with > > > the case when it is empty. > > > > > This is only happening when the form is enclosed in a table. When the form > > is not, the keys do not include empty text input elements. > > Well then you have two options: > > 1) Let the Python script know when the form is in a table, or > > 2) Deal with cases when the field is present but empty > > Not only is option 2 probably easier, but it's also the "correct" thing to do, > because other browsers may behave in a different manner, returning the empty > field whether or not the input is in a table. > I know that 2 is much easier; and after what happened I am getting into the habit of checking on all keys and to check if they are empty: I only thought it was strange that the key of an empty element was included as a key when the form happens to be in a table. DB From drmiller at pldi.net Tue Oct 16 09:20:17 2001 From: drmiller at pldi.net (Donnie Miller) Date: 16 Oct 2001 08:20:17 -0500 Subject: Telnetlib - send BRK Message-ID: <1003238417.1195.20.camel@drmiller> Patrick, Thanks for the response. I was afraid the answer would be something like this. I tried sending chr(243), but had no luck. Thanks again, Donnie M. From grahamd at dscpl.com.au Mon Oct 15 21:33:36 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 15 Oct 2001 18:33:36 -0700 Subject: ANN: OSE 7.0b9 is now available. Message-ID: OSE 7.0b9 is now available. At its core, OSE is a C++ class library for general purpose programming, but also includes support for building event driven systems and distributed applications using a request/reply and publish/subscribe style service agent framework. The ability to interact with an application is facilitated using a HTTP servlet framework and RPC over HTTP interfaces. In short, OSE could be said to take technology from message oriented middleware, application server and web service technology and wraps it all into one. Although C++ at its core, OSE also provides wrappers for the Python programming language. This mix means that OSE serves as a useful platform for building standalone or distributed applications in Python, C++ or a mix of both. Its support of both XML-RPC and SOAP protocols through a single service interface makes it ideal for building web based services. Further information on OSE and the software itself, can be found at: http://ose.sourceforge.net This includes over 100 pages of documentation on the Python interfaces alone. The Python documentation can be viewed on the site as HTML, or as a single PDF file at: http://ose.sourceforge.net/python-manual.pdf OSE is released under the QPL. This release is the culmination of over 10 years of development, OSE first being available over the Internet in 1993. From cgale1 at _remove_home.com Tue Oct 16 19:59:20 2001 From: cgale1 at _remove_home.com (Van Gale) Date: Tue, 16 Oct 2001 23:59:20 GMT Subject: Extracting attachments with Python? References: <0B%x7.10230$YC3.3926894@typhoon.southeast.rr.com> Message-ID: Looks fine to me! From cdelarue at bigfoot.com Wed Oct 24 06:25:57 2001 From: cdelarue at bigfoot.com (Christophe Delarue) Date: 24 Oct 2001 03:25:57 -0700 Subject: odbc introspection Message-ID: <2c71728a.0110240225.1fedbe08@posting.google.com> I'am new as a child in windows. But I would like to query DB through the odbc interface from Sam's dynwin or the Hammon's win32 interface. We have got a SQLServer database on a server. I've created a ODBC link on my local PC. When I connect through Access to this DB I can see all the tables (there is a table named ``dbo_SITE'') and their column in a graphical way. If I connect to this DB trough python.odbc, I can only do SELECT requests. If I do SQL query like 'SELECT * FROM dbo_SITE', an error raise saying there is no table wich this name. This query work on through the access api. How could I have the list of tables names present on this connection ? Once I've got the table names I saw how to browse their columns. Right now I make an export in DB3 format, convert to gadfly ! (That is not a good solution to be on time) From smithrc at zdbaora.nat.bt.com Fri Oct 12 10:25:11 2001 From: smithrc at zdbaora.nat.bt.com (Robin Smith) Date: 12 Oct 2001 15:25:11 +0100 Subject: J2EE equivalent in Python References: Message-ID: Martin von Loewis writes: > Robin Smith writes: > > > I like J2EE but I am also an open source fan. > > What exactly is it that you like about J2EE? The way it hangs together. I like JSP, beans and tag libraries. Ideally I'm looking for tag libraries that run with python. Robin From john.thingstad at chello.no Thu Oct 18 10:02:23 2001 From: john.thingstad at chello.no (John Thingstad) Date: Thu, 18 Oct 2001 16:02:23 +0200 Subject: On morgage payments Message-ID: <20011018140925.AFL25693.mta01@mjolner> Isaw earlier a very inefficient way of calculating morgage on a loan. The recurence relation: P = amount i = interest d = downpayment P = i*P - d n n-1 was solver by itteration in a loop I would like to point out: P = i * (i*P - d) - d i+1 i P = i * ( i * (i * P - d) -d) -d) i + 2 i P = i*i*i*P -d(i^2 + i +1) i+2 i by inspecion i*i*i is a exponential and i^2 + i +1 is a geometric series so we have: P = i^n * P - d * (i^n -1 / i -1) n 0 Which can be computed once. From usenet at jeffjohnson.net Thu Oct 25 11:32:07 2001 From: usenet at jeffjohnson.net (Jeff Johnson) Date: 25 Oct 2001 08:32:07 -0700 Subject: urllib.urlopen + https = all threads locked? References: Message-ID: Thanks Gerhard! Here's a test script that shows the problem and output from the script. I open the same public link in both https and http. The ticker thread pauses during the https call. I'll test the patch out in a bit and let you know what I find. -Jeff ==== OUTPUT ==== time between ticks = 0.00 time between ticks = 0.41 time between ticks = 0.51 Opening HTTPS://www.digitalegroup.com/ea/ThreadTest3. Finished. time between ticks = 3.46 time between ticks = 0.50 Opening HTTP://www.digitalegroup.com/ea/ThreadTest3. time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 Finished. time between ticks = 0.51 time between ticks = 0.51 ==== SCRIPT ==== from threading import Thread import urllib, time def read(url): print "Opening %s." % url f = urllib.urlopen(url) print "Finished." def ticker(): t1 = time.time() while 1: t2 = time.time() print " time between ticks = %0.2f" % (t2 - t1) t1 = time.time() time.sleep(.5) t2 = Thread(target=ticker) t2.setDaemon(1) t2.start() time.sleep(1) read("HTTPS://www.digitalegroup.com/ea/ThreadTest3") time.sleep(1) read("HTTP://www.digitalegroup.com/ea/ThreadTest3") time.sleep(1) From mal at lemburg.com Mon Oct 22 15:29:31 2001 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon, 22 Oct 2001 21:29:31 +0200 Subject: PyArg_ParseTuple and Unicode References: Message-ID: <3BD4739B.9F2FE4F@lemburg.com> Scottie wrote: > > I am confused here, but this is not uncommon. I am trying to get an > extension to handle both normal strings and unicode. From my initial > reading of the PyArg_ParseTuple document, I thought the following > would work: > > if( PyArg_ParseTuple(arg, "...u#...", ...) ) { > ...Unicode ops... > } > else if( PyArg_ParseTuple(arg, "...s#...", ...) ) { > ...plain string ops... > } > > My understanding of "u" and "u#" was that they would fail on non- > unicode input (while "s" and "s#" pass both along). The behavior I > see is different: "u#" gives me a pointer to the base of a vanilla > string, but divides the length by two. "u#" behaves just like "s#" in this case: it uses the read buffer interface and assumes that the object in question returns native Unicode data through this interface. In your situation, it's better to use the "O" parser marker which returns the object and then switch on the object type using PyString_Check(obj) / PyUnicode_Check(obj). -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Consulting & Company: http://www.egenix.com/ Python Software: http://www.lemburg.com/python/ From psycho9909 at charter.net Wed Oct 3 20:18:06 2001 From: psycho9909 at charter.net (Loula) Date: Wed, 3 Oct 2001 19:18:06 -0500 Subject: Newbie question please answer if you have time Message-ID: I was just wondering if anyone could tell me of some games or other programs that were written in python? I'm new to this and I'm very curious about what python can do. Thanks From peter at engcorp.com Tue Oct 9 08:23:15 2001 From: peter at engcorp.com (Peter Hansen) Date: Tue, 09 Oct 2001 08:23:15 -0400 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> <3BC2BDC3.20A41F38@snakefarm.org> Message-ID: <3BC2EC33.EFEA6EFF@engcorp.com> piet at cs.uu.nl wrote: > > >>>>> Carsten Gaebler (CG) writes: > > CG> Thanks for all the answers. Seems as if I hadn't been specific > CG> enough about what I was looking for. It would be nice if there was > CG> some builtin dictionary magic that would allow > > CG> "%(foo) %(bar)" % magic(dict1, dict2, ...) > > CG> where in case of duplicate keys the leftmost dictionary would be > CG> preferred. > > CG> Perhaps the builtin dictionary() class could be extended so that > CG> it accepts more than one dictionary argument? > > My solution gave you that. Except for the part about "builtin". But for that the answer to Carsten is that Python has a professed tendency to avoid growing the core in little magic ways like this where so many simple alternatives exist and writing the magic behaviour yourself, as Piet did, is so easy. (I say only "professed" because lately some have wondered whether some of the recent additions might not violate that principle. But leave it to the core developers' better judgement whether this particular case of "magic" actually represents something elegant and logical which should be added, or special-case and unnecessary which will be left out.) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From quinn at yak.ugcs.caltech.edu Mon Oct 15 10:01:44 2001 From: quinn at yak.ugcs.caltech.edu (Quinn Dunkan) Date: 15 Oct 2001 09:01:44 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 15) Message-ID: <1EA9D59A02C6D660.642E9F4639E57DBB.F10C72E7B929E71F@lp.airnews.net> The International Python Conference is coming up again: http://www.python10.org/ Progress on a faster python compiler continues. It's not ready, and probably won't be for a while, but it's interesting to read about: http://groups.google.com/groups?threadm=3bc4d2e4%240%2436473%24ba620e4c%40news.skynet.be SOAP, XML-RPC, or just drop a pickle on the wire? Don't discount a simple pickle: http://groups.google.com/groups?threadm=uy9mluant.fsf%40ctwd0143.fitlinxx.com Software Announcements: pSQL.py translates python syntax into SQL, so talking to an SQL database looks more like normal python attribute access: http://groups.google.com/groups?threadm=mailman.1002903093.15232.clpa-moderators%40python.org Here's a command line filter for processing MIME messages: http://groups.google.com/groups?threadm=mailman.1002897132.26404.python-list%40python.org ======================================================================== Everything 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 daily python url http://www.pythonware.com/daily comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect 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/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.de/oo_python.html Python FAQTS http://python.faqts.com/ 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://python.sourceforge.net/peps/pep-0042.html Python Journal is at work on its second issue http://www.pythonjournal.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python 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/topics/pythonurl/ 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 Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning, ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From paul at ActiveState.com Mon Oct 1 13:00:32 2001 From: paul at ActiveState.com (Paul Prescod) Date: Mon, 01 Oct 2001 10:00:32 -0700 Subject: Python in The Economist's "Technology Quarterly", September 22 References: <9p2nda$hr8$1@lancelot.camelot> Message-ID: <3BB8A130.A391200D@ActiveState.com> Alex Martelli wrote: > > A bit tangentially, but... if you subscribe to their online edition you can > read the story at: > http://www.economist.com/displayStory.cfm?Story_ID=S%26%28%280%25QQ%2F%2A%0A > In the print edition, it's page 14 of "Technology Quarterly" in the middle > of the September 22 printed Economist. "A lingua franca for the Internet" > is the title, and the article purports to be mostly about the clash between > Java and C#, but... The article has been opened up for free consumption. http://www.economist.com/science/displayStory.cfm?Story_ID=779459 It isn't a great article but it is nice to see Python mentioned. It indicates we are moving into the list of mainstream languages. Most programmers should by now know ABOUT Python even if they don't know Python. That's a big change from even two years ago. Paul Prescod From wtanksle at dolphin.openprojects.net Thu Oct 11 17:14:35 2001 From: wtanksle at dolphin.openprojects.net (William Tanksley) Date: Thu, 11 Oct 2001 21:14:35 GMT Subject: a pure python mp3 player? References: <9q50uh$qlj$1@uranium.btinternet.com> Message-ID: On Thu, 11 Oct 2001 21:56:16 +0100, G. Willoughby wrote: >Hi, > do you know of any mp3 players that have been exclusively written in >python, and not just a gui for the C coded 'mp123'? Hope you're kidding. Not only is MP3 playing *very* mathematically complex, but it requires heavy access to audio playing, which is rather difficult. I suppose a NumPy-based MP3 decoder would be possible, but after that we'd want to pipe the output to something like a WAV player, not play it ourself. >G. WIlloughby -- -William "Billy" Tanksley From paul at boddie.net Tue Oct 9 03:40:01 2001 From: paul at boddie.net (Paul Boddie) Date: 9 Oct 2001 00:40:01 -0700 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> Message-ID: <23891c90.0110082340.541e6993@posting.google.com> Paul Rubin wrote in message news:<7xwv25zftv.fsf at ruckus.brouhaha.com>... > Joshua Macy writes: > > From where I sit this looks like (possibly > > unintentional) anti-Python FUD--"ooh, better not use Python...don't > > know if its libraries are properly licensed...beware! beware!" > > I don't think anything in the standard Python library is GPL'd. > (GPL-compatible yes, GPL'd no). Since the Python allows usage in > closed-source programs, the GPL issues don't apply. However, the > discussion seemed to pertain to independently distributed add-on > libraries, not just the standard library included with Python. I would seriously doubt that any of the libraries distributed with Python are GPL licenced. Indeed, options such as the readline module remain just that: optional. So, there seems to have been an explicit policy of avoiding "GPL by stealth". However, there are a number of useful packages which have GPL licences. I was asked to update the Python Web modules page which I maintain some time ago with licence information, purely so that people could see which modules/frameworks weren't worth evaluating because of the licence, and there are a lot of them with GPL licences - it's quite surprising. > If I submitted a patch to the standard Python library, I'd expect the > patch to be distributed under the same Python license that the library > is distributed in, i.e. closed-source usage would be ok. I might be > less motivated in the first place to contribute substantial patches > than if Python were GPL'd, since I'd in effect be working for > closed-source vendors without getting paid, but that's a totally > separate issue. I don't want to start a mindless debate about the benefits or evils of GPL licensing, but usage of the GPL and any resulting success of a particular project is probably quite dependent on the scale or adoption of that project, along with how unique or interesting it is. In many cases, based on observation of people's behaviour or attitude alone, it seems that putting a GPL licence on a project at an early stage is like putting a "do not touch" sign on it. Paul From serge at rohan.sdsu.edu Thu Oct 18 18:09:29 2001 From: serge at rohan.sdsu.edu (Serge Rey) Date: Fri, 19 Oct 2001 08:09:29 +1000 Subject: self naming class? In-Reply-To: <3BCF0FD3.16C62896@home.net>; from chrishbarker@home.net on Thu, Oct 18, 2001 at 10:22:27AM -0700 References: <3BCF0FD3.16C62896@home.net> Message-ID: <20011019080929.D349@typhoon.sdsu.edu> On Thu, Oct 18, 2001 at 10:22:27AM -0700, Chris Barker wrote: > Luigi Ballabio wrote: > > At 10:05 PM 10/18/01 +1000, Serge Rey wrote: > > >i'm trying to create a class that assigns a name attribute in such a way > > >that the name is set equal to the name of the instance. for example: > > > > > >test = MyClass() > > > > > >so that test.name == "test" > > I see a phylosophical problem with the above, which is, "test" is not the > > name of your instance but rather the name of a reference to such instance. > > Luigi is right, and while I'm sure that someone on this group could find > a way to do it, you probably don't want to. What you need to do is step > back and ask yourself why you want to so this at all. In general, having > a link between the data and actual variable names can make it a little > easier to think about the code, but takes away a lot of flexibility, and > is ripe for the kind of problems that Luigi has pointed out, > particularly in Python. > thanks to you and luigi for pointing out the problems with what i was trying to do. learning of the problem with this is more important to me than getting a "fix". > When I want a bunch of instances to have useful names that I can refer > to them by, I usually put them in a dictionary: > > d = {} > dict["test"] = MyClass() > dict["test2"] = MyClass() this was one of my early solutions, but then you have to access the instance via the dictionary key, rather than directly. > > or if you want the instance to have a name atribute: > > thisname = "test" > dict[thisname] = MyClass(name = thisname) > > Note, however, that I probably wouldn't do this (or what you have > proposed) at all. If the object has a name attribute, than you don't > want a duplication of data, there is too much of a chance of it getting > mixed up. You might do: > > thisname = "test" > instance = MyClass(name = thisname) > > dict[instance.name] = instance > > that way you are guaranteed that the names match. yes, i'll have to rework my thinking along these lines. > > A good general rule is that if it is hard to do something in Python, you > are probably trying to solve a problem in a non "Pythonic" way, and you > should step back and find a more natural way to do it. a very good rule. it is going up over my desk :) -- Sergio J. Rey http://typhoon.sdsu.edu/rey.html GPG fingerprint = 16DB 4934 E0F1 B386 AE81 D379 914C 33E5 F690 95DF "The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change." - from a Fortran manual for Xerox computers -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 240 bytes Desc: not available URL: From max at alcyone.com Sat Oct 6 14:12:09 2001 From: max at alcyone.com (Erik Max Francis) Date: Sat, 06 Oct 2001 11:12:09 -0700 Subject: Octonians in Python References: Message-ID: <3BBF4979.4067B406@alcyone.com> David Feustel wrote: > There is one additional system of complex numbers > (octonians) beyond quaternions. Are there any > python implementations of octonians? I recall there being a Python module that supported geometric algebras, in which quaternions and octonions (not octonians) are pretty easily emulated, and not in a way that defeats their purpose (like matrices). I know that it was posted to comp.lang.python some months or years ago; a Google Groups search would probably turn it up. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ A wise man never loses anything if he have himself. \__/ Montaigne Maths reference / http://www.alcyone.com/max/reference/maths/ A mathematics reference. From db3l at fitlinxx.com Tue Oct 9 12:28:03 2001 From: db3l at fitlinxx.com (David Bolen) Date: 09 Oct 2001 12:28:03 -0400 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> Message-ID: "Markus Jais" writes: > I haven't followed the discussion > but to write 3.foo is something I would like to have in Python > I am a big fan of Ruby and there you can write > for example > > -4.abs But is there any practical reason you'd ever write that (e.g. instead of just writing "4" and being clearer?) I could understand if you had something like: value = -4 (...) value.abs() but why would you ever invoke a method on a numeric literal in your source? I can appreciate how such orthogonality may have an attraction, but am not sure I see any practical benefits to trying to fit such a thing into the Python parser. > which gives 4 (of course) Is it? "Of course" that is. I would think you could read that as: -(4.abs) which would be -4 (-4).abs which would be 4 In Python, -4 is actually the unary - operator applied to the numeric literal 4, whereas I believe in Ruby it's a numeric literal -4, so there's a basic difference in the parsers. But it does mean that there's some ambiguity as to how you might read the expression, particularly if you want to be consistent with an object invocation. For example, using an object instead of a literal: -obj.abs If this was treated, just as your numeric literal case, it would be retrieving the value of "obj" (somehow), negating it, and then calling the abs method on that resulting negated value? Of course, in both Python and Ruby it instead calls the obj.abs method and then negates the result. In Python, it's the same unary - operator and precendence in effect in both cases, while in Ruby in one case it's a numeric literal and the other the unary operator. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From greg at cosc.canterbury.ac.nz Thu Oct 11 20:52:08 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 12 Oct 2001 13:52:08 +1300 Subject: Curious assignment behaviour References: <101020012140297889%jwbaxter@spamcop.net> <2793844.VU6TSbVV5P@lunix.schabi.de> Message-ID: <3BC63EB8.D3F4A5EB@cosc.canterbury.ac.nz> Markus Schaber wrote: > > But there's a drawback: Trying to type :-) means Shift-:, then (without > shift) a -, and after that shift-9... :-) That's not unique to German keyboards -- the same shift pattern applies to the one I'm using now! The general solution obviously is to connect two keyboards to your computer, one permanently shifted and the other permanently non-shifted. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From wayne at tbnets.com Fri Oct 26 22:37:35 2001 From: wayne at tbnets.com (Wayne Ringling) Date: Fri, 26 Oct 2001 22:37:35 -0400 Subject: Converting perl to python available? Message-ID: I have a few programs that I would love to convert to python but don't want to spend the time to recode them completly. Is there a project that is working on a conversion program yet? I searched Google and python archives and did really find a answer for this. So I thought I would ask the experts. Wayne From odeckmyn at teaser.fr Mon Oct 8 02:03:44 2001 From: odeckmyn at teaser.fr (Olivier Deckmyn) Date: Mon, 8 Oct 2001 08:03:44 +0200 Subject: [ANNOUNCE] Website for the french speaking community of Zope Message-ID: <9prffq$m7l$1@feed.teaser.net> Hi ! We are proud to announce you the launch of the website for the french speaking community of Zope ! Visit us at http://www.zopera.org ! Here is the full announce in French : 8<----------------------------------------- Cher tous, Nous sommes ravis de vous annoncer l'ouverture du site que nous attendions tous : le premier site communautaire pour Zope en fran?ais ! Rien que ?a ;) Zopera est n? ! Retrouvez nous sur http://www.zopera.org ! L'objectif du site est de f?d?rer l'ensemble de la communaut? avec un outil simple et efficace : le portail Zopera. Cet outil nous permet d'?changer et de partager autour de Zope, en fran?ais. Grace ? lui, tenez vous courant de l'activit? dans l'ensemble du monde Zope, et en fran?ais ! Ce site est ouvert ? tous : d?butants et experts, d?veloppeurs et webmasters, mais aussi utilisateurs ou d?cideurs. C'est aussi une vitrine Zope int?ressante. Le contenu du site est ouvert : c'est un site collaboratif ! Venez donc vous inscrire pour partager vos exp?riences et faire part ? la communaut? de votre connaissance de Zope. C'est VOUS qui faites le contenu du site, qui le faites vivre ! Vous y trouverez aujourd'hui: des news, des articles sur zope ou python, des howtos en fran?ais, des propositions d'embauches et un annuaire des sites zope. Dans les prochaines semaines, vous trouverez, ? peu pr?s dans cet ordre : tutoriaux, mise en ligne de vos CVs, Questions/R?ponses (avec g?n?ration de FAQ), Forum de discussion, sondages, annuaire des prestataires Zope, etc... Vos id?es sont bien entendues les bienvenues ! Ce site est r?alis? avec Zope bien s?r, avec l'aide du CMF. Nous l'avons intensivement test? depuis une semaine, mais il se peut qu'il reste quelques bugs ou comportements non triviaux : n'h?sitez pas ? nous les signaler ! Au chapitre des difficult?s techniques, ce site fonctionne tr?s mal avec les version 4.x de Netscape : pour une raison inconnue ? nos yeux, le navigateur semble bloqu? pdt 30sec avant de donner la main ? l'utilisateur sur une page d?mantibul?e. Nous sommes vraiment d?sol?s, cherchons toujours mais si quelqu'un a une id?e... Bien entendu, il est enti?rement gratuit. Venez vite nous rejoindre ! Et n'oubliez pas : "Qui a zop? zopera !" ;) Zopera Team : Kamon Ayeva, Pierre-Julien Grizel et Olivier Deckmyn. Ecrivez nous ? cette addresse : zopera at zopera.org From tjreedy at home.com Tue Oct 23 11:34:24 2001 From: tjreedy at home.com (Terry Reedy) Date: Tue, 23 Oct 2001 15:34:24 GMT Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> Message-ID: <46gB7.151079$5A3.52079649@news1.rdc2.pa.home.com> "Stephen" wrote in message news:97ae44ee.0110230529.5c33dd83 at posting.google.com... > > > I'm developing a catalog application (storing its data in a > > > relational database), where catalog entries are categorized > > > by one or more categories/subcategories. >From the above and your example catagories, I mistakenly assumed that you wanted to store relational data in your relational database, and described how to do that. Instead, it seems, you want to simulate a dynamically adjustable hierarchical database using an RDBM as the data manager behind the scenes. > > > It would be nice to have "unlimited" levels of subcategories ... > Thank you for the advice, Terry. Sorry if I'm being obstinate, > but I think the problem is a little less simplistic than it first > appears. Definitely (and wanting a solution to your actual problem, now better explaned, is not really being obstinate). > Let's look at the everyday addressbook in Act! or Outlook ? I'm not familiar with either, or any similar programs. My closest point of reference is the Windows registry. Otherwise, my experience is 'limited' to static schema (from users viewpoint) relational databases. > How would you create unlimited levels of categorisation > and unlimited numbers of subcategories ? Interesting question. To say much more, I'd need more specification. Such as, do you want to do search and selection with the RDBM (mostly off the disk) or with Python (possibly in memory)? If with the RDBM, I think my original comment stands: if you want to efficiently (and scalably) search and retrieve on any level of the hierachy, then you mush explicitly store each level with each item. An alternative would be an expandable tree index structure written, in this case, in Python. Terry J. Reedy From cliechti at gmx.net Wed Oct 31 17:05:59 2001 From: cliechti at gmx.net (Chris Liechti) Date: 1 Nov 2001 00:05:59 +0200 Subject: MS network provider using Python References: Message-ID: "John S. Yates, Jr." wrote in news:k7o0ut8u8pm4ueoju5djri48ecabjanver at 4ax.com: > I am prototyping a network provider (a DLL exporting > an implementation of the MS defined NP API and invoked > by MS's MPR (Multiple Provider Router)). Since I > anticipate a great deal of experimentation I would > dearly love to do some prototyping in Python. so you want a DLL that is used by an other programm but is itself written in python? > Can anyone in this news group offer words of wisdom? > > What is the best way in this kind of a rapid prototyping > environment to expose my python code as a DLL? haven't heard of such a tool. py2exe generates standalone python apps, but thats not what you want. wrapping DLLs so that the functions are available in python can be done with SWIG, thats the wrong way in this case. if you want to expose some (python coded) functions as a DLL, i think you have to write such a lib yourself. this DLL would then simply call an embedded python interpreter to achieve the function. the DLL init function starts the python interpreter and imports your script. all calls to the dll are then maped to a coresponding function in the python script. embedding python in C is failrly simple as all what you need to convert python data to c back and forth is provided by the Python DLL. for a documentation of this interface, have a look at "Extending & Embedding" in the Python docs that have come along with your Python distribution. the source version of python has also some example code on embedding the interpreter. chris -- Chris From cjw at sympatico.ca Fri Oct 26 10:36:52 2001 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 26 Oct 2001 10:36:52 -0400 Subject: sgmllib.py Message-ID: <3BD97504.A7272B02@sympatico.ca> An HTML attachment was scrubbed... URL: From bkelley at wi.mit.edu Wed Oct 17 18:04:36 2001 From: bkelley at wi.mit.edu (Brian Kelley) Date: Wed, 17 Oct 2001 17:04:36 -0500 Subject: ANNOUNCE PySomorph - a subgraph and graph isomorphism library Message-ID: <3BCE0074.1070004@wi.mit.edu> vf graph isomorphism library 0.9 You can download this package from http://staffa.wi.mit.edu/people/kelley/ This is a python binding to the VF graph isomorphism library available from http://amalfi.dis.unina.it/ There are three kinds of graph isomorphism performed 1 Graph Isomorphism - are two graphs G and H identical 2 SubGraph Isomorphism - is a graph G contained in a graph H maintaining edge counts. This means that matched nodes must have the same number of edges, for example the following two graphs will not match G H a c a'----c' \ / \ / \ / \ / b b' since a and a' do not have the same number of edges. 3 Subgraph Monomorphism - is a graph G contained in a graph H without maintaining edge counts This means that graph G matches graph H There are three basic implementations: Ullman - the granddaddy of graph ismorphisms, there are two variations of this matcher matchUll - graph isomorphism matchUllSub - subgraph isomophism VF - The VF algorithm matchVF - graph isomorphism matchVFSub - subgraph isomorphism matchVFMono - monomorphism VF2 - The VF2 algorithsm matchVF2 - graph isomorphism matchVF2Sub - subgraph isomorphism matchVF2Mono - monomorphism For a better description of the algorithm see the docs directory under vflib-2.0. Basic usage: I Creating a graph Graphs are created using vflib.ARGEdit() ARGEdit has two functions ARGEdit.InsertNode(object) -> returns the inserted node index ARGEdit.InsertEdge(index1, index2, object) Nodes and edges are typed. In both cases "object" must support equivalence replationships. You can use None for untyped graphs. Nodes and edges can be arbitrary python objects so the equivalence relationships can be quite complex. II making a matching object A matching object is created using vflib.GraphMatcher(graph) where graph is an ARGEdit object. matcher = vflib.GraphMatcher(graph) a GraphMatcher object has match functions that support the following interface matcher.match(graph, maxcount) maxcount is a limit on how many matches to search. For example matcher.match(graph, -1) -> returns all matches matcher.match(graph, 1) -> returns only the first match a matching object supports the following matches (see above for descriptions): matcher.matchVF(graph, maxcount) matcher.matchVFSub(graph, maxcount) matcher.matchVFMono(graph, maxcount) matcher.matchVF2(graph, maxcount) matcher.matchVF2Sub(graph, maxcount) matcher.matchVF2Mono(graph, maxcount) matcher.matchUll(graph, maxcount) matcher.matchUllSub(graph, maxcount) each matching function returns a list of matches in the following form. [ ( nodes1, edges1 ), ( nodes2, edges2 ) ... ] the nodes and edges returned are nodes and edges of the target graph that are isomorphic matches of the matcher graph. The nodes are mapped in order of the nodes and edges of the matcher graph. For example: G = vflib.ARGEdit() G.InsertNode(1) G.InsertNode(2) G.InsertEdge(0,1, "first edge") H = vflib.ARGEdit() H.InsertNode(2) H.InsertNode(1) H.InsertEdge(1,0, "first edge") matcher = vflib.GraphMatcher(G) print matcher.matchVF(H, -1) -> [((1, 2), ('first edge',))] Confused? Let's be more explicit. I'll create an object that can tell exactly what node it is and still match the integers. class Wrapper: def __init__(self, data, nodeid): self.data = data self.nodeid = nodeid def __eq__(self, other): return self.data == other.data def __repr__(self): return "Wrapper(data=%s,nodeid=%s)"%(self.data,self.nodeid) G = vflib.ARGEdit() G.InsertNode(Wrapper(1, nodeid=0)) G.InsertNode(Wrapper(2, nodeid=1)) G.InsertEdge(0,1, "first edge") H = vflib.ARGEdit() H.InsertNode(Wrapper(2, nodeid=2)) H.InsertNode(Wrapper(1, nodeid=1)) H.InsertEdge(1,0, "first edge") matcher = vflib.GraphMatcher(G) print matcher.matchVF(H, -1) -> [((Wrapper(1,1), Wrapper(2,2)), ('first edge',))] Now we can see that the order of the matches is indeed the order of the matching graph G. We can also see the power of using python objects to form the graph! This code is located in test_objects.py For a good example of how to make graphs and compare them, see test_vf.py which performs a check on the monoisomorphic routines. NOTES: There can only be two edges between any two nodes a and b. The edge from a to b and the edge from b to a. KNOWN BUGS: 1. Apparently the GraphMatcher class is kind of picky if the underlying graph goes away and is reference collected. G = vflib.ARGEdit() matcher = vflib.GraphMatcher(G) del graph matcher.matchVF(H) will fail with something like: Traceback (most recent call last): File "", line ?, in ? RuntimeError: unidentifiable C++ exception The fix for this problem is known and will be updated in the next version. Fortunately the program will not crash at this point. 2. Error reporting is a little screwy >>> import vflib >>> G = vflib.ARGEdit() >>> G.InsertNode(1) 0 >>> G.InsertNode(2) 1 >>> G.InsertEdge("hello", "there", None) Traceback (most recent call last): File "", line 1, in ? TypeError: an integer is required It doesn't really tell you where an integer is required... 3. No linux port yet... From gherman at darwin.in-berlin.de Mon Oct 15 04:44:11 2001 From: gherman at darwin.in-berlin.de (Dinu Gherman) Date: Mon, 15 Oct 2001 10:44:11 +0200 Subject: ActiveState Python Cookbook site broken or frozen!? Message-ID: <3BCAA1DB.AE557798@darwin.in-berlin.de> The ActiveState Python Cookbook doesn't accept recipes anymore! See error below! Is it broken or is the game over? Regards, Dinu -- Dinu C. Gherman ReportLab Consultant - http://www.reportlab.com ................................................................ "The world becomes a better place as a result of the refusal to bend to authority and doctrine." (Noam Chomsky) Error: Sorry some unknown SQL error occured. [sql.error] [('37000', 403, '[Microsoft][ODBC SQL Server Driver] [SQL Server]Invalid operator for data type. Operator equals add, type equals text.')] From James_Althoff at i2.com Fri Oct 12 14:24:08 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Fri, 12 Oct 2001 11:24:08 -0700 Subject: Why not 3.__class__ ? Message-ID: Walter D?rwald wrote: >The only type still missing is module (at least for type checks, I don't > know what the factory function module should do, and how deriving from >module would be useful). Good point. For now, it seems like three choices are available (for the isinstance check): 1) the "butt ugly" mechanism, 2) the "type-method spelled backwards" mechanism, 3) the "import types / heavy artillery" mechanism, (s throughout) Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>> >>> import thread as t >>> >>> isinstance(t, __builtins__.__class__) 1 >>> >>> isinstance(t, type(__builtins__)) 1 >>> >>> import types >>> isinstance(t, types.ModuleType) 1 >>> Don't know if there are any plans/thoughts regarding the addition of a "module" or "mod" equivalent of "int" (etc.) someday. Jim From jknapka at earthlink.net Sun Oct 7 19:58:08 2001 From: jknapka at earthlink.net (Joseph A Knapka) Date: Sun, 07 Oct 2001 23:58:08 GMT Subject: How to call a python function in C++ References: <3BC09555.9090903@auburn.edu> Message-ID: <3BC096A4.478C3510@earthlink.net> clio wrote: > > Hi, > Here is a very confusing problem. I am trying to call a python function > in C. I build a .cxx which have following functions: > > ...... > static PyObject *my_callback=NULL; > > static PyObject * my_set_callback(PyObject * dummy,PyObject * args) > > { > PyObject *result = NULL; > PyObject *temp; > > if (PyArg_ParseTuple(args, "O:set_callback", &temp)) { > if (!PyCallable_Check(temp)) { > PyErr_SetString(PyExc_TypeError, "parameter must be > callable"); > return NULL; > } > Py_XINCREF(temp); /* Add a reference to new > callback */ > Py_XDECREF(my_callback); /* Dispose of previous callback */ > my_callback = temp; /* Remember new callback */ > /* Boilerplate to return "None" */ > Py_INCREF(Py_None); > result = Py_None; > } > return result; > } > .......... > Acctually, this code is from online manual. Then in another c++ program > I have this: > > extern PyObject *my_callback; This will not work because my_callback is declared static and therefor is visible only within its source file. Try PyObject *my_callback; instead. > ...... > PyObject * arglist; > arglist = Py_BuildValue("(s1000)", buf); > PyObject *result; > > result = PyEval_CallObject(my_callback, arglist); > Py_DECREF(arglist); > > ....... > > I compiled them to seprate object file and link them to be provapimodule.so. > > I got no error in compiling, but when I load the provapi in python, > there is an error: > > >ImportError: ./provapimodule.so: undefined symbol: my_callback. See my comment above. There is essentially no link step at build time for a Linux shared library; the Linux dynamic loader attempts to resolve linkage at load time, so that's why you see the error here rather than at build time. > Then I try to remove "static" in defination of my_callback. This time, I > can load the module without error, and I can access provapi.my_callback > too. But I met this: > > >>> provapi.my_set_callback(binstr,happy) > Traceback (innermost last): > File "", line 1, in ? > AttributeError: my_set_callback > > I do not know what does this mean? You -have- initialized the module method table using Py_InitModule(), haven't you? If not, that's the problem. > I am using g++ (gcc version 2.96 20000731) and Linux 7.1. Python 1.5.2. > > Anyone can help me, thank you! > > clio HTH, -- Joe # "You know how many remote castles there are along the # gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald # Linux MM docs: http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html From guido at python.org Thu Oct 25 23:33:09 2001 From: guido at python.org (Guido van Rossum) Date: Fri, 26 Oct 2001 03:33:09 GMT Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> Message-ID: Greg Ewing writes: > In the case in question, i.e. > > () = () > > the patterns clearly do match. And, every name in > the LHS has a corresponding value in the RHS. The > numbers of both these things happen to be 0, but > so what? > > I think Michael Abbot is quite right. There's no > reason this shouldn't be a legitimate, albeit > degenerate, case of tuple unpacking. FWIW, I agree. I just never thought of this. --Guido van Rossum (home page: http://www.python.org/~guido/) From l0819m0v0smfm001 at sneakemail.com Sat Oct 6 15:34:13 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Sat, 06 Oct 2001 19:34:13 GMT Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> <9pimak$c22$1@tyfon.itea.ntnu.no> <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> <3BBE4E12.16FE036A@earthlink.net> <9pn44q$m1r$1@tyfon.itea.ntnu.no> Message-ID: <3BBF2751.3010309@sneakemail.com> Magnus Lie Hetland wrote: > > Feel free to contradict Strunk & White, if you like. I won't, though. OK, I will. Strunk & White is fine, and I use it myself, but the use of the possessive apostrophe is, and has always been highly contentious. According to The Oxford Companion to the English Language: "...there appears from the evidence that there was never a golden age in in which the rules for the use of the possessive apostrophe in English were clear-cut and known, understood, and followed by most educated people...[snip restatement of 20th c. rules essentially the same as S&W]...beyond this point difficulties and inconsistencies are as common in the 1990s as in earlier times, especially with proper nouns...[snip discussion of ommission of ' in place names and organization names]...There is widespread inconsistency and uncertainty in the use of the apostrophe when a singular noun already ends in -s...[snip discussion of ancient names such as Xerxes]...With short names, an extra syllable is generally pronounced, although the possessive can be written either way: Mr Harris' job, Mr Harris's job; Keats' poetry, Keats's poetry..." - The Oxford Companion to the English Language, p. 75-76 The Chicago Manual of Style (section 6.30, I believe) allows that with polysyllabic personal names ending in a z sound, many writers and editors now use the possessive apostrophe without an accompanying s, e.g. Dickens' but Harriss's. Hence, Peters'. This is acceptable usage in a manuscript prepared according to the manual. The Grammar Lady (http://www.grammarlady.com) is even more liberal, allowing the ' without-s form for any personal name ending in s. This probably started as a hyper-generalization of the exception mentioned in Strunk and White for certain ancient names such as Moses and Jesus, but if it's common enough to rate an allowable-if-used-consistently by the CMoS, it's good enough for me. and-if-it's-good-enough-for-Moses-it's-good-enough-for-Tim-Peters--ly yrs, Joshua From qrczak at knm.org.pl Sat Oct 20 15:43:50 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 20 Oct 2001 19:43:50 GMT Subject: Dictionary from list? References: Message-ID: Sat, 20 Oct 2001 14:42:55 -0400, Tim Peters pisze: > It's quite handy in Perl! Picture parsing a simple textual database with > key + value lines (like, e.g., mail headers). In Python you can use > re.findall() to parse them all up in one gulp, but then you're left with a > flat [k,v,...] list. findall(pattern, string) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. It seems that it will return [(k,v),(k,v),...], no? > dictionary() is a constructor in 2.2, and I spent a lot of time worrying > about what kind of arguments it should take. I believe a flat [k,v,...] > list would have been the most useful thing to accept; I believe in [(k,v),(k,v),...]. This representation of dictionaries is much easier to iterate over, and much easier to generate with list comprehensions. And it's the inverse of d.items(). And IMHO it's more elegant: the list is homogeneous. It fits statically typed languages too, unlike [k,v,k,v,...] (it's used in Haskell for example). I'm using it in my little dynamically typed language. > Everyone's first thought seems to be that dictionary() should accept > a list of (key, value) tuples -- but there are few core functions > that produce such a list Is there any function which produces [k,v,k,v,...]? -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From asencio at mitre.org Fri Oct 26 16:48:09 2001 From: asencio at mitre.org (Angel Asencio) Date: Fri, 26 Oct 2001 16:48:09 -0400 Subject: BOA GUI builder? Message-ID: <3BD9CC09.2B1AB020@mitre.org> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: asencio.vcf Type: text/x-vcard Size: 317 bytes Desc: Card for Angel Asencio URL: From loewis at informatik.hu-berlin.de Mon Oct 8 07:43:02 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 08 Oct 2001 13:43:02 +0200 Subject: Status of SOAP and Python. References: Message-ID: grahamd at dscpl.com.au (Graham Dumpleton) writes: > Enough of the rambling I guess. How do others see where SOAP is going in > relation to Python? Do people still think SOAP is the best thing since > sliced bread, or are people starting to realise it is pretty crappy after > all? I certainly hope that SOAP is going to disappear rather sooner than later, and that people who care about distributed systems come back to well-defined interfaces, and efficient marshalling. Regards, Martin From sholden at holdenweb.com Thu Oct 25 07:12:51 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 25 Oct 2001 07:12:51 -0400 Subject: Learing Python, Newbie question References: Message-ID: "Johannes Gamperl" wrote ... > michael at rcp.co.uk says... > > Johannes Gamperl wrote: > > > > > Do you know if there is a > > > coditional operator in python ( ?: ) > > > > > > e.g. > > > > > > if os.path.exists("gbook.txt"): > > > db_first = 0; > > > else: > > > db_first = 1; > > > > > > > > > db_first = ( os.path.exists("gbook.txt") ) ? 0:1; > > > > Ho ho! > > > > I'm glad that beginners also miss the conditional operator. > > > > I'm afraid there's been a bit of an argument about possible syntax, and > > most of the old hands seem firmly convinced that the conditional operator > > serves no useful purpose. > > > > No, it doesn't exist! > > > > > > Mind you, in the example you give, there's no point at all in having a > > conditional operator, since what you *really* wanted to write is: > > > > db_first = not os.path.exists("gbook.txt") > > hello Michael, > > the e.g. doesn't make sin :) .. but i want to describe for what i'm > looking for. i came from perl and i find the conditional operator very > usefull .. > > oki ... my journey to python goes on ;) > Not, you understand, that there's any *prejudice* against a conditional operator. There has been a lot of discussion as to how the equivalent to the C/Perl operator could/should be programmed in Python as it currently exists, and also some (!) discussion as to how a new feature could be added to the language. What we are currently missing is *agreement* - both on whether it's really useful and, more especially, on what the syntax should be. Keep asking questions! regards Steve -- http://www.holdenweb.com/ From carlca at dircon.co.uk Mon Oct 29 15:54:41 2001 From: carlca at dircon.co.uk (Carl Caulkett) Date: Mon, 29 Oct 2001 20:54:41 -0000 Subject: ActivePython 2.2 alpha status Message-ID: Hi all, I've downloaded the latest alpha release of ActiveState's ActivePython, with a view to playing with some of the new 2.2 features such as iterators, abilty to sub-class types, etc. As far as I can see, the new features all work apart from the new property keyword. Can anyone confirm that this is what they see? Mark H, if you are reading, could you let me know what the timeframe is for a full release of ActivePython 2.2? -- Thanks in advance, Carl From s.keim at laposte.net Thu Oct 25 03:35:23 2001 From: s.keim at laposte.net (sebastien) Date: 25 Oct 2001 00:35:23 -0700 Subject: Question: How to only create new object instances? References: <9r74ra$94o$1@netnews.upenn.edu> Message-ID: <7da8d8f8.0110242335.170277a0@posting.google.com> > I am trying to create new cells only when they don't exist in a given library > of cells. In the case where they already exist in the supplied library, I > would like the "new" cell to refer to the exisiting cell in the library. Maybe something like this could work class _Cell: def __init__(self,cellName,library=None): self.cellName = cellName self.library = library self.library.add_cell(self.cellName,self) def Cell(cellName,library=None): if cellName in library.cellList.keys(): print "cell already exists" return library.cellList[cellName] else: return _Cell(cellName, library) In Python 2.2 the natural way to achieve this would probably be to use the __new__ class method and to construct the new instance 'by hand'. From tim.one at home.com Wed Oct 10 01:25:29 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 10 Oct 2001 01:25:29 -0400 Subject: Curious assignment behaviour In-Reply-To: Message-ID: [Dale Strickland-Clark] > Thanks for bringing me up-to-date with this debate. > > I'm not sure I sympathise with the philosophy that if you can't please > everyone then don't please anyone. An argumentative group can thus > bring progress to a stand-still. Take the hint and follow the link I provided: if you don't study the debates for yourself, you're going to reduce them to shallow characterizations (like, say, that one) based on imagination. If Guido has a reputation for anything, fear of not pleasing everyone ain't it. > For just about any operator you can come up with an example that needs > parenthesise to behave in the 'natural' way rather than the way forced > by precedence. Sure. It's a bad sign when examples aren't strained or contrived, though. > Assignment in expressions, particularly in conditional statements can > reduce complexity and simplify legibility. While a stiff dose of poison can be good for some illnesses -- absolutes aren't particularly illuminating. > You can always write code that's difficult to understand and I would > argue that the recently added list comprehension syntax can be a real > pig to decypher but I wouldn't be without it now. Sure and sure, but "difficult to understand" wasn't the issue so much as "surprising in ordinary cases" and even "not helpful enough often enough to be worth the costs". > Not introducing a feature because it might make some code more > difficult to understand is on a par with not letting adults buy knives > in case they cut themselves. It was more akin to not letting adults piss on the toaster because it might short out and cause a fire . opposing-arguments-that-were-actually-made-would-probably-be-more- interesting-ly y'rs - tim From dalke at dalkescientific.com Mon Oct 15 03:48:16 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Mon, 15 Oct 2001 01:48:16 -0600 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: <9qe49r$4k1$1@slb3.atl.mindspring.net> Chris Tavares wrote: >May I be the first to say - ICK! I'll second that nomination. It looks ugly, and doesn't solve any problems I have. I *like* if e1: x = e2 else: x = e3 Makes it easy to see what goes on when e1 is true or false. Take Uncle Tim's example code x = (if a+b/sqrt(3) then 3**f(5, 3)- 12 else ",".join(list) + ":\n") and compare its readability to if a+b/sqrt(3): x = 3**f(5, 3) - 12 else: x = ",".join(list) + ":\n" I can easily understand the second. The first takes effort. There's talk of generalization. But more likely the expansion of a one-liner like the above is to add more statements to a branch, as in something like: if a+b/sqrt(3): count = count + 1 x = 3**f(5, 3) - 12 else: spam *= count x = ",".join(list) + ":\n" With the one-liner form, translation to the normal Python if/else statement calls for a lot of code changes. I tried looking through the thread in its various subject names. I couldn't figure out what was the driving reason for this idea. (Other than as a replacement for C's ?: ternary operator.) Enlightment, anyone? Andrew dalke at dalkescientific.com From com-nospam at ccraig.org Thu Oct 18 10:22:50 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 18 Oct 2001 10:22:50 -0400 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) In-Reply-To: <3bcedae2$0$3754$edfadb0f@dspool01.news.tele.dk> References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <3bcedae2$0$3754$edfadb0f@dspool01.news.tele.dk> Message-ID: "Anders J. Munch" writes: > Here's an additional alternative: > > Use a function-like form let to perform assignment within expression. > let(X,Y) > has the effect of doing > X = Y > and returning the assigned object. I had thought about doing this earlier. You could do this now with a little ugly syntax: def let(a, b): a[0] = b return a[0] while let([a], get_next()): process(x) The problem being that you have to pass the variable as an element in a mutable structure in order to modify it. The problem with your proposal being that you don't (and it would be the only function where you don't). -- Christopher A. Craig From loewis at informatik.hu-berlin.de Tue Oct 30 07:38:40 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 30 Oct 2001 13:38:40 +0100 Subject: thread SIG??? References: Message-ID: "Markus Jais" writes: > in my "Core python" book is a SIG for Threads mentioned > but I can not find one on python.org > does this SIG no longer existes?? I think it has expired, indeed. > or there another place or mailinglist for threads in python?? Questions and discussion of threads in Python are welcome on python-list at python.org (aka comp.lang.python). Regards, Martin From andersjm at dancontrol.dk Tue Oct 16 06:56:35 2001 From: andersjm at dancontrol.dk (Anders J. Munch) Date: Tue, 16 Oct 2001 12:56:35 +0200 Subject: [Python-Dev] conditional expressions? References: <3bcbfda6$0$42081$edfadb0f@dspool01.news.tele.dk> Message-ID: <3bcc127a$0$42071$edfadb0f@dspool01.news.tele.dk> "Michael Abbott" wrote in message news:Xns913C6BFA94D38michaelrcpcouk at 194.238.50.13... > "Anders J. Munch" wrote in > news:3bcbfda6$0$42081$edfadb0f at dspool01.news.tele.dk: > > > Quick, what does this snippet do if return_as_map is true? > > > > return if return_as_map then {'A':a,'B':b} else a,b > > > > Rather than open up a new venue of obfuscation possibilities in > > Python, I'd go for mandatory parentheses around the conditional > > expression. > > Nah. Go for "maximal munch", I can't think of anything wrong with that. > The above expression then returns the dictionary (only). Good try. Maximal munch is certainly one of the better options, but it's not perfect. What should be the output from: x = 260 abs_x_mod_256 = divmod(if x<0: -x else: +x, 256)[1] print abs_x_mod_256 wir-brauchen-maximal-munch-oder-vielleicht-was-anders-munch-ly-y'rs, Anders From rikard at strakt.com Mon Oct 22 10:08:26 2001 From: rikard at strakt.com (Rikard Bosnjakovic) Date: Mon, 22 Oct 2001 16:08:26 +0200 Subject: a better prime number generator References: Message-ID: <3BD4285A.70400@strakt.com> John Thingstad wrote: > This should work fast up to say 10000. [...] > set = [x for x in set if x== n or x % p != 0) That comprehension does not work. Where do you define "p"? -- Cheers, ------------------------------------------------------------------------ Rikard Bosnjakovic http://bos.hack.org/cv/ Python Hacker rikard at strakt.com AB Strakt bos at hack.org From dale at riverhall.NOTHANKS.co.uk Sat Oct 27 12:55:31 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Sat, 27 Oct 2001 17:55:31 +0100 Subject: xml.dom.minidom.parseString() doesn't accept Unicode. Message-ID: Given that XML is very Unicode friendly, this seems a rather odd limitation. >>> import xml.dom.minidom >>> dom = xml.dom.minidom.parseString(u'') Traceback (most recent call last): File "", line 1, in ? File "c:\python21\lib\xml\dom\minidom.py", line 915, in parseString return _doparse(pulldom.parseString, args, kwargs) File "c:\python21\lib\xml\dom\minidom.py", line 901, in _doparse events = apply(func, args, kwargs) File "c:\python21\lib\xml\dom\pulldom.py", line 299, in parseString buf = StringIO(string) TypeError: expected string, unicode found >>> -- Dale Strickland-Clark Riverhall Systems Ltd From mcfletch at home.com Mon Oct 15 02:08:35 2001 From: mcfletch at home.com (Mike C. Fletcher) Date: Mon, 15 Oct 2001 02:08:35 -0400 Subject: Will Ware alive? (was Re: where lives uthread (microthreads) now ??) In-Reply-To: <3BCA6864.53EFD051@alum.mit.edu> Message-ID: <000101c1553f$d3b0e250$1802a8c0@Rose> Will, my latest version of uthreads (uthread9.py) is included with the latest Stackless versions as "uthread.py". I quit my job almost 4 months ago (egads! has it been that long?), and finished work on my micro-threading distributed virtual reality system a while before that, so I haven't even played with uthreads for almost half a year (not much call in graphics land). I'd like to try the C-switched ones when they arrive (Guido? Chris?) and build a decent network server architecture out of them (they are, by far, the nicest way I've encountered to write network code). Not a high priority for me though, as I'm focussing on my real career instead of the programming hobby. If, for some reason, you want to link to my version on my site (sorry for the outdated page, haven't done much with the web-site): http://members.home.com/mcfletch/programming/ But I'd suggest just letting people get it from the latest Stackless distributions. http://www.stackless.com/ Oh, and my email is now: mcfletch at home.com or mcfletch at geocities.com what with leaving Tpresence. Enjoy yourself, Mike -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Will Ware Sent: October 15, 2001 12:39 AM To: python-list at python.org Subject: Re: Will Ware alive? (was Re: where lives uthread (microthreads) now ??) ... Mike, if you see this, can you check and make sure I have the most recent version at http://willware.net:8080/uthread.py ? I'd appreciate it, thanks. ... From opengeometry at yahoo.ca Tue Oct 16 15:34:26 2001 From: opengeometry at yahoo.ca (William Park) Date: Tue, 16 Oct 2001 19:34:26 GMT Subject: Python, Unix sendmail, and multiple recipients References: Message-ID: <6Z%y7.267$j5.9750@news.eol.ca> Kemp Randy-W18971 wrote: > Thanks to everyone for the quick responses. As soon as I emailed the > question, I got two answers from the Python community in under five > minutes. If only the other lists I subscribe to were so prompt! If you're already on Unix system, then it begs the question why write Python script to something that cries out for shell, ie. $ for i in 'a at xxx.com' 'b at xxx.com' ... > do mutt $i ... > done -- William Park, Open Geometry Consulting, 8 CPU cluster, Linux (Slackware), Python, LaTeX, Vim, Mutt, Tin From jim_kerr at agilent.com Tue Oct 9 16:04:03 2001 From: jim_kerr at agilent.com (Jim Kerr) Date: 9 Oct 2001 13:04:03 -0700 Subject: problem processing COMException in VB6 References: <50626d00.0110021619.2000be73@posting.google.com> <3BBBBE74.20509@ActiveState.com> Message-ID: <50626d00.0110091204.11ad8978@posting.google.com> Using DISP_E_EXCEPTION didn't work either; VB displayed the message "Automation error - exception occurred" which again suggests that only the scode is being consulted, not the description. After poking around a bit, I discovered that you can force VB to display your description string if you set the facility code to FACILITY_ITF (= 4), and use a custom error code greater than 0x200, as in: raise COMException(desc="Your message goes here", scode=0x80040201) I'll leave it to the experts to decide if it's best to express the scode as scode = winerror.OLE_E_OLEVERB | MYCUSTOMHRESULT or some other symbolic representation instead of hardcoding the value. Jim Mark Hammond wrote in message news:<3BBBBE74.20509 at ActiveState.com>... > Jim Kerr wrote: > ... > > > raise COMException(desc="No measurement defined on channel %d" % > > channelNum, scode=winerror.DISP_E_BADINDEX) > > > > and the VB client catches the exception with > > > > MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Server > > Error" > > > > then the message box displays the text "Subscript out of range" > > instead of "No measurement defined on channel 3". > > > It is likely that VB is treating DISP_E_BADINDEX specially. Try using > DISP_E_EXCEPTION. > > Mark. From peter at engcorp.com Tue Oct 9 00:18:49 2001 From: peter at engcorp.com (Peter Hansen) Date: Tue, 09 Oct 2001 00:18:49 -0400 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> Message-ID: <3BC27AA9.B1729BCA@engcorp.com> Chris Liechti wrote: > > Carsten Gaebler wrote in > news:3BC166F4.5E7FAB08 at snakefarm.org: > > Given a string > > s = "%(foo)s %(spam)s" > > and two dictionaries > > d1 = {"foo": "bar"} > > d2 = {"spam": "eggs"} > > > > how would you apply d1 and d2 to s without modifying or explicitly > > copying one of the dicts? > > > s = ("%(foo)s %%(spam)s" % d1) % d2 > > use two "%" for variables that are in the second dict. Neat. Note of course that this requires everything which has only a single % to be in the first dictionary, and everything with %% to be in the second. Might be what was wanted... or maybe the OP won't like that either... -Peter From tjreedy at home.com Tue Oct 23 12:53:05 2001 From: tjreedy at home.com (Terry Reedy) Date: Tue, 23 Oct 2001 16:53:05 GMT Subject: Dictionary from list? References: Message-ID: "Tim Peters" wrote in message news:mailman.1003813882.5893.python-list at python.org... > I appreciate that. However, the builtin dictionary() cow has already > escaped the 2.2 barn, so the question now is whether we let it roam the > Python pasture with two broken legs, or put a spiffy sequence saddle on it > so you can gallop on it in comfort into the mooooonlight. Fact: a Python dictionary literal is a sequence of key:value pairs of literals, with the first becoming a hashable object, and only such a sequence. Observation: ':' is analogous to '( , )', which could have been the syntax chosen (though I'm glad it wasn't). Therefore: Proposed rule 1: the dictionary() constructor should accept a sequence of pairs of objects, with the first being keyable (hashable). In particular, it should invert dict.items. Note: by type, 'pair' might mean duple only; by interface, it would mean an object reporting a length of two and yielding objects with indexes 0 and 1. Comment: once pair is defined, this rule gives a uniform target for conversion from other formats, including those generated by other software systems. I currently vote for the latter. Proposed rule 2: dictionary() should reject any other sequence, just as does the internal constructor-from-literals. Paraphrase: conversions from the many other possible formats should be handled externally from dictionary(). Opinion 3: Given the fact and comments above, these two rules should be easy to understand and teach. Terry J. Reedy From fdrake at acm.org Fri Oct 19 16:59:04 2001 From: fdrake at acm.org (Fred L. Drake) Date: Fri, 19 Oct 2001 16:59:04 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011019205904.1F95528697@beowolf.digicool.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Documentation update beyond the Python 2.2 beta 1 docs. This matches the revised iSilo document conversion. From shari.maria at zoom.co.uk Wed Oct 3 11:42:58 2001 From: shari.maria at zoom.co.uk (shari) Date: 3 Oct 2001 08:42:58 -0700 Subject: AttributeError: class 'jnios.os' has no attribute 'fork' ---- what!!?? Message-ID: <417b6bb2.0110030742.3d09c719@posting.google.com> Sorry if this sounds simple, but I've just started using jpython. I want to call a python script from java. I thought it would be simple! Within my java code I am using: PythonInterpreter pInt = new PythonInterpreter(); pInt.execfile(".\\Test.py"); To call a python script containing: self.pid = os.fork() At first I got the error "os has no attribute pipe", which I solved by using 'jnios-1.7' to replace Lib\os.py. My error then mutated into the following: AttributeError: class 'jnios.os' has no attribute 'fork' So I can't use popen2.py or os.fork(). I'm now at a complete dead end, has anyone got any clues? Cheers, Shari From matt at mondoinfo.com Fri Oct 26 16:08:20 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Fri, 26 Oct 2001 20:08:20 GMT Subject: Tk and focusing windows References: Message-ID: On Fri, 26 Oct 2001 10:52:34 GMT, Graham Ashton wrote: Dear Graham, >Thanks very much for the example - I'll have a play around with that now >and see if I can get it to work for me. You're most welcome. >> Of course, once you've got the right incantation for your window >> manager, there's no guarantee that another window manager will do >> just the same thing in response to the same requests. >That's more than a bit depressing. I think I'm going to be looking at >GTK pretty soon. Thanks again... GTK may be handier in any number of ways (I haven't used it myself) but just to cheer you up : the problem of recalcitrant and uncooperative window managers isn't limited to Tkinter or Python. I generally think of a request to a window manager as being roughly equivalent to a request made to a stranger on the street. Regards, Matt From christophertavares at earthlink.net Mon Oct 15 02:16:12 2001 From: christophertavares at earthlink.net (Chris Tavares) Date: Mon, 15 Oct 2001 06:16:12 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: "Tim Peters" wrote in message news:mailman.1003089072.26009.python-list at python.org... > [Tim] [... snip ... ] > Alas, it didn't to Python's parser -- one-token lookahead isn't enough to > distinguish > > if 1: > > from > > if 1 then 2 else 3 > [ ... snip ... ] > Everything's cool if parens are required around a conditional expression, > though, in which case: > > x = if e1 then e2 else e3 + 1 # SyntaxError > x = (if e1 then e2 else e3) + 1 # cool > x = (if e1 then e2 else e3 + 1) # cool > x = if e1 then e2 else e3 # SyntaxError > x = (if e1 then e2 else e3) # cool > x = if if e1 then e2 else e3 then e4 else e5 # SyntaxError > x = (if (if e1 then e2 else e3) then e4 else e5) # cool > > Seems a mixed bag, but I'm more interested in readability and the > functionality than in minimizing keystrokes; requiring parens doesn't hurt > the goals I care about. > May I be the first to say - ICK! I have enough political problems trying to get people I know to try python out - adding a wart like this ( and requiring parens on this one, and only one expression is really a wart!) and trying to explain it to newbies doesn't strike me as a winner, and I've never really pined for this as an experienced user. Question - what happens with: x = (if e1 then e2 else e3,) # <--- note trailing comma Should be a 1 element tuple, yes? What happens? Or would you have to write: x = ((if e1 then e2 else e3),) That's just ugly. -Chris From lac at strakt.com Sun Oct 21 09:27:15 2001 From: lac at strakt.com (Laura Creighton) Date: Sun, 21 Oct 2001 15:27:15 +0200 Subject: error messages raised by python got me thinking. Message-ID: <200110211327.f9LDRFoT020471@ratthing-b246.strakt.com> Here is a common error: >>> f='1' >>> g=2 >>> f+g Traceback (most recent call last): File "", line 1, in ? TypeError: cannot add type "int" to string -------------- Here is another one: >>> g+f Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand types for + ----------- These are rather different error messages. The reason I noticed this, is because every time I get the first error, my initial parsing is always: f is the int, and g is the string. I seem to expect order of the arguments as presented in the error message to be the order in which I typed them. I think I would prefer 'Cannot add type string _and_ int'. For me, adding is not something that I do _to_ an existing thing, but something you do from top to bottom (or in this case left to right). Not quite the difference between a transitive and an intransitive verb, but it has that flavour. Perhaps I do not _add_ but _sum_. [Both are transitive, but I sum the whole set, not an individual element of the set. In my head anyway.] This has possible implications in how easy it is to learn python. Am I simply odd, or typical? In an international world, what does 'typical' mean given than many languages don't have verb constructs like this at all? (Further question: why the double quotes around _int_ but not _string_?) ever curious, Laura Creighton From nospam at wanted.com Mon Oct 29 04:06:45 2001 From: nospam at wanted.com (huber) Date: Mon, 29 Oct 2001 10:06:45 +0100 Subject: tkinter-canvas-rectangle-delete Message-ID: Can someone tell me what I am doing wrong ? from Tkinter import * def delz(): for i in c.find_all(): print c.gettags(i) c.delete("200") root=Frame() c=Canvas(root,width=100,height=100) n=c.create_rectangle(0,0, 10,10, fill="red",tag="res") c.addtag_withtag("200",n) b=Button(text="delete 200",command=delz) b.pack() c.pack() root.pack() root.mainloop() the output is : ('res', '200') ('res', '200') ........... ther rectangle is not deleted by clicking ther button ! if I delete the elements with tag="res" ( c.delete("res") ) the rectangle will be deleted! I am using : tk8.3.3 , tcl8.3.3 , python 2.1.1 on Suse linux 7.3 thanks in advance From skip at pobox.com Wed Oct 3 22:00:08 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 3 Oct 2001 21:00:08 -0500 Subject: using xmpl.parsers.expat In-Reply-To: <9pg388$hs72r$1@ID-91520.news.dfncis.de> References: <9pg388$hs72r$1@ID-91520.news.dfncis.de> Message-ID: <15291.49832.158195.207271@beluga.mojam.com> Rajarshi> When I try and do: >>>> import xml.parsers.expat Rajarshi> I get the following error: Rajarshi> Traceback (most recent call last): Rajarshi> File "", line 1, in ? Rajarshi> File Rajarshi> "/usr/src/build/42396-i386/install/usr/lib/python2.2/xml/parsers/expat.py", Rajarshi> line 4, in ? Rajarshi> ImportError: No module named pyexpat Rajarshi> Where is the module pyexpat supposed to come from? I believe you have to download, compile, and install it yourself, but you might get lucky and find an RPM somewhere. Try googling for pyexpat or check out the expat project page: http://expat.sf.net/ or the XML-SIG page: http://www.python.org/sigs/xml-sig/ -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From mjais at web.de Thu Oct 25 03:58:26 2001 From: mjais at web.de (Markus Jais) Date: Thu, 25 Oct 2001 09:58:26 +0200 Subject: string question. difference between string.split(str, ":") and str.split(":") Message-ID: hello what is the difference between import string str = "one:two:three" a, b, c = string.split(str, ":") and str = "one:two:three" a, b, c = str.split(":") except for the import statement in the first example. I prefer the 2nd version because it looks more oop (like Ruby) and less like Perl or C. but is there any difference, for example in performance??? any hints are welcome regards markus From paul at boddie.net Mon Oct 15 06:33:29 2001 From: paul at boddie.net (Paul Boddie) Date: 15 Oct 2001 03:33:29 -0700 Subject: J2EE equivalent in Python References: Message-ID: <23891c90.0110150233.3561ca32@posting.google.com> Robin Smith wrote in message news:... > Martin von Loewis writes: > > > Robin Smith writes: > > > > > I like J2EE but I am also an open source fan. > > > > What exactly is it that you like about J2EE? > > The way it hangs together. I like JSP, beans and tag libraries. That's more "J2EE Light" than J2EE, though. Indeed, there was some article I read recently which warned enterprises about buying into the whole J2EE thing when they're only really interested in JSP and related stuff. > Ideally I'm looking for tag libraries that run with python. Perhaps PSP within Webware is what you're looking for. However, as Gerhard H?ring almost pointed out, there is a vague comparison of solutions at... http://www.paul.boddie.net/Python/web_modules.html Arguably, Webware and Zope are closest to delivering some kind of platform supporting a range of activities comparable to J2EE, but unlike database connectivity with the DB-API, for example, there's no consensus on how such activities are to be carried out in applications, let alone any standardisation. Paul From alet at unice.fr Fri Oct 26 18:11:50 2001 From: alet at unice.fr (Jerome Alet) Date: Sat, 27 Oct 2001 00:11:50 +0200 Subject: [ANN] french audio conference about Python Message-ID: <3BD9DFA6.EEC3C6E4@unice.fr> Just a reminder : On October 27th 2001, at 2 p.m. French time, a conference about the Python language will take place at our local LUG. This conference will be given in French, and streamed live to the Internet for our very first time. Two dedicated irc channels will be available to discuss and ask questions. All the informations on how to tune-in and chat are available from: http://www.linux-azur.org and more precisely: http://www.linux-azur.org/python.html Hoping you'll be with us tomorrow ! thank you for reading. Jerome Alet From CpJohnson at edgars.co.za Mon Oct 15 07:16:08 2001 From: CpJohnson at edgars.co.za (CpJohnson at edgars.co.za) Date: Mon, 15 Oct 2001 14:16:08 +0300 Subject: CGIHTTPServer Message-ID: <42256AE6.003DE195.00@JHBMAIL01.edgars.co.za> Hi All, Has anybody got the CGIHTTPServer library working under windows? Or on RedHat 6.1 for that matter? Craig ------------------Edcon Disclaimer ------------------------- This email is private and confidential and its contents and attachments are the property of Edcon. It is solely for the named addressee. Any unauthorised use or interception of this email, or the review, retransmission, dissemination or other use of, or taking of any action in reliance upon the contents of this email, by persons or entities other than the intended recipient, is prohibited. Save for communications relating to the official business of Edcon, the company does not accept any responsibility for the contents of this email or any opinions expressed in this email or its attachments . If you are not the named addressee please notify us immediately by reply email and delete this email and any attached files. Due to the nature of email Edcon cannot ensure and accepts no liability for the integrity of this email and any attachments, nor that they are free of any virus. Edcon accepts no liability for any loss or damage whether direct or indirect or consequential, however caused, whether by negligence or otherwise, which may result directly or indirectly from this communication or any attached files. Edgars Consolidated Stores LTD ,Post office box 200 Crown Mines, Telephone: (011) 495-6000 From johnroth at ameritech.net Wed Oct 31 12:55:24 2001 From: johnroth at ameritech.net (John Roth) Date: Wed, 31 Oct 2001 09:55:24 -0800 Subject: Why 'self' ? References: <3BE04E7A.8E2CF101@ces.clemson.edu> Message-ID: "Schaefer, F." wrote in message news:3BE04E7A.8E2CF101 at ces.clemson.edu... > Hi all, > > It's been a while that I am working with Python and actually > the only thing I really do not like about it is 'self' in the > member function definitions as argument. If it > has to be there anyway, it is totally redundant to write it. > > So, why is self there ? You need to have some way to refer to the instance. Some people don't like the word 'self', and abbreviate it to 's' or some such. I suppose it's slightly clearer to have it in the method definition than to simply have 'self' be a pre-defined variable name in a method, but in any case, it's way too late to change now. John Roth From thomasNO at SPAM.obscure.dk Mon Oct 22 18:39:50 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Mon, 22 Oct 2001 22:39:50 GMT Subject: Mixing asyncore with threads Message-ID: Hi, Is it possible/advisible to mix asyncore (or modules using it) with threads ? More specifically, I'd like to build a HTTP based server, which will serve, more or less, IO bound content most of the time (served directly from memory/disk/DB). For this asyncore seems ideal. However, in some circumstances the content will be quite CPU intensive (like dynamically generated PNGs from a large dataset, etc.). In this case a thread would be nice, to prevent blocking other trafic while calculating. The problem is, that select() will block until it sees trafic on a readable or writeable port (AFAIK). So far I've come up with the following solutions: (1) Wraping asyncore.poll() in a loop with a small timeout value. (2) Use a "dummy" port on the loopback interface for triggering select() once output from the thread is finished. Of the two, I like (2) best, but I keep getting the feeling that there must be a better way ? Perhaps I should just settle on either asyncore or threads ? -- Best Regards Thomas Jensen From chris.gonnerman at newcenturycomputers.net Mon Oct 8 08:22:18 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Mon, 8 Oct 2001 07:22:18 -0500 Subject: Curious assignment behaviour References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> Message-ID: <004d01c14ff3$e0380720$0101010a@local> ----- Original Message ----- From: "Dale Strickland-Clark" > I observe that the folowing works as some might expect: > > x = y = 5 > > Assigns 5 to both x and y. > > However the expression: > > y = 5 > > does not yeild 5 > > >>> print y = 5 > Traceback ( File "", line 1 > print y = 5 > ^ > SyntaxError: invalid syntax > >>> > > So this is obviously a gludge in assignment. > > I'd be much happier if assignment yeilds the value assigned, as it > does in C (I believe). It could then be used universaly. Assignment isn't an expression, it's a statement. What you are requesting is asked for all the time; Guido decided against it a long time ago because constructions like: if c = 1: ... are almost certainly not what the programmer had in mind. C does the wrong thing; Python throws an error so the programmer can see what he or she did wrong immediately. > Also, where is this curious behaviour documented? 6.3 of the Language > Ref makes no reference to it. (Go on. Prove me wrong!) The simple fact that it's in section 6 (Statements) instead of 5 (Expressions) gives the answer. > Thanks. > -- > Dale Strickland-Clark > Riverhall Systems Ltd > -- > http://mail.python.org/mailman/listinfo/python-list > > From chrishbarker at home.net Thu Oct 18 13:22:27 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 18 Oct 2001 10:22:27 -0700 Subject: self naming class? References: Message-ID: <3BCF0FD3.16C62896@home.net> Luigi Ballabio wrote: > At 10:05 PM 10/18/01 +1000, Serge Rey wrote: > >i'm trying to create a class that assigns a name attribute in such a way > >that the name is set equal to the name of the instance. for example: > > > >test = MyClass() > > > >so that test.name == "test" > I see a phylosophical problem with the above, which is, "test" is not the > name of your instance but rather the name of a reference to such instance. Luigi is right, and while I'm sure that someone on this group could find a way to do it, you probably don't want to. What you need to do is step back and ask yourself why you want to so this at all. In general, having a link between the data and actual variable names can make it a little easier to think about the code, but takes away a lot of flexibility, and is ripe for the kind of problems that Luigi has pointed out, particularly in Python. When I want a bunch of instances to have useful names that I can refer to them by, I usually put them in a dictionary: d = {} dict["test"] = MyClass() dict["test2"] = MyClass() or if you want the instance to have a name atribute: thisname = "test" dict[thisname] = MyClass(name = thisname) Note, however, that I probably wouldn't do this (or what you have proposed) at all. If the object has a name attribute, than you don't want a duplication of data, there is too much of a chance of it getting mixed up. You might do: thisname = "test" instance = MyClass(name = thisname) dict[instance.name] = instance that way you are guaranteed that the names match. A good general rule is that if it is hard to do something in Python, you are probably trying to solve a problem in a non "Pythonic" way, and you should step back and find a more natural way to do it. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From l0819m0v0smfm001 at sneakemail.com Tue Oct 2 23:55:59 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Wed, 03 Oct 2001 03:55:59 GMT Subject: Python is better than free (was Re: GNU wars again) References: Message-ID: <3BBA56C4.9010904@sneakemail.com> Delaney, Timothy wrote > However, GPL is *not* extortion. The writer of a piece of code has every > right to want to protect, control or charge for it. > Not if you take Stallman (et al's) position seriously. I agree that GPL is not extortion, but that the writer of a piece of code has every right to want to protect, control, or charge for it is something that Stallman seems to regard as an unfortunate historical accident; the GPL is his best attempt to simulate a regime where that isn't true under the rules of a regime where it is. Even though I've released some of my Python work under the GPL, I'm coming around to Tim Peter's way of thinking: just release things into the public domain and have done with it. No worries about enforcing the license because no licence. "free"-as-in-"free"'ly yrs, Joshua From madsdyd at challenge.dk Mon Oct 1 09:23:34 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 15:23:34 +0200 (CEST) Subject: Problem with linking embedding C application In-Reply-To: <20011001150510.A2473@lilith.hqd-internal> Message-ID: On Mon, 1 Oct 2001, Gerhard H?ring wrote: > On Mon, Oct 01, 2001 at 02:40:19PM +0200, Mads Bondo Dydensborg wrote: > > > from distutils.sysconfig import get_config_var > > > print get_config_var("LIBS") + " " + get_config_var("SYSLIBS") > > > > Thanks, that is nice. > > > > Am I correct in assuming that this module is rather new? (I just checked, > > it does not seem to be present in Python 1.6, but is very much in 2.0). > > > > Where did you figure out about "LIBS" and "SYSLIBS" from? > > Hmm. I first read about the distutils.sysconfig in the Extending and > Embedding Chapter of the Python docs. Section 5.6 (Linking > Requirements). I have read that as well, - I read it as beeing about exporting symbols from extensions. > When I read your post, I thought there must a way > to figure it out with the distutils.sysconfig module. I confess I just > printed the result of get_config_vars() and compared that with what > ldd /usr/bin/python showed me. > > The LIBS and SYSLIBS stuff seem to come in fact from the Python Makefile > that distutils.sysconfig parses. OK - I will look for more interessting variables, then ;-) > > distutils-is-magic-ly yours, Thanks, Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk A series on the annoying idiosyncrasies of popular programs such as Windows, Word and Excel features irritating or irritated animals. Word 97 Annoyances sports a decidedly miffed opossum, while Windows 98 Annoyances gets a European common toad, covered with warts. - Elizabeth Weise, USA TODAY, on O'Reilly bookcovers From RevolvingDoors at btopenworld.com Wed Oct 10 19:04:00 2001 From: RevolvingDoors at btopenworld.com (Adrian Philpott) Date: Thu, 11 Oct 2001 00:04:00 +0100 Subject: YOU ARE ALL GAY! References: Message-ID: <9q2k92$2vd$1@plutonium.btinternet.com> Yeh, reckon I had better go get in the closet so I can come out of it! From rikard at strakt.com Mon Oct 15 02:00:53 2001 From: rikard at strakt.com (Rikard Bosnjakovic) Date: Mon, 15 Oct 2001 08:00:53 +0200 Subject: Cgi Counter References: Message-ID: <3BCA7B95.AEFDEE@strakt.com> Neal Irwin wrote: > Does anyone have sample code for a web-page hit > counter. I was curious what one would look like in > Python. I have made one in Perl and would like to > compare them. You can use some ugly hack like this: #!/usr/bin/env python import os.path FILE = "/tmp/counter" if not os.path.exists(FILE): c = 0 else: c = int(open(FILE).readline()) print c # increase the counter c = c + 1 open(FILE, "w").write(str(c)) Gives: >>> ## working on region in file /tmp/python-3601Dum... 0 >>> ## working on region in file /tmp/python-3601Q4s... 1 >>> ## working on region in file /tmp/python-3601dCz... 2 Cheers, Rikard From christy_girl99 at yahoo.com Sun Oct 28 01:26:38 2001 From: christy_girl99 at yahoo.com (christy_girl99 at yahoo.com) Date: Sun, 28 Oct 2001 05:26:38 -0000 Subject: binary search tress using classes Message-ID: <9rg4ue+r4bt@eGroups.com> Hi, I was wondering if anyone had a binary search tree module I could use? I need to write a program that counts the number of occurrences of each word in a file, and outputs the word and corresponding counts alphabetically. For example, if input is Have a nice day. Have a nice day. Have a nice day. Have a nice day. the output is a 4 day 4 have 4 nice 4 The code has to be modular based on classes. I'm thinking of making a tree node that looks like this bintree[ [key, data], left, right] , where I can traverse the tree by simply incrementing the current root to the appropriate child. temp = bintree.root temp = temp[1] #move to the left child. temp = temp[2] #move to the right child. but I don't know how to implement it correctly using classes. (i.e using def __init__(self), etc) I'm new to this python language so I would appreciate anyone's help. Thanks in advance :) Christy From pete at visionart.com Mon Oct 29 14:06:14 2001 From: pete at visionart.com (Pete Shinners) Date: Mon, 29 Oct 2001 11:06:14 -0800 Subject: detecting and creating directories References: <3BDDA7BC.8CF7C891@mitre.org> Message-ID: <3BDDA8A6.9070704@visionart.com> Angel Asencio wrote: > Greetings: > > I found the module that has the command to make directories, but I > have not been lucky finding a way to check for the existance of a > directory (so it is not there, I can create it). > > Any pointers? os.path.isdir() would be a likely starting place :] From jan at blackbox.hell Mon Oct 1 11:12:25 2001 From: jan at blackbox.hell (Jan Samohyl) Date: Mon, 1 Oct 2001 17:12:25 +0200 Subject: How do Java interfaces translate to Python? In-Reply-To: References: Message-ID: <20011001171225.A10925@blackbox.hell> On Sun, Sep 30, 2001 at 10:50:15PM +0000, Gordon Tyler wrote: > In article , Martin von Loewis wrote: > > What exactly is it that you do with interfaces in Java? > > I find myself unable to think of anything other than that. Which suggests > to me that perhaps interfaces aren't such a useful construct after all. ;) I have heard somewhere that in java one often uses interfaces where he would use multiple inheritance. Maybe this is the case. Regards, Jan Samohyl From sonyi at iae.re.kr Thu Oct 25 02:12:45 2001 From: sonyi at iae.re.kr (¼Õ¿µÀÏ) Date: Thu, 25 Oct 2001 15:12:45 +0900 Subject: [wxPython] How can I find wxPostScriptDC? Message-ID: <9r89k9$s18$1@news2.kornet.net> I cannot find wxPostScriptDC on latest version of wxPython. However, the help documents say that that is implemented in wxPython. How can I find wxPostScriptDC? Young-il Sohn IAE From fredrik at pythonware.com Mon Oct 22 16:44:04 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Oct 2001 20:44:04 GMT Subject: suggestion for module re References: <3BD3E830.3EC94E94@artenumerica.com> <3BD46B5E.5EFD1292@artenumerica.com> Message-ID: Jose Sebrosa wrote: > Anyway, it still remains the need of a function to travel through a string and > collect all the matches in one single object, *while preserving the names*. if you pass a callable object to the sub method, that object will be called with a match object for each match in the string. for example: import re class Scanner: def __init__(self, pattern): self.pattern = re.compile(pattern) def parse(self, string): self.result = [] self.pattern.sub(self.handler, string) return self.result def handler(self, match): # can be overridden self.result.append(match.groupdict()) return "" # must return string >>> scanner = Scanner('(?P
a|A)(?Pb|B)') >>> for item in scanner.parse('aBAb'): >>> print item {'b': 'B', 'a': 'a'} {'b': 'b', 'a': 'A'} this works with 1.5.2 and newer. to get custom behaviour, override the "handler" method. in Python 2.2, you can use the undocumented scanner object, together with an iterator, to loop over every match: >>> import re >>> p = re.compile('(?Pa|A)(?Pb|B)') >>> for match in iter(p.scanner('aBAb').search, None): >>> print match.groupdict() {'a': 'a', 'b': 'B'} {'a': 'A', 'b': 'b'} From sholden at holdenweb.com Wed Oct 31 13:51:38 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 13:51:38 -0500 Subject: Why 'self' ? References: <3BE04E7A.8E2CF101@ces.clemson.edu> Message-ID: "Schaefer, F." wrote ... > Hi all, > > It's been a while that I am working with Python and actually > the only thing I really do not like about it is 'self' in the > member function definitions as argument. If it > has to be there anyway, it is totally redundant to write it. > > So, why is self there ? > http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.007.htp regards Steve -- http://www.holdenweb.com/ From skip at pobox.com Tue Oct 16 08:50:13 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 07:50:13 -0500 Subject: fast sub list operations In-Reply-To: References: Message-ID: <15308.11525.102304.624520@beluga.mojam.com> Robin> I constantly miss some nice way to subset lists. As an example Robin> suppose I have a list of x y coordinates eg Robin> [x0,y0,x1,y1,.....] Robin> and wish to perform the operation x->x+v, y->y+w for the Robin> co-ordinates in the list I don't seem to be able to do this fast Robin> using map. I think most people will point you to NumPy. Robin> ... I don't seem to have an interlace to get back to the original Robin> list format. Check out the zip builtin function: >>> zip([1,2,3],[7,8,9]) [(1, 7), (2, 8), (3, 9)] -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From BPettersen at NAREX.com Thu Oct 25 15:47:02 2001 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Thu, 25 Oct 2001 13:47:02 -0600 Subject: Question: Dynamic code import Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215102@admin56.narex.com> > From: K?roly Ladv?nszky [mailto:aa at bb.cc] > > Hi, Hi > I've been experimenting with Python for a short period of > time and I really enjoy it. It allows me to do a lot of > things that are much harder or even not possible to > accomplish in other languages. I'd like to receive comments > on the following problems. Welcome > 1. Is it possible to 'import' Python code in a dynamic fashion? > > For instance, the running program refers to function f1 through ff: > > def f1(a): > return a*1.25 > > ff=f1 > > At some point, it turns out that f1(a) should return a*1.3+5. > If it was possible to insert a new function, the running > program could be modified like this: > > #--- this is to be 'imported' > def f11(a): > return a*1.3+5 > #--- > > ff=f11 > > Now ff(a) would produce results by using the new rule embodied in f11! Try it in the interpreter: >>> def f1(a): return a*1.25 ... >>> ff = f1 >>> ff(1) 1.25 >>> def f2(a): return a*1.3+5 ... >>> ff = f2 >>> ff(1) 6.2999999999999998 >>> > 2. Something is wrong with globals. Given the example below, > I'd expect 2 for the second print. You're misunderstanding the "global" directive. It is used inside a function to tell the interpreter that it should look for a given variable in the global scope: var = 1 def f(x): global var # look for var in global namespace var += x (the global directive is also only needed when assigning to the global, but you can probably forget that for now...) -- bjorn From johnroth at ameritech.net Sun Oct 14 11:44:49 2001 From: johnroth at ameritech.net (John Roth) Date: Sun, 14 Oct 2001 08:44:49 -0700 Subject: How to make a copy? References: <3bc9918a_2@news.newsgroups.com> <87elo6fid8.fsf@lisboa.ifm.uni-kiel.de> <3bc9a389_4@news.newsgroups.com> Message-ID: "Janos Blazi" wrote in message news:3bc9a389_4 at news.newsgroups.com... > > import copy > > a=copy.deepcopy(b) > > That does not work. I get many messages and at the end I get > "und-deep-copyable object: ". This means you need to do the copy yourself. In general, when you want a copy of a structure, what you really want is a copy of only part of the structure, and will be quite content with references to other objects. There's no way that a general utility can know that. See the documentation on deepcopy in the copy module. John Roth From clpy at snakefarm.org Mon Oct 8 04:42:28 2001 From: clpy at snakefarm.org (Carsten Gaebler) Date: Mon, 08 Oct 2001 10:42:28 +0200 Subject: String formatting with two dictionaries? Message-ID: <3BC166F4.5E7FAB08@snakefarm.org> Hi there! Given a string s = "%(foo)s %(spam)s" and two dictionaries d1 = {"foo": "bar"} d2 = {"spam": "eggs"} how would you apply d1 and d2 to s without modifying or explicitly copying one of the dicts? I mean, I don't like to d3 = dictionary(d1) d3.update(d2) s = s % d3 cg. From warkid at storm.ru Fri Oct 12 04:18:56 2001 From: warkid at storm.ru ( Kerim Borchaev ( WarKiD ) ) Date: Fri, 12 Oct 2001 12:18:56 +0400 Subject: Profiling PyOpenGL In-Reply-To: <000401c152bc$86741b90$0202a8c0@MikeySpace> References: <000401c152bc$86741b90$0202a8c0@MikeySpace> Message-ID: <3513.011012@storm.ru> Thanks you (and Georg) for clarifying this glutMainLoop thing. But I didn't quite understand this phrase: > forcing a request for a PyGame context in one of the OpenGLContext > tests (sorry for sounding dumb but I'm just starting to learn (Py)OpenGl ) Best regards, Kerim mailto:warkid at storm.ru Friday, October 12, 2001, 5:23:38 AM, you wrote: MF> Profiling the GLUT mainloop is rather difficult, as it's a C loop that only MF> returns by executing a sys.exit (as mentioned by Georg). You can, however, MF> profile a PyGame-hosted PyOpenGL project fairly readily (PyGame doesn't have MF> a native-code mainloop and it's Python one(s) can easily return as a normal MF> function would). I tested by forcing a request for a PyGame context in one MF> of the OpenGLContext tests and then using profile.run to call MainLoop. MF> Of course, swapping contexts is sometimes not an option, but if you're early MF> in the project and PyGame is available on your platforms, using it might MF> work for you. MF> HTH, MF> Mike MF> BTW, posting to the SourceForge PyOpenGL list is probably the fastest way to MF> get a response on PyOpenGL-specific questions like this. MF> -----Original Message----- MF> From: python-list-admin at python.org MF> [mailto:python-list-admin at python.org]On Behalf Of Kerim Borchaev ( MF> WarKiD ) MF> Sent: October 11, 2001 04:03 MF> To: python-list at python.org MF> Subject: Profiling PyOpenGL MF> Hello python-list, MF> why can't I profile PyOpenGL application using profile module? MF> ... MF> but it prints nothing unless I remove glutMainLoop call. MF> Best regards, MF> Kerim mailto:warkid at storm.ru MF> -- MF> http://mail.python.org/mailman/listinfo/python-list From thomas.heller at ion-tof.com Tue Oct 2 08:55:38 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Tue, 2 Oct 2001 14:55:38 +0200 Subject: doc strings and efficiency References: Message-ID: <9pcdga$hsch8$1@ID-59885.news.dfncis.de> > Documentation strings, as they are available at runtime, increase the > memory requirement of the running python process. Currently, I have memory to > burn in the environments that I code on, but if I want to use Python in an > environment where memory is very tight, I find myself suddenly wondering if I > should use docstrings. > I'd like to, as they are a great feature of the language, but a "would be > nice" feature in the interpreter would be an option to ignore them, so that > under tight conditions I could shut them off, but still have them in the > source code for debugging on boxes where I'm not under those tight > restrictions. > Does anyone know of any plans for such a feature? Any counter-arguments > for why this would not be necessary? The time machine strikes again: python -h prints (among other stuff): -O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x) -OO : remove doc-strings in addition to the -O optimizations Thomas From joseph at arbitrary.org Wed Oct 17 15:27:52 2001 From: joseph at arbitrary.org (Joseph Santaniello) Date: Wed, 17 Oct 2001 12:27:52 -0700 Subject: Help optimize a script? In-Reply-To: References: Message-ID: Thanks for the tips. These are going to make a big difference, I'm sure. Joseph PS: I'll change my anti-spam strategy. Since my email address is cryptic enough as it is, I should make it more clear how to change it to make it valid. On Wed, 17 Oct 2001 at 13:20, Skip Montanaro wrote: > > Joseph> First, does anyone know of a tool that does this so I don't have > Joseph> to reinvent the wheel, and barring that, can anyone offer some > Joseph> tips on how to optimize this code > [snip] > Joseph> Any suggestions on how to speed this up? > > First suggestion: check out the xreadlines module if you are using a pre-2.2 > version of Python. If you are using 2.2 already you can just loop over the > file object because it implements the iterator protocol: > > for line in sys.stdin: > ... > > (xreadlines might still be faster because of buffering, you'll have to > check to be sure.) > > Second suggestion: make "new" a list and either just append to it (starting > with new being an empty list): > > new = [] > for index ...: > new.append(string.strip(...)) > ... > > or set the index in new explicitly (starting with new being a list of > appropriate length filled with None): > > new = [None] * len(indecies[sys.argv[1]]) > for index ...: > new[index] = string.strip(...)) > ... > > When you want to print the result just join the list: > > print "".join(new) > > or > > print string.join(new, "") > > Third (minor) suggestion: if you are using a version of Python with string > methods (to check, does executing "print ''.join" work?), skip string.strip > and just use the strip() method of the string you're manipulating. > > Fourth suggestion: to allow people to respond directly to you, don't try and > disguise your email address. I couldn't tell what I needed to do to get > email to you (delete "no-spam"? change "someone" to something else? change > "arbitrary" to something else?), so I just punted and am simply replying to > the list. > > From jeff at ccvcorp.com Wed Oct 10 19:07:27 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 10 Oct 2001 16:07:27 -0700 Subject: Newbie Question References: <9pp1ca$ca6$1@slb4.atl.mindspring.net> <3bc0155f_8@news.newsgroups.com> Message-ID: <3BC4D4AE.9019F5F6@ccvcorp.com> Janos Blazi wrote: > (3) > >>>from string import * > then you can use +every+ function from string without the "string."-prefix > A word of warning about this idiom, though--it has several serious drawbacks. First, it makes your code harder to understand, because it's not apparent where you're getting your functions from. When someone is reading through your code, they have no way of knowing if a given function is a builtin, defined elsewhere in that module, or from the string module (or whatever other modules you may have imported this way). Second, if you are working interactively, it becomes difficult to use any changes you make to a module. In order to have changes take effect, you need to 'reload(module)', but if you've done 'from module import ...', then there's no module name to reload. Finally, and most importantly, this is a good way to "lose" functions. Suppose you have a module "utils" which has a function "list()", that returns a list of whatever you're working with. You can import this module the normal way, 'import utils', and then call your function 'mylist = utils.list()', and all is well. But if you import it by 'from utils import *', then you refer to the function like 'mylist = list()'. However, there's a built-in function list(), which is normally called in that same way. Now you've hidden that built-in function, and can no longer call it. (Technically, it is possible to call it as __builtin__.list(), but this is ugly and not good practice to rely on...) In short, it really is best, in 99% of all circumstances, to use 'import module', 'module.function()' syntax. There are a few modules that are specifically designed to be used as 'from x import *' (e.g., Tkinter and wxPython), but they are definately the exception, and it's not a good idea to get in the habit of using that syntax regularly. Jeff Shannon Technician/Programmer Credit International From rdacker at pacbell.net Wed Oct 17 16:19:33 2001 From: rdacker at pacbell.net (rdack) Date: 17 Oct 2001 13:19:33 -0700 Subject: [OSX] where python files go? Message-ID: <644f6688.0110171219.656a56@posting.google.com> i put an html file to get login info from user in /Users/bobacker/Sites. i get there ok. where do i point the form action to find my python file? where should my python file be? is there a cgi-bin directory on os x? a correct place to create one? From sdm7g at Virginia.EDU Wed Oct 31 13:31:38 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Wed, 31 Oct 2001 13:31:38 -0500 (EST) Subject: Freeware Python editor In-Reply-To: <20011031210948.W21151@phd.pp.ru> Message-ID: On Wed, 31 Oct 2001, Oleg Broytmann wrote: > On Wed, Oct 31, 2001 at 01:08:15PM -0500, Steven D. Majewski wrote: > > > > You said you didn't want to start another GNU flamewar. But what do you > > > > think you're doing? > > > > > > Trying to stop you arguing :) > > > > That's not an argument. > > It's merely a negation. > > I paid for an argument! > > I am not selling free software. Even less *arguments* about free > software. > Are Too! From grante at visi.com Tue Oct 2 14:47:33 2001 From: grante at visi.com (Grant Edwards) Date: Tue, 02 Oct 2001 18:47:33 GMT Subject: curses vs slang References: Message-ID: In article , Marco Mariani wrote: > > I'm about to write a tty data-entry application on Linux. > > Do you think I should go for the ncurses or the slang wrapper? If I were you, I'd pick a high-level library like newt (uses newt/slang) or something similar for ncurses (is there a Python interface to CDK?). If you're rolling your own widgets, then I think ncurses is more heavyweight. -- Grant Edwards grante Yow! Spreading peanut at butter reminds me of visi.com opera!! I wonder why? From jlh at home.com Tue Oct 23 00:34:12 2001 From: jlh at home.com (Jeff Hinrichs) Date: Mon, 22 Oct 2001 23:34:12 -0500 Subject: Error Handling Resources Message-ID: <007c01c15b7b$f7381f80$6702a8c0@gato> I am relatively new to Python coding and have written some small applets but now I'm moving on to some bigger projects. I am searching for a good resource on error handling in Python. Would anyone on the list care to nudge me in the direction of an URL or book? thanks, Jeff From madsdyd at challenge.dk Mon Oct 1 07:43:10 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 13:43:10 +0200 (CEST) Subject: Python embedding & question about autoconf and dynamic linking In-Reply-To: Message-ID: On Mon, 1 Oct 2001, Olivier Deme wrote: > > I think it is more common to extend Python, than to embed it. I knew > > nothing about Python (apart from the name) a week ago, so I may be wrong > > though. > > Same for me. :-) I just found this page http://www.mcmillan-inc.com/embed.html Hmm. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk You know you're a Linux geek when... You can reconstruct your fstab from scratch, and not even think about it. - segfault From jp at NOSPAMdemonseed.net Wed Oct 31 15:43:33 2001 From: jp at NOSPAMdemonseed.net (jason petrone) Date: Wed, 31 Oct 2001 20:43:33 +0000 Subject: Nicer Tkinter on UNIX? References: <3BBCAF3D.C9EE4712@home.net> Message-ID: Artur Skura wrote: > I fully appreciate and share your opinion, but I have to write something > for folks who are completely clueless. I don't think they will be able to > install additional libraries. There once was a time when any hip X11 program looked like NeXT. Since a few people wrote some hip TCL/Tk programs they got the bright idea to create a version of Tk that looked like NeXT. I don't think it is still actively maintained, but Tkstep looks a lot better than standard Tk(if you like NeXT). It should be a clean replacement for Tk in python. http://freshmeat.net/projects/TkSTEP/ This requires installing extra system libraries though, though not extra python libaries. jason From greg at cosc.canterbury.ac.nz Thu Oct 25 22:27:02 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 26 Oct 2001 15:27:02 +1300 Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> Message-ID: <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> Terry Reedy wrote: > > An so it is. If the patterns do not match, an exception is raised. > However, after the match, the names (in your example above) 'time', > 'status', 'value', and 'boring' are then bound to the corresponding > objects in the current namespace. In the case in question, i.e. () = () the patterns clearly do match. And, every name in the LHS has a corresponding value in the RHS. The numbers of both these things happen to be 0, but so what? I think Michael Abbot is quite right. There's no reason this shouldn't be a legitimate, albeit degenerate, case of tuple unpacking. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From kalle at gnupung.net Tue Oct 2 16:30:29 2001 From: kalle at gnupung.net (Kalle Svensson) Date: Tue, 2 Oct 2001 22:30:29 +0200 Subject: comparing interpreter speed on two platforms In-Reply-To: References: Message-ID: <20011002223029.A8109@sandrew.lysator.liu.se> [Chris Liechti] > i have run a simple benchmark on two systems: [snip] > why is the python programm that much slower than the BogoMips comparison > would imply? What do you think "bogo" in bogomips stands for? Think about it. Peace, Kalle -- [ Thought control, brought to you by the WIPO! ] [ http://anti-dmca.org/ http://eurorights.org/ ] From chrishbarker at home.net Tue Oct 30 15:38:00 2001 From: chrishbarker at home.net (Chris Barker) Date: Tue, 30 Oct 2001 12:38:00 -0800 Subject: os.listdir References: <3BDEE6C6.8E96DBF3@ncsa.uiuc.edu> Message-ID: <3BDF0FA8.3D37194C@home.net> Randy Heiland wrote: > I get this: > > >>> for file in os.listdir('mydir'): > ... print file > ... > f100.dat > f1.dat > f2.dat > > but would like this: > f1.dat > f2.dat > f100.dat I use file names like: f001.dat f002.dat f100.dat Just to avoid this issue. It is not a Python issue at all. However, if you don't have control over the file names, others have offered good suggestions... -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From gabriel_ambuehl at buz.ch Tue Oct 23 14:32:19 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Tue, 23 Oct 2001 20:32:19 +0200 Subject: programming unlimited "categories" in python ? In-Reply-To: <5.1.0.14.0.20011023134155.026dc008@imap.hq.movilogic.com> References: <5.1.0.14.0.20011023130239.088b9768@imap.hq.movilogic.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> <5.1.0.14.0.20011023130239.088b9768@imap.hq.movilogic.com> <5.1.0.14.0.20011023134155.026dc008@imap.hq.movilogic.com> Message-ID: <33186660193.20011023203219@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello Lucio, Tuesday, October 23, 2001, 6:49:03 PM, you wrote: >>You still need a link between the two, else you haven't got any >>chance >>to match them anyway so why not just build the region tree and >>store all the data under it? then you query for africa first and >>fetch only the results which have got the attribute deadly in 5 >>hours? > you can match them using intersections. you get all the children > for every node in all the categories you want, then intersect them > all. But you can only intersect them if you have some additional information about which apply to which hence you need some kind of link. >>I wasn't thinking about the implementation itself but mostly about >>suitable approaches. IMHO, you should try to squeeze your data >>model into ONE tree and the problem is almost solved. > so you do this tree: > africa - ->> mozambique - -- >> capital - ---->> deadly - ------>> really deadly - ------>> not so deadly - --->> deadly - ----->> really deadly - ----->> not so deadly - -->> deadly - ---->> really deadly - ---->> not so deadly - ->> deadly - --->> really deadly - --->> not so deadly > but suppose you suddently have cases of a kinda deadly thing. you > have to edit the whole tree! Why? Personally, I'd simply save the deadly stuff in a string (or even integer) so I can easily add another mode if need be. > but you can have that if you hard code the tree. but what if you > have some subset (really deadly, or spooky deadly.. or whatever, in > the query you are doing) and want to find out the africa tree? I think Python's polymorphism allows for a not so hard coded kind of tree as Python won't care what type of object you put into data... Best regards, Gabriel b -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO9Wpp8Za2WpymlDxAQGgeAf+IknX8DozdjypiZxT3NO1zcyYGT93nS3N mVqDKQ/wMdZv9ZsqxGskf9SaRBv2Wfin+Dz9foCZOXqUe4ynicp6QcU0RFB7DTYc jWDfKXx+hJVYWjGjrNlrv0KQudqzxfyrOJ8igxZEgy3x2g28sXnIi84uCqwE8wLQ xA9mKel0C4liNXs/BwVy+eavdBqwds8JSnL4Pu7xlaA+BokAfoW8AB6vf6Kn7OkR y1gZIzNAQk8swMOuJd44NEuwSfSQCS7Ha98AMsybtSNIwf0FrqYw8yWcvetxX5lk wBEnY27c7t+eXXqSkWmS4MqJngAzcI/U/wetymQFJrNtIkJZl1OB2A== =A57+ -----END PGP SIGNATURE----- From Pieter_Claerhout at CreoScitex.com Tue Oct 23 10:00:22 2001 From: Pieter_Claerhout at CreoScitex.com (Pieter Claerhout) Date: Tue, 23 Oct 2001 16:00:22 +0200 Subject: My modules doesn't seem to reload in IIS asp pages Message-ID: <490316A24CC5D411ACD700B0D078F7F001031C58@cseexch01.cse.creoscitex.com> Try to change the code to: <%@ LANGUAGE="Python"%> <% from marcipan.Receipees import Receipees, Categories reload(Receipees) reload(Categories) # stuff rcps = Receipees() id = Request(rcps.getKey()) if str(id) != 'None': rcp = rcps.getOneById(id) else: rcp = rcps.getNew() %> Should work fine that way... Pieter -----Original Message----- From: Max M [mailto:maxm at normik.dk] Sent: Tuesday, October 23, 2001 3:55 PM To: python-list at python.org Subject: My modules doesn't seem to reload in IIS asp pages I am writing .asp pages with Python, and my modules doesn't seem to reload. I see changes i make in the html when editing the page, but changes I make in the modules does not go through. Isn't this correct? <%@ LANGUAGE="Python"%> <% import marcipan reload(marcipan) from marcipan.Receipees import Receipees, Categories # stuff rcps = Receipees() id = Request(rcps.getKey()) if str(id) != 'None': rcp = rcps.getOneById(id) else: rcp = rcps.getNew() %> Win2K, SP2, Python2.11 regards Max M -- http://mail.python.org/mailman/listinfo/python-list From nde at comp.leeds.ac.uk Thu Oct 4 07:04:49 2001 From: nde at comp.leeds.ac.uk (Nick Efford) Date: Thu, 4 Oct 2001 11:04:49 GMT Subject: problem with FFT from Numeric 20.2.0 Message-ID: I'm trying to build a working Numeric 20.2.0 from source using GCC 3.0 on a Linux system running Python 2.1. The FFT module is causing problems at present; when attempting to import, I get >>> import FFT Fatal Python error: can't initialize module fftpack Abort and Python crashes. Can anyone suggest what is causing this, or possible fixes? Thanks, Nick From pih at oek.dk Sat Oct 6 08:30:09 2001 From: pih at oek.dk (Peter I. Hansen) Date: Sat, 06 Oct 2001 14:30:09 +0200 Subject: PyML Message-ID: <3BBEF951.BEECA468@oek.dk> Hi I'm trying to get PyML installed on my FreeBSD 4.3-rel. (www.pyml.org) I've followed the instruktions, but the embedded code is not translated. Have anyone here tried this package ? /Peter From ignacio at openservices.net Wed Oct 10 20:19:46 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 10 Oct 2001 20:19:46 -0400 (EDT) Subject: re.group vs re.groups In-Reply-To: Message-ID: On Thu, 11 Oct 2001, Huaiyu Zhu wrote: > Hi, I'm puzzled by the behavior of the group and groups attributes of the re > match objects. Why would b.group(0) below return the entire match string? > > Python 2.1 (#1, Oct 2 2001, 15:35:43) > [GCC 2.95.2 19991024 (release)] on linux2 > >>> import re > >>> start = re.compile("^\[(\d{4})\] ") > >>> b = start.match ("[0256] ") > >>> b > > >>> b.group() > '[0256] ' > >>> b.group(0) > '[0256] ' > >>> b.groups(0) > ('0256',) > >>> b.groups() > ('0256',) > >>> b.groups()[0] > '0256' Because that's what it does. Subgroup matches start at 1. .groups() has subgroup 1 as element 0, subgroup 2 as element 1, etc. -- Ignacio Vazquez-Abrams From opengeometry at yahoo.ca Sat Oct 6 01:59:31 2001 From: opengeometry at yahoo.ca (William Park) Date: Sat, 06 Oct 2001 05:59:31 GMT Subject: Quaternions in Python References: Message-ID: <75xv7.4150$oI4.142736@news.eol.ca> David Feustel wrote: > Is there a Python module that does quaternion math? I don't think so. I'm not too familiar with quaternion math, but you could probably implement it yourself as tuple with class frontend. -- William Park, Open Geometry Consulting, 8 CPU cluster, Linux (Slackware), Python, LaTeX, Vim, Mutt, Tin From drew_csillag at geocities.com Tue Oct 30 11:25:06 2001 From: drew_csillag at geocities.com (Drew Csillag) Date: Tue, 30 Oct 2001 11:25:06 -0500 Subject: [ANN] SkunkWeb 3.1.3 released! Message-ID: <20011030112506.H1163@localhost.localdomain> Release 3.1.3 of The SkunkWeb Web Application Server has just been released. The release is available from the SkunkWeb home page at http://skunkweb.sourceforge.net or directly from http://prdownloads.sourceforge.net/skunkweb/skunkweb-3.1.3.tgz What's new? (from 3.1) ------------------------------ * remote component fixes * doc updates * caching fixes * misc output fixes * Now have a CGI adaptor -- swcgi. See docs for details Very best wishes to all, -Drew From rclilly at nospam.lvcm.com Tue Oct 30 11:14:06 2001 From: rclilly at nospam.lvcm.com (Robert Lilly) Date: Tue, 30 Oct 2001 08:14:06 -0800 Subject: [Tutor] DNS module or how to ... ? References: Message-ID: "Danny Yoo" wrote in message news:mailman.1004416135.1869.python-list at python.org... > On Mon, 8 Oct 2001, A wrote: > > > Is there a DNS module available for Python ? > > There are a few resources you can use if you're looking for Python > modules. One of the best ones is the Vaults of Parnassus: > > http://www.vex.net/parnassus/ > > which collects links for a bunch of stuff. Wow! What a great resource! Thank you to whomever put this site together. Thanks! RCLilly From webmaster at itareview.com Sun Oct 7 19:47:38 2001 From: webmaster at itareview.com (Itareview.com) Date: Mon, 8 Oct 2001 01:47:38 +0200 Subject: OT - Itareview.com Message-ID: <9pqojd$pn4$1@fe1.cs.interbusiness.it> Scrivi la recensione del tuo sito e pubblica gratuitamente su www.itareview.com! Write a review of your site and put it for free on www.itareview.com! From phd at phd.pp.ru Tue Oct 2 06:35:25 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 2 Oct 2001 14:35:25 +0400 Subject: '%r' docs In-Reply-To: ; from pearu@cens.ioc.ee on Tue, Oct 02, 2001 at 12:24:29PM +0200 References: Message-ID: <20011002143525.H18126@phd.pp.ru> On Tue, Oct 02, 2001 at 12:24:29PM +0200, Pearu Peterson wrote: > To my pleasing surprice I discovered (from some python code, not > mine) that '%s'%(repr(obj)) has shorter form '%r'%(obj). > > Though I scanned Python 2.1 docs in order to find some backing for this > discovery, I found non. > > So, is this undocumented feature (and therefore may disappear in > future??)? Or could some one point out where are the fancy output formats > documented beside in the Tutorial. http://www.python.org/doc/current/lib/typesseq-strings.html Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From palm at gmx.net Thu Oct 18 07:41:16 2001 From: palm at gmx.net (Mathias Palm) Date: 18 Oct 2001 13:41:16 +0200 Subject: Python 2.1 with Tix under Windows References: <3BCC5191.399932D@gmx.net> Message-ID: <874roxw4yr.fsf@gmx.net> Found a working solution. Is not nice however. Download an extra tcl/tk package and install. Download Tix package and install in ...\Python21\tcl _and_ ...\tcl\lib I used Python 2.1, tcl 8.3 and Tix 8.0. I hope Tix will be included in the Python 2.2 package. Mathias From rnd at onego.ru Sun Oct 7 08:06:16 2001 From: rnd at onego.ru (Roman Suzi) Date: Sun, 7 Oct 2001 16:06:16 +0400 (MSD) Subject: Tkinter window minsize question Message-ID: I am wondering why when I execute the following piece of code after BUTTON1 is pressed top level window become less than specified minsize: ------------------------------------------------------------ #!/usr/bin/env python from Tkinter import * root = Tk() root.minsize(600, 400) def to_f2(): f1.pack_forget() f2.pack(fill=BOTH, expand=1) # prepare frame 1 f1 = Frame(root) b1 = Button(f1, text="BUTTON1", command=to_f2) b1.pack(fill=BOTH) # pack frame 1 f1.pack(fill=BOTH, expand=1) # prepare frame 2 f2 = Frame(root) b2 = Button(f2, text="BUTTON2", command=root.destroy) b2.pack(fill=BOTH) l2 = Label(f2, text="Label") l2.pack(fill=BOTH) root.mainloop() ---------------------------------------------------------- While when I resize it manually (to the greater size) it remains in tact. What is wrong? Sincerely yours, Roman Suzi -- _/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/ _/ Sunday, October 07, 2001 _/ Powered by Linux RedHat 6.2 _/ _/ "How come there's only one Monopolies Commission?" _/ From max at alcyone.com Thu Oct 4 15:04:48 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 04 Oct 2001 12:04:48 -0700 Subject: Mutable default values for function parameters References: <7da8d8f8.0110040056.42443bb@posting.google.com> <3BBCA084.B10B6061@alcyone.com> <0T1v7.4$rq1.2363@atlpnn01.usenetserver.com> Message-ID: <3BBCB2D0.D764F7A7@alcyone.com> Steve Holden wrote: > I've used this idiom myself many times. I eventuallu decided it was > shorter > as > > def sample(x, d = None): > d = d or [] > d.append(x) > print d > > but this looks so weird I'd appreciate confirmation that it's a valid > replacement. d would be replaced with a new empty list if it evaluated to false, rather than only if it is the sentinel value (in this case, None). There _is_ a difference there, since lots of things can evaluate to false, not just None. Plenty of non-lists evaluate to false (zeroes, empty strings, etc.). More importantly, though, empty sequence objects evaluate to false. Even in this case, you can come up with a case that would be unexpected. With your definition above, consider: >>> l = [1, 2] >>> sample(3, l) [1, 2, 3] >>> l [1, 2, 3] >>> l = [] >>> sample('a', l) ['a'] >>> l [] l is an empty list so it evaluates to false, and so your hack replaced it with a new, local list. That probably isn't what was intended. I'm all for replacing wordy idioms with shorter, equivalent ones to save typing and to increase clarity, but in this case it decreases clarity and actually means something (subtly) different. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Magnificent desolation. \__/ Buzz Aldrin (on the Moon) Alcyone Systems / http://www.alcyone.com/ Alcyone Systems, San Jose, California. From phr-n2001d at nightsong.com Tue Oct 30 21:33:23 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 30 Oct 2001 18:33:23 -0800 Subject: python development practices? References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: <7x3d40sfm4.fsf@ruckus.brouhaha.com> Peter Wang writes: > >Well, there's cheesy data hiding in the sense that instance variables > >whose names begin with underscores are difficult to reach from other > >modules. > > well... kind of. but short of naming all my private variables "_foo" > and hacking around the problem, there's no way to prevent lazy > programmers from touching all of your classes's data members. i know > this is not python's paradigm, but OTOH this is something that has to > be dealt with in a production environment... Yeah, it's better than nothing, but as I said, it's cheesy. I tend to have very few private variables. If I want a bunch of variables I make them attributes of a class instance, instead of class variables _a, _b, and _c, I prefer to have just one variable _x, with attributes _x.a, _x.b, and _x.c. That helps some. > as an aside, and i don't mean to sound obnoxious, but why did guido > not put in data hiding into python at an earlier stage? my colleague > whose background on generic programming comes entirely from the STL > points this "wart" out as one of python's largest, and brings up the > good point that data hiding was well known to the OOP world at the > time of python's first incarnations. IMO a bunch of the frustration I sometimes feel with Python comes from its originally being intended as a "glue" language. It's too good for that, and finds itself used as a work horse or even a race horse. Neither type of horse belongs in the glue factory ;-). > >If by "interfaces" you mean Java-like interfaces, that's a bogus > >criticism since Python supports multiple base classes, which let > >you do the same things and then some. > > nope, didn't mean Java interfaces. just meant some clean way to > define contracts between callers and functions. static typing is an > interface mechanism. if python had an elegant language-level > construct for defining basic contracts, it would be a boon to (1) > compile-time debugging and (2) design by contract in python. I wrote a really simple assert-like function, def _check(condition, msg='check fails'): if not condition: raise SomeError, msg and use it to enforce all kinds of conditions on input values, etc. Semantically it's nearly a do-nothing but again, it feels much cleaner than using if statements. I have tons of these sprinkled through my code. > actually that was the least of my worries. :-) if could just > guarantee code coverage on the stuff i write, i'd be happy! i have to > be honest: i haven't done much with trace.py or pylint. but my > original question was much more about development practices with > python: coding specs, docstring conventions, module import rules, etc. > i can read PEPs and documentation as well as the next guy, but > development practices - there, i haven't got a clue. You might look at the actual code of big systems written in Python, such as Zope, Twisted Matrix, etc. > >I don't know about Python, but large systems have been built in Lisp, > >and there have been some studies too. Lisp's runtime semantics are > >fairly similar to Python, though the development environments are > >far more highly evolved. > > can you point me to some of these studies? or at least a list of > google keywords? :-) > > -peter Here's one that got some attention recently: http://www-aig.jpl.nasa.gov/public/home/gat/lisp-study.html From tim at bladerman.com Wed Oct 31 20:33:00 2001 From: tim at bladerman.com (Tim Gahnström /Bladerman) Date: Thu, 01 Nov 2001 01:33:00 GMT Subject: accessing a web search engine References: <9rq340$1hfc@r02n01.cac.psu.edu> Message-ID: Hi I am guessing bigtimes here so dont take this as a fact. There might verry well be a much easier solution but I see that the post have been out a while and none have answered so I thought that you might be able to make, atleast, a little bit of use of my humble opinion. A javascript is normaly executed by a java-script executor, normaly that is IE or netscape. But maybe they use a standalone program or activeX control or something to execute it than it should be possible for you to execute that program with the javascript code right? Maybe they use something internal, then your hope is that it might be a python javascript module. I think there is a Html module so maybe there is a java-script module. Maybe you could see what the javascript on the webpage really do. Does it just format the inqiery a little bit and then send it's message to a CGI-program? if that is the case you can do the processing in your program and then call the CGI. In essense, rewrite the javascript in Python. Gl, hope it helps Tim Gahnstr?m ----- Original Message ----- From: "Rajarshi Guha" Newsgroups: comp.lang.python Sent: Thursday, November 01, 2001 12:57 AM Subject: accessing a web search engine > Hi, > I'm trying to use Python to send queries to a webpage and analyse the > results. However the search engine does'nt use cgi scripts - it uses a > Javascript function. How can I access a JScript function. I realize that > this is not really a Python question, but since I am using it I thought I'd > ask here. I know that I have to use the urllib module but what string do I > send to the server? > > TIA > -- > ------------------------------------------------------------------- > Rajarshi Guha | email: rajarshi at presidency.com > 152 Davey Laboratory | web : www.rajarshi.outputto.com > Department of Chemistry | ICQ : 123242928 > Pennsylvania State University | AIM : LoverOfPanda > ------------------------------------------------------------------- > GPG Fingerprint: DCCB 4D1A 5A8B 2F5A B5F6 1F9E CDC4 5574 9017 AF2A > Public Key : http://pgp.mit.edu/ > ------------------------------------------------------------------- > All syllogisms have three parts, therefore this is not a syllogism. > From sdm7g at Virginia.EDU Wed Oct 31 13:08:15 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Wed, 31 Oct 2001 13:08:15 -0500 (EST) Subject: Freeware Python editor In-Reply-To: <20011031210158.V21151@phd.pp.ru> Message-ID: On Wed, 31 Oct 2001, Oleg Broytmann wrote: > On Wed, Oct 31, 2001 at 09:45:25AM -0800, Erik Max Francis wrote: > > You said you didn't want to start another GNU flamewar. But what do you > > think you're doing? > > Trying to stop you arguing :) > That's not an argument. It's merely a negation. I paid for an argument! -- Steve Majewski From clpy at snakefarm.org Fri Oct 5 10:48:16 2001 From: clpy at snakefarm.org (Carsten Gaebler) Date: Fri, 05 Oct 2001 16:48:16 +0200 Subject: Boy do REs ever suck sometimes... References: Message-ID: <3BBDC830.E9B69E01@snakefarm.org> Richard Jones wrote: > Hrm - perhaps the ref could have a note in it to explain that "$" will do > some sort of automagic lookahead for a newline, and that if you don't want > that, then use '\Z'? The truth, the whole truth and nothing but the truth about "$" is hidden in http://www.python.org/doc/current/lib/Contents_of_Module_re.html under "MULTILINE": 'By default, "^" matches only at the beginning of the string, and "$" only at the end of the string and immediately before the newline (if any) at the end of the string.' Perhaps this should be moved to some more visible place? cg. From thomas.heller at ion-tof.com Fri Oct 5 13:55:54 2001 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Fri, 5 Oct 2001 19:55:54 +0200 Subject: daemon threads Message-ID: <9pks7b$j820d$1@ID-59885.news.dfncis.de> I'm using a background thread running all the time. Sometimes when Python exits I get a traceback like this: Unhandled exception in thread: Traceback (most recent call last): File "c:\python21\lib\threading.py", line 393, in __bootstrap self.__stop() File "c:\python21\lib\threading.py", line 399, in __stop self.__block.notifyAll() File "c:\python21\lib\threading.py", line 235, in notifyAll self.notify(len(self.__waiters)) File "c:\python21\lib\threading.py", line 217, in notify me = currentThread() TypeError: object of type 'None' is not callable This traceback does not appear when I register an atexit function to stop the thread. Is this behaviour intended, or am I doing something wrong? I would have the impression that daemon threads would have to cleanup themselves... Thomas From anthony at interlink.com.au Tue Oct 16 08:40:36 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 16 Oct 2001 22:40:36 +1000 Subject: python2.1 SEGV on Solaris 2.7 Message-ID: <200110161240.f9GCeaw20563@mbuna.arbhome.com.au> I've got a Zope installation where python2.1 is segfaulting on Solaris2.7 - it's running a largish ZEO server. The tail of the gdb output is: #128 0x26164 in PyEval_CallObjectWithKeywords () #129 0x264c0 in PyEval_CallObjectWithKeywords () #130 0x26140 in PyEval_CallObjectWithKeywords () #131 0x25fc0 in PyEval_CallObjectWithKeywords () #132 0x517bc in PyInstance_New () #133 0x261a4 in PyEval_CallObjectWithKeywords () #134 0x25fc0 in PyEval_CallObjectWithKeywords () #135 0x42c90 in initgc () It's built with $ gcc -v Reading specs from /opt/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs gcc version 2.95.2 19991024 (release) which is a bit old. Has anyone seen anything like this? I'm going to rebuild with gcc3.0 and also try turning off GC. Any help appreciated. Anthony From phr-n2001d at nightsong.com Wed Oct 31 18:12:44 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 31 Oct 2001 15:12:44 -0800 Subject: Running phyton on 50Mips RISC doable? References: <9rovil$fei$1@news1.xs4all.nl> Message-ID: <7x668vtndf.fsf@ruckus.brouhaha.com> 50 mips is plenty for most Python scripting purposes. However, you'll need quite a bit of memory, like several hundred k minimum. You might look at Pippy at www.python.org for a small implementation. It still might be too big for your application. From sholden at holdenweb.com Fri Oct 19 14:00:38 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 19 Oct 2001 14:00:38 -0400 Subject: Database Sessions and Transactions References: Message-ID: "DeepBlue" wrote in message news:tt0os832km0dbb at corp.supernews.com... > I am working on a CGI program in Python that connects to an Oracle database. > I am wondering on how to implement a transaction that belongs to a database > connection so that everything that belongs to the transaction can be rolled > back. Maybe this is a semantic thing. What you think of as a "session", I suspect, the DB-API refers to as a "connection". But Oracle isn't my first( or second) database platform, so don't take that as gospel. > In other words, the scope of the rollback is NOT the database connection BUT > the transaction that is defined from within the database connection. On any given connection, once you call the commit() method of that connection every change that has been made using that connection is now committed to the database, and further interactions take place in a new transaction. Similarly, if you call the rollback() method, every change made using that connection since the last commit() or rollback() call will be undone. > Please note that Python DB API 2 talks of a transaction as belonging to the > scope of the database connection, and not something that can be created > independently from the Connection. A transaction is a sequence of interactions with an RDBMS over a single connection. It is terminated (successfully) by calling commit(), or (unsuccessfully) by calling rollback(). At this point a new transaction begins. > Also, I can find no reference in Python DB API 2 to Sessions. How do we > manage different sessions/connections? Perhaps you now have enough information to clarify the difference between a "session" and a connection, so we can answer your question more fully? regards Steve -- http://www.holdenweb.com/ From lac at strakt.com Tue Oct 23 13:19:21 2001 From: lac at strakt.com (Laura Creighton) Date: Tue, 23 Oct 2001 19:19:21 +0200 Subject: Tkinter entry field question Message-ID: <200110231719.f9NHJLHf023928@ratthing-b246.strakt.com> Tkinter Entry fields have a width but not a height. If you don't like the height they come in, and know what height you want, how do you change them? Laura Creighton From sholden at holdenweb.com Thu Oct 4 18:08:30 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 18:08:30 -0400 Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> <9pimak$c22$1@tyfon.itea.ntnu.no> Message-ID: <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> "Magnus Lie Hetland" wrote in message news:9pimak$c22$1 at tyfon.itea.ntnu.no... > "Joshua Macy" wrote in message > news:3BBABE1C.5010108 at sneakemail.com... > > > > > > Joshua Macy wrote: > > > > > > > Even though I've released some of my Python work under the GPL, I'm > > > coming around to Tim Peter's way of thinking: just release things into > > > the public domain and have done with it. > > > > > > > > D'oh! Apostrophe error. Tim Peters' way of thinking. > > Well, actually, according to The Elements of Style by Strunk & White, > it should be > > Tim Peters's way of thinking > > ("Peters'" is a plural possessive, I think :) > Nope. If Tim were married, you would write about his and his wife's home (assuming they lived together) as the Peters's home. Since (and how could it be else) there is only one Tim, you should write about Tim Peters' way of thinking. but-then-i'm-english-so-what-do-i-know-ly y'rs - steve -- http://www.holdenweb.com/ From python_only at yahoo.com Fri Oct 12 02:44:17 2001 From: python_only at yahoo.com (Goh S H) Date: 11 Oct 2001 23:44:17 -0700 Subject: Psyco Specializing Compiler References: <3bc4d2e4$0$36473$ba620e4c@news.skynet.be> Message-ID: <184fbd02.0110112244.644a7a03@posting.google.com> Hi Rigo Armin, Great works! you're moving Python into next level, just wonder when can I use it in production, light-speed performance. Will it faster then Java? or should I should ask will it faster than C/C++? :-) Thanks & Regards, Goh From lac at strakt.com Mon Oct 8 15:39:47 2001 From: lac at strakt.com (Laura Creighton) Date: Mon, 08 Oct 2001 21:39:47 +0200 Subject: Why so few Python jobs? In-Reply-To: Your message of "08 Oct 2001 11:10:06 PDT." <9psq5u$agh$1@panix3.panix.com> References: <9psq5u$agh$1@panix3.panix.com> Message-ID: <200110081939.f98Jdl0W001553@ratthing-b246.strakt.com> > Stock C++ has better libraries than Python? Irrelevant. What counts is that they either already have the excellent C++ libraries or they know where they are and how to get them. Laura Creighton From ignacio at openservices.net Fri Oct 5 02:45:58 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 5 Oct 2001 02:45:58 -0400 (EDT) Subject: Boy do REs ever suck sometimes... Message-ID: Here's the problem I'm having with REs. When I use an RE like '^[0-9]+$' it matches both '123' and '123\n'. How can I get it to not match the string with the newline? -- Ignacio Vazquez-Abrams From ChuckEsterbrook at yahoo.com Wed Oct 31 05:07:44 2001 From: ChuckEsterbrook at yahoo.com (Chuck Esterbrook) Date: Wed, 31 Oct 2001 02:07:44 -0800 Subject: [Webware-discuss] Viewing sourcecode with PyDoc In-Reply-To: Message-ID: <5.1.0.14.0.20011031020524.02e20350@mail> Just a note that Webware uses py2html and PyFontify which we grabbed from other sources. Although we have made the slightest of mods to these which might be useful in general. We also have an original PySummary.py so you can see the interface of a class at a glance, sans docs and code. You can consult CVS if any of that interests you: https://sourceforge.net/cvs/?group_id=4866 http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/webware/Webware/DocSupport/ -Chuck At 11:57 AM 10/31/2001 +0200, Mark Gebhardt wrote: >Hi Jan / Ping > >I came across this posting (see below) re adding sourcecode viewing to pydoc >in the mailing list archive and wondered if anyone knew if there had been >any developments on this front? > >We use Python/Webware and Webware has a nice .py -> html converter that does >pretty colours, etc. Perhaps this could be included into pydoc. I'm prepared >to have a go at that as long as its not duplicating someone else's effort. > >Any thoughts? > >Cheers >Mark > >----- > >From: Jan Kybic (Jan.Kybic at epfl.ch) >Subject: 'pydoc -p' is great. Could it show the source as well? >Newsgroups: comp.lang.python >View this article only >Date: 2001-04-17 02:46:02 PST > > >Hi, > I have just discovered 'pydoc -p' which extract documentation >from your classes and presents it with your web browser and I am >delighted. Great work, many thanks. > >I have a feature wish: Could I access the HTMLized source code (of the >methods) as well, say by clicking on some link from the page generated >by pydoc? That would save me from having to go to the editor and >consult the actual source code manually. > >Jan > > >-- >------------------------------------------------------------------------- >Jan Kybic BIG IOA DMT EPFL Lausanne, Switzerland > or tel. work +41 (21) 693 5142 >For PGP key see my WWW page. http://bigwww.epfl.ch/kybic >Message 2 in thread >From: Aahz Maruch (aahz at panix.com) >Subject: Re: 'pydoc -p' is great. Could it show the source as well? >Newsgroups: comp.lang.python >View this article only >Date: 2001-04-17 08:38:08 PST > > >In article , >Jan Kybic wrote: > > > >I have a feature wish: Could I access the HTMLized source code (of the > >methods) as well, say by clicking on some link from the page generated > >by pydoc? That would save me from having to go to the editor and > >consult the actual source code manually. > >Send suggestions for pydoc to Ka-Ping Yee, ping at lfw.org > >Alternatively, given that it's now part of core Python, you should be >able to post suggestions to the SourceForge feature request. >-- > --- Aahz <*> (Copyright 2001 by aahz at pobox.com) > >Androgynous poly kinky vanilla queer het Pythonista >http://www.rahul.net/aahz/ >Hugs and backrubs -- I break Rule 6 > >"If we had some ham, we could have ham & eggs, if we had some eggs." --RH > > > > >_______________________________________________ >Webware-discuss mailing list >Webware-discuss at lists.sourceforge.net >https://lists.sourceforge.net/lists/listinfo/webware-discuss From dale at riverhall.NOSPAMco.uk Tue Oct 16 09:03:51 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Tue, 16 Oct 2001 14:03:51 +0100 Subject: Troubles with global variables References: <87r8s4vmgy.fsf@toadmail.com> <87elo6cd4w.fsf@lisboa.ifm.uni-kiel.de> <87pu7op8p2.fsf@toadmail.com> <87vghfrnph.fsf@toadmail.com> Message-ID: Jeremy Whetzel wrote: >Dale Strickland-Clark writes: > >> >eo = [['E',') Encoder: ','chooseenc()',enc], >> > ['B',') Bitrate: ','choosebr()',br]] >> >> ^^^^ >> Your problem, I think, is here. >> >> The values of enc and br are taken at the time eo is built. If you >> want new values, you will need to re-assign eo or use an alternative >> approach. > >Hmmmm... sometimes being a newbie can really be a pain. I hate to ask >this, but how does one "re-assign" eo? > >Jeremy Put the 'eo = ...' statement somewhere between the asignment to enc/br and where you next refer to it. -- Dale Strickland-Clark Riverhall Systems Ltd From gustafl at algonet.se Sun Oct 14 21:17:01 2001 From: gustafl at algonet.se (Gustaf Liljegren) Date: Mon, 15 Oct 2001 01:17:01 +0000 (UTC) Subject: Regex mystery: matching or Message-ID: I'm trying to match HTML or elements with the 'href' attribute. For some reason, the regex can't find any match if I put a sample match in the context of something else. I only need to add a space before, as in the string 's3' below. >>> re_link = re.compile(r'<(a|area)[^>]+href.*/?>', re.I | re.M) >>> s1 = '' >>> s2 = '' >>> s3 = ' ' >>> re.match(re_link, s1).group() '' >>> re.match(re_link, s2).group() '' >>> re.match(re_link, s3).group() Traceback (most recent call last): File "", line 1, in ? re.match(re_link, s3).group() AttributeError: 'None' object has no attribute 'group' >>> From sholden at holdenweb.com Wed Oct 24 20:32:02 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 24 Oct 2001 20:32:02 -0400 Subject: question on using format in struct module References: Message-ID: "Suresh" wrote ... > Hi All, > > I need some help with struct module. I have a binary file (obtained > with our product) and it contains char, int, float values. I used > struct module for this purpose in this manner -- > > import struct > binfile = open('binary_file.bin','rb') > format = ???? > bytes = struct.calcsize(format) > i1, i2 and so on = struct.unpack(format, binfile.read(bytes)) > > (i1, i2, i3 etc will have the equivalent text values of the binary > fields from the "binary_file.bin") > > The problem is specifying for "format" variable. Since my binary file > has non-uniform and different data types how do I specify for format = > ???? Is there a way I can tell python to decide upon format looking at > the binary file. Any help is appreciated ! > So, what you are sayng is that you don't know the format of the tile, and you'd like someone to tell you how to decode it? If *you* don't know how to decode your application's data, how do you expect someone else to? I must be missing something. Maybe there's something you can use in http://www.holdenweb.com/Python/PDCode/dbxread.py which reads binary files from Outlokk Express. regards Steve -- http://www.holdenweb.com/ From paul at fxtech.com Tue Oct 9 13:58:43 2001 From: paul at fxtech.com (Paul Miller) Date: Tue, 09 Oct 2001 12:58:43 -0500 Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> Message-ID: <3BC33AD3.50EDD419@fxtech.com> > I haven't followed the discussion > but to write 3.foo is something I would like to have in Python > I am a big fan of Ruby and there you can write > for example > -4.abs > which gives 4 (of course) **COUGH**syntactic sugar**cough** It may be "cool" (oh look everything is an object), but Python is also a functional language and in many cases it's just more clear to use that instead I prefer "print abs(-4)" From gward at python.net Thu Oct 18 18:13:04 2001 From: gward at python.net (Greg Ward) Date: Thu, 18 Oct 2001 22:13:04 GMT Subject: install packages to home dir? References: Message-ID: Ozone Hole near South Pole wrote: > However, when I go back to university, problem arises... Being low in > the pecking order, our sysadmin does not respond well to our request > for package install. As we do not have write access to > python2.0/site-packages, I can only copy all the files in the external > packages into my own work directory... > > It is sort of working. But, it is very confusing. I wonder if there > is any option that can allow us to intall the extra packages into say > ~/lib/python/my-packages or can we do sth like 'import > ~/supportpy/usefulstuff' ? Every time you install a new package: python setup.py install --home=~ See the manual "Installing Python Modules" for details. I'm pretty sure I documented that stuff... Greg -- Greg Ward gward at python.net http://starship.python.net/~gward/ If at first you don't succeed, give up--no use making a damn fool of yourself. From jason.martin at marconi.com Thu Oct 11 11:04:03 2001 From: jason.martin at marconi.com (Jason Martin) Date: Thu, 11 Oct 2001 11:04:03 -0400 Subject: New list member... Message-ID: <200110111500.AA23084@clt2.picker.com> Hello to the list. I just wanted to take some time and say hello! I am new to the list, and to Python. I will probably not be much help for most for now, but with the help of this list, and all the information I find on the web and from other sources, I hope to remedy that very shortly. Jason From rharkins at thinkronize.com Tue Oct 16 10:19:39 2001 From: rharkins at thinkronize.com (Rich Harkins) Date: Tue, 16 Oct 2001 10:19:39 -0400 Subject: fast sub list operations In-Reply-To: Message-ID: Would this work for you? coords=[x1,y1,x2,y2,x3,y3,...] final=[(coords[i],coords[i+1]) for i in xrange(0,len(coords),2)] final will now be [(x1,y1),(x2,y2),(x3,y3),...] Wouldn't be terribly fast but it should do the trick. Use range instead of xrange if you know coords will not be very big. You will get an IndexError if the length of coords is not a multiple of two. Rich > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Robin Becker > Sent: Tuesday, October 16, 2001 9:39 AM > To: Skip Montanaro > Cc: python-list at python.org > Subject: Re: fast sub list operations > > > In message <15308.11525.102304.624520 at beluga.mojam.com>, Skip Montanaro > writes > > > > > .... > > > >I think most people will point you to NumPy. > > > > Robin> ... I don't seem to have an interlace to get back to > the original > > Robin> list format. > > > >Check out the zip builtin function: > > > > >>> zip([1,2,3],[7,8,9]) > > [(1, 7), (2, 8), (3, 9)] > > > > I know about NumPy and like it a lot, but it's a bit heavyweight for > what we need. I also know about zip and apart from there being no unzip > it doesn't join up my list which should look like [1,7,2,8,3,9]. > -- > Robin Becker > > -- > http://mail.python.org/mailman/listinfo/python-list > From jknapka at earthlink.net Sun Oct 7 21:10:08 2001 From: jknapka at earthlink.net (Joseph A Knapka) Date: Mon, 08 Oct 2001 01:10:08 GMT Subject: How to call a python function in C++ References: <3BC09555.9090903@auburn.edu> <3BC096A4.478C3510@earthlink.net> Message-ID: <3BC0A785.E95D516@earthlink.net> Joseph A Knapka wrote: > > clio wrote: > > > > Hi, > > Here is a very confusing problem. I am trying to call a python function > > in C. I build a .cxx which have following functions: > > > > ...... > > static PyObject *my_callback=NULL; > > > > static PyObject * my_set_callback(PyObject * dummy,PyObject * args) > > > > { > > PyObject *result = NULL; > > PyObject *temp; > > > > if (PyArg_ParseTuple(args, "O:set_callback", &temp)) { > > if (!PyCallable_Check(temp)) { > > PyErr_SetString(PyExc_TypeError, "parameter must be > > callable"); > > return NULL; > > } > > Py_XINCREF(temp); /* Add a reference to new > > callback */ > > Py_XDECREF(my_callback); /* Dispose of previous callback */ > > my_callback = temp; /* Remember new callback */ > > /* Boilerplate to return "None" */ > > Py_INCREF(Py_None); > > result = Py_None; > > } > > return result; > > } > > .......... > > Acctually, this code is from online manual. Then in another c++ program > > I have this: > > > > extern PyObject *my_callback; > > This will not work because my_callback is declared static > and therefor is visible only within its source file. Try > > PyObject *my_callback; > > instead. Sorry to reply to myself, but I just noticed this advice could be misinterpreted. In the first file, static PyObject* my_callback; should just be PyObject* my_callback; The "extern PyObject* my_callback;" in the second file is correct. -- Joe # "You know how many remote castles there are along the # gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald # Linux MM docs: http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html From Krzysztof.Czarnowski at dgt-lab.com.pl Mon Oct 22 07:47:16 2001 From: Krzysztof.Czarnowski at dgt-lab.com.pl (Krzysztof Czarnowski) Date: Mon, 22 Oct 2001 13:47:16 +0200 Subject: Windows/COM events/strange behavior Message-ID: <012a01c15aef$4c8d3250$2706a8c0@krzysiek> Hello, Platform: WinNT4/Python2.1.1/win32all-140 The situation: I run a script that, in one of its threads, receives events from a COM object and occasionally does some polling to test if the event source is alive. The script is being started from a DOS prompt. Module "threading" is used. The COM event handler is constructed inside the thread and it lives in a "single threaded appartment" (CoInitialize(), loop PumpWaitingMessages(), CoUninitialize()). Then, when I start Pythonwin it gets stuck! When I stop the script Pythonwin seems to get released and starts (the window is displayed ...). Then I can run the script again without problems. Questions: Has anyone encountered such behaviour? Explanation? Danger behind scenes? Tips on how to change design to avoid such effects (use free threaded COM model? native Win threads? ...?) Thanks in advance, Krzysztof From pearu at cens.ioc.ee Tue Oct 2 06:24:29 2001 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 2 Oct 2001 12:24:29 +0200 Subject: '%r' docs Message-ID: Hi! To my pleasing surprice I discovered (from some python code, not mine) that '%s'%(repr(obj)) has shorter form '%r'%(obj). Though I scanned Python 2.1 docs in order to find some backing for this discovery, I found non. So, is this undocumented feature (and therefore may disappear in future??)? Or could some one point out where are the fancy output formats documented beside in the Tutorial. Thanks, Pearu From slinkp23 at yahoo.com Wed Oct 17 00:24:25 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Wed, 17 Oct 2001 04:24:25 GMT Subject: Library function for sorting References: <9qip39$6do$1@nserve1.acs.ucalgary.ca> Message-ID: On 17 Oct 2001 02:06:33 GMT, Michael Yuen wrote: >I'm really new to this Python stuff and was wondering if there's a >library function for sorting strings. I sure there is one but haven't >been able to find one when I looked through the documentation. The usual way is to put them in a list and use the list's sort() method. By default, this sorts in ASCII order - e.g. capitals in alphabetical order, then lowercase in alphabetical order. Example: >>> words = ['foo', 'bar', 'Baz', 'bat', 'baf', 'spam', 'eggs', 'bacon'] >>> words.sort() >>> words ['Baz', 'bacon', 'baf', 'bar', 'bat', 'eggs', 'foo', 'spam'] See the standard library reference, section 2.1.5.4, for more on list methods. If you want to sort by some other algorithm, pass in a comparison function. The comparison function should return 1, 0, or -1, as described in the reference above. The list will be put in *ascending* order according to this function. Example: Let's sort a list of strings by the last character in each string, ignoring the case. >>> def cmp_last_nocase(a, b): ... aLast = a[-1].upper() # force all to uppercase ... bLast = b[-1].upper() # for purposes of comparison ... if aLast > bLast: return 1 ... elif aLast == bLast: return 0 ... else: return -1 ... >>> words.sort(cmp_last_nocase) # pass the function - don't call it! >>> words ['baf', 'spam', 'bacon', 'foo', 'bar', 'eggs', 'bat', 'Baz'] Hope that helps... --PW From phd at phd.pp.ru Fri Oct 12 10:31:10 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 12 Oct 2001 18:31:10 +0400 Subject: MIME decode Message-ID: <20011012183110.F16906@phd.pp.ru> Hello! MIME decode WHAT IS IT Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is very good because it allows us to use apropriate formats/encodings/whatever. Sometimes, though, some unification is desireable. For example, one may want to put mail messages into an archive, make HTML indicies, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary atachmetnts will be much desireable. Here is the solution - mimedecode.py. This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which treated as an RFC822 mesage, and decoded to stdout. If the file is not an RFC822 message the file just piped to stdout one-to-one. If it is a simple RFC822 message it is just decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts decoded. Decoding can be controlled by command-line options. WHERE TO GET Master site: http://phd.pp.ru/Software/Python/#mimedecode Faster mirror: http://phd.by.ru/Software/Python/#mimedecode Requires: Python 2.0+, configured mailcap database. Documentation (also included in the package): http://phd.pp.ru/Software/Python/mimedecode.txt http://phd.by.ru/Software/Python/mimedecode.txt AUTHOR Oleg Broytmann COPYRIGHT Copyright (C) 2001 PhiloSoft Design LICENSE GPL Detailed manual NAME mimedecode.py - decode MIME message. SYNOPSIS mimedecode.py [-h|--help] [-V|--version] [-cCfFsS] [-beit mask] [filename] DESCRIPTION First, Subject and Content-Disposition headers are examined. If any of those exists, they decoded according to RFC2047. Content-Disposition header is not decoded - only its "filename" parameter. Encoding header's parameters is in violation of the RFC, but widely deployed anyway, especially in the M$ Ophice GUI (often referred as "Windoze") world, where programmers are usually ignorant lamers who never even heard about RFCs. Correct parameter encoding specified by RFC2231. This program decodes RFC2231-encoded parameters; continuation parameters (header*1, header*2, etc.) are not yet supported. Then the body of the message (or current part) decoded. Decoding starts with looking at header Content-Transfer-Encoding. If the header specifies non-8bit encoding (usually base64 or quoted-printable), the body converted to 8bit. Then, if its content type is multipart (multipart/related or multipart/mixed, e.g) every part recursively decoded. If it is not multipart, mailcap database is consulted to find a way to convert the body to plain text. (I have no idea how mailcap could be configured on said M$ Ophice GUI, please don't ask me; real OS users can consult my example at http://phd.pp.ru/Software/dotfiles/mailcap.html). The decoding process uses first copiousoutput filter it can find. If there is no filter the body just passed as is. Then Content-Type header consulted for charset. If it is not equal to current default charset the body text recoded using Unicode codecs. Finally message headers and body flushed to stdout. OPTIONS -h --help Print brief usage help and exit. -V --version Print version and exit. -c Recode different character sets to current default charset; this is the default. -C Do not recode character sets. -f Decode "filename" parameter of Content-Disposition header; this is the default. -F Do not decode filenames. -s Decode Subject header; this is the default. -S Do not decode Subject. -b mask Append mask to the list of binary content types; if the message to decode has a part of this type the program will pass the part as is, without any additional processing. -e mask Append mask to the list of error content types; if the message to decode has a part of this type the program will raise ValueError. -i mask Append mask to the list of content types to ignore; if the message to decode has a part of this type the program will not pass it, instead a line \nMessage body of type `%s' skipped.\n" will be issued. -t mask Append mask to the list of content types to convert to text; if the message to decode has a part of this type the program will consult mailcap database, find first copiousoutput filter and convert the part. The last 4 options (-beit) require more explanation. They allow a user to control body decoding with great flexibility. Think about said mail archive; for example, its maintainer wants to put there only texts, convert Postscript/PDF to text, pass HTML and images as is, and ignore everything else. Easy: mimedecode.py -t application/postscript -t application/pdf \ -b text/html -b 'image/*' -i '*/*' When the program decodes a message (or its part), it consults Content-Type header. The content type is searched in all 4 lists, in order "text-binary-ignore-error". If found, appropriate action performed. If not found, the program search the same lists for "type/*" mask (the type of "text/html" is just "text"). If found, appropriate action performed. If not found, the program search the same lists for "*/*" mask. If found, appropriate action performed. If not found, the program use default action, which is to decode everything to text (if mailcap specifies filters). Initially all 4 lists are empty, so without any additional parameters the program always use the default decoding. ENVIRONMENT LANG LC_ALL LC_CTYPE Define current locale settings. Usually used to determine current default charset. BUGS The program may output incorrect MIME message. The purpose of the program is to decode whatever is possible to decode, not to produce absolutely correct MIME output. The incorrect parts are obvious - decoded Subject headers and filenames. Decoding mail header parameters is incomplete - continuations in RFC2231-encoded parameters (header*1, header*2, etc.) are not parsed yet. NO WARRANTIES This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From maxmcorp at worldonline.dk Sat Oct 13 14:40:01 2001 From: maxmcorp at worldonline.dk (maxm) Date: Sat, 13 Oct 2001 20:40:01 +0200 Subject: how do I add site-packages on Windows? References: <3bc57f3b$0$233$edfadb0f@dspool01.news.tele.dk> <9q7m1c$2e70$1@rivage.news.be.easynet.net> Message-ID: "Justin" wrote in message news:9q7m1c$2e70$1 at rivage.news.be.easynet.net... > I may be missing something here, and you may absolutely want > to achieve this programmatically, but otherwise you can use > pythonwin, "Tools/Edit Python Path", then right click on > PythonPath and edit the value, or add a dependent key. Doh! ... never noticed that menu item. That was certainly easy. Thanks! Max M From donn at u.washington.edu Mon Oct 29 12:17:38 2001 From: donn at u.washington.edu (Donn Cave) Date: 29 Oct 2001 17:17:38 GMT Subject: Is Stackless Python DEAD? References: <184fbd02.0110262039.74799675@posting.google.com> Message-ID: <9rk2vi$16dm$1@nntp6.u.washington.edu> Quoth tatebll at aol.com (Bill Tate): ... | In every respect, I believe Christian's work advances Python in very | meaningful ways in terms of flexibility and performance. It is stable | and snap to install. I'll say. For myself, I have mixed feelings - very powerful, but a little scary. I was able to set up a callback-driven system that uses continuations to span callbacks in a single function - like, # callback from UI - selected login option def login(self): name = self.config.loginid password = self.getpassword(name) # posts password prompt window # Function actually returns from callback ... # ... New callback arrives with password requested here; continue! self.loginwithpassword(name, password) That's arguably more readable than any alternative I ever thought of, but then it substantially obscures the "real" flow of control in the program. Anyway, whether I want to go that way or not (and I don't know for myself), it clearly is indeed a meaningful advance, something that makes a substantial difference in what you can do with Python. Definitely worth looking at, if you have gnarly asynchronous programming issues. Donn Cave, donn at u.washington.edu From grante at visi.com Tue Oct 9 13:37:34 2001 From: grante at visi.com (Grant Edwards) Date: Tue, 09 Oct 2001 17:37:34 GMT Subject: Python is better than free (was Re: GNU wars again) References: <200110030312.f933COK01047@smtp2.idir.net> <9ptagr$m6c$1@panix3.panix.com> Message-ID: In article , Ken Seehof wrote: > Why do you even respond to people who make useless posts like > that? It's not funny. It just wastes space in peoples mail > boxes. [...] > Copyright 2001, Ken Seehof > > This message is free software; you can redistribute it and/or > modify it under the terms of the GNU General Public License > as published by the Free Software Foundation; either version 2 > of the License, or (at your option) any later version. > > This message is distributed in the hope that it will be useful, > but WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > See the GNU General Public License for more details. My post is a waste of space? As opposed to the valuable content in that last bit? -- Grant Edwards grante Yow! I KAISER ROLL?! What at good is a Kaiser Roll visi.com without a little COLE SLAW on the SIDE? From gerrie at trispen.com Wed Oct 3 05:36:05 2001 From: gerrie at trispen.com (Gerrie Roos) Date: Wed, 03 Oct 2001 11:36:05 +0200 Subject: Compiling Python2.1.1 on FreeBSD3.5 Problem Message-ID: <3BBADC04.2F245B68@trispen.com> Hi! Hope it's in order to ask such questions here... I downloaded Python-2.1.1.tgz, the latest sources I could find, unpacked the lot on a FreeBSD3.5 machine read all the compiling/installation stuff, etc...then I: - did 'make clobber' just to make sure... - Removed '-ltermcap' from the 'readline' entry in Modules/Setup, as advised in the README. This entry was commented out with a '#', so I left it...hmmm...should I uncomment it? - Added: '_curses _cursesmodule.c -lmytinfo -lncurses -ltermcap' to Modules/Setup, as advised in the README. The README doesn't use the underscores, but I think one should, since the commented-out examples in the Setup file does use underscores...and the source file is _cursesmodule.c. Is all I did here right? - I ran ./configure - I checked the Modules/Setup file to see if my changes were still there - did 'make' ...and this is what I got: . . lots of successful stuff . . . gcc -g -O2 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -c ./Modules/_cursesmodule.c -o Modules/_cursesmodule.o ./Modules/_cursesmodule.c: In function `PyCursesWindow_wsyncup': ./Modules/_cursesmodule.c:295: warning: implicit declaration of function `wsyncup' ./Modules/_cursesmodule.c: In function `PyCursesWindow_wsyncdown': ./Modules/_cursesmodule.c:296: warning: implicit declaration of function `wsyncdown' ./Modules/_cursesmodule.c: In function `PyCursesWindow_wcursyncup': ./Modules/_cursesmodule.c:299: warning: implicit declaration of function `wcursyncup' ./Modules/_cursesmodule.c: In function `PyCursesWindow_idcok': ./Modules/_cursesmodule.c:304: warning: implicit declaration of function `idcok' ./Modules/_cursesmodule.c: In function `PyCursesWindow_immedok': ./Modules/_cursesmodule.c:305: warning: implicit declaration of function `immedok' ./Modules/_cursesmodule.c: In function `PyCursesWindow_getparyx': ./Modules/_cursesmodule.c:311: warning: implicit declaration of function `getparyx' ./Modules/_cursesmodule.c:311: warning: `arg1' might be used uninitialized in this function ./Modules/_cursesmodule.c:311: warning: `arg2' might be used uninitialized in this function ./Modules/_cursesmodule.c: In function `PyCursesWindow_wattron': ./Modules/_cursesmodule.c:313: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:313: (Each undeclared identifier is reported only once ./Modules/_cursesmodule.c:313: for each function it appears in.) ./Modules/_cursesmodule.c:313: parse error before `arg1' ./Modules/_cursesmodule.c:313: `arg1' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_wattroff': ./Modules/_cursesmodule.c:314: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:314: parse error before `arg1' ./Modules/_cursesmodule.c:314: `arg1' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_wattrset': ./Modules/_cursesmodule.c:315: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:315: parse error before `arg1' ./Modules/_cursesmodule.c:315: `arg1' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_syncok': ./Modules/_cursesmodule.c:332: warning: implicit declaration of function `syncok' ./Modules/_cursesmodule.c: In function `PyCursesWindow_mvderwin': ./Modules/_cursesmodule.c:335: warning: implicit declaration of function `mvderwin' ./Modules/_cursesmodule.c: In function `PyCursesWindow_wresize': ./Modules/_cursesmodule.c:338: warning: implicit declaration of function `wresize' ./Modules/_cursesmodule.c: In function `PyCursesWindow_AddCh': ./Modules/_cursesmodule.c:369: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:369: parse error before `attr' ./Modules/_cursesmodule.c:377: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_AddStr': ./Modules/_cursesmodule.c:415: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:415: parse error before `attr' ./Modules/_cursesmodule.c:424: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c:444: `attr_old' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_AddNStr': ./Modules/_cursesmodule.c:461: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:461: parse error before `attr' ./Modules/_cursesmodule.c:470: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c:490: `attr_old' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_Bkgd': ./Modules/_cursesmodule.c:507: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:507: parse error before `attr' ./Modules/_cursesmodule.c:515: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_BkgdSet': ./Modules/_cursesmodule.c:536: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:536: parse error before `attr' ./Modules/_cursesmodule.c:544: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_EchoChar': ./Modules/_cursesmodule.c:648: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:648: parse error before `attr' ./Modules/_cursesmodule.c:656: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c:673: warning: implicit declaration of function `pechochar' ./Modules/_cursesmodule.c: In function `PyCursesWindow_GetStr': ./Modules/_cursesmodule.c:798: warning: implicit declaration of function `mvwgetnstr' ./Modules/_cursesmodule.c: In function `PyCursesWindow_Hline': ./Modules/_cursesmodule.c:817: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:817: parse error before `attr' ./Modules/_cursesmodule.c:825: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_InsCh': ./Modules/_cursesmodule.c:860: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:860: parse error before `attr' ./Modules/_cursesmodule.c:868: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_InStr': ./Modules/_cursesmodule.c:940: warning: implicit declaration of function `mvwinstr' ./Modules/_cursesmodule.c: In function `PyCursesWindow_InsStr': ./Modules/_cursesmodule.c:962: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:962: parse error before `attr' ./Modules/_cursesmodule.c:971: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c:991: `attr_old' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_InsNStr': ./Modules/_cursesmodule.c:1008: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:1008: parse error before `attr' ./Modules/_cursesmodule.c:1017: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c:1037: `attr_old' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCursesWindow_PutWin': ./Modules/_cursesmodule.c:1199: warning: implicit declaration of function `putwin' ./Modules/_cursesmodule.c: In function `PyCursesWindow_Vline': ./Modules/_cursesmodule.c:1345: `attr_t' undeclared (first use this function) ./Modules/_cursesmodule.c:1345: parse error before `attr' ./Modules/_cursesmodule.c:1353: `attr' undeclared (first use this function) ./Modules/_cursesmodule.c: In function `PyCurses_termattrs': ./Modules/_cursesmodule.c:1516: warning: implicit declaration of function `termattrs' ./Modules/_cursesmodule.c: In function `PyCurses_termname': ./Modules/_cursesmodule.c:1518: warning: implicit declaration of function `termname' ./Modules/_cursesmodule.c:1518: warning: passing arg 1 of `PyString_FromString' makes pointer from integer without a cast ./Modules/_cursesmodule.c: In function `PyCurses_has_ic': ./Modules/_cursesmodule.c:1523: warning: implicit declaration of function `has_ic' ./Modules/_cursesmodule.c: In function `PyCurses_has_il': ./Modules/_cursesmodule.c:1524: warning: implicit declaration of function `has_il' ./Modules/_cursesmodule.c: In function `PyCurses_filter': ./Modules/_cursesmodule.c:1526: warning: implicit declaration of function `filter' ./Modules/_cursesmodule.c: In function `PyCurses_noqiflush': ./Modules/_cursesmodule.c:1528: warning: implicit declaration of function `noqiflush' ./Modules/_cursesmodule.c: In function `PyCurses_Delay_Output': ./Modules/_cursesmodule.c:1604: warning: implicit declaration of function `delay_output' ./Modules/_cursesmodule.c: In function `PyCurses_GetWin': ./Modules/_cursesmodule.c:1687: warning: implicit declaration of function `getwin' ./Modules/_cursesmodule.c:1687: warning: assignment makes pointer from integer without a cast ./Modules/_cursesmodule.c: In function `PyCurses_has_key': ./Modules/_cursesmodule.c:1726: warning: implicit declaration of function `has_key' ./Modules/_cursesmodule.c: In function `PyCurses_Napms': ./Modules/_cursesmodule.c:2026: warning: implicit declaration of function `usleep' ./Modules/_cursesmodule.c: In function `PyCurses_QiFlush': ./Modules/_cursesmodule.c:2148: warning: implicit declaration of function `qiflush' ./Modules/_cursesmodule.c: In function `PyCurses_Use_Env': ./Modules/_cursesmodule.c:2379: warning: implicit declaration of function `use_env' *** Error code 1 Stop. How do I get past this problem? Any help much appreciated! Gerrie From ullrich at math.okstate.edu Mon Oct 29 10:57:48 2001 From: ullrich at math.okstate.edu (David C. Ullrich) Date: Mon, 29 Oct 2001 15:57:48 GMT Subject: binary search tress using classes References: Message-ID: <3bdd7c4b.859220638@news> On Sun, 28 Oct 2001 09:55:06 +0000, Dale Strickland-Clark wrote: [...] > >I suspect this is a college project. Well of course it is - how could "The code has to be modular based on classes" be anything but a class requirement? > It pops up almost identically >every now and then. >-- >Dale Strickland-Clark >Riverhall Systems Ltd David C. Ullrich From cbarber at curl.com Mon Oct 29 13:48:10 2001 From: cbarber at curl.com (Christopher Barber) Date: 29 Oct 2001 13:48:10 -0500 Subject: Curl-ing, anyone? References: <458b194a.0110241156.795e9618@posting.google.com> Message-ID: "Jeff Hinrichs" writes: > It's closed source proprietary nature, True, although we would like to open source part of the technology in the future. > it's requirement of installing plug-ins to see content on your browser, Yes, but that is not our fault. Based on this argument, you should only use technology provided by your OS vendor (e.g. Microsoft). If you want to operate under a set of OS'es and browsers you are left with vanilla HTML and relatively simple JavaScript as your client-side solution. This leaves you with really lame GUIs. Note that Windows XP doesn't even include Java suppport by default, so pretty soon the same argument could be used to flame that technology as well. > it's lack of ODBC, Yes, we are working on that one. We do provide XML support and will be supporting SOAP in the next release, which will be coming out very soon. > it's skewed vision of web content only or some other pigeon holing > "feature" that I have not brought up. Like oh yea, to "curl" your > site you need to convert all of you html to curl and then have your > audience download a plug-in. No, you don't have to convert your entire site to the Curl language in order to take advantage of the technology, anymore than you would have to convert your entire site to Flash or Java in order to use those technologies. - Christopher From just at letterror.com Tue Oct 16 14:27:18 2001 From: just at letterror.com (Just van Rossum) Date: Tue, 16 Oct 2001 20:27:18 +0200 Subject: fast sub list operations References: <3BCC4C52.7F0881A4@letterror.com> Message-ID: <3BCC7C06.F7DD30BC@letterror.com> Robin Becker wrote: > I didn't actually choose the data structure. Actually in this case Just > the points are the lists of points from your Path class in > reportlab.graphics.shapes, but I guess you didn't choose the base > representation for lists of points either :-) Heh, exactly... I think it was the Polygon class that set the example. It's been a pain ever since ;-) Just From kragen at dnaco.net Tue Oct 16 12:05:31 2001 From: kragen at dnaco.net (Kragen Sitaker) Date: Tue, 16 Oct 2001 16:05:31 GMT Subject: defstruct.py Message-ID: # I occasionally find myself writing code like the following: # class Point: # def __init__(self, x, y): # self.x = x # self.y = y # and that's the whole class. This little module lets me write the above code # as # Point = defstruct('x', 'y') # and have done with it. # # The name is taken from Common Lisp; the syntax is taken from MzScheme's # define-struct and is similar to the Common Lisp boa constructor syntax. # define-record-type from SRFI 9 is nasty and Scheme-specific enough that # I didn't use it. # # I hereby dedicate this code to the public domain and disavow any copyright # interest in it. # # -- Kragen Sitaker, 2001-10-16 def defstruct(*fields): class Struct: def __init__(self, *contents): if len(contents) != len(self.structfields): raise TypeError, ( "wrong number of arguments: expected %d %s, got %d" % (len(self.structfields), repr(self.structfields), len(contents))) for fieldnum in range(len(contents)): setattr(self, self.structfields[fieldnum], contents[fieldnum]) Struct.structfields = fields return Struct def test(): point = defstruct('x', 'y') p1 = point(1, 2) assert p1.x == 1 assert p1.y == 2 complex = defstruct('real', 'imag') assert point is not complex assert isinstance(p1, point) assert not isinstance(p1, complex) test() -- Kragen Sitaker Perilous to all of us are the devices of an art deeper than we possess ourselves. -- Gandalf the White [J.R.R. Tolkien, "The Two Towers", Bk 3, Ch. XI] From qrczak at knm.org.pl Fri Oct 19 07:26:22 2001 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: 19 Oct 2001 11:26:22 GMT Subject: Curious assignment behaviour References: <3bcc75d8.1903824318@news> <3BCCE77D.CBC64E56@cosc.canterbury.ac.nz> <3bcdbb39.1987133892@news> Message-ID: Fri, 19 Oct 2001 11:59:43 +0200, Nomad pisze: > I'm probably over my head (and more than likely rambling as well), > but in "let x = y" doesn't the 'let' denote that the value of 'x' > will be changed? It depends on the language. There are languages where 'let x = y' introduces the name x, defined as y, and its value can't change. -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZAST?PCZA QRCZAK From kosh at aesaeion.com Mon Oct 1 17:55:37 2001 From: kosh at aesaeion.com (kosh at aesaeion.com) Date: Mon, 1 Oct 2001 15:55:37 -0600 (MDT) Subject: list.append problem? In-Reply-To: Message-ID: On 1 Oct 2001, newgene wrote: > I am a newer of python. I have a problem like this code: > > >>> a=b=c=[] > >>> a.append(1) > >>> b.append(2) > >>> c.append(3) > >>> a > [1, 2, 3] > >>> b > [1, 2, 3] > >>> c > [1, 2, 3] > > a,b,c become the same, although append method applied seperately. > It's really strange and unreasonable. > My python is ActivePython Build 210 running on WinNT. Actually you bound a b and c to the same object. Everything in python is by reference so you have 3 names for the same object and that is why the append on any of them showed in all of them since they are really the same. From asencio at mitre.org Mon Oct 29 16:32:44 2001 From: asencio at mitre.org (Angel Asencio) Date: Mon, 29 Oct 2001 16:32:44 -0500 Subject: detecting and creating directories References: <3BDDA7BC.8CF7C891@mitre.org> Message-ID: <3BDDCAFC.7EF39E4A@mitre.org> Excellent thanks! Steve Holden wrote: > "Angel Asencio" wrote in ... > > Greetings: > > > > I found the module that has the command to make directories, but I > > have not been lucky finding a way to check for the existance of a > > directory (so it is not there, I can create it). > > > > Any pointers? > > > You should also check that it really is a directory and not just a plain > file! The following code is untested... > > import os > path = "/usr/tmp/newdir" > if os.path.exists(path): > if not os.path.isdir(path): > raise ValueError, "%s exists but is not a directory" % path > else: > os.mkdir(path) > > regards > Steve > -- > http://www.holdenweb.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: asencio.vcf Type: text/x-vcard Size: 337 bytes Desc: Card for Angel Asencio URL: From root at rainerdeyke.com Tue Oct 23 16:12:51 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Tue, 23 Oct 2001 20:12:51 GMT Subject: Dictionary from list? References: Message-ID: <7bkB7.14803$IR4.9036934@news1.denver1.co.home.com> "Huaiyu Zhu" wrote in message news:slrn9tbier.135.huaiyu at gauss.almadan.ibm.com... > There have been several good arguments about why [(k,v), (k,v) ...] is > better than [k, v, k, v, ...]. Here are some more observations: Add to that: - When dealing with '[k, v, k, v, ...]' sequences, it is easy to accidentally mess up the alignment and create a '[k, k, v, k, v, ...]' sequence instead (with disasterous results). -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From slinkp23 at yahoo.com Thu Oct 25 16:21:52 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Thu, 25 Oct 2001 20:21:52 GMT Subject: print to emacs buffer? References: <3BD85974.B1A5BA8F@juno.com> Message-ID: On Thu, 25 Oct 2001 18:27:00 GMT, Jeff Sandys wrote: >Is there an easy way to get a python >script to print to an emacs buffer? > >So when I enter 'python my-script.py' >at the unix prompt in an emacs shell >the output of the print statements >goes to a separate (python-output) >buffer instead of the shell buffer. Have you tried hitting C-c C-c in the buffer for your python script? This sends stdout to a buffer *Python Output*, or just prints "No output" in the minibuffer. M-x describe-mode in a python buffer will tell you lots of interesting things! >If it helps, I am using emacs 19.34.1 >(I don't have a choice about this!) >and python-mode 3.105. I have emacs 20.something, but the same version of python-mode. A link that may be helpful with updating your python-mode, if you want to: http://www.python.org/emacs/python-mode/compat_emacs19.html -- Paul Winkler From tim.one at home.com Fri Oct 26 15:49:26 2001 From: tim.one at home.com (Tim Peters) Date: Fri, 26 Oct 2001 15:49:26 -0400 Subject: Can't copy iterator object In-Reply-To: <1512.011026@storm.ru> Message-ID: [Kerim Borchaev] > I can agree that one shouldn't be able to copy "non-copiable" iterator. > Like file iterator. But why not leave it to the particular iterator > implementation? So as file's iterator to be "non-copiable" but list's > one - copiable? It *is* up to each particular iterator implementation, and you can add any methods you like to your own iterators. All of the builtin iterators chose not to support copying, due to a lack of interest, compelling use cases, and time. Note that "copy" is also ambiguous along several dimensions: besides the usual "shallow vs deep" distinction, it's also unclear whether iterator.copy() "should" in general strive to duplicate the *current* state of the iterator, or to return a fresh restart-from-the-beginning iterator "over the same object". The latter meaning (sometimes called "refresh") may be more useful more often. Regardless, the builtin iterators chose to stay out of these arguments entirely for now. That doesn't preclude them from growing new behaviors in later releases, provided someone writes a compelling PEP in favor of some. From MARTIME at kellyservices.com Mon Oct 8 15:07:43 2001 From: MARTIME at kellyservices.com (MARTIME at kellyservices.com) Date: Mon, 8 Oct 2001 15:07:43 -0400 Subject: Message to be posted Message-ID: <85256ADF.00691864.00@mail.kellyservices.com> I would like to post to the newsgroup. I am contacting you from Kelly Services. I have a need for a Python, VC++ programmer and would like to post my opportunity on the Usenet newsgroups Details: Candidates should send their resumes to: Maria Martino martime at kellyservices.com Term: Contractor Length: 4 months Job Description: Work with the development team on an exciting business application software. Location: Tarrytown, Westchester County, NY Required Skills: Commercial development experience in Python and Visual C++ on Win32 platform. Strong analytical skill. Object-oriented programming is a must. SQL Server or other database server. Experience in widget-based GUI development. Experience in webserver or application server (e.g. IIS, Zope). Desirable skills: Advanced degree (CS/EE, Science, Math or other) welcome. Previous experience in finance, statistics, or Monte Carlo simulation. XML processing. Internet programming experience (TCP/IP, HTTP protocol, RPC, socket programming.) COM programming in business applications, interfacing with Access/Excel. Visual Basic for Applications. Source code revision control systems. Bug report database. InstallShield. From vig at ParallelGraphics.COM Mon Oct 1 11:56:51 2001 From: vig at ParallelGraphics.COM (Ivan A. Vigasin) Date: Mon, 1 Oct 2001 19:56:51 +0400 (MSD) Subject: Handling C structs in python Message-ID: Hello, All I'm writing python extension and need to pass C structs from C++ to python. What is the usual way of doing whis? Thanks Regards, Ivan ICQ: 22181170 From kseehof at neuralintegrator.com Wed Oct 10 02:34:59 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Tue, 9 Oct 2001 23:34:59 -0700 Subject: PYTHONPATH and embedding python References: Message-ID: <03e401c15155$b2f5ae80$e4cfbfa8@kens> > On Tue, 9 Oct 2001, Idriz SMAILI wrote: > > > I have the following problem: > > > > I have embedded Python in an C++ application. The Python modules are > > after freezing integrated in the application and those modules should be > > imported as frozen modules. Before I initialize the Python interpreter > > I've used the putenv in C code to set the environment variable > > PYTHONPATH to "pwd == .". I've used the getenv function to check if the > > environment variable has been changed and it is as expected really > > changed to the new setting result. The problem is that the Python > > Interpreter during its initialization uses the same getenv function and > > it gets the old value of the PYTHONPATH value. This is my problem, > > because I've got a lot of problems in case the user has installed a > > different python version, because the Python Interpreter tries to import > > for example the os module, which is different between Python 1.5.2 and > > Python 2.1.1. I am using Python 2.1.1 and Microsoft Visual Studio V. > > 6.0. under WinNT operating system. > > > > Does anyone have any suggestions? Thanks. > > Use this bit of code right after Py_Initialize(): > > --- > char *path, *newpath; > > path=Py_GetPath(); > newpath=strcat(path, ":."); // or ";.", possibly > PySys_SetPath(newpath); > free(newpath); > --- Yikes! That doesn't look quite right to me. strcat(char *dest, char *src) returns its first argument after concatenating *src to it. In your example, path points to static storage returned by Py_GetPath. Your code proceeds to concatenate onto it (blasting away at static memory reserved for the python library), and then frees it (note that newpath==path at the end) which it doesn't have a right to do. You probably mean something like this: // untested code: char *path, *newpath; path=Py_GetPath(); newpath=new char[strlen(path)+4]; strcpy(newpath, path); strcat(newpath, ":."); // ":." for unix, or ";." for windows PySys_SetPath(newpath); free(newpath); from the docs: char* Py_GetPath () Return the default module search path; this is computed from the program name (set by Py_SetProgramName() above) and some environment variables. The returned string consists of a series of directory names separated by a platform dependent delimiter character. The delimiter character is ":" on Unix, ";" on DOS/Windows, and "\n" (the ASCII newline character) on Macintosh. The returned string points into static storage; the caller should not modify its value. The value is available to Python code as the list sys.path, which may be modified to change the future search path for loaded modules. Hmm, I can't seem to find any documentation on PySys_SetPath. I wonder if it automatically converts the delimiter (":" <=> ";"). - Ken Seehof kseehof at neuralintegrator.com From huaiyu at gauss.almadan.ibm.com Wed Oct 17 23:22:36 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 18 Oct 2001 03:22:36 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> Message-ID: You raised several valid points, but your picking on the examples sometimes hinges on specific wart of the examples. Obviously I did not contruct the examples well enough in this respect. So let me give it another try. >It doesn't have to use an extra variable. > > while 1: > x = next() > if x.is_end: > raise "not found" > y = process(x) > if y.is_what_we_are_looking_for(): > break > Do you recommend always using this while 1: if not A: E break B if C: break D in place of this? while A: B if C: break D else: E This style change is orthogonal to the issue of statements before condition. The question is whether the else-clause in while-loop has any real use. >> while x = get_next(); x: >> whatever(x) > >I prefer the syntax mentioned some months ago when this discussion >last flared up. > >loop: > x = get_next() >break if x: > whatever(x) That is something I'd like too, except: - new keyword "loop", - do we want to make "while" obsolete? - need two kinds of "break" (one impact "else" the other does not). >Basically, I don't like multiple actions in the same line. I >like vertical arrangement of code. I find it easier to read and >easier to understand. Me too, but not if it requires more nested structures, duplicate code, or temporary variables for flow-control purpose only. See below. >for line in iter(readline, ""): Not every action can be changed to iterators. See below. >> if x = dict[a]; x: proc1(x) >> elif x = next(x); x.ok(): proc2(x) >> elif x.change(); property(x): proc3(x) >> ... > >Need a real life example here. Is there something in the standard >library which would be improved with this change? The reason I >ask is because this code can be refactored into a function. if m = re.match(patt1, x); len(m.groups())>3: a = process_header(m) elif m = re.match(patt2, x); m: b = process_body(m, some_other_data) ... >def funky_function(dict, a, x): > x = dict[a] > if x: > return proc1(x) > x = next(x) > if x.ok(): > return proc2(x) > x.change() > if property(x): > return proc3(x) Do you suggest that the normal way to use such control structures is to always enclose them in a function? It is almost identical to my hack using a while loop that was immediately following this example, except being less obvious (in another scope) and possibly slower: while 1: x = dict[a] if x: proc1(x); break x = next(x) if x.ok(): proc2(x); break x.change() if property(x): proc3(x); break ... break >You can add qualifications to make a function call harder to do, >but I'm betting they aren't common in real life. I'd say the above regular expression example is quite common, and your function would need quite some optional variables. >but increasing the temptation for people to write > > a = f(x) > if a > 2: > g() > >as > > if a = f(x); a > 2: > g() Good point. Although I do not see the temptation, I don't see the use, either. Maybe it should not be allowed after "if", only after "elif". >Here's a single typing error. > >if x > 1;0: > ... > >when it should have been > >if x > 1.0: > ... If we are not considering typos between ";" and ":", this can already happen x = 1;0; y = 2.0 if x > 1,0: ... > >> - mistype == for = in statement will be detected > >How? An expression is a statement. What was I thinking? You are right. Nothing can automatically prevent this. >Quick! Spot the colon! > >if a; \ > b; \ > c; \ > d: \ > e; \ > f; \ > g I would rather consider this as contrived. :-) >> while char=file.readline()[3]; char != 'x': >> process(char) > >To quote Winnie-the-Pooh, I am a programmer of very little brain. >I forget things too easily, so I like to step through what I'm doing. > >for line in iter(file.readline, ""): > char = line[3] > if char != 'x': > break > process(char) Maybe our intuition is different, but it appears to me that while char=file.readline()[3]; char != 'x': is exactly following things one step at a time, in the right order. But more seriously, is it practical to change every while loop to for-loops with iterators? Consider my other example you ignored while string = raw_input(prompt): not string.startswith("n"): do things with string break the loop according to condition change prompt according to condition do something more In practice it is not always a good idea to put every code block in a separate function, although it might be an ideal goal in some style. >This is also easier to debug. I can stick in a "print line" and >see what's going on. It calls for more work to change the original >code to do that. True, but not very much. while line=file.readline(); char=line[3]; char != 'x': >Yes, it's 5 lines compared to 2. Again, your example is contrived. >The real code might look like > > commands = ( > (3, 'x', None), > (0, 'reset', do_reset), > (4, 'fly', use_swatter), > ) > for line in file: > for cmd in commands: > if line[cmd[0]:].startswith(cmd[1]): > f = cmd[2] > if f is None: > return > f(line) > This example does not fit the pattern. This proposal is not meant to replace all the usage of "for" by "while". On the other hand, your alternatives seem to recommend changing all the "while" to "for". >> while string = raw_input(prompt): not >string.startswith("n"): >> process(string) > >Should be a semicolon there ;) Can be detected automatically. :-) >You didn't mention > >loop: > statements >break if expr: > statements > >as an alternative, with various spellings of 'loop' and 'break if'. >One with no new keywords is > >while expr: > statements >break if expr: > statements Now I do. :-) (See near top.) I'll add it to the PEP. The main issue is that it does not distinguish two kinds of "break" (in terms of interaction with "else"). To most of the alternatives you mention my immediate reaction is one of these two questions: 1. Is it practical to change all while loops to for-loops with iterators? 2. Is it practical to change all elif into nested scope with break / return? I'd guess no. Of course for any simple example it would appear so, and any complicated example may appear contrived. Huaiyu From samschul at pacbell.net Wed Oct 17 16:47:13 2001 From: samschul at pacbell.net (Samuel Schulenburg) Date: 17 Oct 2001 13:47:13 -0700 Subject: Python and win32api References: <9qk64l$i3e$1@oslo-nntp.eunet.no> Message-ID: olav.viken at kmss.no wrote in message news:<9qk64l$i3e$1 at oslo-nntp.eunet.no>... > This is what i'm trying to do with a simple Python script: > > - Retrive the operating system on the computer the script is running > - Retrive the service pack installed > - Retrive the native language of the OS installed. > > The first two is easy, but last one is giving me problems. > > This is from Microsoft knowledgebase > > HOWTO: Determine Default Language ID of Windows 95 or WinNT > http://support.microsoft.com/support/kb/articles/q181/6/04.asp > > Which says in part: > | SUMMARY > | Some applications need to get the operating system's language ID. > | GetSystemDefaultLangID doesn't work, because the user can change it > | in the Control Panel. [...] > | Under both Windows NT and Windows 95, you can get the language > | information in the FileVersionInfo of User.exe by calling > | GetFileVersionInfo, and then VerQueryValue (on > \\VarFileInfo\\Translation") > | on the VersionInfo block of the operating system's User.exe. > | NOTE: This method is the most reliable. It works well under both Windows > > > | NT and Windows 95. This method also works for Windows 3.1. > > I can't find the GetFileVersionInfo method under win32api, and I can't find > another way of telling the language. > > > Anyone? > > Thanks > Olav See the following URL for Sam Rushing's CALLDLL module that is part of Windll. There is a version for Python 2.1 http://www.nightmare.com/software.html Also get Dynwin at this URL "http://www.nightmare.com/~rushing/dynwin/" for support functions. Sam Schulenburg From dkuhlman at rexx.com Thu Oct 18 13:09:00 2001 From: dkuhlman at rexx.com (Dave Kuhlman) Date: 18 Oct 2001 12:09:00 -0500 Subject: Python script engine References: Message-ID: <1003425607.647091@rexx.com> The built-in function exec will do this for you (or use eval, if it's a expression). But exec is dangerous, because it enables your users to do anything that Python can do. If this is too much power, then look at 'rexec' (Restricted execution framework) in the Python standard library. And, if _you_ want to implement the commands that your users execute, then take a look at 'cmd' (Support for line-oriented command interpreters) in the Python standard library. Also, if you want users to enter and execute Python code interactively, then I believe you will want to look at 'code' (Interpreter base classes) in the Python standard library. You will find an example of it's use in Tools/idle in the Python source code distribution. - Dave A wrote: > > Hello, > In my application I would like to allow users to add/use basic > python commands but I do not want users to change my code of > application directly. > > > For example my program expects > telephone. number in format > +442076812563 > but a user sometimes may want to > supply > 0044 207 681 2563 > (please note a blank). > Then the user would need > to use STRING.JOIN Python function to get from the user's input > (0044 207 681 2563) the string that my program expects > (+442076812563) > > Does anyone have any idea how to do that? > > Thank you for help > Ladislav > > -- Dave Kuhlman dkuhlman at rexx.com -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From tim.one at home.com Fri Oct 26 15:26:00 2001 From: tim.one at home.com (Tim Peters) Date: Fri, 26 Oct 2001 15:26:00 -0400 Subject: A small inconsistency in syntax? In-Reply-To: <_ohC7.38719$Nx2.821986@atlpnn01.usenetserver.com> Message-ID: [Steve Holden] > This is getting TOO weird. Should this really be allowed? Does it make > any kind of sense? The attached comes from 2.0, but 2.1.1 and 2.2b1 give > the same result. > > >>> [a,b] = (1,2) # no surprises here > >>> a > 1 > >>> b > 2 > >>> [a,b][1] = 23 # WHAT!?!?!?!?!?!? > >>> b > 2 > > What does the interpreter actually DO with this statement, and why is it > allowed? To what is the value 23 actually bound here? 23 is assigned to the slot at index 1 of the anonymous list created by the list-builder [a, b]. Much the same as, e.g., >>> anonymous = [a, b] >>> anonymous[1] = 23 >>> del anonymous >>> b It appears to be a challenge to dream up a good use for it, though . From huaiyu at gauss.almadan.ibm.com Tue Oct 23 21:32:46 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 24 Oct 2001 01:32:46 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> Message-ID: On Tue, 23 Oct 2001 23:09:01 +0200, Markus Schaber wrote: > >> - presumably multiple "while" parts would be allowed. > >I don't see the sense behind this, could you give me an example where this would be useful and what semantics you have in mind? do: line = f.readline() while not line.is_end(): ... while count < max: ... If it's in the middle of a loop, it should be able to replace the 'if not: break' idiom, which could occur multiple times. >> One small problem is whether the while part should be indented or not: >> It is more like a "case" statement (with fall through) than an "elif" >> statement. > >You mean that while is more indented than do, and the statements are further indented? I'm afraid this would be too complex for programmers and parsers to handle. > >if/elif/else use same indentation level, also try/except/finally use the same indentation level. But those branches are exclusionary. The above example is like while 1: ... if line.is_end(): break ... if count >= max: break ... The different blocks in the body are actually segments in one flow. So the spelling should be something like (notice no colon after while) loop: ... while not line.is_end() ... while count < max ... and the current while-statement could be spelt as loop: while ... ... The 'until' structure proposed by someone would be spelt as loop: ... while not ... This of course would change the meaning of the keyword, so it's not going to happen. BTW, just to show that there are more variations on this topic than currently being discussed, there was recently a thread about prime algorithms. I found that the clearest pseudocode would look like def getprimes(x): primes = [] for n in range(2, x): for p in primes while p*p <= n: if n % p == 0: break else: primes.append(n) return primes I have not been able to translate this into Python without using duplicate code or temporary variables - not sure about iterators as I haven't tried 2.2 yet. This would also be handy for list comprehensions. In analogy to >>> a = range(10) >>> [x for x in a if (x-5)**2 > 4] [0, 1, 2, 8, 9] we could have >>> a = range(10) >>> [x for x in a while (x-5)**2 > 4] [0, 1, 2] Thinking about this - perhaps the real problem is multiple exits for loops - at least one normal end to loop and another abnormal end. Huaiyu From paul at boddie.net Tue Oct 9 10:30:28 2001 From: paul at boddie.net (Paul Boddie) Date: 9 Oct 2001 07:30:28 -0700 Subject: python -i References: <3BC27C3C.732C6A6B@engcorp.com> Message-ID: <23891c90.0110090630.5650a9a5@posting.google.com> epchaves at yahoo.com.br wrote: > > if i do: python -i myfile.py > the output is OK: ??????aaa > > but if i do: python myfile.py > the output isn't the expected: ??????aaa Could there be a file defined in the PYTHONSTARTUP environment variable which makes it work as expected? Have you checked the documentation to see which other start-up resources might be affecting your results? For what it's worth, using Python 2.0.1 on Windows NT 4.0, invoking the lower method on a string of characters in an interactive session within an MS-DOS window doesn't yield complete success: >>> print "??????AAA".lower() ??????aaa >>> The same operation works both from within a script and interactively in IDLE: >>> print "??????AAA".lower() ??????aaa >>> It's virtually meaningless to test running a script with or without -i at the MS-DOS prompt, given the strange characters that are returned, but if one sends the output data to a file, one sees the same output as in the first case above for both interactive and non-interactive script execution. Now, when I try Unicode, things work out a bit better. Here's my script: print u"??????AAA".lower().encode("cp1252") print u"??????AAA".lower().encode("iso8859-1") Here are the results (for both with and without -i): ??????aaa ??????aaa Sadly, this doesn't work interactively at the MS-DOS prompt, but it does work in IDLE. No, I don't know what all this means, unfortunately, apart from that Unicode is the only thing you may be able to rely on, and that MS-DOS boxes on Windows NT can't necessarily be trusted (hardly a big surprise, that). That's not too surprising, given the potential for ambiguity with standard character strings. Paul From logiplexsoftware at earthlink.net Wed Oct 31 16:11:21 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 31 Oct 2001 13:11:21 -0800 Subject: python development practices? In-Reply-To: References: Message-ID: <0110311311210A.06896@logiplex1.logiplex.net> On Wednesday 31 October 2001 12:20, James_Althoff at i2.com wrote: > Absolutely! The ability to change a class implementation whilst preserving > backwards compatibility via the safety net of method access has saved the > derriere on numerous occasions. (The very notion of hard-coded access to > instance variables strewn about in random pieces of code in a large system > just flat-out gives me the willies. For me, the really important thing is > actually *to buy into* the idea of encapsulation). Encapsulation is as much a part of data hiding as private variables. However, it would be nice to have a mechanism so that derived classes wouldn't have to be careful of accidentally stepping on the attributes of base classes. As I said earlier, a class should be a "black box". Authors of derived classes shouldn't have to look at the internals of base classes to avoid this, especially since, as we were discussing, the internals of the base class could conceivably change, introducing name-collisions in derived classes. A single underscore will not prevent this. For instance: class Base: def __init__(self): self._foo = 1 class Derived(Base): def __init__(self): Base.__init__(self) self._x = 1 self._y = 2 No problem here, but later, the author of Base decides to add a self._x to Base. Now Derived is undoubtedly broken and it won't be clear why. A private variable mechanism that could prevent this scenario would be a definite benefit. Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From michael.niemetz at he2.de Wed Oct 10 05:06:22 2001 From: michael.niemetz at he2.de (Michael Niemetz) Date: 10 Oct 2001 02:06:22 -0700 Subject: How to install on NT without write permissions to c:\winnt Message-ID: <81363cf9.0110100106.d3202c3@posting.google.com> Hello! I want to install Python on a Win NT machine at which I do not have administrator privileges and - even worse - have no write permission in the c:\winnt directory which breaks the install process. Is there any way to get Python installed without contacting our local support team and filling out numerous forms? Thanks for your help! Michael From logiplexsoftware at earthlink.net Thu Oct 11 17:58:09 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Thu, 11 Oct 2001 14:58:09 -0700 Subject: Does Python license permit embedding in commercial product ? In-Reply-To: <8a12e538.0110111318.76668cf3@posting.google.com> References: <8a12e538.0110111318.76668cf3@posting.google.com> Message-ID: <01101114580900.06046@logiplex1.logiplex.net> On Thursday 11 October 2001 14:18, Russell Turpin wrote: > This is sort of the opposite case of wanting to sell a program > written in Python, which clearly is allowed. Consider a > commercial product that needs a scripting language. One > obvious way to achieve this, which I'm sure all here would > encourage, is to (a) embed Python in the product, then when > a script for the product is invoked to (b) create a code object > from the script, (c) bind Python variables to appropriate > internal state, (d) execute the code object, and (e) update > internal state from Python variables. > > All of this can be done without modifying Python's source > code. (I hope. I haven't actually tried this, but the principle > seems clear.) The question is whether doing so infringes on > Python's license, given that the product is commercially sold, > and maybe even some of the scripts subsequently provided. My > naive reading is that this is OK. But I thought I would seek > the broader opinion here. I believe there are several commercial applications that use Python as a scripting language, here's a couple: Blender (yes, there's both commercial and free versions - and they are different, in fact, I believe Python support was at one time only available in the commercial version) http://www.blendermania.com/tutorials/tutor/theiceman/genodoespython.php3 Poser http://www.curiouslabs.com/products/proPack/python/ and probably many more. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From phd at phd.pp.ru Thu Oct 18 11:27:41 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 18 Oct 2001 19:27:41 +0400 Subject: mimedecode.py version 1.0.3 Message-ID: <20011018192741.H25821@phd.pp.ru> Hello! MIME decode WHAT IS IT Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is very good because it allows us to use apropriate formats/encodings/whatever. Sometimes, though, some unification is desireable. For example, one may want to put mail messages into an archive, make HTML indicies, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary atachmetnts will be much desireable. Here is the solution - mimedecode.py. This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which treated as an RFC822 mesage, and decoded to stdout. If the file is not an RFC822 message the file just piped to stdout one-to-one. If it is a simple RFC822 message it is just decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts decoded. Decoding can be controlled by command-line options. WHAT'S NEW in version 1.0.3 Minor code refactoring. Added -f charset option that forces this charset to be the current default charset instead of sys.getdefaultencoding(). WHERE TO GET Master site: http://phd.pp.ru/Software/Python/#mimedecode Faster mirrors: http://phd.by.ru/Software/Python/#mimedecode http://phd2.chat.ru/Software/Python/#mimedecode Requires: Python 2.0+ (actually tested with 2.1.1), configured mailcap database. Documentation (also included in the package): http://phd.pp.ru/Software/Python/mimedecode.txt http://phd.by.ru/Software/Python/mimedecode.txt http://phd2.chat.ru/Software/Python/mimedecode.txt AUTHOR Oleg Broytmann COPYRIGHT Copyright (C) 2001 PhiloSoft Design LICENSE GPL Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From BrianQ at ActiveState.com Fri Oct 19 15:04:17 2001 From: BrianQ at ActiveState.com (Brian Quinlan) Date: Fri, 19 Oct 2001 12:04:17 -0700 Subject: Mirror site for tcl/tk? In-Reply-To: <9qplid$q3h$1@netnews.upenn.edu> Message-ID: <001901c158d0$da1a19b0$b503a8c0@activestate.ca> Paul wrote: > My browser can't locate dev.scriptics.com. Does anyone know of a > mirror site for tcl/tk so I can get Tkinter up and running? I believe that the new site is: http://tcl.activestate.com Let me know if you can't find what you want there. Cheers, Brian -- Brian Quinlan BrianQ at ActiveState.com From fredrik at pythonware.com Mon Oct 29 15:46:52 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Oct 2001 20:46:52 GMT Subject: detecting and creating directories References: <3BDDA7BC.8CF7C891@mitre.org> Message-ID: <0fjD7.3353$Z_1.574942@newsc.telia.net> Steve wrote: > import os > path = "/usr/tmp/newdir" > if os.path.exists(path): > if not os.path.isdir(path): > raise ValueError, "%s exists but is not a directory" % path > else: > os.mkdir(path) for ten extra points, explain why this is a lousy way to do this. From madsdyd at challenge.dk Mon Oct 1 07:19:43 2001 From: madsdyd at challenge.dk (Mads Bondo Dydensborg) Date: Mon, 1 Oct 2001 13:19:43 +0200 (CEST) Subject: Python embedding & question about autoconf and dynamic linking In-Reply-To: <9p9hmn$2dj$1@kermit.esat.net> Message-ID: On Mon, 1 Oct 2001, Olivier Deme wrote: > I am myself into the same situation... > I am trying to link my C application against libpython and I get > unresolved symbols with posix thread related symbols. Why the heck > would I need the posix thread library if I never create any thread ?!? Python needs it. This is not so strange. The annyoing thing is, that other libs, like gtk, often have a gtk-config command you can call, to help you determine these sort of things - Python has no such thing. (At least I haven't found it :-) I guess we could write one - but that does not solve our problem with old versions of Python > > Why is it so difficult to do something as common as this? I think it is more common to extend Python, than to embed it. I knew nothing about Python (apart from the name) a week ago, so I may be wrong though. Mads -- Mads Bondo Dydensborg. madsdyd at challenge.dk Estimates of online gamers in the United States alone run as high as 15 to 20 million people. - Jon Katz, Slashdot, on youth culture. From cheah at comline.com.my Wed Oct 17 23:49:01 2001 From: cheah at comline.com.my (Alec D. Cheah) Date: 17 Oct 2001 20:49:01 -0700 Subject: Verified Input. Message-ID: <4783f0eb.0110171949.125344dc@posting.google.com> How do verified from input the variable entered is a file or a path and how do you check whether it exist or not?? Help... Newbie on Python.... From richard at bizarsoftware.com.au Thu Oct 18 19:37:50 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 19 Oct 2001 09:37:50 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: References: Message-ID: <0110190937503G.11044@ike> On Thursday 18 October 2001 22:26, Steve Holden wrote: > "Anthony Baxter" wrote ... > > > >>> "Tim Peters" wrote > > > > > > The bugfix release process is the topic of Aahz's PEP 6, who may have > > > believed that titling it "Bug Fix Releases" was enough clue : > > > > Ah, that cunning "hidden in plain sight" approach. Who'd have thought. > > Gets *me* every time... > > > It still doesn't cover the process of deciding what would go in the > > patch release... I know that I'd be happier upgrading to 2.1.2 than > > 2.2 in the next couple of months - and given the peasants-are-revolting > > sentiment of c.l.py at the moment, I doubt I'm the only one... > > It's only the fatc that they're revolting that identifies them as peasants. > Seriously, though, there are many good reasons why you might not want to > upgrade, including having a large and varied hardware base and wanting to > keep all Pythons roughly in step. Actually, my biggest reason for not going to 2.2 is that it introduces a bunch of new stepwise changes to the code. New code == new bugs as far as I'm concerned. This is not the way to go if your prime intention is to aim for less bugs. Richard From sholden at holdenweb.com Thu Oct 4 23:47:03 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 23:47:03 -0400 Subject: Mutable default values for function parameters References: Message-ID: "Ignacio Vazquez-Abrams" wrote in message news:mailman.1002232865.30569.python-list at python.org... > On Thu, 4 Oct 2001, Brian Quinlan wrote: > > > Here is my proposed expression: > > > > d = ((d is not None and [d]) or [[]])[0] > > > > Here is the test: > > > > def test(d = None): > > return ((d is not None and [d]) or [[]])[0] > > > > assert test() == [] > > assert test(None) == [] > > assert test(0) == 0 > > assert test('') == '' > > assert test(5) == 5 > > assert test([1,2,3]) == [1,2,3] > > > > I believe that those are the semantics that you are looking for? And > > so easy to understand... > > This is your brain on drugs. Any questions? ;) > Yes. Why isn't he sharing them round? don't-bogart-that-joint-ly y'rs - steve From com-nospam at ccraig.org Thu Oct 18 10:10:19 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 18 Oct 2001 10:10:19 -0400 Subject: Conditional Expressions don't solve the problem In-Reply-To: References: Message-ID: salemail at dial.pipex.com (Kevin D) writes: > Can I assume that's IYHO ? Please elucidate on what, exactly, numbs > your mind about them. I've tried to reason out what I thought were the > issues that cause this thread to appear periodically (modulo "it isn't > like C") and suggest syntax that fixes those problems. > > Can we at least agree that the issues I listed _are_ problems ? If > not, please give reasons. > I do appreciate your not trying to make Python like C. I will try to qualify my reservations. Here is your original suggestion (just because I don't like replying to it without it being quoted): ] Something like: ] ] while foo != terminating_condition; given foo = some_long_expression: ] body_of_loop() ] ] or maybe "where": ] ] while foo != terminating_condition; where foo = some_long_expression: ] body_of_loop() ] ] This would extend to 'if'/'elif': ] ] if m is not None; where m = compiled_re.match(inputline): ] stuff(m) ] elif m is not None; where m = compiled_re2.match(inputline): ] otherstuff(m) My problems with it: 1) Foo is assigned after foo is referenced. This is ugly and requires a second pass by the compiler which currently no Python construct does. 2) This syntax is complicated. It seems un-Pythonic to me to have more than one statement per line. > [ my stuff about do: until loops ] > I don't see what _problem_ this is addressing. You're just > substituting words. I was actually trying to _identify readability > issues_ with this construct and fix them. But even your suggestion doesn't really contribute that much. while ; where : could also be expressed as while 1: if not : break The problem, as you pointed out, is that the second form is ugly. It is not really a while loop, yet uses the keywords of one. Thus in addition to the 'while' form in Python, we frequently see a special 'while 1: if not' form. I see presenting it as loop: until as being more intuitive and still keeping one statement per line. (It also generalizes to loop: until for when you need multiple statements in your initialization. That said, I'm not sure there is sufficient motivation to add two keywords just for sugar. > > Additionally I think that the present system is not that hard to adapt to. > > Remembering to prefix all your string variables with '$' and all your > integer variables with '%' isn't "hard to adapt to". Plenty of BASIC > newbies did. That doesn't mean that there aren't better ways of doing > it :) -1 me. That said, many of the posts in this thread have been advocating change, not because the change is better, but because Python doesn't fit their method of writing programs. I personnally don't think that your change adds enough functionality to justify putting the usage of a variable before its assignment, but my opinion doesn't count for that much, so take that for what it's worth. -- Christopher A. Craig From jdunnett at uoguelph.ca Tue Oct 30 10:16:47 2001 From: jdunnett at uoguelph.ca (Jeffrey Dunnett) Date: 30 Oct 2001 15:16:47 GMT Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <9riefm$tseam$1@ID-11957.news.dfncis.de> <3BDCC4C9.B0597DF1@uoguelph.ca> <8djpttobn2i18avnq3817bmg1ua6eavq8r@4ax.com> $1I3.435326 at atlpnn01.usenetserver.com> <3BDE4A4D.92C0FBC at engcorp.com> : Distribution: Steve Holden (sholden at holdenweb.com) wrote: : "Peter Hansen" wrote ... : > Steve Purcell wrote: : > > : > > Steve Holden wrote: : > > > But it wasn't that funny, since nothing is ever simply black or white, : good : > > > answers must always conside the graze. : > > : > > I hope the original poster won't be cowed by these yokes at his expense. : > : > Look guys, this is a bunch of bull. Can we just moove on? : > : I herd you, Peter, but this leaves me on the horns of a dilemma. I guess I : shoud hide for a while. : regards : Steve : -- : http://www.holdenweb.com/ Ok guys don't you thinking your milking this name pun game a little to much Jeff From vulpine at dontspam.earthling.net Wed Oct 3 14:08:54 2001 From: vulpine at dontspam.earthling.net (Tod Fox) Date: Wed, 03 Oct 2001 18:08:54 GMT Subject: Past command buffer gone in interpreter? References: <5536892.9nUPlyArG6@lunix.schabi.de> Message-ID: Markus Schaber wrote: > Tod Fox schrub: > It seems that your Python version is compiled without readline support. > If you did compile it yourself, check your configure options, otherwise > check the location you got the packages whether they offer a version > compiled with readline support. I will look into this and recompile it with 'readline' support turned on. Thanks for the suggestion. Kit From tim.one at home.com Mon Oct 29 02:01:28 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 29 Oct 2001 02:01:28 -0500 Subject: Dictionary from list? In-Reply-To: Message-ID: [Greg Chapman] > On the subject of slippery mappings and the dictionary constructor, > consider a subclass of dictionary which overrides __getitem__ to > transform the value stored in the (inherited) dictionary structure to > the "real" value stored in the (logical) mapping defined by the > dictionary subclass. (For example: a dictionary subclass which supports > a defined order of iteration by using nodes in a linked list to store > the keys and values, and then storing the keys and nodes in the > dictionary structure). In the 2.2b1, if an instance of such a > subclass is passed to the constructor (or to the update method) > of a normal dictionary, the overridden __getitem__ is ignored because > of the PyDict_Check near the top of PyDict_Merge. Yes. Note that this isn't unique to dicts -- if, for example, you subclass list, list(instance_of_that_list_subclass) doesn't look up list.__getitem__ either. They all work this way. > I'd like to suggest that that check be changed to PyDict_CheckExact > (which apparently does not exist yet, but would be analogous > to PyString_CheckExact). This would shunt dictionary subclasses into the > generic mapping branch of PyDict_Merge, which would allow an overridden > __getitem__ to work. I agree that it would. Whether it *should* is something you'll have to take up with Guido. Subclassing builtins is a tricky business. Note that you *can* fiddle your subclass to change what's stored, by overriding __init__. A list example is clearer than a dict one simply because less involved: class L(list): def __init__(self, arg): list.__init__(self, arg) for i in range(len(arg)): self[i] = arg[i] * 100 def __getitem__(self, i): return 666 x = L(range(3)) print x, list(x) That prints [0, 100, 200] twice. The second one isn't what you want today (or so I predict), but it's clear as mud (to me) what most people will want most often. Is list() *defined* in terms of __getitem__? Not really, not even under the covers (it's defined more in terms of the iterator protocol now). What is dictionary() defined in terms of? It simply isn't spelled out yet. With the dictionary() in current CVS, dictionary(subclass) won't pay attention to a __getitem__ override, and dictionary(subclass.items()) won't either but will (trivially) pay attention to an .items() override. Python usually resolves questions of this nature by picking the answer that's easier to explain. Since subclassing builtins in Python can't override the builtin representation, I bet Guido will say current 2.2b1 behavior is easier to explain. It's sure debatable, though. > Alternatively, the PyDict_Check could be supplemented by a check to see > if __getitem__ has been overridden (and if so, using the generic > code). However, this would not help a subclass which transforms its > keys in some way (so that PyMapping_Keys returns a different set of keys > than that stored in the dictionary structure). (I suppose the check > could be extended to look for an overridden keys method.) That's the problem, isn't it? You can't guess what's going to happen without studying the implementation code. Since subclassing builtins is brand new, Python takes "shortcuts" *all over the place* internally (the marvel to me isn't that you discovered this about dict.update(), but that you didn't stumble over 100 others before it ). They weren't shortcuts before 2.2 -- they were just the obvious ways to implement things. Now they look like shortcuts, "avoiding" thousands of lines of fiddly new code to worry about "oops -- maybe this isn't a 'real' str, list, tuple, dict, file, complex, int, long, float, let's do a long-winded dance to see whether it's a subclass". I expect it will take years to resolve all that. In the meantime, exactly when the assorted magic methods get called for instances of subclasses of builtins is going to be unclear and sometimes surprising. I also expect changes to be driven by compelling use cases (for example, people have been very vocal over the years about wanting to pass a dictionary substitute to eval(), so it's no accident that case works for dict subclasses in 2.2b1). And I also expect that some arguably good changes will never get made (e.g., because of the central role dicts play throughout Python's implementation, anything catering to dict subclasses that slows "real dicts"-- even a little --is going to be a difficult sell). good-thing-python-never-gave-a-rip-about-theoretical-purity-ly y'rs - tim From mk at ji.cz Fri Oct 12 09:52:16 2001 From: mk at ji.cz (=?iso-8859-2?Q?Marek_Kro=E8=E1k?=) Date: Fri, 12 Oct 2001 15:52:16 +0200 Subject: Semantic indentation (OpenGL) Message-ID: I am very very sorry for opening such a topic again. Before anything else I must say that I *love* Python's way of treating indentation. When I was at school we were doing a lot of OpenGL (in VC++). I have often (not always but many times) used following way of indentation for making my code a bit cleaner: glBegin(GL_POINTS); ... glVertex3f(...); ... glEnd(); These are syntactically at the same level (compiler's point of view), but semantically not (library's point of view). Unfortunately python does not allow me to use this formatting any more. I wonder how (whether?) do other programmers cope with this. Actually this is not a problem, I am just curious. -- Marek Kro??k (Marek Krocak) mk at ji.cz From robin at jessikat.fsnet.co.uk Tue Oct 16 13:39:30 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 16 Oct 2001 18:39:30 +0100 Subject: fast sub list operations References: <3BCC4C52.7F0881A4@letterror.com> Message-ID: In article <3BCC4C52.7F0881A4 at letterror.com>, Just van Rossum writes >Robin Becker wrote: >> >> I constantly miss some nice way to subset lists. As an example suppose I >> have a list of x y coordinates eg >> >> [x0,y0,x1,y1,.....] >> >> and wish to perform the operation x->x+v, y->y+w for the co-ordinates in >> the list I don't seem to be able to do this fast using map. Even if I >> had a way to slice the list nicely into >> >> X=[x0,x1,.....x(n-1)] & Y=[y0,y1,.....,y(n-1)] >> >> so that I can do map(operator.add,X,n*[v]) to perform the arithmetic >> quickly I don't seem to have an interlace to get back to the original >> list format. >> >> How can these kinds of operations be performed quickly in current python >> and what if any new features would python require to do them best? > >Your problem is not with missing Python features but with your data >structure. Why not use [(x0, y0), (x1, y1), ...] instead? > >Just I didn't actually choose the data structure. Actually in this case Just the points are the lists of points from your Path class in reportlab.graphics.shapes, but I guess you didn't choose the base representation for lists of points either :-) -- Robin Becker From logiplexsoftware at earthlink.net Wed Oct 24 15:54:23 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 24 Oct 2001 12:54:23 -0700 Subject: Critical sections and mutexes In-Reply-To: References: Message-ID: <01102412542300.24656@logiplex1.logiplex.net> On Tuesday 23 October 2001 18:33, brueckd at tbye.com wrote: > No, "normal" operations on Python objects are atomic as far as threads are > concerned. There are some very good reasons for using locking/signaling > (to sequentialize access to a function, to keep a worker thread asleep > until you use a semaphore to signal it to awake, etc), but it's not always > a requirement. Consider a simple producer/consumer situation: True, I may have overstated it a bit, however, I would expect that the typical multi-threaded application is going to do things that require more than a single-line of python to manipulate data, i.e. len() prior to append() or pop() or whatever. If another thread alters the list (or other mutable object) between the call to len() and append() (or whatever) then the value returned from len() may be invalid. Unless you are a very careful programmer, you are asking for trouble that can be difficult to track down. In this case, the person asking for help clearly has little experience with threads and wrapping all shared objects in locks would be a safer choice for him. Regards, -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From phd at phd.pp.ru Tue Oct 2 15:58:31 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 2 Oct 2001 23:58:31 +0400 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <5.1.0.14.2.20011002115026.02c780e8@cedar.he.net>; from paul@fxtech.com on Tue, Oct 02, 2001 at 11:58:52AM -0500 References: <1002040943.560.290.l9@yahoogroups.com> <5.1.0.14.2.20011002115026.02c780e8@cedar.he.net> Message-ID: <20011002235831.E25358@phd.pp.ru> On Tue, Oct 02, 2001 at 11:58:52AM -0500, Paul Miller wrote: > Trying to make me into a cheap-skate and a thief doesn't endear me too much > to you Oleg. But of course! > The issue is not whether I use people's work without paying them - if they > didn't want me to, they would CHARGE for it. This is exactly how the GPL works - it charges for my code. You can pay me money, or you can pay me by opening your code. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From gh_pythonlist at gmx.de Fri Oct 5 09:20:56 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 5 Oct 2001 15:20:56 +0200 Subject: list to tuple question In-Reply-To: <20011005145218.A539@lilith.hqd-internal>; from gh_pythonlist@gmx.de on Fri, Oct 05, 2001 at 02:52:18PM +0200 References: <3bbdc533_6@news.newsgroups.com> <20011005145218.A539@lilith.hqd-internal> Message-ID: <20011005152055.A873@lilith.hqd-internal> On Fri, Oct 05, 2001, Gerhard H?ring made a fool of himself writing: > On Fri, Oct 05, 2001 at 04:35:25PM +0200, Janos Blazi wrote: > > I'd like to make a formatted string like this: > > > > s='%s %s %s %s %s %s %s %s %s\n' % (A,)+b+(C,D) > > [...] > Concatenate lists: [A,]+b+[C,D] Please ignore my previous stupid post. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From robin at jessikat.fsnet.co.uk Tue Oct 16 13:29:32 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 16 Oct 2001 18:29:32 +0100 Subject: fast sub list operations In-Reply-To: <15308.17945.822446.173014@beluga.mojam.com> References: <15308.11525.102304.624520@beluga.mojam.com> <15308.17945.822446.173014@beluga.mojam.com> Message-ID: In message <15308.17945.822446.173014 at beluga.mojam.com>, Skip Montanaro writes > >> >>> zip([1,2,3],[7,8,9]) > >> [(1, 7), (2, 8), (3, 9)] > > Robin> I know about NumPy and like it a lot, but it's a bit heavyweight > Robin> for what we need. I also know about zip and apart from there > Robin> being no unzip it doesn't join up my list which should look like > Robin> [1,7,2,8,3,9]. > >Whoops... Try this instead: > > >>> l = zip([1,2,3],[7,8,9]) > >>> reduce(operator.add, l, ()) > (1, 7, 2, 8, 3, 9) > >Obviously, if you need a list, you can apply that function to the result. > that's nice from pairs to a simple tuple -- Robin Becker From ajm at enteract.com Mon Oct 8 17:39:17 2001 From: ajm at enteract.com (Alan Miller) Date: Mon, 8 Oct 2001 16:39:17 -0500 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> Message-ID: Aahz Maruch (aahz at panix.com) wrote: >Laura Creighton wrote: >>I know of 2 companies that considered doing their development work in >>Python but concluded that though the core language was terrific, the >>libraries were fragmentary, incomplete, and not up to the vigorous >>standards they had come to expect from other languages such as C++. > > Stock C++ has better libraries than Python? In some ways it might for commercial development, though perhaps not off the shelf. The standard libraries in Python are good, but quite a bit of functionality is added through libraries that are GPL'd. Sure it's possible to get in touch with the authors of various packages and negotiate your own licenses with them, but the combination of that _and_ a new programming language might well be enough to scare off companies. I know that very issue has been a concern to me and has kept me from pushing harder to get Python widely accepted internally - since we're developing closed-source software, being able to keep it closed is important. Sure it's possible to negotiate licenses, but if it takes significant time internally plus a few hundred dollars in licensing fees are we much better off than if we'd gone out and bought a commercial library for $200? If nothing else the company is large enough that purchasing off-the-shelf libraries is pretty simple, while negotiating licenses is less so. ajm From dharland at surfanytime.co.uk Wed Oct 24 15:15:20 2001 From: dharland at surfanytime.co.uk (dharland) Date: Wed, 24 Oct 2001 20:15:20 +0100 Subject: Critical sections and mutexes References: Message-ID: <3bd713a4$1_1@news1.vip.uk.com> "David Brady" wrote in message news:mailman.1003946245.30925.python-list at python.org... > > -----Original Message----- > > From: brueckd at tbye.com [mailto:brueckd at tbye.com] > > No, "normal" operations on Python objects > > are atomic as far as threads are concerned. > [snip] > Interestingly, in several sets of tests, I discovered > that print statements aren't entirely atomic; tightly > threaded code can interrupt a print statement after > the text, but before the newline has been printed: This is because what really is atomic in python are not "operations" but Python bytecode. And print "Boo!" for example is implemented in at least three bytecodes (LOAD_FAST, PRINT_ITEM, PRINT_NEWLINE), hence the behavoiur you see with the newline. From max at alcyone.com Wed Oct 31 10:53:51 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 07:53:51 -0800 Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> Message-ID: <3BE01E8F.3A384D4C@alcyone.com> Oleg Broytmann wrote: > On Wed, Oct 31, 2001 at 08:08:22AM -0600, Kemp Randy-W18971 wrote: > > Check out the free Python editor at www.crimsoneditor.com. > > Free (like free beer), but not free (like freedom). No source code, > Windows only. And consistent with the term "freeware," as the Subject states. There's a time for open source advocacy, but it isn't here and now. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From spaceman at bsdzine.org Tue Oct 23 04:22:41 2001 From: spaceman at bsdzine.org (Karol Makowski) Date: 23 Oct 2001 08:22:41 GMT Subject: Python for ipaq Message-ID: hello Do you know where can i find python for compaq ipaq pocket pc running Windows CE? And second question: i need a _simple_ ftp client written in python (using ftplib) which will store some files on server and will get other files from server. I need to put it in my C program via the system(); Thanks! -- Karol Makowski, System Administrator URL: http://spaceman.bsdzine.org e-mail: spaceman at bsdzine.org From sholden at holdenweb.com Tue Oct 16 17:31:19 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 16 Oct 2001 17:31:19 -0400 Subject: Directed input References: <9qi4r2$gpq$1@nserve1.acs.ucalgary.ca> Message-ID: "Kragen Sitaker" wrote in message news:BR0z7.1417$Z2.283368 at e420r-atl2.usenetserver.com... > In article <9qi4r2$gpq$1 at nserve1.acs.ucalgary.ca>, > Michael Yuen wrote: > >I'm just in the process of learning Python right now and i'm wondering if > >there's a way run a program to take a file via directed input and > >sending output to another file via the command line. > > > >Here's what I mean: > > > >myprogram.py < my_input > my_output > > I assume you're on Unix? The above should work fine. If, however, you are on Windows NT, you will find that a bug in the command processor (NT's, that is) stops redirection from working on commands where the executable is deduced from a file extension. Therefore in this environment you need: python myprogram.py < my_input > my_output This is also required on Win95/98 (except cygwin/bash, which is pretty Unix-like on all Windows flavors). regards Steve -- http://www.holdenweb.com/ From emile at fenx.com Wed Oct 31 19:58:25 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 31 Oct 2001 16:58:25 -0800 Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <9rp4d8$830$1@tyfon.itea.ntnu.no> <3BE0240A.A2CCAA83@alcyone.com> <3BE099F6.A9E0708F@alcyone.com> Message-ID: <9rq70r$ve8u6$1@ID-11957.news.dfncis.de> "Erik Max Francis" wrote in message news:3BE099F6.A9E0708F at alcyone.com... > Paul Winkler wrote: > > > But this was before my time. Can anyone who was hacking in the 70s/80s > > comment on the evolution of these terms? When did "freeware" come to > > mean "free beer, no source"? > > In the eighties, _freeware_ was a very common term which simply meant > that the software was freely available for (sometimes non-commercial > only) use. Whether source code was available for free, available for a > fee, or not available at all was a totally separate question. > > >From the Jargon file: freeware /n./ Free software, often written by enthusiasts and distributed by users' groups, or via electronic mail, local bulletin boards, Usenet, or other electronic media. At one time, `freeware' was a trademark of Andrew Fluegelman, the author of the well-known MS-DOS comm program PC-TALK III. It wasn't enforced after his mysterious disappearance and presumed death in 1984. See shareware, FRS. ----- Also of interest: all the -ware terms from the Jargon file: annoyware bloatware brochureware careware charityware crippleware crudware firmware freeware fritterware guiltware liveware meatware nagware payware postcardware psychedelicware shareware shelfware shovelware treeware vaporware wetware ------- Obvious by their absence from this list are: hardware software ----- And a term I remember, but also not on the list: trialware (a forerunner of nagware, only the sales reps called you) --- Other -wares that shoulda been: dongleware (only works when your printer doesn't ;-) timeware (stops working on lapse of maintenance contract) -- Emile van Sebille emile at fenx.com --------- From phd at phd.pp.ru Wed Oct 17 16:29:10 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Thu, 18 Oct 2001 00:29:10 +0400 Subject: mimedecode.py version 1.0.2 Message-ID: <20011018002910.A21401@phd.pp.ru> Hello! MIME decode WHAT IS IT Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is very good because it allows us to use apropriate formats/encodings/whatever. Sometimes, though, some unification is desireable. For example, one may want to put mail messages into an archive, make HTML indicies, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary atachmetnts will be much desireable. Here is the solution - mimedecode.py. This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which treated as an RFC822 mesage, and decoded to stdout. If the file is not an RFC822 message the file just piped to stdout one-to-one. If it is a simple RFC822 message it is just decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts decoded. Decoding can be controlled by command-line options. WHAT'S NEW in version 1.0.2 Minor code refactoring; few bug fixes. WHERE TO GET Master site: http://phd.pp.ru/Software/Python/#mimedecode Faster mirrors: http://phd.by.ru/Software/Python/#mimedecode http://phd2.chat.ru/Software/Python/#mimedecode Requires: Python 2.0+ (actually tested with 2.1.1), configured mailcap database. Documentation (also included in the package): http://phd.pp.ru/Software/Python/mimedecode.txt http://phd.by.ru/Software/Python/mimedecode.txt http://phd2.chat.ru/Software/Python/mimedecode.txt AUTHOR Oleg Broytmann COPYRIGHT Copyright (C) 2001 PhiloSoft Design LICENSE GPL Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From phd at phd.pp.ru Tue Oct 30 08:08:52 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 30 Oct 2001 16:08:52 +0300 Subject: File upload in python module? In-Reply-To: ; from wayne@tbnets.com on Tue, Oct 30, 2001 at 07:53:48AM -0500 References: Message-ID: <20011030160852.C1342@phd.pp.ru> On Tue, Oct 30, 2001 at 07:53:48AM -0500, Wayne Ringling wrote: > I am working on a web project that needs a way to upload a gif or jpg (or > any file I guess) to a web server via the web interface. I have seen them in > perl and java. I am trying to use all python. Is there a python module or > script already done to handle this? I looked thru the module list at > python.org but didn't see anything that looked like it would handle it. > Maybe I missed it. Any pointers or ideas. Thanks cgi.py handles uploads, too. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From johnmc at velseis.com.au Thu Oct 25 19:26:40 2001 From: johnmc at velseis.com.au (John McMonagle) Date: Fri, 26 Oct 2001 09:26:40 +1000 Subject: Tkinter.Listbox: activate() doesn't work References: Message-ID: <3BD89FB0.1010507@velseis.com.au> Theodore D. Sternberg wrote: > How can I programmatically activate an element in a Tkinter.Listbox? > I've tried activate() but nothing happens. For example, > > import Tkinter > root=Tkinter.Tk() > lb = Tkinter.Listbox(root) > lb.insert( Tkinter.End, 'foo' ) > lb.insert( Tkinter.End, 'bar' ) > lb.pack() > lb.activate( 1 ) > > ...but I don't see 'bar' now getting highlighted. What am I doing wrong? > > You are doing nothing wrong at all - the activate method sets the element specified by the given index as active when the listbox widget has input focus. One way of setting the input focus is by tabbing to the desired widget - try this and you will see the desired behaviour. Note: an active element is not equivalent to a selected element. To select elements you can use the selection_set method. Regards, John From bit_bucket5 at hotmail.com Fri Oct 26 10:27:10 2001 From: bit_bucket5 at hotmail.com (Chris) Date: 26 Oct 2001 07:27:10 -0700 Subject: mysql + mxdatetime query problem--datetime not returned sometimes Message-ID: Experiencing a weird problem retrieving a datetime value from a mysql db. Here's what I'm doing, roughly: connection = MySQLdb.connect(db = DB_NAME) cursor = connection.cursor() cursor.execute('select date_entered, description ' 'from issue_actions ' 'where issue_id = ' + selectedIssueId + ' order by date_entered') actions = cursor.fetchall() ...do stuff iterating thru actions, this select works perfectly.... cursor.execute('select description, when_opened from issues where id = ' + selectedIssueId) result = cursor.fetchone() This retrieves the tuple ('issue description',). The mxDateTime object is missing. Every other select I run that gets a datetime works fine. This single instance always just returns the description. If I run this series of commands in the interactive window, all works fine--datetime object is returned (this is in a cgi script, so debugging is a bit harder). If I go into mysql and run it all is fine. I'm completely confused re what's going wrong here. Any ideas? Disclaimer: I'm a database and mysql newbie. Many thanks for any pointers. -Chris From karl at elemtech.com Wed Oct 3 16:05:59 2001 From: karl at elemtech.com (Karl G. Merkley) Date: Wed, 03 Oct 2001 14:05:59 -0600 Subject: MacPython -- Tk problems Message-ID: <3BBB6FA7.1000504@elemtech.com> I just installed MacPython on a Mac OS 9 machine this morning. However, it complained about Tk not working with Carbon. This is on a machine at an elementary school and they are not planning on upgrading the OS anytime in the foreseeable future. The teacher is really excited about using Python in a grade school setting to teach some basic programming skills. Is there anything I can do to get MacPython fully working in this configuration? Thanks From mark21rowe at yahoo.com Tue Oct 23 00:54:13 2001 From: mark21rowe at yahoo.com (Mark Rowe) Date: Tue, 23 Oct 2001 17:54:13 +1300 Subject: POLL in different OSes References: Message-ID: <3bd50785@news.actrix.gen.nz> Hello, >From the interpreter under Windows: Python 2.2b1 (#25, Oct 19 2001, 11:44:52) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import select >>> select.poll Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'poll' >>> dir(select) ['__doc__', '__file__', '__name__', 'error', 'select'] >>> I guess its not :) Mark Rowe "Lucio Torre" wrote in message news:mailman.1003802122.10872.python-list at python.org... > From the documentation: > > "The poll() system call, supported on most Unix systems" > > and my questions: > > a) is poll supported on Windows? > > my guess is no, but i hoping for a yes. > > thanks > > From phd at phd.pp.ru Wed Oct 31 11:40:44 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 31 Oct 2001 19:40:44 +0300 Subject: connecting database In-Reply-To: <29A97D00F387D411AC7900902770E148024B784D@lcoeexc01.coelce.net>; from calves@coelce.com.br on Wed, Oct 31, 2001 at 02:37:35PM -0300 References: <29A97D00F387D411AC7900902770E148024B784D@lcoeexc01.coelce.net> Message-ID: <20011031194044.P21151@phd.pp.ru> On Wed, Oct 31, 2001 at 02:37:35PM -0300, Alves, Carlos Alberto - Coelce wrote: > How can I connect to databases?! By installing apropriate DB API driver. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From anthony at interlink.com.au Wed Oct 31 00:04:18 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Wed, 31 Oct 2001 16:04:18 +1100 Subject: python development practices? In-Reply-To: Message from Peter Wang of "Tue, 30 Oct 2001 23:49:50 CDT." <6YLfO=JIhU1VpcRCSlWyV5uJY4mq@4ax.com> Message-ID: <200110310504.f9V54Ig19035@mbuna.arbhome.com.au> >>> Peter Wang wrote > i don't think data hiding's purpose is to keep rogue programmers in > line. it's partly to insulate imperfect development practice (e.g. > sloppy documentation) and partly to define an interface for a class. But in that case, you're relying on the language to compensate for your development processes... this seems a bit of a problem, particularly since a sloppy/lazy/poorly-informed coder is always going to find a way to screw it up, regardless of whether the language prevents some forms of screwups. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From Armin_member at newsguy.com Fri Oct 12 06:14:55 2001 From: Armin_member at newsguy.com (Armin) Date: 12 Oct 2001 03:14:55 -0700 Subject: Link between a C variable and a python object References: <3BC4366A.DC3F6982@wanadoo.fr> Message-ID: <9q6fqv02o9g@drn.newsguy.com> In article <3BC4366A.DC3F6982 at wanadoo.fr>, guignot says... > >Does Python have a nice feature of Tcl, i.e. linking an external C >variable and an internal variable, with TclLinkVar ? Yes ... have a look to the C API. Armin > >tks in advance... From jnlc at bellsouth.net Wed Oct 31 11:55:49 2001 From: jnlc at bellsouth.net ( 1) Date: Wed, 31 Oct 2001 11:55:49 -0500 Subject: newbie question References: Message-ID: ok to keep it simple. I am running win98se w/ python 2.1 installed. I have tried this in both python shell and in command line. Just to keep it simple I wrote a file called "hello.py". all that it contains is a print command (print" hello world!"). I saved the command in the python dir in my PC and named it "hello.py". When I got to run the file (by typing python hello.py)i get this error message: >>> python hello.py SyntaxError: invalid syntax >>> Is there anything that i missed or did wrong. This is just a simple little example of a bigger problem. "Steve Holden" wrote in message news:TBVD7.12967$0l4.499714 at atlpnn01.usenetserver.com... > " 1" wrote ... > > I must have missed it in the tutorial or some thing. > > > > I want to know how to open and run a file in python. The tutorial said to > > just type " python filename.py" and hit enter. I did this and it comes > back > > with an error message telling me the the file name is not defined. I > wasn't > > told that I had to define it first before I can run it. Is there an easier > > way to run files otherthan defining them? > > > OK. When asking for help, it's usually a good idea to give more rather than > less information, since you may not know what's going to be useful to the > helper. > > In this case I am assuming that the file name that is "not defined" is > python -- in other words, that when you type > > python filename.py > > the system can't find the Python interpreter, rather than the system is > running Python which then cannot find filename.py. If this is the case then > you are going to have to tell your command line interpreter (the Unix shell, > or the NT/W98/W95/W2k cmd.exe program) how to find Python. This will involve > modifying your "path setting". > > If this doesn't help you enough, perhaps you could let us see the exact > error message, and tell us which OS you are using? > > regards > Steve > -- > http://www.holdenweb.com/ > > > > > From emile at fenx.com Wed Oct 24 19:00:23 2001 From: emile at fenx.com (Emile van Sebille) Date: Wed, 24 Oct 2001 16:00:23 -0700 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 24) References: <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E@lp.airnews.net> Message-ID: <9r7hf7$sj7cs$1@ID-11957.news.dfncis.de> "David Bolen" wrote in message news:uadygej41.fsf at ctwd0143.fitlinxx.com... > Oleg Broytmann writes: > > > On Wed, Oct 24, 2001 at 12:59:52PM -0500, Cameron Laird > > wrote: > > > In article <7F3A1C185F74E4DF.70F5900B641ECAAA.8AD96ACD9AEE6E8E at lp.airnews.net>, > > > Cameron Laird wrote: > > > > Two different Cameron Lairds talk to each other? (-: > > Either that or one half of the brain is picking on the other half... > > Then it must be the left side picking on the right side. -- Emile van Sebille emile at fenx.com --------- From jorjun at mac.com Mon Oct 8 05:57:03 2001 From: jorjun at mac.com (jorjun) Date: Mon, 08 Oct 2001 10:57:03 +0100 Subject: Financial modules for Python Message-ID: <3BC17870.EB8CC191@mac.com> I'm looking for tools to help me make mortgage repayment decisions. Couldn't get a working URL for pyfi which contains loan amortization stuff, I think. Can someone help? From johnroth at ameritech.net Tue Oct 30 20:56:24 2001 From: johnroth at ameritech.net (John Roth) Date: Tue, 30 Oct 2001 17:56:24 -0800 Subject: python development practices? References: Message-ID: "Peter Wang" wrote in message news:e1iuttghajb226flvq9jr07ddq229tki38 at 4ax.com... > are there good references on using Python in a commercial, team > development environment? > > i have been advocating and slowly convincing various people in my > company to use Python. i've successfully used it to write a few tools > and an application. however, the general perception is that it is a > good scripting language and possibly acceptable for single-person > development use, but it doesn't afford use in a large-scale software > team. the lack of data hiding, the lack of data coverage tools > (pre-run-time linting), and the lack of interfaces and strong types > are the typical turn-offs, in addition to the minor but omnipresent > tab indentation issue. :-) > > while i feel that Python makes me far more productive as a programmer > for all the projects on which i've worked, i'm inclined to agree that > the lack of data hiding coupled with lack of a standard interface > specification would cause problems in a team. IMHO, the data hiding issue is a red hering. If there's someone on the team where you absolutely need private variables to keep them honest, you've got lots greater problems than the choice of language. In python, if you don't want to export a variable or method, simply prefix it with an underscore. This will tell anyone who really cares that it's private, and if it's used outside, then the code needs to be refactored. There's a PEP outstanding for interfaces, and I presume that it will be seriously considered for 2.3. In any case, if you really need interfaces, it's possible to write one in Python, although it wouldn't look very pretty. As far as causing problems in a team environment, the eXtreme program folks at comp.software.extreme-programming like python - and that development methodology carries team orientation to an eXtreme. I'm not sure what you mean by 'data coverage tools.' If you mean a code coverage tool to check whether the unit tests cover everything, look on the Vaults of Parnassus. PyCover is acceptable, although it could use a bit more work. There's also some code inspection tools, but I don't remember the name. Tab versus space indentation is simply a matter of setting team standards. If you want to be very anal about it, you can always set up an enforcement mechanism at code checkin, when you insure that all your unit tests run to 100%. You do that, don't you? > how do Python development teams get around these issues? does using > Python in a commercial software team simply require more disciplined > programmers? Programming requires discipline. Period. If you're depending on a compiler to catch sloppy thinking, then you've got trouble. John Roth From quinn at hurl.ugcs.caltech.edu Mon Oct 22 03:19:46 2001 From: quinn at hurl.ugcs.caltech.edu (Quinn Dunkan) Date: 22 Oct 2001 07:19:46 GMT Subject: Dictionary from list? References: <6KVz7.132664$vq.30203786@typhoon.ne.mediaone.net> Message-ID: On Sat, 20 Oct 2001 01:14:46 GMT, Jim Correia wrote: >> Hopefully you and everyone who reads your code has all >> the little details in the camel book memorized. > >I was just asking if there was a built in coercion available. >(Coercions aren't unheard of in scripting languages.) This wasn't a my >language is better than your language war. I don't have particularly >strong feelings about perl or python one way or the other (I do most of >my work in compiled languages - C mostly) but use the right tool, or >sometimes the convenient tool, for the job. Sorry if I came across as a jerk. I read more into your post than you intended. Dynamic languages generally can't convert at assignment because there are no declarations to tell them what to convert to (perl's @$% are effectively type declarations). Python's '=' has a different philosophy than a C++-ish operator= anyway. The only way to coerce things is to explicitly call the coerce() function on them. Python's built-in operators do this for numeric types, but that's about it. You can also give objects a __coerce__ method. But it really doesn't do the sort of thing I think you mean when you say "coerce". I think a list->dict converter would be a perfectly reasonable addition to the library, but it's not there to my knowledge. There is a built-in function in mxTools, but it expects a list of tuples and it's not the the stdlib anyway. From dale at riverhall.NOSPAMco.uk Fri Oct 5 21:23:19 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Sat, 06 Oct 2001 02:23:19 +0100 Subject: Pipes References: Message-ID: Oleg Broytmann wrote: >On Fri, Oct 05, 2001 at 11:11:53AM +0100, Dale Strickland-Clark wrote: >> I notice that pipe support in Python is specific to Unix. >> >> There is win32pipe for Windows but documentation is thin, to say the >> least. >> >> Has anyone done any work on inter-process and inter-machine >> communication? > > Pipes are good enough. >http://www-106.ibm.com/developerworks/linux/library/l-rt4/?open&t=grl,l=252,p=pipes > >Oleg. >---- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. Yeah. I saw this. Windows pipes don't stack up too well, do they! However, this was more of an implimentation type of qeustion. Thanks anyway. -- Dale Strickland-Clark Riverhall Systems Ltd From brueckd at tbye.com Thu Oct 25 09:39:54 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 25 Oct 2001 06:39:54 -0700 (PDT) Subject: Critical sections and mutexes In-Reply-To: Message-ID: On 25 Oct 2001, David Bolen wrote: > > FWIW, I don't think the GIL will ever go away, or if it does, we'll end up > > with something that gives the same behavior. Think about it: no GIL means > > that a normal Python program (ie no extension modules in use) could crash > > the interpreter. > > No it doesn't. Obviously removing the GIL requires making the C core > of Python threadsafe, thus it will internally use whatever locks or > synchronization mechanisms are necessary around shared structures or > processes. You don't just stop using the GIL without any other > changes. The interpreter just won't be a single global lock. Python > scripts shouldn't have any risk at all That's exactly my point: if the GIL goes away, its replacement will have the same behavior. For example, today I can safely have two threads append items to the same list "simultaneously". In your threadsafe Python core implementation, the same will be true. In neither case do I need to perform explicit locking on the list, while in C, for example, I'd have to. This is precisely the type of "free thread safety" that I've been talking about, and I'm in no way saying that this fulfills all your needs all the time. > have today through misuse of shared resources without locking , and > yes those scripts that today make assumptions may run into trouble. > But I just see that as the definition of a well-written threadsafe > program. So assuming the GIL is replaced by a threadsafe Python core, what will break in my program with two worker threads appending to the same list? -Dave From nas at python.ca Mon Oct 22 20:18:55 2001 From: nas at python.ca (Neil Schemenauer) Date: Mon, 22 Oct 2001 17:18:55 -0700 Subject: nested_scopes totally broken? In-Reply-To: ; from tim.one@home.com on Mon, Oct 22, 2001 at 06:29:21PM -0400 References: <3bd499a8@news.bezeqint.net> Message-ID: <20011022171855.A3171@glacier.arctrix.com> Tim Peters wrote: > Then I bet you didn't read PEP 227, "Statically Nested Scopes": > > http://python.sf.net/peps/pep-0227.html > > Read that first; all that you raised is covered there. "A class definition is an executable statement that may uses and definitions of names." I would fix it but I have no idea what that statement is supposed to mean. Neil From greg at cosc.canterbury.ac.nz Mon Oct 29 22:20:38 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 30 Oct 2001 16:20:38 +1300 Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> Message-ID: <3BDE1C86.47E65694@cosc.canterbury.ac.nz> Terry Reedy wrote: > > He also thought that > > a,() = somefunc() > > should be legal -- matching, I presume, something like 1,(). Do you > agree with that also? Yes. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From rikard at strakt.com Thu Oct 18 03:25:56 2001 From: rikard at strakt.com (Rikard Bosnjakovic) Date: Thu, 18 Oct 2001 09:25:56 +0200 Subject: Help Need In Coding References: <4783f0eb.0110172313.ef7755e@posting.google.com> Message-ID: <3BCE8404.1010703@strakt.com> Alec D. Cheah wrote: > How do verified from input the variable entered is a file or a path > and how do you check whether it exist or not?? Didn't you read the previous answers? http://www.python.org/doc/current/lib/module-stat.html -- Cheers, ------------------------------------------------------------------------ Rikard Bosnjakovic http://bos.hack.org/cv/ Python Hacker rikard at strakt.com AB Strakt bos at hack.org From skip at pobox.com Wed Oct 31 16:05:25 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 31 Oct 2001 15:05:25 -0600 Subject: Is round() broken? In-Reply-To: <001201c1624d$82ea6dd0$a905a8c0@JWILHELM> References: <001201c1624d$82ea6dd0$a905a8c0@JWILHELM> Message-ID: <15328.26517.309720.938487@beluga.mojam.com> Joseph> So, what this is saying.. is that rounding to 1 decimal point Joseph> works... but anything beyond that is broken? Nothing's broken. Floating point representation is simply inexact. Check out the appendix on floating point arithmetic in the development version of the Python tutorial: http://python.sourceforge.net/devel-docs/tut/node14.html -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From sholden at holdenweb.com Thu Oct 4 23:21:02 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 23:21:02 -0400 Subject: Compiling 2.1.1 on Mac OS X 10.1 - test failures References: <0110051145150H.04291@ike> Message-ID: Richard: You should go to http://python.sf.net and report these bugs. Follow the link to the project page, then select bugs. There's a "Submit New" link close to the top of the page. It's only in that way you can be sure your bugs will come to the attention of the development team, especially as the 2.2 release gets nearer. regards Steve -- http://www.holdenweb.com/ "Richard Jones" wrote in message news:mailman.1002247326.10889.python-list at python.org... > On Friday 05 October 2001 11:45, Richard Jones wrote: > > Hi all, I'm trying to get python built on my mac powerbook running OS X > > 10.1. I've edited the configure script so that LDSHARED is defined as > > > > LDSHARED= $(CC) $(LDFLAGS) -bundle -flat_namespace -undefined suppress > > > > for Darwin. I then ran configure with: > > > > OPT='-O3 -no-cpp-precomp' ./configure --with-suffix=.exe --with-dyld \ > > --program-transform-name=s/.exe//g > > > > Compiling went OK. Then I tried "make test". Oh dear. > > > > test_largefile: took about 2.5 minutes. Top reported that it was mostly > > "stuck" and occasionally "running" - using very little CPU and no disk that > > I could detect (by the scientific aural detection process ;) When it was > > finished, it printed the message "@test exists: 0". No idea if this normal > > - my Linux machine doesn't have large file support. > > > > test_re: got a segfault (with -O3, -O2 and no optimisation at all) > > > > > > Also, the program-transform-name didn't appear to do anything. My programs > > were installed with the .exe extension. > > Another problem I'm having is that when I try to build extension modules, the > -flat_namespace flag doesn't seem to be used. > > > Richard > From johnroth at ameritech.net Sat Oct 20 22:38:37 2001 From: johnroth at ameritech.net (John Roth) Date: Sat, 20 Oct 2001 19:38:37 -0700 Subject: Magic Module Methods? References: <9qsmsg$afb$1@tyfon.itea.ntnu.no> Message-ID: "Magnus Lie Hetland" wrote in message news:9qsmsg$afb$1 at tyfon.itea.ntnu.no... > > I just found myself needing (or wanting) a module which > could have default values for variables that weren't set; > this can be done with Alex's object-as-module trick, but > it occurred to me, why should this be necessary? All I > wanted was to add a __getattr__ method to the module... > Why should I have to replace the module with some other > object to do that? Can't modules be more like objects in > this respect? I mean, why not simply allow this: > > def __getattr__(self, name): > print 'Accessing attribute %s of module %s' (name, self) I think you're using the wrong tool here. If you want something similar to __getattr__, just define a function that the client needs to call to access one of the defaults, and then have that function access the __dict__ attribute of the module. It would require refactoring the clients to call the function, but IMO that would be clearer in any case. John Roth From sholden at holdenweb.com Mon Oct 29 16:55:48 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 16:55:48 -0500 Subject: detecting and creating directories References: <3BDDA7BC.8CF7C891@mitre.org> <0fjD7.3353$Z_1.574942@newsc.telia.net> Message-ID: "Fredrik Lundh" wrote ... > Steve wrote: > > > import os > > path = "/usr/tmp/newdir" > > if os.path.exists(path): > > if not os.path.isdir(path): > > raise ValueError, "%s exists but is not a directory" % path > > else: > > os.mkdir(path) > > for ten extra points, explain why this is a lousy way to > do this. Because the effbot is inherently clueful, and has suggested this is not the best way? It would be nice, of course, to ensure that the mkdir() had generated a writable directory. Or that an existent directory was writable. Those cases would be handled by the open-for-writing code that created the file, though. I'm sure you have much more to say than just that... asking-for-it-ly y'rs - steve -- http://www.holdenweb.com/ From claird at starbase.neosoft.com Thu Oct 18 14:01:22 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 18 Oct 2001 13:01:22 -0500 Subject: writing tcl wrapper with tkinter References: <9e934833.0110180828.4842d434@posting.google.com> Message-ID: <545D8B2DF16A6E76.6993863E4741C004.1E9B970F7929B34E@lp.airnews.net> In article <9e934833.0110180828.4842d434 at posting.google.com>, Damien Thomas wrote: >Hello, > >I have a tcl piece of code that I found useful. As I'm using >tkinter for GUI, I would like to do a class that encapsulate >this tcl code. > >It would be a sort of new tkinter widget on wich I can apply >all the std operation (pack, config, ...) > >Is there a simple way to do that or is there documentation ? Yes. I think everything you need already is in place, as the example from Tkinter import * root = Tk() my_script = 'info hostname' print root.eval.tk(my_script) illustrates. > >(I had a look inside the PyTix code, but it's a little bit too >complicated(modifying tkinter.py, recompiling python.....)) Or maybe you're asking how to code a new Tkinter widget--is that it? -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From richard at bizarsoftware.com.au Fri Oct 5 03:30:41 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 5 Oct 2001 17:30:41 +1000 Subject: Formatted printing of deep tuples In-Reply-To: References: Message-ID: <01100517304104.10490@ike> On Friday 05 October 2001 17:12, Mikael Olofsson wrote: > On 05-Oct-2001 Ignacio Vazquez-Abrams wrote: > > Okay, here's a good one. Say I have a tuple as follows: > > > > --- > > (((1, 2),), ((), ('a', (('b', 'c'),)))) > > --- > > > > Does anyone have or know of any code that will format it similar to: > > > > --- > > ( > > ( > > ( > > 1, 2 > > ), > > ), > > ( > > ( > > ), > > ( > > 'a', > > ( > > ( > > 'b', 'c' > > ), > > ) > > ) > > ) > > ) > > I'm sure someone else has a one-liner using regexps, but the following > seems to be doing the trick. > > def test(a,indent=2): > import string > a=str(a) > s=[] > i=0 > f=0 > for x in a: > if x=='(': > s.append('\n'+i*' '+'(') > i=i+indent > f=1 > elif x==')': > i=i-indent > s.append('\n'+i*' '+')') > f=0 > else: > if f: > s.append('\n'+i*' ') > f=0 > s.append(x) > return string.join(s,'') Bored. Wrote this: def format_tuple(out, tuple, indent=''): out('%s(\n'%indent) new_indent = indent+' ' for element in tuple: if type(element) == type(()): format_tuple(out, element, new_indent) else: out('%s%r,\n'%(new_indent, element)) out('%s)\n'%indent) import sys out = sys.stdout.write format_tuple(out, (((1, 2),), ((), ('a', (('b', 'c'),))))) Might write another before I go home ;) Richard From frederic.giacometti at arakne.com Sun Oct 21 14:06:38 2001 From: frederic.giacometti at arakne.com (Frederic Giacometti) Date: Sun, 21 Oct 2001 18:06:38 GMT Subject: comparative performance benchmark Python 1.5.2 - 2.0 - 2.1 Message-ID: I have been puzzled this week when shown results of a simple benchmarck between python 1.5.2, 2.0 and 2.1. I am wondering; Has there been some official research on the issue ? (pointers....?) The benchmarking program was only basic python objects (strings, dictionaries, string/flot conversions...). In my haste to try do defend Python 2.1, we had done the changes I was aware of: turn off garbage collection (20% gain), switch sre to pre (though this program does not use 're'0; replace string.xxx() calls with o.xxx() string methods. I/O and file read actions account for less than 2 % to the time. Still, we had these depressing results: Python 1.5.2 to Python 2.0: +30% CPU time Python 2.0 to Python 2.1: +15% CPU time The results where confirmed using either the Python profiler of the opertating system time command. This is far too much. It's beyond what I could explain; and this is deemed not acceptable by the end users. As result, I'm getting in the situation where I'm being asked to retroceed all our developments from Python 2.1 to Python 1.5.2. Any help for getting me out of this trap ? Thanks, Frederic Giacometti Arakne, San Diego Supercompter Center From sholden at holdenweb.com Wed Oct 3 12:29:46 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 3 Oct 2001 12:29:46 -0400 Subject: Assignment not the same as defining? References: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> <1002126344.97387@cswreg.cos.agilent.com> Message-ID: "Greg Weeks" wrote in message news:1002126344.97387 at cswreg.cos.agilent.com... > John J. Lee (jjl at pobox.com) wrote: > : On Wed, 3 Oct 2001, Oleg Broytmann wrote: > > : > On Wed, Oct 03, 2001 at 12:35:58PM +0100, Dale Strickland-Clark wrote: > : [...] > : > Python does not have assingment at all. > : > a = b > : > is not assignment in Python - it is binding and rebinding. Reference to > : > b copied into a. Only reference, not an object. > : [...] > > : true > > But also false. In other words, it is a matter of vocabulary. > Value-to-variable binding is essentially the same in Lisp as in Python, and > Lispers call it assignment. > Well, the documentation dares to call them assignment statements (see RefMan 6.3), so I don't see why we shouldn't think of the operation as assignment (even if it's a reference that's being assigned), and even call it that. The main thing is to remember that assignment is only one of the several (I seem to remember Tim Peters listed five) ways to bind a value to a name. though-i'm-not-really-into-bondage-ly y'rs - steve -- http://www.holdenweb.com/ From slinkp23 at yahoo.com Sat Oct 20 19:16:54 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Sat, 20 Oct 2001 23:16:54 GMT Subject: Reverse argument order References: <3bd1f335.1049196274@wa.news.verio.net> Message-ID: On Sat, 20 Oct 2001 21:53:52 GMT, Bengt Richter wrote: >Brute force, but clear: > > >>> def wait(first=None,second=None,third=None): > ... if third: h,m,s = first,second,third > ... elif second: h,m,s=0,first,second > ... elif first: h,m,s=0,0,first > ... else: h,m,s=0,0,0 > ... print "h=%d, m=%d, s=%d" % (h,m,s) # or whatever you want to do > ... > >>> wait() > h=0, m=0, s=0 > >>> wait(1) > h=0, m=0, s=1 > >>> wait(1,2) > h=0, m=1, s=2 > >>> wait(1,2,3) > h=1, m=2, s=3 This is broken! >>> wait(1,2,3) h=1, m=2, s=3 >>> wait(1,0,0) h=0, m=0, s=1 Clearly the user intended to get h=1, m=0, s=0. Fix: Change it so your tests look like "if third is not None:" ... etc. Then it works: >>> wait(1,0) h=0, m=1, s=0 >>> wait(1,0,0) h=1, m=0, s=0 >>> wait(1,0,5) h=1, m=0, s=5 But it's still not great, because the function def implies that this function can take keyword args when in fact it can't: >>> wait(second=9) Traceback (most recent call last): File "", line 1, in ? File "", line 6, in wait TypeError: an integer is required That could confuse a user who actually bothered to learn python. I think Kirill's solution (among others) is better; it does the right thing with inappropriate keyword args: TypeError: wait() got an unexpected keyword argument 'foo' --Paul Winkler From dale at riverhall.NOSPAMco.uk Fri Oct 5 06:11:53 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Fri, 05 Oct 2001 11:11:53 +0100 Subject: Pipes Message-ID: I notice that pipe support in Python is specific to Unix. There is win32pipe for Windows but documentation is thin, to say the least. Has anyone done any work on inter-process and inter-machine communication? Would pipes be the best approach or should we consider sockets? Is there another alternative? Ta very much. -- Dale Strickland-Clark Riverhall Systems Ltd From dale at riverhall.NOSPAMco.uk Mon Oct 15 10:51:32 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Mon, 15 Oct 2001 15:51:32 +0100 Subject: Troubles with global variables References: <87r8s4vmgy.fsf@toadmail.com> <87elo6cd4w.fsf@lisboa.ifm.uni-kiel.de> <87pu7op8p2.fsf@toadmail.com> Message-ID: Jeremy Whetzel wrote: >Janko Hauser writes: > >> Perhaps something else is wrong > >That has to be the case. I just can't figure out, for the life of me, >why this is happening, though. I greatly reduced my code to show here. >It's still doing the same thing (not updating the variables when the >menu is refreshed) > > >import os >import sys >import string > >enc = 'gogo' >br = '128' > >eo = [['E',') Encoder: ','chooseenc()',enc], > ['B',') Bitrate: ','choosebr()',br]] ^^^^ Your problem, I think, is here. The values of enc and br are taken at the time eo is built. If you want new values, you will need to re-assign eo or use an alternative approach. -- Dale Strickland-Clark Riverhall Systems Ltd From skip at pobox.com Thu Oct 4 22:14:41 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 4 Oct 2001 21:14:41 -0500 Subject: advanced regex, was: Re: scanf style parsing References: <3BB16A50.BAE082FE@cygnus-software.com> <3BB2C7DA.F63EEAA7@cygnus-software.com> Message-ID: <15293.6033.223674.631163@beluga.mojam.com> Hans-Peter> Well, yesterday, I tried to parse some simple hexdump, Hans-Peter> produced by tcpdump -xs1500 port 80. The idea was, filter Hans-Peter> the hexcodes, and display and 7 bit acsii codes like a Hans-Peter> little advanced hex monitors do. Hans-Peter> As I'm fairly new to advanced regex constructs, would Hans-Peter> somebody enlight me, how to efficiently parse lines like: Hans-Peter> 2067 726f 7570 732e 2e2e 3c2f 613e 3c2f Hans-Peter> 666f 6e74 3e3c 2f74 643e 3c2f 7472 3e3c Hans-Peter> 7472 3e3c 7464 2062 6763 6f6c 6f72 3d23 Hans-Peter> 6666 6363 3333 2063 6f6c 7370 616e 3d34 Hans-Peter> 3e3c 494d 4720 6865 6967 6874 3d31 2073 Hans-Peter> 7263 3d22 2f69 6d61 6765 732f 636c 6561 Hans-Peter> 7264 6f74 2e67 6966 2220 7769 6474 683d Hans-Peter> 3120 3e3c 2f74 643e 3c2f 7472 3e3c 2f74 Hans-Peter> 6162 6c65 3e3c 703e 3c66 6f6e 7420 7369 Hans-Peter> 7a65 3d2d 313e 4172 6520 796f 7520 6120 Hans-Peter> with respect to varying column numbers. I will refrain to Hans-Peter> show my stupid beginnings, but I wasn't able to get that Hans-Peter> _one_ regex right, with all columns in matchobj.groups() Hans-Peter> listed. I'm not sure quite what you're looking for, but this data is so regular I wouldn't use regular expressions to parse it (no pun intended). Assuming the above stream is coming in on stdin and I wanted to display any printable ASCII characters, I'd start with something like this: import sys for line in sys.stdin.readlines(): line = line.strip() fields = line.split() printing = [] for pair in fields: first = chr(int(pair[:2], 16)) second = chr(int(pair[2:], 16)) if first < " " or first > "~": first = "." if second < " " or second > "~": second = "." printing.extend([first, second]) print line, "".join(printing) The above hex data fed to this code produces 2067 726f 7570 732e 2e2e 3c2f 613e 3c2f groups...< 7472 3e3c 7464 2062 6763 6f6c 6f72 3d23 tr>

Are you a on stdout. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From garth_grimm at hp.com Wed Oct 10 13:02:36 2001 From: garth_grimm at hp.com (Garth Grimm) Date: Wed, 10 Oct 2001 10:02:36 -0700 Subject: using timeoutsocket.py Message-ID: <3BC47F2C.6090206@hp.com> Thanks to Oleg who pointed me to http://www.timo-tasi.org/python/timeoutsocket.py as a solution to my problem. Unfortunately, I'm getting some unusual behavior. The situation is that while handling an HTTP request from one user, I'm sending and receiving some data from another server, which I then repurpose in formulating the response to the user's request. The code below works, but I'm trying to protect against the failure mode in which the second server never responds by timing out the connection. import httplib # to generate the HTTP requests #import timeoutsocket # to add timeout characteristics to all socket connections # set the timeout to 15 seconds #timeoutsocket.setDefaultSocketTimeout(15) # declare and initialize some variables patchDisplay = [] # this is the list of 3-element tuples that we want to end up with patchQS = [] # repository to store the potential patch names REQUEST_DOMAIN = 'some.domain.com' # the domain to sent the request to REQUEST_PATH = '/URLpath/file.html?PATCHIDS=' # the URL Path to send the request to # Code to construct patchQS is here # Construct the HTTP request to retrieve the XML file describing exact matches for the list of # matches try: h = httplib.HTTP(REQUEST_DOMAIN) h.putrequest('GET', REQUEST_PATH + string.join(patchQS, ',') ) h.putheader('Accept', 'text/xml') h.endheaders() errcode, errmsg, headers = h.getreply() # Protect against all kinds of connection errors, by catching exceptions and designating errcode to 404. except: errcode = 404 # Send the request and parse the XML data if a valid response is returned. if errcode == 200: try: # Parsing routine to build patchDisplay is here # this includes a use of h.getfile().read() except Exception: pass patchDisplay = [] When I uncomment out the timeoutsocket lines to add the protection, the first request is processed fine, but subsequent requsts generate an exception that has the following trace: socket.error: (10056, 'Socket is already connected') File , line 1, in connect args = (('some.domain.com', 80),) self = File timeoutsocket.py, line 252, in connect addr = ('some.domain.com', 80) blocking = 1 dumbhack = 1 errcode = 10056 port = None self = sock = timeout = None why = File timeoutsocket.py, line 261, in connect addr = ('some.domain.com', 80) blocking = 1 dumbhack = None e = [] errcode = 10035 port = None r = [] self = sock = timeout = None w = [] why = File httplib.py, line 351, in connect self = File httplib.py, line 367, in send self = str = 'GET /URLpath/file.html?PATCHIDS=PHSS_24591 File httplib.py, line 429, in putrequest method = 'GET' self = str = 'GET /URLpath/file.html?PATCHIDS=PHSS_24591 url = '/URLpath/file.html?PATCHIDS=PHSS_24591' v = Is the timeoutsocket.py wrapper around the base socket class preventing connections from being closed? If so, any ideas on how to fix it? I've attempted to do a h.close() at the end of the XML parsing routine, but that didn't solve the problem. TIA, Garth From max at alcyone.com Thu Oct 4 13:46:44 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 04 Oct 2001 10:46:44 -0700 Subject: Mutable default values for function parameters References: <7da8d8f8.0110040056.42443bb@posting.google.com> Message-ID: <3BBCA084.B10B6061@alcyone.com> sebastien wrote: > I'd like to point something that is said in ?4.7.1 of the tutorial: > > "Important warning: The default value is evaluated only once. This > makes a difference when the default is a mutable object such as a list > or dictionary" > > I think that this point is really difficult to understand. That means > that parameters with mutable default value are global to all the calls > of the function: ... > > This is a really confusing and I always fall in this sort of trap. > Maybe a bad neuronal connection;-) I avoid this problem by simply never using a mutable object as a default argument, but instead always using a sentinel value that's substituted in the function body: def sample(x, d = None): if d is None: d = [] d.append(x) print d To be honest, I can't remember ever running into this pitfall, since I've used this pattern ever since I started using Python, and happened to be made aware of the rule before encountering the wrong end of it. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Sanity is a cozy lie. \__/ Susan Sontag Alcyone Systems' CatCam / http://www.catcam.com/ What do your pets do all day while you're at work? Find out. From dale at riverhall.NOTHANKS.co.uk Tue Oct 16 11:43:54 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Tue, 16 Oct 2001 16:43:54 +0100 Subject: FW: fast sub list operations References: Message-ID: "Alves, Carlos Alberto - Coelce" wrote: >-----Original Message----- >From: Robin Becker [mailto:robin at jessikat.fsnet.co.uk] >Sent: Tuesday, October 16, 2001 8:34 AM >To: python-list at python.org >Subject: fast sub list operations > > >I constantly miss some nice way to subset lists. As an example suppose I >have a list of x y coordinates eg > > [x0,y0,x1,y1,.....] > >and wish to perform the operation x->x+v, y->y+w for the co-ordinates in >the list I don't seem to be able to do this fast using map. Even if I >had a way to slice the list nicely into > >X=[x0,x1,.....x(n-1)] & Y=[y0,y1,.....,y(n-1)] > >so that I can do map(operator.add,X,n*[v]) to perform the arithmetic >quickly I don't seem to have an interlace to get back to the original >list format. > >How can these kinds of operations be performed quickly in current python >and what if any new features would python require to do them best? >-- >Robin Becker A simple class should help manipulate these lists: class pairs: def __init__(self, list): self.list = list def __getitem__(self, index): if index * 2 >= len(self.list): raise IndexError return self.list[index * 2: index * 2 + 2] l = pairs(range(20)) print 'Pairs', [[x, y] for x,y in l] print 'Odds', [y for x,y in l] print 'Evens', [x for x,y in l] print 'Doubled evens', [x*2 for x,y in l] -- Dale Strickland-Clark Riverhall Systems Ltd From tim.one at home.com Mon Oct 29 14:21:38 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 29 Oct 2001 14:21:38 -0500 Subject: pydoc question In-Reply-To: Message-ID: [Luca Fini] > I'm trying to use pydoc to document a class of my own which is a subclass > of Tkinter.Canvas. > > When I generate the documentation, pydoc automatically extracts the full > documentation of the root class and puts it into my class documentation. > > Well I'd prefare to put a line saying something like: "this is a subclass > of Canvas, see Tkinter documentation for other details" > > Is there any way to force this behaviour? No, at least not short of changing the code in pydoc.py. From me at mikerobin.com Sun Oct 21 18:00:26 2001 From: me at mikerobin.com (Michael Robin) Date: 21 Oct 2001 15:00:26 -0700 Subject: async. winsound .PlaySound question.... References: <70461e98.0110191729.62212d6b@posting.google.com> Message-ID: <52e5ab5f.0110211400.4fdc18b4@posting.google.com> This looks like a wrapper around Windows' MMSYSTEM dll. This Windows sub-system does not support playing more than one sound at the same time. ASYNC in this case means "return from the call right away" rather than "wait for the sound to complete". ASYNC and NOSTOP don't work together when a sound is already playing - there is also no automatic queuing in this interface. If you want to be win32 specific, use DirectX and the win32com extensions. An easier route is probably to use pygame's wrapper of SDL which does support mixing and looping of sounds (but no queuing/concatenation.) (www.pygame.org) This will also work on *nix platforms. If you do a google search on "Crossplattform audio" you will also see a recent thread. hope this helps, mike andrew at mail.idrive.com (andrew) wrote in message news:<70461e98.0110191729.62212d6b at posting.google.com>... > i cannot seem to get my system to run more than one winsound.PlaySound > asyncronously ... I think I am using the right flags ... here is my > code snippet: > > > winsound.PlaySound(filePath1, winsound.SND_FILENAME | > winsound.SND_ASYNC | winsound.SND_NOSTOP) > > winsound.PlaySound(filePath2, winsound.SND_FILENAME | > winsound.SND_ASYNC | winsound.SND_NOSTOP) > > > on the second attempt to play a sound, i get a RunTimeError. i am on > a win2k system with a full-duplex enabled sound driver. Python 2.1. > > any ideas? > > thanks in advance From tim.one at home.com Mon Oct 29 13:53:35 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 29 Oct 2001 13:53:35 -0500 Subject: Python 2.2b1 hashable dictionary bug? In-Reply-To: Message-ID: [Tim] > It should suffice to override just __eq__ and __hash__. However, you > can't override __eq__ via object.__eq__ [because object.__eq__ doesn't > exist]. [Rainer Deyke] > That's surprising (and therefore probably a bad thing). I don't know why it's surprising to you. Rich comparisons are optional behaviors; object only supplies defaults for a minimum of required behaviors. > My first expectation was for something like this: > > class object: > def __eq__(self, other): > return id(self) == id(other) > > The problem with that is that it breaks '__cmp__'. My second > expectation was for something like this: > > class object: > def __cmp__(self, other): > return cmp(id(self), id(other)) > def __eq__(self, other): > return self.__cmp__(other) == 0 > > I see no reason why this has not been included. I'm not clear on what you're saying, but whatever it is I'm sure life isn't that simple . Note that object is *itself* an object: >>> object.__class__ >>> and object.__cmp__ is actually defined by object's class, the type "type" (of course type doesn't provide a default implementation for rich comparisons either -- else object.__eq__ would have succeeded): object.__cmp__ is not an all-purpose "compare any two objects" function, it's a bound method accepting one argument and comparing it to object specifically (just as, e.g., (2).__cmp__ is a bound method that compares its argument to 2 specifically). >>> object.__cmp__(object) 0 >>> object.__cmp__(type) 1 >>> type.__cmp__ is closer to what you seem to have in mind, although that's a method restricted to comparing objects of type type (incl. subclasses of type). If you want to define your own comparisons, define them explicitly and you'll have no problems. plus-as-an-added-bonus-your-head-won't-explode-ly y'rs - tim From kseehof at neuralintegrator.com Wed Oct 10 17:38:45 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Wed, 10 Oct 2001 14:38:45 -0700 Subject: ODBC access via Python References: Message-ID: <003401c151d3$f2075280$b7d185ce@kens> There's an odbc module in the win32all libraries. I've attached a short sample. > Hi all! > > I have recently become a die-hard Python fan, but I can't seem to > overcome a minor obstacle: > > Can anyone direct me to a good ODBC module/library for python under > win32? > > I've tried to install mxODBC, but it doesn't work for some reason... > > > thanx in advance, > > vm > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- A non-text attachment was scrubbed... Name: odbc_obj.py Type: application/octet-stream Size: 1409 bytes Desc: not available URL: From guido at python.org Thu Oct 11 15:22:43 2001 From: guido at python.org (Guido van Rossum) Date: Thu, 11 Oct 2001 15:22:43 -0400 Subject: Why not 3.__class__ ? In-Reply-To: Your message of "Thu, 11 Oct 2001 11:30:47 PDT." References: Message-ID: <200110111922.PAA31768@cj20424-a.reston1.va.home.com> > Here's another example of invoking an attribute on a literal: > > C:\>python > Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license" for more information. > >>> > >>> class Spam: pass > ... > >>> s = Spam() > >>> x = Spam() > >>> > >>> isinstance(x,s.__class__) > 1 > >>> x = 'abc' > >>> isinstance(x,''.__class__) > 1 > >>> x = 100 > >>> isinstance(x,0 .__class__) > 1 > >>> > > If you generally want to know if x is the same kind of instance as y, then > isinstance(x,y.__class__) > seems to be a reasonable idiom. > > Given that, it's nice to use the same idiom when y is a builtin type, as in > isinstance(x,''.__class__) > isinstance(x,0 .__class__) > isinstance(x,[].__class__) > isinstance(x,().__class__) > isinstance(x,{}.__class__) > > instead of using a second idiom for builtins > > import types > isinstance(x,types.IntType) > . . . I find the ''.__class__ form butt-ugly, and would recommend type('') instead. Fortunately, in 2.2 there are built-in names that express these types much clearer: isinstance(x, str) isinstance(x, int) isinstance(x, list) isinstance(x, tuple) isinstance(x, dictionary) --Guido van Rossum (home page: http://www.python.org/~guido/) From thomas at gatsoft.no Mon Oct 15 02:21:06 2001 From: thomas at gatsoft.no (Thomas Weholt) Date: Mon, 15 Oct 2001 06:21:06 GMT Subject: How to set tab-width to 4 spaces in emacs ?? References: <1J1x7.14385$tu6.623674@news1.oke.nextra.no> Message-ID: Eh .. after messing around with my .emacs-file I've had some problems with auto-indention editing python-code so I'll probably remove the entry in .emacs. I'd still like to have indent set to 4 spaces, not 8, but working code is nice too ;-> Thanks for the tip though. Thomas "Lee Morgan" wrote in message news:wkadyyn9li.fsf at lee-morgan.net... > "Thomas Weholt" writes: > > > Trying to set the tab-width in emacs to 4 spaces without luck. Using > > Mandrake 8.1 ( great distro btw, python 2.1.1, postgresql 7.1.3 etc. try it > > now !) > > > > tried : > > > > # tab-width: 4 > > etc. but no go. > > > > Any hints ??? > > > > I think (setq tab-width 4) is correct, although isnt it both a global and buffer > variable(or is it a mode var?) - so you may need to add it on to your mode > hook. (Although I've never had reason to change python-mode) > > > Thomas > > > > > > -- > Lee Morgan From robin at jessikat.fsnet.co.uk Sat Oct 13 05:11:48 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 13 Oct 2001 10:11:48 +0100 Subject: signum() not in math? References: <3BC6B774.4688E9A2@darwin.in-berlin.de> <3BC6D71E.D701A15@darwin.in-berlin.de> Message-ID: In article , Harald Hanche-Olsen writes .... >>>> import math >>>> math.atan2(0.,-1.) >3.1415926535897931 >>>> math.atan2(-0.,-1.) >-3.1415926535897931 > perhaps we need some new type to distinguish numbers which might result in this behaviour. Then we could have a flame war about introducing it :) -- Robin Becker From phr-n2001d at nightsong.com Tue Oct 16 18:25:56 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 16 Oct 2001 15:25:56 -0700 Subject: Extending Python - variable sized arrays? References: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> <9qi8f2$o0o9a$1@ID-75083.news.dfncis.de> Message-ID: <7xlmibjk7f.fsf@ruckus.brouhaha.com> Tim Egbert writes: > Returning the array as a tuple using Py_BuildValue() is a problem because, > although I can create the format string dynamically, I can't create a > dymanically sized argument list. Use the apply function. apply(f, [1,2,3]) is the same as f(1,2,3). From info at mjais.de Tue Oct 16 17:21:19 2001 From: info at mjais.de (Markus Jais) Date: Tue, 16 Oct 2001 23:21:19 +0200 Subject: size / length of a list ??? References: <9qi7t2$oe47u$1@ID-75083.news.dfncis.de> Message-ID: <9qi8f2$o0o9a$1@ID-75083.news.dfncis.de> thanks! just found it in another book! markus I.P. Clouzeau wrote: > len(L) > > I.P. Clouzeau From n8gray at caltech.edu.is.my.e-mail.address.com Mon Oct 1 23:03:12 2001 From: n8gray at caltech.edu.is.my.e-mail.address.com (Nathaniel Gray) Date: Mon, 1 Oct 2001 20:03:12 -0700 Subject: gracePlot.py References: <9p316p$9uh@gap.cco.caltech.edu> Message-ID: <9pbba6$af9@gap.cco.caltech.edu> DeepBlue wrote: > I checked your web site. Quite some useful work there. I have a question > for you: > Does gracePlot have any support for plotting in 3-D space? Grace is a 2-D only system. In my experience 3-D plots are rarely useful for conveying actual, quantitative information, though they can be nice qualitative purposes. They're also great for making screenshots for your plotting package. ;-) If 3-D plots are important to you you should check out SciGraphica (go google). It's even got an embedded Python interpreter. :-) Unfortunately it also has a somewhat long dependency list and some other qualities that made it the wrong choice for my purposes. gracePlot is IMHO quite good for quick, simple, 2-D plots with high-quality output both on the display and the printed page. It's for when you're working with Numpy and say, "man, I wish I could just plot these points and see if they make sense," or, "I just need a simple plot with a legend, title, and axis labels to show at the next lab meeting." If you need to do 3-D volume rendering with embedded vector fields then this is not the right package for you. That having been said, though, I should point out that Grace, and by extension gracePlot, does what it does quickly, flexibly, and attractively. > Also, can we > export data points into csv files? gracePlot just knows how to plot things. Saving things is somebody else's job. :-) Seriously, though, you use gracePlot to get your data from Python to Grace. You should be able to save to csv from Python with at most 5 lines of code, and from Grace you can save to, well, whatever formats Grace supports. > How does it compare to GNUplot? Gnuplot is an extremely full-featured plotting package, but it has no interactivity. I want to be able to explore data by zooming in on different parts of curves using this crazy modern invention known as a "mouse", but there's no way to do that in gnuplot AFAIK. If my title is wrong I just want to double click on it and change it, not start the whole plot over again. The real competition to Grace IMO is SciGraphica, which I may do some work on in the future. Understand that most of these questions pertain to Grace itself rather than my package, which is just a high-level wrapper for it. Information about Grace can be had from their website: http://plasma-gate.weizmann.ac.il/Grace/ For those of you who missed it the first time, gracePlot.py can be obtained from my website: http://www.idyll.org/~n8gray/code/ Cheers, -n8 -- Nathaniel Gray California Institute of Technology Computation and Neural Systems -- From mike at unicorn-fs.com Thu Oct 25 12:11:13 2001 From: mike at unicorn-fs.com (Mike Peat) Date: Thu, 25 Oct 2001 17:11:13 +0100 Subject: python as a cgi script engine References: Message-ID: <1004026229.8757.0.nnrp-13.d4f0f8ae@news.demon.co.uk> Damn! ;-) Sorry Jilly, but what did you do to get it to work? I was lurking here waiting to see what answer you got. I can get cgi stuff to work with Apache (on various Linuxs), but on my own W2K (& IIS 5.0) laptop it is a no-go. Mike "jilly" wrote in message news:f828f146.0110250656.2da737f8 at posting.google.com... > "DeepBlue" wrote in message news:... > > When you say it failed: What error are you getting? > > DB > > > > "jilly" wrote in message > > news:f828f146.0110240116.27caedca at posting.google.com... > > > i use "http://localhost/CGI/python.exe?hello.py" ,then i succeed. > > > but when i use "http://localhost/CGI/hello.py" ,i failed. > > > and i have setted scriptmap in the IIS > > > (just like:".py-->c:\python21\python.exe -u"). > > > > > > The context is: > > > windows 2000 and IIS server > > > > > > Please help me > > > Thanks first! > > I have got it work fine! > Thank you again! From tdelaney at avaya.com Tue Oct 30 21:00:15 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 31 Oct 2001 13:00:15 +1100 Subject: adding items from a text file to a list Message-ID: From: Peter Wang [mailto:pzw1 at cor-no-spam-nell.edu.avaya.com] > Sent: Wednesday, 31 October 2001 12:47 PM > To: python-list at python.org > Subject: Re: adding items from a text file to a list > > > good call... i guess if someone really wanted to cheat themselves out > of their tuition, i was a party to their crime... That's why I didn't give a solution - that and I was fairly certain that he hadn't fully read the homework spec ... I much prefer to give a pointer, and then let people work it out for themselves. Pointer #1 - always read and understand the spec. Tim Delaney From huaiyu at gauss.almadan.ibm.com Thu Oct 18 23:28:59 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 19 Oct 2001 03:28:59 +0000 (UTC) Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <3BCF7087.B59CE3C3@ccvcorp.com> Message-ID: On Thu, 18 Oct 2001 17:15:04 -0700, Jeff Shannon wrote: >As for your examples: > >Lib/ftplib.py: >--------------------------------------------(3) > def getmultiline(self): > line = self.getline() > if line[3:4] == '-': > code = line[:3] > while 1: > nextline = self.getline() > line = line + ('\n' + nextline) > if nextline[:3] == code and \ > nextline[3:4] != '-': > break > return line > >changed to > > def getmultiline(self): > code = None > lines = [] > while line = self.getline(); lines.append(line); line[3:4] == '-': >#????? > if code != line[:3]: break > else: code = line[:3] > return '\n'.join(lines) >---------------- >Just looking at that line makes my brain want to explode. Yeah, I could >probably struggle my way through understanding what's going on, but... ick. > >I will admit that the original code could be rewritten to be clearer, but I do >*not* find your version to be at all clearer--quite the opposite. > >.... hm, in sorting through this, it looks to me like you've got it wrong, >anyhow. The first line should be checked if line[3:4] *is* a '-', and if so, >the following line(s) are added, but in the while loop, further lines are added >only if there is *not* a '-' at [3:4] .... the loop condition is inverted after >the first line. And your version will *never* have more than one line, because >the first time through the body of your loop, code (None) will never be equal to >line[:3], so you will *always* break. > >So, not only is it ugly and difficult to understand, it's wrong. Which would >have been far more apparent if it were *not* so difficult to understand..... Thank you (and several others) for pointing this out. I misunderstood the original code. It is interesting that your interpretation is also wrong - condition line[3:4]=='-' was not inverted - what was inverted is code==[:3]. Is this an indication of the (lack of) readability for using "if not: break" in place of "while"? :-) The original code is quite enigmatic to me. I don't know the ftp protocol, but from Andrew's example data I think the code is intended to be def getmultiline(self): code = None lines = [] while line = self.getline(); \ lines.append(line); \ line[3:4] == '-' or code != line[:3]: code = line[:3] return '\n'.join(lines) I'm not sure if this is correc, either, except it works on Andrew's data. (What should happen if code changes when line[3:4]=='-', etc?) realizing-spent-too-long-on-this-topic-and-running-away-ly yr's Huaiyu From uwe at rocksport.de Thu Oct 4 09:52:54 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 4 Oct 2001 13:52:54 GMT Subject: wxPython-question Message-ID: <9phpjm$5qrtb$1@hades.rz.uni-sb.de> Hi, I'm just playing with wxPython and got a problem: I use a wxTextCtrl-Control and load a text into it. This works fine until i add an EVT_SIZE-handler: now the text in tex Text-Control disapears.... Can anybody help me ? Yours, Uwe -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From mal at lemburg.com Mon Oct 22 07:20:43 2001 From: mal at lemburg.com (M.-A. Lemburg) Date: Mon, 22 Oct 2001 13:20:43 +0200 Subject: mxODBC References: <8beb91f5.0109251630.13d6492e@posting.google.com> Message-ID: <3BD4010B.74D46D69@lemburg.com> Ben C wrote: > > Hi there, > > I am pushing text data to a MS SQL Server DB using the mxODBC module > which seems to work fine ... most of the time. One of the columns I am > pushing this text to has the data type set to Text. However ... I am > getting data truncation when attempting to upload some largish strings > ~ 14kb ... the Text datatype should handle 2 gigabytes of data ... the > warning message is as follows > > Warning: ('22001', 0, '[Microsoft][ODBC SQL Server Driver]String data, > right truncation', 4490) > > Would this have something to do with a buffer size setting? > > any suggestions most appreciated.. This could be a problem with the network buffer size used by the ODBC driver. Please check the MSDN for possible workarounds or how to increase the buffer size. -- Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Consulting & Company: http://www.egenix.com/ Python Software: http://www.lemburg.com/python/ From graham_guttocks at yahoo.co.nz Mon Oct 8 02:12:57 2001 From: graham_guttocks at yahoo.co.nz (Graham Guttocks) Date: Sun, 7 Oct 2001 23:12:57 -0700 (PDT) Subject: safe simultaneous file append? Message-ID: <20011008061257.76888.qmail@web10304.mail.yahoo.com> Greetings, Given the following code, is there any danger of the logfile being corrupted if two copies of this code try to append at the same time? file = open('logfile.txt','a+') file.write('testing' + '\n') file.close() If so, how do I guard against this? This is on UNIX BTW. Regards, Graham __________________________________________________ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 From phr-n2001d at nightsong.com Tue Oct 9 11:46:51 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 08:46:51 -0700 Subject: Curious assignment behaviour References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> <9psk9s$rbk@newton.cc.rl.ac.uk> Message-ID: <7x669o7r4k.fsf@ruckus.brouhaha.com> "John Roth" writes: > However, I think := makes a good choice for an expression assignment > operator. It needs to be different from both the statement assignment > operator and the equality operator. It also can't be in use for an > extended assignment. Why on earth does it have to be different from the statement assignment operator? What's wrong with while x=get_next(): whatever(x) I just don't buy the rationale that using = instead of == is a big source of bugs. In 25 years of hacking C code, I think I've seen that error maybe once or twice. From cor at dapdesign.com Wed Oct 31 08:47:03 2001 From: cor at dapdesign.com (Cor) Date: Wed, 31 Oct 2001 14:47:03 +0100 Subject: Running phyton on 50Mips RISC doable? Message-ID: <9rovil$fei$1@news1.xs4all.nl> Hi, I'm trying to figure out if I should use Python for my embedded application that needs some scripting. It is an application with 50Mips Risc processor, with little (and slow) memory. So when I want to run the python interpreter on this machine, will it be terrible slow? And more inportant: how mauch memory will I need? a few K? a few hondred K? Is it difficult to port the code such that it will run on this machine? (It uses gcc compiler) I hope anybody can give me any idea about this? Thanks, Cor Jansen. From tim.one at home.com Mon Oct 15 15:05:16 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 15 Oct 2001 15:05:16 -0400 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) In-Reply-To: Message-ID: [John Roth] > Huh? The purpose of the new syntax is to have a conditional > facility within an expression. If a new line begins with the keyword > 'if', then that is a statement. A conditional if only makes sense _inside_ > an expression, hence it doesn't look like there is an issue. Any Python expression can be used as a statement (think of what you type at an interactive shell). > A bigger issue from a usability standpoint is the lack of a > clear end to the scope of a given 'if', leading to the infamous > dangling 'else' problem. The 'else' clause is not optional in a conditional expression, so the "dangling else" problem can't arise. From matt at mondoinfo.com Thu Oct 4 15:42:29 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Thu, 04 Oct 2001 19:42:29 GMT Subject: Tkinter/Pmw Pack Question References: <3daa1aa8.0110040848.22b76a02@posting.google.com> Message-ID: On 4 Oct 2001 09:48:05 -0700, Jeffrey wrote: Dear Jeff, >Hi, Hi! >I'm using a the pack function to show my widget in it's parent >widget. But I wanted to make it so that the child widget and go from >it's parent widget to another widget. So in essence in can move >around.... The packer has the option in_ that's not much used but will do what you want: >>> from Tkinter import * >>> r=Tk() >>> f1=Frame(r,width=100,height=100,bg="blue") >>> f1.pack_propagate(0) >>> f1.pack() >>> f2=Frame(r,width=100,height=100,bg="green") >>> f2.pack_propagate(0) >>> f2.pack() >>> l=Label(r,text="Wibble") >>> l.pack(in_=f1) >>> l.pack(in_=f2) Note that when you create the Label, its parent widget needs to be a widget that's a parent of both of the widgets that you want to put the label in. Regards, Matt From rdsteph at earthlink.net Sun Oct 28 18:19:52 2001 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 28 Oct 2001 23:19:52 GMT Subject: AskMerlin, your AI expert system guru oracle advisor References: <3BDC649F.6EB6680B@earthlink.net> Message-ID: <3BDC9411.18C441FA@earthlink.net> Ok i want to ask a simple question that I can not figure out yet. (Even though I used and then modified the the line of code below: x = (self._getGoogleHits(self.question + ' ' + reply)) y = (self._getGoogleHits(reply)) I am not sure what the significance of the (self.question + ' ' +reply) is. Specifically, what is the significance of the two quotation marks in the middle? Doe sit just ad a space between the two strings (question and reply), or does it do something else? I tried the program without hte two quotes and it didn't seem to change the operation noticeably. OK, I feel dumb but I would still like to know the answer. Anyone? Ron Stephens http://www.awaretek.com Ron Stephens wrote: > Ok, so this is what happens when Guido promotes CP4E. You get newbie, > duffer, weekend hackers doing whatever turns them on. > > I make no claims that this code is anything more than a hack. Please > excuse it, but if anyone is interested, you can link to my programs > below. Thanks to the inventors of NLQ and multiChoiceGuesser! I hope you > can forgive me for hacking your code ;-)) > > #!/usr/bin/python > # AskMerlin is a weekend hack I did by putting together a short program > called NLQ, > # or natural language query, which can be found online at > http://gurno.com/adam/nlq/#download > # NLQ is a Class to take an inputted query and output 1. Keywords and 2. > also to categorize > # the type of question being asked. I am primarily interested in using > the Keywords > # extracted form a query by NLQ. I shamelessly modified NLQ to add many > more > # IGNORE_WORDS and otherwise spruce it up. > # Next, I utilized the multiChoise Guesser script that some nice person > posted > # on the newsgroup a couple weeks ago. This uses urllib to go out to the > web > # and judge teh appropriateness of a given answer by how many hits it > gets on Google > # when coupled with the original question in a Google search. > # My main contribution, such as it was, was simply to enable the program > to create > # choices in order to choose a most appropriate answer. This is done by > using > # NLQ to pick out Keywords form teh HTML page returned by Google in its > search > # on the question. This version, AskMerlin, currently takes a long time > # to come to an answer because it must do many web searches/ I have also > a simpler version > # called aNoDivisorAskMerlin that comes to a much quicker decision, btu > is not as good in the > # appropriateness of its answer's. In either case, you must wait > patiently while > # merlin considers his options...dependign on speed of your internet > connection. > # On my cable modem at home, AsKMerlin takes about three minutes. > # I am hoping that someone or other might give me ideas on how to > improve the > # intelligence behind Merlin's deliberations. This version is just a > hack to see if it works > # in principle. I have other ideas to increase "intelligence" but I need > more. > # Currently, Merlin is very low IQ, but he has potential for the future. > > # Anyway, Merlin can already answer just about any question. > # Someday, perhaps he will even answer correctly or at least with wisdom > > # ;-))))))))))))) > > http://www.awaretek.com/AskMerlin.py > > http://www.awaretek.com/aNoDivisorAskMerlin.py From jbell at iinet.net.au Sun Oct 14 09:19:19 2001 From: jbell at iinet.net.au (John Bell) Date: Sun, 14 Oct 2001 21:19:19 +0800 Subject: PostgreSQL Interface Query References: Message-ID: <3BC990D7.2680A5AE@iinet.net.au> Stuart Bishop wrote: > On Saturday, October 13, 2001, at 02:05 PM, John Bell wrote: > > > I have been evaluating various Python interfaces to PostgreSQL. So far > > as I've been able to determine the options are PygreSQL (packaged with > > PostgreSQL), PoPy, psycopg and a new entrant, pypgsql. I am leaning > > towards pypgsql (available from SourceForge) based on an comparitive > > assessment of functionality only. However, as pypgsql is just under a > > year old and I've never heard it mentioned on any major Python or > > PostgreSQL forum before I am somewhat concerned regarding its > > stability. I would be very interrested in comments from anyone with > > experience of the pypgsql package. > > I got as far as checking its threadsafety - level 1 compliance > is a major lack to me. I also stick to using the DB API, so I can't > see any improvement in functionality to PoPy or Psycopg. If you only > want a thread level 1 compliant driver, is there any real advantage > over using PyGreSQL which is shipped as part of PostgreSQL? For the moment the low level of thread safety is not an issue in this project. I agree that under most circumstances it would be better to stick strictly to the DB API. However, there appears to be a situation that is only covered by the pypgsql package. The cursor object has an attribute which stores the OID of the last inserted row thus allowing for the indirect retrieval of SERIAL keys for insertion in foreign key fields. This doesn't seem to be achievable in either PoPy or psycopg. Please correct me if I'm wrong. > > > These issues may be the reason there is a lack of commentary on pypgsql. > The other reason is that it must be a secret, as it still hasn't made > it onto the DB-SIG's modules list. I know. I came across it quite by accident. John > > > -- > Stuart Bishop From rand0m at nelvento.it Tue Oct 30 13:18:12 2001 From: rand0m at nelvento.it (rand0m) Date: Tue, 30 Oct 2001 18:18:12 GMT Subject: Programming Python by Mark Lutz 2nd Ed. Message-ID: Hi all, would like your opionion on this book. Read that it has been updated since the Python 2 release. Is it true or it has only some minor changes? I mean i don't even own the 1st edition but i would like a text that teaches taking advantages of the new revised Python library. So again what's your opionion on the 2nd edition of this book? Thank You, Lorenzo P.S Anyhow i think i'll buy it because i need something to explain me OOP ;-) which sometimes sounds a sort of voodoo to me! From com-nospam at ccraig.org Fri Oct 19 09:45:36 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 19 Oct 2001 09:45:36 -0400 Subject: PEP: statements in control structures (Re: Conditional Expressions don't solve the problem) In-Reply-To: References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) writes: > Carl Banks gave some well-thought out objection, which I'd like to summarize > them as: > > (1) There may be many statements before the condition, resulting in long > while-lines. > (2) The else-clause for while is not necessary for while 1. > > But then I was reminded of the examples I collected by searching for break > statements in the source distribution. Most usages are similar to [example with a single assignment followed by a test] I disagree. I used zsh to do grep 'while 1' **/*.py in the standard library and then looked at the loops in the first few files that came back and I found that 8 of those files had forms like # asyncore.py line 468 while 1: tbinfo.append (( tb.tb_frame.f_code.co_filename, tb.tb_frame.f_code.co_name, str(tb.tb_lineno) )) tb = tb.tb_next if not tb: break or # code.py line 229 while 1: try: if more: prompt = sys.ps2 else: prompt = sys.ps1 try: line = self.raw_input(prompt) except EOFError: self.write("\n") break else: more = self.push(line) except KeyboardInterrupt: self.write("\nKeyboardInterrupt\n") self.resetbuffer() more = 0 which do not translate well to your model, 3 have actual infinite loops or loops that terminate by some means other than a break (exception or return), 6 have loops that have a single statement before the test, and 2 have a combination of these. If this were statistically significant (which it isn't as I am way too lazy to write a parser to try a significant sample), it would imply that you will fix somewhere around half of the instances of 'while 1:' structures, at the cost of adding a structure to Python that requires the use of semicolon delimited statements. I will go ahead and state that I think the current 'while 1: if not' loops are more readable than those your proposal, and that iterators/generators solve the vast majority of problems that you have raised, but I really only wanted to present this to make sure that the Carl's first point does not get understated in your PEP (which I believe you should finish, if for no other reason than hopefully putting this argument to rest). -- Christopher A. Craig From maxx at easynews.com Tue Oct 9 22:59:02 2001 From: maxx at easynews.com (Max) Date: Wed, 10 Oct 2001 02:59:02 GMT Subject: Article: From Logo to Python in Two Decades Message-ID: Software Development magazine (November 2001) ends the current issue with an article, briefly mentioning Python as a language providing a "glimpse of the future". The context of the mention is as a training and prototyping language, but it is still a good mention. The magazine's website (http://www.sdmagazine.com) does not have the article on line yet, as it usually lags behind the print edition. From achim.domma at syynx.de Mon Oct 8 04:41:48 2001 From: achim.domma at syynx.de (Achim Domma) Date: Mon, 8 Oct 2001 10:41:48 +0200 Subject: bound member functions ? Message-ID: <9proou$rsh$04$1@news.t-online.com> Hi, I have tried the following code : --- code -------------------------- class Dummy: def __init__(self,val): self.val = val def mult(self,fac): return self.val * fac obj = Dummy(5) mult = obj.mult print mult(5) ------------------------------------ The script prins 25 as I expected. If I change now the last three lines to --- code --------------------------- ... mult = Dummy(7).mult print mult(5) ------------------------------------- I still get 35. What's about reference counting in this case ? Is there a refernce hidden in mult which keeps 'Dummy(7)' alive ? Can I be sure, that the object constructed by Dummy(7) is not destroyed after this line ? greetings Achim From daves_spam_dodging_account at yahoo.com Wed Oct 24 13:56:04 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Wed, 24 Oct 2001 10:56:04 -0700 (PDT) Subject: Critical sections and mutexes Message-ID: <20011024175604.3684.qmail@web21103.mail.yahoo.com> > -----Original Message----- > From: brueckd at tbye.com [mailto:brueckd at tbye.com] > Sent: Tuesday, October 23, 2001 7:33 PM > Subject: Re: Critical sections and mutexes > > No, "normal" operations on Python objects > are atomic as far as threads are concerned. [snip] > Consider a simple producer/consumer > situation: Yes, but. Consider this minor rewriting of your code. Three changes have been made. First, I made it a stack instead of a list, so insertions and removals are happening at the same point. Second, I do a decidedly non-atomic set of operations: I peek at the stack, print a message, then pop the stack. Finally, I tightened the timing down to 0.1 seconds max to increase the likelihood of a collision. It took about 6 runs, but I finally got one: #---------------------------------------- # Code import threading, time, random foo = [] def producer(): for i in range(10): print 'Producing', i foo.insert(0,i) time.sleep(random.random() * 0.1) print 'Producer done' def consumer(): count = 0 while 1: try: peeknum = foo[0] print 'Consumer: about to consume %d.' % peeknum num = foo.pop(0) print 'Consuming', num count += 1 if count >= 10: break except IndexError: pass time.sleep(random.random() * 0.1) print 'Consumer done' threading.Thread(target=consumer).start() threading.Thread(target=producer).start() """ Output: Notice last 2 lines ... Producing 3 Consumer: about to consume 3. Consuming 3 Producing 4 Producing 5 Consumer: about to consume 4. Consuming 5 ... """ Now, this is arguably a malicious rewriting of your code, and it certainly flies in the face of the notion that multithreaded code should at least be careful about how it interacts with its neighbors. Anyway, this is the kind of "critical section" idea I'm talking about. If I do a series of operations expecting a shared resource to remain unchanged, I either need to have uninterruptable code (a critical section) or the resource needs to be mutexed. Interestingly, in several sets of tests, I discovered that print statements aren't entirely atomic; tightly threaded code can interrupt a print statement after the text, but before the newline has been printed: def fn1(): for i in range(10): print "Hello Bob!" time.sleep(random.random() * 0.1) def fn2(): for i in range(10): print "This is Fred!" time.sleep(random.random() * 0.1) ...can produce output like this: Hello Bob! This is Fred! Hello Bob!This is Fred! Hello Bob! This is Fred! Anyway. The upshot is, I need to think about Python threading in terms of mutices [1] instead of critical sections; groups of resources that need to be accessed atomically will need a mutex to control them. For the nonce, I have rewritten my PriorityQueue class to use a pair of Queue.Queues, and included a mutex above them so that two threads cannot simultaneously access the separate queues. I still need to profile it, but I'm assuming that Queue.Queue will be more efficient over the long haul than a list. My assumption is that Queues are fairly smart about managing memory creep, but the queue's mutex code may be an unnecessary speed hit. I'll know for sure once I profile them; it may be that lists are better. (The reality is, both are probably sufficient.) Thank you all for your responses. -dB [1] Yeah, yeah. I know it's not a word... but neither is "Kleenices", and I say that, too. :-) ===== David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From thomasNO at SPAM.obscure.dk Mon Oct 22 19:45:56 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Mon, 22 Oct 2001 23:45:56 GMT Subject: Mixing asyncore with threads References: Message-ID: Lucio Torre wrote in news:mailman.1003791264.11491.python-list at python.org: [snip (TJ) - CPU/IO bound server] >>other trafic while calculating. The problem is, that select() will >>block until it sees trafic on a readable or writeable port (AFAIK). > > select does not necesarily blocks. > the select bit goes like this: (from some of my code) > > readable, writable, exceptional = > select.select([conn.fd], [], [], 0.2) > if len(readable) > 0 : > tmp = readable[0].recv(1024*8) > # log byte count > conn.read_b += len(tmp) > conn.out_buff += tmp > if tmp != "": > conn.read_time = > time.clock() > > 0.2 being the timeout for select. if you use 0, it will just never > block. I see, somehow I had (wrongly) gotten the impression that 0 meant "block", when it's really None. Problem is, a voice inside my head keeps whispering "busywait", but probably the overhead is neglectible :-) [snip] > cant help you with asyncore or threads, but i know you can use > select for this. Thanks. -- Best Regards Thomas Jensen From noagfa at noagfa.com Mon Oct 8 22:12:45 2001 From: noagfa at noagfa.com (Jean-Marc Chamberland) Date: Mon, 08 Oct 2001 22:12:45 -0400 Subject: Agfa, cheap service pourri Message-ID: Why is it that it is possible to repair a 20$ toaster but impossible to repair an Agfa scanner worth 350$? If you wish to learn how the company AGFA exploits its customers, check my website: http://pages.infinit.net/noagfa There, you will find countless details of my endless mishaps with the company. P.S. My apologies to those of you who may take offense to this message, however, when facing a large company such as AGFA, the cheated consumer cannot do much besides complain, which I have decided to do with the help of the web... Pourquoi peut-on faire r?parer un grille-pain de 20$ mais pas un scanner Agfa de 350$? Si vous voulez savoir comment la compagnie AGFA exploite sa client?le, allez visiter mon site web: http://pages.infinit.net/noagfa Vous y trouverez l'histoire de mes probl?mes avec cette compagnie. P.S. Excusez-moi si ce message vous importune, mais face ? une grosse compagnie comme AGFA, un consommateur l?s? ne peut que chi?ler. Ce que j'ai d?cid? de faire par l'interm?diaire du web... -- Jean-Marc Chamberland, Granby, Qu?bec -- Jean-Marc Chamberland, Granby, Qu?bec From db3l at fitlinxx.com Thu Oct 11 17:13:07 2001 From: db3l at fitlinxx.com (David Bolen) Date: 11 Oct 2001 17:13:07 -0400 Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> Message-ID: Dale Strickland-Clark writes: > Not so. It can avoid an extra enclosing block in cases such as: > > if (x==y) > for (initialise loop; ....) > do something > > Which is less fussy than > > if (x==y) > { initialise loop > for (....) > do something > } Except that I'd never recommend writing the former (initialization or not) since you're just asking for maintenance headaches later when someone tries to add a new statement to the conditional and forgets to add the block back in. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From user at domain.invalid Sat Oct 13 12:35:31 2001 From: user at domain.invalid (user at domain.invalid) Date: Sun, 14 Oct 2001 00:35:31 +0800 Subject: Help: Playing media files in Win32 using Python Message-ID: <3BC86D53.5070501@domain.invalid> Hi, I'm looking for help to play AVIs and MPEGS in Python using COM. Is there any reference code that I can use ? Thanks, -Alvin From tim.one at home.com Mon Oct 8 00:45:24 2001 From: tim.one at home.com (Tim Peters) Date: Mon, 8 Oct 2001 00:45:24 -0400 Subject: Is this a tiny bug? In-Reply-To: <9pqail$js5@dispatch.concentric.net> Message-ID: [Julius Welby] > In Idle, when I use the tuple(sequence) built in function, the "tip" that > pops up when I open the bracket is: > > tuple(sequence) -> list > > which surprised me, as I expected: > > tuple(sequence) -> tuple. > > The function obviously works fine, but I wondered what controls the > "tip", and if this is a mistake. The tip is automatically extracted from the first line of the function's docstring (tuple.__doc__). The docstring was in error, and I happened to fix it a few weeks ago (so you won't see this in 2.2a4). It looks like the docstring for tuple() was a cut-and-paste job from the docstring for list(), and whoever did that forgot to s/list/tuple/g. they'll-be-punished-but-probably-not-killed-ly y'rs - tim From michael.g.abbott at ntlworld.com Thu Oct 25 16:26:42 2001 From: michael.g.abbott at ntlworld.com (Michael Abbott) Date: Thu, 25 Oct 2001 20:26:42 GMT Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> Message-ID: "Terry Reedy" wrote in news:4vXB7.155961$5A3.54581770 at news1.rdc2.pa.home.com: >> time, status, _ = myobject.read() >> >> instead, so I'm grumbling about trivia here. > > The problem is that Python assignment is not sufficiently well > explained for many. Well, I guess I was thinking about assignment in terms of "pattern matching", where the right hand side is matched against the left hand side and assigments are used to fill in the gaps -- and an exception occurs if the pattern doesn't match. However, Python tuple assignment does look somewhat like pattern matching; for example, sometimes my .read() method returns some (one) thing, and I write: time, status, ((value, boring),) = myobject.read() So here I think of this as matching the one value (itself a pair of values) that happens to be returned. This looks awfully like pattern matching (cf Haskell). From ignacio at openservices.net Tue Oct 2 18:30:29 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Tue, 2 Oct 2001 18:30:29 -0400 (EDT) Subject: need design suggestions: local namespace problem In-Reply-To: Message-ID: On Tue, 2 Oct 2001, Jason R. Mastaler wrote: > I'm writing a mail application that needs to have different values for > variables depending on whether the app is running under qmail or > Sendmail. > > Currently I have those variables in a module called "Defaults.py". > So, within the program main, I do things like: > > import Defaults > sys.exit(Defaults.ERR_HARD) > > Some of these variables need to conditionally have different values as > I mentioned. For example, exit status codes. Under qmail, > `ERR_HARD = 100', while under Sendmail, `ERR_HARD = 75'. > > I was thinking of splitting Defaults.py up into multiple files > (Qmail.py and Sendmail.py), and then using local namespace trickery so > that within the program main I can do things like: > > if qmail: > import Qmail as mta > elif sendmail: > import Sendmail as mta > > sys.exit(mta.ERR_HARD) > > However, the "import module as name" syntax is a Python2-ism, and I'd > still like to support Python-1.5.2 if I can. How about this: sendmail.py --- class mta: ERR_HARD=75 ... --- qmail.py --- class mta: ERR_HARD=100 ... --- main.py --- ... if issendmail: from sendmail import mta elif isqmail: from sendmail import mta ... sys.exit(mta.ERR_HARD) ... --- -- Ignacio Vazquez-Abrams From dale at riverhall.NOTHANKS.co.uk Tue Oct 23 19:09:21 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 24 Oct 2001 00:09:21 +0100 Subject: Speeding up a regular expression References: Message-ID: Michael Lerner wrote: >Hi, > >I'm a relative newbie to Python, and I'm certainly no regular expression >wizard. I have a text file with a bunch of lines of the form > > 1-1.1 2.2 -3.3 4.4 5.5 -6.6 > >That is, an integer, followed by six floats, with an arbitrary number of >spaces in between the numbers. Note that that arbitrary number can be >zero, as is the case between the 1 and -1.1 above. > >There are also a bunch of other lines in the file. I only want the ones >that are like the line above. > >So, here's what I did: > >---- begin my schlocky code ---- > >import re > >def gimmeWhatIWant(inputString): > myRe = re.compile(r""" > ^ # start at the beginning of the line > (\s*) # our leading spaces > (\d+\s*) # the integer, which may or may not > # have a trailing space! > (-?\d+\.\d+\s*){6,6} # all six floats MAY have spaces > # after them > $ # end at the end of the line > """, re.VERBOSE) > > lines = string.split(inputString,"\n") > returnString = "" > for line in lines: > if myRe.match(line): > returnString = returnString + line + "\n" > > return returnString > >---- end my schlocky code ---- > >The thing is, this is slow when I run it on input strings with 6 or 7 >thousand lines. > >Any hints on how I could speed it up? > >One thing: I think that replacing the string.split(...) call with >inputString.split("\n") might speed things up a little. But, that's not >where most of the time is spent and I'd like this to work with Python >1.5.2 if possible. > >thanks, > >-michael It really depends on how losely you can identify the difference between the lines you want and those you don't. For example, would a line starting with a space and containing six dots be an accurate enough test? if line.startswith(' ') and line.count('.') == 6: However, it doesn't look like you need to group all the matches so removing the parenthasese may improve the speed. Also, if you use 'match' you don't need to start the pattern with '^' It would help to have a bigger sample of what you want to match and also an example of what you want to NOT match. -- Dale Strickland-Clark Riverhall Systems Ltd From com-nospam at ccraig.org Fri Oct 5 08:33:50 2001 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 05 Oct 2001 08:33:50 -0400 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: References: Message-ID: <873d4yfeq9.fsf@elbereth.ccraig.org> "Tim Peters" writes: > BTW, doesn't this look fishy to you (s/Peters/Holden/)?: > > Nope. If Steve were married, you would write about his and his wife's > home (assuming they lived together) as the Holden's home. Since (and > how could it be else) there is only one Steve, you should write about > Steve Holden' way of thinking. This doesn't negate the fact that Steve was correct. Names ending in "s" are a special case for apostrophe rules. > When I was about 12, a teacher said Peter's or Peters's was acceptable for > the singular possessive (I stuck with Peters's), and Peterses' for the > plural (I stuck with Peters', and got extra credit later ). What you were told by you teacher seems far more fishy. Try s/Peters/Chris/ When I was about 12, a teacher said Chri's or Chris's was ^^^^^^ acceptable for the singular possessive (I stuck with Chris's), and Chrises' for the plural (I stuck with Chris', and got extra credit later ). trying-to-decide-if-this-is-more-off-topic-than-the-gpl'ly yours, -- Christopher A. Craig "I don't know of any version of Unix on Intel that is not technically superior to Windows NT." -- Nicholas Petreley (InfoWorld Columnist) From offer at sgi.com Mon Oct 1 11:50:25 2001 From: offer at sgi.com (Nhi Vanye) Date: 1 Oct 2001 15:50:25 GMT Subject: GNU wars again (was Re: Proposal: add vector arithmetic to array module) References: <9p7kq3$kiu$1@panix3.panix.com> Message-ID: <9pa3c1$o6af2$1@fido.engr.sgi.com> $ from chasm at galileo.rift -#162901 | sed "1,$s/^/> /" > > >In article , Trond Eivind >Glomsr?d wrote: >>Of course, "free" means that you have and can modify the source and I >>haven't seen anyone claim that using the term "open source" doesn't >>include this. The GPL restricts your freedom to restrict the software >>as released by you and is thus "less free" than eg. the XFree86 >>license. > >Ever heard the phrase "information should be free" ? Check out some >definitions of `hacker ethic' or read some Levy. > >Thinking about it this way, the GPL is more free than the XFree86 license, >since it is the continuing availability of the code, and variations on it, >that the license ensures - not your personal human rights/liberties/whatever. You're right in identifying that "free" in GNU sense means the freedom of the code, not of the developer. I like to think of it this way: Microsoft: All our IP belongs to us. GNU: Touch our IP, and your IP belongs to us. X: Here's our IP, just use it. > >Julian richard. -- Richard Offer Technical Lead, Trust Technology. "Specialization is for insects" __________________________________________http://reality.sgi.com/offer/ From mertz at gnosis.cx Sun Oct 21 18:55:39 2001 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Sun, 21 Oct 2001 18:55:39 -0400 Subject: comparative performance benchmark Python 1.5.2 - 2.0 - 2.1 (fwd) Message-ID: [Neil Schemenauer] > Benchmarking is hard: > spud ~$ python1.5 pystone.py > Pystone(1.1) time for 10000 passes = 1.33224 > This machine benchmarks at 7506.16 pystones/second > spud ~$ python2.0 pystone.py > Pystone(1.1) time for 10000 passes = 1.38104 > This machine benchmarks at 7240.92 pystones/second > spud ~$ python2.1 pystone.py > Pystone(1.1) time for 10000 passes = 1.04334 > This machine benchmarks at 9584.57 pystones/second > spud ~$ python2.2 pystone.py > Pystone(1.1) time for 10000 passes = 0.975024 > This machine benchmarks at 10256.2 pystones/second Not that much anyone probably need more benchmark numbers... but I got curious, and ran all the Python versions on my OS/2 machine, which is what I use most of the time (I use a little script to massage environment variables to select a version): D:\py151\lib\test % py 151 -- Using Python v1.51 -- D:\py151\lib\test % python pystone.py Pystone(1.1) time for 10000 passes = 2.242 This machine benchmarks at 4460.3 pystones/second D:\py151\lib\test % py 152 -- Using Python v1.52 -- D:\py151\lib\test % python pystone.py Pystone(1.1) time for 10000 passes = 1.086 This machine benchmarks at 9208.1 pystones/second D:\py151\lib\test % py 20 -- Using Python v2.0/emx -- D:\py151\lib\test % python pystone.py Pystone(1.1) time for 10000 passes = 1.07 This machine benchmarks at 9345.79 pystones/second D:\py151\lib\test % py sl -- Using Python v2.0/emx (Stackless) -- D:\py151\lib\test % python pystone.py Pystone(1.1) time for 10000 passes = 1.07 This machine benchmarks at 9345.79 pystones/second D:\py151\lib\test % py 21 -- Using Python v2.1/emx -- D:\py151\lib\test % python pystone.py Pystone(1.1) time for 10000 passes = 1.11 This machine benchmarks at 9009.01 pystones/second D:\py151\lib\test % \jython20\jython.cmd pystone.py Pystone(1.1) time for 10000 passes = 1.782 This machine benchmarks at 5611.67 pystones/second FWIW, I don't seem to get any significant difference for a second run, as Tim finds on Win98. 1.5.1 seems pretty slow. But the others seem pretty close... interestingly, the pattern between versions is not like what Neil finds. YMMV. Yours, Lulu... From claird at starbase.neosoft.com Thu Oct 18 10:52:00 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 18 Oct 2001 09:52:00 -0500 Subject: [OsX] Tkinter compile prob. References: Message-ID: In article , Andreas Schoeller wrote: . . . >I updated OsX and developer Tools to latest V10.1 Now I compiled and >installed tcl8.4.a / tk8.4.a and python 2.2. Then I prepared /Modules/Setup >file with the correct paths to tcl/tk and X11 headers and libs. The >following =B4make=B4 brings this result : > >libtool -o Python.framework/Versions/2.2/Python -dynamic libpython2.2.a \ > -framework System -lcc_dynamic -arch_only ppc -flat_namespace -U >_environ -framework Carbon -framework Foundation -install_name >Python.framework/Versions/2.2/Python -compatibility_version 2.2 >-current_version 2.2 >ld: Undefined symbols: >_TclFreeObj >_Tcl_AddErrorInfo ><.snip.> >... a lot more tcl/tk symbols ... ><.snip.> >_Tcl_Init >_Tk_Init >_Tk_MainWindow . . . That libtool invocation includes neither the Tk nor Tcl libraries. I don't know the latest generations well enough to advise you on the canonical correction; somehow, though, you must include them. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From xavier at perceval.net Fri Oct 5 10:48:34 2001 From: xavier at perceval.net (Xavier Defrang) Date: Fri, 5 Oct 2001 16:48:34 +0200 (CEST) Subject: list to tuple question In-Reply-To: <3bbdc533_6@news.newsgroups.com> Message-ID: On Fri, 5 Oct 2001, Janos Blazi wrote: > The point is, that b is already a list and this would simplify matters. Most > unfortunately (or most obviously for the initiated) I get the error message > that a tuple and a list cannot be concatenated. What should I do. I could > solve the problem by using a for-loop but is it necessary? You may transform your list into a tuple using the tuple built-in function. Xavier From Kevin.Smith at sas.com Thu Oct 11 10:44:16 2001 From: Kevin.Smith at sas.com (Kevin Smith) Date: Thu, 11 Oct 2001 14:44:16 GMT Subject: Detecting whether a Python program was invoked in the background or foreground Message-ID: <9q4b80$fq9$1@license1.unx.sas.com> Is it possible to detect whether a Python program was invoked in the background? In other words, is there a variable that will differ when invoking the following commands. python myscript.py & python myscript.py Kevin Smith Kevin.Smith at sas.com From dkuhlman at rexx.com Mon Oct 29 16:56:01 2001 From: dkuhlman at rexx.com (Dave Kuhlman) Date: 29 Oct 2001 15:56:01 -0600 Subject: ANNOUNCE -- Upgrade to libxslt, libxml_saxmod, pyeditor, etc. Message-ID: <1004393248.789521@rexx.com> ANNOUNCE -- Upgrade to libxslt, libxml_saxmod, pyeditor, etc. I've fixed some errors and added a feature to libxml_saxlib, the Python wrappers for the the SAX XML parser C library from http://xmlsoft.org: - fixed bug that prevented display of error messages from Python call-backs - added ability of call-backs to catch and handle parser messages (formerly, they all went to stderr). There are also a few bug fixes for libxsltmod, the Python wrapper for the XSLT C library from http://xmlsoft.org. And, pyeditor, the text editor that is extensible in Python, has some added features and some fixes. You can find the new versions at http://www.rexx.com/~dkuhlman Please let me know if you have suggestions or questions or if you need fixes or support. - Dave -- Dave Kuhlman dkuhlman at rexx.com -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From db3l at fitlinxx.com Wed Oct 24 18:49:37 2001 From: db3l at fitlinxx.com (David Bolen) Date: 24 Oct 2001 18:49:37 -0400 Subject: Critical sections and mutexes References: Message-ID: writes: > I was merely responding to somebody's not-entirely-true assertion that > "_every_ access to that [shared] resource _must_ be enclosed in locks". But that statement is more true than not (as other respondents have shown, even a simple assignment may be an issue), and certainly it's much smarter when writing threaded code to behave as if it were always true, since the potential consequences when it isn't can be very subtle. There are some cases (e.g., when performing read-only access to a value where it isn't critical if the value changes and you just get one of the two potential values, such as when watching a sentinel that you'll just pick up on the next loop), but you really do need to consider all possible users of every shared resource. > P.S. - Print statements are not atomic and do not fall in the same realm > as "normal" Python operations (e.g. "i = 5") because 'print' involves > a potentially blocking access to an external resource (stdout). To avoid > blocking the interpreter releases its global lock before writing to a file > descriptor and reaquires it when done. While the GIL is released around external I/O, even if that weren't the case, a 'print' could be interrupted simply because it requires multiple bytecodes, and the regular interruption at every 'n' bytecodes could occur in the middle of the overall print processing. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From richard at NOstarfighterSPAM.freeuk.com Wed Oct 3 13:32:29 2001 From: richard at NOstarfighterSPAM.freeuk.com (RT) Date: Wed, 3 Oct 2001 18:32:29 +0100 Subject: Basic button question References: <3bbb4a89_8@news.newsgroups.com> Message-ID: <1002130337.69458.1@eos.uk.clara.net> "Janos Blazi" wrote in message news:3bbb4a89_8 at news.newsgroups.com... > I have a button that is bound to a call-back wich ''. Now when I > press the button, it is not pressed and the call-back is called immediately. > It then creates a new toplevel window and a lot of processing happens. > Finally, when th newly created toplevel returns (I use t.quit() and > t.destroy()), the original button is pressed (a bit late) and remains > pressed, unless I touch it with the mouse. All this look very, very ugly. > > Can somebody give me a hint? > Try binding instead. RT From dummy at net-es.dk Mon Oct 29 14:57:33 2001 From: dummy at net-es.dk (Per Jensen) Date: Mon, 29 Oct 2001 20:57:33 +0100 Subject: PIL - Image.open() problem References: Message-ID: In article , "Fredrik Lundh" wrote: That was it ! When the routine failed, it was always when reading elements from a XML file. Apparently it was this Unicode issue. Thanks a lot, I have been struggling with this for a *long* time :-) BTW: this solution wil clear the way for a new release of a little, yet very useful, program. Check it out at http://www.net-es.dk/~pj/python Thanx > Per Jensen wrote: > >> Problem: I have a method in a classe which sometimes open a JPEG image, >> and at other times do not. > >> --------------------------------------------- Opening picture: "1.jpg" >> Traceback (most recent call last): >> File "./picture.py", line 155, in getImage self.picture = >> Image.open(self.filename) File >> "/var/tmp/python-imaging-root//usr/lib/python2.0/site-packages/PIL/Image.py", >> line 871, in open prefix = fp.read(16) >> AttributeError: read >> -------------------------------------------- > > could it be that someone's passing you a unicode string? PIL's > file-or-string code doesn't deal properly with unicode strings: > >>>> import Image >>>> i = Image.open("lena.jpg") >>>> i = Image.open(u"lena.jpg") > Traceback (most recent call last): > File "", line 1, in ? > File "c:\py21\PIL\Image.py", line 936, in open > prefix = fp.read(16) > AttributeError: read >>>> >>>> > try changing your code to: > > self.picture = Image.open(str(self.filename)) > > or, if you're on a platform that can handle unicode filenames: > > self.picture = Image.open(open(self.filename, "rb")) > > ::: > > note that 2.2 is a bit more helpful: > > Python 2.2b1 (#25, Oct 19 2001, 21:26:51) >>>> import Image >>>> i = Image.open("lena.jpg") >>>> i = Image.open(u"lena.jpg") > Traceback (most recent call last): > File "", line 1, in ? > File "c:\py22\PIL\Image.py", line 936, in open > prefix = fp.read(16) > AttributeError: 'unicode' object has no attribute 'read' > > From wangye1 at auburn.edu Sun Oct 7 23:13:05 2001 From: wangye1 at auburn.edu (clio) Date: Sun, 07 Oct 2001 22:13:05 -0500 Subject: How to call a python function in C++ References: <3BC09555.9090903@auburn.edu> <3BC096A4.478C3510@earthlink.net> <3BC0A785.E95D516@earthlink.net> Message-ID: <3BC119C1.9070209@auburn.edu> Thank you for your help. I did not add the my_set_callback in method table. But now I can not access my_callback in python. The error like this: >>> import provapi Diffusion Routing Agent: Initializing... Agent ID = 32792 >>> def happy(binstr): print binstr ... >>> provapi.set_callback(happy) >>> print provapi.my_callback Traceback (innermost last): File "", line 1, in ? AttributeError: my_callback >>> print happy >>> It seems that set_callback doesn't work. But I don't know why? Thank you again. clio From flognat at flognat.myip.org Mon Oct 8 03:07:46 2001 From: flognat at flognat.myip.org (Andrew Markebo) Date: Mon, 08 Oct 2001 07:07:46 GMT Subject: How to call a python function in C++ References: <3BC09555.9090903@auburn.edu> <3BC096A4.478C3510@earthlink.net> <3BC0A785.E95D516@earthlink.net> <3BC119C1.9070209@auburn.edu> Message-ID: Just a couple of thoughts.. Are you trying the code you sent here, or it is an excerpt? I mean.. ;-) sometimes you static-declare a function in a class in c++ to be able to call it from the outside without an instance.. Tried to do extern "C" around the function?? Maybe python is looking for c-names, not c++-names?? /Andy / clio wrote: | Thank you for your help. | | I did not add the my_set_callback in method table. But now I can not | access my_callback in python. The error like this: | | >>> import provapi | Diffusion Routing Agent: Initializing... Agent ID = 32792 | >>> def happy(binstr): print binstr | ... | >>> provapi.set_callback(happy) | >>> print provapi.my_callback | Traceback (innermost last): | File "", line 1, in ? | AttributeError: my_callback | >>> print happy | | >>> | | It seems that set_callback doesn't work. But I don't know why? | | Thank you again. | | clio | -- The eye of the beholder rests on the beauty! From barry at zope.com Thu Oct 11 16:37:35 2001 From: barry at zope.com (Barry A. Warsaw) Date: Thu, 11 Oct 2001 16:37:35 -0400 Subject: testing, please ignore Message-ID: <15302.783.861538.503440@anthem.wooz.org> From iblank at nospam.com Thu Oct 25 22:59:14 2001 From: iblank at nospam.com (Ingo Blank) Date: Fri, 26 Oct 2001 04:59:14 +0200 Subject: Dynamic assignment Message-ID: <9raji3$jpb$01$1@news.t-online.com> Hi, I want to dynamically create variables and assign values to them. I tried the following: >>> vn = "dynVar" >>> vv = 1 >>> eval("%s=%d" % (vn,vv)) Traceback (most recent call last): File "", line 1, in ? File "", line 1 dynVar=1 ^ SyntaxError: invalid syntax Q1: Why is the "syntax error" issued ? Q2: *HOW* do I achieve a dynamic assignment ? TIA --ibl From pzw1 at cor-no-spam-nell.edu Tue Oct 30 21:00:39 2001 From: pzw1 at cor-no-spam-nell.edu (Peter Wang) Date: Wed, 31 Oct 2001 02:00:39 GMT Subject: python development practices? References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> Message-ID: On 30 Oct 2001 17:11:28 -0800, Paul Rubin wrote: >Peter Wang writes: >> while i feel that Python makes me far more productive as a programmer >> for all the projects on which i've worked, i'm inclined to agree that >> the lack of data hiding coupled with lack of a standard interface >> specification would cause problems in a team. > >Well, there's cheesy data hiding in the sense that instance variables >whose names begin with underscores are difficult to reach from other >modules. well... kind of. but short of naming all my private variables "_foo" and hacking around the problem, there's no way to prevent lazy programmers from touching all of your classes's data members. i know this is not python's paradigm, but OTOH this is something that has to be dealt with in a production environment... as an aside, and i don't mean to sound obnoxious, but why did guido not put in data hiding into python at an earlier stage? my colleague whose background on generic programming comes entirely from the STL points this "wart" out as one of python's largest, and brings up the good point that data hiding was well known to the OOP world at the time of python's first incarnations. >If by "interfaces" you mean Java-like interfaces, that's a bogus >criticism since Python supports multiple base classes, which let >you do the same things and then some. nope, didn't mean Java interfaces. just meant some clean way to define contracts between callers and functions. static typing is an interface mechanism. if python had an elegant language-level construct for defining basic contracts, it would be a boon to (1) compile-time debugging and (2) design by contract in python. i've read the interfaces PEP and that seems like a nice way to do it at the class level, but almost seems too heavyweight for "basic" types. or, in light of "classes are types are classes", there doesn't seem to currently be a lightweight way to say "this is a list-like item" or "this is an INT-like item". one could fiddle with proxies and such to achieve the effect, but that's the difference between a language *allowing* a feature versus *providing* a feature. >I agree with the criticism about the tool environment, and would also >have to say the runtime library isn't what I'd call "industrial strength". actually that was the least of my worries. :-) if could just guarantee code coverage on the stuff i write, i'd be happy! i have to be honest: i haven't done much with trace.py or pylint. but my original question was much more about development practices with python: coding specs, docstring conventions, module import rules, etc. i can read PEPs and documentation as well as the next guy, but development practices - there, i haven't got a clue. >> how do Python development teams get around these issues? does using >> Python in a commercial software team simply require more disciplined >> programmers? > >> are there good references on using Python in a commercial, team >> development environment? > >I don't know about Python, but large systems have been built in Lisp, >and there have been some studies too. Lisp's runtime semantics are >fairly similar to Python, though the development environments are >far more highly evolved. can you point me to some of these studies? or at least a list of google keywords? :-) -peter From skip at pobox.com Mon Oct 15 14:49:53 2001 From: skip at pobox.com (Skip Montanaro) Date: Mon, 15 Oct 2001 13:49:53 -0500 Subject: Python web client anyone? In-Reply-To: <7xlmickaui.fsf@ruckus.brouhaha.com> References: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> <7xn12tombq.fsf@ruckus.brouhaha.com> <7xu1x1px4d.fsf@ruckus.brouhaha.com> <9qer0a$don$1@dahlia.singnet.com.sg> <7xlmickaui.fsf@ruckus.brouhaha.com> Message-ID: <15307.12241.939364.354271@beluga.mojam.com> Paul> Thanks, that's the kind of thing I have in mind--a more convenient Paul> interface would have been nice, but it's a start. I think that's the standard sort of interface provided by SGML parsers in general. You define callbacks associated with the opening and/or closing tags. You just sort of have to get used to it. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From skip at pobox.com Wed Oct 17 14:20:06 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 17 Oct 2001 13:20:06 -0500 Subject: Help optimize a script? In-Reply-To: References: Message-ID: <15309.52182.446718.577072@beluga.mojam.com> Joseph> First, does anyone know of a tool that does this so I don't have Joseph> to reinvent the wheel, and barring that, can anyone offer some Joseph> tips on how to optimize this code [snip] Joseph> Any suggestions on how to speed this up? First suggestion: check out the xreadlines module if you are using a pre-2.2 version of Python. If you are using 2.2 already you can just loop over the file object because it implements the iterator protocol: for line in sys.stdin: ... (xreadlines might still be faster because of buffering, you'll have to check to be sure.) Second suggestion: make "new" a list and either just append to it (starting with new being an empty list): new = [] for index ...: new.append(string.strip(...)) ... or set the index in new explicitly (starting with new being a list of appropriate length filled with None): new = [None] * len(indecies[sys.argv[1]]) for index ...: new[index] = string.strip(...)) ... When you want to print the result just join the list: print "".join(new) or print string.join(new, "") Third (minor) suggestion: if you are using a version of Python with string methods (to check, does executing "print ''.join" work?), skip string.strip and just use the strip() method of the string you're manipulating. Fourth suggestion: to allow people to respond directly to you, don't try and disguise your email address. I couldn't tell what I needed to do to get email to you (delete "no-spam"? change "someone" to something else? change "arbitrary" to something else?), so I just punted and am simply replying to the list. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From pearu at cens.ioc.ee Mon Oct 29 10:33:26 2001 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 29 Oct 2001 17:33:26 +0200 Subject: Putting site-packages somewhere else In-Reply-To: References: Message-ID: Here is one simple (but not very nice way, I guess) to cheat both Encap and Distutils (never tried myself, though): 1) install python. Then from your descriptions there should be /usr/local/encap/python-2.1.1 - a directory /usr/local/lib/python-2.1 - a link pointing to /usr/local/encap/python-2.1.1/lib/python-2.1 2) Move /usr/local/encap/python-2.1.1/lib/python-2.1/site-packages somewhere where you like it to be, say, /path/to/site-packages. 3) Create symbolic link /usr/local/encap/python-2.1.1/lib/python-2.1/site-packages pointing to /path/to/site-packages Regards, Pearu On Sun, 28 Oct 2001, Lars Kellogg-Stedman wrote: > I'm a long-time perl user who's recently started working more with Python. > I'm also responsible for software packaging and distribution at my > employer, and I'm looking for some suggestions in maintaining our Python > distribution. > > We're using an Encap-based software distribution system, which means that > each software package is installed into its own subdirectory, e.g., > '/usr/local/encap/python-2.1.1', and then symlinks are created so that it > appears in /usr/local. > > The problem is that additional modules -- e.g., modules that end up in > site-packages -- should *not* get installed into the package directory. > They should be placed in, e.g., /usr/local/lib/python2.1/site-packages, > rather than /usr/local/encap/python-2.1.1/lib/python2.1/site-packages, > which is where they're going right now. > > After spending some time looking through the Python documentation and > perusing some mailing list archives, I haven't found a good way of doing > this. The solution needs to fulfill the following requirements: > > (1) Distutils needs to know about the proper location for packages, > so that no additional flags need be specified on the command line. > > (2) The interpreter needs to know about the site-packages directory > *outside* of the python installation prefix. > > I thought that perhaps I could modify site.py to add the additional > path(s), but after reading through the comments in that file, I'm not > exactly sure how I would go about making those changes. I'm sure this is a > common problem with a simple solution; I'd appreciate it if someone could > point me at it. > > Thanks! > > -- Lars > > -- > Lars Kellogg-Stedman > > From a00tch00 at nchc.gov.tw Tue Oct 23 23:41:49 2001 From: a00tch00 at nchc.gov.tw (T. C. Huang) Date: Wed, 24 Oct 2001 11:41:49 +0800 Subject: How to set papersize for printer in win32 Message-ID: <3BD6387D.5AC8219@nchc.gov.tw> Hi, Anyone knows how to set papersize (such as letter or A4) for a printer by pythonwin. I program directly to draw contents on DeviceContent. Tsuangchi Huang From skip at pobox.com Thu Oct 11 09:22:07 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 11 Oct 2001 08:22:07 -0500 Subject: python process killed In-Reply-To: <9q4503+mtup@eGroups.com> References: <9q4503+mtup@eGroups.com> Message-ID: <15301.40191.72924.355735@beluga.mojam.com> Kiran> I was trying to run a giant program, which generates something Kiran> like 200 million lines of data and write to a file. The python Kiran> program stops in between and just displays "Killed" after Kiran> terminating. Are you sure it successfully terminates before getting "killed"? If you are trying to manipulate 200 million lines of data in memory I suspect you're running out of virtual memory. Try running "top" to monitor the process size and available free/virtual memory as your program runs. Kiran> OS : Linux 7.1 Kiran> Python Version : 2.2a1 Kiran> LinuxUser : Ordinary(not root) While I doubt it's the cause of your problem, you should either not be running any 2.2 alpha release or be prepared to closely track the changes to the distribution. The current stable release is 2.1.1. The current alpha release is 2.2a4. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From tjreedy at home.com Thu Oct 18 20:13:59 2001 From: tjreedy at home.com (Terry Reedy) Date: Fri, 19 Oct 2001 00:13:59 GMT Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> Message-ID: "Huaiyu Zhu" wrote in message news:slrn9sua6b.k8.huaiyu at gauss.almadan.ibm.com... > Here are 6 examples [from standard library] Most should be rewritten with iterators. No other new syntax is needed. Then there is this: > Lib/ftplib.py: > --------------------------------------------(3) > def getmultiline(self): > line = self.getline() > if line[3:4] == '-': > code = line[:3] > while 1: > nextline = self.getline() > line = line + ('\n' + nextline) > if nextline[:3] == code and \ > nextline[3:4] != '-': > break > return line > > changed to > > def getmultiline(self): > code = None > lines = [] > while line = self.getline(); lines.append(line); line[3:4] == '-': > if code != line[:3]: break > else: code = line[:3] > return '\n'.join(lines) Thanks for finding some concrete, realistics examples of what the proposed change would lead to. To me, that 'while' line is convincing evidence againt this syntax. What bothers me is this. ';' is a statement separator (whose use is generally discouraged). What the proposed change means is that a 'while' at the beginning of the sequence means that the last statement is instead to be a condition. This requires a sort of mental suspension that I believe many besides me would find obnoxious. Terry J. Reedy From arp at europe.com Mon Oct 1 20:38:01 2001 From: arp at europe.com (ARP RF) Date: Tue, 2 Oct 2001 04:38:01 +0400 Subject: =?KOI8-R?B?8sXLzMHNwSDXINLFx8nPzsHM2M7PyiDQ0sXT08U=?= Message-ID: ?????????? ???????????? ?????? ?? ??????????: 2.550 ?????? - ? ???? ??????? ? 65 ????????? ??????? ?????? (????? ????? - 1.700.000 ???.) ?? ?????????????? ??????????? ???????: ?????? (095) 956-1872 ?.-????????? (812) 321-8842 ???????????? (3432)78-55-45 _____________________________________ ?????? ???????? ??????????? ????????? E-Market Research Inc. (Seattle, US) ? ???????????? ? ?. 4 ??. 29 ??????????? ??. ??? ??????????? ????? ??????? ?? ???????? ?????????? ? ???????????? ??? ????????? ???????? ?????????. ? ?????? ????????? ???????? ??????????? ????? ???????? ???????? ?? ??? ?????? ? ???????? ? ???? "REMOVE" - ??? e-mail ????? ?????? ?? ???? ?????? ?????????????. ??? ???./???? +1 (360) 351-6818. From esh at berlingske.dk Fri Oct 12 09:07:49 2001 From: esh at berlingske.dk (Emil S. Hansen) Date: Fri, 12 Oct 2001 15:07:49 +0200 Subject: Using assingment as an operator. Message-ID: Hello fellow PP. I have a simple question. In a program I have a statement like this: while re.search("[^a-z0-9.]", domainname = raw_input("Please enter domainname: ")) != None: print "Error in domainname, please use lovercase letters and numbers only." When I run the program I get a "TypeError: unexpected keyword argument: domainname", how can I use an assigment as an operator for a function? -- Best Regards Emil S. Hansen - esh at berlingske.dk - ESH14-DK UNIX Administrator, Berlingske Tidende - www.berlingske.dk "Tilgiv mig min uvidenhed, men man kan vel forh?bentlig logge ind p? en NT med telnet - ellers kan det vel vanskeligt kaldes et server-operativsystem." - Allan Olesen From phr-n2001d at nightsong.com Mon Oct 15 03:43:31 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 15 Oct 2001 00:43:31 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: <7xitdha8tg.fsf@ruckus.brouhaha.com> Message-ID: <7xu1x1z6u4.fsf@ruckus.brouhaha.com> Ian Parker writes: > >How did Algol 60 deal with this? > > to excess, and with a more complicated parser, I imagine: > > > Because statements are expressions in Algo68, the 'if' clause returns a > value, and can be used as both a statement and an expression, and either > can be squeezed onto one line or spread across multiple lines. Algol 60 wasn't anything like Algol 68 though. Its parser had to have been pretty simple. From chris.gonnerman at newcenturycomputers.net Wed Oct 24 20:10:56 2001 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Wed, 24 Oct 2001 19:10:56 -0500 Subject: Need help with programming. References: <20011024194636.07978.00000094@mb-mb.aol.com> Message-ID: <007501c15ce9$88783840$0101010a@local> ----- Original Message ----- From: "Django" > Hello. I've just begun using Python, and am now getting into simple commands. > Everytime I try to use "else:" I get this message: > > SyntaxError: invalid syntax > >>> else: goes with if:. Can you show us a sample of your source code which does not work? > I've tried retyping it, skipping it, etc. but it's really bothering me... is > there an alternative I can use for "else:" such as "or:"... Or am I typing it > wrong, or something? I tried browsing a few webpage's a bit, to hopefully find > an answer to my question, but I didnt find anything to help me out. Any help > would be very much appreciated. Thank you. Show us the code, and we'll be happy to help. > May I remind you that I AM NEW TO PYTHON, and COMPUTER LANGUAGES ALL TOGETHER > (Excluding HTML). I'M LEARNING PYTHON FOR SELF INTEREST, SO PLEASE NO FLAMES.. Rest easy. The Python community is much nicer than most. From shalehperry at home.com Fri Oct 5 16:07:37 2001 From: shalehperry at home.com (Sean 'Shaleh' Perry) Date: Fri, 05 Oct 2001 13:07:37 -0700 (PDT) Subject: how to create a def that has the behaviour like a built-in k In-Reply-To: Message-ID: > why, oh why, is it illegal and is there a trick to make it legal. > can i call a function without any parenthesis( ). > silly me, but why would you want to do this? From kirill at xyz.donetsk.ua Wed Oct 3 16:04:38 2001 From: kirill at xyz.donetsk.ua (Kirill Simonov) Date: Wed, 3 Oct 2001 23:04:38 +0300 Subject: font display problem in IDLE In-Reply-To: <20011003174548.85437.qmail@web20706.mail.yahoo.com>; from oktay_safak@yahoo.com on Wed, Oct 03, 2001 at 10:45:48AM -0700 References: <20011003174548.85437.qmail@web20706.mail.yahoo.com> Message-ID: <20011003230437.B1011@xyz.donetsk.ua> On Wed, Oct 03, 2001 at 10:45:48AM -0700, Oktay Safak wrote: > > I use sitecustomize.py to use turkish encoding, the > console gets it right but on IDLE, the characters > special to my language are not displayed properly, > some other funny characters are shown instead. When I > write some text to a file and inspect the file with > notepad I see that the characters are OK. So IDLE does > what I want but does not show it properly. I tried to > configure IDLE by changing the font it uses for > display from its config file but somehow a sans-serif > font shows up instead of courier new, and it still > shows the wrong encoding. Any ideas? German and French > fellows might have had a similar problem I guess. > I expect that you use Python 2.1 on Windows. The recipe is: Step 1: Open file "Python21/Lib/lib-tk/FixTk.py", remove all lines and write the following code: import sys, os if not os.environ.has_key('TCL_LIBRARY'): tcl_library = os.path.join(sys.prefix, "tcl", "tclX.Y") os.environ['TCL_LIBRARY'] = tcl_library Step 2: Open file "Python21/Tools/idle/Percolator.py", go to the line 23. You need to insert two lines of code into the function "insert": def insert(self, index, chars, tags=None): # Could go away if inheriting from Delegator if index != 'insert': # You need to add chars = unicode(chars) # these lines. self.top.insert(index, chars, tags) Step 3: Open file "Python21/Tools/idle/PyShell.py", go to the line 470. You need to add two lines: line = self.text.get("iomark", "end-1c") if type(line) == type(u""): # You need to add line = line.encode() # these lines. self.resetoutput() And please tell me, does this recipe solves your problem? \Xi From cjaeger at ensim.com Tue Oct 9 18:24:35 2001 From: cjaeger at ensim.com (Chris Jaeger) Date: Tue, 09 Oct 2001 15:24:35 -0700 Subject: Question about read() behavior and EINTR References: <3BC37564.C8F2418F@ensim.com> Message-ID: <3BC37923.95E44D77@ensim.com> Hrm... I've just realized that I'm probably getting a SIGCHLD from the child process generating the data (which means somewhere I must have registered a handler for it). So, I could solve this by setting up the signal handler for SIGCHLD to restart system calls. However, I'm still wondering if python should have thrown the IOError earlier (back when errno was still set). And what should the behavior be if the signal weren't SIGCHLD? Thanks, Chris Chris Jaeger wrote: > > Hi all, > > I've encountered an annoying behavior with respect to > the built-in read() function and I'm wondering whether it is > a Python bug, a glibc bug, or a case of abusing read(). For > reference, I'm using Python 2.1.1 on a glibc-2.2.2 Linux > system, with kernel 2.4.2. > > I have a python extension module written in C that > executes commands via execl, and returns the stdin, stdout, > and stderr as Python file objects. With one particular > command sequence, my code received an IOError exception > with errno set to 0. I started digging down, and this is > what I've reconstructed about the sequence of events: > > - from python: > data = stdout.read(16384) > while data: > > data = stdout.read(16384) > > Three read()s occur, with the following behavior: > stdout.read(16384) returns 12288 bytes > stdout.read(16384) returns 1266 bytes > stdout.read(16384) throws IOError(0, 'Error') > > I added some tracing code into the python binary and > noticed that the error bit in the FILE structure is set > during the first read, and this is what eventually causes > the IOError to be thrown. Here is a more detailed sequence: > > stdout.read(16384) > file_read(16384) > fread(16384) > read(16384) returns 12288 bytes > read(4096) returns EINTR, causing glibc to set error bit in > FILE > fread returns 12288 bytes > file_read returns 12288 bytes > stdout.read returns 12288 bytes > stdout.read(16384) > file_read(16384) > fread(16384) > read(16384) returns 1266 bytes > read(15118) returns 0, setting EOF bit in FILE > fread returns 1266 bytes > file_read returns 1266 bytes > stdout.read returns 1266 bytes > stdout.read(16384) > file_read(16384) > fread(16384) > fread returns 0 > file_read notes 0 return value and checks ferror() > ferror() returns true (due to EINTR, way back in the first call) > file_read sets up exception and returns > stdout.read throws IOError > > So, any ideas as to who is at fault? Should glibc see EINTR > and not bother setting the error bit? Should python check feof() in > preference to ferror()? Should I be setting up signal handlers to > restart the read system call? Any ideas are appreciated. > > Thanks, > Chris > > -- > http://mail.python.org/mailman/listinfo/python-list From aahz at panix.com Sun Oct 14 22:27:33 2001 From: aahz at panix.com (Aahz Maruch) Date: 14 Oct 2001 19:27:33 -0700 Subject: Will Ware alive? (was Re: where lives uthread (microthreads) now ??) References: <3b091a1c.0110080739.23205b07@posting.google.com> Message-ID: <9qdhil$iek$1@panix2.panix.com> [x-posted to c.l.py and python-dev] In article <3b091a1c.0110080739.23205b07 at posting.google.com>, cmkl wrote: > >I wanted to test a samle code with microthreads needed. >The download area: http://world.std.com/~wware/uthread.html >is not available however. > >Is there a mirror to get this code somewhere? Has anybody heard from Will Ware since 9/12? E-mail to him doesn't bounce, but I haven't received any reply. -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista We must not let the evil of a few trample the freedoms of the many. From thecalm at NOSPAM.btinternet.com Mon Oct 8 07:38:17 2001 From: thecalm at NOSPAM.btinternet.com (G. Willoughby) Date: Mon, 8 Oct 2001 12:38:17 +0100 Subject: permissions removing a directory? References: <9ppo49$cpk$1@neptunium.btinternet.com> Message-ID: <9ps34c$fun$1@plutonium.btinternet.com> yes i am, is there anyway of deleting a whole directory filled with stuff? G. Willoughby "Robert Amesz" wrote in message news:Xns913415E48E29Frcamesz at 127.0.0.1... > G. Willoughby wrote: > > > I want to remove a directory but i keep getting this error: > > > > OSError: [Errno 13] Permission denied: > > > > heres the code: > > > > [snip] > > > > self.workingDirectory=self.directory.get() > > self.thumbnailDirectory=os.path.join(self.workingDirectory, > > "thumbnails") > > if os.path.isdir(self.thumbnailDirectory): > > os.rmdir(self.thumbnailDirectory) > > > > [/snip] > > > > any ideas??? > > Could be you're trying to remove a non-empty directory. > > > Robert Amesz From D.M.Pick at qmw.ac.uk Tue Oct 30 09:15:18 2001 From: D.M.Pick at qmw.ac.uk (please_no_spam_to_) Date: 30 Oct 2001 14:15:18 GMT Subject: Conditional Expressions don't solve the problem References: Message-ID: <9rmclm$nu$1@beta.qmw.ac.uk> Christopher A. Craig (com-nospam at ccraig.org) wrote: : salemail at dial.pipex.com (Kevin D) writes: : > So, to fix those problems a solution must: : > : > 1) Allow the loop's "load" code to exist just once, preferably : > somewhere near the terminating condition. : > 2) Have the terminating condition near the "while", and of the right : > "polarity". : > 3) To be Pythonic, have an obvious meaning. : > : I personnally don't like your suggestion as they are mind numbingly ugly and : remind me of the Algol 60 loops. I wish Python had initially adopted : do: : : until : : Which is, of course, behaves identically to : while 1: : : if : break : : but is prettier. But I don't see the increased readability being sufficient : to warrant the change. Additionally I think that the present system is not : that hard to adapt to. And even prettier is: do: until condition: with the indentation highlighting the places where an "exit" from the loop can happen under control. -- David Pick From tjreedy at home.com Wed Oct 17 15:15:11 2001 From: tjreedy at home.com (Terry Reedy) Date: Wed, 17 Oct 2001 19:15:11 GMT Subject: Help optimize a script? References: Message-ID: <3Nkz7.138277$5A3.44609227@news1.rdc2.pa.home.com> "Joseph Santaniello" wrote in message news:Pine.LNX.4.33.0110171040490.22682-100000 at harmony.arbitrary.org... > Hello All, > > I have a simple script that I wrote to convert some fixed-width delimted > files to tab-delimited. > > It works, but some of my files are over 100MB and it takes forever. > > First, does anyone know of a tool that does this so I don't have to > reinvent the wheel, and barring that, can anyone offer some tips on how to > optimize this code: > > indecies = { 'cob':[3,6,2,2,8,1,8], 'opend':[6,3,3,2,3,4,12,29] } > # above is trimmed for this example > # the lists in these dictionaries above are are the widths of the fields > # in the input files. The keys match the input file names just to keep > things readable. > > > # while is used cuz line in readlines() used too much ram with > # huge files. > while 1: > line = sys.stdin.readline() > if not line: > break > new = '' > start = 0 > for index in indecies[sys.argv[1]]: > new = new + strip(line[start:start + index])+'\t' > start = start + index > print new > > So it reads in a line, then iterates over the list in he corresponding > dictionary, and prints stripped substrings extracted according the the > field widths in the list, printing a tab between each, then grabs a new > line and does it again. > > Any suggestions on how to speed this up? 1. Build the new (output) line by appending to a list and then joining with \t. new = [] for whatever: new.append(field) print '\t'.join(new) This is linear rather than quadratic in num fields and should speed things up in itself. 2. for line in file.xreadlines() may be faster if using new enough Python. I believe it reads in large blocks and then peels off lines. Otherwise, try to find code on groups.google which does same. IE, read in megabyte (for instance) split into lines, deliver 1 at a time, and paste leftover piece onto beginning of next block. readline() is known to be slow. 3. If fields have spaces between and none within, break up lines with split(). Otherwise, preprocessing index (pl. indices or maybe indexes, but not what you wrote) into tuple of duples (pairs) with start and stop for each field might or might not be faster. IE. fields = process ([3,6,2,2,8,1,8]) # ((0,3),(3,9),(9,11),(11,13),(13,21),(21,22),(22,30)) for start,stop in fields: new.append(strip(line[start:stop])) Even better, carry preprocessing idea further and replace simple list of field widths with explicit expression for new line field sequence that unrolls inner loop. ie, forms = { 'cob': lambda x: (strip(x[0:3], strip(x[3:9], ..., strip(x[22:30]), ...} (This conversion can be done with a fairly simple function.) Then, your program reduces to new = forms['cob'] for line in file.xreadlines(): print '\t'.join(new(line)) If fields do not have spaces within, it might be faster to build lines and delete spaces all at once with translate after joining. Good luck. Terry J. Reedy From paul at ActiveState.com Mon Oct 15 21:16:22 2001 From: paul at ActiveState.com (Paul Prescod) Date: Mon, 15 Oct 2001 18:16:22 -0700 Subject: FW: [Python-Dev] conditional expressions? References: <9qfu1p$iei$1@newshost.accu.uu.nl> <7xitdg4efs.fsf@ruckus.brouhaha.com> Message-ID: <3BCB8A66.E3989C71@ActiveState.com> Paul Rubin wrote: > > m.faassen at vet.uu.nl (Martijn Faassen) writes: > > * list comprehensions are signalled by the fairly clear [ and ]. > > Conditional expressions use the already fairly strongly > > overloaded ( and ). Of course I guess they wouldn't really > > overload them further, but.. > > A conditional expression analogy to list comprehensions would be > x = (a if b else c) > rather than > x = if a then b else c The former actually reads better in English: unit is meters if metric else feet versus unit is, if metric, meters, else feet Paul Prescod From dale at riverhall.NOTHANKS.co.uk Mon Oct 29 09:53:44 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 29 Oct 2001 14:53:44 +0000 Subject: xml.dom.minidom.parseString() doesn't accept Unicode. References: Message-ID: Dale Strickland-Clark wrote: >Given that XML is very Unicode friendly, this seems a rather odd >limitation. > >>>> import xml.dom.minidom >>>> dom = xml.dom.minidom.parseString(u'') >Traceback (most recent call last): > File "", line 1, in ? > File "c:\python21\lib\xml\dom\minidom.py", line 915, in parseString > return _doparse(pulldom.parseString, args, kwargs) > File "c:\python21\lib\xml\dom\minidom.py", line 901, in _doparse > events = apply(func, args, kwargs) > File "c:\python21\lib\xml\dom\pulldom.py", line 299, in parseString > buf = StringIO(string) >TypeError: expected string, unicode found >>>> Should I fill in a bug report for this? -- Dale Strickland-Clark Riverhall Systems Ltd From chrishbarker at home.net Mon Oct 22 13:24:14 2001 From: chrishbarker at home.net (Chris Barker) Date: Mon, 22 Oct 2001 10:24:14 -0700 Subject: Dictionary from list? References: Message-ID: <3BD4563E.9F15F335@home.net> Tim Peters wrote: > So what should dictionary(x) do? Personally, I would find: dict = dictionary(sequence_of_keys, sequence_of_values) most valuable to me because I have found the need for it enought times that I have written my own function to do it, and have used it a lot. If it were: dict = dictionary(sequence_of_keys_value_pairs) I could do: dict = dictionary(zip(sequence_of_keys, sequence_of_values)) So that would be me second choice. All I can say about: dictionary([k,v,k,v,k,v]) is YECH! (IMHO, of course) -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From mertz at gnosis.cx Tue Oct 2 13:18:13 2001 From: mertz at gnosis.cx (Dr. David Mertz) Date: Tue, 02 Oct 2001 13:18:13 -0400 Subject: XML Marshalling of objects (fwd) Message-ID: |http://www-106.ibm.com/developerworks/xml/library/xml-matters1/ I am pleased that a couple people posted links to my xml_pickle module, and the above article I wrote discussing it. I just wanted to add that some of the limitation discussed in the above article (and some others users discovered after the article was written) have been lifted. And some other improvements have been made along the way by users. The new, brighter, shinier version is discussed in: http://www-106.ibm.com/developerworks/library/x-matters11.html You can also read the changelog in thhe module docstrings to get a sense of enhancements: http://gnosis.cx/download/xml_pickle.py Given the first poster's requirements, I think xml_pickle is a better choice than XML-RPC (for example, it knows about lists/tuples). From wtanksle at dolphin.openprojects.net Thu Oct 25 20:37:15 2001 From: wtanksle at dolphin.openprojects.net (William Tanksley) Date: Fri, 26 Oct 2001 00:37:15 GMT Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> <9r5h75$1m5$1@slb6.atl.mindspring.net> Message-ID: On Thu, 25 Oct 2001 01:17:31 +0000 (UTC), Huaiyu Zhu wrote: >On Wed, 24 Oct 2001 20:11:31 GMT, William Tanksley >>I'm confused -- I don't see how your version can work either. Both of you >>are iterating over an empty list, and the only code which could possibly >>add anything to the list is inside the iteration; that list is empty no >>matter what, so nothing will execute, and the list will never be anything >>but empty. >That's what that 'else' is for - and that's the whole point of this thread. >I have a suspicion that the usage of for-else in Python is not well known to >many discussants in this thread. A well-founded suspicion. I've complained about Python's for-else before, and I find it so bad that I consider any code using it to be broken until proven correct. Looks like I accidentally followed that rule here (sorry, my fault). >The equivalent code is (note the duplication of primes.append(n)): > def getprimes(x): > primes = [] > for n in range(2, x): > for p in primes: > if p*p > n: primes.append(n); break > elif n % p == 0: break > else: primes.append(n) > return primes >Try it and see how it works. Yes, I see. Thanks for the equivalent code. I begin to see (thanks to the equivalent code) the reasoning behind your 'for-while' construct: you wish to have a way to automatically iterate through a sequence which has a stopping point that has to be computed. Such sequences will appear especially often with generators (which can well be infinite). I will join with those who suggest that you write this up in a PEP. But it appears to me that generators, in addition to aggrivating the problem, also provide the obvious solution: def up_to_sqrt_of(square,sequence): for x in sequence: if x*x < square: yield x else: return def primes(max): primes = [] for n in range(2,max): for p in up_to_sqrt_of(n, primes): if n%p==0: break else: primes.append(n) >>I don't like your "for x in list while y" construct, either. It's >>terrificly ambiguous: does it mean that every item in the list which meets >>the 'y' criterion will be processed, or does it loop over all the items up >>to the first one which fails to satisfy 'y'? >So let me explain this in detail and hope I don't need to do it again. I do appreciate your earlier explanation -- I now understand why you want that code, and I see how it works. I didn't find your explanation below helpful. It was confusing for two reasons: first, the way you laid it out forced me to refer between three texts (the code, the explanation, and a legend); and second, the legend referred to a "pass", which was not present anywhere in the code. But that's academic; as I mentioned, thanks to your other efforts, this makes sense to me now. >The pseudo code was: > def getprimes(x): > primes = [] > for n in range(2, x): > for p in primes while p*p < n: > if n % p == 0: break > else: primes.append(n) > return primes >The 'for p' loop will exit under three conditions: >- p reaches end of primes: jump to (A) >- not p*p < n: jump to (A) >- n % p == 0: jump to (B) >where >(A) primes.append(n) >(B) pass I'm not sure where (B) is. Perhaps instead of "jump to (B)" your explanation should say "continue the outer loop". >The juicy part of the code is: > for p in primes while p*p < n: > if n % p == 0: break > else: primes.append(n) >So the question is: is there a way to write the idea that two of the exits >go to the same follow-up code (A) without actually duplicating the code in >(A), or using a temporary variable to hold the state information? I have >not found a positive answer (which is not the same as claiming it does not >exist). Does the generator solution work for you? >Why does this matter at all? >I hope this clarifies what I meant when I said that the issue really appears >to be the existence of two types of exits of loops. Indeed. >Of course, all of these could be easily done by using an auxiliary >variable found_factor which is set to true or false before different >breaks, and using an "if found_factor" after the loop. But I found the >pseudocode clearer, as long as one makes the mental distinction between >"exiting due to exhausting of candidates" and "exiting due to a special >condition being met". It would be convenient if Python allows such >pseudocodes to be real codes. It really seems ideal for generators -- they form sequences which can have arbitrary terminations, just like you want. That way your real for loop ALWAYS examines all of the possibilities. >In any case, a syntax that removes the benefit of existing for-else and >while-else structures would look quite a retrogress to me. Grin. Such a thing would lighten my heart -- I hate for-else. Someday I'll use it by accident, I'm afraid, and create code which is readable only by Python experts. >Huaiyu -- -William "Billy" Tanksley From claird at starbase.neosoft.com Tue Oct 9 09:51:08 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 9 Oct 2001 08:51:08 -0500 Subject: wxPython and Tkinter References: <3daa1aa8.0110080841.526a6cc2@posting.google.com> Message-ID: In article <3daa1aa8.0110080841.526a6cc2 at posting.google.com>, Jeffrey wrote: >I was wondering if anybody knew if it was possible to have wxPython >widget be placed on a Tkinter Canvas Widget. wxPython has a HTML >displayer and I wanted to display HTML on the Tkinter Canvas Widget. > > Thanks, > Jeff Yes and no. No, I know of no one who has melded wxPython and Tkinter; however, Tk-ers have been experimenting with hybridized toolkits during the last year or so. It would take serious, but finite, effort to provide the same for Python. Tkinter doesn't build in an HTML widget--I assume the htmllib- formatter combination doesn't satisfy you. I thought PMW provided one, but now I can't find it. The Tk people have a couple , but I don't know that anyone's gone to the trouble of packaging them for Tkinter. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From sheila at spamcop.net Thu Oct 25 09:43:00 2001 From: sheila at spamcop.net (Sheila King) Date: Thu, 25 Oct 2001 13:43:00 GMT Subject: smtp References: <9r925q$863$1@verence.demon.co.uk> Message-ID: <9r8c9e.3vv9mah.1@kserver.org> On 25 Oct 2001 13:56:26 +0100, -$Paul$- at verence.demon.co.uk (Paul Wright) wrote in comp.lang.python in article <9r925q$863$1 at verence.demon.co.uk>: :- Some ISPs transparently redirect outgoing SMTP connections to their : own mail server. So you're program will probably still work in those : cases. This is what AOL does, and yet his program didn't work. However... with AOL, even though you use a non-AOL address in the From: field, it adds some "apparently-from:" header to the email, with your AOL address in it. Is it possible, that he wasn't 'logged-on' as an AOL userid, and so the earthlink.net addy got refused as a bad sender? (He got SMTPSenderRefused error, which sounds like it was complaining about the From: address ? Actually, now that I think about it, it would be complaining about the sender in the SMTP envelope. I wonder if he changed that to the correct AOL logon id, if his program would now work, even though he left the earthlink.net sender in as the mail server. What should happen at AOL, is that even though you designate the earthlink mail server, it will quietly intercept and send through their own server anyway. Try changing the address in the SMTP envelope. (i.e. the sender of the SMTP envelope doesn't have to be the same as the From: header in the message itself). Try this: Add an additional prompt after From: fromaddr = prompt("From: ") sender = prompt("SMTP Sender: ") I would try the user's AOL logon id for the sender? And change this line: server.sendmail(fromaddr, toaddrs, msg) To this: server.sendmail(sender, toaddrs, msg) And see if you can send through AOL using that code? Still, the best thing is to let the user also specify his own SMTP server. I'm not sure why you aren't letting the user configure that for themself? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From loewis at informatik.hu-berlin.de Wed Oct 31 05:45:51 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 31 Oct 2001 11:45:51 +0100 Subject: XML can't read Unicode shock horror. News at 11. References: Message-ID: Dale Strickland-Clark writes: > I see that this is probably the same as Python bug #216388 which has > been around for over a year and been given a low priority (3). It is not the same bug. Even if cStringIO supported Unicode objects, expat would still require byte strings. > Non-unicode XML is a bit restrictive. :-( Why do you think so? XML documents are byte sequences, not character strings. The *content* is Unicode; the document is not. Regards, Martin From john.thingstad at chello.no Mon Oct 22 04:08:02 2001 From: john.thingstad at chello.no (John Thingstad) Date: Mon, 22 Oct 2001 10:08:02 +0200 Subject: primes Message-ID: <20011022084013.CYFB12720.mta01@mjolner> reusing n is probably confusing. Try this then: def prime(max): set = [2] + range(3,max, 2) for n in range(3, int(math.sqrt(max))+1, 2): set = [x for x in set if x == n or x % n != 0] return set From uwe at rocksport.de Fri Oct 5 17:17:58 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 5 Oct 2001 21:17:58 GMT Subject: wxPython-question References: <9phpjm$5qrtb$1@hades.rz.uni-sb.de> Message-ID: <9pl826$5scab$1@hades.rz.uni-sb.de> Vadim Zeitlin wrote: | On 4 Oct 2001 13:52:54 GMT, Uwe Schmitt wrote: |> This works fine until i add an EVT_SIZE-handler: |> now the text in tex Text-Control disapears.... | Do you call event.Skip() in your event handler? No. shouuld I ? Where should I use it ? I followed the wxWindows-doc and there was no event.Skip() at all... Yours Uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From heiland at ncsa.uiuc.edu Tue Oct 30 12:43:34 2001 From: heiland at ncsa.uiuc.edu (Randy Heiland) Date: Tue, 30 Oct 2001 11:43:34 -0600 Subject: os.listdir Message-ID: <3BDEE6C6.8E96DBF3@ncsa.uiuc.edu> I get this: >>> for file in os.listdir('mydir'): ... print file ... f100.dat f1.dat f2.dat but would like this: f1.dat f2.dat f100.dat What's the trick? thanks, Randy From andreas at mtg.co.at Tue Oct 23 05:47:19 2001 From: andreas at mtg.co.at (Andreas Kostyrka) Date: Tue, 23 Oct 2001 11:47:19 +0200 Subject: Array of 2^n In-Reply-To: <9qvbat$kak$1@news-int.gatech.edu> References: <9qvbat$kak$1@news-int.gatech.edu> Message-ID: <200110230947.f9N9lQR11603@lap1.mtg.at> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am Sonntag, 21. Oktober 2001 22:31 schrieb Moshe: > John Thingstad had nothing better to do than to say: > > l = [2**i for i in range(10)] > > I definitely like this way more than the lambda way, because it is far > more readable. Well, at least for python 2.0 (SuSE 7.2) this way is also about 25% slower than map/lambda (7 seconds to 10 seconds wall time). Which is sad, because I like the new syntax much better than the lambda one :( Has it been sped up in later versions? Andreas - -- Andreas Kostyrka; Raiffeisenstr. 16/9; 2320 Zw?lfaxing Tel: +43/676/4091256; Fax: +43/1/7065299 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.5 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE71TyrHJdudm4KnO0RAjazAKDcY6f+05/i4kK1P4rHTLDVDyzLMgCdFfwN vjHex+ntYlqIewtzTC2K/qQ= =4iRJ -----END PGP SIGNATURE----- From sholden at holdenweb.com Mon Oct 1 17:16:06 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 1 Oct 2001 17:16:06 -0400 Subject: Are there 'Interfaces' in Python?? References: <9orb19$ba6$1@slb6.atl.mindspring.net> <9oufa5$8rm$1@chabry.caltech.edu> <9p406c$k8e$1@chabry.caltech.edu> Message-ID: <1%4u7.11117$ib.158249@atlpnn01.usenetserver.com> "Quinn Dunkan" wrote ... [ ... ] > Someone must have unplugged Alex or deleted his state pickle... both > "interfaces" and "signature-oriented polymorphism" have come up and he's > nowhere to be seen. In a Nutshell, he's busy! regards Steve -- http://www.holdenweb.com/ From maj64 at hotmail.com Sat Oct 13 14:31:03 2001 From: maj64 at hotmail.com (Mark J) Date: 13 Oct 2001 11:31:03 -0700 Subject: dictionary.update() enhancement? References: Message-ID: "Tim Peters" wrote in message news:... > [Mark J] > > The above enhancement ... > > would be much faster than anything that can currently be implemented > > within Python (by subclassing dictionary and overriding the update > > method with hand iteration). > > Unfortunately, it would be slower than hand iteration. David Bolen went > into the most detail about that, and he's right: the overhead of calling > back into a Python function each time would kill performance. > > Compare, e.g., > > x = 3 > for i in xrange(1000000): > y = x+x > > to > > def add(i, j): > return i+j > x = 3 > for i in xrange(1000000): > y = add(x, x) > > for a direct comparison of doing a thing by hand inline versus calling a > Python function to do it. When I ran the above comparison, the extra call to the Python function performed a bit less than half as fast as the inline function (43%). This is about the cost that I was figuring on. > I should also note that the actual implementation of dict.update does no > "collision checking" at all; Ya, I should have kept the collision conditional out of the loop in withloop() for a fairer test. Without the collision test, the hand iteration is still about 10x slower. When I used other.iteritems() instead of other.items() with Python2.2a4, I didn't notice a change in performance until dictsize was over about 3000. After about dictsize=5000, there was roughly a 2x speedup using iteritems() over item(). I'll drop the case. Nonetheless, I appreciate the discussion... Mark From max at alcyone.com Tue Oct 23 16:23:21 2001 From: max at alcyone.com (Erik Max Francis) Date: Tue, 23 Oct 2001 13:23:21 -0700 Subject: Import Error within Python Win32 COM object References: Message-ID: <3BD5D1B9.43C1B84C@alcyone.com> Sue Giller wrote: > But, if I add `import Numeric` to it, I get the error. The module > runs > just fine as a simple python class module - it finds all imports, > whether run from PythonWin or DOS. Well, did you install NumPy? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ War is cruelty, and you cannot refine it. \__/ Karl Shapiro Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html A new, virtual planet, every day. From DeepBlue at DeepBlue.org Wed Oct 24 10:38:47 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Wed, 24 Oct 2001 09:38:47 -0500 Subject: python as a cgi script engine References: Message-ID: When you say it failed: What error are you getting? DB "jilly" wrote in message news:f828f146.0110240116.27caedca at posting.google.com... > i use "http://localhost/CGI/python.exe?hello.py" ,then i succeed. > but when i use "http://localhost/CGI/hello.py" ,i failed. > and i have setted scriptmap in the IIS > (just like:".py-->c:\python21\python.exe -u"). > > The context is: > windows 2000 and IIS server > > Please help me > Thanks first! From cja at dds.nl Tue Oct 23 17:21:24 2001 From: cja at dds.nl (Chris Abraham) Date: Tue, 23 Oct 2001 23:21:24 +0200 Subject: Looking for Python & Zope =?ISO-8859-1?B?R3VydXMnIFLpc3Vt6XMh?= In-Reply-To: <1003861636.411.48320.m9@yahoogroups.com> References: <1003861636.411.48320.m9@yahoogroups.com> Message-ID: <1003872084.3bd5df544e015@webmail.dds.nl> Gurus & Geeks: I would like to have a file of Python, and Zope coders who are available for short-term, long-term, contract, sub-contract work, project-based, and "crap, it broke can you fix it?" work. ? Either in the Washington Metro Area or via Telecommuting. ?If you are out of the DC-Area, please send your resume anyway, and I will keep it on file. ?I am getting lots of requests and I want to make sure that I have loads of people who might be interested in the projects. Please send your r?sum? and an hourly, day, and salary range and I will do what I can. Cheers, Chris Abraham -- chris abraham washington, dc 20003-0163 united states From gh_pythonlist at gmx.de Thu Oct 25 09:19:15 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 25 Oct 2001 15:19:15 +0200 Subject: HELP for embedding Python in C prog In-Reply-To: <3bd7e585$0$853$626a54ce@news.free.fr>; from dag4004@caramail.com on Thu, Oct 25, 2001 at 12:15:15PM -0400 References: <3bd7e585$0$853$626a54ce@news.free.fr> Message-ID: <20011025151915.A1406@lilith.hqd-internal> On Thu, Oct 25, 2001 at 12:15:15PM -0400, dag4004 wrote: > hello, > > I want to embedded Python in a C prog. I try with the Programming Python > (O'REILLY). > Here is the exemple : basic1.c > > #include > > int main(void) > { > Py_Initialize(); > PyRun_SimpleString("a=1"); > PyRun_SimpleString("print a"); > return 0; > } > > the makefile > > PY = /usr/src/Python-2.1.1 > > PLIBS = $(PY)/libpython2.1.a > > basic1: basic1.o > gcc -g basic1.o $(PLIBS) -lm -o basic1 > > basic1.o: basic1.c > gcc basic1.c -c -g -I$(PY)/Include -I$(PY)/. > > And what i get : > > # make > gcc -g basic1.o /usr/src/Python-2.1.1/libpython2.1.a -lm -o basic1 > /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function > `posix_tmpnam':/usr/src/Python-2.1.1/./Modules/posixmodule.c:4212: the use > of `tmpnam_r' is dangerous, better use `mkstemp' > /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function > `posix_tempnam': > /usr/src/Python-2.1.1/./Modules/posixmodule.c:4168: the use of `tempnam' is > dangerous, better use `mkstemp' > /usr/src/Python-2.1.1/libpython2.1.a(dynload_shlib.o): In function > `_PyImport_GetDynLoadFunc': > /usr/src/Python-2.1.1/Python/dynload_shlib.c:86: undefined reference to > `dlopen'/usr/src/Python-2.1.1/Python/dynload_shlib.c:94: undefined > [...] You need to link against additional libraries. To know which ones, try this at an interactive Python prompt: >>> from distutils.sysconfig import get_config_var >>> print get_config_var("LIBS") + " " + get_config_var("SYSLIBS") -lpthread -ldl -lutil -lm Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From kragen at dnaco.net Tue Oct 16 15:24:19 2001 From: kragen at dnaco.net (Kragen Sitaker) Date: Tue, 16 Oct 2001 19:24:19 GMT Subject: import question References: <9qhkrp$n3u64$1@ID-11957.news.dfncis.de> Message-ID: In article <9qhkrp$n3u64$1 at ID-11957.news.dfncis.de>, Emile van Sebille wrote: >What you're looking for is reload. Watch out for its 'gotcha's though, as >you may not get what you'd expect from previous existing objects. Right. Specifically, objects created from the old version of the module will retain their old behavior. -- Kragen Sitaker Perilous to all of us are the devices of an art deeper than we possess ourselves. -- Gandalf the White [J.R.R. Tolkien, "The Two Towers", Bk 3, Ch. XI] From donn at u.washington.edu Mon Oct 8 12:20:23 2001 From: donn at u.washington.edu (Donn Cave) Date: 8 Oct 2001 16:20:23 GMT Subject: safe simultaneous file append? References: <3np2st060vt841lqfimibi12909td1p02c@4ax.com> <9prtkc$56a$1@samos.cs.uu.nl> <1cv2st0g180m0cfoloqf99s5pofe4pmi32@4ax.com> Message-ID: <9psjo7$i1g$1@nntp6.u.washington.edu> Quoth "Chris Gonnerman" : ... [ re O_APPEND ] | The only thing you need to do for safety is to ensure that complete | messages are written by a single write(2) call. Do this: | | logfile.write("A long message...\n") | | rather than this: | | logfile.write("A ") | logfile.write("long message...") | logfile.write("\n") | | (for instance) | | It wouldn't hurt to add | | logfile.flush() | | after each write. In fact that flush() would be a darn good idea. Or just use posix.write directly, to get that single write(2) call. Otherwise, if you just let the file object do its thing, I'm pretty sure the appended write will be a buffer and not a line. Donn Cave, donn at u.washington.edu From gbreed at cix.compulink.co.uk Fri Oct 26 12:51:30 2001 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Fri, 26 Oct 2001 16:51:30 +0000 (UTC) Subject: Confusion with string.replace() References: Message-ID: <9rc4ai$4jn$1@thorium.cix.co.uk> Joseph Wilhelm wrote: > I'm getting some really strange behaviour from string.replace(), and I > was > wondering if somebody could help explain this to me. All I'm trying to > do is > escape single quotes in a string for a SQL query, but here's an example > of > what I'm getting: > > >>> import string > >>> a = "a'b" > >>> b = string.replace( a, "'", "\'" ) > >>> b > "a'b" > >>> b = string.replace( a, "'", "\\'" ) > >>> b > "a\\'b" > >>> > > I just can't seem to wrap my brain around why it's doing that. Can > somebody > explain that, or perhaps provide an easier option for preparing a SQL > statement? The second example is doing what you thing is should do. Try print b to see that this is so. But string.replace(a, "'", "''") is correct SQL. The best option is to use a library to do the dirty work for you. Graham From robin at jessikat.fsnet.co.uk Thu Oct 25 11:00:24 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 25 Oct 2001 16:00:24 +0100 Subject: super References: Message-ID: <22ZMKKAIkC27EwBH@jessikat.demon.co.uk> In article , Martin von Loewis writes >Robin Becker writes: > >> After looking at the 2.2 'features' I started wondering why there isn't >> a special attribute __super__ to indicate super(self.__class__,self). >> GvR indicates that as it stands super will likely cause cut and paste >> errors and gives a hacky workaround, but wouldn't it be easier to have a >> special attribute? > >I think having it use self.__class__ inside would be undesirable; it >should be super(class_in_which_super_call_occurs, self) instead, no? > >The problem here would be that you'd need compile-time computation of >the class object, which is difficult: the class object hasn't been >constructed, and you can't statically know what its name is. > >Regards, >Martin yes you're probably right, seem pretty poor of the parser not to allow the name of the class to be known in the class scope, but that's python. I wonder why pascal could do this so easily and pythoneers find it so hard. Must be that out of date LL(1) technology. -- Robin Becker From paul1brian at yahoo.com Fri Oct 12 12:04:22 2001 From: paul1brian at yahoo.com (Paul Brian) Date: Fri, 12 Oct 2001 17:04:22 +0100 Subject: Python, XML, and databases References: <9q1hir$tji$1@slb3.atl.mindspring.net> Message-ID: <1002902665.4775.0.nnrp-02.c1c3e19f@news.demon.co.uk> I seem to remember some stuff by David Mertz mentioning this. Try looking on the IBM DeveloperWorks site for xml2SQL. wrote in message news:9q1hir$tji$1 at slb3.atl.mindspring.net... > Is there a Python tool to exchange data between a relational database and > XML? > > I've looked at python.org, searched the archive of this list and xml.com, > looked in the mysql documentation, no luck yet. Pointers welcome, hopefully > I've missed something. > > thx, > > - adina > > From syver at NOSPAMcyberwatcher.com Tue Oct 23 00:00:32 2001 From: syver at NOSPAMcyberwatcher.com (Syver Enstad) Date: Tue, 23 Oct 2001 04:00:32 GMT Subject: Multimedia audio programming in Python Message-ID: I wonder (being totally green in sound programming) if it is straightforward to make a python program to adjust speed on an audio CD track without changing the frequency of the sound. What modules could help me. Any suggestions much appreciated. From leo at iems.nwu.edu Fri Oct 5 16:17:45 2001 From: leo at iems.nwu.edu (Leonardo B Lopes) Date: Fri, 05 Oct 2001 15:17:45 -0500 Subject: SQL/Python question -- slow... What is the fixed cost? References: Message-ID: <3BBE1569.277E53A0@iems.nwu.edu> Ignacio Vazquez-Abrams wrote: > > MySQL is pretty good at keeping the relevant data in memory, so there > shouldn't be much if any gain that way. > That is what I thought too, which is why I figured I could rely on it for this job. I might still be able to. But the crux of the problem is that the profiler after all is NOT measuring the time being used by the mysql process. A good explanation with source snippets has been provided by Skip. See another posting on this thread... -- ======================================================================= Leonardo B. Lopes leo at iems.nwu.edu Ph.D. Student (847)491-8470 IEMS - Northwestern University http://www.iems.nwu.edu/~leo From barry at zope.com Tue Oct 23 23:04:22 2001 From: barry at zope.com (Barry A. Warsaw) Date: 23 Oct 2001 23:04:22 -0400 Subject: Dictionary from list? References: <9r463e$2umq$1@nntp6.u.washington.edu> Message-ID: >>>>> "REO" == Russell E Owen writes: REO> Thank you for a most mooving posting -- funniest I've read in REO> a programming newsgroup in a long time. Yes, but udderly worthless. http://barry.wooz.org/poems/milkme2.html-ly y'rs, -Barry From cliechti at gmx.net Mon Oct 29 13:44:07 2001 From: cliechti at gmx.net (Chris Liechti) Date: 29 Oct 2001 20:44:07 +0200 Subject: Python still remembers script after change and save References: <1004382387.8324.0.nnrp-07.c1c3e128@news.demon.co.uk> Message-ID: "Paul Brian" wrote in news:1004382387.8324.0.nnrp-07.c1c3e128 at news.demon.co.uk: > I occasionally come across a situation where I have changed a file, > rerun the file in python but python still produces an error, quoting > the original file in the error string you're looking for the "reload" command 1. for the first usage type: import mymod 2. usage after modifications on mymod, type: reload(mymod) chris -- Chris From geiseri at yahoo.com Thu Oct 25 14:23:09 2001 From: geiseri at yahoo.com (ian reinhart geiser) Date: Thu, 25 Oct 2001 14:23:09 -0400 Subject: Createing PyObjects from modules Message-ID: <200110251822.OAA17956@generic2.axs2000.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Greetings, I have a little confusion about python objects. I am trying to share an object between C++ and my embedded python script. To do this I have found little to no help from the Python docs or on the web as how to mirror a complex object between the two. I have found that siplib the library that makes SIP work has the ability to map C++ objects to python and vis versa. ++++Reference Notes++++ sipMapCppToSelf Name sipMapCppToSelf?--?Convert a C/C++ pointer to a Python instance PyObject * sipMapCppToSelf(const void * cppPtr, PyObject * pyClass); Description If the C/C++ pointer is recognized and it is an instance of a sub-class of the expected class then the previously wrapped instance is returned. Otherwise a new Python instance is created with the expected class. The instance comes with a reference. Return Value A pointer to the Python object instance (or Py_None if a NULL pointer was passed in). cppPtr - A pointer to the C++ object. pyClass - The expected Python class. ++++END++++ - From what I can tell in the code this pyClass is the class created by my module that is being called from the embedded script. My question is how do a make a PyObject out of it? In python i do this: from foo import * bar = foo() I tried this in C++ but it seems not to work: PyObject *object = PyModule_New("foo"); Am I mis understanding the documentation here? Thanks - -ian reinhart geiser - -- ======================================== May all your PUSHes be POPped. ======================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE72FiNPy62TRm8dvgRAtkUAKDRI2Y+UoBupROhi6lfkLJ3dUsMKwCdES0d CfKC0vgu63VIrMlTsHU3kuU= =boXL -----END PGP SIGNATURE----- From kseehof at neuralintegrator.com Sat Oct 13 17:22:36 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Sat, 13 Oct 2001 14:22:36 -0700 Subject: Semantic indentation (OpenGL) References: Message-ID: <003401c1542d$2f808d60$25cdbfa8@kens> Marek Kro??k wrote: > I am very very sorry for opening such a topic again. Before anything else > I must say that I *love* Python's way of treating indentation. > When I was at school we were doing a lot of OpenGL (in VC++). I have often > (not always but many times) used following way of indentation for making > my code a bit cleaner: Well, this is a toung-in-cheek suggestion (hey, does anyone know the official emoticon for toung-in-cheek?), but why not: ;-& glBegin(GL_POINTS); if 1: ... glVertex3f(...); ... glEnd(); - Ken From ralph at inputplus.demon.co.uk Wed Oct 10 05:06:12 2001 From: ralph at inputplus.demon.co.uk (Ralph Corderoy) Date: 10 Oct 2001 10:06:12 +0100 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> <3BC27AA9.B1729BCA@engcorp.com> Message-ID: <9q1324$3ab$1@inputplus.demon.co.uk> Hi, > > s = ("%(foo)s %%(spam)s" % d1) % d2 > > > > use two "%" for variables that are in the second dict. > > Neat. Note of course that this requires everything which has only a > single % to be in the first dictionary, and everything with %% to be > in the second. Might be what was wanted... or maybe the OP won't > like that either... Doesn't that cause problems if the substitution for %(foo)s contains a percent sign? Ralph. From owen at astrono.junkwashington.emu Wed Oct 31 12:39:40 2001 From: owen at astrono.junkwashington.emu (Russell E. Owen) Date: Wed, 31 Oct 2001 09:39:40 -0800 Subject: Why 'self' ? References: <3BE04E7A.8E2CF101@ces.clemson.edu> Message-ID: <9rpd0t$1ba2$1@nntp6.u.washington.edu> In article <3BE04E7A.8E2CF101 at ces.clemson.edu>, "Schaefer, F." wrote: >It's been a while that I am working with Python and actually >the only thing I really do not like about it is 'self' in the >member function definitions as argument. If it >has to be there anyway, it is totally redundant to write it. > >So, why is self there ? I believe it was basically to make implementation of the language easier. I certainly agree it's a problem. I find forgetting to include the "self" argument to be one of the more significant sources of error in my own coding. Aside from that, I find it confusing that the caller and callee argument list are different. There are a number of other weaknesses in the object model. Still...with all their possible warts, Python classes are very useful, the introspection mechanism is handy and the language overall is great -- powerful and fairly simple. One interesting question is whether Guido sees "self" as a problem. If he does, he might be tempted to fix it in some future incompatible version (anybody know if version 3 is going to be the fabled incompatible Python 3000?). -- Russell From Dick.Zantow at lexisnexis.com Fri Oct 26 13:02:49 2001 From: Dick.Zantow at lexisnexis.com (-RZ) Date: Fri, 26 Oct 2001 13:02:49 -0400 Subject: Confusion with string.replace() References: Message-ID: <9rc52g$1jj$1@mailgate2.lexis-nexis.com> "Joseph Wilhelm" wrote in message news:mailman.1004110827.23550.python-list at python.org... > I'm getting some really strange behaviour from string.replace(), and I was > wondering if somebody could help explain this to me. All I'm trying to do is > escape single quotes in a string for a SQL query, but here's an example of > what I'm getting: > > >>> import string > >>> a = "a'b" > >>> b = string.replace( a, "'", "\'" ) > >>> b > "a'b" > >>> b = string.replace( a, "'", "\\'" ) > >>> b > "a\\'b" > >>> > > I just can't seem to wrap my brain around why it's doing that. Can somebody > explain that, or perhaps provide an easier option for preparing a SQL > statement? > > --Joseph Wilhelm Things are not always what they appear >>> a = "a'b" >>> b = string.replace( a, "'", "\\'" ) >>> b "a\\'b" >>> print b a\'b >>> print len(b) 4 From root at rainerdeyke.com Mon Oct 29 12:26:16 2001 From: root at rainerdeyke.com (Rainer Deyke) Date: Mon, 29 Oct 2001 17:26:16 GMT Subject: Python 2.2b1 hashable dictionary bug? References: Message-ID: "Tim Peters" wrote in message news:mailman.1004342908.6096.python-list at python.org... > [Rainer Deyke] > > What about this: > > > > class dictionary_with_identity_compare(dictionary): > > __eq__ = object.__eq__ > > __ne__ = object.__ne__ > > __lt__ = object.__lt__ > > __gt__ = object.__gt__ > > __le__ = object.__le__ > > __ge__ = object.__ge__ > > __hash__ = object.__hash__ > > > > d = {dictionary_with_identity_compare() : None} > > It should suffice to override just __eq__ and __hash__. However, you can't > override __eq__ via object.__eq__: That's surprising (and therefore probably a bad thing). My first expectation was for something like this: class object: def __eq__(self, other): return id(self) == id(other) The problem with that is that it breaks '__cmp__'. My second expectation was for something like this: class object: def __cmp__(self, other): return cmp(id(self), id(other)) def __eq__(self, other): return self.__cmp__(other) == 0 I see no reason why this has not been included. -- Rainer Deyke (root at rainerdeyke.com) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor From boyd at insultant.net Mon Oct 1 06:02:16 2001 From: boyd at insultant.net (Boyd Roberts) Date: Mon, 1 Oct 2001 12:02:16 +0200 Subject: How do Java interfaces translate to Python? References: Message-ID: <9p9f4s$o7q$1@neon.noos.net> "Martin von Loewis" a ?crit dans le message news: j44rpk2unm.fsf at informatik.hu-berlin.de... > What exactly is it that you do with interfaces in Java? code yourself into a corner? From richard at bizarsoftware.com.au Tue Oct 9 19:27:12 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Wed, 10 Oct 2001 09:27:12 +1000 Subject: ARGV and import ? In-Reply-To: <20011009192330.A3209@lilith.hqd-internal> References: <660c52de.0110090907.4017f907@posting.google.com> <20011009192330.A3209@lilith.hqd-internal> Message-ID: <0110100927120Q.11044@ike> On Wednesday 10 October 2001 03:23, Gerhard H?ring wrote: > On Tue, Oct 09, 2001 at 10:07:38AM -0700, J wrote: > > Hi all, > > > > This is my first post to this group & I am also fairly new to python, > > so please forgive me if this isn't the brightest question or the > > appropriate venue. > > > > I would like to do the following: > > import a module based on what is typed on the command line. > > > > I thought this would work: > > import sys > > recipes = sys.argv[1] > > import recipes > > > > But, I get this error: > > >> ImportError: No module named recipes > > > > Is there any way to pass the module name to import through an argv? > > I think this is one of the rare cases where an exec statement is > appropriate: > > statement = "import %s as mod" % sys.argv[1] > exec statement Nooo. In a language as truly introspective as Python, exec is rarely needed. As Steve Holden pointed out, the __import__ builtin function is the way to go. Richard From belen at netcom.no Mon Oct 22 07:22:16 2001 From: belen at netcom.no (belen at netcom.no) Date: Mon, 22 Oct 2001 12:22:16 +0100 Subject: Service not stopping Message-ID: <133d91138ecb.138ecb133d91@netcom.no> Yeah, The problem is that my program never gets to the while loop. Is there a way of regaining control of the service process...Can I create then two simultanous processes an control bot of them? Might the problem have been the way I have created the scheduler process? self.Start_Scheduler() import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_,'')) while 1: rc=win32event.WaitForMultipleObjects ((self.hWaitStop,self.hSched),0,win32event.INFINITE) Thanks again Belen From sheila at spamcop.net Wed Oct 24 20:17:48 2001 From: sheila at spamcop.net (Sheila King) Date: Thu, 25 Oct 2001 00:17:48 GMT Subject: smtp References: Message-ID: <9r6t3n.3vvbepd.1@kserver.org> AOL intercepts all Port 25 traffic. Therefore, you cannot send outbound mail to a non-AOL smtp server via an AOL Internet connection. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Wed, 24 Oct 2001 16:01:06 -0700, Cliff Wells wrote in comp.lang.python in article : :However - I tried it on someone :else's Windows PC who uses AOL (blech) and it failed with SMTPSenderRefused. : :The problem is easily reproduced using the code from the smtplib module but :substituting "mail.earthlink.net" (my ISP) in place of "localhost" and my :email address for the toaddrs: : : :import smtplib :import string : :def prompt(prompt): : return raw_input(prompt).strip() : :fromaddr = prompt("From: ") :# toaddrs = prompt("To: ").split() :toaddrs = ["logiplexsoftware at earthlink.net"] :print "Enter message, end with ^D:" : :# Add the From: and To: headers at the start! :msg = ("From: %s\r\nTo: %s\r\n\r\n" : % (fromaddr, string.join(toaddrs, ", "))) :while 1: : try: : line = raw_input() : except EOFError: : break : if not line: : break : msg = msg + line : :print "Message length is " + `len(msg)` : :server = smtplib.SMTP('mail.earthlink.net') :server.set_debuglevel(1) :server.sendmail(fromaddr, toaddrs, msg) :server.quit() : :It seems it should be legal to send directly to that server, since that's the :final destination anyway. Am I wrong, or is just AOL? I don't have access :to enough separate ISP's to test this very well. From tjreedy at home.com Mon Oct 22 19:07:47 2001 From: tjreedy at home.com (Terry Reedy) Date: Mon, 22 Oct 2001 23:07:47 GMT Subject: programming unlimited "categories" in python ? References: <97ae44ee.0110221318.6eec382d@posting.google.com> Message-ID: <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> "Stephen" wrote in message news:97ae44ee.0110221318.6eec382d at posting.google.com... > Scratching my head over what I thought was a simple problem. > > I'm developing a catalog application (storing its data in a > relational database), where catalog entries are categorized > by one or more categories/subcategories. It would be nice to > have "unlimited" levels of subcategories and that seemed > simple enough ~ "Use a parent/child" I hear you say ~ and that's > what I did but I've since found it's not very flexible further > down the line. This is a database rather than Python question, but since you asked, I'll answer from my database experience. > Let me demonstrate with some example categories/subcategories > which we place in a category tree, giving each node a unique ID. > The root node is deemed to have node ID zero (0). > > Root -- 1. ByLocation --- 3. Africa --- 4. Mozambique > --- 6. SouthAfrica > --- 5. Europe --- 9. Portugal > -- 2. BySeverity --- 7. Critical --- 8. Death > --- 11. Handicap > --- 10. Moderate--- Location and Severity are two separate variables that should be coded completely separately from each other. Severity, if not numeric, is usually an ordered series of categories, such as 1=mild, 2=moderate, 3=handicap, 4=critical, 5=death. Coding three-level LOcation is more complicated. Either 1. Split it into three variables - continent, country, city, with continent required and country and city optional -or- 2. Encoded the levels into 'one' entry (which you split into pieces as needed). You could try a separater-ed entry such as continent-country-city (like internet address, windows registry, etc) or positional-subfield encoded (like many product ids and library book categorizers (as in either Dewey Decimal or Library of Congress systems)). For instance, 0 = Africa, 10 = Mozanbique, 11=(capital city), 20= Angola, 1000 = Europe, etc. In otherwords, 1000s = continent, hundreds/tens = country, ones position = city. > This structure can be stored in a single table of a database. > > Parent_ID Category_ID Category_Label > 0 1 ByLocation > 0 2 BySeverity > 1 3 Africa > 3 4 Mozambique > 1 5 Europe > 3 6 SouthAfrica > 2 7 Critical > 7 8 Death > 5 9 Portugal > etc Mixing two varriables like this is a mistake. > So far so good. Cataloged items/illnesses record their > categories in a one-to-many table. For example, an illness > with categories "4" and "8" occurs in Mozambique and can > result in death. > > This appears scalable. > > Likewise you can easily select all illnesses occuring in > Portugal using a JOIN and filtering category ID "9". > > So what's the problem ? > > The problem arises if one asks "Which illnesses occur > in Africa ?". First, one has to find all category IDs > for which this is true. This may be easy for the example > above but imagine if the category ("Africa") has a sub- > -category for each and every country then further > subcategorized by major cities. To find all possible > categories, one would have to do a recursive select > finding each subscategory with the appropriate "parent ID". > This does not seem like a very efficient method. If location were coded with continent either a separate variable/field or separate subfield, this query would be trivial, as it should be. Terry J. Reedy From richard at bizarsoftware.com.au Wed Oct 10 20:39:54 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Thu, 11 Oct 2001 10:39:54 +1000 Subject: Python questions -> compiler and datatypes etc In-Reply-To: <7xr8sbc993.fsf@ruckus.brouhaha.com> References: <20011010100130.30712.qmail@web11208.mail.yahoo.com> <7xr8sbc993.fsf@ruckus.brouhaha.com> Message-ID: <01101110395417.11044@ike> On Thursday 11 October 2001 10:26, Paul Rubin wrote: > Richard Jones writes: > > Do a search in the python mailing list for "python compiler". The > > answer is invariably "it's bloody hard". This stems from the > > fundamental dynamic typing of python. It's very very very hard to > > write a compiler when you don't know the type of the objects you're > > dealing with beforehand. Java knows these types, because it's > > statically typed. Therefore it's relatively trivial (compared to > > python) to write a compiler for Java. > > I think the real answer to why there's no Python compiler is no one > has really wanted to write one. That's not true - as I have mentioned in my last post, there have been efforts and as far as I recall there is an ongoing effort right now. I just can't find the reference at the moment. > Python's runtime semantics are pretty > similar to Lisp systems, and native-code Lisp compilers have existed > since the 1960's or maybe even earlier. It might even be feasible > to adapt one to compile Python. I believe I've seen a similar proposal along those lines in the past too. I don't believe it's a case of people not wanting to do it - it's would just required huge resources. The kind of resources only a commercially funded operation could provide at the moment. And I guess that at the moment, no-one can make a business case for it. Richard From rxg218 at psu.edu Tue Oct 30 11:01:09 2001 From: rxg218 at psu.edu (Rajarshi Guha) Date: Tue, 30 Oct 2001 11:01:09 -0500 Subject: redirecting sdtout/sdterr in a daemon Message-ID: <9rmiqc$23hq@r02n01.cac.psu.edu> Hi, I'm using the daemonize.py module to make my code run as a daemon. However the module contains the lines: sys.stdout = NullDevice() sys.stderr = NullDevice() Instead of this behaviour I would like it to write output to a file. So I write: sys.stderr = open(outputhandle,'w') sys.stdout = open(outputhandle,'w') Where outputhandl is a passed to the function. However no output comes to the this file. In addition when i try and print anything from the function, nothing is output. How can I fix this problem. Below is the code for daemonize.py: ---------------------------------------------------------------------- def become_daemon(ourHomeDir='.'): """Robustly turn us into a UNIX daemon, running in ourHomeDir. XXX on SVR4 some claim you should re-fork after the setsid() jjk 06/25/97 001 """ import os import sys if os.fork() != 0: # launch child and... os._exit(0) # kill off parent os.setsid() os.chdir(ourHomeDir) os.umask(0) sys.stdin.close() #sys.stdout.close() #sys.stderr.close() sys.stdout = NullDevice() sys.stderr = NullDevice() for z in range(3, 256): try: os.close(z) except: pass class NullDevice: """A substitute for stdout and stderr that writes to nowhere jjk 06/25/97 001 """ def write(self, s): """accept a write command, but do nothing jjk 06/25/97 001 """ pass -- ------------------------------------------------------------------- Rajarshi Guha | email: rajarshi at presidency.com 152 Davey Laboratory | web : www.rajarshi.outputto.com Department of Chemistry | ICQ : 123242928 Pennsylvania State University | AIM : LoverOfPanda ------------------------------------------------------------------- GPG Fingerprint: DCCB 4D1A 5A8B 2F5A B5F6 1F9E CDC4 5574 9017 AF2A Public Key : http://pgp.mit.edu/ ------------------------------------------------------------------- COBOL is for morons. -- E.W. Dijkstra From mlh at idi.ntnu.no Sun Oct 21 14:34:20 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 21 Oct 2001 20:34:20 +0200 Subject: Dictionary from list? References: <6KVz7.132664$vq.30203786@typhoon.ne.mediaone.net> Message-ID: <9qv4fd$gpb$1@tyfon.itea.ntnu.no> "Martin von Loewis" wrote in message news:j4d73hjhma.fsf at informatik.hu-berlin.de... > Jim Correia writes: [snip] > Note that the list->dictionary conversion is not as obvious as you > think. Given > > [(1,2),(3,4)] > > would you like to get > > a) {1:2, 3:4} > > or > > b) {(1,2) : (3,4)} > > Your answer is probably b), but many Python people would rather expect > a) (since it would be the reverse of the .items() operation). Why would one want b?! (I must have missed some posts here...) - Magnus, who thinks a is the obvious choice. > Regards, > Martin -- Magnus Lie Hetland http://hetland.org From mlh at idi.ntnu.no Tue Oct 2 18:40:22 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 3 Oct 2001 00:40:22 +0200 Subject: Python is better than free (was Re: GNU wars again) References: <1002028115.395.70447.l7@yahoogroups.com> <5.1.0.14.2.20011002085745.02b8ee00@cedar.he.net> Message-ID: <9pdfon$c93$1@tyfon.itea.ntnu.no> "Oleg Broytmann" wrote in message news:mailman.1002053344.12235.python-list at python.org... > On Tue, Oct 02, 2001 at 01:01:11PM -0700, Samuel Schulenburg wrote: > > Sometimes you have code that you want to release with a commercial > > product, that contains propriatary information about the internals in > > your product. A GPL license would keep you from releasing this code > > using Python. > > This is easily solvable: buy specially licensed version. GNU GPL allows > it. But do not take my code for nothing, please. That is a valid point, and I won't say that one "should" use GPL or something else... But for the user of the licensed code (as opposed to the programmer) getting something for free would seem "better" than paying for it, wouldn't it? Now, whether one can afford to give away one's code for free is, of course, an individual thing. > Oleg. -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From sholden at holdenweb.com Mon Oct 29 04:59:18 2001 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 29 Oct 2001 04:59:18 -0500 Subject: python binary search References: Message-ID: "Tim Peters" wrote in message news:mailman.1004331032.3471.python-list at python.org... > [Jeff Dunnett] > >>> Duh. What an idoit I am. Poor spelling you can tell I am > >>> not an English major or I probably would have picked up on > >>> the ocmment. > > [Jeff Dunnett again, beating himself to the jab] > >> That should say comment. > > [Timothy Delaney, can't resist] > > I should resist, but I can't. > > > > So, what is this "it" that you do? (idoit). > > I expect Jeff is a philosophy major, since few others know that an "ocmment" > is a cutting comment about Ocmma's Razor. > > on-the-other-hand-"idoit"-suggest-a-physics-background-ly y'rs - tim > Tim: Was Ocmma's Razor the separator used for OSVs (Ocmma Separated Files)? I have several that I need to read: do you have any code that will help me? throwing-stones-from-inside-my-glass-house-ly y'rs - steve -- http://www.holdenweb.com/ From stephen.boulet at motorola.com Tue Oct 9 15:46:57 2001 From: stephen.boulet at motorola.com (Stephen Boulet) Date: Tue, 09 Oct 2001 14:46:57 -0500 Subject: Generating a random number References: <9plkkk$98r$1@ins22.netins.net> Message-ID: <3BC35431.158D9B8D@motorola.com> from random import * print randrange(1,11) * Notice that you have to put in an 11 to get from 1 to 10 -- Stephen Ron White wrote: > > Will someone please tell me exactly how to generate a random number from 1 > to 10 in Python 2.1.1 running under windows me? I'm beginning to think > there is something wrong with my installation or I'm just not smart enough > to understand what I read. > > Thank you for any help. > Ron > > -- > Ron White > Amateur Radio WA0MWW From ransen_spam_me_not at nemo.it Thu Oct 4 01:50:03 2001 From: ransen_spam_me_not at nemo.it (Owen F. Ransen) Date: Thu, 04 Oct 2001 05:50:03 GMT Subject: test - don't read... References: <3bb9e35a.695404@news.newsguy.com> Message-ID: <3bbbe47b.623163@news.newsguy.com> On Wed, 03 Oct 2001 22:36:06 -0000, Robert Amesz wrote: >Owen F. Ransen wrote: > >> don't read > > >don't write don't respond -- Owen F. Ransen http://www.ransen.com/ Home of Gliftic & Repligator Image Generators From chr_w at gmx.de Thu Oct 11 04:28:12 2001 From: chr_w at gmx.de (chr_w at gmx.de) Date: Thu, 11 Oct 2001 10:28:12 +0200 (MEST) Subject: get uniform binary data into array for further processing Message-ID: <11245.1002788892@www29.gmx.net> Hi list :-) I just started coding with python recently and ran into my first major problem. Ok, here's the story: I have to import pretty massive binary files containing double-precision real values (climate data) so I can do some operations to it (mainly simplyfying, getting the daily some etc.). The file can get really ugly in size... up to a gig eventually... But my main concern: a) what's the best and fasted way to get this data into a 2-dimensional array (or list?)? b) which modul to use (Numeric, array, struct, pickle) ??? c) I have some fortran code which handles this quite good - is there a similar way to do it in python? I managed to import a test file of some megs but it took ages and i'm not sure i did it right, since most values appeared to be 0.0 's... which might be ok?...?!? -- -------------------------- christian werner GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net From tdelaney at avaya.com Tue Oct 30 18:51:35 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 31 Oct 2001 10:51:35 +1100 Subject: file operations Message-ID: > From: Eyal Lotem [mailto:eyal at hyperroll.com] > Kerstin wrote: > > > begin loop > > - read file > > - replace something in the file (seem to work) > > - write file > > end loop > > > > This has to be done quite often. > > A nice approach to this (if the files are not too large), is > to replace the > loop with something like: > > open('filteredfile.output', 'w').writelines( > map(lambda line: line.rstrip() + '\n', > open('inputfile', 'r').readlines())) That's an evil thing to do to someone asking you to do their homework ... :) Also, it's not a good thing to do in general, as not all implementations of Python immediately call the finalizer of objects with a refcount of zero (e.g. Jython). Tim Delaney From emile at fenx.com Sat Oct 13 10:51:52 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 13 Oct 2001 07:51:52 -0700 Subject: Int to long conversion bug? Message-ID: <9q9kns$mr511$1@ID-11957.news.dfncis.de> In view of the int to long automatic conversion, should this be considered a bug? F:\Python22>python Python 2.2a4 (#24, Sep 27 2001, 21:44:09) [MSC 32 bit (Intel)] on win32 >>> n = int('9999999999') Traceback (most recent call last): File "", line 1, in ? ValueError: int() literal too large: 9999999999 >>> I can use long() of course, but is it the intent that long become an implementation detail? -- Emile van Sebille emile at fenx.com --------- From BPettersen at NAREX.com Thu Oct 25 17:43:20 2001 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Thu, 25 Oct 2001 15:43:20 -0600 Subject: Question: Dynamic code import Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158C02@admin56.narex.com> > From: K?roly Ladv?nszky [mailto:aa at bb.cc] > > Hi Bjorn, > > Thanks for your quick answer. Yes, I was mistaken with the > global directive. It's clear now. Regarding the first > question, it works fine with the interpreter but I would like to read > f11(a) from somewhere else, most likely from a file. Hmmm... Not quite sure what you mean. Is it in a Python file, a text file, ?? If it's in a Python file you can just import the module and assign to the variable as before, if it's in a text file you'd need to use eval or exec. Let us know which it is and I'm sure we could come up with examples... :-) -- bjorn From dalke at dalkescientific.com Wed Oct 24 00:46:56 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 23 Oct 2001 22:46:56 -0600 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> Message-ID: <9r5h75$1m5$1@slb6.atl.mindspring.net> Huaiyu Zhu wrote: > there was recently a thread about prime >algorithms. I found that the clearest pseudocode would look like > > def getprimes(x): > primes = [] > for n in range(2, x): > for p in primes while p*p <= n: > if n % p == 0: break > else: primes.append(n) > return primes > >I have not been able to translate this into Python without using duplicate >code or temporary variables - not sure about iterators as I haven't tried >2.2 yet. You may want to write more code in existing Python before proposing new syntax forms -- how many variations do you want? :) # I know, for some reason you don't like putting the end condition # inside the loop. But it's one I've brought up before and it's # a simple mechanical transformation from what you want to do. # And only one extra line (assuming your proposed code is written in # a more readable form.) def getprimes(x): primes = [] for n in range(2, x): for p in primes: if p*p > n: primes.append(n) break elif n % p == 0: break return primes # Here's one that's the same number of lines, although it # makes a copy of the list while yours doesn't. It's # 13 extra characters. def getprimes(x): primes = [] for n in range(2, x): for p in filter(lambda p: p*p<= n, primes): if n % p == 0: break else: primes.append(n) return primes # This may be slower, since 2/3 of the tests are # removable in the first two tests, while this makes # a copy of the primes. On the other hand, it doesn't # do the "p*p" test all the time. But if you're worried # about speed you wouldn't use this algorithm. def getprimes(x): primes = [] for n in range(2, x): pos = bisect.bisect(primes, math.sqrt(x)) for p in primes[:pos]: if n % p == 0: break else: primes.append(n) return primes # This starts returning answers quickly, instead of waiting # for all the primes to be computed. It also knows that 2 # is a prime so it skips all even numbers. def getprimes(x): if x > 2: yield 2 if x > 3: yield 3 odd_primes = [3] for n in xrange(5, x, 2): for p in odd_primes: if p*p > n: odd_primes.append(n) yield n break elif n % p == 0: break and can be used like >>> for x in getprimes(sys.maxint): ... if x % 10 == 7: ... print x, "(ends in a 7!)" ... else: ... print x ... if x > 30: ... break ... 2 3 5 7 (ends in a 7!) 11 13 17 (ends in a 7!) 19 23 29 31 >>> >This would also be handy for list comprehensions. In analogy to > > >>> a = range(10) > >>> [x for x in a if (x-5)**2 > 4] > [0, 1, 2, 8, 9] > >we could have > > >>> a = range(10) > >>> [x for x in a while (x-5)**2 > 4] > [0, 1, 2] Is that useful? Not often enough I warrant. BTW, you can do def while_true(f, data): gen = iter(data) while 1: x = gen.next() if f(x): yield x else: break >>> a = range(10) >>> for x in while_true(lambda x: (x-5)**2 > 4), a): ... print x ... 0 1 2 >>> Or even without generators but with filter (so works with any Python in the last decade.) class while_true: def __init__(self, f): self.f = f self.flg = 1 def __call__(self, x): if self.flg == 0: return 0 if self.f(x): return 1 self.flg = 0 return 0 >>> a = range(10) >>> filter(while_true(lambda x: (x-5)**2 > 4), a) [0, 1, 2] >>> I'm betting it's more likely that Python will grow a new module with various predicates or iterable functions than add new styles of syntax. Then you could do things like from generator_functions import lazy_filter, every_other for x in lazy_filter(lamba x: x%10==7, every_other(get_primes(100))): print x and get the sequence starting 7, 47, 67, 97, 127, ... I know I would like such a module - but not enough to write it. >Thinking about this - perhaps the real problem is multiple exits for loops - >at least one normal end to loop and another abnormal end. And I still insist there is no problem. You've yet to really come up with an example of how your proposal would clarify any real code, and you have yet to show that the addition of a new construct won't make Python more confusing. Shortness does not equal readable. Andrew dalke at dalkescientific.com P.S. Who said "TMTOWTDI"? :) From oktay_safak at yahoo.com Fri Oct 5 04:11:17 2001 From: oktay_safak at yahoo.com (Oktay Safak) Date: Fri, 5 Oct 2001 11:11:17 +0300 Subject: font display problem in IDLE References: <20011003174548.85437.qmail@web20706.mail.yahoo.com> <20011003230437.B1011@xyz.donetsk.ua> Message-ID: <000501c14db2$2f9cb0c0$13ff2bd5@b> Thank you very much Kirill, your suggestion solved my problem perfectly. At first IDLE gave some "ASCII error" messages, but then I remembered that I had deleted the sitecustomize.py file while trying to solve the problem. I restored it, and everything is working perfectly now. But I wonder how you managed to find that solution, which I think is far from being a trivial one. Perhaps you should consider writing a How-To about this subject. This must be biting lots of people. And, do you think that this is a bug of IDLE or is there a reason why this is the default behaviour? Gratefully yours, Oktay Safak ********************************************************** For the sake of completeness, and for those who have had the same problem: __________________________________________________________ Create a new text file in the folder where your Python executable resides, name it sitecustomize.py and put these lines in it: import sys sys.setdefaultencoding("ISO 8859-9") close and save the file. The ISO encoding no given above is for Turkish. Of the encodings given below, use the appropriate one for your language: (taken from www.unicode.org) 8859-1 (Latin-1) 8859-2, -3, -4, -9 (European Latin) 8859-5 (Cyrillic) 8859-6 (Arabic) 8859-7 (Greek) 8859-8 (Hebrew) and then follow Kirill's instructions given below. After everything is done, run IDLE and enjoy it. ----- Original Message ----- From: "Kirill Simonov" To: Sent: Wednesday, October 03, 2001 11:04 PM Subject: Re: font display problem in IDLE > On Wed, Oct 03, 2001 at 10:45:48AM -0700, Oktay Safak wrote: > > > > I use sitecustomize.py to use turkish encoding, the > > console gets it right but on IDLE, the characters > > special to my language are not displayed properly, > > some other funny characters are shown instead. When I > > write some text to a file and inspect the file with > > notepad I see that the characters are OK. So IDLE does > > what I want but does not show it properly. I tried to > > configure IDLE by changing the font it uses for > > display from its config file but somehow a sans-serif > > font shows up instead of courier new, and it still > > shows the wrong encoding. Any ideas? German and French > > fellows might have had a similar problem I guess. > > > > I expect that you use Python 2.1 on Windows. > > The recipe is: > > Step 1: > Open file "Python21/Lib/lib-tk/FixTk.py", remove all lines and write the > following code: > > import sys, os > if not os.environ.has_key('TCL_LIBRARY'): > tcl_library = os.path.join(sys.prefix, "tcl", "tclX.Y") > os.environ['TCL_LIBRARY'] = tcl_library > > Step 2: > Open file "Python21/Tools/idle/Percolator.py", go to the line 23. > You need to insert two lines of code into the function "insert": > > def insert(self, index, chars, tags=None): > # Could go away if inheriting from Delegator > if index != 'insert': # You need to add > chars = unicode(chars) # these lines. > self.top.insert(index, chars, tags) > > Step 3: > Open file "Python21/Tools/idle/PyShell.py", go to the line 470. > You need to add two lines: > > line = self.text.get("iomark", "end-1c") > if type(line) == type(u""): # You need to add > line = line.encode() # these lines. > self.resetoutput() > > And please tell me, does this recipe solves your problem? > > > \Xi > > > -- > http://mail.python.org/mailman/listinfo/python-list > From hamish_lawson at yahoo.co.uk Tue Oct 16 13:44:08 2001 From: hamish_lawson at yahoo.co.uk (=?iso-8859-1?q?Hamish=20Lawson?=) Date: Tue, 16 Oct 2001 18:44:08 +0100 (BST) Subject: FW: [Python-Dev] What happened to Guido's plans for (S1; S2; ...; Sn; E) ? Message-ID: <20011016174408.63377.qmail@web11001.mail.yahoo.com> The current discussion on conditional expressions has at times touched on the ever-recurring issue of assignment in expressions. It reminded me that a proposal by Kevin Digweed back in early 1999 had actually managed to obtain Guido's approval as a reasonably Pythonic approach to allowing assignment in expressions, and the proposal seemed intended to make its eventual way into Python. Is this still the case? Kevin's original proposal: | What about allowing an optional "assignment only" suite | between "while" and the test condition. This suite will be executed | before testing the condition each time | Guido then expanded on the proposal and seemed to give it his approval: | Why stop there? It could easily be any number of "small" statements | separated by semicolons with the restriction that the final one must | be an expression and that the ones before it must not be flow-control | statements (return, raise, continue, break). Other useful statements | to allow are print (for debugging) and assert, and for all I care | import, del, pass, and exec. | | Note that I like this for 2.0, not so much for for 1.6 (if only | because I don't want 1.6 to make existing books obsolete). | Guido also clarified its intended syntax and semantics: | In my interpretation, the expression (S1; S2; ...; Sn; E) yields the | value of expression E -- S1-Sn are only there for their side effects. | Hamish Lawson ____________________________________________________________ Do You Yahoo!? Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk or your free @yahoo.ie address at http://mail.yahoo.ie From petr at kubanek.net Thu Oct 25 15:49:44 2001 From: petr at kubanek.net (Petr Kubanek) Date: Thu, 25 Oct 2001 21:49:44 +0200 Subject: Question: Dynamic code import References: <3bd86540_2@corp-goliath.newsgroups.com> Message-ID: <9r9q9l$u5i$06$1@news.t-online.com> > For instance, the running program refers to function f1 through ff: > > def f1(a): > return a*1.25 > > ff=f1 > > At some point, it turns out that f1(a) should return a*1.3+5. If it was > possible to insert a > new function, the running program could be modified like this: > > #--- this is to be 'imported' > def f11(a): > return a*1.3+5 > #--- > > ff=f11 > > Now ff(a) would produce results by using the new rule embodied in f11! Yes, it does. So where is problem? > 2. Something is wrong with globals. Given the example below, I'd expect 2 > for the second print. > > global gx > gx=1 > > def set_gx(gx_new): > gx=gx_new gx is local variable (at that point). Python works so. To work as expected, you should add global: def set_gx(gx_new): global gx gx=gx_new > > #--- This one works, test() prints the global gx. > global gx > gx=1 > > def test(): > print gx # prints 1 > > b. > #--- This one runs to error -> 'UnboundLocalError: local variable 'gx' > referenced before assignment' !!! > global gx > gx=1 > > def test(): > print gx > gx=2 Ansewer is in error. Same problem: def test(): global gx print gx gx=2 > > c. > #--- This one works but treats gx as local. Try test() first, then test1() > will print the original 1 for the global gx! > global gx > gx=1 > > def test(): > gx=2 > print gx # prints 2 > > def test1(): > print gx # prints 1! Again, it's in syntax. Insert global gx before first statement in def. Using global in Python is quite strange and you should try to avoid it, or remeber to use global every time. Other possible way is throught __main__ module, which worked like: import __main__ __main__.gx=1 def test: print __main__.gx Even when __main__ gets reimported in second module, it's contents remains. Petr Kubanek From BgPorter at NOartlogicSPAM.com Mon Oct 29 09:29:35 2001 From: BgPorter at NOartlogicSPAM.com (Brett g Porter) Date: Mon, 29 Oct 2001 14:29:35 GMT Subject: setting the clipboard References: <3bdd553c$1@207.229.64.20> Message-ID: "Peter Bismuti" wrote in message news:3bdd553c$1 at 207.229.64.20... > How can you set the clipboard from within Python? I was told that it can be > done. > > Thanks! You don't specify, but I assume that you're running Windows of some flavor. First, if you haven't already gotten the Win32 extensions, do so. Then, look at the module win32clipboard, which contains everything you need. It may also be useful to look at the Platform SDK's section on the clipboard if you're not already familiar with how it works (clipboard formats, etc.) From joonas at olen.to Sat Oct 27 16:54:39 2001 From: joonas at olen.to (Joonas Paalasmaa) Date: 27 Oct 2001 13:54:39 -0700 Subject: os.system() and cgi References: Message-ID: <11aed8f9.0110271254.4a8b36c1@posting.google.com> iamcanadian89 at yahoo.com (M. Ibaraki) wrote in message news:... > This script (test.py) works fine and creates a file 'outputfile' when > I run this in test mode (python test.py). > > > --- test.py ---- > #!/usr/bin/python > > import cgi, os > > print "Content-type: text/html\r\n" > print "" > print "" > > ret = os.system('/usr/X11R6/bin/xmgrace -help > outputfile') > # ret = os.system('/bin/ls > outputfile') > > print "

ret = ", ret > ---------------- > > > > It shows: > > Content-type: text/html > > > >

ret = 0 > > > > However, when this is executed as a cgi it shows: > > ret = 256 > > and no 'outputfile' file is created. > > > > Permission of /usr/X11R6/bin/xmgrace is: > -rwxr-xr-x 1 root root 450 May 20 18:48 > /usr/X11R6/bin/xmgrace > > xmgrace is a 2D plotting tool > (http://plasma-gate.weizmann.ac.il/Grace/) > > > > I also tried '/bin/ls > outputfile' instead of '/usr/X11R6/bin/xmgrace > -help > outputfile'. This 'ls' command is executed and it creates > 'outputfile' in both cgi and test modes. > > > Permission of /bin/ls is: > -rwxr-xr-x 1 root root 48316 Sep 15 12:54 /bin/ls Perhaps /usr/X11R6/bin/xmgrace fails because user, that is running Apache can't open x-server. Or something like that. From pzw1 at cornell.edu Tue Oct 30 23:42:46 2001 From: pzw1 at cornell.edu (pzw1 at cornell.edu) Date: Tue, 30 Oct 2001 23:42:46 -0500 (EST) Subject: python development practices? In-Reply-To: <200110310114.f9V1Ew334485@bigboy.bizarsoftware.com.au> Message-ID: On Wed, 31 Oct 2001, Richard Jones wrote: > > and the lack of interfaces and strong types > > are the typical turn-offs, > > Nah, they're just Old School concerns :) Seriously, those mechanisms do help > catch stupid bugs, but reliance on those issues can sometimes reduce the > amount of time actually documenting the interfaces/components and testing > them. i think reliance on them is not a healthy thing, and in fact makes people too comfortable with not having a good development process. however, they are really really really nice for catching dumb things like typos or a forgotten integer->string cast somewhere deep inside a rarely-executed bit of the code. that's why i also asked about code coverage tools in the same breath. :-) > > while i feel that Python makes me far more productive as a programmer > > for all the projects on which i've worked, i'm inclined to agree that > > the lack of data hiding coupled with lack of a standard interface > > specification would cause problems in a team. > > You've just got to move the interface and component specifications up from > the code into documentation (where, IMO, it belongs.) and enforce component > compliance with unit tests. hmm.. this seems to be the uniform response to my questions, and it was what i had surmised before even posting. is there really no middle ground? are there no real development groups using python with high time-to-market pressures and imperfect process? i find it hard to believe that someone or some group hasn't evolved a way of dealing with this... i mean, i agree wholeheartedly with what you are saying, except that it's much like having a car which is completely crashproof and extremely fuel-efficient when tire pressure is maintained exactly, oil changed every 3,000 miles, and the dashboard is treated every 3 months with armor-all. but as soon as tire pressure dips 2 psi below spec, the engine explodes. and only when you drive down roads with a prime number of letters. > Programmers must be disciplined anyway, again IMO. This idea that programmers > can just write whatever they damn well like, with little regard for what > other people are diong (an idea propogated mostly by the "write it any damn > way you like" ideology of Perl) is extremely detrimental to a working team. oh, absolutely. disciplined progammers are a must in any circumstance if one is to even develop usable code. but no one's perfect, and python is so incredibly useful and powerful and elegant in so many cases that it's doubly grating on my sensibilities that the language isn't more of an ally in catching honest mistakes... > Well, there you have (some) of them, hope they help :) thanks for your responses. :) -peter From usenet at jeffjohnson.net Thu Oct 25 15:48:08 2001 From: usenet at jeffjohnson.net (Jeff Johnson) Date: 25 Oct 2001 12:48:08 -0700 Subject: urllib.urlopen + https = all threads locked? References: Message-ID: Here's a test script and output that demonstrates that opening a HTTPS url freezes other threads. Thanks for the help, -Jeff === OUTPUT === time between ticks = 0.00 time between ticks = 0.22 time between ticks = 0.51 Opening HTTPS://www.digitalegroup.com/ea/ThreadTest3. Finished. time between ticks = 3.69 time between ticks = 0.50 Opening HTTP://www.digitalegroup.com/ea/ThreadTest3. time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 time between ticks = 0.51 Finished. time between ticks = 0.51 time between ticks = 0.51 === SCRIPT === from threading import Thread import urllib, time def read(url): print "Opening %s." % url f = urllib.urlopen(url) print "Finished." def ticker(): t1 = time.time() while 1: t2 = time.time() print " time between ticks = %0.2f" % (t2 - t1) t1 = time.time() time.sleep(.5) t2 = Thread(target=ticker) t2.setDaemon(1) t2.start() time.sleep(1) read("HTTPS://www.digitalegroup.com/ea/ThreadTest3") time.sleep(1) read("HTTP://www.digitalegroup.com/ea/ThreadTest3") time.sleep(1) From logiplexsoftware at earthlink.net Fri Oct 12 15:59:27 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Fri, 12 Oct 2001 12:59:27 -0700 Subject: dictionary.update() enhancement? In-Reply-To: <3BC73EA4.D9994ED8@alcyone.com> References: <3BC73EA4.D9994ED8@alcyone.com> Message-ID: <01101212592702.07109@logiplex1.logiplex.net> On Friday 12 October 2001 12:04, Erik Max Francis wrote: > Mark J wrote: > > Because it's not as straight-forward as saying d.update(other, > > collision_handler) and it's about 10 times slower. > > Ten times slower? What in the world gives you that idea? Especially since d.update(other, collision_handler) doesn't exist and hence can't be benchmarked. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From tim.one at home.com Thu Oct 11 20:46:47 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 11 Oct 2001 20:46:47 -0400 Subject: Why not 3.__class__ ? In-Reply-To: Message-ID: [Tim, on __xxx__ names] > They're supposed to be ugly: if you find yourself using __xxx__ thingies > a lot, it's supposed to be a clue that you're not using the language as > intended. [James_Althoff at i2.com>] > Point taken. (In his defense, he reminds the jury that he *did* end his > remark with a "full wink"). Sure -- I didn't end mine with a skull and crossbones either . > BTW, I've just written a Jython-based debugger-type thingie that > provides a GUI in which you (our developers, that is) can visually > inspect all fields, methods, base classes, etc. for any object > ... > Moreover you (the developer, again) can change (using the GUI) any field > value on the fly (or add or delete same). And ... you can rewrite a > method on the fly (using the GUI) > ... > But the point is, accessing __class__ (not to mention __bases__, > __name__, __dict__, func_code, func_globals, etc.) is something I need > to do a lot for this type of deal. I hope, then, that this is *not* a > case of "not using the language as intended". a wink is > included ;-) No problem, that level of internal detail is exposed precisely so that debuggers and browsers and profilers and compilers and disassemblers (etc) can be written in Python. Language meta-tools are very specialized applications, though, tackled by few and mastered by fewer. You'll have to use every __xxx__ thing there is in the end, and in 2.2 I expect you're actually going to find it harder than ever, because the new stuff is in addition to all the old stuff (e.g., instances of "old style" classes still all have the same type in 2.2, but instances of "new style" classes do not; and you're also going to have to worry about static classes vs dynamic classes, and dict-based namespaces vs slot-based, and static and class methods in addition to "regular old methods", and computed attributes, and custom metatypes changing method resolution order behind your back, and on & on). But the need for an end-user who's simply programming in Python-- not trying to extend or dissect it --to even think about writing 3.__class__, is non-existent. The handful of wizards working on meta-tools can learn to use parentheses, else I strongly doubt their mental capacities are adequate to the tasks they've tackled . > ... > (He repeats to himself as he codes, tense and white-knuckled: "functions > are not evil, functions are not evil, functions are not evil, . . ."). Think of them as methods spelled backwards and you'll be fine. of-course-that-doesn't-prove-they-aren't-evil-but-at-least-it- proves-they're-not-terrorists-ly y'rs - tim From pinard at iro.umontreal.ca Sun Oct 7 19:21:25 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 07 Oct 2001 19:21:25 -0400 Subject: SPAM (Re: ANNOUNCE: "Compiler") In-Reply-To: <7xitdr4ccv.fsf@ruckus.brouhaha.com> References: <7xitdr4ccv.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > This is a commercial closed-source program that has nothing to do with > Python. The guy once lobbied Python users to raise funds for a Python compiler of his own, to be the eight wonder of this world. He visits us once in a while. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From pinard at iro.umontreal.ca Wed Oct 17 16:01:05 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 17 Oct 2001 16:01:05 -0400 Subject: Pymacs 0.11 In-Reply-To: <15309.50374.210122.479399@beluga.mojam.com> References: <9qjosn$5nd$1@animus.fel.iae.nl> <15309.50374.210122.479399@beluga.mojam.com> Message-ID: [Skip Montanaro] > Fran?ois> From which Python version were function attributes made > Fran?ois> available? > Works for me with 2.0, but not 1.6. Thanks for the information. I guess it would be premature using these functions attributes in a package meant to be portable to most Python versions still being used nowadays. Later, maybe. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From paul at boddie.net Mon Oct 22 06:32:12 2001 From: paul at boddie.net (Paul Boddie) Date: 22 Oct 2001 03:32:12 -0700 Subject: Database Sessions and Transactions References: Message-ID: <23891c90.0110220232.1b0e9139@posting.google.com> "DeepBlue" wrote in message news:... > I am working on a CGI program in Python that connects to an Oracle database. > I am wondering on how to implement a transaction that belongs to a database > connection so that everything that belongs to the transaction can be rolled > back. Assuming that there isn't anything that the CGI program talks to, between itself and the database system, which holds the connection object and keeps the connection open... > In other words, the scope of the rollback is NOT the database connection BUT > the transaction that is defined from within the database connection. ...you appear to want to be able to open a connection by instantiating a connection object, explicitly define a transaction, do some work, suspend the transaction as you close the connection, and then upon a subsequent invocation of your CGI program, re-open the connection and resume the transaction. Is this a correct summary of your intentions? > Please note that Python DB API 2 talks of a transaction as belonging to the > scope of the database connection, and not something that can be created > independently from the Connection. That is my understanding. If you close a connection object, the DB-API module should perform a rollback of any open transaction (depending on various options, but this is generally the case). > Also, I can find no reference in Python DB API 2 to Sessions. How do we > manage different sessions/connections? There will definitely be people who know more about this than I do, but you should subscribe to the DB-SIG mailing list and post your question there - you can find the subscription page from http://www.python.org, of course. I remember that there was one person who was interested in improving the transaction support in the DB-API, so this may be on someone's wish list. Paul From mikael at isy.liu.se Fri Oct 5 02:07:59 2001 From: mikael at isy.liu.se (Mikael Olofsson) Date: Fri, 05 Oct 2001 08:07:59 +0200 (MET DST) Subject: Worldwide English (was Re: Python is better than free (was Re: G In-Reply-To: Message-ID: On 05-Oct-2001 Steve Holden wrote: > Well, I could even take exception to the word "it", since there are many > different Englishes. The following is hearsay: An English royalty is said to have claimed "English is not a worldwide language - bad English is." /Mikael ----------------------------------------------------------------------- E-Mail: Mikael Olofsson WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 Date: 05-Oct-2001 Time: 08:02:36 /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ This message was sent by XF-Mail. ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From skip at pobox.com Mon Oct 15 21:13:25 2001 From: skip at pobox.com (Skip Montanaro) Date: Mon, 15 Oct 2001 20:13:25 -0500 Subject: maximum recursion in "re" module? In-Reply-To: <200110160056.TAA20412@scortch.unisrv.net> References: <200110160056.TAA20412@scortch.unisrv.net> Message-ID: <15307.35253.91335.661869@beluga.mojam.com> CJ> startString = ".*?Lo Fi Play mp3String = re.compile(startString, re.I).sub("", mp3String, 1) Why do you need the ".*?" part of the re? I'd try this: startString = "Lo Fi Play Here's a first try at a PEP for making Python's codec error handling customizable. This has been briefly discussed before on the I18N-SIG mailing list. A sample implementation of the proposed feature is available as a SourceForge patch. Bye, Walter D?rwald --------------------------------------------------------------------------- PEP: ??? Title: Codec error handling callbacks Version: $Revision$ Last-Modified: $Date$ Author: walter at livinglogic.de (Walter D?rwald) Status: Draft Type: Standards Track Python-Version: 2.3 Created: ??-???-2001 Post-History: 04-Oct-2001 Abstract This PEP aims at extending Python's fixed codec error handling schemes with a more flexible callback based approach. Python currently uses a fixed error handling for codec error handlers. This PEP describes a mechanism which allows Python to use function callbacks as error handlers. With these more flexible error handlers it is possible to add new functionality to existing codecs by e.g. providing fallback solutions or different encodings for cases where the standard codec mapping does not apply. Problem A typical case is where a character encoding does not support the full range of Unicode characters. For these cases many high level protocols support a way of escaping a Unicode character (e.g. Python itself support the \x, \u and \U convention, XML supports character references via &#xxxx; etc.). When implementing such an encoding algorithm, a problem with the current implementation of the encode method of Unicode objects becomes apparent: For determining which characters are unencodable by a certain encoding, every single character has to be tried, because encode does not provide any information about the location of the error(s), so # (1) us = u"xxx" s = us.encode(encoding) has to be replaced by # (2) us = u"xxx" v = [] for c in us: try: v.append(c.encode(encoding)) except UnicodeError: v.append("&#" + ord(c) + ";") s = "".join(v) This slows down encoding dramatically as now the loop through the string is done in Python code and no longer in C code. Furthermore this solution poses problems with stateful encodings. For example UTF16 uses a Byte Order Mark at the start of the encoded byte string to specify the byte order. Using (2) with UTF16, results in an 8 bit string with a BOM between every character. To work around this problem, a stream writer - which keeps state between calls to the encoding function - has to be used: # (3) us = u"xxx" import codecs, cStringIO as StringIO writer = codecs.lookup(encoding)[3] v = StringIO.StringIO() uv = writer(v) for c in us: try: uv.write(c) except UnicodeError: uv.write(u"&#%d;" % ord(c)) s = str(v) To compare the speed of (1) and (3) the following test script has been used: # (4) import time us = u"?a"*1000000 encoding = "ascii" import codecs, cStringIO as StringIO t1 = time.time() s1 = us.encode(encoding, "replace") t2 = time.time() writer = codecs.lookup(encoding)[3] v = StringIO.StringIO() uv = writer(v) for c in us: try: uv.write(c) except UnicodeError: uv.write(u"?") s2 = v.getvalue() t3 = time.time() assert(s1==s2) print "1:", t2-t1 print "2:", t3-t2 print "factor:", (t3-t2)/(t2-t1) On Linux with Python 2.1 this gives the following output: 1: 0.395456075668 2: 126.909595966 factor: 320.919575586 i.e. (3) is 320 times slower than (1). Solution 1 Add a position attribute to UnicodeError instances. When the encoder encounters an unencodable character it raises an exception that specifies the position in the Unicode object where the unencodable character occurs. The application can then reencode the Unicode object up to the offending character, replace the offending character with something appropriate and retry encoding with the rest of the Unicode string until encoding is finished. A stream writer will write everything up to the offending character and then raise an exception, so the application only has to replace the offending character and retry the rest of the string. Advantage Requires minor changes to all the encoders/stream writers. Disadvantage As the encoder has to be called multiple times, this won't work with stateful encoding, so a stream writer has to be used in all cases. If unencodable characters occur very often Solution 1 will probably not be much faster than (3). E.g. for the string u"a"*10000+u"?" all the characters but the last one will have to be encoded twice when using an encoder (but only once when using a stream writer). This solution is specific to encoding and can't be extended to decoding easily. Solution 2 Add additional error handling names for every needed replacement scheme (e.g. "xmlcharrefreplace" for "&#%d;" or "escapereplace" for "\\x%02x" / "\\u%04x" / "\\U%08x") Advantage Requires minor changes to all encoders/stream writers. As the replacement scheme is implemented directly in the encoder this should be the fastest solution. Disadvantages The available replacement schemes are hardwired. Additional replacement schemes require that all encoders/decoders are changed again. This is especially problematic for decoding where users might want to implement various error handlers for handling broken text files. Solution 3 The errors argument is no longer a string, but a callback function: This callback function gets passed the original unicode object and the position of the unencodable character and returns a new unicode object that should be encoded instead of the unencodable one. (Note that this requires that the encoder *must* be able to encode what is returned from the handler. If not a normal UnicodeError will be raised.) Example code could look like this: us = u"xxx" def xmlescape(uni, pos): return u"&#%d;" % ord(uni[pos]) s = us.encode(encode, xmlescape) Advantages This makes the error handling completely customizable. The error handler may choose to raise an exception or do any kind of replacement required. The interface between the encoder and the error handler can be designed in a way that this mechanism can be used for decoding too: The original 8bit string is passed to the error handler and the error handler returns a replacement unicode object and a resyncronization position where decoding should continue. Disadvantages This solutions requires changes to every C function that has "const char *errors" arguments. (e.g. PyUnicode_EncodeLatin1( const Py_UNICODE *p, int size, const char *errors) has to be changed to PyUnicode_EncodeLatin1( const Py_UNICODE *p, int size, PyObject *errors) (To provide backwards compatibility the PyUnicode_EncodeLatin1 signature remains the same, a new function PyUnicode_EncodeLatin1Ex is introduced with the new signature. PyUnicode_EncodeLatin1 simply calls the new function.) Solution 4 The errors argument is still a string, but this string is used to lookup a error handling callback function from a callback registry. Advantage No changes to the Python C API are required. Well known error handling schemes could be implemented directly in the encoder/decoder for maximum speed. Like solution 3 this can be done for encoders and decoders. Disadvantages Currently all encoding/decoding functions have arguments const Py_UNICODE *p, int size or const char *p, int size to specify the unicode characters/8bit characters to be encoded/decoded. In case of a error a new unicode or str object has to be created from this information and passed to the error handler. This has to be done either for every occuring error or once on the first error and the result object must be kept until the end of the function in case another error occurs. Most functions that call the codec functions work with unicode/str objects anyway, so they have to extract the const Py_UNICODE */int arguments and pass it to the functions, which has to reconstruct the object in case of an error. Sample implementation A sample implementation is available on SourceForge [1]. This patch implements a combination of solutions 3 and 4, i.e. it is possible to pass functions *and* registered callback names to unicode.encode. The interface between the encoder and the handler has been extended to be able to support the same interface for encoding and decoding. The encoder/decoder passes a tuple to the callback with the following entries: 0: the name of the encoding 1: the original Unicode object/the original 8bit string 2: the position of the unencodable character/byte 3: the reason why the character/byte can't be encoded/decoded as a string (e.g. "character not in range(128)" for encoding or "unexpected end of data", "invalid code byte" etc. for decoding) 4: an additional object that can be used to pass state information to the callback. All implemented encoders/decoders currently pass None for this. The callback must return a tuple with the following info: 0: a Unicode object which will be encoded instead of the offending character (for encoders). A Unicode object that will be used as a replacement for the undecodable bytes in the decoded Unicode object (for decoders) 1: a position where the encoding/decoding process should continue after processing the replacement string. The patch includes several preregistered encode error handlers schemes with the following names: "strict", "ignore", "replace", "xmlcharrefreplace", "escapereplace" and decode error handlers with the names: "strict", "ignore", "replace" The patch includes the other change to the C API described in Solution 4. The parameters const Py_UNICODE *p, int size have been replace by PyObject *p so that all functions get the Unicode object directly as a PyObject * and pass this directly along to the error callback. For further details see the patch on SourceForge. References [1] Python patch #432401 "unicode encoding error callbacks" http://sourceforge.net/tracker/?group_id=5470&atid=305470&func=detail&aid=432401 [2] Previous discussions on this topics in the I18N-SIG mailing list http://mail.python.org/pipermail/i18n-sig/2000-December/000587.html http://mail.python.org/pipermail/i18n-sig/2001-June/001173.html Copyright This document has been placed in the public domain. From weismann at netvision.net.il Tue Oct 30 06:07:12 2001 From: weismann at netvision.net.il (Amit Weisman) Date: Tue, 30 Oct 2001 13:07:12 +0200 Subject: Send an email . Message-ID: <007901c16133$0835e260$a197003e@rashome> What module should I use to send an email ? Thanks ---------------------------------------------------------------- Weisman Amit 11 Rupin st. Holon 58344 Israel Tel : 050397330 weismana at cs.bgu.ac.il -------------- next part -------------- An HTML attachment was scrubbed... URL: From volucris at hotmail.com Wed Oct 3 22:52:34 2001 From: volucris at hotmail.com (Greg Krohn) Date: Wed, 3 Oct 2001 21:52:34 -0500 Subject: Newbie question please answer if you have time References: Message-ID: <3bbbcdfc$0$317$6e49188b@news.goldengate.net> A good game is SolarWolf http://shredwheat.zopesite.com/solarwolf >From my limited experience, there isn't much you can't do. Off the top of my head, I can't think of anything that wasn't possible to do in Python. Well, maybe some low level stuff, but if you're a newbie, you probably don't care about that too much yet. A warning though: it's addictive. Since learning Python I haven't touched another language (except a little stint in esperanto). greg -- Volucris (a) hotmail.com "Eu n?o falo uma ?nica palavra do portugu?s." "Loula" wrote in message news:trnaonkc84jg7c at corp.supernews.com... > I was just wondering if anyone could tell me of some games or other programs > that were written in python? I'm new to this and I'm very curious about what > python can do. Thanks > > From max at alcyone.com Fri Oct 5 13:44:57 2001 From: max at alcyone.com (Erik Max Francis) Date: Fri, 05 Oct 2001 10:44:57 -0700 Subject: Mutable default values for function parameters References: <7da8d8f8.0110040056.42443bb@posting.google.com> <3BBCA084.B10B6061@alcyone.com> <7da8d8f8.0110050143.25e58dd8@posting.google.com> Message-ID: <3BBDF199.DC87DDDE@alcyone.com> sebastien wrote: > In fact my question is maybe not related to mutable default arguments > at all. This is only the way I used to try to solve my problem wich is > to find a way to mimic this: > > def variant(data, old_data): > r = (data <> old_data[0]) > old_data[0] = data > return r > > A=[None] > for i in range(10): > assert variant(i,A) > > But without mandate the user to explicitely manage the plumbery used > to save the data between two calls of the function (A here). Why not make the interface clearer and have a support class that holds one value and supports get and set methods and have the caller pass that in? That would make things much clearer and everyone would agree on the interface. class Placeholder: def __init__(self, x = None): self.x = x def get(self): return self.x def set(self, x): self.x = x def variant(data, oldData): r = data != oldData.get() oldData.set(data) return r A = Placeholder() for i in range(10): assert variant(i, A) The contract is enforced since if the caller pass in something without get and set methods AttributeErrors will be thrown (or you could explicitly enforce the type of oldData with a typecheck). -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Morality is a weakness of the mind. \__/ Arthur Rimbaud Alcyone Systems' CatCam / http://www.catcam.com/ What do your pets do all day while you're at work? Find out. From gmcm at hypernet.com Fri Oct 12 08:28:02 2001 From: gmcm at hypernet.com (Gordon McMillan) Date: 12 Oct 2001 12:28:02 GMT Subject: multi command session through a socket References: Message-ID: Nomad wrote: > I've been playing with sockets and serversockets in Python (2.1 win32) > for the last few days. I've been trying to adapt the code from > 'BaseHTTPServer.py' in the standard library, but no matter what I try, > the server side always drops the connection after only one command, > whereas I'd like to be able to run several commands (like telnetting > into a pop3 session) and finishing with a QUIT command (or hopfully > later a timeout, but that's another question entirely). [snip] > def handle(self): [snip] > self.quit = 1 > while self.quit == 1: # <---- what is wrong here > self.raw_requestline = self.rfile.readline() > if not self.parse_request(): > return > > def parse_request(self): [snip] A cursory examination reveals that you are always returning a false value from parse_request. Looks like "self.quit" and the return from parse_request have redundant intents and conflicting implementations. - Gordon From burner at core.binghamton.edu Sun Oct 28 10:36:27 2001 From: burner at core.binghamton.edu (Michael R. Head) Date: Sun, 28 Oct 2001 10:36:27 -0500 Subject: Schools that teach Python (or use for assignments) In-Reply-To: ; from python-list-request@python.org on Sun, Oct 28, 2001 at 09:57:01AM -0500 References: Message-ID: <20011028103627.B21174@warp.core.binghamton.edu> It was asked recently which schools are teaching Python. I just started PhD work at Brandeis, and one of the (shared grad/undergrad) courses I'm taking uses Python for implementing a natural language processor. Very interesting. I wouldn't say they're teaching it, though, because we didn't have much in-class tutulage on the language - which is exactly how it should be. I'd always wanted to learn Python, particularly after reading Bruce Eckel's chapter on "the multi-language pattern", using Jython with Java. I've been disappointed a little, but overall very impressed. (Most of my disappointments have stemmed from my desire to make Python act like Haskell, and 1.5.2 (the version we are using in class) doesn't have enough FP features, though 2.2 appears to resolve most of my concerns. One of the things I really like about learning Python (as opposed to "bigger" or "smaller" langauages) is that the barrier to entry is so low (just like perl) that you end up using it for "getting stuff done" at the command line, but at the same time, it's powerful enough and modular enough to build big complex systems. mike -- Michael R. Head burner at core.binghamton.edu GPG public key: http://www.core.binghamton.edu/~burner/gpg.key.txt -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 536 bytes Desc: not available URL: From wtanksle at dolphin.openprojects.net Fri Oct 12 15:59:10 2001 From: wtanksle at dolphin.openprojects.net (William Tanksley) Date: Fri, 12 Oct 2001 19:59:10 GMT Subject: Semantic indentation (OpenGL) References: Message-ID: On Fri, 12 Oct 2001 15:52:16 +0200, Marek Kro??k wrote: >glBegin(GL_POINTS); > ... > glVertex3f(...); > ... >glEnd(); >These are syntactically at the same level (compiler's point of view), but >semantically not (library's point of view). Unfortunately python does not >allow me to use this formatting any more. How about: try: glBegin(GL_POINTS) glVertex3f(...) finally: glEnd() >(Marek Krocak) -- -William "Billy" Tanksley From robin at jessikat.fsnet.co.uk Tue Oct 16 13:36:33 2001 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 16 Oct 2001 18:36:33 +0100 Subject: fast sub list operations References: Message-ID: In article , Rich Harkins writes >Would this work for you? > >coords=[x1,y1,x2,y2,x3,y3,...] >final=[(coords[i],coords[i+1]) for i in xrange(0,len(coords),2)] >final will now be [(x1,y1),(x2,y2),(x3,y3),...] > >Wouldn't be terribly fast but it should do the trick. Use range instead of >xrange if you know coords will not be very big. You will get an IndexError >if the length of coords is not a multiple of two. > >Rich .... yes it would work, but what I'm getting at is that there seem to be few if any fast list methods except the obvious. I would expect that there should at least be a way to split lists using ranges and I know that this is done in NumPy so why not in python. map and reduce etc are fast, but useless without builtin C speed things to go with them. Skip points out a way to interleave pairs back into the single level eg reduce(operator.add,[(1,2),(3,4),(5,6)],()) --> (1, 2, 3, 4, 5, 6) -- Robin Becker From dalke at dalkescientific.com Wed Oct 17 20:58:07 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 17 Oct 2001 18:58:07 -0600 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: <9ql9l5$tcr$1@slb5.atl.mindspring.net> Huaiyu Zhu: > cannot be written in this naive version: > > while 1: > x = next() > if x.is_end: break > y = process(x) > if y.is_what_we_are_looking_for(): break > else: > raise "not found" > > This is because there are two breaks that have different semantical > meanings. The fully equivalent version in current syntax has to use > one extra variable to keep track of the breaks that affect the else It doesn't have to use an extra variable. while 1: x = next() if x.is_end: raise "not found" y = process(x) if y.is_what_we_are_looking_for(): break > 4.1. Action needed before condition: > > while x = get_next(); x: > whatever(x) I prefer the syntax mentioned some months ago when this discussion last flared up. loop: x = get_next() break if x: whatever(x) (with variations of the spelling - I don't recall the details of what came up) Basically, I don't like multiple actions in the same line. I like vertical arrangement of code. I find it easier to read and easier to understand. > 4.2. Condition does not need to be a method of an object in assignment: > > while line = readline(); 'o' in line: > line = process(line) > if 'e' in line: break > else: > print "never met break" for line in iter(readline, ""): if 'o' in line: print "never met break" # Really, "never saw an 'e'" break line = process(line) if 'e' in line: break This one extra line if you (unlike me) put the 'break' after if's ":".) And since you like code after semicolon, for line in iter(readline, ""): if 'o' in line: print "never saw an 'e'"; break line = process(line) if 'e' in line: break > 4.4. More complex example: > > if x = dict[a]; x: proc1(x) > elif x = next(x); x.ok(): proc2(x) > elif x.change(); property(x): proc3(x) > ... Need a real life example here. Is there something in the standard library which would be improved with this change? The reason I ask is because this code can be refactored into a function. def funky_function(dict, a, x): x = dict[a] if x: return proc1(x) x = next(x) if x.ok(): return proc2(x) x.change() if property(x): return proc3(x) You can add qualifications to make a function call harder to do, but I'm betting they aren't common in real life. > It is seen that the new syntax remove substantial amount of clutter, in contrived cases > thereby increasing readability and expressiveness. but increasing the temptation for people to write a = f(x) if a > 2: g() as if a = f(x); a > 2: g() which is *less* readable because it is *more* expressive. > This structure is safe against single typing errors: Here's a single typing error. if x > 1;0: ... when it should have been if x > 1.0: ... > - mistype == for = in statement will be detected How? An expression is a statement. > Since the change is only in the syntax of "if", "elif" and "while", > not in the fundamentals of expressions and statements, there is not > much more chance of obfuscation than existing syntax. Famous last words. :) Quick! Spot the colon! if a; \ b; \ c; \ d: \ e; \ f; \ g This isn't possible now because the first ";" or ":"-like symbol after the 'if' must be a ':' else Python would complain. > We show that the following alternatives have more problems than the > proposed extension. ... > 6.3. Using iterators: In Python 2.2, it is possible to write > > for line in file: > if line=='end': break > process_line(line) > > in place of > > while line=file.readline(); line != 'end': > process_line(line) > > However, this does not solve the problem we are considering > completely. It is more suitable for objects that are naturally used > (and reused) in iterations so that it is profitable to create > iterators for them. It is not practical to define an iterator for > every action that might go before a condition: > > while char=file.readline()[3]; char != 'x': > process(char) To quote Winnie-the-Pooh, I am a programmer of very little brain. I forget things too easily, so I like to step through what I'm doing. for line in iter(file.readline, ""): char = line[3] if char != 'x': break process(char) This is also easier to debug. I can stick in a "print line" and see what's going on. It calls for more work to change the original code to do that. Yes, it's 5 lines compared to 2. Again, your example is contrived. The real code might look like commands = ( (3, 'x', None), (0, 'reset', do_reset), (4, 'fly', use_swatter), ) for line in file: for cmd in commands: if line[cmd[0]:].startswith(cmd[1]): f = cmd[2] if f is None: return f(line) > while string = raw_input(prompt): not string.startswith("n"): > process(string) Should be a semicolon there ;) You didn't mention loop: statements break if expr: statements as an alternative, with various spellings of 'loop' and 'break if'. One with no new keywords is while expr: statements break if expr: statements but all this does is save one line over while expr: statements if expr: break But-then-again-it-took-me-a-while-to-like-list-comprehensions-ly y'rs Andrew dalke at dalkescientific.com From gh_pythonlist at gmx.de Thu Oct 4 09:21:27 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 4 Oct 2001 15:21:27 +0200 Subject: SQL/Python question -- slow... What is the fixed cost? In-Reply-To: <3bbc26d3.1098181651@spamkiller.newsfeeds.com>; from pengo243@hotmail.com on Thu, Oct 04, 2001 at 09:12:13AM +0000 References: <3BBB7DFD.25217E1A@iems.nwu.edu> <3bbc26d3.1098181651@spamkiller.newsfeeds.com> Message-ID: <20011004152126.B2191@lilith.hqd-internal> On Thu, Oct 04, 2001 at 09:12:13AM +0000, Mark Berry wrote: > Another database that would be worth looking at is SAPDB. It's free > (GPL) and is VERY feature rich (more so than even postgres), though I > am not sure if there are python database drivers. There are. They're even maintained by the SAPdb people themselves. http://www.sapdb.org/ Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From palisade at users.sourceforge.net Fri Oct 26 05:25:04 2001 From: palisade at users.sourceforge.net (Nelson Rush) Date: Fri, 26 Oct 2001 09:25:04 GMT Subject: PIL - cannot get jpeg decoder to work Message-ID: I've tried everything I can think of to get the Jpeg decoder to function under PIL, but I've yet to get it working. Can anyone tell me what I'm doing wrong? Thanks. Python 2.0 (#1, Oct 18 2000, 13:16:26) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import os,sys >>> import _imaging >>> import Image >>> import JpegImagePlugin >>> Image._initialized=1 >>> Image.init() >>> im = Image.open("face.jpg").save("testing.jpg") Traceback (most recent call last): File "", line 1, in ? File "/usr/home2/palisade/PIL/PIL/Image.py", line 709, in save self.load() File "/usr/home2/palisade/PIL/PIL/ImageFile.py", line 140, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File "/usr/home2/palisade/PIL/PIL/Image.py", line 243, in _getdecoder raise IOError, "decoder %s not available" % decoder_name IOError: decoder jpeg not available Sincerely, Nelson Rush "To make available for life every place where life is possible. To make inhabitable all worlds as yet uninhabitable, and all life purposeful." -- Hermann Oberth From rcena at epcor.ca Thu Oct 25 11:00:50 2001 From: rcena at epcor.ca (Resty Cena) Date: 25 Oct 2001 08:00:50 -0700 Subject: Curl-ing, anyone? References: <458b194a.0110241156.795e9618@posting.google.com> Message-ID: <458b194a.0110250700.4f71b05d@posting.google.com> "Jeff Hinrichs" wrote in message news:... > I don't think so, what about it makes you consider the possibility? > Just that I find the language cool (though I'm disappointed with the lack of facility for incrementally re-defining classes, or at least I haven't found a way to do it), and the IDE even cooler. I always have a soft spot for things well done. From tim.one at home.com Wed Oct 17 21:49:35 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 17 Oct 2001 21:49:35 -0400 Subject: Assignment direction (Re: Curious assignment behaviour) In-Reply-To: <3BCE23A9.E39D04C2@cosc.canterbury.ac.nz> Message-ID: [Greg Ewing] > ... > By the way, when I was very young, before I'd had > much contact with real computers or HLLs, I designed > a programming language in which assigment was written > = , e.g. A + B = C. It seemed logical > to me -- you do the arithmetic first and then store > the result! > > I was quite surprised when I found out later that > most languages do it the other way around. ABC's newbie-testing drove them to spell assignment PUT a+b IN c so-much-for-the-value-of-newbie-friendliness-ly y'rs - tim From senux at senux.com Tue Oct 2 10:05:40 2001 From: senux at senux.com (Brian Lee) Date: Tue, 2 Oct 2001 23:05:40 +0900 Subject: trying sockets In-Reply-To: <9pce64$5gnu5$1@hades.rz.uni-sb.de>; from uwe@rocksport.de on Tue, Oct 02, 2001 at 01:07:16PM +0000 References: <9pce64$5gnu5$1@hades.rz.uni-sb.de> Message-ID: <20011002230540.A28605@jupiter.senux.com> Try urllib module. It's very easy to use to fetch web page. And I think you don't need to bind in your source because you want to fetch web page by GET command. You don't need to start tcp server. Right? [senux at pooky senux]$ python Python 1.5.2 (#1, Mar 3 2001, 01:35:43) [GCC 2.96 20000731 (Red Hat Linux 7.1 2 on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import urllib >>> a = urllib.urlopen('http://www.num.uni-sb.de') >>> print len(a.read()) 4678 I got 4678 bytes from www.num.uni-sb.de. Brian On Tue, Oct 02, 2001 at 01:07:16PM +0000, Uwe Schmitt wrote: > Hi, > > i'm just playing with the socket module: i'd like to send > a "GET/HTTP" request to a webserver and record the answer > of the server. so i wrote > > from socket import * > > snd=socket(AF_INET,SOCK_STREAM) > snd.connect(("www.num.uni-sb.de",80)) > print snd.getsockname() > > lstn=socket(AF_INET,SOCK_STREAM) > lstn.bind(snd.getsockname()) > > snd.send("GET / HTTP/1.0 ") > lsten.listen(1) > conn,addr=lstn.accept() > print conn.recv(1024) > > lstn.close() > snd.close() > > but i get the following output: > > ('134.96.31.42', 1662) > Traceback (most recent call last): > File "client.py", line 8, in ? > lsten.bind(snd.getsockname()) > socket.error: (98, 'Address already in use') > > so: what did i do wrong ??? > > yours, uwe. > > > > -- > Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes > phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 > D-66041 Saarbr?cken > http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 > > -- > http://mail.python.org/mailman/listinfo/python-list -- Brian Lee - http://www.senux.com/ Bigamy is having one spouse too many. Monogamy is the same. From matt at mondoinfo.com Wed Oct 3 15:26:11 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Wed, 03 Oct 2001 19:26:11 GMT Subject: Tkinter pack w/o gutter References: <6f355f51.0110031013.5192d60@posting.google.com> Message-ID: On 3 Oct 2001 11:13:15 -0700, Phlip wrote: >Try this snip: > > from Tkinter import * > tk = Tk() > > for side in ('left', 'right'): > canvas = Canvas(tk, background='blue', width = 100, height = 100) > canvas.pack(side = side, padx = "0m") > > mainloop() > >Observe how there is a gutter of 2 pixels (one per canvas) between >them. > >How do I get rid of this gutter? > >'padx = 2' stretches the gutter out, but 'padx = 0' does not get rid >of it. Other experiments, such as with 'ipadx', don't work. I think that adding highlightthickness=0 to your canvas's options will do what you want. Regards, Matt From graz at mindless.com Wed Oct 31 12:09:22 2001 From: graz at mindless.com (Graham Ashton) Date: Wed, 31 Oct 2001 17:09:22 GMT Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <3BE01E8F.3A384D4C@alcyone.com> Message-ID: <6fWD7.5601$4x3.771970@news1.cableinet.net> In article , "Oleg Broytmann" wrote: > On Wed, Oct 31, 2001 at 07:53:51AM -0800, Erik Max Francis wrote: >> >> There's a time for open source advocacy, but it isn't here and now. > > I am not advocating "open source". I am advocating "free software".... And they're off.... -- Graham From grante at visi.com Fri Oct 12 16:26:39 2001 From: grante at visi.com (Grant Edwards) Date: Fri, 12 Oct 2001 20:26:39 GMT Subject: YOU ARE ALL GAY! References: Message-ID: In article , PoulsenL at capecon.com wrote: > Bizarrly enough it looks like stenography. Maybe just my > paranoid self, but it is english sounding gibberish. Actually > i have seen stenographic examples that were more coherent. I presume you mean steganography. Shouldn't a good steganographic message really ought to make sense on it's own? That way nobody would suspect that there is concealed content. -- Grant Edwards grante Yow! .. I wonder if I at ought to tell them about my visi.com PREVIOUS LIFE as a COMPLETE STRANGER? From benjaminsims at yahoo.com Wed Oct 3 13:16:19 2001 From: benjaminsims at yahoo.com (Ben) Date: 3 Oct 2001 10:16:19 -0700 Subject: Zope capabilities question Message-ID: <54410e1f.0110030916.15292301@posting.google.com> Hi all, wonder if anyone can give me some tips on this subject. I am attempting to build a portal which will allow the display of information by keyword or subject, independently of the directory or folder it is stored in. For example, say I had a several departments in my company. One produces documents about cars, the other about airplanes. These will sometimes have things in common. So, I want to implement a system whereby when a user clicks on the 'tyres' section all the relevant document metadata from each department appears on one page. It should seem to the user like there is a seperate 'tyres' section. Sorry for the bad analogy; hope you see what I mean. It is possible for a Zope solution to do this, or will I have to start building in PHP or something similar? From stephen at theboulets.net Wed Oct 24 08:01:24 2001 From: stephen at theboulets.net (Stephen Boulet) Date: Wed, 24 Oct 2001 07:01:24 -0500 Subject: Executing a string as python code References: Message-ID: Yes, but this is no cgi script. It's in my program, which, after all, also executes python code. If I write: << command = '' for i in range(100): command = command + 'list%d = []\n' % i exec(command) >> That's no less secure than typing them out by hand, right? -- Stephen Richard Jones wrote: > On Wednesday 24 October 2001 13:30, Stephen Boulet wrote: >> Can someone tell me how to execute an arbitrary string as python code? >> >> I'm trying to make a bunch of lists named list00, list01, ..., to list99 >> (I don't want to make a single list of lists, since list00 is actually >> already a list of lists), and I thought doing this as a string would be >> the easiest way. >> >> I guess a dictionary with string keys and list values would be another >> way (maybe a better way). > > Pretty much any time you're considering "execute an arbitrary string as > python code", you're doing things the (hard|insecure) way. > > Investigate using a dictionary. > > > Richard From huaiyu at gauss.almadan.ibm.com Tue Oct 23 15:49:37 2001 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 23 Oct 2001 19:49:37 +0000 (UTC) Subject: Dictionary from list? References: Message-ID: On Tue, 23 Oct 2001 01:21:04 -0400, Tim Peters wrote: >There's already a dictionary() constructor in 2.2, and that's not going to >change (it would be too odd if every scalar and container builtin type had a >builtin constructor except for dicts). One question is what it should do; >all it can do in 2.2b1 is basically silly, amounting to yet another way to >spell "shallow-copy the argument". There have been several good arguments about why [(k,v), (k,v) ...] is better than [k, v, k, v, ...]. Here are some more observations: - I found Perl's hash initialization quite non-intuitive when I was using Perl two years ago. Most text files put k,v in the same line, and most regular expression extract them at once. It takes a little bit extra work to put k,v pairs into a flat array. - In Python the sequence-of-pairs structure is easily created by d.items(), re.match.groups and possibly others. It is quite handy for sorting, filtering and other processings. It is often necessary to put them into a dictionary afterwards, and a constructor would be helpful. - Perhaps a pair of functions flatten(x) and collect(x, n) would be useful when dealing with flat sequences, even when it is not necessarily associated with dictionaries. - As to the question of what the constructor should do in borderline cases, is there a specific reason that it should not behave exactly like this? def dict(x): d = {} for k, v in x: d[k] = v return d There is no need to differentiate between tuples, lists, iterators, etc. Any sequence whose every element is a sequence of length two should work. Everything else should raise an exception. - The form of ([k, k, ...], [v, v, ...]) is less frequently used (in my case anyway) and can be easily converted using zip(). I keep a file utils.py around that include a many little functions like the above, and I find myself doing "from utils import dict" quite often. Another function I use is items(x) returning x.items() if x is dictionary, or [(i,x[i]), ...] if x is sequence. With dict(), items() and zip() I could write many programs useful for both lists and dicts. Huaiyu From singleton at skynet.be Tue Oct 16 08:24:49 2001 From: singleton at skynet.be (Thomas Singleton) Date: 16 Oct 2001 05:24:49 -0700 Subject: Parsing XML (simple) References: Message-ID: "John J. Lee" wrote in message news:... > On 15 Oct 2001, Martin von Loewis wrote: > > > singleton at skynet.be (Thomas Singleton) writes: > > > > > > > > commande1 > > > commande2 > > > > [...] > > > After reading the modules doc and a few usenet posts, i have written a > > > small python program to echo the values contained between tags, but > > > i'm having troubles with the commands, only the FIRST one is echoed. > > Martin fixed your problem, but since I've read in several different places > that 'there are two apis for dealing with XML in Python', I thought I'd > point out the third, XPath, an implementation of which is available in > 4Suite. Simpler to use (for my simple purposes, at least), but slower, I > expect. > > > John Thank you both for your comments ! Thomas Singleton From nospam at bigfoot.com Wed Oct 17 08:25:16 2001 From: nospam at bigfoot.com (Gillou) Date: Wed, 17 Oct 2001 14:25:16 +0200 Subject: HTMLParser cannot parse some web pages? References: <3BCD77D2.EBFB2D98@starhub.net.sg> Message-ID: <9qjt01$2qhu$1@norfair.nerim.net> Paul, Have a look at this... http://www.oreilly.com/catalog/pythonsl/chapter/ch05.html This includes an example that samples the links of a page. Of course, an as most HTML sniffer, it cannot handle properly links which target are results of javascript expressions. --Gilles "Paul Lim" a ?crit dans le message news: 3BCD77D2.EBFB2D98 at starhub.net.sg... > Hi, > I am a newbie in Python. I hope the guru could advise me on the > following > > I am trying to extract the links in html file. > My code is shown below: > > The code works fine. But I just want to understand more about this > HTMLParser module. Apparently, there are some webpages where I cannot > extract the links. > But I really don't understand why? An example is > http://www.admissions.rmit.edu.au/about/index.html > > Is there certain limitation in this HTMLParser? For example, is it that > it cannot extract from certain kind of web pages. If so, which kind? > > Thank you very much for your help. > > Sincerely > Paul > > "To extract the links in a page." > > # To open a url and return url handler > try: > linkHandler = urllib.urlopen(link) > except IOError: > print "Unable to open url!" > > > # Extract link from the HTML file and stored in anchorlist > try: > parser = HTMLParser(NullFormatter()) > parser.feed(linkHandler.read()) > except: > print "Unable to extract!" > pass > > > From michael at stroeder.com Tue Oct 30 15:38:49 2001 From: michael at stroeder.com (Michael =?iso-8859-1?Q?Str=F6der?=) Date: Tue, 30 Oct 2001 21:38:49 +0100 Subject: [Tutor] DNS module or how to ... ? References: Message-ID: <3BDF0FD9.E38AD4CE@stroeder.com> Danny Yoo wrote: > > On Mon, 8 Oct 2001, A wrote: > > > Is there a DNS module available for Python ? > > There are a few resources you can use if you're looking for Python > modules. A DNS module in pure Python can be found at http://pydns.sf.net. You have to check it out from CVS at the moment. Ciao, Michael. From gregczajkowski at yahoo.com Tue Oct 2 16:09:55 2001 From: gregczajkowski at yahoo.com (mykroft) Date: 2 Oct 2001 13:09:55 -0700 Subject: Non-arbitrary integer math Message-ID: <79b176de.0110021209.6142c830@posting.google.com> Hi all, I've been searching for math libraries that define non-arbitrary length integer types. Including but not limited to signed/unsigned 1/2/4/8/16 byte types. I've tried searching "the vaults" and previous c.l.p posts, without much success. The struct and array module's won't do either. Most of the math I need to do is integer arithmetic. For now I'm coding my own version of these but if this has been done before, Id rather not repeat it. Thanks, mykroft From sholden at holdenweb.com Tue Oct 23 06:58:31 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 23 Oct 2001 06:58:31 -0400 Subject: Dictionary from list? References: Message-ID: <60cB7.7727$Ub2.262781@atlpnn01.usenetserver.com> "Tim Peters" wrote ... > [Steve Holden] > > Erm, wouldn't it make more sense (since there isn't a dictionary to start > > with) to implement a "toDict()" method of lists rather than a dictionary > > constructor? > > There's already a dictionary() constructor in 2.2, and that's not going to > change (it would be too odd if every scalar and container builtin type had a > builtin constructor except for dicts). One question is what it should do; > all it can do in 2.2b1 is basically silly, amounting to yet another way to > spell "shallow-copy the argument". > Well, I certainly agree that TypeError: argument must be of a mapping type isn't impressive. If it has to be a mapping already then making a dictionary out of it doesn't really help a lot (though I suppose it might speed up access for mappings with complex implementations behind them). > Sticking a toDict() method on lists isn't appealing regardless because > "iterable object" is the natural decomposition in 2.2 (for example, a tuple > of two-element lists is just as good of an input argument as a list of > two-element tuples, ditto a generator producing a sequence of address-book > objects that supply an iterator over their name and address fields, and so > on -- "a list" just isn't special here). > Sorry, must have been "Not Thinking in Java" for a second there. Given the rich variety of choices which *could* be made here, I don't see an argument that any *specific* choice would be less silly than any other. Certainly not really any argument for Perl's particular coercion. regards Steve -- http://www.holdenweb.com/ From pzw1 Wed Oct 31 11:28:55 2001 From: pzw1 (Peter Wang) Date: Wed, 31 Oct 2001 11:28:55 -0500 Subject: python development practices? References: Message-ID: just as an initial comment, i think this is about the most sensible/meaningful answer i've seen to my question so far... On Tue, 30 Oct 2001 20:58:56 -0800 (PST), wrote: >> as an aside, and i don't mean to sound obnoxious, but why did guido >> not put in data hiding into python at an earlier stage? my colleague >> whose background on generic programming comes entirely from the STL >> points this "wart" out as one of python's largest, and brings up the >> good point that data hiding was well known to the OOP world at the >> time of python's first incarnations. > >"Well known" != "Always a Good Thing". Curly braces were also well-known >then too, and I'm very glad Guido chose against using them. :) ditto. i realized a while back that tab indentation is ultimately an enforcement of the Don't Repeat Yourself principle. *all* good human programmers indent code blocks, and to require delimiters for ease of parsing is just duplicating that structural information to the compiler. duplication = source of bugs. there is really no simpler argument in favor of tabs. >A better approach is to cater to mature programmers and to use processes >that help other programmers mature too. A few places I've worked have used >something like the following (and these work well for non-Python code >too) and they really helped me: ----snip---- >We've used these guidelines and have had very few problems that you'd >consider related to "data-hiding". When breakage occurs, we go look at the >unittests (including the previous versions if needed) and compare it to >the code that broke. If breakage is due to the library maintainer changing >the documented use and behavior of the code, it's the maintainer's >responsibility to fix the problem, provide a good upgrade path, etc. this is a good approach. the crux of the approach you outlined - using unit tests as the primary API documentation - is really the sort of answer i was looking for. are there other, perhaps python-specific practices which have worked well? >Like I said, these worked for me and really helped me become more >disciplined. thanks for the info. -peter From grante at visi.com Mon Oct 29 11:57:51 2001 From: grante at visi.com (Grant Edwards) Date: Mon, 29 Oct 2001 16:57:51 GMT Subject: binary search tress using classes References: Message-ID: In article , christy_girl99 at yahoo.com wrote: > I was wondering if anyone had a binary search tree module I could > use? I need to write a program that counts the number of occurrences > of each word in a file, and outputs the word and corresponding counts > alphabetically. For example, if input is I remember this exact homework assignment from 20 years ago (ouch!). Though we were using Pascal (hence no classes), it gives one a nice feeling of continuity, doesn't it? -- Grant Edwards grante Yow! Zippy's brain cells at are straining to bridge visi.com synapses... From martin.franklin at westgeo.com Fri Oct 12 04:16:08 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Fri, 12 Oct 2001 09:16:08 +0100 Subject: Controlling the Opera browser under UNIX References: <3BC5C3DE.56459533@cz.ibm.com> Message-ID: <9q68o2$lui$1@mail1.wg.waii.com> Jaroslav Gergic wrote: > The webbrowser module in the Python 2.1 does not > support the Opera browser directly. > I think I posted this a few months ago....... here it is again. from webbrowser import * class Opera: def _remote(self, action): cmd = "opera -remote '%s' >/dev/null 2>&1 &" % (action) rc = os.system(cmd) if rc: import time os.system("opera &") time.sleep(PROCESS_CREATION_DELAY) rc = os.system(cmd) return not rc def open(self, url, new=0): if new: self.open_new(url) else: self._remote("openURL(%s)" % url) def open_new(self, url): self._remote("openURL(%s, new-window)" % url) register("opera", Opera) From sholden at holdenweb.com Fri Oct 19 12:45:16 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 19 Oct 2001 12:45:16 -0400 Subject: Python Aborts when I quit References: Message-ID: "tilwe" wrote ... > "Steve Holden" wrote ... > > ..... > > I too, am puzzled, but for a different reason. If you have indeed > > cut-and-pasted the stuff above from Python interpreter sessions and files, I > > am puzzled as to why you don't see error messages! > > [ ... ] > > Hi Steve, > I have reduced the code to a manageable size. The actual code is > about 1500 lines. It was only after I had the above code was when I > started > getting errors. Here is the actual code. > [ ...much more useful detail... ] > > Now I have Python script which imports "MyTools.py". This script > runs and executes as expected. The only problem comes when I execute > sys.exit(0) in the script. I believe that somewhere I have to > increment > or decrement the reference count of the result set, BUT I have no idea > where to start? > > Any pointers?????????????? > Well I have to confess I'm not an internals guy, but with the amount of detail you have now provided I'm sure someone will find out what your problem is. regards Steve -- http://www.holdenweb.com/ From sasoft at gmx.de Sun Oct 28 10:28:16 2001 From: sasoft at gmx.de (Stefan Antoni) Date: Sun, 28 Oct 2001 10:28:16 -0500 Subject: FInding files with python In-Reply-To: ; from Widgeteye@widgets.com on Sun, Oct 28, 2001 at 04:23:40AM -0000 References: Message-ID: <20011028102816.A9500@cruciatuz.de> On Sun, Oct 28, 2001 at 04:23:40AM -0000, Widgeteye wrote: > If (file exists) > do the following > > But I can't figure out how to test for the file.. > help?? > try the following: import os os.path.isfile("/mypath/to/myfile") this returns 1 or 0. -- Stefan Antoni From dale at riverhall.NOSPAMco.uk Fri Oct 5 21:24:06 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Sat, 06 Oct 2001 02:24:06 +0100 Subject: Pipes References: Message-ID: David Bolen wrote: >Most of the win32all modules are wrappers around standard Win32 calls. >In general, the docs with the package just give you anything specific >to their Python implementation/interface. For more detail, just pull >up documentation on the underlying Win32 calls, such as in MSDN. If >you don't have a local set of documentation, they are available at >http://msdn.microsoft.com/library/default.asp. > >> Has anyone done any work on inter-process and inter-machine >> communication? > >For interprocess I normally go ahead and use the popen# functions. >For inter-machine I'm much more likely to use an IP approach with >sockets (I've done named pipes in pure Windows applications that >weren't written in Python but not in Python to this point). > >-- >-- David Thanks. I'll check popen out but I may end up with sockets. -- Dale Strickland-Clark Riverhall Systems Ltd From tim at vegeta.ath.cx Mon Oct 1 16:04:30 2001 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Mon, 01 Oct 2001 20:04:30 GMT Subject: scanf style parsing References: <3BB16A50.BAE082FE@cygnus-software.com> <3BB2C7DA.F63EEAA7@cygnus-software.com> <9p4a4f$kdd$1@inputplus.demon.co.uk> <0hegrtgbg4bqjjkalcad8jr2nnh03k093d@4ax.com> Message-ID: Me parece que Toby Dickenson dijo: > "Fredrik Lundh" wrote: > > >Ralph Corderoy wrote: > >> > or, much more preferably: > >> > > >> > if filename[-4:] == '.txt': > >> > >> Overall, the Perl code's better. It didn't have to hard-code the > >> length of the string. > > > >if it matters, use endswith instead: > > > > if filename.endswith('.txt'): > > ... > > That wont match any .TXT files. Whether thats a problem depends on > whether you use Windows or not..... Wouldn't be the first time Windows was a thorn in my side. But: filename = 'AUTOEXEC.BAT' if filename.lower().endswith('.bat'): # things and stuff > Toby Dickenson > tdickenson at geminidataloggers.com Tim Hammerquist -- "Supported" is an MS term that means the function exists. The fact that it always fails means that it is an exercise for the programmer. -- Sarathy, p5p From welch at cs.unc.edu Thu Oct 25 08:56:27 2001 From: welch at cs.unc.edu (Greg Welch) Date: Thu, 25 Oct 2001 08:56:27 -0400 Subject: running Python remotely w/ Mac OS X 10.1 Message-ID: Hi. I am running Python 2.2b1 on three different Macs, each/all OS X 10.1 (relatively clean installs) with the 10-19-2001 security (and MS IE) patch. All are G4 machines w/ lots of memory. 2.2b1seems to build (configure --with-suffix=.exe), install, and run just fine on all machines when working from a local terminal window. However I see strange behavior when trying to run remotely. 1. If I connect to one of the machines remotely using ssh (e.g. ssh to my dual G4, which is faster than my home machine) and try and start python, I see the following errors: [mac-welch:~/proj/python] welch% python kCGErrorIllegalArgument : CGSNewConnection cannot get connection port kCGErrorIllegalArgument : CGSNewConnection cannot get connection port kCGErrorInvalidConnection : CGSGetEventPort: Invalid connection [mac-welch:~/proj/python] welch% 2. If I su to root in the same remote session, python starts just fine! I have tried looking at the system libraries/frameworks to make sure none are accidentally unreadable by me, and I have even tried to look through Python and Darwin source some to see if I could figure out where this was arising, but so far no luck. Thanks (in advance). ________ Gregory F. Welch Research Associate Professor Department of Computer Science University of North Carolina at Chapel Hill http://www.cs.unc.edu/~welch welch at cs.unc.edu 919-962-1819 From stuart at bmsi.com Fri Oct 19 15:49:51 2001 From: stuart at bmsi.com (Stuart D. Gathman) Date: Fri, 19 Oct 2001 15:49:51 -0400 Subject: Which python libraries are thread-safe? Message-ID: <9qq04v$ie5$1@nntp2-cm.news.eni.net> While python threads are simple and effective, how am I to know which library functions are thread safe and/or reentrant? Do I have to carefully examine the source for each one, and wrap it in a lock if I am not convinced it is safe? Shouldn't this be a required part of the docs for any library module? A lot of modules have global state which is obviously a problem, but sometimes it is not clear. Does tempfile work reliably with threads? -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - Mozart background song for the Microsoft "Where do you want to go from here?" commercial. From health at heylady.com Wed Oct 10 15:54:07 2001 From: health at heylady.com (health at heylady.com) Date: Wed, 10 Oct 2001 14:54:07 -0500 Subject: Your remove request has been successfully processed! Message-ID: <200110101954.OAA09591@server1.maxsvc.com> We have processed your remove request successfully and removed your email from the lifeover99 at royal-responder.com autoresponder. From rxg218 at psu.edu Mon Oct 29 17:32:50 2001 From: rxg218 at psu.edu (Rajarshi Guha) Date: Mon, 29 Oct 2001 17:32:50 -0500 Subject: Returning a dict with PySOAP Message-ID: <9rklcn$1t3o@r02n01.cac.psu.edu> Hi, I'm using PySOAP on AvtiveState Python 2.1 I have a problem; when a function on the server process returns a dictionary, the client can access the various values in the normal fashion (ie val = d['keystring'] etc) - however the when I do d.keys() I get an error: TypeError: object of type 'string' is not callable But since I can acess the values as a dictionary, should'nt keys() work? How can I get around it? TIA -- ------------------------------------------------------------------- Rajarshi Guha | email: rajarshi at presidency.com 152 Davey Laboratory | web : www.rajarshi.outputto.com Department of Chemistry | ICQ : 123242928 Pennsylvania State University | AIM : LoverOfPanda ------------------------------------------------------------------- GPG Fingerprint: DCCB 4D1A 5A8B 2F5A B5F6 1F9E CDC4 5574 9017 AF2A Public Key : http://pgp.mit.edu/ ------------------------------------------------------------------- "I'd love to go out with you, but the man on television told me to say tuned." From DeepBlue at DeepBlue.org Sun Oct 14 19:47:44 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Sun, 14 Oct 2001 23:47:44 GMT Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: "Tim Peters" wrote in message news:mailman.1003089072.26009.python-list at python.org... > > x = if e1 then e2 else e3 + 1 # SyntaxError > x = (if e1 then e2 else e3) + 1 # cool Much better: x = if e1 then (e2) else (e3) note that (e2) and (e3) stand for any operation: The problem with: x = (if e1 then e2 else e3) + 1 # cool is that it lacks potential of generalization. x = if e1 then (e2) else (e3) does give the user more freedom. > x = (if e1 then e2 else e3 + 1) # cool but not clear. > x = if e1 then e2 else e3 # SyntaxError no reason for error > x = (if e1 then e2 else e3) # cool shuold be euivalent to above > x = if if e1 then e2 else e3 then e4 else e5 # SyntaxError > x = (if (if e1 then e2 else e3) then e4 else e5) # cool But x = if (if e1 then e2 else e3) then e4 else e5 # should be cool too and so x = (if (if e1 then e2 else e3) then e4 else e5) with my idea: x = (if (if e1 then (e2) else (e3)) then (e4) else (e5)) or x = if (if e1 then (e2) else (e3)) then (e4) else (e5) should be equivalent. If the original posting passes Python will have its first confusing moment. x = if e1 then (e2) else (e3) and x = (if e1 then (e2) else (e3)) should be equivalent and they preserve clarity. DB From ignacio at openservices.net Thu Oct 4 00:04:48 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Thu, 4 Oct 2001 00:04:48 -0400 (EDT) Subject: return command in a function. In-Reply-To: Message-ID: On 4 Oct 2001, Quinn Dunkan wrote: > On Wed, 26 Sep 2001 22:10:48 -0400 (EDT), Ignacio Vazquez-Abrams > wrote: > >Heh. That's actually quite humorous to hear. It's one thing to not like gotos, > >but to actually give up the benefits of structured programming by eliminating > >break and continue and only allowing return at the end of a function borders > >on insanity. > > > >Yes, it is possible to write complex code without them, but only if you're > >prepared to write hundred-line if blocks and you honestly believe that doing > >that would make clearer code than using break, continue, or a premature > >return. > > > >Which it won't, I promise you. > > I guess you've never written Pascal. Neither have I, but I have written > Eiffel (though I never had a problem with lack of loop control or > return---possibly your hundred line blocks illustrate a different problem) Actually Pascal was my fourth language (after BASIC, machine code, and assembly). I remember those hundred-line blocks quite vividly; well, maybe only 20-30 lines, but you know what I mean(t). > See Kernighan's classic "Why Pascal is Not My Favorite Programming Language", > especially the "death of a thousand cuts" section: > > http://www.lysator.liu.se/c/bwk-on-pascal.html Yeah, that sounds about right... > I find it humorous that you describe elimination of break and continue as > "giving up on the benefits of structured programming" because one-in one-out, > no return, no loop control, etc. were the basic *tenets* of structured > programming when everyone got so gung-ho about it in the 70s or 80s or > whenever. I imagine that back in the goto-considered-harmful day all the > structured programming quiche-eaters sneered at C for being such a backsliding > recidivist. Yeah, well... it's the 21st century now, right? (Yeah, that's it!) ;) -- Ignacio Vazquez-Abrams From daves_spam_dodging_account at yahoo.com Tue Oct 30 16:12:09 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Tue, 30 Oct 2001 13:12:09 -0800 (PST) Subject: A better way to send mail? Message-ID: <20011030211209.77130.qmail@web21102.mail.yahoo.com> Hello all, Python promotes marital harmony. I came across an interesting problem the other day, and used Python to solve it. My wife always wants to know what the weather is going to be like, and works in a place where she can receive e-mail with image attachments but is not allowed to access the web. As a newcomer to Python, it seemed like a good exercise for me to learn how to write a script that gets the forecast image from our local news station's website, then e-mails it to her. It took me about 5 hours, most of which was spent reading up on urllib and smtplib. I finally ended up with a script that I'm rather proud of. I'm sure it's stilted and baby-talkish, but it works. Every day at 2:30pm my wife gets the forecast in her e-mail. My question is this: someone on this list just mentioned MimeWriter as the better package to use for authoring e-mail and attachments. I could not figure MimeWriter out in the hour or so I spent trying to get this script working, and I finally got the uu module to do what I needed so I used that instead. But I wonder if mime wouldn't be the better way. Here is the code I use to uuencode the forecast image and send it, with the error handling and other fluff stripped out. Can anyone tell me how I'd go about this using MimeWriter, and more importantly, do I want to? On the one hand, this script works, so I can easily call it "good enough" and forget it. On the other hand, I'd like to do a whole lot more with e-mail and attachments, so I'd like to learn to do it right. Here is the code: # Note: img contains the binary image # downloaded with urlib. imgfile = StringIO.StringIO(img) uuimg = StringIO.StringIO() uu.encode( imgfile, uuimg, 'SevenDayForecast.jpg' ) # msg starts out with the boilerplate text I # send with every e-mail. Basically it reads, # "here's the forecast. This was sent with # Python, e-mail me if you want it to stop." msg = msg + uuimg.getvalue() # SMTPSender, SMTPRecipient are set to my and her # e-mail addresses, respectively s = smtplib.SMTP(SMTPServer) ErrorAddresses = s.sendmail( SMTPSender, SMTPRecipient, msg ) s.close() Anyway, I'm just wondering if the MimeWriter libs would be better suited, and if so, how? Sorry if this example is too long. I probably only needed to post the first three lines of code, but I wanted other newcomers like me to be able to see the context. Thank you, -dB ===== David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From padhia at yahoo.com Tue Oct 30 15:57:40 2001 From: padhia at yahoo.com (P Adhia) Date: 30 Oct 2001 12:57:40 -0800 Subject: ReXX Style translate() function for strings ? Message-ID: <3281a460.0110301257.1a4d9a14@posting.google.com> Hello, I am a newbie to python, and remain impressed with the power of the language overall. There are however some little features that I am used to in ReXX (default scripting language for mainframes) that I could not find in python. ReXX has a translate() function that is much more powerful (and I think coule be a nice addition to python; of course with a different name) e.g. in ReXX, to change a date from yyyymmdd to mm/dd/yyyy is trivially simple, new_date = Translate('56/78/1234', old_date, '12345678') for formal syntax refert to, http://users.comlab.ox.ac.uk/ian.collier/Docs/rexx_ref/F/BI Python's l/r/strip() functions always remove white spaces -- corresponding ReXX functions (actually only one) has a optional argument that defines what character to strip. e.g. removing leading '0' from a number, punctualtion characters etc. If such functionality is trivial in python, I'll appreciate any new addition to my growing python knowledge. TIA P. Adhia From max at alcyone.com Wed Oct 31 19:40:22 2001 From: max at alcyone.com (Erik Max Francis) Date: Wed, 31 Oct 2001 16:40:22 -0800 Subject: Freeware Python editor References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <9rp4d8$830$1@tyfon.itea.ntnu.no> <3BE0240A.A2CCAA83@alcyone.com> Message-ID: <3BE099F6.A9E0708F@alcyone.com> Paul Winkler wrote: > But this was before my time. Can anyone who was hacking in the 70s/80s > comment on the evolution of these terms? When did "freeware" come to > mean "free beer, no source"? In the eighties, _freeware_ was a very common term which simply meant that the software was freely available for (sometimes non-commercial only) use. Whether source code was available for free, available for a fee, or not available at all was a totally separate question. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Laws are silent in time of war. \__/ Cicero Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From loredo at astro.cornell.edu Mon Oct 15 15:17:07 2001 From: loredo at astro.cornell.edu (Tom Loredo) Date: Mon, 15 Oct 2001 15:17:07 -0400 Subject: Image processing? References: <3BC9D56D.706A9BDF@ix.netcom.com> Message-ID: <3BCB3633.40EEA33@astro.cornell.edu> Gerhard H?ring wrote: > > > The Python Imaging Library is your friend. http://www.pythonware.com/ Yes indeed! If you want to manipulate the image data, you may want to bring it over from PIL into NumPy arrays. An example for doing this with RGB images is here: http://www.museweb.com/python/thumbnails.html You don't need the C extension; just pull the Python stuff from the RGBImage class. Not too well documented, but I only just put it up... Peace, Tom Loredo From jdunnett at uoguelph.ca Tue Oct 30 11:07:19 2001 From: jdunnett at uoguelph.ca (Jeffrey Dunnett) Date: 30 Oct 2001 16:07:19 GMT Subject: python binary search References: <9rkr8q$6e2$0@216.39.145.92> <9rkrp4$ltv$1@testinfo.cs.uoguelph.ca> <3BDE4C95.540DA929@engcorp.com> <3BDEAA81.DE839D17@uoguelph.ca> <3BDECCC0.1064A160@engcorp.com> Message-ID: <9rmj7n$26q$1@testinfo.cs.uoguelph.ca> Peter Hansen (peter at engcorp.com) wrote: : Jeff Dunnett wrote: : > : > Actually the Moo U is still teaching Java to the newbies partially be demand : > of the other departments who insist on giving us their first year students : > for a programming course. Prof. Kremer is one of the people who pushed for : > Python to be added. Apparently from what I have heard he is a steady : > preacher of Python. I think it was only in introduced last year or the year : > before. : Thanks for the info. I guess I might have played a small role yet. :-) : > I'll have you know that Computer Science is now the largest major on campus : > at Guelph. Although with the Ontario Vet College the campus can have a : > distinctive odor. : So Guelph might be the origin of the eXtreme Programming concept : of "Code Smell"? :-) : By the way, I just released your last name explains why you : wrote "IDOIT" previously.... you are in fact already done! : -- : ---------------------- : Peter Hansen, P.Eng. : peter at engcorp.com You might have had some influence I really don't know. Speaking of which Kremer has one of the best reputations in the department for teaching Professors. As for the last name I was wondering when you guys would start making the Dunnett puns. However, at least you could come up with something original. Jeff From olivier.deme at airtel-atn.com Mon Oct 1 08:46:49 2001 From: olivier.deme at airtel-atn.com (Olivier Deme) Date: Mon, 01 Oct 2001 12:46:49 +0000 Subject: Python embedding & question about autoconf and dynamic linking Message-ID: <9p9hmn$2dj$1@kermit.esat.net> I am myself into the same situation... I am trying to link my C application against libpython and I get unresolved symbols with posix thread related symbols. Why the heck would I need the posix thread library if I never create any thread ?!? Why is it so difficult to do something as common as this? O. In article , Mads Bondo Dydensborg wrote: > Hi there > > I am trying to use Python as an embedded interprenter. Whilst it is > quite easy to understand the C interface, I have found it _very_ hard to > figure out what flags I need to pass to the linker to get a succesfull > compile. It seems to depend rather heavily on a lot of parameters. > > So, my first question is if there are any autoconf macros out there that > will work for me, sort of like a AM_PATH_SDL macro? I have been > searching around, and found one from on of the KDE libs, but it seems to > break rather quickly for everything else than Python 1.5 (which it seems > to be only partly succesfull in anyway). > > My next question is with respect to dynamicly linking to the python > interprenter, when embedding it. All info I have been able to find, > points towards linking statically with libpython..a - however, > this adds about 660KB to my application, and in general I would much > rather link to a .so file - but I have not been able to find "such a > beast" or instructions on how to build one. Is it possible? Or is there > a clever way arond this kind of problem that I - beeing a clueless > newbee - have totally overlooked? (Maybe some weird extension trickery?) > > Thanks in advance! > > Mads > From LLewin at oreilly.com Mon Oct 29 22:33:15 2001 From: LLewin at oreilly.com (Laura Lewin) Date: 29 Oct 2001 19:33:15 -0800 Subject: Oreilly's Python and XML References: Message-ID: Hi, Please note that the chapter posted online is a beta chapter, and has not gone through the full round of editorial cycles (it is an "uncorrected proof"). We are aware of the issues that you have raised. They will certainly be addressed in the final version of the book, which is due out in December. Thanks for the feedback. You can feel free to email me directly if you have any further comments. Thanks, Laura LLewin at oreilly.com > >oreilly now has a sample chapter on their upcoming book "python and xml" > >look at: > > > >http://www.ora.com/catalog/pythonxml/chapter/ch01.html > > > >looks very promising. > -----------> in the interactive python session, when they > pprint(mapping), they show strings, whereas when I tried it I get unicode > strings (prefixed with a `u') > > Unfortunately I couldn't find an e-mail address to report these to. Anyone > know one? > > Julian From daves_spam_dodging_account at yahoo.com Fri Oct 19 15:07:03 2001 From: daves_spam_dodging_account at yahoo.com (David Brady) Date: Fri, 19 Oct 2001 12:07:03 -0700 (PDT) Subject: Extending back to the embedder Message-ID: <20011019190703.9517.qmail@web21110.mail.yahoo.com> Hello all, I am trying to use Python as a macro language for my application (written in MFC/C++). What I would like to do is allow users to write short scripts in Python that can control the parent application. I have successfully written a trivial embedding app, and a trivial extension app. What I don't understand clearly is how to compile an extension so that Python could call back into the parent application. What I have now is a C app that can call Python, which can invoke C code in another library apart from my app. Forgive my terrible ASCII UML: +---+ +--------+ +---+ | C |--->| Python |--->| C + +---+ +--------+ +---+ When what I really want is +---+ +--------+ | C |--->| Python | | |<---| | +---+ +--------+ I understand how to register a Python object at runtime in C so that C can call back into an object that was created by a user after my app was written. What I would like to do is go the other way: be able to register a C function with Python so that it can call C back at runtime. Actually, that's a bit misleading. I do not need to access C functions written after my embedding/extending work is done. I have a fixed C interface that I want Python to interact with. What I want, I guess, is a way to embed Python, and give the embedded Python access to some of my C functions. So... how would I go about this? Is there a way to compile my entire app so that it behaves like an extension to the embedded Python interpreter? Or do I need to extend out into a .dll that hunts down the parent app? Thank you for your time. Oh, for simplicity, here's a example code for us all to share. This is just trivial examples of what I want to do, if my whole approach is wrong (like returning a char* instead of modifying a char* argument) let me know. Imagine I have C++ code to get the ID number of the current document, and to set the name of a given document. I also have a button named "Foo" on the App that runs the python code "UserMacroFoo" when it is clicked. UserMacroFoo will try to set the name of the active document to "Foo!": // C++ code: int GetActiveDocument( void ); void SetDocumentName( int DocID, char* Name ); //... void Foo_OnClick() { PyObject *pModule, *pFunction, *pResult; pModule = PyImport_ImportModule( "UserMacros" ); pFunction = PyObject_GetAttrString(pmod, "UserMacroFoo"); pResult = PyEval_CallObject(pfunc, NULL); } # Python code def UserMacroFoo(): i = App.GetActiveDocument() App.SetDocumentName( i, "Foo!" ) Thank you in advance, -dB -- David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From mlh at idi.ntnu.no Thu Oct 25 18:02:43 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Fri, 26 Oct 2001 00:02:43 +0200 Subject: Question: CPython References: <3BD79BBC.B2FA669B@hotmail.com> Message-ID: <9ra264$oeu$1@tyfon.itea.ntnu.no> "Lucio Torre" wrote in message news:mailman.1004036427.3889.python-list at python.org... > scott wrote: > > > > >Sean 'Shaleh' Perry wrote: > > > >>On 24-Oct-2001 K?roly Ladv?nszky wrote: > >> > >>>What is CPython and where is it available? > >>> > >>>Thanks for any help, > >>> > > > > > > > >>There is > >>a new thing called 'JPython' which is a python implementation in Java > >> > > > > > >Called 'Jython' now. Its predecessor was JPython. > >http://www.jython.org > > > And python is now called Cython. :) I was actually thinking about writing an XML-dialect of Python called Xython... But when I tried to create the SourceForge project, it was taken (by another XML-dialect of Python... What a coincidence ) Oh, well. I've got better things to do anyway. -- Magnus Lie Hetland http://hetland.org From tdelaney at avaya.com Tue Oct 30 19:24:29 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 31 Oct 2001 11:24:29 +1100 Subject: adding items from a text file to a list Message-ID: > From: toflatpy2 at oaktown.org [mailto:toflatpy2 at oaktown.org] > > I have a text file with a list of data items. > > ex: > > pickle (fruit or veggie?) > pickled eggs (just plain strange) > seinfeld (funny show) > yada yada (yada) > > What I want to do is add each item in the file to a python list. The > thing that is eluding me is how to leave out the comments. I need it > to scan in the item, skip anything in parenthsis then proceed to the > next line. You will need to read the spec carefully. Does it state that anything on a line following an open parenthesis is part of the comment, or is it only things within parentheses? These have two different solutions. 1. Everything after the start of a comment is part of the comment (or guaranteed that there is nothing on a line after a comment). Find the start of the comment, then discard anything on the line from that point on. POssibly trim any excess whitespace from the line. 2. Only things within the comment delimiters are comments. Find the start of a comment, then the end of that comment. Add everything before the comment to everything behind the comment. Repeat until no comments are found in the line. Possibly need to remove excess whitespace. The implementation is up to you. Probably the simplest option would be to use string.find(), followed by slicing the string at the appropriate points. Tim Delaney From martin.franklin at westgeo.com Thu Oct 25 05:55:02 2001 From: martin.franklin at westgeo.com (Martin Franklin) Date: Thu, 25 Oct 2001 10:55:02 +0100 Subject: multipart mime References: <9r8lur$7oqsi$1@hades.rz.uni-sb.de> Message-ID: <9r8nfl$7g6$1@mail1.wg.waii.com> Uwe Schmitt wrote: > Hi, > > I'm looking for a module which is suited to handle multi-part > mime-mails. Is somehting like this available ? I browsed the > module-index on www.python.org, but did not find anything > apropriate. > > Greetings, Uwe. > http://sourceforge.net/projects/mimelib/ now called email and part of standard python 2.2 From nhodgson at bigpond.net.au Tue Oct 30 21:07:19 2001 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 31 Oct 2001 02:07:19 GMT Subject: PythonWin 2.1 saving bugg??? References: Message-ID: Tim Gahnstr?m: > I were in the testing phase of a program I had made (actually a lab report) > . When PythonWin 2.1 for some reason didnt want to save my file again. I > tried saving it under a different name but it didnt work either, it just > ended up with a text saying > saving... > in the bottom grey field. > I had just done minor changes since last save so I didnt really consider it > a big problem. But after (abruptly and with scandisk...) having restarted > the computer I came back and found that my program wasn't ther at all! > anymore. > Just the compiled file. The textfile seemed pretty much deleted :-( Have a look in the temporary directory. There should be a subdirectory called bak containing backups made by PythonWin. The location of the temporary directory is normally set by the TEMP or TMP environment variable. If you can't find this then use the search files command to search "Local harddrives" for the file name you were using. Did you run out of disk space? That is one of the best ways to provoke behaviour like this. Neil From urner at alumni.princeton.edu Sun Oct 21 02:23:59 2001 From: urner at alumni.princeton.edu (Kirby Urner) Date: Sat, 20 Oct 2001 23:23:59 -0700 Subject: Beginner COM problem (Windows) Message-ID: I've written (actually downloaded [1]) a COM object in Visual FoxPro 5. I'd like Python to be its client. The object is registered, and when I write a macro in Excel, using VBA, the behavior works as advertized. Here's the VBA from Excel: Sub test() '-- Declare variable to hold the reference Dim VFPOLE As Object '-- Assign object reference to variable Set VFPOLE = CreateObject("VFP_OLE.VFP_OLE_Server") VFPOLE.FoxCommand _ ("Wait Window 'Executing Query' Nowait") VFPOLE.FoxCommand ("Select * From G:\VFPAPPS\PATS\ACC\CVL1 " & _ "Into Table TestAll3") VFPOLE.FoxCommand ("CLOSE ALL") VFPOLE.FoxCommand ("Wait Clear") '-- Release the reference Set VFPOLE = Nothing End Sub However, when I try to do something similar in Python, with win32all installed, the following occurs: >>> import win32com.client >>> vfpole = win32com.client.Dispatch("VFP_OLE.VFP_OLE_Server") >>> vfpole >>> vfpole.FoxCommand ("Wait Window 'Executing Query' Nowait") Traceback (most recent call last): File "", line 1, in ? vfpole.FoxCommand ("Wait Window 'Executing Query' Nowait") File "D:\Program Files\Python21\win32com\client\dynamic.py", line 432, in __getattr__ raise pythoncom.com_error, details com_error: (-2147352567, 'Exception occurred.', (99, 'Visual FoxPro for Windows', 'Procedure canceled.', None, 0, 0), None) Any ideas? I tried setting _unicode_to_string_ to 1, but that didn't make any difference. I actually get an error the second I hit a parenthesis key after vfpole.FoxCommand -- unless I move the (argument) out a space -- legal. That postpones the error message until after I hit enter. That behavior tells me something, but I'm not sure what. Pls CC: urnerk at qwest.net and/or urner at alumni.princeton.edu Muchas gracias, Kirby From BrianQ at ActiveState.com Mon Oct 15 17:52:23 2001 From: BrianQ at ActiveState.com (Brian Quinlan) Date: Mon, 15 Oct 2001 14:52:23 -0700 Subject: FW: [Python-Dev] conditional expressions? In-Reply-To: Message-ID: <002101c155c3$ac2b0a10$b503a8c0@activestate.ca> Tim wrote: > If you don't use parens, they're equivalent to > > ]*** ) 3fo?rkl Tim, please stop using idiomatic Perl in your examples - it's hard for some of us to follow. Cheers, Brian From paulsid at home.com Wed Oct 24 21:15:35 2001 From: paulsid at home.com (Paul Sidorsky) Date: Wed, 24 Oct 2001 19:15:35 -0600 Subject: help with something that ought to be simple References: Message-ID: <3BD767B7.E8B04E10@home.com> Matthew Nobes wrote: > def del_2(rho,input,output): > > output=[[0,0,0,0]] First off, output is unnecessary as a parameter since you return it later. There's no need to provide output as a "buffer" like in other languages. In fact you can't do this; the assignment to output will just rebind the name output to something else without affecting the name of the original object (whatever was passed in). Simply do output = del_2(a, b) and it will work fine. > > for i in input: > i[rho-1]=1 Here's a problem, though it's not the one described. You are working on the items of input itself. Try printing input after this loop. Notice how it has changed! And unlike above, this time you're changing the items of i so the changes WILL make it back to the original object! If you're throwing away input (e.g. replacing it with output) this won't matter but otherwise you'll want to use a copy of input: for i in list(input): or for i in input[:]: Either makes a copy of input and operates on that. (I prefer the former but I think it only works in 2.x Python versions; the latter works in earlier ones.) It's probably better coding style to make the copy and avoid changing the input even if you won't be using it later, because you never know when you'll want to change your mind. > output.append(i) This is what's causing the described behaviour. It should be: output.append(list(i)) or output.append(i[:]) In Python everything is done by references so you are appending a reference to the old object to your list rather than a new object. Again you need to append a copy to avoid altering the original later. > temp.append(i) > output.append(i) These should be similarly altered as above. > Now I did this to temp. So I should be able to now append this > to output and my result *SHOULD* be > [[0,0,0,0],[0,1,0,0],[1,1,0,0],[1,0,0,0]] The change I just described does indeed produce this output. > but instead the operation on temp also gets preformed on output > and I get > [[0,0,0,0],[0,1,0,0],[1,0,0,0],[1,0,0,0]] If you're not convinced as to why this happens and why the above fixes it, try this: a = [0,0,0,0] b = [0,1,0,0] output = [a, b, a] a[0] = 1 # Changes both a and items 0 and 2 of output output[0][1] = 2 # Also changes items 0 and 2 of output & a. a = [0,1,1,1] # Now a is different but items 0 and 2 of output # still exist and are the same old list. This behaviour is annoying at first but once you get used to it you can exploit it for a lot of neat tricks. Hope that helps. -- ====================================================================== Paul Sidorsky Calgary, Canada paulsid at home.com http://members.home.net/paulsid/ From guido at python.org Fri Oct 26 10:19:49 2001 From: guido at python.org (Guido van Rossum) Date: Fri, 26 Oct 2001 14:19:49 GMT Subject: Integer coercion and 2.2 Type/Class changes References: Message-ID: com-nospam at ccraig.org (Christopher A. Craig) writes: > Consider the following Python 2.2 code: > > >>> class foo(int): > ... def __init__(self, n=0): > ... self=n This __init__ is a total no-op. The assignment to self is a local variable rebinding that has no effect on the object that was initially represented by self. In addition, since int is an immutable type, you can't affect the value in __init__; you must use __new__ instead. Your class works despite all that, because the default __new__ constructor does the right thing. :-) > ... def bar(self): return self+6 > ... > >>> t=foo(4) > >>> t.bar() > 10 > >>> type(t) > > >>> type(t+6) > > >>> type(t+t) > > > This is the expected result, but probably often not the desired one. > So my question is, is there some way, without redefining all of > the numeric operations, to define a subclass that recasts all numeric > operations to it's own type? No, you'll have to redefine all operators. --Guido van Rossum (home page: http://www.python.org/~guido/) From tjreedy at home.com Thu Oct 4 09:34:50 2001 From: tjreedy at home.com (Terry Reedy) Date: Thu, 04 Oct 2001 13:34:50 GMT Subject: Mutable default values for function parameters References: <7da8d8f8.0110040056.42443bb@posting.google.com> Message-ID: <_zZu7.97779$5A3.27836734@news1.rdc2.pa.home.com> "sebastien" wrote in message news:7da8d8f8.0110040056.42443bb at posting.google.com... > For sample I have tried to do something like Eiffel loop variant: > > def variant(data, old_data=[None]): > st = (data <> old_data[0]) > old_data[0] = data > return st > > for i in range(5): > assert variant(i) > print i > while i>0: > assert variant(i) > i -= 1 > > This fail because old_data remain the same between the last loop in > the for and the first one in the while. Call function with value that will result in reinitialization of static. For above, insert 'variant(None)' before while loop to reinitialize old_data. > I've seen the same problem in > http://www-106.ibm.com/developerworks/library/l-pycon.html?n-l-9271 > > def randomwalk_static(last=[1]): # init the "static" var(s) ... > The first call of print_numl work fine, but later calls will fail > because 'last' parameter will always contain a number <0.1 ... > Or maybe, someone could give me an obvious way to solve this kind of > problems? 1. Add explicit reinitialization code to function. For randomwalk_static(): def randomwalk_static(restart=0, last = [1]): if restart: last = [1] return ... randomwalk_static(1) #reinits and nothing else ... This requires second argument, whether defaulted (as above) or not (as in variant()) since assigning explicit value to mutable arg blocks access to behind-the-scenes default value. 2. Make the static var global (ie, public instead of private) so you can access it from outside the function to reinitialize. 3. Rewrite function of __call__ method of class that keeps static vars as instance attributes. This allows, in this case, multiple randomwalks to be going at once. No need to revise Python 8-). Terry J. Reedy From drew at level3.net Mon Oct 8 15:51:13 2001 From: drew at level3.net (Drew Fisher) Date: Mon, 8 Oct 2001 13:51:13 -0600 Subject: Newbie: problem comparing values In-Reply-To: <873d4tli9i.fsf_-_@yahoo.com>; from jeremy@bears on Mon, Oct 08, 2001 at 08:22:17PM -0500 References: <9pqe9i$h0q$1@verence.demon.co.uk> <873d4tli9i.fsf_-_@yahoo.com> Message-ID: <20011008135113.E6727@level3.net> > Hi, > > I'm trying to set up a script to check to see whether the person running > the script is root or not. If they are, I want to make it exit > immediately. This is the code that I have that I'm trying to use: > > > user = os.popen("whoami").read() > if user == "root": > print "You are logged in as root" > else: > print "You are not logged in as root." > > > The problem is that each time, no matter if it's root or not that's > running the script, it always says "You are not logged in as root." I > know that this has to be something small that I'm missing, and please > forgive me for asking such a "simple" question, but I've only been at > this for a couple of days (with python. I have a few months of > experience with bash scripts). I've checked about every resource I can > think of and I still can't figure out what I'm doing wrong. > > Thanks in advance for your help, > Jeremy > > -- > http://mail.python.org/mailman/listinfo/python-list When you use the read() command, you are forgetting that the newline character is present in the output: >>> import os >>> user = os.popen("whoami").read() >>> user 'drew\n' >>> You can solve your problem by either a) stripping of the newline character at the end of the output user = os.popen ("whoami").read().strip() or b) comparing with the "\n" if user == 'root\n": print "You are logged in as root" else: print "You are not logged in as root." Hope this helps Drew -- Hell is other people's Perl. -- Linux Journal From richard at bizarsoftware.com.au Sun Oct 14 21:08:45 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Mon, 15 Oct 2001 11:08:45 +1000 Subject: Python web client anyone? In-Reply-To: <01101510574220.11044@ike> References: <7xitdiv4sb.fsf_-_@ruckus.brouhaha.com> <7xu1x1px4d.fsf@ruckus.brouhaha.com> <01101510574220.11044@ike> Message-ID: <01101511084521.11044@ike> On Monday 15 October 2001 10:57, Richard Jones wrote: > My SimpleDOM module will do this. Here's some off-the-top-of-my-head usage: > >>> import SimpleDOM, urllib > >>> page = urllib.urlopen('http://www.w3c.org/').read() > >>> dom = SimpleDOM.SimpleDOMParser() > >>> dom.parseString(page) > >>> len(dom.getByName('a')) Sorry, bad cutnpaste there. There's a valid example in the module docstring though. Richard From ignacio at openservices.net Mon Oct 15 21:38:28 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Mon, 15 Oct 2001 21:38:28 -0400 (EDT) Subject: newbie printing question In-Reply-To: <9qg0l9$5hp$1@slb3.atl.mindspring.net> Message-ID: On Mon, 15 Oct 2001 adina_levin at mindspring.com wrote: > I'd like to create a string with the current date and time. I've got the > mxDateTime library, so far so good. > > print mxDateTime.now() will generate the date and time to the screen. write > will send it to a file. > > But how can I assign this to a string? > > I will be most thankful and embarrassed to hear the answer to this question. > It oughta be obvious! Use time.localtime() along with time.strftime(). -- Ignacio Vazquez-Abrams "As far as I can tell / It doesn't matter who you are / If you can believe there's something worth fighting for." - "Parade", Garbage From thomasNO at SPAM.obscure.dk Sat Oct 20 07:48:27 2001 From: thomasNO at SPAM.obscure.dk (Thomas Jensen) Date: Sat, 20 Oct 2001 11:48:27 GMT Subject: struct module References: <3bd0f13e$0$27332$afc38c87@news.optusnet.com.au> Message-ID: "nobody" wrote in news:3bd0f13e$0$27332$afc38c87 at news.optusnet.com.au: > Can someone tell me what I'm missing here? > >>>> struct.calcsize('H') 2 struct.calcsize('B') 1 >>>> struct.calcsize('HB') > 3 > > wait for it... > >>>> struct.calcsize('BH') > 4 > > ? Try this: >>> struct.calcsize('BH') 4 >>> struct.calcsize('=BH') 3 If I'm reading the docs correctly, this should be standard across platforms. -- Thomas Jensen From uwe at rocksport.de Thu Oct 25 05:27:55 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 25 Oct 2001 09:27:55 GMT Subject: multipart mime Message-ID: <9r8lur$7oqsi$1@hades.rz.uni-sb.de> Hi, I'm looking for a module which is suited to handle multi-part mime-mails. Is somehting like this available ? I browsed the module-index on www.python.org, but did not find anything apropriate. Greetings, Uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From gbreed at cix.compulink.co.uk Thu Oct 25 10:17:35 2001 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Thu, 25 Oct 2001 14:17:35 +0000 (UTC) Subject: Conditional expressions (again) References: Message-ID: <9r96tv$m26$1@thorium.cix.co.uk> In article , michael at rcp.co.uk (Michael Abbott) wrote: ... > Well, I don't really think there's a great deal of argument about the > syntax. There are, as far as I'm aware, two live proposals for syntax: > > (1) x = if a: b elif c: d else: e > or > (2) x = if a then b elif c then d else e I don't remember "elif" being generally supported. Or a good argument against x = b if a else (d if c else e) unless you count "P*rl has something like that" as a good counter-argument. > I seem to recall that Guido stated that he'd had a go at implementing > syntax 2 (which I prefer if we're willing to pay the price of a new > keyword 'then'), and that it worked well enough with the Python syntax. No "elif", and has to be parenthesised if it's used as a statement. > The main argument, really, seems to be about whether this is useful. Yes, there's that one as well. Graham From avdi at avdi.org Tue Oct 16 19:22:10 2001 From: avdi at avdi.org (Avdi B. Grimm) Date: 16 Oct 2001 19:22:10 -0400 Subject: python library path on Debian LInux Message-ID: <1003274531.4259.9.camel@mycroft> I'm using Python on a Debian machine, and I've installed both the python-1.5 and the python2 packages. I prefer to use python2. Unfortunately, the way the Debian packages are arranged, many of the additional libraries available for python (such as PyGTK) are as yet only packaged for Python1.5. Apparently libraries packaged for different Python versions are installed in different directories, and each python executable only sees the libs that were packaged for it. Now, as I understand it, Python2 shouldn't have any difficulty using the python1.5 versions of PyGTK, wxPython, and other such libs. (Correct me if I'm wrong). My question is, how can I make the python2 executable "see" the python1.5 lib dirs, in a way that is effective system-wide and does not have to be specified on the command line every time python is executed? thanks, -Avdi Grimm From use-net at schabi.de Thu Oct 18 04:28:00 2001 From: use-net at schabi.de (Markus Schaber) Date: Thu, 18 Oct 2001 10:28:00 +0200 Subject: Apologise (was: Re: IF STATEMENTS) References: <20011018002005.53f58ef2.use-net@schabi.de> Message-ID: <20011018102800.11c71435.use-net@schabi.de> Hi, On Thu, 18 Oct 2001 00:20:05 +0200, Markus Schaber wrote: [...] I have to apologise for this message. At first, it was intended to go to per mail only. And second, it seems that some news readers have problems with MIME-signed messages. This messages should _not_ display as empty messages with attachment as some people have told me. In my eyes, they look conform to the standards, and the first part with type text/plain is the content. Non-MIME aware readers may show three lines of strange text before the message, and MIME-aware readers should show my message as content and the signature as attachment. Nevertheless, I won't send any signed messages here again, as long as this issue is not resolved. markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From l0819m0v0smfm001 at sneakemail.com Thu Oct 11 17:39:46 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Thu, 11 Oct 2001 21:39:46 GMT Subject: Does Python license permit embedding in commercial product ? References: <8a12e538.0110111318.76668cf3@posting.google.com> Message-ID: <3BC5DC6F.1050601@sneakemail.com> Russell Turpin wrote: > This is sort of the opposite case of wanting to sell a program > written in Python, which clearly is allowed. Consider a > commercial product that needs a scripting language. One > obvious way to achieve this, which I'm sure all here would > encourage, is to (a) embed Python in the product, then when > a script for the product is invoked to (b) create a code object > from the script, (c) bind Python variables to appropriate > internal state, (d) execute the code object, and (e) update > internal state from Python variables. > > All of this can be done without modifying Python's source > code. (I hope. I haven't actually tried this, but the principle > seems clear.) The question is whether doing so infringes on > Python's license, given that the product is commercially sold, > and maybe even some of the scripts subsequently provided. My > naive reading is that this is OK. But I thought I would seek > the broader opinion here. > > (Obviously, if we do extend Python in any way, we'll release > *that* code. But that's not currently in the plans.) > > Russell > Yes. >From the FAQ: "In particular, if you honor the copyright rules, it's OK to use Python for commercial use, to sell copies of Python in source or binary form, or to sell products that enhance Python or incorporate Python (or part of it) in some form. I would still like to know about all commercial use of Python!" So you're okay even if you end up modifying Python somehow to fit your application. Joshua From sholden at holdenweb.com Tue Oct 2 12:27:02 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 2 Oct 2001 12:27:02 -0400 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> Message-ID: <_Rlu7.21425$ib.329102@atlpnn01.usenetserver.com> "Dale Strickland-Clark" wrote ... > "Steve Holden" wrote: > [ ... ] > >1. Use names with a special prefix for the database fields, then you can > >just test the attribute name using beginswith() or similar to determine > >whether it's a database filed. > > > >2. Have objects store database fields inside another object (such as a > >DatabaseTuple), so instead of assigning > > > > object.dbfield = value > > > >you assign > > > > object.db.field = value > > > >This localises the database fields and means you don't need __setattr__ on > >the object itself. > > [ ... ] > > Thanks for sticking with this so far. > > The problem isn't with handling the database assignments. It's the > fact that all instance assignments (self.anything) has to go through > the same code. This is such an ugly overhead. > > Throughout the class, there are dozens of uses of instance variables > which are forced through this code. I don't want to know about them. > > I guess I'd like to explicitly declare which attributes are part of > the public face of the class and which are not. > > I assume my approach is as good as any. > Well, the advantage of centralizing the database fields as attributes of a contained object is that you then only need to monitor bindingd to the attributes of that object, so the containing object wouldn't need a __setattr__() implementation. If you can't do that then I guess you're stucj with something similar to your current approach. regards Steve -- http://www.holdenweb.com/ From joost_jacob at hotmail.com Sun Oct 28 07:04:29 2001 From: joost_jacob at hotmail.com (J.Jacob) Date: 28 Oct 2001 04:04:29 -0800 Subject: Why doesn't this simple Curry-like implemention work? References: Message-ID: <13285ea2.0110280404.1216a5c4@posting.google.com> "Michael R. Head" wrote in message news:... > # for some reason this function doesn't work in python 1.5.2. > def curry(f, p): > return lambda x: apply(f, p, x) > I'm supposing that lamda isn't storing > the reference to its inputs -- which it seems it should -- is this > correct? > mike Try this: def curry(f, p): return lambda x, ff=f, pp=p: apply(ff, pp, x) But i wonder if it does what you want Joost From stojek at part-gmbh.de Wed Oct 31 08:01:08 2001 From: stojek at part-gmbh.de (Marcus Stojek) Date: Wed, 31 Oct 2001 13:01:08 GMT Subject: newbie, relative path Message-ID: <3bdff425.12589703@news.easynews.net> Hi, 2 little questions.: 1. I have a small script that uses an .ini file for configuration. How can I open the file config.ini that is in the same dir as the script itself? (script dir is changing) config=open("?????config.ini","r") 2. I am pretty sure that I have read somewhere that it is possible to link the Python Interpreter and everthing together and make a binary executabel (WIN) from the script. I don't find this in "Programming Python" or "Learning Python" any more. Is it possible and where can I find a description? Thanks again. Marcus From lac at strakt.com Thu Oct 25 09:19:22 2001 From: lac at strakt.com (Laura Creighton) Date: Thu, 25 Oct 2001 15:19:22 +0200 Subject: howto combine regex special sequences? In-Reply-To: Your message of "Wed, 24 Oct 2001 17:01:22 PDT." <20011025000122.15639.qmail@web10304.mail.yahoo.com> References: <20011025000122.15639.qmail@web10304.mail.yahoo.com> Message-ID: <200110251319.f9PDJM0W026690@ratthing-b246.strakt.com> > Greetings, > > I'm trying to compile a regex so that I can test whether a string > contains characters other than alphanumeric or whitespace. > > I'm currently using this which seems to work: > > regex = re.compile(r'[^a-zA-Z0-9_ \t\n\r\f\v]') > > I'd like to use the special sequences "\W" and "\S" for brevity > however. How can I rewrite the above regex using them instead? > > I thought the following would work, but it doesn't: > > regex = re.compile(r'\W\S') > > Another question: is there an easier/faster way to test whether a > string contains characters other than alphanumeric or whitespace > without using the re module, or am I on the right track? > I've been up for 36 hours, but the expression you are looking for is r = re.compile('[^\w\s]') But you don't want to do that. Z is the last letter of the alphabet in New Zealand, but ? is the last letter here in Sweden. Use the string methods instead. Laura Creighton From arturs at iidea.pl Thu Oct 4 15:13:30 2001 From: arturs at iidea.pl (Artur Skura) Date: 4 Oct 2001 19:13:30 GMT Subject: QNX Support References: <9phqv4$bh2$1@bcarh8ab.ca.nortel.com> Message-ID: Don Parker wrote: > I can get a port of 1.5.2 from QSSL but I was wondering if anyone had done a > more recent release port (e.g. 2.x) of Python to QNX Neutrino (aka QNX 6.0). http://sourceforge.net/projects/pyqnx/ But Tcl/Tk didn't want to compile at first. Regards, Artur -- http://www.wolneprogramy.org From sill at optonline.net Fri Oct 19 11:50:33 2001 From: sill at optonline.net (Andrei Kulakov) Date: Fri, 19 Oct 2001 15:50:33 GMT Subject: Dictionary from list? References: Message-ID: On Fri, 19 Oct 2001 03:42:57 GMT, Jim Correia wrote: > Suppose I have a list with an even number of elements in the form > > [key1, value1, key2, value2, key3, value3] > > If I were writing Perl I could write > > my %hash = @array; > > and it would do the coercion for me, and build the hash appropriately. > > I'm a python newbie. I know how to do it "by hand" with a loop, but is > there a built in conversion operater that will let me do something > simply like the perl assignment? > > Jim You know, this sort of thing comes up often - X is a built-in feature in perl, why do I have to do it manually in python? I think this is a justified design decision - there's simply too many built-in things perl does. You can't remember all of them and if you look at someone else's perl program you have to scratch your head a lot. Python is small, lean and clean, and that's one of the best things about it. - Andrei -- Cymbaline: intelligent learning mp3 player - python, linux, console. get it at: cy.silmarill.org From mmealman at tarsis.org Wed Oct 10 10:31:49 2001 From: mmealman at tarsis.org (Mark) Date: 10 Oct 2001 09:31:49 -0500 Subject: Why so few Python jobs? (and licenses) References: <7x1ykd7es3.fsf@ruckus.brouhaha.com> <7xn13060xv.fsf@ruckus.brouhaha.com> Message-ID: In article <7xn13060xv.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Cliff Wells writes: > > leisure, sure, that's a gesture of goodwill. If I spend $5000 worth > of development time writing and releasing a feature for GIMP that I > could have had instead by paying $500 for a retail copy of Photoshop, > the GIMP author has (at least monetarily) benefitted from my effort > more than I've benefitted from his. (Note: that GIMP example is made > up, not something that really happened to me). The GIMP author isn't benefiting, so much as the community is. Even if the author took all that code, bundled it up and went commercial, the GPL ensures that your contribution and the origional work it contributed to remain in the public. Short term, going commercial may win the author some money, but longer term it's a dead end. The public version will likely exceed the commercial port in features and stability. I understand how it might be distasteful that the origional author might take your work and earn profit off of it. But if the alternative is that once you GPL software you lose all copyrights over it once anyone submits a patch, then there's every reason not to release your software under the GPL. I haven't read the GPL in awhile, but it seemed that the intent was that a software author DID keep his copyright on any software he GPL'd. It was win/win. Win for the author: he keeps his copyright, no one can take his software away from him if it's GPL. Win for the community: they gain his software, and not even the author can take it away from them. Right now I think the community is operating on a system of respect. Core authors are respecting patch submitters and not going commercial. But as more and more corps start using GPL resources I think we're going to have to define this aspect of the GPL a little better. If we don't, then I don't see how we're going to convince authors to use it on their software. -Mark -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From shalehperry at home.com Wed Oct 10 15:50:57 2001 From: shalehperry at home.com (Sean 'Shaleh' Perry) Date: Wed, 10 Oct 2001 12:50:57 -0700 (PDT) Subject: Newbie - unslicable type error etc In-Reply-To: <45956635.0110101132.245dcbf6@posting.google.com> Message-ID: > I have a large (7MB or so) file of raw hex data (ie values E{0,255}) > from which I need to identify a given byte sequence that occurs about > 800 000 times within the file. Once I have found these data fragments > I need to extract them to another file. My problem is that while I > have been able to open the file and use read(10) etc to look at the > file, I am unable to process it - I tried using input[23:67] (where > 'input' is the name of the file I am working with) but python > complained that I was using an unslicable type. > slices work on sequences, your variable 'input' is a file handle (like a FILE * in C). > So my question is how do I my file into a format where I am able to > use RE's in python to play with it? When I input.read(10) it looks > like: > > x05\x0A\x45\xA1... > > That is raw hex data. All suggestions most welcome. > http://py-howto.sourceforge.net/regex/regex.html is the regex howto. It may be of help. From paullim at starhub.net.sg Wed Oct 17 08:21:39 2001 From: paullim at starhub.net.sg (Paul Lim) Date: Wed, 17 Oct 2001 20:21:39 +0800 Subject: Help: HTMLParser cannot parse some web pages? Message-ID: <3BCD77D2.EBFB2D98@starhub.net.sg> Hi, I am a newbie in Python. I hope the guru could advise me on the following I am trying to extract the links in html file. My code is shown below: The code works fine. But I just want to understand more about this HTMLParser module. Apparently, there are some webpages where I cannot extract the links. But I really don't understand why? An example is http://www.admissions.rmit.edu.au/about/index.html Is there certain limitation in this HTMLParser? For example, is it that it cannot extract from certain kind of web pages. If so, which kind? Thank you very much for your help. Sincerely Paul "To extract the links in a page." # To open a url and return url handler try: linkHandler = urllib.urlopen(link) except IOError: print "Unable to open url!" # Extract link from the HTML file and stored in anchorlist try: parser = HTMLParser(NullFormatter()) parser.feed(linkHandler.read()) except: print "Unable to extract!" pass From michael at stroeder.com Tue Oct 30 15:37:18 2001 From: michael at stroeder.com (Michael =?iso-8859-1?Q?Str=F6der?=) Date: Tue, 30 Oct 2001 21:37:18 +0100 Subject: BNF parsing in Python References: <3BDDA9D8.972BAEA2@stroeder.com> <7x668xhx3j.fsf@ruckus.brouhaha.com> Message-ID: <3BDF0F7E.4E2DCFEF@stroeder.com> Paul Rubin wrote: > > That sounds like you want an asn.1 parser. I think a few are around. No I don't want to compile ASN.1 syntax for this task. It has to parse just strings describing a LDAP schema element according to a hopefully well-defined BNF. Ciao, Michael. From tnaran at direct.ca Fri Oct 5 11:00:30 2001 From: tnaran at direct.ca (Travers Naran) Date: Fri, 5 Oct 2001 08:00:30 -0700 Subject: Worldwide English (was Re: Python is better than free (was Re: G References: Message-ID: <9pkhu90s0h@enews2.newsguy.com> "Mikael Olofsson" wrote in message news:mailman.1002262146.25244.python-list at python.org... > > On 05-Oct-2001 Steve Holden wrote: > > Well, I could even take exception to the word "it", since there are many > > different Englishes. > > The following is hearsay: > > An English royalty is said to have claimed "English is not a worldwide > language - bad English is." The proper term for a singular member of the English royalty is 'royal'. "... is said to have claimed..." is better written as "...supposedly claimed.." The passive voice is poor style. The '-' is properly written as '--' with no spaces on either side. So, your revised statement would be: An English Royal supposedly claimed: "English is not a worldwide language--bad english is." :-) I now return you to our regularly scheduled GPL war... From tjg at hyperlinq.net Wed Oct 17 01:14:39 2001 From: tjg at hyperlinq.net (Timothy Grant) Date: 16 Oct 2001 22:14:39 -0700 Subject: Further help w/ readline needed (was:Re: Past command buffer gone in interpreter?) In-Reply-To: References: Message-ID: <1003295680.1357.19.camel@reepicheep> Having recently been through this, you may want to try replacing the -ltermcap with -lncurses and see if that resolves your problem. It did for me. On Tue, 2001-10-16 at 17:18, Tod Fox wrote: > Ignacio Vazquez-Abrams wrote: > > You'll need to install the readline-devel RPM. > > I made sure readline was installed on my system, and then installed the > readline-devel RPM without any problems. I uncommented the readline > entry in Modules/Setup, but when I run make I get the following error: > > ar cr libpython2.1.a Modules/gcmodule.o Modules/threadmodule.o > Modules/signalmodule.o Modules/posixmodule.o Modules/_sre.o > Modules/readline.o Modules/arraymodule.o Modules/mathmodule.o > Modules/timemodule.o Modules/operator.o Modules/_testcapimodule.o > Modules/pwdmodule.o Modules/grpmodule.o Modules/audioop.o > Modules/imageop.o > ranlib libpython2.1.a > gcc -Xlinker -export-dynamic -o python \ > Modules/python.o \ > libpython2.1.a -lpthread -ldl -lutil -lreadline > -ltermcap -lm > /usr/bin/ld: cannot find -ltermcap -- Stand Fast, tjg. Timothy Grant -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 240 bytes Desc: not available URL: From sorr at rightnow.com Wed Oct 10 10:34:47 2001 From: sorr at rightnow.com (Orr, Steve) Date: Wed, 10 Oct 2001 08:34:47 -0600 Subject: Spewing SQL query resultset to HTML table... Message-ID: Problem solved. I'm over the SQL column alias / HTML column header show stopper... full speed ahead with Python. Thanks Martin Franklin, Steve Holden and list! > KEY QUESTION: How do I capture the column aliases and display them as > headers in an HTML table? From peter at engcorp.com Mon Oct 29 00:58:32 2001 From: peter at engcorp.com (Peter Hansen) Date: Mon, 29 Oct 2001 00:58:32 -0500 Subject: AskMerlin, your AI expert system guru oracle advisor References: <3BDC649F.6EB6680B@earthlink.net> <3BDC9411.18C441FA@earthlink.net> Message-ID: <3BDCF008.D6487FAE@engcorp.com> Ron Stephens wrote: > > x = (self._getGoogleHits(self.question + ' ' + reply)) > y = (self._getGoogleHits(reply)) > > I am not sure what the significance of the (self.question + ' ' +reply) is. > Specifically, what is the significance of the two quotation marks in the > middle? Doe sit just ad a space between the two strings (question and > reply), or does it do something else? Python is exceptionally friendly about this kind of question when you use the interactive prompt. It's worth spending a moment getting used to it: >>> someString = 'this is a test' >>> reply = 'and a reply' >>> someString + reply 'this is a testand a reply' >>> someString + ' ' + reply 'this is a test and a reply' >>> '%s %s' % (someString, reply) 'this is a test and a reply' Enjoy! :) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From salemail at dial.pipex.com Thu Oct 18 03:53:43 2001 From: salemail at dial.pipex.com (Kevin D) Date: 18 Oct 2001 00:53:43 -0700 Subject: Conditional Expressions don't solve the problem References: Message-ID: Hi Dale, Dale Strickland-Clark wrote in message news:... > > > >Something like: > > > >while foo != terminating_condition; given foo = some_long_expression: > > body_of_loop() > > > >or maybe "where": > > > >while foo != terminating_condition; where foo = some_long_expression: > > body_of_loop() > > > > Sorry but these don't work for me. Given that foo is still quoted > twice, it doesn't really buy you much. It's spelling 'some_long_expression' twice that was the 'duplication problem' I was addressing. Trying to avoid spelling 'foo' twice (eg, by overloading a single expression to be an assignment _and_ a test) falls into "saving keystrokes for the sake of it" territory, which is what Guido has already said he will not consider. My suggesting is not trying to "save keystrokes" - it's trying to save duplication of an expression that doesn't _need_ to be written twice. This is one of the arguments that got augmented assignment into the language. Regards, Kev. From msp at tpg.com.au Mon Oct 8 06:18:43 2001 From: msp at tpg.com.au (Michael Palm) Date: Mon, 08 Oct 2001 18:18:43 +0800 Subject: += doesn't work in python cgi's Message-ID: <3BC17D83.A4EEED81@tpg.com.au> I have a strange error in that += doesn't seem to work in a cgi program test.py: #!/usr/bin/env python print "Content-type: text/html\n\n" j = 1 j +=1 print " j is %d" % j works fine with python test.py but as a cgi gives j += 1 ^ SyntaxError: invalid syntax any ideas?? From gh_pythonlist at gmx.de Wed Oct 24 19:27:03 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 25 Oct 2001 01:27:03 +0200 Subject: urllib.urlopen + https = all threads locked? In-Reply-To: ; from usenet@jeffjohnson.net on Wed, Oct 24, 2001 at 02:51:08PM -0700 References: Message-ID: <20011025012702.A1788@lilith.hqd-internal> On Wed, Oct 24, 2001 at 02:51:08PM -0700, Jeff Johnson wrote: > I have a multi-threaded application that makes calls > urllib.urlopen("https://yadayada.com"). Until the call completes (or > maybe the following read) all other threads just freeze. They > continue working after the call completes so it took me a while to > realize there was a problem. > > Someone suggested: > > "Sounds like the C code that does the SSL is not _releasing_ > the global thread lock." Yes, this is true. > I'm using python SSL that comes with Python 2.1.1 on FreeBSD 4.3. > > I searched usenet and everywhere else I could think of but only found > one usenet post about broken ThreadingMixin know to be broken in > 2.1.1c but I'm not sure if this is related. > > Any suggestions? Could you perhaps provide a test case for publicly available SSL servers? That would be helpful for fixing the problem. In the meantime, this is a quick (untested) patch against current CVS Python: *** /mnt/gargamel/src/python.orig/dist/src/Modules/socketmodule.c Fri Oct 19 19:11:51 2001 --- socketmodule.c Thu Oct 25 01:19:24 2001 *************** *** 2689,2695 **** --- 2689,2697 ---- if (!PyArg_ParseTuple(args, "s#:write", &data, &len)) return NULL; + Py_BEGIN_ALLOW_THREADS len = SSL_write(self->ssl, data, len); + Py_END_ALLOW_THREADS if (len > 0) return PyInt_FromLong(len); else *************** *** 2714,2721 **** if (!(buf = PyString_FromStringAndSize((char *) 0, len))) return NULL; count = SSL_read(self->ssl, PyString_AsString(buf), len); ! if (count <= 0) { Py_DECREF(buf); return PySSL_SetError(self->ssl, count); } --- 2716,2725 ---- if (!(buf = PyString_FromStringAndSize((char *) 0, len))) return NULL; + Py_BEGIN_ALLOW_THREADS count = SSL_read(self->ssl, PyString_AsString(buf), len); ! Py_END_ALLOW_THREADS ! if (count <= 0) { Py_DECREF(buf); return PySSL_SetError(self->ssl, count); } If the patch doesn't apply cleanly, just search for SSL_read and SSL_write and wrap these lines with Py_BEGIN_ALLOW_THREADS resp. Py_END_ALLOW_THREADS. > Is this a known problem? Unless it's reported as a bug with the Sourceforge bugtracker, it's not a known problem <0.7 wink>. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From James_Althoff at i2.com Wed Oct 10 14:00:05 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 10 Oct 2001 11:00:05 -0700 Subject: Curious assignment behaviour Message-ID: Tim Peters wrote: Oops! The assert turned out to be the perversely self-fulfilling: assert(i = 1); and multiple senior programmers with many decades of industrial C experience had stared at that multiple times without realizing the mistake. I could certainly look at that a bunch of times and think "equality" instead of "assignment". This is one of the reasons why Smalltalk (among other languages) insisted on *not* using "=" to spell assignment. In my experience, when assignment is *not* spelled with "=" such mistakes don't come up in practice. And then it *is* acceptable (and very convenient) to make assignment an expression. Jim From skip at pobox.com Thu Oct 11 12:32:51 2001 From: skip at pobox.com (Skip Montanaro) Date: Thu, 11 Oct 2001 11:32:51 -0500 Subject: Length on an input parameter in python In-Reply-To: References: Message-ID: <15301.51635.832030.865995@beluga.mojam.com> >> It looks like the length of an input parameter (taken from the >> command line atleast) is limited to 256 characters. Is there a way >> around this? can I set something? can I use something special? or is >> there no way around this? Must be system-dependent. On my system I can read lines longer than 256 characters from console stdin: % python Python 2.2a4+ (#4, Oct 8 2001, 09:49:18) [GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = raw_input("Enter long line: ") Enter long line: ssssssss... bunch of s's elided ...ssssssss >>> print len(s) 377 and get parameters from the command line that are longer than 256 characters: % cat longparm.py #!/usr/bin/env python import sys print map(len, sys.argv) % python longparm.py sssssss... bunch of s's elided ...sssssssssssssssss [11, 377] -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From smarsh at hotmail.com Sun Oct 21 00:02:10 2001 From: smarsh at hotmail.com (scott) Date: Sun, 21 Oct 2001 04:02:10 GMT Subject: silly idea - interesting problem References: Message-ID: <3BD248BA.2163BBDB@hotmail.com> Stefan Antoni wrote: > > i got a silly idea about a small script which takes to strings (lets say > "test" and "dust") and mixes them to "tdeusstt". > i tried to code it because i thought it would be easy, but now i cannot > find out _how_ to do it ;) > > i tried to "list()" the string and mix the items. but ... > > Anybody has a hint or even a solution? > Here's a back to basics solution: firstWord = 'test' secondWord = 'dust' i = 0 while i < len(firstWord): print firstWord[i], secondWord[i], i = i+1 P.S.: Remember when Python used to differentiate itself from line noise (sorry, I meant Perl) with a philosophy that went something like "There's only one right way to do it."? -- Colorless green ideas sleep furiously. Chomsky From phr-n2001d at nightsong.com Tue Oct 9 15:57:48 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 12:57:48 -0700 Subject: Why so few Python jobs? (and licenses) References: <7x1ykd7es3.fsf@ruckus.brouhaha.com> Message-ID: <7xn13060xv.fsf@ruckus.brouhaha.com> Cliff Wells writes: > I have to admit I hadn't thought of that.... :( Still, to be honest, > I consider GPL'd/open source stuff to be a matter of goodwill, and > if I submitted a patch to a GPL'd author that means that I am > obviously using his code to a significant degree and the patch is > just my small thanks for that. If the author later profits from > that it's all the better, as far as I'm concerned, as this will > undoubtedly encourage him/her to develop more code (and maybe even > let him eat, if he needs to). People who resent that sort of thing > are perhaps missing the larger picture. I mostly agree with this sentiment--it does depend somewhat on the situation though. If I correct some typos in the manual at my leisure, sure, that's a gesture of goodwill. If I spend $5000 worth of development time writing and releasing a feature for GIMP that I could have had instead by paying $500 for a retail copy of Photoshop, the GIMP author has (at least monetarily) benefitted from my effort more than I've benefitted from his. (Note: that GIMP example is made up, not something that really happened to me). Most (admittedly not all - large projects like Linux being an > exception) GPL'd projects 90% the result of one or two people's > efforts with small improvements and fixes being submitted by others I guess that might be true--I'd be interested in seeing a real survey, based on, say, examining the CVS histories of projects on SourceForge. > (who, as I said earlier, are already benefitting from the existence > of that project - probably more than enough to compensate for their > small contribution). OK, though one should not underestimate the value of "small" contributions, especially considering that some may have been made at "gunpoint". E.g. I mentioned in another post I once spent a frantic all-nighter finding an Apache module bug that was crashing my employer's web site. The result was a two-line fix (it was a malloc error). If I did emergency repairs of someone else's software for a paying client, I'd charge at least 2x-3x my normal consulting rate per hour. By that reckoning, the two-line fix was worth enough to my employer to pay for several copies of a commercial server, because of the time spent in a critical situation. (Of course the commercial server would have had its own bugs...) > I suppose those same people resent the FSF selling copies of GPL'd > books. I hope not--a main point of the GPL is you're ALLOWED to sell copies of GPL'd stuff, as long as the recipient isn't restricted from making further copies. The FSF has in fact sold copies of a book I wrote and I don't object at all. It annoys me more if I write a program and a commercial publisher publishes a proprietary book about it--I'd rather that people buy the FSF book. > I think licensing GPL'd code is a good idea if it helps support the > efforts of open source programmers. I guess that can be true in some situations. Other times it's the opposite. GCC has benefitted tremendously from contributions of backends for various machines, front ends for alternative languages, etc. If proprietary versions were allowed, those improvements never would have been released. So I think more free Python improvements would result if Python were GPL'd, though I'm also ok with its present state of licensing. Anyway, the main thing IMO is not whether something is GPL'd, but that whatever the author decides to do, they announce their choice up front and don't spring surprises on contributors afterwards. > Getting paid to develop open source is the best of both worlds and > benefits everyone. Yes, that's a very good feeling :-). > Very true, I was thinking more along the lines of _who_ you choose > to give your money to. Since I use open source/GPL stuff all the > time, if I can justify giving them money, that's what I prefer to > do. That's why I buy the RedHat CD's rather than just downloading > them. I like Red Hat--they've written a lot of good code, and after stumbling a little in their early days, they've been consistent about GPL'ing all of it. I think it was Eric Troan who described it with some surprise--they found the more they gave stuff away, the more successful they were. (However, since I'm a cheapskate with currently low income, and since Redhat CD's contain a fair amount of code that I wrote, I feel like I've already contributed enough to them, so I don't go out of my way to buy the CD's--but I'm glad that you do ). From James_Althoff at i2.com Wed Oct 31 17:48:30 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 31 Oct 2001 14:48:30 -0800 Subject: python development practices? Message-ID: Cliff Wells wrote: >Encapsulation is as much a part of data hiding as private variables. >However, it would be nice to have a mechanism so that derived classes >wouldn't have to be careful of accidentally stepping on the attributes of >base classes. As I said earlier, a class should be a "black box". Authors >of derived classes shouldn't have to look at the internals of base classes to >avoid this, especially since, as we were discussing, the internals of the >base class could conceivably change, introducing name-collisions in derived >classes. A single underscore will not prevent this. For instance: > >class Base: > def __init__(self): > self._foo = 1 > >class Derived(Base): > def __init__(self): > Base.__init__(self) > self._x = 1 > self._y = 2 > >No problem here, but later, the author of Base decides to add a self._x to >Base. Now Derived is undoubtedly broken and it won't be clear why. A >private variable mechanism that could prevent this scenario would be a >definite benefit. Yep. Sadly, the fragile base-class monster does raise its head and take a bite now and again -- and it can be nasty. And I agree that the _ doesn't help because of the general need and desire for more than one level of subclassing. And this is true for methods that might be overridden unintentionally in a subclass as well as for fields. Jim From phr-n2001d at nightsong.com Mon Oct 15 17:15:17 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 15 Oct 2001 14:15:17 -0700 Subject: FW: [Python-Dev] conditional expressions? References: Message-ID: <7xy9mc8v16.fsf@ruckus.brouhaha.com> "Tim Peters" writes: > Some examples where parentheses *are* required: > > (if 1 then 2 else 3) + 4 > a[(if i then 2 else 3) : 4] Hmmm, this looks error prone. What happens if you omit the parentheses in these examples? Are they equivalen to if 1 then 2 else (3+4) and if i then a[2] else a[3:4] respectively? From jeff at ccvcorp.com Wed Oct 17 14:16:58 2001 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 17 Oct 2001 11:16:58 -0700 Subject: Troubles with global variables References: <87r8s4vmgy.fsf@toadmail.com> <87elo6cd4w.fsf@lisboa.ifm.uni-kiel.de> <87pu7op8p2.fsf@toadmail.com> <3BCCCC86.55A5C7F7@ccvcorp.com> <87g08hr5zc.fsf@toadmail.com> Message-ID: <3BCDCB1A.BA61698F@ccvcorp.com> Jeremy Whetzel wrote: > I've been playing around with the code, and I have a couple of > questions. > > First, with the dictionary having tuples, the items in the > tuples cannot be reassigned. (which is the error I receive when I try to > change an option) If I change the tuples to lists, I then receive an > error saying "TypeError: not enough arguments for format string". (I > think I got this one figured out by putting (item[0],item[1],item[2]) > instead of just 'item' on the string formatting line. What would _you_ > do to change this? (ie, did I hit close to the mark?) I *knew* I should've tested that code before I posted it. :) Yes, you can solve it that way, or just use tuple(item) as Tim Hochberg suggested. > > Also, I've noticed that when the menu prints, it tends to print the menu > listing in alphabetical order of the keys in menudict. Is there a way > to change this behavior? > > One last thing, and this was something I didn't address earlier, but > having the 'enc' variable is something I need later in the program. I > know I could use menudict['E'][2], but that feels cumbersome to type out > each place I need it. How would you approach this? > > I really appreciate your help, and your suggestions have been great. Hm. To be honest, I'd approach this whole thing from an object-oriented viewpoint, instead of the procedural one you're using, so it would end up looking quite a bit different. And much of the design would end up depending on just *how* everything else is being used. Making a few wild guesses based on the names you're using (hopefully you can follow the logic I'm using and apply it to your *real* problem ) ... Say you're trying to encode a data file into some other format, and you want to be able to select the type of format (the encoder) and the sampling bitrate to use. I would have an object representing a generic encoder, which would have an member variable for the bitrate, and methods to take in a data stream and output a new (encoded) data stream/file. I would then make subclasses of this generic encoder, one for each specific type of encoder I wanted to use. These subclasses would override the output function to create the proper type of file. Now, your encoding type, which you're currently storing in your 'enc' variable, is defined by the class of your encoder, but you probably won't *need* to worry about it elsewhere in the program, because the encoder will know, on its own, how to behave properly for its type of encoding. Then, selecting a new encoder from your menu would create a new encoder object, freeing the old one. The menu function would have to query the current encoder object to find out what type it is, and what its bitrate is--there'd probably be a method or three in the encoder class to provide this information. All in all, the architecture would be *quite* different from what you're working with, so it's hard to provide specific code without having a better idea if I'm even on the right track. :) And of course, not everyone is fond of object-oriented programming, so this approach may not even be suitable for you--it does require a big change in perspective. If you *are* interested in it, there's lots of guidelines and tutorials about OOP available on the web. Hopefully this hasn't totally confused you now. :) And of course, Python works quite well for either object-oriented or procedural styles. Jeff Shannon Technician/Programmer Credit International From mwh at python.net Wed Oct 24 05:00:12 2001 From: mwh at python.net (Michael Hudson) Date: Wed, 24 Oct 2001 09:00:12 GMT Subject: non-function members of string-module. References: <3BD58F4A.2000408@engineer.com> <3BD61042.CF3B72C1@home.com> Message-ID: Michael Hudson writes: > In Python 2.2, > > map(str.strip, lines) > > is the fastest of the lot. Hmm, I feel a patch coming on... No I don't: unicode. Crap. Cheers, M. -- 81. In computing, turning the obvious into the useful is a living definition of the word "frustration". -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From chrishbarker at home.net Mon Oct 29 13:58:01 2001 From: chrishbarker at home.net (Chris Barker) Date: Mon, 29 Oct 2001 10:58:01 -0800 Subject: Write and read objects from files . References: <005701c15f08$0979d140$4396003e@rashome> Message-ID: <3BDDA6B9.907AA600@home.net> > > I'm a python beginner and looking for : > > 1. A way to save a list on a file (as a string) and then retrieve it > > back (read the string from the file and build automatically a list) . you might want to try repr() and eval(). In general, the goal of repr() is to produce a string such that: eval(repr(x)) = x so you can do: file.write(repr(YourList)) and later: eval(file.read()) You'r reading code will probably be a lot more complex, if you have more than one item stored in the file, but this should give you the idea. Here is a short example at the command line: >>> l1 = ['this', 'that', '56'] >>> l1 ['this', 'that', '56'] >>> s = repr(l1) >>> s "['this', 'that', '56']" >>> l2 = eval(s) >>> l2 ['this', 'that', '56'] >>> l2 == l1 1 >>> -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From weeks at vitus.scs.agilent.com Sat Oct 6 00:56:31 2001 From: weeks at vitus.scs.agilent.com (Greg Weeks) Date: Sat, 6 Oct 2001 04:56:31 +0000 (UTC) Subject: sameness/identity References: <1001876090.367103@cswreg.cos.agilent.com> Message-ID: <1002344191.578675@cswreg.cos.agilent.com> Greg Weeks (weeks at vitus.scs.agilent.com) wrote: : That's why you won't find me adding __cmp__ and __hash__ methods to bank : accounts. Having written the above, I was pleased to notice recently that for a file object f: hash(f) == id(f) So, just like Bank_accounts, file objects have the default hash function and *can* be used as hash table keys. So, in my slightly incendiary phrasing, Python "got it right" for file objects. Python, then, is sending a mixed message. Greg From =?iso-8859-5?Q?=DF=D5=DD=D3=E3=D8=DD=D8=E1=E2=D0?= at =?iso-8859-5?Q?=DC=D0=D8=DB?=.=?iso-8859-5?Q?=DD=D5=E2?=.=?iso-8859-5?Q?=DC=DA?= Fri Oct 19 13:02:45 2001 From: =?iso-8859-5?Q?=DF=D5=DD=D3=E3=D8=DD=D8=E1=E2=D0?= at =?iso-8859-5?Q?=DC=D0=D8=DB?=.=?iso-8859-5?Q?=DD=D5=E2?=.=?iso-8859-5?Q?=DC=DA?= (=?iso-8859-5?Q?=B4=D0=DC=F8=D0=DD_=B3=2E?=) Date: Fri, 19 Oct 2001 19:02:45 +0200 Subject: global variables References: <9q6njs$17s4$1@f1node01.rhrz.uni-bonn.de> Message-ID: <3bd05cb1$1@news.mt.net.mk> > I?m experiencing a little problem due to my > poor understanding of the way python handles > global variables. Basically the problem is the following > I have a programm with several variables which > I would like to access globaly. var=0 def example_function(??) global var var=var+1 (function definition) print example_function(10) -- ?????? ??????? ? ?? ?? ?????, ?? ?? ??????? ?????? ????? ?? ?? root. From grahamd at dscpl.com.au Sun Oct 7 08:14:51 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 7 Oct 2001 05:14:51 -0700 Subject: Status of SOAP and Python. Message-ID: For those in the inner circle who now, where is SOAP for Python heading? Current contenders that I know of and have tried are: PythonWare soaplib PyWebSvcs SOAP Zolera ZSI There is also the ActiveState (??) .NET for Python stuff, but I don't know much about that. Anyway, PythonWare release was in June. It uses its own way of passing dictionaries which no one else uses, making it only useful with itself. Even then I find it doesn't want to work with itself sometimes, but then that might be the way I am using the encode and decode routines directly. Further, it only supports DateTime, Boolean and Binary beyond the basic Python types. Ie., No Time, Date, Duration, etc. Also doesn't support None. Next is PyWebSvcs of which the last release was also in June. This package does a better job, although one downside is that when Boolean, Date and Time types and also Binary (I think) are converted to Python objects, the type information is lost, being passed as int, tuples of ints or strings. This isn't useful if you are gatewaying all requests into a distinct system, ie., where you don't know the nature of what each call represents, but where you need to preserve the type information. Although there has been a little traffic on the pywebsvcs mailing list, questions on the web forums haven't been getting answered and there have been no responses to bug reports or feature requests. People are still downloading the package, but in general, little indication of whether it is still being actively developed. Most promising new addition to SOAP support for Python has been ZSI from Zolera. It also doesn't seem to support None and am having troubles with its handling of dictionaries and the fact that a single object returned by a remote method is returned in a single item list by client. Must admit I am waiting for response on these issues in case I am missing something. In general some of the other problems that come up with SOAP being used in Python are the inability to seemingly pass an empty dictionary. In the pywebsvcs package it translates these as empty strings where as in ZSI it translates them as an empty array. The PythonWare stuff can handle an empty dictionary, but then it can't talk to anything else. Being fair, I believe the empty dictionary problem comes back to a problem in the SOAP protocol itself. Next on the list of problems with dictionaries is the default encoding for SOAP in which dictionaries are encoded has keys encoded as element names. This means that key values in a dictionary must not only be strings, which is also the case with XML-RPC, but that the values of the keys must follow XML element name conventions. This means you can't just stick anything in a key. Whitespace is generally a bad idea, as are various punctuations characters, leading numerical data, anything starting with "[xX][mM][lL]" etc. Note that although in XML-RPC, you can only have strings for keys, you can use any value for it (well perhaps maybe only ASCII if you ask the purists). Note that their is a encoding called Apache:Map (name?) which can be used in SOAP to get around the key is string restriction, ie., any value for string, but also any type for key. The ZSI package has support for this, but the others don't. Because this is outside the standard encoding for SOAP, one can't expect SOAP implementations in other languages to support it either. Hell will probably freeze other before Microsoft supports it and I am sure they will come up with their own way of doing the same thing. In terms of the implementations which are available there is no one way of how faults should be handled, Again this is partly due to SOAP making fault details use definable. This makes it confusing when you are trying to pack the error messages of some distinct system into a SOAP fault, especially when the SOAP packages idea of how to handle faults are more or less melded with their particular dispatch mechanism, ignoring that someone may want to use just their encoding and decoding routines in a different framework. Anyway, the end result of all this is that I see SOAP in general as a mess. In relation to Python and SOAP, I don't see the combination of the two to be that inspiring. Right now, other RPC over HTTP protocols with the simplicity of XML-RPC seem to be a better match with Python, although must say that XML-RPC doesn't support None. But then, various people have added it themselves and yet more have developed their own new protocols. Enough of the rambling I guess. How do others see where SOAP is going in relation to Python? Do people still think SOAP is the best thing since sliced bread, or are people starting to realise it is pretty crappy after all? What other SOAP for Python implementations are there out there? Does anyone know if PythonWare and pywebsvcs are going to be coming out with updated implementations? Is there any point in trying to provide a SOAP gateway into a system capable of being used to build web services when it already supports XML-RPC as well as a much more functional RPC over HTTP protocol albeit one that is particular to that system? Anyone have any better ideas? From rxg218 at psu.edu Wed Oct 31 18:57:42 2001 From: rxg218 at psu.edu (Rajarshi Guha) Date: Wed, 31 Oct 2001 18:57:42 -0500 Subject: accessing a web search engine Message-ID: <9rq340$1hfc@r02n01.cac.psu.edu> Hi, I'm trying to use Python to send queries to a webpage and analyse the results. However the search engine does'nt use cgi scripts - it uses a Javascript function. How can I access a JScript function. I realize that this is not really a Python question, but since I am using it I thought I'd ask here. I know that I have to use the urllib module but what string do I send to the server? TIA -- ------------------------------------------------------------------- Rajarshi Guha | email: rajarshi at presidency.com 152 Davey Laboratory | web : www.rajarshi.outputto.com Department of Chemistry | ICQ : 123242928 Pennsylvania State University | AIM : LoverOfPanda ------------------------------------------------------------------- GPG Fingerprint: DCCB 4D1A 5A8B 2F5A B5F6 1F9E CDC4 5574 9017 AF2A Public Key : http://pgp.mit.edu/ ------------------------------------------------------------------- All syllogisms have three parts, therefore this is not a syllogism. From aahz at panix.com Mon Oct 8 18:48:59 2001 From: aahz at panix.com (Aahz Maruch) Date: 8 Oct 2001 15:48:59 -0700 Subject: Python is better than free (was Re: GNU wars again) References: <200110030312.f933COK01047@smtp2.idir.net> Message-ID: <9ptagr$m6c$1@panix3.panix.com> In article , Laura Creighton wrote: > >Stop discussing the GPL in comp.lang.python. It makes people unsubscribe >in droves. This is how much some people hate discussions about the GPL. Oooo! A meta-discussion about what to post! ;-) Seriously, I think that as long as an appropriate Subject: line is used, people can easily killfile any such discussions they hate. -- --- Aahz <*> (Copyright 2001 by aahz at pobox.com) Hugs and backrubs -- I break Rule 6 http://www.rahul.net/aahz/ Androgynous poly kinky vanilla queer het Pythonista We must not let the evil of a few trample the freedoms of the many. From timr at probo.com Wed Oct 3 02:34:54 2001 From: timr at probo.com (Tim Roberts) Date: Tue, 02 Oct 2001 23:34:54 -0700 Subject: Alternative docstring implementation (Re: doc strings and efficiency) References: <3BBA6BB7.36C03366@cosc.canterbury.ac.nz> Message-ID: <15clrtc5dmiun1ufbdm59s90pd7psitu84@4ax.com> Greg Ewing wrote: >Instead of keeping docstrings in memory, perhaps the >interpreter should just keep a reference to their locations >in the .pyc file, and pull them out when the __doc__ >attribute is referenced. Not worth it. The entire standard Python library in its full, uncompiled source form is only 1.8MB. Even if half of that was doc strings, it's less than a megabyte. Better to blow the memory and skip the computational and disk overhead. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skip at pobox.com Wed Oct 31 11:36:53 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 31 Oct 2001 10:36:53 -0600 Subject: List -> Tuple In-Reply-To: <000401c16228$2d7f5ce0$a905a8c0@JWILHELM> References: <000401c16228$2d7f5ce0$a905a8c0@JWILHELM> Message-ID: <15328.10405.274307.841421@beluga.mojam.com> Joseph> Is there a simple way to convert a list into a tuple, like a Joseph> built-in function for that? Or is the easiest way to just Joseph> iterate through the list and append to a tuple? Try the tuple builtin: >>> l = [1,2,3] >>> tuple(l) (1, 2, 3) -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From ldw at us.ibm.com Tue Oct 23 14:01:09 2001 From: ldw at us.ibm.com (Larry Whitley) Date: Tue, 23 Oct 2001 13:01:09 -0500 Subject: None Message-ID: <9r4b95$suc$1@news.rchland.ibm.com> I want to have a methode of a class that will take the argument of a file object that has previously been opened for write and be able to call it, directing it's output to a file, or directing the output to standard output. def output(self, fout): print >>fout, self.thing1, self.thing2, self.thing3 In the calling program I say: object.output( fout ) # print to file object.output( None) # print to standard output But Python complains that None is a variable that has not been previously set. Can someone explain? I thought None was the empty object reference. Where have I gone astray? Larry From phd at phd.pp.ru Wed Oct 31 10:19:59 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Wed, 31 Oct 2001 18:19:59 +0300 Subject: Freeware Python editor In-Reply-To: <9rp4d8$830$1@tyfon.itea.ntnu.no>; from mlh@idi.ntnu.no on Wed, Oct 31, 2001 at 04:12:40PM +0100 References: <81F59ACE9063D511A5BB0002B328D2265115F4@il93exm20.css.mot.com> <9rp4d8$830$1@tyfon.itea.ntnu.no> Message-ID: <20011031181959.J21151@phd.pp.ru> On Wed, Oct 31, 2001 at 04:12:40PM +0100, Magnus Lie Hetland wrote: > > > Check out the free Python editor at www.crimsoneditor.com. > > > > Free (like free beer), but not free (like freedom). No source code, > > Windows only. > > Well, if you're a Windows user you're free to use it. Why complain? I was not complaining. I just wanted to make things clear. And, BTW, "free to use" is not free in the sense I prefer. I'd better read free code. And free code is the code I can read, modify and distribute. I hope I do not start yet another GNU flame war. :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From michael at rcp.co.uk Wed Oct 10 12:03:20 2001 From: michael at rcp.co.uk (Michael Abbott) Date: Wed, 10 Oct 2001 16:03:20 +0000 (UTC) Subject: Why not 3.__class__ ? References: <15280.59294.607840.917806@beluga.mojam.com> <7x4rp8q1cy.fsf@ruckus.brouhaha.com> Message-ID: "John Roth" wrote in news:ts8qte7m3n97e2 at news.supernews.com: > That's not exactly true. Making a feature dependent on whether there is > white space between components violates the principle of least > astonishment. It's also a very fertile source for very obscure bugs. Well, I suppose the only issue is what happens when someone writes 3.foo where the thing on the left is an integer literal and the thing on the right is an identifier. This is, presumably, parsed as and I would imagine that this would inevitably cause a syntax error. Although mildly surprising to the programmer, this doesn't strike me as particularly astonishing. More to the point, I don't see any room for any bugs at all here (let alone obscure ones), since the offending syntax is caught by the "compiler". From maxm at normik.dk Wed Oct 3 07:30:21 2001 From: maxm at normik.dk (Max M) Date: Wed, 3 Oct 2001 13:30:21 +0200 Subject: A little amusing Python program Message-ID: <3bbaf6c9$0$244$edfadb0f@dspool01.news.tele.dk> I have written this little Python program that usually raises a few eyebrows. It answer multiple choice questions. It is very simple. ie. question = 'What is Python' choices = ( 'a programming language', 'a tv series', 'a snake' ) It then queries google with: "What is Python a programming language" "What is Python a tv series" "What is Python a snake" and chooses the result that gets the most hits. Simple, but far better then random. Well it's not of much use, but kind of fun and very low budget AI ... regards Max M ####################################### from urllib import urlopen, urlencode import re class multiChoiceGuesser: def __init__(self, question='', replys=()): self.question = question self.replys = replys def guessedAnswer(self): hits = [] for reply in self.replys: hits.append(self._getGoogleHits(self.question + ' ' + reply)) return hits.index(max(hits)) def _getGoogleHits(self, query): query = urlencode({'q':query}) urlHandle = urlopen('http://www.google.com/search?%s' % query) googlePage = urlHandle.read() try: numberAsString = re.search( 'of about (.*?).', googlePage, re.S ).group(1) hits = re.sub(',', '',numberAsString) urlHandle.close() hits = int(hits) except: hits = 0 return hits def guess(question, choices): mcg = multiChoiceGuesser(question, choices) print 'The question is: ', question print 'The most likely answer is: ', choices[mcg.guessedAnswer()] print '' if __name__ == '__main__': """ The test suite. """ question = 'In which part of the world is Denmark located' choices = ('Europe', 'America', 'Asia', 'usa' ) guess(question, choices) question = 'Who created Linux' choices = ('Linus Torvalds', 'RMS', 'Steve Jobs', 'Bill Gates' ) guess(question, choices) question = 'What is Python' choices = ('a programming language', 'a tv series', 'a snake' ) guess(question, choices) question = 'Who is norman bates' choices = ('a character in Psycho', 'A hotel owner', 'the main character in american psycho' ) guess(question, choices) question = 'What is Madonna\'s full name?' choices = ('Madonna Lewis Ciccone', 'Madonna lillith Ciccone', 'Madonna Louise Ciccone' ) guess(question, choices) ####################################### The question is: In which part of the world is Denmark located The most likely answer is: Europe The question is: Who created Linux The most likely answer is: Linus Torvalds The question is: What is Python The most likely answer is: a programming language The question is: Who is norman bates The most likely answer is: a character in Psycho The question is: What is Madonna's full name? The most likely answer is: Madonna Louise Ciccone From vm_usenet at yahoo.com Wed Oct 10 16:15:29 2001 From: vm_usenet at yahoo.com (vm_usenet) Date: 10 Oct 2001 13:15:29 -0700 Subject: ODBC access via Python Message-ID: Hi all! I have recently become a die-hard Python fan, but I can't seem to overcome a minor obstacle: Can anyone direct me to a good ODBC module/library for python under win32? I've tried to install mxODBC, but it doesn't work for some reason... thanx in advance, vm From mikeb at mitre.org Mon Oct 15 19:00:08 2001 From: mikeb at mitre.org (Mike Brenner) Date: Mon, 15 Oct 2001 19:00:08 -0400 Subject: Python COM for Microsoft Project Message-ID: <3BCB6A78.62538A86@mitre.org> Has anyone played with Python to control Microsoft Project? It is, of course, easy to open a MP file: from win32com.client import Dispatch mpApp = Dispatch("MSProject.Application") mpApp.Visible = 1 mpApp.FileOpen ("C:\Documents and Settings\projectA.mpp") # Warning: works only with absolute file names. For the next line of code, I would like to resave the file as a tab-delimited file for further processing in Python. Actually, I will build a robot that opens all the MP files and resaves them. - Is there a URI to download the objects and methods that are now available? - Or is the list of objects somehow hidden inside my Visual Studio or my Microsoft Developer CDs? - Or do I need to buy Visual Basic for Applications or some other application to gain access to the objects? - Is there an upgrade to the COM object browser that comes with Python for Windows? Thanks Mike Brenner From x at x.com Sun Oct 28 06:45:37 2001 From: x at x.com (Alberto Rodriguez [FoxPress]) Date: Sun, 28 Oct 2001 12:45:37 +0100 Subject: win32com parameters Message-ID: <9rgqf0$k1d$1@diana.bcn.ttd.net> HI: I'm working with win32com and run fine to me when i ask a remote method without parameters but not with parameters. I have this error: Traceback (most recent call last): File "", line 1, in ? TypeError: object of type 'int' is not callable the code is: import win32com.client ox = win32com.client.Dispatch("proy1.miclase") oRec = ox.primero('asfd') The COM objetct is writed in Visual Foxpro and run fine from Visual FoxPro or Visual Basic any help? TIA From kseehof at neuralintegrator.com Thu Oct 4 03:13:40 2001 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 4 Oct 2001 00:13:40 -0700 Subject: Python embedding & question about autoconf and dynamic linking References: Message-ID: <03a401c14ca6$00c0c500$a0d185ce@kens> > Yes, I found that web site last week. > The reason for us to do embedding rather than extending is that our main > applciation is written in C (would you write a router in Python?...) and we > use python for writing a re-usable component, that is a CLI component. > Debugging our application is a lot easier if we embedd the Python code, which > represents a small percentage of our application code size. This is because > we can use the debugger as usual. If we were embedding our router in a > Python application (a hell of an extension), we would need to debug the python > interpreter, put a breakpoint where it loads extensions, continue until > it loads our router and then put a breakpoint in our router code. > Why do I not feel comfortable telling my colleagues who never used Python to > do this? Well I suppose it depends on how fancy your debugger is. I have no trouble at all debugging extensions using MSVC++ on windoze. I debug the extension as a DLL and set the command line to "python myapp.py ...". Setting breakpoints is just as easy as with an executable and this can even be done before starting the application, so I don't have to take any of the extra steps you are talking about, and I certainly don't need to debug the interpreter. I don't know if you are in windoze or *nix, but I'd assume the more fancy *nix debuggers can do this too. Sometimes I have a python debugger and a C++ debugger running at the same time, and set breakpoints in both! You can even step through python code and -kablam- your C++ debugger pops up in the extension code. It's really fun once you get used to it. Sometimes it does make more sense to embed than extend, but usually extending makes more sense, because the high level parts of a program (user interface, architecture, rules, data processing) really should be written in a high level language. Performance critical code, hardware specific code, etc. can usually be reduced to a set of low-level functions in C++ (C is arguably just as good since you usually don't need much object oriented design at this level). The only time I have used embedding was on an existing large application that already had a user interface, to add python as a built in scripting language. Generally, embedding involves extending since you usually need to expose your application to the embedded interpreter. - Ken kseehof at neuralintegrator.com > On Mon, 1 Oct 2001, Mads Bondo Dydensborg wrote: > > > On Mon, 1 Oct 2001, Olivier Deme wrote: > > > > > > I think it is more common to extend Python, than to embed it. I knew > > > > nothing about Python (apart from the name) a week ago, so I may be wrong > > > > though. > > > > > > Same for me. :-) > > > > I just found this page > > http://www.mcmillan-inc.com/embed.html > > > > Hmm. > > > > Mads > > > > -- > > Mads Bondo Dydensborg. madsdyd at challenge.dk > > You know you're a Linux geek when... > > > > You can reconstruct your fstab from scratch, and not even think about it. > > > > - segfault > -- > http://mail.python.org/mailman/listinfo/python-list From uwe at rocksport.de Tue Oct 2 09:07:16 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 2 Oct 2001 13:07:16 GMT Subject: trying sockets Message-ID: <9pce64$5gnu5$1@hades.rz.uni-sb.de> Hi, i'm just playing with the socket module: i'd like to send a "GET/HTTP" request to a webserver and record the answer of the server. so i wrote from socket import * snd=socket(AF_INET,SOCK_STREAM) snd.connect(("www.num.uni-sb.de",80)) print snd.getsockname() lstn=socket(AF_INET,SOCK_STREAM) lstn.bind(snd.getsockname()) snd.send("GET / HTTP/1.0 ") lsten.listen(1) conn,addr=lstn.accept() print conn.recv(1024) lstn.close() snd.close() but i get the following output: ('134.96.31.42', 1662) Traceback (most recent call last): File "client.py", line 8, in ? lsten.bind(snd.getsockname()) socket.error: (98, 'Address already in use') so: what did i do wrong ??? yours, uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From a.dijkstra03 at kpn.com Thu Oct 4 04:44:41 2001 From: a.dijkstra03 at kpn.com (dijkhuis) Date: 4 Oct 2001 08:44:41 GMT Subject: Newbie question please answer if you have time References: <3bbbcdfc$0$317$6e49188b@news.goldengate.net> Message-ID: <01c14cb0$ceef9f50$402b15ac@HKTGN0006211943> How about PySol? It's great! http://pysol.tsx.org Dijkhuis Greg Krohn schreef in artikel <3bbbcdfc$0$317$6e49188b at news.goldengate.net>... > A good game is SolarWolf > http://shredwheat.zopesite.com/solarwolf > > From my limited experience, there isn't much you can't do. Off the top of my > head, I can't think of anything that wasn't possible to do in Python. Well, > maybe some low level stuff, but if you're a newbie, you probably don't care > about that too much yet. A warning though: it's addictive. Since learning > Python I haven't touched another language (except a little stint in > esperanto). > > greg > > -- From tdelaney at avaya.com Mon Oct 29 18:47:19 2001 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 30 Oct 2001 10:47:19 +1100 Subject: Multiple postings Message-ID: > From: seb at tesco.net [mailto:seb at tesco.net] > > A post about duplicate posts being duplicated. Excellent. It's traditional. Anytime you post about a problem (such as someone else's spelling) you will include the exact same problem in your own post. Of course, since I'm not directly posting about the problem (as was the same with you) we need not be affected by this phenomenom. :) Tim Delaney From cd.cd at wanadoo.fr Sat Oct 13 05:46:08 2001 From: cd.cd at wanadoo.fr (Cyr) Date: Sat, 13 Oct 2001 11:46:08 +0200 Subject: Newbie - converting binary data to ASCII text ? Message-ID: <9q92g4$6hd$1@wanadoo.fr> hello, I'm completely new to python and I've got problem reading binary data file. When I read a file with read(), the binary data aren't converted. In fact, I'd like to know if there's a method for converting a file object (or a string) from binary to the equivalent ASCII text. The data aren't written in a particular format. Fortran doesn't have any problem with theese files I'would greetly appreciate any help, thanks Cyril D PS : I'm working on an SGI Irix operating system From nospam.dutoitc at hotmail.com Wed Oct 31 15:12:34 2001 From: nospam.dutoitc at hotmail.com (Cédric DUTOIT) Date: Wed, 31 Oct 2001 21:12:34 +0100 Subject: Reverse engineering (UML) Message-ID: <9rplu7$i651@news.vtx.ch> Hi ! Do you know a REVERSE-ENGINEERING program, wich read python code and generate the corresponding uml class diagrams ? Please, don't bother me with ObjectDomain - I don't like Java (i really hate closing others program to let java program run) thks, C.Dutoit/Switzerland __ PS : if you like mindmaping, i'm coding gimini, a free soft to make mindmap, in python. Source available at sourceforge : http://www.sourceforge.net/projects/gimini ; homepage= http://gimini.sf.net From spaceman at bsdzine.org Tue Oct 23 06:59:41 2001 From: spaceman at bsdzine.org (Karol Makowski) Date: 23 Oct 2001 10:59:41 GMT Subject: Python for ipaq References: <1003829421.27538.0.nnrp-01.d4f0f8ae@news.demon.co.uk> <7SbB7.7669$Ub2.260976@atlpnn01.usenetserver.com> Message-ID: On 23 Oct 2001 10:59:11 GMT, Karol Makowski wrote: > It's all i need, server, username/pass is defined in program, > while filename and/or path should be a variable. and it should not print any output, even error messages. -- Karol Makowski, System Administrator URL: http://spaceman.bsdzine.org e-mail: spaceman at bsdzine.org From idot at vt.edu Sat Oct 6 11:09:17 2001 From: idot at vt.edu (Carl Banks) Date: Sat, 6 Oct 2001 11:09:17 -0400 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> <3BBE6A57.FD354FE3@alcyone.com> <7xlmipcji1.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Erik Max Francis writes: >> > I think there's a simple way to represent quaternions as 3x3 matrices. >> > So you could probably just store them that way and use NumPy for the >> > arithmetic. >> >> ... which rather defeats the purpose for using quaternions in the first >> place. > > Nah. I mean, if efficiency was a big issue, you wouldn't be using an > interpreted language in the first place. What's left, if you have a > good matrix package, is something like if your language had complex > numbers but didn't have reals. You can still represent the reals as > complexes. For that matter, lots of languages have had reals but no > integers. It hasn't been that bad a problem. You severely underestimate the difficulty of doing this. While any quarternion can be represented as a 3x3 matrix, not every 3x3 matrix is a quarternion. And keeping your matrix in "quarternion form" when you do arithmetic is not trivial. To wit, a quarternion has 4 components. A 3x3 matrix has 9 components. Therefore, when doing quarternion arithmetic using a 3x3 matrix, you must be sure the resulting matrix satisfies 5 constraints. And, IIRC, the constraints are not simple. (Contrast this to using a complex as a real. Here, only one very simple constraint, namely Im(z)==0, must be maintained.) -- CARL BANKS From tim.one at home.com Thu Oct 4 20:36:44 2001 From: tim.one at home.com (Tim Peters) Date: Thu, 4 Oct 2001 20:36:44 -0400 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> Message-ID: [Steve Holden] > Nope. If Tim were married, you would write about his and his wife's home > (assuming they lived together) as the Peters's home. Since (and how > could it be else) there is only one Tim, you should write about Tim > Peters' way of thinking. Well, if there is only one Tim, we should drop the redundant surname and just say it's Tim's simulation of thinking. BTW, doesn't this look fishy to you (s/Peters/Holden/)?: Nope. If Steve were married, you would write about his and his wife's home (assuming they lived together) as the Holden's home. Since (and how could it be else) there is only one Steve, you should write about Steve Holden' way of thinking. When I was about 12, a teacher said Peter's or Peters's was acceptable for the singular possessive (I stuck with Peters's), and Peterses' for the plural (I stuck with Peters', and got extra credit later ). > but-then-i'm-english-so-what-do-i-know-ly y'rs - steve You *should* know that America fought a bloody war to get away from your illogical grammar rules, and it can happen again. still-confused-about-fingersbreadth-vs-fingerbreadth's-ly y'rs - tim From anthony at interlink.com.au Sun Oct 21 01:05:21 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Sun, 21 Oct 2001 15:05:21 +1000 Subject: Smtplib module In-Reply-To: Message from Sheila King of "Sun, 21 Oct 2001 03:48:18 GMT." <9qsnue.3vv5vib.1@kserver.org> Message-ID: <200110210505.f9L55LY29981@mbuna.arbhome.com.au> >>> Sheila King wrote > For more excitement: > > Do an MX record look up on the domain name in the email address, and > deliver directly to that SMTP server. > > Coding is left as an exercise for the reader. Note that if you are going to do this, make sure you read the relevant RFCs and behave correctly w.r.t backup MXs and the like. Just Say No To Badly Written MTAs :) Anthony -- Anthony Baxter It's never too late to have a happy childhood. From chrishbarker at home.net Wed Oct 3 15:58:51 2001 From: chrishbarker at home.net (Chris Barker) Date: Wed, 03 Oct 2001 12:58:51 -0700 Subject: comparing interpreter speed on two platforms References: Message-ID: <3BBB6DFB.9A32F590@home.net> "Steven D. Majewski" wrote: > > a standard PC: > > 1. PentiumPro 200Mhz (400BogoMips) Debian Linux 2.2 (Kernel 2.2-17) 64M RAM > > > > and an embedded system: > > 2. PowerPC ~60Mhz (68BogoMips) HardHat Linux 2.0 (Kernel 2.4) 16MB RAM > >Because, as stated in the Linux docs, BogoMips is a meaningless benchmark. True, but as a rule PPC chips a little faster that Pentiums with the same clock speed, so I wouldn't expect a 60 Mhz PPC to be 20 times slower than a 200Mhz Pentium. I have done occasional benchmarks with Python code, and my 450Mhz Pentium (running Linux) is about the same speed as my 300Mhz PPC running MacOS 8.6, unless there is a lot of disk access, in which case the Linux box is much faster. Of course there are a lot of other factors: cache: a larger/faster cache could be making a huge difference. bus speed: memory access time could be very different. Of course, you have done the right thing: benchmark your actual application. Now the hard part: find the the bottlenecks, and fixing them. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From markus at schabi.de Thu Oct 11 16:13:11 2001 From: markus at schabi.de (Markus Schaber) Date: Thu, 11 Oct 2001 22:13:11 +0200 Subject: Curious assignment behaviour References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> Message-ID: <5864998.WnqpD5jiFI@lunix.schabi.de> Hi, Paul Rubin schrub: > Anyway, I can live with "while x:=get_next()" instead of x=get_next. > But I feel seriously cramped in Python when I have to say > > while 1: > x=get_next() > if not x: break > whatever(x) > > so I hope something is done about the issue. Using cutting-edge Python, one might wrap it with an iterator: def seq(): temp = get_next() while temp: yield temp temp = get_next() And then easily use it this way: for i in seq(): whatever(x) (this code is not tested, as I currently don't have a 2.2 python here.) markus -- You don't have to be Microsoft to suck... but it helps. (Tim Hammerquist in comp.lang.python) From loewis at informatik.hu-berlin.de Thu Oct 18 13:09:44 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 18 Oct 2001 19:09:44 +0200 Subject: Random from Dictionary References: <4f7234de.0110180504.20aa475b@posting.google.com> <9qml3o$ovl8k$1@ID-11957.news.dfncis.de> <181020010938443703%tpayne@mac.com> <9qmoft$p7mln$1@ID-11957.news.dfncis.de> Message-ID: "Emile van Sebille" writes: > I can't confirm that error. I tested with 1.5.2, 2.0, 2.1 and > 2.2a4+ and it appears to work Not for me: Python 2.1.1 (#1, Jul 21 2001, 20:59:12) [GCC 2.95.2 19991024 (release)] on sunos5 Type "copyright", "credits" or "license" for more information. >>> x={'Hallo':'Welt'} >>> import random >>> random.choice(x) Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.1/random.py", line 329, in choice return seq[int(self.random() * len(seq))] KeyError: 0 Perhaps you where using integer keys? Regards, Martin From lucio at movilogic.com Tue Oct 23 16:37:52 2001 From: lucio at movilogic.com (Lucio Torre) Date: Tue, 23 Oct 2001 17:37:52 -0300 Subject: POLL in different OSes References: Message-ID: <3BD5D520.7050007@movilogic.com> > > > >Create the polled objects... > >>>>obj1=makepolled(fd1) >>>>obj2=makepolled(fd2) >>>> > >Create the poller and add the polled... > >>>>poller=makepoller() >>>>poller.addpolled(obj1) >>>>poller.addpolled(obj2) >>>> > >Enable the events I want to know about... > >>>>obj1.enable(PL_READ) >>>>obj2.enable(PL_WRITE) >>>> > >Poll 'em... > >>>>poller.poll() >>>> > >Test the result... > >>>>if obj1.has(PL_READ): >>>> # Read from obj1 >>>>if obj2.has(PL_WRITE): >>>> # Write to obj2 >>>> isnt iterating over every object to see if its ready or not (again) too expensive? lucio From clpy at snakefarm.org Tue Oct 30 11:20:12 2001 From: clpy at snakefarm.org (Carsten Gaebler) Date: Tue, 30 Oct 2001 17:20:12 +0100 Subject: redirecting sdtout/sdterr in a daemon References: <9rmiqc$23hq@r02n01.cac.psu.edu> Message-ID: <3BDED33C.23CBD7BC@snakefarm.org> Rajarshi Guha wrote: > I'm using the daemonize.py module to make my code run as a daemon. > However the module contains the lines: > > sys.stdout = NullDevice() > sys.stderr = NullDevice() > > Instead of this behaviour I would like it to write output to a file. So I > write: > > sys.stderr = open(outputhandle,'w') > sys.stdout = open(outputhandle,'w') > > Where outputhandl is a passed to the function. However no output comes to > the this file. This is due to the lines that follow the STDERR/STDOUT redirection: > for z in range(3, 256): > try: os.close(z) > except: pass This loop closes all file handles except for the "real" STDIN/STDOUT/STDERR which are 0, 1 and 2. Especially your newly opened files will be closed here. Open the files after the loop and it should work as you expected. cg. From tefol at This.Is.Not.An.Address Sun Oct 7 10:10:48 2001 From: tefol at This.Is.Not.An.Address (tefol) Date: Sun, 07 Oct 2001 14:10:48 GMT Subject: Webform python cgi issue References: <9133E264AtefolThisIsNotAnAddr@61.9.128.12> Message-ID: <9134D587tefolThisIsNotAnAddr@61.9.128.12> tefol at This.Is.Not.An.Address (tefol) wrote in <9133E264AtefolThisIsNotAnAddr at 61.9.128.12>: >Hiya everyone.... > >What the heck is all that stuff? I figured out what all that stuff was now. That is what pickling does to s a form. So instead of pickling what I am returning, I have altered the FeedbackData thus: class FeedbackData(FormData): fieldnames = ('field1', 'field2', 'field3', 'field4', 'field5') def __repr__(self): return 'Field1 = %(field1)s \nField2 = %(field2)s \nField3 = %(field3)s \nField4 = %(field4)s' % vars(self) This works great, proved when I exit the script like this: data = FeedbackData(form) print "Content-type: text/html\n\n" print "

You did it!

" print data sys.exit() I get exactly what I want displayed in my browser. Only thing is when I try: output = open('/home/nemir/output/output.txt', 'w') output.write(data) output.close() I get this in my apache error log: malformed header from script. Bad header= File "/home/nemir/public_htm: /home/nemir/public_html/cgi-bin/inputform.py What is the "/home/nemir/public_htm: "??? the directory is public_html! not htm.... And where does that colon come from? Is this something I should post on the apache ng? again, TIA Tefol From cliechti at gmx.net Mon Oct 8 13:54:39 2001 From: cliechti at gmx.net (Chris Liechti) Date: 8 Oct 2001 19:54:39 +0200 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> Message-ID: Carsten Gaebler wrote in news:3BC166F4.5E7FAB08 at snakefarm.org: > Given a string > s = "%(foo)s %(spam)s" > and two dictionaries > d1 = {"foo": "bar"} > d2 = {"spam": "eggs"} > > how would you apply d1 and d2 to s without modifying or explicitly > copying one of the dicts? > s = ("%(foo)s %%(spam)s" % d1) % d2 use two "%" for variables that are in the second dict. Chris -- Chris From sholden at holdenweb.com Sat Oct 13 06:05:19 2001 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 13 Oct 2001 06:05:19 -0400 Subject: Newbie - converting binary data to ASCII text ? References: <9q92g4$6hd$1@wanadoo.fr> Message-ID: "Cyr" wrote in message news:9q92g4$6hd$1 at wanadoo.fr... > hello, > > I'm completely new to python and I've got problem reading binary data file. > When I read a file with read(), the binary data aren't converted. In fact, > I'd like to know if there's a method for converting a file object (or a > string) from binary to the equivalent ASCII text. The data aren't written in > a particular format. Fortran doesn't have any problem with theese files > Unfortunately, Python offers much greater flexibility than Python in data handling, and correspondingly more chances to shoot yourself in the foot. I'm assuming it's *convenient* to have these data in binary form, otherwise you could always write a Fortran program to convert them into something Python finds easier to deal with ... I also presume it was written with FORMAT statements (sheesh, does Fortran even USE those now, showing my age I'm afraid). Python can read a particular number of bytes if you give read() a numeric argument, but if you don't it just tries to gobble the whole file in a oner. Otherwise you may have to look at the struct module, and that's too tricky for a beginner. regards Steve -- http://www.holdenweb.com/ > PS : I'm working on an SGI Irix operating system > > From aleax at aleax.it Sat Oct 13 04:53:26 2001 From: aleax at aleax.it (Alex Martelli) Date: Sat, 13 Oct 2001 10:53:26 +0200 Subject: Borg Pattern Class usable from other classes? References: <9q69h8$grb$1@serv1.iunet.it> Message-ID: <9q8ve6$hb7$1@lancelot.camelot> Paul Winkler wrote: > On Fri, 12 Oct 2001 10:27:23 +0200, Alex Martelli wrote: >>Highlander for the DP, and Borg for the non-pattern which I >>posted and D. Ascher named, seem much more appropriate names, >>as the connection to science fiction movies/TV series is sharp >>and pleasingly anti-parallel. > > AFAIKT, Borg is the same as Monostate which seems to have been around > for a couple years: > > http://www.ddj.com/articles/1998/9809/9809a/9809as2.htm > > At least, the Consequences are identical: > """ > * Multiple local instantiations but always with only a single state. > * Persistent object state in the absence of any instantiations. > * Familiar syntax. Does not require an accessor function as with > Singleton objects. > """ > > Borg is an OK name but Monostate is a little more obvious to those of > us who don't know much about Star Trek (yes, we exist). Borg and Monostate (attempt to) solve the same forces. However, they do so in different languages. *Language-appropriateness* of patterns is often ignored, even though the Gang of 4 mention it quite well right in Chapter 1, exemplifying with Visitor, which would be pretty silly in a language with multiple dispatch. Similarly, "just keep all data static" (which I had first met, without a catchy name, in the context of C++) is OK for C++ or Java, but not for Python, where you may want to allow, for example: theobj.acount += 1 This would be bad practice in languages bereft of "property idioms" such as C++ of Java, but it's fine where properties are indeed idiomatic, such as Delphi or Python: the class author can and should ensure that accesses to properties "from the outside" go through appropriate method calls implicitly if need be. It would be anti-idiomatic to force client code through such contortions as theobj.setAcount(theobj.getAcount() + 1) in such languages (even though people who don't fully grasp a language do try to "program Java in Delphi" and so on, of course, good idiomatic language use has substantial advantages). The "keep it static" (Monostate) pattern in Python would give: class AClass: acount = 0 and would work fine as long as you're just accessing x.acount from client code (AClass.acount would implicitly be used, just as in a similar situation in C++ or Java), but not for rebinding (or deletion). You'd have to impose supplementary, non-Pythonic restriction on client code, or start messing with __setattr__ &c (in Python 2.2, you could use less-messy specific per-attribute getters/setters, but if you have more attributes it's still rather a lot of boilerplate). > BTW, are there any "gotchas" with Borg/Monostate in a multi-threaded > context? Singleton requires extra care, leading to the "Double-checked > Locking" pattern which apparently has been found not to work in > Java. Any such snags for Borg? I can't think of any, but I've only > really toyed with threads. If two Borg instances are created in separate threads, they still access the same state-data, so you get the joys of dealing with whatever synchronization issues. There's no implicit per-object or per-method locking in Python anyway (unless you make it yourself with a metaclass, I guess, but I've never tried doing that). No extra care wrt direct accessing shared state, but no special help for that, either. Although it may be a bit heavyweight for many uses, there is a Pythonic pattern based on Queue for multi-thread access to shared state, which I haven't seen published as such but I think could be called GateKeeper or Guardian. A guardian-thread is sole accessor of a complex of shared state (which could but need not be a Borg). All access to the guardian thread is by posting to a specific Queue tuples of (ResponseQueue, boundmethod, args, kwds) followed (at once or a bit later) by waiting on the ResponseQueue. The Guardian thread just loops taking request pairs from its Queue, running the boundmethod, posting the result to the ResponseQueue. Yep, it's overkill in many cases, but it does lend itself to neat encapsulation. Say the client code only "sees" object guardianProxy which wraps sharedObject (which could but need not be a Borg). Then client code just calls, e.g.: myresult = guardianProxy.someMethod(someThing,anOther) and the only issues for client code are with "granularity of locks" -- i.e. if client code tries mytotal = guardianProxy.oneThing()+guardianProxy.anOther() anything may happen between the two method calls although each is running atomically (needs some explicit locking if that is a problem!). GuardianProxy's __getattr__ delegates to sharedObject's, but, when it gets a callable, builds on the fly another callable wrapping it, and returns the wrapper. The wrapper callable does the queue-minuet on behalf of its caller: class QueueWrapper: def __init__(self, realthing, requestQueue): self.realthing = realthing self.requestQueue = requestQueue def __call__(self, *args, **kwds): responseQueue = Queue() self.requestQueue.put(( responseQueue,self.realthing,args,kwds)) return responseQueue.get() The overkill aspects come e.g. in the overgenerous creation of Queue objects, but it's not hard to remedy by adding some usage conventions regarding what reuse (or lack thereof) is made of the QueueWrapper callables. It's just a bit harder to extend this to self.realthing raising an exception in the guardian thread to be propagated this back to the client thread: the responseQueue would have to receive exception-indicators and re-raise appropriately. But more often, I think non-hypergeneralized Queue usages that in some sense specialcase this ambitious general scheme are typical and appropriate. But the whole issue of non-Patterns vs Patterns is a rather large subject -- we can hardly do it justice here. Alex From richard at bizarsoftware.com.au Thu Oct 4 21:45:15 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 5 Oct 2001 11:45:15 +1000 Subject: Compiling 2.1.1 on Mac OS X 10.1 - test failures Message-ID: <0110051145150H.04291@ike> Hi all, I'm trying to get python built on my mac powerbook running OS X 10.1. I've edited the configure script so that LDSHARED is defined as LDSHARED= $(CC) $(LDFLAGS) -bundle -flat_namespace -undefined suppress for Darwin. I then ran configure with: OPT='-O3 -no-cpp-precomp' ./configure --with-suffix=.exe --with-dyld \ --program-transform-name=s/.exe//g Compiling went OK. Then I tried "make test". Oh dear. test_largefile: took about 2.5 minutes. Top reported that it was mostly "stuck" and occasionally "running" - using very little CPU and no disk that I could detect (by the scientific aural detection process ;) When it was finished, it printed the message "@test exists: 0". No idea if this normal - my Linux machine doesn't have large file support. test_re: got a segfault (with -O3, -O2 and no optimisation at all) Also, the program-transform-name didn't appear to do anything. My programs were installed with the .exe extension. Richard From db3l at fitlinxx.com Thu Oct 4 12:47:39 2001 From: db3l at fitlinxx.com (David Bolen) Date: 04 Oct 2001 12:47:39 -0400 Subject: XML Marshalling of objects References: <9pdfd4$c0q$1@tyfon.itea.ntnu.no> <2347302.PoejJDZkT8@lunix.schabi.de> <3BBBF99B.46165827@engcorp.com> Message-ID: Peter Hansen writes: > which might be what you meant by CDATA element in a DTD but then again > it might not be (and DTDs are obsolete, aren't they?). Yeah, my mistake - I should have said #PCDATA for the DTD - or the CDATA section is fine too. XML Schemas may be the "in" thing, but DTDs are still very much in use from what I can see (particularly when you also want compatibility with SGML). > That way you > would have to escape only the sequence ]]> if it were to occur in the > data. The use of the embedded CDATA section would help minimize the tokens to quote, but the moment you have any escape (even one) you pretty much have the same overhead for encoding and decoding, in terms of having to walk the stream on both ends independent of the pickle. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From -$Paul$- at verence.demon.co.uk Wed Oct 17 09:09:43 2001 From: -$Paul$- at verence.demon.co.uk (Paul Wright) Date: 17 Oct 2001 14:09:43 +0100 Subject: python library path on Debian LInux References: Message-ID: <9qjvun$770$1@verence.demon.co.uk> In article , Avdi B. Grimm wrote: >I'm using Python on a Debian machine, and I've installed both the >python-1.5 and the python2 packages. I prefer to use python2. >Unfortunately, the way the Debian packages are arranged, many of the >additional libraries available for python (such as PyGTK) are as yet >only packaged for Python1.5. Apparently libraries packaged for different >Python versions are installed in different directories, and each python >executable only sees the libs that were packaged for it. Yes. What I do is get binaries from stable and source from testing: deb ftp://ftp.uk.debian.org/debian/ stable main non-free contrib deb-src ftp://ftp.uk.debian.org/debian/ testing main non-free contrib deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free deb-src http://non-us.debian.org/debian-non-US testing/non-US main contrib non-free deb http://security.debian.org/ stable/updates main contrib non-free When I want something which isn't in stable, or a more recent version of something which is, I get the source from testing and build the package. I'm doing it this way because I don't know how reliable the testing distribution is at the moment so I'm not quite willing to make the jump to it yet, but if you need the latest stuff and have a fast connection, upgrading to testing is probably the easiest way to do it. -- ----- Paul Wright ------| /dev/hda - 3.2Gb of spinning metal, all alone in -paul.wright at pobox.com--| the night... http://pobox.com/~pw201 | From DeepBlue at DeepBlue.org Thu Oct 11 14:02:45 2001 From: DeepBlue at DeepBlue.org (DeepBlue) Date: Thu, 11 Oct 2001 13:02:45 -0500 Subject: CGI question on input type=text form elements References: Message-ID: "Ignacio Vazquez-Abrams" wrote in message news:mailman.1002815363.21257.python-list at python.org... > On Thu, 11 Oct 2001, DeepBlue wrote: > > > I am running into a strange problem with a form while using CGI module in > > Python. > > Let us say I have the following form: > >
> > > > > >
> > > > Now, let us say that test_form=cgi.FieldStorage() > > If the above form is submitted without typing anything in the text field one > > expects test_form.keys() to generate: > > ['submit'] > > > > But i am getting: > > ['text_1', 'submit'] > > Which is unexpected, and in my case, undesirable. What am I doing wrong? > > You are assuming that the browser won't pass the contents of text_1 if it is > empty. Obviously this isn't true. You need to fine-tune your code to deal with > the case when it is empty. > This is only happening when the form is enclosed in a table. When the form is not, the keys do not include empty text input elements. DeepBlue > -- > Ignacio Vazquez-Abrams > > From eric at enthought.com Thu Oct 25 11:18:49 2001 From: eric at enthought.com (eric) Date: 25 Oct 2001 08:18:49 -0700 Subject: HELP -- py2exe failed to build app that uses scipy.plt References: <436bca17.0110181944.247f4ecd@posting.google.com> Message-ID: <16f9b1ea.0110250718.7ccc7fe9@posting.google.com> Hey Phil, I haven't ever used py2exe, so I'll be of little help. I can't say I'm surprised though. The __init__ files in SciPy have some strange importing practices that may make it hard for py2exe to determine the needed modules. I don't know how hard it is to fix this sort of thing -- or even if it is the problem. You could try and pull plt out of scipy and use it stand alone, but would require at least some hacking as there are some dependencies. sorry I don't have more info. eric pho56 at yahoo.com.au (Phil Ho) wrote in message news:<436bca17.0110181944.247f4ecd at posting.google.com>... > Hi, > > Sorry for this lengthy message. I do appreciate if you could help, > give me some hints or workarounds etc. for this py2exe (0.2.6) > conversion problem. > > I built an application under Windows NT4.0 with ActivePython 2.1.1, > SciPy-0.1 and wxPython 2.3. Basically it has: > > 1. An GUI in wxPython > 2. Access binary data from a database that return as Numeric arrays. > 3. Plot the data array using scipy.plt which is also implemented in > wxPython. > > The app worked happily by activating 'python hat.pyw'. However, I was > unable to use py2exe to convert to an executable due to errors as > attached at end of this message. I found out the scipy.plt module that > caused the problem because py2exe will convert successfully if the > codes that use scipy.plt are commented out. > > Thank you. > > Phil > > > > Atatched py2exe error messages: > > > > running py2exe > running build > running build_scripts > not copying hat.pyw (up-to-date) > running install_scripts > not copying build\scripts\hat.pyw (output up-to-date) > +---------------------------------------------------- > | Processing script hat.pyw with py2exe-0.2.6 > +---------------------------------------------------- > Searching modules needed to run 'hat.pyw' on path: > ['C:\\Pho\\hat\\wxwin\\build\\bdist.win32\\winexe\\lib\\usr\\Python21', > '', 'H:\\python\\Lib', 'C:\\usr\\Python21\\Pythonwin', > 'C:\\usr\\Python21\\win32', 'C:\\usr\\Python21\\win32\\Lib', > 'C:\\usr\\Python21', 'C:\\usr\\Python21\\DLLs', > 'C:\\usr\\Python21\\lib', 'C:\\usr\\Python21\\lib\\plat-win', > 'C:\\usr\\Python21\\lib\\lib-tk', 'C:\\usr\\Python21\\Numeric', > 'C:\\usr\\Python21\\PPM'] > warning: install: modules installed to > 'build\bdist.win32\winexe\lib\usr\Python21\', which is not in Python's > module search path (sys.path) -- you'll have to change the search path > yourself > Traceback (most recent call last): > File "setup.py", line 14, in ? > scripts = ["hat.pyw"] > File "C:\usr\Python21\lib\distutils\core.py", line 138, in setup > dist.run_commands() > File "C:\usr\Python21\lib\distutils\dist.py", line 899, in > run_commands > self.run_command(cmd) > File "C:\usr\Python21\lib\distutils\dist.py", line 919, in > run_command > cmd_obj.run() > File "C:\usr\Python21\py2exe\py2exe.py", line 312, in run > mf.run_script(script) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 98, in > run_script > self.load_module('__main__', fp, pathname, stuff) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in > load_module > self.scan_code(co, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in > scan_code > self.import_hook(name, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in > import_hook > q, tail = self.find_head_package(parent, name) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in > find_head_package > q = self.import_module(head, qname, parent) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in > import_module > m = self.load_module(fqname, fp, pathname, stuff) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in > load_module > self.scan_code(co, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in > scan_code > self.import_hook(name, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in > import_hook > q, tail = self.find_head_package(parent, name) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in > find_head_package > q = self.import_module(head, qname, parent) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in > import_module > m = self.load_module(fqname, fp, pathname, stuff) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 250, in > load_module > m = self.load_package(fqname, pathname) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 324, in > load_package > self.load_module(fqname, fp, buf, stuff) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in > load_module > self.scan_code(co, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in > scan_code > self.import_hook(name, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in > import_hook > q, tail = self.find_head_package(parent, name) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in > find_head_package > q = self.import_module(head, qname, parent) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in > import_module > m = self.load_module(fqname, fp, pathname, stuff) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 267, in > load_module > self.scan_code(co, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 287, in > scan_code > self.import_hook(name, m) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 110, in > import_hook > q, tail = self.find_head_package(parent, name) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 151, in > find_head_package > q = self.import_module(head, qname, parent) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 239, in > import_module > m = self.load_module(fqname, fp, pathname, stuff) > File "C:\usr\Python21\py2exe\tools\modulefinder.py", line 254, in > load_module > co = compile(fp.read()+'\n', pathname, 'exec') > File "", line 30 > """ > > ^ > SyntaxError: invalid syntax From phd at phd.pp.ru Tue Oct 2 04:16:22 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Tue, 2 Oct 2001 12:16:22 +0400 Subject: =?koi8-r?B?8sXLzMHNwSDXINLFx8nPzsHM2M7PyiDQ0sXT08U=?= In-Reply-To: ; from arp@europe.com on Tue, Oct 02, 2001 at 04:38:01AM +0400 References: Message-ID: <20011002121622.F17018@phd.pp.ru> On Tue, Oct 02, 2001 at 04:38:01AM +0400, ARP RF wrote: > E-Market Research Inc It was russian spam. Please everyone complain to postmaster at attglobal.net (information from SpamCop.NET). Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From smarsh at hotmail.com Sun Oct 21 01:02:35 2001 From: smarsh at hotmail.com (scott) Date: Sun, 21 Oct 2001 05:02:35 GMT Subject: silly idea - interesting problem References: <3BD248BA.2163BBDB@hotmail.com> <9qtijq$miu$1@tyfon.itea.ntnu.no> Message-ID: <3BD256E7.B35E63D7@hotmail.com> Magnus Lie Hetland wrote: > > "scott" wrote in message > news:3BD248BA.2163BBDB at hotmail.com... > > > > Stefan Antoni wrote: > > > > > > i got a silly idea about a small script which takes to strings (lets say > > > "test" and "dust") and mixes them to "tdeusstt". > > > i tried to code it because i thought it would be easy, but now i cannot > > > find out _how_ to do it ;) > > > > > > i tried to "list()" the string and mix the items. but ... > > > > > > Anybody has a hint or even a solution? > > > > > > > Here's a back to basics solution: > > > > firstWord = 'test' > > secondWord = 'dust' > > i = 0 > > while i < len(firstWord): > > print firstWord[i], secondWord[i], > > i = i+1 > > This will give spaces between every word... Since we are nit-picking, the spaces are actually between each letter ;-) The point I was trying to make was that spraying a new Python user with marginally readable code might be good for your ego but not much help for learning the basics. I admit that if my code actually met the requirements my argument would have been a bit more persuasive :-) Here is the (as specified) no space version: firstWord = 'test' secondWord = 'dust' endString = '' i = 0 while i < len(firstWord): endString = endString + firstWord[i] + secondWord[i] i = i+1 print endString -- Colorless green ideas sleep furiously. Chomsky From gh_pythonlist at gmx.de Thu Oct 11 11:37:20 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 11 Oct 2001 17:37:20 +0200 Subject: help: Crossplattform audio functionality in Python In-Reply-To: ; from olov_johansson_not_for_sale@mail.ru on Thu, Oct 11, 2001 at 03:03:37PM +0000 References: Message-ID: <20011011173718.A12013@lilith.hqd-internal> On Thu, Oct 11, 2001 at 03:03:37PM +0000, Olov Johansson wrote: > Hello all, > I recently had my first serious look at Python and like it for many reasons. > I'm trying to get a grip on it's capabilities and limits and as a result of > that..: > > How is the crossplatform sound support? From what I found in the > documentation (2.1.1) there is Al (SGI), sunaudiodev (SunOS) and winsound > (win32 and very limited). I want something that gives me a soundbuffer I can > write to, and I'd like it to work on at least Linux (OSS/ALSA) and Windows. > [...] pygame (http://www.pygame.org/) contains a sound library that works on *nix and Windows. It is based on several SDL libraries, so for cross-platform sound only, it might be overkill. But it's cool stuff nevertheless. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From david.jay.jackson at wcox.com Fri Oct 19 23:42:37 2001 From: david.jay.jackson at wcox.com (Jackson) Date: Fri, 19 Oct 2001 21:42:37 -0600 Subject: Solaris and tinter: cann't fint curses Message-ID: <200110192142.AA2031914@wcox.com> I'm tyring to use the tinter (curses gui) module with 2.2.1 on a Solaris-2.8. If I load the curses seperatly it works, but fails if when import tinter with: Thanks. David >>> import tinter Traceback (most recent call last): File "", line 1, in ? File "./tinter.py", line 66, in ? import curses # I use curses because I'm reasonably sure everyone has it File "/usr/local/lib/python2.1/curses/__init__.py", line 15, in ? from _curses import * ImportError: No module named _curses >>> From tjreedy at home.com Fri Oct 26 02:15:36 2001 From: tjreedy at home.com (Terry Reedy) Date: Fri, 26 Oct 2001 06:15:36 GMT Subject: A small inconsistency in syntax? References: <4vXB7.155961$5A3.54581770@news1.rdc2.pa.home.com> <7x2C7.156751$5A3.54994939@news1.rdc2.pa.home.com> <3BD8C9F6.BBBD605A@cosc.canterbury.ac.nz> Message-ID: "Guido van Rossum" wrote in message news:cp7ktjcbzx.fsf at cj20424-a.reston1.va.home.com... > Greg Ewing writes: > > In the case in question, i.e. > > > > () = () > > > > the patterns clearly do match. And, every name in > > the LHS has a corresponding value in the RHS. The > > numbers of both these things happen to be 0, but > > so what? > > I think Michael Abbot is quite right. There's no > > reason this shouldn't be a legitimate, albeit > > degenerate, case of tuple unpacking. > FWIW, I agree. I just never thought of this. > > --Guido van Rossum (home page: http://www.python.org/~guido/) As I understand it, the rule is this: if item on LHS is tuple rather than name, then corresponding object on RHS must be a tuple, which will then be seen as collection rather than object in itself and consequently unpacked for matching to items within LHS tuple. Allowing for null matches and applying the rule recursively, a,() = 1,() should also be legal, as Abbot also expected. I can imagine some use to () = function() which I presume would raise exception if function() returned anything other than (). Terry J. Reedy From clpy at snakefarm.org Tue Oct 9 05:05:07 2001 From: clpy at snakefarm.org (Carsten Gaebler) Date: Tue, 09 Oct 2001 11:05:07 +0200 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> Message-ID: <3BC2BDC3.20A41F38@snakefarm.org> Thanks for all the answers. Seems as if I hadn't been specific enough about what I was looking for. It would be nice if there was some builtin dictionary magic that would allow "%(foo) %(bar)" % magic(dict1, dict2, ...) where in case of duplicate keys the leftmost dictionary would be preferred. Perhaps the builtin dictionary() class could be extended so that it accepts more than one dictionary argument? cg. From max at alcyone.com Fri Oct 5 22:20:07 2001 From: max at alcyone.com (Erik Max Francis) Date: Fri, 05 Oct 2001 19:20:07 -0700 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> Message-ID: <3BBE6A57.FD354FE3@alcyone.com> Paul Rubin wrote: > I think there's a simple way to represent quaternions as 3x3 matrices. > So you could probably just store them that way and use NumPy for the > arithmetic. ... which rather defeats the purpose for using quaternions in the first place. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Perfect situations must go wrong \__/ Florence, _Chess_ Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html A new, virtual planet, every day. From vincent_a_primavera at netzero.net Wed Oct 24 09:28:46 2001 From: vincent_a_primavera at netzero.net (Vincent A.Primavera) Date: Wed, 24 Oct 2001 13:28:46 +0000 Subject: MySQLdb... Message-ID: <20011024132847.2B0672AD3D@del-vap-bos.ralphpill.com> Hello, I am experiencing a problem using MySQLdb with release 2.1.1 of Python... The error is listed below. If anyone has any suggestions of how I can "fake out" MySQLdb or what else I need to do I would greatly appreciate it. Thank you, Vincent A. Primavera. WARNING: Python C API version mismatch for module _mysql: This Python has API version 1010, module _mysql has version 1007. From cpr at emsoftware.com Mon Oct 15 15:58:32 2001 From: cpr at emsoftware.com (Chris Ryland) Date: 15 Oct 2001 12:58:32 -0700 Subject: why no RealPython yet? Message-ID: <8827e15d.0110151158.1a1a8c36@posting.google.com> If you're aware of the RAD tool RealBasic for the Mac (which produces single-file native executables for MacOS 9, X (Carbon-based) and Win32, without source changes), I wonder if you have any thoughts of why a similarly productive tool hasn't appeared for Mac/Win based on Python? If you're not aware of RealBasic, take a look (www.realbasic.com). It's quite impressive for what it does. And, yes, it's not as powerful a tool in some sense as something like BlackAdder, but it's oh so much more approachable (which is the point of RAD tools), and it produces all three platform binaries with one click, which is even more the point of tools for people in the commercial world whose targets are pretty much limited to Win32 and MacOS 8/9 and X. I'm almost tempted to produce a clone based on Python... From anthony at interlink.com.au Thu Oct 18 03:58:04 2001 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 18 Oct 2001 17:58:04 +1000 Subject: Bugfix releases (RE: profiler results for __getattr__, am I reading this correctly ? ) In-Reply-To: Message from "Tim Peters" of "Wed, 17 Oct 2001 22:57:09 -0400." Message-ID: <200110180758.f9I7w4M00794@mbuna.arbhome.com.au> >>> "Tim Peters" wrote > The bugfix release process is the topic of Aahz's PEP 6, who may have > believed that titling it "Bug Fix Releases" was enough clue : Ah, that cunning "hidden in plain sight" approach. Who'd have thought. It still doesn't cover the process of deciding what would go in the patch release... I know that I'd be happier upgrading to 2.1.2 than 2.2 in the next couple of months - and given the peasants-are-revolting sentiment of c.l.py at the moment, I doubt I'm the only one... How would this sound as a first cut at a what-goes-in-and-what-stays: a) bugfixes. b) no new modules, no new packages. c) no new methods on classes, unless they're bugfixes. d) if the bug fix relies on some 2.2-ism, then it's either rewritten, or ignored and relnoted Anthony From loewis at informatik.hu-berlin.de Tue Oct 30 07:36:51 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 30 Oct 2001 13:36:51 +0100 Subject: DOM4J, JDOM or Castor implementation in Python References: Message-ID: Firestar writes: > Just curious: are there any similar implementation for > Java XML tools such as DOM4J, JDOM or Castor > data-binding for Python? I'm not aware of Java XML tools for Python, but I normally find the Python XML tools for Python to be sufficient. Most prominently, xml.dom.minidom is part of the standard library. If that is not sufficient, please have a look at pyxml.sf.net. Regards, Martin From skip at pobox.com Tue Oct 16 08:53:36 2001 From: skip at pobox.com (Skip Montanaro) Date: Tue, 16 Oct 2001 07:53:36 -0500 Subject: Psyco Specializing Compiler In-Reply-To: <2542dd24.0110160437.60eeb642@posting.google.com> References: <3bc4d2e4$0$36473$ba620e4c@news.skynet.be> <2542dd24.0110160437.60eeb642@posting.google.com> Message-ID: <15308.11728.46126.633139@beluga.mojam.com> aotto> if you wan't to have a look to a full working script "Compiler" aotto> don't forget to visit: ... Why do you keep posting teasers to this list? It appears you don't support Python, and when I visited last time I saw no indication that you planned to. In addition, your tools aren't open source, so it's unlikely they would appeal to a broad subset of Python's user population. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From joseph at arbitrary.org Wed Oct 17 18:15:23 2001 From: joseph at arbitrary.org (Joseph Santaniello) Date: Wed, 17 Oct 2001 15:15:23 -0700 Subject: Help optimize a script? In-Reply-To: <3Nkz7.138277$5A3.44609227@news1.rdc2.pa.home.com> References: <3Nkz7.138277$5A3.44609227@news1.rdc2.pa.home.com> Message-ID: On Wed, 17 Oct 2001 at 19:15, Terry Reedy wrote: [snip] > > forms = { > 'cob': lambda x: (strip(x[0:3], strip(x[3:9], ..., strip(x[22:30]), > ...} > > (This conversion can be done with a fairly simple function.) Then, > your program reduces to > > new = forms['cob'] > for line in file.xreadlines(): > print '\t'.join(new(line)) [snip] Thanks Terry, that resulted in a 5x speed increase! After compling 2.1.1 for HP-UX so I would have access to the join() method of sting, I started to wonder how much of this speed increase (if any) is from just using 2.1.1 over 1.5.2 ? Any ideas? Joseph From tim.one at home.com Sun Oct 21 17:29:07 2001 From: tim.one at home.com (Tim Peters) Date: Sun, 21 Oct 2001 17:29:07 -0400 Subject: Random from Dictionary In-Reply-To: Message-ID: [Tim] > ... > In 2.2 you could use a more memory-efficient scheme via iterating over > d directly: > > def random_from_dict(d, x): > "Return and remove x random (k, v) pairs from d." > from random import random > n = float(len(d)) # float() so x/n later doesn't truncate to 0 > if not 1 <= x <= n: > raise ValueError("go away") > result = [] > for k in d: > # Choose this item with probability x/n. > if random() <= x/n: > result.append((k, d[k])) > x -= 1 > if x == 0: > break > n -= 1 > for k, v in result: > del d[k] > return result [Martin von Loewis] > Does that give each key in the dictionary the same probability of > being picked (assuming random() distributes uniformly)? Yes. > If yes, is there some easy way to "see" that this is the case? Not an entirely convincing easy way that I know of. I view it like this: The first element is obviously chosen with probability x/n, and that's obviously correct. If it's not chosen, then we need to pick an x-combination of the n-1 remaining elements at random, so decrementing n alone "obviously" does the right thing to reduce the problem to this new case. OTOH, if we do choose the first element, then what remains is to choose a random x-1 combination of the remaining n-1 elements, so decrementing both x and n is "obviously" correct to reduce the problem to that new case. You can turn that into a formal proof without *much* difficulty. "Algorithm S" in Knuth Vol 2 Ed 3 Section 3.4.2 is a more confusingly (to my mind) coded version of this. The text remarks that the algorithm appears "to be incorrect", but leaves it to a series of detailed exercises to prove it's unbiased. Here's a start: again, the first element is obviously chosen with probability x/n. It is or it isn't picked. If it is, the 2nd element is chosen with (conditional) probability x/n * (x-1)/(n-1); if it isn't, with cond prob (n-x)/n * x/(n-1). Add those together to get the prob that the 2nd element is chosen: x*(x-1) (n-x)*x x*(x-1+n-x) x*(n-1) x ------- + ------- = ----------- = ------- = - n*(n-1) n*(n-1) n*(n-1) n*(n-1) n Now wave your hands a lot for the rest, or break down and do some actual math . > If no, could one design an algorithm that iterates over a dictionary > only once, still offers the same probability to each key? Already done by the above. A more efficient way, but harder to work out the details, is to exploit that there are comb(n, x) possible x- combinations of the integers in range(n). Establish a computable bijection beteen all x-combinations of range(n) and the integers in range(comb(n, x)). Pick one integer from range(comb(n, x)) at random, and compute the corresponding x-combination of range(n) under the bijection. This can be used as a list of indices to suck out x elements from d.items(). playing-the-odds-ly y'rs - tim From quinn at seniti.ugcs.caltech.edu Fri Oct 5 20:00:00 2001 From: quinn at seniti.ugcs.caltech.edu (Quinn Dunkan) Date: 6 Oct 2001 00:00:00 GMT Subject: Boy do REs ever suck sometimes... References: Message-ID: >> On Friday 05 October 2001 16:45, Ignacio Vazquez-Abrams wrote: >> > Here's the problem I'm having with REs. When I use an RE like '^[0-9]+$' it >> > matches both '123' and '123\n'. How can I get it to not match the string >> > with the newline? Note that, for that particular RE, you are probably better off with the isidigit() method. It really depends on the data you're parsing, but I almost always prefer either split, join, isdigit, replace, find, and my own functions or an actual parser (hand coded in the past, but SPARK and mxTextTools look interesting) to regexps. Generators should make parser-writing even more fun. REs can work nicely for some tasks, but they definately have that "hammer that makes everything look like a thumb" thing going on (see the scanf thread). From jhauser at ifm.uni-kiel.de Mon Oct 15 04:14:42 2001 From: jhauser at ifm.uni-kiel.de (Janko Hauser) Date: 15 Oct 2001 10:14:42 +0200 Subject: BINARY DATA, SCIPY, MIO (...again) References: Message-ID: <87n12t8glp.fsf@lisboa.ifm.uni-kiel.de> This seems strange. What happens if you start a vanilla python session and import the types module. Python 2.1 (#1, Jul 20 2001, 22:26:10) [GCC 2.95.4 20010319 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import types >>> dir(types) ['BufferType', ... , 'ListType', ... , 'TupleType', ...] And your loop is definitely very slow. It would be better to fread(2000,'l') and create the two wanted arrays by slicing. HTH, __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser at ifm.uni-kiel.de 24105 Kiel, Germany From db3l at fitlinxx.com Mon Oct 8 16:41:42 2001 From: db3l at fitlinxx.com (David Bolen) Date: 08 Oct 2001 16:41:42 -0400 Subject: Status of SOAP and Python. References: Message-ID: Gabriel Ambuehl writes: > So what do you recommend to use instead of SOAP? XML-RPC? Classic RPC > (*uaah*)? I think it depends on what you need out of your RPC layer. If I recall correctly, SOAP certainly aims higher than XML-RPC in terms of object invocation as opposed to simple RPC, so their can be advantages there. But that also introduces complexity. Also, there's the question of whether you really need compatibility with other systems/languages. We've used XML-RPC successfully for internal communication in a scheduling system we use, but as it turned out over time, the system remained soley Python, so the interoperability issue turned out not to be one, and in retrospect having to work a bit around issues such as not supporting None and dictionaries must use string keys could have been unnecessary. But it did certainly get things rolling quickly is easy to use from Python. For another remote site management tool, where information transferred and transparency to upper level Python layers was most important (and interoperability outside of Python wasn't), we just went to a simple locally written RPC mechanism where the payload of the RPC was a binary pickle compressed with zlib. Works very well and can pass anything the Python scripts on either side may need to deal with (we haven't had to do any custom marshalling yet although that may happen if we run into an object that won't serialize by default). -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From skip at pobox.com Wed Oct 3 21:31:34 2001 From: skip at pobox.com (Skip Montanaro) Date: Wed, 3 Oct 2001 20:31:34 -0500 Subject: SQL/Python question -- slow... What is the fixed cost? In-Reply-To: <3BBB7DFD.25217E1A@iems.nwu.edu> References: <3BBB7DFD.25217E1A@iems.nwu.edu> Message-ID: <15291.48118.900258.317603@beluga.mojam.com> Leonardo> I am looking at the output of the python profiler, and I Leonardo> notice that all the queries take .001 cpu/sec. per call. Not Leonardo> only the more complex query above, but also a query which only Leonardo> filters over one small table. You're not measuring what you think you're measuring. The .001 cpu seconds per call is in the Python process. It says nothing about how long it takes the MySQL database to process the query. If you're worried about performance you should be profiling the queries in the database server, not the Python client. Check out the MySQL docs and in particular the EXPLAIN statement. -- Skip Montanaro (skip at pobox.com) http://www.mojam.com/ http://www.musi-cal.com/ From gh_pythonlist at gmx.de Wed Oct 10 09:16:28 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Wed, 10 Oct 2001 15:16:28 +0200 Subject: How to install on NT without write permissions to c:\winnt In-Reply-To: <81363cf9.0110100106.d3202c3@posting.google.com>; from michael.niemetz@he2.de on Wed, Oct 10, 2001 at 02:06:22AM -0700 References: <81363cf9.0110100106.d3202c3@posting.google.com> Message-ID: <20011010151626.A1620@lilith.hqd-internal> On Wed, Oct 10, 2001 at 02:06:22AM -0700, Michael Niemetz wrote: > Hello! > > I want to install Python on a Win NT machine at which I do not have > administrator privileges and - even worse - have no write permission > in the c:\winnt directory which breaks the install process. > > Is there any way to get Python installed without contacting our local > support > team and filling out numerous forms? You could install the PythonWare PY21 Python distribution. http://www.pythonware.com/products/python/index.htm It has a dead simple installer that simply unzips all the files in a directory. I have read that PythonLabs now have access to a newer version of the Wise Installer that also enables non-admin installs. But IIRC think this is only used in the latest 2.2 alphas and not yet in 2.1.1. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From dale at riverhall.NOTHANKS.co.uk Tue Oct 30 09:04:56 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Tue, 30 Oct 2001 14:04:56 +0000 Subject: XML can't read Unicode shock horror. News at 11. Message-ID: Dale Strickland-Clark wrote: >Given that XML is very Unicode friendly, this seems a rather odd >limitation. > >>>> import xml.dom.minidom >>>> dom = xml.dom.minidom.parseString(u'') >Traceback (most recent call last): > File "", line 1, in ? > File "c:\python21\lib\xml\dom\minidom.py", line 915, in parseString > return _doparse(pulldom.parseString, args, kwargs) > File "c:\python21\lib\xml\dom\minidom.py", line 901, in _doparse > events = apply(func, args, kwargs) > File "c:\python21\lib\xml\dom\pulldom.py", line 299, in parseString > buf = StringIO(string) >TypeError: expected string, unicode found >>>> I see that this is probably the same as Python bug #216388 which has been around for over a year and been given a low priority (3). Is there any chance that this might be elevated? Non-unicode XML is a bit restrictive. :-( -- Dale Strickland-Clark Riverhall Systems Ltd From greg at cosc.canterbury.ac.nz Tue Oct 30 22:41:16 2001 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 31 Oct 2001 16:41:16 +1300 Subject: Unpacking extension (Re: A small inconsistency in syntax?) References: Message-ID: <3BDF72DC.B0C3D61E@cosc.canterbury.ac.nz> James_Althoff at i2.com wrote: > > Did you mean > > def __unpack__(self): > return self.x, self.y Yes, sorry. > And is Pair(a,b) on the LHS any *callable*? Or must the object Pair be a > type object or class object only? It must be a type or class object. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand To get my email address, please visit my web page: http://www.cosc.canterbury.ac.nz/~greg From tim.one at home.com Tue Oct 9 21:01:43 2001 From: tim.one at home.com (Tim Peters) Date: Tue, 9 Oct 2001 21:01:43 -0400 Subject: Why not 3.__class__ ? In-Reply-To: Message-ID: In case anyone is still wondering, you will never be able to write 3.attribute in Python without getting a richly deserved SyntaxError for your trouble. 3 .attribute works fine, as does the ever-popular (1+2).attribute and the less popular 3\ .\ attribute and the increasingly popular (3 . attribute) We're still debating whether to require that floating zero be spelled 42j.real helpfully y'rs - tim From loewis at informatik.hu-berlin.de Sun Oct 21 08:39:13 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 21 Oct 2001 14:39:13 +0200 Subject: Dictionary from list? References: Message-ID: Jim Correia writes: > I wasn't insisting that there must be on in python, just asking if there > was :-) I think this thread would have died quite early if you did just that... Instead, after being told that this conversion is not supported as a built-in, you responded "This is quite unfortunate." People then have read this into insisting. Regards, Martin From nhv at yahoo.com Thu Oct 4 12:53:24 2001 From: nhv at yahoo.com (Norman Vine) Date: 4 Oct 2001 09:53:24 -0700 Subject: mx.ODBC/Cygwin/Python 2.1.1 References: Message-ID: <20db98f.0110040853.1aecf6f2@posting.google.com> "Steve Holden" wrote in message news:... > Has anyone built the mxCommercial extensions for Cygwin? I'm having many > problems which look so fundamental I'm hoping they have a really simple fix. > This is where they begin: I haven't tried to build the latest mxCommercial extensions but I have built earlier versions using method 2 as outlined at http://www.vso.cape.com/~nhv/files/python/myDistutils.txt Cheers Norman From emile at fenx.com Sat Oct 27 12:46:40 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Oct 2001 09:46:40 -0700 Subject: Question: Event driven programming References: <3bdad71d$1_3@corp-goliath.newsgroups.com> Message-ID: <9reom4$t2hbi$1@ID-11957.news.dfncis.de> Take a look in the Graphics and Development environments sections of http://www.rimbault.net/python/ . I'm sure you'll find something. BTW, Thanks to whoever put this page together. -- Emile van Sebille emile at fenx.com --------- "K?roly Ladv?nszky" wrote in message news:3bdad71d$1_3 at corp-goliath.newsgroups.com... > Does Python have means for event driven programming? > It's a neat feature in VB, I wish there was something similar in Python. > Thanks for any pointers. > > Cheers > > K?roly > > > ____________________________________________________________________________ __ > Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net From gh_pythonlist at gmx.de Sat Oct 13 08:11:27 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 13 Oct 2001 14:11:27 +0200 Subject: PostgreSQL Interface Query In-Reply-To: <60F8F7C0-BF98-11D5-A0A8-000393031882@shangri-la.dropbear.id.au>; from zen@shangri-la.dropbear.id.au on Sat, Oct 13, 2001 at 03:08:46PM +1000 References: <3BC7BD91.A604728C@iinet.net.au> <60F8F7C0-BF98-11D5-A0A8-000393031882@shangri-la.dropbear.id.au> Message-ID: <20011013141127.A1010@lilith.hqd-internal> On Sat, Oct 13, 2001 at 03:08:46PM +1000, Stuart Bishop wrote: > On Saturday, October 13, 2001, at 02:05 PM, John Bell wrote: > > [...] I am leaning towards pypgsql [...] > > I got as far as checking its threadsafety - level 1 compliance > is a major lack to me. I will look into the thread level compliance thing, but for now I only remember a message from the main developer Bill Allie, which sounds reasonable to me: http://mail.vex.net:99/pipermail/pygresql/2001-July/000420.html > I also stick to using the DB API, so I can't see any improvement in > functionality to PoPy or Psycopg. Yes, the Python-PostgreSQL land is quite fragmented. The modules differ in several things, among them licenses, features, DB-API compliance and portability. > If you only want a thread level 1 compliant driver, is there any real > advantage over using PyGreSQL which is shipped as part of PostgreSQL? PyGreSQL is in my experience buggy and little maintained. The DB-API stuff is really a wrapper on the the old proprietary interface, and is relatively new and probably not used very much. Somehow it got into PostgreSQL, but the most likely reason is IMHO that it was the only module being available at the time, not because it is the best one today. > These issues may be the reason there is a lack of commentary on > pypgsql. The other reason is that it must be a secret, as it still > hasn't made it onto the DB-SIG's modules list. I've notified the DB-SIG coordinator and python.org webmaster. Some modules aren't mentioned on the DB-SIG's modules list, but are listed on the relevant dmoz.org page: http://dmoz.org/Computers/Programming/Languages/Python/Modules/Database/ Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From rparnes at megalink.net Thu Oct 11 20:18:56 2001 From: rparnes at megalink.net (Bob Parnes) Date: Thu, 11 Oct 2001 19:18:56 -0500 Subject: Event Problem in Tkinter References: Message-ID: Laura Creighton wrote: > I tried your program on my debian linux system under KDE, and it worked > great. Output follows. One extra Focus-In for I just moved to another > window and back. > > What operating system and what window manager are you using? > > Laura > -------------------------------- > > lac at ratthing-b246:~/scratch$ python rparnes.py > > List of Entry Widgets > .139090996.135535468 > .139090996.139118476 > .139090996.139639188 > .139090996.139287116 > Event: ButtonPress, coordinates: 208, 659; widget: .139090996.135535468 > Event: FocusIn, coordinates: 1076223268, 139638232; widget: > .139090996.135535468 > --------------------------------------------------------------------------- > Event: KeyPress, coordinates: 209, 660; widget: .139090996.135535468 > Event: FocusIn, coordinates: 1076223268, 139638232; widget: > .139090996.139118476 > --------------------------------------------------------------------------- > Event: FocusIn, coordinates: -1073745224, 0; widget: .139090996.139118476 > --------------------------------------------------------------------------- > Event: KeyPress, coordinates: 297, 666; widget: .139090996.139118476 > Event: FocusIn, coordinates: 1076223268, 139638232; widget: > .139090996.139639188 > --------------------------------------------------------------------------- > Event: KeyPress, coordinates: 297, 666; widget: .139090996.139639188 > Event: FocusIn, coordinates: 1076223268, 139638232; widget: > .139090996.139287116 > --------------------------------------------------------------------------- > > Thanks for responding. I am running debian 2.2r3 and KDE, version 2.x. So we may be operating under the same conditions. Perhaps it's a hardware problem. Or if you have any other suggestions, I'd appreciate hearing them. -- Bob Parnes rparnes at megalink.net From mwh at python.net Fri Oct 19 05:00:02 2001 From: mwh at python.net (Michael Hudson) Date: Fri, 19 Oct 2001 09:00:02 GMT Subject: dynamic call of a function References: <3BCFE666.C8C6136C@c-s.fr> Message-ID: anthony harel writes: > I have got a string that contains the name of the function I > want to call but I don't want to do something like this : [schnipp] > Is it possible to do sommething like that : > ch = "foo" > apply(ch, ( ))??? Well, there's eval(ch)() but that's rather horrible. vars()[ch]() is, possibly, better. More context please. What are you really trying to do? Cheers, M. -- ZAPHOD: You know what I'm thinking? FORD: No. ZAPHOD: Neither do I. Frightening isn't it? -- The Hitch-Hikers Guide to the Galaxy, Episode 11 From johnroth at ameritech.net Wed Oct 31 23:58:02 2001 From: johnroth at ameritech.net (John Roth) Date: Wed, 31 Oct 2001 20:58:02 -0800 Subject: Underscore data hiding (was python development practices?) References: <7xitcwpq9r.fsf@ruckus.brouhaha.com> <9rpbk1$19rg$1@nntp6.u.washington.edu> Message-ID: "Skip Montanaro" wrote in message news:mailman.1004551677.1783.python-list at python.org... > > Russell> My understanding is that a double underscore is required for > Russell> Python to automagically mangle the name. On the other hand, two > Russell> postings now suggest that a single underscore is sufficient. > > Russell> If double underscore is required, then it seems to me this is a > Russell> very common misconception that a single is sufficient. It might > Russell> be worth changing. > > A double leading underscore is requred to coax Python into mangling an > attribute. I think a lot of people use a single underscore as a simple cue > for themselves and other programmers that an attribute isn't meant to be > part of the public interface without messing up the actual name, so it can > be used easily in subclasses. It also 'hides' the names from a 'from import *' construct. > -- > Skip Montanaro (skip at pobox.com) > http://www.mojam.com/ > http://www.musi-cal.com/ > From john.thingstad at chello.no Sun Oct 21 17:59:58 2001 From: john.thingstad at chello.no (John Thingstad) Date: Sun, 21 Oct 2001 23:59:58 +0200 Subject: Ops: corrected prime algorithm Message-ID: <20011021222419.BTCF12720.mta01@mjolner> Just checked my own algorithm and found several mistakes. Here is the correct algorithm: def prime(n): set = [2] + range(3,n, 2) for n in range(3, int(math.sqrt(n))+1, 2): set = [x for x in set if x == n or x % n != 0] return set From gh_pythonlist at gmx.de Tue Oct 23 04:18:40 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 23 Oct 2001 10:18:40 +0200 Subject: POLL in different OSes In-Reply-To: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com>; from lucio@movilogic.com on Mon, Oct 22, 2001 at 10:51:02PM -0300 References: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> Message-ID: <20011023101838.A561@lilith.hqd-internal> On Mon, Oct 22, 2001 at 10:51:02PM -0300, Lucio Torre wrote: > From the documentation: > > "The poll() system call, supported on most Unix systems" > > and my questions: > > a) is poll supported on Windows? > > my guess is no, but i hoping for a yes. It isn't. Unless, you're using Cygwin. Also, select only works with sockets on Windows. Wouldn't it be possible to emulate poll() with select()? I'd be glad to see a patch appear at Sourceforge if that's possible :-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From gh_pythonlist at gmx.de Tue Oct 9 13:23:30 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 9 Oct 2001 19:23:30 +0200 Subject: ARGV and import ? In-Reply-To: <660c52de.0110090907.4017f907@posting.google.com>; from geek_girl@mailcity.com on Tue, Oct 09, 2001 at 10:07:38AM -0700 References: <660c52de.0110090907.4017f907@posting.google.com> Message-ID: <20011009192330.A3209@lilith.hqd-internal> On Tue, Oct 09, 2001 at 10:07:38AM -0700, J wrote: > Hi all, > > This is my first post to this group & I am also fairly new to python, > so please forgive me if this isn't the brightest question or the > appropriate venue. > > I would like to do the following: > import a module based on what is typed on the command line. > > I thought this would work: > import sys > recipes = sys.argv[1] > import recipes > > But, I get this error: > >> ImportError: No module named recipes > > Is there any way to pass the module name to import through an argv? I think this is one of the rare cases where an exec statement is appropriate: statement = "import %s as mod" % sys.argv[1] exec statement The import ... as ... imports the module and immediately "renames" it (in reality, it works on the dictionary sys.modules). So in the above example, you can use the imported module with the name "mod". Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From grahamd at dscpl.com.au Sat Oct 27 20:46:03 2001 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 27 Oct 2001 17:46:03 -0700 Subject: Question: Event driven programming References: <3bdad71d$1_3@corp-goliath.newsgroups.com> Message-ID: "K?oly Ladv?szky" wrote in message news:<3bdad71d$1_3 at corp-goliath.newsgroups.com>... > Does Python have means for event driven programming? > It's a neat feature in VB, I wish there was something similar in Python. As others have pointed out, it depends in what context you mean event driven programming. For a system probably quite removed from VB and GUI work but more suited to real time server side systems check out OSE. This can be found at "http://ose.sourceforge.net". There is also the "asyncore" module, but it doesn't go as far, although it is pure Python where OSE isn't. From rajarshi at seed.chem.psu.edu Wed Oct 3 18:26:51 2001 From: rajarshi at seed.chem.psu.edu (Rajarshi Guha) Date: Wed, 3 Oct 2001 18:26:51 -0400 Subject: using xmpl.parsers.expat Message-ID: <9pg388$hs72r$1@ID-91520.news.dfncis.de> Hi, I just installed the RPM for Python 2.2a3. When I try and do: >>> import xml.parsers.expat I get the following error: Traceback (most recent call last): File "", line 1, in ? File "/usr/src/build/42396-i386/install/usr/lib/python2.2/xml/parsers/expat.py", line 4, in ? ImportError: No module named pyexpat Where is the module pyexpat supposed to come from? How do I get it to work (I need it so I can start using SOAP) TIA -- -- Rajarshi Guha From emile at fenx.com Tue Oct 30 20:19:35 2001 From: emile at fenx.com (Emile van Sebille) Date: Tue, 30 Oct 2001 17:19:35 -0800 Subject: ReXX Style translate() function for strings ? References: <3281a460.0110301257.1a4d9a14@posting.google.com> Message-ID: <9rnk6n$usmo3$1@ID-11957.news.dfncis.de> "P Adhia" wrote in message news:3281a460.0110301257.1a4d9a14 at posting.google.com... > Hello, > > I am a newbie to python, and remain impressed with the power of the > language overall. There are however some little features that I am > used to in ReXX (default scripting language for mainframes) that I > could not find in python. > > ReXX has a translate() function that is much more powerful (and I > think coule be a nice addition to python; of course with a different > name) > > e.g. in ReXX, to change a date from yyyymmdd to mm/dd/yyyy is > trivially simple, > new_date = Translate('56/78/1234', old_date, '12345678') > > for formal syntax refert to, > http://users.comlab.ox.ac.uk/ian.collier/Docs/rexx_ref/F/BI > Easy enough to do... """ from http://users.comlab.ox.ac.uk/ian.collier/Docs/rexx_ref/F/BI TRANSLATE(string[,[tableo][,[tablei][,pad]]]) This function translates characters in string to other characters, or may be used to change the order of characters in a string. If neither translate table is specified, then the string is translated into uppercase. Otherwise each character of string which is found in tablei is translated into the corresponding character in tableo - characters which are not found in tablei remain unchanged. The default input table is XRANGE('00'x,'ff'x) and the default output table is the null string. The output table is padded or truncated in order to make it the same length as the input table, the default pad character being a blank. Examples: translate('abc123DEF') == 'ABC123DEF' translate('abbc','&','b') == 'a&&c' translate('abcdef','12','ec') == 'ab2d1f' translate('abcdef','12','abcd','.') == '12..ef' translate('4123','abcd','1234') == 'dabc' """ def translate(txt, tableo=None, tablei=None, pad=None): if tableo == tablei == None: return txt.upper() if pad == None: pad = ' ' if len(tableo) < len(tablei): tableo = tableo + pad*(len(tablei)-len(tableo)) for old, new in zip(tablei, tableo): txt = txt.replace(old, new) return txt assert translate('abc123DEF') == 'ABC123DEF' assert translate('abbc','&','b') == 'a&&c' assert translate('abcdef','12','ec') == 'ab2d1f' assert translate('abcdef','12','abcd','.') == '12..ef' assert translate('4123','abcd','1234') == 'dabc' -- Emile van Sebille emile at fenx.com --------- From richard at bizarsoftware.com.au Thu Oct 4 21:59:59 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Fri, 5 Oct 2001 11:59:59 +1000 Subject: Compiling 2.1.1 on Mac OS X 10.1 - test failures In-Reply-To: <0110051145150H.04291@ike> References: <0110051145150H.04291@ike> Message-ID: <0110051159590I.04291@ike> On Friday 05 October 2001 11:45, Richard Jones wrote: > Hi all, I'm trying to get python built on my mac powerbook running OS X > 10.1. I've edited the configure script so that LDSHARED is defined as > > LDSHARED= $(CC) $(LDFLAGS) -bundle -flat_namespace -undefined suppress > > for Darwin. I then ran configure with: > > OPT='-O3 -no-cpp-precomp' ./configure --with-suffix=.exe --with-dyld \ > --program-transform-name=s/.exe//g > > Compiling went OK. Then I tried "make test". Oh dear. > > test_largefile: took about 2.5 minutes. Top reported that it was mostly > "stuck" and occasionally "running" - using very little CPU and no disk that > I could detect (by the scientific aural detection process ;) When it was > finished, it printed the message "@test exists: 0". No idea if this normal > - my Linux machine doesn't have large file support. > > test_re: got a segfault (with -O3, -O2 and no optimisation at all) > > > Also, the program-transform-name didn't appear to do anything. My programs > were installed with the .exe extension. Another problem I'm having is that when I try to build extension modules, the -flat_namespace flag doesn't seem to be used. Richard From fdrake at acm.org Thu Oct 25 11:56:18 2001 From: fdrake at acm.org (Fred L. Drake) Date: Thu, 25 Oct 2001 11:56:18 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011025155618.C21CA28697@cj42289-a.reston1.va.home.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Experimental stylesheet changes -- code is now presented using proportional fonts (mostly since Guido really dislikes Courier). Please send comments on this change to me at python-docs at python.org. From scott_hathaway at riskvision.com Mon Oct 1 09:01:04 2001 From: scott_hathaway at riskvision.com (Scott Hathaway) Date: Mon, 1 Oct 2001 08:01:04 -0500 Subject: A question about pyhton and COM/DCOM References: <3BB6FA20.4030109@wanadoo.fr> Message-ID: Marc, Your question is very broad, but one thing that VB can do that Python cannot (in the COM world) is create an ActiveX control/ActiveX Document. Deployment has been easier with VB as well, but now, I think that you can create a standalone COM server component with Gordon's installer or py2exe. HTH, Scott "marc" wrote in message news:3BB6FA20.4030109 at wanadoo.fr... > Hi > > I 'am a python fan , and i use it a lot under linux and windows, > but today i have to enter to the World of COM/DCOM to realize a > production application. > my question is simple > What python can't do , that VB can in term off COM/DCOM and WIN32 API > (for the moment we don't want to use C++, our application is too little) > PS > > Dont try to convince me that VB is not a good language it knwo it ;) > > thank > > > Marc > From sholden at holdenweb.com Tue Oct 2 08:56:21 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 2 Oct 2001 08:56:21 -0400 Subject: list.append problem? References: Message-ID: "Bob Parnes" wrote ... > Bob Parnes wrote: [ ... ] > > As another newcomer I discovered this on my own. What is confusing, I > > think, is that it seems to apply only to empty objects. For example > > > >>>> a = b = [1, 2. 3] > >>>> a = [4, 5, 6] > >>>> b > > [1, 2, 3] > >>>> a.append(7) > >>>> a > > [4, 5, 6, 7] > >>>> b > > [1, 2, 3] > > > > In this case a and b are not bound to the same object. It seems to me that > > python treats empty objects differently from assigned objects. Or > > something like that, I'm probably not articulating it well. > > > > Sorry, I wrote too hastily > > >>> a = b = [1, 2, 3] > >>> a.append(4) > >>> a > [1, 2, 3, 4] > >>> b > [1, 2, 3, 4] > > The rule is the same, I used the wrong example. > Yup. In your first example you explicity rebound the name a, meaning that you could no longer use it to see changes to the original object, still bound to the name b. Once a beginner realises that all names in Python are essentially object references, this style becomes quite natural. Nice to see I'm no the only person to reply to my own posts! regards Steve -- http://www.holdenweb.com/ From barry at zope.com Tue Oct 23 23:01:09 2001 From: barry at zope.com (Barry A. Warsaw) Date: 23 Oct 2001 23:01:09 -0400 Subject: smtplib.SMTPDataError: (503, 'Error: need RCPT command') References: <3BD4F3E8.1E4B826B@cs.utwente.nl> <9r3nqd$r34a5$1@ID-11957.news.dfncis.de> Message-ID: >>>>> "EvS" == Emile van Sebille writes: EvS> Start with http://www.ietf.org/rfc/rfc821.txt Better make that RFC 2821! And note that RFC 2822 is also the latest revision of that seminal standard. http://www.faqs.org/rfcs/rfc2821.html http://www.faqs.org/rfcs/rfc2822.html -Barry From Sharriff.Aina at med-iq.de Tue Oct 30 08:44:06 2001 From: Sharriff.Aina at med-iq.de (Sharriff.Aina at med-iq.de) Date: Tue, 30 Oct 2001 13:44:06 +0000 Subject: os.system, backslash and commandline problem Message-ID: I am trying to code a small frontend for a commandline application using tkinter. Upon using os.system to call the commandline program with switches, I noticed that the switches were detected as files and not passed on, furthermore, passing paths on is somewhat problematic. #### code snippet, callback function for tkinter button def go_app(): ........textfile = inputfile.get() # inputfile is a tkintet entry widget ........textfile = string.replace(textfile, '/', '\\') ........editor = editorpath.get()# editorpath is a tkinter entry widget ........editor = string.replace(editor, '/', '\\') ........editor = editor + " -test" # switch test ........os.system(r"%s %s" % (editor, textfile)) ........ ############## end code I tried out a file that had "dangerous" characters: c:\the\boy.txt ("\t" TAB, "\b" BELL) the commandline application was correctly called but the file above caused a "file not found" error. I did a print to screen and saw that the path was trashed: " theoy.txt " Is there no sure way to run commandline executables with switches with os.sytem? also switches built into a command (example "c:\foo.exe -test") always fail, with a file not found error. This is very saddening, any clues? help? Thanks in advance Sharriff From richard at bizarsoftware.com.au Wed Oct 3 23:16:46 2001 From: richard at bizarsoftware.com.au (Richard Jones) Date: Thu, 4 Oct 2001 13:16:46 +1000 Subject: install on MacOS X 10.1? In-Reply-To: <3BBBC870.D0AE585E@nisus.com> References: <3BBBC870.D0AE585E@nisus.com> Message-ID: <01100413164608.04291@ike> On Thursday 04 October 2001 12:24, xxxx wrote: > I down-laoded 2.1.1 > > In the Makefile I found this suggested sequence > # ./configure > # make > # make test > # make install > > In the README it says > Mac OS X 10.0: Run configure with "OPT='-no-cpp-precomp' ./configure > --with-suffix=.exe --with-dyld". This generates executable > file: 'python.exe' (it cannot be named 'python' on an HFS or > HFS+ disk as the file name clashes with directory 'Python'). > The '-no-cpp-precomp' option prevents a large number of > compilation warnings. One of the regular expression tests > fails with a SEGV due to the small stack size used by default > (how to change this?), and the test_largefile test is only > expected to work on a Unix UFS filesystem (how to check for > this on Mac OS X?). The README neglects to take into account that the default shell for the Terminal program is tcsh, and the configure line given: OPT='-no-cpp-precomp' ./configure --with-suffix=.exe --with-dyld won't work in tcsh. Try running it in the bourne shell using the "sh" command first: [localhost:~/src/Python-2.1.1] richard% sh locahost% OPT='-no-cpp-precomp' ./configure --with-suffix=.exe --with-dyld and it should work. Note: Python 2.1.1 doesn't support Mac OS 10.1 very well at all. Read the thread at http://lists.zope.org/pipermail/zope-dev/2001-October/013416.html Richard From uwe at rocksport.de Tue Oct 16 11:48:27 2001 From: uwe at rocksport.de (Uwe Schmitt) Date: 16 Oct 2001 15:48:27 GMT Subject: hashval and Numpy Message-ID: <9qhksb$6raii$1@hades.rz.uni-sb.de> Hi, I'd like to use a dictionary with NumericalPython-arrays as keys. This does not work, because NumPy does not provide hashvals for arrays. But this could be easyly done, as tupels are hashable. So: how can I extend NumPy, so that arrays get a hashval ??? Greetings, Uwe. -- Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 D-66041 Saarbr?cken http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 From max at alcyone.com Sun Oct 7 04:11:39 2001 From: max at alcyone.com (Erik Max Francis) Date: Sun, 07 Oct 2001 01:11:39 -0700 Subject: Newbie Question References: <9pp1ca$ca6$1@slb4.atl.mindspring.net> Message-ID: <3BC00E3B.27017561@alcyone.com> Mel Brown wrote: > I am trying to get Python up and running. Among the modules that I > know that > I will need are math, cmath, and string. So import them: import math import cmath import string -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ It's hard to say what I want my legacy to be when I'm long gone. \__/ Aaliyah Alcyone Systems / http://www.alcyone.com/ Alcyone Systems, San Jose, California. From phd at phd.pp.ru Sun Oct 7 15:12:04 2001 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 7 Oct 2001 23:12:04 +0400 Subject: python process killed In-Reply-To: ; from sholden@holdenweb.com on Sun, Oct 07, 2001 at 01:13:26PM -0400 References: Message-ID: <20011007231204.C22060@phd.pp.ru> On Sun, Oct 07, 2001 at 01:13:26PM -0400, Steve Holden wrote: > > I was trying to run a giant program, which generates something like > > 200 million lines of data and write to a file. The python program > > stops in between and just displays "Killed" after terminating. > > > > Can i avoid this abrupt killing of the program and force it to run > > completely. > > > Another request for "psychic Python" debugging :-) > > You give no details of your environment: Windows (if so which flavor), > Python version? The word "killed" instead of Blue Screen suggests it is a kind of UNIX or GNU/Linux. > In the absence of more data, I might surmise you are running under Unix of > some flavor, and the shell is killing your process because it has exceeded > the process resource limits. Does this help at all? User limits (ulimits) is the first thing I suspect, too. Oleg. ---- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From odeme at airtel-atn.com Mon Oct 1 08:48:43 2001 From: odeme at airtel-atn.com (Olivier Deme) Date: Mon, 1 Oct 2001 13:48:43 +0100 (BST) Subject: Problem with linking embedding C application In-Reply-To: Message-ID: Thanks for the link to the demo application. Indeed it seems that there a plenty of libraries to link with... Something also really annoying: The libraries are located in an unusual place on my machine: /usr/local/lib/python2.1/config/ Plus, the fact that libpython*.a has its version number in the file name. That means that if our customer has a different version of Python, they won't be able to link our application! Usually, this should be solved by adding a symbolink link in a common directory. Sonething like: /usr/lib/libpython.a -> /usr/local/lib/python2.1/config/libpython2.1.a But this is not done during installation of Python. How are we supposed to know the version used by the people who are going to build our application? And no, I didn;t find any AUTOCONF macro to help resolving that problem... O. On Mon, 1 Oct 2001, Mads Bondo Dydensborg wrote: > On Mon, 1 Oct 2001, Olivier Deme wrote: > > > > I think that you may need to add at least > > > -lpthread -lm -lutil > > > to you ld line? > > > > > > I have a machine, where I need to do: > > > -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm > > > to be able to link with python. > > > > I can't believe I would have to link my application with something like pthread > > if I don't use it! After all, Python is supposed to make an application > > portable... Our C application is portable and needs to be shipped to a > > customer. So including things like "pthread", "nsl" and the-like would break > > the main reason why I decided to extend our application with some Python code. > > Well, it could still be portable, if you had a portable way of determing > this. Among different unixs and the like, you should have no troubles. I > have no idea about Windows, Macs and the like though. > > > > > As far as it seems, it looks like it is way easier to embed TCL code in C, > > rather than Python... > > Sad, since I prefer Python. > > TCL or Perl, yes. I would prefer Python as well; perl gives me headaches, > and tcl is annoying with its strings-strings-strings stuff. > > > > > Maybe, we are missing some information. Is there a hello world type application > > that would demonstrate embedding Python with C or C++? > > > > The Python sources "Demo/embed" - the demo.c file - but, it uses a static > Makefile. > > Mads > > -- > Mads Bondo Dydensborg. madsdyd at challenge.dk > 7) Sacrifice a small animal for Good Luck > > (step 7 of 8 in configuring the Open Source Global File System for Linux) > From andersjm at dancontrol.dk Tue Oct 16 04:12:13 2001 From: andersjm at dancontrol.dk (Anders J. Munch) Date: Tue, 16 Oct 2001 10:12:13 +0200 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: <3bcbebf3$0$42126$edfadb0f@dspool01.news.tele.dk> "Tim Peters" wrote in message news:mailman.1003176136.32708.python-list at python.org... > For anyone keen to play with this, Guido has uploaded a patch. It > requires surrounding parens in fewer places than has been discussed so far: > > > """It's hairier than expected because I'm trying to require you to put parentheses around it in some cases but not in others.""" For simplicity and consistency I think mandatory parentheses are better. Combine that with the form mentioned (though not preferred) by Michael Abbott elsewhere we get: x = (if e1: e2 else: e3) No new keyword, consistent with if-statement syntax and hence more intuitive to someone who knows Python but not a heap of other languages as well. And it's slightly more terse than the if-then-else form, which is important because terseness is the only reason to use a conditional expression in the first place. - Anders From leo at iems.nwu.edu Fri Oct 5 11:47:33 2001 From: leo at iems.nwu.edu (Leonardo B. Lopes) Date: Fri, 5 Oct 2001 10:47:33 -0500 (CDT) Subject: your mail In-Reply-To: <15293.5997.312594.517674@beluga.mojam.com> Message-ID: Dear Skip, Thanks! I think you've found the crux of the problem. Do you mind if I forward this message to the two groups? I think it would really help the other people on the threads. So if I understand correctly, you are right and the profiler is not measuring elapsed time but indeed only the cpu time used by the python process. So if it is blocked waiting for the mysql process, the time of the query is not taken into account. That would explain why the "easy" query and the "hard" query take about the same time according to the profiler. Is that precise? Leo. On Thu, 4 Oct 2001, Skip Montanaro wrote: > > Leonardo> Thanks for the tip. I actually have used the explain > Leonardo> statement. But are you sure about the profiler ignoring the > Leonardo> time taken by the query? Why would it be excluded from the > Leonardo> computation time? > > If the profiler is measuring cpu seconds, it will be measuring the > computation time of the Python process. The computation time of other > processes involved in the computation (possibly on other machines) just > isn't available to it. If it's measuring elapsed (wall clock) time, then > sure, it gives you some measure of the time it takes for the entire > computation to complete. However, that would include networking delays as > well as delays caused by either or both the Python program and the MySQL > database server not actually having the CPU. > > Leonardo> How would the profiler even be able to distinguish between > Leonardo> time waiting in a function for some external process and time > Leonardo> spent in the python interpreter itself? > > The profiler uses time.clock() if it's available, which is generally true on > most Unix-like systems. Again, on Unix-like systems, time.clock() returns > the CPU time of the current process, not the elapsed time. From the clock() > man page: > > DESCRIPTION > The clock() function returns an approximation of processor > time used by the program. > > Leonardo> I checked the manual for the profiler section. It says that > Leonardo> the profiler is activated by callbacks when functions are > Leonardo> called and when they return, so if a function is blocked > Leonardo> waiting for mysql, that time should be computed. > > It all depends. Take a look at the code in the Profile class's __init__ > method: > > if not timer: > if os.name == 'mac': > self.timer = MacOS.GetTicks > self.dispatcher = self.trace_dispatch_mac > self.get_time = _get_time_mac > elif hasattr(time, 'clock'): > self.timer = self.get_time = time.clock > self.dispatcher = self.trace_dispatch_i > elif hasattr(os, 'times'): > self.timer = os.times > self.dispatcher = self.trace_dispatch > self.get_time = _get_time_times > else: > self.timer = self.get_time = time.time > self.dispatcher = self.trace_dispatch_i > > If you're running on Windows (I think you said something about Linux), then > time.clock is either unavailable or is, but doesn't record CPU time. On > Linux systems it does (though to varying degrees of (in)accuracy). > > -- > Skip Montanaro (skip at pobox.com) > http://www.mojam.com/ > http://www.musi-cal.com/ > ======================================================================== Leonardo B. Lopes leo at iems.nwu.edu Ph.D. Student (847)491-8470 IEMS - Northwestern University http://www.iems.nwu.edu/~leo From chr_w at gmx.de Thu Oct 11 06:19:18 2001 From: chr_w at gmx.de (chr_w at gmx.de) Date: Thu, 11 Oct 2001 12:19:18 +0200 (MEST) Subject: get uniform binary data into array for further processing References: <7xg08qh6na.fsf@ruckus.brouhaha.com> Message-ID: <17082.1002795558@www29.gmx.net> Hey, thanx for the quick response Paul :-) Your suggestions sounds good (same idea I came up with). But I really get confused with the coding of this... I should be fairly simple using the fromfile thingy of array but I just can't figure how to use it properly... :-( Would you mind to give me a 3/5line hint on this? How is this module used ??? I have to admit that I#m not too familiar with python (just starting... The performance issue: well I'm stuck with a 32bit intel machine... but the data is coming from a SGI of our climate guys. Maybe I can just do the transformation block by block to keep the memory consumption on the ground. Actually the main purpose is to reduce the amount of data. For instance create the mean temperature for a day out of the half-hour-temperaturevalues in the input-file etc. and write to a ascii file in a specified format (which serves as the input for another model). Thanx a lot! christian -- GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net From jnlc at bellsouth.net Wed Oct 31 14:49:41 2001 From: jnlc at bellsouth.net (lance crocker) Date: Wed, 31 Oct 2001 19:49:41 GMT Subject: newbie question References: <9rpbr2$us4bd$1@ID-11957.news.dfncis.de> <3BE0394E.9C4E92BF@alcyone.com> <3be04a08.19984913@news1.lig.bellsouth.net> Message-ID: <3be053e7.293796@news1.lig.bellsouth.net> i just tried putting that path into the autoexec file and rebooting. it didn't change anything i still get the same errors. when you go to open a file how do you do it? do you type python hello.py while you are in commandline mode or while you are in gui mode? On Wed, 31 Oct 2001 14:19:56 -0500, "Steve Holden" wrote: >"lance crocker" wrote ... >> >> this is an actual exert from a tutorial i got off the net. >> >> Programming tutorials since the beginning of time have started with a >> little program called Hello, World! So here it is: >> >> print "Hello, World!" >> >> If you are using the command line to run programs then type it in with >> a text editor, save it as hello.py and run it with ``python >> hello.py'' >> >> Otherwise go into IDLE, create a new window, and create it as in >> section 1.4. >> >> When this program is run here's what it prints: >> >> Hello, World! >> >> i did evrything that it asked me to do but i keep getting syntax >> errors. i tried running it in DOS but it then gives me a bad command >> or file name error. >> >This is because the command processor doesn't know where to find the Python >interpreter. Suppose you have installed Python at the default location >(C:\Python21 for Python version 2.1) then the following command should work, >although requiring a little more typing: > > C:\python21\python hello.py > >You can fix this need for extra typing for a single session with the DOS >command > > path c:\python21;%path% > >[this adds the Python installation directory to the places that the command >processor looks for programs you tell it to run]. > >The DOS command > > python hello.py > >should now execute your "hello.py" program. To fix it for good you need to >add the command > > path C:\python21;%path% > >to a file called "autoexec.bat" in the C:\ directory. The install procedure >would be kinder to newbies if it did this, but undoing such changes at >uninstall time is not always easy so maybe the implementors chose not to do >this. > >> I want to get this fixed b/c how can i use progs with out being able >> to run them? > >Well, that would be kind of difficult. I know you must be feeling frustrated >right now, but stick with it. You are about to run your very first Python >program! > >regards > Steve >-- >www.holdenweb.com > > > From max at alcyone.com Thu Oct 25 13:44:17 2001 From: max at alcyone.com (Erik Max Francis) Date: Thu, 25 Oct 2001 10:44:17 -0700 Subject: Conditional expressions (again) References: <9r96tv$m26$1@thorium.cix.co.uk> Message-ID: <3BD84F71.6E035616@alcyone.com> gbreed at cix.compulink.co.uk wrote: > I don't remember "elif" being generally supported. Or a good argument > against > > x = b if a else (d if c else e) > > unless you count "P*rl has something like that" as a good > counter-argument. Nested conditional expressions get extremely hard to read very quickly. If the syntax can support this directly and more clearly and people support it, that seems a much better option. (Not that I use conditional operators for complex comparisons anyway.) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ Who shall stand guard to the guards themselves? \__/ Juvenal Alcyone Systems' CatCam / http://www.catcam.com/ What do your pets do all day while you're at work? Find out. From dalke at dalkescientific.com Fri Oct 26 03:39:01 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 26 Oct 2001 01:39:01 -0600 Subject: statements in control structures (Re: Conditional Expressions don't solve the problem) References: <9qhqi1$vba$1@slb3.atl.mindspring.net> <9ql9l5$tcr$1@slb5.atl.mindspring.net> <9qm32o$h80$1@slb7.atl.mindspring.net> <20011019084040.66952ddc.use-net@schabi.de> <9qp1o9$3fh$1@slb2.atl.mindspring.net> <20011023230901.2279a12b.use-net@schabi.de> <9r5h75$1m5$1@slb6.atl.mindspring.net> Message-ID: <9rb46d$he3$1@slb2.atl.mindspring.net> Huaiyu Zhu: >The reason is very simple - the naive translation does not work. Period. Okay, I understand now your point. I misunderstood your point, so my code was wrong. Give me enough time and eventually I might figure things out. :) >Does the above count as an example? As an example of a problem with for/else, yes. As a reason for the solution you once proposed, no, since iterators are another solution. > I can see that >iterators can solve some of them, but not all. The problem is more >complicted than either you or I thought initially. Well, I'm still not convinced that iterators aren't the right solution. I gave a couple iterator examples in my previous response. William Tanksley's follow-up (with the iterator "up_to_sqrt_of") describes the same points I would have said on this topic, so I suggest ending this thread here for that one. Andrew dalke at dalkescientific.com From opsys at voodooland.net Tue Oct 2 23:14:58 2001 From: opsys at voodooland.net (Chris Watson) Date: Tue, 2 Oct 2001 22:14:58 -0500 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: References: Message-ID: <200110030312.f933COK01047@smtp2.idir.net> On Tuesday 02 October 2001 09:54 pm, Delaney, Timothy wrote: > > From: Chris Watson [mailto:opsys at voodooland.net] > However, GPL is *not* extortion. The writer of a piece of code has every > right to want to protect, control or charge for it. That's true. But dont call it Free code if you do. Because it is not free. Look up free in the dictionary. That is the ONLY definition that should be followed. Not whatever twisted version the FSF and GNU people want to use. The gernal gist of any dictionary is its free if its free from control, opression, or restrictions. Chris From calves at coelce.com.br Wed Oct 31 12:31:14 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Wed, 31 Oct 2001 14:31:14 -0300 Subject: test Message-ID: <29A97D00F387D411AC7900902770E148024B779F@lcoeexc01.coelce.net> test -------------- next part -------------- An HTML attachment was scrubbed... URL: From rafial at well.com Fri Oct 5 15:45:22 2001 From: rafial at well.com (Wilhelm Fitzpatrick) Date: Fri, 05 Oct 2001 19:45:22 -0000 Subject: why are *two* ctrl-D's needed with readlines() Message-ID: <9pl2ki+tpjl@eGroups.com> "Wilhelm Fitzpatrick" wrote in message news:mailman.1002297908.5879.python-list at p... > I was writing a little python script using > > for line in sys.stdin.readlines() : > > to iterate through input, and I noticed that I had to press ctrl-D > TWICE to terminate input. ... > for line in sys.stdin.read().splitlines() : > > terminates on the first ctrl-D (as I would expect). "Steve Holden" responded: > Are you pressing the ^D at the end of a line of input, or at the > start of a blank line? (I replied to this message once already, but I think it went to Steve and not the list. My apologies if some of this is a duplicate) I am pressing ctrl-D at the start of blank line. My platform is indeed Linux, and that may have some bearing. I could not reproduce the behavior on a Solaris box with 2.1.1 installed. I installed 2.1.1 under Linux, and got the same problem behavior as described above. Another interesting test I did was to place a readlines() loop in a script and invoke it this way: cat | myscript.py Which produced the correct behavior (EOF on single ctrl-d) It appears to be some bad interaction between Linux (glibc?) and the way python handles stdin for readlines(), as opposed to say read() or raw_input(), which seem to be doing the right thing. Any thoughts from the gurus? From pengo243 at hotmail.com Tue Oct 2 10:03:20 2001 From: pengo243 at hotmail.com (Mark Berry) Date: Tue, 02 Oct 2001 14:03:20 GMT Subject: trying sockets References: <9pce64$5gnu5$1@hades.rz.uni-sb.de> Message-ID: <3bb9c8ed.943072055@spamkiller.newsfeeds.com> Without trying to write the code for you, basically your binding a local socket and trying to serve connections, not just connect to a remote socket. ;-) they have pretty simple examples for doing this in the OReilly python books, or probably any for that matter that covers sockets. Good luck On 2 Oct 2001 13:07:16 GMT, Uwe Schmitt wrote: >Hi, > >i'm just playing with the socket module: i'd like to send >a "GET/HTTP" request to a webserver and record the answer >of the server. so i wrote > > from socket import * > > snd=socket(AF_INET,SOCK_STREAM) > snd.connect(("www.num.uni-sb.de",80)) > print snd.getsockname() > > lstn=socket(AF_INET,SOCK_STREAM) > lstn.bind(snd.getsockname()) > > snd.send("GET / HTTP/1.0 ") > lsten.listen(1) > conn,addr=lstn.accept() > print conn.recv(1024) > > lstn.close() > snd.close() > >but i get the following output: > > ('134.96.31.42', 1662) > Traceback (most recent call last): > File "client.py", line 8, in ? > lsten.bind(snd.getsockname()) > socket.error: (98, 'Address already in use') > >so: what did i do wrong ??? > >yours, uwe. > > > >-- >Uwe.Schmitt at num.uni-sb.de Universit?t des Saarlandes >phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150 > D-66041 Saarbr?cken >http://www.rocksport.de http://www.rocksport.de/first_ride.mp3 > From brueckd at tbye.com Tue Oct 23 15:16:26 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 23 Oct 2001 12:16:26 -0700 (PDT) Subject: POLL in different OSes In-Reply-To: <9r49ju$jk6$1@nntp6.u.washington.edu> Message-ID: On 23 Oct 2001, Donn Cave wrote: > I would rather discourage people from using poll in python, since select > appears to work everywhere poll does, but not vice versa. Seems like > speed of one vs. the other would be irrelevant in the context of a > Python program. Hmm, no. The reasons why poll support was added to Linux, FreeBSD, etc. are the same reasons why poll support is nice to have in Python (handles more concurrent connections, more efficient, etc.). Put another way: many servers are I/O and not CPU bound, so if something benefits I/O in a C server then it has a good chance of benefiting a Python version of the same thing, and poll vs. select just happens to be one of those things. -Dave From slinkp23 at yahoo.com Thu Oct 11 15:27:32 2001 From: slinkp23 at yahoo.com (Paul Winkler) Date: Thu, 11 Oct 2001 19:27:32 GMT Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> <9q4it9$tio$1@nntp6.u.washington.edu> Message-ID: On 11 Oct 2001 16:55:05 GMT, Donn Cave wrote: >There are plenty of applications for a separate entry, and that's >where we came in. The most frequently cited application for an >assignment expression is > > while line = file.readline(): > ... That's not a very compelling example anymore. Presumably you don't want to do "for line in file.readlines()" because of the memory implications of slurping the whole file? Well, as of python 2.1 we can get one line at a time like this: for line in file.xreadlines(): ... And as of Python 2.2, files have an iterator that lets us do it like this: for line in file: ... Of course, we've already had the xreadlines module for quite a while, but the new sugary way to do it is easier to remember. - Paul Winkler From dale at riverhall.NOTHANKS.co.uk Thu Oct 25 04:57:05 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Thu, 25 Oct 2001 09:57:05 +0100 Subject: string question. difference between string.split(str, ":") and str.split(":") References: Message-ID: <4ukftto9fafaqnol0b51gaclu4jsscfkgb@4ax.com> "Markus Jais" wrote: >hello > >what is the difference between > >import string >str = "one:two:three" >a, b, c = string.split(str, ":") > >and > >str = "one:two:three" >a, b, c = str.split(":") > > The second superseded the first. -- Dale Strickland-Clark Riverhall Systems Ltd From peoter_veliki at hotmail.com Mon Oct 29 20:23:22 2001 From: peoter_veliki at hotmail.com (Peoter Veliki) Date: Mon, 29 Oct 2001 17:23:22 -0800 Subject: setting the clipboard References: <3bdd553c$1@207.229.64.20> <44rqttchjigpj1rkd4qvljr4bn5atmc75n@4ax.com> Message-ID: <6hnD7.320$MT2.19293225@news.incc.net> I see there is a setClipboardText, but there is no getClipboardText. How can this be done using getClipboardData? "Oleg Broytmann" wrote in message news:mailman.1004367760.13942.python-list at python.org... > On Mon, Oct 29, 2001 at 02:50:26PM +0000, Dale Strickland-Clark wrote: > > This puts the text in 'spam' on the clipboard: > > win32clipboard.SetClipboardText(spam) > > No, this put the value of the variable "spam". > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru > Programmers don't die, they just GOSUB without RETURN. > From rockvz at yahoo.com Thu Oct 11 11:47:54 2001 From: rockvz at yahoo.com (Rock VZ) Date: Thu, 11 Oct 2001 08:47:54 -0700 (PDT) Subject: dtd and xml schema parse Message-ID: <20011011154754.10496.qmail@web13503.mail.yahoo.com> Hello, What are the pyhton libraries available to parse dtd and xml schema documents. Are these releases stable? regards rock ===== __________________________________________________ Do You Yahoo!? Make a great connection at Yahoo! Personals. http://personals.yahoo.com From piet at cs.uu.nl Tue Oct 9 07:29:32 2001 From: piet at cs.uu.nl (piet at cs.uu.nl) Date: 09 Oct 2001 13:29:32 +0200 Subject: String formatting with two dictionaries? References: <3BC166F4.5E7FAB08@snakefarm.org> <3BC2BDC3.20A41F38@snakefarm.org> Message-ID: >>>>> Carsten Gaebler (CG) writes: CG> Thanks for all the answers. Seems as if I hadn't been specific CG> enough about what I was looking for. It would be nice if there was CG> some builtin dictionary magic that would allow CG> "%(foo) %(bar)" % magic(dict1, dict2, ...) CG> where in case of duplicate keys the leftmost dictionary would be CG> preferred. CG> Perhaps the builtin dictionary() class could be extended so that CG> it accepts more than one dictionary argument? My solution gave you that. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From ignacio at openservices.net Wed Oct 10 18:41:49 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Wed, 10 Oct 2001 18:41:49 -0400 (EDT) Subject: problem using using list with function In-Reply-To: Message-ID: On Wed, 10 Oct 2001, adam griffin wrote: > I think I figured out my problem. I had the function definition at the end > of my script when I put it at the beginning it worked. is this the only > place you can put definitions? No, but you have to define a function before you can use it. Note that "using it" is defined as calling it, not just spelling it out, so the following works just fine: --- >>> def a(): ... b() ... >>> def b(): ... print 'Blah!' ... >>> a() Blah! >>> --- -- Ignacio Vazquez-Abrams From miker at 21stcenturyhealth.com Fri Oct 5 10:56:55 2001 From: miker at 21stcenturyhealth.com (Mike Ryan) Date: Fri, 5 Oct 2001 10:56:55 -0400 Subject: list to tuple question References: <3bbdc533_6@news.newsgroups.com> Message-ID: "Janos Blazi" wrote in message news:3bbdc533_6 at news.newsgroups.com... > I'd like to make a formatted string like this: > > s='%s %s %s %s %s %s %s %s %s\n' % (A,)+b+(C,D) > > The point is, that b is already a list and this would simplify matters. Most > unfortunately (or most obviously for the initiated) I get the error message > that a tuple and a list cannot be concatenated. What should I do. I could > solve the problem by using a for-loop but is it necessary? Try this: s = '%s %s %s %s %s %s %s %s %s\n' % ((A,) + tuple(b) + (C, D)) BTW, the other error in your statement was not putting the concatenation inside of parentheses. Remember your order of evaluation for operators. The modulo operator (%) has a higher precedence than the addition (+) operation. It suprises me that you actually got the error that you did get. -- Michael Ryan Information Services Manager 21st Century Health and Benefits, Inc. From donn at u.washington.edu Tue Oct 23 13:32:46 2001 From: donn at u.washington.edu (Donn Cave) Date: 23 Oct 2001 17:32:46 GMT Subject: POLL in different OSes References: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> Message-ID: <9r49ju$jk6$1@nntp6.u.washington.edu> Quoth Lucio Torre : | At 10:18 AM 23/10/2001 +0200, Gerhard H=E4ring wrote: ... |> Wouldn't it be possible to emulate poll() with select()? I'd be glad to |> see a patch appear at Sourceforge if that's possible :-) | i think i could do that. i can make a .c with the code that amulates poll=20 | from select, if someone else is willing to make it a patch or whatever it=20 | should be to get into python. | | btw: is it worth it? poll is supposed to be faster, so why emulate it? it=20 | would have no reason to exist! I would rather discourage people from using poll in python, since select appears to work everywhere poll does, but not vice versa. Seems like speed of one vs. the other would be irrelevant in the context of a Python program. But from C, I know poll is more fun to use, and there was a time when a few System V 3.2 platforms with STREAMS network support didn't have select, so here's a working if limited poll.c from those days. Donn Cave, donn at u.washington.edu ---------------------------------------- #ifndef _POLL_H_H_ #define _POLL_H_H_ /* ** Emulate poll() for those platforms (e.g., Ultrix) that don't have it. ** Usually select() and poll() are the same functionally, differing only ** in the calling interface, but in a few cases they behave differently, ** possibly where the platform implements STREAMS devices and one or the ** other has some compatibility bug. Poll() has a cleaner programming ** interface, anyway. */ #ifdef HAVE_POLL # include #else struct pollfd { int fd; short events; short revents; }; #define POLLIN 001 #define POLLPRI 002 #define POLLOUT 004 #define POLLNORM POLLIN #define POLLERR 010 #define POLLHUP 020 #define POLLNVAL 040 int poll PROTO((struct pollfd *, int, int)); #endif #endif /* _POLL_H_H_ */ ---------------------------------------- /* * prt * * Copyright 1994 University of Washington * * Permission is hereby granted to copy this software, and to * use and redistribute it, except that this notice may not be * removed. The University of Washington does not guarantee * that this software is suitable for any purpose and will not * be held liable for any damage it may cause. */ /* ** emulate poll() for those platforms (Ultrix) that don't have it. */ #include "osdefs.h" #ifdef HAVE_POLL int DontLoadMe; #else #include #include #include "poll.h" void bzero(); int poll(fds, nfds, timo) struct pollfd *fds; unsigned long nfds; int timo; { struct timeval timeout, *toptr; fd_set ifds, ofds, efds, *ip, *op, *ep; int i, rc, n; FD_ZERO(&ifds); FD_ZERO(&ofds); FD_ZERO(&efds); for (i = 0, n = -1, op = ip = 0; i < nfds; ++i) { fds[i].revents = 0; if (fds[i].fd < 0) continue; if (fds[i].fd > n) n = fds[i].fd; if (fds[i].events & (POLLIN|POLLPRI)) { ip = &ifds; FD_SET(fds[i].fd, ip); } if (fds[i].events & POLLOUT) { op = &ofds; FD_SET(fds[i].fd, op); } FD_SET(fds[i].fd, &efds); } if (timo < 0) toptr = 0; else { toptr = &timeout; timeout.tv_sec = timo / 1000; timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; } rc = select(++n, ip, op, &efds, toptr); if (rc <= 0) return rc; for (i = 0, n = 0; i < nfds; ++i) { if (fds[i].fd < 0) continue; if (fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(i, &ifds)) fds[i].revents |= POLLIN; if (fds[i].events & POLLOUT && FD_ISSET(i, &ofds)) fds[i].revents |= POLLOUT; if (FD_ISSET(i, &efds)) /* Some error was detected ... should be some way to know. */ fds[i].revents |= POLLHUP; } return rc; } #endif /* ultrix */ From dalke at dalkescientific.com Sat Oct 6 13:34:18 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 6 Oct 2001 11:34:18 -0600 Subject: Octonians in Python References: <1kFv7.36296$My2.18330031@news1.mntp1.il.home.com> Message-ID: <9pnfvm$uct$1@slb2.atl.mindspring.net> David Feustel: >Failure to find an instance does not imply that >such an instance does not exist, although many >such failures should probably give one pause. What failure? I just did a search for "octonians python" and google replied "Did you mean: octonions python". The first hit from that search showed that Boost, a C++ library with Python bindings, supports octonions. Though I don't know enough about Boost to know if this is useful, I have heard others say good things about the package. Figure out for yourself at http://www.boost.org/ Andrew dalke at dalkescientific.com From dkuhlman at rexx.com Tue Oct 23 13:12:59 2001 From: dkuhlman at rexx.com (Dave Kuhlman) Date: 23 Oct 2001 12:12:59 -0500 Subject: python + xml performance compared to Java and C++ ?? References: Message-ID: <1003857852.889699@rexx.com> As suggested in this thread, Python processing of XML can be quite fast when the underlying parser is written C or C++. So: 1. expat is available to Python in pyexpat. 2. The parsers and XSLT processor at http://xmlsoft.org have been wrapped and made available to Python (see http://www.rexx.com/~dkuhlman). 3. Python support for the Apache tools (Xerces and Xalan) is in process. 4. PyXML and 4Suite provide drivers for pyexpat and sgmlop, both of which are written in C. For those who want _fast_ XML processing, that seems like pretty good coverage to me. If you use one of the above parsers, then the issue becomes how much logic and processing time you add in Python. - Dave Brian Quinlan wrote: > > Markus wrote: >> hello >> does anyone have experiences how fast xml processing >> and XSLT processing with python (using PyXML and 4Suite tools) >> is, compared to Java and C++ (using the apache tools, like >> Xalan, Xerces....) > > Fortunately, there are two projects that are working on providing > bridges between the C++ versions of Xalan and Xerces and Python: > > Pyana is focused on providing Xalan's transformation capabilities to > Python scripts: > https://sourceforge.net/projects/pyana > http://pyana.sourceforge.net/docs/ > > Pirxx is focused on providing an interface to Xerces, right now it > only provides SAX2 drivers but work is on-going: > https://sourceforge.net/projects/pirxx > (don't know where the docs are) > > Cheers, > Brian > > > -- Dave Kuhlman dkuhlman at rexx.com -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From fdrake at acm.org Thu Oct 25 23:13:46 2001 From: fdrake at acm.org (Fred L. Drake) Date: Thu, 25 Oct 2001 23:13:46 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011026031346.8550628697@beowolf.digicool.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Yet another experimental change to the presentation -- ditch the proportional font for code since some displays (especially interactive sessions and tabular displays) get messed up with proportional fonts. We do try to use monospaced fonts that are less ugly than Courier. As before, feedback on the fonts is welcome at python-docs at python.org. From LynnB at Yogananda-SRF.org Mon Oct 22 20:04:02 2001 From: LynnB at Yogananda-SRF.org (LynnB at Yogananda-SRF.org) Date: Mon, 22 Oct 2001 17:04:02 -0700 Subject: Mixing asyncore with threads Message-ID: >(2) Use a "dummy" port on the loopback interface for triggering >select() once output from the thread is finished. I've used this method and it works quite well for me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mondoinfo.com Tue Oct 16 13:21:47 2001 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Tue, 16 Oct 2001 17:21:47 GMT Subject: pmw "about" dialog References: Message-ID: On Tue, 16 Oct 2001 12:50:40 +0100, Sharriff.Aina at med-iq.de wrote: >Could someone tell me why the about dialog in this code does not show? >#create submenu "About" >aboutmenu = Menu(menubar, tearoff=0) >aboutmenu.add_command(label = "About") ># add submenu "about" to menubar >menubar.add_cascade(label="About", menu=aboutmenu, command = >dialogue_about) The command option needs to be in the call to add_command() not in the call to add_cascade(). I don't know why add_cascade() doesn't complain about getting an option that it doesn't want. Regards, Matt From lucio at movilogic.com Tue Oct 23 15:11:54 2001 From: lucio at movilogic.com (Lucio Torre) Date: Tue, 23 Oct 2001 16:11:54 -0300 Subject: programming unlimited "categories" in python ? In-Reply-To: <33186660193.20011023203219@buz.ch> References: <5.1.0.14.0.20011023134155.026dc008@imap.hq.movilogic.com> <5.1.0.14.0.20011023130239.088b9768@imap.hq.movilogic.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> <5.1.0.14.0.20011023130239.088b9768@imap.hq.movilogic.com> <5.1.0.14.0.20011023134155.026dc008@imap.hq.movilogic.com> Message-ID: <5.1.0.14.0.20011023160159.026dc008@imap.hq.movilogic.com> At 08:32 PM 23/10/2001 +0200, Gabriel Ambuehl wrote: >-----BEGIN PGP SIGNED MESSAGE----- > >Hello Lucio, > >Tuesday, October 23, 2001, 6:49:03 PM, you wrote: > > >>You still need a link between the two, else you haven't got any > >>chance > >>to match them anyway so why not just build the region tree and > >>store all the data under it? then you query for africa first and > >>fetch only the results which have got the attribute deadly in 5 > >>hours? > > you can match them using intersections. you get all the children > > for every node in all the categories you want, then intersect them > > all. > >But you can only intersect them if you have some additional >information about which apply to which he if i have a tree, i can get the children from one node. if i have two list of children, i can compare them and see where they intersect. (equal records) not the prettiest thing to do in sql maybe. but thats how you cross both selections. as i said, the categorization data is not in the data point structure, but in the tree. and thats how you get unlimited. >nce you need some kind of >link. > > >>I wasn't thinking about the implementation itself but mostly about > >>suitable approaches. IMHO, you should try to squeeze your data > >>model into ONE tree and the problem is almost solved. > > so you do this tree: > > > africa >- ->> mozambique >- -- >> capital >- ---->> deadly >- ------>> really deadly >- ------>> not so deadly >- --->> deadly >- ----->> really deadly >- ----->> not so deadly >- -->> deadly >- ---->> really deadly >- ---->> not so deadly >- ->> deadly >- --->> really deadly >- --->> not so deadly > > > but suppose you suddently have cases of a kinda deadly thing. you > > have to edit the whole tree! > >Why? Personally, I'd simply save the deadly stuff in a string (or >even >integer) so I can easily add another mode if need be. > > > but you can have that if you hard code the tree. but what if you > > have some subset (really deadly, or spooky deadly.. or whatever, in > > the query you are doing) and want to find out the africa tree? > >I think Python's polymorphism allows for a not so hard coded >kind of tree as Python won't care what type of object you put into >data... yeah, but thins thing you are propossing, is one of the reasons people want to switch from RDBMS to OODMS! and we are dealing with sql here. lucio From fdrake at acm.org Sat Oct 6 02:09:45 2001 From: fdrake at acm.org (Fred L. Drake) Date: Sat, 6 Oct 2001 02:09:45 -0400 (EDT) Subject: [development doc updates] Message-ID: <20011006060945.4C32828697@beowolf.digicool.com> The development version of the documentation has been updated: http://python.sourceforge.net/devel-docs/ Updates to add ReferenceError to the standard exceptions. From jpt.d at home.com Sun Oct 28 01:08:54 2001 From: jpt.d at home.com (Jeffrey Drake) Date: Sun, 28 Oct 2001 06:08:54 GMT Subject: Win32 Dll Extention Module Problem Message-ID: In my python program, whenever calling the following function it freezes and I have to kill python. Otherwise the program works fine. Here is the source to the function: static PyObject * Win32X_InitializeFlatSB( PyObject *self, PyObject *args) { HWND hwnd; BOOL ret; if (!PyArg_ParseTuple(args, "i", &hwnd)) return NULL; ret = InitializeFlatSB(hwnd); return Py_BuildValue("i", 1); } and... static PyMethodDef Win32X_methods[] = { {"InitializeFlatSB", Win32X_InitializeFlatSB, METH_VARARGS, "InitializeFlatSB will initialize flat scrollbars for your window. Just pass the window handle."}, and... (inside initWin32X) Py_InitModule("Win32X", Win32X_methods); The only problem I can think of is the data conversion. "i" is the closest or "l" that is listed to be able to convert the HWND. HWND natively is a void* i believe. Notes: I know win32all exists, but it doesn't have these methods. Any help appreciated. BTW, is there a conversion for void*? Regards, Jeffrey Drake. From mackeith at hks.com Tue Oct 30 09:53:31 2001 From: mackeith at hks.com (Andrew MacKeith) Date: Tue, 30 Oct 2001 09:53:31 -0500 Subject: stat.S_ISLNK and os.path.islink Message-ID: <3BDEBEEB.ED9C563A@hks.com> Has anyone seen os.path.islink(path) return a different result to stat.S_ISLNK(os.stat(path)[stat.ST_MODE]) ? The directory in question is a symbolic link. My result, on IRIX, is as follows: (lines split up for readability) The path is a symbolic link to a directory. > python21 -c "import os,stat; s = os.stat('../removeStar/is_base_link')[stat.ST_MODE]; print s, stat.S_IFMT(s); print stat.S_ISLNK(s); print os.path.islink('../removeStar/is_base_link')" 16872 16384 0 1 Andrew MacKeith From phr-n2001d at nightsong.com Sun Oct 14 23:19:55 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 14 Oct 2001 20:19:55 -0700 Subject: conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour)) References: Message-ID: <7xitdha8tg.fsf@ruckus.brouhaha.com> "Tim Peters" writes: > > x = if e1 then (e2) else (e3) > > and > > x = (if e1 then (e2) else (e3)) > > should be equivalent and they preserve clarity. > > The latter form would be accepted, but not the former (and the former cannot > be accepted, which is a question of parser technology, not of taste). How did Algol 60 deal with this? From db3l at fitlinxx.com Mon Oct 29 15:56:16 2001 From: db3l at fitlinxx.com (David Bolen) Date: 29 Oct 2001 15:56:16 -0500 Subject: BOA GUI builder? References: <3BD9CC09.2B1AB020@mitre.org> <3BDC909B.4F500B9C@mitre.org> <3BDDA284.B564E2CB@mitre.org> Message-ID: Angel Asencio writes: > Ok, someone told me that to be able to use boa v0.0.13 with wxPython > 2.3.1 I had to do some modifications. I checked on source forge, > and I could not find any patch related to this. Could someone post > the changes or a place to get the patch for v0.0.13 to be able to > work with wxPython 2.3.1? If it was on SourceForge, then you wouldn't need to do the modifications :-) There's a check for version 2.3.0 in the current CVS boa files - such that if you try to run it with 2.3.1 it'll give you a message box complaining that it needs 2.3.0. Just look for "2.3.0" in the files to find the error and you'll find the bit of code that you need to tweak. I think it was in the main Boa.py module, and just tweak the (2,3,0) tuple to (2,3,1). -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From mikael at isy.liu.se Fri Oct 5 03:12:07 2001 From: mikael at isy.liu.se (Mikael Olofsson) Date: Fri, 05 Oct 2001 09:12:07 +0200 (MET DST) Subject: Formatted printing of deep tuples In-Reply-To: Message-ID: On 05-Oct-2001 Ignacio Vazquez-Abrams wrote: > Okay, here's a good one. Say I have a tuple as follows: > > --- > (((1, 2),), ((), ('a', (('b', 'c'),)))) > --- > > Does anyone have or know of any code that will format it similar to: > > --- > ( > ( > ( > 1, 2 > ), > ), > ( > ( > ), > ( > 'a', > ( > ( > 'b', 'c' > ), > ) > ) > ) > ) I'm sure someone else has a one-liner using regexps, but the following seems to be doing the trick. def test(a,indent=2): import string a=str(a) s=[] i=0 f=0 for x in a: if x=='(': s.append('\n'+i*' '+'(') i=i+indent f=1 elif x==')': i=i-indent s.append('\n'+i*' '+')') f=0 else: if f: s.append('\n'+i*' ') f=0 s.append(x) return string.join(s,'') HTH /Mikael ----------------------------------------------------------------------- E-Mail: Mikael Olofsson WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael Phone: +46 - (0)13 - 28 1343 Telefax: +46 - (0)13 - 28 1339 Date: 05-Oct-2001 Time: 09:07:32 /"\ \ / ASCII Ribbon Campaign X Against HTML Mail / \ This message was sent by XF-Mail. ----------------------------------------------------------------------- Link?pings kammark?r: www.kammarkoren.com From shehrer1 at yahoo.co.nz Wed Oct 31 03:14:53 2001 From: shehrer1 at yahoo.co.nz (Valerie) Date: 31 Oct 2001 00:14:53 -0800 Subject: How can I install win32all-140.exe over Python2.2? Message-ID: <76974d4a.0110310014.3effd408@posting.google.com> Hi all! I've install a new Python 2.2 version and want to use win32all with it. There is a win32all's version for Python 2.1, only. :-( How can I decompress package to use some known utilities from win32all? Or I need to wait the better time... :-) Thank you. Regard, Valerie Ivanov From gh_pythonlist at gmx.de Fri Oct 5 08:52:18 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 5 Oct 2001 14:52:18 +0200 Subject: list to tuple question In-Reply-To: <3bbdc533_6@news.newsgroups.com>; from jblazi@hotmail.com on Fri, Oct 05, 2001 at 04:35:25PM +0200 References: <3bbdc533_6@news.newsgroups.com> Message-ID: <20011005145218.A539@lilith.hqd-internal> On Fri, Oct 05, 2001 at 04:35:25PM +0200, Janos Blazi wrote: > I'd like to make a formatted string like this: > > s='%s %s %s %s %s %s %s %s %s\n' % (A,)+b+(C,D) > > The point is, that b is already a list and this would simplify matters. Most > unfortunately (or most obviously for the initiated) I get the error message > that a tuple and a list cannot be concatenated. What should I do. I could > solve the problem by using a for-loop but is it necessary? Concatenate lists: [A,]+b+[C,D] Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From tim.one at home.com Wed Oct 17 22:41:28 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 17 Oct 2001 22:41:28 -0400 Subject: fast sub list operations In-Reply-To: Message-ID: [mwh at python.net] > ... > [0] Actually, this is obvious. interleave1 is quadratic in list > length, so maybe that's what's killing it, rather than the eval loop > optimisations. Remind me what reduce is doing in the language again? reduce() came as part of the contributed code that also added lambda, filter and map to Python 1.0. I don't think I've seen a program using Python's reduce() that wasn't made both faster and clearer by replacing it with a loop; the same isn't true of filter and map; lambda can be argued either way, but with the special twist that people arguing in favor of it are usually thinking of some other language . never-point-with-your-feet-it's-considered-impolite-ly y'rs - tim From sholden at holdenweb.com Fri Oct 26 07:53:23 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 26 Oct 2001 07:53:23 -0400 Subject: Conditional expressions (again) References: <3BD8C52A.53E97472@alcyone.com> <9rbh46$p95$1@thorium.cix.co.uk> Message-ID: wrote ... > Erik Max Francis wrote: > > > Greg Ewing wrote: > > > > > Write that as > > > > > > x = ( > > > b if a else > > > d if c else > > > e > > > ) > > > > > > and it looks a lot clearer. > > > > Sure, but since conditional expressions are intended for brevity, you've > > just made a five line nested conditional express. Why not just use an > > if ... elif ... else statement instead? > > Compare > > order.append( > spam if customer == michae1 else > eggs if customer == john else > cheese) > > with > > if customer == michael: > side0rder = spam > elif customer == john: > sideOrder = eggs > else: > sideOrder = cheese > order.append(sideOrder) > > in terms of how likely each error is to arise in testing, and how much > time it would take to work out what was going wrong. I find that almost > convincing ;-) > if customer == michael: order.append(spam) elif customer == john: order.append(eggs) else: order.append(cheese) is, of course, simpler if you don't need a record of the sideOrder. I think "cheese" should have been "chips", by the way ;-) we-don't-need-no-stinkin'-conditional-expressions-ly y'rs - steve -- http://www.holdenweb.com/ From dalke at dalkescientific.com Sat Oct 6 02:30:54 2001 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 6 Oct 2001 00:30:54 -0600 Subject: Quaternions in Python References: <7xhetd5y94.fsf@ruckus.brouhaha.com> Message-ID: <9pm927$dh8$1@slb4.atl.mindspring.net> Paul Rubin: >I think there's a simple way to represent quaternions as 3x3 matrices. Thank you for giving me a chance to repeat one of my favorite phrases from the movie "Apollo 13" -- "Gimbal lock". (Okay, it isn't a widely popular quote, but I like it anyway!) For an example of what that means and why 3x3 matricies don't work, an "I'm feeling lucky" Google search for "Gimbal lock quaternion" yields http://www.anticz.com/eularqua.htm and this link has more details, http://www.gamasutra.com/features/19980703/quaternions_01.htm Andrew dalke at dalkescientific.com From loewis at informatik.hu-berlin.de Wed Oct 24 06:00:15 2001 From: loewis at informatik.hu-berlin.de (Martin von Loewis) Date: 24 Oct 2001 12:00:15 +0200 Subject: Name of current method (for C functions) ? References: <50cd1e5d.0110231608.e955f0e@posting.google.com> Message-ID: tgloth at earthlink.net (Tobias Gloth) writes: > Any hints or suggestions would be greatly appreciated! Before being called, each C function is wrapped with a PyCFunctionObject. You normally don't create those yourself (but use Py_FindMethod instead), but in this case, you should: Each C function has an m_self member, which is passed as the first argument to the function. When creating a C function (via PyCFunction_New), you can put any PyObject* into self, for example the string representing the function name. HTH, Martin From jwelby at waitrose.com Wed Oct 3 02:24:00 2001 From: jwelby at waitrose.com (Julius Welby) Date: 03 Oct 2001 06:24:00 GMT Subject: [?] sorting files by modification time. References: <9pd5me$lo1@dispatch.concentric.net> Message-ID: <9peau0$26q@dispatch.concentric.net> Oh yes. I only needed to find the oldest file, so for me this was fine. To 'Doh!' is human. :-) "I?igo Serna" wrote in message news:mailman.1002062407.8789.python-list at python.org... Hi, En mar, 2001-10-02 a 21:48, Julius Welby escribi?: > Get a listing of the file names using os.listdir for the folder, then you > can do something like: > > for name in filenames: > path = os.path.join(folder, name) > modified = os.path.getmtime(path) > statdict[modified] = name > keylist = statdict.keys() No, you can't do this. If several files have the same modification time, last one would overwrite previous ones. filenames = os.listdir(folder) statdict = {} for name in filenames: path = os.path.join(folder, name) modified = os.path.getmtime(path) while statdict.has_key(modified): # this is the trick: modified += 0.1 # do not allow repeated keys statdict[modified] = name keylist = statdict.keys() keylist.sort() filenames_sorted_bymtime = [] for k in keylist: filenames_sorted_bymtime.append(statdict[k]) I use this in lfm (http://www.terra.es/personal7/inigoserna/lfm). Best regards, I?igo Serna From pterk at datatailors.xs4all.nl Wed Oct 24 21:50:20 2001 From: pterk at datatailors.xs4all.nl (Peter van Kampen) Date: 25 Oct 2001 01:50:20 GMT Subject: smtp References: Message-ID: <3bd76fdb$0$1532$e4fe514c@newszilla.xs4all.nl> In article , Cliff Wells wrote: >I'm trying to add a "Contact Us" button to a Python app. Using the smtplib >module was straightforward and works from Linux using 'localhost' as the >server (sendmail handles it), but this doesn't work on a Windows box. I >worked around this by using our ISP's mail server which works fine if I am >sending the email (even if I send it using a different email address for the >sender) from my PC or from a coworkers. However - I tried it on someone >else's Windows PC who uses AOL (blech) and it failed with SMTPSenderRefused. > Chris, My guess is your ISP allows the use of the mailservers from within their network. From your own pc you can therefor send mail with whatever address as the sender, which is fine - if such mail causes trouble they can always trace it to you. They will not allow computer from a different network (such as AOL) to use their mailserver. If you have a dial-up account (or you have a decent dsl/cable provider) you can dial in to your ISP from whatever PC to check if this works. You can also substitute your isp's mailserver with the aol-mailserver to check it from the aol computer. Hth, PterK From nicoLALALALALA at altiva.fr Fri Oct 19 13:26:45 2001 From: nicoLALALALALA at altiva.fr (NM - Remove LALALALALA to email me) Date: Fri, 19 Oct 2001 19:26:45 +0200 Subject: About popen2 References: Message-ID: On Fri, 19 Oct 2001 17:12:30 +0200, Neil Schemenauer wrote: > NM - Remove LALALALALA to email me wrote: >> Am I right to assume that, unlike C's popen, popen2's "command" >> argument does not get passed through the shell? >> >> If I am, is there a way to pass arguments? > > Something like this: > > popen2.popen2(("ls", "-l", "/")) Thanks. It's surprising it's not mentioned in the doc. > Reading the source code is a useful exercise. > > Neil I'm not very familiar with Python ATM, currently getting up to speed trying to fix an existing program. From sholden at holdenweb.com Thu Oct 4 23:25:36 2001 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 4 Oct 2001 23:25:36 -0400 Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> <9pimak$c22$1@tyfon.itea.ntnu.no> <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> <00a001c14d26$30fce2a0$d938a8c0@Hadfield> Message-ID: Well, I could even take exception to the word "it", since there are many different Englishes. By the way, while everyone's got their grammar books out, what's the possessive of "class" and "classes". Do we write "this class's __init__() method" and "those classes' __init__() methods", or what? regards Steve -- http://www.holdenweb.com/ "Mark Hadfield" wrote in message news:00a001c14d26$30fce2a0$d938a8c0 at Hadfield... > From: "Steve Holden" > > but-then-i'm-english-so-what-do-i-know-ly y'rs - steve > > Yeah, but you know as well as I do that the worldwide language is only > called "English" for historical reasons. > > --- > Mark Hadfield > m.hadfield at niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield > National Institute for Water and Atmospheric Research > > > > -- > Posted from clam.niwa.cri.nz [202.36.29.1] > via Mailgate.ORG Server - http://www.Mailgate.ORG From jblazi at hotmail.com Mon Oct 15 12:57:58 2001 From: jblazi at hotmail.com (Janos Blazi) Date: Mon, 15 Oct 2001 18:57:58 +0200 Subject: TkTable Message-ID: <3bcb1592$1_5@news.newsgroups.com> Is there a way to use tkTable from within Tkinter? Thx in advance, J.B. -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From erik at pacific-shores.com Wed Oct 3 16:18:10 2001 From: erik at pacific-shores.com (Erik Myllymaki) Date: Wed, 03 Oct 2001 20:18:10 GMT Subject: win32security question References: Message-ID: <6oKu7.46034$L8.11733321@news2.rdc1.bc.home.com> Answering my own question: import win32net level = 3 try: dict = win32net.NetUserGetInfo(None, 'myusername' , level ) if dict['password_expired']: print "Expired Password" except: . . . "Erik Myllymaki" wrote in message news:DHGu7.45378$L8.11573696 at news2.rdc1.bc.home.com... > How can I tell if a user's password has expired through python's win32 APIs? > > -- > Erik Myllymaki > erik at pacific-shores.com > > From brueckd at tbye.com Tue Oct 9 14:21:21 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 9 Oct 2001 11:21:21 -0700 (PDT) Subject: Why not 3.__class__ ? In-Reply-To: Message-ID: On Tue, 9 Oct 2001, Markus Jais wrote: > In article , "Guido van > Rossum" wrote: > > > Marcin, I don't understand why you care so much about being able to > > write 3.foo. It's painful to fix in the lexer, and probably leads to > > less useful error messages if someone makes a mistake in a float literal > > (e.g. "3.e 0"). And I see zero use for it: in practice, you will never > > ask for 3.foo -- you'll ask for x.foo where x happens to contain the > > value 3. [snip] > but to write 3.foo is something I would like to have in Python [snip] > It would be great, if this would be possible in Python too Care to elaborate on why it would be "great"? Guido's reply to Marcin points out that there doesn't seem to be any usefulness to it. So.... what problem would it solve or simplifiy? What exactly would its benefit be, anyway? From calves at coelce.com.br Thu Oct 11 10:21:24 2001 From: calves at coelce.com.br (Alves, Carlos Alberto - Coelce) Date: Thu, 11 Oct 2001 11:21:24 -0300 Subject: FW: Profiling PyOpenGL Message-ID: <29A97D00F387D411AC7900902770E1480214523C@lcoeexc01.coelce.net> Anyone can send odbc module used in the attached file?! -----Original Message----- From: Georg Bisseling [mailto:Georg.Bisseling at pallas.com] Sent: Thursday, October 11, 2001 11:06 AM To: python-list at python.org Subject: Re: Profiling PyOpenGL [sent by email and posted via news] " Kerim Borchaev ( WarKiD )" wrote: > > Hello python-list, > > why can't I profile PyOpenGL application using profile module? > glutMainLoop() > but it prints nothing unless I remove glutMainLoop call. Because glutMainLoop() is an endless loop as long as you do not close the window. -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.one at home.com Sat Oct 27 13:16:43 2001 From: tim.one at home.com (Tim Peters) Date: Sat, 27 Oct 2001 13:16:43 -0400 Subject: Dictionary from list? In-Reply-To: Message-ID: [Terry Reedy] > Fact: a Python dictionary literal is a sequence of key:value pairs of > literals, with the first becoming a hashable object, and only such a > sequence. Sounds more like a definition than a fact . > Observation: ':' is analogous to '( , )', which could have been the > syntax chosen (though I'm glad it wasn't). > > Therefore: > > Proposed rule 1: the dictionary() constructor should accept a sequence > of pairs of objects, with the first being keyable (hashable). In > particular, it should invert dict.items. In current CVS, it does. In 2.2-speak, it accepts an iterable object producing iterable objects producing exactly 2 objects. It also accepts a mapping object (as it did in 2.2b1), and also accepts nothing (ditto -- it returns {} then, much as list() returns [] and tuple() returns ()). > Note: by type, 'pair' might mean duple only; by interface, it would > mean an object reporting a length of two and yielding objects with > indexes 0 and 1. "By interface" is important, but the details there are off for 2.2 -- iterable objects don't have to support len or indexing. For example, class AddressBookEntry: # with .firstname, .lastname attributes ... def __iter__(self): return iter((self.firstname, self.lastname)) A sequence of AddressBookEntry instances is OK to pass to dictionary(), despite that an AddressBookEntry defines neither __len__ nor __getitem__. A generator yielding instances of AddressBookEntry is also fine; etc. > Comment: once pair is defined, this rule gives a uniform target for > conversion from other formats, including those generated by other > software systems. I currently vote for the latter. I didn't understand "the latter" here, unless it's a vote for "other software systems", in which case I'm keen to see the patch . > Proposed rule 2: dictionary() should reject any other sequence, just > as does the internal constructor-from-literals. "Sequence" is a slippery word. dictionary() continues to accept a mapping object too. Of course, "mapping object" is also a slippery phrase. > Paraphrase: conversions from the many other possible formats should be > handled externally from dictionary(). Indeed, we're going to cheerfully endure abuse for sticking to that. > Opinion 3: Given the fact and comments above, these two rules should > be easy to understand and teach. Yup. From oliphant at ee.byu.edu Mon Oct 15 23:36:01 2001 From: oliphant at ee.byu.edu (Travis Oliphant) Date: Mon, 15 Oct 2001 23:36:01 -0400 Subject: BINARY DATA, SCIPY, MIO (...again) In-Reply-To: References: Message-ID: A version of scipy had a typo in mio.py so that Tupletype should have been TupleType >>> from scipy import * >>> help(io.fopen.fort_read) fort_read(fmt, dtype=None) Read a Fortran binary record. Inputs: fmt -- If dtype is not given this represents a struct.pack format string to interpret the next record. Otherwise this argument is ignored. dtype -- If dtype is not None, then read in the next record as an array of type dtype. Outputs: (data,) data -- If dtype is None, then data is a tuple containing the output of struct.unpack on the next Fortan record. If dtype is a datatype string, then the next record is read in as a 1-D array of type datatype. There are two ways to call this method of the object returned by fopen: 1) output_tuple = fid.fort_read() 2) 1darray = fid.fort_read(whatever, dtype='double') You probably whan the second method to read in a fortran record (created by each write statement in your Fortran code) as an array of real*8 values -Travis From tex_r at hotmail.com Thu Oct 18 19:24:36 2001 From: tex_r at hotmail.com (Tex Riddell) Date: 18 Oct 2001 16:24:36 -0700 Subject: Is there a small Python runtime environment installer? Message-ID: <3583b331.0110181524.5695bd67@posting.google.com> I have some useful scripts that I'd like to share with someone that doesn't have Python. He doesn't want to install all of Python right now (like examples, utilities, source, IDE's and tk - yuck), he'd rather just have an executable or install a simple runtime library and run my script. I only know of two main distributions of python and each are made for people developing with python. Is there a simple, compact, binary distribution available anywhere? Ideally, I'd like to see a binary shared library, compiled for the target platform, with a minimum of external dependencies. Hopefully, with support scripts (for standard features) compiled to byte code and compressed or at least clumped together in a single file (or a few files, one for each larger feature area). More specifically I'm looking for something for the windows environment, but one should be able to make something like this multi-platform, right? How can we expect python to become more mainstream if only developers can understand the environment that must be set up for scripts to run? I really don't have time to learn distutils (re-inventing the wheel that I'm sure so many have done) in order to install a runtime environment on someone's machine so they can run a simple 8k script. -Tex From kkto at csis.hku.hk Mon Oct 8 22:58:16 2001 From: kkto at csis.hku.hk (Isaac To) Date: 09 Oct 2001 10:58:16 +0800 Subject: Tkinter window minsize question References: Message-ID: <7iwv255xkn.fsf@enark.csis.hku.hk> >>>>> "Roman" == Roman Suzi writes: Roman> While when I resize it manually (to the greater size) it remains Roman> in tact. What is wrong? Because the size of the button is too small, which propagate to the frame asking it to be resized to a small size. Remember that w.resize(x,y) only specify a size smaller than which the user cannot resize the window, and your program (in particular, the buttons) is still free to resize the window to whatever size it want. To do what you want, just add the following after the frame f1 is created: f1.propagate(0) Regards, Isaac. From ykingma at accessforall.nl Sun Oct 28 14:25:31 2001 From: ykingma at accessforall.nl (Ype Kingma) Date: Sun, 28 Oct 2001 20:25:31 +0100 Subject: binary search trees using classes References: Message-ID: <3BDC5B9F.32246B75@accessforall.nl> Christy, christy johnson wrote: > > Hi, > I was wondering if anyone had a binary search tree > module I could use? I need to write a program that > counts the number of occurrences of each word in a > file, and outputs the word and corresponding counts > alphabetically. For example, if input is > > Have a nice day. Have a nice day. > Have a nice day. > Have a nice day. > > the output is > > a 4 > day 4 > have 4 > nice 4 > > The code has to be modular based on classes. I'm > thinking of making a > tree node that looks like this > > bintree[ [key, data], left, right] , > > where I can traverse the tree by simply incrementing > the current root > to the appropriate child. > > temp = bintree.root > temp = temp[1] #move to the left child. > temp = temp[2] #move to the right child. > > but I don't know how to implement it correctly using > classes. (i.e > using def __init__(self), etc) > You might consider an alternative: Counting words is better done using a dictionary. This will use hashing for lookups, which is normally faster than using a binary tree. Afterwards you can sort the keys of the dictionary and provide output from that. Another advantage is that you'll only need standard python data structures: counts = {} # put this in a loop providing the line in lower case and without punctuation: for word in line.split(): if counts.has_key(word): counts[word] += 1 else: counts[word] = 1 words = counts.keys() words.sort() for word in words: print word, counts[word] Regards, Ype -- email at xs4all.nl From phr-n2001 at nightsong.com Sat Oct 6 14:33:59 2001 From: phr-n2001 at nightsong.com (Paul Rubin) Date: 06 Oct 2001 11:33:59 -0700 Subject: Octonians in Python References: Message-ID: <7x3d4wpqi0.fsf@ruckus.brouhaha.com> "David Feustel" writes: > There is one additional system of complex numbers > (octonians) beyond quaternions. Are there any > python implementations of octonians? Octonians are also sometimes called octaves. I think they have applications in some esoteric areas of theoretical physics, but I know of no applications at all for them in ordinary CS or engineering. That's probably why there aren't many implementations around. Octonian arithmetic is not only noncommutative, but it's also nonassociative. Here's a nice article abont octonians, by the always entertaining John Baez: http://www.math.niu.edu/~rusin/known-math/97/divialg2 From sholden at holdenweb.com Tue Oct 2 10:46:34 2001 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 2 Oct 2001 10:46:34 -0400 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> Message-ID: "Dale Strickland-Clark" wrote in message news:l1gjrtsru6nual0ress6vqp70s044u38ij at 4ax.com... > "Steve Holden" wrote: > > >"Dale Strickland-Clark" wrote in message > >news:9lajrtcqsojv72nr88c7j6kmdapjo44vc0 at 4ax.com... > >> A 'properly' encapsulated business class tends to involve methods and > >> attributes. However, managing attribute assignment gets very messy > >> with __setattr__ as you need to devise a scheme to distinguish class > >> attributes and working instance variables. > >> > >> Often, externally visible class attributes need to be validated and > >> instance variables don't. Or they may get stored elsewhere. > >> > >> What strategies have people come up with to manage this distinction > >> without bogging the code down in excessive checks. > >> > >> I would really like a way to distinguish between these two without > >> having to check dictionaries. > >> > >Dale: > > > >I'm not quite sure what problem you are trying to solve here. Are you > >suggesting that your code will change some class attributes and some > >instance attributes to parameterize the operation of all instances for a > >particular context. Maybe I need another cup of coffee ... > > > >Well, the coffee was a good idea. Your problem is that when you *use* > >__setattr__ you need to know whether you are setting a class or an instance > >variable, right? And you want to set class attributes from inside methods? > > > >Perhaps you'd explain what you mean by "proper" encapsulation is a problem > >in your particular context. I'm presuming that you are working in a COM > >environment, but of course I've been wrong before... > > > >regards > > Steve > > > >PS: See recent thread on not hiding your email address from spam! > > I thought this might be difficult to convey. This is typical of the > approach I'm currently using: > > def __setattr__(self, field, value): > if self._dbTable.has_key(field): > self._dbTable[field].validate(value) > self._fields[field] = value > self._saved = 0 > else: > self.__dict__[field] = value > > I have to distinguish between assignments to 'public' attributes > (which will go in my database) and instance variables which are used > throughout the class. I need to validate assignments to the database > but just let everything else through. > > But it means that EVERY internal assignment to instance attributes > needs to go through this code. > > I guess what I'm after is a distinction between private and public > attrbutes. > > Does that make it any clearer? I think so. For a start it appears to mean that we can forget all about class attributes ... I'm not sure why using a dictionary appears so evil to you, given that you seem to need the dictionary for field validation anyway. Two possible simplistic alternatives suggest themselves immediately, which might be enough to loosen your thinking and give you a better solution for your needs. 1. Use names with a special prefix for the database fields, then you can just test the attribute name using beginswith() or similar to determine whether it's a database filed. 2. Have objects store database fields inside another object (such as a DatabaseTuple), so instead of assigning object.dbfield = value you assign object.db.field = value This localises the database fields and means you don't need __setattr__ on the object itself. Of course there may well be valid reasons why neither of these approaches is satisfactory. Explain why not, and others might well have better suggestions. regards Steve -- http://www.holdenweb.com/ From grante at visi.com Wed Oct 10 23:05:30 2001 From: grante at visi.com (Grant Edwards) Date: Thu, 11 Oct 2001 03:05:30 GMT Subject: Sockets References: <3BC50853.505C8641@engcorp.com> Message-ID: On Wed, 10 Oct 2001 22:47:47 -0400, Peter Hansen wrote: >Hugo Martires wrote: >> My server need to send 2 strings separeted: [...] >> The problem is that the Client received s1 and s2 in one only string. >> >> How can i received in 2 separeted variables ? > >I note the other answers, and still feel the need to point out two >things. > >1. When asking questions of this sort, it is *always* advisable > to post sample code showing what you are trying to do. > If you don't, the answers are just guesses (maybe educated ones, > but still guesses). > >2. Assuming you are opening a socket between the two programs, Another unstated assumption is that he's opening a _TCP_ socket since the problem he's reporting is common among TCP beginners. However, "socket" != "TCP", so it is (like the man said) an educated guess. -- Grant Edwards grante Yow! If I felt any more at SOPHISTICATED I would DIE visi.com of EMBARRASSMENT! From hughett at mercur.uphs.upenn.edu Wed Oct 17 10:52:28 2001 From: hughett at mercur.uphs.upenn.edu (Paul Hughett) Date: 17 Oct 2001 14:52:28 GMT Subject: BBLimage 0.65 is now available Message-ID: <9qk5vc$o8k$4@netnews.upenn.edu> The source distribution kit for BBLimage version 0.65 is now available from http://www.med.upenn.edu/bbl/publications_downloads/downloads/software.shtml BBLimage is a collection of tools for processing volume images, especially medical images; it includes Pyvox, a Python extension for large multi-dimensional arrays. Features added in release 0.65 include: Motif is now required only to compile the qdv image viewer. LAPACK and BLAS are now optional; BBLimage will use an internal lightweight version if it cannot find one on the host platform. Compilation and installation on Solaris 8 have been verified using the gcc compiler. New functions row(), column(), matrix(), point(), and vector() have been added to the pyvox module; these functions all attempt to convert any reasonable data format into a Pyvox array of the specified flavor and type double. BBLimage is currently available as an alpha release under an open- source license and is written in ANSI C and designed to be easily portable to any Unix or Posix-compatible platform. Some programs also require the X Window System. Paul Hughett ================================================================ Paul Hughett, Ph.D. Research Associate Brain Behavior Laboratory 10th floor Gates Building Hospital of the University (215) 662-6095 (voice) of Pennsylvania (215) 662-7903 (fax) 3400 Spruce Street Philadelphia PA 19104 hughett at bbl.med.upenn.edu A rose by any other name confuses the issue. -Patrick E. Raume ================================================================ From pinard at iro.umontreal.ca Mon Oct 8 10:24:43 2001 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 Oct 2001 10:24:43 -0400 Subject: SPAM (Re: ANNOUNCE: "Compiler") In-Reply-To: References: <7xitdr4ccv.fsf@ruckus.brouhaha.com> Message-ID: [Andreas Otto] > (e.g. i hope phyton will catch up) Still unable to spell the language correctly, hey? :-) > once a while i post the current state of the Tcl based compiler > just to speed up competition Just stop worrying! The competition will gladly take care of itself. :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From tim.one at home.com Wed Oct 17 23:26:23 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 17 Oct 2001 23:26:23 -0400 Subject: signum() not in math? In-Reply-To: <3BCC4F94.9170B0BB@darwin.in-berlin.de> Message-ID: [Dinu Gherman] > ... > To prevent some folks from getting me wrong: I *do* like Py- > thon and 2.2 will be likely the best Python there ever was, > but I fail to understand why people don't care to make a damn > jolly good product even better? So let's ask: everyone on c.l.py please send a msg to Dinu explaining why you personally haven't submitted a patch to add signum() . > All it takes in this case is to undust a few corners of the > standard library and give it back some of the "ease-of-use"/ > "battery-inluded" philosophy that it used to be advocated > with. > > Now,-that-would-certainly-deserve-a-PEP'ly, Without a PEP, and without anyone contributing code, docs and a test suite, it's a safe bet nothing will happen. batteries-are-best-when-they-can-power-more-than-one-toy-ly y'rs - tim From gabriel_ambuehl at buz.ch Tue Oct 23 12:29:21 2001 From: gabriel_ambuehl at buz.ch (Gabriel Ambuehl) Date: Tue, 23 Oct 2001 18:29:21 +0200 Subject: programming unlimited "categories" in python ? In-Reply-To: <5.1.0.14.0.20011023130239.088b9768@imap.hq.movilogic.com> References: <97ae44ee.0110230529.5c33dd83@posting.google.com> <97ae44ee.0110221318.6eec382d@posting.google.com> <7F1B7.149206$5A3.51197886@news1.rdc2.pa.home.com> <97ae44ee.0110230529.5c33dd83@posting.google.com> <5.1.0.14.0.20011023130239.088b9768@imap.hq.movilogic.com> Message-ID: <121179282033.20011023182921@buz.ch> -----BEGIN PGP SIGNED MESSAGE----- Hello Lucio, Tuesday, October 23, 2001, 6:08:48 PM, you wrote: > i think the key in what he is asking is that he is not talking > about ONE tree. So he want's to have like relational trees? Sounds like serious fun to implement. > what if i have the followinf: > region: > 1- africa > 1.1 mozambique > 1.1.1 capital > severity > 1. deadly > 1.1 next 5 hours > 1.2 next ten days > and you want a query like '5 hours deadly in africa' You still need a link between the two, else you haven't got any chance to match them anyway so why not just build the region tree and store all the data under it? then you query for africa first and fetch only the results which have got the attribute deadly in 5 hours? > problems with this: > a) the categorization is not stored in the object, but in the tree > that points at it. not so big a deal in SQL (you can select from > all_trees where objectid = self), but what about python? how would > you implement it? I wasn't thinking about the implementation itself but mostly about suitable approaches. IMHO, you should try to squeeze your data model into ONE tree and the problem is almost solved. > b) africa can be pretty big. shouldnt i be able to get/(build?) the > region tree under any node of the others? something like olap. Uuh? Of course you can have africa as a subtree of some other tree if you use some sort of generic tree class like: class tree [some class] data list childs (pointer to parent) (pointer to next sibling) Best regards, Gabriel  -----BEGIN PGP SIGNATURE----- Version: PGP 6.5i iQEVAwUBO9WM1MZa2WpymlDxAQGxfAgAhW7j3v5EU9CHLojNlFAD/Yc/5dHLGTKi Ra4wZh84CnjoqEmgpDVLAs2HGKFZe+jDrb7vVA03qfpeGz98k/wJ9JRL3r0MR07s FSKqF4F8Nl2ppNLagu0ZMr4SA6m9CQ0Ur6pkNUjvk7ETu1mtiCMwFtRQ9hunEO9C Zibf8h3dWMszy8zs75U06Fw9lUiMemEH4qTDB6t4PMQVpVXa4pX2XDcE5ApdEoxH +9HuZmyGrGefIMfDJZK7e4tqv2/PjYVCMv9+2j3hDfL1+aZPI8DCDvRuQPKruR1n qw0/40TddnYABhipzDPICBvOQ9hPwsS1O3f5DMh2MPDY7m9JM2tpeQ== =p5+V -----END PGP SIGNATURE----- From gh_pythonlist at gmx.de Mon Oct 1 20:37:32 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 2 Oct 2001 02:37:32 +0200 Subject: Problems embedding python (undefined symbol: stat) In-Reply-To: ; from obscurity@obscure.org on Mon, Oct 01, 2001 at 06:19:03PM +0000 References: Message-ID: <20011002023731.B1161@lilith.hqd-internal> On Mon, Oct 01, 2001 at 06:19:03PM +0000, obscurity wrote: > On Tue, 25 Sep 2001 00:04:24 GMT, obscurity > wrote: > > I'm trying to embed python in a C++ app I'm writing (on linux). All > > I've added so far is a call to Py_Initialize, and when I run my app > > it dies somewhere in Py_Initialize with "undefined symbol: stat". > > Isn't stat a standard libc call? If so, how the hell can it be > > undefined? I'm coming to the conclusion that my python > > installation is broken in some way, but it was a simply > > ./comfigure;make;make install job, so I haven't done anything > > strange with it. > > > > Can anyone offer an advice in fixing this? > > So, can *no-one* help me with this? Not even a vague pointer to some > documentation or something? Anyone? Pretty please? Perhaps you haven't linked against all the required libraries. This was just being discussed in the thread "Problem with linking embedding C application". For something quick and dirty, do a ldd $PYTHONROOT/bin/python and link against these libraries: gerhard at lilith:~ > ldd /usr/bin/python libpthread.so.0 => /lib/libpthread.so.0 (0x40025000) libdl.so.2 => /lib/libdl.so.2 (0x4003b000) libutil.so.1 => /lib/libutil.so.1 (0x40040000) libm.so.6 => /lib/libm.so.6 (0x40043000) libc.so.6 => /lib/libc.so.6 (0x40062000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) So I also link with -lpthread -ldl -lutil -lm. HTH, Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From fgeiger at datec.at Fri Oct 12 02:46:13 2001 From: fgeiger at datec.at (F. GEIGER) Date: Fri, 12 Oct 2001 08:46:13 +0200 Subject: Holden's Python Web Programming Book References: <4glx7.11739$I83.231559@atlpnn01.usenetserver.com> Message-ID: <9q63ma$rug$1@newsreaderg1.core.theplanet.net> Looks quite promising! Especially the XML stuff I'll be interested in. Cheers Franz "Steve Holden" schrieb im Newsbeitrag news:4glx7.11739$I83.231559 at atlpnn01.usenetserver.com... > Further update: you can see a high-level overview at > > http://www.holdenweb.com/steve/webtoc.txt > > Hope this helps. > > regards > Steve > -- > http://www.holdenweb.com/ > > > "DeepBlue" wrote in message > news:tsb84mihle6d07 at corp.supernews.com... > > This is a question for Steve Holden: > > Steve, > > Is there a way to view the table of contents of your upcoming book? > > I want to compare this book with Mitchell's book "Python for the Web." > > Thanks, > > DB > > > > > > From Mathias.Palm at gmx.net Tue Oct 16 11:26:09 2001 From: Mathias.Palm at gmx.net (Mathias.Palm at gmx.net) Date: Tue, 16 Oct 2001 17:26:09 +0200 Subject: Python 2.1 with Tix under Windows Message-ID: <3BCC5191.399932D@gmx.net> I currently writing a python application which I need to port to MS Windows systems. This application contains a gui which is written using Tix for most parts of it. Unfortunately, Python 2.1. has no tix library included contrary to what they say. So I tried to install the Tix package later on. Because I do not know much about Windows, I did not come very far. The installation of an own tcl/tk including tix works fine. Details: import Tix works fine root = Tix.Tk() returns the TclError: Can?t find package Tix Just copying the tix package into the tcl directory (under Python) doesn?t work either. Python 2.2 neither a Tix support build in. Anybody an idea? Thanks in advance. From cdelarue at bigfoot.com Wed Oct 10 07:43:41 2001 From: cdelarue at bigfoot.com (Christophe Delarue) Date: 10 Oct 2001 04:43:41 -0700 Subject: LIKE missing in gadfly Message-ID: <2c71728a.0110100343.75dd89eb@posting.google.com> I am quite new in SQL. I make through a gfclient/gfserve a query resulting of a wilde result. Right now, I reduce this result on the client side by using a regexp on a special field. How could this be done on the server side ? In the gadfly doc, the LIKE command is ommitted due to the ``re'' module in python. All right, how could I implement this on the server side to avoid too many data to transit. i.e. TABLE='FELLOWS' FIRSTNAME NAME --------------- Bill O'shea Chris El'Froggy I'd like something : SELECT name FROM fellows WHERE name LIKE NAME.match(re.compile("[A-Z]{2}'[A-Za-z]+")) thank's From gherman at darwin.in-berlin.de Fri Oct 12 07:42:22 2001 From: gherman at darwin.in-berlin.de (Dinu Gherman) Date: Fri, 12 Oct 2001 13:42:22 +0200 Subject: signum() not in math? References: <3BC6B774.4688E9A2@darwin.in-berlin.de> Message-ID: <3BC6D71E.D701A15@darwin.in-berlin.de> Des Small wrote: > > The only possible controversy would be the definition at zero. I > usually define signum(0) = 0, but others may not. I don't even want > to think about the differences between +0 and -0 in this case. Well, I'm surethis can be solved, and, no worries, there doesn't seem to be any such difference between -0 and +0 in Python: PythonWin 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32. >>> -0 < +0 0 >>> -0 > +0 0 >>> -0 == +0 1 >>> -0. == +0. 1 >>> -0. < +0. 0 >>> -0. < +0 0 > I certainly endorse the sentiment that it should be available in the > standard library, but now that I come to look (and prompted by your > use of "sign()") I find that there _is_ a sign function in Numeric. > Since I always use Numeric, this removes much of the urgency. Which is sort of a SIGNificant overhead for using one function, isn't it? ;-) (Ha - if you don't take it, write your own!) > I think there is a sentiment that Numeric should be absorbed into the > standard library, after the code has been cleaned up (which noone has > time to do). Oh, really? I argued for that three years ago, maybe. The response was sort of "Who needs that in standard Python?" Good to see times changing for the better... If only the same would happen to the documentation... sigh! Dinu -- Dinu C. Gherman ReportLab Consultant - http://www.reportlab.com ................................................................ "The world becomes a better place as a result of the refusal to bend to authority and doctrine." (Noam Chomsky) From mlh at idi.ntnu.no Wed Oct 10 14:32:40 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 10 Oct 2001 20:32:40 +0200 Subject: Assigning to lists with arbitrary names References: <3BC35131.C9AB1393@motorola.com> Message-ID: <9q2488$nld$1@tyfon.itea.ntnu.no> "Stephen Boulet" wrote in message news:3BC35131.C9AB1393 at motorola.com... > I can't quite figure out how to do this. > > I have 100 text files in a directory: file00.txt to file99.txt. > > I want to read each file in turn, parse it, and generate a list from > each file. > > Here's the problem: I want to name each list list00 to list99. I don't > want to do list[0] to list[99] (since each list is actually a list of > lists, and I'd like to avoid a list of lists of lists :). Excuse me if this isn't helpful, but -- why do you want to avoid a list of lists of lists? And -- if each file generates a list, and you have a list of files -- wouldn't that simply be a list of lists? (I can see the problem with naming the list if lists "list", since that is the name of the built-in type/function list... :) > Any idea how I can do this? Thanks. Certainly -- just use eval(), or exec or access globals() or something. I don't see why you think having something named foo42 is better than foo[42], though, since you will no longer be able to iterate over all of your foos, and you will have to hand-code everything... But here is an example of how it could be done (untested): for number in range(100): exec 'list%s = process("file%s.txt")' % (number, number) Again: I would not advise you to actually use this -- I see no reason to, and I see several reasons not to :) > -- Stephen -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From tim at vegeta.ath.cx Wed Oct 31 17:24:56 2001 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Wed, 31 Oct 2001 22:24:56 GMT Subject: hola nesesito su ayuda References: Message-ID: [ Broadcast in Spanish ;] Me parece que fernando orellana dijo: > hola que tal Bien. Gracias. > soy leandro vivo en un pueblito de argentina y estudio = > analista de sistemas. Me llamo Tim. Yo estudio cualquiera que me interesa. ;) Estudi? Espa?ol, Romana, Perl, Python, y m?s linguas. Este grupo habla ingl?s. Parece que no hay grupo espa?ol para python. En este caso, es mejor que escribas en ingl?s. Mi espa?ol me falta a veces. (?) Y yo creo que la majoridad de las personas aqui no hablan espa?ol; alguien otra lo habla? Bueno, vamos a ver... ;) [ snippage ] > bueno les escribo porque tengo una duda nesecito hacer un sistenma de = > matriculacion y tengo que ingresar los nombres de los alunmos, asi como = > su correo, su numero de legajo y las materias que va a tomar, donde = > deveria meter estas variables?, en listas o diccionario o talves hacerlo = > con clases ? bueno si me pueden dar una mano mejor y si nescesitan mas = > datos o que sean mas puntuales diganme y yo les escribo de nuevo. > desde ya muchas gracias por su atencion y perdonen mi molestia. > suerte y gracias un saludo leo. Si hay muchisimas personas, yo usar?a MySQL u otra db. Si necesitas usar python, diccionarios o clases son buenas ideas. If you want as much help as possible from as many experts here as possible, post in English. My Spanish isn't what it used to be. =) Tim -- The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us. -- Bill Watterson (Calvin & Hobbes) From jdunnett at uoguelph.ca Mon Oct 29 07:37:39 2001 From: jdunnett at uoguelph.ca (Jeff Dunnett) Date: Mon, 29 Oct 2001 07:37:39 -0500 Subject: python binary search References: <344d84d2.0110272241.71ad6f23@posting.google.com> <3BDC0341.8A213560@engcorp.com> <3BDCA674.FF268D0E@uoguelph.ca> <3BDCF1FD.45F0EF49@engcorp.com> Message-ID: <3BDD4D93.401D5621@uoguelph.ca> No but by one of his close assoiciate Prof. Dave McCaughon :) Jeff Peter Hansen wrote: > Jeff Dunnett wrote: > > > > In case your wondering the school that I attend teaches Python. In fact it > > is a main part of one of the first major software design course. That is > > the University of Guelph in Ontario Canada. In fact the departement has > > quite a lot of fallowers who like Python. > > Hmmm... that wouldn't by any chance be a course taught by > Professor Kremer, would it? > > -- > ---------------------- > Peter Hansen, P.Eng. > peter at engcorp.com From Georg.Bisseling at pallas.com Fri Oct 19 09:07:47 2001 From: Georg.Bisseling at pallas.com (Georg Bisseling) Date: Fri, 19 Oct 2001 15:07:47 +0200 Subject: Traceback oddity References: Message-ID: <3BD025A3.D0724FFC@pallas.com> Dale Strickland-Clark wrote: > File "S:\JOBS\Gibson\Library Manager\librarymanager\cli\lb.py", line ... > File "s:\jobs\gibson\library manager\librarymanager\lbdbTable.py", > > The observant will have noticed that the first few filepaths are in > mixed case whereas the last are all lower case. > > I only noticed because I'm trying to post-process this report. > > Any ideas why? Because Bill didn't get it right in the first place... The FAT12/16/32- and NT-Filesystems are not case sensitive but "case aware". That means you can have a file named "a" and a file named "A" but they are not allowed to live in the same directory. If you open "a" or "A" for read you get either "a" or "A" whatever is there. To complicate things the newer Windows-Versions do not show the filenames as they are stored on disk but in a "beautified" Form. So it is safe and consistent to use lower case letters when searching for files to read. ciao Georg From claird at starbase.neosoft.com Mon Oct 15 09:08:51 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 15 Oct 2001 08:08:51 -0500 Subject: python + xml performance compared to Java and C++ ?? References: Message-ID: <4C6BC4CCC8BA9D13.4ADD8C5B690BF72E.69C5F520C514F353@lp.airnews.net> In article , Philipp Weinfurter wrote: >Markus Jais wrote: >>hello >>does anyone have experiences how fast xml processing >>and XSLT processing with python (using PyXML and 4Suite tools) >>is, compared to Java and C++ (using the apache tools, like >>Xalan, Xerces....) > >dunno about java, but the C++ versions of the apache tools are >much much faster than anything you can do with python. but that's >kinda obvious, since XSLT processing ist quite CPU intensive. >same goes with building large DOM trees. i guess with SAX you'd >be better off, using pure python. > >philipp >(who thinks that XSLT is the ugliest language ever designed) There are several issues here, as so often is the case with performance questions. 4Suite simply is not designed for performance, from all I know. It's really quite slow, even compared to some of the Java-oriented engines, whose advertising exceeds their performance. I have ideas about "quick fixes" that might work with pyXML and 4Suite to accelerate their performance a great deal. They'd no longer be "pure Python" in the sense they are today. Yes, I agree that this appears to be an area where C codings have jumped quite a bit ahead of what's generally available in Python. 'Everyone aware of the new XSLT book from O'Reilly? That might palliate, at least, a bit of the sentiment about its ugliness. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From aleax at aleax.it Fri Oct 12 04:14:14 2001 From: aleax at aleax.it (Alex Martelli) Date: Fri, 12 Oct 2001 10:14:14 +0200 Subject: Python Cookbook: last call for recipes for printed version References: <9q52b1$3q5$1@lancelot.camelot> <15302.9739.67065.524596@beluga.mojam.com> Message-ID: <9q68ok05uq@enews1.newsguy.com> "Skip Montanaro" wrote in message news:15302.9739.67065.524596 at beluga.mojam.com... > > Alex> while the Python Cookbook > Alex> (http://aspn.activestate.com/ASPN/Cookbook/Python) will stay open > Alex> for good, soon we'll have to "freeze" the set of recipes to be > Alex> considered for the book version to be published by O'Reilly & > Alex> Associates. > > I guess this aspect wasn't well publicized. This is the first time I've > heard there was going to be a book... On http://aspn.activestate.com/ASPN/Cookbook/Python, the relevant sentence is "O'Reilly plans to publish a selection of the recipes in a paper volume". But you're surely right that we didn't do enough to publicize this -- and I suspect that Frank Willison's untimely, much-mourned demise may well have to do with this:-(. Maybe c.l.p.announce's technical issues didn't help, either (I can't find any Cookbook announcement on c.l.p.a's archives). Please see http://www.oreilly.com/frank/pythoncook_0501.html for Frank's own words on the subject. While I can only speak for myself, I'm sure my apologies for not doing enough to communicate the Cookbook's multiple purposes are shared by all involved. But the Cookbook site will stay, and there's a last window of opportunity to get a recipe into it in time for consideration for paper-publication -- and/or edit recipes you have already submitted (particularly to beef up discussion!-), add comments, and so on, again in time for your contribution to be considered for the printed-book. Please help fulfil Frank's vision! Alex From phr-n2001d at nightsong.com Tue Oct 9 12:07:38 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 09 Oct 2001 09:07:38 -0700 Subject: changing a strig to a variable References: Message-ID: <7xsncsssol.fsf@ruckus.brouhaha.com> "Raibatak Das" writes: > this might be a silly question but i would greatly appreciate an answer. > is there any way to convert a string to a variable name. that is, suppose > i have x = 'var' and i want to do, say, var=13 is there an easy way to do > so? vars()[x]=13 From emile at fenx.com Sat Oct 13 10:07:29 2001 From: emile at fenx.com (Emile van Sebille) Date: Sat, 13 Oct 2001 07:07:29 -0700 Subject: Newbie - converting binary data to ASCII text ? References: <9q92g4$6hd$1@wanadoo.fr> Message-ID: <9q9i4l$mbdm3$1@ID-11957.news.dfncis.de> "Cyr" wrote in message news:9q92g4$6hd$1 at wanadoo.fr... > hello, > > I'm completely new to python and I've got problem reading binary data file. > When I read a file with read(), the binary data aren't converted. In fact, > I'd like to know if there's a method for converting a file object (or a > string) from binary to the equivalent ASCII text. The data aren't written in > a particular format. Fortran doesn't have any problem with theese files > > I'would greetly appreciate any help, thanks > > Cyril D > > PS : I'm working on an SGI Irix operating system > > Getting the data shouldn't be a problem. >>> bytes = open("command.com",'rb').read() >>> len(bytes) 93880 # which matches >>> print bytes[:10] MZ? ? $? >>> print repr(bytes[:10]) 'MZ\xb8\x00\xb8\x00\x00\x00$\x04' As for making sense of the bytes, the only way you'll do that is to use/write a parser that understands how the content was put on the disk, and each application pretty much decides its own internal data scheme. -- Emile van Sebille emile at fenx.com --------- From paul at zope.com Thu Oct 25 13:08:21 2001 From: paul at zope.com (Paul Everitt) Date: Thu, 25 Oct 2001 13:08:21 -0400 Subject: can I use sessions with Zope? References: <9r8ihf$emi$06$1@news.t-online.com> Message-ID: <3BD84705.5040208@zope.com> Session tracking isn't currently a core part of Zope, but is scheduled for addition in the next major release (2.5). Instead, there are quite a number of add-on products to do this that have been baked over many months/years. Here's the version that's going into the core of Zope: http://www.zope.org/Members/mcdonc/Products/CoreSessionTracking Here is a link to show other session products: http://www.zope.org/SiteIndex/search?text_content=session&meta_type%3Alist=Software+Product Hope that helps... --Paul Timo Kuchenbuch wrote: > Is this possible to open a session with Zope??? > In the dokutemtaion I havent found anything. > > Thanks > Timo > > > From opsys at voodooland.net Mon Oct 1 13:07:56 2001 From: opsys at voodooland.net (Open Systems) Date: Mon, 1 Oct 2001 12:07:56 -0500 (CDT) Subject: GNU wars again (was Re: Proposal: add vector arithmetic to array module) In-Reply-To: Message-ID: > Ever heard the phrase "information should be free" ? Check out some It was "Information wants to be free", and thats the DUMBEST thing I have ever heard. > Thinking about it this way, the GPL is more free than the XFree86 license, > since it is the continuing availability of the code, and variations on it, > that the license ensures - not your personal human rights/liberties/whatever. Whoa nelly. Can't let that fly. "...since it is the continuing availability of the code, and variations on it, that the license ensures". First of all Code that is BSDL'ed is ALWAYS available for the user AND developer in the form it was released as BSDL'ed code. You *cant* take it away any more then you can take back air on the planet and bottle it all up and charge people for it. The second problem with the GPL is your second point. "and variations on it" the GPL attempts to take and take and take. It attempts to take code that doesnt belong to you. Like a virus wrapping around healthy DNA it attempts to re-write the healthy DNA with its own code "the GPL license" thereby freeing up the entire application that uses any GPL code in it to also become available under the GPL to infect more code out there, and to end binary only distributions, and to do other evil things. So dont try saying the GPL is free. It is NOT free. And no one says buys that argument. I dont have a problem with the GPL as long as you do not call it free code when its applied to code. It's a bold faced lie. Chris From dale at riverhall.NOSPAMco.uk Wed Oct 3 08:17:28 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Wed, 03 Oct 2001 13:17:28 +0100 Subject: Assignment not the same as defining? References: <3itlrt0hds3sjjjt5apj53oo9840sopomp@4ax.com> Message-ID: "Steve Holden" wrote: >"Dale Strickland-Clark" wrote in message >news:3itlrt0hds3sjjjt5apj53oo9840sopomp at 4ax.com... >> A solution I thought I had to using __setattr__ doesn't seem to work. >> >> class wibble: >> def __init__(self): >> >> self.__setattr__ = self.set >> >> def set(self, attr, value): >> >> >> My late bound __setattr__ is never called. >> >> I've clearly misunderstood something fundamental here. What am I doing >> wrong? >> >From Python 2.0 Reference Manual, section 3.3.2: >""" >The following methods can be defined to customize the meaning of attribute >access (use of, assignment to, or deletion of x.name) for class instances. >For performance reasons, these methods are cached in the class object at >class definition time; therefore, they cannot be changed after the class >definition is executed. >""" > >foiled-by-an-optimization-ly y'rs - steve Thanks Steve. What a handy chap you are to have around but can I just eject a heartfelt *BOLLOCKS* on this one? Now I need yet another cludge. -- Dale Strickland-Clark Riverhall Systems Ltd From rjroy at takingcontrol.com Tue Oct 30 16:57:58 2001 From: rjroy at takingcontrol.com (Robert Roy) Date: Tue, 30 Oct 2001 21:57:58 GMT Subject: How to read a xml-file sequentially References: Message-ID: <3bdf1dd6.183937921@news1.on.sympatico.ca> "Thomas Weholt" On Tue, 30 Oct 2001 12:17:37 GMT, >Hi, > >I need to read a xml-file sequentially, piece by piece, when a given end-tag >to a given start-tag is found, the xml-data inbetween the start and end are >sent to a different method for processing, then the next piece of data is >read, sort of like old-school record-based files. > >Only the needed data is kept in memory. > >How can this be done using preferrably expat or sax? No DOM cuz the files >are huge. > >Thomas > > Here is an example of how you could do this. My example document is an xml document from project gutenberg. It contains a bunch of letters which I wish to extract into individual documents.. http://gutenberg.hwg.org/xmlfiles/lvfnd10v2.xml You define a class Handler that exposes 3 methods: initialise, write, and finalise. In this case the document I have contains a bunch of letters Then you define a parser class that takes as a parameter an instantiated Handler. The parser class will then call the appropriate methods in Handler. I also defined a FancyHandler that will create parse each file and output it in html format. This is something I just slapped together so the implementation is a bit fragile, ie if there is no tag, the html will be incorrect, but it illustrates the concept. bob ######### the basic stuff from xml.parsers import expat class Handler: def __init__(self): self.filenum = 1 self.outfile = None def initialise(self): self.outfile = open("letters/letter%s"%self.filenum, 'w') self.filenum += 1 def finalise(self): self.outfile.close() self.outfile = None def write(self, data): self.outfile.write(data) class parsit: def __init__(self, handler, interestingtag="record"): self.parser = parser = expat.ParserCreate() parser.StartElementHandler = self.unknown_starttag parser.EndElementHandler = self.unknown_endtag parser.CharacterDataHandler = self.handle_data self.data = [] self.interestingtag = interestingtag self.capture = 0 self.handler = handler def handle_data(self, data): if self.capture: self.handler.write(data) def unknown_starttag(self, tag, attrs): if tag == self.interestingtag: self.capture = 1 self.handler.initialise() if self.capture: hd = self.handle_data hd('<%s' % tag) for item in attrs.items(): hd(' %s="%s"' % item) hd('>') def unknown_endtag(self, tag): if self.capture: self.handle_data('</%s>' % tag) if tag == self.interestingtag: self.capture = 0 self.handler.finalise() def feed(self, data, isfinal=1): self.parser.Parse(data, isfinal) def close(self): pass if __name__=="__main__": # p = parsit(FancyHandler(), "letter") p = parsit(Handler(), "letter") infile = open('lvfnd10v2.xml') # feed only what you can chew while 1: buffer = infile.read(16000) if not buffer: p.feed(buffer) break else: p.feed(buffer, 0) ########## this is an alternative handler class FancyHandler: def __init__(self): self.filenum = 1 self.outfile = None self.outfilenames = [] self.start_handlers = {'para': self.start_letter, 'para': self.start_para, 'title': self.start_title, 'from': self.start_from, 'to': self.start_to, 'sig': self.start_sig} self.end_handlers = {'letter': self.end_letter, 'para': self.end_para, 'title': self.end_title, 'from': self.end_from, 'to': self.end_to, 'sig': self.end_sig} def initialise(self): self.parser = parser = expat.ParserCreate() parser.StartElementHandler = self.unknown_starttag parser.EndElementHandler = self.unknown_endtag parser.CharacterDataHandler = self.handle_data fn = "htmlletters/letter%s.html"%self.filenum self.outfilenames.append(fn) self.outfile = open(fn, 'w') self.filenum += 1 self.title = '' self.intitle = '' def finalise(self): self.parser.Parse('', 1) self.outfile.close() self.outfile = None def write(self, data): #if data.find("letter")!= -1: print data self.parser.Parse(data, 0) def handle_data(self, data): if self.intitle: self.title += data self.outfile.write(data) ## handlers def unknown_starttag(self, tag, attrs): hndlr = self.start_handlers.get(tag, None) if hndlr: hndlr(attrs) def unknown_endtag(self, tag): hndlr = self.end_handlers.get(tag, None) if hndlr: hndlr() def start_letter(self, attrs): self.handle_data('<html>') def end_letter(self): self.handle_data('</body></html>') def start_para(self, attrs): self.handle_data('<p>') def end_para(self): self.handle_data('</p>') def start_title(self, attrs): self.handle_data('<head><title>') self.intitle = 1 def end_title(self): self.handle_data('%s

%s

'%(self.title, self.title)) self.intitle = 0 def start_from(self, attrs): self.handle_data('') def end_from(self): self.handle_data('') def start_to(self, attrs): self.handle_data('') def end_to(self): self.handle_data('') def start_sig(self, attrs): self.handle_data('') def end_sig(self): self.handle_data('') def makeIndex(self): pass From chrishbarker at home.net Tue Oct 23 12:23:50 2001 From: chrishbarker at home.net (Chris Barker) Date: Tue, 23 Oct 2001 09:23:50 -0700 Subject: error messages raised by python got me thinking. References: Message-ID: <3BD59996.4C9ECDBF@home.net> "Delaney, Timothy" wrote: > Much the same information would be conveyed though if, in addition to the > line number, the column number were also displayed in the traceback. True, and I have wanted this in a lot of situations. How hard would it be? I'm guessing that no information about the the columns is stored in the bytecode, but maybe I'm wrong. -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From emile at fenx.com Fri Oct 5 08:57:59 2001 From: emile at fenx.com (Emile van Sebille) Date: Fri, 5 Oct 2001 05:57:59 -0700 Subject: nocaret.py - Zope install error References: Message-ID: <9pkh2b$imgqo$1@ID-11957.news.dfncis.de> These SyntaxError's are intentional, and the current CVS has them renamed to badsyntax_future3.py, etc. HTH, -- Emile van Sebille emile at fenx.com --------- "Mike James" wrote in message news:Xns9130D2AC2B465maentigejmsethnnt at 24.2.68.108... > I have zope 2.4.1, apache 1.3.20, RH linux 7.1 - and here's the problem... > > When I run ./install, I get the following errors: > > Compiling python modules > File "/usr/local/zope/lib/python2.1/test/nocaret.py", line 2 > [x for x in x] = x > > SyntaxError: can't assign to list comprehension > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future3.py, line 3) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future4.py, line 3) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future5.py, line 4) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future6.py, line 3) > SyntaxError: from __future__imports must occur at the beginning of the file > (test_future7.py, line 3) > > Everything else seems to go just fine. When I run ./start, I get messages > about the HTTP and FTP server starting. The PCGI server starts, but never > goes into the background. Why is that? > > While the python process from ./start is running, I can access zope through > the browser (http://localhost:8080) and even manage zope using the inituser > id and password generated by the install. > > Just that one little problem about the ./start script is bugging me. Any > help would be appreciated!! thanks, Mike From sburr at home.com Mon Oct 22 16:41:10 2001 From: sburr at home.com (sburrious) Date: 22 Oct 2001 13:41:10 -0700 Subject: a better prime number generator References: <23d58b26.0110210939.55bb7e0c@posting.google.com> Message-ID: <5396362c.0110221241.13f2d550@posting.google.com> dhillon_rs at rediffmail.com (Rupendra Dhillon) wrote in message news:<23d58b26.0110210939.55bb7e0c at posting.google.com>... > #the following algo returns all the primes below x Not quite. When I ran your code, it included 4 in the list of primes. See below for the reason. > def getPrimesTill(x): > a = range(2,x) > c = [2] > > i = 0 > j = 0 > > foundone = 1 > > while i < len(a): > while j < len(c) and (c[j] < (.5 * a[i]) ) and foundone == 1: ^^^^^^^^^^^^^^^^^^ The culprit is here. When you get to a[i] == 4 and then test c[j] == 2, you drop out of the second while loop without checking whether 2 is a factor of 4. So "foundone" remains 1, and 4 is identified as prime. As you've probably noticed from the other responses, you could eliminate this problem by testing odd numbers only, which is in any case more efficient. It's also more efficient to test c[j] <= math.sqrt(a[i]) rather than .5 * a[i], since the square root of a number is its largest possible factor. I have a stylistic objection to your use of the name "foundone"; it's somewhat misleading, since you don't know if you've "found one" (i.e. a prime) until you get to the end of the inner loop. > if a[i]%c[j] == 0: > foundone = 0 > j = j + 1 > if foundone == 1 and i > 0: > c.append(a[i]) > j = 0 > foundone = 1 > i = i + 1 Rather than using an index and a while loop to test each member of a, the more natural approach in Python is to apply a for loop directly to a. See below for an example. > return c Since the other responses have focussed on alternative algorithms, I thought it might be helpful for you to see an edited version of yours reflecting the above comments: import math def getPrimesTill(x): a = range(3, x, 2) # test odd numbers only, c = [2] # since we know 2 is only even prime for candidate in a: maybeprime = 1 j = 0 while (j < len(c) and c[j] <= math.sqrt(candidate) and maybeprime): if candidate % c[j] == 0: maybeprime = 0 j += 1 if maybeprime: c.append(candidate) return c From tim at worthy.demon.co.uk Mon Oct 22 16:54:29 2001 From: tim at worthy.demon.co.uk (Tim Howarth) Date: Mon, 22 Oct 2001 21:54:29 +0100 Subject: Win32com to copy Excel worksheet References: <25cc93cd4a%tim@worthy.demon.co.uk> Message-ID: <395a9ecd4a%tim@worthy.demon.co.uk> In message <25cc93cd4a%tim at worthy.demon.co.uk> Tim Howarth wrote: > I'm trying to enter data into Excel using win32com.client and would like > to copy a worksheet. > > Sheets(1).copy Before:=Sheets(2) > > My question, how do you pass the "Before:=Sheets(2)" parameter using Repying to myself - tut. Ah I was doing it right but hadsn't set something up properly - (makepy?) Sheets(1).copy(Before=Sheets(2)) does now work. -- ___ |im ---- ARM Powered ---- From gh_pythonlist at gmx.de Mon Oct 1 07:49:18 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Mon, 1 Oct 2001 13:49:18 +0200 Subject: Problem with linking embedding C application In-Reply-To: ; from madsdyd@challenge.dk on Mon, Oct 01, 2001 at 01:16:58PM +0200 References: <9p9h2l$24o$1@kermit.esat.net> Message-ID: <20011001134917.A2116@lilith.hqd-internal> On Mon, Oct 01, 2001 at 01:16:58PM +0200, Mads Bondo Dydensborg wrote: > On Mon, 1 Oct 2001, Olivier Deme wrote: > > > Hi, > > > > We have written an application written in C, which invokes sometimes > > the Python interpreter for executing Python methods. > > > > So, I am trying to statically link our application with > > libpython*.*.a., but this result in various undefined symbols (see > > below). [...] > [...] > I have a machine, where I need to do: -lnsl -ldl -lreadline -ltermcap > -lpthread -lutil -lm to be able to link with python. > > The annoying thing is, that it is very hard to determine this in > general. At least I am not aware of any way to do it. I think this will do it. It does work for me: from distutils.sysconfig import get_config_var print get_config_var("LIBS") + " " + get_config_var("SYSLIBS") Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From peter at engcorp.com Wed Oct 10 22:47:47 2001 From: peter at engcorp.com (Peter Hansen) Date: Wed, 10 Oct 2001 22:47:47 -0400 Subject: Sockets References: Message-ID: <3BC50853.505C8641@engcorp.com> Hugo Martires wrote: > > My server need to send 2 strings separeted: > s1= 'xxx' > s2= 'yyy' > > My client must received like this: > rec1= 'xxx' > rec2= 'yyy' > > The problem is that the Client received s1 and s2 in one only string. > > How can i received in 2 separeted variables ? I note the other answers, and still feel the need to point out two things. 1. When asking questions of this sort, it is *always* advisable to post sample code showing what you are trying to do. If you don't, the answers are just guesses (maybe educated ones, but still guesses). 2. Assuming you are opening a socket between the two programs, my (educated :-) guess is that you are doing a pair of socket.send() calls with the two strings, and expecting these two be received *separately* with two recv() calls on the other end. If this is so, you misunderstand how sockets and TCP/IP and such work. Nowhere in the documentation will you find any guarantee that the data from two consecutive send() calls matches up with the two recv() calls. They might be lumped together so that you get 'xxxyyy' after the first recv(). You might have to use four recv() calls and get 'x', 'x', 'xxy' and finally 'yy'. No guarantees. Don't ever assume you have all the data just because recv() returns. And that's the reason behind John's suggestion of disabling the Nagel algorithm, since it *might* appear to solve the problem. Don't be fooled: it's a very fragile, hackish way of "fixing" the problem, and not suitable for "real" programs in most cases. (Standard anti-flame disclaimers apply...) -- ---------------------- Peter Hansen, P.Eng. peter at engcorp.com From john.thingstad at chello.no Wed Oct 10 05:39:44 2001 From: john.thingstad at chello.no (John Thingstad) Date: Wed, 10 Oct 2001 11:39:44 +0200 Subject: newbe question Message-ID: <20011010094532.CZAW10776.mta01@mjolner> I wrote the following function to use polymorphism. def rootClassName(var): """Return the name of the root of a sigle inheretance class tree. If multiple inheritance is used the leftmost class is traversed.""" if type(var) is ClassType: cls = var while len(cls.__bases__) != 0: cls = cls.__bases__[0] return cls.__name__ else: return "" Is there a built in function to do this ? From shalehperry at home.com Wed Oct 24 13:17:04 2001 From: shalehperry at home.com (Sean 'Shaleh' Perry) Date: Wed, 24 Oct 2001 10:17:04 -0700 (PDT) Subject: Question: CPython In-Reply-To: <3bd6f0f1_3@corp-goliath.newsgroups.com> Message-ID: On 24-Oct-2001 K?roly Ladv?nszky wrote: > What is CPython and where is it available? > > Thanks for any help, > CPython is the standard python we have all known and loved for years. There is a new thing called 'JPython' which is a python implementation in Java, so now the original python (implemented in C) is referred to as CPython to differentiate them. From fredrik at pythonware.com Sat Oct 20 10:19:35 2001 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 20 Oct 2001 14:19:35 GMT Subject: Python Aborts when I quit References: Message-ID: "tilwe" wrote: > } catch(const char * err) { > strcpy(errMsg, err) ; > cerr << "Error: " << err << endl ; > rRow = Py_None; + Py_INCREF(Py_None); > } > return rRow ; > } From ozonehole2k at yahoo.com Thu Oct 18 07:42:39 2001 From: ozonehole2k at yahoo.com (Ozone Hole near South Pole) Date: 18 Oct 2001 04:42:39 -0700 Subject: install packages to home dir? Message-ID: Hi, I've just picked up Python in the last couple of weeks. At home, I use Linux (Mandrake 8.0). Everything is fine. I've downloaded and tested out quite a few useful packages. However, when I go back to university, problem arises... Being low in the pecking order, our sysadmin does not respond well to our request for package install. As we do not have write access to python2.0/site-packages, I can only copy all the files in the external packages into my own work directory... It is sort of working. But, it is very confusing. I wonder if there is any option that can allow us to intall the extra packages into say ~/lib/python/my-packages or can we do sth like 'import ~/supportpy/usefulstuff' ? Thanks in advance From bmoyle at mvista.com Mon Oct 29 19:53:15 2001 From: bmoyle at mvista.com (Brian Moyle) Date: Mon, 29 Oct 2001 16:53:15 -0800 Subject: Tk and focusing windows References: <0GDB7.5546$P4.665092@news1.cableinet.net> Message-ID: <3BDDF9FB.CB106992@mvista.com> I'm new to Tkinter, but I decided to give this a shot anyway (using your example as the base). It seems to do the trick, but I'm not sure if it's considered good Tkinter coding style. Brian ----- #!/usr/bin/env python from Tkinter import * import sys root=Tk() root.withdraw() window = Toplevel() window.withdraw() window.resizable(0, 0) window.title("Main window") window.protocol("WM_DELETE_WINDOW", sys.exit) widget = Label(window, text="I wait for the dialog, but why?") widget.pack() dialog = Toplevel() dialog.withdraw() dialog.resizable(0, 0) dialog.title("A dialog") widget = Label(dialog, text="Why is this window drawn first?") widget.pack() window.deiconify() dialog.wait_visibility(window) # seems to do something! dialog.deiconify() root.mainloop() ----- Graham Ashton wrote: > > In article , "Graham Ashton" > wrote: > > > I've got an application which opens two Tk windows as soon as it starts > > up; the main window and a progress dialog. > > > > I want the dialog to be displayed after the main window (so the main > > window can't cover it up).... > > Somebody suggested I have a play with wait_visibility(): > > http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm > > I can't get it work though. I've written a small example that > demonstrates my problem (below). It creates two top level windows, one of > which I've called a dialog, another the main window. I don't want the > dialog to be displayed on screen until after the main window has been > drawn. It looks like that is what wait_visibility() is there for, but I > think I'm using it wrong. > > The only way I've managed to change the order in which the windows are > drawn is by swapping the order in which the code creates them - the > last one in the code is the first one on screen. This would be a fairly > hackish solution, and I'd have to mess around with my application's logic > to do it. > > Anyway, here's the example. Thanks... > > -- > Graham > > ---cut--- > #!/usr/bin/env python > # > # How do I get the dialog to be displayed _after_ the window? > > from Tkinter import * > > NoDefaultRoot() > > window = Tk() > window.resizable(0, 0) > window.title("Main window") > widget = Label(window, text="I wait for the dialog, but why?") > widget.pack() > > dialog = Tk() > dialog.resizable(0, 0) > dialog.title("A dialog") > widget = Label(dialog, text="Why is this window drawn first?") > widget.pack() > widget.wait_visibility(window) # does this do anything? > > window.mainloop() # same behaviour if we do dialog.mainloop() From jason-dated-1002753884.cf7c66 at mastaler.com Tue Oct 2 18:44:43 2001 From: jason-dated-1002753884.cf7c66 at mastaler.com (Jason R. Mastaler) Date: Tue, 02 Oct 2001 16:44:43 -0600 Subject: need design suggestions: local namespace problem In-Reply-To: <002701c14b93$00875770$b503a8c0@activestate.ca> ("Brian Quinlan"'s message of "Tue, 2 Oct 2001 15:38:47 -0700") References: <002701c14b93$00875770$b503a8c0@activestate.ca> Message-ID: "Brian Quinlan" writes: > Why are you getting so fancy? Why can't you simply use: > > if running_under_qmail: > ERR_HARD = 100 > else: > ERR_HARD = 75 This would suffice if I were only referencing these variables a few times, but I need to do this many, many times throughout the program. Doing an if/else every time I needed to refer to a variable would be too cumbersome. From donn at u.washington.edu Thu Oct 11 12:55:05 2001 From: donn at u.washington.edu (Donn Cave) Date: 11 Oct 2001 16:55:05 GMT Subject: Loop-and-a-half (Re: Curious assignment behaviour) References: <7xsncs9cmo.fsf@ruckus.brouhaha.com> <3BC4E625.E6C73878@cosc.canterbury.ac.nz> Message-ID: <9q4it9$tio$1@nntp6.u.washington.edu> Quoth Dale Strickland-Clark : ... | The general loop construct as found in C and Java where you have three | expressions: initialisation, increment/iteration, test is a very | flexible and powerful approach which I really like. I sort of regret wasting bandwidth on this purely academic question, but it's a matter of truly venerable tradition that C's loop is a bit shy of perfection. The idea as I understand it, is that there are essentially two control points in a loop, the entry, and the conditional repeat. C conflates those two in one, because both entry and the conditional repeat have to be at the "top". There are plenty of applications for a separate entry, and that's where we came in. The most frequently cited application for an assignment expression is while line = file.readline(): ... A very flexible and powerful approach to looping would allow you to enter the loop in time to set up for the condition, however many statements that might take. C and Python give you one expression, and in C that expression can be an assignment. If you can't do what you need there, then you have to choose between A) repeat the same code before the loop: line = file.readline() while line: ... line = file.readline() or B) take the condition out of the loop control (standard Python solution) while 1: line = file.readline() if not line: break People who claim that C fixes this just expose the limitations of their thinking. C does not fix this, by allowing an assignment there, except in the restricted case where the pre-conditional part of the loop can fit into one expression. (Note that I'm not talking about the initialization section of for(), which is a pure non-feature - those statements can just as well be written before the loop.) Anyone writing a new language should obviously think about that (if the language has any looping constructs at all - there are so many "functional" languages crowding the landscape that I'm not sure anyone invents procedural languages these days.) Donn Cave, donn at u.washington.edu From cjaeger at ensim.com Fri Oct 26 15:31:25 2001 From: cjaeger at ensim.com (Chris Jaeger) Date: Fri, 26 Oct 2001 12:31:25 -0700 Subject: bug in Python's read function (trying again) Message-ID: <3BD9BA0C.3FEF3003@ensim.com> Hi all, Having looked at the python 2.1.1 implementation of file_read (which provides the read function for python file objects), I think I've discovered a bug, unless this behavior is really intended. file_read calls fread multiple times in order to try to fill the request of the caller. Each time fread returns, whatever data is returned is tacked onto whatever was returned before. If some call to fread after the first call returns an error, then an exception is raised and any data already read is lost. This may be fine for regular files that you can seek on, but for other sources of data (such as that belonging to the output from commands), this won't work. This can be reproduced fairly easily by setting O_NONBLOCK on the file descriptor you are reading. So, is this a bug, or is this done by design? If you are monitoring both stdout and stderr, you need to set O_NONBLOCK on the files to prevent deadlock. Perhaps on error file_read should set a bit indicating that it should fail on the next invocation, as opposed to throwing away the data read during the current invocation.. Thanks, Chris From johnroth at ameritech.net Mon Oct 8 11:28:21 2001 From: johnroth at ameritech.net (John Roth) Date: Mon, 8 Oct 2001 08:28:21 -0700 Subject: Curious assignment behaviour References: <0k43stgh288qgmn26dbb4rs8i1n684ov95@4ax.com> <8tb3stc5jcqfc0mh8eijmon4pnfa501loj@4ax.com> <9pseug$jj0@newton.cc.rl.ac.uk> Message-ID: "Richard Brodie" wrote in message news:9pseug$jj0 at newton.cc.rl.ac.uk... > > "Dale Strickland-Clark" wrote in message > news:8tb3stc5jcqfc0mh8eijmon4pnfa501loj at 4ax.com... > > > So how about an alternative assignment operator that can't be confused > > with equality but which yeilds the assigned value? > > > > Pascal uses := > > Nope. Pascal is like Python, it doesn't have an assignment operator. But it does have a *syntax* that means assignment, just like Python. I believe that is what the poster had in mind. There are a few cases where I would like to do an assignment in the middle of an expression; the much abused lambda function comes to mind immediately. I kind of like ":=". John Roth > > From emile at fenx.com Mon Oct 8 06:28:36 2001 From: emile at fenx.com (Emile van Sebille) Date: Mon, 8 Oct 2001 03:28:36 -0700 Subject: += doesn't work in python cgi's References: <3BC17D83.A4EEED81@tpg.com.au> Message-ID: <9prvde$k1i6v$1@ID-11957.news.dfncis.de> Are you running the same versions? Instead of j+=1, try: import sys j = sys.version IIRC, you need to be at version 2 or better to support += HTH, -- Emile van Sebille emile at fenx.com --------- "Michael Palm" wrote in message news:3BC17D83.A4EEED81 at tpg.com.au... > I have a strange error in that += doesn't seem to work in a cgi program > > test.py: > > #!/usr/bin/env python > print "Content-type: text/html\n\n" > j = 1 > j +=1 > print " j is %d" % j > > works fine with > python test.py > > but as a cgi gives > j += 1 > ^ > SyntaxError: invalid syntax > > any ideas?? > From gbreed at cix.compulink.co.uk Fri Oct 26 07:23:50 2001 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Fri, 26 Oct 2001 11:23:50 +0000 (UTC) Subject: Conditional expressions (again) References: <3BD8C52A.53E97472@alcyone.com> Message-ID: <9rbh46$p95$1@thorium.cix.co.uk> Erik Max Francis wrote: > Greg Ewing wrote: > > > Write that as > > > > x = ( > > b if a else > > d if c else > > e > > ) > > > > and it looks a lot clearer. > > Sure, but since conditional expressions are intended for brevity, you've > just made a five line nested conditional express. Why not just use an > if ... elif ... else statement instead? Compare order.append( spam if customer == michae1 else eggs if customer == john else cheese) with if customer == michael: side0rder = spam elif customer == john: sideOrder = eggs else: sideOrder = cheese order.append(sideOrder) in terms of how likely each error is to arise in testing, and how much time it would take to work out what was going wrong. I find that almost convincing ;-) Graham From david.jay.jackson at wcox.com Tue Oct 23 18:03:42 2001 From: david.jay.jackson at wcox.com (Jackson) Date: Tue, 23 Oct 2001 16:03:42 -0600 Subject: FWD: Questions about shelve Message-ID: <200110231603.AA24379680@wcox.com> Objective (Please see script below): Create simple server outage tracking db. While MySQL would be easer to use, it's not as much fun *grin* Data layout: Each record consist of; hostname,date,problem,resolution with hostname and date beging key fields, and problem/resolution being multi-line text field. What's missing: 1. Need to be able to enter more than one outage per server, did I read someplace that you can set Btree to allow dup keys? 2. Change "end_of_field" char to Ctrl+a to allow multi line imput for problem and resolution fields. Thanks for you time. David Jackson ------------- Script ----------------------- #!/usr/bin/python import shelve # people = shelve.open("/tmp/btree.db") host=raw_input("Enter Hostname: ") date=raw_input("Date of Outage: ") problem=raw_input("Problem Descrption: ") resolution=raw_input("Problem Resolution: ") people[host]=[date,problem,resolution] people.close() From brian_zhouNOSPAM at techie.com Thu Oct 4 20:20:58 2001 From: brian_zhouNOSPAM at techie.com (Brian Zhou) Date: Thu, 4 Oct 2001 17:20:58 -0700 Subject: SWIG question Message-ID: <1002241259.529836@cswreg.cos.agilent.com> I want to use SWIG to wrap a C routine that accepting a python string: >>> c_routine("abc") and in the c_routine(), I need to get the string pointer and length, probably using char *ptr, int size; PyArg_Parse(str, "s#", &ptr, &size); I tried: int routine(PyObject *s) { char *ptr, int size; PyArg_Parse(str, "s#", &ptr, &size); // ... } it compiled ok, but when called, >>> from testmodule import * >>> p = routine("abc") Traceback (innermost last): File "", line 1, in ? File "queue_module.py", line 35, in routine val = queue_modulec.routine(arg0) TypeError: Type error in argument 1 of routine. Expected _PyObject_p. >>> How should I write the correct C routine? Thanks for any suggestions. -Brian From maxm at normik.dk Wed Oct 24 09:12:47 2001 From: maxm at normik.dk (Max M) Date: Wed, 24 Oct 2001 15:12:47 +0200 Subject: Request: RFC1867 HTTP File Upload module Message-ID: <3bd6be4f$0$29063$edfadb0f@dspool01.news.tele.dk> I am looking to upload files to the iis via a form, and wonders if anybody has written a module for helping with this. I cannot find any modules on the web. Perhaps it's available as a module in some other package like webware or the like I have browsed the source but to no avail. regards Max M? From s713221 at student.gu.edu.au Sat Oct 13 22:25:45 2001 From: s713221 at student.gu.edu.au (Joal Heagney) Date: Sun, 14 Oct 2001 12:25:45 +1000 Subject: signum() not in math? References: <3BC6B774.4688E9A2@darwin.in-berlin.de> Message-ID: <3BC8F7A9.493B381E@student.gu.edu.au> Marcin 'Qrczak' Kowalczyk wrote: > > Fri, 12 Oct 2001 11:27:16 +0200, Dinu Gherman pisze: > > > How comes there is no sign() or signum() function in math? > > You could use cmp(x,0) if it was guaranteed that it returns only > -1,0,1. Unfortunately it's not said in docs; it happens to work > though. Perhaps docs should be changed... > > -- > __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ > \__/ > ^^ SYGNATURA ZAST?PCZA > QRCZAK Sweet. That gets dropped into my python scrapbook! And for the picky: >>> import math >>> math.sign = lambda x: cmp(x,0) However, it chucks a hissyfit if you try to use complexes, as it should - now if only I could get a better error message >>> math.sign(1+1j) Traceback (most recent call last): File "", line 1, in ? File "", line 1, in TypeError: cannot compare complex numbers using <, <=, >, >= >>> -- Joal Heagney is: _____ _____ /\ _ __ __ _ | | _ ___ | /__\|\ || ||__ |\ || |___|/_\|___] | / \ \_||__ ||___| \_|! | | \ \ ! From chrishbarker at home.net Fri Oct 26 13:37:52 2001 From: chrishbarker at home.net (Chris Barker) Date: Fri, 26 Oct 2001 10:37:52 -0700 Subject: Confusion with string.replace() References: Message-ID: <3BD99F70.7424967E@home.net> Joseph Wilhelm wrote: > >>> import string > >>> a = "a'b" > >>> b = string.replace( a, "'", "\'" ) > >>> b > "a'b" > >>> b = string.replace( a, "'", "\\'" ) > >>> b > "a\\'b" > I just can't seem to wrap my brain around why it's doing that. Can somebody > explain that, or perhaps provide an easier option for preparing a SQL > statement? This has nothing top do with replace(), and eveything to do with Python's default interpretation of sting constants. \ is an escape for python also, so your first version:"\'" just creates a "'". The second version "\\'" is correct, as the \\ is the correct code for a \. You are getting confused by the command line representation. There are two methods for turning a Python object into a string for presentation: repr() Which creates a string representation of an object that can be used to re-construct the object. the goal is that eval(repr(x)) == x str() creates a string representation that is designed for humans to read. At the command line, if you just type the name of a variable, what you get is repr(var). Ifyou use a print statement, you get the pretty version. Some examples: >>> s = "\'" >>> print s ' >>> s "'" # so you have only the ' character. >>> s = "\\'" >>> s "\\'" >>> # now it looks like you have two slashes, but you don't really: ... >>> len(s) 2 >>> print s \' >>> Another option is to use "raw" strings. You get these be putting an r in front of the string. When you do this, you are telling Python to ignore special escape sequences, and jsut taek what you types literally. this is very handy for things like what you are doing, creating a string that with escapes to be interpreted by something else. It is used a lot with regexes. >>> s = r"/'" >>> s "/'" >>> print s /' >>> So your code could be: a = "a'b" b = string.replace( a, "'", r"\'" ) By the way, in newer version of Python, you can use string methods rather than the string module: b = a.replace("'",r"\'") Hope that helps -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From sdm7g at Virginia.EDU Thu Oct 18 11:59:48 2001 From: sdm7g at Virginia.EDU (Steven D. Majewski) Date: Thu, 18 Oct 2001 11:59:48 -0400 (EDT) Subject: Help : IndexError - probably pretty simple In-Reply-To: Message-ID: On 18 Oct 2001, JT wrote: > def CRRBi(ae="a", cp="c", stock=100, strike=100, time=(1.00/12), > interest=0.6, cc=0.10, vol=1.00, n=10): > """CRRBi: the Cox-Ross-Rubinstein Binomial Option Pricing Model""" > ov = [] 'ov' initialized to the empty list: len(ov) -> 0 ... > for i in range(n): > ov[i] = max(0, z * (stock * pow(u, i) * pow(d, n-1) - strike)) default value for n=10: iterate over ov[0] ... ov[9], except len = 0, so > IndexError: list assignment index out of range I'm not quite sure exactly what you OUGHT to be doing for this algorithm, but you might try either initializing ov = [0]*n, (i.e. with n zero's ) or else add values to the list with ov.append. -- Steve Majewski From phr-n2001d at nightsong.com Fri Oct 12 12:02:46 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 12 Oct 2001 09:02:46 -0700 Subject: webserver performance (was Re: Why so few Python jobs? (and licenses)) References: <7xwv2418xk.fsf@ruckus.brouhaha.com> <9q6a1u$ke9$1@serv1.iunet.it> Message-ID: <7xr8s8q21l.fsf@ruckus.brouhaha.com> "Alex Martelli" writes: > > These programs are all way too slow for a high-traffic site on the > > hardware we used back then. Even with today's hardware, it would be > > Have you actually _measured_ the performance and scalability of a web > server architecture based on asyncore/asynchat, versus more traditional > architectures based on multiple processes and/or multiple threads? I > haven't done it systematically at all, but the few informal attempts > I did do have consistently amazed me. Event-driven programming seems > to have extremely interesting characteristics in this sense. Take a look at the benchmarks for thttpd and other servers, at www.acme.com, if you're interested in that question. I haven't personally done measurements but Jef's look right to me. We played with the Java web server and it was dog slow. From logiplexsoftware at earthlink.net Wed Oct 3 13:07:21 2001 From: logiplexsoftware at earthlink.net (Cliff Wells) Date: Wed, 3 Oct 2001 10:07:21 -0700 Subject: Python is better than free (was Re: GNU wars again) In-Reply-To: <200110030239.f932ddT02254@smtp.skyenet.net> References: <1002040943.560.290.l9@yahoogroups.com> <20011002235831.E25358@phd.pp.ru> <200110030239.f932ddT02254@smtp.skyenet.net> Message-ID: <01100310072101.03969@logiplex1.logiplex.net> On Tuesday 02 October 2001 18:49, Chris Watson wrote: > > > > This is exactly how the GPL works - it charges for my code. You can > > pay me money, or you can pay me by opening your code. > > Thats called extorsion. > No, extortion is when I demand your code at gunpoint or by threatening to reveal that you subscribe to the Visual Basic mailing list as well. -- Cliff Wells Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From warkid at storm.ru Mon Oct 29 15:05:31 2001 From: warkid at storm.ru ( Kerim Borchaev ( WarKiD ) ) Date: Mon, 29 Oct 2001 23:05:31 +0300 Subject: Python still remembers script after change and save In-Reply-To: <01102911123601.03754@logiplex1.logiplex.net> References: <01102911123601.03754@logiplex1.logiplex.net> Message-ID: <7962.011029@storm.ru> CW> You must call reload(module) to force Python to reinterpret the module Or just press Ctrl-I on your module. Best regards, Kerim mailto:warkid at storm.ru From jdries at mail.com Mon Oct 15 17:00:39 2001 From: jdries at mail.com (Jan Dries) Date: Mon, 15 Oct 2001 22:00:39 +0100 Subject: mod_python seems to be missing a file References: Message-ID: <3BCB4E77.6090308@mail.com> MM wrote: > I've followed the mod_python documentation to the letter. It seems to be on > the verge of working with the one following problem: > > from mod_python import apache > > this is the first line of the test program you're told to write to see if > you're up and running. The problem with this is that the apache.py file in > the mod_python package is trying to import a file called _apache. I cannot > find this file anywhere and, apparently, neither can Python, since it > complains about it, as well. Any help on where this file can be found would > be appreciated. > If you check the C source, you will find that the mod_python DLL itself export a function init_apache(). In other words, mod_python.dll is your missing _apache.pyd. When mod_python.dll is loaded, the function is registered to the Python runtime, and from that moment on the module _apache is known to the Python interpreter. If you could tell what exactly the errors are that you get in trying to make mod_python work, maybe I could tell what's going wrong. But it certainly isn't the fact that some _apache.py(d) would be missing. Regards, Jan From walter at livinglogic.de Thu Oct 11 08:16:58 2001 From: walter at livinglogic.de (Walter =?ISO-8859-1?Q?D=F6rwald?=) Date: Thu, 11 Oct 2001 14:16:58 +0200 Subject: image from URL References: <3BC57869.E95139D7@ncsa.uiuc.edu> <20011011145841.I500@phd.pp.ru> <1011011060148.ZM2689@kelgia.ncsa.uiuc.edu> <20011011150536.J500@phd.pp.ru> Message-ID: <3BC58DBA.4040908@livinglogic.de> Oleg Broytmann wrote: > On Thu, Oct 11, 2001 at 06:01:48AM -0500, Randy Heiland wrote: > >> fp = __builtin__.open(fp, "rb") >>TypeError: open() argument 1 must be (encoded string without NULL bytes), not >>str >> > > Please continue to answer to newsgroup. > > So you have a minor problem - Image expects filename. So, save fp.read() > to a file, and pass its filename to Image. or use urllib.urlretrieve instead of urllib.urlopen Bye, Walter D?rwald From rafial at well.com Mon Oct 8 21:10:47 2001 From: rafial at well.com (Wilhelm Fitzpatrick) Date: Tue, 09 Oct 2001 01:10:47 -0000 Subject: why are *two* ctrl-D's needed with readlines() Message-ID: <9ptiqn+79ev@eGroups.com> --- In python-list at y..., Donn Cave wrote: > Quoth "Wilhelm Fitzpatrick" : > | So would it be reasonable to report this as a bug? Certainly, I > | found the behavior surprising and non-standard... ... > So phrasing it as a question - do you see this phenomenon > when input is already at beginning of line? If you do, > then it's a bug. As clarified in an earlier post, I *do* see the behavior when ctrl-D is issued at the beginning of the line. So I guess it's time for me to go figure out how to submit a bug ;) > In the present case, I would guess that you have the GNU readline > module built in, and the bug is some interaction between that > library, on your version of Linux/glibc, and readlines(). Actually, I first noticed the problem with python 2.0.1 as distributed in Debian 2.2, which *does not* have readline built in. I later confirmed it with 1.5.2 which *did* have readline built in. So I believe the issue is unconnected with readline. From dale at riverhall.NOTHANKS.co.uk Wed Oct 17 04:36:41 2001 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 17 Oct 2001 09:36:41 +0100 Subject: Conditional Expressions don't solve the problem References: <9qhqi1$vba$1@slb3.atl.mindspring.net> Message-ID: Guido van Rossum wrote: >It comes from the analogy between > > while : > > else: > > >and > > if : > > else: > > >In both cases, when is false, a jump to the else: label is >taken. > >From this it also follows that the else part of a loop is skipped when >a break is taken -- hence finally would be wrong. OK. Fair enough. > >> Is iter just an extra object layer to map the interface. Will it be an >> overhead? > >What do you mean? Well, I could knock up an iter of my own: class iter: def __init__(self, function, endCase): self.endCase = endCase self.function = function def __getitem__(self, v): r = self.function() if r == self.endCase: raise IndexError return r But this would add an extra layer of Python between a function and where it is used. On our larger systems, I would prefer not to introduce such overheads where it is only a small coding convenience. Is iter handled more effeciently than this? -- Dale Strickland-Clark Riverhall Systems Ltd From sholden at holdenweb.com Fri Oct 26 12:49:36 2001 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 26 Oct 2001 12:49:36 -0400 Subject: Confusion with string.replace() References: Message-ID: "Joseph Wilhelm" wrote in ... > I'm getting some really strange behaviour from string.replace(), and I was > wondering if somebody could help explain this to me. All I'm trying to do is > escape single quotes in a string for a SQL query, but here's an example of > what I'm getting: > > >>> import string > >>> a = "a'b" > >>> b = string.replace( a, "'", "\'" ) > >>> b > "a'b" > >>> b = string.replace( a, "'", "\\'" ) > >>> b > "a\\'b" > >>> > > I just can't seem to wrap my brain around why it's doing that. Can somebody > explain that, or perhaps provide an easier option for preparing a SQL > statement? > The major difficulty you are experiencing is understanding the interactive iterpreter's behavior. However, we also need to talk about SQL, which we'll do next. Here's a session that might help you to understand a little better: >>> s1 = "\\" >>> print s1 \ >>> s1 '\\' >>> print len(s1) 1 >>> print "repr():", repr(s1), "str:", str(s1) repr(): '\\' str: \ >>> When you enter an expression into the interpreter it evaluates it and then prints out the value (unless it is None) using the __repr__() method. repr() usually attempts to produce something that would yield the correct value is given as an argument to eval(), so it puts quotes around strings and uses backslash quoting on any special characters, like backslashes! So, replace() is doing exactly what you want it to: in the first example, the backslash quotes the single-quote, and so you simply replace single quotes with single-quotes. In the second example the backslash escapes another backslash, so you replace single quotes with a backslash and a single quote. When you ask the interpreter to evaluate the resulting string, however, it uses the repr() of the string, so you see surrounding double quotes and doubled backslashes. If you take the length of the string you will find there is actually only one backslash in it. Why should you not do this to build SQL statements? Well, first of all, some databases require you to escape single quotes in string values by putting two single quotes in a row. So, in some SQLs, rather than 'a\'b' you should use 'a''b' to represent the three character string containing a single quote between a letter "a" and an letter "b". Secondly the DB API allows you to use paramterized SQL, and have the database module put the values in to the SQL statement dynamically, with no need to do anything except pass them through as Python expressions. So, you might write: name = "Steve O'Reilly" address = "12, Dingle's Hill Road" age = 35 sql = "INSERT INTO ctbl (custname, custaddr, custage) VALUES (?, ?, ?)" cursor.execute(sql, (name, address, age)) The execute() call substitutes the tuple elements for the parameter markers (in this case, question marks, but there are five possible parameterization styles) in the SQL statement. This way of doing things has two advantages: 1. You don't have to pratt about replacing single quotes in string values. In fact you don't have to bother much with any kind of conversion, since the DB modules do their best to coerce the values you provide into the appropriate types to be stored in the database. 2. The DB module will prepare the SQL statement, and if you use the same statement repreatedly it will not need to repeat the preaparation, gaining a good deal of performance in the process. Hope this helps. regards Steve -- http://www.holdenweb.com/ From mmealman at tarsis.org Tue Oct 9 10:30:59 2001 From: mmealman at tarsis.org (Mark) Date: 9 Oct 2001 09:30:59 -0500 Subject: Why so few Python jobs? (and licenses) References: <9psq5u$agh$1@panix3.panix.com> <7x1ykd7es3.fsf@ruckus.brouhaha.com> <3BC228BA.9030306@sneakemail.com> <7xwv25zftv.fsf@ruckus.brouhaha.com> <7xd73x1cgf.fsf@ruckus.brouhaha.com> Message-ID: In article <7xd73x1cgf.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Gerhard H?ring writes: > of people's hands in them (that's the whole point of the GPL). If I > write a GPL'd module and users start sending me fixes and > improvements, I have to think of them as contributors who worked on > the program with the understanding that it was free. If someone else > then wants to pay me for the right to use the improved module in a > closed product, I have to get the permission of everyone else who > contributed, which may mean they all have to also get paid. No. If I wrote a module and placed it under the GPL, I still own the copyright on that module. That gives me the right to release that code under any other license as I see fit, even though I can never take away anyone's right to use it under the GPL. IMHO submitting patches to a program does not give you any copyright hold over that program, although I don't think it's been legally tested yet. The spirit of the GPL is not about placing restrictions on the origional copyright holder of a program, it's a means for him or her to place his software into the public domain and insure that no one "steals" it without giving back. -Mark -Mark -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From dale at riverhall.NOSPAMco.uk Tue Oct 2 17:29:06 2001 From: dale at riverhall.NOSPAMco.uk (Dale Strickland-Clark) Date: Tue, 02 Oct 2001 22:29:06 +0100 Subject: Strategies for controling attribute assignment References: <9lajrtcqsojv72nr88c7j6kmdapjo44vc0@4ax.com> <0tiu7.19253$ib.294456@atlpnn01.usenetserver.com> Message-ID: David Bolen wrote: > >The same suggestion can also help with this problem. Call the >instance of the contained database class "public", and then all users >of your class will be accessing database query/assignments with >references such as "object.public.value" > >I suppose if you really wanted to (e.g., users of your object just had >to be able to reference object.value), you could invert this. Leave >all instance variables as just for the database, and place all of your >prior private instance variables into a contained object - let's call >it "private". You'd end up using "self.private.xxxx" instead of just >"self.xxx" inside your object. > >-- >-- David It would address the problem, you're right, but it lacks the clean external appearance of the traditional approach. If I have to resort to these type of tricks, I think I'd rather use a 'set' method for all public assignment instead. Actually, I've found that if I don't define __setattr__ until the end of __init__ , most the the inefficiencies I've been suffering are avoided. This also helps avoid some of the initialisation problems when using __setattr__. class wibble: def __init__(self): ... stuff... __setattr__ = set def set(self, attr, value): ... stuff... -- Dale Strickland-Clark Riverhall Systems Ltd From jim.correia at pobox.com Thu Oct 18 23:42:57 2001 From: jim.correia at pobox.com (Jim Correia) Date: Fri, 19 Oct 2001 03:42:57 GMT Subject: Dictionary from list? Message-ID: Suppose I have a list with an even number of elements in the form [key1, value1, key2, value2, key3, value3] If I were writing Perl I could write my %hash = @array; and it would do the coercion for me, and build the hash appropriately. I'm a python newbie. I know how to do it "by hand" with a loop, but is there a built in conversion operater that will let me do something simply like the perl assignment? Jim From nospam at bigfoot.com Mon Oct 15 08:23:39 2001 From: nospam at bigfoot.com (Gillou) Date: Mon, 15 Oct 2001 14:23:39 +0200 Subject: importing Access 8.0 library References: Message-ID: <9qek51$215a$1@norfair.nerim.net> Try makepy "Access.Application" Or do it through PythonWin IDE --Gillou "Piotr Lipski" a ?crit dans le message news: e2cbf98c.0110142339.4621de4 at posting.google.com... > Hi, > can someone explain to me why the following error occured? > I'm using Python 2.1.1 (from Activestate). > Thanks, > Piotr Lipski > > D:\Python21\win32com\client>makepy "Microsoft Access 8.0 Object Library" > Generating to D:\Python21\win32com\gen_py\4AFFC9A0-5F99-101B-AF4E-00AA003F0F07x0 > x8x0.py > Traceback (most recent call last): > File "D:\Python21\win32com\client\makepy.py", line 357, in ? > rc = main() > File "D:\Python21\win32com\client\makepy.py", line 350, in main > GenerateFromTypeLibSpec(arg, f, verboseLevel = verboseLevel, bForDemand = bF > orDemand, bBuildHidden = hiddenSpec) > File "D:\Python21\win32com\client\makepy.py", line 261, in GenerateFromTypeLib > Spec > gencache.AddModuleToCache(info.clsid, info.lcid, info.major, info.minor) > File "D:\Python21\win32com\client\gencache.py", line 444, in AddModuleToCache > mod = _GetModule(fname) > File "D:\Python21\win32com\client\gencache.py", line 468, in _GetModule > mod = __import__("win32com.gen_py.%s" % fname) > File "D:\Python21\win32com\gen_py\4AFFC9A0-5F99-101B-AF4E-00AA003F0F07x0x8x0.p > y", line 6396, in ? > class __CodeModule_(CoClassBaseClass): # A CoClass > File "D:\Python21\win32com\gen_py\4AFFC9A0-5F99-101B-AF4E-00AA003F0F07x0x8x0.p > y", line 6400, in __CodeModule_ > coclass_interfaces = [ > NameError: name '_CodeModule___IVbaModule_' is not defined From stevenc at engineer.com Tue Oct 23 16:12:33 2001 From: stevenc at engineer.com (Steven Cummings) Date: Tue, 23 Oct 2001 15:12:33 -0500 Subject: Printing unicode to file Message-ID: <3BD5CF31.30803@engineer.com> I know this has been covered a little before on this newsgroup, but I think my problem is a little different than was solved before. I'm retrieving text from Word (which is apparently unicode through COM) and I'm writing out the information to html files. I can't do an encode('utf-16') or nothing shows up right (I get a big chunk of chinese characters). If I encode('utf-8') on the way out to file, it may work, but it's hard to tell because for some reason it takes up to three minutes just to do the encode (?!?). And I'm not so sure if all of the characters will get translated correctly. What is the best way to go about this, altering text from MSWord through COM and generally writing it out to some text format? /S From mlh at idi.ntnu.no Sat Oct 6 11:52:35 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 6 Oct 2001 17:52:35 +0200 Subject: A bug in pindent.py? Message-ID: <9pn9c3$on8$1@tyfon.itea.ntnu.no> I've been taking a look at changing xml files into Python programs with xslt (for applications like psp etc.) What I do, is change something like bar into something like: print ''' bar ''' print "2*2 is", 2*2 print ''' ''' Obviously, the indentation isn't correct here. My hope was that I could use pindent.py (from the standard Tools/scripts directory) to fix this, using # end foo tags where necessary. However, it seems that pindent also destroys triple-quoted strings, so the result is: print ''' bar ''' print "2*2 is, 2*2 print ''' ''' Admittedly, this works, and the xml is still well-formed, but I'm sure there are cases (like in xhtml
 tags
containing Python examples) where this would foul up the
result beyond the pure aesthetics of xml indentation.

I just wanted to hear if anybody knows of an alternative
solution, or if anybody was willing to fix this. Otherwise
I might try to write a patch myself, or, failing that,
write a separate tool... (This may, of course, be solvable
completely in xslt, though I'm not sure how.)

--

  Magnus Lie Hetland         http://www.hetland.org

 "Reality is that which, when you stop believing in
  it, doesn't go away."           -- Philip K. Dick





From cjensen at bioeng.ucsd.edu  Wed Oct  3 12:24:29 2001
From: cjensen at bioeng.ucsd.edu (Curtis Jensen)
Date: Wed, 03 Oct 2001 09:24:29 -0700
Subject: Tkinter image mapping
Message-ID: <3BBB3BBD.602470C2@bioeng.ucsd.edu>

Is there a convient way to do image mapping in Tkinter?  
ie:  We display an image in a Tkinter frame, and we would like to set a
binding to a mouse click in a certain area of the image.

-- 
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451


From emile at fenx.com  Tue Oct 16 17:12:13 2001
From: emile at fenx.com (Emile van Sebille)
Date: Tue, 16 Oct 2001 14:12:13 -0700
Subject: breaking a string
References: <9qi6uu$h4c$1@nserve1.acs.ucalgary.ca>
Message-ID: <9qi85i$o2t3m$1@ID-11957.news.dfncis.de>

Depending on the version of python, use
string.split("Hello World!"[:-1])
or
"Hello World!"[:-1].split()

--

Emile van Sebille
emile at fenx.com

---------
"Michael Yuen"  wrote in message
news:9qi6uu$h4c$1 at nserve1.acs.ucalgary.ca...
> I'm pretty new to this Python stuff and i'm trying to figure out how to
> break a string into it's component parts.
>
> For example, if a line of text in a file is:
> "Hello World!"
>
> I want to enter that into my list as just ['Hello', 'World']
> Can someone help me out?
>
> Thanks,
> M
>
> --



From jnlc at bellsouth.net  Wed Oct 31 11:13:44 2001
From: jnlc at bellsouth.net ( 1)
Date: Wed, 31 Oct 2001 11:13:44 -0500
Subject: newbie question
Message-ID: 

I must have missed it in the tutorial or some thing.

I want to know how to open and run a file in python. The tutorial said to
just type " python filename.py" and hit enter. I did this and it comes back
with an error message telling me the the file name is not defined. I wasn't
told that I had to define it first before I can run it. Is there an easier
way to run files otherthan defining them?

thanks
lancer






From MarkH at ActiveState.com  Mon Oct 29 17:16:27 2001
From: MarkH at ActiveState.com (Mark Hammond)
Date: Mon, 29 Oct 2001 22:16:27 GMT
Subject: Windows/COM events/strange behavior
References:  
Message-ID: <3BDDD56E.4040003@ActiveState.com>

Krzysztof Czarnowski wrote:

> Sat, 27 Oct 2001 05:42:26 GMT
> Mark Hammond wrote:
> 
> 
>>As I said, this main thread probably needs to be calling
>>PumpWaitingMessages() each time around the loop.
>>
> Well... This definitely doesn't look very elegant to me!


I don't recall saying it did to me :)  One extra function call in your 
main loop is hardly an imposition though.

> Anyway, if I got it well:
> 
> 1. I should introduce CoInitialize()/CoUninitialize() pair in the main
> thread *and* call PumpWaitingMessages() in its loop? Right? I assume that no
> COM event will be delivered here, or will it?


The main thread does not need a CoInitialize call.  pythoncom 
automatically calls the apartment threaded model version.

> 2. No need to do this in other child threads (like the CORBA thread). Right?


It must be done on every thread that calls any COM function or uses any 
COM objects.


> 3. Will the problem go away if:
> 
>  * the COM event handler is installed in a "free threaded appartment"? (can
> I do this in a threading. thread?)
> 
> or
> 
>  * native Windows threads from ? (now module threading is used)


It depends on the app.  I haven't followed your code/this thread closely 
enough to remember what thread the COM event originates from.


> And generally, what would be *your* favorite solution? (my task is basically
> to receive events from a COM driven subsystem and pass them to a CORBA
> subsystem)


Again, it depends on the app.  However, my favourite solution is 
generally the one that works :)

"Python Programming on Win32" has a reasonably complete discussion on 
threads in COM from Python's POV.

Mark.



From sebrosa at artenumerica.com  Mon Oct 22 05:34:40 2001
From: sebrosa at artenumerica.com (Jose' Sebrosa)
Date: Mon, 22 Oct 2001 10:34:40 +0100
Subject: suggestion for module re
Message-ID: <3BD3E830.3EC94E94@artenumerica.com>

Hi

My first goal is to get all the *named* fields of a regex, for all of the
matches in a source string.  The re.RegexObject.findall method is "almost"
good, but it returns a tuple of matched *groups*, leading to a dumb
pharentesis-counting task and to code hard to maintain.  Just imagine that you
have a regex with several groups and wish to insert a new group in the middle. 
This changes the group counting, and that's no good.

In the beginning I was thinking about making a variant of the findall method
returning a dictionary of named groups instead of a tuple of groups.  But we
have already the re.MatchObject.groupdict method, (along with a bunch of other
useful match objects' methods), so I found it better to make a list of all the
match objects found in a source string.

Here is the method I would like to add to re.RegexObject (sure it could be
better named...)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def find_all_match_obj(self, source, method = 'match'):
        """Return a list of all non-overlapping match objects in the string.
        """
        pos = 0
        end = len(source)
        results = []
        if method == 'match':
            worker = self.match
        elif method == 'search':
            worker = self.search
        else:
            if type(method) != type(''):
                raise TypeError, ('Invalid type for method: %s'
                                  % `type(method)`)
            raise ValueError, 'Invalid value for method: %s' % `method`
        append = results.append
        while pos <= end:
            m = worker(source, pos, end)
            if m == None:
                break
            append(m)
            pos = max(m.end(), pos+1)
        return results
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Such a method would let users to use the full functionality of match objects in
very simple python constructs.  For example, my first problem (to get all the
named groups of all matches) get solved like this (silly example follows):

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rx = re.compile(r'((?Pa|A)(?Pb|B))')
match_list = rx.find_all_match_obj('abaBAbAB')
named_group_list = map(lambda m: m.groupdict(),  match_list)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Notes:

 - I'm using Python 1.5.2 (under Linux), but I inspected the docs for Python
2.1 and it seems to me that it too lacks a method like this.

 - I don't know which is better to use, "match" or "search", as the matching
function, so I used both...  But it still remains the question of which default
should we define.  Or if we should define *two* different methods, one with
match and other with search.  What's the usual policy?

 - I like to use the clean syntax obj.name instead of the hairy obj['name']
whenever possible.  Sure it is easy to go from one to another, but it is a pity
to have a groupdict method and not an equivalent groupobject method to return
an object usable with the cleanest syntax.  With it, we could look at a regex
with named groups as a way to define a set of standard names in Python (and to
give them values).  Furthermore, the requirements for named groups in regexs
are that the names must be valid Python names, so it is *really* a pity...! 
Anyway, that's just an aesthetic modification.


Thanks,
Sebrosa


From info at devshare.de  Thu Oct 25 05:21:38 2001
From: info at devshare.de (Johannes Gamperl)
Date: Thu, 25 Oct 2001 11:21:38 +0200
Subject: Learing Python, Newbie question
Message-ID: 

Hello,

i just starting to learn python ... so i've two questions:

1. is there a easy way to test, if a file exists?
2. do you have an example to do a template work for cgi?

   e.g.

   you have this template

   
   ...
   
   %name%  

   ... 
   

   so what i want is, to open this file and replace %name%
   with a variable inside the py-script ...


thx for any help .. :-)
Hannes


From kalle at gnupung.net  Sat Oct 20 05:15:41 2001
From: kalle at gnupung.net (Kalle Svensson)
Date: Sat, 20 Oct 2001 11:15:41 +0200
Subject: struct module
In-Reply-To: <3bd10af8$0$27331$afc38c87@news.optusnet.com.au>
References: <3bd0f13e$0$27332$afc38c87@news.optusnet.com.au>  <3bd10af8$0$27331$afc38c87@news.optusnet.com.au>
Message-ID: <20011020111540.A27786@sandra.lysator.liu.se>

[nobody]
> > H has a two-byte alignment requirement.  There's one byte for the "B",
> then
> > it has to throw in a pad byte to get the correct word alignment for the
> > "H".
> 
> How do I disable that?

You don't.

Peace,
  Kalle
-- 
[ Thought control, brought to you by the WIPO! ]
[ http://anti-dmca.org/ http://eurorights.org/ ]



From db3l at fitlinxx.com  Thu Oct 18 19:49:44 2001
From: db3l at fitlinxx.com (David Bolen)
Date: 18 Oct 2001 19:49:44 -0400
Subject: Is there a small Python runtime environment installer?
References: <3583b331.0110181524.5695bd67@posting.google.com>
Message-ID: 

tex_r at hotmail.com (Tex Riddell) writes:

> More specifically I'm looking for something for the windows
> environment, but one should be able to make something like this
> multi-platform, right?

Well, you'd have a harder time having a portable distribution if you
were looking for a binary, sort of by definition.

But since you're specifically targetted at Windows, why not just use
the standard Windows installer?  It lets you ignore the examples and
documentation and just install the core stuff if you like.  Any
Windows user should be completely at home with the installation
process.

> How can we expect python to become more mainstream if only developers
> can understand the environment that must be set up for scripts to run?

At least under Windows, I don't think installing Python is any harder
than installing any other application.  That's largely true as well on
various Unix platforms, since there are rpms and other install
packages written for Python to conform to local platform expectations.

> I really don't have time to learn distutils (re-inventing the wheel
> that I'm sure so many have done) in order to install a runtime
> environment on someone's machine so they can run a simple 8k script.

Of course, those same people (under Windows) have already installed
MBs of common code just so they can run small VB applications, whether
via their initial Windows installation or updated silently in other
stuff they may have installed. :-)


BTW, there is also the option of constructing a standalone
installation (for Windows, look into the py2exe or installer packages,
and installer also handles Linux) for your script.  For Windows, it
would include the Python DLL and appropriate lib files all packages
into a single file or collection of files that you could then
distribute independently of any other.  On the Windows platform if you
combine that with an installer - like the free Inno Setup - you'd end
up handing your script to your friend as a normal Windows installation
program that took care of installing everything.

Of course, this would be much larger than an 8K script and would thus
be hellishly less efficient if you were sending a lot of scripts this
way (as opposed to just having him install the runtime one time), but
for a one-shot deal it would make the receiver's life simple.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/


From sdm7g at Virginia.EDU  Sat Oct 20 11:17:47 2001
From: sdm7g at Virginia.EDU (Steven D. Majewski)
Date: Sat, 20 Oct 2001 11:17:47 -0400 (EDT)
Subject: silly idea - interesting problem
In-Reply-To: <20011020122801.A3963@cruciatuz.de>
Message-ID: 


On Sat, 20 Oct 2001, Stefan Antoni wrote:

> 
> i got a silly idea about a small script which takes to strings (lets say
> "test" and "dust") and mixes them to "tdeusstt".
> i tried to code it because i thought it would be easy, but now i cannot
> find out _how_ to do it ;)
> 
> i tried to "list()" the string and mix the items. but ...
> 
> Anybody has a hint or even a solution?

>>> import operator
>>> reduce( operator.__add__, map( operator.__add__, 'test', 'dust' ), '' )
'tdeusstt'

-- Steve





From dubal at khimjiramdas.com  Wed Oct 31 02:17:01 2001
From: dubal at khimjiramdas.com (J Dubal)
Date: 30 Oct 2001 23:17:01 -0800
Subject: Help: python-postgres-informix interaction problems
Message-ID: 

Hello good people!

We have developed Informix RDBMS based commercial applications in
Informix-4gl. It is a good procedural language with embeded SQL. We
are trying to rewrite some apps in Python with postgresql backend for
licensing reasons. Python is good too. We are trying to do this with
latest versions of RH linux (7.2), python 2.1 and postgres 7.1.3. We
face following issues:

1. We have to read data from informix db, process it and insert into
postgres. We are using informixdb module (DBAPI 1) which is bit dated.
In Informix we 'select custno, custname, custaddr1, ... into progvar1,
progvar2, ... from custmf where ...' In python, we say fetchone() and
we get a list. We are then moving the elements of the list to named
program variables thus:
        pcustno = list1[0]
        pcustname = list1[1]
        pcustaddr1 = list1[2]
        ... as many as reqd
This way we give meaningful names to data items read from db and
process further.
Is there a better, more elegant/efficient way to to this?

2. To insert this data into postgres, we used to use pygres included
in the postgres distribution (latest). We had to stop using this
because we couldn't find a way to find out how many rows it have
inserted, updated or deleted after such statements are executed ie we
couldn't find a way to check the status or return code. So we switched
over to PoPy which is DBAPI2 and where we could check number of rows
affected. Is this right thing to do?

3. In order to insert data into postgres, we have to compose an insert
statement thus:
        cur.execute("insert into custmf (custno, custname,
custaddr1,...)
            values (%i,'%s','%s'...)" %(pcustno,pcustname,
pcustaddr1....))
Is there a better way of doing this?

4. The above string substitute converts program variables holding null
value into 'None' which goes into target table as string 'None'. To
avoid this we parse all columns to check if they are 'None' and
replace them by ''. Is there a better way to do this?

5. The above check works only on string variables. We have not found
yet a way to handle nulls in numeric columns. Please suggest a
solution.

6. If the character columns happen to contain quotes, the above
composed insert statement breaks. Please suggest a solution.

Any help is greatly appreciated.
Thanks in advance.
Dubal


From lucio at movilogic.com  Tue Oct 23 11:47:16 2001
From: lucio at movilogic.com (Lucio Torre)
Date: Tue, 23 Oct 2001 12:47:16 -0300
Subject: POLL in different OSes
In-Reply-To: <3bd50785@news.actrix.gen.nz>
References: 
Message-ID: <5.1.0.14.0.20011023124514.088ce2e0@imap.hq.movilogic.com>

At 05:54 PM 23/10/2001 +1300, Mark Rowe wrote:
>Hello,
>
> >From the interpreter under Windows:
>
>Python 2.2b1 (#25, Oct 19 2001, 11:44:52) [MSC 32 bit (Intel)] on win32
>Type "help", "copyright", "credits" or "license" for more information.
> >>> import select
> >>> select.poll
>Traceback (most recent call last):
>   File "", line 1, in ?
>AttributeError: 'module' object has no attribute 'poll'
> >>> dir(select)
>['__doc__', '__file__', '__name__', 'error', 'select']
> >>>
>
>I guess its not :)
>
>Mark Rowe

Yes, i did the same in my linux box and got:

Python 2.0.1 (#0, Jun 23 2001, 23:50:30)
[GCC 2.95.4 20010319 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
 >>> import select
 >>> dir(select)
['POLLERR', 'POLLHUP', 'POLLIN', 'POLLMSG', 'POLLNVAL', 'POLLOUT', 
'POLLPRI', 'POLLRDBAND', 'POLLRDNORM', 'POLLWRBAND', 'POLLWRNORM', 
'__doc__', '__file__', '__name__', 'error', 'poll', 'select']
 >>>

so, another question: is bsd sockets the only networking interface Windows 
has? doesnt it have a win32socketlib ( :) ) or something like that?

and deeper again, (for pygame people), does the networking code from 
directx use bsd sockets? or what?

danke.





From matt at mondoinfo.com  Mon Oct 29 19:05:34 2001
From: matt at mondoinfo.com (Matthew Dixon Cowles)
Date: Tue, 30 Oct 2001 00:05:34 GMT
Subject: tkinter - tkFileDialog - how to get dir instead of file
References: 
Message-ID: 

On Mon, 29 Oct 2001 23:14:44 +0100, maxm  wrote:

Max,

>I am writing my first tkinter program and so far it's been pretty painless.

That's great, you're ahead of the game.

>But now I need to open a directory and not a file. I cannot see a
>simple way to get this from the standard module "tkFileDialog".

>Do I really have to write a special class for this?

Alas, you probably do. Tk provides a directory chooser but Python
doesn't (yet) expose it. I filed a feature request on SourceForge for
it but it doesn't look like anything has been done about it yet,
including by me.

Regards,
Matt


From nobody at tek.kom  Tue Oct 16 18:36:38 2001
From: nobody at tek.kom (Kevin)
Date: Tue, 16 Oct 2001 22:36:38 GMT
Subject: Python app. Eroaster and "output = pipe[0].readlines()" trouble
References: 
Message-ID: 

I checked "cdrecord -scanbus" and it writes everything to
stdout.  So, I took out the "2>&1".  I got exactly the same
results, namely:

    Traceback (most recent call last):
      File "/usr/lib/python2.0/site-packages/gtk.py", line 125, in __call__
	ret = apply(self.func, a)
      File "/usr/lib/eroaster/main.py", line 1468, in DetectRecorder
	self.DetectSCSIDevice(deviceRecorder)
      File "/usr/lib/eroaster/main.py", line 1479, in DetectSCSIDevice
	output = pipe[0].readlines()
    IOError: [Errno 4] Interrupted system call

The line I think caused this is the "output = pipe[0].readlines()"
line in the following:

    # Detect SCSI-devices
    def DetectSCSIDevice(self, device):
	pipe = popen2.popen2("cdrecord -scanbus 2>&1")
	output = pipe[0].readlines()
	devicelist = []


Any more ideas?  What is "output = pipe[0].readlines()" supposed
to do?  How can I test that?  Thanks...


In article ,
 Ignacio Vazquez-Abrams  writes:
> The problem is most likely the "2>&1" in the call to
> popen2(). Redirection is a shell function; popen*() just
> execute the process seperately, so cdrecord thinks that "2>&1"
> is a (bad) argument. It should use popen4() instead.

--
Unless otherwise noted, the statements herein reflect my personal
opinions and not those of any organization with which I may be affiliated.


From daves_spam_dodging_account at yahoo.com  Fri Oct 19 17:59:19 2001
From: daves_spam_dodging_account at yahoo.com (David Brady)
Date: Fri, 19 Oct 2001 14:59:19 -0700 (PDT)
Subject: Reverse argument order
Message-ID: <20011019215919.3702.qmail@web21108.mail.yahoo.com>

Thanks, everyone, for your answers.  Also, thanks to
those of you that ways of asking if the question
really needed to be asked.

At the time I had posted, we had considered all of the
non-answer answers that were posted here.  Most were
rejected by the business half of the team, because
they have a goal of reducing the keystroke count as
much as possible.  They're already upset that the new
scripting language has to have parentheses everywhere.
 :-)

Specifically,

We considered using named arguments, but rejected them
because even typing Wait(m=3,s=10) was judged to be
too hard, let alone Wait(minutes=3, seconds=10). 
Personally, I like this approach best, and I want to
just write in the manual, "Look, you're going to have
to learn to type, okay?"  But that's just me.

We also considered using Wait(0,0,5) for a 5-second
wait, but this was also shot down.

One possible compromise was offered by the business
half of the team, that they would be willing to type
Wait(,,5), but *WE* shot that down on the grounds that
it does not work.  (They were thinking it would
evaluate to Wait(None,None,5) which could then have
been turned into 0,0,5).

We considered the string bit, but strings require
quotes....

We even considered modifying the Python source so that
it would accept 00:00:00 as a token identifying a time
type (that we would add).  This was discarded by
everyone as WAY too much effort.  (Imagine getting the
lexer to accept things like "while t < 1:05: pass")

Anyway, thank you all again for your answers and help.
 This project is starting to shape up!

-dB
P.S. We're going to go with the "while len(args)<3:
args.insert(0,0)" model for now.  Much less sucky,
yes, thanks!

=====
--
David Brady
daves_spam_dodging_account at yahoo.com
I'm feeling very surreal today... or *AM* I?

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com



From phr-n2001d at nightsong.com  Wed Oct 10 03:29:19 2001
From: phr-n2001d at nightsong.com (Paul Rubin)
Date: 10 Oct 2001 00:29:19 -0700
Subject: Curious assignment behaviour
References: 
Message-ID: <7xsncs9cmo.fsf@ruckus.brouhaha.com>

"Tim Peters"  writes:

> [Paul Rubin, on an expression assignment operator]
> > Why on earth does it have to be different from the statement assignment
> > operator?  What's wrong with
> >
> >   while x=get_next(): whatever(x)
> >
> > I just don't buy the rationale that using = instead of == is a big source
> > of bugs.  In 25 years of hacking C code, I think I've seen that error
> > maybe once or twice.
> 
> I suggest you're highly atypical here, Paul.  This was the very first of the
> gotchas listed in Andrew Koenig's classic (late 80s) "C Traps and Pitfalls",
> and has made nearly every list of C "deadly sins" I've seen since then.
> I've wasted weeks of my own life helping people track this error down in C,
> too often under extreme time or customer pressure.  The experience of the
> other folks at PythonLabs is similar, so even if it's a disease you're
> immune to, you can be sure this will never go in.

The thing is, it's just not a matter of MY immunities.  I've spent
plenty of time debugging other people's code too, and have encountered
all kinds of errors in both their code and mine.  The =/== mistake has
just been very rare in my experience.  Can it be that the Unix
compilers I use flag the error a lot of the time, so it gets fixed
quickly, while Windows compilers don't flag it, and you're mostly
using Windows compilers?

Anyway, I can live with "while x:=get_next()" instead of x=get_next.
But I feel seriously cramped in Python when I have to say

  while 1:
     x=get_next()
     if not x: break
     whatever(x)

so I hope something is done about the issue.

> Oops!  The assert turned out to be the perversely self-fulfilling:
> 
>     assert(i = 1);

Ouch!!!! ;-)


From sholden at holdenweb.com  Thu Oct 25 11:22:23 2001
From: sholden at holdenweb.com (Steve Holden)
Date: Thu, 25 Oct 2001 11:22:23 -0400
Subject: A small inconsistency in syntax?
References: 
Message-ID: 

"Michael Abbott"  wrote in message
news:Xns91459674D7271michaelrcpcouk at 194.238.50.13...
> It seems to me that there's a little inconsistency in assigning to tuples:
>
>     >>> (x,) = ()
>     Traceback (most recent call last):
>       File "", line 1, in ?
>     ValueError: unpack tuple of wrong size
>
> Yes, that's what I expect.
>
Indeed.

>     >>> () = ()
>     SyntaxError: can't assign to ()
>
> Eh?  Why not?  It's just a matter of checking that the right hand side
> really is an empty tuple...
>
Oh, no it isn't. The best parallel I can think of is writing

>>> 2 = 34
Traceback (SyntaxError: can't assign to literal

although in your case you are trying to assign to a constructor rather than
a literal
.
> I actually hit this in some code, where I wrote:
>
>     time, status, () = myobject.read()
>
> where I happen to know that that in this particular case my object will
> return an empty tuple in its third argument.
>
> Ok, so it's easy enough for me to write
>
>     time, status, _ = myobject.read()
>
> instead, so I'm grumbling about trivia here.

Indeed :-)

Or, if you really don't want to do that, how about

    time, status = myobject.read()[:2]

regards
 Steve
--
http://www.holdenweb.com/







From mmichalski3 at home.com  Tue Oct 16 14:13:47 2001
From: mmichalski3 at home.com (MM)
Date: Tue, 16 Oct 2001 18:13:47 GMT
Subject: mod_python seems to be missing a file
References:  
Message-ID: 

Here is the apache error generated when I try to view a file named
'mptest.py':

######START
Mod_python error: "PythonHandler mptest"

Traceback (most recent call last):

  File "C:\PYTHON21\lib\mod_python\apache.py", line 181, in Dispatch
    module = import_module(module_name, _req)

  File "C:\PYTHON21\lib\mod_python\apache.py", line 335, in import_module
    f, p, d = imp.find_module(parts[i], path)

ImportError: No module named mptest
######END

Here is the configuration directive in the httpd.conf file:

    AddHandler python-program .py
    PythonHandler mptest
    PythonDebug On


I'm not sure what you mean by Python runtime and when the file's loaded.
I've placed the mod_python.dll in the modules directory of Apache and added
the appropriate LoadModule directive into the configuration file.  When
Apache loads it tells me "Apache 1.3.20 (Win32) mod_python/2.7.4
Python/2.1.1 running..."

That's the only configuration I've done with respect to Apache and Python.
Please let me know if I'm missing something.

Jan Dries  wrote in message
news:mailman.1003176151.32729.python-list at python.org...
> MM wrote:
>
>  > I've followed the mod_python documentation to the letter.  It seems
> to be on
>  > the verge of working with the one following problem:
>  >
>  > from mod_python import apache
>  >
>  > this is the first line of the test program you're told to write to see
if
>  > you're up and running.  The problem with this is that the apache.py
> file in
>  > the mod_python package is trying to import a file called _apache.  I
> cannot
>  > find this file anywhere and, apparently, neither can Python, since it
>  > complains about it, as well.  Any help on where this file can be
> found would
>  > be appreciated.
>  >
>
>
> If you check the C source, you will find that the mod_python DLL itself
> export a function init_apache().
> In other words, mod_python.dll is your missing _apache.pyd. When
> mod_python.dll is loaded, the function is registered to the Python
> runtime, and from that moment on the module _apache is known to the
> Python interpreter.
>
> If you could tell what exactly the errors are that you get in trying to
> make mod_python work, maybe I could tell what's going wrong. But it
> certainly isn't the fact that some _apache.py(d) would be missing.
>
> Regards,
> Jan
>
>
>
>




From phr-n2001d at nightsong.com  Sun Oct 28 09:51:19 2001
From: phr-n2001d at nightsong.com (Paul Rubin)
Date: 28 Oct 2001 06:51:19 -0800
Subject: interpreter crashes
References: <7xzo6cd1hw.fsf_-_@ruckus.brouhaha.com> <3BDB8F30.FEE9004C@engcorp.com> <7xd738qr2f.fsf@ruckus.brouhaha.com> <3BDC016C.7E45106@engcorp.com>
Message-ID: <7x4rojvmvs.fsf@ruckus.brouhaha.com>

Peter Hansen  writes:
> All crashes I've ever seen were with other libraries, or when
> I was trying to wrap a DLL with calldll under Windows.  Never 
> seen a crash yet under Linux.  Python is _solid_.

This was Python 2.1.1 under Redhat 7.1.  I am 100% positive I wasn't
using any 3rd party extension modules.  However I had some standard
library modules loaded--I'm not sure which ones.  Also, I had been
repeatedly reloading my own Python modules, which has always seemed
like a flaky process to me.

> Run a separate task which checks the status of the Python app from
> time to time (maybe with cron?).  Kill and restart as necessary.

Good idea, I guess.  Although the app needs to keep some persistent
data structures in ram (for security reasons it can NOT checkpoint
them to disk, so don't bother suggesting that).  Maybe I have to use
the shm module or something like that.

Thanks


From jmcwill at tridog.com  Wed Oct 10 17:16:32 2001
From: jmcwill at tridog.com (Jason McWilliams)
Date: Wed, 10 Oct 2001 15:16:32 -0600
Subject: upload file using cgi on Win2k IIS
References: 
Message-ID: <3BC4BAB0.DB2F605A@tridog.com>


Ignacio Vazquez-Abrams wrote:
> 
> On Wed, 10 Oct 2001, Jason McWilliams wrote:
> 
> > I seem to be doing everything correctly to save a posted
> > multipart/form-data file on IIS server.  Yet, I only
> > seem to be able to save a small portion of the file, not
> > the whole thing.
> >
> > The internet user has permission to the temp directory and
> > I am not getting any errors.  It works properly with the
> > same code on unix, so it must be a IIS thing?
> >
> > I have tried file.read file.value and also tried to just
> > do one line at a time... file.readline .  I can get the
> > file name fine using cgiobj.filename  ... etc.
> >
> > I get about 498 k as the file size on the uploaded file, never
> > more and I am trying to upload a big file.  Maybe there is
> > a post limit in IIS?  I know that you can set a GET limit.
> 
> What is the value of the hidden field named "MAX_FILE_SIZE" set to? Is there
> one at all? If not, then don't expect your file input to work properly.

I did not think this variable was used in cgi.py
Isnt that a php type thing.  Isn't maxlen set to 0 inside cgi.py
to allow for unlimited post length?  That is why I thought
it might be a IIS setting somewhere.



> 
> --
> Ignacio Vazquez-Abrams  
> 
> --
> http://mail.python.org/mailman/listinfo/python-list



From cqx at nefud.org  Mon Oct 22 00:11:19 2001
From: cqx at nefud.org (cqx)
Date: 21 Oct 2001 21:11:19 -0700
Subject: Ops: corrected prime algorithm
References: 
Message-ID: 

John Thingstad  writes:

> Just checked my own algorithm and found several mistakes.
> Here is the correct algorithm:
> 
> 
> def prime(n):
> 	set = [2] + range(3,n, 2)
> 	for n in range(3, int(math.sqrt(n))+1, 2):
            ^                           ^
 which 'n' is this 'n'?                 and this one?

> 		set = [x for x in set if x == n or x % n != 0]
> 	return set


-cqx


From Armin_member at newsguy.com  Thu Oct 25 06:52:06 2001
From: Armin_member at newsguy.com (Armin Steinhoff)
Date: 25 Oct 2001 03:52:06 -0700
Subject: cPickle
References: <9r3ctr02o31@drn.newsguy.com> 
Message-ID: <9r8qsm02d3a@drn.newsguy.com>

Oleg,

thanks a lot for that hint ... it's working now :)

Armin



In article , Oleg says...
>
>On Tue, Oct 23, 2001 at 02:23:07AM -0700, Armin Steinhoff wrote:
>> are there any know problems with cPickle which does prevent reading of a
>> 'pickled' file from a Windows machine on a machine with an other operating
>> system ??
>>  (e.g. QNX6) 
>> 
>> Any ideas about the reasons ??
>
>   On broken Windows OS you must open binary files in binary
>modes (and cPickle fies are binary):
>
>   infile = open(filename, 'rb')
>   outfile = open(filename, 'wb')



>
>Oleg.
>-- 
>     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
>           Programmers don't die, they just GOSUB without RETURN.
>



From sholden at holdenweb.com  Tue Oct 30 15:15:57 2001
From: sholden at holdenweb.com (Steve Holden)
Date: Tue, 30 Oct 2001 15:15:57 -0500
Subject: Unpacking extension (Re: A small inconsistency in syntax?)
References: 
Message-ID: 

 wrote in ...
>
> Bernhard Herzog wrote:
> >Personally, I wouldn't mind to see the "[a,b] = sequence" syntax go.
>
> I agree.  I think it's confusing and adds no value (unless I'm missing
> something).
>
But since it's been permissible for a long time, removing it might break
existing code. Would you propose a PEP to go through the "from __future__
..." phase and arrive at "feature removed"? As far as I'm concerned it
remains a quirk, which I could easily live without but equally easily
ignore.

regards
 Steve
--
http://www.holdenweb.com/







From info at mjais.de  Tue Oct  9 15:18:48 2001
From: info at mjais.de (Markus Jais)
Date: Tue, 09 Oct 2001 21:18:48 +0200
Subject: Why not 3.__class__ ?
References: 
Message-ID: <9pvilt$kepge$1@ID-75083.news.dfncis.de>

brueckd at tbye.com wrote:

> On Tue, 9 Oct 2001, Markus Jais wrote:
> 
>> In article , "Guido van
>> Rossum"  wrote:
>>
>> > Marcin, I don't understand why you care so much about being able to
>> > write 3.foo.  It's painful to fix in the lexer, and probably leads to
>> > less useful error messages if someone makes a mistake in a float
>> > literal
>> > (e.g. "3.e 0").  And I see zero use for it: in practice, you will never
>> > ask for 3.foo -- you'll ask for x.foo where x happens to contain the
>> > value 3.
> 
> [snip]
>> but to write 3.foo is something I would like to have in Python
> [snip]
>> It would be great, if this would be possible in Python too
> 
> Care to elaborate on why it would be "great"? Guido's reply to Marcin
> points out that there doesn't seem to be any usefulness to it. So.... what
> problem would it solve or simplifiy?  What exactly would its benefit be,
> anyway?

it would be more consise.
in Ruby, everything is an object and I can invoke methods on everything
with object.method

the result is the same.
I just think, that ruby is "more" object oriented like Python
(another reason for this is, that in Ruby every instance variable
is private!)

but  this is just a matter of taste.
again. both are cool languages and I like both.
markus




From reqhye72zux at mailexpire.com  Sat Oct  6 17:15:38 2001
From: reqhye72zux at mailexpire.com (Robert Amesz)
Date: Sat, 06 Oct 2001 21:15:38 -0000
Subject: Tkinter Html Display
References: <3daa1aa8.0110051100.33815499@posting.google.com>
Message-ID: 

Jeffrey wrote:

> Hi All,
>   I want to display an HTML file on a Tkinter Canvas widget.  Do any
> of you know how to do this?  The principle problem I have is that the
> HTML file can display subscript and symbols and stuff, while
> translated the HTML lines into text, you lose that.  I came up with
> one solution that one could just capture the HTML off the browser and
> turn it into a gif file and then display on the widget.  But I just
> wanted to know if there is anything out there or any solution for
> this....

How desperate are you to be able to display HTML? If it's important 
enough, you might consider switching to wxPython: it has an HTML-
component which can display all common HTML 3.2 elements, like fonts, 
pictures and tables.


Robert Amesz


From tefol at This.Is.Not.An.Address  Sun Oct  7 08:12:46 2001
From: tefol at This.Is.Not.An.Address (tefol)
Date: Sun, 07 Oct 2001 12:12:46 GMT
Subject: newbie form questions...
Message-ID: <9133E264AtefolThisIsNotAnAddr@61.9.128.12>

Hiya everyone....

I am trying to get a form to create a file (or append to a file if the file 
already exists, maybe..  haven't quite decided what to do in case the form 
is processed too foten to quickly yet) on a webserver as a result of a POST 
to a http form.  How I want the file to look is something like this:

field1=stringOfField1
field2=stringOfField2
field3=stringOfField3
field4=stringOfField4
field5=stringOfField5

or alternatively, 

field1 stringOfField1
field2 stringOfField2
field3 stringOfField3
field4 stringOfField4
field5 stringOfField5

But what I get is this:

(i__main__
FeedbackData
p0
(dp1
S'field5'
p2
S'stringOfField5'
p3
sS'field4'
p4
S'stringOfField4'
p5
sS'field1'
p6
S'stringOfField1'
p7
sS'field3'
p8
S'stringOfField3'
p9
sS'field2'
p10
S'stringOfField2'
p11


What the heck is all that stuff?   Is there a way to make the output be as 
I require?  Or should I create some huge regex thing to process this output 
so that it appears as I want??

Or is there an entirely different approach to take?  Basically,  I want a 
script to create a file that a cron script will regularly search for.  If 
it finds it,  it should process the information accordingly.   My script 
and html follow.  

TIA

Tefol

+++++++++++


FORM HTML:








Python Form Test



All fields are required, or else the form funtion cannot proceed.

Field1
Field2
Field3
Field4
Field5
++++++++ Python script. #!/usr/bin/python2 import cgi, os, sys, string, pickle def bail(): print "Content-type: text/html\n\n" print "

You didn't fill something out

" print "

Double check each field!
" print "Press the 'Back' button to do it again." sys.exit() class FormData: '''CGI Form information''' def __init__(self, form): for fieldname in self.fieldnames: if not form.has_key(fieldname) or form[fieldname].value == "": bail() else: setattr(self, fieldname, form[fieldname].value) class FeedbackData(FormData): fieldnames = ('field1', 'field2', 'field3', 'field4', 'field5') def __repr__(self): return '%(name)s' % vars(self) if __name__ == '__main__': sys.stderr = sys.stdout form = cgi.FieldStorage() data = FeedbackData(form) pickle.dump(data, open('/home/nemir/output/form.txt', 'w')) print "Content-type: text/html\n\n" print "

You did it!

" sys.exit() From ozonehole2k at yahoo.com Tue Oct 30 01:44:20 2001 From: ozonehole2k at yahoo.com (Ozone Hole near South Pole) Date: 29 Oct 2001 22:44:20 -0800 Subject: Matlab-style mask in Python?? Message-ID: Hi, I am a long time Matlab user. I just picked up Python for a short while. I wonder what should be the best way to do sth like: Matlab: a=[3,4,6,7,2,54,2,1,2] idx=a>4 ans: [0,0,1,1,0,1,0,0,0] a(idx) ans: [6,7,54] Python: a=[3,4,6,7,2,54,2,1,2] idx=map(lambda x: x>4,a) #assume this calculation is lengthy #and we don't want to repeat last cmd??? While we can always put that into a for loop, then append the ans element-by-element.... I feel there should be an easier way in Python. Any suggestions? From ransen_spam_me_not at nemo.it Thu Oct 4 10:21:33 2001 From: ransen_spam_me_not at nemo.it (Owen F. Ransen) Date: Thu, 04 Oct 2001 14:21:33 GMT Subject: test - don't read... References: Message-ID: <3bbc2a8b.10142621@news.newsguy.com> On Thu, 4 Oct 2001 16:50:16 +1000, Richard Jones wrote: >On Thursday 04 October 2001 16:36, Ignacio Vazquez-Abrams wrote: >> On Thu, 4 Oct 2001, Owen F. Ransen wrote: >> > On Wed, 03 Oct 2001 22:36:06 -0000, Robert Amesz >> > >> > wrote: >> > >Owen F. Ransen wrote: >> > >> don't read >> > > >> > >don't write >> > >> > don't respond >> >> don't care > >But you told me you loved me! That was then, this is now. You see, I met this snake... -- Owen F. Ransen http://www.ransen.com/ Home of Gliftic & Repligator Image Generators From gleki at gol.ge Tue Oct 23 16:34:17 2001 From: gleki at gol.ge (Giorgi Lekishvili) Date: Tue, 23 Oct 2001 13:34:17 -0700 Subject: unnecessary change References: <3BD5BCDF.B40C1422@gol.ge> <6UbB7.7681$Ub2.261294@atlpnn01.usenetserver.com> Message-ID: <3BD5D449.F7680D7D@gol.ge> Thank you for the hint! The bad news is, that the matrix turned to be un-deep-copyable object: """ >>> m1=deepcopy(m) Traceback (innermost last): File "", line 1, in ? m1=deepcopy(m) File "d:\python20\lib\copy.py", line 151, in deepcopy y = copierfunction(x, memo) File "d:\python20\lib\copy.py", line 237, in _deepcopy_inst state = deepcopy(state, memo) File "d:\python20\lib\copy.py", line 151, in deepcopy y = copierfunction(x, memo) File "d:\python20\lib\copy.py", line 200, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(x[key], memo) File "d:\python20\lib\copy.py", line 147, in deepcopy raise error, \ Error: un-deep-copyable object of type """ however, the copy function did help: """ Grtz, Giorgi Steve Holden wrote: > "Giorgi Lekishvili" wrote in message > news:3BD5BCDF.B40C1422 at gol.ge... > > Hi folks! > > > > My problem is the following: > > I want to save initial data matrix, as e.g., follows > > self.Mdata=Matr > > In the same time I need a matrix, which is used and processed. The > > latter is created as follows > > self.Mactual=self.Mdata > > > > No the problem is, that, when I have finished to use the Mactual matrix, > > self.Mdata is always changed and equals the final Mactual matrix. > > > > What is the systematic solution of the problem? > > > > Thanx in advance, > > Giorgi > > > > PS. I use Numeric module. > > > This is because Python variable bindings are actually references. You > probably need to make a copy of the matric. See if the copy module (and > particularly copy.deepcopy()) will help. > > regards > Steve > -- > http://www.holdenweb.com/ From mlh at idi.ntnu.no Wed Oct 10 14:44:15 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 10 Oct 2001 20:44:15 +0200 Subject: Why not 3.__class__ ? References: Message-ID: <9q24tv$nvh$1@tyfon.itea.ntnu.no> wrote in message news:mailman.1002735730.12645.python-list at python.org... > > Yukihiro Matsumoto wrote: > > >I'm not sure Python needs something like 3.method. Python's > >integers have far fewer methods than Ruby (because it uses > >functional style). And it doesn't have idioms like > > > > 100.times {|i| > > puts i > > } > > > >So (3).method is enough for Python. > > Agreed. Invoking methods on literals (like integers) is quite nice when > you have methods that take unnamed, in-place, code blocks as arguments as > is possible in Ruby (example above) and Smalltalk. > > Obviates the need for unfortunate idioms like "for i in range(100):" -- or > should we make that "xrange"? ;-). Well... I'm not sure it's unfortunate. For a beginner, it might be easier to translate the above into something understandable ("for each value of the index variable i in the range up to 100, execute the following block") than it would be for the Ruby version ("call the times method of the number 100 with an unnamed code block, which will then be executed with the numbers up to 100 supplied for the parameter i"). The Ruby version may be nice, but seems unnecessary to me, as long as you actually have a looping construct in the language. (And if you haven't, then methods like .times must have them internally anyway...) I do, however, think it would be nice to have some syntactic sugar for the range function, e.g.: for i in 1..10: foo() But I guess that'll never happen. :) (And, no, I don't like names like "xrange" either.) > Jim -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From jwilhelm at outsourcefinancial.com Wed Oct 31 15:49:18 2001 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: Wed, 31 Oct 2001 13:49:18 -0700 Subject: Is round() broken? Message-ID: <001201c1624d$82ea6dd0$a905a8c0@JWILHELM> Hello again everybody! I'm having some troubles with round() now... either I'm doing it completely wrong or round() is. But here's what I'm getting. >>> round( 43583.010000000002, 2 ) 43583.010000000002 >>> round( 43583.010000000002 ) 43583.0 >>> round( 43583.010000000002, 1 ) 43583.0 >>> round( 43583.010000000002, 2 ) 43583.010000000002 >>> So, what this is saying.. is that rounding to 1 decimal point works... but anything beyond that is broken? Rounding negative will round the number before the decimal point also. And actually, as a side question.. that number was pulled from a float8 field in a Postgres database, using the 'pg' module. If I look at the field through pgAdmin, I just see it as "43583.01", instead of that whole big long decimal. Is it supposed to come out like this? --Joseph Wilhelm From office at tangfeng.org Tue Oct 16 04:44:50 2001 From: office at tangfeng.org (office at tangfeng.org) Date: Tue, 16 Oct 2001 16:44:50 +0800 Subject: Beijing Tangfeng Culture Exchange Centre Message-ID: An HTML attachment was scrubbed... URL: From mrq at for.mat.bham.ac.uk Fri Oct 26 09:01:58 2001 From: mrq at for.mat.bham.ac.uk (Martyn Quick) Date: Fri, 26 Oct 2001 14:01:58 +0100 Subject: Enabling/disabling Pmw menubar items In-Reply-To: References: Message-ID: Dear All, I've been creating a menubar for an application using the Pmw MenuBar class. For example, I have something like the following: menubar = self.createcomponent( 'menubar', (), None, Pmw.MenuBar, (self.interior(),) menubar.pack() menubar.addmenu('Menu', 'A dummy menu') menubar.addmenuitem( 'Menu', 'command', 'A non-existent command', command=dummy_fucntion, label='Something', state='disabled') This has the effect that my menu item is disabled. But how do I enable it again? (I can't seem to find this out on the Pmw website!) Thanks, Martyn -------------------------------------------------------- Dr. Martyn Quick (Lecturer in Pure Mathematics) University of Birmingham, Edgbaston, Birmingham, UK. http://www.mat.bham.ac.uk/M.R.Quick/ From tim.one at home.com Wed Oct 31 00:29:47 2001 From: tim.one at home.com (Tim Peters) Date: Wed, 31 Oct 2001 00:29:47 -0500 Subject: python development practices? In-Reply-To: <7x3d40sfm4.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > ... > IMO a bunch of the frustration I sometimes feel with Python comes > from its originally being intended as a "glue" language. It's too > good for that, and finds itself used as a work horse or even a race > horse. Neither type of horse belongs in the glue factory ;-). Oooh -- good one! If Andrew doesn't add it to his Python Quotes collection, I get first dibs on passing it off as my own . From l0819m0v0smfm001 at sneakemail.com Tue Oct 9 18:14:50 2001 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Tue, 09 Oct 2001 22:14:50 GMT Subject: Python is better than free (was Re: GNU wars again) References: <3BBA56C4.9010904@sneakemail.com> <3BBABE1C.5010108@sneakemail.com> <9pimak$c22$1@tyfon.itea.ntnu.no> <825v7.1025$rq1.37994@atlpnn01.usenetserver.com> <3BBE4E12.16FE036A@earthlink.net> <9pn44q$m1r$1@tyfon.itea.ntnu.no> <3BBF2751.3010309@sneakemail.com> <23891c90.0110090118.7df7917e@posting.google.com> Message-ID: <3BC34197.2000403@sneakemail.com> Paul Boddie wrote: > > Who are these Strunk and White people anyway? (Serious question - I > assume it's an American English style manual people keep referring to, > or something, but I can't be bothered to search for it.) They must be > rich by now, though. ;-) Strunk & White are William Strunk, Jr. and E.B. White, authors of The Elements of Style, which is pretty much *the* American English style manual...all the books you've ever seen called The Elements of ____ Style (e.g. The Elements of Programming Style by Kernighan and Plauger) are patterned after it. E.B. White was a famous essayist (writing for the New Yorker for many years) and author of Charlotte's Web; William Strunk, Jr. was a college English professor of his. The Elements of Style started as a textbook written and privately printed by Strunk, and was revised by White. It's a slim volume, weighing in at 85 pages, and is almost Pythonic in its pithiness. Joshua From thomas at gatsoft.no Tue Oct 30 07:17:37 2001 From: thomas at gatsoft.no (Thomas Weholt) Date: Tue, 30 Oct 2001 12:17:37 GMT Subject: How to read a xml-file sequentially Message-ID: Hi, I need to read a xml-file sequentially, piece by piece, when a given end-tag to a given start-tag is found, the xml-data inbetween the start and end are sent to a different method for processing, then the next piece of data is read, sort of like old-school record-based files. Only the needed data is kept in memory. How can this be done using preferrably expat or sax? No DOM cuz the files are huge. Thomas From mmealman at tarsis.org_NOSPAM Thu Oct 4 13:35:14 2001 From: mmealman at tarsis.org_NOSPAM (Mark) Date: 4 Oct 2001 12:35:14 -0500 Subject: Zope vs PHP for the Linux guru Message-ID: I've been doing web app development for the last 3 years using php. I already plan on learning Python to use as a rapid GUI development language(maybe even replace some of my perl-use) and was curious about Zope. I currently develop applications using php to query both remote and local databases. I use local MySQL databases for fast read-only queries, and use a remote MS SQL 2000 database for storing mutable data. I use mod_php compiled into Apache 1.3.xx, and run php apps that range from a few hundred lines to over 50k. DB access is through php's API using MySQL's native libs and FreeTDS for connecting to SQL. On the larger php apps I use an OO design model to keep the project managable. My smaller apps are pretty much just quickly thrown together scripts. Right now I run it all on one Linux box, but have plans on creating farms of apache servers for future scalability. Some questions I had about Zope where: Is developing apps in it a quick process? Php is a very rapid language to develop in and that has become my most favored trait of the language. Does Zope have good database support? Is it faster, slower than php with database queries? I'm assuming Zope will be better than php for large project development? Is Zope easy for newbies to learn? I'm not a newbie, but we do have some clients learning to program on our seperate Cold Fusion server, they find it easier than php. I'd love to get them off Cold Fusion and onto a more cost effective open source solution. Does Zope scale well in large deployments? Any kind of support for web server farming? Any other major differences from php? Good things about it, bad things about it? Thanks for any input. -Mark -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==----- From jh at web.de Tue Oct 30 14:57:20 2001 From: jh at web.de (Jürgen Hermann) Date: Tue, 30 Oct 2001 20:57:20 +0100 Subject: [ANN] PIRXX 1.2 Message-ID: <9rn0j7$k1b$02$2@news.t-online.com> PIRXX provides a Python InteRface to Xerces and Xalan, integrating it into PyXML. This release features a stable and complete SAX2 binding. Links: * Homepage - http://pirxx.sourceforge.net/ * Download - http://sourceforge.net/project/showfiles.php?group_id=25711&release_id=58705 Changes: * Added locator support to ContentHandler interface * Implemented DTDHandler and EntityResolver * Implemented the LexicalHandler interface and SAX2 property * Some changes to SAX2 event calls so that PIRXX behaves more like xmlproc, especially delivering None instead of empty strings for empty public IDs and the like * PIRXX passes adapted "test_sax.py" * Removed reference leaks (by using PirxxObject nearly everywhere) From db3l at fitlinxx.com Fri Oct 5 13:05:05 2001 From: db3l at fitlinxx.com (David Bolen) Date: 05 Oct 2001 13:05:05 -0400 Subject: another wxPython-question References: <9pi16t$5pt1t$1@hades.rz.uni-sb.de> <3BBCB53D.407B103B@home.net> <9pk06u$58ljt$1@hades.rz.uni-sb.de> Message-ID: Uwe Schmitt writes: > thanks a lot. the import statement above works. i made an error: > i looked for a file "*wxDC*" which is not on my computer. > i'll study your example, BTW, if you haven't already, be sure and run the demo and then examine its source as full of example code. The demo exercises the majority of the wxPython features, so it's generally pretty easy to find a portion of the demo at least close to what you're working with and then look at the code to see how it accomplishes it. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From john at yates-sheets.org Wed Oct 31 16:00:50 2001 From: john at yates-sheets.org (John S. Yates, Jr.) Date: Wed, 31 Oct 2001 21:00:50 GMT Subject: MS network provider using Python Message-ID: I am still in my Python learning stage. (Not yet ready to roll my own implementation :-) I am prototyping a network provider (a DLL exporting an implementation of the MS defined NP API and invoked by MS's MPR (Multiple Provider Router)). Since I anticipate a great deal of experimentation I would dearly love to do some prototyping in Python. Can anyone in this news group offer words of wisdom? What is the best way in this kind of a rapid prototyping environment to expose my python code as a DLL? The relevant interfaces are not part of win32 so they are not supported by Mark Hammond's win32all package. This suggests that I need some kind of foreign function interface/package/technology. Should I try to decipher CALLDLL? Is there a better alternative? (In a past life I have been alternatively an assembly language coder and a compiler writer. So mapping function prototypes to calling mechanisms and data representations is not a stumbling block.) As I mentioned earlier, I would love to pull this off in Python. But I am willing to be told by those in the know that I am really better of sticking to C++... /john -- John Yates 40 Pine Street Needham, MA 02492 781 444-2899 From jmcwill at tridog.com Wed Oct 10 18:52:03 2001 From: jmcwill at tridog.com (Jason McWilliams) Date: Wed, 10 Oct 2001 16:52:03 -0600 Subject: upload file using cgi on Win2k IIS References: Message-ID: <3BC4D113.F99FE096@tridog.com> Ignacio Vazquez-Abrams wrote: > > On Wed, 10 Oct 2001, Jason McWilliams wrote: > > > Ignacio Vazquez-Abrams wrote: > > > > > > On Wed, 10 Oct 2001, Jason McWilliams wrote: > > > > > > > I seem to be doing everything correctly to save a posted > > > > multipart/form-data file on IIS server. Yet, I only > > > > seem to be able to save a small portion of the file, not > > > > the whole thing. > > > > > > > > The internet user has permission to the temp directory and > > > > I am not getting any errors. It works properly with the > > > > same code on unix, so it must be a IIS thing? > > > > > > > > I have tried file.read file.value and also tried to just > > > > do one line at a time... file.readline . I can get the > > > > file name fine using cgiobj.filename ... etc. > > > > > > > > I get about 498 k as the file size on the uploaded file, never > > > > more and I am trying to upload a big file. Maybe there is > > > > a post limit in IIS? I know that you can set a GET limit. > > > > > > What is the value of the hidden field named "MAX_FILE_SIZE" set to? Is there > > > one at all? If not, then don't expect your file input to work properly. > > > > I did not think this variable was used in cgi.py > > Isnt that a php type thing. Isn't maxlen set to 0 inside cgi.py > > to allow for unlimited post length? That is why I thought > > it might be a IIS setting somewhere. > > Hmm. I had always thought it was a browser thing, but after doing some > research I think that you're right. Unfortunately I don't have enough IIS > knowledge to know exactly which setting it is. It's under the web properties, > probably, but I have no idea past that. > > FYI, the default value of cgi.maxlen is 0, so that's probably not it. Here is something interesting. I can upload .txt and .doc files no problem, no matter what the size. Things die when trying to upload .gif or .zip or .tgz or other binaries similar. Some of it gets uploaded, but only a small portion? I am at a loss now. > > -- > Ignacio Vazquez-Abrams > > -- > http://mail.python.org/mailman/listinfo/python-list From Virus.Patrol at drsolomon.com Tue Oct 9 14:36:06 2001 From: Virus.Patrol at drsolomon.com (Dr Solomon's Virus Patrol) Date: Tue, 09 Oct 2001 18:36:06 GMT Subject: TROJAN ALERT! (JS/Loop) References: Message-ID: <3bc343a0.fba6e0c5.c0a801.00.R@drsolomon.com> WARNING! A trojan has been found in an article posted to the following newsgroup(s): comp.lang.javascript, alt.config, comp.lang.perl.misc, comp.lang.python, comp.os.linux.misc Message header follows: >Message-Id: >From: "dvus" >Subject: YOU ARE ALL GAY! >Date: 09 Oct 2001 15:11:40 GMT Dr Solomon's FindVirus/VirusScan report follows: Dr Solomon's FindVirus IN-HOUSE version. Copyright (c) 1999 Network Associates Inc. Virus data file v9999 created Oct 08 2001 Scanning for 58978 viruses, trojans and variants. [HTML part] ... Found the JS/Loop trojan !!! You can download a free evaluation (yet fully functional) copy of the latest released version of Dr Solomon's FindVirus/VirusScan from the following locations: WWW: http://www.nai.com/naicommon/buy-try/try/products-evals.asp CompuServe: GO DRSOLOMON or GO MCAFEE AOL: SAFETYONLINE IMPORTANT! The trojan has been detected by the latest IN-HOUSE version of Dr Solomon's FindVirus/VirusScan. As new viruses and trojans appear at the rate of several hundreds a month, the latest RELEASED version of FindVirus/VirusScan might be unable to detect this particular trojan. If you have downloaded the above file and your copy of FindVirus/VirusScan does not detect the trojan in it, contact Network Associates Technical support and ask for the extra driver to detect the JS/Loop trojan. -- Dr Solomon's Virus Patrol UK Support: support at drsolomon.com NAI Anti-Virus Emergency Response Team US Support: support at nai.com WWW: http://www.mcafeeb2b.com UK Tel: +44 (0) 1296 318700 CompuServe: GO DRSOLOMON USA Tel: +1 408 988-3832 From dash at home.com Sun Oct 14 18:30:08 2001 From: dash at home.com (David Ashe) Date: Sun, 14 Oct 2001 22:30:08 GMT Subject: Tkinter & all widgets Message-ID: Is there a way to get the complete list of widgets in a window as a list, array, dictionary, or tuple? I seem to recall this was possible under tcl, but I can't remember how. D From brueckd at tbye.com Thu Oct 11 00:32:07 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 10 Oct 2001 21:32:07 -0700 (PDT) Subject: Python questions -> compiler and datatypes etc In-Reply-To: <7xr8sbc993.fsf@ruckus.brouhaha.com> Message-ID: On 10 Oct 2001, Paul Rubin wrote: > Richard Jones writes: > > Do a search in the python mailing list for "python compiler". The > > answer is invariably "it's bloody hard". This stems from the > > fundamental dynamic typing of python. It's very very very hard to > > write a compiler when you don't know the type of the objects you're > > dealing with beforehand. Java knows these types, because it's > > statically typed. Therefore it's relatively trivial (compared to > > python) to write a compiler for Java. > > I think the real answer to why there's no Python compiler is no one > has really wanted to write one. Python's runtime semantics are pretty > similar to Lisp systems, and native-code Lisp compilers have existed > since the 1960's or maybe even earlier. It might even be feasible > to adapt one to compile Python. That'd be great. How about just creating a Python-to-Lisp translator? Then you could use whatever Lisp compilation tools are available (assuming, of course, that the performance of compiled Lisp is good enough to make the effort worthwhile). It seems like the really hard part about translating Python to C, for example, is that you're moving "down" the dynamic language scale. But if you already have a compiler for a language that is near or higher on that scale, then somebody has already done a lot of the work for you. -Dave From James_Althoff at i2.com Wed Oct 17 13:35:43 2001 From: James_Althoff at i2.com (James_Althoff at i2.com) Date: Wed, 17 Oct 2001 10:35:43 -0700 Subject: Conditional Expressions don't solve the problem Message-ID: Fredrik Lundh wrote: >and the "while 1" pydiom usually doesn't look that way. >write pydiomatic Python code instead doing things the C/Java "Pydiom" & "pydiomatic"? Pretty cool. Is this new? Jim From phr-n2001d at nightsong.com Sun Oct 7 12:57:20 2001 From: phr-n2001d at nightsong.com (Paul Rubin) Date: 07 Oct 2001 09:57:20 -0700 Subject: SPAM (Re: ANNOUNCE: "Compiler") References: Message-ID: <7xitdr4ccv.fsf@ruckus.brouhaha.com> This is a commercial closed-source program that has nothing to do with Python. From sholden at holdenweb.com Wed Oct 31 08:42:01 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 31 Oct 2001 08:42:01 -0500 Subject: python-postgres-informix interaction problems References: Message-ID: "J Dubal" wrote ... > Hello good people! > Hello yourself. All the *good* people were busy, so they asked *me* to reply :-) > We have developed Informix RDBMS based commercial applications in > Informix-4gl. It is a good procedural language with embeded SQL. We > are trying to rewrite some apps in Python with postgresql backend for > licensing reasons. Python is good too. We are trying to do this with > latest versions of RH linux (7.2), python 2.1 and postgres 7.1.3. We > face following issues: > Excellent. Another company decides to embrace open source products. If only Microsoft would learn this lesson ... > 1. We have to read data from informix db, process it and insert into > postgres. We are using informixdb module (DBAPI 1) which is bit dated. > In Informix we 'select custno, custname, custaddr1, ... into progvar1, > progvar2, ... from custmf where ...' In python, we say fetchone() and > we get a list. We are then moving the elements of the list to named > program variables thus: > pcustno = list1[0] > pcustname = list1[1] > pcustaddr1 = list1[2] > ... as many as reqd > This way we give meaningful names to data items read from db and > process further. > Is there a better, more elegant/efficient way to to this? > Yes. Not necessarily more efficient (probably less so), but much more usable from a programmatic point of view is Greg Stein's dtuple module, whicj allows you to address the tuple using numerical or field-name subscripts as well as attributes (t.fieldname). See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81252 gives you a short example of the advantages of this excellent module. > 2. To insert this data into postgres, we used to use pygres included > in the postgres distribution (latest). We had to stop using this > because we couldn't find a way to find out how many rows it have > inserted, updated or deleted after such statements are executed ie we > couldn't find a way to check the status or return code. So we switched > over to PoPy which is DBAPI2 and where we could check number of rows > affected. Is this right thing to do? > This sounds like an excellent plan. > 3. In order to insert data into postgres, we have to compose an insert > statement thus: > cur.execute("insert into custmf (custno, custname, > custaddr1,...) > values (%i,'%s','%s'...)" %(pcustno,pcustname, > pcustaddr1....)) > Is there a better way of doing this? > Yes. Use parameterized statements. There are five different schemes, the most common of which uses question marks in the statement to associate data values from a tuple provided to the cursor.execute() method as a second argument. So you would write: cur.execute("""INSERT INTO custmf (custno, custname, pcustaddr1, ...) VALUES (?, ?, ?, ...)""", (pcustno, pcustname, pcustaddr1, ...)) The DB API documentation gives you more detail on this. Note that not only is this saving you from constructing individual statements, it also gives the DB API chance to optimize successive uses of the same statement with different values. > 4. The above string substitute converts program variables holding null > value into 'None' which goes into target table as string 'None'. To > avoid this we parse all columns to check if they are 'None' and > replace them by ''. Is there a better way to do this? > Parameterization should solve this problem too! > 5. The above check works only on string variables. We have not found > yet a way to handle nulls in numeric columns. Please suggest a > solution. > And this one! > 6. If the character columns happen to contain quotes, the above > composed insert statement breaks. Please suggest a solution. > And this one! THe DB module will perform all necessary quoting! Hope this helps. Good luck with your project. regards Steve -- http://www.holdenweb.com/ From sandysj at juno.com Thu Oct 4 15:38:07 2001 From: sandysj at juno.com (Jeff Sandys) Date: Thu, 4 Oct 2001 19:38:07 GMT Subject: A little amusing Python program References: <3bbaf6c9$0$244$edfadb0f@dspool01.news.tele.dk> Message-ID: <3BBCBA9F.D1777976@juno.com> What a clever little program. I have felt for a long time that a program that passes the Turing test will use the web as a corpus of data. Microsoft showed a similar program at the IJCAI that would answer questions. It answered some questions like "What is A.I." and "Who made the movie A.I.", but when asked "Who is Bill Gates married to" it's reply was "I'm not sure, either Malinda French or Microsoft" Another program shown at an AI conference was a document classifier. To determine which folder to add the document to, it simply compare the size of the tarred folders before and after adding the document. Of all the AI programs used for document sorting it came closest to a human sorter. Thanks, Jeff Sandys From gh_pythonlist at gmx.de Thu Oct 25 16:37:39 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 25 Oct 2001 22:37:39 +0200 Subject: urllib.urlopen + https = all threads locked? In-Reply-To: ; from guido@python.org on Thu, Oct 25, 2001 at 04:00:01AM +0000 References: Message-ID: <20011025223736.A12493@lilith.hqd-internal> On Thu, Oct 25, 2001 at 04:00:01AM +0000, Guido van Rossum wrote: > Gerhard H?ring writes: > > > In the meantime, this is a quick (untested) patch against current CVS > > Python: > [patch snipped] > > > Is this a known problem? > > > > Unless it's reported as a bug with the Sourceforge bugtracker, it's not > > a known problem <0.7 wink>. > > Gerhard, would you mind uploading that to SF? Done (#475045). I hope it's not too late for 2.2. Jeff, thanks for the test case. It was very useful. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From info at mjais.de Wed Oct 17 17:26:41 2001 From: info at mjais.de (Markus Jais) Date: Wed, 17 Oct 2001 23:26:41 +0200 Subject: problem with indentation and emacs Message-ID: <9qkt53$olvlr$1@ID-75083.news.dfncis.de> hello I have a problem which drives me crazy! when I cut and paste some code within a *.py file then there seems to be problems with identation. everything looks fine, but the programm crashes with syntax error or with "IndentationError: expected an indented block" when I look at the code, everything looks o.k. when I open the file with vim and reindent everyting, the programm works. when I reindent it with Xemacs, I got the same errors maybe this is a problems with tabs and spaces, but I couldn't find out anything. please help. Xemacs is cool and python is cool. but I want to use them together. markus From nomad*** at ***freemail.absa.co.za Tue Oct 9 08:39:57 2001 From: nomad*** at ***freemail.absa.co.za (Nomad) Date: Tue, 09 Oct 2001 14:39:57 +0200 Subject: Octonians in Python References: <7x3d4wpqi0.fsf@ruckus.brouhaha.com> <_4Lv7.36535$My2.18927726@news1.mntp1.il.home.com> Message-ID: On Sat, 06 Oct 2001 21:55:06 GMT, "David Feustel" wrote: >Lots of interesting stuff on 'onions here. onions? No. No it's too easy, but I can't help it -- Nomad Wondering of the vast emptyness of the 'net in search of something cool. From grante at visi.com Wed Oct 24 20:59:49 2001 From: grante at visi.com (Grant Edwards) Date: Thu, 25 Oct 2001 00:59:49 GMT Subject: Need help with programming. References: <20011024194636.07978.00000094@mb-mb.aol.com> Message-ID: On Thu, 25 Oct 2001 00:50:22 GMT, William Tanksley wrote: >>May I remind you that I AM NEW TO PYTHON, and COMPUTER LANGUAGES ALL >>TOGETHER (Excluding HTML). I'M LEARNING PYTHON FOR SELF INTEREST, SO >>PLEASE NO FLAMES.. > >Are you under the impression that screaming at people you've never met is >socially commendable? I assume that he is not only new to programming, but is is also new to Usenet and doesn't know that all caps text is considered to be shouting. Except in Zippy the Pinhead quotes where it is an important part of the literary experience... -- Grant Edwards grante Yow! .. does your DRESSING at ROOM have enough ASPARAGUS? visi.com From jim_kerr at agilent.com Tue Oct 2 20:19:26 2001 From: jim_kerr at agilent.com (Jim Kerr) Date: 2 Oct 2001 17:19:26 -0700 Subject: problem processing COMException in VB6 Message-ID: <50626d00.0110021619.2000be73@posting.google.com> I've written a COM server in Python that is accessed by a VB6 client. The client/server interaction works just fine, but I'm having a problem displaying error messages in VB when the server throws an exception. The problem is that VB seems to be displaying a generic error message based upon the scode for the exception, and ignoring the error description entirely. For example, if the server executes raise COMException(desc="No measurement defined on channel %d" % channelNum, scode=winerror.DISP_E_BADINDEX) and the VB client catches the exception with MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Server Error" then the message box displays the text "Subscript out of range" instead of "No measurement defined on channel 3". I must be missing something obvious here...? BTW, I'm running ActivePython 2.1.211 on Windows 2000. -Jim ========== Jim Kerr Software Engineer Agilent Technologies, Inc. From mlh at idi.ntnu.no Sat Oct 6 10:02:50 2001 From: mlh at idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 6 Oct 2001 16:02:50 +0200 Subject: Generating a random number References: <9plkkk$98r$1@ins22.netins.net> <4cnsrtsj7ks3jc6emj39ksod2ipmr9f0bb@4ax.com> <3BBE4728.40101@sneakemail.com> Message-ID: <9pn2ua$lg7$1@tyfon.itea.ntnu.no> "Joshua Macy" wrote in message news:3BBE4728.40101 at sneakemail.com... > > > Dale Strickland-Clark wrote > > > > > from whrandom import randint > > > > print randint(1, 10) > > > > > whrandom is deprecated. Use random instead. Actually, randint is deprecated as well... Use randrange instead :) Note that when using randrange, the endpoints are interpreted as with the range function, so the statement becomes print randrange(1,11) or print randrange(10)+1 > > Joshua -- Magnus Lie Hetland http://www.hetland.org "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick From brueckd at tbye.com Tue Oct 9 17:56:36 2001 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 9 Oct 2001 14:56:36 -0700 (PDT) Subject: Why not 3.__class__ ? In-Reply-To: <9pvilt$kepge$1@ID-75083.news.dfncis.de> Message-ID: > > [snip] > >> but to write 3.foo is something I would like to have in Python > > [snip] > >> It would be great, if this would be possible in Python too > > > > Care to elaborate on why it would be "great"? Guido's reply to Marcin > > points out that there doesn't seem to be any usefulness to it. So.... what > > problem would it solve or simplifiy? What exactly would its benefit be, > > anyway? > > it would be more consise. > in Ruby, everything is an object and I can invoke methods on everything > with object.method Uh... that is not any different than Python, but even if it was, the conciseness of something useless is irrelevant. :) From alan.gauld at bt.com Thu Oct 25 10:54:03 2001 From: alan.gauld at bt.com (Alan Gauld) Date: Thu, 25 Oct 2001 15:54:03 +0100 Subject: My Web Tutor has moved Message-ID: <3BD8278B.9000405@bt.com> My online beginner's tutorial has moved. If you currently have a web site linked to: http://www.crosswinds.net/~agauld Could you please move the link to: http://www.freenetpages.co.uk/hp/alan.gauld The new site has no adverts (hooray!) and more importantly seems much more stable. As soon as the crosswinds site becomes stable again I will put a notice and redirector onto the welcome page. Thanks, Alan Gauld. From sholden at holdenweb.com Wed Oct 24 08:20:17 2001 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 24 Oct 2001 08:20:17 -0400 Subject: Executing a string as python code References: Message-ID: "Stephen Boulet" wrote in message news:ttdbclaabhte92 at corp.supernews.com... > Yes, but this is no cgi script. It's in my program, which, after all, also > executes python code. > > If I write: > > << > command = '' > for i in range(100): > command = command + 'list%d = []\n' % i > > exec(command) > > >> > > That's no less secure than typing them out by hand, right? > This may be so. But your next problem is then presumably to write a loop to process each of these different variables. The major point (assuming no user input is associated with your executed code) is the pollution of your name space in a way which doesn't help you in your overall programming goal. You haven't yet demonstrated why you'd rather run your code than something like lst = [] for i in range(100): lst.append([]) If you really need 100 different empty lists, why not create a list, or dictionary, of lists to hold them? Saving each one as a variable makes them difficult to deal with, which is quite unnecessary. Your way you have to create a statement referencing listN and then execute it. stmt = "list%d.append(something)" % n exec(stmt) With a list of lists you can just execute lst[n].append(something) Simpler, cleanr, faster. Where are the *dis*advantages? regards Steve -- http://www.holdenweb.com/ From kragen at dnaco.net Tue Oct 16 16:34:41 2001 From: kragen at dnaco.net (Kragen Sitaker) Date: Tue, 16 Oct 2001 20:34:41 GMT Subject: Directed input References: <9qi4r2$gpq$1@nserve1.acs.ucalgary.ca> Message-ID: In article <9qi4r2$gpq$1 at nserve1.acs.ucalgary.ca>, Michael Yuen wrote: >I'm just in the process of learning Python right now and i'm wondering if >there's a way run a program to take a file via directed input and >sending output to another file via the command line. > >Here's what I mean: > >myprogram.py < my_input > my_output I assume you're on Unix? The above should work fine. -- Kragen Sitaker Perilous to all of us are the devices of an art deeper than we possess ourselves. -- Gandalf the White [J.R.R. Tolkien, "The Two Towers", Bk 3, Ch. XI] From mel.b at mindspring.com Sun Oct 7 03:45:07 2001 From: mel.b at mindspring.com (Mel Brown) Date: Sun, 7 Oct 2001 00:45:07 -0700 Subject: Newbie Question Message-ID: <9pp1ca$ca6$1@slb4.atl.mindspring.net> I am trying to get Python up and running. Among the modules that I know that I will need are math, cmath, and string. When I import sys, then print out the included module names, I get that math and cmath are included but sting is not. When I import math and then try to compute something simple like sin(3), I am told that the function sin() is not available. My question is how to make the modules math, cmath, and string available for my use. Any help, please? From guido at python.org Mon Oct 29 02:58:42 2001 From: guido at python.org (Guido van Rossum) Date: Mon, 29 Oct 2001 02:58:42 -0500 Subject: Dictionary from list? In-Reply-To: Your message of "Mon, 29 Oct 2001 02:01:28 EST." References: Message-ID: <200110290758.CAA11453@cj20424-a.reston1.va.home.com> Subclassing list and dictionary etc. should be seen as an experimental feature; I don't want to fully fix the semantics yet in all cases. I think of these types as having two sets of interfaces: an internal, fixed one (e.g. PyDict_SetItem) and an external, overridable one (e.g. __setitem__). The external operations are defined in terms of the internal ones. When you invoke an operation with a Python notation (e.g. dict[key]), you invoke the external operation, and hence overrides will have the expected effect. But many accesses from inside the Python VM (e.g. dictionary use by exec) and from other methods (e.g. dict.update) invoke the internal versions of various operations, and hence won't see the overrides. IMO, fixing these internal accesses to always use the overrides would remove much of the attractiveness of subclassing built-in types; I believe it would slow things down too much given the current state of the implementation. If you want a vaguely dictionary-like object, write a class that doesn't derive from dictionary but implements the mapping protocol; if you want a base class that implements most of the operations already, start with UserDict. Subclassing a built-in type is appropriate when either (a) you want to use it in a context where a genuine list/dictionary/file/etc.; or (b) you want the speed advantage of the built-in type. In both cases you have to live with some restrictions. Remapping the fundamental accessors (like __getitem__) is probably not a good idea in either case. Adding new state and behavior is fine. We should document this more clearly and in more detail. --Guido van Rossum (home page: http://www.python.org/~guido/) From unknown at lee-morgan.net Wed Oct 10 23:15:10 2001 From: unknown at lee-morgan.net (Lee Morgan) Date: Thu, 11 Oct 2001 03:15:10 GMT Subject: How to set tab-width to 4 spaces in emacs ?? References: <1J1x7.14385$tu6.623674@news1.oke.nextra.no> Message-ID: "Thomas Weholt" writes: > Trying to set the tab-width in emacs to 4 spaces without luck. Using > Mandrake 8.1 ( great distro btw, python 2.1.1, postgresql 7.1.3 etc. try it > now !) > > tried : > > # tab-width: 4 > etc. but no go. > > Any hints ??? > I think (setq tab-width 4) is correct, although isnt it both a global and buffer variable(or is it a mode var?) - so you may need to add it on to your mode hook. (Although I've never had reason to change python-mode) > Thomas > > -- Lee Morgan From rjroy at takingcontrol.com Tue Oct 16 09:39:38 2001 From: rjroy at takingcontrol.com (Robert Roy) Date: Tue, 16 Oct 2001 13:39:38 GMT Subject: Link between a C variable and a python object References: Message-ID: <3bcc370d.1705250234@news1.on.sympatico.ca> On Fri, 12 Oct 2001 13:01:23 +0200 (CEST), Mads Bondo Dydensborg wrote: >On 12 Oct 2001, Armin wrote: > >> In article <3BC4366A.DC3F6982 at wanadoo.fr>, guignot says... >> > >> >Does Python have a nice feature of Tcl, i.e. linking an external C >> >variable and an internal variable, with TclLinkVar ? >> >> Yes ... have a look to the C API. > >Could you possible be more specific? I have looked at the API, and the >code generated by SWIG, and it seems that you need to use function calls - >there seems to be no easy way to share a variable? > >Mads See the sources for fileobject.c. It exposes some C vars to python. look for "struct PyMemberDef" and follow the declared variable. Note that python 2.2 has a new way of doing this. It seems simpler than before now. I have not tried this. Your question just got me looking thats all... bob > >-- >Mads Bondo Dydensborg. madsdyd at challenge.dk >It is strange to claim that video games should influence children. If for >example Pac-Man influenced children born in the 1980'ies, then today we >would have a lot of young people jumping around in dark rooms, eating pills >while listening to monotome music > > - Anonym > > From bill-bell at bill-bell.hamilton.on.ca Mon Oct 15 07:44:34 2001 From: bill-bell at bill-bell.hamilton.on.ca (Bill Bell) Date: Mon, 15 Oct 2001 07:44:34 -0400 Subject: Python web client anyone? In-Reply-To: <1003107518.407.27951.m4@yahoogroups.com> Message-ID: <3BCA93E2.27792.2C9ABBD@localhost> Paul Rubin wrote, in part: > ... I was looking for something that actually parses the HTML on > the retrieved page like LWP does. I wonder if there's some way to > do that with the XML libraries (though HTML is generally not > well-formed XML ... Paul, If your platform is MSW then you might consider using MSHTML. It's the HTML parser+ that's embedded in IE, and it can be exercised as a COM object. Clearly a product like IE does an excellent job of parsing broken HTML docs and MSHTML is I believe freely distributable. The snag in using MSHTML with Python is that Python is as yet unable to process vtable-based interfaces (which is really needed to use MSHTML)--ref Mark Hammond's remarks of several weeks ago. One way around this problem is to model code on the 'walkall' example provided on MSDN and wrap it in some way to make what you want accessible in Python. I have not investigated what's available for parsing HTML on other platforms. However, the same general strategy (ie, that of exercising one of the best available web clients on the platform) might work in those cases too. Best of luck, Bill "It is the time that you have wasted for your rose that makes your rose so important."--St-Exupery From eyal at hyperroll.com Sun Oct 28 17:23:02 2001 From: eyal at hyperroll.com (Eyal Lotem) Date: Mon, 29 Oct 2001 00:23:02 +0200 Subject: Why doesn't this simple Curry-like implemention work? References: Message-ID: <3bdc8494@news.bezeqint.net> Michael R. Head wrote: > # for some reason this function doesn't work in python 1.5.2. > def curry(f, p): > return lambda x: apply(f, p, x) apply(f, p, x) is in the context of an internal function. Without nested_scopes (optionally introduced in Python 2.1, and in by default in Python 2.2), internal functions cannot use containing-function's scopes. Python 1.5 code: def curry(f, p): return lambda x,f=f,p=p: apply(f, p, x) or in Python 2.1: from __future__ import nested_scopes def curry(f, p): return lambda x: apply(f, p, x) will work. I would suggest considering moving to Python 2.1, as nested_scopes seem to be safer, at least for this case. With the default-argument trick, you allow more arguments than you really want to allow, which could cause trouble. From jkraska at san.rr.com Tue Oct 2 20:21:30 2001 From: jkraska at san.rr.com (Courageous) Date: Wed, 03 Oct 2001 00:21:30 GMT Subject: How do Java interfaces translate to Python? References: Message-ID: >> What exactly is it that you do with interfaces in Java? >Enforcing a contract between... _Enforcement_ is antithetical to Python. Python is a _dynamic_ language. Dynamic languages provided an environment which is _mutable_ at run-time, by definition. C// From john.thingstad at chello.no Sun Oct 21 09:15:56 2001 From: john.thingstad at chello.no (John Thingstad) Date: Sun, 21 Oct 2001 15:15:56 +0200 Subject: Array of 2^n Message-ID: <20011021133449.BLZ12720.mta01@mjolner> > Okay, python newbie here. I'm liking what I see, but it seems like there > are holes in the features of python's objects. I remember programming in > squeak (an extension of smalltalk), and you could do complex operations on > lists, and it would apply the result to each item. I want to make a n-item > list such that mylist[i] = 2**i. How can I generate such a list in Python? The fastest, cleanest way would probably be using list comprehentions: l = [2**i for i in range(10)] From tim.golden at iname.com Wed Oct 3 02:20:34 2001 From: tim.golden at iname.com (Tim Golden) Date: 2 Oct 2001 23:20:34 -0700 Subject: Problem with COM and Excel References: <3BBA1BD5.8E833283@vip.fi> Message-ID: Pekka Niiranen wrote in message news:<3BBA1BD5.8E833283 at vip.fi>... > How can I run AutoFit to all columns of my Excel sheet from python ? > > I have tried: > > >>> xlApp = win32com.client.dynamic.Dispatch('Excel.Application') > >>> xlBook = xlApp.Workbooks.Add() > >>> sht = xlBook.Worksheets("Sheet1") > >>> xlApp.Visible = 1 > > So far so good, but at this stage I added some values to Excel Sheet > (manually) and then run: > > >>> sht.Columns().AutoFit > > The whole PC is jamming with harddisk running madly. I have to use task > manager to kill Idle and Excel. > > -pekka- The following works for me: def _2xl (headers, rowset, spreadsheet): """_2xl - put a cursor output set to a spreadsheet, optionally applying traffic light formatting Parameters: headers - sequence of sequences containing column names & types (typically from cursor.description) rowset - sequence containing each row as a sequence spreadsheet - full path to a spreadsheet """ n_cols = len (headers) n_rows = len (rowset) xl = Dispatch ("Excel.Application") xl.DisplayAlerts = 0 try: xl.Workbooks.Add () xl.ActiveSheet.Range (xl.Cells (1, 1), xl.Cells (1, n_cols)).Value = [header[0] for header in headers] xl.ActiveSheet.Range (xl.Cells (1, 1), xl.Cells (1, n_cols)).Font.Bold = 1 xl.ActiveSheet.Range (xl.Cells (2, 1), xl.Cells (1 + n_rows, n_cols)).Value = rowset xl.ActiveSheet.Range (xl.Cells (1, 1), xl.Cells (1 + n_rows, n_cols)).EntireColumn.AutoFit () xl.ActiveSheet.SaveAs (Filename=spreadsheet) xl.Quit () finally: xl = None del xl I suspect the bit you need is the EntireColumn property of the range. HTH. Tim From ignacio at openservices.net Fri Oct 5 04:11:07 2001 From: ignacio at openservices.net (Ignacio Vazquez-Abrams) Date: Fri, 5 Oct 2001 04:11:07 -0400 (EDT) Subject: Formatted printing of deep tuples In-Reply-To: <01100517304104.10490@ike> Message-ID: On Fri, 5 Oct 2001, Richard Jones wrote: > Bored. Wrote this: Heh. I write some of my best code when bored. > def format_tuple(out, tuple, indent=''): > out('%s(\n'%indent) > new_indent = indent+' ' > for element in tuple: > if type(element) == type(()): > format_tuple(out, element, new_indent) > else: > out('%s%r,\n'%(new_indent, element)) > out('%s)\n'%indent) > > import sys > out = sys.stdout.write > format_tuple(out, (((1, 2),), ((), ('a', (('b', 'c'),))))) > > > Might write another before I go home ;) Already done. Take a look at this: --- def format_tuple(input, indent=2, _indent=0, chars='()', first=0): ret='%s%s' % (_indent*' ', chars[0]) for element in range(len(input)): if element: ret=ret+', ' if type(input[element])==type(()): ret=ret+'\n'+format_tuple(input[element], indent, _indent+indent, '()', 0) first=1 elif type(input[element])==type([]): ret=ret+'\n'+format_tuple(input[element], indent, _indent+indent, '[]', 0) first=1 else: ret=ret+'%s' % (`input[element]`) first=0 ret=ret+'%s%s%s' % (first*'\n', first*_indent*' ', chars[1]) return ret print format_tuple((((1, 2),), ((), ('a', (['b', 'c'],))))) --- I made the ouput a little clearer than my initial spec (like that's a _bad_ thing...). -- Ignacio Vazquez-Abrams From claird at starbase.neosoft.com Thu Oct 18 13:56:28 2001 From: claird at starbase.neosoft.com (Cameron Laird) Date: 18 Oct 2001 12:56:28 -0500 Subject: On morgage payments References: Message-ID: In article , John Thingstad wrote: >Isaw earlier a very inefficient way of calculating morgage on a loan. >The recurence relation: > >P = amount >i = interest >d = downpayment > >P = i*P - d > n n-1 > >was solver by itteration in a loop > >I would like to point out: > >P = i * (i*P - d) - d > i+1 i > >P = i * ( i * (i * P - d) -d) -d) > i + 2 i > > >P = i*i*i*P -d(i^2 + i +1) > i+2 i > >by inspecion i*i*i is a exponential and i^2 + i +1 is a geometric series so we have: > >P = i^n * P - d * (i^n -1 / i -1) > n 0 > >Which can be computed once. > > I can't interpret what appears above in any standard way to yield internally-consistent results. Rather than patch up what I suspect is just mis-parenthesization, I offer factor = (1 + i) ** n payment = P * i * factor / (factor - 1) as the most useful pertinent closed-form computation. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From bonzo at vnet.net Sat Oct 13 14:19:40 2001 From: bonzo at vnet.net (Alex Ravenel) Date: Sat, 13 Oct 2001 18:19:40 GMT Subject: Extracting attachments with Python? Message-ID: <0B%x7.10230$YC3.3926894@typhoon.southeast.rr.com> Is there a way to have Python extract a series of attachments from a Microsoft Outlook .dbx file into a file of my choosing? I was sent a series of documents by my brother, and while they arent really that many (about 100), I think it would be interesting to see if Python could do it for me. Thanks. -- Alex Ravenel bonzo at vnet.net From gh_pythonlist at gmx.de Tue Oct 23 12:11:25 2001 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 23 Oct 2001 18:11:25 +0200 Subject: POLL in different OSes In-Reply-To: <5.1.0.14.0.20011023125024.027cf278@imap.hq.movilogic.com>; from lucio@movilogic.com on Tue, Oct 23, 2001 at 12:52:28PM -0300 References: <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> <5.1.0.14.0.20011022224503.00b4e280@imap.hq.movilogic.com> <20011023101838.A561@lilith.hqd-internal> <5.1.0.14.0.20011023125024.027cf278@imap.hq.movilogic.com> Message-ID: <20011023181125.A2111@lilith.hqd-internal> On Tue, Oct 23, 2001 at 12:52:28PM -0300, Lucio Torre wrote: > At 10:18 AM 23/10/2001 +0200, Gerhard H?ring wrote: > >On Mon, Oct 22, 2001 at 10:51:02PM -0300, Lucio Torre wrote: > > > From the documentation: > > > > > > "The poll() system call, supported on most Unix systems" > > > > > > and my questions: > > > > > > a) is poll supported on Windows? > > > > > > my guess is no, but i hoping for a yes. > > > >It isn't. Unless, you're using Cygwin. Also, select only works with > >sockets on Windows. > > > >Wouldn't it be possible to emulate poll() with select()? I'd be glad to > >see a patch appear at Sourceforge if that's possible :-) > > > >Gerhard > > i think i could do that. i can make a .c with the code that emulates > poll from select, if someone else is willing to make it a patch or > whatever it should be to get into python. That would be nice. I'd be willing to review, test, document and do the patch submission at Sourceforge, if you want to avoid that. > btw: is it worth it? poll is supposed to be faster, so why emulate it? > it would have no reason to exist! Consistency across platforms is a good reason to have it. I once wanted to use a Python module using poll on Windows and had to rewrite it with select. Had poll() been available on Windows, this wouldn't have been necessary. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0 public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From use-net at schabi.de Tue Oct 23 17:15:12 2001 From: use-net at schabi.de (Markus Schaber) Date: Tue, 23 Oct 2001 23:15:12 +0200 Subject: Apologise (was: Re: IF STATEMENTS) References: <20011018002005.53f58ef2.use-net@schabi.de> <20011018102800.11c71435.use-net@schabi.de> Message-ID: <20011023231512.79e51793.use-net@schabi.de> Hi, On Fri, 19 Oct 2001 10:46:27 -0700, "John Roth" wrote: > I saved it and looked at it, using Outlook Express. There is no text > between the header and the > first boundary delimiter. It appears that OE may be being overzealous > in its attempt to protect you from viruses - even though it says txt, > it still cautions me > that it may contain harmful stuff, and requires me to validate it. I'm afraid this is just another strange behaviour of OE (I don't want to call it bug :-) In fact, it seems a security feature, as OE under some circumstances executes