From cystem7 at hotmail.com Mon Feb 24 07:01:18 2003 From: cystem7 at hotmail.com (cystem7) Date: Mon, 24 Feb 2003 12:01:18 GMT Subject: newbie question: finding developers Message-ID: hi all! i think python and or C++ (wxwindows/wxpython) is the choice 4 my software (i'm not a programmer) how can i find someone -who can verify that? -who can make an estimate and a data model 4 that? thnx c7 (vienna/austria) From pedronis at bluewin.ch Mon Feb 10 18:13:38 2003 From: pedronis at bluewin.ch (Samuele Pedroni) Date: Tue, 11 Feb 2003 00:13:38 +0100 Subject: ternary operator vote References: <200302081710.h18HA2S03849@europa.research.att.com> <20030208171639.GA10283@panix.com> <2xR1a.22206$F25.5011@nwrddc02.gnilink.net> Message-ID: <3e4833a6_1@news.bluewin.ch> "James J. Besemer" ha scritto nel messaggio news:mailman.1044913129.2172.python-list at python.org... > > Aahz wrote: > > In article <2xR1a.22206$F25.5011 at nwrddc02.gnilink.net>, > > Raymond Hettinger wrote: > > > >>"James J. Besemer" wrote in message > >> > >>>I would humbly suggest that somebody other than Aahz control the > >>>voting. > >>> > >>>I don't know Aahz. I have no reason to doubt his integrity or expect > >>>him to cheat. Nevertheless, he has indicated considerable hostility > >>>towards the propsoal and this strikes me as inconsistent with the > >>>role. > >> > >>For someone like Aahz, strong convictions do not preclude fairness. > > > > > > Thank you. I appreciate the vote of confidence (and that applies to > > everyone else who's said similar things). > > It's not about trust. It's about avoiding the proverbial appearance of > impropriety. Psychological experiments have shown that bias can affect a > person's decision making even though the person is not conscious of the > influence. I think the vote should be controlled by a proponent of the PEP, > not an opponent. this is incosequential, then you had to find a neutral person. BTW if the debate will go on longer and longer people will just lose their lucidity. From essai1 at mci.local Tue Feb 11 19:17:23 2003 From: essai1 at mci.local (News M Claveau /Hamster-P) Date: Wed, 12 Feb 2003 01:17:23 +0100 Subject: Summary: Python.org as a multi-language portal (was: Some thoughts about Python, python.org and non-English languages) References: <018e01c2ced7$ec337140$0db607d5@A31> Message-ID: Bonsoir ! Je trouve cette initiative tr?s int?ressante (si j'ai bien tout compris). J'approuve. And, with Babel-fish : Good evening! I find this initiative very interesting (if I well understood all). I approve. @-salutations -- Michel Claveau From jsaul at gmx.de Thu Feb 13 06:04:07 2003 From: jsaul at gmx.de (jsaul) Date: Thu, 13 Feb 2003 12:04:07 +0100 Subject: float / double support in Python? In-Reply-To: References: <1T32a.10925$1q2.1049400@newsread2.prod.itd.earthlink.net> Message-ID: <20030213110407.GC671@jsaul.de> * Brandon Van Every [2003-02-12 02:30]: > > And yes, we should all use > > multibyte chars, because guess what, out of the about 6 billion > > people around only a fraction exclusively uses characters in the > > ascii range > > Then why is this newsgroup in English? Why is so much code written in > English? Would you be able to participate in this newsgroup if it were in anything other than english? Wherever people from all over the world communicate in a written language, it obviously makes little sense if everybody speaks in his/her native tongue. English has become the common denominator because of its extremely simple structure and grammatics, which makes it rather easy to learn; apart from some historical reasons. That doesn't mean that everyone everywhere is keen on adopting english as primary language; for most it is no more than *one* option. A useful one, no doubt, because this is the only way I can communicate with my colleagues in India, China or the US. Cheers, jsaul -- Palo pa'que aprenda que aqu? s? hay honor! [Rub?n Blades] From bokr at oz.net Wed Feb 12 17:16:53 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Feb 2003 22:16:53 GMT Subject: ternary operator vote References: <200302081710.h18HA2S03849@europa.research.att.com> Message-ID: On 12 Feb 2003 11:08:05 -0500, aahz at pythoncraft.com (Aahz) wrote: >In article , >Andrew Koenig wrote: >> >>Electionmethods.org argues at some length that allowing votes other >>than "yes" and "no" without otherwise changing the system does not >>make the system more fair in any useful sense. As an alternative, >>it proposes "Condorcet voting", which allows people to vote by >>rank ordering rather than just yes/no. > >While technically accurate, because this isn't *just* a vote in the >traditional sense, but more like a poll, I believe that using >YES/NO/ABSTAIN produces more information, so that people can vote for >proposals they like, against proposals they hate, and skip the others. +1 Regards, Bengt Richter From user at domain.invalid Wed Feb 19 10:28:32 2003 From: user at domain.invalid (user at domain.invalid) Date: Wed, 19 Feb 2003 17:28:32 +0200 Subject: sorting a dictionary References: Message-ID: <3E53A2A0.8090804@domain.invalid> Sean 'Shaleh' Perry wrote: > On Wednesday 19 February 2003 00:32, user at domain.invalid wrote: > >>Suppose I have dictionary (associative arry) with people's names and >>ages, like >> >> names = {"Bob":27, "Larry":35, "Curly":65, "Moe":66, "Jeff":31, >> "Guido":34, "Parrot":36} >> >>How can I sort this? And what does the method "names.keys().sort()" >>actually do? > > > the sort() method affects the list it is called on rather than create a copy. > In other words: > > foo = my_list.sort() # does not work > > This is why names.keys().sort() does not work. You have to use a temporary > variable. > > sorted_names = names.keys() > sorted_names.sort() > for name in sorted_names: > process(name) > Thanks, but what about the sorting of the dictionary. From gerrit at nl.linux.org Sun Feb 9 07:48:31 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Sun, 9 Feb 2003 13:48:31 +0100 Subject: Limitations to subclassing builtin types (FAQ 6.6) In-Reply-To: <20030209104608.GA3042@nl.linux.org> References: <20030208203415.GA5989@nl.linux.org> <200302090209.h19294jL026569@ratthing-b246.strakt.com> <20030209084918.GA2515@nl.linux.org> <20030209104608.GA3042@nl.linux.org> Message-ID: <20030209124831.GA3241@nl.linux.org> Gerrit Holl schreef op zondag 9 februari om 11:45:35 +0000: > Gerrit Holl schreef op zondag 9 februari om 09:48:41 +0000: > > Laura Creighton schreef op zondag 9 februari om 03:20:32 +0000: > > > Can you write up a better FAQ entry based on your experiences? > > I can describe the behaviour, but I can't describe why it behaves as such. > Yes I can, because I found the answer. I found it partially. I have written this FAQ entry. I'd appreciate it when someone could check it for errors, although most is copied from http://www.python.org/2.2/descrintro.html. Q: 6.6. Why can't I derive a class from built-in types (e.g. lists or files)? A: As of Python 2.2, you can derive from built-in types. It is restricted, however. * You can use multiple inheritance, but you can't multiply inherit from different built-in types (for example, you can't create a type that inherits from both the built-in dict and list types). This is a permanent restriction; it would require too many changes to Python's object implementation to lift it. However, you can create mix-in classes by inheriting from "object". This is a new built-in, naming the featureless base type of all built-in types under the new system. * When using multiple inheritance, you can mix classic classes and built-in types (or types derived from built-in types) in the list of base classes. (This is new in Python 2.2b2; in earlier versions you couldn't.) * Some types can't be subclassed: * Types with a fixed number of instances: BooleanType, EllipsisType, NoneType, NotImplementedType. * Callables: FunctionType, MethodType, ClassType, GeneratorType, and related * Internal types: CodeType, TracebackType, SliceType, FrameType * Further: BufferType, DictProxyType, XRangeType. More information on types, old and new, can be found at: http://www.python.org/2.2/descrintro.html http://www.python.org/doc/current/ref/types.html For previous versions, the answer is: This is caused by the relatively late addition of (user-defined) classes to the language -- the implementation framework doesn't easily allow it. See the answer to question 4.2 for a work-around. Remaining questions: * Why can't types with a fixed number of instances be subclassed? * Why can't callables be subclassed? * Why can't internal types be subclassed? * Why can't BufferType, DictProxyType and XRangeType be subclassed? Is the answer to these questions the same as with multiple inheritance, that 'it would require too many changes to Python's object implementation'? Although I wouldn't know when I'd _want_ to subclass any of these, it would be cool to understand... 28 >>> def f(): 28 ... gelukt = [] 28 ... mislukt = [] 28 ... for t in dir(types): 28 ... try: exec "class A(types.%s): pass" % t 28 ... except: mislukt.append(t) 28 ... else: gelukt.append(t) 28 ... return mislukt, gelukt 29 >>> f() (['BooleanType', 'BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', 'CodeType', 'DictProxyType', 'EllipsisType', 'FrameType', 'FunctionType', 'GeneratorType', 'InstanceType', 'LambdaType', 'MethodType', 'NoneType', 'SliceType', 'StringTypes', 'TracebackType', 'UnboundMethodType', 'XRangeType', '__builtins__', '__doc__', '__file__', '__name__'], ['ComplexType', 'DictType', 'DictionaryType', 'FileType', 'FloatType', 'IntType', 'ListType', 'LongType', 'ModuleType', 'ObjectType', 'StringType', 'TupleType', 'TypeType', 'UnicodeType']) yours, Gerrit. -- Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/ Het zijn tijden om je zelf met politiek te bemoeien: http://www.sp.nl/ From aleax at aleax.it Sun Feb 23 15:34:04 2003 From: aleax at aleax.it (Alex Martelli) Date: Sun, 23 Feb 2003 20:34:04 GMT Subject: Any tool to convert Python source code to HTML? References: Message-ID: <0fa6a.222439$0v.6240874@news1.tin.it> Aki Niimura wrote: > Hello everyone, > > I thought finding such was very easy but I couldn't find any pointer > in the Internet. I would like to put my Python code to my Intranet. > > Instead of putting a plain text, I would like to put a HTMLized code > (with keyword coloring, simple links to def, class, ...) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298 (most popular recipe currently in the Cookbook, apparently!) or for somewhat-richer functionality: http://www.norvig.com/python/py2html.html http://www.danbala.com/python/lpy/lpy.py.html and no doubt many others. Alex From BrenBarn at aol.com Sun Feb 23 00:38:47 2003 From: BrenBarn at aol.com (OKB (not okblacke)) Date: 23 Feb 2003 05:38:47 GMT Subject: Yet Another Case Question References: <3E584C41.54862DF3@alcyone.com> Message-ID: Erik Max Francis wrote: > Sure, people won't deliberately use bizarre choices of mixed case > except to deliberately prove a point, but it seems undeniable that > allowing case insensitivity _will_ result in different people using > different capitalization conventions. To use your example, some > will write `maximumcolumns', some will write `maximumColumns', and > some will write `MaximumColumns'. This is, needless to say, > obnoxious. I don't think you can really argue against this point, > since the case insensitive languages I've been exposed to one sees > it over and over again. But what is the negative effect, since regardless of which convention they use you will be able to refer to the variable with whatever capitalization you please? I don't see that this obnoxious at all. -- --OKB (not okblacke) "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From a.schmolck at gmx.net Tue Feb 25 12:07:22 2003 From: a.schmolck at gmx.net (Alexander Schmolck) Date: 25 Feb 2003 17:07:22 +0000 Subject: Underscore/Camelcase insensitivity References: <3E5749A2.D1399A4C@alcyone.com> Message-ID: Alex Martelli writes: > Alexander Schmolck wrote: > > > m.faassen at vet.uu.nl (Martijn Faassen) writes: > >> the camelCase convention. This week I was pondering making a mixin class > >> which helps us transition underscore to camelcase automatically. So, in a > >> way I was even serious here. > > > > I've actually discovered that converting from and to camelCase is really > > much more of a pain than you'd think (I might just be doing it stupidly). > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66009 > > I think I have a better solution in the way I expanded this recipe > in the printed Cookbook (seeing a mixedcase or underscored name as > a hidden sequence of underlying words, recovering the words, and > joining them up again by whatever convention is required). > > But both approaches break horribly for e.g HTTPBaseHandler, finding > it hard to gauge which of the caps are "breaks" in the word sequence > and which are not. Not impossible, I guess, just hard;-). Certainly not impossible: >>> camelSplit('HTTPBaseHandler') ['HTTP', 'base', 'handler'] # online cookbook recipe >>> cw2us('HTTPBaseHandler') 'http_base_handler' My code might be convoluted, but it certainly tries harder :) alex From nospampls.jlr at doctor.com Thu Feb 13 16:47:41 2003 From: nospampls.jlr at doctor.com (John La Rooy) Date: Fri, 14 Feb 2003 08:47:41 +1100 Subject: Python for small systems (ucLinux) References: <3e4a6f8b$0$148$a1866201@newsreader.visi.com> Message-ID: <20030214084741.6459e384.nospampls.jlr@doctor.com> On 12 Feb 2003 16:00:11 GMT grante at visi.com (Grant Edwards) wrote: > In article , David Brown wrote: > > > I am going to be writing an application that will run on a > > ucLinux system. It works mostly like a real Linux system > > (except there is no MMU, meaning no virtual memory and no > > protection between process' memory areas), but is a lot more > > limited in resources compared to most Linux systems - perhaps 4 > > MB Flash and 8 MB Ram in total. Does anyone know of projects > > using python in such limited systems? > > Once upon a time, there was a project called "deeply embedded > python" that was running Python on an embedded system (I don't > think there was any OS, but I don't recall). It ran in > something like a few hundred KB of memory. > > Here's a mailing list posting about it: > > http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html > > The URL in that posting doesn't work anymore, so it may take > some detective work to dig up more info. > > Somebody else has already pointed you towards the Palm stuff. > That's probably more current. > > -- > Grant Edwards grante Yow! With this weapon > at I can expose fictional > visi.com characters and bring about > sweeping reforms!! Try this link http://web.archive.org/web/20011005093720/www.abo.fi/~iporres/python/ Looks like the project might be dead though. Pity :( John From marklists at mceahern.com Tue Feb 11 19:10:44 2003 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 11 Feb 2003 18:10:44 -0600 Subject: Truly random numbers In-Reply-To: Message-ID: > [...] > it, convert it into binary and then do it what ever I want. Anyway, what > I need is a list of n groups of XXXX ( four digits ) numbers, and I > solved it through the list, but can I ( I know I can, but I don't know > how ) somehow generate this list from /dev/random? Does this work? #!/usr/bin/env python from __future__ import generators def random_characters(count, valid_characters): valid_characters = map(str, valid_characters) f = file('/dev/urandom') for x in xrange(count): while True: candidate = f.read(1) if candidate in valid_characters: yield candidate break for x in random_characters(10, range(10)): print x // m - From max at alcyone.com Sun Feb 9 20:08:53 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 09 Feb 2003 17:08:53 -0800 Subject: For review: PEP 308 - If-then-else expression References: Message-ID: <3E46FBA5.4E90DDC2@alcyone.com> Anthony Baxter wrote: > > We could then also have one for ints rather than bools: > > > > i -> [ v_0, v_1, v_2, ... ] > > which would pick v_i and evaluate that. > > On the other hand, I don't like this. If you need to do something like > this, why not just > > [ v_0, v_1, v_2, ... ][i] ? Lazy evaluation. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ Light ... more light! \__/ (the last words of Goethe) Bosskey.net / http://www.bosskey.net/ A personal guide to online multiplayer first person shooters. From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Wed Feb 26 17:41:09 2003 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Wed, 26 Feb 2003 23:41:09 +0100 Subject: transparent proxy object In-Reply-To: References: Message-ID: <3e5d429e$0$49117$e4fe514c@news.xs4all.nl> Alex A. Naanou wrote: > Task: > "transparently" intercept/cache all calls to the object, all its > attributes and sub-objects while maintaining full object > functionality. > > The Answer: > here is the answer I came up with, though it fits the task > semanticly and I like how it works in concept, the application is > rather time-critical thus this code does not fit the job... > does any one have an idea how to implement something with the same > semantics but more efficiently (I'm intrested in a pure Python > solution, not a C/C++ extention type)?? ...Thanks. > What about the code below? I snipped it from Pyro and stripped it a bit. Didn't do any comparison with your code, although yours looks a lot more complex than this one... Irmen de Jong ----- class DynamicProxy: def __init__(self, proxiedObject): # first set the list of 'local' attrs for __setattr__ self.__dict__["_local_attrs"] = ("_local_attrs", "_name", "_proxiedObject" ) self._proxiedObject=proxiedObject self._name=[] def _r_ga(self, attr, value=0): if value: self._name.append("_r_ga") else: self._name.append("_r_ha") return self.__invokeOriginal__(attr) def findattr(self, attr): return self._r_ga(attr) def __setattr__(self, attr, value): if attr in self.__dict__["_local_attrs"]: self.__dict__[attr]=value else: result = self.findattr(attr) if result==2: # attribute self._name.append("_r_sa") return self.__invokeOriginal__(attr,value) else: raise AttributeError('not an attribute') def __getattr__(self, attr): # allows it to be safely pickeled if attr != "__getinitargs__": result=self.findattr(attr) if result==1: # method self._name.append(attr) return self.__invokeOriginal__ elif result: return self._r_ga(attr, 1) raise AttributeError() def __invokeOriginal__(self, *vargs, **kargs): methodName=self._name.pop() if methodName=="_r_ha": try: attr = getattr(self._proxiedObject ,vargs[0]) if type(attr) in (UnboundMethodType, MethodType, BuiltinMethodType): return 1 # method except: pass return 2 # attribute elif methodName=="_r_ga": return getattr(self._proxiedObject, vargs[0]) elif methodName=="_r_sa": return setattr(self._proxiedObject, vargs[0], vargs[1]) method = getattr(self._proxiedObject, methodName ) return apply(method, vargs, kargs) # test class Test: def __init__(self): print "init from test" self.attribute = 42 def method(self, arg): print "method in test, arg=",arg return "result from test method!!!" def setAttribute(self, value): self.attribute=value object = Test() proxy = DynamicProxy(object) print "Calling method:" print proxy.method("the arguments") print "Printing attribute:" print proxy.attribute print "Setting attribute with method" proxy.setAttribute(99) print "Printing attribute:" print proxy.attribute print "Setting attribute directly" proxy.attribute=555 print "Printing attribute:" print proxy.attribute print "Printing original attribute:" print object.attribute From dfan at dfan.org Tue Feb 11 13:59:42 2003 From: dfan at dfan.org (Dan Schmidt) Date: Tue, 11 Feb 2003 13:59:42 -0500 Subject: Voting for PEP 308 References: <200302071714.h17HEew09033@odiug.zope.com> <3E4544F9.4011E0AB@alcyone.com> <3E461162.BC849E8F@alcyone.com> <200302091044.h19AiojL000448@ratthing-b246.strakt.com> <3E480D93.8030105@cascade-sys.com> Message-ID: Hans Nowak writes: | Hmm, what if bools grew an if() method? We could then write: | | z = (x == y).if(whentrue, whenfalse) | | This strikes me as much more elegant than the other proposals. | | (ducking for cover, etc :-) You joke, but that's basically what Smalltalk does. Dan -- http://www.dfan.org From tismer at tismer.com Mon Feb 24 21:47:26 2003 From: tismer at tismer.com (Christian Tismer) Date: Tue, 25 Feb 2003 03:47:26 +0100 Subject: declaration of variables? In-Reply-To: References: <7xu1f324ew.fsf@ruckus.brouhaha.com> Message-ID: <3E5AD93E.9000701@tismer.com> jcm wrote: ... > And these unit tests are likely written in Python, and have the same > quirks as the programs they're testing. You sound like you've never written a unit test in your life, otherwise you would not move yourself in such a questionable corner. Unit tests are so much easier to test than your application, and proving a program to be wrong is so much easier than to prove it being right! > Certainly tests are extremely useful, although if you're script is > small/simple enough, I think it's reasonable to go without. Please show me code that doesn't need unit tests. Either is is smaller than 100 lines, or it has bugs in its first implementation. Try to prove me wrong, without cheating! -- chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From pyth at devel.trillke.net Mon Feb 10 20:22:51 2003 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 11 Feb 2003 02:22:51 +0100 Subject: PEP 308: Alternative conditional operator forms In-Reply-To: <3E484B41.ED0EBC85@alcyone.com>; from max@alcyone.com on Mon, Feb 10, 2003 at 05:00:49PM -0800 References: <3E46F0CE.5675E180@alcyone.com> <3e470163.1200420398@News.CIS.DFN.DE> <8kjjh-mq3.ln1@beastie.ix.netcom.com> <3e473678.1214011033@News.CIS.DFN.DE> <3E473E44.3F7EF4CC@alcyone.com> <3E484B41.ED0EBC85@alcyone.com> Message-ID: <20030211022251.X1706@prim.han.de> Erik Max Francis wrote: > John Roth wrote: > > > Because you've got a major ambiguity if the statement begins > > with an "if". That comment is in the PEP. > > It's only an ambiguity if you insist that the two forms meet in the > middle. There's no reason to make this happen; simply keep things as > is, where an `if' keyword starting a statement always means an if > statement. Thus > > if C: x else: y > > as a standalone statement is SyntaxError (perhaps with a slightly more > helpful message attached). If you really wanted the conditional > operator, surround it in parentheses. > > No ambiguity, since an if statement cannot possibly be preceded by an > open parenthesis. It only involves additions to the grammar, no > changes. Not true but Andrew Koenig (probably) found a way to make this happen (changing the grammar and adding to it). holger From cribeiro at mail.inet.com.br Mon Feb 3 20:57:14 2003 From: cribeiro at mail.inet.com.br (Carlos Ribeiro) Date: Tue, 4 Feb 2003 01:57:14 +0000 Subject: Python's 8-bit cleanness deprecated? In-Reply-To: <002f01c2cbbf$6b73abd0$21795418@dell1700> References: <002f01c2cbbf$6b73abd0$21795418@dell1700> Message-ID: <200302040157.14767.cribeiro@mail.inet.com.br> On Monday 03 February 2003 08:04 pm, Brian Quinlan wrote: > The effort required to do that doesn't strike me as significant. How > many total source files do you have that have non-ASCII characters in > them? For me it's rather extreme - I doubt I have a single source file *without* non-ASCII characters. I heavily document my code, mostly in Portuguese, and using the Latin-1 encoding most of the time. BTW, it's interesting that I just replied to a related question regarding the CSV API. As a brazilian, I'm not only Latin-1 bound - we also use d/m/y dates and comma as decimal separators. Carlos Ribeiro From rjones at ekit-inc.com Fri Feb 7 22:03:04 2003 From: rjones at ekit-inc.com (Richard Jones) Date: Sat, 8 Feb 2003 14:03:04 +1100 Subject: For review: PEP 308 - If-then-else expression In-Reply-To: <200302080251.17984.cribeiro@mail.inet.com.br> References: <200302080251.17984.cribeiro@mail.inet.com.br> Message-ID: <200302081403.04323.rjones@ekit-inc.com> On Sat, 8 Feb 2003 1:51 pm, Carlos Ribeiro wrote: > On Saturday 08 February 2003 02:32 am, Andrew Koenig wrote: > > Carlos> I don't think that the code above is much clearer than the > > Carlos> one-liner with the ternary operator. > > > > My experience is that when people say "x is much clearer than y", > > what they are really saying is often "x is more familiar than y". > > I fully agree with you - in fact, I think that most people that reacted > today (tonight?) against the PEP are just reacting because the new syntax > is not familiar to them, and the step-by-step evaluation is. Not at all. I believe the opposing reactions are far more varied and far deeper than the superficial theory you're pushing here. The main concerns I see are: 1. Python already has the required functionality, just in another form (ie. not as an expression, but as a statement) 2. A lot of people have a real problem with the "value is this.... er, except when it's not and then it's this" ... ie. when quickly parsing the code, the value appears to be one thing, but then you're presented with a test which indicates that it may not - the code "branches" _after_ you've specified the value that may or may not be the result of the expression. The statement form of "if/elif/else" is much clearer - you do the test first, and the results of the test are perfectly clear. Nothing to do with the new expression syntax not being familiar, or comfortable. Richard From mwh at python.net Mon Feb 10 05:10:50 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 10 Feb 2003 10:10:50 GMT Subject: For review: PEP 308 - If-then-else expression References: <9r1a4vo45egeuavsgqe2pd9p1dcoqammus@4ax.com> <7h3el6i21id.fsf@pc150.maths.bris.ac.uk> <7x3cmyttn6.fsf@ruckus.brouhaha.com> Message-ID: <7h3vfzszbug.fsf@pc150.maths.bris.ac.uk> Paul Rubin writes: > Michael Hudson writes: > > An example: > > > > def get_arg(self, default=1): > > """Return any prefix argument that the user has supplied, > > returning `default' if there is None. `default' defaults > > (groan) to 1.""" > > if self.arg is None: > > return default > > else: > > return self.arg > > > > could become > > > > def get_arg(self, default=1): > > """Return any prefix argument that the user has supplied, > > returning `default' if there is None. `default' defaults > > (groan) to 1.""" > > return default if self.arg is None else self.arg > > > > Is that an improvement? *I* certainly don't think so. The original > > has all these wonderful visual cues about what's going on (colons at > > end of lines and indentation being the key two). The second just has > > a stream of name-like tokens. It looks better when syntax hilighted, > > but only slightly. > > Think of how you actually call get_arg: > > a = x.get_arg() > > In order to read that line you have to actually go check the > definition of get_arg. No, you have to know what get_arg() does. > The conditional expression (maybe) simplifies your code, not by > shortening the get_arg function, but by eliminating it. You'd > instead say > > a = self.arg if (self.arg is not None) else 1 > > or whatever. I posted out of context so you weren't to know this, but: no! In this case get_arg() is a (one) conceptual feature; it is also (only, I think) called from outside the class that defines it. > Maybe that syntax is clumsy but it still seems preferable to having > to scroll to some method definition several screens away in order to > find a 4-line function definition that needs 3 lines of > documentation to explain what it's doing. In this case, I really don't think so. Cheers, M. -- > Touche! But this confirms you are composed of logic gates. Crud, I thought those were neurons in there. -- Thomas F. Burdick, Kenny Tilton, comp.lang.lisp From maxm at mxm.dk Mon Feb 10 06:38:04 2003 From: maxm at mxm.dk (Max M) Date: Mon, 10 Feb 2003 12:38:04 +0100 Subject: I wrote a Java implementation of Zope Page Templates (ZPT) In-Reply-To: <80ef91b8.0302100238.35a46f4a@posting.google.com> References: <80ef91b8.0302100238.35a46f4a@posting.google.com> Message-ID: <3E478F1C.9030605@mxm.dk> Stefano Masini wrote: > The implementation is not 100% complete with respect to the specs, but > I tried to stay compliant. So far TAL is complete, TALES has path:, > not: and string:. Mhmm... I just realized I forgot exists:... that > must be because it's not in the specs. I guess I'm gonna implement it > right now then, it'll just take a few minutes at this point. METAL is > not implemented at all, and I'm not planning on supporting any java: > type in TALES, for now. It is great that Page Templates are being spread to more languages. But metal is probably the most important part of the spec. This is what makes it possible to have a site-wide layout, with only a few templates. Page Templates without metal is like python without functions. -- hilsen/regards Max M Rasmussen, Denmark http://www.futureport.dk/ Fremtiden, videnskab, skeptiscisme og transhumanisme From piet at cs.uu.nl Sun Feb 23 10:51:17 2003 From: piet at cs.uu.nl (Piet van Oostrum) Date: 23 Feb 2003 16:51:17 +0100 Subject: Case sensitivity References: <20030218122244.GA2396@nl.linux.org> Message-ID: >>>>> Dennis Lee Bieber (DLB) wrote: DLB> in which the only thing differentiating the loop from the assignment is DLB> the "," vs "."... Makes for ugly parsing as no matter which choice is DLB> the default path, the other path requires massive backtracking: (loop DLB> favored: token do, token 10, token i, token = token 2, token . DLB> back up and combine do 10 i into one token) IIRC, it's just a simple scan. There is only a problem if it contains an = sign (outside of string), and then if later it contains a comma outside of parentheses (and outside of string), it could be a DO, otherwise it is an assignment. As you would have to count parentheses it can't just be done with a regexp. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From cx at cx.hu Thu Feb 27 19:06:40 2003 From: cx at cx.hu (Ferenczi Viktor) Date: Fri, 28 Feb 2003 01:06:40 +0100 Subject: PEP 308: then else Message-ID: <000901c2debd$4cacbf50$8800a8c0@Sirius> I often need inlined conditions when defining class attributes to give a default value for something. Sometimes workarounds must be implemented to give similar functionality as an inlined conditional. A conditional function is used to implement this, but it has hard to debug side-effects and severally decreases application efficiency in some cases. I had to implement classes or use ugly lambdas as a workaround, but they are not an elegant solution. I've read PEP 308 and found the condition then 'true' else 'false' syntax very simple and elegant. Let's analyse the possibility of ambiguous syntax: c1 then (c2 then t2 else f2) else (c3 then t3 else f3) can be written without ambiguity as: c1 then c2 then t2 else f2 else c3 then t3 else f3 There is no ambiguity, because an else statement always persent for each then statement. The later syntax is hard to understand. For example: a then b then c else d else e then f else g - "What's this?" ;-) One inline condition should be written without parenthesis: r = c then t else f Nested inline conditions should be placed in parenthesis to ensure readability: r = c1 then (c2 then t2 else f2) else (c3 then t3 else f3) In my opinion the language syntax should not force the parenthesis, but they are strongly recommended in the nested case. With correctly placed ( ) pairs inline conditions are not harder to read and not more "COBOL like" than a list comprehension. -Viktor- From adalke at mindspring.com Tue Feb 11 14:15:09 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 11 Feb 2003 12:15:09 -0700 Subject: For review: PEP 308 - If-then-else expression References: <3E45FED3.5D76CCFF@alcyone.com> <3e471677_2@news.bluewin.ch> <7xznp49639.fsf@ruckus.brouhaha.com> <3e471d1b$1_4@news.bluewin.ch> <7x8ywon3r6.fsf@ruckus.brouhaha.com> <3E473696.87B0E92B@alcyone.com> <3cmv52n1.fsf@morpheus.demon.co.uk> <3E487675.DD5DDE7A@alcyone.com> Message-ID: Erik Max Francis: > Obviously, but if you come to rely on the idiom, it's easy to forget > that it doesn't work properly if x is false. As we've seen from Andrew > Koenig's example of an _improper_ use of this construct in the standard > library. Though as others have pointed out as well, I've found improper use of quite a few things in the library, and filed bug reports against them and patches. Does that mean we need a new syntax for all of those? No, I don't think so. Andrew dalke at dalkescientific.com From vze4rx4y at verizon.net Mon Feb 10 12:43:26 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Mon, 10 Feb 2003 17:43:26 GMT Subject: ternary operator vote References: <200302081710.h18HA2S03849@europa.research.att.com> <20030208171639.GA10283@panix.com> Message-ID: <2xR1a.22206$F25.5011@nwrddc02.gnilink.net> "James J. Besemer" wrote in message > I would humbly suggest that somebody other than Aahz control the voting. > > I don't know Aahz. I have no reason to doubt his integrity or expect him to > cheat. Nevertheless, he has indicated considerable hostility towards the > propsoal and this strikes me as inconsistent with the role. For someone like Aahz, strong convictions do not preclude fairness. Raymond Hettinger From lac at strakt.com Sat Feb 8 04:20:24 2003 From: lac at strakt.com (Laura Creighton) Date: Sat, 08 Feb 2003 10:20:24 +0100 Subject: The 3D picture of Python In-Reply-To: Message from "Brandon Van Every" of "Sat, 08 Feb 2003 08:13:17 GMT." References: Message-ID: <200302080920.h189KOjL023038@ratthing-b246.strakt.com> > Richard Jones wrote: > > On Sat, 8 Feb 2003 1:55 pm, Brandon Van Every wrote: > > > >> - Python itself is rather piggish in that it doesn't have 4-byte > >> floats, and pads 8-byte doubles with an extra 8 bytes of Python > >> object overhead. > > > > Again with abusive language like "piggish". You're really not big on > > the social skills, are ya pal? > > Christ, Richard, I've not met anyone in 10 years of Usenetting who's so > touchy about choice of words. It is a trademark around here. We are trying to produce an envirornment where the shiest, most delicate novice will feel comfortable asking questions, even questions that are _really_ _stupid_. So we worry a lot about whether certain postings carry with it the message 'only the tough need post here'. We want 'gentle' even though it is a hard, often unattainable goal. Laura From grante at visi.com Wed Feb 5 18:52:57 2003 From: grante at visi.com (Grant Edwards) Date: 05 Feb 2003 23:52:57 GMT Subject: 3D graphics programmers using Python? References: <3e419a1c$0$153$a1866201@newsreader.visi.com> <3e41a115.31178362@news.pa.comcast.giganews.com> Message-ID: <3e41a3d9$0$187$a1866201@newsreader.visi.com> In article <3e41a115.31178362 at news.pa.comcast.giganews.com>, Sol Rosenberg wrote: [fixing top posting...] >>> A one-off has no economy of scale. 30 seconds vs. 1 minute, >>> who cares? It only pays off if you're doing that kind of >>> problem lotsa times. >> >>How many professional programmers do you know who only write >>one program in their lifetimes? Sure, saving 50% on a single >>program may not seem like much, but I've written thousands and >>thousands of programs over the years. It adds up. > > The quote "If all you have is a hammer everything looks like a > nail" seems to apply here. Why is that? Choose the tool that gets the job done the most quickly. In my experience that is often Python. -- Grant Edwards grante Yow! One FISHWICH coming at up!! visi.com From aleax at aleax.it Fri Feb 21 15:11:44 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 21 Feb 2003 20:11:44 GMT Subject: Can Python work for me? References: <13c3ff37.0302181730.578559f9@posting.google.com> Message-ID: <4Kv5a.289466$AA2.10970683@news2.tin.it> Steven Taschuk wrote: > Quoth Alex Martelli: >> Adam Rumpke wrote: > [...] >> > FOR EXAMPLE: If I want to print and the printer is jammed a user at >> > home will need to know the printer is not working. I would like the >> > system to send a message via >> > the browser with out the browser constantly reloading. Could Python do >> > this? >> >> It doesn't matter much what language you use on the server-side >> for this: you want to do something outside the parameters of the >> HTTP protocol, which is based on request/response, i.e. have the >> server "initiate" something [...] > > Well, you could run a special-purpose HTTP server on the client > machine, and have the print server send HTTP POSTs to that server > to inform it of job status, etc.. That's "inside" HTTP, in a > certain sense. But the browser (specified by the OP) would STILL have to be constantly reloading: even though the constant reloading would be from a special-purpose server rather than from a general one, it still would violate the specs. > (Not to dispute your point that a vanilla browser and server can't > do this without polling.) It doesn't matter if the server is mocha fudge. If by "the browser" the OP (as presumably he does) means a "vanilla browser", i.e. one that implements HTTP and a few other traditional protocols such as FTP, the server cannot "send a message via the browser" without the browser periodically polling. "Push" (server taking the initiative of sending a message) is not part of today's HTTP. Alex From tjreedy at udel.edu Tue Feb 11 23:01:32 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Feb 2003 23:01:32 -0500 Subject: PEP-308 a "simplicity-first" alternative References: Message-ID: "David LeBlanc" wrote in message news:mailman.1045005487.14624.python-list at python.org... > ternary op as ? : +1 Having come to Python from C, I would not mind the C form either. But I have the impression that Guido has vetoed that, and many other do not like it either. > any other form: -1 So you would prefer that I and other users of and/or stick with that instead of switching to, for instance, and/else? That *is* what 'no change' means. Terry J. Reedy From logistix at zworg.com Tue Feb 18 17:44:47 2003 From: logistix at zworg.com (logistix) Date: 18 Feb 2003 14:44:47 -0800 Subject: More about Debugging Unahndled Exceptions References: Message-ID: "Lexy Zhitenev" wrote in message news:... > I've read http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287. > Very interesting material. I don't want to look through PEPs or post mine. > > How about including some basic features into Python itself? > > I develop my Python programs in PythonWin. Most of them are graphical. They > use wxPython. The problem is that I simply _can't_ debug such GUI programs. > PythonWin dies with 'Unhandled exception la-la-la'. I write something, then > run the program in the console, watch the printed exceptions, place 'print > var' in the source code, run the program several times, place 'print var' in > other places and when I find the mistake, delete prints, forget them in > other places and so on... > > Debugging is hard... > If you're running pythonwin, won't "import pywin.debugger;pywin.debugger.set_trace();" in your program throw you into debug mode? Don't know how it'll interact with wxWindows though. From tismer at tismer.com Thu Feb 13 22:17:17 2003 From: tismer at tismer.com (Christian Tismer) Date: Fri, 14 Feb 2003 04:17:17 +0100 Subject: PEP 308: "then" "else" for deprecating "and" "or" side effects Message-ID: <3E4C5FBD.2070309@tismer.com> Dear community, there has been some favor of my silly/simple a then b else c proposal. Please let me elaborate a little on this, with respect to the existing "and" and "or operators. "and" and "or" are two-headed beasts: At first glance, they pretend to be logical operators. At second inspection, they do this logic by promoting one of their operands. This is not obviously bad, and it is consistant with the logic. Due to the presence of a real boolean type, we should ask ourselves if "and" and "or" shouldn't be deprecated in their current meaning, towards being "boolean only"? I think it would be nicer if "and" and "or" would only produce true or false. But this would break lots of code. Therefore, I propose to keep them as they are, but to deprecate using them to carry their operand values instead of a true truth value. This would be still allowed, but there are new, more explicit operators, which should be used instead for new Python code: The binary operators "then" and "else". The ternary operator "then else". For a clear definition, see the function definitions below. Example: Parameter cleanup. Parameters are often massaged like this: "or" case: arg = arg or "Default" The meaning of this phrase is: "If the user has provided no argument value that is true (non-empty or not 0 most of the time), then provide some default value". arg = arg then arg else "Default" would be the verbose ternary replacement of this. A short replacement would read better: arg = arg else "Default" which means "If arg is false, replace it by 'Default'". "and" case: arg = arg and 42 The meaning of this phrase is: "If the user provided any argument that is true, use some default value". arg = arg then 42 else arg would be the verbose replacement of this. A short replacement would read better: arg = arg then 42 Summary: -------- "and" and "or" are behaving like logical operators. They happen to do this by not providing a plain truth value, but by promoting one of their operands. "and" and "or" are valid operators, when used in a logical context, only, meaning only to use the truth value. They have the side effect of carrying an operand, which I regard as a design flaw, but this is bearable when used properly. Using "and" and "or", when they are meant as "then" or "else" should be deprectaed as bad style in the long term. Almost all instances of "and" and "or" used to carry a value can be replaced by "then" or "else" with ease, which makes the resulting code much more readable without prior knowledge. "and" and "or" do have a builtin perception of symmetry, which is not related to the truth, and hard to explain to newcomers. Therefore, I propose to deprecate their use to promote a value, and I propose to introduce "then" and "else" as dual operators, together with the "then else" pair as ternary operator, to be used in any context where the inquiry should promote the right operand without evaluating its truth value. Definition: ----------- Here is my "cure" to "and" and "or" with side-effects: a then b -------- is equivalent to def then_proc(a, b): if a: return b else: return a a else b -------- is equivalent to def else_proc(a, b): if a: return a else: return b a then b else c --------------- is equivalent to def then_else_proc(a, b, c): if a: return b else: return c "and" and "or" should be replaced by the above constructs, in all contexts where "and" and "or" are not pure logical, but are meant to propagate specific values, for all new code. kind regards -- chris p.s.: Please correct me positively, if I made a mistake at 4:15am -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From exarkun at intarweb.us Mon Feb 17 11:57:22 2003 From: exarkun at intarweb.us (Jp Calderone) Date: Mon, 17 Feb 2003 11:57:22 -0500 Subject: PEP 308: I liked the original proposal better In-Reply-To: References: <10F0E58C0018054484E329DC494C4D7F01ADF2@mexper1> Message-ID: <20030217165722.GA5893@meson.dyndns.org> On Mon, Feb 17, 2003 at 09:08:24AM -0500, Mel Wilson wrote: > [snip] > > Hmm.. well then.. arithmetic expressions haven't run left-to-right > since the days of FORTRAN: > > a + b * c + d > > has to run inside-out, and with the Python extensions > > 'oh' * 4 + 3 * 'my' > > will die a horrible death unless it's run outside-in > You don't understand (intentionally or un-). >>> def function(argument): ... print 'rar, ', argument, ' is evaluated!' ... return argument >>> function('oh') * function(4) + function(3) * function('my') rar, oh is evaluated! rar, 4 is evaluated! rar, 3 is evaluated! rar, my is evaluated! See? Jp -- #!/bin/bash ( LIST=(~/.netscape/sigs/*.sig) cat ${LIST[$(($RANDOM % ${#LIST[*]}))]} echo --$'\n' `uptime` ) > ~/.netscape/.signature -- up 8 days, 20:28, 2 users, load average: 0.12, 0.13, 0.09 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From dave at pythonapocrypha.com Tue Feb 18 18:28:26 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Tue, 18 Feb 2003 15:28:26 -0800 (PST) Subject: interacting with gui-based programs In-Reply-To: References: Message-ID: On Tue, 18 Feb 2003, Jeff wrote: > I'd like to use Python to automate my interactions with graphical user > interfaces, such as those of Mozilla and Kazaa (running with Wine). Is > this possible? Are there libraries that can help with this kind of > thing? Google for AutoIt. It's not Python, but it does have an Active/X interface, which I'm using via Mark Hammond's win32com package. Not sure how well any of that stuff works under Wine though. Actually, if you go to Google groups you can search for AutoIt on c.l.py - somebody mentioned it several months back and IIRC posted a snippet of code on how to use it. -Dave From bokr at oz.net Wed Feb 12 21:31:46 2003 From: bokr at oz.net (Bengt Richter) Date: 13 Feb 2003 02:31:46 GMT Subject: PEP-308 a "simplicity-first" alternative References: <200302071714.h17HEew09033@odiug.zope.com> <7xr8aenyj1.fsf@ruckus.brouhaha.com> <7xof5icfpy.fsf@ruckus.brouhaha.com> <3E4AF9F2.B1C5ACE1@alcyone.com> Message-ID: On Wed, 12 Feb 2003 17:50:42 -0800, Erik Max Francis wrote: >Bengt Richter wrote: > >> My fix is >> x and {y} or z >> >> meaning y is treated as True in logical expression context, but >> retains its value for purposes of the expression value. > >And, as I've pointed out through these threads, I think that cure is >worse than the disease. > "That cure" hasn't been presented before AFAIK, so how can you have pointed out anything about it before? Unless you are looking at it through special-ternary-syntax-colored goggles, and aren't seeing what it actually does. It is _not_ a ternary syntax. {x} is an expression all by itself, just as [x] is, except that all it does is guarantee that {x} will be seen as true in any logical expression context. It just happens to be usable to fix the hole in the old ternary idiom. IMO it's a good substitute for using a list to guarantee a true term, as in (x and [y] or [z])[0] Of course, if you intensely dislike the old x and y or z idiom, making it bullet proof will not particularly please you ;-) OTOH, others have pointed out that the old idiom has seen considerable use in the libraries, so maybe a 2-character bulletproofing is not such a bad idea? Does x and {y} or {z} read better as making the two choices easily identifiable? ({} is optional on the second term). Give it another thought ;-) Regards, Bengt Richter From gtalvola at nameconnector.com Thu Feb 27 16:06:00 2003 From: gtalvola at nameconnector.com (Geoffrey Talvola) Date: Thu, 27 Feb 2003 16:06:00 -0500 Subject: Just for fun - PickleRPC Message-ID: <61957B071FF421419E567A28A45C7FE54011B5@mailbox.nameconnector.com> Webware has its own protocol called PickleRPC, probably very similar to what you've written. You might be interested to compare and contrast. Here are links to the relevant source files if you're interested: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/webware/Webware/Mi scUtils/PickleRPC.py?rev=HEAD http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/webware/Webware/We bKit/PickleRPCServlet.py?rev=HEAD http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/webware/Webware/We bKit/Examples/PickleRPCExample.py?rev=HEAD - Geoff Skip Montanaro [mailto:skip at pobox.com] wrote: > Trying to speed up a simple client/server application in the > spambayes world > I decided to try replacing XML-RPC with a simpler protocol. > I wound up with > an RPC protocol running over raw sockets which uses pickle as the > serialization format. If you're curious about it, you can > see PickleRPC and > a simple client/server pair here: > > http://manatee.mojam.com/~skip/python/PickleRPC.py > http://manatee.mojam.com/~skip/python/hammiesrv.py > http://manatee.mojam.com/~skip/python/hammiecli.py > > Unless you are running the spambayes stuff already you won't > actually be > able to run hammiesrv or hammiecli. Still, they demonstrate > how easy it can > be to create an RPC server - four lines for the server, three for the > client, including imports. PickleRPC.py itself is less than > 100 lines of > Python. > > I'm sure this is just a toy - no real competition for xmlrpc, > pyro or other > packages of that ilk, but it seems to work okay to the extent > I've tested > it. > > Skip From pyxis at iol.it Sun Feb 16 15:50:26 2003 From: pyxis at iol.it (=?iso-8859-1?Q?pyxis@iol.it?=) Date: Sun, 16 Feb 2003 21:50:26 +0100 Subject: =?iso-8859-1?Q?Calling_a_Windows_dll_(with_pointers_parameters)_with_calldll?= Message-ID: Here is the code I used to call a Windows dll like that """void FAR PASCAL hllapi(int FAR *, char FAR *, int FAR *, int FAR *)""" with calldll (http://www.nightmare.com/software.html). For me, without documentation, calling a windows dll who needs pointers was a nightmare. And then I'd like to show you the code (may this 'll be useful to you). PS Yes, I know there is ctypes (http://starship.python.net/crew/theller/ctypes.html) but with ctypes it's too easy to do ;-) # PROGRAM NAME : HLLAPI interface - calldll version # Author: Stefano Spinucci # Written: 2002/02/16 # DESCRIPTION # This program interface the 3270 HLLAPI library of an Italian 3270 emulator using # the calldll library (from Sam Rushing http://www.nightmare.com/software.html) # I've found very useful also edll.py from http://pages.ccapcable.com/lac/undergroundPython.html # The calling scheme for the function is : # void FAR PASCAL hllapi(int FAR *, char FAR *, int FAR *, int FAR *); # ------------------------------------------------------------------------------------------------ # Function defining : # - myPrintLong : given a membuf with a long inside, print the long # - myPrintString : given a membuf with a string inside, print the string # - mySetLong : given a membuf with a long inside len (4), set his value with the long passed # ------------------------------------------------------------------------------------------------ def myPrintLong(vVar): #Print the long (first way) a= struct.unpack('I', vVar.read())[0] print a #Print the long (second way) print calldll.read_long(vVar.address()) def myPrintString(vVar): #Print the string (first way) a = vVar.read() print a[:len(a)-1] print len(a) #Print the string (second way) a = calldll.read_string(vVar.address()) print a print len(a) def mySetLong(vMemBuf, vValueToSet): string_packed = struct.pack("L",vValueToSet) # packed as unsigned long vMemBuf.write(string_packed) def mySetString(vMemBuf, vValueToSet): data_len = len(vValueToSet) pack_format = str(data_len+1)+"s" # add one for \0 at the end. string_packed = struct.pack(pack_format, vValueToSet) # pack() will add \0 for us vMemBuf.write(string_packed) # ------------------------------------------------------------------------------------------------ # Import the required library # ------------------------------------------------------------------------------------------------ #Import the calldll module import calldll #Import the struct module (a standard python module) import struct # ------------------------------------------------------------------------------------------------ # Get the handle of the dll and the address of the function # ------------------------------------------------------------------------------------------------ #Get the handle of the Dll handle = calldll.load_library ('C:\Tee3270\Ehllap32') #Get the address of the function address = calldll.get_proc_address (handle, 'HLLAPI') # ------------------------------------------------------------------------------------------------ # Initialization # ------------------------------------------------------------------------------------------------ # vFunction, vTextLen and vResult are defined as a membuf with lenght = 4, because 4 is the lenght # of an unsigned long packed with struct.pack("L", NumberToPack) vFunction = calldll.membuf(4) vTextLen = calldll.membuf(4) vResult = calldll.membuf(4) # vFunction is defined as a membuf with lenght = 1921 because the dll needs a buffer of # 1920 char + 1 for \0 at the end vText = calldll.membuf(1921) # ------------------------------------------------------------------------------------------------ # Function calling # ------------------------------------------------------------------------------------------------ # Vars setting #1 mySetLong(vFunction, 1) #2 string_value_to_write = 'A' mySetString(vText, string_value_to_write) #3 mySetLong(vTextLen, len(string_value_to_write)) #4 mySetLong(vResult, 1) #Call the function calldll.call_foreign_function ( address, 'llll', 'l', (vFunction.address(), vText.address(), vTextLen.address(), vResult.address()) ) myPrintLong(vResult) myPrintString(vText) # ------------------------------------------------------------------------------------------------ # Dll unloading # ------------------------------------------------------------------------------------------------ #Unload the dll calldll.free_library (handle) From pedronis at bluewin.ch Sun Feb 9 22:45:33 2003 From: pedronis at bluewin.ch (Samuele Pedroni) Date: Mon, 10 Feb 2003 04:45:33 +0100 Subject: For review: PEP 308 - If-then-else expression References: <9r1a4vo45egeuavsgqe2pd9p1dcoqammus@4ax.com> <3e471606$1_2@news.bluewin.ch> <3e471eb4_4@news.bluewin.ch> <3E472087.4793DC71@alcyone.com> Message-ID: <3e4721d8_1@news.bluewin.ch> "Erik Max Francis" ha scritto nel messaggio news:3E472087.4793DC71 at alcyone.com... > Samuele Pedroni wrote: > > > Aside that: too much punctuation. > > So is there too much punctuation in if...else statements? I guess I'm > not getting this objection. statements are not expressions. For example the : in else: is absolutely spurious for the expression case. From max at alcyone.com Sat Feb 8 15:56:19 2003 From: max at alcyone.com (Erik Max Francis) Date: Sat, 08 Feb 2003 12:56:19 -0800 Subject: Defending the ternary operator References: <61957.200.225.212.17.1044678362.squirrel@correio.seven.com.br> <200302080701.h18719jL022300@ratthing-b246.strakt.com> <1044691096.761.2945.camel@lothlorien> <7xfzqzm4w4.fsf@ruckus.brouhaha.com> Message-ID: <3E456EF3.4000DCC3@alcyone.com> Alexander Schmolck wrote: > True. Still, that doesn't mean that allowing further grammatically > distinct > "if"s wouldn't have a negative impact. The list comprehension "if" at > least is > quite limited: there is no "else" part, you can't chain it and it > occurs in a > fairly narrow context. Introducing an "if" expression would almost > certainly > increase the impact: > > if ...: > y = [i if ... else ... for i if i ...] if ... else ... Yep, language features can be abused. That's true for any language feature in any language. I don't find it a compelling argument, especially in this case where the construct being proposed has the opportunity make code _more_ clear and concise when used properly, not less. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ Lawyers, I suppose, were children once. \__/ Charles Lamb The laws list / http://www.alcyone.com/max/physics/laws/ Laws, rules, principles, effects, paradoxes, etc. in physics. From tr at jotsite.com Mon Feb 24 09:19:36 2003 From: tr at jotsite.com (Hoang) Date: Mon, 24 Feb 2003 14:19:36 GMT Subject: wxTree control in Boa Message-ID: does anyone have a most simplistic example of a treeview control in the Boa framework that includes displaying of icons, the + or - sign during expansion and collapse? I've gotten the control to work but the visual aspects aren't there. The Boa Explorer has that feature and I was looking into the code to see that. However, I am still a novice at Python and there is just too much code in Explorer.py and ExplorerNodes.py. I'm sure someone must have fumbled through this while trying out Boa. thanks From aka at mvps.org Fri Feb 14 14:44:29 2003 From: aka at mvps.org (Alex K. Angelopoulos) Date: Fri, 14 Feb 2003 14:44:29 -0500 Subject: Reboot windows when nobody logged in References: Message-ID: In news:Pine.LNX.4.44.0302140755490.18107-100000 at x.opf.slu.cz, Lukas Kubin typed: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Thank you for your reply. > My code works fine when anybody is logged on. But it doesn't when there's > the login window of Novell. Then I send the signal, nothing happens; I log > in or just (!) press Esc and it reboots. > I know almost nothing about Windows programming. So WMI says nothing to > me. Could you please let me know more about it? How to call that > reboot method? Do you mean I should not use ExitWindowsEx() ? > Thanks. If you don't know much about programming, you may not want to run after WMI right away. It sounds to me like the signal is being caught, but isn't being processed until you log in. How does the TCP service work? I assume it runs at startup... > lukas > > On Thu, 13 Feb 2003, Alex K. Angelopoulos wrote: > >> In addition to your comments, Lukas - >> >> I've successfully implemented code which reboots XP using the >> ExitWindowsEx function after performing token adjustment. Based on your >> description, I would try testing it while logged on interactively. >> >> Why? >> >> This will tell us whether the problem is technical details of method you >> are using to call it (in which case it will fail there), or related to >> environment/privileges of the account running it when no one is logged >> on. >> >> By the way, if it makes a difference, you don't need any of this with >> 2000/XP to perform a remote reboot. You can use WMI, which is >> accessible to Python, and call the Reboot Method in class >> Win32_OperatingSystem. >> >> Depending on your situation, this might be a feasible solution. >> >> -- >> >> "Lukas Kubin" wrote in message >> news:Pine.LNX.4.44.0302130829010.14458-100000 at x.opf.slu.cz... >>> -----BEGIN PGP SIGNED MESSAGE----- >>> Hash: SHA1 >>> >>> I don't have the book but I've tried the RebootServer.py script from the >>> examples archive. It didn't work for me. Could you tell me, please, how >>> did you implement the reboot code to work while waiting for login? How >>> did you let it know you wish to reboot? >>> Thank you. >>> >>> lukas >>> >>> On Wed, 12 Feb 2003, dsavitsk wrote: >>> >>>> "Lukas Kubin" wrote in message >>>> news:Pine.LNX.4.44.0302121331021.31917-100000 at x.opf.slu.cz... >>>>> I need to code a program rebooting windows xp, when nobody is logged >>>>> on. It means the computer is in the state with login window on. I >>>>> have a simple windows service waiting for a tcp connection which >>>>> should cause the reboot. I use the Python's win32api function >>>>> ExitWindowsEx() but nothing happens. When I test the reboot when >>>>> anybody is logged on, it works. (Yes I've done all the >>>>> AdjustPrivilege etc. already). Does anybody have experience doing >>>>> such code? >>>> >>>> There is an example of how to reboot a remote computer which is >>>> included (i think) in both win32all and Mark's book. It works on a >>>> computer at the login screen in win2k, but I can't speak to XP. >>>> >>>> -d >>>> >>>> >>>> >>> >>> - -- >>> Lukas Kubin >>> >>> phone: +420696398285 >>> email: kubin at opf.slu.cz >>> >>> Information centre >>> The School of Business Administration in Karvina >>> Silesian University in Opava >>> Czech Republic >>> http://www.opf.slu.cz >>> -----BEGIN PGP SIGNATURE----- >>> Version: GnuPG v1.2.0 (GNU/Linux) >>> Comment: Made with pgp4pine 1.75-6 >>> >>> iD8DBQE+S0oMhukdIiZrwu4RAg26AJkBkLg4XPNIoaAcNgk1luvAbgg80ACcCxKn >>> k1YlBFrVmJbVy5ufqEP/8Rw= >>> =71vC >>> -----END PGP SIGNATURE----- >>> >>> >> >> >> > > - -- > Lukas Kubin > > phone: +420696398285 > email: kubin at opf.slu.cz > > Information centre > The School of Business Administration in Karvina > Silesian University in Opava > Czech Republic > http://www.opf.slu.cz > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.0 (GNU/Linux) > Comment: Made with pgp4pine 1.75-6 > > iD8DBQE+TJ6dhukdIiZrwu4RAqxxAJ4k6ebytfLSWYLu5WTEXUa8XxQMjwCgkbnB > 4V6EIxk6GztG3Fe+gOv0NsU= > =KyRQ > -----END PGP SIGNATURE----- --? From peter at engcorp.com Mon Feb 17 09:02:03 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 17 Feb 2003 09:02:03 -0500 Subject: using sockets the same as in Ruby ? References: Message-ID: <3E50EB5B.CEBDDDA7@engcorp.com> Markus Jais wrote: > > that is, how can I read from a socket line by line ? > in the doc I found only the recv function which needs a buffer size. Look up the makefile() method on the socket object. With that, I believe you will easily find how to do what you want. -Peter From eichin at metacarta.com Tue Feb 11 15:06:15 2003 From: eichin at metacarta.com (eichin at metacarta.com) Date: 11 Feb 2003 15:06:15 -0500 Subject: scp module for python ? References: <2259b0e2.0302070906.4d2983e5@posting.google.com> <2259b0e2.0302110907.33faaa8a@posting.google.com> Message-ID: <7ghebah9ag.fsf@pikespeak.metacarta.com> here's a snippet of the code I use in my local customizations of qmtest; this is using the debian python-expect package, not sure where it came from before that. This runs ssh, not scp, but the concept is the same. You'll probably want to delete even more of the code, the key concepts are "use expect" and "wait for the password prompt before sending it". (The rest is mostly arranging that the user's privileges don't get used by accident.) import expect # start the command if os.environ.has_key("SSH_AUTH_SOCK"): del os.environ["SSH_AUTH_SOCK"] env_fix = " 'PATH=/sbin:$PATH;' " ssh_cmd = "ssh -F ssh_safe_config " + app_ut_user + "@" + app_ut_host + " " + env_fix + app_cmd # result[Result.CAUSE]="ok: " + ssh_cmd f = expect.popen2(ssh_cmd + " < /dev/null", "p") # give the password toss = f.read("password: ") f.write(app_ut_pass + "\n") # toss = f.read("\n") # this was problematic # get all the input stdout = f.read() # result[Result.CAUSE]="ok: stdout=" + stdout f.close() From jbperez808 at yahoo.com Sat Feb 15 06:42:26 2003 From: jbperez808 at yahoo.com (Jon Perez) Date: Sat, 15 Feb 2003 19:42:26 +0800 Subject: a 'case' statement? References: Message-ID: "Aahz" wrote: > Wouldn't you like a nice ternary operator instead? ROTFLMAO...!!! "Wouter van Marle" writes: > If the statement is just syntactic sugar for a chain of > if/elifs then I for one don't see the point. Imo, one of the things that make Python so much fun to use is its most EXCELLENT and well-thought out syntactic sugar. From rjones at ekit-inc.com Fri Feb 7 22:15:11 2003 From: rjones at ekit-inc.com (Richard Jones) Date: Sat, 8 Feb 2003 14:15:11 +1100 Subject: The 3D picture of Python In-Reply-To: References: Message-ID: <200302081415.11846.rjones@ekit-inc.com> On Sat, 8 Feb 2003 1:55 pm, Brandon Van Every wrote: > Ok, here's a summary of what I've learned about 3D and Python so far. Just > so you get an idea why I'm not downloading Python right this second. > > - after much debating about the merits / demerits of Python, C++, and plain > C, I decided that for 3D graphics problems, an interoperable Python / C++ > approach is absolutely required. This is the commonly accepted solution, yes. > - Python itself is rather piggish in that it doesn't have 4-byte floats, > and pads 8-byte doubles with an extra 8 bytes of Python object overhead. Again with abusive language like "piggish". You're really not big on the social skills, are ya pal? > - Numarray gets around the float and overhead issues as long as you're > using arrays. 4-byte floats are available and Python object overhead is > incurred only once per array, not once per element. Numarray isn't going > to help with structures, the Python structures will be much larger than the > C++ structures. Numarray is widely deployed as a de facto Python > programming component. Yep. > - Several Python / C++ class bridging solutions are available. The most > frequently recommended one is Boost, the 2nd is SWIG. I've heard positive > anecdotes about both. However, since there's no clear de facto standard, > one can expect worms that will only be elucidated through painful > experience. That's also correct. > - Nobody has said that Python integrates well with a Visual Studio > environment. My suspicion is the majority of Python aficionados shun > Microsoft products like the plague, and have little collective experience > with Visual Studio. I'm certain I've seen responses that invalidate this statement, and I don't even pay much attention to V.S. threads because I don't work with it. Hurm, a 10-second google search for "python visual studio support" gives me the first link: http://msdn.microsoft.com/vstudio/partners/language/activestate.asp and then quickly to: http://www.activestate.com/Products/Visual_Python/?_x=1 I don't know what you're after in particular, but this seems to indicate a high level of support. > - several different toolkits for doing OpenGL stuff are available. Their > level of abstraction and domain applicability varies. Yep. > Estimated time in the real world to become fully productive in newfangled > Python / C++ 3D environment: 1 month. Either you're not as good a programmer as you're making out, or you're not giving yourself enough credit. I'd expect you'd be able to learn the requisite Python, Numeric and PyOpenGL (assuming existing familiarity with OpenGL) knowledge within a week, perhaps two at the most. Richard From sholden at holdenweb.com Mon Feb 24 09:34:46 2003 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 24 Feb 2003 14:34:46 GMT Subject: greed (was) References: <23891c90.0302040318.6406e26d@posting.google.com><23891c90.0302050422.f1ee943@posting.google.com> Message-ID: "Mongryong" wrote ... > On Wed, 2003-02-05 at 18:05, Brandon Van Every wrote: > >Ergo the market > > perception of Linux remains "a hacker's OS" whereas Windows is "a consumer's > > OS." Rightly so. The situation is changing quite rapidly, however. I know you were a Linux user. Have you actually installed a major Linux distribution on recent hardware? It's less painful than installing Windows. Everything gets recognised. One thing that will almost certainly end up as a Linux competitive advantage is the higher degree of "out of the box" network security (though it's still not as good as FreeBSD). Right now Windows may be the logical choice for the consumer. There are no signs that Microsoft knows what to do to compete effectively on a technical level, though, and the further they go out along the anti-competitive branch they seem to have chosen (no-open-source EULA, certificate control of installed components, etc.) the more likely it is to break under the weight of the marketing leviathon. > M$ has won the desktop market - there's no doubt about that. To try to > get into the desktop market now would be a waste of money and time. > That's why it's pointless to try to make OSes like Linux 'cute' because > only intelligent people use them. But as history has taught us, things > always change. The times are a changing and the peak of this next > change is getting close. Like the type-writer, the desktop computer > will give way to a new breed of smart devices. When that change hits > full circle, it's going to be difficult to imagine that M$'s Windows > will be the last OS standing. > This defeatist talk assumes that a monopoly now will remain a monopoly, despite historical evidence to the contrary. In 1980 you would doubtless have written "IBM has won the hardware market - there's no doubt about that. To try to get into the hardware market now would be a waste of time. ..." Linuc doesn't need to be cute: it needs to be reliable and usable. It's getting there... I agree that the software environment is changing, but frankly I think the thing that will turn Microsoft into the first IBM of the 21st century is that fact that they have produced systems that have educated users about windows. Nowadays a Windows user can sit down at a Linux desktop and the environment more or less makes sense to them. This was completely untrue ten years ago. The thing that will turn the tide will be the desire of large corporations to stop paying huge amounts of money for unnecessary software of dubious quality. There are also going to be huge changes in the world's approach to intellectual property over the next twenty-five years. Microsoft won't disappear (just as IBM haven't), but they certainly won't be the dominant force that they are now, because they have made the same mistake IBM made: they think that market leadership implies control over technical direction. To a certain degeree this is true, but such control has limits. For example, look at how IBM thought they could control the market by introducing the licensed microchannel hardware bus design. The industry simply bypassed this technology and pushed ISA (the original bus interconnect, which the industry deemd standard) further than microchannel could go. ISA ended up with more investment, because the industry wouldn't go with a closed standard. IBM made exactly the same mistake in networking, where they stuck with SNA far longer than was justified. Guess what - they sell IP networking and peer-to-peer now just like everybody else. IBM simply became less relevant. So will Microsoft. Linux is still developing, but it has everything it needs except marketing muscle and volume of applications behind it. The marketing muscle is arriving in force, and what we have seen so far (Linux support from H-P, IBM's $6bn investment in Linux) is just the first wave. When there's sufficient economic advantage to be gained by switching, corporations will leave Microsoft behind in droves, and Microsoft apparently lack the imagination to compete by embracing open source. We've already seen them stumble and nearly miss the boat over Internet technology. Open source is a model they simply can't afford not to understand: but the evidence is, they don't want to embrace it because they see their profits coming from proprietary intellectual property. Just the ruminations of an old fart with a lifetime's industry experience. but-that-doesn't-mean-microsoft-is-a-bad-short-term-investment-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ Register for PyCon now! http://www.python.org/pycon/reg.html From Scott.Daniels at Acm.Org Fri Feb 7 18:26:17 2003 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 07 Feb 2003 15:26:17 -0800 Subject: Python's 8-bit cleanness deprecated? In-Reply-To: References: <3E437299.4070505@lemburg.com> Message-ID: <3e44409a@nntp0.pdx.net> Simo Salminen wrote: > * Kirill Simonov [Fri, 7 Feb 2003 18:39:56 +0200] >>...But what is the price that we pay for this? The millions of Python >>scripts that use 8-bit string literals or comments are broken now in >>order to allow the feature that no one ever used! I think that this is >>an extreme. > ... > This change only makes python hostile to regular programmer, who > does not care about encodings, and only wants to use simple 8-bit > characters in comments. I told myself to be quiet, but .... This change is one step on the way to switching python source from bytes to characters; from binary source to text source. Unix users often think there is no difference between binary and text files: the two are different, but on unix the representation is the same. That is, the text file consists of characters (which have particular meanings), while the binary files are simply byte streams which can only be replicated. Html files are not the same as text files either, although they are represented as text files. The difference is in what you know about the contents of the file. If I know a file is html, I can display it with a browser and see nifty effects like bold, italic, type size changes, .... Without that information, I have less knowledge about how I might be able to use that file. Conceptually, source code is text, not bytes. Nobody really cares how the characters in a line are encoded: the meaning is apparent by looking at displayed characters. Unfortunately, we are now (as we always were) in a world where there are multiple encodings for the same characters. On any given computer system, for a particular user, there is a text encoding they are most comfortable using. THis preference is usually because their favorite text editor can read and write that encoding, and it has all of the characters they are likely to use. There are various options for python source: First, we could define the coding to be 'system local,' and endure constant complaints when a file that works right on one system (or even for one user) does not behave in the same way for another. This is the "plain old 8-bit" option. Second, we could (as I understand Python was conceived) restrict python to a 7-bit printable ASCII plus space, horizontal tab, and (? \n, \r, \r\n). By the by, if you think the last is nit-picking, exactly which bytes are in the constant: """a z""". The answer may depend on your operating system, or it may not. You probably can run python programs shipped (as binary files) from Mac OS X, Microsoft Windows, and Unix systems. The results might differ. Pretty much anyone who uses more characters than are available in ASCII are going to be infuriated by this choice. Third, we could declare a single encoding as "the blessed" encoding for python source. This would be perfect for the winners and nasty for the losers. One group would love "latin1" to be the code. Well, UTF-8 at least has the pleasant property of being able to represent the vast majority of characters representable on computers. So UTF-8 might be a good choice. However, with a few exceptions, text editors on a system work well with a particular local encoding. Only in a very few cases is this a variant of unicode. So on many systems people who use python will be forced to use a different text editor than they normally use. Fourth, we could define python in terms of characters, and allow locally-encoded text to be be used as long as we know the mapping from the local code to some standard (say, unicode). It is likely that such python translators will consist of a thin sugary coating of local-encoding-capable code over a chocolatey core of standard python code to do the actual parsing, compiling, etc. The core, in order to be most portable, is likely to munch on unicode. We'll also need a sugary layer that knows how to determine which original bytes of local encoding to use in such things as non-unicode string constants (note the unicode strings will be just dandy as-is). This looks a _lot_ like the first case, but allows local text encoding that doesn't map ASCII to the ASCII subset of unicode. This is also the first character-based option. Fifth, and I personally choose to take the fifth, we could use the fourth option, except we could write the encoding at the front of the file (oops, unix uses the first line to control certain program behavior, lets allow the forst _or_ the second line). If this works, not only does it work as well as the fourth option, but we can actually use modules developed under another encoding on our system without ever having to push them through some sort of "try to do what they mean" translator to get it into our local format. This option uses character-based source code with explicit encoding to allow us to run python from anywhere locally. _But_, it requires we be explicit about encodings. Our translator will cope properly with a program built from modules in different encodings, _but_it_ _must_know_the_encodings_. This is delightful, since now we can have a code repository where we can pull contributed code written in Brazil, Serbia, Kyoto, and Thailand from a single repository safely. The sole cost is explicit encoding. We could probably even cope with EBCDIC, were someone lusting to use old character codes, since we need to only look at the first two lines. If we cannot find an encoding in the first two lines looking at simple ASCII, we try as EBCDIC and look to see if we find it. If not, we then try big5 and .... Roman Suzi asked: "how one would feel if '# -*- coding: ascii -*-' would be necessary for every program?" I replied, "I would probably never use it. If I had to use an encoding, I would probably use: '# -*- coding: UTF-8 -*-', since I could encode other author's names in comments (or credit strings)." I really have no idea whether I am mentioning issues here that people don't realize, or simply spouting off my opinions to a group that finds them unconvincing. I, of course, hope to be doing the former and will resume my silence for fear that I am doing the latter. -Scott David Daniels From mcfletch at rogers.com Mon Feb 3 13:01:56 2003 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 03 Feb 2003 13:01:56 -0500 Subject: Reliably getting/setting the (current) encoding name? In-Reply-To: <7h3wukhv8wq.fsf@pc150.maths.bris.ac.uk> References: <7h3znphwdtp.fsf@pc150.maths.bris.ac.uk> <7h365s5w5hw.fsf@pc150.maths.bris.ac.uk> <7h3wukhv8wq.fsf@pc150.maths.bris.ac.uk> Message-ID: <3E3EAE94.90003@rogers.com> Michael Hudson wrote: >"Mike C. Fletcher" writes: > > ... >>I don't expect it'll be too terribly difficult, but wxprop is heavily >>into types, it's got an lot of automation machinery (including >>type-checking and coercian) for dealing with strings in a GUI as part >>of an object model. Suddenly switching the object-model to be unicode >>based is probably going to cause headaches with upgrading old content >>and the like. It's just not a place I want to venture just yet. >> >> > >Sounds like you're paying the price for being too clever :) > > The wages of genius ;) . Actually more like paying the price for not just trying the conversion. Because the entire system is automated the conversion was a matter of setting the defaulting encoding to the system default (so logging and like worked) and then rewriting a property type. So now, the entire thing is Unicode/utf-8, with only a few sub-classes which are using strings for such things as module.class names. The content is updated on the fly by the conversion mechanisms in the properties. Thanks for the kick to do it :) . >Shh, didn't we tell you not to mention the Secret PSU >Licensi**$?*%^ NO CARRIER > > Honestly, am I the only one who has noticed these access ports in the PSU holding pens? Check behind your bunk. Thursday is Apple-dumpling day, Mike (The man in the scaly mask) _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From skip at pobox.com Fri Feb 28 10:10:04 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 28 Feb 2003 09:10:04 -0600 Subject: Just for fun - PickleRPC In-Reply-To: <8264j-213.ln1@nb2.stroeder.com> References: <8264j-213.ln1@nb2.stroeder.com> Message-ID: <15967.31692.469046.467327@montanaro.dyndns.org> >> I wound up with an RPC protocol running over raw sockets which uses >> pickle as the serialization format. Michael> How do you deal with security? I don't. ;-) Another reason the subject says "Just for fun". In fact, I do pickle Exception classes and instances when an exception is raised on the server, so classes and instances are created on the client. Skip From dale at riverhall.NOTHANKS.co.uk Wed Feb 19 16:17:06 2003 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 19 Feb 2003 21:17:06 +0000 Subject: Web stress tester References: Message-ID: Dale Strickland-Clark wrote: Thanks to all the replies. I've made significant progress with this now. -- Dale Strickland-Clark Riverhall Systems Ltd From adalke at mindspring.com Wed Feb 26 01:50:46 2003 From: adalke at mindspring.com (Andrew Dalke) Date: Tue, 25 Feb 2003 23:50:46 -0700 Subject: class derived from dict in eval References: Message-ID: Alex: > Wow -- heroic, really... Naah, more like stubborn. ;) > Hmmm, one architectural one, I think -- what happens if > d is, say, {'a': 23}, while s is, say, '{}["a"]', which > SHOULD raise a KeyError? I think this will loop forever... In the context from which this is done, that cannot happen because I haven't documented that {} is valid. *ahem* OTOH, your code would be tricky because I do have a reference to 'math', so people can do math.abs(). The co_names solution yields >>> compile("math.abs(c)", "", "eval") ", line -1> >>> _.co_names ('math', 'abs', 'c') >>> Hmmm... it's theoretically possible that my dict-like object defines an 'abs' which takes a long time to compute, so that a possible workaround like for name in co_names: try: real_d = d[name] except KeyError: pass eval(compiled, real_d) would trigger computing an 'abs' when it shouldn't. I say theoretically because all of the names used should be all caps, possibly with an "_", but that's not prohibited. So what I think I'll do is just add your double check and leave my code as it is. > You're welcome! I'm slightly surprised I didn't already > post this kind code in the past, put it in the cookbook, > or something like that, but some googling suggests I didn't. Feel free to add my trick with your fix - it might be useful for a few cases. Andrew dalke at dalkescientific.com From mykbourassa at cogeco.ca Sat Feb 22 08:03:05 2003 From: mykbourassa at cogeco.ca (myk) Date: Sat, 22 Feb 2003 08:03:05 -0500 Subject: Python Imaging Library ... Help! In-Reply-To: References: <8iD5a.18023$q26.351151@read1.cgocable.net> Message-ID: Very nice site! Thanks for the link. Mike Duncan Smith wrote: >"myk" wrote in message >news:8iD5a.18023$q26.351151 at read1.cgocable.net... > > >>I've just killed an evening trying to install the PIL on my HP laptop >>(Omni 6000) running Python 2.2.2 on Windows98. I've tried the binary >>for PIL 1.1.2 but it automatically installs in Py22 which isn't the name >>of my Python directory. I also tried unpacking the 1.1.3 tar.gz. But I >>can't seem to get "setup.py" to run. A dos window winks in and out of >>existence but the module can't be imported when I try to do so in IDLE. >> I've tried to figure out what "setup.py" is doing but since I'm a >>Python newbie that didn't help. Any ideas as to what I'm doing wrong or >>how I can very manually get all the files to where they should be? TIA. >> >>myk >> >> >> > >Instructions here, http://www.visionegg.org/install-windows-details.html. > >Duncan > > > > From staschuk at telusplanet.net Sat Feb 15 12:15:18 2003 From: staschuk at telusplanet.net (Steven Taschuk) Date: Sat, 15 Feb 2003 10:15:18 -0700 Subject: (PEP-308) Python's Conditional Selection Operators In-Reply-To: ; from tjreedy@udel.edu on Fri, Feb 14, 2003 at 07:24:50PM -0500 References: Message-ID: <20030215101518.C422@tibia.amotlpaa.bogus> Quoth Terry Reedy: > PYTHON'S CONDITIONAL SELECTION OPERATORS: 'AND' AND 'OR' An interesting discussion. > [...] For > efficiency, execution of the second operand can be conditional on the > first not being dominant. The possible problem is when execution of b > has a side-effect that also becomes conditional. What is "the possible problem" to which you refer? To me, the fact that the second operand's side-effects are conditional is one of the most desirable properties of these operators' definitions. > Selective 'and' and 'or' have an unusual combination of properties. > [...] They are non-commutative [...] Both are associative [...] Also note these properties: Homomorphism: a and b == c ==> bool(a) and bool(b) == bool(c) a or b == c ==> bool(a) or bool(b) == bool(c) Law of tautology: a and a == a or a == a Left double distributivity: a and (b or c) == (a and b) or (a and c) a or (b and c) == (a or b) and (a or c) Left absorption: a or (a and b) == a a and (a or b) == a And, although we haven't defined 'not' for the new domain (indeed, 'not' can't be selective except for a one-element domain), we do have Weak left cancellativity: a and b == a and c ==> bool(a) == F or b == c a or b == a or c ==> bool(a) == T or b == c (Note the analogy to rings, in which if ab = ac then a = 0 or b = c.) These properties make me feel that selective {and,or} are a pretty good stab at a non-commutative generalization of boolean algebras. Imho they are the most natural way to make them binary operators on an arbitrary domain (rather than merely relations on that domain, as the coercing versions are). (I leave exploring the right-side analogues to the interested reader. They're not all straightforward.) > A non-trival binary logic operator is one whose output depends on both > inputs. Of the ten possible, only and and or are selective in that > the output is always one of the inputs. (To be selective, 0 op 0 and 1 > op 1 must be 0 and 1 respectively. Of the four possible assignments > to 0 op 1 and 1 op 0, two produce the trivial selectors a op b == a > and a op b == b. The other two are and and or.) They are thus the > only two that can be generalized in the way they are in Python. Nice observation! This gives another way to show that 'not' cannot be selective except in trivial cases: if it were, then e.g. 'a and not b' would be selective (since compositions of selective functions are selective). -- Steven Taschuk | Receive them ignorant; staschuk at telusplanet.net | dispatch them confused. | (Weschler's Teaching Motto) From max at alcyone.com Thu Feb 6 18:35:13 2003 From: max at alcyone.com (Erik Max Francis) Date: Thu, 06 Feb 2003 15:35:13 -0800 Subject: 3D graphics programmers using Python? References: Message-ID: <3E42F131.FEB7FBAD@alcyone.com> Brandon Van Every wrote: > Sure. Otherwise I wouldn't be here. But what I've learned about > Python > says it isn't going to cut down the time for all problems. Python has > its > pitfalls that can chew up time. The main ones that concern me right > now are > integration with C++, floating point support, ... What floating point support pitfall? > Also it occurred to me last night: does Python support > operator > overloading? If it doesn't, that would totally change how I write all > of my > 3D calculations. Yes, it does. Shouldn't you know that by this point? You've been making a lot of declarations about Python being this and Python being that, but so far it seems very clear that you know very little about it. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ War is like love, it always finds a way. \__/ Bertolt Brecht Bosskey.net: Return to Wolfenstein / http://www.bosskey.net/rtcw/ A personal guide to Return to Castle Wolfenstein. From snarflemike at yahoo.com Tue Feb 18 18:14:46 2003 From: snarflemike at yahoo.com (Mike Silva) Date: 18 Feb 2003 15:14:46 -0800 Subject: Best Python book(s) for a pre-teen? Message-ID: <20619edc.0302181514.7a37d7b5@posting.google.com> snarflemike at yahoo.com (Mike Silva) wrote in message news:<20619edc.0302181127.6ad39e68 at posting.google.com>... <...> > One other question -- I'd like him to be able to do simple graphics > fairly early, since I think it makes the whole self-learning process > much more interesting. I'm talking about things like points, lines, > circles, fills, etc. Is there a binding to the Win32 graphics > primatives in 2.2.2, or can I find one someplace? If this is a RTFM > question, any pointers to TFM chapter, etc would be appreciated! OK, in poking around more I discovered Tkinter and the turtle module. This looks like it will be fine -- certainly kept me entertained for the last hour! (If this message comes through as a new thread rather than a followup, it's a google strangeness happening...) Mike From km-news1 at onlinehome.de Fri Feb 21 17:01:43 2003 From: km-news1 at onlinehome.de (Klaus Meyer) Date: Fri, 21 Feb 2003 23:01:43 +0100 Subject: c enum - how to do this in python? In-Reply-To: References: Message-ID: Hi Rene, >> enum { M0, M1, M2, MCOUNT }; >> How to do this in Python? > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/67107 Thanks, but surprisingly complex in Python... -- Gru? - regards Klaus :-) From rnd at onego.ru Sun Feb 9 14:08:34 2003 From: rnd at onego.ru (Roman Suzi) Date: Sun, 9 Feb 2003 22:08:34 +0300 (MSK) Subject: Python's 8-bit cleanness deprecated? In-Reply-To: <20030209124653.A7055@unpythonic.net> Message-ID: On Sun, 9 Feb 2003, Jeff Epler wrote: >Roman, >we're sorry there's such a minefield of different encodings. But what >happens if you write something koi8-r, and somebody using cp1251 downloads >it? It depends on what browser do it. Some browsers automatically convert text files from one encoding to another... Mail is also transparently converted from one encoding to another. >Without an encoding cookie, he'll get gibberish when he runs the >program, since all non-ASCII strings will be in the wrong encoding. > >With an encoding cookie, he'll get the right thing. No. It depends on output. When raw-8-bit are used, it is just a matter of recoding source to get it to work. With encookies one will get gibberish on the stdout (if stdout is used). So, one must make 2 things instead of just recoding the file: 1. recode source file 2. change the cookie But this is probably very specific to Russia as we have 6 encodings for cyrillic letter: all of them in more or less use! BTW, it's the same with HTML and meta-tag. Encookie will be in full glory only when most users will have Unicode-capable stdin/stdout. >I don't know what to suggest for printed code listings. The GUI editor >that people use should simply insert # -*- coding: xxx -*- automatically, >using the right 'xxx' value. (we're talking about idiots here, so it'll >have to be done automatically) And in your listing, you could just print > # -*- encoding: /see text/ -*- >with // denoting italics or something that is obviously not simple program >text. > >"Your" way, of trying to assume the contents of a file with high bits set, >means that the common way of exchanging Python programs (as electronic >files) won't work, but an uncommon way seems to present a small problem >that you'd be forced to explain. Ok. >Jeff Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.3 From irmen at -NOSPAM-REMOVE-THIS-xs4all.nl Thu Feb 27 16:19:48 2003 From: irmen at -NOSPAM-REMOVE-THIS-xs4all.nl (Irmen de Jong) Date: Thu, 27 Feb 2003 22:19:48 +0100 Subject: Just for fun - PickleRPC In-Reply-To: References: Message-ID: <3e5e80f4$0$49099$e4fe514c@news.xs4all.nl> Skip Montanaro wrote: > Trying to speed up a simple client/server application in the spambayes world > I decided to try replacing XML-RPC with a simpler protocol. I wound up with > an RPC protocol running over raw sockets which uses pickle as the > serialization format. Checked it out briefly - I saw that you "snagged" something from xmlrpclib, namely (a part of) the dynamic proxy. How does this proxy work? Does it deal with direct attribute access (object.attribute) and nested lookups (object.attribute.subattr.method() )? I still have to fix Pyro's dynamic proxy -- it can't yet deal with nested lookups. So I was wondering if I could "snag" some stuff from here :-) Regards Irmen de Jong. From bokr at oz.net Sun Feb 9 13:53:03 2003 From: bokr at oz.net (Bengt Richter) Date: 9 Feb 2003 18:53:03 GMT Subject: why not extending the syntax for classes, too ? References: <2259b0e2.0302070810.7b6ddd8c@posting.google.com> Message-ID: On 7 Feb 2003 08:10:21 -0800, mis6 at pitt.edu (Michele Simionato) wrote: >Within the proposals of extending the function syntax, >reported on the python-dev summary recently posted on c.l.p., >I like the most the proposal with "is", as for instance in > >def double(x) is staticmethod: > return 2*x > How about specialization or specialty or kind or narrowly or becomes? def double(x) specialization staticmethod: return 2*x def double(x) becomes staticmethod: return 2*x def double(x) kind staticmethod: return 2*x >I like the "is" syntax more than the syntax with "as" and the syntax >with the square brackets, especially because with "is" it would be >natural to extend the notation for classes, using metaclasses as class >descriptors. Metaclasses are typically denoted by adjectives and thus, >instead of writing, for instance > >class C(B): > __metaclass__=Traced > #assuming Traced is a metaclass adding tracing capabilities > >one could write > >class C(B) is Traced: > #This is much more readable class C(B) specialization Traced: #This is much more readable class C(B) becomes Traced: #This is much more readable Or we could use a suffix: def double(x) staticmethod'ly: return 2*x class C(B) Traced'ly: #This is much more readable ;-) Regards, Bengt Richter From max at alcyone.com Fri Feb 21 20:35:57 2003 From: max at alcyone.com (Erik Max Francis) Date: Fri, 21 Feb 2003 17:35:57 -0800 Subject: Range() limit References: <4378fa6f.0302211708.2e531aa0@posting.google.com> Message-ID: <3E56D3FD.85281214@alcyone.com> Marc wrote: > I have a quick question on the limits of the range() function. This is > probably computer speed and memory dependent, but is there any value > over which the range function can't handle. I'm doing iterations over > quite a large range, and as it approaches 50 million potential > iterations it stalls and dies. > > Have I exceeded Python's ability to handle iterations or is a > limitation with my computer. range _actually builds a list_. If the number of elements in that list is huge, you're going to be building a really big list. If you're using it solely for the purposes of iterating over, obviously this ain't the brightest idea in the world. Use xrange instead, or simply count manually. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ There are defeats more triumphant than victories. \__/ Montaigne Python chess module / http://www.alcyone.com/pyos/chess/ A chess game adjudicator in Python. From gerhard.haering at gmx.de Sat Feb 1 10:31:59 2003 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 1 Feb 2003 15:31:59 GMT Subject: MySQLdb and distutil errors? References: Message-ID: Colin wrote: > Hi everyone, > > First off, let me say that I'm a Python newbie. Welcome to the club :-) > I just started > playing around with it, but I'm running into some problems trying to > get things installed. I want to install the MySQLdb module, but when > I try to run "python2.2 setup.py build" for MySQLdb I get the > following error: > > Traceback (most recent call last): > File "setup.py", line 6, in ? > from distutils.core import setup > ImportError: No module named distutils.core You're using some Linux flavour, right? Most Linux distributions have split up Python into several packages, one of them being the "development" package. If this is the case, you'll have to install the Python development package, normally ending in "-dev" or "-devel". > So okay, I don't have the distutils module. I find that a little > weird, since I thought all later version of Python came with > distutils. Yep. > But anyways, I tried to install the distutils, [...] I suggest installing distutils by installing the development package made by your distribution. Gerhard -- Favourite database: http://www.postgresql.org/ Favourite programming language: http://www.python.org/ Combine the two: http://pypgsql.sf.net/ Embedded database for Python: http://pysqlite.sf.net/ From grante at visi.com Thu Feb 13 14:05:44 2003 From: grante at visi.com (Grant Edwards) Date: 13 Feb 2003 19:05:44 GMT Subject: float / double support in Python? References: <1T32a.10925$1q2.1049400@newsread2.prod.itd.earthlink.net> <20030213110407.GC671@jsaul.de> <3E4B7DD9.1443E8FA@alcyone.com> <20030213113248.GF671@jsaul.de> Message-ID: <3e4bec88$0$157$a1866201@newsreader.visi.com> In article , Andrew Dalke wrote: > jsaul: >> What other language would you consider easier to learn than >> English? I am referring to written English, the weird >> pronounciation "rules" are a different issue, of course. >> >> Latin? French? Spanish? Or Chinese? > > Perhaps one of the trade languages, like ... Swahili? > Or one of the creole languages? Esperanto was designed specifically to be the universal second language. It seems there are a surprising number of Pythonistas who know Esperanto. -- Grant Edwards grante Yow! Are the STEWED PRUNES at still in the HAIR DRYER? visi.com From grante at visi.com Thu Feb 6 15:01:11 2003 From: grante at visi.com (Grant Edwards) Date: 06 Feb 2003 20:01:11 GMT Subject: How to tell when a script is executed by cron ? References: Message-ID: <3e42bf07$0$183$a1866201@newsreader.visi.com> In article , Simon Dobner wrote: > On Wed, 05 Feb 2003 06:24:02 +0000, Grant Edwards wrote: > >> You can also use >> >> if os.isatty(sys.stdout.fileno()): >> # we're running interactively >> else: >> # batch mode > > Cool. > > Is os.isatty somewhere in the docs, and I just can't find it, or is it > covered by this sentence The former: http://python.org/doc/current/lib/os-fd-ops.html It's between ftruncate() and lseek(). ;) -- Grant Edwards grante Yow! An Italian is COMBING at his hair in suburban DES visi.com MOINES! From enrique.palomo at xgs-spain.com Mon Feb 3 05:08:35 2003 From: enrique.palomo at xgs-spain.com (Enrique Palomo) Date: Mon, 3 Feb 2003 11:08:35 +0100 Subject: compiling... In-Reply-To: Message-ID: Hello again. I have sent this message two hours ago. Another solution, could be that anyone tell me what is what i need to compile a c++ module and use like a python one. Is the first time i must do something like that and i feel quite lost. I've downloaded pycrypto package, run setup.py build and ... cl.exe /c /nologo /Ox /MD /W3 /GX -Isrc/ -IC:\ARCHIV~1\python2.2\include /Tcsrc/MD2.c /Fobuild\temp.win32-2.2\Release\MD2.obj error: command 'cl.exe' failed: No such file or directory i would be eternally thanked i anyone could explain me, step by step, what must i do. Not only thanked, a couple of beers for the people of good heart. ;-) Enrique Hello all. I need mxCrypto or pycrypto for Python 2.2 I have it for python 1.5.2. and i have found it for 2.0. Thanks. Enrique -------------- next part -------------- An HTML attachment was scrubbed... URL: From webmaster at nextmovetech.com Sun Feb 9 06:49:51 2003 From: webmaster at nextmovetech.com (James Tan) Date: Sun, 9 Feb 2003 19:49:51 +0800 Subject: wxpython: wxbitmap transparency Message-ID: <3e463e28_1@news.tm.net.my> Hie everyone, i finally manage to display my gif and jpg perfectly I'm trying to display the little transparent gif image onto another image it goes from wxbitmap -> wxstaticbitmap - > wxpanel i've applied a masking onto the little gif file (wxbitmap) white for appearing, and black for not appearing -_- :P (wxbitmap -> wxmask -> wxbitmap.setmask(wxmask)) I've set the style of the wxstaticbitmap to transparent. but when i display the wxstaticbitmap onto the panel the background is still colored with grey?? what's wrong? or is there any other way? i'm using python 2.2.2 with wxpython 2.4 please advice, thank you. best regards, James "holger krekel" wrote in message news:mailman.1044743303.16764.python-list at python.org... > Peter Hansen wrote: > > I haven't seen anyone pointing out the obvious _real_ reason for > > Guido's proposal on the ternary operator (and I hereby vote +1 > > for anything that reduces the use of the ([a] and [b] or [c])[0] > > crap, but -1.2 on the counter-intuitive order of elements in > > the proposed syntax, for a net vote of -0.2). > > > > Recently Python has been dropping in the polls, with languages > > such as LabVIEW and even Clipper encroaching on its territory. > > > > With the release of new PSU technology which is able to measure the > > popularity of a programming(*) language based on advanced metrics > > including the number of unique posters in the last month's worth > > of posts to a newsgroup, it is suddenly more important than > > ever to make sure that activity remains high in the newsgroup. > > More than that, activity by many lurkers must be encouraged, > > so that frequent posters don't reduce the measured popularity > > with their useless and annoying babble. > > > [explains in detail the background of this true assertions] > > this is but one part of the picture. The recent PSU strategies > try to hide something else which is even more pervasive. And > of course they use Python for it as it is clearly the best > thing for the job: One "Google" to rule them all. > > Luckily i managed to get the following interesting observations > past their brutal email-crippling bot. But this may be the last > time i succeeded against the ever-increasing power > of the PSU/Google bots. > > Let's start with a simple question: > > How does google get the incredible amount of money they need? > > They have 12000 server nodes (and increasing) running > and must have quite a some IP-traffic bill. > They have some brilliant minds and programmers (using > Python, sic!) on their payroll doing research, > programming and maintenance. They are cataloging > more and more content. And fast. > > And some small text-ads and some companies using their > technology are going to pay for all this? > You godda be kidding. > > So let's add a second simple observation. They have > damn good search technology and everybody is keen > on getting their content into google. That's right: > everybody tries to get content into google *by their own*. > > Now ask yourself who is most interested today in having > significant information about everything? > > Right, that would be certain agencies who officially have > projects longing for "Total Information Awareness", even. > > So, of course they decided early on to put a couple of > hundred-millions into obtaining enough control of the > technology. > > In return they > > a) get as much information as possible (because > everybody even wants to have it in by themselves) > > b) make everybody addicted and thus especially keeps > free developers from developing their own solutions > which might not be accessible to them > > c) efficiently encourage finding the most scalable > technical solutions. > > d) build an unprecendented power structure across the net > > e) can add their huge amount of data and files to have a > really nice searching facility about everyone. > > There is no doubt that these agencies have the money and > the interest to use Google for sorting out the huge amounts > of data they want to gather. > > It's an easy step towards net-wide domination and control. > Face it. > > And of course they don't officially tell us about it > because then we would have every reason to be scared > and might even try to do something against it. So it's better > to make us friends with this nice "Saruman" aka Google. > > This "google conspiracy" is about as founded as the > (currently unfashionable) "bin lad** conspiracy". > I'd say believe both or None. > From mertz at gnosis.cx Sat Feb 1 23:24:07 2003 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Sat, 01 Feb 2003 23:24:07 -0500 Subject: List comprehension confusion... References: <483p3v8pq8vfk7jbpl2u7m314v2j4ledc5@4ax.com> Message-ID: Andrew Dalke wrote previously: |get the "some_field" attribute of all elements in a list |results = [term.some_field for term in data] Just to throw flame on the fire, I am one of the odd people who find map quite readable too: result = map(lambda t: t.some_field, data) Yours, Lulu... -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From eppstein at ics.uci.edu Wed Feb 12 10:08:32 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Wed, 12 Feb 2003 07:08:32 -0800 Subject: [poll] anyone else needs fast random element access off a dictionary? References: <20030211163725.GA29995@foof.i3.cz> <15945.11137.883755.733359@montanaro.dyndns.org> Message-ID: In article , Michal Vitecek wrote: > actually you can't update the list in O(1) time because of its internal > working. by updating i do not only mean changing a value already stored > in it but also removing a value off it: Use lazy deletion from the list -- replace the value you want to remove by "None" (an O(1) operation), keep a count of how many removed positions there are, and keep an index to a position in the array that is less than or equal to the first nonempty item. When you want to find a nonempty item, increment the index until it points to one. When the count of removed items gets too large, replace the list by a compacted one in which all the removed items are actually removed. Result: constant amortized time per operation. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From mertz at gnosis.cx Fri Feb 28 22:03:45 2003 From: mertz at gnosis.cx (David Mertz) Date: Fri, 28 Feb 2003 22:03:45 -0500 Subject: Why does 2.3a2 change "slots" in complex? Message-ID: Our gnosis.xml.pickle package makes an effort to pickle various objects, generally trying even harder than the standard pickle module. In particular, we try to do sensible things with new-style classes that have slots, and that don't. One of the unit tests involves adding extra attributes to descendents of standard data types. It turns out, that test breaks with Python 2.3a2, because of a change in the implementation of complex. Here is a brief test case that shows the behavior. I am interested in why this change was made. Is it a bug or a feature? If a feature, what benefit does this have? If a bug... well, I guess that's the point of an alpha version. % cat newstyle.py # Test of extra attributes in new-style classes import sys print sys.version class Int(int): pass i = Int(4) print i, i.attr = 5 print i.attr class Complex(complex): pass c = Complex(1+1j) print c, c.attr = 2 print c.attr % python22 newstyle.py 2.2.2 (#0, Oct 24 2002, 20:53:04) [EMX GCC 2.8.1] 4 5 (1+1j) 2 % python23a2 newstyle.py 2.3a2 (#0, Feb 21 2003, 19:35:57) [EMX GCC 2.8.1] 4 5 (1+1j) Traceback (most recent call last): File "newstyle.py", line 14, in ? c.attr = 2 AttributeError: 'complex' object has no attribute 'attr' Yours, David... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From logistix at zworg.com Sun Feb 9 17:27:29 2003 From: logistix at zworg.com (logistix) Date: 9 Feb 2003 14:27:29 -0800 Subject: Some win32security questions References: Message-ID: Dmitry Bely wrote in message news:... > I am trying to write a script to set some file ACLs. This seems to be > surprisingly complicated when compared, say, to Perl or Visual Basic. I > realize that Python libraries are direct wrappers to WIN32 API -- this is > not a problem, I simply cannot find the way to do some things. Maybe I am > missing something? > Depending on what you're trying to do, it's usually easier to cheat and use Python's os.popen() to call xcacls or subinacls. If you provide more details though, I might be able to give some other pointers. From paul.rudin at ntlworld.com Thu Feb 6 03:22:34 2003 From: paul.rudin at ntlworld.com (Paul Rudin) Date: 06 Feb 2003 08:22:34 +0000 Subject: greed (was) References: <23891c90.0302040318.6406e26d@posting.google.com> <23891c90.0302050422.f1ee943@posting.google.com> Message-ID: Mongryong writes: > On Wed, 2003-02-05 at 18:05, Brandon Van Every wrote: > >Ergo the market > > perception of Linux remains "a hacker's OS" whereas Windows is "a consumer's > > OS." Rightly so. > M$ has won the desktop market - there's no doubt about that. To try to > get into the desktop market now would be a waste of money and time. People are trying, precisely because of money. Not so much home users, but organisation that have lots of desktop machines. No doubt the share of the market is tiny at the moment, but if read the various trade rags, you'll see a steady trickle of contracts to install networks of linux desktop machines in different places. I suspect the way Microsoft licencing is going will encourage this. Windows is used partly because lots of people don't actually buy all the licences they need. Microsoft's clamping down on this may actually something of an own goal. Sure they'll extract more money from those who are actually using their software, but they'll push more people to actively consider the alternatives and weaken the perception that windows is the only thing to have on your desktop. From danb_83 at yahoo.com Sat Feb 8 15:37:35 2003 From: danb_83 at yahoo.com (Dan Bishop) Date: 8 Feb 2003 12:37:35 -0800 Subject: ternary operator References: <3e404255.1172145764@news.cis.dfn.de> <7xisvxax2r.fsf@ruckus.brouhaha.com> <7xd6m43m0i.fsf@ruckus.brouhaha.com> <11feh-on3.ln1@beastie.ix.netcom.com> Message-ID: Andrew Koenig wrote in message news:... > Dennis> Similar for > > Dennis> or > Dennis> vs > Dennis> or else > > Indeed -- this is the best evidence that Ada is the result of a military > project. In what other language is "or else" an operator? Babbage (http://www.tlc-systems.com/babbage.htm) uses it as a "conditional threat" ("Add these two numbers OR ELSE!"). But if you meant whether there's an "or else" in a language that people actually program in, I don't know of any. From scjuonline at web.de Sat Feb 8 12:12:59 2003 From: scjuonline at web.de (JS) Date: Sat, 8 Feb 2003 18:12:59 +0100 Subject: cgi Module Message-ID: <200302081812.59469.scjuonline@web.de> Hi, I have a question about the cgi module: I would like to write a robust cgi programm which checks all the parameters. Possible calls are: 1.) http://www.example.com/cgi-bin/test.py 2.) http://www.example.com/cgi-bin/test.py?param 3.) http://www.example.com/cgi-bin/test.py?param= 4.) http://www.example.com/cgi-bin/test.py?param=xyz 5.) param=file (POST) form = cgi.FieldStorage() gives me in cases 1+2+3 nothing? Shouldn't case 2 be param==None and case 3 param=="" ? thx a lot, JS From pyth at devel.trillke.net Mon Feb 10 13:30:49 2003 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 10 Feb 2003 19:30:49 +0100 Subject: PEP 308: Alternative conditional operator forms In-Reply-To: ; from tim.one@comcast.net on Mon, Feb 10, 2003 at 12:44:57PM -0500 References: <20030210181755.X1706@prim.han.de> Message-ID: <20030210193049.A1706@prim.han.de> Tim Peters wrote: > [holger krekel] > >> No, that's not a short-circuiting form. > > > which is rarely needed. Tim Peters said that with the hundred > > cases of the beloved "x and y or z" idiom in the 150+ modules of > > Python it's needed exactly 0 (zero) times. > > Nope. I said the relative handful of examples I included didn't need > short-circuiting, and that it was rarely needed. Yup, i mixed up. > [good examples of and/or short-circuit usage in standard lib] > In the end, I didn't find any code in the std library I'd change if the PEP > were to be accepted. I didn't study every line, though. That is still a good point. Easy to get confused these days. I should stop posting to this thread for a while. It's almost getting an addiction and everything else than PEP-308 suddenly seems to uninteresting . holger From dave at pythonapocrypha.com Sat Feb 8 23:36:56 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Sat, 8 Feb 2003 20:36:56 -0800 (PST) Subject: For review: PEP 308 - If-then-else expression In-Reply-To: <3E45A8C0.7060701@tismer.com> References: <7xsmuzx5s7.fsf@ruckus.brouhaha.com> <3E456DD7.6080406@tismer.com> <3E45A8C0.7060701@tismer.com> Message-ID: On Sun, 9 Feb 2003, Christian Tismer wrote: > Dave Brueck wrote: > >>listcomps are leading to "uncomprehensions". I would > >>like to see them dropped as a step in the wrong direction. > > > > Not me - when used properly they really add to the readability of my code. > > I'm glad we have 'em! > > "When used properly" applies to almost every construct. Obviously - I don't think anyone argues that. But it's simply your opinion that it lowers readability. IMO it raises it, that's all. Yay, we all have opinions. > >>The proposed syntax is counterintuitive for me by two reasons: > >> > >>a) control flow in Python always involves special characters. > >> It should at least have some markup at the start and end. > > > > That's part of the problem: you're thinking of control flow in the > > assembly-language sense and not in the Python sense. > > How is my thinking part of the problem, please? Because your original comment implied that if-expressions are for control flow. They are, but only at the lowest (bytecode or assembly language) level. In terms of program logic (what the developer is thinking about), if-expressions _aren't_ for control flow, in the normal sense of the term. > > It has no special characters because (1) the keywords used have > > the saming meaning as always and (2) it's an expression, not a statement. > > Aha. So you propose to replace + - * / ** by keywords. What in the world are you talking about? The PEP uses 'if' and 'else' - keywords that already have well-understood meaning in Python, and their meaning is the same in all contexts. I have no idea how you get from that the idea that I want to replace other operators with keywords. > >>b) reading and execution order should match as much as possible. > > > > Why? Do reading and execution order match here? > > > > x.append((x+y, w+z)) > > > > Nope! If they did, we would write it something like: > > > > x+y, w+x toTuple applyTo x.append > > Makes no sense to me. It is clear that pure left to > right evaluation would forbid any infix operators. > In the append case, everything is fine: You append a > single tuple, which happens to be created inplace. > This was one of the reasons to replace the string > module by methods, which turned bulks of execution > ordering braces into rather linear sequences of > method calls. Improvements are always posible. Ok - reread the last few paragraphs. You said that reading and execution order should match as much as possible, I'm simply pointing out that in practice that happens far less often than you think, and it doesn't seem to cause people any problems. Most likely people read whole statements at a time anyway, so in practice I doubt there's much LtoR, RtoL reading going on anyway, and if there is it's in whole groups of tokens rather than individual ones. > > But would you like to read > true-statement > if condition: > else: > false-statement > or something like that? Of course not, that's silly and overly verbose. The order of logic in the PEP isn't troubling: "use that door if it's open, otherwise use the back door" makes perfect sense. My perception is that some people react negatively to the proposed ordering more out of unfamiliarity than anything else - it doesn't take much effort to get accustomed to it. -Dave From john.abel at pa.press.net Tue Feb 25 04:38:27 2003 From: john.abel at pa.press.net (John Abel) Date: Tue, 25 Feb 2003 09:38:27 +0000 Subject: Some Python posix-related questions In-Reply-To: References: Message-ID: <3E5B3993.9040309@pa.press.net> Hi, Can only help you with no 1, I'm afraid. The easiest way, is to parse /etc/mnttab, though again, this isn't that portable, though this is basically what df does. If you do, then you could use: def GetSpace( path ): s = os.statvfs(path) return s[statvfs.F_BAVAIL] * long(s[statvfs.F_BSIZE]) Regards John Tim Daneliuk wrote: > 1) On Unix-like (posix) systems, is there some reasonably straighforward > way to get the mount information back. What I really want is: > > - The device name > - Total available space > - Available free space > - Mount point > > I would prefer to not have to parse the results of the 'df' command to > do this, since I cannot guarantee portability of the output of this > command on all systems. > > 2) What does Mac OS X return for os.name? I have a program that is > coded to work properly when os.name returns 'nt' or 'posix'. I > was kinda hoping that OS X returns 'posix' (and my program should > thus work there), as I have no access to such as system. > > TIA, > ------------------------------------------------------------------------------ > Tim Daneliuk > tundra at tundraware.com > From pyth at devel.trillke.net Wed Feb 5 12:24:15 2003 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 5 Feb 2003 18:24:15 +0100 Subject: List comprehensions' ugliness (Was: Re: How to explain exactly what "def" does?) In-Reply-To: <20030205165926.GA3783@nl.linux.org>; from gerrit@nl.linux.org on Wed, Feb 05, 2003 at 05:59:26PM +0100 References: <20030203212807.C5939@prim.han.de> <3E3EFB2B.5010503@privacy.net> <20030205165926.GA3783@nl.linux.org> Message-ID: <20030205182415.E1706@prim.han.de> Gerrit Holl wrote: > Greg Ewing (using news.cis.dfn.de) schreef op dinsdag 4 februari om 00:32:39 +0000: > > List comps themselves aren't ugly, but abusing them > > for things like that certainly is! (And probably > > gives them a bad name.) > > So, when exactly is a list comprehension ugly? I use them a lot in > places where I used to use filter. For example: > > filter(foo, i) --> [i for i in l if foo(i)] you mean filter(foo, l) To some of us the filter version reads much better. It actually tells exactly what is happening: the 'foo' function filters out matching elements. whereas the list comprehension [i for i in l if foo(i)] needs to be interpreted almost token by token. > What is the correct use for list comprehensions and what isn't? It's nice to use list comprehensions when you would otherwise need to use lambda constructs (anonymous functions). consider filter(lambda x: x.name.startswith('emil'), l) and [x for x in l if x.name.startswith('emil')] Here the lambda-construct starts to get more dubious because you also have to 'parse' it by hand. List comprehensions are sometimes more legible than those lambda-constructs. Of course friends of filter might argue that with class hasprefix(str): def __call__(self, arg): return arg.startswith(self) the filter version filter(hasprefix('emil'), l) again reads better. Probably this depends mostly on your programming background. If you like passing function objects around then you might prefer filter/map/reduce constructs sometimes. regards, holger From grante at visi.com Mon Feb 10 18:41:27 2003 From: grante at visi.com (Grant Edwards) Date: 10 Feb 2003 23:41:27 GMT Subject: ternary operator vote References: <200302081710.h18HA2S03849@europa.research.att.com> <20030208171639.GA10283@panix.com> <2xR1a.22206$F25.5011@nwrddc02.gnilink.net> Message-ID: <3e4838a7$0$190$a1866201@newsreader.visi.com> In article , James J. Besemer wrote: > It's not about trust. It's about avoiding the proverbial appearance of > impropriety. Psychological experiments have shown that bias can affect a > person's decision making even though the person is not conscious of the > influence. I think the vote should be controlled by a proponent of the PEP, > not an opponent. How somebody biased for the PEP any less "improprietary" than sombebody biased against it? -- Grant Edwards grante Yow! .. If I cover this at entire WALL with MAZOLA, visi.com wdo I have to give my AGENT ten per cent?? From sjmachin at lexicon.net Sun Feb 23 18:35:31 2003 From: sjmachin at lexicon.net (John Machin) Date: 23 Feb 2003 15:35:31 -0800 Subject: Yet Another Case Question References: Message-ID: Lulu of the Lotus-Eaters wrote in message news:... > "Tim Churches" wrote previously: > |You haven't had enough conversations with seven year olds lately. It's > |not self-evident at all. > |>>> count == Count > |NameError > > And THIS doesn't confuse a seven year old?! Heck, it confuses me... and > I'm old. Dave, you haven't mentioned the bitter religious wars between the O-slashers and the 0-slashers, so you can't be *really* old. The problem is one of where you drive in your peg on the scale between bit-by-bit exactness and "equivalent for the job in hand". Bitwise exact is unfortunately all too easy and all too often not a bright idea. Skip the admittedly sometimes enlightening chats with 7yos. Moving outside the domain of variable names into the real world, try talking to the computer system users and customers who are affected by sillinesses such as: (1) rejecting customer transactions because "John Citizen" != "JOHN CITIZEN" (2) rejecting customer transactions because "John Arthur" != "John Arthur" (3) doubling taxes because "000123456" != "123456" and ask them what they think of bit-by-bit exactness. Cheers, John From duncan at NOSPAMrcp.co.uk Thu Feb 27 06:05:32 2003 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 27 Feb 2003 11:05:32 +0000 (UTC) Subject: Splitting lists References: <2Vl7a.329137$AA2.12321414@news2.tin.it> Message-ID: Alex Martelli wrote in news:2Vl7a.329137$AA2.12321414 at news2.tin.it: > Yes, and I think it's the most Pythonic approach. However, it > would not impress people -- it's too clear and understandable, > so everybody can see at once what it does, and nobody will be > oohing and aahing about how "kewl" Python is. > > More impressive...: > > appenders = tl.append, fl.append > for e in lst: appenders[not fn(e)](e) > > now isn't THAT more like it...? > Kewl, but still maintaing a semblance of readability might be: >>> test = range(10) >>> def odd(x): return x%2 != 0 >>> fl = [] >>> tl = [ x for x in test if odd(x) or fl.append(x) ] >>> tl [1, 3, 5, 7, 9] >>> fl [0, 2, 4, 6, 8] >>> -- 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 wurmy at earthlink.net Tue Feb 11 12:55:47 2003 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 11 Feb 2003 17:55:47 GMT Subject: Voting for PEP 308 (was Re: For review: PEP 308 - If-then-else expression) References: <200302071714.h17HEew09033@odiug.zope.com> <3E4544F9.4011E0AB@alcyone.com> <3E461162.BC849E8F@alcyone.com> <200302091044.h19AiojL000448@ratthing-b246.strakt.com> <3E480D93.8030105@cascade-sys.com> Message-ID: I wrote: > Laura Creighton wrote: > >> Most of the people who don't care will also not be posting. Or >> voting. They're probably not reading comp.lang.python, either. I >> remember when 2.0 came out and people found out about string methods. >> A whole bunch of them came back to post articles about how they >> thought the new join syntax was really awful and ugly. They only >> cared after it got in, but enough to complain a lot. > > > Hmm, what if bools grew an if() method? We could then write: > > z = (x == y).if(whentrue, whenfalse) > > This strikes me as much more elegant than the other proposals. > > (ducking for cover, etc :-) Or rather, to be more in the spirit of the PEP and the join() method, maybe it should be: z = whentrue.if(cond, whenfalse) Of course, all objects would have to grow the if() method for this. :-) -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.awaretek.com/nowak/kaa.html Soon: http://zephyrfalcon.org/ From zhitenev at cs.vsu.ru Fri Feb 28 08:50:27 2003 From: zhitenev at cs.vsu.ru (Lexy Zhitenev) Date: Fri, 28 Feb 2003 16:50:27 +0300 Subject: Why doesn't this draw on my wxPython DC? References: Message-ID: "Brian Elmegaard" wrote in message: news:uadgg3igj.fsf at mail.afm.dtu.dk... > ================================================================ > from wxPython.wx import * > > class MyCanvas(wxScrolledWindow): > def __init__(self, parent, id = -1, size = wxDefaultSize): > wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER) > > self.buffer=wxEmptyBitmap(100,100) > dc=wxBufferedDC(None, self.buffer) > dc.SetBackground(wxBrush(self.GetBackgroundColour())) > dc.Clear() > dc.BeginDrawing() > dc.DrawRectangle(10,10,100,100) > dc.EndDrawing() > > EVT_PAINT(self,self.OnPaint) > > def OnPaint(self,event): > dc = wxBufferedPaintDC(self,self.buffer) > > app=wxPySimpleApp() > frame=wxFrame(None,-1,"Test") > win = MyCanvas(frame) > frame.Show(true) > app.MainLoop() > ======================================================== > and draws a rectangle on the window. I could go on living happily, but > I would like to know why do I need a DC in both __init__ and OnPaint. You need DC to paint. You can Paint only on a Device Context. You create a buffered DC and paint on it. It is not a screen device context, but a memory one. When you paint inside OnPaint event handler, you just copy the contents of your memory dc to your paint dc. Inside OnPaint handler, only PaintDCs are available. The specifics is such. > Why do I need to have the EVT_PAINT when the docs say: > "To draw on a window from outside OnPaint, construct a wxClientDC > object."? Certainly. > Removing the event and changing the dc line in __init__ to use a > wxClientDC does not draw anything. Yes, it does. You just don't see it, because here comes OnPaint event and clears what you have painted on a ClientDC. > > What are the arguments I feed to the DC's. Buffered DC is not > mentioned anywhere in the doc AFAICS. I don't have the docs here. Maybe later I'll look for it. Generally, you need no arguments if you are _constructing_ or _getting_ a DC, and you need one or more if you are _copying_ a DC. If you construct a MemoryDC or BufferedDC, you don't need any arguments. If you want to paint on a standard DC, such as screen, client window or printer, you are getting a DC Copying, I think, doesn't need to be explained. > > Another question is what is the difference between the different > wxDC's (Paint, Client, Buffered, BufferedPaint,...)? > Roughly, use PaintDC - to paint inside OnPaint event ClientDC - to paint on the client area of the window Buffered... - to paint everything in memory and then just copy the image to a DC. used for speeding up. Read the documentation for details, or write a letter to me. I'll answer you as soon as I get to the documentation. > Could I do it without the class MyCanvas and completely procedural? I > believe not as I can't figure out what arguments to give to the > EVT_PAINT and the OnPaint if not self from a class. Does the script > itself have a 'self'? No, you can't. Your classes are derived from wxWindow. This class knows how to paint itself, and it already has a DC. You get it and use. The object of this class draws itself in a window. wxWindow class is responsible for creating it. self is an attribute of class, not of a script. Script is not a class also. However, if you dare, you can globally get a whole screen device context and paint directly on the screen, not being tied to a window. You can dare to get a device context, associated with another window, but I guess you shouldn't! Remember, your application won't work, you won't get any DC if you has not constructed a wxApp instance already. > Now when I have got it running I would like to be able to click on > items on the window, open an entry and write the input on this on the > DC. > I make a left down event reacting with: > def OnLeftDown(self,event): > dlg = wxTextEntryDialog(frame,"Write here","Entry","") > dlg.ShowModal() > > I then would like to draw the output from dlg.GetValue() on the DC, > but a new wxBufferedDC written exactly as in __init__ doesn't draw. Why? Right now, I can't figure it out. > > A lot of questions which I hope someone will give me some information > on. > Contact me. Lexy zhitenev at cs.vsu.ru From antonmuhin at sendmail.ru Thu Feb 6 07:04:16 2003 From: antonmuhin at sendmail.ru (Anton Muhin) Date: Thu, 06 Feb 2003 15:04:16 +0300 Subject: opening a file opens it in Notepad In-Reply-To: References: Message-ID: Lance wrote: > Hi All, > > I'm running PythonWin build 148 on Windows XP. > > The following results in the file being opened in Notepad! This confuses me > greatly. I simply want the file handle. My next line is to read the file > into a string, using f1.read() > Any suggestions will be appreciated. > > Also, I have a number of files in srcfiles. I imagine I must issue > f1.close() each time in the loop, yes? > > for file in srcfiles: > f1 = open(file,"r") > ... do stuff... > > Thanks, > Lance > > Copy-paste of your code revealed no problem, pelase send the full script. BTW, using file as a variable is really, really bad --- file is a built-in function. Your code would be better written like this: for fileName in srcfiles: f = file(fileName, "r") # file is prefered to open now HTH, Anton From mwm at mired.org Mon Feb 17 17:16:45 2003 From: mwm at mired.org (Mike Meyer) Date: Mon, 17 Feb 2003 22:16:45 GMT Subject: declaration of variables? References: <7xd6lrnw14.fsf@ruckus.brouhaha.com> Message-ID: mwilson at the-wire.com (Mel Wilson) writes: > My favorite poster child for not declaring things is: I can't resist... > def number (s): > "convert something (probably a string) to a convenient numeric type" > try: > return int (s) > except ValueError: > try: > return long (s) > except ValueError: > return float (s) > > If I had to declare things, I'd have to declare the > return type of `number`, and obviously I don't want to. With a sane strict type system, you declare it as "number", a deferred class of which int, long and float are subclasses. > Since the parameter `s` has no declared type, `number` is > safe to call with an object that's already a number, and it > can be called successfully with any class instance that has > a __int__, __long__ or __float__ method, s, on the other hand, is harder to deal with, because you're relying on the ability to dynamically test for a method, which is something relatively rare in strictly typed languages. BTW, I'd have added one more try-except clause, so that "j" would be correctly converted to a complex :-). http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lac at strakt.com Wed Feb 5 11:00:44 2003 From: lac at strakt.com (Laura Creighton) Date: Wed, 05 Feb 2003 17:00:44 +0100 Subject: Why use Python instead of Perl? In-Reply-To: Message from Skip Montanaro of "Wed, 05 Feb 2003 09:35:50 CST." <15937.12118.849295.836028@montanaro.dyndns.org> References: <2fe7b80f.0302050640.66592ae2@posting.google.com> <200302051515.h15FFxjL007100@ratthing-b246.strakt.com> <15937.12118.849295.836028@montanaro.dyndns.org> Message-ID: <200302051600.h15G0ijL007367@ratthing-b246.strakt.com> > > >> 4) Do many web-hosts allow scripts to be written in python? Tons of > >> dirt-cheap web-hosts have perl scripting, what about python? > > Laura> Depends on your defintion of 'many'. Here are some. This is far > Laura> from all of them. When you find more, let us know. > Laura> http://www.python.org/hosting/ > > Ack! I thought we had a redirect in there. That's pretty far out-of-date. > The correct page is > > http://www.python.org/cgi-bin/moinmoin/PythonHosting > > Skip Ick. I got it by going to Python.org and searching for hosting using the search facility. Is there a way to make that not be the hit? Apologies, Laura From max at alcyone.com Sun Feb 16 17:35:01 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 16 Feb 2003 14:35:01 -0800 Subject: PEP 308 - ternary operator References: <3E4FBF08.6C5734C1@alcyone.com> <3E500692.C184D5B3@alcyone.com> Message-ID: <3E501215.8721C322@alcyone.com> Wolfgang Strobl wrote: > Sure. But as I said: some constructs are an invitation for abuse. But an IOCCC entry -- specifically designed to be abusive -- is hardly good evidence that any construct will be frequently abused in _real code_. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ Only the ephemeral is of lasting value. \__/ Ionesco Official Omega page / http://www.alcyone.com/max/projects/omega/ The official distribution page for the popular Roguelike, Omega. From peter at engcorp.com Sun Feb 2 04:56:55 2003 From: peter at engcorp.com (Peter Hansen) Date: Sun, 02 Feb 2003 04:56:55 -0500 Subject: Missing tarfile Module References: Message-ID: <3E3CEB67.163CDB1A@engcorp.com> Metnetsky wrote: > > I'm trying to use the 'tarfile' module without any luck. The Python > interpreter keeps telling me: "ImportError: No module named tarfile". So > naturally I don't seem to have the module, which is slightly confusing > because I'm running version '2.2.1-17' on RedHat Linux. I'm at a loss, > suggestions would be greatly appreciated. The docs at http://www.python.org/doc/current/modindex.html don't show any tarfile module in the standard library, but I'm sure in this case Google would be your friend... :) -Peter From brian at sweetapp.com Sat Feb 22 21:14:17 2003 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 22 Feb 2003 18:14:17 -0800 Subject: .NET and Python? In-Reply-To: <3E582AB2.4040505@verizon.net> Message-ID: <00b301c2dae1$452514b0$21795418@dell1700> > Am I stuck using VB instead of Python if I am forced to go .NET? Why would anyone chose VB over C#? Cheers, Brian From tim_one at email.msn.com Sun Feb 16 23:20:17 2003 From: tim_one at email.msn.com (Tim Peters) Date: Sun, 16 Feb 2003 23:20:17 -0500 Subject: PEP-308 a "simplicity-first" alternative In-Reply-To: <3E4FB85A.C7FE3F2B@alcyone.com> Message-ID: [Erik Max Francis] > ... > We've already seen several examples from the standard library (whether > corrected later or not) that used the idiom incorrectly; I've seen exactly one, found by Andrew Koenig, where the difference was between printing "1 test" (intended) and "1 tests" (actual) -- it was truly of no consequence. > we're well past the theoretical question of whether and/or can be > misunderstood and misused. On that basis, list slicing is much more dangerous in real life, because (for example) "the idiom" list[-i:] doesn't return the last i list items when i happens to be 0, and I've seen that bug in real code many times. Pick just about any operation, and *some* real-life code has suffered due to using it incorrectly. The and/or trick simply isn't a significant source of bugs in real life (not because it's robust, but because it is fragile it's rarely used in tricky situations). A full-fledged conditional expression may or may not prove less error-prone in practice. I wager it would have squashed the inconsequential bug Andrew found, but the std library mostly uses and/or for very simple selections where its use is obviously correct, and I wager too that a full-fledged conditional expression will get used for more complicated selections. That carries risks of introducing new bugs. Regardless, since there are no known and/or bugs in current CVS (the unittest pluralization buglet was fixed 8 months ago), the introduction of a conditional expression won't improve the std library's correctness. From rnd at onego.ru Sun Feb 2 09:44:56 2003 From: rnd at onego.ru (Roman Suzi) Date: Sun, 2 Feb 2003 17:44:56 +0300 (MSK) Subject: Instance methods vs. functions and the self parameter In-Reply-To: <3E3D21DB.4080609@vip.cybercity.dk> Message-ID: What is we try to look at the types: >>> class Class: ... def method(self): ... print "I have a self!" ... >>> def function(): ... print "I don't..." ... >>> instance = Class() >>> instance.method > >>> >>> instance.method1 = function >>> instance.method1 >>> >>> Class.method2 = function >>> instance.method2 > It can be seen that attribute instance.method1 is a function, not method at all... (I made method names differ because otherwise class method is in shadow) Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.3 From tjreedy at udel.edu Fri Feb 21 11:15:54 2003 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 21 Feb 2003 11:15:54 -0500 Subject: PEP 308: "then" "else" for deprecating "and" "or" side effects References: Message-ID: "Tim Peters" wrote in message news:mailman.1045800478.31116.python-list at python.org... > [Mike Orr] > > Python has always been great in adding, not every feature, > > but a few well-chosen features that have wide applicability. > > The perceived lack of which (wide applicability) being why Guido rejected > his implementation of conditionals last time around. I can't say I've seen > many compelling use cases in this incarnation of the beast (and, no, min and > max aren't compelling -- although they would be if they weren't built in > already -- if "functions like that" were common, I'd expect to see some > examples other than min and max ). If Python did all looping by recursion, there would be many more possible uses (though no more necessity) for a ternary conditional: def fact(n): return n and n*fact(n-1) or 1 # needs a negative arg guard def sum(seq): return (len(seq) or 0) and seq(-1) + sum(:-1) # works better with head/tail linked list so no copying of tail But Python does have for, while, map, filter, reduce, file.readlines, (new) itertools, etc. in addition to min and max. Terry J. Reedy From imbosol-1045251534 at aerojockey.com Fri Feb 14 14:54:41 2003 From: imbosol-1045251534 at aerojockey.com (Carl Banks) Date: Fri, 14 Feb 2003 19:54:41 GMT Subject: PEP 308 syntax suggestions -- a matrix-based approach Message-ID: <5Qb3a.14818$wH5.13330@nwrddc04.gnilink.net> Rather than everyone suggesting their own favorite syntax for PEP 308, we could just break down all the suggestions into manageable parts. Consider the following conditional in it's C syntax: a ? b : c Possibilities for a ? b are: 1) a ? b 2) a ?? b 3) b if a 4) if a: b 5) when a: b 6) a then b 7) cond(a,b 8) if a:(b 9) cond a:(b Possibilities for _ : c are (where _ is whatever you chose for a ? b): 1) _ : c 2) _ else c 3) _ else: c 4) _ || c 5) _ | c 6) _ ! c 7) _,c) 8) c if not _ The third dimension of this matrix has two possibilities: 1) Parentheses not required 2) Parentheses required So instead of all these long, silly new syntax suggestions, we can just site our favorite combination in the matrix. At worst, we have to add a new possibility to one of the dimensions. (Personally, I prefer PEP308[1,1,1]) -- CARL BANKS From missedby2inches at gmx.net Sat Feb 8 18:29:29 2003 From: missedby2inches at gmx.net (Two Inches) Date: Sun, 09 Feb 2003 00:29:29 +0100 Subject: comp.lang.python.ternary In-Reply-To: References: Message-ID: Daniel Dittmar wrote: > As I don't think these discussions will stop even if PEP 308 gets > rejected, how about moving them to a seperate newsgroup. +1 for this most brilliant idea :-) From peter at engcorp.com Fri Feb 21 21:37:57 2003 From: peter at engcorp.com (Peter Hansen) Date: Fri, 21 Feb 2003 21:37:57 -0500 Subject: The sprit of this newsgroup! References: <3e554289$0$49101$e4fe514c@news.xs4all.nl> <3E557BAE.A660258@engcorp.com> <3E568DDF.1CB7CBA3@engcorp.com> Message-ID: <3E56E285.FEF39E57@engcorp.com> Martijn Faassen wrote: > [...] > but i figured it out all by myself and soon I can be a senior too: > > mystring = 'Hello world how are you?" > mystring = range(217) > mystring[10] = 'F' > > works!! > > but now i have a problem printing my string, I get it looking all weird like > a lot of numbers and stuff. What is happening? Ah, that's called "Unicode". It's a replacement for "bytes" which is coming into vogue these days. There's another fellow in this newsgroup who posts answers about Unicode and I'm sure he'll be along shortly to help you out. He's from somewhere Dutch, I think, like maybe Belgium? -self-newbie-referential-ly-and-unhelpful-ly yr's -Peter ;-) From max at alcyone.com Sun Feb 2 20:16:34 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 02 Feb 2003 17:16:34 -0800 Subject: List comprehension confusion... References: <483p3v8pq8vfk7jbpl2u7m314v2j4ledc5@4ax.com> Message-ID: <3E3DC2F2.171AF0E9@alcyone.com> Afanasiy wrote: > Replies to this question relating to convenience led > me to look for something like C's ternary ? operator. > > Does something like that exist in Python? FAQ: No. There are syntaxes that come close but have defects; the closer you come to the full functionality of a true conditional operator in Python, the further you get from readability, thus defeating the purpose. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ The quickest way of ending a war is to lose it. \__/ George Orwell REALpolitik / http://www.realpolitik.com/ Get your own customized newsfeed online in realtime ... for free! From elechak at bigfoot.com Fri Feb 7 03:34:44 2003 From: elechak at bigfoot.com (Erik Lechak) Date: 7 Feb 2003 00:34:44 -0800 Subject: pycrust editor Message-ID: Hello all, Sorry for asking but I have been searching for hours now. I am using wxPython and like the pyCrust shell. But I can't seem to find an editor that gives me the same type aware autocompletion as the shell ( boa constructor does, but it's a little overkill at times). I took a look at SciTE and thought that I hit the jackpot. But it does not seem to understand python as well as pyCrust (or boa contructor) even with the generated python.api file. Then I looked at the screenshot for SciTE here: http://www.scintilla.org/SciTEImage.html The screenshot is of SciTE editing a file called PyCrustEditor.py. Sounds just like what I am looking for. Does anyone know anything about this editor and where I can get it? Thanks, Erik Lechak From peter at engcorp.com Sun Feb 2 17:49:47 2003 From: peter at engcorp.com (Peter Hansen) Date: Sun, 02 Feb 2003 17:49:47 -0500 Subject: Cleanest C++ Interface to Python References: Message-ID: <3E3DA08B.FD3B1223@engcorp.com> Brandon Philips wrote: > > I am writing a custom user-level USB-HID driver for a device I created for a > research process. My colleague who is writing the gui and surrounding > software presented to the user wants to use Python for its obvious > advantages. My software is all written in "un-managed" C++ compiled with > VC++ 7.0 (or .NET). Now as I see it I have a few options to give him the > ability to call my "low-level" driver from Python: > SWIG > Embedding Python > Visual Python > > My experience with .NET is minimal so if Visual Python requires to much .NET > knowledge I would like to avoid it. So what option of the three do you > think is the easiest and most viable for an experienced C++ developer who > wants the cleanest interface to Python? Perhaps none of the three... try Googling for "python ctypes module". ? -Peter From hst at empolis.co.uk Tue Feb 25 08:00:03 2003 From: hst at empolis.co.uk (Harvey Thomas) Date: Tue, 25 Feb 2003 13:00:03 -0000 Subject: autoincrementing Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB53BC4C@hendrix.empolisuk.com> Dale Strickland-Clark wrote > > Alex Martelli wrote: > > > > >For the same reason i?!@ doesn't work -- there is > >no ++ operator in Python, just as there is no ?!@ > >operator (and MOST other sequences of special symbols > >and punctuation are also not operators, thanks be). > > > >Writing one more character to code +=1 instead of ++ > >is no great hardship, and it would be absurd for > >Python to introduce a special operator just for the > >purpose of saving that one character. > > > > > >Alex > > That is not the point of auto-increment (and I'm sure you must know > this) > > intPrev = intNew++ > > is equivalent to: > > intPrev = intNew > intNew += 1 > > Rather more than one character saved. And there are times when it can > save you a lot more than that, too. > -- > Dale Strickland-Clark > Riverhall Systems Ltd > -- Surely, the main point is that i += 1 is an assignment statement and i++ is an expression. Python makes a clear distinction between expressions and functions. Implementing i++ would give in-line assignment which the BDFL is apparently set against (so am I in the form if a = b..., but wouldn't mind if a := b...). _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From davecook at nowhere.net Tue Feb 25 13:37:39 2003 From: davecook at nowhere.net (David M. Cook) Date: Tue, 25 Feb 2003 18:37:39 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Feb 24) References: <3E5B80EA.5050101@indy.rr.com> <3E5B8EC8.264EF159@engcorp.com> Message-ID: In article <3E5B8EC8.264EF159 at engcorp.com>, Peter Hansen wrote: > Tim Ottinger wrote: >> >> BTW: comp.object has spawned threads on python recently. >> It's partly my fault, but it wasn't really my intent. >> It would not hurt to have a few python experts in the >> discussion, especially as regards the "python is slow" bit. > > Oh god! Not comp.object. _Anything_ but comp.object. :-( It seems to be a whole newsgroup full of Brandon Van Every types. Dave Cook From eppstein at ics.uci.edu Mon Feb 10 12:59:01 2003 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 10 Feb 2003 09:59:01 -0800 Subject: PEP308: Yet another syntax proposal References: <9pR1a.22187$F25.13842@nwrddc02.gnilink.net> Message-ID: In article , aahz at pythoncraft.com (Aahz) wrote: > You're missing the point. How frequently does this occur such that > getting all our knickers in a twist is worth it? So far, most of the > examples pushing a conditional expression have *NOT* required > short-circut behavior. For the cases where side-effects restrict the > use of a conditional expression, I think perhaps requiring the use of an > if statement is the most appropriate way to handle it. My feeling is that the reason for short circuiting isn't so much because of side effects (I think we should try to keep expressions as free of side effects as possible) but because one or both of the two sides may be undefined and raise an exception if the guard condition is not met. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From sismex01 at hebmex.com Mon Feb 24 17:40:25 2003 From: sismex01 at hebmex.com (sismex01 at hebmex.com) Date: Mon, 24 Feb 2003 16:40:25 -0600 Subject: Case sensitivity Message-ID: > From: alloydflanagan at attbi.com [mailto:alloydflanagan at attbi.com] > Sent: Monday, February 24, 2003 4:36 PM > > OTOH, I like the idea of forbidding variable names that differ only in > case, seems to me it would eliminate silly mistakes and could be > enforced on the 'compile'. > It could be an option for PyChecker. -gus From dave at pythonapocrypha.com Mon Feb 10 15:35:36 2003 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 10 Feb 2003 12:35:36 -0800 (PST) Subject: PEP308: Yet another syntax proposal In-Reply-To: <20030210194154.C1706@prim.han.de> References: <20030210194154.C1706@prim.han.de> Message-ID: On Mon, 10 Feb 2003, holger krekel wrote: > > Short-circuit evaluation is never "necessary" in _any_ language - it's > > just very, very useful sometimes. Python's 'and' operator doesn't _have_ > > to be a short-circuit operator, but it's far more useful because it is. > > > > > and therefore iif() unreasonable. > > > > Several of the previous examples have already illustrated this: > > > > z = iif(x, x.getPref(), 'Not specified') > > > > is broken without short-circuiting. > > yes, but it is easily written with an and-expression > > z = not x and 'Not specified' or x.getPref() Yikes! The above line of code is a great argument _in favor of_ if-expressions on the basis of readability and maintainability. I couldn't encourage anyone to use that form. > and a ternary op would simply add another possibility. ...and hopefully deprecate the usage of your above example, the "simulated conditional expression". -Dave From max at alcyone.com Tue Feb 11 21:50:18 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 11 Feb 2003 18:50:18 -0800 Subject: ternary operator vote References: <200302081710.h18HA2S03849@europa.research.att.com> <20030208171639.GA10283@panix.com> <2xR1a.22206$F25.5011@nwrddc02.gnilink.net> <3E487291.70FDD1B6@alcyone.com> <3E498B0A.970ED285@alcyone.com> Message-ID: <3E49B66A.E7C72BD2@alcyone.com> Bengt Richter wrote: > But you can't express an opinion that says, "I'm willing to accept > C or D or no change, but I am dead set against B." Sure you can, you just don't vote for that. The +1 ... -1 responses you see in the newsgroup are just shorthand for people expressing their like, dislike, or anything in between. This is actually fairly common for PEP discussions and has nothing to do with this particular PEP. So far no voting process suggested (that I've seen) except yours would involve people expressing the -1 ... +1 values on the _votes_ themselves; you'd, like any voting process, vote for or against something or abstain, or in the case of approval voting, vote for as many of the alternatives as you like. > BTW, we could vote by just posting to a special voting > thread with some formatted lines from an official template like Yes, making a voting template and taking the actual vote itself is very straightforward. > Actually, I'd like to be able to weight E, F, and G differently. > Perhaps > we could have three columns for different voting marks, the first for > pure > approval 0/1 style, the second for {-1,-0,+0,+1} and another for > +-cents > of a total voting budget of one voting dollar per choice. Okay, so in this process where you can vote between -1 and +1 on any or all of the alternatives, what in the world is the distinction between +0 and -0? What's the difference between entering a 0 and leaving the entry blank? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ Do not seek death. Death will find you. \__/ Dag Hammarskjold Esperanto reference / http://www.alcyone.com/max/lang/esperanto/ An Esperanto reference for English speakers. From phr-n2003b at NOSPAMnightsong.com Sun Feb 9 03:34:04 2003 From: phr-n2003b at NOSPAMnightsong.com (Paul Rubin) Date: 09 Feb 2003 00:34:04 -0800 Subject: For review: PEP 308 - If-then-else expression References: <200302071714.h17HEew09033@odiug.zope.com> <3E460511.AB633977@alcyone.com> Message-ID: <7x3cmx7szn.fsf@ruckus.brouhaha.com> Erik Max Francis writes: > A strict analysis of how frequently a construct will be used shouldn't > be the sole deciding factor in whether or not it gets introduced into > the language. Certainly not the sole factor, but it does have some relevance. I don't know whether analyzing already-written code is the right way to measure it either. I find on a fairly regular basis that I get annoyed by not having a conditional expression in Python. Maybe it happens once ever few weeks of coding. That's enough to notice, and to be supportive of efforts to add it. It's like if I get a telemarketing phone call every few weeks--it's not a night and day source of agony, but it would be nice to be able to get it to stop. I'd say every time I write code with regexps, I want an assignment expression like while (m := re.match(exp, something)): ... so if I could add just one construct, assignment expressions or conditional expressions, I'd probably take assignment expressions even though they don't do as much from a functional programming point of view. I'm not a coding robot or lumberjack-style coder. I like to enjoy myself when I code, and to massage code around til it looks nice on the screen. It's like eating potato chips one after another. Hitting some silly limitation of the language is like getting a potato chip that tastes terrible. If every 500th potato chip has some awful taste that makes you go "ptui", it messes up your enjoyment of the other 499. It's a separate issue from whether you need all 500 for nourishment. From imcmeans at telus.net Tue Feb 25 19:13:11 2003 From: imcmeans at telus.net (Ian McMeans) Date: Wed, 26 Feb 2003 00:13:11 GMT Subject: profiling threads References: Message-ID: I forgot to mention: If something is using 100% of my CPU time while the program is running, shouldn't it show up in the profiler? From mwh at python.net Wed Feb 5 10:10:42 2003 From: mwh at python.net (Michael Hudson) Date: Wed, 5 Feb 2003 15:10:42 GMT Subject: Python's 8-bit cleanness deprecated? References: <3E405EAD.304EDF73@alcyone.com> Message-ID: <7h3ptq6u5lj.fsf@pc150.maths.bris.ac.uk> Erik Max Francis writes: > Roman Suzi wrote: > > > That is why I am asking for unconditional raw 8-bit cleanness of > > Python > > without any -*- things... > > Personally, I think it's an extremely good idea. Me too. I'll also observe that editing files in GNU Emacs 21 that have characters with the high bit set and don't have a coding cookie is exceptionally annoying so putting the coding in not only soothes Python, but also potential contributors. Cheers, M. -- Unfortunately, nigh the whole world is now duped into thinking that silly fill-in forms on web pages is the way to do user interfaces. -- Erik Naggum, comp.lang.lisp From NOSPAMebo at unicornDOTdemonDOTnl Fri Feb 7 14:13:12 2003 From: NOSPAMebo at unicornDOTdemonDOTnl (Ebo) Date: Fri, 07 Feb 2003 20:13:12 +0100 Subject: For review: PEP 308 - If-then-else expression References: Message-ID: > Examples of how this works out: > > x if C else y if D else z <==> x if C else (y if D else z) > x or y if C else z <==> (x or y) if C else z > x if C else y or z <==> x if C else (y or z) > lambda: x if C else y <==> lambda: (x if C else y) > x if C else lambda: y <==> SyntaxError > x if C else y, z <==> (x if C else y), z > x, y if C else z <==> x, (y if C else z) > Hi all, Allthough I think this form of if statements could be useful in some cases, I seriously doubt whether Python really _needs_ this _feature_. Apart from this construct looks rather unpythonic. So, unless some really good arguments come along, I'd vote nay... $0.02 E. From mlh at furu.idi.ntnu.no Fri Feb 21 22:56:35 2003 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 22 Feb 2003 03:56:35 +0000 (UTC) Subject: itertools comments [Was: Re: RELEASED: Python 2.3a2] References: Message-ID: In article , Chad Netzer wrote: [snip] >At least there is now an izip() in itertools (although, again, I would >prefer the 'x' naming, or the addition of irange() and the deprecation >of xrange()) ... and xreadlines()... -- Magnus Lie Hetland "Nothing shocks me. I'm a scientist." http://hetland.org -- Indiana Jones From dubois at users.sourceforge.net Sat Feb 8 13:40:49 2003 From: dubois at users.sourceforge.net (Paul F. Dubois) Date: Sat, 08 Feb 2003 18:40:49 GMT Subject: For review: PEP 308 - If-then-else expression References: <200302071714.h17HEew09033@odiug.zope.com> <200302080622.h186MJjL022026@ratthing-b246.strakt.com> <20030208131934.I1706@prim.han.de> <200302081422.h18EMdp02970@europa.research.att.com> <20030208160000.N1706@prim.han.de> Message-ID: "Dave Brueck" wrote in message news:mailman.1044726939.7430.python-list at python.org... > I guess I'm just emphasizing that, for or against the PEP, we should all > be careful about including "increased readability" in our list of reasons > - if you had been using if-expressions all along you would probably > consider them to be quite readable. Now, exuse me while I go argue some > more that if-exprs can make code more readable. ;-) > I remember all the people who wrote that list comprehensions were unreadable. Curious, when I recently presented this to a room full of scientists who use Python as a new feature, all I heard was, "Oh, Thank God!". I think we should distinguish the amount of cognitive effort involved to see the meaning of something. People who argue that one can already say things like condition and xor y are assuming the reader posseses a knowlege of the semantics of the 'and' and 'or' (for example, that condition and x is x if condition is true, whereas it might well be a 1 if you don't know otherwise) and the and/or precedence. Sure, I can figure it out, but that isn't the point. The point is, can I read it without employing too much of my higher-level thinking processes. By contrast, x if condition else y requires learning the thing once, after which it would be really hard to mistake it. From abelikov72 at hotmail.com Tue Feb 4 16:50:32 2003 From: abelikov72 at hotmail.com (Afanasiy) Date: Tue, 04 Feb 2003 21:50:32 GMT Subject: global threading.Lock not locking correctly? References: Message-ID: <3kd04vsen5gv7h755a6avkqas2kce78e1n@4ax.com> On Tue, 04 Feb 2003 14:22:01 -0500, Tim Peters wrote: >[Afanasiy] >> I am replying to this just to answer your question. My question was >> already answered. However, I am now curious what I should have said >> instead of "P.S. this is simplified example code". I am finding it >> difficult to communicate here and I consider my English excellent. > >Grant explained it well. Your "P.S. this is simplified example code" added >no information, so it's natural to question why you wrote it. The usual >answer to that is (as Grant explained) that it's not actually code you've >run. The dictionary entry for 'example' seems to make sense for this purpose. Is there another adjective, short of "but it reproduces the symptoms" ? From vvainio at tp.spt.fi Fri Feb 14 06:08:47 2003 From: vvainio at tp.spt.fi (Ville Vainio) Date: 14 Feb 2003 03:08:47 -0800 Subject: Speeding up ftp, async/threadpool? References: <84b9dff5.0302130818.50a36ef3@posting.google.com> Message-ID: vvainio at tp.spt.fi (Ville Vainio) wrote in message news:... > BTW, your name sounds vaguely familiar from ICQ something like 8 years > ago ;-). ...and of course I meant IRC. From mykbourassa at cogeco.ca Fri Feb 21 23:47:06 2003 From: mykbourassa at cogeco.ca (myk) Date: Fri, 21 Feb 2003 23:47:06 -0500 Subject: Python IDE ERIC3 In-Reply-To: References: Message-ID: I gave Eric a miss for the same reasons as you described. You might try Boa-constructor at Sourceforge but you need to get the latest CVS as the Windows .exe for 0.2.0 doesn't work properly. I've had a nice time with Eclipse though with the Python plug-in. It isn't fancy but it does nice basic editing. Hope that helps. myk Ken Godee wrote: >>>I have tried to install this on Windows and run into a lot of problems. >>> >>>First of all I had to install: >>> >>>Qt (latest version but it is a demo - the non commercial version doesn't >>>work with QScintilla) >>>SIP >>>PyQt >>>QScintilla >>> >>>PyQt doesn't build properly, maybe because it is meant for the >>>non-commercial version of Qt (version 2.3!) but then QScintilla requires >>>Qt >>>3 or above. >>> >>>The thing is I don't even want to develop any Qt software so I don't want >>>the whole SDK installed. I've looked for a simple binary runtime download >>>on >>>the Trolltech site but they don't seem to have one! It would be a good >>>idea >>>to make a binary package of Eric3 (ie. with PyQt extension prebuilt and >>>Qt , >>>QScintilla runtime components only (just the dlls)). Maybe put Qt and >>>QScintilla in a separate download in case people already have them. >>> >>>It looks an excellent IDE by the look of the screenshots. I'm sure you >>>would >>>have much more users if it was easier to install! >>> >>>John >>> >>> >>Don't get me started.... >> >>I agree - it might be more popular if it was possible to install it. Keep >>in mind however, it is not licensed to be run under Windows because Qt is >>not GPL'd for Win32. I was reminded of this and was told to stop trying to >>install it on Windows. Also, even if you could get it installed, I don't >>think it was even tested or coded to run on Win32 so it probably has all >>kinds of gotchas. >> >>I also tried a fresh install of Linux for the sole purpose of checking this >>IDE out and gave up after 3 days of failing to satisfy all dependencies. >>The older verison went in no problem, but it lacks most of the features of >>v3. You are not alone in your installation woes... >> >> > >I'll step in and say "Eric3" is an outstanding piece of work >and I've installed it on three different Linux (rh7.3) machines and >had no problems at all! My only suggestion is to make sure >to read the readme's and use CURRENT snapshots of QScintilla, >sip, eric3 and PyQt, there's been alot of changes in these programs >in the last couple of months. The whole install takes about a couple >of hours and is a great setup! > PyQt does not work with the Qt Demo version (linux or win) >you must run gpl or commerical version w/commercial version of >PyQt. >Don't pass it up, it's a cool program. > > > From frobozz_electric at hotmail.com Thu Feb 13 10:12:01 2003 From: frobozz_electric at hotmail.com (Sean Ross) Date: Thu, 13 Feb 2003 10:12:01 -0500 Subject: Never mind (was Re: a "generic" problem) References: Message-ID: Hi. Never mind that last post, I've figured out what I was doing wrong. Thanks for your help. Sean From chastel_pelerin at hotmail.com Thu Feb 6 05:57:21 2003 From: chastel_pelerin at hotmail.com (Jason Smith) Date: 6 Feb 2003 02:57:21 -0800 Subject: Why does Dynamic Typing really matter?!? Message-ID: <623cd325.0302060257.1542e098@posting.google.com> Hi All I'm doing some research into language constructs, particularly dynamic typing. What I'm looking for are examples in dynamically typed languages that clearly illustrate the benefits that dynamic typing give to a solution to a problem. I'm aware that dynamic typing provides the following, But what I want need is an solution to a problem that would not be possible to replicate in a statically typed language... Can anyone pt me in the right direction or provide a small example? Thanks Jason. From fredrik at pythonware.com Sat Feb 8 09:54:41 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Feb 2003 15:54:41 +0100 Subject: How best to handle Unicode where only 8-bit chars are now? References: <15940.37847.263991.794301@montanaro.dyndns.org> Message-ID: Skip Montanaro wrote: > The csv module supporting PEP 305 doesn't do Unicode yet. All string > manipulation is currently done using null-terminated C strings for speed. > I'm looking for suggestions about how best to incorporate Unicode string > handling into the code. I see three possibilities: > > 1 Try and treat unicode objects the same as string objects - extract the > raw data and handle them as bytes. > > 2 Provide two different state machines, the current fast one which > operates only on C strings representing ASCII data and a slow one > which operates on unicode objects. > > 3 Rewrite the state machine to operate at the level of string or unicode > objects even though it will slow down the common case significantly. > > Option 1 seems doomed because you'd be trying to mix processing of wide and > narrow characters. Option 2 seems the least disruptive, but if somehow a > unicode object snuck into the system (say, a single field was unicode or the > delimiter was specified as u'"' even though it was really ASCII), the whole > system might mysteriously slow down. Option 3 seems the cleanest, but would > slow everything down significantly because character extraction and > comparison would require a function call instead of an array index operation > or a simple comparison. what makes you think 8-bit == fast and unicode == slow? have you looked at SRE? it compiles portions of itself twice, to get 8-bit and unicode versions of the core engine. on modern machines, the unicode version often runs *faster* than the corresponding 8-bit code. From darren at coolpink.net Sun Feb 23 17:47:42 2003 From: darren at coolpink.net (Darren Watson) Date: 23 Feb 2003 14:47:42 -0800 Subject: Compiling Python with Tk Support Message-ID: <3a427488.0302231447.79cc3fbf@posting.google.com> Hi I'm trying to compile python with Tk support on Red Hat Linux with Python 2.3a2. I have built and installed tcl 8.4 and tk 8.4, but when I try and make Python I get: ./python: error while loading shared libraries: libtk8.4.so: cannot open shared object file: No such file or directory However this file does exist in /usr/local/lib/libtk8.4.so I have uncommented the _tkinter lines in the Modules/Setup file, but I can't work out why this isn't working. I also have Python 2.2.1 installed, but I am trying to install the latest version to /home/darren/python2.3 using ./configure --prefix=/home/darren/python2.3 I would appreciate any advice to help sort this problem out. Regards Darren From aleax at aleax.it Wed Feb 5 08:22:58 2003 From: aleax at aleax.it (Alex Martelli) Date: Wed, 05 Feb 2003 13:22:58 GMT Subject: where python is slower? References: Message-ID: Enrique Palomo wrote: ... > I would like to know where python is slower, reading files, writing, > string manipulation... None of the above. File I/O speeds are essentially determined by your disk, operating system and runtime library (and Python uses the C runtime library), and string manipulation is quite well optimized in Python -- it's unlikely, in general, that you can easily code custom C code to do much better (in a few very special cases it might be possible, because Python strings are immutable -- if the specific manipulation you need is, e.g., "change the 277th character into a 'K'", then C lets you do that in-place while Python requires making a new string object). Alex From bob_jones2002uk at yahoo.co.uk Wed Feb 26 09:38:38 2003 From: bob_jones2002uk at yahoo.co.uk (bob) Date: 26 Feb 2003 06:38:38 -0800 Subject: Introduction to Socket Programming on Python Message-ID: Hi all, Can anyone recommend a good online introduction (with plenty of examples) to socket programming in Python? I've looked at the Socket HOWTO, but it moves quite quickly and doesn't have a lot of hands programming in it. Thanks, B. From max at alcyone.com Wed Feb 12 03:10:39 2003 From: max at alcyone.com (Erik Max Francis) Date: Wed, 12 Feb 2003 00:10:39 -0800 Subject: PEP 308 vote type (was Re: Update to PEP308: if-then-else expression) References: <002201c2d17c$3c084500$530f8490@eden> <8v4ph-u24.ln1@beastie.ix.netcom.com> Message-ID: <3E4A017F.E3911931@alcyone.com> Dennis Lee Bieber wrote: > Andrew Koenig wrote: > > > Disapproval of all of the alternatives except "no change". > > Which still doesn't handle the case of "I can live with any of > these EXCEPT x" Sure it does. Mark every entry except the one(s) you are dead-set against. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ So look into my eyes / I won't tell you lies \__/ Neneh Cherry HardScience.info / http://www.hardscience.info/ The best hard science Web sites that the Web has to offer. From max at alcyone.com Mon Feb 10 02:37:37 2003 From: max at alcyone.com (Erik Max Francis) Date: Sun, 09 Feb 2003 23:37:37 -0800 Subject: For review: PEP 308 - If-then-else expression References: <7xbs1nibfz.fsf@ruckus.brouhaha.com> <3E46F19E.2F0DF737@alcyone.com> <3E47171C.D141F528@alcyone.com> <3E472A30.A7B976DF@alcyone.com> <3E47390E.B3A060A8@alcyone.com> Message-ID: <3E4756C1.F1F7E948@alcyone.com> Andrew Koenig wrote: > I think we agree. ... > Again, I think we agree. I think the behavior should be whatever is > easiest to describe. Indeed we do. > I'd still be willing to live with `x if C else y', because I think > it's much better than `C and x or y'. Practically any real conditional operator would be better than `C and x or y', because `C and x or y' is _wrong_ (as you have so eloquently pointed out many times in these threads). -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ No man quite believes in any other man. \__/ H.L. Mencken Alcyone Systems / http://www.alcyone.com/ Alcyone Systems, San Jose, California. From v.wehren at home.nl Sat Feb 1 10:25:53 2003 From: v.wehren at home.nl (vincent wehren) Date: Sat, 1 Feb 2003 16:25:53 +0100 Subject: Running a Tkinter GUI in WIN98 without the useless DOS window? References: Message-ID: "Jack Crane" schrieb im Newsbeitrag news:Xns9315316F1819Ejdcrane7yahoocom at 130.133.1.4... > "vincent wehren" wrote in > news:b1gbar$o6g$1 at news3.tilbu1.nb.home.nl: > > > "Jack Crane" schrieb im Newsbeitrag > > news:Xns93151D69F34FAjdcrane7yahoocom at 130.133.1.4... > >> Can a Tkinter GUI be run in Win98 without the useless DOS window? I'm > >> not sure if I expressed that correctly or clearly, but I am using the > >> Python script at > >> http://answers.google.com/answers/main?cmd=threadview&id=121280 , > >> calling it with a shortcut to grepper.py. Grepper works well, but is > >> there a way to call grepper.py without that useless DOS window opening > >> as well? > > > > Try calling your modules *.pyw instead of *.py. > > Nope. Still get the DOS window. > Well, I don't... How are you starting the module exactly? Vincent Wehren > > (BTW: I wouldn't call the command prompt useless..Once you run your > > code as *.pyw any exceptions that you do not particularly catch and > > output via a Tkinter message box will never surface. So I'd leave the > > *.pyw suffix alone during the entire process of writing/debugging, and > > rename the when *ready* to deploy...) > > Thanks for this info. > > Jack Crane > jdcrane7 at yahoo.com From peter at engcorp.com Mon Feb 10 13:12:32 2003 From: peter at engcorp.com (Peter Hansen) Date: Mon, 10 Feb 2003 13:12:32 -0500 Subject: PEP 308: Alternative conditional operator forms References: <3E46F0CE.5675E180@alcyone.com> <2259b0e2.0302100926.5e0d9dc5@posting.google.com> Message-ID: <3E47EB90.65E212BD@engcorp.com> Michele Simionato wrote: > > Erik Max Francis wrote in message news:<3E46F0CE.5675E180 at alcyone.com>... > > I'd like to build an exhaustive (or nearly so) of forms of the > > conditional operator that have been made so far that people have thought > > had _some_ merit (i.e., ones that were proposed and which someone other > > than the proponent indicated they thought might be a good idea), and > > those which Guido has not already absolutely dismissed (such as C ? x : > > y). I'd like to do this both for my own edification in seeing them all > > in one place and for a potential second vote on the desired form (should > > the process get that far, of course). (I'm also putting aside for the > > moment the issue of the introduction of new keywords or punctuation, or > > the appearance of chained conditional operators.) > > > > Erik, thanks for offering your time to prepare the list. However, I think we > should first make sure that there is a majority of Pythonistas favorable to > the introduction of the ternary operator. There is no point in arguing > between us about the more pythonic solution if 80% of users are already > against the ternary operator. I would think you could consider Erik's efforts to be focusing on the secondary question of "how to do it", just for that potential 20% (which is likely larger, but that's another story) who do want the ternary operator. Don't stop someone who already knows he wants it from putting together a list that will help likeminded people agree on the preferred syntax for that operator. > I think there is a big majority not > posting on c.l.p that could be contrary to the innovation and don't > bother to sent verbose postings. I fear this majority could kill > us at the voting moment (and maybe Guido counts on that). "counts on that"? That ascribes a somewhat underhanded approach to this whole thing to someone who appeared to be very open and upfront about the whole issue. Or am I misinterpreting your comment? I don't understand all the comments about who can be trusted to manage the voting, who has ulterior motives, etc... this isn't *that* big a deal, is it? This is the discussion phase, where people's opinions can be swayed (even repeatedly :-) and some of the sillier arguments can be eliminated. After the dust settles, either a consensus emerges, or the need to vote is clear and we can proceed to that step. It doesn't really seem we're there yet, to me. -Peter From reageer.in at de.nieuwsgroep Mon Feb 10 09:10:52 2003 From: reageer.in at de.nieuwsgroep (Rene Pijlman) Date: Mon, 10 Feb 2003 15:10:52 +0100 Subject: zope documentation References: <7tqe4vsbe5h549gd7v1hgnp6hfaddogaqu@4ax.com> Message-ID: tom thumb: >thanks, very helpful! You're welcome. I forgot to add that these are the books I selected myself recently based on online reviews etc. There are some other books as well (search for "zope" at Amazon), but the titles I mentioned appeared to be a good selection. -- Ren? Pijlman Wat wil jij leren? http://www.leren.nl From jjgalvez at ucdavis.edu Thu Feb 13 13:01:32 2003 From: jjgalvez at ucdavis.edu (Jose Galvez) Date: Thu, 13 Feb 2003 10:01:32 -0800 Subject: Does anyone know how to use spawn with OSX? References: <20030212215029.0000429d.Jose@somplace.com> <7h3u1f8tid6.fsf@pc150.maths.bris.ac.uk> Message-ID: HMM then I must be doing something wrong, I am trying to use it to copy some files with the ditto command and when I run the command I get back what I am assuming is a PID but nothing happends (at least the files I wanted copied don't seem to be copied). I'll give it an other try and see what happends Jose "Michael Hudson" wrote in message news:7h3u1f8tid6.fsf at pc150.maths.bris.ac.uk... > Jose writes: > > > Does anyone know how to use spawnv with OSX, specifically jaguar? > > The same as on any other unix... if you want to launch a GUI app, I > think you want to shell out to 'open'. > > Cheers, > M. > > -- > Python enjoys making tradeoffs that drive *someone* crazy . > -- Tim Peters, comp.lang.python From mwh at python.net Mon Feb 10 10:51:09 2003 From: mwh at python.net (Michael Hudson) Date: Mon, 10 Feb 2003 15:51:09 GMT Subject: keypressed... References: <3E470F40.F5F73039@engcorp.com> <3E472894.789CFF65@alcyone.com> Message-ID: <7h3n0l4xhiu.fsf@pc150.maths.bris.ac.uk> gabor writes: > On Mon, 2003-02-10 at 05:20, Erik Max Francis wrote: > > gabor wrote: > > > > > sorry, linux here.... > > > > > > any info on that platform ? > > > > curses would probably be your best bet there. > yes, at the end i used curses, and it works nicely, thanks... > > i just thought that maybe there's a simpler solution not needing > curses.... Not really. You can muck with terminal settings and ioctl calls if you really want to avoid curses. It's not really hard, but it's fiddly and tedious. Cheers, M. -- "Well, the old ones go Mmmmmbbbbzzzzttteeeeeep as they start up and the new ones go whupwhupwhupwhooopwhooooopwhooooooommmmmmmmmm." -- Graham Reed explains subway engines on asr From raims at dot.com Sun Feb 2 10:51:28 2003 From: raims at dot.com (Rhymes) Date: Sun, 02 Feb 2003 16:51:28 +0100 Subject: Newbie question - Python mode in SciTE ? References: <3E3D289A.1010201@wanadoo.fr> Message-ID: On Sun, 02 Feb 2003 15:18:02 +0100, Henri Chorand wrote: > My question is, what should I do in order to specify Python as my source > language, or does SciTE recognize the source language from the file > extension, or else... You don't need any special properties..just select your favourite language from Language menu and start coding... And then use the Tools menu to execute your source file For special settings see docs on the web -- Rhymes rhymes at NOSPAMmyself.com From davidw at dedasys.com Thu Feb 27 13:22:07 2003 From: davidw at dedasys.com (David N. Welton) Date: Thu, 27 Feb 2003 18:22:07 GMT Subject: get directory name of file being executed References: <87u1eqmfkz.fsf@dedasys.com> <6qznoh4orb.fsf@salmakis.intevation.de> Message-ID: <87heapmvm6.fsf@dedasys.com> Ok, either one of those solutions works for me! Thankyou kindly for the answers. -- David N. Welton Consulting: http://www.dedasys.com/ Personal: http://www.dedasys.com/davidw/ Free Software: http://www.dedasys.com/freesoftware/ Apache Tcl: http://tcl.apache.org/ From ark at research.att.com Tue Feb 11 19:18:13 2003 From: ark at research.att.com (Andrew Koenig) Date: Wed, 12 Feb 2003 00:18:13 GMT Subject: ternary operator vote References: <200302081710.h18HA2S03849@europa.research.att.com> <20030208171639.GA10283@panix.com> <2xR1a.22206$F25.5011@nwrddc02.gnilink.net> <3E487291.70FDD1B6@alcyone.com> <3E498B0A.9 Message-ID: Erik> Quite frankly, I think Andrew's hit the nail on the head. This Erik> really sounds like they way to go, since it eliminates the Erik> question of fracturing communities _and_ allows people to Erik> simultaneously vote for several alternatives (internally I was Erik> thinking of something more like listing the alternatives and Erik> saying, "Choose one to three, and rank them," but I think this Erik> works much better). It is possible to arrange a vote with "choose one to three, and rank them", but much more complicated. Please visit at www.electionmethods.org and go to the descriptions of approval voting and Condorcet voting, respectively. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From hamonlypaulpaterson at houston.rr.com Sat Feb 8 13:00:50 2003 From: hamonlypaulpaterson at houston.rr.com (Paul Paterson) Date: Sat, 08 Feb 2003 18:00:50 GMT Subject: For review: PEP 308 - If-then-else expression References: <5DV0a.34649$CF1.1127662@news20.bellglobal.com> <2259b0e2.0302080516.1c577eb2@posting.google.com> Message-ID: "Andrew Koenig" wrote in message news:yu997kcaaezk.fsf at europa.research.att.com... > Sean> Personally, I don't mind > > Sean> if (y, x)[C]: > Sean> ...do stuff... > > Sean> although I don't consider it to be either obvious or clear. > > I *do* mind it, for two reasons: > > 1) It puts the false condition ahead of the true condition. > This is a very good point. I am somewhat in favour of the "outcomes before conditions" ordering but your objection here is very good - the first outcome should be the normal one (if relevant). What about, val = *some syntactic identifier* (sqrt(a), 0)[a>=0] # returns sqrt(a) if a>=0 word = *some syntactic identifier* ("one", "two", "many")[num==1, num==2] In fact (without lazy evaluation), this could be done now with a suitable function. import sys class choicedict(dict): def __getitem__(self, key): """Get the item with key as a tuple of logicals""" try: length = len(key) except TypeError: key = [key] length = 1 for item in range(length): if key[item]: return dict.__getitem__(self, item) return dict.__getitem__(self, len(key)) def select(*choices): return choicedict(zip(xrange(sys.maxint), choices)) for i in (0, 1, 2, 3, 10): print i, select("none", "one", "two", "many")[i==0, i==1, i==2] Of course, the non-lazy evaluation really kills you on, print select(sqrt(a), 0)[a>=0] # ValueError: math domain error From vze4rx4y at verizon.net Thu Feb 20 17:02:51 2003 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Thu, 20 Feb 2003 22:02:51 GMT Subject: PEP 308: ternary operator References: <3e54e545$0$71606$edfadb0f@dread11.news.tele.dk> Message-ID: > "Terry Hancock" wrote: > > 1) Is it ? : or : ? > > I can never remember this! > > and are answers, is the question. > The question is followed by a question mark. > > Quite logical, actually. > > - Anders Also, the use of c?a:b in other languages is an important consideration so that skills are transferrable both to and from Python. That syntax is used in enough other places to make it a valuable thing to know. Raymond Hettinger From imbosol at aerojockey.com Wed Feb 12 19:34:25 2003 From: imbosol at aerojockey.com (Carl Banks) Date: Thu, 13 Feb 2003 00:34:25 GMT Subject: PEP 309 - Built-in closure type (with tentative syntax proposal) References: <3E481CE1.7050406@blueyonder.co.uk> Message-ID: Peter Harris wrote: > My proposal is for a built-in closure type for Python, and > a syntax for closure literals. > > The reference implementation for the easy part is just: > > class closure(object): > __slots__=('fn','args','kw') > def __init__(self, fn, *args, **kw): > self.fn, self.args, self.kw = (fn, args, kw) > > def __call__(self, *args, **kw): > d = self.kw.copy() > d.update(kw) > return self.fn(*(self.args + args), **d) > > So you can freeze a function or other callable with a partial > argument list and keyword arguments into a handy callable > object. I hope you're aware that Python (staring from 2.1) already has closures (and they're quickly becoming my favorite thing ever). As others have mentioned, what you're proposing is a built-in curry, which is just a closure that calls a given function with given arguments. In fact, the better way to do the above (2.1+) is to use a real closure (I'm surprised Martelli didn't point this out): from __future__ import nested_scopes def curry(fn,*cargs,**ckwargs): def call_fn(*fargs,**fkwargs): d = ckwargs.copy() d.update(fkwargs) return fn(*(cargs+fargs),**d) return call_fn > Obviously, the C implementation would try to minimise the > penalty of a dict copy and update per call, if there's a > nifty way to do it. If not, it's still a powerful abstraction > that would be useful even if it's not particularly fast. I wonder if the biggest benefit of a C-optimized curry would be eliminating Python function call overhead. Maybe this could allow fast functional code when speed matters: first = curry(operator.getitem,1) first_items = map(first,list_o_lists) +1 for curry implented in C if this will save a lot over slower Pyhton methods. > The kind of things where I see myself using it is in UI callbacks, > which never get executed in a tight loop anyway (unless something > is already wrong). Same here. Also functional programming for me. > The syntax proposal is more controversial. No kidding. -1 on any syntax change. > I want a function > call operator @(*args,**kw) that instead of invoking __call__ on its > left argument, returns a closure object. > > So the above examples would be written: > clamp=max@(0) > buttonmaker=Tkinter.Button@(my_window,bg='white') > > I'm a great fan of concise syntax, and this really appeals to me, > but what is the community view? Does python need a closure type? > Is the @ syntax too ugly to be worth it? I'm a fan of concise code, but not concise syntax. I would still be using Perl if I liked concise syntax. Concerning the semantics: I have two issues. First, I generally dislike incomplete solutions, and your proposal is incomplete because it only allows currying from the left. Second, there is an inconsistency between keyword and position arguments: the curried keyword arguments can be overriden by the caller. I don't like it, even if it could be useful. I would like to be able to curry arbitrary arguments. Something like: curry(fn,__,arg,__) where the __ parameters become arguments of the curried function. Functions like curryleft could be special cases or something. -- CARL BANKS From aleax at aleax.it Fri Feb 7 04:59:29 2003 From: aleax at aleax.it (Alex Martelli) Date: Fri, 07 Feb 2003 09:59:29 GMT Subject: Why does Dynamic Typing really matter?!? References: <623cd325.0302060257.1542e098@posting.google.com> <3E4269DD.96286B67@engcorp.com> <623cd325.0302061654.92aca73@posting.google.com> Message-ID: <5sL0a.143298$0v.4078395@news1.tin.it> Jason Smith wrote: > Hi Alex > >> but, it's not a deep and desperate need anyway (I do not know >> of any case where I'd suffer a BIG loss of productivity if it >> was impossible to change an object's type on the fly, _IF_ >> the whole system uses signature-polymorphism as below). > > "signature" polymorphism is the same as "explicit" bounded > quantification over types? i.e. haskell, forall a.b => a -> [String] > -> b etc...instead of letting the static inferencing take over..? Nope. You can perfectly well let type inferencing do its job -- but when it sees for example a + b it will infer that a and b are in SOME type in class Num -- it won't infer the exact type YET, because all types in class Num have a (+), e.g. as Prelude.hs says: class (Eq a, Show a) => Num a where (+), (-), (*) :: a -> a -> a [etc] i.e., any type a is in class Num if there exist (+), (-) and (*) as binary functions onto a (and also belongs to classes Eq and Show, etc, etc). Basically this is signature polymorphism at compile-time -- and so are C++'s templates, in a way that's not quite as explicit or elegant, but has a few advantages of its own in practical terms. Python does it at runtime -- slower (and you need unit tests to catch some errors Haskell would catch during the compilation phase -- but, as you DO need unit tests anyway to catch most errors, no real problem), not explicit, reasonably elegant IMHO, *very* practical. > I was under the impression that C++ templates were nothing more then a > macro hack by the preprocessor, though I would love to hear > otherwise..? please fill me in... The preprocessor doesn't know about types, so it can't do zilch with templates. If I write, e.g: template T accumulate(T x) { static T gg; gg += x; return gg; } then by C++ semantics, accumulate must be instantiated exactly once for each different type it's called with -- and implicitly can only be called with a type that support copy construction (because the argument x is passed by value, and thus also is the result returned), default construction (because of the way gg is declared), and operator +=. (A type with an inaccessible destructor would also be inacceptable). This set of operators and special methods that must be available on T make up the (implicit) "signature" T must respect to be acceptable here to the C++ compiler. So, I can call accumulate(23) and get one compile-time instantiation of the template with T set to int, then accumulate(2.3) and get another with T set to double, and when I then call accumulate(45) it must be the first one that's used again (so the result is 68). (Then it gets hairy because you can, and in some cases must, explicitly control the instantiations -- but, hey, I NEVER accused C++ of being _SIMPLE_ in any way...:-). Alex From bronzesink77 at hotmail.com Tue Feb 18 16:52:03 2003 From: bronzesink77 at hotmail.com (Jeff) Date: 18 Feb 2003 13:52:03 -0800 Subject: interacting with gui-based programs Message-ID: I'd like to use Python to automate my interactions with graphical user interfaces, such as those of Mozilla and Kazaa (running with Wine). Is this possible? Are there libraries that can help with this kind of thing? Thanks much. -Jeff From gminick at hacker.pl Fri Feb 7 11:47:09 2003 From: gminick at hacker.pl (Wojtek Walczak) Date: Fri, 7 Feb 2003 16:47:09 +0000 (UTC) Subject: ternary operator References: Message-ID: Dnia Fri, 7 Feb 2003 16:19:41 GMT, Andrew Koenig napisa?(a): > David> I think that's POOR programming practice! > > Then how would you write the following loop? > > i = 0; > while i < len(n) and x[i] != y: > i += 1 Here's what I'm assuming: n = "QQQ" y = "y" x = "abcdfghy" and here's the rest of the script: # here's your way i = 0 while i < len(n) and x[i] != y: i += 1 print i # the other way ;) print len(filter(lambda z: z!=y, list(x)[:len(n)])) ...but, well, in almost any case I'd use while loop, and what's _POOR_ for me is top-posting on Usenet rather than using i=0;while ...:... :) -- [ ] gminick (at) underground.org.pl http://gminick.linuxsecurity.pl/ [ ] [ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ] From dickerc6 at hotmail.com Wed Feb 5 18:39:30 2003 From: dickerc6 at hotmail.com (pedro alvarez) Date: 5 Feb 2003 15:39:30 -0800 Subject: Python and p2p References: <3E41371D.8080100@nipltd.com> Message-ID: Geoff Gerrietts wrote in message news:... > > I think, having some formal training as a librarian, and seeing the > way these things tend to play out, that except in very few > circumstances, a library would be a better choice for obtaining this > content than the indirect theft that is P2P networks. Most countries > have very progressive libraries, even in countries that are not > progressive. Getting access to quality technical books is possible. > Yes libraries. You are absolutely right. No doubt you can get the latest published edition of Fortran77, or Turbo Pascal. Maybe if you look around a bit, you might find ...surprise 'Advanced Cobol programming 2nd edition'. Point is just because your library is well stocked, it doesnt mean other libraries will be. Also, lots of people keep nicking the books. From skip at pobox.com Fri Feb 28 08:51:16 2003 From: skip at pobox.com (Skip Montanaro) Date: Fri, 28 Feb 2003 07:51:16 -0600 Subject: Python docs in Plucker format In-Reply-To: <1046436180.38229@newsmaster-03.atnet.at> References: <1046436180.38229@newsmaster-03.atnet.at> Message-ID: <15967.26964.440897.855781@montanaro.dyndns.org> Thomas> I'd like to contribute the whole Python Documentation (html) Thomas> that comes with the Debian Sid-Package (01-18-2003) in Plucker- Thomas> format (http://www.plkr.org). Thomas> (for those who don't know plucker: it's a static html-viewer for Thomas> PalmOS). You should send a note to python-docs at python.org. I know Fred Drake was experimenting with iSilo format some time ago. I don't know how many different Palm formats are needed. Skip From user at domain.invalid Thu Feb 27 02:19:18 2003 From: user at domain.invalid (user at domain.invalid) Date: Thu, 27 Feb 2003 09:19:18 +0200 Subject: global exception catching References: Message-ID: This may be overly simplified, but anyway, is there a reason for no putting all your code inside a "try" clause? Something like try: do this, created that file, etc, . . . exception ExceptionType1: do something,etc . . . exception ExceptionTypen: do something else,etc . . . exception: handle unexpectd (general) exceptions Hilbert wrote: > Hello, > > Is there a way to catch a "global" exception in a python > program (meaning that if there would be an error > during execution it could call a function before exiting)? > > I have a program that creates large temp files and in case > of any unforseen problems I still need to clean up before > exiting. > > > Thanks, > Hilbert > > > From tim.one at comcast.net Mon Feb 10 14:30:38 2003 From: tim.one at comcast.net (Tim Peters) Date: Mon, 10 Feb 2003 14:30:38 -0500 Subject: For review: PEP 308 - If-then-else expression In-Reply-To: Message-ID: [Andrew Koenig] > Here's another example, this one from Lib/test/test_iter.py, starting > at line 390: > > # Test map()'s use of iterators. > def test_builtin_map(self): > self.assertEqual(map(None, SequenceClass(5)), range(5)) > self.assertEqual(map(lambda x: x+1, SequenceClass(5)), > range(1, 6)) > > d = {"one": 1, "two": 2, "three": 3} > self.assertEqual(map(None, d), d.keys()) > self.assertEqual(map(lambda k, d=d: (k, d[k]), d), d.items()) > dkeys = d.keys() > expected = [(i < len(d) and dkeys[i] or None, > i, > i < len(d) and dkeys[i] or None) > for i in range(5)] > > and so on. > > This code works as written, but only by coincidence. You're pushing this too hard. Pointing out examples of code that work fine, but wouldn't *if* you changed them, isn't a worthy exercise. > If, for example, I were to change the initialization of d to > > d = {"": 0, "one": 1, "two": 2, "three": 3} > > then the code would break. That's why d wasn't initialized that way (I wrote this test, so I happen to know that; the test isn't a random collection of independent lines). From maxm at mxm.dk Tue Feb 11 03:42:49 2003 From: maxm at mxm.dk (Max M) Date: Tue, 11 Feb 2003 09:42:49 +0100 Subject: Extracting links! In-Reply-To: <2df14da0.0302100452.2ff25d9e@posting.google.com> References: <2df14da0.0302100452.2ff25d9e@posting.google.com> Message-ID: <3E48B789.2010106@mxm.dk> Muhammad wrote: > I'm building a search engine for our interior sites in Perl. > The engine uses index (word->urls), I built an index perl script that > indexes all the pages on a site, and start running it in our server, > but it was so heavy, took a lot of time and stacked the server > sometimes. The file I have attached here contains a module that might be of some help. It parses a html file for links. You can ie. relatively easy make it return all links in a page as absolute urls. lp = LinkParser(slashdot_source) absolue_urls = lp.relative2abs('http://www.slashdot.org/').values() -- hilsen/regards Max M Rasmussen, Denmark http://www.futureport.dk/ Fremtiden, videnskab, skeptiscisme og transhumanisme -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: LinkParser.py URL: From max at alcyone.com Tue Feb 11 07:08:19 2003 From: max at alcyone.com (Erik Max Francis) Date: Tue, 11 Feb 2003 04:08:19 -0800 Subject: Tix problem solved (Red Hat 7.x -> XLowerWindow undefined) References: Message-ID: <3E48E7B3.1006F7B4@alcyone.com> Ben Caradoc-Davies wrote: > Yikes! A clean Python build and installation should of course be > > ./configure; make; make test; make install > > Must try to get more sleeeeep ... I'd suggest ./configure && make && make test && make install :-). -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE / \ Never make a promise or plan / Take a little love where you can \__/ Florence, _Chess_ Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/ A personal guide to Quake III Arena. From jack at performancedrivers.com Fri Feb 14 20:56:36 2003 From: jack at performancedrivers.com (Jack Diederich) Date: Fri, 14 Feb 2003 20:56:36 -0500 Subject: While we're on the subject of proposing language changes... ;-) In-Reply-To: ; from danb_83@yahoo.com on Fri, Feb 14, 2003 at 05:35:00PM -0800 References: Message-ID: <20030214205636.D5005@localhost.localdomain> On Fri, Feb 14, 2003 at 05:35:00PM -0800, Dan Bishop wrote: > PEP: XXX When Guido chummed the waters with 308, could he have known the results? guilty-as-the-next-man-ly, -jackdied From mueller-oertel at arcor.de Fri Feb 7 20:41:31 2003 From: mueller-oertel at arcor.de (=?iso-8859-1?Q?M._M=FCller-Oertel?=) Date: Sat, 8 Feb 2003 02:41:31 +0100 Subject: Some thoughts about Python, python.org and non-English languages References: <3E448083.9090304@removethis.free.fr> Message-ID: <010a01c2cf14$53c12e60$46b707d5@A31> > In an perfect world, it would make perfect sens... But the fact is that > not reading (not speaking, reading) english seems hardly avoidable if > you plan to do anything in computer programming. For me this doesn't seem to be a law of nature. > BTW, I think that the real reason why Python is not that 'hype' as to do > with the fact that there is no big-company-with-big-dollars pushing it > (and I thank God - if He exists - for that point). So do I. It's much better the community pushes it. Marcus From d95-bli at nada.kth.se Mon Feb 24 18:18:15 2003 From: d95-bli at nada.kth.se (=?iso-8859-1?q?Bj=F6rn?= Lindberg) Date: 25 Feb 2003 00:18:15 +0100 Subject: Yet Another Case Question References: Message-ID: Alex Martelli writes: > IF Python was case-insensitive, you might freely PRETEND the > convention was universally applied, spelling that particular > constant as math.PI in your code for example. As things stand > (and will keep standing, alas), you cannot even pretend: you > must inherently acknowledge every time you use something as > fundamental as standard module math that the convention is in > fact broken all over the place. Quite a way from "enforcing"!!! I would like to add one viewpoint here. I think you are painting a little too bright a picture here when you say that names of different capitalisation schemes could be used interchangeably. The two most common capitalisation schemes are CamelCase and no_case. Personally, I have a strong dislike for camel case which I find distrubing and difficult to read. Therefore, I use underscores. Normally I don't even capitalise class names, although that depends on which language I'm working in. Anyway, my funtion names will look like generate_binary_tree, and get_token, and such. A person favouring camel case could not apply it to my variable names. The best he/she could do, is Generate_Binary_Tree, and get_Token, which is probably not what he wants. It works equally bad the other way around. Any longer camel case name will look completely incomprehensible in only small letters. A person like me, who favours the underscore notation, would have to make do with generatebinarytree, and gettoken. In practice, I would probably be forced to use camel case anyway, just to be able to write the names correctly. So, your freedom of choice in notation is in practice really only valid for short names. For longer names, there will be no improvement. I predict then that the smaller names would be written in a style dictated by how the larger names are already written, for some module or a project utilising several modules. Bj?rn From markus_wankus at hotmail.com Wed Feb 19 15:44:19 2003 From: markus_wankus at hotmail.com (Markus Wankus) Date: Wed, 19 Feb 2003 15:44:19 -0500 Subject: Python IDE ERIC3 In-Reply-To: References: <3E032E45.5050902@uni-koeln.de> Message-ID: On Wed, 19 Feb 2003 19:58:21 -0000, KrayZee--J wrote: > I have tried to install this on Windows and run into a lot of problems. > > First of all I had to install: > > Qt (latest version but it is a demo - the non commercial version doesn't > work with QScintilla) > SIP > PyQt > QScintilla > > PyQt doesn't build properly, maybe because it is meant for the > non-commercial version of Qt (version 2.3!) but then QScintilla requires > Qt > 3 or above. > > The thing is I don't even want to develop any Qt software so I don't want > the whole SDK installed. I've looked for a simple binary runtime download > on > the Trolltech site but they don't seem to have one! It would be a good > idea > to make a binary package of Eric3 (ie. with PyQt extension prebuilt and > Qt , > QScintilla runtime components only (just the dlls)). Maybe put Qt and > QScintilla in a separate download in case people already have them. > > It looks an excellent IDE by the look of the screenshots. I'm sure you > would > have much more users if it was easier to install! > > John Don't get me started.... I agree - it might be more popular if it was possible to install it. Keep in mind however, it is not licensed to be run under Windows because Qt is not GPL'd for Win32. I was reminded of this and was told to stop trying to install it on Windows. Also, even if you could get it installed, I don't think it was even tested or coded to run on Win32 so it probably has all kinds of gotchas. I also tried a fresh install of Linux for the sole purpose of checking this IDE out and gave up after 3 days of failing to satisfy all dependencies. The older verison went in no problem, but it lacks most of the features of v3. You are not alone in your installation woes... -- Markus From bokr at oz.net Tue Feb 11 20:13:32 2003 From: bokr at oz.net (Bengt Richter) Date: 12 Feb 2003 01:13:32 GMT Subject: ternary operator vote References: <200302081710.h18HA2S03849@europa.research.att.com> <20030208171639.GA10283@panix.com> <2xR1a.22206$F25.5011@nwrddc02.gnilink.net> <3E487291.70FDD1B6@alcyone.com> Message-ID: On Wed, 12 Feb 2003 00:15:50 GMT, Andrew Koenig wrote: >>> If "no change" is an alternative, you can express disapproval by >>> voting for that alternative. > >Bengt> A: +1 >Bengt> B: +0 >Bengt> C: -0 # actual opinion, no way to express >Bengt> D: -1 # ditto >Bengt> no change: +1 means what? > >In approval voting, you are presented with a collection of >alternatives, and you choose which of those alternatives you are >willing to accept. > >You can choose more than one. > >So, if the alternatives are A, B, C, D, or no change, you could >vote for no change (alone) if you want to express disapproval of >any change. > But you are bypassing my point. I want to say I'm ok with A, but "hell no" to C. Just a no_change +1 makes it seem like I'm equally ok with A or no change, and indifferent to C. IOW, even allowing only {-1,0,+1} for A-D gives 3**4 information states, whereas {0,1} for A-D+No_change gives 2**5 : 81 vs 32, so obviously (ISTM) a single no_change is no substitute for the expressiveness of -1,0,+1. It's always (for n>=2 choices) going to be true that 3**n > 2**(n+1). Regards, Bengt Richter From jeremy at zope.com Tue Feb 11 17:31:19 2003 From: jeremy at zope.com (Jeremy Hylton) Date: 11 Feb 2003 17:31:19 -0500 Subject: PEP-308 a "simplicity-first" alternative In-Reply-To: References: Message-ID: <1045002679.1388.9.camel@slothrop.zope.com> On Tue, 2003-02-11 at 17:25, David LeBlanc wrote: > > Ditto. +1. > Is there an official vote in progress or not? I thought there was going to > be a python-announce(ment) about it? > Yes. I think that last +1 seals it now. The +1 votes have exceeded the minimum threshold necessary to decide the issue. If we get any more, I think Andrew will have to add it to C++, too. Jeremy From simonb at webone.com.au Thu Feb 13 07:30:17 2003 From: simonb at webone.com.au (Simon Burton) Date: Thu, 13 Feb 2003 23:30:17 +1100 Subject: Tree transformation programs? References: Message-ID: On Wed, 12 Feb 2003 10:08:55 +0000, Edward C. Jones wrote: > Are there any programs written in Python for transforming trees, > especially AST trees? The input should be > > A tree that is produced by a C parser. > Rules for matching patterns in trees. > Transformations to be done on the input if a pattern is matched.. What are you up to ? I was asking about term rewriting here a while back. here is my work so far: http://arrowtheory.com/software/python/index.html Simon Burton. From missive at frontiernet.net Fri Feb 28 14:10:01 2003 From: missive at frontiernet.net (Lee Harr) Date: Fri, 28 Feb 2003 19:10:01 -0000 Subject: cross platform application configuration files References: Message-ID: >> http://www.python.org/doc/2.3a2/lib/module-ConfigParser.html >> > My question, though, is more about where to put the file, > and how to find it again on any platform. > Actually, it looks like this does have support for what I want to do. You have to read on to the 2nd page to see that tho :o) I guess I am still unclear about what should be the choices for config.read() so that my application will find the right file on any platform. Any suggestions? From exarkun at intarweb.us Sun Feb 2 13:06:04 2003 From: exarkun at intarweb.us (Jp Calderone) Date: Sun, 2 Feb 2003 13:06:04 -0500 Subject: Help on scope/namespace In-Reply-To: <0y0%9.1101$zM1.121337873@newssvr21.news.prodigy.com> References: <0y0%9.1101$zM1.121337873@newssvr21.news.prodigy.com> Message-ID: <20030202180604.GA25338@meson.dyndns.org> On Sun, Feb 02, 2003 at 03:48:12AM +0000, Byron Morgan wrote: > [snip] > > Is there some way I can import functions from a file, and have them behave > just as though they are contained in the main script ? There's a way, but you don't want to use it. The problem you're seeing is that code runs in the scope it was *defined* in, not the scope it is invoked in. Functions defined in module Y and called from module X don't see module X's globals - they see module Y's globals. The easiest, least painful, and cleanest way around this is to somehow make module X's globals into parameters passed to module Y's functions. You can do this directly, by simply adding a parameter or two to each function in Y, or create a class that takes each of the globals as an __init__ argument, then keeps references to them that the now-member functions can examine. Jp -- A sad spectacle. If they be inhabited, what a scope for misery and folly. If they be not inhabited, what a waste of space. -- Thomas Carlyle, looking at the stars -- up 48 days, 21:50, 4 users, load average: 0.27, 0.16, 0.06 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From rnd at onego.ru Sat Feb 8 14:49:19 2003 From: rnd at onego.ru (Roman Suzi) Date: Sat, 8 Feb 2003 22:49:19 +0300 (MSK) Subject: Python's 8-bit cleanness deprecated? In-Reply-To: Message-ID: I've made some summary again (please correct me if I misunderstood): pro PEP-0263: Brian Quinlan M.-A. Lemburg (PEP's author) Jp Calderone Michael Hudson Scott David Daniels (bytes vs. symbols) Erik Max Francis Terry Reedy (?) Neil Hodgson John Roth contra: Roman Suzi Kirill Simonov (is willing to patch) Chris Liechti (bad for newbies) Mike C. Fletcher Simo Salminen Carlos Ribeiro Paul Rubin (against comment) Just (against comment) Bengt Richter (against comment) Dale Strickland-Clark (against comment) Laura Creighton (against comment) ? or 0: Skip Montanaro (control via site.py) Francois Pinard Alex Martelli Anders J. Munch Jeff Epler Andrew Bennetts This "statistics" shows that those who use some extension of ASCII are concerned. However, I'd liked to hear people from Asia. What are you thinking about PEP-0263? Is it good, neutral or bad for you? Please, voice your opinion as it not too late to change Python behaviour to better suit our needs. Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.3 From mis6 at pitt.edu Fri Feb 14 10:31:26 2003 From: mis6 at pitt.edu (Michele Simionato) Date: 14 Feb 2003 07:31:26 -0800 Subject: PEP 308: Alternative conditional operator forms References: <3E46F0CE.5675E180@alcyone.com> <2259b0e2.0302110716.30b11ee2@posting.google.com> <2259b0e2.0302111142.f86a2b1@posting.google.com> <2259b0e2.0302120832.6fb89c7d@posting.google.com> <2259b0e2.0302131212.746b7c36@posting.google.com> Message-ID: <2259b0e2.0302140731.6464175a@posting.google.com> Nick Vargish